quantumcoin 7.0.11 → 7.0.13

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 (324) hide show
  1. package/README-SDK.md +828 -807
  2. package/README.md +17 -0
  3. package/config.d.ts +50 -50
  4. package/examples/example-generated-sdk-js/README.md +65 -0
  5. package/examples/example-generated-sdk-js/examples/_test-wallet.js +17 -0
  6. package/examples/example-generated-sdk-js/examples/deploy.js +41 -0
  7. package/examples/example-generated-sdk-js/examples/events.js +36 -0
  8. package/examples/example-generated-sdk-js/examples/read-operations.js +46 -0
  9. package/examples/example-generated-sdk-js/examples/write-operations.js +44 -0
  10. package/examples/example-generated-sdk-js/index.d.ts +1 -0
  11. package/examples/example-generated-sdk-js/index.js +15 -0
  12. package/examples/example-generated-sdk-js/package-lock.json +59 -0
  13. package/examples/example-generated-sdk-js/package.json +22 -0
  14. package/examples/example-generated-sdk-js/src/SimpleERC20.d.ts +19 -0
  15. package/examples/example-generated-sdk-js/src/SimpleERC20.js +353 -0
  16. package/examples/example-generated-sdk-js/src/SimpleERC20__factory.d.ts +10 -0
  17. package/examples/example-generated-sdk-js/src/SimpleERC20__factory.js +29 -0
  18. package/examples/example-generated-sdk-js/src/index.d.ts +4 -0
  19. package/examples/example-generated-sdk-js/src/index.js +5 -0
  20. package/examples/example-generated-sdk-js/src/quantumcoin-shims.d.ts +23 -0
  21. package/examples/example-generated-sdk-js/src/types.d.ts +3 -0
  22. package/examples/example-generated-sdk-js/src/types.js +3 -0
  23. package/examples/example-generated-sdk-js/test/e2e/SimpleERC20.e2e.test.js +78 -0
  24. package/examples/example-generated-sdk-ts/README.md +65 -0
  25. package/examples/example-generated-sdk-ts/examples/_test-wallet.js +17 -0
  26. package/examples/example-generated-sdk-ts/examples/deploy.js +41 -0
  27. package/examples/example-generated-sdk-ts/examples/events.js +36 -0
  28. package/examples/example-generated-sdk-ts/examples/read-operations.js +46 -0
  29. package/examples/example-generated-sdk-ts/examples/write-operations.js +44 -0
  30. package/examples/example-generated-sdk-ts/index.d.ts +1 -0
  31. package/examples/example-generated-sdk-ts/index.js +15 -0
  32. package/examples/example-generated-sdk-ts/package-lock.json +59 -0
  33. package/examples/example-generated-sdk-ts/package.json +23 -0
  34. package/examples/example-generated-sdk-ts/src/SimpleERC20.ts +334 -0
  35. package/examples/example-generated-sdk-ts/src/SimpleERC20__factory.ts +28 -0
  36. package/examples/example-generated-sdk-ts/src/index.ts +4 -0
  37. package/examples/example-generated-sdk-ts/src/quantumcoin-shims.d.ts +23 -0
  38. package/examples/example-generated-sdk-ts/src/types.ts +4 -0
  39. package/examples/example-generated-sdk-ts/test/e2e/SimpleERC20.e2e.test.js +78 -0
  40. package/examples/example-generated-sdk-ts/tsconfig.json +14 -0
  41. package/examples/package-lock.json +1 -1
  42. package/examples/sdk-generator-erc20.inline.json +251 -251
  43. package/generate-sdk.js +1825 -1823
  44. package/package.json +1 -1
  45. package/src/abi/fragments.d.ts +42 -42
  46. package/src/abi/index.d.ts +13 -13
  47. package/src/contract/index.d.ts +9 -9
  48. package/src/errors/index.d.ts +92 -92
  49. package/src/generator/index.d.ts +11 -4
  50. package/src/generator/index.js +33 -5
  51. package/src/internal/hex.d.ts +68 -61
  52. package/src/internal/hex.js +36 -0
  53. package/src/providers/json-rpc-provider.d.ts +12 -12
  54. package/src/providers/provider.js +3 -3
  55. package/src/utils/address.d.ts +58 -58
  56. package/src/utils/encoding.d.ts +120 -120
  57. package/src/utils/hashing.js +298 -298
  58. package/src/utils/index.d.ts +63 -63
  59. package/src/utils/index.js +14 -14
  60. package/src/utils/result.d.ts +57 -57
  61. package/src/utils/rlp.d.ts +12 -12
  62. package/src/utils/units.d.ts +29 -29
  63. package/src/wallet/index.d.ts +10 -10
  64. package/src/wallet/wallet.d.ts +192 -187
  65. package/src/wallet/wallet.js +630 -610
  66. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/README.md +83 -0
  67. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/artifacts/AllSolidityTypes.abi.json +12544 -0
  68. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/artifacts/AllSolidityTypes.bin +1 -0
  69. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/_test-wallet.js +17 -0
  70. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/_test-wallet.ts +10 -0
  71. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/deploy.js +41 -0
  72. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/deploy.ts +41 -0
  73. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/events.js +36 -0
  74. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/events.ts +36 -0
  75. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/offline-signing.js +82 -0
  76. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/offline-signing.ts +80 -0
  77. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/read-operations.js +46 -0
  78. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/read-operations.ts +44 -0
  79. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/write-operations.js +44 -0
  80. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/write-operations.ts +44 -0
  81. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/index.d.ts +1 -0
  82. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/index.js +21 -0
  83. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/package-lock.json +597 -0
  84. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/package.json +25 -0
  85. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes.d.ts +1280 -0
  86. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes.js +14021 -0
  87. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes__factory.d.ts +11 -0
  88. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes__factory.js +29 -0
  89. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/index.d.ts +4 -0
  90. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/index.js +5 -0
  91. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/quantumcoin-shims.d.ts +25 -0
  92. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/types.d.ts +3 -0
  93. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/types.js +3 -0
  94. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/test/e2e/AllSolidityTypes.e2e.test.js +77 -0
  95. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/test/e2e/AllSolidityTypes.extra.test.js +195 -0
  96. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/README.md +83 -0
  97. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/artifacts/AllSolidityTypes.abi.json +12544 -0
  98. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/artifacts/AllSolidityTypes.bin +1 -0
  99. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/_test-wallet.js +17 -0
  100. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/_test-wallet.ts +10 -0
  101. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/deploy.js +41 -0
  102. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/deploy.ts +41 -0
  103. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/events.js +36 -0
  104. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/events.ts +36 -0
  105. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/offline-signing.js +82 -0
  106. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/offline-signing.ts +80 -0
  107. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/read-operations.js +46 -0
  108. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/read-operations.ts +44 -0
  109. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/write-operations.js +44 -0
  110. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/write-operations.ts +44 -0
  111. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/index.d.ts +1 -0
  112. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/index.js +21 -0
  113. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/package-lock.json +597 -0
  114. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/package.json +26 -0
  115. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/AllSolidityTypes.ts +13940 -0
  116. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/AllSolidityTypes__factory.ts +29 -0
  117. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/index.ts +4 -0
  118. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/quantumcoin-shims.d.ts +25 -0
  119. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/types.ts +4 -0
  120. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/test/e2e/AllSolidityTypes.e2e.test.js +77 -0
  121. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/test/e2e/AllSolidityTypes.extra.test.js +195 -0
  122. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/tsconfig.json +18 -0
  123. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/README.md +74 -0
  124. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/artifacts/SimpleERC20.abi.json +245 -0
  125. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/artifacts/SimpleERC20.bin +1 -0
  126. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/_test-wallet.js +17 -0
  127. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/_test-wallet.ts +10 -0
  128. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/deploy.js +41 -0
  129. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/deploy.ts +41 -0
  130. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/events.js +36 -0
  131. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/events.ts +36 -0
  132. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/offline-signing.js +82 -0
  133. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/offline-signing.ts +80 -0
  134. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/read-operations.js +46 -0
  135. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/read-operations.ts +44 -0
  136. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/write-operations.js +44 -0
  137. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/write-operations.ts +44 -0
  138. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/index.d.ts +1 -0
  139. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/index.js +16 -0
  140. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/package-lock.json +597 -0
  141. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/package.json +25 -0
  142. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20.d.ts +24 -0
  143. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20.js +372 -0
  144. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20__factory.d.ts +10 -0
  145. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20__factory.js +29 -0
  146. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/index.d.ts +4 -0
  147. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/index.js +5 -0
  148. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/quantumcoin-shims.d.ts +25 -0
  149. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/types.d.ts +3 -0
  150. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/types.js +3 -0
  151. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/test/e2e/SimpleERC20.e2e.test.js +90 -0
  152. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/README.md +74 -0
  153. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/artifacts/SimpleERC20.abi.json +245 -0
  154. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/artifacts/SimpleERC20.bin +1 -0
  155. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/_test-wallet.js +17 -0
  156. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/_test-wallet.ts +10 -0
  157. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/deploy.js +41 -0
  158. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/deploy.ts +41 -0
  159. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/events.js +36 -0
  160. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/events.ts +36 -0
  161. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/offline-signing.js +82 -0
  162. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/offline-signing.ts +80 -0
  163. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/read-operations.js +46 -0
  164. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/read-operations.ts +44 -0
  165. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/write-operations.js +44 -0
  166. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/write-operations.ts +44 -0
  167. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/index.d.ts +1 -0
  168. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/index.js +16 -0
  169. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/package-lock.json +597 -0
  170. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/package.json +26 -0
  171. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/SimpleERC20.ts +355 -0
  172. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/SimpleERC20__factory.ts +28 -0
  173. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/index.ts +4 -0
  174. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/quantumcoin-shims.d.ts +25 -0
  175. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/types.ts +4 -0
  176. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/test/e2e/SimpleERC20.e2e.test.js +90 -0
  177. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/tsconfig.json +18 -0
  178. package/test/e2e/generator-interface.e2e.test.js +163 -0
  179. package/test/e2e/generator-interface.e2e.test.ts +158 -0
  180. package/test/e2e/signing-context-and-fee.e2e.test.js +141 -141
  181. package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -128
  182. package/test/integration/provider.test.js +88 -88
  183. package/test/unit/address-wallet.test.js +892 -751
  184. package/test/unit/address-wallet.test.ts +877 -736
  185. package/test/unit/generator.test.js +48 -1
  186. package/test/unit/generator.test.ts +48 -1
  187. package/test/unit/hashing.test.js +64 -64
  188. package/test/unit/hashing.test.ts +63 -63
  189. package/test/unit/internal-hex.test.js +32 -1
  190. package/test/unit/internal-hex.test.ts +32 -1
  191. package/test/unit/providers.test.js +51 -1
  192. package/test/unit/providers.test.ts +53 -0
  193. package/SPEC.md +0 -3784
  194. package/examples/node_modules/.bin/esbuild +0 -16
  195. package/examples/node_modules/.bin/esbuild.cmd +0 -17
  196. package/examples/node_modules/.bin/esbuild.ps1 +0 -28
  197. package/examples/node_modules/.bin/sdkgen +0 -16
  198. package/examples/node_modules/.bin/sdkgen.cmd +0 -17
  199. package/examples/node_modules/.bin/sdkgen.ps1 +0 -28
  200. package/examples/node_modules/.bin/tsx +0 -16
  201. package/examples/node_modules/.bin/tsx.cmd +0 -17
  202. package/examples/node_modules/.bin/tsx.ps1 +0 -28
  203. package/examples/node_modules/.package-lock.json +0 -235
  204. package/examples/node_modules/@esbuild/win32-x64/README.md +0 -3
  205. package/examples/node_modules/@esbuild/win32-x64/esbuild.exe +0 -0
  206. package/examples/node_modules/@esbuild/win32-x64/package.json +0 -20
  207. package/examples/node_modules/esbuild/LICENSE.md +0 -21
  208. package/examples/node_modules/esbuild/README.md +0 -3
  209. package/examples/node_modules/esbuild/bin/esbuild +0 -223
  210. package/examples/node_modules/esbuild/install.js +0 -289
  211. package/examples/node_modules/esbuild/lib/main.d.ts +0 -716
  212. package/examples/node_modules/esbuild/lib/main.js +0 -2532
  213. package/examples/node_modules/esbuild/package.json +0 -49
  214. package/examples/node_modules/get-tsconfig/LICENSE +0 -21
  215. package/examples/node_modules/get-tsconfig/README.md +0 -235
  216. package/examples/node_modules/get-tsconfig/dist/index.cjs +0 -7
  217. package/examples/node_modules/get-tsconfig/dist/index.d.cts +0 -2088
  218. package/examples/node_modules/get-tsconfig/dist/index.d.mts +0 -2088
  219. package/examples/node_modules/get-tsconfig/dist/index.mjs +0 -7
  220. package/examples/node_modules/get-tsconfig/package.json +0 -46
  221. package/examples/node_modules/quantum-coin-js-sdk/.github/workflows/publish-npmjs.yaml +0 -22
  222. package/examples/node_modules/quantum-coin-js-sdk/LICENSE +0 -21
  223. package/examples/node_modules/quantum-coin-js-sdk/LICENSE-wasm_exec.js.txt +0 -30
  224. package/examples/node_modules/quantum-coin-js-sdk/README.md +0 -1665
  225. package/examples/node_modules/quantum-coin-js-sdk/example/README.md +0 -14
  226. package/examples/node_modules/quantum-coin-js-sdk/example/conversion-example.js +0 -19
  227. package/examples/node_modules/quantum-coin-js-sdk/example/example-create-contract.js +0 -396
  228. package/examples/node_modules/quantum-coin-js-sdk/example/example-encode-decode-rlp.js +0 -225
  229. package/examples/node_modules/quantum-coin-js-sdk/example/example-event-pack-unpack.js +0 -391
  230. package/examples/node_modules/quantum-coin-js-sdk/example/example-misc.js +0 -101
  231. package/examples/node_modules/quantum-coin-js-sdk/example/example-rpc-send-signRawTransaction.js +0 -318
  232. package/examples/node_modules/quantum-coin-js-sdk/example/example-rpc-send.js +0 -116
  233. package/examples/node_modules/quantum-coin-js-sdk/example/example-send.js +0 -70
  234. package/examples/node_modules/quantum-coin-js-sdk/example/example-token-pack-unpack.js +0 -961
  235. package/examples/node_modules/quantum-coin-js-sdk/example/example-wallet-version4.js +0 -35
  236. package/examples/node_modules/quantum-coin-js-sdk/example/example-wallet.js +0 -43
  237. package/examples/node_modules/quantum-coin-js-sdk/example/example.js +0 -405
  238. package/examples/node_modules/quantum-coin-js-sdk/example/package-lock.json +0 -134
  239. package/examples/node_modules/quantum-coin-js-sdk/example/package.json +0 -15
  240. package/examples/node_modules/quantum-coin-js-sdk/index.d.ts +0 -1024
  241. package/examples/node_modules/quantum-coin-js-sdk/index.js +0 -3062
  242. package/examples/node_modules/quantum-coin-js-sdk/package.json +0 -34
  243. package/examples/node_modules/quantum-coin-js-sdk/tests/encrypted-32.json +0 -1
  244. package/examples/node_modules/quantum-coin-js-sdk/tests/encrypted-36.json +0 -1
  245. package/examples/node_modules/quantum-coin-js-sdk/tests/encrypted-48.json +0 -1
  246. package/examples/node_modules/quantum-coin-js-sdk/tests/generate-verify-vectors.js +0 -91
  247. package/examples/node_modules/quantum-coin-js-sdk/tests/non-transactional.preinit.test.js +0 -41
  248. package/examples/node_modules/quantum-coin-js-sdk/tests/non-transactional.test.js +0 -686
  249. package/examples/node_modules/quantum-coin-js-sdk/tests/sign-raw-keytype5-context-null.test.js +0 -107
  250. package/examples/node_modules/quantum-coin-js-sdk/tests/sign-raw-transaction.test.js +0 -196
  251. package/examples/node_modules/quantum-coin-js-sdk/tests/sign-verify.test.js +0 -311
  252. package/examples/node_modules/quantum-coin-js-sdk/tests/transactional.relay.test.js +0 -131
  253. package/examples/node_modules/quantum-coin-js-sdk/tests/transactional.rpc.test.js +0 -103
  254. package/examples/node_modules/quantum-coin-js-sdk/tests/verify-vectors.json +0 -95035
  255. package/examples/node_modules/quantum-coin-js-sdk/wasmBase64.d.ts +0 -9
  256. package/examples/node_modules/quantum-coin-js-sdk/wasmBase64.js +0 -16
  257. package/examples/node_modules/quantum-coin-js-sdk/wasm_exec.d.ts +0 -0
  258. package/examples/node_modules/quantum-coin-js-sdk/wasm_exec.js +0 -587
  259. package/examples/node_modules/resolve-pkg-maps/LICENSE +0 -21
  260. package/examples/node_modules/resolve-pkg-maps/README.md +0 -216
  261. package/examples/node_modules/resolve-pkg-maps/dist/index.cjs +0 -1
  262. package/examples/node_modules/resolve-pkg-maps/dist/index.d.cts +0 -11
  263. package/examples/node_modules/resolve-pkg-maps/dist/index.d.mts +0 -11
  264. package/examples/node_modules/resolve-pkg-maps/dist/index.mjs +0 -1
  265. package/examples/node_modules/resolve-pkg-maps/package.json +0 -42
  266. package/examples/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
  267. package/examples/node_modules/seed-words/BUILD.md +0 -7
  268. package/examples/node_modules/seed-words/LICENSE +0 -121
  269. package/examples/node_modules/seed-words/README.md +0 -67
  270. package/examples/node_modules/seed-words/dist/seedwords.d.ts +0 -39
  271. package/examples/node_modules/seed-words/package.json +0 -27
  272. package/examples/node_modules/seed-words/seedwords.js +0 -315
  273. package/examples/node_modules/seed-words/seedwords.txt +0 -65536
  274. package/examples/node_modules/seed-words/tsconfig.json +0 -21
  275. package/examples/node_modules/tsx/LICENSE +0 -21
  276. package/examples/node_modules/tsx/README.md +0 -32
  277. package/examples/node_modules/tsx/dist/cjs/api/index.cjs +0 -1
  278. package/examples/node_modules/tsx/dist/cjs/api/index.d.cts +0 -35
  279. package/examples/node_modules/tsx/dist/cjs/api/index.d.mts +0 -35
  280. package/examples/node_modules/tsx/dist/cjs/api/index.mjs +0 -1
  281. package/examples/node_modules/tsx/dist/cjs/index.cjs +0 -1
  282. package/examples/node_modules/tsx/dist/cjs/index.mjs +0 -1
  283. package/examples/node_modules/tsx/dist/cli.cjs +0 -54
  284. package/examples/node_modules/tsx/dist/cli.mjs +0 -55
  285. package/examples/node_modules/tsx/dist/client-BQVF1NaW.mjs +0 -1
  286. package/examples/node_modules/tsx/dist/client-D6NvIMSC.cjs +0 -1
  287. package/examples/node_modules/tsx/dist/esm/api/index.cjs +0 -1
  288. package/examples/node_modules/tsx/dist/esm/api/index.d.cts +0 -35
  289. package/examples/node_modules/tsx/dist/esm/api/index.d.mts +0 -35
  290. package/examples/node_modules/tsx/dist/esm/api/index.mjs +0 -1
  291. package/examples/node_modules/tsx/dist/esm/index.cjs +0 -2
  292. package/examples/node_modules/tsx/dist/esm/index.mjs +0 -2
  293. package/examples/node_modules/tsx/dist/get-pipe-path-BHW2eJdv.mjs +0 -1
  294. package/examples/node_modules/tsx/dist/get-pipe-path-BoR10qr8.cjs +0 -1
  295. package/examples/node_modules/tsx/dist/index-7AaEi15b.mjs +0 -14
  296. package/examples/node_modules/tsx/dist/index-BWFBUo6r.cjs +0 -1
  297. package/examples/node_modules/tsx/dist/index-gbaejti9.mjs +0 -1
  298. package/examples/node_modules/tsx/dist/index-gckBtVBf.cjs +0 -14
  299. package/examples/node_modules/tsx/dist/lexer-DQCqS3nf.mjs +0 -3
  300. package/examples/node_modules/tsx/dist/lexer-DgIbo0BU.cjs +0 -3
  301. package/examples/node_modules/tsx/dist/loader.cjs +0 -1
  302. package/examples/node_modules/tsx/dist/loader.mjs +0 -1
  303. package/examples/node_modules/tsx/dist/node-features-_8ZFwP_x.mjs +0 -1
  304. package/examples/node_modules/tsx/dist/node-features-roYmp9jK.cjs +0 -1
  305. package/examples/node_modules/tsx/dist/package-CeBgXWuR.mjs +0 -1
  306. package/examples/node_modules/tsx/dist/package-Dxt5kIHw.cjs +0 -1
  307. package/examples/node_modules/tsx/dist/patch-repl.cjs +0 -1
  308. package/examples/node_modules/tsx/dist/patch-repl.mjs +0 -1
  309. package/examples/node_modules/tsx/dist/preflight.cjs +0 -1
  310. package/examples/node_modules/tsx/dist/preflight.mjs +0 -1
  311. package/examples/node_modules/tsx/dist/register-2sWVXuRQ.cjs +0 -1
  312. package/examples/node_modules/tsx/dist/register-B7jrtLTO.mjs +0 -1
  313. package/examples/node_modules/tsx/dist/register-CFH5oNdT.mjs +0 -4
  314. package/examples/node_modules/tsx/dist/register-D46fvsV_.cjs +0 -4
  315. package/examples/node_modules/tsx/dist/repl.cjs +0 -3
  316. package/examples/node_modules/tsx/dist/repl.mjs +0 -3
  317. package/examples/node_modules/tsx/dist/require-D4F1Lv60.cjs +0 -1
  318. package/examples/node_modules/tsx/dist/require-DQxpCAr4.mjs +0 -1
  319. package/examples/node_modules/tsx/dist/suppress-warnings.cjs +0 -1
  320. package/examples/node_modules/tsx/dist/suppress-warnings.mjs +0 -1
  321. package/examples/node_modules/tsx/dist/temporary-directory-B83uKxJF.cjs +0 -1
  322. package/examples/node_modules/tsx/dist/temporary-directory-CwHp0_NW.mjs +0 -1
  323. package/examples/node_modules/tsx/dist/types-Cxp8y2TL.d.ts +0 -5
  324. package/examples/node_modules/tsx/package.json +0 -68
@@ -1,610 +1,630 @@
1
- /**
2
- * @fileoverview Wallet and signer implementations.
3
- *
4
- * The QuantumCoin.js wallet model mirrors ethers.js v6:
5
- * - AbstractSigner -> BaseWallet -> Wallet
6
- * - NonceManager wrapper
7
- *
8
- * Cryptographic operations are delegated to `quantum-coin-js-sdk`.
9
- */
10
-
11
- const qcsdk = require("quantum-coin-js-sdk");
12
- const { JsonRpcProvider } = require("../providers/json-rpc-provider");
13
- const { assertArgument, assertSecretArgument, makeError } = require("../errors");
14
- const { arrayify, bytesToHex, hexToBytes, isHexString, normalizeHex } = require("../internal/hex");
15
- const { getAddress } = require("../utils/address");
16
- const { WeiPerEther } = require("../constants");
17
-
18
- function _requireInitialized() {
19
- // eslint-disable-next-line global-require
20
- const { isInitialized, getInitializationPromise } = require("../../config");
21
- if (isInitialized()) return;
22
- if (getInitializationPromise() != null) {
23
- throw makeError(
24
- "QuantumCoin SDK is still initializing. Await the Initialize() promise before using SDK methods.",
25
- "UNKNOWN_ERROR",
26
- { operation: "requireInitialized" },
27
- );
28
- }
29
- throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", { operation: "wallet" });
30
- }
31
-
32
- function _bytesToNumberArray(bytes) {
33
- return Array.from(bytes);
34
- }
35
-
36
- const _maxSafeInt = 0x1fffffffffffffn; // 2^53 - 1
37
-
38
- function _getBigInt(value, name) {
39
- if (typeof value === "bigint") return value;
40
- if (typeof value === "number") {
41
- assertArgument(Number.isInteger(value), "underflow", name, value);
42
- assertArgument(value >= -Number(_maxSafeInt) && value <= Number(_maxSafeInt), "overflow", name, value);
43
- return BigInt(value);
44
- }
45
- if (typeof value === "string") {
46
- if (value === "0x" || value === "0X") return 0n;
47
- try { return BigInt(value); }
48
- catch { assertArgument(false, "invalid BigNumberish string", name, value); }
49
- }
50
- assertArgument(false, "invalid BigNumberish", name, value);
51
- }
52
-
53
- function _getNumber(value, name) {
54
- const bi = _getBigInt(value, name);
55
- assertArgument(bi >= -_maxSafeInt && bi <= _maxSafeInt, "overflow", name, value);
56
- return Number(bi);
57
- }
58
-
59
- /**
60
- * SigningKey wrapper (PQC private/public key bytes).
61
- */
62
- class SigningKey {
63
- /**
64
- * @param {Uint8Array} privateKeyBytes
65
- * @param {Uint8Array} publicKeyBytes
66
- */
67
- constructor(privateKeyBytes, publicKeyBytes) {
68
- Object.defineProperty(this, "privateKeyBytes", {
69
- enumerable: false,
70
- configurable: false,
71
- writable: false,
72
- value: new Uint8Array(privateKeyBytes),
73
- });
74
- this.publicKeyBytes = new Uint8Array(publicKeyBytes);
75
- }
76
-
77
- toJSON() {
78
- return {};
79
- }
80
- }
81
-
82
- /**
83
- * AbstractSigner base (minimal).
84
- */
85
- class AbstractSigner {
86
- /**
87
- * @param {import("../providers/provider").AbstractProvider|null} provider
88
- */
89
- constructor(provider) {
90
- this.provider = provider || null;
91
- }
92
-
93
- async getAddress() {
94
- throw makeError("getAddress not implemented", "NOT_IMPLEMENTED", {});
95
- }
96
- }
97
-
98
- /**
99
- * BaseWallet - core signing implementation.
100
- */
101
- class BaseWallet extends AbstractSigner {
102
- /**
103
- * @param {SigningKey} signingKey
104
- * @param {import("../providers/provider").AbstractProvider|null=} provider
105
- * @param {{ address: string }=} precomputed
106
- * @param {any=} qcWallet Internal quantum-coin-js-sdk Wallet (optional)
107
- */
108
- constructor(signingKey, provider, precomputed, qcWallet) {
109
- super(provider || null);
110
- _requireInitialized();
111
-
112
- Object.defineProperty(this, "signingKey", {
113
- enumerable: false,
114
- configurable: false,
115
- writable: false,
116
- value: signingKey,
117
- });
118
- Object.defineProperty(this, "_qcWallet", {
119
- enumerable: false,
120
- configurable: true,
121
- writable: true,
122
- value: qcWallet || null,
123
- });
124
-
125
- /** @type {string} */
126
- this.address = precomputed?.address || "";
127
-
128
- Object.defineProperty(this, "privateKey", {
129
- enumerable: false,
130
- get: () => bytesToHex(this.signingKey.privateKeyBytes),
131
- });
132
-
133
- Object.defineProperty(this, "publicKey", {
134
- enumerable: true,
135
- get: () => bytesToHex(this.signingKey.publicKeyBytes),
136
- });
137
-
138
- Object.defineProperty(this, "_seed", {
139
- enumerable: false,
140
- configurable: true,
141
- writable: true,
142
- value: null,
143
- });
144
-
145
- Object.defineProperty(this, "seed", {
146
- enumerable: false,
147
- get: () => this._seed,
148
- });
149
- }
150
-
151
- toJSON() {
152
- return { address: this.address };
153
- }
154
-
155
- async getAddress() {
156
- return this.address;
157
- }
158
-
159
- /**
160
- * Sign a transaction using quantum-coin-js-sdk signRawTransaction().
161
- * @param {import("../providers/provider").TransactionRequest} tx
162
- * @returns {Promise<string>}
163
- */
164
- async signTransaction(tx) {
165
- _requireInitialized();
166
- assertArgument(tx && typeof tx === "object", "invalid tx", "tx", tx);
167
-
168
- const toAddress = tx.to == null ? null : getAddress(tx.to);
169
- const valueInWei = tx.value == null ? 0n : _getBigInt(tx.value, "tx.value");
170
- const gasLimit = tx.gasLimit == null ? 21000 : _getNumber(tx.gasLimit, "tx.gasLimit");
171
-
172
- const data = tx.data == null ? null : normalizeHex(tx.data);
173
- const remarks = tx.remarks == null ? null : normalizeHex(tx.remarks);
174
-
175
- if (remarks != null) {
176
- assertArgument(isHexString(remarks), "remarks must be hex string", "remarks", remarks);
177
- const remarkBytes = hexToBytes(remarks);
178
- assertArgument(remarkBytes.length <= 32, "remarks too long (max 32 bytes)", "remarks", remarks);
179
- }
180
-
181
- // Nonce must be provided or resolved from provider.
182
- let nonce = tx.nonce;
183
- if (nonce == null) {
184
- if (!this.provider) throw makeError("missing provider to resolve nonce", "UNKNOWN_ERROR", { operation: "signTransaction" });
185
- // Prefer pending to avoid nonce collisions with in-flight transactions.
186
- try {
187
- nonce = await this.provider.getTransactionCount(this.address, "pending");
188
- } catch {
189
- nonce = await this.provider.getTransactionCount(this.address, "latest");
190
- }
191
- }
192
- assertArgument(Number.isInteger(nonce) && nonce >= 0, "invalid nonce", "nonce", nonce);
193
-
194
- const chainId = tx.chainId != null ? tx.chainId : (this.provider && this.provider.chainId != null ? this.provider.chainId : null);
195
- const signingContext = tx.signingContext ?? null;
196
-
197
- /** @type {any} */
198
- const qcWallet =
199
- this._qcWallet ||
200
- new qcsdk.Wallet(
201
- this.address,
202
- _bytesToNumberArray(this.signingKey.privateKeyBytes),
203
- _bytesToNumberArray(this.signingKey.publicKeyBytes),
204
- );
205
-
206
- const req = new qcsdk.TransactionSigningRequest(
207
- qcWallet,
208
- toAddress,
209
- valueInWei,
210
- nonce,
211
- data,
212
- gasLimit,
213
- remarks,
214
- chainId,
215
- signingContext,
216
- );
217
- const signResult = qcsdk.signRawTransaction(req);
218
- // quantum-coin-js-sdk returns a SignResult object: { resultCode, txnHash, txnData }
219
- if (!signResult || typeof signResult !== "object") {
220
- throw makeError("signRawTransaction failed", "UNKNOWN_ERROR", {});
221
- }
222
- if (typeof signResult.resultCode === "number" && signResult.resultCode !== 0) {
223
- throw makeError("signRawTransaction failed", "UNKNOWN_ERROR", {
224
- resultCode: signResult.resultCode,
225
- hash: signResult.txnHash || null,
226
- });
227
- }
228
- const raw = signResult.txnData;
229
- if (typeof raw !== "string") throw makeError("signRawTransaction did not return txnData", "UNKNOWN_ERROR", {});
230
- return normalizeHex(raw);
231
- }
232
-
233
- /**
234
- * Signs and sends a transaction.
235
- * @param {import("../providers/provider").TransactionRequest} tx
236
- * @returns {Promise<import("../providers/provider").TransactionResponse>}
237
- */
238
- async sendTransaction(tx) {
239
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "sendTransaction" });
240
- const raw = await this.signTransaction({ ...tx, from: this.address });
241
- return this.provider.sendTransaction(raw);
242
- }
243
- }
244
-
245
- /**
246
- * Wallet - convenience methods around BaseWallet.
247
- */
248
- class Wallet extends BaseWallet {
249
- /**
250
- * @param {string|Uint8Array|SigningKey} key
251
- * @param {import("../providers/provider").AbstractProvider=} provider
252
- */
253
- constructor(key, provider) {
254
- _requireInitialized();
255
-
256
- let signingKey;
257
- let qcAddress;
258
-
259
- if (key instanceof SigningKey) {
260
- signingKey = key;
261
- // Compute address from public key
262
- const addr = qcsdk.addressFromPublicKey(_bytesToNumberArray(signingKey.publicKeyBytes));
263
- if (typeof addr !== "string") throw makeError("addressFromPublicKey failed", "UNKNOWN_ERROR", {});
264
- qcAddress = normalizeHex(addr);
265
- } else {
266
- const privBytes = typeof key === "string" ? hexToBytes(key) : arrayify(key);
267
- const pubHex = qcsdk.publicKeyFromPrivateKey(_bytesToNumberArray(privBytes));
268
- if (typeof pubHex !== "string") throw makeError("publicKeyFromPrivateKey failed", "UNKNOWN_ERROR", {});
269
- const pubBytes = hexToBytes(pubHex);
270
- const addr = qcsdk.addressFromPublicKey(_bytesToNumberArray(pubBytes));
271
- if (typeof addr !== "string") throw makeError("addressFromPublicKey failed", "UNKNOWN_ERROR", {});
272
- qcAddress = normalizeHex(addr);
273
- signingKey = new SigningKey(privBytes, pubBytes);
274
- }
275
-
276
- /** @type {any} */
277
- const qcWallet = new qcsdk.Wallet(
278
- qcAddress,
279
- _bytesToNumberArray(signingKey.privateKeyBytes),
280
- _bytesToNumberArray(signingKey.publicKeyBytes),
281
- );
282
-
283
- super(signingKey, provider || null, { address: qcAddress }, qcWallet);
284
- }
285
-
286
- /**
287
- * Returns wallet address (sync).
288
- * @returns {string}
289
- */
290
- getAddress() {
291
- return this.address;
292
- }
293
-
294
- /**
295
- * Returns wallet balance.
296
- * @param {string=} blockTag
297
- * @returns {Promise<bigint>}
298
- */
299
- async getBalance(blockTag) {
300
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "getBalance" });
301
- void blockTag;
302
- return this.provider.getBalance(this.address);
303
- }
304
-
305
- /**
306
- * Returns wallet nonce.
307
- * @param {string=} blockTag
308
- * @returns {Promise<number>}
309
- */
310
- async getTransactionCount(blockTag) {
311
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "getTransactionCount" });
312
- return this.provider.getTransactionCount(this.address, blockTag);
313
- }
314
-
315
- /**
316
- * Encrypts and serializes this wallet to JSON.
317
- * @param {string|Uint8Array} password
318
- * @returns {string}
319
- */
320
- encryptSync(password) {
321
- _requireInitialized();
322
- if (this._seed != null) {
323
- return Wallet.encryptSeedSync(hexToBytes(this._seed), password);
324
- }
325
- const pw = typeof password === "string"
326
- ? password.normalize("NFC")
327
- : Buffer.from(arrayify(password)).toString("utf8").normalize("NFC");
328
- assertSecretArgument(pw.length >= 12, "password must be at least 12 characters", "password");
329
- const json = qcsdk.serializeEncryptedWallet(this._qcWallet, pw);
330
- if (typeof json !== "string") throw makeError("serializeEncryptedWallet failed", "UNKNOWN_ERROR", {});
331
- return json;
332
- }
333
-
334
- /**
335
- * Encrypts raw seed bytes into a wallet JSON string (version 5 pre-expansion format).
336
- * The resulting JSON can be opened with `Wallet.fromEncryptedJsonSync()` or
337
- * Desktop/Mobile/Web/CLI wallet applications.
338
- * @param {number[]|Uint8Array} seed Raw seed bytes: 64 (keyType 3), 72 (keyType 5), or 96 (legacy)
339
- * @param {string|Uint8Array} password Passphrase (at least 12 characters)
340
- * @returns {string}
341
- */
342
- static encryptSeedSync(seed, password) {
343
- _requireInitialized();
344
- const seedArr = seed instanceof Uint8Array ? Array.from(seed) : seed;
345
- assertArgument(Array.isArray(seedArr), "seed must be an array of numbers or Uint8Array", "seed", seed);
346
- const allowedLengths = [64, 72, 96];
347
- assertArgument(allowedLengths.includes(seedArr.length), "seed must be 64, 72, or 96 bytes", "seed", seedArr.length);
348
- const pw = typeof password === "string"
349
- ? password.normalize("NFC")
350
- : Buffer.from(arrayify(password)).toString("utf8").normalize("NFC");
351
- assertSecretArgument(pw.length >= 12, "password must be at least 12 characters", "password");
352
- const json = qcsdk.serializeSeedAsEncryptedWallet(seedArr, pw);
353
- if (typeof json !== "string") throw makeError("serializeSeedAsEncryptedWallet failed", "UNKNOWN_ERROR", {});
354
- return json;
355
- }
356
-
357
- /**
358
- * Returns the recommended signing context for this wallet.
359
- * Setting fullSign to true may incur additional gas cost.
360
- * @param {boolean|null=} fullSign Defaults to false when null or omitted.
361
- * @returns {number}
362
- */
363
- getSigningContext(fullSign) {
364
- const fs = fullSign ?? false;
365
- const pubLen = this.signingKey.publicKeyBytes.length;
366
- if (pubLen === 1408) {
367
- return fs ? 2 : 0;
368
- }
369
- if (pubLen === 2688) {
370
- return 1;
371
- }
372
- throw makeError("unsupported public key size", "UNSUPPORTED_OPERATION", { publicKeyLength: pubLen });
373
- }
374
-
375
- /**
376
- * Returns a new wallet connected to a provider.
377
- * @param {import("../providers/provider").AbstractProvider} provider
378
- * @returns {Wallet}
379
- */
380
- connect(provider) {
381
- const w = new Wallet(this.signingKey, provider);
382
- w._qcWallet = this._qcWallet;
383
- w._seed = this._seed;
384
- return w;
385
- }
386
-
387
- /**
388
- * Creates a new random wallet.
389
- * @param {import("../providers/provider").AbstractProvider=} provider
390
- * @param {number|null=} keyType Optional key type: null (default=3), 3, or 5
391
- * @returns {Wallet}
392
- */
393
- static createRandom(provider, keyType) {
394
- _requireInitialized();
395
- if (keyType != null) {
396
- assertArgument(keyType === 3 || keyType === 5, "keyType must be null, 3, or 5", "keyType", keyType);
397
- }
398
- const words = qcsdk.newWalletSeedWords(keyType ?? null);
399
- if (!words || !Array.isArray(words)) {
400
- throw makeError("newWalletSeedWords failed", "UNKNOWN_ERROR", { result: words });
401
- }
402
- return Wallet.fromPhrase(words, provider);
403
- }
404
-
405
- /**
406
- * Creates a wallet from raw seed bytes.
407
- * @param {number[]} seed Raw seed bytes: 64 (keyType 3), 72 (keyType 5), or 96 (legacy)
408
- * @param {import("../providers/provider").AbstractProvider=} provider
409
- * @returns {Wallet}
410
- */
411
- static fromSeed(seed, provider) {
412
- _requireInitialized();
413
- assertArgument(Array.isArray(seed), "seed must be an array of numbers", "seed", seed);
414
- const allowedLengths = [64, 72, 96];
415
- assertArgument(allowedLengths.includes(seed.length), "seed must be 64, 72, or 96 bytes", "seed", seed.length);
416
- const qcWallet = qcsdk.openWalletFromSeed(seed);
417
- if (!qcWallet || typeof qcWallet === "number") {
418
- throw makeError("openWalletFromSeed failed", "UNKNOWN_ERROR", { result: qcWallet });
419
- }
420
- return Wallet._fromQcWallet(qcWallet, provider || null);
421
- }
422
-
423
- /**
424
- * Creates a wallet from an encrypted JSON string.
425
- * @param {string} json
426
- * @param {string} password
427
- * @param {import("../providers/provider").AbstractProvider=} provider
428
- * @returns {Wallet}
429
- */
430
- static fromEncryptedJsonSync(json, password, provider) {
431
- _requireInitialized();
432
- const qcWallet = qcsdk.deserializeEncryptedWallet(json, password);
433
- if (!qcWallet) throw makeError("deserializeEncryptedWallet failed", "UNKNOWN_ERROR", {});
434
- return Wallet._fromQcWallet(qcWallet, provider || null);
435
- }
436
-
437
- /**
438
- * Creates a wallet from a seed phrase (32, 36, or 48 words).
439
- * @param {string|string[]} phrase
440
- * @param {import("../providers/provider").AbstractProvider=} provider
441
- * @returns {Wallet}
442
- */
443
- static fromPhrase(phrase, provider) {
444
- _requireInitialized();
445
- let words = phrase;
446
- if (typeof phrase === "string") {
447
- words = phrase
448
- .split(/[,\s]+/g)
449
- .map((w) => w.trim())
450
- .filter(Boolean);
451
- }
452
- assertArgument(Array.isArray(words), "phrase must be a string or string[]", "phrase", phrase);
453
- const allowedLengths = [32, 36, 48];
454
- assertArgument(
455
- allowedLengths.includes(words.length),
456
- "seed phrase must contain 32, 36, or 48 words",
457
- "phrase",
458
- words.length,
459
- );
460
- const qcWallet = qcsdk.openWalletFromSeedWords(words);
461
- if (!qcWallet) throw makeError("openWalletFromSeedWords failed", "UNKNOWN_ERROR", {});
462
- return Wallet._fromQcWallet(qcWallet, provider || null);
463
- }
464
-
465
- /**
466
- * Creates a wallet from raw private and public key bytes.
467
- * @param {Uint8Array|string} privateKey Private key bytes or hex string
468
- * @param {Uint8Array|string} publicKey Public key bytes or hex string
469
- * @param {import("../providers/provider").AbstractProvider=} provider
470
- * @returns {Wallet}
471
- */
472
- static fromKeys(privateKey, publicKey, provider) {
473
- _requireInitialized();
474
- const privBytes = typeof privateKey === "string" ? hexToBytes(privateKey) : arrayify(privateKey);
475
- const pubBytes = typeof publicKey === "string" ? hexToBytes(publicKey) : arrayify(publicKey);
476
- assertSecretArgument(privBytes.length > 0, "privateKey must not be empty", "privateKey");
477
- assertSecretArgument(pubBytes.length > 0, "publicKey must not be empty", "publicKey");
478
-
479
- const privArr = _bytesToNumberArray(privBytes);
480
- const pubArr = _bytesToNumberArray(pubBytes);
481
- const addr = qcsdk.addressFromPublicKey(pubArr);
482
- if (typeof addr !== "string") throw makeError("addressFromPublicKey failed", "UNKNOWN_ERROR", {});
483
-
484
- const qcWallet = new qcsdk.Wallet(addr, privArr, pubArr);
485
- const verified = qcsdk.verifyWallet(qcWallet);
486
- if (verified !== true) {
487
- throw makeError("verifyWallet failed: the provided key pair is invalid", "INVALID_ARGUMENT", { verified });
488
- }
489
-
490
- return Wallet._fromQcWallet(qcWallet, provider || null);
491
- }
492
-
493
- /**
494
- * Internal helper: build a Wallet from a quantum-coin-js-sdk Wallet object.
495
- * @param {any} qcWallet
496
- * @param {import("../providers/provider").AbstractProvider|null} provider
497
- * @returns {Wallet}
498
- */
499
- static _fromQcWallet(qcWallet, provider) {
500
- const privSrc = qcWallet.privateKey;
501
- const pubSrc = qcWallet.publicKey;
502
-
503
- if (!privSrc || (privSrc instanceof Uint8Array && privSrc.length === 0) || (Array.isArray(privSrc) && privSrc.length === 0)) {
504
- throw makeError("qcWallet.privateKey is empty or missing", "UNKNOWN_ERROR", {});
505
- }
506
- if (!pubSrc || (pubSrc instanceof Uint8Array && pubSrc.length === 0) || (Array.isArray(pubSrc) && pubSrc.length === 0)) {
507
- throw makeError("qcWallet.publicKey is empty or missing", "UNKNOWN_ERROR", {});
508
- }
509
-
510
- const privBytes =
511
- privSrc instanceof Uint8Array ? new Uint8Array(privSrc) : Uint8Array.from(Array.from(privSrc).map((n) => (Number(n) & 0xff)));
512
- const pubBytes =
513
- pubSrc instanceof Uint8Array ? new Uint8Array(pubSrc) : Uint8Array.from(Array.from(pubSrc).map((n) => (Number(n) & 0xff)));
514
- const key = new SigningKey(privBytes, pubBytes);
515
-
516
- const w = new Wallet(key, provider || null);
517
- // Ensure we keep the exact underlying qcWallet for operations like encrypt/signRawTransaction.
518
- w._qcWallet = qcWallet;
519
- if (typeof qcWallet.address === "string") {
520
- w.address = normalizeHex(qcWallet.address);
521
- }
522
- if (qcWallet.preExpansionSeed != null) {
523
- const seedSrc = qcWallet.preExpansionSeed;
524
- const seedBytes =
525
- seedSrc instanceof Uint8Array ? seedSrc : Uint8Array.from(Array.from(seedSrc).map((n) => (Number(n) & 0xff)));
526
- w._seed = bytesToHex(seedBytes);
527
- }
528
- return w;
529
- }
530
- }
531
-
532
- /**
533
- * NonceManager wrapper.
534
- */
535
- class NonceManager extends AbstractSigner {
536
- /**
537
- * @param {AbstractSigner} signer
538
- */
539
- constructor(signer) {
540
- super(signer.provider || null);
541
- this.signer = signer;
542
- this._nonce = null;
543
- }
544
-
545
- async getAddress() {
546
- return this.signer.getAddress();
547
- }
548
-
549
- async getTransactionCount(blockTag) {
550
- if (this._nonce != null) return this._nonce;
551
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "getTransactionCount" });
552
- const address = await this.getAddress();
553
- this._nonce = await this.provider.getTransactionCount(address, blockTag);
554
- return this._nonce;
555
- }
556
-
557
- async sendTransaction(tx) {
558
- const nonce = await this.getTransactionCount("latest");
559
- const result = await this.signer.sendTransaction({ ...tx, nonce });
560
- this._nonce = nonce + 1;
561
- return result;
562
- }
563
-
564
- reset() {
565
- this._nonce = null;
566
- }
567
-
568
- increment() {
569
- if (this._nonce == null) this._nonce = 0;
570
- this._nonce++;
571
- }
572
- }
573
-
574
- /**
575
- * JsonRpcSigner placeholder (ethers-like).
576
- * This SDK encourages using Wallet directly for signing.
577
- */
578
- class JsonRpcSigner extends AbstractSigner {
579
- constructor(provider, address) {
580
- super(provider);
581
- this._address = address;
582
- }
583
- async getAddress() {
584
- return this._address;
585
- }
586
- }
587
-
588
- /**
589
- * VoidSigner (cannot sign, only provides address).
590
- */
591
- class VoidSigner extends AbstractSigner {
592
- constructor(address, provider) {
593
- super(provider || null);
594
- this._address = getAddress(address);
595
- }
596
- async getAddress() {
597
- return this._address;
598
- }
599
- }
600
-
601
- module.exports = {
602
- SigningKey,
603
- AbstractSigner,
604
- BaseWallet,
605
- Wallet,
606
- NonceManager,
607
- JsonRpcSigner,
608
- VoidSigner,
609
- };
610
-
1
+ /**
2
+ * @fileoverview Wallet and signer implementations.
3
+ *
4
+ * The QuantumCoin.js wallet model mirrors ethers.js v6:
5
+ * - AbstractSigner -> BaseWallet -> Wallet
6
+ * - NonceManager wrapper
7
+ *
8
+ * Cryptographic operations are delegated to `quantum-coin-js-sdk`.
9
+ */
10
+
11
+ const qcsdk = require("quantum-coin-js-sdk");
12
+ const seedWords = require("seed-words");
13
+ const { JsonRpcProvider } = require("../providers/json-rpc-provider");
14
+ const { assertArgument, assertSecretArgument, makeError } = require("../errors");
15
+ const { arrayify, bytesToHex, hexToBytes, isHexString, normalizeHex } = require("../internal/hex");
16
+ const { getAddress } = require("../utils/address");
17
+ const { WeiPerEther } = require("../constants");
18
+
19
+ function _requireInitialized() {
20
+ // eslint-disable-next-line global-require
21
+ const { isInitialized, getInitializationPromise } = require("../../config");
22
+ if (isInitialized()) return;
23
+ if (getInitializationPromise() != null) {
24
+ throw makeError(
25
+ "QuantumCoin SDK is still initializing. Await the Initialize() promise before using SDK methods.",
26
+ "UNKNOWN_ERROR",
27
+ { operation: "requireInitialized" },
28
+ );
29
+ }
30
+ throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", { operation: "wallet" });
31
+ }
32
+
33
+ function _bytesToNumberArray(bytes) {
34
+ return Array.from(bytes);
35
+ }
36
+
37
+ const _maxSafeInt = 0x1fffffffffffffn; // 2^53 - 1
38
+
39
+ function _getBigInt(value, name) {
40
+ if (typeof value === "bigint") return value;
41
+ if (typeof value === "number") {
42
+ assertArgument(Number.isInteger(value), "underflow", name, value);
43
+ assertArgument(value >= -Number(_maxSafeInt) && value <= Number(_maxSafeInt), "overflow", name, value);
44
+ return BigInt(value);
45
+ }
46
+ if (typeof value === "string") {
47
+ if (value === "0x" || value === "0X") return 0n;
48
+ try { return BigInt(value); }
49
+ catch { assertArgument(false, "invalid BigNumberish string", name, value); }
50
+ }
51
+ assertArgument(false, "invalid BigNumberish", name, value);
52
+ }
53
+
54
+ function _getNumber(value, name) {
55
+ const bi = _getBigInt(value, name);
56
+ assertArgument(bi >= -_maxSafeInt && bi <= _maxSafeInt, "overflow", name, value);
57
+ return Number(bi);
58
+ }
59
+
60
+ /**
61
+ * SigningKey wrapper (PQC private/public key bytes).
62
+ */
63
+ class SigningKey {
64
+ /**
65
+ * @param {Uint8Array} privateKeyBytes
66
+ * @param {Uint8Array} publicKeyBytes
67
+ */
68
+ constructor(privateKeyBytes, publicKeyBytes) {
69
+ Object.defineProperty(this, "privateKeyBytes", {
70
+ enumerable: false,
71
+ configurable: false,
72
+ writable: false,
73
+ value: new Uint8Array(privateKeyBytes),
74
+ });
75
+ this.publicKeyBytes = new Uint8Array(publicKeyBytes);
76
+ }
77
+
78
+ toJSON() {
79
+ return {};
80
+ }
81
+ }
82
+
83
+ /**
84
+ * AbstractSigner base (minimal).
85
+ */
86
+ class AbstractSigner {
87
+ /**
88
+ * @param {import("../providers/provider").AbstractProvider|null} provider
89
+ */
90
+ constructor(provider) {
91
+ this.provider = provider || null;
92
+ }
93
+
94
+ async getAddress() {
95
+ throw makeError("getAddress not implemented", "NOT_IMPLEMENTED", {});
96
+ }
97
+ }
98
+
99
+ /**
100
+ * BaseWallet - core signing implementation.
101
+ */
102
+ class BaseWallet extends AbstractSigner {
103
+ /**
104
+ * @param {SigningKey} signingKey
105
+ * @param {import("../providers/provider").AbstractProvider|null=} provider
106
+ * @param {{ address: string }=} precomputed
107
+ * @param {any=} qcWallet Internal quantum-coin-js-sdk Wallet (optional)
108
+ */
109
+ constructor(signingKey, provider, precomputed, qcWallet) {
110
+ super(provider || null);
111
+ _requireInitialized();
112
+
113
+ Object.defineProperty(this, "signingKey", {
114
+ enumerable: false,
115
+ configurable: false,
116
+ writable: false,
117
+ value: signingKey,
118
+ });
119
+ Object.defineProperty(this, "_qcWallet", {
120
+ enumerable: false,
121
+ configurable: true,
122
+ writable: true,
123
+ value: qcWallet || null,
124
+ });
125
+
126
+ /** @type {string} */
127
+ this.address = precomputed?.address || "";
128
+
129
+ Object.defineProperty(this, "privateKey", {
130
+ enumerable: false,
131
+ get: () => bytesToHex(this.signingKey.privateKeyBytes),
132
+ });
133
+
134
+ Object.defineProperty(this, "publicKey", {
135
+ enumerable: true,
136
+ get: () => bytesToHex(this.signingKey.publicKeyBytes),
137
+ });
138
+
139
+ Object.defineProperty(this, "_seed", {
140
+ enumerable: false,
141
+ configurable: true,
142
+ writable: true,
143
+ value: null,
144
+ });
145
+
146
+ Object.defineProperty(this, "seed", {
147
+ enumerable: false,
148
+ get: () => this._seed,
149
+ });
150
+ }
151
+
152
+ toJSON() {
153
+ return { address: this.address };
154
+ }
155
+
156
+ async getAddress() {
157
+ return this.address;
158
+ }
159
+
160
+ /**
161
+ * Sign a transaction using quantum-coin-js-sdk signRawTransaction().
162
+ * @param {import("../providers/provider").TransactionRequest} tx
163
+ * @returns {Promise<string>}
164
+ */
165
+ async signTransaction(tx) {
166
+ _requireInitialized();
167
+ assertArgument(tx && typeof tx === "object", "invalid tx", "tx", tx);
168
+
169
+ const toAddress = tx.to == null ? null : getAddress(tx.to);
170
+ const valueInWei = tx.value == null ? 0n : _getBigInt(tx.value, "tx.value");
171
+ const gasLimit = tx.gasLimit == null ? 21000 : _getNumber(tx.gasLimit, "tx.gasLimit");
172
+
173
+ const data = tx.data == null ? null : normalizeHex(tx.data);
174
+ const remarks = tx.remarks == null ? null : normalizeHex(tx.remarks);
175
+
176
+ if (remarks != null) {
177
+ assertArgument(isHexString(remarks), "remarks must be hex string", "remarks", remarks);
178
+ const remarkBytes = hexToBytes(remarks);
179
+ assertArgument(remarkBytes.length <= 32, "remarks too long (max 32 bytes)", "remarks", remarks);
180
+ }
181
+
182
+ // Nonce must be provided or resolved from provider.
183
+ let nonce = tx.nonce;
184
+ if (nonce == null) {
185
+ if (!this.provider) throw makeError("missing provider to resolve nonce", "UNKNOWN_ERROR", { operation: "signTransaction" });
186
+ // Prefer pending to avoid nonce collisions with in-flight transactions.
187
+ try {
188
+ nonce = await this.provider.getTransactionCount(this.address, "pending");
189
+ } catch {
190
+ nonce = await this.provider.getTransactionCount(this.address, "latest");
191
+ }
192
+ }
193
+ assertArgument(Number.isInteger(nonce) && nonce >= 0, "invalid nonce", "nonce", nonce);
194
+
195
+ const chainId = tx.chainId != null ? tx.chainId : (this.provider && this.provider.chainId != null ? this.provider.chainId : null);
196
+ const signingContext = tx.signingContext ?? null;
197
+
198
+ /** @type {any} */
199
+ const qcWallet =
200
+ this._qcWallet ||
201
+ new qcsdk.Wallet(
202
+ this.address,
203
+ _bytesToNumberArray(this.signingKey.privateKeyBytes),
204
+ _bytesToNumberArray(this.signingKey.publicKeyBytes),
205
+ );
206
+
207
+ const req = new qcsdk.TransactionSigningRequest(
208
+ qcWallet,
209
+ toAddress,
210
+ valueInWei,
211
+ nonce,
212
+ data,
213
+ gasLimit,
214
+ remarks,
215
+ chainId,
216
+ signingContext,
217
+ );
218
+ const signResult = qcsdk.signRawTransaction(req);
219
+ // quantum-coin-js-sdk returns a SignResult object: { resultCode, txnHash, txnData }
220
+ if (!signResult || typeof signResult !== "object") {
221
+ throw makeError("signRawTransaction failed", "UNKNOWN_ERROR", {});
222
+ }
223
+ if (typeof signResult.resultCode === "number" && signResult.resultCode !== 0) {
224
+ throw makeError("signRawTransaction failed", "UNKNOWN_ERROR", {
225
+ resultCode: signResult.resultCode,
226
+ hash: signResult.txnHash || null,
227
+ });
228
+ }
229
+ const raw = signResult.txnData;
230
+ if (typeof raw !== "string") throw makeError("signRawTransaction did not return txnData", "UNKNOWN_ERROR", {});
231
+ return normalizeHex(raw);
232
+ }
233
+
234
+ /**
235
+ * Signs and sends a transaction.
236
+ * @param {import("../providers/provider").TransactionRequest} tx
237
+ * @returns {Promise<import("../providers/provider").TransactionResponse>}
238
+ */
239
+ async sendTransaction(tx) {
240
+ if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "sendTransaction" });
241
+ const raw = await this.signTransaction({ ...tx, from: this.address });
242
+ return this.provider.sendTransaction(raw);
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Wallet - convenience methods around BaseWallet.
248
+ */
249
+ class Wallet extends BaseWallet {
250
+ /**
251
+ * @param {string|Uint8Array|SigningKey} key
252
+ * @param {import("../providers/provider").AbstractProvider=} provider
253
+ */
254
+ constructor(key, provider) {
255
+ _requireInitialized();
256
+
257
+ let signingKey;
258
+ let qcAddress;
259
+
260
+ if (key instanceof SigningKey) {
261
+ signingKey = key;
262
+ // Compute address from public key
263
+ const addr = qcsdk.addressFromPublicKey(_bytesToNumberArray(signingKey.publicKeyBytes));
264
+ if (typeof addr !== "string") throw makeError("addressFromPublicKey failed", "UNKNOWN_ERROR", {});
265
+ qcAddress = normalizeHex(addr);
266
+ } else {
267
+ const privBytes = typeof key === "string" ? hexToBytes(key) : arrayify(key);
268
+ const pubHex = qcsdk.publicKeyFromPrivateKey(_bytesToNumberArray(privBytes));
269
+ if (typeof pubHex !== "string") throw makeError("publicKeyFromPrivateKey failed", "UNKNOWN_ERROR", {});
270
+ const pubBytes = hexToBytes(pubHex);
271
+ const addr = qcsdk.addressFromPublicKey(_bytesToNumberArray(pubBytes));
272
+ if (typeof addr !== "string") throw makeError("addressFromPublicKey failed", "UNKNOWN_ERROR", {});
273
+ qcAddress = normalizeHex(addr);
274
+ signingKey = new SigningKey(privBytes, pubBytes);
275
+ }
276
+
277
+ /** @type {any} */
278
+ const qcWallet = new qcsdk.Wallet(
279
+ qcAddress,
280
+ _bytesToNumberArray(signingKey.privateKeyBytes),
281
+ _bytesToNumberArray(signingKey.publicKeyBytes),
282
+ );
283
+
284
+ super(signingKey, provider || null, { address: qcAddress }, qcWallet);
285
+ }
286
+
287
+ /**
288
+ * Returns wallet address (sync).
289
+ * @returns {string}
290
+ */
291
+ getAddress() {
292
+ return this.address;
293
+ }
294
+
295
+ /**
296
+ * Returns wallet balance.
297
+ * @param {string=} blockTag
298
+ * @returns {Promise<bigint>}
299
+ */
300
+ async getBalance(blockTag) {
301
+ if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "getBalance" });
302
+ void blockTag;
303
+ return this.provider.getBalance(this.address);
304
+ }
305
+
306
+ /**
307
+ * Returns wallet nonce.
308
+ * @param {string=} blockTag
309
+ * @returns {Promise<number>}
310
+ */
311
+ async getTransactionCount(blockTag) {
312
+ if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "getTransactionCount" });
313
+ return this.provider.getTransactionCount(this.address, blockTag);
314
+ }
315
+
316
+ /**
317
+ * Encrypts and serializes this wallet to JSON.
318
+ * @param {string|Uint8Array} password
319
+ * @returns {string}
320
+ */
321
+ encryptSync(password) {
322
+ _requireInitialized();
323
+ if (this._seed != null) {
324
+ return Wallet.encryptSeedSync(hexToBytes(this._seed), password);
325
+ }
326
+ const pw = typeof password === "string"
327
+ ? password.normalize("NFC")
328
+ : Buffer.from(arrayify(password)).toString("utf8").normalize("NFC");
329
+ assertSecretArgument(pw.length >= 12, "password must be at least 12 characters", "password");
330
+ const json = qcsdk.serializeEncryptedWallet(this._qcWallet, pw);
331
+ if (typeof json !== "string") throw makeError("serializeEncryptedWallet failed", "UNKNOWN_ERROR", {});
332
+ return json;
333
+ }
334
+
335
+ /**
336
+ * Encrypts raw seed bytes into a wallet JSON string (version 5 pre-expansion format).
337
+ * The resulting JSON can be opened with `Wallet.fromEncryptedJsonSync()` or
338
+ * Desktop/Mobile/Web/CLI wallet applications.
339
+ * @param {number[]|Uint8Array} seed Raw seed bytes: 64 (keyType 3), 72 (keyType 5), or 96 (legacy)
340
+ * @param {string|Uint8Array} password Passphrase (at least 12 characters)
341
+ * @returns {string}
342
+ */
343
+ static encryptSeedSync(seed, password) {
344
+ _requireInitialized();
345
+ const seedArr = seed instanceof Uint8Array ? Array.from(seed) : seed;
346
+ assertArgument(Array.isArray(seedArr), "seed must be an array of numbers or Uint8Array", "seed", seed);
347
+ const allowedLengths = [64, 72, 96];
348
+ assertArgument(allowedLengths.includes(seedArr.length), "seed must be 64, 72, or 96 bytes", "seed", seedArr.length);
349
+ const pw = typeof password === "string"
350
+ ? password.normalize("NFC")
351
+ : Buffer.from(arrayify(password)).toString("utf8").normalize("NFC");
352
+ assertSecretArgument(pw.length >= 12, "password must be at least 12 characters", "password");
353
+ const json = qcsdk.serializeSeedAsEncryptedWallet(seedArr, pw);
354
+ if (typeof json !== "string") throw makeError("serializeSeedAsEncryptedWallet failed", "UNKNOWN_ERROR", {});
355
+ return json;
356
+ }
357
+
358
+ /**
359
+ * Returns the seed phrase (list of words) if this wallet has a seed, else null.
360
+ * Derived from the stored pre-expansion seed via seed-words.getWordListFromSeedArray.
361
+ *
362
+ * Non-null for wallets created via createRandom, fromPhrase, fromSeed, and
363
+ * fromEncryptedJsonSync when the JSON is a version-5 keystore produced by
364
+ * encryptSync on a seed-bearing wallet or by encryptSeedSync.
365
+ * Null for fromKeys and for v3/v4 keystores without preExpansionSeed.
366
+ *
367
+ * @returns {string[]|null}
368
+ */
369
+ getPhrase() {
370
+ _requireInitialized();
371
+ if (this._seed == null) return null;
372
+ const bytes = Array.from(hexToBytes(this._seed));
373
+ const words = seedWords.getWordListFromSeedArray(bytes);
374
+ return Array.isArray(words) ? words : null;
375
+ }
376
+
377
+ /**
378
+ * Returns the recommended signing context for this wallet.
379
+ * Setting fullSign to true may incur additional gas cost.
380
+ * @param {boolean|null=} fullSign Defaults to false when null or omitted.
381
+ * @returns {number}
382
+ */
383
+ getSigningContext(fullSign) {
384
+ const fs = fullSign ?? false;
385
+ const pubLen = this.signingKey.publicKeyBytes.length;
386
+ if (pubLen === 1408) {
387
+ return fs ? 2 : 0;
388
+ }
389
+ if (pubLen === 2688) {
390
+ return 1;
391
+ }
392
+ throw makeError("unsupported public key size", "UNSUPPORTED_OPERATION", { publicKeyLength: pubLen });
393
+ }
394
+
395
+ /**
396
+ * Returns a new wallet connected to a provider.
397
+ * @param {import("../providers/provider").AbstractProvider} provider
398
+ * @returns {Wallet}
399
+ */
400
+ connect(provider) {
401
+ const w = new Wallet(this.signingKey, provider);
402
+ w._qcWallet = this._qcWallet;
403
+ w._seed = this._seed;
404
+ return w;
405
+ }
406
+
407
+ /**
408
+ * Creates a new random wallet.
409
+ * @param {import("../providers/provider").AbstractProvider=} provider
410
+ * @param {number|null=} keyType Optional key type: null (default=3), 3, or 5
411
+ * @returns {Wallet}
412
+ */
413
+ static createRandom(provider, keyType) {
414
+ _requireInitialized();
415
+ if (keyType != null) {
416
+ assertArgument(keyType === 3 || keyType === 5, "keyType must be null, 3, or 5", "keyType", keyType);
417
+ }
418
+ const words = qcsdk.newWalletSeedWords(keyType ?? null);
419
+ if (!words || !Array.isArray(words)) {
420
+ throw makeError("newWalletSeedWords failed", "UNKNOWN_ERROR", { result: words });
421
+ }
422
+ return Wallet.fromPhrase(words, provider);
423
+ }
424
+
425
+ /**
426
+ * Creates a wallet from raw seed bytes.
427
+ * @param {number[]} seed Raw seed bytes: 64 (keyType 3), 72 (keyType 5), or 96 (legacy)
428
+ * @param {import("../providers/provider").AbstractProvider=} provider
429
+ * @returns {Wallet}
430
+ */
431
+ static fromSeed(seed, provider) {
432
+ _requireInitialized();
433
+ assertArgument(Array.isArray(seed), "seed must be an array of numbers", "seed", seed);
434
+ const allowedLengths = [64, 72, 96];
435
+ assertArgument(allowedLengths.includes(seed.length), "seed must be 64, 72, or 96 bytes", "seed", seed.length);
436
+ const qcWallet = qcsdk.openWalletFromSeed(seed);
437
+ if (!qcWallet || typeof qcWallet === "number") {
438
+ throw makeError("openWalletFromSeed failed", "UNKNOWN_ERROR", { result: qcWallet });
439
+ }
440
+ return Wallet._fromQcWallet(qcWallet, provider || null);
441
+ }
442
+
443
+ /**
444
+ * Creates a wallet from an encrypted JSON string.
445
+ * @param {string} json
446
+ * @param {string} password
447
+ * @param {import("../providers/provider").AbstractProvider=} provider
448
+ * @returns {Wallet}
449
+ */
450
+ static fromEncryptedJsonSync(json, password, provider) {
451
+ _requireInitialized();
452
+ const qcWallet = qcsdk.deserializeEncryptedWallet(json, password);
453
+ if (!qcWallet) throw makeError("deserializeEncryptedWallet failed", "UNKNOWN_ERROR", {});
454
+ return Wallet._fromQcWallet(qcWallet, provider || null);
455
+ }
456
+
457
+ /**
458
+ * Creates a wallet from a seed phrase (32, 36, or 48 words).
459
+ * @param {string|string[]} phrase
460
+ * @param {import("../providers/provider").AbstractProvider=} provider
461
+ * @returns {Wallet}
462
+ */
463
+ static fromPhrase(phrase, provider) {
464
+ _requireInitialized();
465
+ let words = phrase;
466
+ if (typeof phrase === "string") {
467
+ words = phrase
468
+ .split(/[,\s]+/g)
469
+ .map((w) => w.trim())
470
+ .filter(Boolean);
471
+ }
472
+ assertArgument(Array.isArray(words), "phrase must be a string or string[]", "phrase", phrase);
473
+ const allowedLengths = [32, 36, 48];
474
+ assertArgument(
475
+ allowedLengths.includes(words.length),
476
+ "seed phrase must contain 32, 36, or 48 words",
477
+ "phrase",
478
+ words.length,
479
+ );
480
+ const qcWallet = qcsdk.openWalletFromSeedWords(words);
481
+ if (!qcWallet) throw makeError("openWalletFromSeedWords failed", "UNKNOWN_ERROR", {});
482
+ return Wallet._fromQcWallet(qcWallet, provider || null);
483
+ }
484
+
485
+ /**
486
+ * Creates a wallet from raw private and public key bytes.
487
+ * @param {Uint8Array|string} privateKey Private key bytes or hex string
488
+ * @param {Uint8Array|string} publicKey Public key bytes or hex string
489
+ * @param {import("../providers/provider").AbstractProvider=} provider
490
+ * @returns {Wallet}
491
+ */
492
+ static fromKeys(privateKey, publicKey, provider) {
493
+ _requireInitialized();
494
+ const privBytes = typeof privateKey === "string" ? hexToBytes(privateKey) : arrayify(privateKey);
495
+ const pubBytes = typeof publicKey === "string" ? hexToBytes(publicKey) : arrayify(publicKey);
496
+ assertSecretArgument(privBytes.length > 0, "privateKey must not be empty", "privateKey");
497
+ assertSecretArgument(pubBytes.length > 0, "publicKey must not be empty", "publicKey");
498
+
499
+ const privArr = _bytesToNumberArray(privBytes);
500
+ const pubArr = _bytesToNumberArray(pubBytes);
501
+ const addr = qcsdk.addressFromPublicKey(pubArr);
502
+ if (typeof addr !== "string") throw makeError("addressFromPublicKey failed", "UNKNOWN_ERROR", {});
503
+
504
+ const qcWallet = new qcsdk.Wallet(addr, privArr, pubArr);
505
+ const verified = qcsdk.verifyWallet(qcWallet);
506
+ if (verified !== true) {
507
+ throw makeError("verifyWallet failed: the provided key pair is invalid", "INVALID_ARGUMENT", { verified });
508
+ }
509
+
510
+ return Wallet._fromQcWallet(qcWallet, provider || null);
511
+ }
512
+
513
+ /**
514
+ * Internal helper: build a Wallet from a quantum-coin-js-sdk Wallet object.
515
+ * @param {any} qcWallet
516
+ * @param {import("../providers/provider").AbstractProvider|null} provider
517
+ * @returns {Wallet}
518
+ */
519
+ static _fromQcWallet(qcWallet, provider) {
520
+ const privSrc = qcWallet.privateKey;
521
+ const pubSrc = qcWallet.publicKey;
522
+
523
+ if (!privSrc || (privSrc instanceof Uint8Array && privSrc.length === 0) || (Array.isArray(privSrc) && privSrc.length === 0)) {
524
+ throw makeError("qcWallet.privateKey is empty or missing", "UNKNOWN_ERROR", {});
525
+ }
526
+ if (!pubSrc || (pubSrc instanceof Uint8Array && pubSrc.length === 0) || (Array.isArray(pubSrc) && pubSrc.length === 0)) {
527
+ throw makeError("qcWallet.publicKey is empty or missing", "UNKNOWN_ERROR", {});
528
+ }
529
+
530
+ const privBytes =
531
+ privSrc instanceof Uint8Array ? new Uint8Array(privSrc) : Uint8Array.from(Array.from(privSrc).map((n) => (Number(n) & 0xff)));
532
+ const pubBytes =
533
+ pubSrc instanceof Uint8Array ? new Uint8Array(pubSrc) : Uint8Array.from(Array.from(pubSrc).map((n) => (Number(n) & 0xff)));
534
+ const key = new SigningKey(privBytes, pubBytes);
535
+
536
+ const w = new Wallet(key, provider || null);
537
+ // Ensure we keep the exact underlying qcWallet for operations like encrypt/signRawTransaction.
538
+ w._qcWallet = qcWallet;
539
+ if (typeof qcWallet.address === "string") {
540
+ w.address = normalizeHex(qcWallet.address);
541
+ }
542
+ if (qcWallet.preExpansionSeed != null) {
543
+ const seedSrc = qcWallet.preExpansionSeed;
544
+ const seedBytes =
545
+ seedSrc instanceof Uint8Array ? seedSrc : Uint8Array.from(Array.from(seedSrc).map((n) => (Number(n) & 0xff)));
546
+ w._seed = bytesToHex(seedBytes);
547
+ }
548
+ return w;
549
+ }
550
+ }
551
+
552
+ /**
553
+ * NonceManager wrapper.
554
+ */
555
+ class NonceManager extends AbstractSigner {
556
+ /**
557
+ * @param {AbstractSigner} signer
558
+ */
559
+ constructor(signer) {
560
+ super(signer.provider || null);
561
+ this.signer = signer;
562
+ this._nonce = null;
563
+ }
564
+
565
+ async getAddress() {
566
+ return this.signer.getAddress();
567
+ }
568
+
569
+ async getTransactionCount(blockTag) {
570
+ if (this._nonce != null) return this._nonce;
571
+ if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "getTransactionCount" });
572
+ const address = await this.getAddress();
573
+ this._nonce = await this.provider.getTransactionCount(address, blockTag);
574
+ return this._nonce;
575
+ }
576
+
577
+ async sendTransaction(tx) {
578
+ const nonce = await this.getTransactionCount("latest");
579
+ const result = await this.signer.sendTransaction({ ...tx, nonce });
580
+ this._nonce = nonce + 1;
581
+ return result;
582
+ }
583
+
584
+ reset() {
585
+ this._nonce = null;
586
+ }
587
+
588
+ increment() {
589
+ if (this._nonce == null) this._nonce = 0;
590
+ this._nonce++;
591
+ }
592
+ }
593
+
594
+ /**
595
+ * JsonRpcSigner placeholder (ethers-like).
596
+ * This SDK encourages using Wallet directly for signing.
597
+ */
598
+ class JsonRpcSigner extends AbstractSigner {
599
+ constructor(provider, address) {
600
+ super(provider);
601
+ this._address = address;
602
+ }
603
+ async getAddress() {
604
+ return this._address;
605
+ }
606
+ }
607
+
608
+ /**
609
+ * VoidSigner (cannot sign, only provides address).
610
+ */
611
+ class VoidSigner extends AbstractSigner {
612
+ constructor(address, provider) {
613
+ super(provider || null);
614
+ this._address = getAddress(address);
615
+ }
616
+ async getAddress() {
617
+ return this._address;
618
+ }
619
+ }
620
+
621
+ module.exports = {
622
+ SigningKey,
623
+ AbstractSigner,
624
+ BaseWallet,
625
+ Wallet,
626
+ NonceManager,
627
+ JsonRpcSigner,
628
+ VoidSigner,
629
+ };
630
+