@arkecosystem/typescript-crypto 0.0.1

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 (278) hide show
  1. package/.editorconfig +16 -0
  2. package/.eslintrc.js +12 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +24 -0
  4. package/.github/workflows/ci.yml +36 -0
  5. package/.github/workflows/publish.yml +56 -0
  6. package/.vscode/settings.json +2 -0
  7. package/README.md +31 -0
  8. package/dist/configuration/Network.d.ts +7 -0
  9. package/dist/configuration/Network.d.ts.map +1 -0
  10. package/dist/configuration/Network.js +12 -0
  11. package/dist/configuration/index.d.ts +2 -0
  12. package/dist/configuration/index.d.ts.map +1 -0
  13. package/dist/configuration/index.js +1 -0
  14. package/dist/enums/AbiFunction.d.ts +10 -0
  15. package/dist/enums/AbiFunction.d.ts.map +1 -0
  16. package/dist/enums/AbiFunction.js +10 -0
  17. package/dist/enums/Constants.d.ts +5 -0
  18. package/dist/enums/Constants.d.ts.map +1 -0
  19. package/dist/enums/Constants.js +5 -0
  20. package/dist/enums/ContractAbiType.d.ts +7 -0
  21. package/dist/enums/ContractAbiType.d.ts.map +1 -0
  22. package/dist/enums/ContractAbiType.js +7 -0
  23. package/dist/enums/ContractAddresses.d.ts +6 -0
  24. package/dist/enums/ContractAddresses.d.ts.map +1 -0
  25. package/dist/enums/ContractAddresses.js +6 -0
  26. package/dist/enums/index.d.ts +5 -0
  27. package/dist/enums/index.d.ts.map +1 -0
  28. package/dist/enums/index.js +4 -0
  29. package/dist/exceptions/InvalidUsernameException.d.ts +4 -0
  30. package/dist/exceptions/InvalidUsernameException.d.ts.map +1 -0
  31. package/dist/exceptions/InvalidUsernameException.js +6 -0
  32. package/dist/exceptions/index.d.ts +2 -0
  33. package/dist/exceptions/index.d.ts.map +1 -0
  34. package/dist/exceptions/index.js +1 -0
  35. package/dist/identities/Address.d.ts +7 -0
  36. package/dist/identities/Address.d.ts.map +1 -0
  37. package/dist/identities/Address.js +15 -0
  38. package/dist/identities/PrivateKey.d.ts +16 -0
  39. package/dist/identities/PrivateKey.d.ts.map +1 -0
  40. package/dist/identities/PrivateKey.js +31 -0
  41. package/dist/identities/PublicKey.d.ts +8 -0
  42. package/dist/identities/PublicKey.d.ts.map +1 -0
  43. package/dist/identities/PublicKey.js +24 -0
  44. package/dist/identities/WIF.d.ts +4 -0
  45. package/dist/identities/WIF.d.ts.map +1 -0
  46. package/dist/identities/WIF.js +13 -0
  47. package/dist/identities/index.d.ts +5 -0
  48. package/dist/identities/index.d.ts.map +1 -0
  49. package/dist/identities/index.js +4 -0
  50. package/dist/index.d.ts +8 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +24 -0
  53. package/dist/networks/AbstractNetwork.d.ts +6 -0
  54. package/dist/networks/AbstractNetwork.d.ts.map +1 -0
  55. package/dist/networks/AbstractNetwork.js +2 -0
  56. package/dist/networks/Mainnet.d.ts +7 -0
  57. package/dist/networks/Mainnet.d.ts.map +1 -0
  58. package/dist/networks/Mainnet.js +12 -0
  59. package/dist/networks/Testnet.d.ts +7 -0
  60. package/dist/networks/Testnet.d.ts.map +1 -0
  61. package/dist/networks/Testnet.js +12 -0
  62. package/dist/networks/index.d.ts +4 -0
  63. package/dist/networks/index.d.ts.map +1 -0
  64. package/dist/networks/index.js +3 -0
  65. package/dist/transactions/Deserializer.d.ts +18 -0
  66. package/dist/transactions/Deserializer.d.ts.map +1 -0
  67. package/dist/transactions/Deserializer.js +106 -0
  68. package/dist/transactions/Serializer.d.ts +9 -0
  69. package/dist/transactions/Serializer.d.ts.map +1 -0
  70. package/dist/transactions/Serializer.js +16 -0
  71. package/dist/transactions/builders/AbstractTransactionBuilder.d.ts +17 -0
  72. package/dist/transactions/builders/AbstractTransactionBuilder.d.ts.map +1 -0
  73. package/dist/transactions/builders/AbstractTransactionBuilder.js +54 -0
  74. package/dist/transactions/builders/EvmCallBuilder.d.ts +9 -0
  75. package/dist/transactions/builders/EvmCallBuilder.d.ts.map +1 -0
  76. package/dist/transactions/builders/EvmCallBuilder.js +18 -0
  77. package/dist/transactions/builders/MultipaymentBuilder.d.ts +9 -0
  78. package/dist/transactions/builders/MultipaymentBuilder.d.ts.map +1 -0
  79. package/dist/transactions/builders/MultipaymentBuilder.js +25 -0
  80. package/dist/transactions/builders/TransferBuilder.d.ts +8 -0
  81. package/dist/transactions/builders/TransferBuilder.d.ts.map +1 -0
  82. package/dist/transactions/builders/TransferBuilder.js +15 -0
  83. package/dist/transactions/builders/UnvoteBuilder.d.ts +8 -0
  84. package/dist/transactions/builders/UnvoteBuilder.d.ts.map +1 -0
  85. package/dist/transactions/builders/UnvoteBuilder.js +15 -0
  86. package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts +9 -0
  87. package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts.map +1 -0
  88. package/dist/transactions/builders/UsernameRegistrationBuilder.js +22 -0
  89. package/dist/transactions/builders/UsernameResignationBuilder.d.ts +8 -0
  90. package/dist/transactions/builders/UsernameResignationBuilder.d.ts.map +1 -0
  91. package/dist/transactions/builders/UsernameResignationBuilder.js +15 -0
  92. package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts +9 -0
  93. package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts.map +1 -0
  94. package/dist/transactions/builders/ValidatorRegistrationBuilder.js +20 -0
  95. package/dist/transactions/builders/ValidatorResignationBuilder.d.ts +8 -0
  96. package/dist/transactions/builders/ValidatorResignationBuilder.d.ts.map +1 -0
  97. package/dist/transactions/builders/ValidatorResignationBuilder.js +15 -0
  98. package/dist/transactions/builders/VoteBuilder.d.ts +9 -0
  99. package/dist/transactions/builders/VoteBuilder.d.ts.map +1 -0
  100. package/dist/transactions/builders/VoteBuilder.js +20 -0
  101. package/dist/transactions/builders/index.d.ts +11 -0
  102. package/dist/transactions/builders/index.d.ts.map +1 -0
  103. package/dist/transactions/builders/index.js +10 -0
  104. package/dist/transactions/index.d.ts +5 -0
  105. package/dist/transactions/index.d.ts.map +1 -0
  106. package/dist/transactions/index.js +4 -0
  107. package/dist/transactions/types/AbstractTransaction.d.ts +22 -0
  108. package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -0
  109. package/dist/transactions/types/AbstractTransaction.js +79 -0
  110. package/dist/transactions/types/EvmCall.d.ts +8 -0
  111. package/dist/transactions/types/EvmCall.d.ts.map +1 -0
  112. package/dist/transactions/types/EvmCall.js +14 -0
  113. package/dist/transactions/types/Multipayment.d.ts +9 -0
  114. package/dist/transactions/types/Multipayment.d.ts.map +1 -0
  115. package/dist/transactions/types/Multipayment.js +38 -0
  116. package/dist/transactions/types/Transfer.d.ts +8 -0
  117. package/dist/transactions/types/Transfer.d.ts.map +1 -0
  118. package/dist/transactions/types/Transfer.js +14 -0
  119. package/dist/transactions/types/Unvote.d.ts +8 -0
  120. package/dist/transactions/types/Unvote.d.ts.map +1 -0
  121. package/dist/transactions/types/Unvote.js +16 -0
  122. package/dist/transactions/types/UsernameRegistration.d.ts +9 -0
  123. package/dist/transactions/types/UsernameRegistration.d.ts.map +1 -0
  124. package/dist/transactions/types/UsernameRegistration.js +33 -0
  125. package/dist/transactions/types/UsernameResignation.d.ts +8 -0
  126. package/dist/transactions/types/UsernameResignation.d.ts.map +1 -0
  127. package/dist/transactions/types/UsernameResignation.js +16 -0
  128. package/dist/transactions/types/ValidatorRegistration.d.ts +9 -0
  129. package/dist/transactions/types/ValidatorRegistration.d.ts.map +1 -0
  130. package/dist/transactions/types/ValidatorRegistration.js +33 -0
  131. package/dist/transactions/types/ValidatorResignation.d.ts +8 -0
  132. package/dist/transactions/types/ValidatorResignation.d.ts.map +1 -0
  133. package/dist/transactions/types/ValidatorResignation.js +16 -0
  134. package/dist/transactions/types/Vote.d.ts +9 -0
  135. package/dist/transactions/types/Vote.d.ts.map +1 -0
  136. package/dist/transactions/types/Vote.js +31 -0
  137. package/dist/transactions/types/index.d.ts +11 -0
  138. package/dist/transactions/types/index.d.ts.map +1 -0
  139. package/dist/transactions/types/index.js +10 -0
  140. package/dist/types.d.ts +72 -0
  141. package/dist/types.d.ts.map +1 -0
  142. package/dist/types.js +1 -0
  143. package/dist/utils/Abi/ArgumentDecoder.d.ts +10 -0
  144. package/dist/utils/Abi/ArgumentDecoder.d.ts.map +1 -0
  145. package/dist/utils/Abi/ArgumentDecoder.js +21 -0
  146. package/dist/utils/Abi/json/Abi.Consensus.json +1673 -0
  147. package/dist/utils/Abi/json/Abi.Multipayment.json +110 -0
  148. package/dist/utils/Abi/json/Abi.Usernames.json +900 -0
  149. package/dist/utils/AbiBase.d.ts +8 -0
  150. package/dist/utils/AbiBase.d.ts.map +1 -0
  151. package/dist/utils/AbiBase.js +25 -0
  152. package/dist/utils/AbiDecoder.d.ts +6 -0
  153. package/dist/utils/AbiDecoder.d.ts.map +1 -0
  154. package/dist/utils/AbiDecoder.js +14 -0
  155. package/dist/utils/AbiEncoder.d.ts +5 -0
  156. package/dist/utils/AbiEncoder.d.ts.map +1 -0
  157. package/dist/utils/AbiEncoder.js +6 -0
  158. package/dist/utils/Helpers.d.ts +19 -0
  159. package/dist/utils/Helpers.d.ts.map +1 -0
  160. package/dist/utils/Helpers.js +38 -0
  161. package/dist/utils/Message.d.ts +14 -0
  162. package/dist/utils/Message.d.ts.map +1 -0
  163. package/dist/utils/Message.js +43 -0
  164. package/dist/utils/Slot.d.ts +5 -0
  165. package/dist/utils/Slot.d.ts.map +1 -0
  166. package/dist/utils/Slot.js +9 -0
  167. package/dist/utils/TransactionUtils.d.ts +7 -0
  168. package/dist/utils/TransactionUtils.d.ts.map +1 -0
  169. package/dist/utils/TransactionUtils.js +35 -0
  170. package/dist/utils/UnitConverter.d.ts +8 -0
  171. package/dist/utils/UnitConverter.d.ts.map +1 -0
  172. package/dist/utils/UnitConverter.js +48 -0
  173. package/dist/utils/index.d.ts +9 -0
  174. package/dist/utils/index.d.ts.map +1 -0
  175. package/dist/utils/index.js +8 -0
  176. package/jest.config.ts +14 -0
  177. package/package.json +59 -0
  178. package/prettier.config.js +8 -0
  179. package/src/configuration/Network.ts +18 -0
  180. package/src/configuration/index.ts +1 -0
  181. package/src/enums/AbiFunction.ts +9 -0
  182. package/src/enums/Constants.ts +4 -0
  183. package/src/enums/ContractAbiType.ts +6 -0
  184. package/src/enums/ContractAddresses.ts +5 -0
  185. package/src/enums/index.ts +4 -0
  186. package/src/exceptions/InvalidUsernameException.ts +6 -0
  187. package/src/exceptions/index.ts +1 -0
  188. package/src/identities/Address.ts +19 -0
  189. package/src/identities/PrivateKey.ts +49 -0
  190. package/src/identities/PublicKey.ts +28 -0
  191. package/src/identities/WIF.ts +16 -0
  192. package/src/identities/index.ts +4 -0
  193. package/src/index.ts +7 -0
  194. package/src/networks/AbstractNetwork.ts +7 -0
  195. package/src/networks/Mainnet.ts +15 -0
  196. package/src/networks/Testnet.ts +15 -0
  197. package/src/networks/index.ts +3 -0
  198. package/src/transactions/Deserializer.ts +140 -0
  199. package/src/transactions/Serializer.ts +24 -0
  200. package/src/transactions/builders/AbstractTransactionBuilder.ts +81 -0
  201. package/src/transactions/builders/EvmCallBuilder.ts +24 -0
  202. package/src/transactions/builders/MultipaymentBuilder.ts +37 -0
  203. package/src/transactions/builders/TransferBuilder.ts +22 -0
  204. package/src/transactions/builders/UnvoteBuilder.ts +21 -0
  205. package/src/transactions/builders/UsernameRegistrationBuilder.ts +35 -0
  206. package/src/transactions/builders/UsernameResignationBuilder.ts +21 -0
  207. package/src/transactions/builders/ValidatorRegistrationBuilder.ts +32 -0
  208. package/src/transactions/builders/ValidatorResignationBuilder.ts +21 -0
  209. package/src/transactions/builders/VoteBuilder.ts +29 -0
  210. package/src/transactions/builders/index.ts +10 -0
  211. package/src/transactions/index.ts +4 -0
  212. package/src/transactions/types/AbstractTransaction.ts +118 -0
  213. package/src/transactions/types/EvmCall.ts +22 -0
  214. package/src/transactions/types/Multipayment.ts +51 -0
  215. package/src/transactions/types/Transfer.ts +22 -0
  216. package/src/transactions/types/Unvote.ts +24 -0
  217. package/src/transactions/types/UsernameRegistration.ts +44 -0
  218. package/src/transactions/types/UsernameResignation.ts +24 -0
  219. package/src/transactions/types/ValidatorRegistration.ts +44 -0
  220. package/src/transactions/types/ValidatorResignation.ts +24 -0
  221. package/src/transactions/types/Vote.ts +42 -0
  222. package/src/transactions/types/index.ts +10 -0
  223. package/src/types.ts +86 -0
  224. package/src/utils/Abi/ArgumentDecoder.ts +29 -0
  225. package/src/utils/Abi/json/Abi.Consensus.json +1673 -0
  226. package/src/utils/Abi/json/Abi.Multipayment.json +110 -0
  227. package/src/utils/Abi/json/Abi.Usernames.json +900 -0
  228. package/src/utils/AbiBase.ts +32 -0
  229. package/src/utils/AbiDecoder.ts +19 -0
  230. package/src/utils/AbiEncoder.ts +7 -0
  231. package/src/utils/Helpers.ts +46 -0
  232. package/src/utils/Message.ts +63 -0
  233. package/src/utils/Slot.ts +11 -0
  234. package/src/utils/TransactionUtils.ts +43 -0
  235. package/src/utils/UnitConverter.ts +57 -0
  236. package/src/utils/index.ts +8 -0
  237. package/tests/fixtures/global.json +10 -0
  238. package/tests/fixtures/identity.json +11 -0
  239. package/tests/fixtures/message-sign.json +5 -0
  240. package/tests/fixtures/sign-compact.json +10 -0
  241. package/tests/fixtures/transactions/evm-sign.json +18 -0
  242. package/tests/fixtures/transactions/multipayment-empty.json +18 -0
  243. package/tests/fixtures/transactions/multipayment-single.json +18 -0
  244. package/tests/fixtures/transactions/multipayment.json +18 -0
  245. package/tests/fixtures/transactions/transfer-0.json +18 -0
  246. package/tests/fixtures/transactions/transfer-large-amount.json +18 -0
  247. package/tests/fixtures/transactions/transfer.json +18 -0
  248. package/tests/fixtures/transactions/unvote.json +18 -0
  249. package/tests/fixtures/transactions/username-registration.json +18 -0
  250. package/tests/fixtures/transactions/username-resignation.json +18 -0
  251. package/tests/fixtures/transactions/validator-registration.json +18 -0
  252. package/tests/fixtures/transactions/validator-resignation.json +18 -0
  253. package/tests/fixtures/transactions/vote.json +18 -0
  254. package/tests/unit/identities/Address.test.ts +26 -0
  255. package/tests/unit/identities/PrivateKey.test.ts +36 -0
  256. package/tests/unit/identities/PublicKey.test.ts +39 -0
  257. package/tests/unit/identities/WIF.test.ts +8 -0
  258. package/tests/unit/transactions/Deserializer.test.ts +138 -0
  259. package/tests/unit/transactions/Serializer.test.ts +9 -0
  260. package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +49 -0
  261. package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +99 -0
  262. package/tests/unit/transactions/builders/TransferBuilder.test.ts +73 -0
  263. package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +47 -0
  264. package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +54 -0
  265. package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +48 -0
  266. package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +51 -0
  267. package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +48 -0
  268. package/tests/unit/transactions/builders/VoteBuilder.test.ts +48 -0
  269. package/tests/unit/transactions/types/AbstractTransaction.test.ts +145 -0
  270. package/tests/unit/utils/Abi/ArgumentDecoder.test.ts +55 -0
  271. package/tests/unit/utils/AbiDecoder.test.ts +44 -0
  272. package/tests/unit/utils/AbiEncoder.test.ts +30 -0
  273. package/tests/unit/utils/Helpers.test.ts +120 -0
  274. package/tests/unit/utils/Message.test.ts +104 -0
  275. package/tests/unit/utils/Slot.test.ts +69 -0
  276. package/tests/unit/utils/TransactionUtils.test.ts +31 -0
  277. package/tests/unit/utils/UnitConverter.test.ts +71 -0
  278. package/tsconfig.json +20 -0
@@ -0,0 +1,8 @@
1
+ import { ContractAbiType } from "../enums/ContractAbiType";
2
+ import { Interface } from "ethers";
3
+ export declare abstract class AbiBase {
4
+ protected interface: Interface;
5
+ constructor(type?: ContractAbiType, customAbi?: string);
6
+ private contractAbi;
7
+ }
8
+ //# sourceMappingURL=AbiBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbiBase.d.ts","sourceRoot":"","sources":["../../src/utils/AbiBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAKnC,8BAAsB,OAAO;IAC5B,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC;gBAEnB,IAAI,GAAE,eAA2C,EAAE,SAAS,CAAC,EAAE,MAAM;IAMjF,OAAO,CAAC,WAAW;CAgBnB"}
@@ -0,0 +1,25 @@
1
+ import { ContractAbiType } from "../enums/ContractAbiType";
2
+ import { Interface } from "ethers";
3
+ import ConsensusContract from "./Abi/json/Abi.Consensus.json";
4
+ import MultipaymentContract from "./Abi/json/Abi.Multipayment.json";
5
+ import UsernamesContract from "./Abi/json/Abi.Usernames.json";
6
+ export class AbiBase {
7
+ constructor(type = ContractAbiType.CONSENSUS, customAbi) {
8
+ const abi = this.contractAbi(type, customAbi);
9
+ this.interface = new Interface(JSON.parse(JSON.stringify(abi)).abi);
10
+ }
11
+ contractAbi(type = ContractAbiType.CONSENSUS, customAbi) {
12
+ switch (type) {
13
+ case ContractAbiType.CONSENSUS:
14
+ return ConsensusContract;
15
+ case ContractAbiType.MULTIPAYMENT:
16
+ return MultipaymentContract;
17
+ case ContractAbiType.USERNAMES:
18
+ return UsernamesContract;
19
+ }
20
+ if (customAbi) {
21
+ return customAbi;
22
+ }
23
+ throw new Error("Invalid contract type");
24
+ }
25
+ }
@@ -0,0 +1,6 @@
1
+ import { AbiResult } from "../types";
2
+ import { AbiBase } from "./AbiBase";
3
+ export declare class AbiDecoder extends AbiBase {
4
+ decodeFunctionData(data: string): AbiResult;
5
+ }
6
+ //# sourceMappingURL=AbiDecoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbiDecoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;CAa3C"}
@@ -0,0 +1,14 @@
1
+ import { AbiBase } from "./AbiBase";
2
+ export class AbiDecoder extends AbiBase {
3
+ decodeFunctionData(data) {
4
+ if (!data.startsWith("0x")) {
5
+ data = "0x" + data;
6
+ }
7
+ const functionSelector = data.slice(0, 10);
8
+ const functionFragment = this.interface.getFunction(functionSelector);
9
+ return {
10
+ functionName: functionFragment.name,
11
+ args: this.interface.decodeFunctionData(functionFragment, data),
12
+ };
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ import { AbiBase } from "./AbiBase";
2
+ export declare class AbiEncoder extends AbiBase {
3
+ encodeFunctionCall(functionName: string, parameters: any[]): string;
4
+ }
5
+ //# sourceMappingURL=AbiEncoder.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ import { AbiBase } from "./AbiBase";
2
+ export class AbiEncoder extends AbiBase {
3
+ encodeFunctionCall(functionName, parameters) {
4
+ return this.interface.encodeFunctionData(functionName, parameters);
5
+ }
6
+ }
@@ -0,0 +1,19 @@
1
+ export declare class Helpers {
2
+ /**
3
+ * Validates a username based on specific rules.
4
+ * Based on https://github.com/ArkEcosystem/mainsail/blob/develop/contracts/src/usernames/UsernamesV1.sol#L101
5
+ *
6
+ * @param username The username to validate
7
+ * @returns true if the username is valid
8
+ * @throws InvalidUsernameException if the username is invalid
9
+ */
10
+ static isValidUsername(username: string): boolean;
11
+ /**
12
+ * Removes the leading '0x' from a hex string.
13
+ *
14
+ * @param hex The hex string to process
15
+ * @returns The hex string without the leading '0x'
16
+ */
17
+ static removeLeadingHexZero(hex: string): string;
18
+ }
19
+ //# sourceMappingURL=Helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../src/utils/Helpers.ts"],"names":[],"mappings":"AAEA,qBAAa,OAAO;IACnB;;;;;;;OAOG;WACW,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAyBxD;;;;;OAKG;WACW,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAGvD"}
@@ -0,0 +1,38 @@
1
+ import { InvalidUsernameException } from "../exceptions/InvalidUsernameException";
2
+ export class Helpers {
3
+ /**
4
+ * Validates a username based on specific rules.
5
+ * Based on https://github.com/ArkEcosystem/mainsail/blob/develop/contracts/src/usernames/UsernamesV1.sol#L101
6
+ *
7
+ * @param username The username to validate
8
+ * @returns true if the username is valid
9
+ * @throws InvalidUsernameException if the username is invalid
10
+ */
11
+ static isValidUsername(username) {
12
+ if (username.length < 1 || username.length > 20) {
13
+ throw new InvalidUsernameException(`Username must be between 1 and 20 characters long. Got ${username.length} characters.`);
14
+ }
15
+ // Only lowercase letters, numbers and underscores are allowed
16
+ if (/[^a-z0-9_]/.test(username)) {
17
+ throw new InvalidUsernameException("Username can only contain lowercase letters, numbers and underscores.");
18
+ }
19
+ // Cannot start or end with underscore
20
+ if (/^_|_$/.test(username)) {
21
+ throw new InvalidUsernameException("Username cannot start or end with an underscore.");
22
+ }
23
+ // Cannot contain two or more consecutive underscores
24
+ if (/__/.test(username)) {
25
+ throw new InvalidUsernameException("Username cannot contain consecutive underscores.");
26
+ }
27
+ return true;
28
+ }
29
+ /**
30
+ * Removes the leading '0x' from a hex string.
31
+ *
32
+ * @param hex The hex string to process
33
+ * @returns The hex string without the leading '0x'
34
+ */
35
+ static removeLeadingHexZero(hex) {
36
+ return hex.replace(/^0x/, ""); // Using replace to only remove the prefix, not leading zeros
37
+ }
38
+ }
@@ -0,0 +1,14 @@
1
+ import { SignedMessage } from "../types";
2
+ export declare class Message {
3
+ publicKey: string;
4
+ signature: string;
5
+ message: string;
6
+ constructor(message: SignedMessage);
7
+ static new(message: SignedMessage): Message;
8
+ static sign(message: string, passphrase: string): Message;
9
+ verify(): boolean;
10
+ toString(): string;
11
+ toArray(): string[];
12
+ toJson(): SignedMessage;
13
+ }
14
+ //# sourceMappingURL=Message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/utils/Message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,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;IAI3C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAazD,MAAM,IAAI,OAAO;IAQjB,QAAQ,IAAI,MAAM;IAIlB,OAAO,IAAI,MAAM,EAAE;IAInB,MAAM,IAAI,aAAa;CAOvB"}
@@ -0,0 +1,43 @@
1
+ import { PrivateKey } from "../identities/PrivateKey";
2
+ import { PublicKey } from "../identities/PublicKey";
3
+ import { keccak256 } from "ethers";
4
+ import { verify } from "tiny-secp256k1";
5
+ export class Message {
6
+ constructor(message) {
7
+ this.publicKey = message.publicKey;
8
+ this.signature = message.signature;
9
+ this.message = message.message;
10
+ }
11
+ static new(message) {
12
+ return new Message(message);
13
+ }
14
+ static sign(message, passphrase) {
15
+ const privateKey = PrivateKey.fromPassphrase(passphrase);
16
+ const publicKey = PublicKey.fromPassphrase(passphrase).publicKey;
17
+ const signature = privateKey.sign(Buffer.from(message).toString("hex"));
18
+ return Message.new({
19
+ publicKey,
20
+ signature: signature.r + signature.s + Number(signature.v).toString(16),
21
+ message,
22
+ });
23
+ }
24
+ verify() {
25
+ const message = Buffer.from(keccak256(Buffer.from(this.message)).slice(2), "hex");
26
+ const signature = Buffer.from(this.signature.slice(0, 128), "hex");
27
+ const publicKey = Buffer.from(this.publicKey, "hex");
28
+ return verify(message, publicKey, signature, true);
29
+ }
30
+ toString() {
31
+ return JSON.stringify(this.toJson());
32
+ }
33
+ toArray() {
34
+ return [this.publicKey, this.signature, this.message];
35
+ }
36
+ toJson() {
37
+ return {
38
+ publicKey: this.publicKey,
39
+ signature: this.signature,
40
+ message: this.message,
41
+ };
42
+ }
43
+ }
@@ -0,0 +1,5 @@
1
+ export declare class Slot {
2
+ static time(): number;
3
+ static epoch(): number;
4
+ }
5
+ //# sourceMappingURL=Slot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Slot.d.ts","sourceRoot":"","sources":["../../src/utils/Slot.ts"],"names":[],"mappings":"AAEA,qBAAa,IAAI;IAChB,MAAM,CAAC,IAAI,IAAI,MAAM;IAIrB,MAAM,CAAC,KAAK,IAAI,MAAM;CAGtB"}
@@ -0,0 +1,9 @@
1
+ import { Network } from "../configuration/Network";
2
+ export class Slot {
3
+ static time() {
4
+ return Math.floor(Date.now() / 1000) - this.epoch();
5
+ }
6
+ static epoch() {
7
+ return Math.floor(new Date(Network.get().epoch()).getTime() / 1000);
8
+ }
9
+ }
@@ -0,0 +1,7 @@
1
+ import { TransactionData } from "../types";
2
+ export declare class TransactionUtils {
3
+ static toBuffer(transaction: TransactionData, skipSignature?: boolean): Buffer;
4
+ static toHash(transaction: TransactionData, skipSignature?: boolean): string;
5
+ static getId(transaction: TransactionData): string;
6
+ }
7
+ //# sourceMappingURL=TransactionUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/TransactionUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,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"}
@@ -0,0 +1,35 @@
1
+ import { encodeRlp, keccak256, toBeArray } from "ethers";
2
+ import { Constants } from "../enums/Constants";
3
+ export class TransactionUtils {
4
+ static toBuffer(transaction, skipSignature = false) {
5
+ var _a, _b, _c, _d, _e;
6
+ const fields = [
7
+ toBeArray((_a = transaction['network']) !== null && _a !== void 0 ? _a : 0),
8
+ toBeArray(transaction['nonce'] ? transaction['nonce'] : 0),
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 : '')),
17
+ [],
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']);
23
+ }
24
+ const encoded = encodeRlp(fields);
25
+ const payload = Constants.EIP_1559_PREFIX + encoded.substring(2);
26
+ return Buffer.from(payload);
27
+ }
28
+ static toHash(transaction, skipSignature = false) {
29
+ const encoding = this.toBuffer(transaction, skipSignature);
30
+ return keccak256('0x' + encoding.toString('binary')).substring(2);
31
+ }
32
+ static getId(transaction) {
33
+ return this.toHash(transaction, false);
34
+ }
35
+ }
@@ -0,0 +1,8 @@
1
+ import BigNumber from "bignumber.js";
2
+ export declare class UnitConverter {
3
+ static parseUnits(value: number | string, unit?: string): BigNumber;
4
+ static formatUnits(value: string, unit?: string): number;
5
+ static weiToArk(value: number | string, suffix?: string): string;
6
+ static gweiToArk(value: number | string, suffix?: string): string;
7
+ }
8
+ //# sourceMappingURL=UnitConverter.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,48 @@
1
+ import BigNumber from "bignumber.js";
2
+ const WEI_MULTIPLIER = 1;
3
+ const GWEI_MULTIPLIER = 1000000000; // 1e9
4
+ const ARK_MULTIPLIER = 1000000000000000000; // 1e18
5
+ export class UnitConverter {
6
+ static parseUnits(value, unit = 'ark') {
7
+ switch (unit.toLowerCase()) {
8
+ case 'wei':
9
+ return BigNumber(value).multipliedBy(WEI_MULTIPLIER);
10
+ case 'gwei':
11
+ return BigNumber(value).multipliedBy(GWEI_MULTIPLIER);
12
+ case 'ark':
13
+ return BigNumber(value).multipliedBy(ARK_MULTIPLIER);
14
+ default:
15
+ throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
16
+ }
17
+ }
18
+ static formatUnits(value, unit = 'ark') {
19
+ switch (unit.toLowerCase()) {
20
+ case 'wei':
21
+ return BigNumber(value).dividedBy(WEI_MULTIPLIER).toNumber();
22
+ case 'gwei':
23
+ return BigNumber(value).dividedBy(GWEI_MULTIPLIER).toNumber();
24
+ case 'ark':
25
+ return BigNumber(value).dividedBy(ARK_MULTIPLIER).toNumber();
26
+ default:
27
+ throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
28
+ }
29
+ }
30
+ static weiToArk(value, suffix) {
31
+ const convertedValue = new BigNumber(this.formatUnits(this.parseUnits(value, 'wei').toString(), 'ark'))
32
+ .decimalPlaces(18)
33
+ .toFixed();
34
+ if (suffix) {
35
+ return convertedValue + ' ' + suffix;
36
+ }
37
+ return convertedValue;
38
+ }
39
+ static gweiToArk(value, suffix) {
40
+ const convertedValue = new BigNumber(this.formatUnits(this.parseUnits(value, 'gwei').toString(), 'ark'))
41
+ .decimalPlaces(18)
42
+ .toFixed();
43
+ if (suffix) {
44
+ return convertedValue + ' ' + suffix;
45
+ }
46
+ return convertedValue;
47
+ }
48
+ }
@@ -0,0 +1,9 @@
1
+ export * from "./AbiBase";
2
+ export * from "./AbiDecoder";
3
+ export * from "./AbiEncoder";
4
+ export * from "./Helpers";
5
+ export * from "./Message";
6
+ export * from "./Slot";
7
+ export * from "./TransactionUtils";
8
+ export * from "./UnitConverter";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from "./AbiBase";
2
+ export * from "./AbiDecoder";
3
+ export * from "./AbiEncoder";
4
+ export * from "./Helpers";
5
+ export * from "./Message";
6
+ export * from "./Slot";
7
+ export * from "./TransactionUtils";
8
+ export * from "./UnitConverter";
package/jest.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'
2
+
3
+ const presetConfig = createDefaultEsmPreset()
4
+
5
+ const jestConfig: JestConfigWithTsJest = {
6
+ ...presetConfig,
7
+
8
+ moduleNameMapper: {
9
+ '^@/(.*)$': '<rootDir>/src/$1',
10
+ '^@tests/(.*)$': '<rootDir>/tests/$1',
11
+ },
12
+ }
13
+
14
+ export default jestConfig
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@arkecosystem/typescript-crypto",
3
+ "version": "0.0.1",
4
+ "engines": {
5
+ "node": ">=20.12.2"
6
+ },
7
+ "description": "A simple TypeScript Cryptography Implementation for the Mainsail blockchain.",
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "tsc && esbuild src/index.ts --outdir=dist --format=esm --bundle",
20
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/ArdentHQ/typescript-crypto/issues"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/ArdentHQ/typescript-crypto.git"
28
+ },
29
+ "keywords": [],
30
+ "author": "",
31
+ "license": "CC BY-NC-ND 4.0",
32
+ "devDependencies": {
33
+ "@jest/globals": "^29.7.0",
34
+ "@types/jest": "^29.5.14",
35
+ "@typescript-eslint/eslint-plugin": "^8.25.0",
36
+ "@typescript-eslint/parser": "^8.25.0",
37
+ "esbuild": "^0.25.0",
38
+ "esbuild-jest": "^0.5.0",
39
+ "eslint": "^9.21.0",
40
+ "eslint-config-prettier": "^10.0.2",
41
+ "eslint-plugin-prettier": "^5.2.3",
42
+ "jest": "^29.7.0",
43
+ "prettier": "^3.5.3",
44
+ "ts-jest": "^29.2.6",
45
+ "ts-node": "^10.9.2",
46
+ "typescript": "^5.8.2"
47
+ },
48
+ "dependencies": {
49
+ "@noble/secp256k1": "^2.2.3",
50
+ "bignumber.js": "^9.1.2",
51
+ "ethers": "^6.13.5",
52
+ "wif": "^5.0.0"
53
+ },
54
+ "pnpm": {
55
+ "onlyBuiltDependencies": [
56
+ "esbuild"
57
+ ]
58
+ }
59
+ }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ semi: true,
3
+ trailingComma: "all",
4
+ singleQuote: false,
5
+ printWidth: 120,
6
+ useTabs: true,
7
+ tabWidth: 4,
8
+ };
@@ -0,0 +1,18 @@
1
+ import { AbstractNetwork } from "@/networks/AbstractNetwork";
2
+ import { Testnet } from "@/networks/Testnet";
3
+
4
+ export class Network {
5
+ private static network: AbstractNetwork;
6
+
7
+ public static get(): AbstractNetwork {
8
+ if (!this.network) {
9
+ this.network = new Testnet();
10
+ }
11
+
12
+ return this.network;
13
+ }
14
+
15
+ public static set(network: AbstractNetwork): void {
16
+ this.network = network;
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ export * from "./Network";
@@ -0,0 +1,9 @@
1
+ export enum AbiFunction {
2
+ VOTE = "vote",
3
+ UNVOTE = "unvote",
4
+ VALIDATOR_REGISTRATION = "registerValidator",
5
+ VALIDATOR_RESIGNATION = "resignValidator",
6
+ USERNAME_REGISTRATION = "registerUsername",
7
+ USERNAME_RESIGNATION = "resignUsername",
8
+ MULTIPAYMENT = "pay",
9
+ }
@@ -0,0 +1,4 @@
1
+ export enum Constants {
2
+ EIP_1559_PREFIX = '02',
3
+ ETHEREUM_RECOVERY_ID_OFFSET = 27,
4
+ }
@@ -0,0 +1,6 @@
1
+ export enum ContractAbiType {
2
+ CUSTOM = 'custom',
3
+ CONSENSUS = 'consensus',
4
+ MULTIPAYMENT = 'multipayment',
5
+ USERNAMES = 'usernames',
6
+ }
@@ -0,0 +1,5 @@
1
+ export enum ContractAddresses {
2
+ CONSENSUS = "0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1",
3
+ MULTIPAYMENT = "0x00EFd0D4639191C49908A7BddbB9A11A994A8527",
4
+ USERNAMES = "0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6",
5
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./AbiFunction";
2
+ export * from "./Constants";
3
+ export * from "./ContractAbiType";
4
+ export * from "./ContractAddresses";
@@ -0,0 +1,6 @@
1
+ export class InvalidUsernameException extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = "InvalidUsernameException";
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export * from "./InvalidUsernameException"
@@ -0,0 +1,19 @@
1
+ import { ethers, sha256 } from "ethers";
2
+
3
+ export class Address {
4
+ static fromPassphrase(passphrase: string): string {
5
+ return this.fromPrivateKey(sha256(Buffer.from(passphrase)));
6
+ }
7
+
8
+ static fromPublicKey(publicKey: string): string {
9
+ return ethers.computeAddress(`0x${publicKey}`);
10
+ }
11
+
12
+ static fromPrivateKey(privateKey: string): string {
13
+ return new ethers.Wallet(privateKey).address;
14
+ }
15
+
16
+ static validate(address: string): boolean {
17
+ return ethers.isAddress(address);
18
+ }
19
+ }
@@ -0,0 +1,49 @@
1
+ import * as WIF from "wif";
2
+
3
+ import { ethers, keccak256, sha256 } from "ethers";
4
+ import { signAsync } from "@noble/secp256k1";
5
+
6
+ import { Constants } from "@/enums/Constants";
7
+ import { Network } from "@/configuration/Network";
8
+
9
+ type RecoverableSignature = {
10
+ r: string;
11
+ s: string;
12
+ v: number;
13
+ };
14
+
15
+ export class PrivateKey {
16
+ public privateKey: string;
17
+
18
+ constructor(keyPair: ethers.Wallet) {
19
+ this.privateKey = keyPair.privateKey.substring(2);
20
+ }
21
+
22
+ static fromPassphrase(passphrase: string): PrivateKey {
23
+ return PrivateKey.fromHex(sha256(Buffer.from(passphrase)));
24
+ }
25
+
26
+ static fromHex(hex: string): PrivateKey {
27
+ const wallet = new ethers.Wallet(hex);
28
+
29
+ return new PrivateKey(wallet);
30
+ }
31
+
32
+ static fromWif(wif: string): PrivateKey {
33
+ const decodedWif = WIF.decode(wif, Buffer.from(Network.get().getWif(), "hex").readUInt8());
34
+
35
+ return PrivateKey.fromHex(Buffer.from(decodedWif.privateKey).toString("hex"));
36
+ }
37
+
38
+ async sign(message: string): Promise<RecoverableSignature> {
39
+ const hash = keccak256("0x" + message).slice(2);
40
+
41
+ const signature = await signAsync(hash, this.privateKey);
42
+
43
+ return {
44
+ r: signature.r.toString(16).padStart(64, "0"),
45
+ s: signature.s.toString(16).padStart(64, "0"),
46
+ v: signature.recovery + Constants.ETHEREUM_RECOVERY_ID_OFFSET,
47
+ };
48
+ }
49
+ }
@@ -0,0 +1,28 @@
1
+ import { sha256, SigningKey } from "ethers";
2
+ import { Signature } from "@noble/secp256k1";
3
+
4
+ export class PublicKey {
5
+ public publicKey: string;
6
+
7
+ constructor(publicKey: string) {
8
+ this.publicKey = publicKey;
9
+ }
10
+
11
+ static fromPassphrase(passphrase: string): PublicKey {
12
+ const publicKey = SigningKey.computePublicKey(sha256(Buffer.from(passphrase)), true).substring(2);
13
+
14
+ return new PublicKey(publicKey);
15
+ }
16
+
17
+ static fromHex(publicKey: string): PublicKey {
18
+ const computedPublicKey = SigningKey.computePublicKey(`0x${publicKey}`).substring(2);
19
+
20
+ return new PublicKey(computedPublicKey);
21
+ }
22
+
23
+ static recover(message: Buffer, r: bigint, s: bigint, v: number): PublicKey {
24
+ const publicKey = new Signature(r, s, v).recoverPublicKey(message);
25
+
26
+ return new PublicKey(publicKey.toHex());
27
+ }
28
+ }
@@ -0,0 +1,16 @@
1
+ import { sha256 } from "ethers";
2
+ import { Network } from "@/configuration/Network";
3
+ import * as WIFPackage from "wif";
4
+ import { PrivateKey } from "./PrivateKey";
5
+
6
+ export class WIF {
7
+ static fromPassphrase(passphrase: string): string {
8
+ const privateKey = PrivateKey.fromPassphrase(passphrase);
9
+
10
+ return WIFPackage.encode({
11
+ version: Buffer.from(Network.get().getWif(), 'hex').readUInt8(),
12
+ privateKey: Buffer.from(privateKey.privateKey, 'hex'),
13
+ compressed: true,
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./Address";
2
+ export * from "./PrivateKey";
3
+ export * from "./PublicKey";
4
+ export * from "./WIF";