@hiero-ledger/sdk 2.81.0 → 2.82.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 (137) hide show
  1. package/dist/umd.js +14018 -16573
  2. package/dist/umd.js.map +1 -1
  3. package/dist/umd.min.js +14 -21
  4. package/dist/umd.min.js.map +1 -1
  5. package/lib/EntityIdHelper.cjs +4 -4
  6. package/lib/EntityIdHelper.js +1 -1
  7. package/lib/EntityIdHelper.js.map +1 -1
  8. package/lib/EthereumFlow.d.ts +2 -2
  9. package/lib/EthereumTransaction.d.ts +2 -2
  10. package/lib/EthereumTransactionDataEip1559.cjs +3 -3
  11. package/lib/EthereumTransactionDataEip1559.js +1 -1
  12. package/lib/EthereumTransactionDataEip1559.js.map +1 -1
  13. package/lib/EthereumTransactionDataEip2930.cjs +3 -3
  14. package/lib/EthereumTransactionDataEip2930.js +1 -1
  15. package/lib/EthereumTransactionDataEip2930.js.map +1 -1
  16. package/lib/EthereumTransactionDataEip7702.cjs +3 -3
  17. package/lib/EthereumTransactionDataEip7702.js +1 -1
  18. package/lib/EthereumTransactionDataEip7702.js.map +1 -1
  19. package/lib/EthereumTransactionDataLegacy.cjs +3 -3
  20. package/lib/EthereumTransactionDataLegacy.js +1 -1
  21. package/lib/EthereumTransactionDataLegacy.js.map +1 -1
  22. package/lib/PrivateKey.cjs +2 -2
  23. package/lib/PrivateKey.js +1 -1
  24. package/lib/PrivateKey.js.map +1 -1
  25. package/lib/Transfer.d.ts +1 -1
  26. package/lib/account/AccountAllowanceAdjustTransaction.d.ts +1 -1
  27. package/lib/account/AccountAllowanceApproveTransaction.d.ts +1 -1
  28. package/lib/account/AccountAllowanceDeleteTransaction.d.ts +1 -1
  29. package/lib/account/AccountCreateTransaction.d.ts +2 -2
  30. package/lib/account/AccountInfoQuery.cjs +7 -8
  31. package/lib/account/AccountInfoQuery.d.ts +8 -0
  32. package/lib/account/AccountInfoQuery.js +1 -1
  33. package/lib/account/AccountInfoQuery.js.map +1 -1
  34. package/lib/account/HbarTransferMap.d.ts +1 -1
  35. package/lib/account/ProxyStaker.d.ts +1 -1
  36. package/lib/account/TokenAllowance.d.ts +1 -1
  37. package/lib/account/TokenTransferMap.d.ts +1 -1
  38. package/lib/account/TransferTransaction.d.ts +1 -1
  39. package/lib/client/addressbooks/mainnet.cjs +1 -1
  40. package/lib/client/addressbooks/mainnet.d.ts +1 -1
  41. package/lib/client/addressbooks/mainnet.js +1 -1
  42. package/lib/client/addressbooks/mainnet.js.map +1 -1
  43. package/lib/client/addressbooks/previewnet.cjs +1 -1
  44. package/lib/client/addressbooks/previewnet.d.ts +1 -1
  45. package/lib/client/addressbooks/previewnet.js +1 -1
  46. package/lib/client/addressbooks/previewnet.js.map +1 -1
  47. package/lib/contract/ContractByteCodeQuery.cjs +2 -1
  48. package/lib/contract/ContractByteCodeQuery.d.ts +8 -2
  49. package/lib/contract/ContractByteCodeQuery.js.map +1 -1
  50. package/lib/contract/ContractCallQuery.cjs +2 -1
  51. package/lib/contract/ContractCallQuery.d.ts +8 -2
  52. package/lib/contract/ContractCallQuery.js.map +1 -1
  53. package/lib/contract/ContractCreateFlow.d.ts +1 -1
  54. package/lib/contract/ContractCreateTransaction.d.ts +2 -2
  55. package/lib/contract/ContractExecuteTransaction.cjs +2 -1
  56. package/lib/contract/ContractExecuteTransaction.d.ts +6 -8
  57. package/lib/contract/ContractExecuteTransaction.js.map +1 -1
  58. package/lib/contract/ContractFunctionParameters.cjs +5 -4
  59. package/lib/contract/ContractFunctionParameters.js +1 -1
  60. package/lib/contract/ContractFunctionParameters.js.map +1 -1
  61. package/lib/contract/ContractFunctionResult.cjs +70 -31
  62. package/lib/contract/ContractFunctionResult.d.ts +13 -3
  63. package/lib/contract/ContractFunctionResult.js +1 -1
  64. package/lib/contract/ContractFunctionResult.js.map +1 -1
  65. package/lib/contract/ContractId.cjs +3 -1
  66. package/lib/contract/ContractId.d.ts +6 -2
  67. package/lib/contract/ContractId.js.map +1 -1
  68. package/lib/contract/ContractInfoQuery.cjs +2 -1
  69. package/lib/contract/ContractInfoQuery.d.ts +8 -2
  70. package/lib/contract/ContractInfoQuery.js.map +1 -1
  71. package/lib/contract/DelegateContractId.cjs +3 -1
  72. package/lib/contract/DelegateContractId.d.ts +6 -2
  73. package/lib/contract/DelegateContractId.js.map +1 -1
  74. package/lib/cryptography/sha384.browser.cjs +3 -2
  75. package/lib/cryptography/sha384.browser.d.ts +2 -2
  76. package/lib/cryptography/sha384.browser.js +1 -1
  77. package/lib/cryptography/sha384.browser.js.map +1 -1
  78. package/lib/exports.js +1 -1
  79. package/lib/exports.js.map +1 -1
  80. package/lib/node/NodeUpdateTransaction.cjs +3 -3
  81. package/lib/node/NodeUpdateTransaction.js +1 -1
  82. package/lib/node/NodeUpdateTransaction.js.map +1 -1
  83. package/lib/schedule/ScheduleCreateTransaction.d.ts +1 -1
  84. package/lib/schedule/ScheduleDeleteTransaction.d.ts +1 -1
  85. package/lib/schedule/ScheduleId.cjs +3 -1
  86. package/lib/schedule/ScheduleId.d.ts +5 -1
  87. package/lib/schedule/ScheduleId.js.map +1 -1
  88. package/lib/schedule/ScheduleSignTransaction.d.ts +1 -1
  89. package/lib/token/AbstractTokenTransferTransaction.d.ts +1 -1
  90. package/lib/token/AssessedCustomFee.d.ts +2 -2
  91. package/lib/token/CustomFixedFee.d.ts +2 -2
  92. package/lib/token/PendingAirdropId.cjs +22 -21
  93. package/lib/token/PendingAirdropId.d.ts +16 -16
  94. package/lib/token/PendingAirdropId.js +1 -1
  95. package/lib/token/PendingAirdropId.js.map +1 -1
  96. package/lib/token/PendingAirdropRecord.d.ts +1 -1
  97. package/lib/token/TokenAirdropTransaction.d.ts +1 -1
  98. package/lib/token/TokenBurnTransaction.d.ts +2 -2
  99. package/lib/token/TokenCreateTransaction.d.ts +3 -3
  100. package/lib/token/TokenFeeScheduleUpdateTransaction.d.ts +1 -1
  101. package/lib/token/TokenMintTransaction.d.ts +2 -2
  102. package/lib/token/TokenNftTransfer.d.ts +1 -1
  103. package/lib/token/TokenTransfer.d.ts +1 -1
  104. package/lib/token/TokenUpdateTransaction.d.ts +1 -1
  105. package/lib/token/TokenWipeTransaction.d.ts +2 -2
  106. package/lib/transaction/Transaction.cjs +45 -1
  107. package/lib/transaction/Transaction.d.ts +19 -1
  108. package/lib/transaction/Transaction.js +1 -1
  109. package/lib/transaction/Transaction.js.map +1 -1
  110. package/lib/util.cjs +5 -1
  111. package/lib/util.js +1 -1
  112. package/lib/util.js.map +1 -1
  113. package/lib/version.js +1 -1
  114. package/package.json +8 -11
  115. package/src/EntityIdHelper.js +4 -4
  116. package/src/EthereumTransactionDataEip1559.js +3 -3
  117. package/src/EthereumTransactionDataEip2930.js +3 -3
  118. package/src/EthereumTransactionDataEip7702.js +3 -3
  119. package/src/EthereumTransactionDataLegacy.js +3 -3
  120. package/src/PrivateKey.js +1 -1
  121. package/src/account/AccountInfoQuery.js +8 -7
  122. package/src/client/addressbooks/mainnet.js +1 -1
  123. package/src/client/addressbooks/previewnet.js +1 -1
  124. package/src/contract/ContractByteCodeQuery.js +2 -1
  125. package/src/contract/ContractCallQuery.js +2 -1
  126. package/src/contract/ContractExecuteTransaction.js +2 -1
  127. package/src/contract/ContractFunctionParameters.js +4 -3
  128. package/src/contract/ContractFunctionResult.js +48 -3
  129. package/src/contract/ContractId.js +3 -1
  130. package/src/contract/ContractInfoQuery.js +2 -1
  131. package/src/contract/DelegateContractId.js +3 -1
  132. package/src/cryptography/sha384.browser.js +4 -2
  133. package/src/node/NodeUpdateTransaction.js +6 -3
  134. package/src/schedule/ScheduleId.js +3 -1
  135. package/src/token/PendingAirdropId.js +31 -21
  136. package/src/transaction/Transaction.js +66 -1
  137. package/src/util.js +5 -6
@@ -25,7 +25,7 @@ var util = _interopRequireWildcard(require("./util.cjs"));
25
25
  var _base = _interopRequireDefault(require("./base32.cjs"));
26
26
  var HieroProto = _interopRequireWildcard(require("@hiero-ledger/proto"));
27
27
  var _PublicKey = _interopRequireDefault(require("./PublicKey.cjs"));
28
- var _bytes = require("@ethersproject/bytes");
28
+ var _ethers = require("ethers");
29
29
  var _EvmAddress = _interopRequireDefault(require("./EvmAddress.cjs"));
30
30
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
31
31
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -520,7 +520,7 @@ function publicKeyToAlias(publicKey) {
520
520
  if (!publicKey.startsWith("0x")) {
521
521
  publicKey = `0x${publicKey}`;
522
522
  }
523
- const bytes = (0, _bytes.arrayify)(publicKey);
523
+ const bytes = (0, _ethers.getBytes)(publicKey);
524
524
  if (!bytes) {
525
525
  return null;
526
526
  }
@@ -538,8 +538,8 @@ function publicKeyToAlias(publicKey) {
538
538
  if (!publicKeyHex.startsWith("0x")) {
539
539
  publicKeyHex = `0x${publicKeyHex}`;
540
540
  }
541
- const leadingBytes = (0, _bytes.arrayify)(leadingHex);
542
- const publicKeyBytes = (0, _bytes.arrayify)(publicKeyHex);
541
+ const leadingBytes = (0, _ethers.getBytes)(leadingHex);
542
+ const publicKeyBytes = (0, _ethers.getBytes)(publicKeyHex);
543
543
  const publicKeyInBytes = appendBuffer(leadingBytes, publicKeyBytes);
544
544
  const alias = _base.default.encode(publicKeyInBytes);
545
545
  return alias;
@@ -1,2 +1,2 @@
1
- import e from"long";import{isHexString as r,decode as t,encode as n}from"./encoding/hex.js";import o from"./BadEntityIdError.js";import{isLongZeroAddress as l,safeView as i,convertToNumber as s}from"./util.js";import u from"./base32.js";import*as a from"@hiero-ledger/proto";import c from"./PublicKey.js";import{arrayify as m}from"@ethersproject/bytes";import f from"./EvmAddress.js";const h=/"^(0|(?:[1-9]\\d*))\\.(0|(?:[1-9]\\d*))\\.(0|(?:[1-9]\\d*))(?:-([a-z]{5}))?$/,d=/^(\d+)(?:\.(\d+)\.([a-fA-F0-9]+))?(?:-([a-z]{5}))?$/;function g(r,t,n){if(null==t&&null!=n||null!=t&&null==n)throw new Error("invalid entity ID");const[o,l,i]="number"==typeof r||e.isLong(r)?[null!=n?e.fromValue(r):e.ZERO,null!=t?e.fromValue(t):e.ZERO,null!=n?e.fromValue(n):e.fromValue(r)]:[null!=r.shard?e.fromValue(r.shard):e.ZERO,null!=r.realm?e.fromValue(r.realm):e.ZERO,e.fromValue(r.num)];if(o.isNegative()||l.isNegative()||i.isNegative())throw new Error("negative numbers are not allowed in IDs");return{shard:o,realm:l,num:i}}function w(e,r){let t=e[0].compare(r[0]);return 0!=t?t:(t=e[1].compare(r[1]),0!=t?t:e[2].compare(r[2]))}function y(e){const r=d.exec(e);if(null==r)throw new Error(`failed to parse entity id: ${e}`);return null==r[2]&&null==r[3]?{shard:"0",realm:"0",numOrHex:r[1],checksum:r[4]}:{shard:r[1],realm:r[2],numOrHex:r[3],checksum:r[4]}}function E(r){const t=y(r);if(Number.isNaN(t.shard)||Number.isNaN(t.realm)||Number.isNaN(t.numOrHex))throw new Error("invalid format for entity ID");return{shard:null!=t.shard?e.fromString(t.shard):e.ZERO,realm:null!=t.realm?e.fromString(t.realm):e.ZERO,num:e.fromString(t.numOrHex),checksum:t.checksum}}function p(r){const n=r.startsWith("0x")?t(r.slice(2)):t(r);if(20!==n.length)throw new Error(`Invalid hex encoded solidity address length:\n expected length 40, got length ${r.length}`);return[e.fromBytesBE([0,0,0,0,...n.slice(0,4)]),e.fromBytesBE(Array.from(n.slice(4,12))),e.fromBytesBE(Array.from(n.slice(12,20)))]}function S(n,o,i){if(!r(i))throw new Error(`Invalid EVM address hex string: ${i}`);const s=i.startsWith("0x")?t(i.slice(2)):t(i);if(20!==s.length)throw new Error(`Invalid hex encoded evm address length:\n expected length 20, got length ${i.length}`);let u=e.ZERO;return l(s)&&(u=e.fromBytesBE(Array.from(s.slice(12,20)))),[n instanceof e?n:e.fromNumber(n),o instanceof e?o:e.fromNumber(o),u,u.isZero()?f.fromBytes(s):null]}function x(e){const r=new Uint8Array(20),t=i(r),[o,l,u]=e;return t.setUint32(0,s(o)),t.setUint32(8,s(l)),t.setUint32(16,s(u)),n(r)}function k(e){if(e instanceof Uint8Array)return n(e);const r=e,t=new Uint8Array(20);return i(t).setUint32(16,s(r)),n(t)}function A(r,t){let n=h.exec(t);if(null===n){return{status:0}}let o=[e.fromString(n[1]),e.fromString(n[2]),e.fromString(n[3])],l=`${o[0].toString()}.${o[1].toString()}.${o[2].toString()}`,i=$(r,l);return{status:void 0===n[4]?2:i==n[4]?3:1,num1:o[0],num2:o[1],num3:o[2],givenChecksum:n[4],correctChecksum:i,noChecksumFormat:l,withChecksumFormat:`${l}-${i}`}}function $(e,r){let t="",n=[],o=0,l=0,i=0,s=0,u=0;const a=11881376,c="a".charCodeAt(0);let m=new Uint8Array(e.length+6);m.set(e,0),m.set([0,0,0,0,0,0],e.length);for(let e=0;e<r.length;e++)n.push("."===r[e]?10:parseInt(r[e],10));for(let e=0;e<n.length;e++)i=(31*i+n[e])%17576,e%2==0?o=(o+n[e])%11:l=(l+n[e])%11;for(let e=0;e<m.length;e++)s=(31*s+m[e])%a;u=(17576*(11*(r.length%5*11+o)+l)+i+s)%a,u=1000003*u%a;for(let e=0;e<5;e++)t=String.fromCharCode(c+u%26)+t,u/=26;return t}function b(e,r,t,n,l){if(null==l._network._ledgerId||null==n)return;const i=$(l._network._ledgerId._ledgerId,`${e.toString()}.${r.toString()}.${t.toString()}`);if(n!=i)throw new o(e,r,t,n,i)}function v(e,r){if(null==r)throw new Error("client cannot be null");if(null==r._network._ledgerId)throw new Error("cannot calculate checksum with a client that does not contain a recognzied ledger ID");return`${e}-${$(r._network._ledgerId._ledgerId,e)}`}function I(e){const r=u.decode(e);if(!r)return null;let t;try{t=a.proto.Key.decode(r)}catch(e){throw new Error("The alias is created with hollow account. Please use aliasToEvmAddress!")}return null!=t.ed25519&&t.ed25519.byteLength>0?c.fromBytes(t.ed25519):null!=t.ECDSASecp256k1&&t.ECDSASecp256k1.byteLength>0?c.fromBytes(t.ECDSASecp256k1):null}function N(e){const r=u.decode(e);if(!r)return null;try{throw a.proto.Key.decode(r),new Error("The alias is created with ed25519 or ECDSASecp256k1 account. Please use aliasToPublicKey!")}catch(e){return function(e){var r="0x";return e.forEach(function(e){r+=("0"+(255&e).toString(16)).slice(-2)}),r}(r)}}function _(e){if("string"==typeof e&&(e.startsWith("0x")&&42==e.length||40==e.length)){e.startsWith("0x")||(e=`0x${e}`);const r=m(e);return r?u.encode(r):null}const r="string"==typeof e?c.fromString(e):e;let t=r.toStringRaw(),n="";"secp256k1"===r._key._type&&(n="0x3A21"),"ED25519"===r._key._type&&(n="0x1220"),t.startsWith("0x")||(t=`0x${t}`);const o=m(n),l=m(t),i=(s=o,a=l,(f=new Uint8Array(s.byteLength+a.byteLength)).set(new Uint8Array(s),0),f.set(new Uint8Array(a),s.byteLength),f);var s,a,f;return u.encode(i)}export{$ as _checksum,A as _parseAddress,N as aliasToEvmAddress,I as aliasToPublicKey,w as compare,g as constructor,S as fromEvmAddress,p as fromSolidityAddress,E as fromString,y as fromStringSplitter,_ as publicKeyToAlias,k as toEvmAddress,x as toSolidityAddress,v as toStringWithChecksum,b as validateChecksum};
1
+ import e from"long";import{isHexString as r,decode as t,encode as n}from"./encoding/hex.js";import o from"./BadEntityIdError.js";import{isLongZeroAddress as l,safeView as i,convertToNumber as s}from"./util.js";import u from"./base32.js";import*as a from"@hiero-ledger/proto";import c from"./PublicKey.js";import{getBytes as m}from"ethers";import f from"./EvmAddress.js";const h=/"^(0|(?:[1-9]\\d*))\\.(0|(?:[1-9]\\d*))\\.(0|(?:[1-9]\\d*))(?:-([a-z]{5}))?$/,d=/^(\d+)(?:\.(\d+)\.([a-fA-F0-9]+))?(?:-([a-z]{5}))?$/;function g(r,t,n){if(null==t&&null!=n||null!=t&&null==n)throw new Error("invalid entity ID");const[o,l,i]="number"==typeof r||e.isLong(r)?[null!=n?e.fromValue(r):e.ZERO,null!=t?e.fromValue(t):e.ZERO,null!=n?e.fromValue(n):e.fromValue(r)]:[null!=r.shard?e.fromValue(r.shard):e.ZERO,null!=r.realm?e.fromValue(r.realm):e.ZERO,e.fromValue(r.num)];if(o.isNegative()||l.isNegative()||i.isNegative())throw new Error("negative numbers are not allowed in IDs");return{shard:o,realm:l,num:i}}function w(e,r){let t=e[0].compare(r[0]);return 0!=t?t:(t=e[1].compare(r[1]),0!=t?t:e[2].compare(r[2]))}function y(e){const r=d.exec(e);if(null==r)throw new Error(`failed to parse entity id: ${e}`);return null==r[2]&&null==r[3]?{shard:"0",realm:"0",numOrHex:r[1],checksum:r[4]}:{shard:r[1],realm:r[2],numOrHex:r[3],checksum:r[4]}}function E(r){const t=y(r);if(Number.isNaN(t.shard)||Number.isNaN(t.realm)||Number.isNaN(t.numOrHex))throw new Error("invalid format for entity ID");return{shard:null!=t.shard?e.fromString(t.shard):e.ZERO,realm:null!=t.realm?e.fromString(t.realm):e.ZERO,num:e.fromString(t.numOrHex),checksum:t.checksum}}function p(r){const n=r.startsWith("0x")?t(r.slice(2)):t(r);if(20!==n.length)throw new Error(`Invalid hex encoded solidity address length:\n expected length 40, got length ${r.length}`);return[e.fromBytesBE([0,0,0,0,...n.slice(0,4)]),e.fromBytesBE(Array.from(n.slice(4,12))),e.fromBytesBE(Array.from(n.slice(12,20)))]}function S(n,o,i){if(!r(i))throw new Error(`Invalid EVM address hex string: ${i}`);const s=i.startsWith("0x")?t(i.slice(2)):t(i);if(20!==s.length)throw new Error(`Invalid hex encoded evm address length:\n expected length 20, got length ${i.length}`);let u=e.ZERO;return l(s)&&(u=e.fromBytesBE(Array.from(s.slice(12,20)))),[n instanceof e?n:e.fromNumber(n),o instanceof e?o:e.fromNumber(o),u,u.isZero()?f.fromBytes(s):null]}function x(e){const r=new Uint8Array(20),t=i(r),[o,l,u]=e;return t.setUint32(0,s(o)),t.setUint32(8,s(l)),t.setUint32(16,s(u)),n(r)}function k(e){if(e instanceof Uint8Array)return n(e);const r=e,t=new Uint8Array(20);return i(t).setUint32(16,s(r)),n(t)}function A(r,t){let n=h.exec(t);if(null===n){return{status:0}}let o=[e.fromString(n[1]),e.fromString(n[2]),e.fromString(n[3])],l=`${o[0].toString()}.${o[1].toString()}.${o[2].toString()}`,i=$(r,l);return{status:void 0===n[4]?2:i==n[4]?3:1,num1:o[0],num2:o[1],num3:o[2],givenChecksum:n[4],correctChecksum:i,noChecksumFormat:l,withChecksumFormat:`${l}-${i}`}}function $(e,r){let t="",n=[],o=0,l=0,i=0,s=0,u=0;const a=11881376,c="a".charCodeAt(0);let m=new Uint8Array(e.length+6);m.set(e,0),m.set([0,0,0,0,0,0],e.length);for(let e=0;e<r.length;e++)n.push("."===r[e]?10:parseInt(r[e],10));for(let e=0;e<n.length;e++)i=(31*i+n[e])%17576,e%2==0?o=(o+n[e])%11:l=(l+n[e])%11;for(let e=0;e<m.length;e++)s=(31*s+m[e])%a;u=(17576*(11*(r.length%5*11+o)+l)+i+s)%a,u=1000003*u%a;for(let e=0;e<5;e++)t=String.fromCharCode(c+u%26)+t,u/=26;return t}function b(e,r,t,n,l){if(null==l._network._ledgerId||null==n)return;const i=$(l._network._ledgerId._ledgerId,`${e.toString()}.${r.toString()}.${t.toString()}`);if(n!=i)throw new o(e,r,t,n,i)}function v(e,r){if(null==r)throw new Error("client cannot be null");if(null==r._network._ledgerId)throw new Error("cannot calculate checksum with a client that does not contain a recognzied ledger ID");return`${e}-${$(r._network._ledgerId._ledgerId,e)}`}function I(e){const r=u.decode(e);if(!r)return null;let t;try{t=a.proto.Key.decode(r)}catch(e){throw new Error("The alias is created with hollow account. Please use aliasToEvmAddress!")}return null!=t.ed25519&&t.ed25519.byteLength>0?c.fromBytes(t.ed25519):null!=t.ECDSASecp256k1&&t.ECDSASecp256k1.byteLength>0?c.fromBytes(t.ECDSASecp256k1):null}function N(e){const r=u.decode(e);if(!r)return null;try{throw a.proto.Key.decode(r),new Error("The alias is created with ed25519 or ECDSASecp256k1 account. Please use aliasToPublicKey!")}catch(e){return function(e){var r="0x";return e.forEach(function(e){r+=("0"+(255&e).toString(16)).slice(-2)}),r}(r)}}function _(e){if("string"==typeof e&&(e.startsWith("0x")&&42==e.length||40==e.length)){e.startsWith("0x")||(e=`0x${e}`);const r=m(e);return r?u.encode(r):null}const r="string"==typeof e?c.fromString(e):e;let t=r.toStringRaw(),n="";"secp256k1"===r._key._type&&(n="0x3A21"),"ED25519"===r._key._type&&(n="0x1220"),t.startsWith("0x")||(t=`0x${t}`);const o=m(n),l=m(t),i=(s=o,a=l,(f=new Uint8Array(s.byteLength+a.byteLength)).set(new Uint8Array(s),0),f.set(new Uint8Array(a),s.byteLength),f);var s,a,f;return u.encode(i)}export{$ as _checksum,A as _parseAddress,N as aliasToEvmAddress,I as aliasToPublicKey,w as compare,g as constructor,S as fromEvmAddress,p as fromSolidityAddress,E as fromString,y as fromStringSplitter,_ as publicKeyToAlias,k as toEvmAddress,x as toSolidityAddress,v as toStringWithChecksum,b as validateChecksum};
2
2
  //# sourceMappingURL=EntityIdHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityIdHelper.js","sources":["../src/EntityIdHelper.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Long from \"long\";\nimport * as hex from \"./encoding/hex.js\";\nimport BadEntityIdError from \"./BadEntityIdError.js\";\nimport * as util from \"./util.js\";\nimport base32 from \"./base32.js\";\nimport * as HieroProto from \"@hiero-ledger/proto\";\nimport PublicKey from \"./PublicKey.js\";\nimport { arrayify } from \"@ethersproject/bytes\";\nimport EvmAddress from \"./EvmAddress.js\";\n\n/**\n * @typedef {import(\"./client/Client.js\").default<*, *>} Client\n */\n\n/**\n * @typedef {object} IEntityId\n * @property {number | Long} num\n * @property {(number | Long)=} shard\n * @property {(number | Long)=} realm\n */\n\n/**\n * @typedef {object} IEntityIdResult\n * @property {Long} shard\n * @property {Long} realm\n * @property {Long} num\n */\n\n/**\n * @typedef {object} IEntityIdParts\n * @property {string?} shard\n * @property {string?} realm\n * @property {string} numOrHex\n * @property {string?} checksum\n */\n\n/**\n * @typedef {object} IEntityIdResultWithChecksum\n * @property {Long} shard\n * @property {Long} realm\n * @property {Long} num\n * @property {string | null} checksum\n */\n\nconst regex =\n /\"^(0|(?:[1-9]\\\\d*))\\\\.(0|(?:[1-9]\\\\d*))\\\\.(0|(?:[1-9]\\\\d*))(?:-([a-z]{5}))?$/;\n\n/**\n * This regex supports entity IDs\n * - as stand alone nubmers\n * - as shard.realm.num\n * - as shard.realm.hex\n * - can optionally provide checksum for any of the above\n */\nconst ENTITY_ID_REGEX = /^(\\d+)(?:\\.(\\d+)\\.([a-fA-F0-9]+))?(?:-([a-z]{5}))?$/;\n\n/**\n * @description The length of an EVM address in bytes.\n */\nconst EVM_ADDRESS_LENGTH = 20;\n\n/**\n * @description The length of the long-zero prefix in bytes.\n */\nconst LONG_ZERO_PREFIX_LENGTH = 12;\n\n/**\n * @description The offset of the entity number in the EVM address.\n */\nconst ENTITY_NUM_OFFSET = 16;\n\n/**\n * This method is called by most entity ID constructors. It's purpose is to\n * deduplicate the constuctors.\n *\n * @param {number | Long | IEntityId} props\n * @param {(number | null | Long)=} realmOrNull\n * @param {(number | null | Long)=} numOrNull\n * @returns {IEntityIdResult}\n */\nexport function constructor(props, realmOrNull, numOrNull) {\n // Make sure either both the second and third parameter are\n // set or not set; we shouldn't have one set, but the other not set.\n //\n //NOSONAR\n if (\n (realmOrNull == null && numOrNull != null) ||\n (realmOrNull != null && numOrNull == null)\n ) {\n throw new Error(\"invalid entity ID\");\n }\n\n // If the first parameter is a number then we need to convert the\n // first, second, and third parameters into numbers. Otherwise,\n // we should look at the fields `shard`, `realm`, and `num` on\n // `props`\n const [shard, realm, num] =\n typeof props === \"number\" || Long.isLong(props)\n ? [\n numOrNull != null\n ? Long.fromValue(/** @type {Long | number} */ (props))\n : Long.ZERO,\n realmOrNull != null ? Long.fromValue(realmOrNull) : Long.ZERO,\n numOrNull != null\n ? Long.fromValue(numOrNull)\n : Long.fromValue(/** @type {Long | number} */ (props)),\n ]\n : [\n props.shard != null ? Long.fromValue(props.shard) : Long.ZERO,\n props.realm != null ? Long.fromValue(props.realm) : Long.ZERO,\n Long.fromValue(props.num),\n ];\n\n // Make sure none of the numbers are negative\n if (shard.isNegative() || realm.isNegative() || num.isNegative()) {\n throw new Error(\"negative numbers are not allowed in IDs\");\n }\n\n return {\n shard,\n realm,\n num,\n };\n}\n\n/**\n * A simple comparison function for comparing entity IDs\n *\n * @param {[Long, Long, Long]} a\n * @param {[Long, Long, Long]} b\n * @returns {number}\n */\nexport function compare(a, b) {\n let comparison = a[0].compare(b[0]);\n if (comparison != 0) {\n return comparison;\n }\n\n comparison = a[1].compare(b[1]);\n if (comparison != 0) {\n return comparison;\n }\n\n return a[2].compare(b[2]);\n}\n\n/**\n * This type is part of the entity ID checksums feature which\n * is responsible for checking if an entity ID was created on\n * the same ledger ID as the client is currently using.\n *\n * @typedef {object} ParseAddressResult\n * @property {number} status\n * @property {Long} [num1]\n * @property {Long} [num2]\n * @property {Long} [num3]\n * @property {string} [correctChecksum]\n * @property {string} [givenChecksum]\n * @property {string} [noChecksumFormat]\n * @property {string} [withChecksumFormat]\n */\n\n/**\n * @param {string} text\n * @returns {IEntityIdParts}\n */\nexport function fromStringSplitter(text) {\n const match = ENTITY_ID_REGEX.exec(text);\n\n if (match == null) {\n throw new Error(`failed to parse entity id: ${text}`);\n }\n\n if (match[2] == null && match[3] == null) {\n return {\n shard: \"0\",\n realm: \"0\",\n numOrHex: match[1],\n checksum: match[4],\n };\n } else {\n return {\n shard: match[1],\n realm: match[2],\n numOrHex: match[3],\n checksum: match[4],\n };\n }\n}\n\n/**\n * @param {string} text\n * @returns {IEntityIdResultWithChecksum}\n */\nexport function fromString(text) {\n const result = fromStringSplitter(text);\n\n if (\n Number.isNaN(result.shard) ||\n Number.isNaN(result.realm) ||\n Number.isNaN(result.numOrHex)\n ) {\n throw new Error(\"invalid format for entity ID\");\n }\n\n return {\n shard: result.shard != null ? Long.fromString(result.shard) : Long.ZERO,\n realm: result.realm != null ? Long.fromString(result.realm) : Long.ZERO,\n num: Long.fromString(result.numOrHex),\n checksum: result.checksum,\n };\n}\n\n/**\n * Return the shard, realm, and num from a solidity address.\n *\n * Solidity addresses are 20 bytes long and hex encoded, where the first 4\n * bytes represent the shard, the next 8 bytes represent the realm, and\n * the last 8 bytes represent the num. All in Big Endian format\n *\n * @param {string} address\n * @returns {[Long, Long, Long]}\n */\nexport function fromSolidityAddress(address) {\n const addr = address.startsWith(\"0x\")\n ? hex.decode(address.slice(2))\n : hex.decode(address);\n\n if (addr.length !== EVM_ADDRESS_LENGTH) {\n throw new Error(`Invalid hex encoded solidity address length:\n expected length 40, got length ${address.length}`);\n }\n\n const shard = Long.fromBytesBE([0, 0, 0, 0, ...addr.slice(0, 4)]);\n const realm = Long.fromBytesBE(Array.from(addr.slice(4, 12)));\n const num = Long.fromBytesBE(Array.from(addr.slice(12, 20)));\n\n return [shard, realm, num];\n}\n\n/**\n * Parse an EVM address and return shard, realm, entity num, and optional EVM address.\n *\n * For long zero addresses (first 12 bytes are zeros): returns [shard, realm, entityNum, null]\n * For regular EVM addresses: returns [shard, realm, 0, EvmAddress]\n *\n * @param {Long | number} shard - The shard number to use\n * @param {Long | number} realm - The realm number to use\n * @param {string} address - The EVM address to parse (with or without 0x prefix)\n * @returns {[Long, Long, Long, EvmAddress | null]} - [shard, realm, entityNum, evmAddressOrNull]\n */\nexport function fromEvmAddress(shard, realm, address) {\n if (!hex.isHexString(address)) {\n throw new Error(`Invalid EVM address hex string: ${address}`);\n }\n\n const addr = address.startsWith(\"0x\")\n ? hex.decode(address.slice(2))\n : hex.decode(address);\n\n if (addr.length !== EVM_ADDRESS_LENGTH) {\n throw new Error(`Invalid hex encoded evm address length:\n expected length ${EVM_ADDRESS_LENGTH}, got length ${address.length}`);\n }\n\n let num = Long.ZERO;\n\n if (util.isLongZeroAddress(addr)) {\n num = Long.fromBytesBE(\n Array.from(addr.slice(LONG_ZERO_PREFIX_LENGTH, EVM_ADDRESS_LENGTH)),\n );\n }\n\n let shardLong = shard instanceof Long ? shard : Long.fromNumber(shard);\n let realmLong = realm instanceof Long ? realm : Long.fromNumber(realm);\n\n return [\n shardLong,\n realmLong,\n num,\n num.isZero() ? EvmAddress.fromBytes(addr) : null,\n ];\n}\n\n/**\n * Convert shard, realm, and num into a solidity address.\n *\n * See `fromSolidityAddress()` for more documentation.\n *\n * @param {[Long,Long,Long] | [number,number,number]} address\n * @returns {string}\n */\nexport function toSolidityAddress(address) {\n const buffer = new Uint8Array(20);\n const view = util.safeView(buffer);\n const [shard, realm, num] = address;\n\n view.setUint32(0, util.convertToNumber(shard));\n view.setUint32(8, util.convertToNumber(realm));\n view.setUint32(16, util.convertToNumber(num));\n\n return hex.encode(buffer);\n}\n\n/**\n * @overload\n * @param {Uint8Array} evmAddressBytes - EVM address bytes to convert to hex\n * @returns {string}\n */\n\n/**\n * @overload\n * @param {Long} accountNum - Account number to convert to long-zero EVM address\n * @returns {string}\n */\n\n/**\n * Convert EVM address bytes to hex string or account num to long-zero EVM address.\n *\n * @param {Uint8Array | Long} evmAddressBytesOrAccountNum\n * @returns {string}\n */\nexport function toEvmAddress(evmAddressBytesOrAccountNum) {\n if (evmAddressBytesOrAccountNum instanceof Uint8Array) {\n return hex.encode(evmAddressBytesOrAccountNum);\n }\n\n const accountNum = evmAddressBytesOrAccountNum;\n const buffer = new Uint8Array(EVM_ADDRESS_LENGTH);\n const view = util.safeView(buffer);\n\n view.setUint32(ENTITY_NUM_OFFSET, util.convertToNumber(accountNum));\n\n return hex.encode(buffer);\n}\n\n/**\n * Parse the address string addr and return an object with the results (8 fields).\n * The first four fields are numbers, which could be implemented as signed 32 bit\n * integers, and the last four are strings.\n *\n * status; //the status of the parsed address\n * // 0 = syntax error\n * // 1 = an invalid with-checksum address (bad checksum)\n * // 2 = a valid no-checksum address\n * // 3 = a valid with-checksum address\n * num1; //the 3 numbers in the address, such as 1.2.3, with leading zeros removed\n * num2;\n * num3;\n * correctchecksum; //the correct checksum\n * givenChecksum; //the checksum in the address that was parsed\n * noChecksumFormat; //the address in no-checksum format\n * withChecksumFormat; //the address in with-checksum format\n *\n * @param {Uint8Array} ledgerId\n * @param {string} addr\n * @returns {ParseAddressResult}\n */\nexport function _parseAddress(ledgerId, addr) {\n let match = regex.exec(addr);\n if (match === null) {\n let result = { status: 0 }; // When status == 0, the rest of the fields should be ignored\n return result;\n }\n let a = [\n Long.fromString(match[1]),\n Long.fromString(match[2]),\n Long.fromString(match[3]),\n ];\n let ad = `${a[0].toString()}.${a[1].toString()}.${a[2].toString()}`;\n let c = _checksum(ledgerId, ad);\n let s = match[4] === undefined ? 2 : c == match[4] ? 3 : 1; //NOSONAR\n return {\n status: s,\n num1: a[0],\n num2: a[1],\n num3: a[2],\n givenChecksum: match[4],\n correctChecksum: c,\n noChecksumFormat: ad,\n withChecksumFormat: `${ad}-${c}`,\n };\n}\n\n/**\n * Given an address like \"0.0.123\", return a checksum like \"laujm\"\n *\n * @param {Uint8Array} ledgerId\n * @param {string} addr\n * @returns {string}\n */\nexport function _checksum(ledgerId, addr) {\n let answer = \"\";\n let d = []; // Digits with 10 for \".\", so if addr == \"0.0.123\" then d == [0, 10, 0, 10, 1, 2, 3]\n let s0 = 0; // Sum of even positions (mod 11)\n let s1 = 0; // Sum of odd positions (mod 11)\n let s = 0; // Weighted sum of all positions (mod p3)\n let sh = 0; // Hash of the ledger ID\n let c = 0; // The checksum, as a single number\n const p3 = 26 * 26 * 26; // 3 digits in base 26\n const p5 = 26 * 26 * 26 * 26 * 26; // 5 digits in base 26\n const ascii_a = \"a\".charCodeAt(0); // 97\n const m = 1000003; // Min prime greater than a million. Used for the final permutation.\n const w = 31; // Sum s of digit values weights them by powers of w. Should be coprime to p5.\n\n let h = new Uint8Array(ledgerId.length + 6);\n h.set(ledgerId, 0);\n h.set([0, 0, 0, 0, 0, 0], ledgerId.length);\n for (let i = 0; i < addr.length; i++) {\n //NOSONAR\n d.push(addr[i] === \".\" ? 10 : parseInt(addr[i], 10));\n }\n for (let i = 0; i < d.length; i++) {\n s = (w * s + d[i]) % p3;\n if (i % 2 === 0) {\n s0 = (s0 + d[i]) % 11;\n } else {\n s1 = (s1 + d[i]) % 11;\n }\n }\n for (let i = 0; i < h.length; i++) {\n sh = (w * sh + h[i]) % p5;\n }\n c = ((((addr.length % 5) * 11 + s0) * 11 + s1) * p3 + s + sh) % p5;\n c = (c * m) % p5;\n\n for (let i = 0; i < 5; i++) {\n answer = String.fromCharCode(ascii_a + (c % 26)) + answer;\n c /= 26;\n }\n\n return answer;\n}\n\n/**\n * Validate an entity ID checksum against a client\n *\n * @param {Long} shard\n * @param {Long} realm\n * @param {Long} num\n * @param {string | null} checksum\n * @param {Client} client\n */\nexport function validateChecksum(shard, realm, num, checksum, client) {\n if (client._network._ledgerId == null || checksum == null) {\n return;\n }\n\n const expectedChecksum = _checksum(\n client._network._ledgerId._ledgerId,\n `${shard.toString()}.${realm.toString()}.${num.toString()}`,\n );\n\n if (checksum != expectedChecksum) {\n throw new BadEntityIdError(\n shard,\n realm,\n num,\n checksum,\n expectedChecksum,\n );\n }\n}\n\n/**\n * Stringify the entity ID with a checksum.\n *\n * @param {string} string\n * @param {Client} client\n * @returns {string}\n */\nexport function toStringWithChecksum(string, client) {\n if (client == null) {\n throw new Error(\"client cannot be null\");\n }\n\n if (client._network._ledgerId == null) {\n throw new Error(\n \"cannot calculate checksum with a client that does not contain a recognzied ledger ID\",\n );\n }\n\n const checksum = _checksum(client._network._ledgerId._ledgerId, string);\n\n return `${string}-${checksum}`;\n}\n\n/**\n * Append Buffers.\n * @param {Uint8Array} buffer1\n * @param {Uint8Array} buffer2\n * @returns {Uint8Array}\n */\nfunction appendBuffer(buffer1, buffer2) {\n var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);\n tmp.set(new Uint8Array(buffer1), 0);\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength);\n return tmp;\n}\n\n/**\n * Convert bytes to hex string.\n * @param {Uint8Array} bytes\n * @returns {string}\n */\nfunction toHexString(bytes) {\n var s = \"0x\";\n bytes.forEach(function (byte) {\n s += (\"0\" + (byte & 0xff).toString(16)).slice(-2);\n });\n return s;\n}\n\n/**\n * Deserialize the alias to public key.\n * Alias is created from ed25519 or ECDSASecp256k1 types of accounts. If hollow account is used, the alias is created from evm address.\n * For hollow accounts, please use aliasToEvmAddress.\n *\n * @param {string} alias\n * @returns {PublicKey | null}\n */\nexport function aliasToPublicKey(alias) {\n const bytes = base32.decode(alias);\n if (!bytes) {\n return null;\n }\n let key;\n try {\n key = HieroProto.proto.Key.decode(bytes);\n } catch (e) {\n throw new Error(\n \"The alias is created with hollow account. Please use aliasToEvmAddress!\",\n );\n }\n\n if (key.ed25519 != null && key.ed25519.byteLength > 0) {\n return PublicKey.fromBytes(key.ed25519);\n }\n\n if (key.ECDSASecp256k1 != null && key.ECDSASecp256k1.byteLength > 0) {\n return PublicKey.fromBytes(key.ECDSASecp256k1);\n }\n\n return null;\n}\n\n/**\n * Deserialize the alias to evm address.\n * Alias is created from hollow account.\n * For ed25519 or ECDSASecp256k1 accounts, please use aliasToPublicKey.\n *\n * @param {string} alias\n * @returns {string | null}\n */\nexport function aliasToEvmAddress(alias) {\n const bytes = base32.decode(alias);\n if (!bytes) {\n return null;\n }\n try {\n HieroProto.proto.Key.decode(bytes);\n throw new Error(\n \"The alias is created with ed25519 or ECDSASecp256k1 account. Please use aliasToPublicKey!\",\n );\n } catch (e) {\n return toHexString(bytes);\n }\n}\n\n/**\n * Serialize the public key to alias.\n * Alias is created from ed25519 or ECDSASecp256k1 types of accounts. If hollow account is used, the alias is created from evm address.\n *\n * @param {string | PublicKey} publicKey\n * @returns {string | null}\n */\nexport function publicKeyToAlias(publicKey) {\n if (\n typeof publicKey === \"string\" &&\n ((publicKey.startsWith(\"0x\") && publicKey.length == 42) ||\n publicKey.length == 40)\n ) {\n if (!publicKey.startsWith(\"0x\")) {\n publicKey = `0x${publicKey}`;\n }\n\n const bytes = arrayify(publicKey);\n if (!bytes) {\n return null;\n }\n return base32.encode(bytes);\n }\n\n const publicKeyRaw =\n typeof publicKey === \"string\"\n ? PublicKey.fromString(publicKey)\n : publicKey;\n let publicKeyHex = publicKeyRaw.toStringRaw();\n let leadingHex = \"\";\n\n if (publicKeyRaw._key._type === \"secp256k1\") {\n leadingHex = \"0x3A21\"; // LEADING BYTES FROM PROTOBUFS\n }\n\n if (publicKeyRaw._key._type === \"ED25519\") {\n leadingHex = \"0x1220\"; // LEADING BYTES FROM PROTOBUFS\n }\n\n if (!publicKeyHex.startsWith(\"0x\")) {\n publicKeyHex = `0x${publicKeyHex}`;\n }\n\n const leadingBytes = arrayify(leadingHex);\n const publicKeyBytes = arrayify(publicKeyHex);\n const publicKeyInBytes = appendBuffer(leadingBytes, publicKeyBytes);\n const alias = base32.encode(publicKeyInBytes);\n return alias;\n}\n"],"names":["regex","ENTITY_ID_REGEX","constructor","props","realmOrNull","numOrNull","Error","shard","realm","num","Long","isLong","fromValue","ZERO","isNegative","compare","a","b","comparison","fromStringSplitter","text","match","exec","numOrHex","checksum","fromString","result","Number","isNaN","fromSolidityAddress","address","addr","startsWith","hex.decode","slice","length","fromBytesBE","Array","from","fromEvmAddress","hex.isHexString","util.isLongZeroAddress","fromNumber","isZero","EvmAddress","fromBytes","toSolidityAddress","buffer","Uint8Array","view","util.safeView","setUint32","util.convertToNumber","hex.encode","toEvmAddress","evmAddressBytesOrAccountNum","accountNum","_parseAddress","ledgerId","status","ad","toString","c","_checksum","undefined","num1","num2","num3","givenChecksum","correctChecksum","noChecksumFormat","withChecksumFormat","answer","d","s0","s1","s","sh","p5","ascii_a","charCodeAt","h","set","i","push","parseInt","String","fromCharCode","validateChecksum","client","_network","_ledgerId","expectedChecksum","BadEntityIdError","toStringWithChecksum","string","aliasToPublicKey","alias","bytes","base32","decode","key","HieroProto","proto","Key","e","ed25519","byteLength","PublicKey","ECDSASecp256k1","aliasToEvmAddress","forEach","byte","toHexString","publicKeyToAlias","publicKey","arrayify","encode","publicKeyRaw","publicKeyHex","toStringRaw","leadingHex","_key","_type","leadingBytes","publicKeyBytes","publicKeyInBytes","buffer1","buffer2","tmp"],"mappings":"gYA8CA,MAAMA,EACF,+EASEC,EAAkB,sDA0BjB,SAASC,EAAYC,EAAOC,EAAaC,GAK5C,GACoB,MAAfD,GAAoC,MAAbC,GACR,MAAfD,GAAoC,MAAbC,EAExB,MAAM,IAAIC,MAAM,qBAOpB,MAAOC,EAAOC,EAAOC,GACA,iBAAVN,GAAsBO,EAAKC,OAAOR,GACnC,CACiB,MAAbE,EACMK,EAAKE,UAAS,GACdF,EAAKG,KACI,MAAfT,EAAsBM,EAAKE,UAAUR,GAAeM,EAAKG,KAC5C,MAAbR,EACMK,EAAKE,UAAUP,GACfK,EAAKE,UAAS,IAExB,CACmB,MAAfT,EAAMI,MAAgBG,EAAKE,UAAUT,EAAMI,OAASG,EAAKG,KAC1C,MAAfV,EAAMK,MAAgBE,EAAKE,UAAUT,EAAMK,OAASE,EAAKG,KACzDH,EAAKE,UAAUT,EAAMM,MAInC,GAAIF,EAAMO,cAAgBN,EAAMM,cAAgBL,EAAIK,aAChD,MAAM,IAAIR,MAAM,2CAGpB,MAAO,CACHC,QACAC,QACAC,MAER,CASO,SAASM,EAAQC,EAAGC,GACvB,IAAIC,EAAaF,EAAE,GAAGD,QAAQE,EAAE,IAChC,OAAkB,GAAdC,EACOA,GAGXA,EAAaF,EAAE,GAAGD,QAAQE,EAAE,IACV,GAAdC,EACOA,EAGJF,EAAE,GAAGD,QAAQE,EAAE,IAC1B,CAsBO,SAASE,EAAmB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EAAUnF,WAAW,OAA6B,IAApBmF,EAAUhF,QAClB,IAApBgF,EAAUhF,QAChB,CACOgF,EAAUnF,WAAW,QACtBmF,EAAY,KAAKA,KAGrB,MAAMjB,EAAQkB,EAASD,GACvB,OAAKjB,EAGEC,EAAOkB,OAAOnB,GAFV,IAGf,CAEA,MAAMoB,EACmB,iBAAdH,EACDP,EAAUnF,WAAW0F,GACrBA,EACV,IAAII,EAAeD,EAAaE,cAC5BC,EAAa,GAEe,cAA5BH,EAAaI,KAAKC,QAClBF,EAAa,UAGe,YAA5BH,EAAaI,KAAKC,QAClBF,EAAa,UAGZF,EAAavF,WAAW,QACzBuF,EAAe,KAAKA,KAGxB,MAAMK,EAAeR,EAASK,GACxBI,EAAiBT,EAASG,GAC1BO,GAzHYC,EAyHoBH,EAzHXI,EAyHyBH,GAxHhDI,EAAM,IAAIjF,WAAW+E,EAAQpB,WAAaqB,EAAQrB,aAClDzB,IAAI,IAAIlC,WAAW+E,GAAU,GACjCE,EAAI/C,IAAI,IAAIlC,WAAWgF,GAAUD,EAAQpB,YAClCsB,GAJX,IAAsBF,EAASC,EACvBC,EA0HJ,OADc9B,EAAOkB,OAAOS,EAEhC"}
1
+ {"version":3,"file":"EntityIdHelper.js","sources":["../src/EntityIdHelper.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Long from \"long\";\nimport * as hex from \"./encoding/hex.js\";\nimport BadEntityIdError from \"./BadEntityIdError.js\";\nimport * as util from \"./util.js\";\nimport base32 from \"./base32.js\";\nimport * as HieroProto from \"@hiero-ledger/proto\";\nimport PublicKey from \"./PublicKey.js\";\nimport { getBytes } from \"ethers\";\nimport EvmAddress from \"./EvmAddress.js\";\n\n/**\n * @typedef {import(\"./client/Client.js\").default<*, *>} Client\n */\n\n/**\n * @typedef {object} IEntityId\n * @property {number | Long} num\n * @property {(number | Long)=} shard\n * @property {(number | Long)=} realm\n */\n\n/**\n * @typedef {object} IEntityIdResult\n * @property {Long} shard\n * @property {Long} realm\n * @property {Long} num\n */\n\n/**\n * @typedef {object} IEntityIdParts\n * @property {string?} shard\n * @property {string?} realm\n * @property {string} numOrHex\n * @property {string?} checksum\n */\n\n/**\n * @typedef {object} IEntityIdResultWithChecksum\n * @property {Long} shard\n * @property {Long} realm\n * @property {Long} num\n * @property {string | null} checksum\n */\n\nconst regex =\n /\"^(0|(?:[1-9]\\\\d*))\\\\.(0|(?:[1-9]\\\\d*))\\\\.(0|(?:[1-9]\\\\d*))(?:-([a-z]{5}))?$/;\n\n/**\n * This regex supports entity IDs\n * - as stand alone nubmers\n * - as shard.realm.num\n * - as shard.realm.hex\n * - can optionally provide checksum for any of the above\n */\nconst ENTITY_ID_REGEX = /^(\\d+)(?:\\.(\\d+)\\.([a-fA-F0-9]+))?(?:-([a-z]{5}))?$/;\n\n/**\n * @description The length of an EVM address in bytes.\n */\nconst EVM_ADDRESS_LENGTH = 20;\n\n/**\n * @description The length of the long-zero prefix in bytes.\n */\nconst LONG_ZERO_PREFIX_LENGTH = 12;\n\n/**\n * @description The offset of the entity number in the EVM address.\n */\nconst ENTITY_NUM_OFFSET = 16;\n\n/**\n * This method is called by most entity ID constructors. It's purpose is to\n * deduplicate the constuctors.\n *\n * @param {number | Long | IEntityId} props\n * @param {(number | null | Long)=} realmOrNull\n * @param {(number | null | Long)=} numOrNull\n * @returns {IEntityIdResult}\n */\nexport function constructor(props, realmOrNull, numOrNull) {\n // Make sure either both the second and third parameter are\n // set or not set; we shouldn't have one set, but the other not set.\n //\n //NOSONAR\n if (\n (realmOrNull == null && numOrNull != null) ||\n (realmOrNull != null && numOrNull == null)\n ) {\n throw new Error(\"invalid entity ID\");\n }\n\n // If the first parameter is a number then we need to convert the\n // first, second, and third parameters into numbers. Otherwise,\n // we should look at the fields `shard`, `realm`, and `num` on\n // `props`\n const [shard, realm, num] =\n typeof props === \"number\" || Long.isLong(props)\n ? [\n numOrNull != null\n ? Long.fromValue(/** @type {Long | number} */ (props))\n : Long.ZERO,\n realmOrNull != null ? Long.fromValue(realmOrNull) : Long.ZERO,\n numOrNull != null\n ? Long.fromValue(numOrNull)\n : Long.fromValue(/** @type {Long | number} */ (props)),\n ]\n : [\n props.shard != null ? Long.fromValue(props.shard) : Long.ZERO,\n props.realm != null ? Long.fromValue(props.realm) : Long.ZERO,\n Long.fromValue(props.num),\n ];\n\n // Make sure none of the numbers are negative\n if (shard.isNegative() || realm.isNegative() || num.isNegative()) {\n throw new Error(\"negative numbers are not allowed in IDs\");\n }\n\n return {\n shard,\n realm,\n num,\n };\n}\n\n/**\n * A simple comparison function for comparing entity IDs\n *\n * @param {[Long, Long, Long]} a\n * @param {[Long, Long, Long]} b\n * @returns {number}\n */\nexport function compare(a, b) {\n let comparison = a[0].compare(b[0]);\n if (comparison != 0) {\n return comparison;\n }\n\n comparison = a[1].compare(b[1]);\n if (comparison != 0) {\n return comparison;\n }\n\n return a[2].compare(b[2]);\n}\n\n/**\n * This type is part of the entity ID checksums feature which\n * is responsible for checking if an entity ID was created on\n * the same ledger ID as the client is currently using.\n *\n * @typedef {object} ParseAddressResult\n * @property {number} status\n * @property {Long} [num1]\n * @property {Long} [num2]\n * @property {Long} [num3]\n * @property {string} [correctChecksum]\n * @property {string} [givenChecksum]\n * @property {string} [noChecksumFormat]\n * @property {string} [withChecksumFormat]\n */\n\n/**\n * @param {string} text\n * @returns {IEntityIdParts}\n */\nexport function fromStringSplitter(text) {\n const match = ENTITY_ID_REGEX.exec(text);\n\n if (match == null) {\n throw new Error(`failed to parse entity id: ${text}`);\n }\n\n if (match[2] == null && match[3] == null) {\n return {\n shard: \"0\",\n realm: \"0\",\n numOrHex: match[1],\n checksum: match[4],\n };\n } else {\n return {\n shard: match[1],\n realm: match[2],\n numOrHex: match[3],\n checksum: match[4],\n };\n }\n}\n\n/**\n * @param {string} text\n * @returns {IEntityIdResultWithChecksum}\n */\nexport function fromString(text) {\n const result = fromStringSplitter(text);\n\n if (\n Number.isNaN(result.shard) ||\n Number.isNaN(result.realm) ||\n Number.isNaN(result.numOrHex)\n ) {\n throw new Error(\"invalid format for entity ID\");\n }\n\n return {\n shard: result.shard != null ? Long.fromString(result.shard) : Long.ZERO,\n realm: result.realm != null ? Long.fromString(result.realm) : Long.ZERO,\n num: Long.fromString(result.numOrHex),\n checksum: result.checksum,\n };\n}\n\n/**\n * Return the shard, realm, and num from a solidity address.\n *\n * Solidity addresses are 20 bytes long and hex encoded, where the first 4\n * bytes represent the shard, the next 8 bytes represent the realm, and\n * the last 8 bytes represent the num. All in Big Endian format\n *\n * @param {string} address\n * @returns {[Long, Long, Long]}\n */\nexport function fromSolidityAddress(address) {\n const addr = address.startsWith(\"0x\")\n ? hex.decode(address.slice(2))\n : hex.decode(address);\n\n if (addr.length !== EVM_ADDRESS_LENGTH) {\n throw new Error(`Invalid hex encoded solidity address length:\n expected length 40, got length ${address.length}`);\n }\n\n const shard = Long.fromBytesBE([0, 0, 0, 0, ...addr.slice(0, 4)]);\n const realm = Long.fromBytesBE(Array.from(addr.slice(4, 12)));\n const num = Long.fromBytesBE(Array.from(addr.slice(12, 20)));\n\n return [shard, realm, num];\n}\n\n/**\n * Parse an EVM address and return shard, realm, entity num, and optional EVM address.\n *\n * For long zero addresses (first 12 bytes are zeros): returns [shard, realm, entityNum, null]\n * For regular EVM addresses: returns [shard, realm, 0, EvmAddress]\n *\n * @param {Long | number} shard - The shard number to use\n * @param {Long | number} realm - The realm number to use\n * @param {string} address - The EVM address to parse (with or without 0x prefix)\n * @returns {[Long, Long, Long, EvmAddress | null]} - [shard, realm, entityNum, evmAddressOrNull]\n */\nexport function fromEvmAddress(shard, realm, address) {\n if (!hex.isHexString(address)) {\n throw new Error(`Invalid EVM address hex string: ${address}`);\n }\n\n const addr = address.startsWith(\"0x\")\n ? hex.decode(address.slice(2))\n : hex.decode(address);\n\n if (addr.length !== EVM_ADDRESS_LENGTH) {\n throw new Error(`Invalid hex encoded evm address length:\n expected length ${EVM_ADDRESS_LENGTH}, got length ${address.length}`);\n }\n\n let num = Long.ZERO;\n\n if (util.isLongZeroAddress(addr)) {\n num = Long.fromBytesBE(\n Array.from(addr.slice(LONG_ZERO_PREFIX_LENGTH, EVM_ADDRESS_LENGTH)),\n );\n }\n\n let shardLong = shard instanceof Long ? shard : Long.fromNumber(shard);\n let realmLong = realm instanceof Long ? realm : Long.fromNumber(realm);\n\n return [\n shardLong,\n realmLong,\n num,\n num.isZero() ? EvmAddress.fromBytes(addr) : null,\n ];\n}\n\n/**\n * Convert shard, realm, and num into a solidity address.\n *\n * See `fromSolidityAddress()` for more documentation.\n *\n * @param {[Long,Long,Long] | [number,number,number]} address\n * @returns {string}\n */\nexport function toSolidityAddress(address) {\n const buffer = new Uint8Array(20);\n const view = util.safeView(buffer);\n const [shard, realm, num] = address;\n\n view.setUint32(0, util.convertToNumber(shard));\n view.setUint32(8, util.convertToNumber(realm));\n view.setUint32(16, util.convertToNumber(num));\n\n return hex.encode(buffer);\n}\n\n/**\n * @overload\n * @param {Uint8Array} evmAddressBytes - EVM address bytes to convert to hex\n * @returns {string}\n */\n\n/**\n * @overload\n * @param {Long} accountNum - Account number to convert to long-zero EVM address\n * @returns {string}\n */\n\n/**\n * Convert EVM address bytes to hex string or account num to long-zero EVM address.\n *\n * @param {Uint8Array | Long} evmAddressBytesOrAccountNum\n * @returns {string}\n */\nexport function toEvmAddress(evmAddressBytesOrAccountNum) {\n if (evmAddressBytesOrAccountNum instanceof Uint8Array) {\n return hex.encode(evmAddressBytesOrAccountNum);\n }\n\n const accountNum = evmAddressBytesOrAccountNum;\n const buffer = new Uint8Array(EVM_ADDRESS_LENGTH);\n const view = util.safeView(buffer);\n\n view.setUint32(ENTITY_NUM_OFFSET, util.convertToNumber(accountNum));\n\n return hex.encode(buffer);\n}\n\n/**\n * Parse the address string addr and return an object with the results (8 fields).\n * The first four fields are numbers, which could be implemented as signed 32 bit\n * integers, and the last four are strings.\n *\n * status; //the status of the parsed address\n * // 0 = syntax error\n * // 1 = an invalid with-checksum address (bad checksum)\n * // 2 = a valid no-checksum address\n * // 3 = a valid with-checksum address\n * num1; //the 3 numbers in the address, such as 1.2.3, with leading zeros removed\n * num2;\n * num3;\n * correctchecksum; //the correct checksum\n * givenChecksum; //the checksum in the address that was parsed\n * noChecksumFormat; //the address in no-checksum format\n * withChecksumFormat; //the address in with-checksum format\n *\n * @param {Uint8Array} ledgerId\n * @param {string} addr\n * @returns {ParseAddressResult}\n */\nexport function _parseAddress(ledgerId, addr) {\n let match = regex.exec(addr);\n if (match === null) {\n let result = { status: 0 }; // When status == 0, the rest of the fields should be ignored\n return result;\n }\n let a = [\n Long.fromString(match[1]),\n Long.fromString(match[2]),\n Long.fromString(match[3]),\n ];\n let ad = `${a[0].toString()}.${a[1].toString()}.${a[2].toString()}`;\n let c = _checksum(ledgerId, ad);\n let s = match[4] === undefined ? 2 : c == match[4] ? 3 : 1; //NOSONAR\n return {\n status: s,\n num1: a[0],\n num2: a[1],\n num3: a[2],\n givenChecksum: match[4],\n correctChecksum: c,\n noChecksumFormat: ad,\n withChecksumFormat: `${ad}-${c}`,\n };\n}\n\n/**\n * Given an address like \"0.0.123\", return a checksum like \"laujm\"\n *\n * @param {Uint8Array} ledgerId\n * @param {string} addr\n * @returns {string}\n */\nexport function _checksum(ledgerId, addr) {\n let answer = \"\";\n let d = []; // Digits with 10 for \".\", so if addr == \"0.0.123\" then d == [0, 10, 0, 10, 1, 2, 3]\n let s0 = 0; // Sum of even positions (mod 11)\n let s1 = 0; // Sum of odd positions (mod 11)\n let s = 0; // Weighted sum of all positions (mod p3)\n let sh = 0; // Hash of the ledger ID\n let c = 0; // The checksum, as a single number\n const p3 = 26 * 26 * 26; // 3 digits in base 26\n const p5 = 26 * 26 * 26 * 26 * 26; // 5 digits in base 26\n const ascii_a = \"a\".charCodeAt(0); // 97\n const m = 1000003; // Min prime greater than a million. Used for the final permutation.\n const w = 31; // Sum s of digit values weights them by powers of w. Should be coprime to p5.\n\n let h = new Uint8Array(ledgerId.length + 6);\n h.set(ledgerId, 0);\n h.set([0, 0, 0, 0, 0, 0], ledgerId.length);\n for (let i = 0; i < addr.length; i++) {\n //NOSONAR\n d.push(addr[i] === \".\" ? 10 : parseInt(addr[i], 10));\n }\n for (let i = 0; i < d.length; i++) {\n s = (w * s + d[i]) % p3;\n if (i % 2 === 0) {\n s0 = (s0 + d[i]) % 11;\n } else {\n s1 = (s1 + d[i]) % 11;\n }\n }\n for (let i = 0; i < h.length; i++) {\n sh = (w * sh + h[i]) % p5;\n }\n c = ((((addr.length % 5) * 11 + s0) * 11 + s1) * p3 + s + sh) % p5;\n c = (c * m) % p5;\n\n for (let i = 0; i < 5; i++) {\n answer = String.fromCharCode(ascii_a + (c % 26)) + answer;\n c /= 26;\n }\n\n return answer;\n}\n\n/**\n * Validate an entity ID checksum against a client\n *\n * @param {Long} shard\n * @param {Long} realm\n * @param {Long} num\n * @param {string | null} checksum\n * @param {Client} client\n */\nexport function validateChecksum(shard, realm, num, checksum, client) {\n if (client._network._ledgerId == null || checksum == null) {\n return;\n }\n\n const expectedChecksum = _checksum(\n client._network._ledgerId._ledgerId,\n `${shard.toString()}.${realm.toString()}.${num.toString()}`,\n );\n\n if (checksum != expectedChecksum) {\n throw new BadEntityIdError(\n shard,\n realm,\n num,\n checksum,\n expectedChecksum,\n );\n }\n}\n\n/**\n * Stringify the entity ID with a checksum.\n *\n * @param {string} string\n * @param {Client} client\n * @returns {string}\n */\nexport function toStringWithChecksum(string, client) {\n if (client == null) {\n throw new Error(\"client cannot be null\");\n }\n\n if (client._network._ledgerId == null) {\n throw new Error(\n \"cannot calculate checksum with a client that does not contain a recognzied ledger ID\",\n );\n }\n\n const checksum = _checksum(client._network._ledgerId._ledgerId, string);\n\n return `${string}-${checksum}`;\n}\n\n/**\n * Append Buffers.\n * @param {Uint8Array} buffer1\n * @param {Uint8Array} buffer2\n * @returns {Uint8Array}\n */\nfunction appendBuffer(buffer1, buffer2) {\n var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);\n tmp.set(new Uint8Array(buffer1), 0);\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength);\n return tmp;\n}\n\n/**\n * Convert bytes to hex string.\n * @param {Uint8Array} bytes\n * @returns {string}\n */\nfunction toHexString(bytes) {\n var s = \"0x\";\n bytes.forEach(function (byte) {\n s += (\"0\" + (byte & 0xff).toString(16)).slice(-2);\n });\n return s;\n}\n\n/**\n * Deserialize the alias to public key.\n * Alias is created from ed25519 or ECDSASecp256k1 types of accounts. If hollow account is used, the alias is created from evm address.\n * For hollow accounts, please use aliasToEvmAddress.\n *\n * @param {string} alias\n * @returns {PublicKey | null}\n */\nexport function aliasToPublicKey(alias) {\n const bytes = base32.decode(alias);\n if (!bytes) {\n return null;\n }\n let key;\n try {\n key = HieroProto.proto.Key.decode(bytes);\n } catch (e) {\n throw new Error(\n \"The alias is created with hollow account. Please use aliasToEvmAddress!\",\n );\n }\n\n if (key.ed25519 != null && key.ed25519.byteLength > 0) {\n return PublicKey.fromBytes(key.ed25519);\n }\n\n if (key.ECDSASecp256k1 != null && key.ECDSASecp256k1.byteLength > 0) {\n return PublicKey.fromBytes(key.ECDSASecp256k1);\n }\n\n return null;\n}\n\n/**\n * Deserialize the alias to evm address.\n * Alias is created from hollow account.\n * For ed25519 or ECDSASecp256k1 accounts, please use aliasToPublicKey.\n *\n * @param {string} alias\n * @returns {string | null}\n */\nexport function aliasToEvmAddress(alias) {\n const bytes = base32.decode(alias);\n if (!bytes) {\n return null;\n }\n try {\n HieroProto.proto.Key.decode(bytes);\n throw new Error(\n \"The alias is created with ed25519 or ECDSASecp256k1 account. Please use aliasToPublicKey!\",\n );\n } catch (e) {\n return toHexString(bytes);\n }\n}\n\n/**\n * Serialize the public key to alias.\n * Alias is created from ed25519 or ECDSASecp256k1 types of accounts. If hollow account is used, the alias is created from evm address.\n *\n * @param {string | PublicKey} publicKey\n * @returns {string | null}\n */\nexport function publicKeyToAlias(publicKey) {\n if (\n typeof publicKey === \"string\" &&\n ((publicKey.startsWith(\"0x\") && publicKey.length == 42) ||\n publicKey.length == 40)\n ) {\n if (!publicKey.startsWith(\"0x\")) {\n publicKey = `0x${publicKey}`;\n }\n\n const bytes = getBytes(publicKey);\n if (!bytes) {\n return null;\n }\n return base32.encode(bytes);\n }\n\n const publicKeyRaw =\n typeof publicKey === \"string\"\n ? PublicKey.fromString(publicKey)\n : publicKey;\n let publicKeyHex = publicKeyRaw.toStringRaw();\n let leadingHex = \"\";\n\n if (publicKeyRaw._key._type === \"secp256k1\") {\n leadingHex = \"0x3A21\"; // LEADING BYTES FROM PROTOBUFS\n }\n\n if (publicKeyRaw._key._type === \"ED25519\") {\n leadingHex = \"0x1220\"; // LEADING BYTES FROM PROTOBUFS\n }\n\n if (!publicKeyHex.startsWith(\"0x\")) {\n publicKeyHex = `0x${publicKeyHex}`;\n }\n\n const leadingBytes = getBytes(leadingHex);\n const publicKeyBytes = getBytes(publicKeyHex);\n const publicKeyInBytes = appendBuffer(leadingBytes, publicKeyBytes);\n const alias = base32.encode(publicKeyInBytes);\n return alias;\n}\n"],"names":["regex","ENTITY_ID_REGEX","constructor","props","realmOrNull","numOrNull","Error","shard","realm","num","Long","isLong","fromValue","ZERO","isNegative","compare","a","b","comparison","fromStringSplitter","text","match","exec","numOrHex","checksum","fromString","result","Number","isNaN","fromSolidityAddress","address","addr","startsWith","hex.decode","slice","length","fromBytesBE","Array","from","fromEvmAddress","hex.isHexString","util.isLongZeroAddress","fromNumber","isZero","EvmAddress","fromBytes","toSolidityAddress","buffer","Uint8Array","view","util.safeView","setUint32","util.convertToNumber","hex.encode","toEvmAddress","evmAddressBytesOrAccountNum","accountNum","_parseAddress","ledgerId","status","ad","toString","c","_checksum","undefined","num1","num2","num3","givenChecksum","correctChecksum","noChecksumFormat","withChecksumFormat","answer","d","s0","s1","s","sh","p5","ascii_a","charCodeAt","h","set","i","push","parseInt","String","fromCharCode","validateChecksum","client","_network","_ledgerId","expectedChecksum","BadEntityIdError","toStringWithChecksum","string","aliasToPublicKey","alias","bytes","base32","decode","key","HieroProto","proto","Key","e","ed25519","byteLength","PublicKey","ECDSASecp256k1","aliasToEvmAddress","forEach","byte","toHexString","publicKeyToAlias","publicKey","getBytes","encode","publicKeyRaw","publicKeyHex","toStringRaw","leadingHex","_key","_type","leadingBytes","publicKeyBytes","publicKeyInBytes","buffer1","buffer2","tmp"],"mappings":"kXA8CA,MAAMA,EACF,+EASEC,EAAkB,sDA0BjB,SAASC,EAAYC,EAAOC,EAAaC,GAK5C,GACoB,MAAfD,GAAoC,MAAbC,GACR,MAAfD,GAAoC,MAAbC,EAExB,MAAM,IAAIC,MAAM,qBAOpB,MAAOC,EAAOC,EAAOC,GACA,iBAAVN,GAAsBO,EAAKC,OAAOR,GACnC,CACiB,MAAbE,EACMK,EAAKE,UAAS,GACdF,EAAKG,KACI,MAAfT,EAAsBM,EAAKE,UAAUR,GAAeM,EAAKG,KAC5C,MAAbR,EACMK,EAAKE,UAAUP,GACfK,EAAKE,UAAS,IAExB,CACmB,MAAfT,EAAMI,MAAgBG,EAAKE,UAAUT,EAAMI,OAASG,EAAKG,KAC1C,MAAfV,EAAMK,MAAgBE,EAAKE,UAAUT,EAAMK,OAASE,EAAKG,KACzDH,EAAKE,UAAUT,EAAMM,MAInC,GAAIF,EAAMO,cAAgBN,EAAMM,cAAgBL,EAAIK,aAChD,MAAM,IAAIR,MAAM,2CAGpB,MAAO,CACHC,QACAC,QACAC,MAER,CASO,SAASM,EAAQC,EAAGC,GACvB,IAAIC,EAAaF,EAAE,GAAGD,QAAQE,EAAE,IAChC,OAAkB,GAAdC,EACOA,GAGXA,EAAaF,EAAE,GAAGD,QAAQE,EAAE,IACV,GAAdC,EACOA,EAGJF,EAAE,GAAGD,QAAQE,EAAE,IAC1B,CAsBO,SAASE,EAAmBC,GAC/B,MAAMC,EAAQpB,EAAgBqB,KAAKF,GAEnC,GAAa,MAATC,EACA,MAAM,IAAIf,MAAM,8BAA8Bc,KAGlD,OAAgB,MAAZC,EAAM,IAA0B,MAAZA,EAAM,GACnB,CACHd,MA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EC,EAAOkB,OAAOnB,GAFV,IAGf,CAEA,MAAMoB,EACmB,iBAAdH,EACDP,EAAUnF,WAAW0F,GACrBA,EACV,IAAII,EAAeD,EAAaE,cAC5BC,EAAa,GAEe,cAA5BH,EAAaI,KAAKC,QAClBF,EAAa,UAGe,YAA5BH,EAAaI,KAAKC,QAClBF,EAAa,UAGZF,EAAavF,WAAW,QACzBuF,EAAe,KAAKA,KAGxB,MAAMK,EAAeR,EAASK,GACxBI,EAAiBT,EAASG,GAC1BO,GAzHYC,EAyHoBH,EAzHXI,EAyHyBH,GAxHhDI,EAAM,IAAIjF,WAAW+E,EAAQpB,WAAaqB,EAAQrB,aAClDzB,IAAI,IAAIlC,WAAW+E,GAAU,GACjCE,EAAI/C,IAAI,IAAIlC,WAAWgF,GAAUD,EAAQpB,YAClCsB,GAJX,IAAsBF,EAASC,EACvBC,EA0HJ,OADc9B,EAAOkB,OAAOS,EAEhC"}
@@ -34,7 +34,7 @@ export default class EthereumFlow {
34
34
  constructor(props?: {
35
35
  ethereumData?: Uint8Array<ArrayBufferLike> | undefined;
36
36
  callData?: import("./file/FileId.js").default | undefined;
37
- maxGasAllowance?: string | number | import("long") | import("bignumber.js").BigNumber | Hbar | undefined;
37
+ maxGasAllowance?: string | number | import("long") | import("bignumber.js") | Hbar | undefined;
38
38
  });
39
39
  /**
40
40
  * @private
@@ -120,7 +120,7 @@ export namespace HieroProto {
120
120
  type IAccountID = import("@hiero-ledger/proto").proto.IAccountID;
121
121
  }
122
122
  }
123
- export type BigNumber = import("bignumber.js").default;
123
+ export type BigNumber = import("bignumber.js");
124
124
  export type AccountId = import("./account/AccountId.js").default;
125
125
  export type FileId = import("./file/FileId.js").default;
126
126
  export type Channel = import("./channel/Channel.js").default;
@@ -42,7 +42,7 @@ export default class EthereumTransaction extends Transaction {
42
42
  ethereumData?: Uint8Array<ArrayBufferLike> | undefined;
43
43
  callData?: FileId | undefined;
44
44
  callDataFileId?: FileId | undefined;
45
- maxGasAllowance?: string | number | import("long") | import("bignumber.js").BigNumber | Hbar | undefined;
45
+ maxGasAllowance?: string | number | import("long") | import("bignumber.js") | Hbar | undefined;
46
46
  });
47
47
  /**
48
48
  * @private
@@ -153,7 +153,7 @@ export namespace HieroProto {
153
153
  type IAccountID = import("@hiero-ledger/proto").proto.IAccountID;
154
154
  }
155
155
  }
156
- export type BigNumber = import("bignumber.js").default;
156
+ export type BigNumber = import("bignumber.js");
157
157
  export type AccountId = import("./account/AccountId.js").default;
158
158
  export type Channel = import("./channel/Channel.js").default;
159
159
  export type Client = import("./client/Client.js").default<any, any>;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var rlp = _interopRequireWildcard(require("@ethersproject/rlp"));
7
+ var _ethers = require("ethers");
8
8
  var hex = _interopRequireWildcard(require("./encoding/hex.cjs"));
9
9
  var _EthereumTransactionData = _interopRequireDefault(require("./EthereumTransactionData.cjs"));
10
10
  var _Cache = _interopRequireDefault(require("./Cache.cjs"));
@@ -68,7 +68,7 @@ class EthereumTransactionDataEip1559 extends _EthereumTransactionData.default {
68
68
  }
69
69
 
70
70
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
71
- const decoded = /** @type {string[]} */rlp.decode(bytes.subarray(1));
71
+ const decoded = /** @type {string[]} */(0, _ethers.decodeRlp)(bytes.subarray(1));
72
72
  if (!Array.isArray(decoded)) {
73
73
  throw new Error("ethereum data is not a list");
74
74
  }
@@ -98,7 +98,7 @@ class EthereumTransactionDataEip1559 extends _EthereumTransactionData.default {
98
98
  * @returns {Uint8Array}
99
99
  */
100
100
  toBytes() {
101
- const encoded = rlp.encode([this.chainId, this.nonce, this.maxPriorityGas, this.maxGas, this.gasLimit, this.to, this.value, this.callData, this.accessList, this.recId, this.r, this.s]);
101
+ const encoded = (0, _ethers.encodeRlp)([this.chainId, this.nonce, this.maxPriorityGas, this.maxGas, this.gasLimit, this.to, this.value, this.callData, this.accessList, this.recId, this.r, this.s]);
102
102
  return hex.decode("02" + encoded.substring(2));
103
103
  }
104
104
 
@@ -1,2 +1,2 @@
1
- import*as t from"@ethersproject/rlp";import{decode as s,encode as i}from"./encoding/hex.js";import a from"./EthereumTransactionData.js";import r from"./Cache.js";class e extends a{constructor(t){super(t),this.chainId=t.chainId,this.nonce=t.nonce,this.maxPriorityGas=t.maxPriorityGas,this.maxGas=t.maxGas,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.accessList=t.accessList,this.recId=t.recId,this.r=t.r,this.s=t.s}static fromBytes(i){if(0===i.length)throw new Error("empty bytes");const a=t.decode(i.subarray(1));if(!Array.isArray(a))throw new Error("ethereum data is not a list");if(12!=a.length)throw new Error("invalid ethereum transaction data");return new e({chainId:s(a[0]),nonce:s(a[1]),maxPriorityGas:s(a[2]),maxGas:s(a[3]),gasLimit:s(a[4]),to:s(a[5]),value:s(a[6]),callData:s(a[7]),accessList:a[8].map(t=>s(t)),recId:s(a[9]),r:s(a[10]),s:s(a[11])})}toBytes(){const i=t.encode([this.chainId,this.nonce,this.maxPriorityGas,this.maxGas,this.gasLimit,this.to,this.value,this.callData,this.accessList,this.recId,this.r,this.s]);return s("02"+i.substring(2))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{chainId:i(this.chainId),nonce:i(this.nonce),maxPriorityGas:i(this.maxPriorityGas),maxGas:i(this.maxGas),gasLimit:i(this.gasLimit),to:i(this.to),value:i(this.value),callData:i(this.callData),accessList:this.accessList.map(t=>i(t)),recId:i(this.recId),r:i(this.r),s:i(this.s)}}}r.setEthereumTransactionDataEip1559FromBytes(t=>e.fromBytes(t));export{e as default};
1
+ import{decodeRlp as t,encodeRlp as s}from"ethers";import{decode as i,encode as a}from"./encoding/hex.js";import r from"./EthereumTransactionData.js";import e from"./Cache.js";class h extends r{constructor(t){super(t),this.chainId=t.chainId,this.nonce=t.nonce,this.maxPriorityGas=t.maxPriorityGas,this.maxGas=t.maxGas,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.accessList=t.accessList,this.recId=t.recId,this.r=t.r,this.s=t.s}static fromBytes(s){if(0===s.length)throw new Error("empty bytes");const a=t(s.subarray(1));if(!Array.isArray(a))throw new Error("ethereum data is not a list");if(12!=a.length)throw new Error("invalid ethereum transaction data");return new h({chainId:i(a[0]),nonce:i(a[1]),maxPriorityGas:i(a[2]),maxGas:i(a[3]),gasLimit:i(a[4]),to:i(a[5]),value:i(a[6]),callData:i(a[7]),accessList:a[8].map(t=>i(t)),recId:i(a[9]),r:i(a[10]),s:i(a[11])})}toBytes(){const t=s([this.chainId,this.nonce,this.maxPriorityGas,this.maxGas,this.gasLimit,this.to,this.value,this.callData,this.accessList,this.recId,this.r,this.s]);return i("02"+t.substring(2))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{chainId:a(this.chainId),nonce:a(this.nonce),maxPriorityGas:a(this.maxPriorityGas),maxGas:a(this.maxGas),gasLimit:a(this.gasLimit),to:a(this.to),value:a(this.value),callData:a(this.callData),accessList:this.accessList.map(t=>a(t)),recId:a(this.recId),r:a(this.r),s:a(this.s)}}}e.setEthereumTransactionDataEip1559FromBytes(t=>h.fromBytes(t));export{h as default};
2
2
  //# sourceMappingURL=EthereumTransactionDataEip1559.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumTransactionDataEip1559.js","sources":["../src/EthereumTransactionDataEip1559.js"],"sourcesContent":["import * as rlp from \"@ethersproject/rlp\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataEip1559JSON\n * @property {string} chainId\n * @property {string} nonce\n * @property {string} maxPriorityGas\n * @property {string} maxGas\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {string[]} accessList\n * @property {string} recId\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataEip1559 extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.chainId\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.maxPriorityGas\n * @param {Uint8Array} props.maxGas\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Uint8Array[]} props.accessList\n * @param {Uint8Array} props.recId\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.chainId = props.chainId;\n this.nonce = props.nonce;\n this.maxPriorityGas = props.maxPriorityGas;\n this.maxGas = props.maxGas;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.accessList = props.accessList;\n this.recId = props.recId;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (rlp.decode(bytes.subarray(1)));\n\n if (!Array.isArray(decoded)) {\n throw new Error(\"ethereum data is not a list\");\n }\n\n if (decoded.length != 12) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n // TODO\n return new EthereumTransactionDataEip1559({\n chainId: hex.decode(/** @type {string} */ (decoded[0])),\n nonce: hex.decode(/** @type {string} */ (decoded[1])),\n maxPriorityGas: hex.decode(/** @type {string} */ (decoded[2])),\n maxGas: hex.decode(/** @type {string} */ (decoded[3])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[4])),\n to: hex.decode(/** @type {string} */ (decoded[5])),\n value: hex.decode(/** @type {string} */ (decoded[6])),\n callData: hex.decode(/** @type {string} */ (decoded[7])),\n // @ts-ignore\n accessList: /** @type {string[]} */ (decoded[8]).map((v) =>\n hex.decode(v),\n ),\n recId: hex.decode(/** @type {string} */ (decoded[9])),\n r: hex.decode(/** @type {string} */ (decoded[10])),\n s: hex.decode(/** @type {string} */ (decoded[11])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n const encoded = rlp.encode([\n this.chainId,\n this.nonce,\n this.maxPriorityGas,\n this.maxGas,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.accessList,\n this.recId,\n this.r,\n this.s,\n ]);\n return hex.decode(\"02\" + encoded.substring(2));\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataEip1559JSON}\n */\n toJSON() {\n return {\n chainId: hex.encode(this.chainId),\n nonce: hex.encode(this.nonce),\n maxPriorityGas: hex.encode(this.maxPriorityGas),\n maxGas: hex.encode(this.maxGas),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n accessList: this.accessList.map((v) => hex.encode(v)),\n recId: hex.encode(this.recId),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataEip1559FromBytes((bytes) =>\n EthereumTransactionDataEip1559.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataEip1559","EthereumTransactionData","constructor","props","super","this","chainId","nonce","maxPriorityGas","maxGas","gasLimit","to","value","accessList","recId","r","s","fromBytes","bytes","length","Error","decoded","rlp","decode","subarray","Array","isArray","hex.decode","callData","map","v","toBytes","encoded","encode","substring","toString","JSON","stringify","toJSON","hex.encode","CACHE","setEthereumTransactionDataEip1559FromBytes"],"mappings":"kKAqBe,MAAMA,UAAuCC,EAiBxD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,QAAUH,EAAMG,QACrBD,KAAKE,MAAQJ,EAAMI,MACnBF,KAAKG,eAAiBL,EAAMK,eAC5BH,KAAKI,OAASN,EAAMM,OACpBJ,KAAKK,SAAWP,EAAMO,SACtBL,KAAKM,GAAKR,EAAMQ,GAChBN,KAAKO,MAAQT,EAA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AKG,gBAChCC,OAAQ8B,EAAWlC,KAAKI,QACxBC,SAAU6B,EAAWlC,KAAKK,UAC1BC,GAAI4B,EAAWlC,KAAKM,IACpBC,MAAO2B,EAAWlC,KAAKO,OACvBgB,SAAUW,EAAWlC,KAAKuB,UAC1Bf,WAAYR,KAAKQ,WAAWgB,IAAKC,GAAMS,EAAWT,IAClDhB,MAAOyB,EAAWlC,KAAKS,OACvBC,EAAGwB,EAAWlC,KAAKU,GACnBC,EAAGuB,EAAWlC,KAAKW,GAE3B,EAGJwB,EAAMC,2CAA4CvB,GAC9ClB,EAA+BiB,UAAUC"}
1
+ {"version":3,"file":"EthereumTransactionDataEip1559.js","sources":["../src/EthereumTransactionDataEip1559.js"],"sourcesContent":["import { decodeRlp, encodeRlp } from \"ethers\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataEip1559JSON\n * @property {string} chainId\n * @property {string} nonce\n * @property {string} maxPriorityGas\n * @property {string} maxGas\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {string[]} accessList\n * @property {string} recId\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataEip1559 extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.chainId\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.maxPriorityGas\n * @param {Uint8Array} props.maxGas\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Uint8Array[]} props.accessList\n * @param {Uint8Array} props.recId\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.chainId = props.chainId;\n this.nonce = props.nonce;\n this.maxPriorityGas = props.maxPriorityGas;\n this.maxGas = props.maxGas;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.accessList = props.accessList;\n this.recId = props.recId;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (decodeRlp(bytes.subarray(1)));\n\n if (!Array.isArray(decoded)) {\n throw new Error(\"ethereum data is not a list\");\n }\n\n if (decoded.length != 12) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n // TODO\n return new EthereumTransactionDataEip1559({\n chainId: hex.decode(/** @type {string} */ (decoded[0])),\n nonce: hex.decode(/** @type {string} */ (decoded[1])),\n maxPriorityGas: hex.decode(/** @type {string} */ (decoded[2])),\n maxGas: hex.decode(/** @type {string} */ (decoded[3])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[4])),\n to: hex.decode(/** @type {string} */ (decoded[5])),\n value: hex.decode(/** @type {string} */ (decoded[6])),\n callData: hex.decode(/** @type {string} */ (decoded[7])),\n // @ts-ignore\n accessList: /** @type {string[]} */ (decoded[8]).map((v) =>\n hex.decode(v),\n ),\n recId: hex.decode(/** @type {string} */ (decoded[9])),\n r: hex.decode(/** @type {string} */ (decoded[10])),\n s: hex.decode(/** @type {string} */ (decoded[11])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n const encoded = encodeRlp([\n this.chainId,\n this.nonce,\n this.maxPriorityGas,\n this.maxGas,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.accessList,\n this.recId,\n this.r,\n this.s,\n ]);\n return hex.decode(\"02\" + encoded.substring(2));\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataEip1559JSON}\n */\n toJSON() {\n return {\n chainId: hex.encode(this.chainId),\n nonce: hex.encode(this.nonce),\n maxPriorityGas: hex.encode(this.maxPriorityGas),\n maxGas: hex.encode(this.maxGas),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n accessList: this.accessList.map((v) => hex.encode(v)),\n recId: hex.encode(this.recId),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataEip1559FromBytes((bytes) =>\n EthereumTransactionDataEip1559.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataEip1559","EthereumTransactionData","constructor","props","super","this","chainId","nonce","maxPriorityGas","maxGas","gasLimit","to","value","accessList","recId","r","s","fromBytes","bytes","length","Error","decoded","decodeRlp","subarray","Array","isArray","hex.decode","callData","map","v","toBytes","encoded","encodeRlp","substring","toString","JSON","stringify","toJSON","hex.encode","CACHE","setEthereumTransactionDataEip1559FromBytes"],"mappings":"+KAqBe,MAAMA,UAAuCC,EAiBxD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,QAAUH,EAAMG,QACrBD,KAAKE,MAAQJ,EAAMI,MACnBF,KAAKG,eAAiBL,EAAMK,eAC5BH,KAAKI,OAASN,EAAMM,OACpBJ,KAAKK,SAAWP,EAAMO,SACtBL,KAAKM,GAAKR,EAAMQ,GAChBN,KAAKO,MAAQT,EAAMS,MACnBP,KAAKQ,WAAaV,EAAMU,WACxBR,KAAKS,MAAQX,EAAMW,MACnBT,KAAKU,EAAIZ,EAAMY,EACfV,KAAKW,EAAIb,EAAMa,CACnB,CAMA,gBAAOC,CAAUC,GACb,GAAqB,IAAjBA,EAAMC,OACN,MAAM,IAAIC,MAAM,eAIpB,MAAMC,EAAmCC,EAAUJ,EAAMK,SAAS,IAElE,IAAKC,MAAMC,QAAQJ,GACf,MAAM,IAAID,MAAM,+BAGpB,GAAsB,IAAlBC,EAAQF,OACR,MAAM,IAAIC,MAAM,qCAIpB,OAAO,IAAIpB,EAA+B,CACtCM,QAASoB,EAAkCL,EAAQ,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5
5
  });
6
6
  exports.default = void 0;
7
- var rlp = _interopRequireWildcard(require("@ethersproject/rlp"));
7
+ var _ethers = require("ethers");
8
8
  var hex = _interopRequireWildcard(require("./encoding/hex.cjs"));
9
9
  var _EthereumTransactionData = _interopRequireDefault(require("./EthereumTransactionData.cjs"));
10
10
  var _Cache = _interopRequireDefault(require("./Cache.cjs"));
@@ -65,7 +65,7 @@ class EthereumTransactionDataEip2930 extends _EthereumTransactionData.default {
65
65
  }
66
66
 
67
67
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
68
- const decoded = /** @type {string[]} */rlp.decode(bytes.subarray(1));
68
+ const decoded = /** @type {string[]} */(0, _ethers.decodeRlp)(bytes.subarray(1));
69
69
  if (!Array.isArray(decoded)) {
70
70
  throw new Error("ethereum data is not a list");
71
71
  }
@@ -94,7 +94,7 @@ class EthereumTransactionDataEip2930 extends _EthereumTransactionData.default {
94
94
  * @returns {Uint8Array}
95
95
  */
96
96
  toBytes() {
97
- const encoded = rlp.encode([this.chainId, this.nonce, this.gasPrice, this.gasLimit, this.to, this.value, this.callData, this.accessList, this.recId, this.r, this.s]);
97
+ const encoded = (0, _ethers.encodeRlp)([this.chainId, this.nonce, this.gasPrice, this.gasLimit, this.to, this.value, this.callData, this.accessList, this.recId, this.r, this.s]);
98
98
  return hex.decode("01" + encoded.substring(2));
99
99
  }
100
100
 
@@ -1,2 +1,2 @@
1
- import*as t from"@ethersproject/rlp";import{decode as s,encode as i}from"./encoding/hex.js";import e from"./EthereumTransactionData.js";import r from"./Cache.js";class a extends e{constructor(t){super(t),this.chainId=t.chainId,this.nonce=t.nonce,this.gasPrice=t.gasPrice,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.accessList=t.accessList,this.recId=t.recId,this.r=t.r,this.s=t.s}static fromBytes(i){if(0===i.length)throw new Error("empty bytes");const e=t.decode(i.subarray(1));if(!Array.isArray(e))throw new Error("ethereum data is not a list");if(11!==e.length)throw new Error("invalid ethereum transaction data");return new a({chainId:s(e[0]),nonce:s(e[1]),gasPrice:s(e[2]),gasLimit:s(e[3]),to:s(e[4]),value:s(e[5]),callData:s(e[6]),accessList:e[7].map(t=>s(t)),recId:s(e[8]),r:s(e[9]),s:s(e[10])})}toBytes(){const i=t.encode([this.chainId,this.nonce,this.gasPrice,this.gasLimit,this.to,this.value,this.callData,this.accessList,this.recId,this.r,this.s]);return s("01"+i.substring(2))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{chainId:i(this.chainId),nonce:i(this.nonce),gasPrice:i(this.gasPrice),gasLimit:i(this.gasLimit),to:i(this.to),value:i(this.value),callData:i(this.callData),accessList:this.accessList.map(t=>i(t)),recId:i(this.recId),r:i(this.r),s:i(this.s)}}}r.setEthereumTransactionDataEip2930FromBytes(t=>a.fromBytes(t));export{a as default};
1
+ import{decodeRlp as t,encodeRlp as s}from"ethers";import{decode as i,encode as r}from"./encoding/hex.js";import a from"./EthereumTransactionData.js";import e from"./Cache.js";class c extends a{constructor(t){super(t),this.chainId=t.chainId,this.nonce=t.nonce,this.gasPrice=t.gasPrice,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.accessList=t.accessList,this.recId=t.recId,this.r=t.r,this.s=t.s}static fromBytes(s){if(0===s.length)throw new Error("empty bytes");const r=t(s.subarray(1));if(!Array.isArray(r))throw new Error("ethereum data is not a list");if(11!==r.length)throw new Error("invalid ethereum transaction data");return new c({chainId:i(r[0]),nonce:i(r[1]),gasPrice:i(r[2]),gasLimit:i(r[3]),to:i(r[4]),value:i(r[5]),callData:i(r[6]),accessList:r[7].map(t=>i(t)),recId:i(r[8]),r:i(r[9]),s:i(r[10])})}toBytes(){const t=s([this.chainId,this.nonce,this.gasPrice,this.gasLimit,this.to,this.value,this.callData,this.accessList,this.recId,this.r,this.s]);return i("01"+t.substring(2))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{chainId:r(this.chainId),nonce:r(this.nonce),gasPrice:r(this.gasPrice),gasLimit:r(this.gasLimit),to:r(this.to),value:r(this.value),callData:r(this.callData),accessList:this.accessList.map(t=>r(t)),recId:r(this.recId),r:r(this.r),s:r(this.s)}}}e.setEthereumTransactionDataEip2930FromBytes(t=>c.fromBytes(t));export{c as default};
2
2
  //# sourceMappingURL=EthereumTransactionDataEip2930.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumTransactionDataEip2930.js","sources":["../src/EthereumTransactionDataEip2930.js"],"sourcesContent":["import * as rlp from \"@ethersproject/rlp\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataEip2930JSON\n * @property {string} chainId\n * @property {string} nonce\n * @property {string} gasPrice\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {string[]} accessList\n * @property {string} recId\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataEip2930 extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.chainId\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.gasPrice\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Uint8Array[]} props.accessList\n * @param {Uint8Array} props.recId\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.chainId = props.chainId;\n this.nonce = props.nonce;\n this.gasPrice = props.gasPrice;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.accessList = props.accessList;\n this.recId = props.recId;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (rlp.decode(bytes.subarray(1)));\n\n if (!Array.isArray(decoded)) {\n throw new Error(\"ethereum data is not a list\");\n }\n\n if (decoded.length !== 11) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n // TODO\n return new EthereumTransactionDataEip2930({\n chainId: hex.decode(/** @type {string} */ (decoded[0])),\n nonce: hex.decode(/** @type {string} */ (decoded[1])),\n gasPrice: hex.decode(/** @type {string} */ (decoded[2])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[3])),\n to: hex.decode(/** @type {string} */ (decoded[4])),\n value: hex.decode(/** @type {string} */ (decoded[5])),\n callData: hex.decode(/** @type {string} */ (decoded[6])),\n // @ts-ignore\n accessList: /** @type {string[]} */ (decoded[7]).map((v) =>\n hex.decode(v),\n ),\n recId: hex.decode(/** @type {string} */ (decoded[8])),\n r: hex.decode(/** @type {string} */ (decoded[9])),\n s: hex.decode(/** @type {string} */ (decoded[10])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n const encoded = rlp.encode([\n this.chainId,\n this.nonce,\n this.gasPrice,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.accessList,\n this.recId,\n this.r,\n this.s,\n ]);\n return hex.decode(\"01\" + encoded.substring(2));\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataEip2930JSON}\n */\n toJSON() {\n return {\n chainId: hex.encode(this.chainId),\n nonce: hex.encode(this.nonce),\n gasPrice: hex.encode(this.gasPrice),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n accessList: this.accessList.map((v) => hex.encode(v)),\n recId: hex.encode(this.recId),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataEip2930FromBytes((bytes) =>\n EthereumTransactionDataEip2930.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataEip2930","EthereumTransactionData","constructor","props","super","this","chainId","nonce","gasPrice","gasLimit","to","value","accessList","recId","r","s","fromBytes","bytes","length","Error","decoded","rlp","decode","subarray","Array","isArray","hex.decode","callData","map","v","toBytes","encoded","encode","substring","toString","JSON","stringify","toJSON","hex.encode","CACHE","setEthereumTransactionDataEip2930FromBytes"],"mappings":"kKAoBe,MAAMA,UAAuCC,EAgBxD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,QAAUH,EAAMG,QACrBD,KAAKE,MAAQJ,EAAMI,MACnBF,KAAKG,SAAWL,EAAMK,SACtBH,KAAKI,SAAWN,EAAMM,SACtBJ,KAAKK,GAAKP,EAAMO,GAChBL,KAAKM,MAAQR,EAAMQ,MACnBN,KAAKO,WAAaT,EAAMS,WACxBP,KAAKQ,MAAQV,EAAMU,MACnBR,KAAKS,EAAIX,EAAMW,EACfT,KAAKU,EAAIZ,EAAMY,CACnB,CAMA,gBAAOC,CAAUC,GACb,GAAqB,IAAjBA,EAAMC,OACN,MAAM,IAAIC,MAAM,eAIpB,MAAMC,EAAmCC,EAAIC,OAAOL,EAAMM,SAAS,IAEnE,IAAKC,MAAMC,QAAQL,GACf,MAAM,IAAID,MAAM,+BAGpB,GAAuB,KAAnBC,EAAQF,OACR,MAAM,IAAIC,MAAM,qCAIpB,OAAO,IAAInB,EAA+B,CACtCM,QAASoB,EAAkCN,EAAQ,IACnDb,MAAOmB,EAAkCN,EAAQ,IACjDZ,SAAUkB,EAAkCN,EAAQ,IACpDX,SAAUiB,EAAkCN,EAAQ,IACpDV,GAAIgB,EAAkCN,EAAQ,IAC9CT,MAAOe,EAAkCN,EAAQ,IACjDO,SAAUD,EAAkCN,EAAQ,IAEpDR,WAAqCQ,EAAQ,GAAIQ,IAAKC,GAClDH,EAAWG,IAEfhB,MAAOa,EAAkCN,EAAQ,IACjDN,EAAGY,EAAkCN,EAAQ,IAC7CL,EAAGW,EAAkCN,EAAQ,MAErD,CAKA,OAAAU,GACI,MAAMC,EAAUV,EAAIW,OAAO,CACvB3B,KAAKC,QACLD,KAAKE,MACLF,KAAKG,SACLH,KAAKI,SACLJ,KAAKK,GACLL,KAAKM,MACLN,KAAKsB,SACLtB,KAAKO,WACLP,KAAKQ,MACLR,KAAKS,EACLT,KAAKU,IAET,OAAOW,EAAW,KAAOK,EAAQE,UAAU,GAC/C,CAKA,QAAAC,GACI,OAAOC,KAAKC,UAAU/B,KAAKgC,SAAU,KAAM,EAC/C,CAKA,MAAAA,GACI,MAAO,CACH/B,QAASgC,EAAWjC,KAAKC,SACzBC,MAAO+B,EAAWjC,KAAKE,OACvBC,SAAU8B,EAAWjC,KAAKG,UAC1BC,SAAU6B,EAAWjC,KAAKI,UAC1BC,GAAI4B,EAAWjC,KAAKK,IACpBC,MAAO2B,EAAWjC,KAAKM,OACvBgB,SAAUW,EAAWjC,KAAKsB,UAC1Bf,WAAYP,KAAKO,WAAWgB,IAAKC,GAAMS,EAAWT,IAClDhB,MAAOyB,EAAWjC,KAAKQ,OACvBC,EAAGwB,EAAWjC,KAAKS,GACnBC,EAAGuB,EAAWjC,KAAKU,GAE3B,EAGJwB,EAAMC,2CAA4CvB,GAC9CjB,EAA+BgB,UAAUC"}
1
+ {"version":3,"file":"EthereumTransactionDataEip2930.js","sources":["../src/EthereumTransactionDataEip2930.js"],"sourcesContent":["import { decodeRlp, encodeRlp } from \"ethers\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataEip2930JSON\n * @property {string} chainId\n * @property {string} nonce\n * @property {string} gasPrice\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {string[]} accessList\n * @property {string} recId\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataEip2930 extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.chainId\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.gasPrice\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Uint8Array[]} props.accessList\n * @param {Uint8Array} props.recId\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.chainId = props.chainId;\n this.nonce = props.nonce;\n this.gasPrice = props.gasPrice;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.accessList = props.accessList;\n this.recId = props.recId;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (decodeRlp(bytes.subarray(1)));\n\n if (!Array.isArray(decoded)) {\n throw new Error(\"ethereum data is not a list\");\n }\n\n if (decoded.length !== 11) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n // TODO\n return new EthereumTransactionDataEip2930({\n chainId: hex.decode(/** @type {string} */ (decoded[0])),\n nonce: hex.decode(/** @type {string} */ (decoded[1])),\n gasPrice: hex.decode(/** @type {string} */ (decoded[2])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[3])),\n to: hex.decode(/** @type {string} */ (decoded[4])),\n value: hex.decode(/** @type {string} */ (decoded[5])),\n callData: hex.decode(/** @type {string} */ (decoded[6])),\n // @ts-ignore\n accessList: /** @type {string[]} */ (decoded[7]).map((v) =>\n hex.decode(v),\n ),\n recId: hex.decode(/** @type {string} */ (decoded[8])),\n r: hex.decode(/** @type {string} */ (decoded[9])),\n s: hex.decode(/** @type {string} */ (decoded[10])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n const encoded = encodeRlp([\n this.chainId,\n this.nonce,\n this.gasPrice,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.accessList,\n this.recId,\n this.r,\n this.s,\n ]);\n return hex.decode(\"01\" + encoded.substring(2));\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataEip2930JSON}\n */\n toJSON() {\n return {\n chainId: hex.encode(this.chainId),\n nonce: hex.encode(this.nonce),\n gasPrice: hex.encode(this.gasPrice),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n accessList: this.accessList.map((v) => hex.encode(v)),\n recId: hex.encode(this.recId),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataEip2930FromBytes((bytes) =>\n EthereumTransactionDataEip2930.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataEip2930","EthereumTransactionData","constructor","props","super","this","chainId","nonce","gasPrice","gasLimit","to","value","accessList","recId","r","s","fromBytes","bytes","length","Error","decoded","decodeRlp","subarray","Array","isArray","hex.decode","callData","map","v","toBytes","encoded","encodeRlp","substring","toString","JSON","stringify","toJSON","hex.encode","CACHE","setEthereumTransactionDataEip2930FromBytes"],"mappings":"+KAoBe,MAAMA,UAAuCC,EAgBxD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,QAAUH,EAAMG,QACrBD,KAAKE,MAAQJ,EAAMI,MACnBF,KAAKG,SAAWL,EAAMK,SACtBH,KAAKI,SAAWN,EAAMM,SACtBJ,KAAKK,GAAKP,EAAMO,GAChBL,KAAKM,MAAQR,EAAMQ,MACnBN,KAAKO,WAAaT,EAAMS,WACxBP,KAAKQ,MAAQV,EAAMU,MACnBR,KAAKS,EAAIX,EAAMW,EACfT,KAAKU,EAAIZ,EAAMY,CACnB,CAMA,gBAAOC,CAAUC,GACb,GAAqB,IAAjBA,EAAMC,OACN,MAAM,IAAIC,MAAM,eAIpB,MAAMC,EAAmCC,EAAUJ,EAAMK,SAAS,IAEl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GAC9CjB,EAA+BgB,UAAUC"}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var rlp = _interopRequireWildcard(require("@ethersproject/rlp"));
7
+ var _ethers = require("ethers");
8
8
  var hex = _interopRequireWildcard(require("./encoding/hex.cjs"));
9
9
  var _EthereumTransactionData = _interopRequireDefault(require("./EthereumTransactionData.cjs"));
10
10
  var _Cache = _interopRequireDefault(require("./Cache.cjs"));
@@ -72,7 +72,7 @@ class EthereumTransactionDataEip7702 extends _EthereumTransactionData.default {
72
72
  }
73
73
 
74
74
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
75
- const decoded = /** @type {string[]} */rlp.decode(bytes.subarray(1));
75
+ const decoded = /** @type {string[]} */(0, _ethers.decodeRlp)(bytes.subarray(1));
76
76
  if (!Array.isArray(decoded)) {
77
77
  throw new Error("ethereum data is not a list");
78
78
  }
@@ -134,7 +134,7 @@ class EthereumTransactionDataEip7702 extends _EthereumTransactionData.default {
134
134
  * @returns {Uint8Array}
135
135
  */
136
136
  toBytes() {
137
- const encoded = rlp.encode([this.chainId, this.nonce, this.maxPriorityGas, this.maxGas, this.gasLimit, this.to, this.value, this.callData, this.accessList, this.authorizationList, this.recId, this.r, this.s]);
137
+ const encoded = (0, _ethers.encodeRlp)([this.chainId, this.nonce, this.maxPriorityGas, this.maxGas, this.gasLimit, this.to, this.value, this.callData, this.accessList, this.authorizationList, this.recId, this.r, this.s]);
138
138
  return hex.decode("04" + encoded.substring(2));
139
139
  }
140
140
 
@@ -1,2 +1,2 @@
1
- import*as t from"@ethersproject/rlp";import{decode as i,encode as s}from"./encoding/hex.js";import a from"./EthereumTransactionData.js";import r from"./Cache.js";class e extends a{constructor(t){super(t),this.chainId=t.chainId,this.nonce=t.nonce,this.maxPriorityGas=t.maxPriorityGas,this.maxGas=t.maxGas,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.callData=t.callData,this.authorizationList=t.authorizationList,this.accessList=t.accessList,this.recId=t.recId,this.r=t.r,this.s=t.s}static fromBytes(s){if(0===s.length)throw new Error("empty bytes");const a=t.decode(s.subarray(1));if(!Array.isArray(a))throw new Error("ethereum data is not a list");if(13!==a.length)throw new Error("invalid ethereum transaction data");if(!Array.isArray(a[9]))throw new Error("authorization list must be an array");const r=a[9].map(t=>{if(!Array.isArray(t)||6!==t.length)throw new Error("invalid authorization list entry: must be [chainId, contractAddress, nonce, yParity, r, s]");return[i(t[0]),i(t[1]),i(t[2]),i(t[3]),i(t[4]),i(t[5])]});return new e({chainId:i(a[0]),nonce:i(a[1]),maxPriorityGas:i(a[2]),maxGas:i(a[3]),gasLimit:i(a[4]),to:i(a[5]),value:i(a[6]),callData:i(a[7]),accessList:a[8].map(t=>i(t)),authorizationList:r,recId:i(a[10]),r:i(a[11]),s:i(a[12])})}toBytes(){const s=t.encode([this.chainId,this.nonce,this.maxPriorityGas,this.maxGas,this.gasLimit,this.to,this.value,this.callData,this.accessList,this.authorizationList,this.recId,this.r,this.s]);return i("04"+s.substring(2))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{chainId:s(this.chainId),nonce:s(this.nonce),maxPriorityGas:s(this.maxPriorityGas),maxGas:s(this.maxGas),gasLimit:s(this.gasLimit),to:s(this.to),value:s(this.value),callData:s(this.callData),authorizationList:this.authorizationList.map(([t,i,a,r,e,o])=>[s(t),s(i),s(a),s(r),s(e),s(o)]),accessList:this.accessList.map(t=>s(t)),recId:s(this.recId),r:s(this.r),s:s(this.s)}}}r.setEthereumTransactionDataEip7702FromBytes(t=>e.fromBytes(t));export{e as default};
1
+ import{decodeRlp as t,encodeRlp as i}from"ethers";import{decode as s,encode as a}from"./encoding/hex.js";import r from"./EthereumTransactionData.js";import o from"./Cache.js";class e extends r{constructor(t){super(t),this.chainId=t.chainId,this.nonce=t.nonce,this.maxPriorityGas=t.maxPriorityGas,this.maxGas=t.maxGas,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.callData=t.callData,this.authorizationList=t.authorizationList,this.accessList=t.accessList,this.recId=t.recId,this.r=t.r,this.s=t.s}static fromBytes(i){if(0===i.length)throw new Error("empty bytes");const a=t(i.subarray(1));if(!Array.isArray(a))throw new Error("ethereum data is not a list");if(13!==a.length)throw new Error("invalid ethereum transaction data");if(!Array.isArray(a[9]))throw new Error("authorization list must be an array");const r=a[9].map(t=>{if(!Array.isArray(t)||6!==t.length)throw new Error("invalid authorization list entry: must be [chainId, contractAddress, nonce, yParity, r, s]");return[s(t[0]),s(t[1]),s(t[2]),s(t[3]),s(t[4]),s(t[5])]});return new e({chainId:s(a[0]),nonce:s(a[1]),maxPriorityGas:s(a[2]),maxGas:s(a[3]),gasLimit:s(a[4]),to:s(a[5]),value:s(a[6]),callData:s(a[7]),accessList:a[8].map(t=>s(t)),authorizationList:r,recId:s(a[10]),r:s(a[11]),s:s(a[12])})}toBytes(){const t=i([this.chainId,this.nonce,this.maxPriorityGas,this.maxGas,this.gasLimit,this.to,this.value,this.callData,this.accessList,this.authorizationList,this.recId,this.r,this.s]);return s("04"+t.substring(2))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{chainId:a(this.chainId),nonce:a(this.nonce),maxPriorityGas:a(this.maxPriorityGas),maxGas:a(this.maxGas),gasLimit:a(this.gasLimit),to:a(this.to),value:a(this.value),callData:a(this.callData),authorizationList:this.authorizationList.map(([t,i,s,r,o,e])=>[a(t),a(i),a(s),a(r),a(o),a(e)]),accessList:this.accessList.map(t=>a(t)),recId:a(this.recId),r:a(this.r),s:a(this.s)}}}o.setEthereumTransactionDataEip7702FromBytes(t=>e.fromBytes(t));export{e as default};
2
2
  //# sourceMappingURL=EthereumTransactionDataEip7702.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumTransactionDataEip7702.js","sources":["../src/EthereumTransactionDataEip7702.js"],"sourcesContent":["import * as rlp from \"@ethersproject/rlp\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataEip7702JSON\n * @property {string} chainId\n * @property {string} nonce\n * @property {string} maxPriorityGas\n * @property {string} maxGas\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {Array<[string, string, string, string, string, string]>} authorizationList - Array of [chainId, contractAddress, nonce, yParity, r, s] tuples\n * @property {string[]} accessList\n * @property {string} recId\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataEip7702 extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.chainId\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.maxPriorityGas\n * @param {Uint8Array} props.maxGas\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Array<[Uint8Array, Uint8Array, Uint8Array, Uint8Array, Uint8Array, Uint8Array]>} props.authorizationList - Array of [chainId, contractAddress, nonce, yParity, r, s] tuples\n * @param {Uint8Array[]} props.accessList\n * @param {Uint8Array} props.recId\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.chainId = props.chainId;\n this.nonce = props.nonce;\n this.maxPriorityGas = props.maxPriorityGas;\n this.maxGas = props.maxGas;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.callData = props.callData;\n this.authorizationList = props.authorizationList;\n this.accessList = props.accessList;\n this.recId = props.recId;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (rlp.decode(bytes.subarray(1)));\n\n if (!Array.isArray(decoded)) {\n throw new Error(\"ethereum data is not a list\");\n }\n\n if (decoded.length !== 13) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n // Decode authorization list: array of [chainId, contractAddress, nonce, yParity, r, s] tuples\n // Authorization list can be empty (empty array is valid)\n if (!Array.isArray(decoded[9])) {\n throw new Error(\"authorization list must be an array\");\n }\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n const authorizationList = /** @type {string[]} */ (decoded[9]).map(\n (authTuple) => {\n if (!Array.isArray(authTuple) || authTuple.length !== 6) {\n throw new Error(\n \"invalid authorization list entry: must be [chainId, contractAddress, nonce, yParity, r, s]\",\n );\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[0])), // chainId\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[1])), // contractAddress (20 bytes)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[2])), // nonce\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[3])), // yParity (0 or 1)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[4])), // r (32 bytes)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[5])), // s (32 bytes)\n ];\n },\n );\n\n return new EthereumTransactionDataEip7702({\n chainId: hex.decode(/** @type {string} */ (decoded[0])),\n nonce: hex.decode(/** @type {string} */ (decoded[1])),\n maxPriorityGas: hex.decode(/** @type {string} */ (decoded[2])),\n maxGas: hex.decode(/** @type {string} */ (decoded[3])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[4])),\n to: hex.decode(/** @type {string} */ (decoded[5])),\n value: hex.decode(/** @type {string} */ (decoded[6])),\n callData: hex.decode(/** @type {string} */ (decoded[7])),\n // @ts-ignore\n accessList: /** @type {string[]} */ (decoded[8]).map((v) =>\n hex.decode(v),\n ),\n // @ts-ignore\n authorizationList: authorizationList,\n recId: hex.decode(/** @type {string} */ (decoded[10])),\n r: hex.decode(/** @type {string} */ (decoded[11])),\n s: hex.decode(/** @type {string} */ (decoded[12])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n const encoded = rlp.encode([\n this.chainId,\n this.nonce,\n this.maxPriorityGas,\n this.maxGas,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.accessList,\n this.authorizationList,\n this.recId,\n this.r,\n this.s,\n ]);\n return hex.decode(\"04\" + encoded.substring(2));\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataEip7702JSON}\n */\n toJSON() {\n return {\n chainId: hex.encode(this.chainId),\n nonce: hex.encode(this.nonce),\n maxPriorityGas: hex.encode(this.maxPriorityGas),\n maxGas: hex.encode(this.maxGas),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n authorizationList: this.authorizationList.map(\n ([chainId, contractAddress, nonce, yParity, r, s]) => [\n hex.encode(chainId),\n hex.encode(contractAddress),\n hex.encode(nonce),\n hex.encode(yParity),\n hex.encode(r),\n hex.encode(s),\n ],\n ),\n accessList: this.accessList.map((v) => hex.encode(v)),\n recId: hex.encode(this.recId),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataEip7702FromBytes((bytes) =>\n EthereumTransactionDataEip7702.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataEip7702","EthereumTransactionData","constructor","props","super","this","chainId","nonce","maxPriorityGas","maxGas","gasLimit","to","value","callData","authorizationList","accessList","recId","r","s","fromBytes","bytes","length","Error","decoded","rlp","decode","subarray","Array","isArray","map","authTuple","hex.decode","v","toBytes","encoded","encode","substring","toString","JSON","stringify","toJSON","hex.encode","contractAddress","yParity","CACHE","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B,EAAMC,2CAA4CzB,GAC9CpB,EAA+BmB,UAAUC"}
1
+ {"version":3,"file":"EthereumTransactionDataEip7702.js","sources":["../src/EthereumTransactionDataEip7702.js"],"sourcesContent":["import { decodeRlp, encodeRlp } from \"ethers\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataEip7702JSON\n * @property {string} chainId\n * @property {string} nonce\n * @property {string} maxPriorityGas\n * @property {string} maxGas\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {Array<[string, string, string, string, string, string]>} authorizationList - Array of [chainId, contractAddress, nonce, yParity, r, s] tuples\n * @property {string[]} accessList\n * @property {string} recId\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataEip7702 extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.chainId\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.maxPriorityGas\n * @param {Uint8Array} props.maxGas\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Array<[Uint8Array, Uint8Array, Uint8Array, Uint8Array, Uint8Array, Uint8Array]>} props.authorizationList - Array of [chainId, contractAddress, nonce, yParity, r, s] tuples\n * @param {Uint8Array[]} props.accessList\n * @param {Uint8Array} props.recId\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.chainId = props.chainId;\n this.nonce = props.nonce;\n this.maxPriorityGas = props.maxPriorityGas;\n this.maxGas = props.maxGas;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.callData = props.callData;\n this.authorizationList = props.authorizationList;\n this.accessList = props.accessList;\n this.recId = props.recId;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (decodeRlp(bytes.subarray(1)));\n\n if (!Array.isArray(decoded)) {\n throw new Error(\"ethereum data is not a list\");\n }\n\n if (decoded.length !== 13) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n // Decode authorization list: array of [chainId, contractAddress, nonce, yParity, r, s] tuples\n // Authorization list can be empty (empty array is valid)\n if (!Array.isArray(decoded[9])) {\n throw new Error(\"authorization list must be an array\");\n }\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n const authorizationList = /** @type {string[]} */ (decoded[9]).map(\n (authTuple) => {\n if (!Array.isArray(authTuple) || authTuple.length !== 6) {\n throw new Error(\n \"invalid authorization list entry: must be [chainId, contractAddress, nonce, yParity, r, s]\",\n );\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[0])), // chainId\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[1])), // contractAddress (20 bytes)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[2])), // nonce\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[3])), // yParity (0 or 1)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[4])), // r (32 bytes)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n hex.decode(/** @type {string} */ (authTuple[5])), // s (32 bytes)\n ];\n },\n );\n\n return new EthereumTransactionDataEip7702({\n chainId: hex.decode(/** @type {string} */ (decoded[0])),\n nonce: hex.decode(/** @type {string} */ (decoded[1])),\n maxPriorityGas: hex.decode(/** @type {string} */ (decoded[2])),\n maxGas: hex.decode(/** @type {string} */ (decoded[3])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[4])),\n to: hex.decode(/** @type {string} */ (decoded[5])),\n value: hex.decode(/** @type {string} */ (decoded[6])),\n callData: hex.decode(/** @type {string} */ (decoded[7])),\n // @ts-ignore\n accessList: /** @type {string[]} */ (decoded[8]).map((v) =>\n hex.decode(v),\n ),\n // @ts-ignore\n authorizationList: authorizationList,\n recId: hex.decode(/** @type {string} */ (decoded[10])),\n r: hex.decode(/** @type {string} */ (decoded[11])),\n s: hex.decode(/** @type {string} */ (decoded[12])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n const encoded = encodeRlp([\n this.chainId,\n this.nonce,\n this.maxPriorityGas,\n this.maxGas,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.accessList,\n this.authorizationList,\n this.recId,\n this.r,\n this.s,\n ]);\n return hex.decode(\"04\" + encoded.substring(2));\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataEip7702JSON}\n */\n toJSON() {\n return {\n chainId: hex.encode(this.chainId),\n nonce: hex.encode(this.nonce),\n maxPriorityGas: hex.encode(this.maxPriorityGas),\n maxGas: hex.encode(this.maxGas),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n authorizationList: this.authorizationList.map(\n ([chainId, contractAddress, nonce, yParity, r, s]) => [\n hex.encode(chainId),\n hex.encode(contractAddress),\n hex.encode(nonce),\n hex.encode(yParity),\n hex.encode(r),\n hex.encode(s),\n ],\n ),\n accessList: this.accessList.map((v) => hex.encode(v)),\n recId: hex.encode(this.recId),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataEip7702FromBytes((bytes) =>\n EthereumTransactionDataEip7702.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataEip7702","EthereumTransactionData","constructor","props","super","this","chainId","nonce","maxPriorityGas","maxGas","gasLimit","to","value","callData","authorizationList","accessList","recId","r","s","fromBytes","bytes","length","Error","decoded","decodeRlp","subarray","Array","isArray","map","authTuple","hex.decode","v","toBytes","encoded","encodeRlp","substring","toString","JSON","stringify","toJSON","hex.encode","contractAddress","yParity","CACHE","setEthereumTransactionDataEip7702FromBytes"],"mappings":"+KAsBe,MAAMA,UAAuCC,EAkBxD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,QAAUH,EAAMG,QACrBD,KAAKE,MAAQJ,EAAMI,MACnBF,KAAKG,eAAiBL,EAAMK,eAC5BH,KAAKI,OAASN,EAAMM,OACpBJ,KAAKK,SAAWP,EAAMO,SACtBL,KAAKM,GAAKR,EAAMQ,GAChBN,KAAKO,MAAQT,EAAMS,MACnBP,KAAKQ,SAAWV,EAAMU,SACtBR,KAAKS,kBAAoBX,EAAMW,kBAC/BT,KAAKU,WAAaZ,EAAMY,WACxBV,KAAKW,MAAQb,EAAMa,MACnBX,KAAKY,EAAId,EAAMc,EACfZ,KAAKa,EAAIf,EAAMe,CACnB,CAMA,gBAAOC,CAAUC,GACb,GAAqB,IAAjBA,EAAMC,OACN,MAAM,IAAIC,MAAM,eAIpB,MAAMC,EAAmCC,EAAUJ,EAAMK,SAAS,IAElE,IAAKC,MAAMC,QAAQJ,GACf,MAAM,IAAID,MAAM,+BAGpB,GAAuB,KAAnBC,EAAQF,OACR,MAAM,IAAIC,MAAM,qCAKpB,IAAKI,MAAMC,QAAQJ,EAAQ,IACvB,MAAM,IAAID,MAAM,uCAIpB,MAAMR,EAA6CS,EAAQ,GAAIK,IAC1DC,IACG,IAAKH,MAAMC,QAAQE,IAAmC,IAArBA,EAAUR,OACvC,MAAM,IAAIC,MACN,8FAGR,MAAO,CAEHQ,EAAkCD,EAAU,IAE5CC,EAAkCD,EAAU,IAE5CC,EAAkCD,EAAU,IAE5CC,EAAkCD,EAAU,IAE5CC,EAAkCD,EAAU,IAE5CC,E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,GACXF,EAAWvB,GACXuB,EAAWtB,KAGnBH,WAAYV,KAAKU,WAAWa,IAAKG,GAAMS,EAAWT,IAClDf,MAAOwB,EAAWnC,KAAKW,OACvBC,EAAGuB,EAAWnC,KAAKY,GACnBC,EAAGsB,EAAWnC,KAAKa,GAE3B,EAGJyB,EAAMC,2CAA4CxB,GAC9CpB,EAA+BmB,UAAUC"}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var rlp = _interopRequireWildcard(require("@ethersproject/rlp"));
7
+ var _ethers = require("ethers");
8
8
  var hex = _interopRequireWildcard(require("./encoding/hex.cjs"));
9
9
  var _EthereumTransactionData = _interopRequireDefault(require("./EthereumTransactionData.cjs"));
10
10
  var _Cache = _interopRequireDefault(require("./Cache.cjs"));
@@ -59,7 +59,7 @@ class EthereumTransactionDataLegacy extends _EthereumTransactionData.default {
59
59
  }
60
60
 
61
61
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
62
- const decoded = /** @type {string[]} */rlp.decode(bytes);
62
+ const decoded = /** @type {string[]} */(0, _ethers.decodeRlp)(bytes);
63
63
  if (decoded.length != 9) {
64
64
  throw new Error("invalid ethereum transaction data");
65
65
  }
@@ -80,7 +80,7 @@ class EthereumTransactionDataLegacy extends _EthereumTransactionData.default {
80
80
  * @returns {Uint8Array}
81
81
  */
82
82
  toBytes() {
83
- return hex.decode(rlp.encode([this.nonce, this.gasPrice, this.gasLimit, this.to, this.value, this.callData, this.v, this.r, this.s]));
83
+ return hex.decode((0, _ethers.encodeRlp)([this.nonce, this.gasPrice, this.gasLimit, this.to, this.value, this.callData, this.v, this.r, this.s]));
84
84
  }
85
85
 
86
86
  /**
@@ -1,2 +1,2 @@
1
- import*as t from"@ethersproject/rlp";import{decode as s,encode as i}from"./encoding/hex.js";import e from"./EthereumTransactionData.js";import r from"./Cache.js";class a extends e{constructor(t){super(t),this.nonce=t.nonce,this.gasPrice=t.gasPrice,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.v=t.v,this.r=t.r,this.s=t.s}static fromBytes(i){if(0===i.length)throw new Error("empty bytes");const e=t.decode(i);if(9!=e.length)throw new Error("invalid ethereum transaction data");return new a({nonce:s(e[0]),gasPrice:s(e[1]),gasLimit:s(e[2]),to:s(e[3]),value:s(e[4]),callData:s(e[5]),v:s(e[6]),r:s(e[7]),s:s(e[8])})}toBytes(){return s(t.encode([this.nonce,this.gasPrice,this.gasLimit,this.to,this.value,this.callData,this.v,this.r,this.s]))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{nonce:i(this.nonce),gasPrice:i(this.gasPrice),gasLimit:i(this.gasLimit),to:i(this.to),value:i(this.value),callData:i(this.callData),v:i(this.v),r:i(this.r),s:i(this.s)}}}r.setEthereumTransactionDataLegacyFromBytes(t=>a.fromBytes(t));export{a as default};
1
+ import{decodeRlp as t,encodeRlp as s}from"ethers";import{decode as i,encode as e}from"./encoding/hex.js";import r from"./EthereumTransactionData.js";import a from"./Cache.js";class o extends r{constructor(t){super(t),this.nonce=t.nonce,this.gasPrice=t.gasPrice,this.gasLimit=t.gasLimit,this.to=t.to,this.value=t.value,this.v=t.v,this.r=t.r,this.s=t.s}static fromBytes(s){if(0===s.length)throw new Error("empty bytes");const e=t(s);if(9!=e.length)throw new Error("invalid ethereum transaction data");return new o({nonce:i(e[0]),gasPrice:i(e[1]),gasLimit:i(e[2]),to:i(e[3]),value:i(e[4]),callData:i(e[5]),v:i(e[6]),r:i(e[7]),s:i(e[8])})}toBytes(){return i(s([this.nonce,this.gasPrice,this.gasLimit,this.to,this.value,this.callData,this.v,this.r,this.s]))}toString(){return JSON.stringify(this.toJSON(),null,2)}toJSON(){return{nonce:e(this.nonce),gasPrice:e(this.gasPrice),gasLimit:e(this.gasLimit),to:e(this.to),value:e(this.value),callData:e(this.callData),v:e(this.v),r:e(this.r),s:e(this.s)}}}a.setEthereumTransactionDataLegacyFromBytes(t=>o.fromBytes(t));export{o as default};
2
2
  //# sourceMappingURL=EthereumTransactionDataLegacy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumTransactionDataLegacy.js","sources":["../src/EthereumTransactionDataLegacy.js"],"sourcesContent":["import * as rlp from \"@ethersproject/rlp\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataLegacyJSON\n * @property {string} nonce\n * @property {string} gasPrice\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {string} v\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataLegacy extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.gasPrice\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Uint8Array} props.v\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.nonce = props.nonce;\n this.gasPrice = props.gasPrice;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.v = props.v;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (rlp.decode(bytes));\n\n if (decoded.length != 9) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n return new EthereumTransactionDataLegacy({\n nonce: hex.decode(/** @type {string} */ (decoded[0])),\n gasPrice: hex.decode(/** @type {string} */ (decoded[1])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[2])),\n to: hex.decode(/** @type {string} */ (decoded[3])),\n value: hex.decode(/** @type {string} */ (decoded[4])),\n callData: hex.decode(/** @type {string} */ (decoded[5])),\n v: hex.decode(/** @type {string} */ (decoded[6])),\n r: hex.decode(/** @type {string} */ (decoded[7])),\n s: hex.decode(/** @type {string} */ (decoded[8])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return hex.decode(\n rlp.encode([\n this.nonce,\n this.gasPrice,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.v,\n this.r,\n this.s,\n ]),\n );\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataLegacyJSON}\n */\n toJSON() {\n return {\n nonce: hex.encode(this.nonce),\n gasPrice: hex.encode(this.gasPrice),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n v: hex.encode(this.v),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataLegacyFromBytes((bytes) =>\n EthereumTransactionDataLegacy.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataLegacy","EthereumTransactionData","constructor","props","super","this","nonce","gasPrice","gasLimit","to","value","v","r","s","fromBytes","bytes","length","Error","decoded","rlp","decode","hex.decode","callData","toBytes","encode","toString","JSON","stringify","toJSON","hex.encode","CACHE","setEthereumTransactionDataLegacyFromBytes"],"mappings":"kKAkBe,MAAMA,UAAsCC,EAcvD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,MAAQH,EAAMG,MACnBD,KAAKE,SAAWJ,EAAMI,SACtBF,KAAKG,SAAWL,EAAMK,SACtBH,KAAKI,GAAKN,EAAMM,GAChBJ,KAAKK,MAAQP,EAAMO,MACnBL,KAAKM,EAAIR,EAAMQ,EACfN,KAAKO,EAAIT,EAAMS,EACfP,KAAKQ,EAAIV,EAAMU,CACnB,CAMA,gBAAOC,CAAUC,GACb,GAAqB,IAAjBA,EAAMC,OACN,MAAM,IAAIC,MAAM,eAIpB,MAAMC,EAAmCC,EAAIC,OAAOL,GAEpD,GAAsB,GAAlBG,EAAQF,OACR,MAAM,IAAIC,MAAM,qCAGpB,OAAO,IAAIjB,EAA8B,CACrCM,MAAOe,EAAkCH,EAAQ,IACjDX,SAAUc,EAAkCH,EAAQ,IACpDV,SAAUa,EAAkCH,EAAQ,IACpDT,GAAIY,EAAkCH,EAAQ,IAC9CR,MAAOW,EAAkCH,EAAQ,IACjDI,SAAUD,EAAkCH,EAAQ,IACpDP,EAAGU,EAAkCH,EAAQ,IAC7CN,EAAGS,EAAkCH,EAAQ,IAC7CL,EAAGQ,EAAkCH,EAAQ,KAErD,CAKA,OAAAK,GACI,OAAOF,EACHF,EAAIK,OAAO,CACPnB,KAAKC,MACLD,KAAKE,SACLF,KAAKG,SACLH,KAAKI,GACLJ,KAAKK,MACLL,KAAKiB,SACLjB,KAAKM,EACLN,KAAKO,EACLP,KAAKQ,IAGjB,CAKA,QAAAY,GACI,OAAOC,KAAKC,UAAUtB,KAAKuB,SAAU,KAAM,EAC/C,CAKA,MAAAA,GACI,MAAO,CACHtB,MAAOuB,EAAWxB,KAAKC,OACvBC,SAAUsB,EAAWxB,KAAKE,UAC1BC,SAAUqB,EAAWxB,KAAKG,UAC1BC,GAAIoB,EAAWxB,KAAKI,IACpBC,MAAOmB,EAAWxB,KAAKK,OACvBY,SAAUO,EAAWxB,KAAKiB,UAC1BX,EAAGkB,EAAWxB,KAAKM,GACnBC,EAAGiB,EAAWxB,KAAKO,GACnBC,EAAGgB,EAAWxB,KAAKQ,GAE3B,EAGJiB,EAAMC,0CAA2ChB,GAC7Cf,EAA8Bc,UAAUC"}
1
+ {"version":3,"file":"EthereumTransactionDataLegacy.js","sources":["../src/EthereumTransactionDataLegacy.js"],"sourcesContent":["import { decodeRlp, encodeRlp } from \"ethers\";\nimport * as hex from \"./encoding/hex.js\";\nimport EthereumTransactionData from \"./EthereumTransactionData.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {object} EthereumTransactionDataLegacyJSON\n * @property {string} nonce\n * @property {string} gasPrice\n * @property {string} gasLimit\n * @property {string} to\n * @property {string} value\n * @property {string} callData\n * @property {string} v\n * @property {string} r\n * @property {string} s\n */\n\nexport default class EthereumTransactionDataLegacy extends EthereumTransactionData {\n /**\n * @private\n * @param {object} props\n * @param {Uint8Array} props.nonce\n * @param {Uint8Array} props.gasPrice\n * @param {Uint8Array} props.gasLimit\n * @param {Uint8Array} props.to\n * @param {Uint8Array} props.value\n * @param {Uint8Array} props.callData\n * @param {Uint8Array} props.v\n * @param {Uint8Array} props.r\n * @param {Uint8Array} props.s\n */\n constructor(props) {\n super(props);\n\n this.nonce = props.nonce;\n this.gasPrice = props.gasPrice;\n this.gasLimit = props.gasLimit;\n this.to = props.to;\n this.value = props.value;\n this.v = props.v;\n this.r = props.r;\n this.s = props.s;\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {EthereumTransactionData}\n */\n static fromBytes(bytes) {\n if (bytes.length === 0) {\n throw new Error(\"empty bytes\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const decoded = /** @type {string[]} */ (decodeRlp(bytes));\n\n if (decoded.length != 9) {\n throw new Error(\"invalid ethereum transaction data\");\n }\n\n return new EthereumTransactionDataLegacy({\n nonce: hex.decode(/** @type {string} */ (decoded[0])),\n gasPrice: hex.decode(/** @type {string} */ (decoded[1])),\n gasLimit: hex.decode(/** @type {string} */ (decoded[2])),\n to: hex.decode(/** @type {string} */ (decoded[3])),\n value: hex.decode(/** @type {string} */ (decoded[4])),\n callData: hex.decode(/** @type {string} */ (decoded[5])),\n v: hex.decode(/** @type {string} */ (decoded[6])),\n r: hex.decode(/** @type {string} */ (decoded[7])),\n s: hex.decode(/** @type {string} */ (decoded[8])),\n });\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return hex.decode(\n encodeRlp([\n this.nonce,\n this.gasPrice,\n this.gasLimit,\n this.to,\n this.value,\n this.callData,\n this.v,\n this.r,\n this.s,\n ]),\n );\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON(), null, 2);\n }\n\n /**\n * @returns {EthereumTransactionDataLegacyJSON}\n */\n toJSON() {\n return {\n nonce: hex.encode(this.nonce),\n gasPrice: hex.encode(this.gasPrice),\n gasLimit: hex.encode(this.gasLimit),\n to: hex.encode(this.to),\n value: hex.encode(this.value),\n callData: hex.encode(this.callData),\n v: hex.encode(this.v),\n r: hex.encode(this.r),\n s: hex.encode(this.s),\n };\n }\n}\n\nCACHE.setEthereumTransactionDataLegacyFromBytes((bytes) =>\n EthereumTransactionDataLegacy.fromBytes(bytes),\n);\n"],"names":["EthereumTransactionDataLegacy","EthereumTransactionData","constructor","props","super","this","nonce","gasPrice","gasLimit","to","value","v","r","s","fromBytes","bytes","length","Error","decoded","decodeRlp","hex.decode","callData","toBytes","encodeRlp","toString","JSON","stringify","toJSON","hex.encode","CACHE","setEthereumTransactionDataLegacyFromBytes"],"mappings":"+KAkBe,MAAMA,UAAsCC,EAcvD,WAAAC,CAAYC,GACRC,MAAMD,GAENE,KAAKC,MAAQH,EAAMG,MACnBD,KAAKE,SAAWJ,EAAMI,SACtBF,KAAKG,SAAWL,EAAMK,SACtBH,KAAKI,GAAKN,EAAMM,GAChBJ,KAAKK,MAAQP,EAAMO,MACnBL,KAAKM,EAAIR,EAAMQ,EACfN,KAAKO,EAAIT,EAAMS,EACfP,KAAKQ,EAAIV,EAAMU,CACnB,CAMA,gBAAOC,CAAUC,GACb,GAAqB,IAAjBA,EAAMC,OACN,MAAM,IAAIC,MAAM,eAIpB,MAAMC,EAAmCC,EAAUJ,GAEnD,GAAsB,GAAlBG,EAAQF,OACR,MAAM,IAAIC,MAAM,qCAGpB,OAAO,IAAIjB,EAA8B,CACrCM,MAAOc,EAAkCF,EAAQ,IACjDX,SAAUa,EAAkCF,EAAQ,IACpDV,SAAUY,EAAkCF,EAAQ,IACpDT,GAAIW,EAAkCF,EAAQ,IAC9CR,MAAOU,EAAkCF,EAAQ,IACjDG,SAAUD,EAAkCF,EAAQ,IACpDP,EAAGS,EAAkCF,EAAQ,IAC7CN,EAAGQ,EAAkCF,EAAQ,IAC7CL,EAAGO,EAAkCF,EAAQ,KAErD,CAKA,OAAAI,GACI,OAAOF,EACHG,EAAU,CACNlB,KAAKC,MACLD,KAAKE,SACLF,KAAKG,SACLH,KAAKI,GACLJ,KAAKK,MACLL,KAAKgB,SACLhB,KAAKM,EACLN,KAAKO,EACLP,KAAKQ,IAGjB,CAKA,QAAAW,GACI,OAAOC,KAAKC,UAAUrB,KAAKsB,SAAU,KAAM,EAC/C,CAKA,MAAAA,GACI,MAAO,CACHrB,MAAOsB,EAAWvB,KAAKC,OACvBC,SAAUqB,EAAWvB,KAAKE,UAC1BC,SAAUoB,EAAWvB,KAAKG,UAC1BC,GAAImB,EAAWvB,KAAKI,IACpBC,MAAOkB,EAAWvB,KAAKK,OACvBW,SAAUO,EAAWvB,KAAKgB,UAC1BV,EAAGiB,EAAWvB,KAAKM,GACnBC,EAAGgB,EAAWvB,KAAKO,GACnBC,EAAGe,EAAWvB,KAAKQ,GAE3B,EAGJgB,EAAMC,0CAA2Cf,GAC7Cf,EAA8Bc,UAAUC"}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _bytes = require("@ethersproject/bytes");
7
+ var _ethers = require("ethers");
8
8
  var _cryptography = require("@hiero-ledger/cryptography");
9
9
  var _proto = require("@hiero-ledger/proto");
10
10
  var _Mnemonic = _interopRequireDefault(require("./Mnemonic.cjs"));
@@ -106,7 +106,7 @@ class PrivateKey extends _Key.default {
106
106
  * @returns {PrivateKey}
107
107
  */
108
108
  static fromBytes(data) {
109
- const keyString = (0, _bytes.hexlify)(data);
109
+ const keyString = (0, _ethers.hexlify)(data);
110
110
  if (PrivateKey.isDerKey(keyString)) {
111
111
  if (PrivateKey.getAlgorithm(keyString) === "ecdsa") {
112
112
  return new PrivateKey(_cryptography.PrivateKey.fromBytesECDSA(data));