The ToolSign is designed to provide [[4. Cellframe Tool Sign|Cellframe Tool Sign]] functional for Java IDE's. With the **`CellframeSDK.jar`** library you can: - Create a Cellframe wallet - Restore a wallet from file - Sign pre-composed transaction from JSON file Download library **[here](https://pub.cellframe.net/java/java-cellframe/master/)**. In the end of the article the **[[Cellframe Tool Sign (Java)#Usage Example|Usage Example]]** is placed. # MODULES The structure of library is represented in the following modules: ## CRYPTO 1) **[[Cellframe Tool Sign (Java)#Class EncKey|Class EncKey]]** 2) **[[Cellframe Tool Sign (Java)#Class EncKeyType enum|Class EncKeyType enum]]** 3) **[[Cellframe Tool Sign (Java)#Class Signer|Class Signer]]** ## DATUM 1) **[[Cellframe Tool Sign (Java)#Class Tx|Class Tx]]** ## UTILS 1) **[[Cellframe Tool Sign (Java)#Class Helpers|Class Helpers]]** 2) **[[Cellframe Tool Sign (Java)#Class NativeLibraryLoader|Class NativeLibraryLoader]]** ## WALLET 1) **[[Cellframe Tool Sign (Java)#Class NetID|Class NetID]]** 2) **[[Cellframe Tool Sign (Java)#Class Wallet|Class Wallet]]** 3) **[[Cellframe Tool Sign (Java)#Class WalletType enum|Class WalletType enum]]** 4) **[[Cellframe Tool Sign (Java)#Class WalletAddress|Class WalletAddress]]** # CLASSES ## Class EncKey This class represents encryption key. **Methods:** ### Get encryption key from seed phrase ```c public static EncKey fromSeed(EncKeyType signType, String seed) --- Return: EncKey object ``` **Arguments:** 1. **`EncKeyType signType`**: type of a signature 2. **`String seed`**: seed phrase **Description:** method takes signature type and seed phrase and returns [[Cellframe Tool Sign (Java)#Class EncKey|EncKey]] object. ## Class EncKeyType enum This class represents different encryption types and contains the following values: ```java INVALID(-1, "invalid"), NULL(0, "null"), IAES(0, "iaes"), OAES(1, "oaes"), BF_CBC(2, "bf_cbc"), BF_OFB(3, "bf_ofb"), GOST_OFB(4, "gost_ofb"), KUZN_OFB(5, "kuzn_ofb"), SALSA2012(6, "salsa2012"), SEED_OFB(7, "seed_ofb"), RLWE_NEWHOPE_CPA_KEM(8, "rlwe_newhope_cpa_kem"), MSRLN(11, "msrln"), RLWE_MSRLN16(12, "rlwe_msrln16"), RLWE_BCNS15(13, "rlwe_bcns15"), LWE_FRODO(14, "lwe_frodo"), CODE_MCBITS(15, "code_mcbits"), NTRU(16, "ntru"), MLWE_KYBER(17, "mlwe_kyber"), SIG_PICNIC(18, "sig_picnic"), SIG_BLISS(19, "sig_bliss"), SIG_TESLA(20, "sig_tesla"), SIG_DILITHIUM(21, "sig_dilithium"), SIG_RINGCT20(22, "sig_ringct20"), KEM_KYBER512(23, "kem_kyber512"), SIG_FALCON(24, "sig_falcon"), SIG_SPHINCSPLUS(25, "sig_sphincsplus"), SIG_ECDSA(26, "sig_ecdsa"), SIG_SHIPOVNIK(27, "sig_shipovnik"), SIG_MULTI_CHAINED(100, "sig_multi_chained"), PQLR_SIG_DILITHIUM(1021, "pqlr_sig_dilithium"), PQLR_SIG_FALCON(1024, "pqlr_sig_falcon"), PQLR_SIG_SPHINCS(1025, "pqlr_sig_sphincs"), PQLR_KEM_SABER(1051, "pqlr_kem_saber"), PQLR_KEM_MCELIECE(1052, "pqlr_kem_mceliece"), PQLR_KEM_NEWHOPE(1058, "pqlr_kem_newhope"); ``` Every encryption type has: - **`code(int)`** - code number - **`value (String)`** - name **Methods:** ### Get encryption type code ```c public int getCode() --- Return: integer ``` **Arguments:** none **Description:** method gets the code of this encryption type. ### Get encryption type name ```c public String getValue() --- Return: String ``` **Arguments:** none **Description:** method gets the name of this encryption type. ### Create encryption type from code ```c public static EncKeyType fromCode(int code) --- Return: EncKeyType object ``` **Arguments:** 1. **`int code`**: code number of encryption type. **Description:** method creates `EncKeyType` object from code number. ### Create encryption type from name ```c public static EncKeyType fromString(String text) --- Return: EncKeyType object ``` **Arguments:** 1. **`String text`**: name of the encryption type. **Description:** method creates an `EncKeyType` object from code number. ## Class Signer This class serves as a datum signer. **Methods:** ### Sign transaction datum ```c public Tx signDatumTx(Tx datumTx) --- Return: Tx object ``` **Arguments:** 1. **`Tx datumTx`**: a transaction datum object for signing **Description:** method takes a transaction datum and sings it. ## Class Tx This class represents a transaction. **Methods:** ### Transform String to JSON ```c public String toJson() --- Return: JSON object ``` **Arguments:** none **Description:** method transforms String to JSON object. ### Get Tx object from JSON ```c public static Tx fromJson(String json) --- Return: Tx object ``` **Arguments:** 1. **`String json`**: a string containing JSON. **Description:** method transforms JSON string into [[Cellframe Tool Sign (Java)#Class Tx|transaction object]]. ## Class NetID This class represents network ID. **Methods:** ### Get Net ID from hash (HEX) ```c public static NetID fromHex(String netIdHex) --- Return: NetID object ``` **Arguments:** 1. **`String netIdHex`**: Net ID in the HEX format. Net ID's: ```ini Backbone - 0x0404202200000000 KelVPN - 0x1807202300000000 ``` **Description:** method forms [[Cellframe Tool Sign (Java)#Class NetID|NetID object]] from the Net ID hash. ### Get Net ID from long integer ```c public static NetID fromLong(long netId) --- Return: NetID object ``` **Arguments:** 1. **`long netId`**: Net ID in the long integer format. **Description:** method forms [[Cellframe Tool Sign (Java)#Class NetID|NetID object]] from the long integer Net ID. ## Class Helpers This is a utility helper class that contains methods for working with various data types. **Methods:** ### Transfrom net ID from HEX to Long ```c public static long netIdHexToLong(String netId) --- Return: long integer ``` **Arguments:** 1. **`String netId`**: net ID in the HEX format **Description:** method transforms Net ID represented in the HEX format into the number. ## Class NativeLibraryLoader This class is designed to dynamically load native SDK libraries into a Java application. ## Class Wallet This class is designed to interact with wallet. **Methods:** ### Get wallet from.dwallet file ```c public static Wallet fromFile(File file) --- Return: Wallet object ``` **Arguments:** 1. **`File file`**: file `.dwallet` containing existing wallet. **Description:** method creates wallet from the `.dwallet` file. ### Get protected wallet from.dwallet file ```c public static Wallet fromFile(File file, String password) --- Return: Wallet object ``` **Arguments:** 1. **`File file`**: file `.dwallet` containing existing wallet. 2. **`String password`**: wallet password. **Description:** method creates wallet from the `.dwallet` file. ### Create protected wallet with seed-phrase ```c public static Wallet create(Path path, String name, WalletType signType, String password, String seed) --- Return: Wallet object ``` **Arguments:** 1. **`Path path`**: a path, where a wallet will be created. 2. **`String name`**: name of the wallet. 3. **`WalletType signType`**: signature type `SIG_DIL` or `SIG_FALCON`. 4. **`String password`**: password. 5. **`String seed`**: 24 words seed phrase. **Description:** method creates `wallet` protected by both `password` and `seed` phrase. ### Create unprotected wallet ```c public static Wallet create(Path path, String name, WalletType signType) --- Return: Wallet object ``` **Arguments:** 1. **`Path path`**: a path, where a wallet will be created. 2. **`String name`**: name of the wallet. 3. **`WalletType signType`**: signature type `SIG_DIL` or `SIG_FALCON`. **Description:** method creates `wallet`. ### Create protected wallet ```c public static Wallet create(Path path, String name, WalletType signType, String password) --- Return: Wallet object ``` **Arguments:** 1. **`Path path`**: a path, where a wallet will be created. 2. **`String name`**: name of the wallet. 3. **`WalletType signType`**: signature type `SIG_DIL` or `SIG_FALCON`. 4. **`String password`**: password. **Description:** method creates a `wallet` protected by password. ### Get wallet address ```c public WalletAddress getAddress(NetID netId) --- Return: WalletAddress object ``` **Arguments:** 1. **`NetID netId`**: a NetID object **Description:** method gets the `wallet` address using network `ID`. ### Get number of certificates ```c public int getCertsNumber() --- Return: int ``` **Arguments:** none **Description:** method gets certificate number of this wallet. ### Get wallet encryption key ```c public EncKey getEncKey() --- Return: EncKey OBJECT ``` **Arguments:** none **Description:** method gets encryption key [[Cellframe Tool Sign (Java)#Class EncKey|EncKey]] of this wallet. ### Class WalletType enum This class contains types of wallet protection. Two type values: ```JAVA SIG_DIL("sig_dil") SIG_FALCON("sig_falcon") ``` ### Get wallet type ```c public String getValue() --- Return: String ``` **Arguments:** none **Description:** method gets wallet protection type `sig_dil` or `sig_falcon`. ### Get wallet type from text ```c public static WalletType fromString(String text) --- Return: WalletType object ``` **Arguments:** **`String text`**: protection type of the wallet. **Description:** method creates a `WalletType` object from the text. ## Class WalletAddress This class represents a wallet address. ### Transform wallet address to string ```c public String toString() --- Return: String ``` **Arguments:** none **Description:** transforms this `wallet address` to string. ## Usage Example The following snippet shows how to create a wallet, get its address, get JSON from a file, turn it into a transaction, sign it with an existing wallet and turn it back to a JSON file. ```java // creation of the wallet object WAL named "wallettest" with SIG_DIL protection type and "12345" password Wallet WAL = Wallet.create(Paths.get("./"), "wallettest", Wallet.WalletType.SIG_DIL, "12345"); // get network ID from the network hash (Backbone) NetID networkID = NetID.fromHex("0x0404202200000000"); // get wallet address of the created wallet (WAL) WalletAddress getAddr = WAL.getAddress(networkID); // wallet(WAL) address print in console System.out.printf(getAddr.toString()); // work with files input/output try { // get path of the "jsonIN.txt" file with transaction Path path = Paths.get("jsonIN.txt"); // reading JSON object from file into string variable String jsonIN = Files.readString(path); // print initial JSON System.out.println(jsonIN); // create a transaction object from initial JSON Tx TX = Tx.fromJson(jsonIN); // get encryption key of the wallet WAL EncKey key = WAL.getEncKey(); // create signer object containing previously gained encryption key Signer signer = new Signer(key); // sign transaction datum using encryption key of the WAL wallet Tx signedTX = signer.signDatumTx(TX); // print signed JSON in console (now JSON must contain signature) System.out.println(signedTX.toJson()); // get file object "walletfile" from file "CELLWALLET.dwallet" File walletfile = new File("CELLWALLET.dwallet"); // create wallet object WAL2 from file "walletfile" Wallet WAL2 = Wallet.fromFile(walletfile); // get wallet address of the WAL2 using previously gained network ID (Backbone) WalletAddress getAddr2 = WAL2.getAddress(networkID); // print wallet address of the WAL2 wallet System.out.printf(getAddr2.toString()); }catch (IOException e) { e.printStackTrace();} ```