The Concordium Java SDK provides an interface to communicating with a Concordium node.
The package is released on Maven Central. The Android compatible package is also released on Maven Central.
- Java 1.8
- Maven
- Rust
make
- Java has been tested with OpenJDK v.1.8.0_292.
- Maven has been tested with v.3.6.3.
- Rust has been tested with v.1.69
To build the native library and put it into the correct folders all one has to do the following:
- Clone this repository and remember to update git submodules, for example when cloning via
git clone https://github.com/Concordium/concordium-java-sdk.git --recurse-submodules- Run
makefrom the root of this repository. - Run
mvn installfrom the root of the concordium-sdk folder.
The first step builds the native dependencies and the latter builds the resulting .jar file.
The two steps builds results in the following two .jar files.
- A regular jar file called
concordium-sdk-{VERSION}.jar. - A
fatjar file calledconcordium-sdk-{VERSION}-jar-with-dependencies.jarwhich embeds the dependencies into one jar.
The "normal" jar can then be used from another project by adding it to the pom.xml:
<dependencies>
<dependency>
<groupId>com.concordium.sdk</groupId>
<artifactId>concordium-sdk</artifactId>
<version>${VERSION}</version>
</dependency>
</dependencies>The fat jar can then be used from another project by adding it to the pom.xml:
<dependencies>
<dependency>
<groupId>com.concordium.sdk</groupId>
<artifactId>concordium-sdk</artifactId>
<version>${VERSION}</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
</dependencies>When doing changes wrt. the JNI two things have to be taken care of.
- The Java native calls
- The rust implementation of which the Java native binds to.
The SDK uses JNI to perform EDDSA_ED25519 signatures.
The JNI entrypoint is located in the EDD25519.java
One can create a new header file by using the command: javac -h . ED25519.java from the root of ed25519 folder.
The output will be a header file, the contents hereof must be matched appropriately as described in the documentation into the lib.rs rust source file.
To build the android AAR package, one has to do the following:
- Clone this repository and remember to update git submodules, for example when cloning via
git clone https://github.com/Concordium/concordium-java-sdk.git --recurse-submodules- Set the ANDROID_HOME environment variable to the path to your Android SDK installation.
- Run
make add-android-targetsfrom the root of this repository. - Run
make androidfrom the root of this repository. - Run
mvn install -Nfrom the root of the repository. - Run
mvn installfrom the root of the concordium-android-sdk folder.
make add-android-targets adds the rust targets that the native libraries will be built for.
make android builds the native libraries for various targets using cargo-ndk.
And the final step builds the aar file concordium-android-sdk.aar in the target folder, which can be used in android projects.
Note that this uses the Android Maven Plugin, which is what requires the Android SDK, the specific version can be seen in its documentation.
Note that the minimum android SDK version for this package is 26.
The ClientV2 is the main entrypoint for the SDK.
It facilitates an API for communicating with the node through the V2 API.
The ClientV2 must be initialized with a Connection which holds information of the node URL, timeout duration etc. for the connection.
Connection connection = Connection.newBuilder()
.host(${node_host})
.port(${node_port})
.useTLS(TLSConfig.auto()) // If the node is under HTTPS
.build();
ClientV2 client = ClientV2.from(connection);where
node_hostis the host of the node e.g.127.0.0.1node_portis the nodes rpc port e.g.20000
One can also provide extra HTTP headers to the grpc calls by setting up the client as the following:
Connection connection = Connection.newbuilder()
.credentials(Credentials.builder()
.withAdditionalHeader(Header.from("HEADER1", "VALUE1"))
.withAdditionalHeader(Header.from("HEADER2", "VALUE2"))
.build())
.host(${node_url})
.port(${node_port})
.timeout(${timeout})
.build();
ClientV2 client = ClientV2.from(connection);It is also possible to enforce TLS to be used in the underlying connection e.g.
Connection connection = Connection.newbuilder()
.host(${node_url})
.port(${node_port})
.timeout(${timeout})
.useTLS(TLSConfig.from(new File("/a/path/to/the/servers/certificate.pem")))
.build();
ClientV2 client = ClientV2.from(connection);Further the Client exposes a close() function which should be called when finished using the client in order to
perform an orderly shutdown of the underlying grpc connection.
The node API is exposed via ClientV2 and transactions can be created using the TransactionFactory e.g. TransactionFactory.newTransfer().
See the examples for example usages of the API.
It is also possible to send a raw transaction via the client e.g., if the transaction has been generated somewhere else.
This can be done via (AccountTransaction.fromBytes(the_raw_transaction_bytes).
By default the java library supports ED25519 signing via the native binding ED25519SecretKey.
However the library also supports external signing services such as HSM's or other secret managers and the like.
In order to use an external signer one must implement the Signer interface.
The interface exposes one function:
byte[] sign(byte[] message) throws ED25519Exception;A signer is then added to a TransactionSigner as follows:
TransactionSignerImpl signer = TransactionSigner.from(SignerEntry.from(Index.from(0), Index.from(1), new Signer() {
// The custom signer
@Override
public byte[] sign(byte[] bytes) throws ED25519Exception {
return new byte[0];
}
}), ... );- Update all the SDK artifacts version to
X.Y.Z-SNAPSHOT, havingX.Y.Zthe next version from the current according to semver. Do it once the changes made require semver version change. Otherwise, the same-SNAPSHOTcan be re-written. To update the version automatically, from the root of the repository invokemvn versions:set -DnewVersion=X.Y.Z-SNAPSHOT - Optionally, if updated
concordium-base, runmakeormake-android - Run
mvn install, so the artifacts get installed in your local Maven repo (an.m2directory under your home directory) - In your application, reference the new SDK snapshot.
Make sure to have
mavenLocal()repository in your dependency resolution configuration
Please follow the steps from the Release guide