ecash-lib 4.13.0-rc.0 → 4.13.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 +1 -1
- package/dist/ffi/ecash_lib_wasm_bg_browser.js +22065 -2616
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +3 -3
- package/dist/ffi/ecash_lib_wasm_browser.d.ts +20 -20
- package/dist/ffi/ecash_lib_wasm_browser.js +84 -83
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/initWasm.js +3 -4
- package/dist/initWasm.js.map +1 -1
- package/package.json +51 -62
- package/src/ffi/ecash_lib_wasm_bg_browser.js +22065 -2616
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +3 -3
- package/src/ffi/ecash_lib_wasm_browser.d.ts +20 -20
- package/src/ffi/ecash_lib_wasm_browser.js +84 -83
- package/src/index.ts +2 -0
- package/src/initWasm.ts +3 -4
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +0 -40
- package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +0 -180
- package/dist/ffi/ecash_lib_wasm_nodejs.js +0 -726
- package/dist/indexBrowser.d.ts +0 -3
- package/dist/indexBrowser.d.ts.map +0 -1
- package/dist/indexBrowser.js +0 -22
- package/dist/indexBrowser.js.map +0 -1
- package/dist/indexNodeJs.d.ts +0 -3
- package/dist/indexNodeJs.d.ts.map +0 -1
- package/dist/indexNodeJs.js +0 -22
- package/dist/indexNodeJs.js.map +0 -1
- package/dist/initBrowser.d.ts +0 -2
- package/dist/initBrowser.d.ts.map +0 -1
- package/dist/initBrowser.js +0 -7
- package/dist/initBrowser.js.map +0 -1
- package/dist/initNodeJs.d.ts +0 -2
- package/dist/initNodeJs.d.ts.map +0 -1
- package/dist/initNodeJs.js +0 -7
- package/dist/initNodeJs.js.map +0 -1
- package/dist/payment/p2shInputData.d.ts +0 -18
- package/dist/payment/p2shInputData.d.ts.map +0 -1
- package/dist/payment/p2shInputData.js +0 -88
- package/dist/payment/p2shInputData.js.map +0 -1
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +0 -40
- package/src/ffi/ecash_lib_wasm_nodejs.d.ts +0 -180
- package/src/ffi/ecash_lib_wasm_nodejs.js +0 -726
- package/src/indexBrowser.ts +0 -6
- package/src/indexNodeJs.ts +0 -6
- package/src/initBrowser.ts +0 -5
- package/src/initNodeJs.ts +0 -5
|
@@ -1,726 +0,0 @@
|
|
|
1
|
-
let imports = {};
|
|
2
|
-
imports['__wbindgen_placeholder__'] = module.exports;
|
|
3
|
-
let wasm;
|
|
4
|
-
const { TextDecoder, TextEncoder } = 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 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
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
72
|
-
ptr = ptr >>> 0;
|
|
73
|
-
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Calculate SHA512(data).
|
|
77
|
-
* @param {Uint8Array} data
|
|
78
|
-
* @returns {Uint8Array}
|
|
79
|
-
*/
|
|
80
|
-
module.exports.sha512 = function(data) {
|
|
81
|
-
try {
|
|
82
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
83
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
84
|
-
const len0 = WASM_VECTOR_LEN;
|
|
85
|
-
wasm.sha512(retptr, ptr0, len0);
|
|
86
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
87
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
88
|
-
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
89
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
90
|
-
return v2;
|
|
91
|
-
} finally {
|
|
92
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Calculate SHA256(SHA256(data)).
|
|
98
|
-
* @param {Uint8Array} data
|
|
99
|
-
* @returns {Uint8Array}
|
|
100
|
-
*/
|
|
101
|
-
module.exports.sha256d = function(data) {
|
|
102
|
-
try {
|
|
103
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
104
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
105
|
-
const len0 = WASM_VECTOR_LEN;
|
|
106
|
-
wasm.sha256d(retptr, ptr0, len0);
|
|
107
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
108
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
109
|
-
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
110
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
111
|
-
return v2;
|
|
112
|
-
} finally {
|
|
113
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Calculate SHA256(data).
|
|
119
|
-
* @param {Uint8Array} data
|
|
120
|
-
* @returns {Uint8Array}
|
|
121
|
-
*/
|
|
122
|
-
module.exports.sha256 = function(data) {
|
|
123
|
-
try {
|
|
124
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
125
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
126
|
-
const len0 = WASM_VECTOR_LEN;
|
|
127
|
-
wasm.sha256(retptr, ptr0, len0);
|
|
128
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
129
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
130
|
-
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
131
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
132
|
-
return v2;
|
|
133
|
-
} finally {
|
|
134
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Calculate RIPEMD160(SHA256(data)), commonly used as address hash.
|
|
140
|
-
* @param {Uint8Array} data
|
|
141
|
-
* @returns {Uint8Array}
|
|
142
|
-
*/
|
|
143
|
-
module.exports.shaRmd160 = function(data) {
|
|
144
|
-
try {
|
|
145
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
146
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
147
|
-
const len0 = WASM_VECTOR_LEN;
|
|
148
|
-
wasm.shaRmd160(retptr, ptr0, len0);
|
|
149
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
150
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
151
|
-
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
152
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
153
|
-
return v2;
|
|
154
|
-
} finally {
|
|
155
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
160
|
-
|
|
161
|
-
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
162
|
-
? function (arg, view) {
|
|
163
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
164
|
-
}
|
|
165
|
-
: function (arg, view) {
|
|
166
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
167
|
-
view.set(buf);
|
|
168
|
-
return {
|
|
169
|
-
read: arg.length,
|
|
170
|
-
written: buf.length
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
175
|
-
|
|
176
|
-
if (realloc === undefined) {
|
|
177
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
178
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
179
|
-
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
180
|
-
WASM_VECTOR_LEN = buf.length;
|
|
181
|
-
return ptr;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let len = arg.length;
|
|
185
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
186
|
-
|
|
187
|
-
const mem = getUint8Memory0();
|
|
188
|
-
|
|
189
|
-
let offset = 0;
|
|
190
|
-
|
|
191
|
-
for (; offset < len; offset++) {
|
|
192
|
-
const code = arg.charCodeAt(offset);
|
|
193
|
-
if (code > 0x7F) break;
|
|
194
|
-
mem[ptr + offset] = code;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (offset !== len) {
|
|
198
|
-
if (offset !== 0) {
|
|
199
|
-
arg = arg.slice(offset);
|
|
200
|
-
}
|
|
201
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
202
|
-
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
203
|
-
const ret = encodeString(arg, view);
|
|
204
|
-
|
|
205
|
-
offset += ret.written;
|
|
206
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
WASM_VECTOR_LEN = offset;
|
|
210
|
-
return ptr;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function isLikeNone(x) {
|
|
214
|
-
return x === undefined || x === null;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Verify a signature for the given cryptographic algorithm.
|
|
218
|
-
* Intended to be used in X509 certificate verification.
|
|
219
|
-
* Throw an exception if the algorithm is not supported.
|
|
220
|
-
* @param {string} algo_oid
|
|
221
|
-
* @param {string | undefined} params
|
|
222
|
-
* @param {Uint8Array} sig
|
|
223
|
-
* @param {Uint8Array} msg
|
|
224
|
-
* @param {Uint8Array} pk
|
|
225
|
-
*/
|
|
226
|
-
module.exports.publicKeyCryptoVerify = function(algo_oid, params, sig, msg, pk) {
|
|
227
|
-
try {
|
|
228
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
229
|
-
const ptr0 = passStringToWasm0(algo_oid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
|
|
230
|
-
const len0 = WASM_VECTOR_LEN;
|
|
231
|
-
var ptr1 = isLikeNone(params) ? 0 : passStringToWasm0(params, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
|
|
232
|
-
var len1 = WASM_VECTOR_LEN;
|
|
233
|
-
const ptr2 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
|
|
234
|
-
const len2 = WASM_VECTOR_LEN;
|
|
235
|
-
const ptr3 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
236
|
-
const len3 = WASM_VECTOR_LEN;
|
|
237
|
-
const ptr4 = passArray8ToWasm0(pk, wasm.__wbindgen_export_0);
|
|
238
|
-
const len4 = WASM_VECTOR_LEN;
|
|
239
|
-
wasm.publicKeyCryptoVerify(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
|
240
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
241
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
242
|
-
if (r1) {
|
|
243
|
-
throw takeObject(r0);
|
|
244
|
-
}
|
|
245
|
-
} finally {
|
|
246
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Throw an exception if the given algo is not supported, otherwise do nothing.
|
|
252
|
-
* @param {string} algo_oid
|
|
253
|
-
* @param {string | undefined} [params]
|
|
254
|
-
*/
|
|
255
|
-
module.exports.publicKeyCryptoAlgoSupported = function(algo_oid, params) {
|
|
256
|
-
try {
|
|
257
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
258
|
-
const ptr0 = passStringToWasm0(algo_oid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
|
|
259
|
-
const len0 = WASM_VECTOR_LEN;
|
|
260
|
-
var ptr1 = isLikeNone(params) ? 0 : passStringToWasm0(params, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
|
|
261
|
-
var len1 = WASM_VECTOR_LEN;
|
|
262
|
-
wasm.publicKeyCryptoAlgoSupported(retptr, ptr0, len0, ptr1, len1);
|
|
263
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
264
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
265
|
-
if (r1) {
|
|
266
|
-
throw takeObject(r0);
|
|
267
|
-
}
|
|
268
|
-
} finally {
|
|
269
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const EccFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
274
|
-
? { register: () => {}, unregister: () => {} }
|
|
275
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_ecc_free(ptr >>> 0));
|
|
276
|
-
/**
|
|
277
|
-
* ECC signatures with libsecp256k1.
|
|
278
|
-
*/
|
|
279
|
-
class Ecc {
|
|
280
|
-
|
|
281
|
-
__destroy_into_raw() {
|
|
282
|
-
const ptr = this.__wbg_ptr;
|
|
283
|
-
this.__wbg_ptr = 0;
|
|
284
|
-
EccFinalization.unregister(this);
|
|
285
|
-
return ptr;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
free() {
|
|
289
|
-
const ptr = this.__destroy_into_raw();
|
|
290
|
-
wasm.__wbg_ecc_free(ptr);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Create a new Ecc instance.
|
|
294
|
-
*/
|
|
295
|
-
constructor() {
|
|
296
|
-
const ret = wasm.ecc_new();
|
|
297
|
-
this.__wbg_ptr = ret >>> 0;
|
|
298
|
-
return this;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Derive a public key from secret key.
|
|
302
|
-
* @param {Uint8Array} seckey
|
|
303
|
-
* @returns {Uint8Array}
|
|
304
|
-
*/
|
|
305
|
-
derivePubkey(seckey) {
|
|
306
|
-
try {
|
|
307
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
308
|
-
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
309
|
-
const len0 = WASM_VECTOR_LEN;
|
|
310
|
-
wasm.ecc_derivePubkey(retptr, this.__wbg_ptr, ptr0, len0);
|
|
311
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
312
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
313
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
314
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
315
|
-
if (r3) {
|
|
316
|
-
throw takeObject(r2);
|
|
317
|
-
}
|
|
318
|
-
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
319
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
320
|
-
return v2;
|
|
321
|
-
} finally {
|
|
322
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Sign an ECDSA signature.
|
|
327
|
-
* @param {Uint8Array} seckey
|
|
328
|
-
* @param {Uint8Array} msg
|
|
329
|
-
* @returns {Uint8Array}
|
|
330
|
-
*/
|
|
331
|
-
ecdsaSign(seckey, msg) {
|
|
332
|
-
try {
|
|
333
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
334
|
-
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
335
|
-
const len0 = WASM_VECTOR_LEN;
|
|
336
|
-
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
337
|
-
const len1 = WASM_VECTOR_LEN;
|
|
338
|
-
wasm.ecc_ecdsaSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
339
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
340
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
341
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
342
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
343
|
-
if (r3) {
|
|
344
|
-
throw takeObject(r2);
|
|
345
|
-
}
|
|
346
|
-
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
347
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
348
|
-
return v3;
|
|
349
|
-
} finally {
|
|
350
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Verify an ECDSA signature.
|
|
355
|
-
* @param {Uint8Array} sig
|
|
356
|
-
* @param {Uint8Array} msg
|
|
357
|
-
* @param {Uint8Array} pk
|
|
358
|
-
*/
|
|
359
|
-
ecdsaVerify(sig, msg, pk) {
|
|
360
|
-
try {
|
|
361
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
362
|
-
const ptr0 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
|
|
363
|
-
const len0 = WASM_VECTOR_LEN;
|
|
364
|
-
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
365
|
-
const len1 = WASM_VECTOR_LEN;
|
|
366
|
-
const ptr2 = passArray8ToWasm0(pk, wasm.__wbindgen_export_0);
|
|
367
|
-
const len2 = WASM_VECTOR_LEN;
|
|
368
|
-
wasm.ecc_ecdsaVerify(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
369
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
370
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
371
|
-
if (r1) {
|
|
372
|
-
throw takeObject(r0);
|
|
373
|
-
}
|
|
374
|
-
} finally {
|
|
375
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Sign a Schnorr signature.
|
|
380
|
-
* @param {Uint8Array} seckey
|
|
381
|
-
* @param {Uint8Array} msg
|
|
382
|
-
* @returns {Uint8Array}
|
|
383
|
-
*/
|
|
384
|
-
schnorrSign(seckey, msg) {
|
|
385
|
-
try {
|
|
386
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
387
|
-
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
388
|
-
const len0 = WASM_VECTOR_LEN;
|
|
389
|
-
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
390
|
-
const len1 = WASM_VECTOR_LEN;
|
|
391
|
-
wasm.ecc_schnorrSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
392
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
393
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
394
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
395
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
396
|
-
if (r3) {
|
|
397
|
-
throw takeObject(r2);
|
|
398
|
-
}
|
|
399
|
-
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
400
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
401
|
-
return v3;
|
|
402
|
-
} finally {
|
|
403
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Verify a Schnorr signature.
|
|
408
|
-
* @param {Uint8Array} sig
|
|
409
|
-
* @param {Uint8Array} msg
|
|
410
|
-
* @param {Uint8Array} pk
|
|
411
|
-
*/
|
|
412
|
-
schnorrVerify(sig, msg, pk) {
|
|
413
|
-
try {
|
|
414
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
415
|
-
const ptr0 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
|
|
416
|
-
const len0 = WASM_VECTOR_LEN;
|
|
417
|
-
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
418
|
-
const len1 = WASM_VECTOR_LEN;
|
|
419
|
-
const ptr2 = passArray8ToWasm0(pk, wasm.__wbindgen_export_0);
|
|
420
|
-
const len2 = WASM_VECTOR_LEN;
|
|
421
|
-
wasm.ecc_schnorrVerify(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
422
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
423
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
424
|
-
if (r1) {
|
|
425
|
-
throw takeObject(r0);
|
|
426
|
-
}
|
|
427
|
-
} finally {
|
|
428
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Return whether the given secret key is valid, i.e. whether is of correct
|
|
433
|
-
* length (32 bytes) and is on the curve.
|
|
434
|
-
* @param {Uint8Array} seckey
|
|
435
|
-
* @returns {boolean}
|
|
436
|
-
*/
|
|
437
|
-
isValidSeckey(seckey) {
|
|
438
|
-
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
439
|
-
const len0 = WASM_VECTOR_LEN;
|
|
440
|
-
const ret = wasm.ecc_isValidSeckey(this.__wbg_ptr, ptr0, len0);
|
|
441
|
-
return ret !== 0;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Add a scalar to a secret key.
|
|
445
|
-
* @param {Uint8Array} a
|
|
446
|
-
* @param {Uint8Array} b
|
|
447
|
-
* @returns {Uint8Array}
|
|
448
|
-
*/
|
|
449
|
-
seckeyAdd(a, b) {
|
|
450
|
-
try {
|
|
451
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
452
|
-
const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
|
|
453
|
-
const len0 = WASM_VECTOR_LEN;
|
|
454
|
-
const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
|
|
455
|
-
const len1 = WASM_VECTOR_LEN;
|
|
456
|
-
wasm.ecc_seckeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
457
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
458
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
459
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
460
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
461
|
-
if (r3) {
|
|
462
|
-
throw takeObject(r2);
|
|
463
|
-
}
|
|
464
|
-
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
465
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
466
|
-
return v3;
|
|
467
|
-
} finally {
|
|
468
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Add a scalar to a public key (adding G*b).
|
|
473
|
-
* @param {Uint8Array} a
|
|
474
|
-
* @param {Uint8Array} b
|
|
475
|
-
* @returns {Uint8Array}
|
|
476
|
-
*/
|
|
477
|
-
pubkeyAdd(a, b) {
|
|
478
|
-
try {
|
|
479
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
480
|
-
const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
|
|
481
|
-
const len0 = WASM_VECTOR_LEN;
|
|
482
|
-
const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
|
|
483
|
-
const len1 = WASM_VECTOR_LEN;
|
|
484
|
-
wasm.ecc_pubkeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
485
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
486
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
487
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
488
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
489
|
-
if (r3) {
|
|
490
|
-
throw takeObject(r2);
|
|
491
|
-
}
|
|
492
|
-
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
493
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
494
|
-
return v3;
|
|
495
|
-
} finally {
|
|
496
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Create a compact ECDSA signature (65 bytes), which allows reconstructing
|
|
501
|
-
* the used public key.
|
|
502
|
-
* The format is one header byte, followed by two times 32 bytes for the
|
|
503
|
-
* serialized r and s values.
|
|
504
|
-
* The header byte: 0x1B = first key with even y,
|
|
505
|
-
* 0x1C = first key with odd y,
|
|
506
|
-
* 0x1D = second key with even y,
|
|
507
|
-
* 0x1E = second key with odd y,
|
|
508
|
-
* add 0x04 for compressed keys.
|
|
509
|
-
* @param {Uint8Array} seckey
|
|
510
|
-
* @param {Uint8Array} msg
|
|
511
|
-
* @returns {Uint8Array}
|
|
512
|
-
*/
|
|
513
|
-
signRecoverable(seckey, msg) {
|
|
514
|
-
try {
|
|
515
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
516
|
-
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
517
|
-
const len0 = WASM_VECTOR_LEN;
|
|
518
|
-
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
519
|
-
const len1 = WASM_VECTOR_LEN;
|
|
520
|
-
wasm.ecc_signRecoverable(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
521
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
522
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
523
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
524
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
525
|
-
if (r3) {
|
|
526
|
-
throw takeObject(r2);
|
|
527
|
-
}
|
|
528
|
-
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
529
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
530
|
-
return v3;
|
|
531
|
-
} finally {
|
|
532
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Recover the public key of a signature signed by signRecoverable.
|
|
537
|
-
* @param {Uint8Array} sig
|
|
538
|
-
* @param {Uint8Array} msg
|
|
539
|
-
* @returns {Uint8Array}
|
|
540
|
-
*/
|
|
541
|
-
recoverSig(sig, msg) {
|
|
542
|
-
try {
|
|
543
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
544
|
-
const ptr0 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
|
|
545
|
-
const len0 = WASM_VECTOR_LEN;
|
|
546
|
-
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
547
|
-
const len1 = WASM_VECTOR_LEN;
|
|
548
|
-
wasm.ecc_recoverSig(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
549
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
550
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
551
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
552
|
-
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
553
|
-
if (r3) {
|
|
554
|
-
throw takeObject(r2);
|
|
555
|
-
}
|
|
556
|
-
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
557
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
558
|
-
return v3;
|
|
559
|
-
} finally {
|
|
560
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
module.exports.Ecc = Ecc;
|
|
565
|
-
|
|
566
|
-
const Sha256HFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
567
|
-
? { register: () => {}, unregister: () => {} }
|
|
568
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_sha256h_free(ptr >>> 0));
|
|
569
|
-
/**
|
|
570
|
-
* Instance to calculate SHA256 in a streaming fashion
|
|
571
|
-
*/
|
|
572
|
-
class Sha256H {
|
|
573
|
-
|
|
574
|
-
static __wrap(ptr) {
|
|
575
|
-
ptr = ptr >>> 0;
|
|
576
|
-
const obj = Object.create(Sha256H.prototype);
|
|
577
|
-
obj.__wbg_ptr = ptr;
|
|
578
|
-
Sha256HFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
579
|
-
return obj;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
__destroy_into_raw() {
|
|
583
|
-
const ptr = this.__wbg_ptr;
|
|
584
|
-
this.__wbg_ptr = 0;
|
|
585
|
-
Sha256HFinalization.unregister(this);
|
|
586
|
-
return ptr;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
free() {
|
|
590
|
-
const ptr = this.__destroy_into_raw();
|
|
591
|
-
wasm.__wbg_sha256h_free(ptr);
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Create new hasher instance
|
|
595
|
-
*/
|
|
596
|
-
constructor() {
|
|
597
|
-
const ret = wasm.sha256h_new();
|
|
598
|
-
this.__wbg_ptr = ret >>> 0;
|
|
599
|
-
return this;
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Feed bytes into the hasher
|
|
603
|
-
* @param {Uint8Array} data
|
|
604
|
-
*/
|
|
605
|
-
update(data) {
|
|
606
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
607
|
-
const len0 = WASM_VECTOR_LEN;
|
|
608
|
-
wasm.sha256h_update(this.__wbg_ptr, ptr0, len0);
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Finalize the hash and return the result
|
|
612
|
-
* @returns {Uint8Array}
|
|
613
|
-
*/
|
|
614
|
-
finalize() {
|
|
615
|
-
try {
|
|
616
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
617
|
-
wasm.sha256h_finalize(retptr, this.__wbg_ptr);
|
|
618
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
619
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
620
|
-
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
621
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
622
|
-
return v1;
|
|
623
|
-
} finally {
|
|
624
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Clone the hasher
|
|
629
|
-
* @returns {Sha256H}
|
|
630
|
-
*/
|
|
631
|
-
clone() {
|
|
632
|
-
const ret = wasm.sha256h_clone(this.__wbg_ptr);
|
|
633
|
-
return Sha256H.__wrap(ret);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
module.exports.Sha256H = Sha256H;
|
|
637
|
-
|
|
638
|
-
const Sha512HFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
639
|
-
? { register: () => {}, unregister: () => {} }
|
|
640
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_sha512h_free(ptr >>> 0));
|
|
641
|
-
/**
|
|
642
|
-
* Instance to calculate SHA512 in a streaming fashion
|
|
643
|
-
*/
|
|
644
|
-
class Sha512H {
|
|
645
|
-
|
|
646
|
-
static __wrap(ptr) {
|
|
647
|
-
ptr = ptr >>> 0;
|
|
648
|
-
const obj = Object.create(Sha512H.prototype);
|
|
649
|
-
obj.__wbg_ptr = ptr;
|
|
650
|
-
Sha512HFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
651
|
-
return obj;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
__destroy_into_raw() {
|
|
655
|
-
const ptr = this.__wbg_ptr;
|
|
656
|
-
this.__wbg_ptr = 0;
|
|
657
|
-
Sha512HFinalization.unregister(this);
|
|
658
|
-
return ptr;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
free() {
|
|
662
|
-
const ptr = this.__destroy_into_raw();
|
|
663
|
-
wasm.__wbg_sha512h_free(ptr);
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Create new hasher instance
|
|
667
|
-
*/
|
|
668
|
-
constructor() {
|
|
669
|
-
const ret = wasm.sha512h_new();
|
|
670
|
-
this.__wbg_ptr = ret >>> 0;
|
|
671
|
-
return this;
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Feed bytes into the hasher
|
|
675
|
-
* @param {Uint8Array} data
|
|
676
|
-
*/
|
|
677
|
-
update(data) {
|
|
678
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
679
|
-
const len0 = WASM_VECTOR_LEN;
|
|
680
|
-
wasm.sha512h_update(this.__wbg_ptr, ptr0, len0);
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Finalize the hash and return the result
|
|
684
|
-
* @returns {Uint8Array}
|
|
685
|
-
*/
|
|
686
|
-
finalize() {
|
|
687
|
-
try {
|
|
688
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
689
|
-
wasm.sha512h_finalize(retptr, this.__wbg_ptr);
|
|
690
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
691
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
692
|
-
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
693
|
-
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
694
|
-
return v1;
|
|
695
|
-
} finally {
|
|
696
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Clone the hasher
|
|
701
|
-
* @returns {Sha512H}
|
|
702
|
-
*/
|
|
703
|
-
clone() {
|
|
704
|
-
const ret = wasm.sha512h_clone(this.__wbg_ptr);
|
|
705
|
-
return Sha512H.__wrap(ret);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
module.exports.Sha512H = Sha512H;
|
|
709
|
-
|
|
710
|
-
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
711
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
712
|
-
return addHeapObject(ret);
|
|
713
|
-
};
|
|
714
|
-
|
|
715
|
-
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
716
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
const path = require('path').join(__dirname, 'ecash_lib_wasm_bg_nodejs.wasm');
|
|
720
|
-
const bytes = require('fs').readFileSync(path);
|
|
721
|
-
|
|
722
|
-
const wasmModule = new WebAssembly.Module(bytes);
|
|
723
|
-
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
724
|
-
wasm = wasmInstance.exports;
|
|
725
|
-
module.exports.__wasm = wasm;
|
|
726
|
-
|