ecash-lib 1.1.0 → 1.2.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.
package/README.md CHANGED
@@ -105,3 +105,4 @@ 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)
@@ -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,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;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,31 @@
1
+ import { AddressType } from './address';
2
+ /**
3
+ * Base 58 Check
4
+ */
5
+ export declare const encodeBase58Check: (data: Uint8Array) => string;
6
+ export declare const decodeBase58Check: (str: string) => Uint8Array;
7
+ type NetworkType = 'mainnet' | 'testnet';
8
+ export interface DecodedLegacyAddress {
9
+ type: AddressType;
10
+ hash: string;
11
+ network: NetworkType;
12
+ }
13
+ interface NetworkVersionBytes {
14
+ p2pkh: number;
15
+ p2sh: number;
16
+ }
17
+ interface VersionByteReference {
18
+ legacy: {
19
+ mainnet: NetworkVersionBytes;
20
+ testnet: NetworkVersionBytes;
21
+ };
22
+ }
23
+ export declare const LEGACY_VERSION_BYTES: VersionByteReference;
24
+ export declare const decodeLegacyAddress: (address: string) => DecodedLegacyAddress;
25
+ /**
26
+ * Encode a legacy address given type and hash
27
+ * For now, this is a stub method that supports only BTC p2pkh and p2sh
28
+ */
29
+ export declare const encodeLegacyAddress: (hash: Uint8Array, type: 'p2pkh' | 'p2sh', network?: NetworkType) => string;
30
+ export {};
31
+ //# sourceMappingURL=legacyaddr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacyaddr.d.ts","sourceRoot":"","sources":["../../src/address/legacyaddr.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC;;GAEG;AAEH,eAAO,MAAM,iBAAiB,SAAU,UAAU,KAAG,MAMpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAS,MAAM,KAAG,UAiB/C,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;AAKD,UAAU,mBAAmB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CAChB;AACD,UAAU,oBAAoB;IAC1B,MAAM,EAAE;QACJ,OAAO,EAAE,mBAAmB,CAAC;QAC7B,OAAO,EAAE,mBAAmB,CAAC;KAChC,CAAC;CACL;AACD,eAAO,MAAM,oBAAoB,EAAE,oBAKlC,CAAC;AAGF,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,oBA4CrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,SACtB,UAAU,QACV,OAAO,GAAG,MAAM,YACb,WAAW,WAOvB,CAAC"}
@@ -0,0 +1,101 @@
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.encodeLegacyAddress = exports.decodeLegacyAddress = exports.LEGACY_VERSION_BYTES = exports.decodeBase58Check = exports.encodeBase58Check = void 0;
7
+ const hash_1 = require("../hash");
8
+ const b58_ts_1 = require("b58-ts");
9
+ const hex_1 = require("../io/hex");
10
+ /**
11
+ * Base 58 Check
12
+ */
13
+ const encodeBase58Check = (data) => {
14
+ const checksum = (0, hash_1.sha256d)(data);
15
+ const dataWithChecksum = new Uint8Array(data.length + 4);
16
+ dataWithChecksum.set(data, 0);
17
+ dataWithChecksum.set(checksum.subarray(0, 4), data.length);
18
+ return (0, b58_ts_1.encodeBase58)(dataWithChecksum);
19
+ };
20
+ exports.encodeBase58Check = encodeBase58Check;
21
+ const decodeBase58Check = (str) => {
22
+ const dataWithChecksum = (0, b58_ts_1.decodeBase58)(str);
23
+ const payload = dataWithChecksum.slice(0, -4);
24
+ const checksum = dataWithChecksum.slice(-4);
25
+ const expectedChecksum = (0, hash_1.sha256d)(payload);
26
+ // Ensure the two checksums are equal
27
+ if ((checksum[0] ^ expectedChecksum[0]) |
28
+ (checksum[1] ^ expectedChecksum[1]) |
29
+ (checksum[2] ^ expectedChecksum[2]) |
30
+ (checksum[3] ^ expectedChecksum[3])) {
31
+ throw new Error('Invalid checksum');
32
+ }
33
+ return payload;
34
+ };
35
+ exports.decodeBase58Check = decodeBase58Check;
36
+ // Length of a valid base58check encoding payload: 1 byte for
37
+ // the version byte plus 20 bytes for a RIPEMD - 160 hash.
38
+ const BASE_58_CHECK_PAYLOAD_LENGTH = 21;
39
+ exports.LEGACY_VERSION_BYTES = {
40
+ legacy: {
41
+ mainnet: { p2pkh: 0, p2sh: 5 },
42
+ testnet: { p2pkh: 111, p2sh: 196 },
43
+ },
44
+ };
45
+ // Modeled from https://github.com/ealmansi/bchaddrjs/blob/master/src/bchaddr.js#L193
46
+ const decodeLegacyAddress = (address) => {
47
+ try {
48
+ const payload = (0, exports.decodeBase58Check)(address);
49
+ if (payload.length !== BASE_58_CHECK_PAYLOAD_LENGTH) {
50
+ throw new Error(`Invalid legacy address: payload length must be ${BASE_58_CHECK_PAYLOAD_LENGTH}`);
51
+ }
52
+ const versionByte = payload[0];
53
+ const hash = (0, hex_1.toHex)(new Uint8Array(payload.slice(1)));
54
+ switch (versionByte) {
55
+ case exports.LEGACY_VERSION_BYTES.legacy.mainnet.p2pkh:
56
+ return {
57
+ hash,
58
+ type: 'p2pkh',
59
+ network: 'mainnet',
60
+ };
61
+ case exports.LEGACY_VERSION_BYTES.legacy.mainnet.p2sh:
62
+ return {
63
+ hash,
64
+ type: 'p2sh',
65
+ network: 'mainnet',
66
+ };
67
+ case exports.LEGACY_VERSION_BYTES.legacy.testnet.p2pkh:
68
+ return {
69
+ hash,
70
+ type: 'p2pkh',
71
+ network: 'testnet',
72
+ };
73
+ case exports.LEGACY_VERSION_BYTES.legacy.testnet.p2sh:
74
+ return {
75
+ hash,
76
+ type: 'p2sh',
77
+ network: 'testnet',
78
+ };
79
+ default: {
80
+ throw new Error(`Invalid legacy address: unrecognized version byte "${versionByte}"`);
81
+ }
82
+ }
83
+ }
84
+ catch {
85
+ throw new Error(`Invalid legacy address`);
86
+ }
87
+ };
88
+ exports.decodeLegacyAddress = decodeLegacyAddress;
89
+ /**
90
+ * Encode a legacy address given type and hash
91
+ * For now, this is a stub method that supports only BTC p2pkh and p2sh
92
+ */
93
+ const encodeLegacyAddress = (hash, type, network = 'mainnet') => {
94
+ const versionByte = exports.LEGACY_VERSION_BYTES.legacy[network][type];
95
+ const combined = new Uint8Array(1 + hash.length);
96
+ combined[0] = versionByte;
97
+ combined.set(hash, 1);
98
+ return (0, exports.encodeBase58Check)(combined);
99
+ };
100
+ exports.encodeLegacyAddress = encodeLegacyAddress;
101
+ //# sourceMappingURL=legacyaddr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacyaddr.js","sourceRoot":"","sources":["../../src/address/legacyaddr.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAEtE,kCAAkC;AAClC,mCAAoD;AAEpD,mCAAkC;AAElC;;GAEG;AAEI,MAAM,iBAAiB,GAAG,CAAC,IAAgB,EAAU,EAAE;IAC1D,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,gBAAgB,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzD,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3D,OAAO,IAAA,qBAAY,EAAC,gBAAgB,CAAC,CAAC;AAC1C,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B;AAEK,MAAM,iBAAiB,GA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,EAClC,EAAE;IACA,MAAM,WAAW,GAAG,4BAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IAC1B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACtB,OAAO,IAAA,yBAAiB,EAAC,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './hash.js';
4
4
  export * from './op.js';
5
5
  export * from './opcode.js';
6
6
  export * from './script.js';
7
+ export * from './address/address';
7
8
  export * from './sigHashType.js';
8
9
  export * from './tx.js';
9
10
  export * from './txBuilder.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __exportStar(require("./hash.js"), exports);
23
23
  __exportStar(require("./op.js"), exports);
24
24
  __exportStar(require("./opcode.js"), exports);
25
25
  __exportStar(require("./script.js"), exports);
26
+ __exportStar(require("./address/address"), exports);
26
27
  __exportStar(require("./sigHashType.js"), exports);
27
28
  __exportStar(require("./tx.js"), exports);
28
29
  __exportStar(require("./txBuilder.js"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;;;;;;;;;;;;;;AAEtE,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,0CAAwB;AACxB,8CAA4B;AAC5B,8CAA4B;AAC5B,mDAAiC;AACjC,0CAAwB;AACxB,iDAA+B;AAC/B,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,iDAA+B;AAC/B,sDAAoC;AACpC,uDAAqC;AACrC,iDAA+B;AAC/B,oDAAkC;AAClC,kDAAgC;AAChC,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;;;;;;;;;;;;;;AAEtE,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,0CAAwB;AACxB,8CAA4B;AAC5B,8CAA4B;AAC5B,oDAAkC;AAClC,mDAAiC;AACjC,0CAAwB;AACxB,iDAA+B;AAC/B,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,iDAA+B;AAC/B,sDAAoC;AACpC,uDAAqC;AACrC,iDAA+B;AAC/B,oDAAkC;AAClC,kDAAgC;AAChC,iDAA+B"}
@@ -1 +1 @@
1
- {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../src/script.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,OAAO,EAAE,EAAE,EAAgC,MAAM,SAAS,CAAC;AAS3D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,gDAAgD;AAChD,qBAAa,MAAM;IACR,QAAQ,EAAE,UAAU,CAAC;IAE5B,2DAA2D;gBACxC,QAAQ,CAAC,EAAE,UAAU;IAIxC;;;QAGI;IACG,aAAa,CAAC,MAAM,EAAE,MAAM;WAKrB,YAAY,CAAC,KAAK,EAAE,KAAK;IAKvC,+CAA+C;WACjC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM;WAc1B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAkClD,0CAA0C;IACnC,GAAG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GAAG,MAAM;IAe9C;;;QAGI;IACG,MAAM,IAAI,OAAO;IAWxB,oDAAoD;WACtC,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM;IASlD,yDAAyD;WAC3C,KAAK,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM;IAa5C,oDAAoD;WACtC,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM;CAGpE;AAED,yCAAyC;AACzC,qBAAa,YAAY;IACrB,KAAK,EAAE,KAAK,CAAC;gBAEM,KAAK,EAAE,KAAK;IAI/B;;;OAGG;IACI,IAAI,IAAI,EAAE,GAAG,SAAS;CAMhC"}
package/dist/script.js CHANGED
@@ -2,38 +2,16 @@
2
2
  // Copyright (c) 2024 The Bitcoin developers
3
3
  // Distributed under the MIT software license, see the accompanying
4
4
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
6
  exports.ScriptOpIter = exports.Script = void 0;
30
7
  const varsize_js_1 = require("./io/varsize.js");
31
8
  const writerlength_js_1 = require("./io/writerlength.js");
32
9
  const writerbytes_js_1 = require("./io/writerbytes.js");
10
+ const hex_js_1 = require("./io/hex.js");
33
11
  const op_js_1 = require("./op.js");
34
12
  const opcode_js_1 = require("./opcode.js");
35
13
  const bytes_js_1 = require("./io/bytes.js");
36
- const cashaddr = __importStar(require("ecashaddrjs"));
14
+ const address_1 = require("./address/address");
37
15
  /** A Bitcoin Script locking/unlocking a UTXO */
38
16
  class Script {
39
17
  /** Create a new Script with the given bytecode or empty */
@@ -67,35 +45,21 @@ class Script {
67
45
  return new Script(bytecodeWriter.data);
68
46
  }
69
47
  static fromAddress(address) {
70
- // Note that hash is always returned as a string when decode is called with 'true'
71
- let decodedAddress;
72
- try {
73
- decodedAddress = cashaddr.decode(address, false);
74
- }
75
- catch (err) {
76
- throw new Error(`Error decoding address "${address}": ${err}`);
77
- }
78
- if (typeof decodedAddress.hash !== 'string') {
79
- // cashaddr.decode returns hash as string | uint8array
80
- // When called with chronikReady=false param, hash is always returned as a uint8array
81
- // typescript does not know this though so we need this gate to prevent an error
82
- switch (decodedAddress.type) {
83
- case 'P2PKH': {
84
- return Script.p2pkh(decodedAddress.hash);
85
- }
86
- case 'P2SH': {
87
- return Script.p2sh(decodedAddress.hash);
88
- }
89
- default: {
90
- // Note we should never get here, as ecashaddrjs decode method
91
- // only supports p2pkh and p2sh
92
- throw new Error(`Unsupported address type: ${decodedAddress.type}`);
93
- }
48
+ // make Address from address
49
+ const thisAddress = address_1.Address.fromCashAddress(address);
50
+ switch (thisAddress.type) {
51
+ case 'p2pkh': {
52
+ return Script.p2pkh((0, hex_js_1.fromHex)(thisAddress.hash));
53
+ }
54
+ case 'p2sh': {
55
+ return Script.p2sh((0, hex_js_1.fromHex)(thisAddress.hash));
56
+ }
57
+ default: {
58
+ // Note we should never get here, as Address constructor
59
+ // only supports p2pkh and p2sh
60
+ throw new Error(`Unsupported address type: ${thisAddress.type}`);
94
61
  }
95
62
  }
96
- // Note we should never get here, as ecashaddrjs decode method
97
- // always returns hash as a Uint8Array when called with (<addr>, false)
98
- throw new Error(`Error decoding address "${address}"`);
99
63
  }
100
64
  /** Iterate over the Ops of this Script */
101
65
  ops() {
@@ -1 +1 @@
1
- {"version":3,"file":"script.js","sourceRoot":"","sources":["../src/script.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtE,gDAA4D;AAE5D,0DAAoD;AACpD,wDAAkD;AAElD,mCAA2D;AAC3D,2CAOqB;AACrB,4CAAsC;AACtC,sDAAwC;AAExC,gDAAgD;AAChD,MAAa,MAAM;IAGf,2DAA2D;IAC3D,YAAmB,QAAqB;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,IAAI,UAAU,EAAE,CAAC;IACjD,CAAC;IAED;;;QAGI;IACG,aAAa,CAAC,MAAc;QAC/B,IAAA,yBAAY,EAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,KAAY;QACnC,MAAM,IAAI,GAAG,IAAA,wBAAW,EAAC,KAAK,CAAC,CAAC;QAChC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,+CAA+C;IACxC,MAAM,CAAC,OAAO,CAAC,GAAS;QAC3B,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;YACnB,MAAM,YAAY,GAAG,IAAI,8BAAY,EAAE,CAAC;YACxC,IAAA,eAAO,EAAC,EAAE,EAAE,YAAY,CAAC,CAAC;YAC1B,UAAU,IAAI,YAAY,CAAC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AED,oDAAoD;IAC7C,MAAM,CAAC,UAAU,CAAC,EAAc,EAAE,GAAe;QACpD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAA,mBAAW,EAAC,GAAG,CAAC,EAAE,IAAA,mBAAW,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;CACJ;AAjJD,wBAiJC;AAED,yCAAyC;AACzC,MAAa,YAAY;IAGrB,YAAmB,KAAY;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED;;;OAGG;IACI,IAAI;QACP,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAC3C,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,IAAA,cAAM,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACJ;AAjBD,oCAiBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecash-lib",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Library for eCash transaction building",
5
5
  "main": "./dist/indexNodeJs.js",
6
6
  "browser": "./dist/indexBrowser.js",
@@ -33,11 +33,12 @@
33
33
  "@types/mocha": "^10.0.6",
34
34
  "@types/node": "^20.12.7",
35
35
  "chai": "^5.1.0",
36
- "chronik-client": "^2.0.0",
36
+ "chronik-client": "^2.1.0",
37
37
  "eslint-plugin-header": "^3.1.1",
38
38
  "mocha": "^10.4.0",
39
39
  "mocha-junit-reporter": "^2.2.1",
40
40
  "nyc": "^15.1.0",
41
+ "random-js": "^2.1.0",
41
42
  "source-map-support": "^0.5.21",
42
43
  "ts-node": "^10.9.2",
43
44
  "tsx": "^4.7.2",
@@ -45,6 +46,7 @@
45
46
  "typescript-eslint": "^7.6.0"
46
47
  },
47
48
  "dependencies": {
48
- "ecashaddrjs": "^1.6.2"
49
+ "b58-ts": "^0.1.0",
50
+ "ecashaddrjs": "^2.0.0"
49
51
  }
50
52
  }