UNPKG

@hazae41/argon2.wasm

Version:
329 lines (273 loc) 9.35 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); let wasm; 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)); } let WASM_VECTOR_LEN = 0; const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8ArrayMemory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } function takeFromExternrefTable0(idx) { const value = wasm.__wbindgen_export_0.get(idx); wasm.__externref_table_dealloc(idx); return value; } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } } function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8ArrayMemory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } class Argon2Deriver { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; return ptr; } [Symbol.dispose]() { const ptr = this.__destroy_into_raw(); wasm.__wbg_argon2deriver_free(ptr, 0); } /** * @param {string} algorithm * @param {number} version * @param {number} memory * @param {number} iterations * @param {number} parallelism */ constructor(algorithm, version, memory, iterations, parallelism) { const ptr0 = passStringToWasm0(algorithm, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.argon2deriver_new(ptr0, len0, version, memory, iterations, parallelism); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } this.__wbg_ptr = ret[0] >>> 0; return this; } /** * @param {Memory} password * @param {Memory} salt * @returns {Memory} */ derive(password, salt) { _assertClass(password, Memory); _assertClass(salt, Memory); const ret = wasm.argon2deriver_derive(this.__wbg_ptr, password.__wbg_ptr, salt.__wbg_ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return Memory.__wrap(ret[0]); } } class Memory { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Memory.prototype); obj.__wbg_ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; this.__wbg_ptr0 = 0; this.__wbg_len0 = 0; return ptr; } [Symbol.dispose]() { const ptr = this.__destroy_into_raw(); wasm.__wbg_memory_free(ptr, 0); } /** * @param {Uint8Array} inner */ constructor(inner) { const ptr0 = passArray8ToWasm0(inner, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.memory_new(ptr0, len0); this.__wbg_ptr = ret >>> 0; this.__wbg_ptr0 = ptr0 >>> 0; this.__wbg_len0 = len0 >>> 0; return this; } /** * @returns {number} */ ptr() { const ret = wasm.memory_ptr(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ len() { const ret = wasm.memory_len(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get ptr0() { return this.__wbg_ptr0 ??= this.ptr(); } /** * @returns {number} */ get len0() { return this.__wbg_len0 ??= this.len(); } /** * @returns {Uint8Array} */ get bytes() { return getUint8ArrayMemory0().subarray(this.ptr0, this.ptr0 + this.len0); } } 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.__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_0; 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_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; return imports; } 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(); 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') { throw new Error(); } 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); } const { instance, module } = await __wbg_load(await module_or_path, imports); return __wbg_finalize_init(instance, module); } exports.Argon2Deriver = Argon2Deriver; exports.Memory = Memory; exports.default = __wbg_init; exports.initSync = initSync; //# sourceMappingURL=argon2_wasm.cjs.map