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@returns{WasmNoiseSession}121122 static kkResponder(local_private_key, local_public_key, remote_public_key) {123 try {124 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);125 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);126 const len0 = WASM_VECTOR_LEN;127 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);128 const len1 = WASM_VECTOR_LEN;129 const ptr2 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);130 const len2 = WASM_VECTOR_LEN;131 wasm.wasmnoisesession_kkResponder(retptr, ptr0, len0, ptr1, len1, ptr2, len2);132 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);133 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);134 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);135 if (r2) {136 throw takeObject(r1);137 }138 return WasmNoiseSession.__wrap(r0);139 } finally {140 wasm.__wbindgen_add_to_stack_pointer(16);141 }142 }143 144@param{Uint8Array}145@returns{WasmNoiseSession}146147 static nkInitiator(remote_public_key) {148 try {149 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);150 const ptr0 = passArray8ToWasm0(remote_public_key, wasm.__wbindgen_export2);151 const len0 = WASM_VECTOR_LEN;152 wasm.wasmnoisesession_nkInitiator(retptr, ptr0, len0);153 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);154 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);155 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);156 if (r2) {157 throw takeObject(r1);158 }159 return WasmNoiseSession.__wrap(r0);160 } finally {161 wasm.__wbindgen_add_to_stack_pointer(16);162 }163 }164 165@param{Uint8Array}166@param{Uint8Array}167@returns{WasmNoiseSession}168169 static nkResponder(local_private_key, local_public_key) {170 try {171 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);172 const ptr0 = passArray8ToWasm0(local_private_key, wasm.__wbindgen_export2);173 const len0 = WASM_VECTOR_LEN;174 const ptr1 = passArray8ToWasm0(local_public_key, wasm.__wbindgen_export2);175 const len1 = WASM_VECTOR_LEN;176 wasm.wasmnoisesession_nkResponder(retptr, ptr0, len0, ptr1, len1);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 WasmNoiseSession.__wrap(r0);184 } finally {185 wasm.__wbindgen_add_to_stack_pointer(16);186 }187 }188 189@param{Uint8Array}190@returns{Uint8Array}191192 readHandshake(message) {193 try {194 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);195 const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_export2);196 const len0 = WASM_VECTOR_LEN;197 wasm.wasmnoisesession_readHandshake(retptr, this.__wbg_ptr, ptr0, len0);198 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);199 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);200 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);201 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);202 if (r3) {203 throw takeObject(r2);204 }205 var v2 = getArrayU8FromWasm0(r0, r1).slice();206 wasm.__wbindgen_export3(r0, r1 * 1, 1);207 return v2;208 } finally {209 wasm.__wbindgen_add_to_stack_pointer(16);210 }211 }212 rekeyIncoming() {213 try {214 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);215 wasm.wasmnoisesession_rekeyIncoming(retptr, this.__wbg_ptr);216 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);217 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);218 if (r1) {219 throw takeObject(r0);220 }221 } finally {222 wasm.__wbindgen_add_to_stack_pointer(16);223 }224 }225 rekeyOutgoing() {226 try {227 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);228 wasm.wasmnoisesession_rekeyOutgoing(retptr, this.__wbg_ptr);229 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);230 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);231 if (r1) {232 throw takeObject(r0);233 }234 } finally {235 wasm.__wbindgen_add_to_stack_pointer(16);236 }237 }238 239@param{Uint8Array}240@returns{Uint8Array}241242 writeHandshake(payload) {243 try {244 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);245 const ptr0 = passArray8ToWasm0(payload, wasm.__wbindgen_export2);246 const len0 = WASM_VECTOR_LEN;247 wasm.wasmnoisesession_writeHandshake(retptr, this.__wbg_ptr, ptr0, len0);248 var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);249 var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);250 var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);251 var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);252 if (r3) {253 throw takeObject(r2);254 }255 var v2 = getArrayU8FromWasm0(r0, r1).slice();256 wasm.__wbindgen_export3(r0, r1 * 1, 1);257 return v2;258 } finally {259 wasm.__wbindgen_add_to_stack_pointer(16);260 }261 }262}263if (Symbol.dispose) WasmNoiseSession.prototype[Symbol.dispose] = WasmNoiseSession.prototype.free;264function __wbg_get_imports() {265 const import0 = {266 __proto__: null,267 __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {268 const ret = Error(getStringFromWasm0(arg0, arg1));269 return addHeapObject(ret);270 },271 __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {272 throw new Error(getStringFromWasm0(arg0, arg1));273 },274 __wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {275 globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));276 }, arguments); },277 __wbindgen_object_drop_ref: function(arg0) {278 takeObject(arg0);279 },280 };281 return {282 __proto__: null,283 "./peach_noise_core_bg.js": import0,284 };285}286287const WasmNoiseSessionFinalization = (typeof FinalizationRegistry === 'undefined')288 ? { register: () => {}, unregister: () => {} }289 : new FinalizationRegistry(ptr => wasm.__wbg_wasmnoisesession_free(ptr, 1));290291function addHeapObject(obj) {292 if (heap_next === heap.length) heap.push(heap.length + 1);293 const idx = heap_next;294 heap_next = heap[idx];295296 heap[idx] = obj;297 return idx;298}299300function dropObject(idx) {301 if (idx < 1028) return;302 heap[idx] = heap_next;303 heap_next = idx;304}305306function getArrayU8FromWasm0(ptr, len) {307 ptr = ptr >>> 0;308 return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);309}310311let cachedDataViewMemory0 = null;312function getDataViewMemory0() {313 if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {314 cachedDataViewMemory0 = new DataView(wasm.memory.buffer);315 }316 return cachedDataViewMemory0;317}318319function getStringFromWasm0(ptr, len) {320 return decodeText(ptr >>> 0, len);321}322323let cachedUint8ArrayMemory0 = null;324function getUint8ArrayMemory0() {325 if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {326 cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);327 }328 return cachedUint8ArrayMemory0;329}330331function getObject(idx) { return heap[idx]; }332333function handleError(f, args) {334 try {335 return f.apply(this, args);336 } catch (e) {337 wasm.__wbindgen_export(addHeapObject(e));338 }339}340341let heap = new Array(1024).fill(undefined);342heap.push(undefined, null, true, false);343344let heap_next = heap.length;345346function passArray8ToWasm0(arg, malloc) {347 const ptr = malloc(arg.length * 1, 1) >>> 0;348 getUint8ArrayMemory0().set(arg, ptr / 1);349 WASM_VECTOR_LEN = arg.length;350 return ptr;351}352353function takeObject(idx) {354 const ret = getObject(idx);355 dropObject(idx);356 return ret;357}358359let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });360cachedTextDecoder.decode();361const MAX_SAFARI_DECODE_BYTES = 2146435072;362let numBytesDecoded = 0;363function decodeText(ptr, len) {364 numBytesDecoded += len;365 if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {366 cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });367 cachedTextDecoder.decode();368 numBytesDecoded = len;369 }370 return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));371}372373let WASM_VECTOR_LEN = 0;374375let wasmModule, wasmInstance, wasm;376function __wbg_finalize_init(instance, module) {377 wasmInstance = instance;378 wasm = instance.exports;379 wasmModule = module;380 cachedDataViewMemory0 = null;381 cachedUint8ArrayMemory0 = null;382 return wasm;383}384385async function __wbg_load(module, imports) {386 if (typeof Response === 'function' && module instanceof Response) {387 if (typeof WebAssembly.instantiateStreaming === 'function') {388 try {389 return await WebAssembly.instantiateStreaming(module, imports);390 } catch (e) {391 const validResponse = module.ok && expectedResponseType(module.type);392393 if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {394 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);395396 } else { throw e; }397 }398 }399400 const bytes = await module.arrayBuffer();401 return await WebAssembly.instantiate(bytes, imports);402 } else {403 const instance = await WebAssembly.instantiate(module, imports);404405 if (instance instanceof WebAssembly.Instance) {406 return { instance, module };407 } else {408 return instance;409 }410 }411412 function expectedResponseType(type) {413 switch (type) {414 case 'basic': case 'cors': case 'default': return true;415 }416 return false;417 }418}419420function initSync(module) {421 if (wasm !== undefined) return wasm;422423424 if (module !== undefined) {425 if (Object.getPrototypeOf(module) === Object.prototype) {426 ({module} = module)427 } else {428 console.warn('using deprecated parameters for `initSync()`; pass a single object instead')429 }430 }431432 const imports = __wbg_get_imports();433 if (!(module instanceof WebAssembly.Module)) {434 module = new WebAssembly.Module(module);435 }436 const instance = new WebAssembly.Instance(module, imports);437 return __wbg_finalize_init(instance, module);438}439440async function __wbg_init(module_or_path) {441 if (wasm !== undefined) return wasm;442443444 if (module_or_path !== undefined) {445 if (Object.getPrototypeOf(module_or_path) === Object.prototype) {446 ({module_or_path} = module_or_path)447 } else {448 console.warn('using deprecated parameters for the initialization function; pass a single object instead')449 }450 }451452 if (module_or_path === undefined) {453 module_or_path = new URL('peach_noise_core_bg.wasm', import.meta.url);454 }455 const imports = __wbg_get_imports();456457 if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {458 module_or_path = fetch(module_or_path);459 }460461 const { instance, module } = await __wbg_load(await module_or_path, imports);462463 return __wbg_finalize_init(instance, module);464}465466export { initSync, __wbg_init as default };