iuna

iuna

iuna - experimental mainnet-candidate protocol
git clone https://getiuna.org/git/iuna.git
Log | Files | Refs | README | LICENSE

iuna_wallet_crypto.js (14055B)


      1 /* @ts-self-types="./iuna_wallet_crypto.d.ts" */
      2 
      3 /**
      4  * @param {string} request_json
      5  * @returns {string}
      6  */
      7 export function build_migration(request_json) {
      8     let deferred3_0;
      9     let deferred3_1;
     10     try {
     11         const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
     12         const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
     13         const len0 = WASM_VECTOR_LEN;
     14         wasm.build_migration(retptr, ptr0, len0);
     15         var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
     16         var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
     17         var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
     18         var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
     19         var ptr2 = r0;
     20         var len2 = r1;
     21         if (r3) {
     22             ptr2 = 0; len2 = 0;
     23             throw takeObject(r2);
     24         }
     25         deferred3_0 = ptr2;
     26         deferred3_1 = len2;
     27         return getStringFromWasm0(ptr2, len2);
     28     } finally {
     29         wasm.__wbindgen_add_to_stack_pointer(16);
     30         wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
     31     }
     32 }
     33 
     34 /**
     35  * @param {string} request_json
     36  * @returns {string}
     37  */
     38 export function build_transfer(request_json) {
     39     let deferred3_0;
     40     let deferred3_1;
     41     try {
     42         const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
     43         const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
     44         const len0 = WASM_VECTOR_LEN;
     45         wasm.build_transfer(retptr, ptr0, len0);
     46         var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
     47         var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
     48         var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
     49         var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
     50         var ptr2 = r0;
     51         var len2 = r1;
     52         if (r3) {
     53             ptr2 = 0; len2 = 0;
     54             throw takeObject(r2);
     55         }
     56         deferred3_0 = ptr2;
     57         deferred3_1 = len2;
     58         return getStringFromWasm0(ptr2, len2);
     59     } finally {
     60         wasm.__wbindgen_add_to_stack_pointer(16);
     61         wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
     62     }
     63 }
     64 
     65 /**
     66  * @param {string} seed
     67  * @param {number} count
     68  * @param {string} network_id
     69  * @returns {string}
     70  */
     71 export function derive_external_addresses(seed, count, network_id) {
     72     let deferred4_0;
     73     let deferred4_1;
     74     try {
     75         const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
     76         const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_export, wasm.__wbindgen_export2);
     77         const len0 = WASM_VECTOR_LEN;
     78         const ptr1 = passStringToWasm0(network_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
     79         const len1 = WASM_VECTOR_LEN;
     80         wasm.derive_external_addresses(retptr, ptr0, len0, count, ptr1, len1);
     81         var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
     82         var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
     83         var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
     84         var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
     85         var ptr3 = r0;
     86         var len3 = r1;
     87         if (r3) {
     88             ptr3 = 0; len3 = 0;
     89             throw takeObject(r2);
     90         }
     91         deferred4_0 = ptr3;
     92         deferred4_1 = len3;
     93         return getStringFromWasm0(ptr3, len3);
     94     } finally {
     95         wasm.__wbindgen_add_to_stack_pointer(16);
     96         wasm.__wbindgen_export3(deferred4_0, deferred4_1, 1);
     97     }
     98 }
     99 
    100 /**
    101  * @param {string} seed
    102  * @param {number} count
    103  * @param {string} network_id
    104  * @returns {string}
    105  */
    106 export function derive_reward_addresses(seed, count, network_id) {
    107     let deferred4_0;
    108     let deferred4_1;
    109     try {
    110         const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
    111         const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    112         const len0 = WASM_VECTOR_LEN;
    113         const ptr1 = passStringToWasm0(network_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    114         const len1 = WASM_VECTOR_LEN;
    115         wasm.derive_reward_addresses(retptr, ptr0, len0, count, ptr1, len1);
    116         var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
    117         var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
    118         var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
    119         var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
    120         var ptr3 = r0;
    121         var len3 = r1;
    122         if (r3) {
    123             ptr3 = 0; len3 = 0;
    124             throw takeObject(r2);
    125         }
    126         deferred4_0 = ptr3;
    127         deferred4_1 = len3;
    128         return getStringFromWasm0(ptr3, len3);
    129     } finally {
    130         wasm.__wbindgen_add_to_stack_pointer(16);
    131         wasm.__wbindgen_export3(deferred4_0, deferred4_1, 1);
    132     }
    133 }
    134 function __wbg_get_imports() {
    135     const import0 = {
    136         __proto__: null,
    137         __wbg___wbindgen_debug_string_edece8177ad01481: function(arg0, arg1) {
    138             const ret = debugString(getObject(arg1));
    139             const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    140             const len1 = WASM_VECTOR_LEN;
    141             getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
    142             getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
    143         },
    144         __wbindgen_cast_0000000000000001: function(arg0, arg1) {
    145             // Cast intrinsic for `Ref(String) -> Externref`.
    146             const ret = getStringFromWasm0(arg0, arg1);
    147             return addHeapObject(ret);
    148         },
    149         __wbindgen_object_drop_ref: function(arg0) {
    150             takeObject(arg0);
    151         },
    152     };
    153     return {
    154         __proto__: null,
    155         "./iuna_wallet_crypto_bg.js": import0,
    156     };
    157 }
    158 
    159 function addHeapObject(obj) {
    160     if (heap_next === heap.length) heap.push(heap.length + 1);
    161     const idx = heap_next;
    162     heap_next = heap[idx];
    163 
    164     heap[idx] = obj;
    165     return idx;
    166 }
    167 
    168 function debugString(val) {
    169     // primitive types
    170     const type = typeof val;
    171     if (type == 'number' || type == 'boolean' || val == null) {
    172         return  `${val}`;
    173     }
    174     if (type == 'string') {
    175         return `"${val}"`;
    176     }
    177     if (type == 'symbol') {
    178         const description = val.description;
    179         if (description == null) {
    180             return 'Symbol';
    181         } else {
    182             return `Symbol(${description})`;
    183         }
    184     }
    185     if (type == 'function') {
    186         const name = val.name;
    187         if (typeof name == 'string' && name.length > 0) {
    188             return `Function(${name})`;
    189         } else {
    190             return 'Function';
    191         }
    192     }
    193     // objects
    194     if (Array.isArray(val)) {
    195         const length = val.length;
    196         let debug = '[';
    197         if (length > 0) {
    198             debug += debugString(val[0]);
    199         }
    200         for(let i = 1; i < length; i++) {
    201             debug += ', ' + debugString(val[i]);
    202         }
    203         debug += ']';
    204         return debug;
    205     }
    206     // Test for built-in
    207     const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
    208     let className;
    209     if (builtInMatches && builtInMatches.length > 1) {
    210         className = builtInMatches[1];
    211     } else {
    212         // Failed to match the standard '[object ClassName]'
    213         return toString.call(val);
    214     }
    215     if (className == 'Object') {
    216         // we're a user defined class or Object
    217         // JSON.stringify avoids problems with cycles, and is generally much
    218         // easier than looping through ownProperties of `val`.
    219         try {
    220             return 'Object(' + JSON.stringify(val) + ')';
    221         } catch (_) {
    222             return 'Object';
    223         }
    224     }
    225     // errors
    226     if (val instanceof Error) {
    227         return `${val.name}: ${val.message}\n${val.stack}`;
    228     }
    229     // TODO we could test for more things here, like `Set`s and `Map`s.
    230     return className;
    231 }
    232 
    233 function dropObject(idx) {
    234     if (idx < 1028) return;
    235     heap[idx] = heap_next;
    236     heap_next = idx;
    237 }
    238 
    239 let cachedDataViewMemory0 = null;
    240 function getDataViewMemory0() {
    241     if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
    242         cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
    243     }
    244     return cachedDataViewMemory0;
    245 }
    246 
    247 function getStringFromWasm0(ptr, len) {
    248     return decodeText(ptr >>> 0, len);
    249 }
    250 
    251 let cachedUint8ArrayMemory0 = null;
    252 function getUint8ArrayMemory0() {
    253     if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
    254         cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
    255     }
    256     return cachedUint8ArrayMemory0;
    257 }
    258 
    259 function getObject(idx) { return heap[idx]; }
    260 
    261 let heap = new Array(1024).fill(undefined);
    262 heap.push(undefined, null, true, false);
    263 
    264 let heap_next = heap.length;
    265 
    266 function passStringToWasm0(arg, malloc, realloc) {
    267     if (realloc === undefined) {
    268         const buf = cachedTextEncoder.encode(arg);
    269         const ptr = malloc(buf.length, 1) >>> 0;
    270         getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
    271         WASM_VECTOR_LEN = buf.length;
    272         return ptr;
    273     }
    274 
    275     let len = arg.length;
    276     let ptr = malloc(len, 1) >>> 0;
    277 
    278     const mem = getUint8ArrayMemory0();
    279 
    280     let offset = 0;
    281 
    282     for (; offset < len; offset++) {
    283         const code = arg.charCodeAt(offset);
    284         if (code > 0x7F) break;
    285         mem[ptr + offset] = code;
    286     }
    287     if (offset !== len) {
    288         if (offset !== 0) {
    289             arg = arg.slice(offset);
    290         }
    291         ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
    292         const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
    293         const ret = cachedTextEncoder.encodeInto(arg, view);
    294 
    295         offset += ret.written;
    296         ptr = realloc(ptr, len, offset, 1) >>> 0;
    297     }
    298 
    299     WASM_VECTOR_LEN = offset;
    300     return ptr;
    301 }
    302 
    303 function takeObject(idx) {
    304     const ret = getObject(idx);
    305     dropObject(idx);
    306     return ret;
    307 }
    308 
    309 let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
    310 cachedTextDecoder.decode();
    311 const MAX_SAFARI_DECODE_BYTES = 2146435072;
    312 let numBytesDecoded = 0;
    313 function decodeText(ptr, len) {
    314     numBytesDecoded += len;
    315     if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
    316         cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
    317         cachedTextDecoder.decode();
    318         numBytesDecoded = len;
    319     }
    320     return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
    321 }
    322 
    323 const cachedTextEncoder = new TextEncoder();
    324 
    325 if (!('encodeInto' in cachedTextEncoder)) {
    326     cachedTextEncoder.encodeInto = function (arg, view) {
    327         const buf = cachedTextEncoder.encode(arg);
    328         view.set(buf);
    329         return {
    330             read: arg.length,
    331             written: buf.length
    332         };
    333     };
    334 }
    335 
    336 let WASM_VECTOR_LEN = 0;
    337 
    338 let wasmModule, wasmInstance, wasm;
    339 function __wbg_finalize_init(instance, module) {
    340     wasmInstance = instance;
    341     wasm = instance.exports;
    342     wasmModule = module;
    343     cachedDataViewMemory0 = null;
    344     cachedUint8ArrayMemory0 = null;
    345     return wasm;
    346 }
    347 
    348 async function __wbg_load(module, imports) {
    349     if (typeof Response === 'function' && module instanceof Response) {
    350         if (typeof WebAssembly.instantiateStreaming === 'function') {
    351             try {
    352                 return await WebAssembly.instantiateStreaming(module, imports);
    353             } catch (e) {
    354                 const validResponse = module.ok && expectedResponseType(module.type);
    355 
    356                 if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
    357                     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);
    358 
    359                 } else { throw e; }
    360             }
    361         }
    362 
    363         const bytes = await module.arrayBuffer();
    364         return await WebAssembly.instantiate(bytes, imports);
    365     } else {
    366         const instance = await WebAssembly.instantiate(module, imports);
    367 
    368         if (instance instanceof WebAssembly.Instance) {
    369             return { instance, module };
    370         } else {
    371             return instance;
    372         }
    373     }
    374 
    375     function expectedResponseType(type) {
    376         switch (type) {
    377             case 'basic': case 'cors': case 'default': return true;
    378         }
    379         return false;
    380     }
    381 }
    382 
    383 function initSync(module) {
    384     if (wasm !== undefined) return wasm;
    385 
    386 
    387     if (module !== undefined) {
    388         if (Object.getPrototypeOf(module) === Object.prototype) {
    389             ({module} = module)
    390         } else {
    391             console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
    392         }
    393     }
    394 
    395     const imports = __wbg_get_imports();
    396     if (!(module instanceof WebAssembly.Module)) {
    397         module = new WebAssembly.Module(module);
    398     }
    399     const instance = new WebAssembly.Instance(module, imports);
    400     return __wbg_finalize_init(instance, module);
    401 }
    402 
    403 async function __wbg_init(module_or_path) {
    404     if (wasm !== undefined) return wasm;
    405 
    406 
    407     if (module_or_path !== undefined) {
    408         if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
    409             ({module_or_path} = module_or_path)
    410         } else {
    411             console.warn('using deprecated parameters for the initialization function; pass a single object instead')
    412         }
    413     }
    414 
    415     if (module_or_path === undefined) {
    416         module_or_path = new URL('iuna_wallet_crypto_bg.wasm', import.meta.url);
    417     }
    418     const imports = __wbg_get_imports();
    419 
    420     if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
    421         module_or_path = fetch(module_or_path);
    422     }
    423 
    424     const { instance, module } = await __wbg_load(await module_or_path, imports);
    425 
    426     return __wbg_finalize_init(instance, module);
    427 }
    428 
    429 export { initSync, __wbg_init as default };