ecash-lib 1.2.2-rc9 → 1.4.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 (125) hide show
  1. package/README.md +2 -1
  2. package/dist/ecc.d.ts +12 -0
  3. package/dist/ecc.d.ts.map +1 -1
  4. package/dist/ecc.js +9 -47
  5. package/dist/ecc.js.map +1 -1
  6. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  7. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +18 -4
  8. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  9. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +18 -4
  10. package/dist/ffi/ecash_lib_wasm_browser.d.ts +95 -4
  11. package/dist/ffi/ecash_lib_wasm_browser.js +245 -14
  12. package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +77 -0
  13. package/dist/ffi/ecash_lib_wasm_nodejs.js +247 -14
  14. package/dist/hash.d.ts +21 -1
  15. package/dist/hash.d.ts.map +1 -1
  16. package/dist/hash.js +16 -10
  17. package/dist/hash.js.map +1 -1
  18. package/dist/hdwallet.d.ts +33 -0
  19. package/dist/hdwallet.d.ts.map +1 -0
  20. package/dist/hdwallet.js +148 -0
  21. package/dist/hdwallet.js.map +1 -0
  22. package/dist/hmac.d.ts +13 -0
  23. package/dist/hmac.d.ts.map +1 -0
  24. package/dist/hmac.js +63 -0
  25. package/dist/hmac.js.map +1 -0
  26. package/dist/index.d.ts +3 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +3 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/initBrowser.d.ts.map +1 -1
  31. package/dist/initBrowser.js +3 -0
  32. package/dist/initBrowser.js.map +1 -1
  33. package/dist/initNodeJs.d.ts.map +1 -1
  34. package/dist/initNodeJs.js +3 -0
  35. package/dist/initNodeJs.js.map +1 -1
  36. package/dist/io/bytes.d.ts +5 -3
  37. package/dist/io/bytes.d.ts.map +1 -1
  38. package/dist/io/bytes.js +15 -7
  39. package/dist/io/bytes.js.map +1 -1
  40. package/dist/io/writer.d.ts +4 -3
  41. package/dist/io/writer.d.ts.map +1 -1
  42. package/dist/io/writerbytes.d.ts +4 -3
  43. package/dist/io/writerbytes.d.ts.map +1 -1
  44. package/dist/io/writerbytes.js +7 -6
  45. package/dist/io/writerbytes.js.map +1 -1
  46. package/dist/io/writerlength.d.ts +4 -3
  47. package/dist/io/writerlength.d.ts.map +1 -1
  48. package/dist/io/writerlength.js +3 -3
  49. package/dist/io/writerlength.js.map +1 -1
  50. package/dist/mnemonic.d.ts +14 -0
  51. package/dist/mnemonic.d.ts.map +1 -0
  52. package/dist/mnemonic.js +123 -0
  53. package/dist/mnemonic.js.map +1 -0
  54. package/dist/pbkdf2.d.ts +11 -0
  55. package/dist/pbkdf2.d.ts.map +1 -0
  56. package/dist/pbkdf2.js +36 -0
  57. package/dist/pbkdf2.js.map +1 -0
  58. package/dist/script.d.ts +4 -0
  59. package/dist/script.d.ts.map +1 -1
  60. package/dist/script.js +6 -0
  61. package/dist/script.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/address/address.ts +346 -0
  64. package/src/address/legacyaddr.ts +129 -0
  65. package/src/consts.ts +8 -0
  66. package/src/ecc.ts +61 -0
  67. package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  68. package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +32 -0
  69. package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  70. package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +32 -0
  71. package/src/ffi/ecash_lib_wasm_browser.d.ts +183 -0
  72. package/src/ffi/ecash_lib_wasm_browser.js +571 -0
  73. package/src/ffi/ecash_lib_wasm_nodejs.d.ts +127 -0
  74. package/src/ffi/ecash_lib_wasm_nodejs.js +498 -0
  75. package/src/hash.ts +46 -0
  76. package/src/hdwallet.ts +181 -0
  77. package/src/hmac.ts +74 -0
  78. package/src/index.ts +29 -0
  79. package/src/indexBrowser.ts +6 -0
  80. package/src/indexNodeJs.ts +6 -0
  81. package/src/initBrowser.ts +21 -0
  82. package/src/initNodeJs.ts +20 -0
  83. package/src/io/bytes.ts +80 -0
  84. package/src/io/hex.ts +69 -0
  85. package/src/io/int.ts +6 -0
  86. package/src/io/str.ts +16 -0
  87. package/src/io/varsize.ts +49 -0
  88. package/src/io/writer.ts +20 -0
  89. package/src/io/writerbytes.ts +87 -0
  90. package/src/io/writerlength.ts +44 -0
  91. package/src/mnemonic.ts +153 -0
  92. package/src/op.ts +162 -0
  93. package/src/opcode.ts +154 -0
  94. package/src/pbkdf2.ts +52 -0
  95. package/src/script.ts +195 -0
  96. package/src/sigHashType.ts +190 -0
  97. package/src/test/testRunner.ts +209 -0
  98. package/src/token/alp.ts +146 -0
  99. package/src/token/common.ts +32 -0
  100. package/src/token/empp.ts +29 -0
  101. package/src/token/slp.ts +212 -0
  102. package/src/tx.ts +180 -0
  103. package/src/txBuilder.ts +262 -0
  104. package/src/unsignedTx.ts +359 -0
  105. package/tsconfig.json +2 -1
  106. package/wordlists/english.json +2053 -0
  107. package/.nyc_output/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
  108. package/.nyc_output/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
  109. package/.nyc_output/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
  110. package/.nyc_output/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
  111. package/.nyc_output/processinfo/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
  112. package/.nyc_output/processinfo/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
  113. package/.nyc_output/processinfo/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
  114. package/.nyc_output/processinfo/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
  115. package/.nyc_output/processinfo/index.json +0 -1
  116. package/dist/address/cashaddr.d.ts +0 -78
  117. package/dist/address/cashaddr.d.ts.map +0 -1
  118. package/dist/address/cashaddr.js +0 -543
  119. package/dist/address/cashaddr.js.map +0 -1
  120. package/dist/cashaddr/cashaddr.d.ts +0 -23
  121. package/dist/cashaddr/cashaddr.d.ts.map +0 -1
  122. package/dist/cashaddr/cashaddr.js +0 -325
  123. package/dist/cashaddr/cashaddr.js.map +0 -1
  124. package/global.d.ts +0 -64
  125. package/test.log +0 -82
@@ -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;IAqBlD,0CAA0C;IACnC,GAAG,IAAI,YAAY;IAI1B,wCAAwC;IACjC,IAAI,IAAI,MAAM;IAIrB;;;;;;;;;;;;;;;;;;OAkBG;IACI,aAAa,CAAC,QAAQ,EAAE,MAAM,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,GA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AK,CAAC;gBAEM,KAAK,EAAE,KAAK;IAI/B;;;OAGG;IACI,IAAI,IAAI,EAAE,GAAG,SAAS;CAMhC"}
package/dist/script.js CHANGED
@@ -114,6 +114,12 @@ class Script {
114
114
  this.bytecode[1] == 20 &&
115
115
  this.bytecode[22] == opcode_js_1.OP_EQUAL);
116
116
  }
117
+ /**
118
+ * Return hex string of this Script's bytecode
119
+ */
120
+ toHex() {
121
+ return (0, hex_js_1.toHex)(this.bytecode);
122
+ }
117
123
  /** Build a P2SH script for the given script hash */
118
124
  static p2sh(scriptHash) {
119
125
  if (scriptHash.length !== 20) {
@@ -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;AAClD,wCAAsC;AACtC,mCAA2D;AAC3D,2CAOqB;AACrB,4CAAsC;AACtC,+CAA4C;AAE5C,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,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,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;AAxJD,wBAwJC;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.2.2-rc9",
3
+ "version": "1.4.0",
4
4
  "description": "Library for eCash transaction building",
5
5
  "main": "./dist/indexNodeJs.js",
6
6
  "browser": "./dist/indexBrowser.js",
@@ -0,0 +1,346 @@
1
+ // Copyright (c) 2024 The Bitcoin developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+ import { toHex, fromHex } from '../io/hex';
5
+ import {
6
+ decodeCashAddress,
7
+ getOutputScriptFromTypeAndHash,
8
+ getTypeAndHashFromOutputScript,
9
+ encodeCashAddress,
10
+ isValidCashAddress,
11
+ } from 'ecashaddrjs';
12
+ import {
13
+ decodeLegacyAddress,
14
+ encodeBase58Check,
15
+ LEGACY_VERSION_BYTES,
16
+ } from './legacyaddr';
17
+ import { Script } from '../script';
18
+
19
+ export type AddressType = 'p2pkh' | 'p2sh';
20
+ export type AddressEncoding = 'cashaddr' | 'legacy';
21
+
22
+ export const ECASH_PREFIXES_TESTNET = ['ectest', 'ecregtest'];
23
+
24
+ /**
25
+ * Converts an ecash address in cashaddr format to legacy format
26
+ * Throws if user attempts to convert a legacy address to a legacy address
27
+ * Separated as its own function here for
28
+ *
29
+ * 1 - simpler unit testing
30
+ * 2 - exported for users looking to convert string cashaddr to string legacy addr
31
+ * without using the Address class
32
+ */
33
+ export const toLegacyAddress = (cashaddress: string): string => {
34
+ try {
35
+ // No-op if user is trying to convert legacy to legacy
36
+ decodeLegacyAddress(cashaddress);
37
+ return cashaddress;
38
+ } catch {
39
+ // Do nothing with this error since we expect it every time for the function's intended use case
40
+ // Proceed to convert to legacy
41
+ }
42
+ const { prefix, type, hash } = decodeCashAddress(cashaddress);
43
+
44
+ const isTestnet = ECASH_PREFIXES_TESTNET.includes(prefix);
45
+
46
+ // Get correct version byte for legacy format
47
+ let versionByte: number;
48
+ switch (type) {
49
+ case 'p2pkh':
50
+ versionByte = isTestnet
51
+ ? LEGACY_VERSION_BYTES.legacy.testnet.p2pkh
52
+ : LEGACY_VERSION_BYTES.legacy.mainnet.p2pkh;
53
+ break;
54
+ case 'p2sh':
55
+ versionByte = isTestnet
56
+ ? LEGACY_VERSION_BYTES.legacy.testnet.p2sh
57
+ : LEGACY_VERSION_BYTES.legacy.mainnet.p2sh;
58
+ break;
59
+ default:
60
+ throw new Error('Unsupported address type: ' + type);
61
+ }
62
+
63
+ // Convert hash to Uint8Array
64
+ const hashArray = fromHex(hash);
65
+
66
+ // Create a new Uint8Array to hold the data
67
+ const uint8Array = new Uint8Array(1 + hashArray.length);
68
+
69
+ // Set the version byte
70
+ uint8Array[0] = versionByte;
71
+
72
+ // Set the hash
73
+ uint8Array.set(hashArray, 1);
74
+
75
+ // Encode to base58check
76
+ return encodeBase58Check(uint8Array);
77
+ };
78
+
79
+ interface AddressInterface {
80
+ /**
81
+ * hash
82
+ * The hash this address encodes as a hex string.
83
+ * It's part of the Script this address represents.
84
+ */
85
+ hash: string;
86
+ /**
87
+ * p2pkh or p2sh
88
+ * The type of address
89
+ * Address supports p2pkh or p2sh address types
90
+ */
91
+ type: AddressType;
92
+ /**
93
+ * Defined for a cashaddr address, i.e. one with encoding === 'cashaddr'
94
+ * This is distinct from the version byte. Common prefixes on ecash include
95
+ * 'ecash', 'etoken', 'ectest', and 'ecregest'. But a prefix could be anything
96
+ * so long as the address checksum matches.
97
+ */
98
+ prefix?: string;
99
+ /**
100
+ * encoded address as a string
101
+ * cashaddr or legacy
102
+ * type available in 'encoding' field
103
+ */
104
+ address: string;
105
+ /**
106
+ * How this address is encoded
107
+ * cashaddr or legacy
108
+ * If cashaddr, 'prefix' is defined and a string
109
+ */
110
+ encoding: AddressEncoding;
111
+ }
112
+
113
+ /**
114
+ * Constructor params for private constructor method of the Address class
115
+ */
116
+ interface AddressConstructorParams {
117
+ hash: string;
118
+ type: AddressType;
119
+ prefix?: string;
120
+ address: string;
121
+ encoding: AddressEncoding;
122
+ }
123
+
124
+ export const DEFAULT_PREFIX = 'ecash';
125
+
126
+ /**
127
+ * Address
128
+ * Stores properties of supported crypto addresses
129
+ * in standard typed structure. Provides methods for
130
+ * easy access of address data in dev-friendly formats.
131
+ * Provides methods for instantiating by type, encoding,
132
+ * script, prefix, and address string of arbitrary encoding.
133
+ *
134
+ * Simplifies conversion between cashaddr prefixes and
135
+ * address encoding types.
136
+ *
137
+ * Address is an ecash-first class. Legacy BTC format
138
+ * is supported to simplify conversion to and from
139
+ * ecash addresses.
140
+ *
141
+ * Address may be extended to support other crypto
142
+ * address formats.
143
+ */
144
+ export class Address implements AddressInterface {
145
+ hash: string;
146
+ type: AddressType;
147
+ prefix?: string;
148
+ address: string;
149
+ encoding: AddressEncoding;
150
+
151
+ private constructor(params: AddressConstructorParams) {
152
+ const { hash, type, address, encoding } = params;
153
+ this.hash = hash;
154
+ this.type = type;
155
+ this.address = address;
156
+ this.encoding = encoding;
157
+ if (typeof params.prefix !== 'undefined') {
158
+ this.prefix = params.prefix;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Create a new p2pkh Address from hash
164
+ * cashaddr encoding, ecash: prefix
165
+ */
166
+ static p2pkh = (hash: string | Uint8Array) =>
167
+ new Address({
168
+ type: 'p2pkh',
169
+ hash: hash instanceof Uint8Array ? toHex(hash) : hash,
170
+ prefix: DEFAULT_PREFIX,
171
+ address: encodeCashAddress(DEFAULT_PREFIX, 'p2pkh', hash),
172
+ encoding: 'cashaddr',
173
+ });
174
+
175
+ /**
176
+ * Create a new p2sh Address from hash
177
+ * cashaddr encoding
178
+ * ecash: prefix
179
+ */
180
+ static p2sh = (hash: string | Uint8Array) =>
181
+ new Address({
182
+ type: 'p2sh',
183
+ hash: hash instanceof Uint8Array ? toHex(hash) : hash,
184
+ prefix: DEFAULT_PREFIX,
185
+ address: encodeCashAddress(DEFAULT_PREFIX, 'p2sh', hash),
186
+ encoding: 'cashaddr',
187
+ });
188
+
189
+ /**
190
+ * Create a new Address from a given address string
191
+ * address must be valid legacy or cashaddr address
192
+ */
193
+ static parse = (address: string) => {
194
+ if (isValidCashAddress(address)) {
195
+ const { type, hash, prefix } = decodeCashAddress(address);
196
+ return new Address({
197
+ type,
198
+ hash,
199
+ prefix,
200
+ encoding: 'cashaddr',
201
+ address,
202
+ });
203
+ }
204
+ try {
205
+ const { type, hash } = decodeLegacyAddress(address);
206
+ return new Address({
207
+ type,
208
+ hash,
209
+ encoding: 'legacy',
210
+ address,
211
+ });
212
+ } catch {
213
+ throw new Error('Invalid cashaddr or legacy address');
214
+ }
215
+ };
216
+
217
+ /**
218
+ * Create a new Address from a cashaddr
219
+ * prefix, type, and hash from creating cashaddr
220
+ */
221
+ static fromCashAddress = (address: string) => {
222
+ const { type, hash, prefix } = decodeCashAddress(address);
223
+ return new Address({
224
+ type,
225
+ hash,
226
+ address,
227
+ encoding: 'cashaddr',
228
+ prefix,
229
+ });
230
+ };
231
+
232
+ /**
233
+ * Create a new Address from legacy address
234
+ * No prefix for Address created from legacy address
235
+ * type and hash from legacy address
236
+ */
237
+ static fromLegacyAddress = (legacy: string) => {
238
+ // Determine addr params from legacy address
239
+ const { type, hash } = decodeLegacyAddress(legacy);
240
+ return new Address({
241
+ type,
242
+ hash,
243
+ address: legacy,
244
+ encoding: 'legacy',
245
+ });
246
+ };
247
+
248
+ /**
249
+ * Create a new Address from an outputScript as Script
250
+ * type and hash from outputScript
251
+ * cashaddr encoding
252
+ * ecash: prefix
253
+ */
254
+ static fromScript = (script: Script) => {
255
+ const scriptHex = toHex(script.bytecode);
256
+ return Address.fromScriptHex(scriptHex);
257
+ };
258
+
259
+ /**
260
+ * Create a new Address from an outputScript as hex string
261
+ * type and hash from outputScript
262
+ * cashaddr encoding
263
+ * ecash: prefix
264
+ */
265
+ static fromScriptHex = (scriptHex: string) => {
266
+ const { type, hash } = getTypeAndHashFromOutputScript(scriptHex);
267
+
268
+ // Default cashaddr encoding with default prefix
269
+ const address = encodeCashAddress(DEFAULT_PREFIX, type, hash);
270
+ const prefix = DEFAULT_PREFIX;
271
+
272
+ return new Address({
273
+ type,
274
+ hash,
275
+ prefix,
276
+ address,
277
+ encoding: 'cashaddr',
278
+ });
279
+ };
280
+
281
+ toString = () => {
282
+ return this.address;
283
+ };
284
+
285
+ legacy = () =>
286
+ new Address({
287
+ type: this.type,
288
+ hash: this.hash,
289
+ address: toLegacyAddress(this.address),
290
+ encoding: 'legacy',
291
+ });
292
+
293
+ /**
294
+ * Create an Address with cashaddr encoding
295
+ * from an existing Address
296
+ */
297
+ cash = () =>
298
+ new Address({
299
+ type: this.type,
300
+ hash: this.hash,
301
+ address: encodeCashAddress(
302
+ typeof this.prefix !== 'undefined'
303
+ ? this.prefix
304
+ : DEFAULT_PREFIX,
305
+ this.type,
306
+ this.hash,
307
+ ),
308
+ encoding: 'cashaddr',
309
+ prefix:
310
+ typeof this.prefix !== 'undefined'
311
+ ? this.prefix
312
+ : DEFAULT_PREFIX,
313
+ });
314
+
315
+ /**
316
+ * Create address with specified prefix
317
+ * from an existing cashaddr-encoding Address
318
+ */
319
+ withPrefix = (prefix: string) => {
320
+ if (this.encoding === 'legacy') {
321
+ // Take no action for legacy address types
322
+ throw new Error('withPrefix does not support legacy address types');
323
+ }
324
+ if (this.prefix === prefix) {
325
+ // Take no action if prefix is not changing
326
+ throw new Error(`prefix is already "${this.prefix}"`);
327
+ }
328
+ return new Address({
329
+ type: this.type,
330
+ hash: this.hash,
331
+ prefix,
332
+ address: encodeCashAddress(prefix, this.type, this.hash),
333
+ encoding: 'cashaddr',
334
+ });
335
+ };
336
+
337
+ toScript = (): Script => {
338
+ return new Script(
339
+ fromHex(getOutputScriptFromTypeAndHash(this.type, this.hash)),
340
+ );
341
+ };
342
+
343
+ toScriptHex = (): string => {
344
+ return getOutputScriptFromTypeAndHash(this.type, this.hash);
345
+ };
346
+ }
@@ -0,0 +1,129 @@
1
+ // Copyright (c) 2024 The Bitcoin developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ import { sha256d } from '../hash';
6
+ import { encodeBase58, decodeBase58 } from 'b58-ts';
7
+ import { AddressType } from './address';
8
+ import { toHex } from '../io/hex';
9
+
10
+ /**
11
+ * Base 58 Check
12
+ */
13
+
14
+ export const encodeBase58Check = (data: Uint8Array): string => {
15
+ const checksum = sha256d(data);
16
+ const dataWithChecksum = new Uint8Array(data.length + 4);
17
+ dataWithChecksum.set(data, 0);
18
+ dataWithChecksum.set(checksum.subarray(0, 4), data.length);
19
+ return encodeBase58(dataWithChecksum);
20
+ };
21
+
22
+ export const decodeBase58Check = (str: string): Uint8Array => {
23
+ const dataWithChecksum = decodeBase58(str);
24
+ const payload = dataWithChecksum.slice(0, -4);
25
+ const checksum = dataWithChecksum.slice(-4);
26
+ const expectedChecksum = sha256d(payload);
27
+
28
+ // Ensure the two checksums are equal
29
+ if (
30
+ (checksum[0] ^ expectedChecksum[0]) |
31
+ (checksum[1] ^ expectedChecksum[1]) |
32
+ (checksum[2] ^ expectedChecksum[2]) |
33
+ (checksum[3] ^ expectedChecksum[3])
34
+ ) {
35
+ throw new Error('Invalid checksum');
36
+ }
37
+
38
+ return payload;
39
+ };
40
+
41
+ type NetworkType = 'mainnet' | 'testnet';
42
+ export interface DecodedLegacyAddress {
43
+ type: AddressType;
44
+ hash: string;
45
+ network: NetworkType;
46
+ }
47
+ // Length of a valid base58check encoding payload: 1 byte for
48
+ // the version byte plus 20 bytes for a RIPEMD - 160 hash.
49
+ const BASE_58_CHECK_PAYLOAD_LENGTH = 21;
50
+
51
+ interface NetworkVersionBytes {
52
+ p2pkh: number;
53
+ p2sh: number;
54
+ }
55
+ interface VersionByteReference {
56
+ legacy: {
57
+ mainnet: NetworkVersionBytes;
58
+ testnet: NetworkVersionBytes;
59
+ };
60
+ }
61
+ export const LEGACY_VERSION_BYTES: VersionByteReference = {
62
+ legacy: {
63
+ mainnet: { p2pkh: 0, p2sh: 5 },
64
+ testnet: { p2pkh: 111, p2sh: 196 },
65
+ },
66
+ };
67
+
68
+ // Modeled from https://github.com/ealmansi/bchaddrjs/blob/master/src/bchaddr.js#L193
69
+ export const decodeLegacyAddress = (address: string): DecodedLegacyAddress => {
70
+ try {
71
+ const payload = decodeBase58Check(address);
72
+ if (payload.length !== BASE_58_CHECK_PAYLOAD_LENGTH) {
73
+ throw new Error(
74
+ `Invalid legacy address: payload length must be ${BASE_58_CHECK_PAYLOAD_LENGTH}`,
75
+ );
76
+ }
77
+ const versionByte = payload[0];
78
+ const hash = toHex(new Uint8Array(payload.slice(1)));
79
+ switch (versionByte) {
80
+ case LEGACY_VERSION_BYTES.legacy.mainnet.p2pkh:
81
+ return {
82
+ hash,
83
+ type: 'p2pkh',
84
+ network: 'mainnet',
85
+ };
86
+ case LEGACY_VERSION_BYTES.legacy.mainnet.p2sh:
87
+ return {
88
+ hash,
89
+ type: 'p2sh',
90
+ network: 'mainnet',
91
+ };
92
+ case LEGACY_VERSION_BYTES.legacy.testnet.p2pkh:
93
+ return {
94
+ hash,
95
+ type: 'p2pkh',
96
+ network: 'testnet',
97
+ };
98
+ case LEGACY_VERSION_BYTES.legacy.testnet.p2sh:
99
+ return {
100
+ hash,
101
+ type: 'p2sh',
102
+ network: 'testnet',
103
+ };
104
+ default: {
105
+ throw new Error(
106
+ `Invalid legacy address: unrecognized version byte "${versionByte}"`,
107
+ );
108
+ }
109
+ }
110
+ } catch {
111
+ throw new Error(`Invalid legacy address`);
112
+ }
113
+ };
114
+
115
+ /**
116
+ * Encode a legacy address given type and hash
117
+ * For now, this is a stub method that supports only BTC p2pkh and p2sh
118
+ */
119
+ export const encodeLegacyAddress = (
120
+ hash: Uint8Array,
121
+ type: 'p2pkh' | 'p2sh',
122
+ network: NetworkType = 'mainnet',
123
+ ) => {
124
+ const versionByte = LEGACY_VERSION_BYTES.legacy[network][type];
125
+ const combined = new Uint8Array(1 + hash.length);
126
+ combined[0] = versionByte;
127
+ combined.set(hash, 1);
128
+ return encodeBase58Check(combined);
129
+ };
package/src/consts.ts ADDED
@@ -0,0 +1,8 @@
1
+ // Copyright (c) 2024 The Bitcoin developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ /** Default dust limit on the eCash network. */
6
+ export const DEFAULT_DUST_LIMIT = 546;
7
+ /** Default fee per kB on the eCash network. */
8
+ export const DEFAULT_FEE_PER_KB = 1000;
package/src/ecc.ts ADDED
@@ -0,0 +1,61 @@
1
+ // Copyright (c) 2024 The Bitcoin developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ /** Interface to abstract over Elliptic Curve Cryptography */
6
+ export interface Ecc {
7
+ /** Derive a public key from secret key. */
8
+ derivePubkey(seckey: Uint8Array): Uint8Array;
9
+
10
+ /** Sign an ECDSA signature. msg needs to be a 32-byte hash */
11
+ ecdsaSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
12
+
13
+ /** Sign a Schnorr signature. msg needs to be a 32-byte hash */
14
+ schnorrSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
15
+
16
+ /**
17
+ * Return whether the given secret key is valid, i.e. whether is of correct
18
+ * length (32 bytes) and is on the curve.
19
+ */
20
+ isValidSeckey(seckey: Uint8Array): boolean;
21
+
22
+ /** Add a scalar to a secret key */
23
+ seckeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
24
+
25
+ /** Add a scalar to a public key (adding G*b) */
26
+ pubkeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
27
+ }
28
+
29
+ /** Ecc implementation using WebAssembly */
30
+ export let Ecc: { new (): Ecc };
31
+
32
+ /** Dummy Ecc impl that always returns 0, useful for measuring tx size */
33
+ export class EccDummy implements Ecc {
34
+ derivePubkey(_seckey: Uint8Array): Uint8Array {
35
+ return new Uint8Array(33);
36
+ }
37
+
38
+ ecdsaSign(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array {
39
+ return new Uint8Array(73);
40
+ }
41
+
42
+ schnorrSign(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array {
43
+ return new Uint8Array(64);
44
+ }
45
+
46
+ isValidSeckey(_seckey: Uint8Array): boolean {
47
+ return false;
48
+ }
49
+
50
+ seckeyAdd(_a: Uint8Array, _b: Uint8Array): Uint8Array {
51
+ return new Uint8Array(32);
52
+ }
53
+
54
+ pubkeyAdd(_a: Uint8Array, _b: Uint8Array): Uint8Array {
55
+ return new Uint8Array(32);
56
+ }
57
+ }
58
+
59
+ export function __setEcc(ecc: { new (): Ecc }) {
60
+ Ecc = ecc;
61
+ }
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function sha512h_new(): number;
5
+ export function sha512h_update(a: number, b: number, c: number): void;
6
+ export function sha512h_finalize(a: number, b: number): void;
7
+ export function sha512h_clone(a: number): number;
8
+ export function sha256h_new(): number;
9
+ export function sha256h_update(a: number, b: number, c: number): void;
10
+ export function sha256h_finalize(a: number, b: number): void;
11
+ export function sha256h_clone(a: number): number;
12
+ export function __wbg_sha256h_free(a: number): void;
13
+ export function sha512(a: number, b: number, c: number): void;
14
+ export function sha256d(a: number, b: number, c: number): void;
15
+ export function sha256(a: number, b: number, c: number): void;
16
+ export function shaRmd160(a: number, b: number, c: number): void;
17
+ export function ecc_new(): number;
18
+ export function ecc_derivePubkey(a: number, b: number, c: number, d: number): void;
19
+ export function ecc_ecdsaSign(a: number, b: number, c: number, d: number, e: number, f: number): void;
20
+ export function ecc_schnorrSign(a: number, b: number, c: number, d: number, e: number, f: number): void;
21
+ export function ecc_isValidSeckey(a: number, b: number, c: number): number;
22
+ export function ecc_seckeyAdd(a: number, b: number, c: number, d: number, e: number, f: number): void;
23
+ export function ecc_pubkeyAdd(a: number, b: number, c: number, d: number, e: number, f: number): void;
24
+ export function __wbg_ecc_free(a: number): void;
25
+ export function ecash_secp256k1_context_create(a: number): number;
26
+ export function ecash_secp256k1_context_destroy(a: number): void;
27
+ export function secp256k1_default_illegal_callback_fn(a: number, b: number): void;
28
+ export function secp256k1_default_error_callback_fn(a: number, b: number): void;
29
+ export function __wbg_sha512h_free(a: number): void;
30
+ export function __wbindgen_export_0(a: number, b: number): number;
31
+ export function __wbindgen_add_to_stack_pointer(a: number): number;
32
+ export function __wbindgen_export_1(a: number, b: number, c: number): void;
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function sha512h_new(): number;
5
+ export function sha512h_update(a: number, b: number, c: number): void;
6
+ export function sha512h_finalize(a: number, b: number): void;
7
+ export function sha512h_clone(a: number): number;
8
+ export function sha256h_new(): number;
9
+ export function sha256h_update(a: number, b: number, c: number): void;
10
+ export function sha256h_finalize(a: number, b: number): void;
11
+ export function sha256h_clone(a: number): number;
12
+ export function __wbg_sha256h_free(a: number): void;
13
+ export function sha512(a: number, b: number, c: number): void;
14
+ export function sha256d(a: number, b: number, c: number): void;
15
+ export function sha256(a: number, b: number, c: number): void;
16
+ export function shaRmd160(a: number, b: number, c: number): void;
17
+ export function ecc_new(): number;
18
+ export function ecc_derivePubkey(a: number, b: number, c: number, d: number): void;
19
+ export function ecc_ecdsaSign(a: number, b: number, c: number, d: number, e: number, f: number): void;
20
+ export function ecc_schnorrSign(a: number, b: number, c: number, d: number, e: number, f: number): void;
21
+ export function ecc_isValidSeckey(a: number, b: number, c: number): number;
22
+ export function ecc_seckeyAdd(a: number, b: number, c: number, d: number, e: number, f: number): void;
23
+ export function ecc_pubkeyAdd(a: number, b: number, c: number, d: number, e: number, f: number): void;
24
+ export function __wbg_ecc_free(a: number): void;
25
+ export function ecash_secp256k1_context_create(a: number): number;
26
+ export function ecash_secp256k1_context_destroy(a: number): void;
27
+ export function secp256k1_default_illegal_callback_fn(a: number, b: number): void;
28
+ export function secp256k1_default_error_callback_fn(a: number, b: number): void;
29
+ export function __wbg_sha512h_free(a: number): void;
30
+ export function __wbindgen_export_0(a: number, b: number): number;
31
+ export function __wbindgen_add_to_stack_pointer(a: number): number;
32
+ export function __wbindgen_export_1(a: number, b: number, c: number): void;