UNPKG

@polkadot-labs/schnorrkel-wasm

Version:

JavaScript WebAssembly (WASM) wrapper for the schnorrkel Rust crate

517 lines (441 loc) 15.8 kB
let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextDecoder, TextEncoder } = require(`util`); const heap = new Array(128).fill(undefined); heap.push(undefined, null, true, false); function getObject(idx) { return heap[idx]; } let heap_next = heap.length; function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); let cachedUint8Memory0 = null; function getUint8Memory0() { if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8Memory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } /** */ module.exports.init = function() { wasm.init(); }; let WASM_VECTOR_LEN = 0; function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8Memory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } let cachedInt32Memory0 = null; function getInt32Memory0() { if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachedInt32Memory0; } function getArrayU8FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); } /** * @param {Uint8Array} pubkey * @param {Uint8Array} secret * @param {Uint8Array} msg * @returns {Uint8Array} */ module.exports.sr25519_sign = function(pubkey, secret, msg) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(pubkey, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc); const len2 = WASM_VECTOR_LEN; wasm.sr25519_sign(retptr, ptr0, len0, ptr1, len1, ptr2, len2); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v4 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v4; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} pubkey * @param {Uint8Array} msg * @param {Uint8Array} signature * @returns {boolean} */ module.exports.sr25519_verify = function(pubkey, msg, signature) { const ptr0 = passArray8ToWasm0(pubkey, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc); const len2 = WASM_VECTOR_LEN; const ret = wasm.sr25519_verify(ptr0, len0, ptr1, len1, ptr2, len2); return ret !== 0; }; /** * @param {Uint8Array} secret * @returns {Uint8Array} */ module.exports.sr25519_pubkey = function(secret) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.sr25519_pubkey(retptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v2 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} seed * @returns {Uint8Array} */ module.exports.sr25519_keypair_from_seed = function(seed) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.sr25519_keypair_from_seed(retptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v2 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} seed * @returns {Uint8Array} */ module.exports.sr25519_secret_from_seed = function(seed) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.sr25519_secret_from_seed(retptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v2 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} seed * @param {Uint8Array} cc * @returns {Uint8Array} */ module.exports.sr25519_derive_seed_hard = function(seed, cc) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(cc, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; wasm.sr25519_derive_seed_hard(retptr, ptr0, len0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v3 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v3; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} keypair * @param {Uint8Array} cc * @returns {Uint8Array} */ module.exports.sr25519_derive_keypair_hard = function(keypair, cc) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(keypair, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(cc, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; wasm.sr25519_derive_keypair_hard(retptr, ptr0, len0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v3 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v3; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} keypair * @param {Uint8Array} cc * @returns {Uint8Array} */ module.exports.sr25519_derive_keypair_soft = function(keypair, cc) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(keypair, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(cc, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; wasm.sr25519_derive_keypair_soft(retptr, ptr0, len0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v3 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v3; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {Uint8Array} pubkey * @param {Uint8Array} cc * @returns {Uint8Array} */ module.exports.sr25519_derive_public_soft = function(pubkey, cc) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(pubkey, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArray8ToWasm0(cc, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; wasm.sr25519_derive_public_soft(retptr, ptr0, len0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v3 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v3; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; 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; getUint8Memory0().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 = getUint8Memory0(); 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 = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; } WASM_VECTOR_LEN = offset; return ptr; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { wasm.__wbindgen_exn_store(addHeapObject(e)); } } module.exports.__wbg_new_abda76e883ba8a5f = function() { const ret = new Error(); return addHeapObject(ret); }; module.exports.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) { const ret = getObject(arg1).stack; const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; getInt32Memory0()[arg0 / 4 + 1] = len1; getInt32Memory0()[arg0 / 4 + 0] = ptr1; }; module.exports.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) { let deferred0_0; let deferred0_1; try { deferred0_0 = arg0; deferred0_1 = arg1; console.error(getStringFromWasm0(arg0, arg1)); } finally { wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); } }; module.exports.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; module.exports.__wbg_crypto_58f13aa23ffcb166 = function(arg0) { const ret = getObject(arg0).crypto; return addHeapObject(ret); }; module.exports.__wbindgen_is_object = function(arg0) { const val = getObject(arg0); const ret = typeof(val) === 'object' && val !== null; return ret; }; module.exports.__wbg_process_5b786e71d465a513 = function(arg0) { const ret = getObject(arg0).process; return addHeapObject(ret); }; module.exports.__wbg_versions_c2ab80650590b6a2 = function(arg0) { const ret = getObject(arg0).versions; return addHeapObject(ret); }; module.exports.__wbg_node_523d7bd03ef69fba = function(arg0) { const ret = getObject(arg0).node; return addHeapObject(ret); }; module.exports.__wbindgen_is_string = function(arg0) { const ret = typeof(getObject(arg0)) === 'string'; return ret; }; module.exports.__wbg_require_2784e593a4674877 = function() { return handleError(function () { const ret = module.require; return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_string_new = function(arg0, arg1) { const ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; module.exports.__wbg_msCrypto_abcb1295e768d1f2 = function(arg0) { const ret = getObject(arg0).msCrypto; return addHeapObject(ret); }; module.exports.__wbg_getRandomValues_504510b5564925af = function() { return handleError(function (arg0, arg1) { getObject(arg0).getRandomValues(getObject(arg1)); }, arguments) }; module.exports.__wbg_randomFillSync_a0d98aa11c81fe89 = function() { return handleError(function (arg0, arg1) { getObject(arg0).randomFillSync(takeObject(arg1)); }, arguments) }; module.exports.__wbindgen_is_function = function(arg0) { const ret = typeof(getObject(arg0)) === 'function'; return ret; }; module.exports.__wbg_newnoargs_c62ea9419c21fbac = function(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; module.exports.__wbg_call_90c26b09837aba1c = function() { return handleError(function (arg0, arg1) { const ret = getObject(arg0).call(getObject(arg1)); return addHeapObject(ret); }, arguments) }; module.exports.__wbg_self_f0e34d89f33b99fd = function() { return handleError(function () { const ret = self.self; return addHeapObject(ret); }, arguments) }; module.exports.__wbg_window_d3b084224f4774d7 = function() { return handleError(function () { const ret = window.window; return addHeapObject(ret); }, arguments) }; module.exports.__wbg_globalThis_9caa27ff917c6860 = function() { return handleError(function () { const ret = globalThis.globalThis; return addHeapObject(ret); }, arguments) }; module.exports.__wbg_global_35dfdd59a4da3e74 = function() { return handleError(function () { const ret = global.global; return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_is_undefined = function(arg0) { const ret = getObject(arg0) === undefined; return ret; }; module.exports.__wbg_call_5da1969d7cd31ccd = function() { return handleError(function (arg0, arg1, arg2) { const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); return addHeapObject(ret); }, arguments) }; module.exports.__wbg_buffer_a448f833075b71ba = function(arg0) { const ret = getObject(arg0).buffer; return addHeapObject(ret); }; module.exports.__wbg_newwithbyteoffsetandlength_d0482f893617af71 = function(arg0, arg1, arg2) { const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; module.exports.__wbg_new_8f67e318f15d7254 = function(arg0) { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; module.exports.__wbg_set_2357bf09366ee480 = function(arg0, arg1, arg2) { getObject(arg0).set(getObject(arg1), arg2 >>> 0); }; module.exports.__wbg_newwithlength_6c2df9e2f3028c43 = function(arg0) { const ret = new Uint8Array(arg0 >>> 0); return addHeapObject(ret); }; module.exports.__wbg_subarray_2e940e41c0f5a1d9 = function(arg0, arg1, arg2) { const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; module.exports.__wbindgen_object_clone_ref = function(arg0) { const ret = getObject(arg0); return addHeapObject(ret); }; module.exports.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; module.exports.__wbindgen_memory = function() { const ret = wasm.memory; return addHeapObject(ret); }; const path = require('path').join(__dirname, 'schnorrkel_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();