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.
@@ -1,8 +1,231 @@
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
+ wait: () => Promise<string>;
137
+ }
1
138
  declare type NumberLike = number | bigint | string;
139
+ export interface UploadContractOperation {
140
+ contract_id?: Uint8Array;
141
+ bytecode?: Uint8Array;
142
+ }
143
+ export interface UploadContractOperationJson {
144
+ contract_id?: string;
145
+ bytecode?: string;
146
+ }
147
+ export interface CallContractOperation {
148
+ contract_id: Uint8Array;
149
+ entry_point: number;
150
+ args: Uint8Array;
151
+ }
152
+ export interface CallContractOperationJson {
153
+ contract_id: string;
154
+ entry_point: number;
155
+ args: string;
156
+ }
157
+ export interface ContractCallBundle {
158
+ contract_id: Uint8Array;
159
+ entry_point: number;
160
+ }
161
+ export interface ContractCallBundleJson {
162
+ contract_id: string;
163
+ entry_point: number;
164
+ }
165
+ export interface ThunkIdNested {
166
+ thunk_id: number;
167
+ }
168
+ export interface ContractCallBundleNested {
169
+ system_call_bundle: ContractCallBundle;
170
+ }
171
+ export declare type SystemCallTarget = ThunkIdNested | ContractCallBundleNested;
172
+ export interface SetSystemCallOperation {
173
+ call_id: number;
174
+ target: SystemCallTarget;
175
+ }
176
+ export interface SetSystemCallOperationJson {
177
+ call_id: number;
178
+ target: number | ContractCallBundleJson;
179
+ }
180
+ export interface UploadContractOperationNested {
181
+ upload_contract: UploadContractOperation;
182
+ }
183
+ export interface CallContractOperationNested {
184
+ call_contract: CallContractOperation;
185
+ }
186
+ export interface SetSystemCallOperationNested {
187
+ set_system_call: SetSystemCallOperation;
188
+ }
189
+ export declare type Operation = UploadContractOperationNested | CallContractOperationNested | SetSystemCallOperationNested;
190
+ export declare type OperationJson = {
191
+ upload_contract?: UploadContractOperationJson;
192
+ call_contract?: CallContractOperationJson;
193
+ set_system_call?: SetSystemCallOperationJson;
194
+ };
195
+ export interface ActiveTransactionData {
196
+ /**
197
+ * Resource credits limit
198
+ */
199
+ rc_limit?: string | number | bigint;
200
+ /**
201
+ * Account nonce
202
+ */
203
+ nonce?: string | number | bigint;
204
+ /**
205
+ * Array of operations
206
+ */
207
+ operations?: Operation[];
208
+ [x: string]: unknown;
209
+ }
210
+ export interface ActiveTransactionDataJson {
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?: OperationJson[];
223
+ [x: string]: unknown;
224
+ }
2
225
  /**
3
226
  * Koinos Transaction
4
227
  */
5
- export interface Transaction {
228
+ export interface TransactionJson {
6
229
  /**
7
230
  * Transaction ID. It must be the sha2-256 of the
8
231
  * serialized data of active data, and encoded in multi base58
@@ -11,55 +234,29 @@ export interface Transaction {
11
234
  /**
12
235
  * Consensus data
13
236
  */
14
- active_data?: {
15
- resource_limit?: string | number | bigint;
16
- /**
17
- * Account nonce
18
- */
19
- nonce?: string | number | bigint;
20
- /**
21
- * Array of operations
22
- */
23
- operations?: {
24
- type: string;
25
- value: unknown;
26
- }[];
27
- [x: string]: unknown;
28
- };
237
+ active?: string;
29
238
  /**
30
239
  * Non-consensus data
31
240
  */
32
- passive_data?: {
33
- [x: string]: unknown;
34
- };
241
+ passive?: string;
35
242
  /**
36
243
  * Signature in compact format enconded in multi base64
37
244
  */
38
245
  signature_data?: string;
39
- [x: string]: unknown;
40
246
  }
41
- export interface BlockHeader {
247
+ export interface BlockHeaderJson {
42
248
  previous?: string;
43
249
  height?: NumberLike;
44
250
  timestamp?: NumberLike;
45
251
  [x: string]: unknown;
46
252
  }
47
- export interface ActiveBlockData {
48
- transaction_merkle_root?: string;
49
- passive_data_merkle_root?: string;
50
- signer?: string;
51
- [x: string]: unknown;
52
- }
53
- export interface PassiveBlockData {
54
- [x: string]: unknown;
55
- }
56
- export interface Block {
253
+ export interface BlockJson {
57
254
  id?: string;
58
- header?: BlockHeader;
59
- active_data?: ActiveBlockData;
60
- passive_data?: PassiveBlockData;
255
+ header?: BlockHeaderJson;
256
+ active?: string;
257
+ passive?: string;
61
258
  signature_data?: string;
62
- transactions?: Transaction[];
259
+ transactions?: TransactionJson[];
63
260
  [x: string]: unknown;
64
261
  }
65
262
  export {};
@@ -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
+ }