koilib 3.0.0 → 4.0.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 +39 -27
- package/dist/koinos.js +252 -200
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +28 -19
- package/lib/Contract.js +47 -52
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +7 -5
- package/lib/Provider.js +24 -15
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +2 -1
- package/lib/Serializer.js +96 -89
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +17 -5
- package/lib/Signer.js +15 -6
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +28 -19
- package/lib/browser/Contract.js +47 -52
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Provider.d.ts +7 -5
- package/lib/browser/Provider.js +24 -15
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/Serializer.d.ts +2 -1
- package/lib/browser/Serializer.js +96 -89
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.d.ts +17 -5
- package/lib/browser/Signer.js +15 -6
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/interface.d.ts +45 -25
- package/lib/browser/jsonDescriptors/{krc20-proto.json → token-proto.json} +0 -0
- package/lib/browser/utils.d.ts +3 -3
- package/lib/browser/utils.js +69 -37
- package/lib/browser/utils.js.map +1 -1
- package/lib/interface.d.ts +45 -25
- package/lib/jsonDescriptors/{krc20-proto.json → token-proto.json} +0 -0
- package/lib/utils.d.ts +3 -3
- package/lib/utils.js +69 -37
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/koinos.js
CHANGED
|
@@ -9785,21 +9785,21 @@ const utils_1 = __webpack_require__(8593);
|
|
|
9785
9785
|
* const signer = new Signer({ privateKey, provider });
|
|
9786
9786
|
* const koinContract = new Contract({
|
|
9787
9787
|
* id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
9788
|
-
* abi: utils.
|
|
9788
|
+
* abi: utils.tokenAbi,
|
|
9789
9789
|
* provider,
|
|
9790
9790
|
* signer,
|
|
9791
9791
|
* });
|
|
9792
9792
|
* const koin = koinContract.functions;
|
|
9793
9793
|
*
|
|
9794
|
-
* // optional: preformat
|
|
9795
|
-
* koinContract.abi.methods.balanceOf.
|
|
9794
|
+
* // optional: preformat argument/return
|
|
9795
|
+
* koinContract.abi.methods.balanceOf.preformat_argument = (owner) =>
|
|
9796
9796
|
* ({ owner });
|
|
9797
|
-
* koinContract.abi.methods.balanceOf.
|
|
9797
|
+
* koinContract.abi.methods.balanceOf.preformat_return = (res) =>
|
|
9798
9798
|
* utils.formatUnits(res.value, 8);
|
|
9799
|
-
* koinContract.abi.methods.transfer.
|
|
9799
|
+
* koinContract.abi.methods.transfer.preformat_argument = (arg) => ({
|
|
9800
9800
|
* from: signer.getAddress(),
|
|
9801
|
-
* to:
|
|
9802
|
-
* value: utils.parseUnits(
|
|
9801
|
+
* to: arg.to,
|
|
9802
|
+
* value: utils.parseUnits(arg.value, 8),
|
|
9803
9803
|
* });
|
|
9804
9804
|
*
|
|
9805
9805
|
* async funtion main() {
|
|
@@ -9808,11 +9808,16 @@ const utils_1 = __webpack_require__(8593);
|
|
|
9808
9808
|
* console.log(result)
|
|
9809
9809
|
*
|
|
9810
9810
|
* // Transfer
|
|
9811
|
-
* const { transaction } = await koin.transfer({
|
|
9811
|
+
* const { transaction, receipt } = await koin.transfer({
|
|
9812
9812
|
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
9813
9813
|
* value: "10.0001",
|
|
9814
9814
|
* });
|
|
9815
|
-
* console.log(`Transaction id ${transaction.id} submitted
|
|
9815
|
+
* console.log(`Transaction id ${transaction.id} submitted. Receipt:`);
|
|
9816
|
+
* console.log(receipt);
|
|
9817
|
+
*
|
|
9818
|
+
* if (receipt.logs) {
|
|
9819
|
+
* console.log(`Transfer failed. Logs: ${receipt.logs.join(",")}`);
|
|
9820
|
+
* }
|
|
9816
9821
|
*
|
|
9817
9822
|
* // wait to be mined
|
|
9818
9823
|
* const blockNumber = await transaction.wait();
|
|
@@ -9834,8 +9839,8 @@ class Contract {
|
|
|
9834
9839
|
if (c.serializer) {
|
|
9835
9840
|
this.serializer = c.serializer;
|
|
9836
9841
|
}
|
|
9837
|
-
else if (c.abi && c.abi.
|
|
9838
|
-
this.serializer = new Serializer_1.Serializer(c.abi.
|
|
9842
|
+
else if (c.abi && c.abi.koilib_types) {
|
|
9843
|
+
this.serializer = new Serializer_1.Serializer(c.abi.koilib_types);
|
|
9839
9844
|
}
|
|
9840
9845
|
this.options = {
|
|
9841
9846
|
signTransaction: true,
|
|
@@ -9861,10 +9866,10 @@ class Contract {
|
|
|
9861
9866
|
...this.options,
|
|
9862
9867
|
...options,
|
|
9863
9868
|
};
|
|
9864
|
-
const { readOnly, output, defaultOutput,
|
|
9869
|
+
const { read_only: readOnly, return: output, default_output: defaultOutput, preformat_argument: preformatArgument, preformat_return: preformatReturn, } = this.abi.methods[name];
|
|
9865
9870
|
let args;
|
|
9866
|
-
if (typeof
|
|
9867
|
-
args =
|
|
9871
|
+
if (typeof preformatArgument === "function") {
|
|
9872
|
+
args = preformatArgument(argu);
|
|
9868
9873
|
}
|
|
9869
9874
|
else {
|
|
9870
9875
|
args = argu;
|
|
@@ -9874,17 +9879,13 @@ class Contract {
|
|
|
9874
9879
|
if (!output)
|
|
9875
9880
|
throw new Error(`No output defined for ${name}`);
|
|
9876
9881
|
// read contract
|
|
9877
|
-
const { result: resultEncoded } = await this.provider.readContract(
|
|
9878
|
-
contract_id: (0, utils_1.encodeBase58)(operation.call_contract.contract_id),
|
|
9879
|
-
entry_point: operation.call_contract.entry_point,
|
|
9880
|
-
args: (0, utils_1.encodeBase64url)(operation.call_contract.args),
|
|
9881
|
-
});
|
|
9882
|
+
const { result: resultEncoded } = await this.provider.readContract(operation.call_contract);
|
|
9882
9883
|
let result = defaultOutput;
|
|
9883
9884
|
if (resultEncoded) {
|
|
9884
9885
|
result = await this.serializer.deserialize(resultEncoded, output);
|
|
9885
9886
|
}
|
|
9886
|
-
if (typeof
|
|
9887
|
-
result =
|
|
9887
|
+
if (typeof preformatReturn === "function") {
|
|
9888
|
+
result = preformatReturn(result);
|
|
9888
9889
|
}
|
|
9889
9890
|
return { operation, result };
|
|
9890
9891
|
}
|
|
@@ -9899,15 +9900,7 @@ class Contract {
|
|
|
9899
9900
|
...((opts === null || opts === void 0 ? void 0 : opts.payer) && { payer: opts === null || opts === void 0 ? void 0 : opts.payer }),
|
|
9900
9901
|
...((opts === null || opts === void 0 ? void 0 : opts.payee) && { payee: opts === null || opts === void 0 ? void 0 : opts.payee }),
|
|
9901
9902
|
},
|
|
9902
|
-
operations: [
|
|
9903
|
-
{
|
|
9904
|
-
call_contract: {
|
|
9905
|
-
contract_id: (0, utils_1.encodeBase58)(operation.call_contract.contract_id),
|
|
9906
|
-
entry_point: operation.call_contract.entry_point,
|
|
9907
|
-
args: (0, utils_1.encodeBase64url)(operation.call_contract.args),
|
|
9908
|
-
},
|
|
9909
|
-
},
|
|
9910
|
-
],
|
|
9903
|
+
operations: [operation],
|
|
9911
9904
|
});
|
|
9912
9905
|
const abis = {};
|
|
9913
9906
|
if (opts === null || opts === void 0 ? void 0 : opts.sendAbis) {
|
|
@@ -9923,8 +9916,8 @@ class Contract {
|
|
|
9923
9916
|
await this.signer.signTransaction(tx, abis);
|
|
9924
9917
|
return { operation, transaction: { ...tx, wait: noWait } };
|
|
9925
9918
|
}
|
|
9926
|
-
const transaction = await this.signer.sendTransaction(tx, abis);
|
|
9927
|
-
return { operation, transaction };
|
|
9919
|
+
const { transaction, receipt } = await this.signer.sendTransaction(tx, abis);
|
|
9920
|
+
return { operation, transaction, receipt };
|
|
9928
9921
|
};
|
|
9929
9922
|
});
|
|
9930
9923
|
}
|
|
@@ -9947,7 +9940,8 @@ class Contract {
|
|
|
9947
9940
|
* const signer = new Signer({ privateKey, provider });
|
|
9948
9941
|
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
9949
9942
|
* const contract = new Contract({ signer, provider, bytecode });
|
|
9950
|
-
* const { transaction } = await contract.deploy();
|
|
9943
|
+
* const { transaction, receipt } = await contract.deploy();
|
|
9944
|
+
* console.log(receipt);
|
|
9951
9945
|
* // wait to be mined
|
|
9952
9946
|
* const blockNumber = await transaction.wait();
|
|
9953
9947
|
* console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
@@ -9955,7 +9949,7 @@ class Contract {
|
|
|
9955
9949
|
*
|
|
9956
9950
|
* @example using options
|
|
9957
9951
|
* ```ts
|
|
9958
|
-
* const { transaction } = await contract.deploy({
|
|
9952
|
+
* const { transaction, receipt } = await contract.deploy({
|
|
9959
9953
|
* // contract options
|
|
9960
9954
|
* abi: "CssCChRrb2lub3Mvb3B0aW9ucy5wc...",
|
|
9961
9955
|
* authorizesCallContract: true,
|
|
@@ -9973,6 +9967,7 @@ class Contract {
|
|
|
9973
9967
|
* signTransaction: true,
|
|
9974
9968
|
* sendTransaction: true,
|
|
9975
9969
|
* });
|
|
9970
|
+
* console.log(receipt);
|
|
9976
9971
|
* // wait to be mined
|
|
9977
9972
|
* const blockNumber = await transaction.wait();
|
|
9978
9973
|
* console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
@@ -10029,8 +10024,8 @@ class Contract {
|
|
|
10029
10024
|
await this.signer.signTransaction(tx);
|
|
10030
10025
|
return { operation, transaction: { ...tx, wait: noWait } };
|
|
10031
10026
|
}
|
|
10032
|
-
const transaction = await this.signer.sendTransaction(tx);
|
|
10033
|
-
return { operation, transaction };
|
|
10027
|
+
const { transaction, receipt } = await this.signer.sendTransaction(tx);
|
|
10028
|
+
return { operation, transaction, receipt };
|
|
10034
10029
|
}
|
|
10035
10030
|
/**
|
|
10036
10031
|
* Encondes a contract operation using Koinos serialization
|
|
@@ -10052,8 +10047,8 @@ class Contract {
|
|
|
10052
10047
|
* // {
|
|
10053
10048
|
* // call_contract: {
|
|
10054
10049
|
* // contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
10055
|
-
* // entry_point:
|
|
10056
|
-
* // args: "
|
|
10050
|
+
* // entry_point: 670398154,
|
|
10051
|
+
* // args: "ChkAEjl6vrl55V2Oym_rzsnMxIqBoie9PHmMEhkAQgjT1UACatdFY3e5QRkyG7OAzwcCCIylGOgH",
|
|
10057
10052
|
* // }
|
|
10058
10053
|
* // }
|
|
10059
10054
|
* ```
|
|
@@ -10066,17 +10061,17 @@ class Contract {
|
|
|
10066
10061
|
if (!this.id)
|
|
10067
10062
|
throw new Error("Contract id is not defined");
|
|
10068
10063
|
const method = this.abi.methods[op.name];
|
|
10069
|
-
let
|
|
10070
|
-
if (method.
|
|
10064
|
+
let bufferArguments = new Uint8Array(0);
|
|
10065
|
+
if (method.argument) {
|
|
10071
10066
|
if (!op.args)
|
|
10072
|
-
throw new Error(`No arguments defined for type '${method.
|
|
10073
|
-
|
|
10067
|
+
throw new Error(`No arguments defined for type '${method.argument}'`);
|
|
10068
|
+
bufferArguments = await this.serializer.serialize(op.args, method.argument);
|
|
10074
10069
|
}
|
|
10075
10070
|
return {
|
|
10076
10071
|
call_contract: {
|
|
10077
|
-
contract_id: this.id,
|
|
10078
|
-
entry_point: method.
|
|
10079
|
-
args:
|
|
10072
|
+
contract_id: (0, utils_1.encodeBase58)(this.id),
|
|
10073
|
+
entry_point: method.entry_point,
|
|
10074
|
+
args: (0, utils_1.encodeBase64url)(bufferArguments),
|
|
10080
10075
|
},
|
|
10081
10076
|
};
|
|
10082
10077
|
}
|
|
@@ -10087,8 +10082,8 @@ class Contract {
|
|
|
10087
10082
|
* const opDecoded = contract.decodeOperation({
|
|
10088
10083
|
* call_contract: {
|
|
10089
10084
|
* contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
10090
|
-
* entry_point:
|
|
10091
|
-
* args: "
|
|
10085
|
+
* entry_point: 0x27f576ca,
|
|
10086
|
+
* args: "ChkAEjl6vrl55V2Oym_rzsnMxIqBoie9PHmMEhkAQgjT1UACatdFY3e5QRkyG7OAzwcCCIylGOgH",
|
|
10092
10087
|
* }
|
|
10093
10088
|
* });
|
|
10094
10089
|
* console.log(opDecoded);
|
|
@@ -10111,17 +10106,17 @@ class Contract {
|
|
|
10111
10106
|
throw new Error("Serializer is not defined");
|
|
10112
10107
|
if (!op.call_contract)
|
|
10113
10108
|
throw new Error("Operation is not CallContractOperation");
|
|
10114
|
-
if (
|
|
10115
|
-
throw new Error(`Invalid contract id. Expected: ${(0, utils_1.encodeBase58)(this.id)}. Received: ${
|
|
10109
|
+
if (op.call_contract.contract_id !== (0, utils_1.encodeBase58)(this.id))
|
|
10110
|
+
throw new Error(`Invalid contract id. Expected: ${(0, utils_1.encodeBase58)(this.id)}. Received: ${op.call_contract.contract_id}`);
|
|
10116
10111
|
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
10117
10112
|
const opName = Object.keys(this.abi.methods)[i];
|
|
10118
10113
|
const method = this.abi.methods[opName];
|
|
10119
|
-
if (op.call_contract.entry_point === method.
|
|
10120
|
-
if (!method.
|
|
10114
|
+
if (op.call_contract.entry_point === method.entry_point) {
|
|
10115
|
+
if (!method.argument)
|
|
10121
10116
|
return { name: opName };
|
|
10122
10117
|
return {
|
|
10123
10118
|
name: opName,
|
|
10124
|
-
args: await this.serializer.deserialize(op.call_contract.args, method.
|
|
10119
|
+
args: await this.serializer.deserialize(op.call_contract.args, method.argument),
|
|
10125
10120
|
};
|
|
10126
10121
|
}
|
|
10127
10122
|
}
|
|
@@ -10171,7 +10166,7 @@ class Provider {
|
|
|
10171
10166
|
else
|
|
10172
10167
|
this.rpcNodes = [rpcNodes];
|
|
10173
10168
|
this.currentNodeId = 0;
|
|
10174
|
-
this.onError = () =>
|
|
10169
|
+
this.onError = () => true;
|
|
10175
10170
|
}
|
|
10176
10171
|
/**
|
|
10177
10172
|
* Function to make jsonrpc requests to the RPC node
|
|
@@ -10184,7 +10179,7 @@ class Provider {
|
|
|
10184
10179
|
// eslint-disable-next-line no-constant-condition
|
|
10185
10180
|
while (true) {
|
|
10186
10181
|
try {
|
|
10187
|
-
const
|
|
10182
|
+
const body = {
|
|
10188
10183
|
id: Math.round(Math.random() * 1000),
|
|
10189
10184
|
jsonrpc: "2.0",
|
|
10190
10185
|
method,
|
|
@@ -10193,18 +10188,27 @@ class Provider {
|
|
|
10193
10188
|
const url = this.rpcNodes[this.currentNodeId];
|
|
10194
10189
|
const response = await fetch(url, {
|
|
10195
10190
|
method: "POST",
|
|
10196
|
-
body: JSON.stringify(
|
|
10191
|
+
body: JSON.stringify(body),
|
|
10197
10192
|
});
|
|
10198
10193
|
const json = (await response.json());
|
|
10199
|
-
if (json.
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
throw
|
|
10194
|
+
if (json.result !== undefined)
|
|
10195
|
+
return json.result;
|
|
10196
|
+
if (!json.error)
|
|
10197
|
+
throw new Error("undefined error");
|
|
10198
|
+
const { message, data } = json.error;
|
|
10199
|
+
if (!data)
|
|
10200
|
+
throw new Error(message);
|
|
10201
|
+
let dataJson;
|
|
10202
|
+
try {
|
|
10203
|
+
dataJson = JSON.parse(data);
|
|
10206
10204
|
}
|
|
10207
|
-
|
|
10205
|
+
catch (e) {
|
|
10206
|
+
dataJson = { data };
|
|
10207
|
+
}
|
|
10208
|
+
throw new Error(JSON.stringify({
|
|
10209
|
+
...(message && { error: message }),
|
|
10210
|
+
...dataJson,
|
|
10211
|
+
}));
|
|
10208
10212
|
}
|
|
10209
10213
|
catch (e) {
|
|
10210
10214
|
const currentNode = this.rpcNodes[this.currentNodeId];
|
|
@@ -10318,16 +10322,16 @@ class Provider {
|
|
|
10318
10322
|
*
|
|
10319
10323
|
* When _byTransactionId_ is used it returns the block id.
|
|
10320
10324
|
*
|
|
10321
|
-
* @param timeout - Timeout in milliseconds. By default it is
|
|
10325
|
+
* @param timeout - Timeout in milliseconds. By default it is 60000
|
|
10322
10326
|
* @example
|
|
10323
10327
|
* ```ts
|
|
10324
10328
|
* const blockNumber = await provider.wait(txId);
|
|
10325
|
-
* // const blockNumber = await provider.wait(txId, "byBlock",
|
|
10326
|
-
* // const blockId = await provider.wait(txId, "byTransactionId",
|
|
10329
|
+
* // const blockNumber = await provider.wait(txId, "byBlock", 60000);
|
|
10330
|
+
* // const blockId = await provider.wait(txId, "byTransactionId", 60000);
|
|
10327
10331
|
* console.log("Transaction mined")
|
|
10328
10332
|
* ```
|
|
10329
10333
|
*/
|
|
10330
|
-
async wait(txId, type = "byBlock", timeout =
|
|
10334
|
+
async wait(txId, type = "byBlock", timeout = 60000) {
|
|
10331
10335
|
const iniTime = Date.now();
|
|
10332
10336
|
if (type === "byTransactionId") {
|
|
10333
10337
|
while (Date.now() < iniTime + timeout) {
|
|
@@ -10427,22 +10431,25 @@ exports.Serializer = void 0;
|
|
|
10427
10431
|
/* eslint-disable @typescript-eslint/require-await */
|
|
10428
10432
|
const light_1 = __webpack_require__(4492);
|
|
10429
10433
|
const utils_1 = __webpack_require__(8593);
|
|
10430
|
-
const
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10434
|
+
const OP_BYTES_1 = "(btype)";
|
|
10435
|
+
const OP_BYTES_2 = "(koinos.btype)";
|
|
10436
|
+
const nativeTypes = [
|
|
10437
|
+
"double",
|
|
10438
|
+
"float",
|
|
10439
|
+
"int32",
|
|
10440
|
+
"int64",
|
|
10441
|
+
"uint32",
|
|
10442
|
+
"uint64",
|
|
10443
|
+
"sint32",
|
|
10444
|
+
"sint64",
|
|
10445
|
+
"fixed32",
|
|
10446
|
+
"fixed64",
|
|
10447
|
+
"sfixed32",
|
|
10448
|
+
"sfixed64",
|
|
10449
|
+
"bool",
|
|
10450
|
+
"string",
|
|
10451
|
+
"bytes",
|
|
10452
|
+
];
|
|
10446
10453
|
/**
|
|
10447
10454
|
* The serializer class serialize and deserialize data using
|
|
10448
10455
|
* protocol buffers.
|
|
@@ -10491,45 +10498,79 @@ class Serializer {
|
|
|
10491
10498
|
if (opts && typeof opts.bytesConversion !== "undefined")
|
|
10492
10499
|
this.bytesConversion = opts.bytesConversion;
|
|
10493
10500
|
}
|
|
10494
|
-
|
|
10495
|
-
const
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
const
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
}
|
|
10501
|
+
btypeDecode(valueBtypeEncoded, protobufType) {
|
|
10502
|
+
const valueBtypeDecoded = {};
|
|
10503
|
+
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
10504
|
+
const { options, name, type, rule } = protobufType.fields[fieldName];
|
|
10505
|
+
if (!valueBtypeEncoded[name])
|
|
10506
|
+
return;
|
|
10507
|
+
const typeField = { type };
|
|
10508
|
+
if (options) {
|
|
10509
|
+
if (options[OP_BYTES_1])
|
|
10510
|
+
typeField.btype = options[OP_BYTES_1];
|
|
10511
|
+
else if (options[OP_BYTES_2])
|
|
10512
|
+
typeField.btype = options[OP_BYTES_2];
|
|
10513
|
+
}
|
|
10514
|
+
// arrays
|
|
10515
|
+
if (rule === "repeated") {
|
|
10516
|
+
valueBtypeDecoded[name] = valueBtypeEncoded[name].map((itemEncoded) => {
|
|
10517
|
+
// custom objects
|
|
10518
|
+
if (!nativeTypes.includes(type)) {
|
|
10519
|
+
const protoBuf = this.root.lookupType(type);
|
|
10520
|
+
return this.btypeDecode(itemEncoded, protoBuf);
|
|
10521
|
+
}
|
|
10522
|
+
// native types
|
|
10523
|
+
return (0, utils_1.btypeDecodeValue)(itemEncoded, typeField);
|
|
10524
|
+
});
|
|
10525
|
+
return;
|
|
10526
|
+
}
|
|
10527
|
+
// custom objects
|
|
10528
|
+
if (!nativeTypes.includes(type)) {
|
|
10529
|
+
const protoBuf = this.root.lookupType(type);
|
|
10530
|
+
valueBtypeDecoded[name] = this.btypeDecode(valueBtypeEncoded[name], protoBuf);
|
|
10531
|
+
return;
|
|
10532
|
+
}
|
|
10533
|
+
// native types
|
|
10534
|
+
valueBtypeDecoded[name] = (0, utils_1.btypeDecodeValue)(valueBtypeEncoded[name], typeField);
|
|
10535
|
+
});
|
|
10536
|
+
return valueBtypeDecoded;
|
|
10537
|
+
}
|
|
10538
|
+
btypeEncode(valueBtypeDecoded, protobufType) {
|
|
10539
|
+
const valueBtypeEncoded = {};
|
|
10540
|
+
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
10541
|
+
const { options, name, type, rule } = protobufType.fields[fieldName];
|
|
10542
|
+
if (!valueBtypeDecoded[name])
|
|
10543
|
+
return;
|
|
10544
|
+
const typeField = { type };
|
|
10545
|
+
if (options) {
|
|
10546
|
+
if (options[OP_BYTES_1])
|
|
10547
|
+
typeField.btype = options[OP_BYTES_1];
|
|
10548
|
+
else if (options[OP_BYTES_2])
|
|
10549
|
+
typeField.btype = options[OP_BYTES_2];
|
|
10550
|
+
}
|
|
10551
|
+
// arrays
|
|
10552
|
+
if (rule === "repeated") {
|
|
10553
|
+
valueBtypeEncoded[name] = valueBtypeDecoded[name].map((itemDecoded) => {
|
|
10554
|
+
// custom objects
|
|
10555
|
+
if (!nativeTypes.includes(type)) {
|
|
10556
|
+
const protoBuf = this.root.lookupType(type);
|
|
10557
|
+
return this.btypeEncode(itemDecoded, protoBuf);
|
|
10558
|
+
}
|
|
10559
|
+
// native types
|
|
10560
|
+
return (0, utils_1.btypeEncodeValue)(itemDecoded, typeField);
|
|
10561
|
+
});
|
|
10562
|
+
return;
|
|
10563
|
+
}
|
|
10564
|
+
// custom objects
|
|
10565
|
+
if (!nativeTypes.includes(type)) {
|
|
10566
|
+
const protoBuf = this.root.lookupType(type);
|
|
10567
|
+
valueBtypeEncoded[name] = this.btypeEncode(valueBtypeDecoded[name], protoBuf);
|
|
10568
|
+
return;
|
|
10569
|
+
}
|
|
10570
|
+
// native types
|
|
10571
|
+
valueBtypeEncoded[name] = (0, utils_1.btypeEncodeValue)(valueBtypeDecoded[name], typeField);
|
|
10572
|
+
});
|
|
10573
|
+
return valueBtypeEncoded;
|
|
10533
10574
|
}
|
|
10534
10575
|
/**
|
|
10535
10576
|
* Function to encode a type using the protobuffer definitions
|
|
@@ -10543,8 +10584,7 @@ class Serializer {
|
|
|
10543
10584
|
? this.bytesConversion
|
|
10544
10585
|
: opts.bytesConversion;
|
|
10545
10586
|
if (bytesConversion) {
|
|
10546
|
-
|
|
10547
|
-
Object.keys(protobufType.fields).forEach((fieldName) => this.converter(valueDecoded, object, protobufType, fieldName));
|
|
10587
|
+
object = this.btypeDecode(valueDecoded, protobufType);
|
|
10548
10588
|
}
|
|
10549
10589
|
else {
|
|
10550
10590
|
object = valueDecoded;
|
|
@@ -10571,38 +10611,9 @@ class Serializer {
|
|
|
10571
10611
|
const bytesConversion = (opts === null || opts === void 0 ? void 0 : opts.bytesConversion) === undefined
|
|
10572
10612
|
? this.bytesConversion
|
|
10573
10613
|
: opts.bytesConversion;
|
|
10574
|
-
if (
|
|
10575
|
-
return object;
|
|
10576
|
-
|
|
10577
|
-
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
10578
|
-
const { options, name, type } = protobufType.fields[fieldName];
|
|
10579
|
-
// No byte conversion
|
|
10580
|
-
if (type !== "bytes")
|
|
10581
|
-
return;
|
|
10582
|
-
// Default byte conversion
|
|
10583
|
-
if (!options || !options[OP_BYTES]) {
|
|
10584
|
-
object[name] = (0, utils_1.encodeBase64url)(object[name]);
|
|
10585
|
-
return;
|
|
10586
|
-
}
|
|
10587
|
-
// Specific byte conversion
|
|
10588
|
-
switch (options[OP_BYTES]) {
|
|
10589
|
-
case "BASE58":
|
|
10590
|
-
case "CONTRACT_ID":
|
|
10591
|
-
case "ADDRESS":
|
|
10592
|
-
object[name] = (0, utils_1.encodeBase58)(object[name]);
|
|
10593
|
-
break;
|
|
10594
|
-
case "BASE64":
|
|
10595
|
-
object[name] = (0, utils_1.encodeBase64url)(object[name]);
|
|
10596
|
-
break;
|
|
10597
|
-
case "HEX":
|
|
10598
|
-
case "BLOCK_ID":
|
|
10599
|
-
case "TRANSACTION_ID":
|
|
10600
|
-
object[name] = `0x${(0, utils_1.toHexString)(object[name])}`;
|
|
10601
|
-
break;
|
|
10602
|
-
default:
|
|
10603
|
-
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
10604
|
-
}
|
|
10605
|
-
});
|
|
10614
|
+
if (bytesConversion) {
|
|
10615
|
+
return this.btypeEncode(object, protobufType);
|
|
10616
|
+
}
|
|
10606
10617
|
return object;
|
|
10607
10618
|
}
|
|
10608
10619
|
}
|
|
@@ -10802,7 +10813,7 @@ class Signer {
|
|
|
10802
10813
|
* ```
|
|
10803
10814
|
* @returns Signer object
|
|
10804
10815
|
*/
|
|
10805
|
-
static fromWif(wif, compressed) {
|
|
10816
|
+
static fromWif(wif, compressed = true) {
|
|
10806
10817
|
const comp = compressed === undefined ? wif[0] !== "5" : compressed;
|
|
10807
10818
|
const privateKey = (0, utils_1.bitcoinDecode)(wif);
|
|
10808
10819
|
return new Signer({
|
|
@@ -10822,7 +10833,7 @@ class Signer {
|
|
|
10822
10833
|
* ```
|
|
10823
10834
|
* @returns Signer object
|
|
10824
10835
|
*/
|
|
10825
|
-
static fromSeed(seed, compressed) {
|
|
10836
|
+
static fromSeed(seed, compressed = true) {
|
|
10826
10837
|
const privateKey = (0, sha256_1.sha256)(seed);
|
|
10827
10838
|
return new Signer({ privateKey, compressed });
|
|
10828
10839
|
}
|
|
@@ -10857,7 +10868,7 @@ class Signer {
|
|
|
10857
10868
|
* // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
|
|
10858
10869
|
* ```
|
|
10859
10870
|
*/
|
|
10860
|
-
getPrivateKey(format = "hex", compressed) {
|
|
10871
|
+
getPrivateKey(format = "hex", compressed = false) {
|
|
10861
10872
|
let stringPrivateKey;
|
|
10862
10873
|
if (this.privateKey instanceof Uint8Array) {
|
|
10863
10874
|
stringPrivateKey = (0, utils_1.toHexString)(this.privateKey);
|
|
@@ -10895,6 +10906,12 @@ class Signer {
|
|
|
10895
10906
|
compactSignature.set(compSignature, 1);
|
|
10896
10907
|
return compactSignature;
|
|
10897
10908
|
}
|
|
10909
|
+
/**
|
|
10910
|
+
* Function to sign a message, which could be a string or a Uint8Array
|
|
10911
|
+
*/
|
|
10912
|
+
async signMessage(message) {
|
|
10913
|
+
return this.signHash((0, sha256_1.sha256)(message));
|
|
10914
|
+
}
|
|
10898
10915
|
/**
|
|
10899
10916
|
* Function to sign a transaction. It's important to remark that
|
|
10900
10917
|
* the transaction parameter is modified inside this function.
|
|
@@ -10944,13 +10961,13 @@ class Signer {
|
|
|
10944
10961
|
tx = await this.signTransaction(tx);
|
|
10945
10962
|
if (!this.provider)
|
|
10946
10963
|
throw new Error("provider is undefined");
|
|
10947
|
-
await this.provider.sendTransaction(tx);
|
|
10948
|
-
tx.wait = async (type = "byBlock", timeout =
|
|
10964
|
+
const { receipt } = await this.provider.sendTransaction(tx);
|
|
10965
|
+
tx.wait = async (type = "byBlock", timeout = 60000) => {
|
|
10949
10966
|
if (!this.provider)
|
|
10950
10967
|
throw new Error("provider is undefined");
|
|
10951
10968
|
return this.provider.wait(tx.id, type, timeout);
|
|
10952
10969
|
};
|
|
10953
|
-
return tx;
|
|
10970
|
+
return { receipt, transaction: tx };
|
|
10954
10971
|
}
|
|
10955
10972
|
/**
|
|
10956
10973
|
* Function to recover the public key from hash and signature
|
|
@@ -10976,6 +10993,9 @@ class Signer {
|
|
|
10976
10993
|
return secp.Point.fromHex(publicKey).toHex(true);
|
|
10977
10994
|
}
|
|
10978
10995
|
}
|
|
10996
|
+
static recoverAddress(hash, signature, compressed = true) {
|
|
10997
|
+
return (0, utils_1.bitcoinAddress)((0, utils_1.toUint8Array)(Signer.recoverPublicKey(hash, signature, compressed)));
|
|
10998
|
+
}
|
|
10979
10999
|
/**
|
|
10980
11000
|
* Function to recover the publics keys from a signed
|
|
10981
11001
|
* transaction or block.
|
|
@@ -11337,12 +11357,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11337
11357
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11338
11358
|
};
|
|
11339
11359
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11340
|
-
exports.
|
|
11360
|
+
exports.tokenAbi = exports.btypeEncode = exports.btypeDecode = exports.btypeEncodeValue = exports.btypeDecodeValue = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.bitcoinEncode = exports.calculateMerkleRoot = exports.decodeBase64 = exports.multihash = exports.encodeBase64 = exports.decodeBase64url = exports.encodeBase64url = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
|
|
11341
11361
|
const multibase = __importStar(__webpack_require__(6957));
|
|
11342
11362
|
const sha256_1 = __webpack_require__(3061);
|
|
11343
11363
|
const ripemd160_1 = __webpack_require__(830);
|
|
11344
|
-
const
|
|
11345
|
-
//import protocolJson from "./jsonDescriptors/protocol-proto.json";
|
|
11364
|
+
const token_proto_json_1 = __importDefault(__webpack_require__(6567));
|
|
11346
11365
|
/**
|
|
11347
11366
|
* Converts an hex string to Uint8Array
|
|
11348
11367
|
*/
|
|
@@ -11561,10 +11580,25 @@ function parseUnits(value, decimals) {
|
|
|
11561
11580
|
return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
|
|
11562
11581
|
}
|
|
11563
11582
|
exports.parseUnits = parseUnits;
|
|
11583
|
+
/**
|
|
11584
|
+
* Makes a copy of a value. The returned value can be modified
|
|
11585
|
+
* without altering the original one. Although this is not needed
|
|
11586
|
+
* for strings or numbers and only needed for objects and arrays,
|
|
11587
|
+
* all these options are covered in a single function
|
|
11588
|
+
*
|
|
11589
|
+
* It is assumed that the argument is number, string, or contructions
|
|
11590
|
+
* of these types inside objects or arrays.
|
|
11591
|
+
*/
|
|
11592
|
+
function copyValue(value) {
|
|
11593
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
11594
|
+
return value;
|
|
11595
|
+
}
|
|
11596
|
+
return JSON.parse(JSON.stringify(value));
|
|
11597
|
+
}
|
|
11564
11598
|
function btypeDecodeValue(valueEncoded, typeField) {
|
|
11565
11599
|
// No byte conversion
|
|
11566
11600
|
if (typeField.type !== "bytes")
|
|
11567
|
-
return valueEncoded;
|
|
11601
|
+
return copyValue(valueEncoded);
|
|
11568
11602
|
const value = valueEncoded;
|
|
11569
11603
|
// Default byte conversion
|
|
11570
11604
|
if (!typeField.btype) {
|
|
@@ -11590,7 +11624,7 @@ exports.btypeDecodeValue = btypeDecodeValue;
|
|
|
11590
11624
|
function btypeEncodeValue(valueDecoded, typeField) {
|
|
11591
11625
|
// No byte conversion
|
|
11592
11626
|
if (typeField.type !== "bytes")
|
|
11593
|
-
return valueDecoded;
|
|
11627
|
+
return copyValue(valueDecoded);
|
|
11594
11628
|
const value = valueDecoded;
|
|
11595
11629
|
// Default byte conversion
|
|
11596
11630
|
if (!typeField.btype) {
|
|
@@ -11620,7 +11654,13 @@ function btypeDecode(valueEncoded, fields) {
|
|
|
11620
11654
|
Object.keys(fields).forEach((name) => {
|
|
11621
11655
|
if (!valueEncoded[name])
|
|
11622
11656
|
return;
|
|
11623
|
-
if (fields[name].
|
|
11657
|
+
if (fields[name].rule === "repeated")
|
|
11658
|
+
valueDecoded[name] = valueEncoded[name].map((itemEncoded) => {
|
|
11659
|
+
if (fields[name].subtypes)
|
|
11660
|
+
return btypeDecode(itemEncoded, fields[name].subtypes);
|
|
11661
|
+
return btypeDecodeValue(itemEncoded, fields[name]);
|
|
11662
|
+
});
|
|
11663
|
+
else if (fields[name].subtypes)
|
|
11624
11664
|
valueDecoded[name] = btypeDecode(valueEncoded[name], fields[name].subtypes);
|
|
11625
11665
|
else
|
|
11626
11666
|
valueDecoded[name] = btypeDecodeValue(valueEncoded[name], fields[name]);
|
|
@@ -11635,9 +11675,16 @@ function btypeEncode(valueDecoded, fields) {
|
|
|
11635
11675
|
Object.keys(fields).forEach((name) => {
|
|
11636
11676
|
if (!valueDecoded[name])
|
|
11637
11677
|
return;
|
|
11638
|
-
if (fields[name].
|
|
11678
|
+
if (fields[name].rule === "repeated")
|
|
11679
|
+
valueEncoded[name] = valueDecoded[name].map((itemDecoded) => {
|
|
11680
|
+
if (fields[name].subtypes)
|
|
11681
|
+
return btypeEncode(itemDecoded, fields[name].subtypes);
|
|
11682
|
+
return btypeEncodeValue(itemDecoded, fields[name]);
|
|
11683
|
+
});
|
|
11684
|
+
else if (fields[name].subtypes)
|
|
11639
11685
|
valueEncoded[name] = btypeEncode(valueDecoded[name], fields[name].subtypes);
|
|
11640
|
-
|
|
11686
|
+
else
|
|
11687
|
+
valueEncoded[name] = btypeEncodeValue(valueDecoded[name], fields[name]);
|
|
11641
11688
|
});
|
|
11642
11689
|
return valueEncoded;
|
|
11643
11690
|
}
|
|
@@ -11645,51 +11692,56 @@ exports.btypeEncode = btypeEncode;
|
|
|
11645
11692
|
/**
|
|
11646
11693
|
* ABI for tokens
|
|
11647
11694
|
*/
|
|
11648
|
-
exports.
|
|
11695
|
+
exports.tokenAbi = {
|
|
11649
11696
|
methods: {
|
|
11650
11697
|
name: {
|
|
11651
|
-
|
|
11652
|
-
|
|
11653
|
-
|
|
11654
|
-
|
|
11698
|
+
entry_point: 0x82a3537f,
|
|
11699
|
+
argument: "name_arguments",
|
|
11700
|
+
return: "name_result",
|
|
11701
|
+
read_only: true,
|
|
11655
11702
|
},
|
|
11656
11703
|
symbol: {
|
|
11657
|
-
|
|
11658
|
-
|
|
11659
|
-
|
|
11660
|
-
|
|
11704
|
+
entry_point: 0xb76a7ca1,
|
|
11705
|
+
argument: "symbol_arguments",
|
|
11706
|
+
return: "symbol_result",
|
|
11707
|
+
read_only: true,
|
|
11661
11708
|
},
|
|
11662
11709
|
decimals: {
|
|
11663
|
-
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
|
|
11710
|
+
entry_point: 0xee80fd2f,
|
|
11711
|
+
argument: "decimals_arguments",
|
|
11712
|
+
return: "decimals_result",
|
|
11713
|
+
read_only: true,
|
|
11667
11714
|
},
|
|
11668
11715
|
totalSupply: {
|
|
11669
|
-
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11716
|
+
entry_point: 0xb0da3934,
|
|
11717
|
+
argument: "total_supply_arguments",
|
|
11718
|
+
return: "total_supply_result",
|
|
11719
|
+
read_only: true,
|
|
11673
11720
|
},
|
|
11674
11721
|
balanceOf: {
|
|
11675
|
-
|
|
11676
|
-
|
|
11677
|
-
|
|
11678
|
-
|
|
11679
|
-
|
|
11722
|
+
entry_point: 0x5c721497,
|
|
11723
|
+
argument: "balance_of_arguments",
|
|
11724
|
+
return: "balance_of_result",
|
|
11725
|
+
read_only: true,
|
|
11726
|
+
default_output: { value: "0" },
|
|
11680
11727
|
},
|
|
11681
11728
|
transfer: {
|
|
11682
|
-
|
|
11683
|
-
|
|
11684
|
-
|
|
11729
|
+
entry_point: 0x27f576ca,
|
|
11730
|
+
argument: "transfer_arguments",
|
|
11731
|
+
return: "transfer_result",
|
|
11685
11732
|
},
|
|
11686
11733
|
mint: {
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11734
|
+
entry_point: 0xdc6f17bb,
|
|
11735
|
+
argument: "mint_arguments",
|
|
11736
|
+
return: "mint_result",
|
|
11737
|
+
},
|
|
11738
|
+
burn: {
|
|
11739
|
+
entry_point: 0x859facc5,
|
|
11740
|
+
argument: "burn_arguments",
|
|
11741
|
+
return: "burn_result",
|
|
11690
11742
|
},
|
|
11691
11743
|
},
|
|
11692
|
-
|
|
11744
|
+
koilib_types: token_proto_json_1.default,
|
|
11693
11745
|
};
|
|
11694
11746
|
//export const ProtocolTypes = protocolJson;
|
|
11695
11747
|
|
|
@@ -19482,7 +19534,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
19482
19534
|
|
|
19483
19535
|
/***/ }),
|
|
19484
19536
|
|
|
19485
|
-
/***/
|
|
19537
|
+
/***/ 6567:
|
|
19486
19538
|
/***/ ((module) => {
|
|
19487
19539
|
|
|
19488
19540
|
"use strict";
|