@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
@@ -4,18 +4,14 @@
4
4
  "type": "function",
5
5
  "name": "UPGRADE_INTERFACE_VERSION",
6
6
  "inputs": [],
7
- "outputs": [
8
- { "name": "", "type": "string", "internalType": "string" }
9
- ],
7
+ "outputs": [{ "name": "", "type": "string", "internalType": "string" }],
10
8
  "stateMutability": "view"
11
9
  },
12
10
  {
13
11
  "type": "function",
14
12
  "name": "activeValidatorsCount",
15
13
  "inputs": [],
16
- "outputs": [
17
- { "name": "", "type": "uint256", "internalType": "uint256" }
18
- ],
14
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
19
15
  "stateMutability": "view"
20
16
  },
21
17
  {
@@ -58,9 +54,7 @@
58
54
  {
59
55
  "type": "function",
60
56
  "name": "calculateActiveValidators",
61
- "inputs": [
62
- { "name": "n", "type": "uint8", "internalType": "uint8" }
63
- ],
57
+ "inputs": [{ "name": "n", "type": "uint8", "internalType": "uint8" }],
64
58
  "outputs": [],
65
59
  "stateMutability": "nonpayable"
66
60
  },
@@ -210,17 +204,13 @@
210
204
  "type": "function",
211
205
  "name": "getRoundsCount",
212
206
  "inputs": [],
213
- "outputs": [
214
- { "name": "", "type": "uint256", "internalType": "uint256" }
215
- ],
207
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
216
208
  "stateMutability": "view"
217
209
  },
218
210
  {
219
211
  "type": "function",
220
212
  "name": "getValidator",
221
- "inputs": [
222
- { "name": "addr", "type": "address", "internalType": "address" }
223
- ],
213
+ "inputs": [{ "name": "addr", "type": "address", "internalType": "address" }],
224
214
  "outputs": [
225
215
  {
226
216
  "name": "",
@@ -304,9 +294,7 @@
304
294
  "type": "function",
305
295
  "name": "getVotesCount",
306
296
  "inputs": [],
307
- "outputs": [
308
- { "name": "", "type": "uint256", "internalType": "uint256" }
309
- ],
297
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
310
298
  "stateMutability": "view"
311
299
  },
312
300
  {
@@ -319,9 +307,7 @@
319
307
  {
320
308
  "type": "function",
321
309
  "name": "isValidatorRegistered",
322
- "inputs": [
323
- { "name": "addr", "type": "address", "internalType": "address" }
324
- ],
310
+ "inputs": [{ "name": "addr", "type": "address", "internalType": "address" }],
325
311
  "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }],
326
312
  "stateMutability": "view"
327
313
  },
@@ -329,18 +315,14 @@
329
315
  "type": "function",
330
316
  "name": "owner",
331
317
  "inputs": [],
332
- "outputs": [
333
- { "name": "", "type": "address", "internalType": "address" }
334
- ],
318
+ "outputs": [{ "name": "", "type": "address", "internalType": "address" }],
335
319
  "stateMutability": "view"
336
320
  },
337
321
  {
338
322
  "type": "function",
339
323
  "name": "proxiableUUID",
340
324
  "inputs": [],
341
- "outputs": [
342
- { "name": "", "type": "bytes32", "internalType": "bytes32" }
343
- ],
325
+ "outputs": [{ "name": "", "type": "bytes32", "internalType": "bytes32" }],
344
326
  "stateMutability": "view"
345
327
  },
346
328
  {
@@ -360,9 +342,7 @@
360
342
  "type": "function",
361
343
  "name": "registeredValidatorsCount",
362
344
  "inputs": [],
363
- "outputs": [
364
- { "name": "", "type": "uint256", "internalType": "uint256" }
365
- ],
345
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
366
346
  "stateMutability": "view"
367
347
  },
368
348
  {
@@ -383,9 +363,7 @@
383
363
  "type": "function",
384
364
  "name": "resignedValidatorsCount",
385
365
  "inputs": [],
386
- "outputs": [
387
- { "name": "", "type": "uint256", "internalType": "uint256" }
388
- ],
366
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
389
367
  "stateMutability": "view"
390
368
  },
391
369
  {
@@ -452,17 +430,13 @@
452
430
  "type": "function",
453
431
  "name": "version",
454
432
  "inputs": [],
455
- "outputs": [
456
- { "name": "", "type": "uint256", "internalType": "uint256" }
457
- ],
433
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
458
434
  "stateMutability": "pure"
459
435
  },
460
436
  {
461
437
  "type": "function",
462
438
  "name": "vote",
463
- "inputs": [
464
- { "name": "addr", "type": "address", "internalType": "address" }
465
- ],
439
+ "inputs": [{ "name": "addr", "type": "address", "internalType": "address" }],
466
440
  "outputs": [],
467
441
  "stateMutability": "nonpayable"
468
442
  },
@@ -673,9 +647,7 @@
673
647
  {
674
648
  "type": "error",
675
649
  "name": "UUPSUnsupportedProxiableUUID",
676
- "inputs": [
677
- { "name": "slot", "type": "bytes32", "internalType": "bytes32" }
678
- ]
650
+ "inputs": [{ "name": "slot", "type": "bytes32", "internalType": "bytes32" }]
679
651
  },
680
652
  { "type": "error", "name": "ValidatorAlreadyRegistered", "inputs": [] },
681
653
  { "type": "error", "name": "ValidatorAlreadyResigned", "inputs": [] },
@@ -1357,9 +1329,7 @@
1357
1329
  "stateMutability": "view",
1358
1330
  "type": "function",
1359
1331
  "name": "isValidatorRegistered",
1360
- "outputs": [
1361
- { "internalType": "bool", "name": "", "type": "bool" }
1362
- ]
1332
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }]
1363
1333
  },
1364
1334
  {
1365
1335
  "inputs": [],
@@ -4,9 +4,7 @@
4
4
  "type": "function",
5
5
  "name": "UPGRADE_INTERFACE_VERSION",
6
6
  "inputs": [],
7
- "outputs": [
8
- { "name": "", "type": "string", "internalType": "string" }
9
- ],
7
+ "outputs": [{ "name": "", "type": "string", "internalType": "string" }],
10
8
  "stateMutability": "view"
11
9
  },
12
10
  {
@@ -30,12 +28,8 @@
30
28
  {
31
29
  "type": "function",
32
30
  "name": "getUsername",
33
- "inputs": [
34
- { "name": "user", "type": "address", "internalType": "address" }
35
- ],
36
- "outputs": [
37
- { "name": "", "type": "string", "internalType": "string" }
38
- ],
31
+ "inputs": [{ "name": "user", "type": "address", "internalType": "address" }],
32
+ "outputs": [{ "name": "", "type": "string", "internalType": "string" }],
39
33
  "stateMutability": "view"
40
34
  },
41
35
  {
@@ -106,18 +100,14 @@
106
100
  "type": "function",
107
101
  "name": "owner",
108
102
  "inputs": [],
109
- "outputs": [
110
- { "name": "", "type": "address", "internalType": "address" }
111
- ],
103
+ "outputs": [{ "name": "", "type": "address", "internalType": "address" }],
112
104
  "stateMutability": "view"
113
105
  },
114
106
  {
115
107
  "type": "function",
116
108
  "name": "proxiableUUID",
117
109
  "inputs": [],
118
- "outputs": [
119
- { "name": "", "type": "bytes32", "internalType": "bytes32" }
120
- ],
110
+ "outputs": [{ "name": "", "type": "bytes32", "internalType": "bytes32" }],
121
111
  "stateMutability": "view"
122
112
  },
123
113
  {
@@ -178,9 +168,7 @@
178
168
  "type": "function",
179
169
  "name": "version",
180
170
  "inputs": [],
181
- "outputs": [
182
- { "name": "", "type": "uint256", "internalType": "uint256" }
183
- ],
171
+ "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
184
172
  "stateMutability": "pure"
185
173
  },
186
174
  {
@@ -330,9 +318,7 @@
330
318
  {
331
319
  "type": "error",
332
320
  "name": "UUPSUnsupportedProxiableUUID",
333
- "inputs": [
334
- { "name": "slot", "type": "bytes32", "internalType": "bytes32" }
335
- ]
321
+ "inputs": [{ "name": "slot", "type": "bytes32", "internalType": "bytes32" }]
336
322
  },
337
323
  { "type": "error", "name": "UsernameNotRegistered", "inputs": [] }
338
324
  ],
@@ -637,9 +623,7 @@
637
623
  "stateMutability": "view",
638
624
  "type": "function",
639
625
  "name": "isUsernameRegistered",
640
- "outputs": [
641
- { "internalType": "bool", "name": "", "type": "bool" }
642
- ]
626
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }]
643
627
  },
644
628
  {
645
629
  "inputs": [
@@ -652,9 +636,7 @@
652
636
  "stateMutability": "pure",
653
637
  "type": "function",
654
638
  "name": "isUsernameValid",
655
- "outputs": [
656
- { "internalType": "bool", "name": "", "type": "bool" }
657
- ]
639
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }]
658
640
  },
659
641
  {
660
642
  "inputs": [],
@@ -1 +1 @@
1
- {"version":3,"file":"AbiDecoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;CAa3C"}
1
+ {"version":3,"file":"AbiDecoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;CAiB3C"}
@@ -6,6 +6,9 @@ export class AbiDecoder extends AbiBase {
6
6
  }
7
7
  const functionSelector = data.slice(0, 10);
8
8
  const functionFragment = this.interface.getFunction(functionSelector);
9
+ if (!functionFragment) {
10
+ throw new Error("Function not found in ABI");
11
+ }
9
12
  return {
10
13
  functionName: functionFragment.name,
11
14
  args: this.interface.decodeFunctionData(functionFragment, data),
@@ -1,5 +1,5 @@
1
1
  import { AbiBase } from "./AbiBase";
2
2
  export declare class AbiEncoder extends AbiBase {
3
- encodeFunctionCall(functionName: string, parameters: any[]): string;
3
+ encodeFunctionCall(functionName: string, parameters: unknown[]): string;
4
4
  }
5
5
  //# sourceMappingURL=AbiEncoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AbiEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,MAAM;CAGnE"}
1
+ {"version":3,"file":"AbiEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM;CAGvE"}
@@ -1,6 +1,7 @@
1
1
  import { AbiBase } from "./AbiBase";
2
+ import { Helpers } from "./Helpers";
2
3
  export class AbiEncoder extends AbiBase {
3
4
  encodeFunctionCall(functionName, parameters) {
4
- return this.interface.encodeFunctionData(functionName, parameters);
5
+ return Helpers.removeLeadingHexZero(this.interface.encodeFunctionData(functionName, parameters));
5
6
  }
6
7
  }
@@ -8,7 +8,7 @@ export declare class Message {
8
8
  static sign(message: string, passphrase: string): Promise<Message>;
9
9
  verify(): boolean;
10
10
  toString(): string;
11
- toArray(): string[];
11
+ toObject(): string[];
12
12
  toJson(): SignedMessage;
13
13
  }
14
14
  //# sourceMappingURL=Message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/utils/Message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,qBAAa,OAAO;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,aAAa;IAMlC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;WAI9B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAaxE,MAAM,IAAI,OAAO;IAQjB,QAAQ,IAAI,MAAM;IAIlB,OAAO,IAAI,MAAM,EAAE;IAInB,MAAM,IAAI,aAAa;CAOvB"}
1
+ {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/utils/Message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,qBAAa,OAAO;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,aAAa;IAMlC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;WAI9B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAaxE,MAAM,IAAI,OAAO;IAQjB,QAAQ,IAAI,MAAM;IAIlB,QAAQ,IAAI,MAAM,EAAE;IAIpB,MAAM,IAAI,aAAa;CAOvB"}
@@ -41,7 +41,7 @@ export class Message {
41
41
  toString() {
42
42
  return JSON.stringify(this.toJson());
43
43
  }
44
- toArray() {
44
+ toObject() {
45
45
  return [this.publicKey, this.signature, this.message];
46
46
  }
47
47
  toJson() {
@@ -2,6 +2,5 @@ import { TransactionData } from "@/types";
2
2
  export declare class TransactionUtils {
3
3
  static toBuffer(transaction: TransactionData, skipSignature?: boolean): Buffer;
4
4
  static toHash(transaction: TransactionData, skipSignature?: boolean): string;
5
- static getId(transaction: TransactionData): string;
6
5
  }
7
6
  //# sourceMappingURL=TransactionUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/TransactionUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,gBAAgB;WACd,QAAQ,CAAC,WAAW,EAAE,eAAe,EAAE,aAAa,GAAE,OAAe,GAAG,MAAM;WA4B9E,MAAM,CAAC,WAAW,EAAE,eAAe,EAAE,aAAa,GAAE,OAAe,GAAG,MAAM;WAM5E,KAAK,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM;CAGzD"}
1
+ {"version":3,"file":"TransactionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/TransactionUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,gBAAgB;WACd,QAAQ,CAAC,WAAW,EAAE,eAAe,EAAE,aAAa,UAAQ,GAAG,MAAM;WA4BrE,MAAM,CAAC,WAAW,EAAE,eAAe,EAAE,aAAa,UAAQ,GAAG,MAAM;CAKjF"}
@@ -4,32 +4,29 @@ export class TransactionUtils {
4
4
  static toBuffer(transaction, skipSignature = false) {
5
5
  var _a, _b, _c, _d, _e;
6
6
  const fields = [
7
- toBeArray((_a = transaction['network']) !== null && _a !== void 0 ? _a : 0),
8
- toBeArray(transaction['nonce'] ? transaction['nonce'] : 0),
7
+ toBeArray((_a = transaction["network"]) !== null && _a !== void 0 ? _a : 0),
8
+ toBeArray(transaction["nonce"] ? transaction["nonce"] : 0),
9
9
  toBeArray(0),
10
- toBeArray((_b = transaction['gasPrice']) !== null && _b !== void 0 ? _b : 0),
11
- toBeArray((_c = transaction['gasLimit']) !== null && _c !== void 0 ? _c : 0),
12
- (_d = transaction['recipientAddress']) !== null && _d !== void 0 ? _d : '0x',
13
- toBeArray(transaction['value'] ? transaction['value'] : 0),
14
- transaction['data'] && transaction['data'].startsWith('0x')
15
- ? transaction['data']
16
- : ('0x' + ((_e = transaction['data']) !== null && _e !== void 0 ? _e : '')),
10
+ toBeArray((_b = transaction["gasPrice"]) !== null && _b !== void 0 ? _b : 0),
11
+ toBeArray((_c = transaction["gas"]) !== null && _c !== void 0 ? _c : 0),
12
+ (_d = transaction["to"]) !== null && _d !== void 0 ? _d : "0x",
13
+ toBeArray(transaction["value"] ? transaction["value"] : 0),
14
+ transaction["data"] && transaction["data"].startsWith("0x")
15
+ ? transaction["data"]
16
+ : "0x" + ((_e = transaction["data"]) !== null && _e !== void 0 ? _e : ""),
17
17
  [],
18
18
  ];
19
- if (!skipSignature && transaction['v'] && transaction['r'] && transaction['s']) {
20
- fields.push(toBeArray(transaction['v'] - Constants.ETHEREUM_RECOVERY_ID_OFFSET));
21
- fields.push('0x' + transaction['r']);
22
- fields.push('0x' + transaction['s']);
19
+ if (!skipSignature && transaction["v"] && transaction["r"] && transaction["s"]) {
20
+ fields.push(toBeArray(transaction["v"] - Constants.ETHEREUM_RECOVERY_ID_OFFSET));
21
+ fields.push("0x" + transaction["r"]);
22
+ fields.push("0x" + transaction["s"]);
23
23
  }
24
24
  const encoded = encodeRlp(fields);
25
25
  const payload = Constants.EIP_1559_PREFIX + encoded.substring(2);
26
- return Buffer.from(payload, 'hex');
26
+ return Buffer.from(payload, "hex");
27
27
  }
28
28
  static toHash(transaction, skipSignature = false) {
29
29
  const encoding = this.toBuffer(transaction, skipSignature);
30
- return keccak256('0x' + encoding.toString('hex')).substring(2);
31
- }
32
- static getId(transaction) {
33
- return this.toHash(transaction, false);
30
+ return keccak256("0x" + encoding.toString("hex")).substring(2);
34
31
  }
35
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UnitConverter.d.ts","sourceRoot":"","sources":["../../src/utils/UnitConverter.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAMrC,qBAAa,aAAa;IACzB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAC,MAAM,EAAE,IAAI,GAAE,MAAc,GAAG,SAAS;IAaxE,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAc,GAAG,MAAM;IAa/D,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAY9D,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;CAW/D"}
1
+ {"version":3,"file":"UnitConverter.d.ts","sourceRoot":"","sources":["../../src/utils/UnitConverter.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAMrC,qBAAa,aAAa;IACzB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,SAAQ,GAAG,SAAS;IAalE,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAQ,GAAG,MAAM;IAavD,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAYhE,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;CAWjE"}
@@ -3,45 +3,45 @@ const WEI_MULTIPLIER = 1;
3
3
  const GWEI_MULTIPLIER = 1000000000; // 1e9
4
4
  const ARK_MULTIPLIER = 1000000000000000000; // 1e18
5
5
  export class UnitConverter {
6
- static parseUnits(value, unit = 'ark') {
6
+ static parseUnits(value, unit = "ark") {
7
7
  switch (unit.toLowerCase()) {
8
- case 'wei':
8
+ case "wei":
9
9
  return BigNumber(value).multipliedBy(WEI_MULTIPLIER);
10
- case 'gwei':
10
+ case "gwei":
11
11
  return BigNumber(value).multipliedBy(GWEI_MULTIPLIER);
12
- case 'ark':
12
+ case "ark":
13
13
  return BigNumber(value).multipliedBy(ARK_MULTIPLIER);
14
14
  default:
15
15
  throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
16
16
  }
17
17
  }
18
- static formatUnits(value, unit = 'ark') {
18
+ static formatUnits(value, unit = "ark") {
19
19
  switch (unit.toLowerCase()) {
20
- case 'wei':
20
+ case "wei":
21
21
  return BigNumber(value).dividedBy(WEI_MULTIPLIER).toNumber();
22
- case 'gwei':
22
+ case "gwei":
23
23
  return BigNumber(value).dividedBy(GWEI_MULTIPLIER).toNumber();
24
- case 'ark':
24
+ case "ark":
25
25
  return BigNumber(value).dividedBy(ARK_MULTIPLIER).toNumber();
26
26
  default:
27
27
  throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
28
28
  }
29
29
  }
30
30
  static weiToArk(value, suffix) {
31
- const convertedValue = new BigNumber(this.formatUnits(this.parseUnits(value, 'wei').toString(), 'ark'))
31
+ const convertedValue = new BigNumber(this.formatUnits(this.parseUnits(value, "wei").toString(), "ark"))
32
32
  .decimalPlaces(18)
33
33
  .toFixed();
34
34
  if (suffix) {
35
- return convertedValue + ' ' + suffix;
35
+ return convertedValue + " " + suffix;
36
36
  }
37
37
  return convertedValue;
38
38
  }
39
39
  static gweiToArk(value, suffix) {
40
- const convertedValue = new BigNumber(this.formatUnits(this.parseUnits(value, 'gwei').toString(), 'ark'))
40
+ const convertedValue = new BigNumber(this.formatUnits(this.parseUnits(value, "gwei").toString(), "ark"))
41
41
  .decimalPlaces(18)
42
42
  .toFixed();
43
43
  if (suffix) {
44
- return convertedValue + ' ' + suffix;
44
+ return convertedValue + " " + suffix;
45
45
  }
46
46
  return convertedValue;
47
47
  }
@@ -0,0 +1,19 @@
1
+ // @ts-check
2
+
3
+ import eslint from "@eslint/js";
4
+ import tseslint from "typescript-eslint";
5
+
6
+ export default tseslint.config(
7
+ eslint.configs.recommended,
8
+ tseslint.configs.strict,
9
+ tseslint.configs.stylistic,
10
+ {
11
+ ignores: ["dist/", "tests/"],
12
+ },
13
+ {
14
+ rules: {
15
+ "@typescript-eslint/no-extraneous-class": "off",
16
+ "@typescript-eslint/no-empty-object-type": "off",
17
+ },
18
+ },
19
+ );
package/jest.config.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'
1
+ import { createDefaultEsmPreset, type JestConfigWithTsJest } from "ts-jest";
2
2
 
3
- const presetConfig = createDefaultEsmPreset()
3
+ const presetConfig = createDefaultEsmPreset();
4
4
 
5
5
  const jestConfig: JestConfigWithTsJest = {
6
6
  ...presetConfig,
7
7
 
8
8
  moduleNameMapper: {
9
- '^@/(.*)$': '<rootDir>/src/$1',
10
- '^@tests/(.*)$': '<rootDir>/tests/$1',
9
+ "^@/(.*)$": "<rootDir>/src/$1",
10
+ "^@tests/(.*)$": "<rootDir>/tests/$1",
11
11
  },
12
- }
12
+ };
13
13
 
14
- export default jestConfig
14
+ export default jestConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkecosystem/typescript-crypto",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "engines": {
5
5
  "node": ">=20.12.2"
6
6
  },
@@ -30,6 +30,7 @@
30
30
  "author": "",
31
31
  "license": "CC BY-NC-ND 4.0",
32
32
  "devDependencies": {
33
+ "@eslint/js": "^9.23.0",
33
34
  "@jest/globals": "^29.7.0",
34
35
  "@types/jest": "^29.5.14",
35
36
  "@typescript-eslint/eslint-plugin": "^8.25.0",
@@ -43,7 +44,8 @@
43
44
  "prettier": "^3.5.3",
44
45
  "ts-jest": "^29.2.6",
45
46
  "ts-node": "^10.9.2",
46
- "typescript": "^5.8.2"
47
+ "typescript": "^5.8.2",
48
+ "typescript-eslint": "^8.28.0"
47
49
  },
48
50
  "dependencies": {
49
51
  "@noble/secp256k1": "^2.2.3",
@@ -53,6 +55,8 @@
53
55
  },
54
56
  "scripts": {
55
57
  "build": "tsc && esbuild src/index.ts --outdir=dist --format=esm --bundle",
58
+ "format": "prettier --write .",
59
+ "lint": "eslint .",
56
60
  "test": "NODE_OPTIONS=--experimental-vm-modules jest"
57
61
  }
58
62
  }
@@ -1,4 +1,4 @@
1
1
  export enum Constants {
2
- EIP_1559_PREFIX = '02',
2
+ EIP_1559_PREFIX = "02",
3
3
  ETHEREUM_RECOVERY_ID_OFFSET = 27,
4
4
  }
@@ -1,6 +1,6 @@
1
1
  export enum ContractAbiType {
2
- CUSTOM = 'custom',
3
- CONSENSUS = 'consensus',
4
- MULTIPAYMENT = 'multipayment',
5
- USERNAMES = 'usernames',
2
+ CUSTOM = "custom",
3
+ CONSENSUS = "consensus",
4
+ MULTIPAYMENT = "multipayment",
5
+ USERNAMES = "usernames",
6
6
  }
@@ -1 +1 @@
1
- export * from "./InvalidUsernameException"
1
+ export * from "./InvalidUsernameException";
@@ -6,11 +6,11 @@ import { signAsync } from "@noble/secp256k1";
6
6
  import { Constants } from "@/enums/Constants";
7
7
  import { Network } from "@/configuration/Network";
8
8
 
9
- type RecoverableSignature = {
9
+ interface RecoverableSignature {
10
10
  r: string;
11
11
  s: string;
12
12
  v: number;
13
- };
13
+ }
14
14
 
15
15
  export class PrivateKey {
16
16
  public privateKey: string;
@@ -30,7 +30,7 @@ export class PrivateKey {
30
30
  }
31
31
 
32
32
  static fromWif(wif: string): PrivateKey {
33
- const decodedWif = WIF.decode(wif, Buffer.from(Network.get().getWif(), "hex").readUInt8());
33
+ const decodedWif = WIF.decode(wif, Buffer.from(Network.get().wif(), "hex").readUInt8());
34
34
 
35
35
  return PrivateKey.fromHex(Buffer.from(decodedWif.privateKey).toString("hex"));
36
36
  }
@@ -1,4 +1,3 @@
1
- import { sha256 } from "ethers";
2
1
  import { Network } from "@/configuration/Network";
3
2
  import * as WIFPackage from "wif";
4
3
  import { PrivateKey } from "./PrivateKey";
@@ -8,8 +7,8 @@ export class WIF {
8
7
  const privateKey = PrivateKey.fromPassphrase(passphrase);
9
8
 
10
9
  return WIFPackage.encode({
11
- version: Buffer.from(Network.get().getWif(), 'hex').readUInt8(),
12
- privateKey: Buffer.from(privateKey.privateKey, 'hex'),
10
+ version: Buffer.from(Network.get().wif(), "hex").readUInt8(),
11
+ privateKey: Buffer.from(privateKey.privateKey, "hex"),
13
12
  compressed: true,
14
13
  });
15
14
  }
@@ -1,7 +1,7 @@
1
1
  export abstract class AbstractNetwork {
2
- abstract chainId(): number;
2
+ abstract chainId(): number;
3
3
 
4
- abstract epoch(): string;
4
+ abstract epoch(): string;
5
5
 
6
- abstract getWif(): string;
6
+ abstract wif(): string;
7
7
  }
@@ -6,10 +6,10 @@ export class Mainnet extends AbstractNetwork {
6
6
  }
7
7
 
8
8
  public epoch(): string {
9
- return "2017-03-21T13:00:00.000Z";
9
+ return "2017-03-21T13:00:00.000Z";
10
10
  }
11
11
 
12
- public getWif(): string {
13
- return "ba";
12
+ public wif(): string {
13
+ return "ba";
14
14
  }
15
15
  }
@@ -9,7 +9,7 @@ export class Testnet extends AbstractNetwork {
9
9
  return "2017-03-21T13:00:00.000Z";
10
10
  }
11
11
 
12
- public getWif(): string {
12
+ public wif(): string {
13
13
  return "ba";
14
14
  }
15
15
  }