koilib 1.5.0 → 2.3.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.
@@ -0,0 +1,246 @@
1
+ {
2
+ "nested": {
3
+ "koinos": {
4
+ "nested": {
5
+ "protocol": {
6
+ "options": {
7
+ "go_package": "github.com/koinos/koinos-proto-golang/koinos/protocol"
8
+ },
9
+ "nested": {
10
+ "contract_call_bundle": {
11
+ "fields": {
12
+ "contract_id": {
13
+ "type": "bytes",
14
+ "id": 1,
15
+ "options": {
16
+ "(koinos_bytes_type)": "CONTRACT_ID"
17
+ }
18
+ },
19
+ "entry_point": {
20
+ "type": "uint32",
21
+ "id": 2
22
+ }
23
+ }
24
+ },
25
+ "system_call_target": {
26
+ "oneofs": {
27
+ "target": {
28
+ "oneof": ["thunk_id", "system_call_bundle"]
29
+ }
30
+ },
31
+ "fields": {
32
+ "thunk_id": {
33
+ "type": "uint32",
34
+ "id": 1
35
+ },
36
+ "system_call_bundle": {
37
+ "type": "contract_call_bundle",
38
+ "id": 2
39
+ }
40
+ }
41
+ },
42
+ "upload_contract_operation": {
43
+ "fields": {
44
+ "contract_id": {
45
+ "type": "bytes",
46
+ "id": 1,
47
+ "options": {
48
+ "(koinos_bytes_type)": "CONTRACT_ID"
49
+ }
50
+ },
51
+ "bytecode": {
52
+ "type": "bytes",
53
+ "id": 2
54
+ }
55
+ }
56
+ },
57
+ "call_contract_operation": {
58
+ "fields": {
59
+ "contract_id": {
60
+ "type": "bytes",
61
+ "id": 1,
62
+ "options": {
63
+ "(koinos_bytes_type)": "CONTRACT_ID"
64
+ }
65
+ },
66
+ "entry_point": {
67
+ "type": "uint32",
68
+ "id": 2
69
+ },
70
+ "args": {
71
+ "type": "bytes",
72
+ "id": 3
73
+ }
74
+ }
75
+ },
76
+ "set_system_call_operation": {
77
+ "fields": {
78
+ "call_id": {
79
+ "type": "uint32",
80
+ "id": 1
81
+ },
82
+ "target": {
83
+ "type": "system_call_target",
84
+ "id": 2
85
+ }
86
+ }
87
+ },
88
+ "operation": {
89
+ "oneofs": {
90
+ "op": {
91
+ "oneof": [
92
+ "upload_contract",
93
+ "call_contract",
94
+ "set_system_call"
95
+ ]
96
+ }
97
+ },
98
+ "fields": {
99
+ "upload_contract": {
100
+ "type": "upload_contract_operation",
101
+ "id": 1
102
+ },
103
+ "call_contract": {
104
+ "type": "call_contract_operation",
105
+ "id": 2
106
+ },
107
+ "set_system_call": {
108
+ "type": "set_system_call_operation",
109
+ "id": 3
110
+ }
111
+ }
112
+ },
113
+ "active_transaction_data": {
114
+ "fields": {
115
+ "rc_limit": {
116
+ "type": "uint64",
117
+ "id": 1,
118
+ "options": {
119
+ "jstype": "JS_STRING"
120
+ }
121
+ },
122
+ "nonce": {
123
+ "type": "uint64",
124
+ "id": 2,
125
+ "options": {
126
+ "jstype": "JS_STRING"
127
+ }
128
+ },
129
+ "operations": {
130
+ "rule": "repeated",
131
+ "type": "operation",
132
+ "id": 3
133
+ }
134
+ }
135
+ },
136
+ "passive_transaction_data": {
137
+ "fields": {}
138
+ },
139
+ "transaction": {
140
+ "fields": {
141
+ "id": {
142
+ "type": "bytes",
143
+ "id": 1,
144
+ "options": {
145
+ "(koinos_bytes_type)": "TRANSACTION_ID"
146
+ }
147
+ },
148
+ "active": {
149
+ "type": "bytes",
150
+ "id": 2
151
+ },
152
+ "passive": {
153
+ "type": "bytes",
154
+ "id": 3
155
+ },
156
+ "signature_data": {
157
+ "type": "bytes",
158
+ "id": 4
159
+ }
160
+ }
161
+ },
162
+ "active_block_data": {
163
+ "fields": {
164
+ "transaction_merkle_root": {
165
+ "type": "bytes",
166
+ "id": 1
167
+ },
168
+ "passive_data_merkle_root": {
169
+ "type": "bytes",
170
+ "id": 2
171
+ },
172
+ "signer": {
173
+ "type": "bytes",
174
+ "id": 3
175
+ }
176
+ }
177
+ },
178
+ "passive_block_data": {
179
+ "fields": {}
180
+ },
181
+ "block_header": {
182
+ "fields": {
183
+ "previous": {
184
+ "type": "bytes",
185
+ "id": 1,
186
+ "options": {
187
+ "(koinos_bytes_type)": "BLOCK_ID"
188
+ }
189
+ },
190
+ "height": {
191
+ "type": "uint64",
192
+ "id": 2,
193
+ "options": {
194
+ "jstype": "JS_STRING"
195
+ }
196
+ },
197
+ "timestamp": {
198
+ "type": "uint64",
199
+ "id": 3,
200
+ "options": {
201
+ "jstype": "JS_STRING"
202
+ }
203
+ }
204
+ }
205
+ },
206
+ "block": {
207
+ "fields": {
208
+ "id": {
209
+ "type": "bytes",
210
+ "id": 1,
211
+ "options": {
212
+ "(koinos_bytes_type)": "BLOCK_ID"
213
+ }
214
+ },
215
+ "header": {
216
+ "type": "block_header",
217
+ "id": 2
218
+ },
219
+ "active": {
220
+ "type": "bytes",
221
+ "id": 3
222
+ },
223
+ "passive": {
224
+ "type": "bytes",
225
+ "id": 4
226
+ },
227
+ "signature_data": {
228
+ "type": "bytes",
229
+ "id": 5
230
+ },
231
+ "transactions": {
232
+ "rule": "repeated",
233
+ "type": "transaction",
234
+ "id": 6
235
+ }
236
+ }
237
+ },
238
+ "block_receipt": {
239
+ "fields": {}
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
package/lib/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Abi } from "./interface";
1
2
  /**
2
3
  * Converts an hex string to Uint8Array
3
4
  */
@@ -14,6 +15,14 @@ export declare function encodeBase58(buffer: Uint8Array): string;
14
15
  * Decodes a buffer formatted in base58
15
16
  */
16
17
  export declare function decodeBase58(bs58: string): Uint8Array;
18
+ /**
19
+ * Encodes an Uint8Array in base64
20
+ */
21
+ export declare function encodeBase64(buffer: Uint8Array): string;
22
+ /**
23
+ * Decodes a buffer formatted in base64
24
+ */
25
+ export declare function decodeBase64(bs64: string): Uint8Array;
17
26
  /**
18
27
  * Encodes a public or private key in base58 using
19
28
  * the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
@@ -39,3 +48,275 @@ export declare function bitcoinDecode(value: string): Uint8Array;
39
48
  * address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
40
49
  */
41
50
  export declare function bitcoinAddress(publicKey: Uint8Array): string;
51
+ /**
52
+ * Function to format a number in a decimal point number
53
+ * @example
54
+ * ```js
55
+ * const amount = formatUnits("123456", 8);
56
+ * console.log(amount);
57
+ * // '0.00123456'
58
+ * ```
59
+ */
60
+ export declare function formatUnits(value: string | number | bigint, decimals: number): string;
61
+ /**
62
+ * Function to format a decimal point number in an integer
63
+ * @example
64
+ * ```js
65
+ * const amount = parseUnits("0.00123456", 8);
66
+ * console.log(amount);
67
+ * // '123456'
68
+ * ```
69
+ */
70
+ export declare function parseUnits(value: string, decimals: number): string;
71
+ /**
72
+ * ABI for tokens
73
+ */
74
+ export declare const Krc20Abi: Abi;
75
+ export declare const ProtocolTypes: {
76
+ nested: {
77
+ koinos: {
78
+ nested: {
79
+ protocol: {
80
+ options: {
81
+ go_package: string;
82
+ };
83
+ nested: {
84
+ contract_call_bundle: {
85
+ fields: {
86
+ contract_id: {
87
+ type: string;
88
+ id: number;
89
+ options: {
90
+ "(koinos_bytes_type)": string;
91
+ };
92
+ };
93
+ entry_point: {
94
+ type: string;
95
+ id: number;
96
+ };
97
+ };
98
+ };
99
+ system_call_target: {
100
+ oneofs: {
101
+ target: {
102
+ oneof: string[];
103
+ };
104
+ };
105
+ fields: {
106
+ thunk_id: {
107
+ type: string;
108
+ id: number;
109
+ };
110
+ system_call_bundle: {
111
+ type: string;
112
+ id: number;
113
+ };
114
+ };
115
+ };
116
+ upload_contract_operation: {
117
+ fields: {
118
+ contract_id: {
119
+ type: string;
120
+ id: number;
121
+ options: {
122
+ "(koinos_bytes_type)": string;
123
+ };
124
+ };
125
+ bytecode: {
126
+ type: string;
127
+ id: number;
128
+ };
129
+ };
130
+ };
131
+ call_contract_operation: {
132
+ fields: {
133
+ contract_id: {
134
+ type: string;
135
+ id: number;
136
+ options: {
137
+ "(koinos_bytes_type)": string;
138
+ };
139
+ };
140
+ entry_point: {
141
+ type: string;
142
+ id: number;
143
+ };
144
+ args: {
145
+ type: string;
146
+ id: number;
147
+ };
148
+ };
149
+ };
150
+ set_system_call_operation: {
151
+ fields: {
152
+ call_id: {
153
+ type: string;
154
+ id: number;
155
+ };
156
+ target: {
157
+ type: string;
158
+ id: number;
159
+ };
160
+ };
161
+ };
162
+ operation: {
163
+ oneofs: {
164
+ op: {
165
+ oneof: string[];
166
+ };
167
+ };
168
+ fields: {
169
+ upload_contract: {
170
+ type: string;
171
+ id: number;
172
+ };
173
+ call_contract: {
174
+ type: string;
175
+ id: number;
176
+ };
177
+ set_system_call: {
178
+ type: string;
179
+ id: number;
180
+ };
181
+ };
182
+ };
183
+ active_transaction_data: {
184
+ fields: {
185
+ rc_limit: {
186
+ type: string;
187
+ id: number;
188
+ options: {
189
+ jstype: string;
190
+ };
191
+ };
192
+ nonce: {
193
+ type: string;
194
+ id: number;
195
+ options: {
196
+ jstype: string;
197
+ };
198
+ };
199
+ operations: {
200
+ rule: string;
201
+ type: string;
202
+ id: number;
203
+ };
204
+ };
205
+ };
206
+ passive_transaction_data: {
207
+ fields: {};
208
+ };
209
+ transaction: {
210
+ fields: {
211
+ id: {
212
+ type: string; /**
213
+ * Computes a bitcoin address, which is the format used in Koinos
214
+ *
215
+ * address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
216
+ */
217
+ id: number;
218
+ options: {
219
+ "(koinos_bytes_type)": string;
220
+ };
221
+ };
222
+ active: {
223
+ type: string;
224
+ id: number;
225
+ };
226
+ passive: {
227
+ type: string;
228
+ id: number;
229
+ };
230
+ signature_data: {
231
+ type: string;
232
+ id: number;
233
+ };
234
+ };
235
+ };
236
+ active_block_data: {
237
+ fields: {
238
+ transaction_merkle_root: {
239
+ type: string;
240
+ id: number;
241
+ };
242
+ passive_data_merkle_root: {
243
+ type: string;
244
+ id: number;
245
+ };
246
+ signer: {
247
+ type: string;
248
+ id: number;
249
+ };
250
+ };
251
+ };
252
+ passive_block_data: {
253
+ fields: {};
254
+ };
255
+ block_header: {
256
+ fields: {
257
+ previous: {
258
+ type: string;
259
+ id: number;
260
+ options: {
261
+ "(koinos_bytes_type)": string;
262
+ };
263
+ };
264
+ height: {
265
+ type: string;
266
+ id: number;
267
+ options: {
268
+ jstype: string;
269
+ };
270
+ };
271
+ timestamp: {
272
+ type: string;
273
+ id: number; /**
274
+ * ABI for tokens
275
+ */
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,10 +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.bitcoinAddress = exports.bitcoinDecode = exports.copyUint8Array = exports.bitcoinEncode = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
25
+ exports.ProtocolTypes = exports.Krc20Abi = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.copyUint8Array = exports.bitcoinEncode = exports.decodeBase64 = exports.encodeBase64 = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
26
26
  const multibase = __importStar(require("multibase"));
27
27
  const js_sha256_1 = require("js-sha256");
28
28
  const noble_ripemd160_1 = __importDefault(require("noble-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"));
29
31
  /**
30
32
  * Converts an hex string to Uint8Array
31
33
  */
@@ -60,6 +62,20 @@ function decodeBase58(bs58) {
60
62
  return multibase.decode(`z${bs58}`);
61
63
  }
62
64
  exports.decodeBase58 = decodeBase58;
65
+ /**
66
+ * Encodes an Uint8Array in base64
67
+ */
68
+ function encodeBase64(buffer) {
69
+ return new TextDecoder().decode(multibase.encode("U", buffer)).slice(1);
70
+ }
71
+ exports.encodeBase64 = encodeBase64;
72
+ /**
73
+ * Decodes a buffer formatted in base64
74
+ */
75
+ function decodeBase64(bs64) {
76
+ return multibase.decode(`U${bs64}`);
77
+ }
78
+ exports.decodeBase64 = decodeBase64;
63
79
  /**
64
80
  * Encodes a public or private key in base58 using
65
81
  * the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
@@ -148,4 +164,96 @@ function bitcoinAddress(publicKey) {
148
164
  return bitcoinEncode(hash160, "public");
149
165
  }
150
166
  exports.bitcoinAddress = bitcoinAddress;
167
+ /**
168
+ * Function to format a number in a decimal point number
169
+ * @example
170
+ * ```js
171
+ * const amount = formatUnits("123456", 8);
172
+ * console.log(amount);
173
+ * // '0.00123456'
174
+ * ```
175
+ */
176
+ function formatUnits(value, decimals) {
177
+ let v = typeof value === "string" ? value : BigInt(value).toString();
178
+ const sign = v[0] === "-" ? "-" : "";
179
+ v = v.replace("-", "").padStart(decimals + 1, "0");
180
+ const integerPart = v
181
+ .substring(0, v.length - decimals)
182
+ .replace(/^0+(?=\d)/, "");
183
+ const decimalPart = v.substring(v.length - decimals);
184
+ return `${sign}${integerPart}.${decimalPart}`.replace(/(\.0+)?(0+)$/, "");
185
+ }
186
+ exports.formatUnits = formatUnits;
187
+ /**
188
+ * Function to format a decimal point number in an integer
189
+ * @example
190
+ * ```js
191
+ * const amount = parseUnits("0.00123456", 8);
192
+ * console.log(amount);
193
+ * // '123456'
194
+ * ```
195
+ */
196
+ function parseUnits(value, decimals) {
197
+ const sign = value[0] === "-" ? "-" : "";
198
+ // eslint-disable-next-line prefer-const
199
+ let [integerPart, decimalPart] = value
200
+ .replace("-", "")
201
+ .replace(",", ".")
202
+ .split(".");
203
+ if (!decimalPart)
204
+ decimalPart = "";
205
+ decimalPart = decimalPart.padEnd(decimals, "0");
206
+ return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
207
+ }
208
+ exports.parseUnits = parseUnits;
209
+ /**
210
+ * ABI for tokens
211
+ */
212
+ exports.Krc20Abi = {
213
+ methods: {
214
+ name: {
215
+ entryPoint: 0x76ea4297,
216
+ input: "name_arguments",
217
+ output: "name_result",
218
+ readOnly: true,
219
+ },
220
+ symbol: {
221
+ entryPoint: 0x7e794b24,
222
+ input: "symbol_arguments",
223
+ output: "symbol_result",
224
+ readOnly: true,
225
+ },
226
+ decimals: {
227
+ entryPoint: 0x59dc15ce,
228
+ input: "decimals_arguments",
229
+ output: "decimals_result",
230
+ readOnly: true,
231
+ },
232
+ totalSupply: {
233
+ entryPoint: 0xcf2e8212,
234
+ input: "total_supply_arguments",
235
+ output: "total_supply_result",
236
+ readOnly: true,
237
+ },
238
+ balanceOf: {
239
+ entryPoint: 0x15619248,
240
+ input: "balance_of_arguments",
241
+ output: "balance_of_result",
242
+ readOnly: true,
243
+ defaultOutput: { value: "0" },
244
+ },
245
+ transfer: {
246
+ entryPoint: 0x62efa292,
247
+ input: "transfer_arguments",
248
+ output: "transfer_result",
249
+ },
250
+ mint: {
251
+ entryPoint: 0xc2f82bdc,
252
+ input: "mint_argumnets",
253
+ output: "mint_result",
254
+ },
255
+ },
256
+ types: krc20_proto_json_1.default,
257
+ };
258
+ exports.ProtocolTypes = protocol_proto_json_1.default;
151
259
  //# sourceMappingURL=utils.js.map