UNPKG

@onmax_/core

Version:

Nimiq's Rust-to-WASM web client (patched for Cloudflare Workers logging fix)

359 lines (309 loc) 13 kB
let wasm_bindgen; (function() { const __exports = {}; let script_src; if (typeof document !== 'undefined' && document.currentScript !== null) { script_src = new URL(document.currentScript.src, location.href).toString(); } let wasm = undefined; function addToExternrefTable0(obj) { const idx = wasm.__externref_table_alloc(); wasm.__wbindgen_export_2.set(idx, obj); return idx; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { const idx = addToExternrefTable0(e); wasm.__wbindgen_exn_store(idx); } } const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } function isLikeNone(x) { return x === undefined || x === null; } const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(state => { wasm.__wbindgen_export_3.get(state.dtor)(state.a, state.b) }); function makeMutClosure(arg0, arg1, dtor, f) { const state = { a: arg0, b: arg1, cnt: 1, dtor }; const real = (...args) => { // First up with a closure we increment the internal reference // count. This ensures that the Rust closure environment won't // be deallocated while we're invoking it. state.cnt++; const a = state.a; state.a = 0; try { return f(a, state.b, ...args); } finally { if (--state.cnt === 0) { wasm.__wbindgen_export_3.get(state.dtor)(a, state.b); CLOSURE_DTORS.unregister(state); } else { state.a = a; } } }; real.original = state; CLOSURE_DTORS.register(real, state, state); return real; } let WASM_VECTOR_LEN = 0; function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8ArrayMemory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } function __wbg_adapter_20(arg0, arg1, arg2) { wasm.closure7_externref_shim(arg0, arg1, arg2); } function __wbg_adapter_30(arg0, arg1, arg2, arg3) { wasm.closure25_externref_shim(arg0, arg1, arg2, arg3); } const CryptoUtilsFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_cryptoutils_free(ptr >>> 0, 1)); class CryptoUtils { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; CryptoUtilsFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_cryptoutils_free(ptr, 0); } /** * Encrypts a message with an [OTP] [KDF] and the given parameters. * The KDF uses Argon2d for hashing. * * [OTP]: https://en.wikipedia.org/wiki/One-time_pad * [KDF]: https://en.wikipedia.org/wiki/Key_derivation_function * @param {Uint8Array} message * @param {Uint8Array} key * @param {Uint8Array} salt * @param {number} iterations * @returns {Promise<Uint8Array>} */ static otpKdf(message, key, salt, iterations) { const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(key, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc); const len2 = WASM_VECTOR_LEN; const ret = wasm.cryptoutils_otpKdf(ptr0, len0, ptr1, len1, ptr2, len2, iterations); return ret; } } __exports.CryptoUtils = CryptoUtils; async function __wbg_load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { if (typeof WebAssembly.instantiateStreaming === 'function') { try { return await WebAssembly.instantiateStreaming(module, imports); } catch (e) { if (module.headers.get('Content-Type') != 'application/wasm') { 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); } else { throw e; } } } const bytes = await module.arrayBuffer(); return await WebAssembly.instantiate(bytes, imports); } else { const instance = await WebAssembly.instantiate(module, imports); if (instance instanceof WebAssembly.Instance) { return { instance, module }; } else { return instance; } } } function __wbg_get_imports() { const imports = {}; imports.wbg = {}; imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) { const ret = arg0.buffer; return ret; }; imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) { const ret = arg0.call(arg1); return ret; }, arguments) }; imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) { const ret = arg0.call(arg1, arg2); return ret; }, arguments) }; imports.wbg.__wbg_new_23a2665fac83c611 = function(arg0, arg1) { try { var state0 = {a: arg0, b: arg1}; var cb0 = (arg0, arg1) => { const a = state0.a; state0.a = 0; try { return __wbg_adapter_30(a, state0.b, arg0, arg1); } finally { state0.a = a; } }; const ret = new Promise(cb0); return ret; } finally { state0.a = state0.b = 0; } }; imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) { const ret = new Uint8Array(arg0); return ret; }; imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return ret; }; imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) { const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0); return ret; }; imports.wbg.__wbg_queueMicrotask_97d92b4fcc8a61c5 = function(arg0) { queueMicrotask(arg0); }; imports.wbg.__wbg_queueMicrotask_d3219def82552485 = function(arg0) { const ret = arg0.queueMicrotask; return ret; }; imports.wbg.__wbg_resolve_4851785c9c5f573d = function(arg0) { const ret = Promise.resolve(arg0); return ret; }; imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() { const ret = typeof global === 'undefined' ? null : global; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() { const ret = typeof globalThis === 'undefined' ? null : globalThis; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() { const ret = typeof self === 'undefined' ? null : self; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() { const ret = typeof window === 'undefined' ? null : window; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; imports.wbg.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) { const ret = arg0.then(arg1); return ret; }; imports.wbg.__wbindgen_cb_drop = function(arg0) { const obj = arg0.original; if (obj.cnt-- == 1) { obj.a = 0; return true; } const ret = false; return ret; }; imports.wbg.__wbindgen_closure_wrapper48 = function(arg0, arg1, arg2) { const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_20); return ret; }; imports.wbg.__wbindgen_error_new = function(arg0, arg1) { const ret = new Error(getStringFromWasm0(arg0, arg1)); return ret; }; imports.wbg.__wbindgen_init_externref_table = function() { const table = wasm.__wbindgen_export_2; const offset = table.grow(4); table.set(0, undefined); table.set(offset + 0, undefined); table.set(offset + 1, null); table.set(offset + 2, true); table.set(offset + 3, false); ; }; imports.wbg.__wbindgen_is_function = function(arg0) { const ret = typeof(arg0) === 'function'; return ret; }; imports.wbg.__wbindgen_is_undefined = function(arg0) { const ret = arg0 === undefined; return ret; }; imports.wbg.__wbindgen_memory = function() { const ret = wasm.memory; return ret; }; imports.wbg.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; return imports; } function __wbg_init_memory(imports, memory) { } function __wbg_finalize_init(instance, module) { wasm = instance.exports; __wbg_init.__wbindgen_wasm_module = module; cachedUint8ArrayMemory0 = null; wasm.__wbindgen_start(); return wasm; } function initSync(module) { if (wasm !== undefined) return wasm; if (typeof module !== 'undefined') { if (Object.getPrototypeOf(module) === Object.prototype) { ({module} = module) } else { console.warn('using deprecated parameters for `initSync()`; pass a single object instead') } } const imports = __wbg_get_imports(); __wbg_init_memory(imports); if (!(module instanceof WebAssembly.Module)) { module = new WebAssembly.Module(module); } const instance = new WebAssembly.Instance(module, imports); return __wbg_finalize_init(instance, module); } async function __wbg_init(module_or_path) { if (wasm !== undefined) return wasm; if (typeof module_or_path !== 'undefined') { if (Object.getPrototypeOf(module_or_path) === Object.prototype) { ({module_or_path} = module_or_path) } else { console.warn('using deprecated parameters for the initialization function; pass a single object instead') } } if (typeof module_or_path === 'undefined' && typeof script_src !== 'undefined') { module_or_path = script_src.replace(/\.js$/, '_bg.wasm'); } const imports = __wbg_get_imports(); if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { module_or_path = fetch(module_or_path); } __wbg_init_memory(imports); const { instance, module } = await __wbg_load(await module_or_path, imports); return __wbg_finalize_init(instance, module); } wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports); })();