koilib 2.0.0 → 2.4.0
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 +49 -7
- package/dist/koinos.js +4910 -4762
- package/dist/koinos.min.js +1 -1
- package/dist/koinos.min.js.LICENSE.txt +1 -10
- package/lib/Contract.d.ts +48 -140
- package/lib/Contract.js +82 -156
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +2 -5
- package/lib/Provider.js +42 -11
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +81 -0
- package/lib/Serializer.js +169 -0
- package/lib/Serializer.js.map +1 -0
- package/lib/Signer.d.ts +130 -24
- package/lib/Signer.js +162 -59
- package/lib/Signer.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -0
- package/lib/index2.js.map +1 -1
- package/lib/interface.d.ts +161 -24
- package/lib/{krc20-proto.json → jsonDescriptors/krc20-proto.json} +1 -1
- package/lib/{protocol-proto.json → jsonDescriptors/protocol-proto.json} +22 -18
- package/lib/utils.d.ts +270 -2
- package/lib/utils.js +72 -34
- package/lib/utils.js.map +1 -1
- package/package.json +9 -5
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"nested": {
|
|
10
10
|
"contract_call_bundle": {
|
|
11
11
|
"fields": {
|
|
12
|
-
"
|
|
12
|
+
"contract_id": {
|
|
13
13
|
"type": "bytes",
|
|
14
14
|
"id": 1,
|
|
15
15
|
"options": {
|
|
16
16
|
"(koinos_bytes_type)": "CONTRACT_ID"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
-
"
|
|
19
|
+
"entry_point": {
|
|
20
20
|
"type": "uint32",
|
|
21
21
|
"id": 2
|
|
22
22
|
}
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"system_call_target": {
|
|
26
26
|
"oneofs": {
|
|
27
27
|
"target": {
|
|
28
|
-
"oneof": ["
|
|
28
|
+
"oneof": ["thunk_id", "system_call_bundle"]
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"fields": {
|
|
32
|
-
"
|
|
32
|
+
"thunk_id": {
|
|
33
33
|
"type": "uint32",
|
|
34
34
|
"id": 1
|
|
35
35
|
},
|
|
36
|
-
"
|
|
36
|
+
"system_call_bundle": {
|
|
37
37
|
"type": "contract_call_bundle",
|
|
38
38
|
"id": 2
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"upload_contract_operation": {
|
|
43
43
|
"fields": {
|
|
44
|
-
"
|
|
44
|
+
"contract_id": {
|
|
45
45
|
"type": "bytes",
|
|
46
46
|
"id": 1,
|
|
47
47
|
"options": {
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
},
|
|
57
57
|
"call_contract_operation": {
|
|
58
58
|
"fields": {
|
|
59
|
-
"
|
|
59
|
+
"contract_id": {
|
|
60
60
|
"type": "bytes",
|
|
61
61
|
"id": 1,
|
|
62
62
|
"options": {
|
|
63
63
|
"(koinos_bytes_type)": "CONTRACT_ID"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"
|
|
66
|
+
"entry_point": {
|
|
67
67
|
"type": "uint32",
|
|
68
68
|
"id": 2
|
|
69
69
|
},
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"set_system_call_operation": {
|
|
77
77
|
"fields": {
|
|
78
|
-
"
|
|
78
|
+
"call_id": {
|
|
79
79
|
"type": "uint32",
|
|
80
80
|
"id": 1
|
|
81
81
|
},
|
|
@@ -88,19 +88,23 @@
|
|
|
88
88
|
"operation": {
|
|
89
89
|
"oneofs": {
|
|
90
90
|
"op": {
|
|
91
|
-
"oneof": [
|
|
91
|
+
"oneof": [
|
|
92
|
+
"upload_contract",
|
|
93
|
+
"call_contract",
|
|
94
|
+
"set_system_call"
|
|
95
|
+
]
|
|
92
96
|
}
|
|
93
97
|
},
|
|
94
98
|
"fields": {
|
|
95
|
-
"
|
|
99
|
+
"upload_contract": {
|
|
96
100
|
"type": "upload_contract_operation",
|
|
97
101
|
"id": 1
|
|
98
102
|
},
|
|
99
|
-
"
|
|
103
|
+
"call_contract": {
|
|
100
104
|
"type": "call_contract_operation",
|
|
101
105
|
"id": 2
|
|
102
106
|
},
|
|
103
|
-
"
|
|
107
|
+
"set_system_call": {
|
|
104
108
|
"type": "set_system_call_operation",
|
|
105
109
|
"id": 3
|
|
106
110
|
}
|
|
@@ -108,7 +112,7 @@
|
|
|
108
112
|
},
|
|
109
113
|
"active_transaction_data": {
|
|
110
114
|
"fields": {
|
|
111
|
-
"
|
|
115
|
+
"rc_limit": {
|
|
112
116
|
"type": "uint64",
|
|
113
117
|
"id": 1,
|
|
114
118
|
"options": {
|
|
@@ -149,7 +153,7 @@
|
|
|
149
153
|
"type": "bytes",
|
|
150
154
|
"id": 3
|
|
151
155
|
},
|
|
152
|
-
"
|
|
156
|
+
"signature_data": {
|
|
153
157
|
"type": "bytes",
|
|
154
158
|
"id": 4
|
|
155
159
|
}
|
|
@@ -157,11 +161,11 @@
|
|
|
157
161
|
},
|
|
158
162
|
"active_block_data": {
|
|
159
163
|
"fields": {
|
|
160
|
-
"
|
|
164
|
+
"transaction_merkle_root": {
|
|
161
165
|
"type": "bytes",
|
|
162
166
|
"id": 1
|
|
163
167
|
},
|
|
164
|
-
"
|
|
168
|
+
"passive_data_merkle_root": {
|
|
165
169
|
"type": "bytes",
|
|
166
170
|
"id": 2
|
|
167
171
|
},
|
|
@@ -220,7 +224,7 @@
|
|
|
220
224
|
"type": "bytes",
|
|
221
225
|
"id": 4
|
|
222
226
|
},
|
|
223
|
-
"
|
|
227
|
+
"signature_data": {
|
|
224
228
|
"type": "bytes",
|
|
225
229
|
"id": 5
|
|
226
230
|
},
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi } from "./
|
|
1
|
+
import { Abi } from "./interface";
|
|
2
2
|
/**
|
|
3
3
|
* Converts an hex string to Uint8Array
|
|
4
4
|
*/
|
|
@@ -32,7 +32,6 @@ export declare function decodeBase64(bs64: string): Uint8Array;
|
|
|
32
32
|
* wallet import format (WIF).
|
|
33
33
|
*/
|
|
34
34
|
export declare function bitcoinEncode(buffer: Uint8Array, type: "public" | "private", compressed?: boolean): string;
|
|
35
|
-
export declare function copyUint8Array(source: Uint8Array, target: Uint8Array, targetStart: number, sourceStart: number, sourceEnd: number): void;
|
|
36
35
|
/**
|
|
37
36
|
* Decodes a public or private key formatted in base58 using
|
|
38
37
|
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
@@ -48,7 +47,276 @@ export declare function bitcoinDecode(value: string): Uint8Array;
|
|
|
48
47
|
* address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
|
|
49
48
|
*/
|
|
50
49
|
export declare function bitcoinAddress(publicKey: Uint8Array): string;
|
|
50
|
+
/**
|
|
51
|
+
* Function to format a number in a decimal point number
|
|
52
|
+
* @example
|
|
53
|
+
* ```js
|
|
54
|
+
* const amount = formatUnits("123456", 8);
|
|
55
|
+
* console.log(amount);
|
|
56
|
+
* // '0.00123456'
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function formatUnits(value: string | number | bigint, decimals: number): string;
|
|
60
|
+
/**
|
|
61
|
+
* Function to format a decimal point number in an integer
|
|
62
|
+
* @example
|
|
63
|
+
* ```js
|
|
64
|
+
* const amount = parseUnits("0.00123456", 8);
|
|
65
|
+
* console.log(amount);
|
|
66
|
+
* // '123456'
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseUnits(value: string, decimals: number): string;
|
|
51
70
|
/**
|
|
52
71
|
* ABI for tokens
|
|
53
72
|
*/
|
|
54
73
|
export declare const Krc20Abi: Abi;
|
|
74
|
+
export declare const ProtocolTypes: {
|
|
75
|
+
nested: {
|
|
76
|
+
koinos: {
|
|
77
|
+
nested: {
|
|
78
|
+
protocol: {
|
|
79
|
+
options: {
|
|
80
|
+
go_package: string;
|
|
81
|
+
};
|
|
82
|
+
nested: {
|
|
83
|
+
contract_call_bundle: {
|
|
84
|
+
fields: {
|
|
85
|
+
contract_id: {
|
|
86
|
+
type: string;
|
|
87
|
+
id: number;
|
|
88
|
+
options: {
|
|
89
|
+
"(koinos_bytes_type)": string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
entry_point: {
|
|
93
|
+
type: string;
|
|
94
|
+
id: number;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
system_call_target: {
|
|
99
|
+
oneofs: {
|
|
100
|
+
target: {
|
|
101
|
+
oneof: string[];
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
fields: {
|
|
105
|
+
thunk_id: {
|
|
106
|
+
type: string;
|
|
107
|
+
id: number;
|
|
108
|
+
};
|
|
109
|
+
system_call_bundle: {
|
|
110
|
+
type: string;
|
|
111
|
+
id: number;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
upload_contract_operation: {
|
|
116
|
+
fields: {
|
|
117
|
+
contract_id: {
|
|
118
|
+
type: string;
|
|
119
|
+
id: number;
|
|
120
|
+
options: {
|
|
121
|
+
"(koinos_bytes_type)": string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
bytecode: {
|
|
125
|
+
type: string;
|
|
126
|
+
id: number;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
call_contract_operation: {
|
|
131
|
+
fields: {
|
|
132
|
+
contract_id: {
|
|
133
|
+
type: string;
|
|
134
|
+
id: number;
|
|
135
|
+
options: {
|
|
136
|
+
"(koinos_bytes_type)": string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
entry_point: {
|
|
140
|
+
type: string;
|
|
141
|
+
id: number;
|
|
142
|
+
};
|
|
143
|
+
args: {
|
|
144
|
+
type: string;
|
|
145
|
+
id: number;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
set_system_call_operation: {
|
|
150
|
+
fields: {
|
|
151
|
+
call_id: {
|
|
152
|
+
type: string;
|
|
153
|
+
id: number;
|
|
154
|
+
};
|
|
155
|
+
target: {
|
|
156
|
+
type: string;
|
|
157
|
+
id: number;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
operation: {
|
|
162
|
+
oneofs: {
|
|
163
|
+
op: {
|
|
164
|
+
oneof: string[];
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
fields: {
|
|
168
|
+
upload_contract: {
|
|
169
|
+
type: string; /**
|
|
170
|
+
* Decodes a public or private key formatted in base58 using
|
|
171
|
+
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
172
|
+
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
173
|
+
*
|
|
174
|
+
* For private keys this encode is also known as
|
|
175
|
+
* wallet import format (WIF).
|
|
176
|
+
*/
|
|
177
|
+
id: number;
|
|
178
|
+
};
|
|
179
|
+
call_contract: {
|
|
180
|
+
type: string;
|
|
181
|
+
id: number;
|
|
182
|
+
};
|
|
183
|
+
set_system_call: {
|
|
184
|
+
type: string;
|
|
185
|
+
id: number;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
active_transaction_data: {
|
|
190
|
+
fields: {
|
|
191
|
+
rc_limit: {
|
|
192
|
+
type: string;
|
|
193
|
+
id: number;
|
|
194
|
+
options: {
|
|
195
|
+
jstype: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
nonce: {
|
|
199
|
+
type: string;
|
|
200
|
+
id: number;
|
|
201
|
+
options: {
|
|
202
|
+
jstype: string;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
operations: {
|
|
206
|
+
rule: string;
|
|
207
|
+
type: string;
|
|
208
|
+
id: number;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
passive_transaction_data: {
|
|
213
|
+
fields: {};
|
|
214
|
+
};
|
|
215
|
+
transaction: {
|
|
216
|
+
fields: {
|
|
217
|
+
id: {
|
|
218
|
+
type: string;
|
|
219
|
+
id: number;
|
|
220
|
+
options: {
|
|
221
|
+
"(koinos_bytes_type)": string;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
active: {
|
|
225
|
+
type: string;
|
|
226
|
+
id: number;
|
|
227
|
+
};
|
|
228
|
+
passive: {
|
|
229
|
+
type: string;
|
|
230
|
+
id: number;
|
|
231
|
+
};
|
|
232
|
+
signature_data: {
|
|
233
|
+
type: string;
|
|
234
|
+
id: number;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
active_block_data: {
|
|
239
|
+
fields: {
|
|
240
|
+
transaction_merkle_root: {
|
|
241
|
+
type: string;
|
|
242
|
+
id: number;
|
|
243
|
+
};
|
|
244
|
+
passive_data_merkle_root: {
|
|
245
|
+
type: string;
|
|
246
|
+
id: number;
|
|
247
|
+
};
|
|
248
|
+
signer: {
|
|
249
|
+
type: string;
|
|
250
|
+
id: number;
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
passive_block_data: {
|
|
255
|
+
fields: {};
|
|
256
|
+
};
|
|
257
|
+
block_header: {
|
|
258
|
+
fields: {
|
|
259
|
+
previous: {
|
|
260
|
+
type: string;
|
|
261
|
+
id: number;
|
|
262
|
+
options: {
|
|
263
|
+
"(koinos_bytes_type)": string;
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
height: {
|
|
267
|
+
type: string;
|
|
268
|
+
id: number;
|
|
269
|
+
options: {
|
|
270
|
+
jstype: string;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
timestamp: {
|
|
274
|
+
type: string;
|
|
275
|
+
id: number;
|
|
276
|
+
options: {
|
|
277
|
+
jstype: string;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
block: {
|
|
283
|
+
fields: {
|
|
284
|
+
id: {
|
|
285
|
+
type: string;
|
|
286
|
+
id: number;
|
|
287
|
+
options: {
|
|
288
|
+
"(koinos_bytes_type)": string;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
header: {
|
|
292
|
+
type: string;
|
|
293
|
+
id: number;
|
|
294
|
+
};
|
|
295
|
+
active: {
|
|
296
|
+
type: string;
|
|
297
|
+
id: number;
|
|
298
|
+
};
|
|
299
|
+
passive: {
|
|
300
|
+
type: string;
|
|
301
|
+
id: number;
|
|
302
|
+
};
|
|
303
|
+
signature_data: {
|
|
304
|
+
type: string;
|
|
305
|
+
id: number;
|
|
306
|
+
};
|
|
307
|
+
transactions: {
|
|
308
|
+
rule: string;
|
|
309
|
+
type: string;
|
|
310
|
+
id: number;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
block_receipt: {
|
|
315
|
+
fields: {};
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
};
|
package/lib/utils.js
CHANGED
|
@@ -22,11 +22,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Krc20Abi = exports.
|
|
25
|
+
exports.ProtocolTypes = exports.Krc20Abi = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.bitcoinEncode = exports.decodeBase64 = exports.encodeBase64 = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
|
|
26
26
|
const multibase = __importStar(require("multibase"));
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const krc20_proto_json_1 = __importDefault(require("./krc20-proto.json"));
|
|
27
|
+
const sha256_1 = require("@noble/hashes/lib/sha256");
|
|
28
|
+
const ripemd160_1 = require("@noble/hashes/lib/ripemd160");
|
|
29
|
+
const krc20_proto_json_1 = __importDefault(require("./jsonDescriptors/krc20-proto.json"));
|
|
30
|
+
const protocol_proto_json_1 = __importDefault(require("./jsonDescriptors/protocol-proto.json"));
|
|
30
31
|
/**
|
|
31
32
|
* Converts an hex string to Uint8Array
|
|
32
33
|
*/
|
|
@@ -111,22 +112,15 @@ function bitcoinEncode(buffer, type, compressed = false) {
|
|
|
111
112
|
prefixBuffer[0] = 128;
|
|
112
113
|
}
|
|
113
114
|
prefixBuffer.set(buffer, 1);
|
|
114
|
-
const firstHash =
|
|
115
|
-
const doubleHash =
|
|
116
|
-
const checksum =
|
|
115
|
+
const firstHash = sha256_1.sha256(prefixBuffer);
|
|
116
|
+
const doubleHash = sha256_1.sha256(firstHash);
|
|
117
|
+
const checksum = new Uint8Array(4);
|
|
118
|
+
checksum.set(doubleHash.slice(0, 4));
|
|
117
119
|
bufferCheck.set(buffer, 1);
|
|
118
120
|
bufferCheck.set(checksum, offsetChecksum);
|
|
119
121
|
return encodeBase58(bufferCheck);
|
|
120
122
|
}
|
|
121
123
|
exports.bitcoinEncode = bitcoinEncode;
|
|
122
|
-
function copyUint8Array(source, target, targetStart, sourceStart, sourceEnd) {
|
|
123
|
-
for (let cursorSource = sourceStart; cursorSource < sourceEnd; cursorSource += 1) {
|
|
124
|
-
const cursorTarget = targetStart + cursorSource - sourceStart;
|
|
125
|
-
/* eslint-disable-next-line no-param-reassign */
|
|
126
|
-
target[cursorTarget] = source[cursorSource];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.copyUint8Array = copyUint8Array;
|
|
130
124
|
/**
|
|
131
125
|
* Decodes a public or private key formatted in base58 using
|
|
132
126
|
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
@@ -140,13 +134,13 @@ function bitcoinDecode(value) {
|
|
|
140
134
|
const privateKey = new Uint8Array(32);
|
|
141
135
|
const checksum = new Uint8Array(4);
|
|
142
136
|
// const prefix = buffer[0];
|
|
143
|
-
|
|
137
|
+
privateKey.set(buffer.slice(1, 33));
|
|
144
138
|
if (value[0] !== "5") {
|
|
145
139
|
// compressed
|
|
146
|
-
|
|
140
|
+
checksum.set(buffer.slice(34, 38));
|
|
147
141
|
}
|
|
148
142
|
else {
|
|
149
|
-
|
|
143
|
+
checksum.set(buffer.slice(33, 37));
|
|
150
144
|
}
|
|
151
145
|
// TODO: verify prefix and checksum
|
|
152
146
|
return privateKey;
|
|
@@ -158,11 +152,53 @@ exports.bitcoinDecode = bitcoinDecode;
|
|
|
158
152
|
* address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
|
|
159
153
|
*/
|
|
160
154
|
function bitcoinAddress(publicKey) {
|
|
161
|
-
const hash =
|
|
162
|
-
const hash160 =
|
|
155
|
+
const hash = sha256_1.sha256(publicKey);
|
|
156
|
+
const hash160 = ripemd160_1.ripemd160(hash);
|
|
163
157
|
return bitcoinEncode(hash160, "public");
|
|
164
158
|
}
|
|
165
159
|
exports.bitcoinAddress = bitcoinAddress;
|
|
160
|
+
/**
|
|
161
|
+
* Function to format a number in a decimal point number
|
|
162
|
+
* @example
|
|
163
|
+
* ```js
|
|
164
|
+
* const amount = formatUnits("123456", 8);
|
|
165
|
+
* console.log(amount);
|
|
166
|
+
* // '0.00123456'
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
function formatUnits(value, decimals) {
|
|
170
|
+
let v = typeof value === "string" ? value : BigInt(value).toString();
|
|
171
|
+
const sign = v[0] === "-" ? "-" : "";
|
|
172
|
+
v = v.replace("-", "").padStart(decimals + 1, "0");
|
|
173
|
+
const integerPart = v
|
|
174
|
+
.substring(0, v.length - decimals)
|
|
175
|
+
.replace(/^0+(?=\d)/, "");
|
|
176
|
+
const decimalPart = v.substring(v.length - decimals);
|
|
177
|
+
return `${sign}${integerPart}.${decimalPart}`.replace(/(\.0+)?(0+)$/, "");
|
|
178
|
+
}
|
|
179
|
+
exports.formatUnits = formatUnits;
|
|
180
|
+
/**
|
|
181
|
+
* Function to format a decimal point number in an integer
|
|
182
|
+
* @example
|
|
183
|
+
* ```js
|
|
184
|
+
* const amount = parseUnits("0.00123456", 8);
|
|
185
|
+
* console.log(amount);
|
|
186
|
+
* // '123456'
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
function parseUnits(value, decimals) {
|
|
190
|
+
const sign = value[0] === "-" ? "-" : "";
|
|
191
|
+
// eslint-disable-next-line prefer-const
|
|
192
|
+
let [integerPart, decimalPart] = value
|
|
193
|
+
.replace("-", "")
|
|
194
|
+
.replace(",", ".")
|
|
195
|
+
.split(".");
|
|
196
|
+
if (!decimalPart)
|
|
197
|
+
decimalPart = "";
|
|
198
|
+
decimalPart = decimalPart.padEnd(decimals, "0");
|
|
199
|
+
return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
|
|
200
|
+
}
|
|
201
|
+
exports.parseUnits = parseUnits;
|
|
166
202
|
/**
|
|
167
203
|
* ABI for tokens
|
|
168
204
|
*/
|
|
@@ -170,45 +206,47 @@ exports.Krc20Abi = {
|
|
|
170
206
|
methods: {
|
|
171
207
|
name: {
|
|
172
208
|
entryPoint: 0x76ea4297,
|
|
173
|
-
|
|
174
|
-
|
|
209
|
+
input: "name_arguments",
|
|
210
|
+
output: "name_result",
|
|
175
211
|
readOnly: true,
|
|
176
212
|
},
|
|
177
213
|
symbol: {
|
|
178
214
|
entryPoint: 0x7e794b24,
|
|
179
|
-
|
|
180
|
-
|
|
215
|
+
input: "symbol_arguments",
|
|
216
|
+
output: "symbol_result",
|
|
181
217
|
readOnly: true,
|
|
182
218
|
},
|
|
183
219
|
decimals: {
|
|
184
220
|
entryPoint: 0x59dc15ce,
|
|
185
|
-
|
|
186
|
-
|
|
221
|
+
input: "decimals_arguments",
|
|
222
|
+
output: "decimals_result",
|
|
187
223
|
readOnly: true,
|
|
188
224
|
},
|
|
189
225
|
totalSupply: {
|
|
190
226
|
entryPoint: 0xcf2e8212,
|
|
191
|
-
|
|
192
|
-
|
|
227
|
+
input: "total_supply_arguments",
|
|
228
|
+
output: "total_supply_result",
|
|
193
229
|
readOnly: true,
|
|
194
230
|
},
|
|
195
231
|
balanceOf: {
|
|
196
232
|
entryPoint: 0x15619248,
|
|
197
|
-
|
|
198
|
-
|
|
233
|
+
input: "balance_of_arguments",
|
|
234
|
+
output: "balance_of_result",
|
|
199
235
|
readOnly: true,
|
|
236
|
+
defaultOutput: { value: "0" },
|
|
200
237
|
},
|
|
201
238
|
transfer: {
|
|
202
239
|
entryPoint: 0x62efa292,
|
|
203
|
-
|
|
204
|
-
|
|
240
|
+
input: "transfer_arguments",
|
|
241
|
+
output: "transfer_result",
|
|
205
242
|
},
|
|
206
243
|
mint: {
|
|
207
244
|
entryPoint: 0xc2f82bdc,
|
|
208
|
-
|
|
209
|
-
|
|
245
|
+
input: "mint_argumnets",
|
|
246
|
+
output: "mint_result",
|
|
210
247
|
},
|
|
211
248
|
},
|
|
212
249
|
types: krc20_proto_json_1.default,
|
|
213
250
|
};
|
|
251
|
+
exports.ProtocolTypes = protocol_proto_json_1.default;
|
|
214
252
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,qDAAkD;AAClD,2DAAwD;AACxD,0FAAgE;AAChE,gGAAiE;AAG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