@chainvue/verus-sapling 0.0.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/LICENSE +202 -0
- package/NOTICE +74 -0
- package/README.md +194 -0
- package/crate/pkg/package.json +17 -0
- package/crate/pkg/verus_sapling_prover.d.ts +71 -0
- package/crate/pkg/verus_sapling_prover.js +451 -0
- package/crate/pkg/verus_sapling_prover_bg.wasm +0 -0
- package/crate/pkg/verus_sapling_prover_bg.wasm.d.ts +15 -0
- package/dist/browser/grpcweb.d.ts +29 -0
- package/dist/browser/grpcweb.js +149 -0
- package/dist/browser/index.d.ts +23 -0
- package/dist/browser/index.js +23 -0
- package/dist/browser/lightwalletd-web.d.ts +36 -0
- package/dist/browser/lightwalletd-web.js +186 -0
- package/dist/browser/protobuf.d.ts +38 -0
- package/dist/browser/protobuf.js +115 -0
- package/dist/browser/prover-worker.d.ts +18 -0
- package/dist/browser/prover-worker.js +61 -0
- package/dist/browser/worker-prover.d.ts +38 -0
- package/dist/browser/worker-prover.js +51 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +25 -0
- package/dist/hex.d.ts +11 -0
- package/dist/hex.js +32 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +35 -0
- package/dist/lightwalletd.d.ts +113 -0
- package/dist/lightwalletd.js +99 -0
- package/dist/money.d.ts +23 -0
- package/dist/money.js +40 -0
- package/dist/parse.d.ts +45 -0
- package/dist/parse.js +129 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +13 -0
- package/dist/wallet.d.ts +124 -0
- package/dist/wallet.js +179 -0
- package/dist/wasm.d.ts +91 -0
- package/dist/wasm.js +90 -0
- package/dist/zaddr.d.ts +19 -0
- package/dist/zaddr.js +107 -0
- package/package.json +90 -0
- package/proto/compact_formats.proto +62 -0
- package/proto/darkside.proto +124 -0
- package/proto/service.proto +172 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/* @ts-self-types="./verus_sapling_prover.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Detect the wallet's own notes by trial-decrypting compact outputs (read path
|
|
5
|
+
* — no params, no proving). `spec_json` is the note-detection request (see
|
|
6
|
+
* `json_api::detect_notes_from_json`). Returns a JSON array of detected notes.
|
|
7
|
+
* Cheap (milliseconds); safe to call on the main thread.
|
|
8
|
+
* @param {string} spec_json
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function detect_notes(spec_json) {
|
|
12
|
+
let deferred3_0;
|
|
13
|
+
let deferred3_1;
|
|
14
|
+
try {
|
|
15
|
+
const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
16
|
+
const len0 = WASM_VECTOR_LEN;
|
|
17
|
+
const ret = wasm.detect_notes(ptr0, len0);
|
|
18
|
+
var ptr2 = ret[0];
|
|
19
|
+
var len2 = ret[1];
|
|
20
|
+
if (ret[3]) {
|
|
21
|
+
ptr2 = 0; len2 = 0;
|
|
22
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
23
|
+
}
|
|
24
|
+
deferred3_0 = ptr2;
|
|
25
|
+
deferred3_1 = len2;
|
|
26
|
+
return getStringFromWasm0(ptr2, len2);
|
|
27
|
+
} finally {
|
|
28
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fully decrypt one incoming output (value + recipient + memo) with the
|
|
34
|
+
* wallet's viewing key. `spec_json` is the read request (see
|
|
35
|
+
* `json_api::read_note_from_json`). Returns a JSON object, or the string
|
|
36
|
+
* "null" if the output is not for this key. Cheap (no params, no proving).
|
|
37
|
+
* @param {string} spec_json
|
|
38
|
+
* @returns {string}
|
|
39
|
+
*/
|
|
40
|
+
export function read_note(spec_json) {
|
|
41
|
+
let deferred3_0;
|
|
42
|
+
let deferred3_1;
|
|
43
|
+
try {
|
|
44
|
+
const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
45
|
+
const len0 = WASM_VECTOR_LEN;
|
|
46
|
+
const ret = wasm.read_note(ptr0, len0);
|
|
47
|
+
var ptr2 = ret[0];
|
|
48
|
+
var len2 = ret[1];
|
|
49
|
+
if (ret[3]) {
|
|
50
|
+
ptr2 = 0; len2 = 0;
|
|
51
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
52
|
+
}
|
|
53
|
+
deferred3_0 = ptr2;
|
|
54
|
+
deferred3_1 = len2;
|
|
55
|
+
return getStringFromWasm0(ptr2, len2);
|
|
56
|
+
} finally {
|
|
57
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build + sign a t->z shielding transaction. `spec_json` is the t->z request
|
|
63
|
+
* (see `json_api::build_t2z_from_json`). Returns the transaction hex; the caller
|
|
64
|
+
* still has the daemon fill the transparent scriptSig (signrawtransaction).
|
|
65
|
+
* @param {string} spec_json
|
|
66
|
+
* @param {Uint8Array} spend_params
|
|
67
|
+
* @param {Uint8Array} output_params
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function shield_t2z(spec_json, spend_params, output_params) {
|
|
71
|
+
let deferred5_0;
|
|
72
|
+
let deferred5_1;
|
|
73
|
+
try {
|
|
74
|
+
const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
75
|
+
const len0 = WASM_VECTOR_LEN;
|
|
76
|
+
const ptr1 = passArray8ToWasm0(spend_params, wasm.__wbindgen_malloc);
|
|
77
|
+
const len1 = WASM_VECTOR_LEN;
|
|
78
|
+
const ptr2 = passArray8ToWasm0(output_params, wasm.__wbindgen_malloc);
|
|
79
|
+
const len2 = WASM_VECTOR_LEN;
|
|
80
|
+
const ret = wasm.shield_t2z(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
81
|
+
var ptr4 = ret[0];
|
|
82
|
+
var len4 = ret[1];
|
|
83
|
+
if (ret[3]) {
|
|
84
|
+
ptr4 = 0; len4 = 0;
|
|
85
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
86
|
+
}
|
|
87
|
+
deferred5_0 = ptr4;
|
|
88
|
+
deferred5_1 = len4;
|
|
89
|
+
return getStringFromWasm0(ptr4, len4);
|
|
90
|
+
} finally {
|
|
91
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Build + sign a z->z / z->t transaction that spends a shielded note. Complete
|
|
97
|
+
* after this (no transparent inputs) — broadcast directly.
|
|
98
|
+
* @param {string} spec_json
|
|
99
|
+
* @param {Uint8Array} spend_params
|
|
100
|
+
* @param {Uint8Array} output_params
|
|
101
|
+
* @returns {string}
|
|
102
|
+
*/
|
|
103
|
+
export function spend_shielded(spec_json, spend_params, output_params) {
|
|
104
|
+
let deferred5_0;
|
|
105
|
+
let deferred5_1;
|
|
106
|
+
try {
|
|
107
|
+
const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
108
|
+
const len0 = WASM_VECTOR_LEN;
|
|
109
|
+
const ptr1 = passArray8ToWasm0(spend_params, wasm.__wbindgen_malloc);
|
|
110
|
+
const len1 = WASM_VECTOR_LEN;
|
|
111
|
+
const ptr2 = passArray8ToWasm0(output_params, wasm.__wbindgen_malloc);
|
|
112
|
+
const len2 = WASM_VECTOR_LEN;
|
|
113
|
+
const ret = wasm.spend_shielded(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
114
|
+
var ptr4 = ret[0];
|
|
115
|
+
var len4 = ret[1];
|
|
116
|
+
if (ret[3]) {
|
|
117
|
+
ptr4 = 0; len4 = 0;
|
|
118
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
119
|
+
}
|
|
120
|
+
deferred5_0 = ptr4;
|
|
121
|
+
deferred5_1 = len4;
|
|
122
|
+
return getStringFromWasm0(ptr4, len4);
|
|
123
|
+
} finally {
|
|
124
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function __wbg_get_imports() {
|
|
128
|
+
const import0 = {
|
|
129
|
+
__proto__: null,
|
|
130
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
131
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
132
|
+
return ret;
|
|
133
|
+
},
|
|
134
|
+
__wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
|
|
135
|
+
const ret = typeof(arg0) === 'function';
|
|
136
|
+
return ret;
|
|
137
|
+
},
|
|
138
|
+
__wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
|
|
139
|
+
const val = arg0;
|
|
140
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
141
|
+
return ret;
|
|
142
|
+
},
|
|
143
|
+
__wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
|
|
144
|
+
const ret = typeof(arg0) === 'string';
|
|
145
|
+
return ret;
|
|
146
|
+
},
|
|
147
|
+
__wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
|
|
148
|
+
const ret = arg0 === undefined;
|
|
149
|
+
return ret;
|
|
150
|
+
},
|
|
151
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
152
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
153
|
+
},
|
|
154
|
+
__wbg_call_a6e5c5dce5018821: function() { return handleError(function (arg0, arg1, arg2) {
|
|
155
|
+
const ret = arg0.call(arg1, arg2);
|
|
156
|
+
return ret;
|
|
157
|
+
}, arguments); },
|
|
158
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
159
|
+
const ret = arg0.crypto;
|
|
160
|
+
return ret;
|
|
161
|
+
},
|
|
162
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
|
|
163
|
+
arg0.getRandomValues(arg1);
|
|
164
|
+
}, arguments); },
|
|
165
|
+
__wbg_length_1f0964f4a5e2c6d8: function(arg0) {
|
|
166
|
+
const ret = arg0.length;
|
|
167
|
+
return ret;
|
|
168
|
+
},
|
|
169
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
170
|
+
const ret = arg0.msCrypto;
|
|
171
|
+
return ret;
|
|
172
|
+
},
|
|
173
|
+
__wbg_new_with_length_e6785c33c8e4cce8: function(arg0) {
|
|
174
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
175
|
+
return ret;
|
|
176
|
+
},
|
|
177
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
178
|
+
const ret = arg0.node;
|
|
179
|
+
return ret;
|
|
180
|
+
},
|
|
181
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
182
|
+
const ret = arg0.process;
|
|
183
|
+
return ret;
|
|
184
|
+
},
|
|
185
|
+
__wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
|
|
186
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
187
|
+
},
|
|
188
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
|
|
189
|
+
arg0.randomFillSync(arg1);
|
|
190
|
+
}, arguments); },
|
|
191
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
|
|
192
|
+
const ret = module.require;
|
|
193
|
+
return ret;
|
|
194
|
+
}, arguments); },
|
|
195
|
+
__wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
|
|
196
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
197
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
198
|
+
},
|
|
199
|
+
__wbg_static_accessor_GLOBAL_THIS_8d1badc68b5a74f4: function() {
|
|
200
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
201
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
202
|
+
},
|
|
203
|
+
__wbg_static_accessor_SELF_146583524fe1469b: function() {
|
|
204
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
205
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
206
|
+
},
|
|
207
|
+
__wbg_static_accessor_WINDOW_f2829a2234d7819e: function() {
|
|
208
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
209
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
210
|
+
},
|
|
211
|
+
__wbg_subarray_3ed232c8a6baee09: function(arg0, arg1, arg2) {
|
|
212
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
213
|
+
return ret;
|
|
214
|
+
},
|
|
215
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
216
|
+
const ret = arg0.versions;
|
|
217
|
+
return ret;
|
|
218
|
+
},
|
|
219
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
220
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
221
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
222
|
+
return ret;
|
|
223
|
+
},
|
|
224
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
225
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
226
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
227
|
+
return ret;
|
|
228
|
+
},
|
|
229
|
+
__wbindgen_init_externref_table: function() {
|
|
230
|
+
const table = wasm.__wbindgen_externrefs;
|
|
231
|
+
const offset = table.grow(4);
|
|
232
|
+
table.set(0, undefined);
|
|
233
|
+
table.set(offset + 0, undefined);
|
|
234
|
+
table.set(offset + 1, null);
|
|
235
|
+
table.set(offset + 2, true);
|
|
236
|
+
table.set(offset + 3, false);
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
__proto__: null,
|
|
241
|
+
"./verus_sapling_prover_bg.js": import0,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function addToExternrefTable0(obj) {
|
|
246
|
+
const idx = wasm.__externref_table_alloc();
|
|
247
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
248
|
+
return idx;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
252
|
+
ptr = ptr >>> 0;
|
|
253
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function getStringFromWasm0(ptr, len) {
|
|
257
|
+
return decodeText(ptr >>> 0, len);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let cachedUint8ArrayMemory0 = null;
|
|
261
|
+
function getUint8ArrayMemory0() {
|
|
262
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
263
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
264
|
+
}
|
|
265
|
+
return cachedUint8ArrayMemory0;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function handleError(f, args) {
|
|
269
|
+
try {
|
|
270
|
+
return f.apply(this, args);
|
|
271
|
+
} catch (e) {
|
|
272
|
+
const idx = addToExternrefTable0(e);
|
|
273
|
+
wasm.__wbindgen_exn_store(idx);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function isLikeNone(x) {
|
|
278
|
+
return x === undefined || x === null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
282
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
283
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
284
|
+
WASM_VECTOR_LEN = arg.length;
|
|
285
|
+
return ptr;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
289
|
+
if (realloc === undefined) {
|
|
290
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
291
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
292
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
293
|
+
WASM_VECTOR_LEN = buf.length;
|
|
294
|
+
return ptr;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let len = arg.length;
|
|
298
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
299
|
+
|
|
300
|
+
const mem = getUint8ArrayMemory0();
|
|
301
|
+
|
|
302
|
+
let offset = 0;
|
|
303
|
+
|
|
304
|
+
for (; offset < len; offset++) {
|
|
305
|
+
const code = arg.charCodeAt(offset);
|
|
306
|
+
if (code > 0x7F) break;
|
|
307
|
+
mem[ptr + offset] = code;
|
|
308
|
+
}
|
|
309
|
+
if (offset !== len) {
|
|
310
|
+
if (offset !== 0) {
|
|
311
|
+
arg = arg.slice(offset);
|
|
312
|
+
}
|
|
313
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
314
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
315
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
316
|
+
|
|
317
|
+
offset += ret.written;
|
|
318
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
WASM_VECTOR_LEN = offset;
|
|
322
|
+
return ptr;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function takeFromExternrefTable0(idx) {
|
|
326
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
327
|
+
wasm.__externref_table_dealloc(idx);
|
|
328
|
+
return value;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
332
|
+
cachedTextDecoder.decode();
|
|
333
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
334
|
+
let numBytesDecoded = 0;
|
|
335
|
+
function decodeText(ptr, len) {
|
|
336
|
+
numBytesDecoded += len;
|
|
337
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
338
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
339
|
+
cachedTextDecoder.decode();
|
|
340
|
+
numBytesDecoded = len;
|
|
341
|
+
}
|
|
342
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const cachedTextEncoder = new TextEncoder();
|
|
346
|
+
|
|
347
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
348
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
349
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
350
|
+
view.set(buf);
|
|
351
|
+
return {
|
|
352
|
+
read: arg.length,
|
|
353
|
+
written: buf.length
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
let WASM_VECTOR_LEN = 0;
|
|
359
|
+
|
|
360
|
+
let wasmModule, wasmInstance, wasm;
|
|
361
|
+
function __wbg_finalize_init(instance, module) {
|
|
362
|
+
wasmInstance = instance;
|
|
363
|
+
wasm = instance.exports;
|
|
364
|
+
wasmModule = module;
|
|
365
|
+
cachedUint8ArrayMemory0 = null;
|
|
366
|
+
wasm.__wbindgen_start();
|
|
367
|
+
return wasm;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async function __wbg_load(module, imports) {
|
|
371
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
372
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
373
|
+
try {
|
|
374
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
375
|
+
} catch (e) {
|
|
376
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
377
|
+
|
|
378
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
379
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
380
|
+
|
|
381
|
+
} else { throw e; }
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const bytes = await module.arrayBuffer();
|
|
386
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
387
|
+
} else {
|
|
388
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
389
|
+
|
|
390
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
391
|
+
return { instance, module };
|
|
392
|
+
} else {
|
|
393
|
+
return instance;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function expectedResponseType(type) {
|
|
398
|
+
switch (type) {
|
|
399
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function initSync(module) {
|
|
406
|
+
if (wasm !== undefined) return wasm;
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
if (module !== undefined) {
|
|
410
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
411
|
+
({module} = module)
|
|
412
|
+
} else {
|
|
413
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const imports = __wbg_get_imports();
|
|
418
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
419
|
+
module = new WebAssembly.Module(module);
|
|
420
|
+
}
|
|
421
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
422
|
+
return __wbg_finalize_init(instance, module);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async function __wbg_init(module_or_path) {
|
|
426
|
+
if (wasm !== undefined) return wasm;
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
if (module_or_path !== undefined) {
|
|
430
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
431
|
+
({module_or_path} = module_or_path)
|
|
432
|
+
} else {
|
|
433
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (module_or_path === undefined) {
|
|
438
|
+
module_or_path = new URL('verus_sapling_prover_bg.wasm', import.meta.url);
|
|
439
|
+
}
|
|
440
|
+
const imports = __wbg_get_imports();
|
|
441
|
+
|
|
442
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
443
|
+
module_or_path = fetch(module_or_path);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
447
|
+
|
|
448
|
+
return __wbg_finalize_init(instance, module);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const detect_notes: (a: number, b: number) => [number, number, number, number];
|
|
5
|
+
export const read_note: (a: number, b: number) => [number, number, number, number];
|
|
6
|
+
export const shield_t2z: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
7
|
+
export const spend_shielded: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
8
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
9
|
+
export const __externref_table_alloc: () => number;
|
|
10
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
11
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
12
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
13
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
14
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC-web transport over `fetch` — the browser's way to reach a native gRPC
|
|
3
|
+
* service (lightwalletd) through a gRPC-web proxy (grpcwebproxy / Envoy).
|
|
4
|
+
*
|
|
5
|
+
* Wire format: each message is a 5-byte-prefixed frame — 1 flag byte (0 = data,
|
|
6
|
+
* 0x80 = trailer) + 4-byte big-endian length + payload. A unary response is one
|
|
7
|
+
* data frame then a trailer frame; a server-streaming response is many data
|
|
8
|
+
* frames then a trailer. The trailer payload is ASCII `grpc-status`/`grpc-message`
|
|
9
|
+
* headers; a non-zero status is surfaced as an error.
|
|
10
|
+
*
|
|
11
|
+
* Uses `application/grpc-web+proto` (binary), which grpcwebproxy serves and
|
|
12
|
+
* Cloudflare tunnels pass through unchanged. Works in the browser and under Node
|
|
13
|
+
* (18+ has `fetch`), which is how the transport is tested headlessly.
|
|
14
|
+
*/
|
|
15
|
+
/** Encode one protobuf message as a gRPC-web data frame. */
|
|
16
|
+
export declare function encodeFrame(msg: Uint8Array): Uint8Array;
|
|
17
|
+
/** A parsed gRPC-web frame. */
|
|
18
|
+
export interface Frame {
|
|
19
|
+
trailer: boolean;
|
|
20
|
+
payload: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
export declare class FrameParser {
|
|
23
|
+
private buf;
|
|
24
|
+
push(chunk: Uint8Array): Frame[];
|
|
25
|
+
}
|
|
26
|
+
/** Unary call: returns the single response message bytes. */
|
|
27
|
+
export declare function unary(baseUrl: string, method: string, reqMsg: Uint8Array): Promise<Uint8Array>;
|
|
28
|
+
/** Server-streaming call: yields each response message's bytes as it arrives. */
|
|
29
|
+
export declare function serverStream(baseUrl: string, method: string, reqMsg: Uint8Array): AsyncGenerator<Uint8Array>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC-web transport over `fetch` — the browser's way to reach a native gRPC
|
|
3
|
+
* service (lightwalletd) through a gRPC-web proxy (grpcwebproxy / Envoy).
|
|
4
|
+
*
|
|
5
|
+
* Wire format: each message is a 5-byte-prefixed frame — 1 flag byte (0 = data,
|
|
6
|
+
* 0x80 = trailer) + 4-byte big-endian length + payload. A unary response is one
|
|
7
|
+
* data frame then a trailer frame; a server-streaming response is many data
|
|
8
|
+
* frames then a trailer. The trailer payload is ASCII `grpc-status`/`grpc-message`
|
|
9
|
+
* headers; a non-zero status is surfaced as an error.
|
|
10
|
+
*
|
|
11
|
+
* Uses `application/grpc-web+proto` (binary), which grpcwebproxy serves and
|
|
12
|
+
* Cloudflare tunnels pass through unchanged. Works in the browser and under Node
|
|
13
|
+
* (18+ has `fetch`), which is how the transport is tested headlessly.
|
|
14
|
+
*/
|
|
15
|
+
const SERVICE = 'cash.z.wallet.sdk.rpc.CompactTxStreamer';
|
|
16
|
+
/** Encode one protobuf message as a gRPC-web data frame. */
|
|
17
|
+
export function encodeFrame(msg) {
|
|
18
|
+
const frame = new Uint8Array(5 + msg.length);
|
|
19
|
+
frame[0] = 0x00; // data frame, uncompressed
|
|
20
|
+
new DataView(frame.buffer).setUint32(1, msg.length, false); // big-endian length
|
|
21
|
+
frame.set(msg, 5);
|
|
22
|
+
return frame;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Incremental frame parser: feed it bytes, it yields complete frames and keeps
|
|
26
|
+
* any partial remainder for the next chunk (needed for streaming across network
|
|
27
|
+
* chunk boundaries).
|
|
28
|
+
*/
|
|
29
|
+
/** Max gRPC-web frame payload (matches gRPC's 4 MiB default). The 4-byte length
|
|
30
|
+
* prefix is server-controlled up to 4 GiB; without a cap a malicious proxy could
|
|
31
|
+
* drive unbounded buffering (memory DoS). */
|
|
32
|
+
const MAX_FRAME_SIZE = 4 * 1024 * 1024;
|
|
33
|
+
export class FrameParser {
|
|
34
|
+
buf = new Uint8Array(0);
|
|
35
|
+
push(chunk) {
|
|
36
|
+
const merged = new Uint8Array(this.buf.length + chunk.length);
|
|
37
|
+
merged.set(this.buf, 0);
|
|
38
|
+
merged.set(chunk, this.buf.length);
|
|
39
|
+
this.buf = merged;
|
|
40
|
+
const frames = [];
|
|
41
|
+
for (;;) {
|
|
42
|
+
if (this.buf.length < 5)
|
|
43
|
+
break;
|
|
44
|
+
const flag = this.buf[0];
|
|
45
|
+
const len = new DataView(this.buf.buffer, this.buf.byteOffset, this.buf.byteLength).getUint32(1, false);
|
|
46
|
+
if (len > MAX_FRAME_SIZE) {
|
|
47
|
+
throw new RangeError(`gRPC-web: frame length ${len} exceeds max ${MAX_FRAME_SIZE}`);
|
|
48
|
+
}
|
|
49
|
+
if (this.buf.length < 5 + len)
|
|
50
|
+
break;
|
|
51
|
+
frames.push({ trailer: (flag & 0x80) !== 0, payload: this.buf.subarray(5, 5 + len) });
|
|
52
|
+
this.buf = this.buf.subarray(5 + len);
|
|
53
|
+
}
|
|
54
|
+
return frames;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Parse a trailer frame's ASCII payload; throw if grpc-status is non-zero. */
|
|
58
|
+
function checkTrailer(payload) {
|
|
59
|
+
const text = new TextDecoder().decode(payload);
|
|
60
|
+
const status = /grpc-status:\s*(\d+)/i.exec(text);
|
|
61
|
+
if (status && status[1] !== '0') {
|
|
62
|
+
const msg = /grpc-message:\s*(.*)/i.exec(text);
|
|
63
|
+
throw new Error(`gRPC error ${status[1]}${msg ? `: ${decodeURIComponent(msg[1].trim())}` : ''}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function post(baseUrl, method, reqMsg) {
|
|
67
|
+
const url = `${baseUrl.replace(/\/$/, '')}/${SERVICE}/${method}`;
|
|
68
|
+
// A stale keep-alive connection (e.g. closed by the proxy while the client was
|
|
69
|
+
// busy proving) surfaces as a fetch rejection, NOT an HTTP status — retry once
|
|
70
|
+
// on a fresh connection. gRPC application errors arrive in the trailer, so they
|
|
71
|
+
// never reach this catch; only genuine transport failures do. Broadcasting is
|
|
72
|
+
// idempotent (a duplicate tx is simply rejected), so retrying is safe.
|
|
73
|
+
let lastErr;
|
|
74
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
75
|
+
try {
|
|
76
|
+
const res = await fetch(url, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/grpc-web+proto',
|
|
80
|
+
'X-Grpc-Web': '1',
|
|
81
|
+
Accept: 'application/grpc-web+proto',
|
|
82
|
+
},
|
|
83
|
+
// A Uint8Array is a valid fetch body; the cast sidesteps TS 5.7+
|
|
84
|
+
// Uint8Array<ArrayBufferLike> vs BodyInit generic friction.
|
|
85
|
+
body: encodeFrame(reqMsg),
|
|
86
|
+
});
|
|
87
|
+
if (!res.ok)
|
|
88
|
+
throw new Error(`gRPC-web HTTP ${res.status} for ${method}`);
|
|
89
|
+
if (!res.body)
|
|
90
|
+
throw new Error(`gRPC-web: no response body for ${method}`);
|
|
91
|
+
return res;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
lastErr = e;
|
|
95
|
+
// Only retry genuine transport failures (fetch rejections), not HTTP errors.
|
|
96
|
+
if (e instanceof Error && e.message.startsWith('gRPC-web HTTP'))
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
throw lastErr;
|
|
101
|
+
}
|
|
102
|
+
/** Unary call: returns the single response message bytes. */
|
|
103
|
+
export async function unary(baseUrl, method, reqMsg) {
|
|
104
|
+
const res = await post(baseUrl, method, reqMsg);
|
|
105
|
+
const buf = new Uint8Array(await res.arrayBuffer());
|
|
106
|
+
const frames = new FrameParser().push(buf);
|
|
107
|
+
let data;
|
|
108
|
+
for (const f of frames) {
|
|
109
|
+
if (f.trailer)
|
|
110
|
+
checkTrailer(f.payload);
|
|
111
|
+
else
|
|
112
|
+
data ??= f.payload;
|
|
113
|
+
}
|
|
114
|
+
if (!data)
|
|
115
|
+
throw new Error(`gRPC-web: no data frame for ${method}`);
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
/** Server-streaming call: yields each response message's bytes as it arrives. */
|
|
119
|
+
export async function* serverStream(baseUrl, method, reqMsg) {
|
|
120
|
+
const res = await post(baseUrl, method, reqMsg);
|
|
121
|
+
const reader = res.body.getReader();
|
|
122
|
+
const parser = new FrameParser();
|
|
123
|
+
let trailerErr;
|
|
124
|
+
try {
|
|
125
|
+
for (;;) {
|
|
126
|
+
const { done, value } = await reader.read();
|
|
127
|
+
if (done)
|
|
128
|
+
break;
|
|
129
|
+
for (const f of parser.push(value)) {
|
|
130
|
+
if (f.trailer) {
|
|
131
|
+
try {
|
|
132
|
+
checkTrailer(f.payload);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
trailerErr = e;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
yield f.payload;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
reader.releaseLock();
|
|
146
|
+
}
|
|
147
|
+
if (trailerErr)
|
|
148
|
+
throw trailerErr;
|
|
149
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser entry for `@chainvue/verus-sapling` — everything needed to run the
|
|
3
|
+
* shielded wallet in a browser extension, with NO Node dependency
|
|
4
|
+
* (no `@grpc/grpc-js`, no `Buffer`):
|
|
5
|
+
*
|
|
6
|
+
* - `LightwalletdWebClient` — `LightwalletdTransport` over gRPC-web (`fetch`),
|
|
7
|
+
* pointed at a gRPC-web proxy in front of lightwalletd.
|
|
8
|
+
* - `createWorkerProver` — runs the ~20 s Sapling spend prove in a Web Worker.
|
|
9
|
+
*
|
|
10
|
+
* Combine with `detectNotes` / `buildShieldedSpend` from the package root:
|
|
11
|
+
*
|
|
12
|
+
* import { detectNotes, buildShieldedSpend } from '@chainvue/verus-sapling';
|
|
13
|
+
* import { LightwalletdWebClient, createWorkerProver } from '@chainvue/verus-sapling/browser';
|
|
14
|
+
*
|
|
15
|
+
* const client = new LightwalletdWebClient('http://localhost:8080');
|
|
16
|
+
* const worker = new Worker(new URL('./prover-worker.js', import.meta.url), { type: 'module' });
|
|
17
|
+
* const prover = await createWorkerProver(worker, { wasmBytes, spendParams, outputParams });
|
|
18
|
+
* const notes = await detectNotes(client, prover.detect, { key: { extskHex }, fromHeight });
|
|
19
|
+
* const { hex } = await buildShieldedSpend(client, prover.spend, { note, shieldedOutputs });
|
|
20
|
+
* await client.sendTransaction(hex);
|
|
21
|
+
*/
|
|
22
|
+
export { LightwalletdWebClient, blockTxid } from './lightwalletd-web.js';
|
|
23
|
+
export { createWorkerProver, type WorkerProver, type WorkerProverInit, } from './worker-prover.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser entry for `@chainvue/verus-sapling` — everything needed to run the
|
|
3
|
+
* shielded wallet in a browser extension, with NO Node dependency
|
|
4
|
+
* (no `@grpc/grpc-js`, no `Buffer`):
|
|
5
|
+
*
|
|
6
|
+
* - `LightwalletdWebClient` — `LightwalletdTransport` over gRPC-web (`fetch`),
|
|
7
|
+
* pointed at a gRPC-web proxy in front of lightwalletd.
|
|
8
|
+
* - `createWorkerProver` — runs the ~20 s Sapling spend prove in a Web Worker.
|
|
9
|
+
*
|
|
10
|
+
* Combine with `detectNotes` / `buildShieldedSpend` from the package root:
|
|
11
|
+
*
|
|
12
|
+
* import { detectNotes, buildShieldedSpend } from '@chainvue/verus-sapling';
|
|
13
|
+
* import { LightwalletdWebClient, createWorkerProver } from '@chainvue/verus-sapling/browser';
|
|
14
|
+
*
|
|
15
|
+
* const client = new LightwalletdWebClient('http://localhost:8080');
|
|
16
|
+
* const worker = new Worker(new URL('./prover-worker.js', import.meta.url), { type: 'module' });
|
|
17
|
+
* const prover = await createWorkerProver(worker, { wasmBytes, spendParams, outputParams });
|
|
18
|
+
* const notes = await detectNotes(client, prover.detect, { key: { extskHex }, fromHeight });
|
|
19
|
+
* const { hex } = await buildShieldedSpend(client, prover.spend, { note, shieldedOutputs });
|
|
20
|
+
* await client.sendTransaction(hex);
|
|
21
|
+
*/
|
|
22
|
+
export { LightwalletdWebClient, blockTxid } from './lightwalletd-web.js';
|
|
23
|
+
export { createWorkerProver, } from './worker-prover.js';
|