123export class WasmNoiseSession {4 static __wrap(ptr) {5 const obj = Object.create(WasmNoiseSession.prototype);6 obj.__wbg_ptr = ptr;7 WasmNoiseSessionFinalization.register(obj, obj.__wbg_ptr, obj);8 return obj;9 }10 __destroy_into_raw() {11 const ptr = this.__wbg_ptr;12 this.__wbg_ptr = 0;13 WasmNoiseSessionFinalization.unregister(this);14 return ptr;15 }16 free() {17 const ptr = this.__destroy_into_raw();18 wasm.__wbg_wasmnoisesession_free(ptr, 0);19 }20 21@param{Uint8Array}22@returns{Uint8Array}2324 decrypt(ciphertext) {25 try {26 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);27 const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_export2);28 const len0 = WASM_VECTOR_LEN;29 wasm.wasmnoisesession_decrypt(retptr, this.__wbg_ptr, ptr0, len0);30 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);31 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);32 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);33 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);34 if (r3) {35 throw takeObject(r2);36 }37 var v2 = getArrayU8FromWasm0(r0, r1).slice();38 wasm.__wbindgen_export3(r0, r1 * 1, 1);39 return v2;40 } finally {41 wasm.__wbindgen_add_to_stack_pointer(16);42 }43 }44 45@param{Uint8Array}46@returns{Uint8Array}4748 encrypt(plaintext) {49 try {50 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);51 const ptr0 = passArray8ToWasm0(plaintext, wasm.__wbindgen_export2);52 const len0 = WASM_VECTOR_LEN;53 wasm.wasmnoisesession_encrypt(retptr, this.__wbg_ptr, ptr0, len0);54 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);55 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);56 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);57 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);58 if (r3) {59 throw takeObject(r2);60 }61 var v2 = getArrayU8FromWasm0(r0, r1).slice();62 wasm.__wbindgen_export3(r0, r1 * 1, 1);63 return v2;64 } finally {65 wasm.__wbindgen_add_to_stack_pointer(16);66 }67 }68 69@returns{Uint8Array}7071 get handshakeHash() {72 try {73 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);74 wasm.wasmnoisesession_handshakeHash(retptr, this.__wbg_ptr);75 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);76 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);77 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);78 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);79 if (r3) {80 throw takeObject(r2);81 }82 var v1 = getArrayU8FromWasm0(r0, r1).slice();83 wasm.__wbindgen_export3(r0, r1 * 1, 1);84 return v1;85 } finally {86 wasm.__wbindgen_add_to_stack_pointer(16);87 }88 }89 90@param{Uint8Array}91@param{Uint8Array}92@param{Uint8Array}93@returns{WasmNoiseSession}9495 static kkInitiator(local_private_key, local_public_key, remote_public_key) {96 try {97 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);98 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);99 const len0 = WASM_VECTOR_LEN;100 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);101 const len1 = WASM_VECTOR_LEN;102 const ptr2 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);103 const len2 = WASM_VECTOR_LEN;104 wasm.wasmnoisesession_kkInitiator(retptr, ptr0, len0, ptr1, len1, ptr2, len2);105 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);106 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);107 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);108 if (r2) {109 throw takeObject(r1);110 }111 return WasmNoiseSession.__wrap(r0);112 } finally {113 wasm.__wbindgen_add_to_stack_pointer(16);114 }115 }116 117@param{Uint8Array}118@param{Uint8Array}119@param{Uint8Array}120@param{Uint8Array}121@returns{WasmNoiseSession}122123 static kkInitiatorWithEphemeralForTest(local_private_key, local_public_key, remote_public_key, ephemeral_private_key) {124 try {125 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);126 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);127 const len0 = WASM_VECTOR_LEN;128 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);129 const len1 = WASM_VECTOR_LEN;130 const ptr2 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);131 const len2 = WASM_VECTOR_LEN;132 const ptr3 = passArray8ToWasm0(ephemeral_private_key, wasm.__wbindgen_export2);133 const len3 = WASM_VECTOR_LEN;134 wasm.wasmnoisesession_kkInitiatorWithEphemeralForTest(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);135 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);136 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);137 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);138 if (r2) {139 throw takeObject(r1);140 }141 return WasmNoiseSession.__wrap(r0);142 } finally {143 wasm.__wbindgen_add_to_stack_pointer(16);144 }145 }146 147@param{Uint8Array}148@param{Uint8Array}149@param{Uint8Array}150@returns{WasmNoiseSession}151152 static kkResponder(local_private_key, local_public_key, remote_public_key) {153 try {154 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);155 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);156 const len0 = WASM_VECTOR_LEN;157 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);158 const len1 = WASM_VECTOR_LEN;159 const ptr2 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);160 const len2 = WASM_VECTOR_LEN;161 wasm.wasmnoisesession_kkResponder(retptr, ptr0, len0, ptr1, len1, ptr2, len2);162 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);163 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);164 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);165 if (r2) {166 throw takeObject(r1);167 }168 return WasmNoiseSession.__wrap(r0);169 } finally {170 wasm.__wbindgen_add_to_stack_pointer(16);171 }172 }173 174@param{Uint8Array}175@param{Uint8Array}176@param{Uint8Array}177@param{Uint8Array}178@returns{WasmNoiseSession}179180 static kkResponderWithEphemeralForTest(local_private_key, local_public_key, remote_public_key, ephemeral_private_key) {181 try {182 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);183 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);184 const len0 = WASM_VECTOR_LEN;185 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);186 const len1 = WASM_VECTOR_LEN;187 const ptr2 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);188 const len2 = WASM_VECTOR_LEN;189 const ptr3 = passArray8ToWasm0(ephemeral_private_key, wasm.__wbindgen_export2);190 const len3 = WASM_VECTOR_LEN;191 wasm.wasmnoisesession_kkResponderWithEphemeralForTest(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);192 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);193 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);194 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);195 if (r2) {196 throw takeObject(r1);197 }198 return WasmNoiseSession.__wrap(r0);199 } finally {200 wasm.__wbindgen_add_to_stack_pointer(16);201 }202 }203 204@param{Uint8Array}205@returns{WasmNoiseSession}206207 static nkInitiator(remote_public_key) {208 try {209 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);210 const ptr0 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);211 const len0 = WASM_VECTOR_LEN;212 wasm.wasmnoisesession_nkInitiator(retptr, ptr0, len0);213 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);214 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);215 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);216 if (r2) {217 throw takeObject(r1);218 }219 return WasmNoiseSession.__wrap(r0);220 } finally {221 wasm.__wbindgen_add_to_stack_pointer(16);222 }223 }224 225@param{Uint8Array}226@param{Uint8Array}227@returns{WasmNoiseSession}228229 static nkInitiatorWithEphemeralForTest(remote_public_key, ephemeral_private_key) {230 try {231 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);232 const ptr0 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);233 const len0 = WASM_VECTOR_LEN;234 const ptr1 = passArray8ToWasm0(ephemeral_private_key, wasm.__wbindgen_export2);235 const len1 = WASM_VECTOR_LEN;236 wasm.wasmnoisesession_nkInitiatorWithEphemeralForTest(retptr, ptr0, len0, ptr1, len1);237 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);238 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);239 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);240 if (r2) {241 throw takeObject(r1);242 }243 return WasmNoiseSession.__wrap(r0);244 } finally {245 wasm.__wbindgen_add_to_stack_pointer(16);246 }247 }248 249@param{Uint8Array}250@param{Uint8Array}251@returns{WasmNoiseSession}252253 static nkResponder(local_private_key, local_public_key) {254 try {255 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);256 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);257 const len0 = WASM_VECTOR_LEN;258 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);259 const len1 = WASM_VECTOR_LEN;260 wasm.wasmnoisesession_nkResponder(retptr, ptr0, len0, ptr1, len1);261 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);262 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);263 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);264 if (r2) {265 throw takeObject(r1);266 }267 return WasmNoiseSession.__wrap(r0);268 } finally {269 wasm.__wbindgen_add_to_stack_pointer(16);270 }271 }272 273@param{Uint8Array}274@param{Uint8Array}275@param{Uint8Array}276@returns{WasmNoiseSession}277278 static nkResponderWithEphemeralForTest(local_private_key, local_public_key, ephemeral_private_key) {279 try {280 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);281 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);282 const len0 = WASM_VECTOR_LEN;283 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);284 const len1 = WASM_VECTOR_LEN;285 const ptr2 = passArray8ToWasm0(ephemeral_private_key, wasm.__wbindgen_export2);286 const len2 = WASM_VECTOR_LEN;287 wasm.wasmnoisesession_nkResponderWithEphemeralForTest(retptr, ptr0, len0, ptr1, len1, ptr2, len2);288 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);289 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);290 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);291 if (r2) {292 throw takeObject(r1);293 }294 return WasmNoiseSession.__wrap(r0);295 } finally {296 wasm.__wbindgen_add_to_stack_pointer(16);297 }298 }299 300@param{Uint8Array}301@returns{Uint8Array}302303 readHandshake(message) {304 try {305 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);306 const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_export2);307 const len0 = WASM_VECTOR_LEN;308 wasm.wasmnoisesession_readHandshake(retptr, this.__wbg_ptr, ptr0, len0);309 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);310 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);311 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);312 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);313 if (r3) {314 throw takeObject(r2);315 }316 var v2 = getArrayU8FromWasm0(r0, r1).slice();317 wasm.__wbindgen_export3(r0, r1 * 1, 1);318 return v2;319 } finally {320 wasm.__wbindgen_add_to_stack_pointer(16);321 }322 }323 rekeyIncoming() {324 try {325 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);326 wasm.wasmnoisesession_rekeyIncoming(retptr, this.__wbg_ptr);327 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);328 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);329 if (r1) {330 throw takeObject(r0);331 }332 } finally {333 wasm.__wbindgen_add_to_stack_pointer(16);334 }335 }336 rekeyOutgoing() {337 try {338 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);339 wasm.wasmnoisesession_rekeyOutgoing(retptr, this.__wbg_ptr);340 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);341 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);342 if (r1) {343 throw takeObject(r0);344 }345 } finally {346 wasm.__wbindgen_add_to_stack_pointer(16);347 }348 }349 350@param{Uint8Array}351@returns{Uint8Array}352353 writeHandshake(payload) {354 try {355 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);356 const ptr0 = passArray8ToWasm0(payload, wasm.__wbindgen_export2);357 const len0 = WASM_VECTOR_LEN;358 wasm.wasmnoisesession_writeHandshake(retptr, this.__wbg_ptr, ptr0, len0);359 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);360 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);361 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);362 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);363 if (r3) {364 throw takeObject(r2);365 }366 var v2 = getArrayU8FromWasm0(r0, r1).slice();367 wasm.__wbindgen_export3(r0, r1 * 1, 1);368 return v2;369 } finally {370 wasm.__wbindgen_add_to_stack_pointer(16);371 }372 }373}374if (Symbol.dispose) WasmNoiseSession.prototype[Symbol.dispose] = WasmNoiseSession.prototype.free;375function __wbg_get_imports() {376 const import0 = {377 __proto__: null,378 __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {379 const ret = Error(getStringFromWasm0(arg0, arg1));380 return addHeapObject(ret);381 },382 __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {383 throw new Error(getStringFromWasm0(arg0, arg1));384 },385 __wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {386 globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));387 }, arguments); },388 __wbindgen_object_drop_ref: function(arg0) {389 takeObject(arg0);390 },391 };392 return {393 __proto__: null,394 "./peach_noise_core_bg.js": import0,395 };396}397398const WasmNoiseSessionFinalization = (typeof FinalizationRegistry === 'undefined')399 ? { register: () => {}, unregister: () => {} }400 : new FinalizationRegistry(ptr => wasm.__wbg_wasmnoisesession_free(ptr, 1));401402function addHeapObject(obj) {403 if (heap_next === heap.length) heap.push(heap.length + 1);404 const idx = heap_next;405 heap_next = heap[idx];406407 heap[idx] = obj;408 return idx;409}410411function dropObject(idx) {412 if (idx < 1028) return;413 heap[idx] = heap_next;414 heap_next = idx;415}416417function getArrayU8FromWasm0(ptr, len) {418 ptr = ptr >>> 0;419 return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);420}421422let cachedDataViewMemory0 = null;423function getDataViewMemory0() {424 if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {425 cachedDataViewMemory0 = new DataView(wasm.memory.buffer);426 }427 return cachedDataViewMemory0;428}429430function getStringFromWasm0(ptr, len) {431 return decodeText(ptr >>> 0, len);432}433434let cachedUint8ArrayMemory0 = null;435function getUint8ArrayMemory0() {436 if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {437 cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);438 }439 return cachedUint8ArrayMemory0;440}441442function getObject(idx) { return heap[idx]; }443444function handleError(f, args) {445 try {446 return f.apply(this, args);447 } catch (e) {448 wasm.__wbindgen_export(addHeapObject(e));449 }450}451452let heap = new Array(1024).fill(undefined);453heap.push(undefined, null, true, false);454455let heap_next = heap.length;456457function passArray8ToWasm0(arg, malloc) {458 const ptr = malloc(arg.length * 1, 1) >>> 0;459 getUint8ArrayMemory0().set(arg, ptr / 1);460 WASM_VECTOR_LEN = arg.length;461 return ptr;462}463464function takeObject(idx) {465 const ret = getObject(idx);466 dropObject(idx);467 return ret;468}469470let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });471cachedTextDecoder.decode();472const MAX_SAFARI_DECODE_BYTES = 2146435072;473let numBytesDecoded = 0;474function decodeText(ptr, len) {475 numBytesDecoded += len;476 if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {477 cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });478 cachedTextDecoder.decode();479 numBytesDecoded = len;480 }481 return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));482}483484let WASM_VECTOR_LEN = 0;485486let wasmModule, wasmInstance, wasm;487function __wbg_finalize_init(instance, module) {488 wasmInstance = instance;489 wasm = instance.exports;490 wasmModule = module;491 cachedDataViewMemory0 = null;492 cachedUint8ArrayMemory0 = null;493 return wasm;494}495496async function __wbg_load(module, imports) {497 if (typeof Response === 'function' && module instanceof Response) {498 if (typeof WebAssembly.instantiateStreaming === 'function') {499 try {500 return await WebAssembly.instantiateStreaming(module, imports);501 } catch (e) {502 const validResponse = module.ok && expectedResponseType(module.type);503504 if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {505 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);506507 } else { throw e; }508 }509 }510511 const bytes = await module.arrayBuffer();512 return await WebAssembly.instantiate(bytes, imports);513 } else {514 const instance = await WebAssembly.instantiate(module, imports);515516 if (instance instanceof WebAssembly.Instance) {517 return { instance, module };518 } else {519 return instance;520 }521 }522523 function expectedResponseType(type) {524 switch (type) {525 case 'basic': case 'cors': case 'default': return true;526 }527 return false;528 }529}530531function initSync(module) {532 if (wasm !== undefined) return wasm;533534535 if (module !== undefined) {536 if (Object.getPrototypeOf(module) === Object.prototype) {537 ({module} = module)538 } else {539 console.warn('using deprecated parameters for `initSync()`; pass a single object instead')540 }541 }542543 const imports = __wbg_get_imports();544 if (!(module instanceof WebAssembly.Module)) {545 module = new WebAssembly.Module(module);546 }547 const instance = new WebAssembly.Instance(module, imports);548 return __wbg_finalize_init(instance, module);549}550551async function __wbg_init(module_or_path) {552 if (wasm !== undefined) return wasm;553554555 if (module_or_path !== undefined) {556 if (Object.getPrototypeOf(module_or_path) === Object.prototype) {557 ({module_or_path} = module_or_path)558 } else {559 console.warn('using deprecated parameters for the initialization function; pass a single object instead')560 }561 }562563 if (module_or_path === undefined) {564 module_or_path = new URL('peach_noise_core_bg.wasm', import.meta.url);565 }566 const imports = __wbg_get_imports();567568 if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {569 module_or_path = fetch(module_or_path);570 }571572 const { instance, module } = await __wbg_load(await module_or_path, imports);573574 return __wbg_finalize_init(instance, module);575}576577export { initSync, __wbg_init as default };