Locus Library
We provide a library that includes the functions required to integrate Locus Chain into your service. The library includes the following features:
- Generate or load keys.
- Convert data formats.
- Verify transactions.
- Sign with private key.
Installation Guide
- Javascript
npm i locuschain-lib
Usage Guide
LocusLib.function(param1, param2, ... )
- function: Function Name
- param: Parameters
- Javascript
import { LocusLib } from 'locuschain-lib';
const result = await LocusLib.GetLibraryVersions()
console.log(result)
All functions are asynchronous. Use await before the function or .then to receive the result.
Functions
GetLibraryVersions
GetLibraryVersion returns the versions of this wasm library.
Input
GetLibraryVersions( )
[None]
Output
| Key | Type | Description |
|---|---|---|
| LibraryVersion | int | Library Version |
| KeyStoreVersion | int | Key Store Version |
| KeyStoreVersionMin | int | Minimum compatible Key Store version |
| GoBuildVersion | string | The Golang version used to build the library |
CreateAccountAndKeystore
creates two separate keystore files for master key and normal key.
Input
CreateAccountAndKeystore( PwdMaster, PwdNormal, MasterKeyAlgo, NormalKeyAlgo )
| Key | Type | Description |
|---|---|---|
| PwdMaster | string | Master Key Password |
| PwdNormal | string | Normal Key Password |
| MasterKeyAlgo | string | Master Key Algorithm |
| NormalKeyAlgo | string | Normal Key Algorithm |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Master and Normal Keystore string |
CreateNormalKey
creates a new normal key for the given address.
Input
CreateNormalKey( Addr, KeyAlgorithm )
| Key | Type | Description |
|---|---|---|
| addr | string | Address |
| KeyAlgorithm | string | Normal Key Algorithm |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Normal Key string |
CreateMasterKeystore
creates a keystore of normal key for the given address.
Input
CreateMasterKeystore( Addr, Password, MskStr, MpkStr )
| Key | Type | Description |
|---|---|---|
| Addr | string | Address |
| Password | string | Master Key Password |
| MskStr | string | Master Secret Key |
| MpkStr | string | Master Public Key |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Master Keystore string |
CreateNormalKeystore
creates a keystore of normal key for the given address.
Input
CreateNormalKeystore( Addr, Password, NskStr, NpkStr, MpkStr, KeySign )
| Key | Type | Description |
|---|---|---|
| Addr | string | Address |
| Password | string | Normal Key Password |
| NskStr | string | Normal Secret Key |
| NpkStr | string | Normal Public Key |
| MpkStr | string | Master Public Key |
| KeySign | string | Key Sign |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Normal Keystore string |
LoadMasterKeystore
returns the master key from master keystore.
Input
LoadMasterKeystore( Password, KsJson )
| Key | Type | Description |
|---|---|---|
| Password | string | Master Key Password |
| KsJson | string | Master Keystore string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Master Key string |
LoadNormalKeystore
returns the normal key from normal keystore.
Input
LoadNormalKeystore ( Password, KsJson )
| Key | Type | Description |
|---|---|---|
| Password | string | Normal Key Password |
| KsJson | string | Normal Keystore string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Normal Key string |
ConvertToData
decodes various values to default encoding (base64)
Input
ConvertToData( Value, ValueType )
| Key | Type | Description |
|---|---|---|
| Value | string | |
| ValueType | int | valueType : 0(raw string), 1(hex), 2(crc16-base32), 3(base64) |
Output
| Key | Type | Description |
|---|---|---|
| - | string |
ConvertDataTo
converts default encoded(base64) value to various types
Input
ConvertDataTo( Value, ValueType )
| Key | Type | Description |
|---|---|---|
| Value | string | |
| ValueType | int | valueType : 0(raw string), 1(hex), 2(crc16-base32), 3(base64) |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertStringToData
decodes string values to default encoding (base64)
Input
ConvertStringToData( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertDataToString
decodes default encoded (base64) value to string values.
Input
ConvertDataToString ( Value )
| Key | Type | Description |
|---|---|---|
| value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertAddressToHex
decodes the base32-encoded address to hex value.
Input
ConvertAddressToHex( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertHexToAddress
encodes hex value to the base32-encoded address.
Input
ConvertHexToAddress( Value )
| Key | Type | Description |
|---|---|---|
| value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertAddressToData
decodes the base32-encoded address to default encoding.
Input
ConvertAddressToData( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertDataToAddress
encodes default encoded value to the base32-encoded address.
Input
ConvertDataToAddress( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertBase32ToHex
decodes the base32-encoded values to hex value.
Input
ConvertBase32ToHex( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertHexToBase32
encodes hex value to the base32-encoded values.
Input
ConvertHexToBase32( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertHexToData
decodes the hex-encoded values to default encoding (base64)
Input
ConvertHexToData( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertDataToHex
encodes default encoded (base64) value to the hex-encoded values.
Input
ConvertDataToHex( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertBase32ToData
decodes the base32-encoded values to default encoding (base64) ConvertBase32ToData( Value )
Input
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
ConvertDataToBase32
encodes default encoded (base64) value to the base32-encoded values.
Input
ConvertDataToBase32( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
SignByMasterKey
produce a signature with the private master key and the message.
Input
SignByMasterKey ( Msk, Message )
| Key | Type | Description |
|---|---|---|
| Msk | string | Master Secret Key |
| Message | string | Message to Sign |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
Sign
produces a signature with the normal secret key and the message.
Input
Sign( Sk, Message )
| Key | Type | Description |
|---|---|---|
| Sk | string | Normal Secret Key |
| Message | string | Message to Sign |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
Verify
returns the result of verifying the signature with message and normal public key.
Input
Verify( Pk, Message, Sig )
| Key | Type | Description |
|---|---|---|
| Pk | string | Normal Public Key |
| Message | string | Message to Verify |
| Sig | string | Signature to Verify |
Output
| Key | Type | Description |
|---|---|---|
| - | boolean | Result |
VerifyTx
verifies all types of transactions that made by RPC.
Input
VerifyTx( JsonTx )
| Key | Type | Description |
|---|---|---|
| JsonTx | string |
Output
| Key | Type | Description |
|---|---|---|
| - | hash | Result |
CompileCoreScript
CompileCoreScript compiles core script source code to byte code.
Input
CompileCoreScript( Code )
| Key | Type | Description |
|---|---|---|
| Code | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
DisCompileCoreScript
DisCompileCoreScript discompiles byte code of core script. DisCompileCoreScript does not detect synstax errors.
Input
DisCompileCoreScript( Code )
| Key | Type | Description |
|---|---|---|
| Code | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
TestCoreScript
TestCoreScript tests ScriptProvide & ScriptAccept with TxDataProvide & TxDataAccept.
Input
TestCoreScript( ScriptProvide, ScriptAccept, TxDataProvide, TxDataAccept )
| Key | Type | Description |
|---|---|---|
| ScriptProvide | string | Provide Script Code |
| ScriptAccept | string | Accept Script Code |
| TxDataProvide | types.ParamTxData | Parameter of the Provide Script |
| TxDataAccept | types.ParamTxData | Parameter of the Accept Script |
types.ParamTxData
| Key | Type | Description |
|---|---|---|
| Round | uint32 | |
| Height | int32 | |
| Args | []string |
Output
| Key | Type | Description |
|---|---|---|
| - | boolean | Result |
GetDefFromCoreScript
GetDefFromCoreScript get definitions from byte code.
Input
GetDefFromCoreScript ( Code )
| Key | Type | Description |
|---|---|---|
| Code | string |
Output
| Key | Type | Description |
|---|---|---|
| - | json string | Result |
EncodeTxNumber
EncodeTxNumber encodes number type data to []byte.
Input
EncodeTxNumber ( Number, Type )
| Key | Type | Description |
|---|---|---|
| Number | string | |
| Type | int |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
EncodeTxCurrency
EncodeTxCurrency encodes currency to []byte.
Input
EncodeTxCurrency( Currency )
| Key | Type | Description |
|---|---|---|
| Currency | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
Hash
Hash hashes data by hash-type.
Input
Hash ( Value, Type )
| Key | Type | Description |
|---|---|---|
| Value | string | |
| Type | int |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
VerifyMerkleProof
VerifyMerkleProof verifies Proof with Hash & GoalHash.
Input
VerifyMerkleProof ( Proof, Hash, GoalHash )
| Key | Type | Description |
|---|---|---|
| Proof | types.MerkleProof | |
| Hash | string | |
| GoalHash | string |
types.MerkleProof
| Key | Type | Description |
|---|---|---|
| Positions | []uint16 | |
| Siblings | []32byte |
Output
| Key | Type | Description |
|---|---|---|
| bool | Result |
CalculateTxLinkHash
Calculating the TxLink hash.
Input
CalculateTxLinkHash( Tx )
| Key | Type | Description |
|---|---|---|
| Tx | string | Tx string |
Output
| Key | Type | Description |
|---|---|---|
| - | hash | Result |
DecodeTxs
DecodeTxs decods base64-encoded transactions that was downloaded from node.
Input
DecodeTxs ( Txs )
| Key | Type | Description |
|---|---|---|
| Txs | []string | Tx string array |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
GzipAndEncode
Compress the string and then encode it in base64.
Input
GzipAndEncode ( Value )
| Key | Type | Description |
|---|---|---|
| Value | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |