UNPKG

semaphore-rs-nodejs

Version:
204 lines (168 loc) 6.5 kB
let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextDecoder, TextEncoder } = require(`util`); let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); 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; let cachedTextEncoder = new TextEncoder('utf-8'); 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 isLikeNone(x) { return x === undefined || x === null; } let cachedDataViewMemory0 = null; function getDataViewMemory0() { if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } return cachedDataViewMemory0; } function addToExternrefTable0(obj) { const idx = wasm.__externref_table_alloc(); wasm.__wbindgen_export_0.set(idx, obj); return idx; } function passArrayJsValueToWasm0(array, malloc) { const ptr = malloc(array.length * 4, 4) >>> 0; for (let i = 0; i < array.length; i++) { const add = addToExternrefTable0(array[i]); getDataViewMemory0().setUint32(ptr + 4 * i, add, true); } WASM_VECTOR_LEN = array.length; return ptr; } function takeFromExternrefTable0(idx) { const value = wasm.__wbindgen_export_0.get(idx); wasm.__externref_table_dealloc(idx); return value; } function getArrayJsValueFromWasm0(ptr, len) { ptr = ptr >>> 0; const mem = getDataViewMemory0(); const result = []; for (let i = ptr; i < ptr + 4 * len; i += 4) { result.push(wasm.__wbindgen_export_0.get(mem.getUint32(i, true))); } wasm.__externref_drop_slice(ptr, len); return result; } /** * Compresses a Groth16 proof * @param {[string, string, string, string, string, string, string, string]} proof - An array of 8 hex encoded strings (with optional 0x prefixes) that represent an uncompressed proof * @returns {[string, string, string, string]} An array of 4 0x prefixed, hex encoded strings represeting a compressed proof */ module.exports.compressProof = function(proof) { const ptr0 = passArrayJsValueToWasm0(proof, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.compressProof(ptr0, len0); if (ret[3]) { throw takeFromExternrefTable0(ret[2]); } var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 4, 4); return v2; }; /** * Decompresses a Groth16 proof * @param {[string, string, string, string]} compressedProof - An array of 4 hex encoded strings (with optional 0x prefixes) that represent a compressed proof * @returns {[string, string, string, string, string, string, string, string]} An array of 8 0x prefixed, hex encoded strings representing an uncompressed proof */ module.exports.decompressProof = function(compressedProof) { const ptr0 = passArrayJsValueToWasm0(compressedProof, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.decompressProof(ptr0, len0); if (ret[3]) { throw takeFromExternrefTable0(ret[2]); } var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 4, 4); return v2; }; module.exports.__wbindgen_error_new = function(arg0, arg1) { const ret = new Error(getStringFromWasm0(arg0, arg1)); return ret; }; module.exports.__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); ; }; module.exports.__wbindgen_string_get = function(arg0, arg1) { const obj = arg1; const ret = typeof(obj) === 'string' ? obj : undefined; var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; module.exports.__wbindgen_string_new = function(arg0, arg1) { const ret = getStringFromWasm0(arg0, arg1); return ret; }; module.exports.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; const path = require('path').join(__dirname, 'semaphore_rs_js_bg.wasm'); const bytes = require('fs').readFileSync(path); const wasmModule = new WebAssembly.Module(bytes); const wasmInstance = new WebAssembly.Instance(wasmModule, imports); wasm = wasmInstance.exports; module.exports.__wasm = wasm; wasm.__wbindgen_start();