Installation and usage of the platform
How the JavaScript SDK works¶
Authorization in the blockchain¶
In order for an application user to interact with the blockchain, the user must be authorized on the network. To do this, the JavaScript SDK provides authorization service REST API methods that allow you to make a multi-level algorithm with all possible types of queries related to user authorization in the blockchain.
Authorization can be done both in the browser and in the Node.js environment.
When authorizing in a browser, the Fetch API interface is used.
For authorization via Node.js, the Axios HTTP client is used.
If the blockchain node used by the application uses the oAuth authorization method, it is recommended to use the api-token-refresher library for its authorization. This library automatically updates access tokens when their usage time expires. For more information about the oAuth authorization and the api-token-refresher library, see the Using the JS SDK in a node with oAuth authorization section.
Seed phrase generation¶
The JS SDK-based application can work with seed phrases in the following variants:
create a new randomized seed phrase;
create a seed phrase from an existing phrase;
encrypt the seed phrase with a password or decrypt it.
Examples of how the JS SDK works with seed phrases are given in the Variants of generation of a seed phrase and work with it in the JS SDK section.
Signing and sending transactions¶
For JS SDK-based applications, any platform transactions can be signed and sent to the blockchain. A list of all transactions is given in the Description of transactions.
The process of signing and sending transactions to the network is as follows:
The application initiates generation of a transaction.
All transaction fields are serialized into bytecode using the transactions-factory auxiliary component of the JS SDK.
The transaction is then signed using the signature-generator component with the user’s private key in the browser or in the Node.js environment. The transaction is signed using a POST request
/transactions/sign
.The JavaScript SDK sends a transaction to the blockchain using the POST request
/transactions/broadcast
.The application gets a response in the form of a transaction hash to a POST request.
Examples of signing and sending different types of transactions are given in the Creating and sending transactions with the use of the JS SDK section.
Cryptographic node methods used by the JavaScript SDK¶
Three cryptographic methods are available for the JavaScript SDK:
crypto/encryptCommon
– data encryption with a single CEK key for all recipients, which in turn is wrapped by unique KEK keys for each recipient;crypto/encryptSeparate
– separate text encryption with a unique key for each recipient;crypto/decrypt
– data decryption, provided that the key of the message recipient is in the keystore of the node.