@quilibrium/quilibrium-js-bulletproofs-sdk 2.1.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/dist/index.js ADDED
@@ -0,0 +1,845 @@
1
+ 'use strict';
2
+
3
+ var buffer = require('buffer');
4
+
5
+ let wasm;
6
+
7
+ const heap = new Array(128).fill(undefined);
8
+
9
+ heap.push(undefined, null, true, false);
10
+
11
+ heap.length;
12
+
13
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
14
+
15
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }
16
+ let cachedUint8Memory0 = null;
17
+
18
+ function getUint8Memory0() {
19
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
20
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
21
+ }
22
+ return cachedUint8Memory0;
23
+ }
24
+
25
+ function getStringFromWasm0(ptr, len) {
26
+ ptr = ptr >>> 0;
27
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
28
+ }
29
+
30
+ let WASM_VECTOR_LEN = 0;
31
+
32
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
33
+
34
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
35
+ ? function (arg, view) {
36
+ return cachedTextEncoder.encodeInto(arg, view);
37
+ }
38
+ : function (arg, view) {
39
+ const buf = cachedTextEncoder.encode(arg);
40
+ view.set(buf);
41
+ return {
42
+ read: arg.length,
43
+ written: buf.length
44
+ };
45
+ });
46
+
47
+ function passStringToWasm0(arg, malloc, realloc) {
48
+
49
+ if (realloc === undefined) {
50
+ const buf = cachedTextEncoder.encode(arg);
51
+ const ptr = malloc(buf.length, 1) >>> 0;
52
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
53
+ WASM_VECTOR_LEN = buf.length;
54
+ return ptr;
55
+ }
56
+
57
+ let len = arg.length;
58
+ let ptr = malloc(len, 1) >>> 0;
59
+
60
+ const mem = getUint8Memory0();
61
+
62
+ let offset = 0;
63
+
64
+ for (; offset < len; offset++) {
65
+ const code = arg.charCodeAt(offset);
66
+ if (code > 0x7F) break;
67
+ mem[ptr + offset] = code;
68
+ }
69
+
70
+ if (offset !== len) {
71
+ if (offset !== 0) {
72
+ arg = arg.slice(offset);
73
+ }
74
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
75
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
76
+ const ret = encodeString(arg, view);
77
+
78
+ offset += ret.written;
79
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
80
+ }
81
+
82
+ WASM_VECTOR_LEN = offset;
83
+ return ptr;
84
+ }
85
+
86
+ let cachedInt32Memory0 = null;
87
+
88
+ function getInt32Memory0() {
89
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
90
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
91
+ }
92
+ return cachedInt32Memory0;
93
+ }
94
+ /**
95
+ * @param {string} values
96
+ * @param {string} blinding
97
+ * @param {bigint} bit_size
98
+ * @returns {string}
99
+ */
100
+ function js_generate_range_proof(values, blinding, bit_size) {
101
+ let deferred3_0;
102
+ let deferred3_1;
103
+ try {
104
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
105
+ const ptr0 = passStringToWasm0(values, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
106
+ const len0 = WASM_VECTOR_LEN;
107
+ const ptr1 = passStringToWasm0(blinding, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
108
+ const len1 = WASM_VECTOR_LEN;
109
+ wasm.js_generate_range_proof(retptr, ptr0, len0, ptr1, len1, bit_size);
110
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
111
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
112
+ deferred3_0 = r0;
113
+ deferred3_1 = r1;
114
+ return getStringFromWasm0(r0, r1);
115
+ } finally {
116
+ wasm.__wbindgen_add_to_stack_pointer(16);
117
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
118
+ }
119
+ }
120
+
121
+ /**
122
+ * @param {string} proof
123
+ * @param {string} commitment
124
+ * @param {bigint} bit_size
125
+ * @returns {string}
126
+ */
127
+ function js_verify_range_proof(proof, commitment, bit_size) {
128
+ let deferred3_0;
129
+ let deferred3_1;
130
+ try {
131
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
132
+ const ptr0 = passStringToWasm0(proof, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ const ptr1 = passStringToWasm0(commitment, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
135
+ const len1 = WASM_VECTOR_LEN;
136
+ wasm.js_verify_range_proof(retptr, ptr0, len0, ptr1, len1, bit_size);
137
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
138
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
139
+ deferred3_0 = r0;
140
+ deferred3_1 = r1;
141
+ return getStringFromWasm0(r0, r1);
142
+ } finally {
143
+ wasm.__wbindgen_add_to_stack_pointer(16);
144
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
145
+ }
146
+ }
147
+
148
+ /**
149
+ * @param {string} input_commitments
150
+ * @param {string} additional_input_values
151
+ * @param {string} output_commitments
152
+ * @param {string} additional_output_values
153
+ * @returns {string}
154
+ */
155
+ function js_sum_check(input_commitments, additional_input_values, output_commitments, additional_output_values) {
156
+ let deferred5_0;
157
+ let deferred5_1;
158
+ try {
159
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
160
+ const ptr0 = passStringToWasm0(input_commitments, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
161
+ const len0 = WASM_VECTOR_LEN;
162
+ const ptr1 = passStringToWasm0(additional_input_values, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
163
+ const len1 = WASM_VECTOR_LEN;
164
+ const ptr2 = passStringToWasm0(output_commitments, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
165
+ const len2 = WASM_VECTOR_LEN;
166
+ const ptr3 = passStringToWasm0(additional_output_values, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
167
+ const len3 = WASM_VECTOR_LEN;
168
+ wasm.js_sum_check(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
169
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
170
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
171
+ deferred5_0 = r0;
172
+ deferred5_1 = r1;
173
+ return getStringFromWasm0(r0, r1);
174
+ } finally {
175
+ wasm.__wbindgen_add_to_stack_pointer(16);
176
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
177
+ }
178
+ }
179
+
180
+ /**
181
+ * @param {string} values
182
+ * @param {string} blinding
183
+ * @returns {string}
184
+ */
185
+ function js_generate_input_commitments(values, blinding) {
186
+ let deferred3_0;
187
+ let deferred3_1;
188
+ try {
189
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
190
+ const ptr0 = passStringToWasm0(values, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
191
+ const len0 = WASM_VECTOR_LEN;
192
+ const ptr1 = passStringToWasm0(blinding, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
193
+ const len1 = WASM_VECTOR_LEN;
194
+ wasm.js_generate_input_commitments(retptr, ptr0, len0, ptr1, len1);
195
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
196
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
197
+ deferred3_0 = r0;
198
+ deferred3_1 = r1;
199
+ return getStringFromWasm0(r0, r1);
200
+ } finally {
201
+ wasm.__wbindgen_add_to_stack_pointer(16);
202
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
203
+ }
204
+ }
205
+
206
+ /**
207
+ * @returns {string}
208
+ */
209
+ function js_keygen() {
210
+ let deferred1_0;
211
+ let deferred1_1;
212
+ try {
213
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
214
+ wasm.js_keygen(retptr);
215
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
216
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
217
+ deferred1_0 = r0;
218
+ deferred1_1 = r1;
219
+ return getStringFromWasm0(r0, r1);
220
+ } finally {
221
+ wasm.__wbindgen_add_to_stack_pointer(16);
222
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * @param {string} input
228
+ * @returns {string}
229
+ */
230
+ function js_scalar_to_point(input) {
231
+ let deferred2_0;
232
+ let deferred2_1;
233
+ try {
234
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
235
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
236
+ const len0 = WASM_VECTOR_LEN;
237
+ wasm.js_scalar_to_point(retptr, ptr0, len0);
238
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
239
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
240
+ deferred2_0 = r0;
241
+ deferred2_1 = r1;
242
+ return getStringFromWasm0(r0, r1);
243
+ } finally {
244
+ wasm.__wbindgen_add_to_stack_pointer(16);
245
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @returns {string}
251
+ */
252
+ function js_alt_generator() {
253
+ let deferred1_0;
254
+ let deferred1_1;
255
+ try {
256
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
257
+ wasm.js_alt_generator(retptr);
258
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
259
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
260
+ deferred1_0 = r0;
261
+ deferred1_1 = r1;
262
+ return getStringFromWasm0(r0, r1);
263
+ } finally {
264
+ wasm.__wbindgen_add_to_stack_pointer(16);
265
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
266
+ }
267
+ }
268
+
269
+ /**
270
+ * @param {string} lhs
271
+ * @param {string} rhs
272
+ * @returns {string}
273
+ */
274
+ function js_scalar_addition(lhs, rhs) {
275
+ let deferred3_0;
276
+ let deferred3_1;
277
+ try {
278
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
279
+ const ptr0 = passStringToWasm0(lhs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
280
+ const len0 = WASM_VECTOR_LEN;
281
+ const ptr1 = passStringToWasm0(rhs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
282
+ const len1 = WASM_VECTOR_LEN;
283
+ wasm.js_scalar_addition(retptr, ptr0, len0, ptr1, len1);
284
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
285
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
286
+ deferred3_0 = r0;
287
+ deferred3_1 = r1;
288
+ return getStringFromWasm0(r0, r1);
289
+ } finally {
290
+ wasm.__wbindgen_add_to_stack_pointer(16);
291
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
292
+ }
293
+ }
294
+
295
+ /**
296
+ * @param {string} lhs
297
+ * @param {string} rhs
298
+ * @returns {string}
299
+ */
300
+ function js_scalar_mult(lhs, rhs) {
301
+ let deferred3_0;
302
+ let deferred3_1;
303
+ try {
304
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
305
+ const ptr0 = passStringToWasm0(lhs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
306
+ const len0 = WASM_VECTOR_LEN;
307
+ const ptr1 = passStringToWasm0(rhs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
308
+ const len1 = WASM_VECTOR_LEN;
309
+ wasm.js_scalar_mult(retptr, ptr0, len0, ptr1, len1);
310
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
311
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
312
+ deferred3_0 = r0;
313
+ deferred3_1 = r1;
314
+ return getStringFromWasm0(r0, r1);
315
+ } finally {
316
+ wasm.__wbindgen_add_to_stack_pointer(16);
317
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
318
+ }
319
+ }
320
+
321
+ /**
322
+ * @param {string} input_scalar
323
+ * @param {string} public_point
324
+ * @returns {string}
325
+ */
326
+ function js_scalar_mult_point(input_scalar, public_point) {
327
+ let deferred3_0;
328
+ let deferred3_1;
329
+ try {
330
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
331
+ const ptr0 = passStringToWasm0(input_scalar, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
332
+ const len0 = WASM_VECTOR_LEN;
333
+ const ptr1 = passStringToWasm0(public_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
334
+ const len1 = WASM_VECTOR_LEN;
335
+ wasm.js_scalar_mult_point(retptr, ptr0, len0, ptr1, len1);
336
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
337
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
338
+ deferred3_0 = r0;
339
+ deferred3_1 = r1;
340
+ return getStringFromWasm0(r0, r1);
341
+ } finally {
342
+ wasm.__wbindgen_add_to_stack_pointer(16);
343
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
344
+ }
345
+ }
346
+
347
+ /**
348
+ * @param {string} input_scalar
349
+ * @returns {string}
350
+ */
351
+ function js_scalar_inverse(input_scalar) {
352
+ let deferred2_0;
353
+ let deferred2_1;
354
+ try {
355
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
356
+ const ptr0 = passStringToWasm0(input_scalar, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
357
+ const len0 = WASM_VECTOR_LEN;
358
+ wasm.js_scalar_inverse(retptr, ptr0, len0);
359
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
360
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
361
+ deferred2_0 = r0;
362
+ deferred2_1 = r1;
363
+ return getStringFromWasm0(r0, r1);
364
+ } finally {
365
+ wasm.__wbindgen_add_to_stack_pointer(16);
366
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
367
+ }
368
+ }
369
+
370
+ /**
371
+ * @param {string} lhs
372
+ * @param {string} rhs
373
+ * @returns {string}
374
+ */
375
+ function js_scalar_subtraction(lhs, rhs) {
376
+ let deferred3_0;
377
+ let deferred3_1;
378
+ try {
379
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
380
+ const ptr0 = passStringToWasm0(lhs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
381
+ const len0 = WASM_VECTOR_LEN;
382
+ const ptr1 = passStringToWasm0(rhs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
383
+ const len1 = WASM_VECTOR_LEN;
384
+ wasm.js_scalar_subtraction(retptr, ptr0, len0, ptr1, len1);
385
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
386
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
387
+ deferred3_0 = r0;
388
+ deferred3_1 = r1;
389
+ return getStringFromWasm0(r0, r1);
390
+ } finally {
391
+ wasm.__wbindgen_add_to_stack_pointer(16);
392
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
393
+ }
394
+ }
395
+
396
+ /**
397
+ * @param {string} input_scalar
398
+ * @param {string} public_point
399
+ * @returns {string}
400
+ */
401
+ function js_scalar_mult_hash_to_scalar(input_scalar, public_point) {
402
+ let deferred3_0;
403
+ let deferred3_1;
404
+ try {
405
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
406
+ const ptr0 = passStringToWasm0(input_scalar, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
407
+ const len0 = WASM_VECTOR_LEN;
408
+ const ptr1 = passStringToWasm0(public_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
409
+ const len1 = WASM_VECTOR_LEN;
410
+ wasm.js_scalar_mult_hash_to_scalar(retptr, ptr0, len0, ptr1, len1);
411
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
412
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
413
+ deferred3_0 = r0;
414
+ deferred3_1 = r1;
415
+ return getStringFromWasm0(r0, r1);
416
+ } finally {
417
+ wasm.__wbindgen_add_to_stack_pointer(16);
418
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
419
+ }
420
+ }
421
+
422
+ /**
423
+ * @param {string} input
424
+ * @returns {string}
425
+ */
426
+ function js_hash_to_scalar(input) {
427
+ let deferred2_0;
428
+ let deferred2_1;
429
+ try {
430
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
431
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
432
+ const len0 = WASM_VECTOR_LEN;
433
+ wasm.js_hash_to_scalar(retptr, ptr0, len0);
434
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
435
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
436
+ deferred2_0 = r0;
437
+ deferred2_1 = r1;
438
+ return getStringFromWasm0(r0, r1);
439
+ } finally {
440
+ wasm.__wbindgen_add_to_stack_pointer(16);
441
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
442
+ }
443
+ }
444
+
445
+ /**
446
+ * @param {string} input_point
447
+ * @param {string} public_point
448
+ * @returns {string}
449
+ */
450
+ function js_point_addition(input_point, public_point) {
451
+ let deferred3_0;
452
+ let deferred3_1;
453
+ try {
454
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
455
+ const ptr0 = passStringToWasm0(input_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
456
+ const len0 = WASM_VECTOR_LEN;
457
+ const ptr1 = passStringToWasm0(public_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
458
+ const len1 = WASM_VECTOR_LEN;
459
+ wasm.js_point_addition(retptr, ptr0, len0, ptr1, len1);
460
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
461
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
462
+ deferred3_0 = r0;
463
+ deferred3_1 = r1;
464
+ return getStringFromWasm0(r0, r1);
465
+ } finally {
466
+ wasm.__wbindgen_add_to_stack_pointer(16);
467
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
468
+ }
469
+ }
470
+
471
+ /**
472
+ * @param {string} input_point
473
+ * @param {string} public_point
474
+ * @returns {string}
475
+ */
476
+ function js_point_subtraction(input_point, public_point) {
477
+ let deferred3_0;
478
+ let deferred3_1;
479
+ try {
480
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
481
+ const ptr0 = passStringToWasm0(input_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
482
+ const len0 = WASM_VECTOR_LEN;
483
+ const ptr1 = passStringToWasm0(public_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
484
+ const len1 = WASM_VECTOR_LEN;
485
+ wasm.js_point_subtraction(retptr, ptr0, len0, ptr1, len1);
486
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
487
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
488
+ deferred3_0 = r0;
489
+ deferred3_1 = r1;
490
+ return getStringFromWasm0(r0, r1);
491
+ } finally {
492
+ wasm.__wbindgen_add_to_stack_pointer(16);
493
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
494
+ }
495
+ }
496
+
497
+ /**
498
+ * @param {string} x
499
+ * @param {string} t
500
+ * @param {string} a
501
+ * @param {string} r
502
+ * @returns {string}
503
+ */
504
+ function js_sign_hidden(x, t, a, r) {
505
+ let deferred5_0;
506
+ let deferred5_1;
507
+ try {
508
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
509
+ const ptr0 = passStringToWasm0(x, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
510
+ const len0 = WASM_VECTOR_LEN;
511
+ const ptr1 = passStringToWasm0(t, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
512
+ const len1 = WASM_VECTOR_LEN;
513
+ const ptr2 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
514
+ const len2 = WASM_VECTOR_LEN;
515
+ const ptr3 = passStringToWasm0(r, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
516
+ const len3 = WASM_VECTOR_LEN;
517
+ wasm.js_sign_hidden(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
518
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
519
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
520
+ deferred5_0 = r0;
521
+ deferred5_1 = r1;
522
+ return getStringFromWasm0(r0, r1);
523
+ } finally {
524
+ wasm.__wbindgen_add_to_stack_pointer(16);
525
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
526
+ }
527
+ }
528
+
529
+ /**
530
+ * @param {string} secret
531
+ * @param {string} message
532
+ * @returns {string}
533
+ */
534
+ function js_sign_simple(secret, message) {
535
+ let deferred3_0;
536
+ let deferred3_1;
537
+ try {
538
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
539
+ const ptr0 = passStringToWasm0(secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
540
+ const len0 = WASM_VECTOR_LEN;
541
+ const ptr1 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
542
+ const len1 = WASM_VECTOR_LEN;
543
+ wasm.js_sign_simple(retptr, ptr0, len0, ptr1, len1);
544
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
545
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
546
+ deferred3_0 = r0;
547
+ deferred3_1 = r1;
548
+ return getStringFromWasm0(r0, r1);
549
+ } finally {
550
+ wasm.__wbindgen_add_to_stack_pointer(16);
551
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
552
+ }
553
+ }
554
+
555
+ /**
556
+ * @param {string} message
557
+ * @param {string} signature
558
+ * @param {string} public_point
559
+ * @returns {string}
560
+ */
561
+ function js_verify_simple(message, signature, public_point) {
562
+ let deferred4_0;
563
+ let deferred4_1;
564
+ try {
565
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
566
+ const ptr0 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
567
+ const len0 = WASM_VECTOR_LEN;
568
+ const ptr1 = passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
569
+ const len1 = WASM_VECTOR_LEN;
570
+ const ptr2 = passStringToWasm0(public_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
571
+ const len2 = WASM_VECTOR_LEN;
572
+ wasm.js_verify_simple(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
573
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
574
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
575
+ deferred4_0 = r0;
576
+ deferred4_1 = r1;
577
+ return getStringFromWasm0(r0, r1);
578
+ } finally {
579
+ wasm.__wbindgen_add_to_stack_pointer(16);
580
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
581
+ }
582
+ }
583
+
584
+ /**
585
+ * @param {string} c
586
+ * @param {string} t
587
+ * @param {string} s1
588
+ * @param {string} s2
589
+ * @param {string} s3
590
+ * @param {string} p_point
591
+ * @param {string} c_point
592
+ * @returns {string}
593
+ */
594
+ function js_verify_hidden(c, t, s1, s2, s3, p_point, c_point) {
595
+ let deferred8_0;
596
+ let deferred8_1;
597
+ try {
598
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
599
+ const ptr0 = passStringToWasm0(c, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
600
+ const len0 = WASM_VECTOR_LEN;
601
+ const ptr1 = passStringToWasm0(t, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
602
+ const len1 = WASM_VECTOR_LEN;
603
+ const ptr2 = passStringToWasm0(s1, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
604
+ const len2 = WASM_VECTOR_LEN;
605
+ const ptr3 = passStringToWasm0(s2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
606
+ const len3 = WASM_VECTOR_LEN;
607
+ const ptr4 = passStringToWasm0(s3, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
608
+ const len4 = WASM_VECTOR_LEN;
609
+ const ptr5 = passStringToWasm0(p_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
610
+ const len5 = WASM_VECTOR_LEN;
611
+ const ptr6 = passStringToWasm0(c_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
612
+ const len6 = WASM_VECTOR_LEN;
613
+ wasm.js_verify_hidden(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
614
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
615
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
616
+ deferred8_0 = r0;
617
+ deferred8_1 = r1;
618
+ return getStringFromWasm0(r0, r1);
619
+ } finally {
620
+ wasm.__wbindgen_add_to_stack_pointer(16);
621
+ wasm.__wbindgen_free(deferred8_0, deferred8_1, 1);
622
+ }
623
+ }
624
+
625
+ class BulletproofsError extends Error {
626
+ }
627
+ function BulletproofsGenerateRangeProof(values, blinding, bitSize) {
628
+ const result = JSON.parse(js_generate_range_proof(JSON.stringify(values.map(v => Buffer.from(v).toString('hex'))), JSON.stringify(blinding.map(b => Buffer.from(b).toString('hex'))), BigInt(bitSize)));
629
+ if (typeof (result) == 'object') {
630
+ if (result.proof && result.commitment) {
631
+ return {
632
+ proof: Buffer.from(result.proof, 'hex'),
633
+ commitment: Buffer.from(result.commitment, 'hex'),
634
+ };
635
+ }
636
+ }
637
+ throw new BulletproofsError(result.error || "unknown response");
638
+ }
639
+ function BulletproofsVerifyRangeProof(proof, commitment, bitSize) {
640
+ const result = JSON.parse(js_verify_range_proof(Buffer.from(proof).toString('hex'), Buffer.from(commitment).toString('hex'), BigInt(bitSize)));
641
+ if (typeof (result) == 'boolean') {
642
+ return result;
643
+ }
644
+ else {
645
+ throw new BulletproofsError(result.error);
646
+ }
647
+ }
648
+ function BulletproofsSumCheck(inputCommitments, additionalInputValues, outputCommitments, additionalOutputValues) {
649
+ const result = JSON.parse(js_sum_check(JSON.stringify(inputCommitments.map(c => Buffer.from(c).toString('hex'))), JSON.stringify(additionalInputValues.map(v => Buffer.from(v).toString('hex'))), JSON.stringify(outputCommitments.map(c => Buffer.from(c).toString('hex'))), JSON.stringify(additionalOutputValues.map(v => Buffer.from(v).toString('hex')))));
650
+ if (typeof (result) == 'boolean') {
651
+ return result;
652
+ }
653
+ else {
654
+ throw new BulletproofsError(result.error);
655
+ }
656
+ }
657
+ function BulletproofsGenerateInputCommitments(values, blinding) {
658
+ const result = JSON.parse(js_generate_input_commitments(JSON.stringify(values.map(v => Buffer.from(v).toString('hex'))), JSON.stringify(blinding.map(b => Buffer.from(b).toString('hex')))));
659
+ if (Array.isArray(result)) {
660
+ return result.map(c => Buffer.from(c, 'hex'));
661
+ }
662
+ else {
663
+ throw new BulletproofsError(result.error);
664
+ }
665
+ }
666
+ function BulletproofsKeygen() {
667
+ const result = JSON.parse(js_keygen());
668
+ if (typeof (result) == 'object') {
669
+ if (result.secret_key && result.public_key) {
670
+ return {
671
+ secretKey: Buffer.from(result.secret_key, 'hex'),
672
+ publicKey: Buffer.from(result.public_key, 'hex'),
673
+ };
674
+ }
675
+ }
676
+ throw new BulletproofsError("unknown response");
677
+ }
678
+ function BulletproofsScalarToPoint(scalar) {
679
+ const result = JSON.parse(js_scalar_to_point(Buffer.from(scalar).toString('hex')));
680
+ if (typeof (result) == 'string') {
681
+ return Buffer.from(result, 'hex');
682
+ }
683
+ else {
684
+ throw new BulletproofsError(result.error);
685
+ }
686
+ }
687
+ function BulletproofsAltGenerator() {
688
+ const result = JSON.parse(js_alt_generator());
689
+ if (typeof (result) == 'string') {
690
+ return Buffer.from(result, 'hex');
691
+ }
692
+ else {
693
+ throw new BulletproofsError(result.error);
694
+ }
695
+ }
696
+ function BulletproofsScalarAddition(lhs, rhs) {
697
+ const result = JSON.parse(js_scalar_addition(Buffer.from(lhs).toString('hex'), Buffer.from(rhs).toString('hex')));
698
+ if (typeof (result) == 'string') {
699
+ return Buffer.from(result, 'hex');
700
+ }
701
+ else {
702
+ throw new BulletproofsError(result.error);
703
+ }
704
+ }
705
+ function BulletproofsScalarMult(lhs, rhs) {
706
+ const result = JSON.parse(js_scalar_mult(Buffer.from(lhs).toString('hex'), Buffer.from(rhs).toString('hex')));
707
+ if (typeof (result) == 'string') {
708
+ return Buffer.from(result, 'hex');
709
+ }
710
+ else {
711
+ throw new BulletproofsError(result.error);
712
+ }
713
+ }
714
+ function BulletproofsScalarMultPoint(scalar, point) {
715
+ const result = JSON.parse(js_scalar_mult_point(Buffer.from(scalar).toString('hex'), Buffer.from(point).toString('hex')));
716
+ if (typeof (result) == 'string') {
717
+ return Buffer.from(result, 'hex');
718
+ }
719
+ else {
720
+ throw new BulletproofsError(result.error);
721
+ }
722
+ }
723
+ function BulletproofsScalarInverse(scalar) {
724
+ const result = JSON.parse(js_scalar_inverse(Buffer.from(scalar).toString('hex')));
725
+ if (typeof (result) == 'string') {
726
+ return Buffer.from(result, 'hex');
727
+ }
728
+ else {
729
+ throw new BulletproofsError(result.error);
730
+ }
731
+ }
732
+ function BulletproofsScalarSubtraction(lhs, rhs) {
733
+ const result = JSON.parse(js_scalar_subtraction(Buffer.from(lhs).toString('hex'), Buffer.from(rhs).toString('hex')));
734
+ if (typeof (result) == 'string') {
735
+ return Buffer.from(result, 'hex');
736
+ }
737
+ else {
738
+ throw new BulletproofsError(result.error);
739
+ }
740
+ }
741
+ function BulletproofsScalarMultHashToScalar(scalar, point) {
742
+ const result = JSON.parse(js_scalar_mult_hash_to_scalar(Buffer.from(scalar).toString('hex'), Buffer.from(point).toString('hex')));
743
+ if (typeof (result) == 'string') {
744
+ return Buffer.from(result, 'hex');
745
+ }
746
+ else {
747
+ throw new BulletproofsError(result.error);
748
+ }
749
+ }
750
+ function BulletproofsHashToScalar(input) {
751
+ const result = JSON.parse(js_hash_to_scalar(Buffer.from(input).toString('hex')));
752
+ if (typeof (result) == 'string') {
753
+ return Buffer.from(result, 'hex');
754
+ }
755
+ else {
756
+ throw new BulletproofsError(result.error);
757
+ }
758
+ }
759
+ function BulletproofsPointAddition(lhs, rhs) {
760
+ const result = JSON.parse(js_point_addition(Buffer.from(lhs).toString('hex'), Buffer.from(rhs).toString('hex')));
761
+ if (typeof (result) == 'string') {
762
+ return Buffer.from(result, 'hex');
763
+ }
764
+ else {
765
+ throw new BulletproofsError(result.error);
766
+ }
767
+ }
768
+ function BulletproofsPointSubtraction(lhs, rhs) {
769
+ const result = JSON.parse(js_point_subtraction(Buffer.from(lhs).toString('hex'), Buffer.from(rhs).toString('hex')));
770
+ if (typeof (result) == 'string') {
771
+ return Buffer.from(result, 'hex');
772
+ }
773
+ else {
774
+ throw new BulletproofsError(result.error);
775
+ }
776
+ }
777
+ function BulletproofsSignHidden(x, t, a, r) {
778
+ const result = JSON.parse(js_sign_hidden(Buffer.from(x).toString('hex'), Buffer.from(t).toString('hex'), Buffer.from(a).toString('hex'), Buffer.from(r).toString('hex')));
779
+ if (typeof (result) == 'object') {
780
+ if (result.c && result.s1 && result.s2 && result.s3) {
781
+ return {
782
+ c: Buffer.from(result.c, 'hex'),
783
+ s1: Buffer.from(result.s1, 'hex'),
784
+ s2: Buffer.from(result.s2, 'hex'),
785
+ s3: Buffer.from(result.s3, 'hex'),
786
+ };
787
+ }
788
+ }
789
+ throw new BulletproofsError(result.error || "unknown response");
790
+ }
791
+ function BulletproofsSignSimple(secret, message) {
792
+ const result = JSON.parse(js_sign_simple(Buffer.from(secret).toString('hex'), Buffer.from(message).toString('hex')));
793
+ if (typeof (result) == 'string') {
794
+ return Buffer.from(result, 'hex');
795
+ }
796
+ else {
797
+ throw new BulletproofsError(result.error);
798
+ }
799
+ }
800
+ function BulletproofsVerifySimple(message, signature, publicKey) {
801
+ const result = JSON.parse(js_verify_simple(Buffer.from(message).toString('hex'), Buffer.from(signature).toString('hex'), Buffer.from(publicKey).toString('hex')));
802
+ if (typeof (result) == 'boolean') {
803
+ return result;
804
+ }
805
+ else {
806
+ throw new BulletproofsError(result.error);
807
+ }
808
+ }
809
+ function BulletproofsVerifyHidden(c, t, s1, s2, s3, pPoint, cPoint) {
810
+ const result = JSON.parse(js_verify_hidden(Buffer.from(c).toString('hex'), Buffer.from(t).toString('hex'), Buffer.from(s1).toString('hex'), Buffer.from(s2).toString('hex'), Buffer.from(s3).toString('hex'), Buffer.from(pPoint).toString('hex'), Buffer.from(cPoint).toString('hex')));
811
+ if (typeof (result) == 'boolean') {
812
+ return result;
813
+ }
814
+ else {
815
+ throw new BulletproofsError(result.error);
816
+ }
817
+ }
818
+
819
+ var bulletproofs = /*#__PURE__*/Object.freeze({
820
+ __proto__: null,
821
+ BulletproofsAltGenerator: BulletproofsAltGenerator,
822
+ BulletproofsGenerateInputCommitments: BulletproofsGenerateInputCommitments,
823
+ BulletproofsGenerateRangeProof: BulletproofsGenerateRangeProof,
824
+ BulletproofsHashToScalar: BulletproofsHashToScalar,
825
+ BulletproofsKeygen: BulletproofsKeygen,
826
+ BulletproofsPointAddition: BulletproofsPointAddition,
827
+ BulletproofsPointSubtraction: BulletproofsPointSubtraction,
828
+ BulletproofsScalarAddition: BulletproofsScalarAddition,
829
+ BulletproofsScalarInverse: BulletproofsScalarInverse,
830
+ BulletproofsScalarMult: BulletproofsScalarMult,
831
+ BulletproofsScalarMultHashToScalar: BulletproofsScalarMultHashToScalar,
832
+ BulletproofsScalarMultPoint: BulletproofsScalarMultPoint,
833
+ BulletproofsScalarSubtraction: BulletproofsScalarSubtraction,
834
+ BulletproofsScalarToPoint: BulletproofsScalarToPoint,
835
+ BulletproofsSignHidden: BulletproofsSignHidden,
836
+ BulletproofsSignSimple: BulletproofsSignSimple,
837
+ BulletproofsSumCheck: BulletproofsSumCheck,
838
+ BulletproofsVerifyHidden: BulletproofsVerifyHidden,
839
+ BulletproofsVerifyRangeProof: BulletproofsVerifyRangeProof,
840
+ BulletproofsVerifySimple: BulletproofsVerifySimple
841
+ });
842
+
843
+ window.Buffer = buffer.Buffer;
844
+
845
+ exports.verenc = bulletproofs;