@lib-q/core 0.0.1 → 0.0.5
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 +15 -83
- package/integrity-manifest.json +6 -0
- package/nodejs/README.md +329 -0
- package/nodejs/libq.d.ts +810 -0
- package/nodejs/libq.js +2455 -0
- package/nodejs/libq_bg.wasm +0 -0
- package/nodejs/libq_bg.wasm.d.ts +123 -0
- package/nodejs/package.json +21 -0
- package/package.json +23 -12
- package/web/README.md +329 -0
- package/web/libq.d.ts +958 -0
- package/web/libq.js +2487 -0
- package/web/libq_bg.wasm +0 -0
- package/web/libq_bg.wasm.d.ts +123 -0
- package/web/package.json +25 -0
- package/.gitignore +0 -1
- package/LICENSE +0 -201
- package/libq.d.ts +0 -145
- package/libq.js +0 -801
- package/libq_bg.wasm +0 -0
- package/libq_bg.wasm.d.ts +0 -37
package/libq.js
DELETED
|
@@ -1,801 +0,0 @@
|
|
|
1
|
-
let wasm;
|
|
2
|
-
|
|
3
|
-
const heap = new Array(128).fill(undefined);
|
|
4
|
-
|
|
5
|
-
heap.push(undefined, null, true, false);
|
|
6
|
-
|
|
7
|
-
function getObject(idx) { return heap[idx]; }
|
|
8
|
-
|
|
9
|
-
let heap_next = heap.length;
|
|
10
|
-
|
|
11
|
-
function addHeapObject(obj) {
|
|
12
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
13
|
-
const idx = heap_next;
|
|
14
|
-
heap_next = heap[idx];
|
|
15
|
-
|
|
16
|
-
heap[idx] = obj;
|
|
17
|
-
return idx;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let cachedUint8ArrayMemory0 = null;
|
|
21
|
-
|
|
22
|
-
function getUint8ArrayMemory0() {
|
|
23
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
24
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
25
|
-
}
|
|
26
|
-
return cachedUint8ArrayMemory0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
30
|
-
ptr = ptr >>> 0;
|
|
31
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function handleError(f, args) {
|
|
35
|
-
try {
|
|
36
|
-
return f.apply(this, args);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
wasm.__wbindgen_export_0(addHeapObject(e));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function dropObject(idx) {
|
|
43
|
-
if (idx < 132) return;
|
|
44
|
-
heap[idx] = heap_next;
|
|
45
|
-
heap_next = idx;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function takeObject(idx) {
|
|
49
|
-
const ret = getObject(idx);
|
|
50
|
-
dropObject(idx);
|
|
51
|
-
return ret;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
55
|
-
|
|
56
|
-
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
57
|
-
|
|
58
|
-
function getStringFromWasm0(ptr, len) {
|
|
59
|
-
ptr = ptr >>> 0;
|
|
60
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let WASM_VECTOR_LEN = 0;
|
|
64
|
-
|
|
65
|
-
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
66
|
-
|
|
67
|
-
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
68
|
-
? function (arg, view) {
|
|
69
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
70
|
-
}
|
|
71
|
-
: function (arg, view) {
|
|
72
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
73
|
-
view.set(buf);
|
|
74
|
-
return {
|
|
75
|
-
read: arg.length,
|
|
76
|
-
written: buf.length
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
81
|
-
|
|
82
|
-
if (realloc === undefined) {
|
|
83
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
84
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
85
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
86
|
-
WASM_VECTOR_LEN = buf.length;
|
|
87
|
-
return ptr;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let len = arg.length;
|
|
91
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
92
|
-
|
|
93
|
-
const mem = getUint8ArrayMemory0();
|
|
94
|
-
|
|
95
|
-
let offset = 0;
|
|
96
|
-
|
|
97
|
-
for (; offset < len; offset++) {
|
|
98
|
-
const code = arg.charCodeAt(offset);
|
|
99
|
-
if (code > 0x7F) break;
|
|
100
|
-
mem[ptr + offset] = code;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (offset !== len) {
|
|
104
|
-
if (offset !== 0) {
|
|
105
|
-
arg = arg.slice(offset);
|
|
106
|
-
}
|
|
107
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
108
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
109
|
-
const ret = encodeString(arg, view);
|
|
110
|
-
|
|
111
|
-
offset += ret.written;
|
|
112
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
WASM_VECTOR_LEN = offset;
|
|
116
|
-
return ptr;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
let cachedDataViewMemory0 = null;
|
|
120
|
-
|
|
121
|
-
function getDataViewMemory0() {
|
|
122
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
123
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
124
|
-
}
|
|
125
|
-
return cachedDataViewMemory0;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
let stack_pointer = 128;
|
|
129
|
-
|
|
130
|
-
function addBorrowedObject(obj) {
|
|
131
|
-
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
132
|
-
heap[--stack_pointer] = obj;
|
|
133
|
-
return stack_pointer;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @returns {string}
|
|
137
|
-
*/
|
|
138
|
-
export function libq_version_standalone() {
|
|
139
|
-
let deferred1_0;
|
|
140
|
-
let deferred1_1;
|
|
141
|
-
try {
|
|
142
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
143
|
-
wasm.libq_version_standalone(retptr);
|
|
144
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
145
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
146
|
-
deferred1_0 = r0;
|
|
147
|
-
deferred1_1 = r1;
|
|
148
|
-
return getStringFromWasm0(r0, r1);
|
|
149
|
-
} finally {
|
|
150
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
151
|
-
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function libq_init_standalone() {
|
|
156
|
-
try {
|
|
157
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
158
|
-
wasm.libq_init_standalone(retptr);
|
|
159
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
160
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
161
|
-
if (r1) {
|
|
162
|
-
throw takeObject(r0);
|
|
163
|
-
}
|
|
164
|
-
} finally {
|
|
165
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* @param {number} length
|
|
171
|
-
* @returns {Uint8Array}
|
|
172
|
-
*/
|
|
173
|
-
export function libq_random_bytes_standalone(length) {
|
|
174
|
-
try {
|
|
175
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
176
|
-
wasm.libq_random_bytes_standalone(retptr, length);
|
|
177
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
178
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
179
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
180
|
-
if (r2) {
|
|
181
|
-
throw takeObject(r1);
|
|
182
|
-
}
|
|
183
|
-
return takeObject(r0);
|
|
184
|
-
} finally {
|
|
185
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @param {Uint8Array} bytes
|
|
191
|
-
* @returns {string}
|
|
192
|
-
*/
|
|
193
|
-
export function libq_bytes_to_hex_standalone(bytes) {
|
|
194
|
-
let deferred1_0;
|
|
195
|
-
let deferred1_1;
|
|
196
|
-
try {
|
|
197
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
198
|
-
wasm.libq_bytes_to_hex_standalone(retptr, addBorrowedObject(bytes));
|
|
199
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
200
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
201
|
-
deferred1_0 = r0;
|
|
202
|
-
deferred1_1 = r1;
|
|
203
|
-
return getStringFromWasm0(r0, r1);
|
|
204
|
-
} finally {
|
|
205
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
206
|
-
heap[stack_pointer++] = undefined;
|
|
207
|
-
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* @param {string} hex
|
|
213
|
-
* @returns {Uint8Array}
|
|
214
|
-
*/
|
|
215
|
-
export function libq_hex_to_bytes_standalone(hex) {
|
|
216
|
-
try {
|
|
217
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
218
|
-
const ptr0 = passStringToWasm0(hex, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
219
|
-
const len0 = WASM_VECTOR_LEN;
|
|
220
|
-
wasm.libq_hex_to_bytes_standalone(retptr, ptr0, len0);
|
|
221
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
222
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
223
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
224
|
-
if (r2) {
|
|
225
|
-
throw takeObject(r1);
|
|
226
|
-
}
|
|
227
|
-
return takeObject(r0);
|
|
228
|
-
} finally {
|
|
229
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const HashResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
234
|
-
? { register: () => {}, unregister: () => {} }
|
|
235
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_hashresultwasm_free(ptr >>> 0, 1));
|
|
236
|
-
/**
|
|
237
|
-
* WASM-compatible hash result
|
|
238
|
-
*/
|
|
239
|
-
export class HashResultWasm {
|
|
240
|
-
|
|
241
|
-
static __wrap(ptr) {
|
|
242
|
-
ptr = ptr >>> 0;
|
|
243
|
-
const obj = Object.create(HashResultWasm.prototype);
|
|
244
|
-
obj.__wbg_ptr = ptr;
|
|
245
|
-
HashResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
246
|
-
return obj;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
__destroy_into_raw() {
|
|
250
|
-
const ptr = this.__wbg_ptr;
|
|
251
|
-
this.__wbg_ptr = 0;
|
|
252
|
-
HashResultWasmFinalization.unregister(this);
|
|
253
|
-
return ptr;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
free() {
|
|
257
|
-
const ptr = this.__destroy_into_raw();
|
|
258
|
-
wasm.__wbg_hashresultwasm_free(ptr, 0);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* @param {Uint8Array} hash
|
|
262
|
-
* @param {string} algorithm
|
|
263
|
-
*/
|
|
264
|
-
constructor(hash, algorithm) {
|
|
265
|
-
const ptr0 = passStringToWasm0(algorithm, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
266
|
-
const len0 = WASM_VECTOR_LEN;
|
|
267
|
-
const ret = wasm.hashresultwasm_new(addHeapObject(hash), ptr0, len0);
|
|
268
|
-
this.__wbg_ptr = ret >>> 0;
|
|
269
|
-
HashResultWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
270
|
-
return this;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* @returns {Uint8Array}
|
|
274
|
-
*/
|
|
275
|
-
get hash() {
|
|
276
|
-
const ret = wasm.hashresultwasm_hash(this.__wbg_ptr);
|
|
277
|
-
return takeObject(ret);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* @returns {string}
|
|
281
|
-
*/
|
|
282
|
-
get algorithm() {
|
|
283
|
-
let deferred1_0;
|
|
284
|
-
let deferred1_1;
|
|
285
|
-
try {
|
|
286
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
287
|
-
wasm.hashresultwasm_algorithm(retptr, this.__wbg_ptr);
|
|
288
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
289
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
290
|
-
deferred1_0 = r0;
|
|
291
|
-
deferred1_1 = r1;
|
|
292
|
-
return getStringFromWasm0(r0, r1);
|
|
293
|
-
} finally {
|
|
294
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
295
|
-
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const KemKeyPairWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
301
|
-
? { register: () => {}, unregister: () => {} }
|
|
302
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_kemkeypairwasm_free(ptr >>> 0, 1));
|
|
303
|
-
/**
|
|
304
|
-
* WASM-compatible key pair for KEM operations
|
|
305
|
-
*/
|
|
306
|
-
export class KemKeyPairWasm {
|
|
307
|
-
|
|
308
|
-
static __wrap(ptr) {
|
|
309
|
-
ptr = ptr >>> 0;
|
|
310
|
-
const obj = Object.create(KemKeyPairWasm.prototype);
|
|
311
|
-
obj.__wbg_ptr = ptr;
|
|
312
|
-
KemKeyPairWasmFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
313
|
-
return obj;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
__destroy_into_raw() {
|
|
317
|
-
const ptr = this.__wbg_ptr;
|
|
318
|
-
this.__wbg_ptr = 0;
|
|
319
|
-
KemKeyPairWasmFinalization.unregister(this);
|
|
320
|
-
return ptr;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
free() {
|
|
324
|
-
const ptr = this.__destroy_into_raw();
|
|
325
|
-
wasm.__wbg_kemkeypairwasm_free(ptr, 0);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* @param {Uint8Array} public_key
|
|
329
|
-
* @param {Uint8Array} secret_key
|
|
330
|
-
*/
|
|
331
|
-
constructor(public_key, secret_key) {
|
|
332
|
-
const ret = wasm.kemkeypairwasm_new(addHeapObject(public_key), addHeapObject(secret_key));
|
|
333
|
-
this.__wbg_ptr = ret >>> 0;
|
|
334
|
-
KemKeyPairWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
335
|
-
return this;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* @returns {Uint8Array}
|
|
339
|
-
*/
|
|
340
|
-
get public_key() {
|
|
341
|
-
const ret = wasm.kemkeypairwasm_public_key(this.__wbg_ptr);
|
|
342
|
-
return takeObject(ret);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* @returns {Uint8Array}
|
|
346
|
-
*/
|
|
347
|
-
get secret_key() {
|
|
348
|
-
const ret = wasm.kemkeypairwasm_secret_key(this.__wbg_ptr);
|
|
349
|
-
return takeObject(ret);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const LibQFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
354
|
-
? { register: () => {}, unregister: () => {} }
|
|
355
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_libq_free(ptr >>> 0, 1));
|
|
356
|
-
/**
|
|
357
|
-
* Main WASM API for lib-Q
|
|
358
|
-
*/
|
|
359
|
-
export class LibQ {
|
|
360
|
-
|
|
361
|
-
__destroy_into_raw() {
|
|
362
|
-
const ptr = this.__wbg_ptr;
|
|
363
|
-
this.__wbg_ptr = 0;
|
|
364
|
-
LibQFinalization.unregister(this);
|
|
365
|
-
return ptr;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
free() {
|
|
369
|
-
const ptr = this.__destroy_into_raw();
|
|
370
|
-
wasm.__wbg_libq_free(ptr, 0);
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Create a new LibQ instance
|
|
374
|
-
*/
|
|
375
|
-
constructor() {
|
|
376
|
-
const ret = wasm.libq_new();
|
|
377
|
-
this.__wbg_ptr = ret >>> 0;
|
|
378
|
-
LibQFinalization.register(this, this.__wbg_ptr, this);
|
|
379
|
-
return this;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Initialize the library
|
|
383
|
-
*/
|
|
384
|
-
init() {
|
|
385
|
-
try {
|
|
386
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
387
|
-
wasm.libq_init(retptr, this.__wbg_ptr);
|
|
388
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
389
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
390
|
-
if (r1) {
|
|
391
|
-
throw takeObject(r0);
|
|
392
|
-
}
|
|
393
|
-
} finally {
|
|
394
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Get library version
|
|
399
|
-
* @returns {string}
|
|
400
|
-
*/
|
|
401
|
-
version() {
|
|
402
|
-
let deferred1_0;
|
|
403
|
-
let deferred1_1;
|
|
404
|
-
try {
|
|
405
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
406
|
-
wasm.libq_version(retptr, this.__wbg_ptr);
|
|
407
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
408
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
409
|
-
deferred1_0 = r0;
|
|
410
|
-
deferred1_1 = r1;
|
|
411
|
-
return getStringFromWasm0(r0, r1);
|
|
412
|
-
} finally {
|
|
413
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
414
|
-
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Generate random bytes
|
|
419
|
-
* @param {number} length
|
|
420
|
-
* @returns {Uint8Array}
|
|
421
|
-
*/
|
|
422
|
-
random_bytes(length) {
|
|
423
|
-
try {
|
|
424
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
425
|
-
wasm.libq_random_bytes(retptr, this.__wbg_ptr, length);
|
|
426
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
427
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
428
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
429
|
-
if (r2) {
|
|
430
|
-
throw takeObject(r1);
|
|
431
|
-
}
|
|
432
|
-
return takeObject(r0);
|
|
433
|
-
} finally {
|
|
434
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Generate a random key
|
|
439
|
-
* @param {number} size
|
|
440
|
-
* @returns {Uint8Array}
|
|
441
|
-
*/
|
|
442
|
-
random_key(size) {
|
|
443
|
-
try {
|
|
444
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
445
|
-
wasm.libq_random_key(retptr, this.__wbg_ptr, size);
|
|
446
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
447
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
448
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
449
|
-
if (r2) {
|
|
450
|
-
throw takeObject(r1);
|
|
451
|
-
}
|
|
452
|
-
return takeObject(r0);
|
|
453
|
-
} finally {
|
|
454
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Convert bytes to hex string
|
|
459
|
-
* @param {Uint8Array} bytes
|
|
460
|
-
* @returns {string}
|
|
461
|
-
*/
|
|
462
|
-
bytes_to_hex(bytes) {
|
|
463
|
-
let deferred1_0;
|
|
464
|
-
let deferred1_1;
|
|
465
|
-
try {
|
|
466
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
467
|
-
wasm.libq_bytes_to_hex(retptr, this.__wbg_ptr, addBorrowedObject(bytes));
|
|
468
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
469
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
470
|
-
deferred1_0 = r0;
|
|
471
|
-
deferred1_1 = r1;
|
|
472
|
-
return getStringFromWasm0(r0, r1);
|
|
473
|
-
} finally {
|
|
474
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
475
|
-
heap[stack_pointer++] = undefined;
|
|
476
|
-
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Convert hex string to bytes
|
|
481
|
-
* @param {string} hex
|
|
482
|
-
* @returns {Uint8Array}
|
|
483
|
-
*/
|
|
484
|
-
hex_to_bytes(hex) {
|
|
485
|
-
try {
|
|
486
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
487
|
-
const ptr0 = passStringToWasm0(hex, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
488
|
-
const len0 = WASM_VECTOR_LEN;
|
|
489
|
-
wasm.libq_hex_to_bytes(retptr, this.__wbg_ptr, ptr0, len0);
|
|
490
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
491
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
492
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
493
|
-
if (r2) {
|
|
494
|
-
throw takeObject(r1);
|
|
495
|
-
}
|
|
496
|
-
return takeObject(r0);
|
|
497
|
-
} finally {
|
|
498
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Hash data using SHAKE256
|
|
503
|
-
* @param {Uint8Array} data
|
|
504
|
-
* @returns {HashResultWasm}
|
|
505
|
-
*/
|
|
506
|
-
hash_shake256(data) {
|
|
507
|
-
try {
|
|
508
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
509
|
-
wasm.libq_hash_shake256(retptr, this.__wbg_ptr, addBorrowedObject(data));
|
|
510
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
511
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
512
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
513
|
-
if (r2) {
|
|
514
|
-
throw takeObject(r1);
|
|
515
|
-
}
|
|
516
|
-
return HashResultWasm.__wrap(r0);
|
|
517
|
-
} finally {
|
|
518
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
519
|
-
heap[stack_pointer++] = undefined;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Generate KEM key pair (placeholder implementation)
|
|
524
|
-
* @param {string} algorithm
|
|
525
|
-
* @param {number} security_level
|
|
526
|
-
* @returns {KemKeyPairWasm}
|
|
527
|
-
*/
|
|
528
|
-
kem_generate_keypair(algorithm, security_level) {
|
|
529
|
-
try {
|
|
530
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
531
|
-
const ptr0 = passStringToWasm0(algorithm, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
532
|
-
const len0 = WASM_VECTOR_LEN;
|
|
533
|
-
wasm.libq_kem_generate_keypair(retptr, this.__wbg_ptr, ptr0, len0, security_level);
|
|
534
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
535
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
536
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
537
|
-
if (r2) {
|
|
538
|
-
throw takeObject(r1);
|
|
539
|
-
}
|
|
540
|
-
return KemKeyPairWasm.__wrap(r0);
|
|
541
|
-
} finally {
|
|
542
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Generate signature key pair (placeholder implementation)
|
|
547
|
-
* @param {string} algorithm
|
|
548
|
-
* @param {number} security_level
|
|
549
|
-
* @returns {SigKeyPairWasm}
|
|
550
|
-
*/
|
|
551
|
-
sig_generate_keypair(algorithm, security_level) {
|
|
552
|
-
try {
|
|
553
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
554
|
-
const ptr0 = passStringToWasm0(algorithm, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
555
|
-
const len0 = WASM_VECTOR_LEN;
|
|
556
|
-
wasm.libq_sig_generate_keypair(retptr, this.__wbg_ptr, ptr0, len0, security_level);
|
|
557
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
558
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
559
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
560
|
-
if (r2) {
|
|
561
|
-
throw takeObject(r1);
|
|
562
|
-
}
|
|
563
|
-
return SigKeyPairWasm.__wrap(r0);
|
|
564
|
-
} finally {
|
|
565
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Get supported algorithms
|
|
570
|
-
* @returns {object}
|
|
571
|
-
*/
|
|
572
|
-
get_supported_algorithms() {
|
|
573
|
-
const ret = wasm.libq_get_supported_algorithms(this.__wbg_ptr);
|
|
574
|
-
return takeObject(ret);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const SigKeyPairWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
579
|
-
? { register: () => {}, unregister: () => {} }
|
|
580
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_sigkeypairwasm_free(ptr >>> 0, 1));
|
|
581
|
-
/**
|
|
582
|
-
* WASM-compatible key pair for signature operations
|
|
583
|
-
*/
|
|
584
|
-
export class SigKeyPairWasm {
|
|
585
|
-
|
|
586
|
-
static __wrap(ptr) {
|
|
587
|
-
ptr = ptr >>> 0;
|
|
588
|
-
const obj = Object.create(SigKeyPairWasm.prototype);
|
|
589
|
-
obj.__wbg_ptr = ptr;
|
|
590
|
-
SigKeyPairWasmFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
591
|
-
return obj;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
__destroy_into_raw() {
|
|
595
|
-
const ptr = this.__wbg_ptr;
|
|
596
|
-
this.__wbg_ptr = 0;
|
|
597
|
-
SigKeyPairWasmFinalization.unregister(this);
|
|
598
|
-
return ptr;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
free() {
|
|
602
|
-
const ptr = this.__destroy_into_raw();
|
|
603
|
-
wasm.__wbg_sigkeypairwasm_free(ptr, 0);
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* @param {Uint8Array} public_key
|
|
607
|
-
* @param {Uint8Array} secret_key
|
|
608
|
-
*/
|
|
609
|
-
constructor(public_key, secret_key) {
|
|
610
|
-
const ret = wasm.kemkeypairwasm_new(addHeapObject(public_key), addHeapObject(secret_key));
|
|
611
|
-
this.__wbg_ptr = ret >>> 0;
|
|
612
|
-
SigKeyPairWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
613
|
-
return this;
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* @returns {Uint8Array}
|
|
617
|
-
*/
|
|
618
|
-
get public_key() {
|
|
619
|
-
const ret = wasm.kemkeypairwasm_public_key(this.__wbg_ptr);
|
|
620
|
-
return takeObject(ret);
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* @returns {Uint8Array}
|
|
624
|
-
*/
|
|
625
|
-
get secret_key() {
|
|
626
|
-
const ret = wasm.kemkeypairwasm_secret_key(this.__wbg_ptr);
|
|
627
|
-
return takeObject(ret);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
async function __wbg_load(module, imports) {
|
|
632
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
633
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
634
|
-
try {
|
|
635
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
636
|
-
|
|
637
|
-
} catch (e) {
|
|
638
|
-
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
639
|
-
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);
|
|
640
|
-
|
|
641
|
-
} else {
|
|
642
|
-
throw e;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
const bytes = await module.arrayBuffer();
|
|
648
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
649
|
-
|
|
650
|
-
} else {
|
|
651
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
652
|
-
|
|
653
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
654
|
-
return { instance, module };
|
|
655
|
-
|
|
656
|
-
} else {
|
|
657
|
-
return instance;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
function __wbg_get_imports() {
|
|
663
|
-
const imports = {};
|
|
664
|
-
imports.wbg = {};
|
|
665
|
-
imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
|
666
|
-
const ret = getObject(arg0).buffer;
|
|
667
|
-
return addHeapObject(ret);
|
|
668
|
-
};
|
|
669
|
-
imports.wbg.__wbg_getRandomValues_3c9c0d586e575a16 = function() { return handleError(function (arg0, arg1) {
|
|
670
|
-
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
671
|
-
}, arguments) };
|
|
672
|
-
imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
|
|
673
|
-
const ret = getObject(arg0).length;
|
|
674
|
-
return ret;
|
|
675
|
-
};
|
|
676
|
-
imports.wbg.__wbg_log_c222819a41e063d3 = function(arg0) {
|
|
677
|
-
console.log(getObject(arg0));
|
|
678
|
-
};
|
|
679
|
-
imports.wbg.__wbg_new_405e22f390576ce2 = function() {
|
|
680
|
-
const ret = new Object();
|
|
681
|
-
return addHeapObject(ret);
|
|
682
|
-
};
|
|
683
|
-
imports.wbg.__wbg_new_78feb108b6472713 = function() {
|
|
684
|
-
const ret = new Array();
|
|
685
|
-
return addHeapObject(ret);
|
|
686
|
-
};
|
|
687
|
-
imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
|
|
688
|
-
const ret = new Uint8Array(getObject(arg0));
|
|
689
|
-
return addHeapObject(ret);
|
|
690
|
-
};
|
|
691
|
-
imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
|
|
692
|
-
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
693
|
-
return addHeapObject(ret);
|
|
694
|
-
};
|
|
695
|
-
imports.wbg.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
|
|
696
|
-
const ret = getObject(arg0).push(getObject(arg1));
|
|
697
|
-
return ret;
|
|
698
|
-
};
|
|
699
|
-
imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
|
|
700
|
-
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
|
701
|
-
};
|
|
702
|
-
imports.wbg.__wbg_set_bb8cecf6a62b9f46 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
703
|
-
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
704
|
-
return ret;
|
|
705
|
-
}, arguments) };
|
|
706
|
-
imports.wbg.__wbindgen_memory = function() {
|
|
707
|
-
const ret = wasm.memory;
|
|
708
|
-
return addHeapObject(ret);
|
|
709
|
-
};
|
|
710
|
-
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
711
|
-
const ret = arg0;
|
|
712
|
-
return addHeapObject(ret);
|
|
713
|
-
};
|
|
714
|
-
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
715
|
-
const ret = getObject(arg0);
|
|
716
|
-
return addHeapObject(ret);
|
|
717
|
-
};
|
|
718
|
-
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
719
|
-
takeObject(arg0);
|
|
720
|
-
};
|
|
721
|
-
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
722
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
723
|
-
return addHeapObject(ret);
|
|
724
|
-
};
|
|
725
|
-
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
726
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
return imports;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
function __wbg_init_memory(imports, memory) {
|
|
733
|
-
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
function __wbg_finalize_init(instance, module) {
|
|
737
|
-
wasm = instance.exports;
|
|
738
|
-
__wbg_init.__wbindgen_wasm_module = module;
|
|
739
|
-
cachedDataViewMemory0 = null;
|
|
740
|
-
cachedUint8ArrayMemory0 = null;
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
return wasm;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
function initSync(module) {
|
|
748
|
-
if (wasm !== undefined) return wasm;
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
if (typeof module !== 'undefined') {
|
|
752
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
753
|
-
({module} = module)
|
|
754
|
-
} else {
|
|
755
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
const imports = __wbg_get_imports();
|
|
760
|
-
|
|
761
|
-
__wbg_init_memory(imports);
|
|
762
|
-
|
|
763
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
764
|
-
module = new WebAssembly.Module(module);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
768
|
-
|
|
769
|
-
return __wbg_finalize_init(instance, module);
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
async function __wbg_init(module_or_path) {
|
|
773
|
-
if (wasm !== undefined) return wasm;
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (typeof module_or_path !== 'undefined') {
|
|
777
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
778
|
-
({module_or_path} = module_or_path)
|
|
779
|
-
} else {
|
|
780
|
-
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
if (typeof module_or_path === 'undefined') {
|
|
785
|
-
module_or_path = new URL('libq_bg.wasm', import.meta.url);
|
|
786
|
-
}
|
|
787
|
-
const imports = __wbg_get_imports();
|
|
788
|
-
|
|
789
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
790
|
-
module_or_path = fetch(module_or_path);
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
__wbg_init_memory(imports);
|
|
794
|
-
|
|
795
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
796
|
-
|
|
797
|
-
return __wbg_finalize_init(instance, module);
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
export { initSync };
|
|
801
|
-
export default __wbg_init;
|