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.
- package/README.md +133 -86
- package/dist/koinos.js +12087 -5016
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +135 -230
- package/lib/Contract.js +219 -154
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +43 -18
- package/lib/Provider.js +69 -19
- 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 +170 -18
- package/lib/Signer.js +215 -42
- package/lib/Signer.js.map +1 -1
- package/lib/index.d.ts +2 -10
- package/lib/index.js +5 -12
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -10
- package/lib/index2.js.map +1 -1
- package/lib/interface.d.ts +232 -35
- package/lib/jsonDescriptors/krc20-proto.json +183 -0
- package/lib/jsonDescriptors/protocol-proto.json +246 -0
- package/lib/utils.d.ts +281 -0
- package/lib/utils.js +109 -1
- package/lib/utils.js.map +1 -1
- package/package.json +10 -3
- package/lib/Multihash.d.ts +0 -41
- package/lib/Multihash.js +0 -38
- package/lib/Multihash.js.map +0 -1
- package/lib/VariableBlob.d.ts +0 -35
- package/lib/VariableBlob.js +0 -227
- package/lib/VariableBlob.js.map +0 -1
- package/lib/Wallet.d.ts +0 -250
- package/lib/Wallet.js +0 -301
- package/lib/Wallet.js.map +0 -1
- package/lib/abi.d.ts +0 -177
- package/lib/abi.js +0 -160
- package/lib/abi.js.map +0 -1
- package/lib/serializer.d.ts +0 -41
- package/lib/serializer.js +0 -273
- package/lib/serializer.js.map +0 -1
package/lib/Wallet.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Wallet = void 0;
|
|
7
|
-
const noble_ripemd160_1 = __importDefault(require("noble-ripemd160"));
|
|
8
|
-
const abi_1 = require("./abi");
|
|
9
|
-
const serializer_1 = require("./serializer");
|
|
10
|
-
const VariableBlob_1 = require("./VariableBlob");
|
|
11
|
-
/**
|
|
12
|
-
* The Wallet Class combines all the features of [[Signer]],
|
|
13
|
-
* [[Contract]], and [[Provider]] classes.
|
|
14
|
-
*
|
|
15
|
-
* @example **How to send transactions**
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* (async () => {
|
|
19
|
-
* // define signer, provider, and contract
|
|
20
|
-
* const signer = Signer.fromSeed("my seed");
|
|
21
|
-
* const provider = new Provider("http://45.56.104.152:8080");
|
|
22
|
-
* const contract = new Contract({
|
|
23
|
-
* id: "Mkw96mR+Hh71IWwJoT/2lJXBDl5Q=",
|
|
24
|
-
* entries: {
|
|
25
|
-
* transfer: {
|
|
26
|
-
* id: 0x62efa292,
|
|
27
|
-
* inputs: {
|
|
28
|
-
* type: [
|
|
29
|
-
* {
|
|
30
|
-
* name: "from",
|
|
31
|
-
* type: "string",
|
|
32
|
-
* },
|
|
33
|
-
* {
|
|
34
|
-
* name: "to",
|
|
35
|
-
* type: "string",
|
|
36
|
-
* },
|
|
37
|
-
* {
|
|
38
|
-
* name: "value",
|
|
39
|
-
* type: "uint64",
|
|
40
|
-
* },
|
|
41
|
-
* ],
|
|
42
|
-
* },
|
|
43
|
-
* },
|
|
44
|
-
* balance_of: {
|
|
45
|
-
* id: 0x15619248,
|
|
46
|
-
* inputs: { type: "string" },
|
|
47
|
-
* outputs: { type: "uint64" },
|
|
48
|
-
* },
|
|
49
|
-
* },
|
|
50
|
-
* });
|
|
51
|
-
*
|
|
52
|
-
* // create a wallet with signer, provider and contract
|
|
53
|
-
* const wallet = new Wallet({ signer, provider, contract });
|
|
54
|
-
*
|
|
55
|
-
* // encode a contract operation to make a transfer
|
|
56
|
-
* const opTransfer = wallet.encodeOperation({
|
|
57
|
-
* name: "transfer",
|
|
58
|
-
* args: {
|
|
59
|
-
* from: wallet.getAddress(),
|
|
60
|
-
* to: "bob",
|
|
61
|
-
* value: BigInt(1000),
|
|
62
|
-
* },
|
|
63
|
-
* });
|
|
64
|
-
*
|
|
65
|
-
* // create a transaction
|
|
66
|
-
* const tx = await wallet.newTransaction({
|
|
67
|
-
* operations: [opTransfer],
|
|
68
|
-
* });
|
|
69
|
-
*
|
|
70
|
-
* // sign and send transaction
|
|
71
|
-
* await wallet.signTransaction(tx);
|
|
72
|
-
* await wallet.sendTransaction(tx);
|
|
73
|
-
* })();
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* @example **How to read contracts**
|
|
77
|
-
* ```ts
|
|
78
|
-
* (async () => {
|
|
79
|
-
* // define provider and contract
|
|
80
|
-
* const provider = new Provider("http://45.56.104.152:8080");
|
|
81
|
-
* const contract = new Contract({
|
|
82
|
-
* id: "Mkw96mR+Hh71IWwJoT/2lJXBDl5Q=",
|
|
83
|
-
* entries: {
|
|
84
|
-
* transfer: {
|
|
85
|
-
* id: 0x62efa292,
|
|
86
|
-
* inputs: {
|
|
87
|
-
* type: [
|
|
88
|
-
* {
|
|
89
|
-
* name: "from",
|
|
90
|
-
* type: "string",
|
|
91
|
-
* },
|
|
92
|
-
* {
|
|
93
|
-
* name: "to",
|
|
94
|
-
* type: "string",
|
|
95
|
-
* },
|
|
96
|
-
* {
|
|
97
|
-
* name: "value",
|
|
98
|
-
* type: "uint64",
|
|
99
|
-
* },
|
|
100
|
-
* ],
|
|
101
|
-
* },
|
|
102
|
-
* },
|
|
103
|
-
* balance_of: {
|
|
104
|
-
* id: 0x15619248,
|
|
105
|
-
* inputs: { type: "string" },
|
|
106
|
-
* outputs: { type: "uint64" },
|
|
107
|
-
* },
|
|
108
|
-
* },
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* // create a wallet with provider and contract (signer is optional)
|
|
112
|
-
* const wallet = new Wallet({ provider, contract });
|
|
113
|
-
*
|
|
114
|
-
* // read the contract providing the name of the contract funtion
|
|
115
|
-
* // and its arguments
|
|
116
|
-
* const balance = await wallet.readContract({
|
|
117
|
-
* name: "balance_of",
|
|
118
|
-
* args: wallet.getAddress(),
|
|
119
|
-
* });
|
|
120
|
-
*
|
|
121
|
-
* console.log(Number(balance) / 1e8);
|
|
122
|
-
* })();
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* @example **How to upload contracts**
|
|
126
|
-
* ```ts
|
|
127
|
-
* (async () => {
|
|
128
|
-
* // define signer, provider and wallet
|
|
129
|
-
* const signer = Signer.fromSeed("my seed");
|
|
130
|
-
* const provider = new Provider("http://45.56.104.152:8080");
|
|
131
|
-
* const wallet = new Wallet({ signer, provider });
|
|
132
|
-
*
|
|
133
|
-
* // encode operation to upload the contract
|
|
134
|
-
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
135
|
-
* const op = wallet.encodeUploadContractOperation(bytecode);
|
|
136
|
-
*
|
|
137
|
-
* // create a transaction
|
|
138
|
-
* const tx = await wallet.newTransaction({
|
|
139
|
-
* operations: [op],
|
|
140
|
-
* });
|
|
141
|
-
*
|
|
142
|
-
* // sign and send transaction
|
|
143
|
-
* await wallet.signTransaction(tx);
|
|
144
|
-
* await wallet.sendTransaction(tx);
|
|
145
|
-
* })();
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
class Wallet {
|
|
149
|
-
constructor(opts = {
|
|
150
|
-
signer: undefined,
|
|
151
|
-
contract: undefined,
|
|
152
|
-
provider: undefined,
|
|
153
|
-
}) {
|
|
154
|
-
this.signer = opts.signer;
|
|
155
|
-
this.contract = opts.contract;
|
|
156
|
-
this.provider = opts.provider;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Creates an unsigned transaction
|
|
160
|
-
*/
|
|
161
|
-
async newTransaction(opts) {
|
|
162
|
-
let nonce;
|
|
163
|
-
if (opts.getNonce === false)
|
|
164
|
-
nonce = 0;
|
|
165
|
-
else {
|
|
166
|
-
if (!this.provider)
|
|
167
|
-
throw new Error("Cannot get the nonce because provider is undefined. To ignore this call use getNonce:false in the parameters");
|
|
168
|
-
nonce = await this.getNonce(this.getAddress());
|
|
169
|
-
}
|
|
170
|
-
const resourceLimit = opts.resource_limit === undefined ? 1000000 : opts.resource_limit;
|
|
171
|
-
const operations = opts.operations ? opts.operations : [];
|
|
172
|
-
return {
|
|
173
|
-
active_data: {
|
|
174
|
-
resource_limit: resourceLimit,
|
|
175
|
-
nonce,
|
|
176
|
-
operations,
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* The current implementation of Koinos expects a contract Id
|
|
182
|
-
* derived from the account deploying the contract:
|
|
183
|
-
* contractId = ripemd160(address serialized)
|
|
184
|
-
* @returns contract id derived from address
|
|
185
|
-
*/
|
|
186
|
-
static computeContractId(address) {
|
|
187
|
-
const signerHash = noble_ripemd160_1.default(serializer_1.serialize(address, { type: "string" }).buffer);
|
|
188
|
-
return new VariableBlob_1.VariableBlob(signerHash).toString();
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Function to encode an operation to upload or update a contract
|
|
192
|
-
* @param bytecode - bytecode in multibase64 or Uint8Array
|
|
193
|
-
*/
|
|
194
|
-
encodeUploadContractOperation(bytecode) {
|
|
195
|
-
if (!this.signer)
|
|
196
|
-
throw new Error("Signer is undefined");
|
|
197
|
-
const bytecodeBase64 = typeof bytecode === "string"
|
|
198
|
-
? bytecode
|
|
199
|
-
: new VariableBlob_1.VariableBlob(bytecode).toString();
|
|
200
|
-
return {
|
|
201
|
-
type: abi_1.abiUploadContractOperation.name,
|
|
202
|
-
value: {
|
|
203
|
-
contract_id: Wallet.computeContractId(this.getAddress()),
|
|
204
|
-
bytecode: bytecodeBase64,
|
|
205
|
-
extensions: {},
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
// Signer
|
|
210
|
-
/**
|
|
211
|
-
* See [[Signer.getAddress]]
|
|
212
|
-
*/
|
|
213
|
-
getAddress(compressed) {
|
|
214
|
-
if (!this.signer)
|
|
215
|
-
throw new Error("Signer is undefined");
|
|
216
|
-
return this.signer.getAddress(compressed);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* See [[Signer.signTransaction]]
|
|
220
|
-
*/
|
|
221
|
-
async signTransaction(tx) {
|
|
222
|
-
if (!this.signer)
|
|
223
|
-
throw new Error("Signer is undefined");
|
|
224
|
-
return this.signer.signTransaction(tx);
|
|
225
|
-
}
|
|
226
|
-
// Contract
|
|
227
|
-
/**
|
|
228
|
-
* See [[Contract.encodeOperation]]
|
|
229
|
-
*/
|
|
230
|
-
encodeOperation(op) {
|
|
231
|
-
if (!this.contract)
|
|
232
|
-
throw new Error("Contract is undefined");
|
|
233
|
-
return this.contract.encodeOperation(op);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* See [[Contract.decodeOperation]]
|
|
237
|
-
*/
|
|
238
|
-
decodeOperation(op) {
|
|
239
|
-
if (!this.contract)
|
|
240
|
-
throw new Error("Contract is undefined");
|
|
241
|
-
return this.contract.decodeOperation(op);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* See [[Contract.decodeResult]]
|
|
245
|
-
*/
|
|
246
|
-
decodeResult(result, opName) {
|
|
247
|
-
if (!this.contract)
|
|
248
|
-
throw new Error("Contract is undefined");
|
|
249
|
-
return this.contract.decodeResult(result, opName);
|
|
250
|
-
}
|
|
251
|
-
// Provider
|
|
252
|
-
/**
|
|
253
|
-
* See [[Provider.call]]
|
|
254
|
-
*/
|
|
255
|
-
async call(method, params) {
|
|
256
|
-
if (!this.provider)
|
|
257
|
-
throw new Error("Provider is undefined");
|
|
258
|
-
return this.provider.call(method, params);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* See [[Provider.getNonce]]
|
|
262
|
-
*/
|
|
263
|
-
async getNonce(address) {
|
|
264
|
-
if (!this.provider)
|
|
265
|
-
throw new Error("Provider is undefined");
|
|
266
|
-
return this.provider.getNonce(address);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* See [[Provider.sendTransaction]]
|
|
270
|
-
*/
|
|
271
|
-
async sendTransaction(transaction) {
|
|
272
|
-
if (!this.provider)
|
|
273
|
-
throw new Error("Provider is undefined");
|
|
274
|
-
return this.provider.sendTransaction(transaction);
|
|
275
|
-
}
|
|
276
|
-
// Provider + Contract
|
|
277
|
-
/**
|
|
278
|
-
* Call the RPC node to read a contract. The operation to read
|
|
279
|
-
* must be in the decoded format (see [[DecodedOperation]]). This
|
|
280
|
-
* function will encode the operation using the contract definition,
|
|
281
|
-
* call the RPC node, and decode the result.
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```
|
|
285
|
-
* const balance = await wallet.readContract({
|
|
286
|
-
* name: "balance_of",
|
|
287
|
-
* args: "126LgExvJrLDQBsxA1Ddur2VjXJkyAbG91",
|
|
288
|
-
* });
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
|
-
async readContract(operation) {
|
|
292
|
-
if (!this.provider)
|
|
293
|
-
throw new Error("Provider is undefined");
|
|
294
|
-
const op = this.encodeOperation(operation);
|
|
295
|
-
const { result } = await this.provider.readContract(op);
|
|
296
|
-
return this.decodeResult(result, operation.name);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.Wallet = Wallet;
|
|
300
|
-
exports.default = Wallet;
|
|
301
|
-
//# sourceMappingURL=Wallet.js.map
|
package/lib/Wallet.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Wallet.js","sourceRoot":"","sources":["../src/Wallet.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAwC;AACxC,+BAAmD;AAInD,6CAAyC;AAEzC,iDAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B;QAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC7D,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;CACF;AAnND,wBAmNC;AAED,kBAAe,MAAM,CAAC"}
|
package/lib/abi.d.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Application Binary Interface (ABI)
|
|
3
|
-
*
|
|
4
|
-
* Set of definitions to tell to the library how to serialize
|
|
5
|
-
* and deserialize data in Koinos.
|
|
6
|
-
*
|
|
7
|
-
* @example **Example for Structs:**
|
|
8
|
-
* Suppose that the c++ contract has a struct for transfers
|
|
9
|
-
* defined as
|
|
10
|
-
*
|
|
11
|
-
* ```cpp
|
|
12
|
-
* struct transfer_args
|
|
13
|
-
* {
|
|
14
|
-
* protocol::account_type from;
|
|
15
|
-
* protocol::account_type to;
|
|
16
|
-
* uint64_t value;
|
|
17
|
-
* };
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* <br>
|
|
21
|
-
*
|
|
22
|
-
* Then, it's ABI can be defined as
|
|
23
|
-
* ```ts
|
|
24
|
-
* const abi = [{
|
|
25
|
-
* name: "from",
|
|
26
|
-
* type: "string",
|
|
27
|
-
* },{
|
|
28
|
-
* name: "to",
|
|
29
|
-
* type: "string",
|
|
30
|
-
* },{
|
|
31
|
-
* name: "from",
|
|
32
|
-
* type: "uint64",
|
|
33
|
-
* }]
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example **Example using the definition of active data:**
|
|
37
|
-
* The ABI can be defined at a great level of detail. This
|
|
38
|
-
* example shows the ABI of the Active Data of a Transaction,
|
|
39
|
-
* which is a complex structure as it contains vectors, variants,
|
|
40
|
-
* nested structures, and opaque objects. See also [[abiActiveData]]
|
|
41
|
-
*
|
|
42
|
-
* The Active data is defined in c++ as:
|
|
43
|
-
* ```cpp
|
|
44
|
-
* struct upload_contract_operation
|
|
45
|
-
* {
|
|
46
|
-
* contract_id_type contract_id;
|
|
47
|
-
* variable_blob bytecode;
|
|
48
|
-
* unused_extensions_type extensions;
|
|
49
|
-
* };
|
|
50
|
-
*
|
|
51
|
-
* struct set_system_call_operation
|
|
52
|
-
* {
|
|
53
|
-
* uint32 call_id;
|
|
54
|
-
* chain::system_call_target target;
|
|
55
|
-
* unused_extensions_type extensions;
|
|
56
|
-
* };
|
|
57
|
-
*
|
|
58
|
-
* struct call_contract_operation
|
|
59
|
-
* {
|
|
60
|
-
* contract_id_type contract_id;
|
|
61
|
-
* uint32 entry_point;
|
|
62
|
-
* variable_blob args;
|
|
63
|
-
* unused_extensions_type extensions;
|
|
64
|
-
* };
|
|
65
|
-
*
|
|
66
|
-
* typedef std::variant<
|
|
67
|
-
* reserved_operation,
|
|
68
|
-
* nop_operation,
|
|
69
|
-
* upload_contract_operation,
|
|
70
|
-
* call_contract_operation,
|
|
71
|
-
* set_system_call_operation
|
|
72
|
-
* > operation;
|
|
73
|
-
*
|
|
74
|
-
* struct active_transaction_data
|
|
75
|
-
* {
|
|
76
|
-
* uint128 resource_limit;
|
|
77
|
-
* uint64 nonce;
|
|
78
|
-
* std::vector< operation > operations;
|
|
79
|
-
* };
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* <br>
|
|
83
|
-
*
|
|
84
|
-
* It's ABI can be defined as
|
|
85
|
-
* ```ts
|
|
86
|
-
* const abiActiveData: Abi = {
|
|
87
|
-
* name: "opaque_active_data",
|
|
88
|
-
* type: "opaque",
|
|
89
|
-
* subAbi: {
|
|
90
|
-
* name: "active_data",
|
|
91
|
-
* type: [
|
|
92
|
-
* {
|
|
93
|
-
* name: "resource_limit",
|
|
94
|
-
* type: "uint128",
|
|
95
|
-
* },
|
|
96
|
-
* {
|
|
97
|
-
* name: "nonce",
|
|
98
|
-
* type: "uint64",
|
|
99
|
-
* },
|
|
100
|
-
* {
|
|
101
|
-
* name: "operations",
|
|
102
|
-
* type: "vector",
|
|
103
|
-
* subAbi: {
|
|
104
|
-
* name: "operation",
|
|
105
|
-
* type: "variant",
|
|
106
|
-
* variants: [
|
|
107
|
-
* { type: "not implemented" }, // abi for reserved operation
|
|
108
|
-
* { type: "not implemented" }, // abi for nop operation
|
|
109
|
-
* { type: "not implemented" }, // abi for upload contract operation
|
|
110
|
-
* { type: "not implemented" }, // abi for call contract operation
|
|
111
|
-
* { type: "not implemented" }, // abi for set system call operation
|
|
112
|
-
* ],
|
|
113
|
-
* },
|
|
114
|
-
* },
|
|
115
|
-
* ],
|
|
116
|
-
* },
|
|
117
|
-
* };
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export interface Abi {
|
|
121
|
-
/**
|
|
122
|
-
* Type of the ABI
|
|
123
|
-
*
|
|
124
|
-
* For structs it should be an array of Abis. Otherwise it should
|
|
125
|
-
* be one of the supported types: opaque, vector, variant, variableblob,
|
|
126
|
-
* fixedblob, string, varint, uint8, uint16, uint32, uint64, uint128,
|
|
127
|
-
* uint160, uint256, int8, int16, int32, int64, int128, int160, int256,
|
|
128
|
-
* unused_extension.
|
|
129
|
-
*/
|
|
130
|
-
type: string | Abi[];
|
|
131
|
-
/**
|
|
132
|
-
* Name of the ABI
|
|
133
|
-
*/
|
|
134
|
-
name?: string;
|
|
135
|
-
/**
|
|
136
|
-
* Fixedblob size. Applicable only for type: "fixedblob"
|
|
137
|
-
*/
|
|
138
|
-
size?: number;
|
|
139
|
-
/**
|
|
140
|
-
* Sub ABI. Applicable only for type "opaque" or "vector"
|
|
141
|
-
*/
|
|
142
|
-
subAbi?: Abi;
|
|
143
|
-
/**
|
|
144
|
-
* ABI variants. Applicable only for type "variant"
|
|
145
|
-
*/
|
|
146
|
-
variants?: Abi[];
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* ABI of Reserved Operation. This abi is used in the
|
|
150
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
151
|
-
*/
|
|
152
|
-
export declare const abiReservedOperation: Abi;
|
|
153
|
-
/**
|
|
154
|
-
* ABI of Nop Operation. This abi is used in the
|
|
155
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
156
|
-
*/
|
|
157
|
-
export declare const abiNopOperation: Abi;
|
|
158
|
-
/**
|
|
159
|
-
* ABI of Upload Contract Operation. This abi is used in the
|
|
160
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
161
|
-
*/
|
|
162
|
-
export declare const abiUploadContractOperation: Abi;
|
|
163
|
-
/**
|
|
164
|
-
* ABI of Set System Call Operation. This abi is used in the
|
|
165
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
166
|
-
*/
|
|
167
|
-
export declare const abiSetSystemCallOperation: Abi;
|
|
168
|
-
/**
|
|
169
|
-
* ABI of Call Contract Operation. This abi is used in the
|
|
170
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
171
|
-
*/
|
|
172
|
-
export declare const abiCallContractOperation: Abi;
|
|
173
|
-
/**
|
|
174
|
-
* ABI of Active Data of a Transaction. This abi is used in the
|
|
175
|
-
* [[Signer]] class to sign transactions.
|
|
176
|
-
*/
|
|
177
|
-
export declare const abiActiveData: Abi;
|
package/lib/abi.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.abiActiveData = exports.abiCallContractOperation = exports.abiSetSystemCallOperation = exports.abiUploadContractOperation = exports.abiNopOperation = exports.abiReservedOperation = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* ABI of Reserved Operation. This abi is used in the
|
|
6
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
7
|
-
*/
|
|
8
|
-
exports.abiReservedOperation = {
|
|
9
|
-
name: "koinos::protocol::reserved_operation",
|
|
10
|
-
type: [
|
|
11
|
-
{
|
|
12
|
-
name: "extensions",
|
|
13
|
-
type: "unused_extension",
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* ABI of Nop Operation. This abi is used in the
|
|
19
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
20
|
-
*/
|
|
21
|
-
exports.abiNopOperation = {
|
|
22
|
-
name: "koinos::protocol::nop_operation",
|
|
23
|
-
type: [
|
|
24
|
-
{
|
|
25
|
-
name: "extensions",
|
|
26
|
-
type: "unused_extension",
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* ABI of Upload Contract Operation. This abi is used in the
|
|
32
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
33
|
-
*/
|
|
34
|
-
exports.abiUploadContractOperation = {
|
|
35
|
-
name: "koinos::protocol::upload_contract_operation",
|
|
36
|
-
type: [
|
|
37
|
-
{
|
|
38
|
-
name: "contract_id",
|
|
39
|
-
type: "fixedblob",
|
|
40
|
-
size: 20,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "bytecode",
|
|
44
|
-
type: "variableblob",
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "extensions",
|
|
48
|
-
type: "unused_extension",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
const abiSystemCallTargetReserved = {
|
|
53
|
-
type: [],
|
|
54
|
-
};
|
|
55
|
-
const abiThunkId = {
|
|
56
|
-
type: "uint32",
|
|
57
|
-
};
|
|
58
|
-
const abiContractCallBundle = {
|
|
59
|
-
type: [
|
|
60
|
-
{
|
|
61
|
-
name: "contract_id",
|
|
62
|
-
type: "fixedblob",
|
|
63
|
-
size: 20,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: "entry_point",
|
|
67
|
-
type: "uint32",
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* ABI of Set System Call Operation. This abi is used in the
|
|
73
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
74
|
-
*/
|
|
75
|
-
exports.abiSetSystemCallOperation = {
|
|
76
|
-
name: "koinos::protocol::set_system_call_operation",
|
|
77
|
-
type: [
|
|
78
|
-
{
|
|
79
|
-
name: "call_id",
|
|
80
|
-
type: "uint32",
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
// chain::sytem_call_target
|
|
84
|
-
name: "target",
|
|
85
|
-
type: "variant",
|
|
86
|
-
variants: [
|
|
87
|
-
abiSystemCallTargetReserved,
|
|
88
|
-
abiThunkId,
|
|
89
|
-
abiContractCallBundle,
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "extensions",
|
|
94
|
-
type: "unused_extension",
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* ABI of Call Contract Operation. This abi is used in the
|
|
100
|
-
* definition of the Active Data ABI. See [[abiActiveData]]
|
|
101
|
-
*/
|
|
102
|
-
exports.abiCallContractOperation = {
|
|
103
|
-
name: "koinos::protocol::call_contract_operation",
|
|
104
|
-
type: [
|
|
105
|
-
{
|
|
106
|
-
name: "contract_id",
|
|
107
|
-
type: "fixedblob",
|
|
108
|
-
size: 20,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: "entry_point",
|
|
112
|
-
type: "uint32",
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "args",
|
|
116
|
-
type: "variableblob",
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: "extensions",
|
|
120
|
-
type: "unused_extension",
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* ABI of Active Data of a Transaction. This abi is used in the
|
|
126
|
-
* [[Signer]] class to sign transactions.
|
|
127
|
-
*/
|
|
128
|
-
exports.abiActiveData = {
|
|
129
|
-
name: "opaque_active_data",
|
|
130
|
-
type: "opaque",
|
|
131
|
-
subAbi: {
|
|
132
|
-
name: "active_data",
|
|
133
|
-
type: [
|
|
134
|
-
{
|
|
135
|
-
name: "resource_limit",
|
|
136
|
-
type: "uint128",
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: "nonce",
|
|
140
|
-
type: "uint64",
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
name: "operations",
|
|
144
|
-
type: "vector",
|
|
145
|
-
subAbi: {
|
|
146
|
-
name: "operation",
|
|
147
|
-
type: "variant",
|
|
148
|
-
variants: [
|
|
149
|
-
exports.abiReservedOperation,
|
|
150
|
-
exports.abiNopOperation,
|
|
151
|
-
exports.abiUploadContractOperation,
|
|
152
|
-
exports.abiCallContractOperation,
|
|
153
|
-
exports.abiSetSystemCallOperation,
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
//# sourceMappingURL=abi.js.map
|
package/lib/abi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":";;;AAwJA;;;GAGG;AACU,QAAA,oBAAoB,GAAQ;IACvC,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EAAE;QACJ;YACE,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,kBAAkB;SACzB;KACF;CACF,CAAC;AAEF;;;GAGG;AACU,QAAA,eAAe,GAAQ;IAClC,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE;QACJ;YACE,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,kBAAkB;SACzB;KACF;CACF,CAAC;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E,MAAM;YACZ,IAAI,EAAE,cAAc;SACrB;QACD;YACE,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,kBAAkB;SACzB;KACF;CACF,CAAC;AAEF;;;GAGG;AACU,QAAA,aAAa,GAAQ;IAChC,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE;QACN,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE;YACJ;gBACE,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,QAAQ;aACf;YACD;gBACE,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE;oBACN,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE;wBACR,4BAAoB;wBACpB,uBAAe;wBACf,kCAA0B;wBAC1B,gCAAwB;wBACxB,iCAAyB;qBAC1B;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
package/lib/serializer.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Abi } from "./abi";
|
|
2
|
-
import { VariableBlob } from "./VariableBlob";
|
|
3
|
-
/**
|
|
4
|
-
* Function to serialize data
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const abi = { type: "uint64" };
|
|
9
|
-
* const vblob = serialize(5869, abi);
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const abi = {
|
|
15
|
-
* type: [
|
|
16
|
-
* { name: "from", type: "string" },
|
|
17
|
-
* { name: "to", type: "string" },
|
|
18
|
-
* { name: "value", type: "uint64" },
|
|
19
|
-
* ],
|
|
20
|
-
* };
|
|
21
|
-
* const vblob = serialize({
|
|
22
|
-
* from: "alice",
|
|
23
|
-
* to: "bob",
|
|
24
|
-
* value: "123456",
|
|
25
|
-
* }, abi);
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare function serialize(data: unknown, abi: Abi): VariableBlob;
|
|
29
|
-
/**
|
|
30
|
-
* Function to deserialize data
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const vblob = new VariableBlob(
|
|
35
|
-
* new Uint8Array([0, 0, 0, 0, 0, 0, 22, 237])
|
|
36
|
-
* );
|
|
37
|
-
* const abi = { type: "uint64" };
|
|
38
|
-
* const number = deserialize(vblob, abi);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function deserialize(buffer: VariableBlob | string, abi: Abi): unknown;
|