@getpara/server-sdk 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +506 -1
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/workers/worker.js +1008 -2
- package/dist/cjs/workers/worker.js.br +0 -0
- package/dist/cjs/workers/worker.js.gz +0 -0
- package/dist/esm/index.js +470 -1
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/workers/chunk-MCKGQKYU.js +15 -0
- package/dist/esm/workers/chunk-MCKGQKYU.js.br +0 -0
- package/dist/esm/workers/chunk-MCKGQKYU.js.gz +0 -0
- package/dist/esm/workers/wasm_exec-UV7SYRZI.js +577 -0
- package/dist/esm/workers/wasm_exec-UV7SYRZI.js.br +0 -0
- package/dist/esm/workers/wasm_exec-UV7SYRZI.js.gz +0 -0
- package/dist/esm/workers/worker.js +408 -1
- package/dist/esm/workers/worker.js.br +0 -0
- package/dist/esm/workers/worker.js.gz +0 -0
- package/dist/types/ParaServer.d.ts +16 -1
- package/package.json +4 -4
- package/dist/esm/workers/chunk-NEJSZOZX.js +0 -1
- package/dist/esm/workers/chunk-NEJSZOZX.js.br +0 -0
- package/dist/esm/workers/chunk-NEJSZOZX.js.gz +0 -0
- package/dist/esm/workers/wasm_exec-TBSO5IWG.js +0 -2
- package/dist/esm/workers/wasm_exec-TBSO5IWG.js.br +0 -0
- package/dist/esm/workers/wasm_exec-TBSO5IWG.js.gz +0 -0
|
@@ -1,2 +1,1008 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);return r!=-1&&(console.log(o.substring(0,r)),o=o.substring(r+1)),s.length},write(n,s,r,a,u,g){if(r!==0||a!==s.length||u!==null){g(t());return}let d=this.writeSync(n,s);g(null,d)},chmod(n,s,r){r(t())},chown(n,s,r,a){a(t())},close(n,s){s(t())},fchmod(n,s,r){r(t())},fchown(n,s,r,a){a(t())},fstat(n,s){s(t())},fsync(n,s){s(null)},ftruncate(n,s,r){r(t())},lchown(n,s,r,a){a(t())},link(n,s,r){r(t())},lstat(n,s){s(t())},mkdir(n,s,r){r(t())},open(n,s,r,a){a(t())},read(n,s,r,a,u,g){g(t())},readdir(n,s){s(t())},readlink(n,s){s(t())},rename(n,s,r){r(t())},rmdir(n,s){s(t())},stat(n,s){s(t())},symlink(n,s,r){r(t())},truncate(n,s,r){r(t())},unlink(n,s){s(t())},utimes(n,s,r,a){a(t())}}}if(globalThis.process||(globalThis.process={getuid(){return-1},getgid(){return-1},geteuid(){return-1},getegid(){return-1},getgroups(){throw t()},pid:-1,ppid:-1,umask(){throw t()},cwd(){throw t()},chdir(){throw t()}}),!globalThis.crypto)throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");if(!globalThis.performance)throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");if(!globalThis.TextEncoder)throw new Error("globalThis.TextEncoder is not available, polyfill required");if(!globalThis.TextDecoder)throw new Error("globalThis.TextDecoder is not available, polyfill required");let l=new TextEncoder("utf-8"),c=new TextDecoder("utf-8");globalThis.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=e=>{e!==0&&console.warn("exit code:",e)},this._exitPromise=new Promise(e=>{this._resolveExitPromise=e}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;let o=(e,i)=>{this.mem.setUint32(e+0,i,!0),this.mem.setUint32(e+4,Math.floor(i/4294967296),!0)},n=(e,i)=>{this.mem.setUint32(e+0,i,!0)},s=e=>{let i=this.mem.getUint32(e+0,!0),h=this.mem.getInt32(e+4,!0);return i+h*4294967296},r=e=>{let i=this.mem.getFloat64(e,!0);if(i===0)return;if(!isNaN(i))return i;let h=this.mem.getUint32(e,!0);return this._values[h]},a=(e,i)=>{if(typeof i=="number"&&i!==0){if(isNaN(i)){this.mem.setUint32(e+4,2146959360,!0),this.mem.setUint32(e,0,!0);return}this.mem.setFloat64(e,i,!0);return}if(i===void 0){this.mem.setFloat64(e,0,!0);return}let m=this._ids.get(i);m===void 0&&(m=this._idPool.pop(),m===void 0&&(m=this._values.length),this._values[m]=i,this._goRefCounts[m]=0,this._ids.set(i,m)),this._goRefCounts[m]++;let y=0;switch(typeof i){case"object":i!==null&&(y=1);break;case"string":y=2;break;case"symbol":y=3;break;case"function":y=4;break}this.mem.setUint32(e+4,2146959360|y,!0),this.mem.setUint32(e,m,!0)},u=e=>{let i=s(e+0),h=s(e+8);return new Uint8Array(this._inst.exports.mem.buffer,i,h)},g=e=>{let i=s(e+0),h=s(e+8),m=new Array(h);for(let y=0;y<h;y++)m[y]=r(i+y*8);return m},d=e=>{let i=s(e+0),h=s(e+8);return c.decode(new DataView(this._inst.exports.mem.buffer,i,h))},f=Date.now()-performance.now();this.importObject={_gotest:{add:(e,i)=>e+i},gojs:{"runtime.wasmExit":e=>{e>>>=0;let i=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(i)},"runtime.wasmWrite":e=>{e>>>=0;let i=s(e+8),h=s(e+16),m=this.mem.getInt32(e+24,!0);fs.writeSync(i,new Uint8Array(this._inst.exports.mem.buffer,h,m))},"runtime.resetMemoryDataView":e=>{e>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":e=>{e>>>=0,o(e+8,(f+performance.now())*1e6)},"runtime.walltime":e=>{e>>>=0;let i=new Date().getTime();o(e+8,i/1e3),this.mem.setInt32(e+16,i%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{e>>>=0;let i=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(i,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(i);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()},s(e+8))),this.mem.setInt32(e+16,i,!0)},"runtime.clearTimeoutEvent":e=>{e>>>=0;let i=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(i)),this._scheduledTimeouts.delete(i)},"runtime.getRandomData":e=>{e>>>=0,X.getRandomValues(u(e+8))},"syscall/js.finalizeRef":e=>{e>>>=0;let i=this.mem.getUint32(e+8,!0);if(this._goRefCounts[i]--,this._goRefCounts[i]===0){let h=this._values[i];this._values[i]=null,this._ids.delete(h),this._idPool.push(i)}},"syscall/js.stringVal":e=>{e>>>=0,a(e+24,d(e+8))},"syscall/js.valueGet":e=>{e>>>=0;let i=Reflect.get(r(e+8),d(e+16));e=this._inst.exports.getsp()>>>0,a(e+32,i)},"syscall/js.valueSet":e=>{e>>>=0,Reflect.set(r(e+8),d(e+16),r(e+32))},"syscall/js.valueDelete":e=>{e>>>=0,Reflect.deleteProperty(r(e+8),d(e+16))},"syscall/js.valueIndex":e=>{e>>>=0,a(e+24,Reflect.get(r(e+8),s(e+16)))},"syscall/js.valueSetIndex":e=>{e>>>=0,Reflect.set(r(e+8),s(e+16),r(e+24))},"syscall/js.valueCall":e=>{e>>>=0;try{let i=r(e+8),h=Reflect.get(i,d(e+16)),m=g(e+32),y=Reflect.apply(h,i,m);e=this._inst.exports.getsp()>>>0,a(e+56,y),this.mem.setUint8(e+64,1)}catch(i){e=this._inst.exports.getsp()>>>0,a(e+56,i),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{e>>>=0;try{let i=r(e+8),h=g(e+16),m=Reflect.apply(i,void 0,h);e=this._inst.exports.getsp()>>>0,a(e+40,m),this.mem.setUint8(e+48,1)}catch(i){e=this._inst.exports.getsp()>>>0,a(e+40,i),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{e>>>=0;try{let i=r(e+8),h=g(e+16),m=Reflect.construct(i,h);e=this._inst.exports.getsp()>>>0,a(e+40,m),this.mem.setUint8(e+48,1)}catch(i){e=this._inst.exports.getsp()>>>0,a(e+40,i),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":e=>{e>>>=0,o(e+16,parseInt(r(e+8).length))},"syscall/js.valuePrepareString":e=>{e>>>=0;let i=l.encode(String(r(e+8)));a(e+16,i),o(e+24,i.length)},"syscall/js.valueLoadString":e=>{e>>>=0;let i=r(e+8);u(e+16).set(i)},"syscall/js.valueInstanceOf":e=>{e>>>=0,this.mem.setUint8(e+24,r(e+8)instanceof r(e+16)?1:0)},"syscall/js.copyBytesToGo":e=>{e>>>=0;let i=u(e+8),h=r(e+32);if(!(h instanceof Uint8Array||h instanceof Uint8ClampedArray)){this.mem.setUint8(e+48,0);return}let m=h.subarray(0,i.length);i.set(m),o(e+40,m.length),this.mem.setUint8(e+48,1)},"syscall/js.copyBytesToJS":e=>{e>>>=0;let i=r(e+8),h=u(e+16);if(!(i instanceof Uint8Array||i instanceof Uint8ClampedArray)){this.mem.setUint8(e+48,0);return}let m=h.subarray(0,i.length);i.set(m),o(e+40,m.length),this.mem.setUint8(e+48,1)},debug:e=>{console.log(e)}}}}async run(o){if(!(o instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=o,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,globalThis,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[globalThis,5],[this,6]]),this._idPool=[],this.exited=!1;let n=4096,s=f=>{let e=n,i=l.encode(f+"\0");return new Uint8Array(this.mem.buffer,n,i.length).set(i),n+=i.length,n%8!==0&&(n+=8-n%8),e},r=this.argv.length,a=[];this.argv.forEach(f=>{a.push(s(f))}),a.push(0),Object.keys(this.env).sort().forEach(f=>{a.push(s(`${f}=${this.env[f]}`))}),a.push(0);let g=n;if(a.forEach(f=>{this.mem.setUint32(n,f,!0),this.mem.setUint32(n+4,0,!0),n+=8}),n>=12288)throw new Error("total length of command line and environment variables exceeds limit");this._inst.exports.run(r,g),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(o){let n=this;return function(){let s={id:o,this:this,args:arguments};return n._pendingEvent=s,n._resume(),s.result}}}})();N.exports={globalThisCopy:S}});var ne={};Y(ne,{handleMessage:()=>te});module.exports=H(ne);var O=P(require("axios")),p=require("@getpara/core-sdk");var w=require("@getpara/core-sdk"),E=(t,l,c)=>`{"ServerUrl":"${t}", "WalletId": "${l}", "Id":"${c}", "Ids":["USER","CAPSULE"], "Threshold":1}`,I=(t,l,c)=>`{"walletId": "${t}", "id":"${l}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${c}}`;async function _(t,l,c,o){let{data:n}=await t.mpcComputationClient.post("/wallets",{userId:l,walletId:c,protocolId:o});return n}async function z(t,l,c,o,n,s){let{data:r}=await t.mpcComputationClient.post(`/wallets/${c}/messages/sign`,{userId:l,protocolId:o,message:n,signer:s});return r}async function U(t,l,c,o,n,s,r){let{data:a}=await t.mpcComputationClient.post(`/wallets/${c}/transactions/send`,{userId:l,protocolId:o,transaction:n,signer:s,chainId:r});return a}async function v(t,l){let{walletId:c,protocolId:o}=await t.client.createWallet(l,{scheme:w.WalletScheme.ED25519,type:w.WalletType.SOLANA}),n=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets);try{return{signer:await new Promise((r,a)=>global.ed25519CreateAccount(n,c,o,(u,g)=>{u&&a(u),r(g)})),walletId:c}}catch{throw new Error(`error creating account of type SOLANA with userId ${l} and walletId ${c}`)}}async function R(t,l,c){let{walletId:o,protocolId:n}=await t.client.createPregenWallet({pregenIdentifier:l,pregenIdentifierType:c,scheme:w.WalletScheme.ED25519,type:w.WalletType.SOLANA}),s=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets);try{return{signer:await new Promise((a,u)=>global.ed25519CreateAccount(s,o,n,(g,d)=>{g&&u(g),a(d)})),walletId:o}}catch{throw new Error(`error creating account of type SOLANA with walletId ${o}`)}}async function k(t,l,c,o,n){let{protocolId:s}=await t.client.preSignMessage(c,o,n,w.WalletScheme.ED25519);try{return{signature:await new Promise((a,u)=>global.ed25519Sign(l,s,n,(g,d)=>{g&&u(g),a(d)}))}}catch{throw new Error(`error signing for account of type SOLANA with userId ${c} and walletId ${o}`)}}async function A(t,l,c,o){let{walletId:n,protocolId:s}=await t.client.createWallet(l,{useTwoSigners:!0,scheme:t.useDKLS?w.WalletScheme.DKLS:w.WalletScheme.CGGMP,type:c,cosmosPrefix:c===w.WalletType.COSMOS?t.cosmosPrefix:void 0});if(t.offloadMPCComputationURL&&!t.useDKLS)return{signer:(await _(t,l,n,s)).signer,walletId:n};let r=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets),a=t.useDKLS?I(n,"USER",t.disableWebSockets):E(r,n,"USER"),u=t.useDKLS?global.dklsCreateAccount:global.createAccountV2;try{return{signer:await new Promise((d,f)=>u(a,r,s,o,()=>{},(e,i)=>{e&&f(e),d(i)})),walletId:n}}catch{throw new Error(`error creating account of type ${c} with userId ${l} and walletId ${n}`)}}async function D(t,l,c,o,n,s){let{walletId:r,protocolId:a}=await t.client.createPregenWallet({pregenIdentifier:c,pregenIdentifierType:o,type:n,cosmosPrefix:n===w.WalletType.COSMOS?t.cosmosPrefix:void 0});if(t.offloadMPCComputationURL&&!t.useDKLS)return{signer:(await _(t,l,r,a)).signer,walletId:r};let u=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets),g=t.useDKLS?I(r,"USER",t.disableWebSockets):E(u,r,"USER"),d=t.useDKLS?global.dklsCreateAccount:global.createAccountV2;try{return{signer:await new Promise((e,i)=>d(g,u,a,s,()=>{},(h,m)=>{h&&i(h),e(m)})),walletId:r}}catch{throw new Error(`error creating account of type ${n} with walletId ${r}`)}}async function L(t,l,c,o,n){let{protocolId:s,pendingTransactionId:r}=await t.client.preSignMessage(o,c,n);if(r)return{pendingTransactionId:r};if(t.offloadMPCComputationURL&&!t.useDKLS)return z(t,o,c,s,n,l);let a=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets),u=t.useDKLS?global.dklsSignMessage:global.signMessage;try{return new Promise((g,d)=>u(l,a,n,s,(f,e)=>{f&&d(f),g({signature:e})}))}catch{throw new Error(`error signing for account with userId ${o} and walletId ${c}`)}}async function W(t,l,c,o,n,s){let{data:{protocolId:r,pendingTransactionId:a}}=await t.client.signTransaction(o,c,{transaction:n,chainId:s});if(a)return{pendingTransactionId:a};if(t.offloadMPCComputationURL&&!t.useDKLS)return U(t,o,c,r,n,l,s);let u=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets),g=t.useDKLS?global.dklsSendTransaction:global.sendTransaction;try{return new Promise((d,f)=>g(l,u,n,s,r,(e,i)=>{e&&f(e),d({signature:i})}))}catch{throw new Error(`error signing transaction for account with userId ${o} and walletId ${c}`)}}async function K(t,l,c,o,n,s){let{data:{protocolId:r,pendingTransactionId:a}}=await t.client.sendTransaction(o,c,{transaction:n,chainId:s});if(a)return{pendingTransactionId:a};if(t.offloadMPCComputationURL&&!t.useDKLS)return U(t,o,c,r,n,l,s);let u=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets),g=t.useDKLS?global.dklsSendTransaction:global.sendTransaction;try{return new Promise((d,f)=>g(l,u,n,s,r,(e,i)=>{e&&f(e),d({signature:i})}))}catch{throw new Error(`error signing transaction to send for account with userId ${o} and walletId ${c}`)}}async function M(t,l,c,o){let{data:{protocolId:n}}=await t.client.refreshKeys(o,c),s=(0,w.getBaseMPCNetworkUrl)(t.env,!t.disableWebSockets),r=t.useDKLS?global.dklsRefresh:global.refresh;try{return new Promise((a,u)=>r(l,s,n,(g,d)=>{g&&u(g),a(d)}))}catch{throw new Error(`error refreshing keys for account with userId ${o} and walletId ${c}`)}}async function $(t,l,c,o){let n=await t.client.getParaShare(o,c);if(!n)return console.error("unable to retrieve Para share"),"";try{return new Promise((s,r)=>global.getPrivateKey(l,n,(a,u)=>{a&&r(a),s(u)}))}catch{throw new Error(`error getting private key for account with userId ${o} and walletId ${c}`)}}var C;async function Q(t,l=3){for(let c=0;c<l;c++)try{return await O.default.get(`${(0,p.getPortalBaseURL)(t,!0,!0)}/static/js/main.wasm`,{responseType:"arraybuffer"})}catch(o){if(c===l-1)throw o}}async function Z(t){await Promise.resolve().then(()=>P(x())),global.WebSocket=require("ws");let l=new global.Go;C||(C=(await Q(t)).data);let c=new Uint8Array(C),o=await WebAssembly.instantiate(c,l.importObject);l.run(o.instance)}async function ee(t,l){let{functionType:c,params:o}=l;switch(c){case"KEYGEN":{let{userId:n,secretKey:s,type:r=p.WalletType.EVM}=o;return A(t,n,r,s)}case"SIGN_TRANSACTION":{let{share:n,walletId:s,userId:r,tx:a,chainId:u}=o;return W(t,n,s,r,a,u)}case"SEND_TRANSACTION":{let{share:n,walletId:s,userId:r,tx:a,chainId:u}=o;return K(t,n,s,r,a,u)}case"SIGN_MESSAGE":{let{share:n,walletId:s,userId:r,message:a}=o;return L(t,n,s,r,a)}case"REFRESH":{let{share:n,walletId:s,userId:r}=o;return M(t,n,s,r)}case"PREKEYGEN":{let{email:n,partnerId:s,secretKey:r,type:a=p.WalletType.EVM}=o,{pregenIdentifier:u,pregenIdentifierType:g}=o;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(u=n,g="EMAIL"),await D(t,s,u,g,a,r)}case"GET_PRIVATE_KEY":{let{share:n,walletId:s,userId:r}=o;return await $(t,n,s,r)}case"ED25519_KEYGEN":{let{userId:n}=o;return v(t,n)}case"ED25519_SIGN":{let{share:n,walletId:s,userId:r,base64Bytes:a}=o;return k(t,n,r,s,a)}case"ED25519_PREKEYGEN":{let{email:n}=o,{pregenIdentifier:s,pregenIdentifierType:r}=o;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(s=n,r="EMAIL"),R(t,s,r)}default:throw new Error(`functionType: ${c} not supported`)}}async function te(t){let{env:l,apiKey:c,cosmosPrefix:o="cosmos",offloadMPCComputationURL:n,disableWorkers:s,sessionCookie:r,useDKLS:a,disableWebSockets:u,workId:g}=t.data,d={env:l,apiKey:c,client:(0,p.initClient)({env:l,version:p.paraVersion,apiKey:c,retrieveSessionCookie:()=>r}),offloadMPCComputationURL:n,mpcComputationClient:n?p.mpcComputationClient.initClient(n,!!s):void 0,useDKLS:a,disableWebSockets:!!u,cosmosPrefix:o};(!d.offloadMPCComputationURL||d.useDKLS)&&await Z(d);let f=await ee(d,t.data);return f.workId=g,f}0&&(module.exports={handleMessage});
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/wasm/wasm_exec.js
|
|
33
|
+
var require_wasm_exec = __commonJS({
|
|
34
|
+
"src/wasm/wasm_exec.js"(exports2, module2) {
|
|
35
|
+
"use strict";
|
|
36
|
+
var globalThisCopy = global;
|
|
37
|
+
if (!globalThisCopy.crypto) {
|
|
38
|
+
globalThisCopy.crypto = require("crypto");
|
|
39
|
+
}
|
|
40
|
+
var crypto = globalThisCopy.crypto;
|
|
41
|
+
(() => {
|
|
42
|
+
const enosys = () => {
|
|
43
|
+
const err = new Error("not implemented");
|
|
44
|
+
err.code = "ENOSYS";
|
|
45
|
+
return err;
|
|
46
|
+
};
|
|
47
|
+
if (!globalThis.fs) {
|
|
48
|
+
let outputBuf = "";
|
|
49
|
+
globalThis.fs = {
|
|
50
|
+
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
|
|
51
|
+
// unused
|
|
52
|
+
writeSync(fd, buf) {
|
|
53
|
+
outputBuf += decoder.decode(buf);
|
|
54
|
+
const nl = outputBuf.lastIndexOf("\n");
|
|
55
|
+
if (nl != -1) {
|
|
56
|
+
console.log(outputBuf.substring(0, nl));
|
|
57
|
+
outputBuf = outputBuf.substring(nl + 1);
|
|
58
|
+
}
|
|
59
|
+
return buf.length;
|
|
60
|
+
},
|
|
61
|
+
write(fd, buf, offset, length, position, callback) {
|
|
62
|
+
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
63
|
+
callback(enosys());
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const n = this.writeSync(fd, buf);
|
|
67
|
+
callback(null, n);
|
|
68
|
+
},
|
|
69
|
+
chmod(path, mode, callback) {
|
|
70
|
+
callback(enosys());
|
|
71
|
+
},
|
|
72
|
+
chown(path, uid, gid, callback) {
|
|
73
|
+
callback(enosys());
|
|
74
|
+
},
|
|
75
|
+
close(fd, callback) {
|
|
76
|
+
callback(enosys());
|
|
77
|
+
},
|
|
78
|
+
fchmod(fd, mode, callback) {
|
|
79
|
+
callback(enosys());
|
|
80
|
+
},
|
|
81
|
+
fchown(fd, uid, gid, callback) {
|
|
82
|
+
callback(enosys());
|
|
83
|
+
},
|
|
84
|
+
fstat(fd, callback) {
|
|
85
|
+
callback(enosys());
|
|
86
|
+
},
|
|
87
|
+
fsync(fd, callback) {
|
|
88
|
+
callback(null);
|
|
89
|
+
},
|
|
90
|
+
ftruncate(fd, length, callback) {
|
|
91
|
+
callback(enosys());
|
|
92
|
+
},
|
|
93
|
+
lchown(path, uid, gid, callback) {
|
|
94
|
+
callback(enosys());
|
|
95
|
+
},
|
|
96
|
+
link(path, link, callback) {
|
|
97
|
+
callback(enosys());
|
|
98
|
+
},
|
|
99
|
+
lstat(path, callback) {
|
|
100
|
+
callback(enosys());
|
|
101
|
+
},
|
|
102
|
+
mkdir(path, perm, callback) {
|
|
103
|
+
callback(enosys());
|
|
104
|
+
},
|
|
105
|
+
open(path, flags, mode, callback) {
|
|
106
|
+
callback(enosys());
|
|
107
|
+
},
|
|
108
|
+
read(fd, buffer, offset, length, position, callback) {
|
|
109
|
+
callback(enosys());
|
|
110
|
+
},
|
|
111
|
+
readdir(path, callback) {
|
|
112
|
+
callback(enosys());
|
|
113
|
+
},
|
|
114
|
+
readlink(path, callback) {
|
|
115
|
+
callback(enosys());
|
|
116
|
+
},
|
|
117
|
+
rename(from, to, callback) {
|
|
118
|
+
callback(enosys());
|
|
119
|
+
},
|
|
120
|
+
rmdir(path, callback) {
|
|
121
|
+
callback(enosys());
|
|
122
|
+
},
|
|
123
|
+
stat(path, callback) {
|
|
124
|
+
callback(enosys());
|
|
125
|
+
},
|
|
126
|
+
symlink(path, link, callback) {
|
|
127
|
+
callback(enosys());
|
|
128
|
+
},
|
|
129
|
+
truncate(path, length, callback) {
|
|
130
|
+
callback(enosys());
|
|
131
|
+
},
|
|
132
|
+
unlink(path, callback) {
|
|
133
|
+
callback(enosys());
|
|
134
|
+
},
|
|
135
|
+
utimes(path, atime, mtime, callback) {
|
|
136
|
+
callback(enosys());
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (!globalThis.process) {
|
|
141
|
+
globalThis.process = {
|
|
142
|
+
getuid() {
|
|
143
|
+
return -1;
|
|
144
|
+
},
|
|
145
|
+
getgid() {
|
|
146
|
+
return -1;
|
|
147
|
+
},
|
|
148
|
+
geteuid() {
|
|
149
|
+
return -1;
|
|
150
|
+
},
|
|
151
|
+
getegid() {
|
|
152
|
+
return -1;
|
|
153
|
+
},
|
|
154
|
+
getgroups() {
|
|
155
|
+
throw enosys();
|
|
156
|
+
},
|
|
157
|
+
pid: -1,
|
|
158
|
+
ppid: -1,
|
|
159
|
+
umask() {
|
|
160
|
+
throw enosys();
|
|
161
|
+
},
|
|
162
|
+
cwd() {
|
|
163
|
+
throw enosys();
|
|
164
|
+
},
|
|
165
|
+
chdir() {
|
|
166
|
+
throw enosys();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (!globalThis.crypto) {
|
|
171
|
+
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
|
172
|
+
}
|
|
173
|
+
if (!globalThis.performance) {
|
|
174
|
+
throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
|
|
175
|
+
}
|
|
176
|
+
if (!globalThis.TextEncoder) {
|
|
177
|
+
throw new Error("globalThis.TextEncoder is not available, polyfill required");
|
|
178
|
+
}
|
|
179
|
+
if (!globalThis.TextDecoder) {
|
|
180
|
+
throw new Error("globalThis.TextDecoder is not available, polyfill required");
|
|
181
|
+
}
|
|
182
|
+
const encoder = new TextEncoder("utf-8");
|
|
183
|
+
const decoder = new TextDecoder("utf-8");
|
|
184
|
+
globalThis.Go = class {
|
|
185
|
+
constructor() {
|
|
186
|
+
this.argv = ["js"];
|
|
187
|
+
this.env = {};
|
|
188
|
+
this.exit = (code) => {
|
|
189
|
+
if (code !== 0) {
|
|
190
|
+
console.warn("exit code:", code);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
this._exitPromise = new Promise((resolve) => {
|
|
194
|
+
this._resolveExitPromise = resolve;
|
|
195
|
+
});
|
|
196
|
+
this._pendingEvent = null;
|
|
197
|
+
this._scheduledTimeouts = /* @__PURE__ */ new Map();
|
|
198
|
+
this._nextCallbackTimeoutID = 1;
|
|
199
|
+
const setInt64 = (addr, v) => {
|
|
200
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
201
|
+
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
202
|
+
};
|
|
203
|
+
const setInt32 = (addr, v) => {
|
|
204
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
205
|
+
};
|
|
206
|
+
const getInt64 = (addr) => {
|
|
207
|
+
const low = this.mem.getUint32(addr + 0, true);
|
|
208
|
+
const high = this.mem.getInt32(addr + 4, true);
|
|
209
|
+
return low + high * 4294967296;
|
|
210
|
+
};
|
|
211
|
+
const loadValue = (addr) => {
|
|
212
|
+
const f = this.mem.getFloat64(addr, true);
|
|
213
|
+
if (f === 0) {
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
if (!isNaN(f)) {
|
|
217
|
+
return f;
|
|
218
|
+
}
|
|
219
|
+
const id = this.mem.getUint32(addr, true);
|
|
220
|
+
return this._values[id];
|
|
221
|
+
};
|
|
222
|
+
const storeValue = (addr, v) => {
|
|
223
|
+
const nanHead = 2146959360;
|
|
224
|
+
if (typeof v === "number" && v !== 0) {
|
|
225
|
+
if (isNaN(v)) {
|
|
226
|
+
this.mem.setUint32(addr + 4, nanHead, true);
|
|
227
|
+
this.mem.setUint32(addr, 0, true);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.mem.setFloat64(addr, v, true);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (v === void 0) {
|
|
234
|
+
this.mem.setFloat64(addr, 0, true);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
let id = this._ids.get(v);
|
|
238
|
+
if (id === void 0) {
|
|
239
|
+
id = this._idPool.pop();
|
|
240
|
+
if (id === void 0) {
|
|
241
|
+
id = this._values.length;
|
|
242
|
+
}
|
|
243
|
+
this._values[id] = v;
|
|
244
|
+
this._goRefCounts[id] = 0;
|
|
245
|
+
this._ids.set(v, id);
|
|
246
|
+
}
|
|
247
|
+
this._goRefCounts[id]++;
|
|
248
|
+
let typeFlag = 0;
|
|
249
|
+
switch (typeof v) {
|
|
250
|
+
case "object":
|
|
251
|
+
if (v !== null) {
|
|
252
|
+
typeFlag = 1;
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case "string":
|
|
256
|
+
typeFlag = 2;
|
|
257
|
+
break;
|
|
258
|
+
case "symbol":
|
|
259
|
+
typeFlag = 3;
|
|
260
|
+
break;
|
|
261
|
+
case "function":
|
|
262
|
+
typeFlag = 4;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
266
|
+
this.mem.setUint32(addr, id, true);
|
|
267
|
+
};
|
|
268
|
+
const loadSlice = (addr) => {
|
|
269
|
+
const array = getInt64(addr + 0);
|
|
270
|
+
const len = getInt64(addr + 8);
|
|
271
|
+
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
272
|
+
};
|
|
273
|
+
const loadSliceOfValues = (addr) => {
|
|
274
|
+
const array = getInt64(addr + 0);
|
|
275
|
+
const len = getInt64(addr + 8);
|
|
276
|
+
const a = new Array(len);
|
|
277
|
+
for (let i = 0; i < len; i++) {
|
|
278
|
+
a[i] = loadValue(array + i * 8);
|
|
279
|
+
}
|
|
280
|
+
return a;
|
|
281
|
+
};
|
|
282
|
+
const loadString = (addr) => {
|
|
283
|
+
const saddr = getInt64(addr + 0);
|
|
284
|
+
const len = getInt64(addr + 8);
|
|
285
|
+
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
286
|
+
};
|
|
287
|
+
const timeOrigin = Date.now() - performance.now();
|
|
288
|
+
this.importObject = {
|
|
289
|
+
_gotest: {
|
|
290
|
+
add: (a, b) => a + b
|
|
291
|
+
},
|
|
292
|
+
gojs: {
|
|
293
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
294
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
295
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
296
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
297
|
+
// func wasmExit(code int32)
|
|
298
|
+
"runtime.wasmExit": (sp) => {
|
|
299
|
+
sp >>>= 0;
|
|
300
|
+
const code = this.mem.getInt32(sp + 8, true);
|
|
301
|
+
this.exited = true;
|
|
302
|
+
delete this._inst;
|
|
303
|
+
delete this._values;
|
|
304
|
+
delete this._goRefCounts;
|
|
305
|
+
delete this._ids;
|
|
306
|
+
delete this._idPool;
|
|
307
|
+
this.exit(code);
|
|
308
|
+
},
|
|
309
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
310
|
+
"runtime.wasmWrite": (sp) => {
|
|
311
|
+
sp >>>= 0;
|
|
312
|
+
const fd = getInt64(sp + 8);
|
|
313
|
+
const p = getInt64(sp + 16);
|
|
314
|
+
const n = this.mem.getInt32(sp + 24, true);
|
|
315
|
+
fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
316
|
+
},
|
|
317
|
+
// func resetMemoryDataView()
|
|
318
|
+
"runtime.resetMemoryDataView": (sp) => {
|
|
319
|
+
sp >>>= 0;
|
|
320
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
321
|
+
},
|
|
322
|
+
// func nanotime1() int64
|
|
323
|
+
"runtime.nanotime1": (sp) => {
|
|
324
|
+
sp >>>= 0;
|
|
325
|
+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
|
|
326
|
+
},
|
|
327
|
+
// func walltime() (sec int64, nsec int32)
|
|
328
|
+
"runtime.walltime": (sp) => {
|
|
329
|
+
sp >>>= 0;
|
|
330
|
+
const msec = (/* @__PURE__ */ new Date()).getTime();
|
|
331
|
+
setInt64(sp + 8, msec / 1e3);
|
|
332
|
+
this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
|
|
333
|
+
},
|
|
334
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
|
335
|
+
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
336
|
+
sp >>>= 0;
|
|
337
|
+
const id = this._nextCallbackTimeoutID;
|
|
338
|
+
this._nextCallbackTimeoutID++;
|
|
339
|
+
this._scheduledTimeouts.set(id, setTimeout(
|
|
340
|
+
() => {
|
|
341
|
+
this._resume();
|
|
342
|
+
while (this._scheduledTimeouts.has(id)) {
|
|
343
|
+
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
344
|
+
this._resume();
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
getInt64(sp + 8)
|
|
348
|
+
));
|
|
349
|
+
this.mem.setInt32(sp + 16, id, true);
|
|
350
|
+
},
|
|
351
|
+
// func clearTimeoutEvent(id int32)
|
|
352
|
+
"runtime.clearTimeoutEvent": (sp) => {
|
|
353
|
+
sp >>>= 0;
|
|
354
|
+
const id = this.mem.getInt32(sp + 8, true);
|
|
355
|
+
clearTimeout(this._scheduledTimeouts.get(id));
|
|
356
|
+
this._scheduledTimeouts.delete(id);
|
|
357
|
+
},
|
|
358
|
+
// func getRandomData(r []byte)
|
|
359
|
+
"runtime.getRandomData": (sp) => {
|
|
360
|
+
sp >>>= 0;
|
|
361
|
+
crypto.getRandomValues(loadSlice(sp + 8));
|
|
362
|
+
},
|
|
363
|
+
// func finalizeRef(v ref)
|
|
364
|
+
"syscall/js.finalizeRef": (sp) => {
|
|
365
|
+
sp >>>= 0;
|
|
366
|
+
const id = this.mem.getUint32(sp + 8, true);
|
|
367
|
+
this._goRefCounts[id]--;
|
|
368
|
+
if (this._goRefCounts[id] === 0) {
|
|
369
|
+
const v = this._values[id];
|
|
370
|
+
this._values[id] = null;
|
|
371
|
+
this._ids.delete(v);
|
|
372
|
+
this._idPool.push(id);
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
// func stringVal(value string) ref
|
|
376
|
+
"syscall/js.stringVal": (sp) => {
|
|
377
|
+
sp >>>= 0;
|
|
378
|
+
storeValue(sp + 24, loadString(sp + 8));
|
|
379
|
+
},
|
|
380
|
+
// func valueGet(v ref, p string) ref
|
|
381
|
+
"syscall/js.valueGet": (sp) => {
|
|
382
|
+
sp >>>= 0;
|
|
383
|
+
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
384
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
385
|
+
storeValue(sp + 32, result);
|
|
386
|
+
},
|
|
387
|
+
// func valueSet(v ref, p string, x ref)
|
|
388
|
+
"syscall/js.valueSet": (sp) => {
|
|
389
|
+
sp >>>= 0;
|
|
390
|
+
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
391
|
+
},
|
|
392
|
+
// func valueDelete(v ref, p string)
|
|
393
|
+
"syscall/js.valueDelete": (sp) => {
|
|
394
|
+
sp >>>= 0;
|
|
395
|
+
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
396
|
+
},
|
|
397
|
+
// func valueIndex(v ref, i int) ref
|
|
398
|
+
"syscall/js.valueIndex": (sp) => {
|
|
399
|
+
sp >>>= 0;
|
|
400
|
+
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
401
|
+
},
|
|
402
|
+
// valueSetIndex(v ref, i int, x ref)
|
|
403
|
+
"syscall/js.valueSetIndex": (sp) => {
|
|
404
|
+
sp >>>= 0;
|
|
405
|
+
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
406
|
+
},
|
|
407
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
408
|
+
"syscall/js.valueCall": (sp) => {
|
|
409
|
+
sp >>>= 0;
|
|
410
|
+
try {
|
|
411
|
+
const v = loadValue(sp + 8);
|
|
412
|
+
const m = Reflect.get(v, loadString(sp + 16));
|
|
413
|
+
const args = loadSliceOfValues(sp + 32);
|
|
414
|
+
const result = Reflect.apply(m, v, args);
|
|
415
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
416
|
+
storeValue(sp + 56, result);
|
|
417
|
+
this.mem.setUint8(sp + 64, 1);
|
|
418
|
+
} catch (err) {
|
|
419
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
420
|
+
storeValue(sp + 56, err);
|
|
421
|
+
this.mem.setUint8(sp + 64, 0);
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
425
|
+
"syscall/js.valueInvoke": (sp) => {
|
|
426
|
+
sp >>>= 0;
|
|
427
|
+
try {
|
|
428
|
+
const v = loadValue(sp + 8);
|
|
429
|
+
const args = loadSliceOfValues(sp + 16);
|
|
430
|
+
const result = Reflect.apply(v, void 0, args);
|
|
431
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
432
|
+
storeValue(sp + 40, result);
|
|
433
|
+
this.mem.setUint8(sp + 48, 1);
|
|
434
|
+
} catch (err) {
|
|
435
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
436
|
+
storeValue(sp + 40, err);
|
|
437
|
+
this.mem.setUint8(sp + 48, 0);
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
|
441
|
+
"syscall/js.valueNew": (sp) => {
|
|
442
|
+
sp >>>= 0;
|
|
443
|
+
try {
|
|
444
|
+
const v = loadValue(sp + 8);
|
|
445
|
+
const args = loadSliceOfValues(sp + 16);
|
|
446
|
+
const result = Reflect.construct(v, args);
|
|
447
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
448
|
+
storeValue(sp + 40, result);
|
|
449
|
+
this.mem.setUint8(sp + 48, 1);
|
|
450
|
+
} catch (err) {
|
|
451
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
452
|
+
storeValue(sp + 40, err);
|
|
453
|
+
this.mem.setUint8(sp + 48, 0);
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
// func valueLength(v ref) int
|
|
457
|
+
"syscall/js.valueLength": (sp) => {
|
|
458
|
+
sp >>>= 0;
|
|
459
|
+
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
460
|
+
},
|
|
461
|
+
// valuePrepareString(v ref) (ref, int)
|
|
462
|
+
"syscall/js.valuePrepareString": (sp) => {
|
|
463
|
+
sp >>>= 0;
|
|
464
|
+
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
465
|
+
storeValue(sp + 16, str);
|
|
466
|
+
setInt64(sp + 24, str.length);
|
|
467
|
+
},
|
|
468
|
+
// valueLoadString(v ref, b []byte)
|
|
469
|
+
"syscall/js.valueLoadString": (sp) => {
|
|
470
|
+
sp >>>= 0;
|
|
471
|
+
const str = loadValue(sp + 8);
|
|
472
|
+
loadSlice(sp + 16).set(str);
|
|
473
|
+
},
|
|
474
|
+
// func valueInstanceOf(v ref, t ref) bool
|
|
475
|
+
"syscall/js.valueInstanceOf": (sp) => {
|
|
476
|
+
sp >>>= 0;
|
|
477
|
+
this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
|
|
478
|
+
},
|
|
479
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
480
|
+
"syscall/js.copyBytesToGo": (sp) => {
|
|
481
|
+
sp >>>= 0;
|
|
482
|
+
const dst = loadSlice(sp + 8);
|
|
483
|
+
const src = loadValue(sp + 32);
|
|
484
|
+
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
485
|
+
this.mem.setUint8(sp + 48, 0);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const toCopy = src.subarray(0, dst.length);
|
|
489
|
+
dst.set(toCopy);
|
|
490
|
+
setInt64(sp + 40, toCopy.length);
|
|
491
|
+
this.mem.setUint8(sp + 48, 1);
|
|
492
|
+
},
|
|
493
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
494
|
+
"syscall/js.copyBytesToJS": (sp) => {
|
|
495
|
+
sp >>>= 0;
|
|
496
|
+
const dst = loadValue(sp + 8);
|
|
497
|
+
const src = loadSlice(sp + 16);
|
|
498
|
+
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
499
|
+
this.mem.setUint8(sp + 48, 0);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const toCopy = src.subarray(0, dst.length);
|
|
503
|
+
dst.set(toCopy);
|
|
504
|
+
setInt64(sp + 40, toCopy.length);
|
|
505
|
+
this.mem.setUint8(sp + 48, 1);
|
|
506
|
+
},
|
|
507
|
+
"debug": (value) => {
|
|
508
|
+
console.log(value);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
async run(instance) {
|
|
514
|
+
if (!(instance instanceof WebAssembly.Instance)) {
|
|
515
|
+
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
516
|
+
}
|
|
517
|
+
this._inst = instance;
|
|
518
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
519
|
+
this._values = [
|
|
520
|
+
// JS values that Go currently has references to, indexed by reference id
|
|
521
|
+
NaN,
|
|
522
|
+
0,
|
|
523
|
+
null,
|
|
524
|
+
true,
|
|
525
|
+
false,
|
|
526
|
+
globalThis,
|
|
527
|
+
this
|
|
528
|
+
];
|
|
529
|
+
this._goRefCounts = new Array(this._values.length).fill(Infinity);
|
|
530
|
+
this._ids = /* @__PURE__ */ new Map([
|
|
531
|
+
// mapping from JS values to reference ids
|
|
532
|
+
[0, 1],
|
|
533
|
+
[null, 2],
|
|
534
|
+
[true, 3],
|
|
535
|
+
[false, 4],
|
|
536
|
+
[globalThis, 5],
|
|
537
|
+
[this, 6]
|
|
538
|
+
]);
|
|
539
|
+
this._idPool = [];
|
|
540
|
+
this.exited = false;
|
|
541
|
+
let offset = 4096;
|
|
542
|
+
const strPtr = (str) => {
|
|
543
|
+
const ptr = offset;
|
|
544
|
+
const bytes = encoder.encode(str + "\0");
|
|
545
|
+
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
546
|
+
offset += bytes.length;
|
|
547
|
+
if (offset % 8 !== 0) {
|
|
548
|
+
offset += 8 - offset % 8;
|
|
549
|
+
}
|
|
550
|
+
return ptr;
|
|
551
|
+
};
|
|
552
|
+
const argc = this.argv.length;
|
|
553
|
+
const argvPtrs = [];
|
|
554
|
+
this.argv.forEach((arg) => {
|
|
555
|
+
argvPtrs.push(strPtr(arg));
|
|
556
|
+
});
|
|
557
|
+
argvPtrs.push(0);
|
|
558
|
+
const keys = Object.keys(this.env).sort();
|
|
559
|
+
keys.forEach((key) => {
|
|
560
|
+
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
561
|
+
});
|
|
562
|
+
argvPtrs.push(0);
|
|
563
|
+
const argv = offset;
|
|
564
|
+
argvPtrs.forEach((ptr) => {
|
|
565
|
+
this.mem.setUint32(offset, ptr, true);
|
|
566
|
+
this.mem.setUint32(offset + 4, 0, true);
|
|
567
|
+
offset += 8;
|
|
568
|
+
});
|
|
569
|
+
const wasmMinDataAddr = 4096 + 8192;
|
|
570
|
+
if (offset >= wasmMinDataAddr) {
|
|
571
|
+
throw new Error("total length of command line and environment variables exceeds limit");
|
|
572
|
+
}
|
|
573
|
+
this._inst.exports.run(argc, argv);
|
|
574
|
+
if (this.exited) {
|
|
575
|
+
this._resolveExitPromise();
|
|
576
|
+
}
|
|
577
|
+
await this._exitPromise;
|
|
578
|
+
}
|
|
579
|
+
_resume() {
|
|
580
|
+
if (this.exited) {
|
|
581
|
+
throw new Error("Go program has already exited");
|
|
582
|
+
}
|
|
583
|
+
this._inst.exports.resume();
|
|
584
|
+
if (this.exited) {
|
|
585
|
+
this._resolveExitPromise();
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
_makeFuncWrapper(id) {
|
|
589
|
+
const go = this;
|
|
590
|
+
return function() {
|
|
591
|
+
const event = { id, this: this, args: arguments };
|
|
592
|
+
go._pendingEvent = event;
|
|
593
|
+
go._resume();
|
|
594
|
+
return event.result;
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
})();
|
|
599
|
+
module2.exports = {
|
|
600
|
+
globalThisCopy
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// src/workers/worker.ts
|
|
606
|
+
var worker_exports = {};
|
|
607
|
+
__export(worker_exports, {
|
|
608
|
+
handleMessage: () => handleMessage
|
|
609
|
+
});
|
|
610
|
+
module.exports = __toCommonJS(worker_exports);
|
|
611
|
+
var import_axios = __toESM(require("axios"));
|
|
612
|
+
var import_core_sdk2 = require("@getpara/core-sdk");
|
|
613
|
+
|
|
614
|
+
// src/workers/walletUtils.ts
|
|
615
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
616
|
+
var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
617
|
+
var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
618
|
+
async function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
619
|
+
const { data } = await ctx.mpcComputationClient.post("/wallets", {
|
|
620
|
+
userId,
|
|
621
|
+
walletId,
|
|
622
|
+
protocolId
|
|
623
|
+
});
|
|
624
|
+
return data;
|
|
625
|
+
}
|
|
626
|
+
async function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
|
|
627
|
+
const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
|
|
628
|
+
userId,
|
|
629
|
+
protocolId,
|
|
630
|
+
message,
|
|
631
|
+
signer
|
|
632
|
+
});
|
|
633
|
+
return data;
|
|
634
|
+
}
|
|
635
|
+
async function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
|
|
636
|
+
const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
|
|
637
|
+
userId,
|
|
638
|
+
protocolId,
|
|
639
|
+
transaction,
|
|
640
|
+
signer,
|
|
641
|
+
chainId
|
|
642
|
+
});
|
|
643
|
+
return data;
|
|
644
|
+
}
|
|
645
|
+
async function ed25519Keygen(ctx, userId) {
|
|
646
|
+
const { walletId, protocolId } = await ctx.client.createWallet(userId, {
|
|
647
|
+
scheme: import_core_sdk.WalletScheme.ED25519,
|
|
648
|
+
type: import_core_sdk.WalletType.SOLANA
|
|
649
|
+
});
|
|
650
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
651
|
+
try {
|
|
652
|
+
const newSigner = await new Promise(
|
|
653
|
+
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
654
|
+
if (err) {
|
|
655
|
+
reject(err);
|
|
656
|
+
}
|
|
657
|
+
resolve(result);
|
|
658
|
+
})
|
|
659
|
+
);
|
|
660
|
+
return { signer: newSigner, walletId };
|
|
661
|
+
} catch (e) {
|
|
662
|
+
throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
666
|
+
const { walletId, protocolId } = await ctx.client.createPregenWallet({
|
|
667
|
+
pregenIdentifier,
|
|
668
|
+
pregenIdentifierType,
|
|
669
|
+
scheme: import_core_sdk.WalletScheme.ED25519,
|
|
670
|
+
type: import_core_sdk.WalletType.SOLANA
|
|
671
|
+
});
|
|
672
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
673
|
+
try {
|
|
674
|
+
const newSigner = await new Promise(
|
|
675
|
+
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
676
|
+
if (err) {
|
|
677
|
+
reject(err);
|
|
678
|
+
}
|
|
679
|
+
resolve(result);
|
|
680
|
+
})
|
|
681
|
+
);
|
|
682
|
+
return { signer: newSigner, walletId };
|
|
683
|
+
} catch (e) {
|
|
684
|
+
throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
688
|
+
const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, import_core_sdk.WalletScheme.ED25519);
|
|
689
|
+
try {
|
|
690
|
+
const base64Sig = await new Promise(
|
|
691
|
+
(resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
692
|
+
if (err) {
|
|
693
|
+
reject(err);
|
|
694
|
+
}
|
|
695
|
+
resolve(result);
|
|
696
|
+
})
|
|
697
|
+
);
|
|
698
|
+
return { signature: base64Sig };
|
|
699
|
+
} catch (e) {
|
|
700
|
+
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
async function keygen(ctx, userId, type, secretKey) {
|
|
704
|
+
const { walletId, protocolId } = await ctx.client.createWallet(userId, {
|
|
705
|
+
useTwoSigners: true,
|
|
706
|
+
scheme: ctx.useDKLS ? import_core_sdk.WalletScheme.DKLS : import_core_sdk.WalletScheme.CGGMP,
|
|
707
|
+
type,
|
|
708
|
+
cosmosPrefix: type === import_core_sdk.WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
709
|
+
});
|
|
710
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
711
|
+
return {
|
|
712
|
+
signer: (await keygenRequest(ctx, userId, walletId, protocolId)).signer,
|
|
713
|
+
walletId
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
717
|
+
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
718
|
+
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
719
|
+
try {
|
|
720
|
+
const newSigner = await new Promise(
|
|
721
|
+
(resolve, reject) => createAccountFn(
|
|
722
|
+
signerConfigUser,
|
|
723
|
+
serverUrl,
|
|
724
|
+
protocolId,
|
|
725
|
+
secretKey,
|
|
726
|
+
() => {
|
|
727
|
+
},
|
|
728
|
+
// no-op for deprecated callback to update progress percentage
|
|
729
|
+
(err, result) => {
|
|
730
|
+
if (err) {
|
|
731
|
+
reject(err);
|
|
732
|
+
}
|
|
733
|
+
resolve(result);
|
|
734
|
+
}
|
|
735
|
+
)
|
|
736
|
+
);
|
|
737
|
+
return { signer: newSigner, walletId };
|
|
738
|
+
} catch (e) {
|
|
739
|
+
throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
|
|
743
|
+
const { walletId, protocolId } = await ctx.client.createPregenWallet({
|
|
744
|
+
pregenIdentifier,
|
|
745
|
+
pregenIdentifierType,
|
|
746
|
+
type,
|
|
747
|
+
cosmosPrefix: type === import_core_sdk.WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
748
|
+
});
|
|
749
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
750
|
+
return {
|
|
751
|
+
signer: (await keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
|
|
752
|
+
walletId
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
756
|
+
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
757
|
+
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
758
|
+
try {
|
|
759
|
+
const newSigner = await new Promise(
|
|
760
|
+
(resolve, reject) => createAccountFn(
|
|
761
|
+
signerConfigUser,
|
|
762
|
+
serverUrl,
|
|
763
|
+
protocolId,
|
|
764
|
+
secretKey,
|
|
765
|
+
() => {
|
|
766
|
+
},
|
|
767
|
+
// no-op for deprecated callback to update progress percentage
|
|
768
|
+
(err, result) => {
|
|
769
|
+
if (err) {
|
|
770
|
+
reject(err);
|
|
771
|
+
}
|
|
772
|
+
resolve(result);
|
|
773
|
+
}
|
|
774
|
+
)
|
|
775
|
+
);
|
|
776
|
+
return { signer: newSigner, walletId };
|
|
777
|
+
} catch (e) {
|
|
778
|
+
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
async function signMessage(ctx, share, walletId, userId, message) {
|
|
782
|
+
const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(userId, walletId, message);
|
|
783
|
+
if (pendingTransactionId) {
|
|
784
|
+
return { pendingTransactionId };
|
|
785
|
+
}
|
|
786
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
787
|
+
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
788
|
+
}
|
|
789
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
790
|
+
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
791
|
+
try {
|
|
792
|
+
return new Promise(
|
|
793
|
+
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
794
|
+
if (err) {
|
|
795
|
+
reject(err);
|
|
796
|
+
}
|
|
797
|
+
resolve({ signature: result });
|
|
798
|
+
})
|
|
799
|
+
);
|
|
800
|
+
} catch (e) {
|
|
801
|
+
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
805
|
+
const {
|
|
806
|
+
data: { protocolId, pendingTransactionId }
|
|
807
|
+
} = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
808
|
+
if (pendingTransactionId) {
|
|
809
|
+
return { pendingTransactionId };
|
|
810
|
+
}
|
|
811
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
812
|
+
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
813
|
+
}
|
|
814
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
815
|
+
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
816
|
+
try {
|
|
817
|
+
return new Promise(
|
|
818
|
+
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
819
|
+
if (err) {
|
|
820
|
+
reject(err);
|
|
821
|
+
}
|
|
822
|
+
resolve({ signature: result });
|
|
823
|
+
})
|
|
824
|
+
);
|
|
825
|
+
} catch (e) {
|
|
826
|
+
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
830
|
+
const {
|
|
831
|
+
data: { protocolId, pendingTransactionId }
|
|
832
|
+
} = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
833
|
+
if (pendingTransactionId) {
|
|
834
|
+
return { pendingTransactionId };
|
|
835
|
+
}
|
|
836
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
837
|
+
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
838
|
+
}
|
|
839
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
840
|
+
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
841
|
+
try {
|
|
842
|
+
return new Promise(
|
|
843
|
+
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
844
|
+
if (err) {
|
|
845
|
+
reject(err);
|
|
846
|
+
}
|
|
847
|
+
resolve({ signature: result });
|
|
848
|
+
})
|
|
849
|
+
);
|
|
850
|
+
} catch (e) {
|
|
851
|
+
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
async function refresh(ctx, share, walletId, userId) {
|
|
855
|
+
const {
|
|
856
|
+
data: { protocolId }
|
|
857
|
+
} = await ctx.client.refreshKeys(userId, walletId);
|
|
858
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
859
|
+
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
860
|
+
try {
|
|
861
|
+
return new Promise(
|
|
862
|
+
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
863
|
+
if (err) {
|
|
864
|
+
reject(err);
|
|
865
|
+
}
|
|
866
|
+
resolve(result);
|
|
867
|
+
})
|
|
868
|
+
);
|
|
869
|
+
} catch (e) {
|
|
870
|
+
throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
async function getPrivateKey(ctx, share, walletId, userId) {
|
|
874
|
+
const paraShare = await ctx.client.getParaShare(userId, walletId);
|
|
875
|
+
if (!paraShare) {
|
|
876
|
+
console.error("unable to retrieve Para share");
|
|
877
|
+
return "";
|
|
878
|
+
}
|
|
879
|
+
try {
|
|
880
|
+
return new Promise(
|
|
881
|
+
(resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
882
|
+
if (err) {
|
|
883
|
+
reject(err);
|
|
884
|
+
}
|
|
885
|
+
resolve(result);
|
|
886
|
+
})
|
|
887
|
+
);
|
|
888
|
+
} catch (e) {
|
|
889
|
+
throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// src/workers/worker.ts
|
|
894
|
+
var rawWasm;
|
|
895
|
+
async function requestWasmWithRetries(ctx, retries = 3) {
|
|
896
|
+
for (let i = 0; i < retries; i++) {
|
|
897
|
+
try {
|
|
898
|
+
return await import_axios.default.get(`${(0, import_core_sdk2.getPortalBaseURL)(ctx, true, true)}/static/js/main.wasm`, { responseType: "arraybuffer" });
|
|
899
|
+
} catch (e) {
|
|
900
|
+
if (i === retries - 1) {
|
|
901
|
+
throw e;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
async function loadWasm(ctx) {
|
|
907
|
+
await Promise.resolve().then(() => __toESM(require_wasm_exec()));
|
|
908
|
+
global.WebSocket = require("ws");
|
|
909
|
+
const goWasm = new global.Go();
|
|
910
|
+
if (!rawWasm) {
|
|
911
|
+
rawWasm = (await requestWasmWithRetries(ctx)).data;
|
|
912
|
+
}
|
|
913
|
+
const wasmBuffer = new Uint8Array(rawWasm);
|
|
914
|
+
const webAssemblySource = await WebAssembly.instantiate(wasmBuffer, goWasm.importObject);
|
|
915
|
+
goWasm.run(webAssemblySource.instance);
|
|
916
|
+
}
|
|
917
|
+
async function executeMessage(ctx, message) {
|
|
918
|
+
const { functionType, params } = message;
|
|
919
|
+
switch (functionType) {
|
|
920
|
+
case "KEYGEN": {
|
|
921
|
+
const { userId, secretKey, type = import_core_sdk2.WalletType.EVM } = params;
|
|
922
|
+
return keygen(ctx, userId, type, secretKey);
|
|
923
|
+
}
|
|
924
|
+
case "SIGN_TRANSACTION": {
|
|
925
|
+
const { share, walletId, userId, tx, chainId } = params;
|
|
926
|
+
return signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
927
|
+
}
|
|
928
|
+
case "SEND_TRANSACTION": {
|
|
929
|
+
const { share, walletId, userId, tx, chainId } = params;
|
|
930
|
+
return sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
931
|
+
}
|
|
932
|
+
case "SIGN_MESSAGE": {
|
|
933
|
+
const { share, walletId, userId, message: message2 } = params;
|
|
934
|
+
return signMessage(ctx, share, walletId, userId, message2);
|
|
935
|
+
}
|
|
936
|
+
case "REFRESH": {
|
|
937
|
+
const { share, walletId, userId } = params;
|
|
938
|
+
return refresh(ctx, share, walletId, userId);
|
|
939
|
+
}
|
|
940
|
+
case "PREKEYGEN": {
|
|
941
|
+
const { email, partnerId, secretKey, type = import_core_sdk2.WalletType.EVM } = params;
|
|
942
|
+
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
943
|
+
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
944
|
+
pregenIdentifier = email;
|
|
945
|
+
pregenIdentifierType = "EMAIL";
|
|
946
|
+
}
|
|
947
|
+
const keygenRes = await preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
948
|
+
return keygenRes;
|
|
949
|
+
}
|
|
950
|
+
case "GET_PRIVATE_KEY": {
|
|
951
|
+
const { share, walletId, userId } = params;
|
|
952
|
+
return await getPrivateKey(ctx, share, walletId, userId);
|
|
953
|
+
}
|
|
954
|
+
case "ED25519_KEYGEN": {
|
|
955
|
+
const { userId } = params;
|
|
956
|
+
return ed25519Keygen(ctx, userId);
|
|
957
|
+
}
|
|
958
|
+
case "ED25519_SIGN": {
|
|
959
|
+
const { share, walletId, userId, base64Bytes } = params;
|
|
960
|
+
return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
961
|
+
}
|
|
962
|
+
case "ED25519_PREKEYGEN": {
|
|
963
|
+
const { email } = params;
|
|
964
|
+
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
965
|
+
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
966
|
+
pregenIdentifier = email;
|
|
967
|
+
pregenIdentifierType = "EMAIL";
|
|
968
|
+
}
|
|
969
|
+
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
970
|
+
}
|
|
971
|
+
default: {
|
|
972
|
+
throw new Error(`functionType: ${functionType} not supported`);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
async function handleMessage(e) {
|
|
977
|
+
const {
|
|
978
|
+
env,
|
|
979
|
+
apiKey,
|
|
980
|
+
cosmosPrefix = "cosmos",
|
|
981
|
+
offloadMPCComputationURL,
|
|
982
|
+
disableWorkers,
|
|
983
|
+
sessionCookie,
|
|
984
|
+
useDKLS,
|
|
985
|
+
disableWebSockets,
|
|
986
|
+
workId
|
|
987
|
+
} = e.data;
|
|
988
|
+
const ctx = {
|
|
989
|
+
env,
|
|
990
|
+
apiKey,
|
|
991
|
+
client: (0, import_core_sdk2.initClient)({ env, version: import_core_sdk2.paraVersion, apiKey, retrieveSessionCookie: () => sessionCookie }),
|
|
992
|
+
offloadMPCComputationURL,
|
|
993
|
+
mpcComputationClient: offloadMPCComputationURL ? import_core_sdk2.mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
|
|
994
|
+
useDKLS,
|
|
995
|
+
disableWebSockets: !!disableWebSockets,
|
|
996
|
+
cosmosPrefix
|
|
997
|
+
};
|
|
998
|
+
if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
|
|
999
|
+
await loadWasm(ctx);
|
|
1000
|
+
}
|
|
1001
|
+
const result = await executeMessage(ctx, e.data);
|
|
1002
|
+
result.workId = workId;
|
|
1003
|
+
return result;
|
|
1004
|
+
}
|
|
1005
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1006
|
+
0 && (module.exports = {
|
|
1007
|
+
handleMessage
|
|
1008
|
+
});
|