ecash-lib 1.5.2-rc → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +5 -40
  2. package/dist/address/legacyaddr.d.ts +1 -1
  3. package/dist/ecc.d.ts +9 -25
  4. package/dist/ecc.d.ts.map +1 -1
  5. package/dist/ecc.js +40 -56
  6. package/dist/ecc.js.map +1 -1
  7. package/dist/ffi/ecash_lib_wasm_bg_browser.d.ts +1 -0
  8. package/dist/ffi/ecash_lib_wasm_bg_browser.js +1707 -0
  9. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  10. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +2 -0
  11. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  12. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +2 -0
  13. package/dist/ffi/ecash_lib_wasm_browser.d.ts +24 -0
  14. package/dist/ffi/ecash_lib_wasm_browser.js +64 -0
  15. package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +22 -0
  16. package/dist/ffi/ecash_lib_wasm_nodejs.js +64 -0
  17. package/dist/hash.d.ts +6 -16
  18. package/dist/hash.d.ts.map +1 -1
  19. package/dist/hash.js +18 -18
  20. package/dist/hash.js.map +1 -1
  21. package/dist/hdwallet.d.ts +2 -4
  22. package/dist/hdwallet.d.ts.map +1 -1
  23. package/dist/hdwallet.js +6 -7
  24. package/dist/hdwallet.js.map +1 -1
  25. package/dist/hmac.js +3 -3
  26. package/dist/hmac.js.map +1 -1
  27. package/dist/initBrowser.d.ts +1 -11
  28. package/dist/initBrowser.d.ts.map +1 -1
  29. package/dist/initBrowser.js +21 -41
  30. package/dist/initBrowser.js.map +1 -1
  31. package/dist/initNodeJs.d.ts +1 -2
  32. package/dist/initNodeJs.d.ts.map +1 -1
  33. package/dist/initNodeJs.js +16 -30
  34. package/dist/initNodeJs.js.map +1 -1
  35. package/dist/io/bytes.js +2 -2
  36. package/dist/io/bytes.js.map +1 -1
  37. package/dist/io/hex.js +5 -4
  38. package/dist/io/hex.js.map +1 -1
  39. package/dist/io/str.js +3 -2
  40. package/dist/io/str.js.map +1 -1
  41. package/dist/io/varsize.js +3 -2
  42. package/dist/io/varsize.js.map +1 -1
  43. package/dist/mnemonic.js +4 -3
  44. package/dist/mnemonic.js.map +1 -1
  45. package/dist/op.js +6 -5
  46. package/dist/op.js.map +1 -1
  47. package/dist/pbkdf2.js +2 -1
  48. package/dist/pbkdf2.js.map +1 -1
  49. package/dist/test/testRunner.d.ts +1 -2
  50. package/dist/test/testRunner.d.ts.map +1 -1
  51. package/dist/test/testRunner.js +10 -23
  52. package/dist/test/testRunner.js.map +1 -1
  53. package/dist/token/alp.d.ts +1 -1
  54. package/dist/token/alp.d.ts.map +1 -1
  55. package/dist/token/alp.js +5 -5
  56. package/dist/token/alp.js.map +1 -1
  57. package/dist/token/common.d.ts +4 -4
  58. package/dist/token/common.d.ts.map +1 -1
  59. package/dist/token/empp.js +2 -1
  60. package/dist/token/empp.js.map +1 -1
  61. package/dist/token/slp.d.ts +1 -1
  62. package/dist/token/slp.d.ts.map +1 -1
  63. package/dist/token/slp.js +7 -7
  64. package/dist/token/slp.js.map +1 -1
  65. package/dist/tx.js +7 -7
  66. package/dist/tx.js.map +1 -1
  67. package/dist/txBuilder.d.ts +5 -1
  68. package/dist/txBuilder.d.ts.map +1 -1
  69. package/dist/txBuilder.js +12 -11
  70. package/dist/txBuilder.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/ecc.ts +47 -59
  73. package/src/ffi/ecash_lib_wasm_bg_browser.d.ts +1 -0
  74. package/src/ffi/ecash_lib_wasm_bg_browser.js +1707 -0
  75. package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  76. package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +2 -0
  77. package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  78. package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +2 -0
  79. package/src/ffi/ecash_lib_wasm_browser.d.ts +24 -0
  80. package/src/ffi/ecash_lib_wasm_browser.js +64 -0
  81. package/src/ffi/ecash_lib_wasm_nodejs.d.ts +22 -0
  82. package/src/ffi/ecash_lib_wasm_nodejs.js +64 -0
  83. package/src/hash.ts +19 -38
  84. package/src/hdwallet.ts +4 -8
  85. package/src/initBrowser.ts +18 -25
  86. package/src/initNodeJs.ts +9 -12
  87. package/src/test/testRunner.ts +3 -11
  88. package/src/txBuilder.ts +12 -7
  89. package/.nyc_output/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
  90. package/.nyc_output/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
  91. package/.nyc_output/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
  92. package/.nyc_output/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
  93. package/.nyc_output/processinfo/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
  94. package/.nyc_output/processinfo/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
  95. package/.nyc_output/processinfo/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
  96. package/.nyc_output/processinfo/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
  97. package/.nyc_output/processinfo/index.json +0 -1
  98. package/dist/address/cashaddr.d.ts +0 -78
  99. package/dist/address/cashaddr.d.ts.map +0 -1
  100. package/dist/address/cashaddr.js +0 -543
  101. package/dist/address/cashaddr.js.map +0 -1
  102. package/dist/cashaddr/cashaddr.d.ts +0 -23
  103. package/dist/cashaddr/cashaddr.d.ts.map +0 -1
  104. package/dist/cashaddr/cashaddr.js +0 -325
  105. package/dist/cashaddr/cashaddr.js.map +0 -1
  106. package/test.log +0 -82
@@ -1 +0,0 @@
1
- {"parent":"b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8","pid":2715843,"argv":["/home/joey/.nvm/versions/node/v20.11.0/bin/node","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/node_modules/mocha/lib/cli/cli.js","./src/ecc.test.ts","./src/hash.test.ts","./src/op.test.ts","./src/script.test.ts","./src/sigHashType.test.ts","./src/tx.test.ts","./src/unsignedTx.test.ts","./src/io/bytes.test.ts","./src/io/varsize.test.ts","./src/io/writerbytes.test.ts","./src/io/writerlength.test.ts","--reporter","mocha-junit-reporter","--reporter-option","mochaFile=test_results/ecash-lib-junit.xml","--reporter-option","testsuitesTitle=Ecash Lib Unit Tests","--reporter-option","rootSuiteTitle=Ecash Lib","--no-config","--no-package","--diff","--extension","js","--extension","cjs","--extension","mjs","--slow","75","--timeout","2000","--ui","bdd","--watch-ignore","node_modules","--watch-ignore",".git"],"execArgv":["--import=tsx"],"cwd":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib","time":1714065308447,"ppid":2715833,"coverageFilename":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/.nyc_output/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json","externalId":"","uuid":"0fc40ca6-d52c-45eb-b31b-2601ce70b887","files":[]}
@@ -1 +0,0 @@
1
- {"parent":null,"pid":2715808,"argv":["/home/joey/.nvm/versions/node/v20.11.0/bin/node","/home/joey/.nvm/versions/node/v20.11.0/bin/npm","test","--","--reporter","mocha-junit-reporter","--reporter-options","mochaFile=test_results/ecash-lib-junit.xml","--reporter-options","testsuitesTitle=Ecash Lib Unit Tests","--reporter-options","rootSuiteTitle=Ecash Lib"],"execArgv":[],"cwd":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib","time":1714065307741,"ppid":2715758,"coverageFilename":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/.nyc_output/ac5be6db-4e40-41f8-8b84-7598d4747e57.json","externalId":"","uuid":"ac5be6db-4e40-41f8-8b84-7598d4747e57","files":[]}
@@ -1 +0,0 @@
1
- {"parent":"ac5be6db-4e40-41f8-8b84-7598d4747e57","pid":2715833,"argv":["/home/joey/.nvm/versions/node/v20.11.0/bin/node","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/node_modules/.bin/mocha","--import=tsx","./src/ecc.test.ts","./src/hash.test.ts","./src/op.test.ts","./src/script.test.ts","./src/sigHashType.test.ts","./src/tx.test.ts","./src/unsignedTx.test.ts","./src/io/bytes.test.ts","./src/io/varsize.test.ts","./src/io/writerbytes.test.ts","./src/io/writerlength.test.ts","--reporter","mocha-junit-reporter","--reporter-options","mochaFile=test_results/ecash-lib-junit.xml","--reporter-options","testsuitesTitle=Ecash Lib Unit Tests","--reporter-options","rootSuiteTitle=Ecash Lib"],"execArgv":[],"cwd":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib","time":1714065308079,"ppid":2715832,"coverageFilename":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/.nyc_output/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json","externalId":"","uuid":"b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8","files":[]}
@@ -1 +0,0 @@
1
- {"parent":null,"pid":2715758,"argv":["/home/joey/.nvm/versions/node/v20.11.0/bin/node","/home/joey/.nvm/versions/node/v20.11.0/bin/nyc","--reporter=text","--reporter=lcov","--reporter=teamcity","npm","test","--","--reporter","mocha-junit-reporter","--reporter-options","mochaFile=test_results/ecash-lib-junit.xml","--reporter-options","testsuitesTitle=Ecash Lib Unit Tests","--reporter-options","rootSuiteTitle=Ecash Lib"],"execArgv":[],"cwd":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib","time":1714065305953,"ppid":2715321,"coverageFilename":"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/.nyc_output/f965566b-9422-4874-b45e-9eefda9c769c.json","externalId":"","uuid":"f965566b-9422-4874-b45e-9eefda9c769c","files":["/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/ffi/ecash_lib_wasm.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/ecc.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/hash.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/index.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/bytes.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/hex.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/int.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/str.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/varsize.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/writer.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/writerbytes.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/writerlength.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/op.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/opcode.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/script.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/sigHashType.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/token/alp.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/token/common.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/token/empp.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/tx.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/txBuilder.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/unsignedTx.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/eslint.config.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/ecc.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/ffi/ecash_lib_wasm.js","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/hash.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/index.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/bytes.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/hex.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/int.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/str.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/varsize.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/writer.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/writerbytes.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/writerlength.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/op.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/opcode.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/script.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/sigHashType.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/token/alp.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/token/common.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/token/empp.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/tx.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/txBuilder.ts","/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/unsignedTx.ts"]}
@@ -1 +0,0 @@
1
- {"processes":{"0fc40ca6-d52c-45eb-b31b-2601ce70b887":{"parent":"b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8","children":[]},"ac5be6db-4e40-41f8-8b84-7598d4747e57":{"parent":null,"children":["b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8"]},"b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8":{"parent":"ac5be6db-4e40-41f8-8b84-7598d4747e57","children":["0fc40ca6-d52c-45eb-b31b-2601ce70b887"]},"f965566b-9422-4874-b45e-9eefda9c769c":{"parent":null,"children":[]}},"files":{"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/ffi/ecash_lib_wasm.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/ecc.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/hash.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/index.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/bytes.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/hex.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/int.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/str.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/varsize.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/writer.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/writerbytes.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/io/writerlength.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/op.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/opcode.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/script.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/sigHashType.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/token/alp.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/token/common.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/token/empp.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/tx.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/txBuilder.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/dist/src/unsignedTx.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/eslint.config.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/ecc.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/ffi/ecash_lib_wasm.js":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/hash.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/index.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/bytes.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/hex.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/int.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/str.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/varsize.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/writer.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/writerbytes.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/io/writerlength.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/op.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/opcode.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/script.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/sigHashType.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/token/alp.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/token/common.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/token/empp.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/tx.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/txBuilder.ts":["f965566b-9422-4874-b45e-9eefda9c769c"],"/home/joey/github/abc/bitcoin-abc/modules/ecash-lib/src/unsignedTx.ts":["f965566b-9422-4874-b45e-9eefda9c769c"]},"externalIds":{}}
@@ -1,78 +0,0 @@
1
- /**
2
- * Handle cashaddr methods
3
- * Improve and extend existing functionality of the ecashaddrjs lib
4
- *
5
- * Spec
6
- * https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md
7
- */
8
- export type AddressType = 'p2pkh' | 'p2sh';
9
- export declare const ADDRESS_TYPES: AddressType[];
10
- export declare const VALID_HASH_SIZES: number[];
11
- /**
12
- * Converts an array of integers made up of 'from' bits into an
13
- * array of integers made up of 'to' bits. The output array is
14
- * zero-padded if necessary, unless strict mode is true.
15
- * Original by Pieter Wuille: https://github.com/sipa/bech32.
16
- *
17
- * @param data Array of integers made up of 'from' bits.
18
- * @param from Length in bits of elements in the input array.
19
- * @param to Length in bits of elements in the output array.
20
- * @param strictMode Require the conversion to be completed without padding.
21
- */
22
- export declare const convertBits: (data: Uint8Array, from: number, to: number, strictMode?: boolean) => Uint8Array;
23
- export declare const getHashSize: (versionByte: number) => number;
24
- /**
25
- * Base 32 encoding / decoding
26
- */
27
- export declare const BASE32_CHARSET: string;
28
- /**
29
- * Encodes the given array of 5-bit integers as a base32-encoded string.
30
- * @param data Array of integers between 0 and 31 inclusive.
31
- */
32
- export declare const encodeBase32: (data: Uint8Array) => string;
33
- export declare const decodeBase32: (string: string) => Uint8Array;
34
- /**
35
- * Encode a hash as a p2pkh or p2sh cashaddr
36
- * defaults to p2pkh "ecash"-prefixed cashaddr
37
- */
38
- export declare const toCashAddress: (hash: string | Uint8Array, prefix?: string, type?: AddressType) => string;
39
- interface DecodedAddress {
40
- prefix: string;
41
- type: AddressType;
42
- hash: string;
43
- }
44
- export declare const decodeCashAddress: (address: string) => DecodedAddress;
45
- /**
46
- * Get type and hash from an outputScript
47
- *
48
- * Supported outputScripts:
49
- *
50
- * p2pkh: 76a914<hash>88ac
51
- * p2sh: a914<hash>87
52
- *
53
- * Validates for supported outputScript and hash length
54
- */
55
- export declare const getTypeAndHashFromOutputScript: (outputScript: string) => {
56
- type: AddressType;
57
- hash: string;
58
- };
59
- export declare const outputScriptToAddress: (outputScript: string, prefix?: string) => string;
60
- export declare const ECASH_PREFIXES_MAINNET: string[];
61
- export declare const toLegacyAddress: (cashaddress: string) => string;
62
- type NetworkType = 'mainnet' | 'testnet';
63
- export interface DecodedLegacyAddress {
64
- type: AddressType;
65
- hash: string;
66
- network: NetworkType;
67
- }
68
- export declare const decodeLegacyAddress: (address: string) => DecodedLegacyAddress;
69
- /**
70
- * Encode a legacy address given type and hash
71
- * For now, this is a stub method that supports only BTC p2pkh and p2sh
72
- */
73
- export declare const encodeLegacyAddress: (hash: Uint8Array, type: 'p2pkh' | 'p2sh', network?: NetworkType) => string;
74
- export declare const isValidCashAddress: (cashaddress: string, optionalPrefix?: boolean | string) => boolean;
75
- export declare const encodeOutputScript: (type: AddressType, hash: string) => string;
76
- export declare const getOutputScriptFromAddress: (address: string) => string;
77
- export {};
78
- //# sourceMappingURL=cashaddr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cashaddr.d.ts","sourceRoot":"","sources":["../../src/address/cashaddr.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AAEH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAC3C,eAAO,MAAM,aAAa,EAAE,WAAW,EAAsB,CAAC;AAG9D,eAAO,MAAM,gBAAgB,UAAmC,CAAC;AAiEjE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,SACd,UAAU,QACV,MAAM,MACR,MAAM,eACE,OAAO,KACpB,UAqCF,CAAC;AAsDF,eAAO,MAAM,WAAW,gBAAiB,MAAM,KAAG,MAqBjD,CAAC;AAiBF;;GAEG;AAGH,eAAO,MAAM,cAAc,EAAE,MAA2C,CAAC;AAsCzE;;;GAGG;AACH,eAAO,MAAM,YAAY,SAAU,UAAU,KAAG,MAa/C,CAAC;AAGF,eAAO,MAAM,YAAY,WAAY,MAAM,KAAG,UAc7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,SAChB,MAAM,GAAG,UAAU,0BAEnB,WAAW,WAmCpB,CAAC;AAEF,UAAU,cAAc;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,cAmDnD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,8BAA8B,iBACzB,MAAM;UACb,WAAW;UAAQ,MAAM;CA4CnC,CAAC;AAGF,eAAO,MAAM,qBAAqB,iBAChB,MAAM,sBAErB,MAMF,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAAsB,CAAC;AAG1D,eAAO,MAAM,eAAe,gBAAiB,MAAM,KAAG,MAyCrD,CAAC;AAEF,KAAK,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AACzC,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;CACxB;AAuBD,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,oBA4CrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,SACtB,UAAU,QACV,OAAO,GAAG,MAAM,YACb,WAAW,WAOvB,CAAC;AAIF,eAAO,MAAM,kBAAkB,gBACd,MAAM,mBACH,OAAO,GAAG,MAAM,KACjC,OAUF,CAAC;AAEF,eAAO,MAAM,kBAAkB,SAAU,WAAW,QAAQ,MAAM,KAAG,MAQpE,CAAC;AAEF,eAAO,MAAM,0BAA0B,YAAa,MAAM,KAAG,MAS5D,CAAC"}
@@ -1,543 +0,0 @@
1
- "use strict";
2
- // Copyright (c) 2024 The Bitcoin developers
3
- // Distributed under the MIT software license, see the accompanying
4
- // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getOutputScriptFromAddress = exports.encodeOutputScript = exports.isValidCashAddress = exports.encodeLegacyAddress = exports.decodeLegacyAddress = exports.toLegacyAddress = exports.ECASH_PREFIXES_MAINNET = exports.outputScriptToAddress = exports.getTypeAndHashFromOutputScript = exports.decodeCashAddress = exports.toCashAddress = exports.decodeBase32 = exports.encodeBase32 = exports.BASE32_CHARSET = exports.getHashSize = exports.convertBits = exports.VALID_HASH_SIZES = exports.ADDRESS_TYPES = void 0;
7
- const hex_1 = require("../io/hex");
8
- const legacyaddr_1 = require("./legacyaddr");
9
- exports.ADDRESS_TYPES = ['p2pkh', 'p2sh'];
10
- // Per spec, valid hash sizes in bytes
11
- exports.VALID_HASH_SIZES = [20, 24, 28, 32, 40, 48, 56, 64];
12
- /**
13
- * Private methods ported from ecashaddrjs
14
- * Helper functions that are used by exported functions
15
- * We do not export cashaddr as a class because users should only bundle the functions they use
16
- */
17
- const prefixToUint5Array = (prefix) => {
18
- const result = new Uint8Array(prefix.length);
19
- for (let i = 0; i < prefix.length; ++i) {
20
- result[i] = prefix[i].charCodeAt(0) & 31;
21
- }
22
- return result;
23
- };
24
- /**
25
- * Converts an array of 5-bit integers back into an array of 8-bit integers,
26
- * removing extra zeroes left from padding if necessary.
27
- */
28
- const fromUint5Array = (data) => {
29
- return (0, exports.convertBits)(data, 5, 8, true);
30
- };
31
- const concat = (a, b) => {
32
- const ab = new Uint8Array(a.length + b.length);
33
- ab.set(a);
34
- ab.set(b, a.length);
35
- return ab;
36
- };
37
- const getTypeBits = (type) => {
38
- switch (type) {
39
- case 'p2pkh':
40
- return 0;
41
- case 'p2sh':
42
- return 8;
43
- default:
44
- throw new Error('Invalid type: ' + type + '.');
45
- }
46
- };
47
- const getHashSizeBits = (hash) => {
48
- switch (hash.length * 8) {
49
- case 160:
50
- return 0;
51
- case 192:
52
- return 1;
53
- case 224:
54
- return 2;
55
- case 256:
56
- return 3;
57
- case 320:
58
- return 4;
59
- case 384:
60
- return 5;
61
- case 448:
62
- return 6;
63
- case 512:
64
- return 7;
65
- default:
66
- throw new Error('Invalid hash size: ' + hash.length + '.');
67
- }
68
- };
69
- /**
70
- * Converts an array of integers made up of 'from' bits into an
71
- * array of integers made up of 'to' bits. The output array is
72
- * zero-padded if necessary, unless strict mode is true.
73
- * Original by Pieter Wuille: https://github.com/sipa/bech32.
74
- *
75
- * @param data Array of integers made up of 'from' bits.
76
- * @param from Length in bits of elements in the input array.
77
- * @param to Length in bits of elements in the output array.
78
- * @param strictMode Require the conversion to be completed without padding.
79
- */
80
- const convertBits = (data, from, to, strictMode = false) => {
81
- const length = strictMode
82
- ? Math.floor((data.length * from) / to)
83
- : Math.ceil((data.length * from) / to);
84
- const mask = (1 << to) - 1;
85
- const result = new Uint8Array(length);
86
- let index = 0;
87
- let accumulator = 0;
88
- let bits = 0;
89
- for (let i = 0; i < data.length; ++i) {
90
- const value = data[i];
91
- if (!(0 <= value && value >> from === 0)) {
92
- throw new Error(`Invalid value: ${value}`);
93
- }
94
- accumulator = (accumulator << from) | value;
95
- bits += from;
96
- while (bits >= to) {
97
- bits -= to;
98
- result[index] = (accumulator >> bits) & mask;
99
- ++index;
100
- }
101
- }
102
- if (!strictMode) {
103
- if (bits > 0) {
104
- result[index] = (accumulator << (to - bits)) & mask;
105
- ++index;
106
- }
107
- }
108
- else {
109
- if (!(bits < from && ((accumulator << (to - bits)) & mask) === 0)) {
110
- throw new Error('Input cannot be converted to ' +
111
- to +
112
- ' bits without padding, but strict mode was used.');
113
- }
114
- }
115
- return result;
116
- };
117
- exports.convertBits = convertBits;
118
- const toUint5Array = (data) => {
119
- return (0, exports.convertBits)(data, 8, 5);
120
- };
121
- const checksumToUint5Array = (checksum) => {
122
- const result = new Uint8Array(8);
123
- for (let i = 0; i < 8; ++i) {
124
- // Extract the least significant 5 bits (31 is 11111 in binary)
125
- result[7 - i] = Number(checksum & 31n);
126
- // Shift right by 5 bits
127
- checksum >>= 5n;
128
- }
129
- return result;
130
- };
131
- const polymod = (data) => {
132
- const GENERATOR = [
133
- BigInt('0x98f2bc8e61'),
134
- BigInt('0x79b76d99e2'),
135
- BigInt('0xf33e5fb3c4'),
136
- BigInt('0xae2eabe2a8'),
137
- BigInt('0x1e4f43e470'),
138
- ];
139
- let checksum = 1n; // BigInt for 1
140
- for (let i = 0; i < data.length; i += 1) {
141
- const value = BigInt(data[i]);
142
- const topBits = checksum >> 35n;
143
- checksum = ((checksum & 0x07ffffffffn) << 5n) ^ value;
144
- for (let j = 0; j < GENERATOR.length; ++j) {
145
- if ((topBits >> BigInt(j)) & 1n) {
146
- checksum ^= GENERATOR[j];
147
- }
148
- }
149
- }
150
- return checksum ^ 1n;
151
- };
152
- // Validation helper to ensure we do not accept addresses with mixed case
153
- const hasSingleCase = (string) => {
154
- return string === string.toLowerCase() || string === string.toUpperCase();
155
- };
156
- const validChecksum = (prefix, payload) => {
157
- const prefixData = concat(prefixToUint5Array(prefix), new Uint8Array(1));
158
- const checksumData = concat(prefixData, payload);
159
- return polymod(checksumData) === 0n;
160
- };
161
- // Retrieves the the length in bits of the encoded hash from its bit
162
- // representation within the version byte.
163
- const getHashSize = (versionByte) => {
164
- switch (versionByte & 7) {
165
- case 0:
166
- return 160;
167
- case 1:
168
- return 192;
169
- case 2:
170
- return 224;
171
- case 3:
172
- return 256;
173
- case 4:
174
- return 320;
175
- case 5:
176
- return 384;
177
- case 6:
178
- return 448;
179
- case 7:
180
- return 512;
181
- default:
182
- throw new Error('Invalid input');
183
- }
184
- };
185
- exports.getHashSize = getHashSize;
186
- // Retrieves the address type from its bit representation within the
187
- // version byte.
188
- const getType = (versionByte) => {
189
- switch (versionByte & 120) {
190
- case 0:
191
- return 'p2pkh';
192
- case 8:
193
- return 'p2sh';
194
- default:
195
- throw new Error(`Invalid address type in version byte: ${versionByte}`);
196
- }
197
- };
198
- /**
199
- * Base 32 encoding / decoding
200
- */
201
- // Charset containing the 32 symbols used in the base32 encoding.
202
- exports.BASE32_CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
203
- // Inverted index mapping each symbol into its index within the charset.
204
- const BASE32_CHARSET_INVERSE_INDEX = {
205
- q: 0,
206
- p: 1,
207
- z: 2,
208
- r: 3,
209
- y: 4,
210
- 9: 5,
211
- x: 6,
212
- 8: 7,
213
- g: 8,
214
- f: 9,
215
- 2: 10,
216
- t: 11,
217
- v: 12,
218
- d: 13,
219
- w: 14,
220
- 0: 15,
221
- s: 16,
222
- 3: 17,
223
- j: 18,
224
- n: 19,
225
- 5: 20,
226
- 4: 21,
227
- k: 22,
228
- h: 23,
229
- c: 24,
230
- e: 25,
231
- 6: 26,
232
- m: 27,
233
- u: 28,
234
- a: 29,
235
- 7: 30,
236
- l: 31,
237
- };
238
- /**
239
- * Encodes the given array of 5-bit integers as a base32-encoded string.
240
- * @param data Array of integers between 0 and 31 inclusive.
241
- */
242
- const encodeBase32 = (data) => {
243
- if (!(data instanceof Uint8Array)) {
244
- throw new Error(`Invalid data: ${data}. Data must be a Uint8Array`);
245
- }
246
- let base32 = '';
247
- for (let i = 0; i < data.length; ++i) {
248
- const value = data[i];
249
- if (!(0 <= value && value < 32)) {
250
- throw new Error(`Invalid value: ${value}.`);
251
- }
252
- base32 += exports.BASE32_CHARSET[value];
253
- }
254
- return base32;
255
- };
256
- exports.encodeBase32 = encodeBase32;
257
- // Decodes the given base32-encoded string into an array of 5-bit integers.
258
- const decodeBase32 = (string) => {
259
- if (typeof string !== 'string') {
260
- throw new Error(`Invalid base32-encoded string: ${string}.`);
261
- }
262
- const data = new Uint8Array(string.length);
263
- for (let i = 0; i < string.length; ++i) {
264
- const value = string[i];
265
- if (!(value in BASE32_CHARSET_INVERSE_INDEX)) {
266
- throw new Error(`Invalid value: ${value}.`);
267
- }
268
- data[i] = BASE32_CHARSET_INVERSE_INDEX[value];
269
- }
270
- return data;
271
- };
272
- exports.decodeBase32 = decodeBase32;
273
- /**
274
- * Encode a hash as a p2pkh or p2sh cashaddr
275
- * defaults to p2pkh "ecash"-prefixed cashaddr
276
- */
277
- const toCashAddress = (hash, prefix = 'ecash', type = 'p2pkh') => {
278
- // Validate hash type
279
- if (typeof hash === 'string') {
280
- hash = (0, hex_1.fromHex)(hash);
281
- }
282
- if (!(hash instanceof Uint8Array)) {
283
- throw new Error('hash must be a string or Uint8Array');
284
- }
285
- // Validate prefix for no mixed case
286
- if (!hasSingleCase(prefix)) {
287
- throw new Error(`Prefix cannot be mixed case ("${prefix}")`);
288
- }
289
- // Validate address type
290
- if (!exports.ADDRESS_TYPES.includes(type)) {
291
- throw new Error('type must be "p2pkh" or "p2sh"');
292
- }
293
- const prefixData = concat(prefixToUint5Array(prefix), new Uint8Array(1));
294
- // Get version byte and validate hash size
295
- const versionByte = getTypeBits(type) + getHashSizeBits(hash);
296
- const payloadData = toUint5Array(concat(new Uint8Array([versionByte]), hash));
297
- const checksumData = concat(concat(prefixData, payloadData), new Uint8Array(8));
298
- const payload = concat(payloadData, checksumToUint5Array(polymod(checksumData)));
299
- return prefix + ':' + (0, exports.encodeBase32)(payload);
300
- };
301
- exports.toCashAddress = toCashAddress;
302
- // Apologies for the unsettling yet accurate name
303
- const decodeCashAddress = (address) => {
304
- if (typeof address !== 'string') {
305
- throw new Error(`Address must be a string`);
306
- }
307
- if (!hasSingleCase(address)) {
308
- throw new Error(`Invalid address "${address}" (mixed-case input is not supported)`);
309
- }
310
- const pieces = address.toLowerCase().split(':');
311
- if (pieces.length > 2) {
312
- throw new Error(`Invalid address: ${address}: Address can contain only one prefix`);
313
- }
314
- let prefix, payload;
315
- if (pieces.length === 1) {
316
- // We only accept prefixless input for 'ecash' prefix
317
- const prefixlessPayload = (0, exports.decodeBase32)(pieces[0]);
318
- if (validChecksum('ecash', prefixlessPayload)) {
319
- // Here's your prefix
320
- prefix = 'ecash';
321
- payload = prefixlessPayload;
322
- }
323
- else {
324
- throw new Error(`Prefixless address checksums for prefix other than "ecash", please specify a prefix`);
325
- }
326
- }
327
- else {
328
- prefix = pieces[0];
329
- payload = (0, exports.decodeBase32)(pieces[1]);
330
- }
331
- // Validate prefix (we validate any prefix)
332
- if (!validChecksum(prefix, payload)) {
333
- throw new Error(`Invalid checksum: ${address}`);
334
- }
335
- // We assert that payload will be defined here, as we validate above
336
- const payloadData = fromUint5Array(payload.subarray(0, -8));
337
- const versionByte = payloadData[0];
338
- const hash = payloadData.subarray(1);
339
- if ((0, exports.getHashSize)(versionByte) !== hash.length * 8) {
340
- throw new Error(`Invalid hash size: ${address}`);
341
- }
342
- const type = getType(versionByte);
343
- return {
344
- prefix: prefix,
345
- type: type,
346
- hash: (0, hex_1.toHex)(hash),
347
- };
348
- };
349
- exports.decodeCashAddress = decodeCashAddress;
350
- /**
351
- * Get type and hash from an outputScript
352
- *
353
- * Supported outputScripts:
354
- *
355
- * p2pkh: 76a914<hash>88ac
356
- * p2sh: a914<hash>87
357
- *
358
- * Validates for supported outputScript and hash length
359
- */
360
- const getTypeAndHashFromOutputScript = (outputScript) => {
361
- const p2pkhPrefix = '76a914';
362
- const p2pkhSuffix = '88ac';
363
- const p2shPrefix = 'a914';
364
- const p2shSuffix = '87';
365
- let hash, type;
366
- // If outputScript begins with '76a914' and ends with '88ac'
367
- if (outputScript.slice(0, p2pkhPrefix.length) === p2pkhPrefix &&
368
- outputScript.slice(-1 * p2pkhSuffix.length) === p2pkhSuffix) {
369
- // We have type p2pkh
370
- type = 'p2pkh';
371
- // hash is the string in between '76a194' and '88ac'
372
- hash = outputScript.substring(outputScript.indexOf(p2pkhPrefix) + p2pkhPrefix.length, outputScript.lastIndexOf(p2pkhSuffix));
373
- // If outputScript begins with 'a914' and ends with '87'
374
- }
375
- else if (outputScript.slice(0, p2shPrefix.length) === p2shPrefix &&
376
- outputScript.slice(-1 * p2shSuffix.length) === p2shSuffix) {
377
- // We have type p2sh
378
- type = 'p2sh';
379
- // hash is the string in between 'a914' and '87'
380
- hash = outputScript.substring(outputScript.indexOf(p2shPrefix) + p2shPrefix.length, outputScript.lastIndexOf(p2shSuffix));
381
- }
382
- else {
383
- // Throw validation error if outputScript not of these two types
384
- throw new Error('Unsupported outputScript: ' + outputScript);
385
- }
386
- // Throw validation error if hash is of invalid size
387
- if (!exports.VALID_HASH_SIZES.includes(hash.length / 2)) {
388
- throw new Error('Invalid hash size in outputScript: ' + outputScript);
389
- }
390
- return { type, hash };
391
- };
392
- exports.getTypeAndHashFromOutputScript = getTypeAndHashFromOutputScript;
393
- // Encodes a given outputScript into an eCash address using the optionally specified prefix.
394
- const outputScriptToAddress = (outputScript, prefix = 'ecash') => {
395
- // Get type and hash from outputScript
396
- const { type, hash } = (0, exports.getTypeAndHashFromOutputScript)(outputScript);
397
- // The encode function validates hash for correct length
398
- return (0, exports.toCashAddress)(hash, prefix, type);
399
- };
400
- exports.outputScriptToAddress = outputScriptToAddress;
401
- exports.ECASH_PREFIXES_MAINNET = ['ecash', 'etoken'];
402
- // Converts an ecash address to legacy format
403
- const toLegacyAddress = (cashaddress) => {
404
- // If called with legacy, return input
405
- try {
406
- (0, exports.decodeLegacyAddress)(cashaddress);
407
- // A legacy address is a legacy address
408
- return cashaddress;
409
- }
410
- catch {
411
- // We expect an error for the most common use case of converting a cashaddr to a legacy addr
412
- // Do nothing
413
- }
414
- const { prefix, type, hash } = (0, exports.decodeCashAddress)(cashaddress);
415
- const isMainnet = exports.ECASH_PREFIXES_MAINNET.includes(prefix);
416
- // Get correct version byte for legacy format
417
- let versionByte;
418
- switch (type) {
419
- case 'p2pkh':
420
- versionByte = isMainnet ? 0 : 111;
421
- break;
422
- case 'p2sh':
423
- versionByte = isMainnet ? 5 : 196;
424
- break;
425
- default:
426
- throw new Error('Unsupported address type: ' + type);
427
- }
428
- // Convert hash to Uint8Array
429
- const hashArray = (0, hex_1.fromHex)(hash);
430
- // Create a new Uint8Array to hold the data
431
- const uint8Array = new Uint8Array(1 + hashArray.length);
432
- // Set the version byte
433
- uint8Array[0] = versionByte;
434
- // Set the hash
435
- uint8Array.set(hashArray, 1);
436
- // Encode to base58check
437
- return (0, legacyaddr_1.encodeBase58Check)(uint8Array);
438
- };
439
- exports.toLegacyAddress = toLegacyAddress;
440
- // Length of a valid base58check encoding payload: 1 byte for
441
- // the version byte plus 20 bytes for a RIPEMD - 160 hash.
442
- const BASE_58_CHECK_PAYLOAD_LENGTH = 21;
443
- const VERSION_BYTES = {
444
- legacy: {
445
- mainnet: { p2pkh: 0, p2sh: 5 },
446
- testnet: { p2pkh: 111, p2sh: 196 },
447
- },
448
- };
449
- // Modeled from https://github.com/ealmansi/bchaddrjs/blob/master/src/bchaddr.js#L193
450
- const decodeLegacyAddress = (address) => {
451
- try {
452
- const payload = (0, legacyaddr_1.decodeBase58Check)(address);
453
- if (payload.length !== BASE_58_CHECK_PAYLOAD_LENGTH) {
454
- throw new Error(`Invalid legacy address: payload length must be ${BASE_58_CHECK_PAYLOAD_LENGTH}`);
455
- }
456
- const versionByte = payload[0];
457
- const hash = (0, hex_1.toHex)(new Uint8Array(payload.slice(1)));
458
- switch (versionByte) {
459
- case VERSION_BYTES.legacy.mainnet.p2pkh:
460
- return {
461
- hash,
462
- type: 'p2pkh',
463
- network: 'mainnet',
464
- };
465
- case VERSION_BYTES.legacy.mainnet.p2sh:
466
- return {
467
- hash,
468
- type: 'p2sh',
469
- network: 'mainnet',
470
- };
471
- case VERSION_BYTES.legacy.testnet.p2pkh:
472
- return {
473
- hash,
474
- type: 'p2pkh',
475
- network: 'testnet',
476
- };
477
- case VERSION_BYTES.legacy.testnet.p2sh:
478
- return {
479
- hash,
480
- type: 'p2sh',
481
- network: 'testnet',
482
- };
483
- default: {
484
- throw new Error(`Invalid legacy address: unrecognized version byte "${versionByte}"`);
485
- }
486
- }
487
- }
488
- catch {
489
- throw new Error(`Invalid legacy address`);
490
- }
491
- };
492
- exports.decodeLegacyAddress = decodeLegacyAddress;
493
- /**
494
- * Encode a legacy address given type and hash
495
- * For now, this is a stub method that supports only BTC p2pkh and p2sh
496
- */
497
- const encodeLegacyAddress = (hash, type, network = 'mainnet') => {
498
- const versionByte = VERSION_BYTES.legacy[network][type];
499
- const combined = new Uint8Array(1 + hash.length);
500
- combined[0] = versionByte;
501
- combined.set(hash, 1);
502
- return (0, legacyaddr_1.encodeBase58Check)(combined);
503
- };
504
- exports.encodeLegacyAddress = encodeLegacyAddress;
505
- // Return true for a valid cashaddress
506
- // Prefixless addresses with valid checksum are also valid for prefix "ecash"
507
- const isValidCashAddress = (cashaddress, optionalPrefix = false) => {
508
- try {
509
- const { prefix } = (0, exports.decodeCashAddress)(cashaddress);
510
- if (optionalPrefix) {
511
- return prefix === optionalPrefix;
512
- }
513
- return true;
514
- }
515
- catch {
516
- return false;
517
- }
518
- };
519
- exports.isValidCashAddress = isValidCashAddress;
520
- const encodeOutputScript = (type, hash) => {
521
- let registrationOutputScript;
522
- if (type === 'p2pkh') {
523
- registrationOutputScript = `76a914${hash}88ac`;
524
- }
525
- else {
526
- registrationOutputScript = `a914${hash}87`;
527
- }
528
- return registrationOutputScript;
529
- };
530
- exports.encodeOutputScript = encodeOutputScript;
531
- const getOutputScriptFromAddress = (address) => {
532
- const { type, hash } = (0, exports.decodeCashAddress)(address);
533
- let registrationOutputScript;
534
- if (type === 'p2pkh') {
535
- registrationOutputScript = `76a914${hash}88ac`;
536
- }
537
- else {
538
- registrationOutputScript = `a914${hash}87`;
539
- }
540
- return registrationOutputScript;
541
- };
542
- exports.getOutputScriptFromAddress = getOutputScriptFromAddress;
543
- //# sourceMappingURL=cashaddr.js.map