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.
- package/README.md +2 -1
- package/dist/ecc.d.ts +12 -0
- package/dist/ecc.d.ts.map +1 -1
- package/dist/ecc.js +9 -47
- package/dist/ecc.js.map +1 -1
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +18 -4
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +18 -4
- package/dist/ffi/ecash_lib_wasm_browser.d.ts +95 -4
- package/dist/ffi/ecash_lib_wasm_browser.js +245 -14
- package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +77 -0
- package/dist/ffi/ecash_lib_wasm_nodejs.js +247 -14
- package/dist/hash.d.ts +21 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +16 -10
- package/dist/hash.js.map +1 -1
- package/dist/hdwallet.d.ts +33 -0
- package/dist/hdwallet.d.ts.map +1 -0
- package/dist/hdwallet.js +148 -0
- package/dist/hdwallet.js.map +1 -0
- package/dist/hmac.d.ts +13 -0
- package/dist/hmac.d.ts.map +1 -0
- package/dist/hmac.js +63 -0
- package/dist/hmac.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/initBrowser.d.ts.map +1 -1
- package/dist/initBrowser.js +3 -0
- package/dist/initBrowser.js.map +1 -1
- package/dist/initNodeJs.d.ts.map +1 -1
- package/dist/initNodeJs.js +3 -0
- package/dist/initNodeJs.js.map +1 -1
- package/dist/io/bytes.d.ts +5 -3
- package/dist/io/bytes.d.ts.map +1 -1
- package/dist/io/bytes.js +15 -7
- package/dist/io/bytes.js.map +1 -1
- package/dist/io/writer.d.ts +4 -3
- package/dist/io/writer.d.ts.map +1 -1
- package/dist/io/writerbytes.d.ts +4 -3
- package/dist/io/writerbytes.d.ts.map +1 -1
- package/dist/io/writerbytes.js +7 -6
- package/dist/io/writerbytes.js.map +1 -1
- package/dist/io/writerlength.d.ts +4 -3
- package/dist/io/writerlength.d.ts.map +1 -1
- package/dist/io/writerlength.js +3 -3
- package/dist/io/writerlength.js.map +1 -1
- package/dist/mnemonic.d.ts +14 -0
- package/dist/mnemonic.d.ts.map +1 -0
- package/dist/mnemonic.js +123 -0
- package/dist/mnemonic.js.map +1 -0
- package/dist/pbkdf2.d.ts +11 -0
- package/dist/pbkdf2.d.ts.map +1 -0
- package/dist/pbkdf2.js +36 -0
- package/dist/pbkdf2.js.map +1 -0
- package/dist/script.d.ts +4 -0
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +6 -0
- package/dist/script.js.map +1 -1
- package/package.json +1 -1
- package/src/address/address.ts +346 -0
- package/src/address/legacyaddr.ts +129 -0
- package/src/consts.ts +8 -0
- package/src/ecc.ts +61 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +32 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +32 -0
- package/src/ffi/ecash_lib_wasm_browser.d.ts +183 -0
- package/src/ffi/ecash_lib_wasm_browser.js +571 -0
- package/src/ffi/ecash_lib_wasm_nodejs.d.ts +127 -0
- package/src/ffi/ecash_lib_wasm_nodejs.js +498 -0
- package/src/hash.ts +46 -0
- package/src/hdwallet.ts +181 -0
- package/src/hmac.ts +74 -0
- package/src/index.ts +29 -0
- package/src/indexBrowser.ts +6 -0
- package/src/indexNodeJs.ts +6 -0
- package/src/initBrowser.ts +21 -0
- package/src/initNodeJs.ts +20 -0
- package/src/io/bytes.ts +80 -0
- package/src/io/hex.ts +69 -0
- package/src/io/int.ts +6 -0
- package/src/io/str.ts +16 -0
- package/src/io/varsize.ts +49 -0
- package/src/io/writer.ts +20 -0
- package/src/io/writerbytes.ts +87 -0
- package/src/io/writerlength.ts +44 -0
- package/src/mnemonic.ts +153 -0
- package/src/op.ts +162 -0
- package/src/opcode.ts +154 -0
- package/src/pbkdf2.ts +52 -0
- package/src/script.ts +195 -0
- package/src/sigHashType.ts +190 -0
- package/src/test/testRunner.ts +209 -0
- package/src/token/alp.ts +146 -0
- package/src/token/common.ts +32 -0
- package/src/token/empp.ts +29 -0
- package/src/token/slp.ts +212 -0
- package/src/tx.ts +180 -0
- package/src/txBuilder.ts +262 -0
- package/src/unsignedTx.ts +359 -0
- package/tsconfig.json +2 -1
- package/wordlists/english.json +2053 -0
- package/.nyc_output/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
- package/.nyc_output/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
- package/.nyc_output/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
- package/.nyc_output/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
- package/.nyc_output/processinfo/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
- package/.nyc_output/processinfo/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
- package/.nyc_output/processinfo/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
- package/.nyc_output/processinfo/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/dist/address/cashaddr.d.ts +0 -78
- package/dist/address/cashaddr.d.ts.map +0 -1
- package/dist/address/cashaddr.js +0 -543
- package/dist/address/cashaddr.js.map +0 -1
- package/dist/cashaddr/cashaddr.d.ts +0 -23
- package/dist/cashaddr/cashaddr.d.ts.map +0 -1
- package/dist/cashaddr/cashaddr.js +0 -325
- package/dist/cashaddr/cashaddr.js.map +0 -1
- package/global.d.ts +0 -64
- package/test.log +0 -82
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
let imports = {};
|
|
2
|
+
imports['__wbindgen_placeholder__'] = module.exports;
|
|
3
|
+
let wasm;
|
|
4
|
+
const { TextDecoder } = require(`util`);
|
|
5
|
+
|
|
6
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
7
|
+
|
|
8
|
+
cachedTextDecoder.decode();
|
|
9
|
+
|
|
10
|
+
let cachedUint8Memory0 = null;
|
|
11
|
+
|
|
12
|
+
function getUint8Memory0() {
|
|
13
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
14
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
15
|
+
}
|
|
16
|
+
return cachedUint8Memory0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getStringFromWasm0(ptr, len) {
|
|
20
|
+
ptr = ptr >>> 0;
|
|
21
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const heap = new Array(128).fill(undefined);
|
|
25
|
+
|
|
26
|
+
heap.push(undefined, null, true, false);
|
|
27
|
+
|
|
28
|
+
let heap_next = heap.length;
|
|
29
|
+
|
|
30
|
+
function addHeapObject(obj) {
|
|
31
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
32
|
+
const idx = heap_next;
|
|
33
|
+
heap_next = heap[idx];
|
|
34
|
+
|
|
35
|
+
heap[idx] = obj;
|
|
36
|
+
return idx;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let WASM_VECTOR_LEN = 0;
|
|
40
|
+
|
|
41
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
42
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
43
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
44
|
+
WASM_VECTOR_LEN = arg.length;
|
|
45
|
+
return ptr;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let cachedInt32Memory0 = null;
|
|
49
|
+
|
|
50
|
+
function getInt32Memory0() {
|
|
51
|
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
|
52
|
+
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
53
|
+
}
|
|
54
|
+
return cachedInt32Memory0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
58
|
+
ptr = ptr >>> 0;
|
|
59
|
+
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
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
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Calculate SHA256(SHA256(data)).
|
|
84
|
+
* @param {Uint8Array} data
|
|
85
|
+
* @returns {Uint8Array}
|
|
86
|
+
*/
|
|
87
|
+
module.exports.sha256d = function(data) {
|
|
88
|
+
try {
|
|
89
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
90
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
91
|
+
const len0 = WASM_VECTOR_LEN;
|
|
92
|
+
wasm.sha256d(retptr, ptr0, len0);
|
|
93
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
94
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
95
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
96
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
97
|
+
return v2;
|
|
98
|
+
} finally {
|
|
99
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Calculate SHA256(data).
|
|
105
|
+
* @param {Uint8Array} data
|
|
106
|
+
* @returns {Uint8Array}
|
|
107
|
+
*/
|
|
108
|
+
module.exports.sha256 = function(data) {
|
|
109
|
+
try {
|
|
110
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
111
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
112
|
+
const len0 = WASM_VECTOR_LEN;
|
|
113
|
+
wasm.sha256(retptr, ptr0, len0);
|
|
114
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
115
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
116
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
117
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
118
|
+
return v2;
|
|
119
|
+
} finally {
|
|
120
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Calculate RIPEMD160(SHA256(data)), commonly used as address hash.
|
|
126
|
+
* @param {Uint8Array} data
|
|
127
|
+
* @returns {Uint8Array}
|
|
128
|
+
*/
|
|
129
|
+
module.exports.shaRmd160 = function(data) {
|
|
130
|
+
try {
|
|
131
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
132
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
133
|
+
const len0 = WASM_VECTOR_LEN;
|
|
134
|
+
wasm.shaRmd160(retptr, ptr0, len0);
|
|
135
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
136
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
137
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
138
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
139
|
+
return v2;
|
|
140
|
+
} finally {
|
|
141
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
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
|
+
|
|
159
|
+
const EccFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
160
|
+
? { register: () => {}, unregister: () => {} }
|
|
161
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_ecc_free(ptr >>> 0));
|
|
162
|
+
/**
|
|
163
|
+
* ECC signatures with libsecp256k1.
|
|
164
|
+
*/
|
|
165
|
+
class Ecc {
|
|
166
|
+
|
|
167
|
+
__destroy_into_raw() {
|
|
168
|
+
const ptr = this.__wbg_ptr;
|
|
169
|
+
this.__wbg_ptr = 0;
|
|
170
|
+
EccFinalization.unregister(this);
|
|
171
|
+
return ptr;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
free() {
|
|
175
|
+
const ptr = this.__destroy_into_raw();
|
|
176
|
+
wasm.__wbg_ecc_free(ptr);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Create a new Ecc instance.
|
|
180
|
+
*/
|
|
181
|
+
constructor() {
|
|
182
|
+
const ret = wasm.ecc_new();
|
|
183
|
+
this.__wbg_ptr = ret >>> 0;
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Derive a public key from secret key.
|
|
188
|
+
* @param {Uint8Array} seckey
|
|
189
|
+
* @returns {Uint8Array}
|
|
190
|
+
*/
|
|
191
|
+
derivePubkey(seckey) {
|
|
192
|
+
try {
|
|
193
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
194
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
195
|
+
const len0 = WASM_VECTOR_LEN;
|
|
196
|
+
wasm.ecc_derivePubkey(retptr, this.__wbg_ptr, ptr0, len0);
|
|
197
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
198
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
199
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
200
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
201
|
+
if (r3) {
|
|
202
|
+
throw takeObject(r2);
|
|
203
|
+
}
|
|
204
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
205
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
206
|
+
return v2;
|
|
207
|
+
} finally {
|
|
208
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sign an ECDSA signature.
|
|
213
|
+
* @param {Uint8Array} seckey
|
|
214
|
+
* @param {Uint8Array} msg
|
|
215
|
+
* @returns {Uint8Array}
|
|
216
|
+
*/
|
|
217
|
+
ecdsaSign(seckey, msg) {
|
|
218
|
+
try {
|
|
219
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
220
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
221
|
+
const len0 = WASM_VECTOR_LEN;
|
|
222
|
+
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
223
|
+
const len1 = WASM_VECTOR_LEN;
|
|
224
|
+
wasm.ecc_ecdsaSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
225
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
226
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
227
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
228
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
229
|
+
if (r3) {
|
|
230
|
+
throw takeObject(r2);
|
|
231
|
+
}
|
|
232
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
233
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
234
|
+
return v3;
|
|
235
|
+
} finally {
|
|
236
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Sign a Schnorr signature.
|
|
241
|
+
* @param {Uint8Array} seckey
|
|
242
|
+
* @param {Uint8Array} msg
|
|
243
|
+
* @returns {Uint8Array}
|
|
244
|
+
*/
|
|
245
|
+
schnorrSign(seckey, msg) {
|
|
246
|
+
try {
|
|
247
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
248
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
249
|
+
const len0 = WASM_VECTOR_LEN;
|
|
250
|
+
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
251
|
+
const len1 = WASM_VECTOR_LEN;
|
|
252
|
+
wasm.ecc_schnorrSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
253
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
254
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
255
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
256
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
257
|
+
if (r3) {
|
|
258
|
+
throw takeObject(r2);
|
|
259
|
+
}
|
|
260
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
261
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
262
|
+
return v3;
|
|
263
|
+
} finally {
|
|
264
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
265
|
+
}
|
|
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
|
+
}
|
|
335
|
+
}
|
|
336
|
+
module.exports.Ecc = Ecc;
|
|
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
|
+
|
|
482
|
+
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
483
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
484
|
+
return addHeapObject(ret);
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
488
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const path = require('path').join(__dirname, 'ecash_lib_wasm_bg_nodejs.wasm');
|
|
492
|
+
const bytes = require('fs').readFileSync(path);
|
|
493
|
+
|
|
494
|
+
const wasmModule = new WebAssembly.Module(bytes);
|
|
495
|
+
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
496
|
+
wasm = wasmInstance.exports;
|
|
497
|
+
module.exports.__wasm = wasm;
|
|
498
|
+
|
package/src/hash.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
export interface Hasher {
|
|
6
|
+
update: (data: Uint8Array) => void;
|
|
7
|
+
finalize: () => Uint8Array;
|
|
8
|
+
clone: () => Hasher;
|
|
9
|
+
free: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type HasherClass = { new (): Hasher };
|
|
13
|
+
|
|
14
|
+
interface EcashLibHashes {
|
|
15
|
+
sha256: (data: Uint8Array) => Uint8Array;
|
|
16
|
+
sha256d: (data: Uint8Array) => Uint8Array;
|
|
17
|
+
shaRmd160: (data: Uint8Array) => Uint8Array;
|
|
18
|
+
sha512: (data: Uint8Array) => Uint8Array;
|
|
19
|
+
Sha256H: HasherClass;
|
|
20
|
+
Sha512H: HasherClass;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let HASHES: EcashLibHashes;
|
|
24
|
+
|
|
25
|
+
export function sha256(data: Uint8Array): Uint8Array {
|
|
26
|
+
return HASHES.sha256(data);
|
|
27
|
+
}
|
|
28
|
+
export function sha256d(data: Uint8Array): Uint8Array {
|
|
29
|
+
return HASHES.sha256d(data);
|
|
30
|
+
}
|
|
31
|
+
export function shaRmd160(data: Uint8Array): Uint8Array {
|
|
32
|
+
return HASHES.shaRmd160(data);
|
|
33
|
+
}
|
|
34
|
+
export function sha512(data: Uint8Array): Uint8Array {
|
|
35
|
+
return HASHES.sha512(data);
|
|
36
|
+
}
|
|
37
|
+
export function sha256Hasher(): Hasher {
|
|
38
|
+
return new HASHES.Sha256H();
|
|
39
|
+
}
|
|
40
|
+
export function sha512Hasher(): Hasher {
|
|
41
|
+
return new HASHES.Sha512H();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function __setHashes(hashes: EcashLibHashes) {
|
|
45
|
+
HASHES = hashes;
|
|
46
|
+
}
|