locuschain-lib 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +149 -0
- package/dist/lclib.d.ts +1 -0
- package/dist/lclib.js +669 -0
- package/dist/types.d.ts +9 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# locuschain-lib
|
|
2
|
+
---
|
|
3
|
+
This is a library that includes functions necessary for applying the `Locus Chain` to your service. The following features are included:
|
|
4
|
+
|
|
5
|
+
- Generate or load keys.
|
|
6
|
+
- Convert to data types used in Locus Chain.
|
|
7
|
+
- Validate transactions.
|
|
8
|
+
- Encode data.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```shell
|
|
13
|
+
npm i locuschain-lib
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
LocusLib.`function`(`params`)
|
|
19
|
+
|
|
20
|
+
- **function:** Function
|
|
21
|
+
- **params:** Parameter
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { LocusLib } from 'locuschain-lib';
|
|
25
|
+
const result = await LocusLib.GetLibraryVersions()
|
|
26
|
+
console.log(result)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
:::tip
|
|
30
|
+
All functions are asynchronous. Use await before them or use then to receive the result.
|
|
31
|
+
:::
|
|
32
|
+
|
|
33
|
+
You can find the list of functions and detailed descriptions in the official Locus Chain documentation.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MerkleProof, ParamTxData } from './types.ts';
|
|
2
|
+
export declare class LocusLib {
|
|
3
|
+
static callWasm(wasmCmd: string, wasmParams: any): Promise<unknown>;
|
|
4
|
+
static GetLibraryVersions(): Promise<unknown>;
|
|
5
|
+
static CreateAccountAndKeystore(passwordMaster: string, passwordNormal: string, mkeyAlgoNormal: string, nkeyAlgoNormal: string): Promise<unknown>;
|
|
6
|
+
static CreateNormalKey(addrStr: any, keyAlgo: string): Promise<unknown>;
|
|
7
|
+
static CreateMasterKeystore(AddrStr: any, Password: any, MskStr: any, MpkStr: any): Promise<unknown>;
|
|
8
|
+
static CreateNormalKeystore(AddrStr: any, Password: any, NskStr: any, NpkStr: any, MpkStr?: any, KeySign?: any): Promise<unknown>;
|
|
9
|
+
static LoadMasterKeystore(PassStr: string, KsJson: string): Promise<unknown>;
|
|
10
|
+
static LoadNormalKeystore(PassStr: string, KsJson: string): Promise<unknown>;
|
|
11
|
+
static ConvertToData(value: string, valueType: number): Promise<unknown>;
|
|
12
|
+
static ConvertDataTo(dataString: string, retType: number): Promise<unknown>;
|
|
13
|
+
static ConvertStringToData(str: string): Promise<unknown>;
|
|
14
|
+
static ConvertDataToString(dataString: string): Promise<unknown>;
|
|
15
|
+
static ConvertAddressToHex(addr: string): Promise<unknown>;
|
|
16
|
+
static ConvertHexToAddress(hexString: string): Promise<unknown>;
|
|
17
|
+
static ConvertAddressToData(addr: string): Promise<unknown>;
|
|
18
|
+
static ConvertDataToAddress(dataString: string): Promise<unknown>;
|
|
19
|
+
static ConvertBase32ToHex(encoded: string): Promise<unknown>;
|
|
20
|
+
static ConvertHexToBase32(hexString: string): Promise<unknown>;
|
|
21
|
+
static ConvertHexToData(encoded: string): Promise<unknown>;
|
|
22
|
+
static ConvertDataToHex(dataString: string): Promise<unknown>;
|
|
23
|
+
static ConvertBase32ToData(encoded: string): Promise<unknown>;
|
|
24
|
+
static ConvertDataToBase32(dataString: string): Promise<unknown>;
|
|
25
|
+
static SignByMasterKey(Msk: string, Message: string): Promise<unknown>;
|
|
26
|
+
static Sign(Sk: string, Message: string): Promise<unknown>;
|
|
27
|
+
static Verify(Pk: string, Message: string, Sig: string): Promise<unknown>;
|
|
28
|
+
static VerifyTx(jsonTx: string): Promise<unknown>;
|
|
29
|
+
static CompileCoreScript(Code: string): Promise<unknown>;
|
|
30
|
+
static DisCompileCoreScript(Code: string): Promise<unknown>;
|
|
31
|
+
static TestCoreScript(ScriptProvide: string, ScriptAccept: string, TxDataProvide: ParamTxData, TxDataAccept: ParamTxData): Promise<unknown>;
|
|
32
|
+
static GetDefFromCoreScript(Code: string): Promise<unknown>;
|
|
33
|
+
static EncodeTxNumber(Number: string, Type: number): Promise<unknown>;
|
|
34
|
+
static EncodeTxCurrency(Currency: string): Promise<unknown>;
|
|
35
|
+
static Hash(Data: string, Type: number): Promise<unknown>;
|
|
36
|
+
static VerifyMerkleProof(Proof: MerkleProof, Hash: string, GoalHash: string): Promise<unknown>;
|
|
37
|
+
static CalculateTxLinkHash(Tx: string): Promise<unknown>;
|
|
38
|
+
static DecodeTxs(Txs: string[]): Promise<unknown>;
|
|
39
|
+
static GzipAndEncode(str: string): Promise<unknown>;
|
|
40
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LocusLib = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const lclib_js_1 = require("./lclib.js");
|
|
7
|
+
(0, lclib_js_1.loadLocusLibrary)().then((res) => {
|
|
8
|
+
});
|
|
9
|
+
class LocusLib {
|
|
10
|
+
static callWasm(wasmCmd, wasmParams) {
|
|
11
|
+
return new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
if (Array.isArray(wasmParams)) {
|
|
13
|
+
wasmParams = wasmParams[0];
|
|
14
|
+
}
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
if (typeof globalThis['CallLclib'] !== "function")
|
|
17
|
+
return;
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const resultString = yield globalThis['CallLclib'](wasmCmd, JSON.stringify(wasmParams));
|
|
20
|
+
const result = JSON.parse(resultString);
|
|
21
|
+
if (result.Error && result.Error.Code != 0) {
|
|
22
|
+
reject(result.Error);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
resolve(result.Result);
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
//=================================================================================
|
|
30
|
+
static GetLibraryVersions() {
|
|
31
|
+
return LocusLib.callWasm('GetLibraryVersions', {});
|
|
32
|
+
}
|
|
33
|
+
static CreateAccountAndKeystore(passwordMaster, passwordNormal, mkeyAlgoNormal, nkeyAlgoNormal) {
|
|
34
|
+
return LocusLib.callWasm('CreateAccountAndKeystore', {
|
|
35
|
+
passwordMaster,
|
|
36
|
+
passwordNormal,
|
|
37
|
+
mkeyAlgoNormal,
|
|
38
|
+
nkeyAlgoNormal
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
static CreateNormalKey(addrStr, keyAlgo) {
|
|
42
|
+
return LocusLib.callWasm('CreateNormalKey', { addrStr, keyAlgo });
|
|
43
|
+
}
|
|
44
|
+
static CreateMasterKeystore(AddrStr, Password, MskStr, MpkStr) {
|
|
45
|
+
return LocusLib.callWasm('CreateMasterKeystore', { AddrStr, Password, MskStr, MpkStr });
|
|
46
|
+
}
|
|
47
|
+
static CreateNormalKeystore(AddrStr, Password, NskStr, NpkStr, MpkStr = '', KeySign = '') {
|
|
48
|
+
return LocusLib.callWasm('CreateNormalKeystore', { AddrStr, Password, NskStr, NpkStr, MpkStr, KeySign });
|
|
49
|
+
}
|
|
50
|
+
static LoadMasterKeystore(PassStr, KsJson) {
|
|
51
|
+
return LocusLib.callWasm('LoadMasterKeystore', { PassStr, KsJson });
|
|
52
|
+
}
|
|
53
|
+
static LoadNormalKeystore(PassStr, KsJson) {
|
|
54
|
+
return LocusLib.callWasm('LoadNormalKeystore', { PassStr, KsJson });
|
|
55
|
+
}
|
|
56
|
+
static ConvertToData(value, valueType) {
|
|
57
|
+
return LocusLib.callWasm('ConvertToData', { value, valueType });
|
|
58
|
+
}
|
|
59
|
+
static ConvertDataTo(dataString, retType) {
|
|
60
|
+
return LocusLib.callWasm('ConvertDataTo', { dataString, retType });
|
|
61
|
+
}
|
|
62
|
+
static ConvertStringToData(str) {
|
|
63
|
+
return LocusLib.callWasm('ConvertStringToData', str);
|
|
64
|
+
}
|
|
65
|
+
static ConvertDataToString(dataString) {
|
|
66
|
+
return LocusLib.callWasm('ConvertDataToString', dataString);
|
|
67
|
+
}
|
|
68
|
+
static ConvertAddressToHex(addr) {
|
|
69
|
+
return LocusLib.callWasm('ConvertAddressToHex', addr);
|
|
70
|
+
}
|
|
71
|
+
static ConvertHexToAddress(hexString) {
|
|
72
|
+
return LocusLib.callWasm('ConvertHexToAddress', hexString);
|
|
73
|
+
}
|
|
74
|
+
static ConvertAddressToData(addr) {
|
|
75
|
+
return LocusLib.callWasm('ConvertAddressToData', addr);
|
|
76
|
+
}
|
|
77
|
+
static ConvertDataToAddress(dataString) {
|
|
78
|
+
return LocusLib.callWasm('ConvertDataToAddress', dataString);
|
|
79
|
+
}
|
|
80
|
+
static ConvertBase32ToHex(encoded) {
|
|
81
|
+
return LocusLib.callWasm('ConvertBase32ToHex', encoded);
|
|
82
|
+
}
|
|
83
|
+
static ConvertHexToBase32(hexString) {
|
|
84
|
+
return LocusLib.callWasm('ConvertHexToBase32', hexString);
|
|
85
|
+
}
|
|
86
|
+
static ConvertHexToData(encoded) {
|
|
87
|
+
return LocusLib.callWasm('ConvertHexToData', encoded);
|
|
88
|
+
}
|
|
89
|
+
static ConvertDataToHex(dataString) {
|
|
90
|
+
return LocusLib.callWasm('ConvertDataToHex', dataString);
|
|
91
|
+
}
|
|
92
|
+
static ConvertBase32ToData(encoded) {
|
|
93
|
+
return LocusLib.callWasm('ConvertBase32ToData', encoded);
|
|
94
|
+
}
|
|
95
|
+
static ConvertDataToBase32(dataString) {
|
|
96
|
+
return LocusLib.callWasm('ConvertDataToBase32', dataString);
|
|
97
|
+
}
|
|
98
|
+
static SignByMasterKey(Msk, Message) {
|
|
99
|
+
return LocusLib.callWasm('SignByMasterKey', { Msk, Message });
|
|
100
|
+
}
|
|
101
|
+
static Sign(Sk, Message) {
|
|
102
|
+
return LocusLib.callWasm('Sign', { Sk, Message });
|
|
103
|
+
}
|
|
104
|
+
static Verify(Pk, Message, Sig) {
|
|
105
|
+
return LocusLib.callWasm('Verify', { Pk, Message, Sig });
|
|
106
|
+
}
|
|
107
|
+
static VerifyTx(jsonTx) {
|
|
108
|
+
return LocusLib.callWasm('VerifyTx', jsonTx);
|
|
109
|
+
}
|
|
110
|
+
static CompileCoreScript(Code) {
|
|
111
|
+
return LocusLib.callWasm('CompileCoreScript', { Code });
|
|
112
|
+
}
|
|
113
|
+
static DisCompileCoreScript(Code) {
|
|
114
|
+
return LocusLib.callWasm('DisCompileCoreScript', { Code });
|
|
115
|
+
}
|
|
116
|
+
static TestCoreScript(ScriptProvide, ScriptAccept, TxDataProvide, TxDataAccept) {
|
|
117
|
+
return LocusLib.callWasm('TestCoreScript', {
|
|
118
|
+
ScriptProvide,
|
|
119
|
+
ScriptAccept,
|
|
120
|
+
TxDataProvide,
|
|
121
|
+
TxDataAccept
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
static GetDefFromCoreScript(Code) {
|
|
125
|
+
return LocusLib.callWasm('GetDefFromCoreScript', { Code });
|
|
126
|
+
}
|
|
127
|
+
static EncodeTxNumber(Number, Type) {
|
|
128
|
+
return LocusLib.callWasm('EncodeTxNumber', { Number, Type });
|
|
129
|
+
}
|
|
130
|
+
static EncodeTxCurrency(Currency) {
|
|
131
|
+
return LocusLib.callWasm('EncodeTxCurrency', { Currency });
|
|
132
|
+
}
|
|
133
|
+
static Hash(Data, Type) {
|
|
134
|
+
return LocusLib.callWasm('Hash', { Data, Type });
|
|
135
|
+
}
|
|
136
|
+
static VerifyMerkleProof(Proof, Hash, GoalHash) {
|
|
137
|
+
return LocusLib.callWasm('VerifyMerkleProof', { Proof, Hash, GoalHash });
|
|
138
|
+
}
|
|
139
|
+
static CalculateTxLinkHash(Tx) {
|
|
140
|
+
return LocusLib.callWasm('CalculateTxLinkHash', { Tx });
|
|
141
|
+
}
|
|
142
|
+
static DecodeTxs(Txs) {
|
|
143
|
+
return LocusLib.callWasm('DecodeTxs', { Txs });
|
|
144
|
+
}
|
|
145
|
+
static GzipAndEncode(str) {
|
|
146
|
+
return LocusLib.callWasm('GzipAndEncode', str);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.LocusLib = LocusLib;
|
package/dist/lclib.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function loadLocusLibrary(): Promise<any>;
|