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,6 +1,12 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
+ * Calculate SHA512(data).
5
+ * @param {Uint8Array} data
6
+ * @returns {Uint8Array}
7
+ */
8
+ export function sha512(data: Uint8Array): Uint8Array;
9
+ /**
4
10
  * Calculate SHA256(SHA256(data)).
5
11
  * @param {Uint8Array} data
6
12
  * @returns {Uint8Array}
@@ -47,4 +53,75 @@ export class Ecc {
47
53
  * @returns {Uint8Array}
48
54
  */
49
55
  schnorrSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
56
+ /**
57
+ * Return whether the given secret key is valid, i.e. whether is of correct
58
+ * length (32 bytes) and is on the curve.
59
+ * @param {Uint8Array} seckey
60
+ * @returns {boolean}
61
+ */
62
+ isValidSeckey(seckey: Uint8Array): boolean;
63
+ /**
64
+ * Add a scalar to a secret key.
65
+ * @param {Uint8Array} a
66
+ * @param {Uint8Array} b
67
+ * @returns {Uint8Array}
68
+ */
69
+ seckeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
70
+ /**
71
+ * Add a scalar to a public key (adding G*b).
72
+ * @param {Uint8Array} a
73
+ * @param {Uint8Array} b
74
+ * @returns {Uint8Array}
75
+ */
76
+ pubkeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
77
+ }
78
+ /**
79
+ * Instance to calculate SHA256 in a streaming fashion
80
+ */
81
+ export class Sha256H {
82
+ free(): void;
83
+ /**
84
+ * Create new hasher instance
85
+ */
86
+ constructor();
87
+ /**
88
+ * Feed bytes into the hasher
89
+ * @param {Uint8Array} data
90
+ */
91
+ update(data: Uint8Array): void;
92
+ /**
93
+ * Finalize the hash and return the result
94
+ * @returns {Uint8Array}
95
+ */
96
+ finalize(): Uint8Array;
97
+ /**
98
+ * Clone the hasher
99
+ * @returns {Sha256H}
100
+ */
101
+ clone(): Sha256H;
102
+ }
103
+ /**
104
+ * Instance to calculate SHA512 in a streaming fashion
105
+ */
106
+ export class Sha512H {
107
+ free(): void;
108
+ /**
109
+ * Create new hasher instance
110
+ */
111
+ constructor();
112
+ /**
113
+ * Feed bytes into the hasher
114
+ * @param {Uint8Array} data
115
+ */
116
+ update(data: Uint8Array): void;
117
+ /**
118
+ * Finalize the hash and return the result
119
+ * @returns {Uint8Array}
120
+ */
121
+ finalize(): Uint8Array;
122
+ /**
123
+ * Clone the hasher
124
+ * @returns {Sha512H}
125
+ */
126
+ clone(): Sha512H;
50
127
  }
@@ -54,24 +54,31 @@ function getInt32Memory0() {
54
54
  return cachedInt32Memory0;
55
55
  }
56
56
 
57
- function getObject(idx) { return heap[idx]; }
58
-
59
- function dropObject(idx) {
60
- if (idx < 132) return;
61
- heap[idx] = heap_next;
62
- heap_next = idx;
63
- }
64
-
65
- function takeObject(idx) {
66
- const ret = getObject(idx);
67
- dropObject(idx);
68
- return ret;
69
- }
70
-
71
57
  function getArrayU8FromWasm0(ptr, len) {
72
58
  ptr = ptr >>> 0;
73
59
  return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
74
60
  }
61
+ /**
62
+ * Calculate SHA512(data).
63
+ * @param {Uint8Array} data
64
+ * @returns {Uint8Array}
65
+ */
66
+ module.exports.sha512 = function(data) {
67
+ try {
68
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
69
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
70
+ const len0 = WASM_VECTOR_LEN;
71
+ wasm.sha512(retptr, ptr0, len0);
72
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
73
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
74
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
75
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
76
+ return v2;
77
+ } finally {
78
+ wasm.__wbindgen_add_to_stack_pointer(16);
79
+ }
80
+ };
81
+
75
82
  /**
76
83
  * Calculate SHA256(SHA256(data)).
77
84
  * @param {Uint8Array} data
@@ -135,6 +142,20 @@ module.exports.shaRmd160 = function(data) {
135
142
  }
136
143
  };
137
144
 
145
+ function getObject(idx) { return heap[idx]; }
146
+
147
+ function dropObject(idx) {
148
+ if (idx < 132) return;
149
+ heap[idx] = heap_next;
150
+ heap_next = idx;
151
+ }
152
+
153
+ function takeObject(idx) {
154
+ const ret = getObject(idx);
155
+ dropObject(idx);
156
+ return ret;
157
+ }
158
+
138
159
  const EccFinalization = (typeof FinalizationRegistry === 'undefined')
139
160
  ? { register: () => {}, unregister: () => {} }
140
161
  : new FinalizationRegistry(ptr => wasm.__wbg_ecc_free(ptr >>> 0));
@@ -243,9 +264,221 @@ class Ecc {
243
264
  wasm.__wbindgen_add_to_stack_pointer(16);
244
265
  }
245
266
  }
267
+ /**
268
+ * Return whether the given secret key is valid, i.e. whether is of correct
269
+ * length (32 bytes) and is on the curve.
270
+ * @param {Uint8Array} seckey
271
+ * @returns {boolean}
272
+ */
273
+ isValidSeckey(seckey) {
274
+ const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
275
+ const len0 = WASM_VECTOR_LEN;
276
+ const ret = wasm.ecc_isValidSeckey(this.__wbg_ptr, ptr0, len0);
277
+ return ret !== 0;
278
+ }
279
+ /**
280
+ * Add a scalar to a secret key.
281
+ * @param {Uint8Array} a
282
+ * @param {Uint8Array} b
283
+ * @returns {Uint8Array}
284
+ */
285
+ seckeyAdd(a, b) {
286
+ try {
287
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
288
+ const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
289
+ const len0 = WASM_VECTOR_LEN;
290
+ const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
291
+ const len1 = WASM_VECTOR_LEN;
292
+ wasm.ecc_seckeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
293
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
294
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
295
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
296
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
297
+ if (r3) {
298
+ throw takeObject(r2);
299
+ }
300
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
301
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
302
+ return v3;
303
+ } finally {
304
+ wasm.__wbindgen_add_to_stack_pointer(16);
305
+ }
306
+ }
307
+ /**
308
+ * Add a scalar to a public key (adding G*b).
309
+ * @param {Uint8Array} a
310
+ * @param {Uint8Array} b
311
+ * @returns {Uint8Array}
312
+ */
313
+ pubkeyAdd(a, b) {
314
+ try {
315
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
316
+ const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
317
+ const len0 = WASM_VECTOR_LEN;
318
+ const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
319
+ const len1 = WASM_VECTOR_LEN;
320
+ wasm.ecc_pubkeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
321
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
322
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
323
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
324
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
325
+ if (r3) {
326
+ throw takeObject(r2);
327
+ }
328
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
329
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
330
+ return v3;
331
+ } finally {
332
+ wasm.__wbindgen_add_to_stack_pointer(16);
333
+ }
334
+ }
246
335
  }
247
336
  module.exports.Ecc = Ecc;
248
337
 
338
+ const Sha256HFinalization = (typeof FinalizationRegistry === 'undefined')
339
+ ? { register: () => {}, unregister: () => {} }
340
+ : new FinalizationRegistry(ptr => wasm.__wbg_sha256h_free(ptr >>> 0));
341
+ /**
342
+ * Instance to calculate SHA256 in a streaming fashion
343
+ */
344
+ class Sha256H {
345
+
346
+ static __wrap(ptr) {
347
+ ptr = ptr >>> 0;
348
+ const obj = Object.create(Sha256H.prototype);
349
+ obj.__wbg_ptr = ptr;
350
+ Sha256HFinalization.register(obj, obj.__wbg_ptr, obj);
351
+ return obj;
352
+ }
353
+
354
+ __destroy_into_raw() {
355
+ const ptr = this.__wbg_ptr;
356
+ this.__wbg_ptr = 0;
357
+ Sha256HFinalization.unregister(this);
358
+ return ptr;
359
+ }
360
+
361
+ free() {
362
+ const ptr = this.__destroy_into_raw();
363
+ wasm.__wbg_sha256h_free(ptr);
364
+ }
365
+ /**
366
+ * Create new hasher instance
367
+ */
368
+ constructor() {
369
+ const ret = wasm.sha256h_new();
370
+ this.__wbg_ptr = ret >>> 0;
371
+ return this;
372
+ }
373
+ /**
374
+ * Feed bytes into the hasher
375
+ * @param {Uint8Array} data
376
+ */
377
+ update(data) {
378
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
379
+ const len0 = WASM_VECTOR_LEN;
380
+ wasm.sha256h_update(this.__wbg_ptr, ptr0, len0);
381
+ }
382
+ /**
383
+ * Finalize the hash and return the result
384
+ * @returns {Uint8Array}
385
+ */
386
+ finalize() {
387
+ try {
388
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
389
+ wasm.sha256h_finalize(retptr, this.__wbg_ptr);
390
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
391
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
392
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
393
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
394
+ return v1;
395
+ } finally {
396
+ wasm.__wbindgen_add_to_stack_pointer(16);
397
+ }
398
+ }
399
+ /**
400
+ * Clone the hasher
401
+ * @returns {Sha256H}
402
+ */
403
+ clone() {
404
+ const ret = wasm.sha256h_clone(this.__wbg_ptr);
405
+ return Sha256H.__wrap(ret);
406
+ }
407
+ }
408
+ module.exports.Sha256H = Sha256H;
409
+
410
+ const Sha512HFinalization = (typeof FinalizationRegistry === 'undefined')
411
+ ? { register: () => {}, unregister: () => {} }
412
+ : new FinalizationRegistry(ptr => wasm.__wbg_sha512h_free(ptr >>> 0));
413
+ /**
414
+ * Instance to calculate SHA512 in a streaming fashion
415
+ */
416
+ class Sha512H {
417
+
418
+ static __wrap(ptr) {
419
+ ptr = ptr >>> 0;
420
+ const obj = Object.create(Sha512H.prototype);
421
+ obj.__wbg_ptr = ptr;
422
+ Sha512HFinalization.register(obj, obj.__wbg_ptr, obj);
423
+ return obj;
424
+ }
425
+
426
+ __destroy_into_raw() {
427
+ const ptr = this.__wbg_ptr;
428
+ this.__wbg_ptr = 0;
429
+ Sha512HFinalization.unregister(this);
430
+ return ptr;
431
+ }
432
+
433
+ free() {
434
+ const ptr = this.__destroy_into_raw();
435
+ wasm.__wbg_sha512h_free(ptr);
436
+ }
437
+ /**
438
+ * Create new hasher instance
439
+ */
440
+ constructor() {
441
+ const ret = wasm.sha512h_new();
442
+ this.__wbg_ptr = ret >>> 0;
443
+ return this;
444
+ }
445
+ /**
446
+ * Feed bytes into the hasher
447
+ * @param {Uint8Array} data
448
+ */
449
+ update(data) {
450
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
451
+ const len0 = WASM_VECTOR_LEN;
452
+ wasm.sha512h_update(this.__wbg_ptr, ptr0, len0);
453
+ }
454
+ /**
455
+ * Finalize the hash and return the result
456
+ * @returns {Uint8Array}
457
+ */
458
+ finalize() {
459
+ try {
460
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
461
+ wasm.sha512h_finalize(retptr, this.__wbg_ptr);
462
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
463
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
464
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
465
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
466
+ return v1;
467
+ } finally {
468
+ wasm.__wbindgen_add_to_stack_pointer(16);
469
+ }
470
+ }
471
+ /**
472
+ * Clone the hasher
473
+ * @returns {Sha512H}
474
+ */
475
+ clone() {
476
+ const ret = wasm.sha512h_clone(this.__wbg_ptr);
477
+ return Sha512H.__wrap(ret);
478
+ }
479
+ }
480
+ module.exports.Sha512H = Sha512H;
481
+
249
482
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
250
483
  const ret = getStringFromWasm0(arg0, arg1);
251
484
  return addHeapObject(ret);
package/dist/hash.d.ts CHANGED
@@ -1,6 +1,26 @@
1
- import type { EcashLibHashes } from '../global';
1
+ export interface Hasher {
2
+ update: (data: Uint8Array) => void;
3
+ finalize: () => Uint8Array;
4
+ clone: () => Hasher;
5
+ free: () => void;
6
+ }
7
+ type HasherClass = {
8
+ new (): Hasher;
9
+ };
10
+ interface EcashLibHashes {
11
+ sha256: (data: Uint8Array) => Uint8Array;
12
+ sha256d: (data: Uint8Array) => Uint8Array;
13
+ shaRmd160: (data: Uint8Array) => Uint8Array;
14
+ sha512: (data: Uint8Array) => Uint8Array;
15
+ Sha256H: HasherClass;
16
+ Sha512H: HasherClass;
17
+ }
2
18
  export declare function sha256(data: Uint8Array): Uint8Array;
3
19
  export declare function sha256d(data: Uint8Array): Uint8Array;
4
20
  export declare function shaRmd160(data: Uint8Array): Uint8Array;
21
+ export declare function sha512(data: Uint8Array): Uint8Array;
22
+ export declare function sha256Hasher(): Hasher;
23
+ export declare function sha512Hasher(): Hasher;
5
24
  export declare function __setHashes(hashes: EcashLibHashes): void;
25
+ export {};
6
26
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names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,IAAI,MAAM,CAErC;AACD,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,QAEjD"}
package/dist/hash.js CHANGED
@@ -3,28 +3,34 @@
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
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.__setHashes = exports.shaRmd160 = exports.sha256d = exports.sha256 = void 0;
6
+ exports.__setHashes = exports.sha512Hasher = exports.sha256Hasher = exports.sha512 = exports.shaRmd160 = exports.sha256d = exports.sha256 = void 0;
7
7
  let HASHES;
8
8
  function sha256(data) {
9
- return globalThis.ecashlib.HASHES.sha256(data);
9
+ return HASHES.sha256(data);
10
10
  }
11
11
  exports.sha256 = sha256;
12
12
  function sha256d(data) {
13
- return globalThis.ecashlib.HASHES.sha256d(data);
13
+ return HASHES.sha256d(data);
14
14
  }
15
15
  exports.sha256d = sha256d;
16
16
  function shaRmd160(data) {
17
- return globalThis.ecashlib.HASHES.shaRmd160(data);
17
+ return HASHES.shaRmd160(data);
18
18
  }
19
19
  exports.shaRmd160 = shaRmd160;
20
+ function sha512(data) {
21
+ return HASHES.sha512(data);
22
+ }
23
+ exports.sha512 = sha512;
24
+ function sha256Hasher() {
25
+ return new HASHES.Sha256H();
26
+ }
27
+ exports.sha256Hasher = sha256Hasher;
28
+ function sha512Hasher() {
29
+ return new HASHES.Sha512H();
30
+ }
31
+ exports.sha512Hasher = sha512Hasher;
20
32
  function __setHashes(hashes) {
21
33
  HASHES = hashes;
22
- Object.assign(globalThis, {
23
- ecashlib: {
24
- ...(globalThis.ecashlib || {}),
25
- HASHES: hashes,
26
- },
27
- });
28
34
  }
29
35
  exports.__setHashes = __setHashes;
30
36
  //# sourceMappingURL=hash.js.map
package/dist/hash.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";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gB;IACnC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAFD,wBAEC;AACD,SAAgB,YAAY;IACxB,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;AAChC,CAAC;AAFD,oCAEC;AACD,SAAgB,YAAY;IACxB,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;AAChC,CAAC;AAFD,oCAEC;AAED,SAAgB,WAAW,CAAC,MAAsB;IAC9C,MAAM,GAAG,MAAM,CAAC;AACpB,CAAC;AAFD,kCAEC"}
@@ -0,0 +1,33 @@
1
+ import { Ecc } from './ecc.js';
2
+ export declare class HdNode {
3
+ private _ecc;
4
+ private _seckey;
5
+ private _pubkey;
6
+ private _chainCode;
7
+ private _depth;
8
+ private _index;
9
+ private _parentFingerprint;
10
+ constructor(params: {
11
+ ecc: Ecc;
12
+ seckey: Uint8Array | undefined;
13
+ pubkey: Uint8Array;
14
+ chainCode: Uint8Array;
15
+ depth: number;
16
+ index: number;
17
+ parentFingerprint: number;
18
+ });
19
+ seckey(): Uint8Array | undefined;
20
+ pubkey(): Uint8Array;
21
+ pkh(): Uint8Array;
22
+ fingerprint(): Uint8Array;
23
+ index(): number;
24
+ depth(): number;
25
+ parentFingerprint(): number;
26
+ chainCode(): Uint8Array;
27
+ derive(index: number): HdNode;
28
+ deriveHardened(index: number): HdNode;
29
+ derivePath(path: string): HdNode;
30
+ static fromPrivateKey(ecc: Ecc, seckey: Uint8Array, chainCode: Uint8Array): HdNode;
31
+ static fromSeed(ecc: Ecc, seed: Uint8Array): HdNode;
32
+ }
33
+ //# sourceMappingURL=hdwallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hdwallet.d.ts","sourceRoot":"","sources":["../src/hdwallet.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAS/B,qBAAa,MAAM;IACf,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,kBAAkB,CAAS;gBAEhB,MAAM,EAAE;QACvB,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;QAC/B,MAAM,EAAE,UAAU,CAAC;QACnB,SAAS,EAAE,UAAU,CAAC;QACtB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,iBAAiB,EAAE,MAAM,CAAC;KAC7B;IAUM,MAAM,IAAI,UAAU,GAAG,SAAS;IAIhC,MAAM,IAAI,UAAU;IAIpB,GAAG,IAAI,UAAU;IAIjB,WAAW,IAAI,UAAU;IAIzB,KAAK,IAAI,MAAM;IAIf,KAAK,IAAI,MAAM;IAIf,iBAAiB,IAAI,MAAM;IAI3B,SAAS,IAAI,UAAU;IAIvB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAqD7B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IASrC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;WAqBzB,cAAc,CACxB,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,UAAU,GACtB,MAAM;WAYK,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM;CAS7D"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ // Copyright (c) 2025 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.HdNode = void 0;
7
+ const hmac_js_1 = require("./hmac.js");
8
+ const hash_js_1 = require("./hash.js");
9
+ const bytes_js_1 = require("./io/bytes.js");
10
+ const str_js_1 = require("./io/str.js");
11
+ const writerbytes_js_1 = require("./io/writerbytes.js");
12
+ const HIGHEST_BIT = 0x80000000;
13
+ class HdNode {
14
+ constructor(params) {
15
+ this._ecc = params.ecc;
16
+ this._seckey = params.seckey;
17
+ this._pubkey = params.pubkey;
18
+ this._chainCode = params.chainCode;
19
+ this._depth = params.depth;
20
+ this._index = params.index;
21
+ this._parentFingerprint = params.parentFingerprint;
22
+ }
23
+ seckey() {
24
+ return this._seckey;
25
+ }
26
+ pubkey() {
27
+ return this._pubkey;
28
+ }
29
+ pkh() {
30
+ return (0, hash_js_1.shaRmd160)(this._pubkey);
31
+ }
32
+ fingerprint() {
33
+ return this.pkh().slice(0, 4);
34
+ }
35
+ index() {
36
+ return this._index;
37
+ }
38
+ depth() {
39
+ return this._depth;
40
+ }
41
+ parentFingerprint() {
42
+ return this._parentFingerprint;
43
+ }
44
+ chainCode() {
45
+ return this._chainCode;
46
+ }
47
+ derive(index) {
48
+ const isHardened = index >= HIGHEST_BIT;
49
+ const data = new writerbytes_js_1.WriterBytes(1 + 32 + 4);
50
+ if (isHardened) {
51
+ if (this._seckey === undefined) {
52
+ throw new Error('Missing private key for hardened child key');
53
+ }
54
+ data.putU8(0);
55
+ data.putBytes(this._seckey);
56
+ }
57
+ else {
58
+ data.putBytes(this._pubkey);
59
+ }
60
+ data.putU32(index, 'BE');
61
+ const hashed = (0, hmac_js_1.hmacSha512)(this._chainCode, data.data);
62
+ const hashedLeft = hashed.slice(0, 32);
63
+ const hashedRight = hashed.slice(32);
64
+ // In case the secret key doesn't lie on the curve, we proceed with the
65
+ // next index. This is astronomically unlikely but part of the specification.
66
+ if (!this._ecc.isValidSeckey(hashedLeft)) {
67
+ return this.derive(index + 1);
68
+ }
69
+ let seckey;
70
+ let pubkey;
71
+ if (this._seckey !== undefined) {
72
+ try {
73
+ seckey = this._ecc.seckeyAdd(this._seckey, hashedLeft);
74
+ }
75
+ catch (ex) {
76
+ console.log('Skipping index', index, ':', ex);
77
+ return this.derive(index + 1);
78
+ }
79
+ pubkey = this._ecc.derivePubkey(seckey);
80
+ }
81
+ else {
82
+ try {
83
+ pubkey = this._ecc.pubkeyAdd(this._pubkey, hashedLeft);
84
+ }
85
+ catch (ex) {
86
+ console.log('Skipping index', index, ':', ex);
87
+ return this.derive(index + 1);
88
+ }
89
+ seckey = undefined;
90
+ }
91
+ return new HdNode({
92
+ ecc: this._ecc,
93
+ seckey: seckey,
94
+ pubkey: pubkey,
95
+ chainCode: hashedRight,
96
+ depth: this._depth + 1,
97
+ index,
98
+ parentFingerprint: new bytes_js_1.Bytes(this.fingerprint()).readU32('BE'),
99
+ });
100
+ }
101
+ deriveHardened(index) {
102
+ if (index < 0 || index >= HIGHEST_BIT) {
103
+ throw new TypeError(`index must be between 0 and ${HIGHEST_BIT}, got ${index}`);
104
+ }
105
+ return this.derive(index + HIGHEST_BIT);
106
+ }
107
+ derivePath(path) {
108
+ let splitPath = path.split('/');
109
+ if (splitPath[0] === 'm') {
110
+ if (this._parentFingerprint) {
111
+ throw new TypeError('Expected master, got child');
112
+ }
113
+ splitPath = splitPath.slice(1);
114
+ }
115
+ let hd = this;
116
+ for (const step of splitPath) {
117
+ if (step.slice(-1) === `'`) {
118
+ hd = hd.deriveHardened(parseInt(step.slice(0, -1), 10));
119
+ }
120
+ else {
121
+ hd = hd.derive(parseInt(step, 10));
122
+ }
123
+ }
124
+ return hd;
125
+ }
126
+ static fromPrivateKey(ecc, seckey, chainCode) {
127
+ return new HdNode({
128
+ ecc,
129
+ seckey: seckey,
130
+ pubkey: ecc.derivePubkey(seckey),
131
+ chainCode,
132
+ depth: 0,
133
+ index: 0,
134
+ parentFingerprint: 0,
135
+ });
136
+ }
137
+ static fromSeed(ecc, seed) {
138
+ if (seed.length < 16 || seed.length > 64) {
139
+ throw new TypeError('Seed must be between 16 and 64 bytes long');
140
+ }
141
+ const hashed = (0, hmac_js_1.hmacSha512)((0, str_js_1.strToBytes)('Bitcoin seed'), seed);
142
+ const hashedLeft = hashed.slice(0, 32);
143
+ const hashedRight = hashed.slice(32);
144
+ return HdNode.fromPrivateKey(ecc, hashedLeft, hashedRight);
145
+ }
146
+ }
147
+ exports.HdNode = HdNode;
148
+ //# sourceMappingURL=hdwallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hdwallet.js","sourceRoot":"","sources":["../src/hdwallet.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAGtE,uCAAuC;AACvC,uCAAsC;AACtC,4CAAsC;AACtC,wCAAyC;AACzC,wDAAkD;AAElD,MAAM,WAAW,GAAG,UAAU,CAAC;AAE/B,MAAa,MAAM;IASf,YAAmB,MAQlB;QACG,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACvD,CAAC;IAEM,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAEM,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAEM,GAAG;QACN,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAEM,WAAW;QACd,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;IAEM,KAAK;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK;QACR,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AE,CAAC;SACvB,CAAC,CAAC;IACP,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,GAAQ,EAAE,IAAgB;QAC7C,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAC;QACrE,CAAC;QACD,MAAM,MAAM,GAAG,IAAA,oBAAU,EAAC,IAAA,mBAAU,EAAC,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAC/D,CAAC;CACJ;AAvKD,wBAuKC"}
package/dist/hmac.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { Hasher } from './hash';
2
+ export declare class Hmac {
3
+ oHash: Hasher;
4
+ iHash: Hasher;
5
+ constructor(hashFactory: () => Hasher, blockLength: number, key: Uint8Array);
6
+ update(data: Uint8Array): void;
7
+ digest(): Uint8Array;
8
+ clone(): Hmac;
9
+ free(): void;
10
+ }
11
+ export declare function hmacSha256(key: Uint8Array, data: Uint8Array): Uint8Array;
12
+ export declare function hmacSha512(key: Uint8Array, data: Uint8Array): Uint8Array;
13
+ //# sourceMappingURL=hmac.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAA8B,MAAM,QAAQ,CAAC;AAE5D,qBAAa,IAAI;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;gBAGV,WAAW,EAAE,MAAM,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,UAAU;IAyBnB,MAAM,CAAC,IAAI,EAAE,UAAU;IAIvB,MAAM,IAAI,UAAU;IAQpB,KAAK,IAAI,IAAI;IAOb,IAAI;CAIP;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAIxE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAIxE"}