koilib 3.0.0 → 3.1.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 CHANGED
@@ -37,7 +37,7 @@ You can also load it directly to the browser by downloading the bunble file loca
37
37
  signer.provider = provider;
38
38
  const koinContract = new Contract({
39
39
  id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
40
- abi: utils.Krc20Abi,
40
+ abi: utils.tokenAbi,
41
41
  provider,
42
42
  signer,
43
43
  });
@@ -92,7 +92,7 @@ a transaction, and read contracts.
92
92
  signer.provider = provider;
93
93
  const koinContract = new Contract({
94
94
  id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
95
- abi: utils.Krc20Abi,
95
+ abi: utils.tokenAbi,
96
96
  provider,
97
97
  signer,
98
98
  });
@@ -109,11 +109,16 @@ a transaction, and read contracts.
109
109
  });
110
110
 
111
111
  // Transfer
112
- const { transaction } = await koin.transfer({
112
+ const { transaction, receipt } = await koin.transfer({
113
113
  to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
114
114
  value: "10.0001",
115
115
  });
116
- console.log(`Transaction id ${transaction.id} submitted`);
116
+ console.log(`Transaction id ${transaction.id} submitted. Receipt:`);
117
+ console.log(receipt);
118
+
119
+ if (receipt.logs) {
120
+ console.log(`Transfer failed. Logs: ${receipt.logs.join(",")}`);
121
+ }
117
122
 
118
123
  // wait to be mined
119
124
  const blockNumber = await transaction.wait();
@@ -139,7 +144,9 @@ It's also possible to upload contracts. First, follow the instructions in [koino
139
144
 
140
145
  // create contract and deploy
141
146
  const contract = new Contract({ signer, provider, bytecode });
142
- const { transaction } = await contract.deploy();
147
+ const { transaction, receipt } = await contract.deploy();
148
+ console.log("Transaction submitted. Receipt:");
149
+ console.log(receipt);
143
150
  // wait to be mined
144
151
  const blockNumber = await transaction.wait();
145
152
  console.log(`Contract uploaded in block number ${blockNumber}`);
@@ -181,7 +188,9 @@ You can also upload a contract in a new address. It is not required that this ne
181
188
  // - signature of accountWithFunds
182
189
 
183
190
  // now broadcast the transaction to deploy
184
- transaction = await newAccount.sendTransaction(transaction);
191
+ const { receipt } = await newAccount.sendTransaction(transaction);
192
+ console.log("Transaction submitted. Receipt: ");
193
+ console.log(receipt);
185
194
  const blockNumber = await transaction.wait();
186
195
  console.log(`Contract uploaded in block number ${blockNumber}`);
187
196
  })();
package/dist/koinos.js CHANGED
@@ -9785,7 +9785,7 @@ 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.Krc20Abi,
9788
+ * abi: utils.tokenAbi,
9789
9789
  * provider,
9790
9790
  * signer,
9791
9791
  * });
@@ -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();
@@ -9874,11 +9879,7 @@ 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);
@@ -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: 0x62efa292,
10056
- * // args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
10050
+ * // entry_point: 670398154,
10051
+ * // args: "ChkAEjl6vrl55V2Oym_rzsnMxIqBoie9PHmMEhkAQgjT1UACatdFY3e5QRkyG7OAzwcCCIylGOgH",
10057
10052
  * // }
10058
10053
  * // }
10059
10054
  * ```
@@ -10074,9 +10069,9 @@ class Contract {
10074
10069
  }
10075
10070
  return {
10076
10071
  call_contract: {
10077
- contract_id: this.id,
10072
+ contract_id: (0, utils_1.encodeBase58)(this.id),
10078
10073
  entry_point: method.entryPoint,
10079
- args: bufferInputs,
10074
+ args: (0, utils_1.encodeBase64url)(bufferInputs),
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: 0x62efa292,
10091
- * args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
10085
+ * entry_point: 0x27f576ca,
10086
+ * args: "ChkAEjl6vrl55V2Oym_rzsnMxIqBoie9PHmMEhkAQgjT1UACatdFY3e5QRkyG7OAzwcCCIylGOgH",
10092
10087
  * }
10093
10088
  * });
10094
10089
  * console.log(opDecoded);
@@ -10111,8 +10106,8 @@ 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 ((0, utils_1.encodeBase58)(op.call_contract.contract_id) !== (0, utils_1.encodeBase58)(this.id))
10115
- throw new Error(`Invalid contract id. Expected: ${(0, utils_1.encodeBase58)(this.id)}. Received: ${(0, utils_1.encodeBase58)(op.call_contract.contract_id)}`);
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];
@@ -10171,7 +10166,7 @@ class Provider {
10171
10166
  else
10172
10167
  this.rpcNodes = [rpcNodes];
10173
10168
  this.currentNodeId = 0;
10174
- this.onError = () => false;
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 data = {
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(data),
10191
+ body: JSON.stringify(body),
10197
10192
  });
10198
10193
  const json = (await response.json());
10199
- if (json.error && json.error.message) {
10200
- const error = new Error(json.error.message);
10201
- error.request = {
10202
- method,
10203
- params,
10204
- };
10205
- throw error;
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
- return json.result;
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 30000
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", 30000);
10326
- * // const blockId = await provider.wait(txId, "byTransactionId", 30000);
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 = 30000) {
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 OP_BYTES = "(btype)";
10431
- /**
10432
- * Makes a copy of a value. The returned value can be modified
10433
- * without altering the original one. Although this is not needed
10434
- * for strings or numbers and only needed for objects and arrays,
10435
- * all these options are covered in a single function
10436
- *
10437
- * It is assumed that the argument is number, string, or contructions
10438
- * of these types inside objects or arrays.
10439
- */
10440
- function copyValue(value) {
10441
- if (typeof value === "string" || typeof value === "number") {
10442
- return value;
10443
- }
10444
- return JSON.parse(JSON.stringify(value));
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
- converter(valueDecoded, object, protobufType, fieldName) {
10495
- const { options, name, type } = protobufType.fields[fieldName];
10496
- if (!valueDecoded[name])
10497
- return;
10498
- // if operation
10499
- if (type.endsWith("_operation")) {
10500
- const protoBuf = this.root.lookupType(type);
10501
- object[name] = {};
10502
- Object.keys(protoBuf.fields).forEach((fdName) => this.converter(valueDecoded[name], object[name], protoBuf, fdName));
10503
- return;
10504
- }
10505
- // No byte conversion
10506
- if (type !== "bytes") {
10507
- object[name] = copyValue(valueDecoded[name]);
10508
- return;
10509
- }
10510
- // Default byte conversion
10511
- if (!options || !options[OP_BYTES]) {
10512
- object[name] = (0, utils_1.decodeBase64url)(valueDecoded[name]);
10513
- return;
10514
- }
10515
- // Specific byte conversion
10516
- switch (options[OP_BYTES]) {
10517
- case "BASE58":
10518
- case "CONTRACT_ID":
10519
- case "ADDRESS":
10520
- object[name] = (0, utils_1.decodeBase58)(valueDecoded[name]);
10521
- break;
10522
- case "BASE64":
10523
- object[name] = (0, utils_1.decodeBase64url)(valueDecoded[name]);
10524
- break;
10525
- case "HEX":
10526
- case "BLOCK_ID":
10527
- case "TRANSACTION_ID":
10528
- object[name] = (0, utils_1.toUint8Array)(valueDecoded[name].replace("0x", ""));
10529
- break;
10530
- default:
10531
- throw new Error(`unknown btype ${options[OP_BYTES]}`);
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
- // TODO: format from Buffer to base58/base64 for nested fields
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 (!bytesConversion)
10575
- return object;
10576
- // TODO: format from Buffer to base58/base64 for nested fields
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
  }
@@ -10944,13 +10955,13 @@ class Signer {
10944
10955
  tx = await this.signTransaction(tx);
10945
10956
  if (!this.provider)
10946
10957
  throw new Error("provider is undefined");
10947
- await this.provider.sendTransaction(tx);
10948
- tx.wait = async (type = "byBlock", timeout = 30000) => {
10958
+ const { receipt } = await this.provider.sendTransaction(tx);
10959
+ tx.wait = async (type = "byBlock", timeout = 60000) => {
10949
10960
  if (!this.provider)
10950
10961
  throw new Error("provider is undefined");
10951
10962
  return this.provider.wait(tx.id, type, timeout);
10952
10963
  };
10953
- return tx;
10964
+ return { receipt, transaction: tx };
10954
10965
  }
10955
10966
  /**
10956
10967
  * Function to recover the public key from hash and signature
@@ -11337,12 +11348,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11337
11348
  return (mod && mod.__esModule) ? mod : { "default": mod };
11338
11349
  };
11339
11350
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11340
- exports.Krc20Abi = 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;
11351
+ 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
11352
  const multibase = __importStar(__webpack_require__(6957));
11342
11353
  const sha256_1 = __webpack_require__(3061);
11343
11354
  const ripemd160_1 = __webpack_require__(830);
11344
- const krc20_proto_json_1 = __importDefault(__webpack_require__(7177));
11345
- //import protocolJson from "./jsonDescriptors/protocol-proto.json";
11355
+ const token_proto_json_1 = __importDefault(__webpack_require__(6567));
11346
11356
  /**
11347
11357
  * Converts an hex string to Uint8Array
11348
11358
  */
@@ -11561,10 +11571,25 @@ function parseUnits(value, decimals) {
11561
11571
  return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
11562
11572
  }
11563
11573
  exports.parseUnits = parseUnits;
11574
+ /**
11575
+ * Makes a copy of a value. The returned value can be modified
11576
+ * without altering the original one. Although this is not needed
11577
+ * for strings or numbers and only needed for objects and arrays,
11578
+ * all these options are covered in a single function
11579
+ *
11580
+ * It is assumed that the argument is number, string, or contructions
11581
+ * of these types inside objects or arrays.
11582
+ */
11583
+ function copyValue(value) {
11584
+ if (typeof value === "string" || typeof value === "number") {
11585
+ return value;
11586
+ }
11587
+ return JSON.parse(JSON.stringify(value));
11588
+ }
11564
11589
  function btypeDecodeValue(valueEncoded, typeField) {
11565
11590
  // No byte conversion
11566
11591
  if (typeField.type !== "bytes")
11567
- return valueEncoded;
11592
+ return copyValue(valueEncoded);
11568
11593
  const value = valueEncoded;
11569
11594
  // Default byte conversion
11570
11595
  if (!typeField.btype) {
@@ -11590,7 +11615,7 @@ exports.btypeDecodeValue = btypeDecodeValue;
11590
11615
  function btypeEncodeValue(valueDecoded, typeField) {
11591
11616
  // No byte conversion
11592
11617
  if (typeField.type !== "bytes")
11593
- return valueDecoded;
11618
+ return copyValue(valueDecoded);
11594
11619
  const value = valueDecoded;
11595
11620
  // Default byte conversion
11596
11621
  if (!typeField.btype) {
@@ -11620,7 +11645,13 @@ function btypeDecode(valueEncoded, fields) {
11620
11645
  Object.keys(fields).forEach((name) => {
11621
11646
  if (!valueEncoded[name])
11622
11647
  return;
11623
- if (fields[name].subtypes)
11648
+ if (fields[name].rule === "repeated")
11649
+ valueDecoded[name] = valueEncoded[name].map((itemEncoded) => {
11650
+ if (fields[name].subtypes)
11651
+ return btypeDecode(itemEncoded, fields[name].subtypes);
11652
+ return btypeDecodeValue(itemEncoded, fields[name]);
11653
+ });
11654
+ else if (fields[name].subtypes)
11624
11655
  valueDecoded[name] = btypeDecode(valueEncoded[name], fields[name].subtypes);
11625
11656
  else
11626
11657
  valueDecoded[name] = btypeDecodeValue(valueEncoded[name], fields[name]);
@@ -11635,9 +11666,16 @@ function btypeEncode(valueDecoded, fields) {
11635
11666
  Object.keys(fields).forEach((name) => {
11636
11667
  if (!valueDecoded[name])
11637
11668
  return;
11638
- if (fields[name].subtypes)
11669
+ if (fields[name].rule === "repeated")
11670
+ valueEncoded[name] = valueDecoded[name].map((itemDecoded) => {
11671
+ if (fields[name].subtypes)
11672
+ return btypeEncode(itemDecoded, fields[name].subtypes);
11673
+ return btypeEncodeValue(itemDecoded, fields[name]);
11674
+ });
11675
+ else if (fields[name].subtypes)
11639
11676
  valueEncoded[name] = btypeEncode(valueDecoded[name], fields[name].subtypes);
11640
- valueEncoded[name] = btypeEncodeValue(valueDecoded[name], fields[name]);
11677
+ else
11678
+ valueEncoded[name] = btypeEncodeValue(valueDecoded[name], fields[name]);
11641
11679
  });
11642
11680
  return valueEncoded;
11643
11681
  }
@@ -11645,7 +11683,7 @@ exports.btypeEncode = btypeEncode;
11645
11683
  /**
11646
11684
  * ABI for tokens
11647
11685
  */
11648
- exports.Krc20Abi = {
11686
+ exports.tokenAbi = {
11649
11687
  methods: {
11650
11688
  name: {
11651
11689
  entryPoint: 0x82a3537f,
@@ -11689,7 +11727,7 @@ exports.Krc20Abi = {
11689
11727
  output: "mint_result",
11690
11728
  },
11691
11729
  },
11692
- types: krc20_proto_json_1.default,
11730
+ types: token_proto_json_1.default,
11693
11731
  };
11694
11732
  //export const ProtocolTypes = protocolJson;
11695
11733
 
@@ -19482,7 +19520,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
19482
19520
 
19483
19521
  /***/ }),
19484
19522
 
19485
- /***/ 7177:
19523
+ /***/ 6567:
19486
19524
  /***/ ((module) => {
19487
19525
 
19488
19526
  "use strict";