koilib 2.5.0 → 2.7.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.
Files changed (46) hide show
  1. package/README.md +6 -6
  2. package/dist/koinos.js +2986 -4607
  3. package/dist/koinos.min.js +1 -1
  4. package/dist/koinos.min.js.LICENSE.txt +2 -2
  5. package/lib/Contract.d.ts +9 -11
  6. package/lib/Contract.js +20 -20
  7. package/lib/Contract.js.map +1 -1
  8. package/lib/Provider.d.ts +24 -17
  9. package/lib/Provider.js +99 -105
  10. package/lib/Provider.js.map +1 -1
  11. package/lib/Serializer.js +9 -9
  12. package/lib/Serializer.js.map +1 -1
  13. package/lib/Signer.d.ts +9 -9
  14. package/lib/Signer.js +30 -22
  15. package/lib/Signer.js.map +1 -1
  16. package/lib/browser/Contract.d.ts +200 -0
  17. package/lib/browser/Contract.js +298 -0
  18. package/lib/browser/Contract.js.map +1 -0
  19. package/lib/browser/Provider.d.ts +160 -0
  20. package/lib/browser/Provider.js +246 -0
  21. package/lib/browser/Provider.js.map +1 -0
  22. package/lib/browser/Serializer.d.ts +81 -0
  23. package/lib/browser/Serializer.js +169 -0
  24. package/lib/browser/Serializer.js.map +1 -0
  25. package/lib/browser/Signer.d.ts +296 -0
  26. package/lib/browser/Signer.js +429 -0
  27. package/lib/browser/Signer.js.map +1 -0
  28. package/lib/browser/index.d.ts +7 -0
  29. package/lib/browser/index.js +34 -0
  30. package/lib/browser/index.js.map +1 -0
  31. package/lib/browser/index2.d.ts +2 -0
  32. package/lib/browser/index2.js +33 -0
  33. package/lib/browser/index2.js.map +1 -0
  34. package/lib/browser/interface.d.ts +279 -0
  35. package/lib/browser/interface.js +3 -0
  36. package/lib/browser/interface.js.map +1 -0
  37. package/lib/browser/jsonDescriptors/krc20-proto.json +183 -0
  38. package/lib/browser/jsonDescriptors/protocol-proto.json +246 -0
  39. package/lib/browser/utils.d.ts +326 -0
  40. package/lib/browser/utils.js +252 -0
  41. package/lib/browser/utils.js.map +1 -0
  42. package/lib/interface.d.ts +24 -25
  43. package/lib/utils.d.ts +12 -8
  44. package/lib/utils.js +7 -7
  45. package/lib/utils.js.map +1 -1
  46. package/package.json +34 -31
@@ -0,0 +1,279 @@
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
+ /**
136
+ * Function to wait for a transaction to be mined.
137
+ * This function comes as a response after sending a transaction.
138
+ * See [[Provider.sendTransaction]]
139
+ *
140
+ * @param type - Type must be "byBlock" (default) or "byTransactionId".
141
+ * _byBlock_ will query the blockchain to get blocks and search for the
142
+ * transaction there. _byTransactionId_ will query the "transaction store"
143
+ * microservice to search the transaction by its id. If non of them is
144
+ * specified the function will use "byBlock" (as "byTransactionId"
145
+ * requires the transaction store, which is an optional microservice).
146
+ *
147
+ * When _byBlock_ is used it returns the block number.
148
+ *
149
+ * When _byTransactionId_ is used it returns the block id.
150
+ *
151
+ * @param timeout - Timeout in milliseconds. By default it is 30000
152
+ */
153
+ export declare type WaitFunction = (type?: "byBlock" | "byTransactionId", timeout?: number) => Promise<string | number>;
154
+ export interface UploadContractOperation {
155
+ contract_id?: Uint8Array;
156
+ bytecode?: Uint8Array;
157
+ }
158
+ export interface UploadContractOperationJson {
159
+ contract_id?: string;
160
+ bytecode?: string;
161
+ }
162
+ export interface CallContractOperation {
163
+ contract_id: Uint8Array;
164
+ entry_point: number;
165
+ args: Uint8Array;
166
+ }
167
+ export interface CallContractOperationJson {
168
+ contract_id: string;
169
+ entry_point: number;
170
+ args: string;
171
+ }
172
+ export interface ContractCallBundle {
173
+ contract_id: Uint8Array;
174
+ entry_point: number;
175
+ }
176
+ export interface ContractCallBundleJson {
177
+ contract_id: string;
178
+ entry_point: number;
179
+ }
180
+ export interface ThunkIdNested {
181
+ thunk_id: number;
182
+ }
183
+ export interface ContractCallBundleNested {
184
+ system_call_bundle: ContractCallBundle;
185
+ }
186
+ export declare type SystemCallTarget = ThunkIdNested | ContractCallBundleNested;
187
+ export interface SetSystemCallOperation {
188
+ call_id: number;
189
+ target: SystemCallTarget;
190
+ }
191
+ export interface SetSystemCallOperationJson {
192
+ call_id: number;
193
+ target: number | ContractCallBundleJson;
194
+ }
195
+ export interface UploadContractOperationNested {
196
+ upload_contract: UploadContractOperation;
197
+ }
198
+ export interface CallContractOperationNested {
199
+ call_contract: CallContractOperation;
200
+ }
201
+ export interface SetSystemCallOperationNested {
202
+ set_system_call: SetSystemCallOperation;
203
+ }
204
+ export declare type Operation = UploadContractOperationNested | CallContractOperationNested | SetSystemCallOperationNested;
205
+ export declare type OperationJson = {
206
+ upload_contract?: UploadContractOperationJson;
207
+ call_contract?: CallContractOperationJson;
208
+ set_system_call?: SetSystemCallOperationJson;
209
+ };
210
+ export interface ActiveTransactionData {
211
+ /**
212
+ * Resource credits limit
213
+ */
214
+ rc_limit?: string | number | bigint;
215
+ /**
216
+ * Account nonce
217
+ */
218
+ nonce?: string | number | bigint;
219
+ /**
220
+ * Array of operations
221
+ */
222
+ operations?: Operation[];
223
+ [x: string]: unknown;
224
+ }
225
+ export interface ActiveTransactionDataJson {
226
+ /**
227
+ * Resource credits limit
228
+ */
229
+ rc_limit?: string | number | bigint;
230
+ /**
231
+ * Account nonce
232
+ */
233
+ nonce?: string | number | bigint;
234
+ /**
235
+ * Array of operations
236
+ */
237
+ operations?: OperationJson[];
238
+ [x: string]: unknown;
239
+ }
240
+ /**
241
+ * Koinos Transaction
242
+ */
243
+ export interface TransactionJson {
244
+ /**
245
+ * Transaction ID. It must be the sha2-256 of the
246
+ * serialized data of active data, and encoded in multi base58
247
+ */
248
+ id?: string;
249
+ /**
250
+ * Consensus data
251
+ */
252
+ active?: string;
253
+ /**
254
+ * Non-consensus data
255
+ */
256
+ passive?: string;
257
+ /**
258
+ * Signature in compact format enconded in multi base64
259
+ */
260
+ signature_data?: string;
261
+ }
262
+ export interface TransactionJsonWait extends TransactionJson {
263
+ wait: WaitFunction;
264
+ }
265
+ export interface BlockHeaderJson {
266
+ previous?: string;
267
+ height?: string;
268
+ timestamp?: string;
269
+ [x: string]: unknown;
270
+ }
271
+ export interface BlockJson {
272
+ id?: string;
273
+ header?: BlockHeaderJson;
274
+ active?: string;
275
+ passive?: string;
276
+ signature_data?: string;
277
+ transactions?: TransactionJson[];
278
+ [x: string]: unknown;
279
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,183 @@
1
+ {
2
+ "nested": {
3
+ "koinos": {
4
+ "nested": {
5
+ "contracts": {
6
+ "nested": {
7
+ "token": {
8
+ "options": {
9
+ "go_package": "github.com/koinos/koinos-proto-golang/koinos/contracts/token"
10
+ },
11
+ "nested": {
12
+ "name_arguments": {
13
+ "fields": {}
14
+ },
15
+ "name_result": {
16
+ "fields": {
17
+ "value": {
18
+ "type": "string",
19
+ "id": 1
20
+ }
21
+ }
22
+ },
23
+ "symbol_arguments": {
24
+ "fields": {}
25
+ },
26
+ "symbol_result": {
27
+ "fields": {
28
+ "value": {
29
+ "type": "string",
30
+ "id": 1
31
+ }
32
+ }
33
+ },
34
+ "decimals_arguments": {
35
+ "fields": {}
36
+ },
37
+ "decimals_result": {
38
+ "fields": {
39
+ "value": {
40
+ "type": "uint32",
41
+ "id": 1
42
+ }
43
+ }
44
+ },
45
+ "total_supply_arguments": {
46
+ "fields": {}
47
+ },
48
+ "total_supply_result": {
49
+ "fields": {
50
+ "value": {
51
+ "type": "uint64",
52
+ "id": 1,
53
+ "options": {
54
+ "jstype": "JS_STRING"
55
+ }
56
+ }
57
+ }
58
+ },
59
+ "balance_of_arguments": {
60
+ "fields": {
61
+ "owner": {
62
+ "type": "bytes",
63
+ "id": 1,
64
+ "options": {
65
+ "(koinos_bytes_type)": "ADDRESS"
66
+ }
67
+ }
68
+ }
69
+ },
70
+ "balance_of_result": {
71
+ "fields": {
72
+ "value": {
73
+ "type": "uint64",
74
+ "id": 1,
75
+ "options": {
76
+ "jstype": "JS_STRING"
77
+ }
78
+ }
79
+ }
80
+ },
81
+ "transfer_arguments": {
82
+ "fields": {
83
+ "from": {
84
+ "type": "bytes",
85
+ "id": 1,
86
+ "options": {
87
+ "(koinos_bytes_type)": "ADDRESS"
88
+ }
89
+ },
90
+ "to": {
91
+ "type": "bytes",
92
+ "id": 2,
93
+ "options": {
94
+ "(koinos_bytes_type)": "ADDRESS"
95
+ }
96
+ },
97
+ "value": {
98
+ "type": "uint64",
99
+ "id": 3,
100
+ "options": {
101
+ "jstype": "JS_STRING"
102
+ }
103
+ }
104
+ }
105
+ },
106
+ "transfer_result": {
107
+ "fields": {
108
+ "value": {
109
+ "type": "bool",
110
+ "id": 1
111
+ }
112
+ }
113
+ },
114
+ "mint_arguments": {
115
+ "fields": {
116
+ "to": {
117
+ "type": "bytes",
118
+ "id": 1,
119
+ "options": {
120
+ "(koinos_bytes_type)": "ADDRESS"
121
+ }
122
+ },
123
+ "value": {
124
+ "type": "uint64",
125
+ "id": 2,
126
+ "options": {
127
+ "jstype": "JS_STRING"
128
+ }
129
+ }
130
+ }
131
+ },
132
+ "mint_result": {
133
+ "fields": {
134
+ "value": {
135
+ "type": "bool",
136
+ "id": 1
137
+ }
138
+ }
139
+ },
140
+ "balance_object": {
141
+ "fields": {
142
+ "value": {
143
+ "type": "uint64",
144
+ "id": 1,
145
+ "options": {
146
+ "jstype": "JS_STRING"
147
+ }
148
+ }
149
+ }
150
+ },
151
+ "mana_balance_object": {
152
+ "fields": {
153
+ "balance": {
154
+ "type": "uint64",
155
+ "id": 1,
156
+ "options": {
157
+ "jstype": "JS_STRING"
158
+ }
159
+ },
160
+ "mana": {
161
+ "type": "uint64",
162
+ "id": 2,
163
+ "options": {
164
+ "jstype": "JS_STRING"
165
+ }
166
+ },
167
+ "last_mana_update": {
168
+ "type": "uint64",
169
+ "id": 3,
170
+ "options": {
171
+ "jstype": "JS_STRING"
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ }