koilib 2.2.0 → 2.5.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.
@@ -1,65 +1,220 @@
1
+ import { INamespace } from "protobufjs/light";
2
+ /**
3
+ * Application Binary Interface (ABI)
4
+ *
5
+ * ABIs are composed of 2 elements: methods and types.
6
+ * - The methods define the names of the entries of the smart contract,
7
+ * the corresponding endpoints and the name of the types used.
8
+ * - The types all the description to serialize and deserialize
9
+ * using proto buffers.
10
+ *
11
+ * To generate the types is necessary to use the dependency
12
+ * protobufjs. The following example shows how to generate the
13
+ * protobuf descriptor from a .proto file.
14
+ *
15
+ * ```js
16
+ * const fs = require("fs");
17
+ * const pbjs = require("protobufjs/cli/pbjs");
18
+ *
19
+ * pbjs.main(
20
+ * ["--target", "json", "./token.proto"],
21
+ * (err, output) => {
22
+ * if (err) throw err;
23
+ * fs.writeFileSync("./token-proto.json", output);
24
+ * }
25
+ * );
26
+ * ```
27
+ *
28
+ * Then this descriptor can be loaded to define the ABI:
29
+ * ```js
30
+ * const tokenJson = require("./token-proto.json");
31
+ * const abiToken = {
32
+ * methods: {
33
+ * balanceOf: {
34
+ * entryPoint: 0x15619248,
35
+ * inputs: "balance_of_arguments",
36
+ * outputs: "balance_of_result",
37
+ * readOnly: true,
38
+ * defaultOutput: { value: "0" },
39
+ * },
40
+ * transfer: {
41
+ * entryPoint: 0x62efa292,
42
+ * inputs: "transfer_arguments",
43
+ * outputs: "transfer_result",
44
+ * },
45
+ * mint: {
46
+ * entryPoint: 0xc2f82bdc,
47
+ * inputs: "mint_argumnets",
48
+ * outputs: "mint_result",
49
+ * },
50
+ * },
51
+ * types: tokenJson,
52
+ * };
53
+ * ```
54
+ *
55
+ * Note that this example uses "defaultOutput" for the method
56
+ * "balanceOf". This is used when the smart contract returns an
57
+ * empty response (for instance when there are no balance records
58
+ * for a specific address) and you require a default output in
59
+ * such cases.
60
+ */
61
+ export interface Abi {
62
+ methods: {
63
+ /** Name of the method */
64
+ [x: string]: {
65
+ /** Entry point ID */
66
+ entryPoint: number;
67
+ /** Protobuffer type for input */
68
+ input?: string;
69
+ /** Protobuffer type for output */
70
+ output?: string;
71
+ /** Boolean to differentiate write methods
72
+ * (using transactions) from read methods
73
+ * (query the contract)
74
+ */
75
+ readOnly?: boolean;
76
+ /** Default value when the output is undefined */
77
+ defaultOutput?: unknown;
78
+ /** Optional function to preformat the input */
79
+ preformatInput?: (input: unknown) => Record<string, unknown>;
80
+ /** Optional function to preformat the output */
81
+ preformatOutput?: (output: Record<string, unknown>) => unknown;
82
+ /** Description of the method */
83
+ description?: string;
84
+ };
85
+ };
86
+ /**
87
+ * Protobuffers descriptor in JSON format.
88
+ * See https://www.npmjs.com/package/protobufjs#using-json-descriptors
89
+ */
90
+ types: INamespace;
91
+ }
92
+ /**
93
+ * Human readable format operation
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const opDecoded = {
98
+ * name: "transfer",
99
+ * args: {
100
+ * from: "1Krs7v1rtpgRyfwEZncuKMQQnY5JhqXVSx",
101
+ * to: "1BqtgWBcqm9cSZ97avLGZGJdgso7wx6pCA",
102
+ * value: 1000,
103
+ * },
104
+ * };
105
+ * ```
106
+ */
107
+ export interface DecodedOperationJson {
108
+ /** Operation name */
109
+ name: string;
110
+ /** Arguments decoded. See [[Abi]] */
111
+ args?: Record<string, unknown>;
112
+ }
113
+ export interface TransactionOptions {
114
+ rc_limit?: number | bigint | string;
115
+ nonce?: number;
116
+ sendTransaction?: boolean;
117
+ sendAbis?: boolean;
118
+ }
119
+ export interface RecoverPublicKeyOptions {
120
+ /**
121
+ * Boolean to define if the public key should
122
+ * be compressed or not. It is true by default
123
+ */
124
+ compressed?: boolean;
125
+ /**
126
+ * Asynchronous function to transform the signature
127
+ * before calculating the public key associated.
128
+ * This transformation is useful in cases were the
129
+ * signature contains additional data. For instance,
130
+ * the signatures for blocks in the PoW consensus
131
+ * algorithm contain the nonce.
132
+ */
133
+ transformSignature?: (signatureData: string) => Promise<string>;
134
+ }
135
+ export interface SendTransactionResponse {
136
+ /**
137
+ * Function to wait for a transaction to be mined.
138
+ * This function comes as a response after sending a transaction.
139
+ * See [[Provider.sendTransaction]]
140
+ *
141
+ * @param type - Type must be "byBlock" (default) or "byTransactionId".
142
+ * _byBlock_ will query the blockchain to get blocks and search for the
143
+ * transaction there. _byTransactionId_ will query the "transaction store"
144
+ * microservice to search the transaction by its id. If non of them is
145
+ * specified the function will use "byBlock" (as "byTransactionId"
146
+ * requires the transaction store, which is an optional microservice).
147
+ *
148
+ * When _byBlock_ is used it returns the block number.
149
+ *
150
+ * When _byTransactionId_ is used it returns the block id.
151
+ *
152
+ * @param timeout - Timeout in milliseconds. By default it is 30000
153
+ */
154
+ wait: (type?: "byBlock" | "byTransactionId", timeout?: number) => Promise<string | number>;
155
+ }
1
156
  declare type NumberLike = number | bigint | string;
2
157
  export interface UploadContractOperation {
3
- contractId?: Uint8Array;
158
+ contract_id?: Uint8Array;
4
159
  bytecode?: Uint8Array;
5
160
  }
6
161
  export interface UploadContractOperationJson {
7
- contractId?: string;
162
+ contract_id?: string;
8
163
  bytecode?: string;
9
164
  }
10
165
  export interface CallContractOperation {
11
- contractId: Uint8Array;
12
- entryPoint: number;
166
+ contract_id: Uint8Array;
167
+ entry_point: number;
13
168
  args: Uint8Array;
14
169
  }
15
170
  export interface CallContractOperationJson {
16
- contractId: string;
17
- entryPoint: number;
171
+ contract_id: string;
172
+ entry_point: number;
18
173
  args: string;
19
174
  }
20
175
  export interface ContractCallBundle {
21
- contractId: Uint8Array;
22
- entryPoint: number;
176
+ contract_id: Uint8Array;
177
+ entry_point: number;
23
178
  }
24
179
  export interface ContractCallBundleJson {
25
- contractId: string;
26
- entryPoint: number;
180
+ contract_id: string;
181
+ entry_point: number;
27
182
  }
28
183
  export interface ThunkIdNested {
29
- thunkId: number;
184
+ thunk_id: number;
30
185
  }
31
186
  export interface ContractCallBundleNested {
32
- systemCallBundle: ContractCallBundle;
187
+ system_call_bundle: ContractCallBundle;
33
188
  }
34
189
  export declare type SystemCallTarget = ThunkIdNested | ContractCallBundleNested;
35
190
  export interface SetSystemCallOperation {
36
- callId: number;
191
+ call_id: number;
37
192
  target: SystemCallTarget;
38
193
  }
39
194
  export interface SetSystemCallOperationJson {
40
- callId: number;
195
+ call_id: number;
41
196
  target: number | ContractCallBundleJson;
42
197
  }
43
198
  export interface UploadContractOperationNested {
44
- uploadContract: UploadContractOperation;
199
+ upload_contract: UploadContractOperation;
45
200
  }
46
201
  export interface CallContractOperationNested {
47
- callContract: CallContractOperation;
202
+ call_contract: CallContractOperation;
48
203
  }
49
204
  export interface SetSystemCallOperationNested {
50
- setSystemCall: SetSystemCallOperation;
205
+ set_system_call: SetSystemCallOperation;
51
206
  }
52
207
  export declare type Operation = UploadContractOperationNested | CallContractOperationNested | SetSystemCallOperationNested;
53
208
  export declare type OperationJson = {
54
- uploadContract?: UploadContractOperationJson;
55
- callContract?: CallContractOperationJson;
56
- setSystemCall?: SetSystemCallOperationJson;
209
+ upload_contract?: UploadContractOperationJson;
210
+ call_contract?: CallContractOperationJson;
211
+ set_system_call?: SetSystemCallOperationJson;
57
212
  };
58
213
  export interface ActiveTransactionData {
59
214
  /**
60
215
  * Resource credits limit
61
216
  */
62
- rcLimit?: string | number | bigint;
217
+ rc_limit?: string | number | bigint;
63
218
  /**
64
219
  * Account nonce
65
220
  */
@@ -74,7 +229,7 @@ export interface ActiveTransactionDataJson {
74
229
  /**
75
230
  * Resource credits limit
76
231
  */
77
- rcLimit?: string | number | bigint;
232
+ rc_limit?: string | number | bigint;
78
233
  /**
79
234
  * Account nonce
80
235
  */
@@ -105,7 +260,7 @@ export interface TransactionJson {
105
260
  /**
106
261
  * Signature in compact format enconded in multi base64
107
262
  */
108
- signatureData?: string;
263
+ signature_data?: string;
109
264
  }
110
265
  export interface BlockHeaderJson {
111
266
  previous?: string;
@@ -118,7 +273,7 @@ export interface BlockJson {
118
273
  header?: BlockHeaderJson;
119
274
  active?: string;
120
275
  passive?: string;
121
- signatureData?: string;
276
+ signature_data?: string;
122
277
  transactions?: TransactionJson[];
123
278
  [x: string]: unknown;
124
279
  }
@@ -164,7 +164,7 @@
164
164
  "jstype": "JS_STRING"
165
165
  }
166
166
  },
167
- "lastManaUpdate": {
167
+ "last_mana_update": {
168
168
  "type": "uint64",
169
169
  "id": 3,
170
170
  "options": {
@@ -9,14 +9,14 @@
9
9
  "nested": {
10
10
  "contract_call_bundle": {
11
11
  "fields": {
12
- "contractId": {
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
- "entryPoint": {
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": ["thunkId", "systemCallBundle"]
28
+ "oneof": ["thunk_id", "system_call_bundle"]
29
29
  }
30
30
  },
31
31
  "fields": {
32
- "thunkId": {
32
+ "thunk_id": {
33
33
  "type": "uint32",
34
34
  "id": 1
35
35
  },
36
- "systemCallBundle": {
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
- "contractId": {
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
- "contractId": {
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
- "entryPoint": {
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
- "callId": {
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": ["uploadContract", "callContract", "setSystemCall"]
91
+ "oneof": [
92
+ "upload_contract",
93
+ "call_contract",
94
+ "set_system_call"
95
+ ]
92
96
  }
93
97
  },
94
98
  "fields": {
95
- "uploadContract": {
99
+ "upload_contract": {
96
100
  "type": "upload_contract_operation",
97
101
  "id": 1
98
102
  },
99
- "callContract": {
103
+ "call_contract": {
100
104
  "type": "call_contract_operation",
101
105
  "id": 2
102
106
  },
103
- "setSystemCall": {
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
- "rcLimit": {
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
- "signatureData": {
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
- "transactionMerkleRoot": {
164
+ "transaction_merkle_root": {
161
165
  "type": "bytes",
162
166
  "id": 1
163
167
  },
164
- "passiveDataMerkleRoot": {
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
- "signatureData": {
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 "./Contract";
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)
@@ -72,3 +71,252 @@ export declare function parseUnits(value: string, decimals: number): string;
72
71
  * ABI for tokens
73
72
  */
74
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
+ };