ecash-lib 1.1.0 → 1.2.1-rc
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.
- package/.nyc_output/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +1 -0
- package/.nyc_output/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +1 -0
- package/.nyc_output/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +1 -0
- package/.nyc_output/f965566b-9422-4874-b45e-9eefda9c769c.json +1 -0
- package/.nyc_output/processinfo/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +1 -0
- package/.nyc_output/processinfo/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +1 -0
- package/.nyc_output/processinfo/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +1 -0
- package/.nyc_output/processinfo/f965566b-9422-4874-b45e-9eefda9c769c.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/README.md +2 -0
- package/dist/address/address.d.ts +131 -0
- package/dist/address/address.d.ts.map +1 -0
- package/dist/address/address.js +253 -0
- package/dist/address/address.js.map +1 -0
- package/dist/address/cashaddr.d.ts +78 -0
- package/dist/address/cashaddr.d.ts.map +1 -0
- package/dist/address/cashaddr.js +543 -0
- package/dist/address/cashaddr.js.map +1 -0
- package/dist/address/legacyaddr.d.ts +31 -0
- package/dist/address/legacyaddr.d.ts.map +1 -0
- package/dist/address/legacyaddr.js +101 -0
- package/dist/address/legacyaddr.js.map +1 -0
- package/dist/cashaddr/cashaddr.d.ts +23 -0
- package/dist/cashaddr/cashaddr.d.ts.map +1 -0
- package/dist/cashaddr/cashaddr.js +325 -0
- package/dist/cashaddr/cashaddr.js.map +1 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +15 -51
- package/dist/script.js.map +1 -1
- package/dist/txBuilder.d.ts.map +1 -1
- package/dist/txBuilder.js +4 -1
- package/dist/txBuilder.js.map +1 -1
- package/package.json +5 -3
- package/test.log +82 -0
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1 @@
|
|
|
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":{}}
|
package/README.md
CHANGED
|
@@ -105,3 +105,5 @@ console.log(toHex(rawTx));
|
|
|
105
105
|
- 1.0.0 - **(Breaking change)** Modify `GenesisInfo` so that `auth` and `data` types match [D17194](https://reviews.bitcoinabc.org/D17194)
|
|
106
106
|
- 1.0.1 - Include `ecashaddrjs` and `chronik-client` installations from `npmjs` instead of local, to prevent need for peer dependencies [D17215](https://reviews.bitcoinabc.org/D17215)
|
|
107
107
|
- 1.1.0 - Add support for the original pre-UAHF Bitcoin signatures, so we can sign transactions for other blockchains like BTC/DOGE/... [D17255](https://reviews.bitcoinabc.org/D17255)
|
|
108
|
+
- 1.2.0 - Add `Address` class for cashaddr and legacy addresses. [D17269](https://reviews.bitcoinabc.org/D17269)
|
|
109
|
+
- 1.2.1 - Patch type check causing txBuilder txs using change to fail in NodeJS environments [D17461](https://reviews.bitcoinabc.org/D17461)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Script } from '../script';
|
|
2
|
+
export type AddressType = 'p2pkh' | 'p2sh';
|
|
3
|
+
export type AddressEncoding = 'cashaddr' | 'legacy';
|
|
4
|
+
export declare const ECASH_PREFIXES_TESTNET: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Converts an ecash address in cashaddr format to legacy format
|
|
7
|
+
* Throws if user attempts to convert a legacy address to a legacy address
|
|
8
|
+
* Separated as its own function here for
|
|
9
|
+
*
|
|
10
|
+
* 1 - simpler unit testing
|
|
11
|
+
* 2 - exported for users looking to convert string cashaddr to string legacy addr
|
|
12
|
+
* without using the Address class
|
|
13
|
+
*/
|
|
14
|
+
export declare const toLegacyAddress: (cashaddress: string) => string;
|
|
15
|
+
interface AddressInterface {
|
|
16
|
+
/**
|
|
17
|
+
* hash
|
|
18
|
+
* The hash this address encodes as a hex string.
|
|
19
|
+
* It's part of the Script this address represents.
|
|
20
|
+
*/
|
|
21
|
+
hash: string;
|
|
22
|
+
/**
|
|
23
|
+
* p2pkh or p2sh
|
|
24
|
+
* The type of address
|
|
25
|
+
* Address supports p2pkh or p2sh address types
|
|
26
|
+
*/
|
|
27
|
+
type: AddressType;
|
|
28
|
+
/**
|
|
29
|
+
* Defined for a cashaddr address, i.e. one with encoding === 'cashaddr'
|
|
30
|
+
* This is distinct from the version byte. Common prefixes on ecash include
|
|
31
|
+
* 'ecash', 'etoken', 'ectest', and 'ecregest'. But a prefix could be anything
|
|
32
|
+
* so long as the address checksum matches.
|
|
33
|
+
*/
|
|
34
|
+
prefix?: string;
|
|
35
|
+
/**
|
|
36
|
+
* encoded address as a string
|
|
37
|
+
* cashaddr or legacy
|
|
38
|
+
* type available in 'encoding' field
|
|
39
|
+
*/
|
|
40
|
+
address: string;
|
|
41
|
+
/**
|
|
42
|
+
* How this address is encoded
|
|
43
|
+
* cashaddr or legacy
|
|
44
|
+
* If cashaddr, 'prefix' is defined and a string
|
|
45
|
+
*/
|
|
46
|
+
encoding: AddressEncoding;
|
|
47
|
+
}
|
|
48
|
+
export declare const DEFAULT_PREFIX = "ecash";
|
|
49
|
+
/**
|
|
50
|
+
* Address
|
|
51
|
+
* Stores properties of supported crypto addresses
|
|
52
|
+
* in standard typed structure. Provides methods for
|
|
53
|
+
* easy access of address data in dev-friendly formats.
|
|
54
|
+
* Provides methods for instantiating by type, encoding,
|
|
55
|
+
* script, prefix, and address string of arbitrary encoding.
|
|
56
|
+
*
|
|
57
|
+
* Simplifies conversion between cashaddr prefixes and
|
|
58
|
+
* address encoding types.
|
|
59
|
+
*
|
|
60
|
+
* Address is an ecash-first class. Legacy BTC format
|
|
61
|
+
* is supported to simplify conversion to and from
|
|
62
|
+
* ecash addresses.
|
|
63
|
+
*
|
|
64
|
+
* Address may be extended to support other crypto
|
|
65
|
+
* address formats.
|
|
66
|
+
*/
|
|
67
|
+
export declare class Address implements AddressInterface {
|
|
68
|
+
hash: string;
|
|
69
|
+
type: AddressType;
|
|
70
|
+
prefix?: string;
|
|
71
|
+
address: string;
|
|
72
|
+
encoding: AddressEncoding;
|
|
73
|
+
private constructor();
|
|
74
|
+
/**
|
|
75
|
+
* Create a new p2pkh Address from hash
|
|
76
|
+
* cashaddr encoding, ecash: prefix
|
|
77
|
+
*/
|
|
78
|
+
static p2pkh: (hash: string | Uint8Array) => Address;
|
|
79
|
+
/**
|
|
80
|
+
* Create a new p2sh Address from hash
|
|
81
|
+
* cashaddr encoding
|
|
82
|
+
* ecash: prefix
|
|
83
|
+
*/
|
|
84
|
+
static p2sh: (hash: string | Uint8Array) => Address;
|
|
85
|
+
/**
|
|
86
|
+
* Create a new Address from a given address string
|
|
87
|
+
* address must be valid legacy or cashaddr address
|
|
88
|
+
*/
|
|
89
|
+
static parse: (address: string) => Address;
|
|
90
|
+
/**
|
|
91
|
+
* Create a new Address from a cashaddr
|
|
92
|
+
* prefix, type, and hash from creating cashaddr
|
|
93
|
+
*/
|
|
94
|
+
static fromCashAddress: (address: string) => Address;
|
|
95
|
+
/**
|
|
96
|
+
* Create a new Address from legacy address
|
|
97
|
+
* No prefix for Address created from legacy address
|
|
98
|
+
* type and hash from legacy address
|
|
99
|
+
*/
|
|
100
|
+
static fromLegacyAddress: (legacy: string) => Address;
|
|
101
|
+
/**
|
|
102
|
+
* Create a new Address from an outputScript as Script
|
|
103
|
+
* type and hash from outputScript
|
|
104
|
+
* cashaddr encoding
|
|
105
|
+
* ecash: prefix
|
|
106
|
+
*/
|
|
107
|
+
static fromScript: (script: Script) => Address;
|
|
108
|
+
/**
|
|
109
|
+
* Create a new Address from an outputScript as hex string
|
|
110
|
+
* type and hash from outputScript
|
|
111
|
+
* cashaddr encoding
|
|
112
|
+
* ecash: prefix
|
|
113
|
+
*/
|
|
114
|
+
static fromScriptHex: (scriptHex: string) => Address;
|
|
115
|
+
toString: () => string;
|
|
116
|
+
legacy: () => Address;
|
|
117
|
+
/**
|
|
118
|
+
* Create an Address with cashaddr encoding
|
|
119
|
+
* from an existing Address
|
|
120
|
+
*/
|
|
121
|
+
cash: () => Address;
|
|
122
|
+
/**
|
|
123
|
+
* Create address with specified prefix
|
|
124
|
+
* from an existing cashaddr-encoding Address
|
|
125
|
+
*/
|
|
126
|
+
withPrefix: (prefix: string) => Address;
|
|
127
|
+
toScript: () => Script;
|
|
128
|
+
toScriptHex: () => string;
|
|
129
|
+
}
|
|
130
|
+
export {};
|
|
131
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address/address.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAC3C,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEpD,eAAO,MAAM,sBAAsB,UAA0B,CAAC;AAE9D;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,gBAAiB,MAAM,KAAG,MA4CrD,CAAC;AAEF,UAAU,gBAAgB;IACtB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,IAAI,EAAE,WAAW,CAAC;IAClB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,QAAQ,EAAE,eAAe,CAAC;CAC7B;AAaD,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAQ,YAAW,gBAAgB;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;IAE1B,OAAO;IAWP;;;OAGG;IACH,MAAM,CAAC,KAAK,SAAU,MAAM,GAAG,UAAU,aAOlC;IAEP;;;;OAIG;IACH,MAAM,CAAC,IAAI,SAAU,MAAM,GAAG,UAAU,aAOjC;IAEP;;;OAGG;IACH,MAAM,CAAC,KAAK,YAAa,MAAM,aAsB7B;IAEF;;;OAGG;IACH,MAAM,CAAC,eAAe,YAAa,MAAM,aASvC;IAEF;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,WAAY,MAAM,aASxC;IAEF;;;;;OAKG;IACH,MAAM,CAAC,UAAU,WAAY,MAAM,aAGjC;IAEF;;;;;OAKG;IACH,MAAM,CAAC,aAAa,cAAe,MAAM,aAcvC;IAEF,QAAQ,eAEN;IAEF,MAAM,gBAMC;IAEP;;;OAGG;IACH,IAAI,gBAgBG;IAEP;;;OAGG;IACH,UAAU,WAAY,MAAM,aAgB1B;IAEF,QAAQ,QAAO,MAAM,CAInB;IAEF,WAAW,QAAO,MAAM,CAEtB;CACL"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Address = exports.DEFAULT_PREFIX = exports.toLegacyAddress = exports.ECASH_PREFIXES_TESTNET = void 0;
|
|
4
|
+
// Copyright (c) 2024 The Bitcoin developers
|
|
5
|
+
// Distributed under the MIT software license, see the accompanying
|
|
6
|
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
7
|
+
const hex_1 = require("../io/hex");
|
|
8
|
+
const ecashaddrjs_1 = require("ecashaddrjs");
|
|
9
|
+
const legacyaddr_1 = require("./legacyaddr");
|
|
10
|
+
const script_1 = require("../script");
|
|
11
|
+
exports.ECASH_PREFIXES_TESTNET = ['ectest', 'ecregtest'];
|
|
12
|
+
/**
|
|
13
|
+
* Converts an ecash address in cashaddr format to legacy format
|
|
14
|
+
* Throws if user attempts to convert a legacy address to a legacy address
|
|
15
|
+
* Separated as its own function here for
|
|
16
|
+
*
|
|
17
|
+
* 1 - simpler unit testing
|
|
18
|
+
* 2 - exported for users looking to convert string cashaddr to string legacy addr
|
|
19
|
+
* without using the Address class
|
|
20
|
+
*/
|
|
21
|
+
const toLegacyAddress = (cashaddress) => {
|
|
22
|
+
try {
|
|
23
|
+
// No-op if user is trying to convert legacy to legacy
|
|
24
|
+
(0, legacyaddr_1.decodeLegacyAddress)(cashaddress);
|
|
25
|
+
return cashaddress;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Do nothing with this error since we expect it every time for the function's intended use case
|
|
29
|
+
// Proceed to convert to legacy
|
|
30
|
+
}
|
|
31
|
+
const { prefix, type, hash } = (0, ecashaddrjs_1.decodeCashAddress)(cashaddress);
|
|
32
|
+
const isTestnet = exports.ECASH_PREFIXES_TESTNET.includes(prefix);
|
|
33
|
+
// Get correct version byte for legacy format
|
|
34
|
+
let versionByte;
|
|
35
|
+
switch (type) {
|
|
36
|
+
case 'p2pkh':
|
|
37
|
+
versionByte = isTestnet
|
|
38
|
+
? legacyaddr_1.LEGACY_VERSION_BYTES.legacy.testnet.p2pkh
|
|
39
|
+
: legacyaddr_1.LEGACY_VERSION_BYTES.legacy.mainnet.p2pkh;
|
|
40
|
+
break;
|
|
41
|
+
case 'p2sh':
|
|
42
|
+
versionByte = isTestnet
|
|
43
|
+
? legacyaddr_1.LEGACY_VERSION_BYTES.legacy.testnet.p2sh
|
|
44
|
+
: legacyaddr_1.LEGACY_VERSION_BYTES.legacy.mainnet.p2sh;
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
throw new Error('Unsupported address type: ' + type);
|
|
48
|
+
}
|
|
49
|
+
// Convert hash to Uint8Array
|
|
50
|
+
const hashArray = (0, hex_1.fromHex)(hash);
|
|
51
|
+
// Create a new Uint8Array to hold the data
|
|
52
|
+
const uint8Array = new Uint8Array(1 + hashArray.length);
|
|
53
|
+
// Set the version byte
|
|
54
|
+
uint8Array[0] = versionByte;
|
|
55
|
+
// Set the hash
|
|
56
|
+
uint8Array.set(hashArray, 1);
|
|
57
|
+
// Encode to base58check
|
|
58
|
+
return (0, legacyaddr_1.encodeBase58Check)(uint8Array);
|
|
59
|
+
};
|
|
60
|
+
exports.toLegacyAddress = toLegacyAddress;
|
|
61
|
+
exports.DEFAULT_PREFIX = 'ecash';
|
|
62
|
+
/**
|
|
63
|
+
* Address
|
|
64
|
+
* Stores properties of supported crypto addresses
|
|
65
|
+
* in standard typed structure. Provides methods for
|
|
66
|
+
* easy access of address data in dev-friendly formats.
|
|
67
|
+
* Provides methods for instantiating by type, encoding,
|
|
68
|
+
* script, prefix, and address string of arbitrary encoding.
|
|
69
|
+
*
|
|
70
|
+
* Simplifies conversion between cashaddr prefixes and
|
|
71
|
+
* address encoding types.
|
|
72
|
+
*
|
|
73
|
+
* Address is an ecash-first class. Legacy BTC format
|
|
74
|
+
* is supported to simplify conversion to and from
|
|
75
|
+
* ecash addresses.
|
|
76
|
+
*
|
|
77
|
+
* Address may be extended to support other crypto
|
|
78
|
+
* address formats.
|
|
79
|
+
*/
|
|
80
|
+
class Address {
|
|
81
|
+
constructor(params) {
|
|
82
|
+
this.toString = () => {
|
|
83
|
+
return this.address;
|
|
84
|
+
};
|
|
85
|
+
this.legacy = () => new Address({
|
|
86
|
+
type: this.type,
|
|
87
|
+
hash: this.hash,
|
|
88
|
+
address: (0, exports.toLegacyAddress)(this.address),
|
|
89
|
+
encoding: 'legacy',
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Create an Address with cashaddr encoding
|
|
93
|
+
* from an existing Address
|
|
94
|
+
*/
|
|
95
|
+
this.cash = () => new Address({
|
|
96
|
+
type: this.type,
|
|
97
|
+
hash: this.hash,
|
|
98
|
+
address: (0, ecashaddrjs_1.encodeCashAddress)(typeof this.prefix !== 'undefined'
|
|
99
|
+
? this.prefix
|
|
100
|
+
: exports.DEFAULT_PREFIX, this.type, this.hash),
|
|
101
|
+
encoding: 'cashaddr',
|
|
102
|
+
prefix: typeof this.prefix !== 'undefined'
|
|
103
|
+
? this.prefix
|
|
104
|
+
: exports.DEFAULT_PREFIX,
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Create address with specified prefix
|
|
108
|
+
* from an existing cashaddr-encoding Address
|
|
109
|
+
*/
|
|
110
|
+
this.withPrefix = (prefix) => {
|
|
111
|
+
if (this.encoding === 'legacy') {
|
|
112
|
+
// Take no action for legacy address types
|
|
113
|
+
throw new Error('withPrefix does not support legacy address types');
|
|
114
|
+
}
|
|
115
|
+
if (this.prefix === prefix) {
|
|
116
|
+
// Take no action if prefix is not changing
|
|
117
|
+
throw new Error(`prefix is already "${this.prefix}"`);
|
|
118
|
+
}
|
|
119
|
+
return new Address({
|
|
120
|
+
type: this.type,
|
|
121
|
+
hash: this.hash,
|
|
122
|
+
prefix,
|
|
123
|
+
address: (0, ecashaddrjs_1.encodeCashAddress)(prefix, this.type, this.hash),
|
|
124
|
+
encoding: 'cashaddr',
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
this.toScript = () => {
|
|
128
|
+
return new script_1.Script((0, hex_1.fromHex)((0, ecashaddrjs_1.getOutputScriptFromTypeAndHash)(this.type, this.hash)));
|
|
129
|
+
};
|
|
130
|
+
this.toScriptHex = () => {
|
|
131
|
+
return (0, ecashaddrjs_1.getOutputScriptFromTypeAndHash)(this.type, this.hash);
|
|
132
|
+
};
|
|
133
|
+
const { hash, type, address, encoding } = params;
|
|
134
|
+
this.hash = hash;
|
|
135
|
+
this.type = type;
|
|
136
|
+
this.address = address;
|
|
137
|
+
this.encoding = encoding;
|
|
138
|
+
if (typeof params.prefix !== 'undefined') {
|
|
139
|
+
this.prefix = params.prefix;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.Address = Address;
|
|
144
|
+
/**
|
|
145
|
+
* Create a new p2pkh Address from hash
|
|
146
|
+
* cashaddr encoding, ecash: prefix
|
|
147
|
+
*/
|
|
148
|
+
Address.p2pkh = (hash) => new Address({
|
|
149
|
+
type: 'p2pkh',
|
|
150
|
+
hash: hash instanceof Uint8Array ? (0, hex_1.toHex)(hash) : hash,
|
|
151
|
+
prefix: exports.DEFAULT_PREFIX,
|
|
152
|
+
address: (0, ecashaddrjs_1.encodeCashAddress)(exports.DEFAULT_PREFIX, 'p2pkh', hash),
|
|
153
|
+
encoding: 'cashaddr',
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* Create a new p2sh Address from hash
|
|
157
|
+
* cashaddr encoding
|
|
158
|
+
* ecash: prefix
|
|
159
|
+
*/
|
|
160
|
+
Address.p2sh = (hash) => new Address({
|
|
161
|
+
type: 'p2sh',
|
|
162
|
+
hash: hash instanceof Uint8Array ? (0, hex_1.toHex)(hash) : hash,
|
|
163
|
+
prefix: exports.DEFAULT_PREFIX,
|
|
164
|
+
address: (0, ecashaddrjs_1.encodeCashAddress)(exports.DEFAULT_PREFIX, 'p2sh', hash),
|
|
165
|
+
encoding: 'cashaddr',
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* Create a new Address from a given address string
|
|
169
|
+
* address must be valid legacy or cashaddr address
|
|
170
|
+
*/
|
|
171
|
+
Address.parse = (address) => {
|
|
172
|
+
if ((0, ecashaddrjs_1.isValidCashAddress)(address)) {
|
|
173
|
+
const { type, hash, prefix } = (0, ecashaddrjs_1.decodeCashAddress)(address);
|
|
174
|
+
return new Address({
|
|
175
|
+
type,
|
|
176
|
+
hash,
|
|
177
|
+
prefix,
|
|
178
|
+
encoding: 'cashaddr',
|
|
179
|
+
address,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const { type, hash } = (0, legacyaddr_1.decodeLegacyAddress)(address);
|
|
184
|
+
return new Address({
|
|
185
|
+
type,
|
|
186
|
+
hash,
|
|
187
|
+
encoding: 'legacy',
|
|
188
|
+
address,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
throw new Error('Invalid cashaddr or legacy address');
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Create a new Address from a cashaddr
|
|
197
|
+
* prefix, type, and hash from creating cashaddr
|
|
198
|
+
*/
|
|
199
|
+
Address.fromCashAddress = (address) => {
|
|
200
|
+
const { type, hash, prefix } = (0, ecashaddrjs_1.decodeCashAddress)(address);
|
|
201
|
+
return new Address({
|
|
202
|
+
type,
|
|
203
|
+
hash,
|
|
204
|
+
address,
|
|
205
|
+
encoding: 'cashaddr',
|
|
206
|
+
prefix,
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Create a new Address from legacy address
|
|
211
|
+
* No prefix for Address created from legacy address
|
|
212
|
+
* type and hash from legacy address
|
|
213
|
+
*/
|
|
214
|
+
Address.fromLegacyAddress = (legacy) => {
|
|
215
|
+
// Determine addr params from legacy address
|
|
216
|
+
const { type, hash } = (0, legacyaddr_1.decodeLegacyAddress)(legacy);
|
|
217
|
+
return new Address({
|
|
218
|
+
type,
|
|
219
|
+
hash,
|
|
220
|
+
address: legacy,
|
|
221
|
+
encoding: 'legacy',
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Create a new Address from an outputScript as Script
|
|
226
|
+
* type and hash from outputScript
|
|
227
|
+
* cashaddr encoding
|
|
228
|
+
* ecash: prefix
|
|
229
|
+
*/
|
|
230
|
+
Address.fromScript = (script) => {
|
|
231
|
+
const scriptHex = (0, hex_1.toHex)(script.bytecode);
|
|
232
|
+
return Address.fromScriptHex(scriptHex);
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Create a new Address from an outputScript as hex string
|
|
236
|
+
* type and hash from outputScript
|
|
237
|
+
* cashaddr encoding
|
|
238
|
+
* ecash: prefix
|
|
239
|
+
*/
|
|
240
|
+
Address.fromScriptHex = (scriptHex) => {
|
|
241
|
+
const { type, hash } = (0, ecashaddrjs_1.getTypeAndHashFromOutputScript)(scriptHex);
|
|
242
|
+
// Default cashaddr encoding with default prefix
|
|
243
|
+
const address = (0, ecashaddrjs_1.encodeCashAddress)(exports.DEFAULT_PREFIX, type, hash);
|
|
244
|
+
const prefix = exports.DEFAULT_PREFIX;
|
|
245
|
+
return new Address({
|
|
246
|
+
type,
|
|
247
|
+
hash,
|
|
248
|
+
prefix,
|
|
249
|
+
address,
|
|
250
|
+
encoding: 'cashaddr',
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/address/address.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;AACtE,mCAA2C;AAC3C,6CAMqB;AACrB,6CAIsB;AACtB,sCAAmC;AAKtB,QAAA,sBAAsB,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACI,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAU,EAAE;IAC3D,IAAI,CAAC;QACD,sDAAsD;QACtD,IAAA,gCAAmB,EAAC,WAAW,CAAC,CAAC;QACjC,OAAO,WAAW,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACL,gGAAgG;QAChG,+BAA+B;IACnC,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAA,+BAAiB,EAAC,WAAW,CAAC,CAAC;IAE9D,MAAM,SAAS,GAAG,8BAAsB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE1D,6CAA6C;IAC7C,I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AAc,EAAE,EAAE;IAC1C,4CAA4C;IAC5C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAA,gCAAmB,EAAC,MAAM,CAAC,CAAC;IACnD,OAAO,IAAI,OAAO,CAAC;QACf,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,QAAQ;KACrB,CAAC,CAAC;AACP,CAAC,AATuB,CAStB;AAEF;;;;;GAKG;AACI,kBAAU,GAAG,CAAC,MAAc,EAAE,EAAE;IACnC,MAAM,SAAS,GAAG,IAAA,WAAK,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AAC5C,CAAC,AAHgB,CAGf;AAEF;;;;;GAKG;AACI,qBAAa,GAAG,CAAC,SAAiB,EAAE,EAAE;IACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAA,4CAA8B,EAAC,SAAS,CAAC,CAAC;IAEjE,gDAAgD;IAChD,MAAM,OAAO,GAAG,IAAA,+BAAiB,EAAC,sBAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,sBAAc,CAAC;IAE9B,OAAO,IAAI,OAAO,CAAC;QACf,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,OAAO;QACP,QAAQ,EAAE,UAAU;KACvB,CAAC,CAAC;AACP,CAAC,AAdmB,CAclB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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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