Skip to content

CoboGlobal/cobo-java-api

Repository files navigation

The Official Java SDK for Cobo WaaS API

JitPack License: GPL v2 GitHub Release

About

This repository contains the official Java SDK for Cobo WaaS API, enabling developers to integrate with Cobo's Custodial and/or MPC services seamlessly using the Java programming language.

Documentation

To access the API documentation, navigate to the API references.

For more information on Cobo's Java SDK, refer to the Java SDK Guide.

Usage

Before You Begin

Ensure that you have created an account and configured Cobo's Custodial and/or MPC services. For detailed instructions, please refer to the Quickstart guide.

Requirements

  • JDK8
  • JDK17 or newer

Installation

Step 1. Add the JitPack repository to your build file

gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

maven:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency

gradle:

dependencies {
    implementation 'com.github.CoboGlobal:cobo-java-api:v0.85'
}

maven:

<dependency>
    <groupId>com.github.CoboGlobal</groupId>
    <artifactId>cobo-java-api</artifactId>
    <version>v0.85</version>
</dependency>

Code Sample

Generate Key Pair

import com.cobo.custody.api.client.impl.LocalSigner;

String[] key = LocalSigner.generateKeyPair();
String secretKey = key[0];
String apiKey = key[1];

For more information on the API key, please click here.

Initialize ApiSigner

ApiSigner can be instantiated through new LocalSigner("secretkey" )

In certain scenarios, the private key may be restricted from export, such as when it is stored in AWS Key Management Service (KMS). In such cases, please pass in a custom implementation using the ApiSigner interface:

import com.cobo.custody.api.client.ApiSigner;
new ApiSigner() {
    @Override
    public String sign(byte[] message) {
        return null;
    }

    @Override
    public String getPublicKey() {
        return null;
    }
}

Initialize RestClient

These can be instantiated using the corresponding factory method provided by CoboApiClientFactory.

import com.cobo.custody.api.client.CoboApiClientFactory;
import com.cobo.custody.api.client.CoboApiRestClient;
import com.cobo.custody.api.client.config.CoboApiConfig;
import com.cobo.custody.api.client.config.Env;
import com.cobo.custody.api.client.impl.LocalSigner;

CoboApiRestClient client = CoboApiClientFactory.newInstance(
                new LocalSigner(apiSecret),
                Env.DEV,
                false).newRestClient();

Complete Code Sample

import com.cobo.custody.api.client.CoboApiClientFactory;
import com.cobo.custody.api.client.CoboApiRestClient;
import com.cobo.custody.api.client.config.CoboApiConfig;
import com.cobo.custody.api.client.config.Env;
import com.cobo.custody.api.client.impl.LocalSigner;

String[] key = LocalSigner.generateKeyPair();
String secretKey = key[0];
String apiKey = key[1];

CoboApiRestClient client = CoboApiClientFactory.newInstance(
                new LocalSigner(secretKey),
                Env.DEV,
                false).newRestClient();
                
ApiResponse<OrgInfo> orgInfo = client.getOrgInfo()
System.out.println(orgInfo);