UNPKG

supercop.wasm

Version:

orlp/ed25519 compiled to WebAssembly using Emscripten and optimized for small size

43 lines (39 loc) 12.1 kB
var __supercopwasm = function(__supercopwasm) { __supercopwasm = __supercopwasm || {}; var a;a||(a=typeof __supercopwasm !== 'undefined' ? __supercopwasm : {});var k={},l;for(l in a)a.hasOwnProperty(l)&&(k[l]=a[l]);a.arguments=[];a.thisProgram="./this.program";a.quit=function(b,c){throw c;};a.preRun=[];a.postRun=[];var m=!1,n=!1,p=!1,q=!1; if(a.ENVIRONMENT)if("WEB"===a.ENVIRONMENT)m=!0;else if("WORKER"===a.ENVIRONMENT)n=!0;else if("NODE"===a.ENVIRONMENT)p=!0;else if("SHELL"===a.ENVIRONMENT)q=!0;else throw Error("Module['ENVIRONMENT'] value is not valid. must be one of: WEB|WORKER|NODE|SHELL.");else m="object"===typeof window,n="function"===typeof importScripts,p="object"===typeof process&&"function"===typeof require&&!m&&!n,q=!m&&!p&&!n; if(!a.scriptDirectory)if(a.scriptDirectory="",p)a.scriptDirectory=__dirname+"/";else if(m){var r=this._currentScript||document.currentScript;0!==r.src.indexOf("blob:")&&(a.scriptDirectory=r.src.split("/").slice(0,-1).join("/")+"/")}else n&&(a.scriptDirectory=(this._selfLocation||self.location).href.split("/").slice(0,-1).join("/")+"/");a.memoryInitializerPrefixURL||(a.memoryInitializerPrefixURL=a.scriptDirectory);a.pthreadMainPrefixURL||(a.pthreadMainPrefixURL=a.scriptDirectory); a.cdInitializerPrefixURL||(a.cdInitializerPrefixURL=a.scriptDirectory);a.filePackagePrefixURL||(a.filePackagePrefixURL=a.scriptDirectory); if(p){var t,u;a.read=function(b,c){t||(t=require("fs"));u||(u=require("path"));b=u.normalize(b);b=t.readFileSync(b);return c?b:b.toString()};a.readBinary=function(b){b=a.read(b,!0);b.buffer||(b=new Uint8Array(b));assert(b.buffer);return b};1<process.argv.length&&(a.thisProgram=process.argv[1].replace(/\\/g,"/"));a.arguments=process.argv.slice(2);process.on("uncaughtException",function(b){if(!(b instanceof v))throw b;});process.on("unhandledRejection",function(){process.exit(1)});a.inspect=function(){return"[Emscripten Module object]"}}else if(q)"undefined"!= typeof read&&(a.read=function(b){return read(b)}),a.readBinary=function(b){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(b));b=read(b,"binary");assert("object"===typeof b);return b},"undefined"!=typeof scriptArgs?a.arguments=scriptArgs:"undefined"!=typeof arguments&&(a.arguments=arguments),"function"===typeof quit&&(a.quit=function(b){quit(b)});else if(m||n)a.read=function(b){var c=new XMLHttpRequest;c.open("GET",b,!1);c.send(null);return c.responseText},n&&(a.readBinary=function(b){var c= new XMLHttpRequest;c.open("GET",b,!1);c.responseType="arraybuffer";c.send(null);return new Uint8Array(c.response)}),a.readAsync=function(b,c,h){var d=new XMLHttpRequest;d.open("GET",b,!0);d.responseType="arraybuffer";d.onload=function(){200==d.status||0==d.status&&d.response?c(d.response):h()};d.onerror=h;d.send(null)},"undefined"!=typeof arguments&&(a.arguments=arguments),a.setWindowTitle=function(b){document.title=b}; a.print="undefined"!==typeof console?console.log.bind(console):"undefined"!==typeof print?print:null;a.printErr="undefined"!==typeof printErr?printErr:"undefined"!==typeof console&&console.warn.bind(console)||a.print;a.print=a.print;a.printErr=a.printErr;for(l in k)k.hasOwnProperty(l)&&(a[l]=k[l]);k=void 0;function w(b){var c;c||(c=16);return Math.ceil(b/c)*c}var x=0;function assert(b,c){b||y("Assertion failed: "+c)}"undefined"!==typeof TextDecoder&&new TextDecoder("utf8"); "undefined"!==typeof TextDecoder&&new TextDecoder("utf-16le");var buffer,z,A,B;function C(){a.HEAP8=new Int8Array(buffer);a.HEAP16=A=new Int16Array(buffer);a.HEAP32=B=new Int32Array(buffer);a.HEAPU8=z=new Uint8Array(buffer);a.HEAPU16=new Uint16Array(buffer);a.HEAPU32=new Uint32Array(buffer);a.HEAPF32=new Float32Array(buffer);a.HEAPF64=new Float64Array(buffer)}var D,G,H,I,J,K,L,M;D=G=I=J=K=L=M=0;H=!1; function N(){y("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+O+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")}var P=a.TOTAL_STACK||5242880,O=a.TOTAL_MEMORY||16777216;O<P&&a.printErr("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+O+"! (TOTAL_STACK="+P+")"); a.buffer?buffer=a.buffer:("object"===typeof WebAssembly&&"function"===typeof WebAssembly.Memory?(a.wasmMemory=new WebAssembly.Memory({initial:O/65536,maximum:O/65536}),buffer=a.wasmMemory.buffer):buffer=new ArrayBuffer(O),a.buffer=buffer);C();B[0]=1668509029;A[1]=25459;if(115!==z[2]||99!==z[3])throw"Runtime error: expected the system to be little-endian!"; function Q(b){for(;0<b.length;){var c=b.shift();if("function"==typeof c)c();else{var h=c.f;"number"===typeof h?void 0===c.a?a.dynCall_v(h):a.dynCall_vi(h,c.a):h(void 0===c.a?null:c.a)}}}var R=[],S=[],aa=[],ba=[],T=[],U=!1;function ca(){var b=a.preRun.shift();R.unshift(b)}var V=0,W=null,X=null;a.preloadedImages={};a.preloadedAudios={};function Y(b){return String.prototype.startsWith?b.startsWith("data:application/octet-stream;base64,"):0===b.indexOf("data:application/octet-stream;base64,")} (function(){function b(){try{if(a.wasmBinary)return new Uint8Array(a.wasmBinary);if(a.readBinary)return a.readBinary(e);throw"on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)";}catch(E){y(E)}}function c(){return a.wasmBinary||!m&&!n||"function"!==typeof fetch?new Promise(function(c){c(b())}):fetch(e,{credentials:"same-origin"}).then(function(b){if(!b.ok)throw"failed to load wasm binary file at '"+e+ "'";return b.arrayBuffer()}).catch(function(){return b()})}function h(b){function d(b){F=b.exports;if(F.memory){b=F.memory;var c=a.buffer;b.byteLength<c.byteLength&&a.printErr("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here");c=new Int8Array(c);(new Int8Array(b)).set(c);a.buffer=buffer=b;C()}a.asm=F;a.usingWasm=!0;V--;a.monitorRunDependencies&&a.monitorRunDependencies(V);0==V&&(null!==W&&(clearInterval(W),W=null),X&&(b=X,X=null,b()))}function g(b){d(b.instance)} function E(b){c().then(function(b){return WebAssembly.instantiate(b,f)}).then(b).catch(function(b){a.printErr("failed to asynchronously prepare wasm: "+b);y(b)})}if("object"!==typeof WebAssembly)return a.printErr("no native wasm support detected"),!1;if(!(a.wasmMemory instanceof WebAssembly.Memory))return a.printErr("no native wasm Memory in use"),!1;b.memory=a.wasmMemory;f.global={NaN:NaN,Infinity:Infinity};f["global.Math"]=Math;f.env=b;V++;a.monitorRunDependencies&&a.monitorRunDependencies(V);if(a.instantiateWasm)try{return a.instantiateWasm(f, d)}catch(fa){return a.printErr("Module.instantiateWasm callback failed with error: "+fa),!1}a.wasmBinary||"function"!==typeof WebAssembly.instantiateStreaming||Y(e)||"function"!==typeof fetch?E(g):WebAssembly.instantiateStreaming(fetch(e,{credentials:"same-origin"}),f).then(g).catch(function(b){a.printErr("wasm streaming compile failed: "+b);a.printErr("falling back to ArrayBuffer instantiation");E(g)});return{}}var d="supercop.wast",e="supercop.wasm",g="supercop.temp.asm.js";"function"===typeof a.locateFile? (Y(d)||(d=a.locateFile(d)),Y(e)||(e=a.locateFile(e)),Y(g)||(g=a.locateFile(g))):(Y(d)||(d=a.scriptDirectory+d),Y(e)||(e=a.scriptDirectory+e),Y(g)||(g=a.scriptDirectory+g));var f={global:null,env:null,asm2wasm:{"f64-rem":function(b,c){return b%c},"debugger":function(){debugger}},parent:a},F=null;a.asmPreload=a.asm;var ha=a.reallocBuffer;a.reallocBuffer=function(b){if("asmjs"===ia)var c=ha(b);else a:{var e=a.usingWasm?65536:16777216;0<b%e&&(b+=e-b%e);e=a.buffer.byteLength;if(a.usingWasm)try{c=-1!== a.wasmMemory.grow((b-e)/65536)?a.buffer=a.wasmMemory.buffer:null;break a}catch(ma){c=null;break a}c=void 0}return c};var ia="";a.asm=function(b,c){if(!c.table){b=a.wasmTableSize;void 0===b&&(b=1024);var e=a.wasmMaxTableSize;c.table="object"===typeof WebAssembly&&"function"===typeof WebAssembly.Table?void 0!==e?new WebAssembly.Table({initial:b,maximum:e,element:"anyfunc"}):new WebAssembly.Table({initial:b,element:"anyfunc"}):Array(b);a.wasmTable=c.table}c.memoryBase||(c.memoryBase=a.STATIC_BASE);c.tableBase|| (c.tableBase=0);(c=h(c))||y("no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods");return c}})();D=1024;G=D+33968;S.push();a.STATIC_BASE=D;a.STATIC_BUMP=33968;G+=16;assert(!H);var da=G;G=G+4+15&-16;M=da;I=J=w(G);K=I+P;L=w(K);B[M>>2]=L;H=!0;a.wasmTableSize=0;a.wasmMaxTableSize=0;a.b={}; a.c={enlargeMemory:function(){N()},getTotalMemory:function(){return O},abortOnCannotGrowMemory:N,___setErrNo:function(b){a.___errno_location&&(B[a.___errno_location()>>2]=b);return b},DYNAMICTOP_PTR:M,STACKTOP:J};var ea=a.asm(a.b,a.c,buffer);a.asm=ea;a._ed25519_create_keypair=function(){return a.asm._ed25519_create_keypair.apply(null,arguments)};a._ed25519_sign=function(){return a.asm._ed25519_sign.apply(null,arguments)};a._ed25519_verify=function(){return a.asm._ed25519_verify.apply(null,arguments)}; var ja=a._free=function(){return a.asm._free.apply(null,arguments)},ka=a._malloc=function(){return a.asm._malloc.apply(null,arguments)};a.asm=ea;a.then=function(b){if(a.calledRun)b(a);else{var c=a.onRuntimeInitialized;a.onRuntimeInitialized=function(){c&&c();b(a)}}return a};function v(b){this.name="ExitStatus";this.message="Program terminated with exit("+b+")";this.status=b}v.prototype=Error();v.prototype.constructor=v;X=function la(){a.calledRun||Z();a.calledRun||(X=la)}; function Z(){function b(){if(!a.calledRun&&(a.calledRun=!0,!x)){U||(U=!0,Q(S));Q(aa);if(a.onRuntimeInitialized)a.onRuntimeInitialized();if(a.postRun)for("function"==typeof a.postRun&&(a.postRun=[a.postRun]);a.postRun.length;){var b=a.postRun.shift();T.unshift(b)}Q(T)}}if(!(0<V)){if(a.preRun)for("function"==typeof a.preRun&&(a.preRun=[a.preRun]);a.preRun.length;)ca();Q(R);0<V||a.calledRun||(a.setStatus?(a.setStatus("Running..."),setTimeout(function(){setTimeout(function(){a.setStatus("")},1);b()}, 1)):b())}}a.run=Z;a.exit=function(b,c){if(!c||!a.noExitRuntime||0!==b){if(!a.noExitRuntime&&(x=!0,J=void 0,Q(ba),a.onExit))a.onExit(b);p&&process.exit(b);a.quit(b,new v(b))}};function y(b){if(a.onAbort)a.onAbort(b);void 0!==b?(a.print(b),a.printErr(b),b=JSON.stringify(b)):b="";x=!0;throw"abort("+b+"). Build with -s ASSERTIONS=1 for more info.";}a.abort=y;if(a.preInit)for("function"==typeof a.preInit&&(a.preInit=[a.preInit]);0<a.preInit.length;)a.preInit.pop()();a.noExitRuntime=!0;Z(); (function(){function b(b){if(b&&b.buffer instanceof ArrayBuffer)b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength);else if("string"===typeof b){for(var c=b.length,e=new Uint8Array(c+1),d=0;d<c;++d)e[d]=b.charCodeAt(d);return e}return b}function c(e,g){var f=new Number(e);f.length=g;f.get=function(b){b=b||Uint8Array;return(new b(buffer,f,g/b.BYTES_PER_ELEMENT)).slice()};f.dereference=function(b){b=b||4;return c(f.get(Uint32Array)[0],b)};f.set=function(c){c=b(c);if(c.length>g)throw RangeError("invalid array length"); z.set(c,f)};f.free=function(){ja(f);d.splice(d.indexOf(f),1)};d.push(f);return f}function h(e,d){d=b(d);0===e&&(e=d.length);var f=c(ka(e),e);void 0!==d?(f.set(d),d.length<e&&z.fill(0,f+d.length,f+e)):z.fill(0,f,f+e);return f}var d=[];a.createPointer=c;a.allocatePointer=function(b){b&&(b=Uint32Array.of(b));return h(4,b)};a.allocateBytes=h;a.freeBytes=function(){for(var b=0,c=d.length;b<c;++b)ja(d[b]);d=[]}})(); return __supercopwasm; }; __supercopwasm = __supercopwasm.bind({ _currentScript: typeof document !== 'undefined' ? document.currentScript : undefined, _selfLocation: typeof self !== 'undefined' ? self.location : undefined }); if (typeof exports === 'object' && typeof module === 'object') module.exports = __supercopwasm; else if (typeof define === 'function' && define['amd']) define([], function() { return __supercopwasm; }); else if (typeof exports === 'object') exports["__supercopwasm"] = __supercopwasm;