@alephium/web3 0.42.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.map +1 -1
  3. package/dist/src/{utils → address}/address.js +15 -19
  4. package/dist/src/address/index.d.ts +1 -0
  5. package/dist/src/address/index.js +34 -0
  6. package/dist/src/api/node-provider.js +10 -9
  7. package/dist/src/api/types.js +1 -1
  8. package/dist/src/codec/array-codec.d.ts +2 -3
  9. package/dist/src/codec/array-codec.js +2 -3
  10. package/dist/src/codec/asset-output-codec.d.ts +3 -4
  11. package/dist/src/codec/asset-output-codec.js +13 -15
  12. package/dist/src/codec/bigint-codec.d.ts +2 -3
  13. package/dist/src/codec/bigint-codec.js +2 -3
  14. package/dist/src/codec/bytestring-codec.d.ts +5 -6
  15. package/dist/src/codec/bytestring-codec.js +7 -7
  16. package/dist/src/codec/codec.d.ts +2 -3
  17. package/dist/src/codec/compact-int-codec.d.ts +11 -15
  18. package/dist/src/codec/compact-int-codec.js +23 -33
  19. package/dist/src/codec/contract-codec.d.ts +5 -6
  20. package/dist/src/codec/contract-codec.js +26 -26
  21. package/dist/src/codec/contract-output-codec.d.ts +2 -3
  22. package/dist/src/codec/contract-output-codec.js +9 -11
  23. package/dist/src/codec/contract-output-ref-codec.d.ts +3 -4
  24. package/dist/src/codec/contract-output-ref-codec.js +2 -2
  25. package/dist/src/codec/either-codec.d.ts +2 -3
  26. package/dist/src/codec/either-codec.js +1 -2
  27. package/dist/src/codec/hash.d.ts +2 -3
  28. package/dist/src/codec/hash.js +17 -0
  29. package/dist/src/codec/input-codec.d.ts +3 -4
  30. package/dist/src/codec/input-codec.js +6 -6
  31. package/dist/src/codec/instr-codec.d.ts +2 -3
  32. package/dist/src/codec/instr-codec.js +1 -2
  33. package/dist/src/codec/lockup-script-codec.d.ts +5 -6
  34. package/dist/src/codec/lockup-script-codec.js +1 -2
  35. package/dist/src/codec/long-codec.d.ts +2 -3
  36. package/dist/src/codec/long-codec.js +1 -2
  37. package/dist/src/codec/method-codec.d.ts +2 -3
  38. package/dist/src/codec/method-codec.js +13 -14
  39. package/dist/src/codec/option-codec.d.ts +3 -4
  40. package/dist/src/codec/option-codec.js +2 -3
  41. package/dist/src/codec/script-codec.d.ts +4 -5
  42. package/dist/src/codec/script-codec.js +2 -4
  43. package/dist/src/codec/signature-codec.d.ts +3 -4
  44. package/dist/src/codec/signature-codec.js +17 -0
  45. package/dist/src/codec/signed-int-codec.d.ts +2 -3
  46. package/dist/src/codec/signed-int-codec.js +1 -2
  47. package/dist/src/codec/token-codec.d.ts +3 -4
  48. package/dist/src/codec/token-codec.js +3 -3
  49. package/dist/src/codec/transaction-codec.d.ts +4 -5
  50. package/dist/src/codec/transaction-codec.js +12 -13
  51. package/dist/src/codec/unlock-script-codec.d.ts +5 -6
  52. package/dist/src/codec/unlock-script-codec.js +14 -15
  53. package/dist/src/codec/unsigned-tx-codec.d.ts +4 -5
  54. package/dist/src/codec/unsigned-tx-codec.js +4 -5
  55. package/dist/src/contract/contract.d.ts +10 -1
  56. package/dist/src/contract/contract.js +197 -21
  57. package/dist/src/contract/ralph.d.ts +2 -1
  58. package/dist/src/contract/ralph.js +25 -11
  59. package/dist/src/{utils → exchange}/exchange.js +5 -5
  60. package/dist/src/exchange/index.d.ts +1 -0
  61. package/dist/src/exchange/index.js +25 -0
  62. package/dist/src/index.d.ts +2 -0
  63. package/dist/src/index.js +2 -0
  64. package/dist/src/signer/signer.js +4 -5
  65. package/dist/src/signer/tx-builder.js +3 -3
  66. package/dist/src/utils/index.d.ts +0 -2
  67. package/dist/src/utils/index.js +0 -7
  68. package/dist/src/utils/sign.js +1 -1
  69. package/dist/src/utils/utils.d.ts +1 -0
  70. package/dist/src/utils/utils.js +30 -11
  71. package/dist/src/utils/webcrypto.js +3 -4
  72. package/package.json +1 -2
  73. package/src/{utils → address}/address.ts +15 -19
  74. package/src/address/index.ts +19 -0
  75. package/src/api/node-provider.ts +2 -9
  76. package/src/api/types.ts +2 -2
  77. package/src/codec/array-codec.ts +5 -6
  78. package/src/codec/asset-output-codec.ts +20 -22
  79. package/src/codec/bigint-codec.ts +4 -5
  80. package/src/codec/bytestring-codec.ts +11 -11
  81. package/src/codec/codec.ts +2 -3
  82. package/src/codec/compact-int-codec.ts +36 -50
  83. package/src/codec/contract-codec.ts +30 -29
  84. package/src/codec/contract-output-codec.ts +13 -15
  85. package/src/codec/contract-output-ref-codec.ts +5 -5
  86. package/src/codec/either-codec.ts +3 -4
  87. package/src/codec/hash.ts +2 -3
  88. package/src/codec/input-codec.ts +10 -10
  89. package/src/codec/instr-codec.ts +3 -4
  90. package/src/codec/lockup-script-codec.ts +8 -9
  91. package/src/codec/long-codec.ts +3 -4
  92. package/src/codec/method-codec.ts +16 -17
  93. package/src/codec/option-codec.ts +4 -5
  94. package/src/codec/script-codec.ts +7 -9
  95. package/src/codec/signature-codec.ts +3 -4
  96. package/src/codec/signed-int-codec.ts +3 -4
  97. package/src/codec/token-codec.ts +6 -6
  98. package/src/codec/transaction-codec.ts +17 -18
  99. package/src/codec/unlock-script-codec.ts +26 -27
  100. package/src/codec/unsigned-tx-codec.ts +10 -11
  101. package/src/contract/contract.ts +274 -9
  102. package/src/contract/ralph.ts +29 -12
  103. package/src/{utils → exchange}/exchange.ts +3 -11
  104. package/src/exchange/index.ts +19 -0
  105. package/src/index.ts +2 -0
  106. package/src/signer/signer.ts +2 -3
  107. package/src/signer/tx-builder.ts +2 -2
  108. package/src/utils/index.ts +0 -2
  109. package/src/utils/sign.ts +1 -1
  110. package/src/utils/utils.ts +29 -10
  111. package/src/utils/webcrypto.ts +3 -4
  112. package/webpack.config.js +1 -5
  113. /package/dist/src/{utils → address}/address.d.ts +0 -0
  114. /package/dist/src/{utils → exchange}/exchange.d.ts +0 -0
@@ -40,12 +40,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
40
40
  return result;
41
41
  };
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
44
- const buffer_1 = require("buffer/");
43
+ exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.signExecuteMethod = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
45
44
  const fs_1 = require("fs");
46
45
  const api_1 = require("../api");
47
46
  const ralph = __importStar(require("./ralph"));
48
47
  const utils_1 = require("../utils");
48
+ const address_1 = require("../address");
49
49
  const global_1 = require("../global");
50
50
  const events_1 = require("./events");
51
51
  const constants_1 = require("../constants");
@@ -128,7 +128,7 @@ class Contract extends Artifact {
128
128
  this.stdInterfaceId = stdInterfaceId;
129
129
  this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch);
130
130
  this.codeHashDebug = codeHashDebug;
131
- this.decodedMethods = codec_1.contract.contractCodec.decodeContract(buffer_1.Buffer.from(bytecode, 'hex')).methods;
131
+ this.decodedMethods = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(bytecode)).methods;
132
132
  }
133
133
  publicFunctions() {
134
134
  return this.functions.filter((_, index) => this.decodedMethods[`${index}`].isPublic);
@@ -198,7 +198,7 @@ class Contract extends Artifact {
198
198
  const addressDef = typeof address !== 'undefined' ? address : Contract.randomAddress();
199
199
  return {
200
200
  address: addressDef,
201
- contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(addressDef)),
201
+ contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(addressDef)),
202
202
  bytecode: this.bytecode,
203
203
  codeHash: this.codeHash,
204
204
  fields: fields,
@@ -271,7 +271,7 @@ class Contract extends Artifact {
271
271
  fromApiContractState(state) {
272
272
  return {
273
273
  address: state.address,
274
- contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(state.address)),
274
+ contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(state.address)),
275
275
  bytecode: state.bytecode,
276
276
  initialStateHash: state.initialStateHash,
277
277
  codeHash: state.codeHash,
@@ -319,7 +319,7 @@ class Contract extends Artifact {
319
319
  addressToCodeHash.set(result.address, result.codeHash);
320
320
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash));
321
321
  return {
322
- contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(result.address)),
322
+ contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.address)),
323
323
  contractAddress: result.address,
324
324
  returns: returns,
325
325
  gasUsed: result.gasUsed,
@@ -647,7 +647,7 @@ function specialContractAddress(eventIndex, groupIndex) {
647
647
  const bytes = new Uint8Array(32).fill(0);
648
648
  bytes[30] = eventIndex;
649
649
  bytes[31] = groupIndex;
650
- return (0, utils_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
650
+ return (0, address_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
651
651
  }
652
652
  exports.CreateContractEventAddresses = Array.from(Array(constants_1.TOTAL_NUMBER_OF_GROUPS).keys()).map((groupIndex) => specialContractAddress(Contract.ContractCreatedEventIndex, groupIndex));
653
653
  exports.DestroyContractEventAddresses = Array.from(Array(constants_1.TOTAL_NUMBER_OF_GROUPS).keys()).map((groupIndex) => specialContractAddress(Contract.ContractDestroyedEventIndex, groupIndex));
@@ -718,7 +718,7 @@ function calcWrapperContractId(parentContractId, mapIndex, key, keyType, group)
718
718
  const prefix = ralph.encodeMapPrefix(mapIndex);
719
719
  const encodedKey = ralph.primitiveToByteVec(key, keyType);
720
720
  const path = (0, utils_1.binToHex)(prefix) + (0, utils_1.binToHex)(encodedKey);
721
- return (0, utils_1.subContractId)(parentContractId, path, group);
721
+ return (0, address_1.subContractId)(parentContractId, path, group);
722
722
  }
723
723
  function genCodeForType(type, structs) {
724
724
  const { immFields, mutFields } = ralph.calcFieldSize(type, true, structs);
@@ -766,7 +766,7 @@ function genCodeForType(type, structs) {
766
766
  fieldLength: immFields + mutFields + 1,
767
767
  methods: [loadImmFieldByIndex, loadMutFieldByIndex, storeMutFieldByIndex, destroy]
768
768
  };
769
- const bytecode = codec_1.contract.contractCodec.encode(codec_1.contract.toHalfDecoded(c));
769
+ const bytecode = codec_1.contract.contractCodec.encodeContract(c);
770
770
  const codeHash = blake.blake2b(bytecode, undefined, 32);
771
771
  return { bytecode: (0, utils_1.binToHex)(bytecode), codeHash: (0, utils_1.binToHex)(codeHash) };
772
772
  }
@@ -785,7 +785,7 @@ function mapToExistingContracts(contract, parentContractId, group, map, mapIndex
785
785
  const contractId = calcWrapperContractId(parentContractId, mapIndex, key, keyType, group);
786
786
  return {
787
787
  ...generatedContract,
788
- address: (0, utils_1.addressFromContractId)(contractId),
788
+ address: (0, address_1.addressFromContractId)(contractId),
789
789
  contractId: contractId,
790
790
  fieldsSig: getContractFieldsSig(valueType),
791
791
  fields,
@@ -811,8 +811,8 @@ function mapsToExistingContracts(contract, parentContractId, group, initialMaps)
811
811
  async function testMethod(factory, methodName, params, getContractByCodeHash) {
812
812
  const txId = params?.txId ?? randomTxId();
813
813
  const contract = factory.contract;
814
- const address = params.address ?? (0, utils_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
815
- const contractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
814
+ const address = params.address ?? (0, address_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
815
+ const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
816
816
  const group = params.group ?? 0;
817
817
  const initialMaps = params.initialMaps ?? {};
818
818
  const contractStates = mapsToExistingContracts(contract, contractId, group, initialMaps);
@@ -839,7 +839,7 @@ class RalphMap {
839
839
  this.parentContract = parentContract;
840
840
  this.parentContractId = parentContractId;
841
841
  this.mapName = mapName;
842
- this.groupIndex = (0, utils_1.groupOfAddress)((0, utils_1.addressFromContractId)(parentContractId));
842
+ this.groupIndex = (0, address_1.groupOfAddress)((0, address_1.addressFromContractId)(parentContractId));
843
843
  }
844
844
  async get(key) {
845
845
  return getMapItem(this.parentContract, this.parentContractId, this.groupIndex, this.mapName, key);
@@ -864,7 +864,7 @@ async function getMapItem(parentContract, parentContractId, groupIndex, mapName,
864
864
  }
865
865
  const [keyType, valueType] = ralph.parseMapType(mapType);
866
866
  const mapItemContractId = calcWrapperContractId(parentContractId, index, key, keyType, groupIndex);
867
- const mapItemAddress = (0, utils_1.addressFromContractId)(mapItemContractId);
867
+ const mapItemAddress = (0, address_1.addressFromContractId)(mapItemContractId);
868
868
  try {
869
869
  const state = await (0, global_1.getCurrentNodeProvider)().contracts.getContractsAddressState(mapItemAddress);
870
870
  const fieldsSig = getContractFieldsSig(valueType);
@@ -892,7 +892,7 @@ function buildMapInfo(contract, fields) {
892
892
  });
893
893
  }
894
894
  function extractFromEventLog(contract, result, allMaps, address, group) {
895
- const parentContractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
895
+ const parentContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
896
896
  const newInserted = [];
897
897
  result.debugMessages.forEach((message) => {
898
898
  if (message.contractAddress !== address)
@@ -902,12 +902,12 @@ function extractFromEventLog(contract, result, allMaps, address, group) {
902
902
  return;
903
903
  const map = allMaps[`${decoded.mapIndex}`];
904
904
  const decodedKey = ralph.decodePrimitive(decoded.encodedKey, map.keyType);
905
- const contractId = (0, utils_1.subContractId)(parentContractId, decoded.path, group);
905
+ const contractId = (0, address_1.subContractId)(parentContractId, decoded.path, group);
906
906
  if (!decoded.isInsert) {
907
907
  map.value.delete(decodedKey);
908
908
  return;
909
909
  }
910
- const state = result.contracts.find((s) => s.address === (0, utils_1.addressFromContractId)(contractId));
910
+ const state = result.contracts.find((s) => s.address === (0, address_1.addressFromContractId)(contractId));
911
911
  if (state === undefined) {
912
912
  throw new Error(`Cannot find contract state for map value, map field: ${map.name}, value type: ${map.valueType}`);
913
913
  }
@@ -919,12 +919,12 @@ function extractFromEventLog(contract, result, allMaps, address, group) {
919
919
  return newInserted;
920
920
  }
921
921
  function updateMaps(contract, result, allMaps, address, group) {
922
- const parentContractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
922
+ const parentContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
923
923
  const updated = [];
924
924
  allMaps.forEach((map) => {
925
925
  Array.from(map.value.keys()).forEach((key) => {
926
926
  const contractId = calcWrapperContractId(parentContractId, map.index, key, map.keyType, group);
927
- const updatedState = result.contracts.find((s) => s.address === (0, utils_1.addressFromContractId)(contractId));
927
+ const updatedState = result.contracts.find((s) => s.address === (0, address_1.addressFromContractId)(contractId));
928
928
  if (updatedState === undefined)
929
929
  return;
930
930
  updated.push(updatedState.address);
@@ -950,8 +950,8 @@ function existingContractsToMaps(contract, address, group, result, maps) {
950
950
  class ContractInstance {
951
951
  constructor(address) {
952
952
  this.address = address;
953
- this.contractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
954
- this.groupIndex = (0, utils_1.groupOfAddress)(address);
953
+ this.contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
954
+ this.groupIndex = (0, address_1.groupOfAddress)(address);
955
955
  }
956
956
  }
957
957
  exports.ContractInstance = ContractInstance;
@@ -1042,6 +1042,182 @@ async function callMethod(contract, instance, methodName, params, getContractByC
1042
1042
  return callResult;
1043
1043
  }
1044
1044
  exports.callMethod = callMethod;
1045
+ async function signExecuteMethod(contract, instance, methodName, params) {
1046
+ const methodIndex = contract.contract.getMethodIndex(methodName);
1047
+ const functionSig = contract.contract.functions[methodIndex];
1048
+ const usePreapprovedAssets = contract.contract.decodedMethods[methodIndex].usePreapprovedAssets;
1049
+ const bytecodeTemplate = getBytecodeTemplate(methodIndex, usePreapprovedAssets, functionSig, contract.contract.structs, params.attoAlphAmount, params.tokens);
1050
+ const fieldsSig = toFieldsSig(contract.contract.name, functionSig);
1051
+ const bytecode = ralph.buildScriptByteCode(bytecodeTemplate, { __contract__: instance.contractId, ...params.args }, fieldsSig, contract.contract.structs);
1052
+ const signer = params.signer;
1053
+ const selectedAccount = await signer.getSelectedAccount();
1054
+ const signerParams = {
1055
+ signerAddress: selectedAccount.address,
1056
+ signerKeyType: selectedAccount.keyType,
1057
+ bytecode: bytecode,
1058
+ attoAlphAmount: params.attoAlphAmount,
1059
+ tokens: params.tokens,
1060
+ gasAmount: params.gasAmount,
1061
+ gasPrice: params.gasPrice
1062
+ };
1063
+ return await signer.signAndSubmitExecuteScriptTx(signerParams);
1064
+ }
1065
+ exports.signExecuteMethod = signExecuteMethod;
1066
+ function getBytecodeTemplate(methodIndex, usePreapprovedAssets, functionSig, structs, attoAlphAmount, tokens) {
1067
+ // For the default TxScript main function
1068
+ const numberOfMethods = '01';
1069
+ const isPublic = '01';
1070
+ const modifier = usePreapprovedAssets ? '03' : '00';
1071
+ const argsLength = '00';
1072
+ const returnsLength = '00';
1073
+ const [templateVarStoreLocalInstrs, templateVarsLength] = getTemplateVarStoreLocalInstrs(functionSig, structs);
1074
+ const approveAlphInstrs = getApproveAlphInstrs(usePreapprovedAssets ? attoAlphAmount : undefined);
1075
+ const approveTokensInstrs = getApproveTokensInstrs(usePreapprovedAssets ? tokens : undefined);
1076
+ const callerInstrs = getCallAddressInstrs(approveAlphInstrs.length / 2 + approveTokensInstrs.length / 3);
1077
+ // First template var is the contract
1078
+ const functionArgsNum = encodeU256Const(BigInt(templateVarsLength - 1));
1079
+ const localsLength = encodeI32(templateVarStoreLocalInstrs.length / 2);
1080
+ const templateVarLoadLocalInstrs = getTemplateVarLoadLocalInstrs(functionSig, structs);
1081
+ const functionReturnTypesLength = functionSig.returnTypes.reduce((acc, returnType) => acc + ralph.typeLength(returnType, structs), 0);
1082
+ const functionReturnPopInstrs = encodeInstr(codec_1.Pop).repeat(functionReturnTypesLength);
1083
+ const functionReturnNum = encodeU256Const(BigInt(functionReturnTypesLength));
1084
+ const contractTemplateVar = '{0}'; // always the 1st argument
1085
+ const externalCallInstr = encodeInstr((0, codec_1.CallExternal)(methodIndex));
1086
+ const numberOfInstrs = encodeI32(callerInstrs.length +
1087
+ approveAlphInstrs.length +
1088
+ approveTokensInstrs.length +
1089
+ templateVarStoreLocalInstrs.length +
1090
+ templateVarLoadLocalInstrs.length +
1091
+ functionReturnTypesLength +
1092
+ 4 // functionArgsNum, functionReturnNum, contractTemplate, externalCallInstr
1093
+ );
1094
+ return (numberOfMethods +
1095
+ isPublic +
1096
+ modifier +
1097
+ argsLength +
1098
+ localsLength +
1099
+ returnsLength +
1100
+ numberOfInstrs +
1101
+ callerInstrs.join('') +
1102
+ approveAlphInstrs.join('') +
1103
+ approveTokensInstrs.join('') +
1104
+ templateVarStoreLocalInstrs.join('') +
1105
+ templateVarLoadLocalInstrs.join('') +
1106
+ functionArgsNum +
1107
+ functionReturnNum +
1108
+ contractTemplateVar +
1109
+ externalCallInstr +
1110
+ functionReturnPopInstrs);
1111
+ }
1112
+ function getApproveAlphInstrs(attoAlphAmount) {
1113
+ const approveAlphInstrs = [];
1114
+ if (attoAlphAmount) {
1115
+ const approvedAttoAlphAmount = encodeU256Const(BigInt(attoAlphAmount));
1116
+ approveAlphInstrs.push(approvedAttoAlphAmount);
1117
+ approveAlphInstrs.push(encodeInstr(codec_1.ApproveAlph));
1118
+ }
1119
+ return approveAlphInstrs;
1120
+ }
1121
+ function getApproveTokensInstrs(tokens) {
1122
+ const approveTokensInstrs = [];
1123
+ if (tokens) {
1124
+ tokens.forEach((token) => {
1125
+ const tokenIdBin = (0, utils_1.hexToBinUnsafe)(token.id);
1126
+ approveTokensInstrs.push(encodeInstr((0, codec_1.ByteConst)({
1127
+ length: codec_1.compactSignedIntCodec.fromI32(tokenIdBin.length),
1128
+ value: tokenIdBin
1129
+ })));
1130
+ approveTokensInstrs.push(encodeU256Const(BigInt(token.amount)));
1131
+ approveTokensInstrs.push(encodeInstr(codec_1.ApproveToken));
1132
+ });
1133
+ }
1134
+ return approveTokensInstrs;
1135
+ }
1136
+ function getCallAddressInstrs(approveAssetsNum) {
1137
+ const callerInstrs = [];
1138
+ if (approveAssetsNum > 0) {
1139
+ callerInstrs.push(encodeInstr(codec_1.CallerAddress));
1140
+ const dup = encodeInstr(codec_1.Dup);
1141
+ if (approveAssetsNum > 1) {
1142
+ callerInstrs.push(...new Array(approveAssetsNum - 1).fill(dup));
1143
+ }
1144
+ }
1145
+ return callerInstrs;
1146
+ }
1147
+ function getTemplateVarStoreLocalInstrs(functionSig, structs) {
1148
+ let templateVarIndex = 1; // Start from 1 since first one is always the contract id
1149
+ let localsLength = 0;
1150
+ const templateVarStoreInstrs = [];
1151
+ functionSig.paramTypes.forEach((paramType) => {
1152
+ const fieldsLength = ralph.typeLength(paramType, structs);
1153
+ if (fieldsLength > 1) {
1154
+ for (let i = 0; i < fieldsLength; i++) {
1155
+ templateVarStoreInstrs.push(`{${templateVarIndex + i}}`);
1156
+ }
1157
+ for (let i = 0; i < fieldsLength; i++) {
1158
+ templateVarStoreInstrs.push(encodeStoreLocalInstr(localsLength + (fieldsLength - i - 1)));
1159
+ }
1160
+ localsLength = localsLength + fieldsLength;
1161
+ }
1162
+ templateVarIndex = templateVarIndex + fieldsLength;
1163
+ });
1164
+ return [templateVarStoreInstrs, templateVarIndex];
1165
+ }
1166
+ function getTemplateVarLoadLocalInstrs(functionSig, structs) {
1167
+ let templateVarIndex = 1;
1168
+ let loadIndex = 0;
1169
+ const templateVarLoadInstrs = [];
1170
+ functionSig.paramTypes.forEach((paramType) => {
1171
+ const fieldsLength = ralph.typeLength(paramType, structs);
1172
+ if (fieldsLength === 1) {
1173
+ templateVarLoadInstrs.push(`{${templateVarIndex}}`);
1174
+ }
1175
+ if (fieldsLength > 1) {
1176
+ for (let i = 0; i < fieldsLength; i++) {
1177
+ templateVarLoadInstrs.push(encodeLoadLocalInstr(loadIndex + i));
1178
+ }
1179
+ loadIndex = loadIndex + fieldsLength;
1180
+ }
1181
+ templateVarIndex = templateVarIndex + fieldsLength;
1182
+ });
1183
+ return templateVarLoadInstrs;
1184
+ }
1185
+ function encodeStoreLocalInstr(index) {
1186
+ if (index < 0 || index > 0xff) {
1187
+ throw new Error(`StoreLocal index ${index} must be between 0 and 255 inclusive`);
1188
+ }
1189
+ return encodeInstr((0, codec_1.StoreLocal)(index));
1190
+ }
1191
+ function encodeLoadLocalInstr(index) {
1192
+ if (index < 0 || index > 0xff) {
1193
+ throw new Error(`LoadLocal index ${index} must be between 0 and 255 inclusive`);
1194
+ }
1195
+ return encodeInstr((0, codec_1.LoadLocal)(index));
1196
+ }
1197
+ function encodeI32(value) {
1198
+ return (0, utils_1.binToHex)(codec_1.compactSignedIntCodec.encodeI32(value));
1199
+ }
1200
+ function encodeU256Const(value) {
1201
+ if (value < 0) {
1202
+ throw new Error(`value ${value} must be non-negative`);
1203
+ }
1204
+ if (value < 6) {
1205
+ return (BigInt(0x0c) + value).toString(16).padStart(2, '0');
1206
+ }
1207
+ else {
1208
+ return encodeInstr((0, codec_1.U256Const)(codec_1.compactUnsignedIntCodec.fromU256(BigInt(value))));
1209
+ }
1210
+ }
1211
+ function encodeInstr(instr) {
1212
+ return (0, utils_1.binToHex)(codec_1.instrCodec.encode(instr));
1213
+ }
1214
+ function toFieldsSig(contractName, functionSig) {
1215
+ return {
1216
+ names: ['__contract__'].concat(functionSig.paramNames),
1217
+ types: [contractName].concat(functionSig.paramTypes),
1218
+ isMutable: [false].concat(functionSig.paramIsMutable)
1219
+ };
1220
+ }
1045
1221
  async function multicallMethods(contract, instance, calls, getContractByCodeHash) {
1046
1222
  const callEntries = Object.entries(calls);
1047
1223
  const callsParams = callEntries.map((entry) => {
@@ -5,7 +5,7 @@ export declare function encodeBool(bool: boolean): Uint8Array;
5
5
  export declare function decodeBool(bytes: Uint8Array): boolean;
6
6
  export declare function encodeI256(i256: bigint): Uint8Array;
7
7
  export declare function encodeU256(u256: bigint): Uint8Array;
8
- export declare function encodeByteVec(bytes: string): Uint8Array;
8
+ export declare function encodeByteVec(hex: string): Uint8Array;
9
9
  export declare function encodeAddress(address: string): Uint8Array;
10
10
  export declare enum VmValType {
11
11
  Bool = 0,
@@ -60,6 +60,7 @@ export declare function tryDecodeMapDebugLog(message: string): {
60
60
  } | undefined;
61
61
  export declare function decodePrimitive(value: Uint8Array, type: string): Val;
62
62
  export declare function primitiveToByteVec(value: Val, type: string): Uint8Array;
63
+ export declare function typeLength(typ: string, structs: Struct[]): number;
63
64
  export declare function flattenFields(fields: Fields, names: string[], types: string[], isMutable: boolean[], structs: Struct[]): {
64
65
  name: string;
65
66
  type: string;
@@ -18,8 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var _a;
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.encodeContractFields = exports.buildScriptByteCode = exports.flattenFields = exports.primitiveToByteVec = exports.decodePrimitive = exports.tryDecodeMapDebugLog = exports.calcFieldSize = exports.encodeMapPrefix = exports.parseMapType = exports.splitFields = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodePrimitiveValues = exports.addressVal = exports.byteVecVal = exports.u256Val = exports.i256Val = exports.boolVal = exports.encodeVmAddress = exports.encodeVmByteVec = exports.encodeVmU256 = exports.encodeVmI256 = exports.encodeVmBool = exports.VmValType = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.decodeBool = exports.encodeBool = void 0;
22
- const buffer_1 = require("buffer/");
21
+ exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.encodeContractFields = exports.buildScriptByteCode = exports.flattenFields = exports.typeLength = exports.primitiveToByteVec = exports.decodePrimitive = exports.tryDecodeMapDebugLog = exports.calcFieldSize = exports.encodeMapPrefix = exports.parseMapType = exports.splitFields = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodePrimitiveValues = exports.addressVal = exports.byteVecVal = exports.u256Val = exports.i256Val = exports.boolVal = exports.encodeVmAddress = exports.encodeVmByteVec = exports.encodeVmU256 = exports.encodeVmI256 = exports.encodeVmBool = exports.VmValType = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.decodeBool = exports.encodeBool = void 0;
23
22
  const api_1 = require("../api");
24
23
  const utils_1 = require("../utils");
25
24
  const codec_1 = require("../codec");
@@ -159,13 +158,13 @@ function encodeU256(u256) {
159
158
  }
160
159
  }
161
160
  exports.encodeU256 = encodeU256;
162
- function encodeByteVec(bytes) {
163
- if (!(0, utils_1.isHexString)(bytes)) {
164
- throw Error(`Given value ${bytes} is not a valid hex string`);
161
+ function encodeByteVec(hex) {
162
+ if (!(0, utils_1.isHexString)(hex)) {
163
+ throw Error(`Given value ${hex} is not a valid hex string`);
165
164
  }
166
- const buffer0 = buffer_1.Buffer.from(bytes, 'hex');
167
- const buffer1 = buffer_1.Buffer.from(encodeI256(BigInt(buffer0.length)));
168
- return buffer_1.Buffer.concat([buffer1, buffer0]);
165
+ const bytes0 = (0, utils_1.hexToBinUnsafe)(hex);
166
+ const bytes1 = encodeI256(BigInt(bytes0.length));
167
+ return (0, utils_1.concatBytes)([bytes1, bytes0]);
169
168
  }
170
169
  exports.encodeByteVec = encodeByteVec;
171
170
  function encodeAddress(address) {
@@ -258,7 +257,7 @@ function encodeScriptFieldU256(value) {
258
257
  return new Uint8Array([Instruction.u256Const, ...encodeU256(value)]);
259
258
  }
260
259
  function encodeScriptFieldAsString(tpe, value) {
261
- return buffer_1.Buffer.from(encodeScriptField(tpe, value)).toString('hex');
260
+ return (0, utils_1.binToHex)(encodeScriptField(tpe, value));
262
261
  }
263
262
  exports.encodeScriptFieldAsString = encodeScriptFieldAsString;
264
263
  function encodeScriptField(tpe, value) {
@@ -369,9 +368,9 @@ function decodePrimitive(value, type) {
369
368
  case 'Bool':
370
369
  return decodeBool(value);
371
370
  case 'I256':
372
- return codec_1.compactSignedIntCodec.decodeI256(buffer_1.Buffer.from(value));
371
+ return codec_1.compactSignedIntCodec.decodeI256(value);
373
372
  case 'U256':
374
- return codec_1.compactUnsignedIntCodec.decodeU256(buffer_1.Buffer.from(value));
373
+ return codec_1.compactUnsignedIntCodec.decodeU256(value);
375
374
  case 'ByteVec':
376
375
  return (0, utils_1.binToHex)(value);
377
376
  case 'Address':
@@ -403,6 +402,21 @@ function primitiveToByteVec(value, type) {
403
402
  }
404
403
  }
405
404
  exports.primitiveToByteVec = primitiveToByteVec;
405
+ function typeLength(typ, structs) {
406
+ if (api_1.PrimitiveTypes.includes(typ)) {
407
+ return 1;
408
+ }
409
+ if (typ.startsWith('[')) {
410
+ const [baseType, size] = (0, api_1.decodeArrayType)(typ);
411
+ return size * typeLength(baseType, structs);
412
+ }
413
+ const struct = structs.find((s) => s.name === typ);
414
+ if (struct !== undefined) {
415
+ return struct.fieldTypes.reduce((acc, fieldType) => acc + typeLength(fieldType, structs), 0);
416
+ }
417
+ return 1;
418
+ }
419
+ exports.typeLength = typeLength;
406
420
  function flattenFields(fields, names, types, isMutable, structs) {
407
421
  return names.flatMap((name, index) => {
408
422
  if (!(name in fields)) {
@@ -18,9 +18,9 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.getAddressFromUnlockScript = exports.getSenderAddress = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
21
+ const address_1 = require("../address");
21
22
  const utils_1 = require("../utils");
22
23
  const unlock_script_codec_1 = require("../codec/unlock-script-codec");
23
- const buffer_1 = require("buffer/");
24
24
  const script_codec_1 = require("../codec/script-codec");
25
25
  function validateExchangeAddress(address) {
26
26
  let decoded;
@@ -33,7 +33,7 @@ function validateExchangeAddress(address) {
33
33
  if (decoded.length === 0)
34
34
  throw new Error('Address is empty');
35
35
  const addressType = decoded[0];
36
- if (addressType !== utils_1.AddressType.P2PKH && addressType !== utils_1.AddressType.P2SH) {
36
+ if (addressType !== address_1.AddressType.P2PKH && addressType !== address_1.AddressType.P2SH) {
37
37
  throw new Error('Invalid address type');
38
38
  }
39
39
  if (decoded.length !== 33) {
@@ -98,7 +98,7 @@ function getAddressFromUnlockScript(unlockScript) {
98
98
  if (unlockScriptBody.length !== 33) {
99
99
  throw new Error(`Invalid p2pkh unlock script: ${unlockScript}`);
100
100
  }
101
- return (0, utils_1.addressFromPublicKey)((0, utils_1.binToHex)(unlockScriptBody));
101
+ return (0, address_1.addressFromPublicKey)((0, utils_1.binToHex)(unlockScriptBody));
102
102
  }
103
103
  if (unlockScriptType === UnlockScriptType.P2MPKH) {
104
104
  throw new Error('Naive multi-sig address is not supported for exchanges as it will be replaced by P2SH');
@@ -106,12 +106,12 @@ function getAddressFromUnlockScript(unlockScript) {
106
106
  if (unlockScriptType === UnlockScriptType.P2SH) {
107
107
  let p2sh;
108
108
  try {
109
- p2sh = unlock_script_codec_1.unlockScriptCodec.decode(buffer_1.Buffer.from(decoded)).script;
109
+ p2sh = unlock_script_codec_1.unlockScriptCodec.decode(decoded).script;
110
110
  }
111
111
  catch (_) {
112
112
  throw new Error(`Invalid p2sh unlock script: ${unlockScript}`);
113
113
  }
114
- return (0, utils_1.addressFromScript)(script_codec_1.scriptCodec.encode(p2sh.script));
114
+ return (0, address_1.addressFromScript)(script_codec_1.scriptCodec.encode(p2sh.script));
115
115
  }
116
116
  throw new Error('Invalid unlock script type');
117
117
  }
@@ -0,0 +1 @@
1
+ export { validateExchangeAddress, isALPHTransferTx, getSenderAddress, getALPHDepositInfo } from './exchange';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.getALPHDepositInfo = exports.getSenderAddress = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
21
+ var exchange_1 = require("./exchange");
22
+ Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
23
+ Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
24
+ Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
25
+ Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
@@ -10,3 +10,5 @@ export * as codec from './codec';
10
10
  export * as utils from './utils';
11
11
  export * from './debug';
12
12
  export * from './block';
13
+ export * from './address';
14
+ export * from './exchange';
package/dist/src/index.js CHANGED
@@ -59,3 +59,5 @@ exports.codec = __importStar(require("./codec"));
59
59
  exports.utils = __importStar(require("./utils"));
60
60
  __exportStar(require("./debug"), exports);
61
61
  __exportStar(require("./block"), exports);
62
+ __exportStar(require("./address"), exports);
63
+ __exportStar(require("./exchange"), exports);
@@ -44,13 +44,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.hashMessage = exports.extendMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
47
- const buffer_1 = require("buffer/");
48
47
  const crypto_1 = require("crypto");
49
48
  const api_1 = require("../api");
50
49
  const utils = __importStar(require("../utils"));
51
50
  const blakejs_1 = __importDefault(require("blakejs"));
52
51
  const tx_builder_1 = require("./tx-builder");
53
- const utils_1 = require("../utils");
52
+ const address_1 = require("../address");
54
53
  class SignerProvider {
55
54
  async getSelectedAccount() {
56
55
  const account = await this.unsafeGetSelectedAccount();
@@ -58,8 +57,8 @@ class SignerProvider {
58
57
  return account;
59
58
  }
60
59
  static validateAccount(account) {
61
- const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
62
- const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
60
+ const derivedAddress = (0, address_1.addressFromPublicKey)(account.publicKey, account.keyType);
61
+ const derivedGroup = (0, address_1.groupOfAddress)(derivedAddress);
63
62
  if (derivedAddress !== account.address || derivedGroup !== account.group) {
64
63
  throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
65
64
  }
@@ -206,7 +205,7 @@ function hashMessage(message, hasher) {
206
205
  return utils.binToHex(blakejs_1.default.blake2b(extendMessage(message), undefined, 32));
207
206
  case 'sha256':
208
207
  const sha256 = (0, crypto_1.createHash)('sha256');
209
- sha256.update(buffer_1.Buffer.from(message));
208
+ sha256.update(new TextEncoder().encode(message));
210
209
  return utils.binToHex(sha256.digest());
211
210
  case 'blake2b':
212
211
  return utils.binToHex(blakejs_1.default.blake2b(message, undefined, 32));
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.TransactionBuilder = void 0;
21
21
  const utils_1 = require("../utils");
22
22
  const api_1 = require("../api");
23
- const utils_2 = require("../utils");
23
+ const address_1 = require("../address");
24
24
  const signer_1 = require("./signer");
25
25
  class TransactionBuilder {
26
26
  static from(param0, param1, customFetch) {
@@ -32,7 +32,7 @@ class TransactionBuilder {
32
32
  })();
33
33
  }
34
34
  static validatePublicKey(params, publicKey, keyType) {
35
- const address = (0, utils_2.addressFromPublicKey)(publicKey, keyType);
35
+ const address = (0, address_1.addressFromPublicKey)(publicKey, keyType);
36
36
  if (address !== params.signerAddress) {
37
37
  throw new Error('Unmatched public key');
38
38
  }
@@ -63,7 +63,7 @@ class TransactionBuilder {
63
63
  ...rest
64
64
  };
65
65
  const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data);
66
- const contractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(response.contractAddress));
66
+ const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(response.contractAddress));
67
67
  return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
68
68
  }
69
69
  async buildExecuteScriptTx(params, publicKey) {
@@ -1,9 +1,7 @@
1
1
  export * from './webcrypto';
2
- export * from './address';
3
2
  export * from './bs58';
4
3
  export * from './djb2';
5
4
  export * from './utils';
6
5
  export * from './subscription';
7
6
  export * from './sign';
8
7
  export * from './number';
9
- export { validateExchangeAddress, isALPHTransferTx, getSenderAddress, getALPHDepositInfo } from './exchange';
@@ -31,17 +31,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
31
31
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.getALPHDepositInfo = exports.getSenderAddress = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
35
34
  __exportStar(require("./webcrypto"), exports);
36
- __exportStar(require("./address"), exports);
37
35
  __exportStar(require("./bs58"), exports);
38
36
  __exportStar(require("./djb2"), exports);
39
37
  __exportStar(require("./utils"), exports);
40
38
  __exportStar(require("./subscription"), exports);
41
39
  __exportStar(require("./sign"), exports);
42
40
  __exportStar(require("./number"), exports);
43
- var exchange_1 = require("./exchange");
44
- Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
45
- Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
46
- Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
47
- Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
@@ -53,7 +53,7 @@ necc.utils.sha256Sync = (...messages) => {
53
53
  return sha256.digest();
54
54
  };
55
55
  necc.utils.hmacSha256Sync = (key, ...messages) => {
56
- const hash = (0, crypto_1.createHmac)('sha256', Buffer.from(key));
56
+ const hash = (0, crypto_1.createHmac)('sha256', key);
57
57
  messages.forEach((m) => hash.update(m));
58
58
  return Uint8Array.from(hash.digest());
59
59
  };
@@ -23,6 +23,7 @@ export declare function sleep(ms: number): Promise<void>;
23
23
  export declare function isDevnet(networkId?: number): boolean;
24
24
  export declare function targetToDifficulty(compactedTarget: HexString): bigint;
25
25
  export declare function difficultyToTarget(diff: bigint): HexString;
26
+ export declare function concatBytes(arrays: Uint8Array[]): Uint8Array;
26
27
  type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
27
28
  export type Eq<X, Y> = _Eq<{
28
29
  [P in keyof X]: X[P];