@arkecosystem/typescript-crypto 0.0.4 → 0.0.5

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 (196) hide show
  1. package/.github/workflows/ci.yml +23 -23
  2. package/.github/workflows/format.yml +80 -0
  3. package/.github/workflows/publish.yml +1 -1
  4. package/.prettierrc.json +8 -0
  5. package/dist/enums/ContractAbiType.d.ts.map +1 -1
  6. package/dist/exceptions/index.d.ts.map +1 -1
  7. package/dist/identities/PrivateKey.d.ts +2 -2
  8. package/dist/identities/PrivateKey.d.ts.map +1 -1
  9. package/dist/identities/PrivateKey.js +1 -1
  10. package/dist/identities/WIF.d.ts.map +1 -1
  11. package/dist/identities/WIF.js +2 -2
  12. package/dist/index.js +532 -627
  13. package/dist/networks/AbstractNetwork.d.ts +1 -1
  14. package/dist/networks/AbstractNetwork.d.ts.map +1 -1
  15. package/dist/networks/Mainnet.d.ts +1 -1
  16. package/dist/networks/Mainnet.d.ts.map +1 -1
  17. package/dist/networks/Mainnet.js +1 -1
  18. package/dist/networks/Testnet.d.ts +1 -1
  19. package/dist/networks/Testnet.d.ts.map +1 -1
  20. package/dist/networks/Testnet.js +1 -1
  21. package/dist/transactions/Deserializer.d.ts +5 -5
  22. package/dist/transactions/Deserializer.d.ts.map +1 -1
  23. package/dist/transactions/Deserializer.js +18 -18
  24. package/dist/transactions/Serializer.d.ts +0 -1
  25. package/dist/transactions/Serializer.d.ts.map +1 -1
  26. package/dist/transactions/Serializer.js +0 -3
  27. package/dist/transactions/builders/AbstractTransactionBuilder.d.ts +7 -6
  28. package/dist/transactions/builders/AbstractTransactionBuilder.d.ts.map +1 -1
  29. package/dist/transactions/builders/AbstractTransactionBuilder.js +15 -8
  30. package/dist/transactions/builders/EvmCallBuilder.d.ts +3 -3
  31. package/dist/transactions/builders/EvmCallBuilder.d.ts.map +1 -1
  32. package/dist/transactions/builders/MultipaymentBuilder.d.ts +5 -4
  33. package/dist/transactions/builders/MultipaymentBuilder.d.ts.map +1 -1
  34. package/dist/transactions/builders/MultipaymentBuilder.js +6 -2
  35. package/dist/transactions/builders/TransferBuilder.d.ts +4 -3
  36. package/dist/transactions/builders/TransferBuilder.d.ts.map +1 -1
  37. package/dist/transactions/builders/TransferBuilder.js +4 -0
  38. package/dist/transactions/builders/UnvoteBuilder.d.ts +3 -3
  39. package/dist/transactions/builders/UnvoteBuilder.d.ts.map +1 -1
  40. package/dist/transactions/builders/UnvoteBuilder.js +1 -1
  41. package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts +3 -3
  42. package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts.map +1 -1
  43. package/dist/transactions/builders/UsernameRegistrationBuilder.js +1 -1
  44. package/dist/transactions/builders/UsernameResignationBuilder.d.ts +3 -3
  45. package/dist/transactions/builders/UsernameResignationBuilder.d.ts.map +1 -1
  46. package/dist/transactions/builders/UsernameResignationBuilder.js +1 -1
  47. package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts +3 -3
  48. package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts.map +1 -1
  49. package/dist/transactions/builders/ValidatorRegistrationBuilder.js +1 -1
  50. package/dist/transactions/builders/ValidatorResignationBuilder.d.ts +3 -3
  51. package/dist/transactions/builders/ValidatorResignationBuilder.d.ts.map +1 -1
  52. package/dist/transactions/builders/ValidatorResignationBuilder.js +1 -1
  53. package/dist/transactions/builders/VoteBuilder.d.ts +3 -3
  54. package/dist/transactions/builders/VoteBuilder.d.ts.map +1 -1
  55. package/dist/transactions/builders/VoteBuilder.js +1 -1
  56. package/dist/transactions/types/AbstractTransaction.d.ts +2 -5
  57. package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -1
  58. package/dist/transactions/types/AbstractTransaction.js +13 -15
  59. package/dist/transactions/types/EvmCall.d.ts +0 -3
  60. package/dist/transactions/types/EvmCall.d.ts.map +1 -1
  61. package/dist/transactions/types/EvmCall.js +0 -8
  62. package/dist/transactions/types/Multipayment.d.ts +1 -3
  63. package/dist/transactions/types/Multipayment.d.ts.map +1 -1
  64. package/dist/transactions/types/Multipayment.js +1 -8
  65. package/dist/transactions/types/Transfer.d.ts +0 -3
  66. package/dist/transactions/types/Transfer.d.ts.map +1 -1
  67. package/dist/transactions/types/Transfer.js +0 -8
  68. package/dist/transactions/types/Unvote.d.ts +0 -3
  69. package/dist/transactions/types/Unvote.d.ts.map +1 -1
  70. package/dist/transactions/types/Unvote.js +0 -8
  71. package/dist/transactions/types/UsernameRegistration.d.ts +1 -3
  72. package/dist/transactions/types/UsernameRegistration.d.ts.map +1 -1
  73. package/dist/transactions/types/UsernameRegistration.js +0 -7
  74. package/dist/transactions/types/UsernameResignation.d.ts +0 -3
  75. package/dist/transactions/types/UsernameResignation.d.ts.map +1 -1
  76. package/dist/transactions/types/UsernameResignation.js +0 -7
  77. package/dist/transactions/types/ValidatorRegistration.d.ts +1 -3
  78. package/dist/transactions/types/ValidatorRegistration.d.ts.map +1 -1
  79. package/dist/transactions/types/ValidatorRegistration.js +0 -8
  80. package/dist/transactions/types/ValidatorResignation.d.ts +0 -3
  81. package/dist/transactions/types/ValidatorResignation.d.ts.map +1 -1
  82. package/dist/transactions/types/ValidatorResignation.js +0 -8
  83. package/dist/transactions/types/Vote.d.ts +1 -3
  84. package/dist/transactions/types/Vote.d.ts.map +1 -1
  85. package/dist/transactions/types/Vote.js +0 -8
  86. package/dist/types.d.ts +19 -19
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/utils/Abi/ArgumentDecoder.js +6 -6
  89. package/dist/utils/Abi/json/Abi.Consensus.json +15 -45
  90. package/dist/utils/Abi/json/Abi.Usernames.json +9 -27
  91. package/dist/utils/AbiDecoder.d.ts.map +1 -1
  92. package/dist/utils/AbiDecoder.js +3 -0
  93. package/dist/utils/AbiEncoder.d.ts +1 -1
  94. package/dist/utils/AbiEncoder.d.ts.map +1 -1
  95. package/dist/utils/AbiEncoder.js +2 -1
  96. package/dist/utils/Message.d.ts +1 -1
  97. package/dist/utils/Message.d.ts.map +1 -1
  98. package/dist/utils/Message.js +1 -1
  99. package/dist/utils/TransactionUtils.d.ts +0 -1
  100. package/dist/utils/TransactionUtils.d.ts.map +1 -1
  101. package/dist/utils/TransactionUtils.js +15 -18
  102. package/dist/utils/UnitConverter.d.ts.map +1 -1
  103. package/dist/utils/UnitConverter.js +12 -12
  104. package/eslint.config.mjs +19 -0
  105. package/jest.config.ts +6 -6
  106. package/package.json +6 -2
  107. package/src/enums/Constants.ts +1 -1
  108. package/src/enums/ContractAbiType.ts +4 -4
  109. package/src/exceptions/index.ts +1 -1
  110. package/src/identities/PrivateKey.ts +3 -3
  111. package/src/identities/WIF.ts +2 -3
  112. package/src/networks/AbstractNetwork.ts +3 -3
  113. package/src/networks/Mainnet.ts +3 -3
  114. package/src/networks/Testnet.ts +1 -1
  115. package/src/transactions/Deserializer.ts +39 -30
  116. package/src/transactions/Serializer.ts +1 -5
  117. package/src/transactions/builders/AbstractTransactionBuilder.ts +20 -11
  118. package/src/transactions/builders/EvmCallBuilder.ts +3 -3
  119. package/src/transactions/builders/MultipaymentBuilder.ts +13 -6
  120. package/src/transactions/builders/TransferBuilder.ts +8 -3
  121. package/src/transactions/builders/UnvoteBuilder.ts +4 -4
  122. package/src/transactions/builders/UsernameRegistrationBuilder.ts +4 -4
  123. package/src/transactions/builders/UsernameResignationBuilder.ts +4 -4
  124. package/src/transactions/builders/ValidatorRegistrationBuilder.ts +4 -4
  125. package/src/transactions/builders/ValidatorResignationBuilder.ts +4 -4
  126. package/src/transactions/builders/VoteBuilder.ts +4 -4
  127. package/src/transactions/types/AbstractTransaction.ts +17 -24
  128. package/src/transactions/types/EvmCall.ts +0 -15
  129. package/src/transactions/types/Multipayment.ts +3 -15
  130. package/src/transactions/types/Transfer.ts +0 -15
  131. package/src/transactions/types/Unvote.ts +0 -15
  132. package/src/transactions/types/UsernameRegistration.ts +1 -13
  133. package/src/transactions/types/UsernameResignation.ts +0 -14
  134. package/src/transactions/types/ValidatorRegistration.ts +1 -14
  135. package/src/transactions/types/ValidatorResignation.ts +0 -15
  136. package/src/transactions/types/Vote.ts +1 -14
  137. package/src/types.ts +19 -19
  138. package/src/utils/Abi/ArgumentDecoder.ts +6 -6
  139. package/src/utils/Abi/json/Abi.Consensus.json +1641 -1671
  140. package/src/utils/Abi/json/Abi.Multipayment.json +108 -108
  141. package/src/utils/Abi/json/Abi.Usernames.json +880 -898
  142. package/src/utils/AbiBase.ts +1 -1
  143. package/src/utils/AbiDecoder.ts +6 -3
  144. package/src/utils/AbiEncoder.ts +3 -2
  145. package/src/utils/Message.ts +1 -1
  146. package/src/utils/TransactionUtils.ts +24 -28
  147. package/src/utils/UnitConverter.ts +29 -29
  148. package/tests/fixtures/global.json +4 -4
  149. package/tests/fixtures/identity.json +10 -10
  150. package/tests/fixtures/transactions/evm-sign.json +4 -4
  151. package/tests/fixtures/transactions/multipayment-empty.json +4 -4
  152. package/tests/fixtures/transactions/multipayment-single.json +4 -4
  153. package/tests/fixtures/transactions/multipayment.json +4 -4
  154. package/tests/fixtures/transactions/transfer-0.json +4 -4
  155. package/tests/fixtures/transactions/transfer-large-amount.json +4 -4
  156. package/tests/fixtures/transactions/transfer.json +4 -4
  157. package/tests/fixtures/transactions/unvote.json +4 -4
  158. package/tests/fixtures/transactions/username-registration.json +4 -4
  159. package/tests/fixtures/transactions/username-resignation.json +4 -4
  160. package/tests/fixtures/transactions/validator-registration.json +4 -4
  161. package/tests/fixtures/transactions/validator-resignation.json +4 -4
  162. package/tests/fixtures/transactions/vote.json +4 -4
  163. package/tests/unit/configuration/Network.test.ts +52 -0
  164. package/tests/unit/identities/Address.test.ts +4 -4
  165. package/tests/unit/identities/PrivateKey.test.ts +5 -5
  166. package/tests/unit/identities/PublicKey.test.ts +9 -9
  167. package/tests/unit/identities/WIF.test.ts +1 -1
  168. package/tests/unit/transactions/Deserializer.test.ts +81 -63
  169. package/tests/unit/transactions/Serializer.test.ts +11 -1
  170. package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +76 -9
  171. package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +125 -17
  172. package/tests/unit/transactions/builders/TransferBuilder.test.ts +146 -47
  173. package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +75 -8
  174. package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +75 -8
  175. package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +75 -8
  176. package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +79 -12
  177. package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +75 -8
  178. package/tests/unit/transactions/builders/VoteBuilder.test.ts +75 -8
  179. package/tests/unit/transactions/types/AbstractTransaction.test.ts +27 -30
  180. package/tests/unit/transactions/types/EvmCall.test.ts +22 -0
  181. package/tests/unit/transactions/types/Multipayment.test.ts +38 -0
  182. package/tests/unit/transactions/types/Transfer.test.ts +18 -0
  183. package/tests/unit/transactions/types/Unvote.test.ts +18 -0
  184. package/tests/unit/transactions/types/UsernameRegistration.test.ts +22 -0
  185. package/tests/unit/transactions/types/UsernameResignation.test.ts +18 -0
  186. package/tests/unit/transactions/types/ValidatorRegistration.test.ts +22 -0
  187. package/tests/unit/transactions/types/ValidatorResignation.test.ts +18 -0
  188. package/tests/unit/transactions/types/Vote.test.ts +20 -0
  189. package/tests/unit/utils/Abi/ArgumentDecoder.test.ts +17 -16
  190. package/tests/unit/utils/AbiEncoder.test.ts +2 -2
  191. package/tests/unit/utils/Message.test.ts +1 -1
  192. package/tests/unit/utils/TransactionUtils.test.ts +1 -5
  193. package/tests/unit/utils/UnitConverter.test.ts +81 -47
  194. package/tsconfig.json +1 -1
  195. package/.eslintrc.js +0 -12
  196. package/prettier.config.js +0 -8
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ var Testnet = class extends AbstractNetwork {
16
16
  epoch() {
17
17
  return "2017-03-21T13:00:00.000Z";
18
18
  }
19
- getWif() {
19
+ wif() {
20
20
  return "ba";
21
21
  }
22
22
  };
@@ -23516,7 +23516,7 @@ var PrivateKey = class _PrivateKey {
23516
23516
  return new _PrivateKey(wallet);
23517
23517
  }
23518
23518
  static fromWif(wif) {
23519
- const decodedWif = decode2(wif, Buffer.from(Network.get().getWif(), "hex").readUInt8());
23519
+ const decodedWif = decode2(wif, Buffer.from(Network.get().wif(), "hex").readUInt8());
23520
23520
  return _PrivateKey.fromHex(Buffer.from(decodedWif.privateKey).toString("hex"));
23521
23521
  }
23522
23522
  async sign(message) {
@@ -23554,7 +23554,7 @@ var WIF = class {
23554
23554
  static fromPassphrase(passphrase) {
23555
23555
  const privateKey = PrivateKey.fromPassphrase(passphrase);
23556
23556
  return encode({
23557
- version: Buffer.from(Network.get().getWif(), "hex").readUInt8(),
23557
+ version: Buffer.from(Network.get().wif(), "hex").readUInt8(),
23558
23558
  privateKey: Buffer.from(privateKey.privateKey, "hex"),
23559
23559
  compressed: true
23560
23560
  });
@@ -23569,195 +23569,11 @@ var Mainnet = class extends AbstractNetwork {
23569
23569
  epoch() {
23570
23570
  return "2017-03-21T13:00:00.000Z";
23571
23571
  }
23572
- getWif() {
23572
+ wif() {
23573
23573
  return "ba";
23574
23574
  }
23575
23575
  };
23576
23576
 
23577
- // src/transactions/builders/AbstractTransactionBuilder.ts
23578
- var AbstractTransactionBuilder = class {
23579
- constructor(data) {
23580
- this.transaction = this.getTransactionInstance(
23581
- data ?? {
23582
- value: "0",
23583
- senderPublicKey: "",
23584
- gasPrice: "5",
23585
- nonce: "1",
23586
- network: Network.get().chainId(),
23587
- gasLimit: 1e6,
23588
- data: ""
23589
- }
23590
- );
23591
- }
23592
- gasLimit(gasLimit) {
23593
- this.transaction.data.gasLimit = gasLimit;
23594
- return this;
23595
- }
23596
- recipientAddress(recipientAddress) {
23597
- this.transaction.data.recipientAddress = recipientAddress;
23598
- return this;
23599
- }
23600
- gasPrice(gasPrice) {
23601
- this.transaction.data.gasPrice = gasPrice;
23602
- return this;
23603
- }
23604
- nonce(nonce) {
23605
- this.transaction.data.nonce = nonce;
23606
- return this;
23607
- }
23608
- network(network) {
23609
- this.transaction.data.network = network;
23610
- return this;
23611
- }
23612
- async sign(passphrase) {
23613
- this.transaction.data.senderPublicKey = PublicKey.fromPassphrase(passphrase).publicKey;
23614
- this.transaction = await this.transaction.sign(PrivateKey.fromPassphrase(passphrase));
23615
- this.transaction.data.id = this.transaction.getId();
23616
- return this;
23617
- }
23618
- verify() {
23619
- return this.transaction.verify();
23620
- }
23621
- toArray() {
23622
- return this.transaction.toArray();
23623
- }
23624
- toJson() {
23625
- return this.transaction.toJson();
23626
- }
23627
- toString() {
23628
- return this.toJson();
23629
- }
23630
- };
23631
-
23632
- // src/utils/TransactionUtils.ts
23633
- var TransactionUtils = class {
23634
- static toBuffer(transaction, skipSignature = false) {
23635
- const fields = [
23636
- toBeArray(transaction["network"] ?? 0),
23637
- toBeArray(transaction["nonce"] ? transaction["nonce"] : 0),
23638
- toBeArray(0),
23639
- toBeArray(transaction["gasPrice"] ?? 0),
23640
- toBeArray(transaction["gasLimit"] ?? 0),
23641
- transaction["recipientAddress"] ?? "0x",
23642
- toBeArray(transaction["value"] ? transaction["value"] : 0),
23643
- transaction["data"] && transaction["data"].startsWith("0x") ? transaction["data"] : "0x" + (transaction["data"] ?? ""),
23644
- []
23645
- ];
23646
- if (!skipSignature && transaction["v"] && transaction["r"] && transaction["s"]) {
23647
- fields.push(toBeArray(transaction["v"] - 27 /* ETHEREUM_RECOVERY_ID_OFFSET */));
23648
- fields.push("0x" + transaction["r"]);
23649
- fields.push("0x" + transaction["s"]);
23650
- }
23651
- const encoded = encodeRlp(fields);
23652
- const payload = "02" /* EIP_1559_PREFIX */ + encoded.substring(2);
23653
- return Buffer.from(payload, "hex");
23654
- }
23655
- static toHash(transaction, skipSignature = false) {
23656
- const encoding = this.toBuffer(transaction, skipSignature);
23657
- return keccak256("0x" + encoding.toString("hex")).substring(2);
23658
- }
23659
- static getId(transaction) {
23660
- return this.toHash(transaction, false);
23661
- }
23662
- };
23663
-
23664
- // src/transactions/Serializer.ts
23665
- var Serializer = class {
23666
- constructor(transaction) {
23667
- this.transaction = transaction;
23668
- }
23669
- static new(transaction) {
23670
- return new this(transaction);
23671
- }
23672
- static getBytes(transaction, skipSignature = false) {
23673
- return transaction.serialize(skipSignature);
23674
- }
23675
- serialize(skipSignature = false) {
23676
- this.transaction.serialized = TransactionUtils.toBuffer(this.transaction.data, skipSignature);
23677
- return this.transaction.serialized;
23678
- }
23679
- };
23680
-
23681
- // src/transactions/types/AbstractTransaction.ts
23682
- var AbstractTransaction = class {
23683
- constructor(data) {
23684
- this.data = { ...data };
23685
- this.refreshPayloadData();
23686
- }
23687
- refreshPayloadData() {
23688
- this.data.data = this.getPayload();
23689
- return this;
23690
- }
23691
- getId() {
23692
- return TransactionUtils.getId(this.data);
23693
- }
23694
- async sign(privateKey) {
23695
- const hash2 = TransactionUtils.toBuffer(this.data, true).toString("hex");
23696
- const signature = await privateKey.sign(hash2);
23697
- this.data["v"] = signature.v;
23698
- this.data["r"] = signature.r;
23699
- this.data["s"] = signature.s;
23700
- return this;
23701
- }
23702
- recoverSender() {
23703
- const publicKey = this.recoverPublicKey();
23704
- this.data["senderPublicKey"] = publicKey.publicKey;
23705
- this.data["senderAddress"] = Address.fromPublicKey(publicKey.publicKey);
23706
- }
23707
- verify() {
23708
- const recoveredPublicKey = this.recoverPublicKey();
23709
- const senderPublicKey = this.data.senderPublicKey;
23710
- if (!senderPublicKey) {
23711
- return false;
23712
- }
23713
- return recoveredPublicKey.publicKey === senderPublicKey;
23714
- }
23715
- toArray() {
23716
- return [
23717
- "gasPrice",
23718
- "network",
23719
- "id",
23720
- "gasLimit",
23721
- "nonce",
23722
- "senderPublicKey",
23723
- "recipientAddress",
23724
- "value",
23725
- "data",
23726
- "r",
23727
- "s",
23728
- "v"
23729
- ].reduce((acc, key) => {
23730
- if (this.data[key] !== void 0) {
23731
- acc[key] = this.data[key];
23732
- }
23733
- return acc;
23734
- }, {});
23735
- }
23736
- toJson() {
23737
- return JSON.stringify(this.toArray());
23738
- }
23739
- hash(skipSignature = false) {
23740
- return TransactionUtils.toHash(this.data, skipSignature);
23741
- }
23742
- serialize(skipSignature = false) {
23743
- return Serializer.new(this).serialize(skipSignature);
23744
- }
23745
- recoverPublicKey() {
23746
- if (!this.data.v || !this.data.r || !this.data.s) {
23747
- throw new Error("Transaction signature is missing");
23748
- }
23749
- return PublicKey.recover(
23750
- Buffer.from(this.hash(true), "hex"),
23751
- BigInt(`0x${this.data.r}`),
23752
- BigInt(`0x${this.data.s}`),
23753
- this.data.v - 27 /* ETHEREUM_RECOVERY_ID_OFFSET */
23754
- );
23755
- }
23756
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
23757
- throw new Error("Method not implemented.");
23758
- }
23759
- };
23760
-
23761
23577
  // node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
23762
23578
  var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
23763
23579
  var mathceil = Math.ceil;
@@ -25102,86 +24918,311 @@ function toFixedPoint(str, e, z) {
25102
24918
  var BigNumber = clone();
25103
24919
  var bignumber_default = BigNumber;
25104
24920
 
25105
- // src/transactions/types/Transfer.ts
25106
- var Transfer = class extends AbstractTransaction {
25107
- getPayload() {
25108
- return "";
24921
+ // src/transactions/builders/AbstractTransactionBuilder.ts
24922
+ var AbstractTransactionBuilder = class {
24923
+ constructor(data) {
24924
+ this.transaction = this.getTransactionInstance(
24925
+ data ?? {
24926
+ value: "0",
24927
+ senderPublicKey: "",
24928
+ gasPrice: "5",
24929
+ nonce: "1",
24930
+ network: Network.get().chainId(),
24931
+ gas: 1e6,
24932
+ data: ""
24933
+ }
24934
+ );
25109
24935
  }
25110
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
25111
- if (!data["data"]) {
25112
- return null;
24936
+ gas(gas) {
24937
+ if (gas instanceof bignumber_default) {
24938
+ gas = gas.toFixed();
25113
24939
  }
25114
- return Deserializer.decodePayload(data, type);
24940
+ this.transaction.data.gas = gas;
24941
+ return this;
24942
+ }
24943
+ to(to) {
24944
+ this.transaction.data.to = to;
24945
+ return this;
24946
+ }
24947
+ gasPrice(gasPrice) {
24948
+ if (gasPrice instanceof bignumber_default) {
24949
+ gasPrice = gasPrice.toFixed();
24950
+ }
24951
+ this.transaction.data.gasPrice = gasPrice;
24952
+ return this;
24953
+ }
24954
+ nonce(nonce) {
24955
+ this.transaction.data.nonce = nonce;
24956
+ return this;
24957
+ }
24958
+ network(network) {
24959
+ this.transaction.data.network = network;
24960
+ return this;
24961
+ }
24962
+ async sign(passphrase) {
24963
+ this.transaction.data.senderPublicKey = PublicKey.fromPassphrase(passphrase).publicKey;
24964
+ this.transaction = await this.transaction.sign(PrivateKey.fromPassphrase(passphrase));
24965
+ this.transaction.data.hash = this.transaction.hash();
24966
+ return this;
24967
+ }
24968
+ verify() {
24969
+ return this.transaction.verify();
24970
+ }
24971
+ toObject() {
24972
+ return this.transaction.toObject();
24973
+ }
24974
+ toJson() {
24975
+ return this.transaction.toJson();
24976
+ }
24977
+ toString() {
24978
+ return this.toJson();
25115
24979
  }
25116
24980
  };
25117
24981
 
25118
- // src/utils/Abi/json/Abi.Consensus.json
25119
- var Abi_Consensus_default = {
25120
- abi: [
25121
- {
25122
- type: "function",
25123
- name: "UPGRADE_INTERFACE_VERSION",
25124
- inputs: [],
25125
- outputs: [
25126
- { name: "", type: "string", internalType: "string" }
25127
- ],
25128
- stateMutability: "view"
25129
- },
25130
- {
25131
- type: "function",
25132
- name: "activeValidatorsCount",
25133
- inputs: [],
25134
- outputs: [
25135
- { name: "", type: "uint256", internalType: "uint256" }
25136
- ],
25137
- stateMutability: "view"
25138
- },
25139
- {
25140
- type: "function",
25141
- name: "addValidator",
25142
- inputs: [
25143
- {
25144
- name: "addr",
25145
- type: "address",
25146
- internalType: "address"
25147
- },
25148
- {
25149
- name: "blsPublicKey",
25150
- type: "bytes",
25151
- internalType: "bytes"
25152
- },
25153
- { name: "isResigned", type: "bool", internalType: "bool" }
25154
- ],
25155
- outputs: [],
25156
- stateMutability: "nonpayable"
25157
- },
25158
- {
25159
- type: "function",
25160
- name: "addVote",
25161
- inputs: [
25162
- {
25163
- name: "voter",
25164
- type: "address",
25165
- internalType: "address"
25166
- },
25167
- {
25168
- name: "validator",
24982
+ // src/utils/TransactionUtils.ts
24983
+ var TransactionUtils = class {
24984
+ static toBuffer(transaction, skipSignature = false) {
24985
+ const fields = [
24986
+ toBeArray(transaction["network"] ?? 0),
24987
+ toBeArray(transaction["nonce"] ? transaction["nonce"] : 0),
24988
+ toBeArray(0),
24989
+ toBeArray(transaction["gasPrice"] ?? 0),
24990
+ toBeArray(transaction["gas"] ?? 0),
24991
+ transaction["to"] ?? "0x",
24992
+ toBeArray(transaction["value"] ? transaction["value"] : 0),
24993
+ transaction["data"] && transaction["data"].startsWith("0x") ? transaction["data"] : "0x" + (transaction["data"] ?? ""),
24994
+ []
24995
+ ];
24996
+ if (!skipSignature && transaction["v"] && transaction["r"] && transaction["s"]) {
24997
+ fields.push(toBeArray(transaction["v"] - 27 /* ETHEREUM_RECOVERY_ID_OFFSET */));
24998
+ fields.push("0x" + transaction["r"]);
24999
+ fields.push("0x" + transaction["s"]);
25000
+ }
25001
+ const encoded = encodeRlp(fields);
25002
+ const payload = "02" /* EIP_1559_PREFIX */ + encoded.substring(2);
25003
+ return Buffer.from(payload, "hex");
25004
+ }
25005
+ static toHash(transaction, skipSignature = false) {
25006
+ const encoding = this.toBuffer(transaction, skipSignature);
25007
+ return keccak256("0x" + encoding.toString("hex")).substring(2);
25008
+ }
25009
+ };
25010
+
25011
+ // src/transactions/Serializer.ts
25012
+ var Serializer = class {
25013
+ constructor(transaction) {
25014
+ this.transaction = transaction;
25015
+ }
25016
+ static new(transaction) {
25017
+ return new this(transaction);
25018
+ }
25019
+ serialize(skipSignature = false) {
25020
+ this.transaction.serialized = TransactionUtils.toBuffer(this.transaction.data, skipSignature);
25021
+ return this.transaction.serialized;
25022
+ }
25023
+ };
25024
+
25025
+ // src/transactions/types/AbstractTransaction.ts
25026
+ var AbstractTransaction = class {
25027
+ constructor(data) {
25028
+ this.data = { ...data };
25029
+ this.refreshPayloadData();
25030
+ }
25031
+ refreshPayloadData() {
25032
+ this.data.data = this.getPayload();
25033
+ return this;
25034
+ }
25035
+ async sign(privateKey) {
25036
+ const hash2 = TransactionUtils.toBuffer(this.data, true).toString("hex");
25037
+ const signature = await privateKey.sign(hash2);
25038
+ this.data["v"] = signature.v;
25039
+ this.data["r"] = signature.r;
25040
+ this.data["s"] = signature.s;
25041
+ return this;
25042
+ }
25043
+ recoverSender() {
25044
+ const publicKey = this.recoverPublicKey();
25045
+ this.data["senderPublicKey"] = publicKey.publicKey;
25046
+ this.data["from"] = Address.fromPublicKey(publicKey.publicKey);
25047
+ }
25048
+ verify() {
25049
+ const recoveredPublicKey = this.recoverPublicKey();
25050
+ const senderPublicKey = this.data.senderPublicKey;
25051
+ if (!senderPublicKey) {
25052
+ return false;
25053
+ }
25054
+ return recoveredPublicKey.publicKey === senderPublicKey;
25055
+ }
25056
+ toObject() {
25057
+ return [
25058
+ "gasPrice",
25059
+ "network",
25060
+ "hash",
25061
+ "gas",
25062
+ "nonce",
25063
+ "senderPublicKey",
25064
+ "to",
25065
+ "value",
25066
+ "data",
25067
+ "r",
25068
+ "s",
25069
+ "v"
25070
+ ].reduce((acc, key) => {
25071
+ let value = this.data[key];
25072
+ if (typeof value === "bigint") {
25073
+ value = bignumber_default(value).toFixed();
25074
+ }
25075
+ if (value !== void 0) {
25076
+ acc[key] = value;
25077
+ }
25078
+ return acc;
25079
+ }, {});
25080
+ }
25081
+ toJson() {
25082
+ return JSON.stringify(this.toObject());
25083
+ }
25084
+ hash(skipSignature = false) {
25085
+ return TransactionUtils.toHash(this.data, skipSignature);
25086
+ }
25087
+ serialize(skipSignature = false) {
25088
+ return Serializer.new(this).serialize(skipSignature);
25089
+ }
25090
+ recoverPublicKey() {
25091
+ if (!this.data.v || !this.data.r || !this.data.s) {
25092
+ throw new Error("Transaction signature is missing");
25093
+ }
25094
+ return PublicKey.recover(
25095
+ Buffer.from(this.hash(true), "hex"),
25096
+ BigInt(`0x${this.data.r}`),
25097
+ BigInt(`0x${this.data.s}`),
25098
+ this.data.v - 27 /* ETHEREUM_RECOVERY_ID_OFFSET */
25099
+ );
25100
+ }
25101
+ };
25102
+
25103
+ // src/transactions/types/EvmCall.ts
25104
+ var EvmCall = class extends AbstractTransaction {
25105
+ getPayload() {
25106
+ return this.data["data"] || "";
25107
+ }
25108
+ };
25109
+
25110
+ // src/utils/Helpers.ts
25111
+ var Helpers = class {
25112
+ /**
25113
+ * Validates a username based on specific rules.
25114
+ * Based on https://github.com/ArkEcosystem/mainsail/blob/develop/contracts/src/usernames/UsernamesV1.sol#L101
25115
+ *
25116
+ * @param username The username to validate
25117
+ * @returns true if the username is valid
25118
+ * @throws InvalidUsernameException if the username is invalid
25119
+ */
25120
+ static isValidUsername(username) {
25121
+ if (username.length < 1 || username.length > 20) {
25122
+ throw new InvalidUsernameException(
25123
+ `Username must be between 1 and 20 characters long. Got ${username.length} characters.`
25124
+ );
25125
+ }
25126
+ if (/[^a-z0-9_]/.test(username)) {
25127
+ throw new InvalidUsernameException("Username can only contain lowercase letters, numbers and underscores.");
25128
+ }
25129
+ if (/^_|_$/.test(username)) {
25130
+ throw new InvalidUsernameException("Username cannot start or end with an underscore.");
25131
+ }
25132
+ if (/__/.test(username)) {
25133
+ throw new InvalidUsernameException("Username cannot contain consecutive underscores.");
25134
+ }
25135
+ return true;
25136
+ }
25137
+ /**
25138
+ * Removes the leading '0x' from a hex string.
25139
+ *
25140
+ * @param hex The hex string to process
25141
+ * @returns The hex string without the leading '0x'
25142
+ */
25143
+ static removeLeadingHexZero(hex) {
25144
+ return hex.replace(/^0x/, "");
25145
+ }
25146
+ };
25147
+
25148
+ // src/transactions/builders/EvmCallBuilder.ts
25149
+ var EvmCallBuilder = class extends AbstractTransactionBuilder {
25150
+ constructor(data) {
25151
+ super(data);
25152
+ }
25153
+ static new(data) {
25154
+ return new this(data);
25155
+ }
25156
+ payload(payload) {
25157
+ this.transaction.data["data"] = Helpers.removeLeadingHexZero(payload);
25158
+ return this;
25159
+ }
25160
+ getTransactionInstance(data) {
25161
+ return new EvmCall(data);
25162
+ }
25163
+ };
25164
+
25165
+ // src/utils/Abi/json/Abi.Consensus.json
25166
+ var Abi_Consensus_default = {
25167
+ abi: [
25168
+ {
25169
+ type: "function",
25170
+ name: "UPGRADE_INTERFACE_VERSION",
25171
+ inputs: [],
25172
+ outputs: [{ name: "", type: "string", internalType: "string" }],
25173
+ stateMutability: "view"
25174
+ },
25175
+ {
25176
+ type: "function",
25177
+ name: "activeValidatorsCount",
25178
+ inputs: [],
25179
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
25180
+ stateMutability: "view"
25181
+ },
25182
+ {
25183
+ type: "function",
25184
+ name: "addValidator",
25185
+ inputs: [
25186
+ {
25187
+ name: "addr",
25169
25188
  type: "address",
25170
25189
  internalType: "address"
25171
- }
25190
+ },
25191
+ {
25192
+ name: "blsPublicKey",
25193
+ type: "bytes",
25194
+ internalType: "bytes"
25195
+ },
25196
+ { name: "isResigned", type: "bool", internalType: "bool" }
25172
25197
  ],
25173
25198
  outputs: [],
25174
25199
  stateMutability: "nonpayable"
25175
25200
  },
25176
25201
  {
25177
25202
  type: "function",
25178
- name: "calculateActiveValidators",
25203
+ name: "addVote",
25179
25204
  inputs: [
25180
- { name: "n", type: "uint8", internalType: "uint8" }
25205
+ {
25206
+ name: "voter",
25207
+ type: "address",
25208
+ internalType: "address"
25209
+ },
25210
+ {
25211
+ name: "validator",
25212
+ type: "address",
25213
+ internalType: "address"
25214
+ }
25181
25215
  ],
25182
25216
  outputs: [],
25183
25217
  stateMutability: "nonpayable"
25184
25218
  },
25219
+ {
25220
+ type: "function",
25221
+ name: "calculateActiveValidators",
25222
+ inputs: [{ name: "n", type: "uint8", internalType: "uint8" }],
25223
+ outputs: [],
25224
+ stateMutability: "nonpayable"
25225
+ },
25185
25226
  {
25186
25227
  type: "function",
25187
25228
  name: "getActiveValidators",
@@ -25328,17 +25369,13 @@ var Abi_Consensus_default = {
25328
25369
  type: "function",
25329
25370
  name: "getRoundsCount",
25330
25371
  inputs: [],
25331
- outputs: [
25332
- { name: "", type: "uint256", internalType: "uint256" }
25333
- ],
25372
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
25334
25373
  stateMutability: "view"
25335
25374
  },
25336
25375
  {
25337
25376
  type: "function",
25338
25377
  name: "getValidator",
25339
- inputs: [
25340
- { name: "addr", type: "address", internalType: "address" }
25341
- ],
25378
+ inputs: [{ name: "addr", type: "address", internalType: "address" }],
25342
25379
  outputs: [
25343
25380
  {
25344
25381
  name: "",
@@ -25422,9 +25459,7 @@ var Abi_Consensus_default = {
25422
25459
  type: "function",
25423
25460
  name: "getVotesCount",
25424
25461
  inputs: [],
25425
- outputs: [
25426
- { name: "", type: "uint256", internalType: "uint256" }
25427
- ],
25462
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
25428
25463
  stateMutability: "view"
25429
25464
  },
25430
25465
  {
@@ -25437,9 +25472,7 @@ var Abi_Consensus_default = {
25437
25472
  {
25438
25473
  type: "function",
25439
25474
  name: "isValidatorRegistered",
25440
- inputs: [
25441
- { name: "addr", type: "address", internalType: "address" }
25442
- ],
25475
+ inputs: [{ name: "addr", type: "address", internalType: "address" }],
25443
25476
  outputs: [{ name: "", type: "bool", internalType: "bool" }],
25444
25477
  stateMutability: "view"
25445
25478
  },
@@ -25447,18 +25480,14 @@ var Abi_Consensus_default = {
25447
25480
  type: "function",
25448
25481
  name: "owner",
25449
25482
  inputs: [],
25450
- outputs: [
25451
- { name: "", type: "address", internalType: "address" }
25452
- ],
25483
+ outputs: [{ name: "", type: "address", internalType: "address" }],
25453
25484
  stateMutability: "view"
25454
25485
  },
25455
25486
  {
25456
25487
  type: "function",
25457
25488
  name: "proxiableUUID",
25458
25489
  inputs: [],
25459
- outputs: [
25460
- { name: "", type: "bytes32", internalType: "bytes32" }
25461
- ],
25490
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
25462
25491
  stateMutability: "view"
25463
25492
  },
25464
25493
  {
@@ -25478,9 +25507,7 @@ var Abi_Consensus_default = {
25478
25507
  type: "function",
25479
25508
  name: "registeredValidatorsCount",
25480
25509
  inputs: [],
25481
- outputs: [
25482
- { name: "", type: "uint256", internalType: "uint256" }
25483
- ],
25510
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
25484
25511
  stateMutability: "view"
25485
25512
  },
25486
25513
  {
@@ -25501,9 +25528,7 @@ var Abi_Consensus_default = {
25501
25528
  type: "function",
25502
25529
  name: "resignedValidatorsCount",
25503
25530
  inputs: [],
25504
- outputs: [
25505
- { name: "", type: "uint256", internalType: "uint256" }
25506
- ],
25531
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
25507
25532
  stateMutability: "view"
25508
25533
  },
25509
25534
  {
@@ -25570,17 +25595,13 @@ var Abi_Consensus_default = {
25570
25595
  type: "function",
25571
25596
  name: "version",
25572
25597
  inputs: [],
25573
- outputs: [
25574
- { name: "", type: "uint256", internalType: "uint256" }
25575
- ],
25598
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
25576
25599
  stateMutability: "pure"
25577
25600
  },
25578
25601
  {
25579
25602
  type: "function",
25580
25603
  name: "vote",
25581
- inputs: [
25582
- { name: "addr", type: "address", internalType: "address" }
25583
- ],
25604
+ inputs: [{ name: "addr", type: "address", internalType: "address" }],
25584
25605
  outputs: [],
25585
25606
  stateMutability: "nonpayable"
25586
25607
  },
@@ -25791,9 +25812,7 @@ var Abi_Consensus_default = {
25791
25812
  {
25792
25813
  type: "error",
25793
25814
  name: "UUPSUnsupportedProxiableUUID",
25794
- inputs: [
25795
- { name: "slot", type: "bytes32", internalType: "bytes32" }
25796
- ]
25815
+ inputs: [{ name: "slot", type: "bytes32", internalType: "bytes32" }]
25797
25816
  },
25798
25817
  { type: "error", name: "ValidatorAlreadyRegistered", inputs: [] },
25799
25818
  { type: "error", name: "ValidatorAlreadyResigned", inputs: [] },
@@ -26475,9 +26494,7 @@ var Abi_Consensus_default = {
26475
26494
  stateMutability: "view",
26476
26495
  type: "function",
26477
26496
  name: "isValidatorRegistered",
26478
- outputs: [
26479
- { internalType: "bool", name: "", type: "bool" }
26480
- ]
26497
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
26481
26498
  },
26482
26499
  {
26483
26500
  inputs: [],
@@ -26909,9 +26926,7 @@ var Abi_Usernames_default = {
26909
26926
  type: "function",
26910
26927
  name: "UPGRADE_INTERFACE_VERSION",
26911
26928
  inputs: [],
26912
- outputs: [
26913
- { name: "", type: "string", internalType: "string" }
26914
- ],
26929
+ outputs: [{ name: "", type: "string", internalType: "string" }],
26915
26930
  stateMutability: "view"
26916
26931
  },
26917
26932
  {
@@ -26935,12 +26950,8 @@ var Abi_Usernames_default = {
26935
26950
  {
26936
26951
  type: "function",
26937
26952
  name: "getUsername",
26938
- inputs: [
26939
- { name: "user", type: "address", internalType: "address" }
26940
- ],
26941
- outputs: [
26942
- { name: "", type: "string", internalType: "string" }
26943
- ],
26953
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
26954
+ outputs: [{ name: "", type: "string", internalType: "string" }],
26944
26955
  stateMutability: "view"
26945
26956
  },
26946
26957
  {
@@ -27011,18 +27022,14 @@ var Abi_Usernames_default = {
27011
27022
  type: "function",
27012
27023
  name: "owner",
27013
27024
  inputs: [],
27014
- outputs: [
27015
- { name: "", type: "address", internalType: "address" }
27016
- ],
27025
+ outputs: [{ name: "", type: "address", internalType: "address" }],
27017
27026
  stateMutability: "view"
27018
27027
  },
27019
27028
  {
27020
27029
  type: "function",
27021
27030
  name: "proxiableUUID",
27022
27031
  inputs: [],
27023
- outputs: [
27024
- { name: "", type: "bytes32", internalType: "bytes32" }
27025
- ],
27032
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
27026
27033
  stateMutability: "view"
27027
27034
  },
27028
27035
  {
@@ -27083,9 +27090,7 @@ var Abi_Usernames_default = {
27083
27090
  type: "function",
27084
27091
  name: "version",
27085
27092
  inputs: [],
27086
- outputs: [
27087
- { name: "", type: "uint256", internalType: "uint256" }
27088
- ],
27093
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
27089
27094
  stateMutability: "pure"
27090
27095
  },
27091
27096
  {
@@ -27235,9 +27240,7 @@ var Abi_Usernames_default = {
27235
27240
  {
27236
27241
  type: "error",
27237
27242
  name: "UUPSUnsupportedProxiableUUID",
27238
- inputs: [
27239
- { name: "slot", type: "bytes32", internalType: "bytes32" }
27240
- ]
27243
+ inputs: [{ name: "slot", type: "bytes32", internalType: "bytes32" }]
27241
27244
  },
27242
27245
  { type: "error", name: "UsernameNotRegistered", inputs: [] }
27243
27246
  ],
@@ -27542,9 +27545,7 @@ var Abi_Usernames_default = {
27542
27545
  stateMutability: "view",
27543
27546
  type: "function",
27544
27547
  name: "isUsernameRegistered",
27545
- outputs: [
27546
- { internalType: "bool", name: "", type: "bool" }
27547
- ]
27548
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
27548
27549
  },
27549
27550
  {
27550
27551
  inputs: [
@@ -27557,9 +27558,7 @@ var Abi_Usernames_default = {
27557
27558
  stateMutability: "pure",
27558
27559
  type: "function",
27559
27560
  name: "isUsernameValid",
27560
- outputs: [
27561
- { internalType: "bool", name: "", type: "bool" }
27562
- ]
27561
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
27563
27562
  },
27564
27563
  {
27565
27564
  inputs: [],
@@ -27834,6 +27833,9 @@ var AbiDecoder = class extends AbiBase {
27834
27833
  }
27835
27834
  const functionSelector = data.slice(0, 10);
27836
27835
  const functionFragment = this.interface.getFunction(functionSelector);
27836
+ if (!functionFragment) {
27837
+ throw new Error("Function not found in ABI");
27838
+ }
27837
27839
  return {
27838
27840
  functionName: functionFragment.name,
27839
27841
  args: this.interface.decodeFunctionData(functionFragment, data)
@@ -27844,7 +27846,7 @@ var AbiDecoder = class extends AbiBase {
27844
27846
  // src/utils/AbiEncoder.ts
27845
27847
  var AbiEncoder = class extends AbiBase {
27846
27848
  encodeFunctionCall(functionName, parameters) {
27847
- return this.interface.encodeFunctionData(functionName, parameters);
27849
+ return Helpers.removeLeadingHexZero(this.interface.encodeFunctionData(functionName, parameters));
27848
27850
  }
27849
27851
  };
27850
27852
 
@@ -27867,7 +27869,7 @@ var Multipayment = class extends AbstractTransaction {
27867
27869
  super(data);
27868
27870
  }
27869
27871
  getPayload() {
27870
- if (!this.data["pay"]) {
27872
+ if (!this.data["pay"] || Array.isArray(this.data["pay"]) && this.data["pay"].length === 0) {
27871
27873
  return "";
27872
27874
  }
27873
27875
  return new AbiEncoder("multipayment" /* MULTIPAYMENT */).encodeFunctionCall(
@@ -27875,111 +27877,82 @@ var Multipayment = class extends AbstractTransaction {
27875
27877
  this.data["pay"]
27876
27878
  );
27877
27879
  }
27878
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
27879
- if (!data["data"]) {
27880
- return null;
27881
- }
27882
- return Deserializer.decodePayload(data, "multipayment" /* MULTIPAYMENT */);
27883
- }
27884
- };
27885
-
27886
- // src/transactions/types/Unvote.ts
27887
- var Unvote = class extends AbstractTransaction {
27888
- getPayload() {
27889
- return new AbiEncoder().encodeFunctionCall("unvote" /* UNVOTE */, []);
27890
- }
27891
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
27892
- if (!data["data"]) {
27893
- return null;
27894
- }
27895
- return Deserializer.decodePayload(data, type);
27896
- }
27897
27880
  };
27898
27881
 
27899
- // src/transactions/types/ValidatorRegistration.ts
27900
- var ValidatorRegistration = class extends AbstractTransaction {
27882
+ // src/transactions/builders/MultipaymentBuilder.ts
27883
+ var MultipaymentBuilder = class extends AbstractTransactionBuilder {
27901
27884
  constructor(data) {
27902
- let payload;
27903
- if (!data["data"] || data["data"] === "") {
27904
- payload = null;
27905
- } else {
27906
- payload = new AbiDecoder().decodeFunctionData(data["data"]);
27907
- }
27908
- data["validatorPublicKey"] = payload ? payload.args[0] : null;
27909
27885
  super(data);
27886
+ this.to("0x00EFd0D4639191C49908A7BddbB9A11A994A8527" /* MULTIPAYMENT */);
27910
27887
  }
27911
- getPayload() {
27912
- if (!this.data["validatorPublicKey"]) {
27913
- return "";
27914
- }
27915
- return new AbiEncoder().encodeFunctionCall("registerValidator" /* VALIDATOR_REGISTRATION */, [
27916
- this.data["validatorPublicKey"]
27917
- ]);
27888
+ static new(data) {
27889
+ return new this(data);
27918
27890
  }
27919
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
27920
- if (!data["data"]) {
27921
- return null;
27891
+ pay(address, amount) {
27892
+ const payload = this.transaction.data["pay"];
27893
+ payload[0].push(address);
27894
+ if (amount instanceof bignumber_default) {
27895
+ amount = amount.toFixed();
27922
27896
  }
27923
- return Deserializer.decodePayload(data, type);
27897
+ payload[1].push(amount);
27898
+ this.transaction.data.pay = payload;
27899
+ this.transaction.data.value = (BigInt(this.transaction.data.value ?? 0) + BigInt(amount)).toString();
27900
+ this.transaction.refreshPayloadData();
27901
+ return this;
27902
+ }
27903
+ getTransactionInstance(data) {
27904
+ return new Multipayment(data);
27924
27905
  }
27925
27906
  };
27926
27907
 
27927
- // src/transactions/types/ValidatorResignation.ts
27928
- var ValidatorResignation = class extends AbstractTransaction {
27908
+ // src/transactions/types/Transfer.ts
27909
+ var Transfer = class extends AbstractTransaction {
27929
27910
  getPayload() {
27930
- return new AbiEncoder().encodeFunctionCall("resignValidator" /* VALIDATOR_RESIGNATION */, []);
27931
- }
27932
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
27933
- if (!data["data"]) {
27934
- return null;
27935
- }
27936
- return Deserializer.decodePayload(data, type);
27911
+ return "";
27937
27912
  }
27938
27913
  };
27939
27914
 
27940
- // src/transactions/types/UsernameRegistration.ts
27941
- var UsernameRegistration = class extends AbstractTransaction {
27942
- constructor(data) {
27943
- let payload;
27944
- if (!data["data"] || data["data"] === "") {
27945
- payload = null;
27946
- } else {
27947
- payload = new AbiDecoder("usernames" /* USERNAMES */).decodeFunctionData(data["data"]);
27948
- }
27949
- data["username"] = payload ? payload.args[0] : null;
27950
- super(data);
27915
+ // src/transactions/builders/TransferBuilder.ts
27916
+ var TransferBuilder = class extends AbstractTransactionBuilder {
27917
+ static new(data) {
27918
+ return new this(data);
27951
27919
  }
27952
- getPayload() {
27953
- if (!this.data["username"]) {
27954
- return "";
27920
+ value(value) {
27921
+ if (value instanceof bignumber_default) {
27922
+ value = value.toFixed();
27955
27923
  }
27956
- return new AbiEncoder("usernames" /* USERNAMES */).encodeFunctionCall("registerUsername" /* USERNAME_REGISTRATION */, [
27957
- this.data["username"]
27958
- ]);
27924
+ this.transaction.data.value = value;
27925
+ this.transaction.refreshPayloadData();
27926
+ return this;
27959
27927
  }
27960
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
27961
- if (!data["data"]) {
27962
- return null;
27963
- }
27964
- return Deserializer.decodePayload(data, "usernames" /* USERNAMES */);
27928
+ getTransactionInstance(data) {
27929
+ return new Transfer(data);
27965
27930
  }
27966
27931
  };
27967
27932
 
27968
- // src/transactions/types/UsernameResignation.ts
27969
- var UsernameResignation = class extends AbstractTransaction {
27933
+ // src/transactions/types/Unvote.ts
27934
+ var Unvote = class extends AbstractTransaction {
27970
27935
  getPayload() {
27971
- return new AbiEncoder("usernames" /* USERNAMES */).encodeFunctionCall("resignUsername" /* USERNAME_RESIGNATION */, []);
27936
+ return new AbiEncoder().encodeFunctionCall("unvote" /* UNVOTE */, []);
27972
27937
  }
27973
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
27974
- if (!data["data"]) {
27975
- return null;
27976
- }
27977
- return Deserializer.decodePayload(data, "usernames" /* USERNAMES */);
27938
+ };
27939
+
27940
+ // src/transactions/builders/UnvoteBuilder.ts
27941
+ var UnvoteBuilder = class extends AbstractTransactionBuilder {
27942
+ constructor(data) {
27943
+ super(data);
27944
+ this.to("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
27945
+ }
27946
+ static new(data) {
27947
+ return new this(data);
27948
+ }
27949
+ getTransactionInstance(data) {
27950
+ return new Unvote(data);
27978
27951
  }
27979
27952
  };
27980
27953
 
27981
- // src/transactions/types/Vote.ts
27982
- var Vote = class extends AbstractTransaction {
27954
+ // src/transactions/types/ValidatorRegistration.ts
27955
+ var ValidatorRegistration = class extends AbstractTransaction {
27983
27956
  constructor(data) {
27984
27957
  let payload;
27985
27958
  if (!data["data"] || data["data"] === "") {
@@ -27987,58 +27960,16 @@ var Vote = class extends AbstractTransaction {
27987
27960
  } else {
27988
27961
  payload = new AbiDecoder().decodeFunctionData(data["data"]);
27989
27962
  }
27990
- data["vote"] = payload ? payload.args[0] : null;
27963
+ data["validatorPublicKey"] = payload ? payload.args[0] : null;
27991
27964
  super(data);
27992
27965
  }
27993
27966
  getPayload() {
27994
- if (!this.data["vote"]) {
27967
+ if (!this.data["validatorPublicKey"]) {
27995
27968
  return "";
27996
27969
  }
27997
- return new AbiEncoder().encodeFunctionCall("vote" /* VOTE */, [this.data["vote"]]);
27998
- }
27999
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
28000
- if (!data["data"]) {
28001
- return null;
28002
- }
28003
- return Deserializer.decodePayload(data, type);
28004
- }
28005
- };
28006
-
28007
- // src/utils/Helpers.ts
28008
- var Helpers = class {
28009
- /**
28010
- * Validates a username based on specific rules.
28011
- * Based on https://github.com/ArkEcosystem/mainsail/blob/develop/contracts/src/usernames/UsernamesV1.sol#L101
28012
- *
28013
- * @param username The username to validate
28014
- * @returns true if the username is valid
28015
- * @throws InvalidUsernameException if the username is invalid
28016
- */
28017
- static isValidUsername(username) {
28018
- if (username.length < 1 || username.length > 20) {
28019
- throw new InvalidUsernameException(
28020
- `Username must be between 1 and 20 characters long. Got ${username.length} characters.`
28021
- );
28022
- }
28023
- if (/[^a-z0-9_]/.test(username)) {
28024
- throw new InvalidUsernameException("Username can only contain lowercase letters, numbers and underscores.");
28025
- }
28026
- if (/^_|_$/.test(username)) {
28027
- throw new InvalidUsernameException("Username cannot start or end with an underscore.");
28028
- }
28029
- if (/__/.test(username)) {
28030
- throw new InvalidUsernameException("Username cannot contain consecutive underscores.");
28031
- }
28032
- return true;
28033
- }
28034
- /**
28035
- * Removes the leading '0x' from a hex string.
28036
- *
28037
- * @param hex The hex string to process
28038
- * @returns The hex string without the leading '0x'
28039
- */
28040
- static removeLeadingHexZero(hex) {
28041
- return hex.replace(/^0x/, "");
27970
+ return new AbiEncoder().encodeFunctionCall("registerValidator" /* VALIDATOR_REGISTRATION */, [
27971
+ this.data["validatorPublicKey"]
27972
+ ]);
28042
27973
  }
28043
27974
  };
28044
27975
 
@@ -28071,7 +28002,7 @@ var Message = class _Message {
28071
28002
  toString() {
28072
28003
  return JSON.stringify(this.toJson());
28073
28004
  }
28074
- toArray() {
28005
+ toObject() {
28075
28006
  return [this.publicKey, this.signature, this.message];
28076
28007
  }
28077
28008
  toJson() {
@@ -28138,6 +28069,149 @@ var UnitConverter = class {
28138
28069
  }
28139
28070
  };
28140
28071
 
28072
+ // src/transactions/builders/ValidatorRegistrationBuilder.ts
28073
+ var ValidatorRegistrationBuilder = class extends AbstractTransactionBuilder {
28074
+ constructor(data) {
28075
+ super(data);
28076
+ this.to("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28077
+ }
28078
+ static new(data) {
28079
+ return new this(data);
28080
+ }
28081
+ validatorPublicKey(validatorPublicKey) {
28082
+ validatorPublicKey = Helpers.removeLeadingHexZero(validatorPublicKey);
28083
+ this.transaction.data.validatorPublicKey = `0x${validatorPublicKey}`;
28084
+ this.transaction.refreshPayloadData();
28085
+ return this;
28086
+ }
28087
+ getTransactionInstance(data) {
28088
+ return new ValidatorRegistration(data);
28089
+ }
28090
+ };
28091
+
28092
+ // src/transactions/types/ValidatorResignation.ts
28093
+ var ValidatorResignation = class extends AbstractTransaction {
28094
+ getPayload() {
28095
+ return new AbiEncoder().encodeFunctionCall("resignValidator" /* VALIDATOR_RESIGNATION */, []);
28096
+ }
28097
+ };
28098
+
28099
+ // src/transactions/builders/ValidatorResignationBuilder.ts
28100
+ var ValidatorResignationBuilder = class extends AbstractTransactionBuilder {
28101
+ constructor(data) {
28102
+ super(data);
28103
+ this.to("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28104
+ }
28105
+ static new(data) {
28106
+ return new this(data);
28107
+ }
28108
+ getTransactionInstance(data) {
28109
+ return new ValidatorResignation(data);
28110
+ }
28111
+ };
28112
+
28113
+ // src/transactions/types/UsernameRegistration.ts
28114
+ var UsernameRegistration = class extends AbstractTransaction {
28115
+ constructor(data) {
28116
+ let payload;
28117
+ if (!data["data"] || data["data"] === "") {
28118
+ payload = null;
28119
+ } else {
28120
+ payload = new AbiDecoder("usernames" /* USERNAMES */).decodeFunctionData(data["data"]);
28121
+ }
28122
+ data["username"] = payload ? payload.args[0] : null;
28123
+ super(data);
28124
+ }
28125
+ getPayload() {
28126
+ if (!this.data["username"]) {
28127
+ return "";
28128
+ }
28129
+ return new AbiEncoder("usernames" /* USERNAMES */).encodeFunctionCall("registerUsername" /* USERNAME_REGISTRATION */, [
28130
+ this.data["username"]
28131
+ ]);
28132
+ }
28133
+ };
28134
+
28135
+ // src/transactions/builders/UsernameRegistrationBuilder.ts
28136
+ var UsernameRegistrationBuilder = class extends AbstractTransactionBuilder {
28137
+ constructor(data) {
28138
+ super(data);
28139
+ this.to("0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6" /* USERNAMES */);
28140
+ }
28141
+ static new(data) {
28142
+ return new this(data);
28143
+ }
28144
+ username(username) {
28145
+ Helpers.isValidUsername(username);
28146
+ this.transaction.data.username = username;
28147
+ this.transaction.refreshPayloadData();
28148
+ return this;
28149
+ }
28150
+ getTransactionInstance(data) {
28151
+ return new UsernameRegistration(data);
28152
+ }
28153
+ };
28154
+
28155
+ // src/transactions/types/UsernameResignation.ts
28156
+ var UsernameResignation = class extends AbstractTransaction {
28157
+ getPayload() {
28158
+ return new AbiEncoder("usernames" /* USERNAMES */).encodeFunctionCall("resignUsername" /* USERNAME_RESIGNATION */, []);
28159
+ }
28160
+ };
28161
+
28162
+ // src/transactions/builders/UsernameResignationBuilder.ts
28163
+ var UsernameResignationBuilder = class extends AbstractTransactionBuilder {
28164
+ constructor(data) {
28165
+ super(data);
28166
+ this.to("0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6" /* USERNAMES */);
28167
+ }
28168
+ static new(data) {
28169
+ return new this(data);
28170
+ }
28171
+ getTransactionInstance(data) {
28172
+ return new UsernameResignation(data);
28173
+ }
28174
+ };
28175
+
28176
+ // src/transactions/types/Vote.ts
28177
+ var Vote = class extends AbstractTransaction {
28178
+ constructor(data) {
28179
+ let payload;
28180
+ if (!data["data"] || data["data"] === "") {
28181
+ payload = null;
28182
+ } else {
28183
+ payload = new AbiDecoder().decodeFunctionData(data["data"]);
28184
+ }
28185
+ data["vote"] = payload ? payload.args[0] : null;
28186
+ super(data);
28187
+ }
28188
+ getPayload() {
28189
+ if (!this.data["vote"]) {
28190
+ return "";
28191
+ }
28192
+ return new AbiEncoder().encodeFunctionCall("vote" /* VOTE */, [this.data["vote"]]);
28193
+ }
28194
+ };
28195
+
28196
+ // src/transactions/builders/VoteBuilder.ts
28197
+ var VoteBuilder = class extends AbstractTransactionBuilder {
28198
+ constructor(data) {
28199
+ super(data);
28200
+ this.to("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28201
+ }
28202
+ static new(data) {
28203
+ return new this(data);
28204
+ }
28205
+ vote(vote) {
28206
+ this.transaction.data.vote = vote;
28207
+ this.transaction.refreshPayloadData();
28208
+ return this;
28209
+ }
28210
+ getTransactionInstance(data) {
28211
+ return new Vote(data);
28212
+ }
28213
+ };
28214
+
28141
28215
  // src/transactions/Deserializer.ts
28142
28216
  var Deserializer = class _Deserializer {
28143
28217
  constructor(serialized) {
@@ -28155,8 +28229,8 @@ var Deserializer = class _Deserializer {
28155
28229
  network: Number(decodedRlp[0]),
28156
28230
  nonce: _Deserializer.parseNumber(decodedRlp[1]),
28157
28231
  gasPrice: _Deserializer.parseNumber(decodedRlp[3]).toString(),
28158
- gasLimit: _Deserializer.parseNumber(decodedRlp[4]).toString(),
28159
- recipientAddress: _Deserializer.parseAddress(decodedRlp[5]),
28232
+ gas: _Deserializer.parseNumber(decodedRlp[4]).toString(),
28233
+ to: _Deserializer.parseAddress(decodedRlp[5]),
28160
28234
  value: _Deserializer.parseBigNumber(decodedRlp[6]),
28161
28235
  data: _Deserializer.parseHex(decodedRlp[7])
28162
28236
  };
@@ -28168,9 +28242,21 @@ var Deserializer = class _Deserializer {
28168
28242
  const transaction = this.guessTransactionFromData(data);
28169
28243
  transaction.data = data;
28170
28244
  transaction.recoverSender();
28171
- transaction.data["id"] = transaction.getId();
28245
+ transaction.data["hash"] = transaction.hash();
28172
28246
  return transaction;
28173
28247
  }
28248
+ static decodePayload(data, abiType = "consensus" /* CONSENSUS */) {
28249
+ const payload = data.data;
28250
+ if (!payload) {
28251
+ return null;
28252
+ }
28253
+ const decoder = new AbiDecoder(abiType);
28254
+ try {
28255
+ return decoder.decodeFunctionData(payload);
28256
+ } catch {
28257
+ }
28258
+ return null;
28259
+ }
28174
28260
  guessTransactionFromData(data) {
28175
28261
  const multipaymentPayloadData = _Deserializer.decodePayload(data, "multipayment" /* MULTIPAYMENT */);
28176
28262
  if (multipaymentPayloadData !== null) {
@@ -28210,18 +28296,6 @@ var Deserializer = class _Deserializer {
28210
28296
  }
28211
28297
  return new EvmCall(data);
28212
28298
  }
28213
- static decodePayload(data, abiType = "consensus" /* CONSENSUS */) {
28214
- const payload = data.data;
28215
- if (!payload) {
28216
- return null;
28217
- }
28218
- const decoder = new AbiDecoder(abiType);
28219
- try {
28220
- return decoder.decodeFunctionData(payload);
28221
- } catch (e) {
28222
- }
28223
- return null;
28224
- }
28225
28299
  static parseNumber(value) {
28226
28300
  return value === "0x" ? 0 : Number(value);
28227
28301
  }
@@ -28235,175 +28309,6 @@ var Deserializer = class _Deserializer {
28235
28309
  return value.replace(/^0x/, "");
28236
28310
  }
28237
28311
  };
28238
-
28239
- // src/transactions/types/EvmCall.ts
28240
- var EvmCall = class extends AbstractTransaction {
28241
- getPayload() {
28242
- return this.data["data"] || "";
28243
- }
28244
- decodePayload(data, type = "consensus" /* CONSENSUS */) {
28245
- if (!data["data"]) {
28246
- return null;
28247
- }
28248
- return Deserializer.decodePayload(data, type);
28249
- }
28250
- };
28251
-
28252
- // src/transactions/builders/EvmCallBuilder.ts
28253
- var EvmCallBuilder = class extends AbstractTransactionBuilder {
28254
- constructor(data) {
28255
- super(data);
28256
- }
28257
- static new(data) {
28258
- return new this(data);
28259
- }
28260
- payload(payload) {
28261
- this.transaction.data["data"] = Helpers.removeLeadingHexZero(payload);
28262
- return this;
28263
- }
28264
- getTransactionInstance(data) {
28265
- return new EvmCall(data);
28266
- }
28267
- };
28268
-
28269
- // src/transactions/builders/MultipaymentBuilder.ts
28270
- var MultipaymentBuilder = class extends AbstractTransactionBuilder {
28271
- constructor(data) {
28272
- super(data);
28273
- this.recipientAddress("0x00EFd0D4639191C49908A7BddbB9A11A994A8527" /* MULTIPAYMENT */);
28274
- }
28275
- static new(data) {
28276
- return new this(data);
28277
- }
28278
- pay(address, amount) {
28279
- let payload = this.transaction.data["pay"];
28280
- payload[0].push(address);
28281
- payload[1].push(amount);
28282
- this.transaction.data.pay = payload;
28283
- this.transaction.data.value = (BigInt(this.transaction.data.value ?? 0) + BigInt(amount)).toString();
28284
- this.transaction.refreshPayloadData();
28285
- return this;
28286
- }
28287
- getTransactionInstance(data) {
28288
- return new Multipayment(data);
28289
- }
28290
- };
28291
-
28292
- // src/transactions/builders/TransferBuilder.ts
28293
- var TransferBuilder = class extends AbstractTransactionBuilder {
28294
- static new(data) {
28295
- return new this(data);
28296
- }
28297
- value(value) {
28298
- this.transaction.data.value = value;
28299
- this.transaction.refreshPayloadData();
28300
- return this;
28301
- }
28302
- getTransactionInstance(data) {
28303
- return new Transfer(data);
28304
- }
28305
- };
28306
-
28307
- // src/transactions/builders/UnvoteBuilder.ts
28308
- var UnvoteBuilder = class extends AbstractTransactionBuilder {
28309
- constructor(data) {
28310
- super(data);
28311
- this.recipientAddress("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28312
- }
28313
- static new(data) {
28314
- return new this(data);
28315
- }
28316
- getTransactionInstance(data) {
28317
- return new Unvote(data);
28318
- }
28319
- };
28320
-
28321
- // src/transactions/builders/ValidatorRegistrationBuilder.ts
28322
- var ValidatorRegistrationBuilder = class extends AbstractTransactionBuilder {
28323
- constructor(data) {
28324
- super(data);
28325
- this.recipientAddress("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28326
- }
28327
- static new(data) {
28328
- return new this(data);
28329
- }
28330
- validatorPublicKey(validatorPublicKey) {
28331
- validatorPublicKey = Helpers.removeLeadingHexZero(validatorPublicKey);
28332
- this.transaction.data.validatorPublicKey = `0x${validatorPublicKey}`;
28333
- this.transaction.refreshPayloadData();
28334
- return this;
28335
- }
28336
- getTransactionInstance(data) {
28337
- return new ValidatorRegistration(data);
28338
- }
28339
- };
28340
-
28341
- // src/transactions/builders/ValidatorResignationBuilder.ts
28342
- var ValidatorResignationBuilder = class extends AbstractTransactionBuilder {
28343
- constructor(data) {
28344
- super(data);
28345
- this.recipientAddress("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28346
- }
28347
- static new(data) {
28348
- return new this(data);
28349
- }
28350
- getTransactionInstance(data) {
28351
- return new ValidatorResignation(data);
28352
- }
28353
- };
28354
-
28355
- // src/transactions/builders/UsernameRegistrationBuilder.ts
28356
- var UsernameRegistrationBuilder = class extends AbstractTransactionBuilder {
28357
- constructor(data) {
28358
- super(data);
28359
- this.recipientAddress("0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6" /* USERNAMES */);
28360
- }
28361
- static new(data) {
28362
- return new this(data);
28363
- }
28364
- username(username) {
28365
- Helpers.isValidUsername(username);
28366
- this.transaction.data.username = username;
28367
- this.transaction.refreshPayloadData();
28368
- return this;
28369
- }
28370
- getTransactionInstance(data) {
28371
- return new UsernameRegistration(data);
28372
- }
28373
- };
28374
-
28375
- // src/transactions/builders/UsernameResignationBuilder.ts
28376
- var UsernameResignationBuilder = class extends AbstractTransactionBuilder {
28377
- constructor(data) {
28378
- super(data);
28379
- this.recipientAddress("0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6" /* USERNAMES */);
28380
- }
28381
- static new(data) {
28382
- return new this(data);
28383
- }
28384
- getTransactionInstance(data) {
28385
- return new UsernameResignation(data);
28386
- }
28387
- };
28388
-
28389
- // src/transactions/builders/VoteBuilder.ts
28390
- var VoteBuilder = class extends AbstractTransactionBuilder {
28391
- constructor(data) {
28392
- super(data);
28393
- this.recipientAddress("0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1" /* CONSENSUS */);
28394
- }
28395
- static new(data) {
28396
- return new this(data);
28397
- }
28398
- vote(vote) {
28399
- this.transaction.data.vote = vote;
28400
- this.transaction.refreshPayloadData();
28401
- return this;
28402
- }
28403
- getTransactionInstance(data) {
28404
- return new Vote(data);
28405
- }
28406
- };
28407
28312
  export {
28408
28313
  AbiBase,
28409
28314
  AbiDecoder,