Kotlin SDK library for interacting with a CSPR node.
SDK to streamline the 3rd party Kotlin client integration processes. Such 3rd parties include exchanges & app developers.
- The SDK is built with Kotlin language versioned 1.5
To build and test the SDK you need the flowing things installed in your computer:
-
Java JDK version 8 or above, Java JDK 18 is suggested
-
IntelliJ IDEA latest version, can be download at this address https://www.jetbrains.com/idea/download
The package can be built and tested from IntelliJ IDEA or from command line with Maven.
You need to have Maven installed in your machine. Follow the instruction here to install Maven:
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Download the Casper-Kotlin-SDK code from Github and put it somewhere in your machine.
Open Terminal if you are using Mac OS or Command Prompt if you are using Windows OS. Enter the root folder of the Casper-Kotlin-SDK, then run this command to test and build the SDK:
mvn package
Somehow the result will be like this
Download the latest IntelliJ IDEA from https://www.jetbrains.com/idea/download
The SDK is developed with IntelliJ IDEA 2021.3.3 (Community Edition). Then a Community Edition is good enough to test the SDK.
Download or clone the code from github, then open it with IntelliJ IDEA.
The first thing to do is to set up the SDK for the Project.
In IntelliJ IDEA hit "File-> Project Structure..."
You will see this screen shown up
Click on tab "SDKs" in the left panel to see the list of SDK being installed in your ItelliJ IDEA. You need to install the SDK from 11 or above, the suggested SDK is "openjdk-18".
By default, the SDKs list is just "Kotlin SDK". To install more SDK, hit the "+" button and choose "Download JDK ..."
Select your JDK version. You can choose any option in the list box, but the suggested version is 18, then hit the "Download" button
After the downloading is completed, you'll see the "openjdk-18" item (if you install JDK version 18) together with the Kotlin SDK.
Add more JDK version with the same step if you wish to test on more version of the JDK.
Next in the tab Project, choose the SDK for the project. In this case the choosen SDK is "openjdk-18"
Just do this for the SDK configuration, left the other configurations with default values. Make sure that the "Language level" is "SDK default" as in the image below.
Click "Apply" and then "OK" to save the configruation. The next step is to import the necessary Jar files to the SDK.
Get the jars file from this link https://drive.google.com/drive/folders/1oflaJ_1m3HX9NYI_5d0PuoT2WNGy6dPq?usp=sharing
Download all the jars file to your local computer, you will have two folders with name "bcutils" and "otherjars" containing the jar files that will be later imported to the SDK.
In IntelliJ IDEA, hit "File-> Project Structure ..."
A new window appears, click on "Libraries" and then "Maven: net.jemzart:jsonkraken:1.2.0", then click the "+" button
Browse to the 2 jar folders that you have already downloaded from the link https://drive.google.com/drive/folders/1oflaJ_1m3HX9NYI_5d0PuoT2WNGy6dPq?usp=sharing above. First choose "bcutils" folder
Select all the files in the "bcutils" folder and click "Open" button
You will see the jar files imported in the list
Next step is to import all the files in the "otherjars", click the "+" button again and browse to the "otherjars" folder
Choose all the files in the "otherjars" folder, then click "Open"
You will see that all the jars from the two folder "bcutils" and "otherjars" is now imported to the list
Click "Apply" and then "OK" button.
You will need to restart IntelliJ IDEA to make the Jar files work. In IntelliJ IDEA click "File->Invalidate Caches ..."
A windows will appear, check all the check box then click "Invalidate and Restart"
The IntelliJ IDEA will close and restart. You may have to wait for 1 or several minutes to wait for IntelliJ IDEA to be ready for the changes. Then you can build and test the SDK.
To build the project, in IntelliJ IDEA, hit "Build->Build Project" as in the image below
You can see the Build log by clicking the "Build" tab in the bottom of the IntelliJ IDEA window
To run the test, in the Project panel that show the files and folders, under the folder "test", right click on the "kotlin" folder (folder marked with green in the below image), hit "Run 'All Tests'".
The test list is in the right panel, the result is in the left panel, as shown in the image:
The Key wrapper do the following work:(for both Secp256k1 and Ed25519):
-
(PrivateKey,PublicKey) generation
-
Sign message
-
Verify message
-
Read PrivateKey/PublicKey from PEM file
-
Write PrivateKey/PublicKey to PEM file
The key wrapper is used in account_put_deploy RPC method to generate approvals signature based on deploy hash.
The Crypto task for Ed25519 and Secp256k1 use BouncyCastle library at this address https://bouncycastle.org/, with the Jar files from this address
https://bouncycastle.org/latest_releases.html
The Ed25519 crypto task is implemented in file Ed25519Handle under package com.casper.sdk.crypto
The Secp256k1 crypto task is implemented in file Secp256k1Handle under package com.casper.sdk.crypto
A detail information on CLType primitive can be read here
Casper Kotlin SDK CLType primitive
All of the main Casper Domain Specific Objects is built in Kotlin with classes like Deploy, DeployHeader, ExecutionDeployItem, NamedArg, Approval, JsonBlock, JsonBlockHeader, JsonEraEnd, JsonEraReport, JsonBlockBody, JsonProof, ValidatorWeight, Reward, ... and so on. All the class belonging to the RPC call is built to store coressponding information.
To use the SDK as external libary in other project, please refer to this document for more detail.