@getpara/web-sdk 1.4.3 → 1.4.4
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/index.js +1735 -3
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/workers/worker.js +993 -2
- package/dist/workers/worker.js.br +0 -0
- package/dist/workers/worker.js.gz +0 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,1736 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
`);return o!=-1&&(console.log(i.substring(0,o)),i=i.substring(o+1)),n.length},write(s,n,o,l,g,u){if(o!==0||l!==n.length||g!==null){u(e());return}let d=this.writeSync(s,n);u(null,d)},chmod(s,n,o){o(e())},chown(s,n,o,l){l(e())},close(s,n){n(e())},fchmod(s,n,o){o(e())},fchown(s,n,o,l){l(e())},fstat(s,n){n(e())},fsync(s,n){n(null)},ftruncate(s,n,o){o(e())},lchown(s,n,o,l){l(e())},link(s,n,o){o(e())},lstat(s,n){n(e())},mkdir(s,n,o){o(e())},open(s,n,o,l){l(e())},read(s,n,o,l,g,u){u(e())},readdir(s,n){n(e())},readlink(s,n){n(e())},rename(s,n,o){o(e())},rmdir(s,n){n(e())},stat(s,n){n(e())},symlink(s,n,o){o(e())},truncate(s,n,o){o(e())},unlink(s,n){n(e())},utimes(s,n,o,l){l(e())}}}if(globalThis.process||(globalThis.process={getuid(){return-1},getgid(){return-1},geteuid(){return-1},getegid(){return-1},getgroups(){throw e()},pid:-1,ppid:-1,umask(){throw e()},cwd(){throw e()},chdir(){throw e()}}),!globalThis.crypto)throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");if(globalThis.performance||(globalThis.performance=Date),!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 r=new TextEncoder("utf-8"),a=new TextDecoder("utf-8");globalThis.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=t=>{t!==0&&console.warn("exit code:",t)},this._exitPromise=new Promise(t=>{this._resolveExitPromise=t}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;let i=(t,c)=>{this.mem.setUint32(t+0,c,!0),this.mem.setUint32(t+4,Math.floor(c/4294967296),!0)},s=(t,c)=>{this.mem.setUint32(t+0,c,!0)},n=t=>{let c=this.mem.getUint32(t+0,!0),f=this.mem.getInt32(t+4,!0);return c+f*4294967296},o=t=>{let c=this.mem.getFloat64(t,!0);if(c===0)return;if(!isNaN(c))return c;let f=this.mem.getUint32(t,!0);return this._values[f]},l=(t,c)=>{if(typeof c=="number"&&c!==0){if(isNaN(c)){this.mem.setUint32(t+4,2146959360,!0),this.mem.setUint32(t,0,!0);return}this.mem.setFloat64(t,c,!0);return}if(c===void 0){this.mem.setFloat64(t,0,!0);return}let p=this._ids.get(c);p===void 0&&(p=this._idPool.pop(),p===void 0&&(p=this._values.length),this._values[p]=c,this._goRefCounts[p]=0,this._ids.set(c,p)),this._goRefCounts[p]++;let y=0;switch(typeof c){case"object":c!==null&&(y=1);break;case"string":y=2;break;case"symbol":y=3;break;case"function":y=4;break}this.mem.setUint32(t+4,2146959360|y,!0),this.mem.setUint32(t,p,!0)},g=t=>{let c=n(t+0),f=n(t+8);return new Uint8Array(this._inst.exports.mem.buffer,c,f)},u=t=>{let c=n(t+0),f=n(t+8),p=new Array(f);for(let y=0;y<f;y++)p[y]=o(c+y*8);return p},d=t=>{let c=n(t+0),f=n(t+8);return a.decode(new DataView(this._inst.exports.mem.buffer,c,f))},m=Date.now()-performance.now();this.importObject={_gotest:{add:(t,c)=>t+c},gojs:{"runtime.wasmExit":t=>{t>>>=0;let c=this.mem.getInt32(t+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(c)},"runtime.wasmWrite":t=>{t>>>=0;let c=n(t+8),f=n(t+16),p=this.mem.getInt32(t+24,!0);fs.writeSync(c,new Uint8Array(this._inst.exports.mem.buffer,f,p))},"runtime.resetMemoryDataView":t=>{t>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{t>>>=0,i(t+8,(m+performance.now())*1e6)},"runtime.walltime":t=>{t>>>=0;let c=new Date().getTime();i(t+8,c/1e3),this.mem.setInt32(t+16,c%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":t=>{t>>>=0;let c=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(c,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(c);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()},n(t+8))),this.mem.setInt32(t+16,c,!0)},"runtime.clearTimeoutEvent":t=>{t>>>=0;let c=this.mem.getInt32(t+8,!0);clearTimeout(this._scheduledTimeouts.get(c)),this._scheduledTimeouts.delete(c)},"runtime.getRandomData":t=>{t>>>=0,crypto.getRandomValues(g(t+8))},"syscall/js.finalizeRef":t=>{t>>>=0;let c=this.mem.getUint32(t+8,!0);if(this._goRefCounts[c]--,this._goRefCounts[c]===0){let f=this._values[c];this._values[c]=null,this._ids.delete(f),this._idPool.push(c)}},"syscall/js.stringVal":t=>{t>>>=0,l(t+24,d(t+8))},"syscall/js.valueGet":t=>{t>>>=0;let c=Reflect.get(o(t+8),d(t+16));t=this._inst.exports.getsp()>>>0,l(t+32,c)},"syscall/js.valueSet":t=>{t>>>=0,Reflect.set(o(t+8),d(t+16),o(t+32))},"syscall/js.valueDelete":t=>{t>>>=0,Reflect.deleteProperty(o(t+8),d(t+16))},"syscall/js.valueIndex":t=>{t>>>=0,l(t+24,Reflect.get(o(t+8),n(t+16)))},"syscall/js.valueSetIndex":t=>{t>>>=0,Reflect.set(o(t+8),n(t+16),o(t+24))},"syscall/js.valueCall":t=>{t>>>=0;try{let c=o(t+8),f=Reflect.get(c,d(t+16)),p=u(t+32),y=Reflect.apply(f,c,p);t=this._inst.exports.getsp()>>>0,l(t+56,y),this.mem.setUint8(t+64,1)}catch(c){t=this._inst.exports.getsp()>>>0,l(t+56,c),this.mem.setUint8(t+64,0)}},"syscall/js.valueInvoke":t=>{t>>>=0;try{let c=o(t+8),f=u(t+16),p=Reflect.apply(c,void 0,f);t=this._inst.exports.getsp()>>>0,l(t+40,p),this.mem.setUint8(t+48,1)}catch(c){t=this._inst.exports.getsp()>>>0,l(t+40,c),this.mem.setUint8(t+48,0)}},"syscall/js.valueNew":t=>{t>>>=0;try{let c=o(t+8),f=u(t+16),p=Reflect.construct(c,f);t=this._inst.exports.getsp()>>>0,l(t+40,p),this.mem.setUint8(t+48,1)}catch(c){t=this._inst.exports.getsp()>>>0,l(t+40,c),this.mem.setUint8(t+48,0)}},"syscall/js.valueLength":t=>{t>>>=0,i(t+16,parseInt(o(t+8).length))},"syscall/js.valuePrepareString":t=>{t>>>=0;let c=r.encode(String(o(t+8)));l(t+16,c),i(t+24,c.length)},"syscall/js.valueLoadString":t=>{t>>>=0;let c=o(t+8);g(t+16).set(c)},"syscall/js.valueInstanceOf":t=>{t>>>=0,this.mem.setUint8(t+24,o(t+8)instanceof o(t+16)?1:0)},"syscall/js.copyBytesToGo":t=>{t>>>=0;let c=g(t+8),f=o(t+32);if(!(f instanceof Uint8Array||f instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let p=f.subarray(0,c.length);c.set(p),i(t+40,p.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{t>>>=0;let c=o(t+8),f=g(t+16);if(!(c instanceof Uint8Array||c instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let p=f.subarray(0,c.length);c.set(p),i(t+40,p.length),this.mem.setUint8(t+48,1)},debug:t=>{console.log(t)}}}}async run(i){if(!(i instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=i,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 s=4096,n=m=>{let t=s,c=r.encode(m+"\0");return new Uint8Array(this.mem.buffer,s,c.length).set(c),s+=c.length,s%8!==0&&(s+=8-s%8),t},o=this.argv.length,l=[];this.argv.forEach(m=>{l.push(n(m))}),l.push(0),Object.keys(this.env).sort().forEach(m=>{l.push(n(`${m}=${this.env[m]}`))}),l.push(0);let u=s;if(l.forEach(m=>{this.mem.setUint32(s,m,!0),this.mem.setUint32(s+4,0,!0),s+=8}),s>=12288)throw new Error("total length of command line and environment variables exceeds limit");this._inst.exports.run(o,u),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(i){let s=this;return function(){let n={id:i,this:this,args:arguments};return s._pendingEvent=n,s._resume(),n.result}}}})();import{getBaseMPCNetworkUrl as h,WalletScheme as P,WalletType as E}from"@getpara/core-sdk";var ce=(e,r,a)=>`{"ServerUrl":"${e}", "WalletId": "${r}", "Id":"${a}", "Ids":["USER","CAPSULE"], "Threshold":1}`,K=(e,r,a)=>`{"walletId": "${e}", "id":"${r}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${a}}`;async function ge(e,r,a,i){let{data:s}=await e.mpcComputationClient.post("/wallets",{userId:r,walletId:a,protocolId:i});return s}async function ue(e,r,a,i,s,n){let{data:o}=await e.mpcComputationClient.post(`/wallets/${a}/messages/sign`,{userId:r,protocolId:i,message:s,signer:n});return o}async function O(e,r,a,i,s,n,o){let{data:l}=await e.mpcComputationClient.post(`/wallets/${a}/transactions/send`,{userId:r,protocolId:i,transaction:s,signer:n,chainId:o});return l}async function U(e,r){let{walletId:a,protocolId:i}=await e.client.createWallet(r,{scheme:P.ED25519,type:E.SOLANA}),s=h(e.env,!e.disableWebSockets);try{return{signer:await new Promise((o,l)=>globalThis.ed25519CreateAccount(s,a,i,(g,u)=>{g&&l(g),o(u)})),walletId:a}}catch{throw new Error(`error creating account of type SOLANA with userId ${r} and walletId ${a}`)}}async function _(e,r,a){let{walletId:i,protocolId:s}=await e.client.createPregenWallet({pregenIdentifier:r,pregenIdentifierType:a,scheme:P.ED25519,type:E.SOLANA}),n=h(e.env,!e.disableWebSockets);try{return{signer:await new Promise((l,g)=>globalThis.ed25519CreateAccount(n,i,s,(u,d)=>{u&&g(u),l(d)})),walletId:i}}catch{throw new Error(`error creating account of type SOLANA with walletId ${i}`)}}async function L(e,r,a,i,s){let{protocolId:n}=await e.client.preSignMessage(a,i,s,P.ED25519);try{return{signature:await new Promise((l,g)=>globalThis.ed25519Sign(r,n,s,(u,d)=>{u&&g(u),l(d)}))}}catch{throw new Error(`error signing for account of type SOLANA with userId ${a} and walletId ${i}`)}}async function D(e,r,a,i){let{walletId:s,protocolId:n}=await e.client.createWallet(r,{useTwoSigners:!0,scheme:e.useDKLS?P.DKLS:P.CGGMP,type:a,cosmosPrefix:a===E.COSMOS?e.cosmosPrefix:void 0});if(e.offloadMPCComputationURL&&!e.useDKLS)return{signer:(await ge(e,r,s,n)).signer,walletId:s};let o=h(e.env,!e.disableWebSockets),l=e.useDKLS?K(s,"USER",e.disableWebSockets):ce(o,s,"USER"),g=e.useDKLS?globalThis.dklsCreateAccount:globalThis.createAccountV2;try{return{signer:await new Promise((d,m)=>g(l,o,n,i,()=>{},(t,c)=>{t&&m(t),d(c)})),walletId:s}}catch{throw new Error(`error creating account of type ${a} with userId ${r} and walletId ${s}`)}}async function M(e,r,a,i,s,n){let{walletId:o,protocolId:l}=await e.client.createPregenWallet({pregenIdentifier:a,pregenIdentifierType:i,type:s,cosmosPrefix:s===E.COSMOS?e.cosmosPrefix:void 0}),g=h(e.env,!e.disableWebSockets),u=K(o,"USER",e.disableWebSockets);try{return{signer:await new Promise((m,t)=>globalThis.dklsCreateAccount(u,g,l,n,()=>{},(c,f)=>{c&&t(c),m(f)})),walletId:o}}catch{throw new Error(`error creating account of type ${s} with walletId ${o}`)}}async function N(e,r,a,i,s,n){let{protocolId:o,pendingTransactionId:l}=await e.client.preSignMessage(i,a,s,null,n);if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return ue(e,i,a,o,s,r);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSignMessage:globalThis.signMessage,d=JSON.parse(r);!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d);try{return await new Promise((m,t)=>u(r,g,s,o,(c,f)=>{c&&t(c),m({signature:f})}))}catch{throw new Error(`error signing for account with userId ${i} and walletId ${a}`)}}async function x(e,r,a,i,s,n){let{data:{protocolId:o,pendingTransactionId:l}}=await e.client.signTransaction(i,a,{transaction:s,chainId:n});if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return O(e,i,a,o,s,r,n);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSendTransaction:globalThis.sendTransaction,d=JSON.parse(r);!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d);try{return await new Promise((m,t)=>u(r,g,s,n,o,(c,f)=>{c&&t(c),m({signature:f})}))}catch{throw new Error(`error signing transaction for account with userId ${i} and walletId ${a}`)}}async function B(e,r,a,i,s,n){let{data:{protocolId:o,pendingTransactionId:l}}=await e.client.sendTransaction(i,a,{transaction:s,chainId:n});if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return O(e,i,a,o,s,r,n);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSendTransaction:globalThis.sendTransaction,d=JSON.parse(r);!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d);try{return await new Promise((m,t)=>u(r,g,s,n,o,(c,f)=>{c&&t(c),m({signature:f})}))}catch{throw new Error(`error signing transaction to send for account with userId ${i} and walletId ${a}`)}}async function $(e,r,a,i,s,n,o){let{data:{protocolId:l}}=await e.client.refreshKeys(i,a,s,n,o),g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsRefresh:globalThis.refresh,d=JSON.parse(r);!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d);try{return await new Promise((m,t)=>u(r,g,l,(c,f)=>{c&&t(c),m({protocolId:l,signer:f})}))}catch{throw new Error(`error refreshing keys for account with userId ${i} and walletId ${a}`)}}async function j(e,r,a,i){let s=await e.client.getParaShare(i,a);if(!s)return"";try{return await new Promise((n,o)=>globalThis.getPrivateKey(r,s,(l,g)=>{l&&o(l),n(g)}))}catch{throw new Error(`error getting private key for account with userId ${i} and walletId ${a}`)}}import{getPortalBaseURL as me,initClient as fe,mpcComputationClient as pe,paraVersion as we,WalletType as G}from"@getpara/core-sdk";async function ye(e,r){if(typeof self>"u")return;let a=new self.Go,i=r;if(!i){if(process.env.DISABLE_WASM_FETCH==="true")throw new Error("fetching wasm file is disabled");i=await(await fetch(`${me(e)}/static/js/main.wasm`,{mode:"cors"})).arrayBuffer()}let s=await WebAssembly.instantiate(i,a.importObject);a.run(s.instance)}async function he(e,r){let{functionType:a,params:i,returnObject:s}=r;switch(a){case"KEYGEN":{let{userId:n,secretKey:o,type:l=G.EVM}=i;return await D(e,n,l,o)}case"SIGN_TRANSACTION":{let{share:n,walletId:o,userId:l,tx:g,chainId:u}=i;return x(e,n,o,l,g,u)}case"SEND_TRANSACTION":{let{share:n,walletId:o,userId:l,tx:g,chainId:u}=i;return B(e,n,o,l,g,u)}case"SIGN_MESSAGE":{let{share:n,walletId:o,userId:l,message:g,cosmosSignDoc:u}=i;return N(e,n,o,l,g,u)}case"REFRESH":{let{share:n,walletId:o,userId:l,oldPartnerId:g,newPartnerId:u,keyShareProtocolId:d}=i,{protocolId:m,signer:t}=await $(e,n,o,l,g,u,d);return s?{protocolId:m,signer:t}:t}case"PREKEYGEN":{let{email:n,partnerId:o,secretKey:l,type:g=G.EVM}=i,{pregenIdentifier:u,pregenIdentifierType:d}=i;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(u=n,d="EMAIL"),await M(e,o,u,d,g,l)}case"GET_PRIVATE_KEY":{let{share:n,walletId:o,userId:l}=i;return await j(e,n,o,l)}case"ED25519_KEYGEN":{let{userId:n}=i;return U(e,n)}case"ED25519_SIGN":{let{share:n,walletId:o,userId:l,base64Bytes:g}=i;return L(e,n,l,o,g)}case"ED25519_PREKEYGEN":{let{email:n}=i,{pregenIdentifier:o,pregenIdentifierType:l}=i;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(o=n,l="EMAIL"),_(e,o,l)}default:throw new Error(`functionType: ${a} not supported`)}}async function H(e,r,a){let{env:i,apiKey:s,cosmosPrefix:n="cosmos",offloadMPCComputationURL:o,disableWorkers:l,sessionCookie:g,useDKLS:u,disableWebSockets:d,wasmOverride:m}=e.data;if(!i)return!0;let t={env:i,apiKey:s,cosmosPrefix:n,client:fe({env:i,version:we,apiKey:s,useFetchAdapter:a,retrieveSessionCookie:()=>g}),offloadMPCComputationURL:o,mpcComputationClient:o?pe.initClient(o,!!l):void 0,useDKLS:u,disableWebSockets:!!d,wasmOverride:m};(!t.offloadMPCComputationURL||t.useDKLS)&&await ye(t,m);let c=await he(t,e.data);return r(c),!1}async function w(e,r){let a=s=>{s.data.functionType!=="CUSTOM"&&r(s.data)};if(e.disableWorkers)return{postMessage:function(n){(async function(){await H({data:n},o=>a({data:o}),e.disableWorkers)})()},terminate:()=>{}};let i;if(e.useLocalFiles)throw new Error("useLocalFiles only supported locally");{let s=await fetch(`${Se(e)}/static/js/mpcWorker-bundle.js`),n=new Blob([await s.text()],{type:"application/javascript"}),o=URL.createObjectURL(n);i=new Worker(o)}return i.onmessage=a,i}import{distributeNewShare as be,waitUntilTrue as k}from"@getpara/core-sdk";async function V(e,r,a){return!!(await e.client.getWallets(r)).data.wallets.find(n=>n.id===a).address}async function Pe(e,r,a,i,s){let{isDone:n}=await e.client.isRefreshDone(r,a,i,s);return n}async function F(e,r,a,i){return!!(await e.client.getPregenWallets({[a]:[r]})).wallets.find(o=>o.id===i).address}function J(e,r,a,i,s=!1,n,o={}){return new Promise(async l=>{let g=await w(e,async u=>{if(await k(async()=>V(e,r,u.walletId),15e3,1e3),s){l({signer:u.signer,walletId:u.walletId,recoveryShare:null}),g.terminate();return}let d=await be({ctx:e,userId:r,walletId:u.walletId,userShare:u.signer,emailProps:o});l({signer:u.signer,walletId:u.walletId,recoveryShare:d}),g.terminate()});g.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{userId:r,secretKey:i,type:a},functionType:"KEYGEN",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:n,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function Y(e,r,a,i,s,n=!1,o,l){return new Promise(async g=>{let u=await w(e,async t=>{await k(async()=>F(e,r,a,t.walletId),15e3,1e3),g({signer:t.signer,walletId:t.walletId,recoveryShare:null}),u.terminate()}),m={pregenIdentifier:r,pregenIdentifierType:a,type:i,secretKey:s,partnerId:o,email:void 0};a==="EMAIL"&&(m.email=r),u.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:m,functionType:"PREKEYGEN",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:l,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function q(e,r,a,i,s,n,o,l){return new Promise(async g=>{let u=await w(e,async d=>{if(!await k(async()=>Pe(e,a,i,o),15e3,1e3))throw new Error("refresh failed");let{protocolId:m,signer:t}=d;g({signer:t,protocolId:m}),u.terminate()});u.postMessage({env:e.env,apiKey:e.apiKey,params:{userId:a,walletId:i,share:s,oldPartnerId:n,newPartnerId:o,keyShareProtocolId:l},functionType:"REFRESH",disableWorkers:e.disableWorkers,sessionCookie:r,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride,returnObject:!0})})}function z(e,r,a,i={}){return new Promise(async s=>{let n=await w(e,async o=>{await k(async()=>V(e,r,o.walletId),15e3,1e3),s({signer:o.signer,walletId:o.walletId,recoveryShare:null}),n.terminate()});n.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{userId:r},functionType:"ED25519_KEYGEN",disableWorkers:e.disableWorkers,sessionCookie:a,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function Z(e,r,a,i){return new Promise(async s=>{let n=await w(e,async g=>{await k(async()=>F(e,r,a,g.walletId),15e3,1e3),s({signer:g.signer,walletId:g.walletId,recoveryShare:null}),n.terminate()}),l={pregenIdentifier:r,pregenIdentifierType:a,email:void 0};a==="EMAIL"&&(l.email=r),n.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:l,functionType:"ED25519_PREKEYGEN",disableWorkers:e.disableWorkers,sessionCookie:i,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function X(e,r,a,i,s,n,o,l){return await new Promise(async g=>{let u=await w(e,async d=>{g(d),u.terminate()});u.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:i,walletId:a,userId:r,tx:s,chainId:n},functionType:"SIGN_TRANSACTION",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:o,useDKLS:l,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function Q(e,r,a,i,s,n,o,l){return await new Promise(async g=>{let u=await w(e,async d=>{g(d),u.terminate()});u.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:i,walletId:a,userId:r,tx:s,chainId:n},functionType:"SEND_TRANSACTION",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:o,useDKLS:l,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function ee(e,r,a,i,s,n,o,l){return await new Promise(async g=>{let u=await w(e,async d=>{g(d),u.terminate()});u.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:i,walletId:a,userId:r,message:s,cosmosSignDoc:l},functionType:"SIGN_MESSAGE",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:n,useDKLS:o,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function te(e,r,a,i,s,n){return await new Promise(async o=>{let l=await w(e,async g=>{o(g),l.terminate()});l.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:i,walletId:a,userId:r,base64Bytes:s},functionType:"ED25519_SIGN",disableWorkers:e.disableWorkers,sessionCookie:n,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function ne(e,r,a,i,s){return await new Promise(async n=>{let o=await w(e,async l=>{n(l),o.terminate()});o.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:i,walletId:a,userId:r},functionType:"GET_PRIVATE_KEY",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:s,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}var W=class{constructor(){this.localStorage=new v;this.sessionStorage=new T;this.secureStorage=null;this.isSyncStorage=!0;this.disableProviderModal=!1}getPrivateKey(r,a,i,s,n){return ne(r,a,i,s,n)}keygen(r,a,i,s,n,o={}){return J(r,a,i,s,!0,n,o)}refresh(r,a,i,s,n,o,l,g){return q(r,a,i,s,n,o,l,g)}preKeygen(r,a,i,s,n,o,l){return Y(r,i,s,n,o,!1,a,l)}signMessage(r,a,i,s,n,o,l,g){return ee(r,a,i,s,n,o,l,g)}signTransaction(r,a,i,s,n,o,l,g){return X(r,a,i,s,n,o,l,g)}sendTransaction(r,a,i,s,n,o,l,g){return Q(r,a,i,s,n,o,l,g)}signHash(r,a){throw new Error("not implemented")}ed25519Keygen(r,a,i,s){return z(r,a,i,s)}ed25519PreKeygen(r,a,i,s){return Z(r,a,i,s)}ed25519Sign(r,a,i,s,n,o){return te(r,a,i,s,n,o)}openPopup(r,a){if(!(typeof window>"u"))if(a){let{type:i}=a,s=550,n;switch(i){case C.LOGIN_PASSKEY:{n=798;break}case C.CREATE_PASSKEY:{n=464;break}case C.SIGN_MESSAGE_REVIEW:{n=585;break}case C.SIGN_TRANSACTION_REVIEW:{n=750;break}case C.OAUTH:default:{n=768;break}}let o=window.screenLeft!==void 0?window.screenLeft:window.screenX,l=window.screenTop!==void 0?window.screenTop:window.screenY,g=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,u=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,d=(g-s)/2+o,m=(u-n)/2+l,t=`toolbar=no, menubar=no, width=${s},
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
export * from "@getpara/core-sdk";
|
|
5
|
+
|
|
6
|
+
// src/ParaWeb.ts
|
|
7
|
+
import * as Sentry from "@sentry/browser";
|
|
8
|
+
import ParaCore, { Environment as Environment2 } from "@getpara/core-sdk";
|
|
9
|
+
|
|
10
|
+
// src/WebUtils.ts
|
|
11
|
+
import { PopupType } from "@getpara/core-sdk";
|
|
12
|
+
|
|
13
|
+
// src/LocalStorage.ts
|
|
14
|
+
var LocalStorage = class {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.get = (key) => {
|
|
17
|
+
if (typeof window !== "undefined") {
|
|
18
|
+
return localStorage.getItem(key) || null;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
this.set = (key, value) => {
|
|
23
|
+
if (typeof window !== "undefined") {
|
|
24
|
+
localStorage.setItem(key, value);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
this.removeItem = (key) => {
|
|
28
|
+
if (typeof window !== "undefined") {
|
|
29
|
+
localStorage.removeItem(key);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
this.clear = (prefix) => {
|
|
33
|
+
if (typeof window !== "undefined") {
|
|
34
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
35
|
+
const key = localStorage.key(i);
|
|
36
|
+
if (key && key.startsWith(prefix)) {
|
|
37
|
+
localStorage.removeItem(key);
|
|
38
|
+
i--;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/SessionStorage.ts
|
|
47
|
+
var SessionStorage = class {
|
|
48
|
+
constructor() {
|
|
49
|
+
this.get = (key) => {
|
|
50
|
+
if (typeof window !== "undefined") {
|
|
51
|
+
return sessionStorage.getItem(key) || null;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
this.set = (key, value) => {
|
|
56
|
+
if (typeof window !== "undefined") {
|
|
57
|
+
sessionStorage.setItem(key, value);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.removeItem = (key) => {
|
|
61
|
+
if (typeof window !== "undefined") {
|
|
62
|
+
sessionStorage.removeItem(key);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
this.clear = (prefix) => {
|
|
66
|
+
if (typeof window !== "undefined") {
|
|
67
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
68
|
+
const key = sessionStorage.key(i);
|
|
69
|
+
if (key && key.startsWith(prefix)) {
|
|
70
|
+
sessionStorage.removeItem(key);
|
|
71
|
+
i--;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/workers/workerWrapper.ts
|
|
80
|
+
import { getPortalBaseURL as getPortalBaseURL2 } from "@getpara/core-sdk";
|
|
81
|
+
|
|
82
|
+
// src/wasm/wasm_exec.js
|
|
83
|
+
(() => {
|
|
84
|
+
const enosys = () => {
|
|
85
|
+
const err = new Error("not implemented");
|
|
86
|
+
err.code = "ENOSYS";
|
|
87
|
+
return err;
|
|
88
|
+
};
|
|
89
|
+
if (!globalThis.fs) {
|
|
90
|
+
let outputBuf = "";
|
|
91
|
+
globalThis.fs = {
|
|
92
|
+
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
|
|
93
|
+
// unused
|
|
94
|
+
writeSync(fd, buf) {
|
|
95
|
+
outputBuf += decoder.decode(buf);
|
|
96
|
+
const nl = outputBuf.lastIndexOf("\n");
|
|
97
|
+
if (nl != -1) {
|
|
98
|
+
console.log(outputBuf.substring(0, nl));
|
|
99
|
+
outputBuf = outputBuf.substring(nl + 1);
|
|
100
|
+
}
|
|
101
|
+
return buf.length;
|
|
102
|
+
},
|
|
103
|
+
write(fd, buf, offset, length, position, callback) {
|
|
104
|
+
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
105
|
+
callback(enosys());
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const n = this.writeSync(fd, buf);
|
|
109
|
+
callback(null, n);
|
|
110
|
+
},
|
|
111
|
+
chmod(path, mode, callback) {
|
|
112
|
+
callback(enosys());
|
|
113
|
+
},
|
|
114
|
+
chown(path, uid, gid, callback) {
|
|
115
|
+
callback(enosys());
|
|
116
|
+
},
|
|
117
|
+
close(fd, callback) {
|
|
118
|
+
callback(enosys());
|
|
119
|
+
},
|
|
120
|
+
fchmod(fd, mode, callback) {
|
|
121
|
+
callback(enosys());
|
|
122
|
+
},
|
|
123
|
+
fchown(fd, uid, gid, callback) {
|
|
124
|
+
callback(enosys());
|
|
125
|
+
},
|
|
126
|
+
fstat(fd, callback) {
|
|
127
|
+
callback(enosys());
|
|
128
|
+
},
|
|
129
|
+
fsync(fd, callback) {
|
|
130
|
+
callback(null);
|
|
131
|
+
},
|
|
132
|
+
ftruncate(fd, length, callback) {
|
|
133
|
+
callback(enosys());
|
|
134
|
+
},
|
|
135
|
+
lchown(path, uid, gid, callback) {
|
|
136
|
+
callback(enosys());
|
|
137
|
+
},
|
|
138
|
+
link(path, link, callback) {
|
|
139
|
+
callback(enosys());
|
|
140
|
+
},
|
|
141
|
+
lstat(path, callback) {
|
|
142
|
+
callback(enosys());
|
|
143
|
+
},
|
|
144
|
+
mkdir(path, perm, callback) {
|
|
145
|
+
callback(enosys());
|
|
146
|
+
},
|
|
147
|
+
open(path, flags, mode, callback) {
|
|
148
|
+
callback(enosys());
|
|
149
|
+
},
|
|
150
|
+
read(fd, buffer, offset, length, position, callback) {
|
|
151
|
+
callback(enosys());
|
|
152
|
+
},
|
|
153
|
+
readdir(path, callback) {
|
|
154
|
+
callback(enosys());
|
|
155
|
+
},
|
|
156
|
+
readlink(path, callback) {
|
|
157
|
+
callback(enosys());
|
|
158
|
+
},
|
|
159
|
+
rename(from, to, callback) {
|
|
160
|
+
callback(enosys());
|
|
161
|
+
},
|
|
162
|
+
rmdir(path, callback) {
|
|
163
|
+
callback(enosys());
|
|
164
|
+
},
|
|
165
|
+
stat(path, callback) {
|
|
166
|
+
callback(enosys());
|
|
167
|
+
},
|
|
168
|
+
symlink(path, link, callback) {
|
|
169
|
+
callback(enosys());
|
|
170
|
+
},
|
|
171
|
+
truncate(path, length, callback) {
|
|
172
|
+
callback(enosys());
|
|
173
|
+
},
|
|
174
|
+
unlink(path, callback) {
|
|
175
|
+
callback(enosys());
|
|
176
|
+
},
|
|
177
|
+
utimes(path, atime, mtime, callback) {
|
|
178
|
+
callback(enosys());
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (!globalThis.process) {
|
|
183
|
+
globalThis.process = {
|
|
184
|
+
getuid() {
|
|
185
|
+
return -1;
|
|
186
|
+
},
|
|
187
|
+
getgid() {
|
|
188
|
+
return -1;
|
|
189
|
+
},
|
|
190
|
+
geteuid() {
|
|
191
|
+
return -1;
|
|
192
|
+
},
|
|
193
|
+
getegid() {
|
|
194
|
+
return -1;
|
|
195
|
+
},
|
|
196
|
+
getgroups() {
|
|
197
|
+
throw enosys();
|
|
198
|
+
},
|
|
199
|
+
pid: -1,
|
|
200
|
+
ppid: -1,
|
|
201
|
+
umask() {
|
|
202
|
+
throw enosys();
|
|
203
|
+
},
|
|
204
|
+
cwd() {
|
|
205
|
+
throw enosys();
|
|
206
|
+
},
|
|
207
|
+
chdir() {
|
|
208
|
+
throw enosys();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (!globalThis.crypto) {
|
|
213
|
+
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
|
214
|
+
}
|
|
215
|
+
if (!globalThis.performance) {
|
|
216
|
+
globalThis.performance = Date;
|
|
217
|
+
}
|
|
218
|
+
if (!globalThis.TextEncoder) {
|
|
219
|
+
throw new Error("globalThis.TextEncoder is not available, polyfill required");
|
|
220
|
+
}
|
|
221
|
+
if (!globalThis.TextDecoder) {
|
|
222
|
+
throw new Error("globalThis.TextDecoder is not available, polyfill required");
|
|
223
|
+
}
|
|
224
|
+
const encoder = new TextEncoder("utf-8");
|
|
225
|
+
const decoder = new TextDecoder("utf-8");
|
|
226
|
+
globalThis.Go = class {
|
|
227
|
+
constructor() {
|
|
228
|
+
this.argv = ["js"];
|
|
229
|
+
this.env = {};
|
|
230
|
+
this.exit = (code) => {
|
|
231
|
+
if (code !== 0) {
|
|
232
|
+
console.warn("exit code:", code);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
this._exitPromise = new Promise((resolve) => {
|
|
236
|
+
this._resolveExitPromise = resolve;
|
|
237
|
+
});
|
|
238
|
+
this._pendingEvent = null;
|
|
239
|
+
this._scheduledTimeouts = /* @__PURE__ */ new Map();
|
|
240
|
+
this._nextCallbackTimeoutID = 1;
|
|
241
|
+
const setInt64 = (addr, v) => {
|
|
242
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
243
|
+
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
244
|
+
};
|
|
245
|
+
const setInt32 = (addr, v) => {
|
|
246
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
247
|
+
};
|
|
248
|
+
const getInt64 = (addr) => {
|
|
249
|
+
const low = this.mem.getUint32(addr + 0, true);
|
|
250
|
+
const high = this.mem.getInt32(addr + 4, true);
|
|
251
|
+
return low + high * 4294967296;
|
|
252
|
+
};
|
|
253
|
+
const loadValue = (addr) => {
|
|
254
|
+
const f = this.mem.getFloat64(addr, true);
|
|
255
|
+
if (f === 0) {
|
|
256
|
+
return void 0;
|
|
257
|
+
}
|
|
258
|
+
if (!isNaN(f)) {
|
|
259
|
+
return f;
|
|
260
|
+
}
|
|
261
|
+
const id = this.mem.getUint32(addr, true);
|
|
262
|
+
return this._values[id];
|
|
263
|
+
};
|
|
264
|
+
const storeValue = (addr, v) => {
|
|
265
|
+
const nanHead = 2146959360;
|
|
266
|
+
if (typeof v === "number" && v !== 0) {
|
|
267
|
+
if (isNaN(v)) {
|
|
268
|
+
this.mem.setUint32(addr + 4, nanHead, true);
|
|
269
|
+
this.mem.setUint32(addr, 0, true);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this.mem.setFloat64(addr, v, true);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (v === void 0) {
|
|
276
|
+
this.mem.setFloat64(addr, 0, true);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
let id = this._ids.get(v);
|
|
280
|
+
if (id === void 0) {
|
|
281
|
+
id = this._idPool.pop();
|
|
282
|
+
if (id === void 0) {
|
|
283
|
+
id = this._values.length;
|
|
284
|
+
}
|
|
285
|
+
this._values[id] = v;
|
|
286
|
+
this._goRefCounts[id] = 0;
|
|
287
|
+
this._ids.set(v, id);
|
|
288
|
+
}
|
|
289
|
+
this._goRefCounts[id]++;
|
|
290
|
+
let typeFlag = 0;
|
|
291
|
+
switch (typeof v) {
|
|
292
|
+
case "object":
|
|
293
|
+
if (v !== null) {
|
|
294
|
+
typeFlag = 1;
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
case "string":
|
|
298
|
+
typeFlag = 2;
|
|
299
|
+
break;
|
|
300
|
+
case "symbol":
|
|
301
|
+
typeFlag = 3;
|
|
302
|
+
break;
|
|
303
|
+
case "function":
|
|
304
|
+
typeFlag = 4;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
308
|
+
this.mem.setUint32(addr, id, true);
|
|
309
|
+
};
|
|
310
|
+
const loadSlice = (addr) => {
|
|
311
|
+
const array = getInt64(addr + 0);
|
|
312
|
+
const len = getInt64(addr + 8);
|
|
313
|
+
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
314
|
+
};
|
|
315
|
+
const loadSliceOfValues = (addr) => {
|
|
316
|
+
const array = getInt64(addr + 0);
|
|
317
|
+
const len = getInt64(addr + 8);
|
|
318
|
+
const a = new Array(len);
|
|
319
|
+
for (let i = 0; i < len; i++) {
|
|
320
|
+
a[i] = loadValue(array + i * 8);
|
|
321
|
+
}
|
|
322
|
+
return a;
|
|
323
|
+
};
|
|
324
|
+
const loadString = (addr) => {
|
|
325
|
+
const saddr = getInt64(addr + 0);
|
|
326
|
+
const len = getInt64(addr + 8);
|
|
327
|
+
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
328
|
+
};
|
|
329
|
+
const timeOrigin = Date.now() - performance.now();
|
|
330
|
+
this.importObject = {
|
|
331
|
+
_gotest: {
|
|
332
|
+
add: (a, b) => a + b
|
|
333
|
+
},
|
|
334
|
+
gojs: {
|
|
335
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
336
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
337
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
338
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
339
|
+
// func wasmExit(code int32)
|
|
340
|
+
"runtime.wasmExit": (sp) => {
|
|
341
|
+
sp >>>= 0;
|
|
342
|
+
const code = this.mem.getInt32(sp + 8, true);
|
|
343
|
+
this.exited = true;
|
|
344
|
+
delete this._inst;
|
|
345
|
+
delete this._values;
|
|
346
|
+
delete this._goRefCounts;
|
|
347
|
+
delete this._ids;
|
|
348
|
+
delete this._idPool;
|
|
349
|
+
this.exit(code);
|
|
350
|
+
},
|
|
351
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
352
|
+
"runtime.wasmWrite": (sp) => {
|
|
353
|
+
sp >>>= 0;
|
|
354
|
+
const fd = getInt64(sp + 8);
|
|
355
|
+
const p = getInt64(sp + 16);
|
|
356
|
+
const n = this.mem.getInt32(sp + 24, true);
|
|
357
|
+
fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
358
|
+
},
|
|
359
|
+
// func resetMemoryDataView()
|
|
360
|
+
"runtime.resetMemoryDataView": (sp) => {
|
|
361
|
+
sp >>>= 0;
|
|
362
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
363
|
+
},
|
|
364
|
+
// func nanotime1() int64
|
|
365
|
+
"runtime.nanotime1": (sp) => {
|
|
366
|
+
sp >>>= 0;
|
|
367
|
+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
|
|
368
|
+
},
|
|
369
|
+
// func walltime() (sec int64, nsec int32)
|
|
370
|
+
"runtime.walltime": (sp) => {
|
|
371
|
+
sp >>>= 0;
|
|
372
|
+
const msec = (/* @__PURE__ */ new Date()).getTime();
|
|
373
|
+
setInt64(sp + 8, msec / 1e3);
|
|
374
|
+
this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
|
|
375
|
+
},
|
|
376
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
|
377
|
+
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
378
|
+
sp >>>= 0;
|
|
379
|
+
const id = this._nextCallbackTimeoutID;
|
|
380
|
+
this._nextCallbackTimeoutID++;
|
|
381
|
+
this._scheduledTimeouts.set(id, setTimeout(
|
|
382
|
+
() => {
|
|
383
|
+
this._resume();
|
|
384
|
+
while (this._scheduledTimeouts.has(id)) {
|
|
385
|
+
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
386
|
+
this._resume();
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
getInt64(sp + 8)
|
|
390
|
+
));
|
|
391
|
+
this.mem.setInt32(sp + 16, id, true);
|
|
392
|
+
},
|
|
393
|
+
// func clearTimeoutEvent(id int32)
|
|
394
|
+
"runtime.clearTimeoutEvent": (sp) => {
|
|
395
|
+
sp >>>= 0;
|
|
396
|
+
const id = this.mem.getInt32(sp + 8, true);
|
|
397
|
+
clearTimeout(this._scheduledTimeouts.get(id));
|
|
398
|
+
this._scheduledTimeouts.delete(id);
|
|
399
|
+
},
|
|
400
|
+
// func getRandomData(r []byte)
|
|
401
|
+
"runtime.getRandomData": (sp) => {
|
|
402
|
+
sp >>>= 0;
|
|
403
|
+
crypto.getRandomValues(loadSlice(sp + 8));
|
|
404
|
+
},
|
|
405
|
+
// func finalizeRef(v ref)
|
|
406
|
+
"syscall/js.finalizeRef": (sp) => {
|
|
407
|
+
sp >>>= 0;
|
|
408
|
+
const id = this.mem.getUint32(sp + 8, true);
|
|
409
|
+
this._goRefCounts[id]--;
|
|
410
|
+
if (this._goRefCounts[id] === 0) {
|
|
411
|
+
const v = this._values[id];
|
|
412
|
+
this._values[id] = null;
|
|
413
|
+
this._ids.delete(v);
|
|
414
|
+
this._idPool.push(id);
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
// func stringVal(value string) ref
|
|
418
|
+
"syscall/js.stringVal": (sp) => {
|
|
419
|
+
sp >>>= 0;
|
|
420
|
+
storeValue(sp + 24, loadString(sp + 8));
|
|
421
|
+
},
|
|
422
|
+
// func valueGet(v ref, p string) ref
|
|
423
|
+
"syscall/js.valueGet": (sp) => {
|
|
424
|
+
sp >>>= 0;
|
|
425
|
+
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
426
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
427
|
+
storeValue(sp + 32, result);
|
|
428
|
+
},
|
|
429
|
+
// func valueSet(v ref, p string, x ref)
|
|
430
|
+
"syscall/js.valueSet": (sp) => {
|
|
431
|
+
sp >>>= 0;
|
|
432
|
+
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
433
|
+
},
|
|
434
|
+
// func valueDelete(v ref, p string)
|
|
435
|
+
"syscall/js.valueDelete": (sp) => {
|
|
436
|
+
sp >>>= 0;
|
|
437
|
+
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
438
|
+
},
|
|
439
|
+
// func valueIndex(v ref, i int) ref
|
|
440
|
+
"syscall/js.valueIndex": (sp) => {
|
|
441
|
+
sp >>>= 0;
|
|
442
|
+
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
443
|
+
},
|
|
444
|
+
// valueSetIndex(v ref, i int, x ref)
|
|
445
|
+
"syscall/js.valueSetIndex": (sp) => {
|
|
446
|
+
sp >>>= 0;
|
|
447
|
+
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
448
|
+
},
|
|
449
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
450
|
+
"syscall/js.valueCall": (sp) => {
|
|
451
|
+
sp >>>= 0;
|
|
452
|
+
try {
|
|
453
|
+
const v = loadValue(sp + 8);
|
|
454
|
+
const m = Reflect.get(v, loadString(sp + 16));
|
|
455
|
+
const args = loadSliceOfValues(sp + 32);
|
|
456
|
+
const result = Reflect.apply(m, v, args);
|
|
457
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
458
|
+
storeValue(sp + 56, result);
|
|
459
|
+
this.mem.setUint8(sp + 64, 1);
|
|
460
|
+
} catch (err) {
|
|
461
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
462
|
+
storeValue(sp + 56, err);
|
|
463
|
+
this.mem.setUint8(sp + 64, 0);
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
467
|
+
"syscall/js.valueInvoke": (sp) => {
|
|
468
|
+
sp >>>= 0;
|
|
469
|
+
try {
|
|
470
|
+
const v = loadValue(sp + 8);
|
|
471
|
+
const args = loadSliceOfValues(sp + 16);
|
|
472
|
+
const result = Reflect.apply(v, void 0, args);
|
|
473
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
474
|
+
storeValue(sp + 40, result);
|
|
475
|
+
this.mem.setUint8(sp + 48, 1);
|
|
476
|
+
} catch (err) {
|
|
477
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
478
|
+
storeValue(sp + 40, err);
|
|
479
|
+
this.mem.setUint8(sp + 48, 0);
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
|
483
|
+
"syscall/js.valueNew": (sp) => {
|
|
484
|
+
sp >>>= 0;
|
|
485
|
+
try {
|
|
486
|
+
const v = loadValue(sp + 8);
|
|
487
|
+
const args = loadSliceOfValues(sp + 16);
|
|
488
|
+
const result = Reflect.construct(v, args);
|
|
489
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
490
|
+
storeValue(sp + 40, result);
|
|
491
|
+
this.mem.setUint8(sp + 48, 1);
|
|
492
|
+
} catch (err) {
|
|
493
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
494
|
+
storeValue(sp + 40, err);
|
|
495
|
+
this.mem.setUint8(sp + 48, 0);
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
// func valueLength(v ref) int
|
|
499
|
+
"syscall/js.valueLength": (sp) => {
|
|
500
|
+
sp >>>= 0;
|
|
501
|
+
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
502
|
+
},
|
|
503
|
+
// valuePrepareString(v ref) (ref, int)
|
|
504
|
+
"syscall/js.valuePrepareString": (sp) => {
|
|
505
|
+
sp >>>= 0;
|
|
506
|
+
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
507
|
+
storeValue(sp + 16, str);
|
|
508
|
+
setInt64(sp + 24, str.length);
|
|
509
|
+
},
|
|
510
|
+
// valueLoadString(v ref, b []byte)
|
|
511
|
+
"syscall/js.valueLoadString": (sp) => {
|
|
512
|
+
sp >>>= 0;
|
|
513
|
+
const str = loadValue(sp + 8);
|
|
514
|
+
loadSlice(sp + 16).set(str);
|
|
515
|
+
},
|
|
516
|
+
// func valueInstanceOf(v ref, t ref) bool
|
|
517
|
+
"syscall/js.valueInstanceOf": (sp) => {
|
|
518
|
+
sp >>>= 0;
|
|
519
|
+
this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
|
|
520
|
+
},
|
|
521
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
522
|
+
"syscall/js.copyBytesToGo": (sp) => {
|
|
523
|
+
sp >>>= 0;
|
|
524
|
+
const dst = loadSlice(sp + 8);
|
|
525
|
+
const src = loadValue(sp + 32);
|
|
526
|
+
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
527
|
+
this.mem.setUint8(sp + 48, 0);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const toCopy = src.subarray(0, dst.length);
|
|
531
|
+
dst.set(toCopy);
|
|
532
|
+
setInt64(sp + 40, toCopy.length);
|
|
533
|
+
this.mem.setUint8(sp + 48, 1);
|
|
534
|
+
},
|
|
535
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
536
|
+
"syscall/js.copyBytesToJS": (sp) => {
|
|
537
|
+
sp >>>= 0;
|
|
538
|
+
const dst = loadValue(sp + 8);
|
|
539
|
+
const src = loadSlice(sp + 16);
|
|
540
|
+
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
541
|
+
this.mem.setUint8(sp + 48, 0);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const toCopy = src.subarray(0, dst.length);
|
|
545
|
+
dst.set(toCopy);
|
|
546
|
+
setInt64(sp + 40, toCopy.length);
|
|
547
|
+
this.mem.setUint8(sp + 48, 1);
|
|
548
|
+
},
|
|
549
|
+
"debug": (value) => {
|
|
550
|
+
console.log(value);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
async run(instance) {
|
|
556
|
+
if (!(instance instanceof WebAssembly.Instance)) {
|
|
557
|
+
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
558
|
+
}
|
|
559
|
+
this._inst = instance;
|
|
560
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
561
|
+
this._values = [
|
|
562
|
+
// JS values that Go currently has references to, indexed by reference id
|
|
563
|
+
NaN,
|
|
564
|
+
0,
|
|
565
|
+
null,
|
|
566
|
+
true,
|
|
567
|
+
false,
|
|
568
|
+
globalThis,
|
|
569
|
+
this
|
|
570
|
+
];
|
|
571
|
+
this._goRefCounts = new Array(this._values.length).fill(Infinity);
|
|
572
|
+
this._ids = /* @__PURE__ */ new Map([
|
|
573
|
+
// mapping from JS values to reference ids
|
|
574
|
+
[0, 1],
|
|
575
|
+
[null, 2],
|
|
576
|
+
[true, 3],
|
|
577
|
+
[false, 4],
|
|
578
|
+
[globalThis, 5],
|
|
579
|
+
[this, 6]
|
|
580
|
+
]);
|
|
581
|
+
this._idPool = [];
|
|
582
|
+
this.exited = false;
|
|
583
|
+
let offset = 4096;
|
|
584
|
+
const strPtr = (str) => {
|
|
585
|
+
const ptr = offset;
|
|
586
|
+
const bytes = encoder.encode(str + "\0");
|
|
587
|
+
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
588
|
+
offset += bytes.length;
|
|
589
|
+
if (offset % 8 !== 0) {
|
|
590
|
+
offset += 8 - offset % 8;
|
|
591
|
+
}
|
|
592
|
+
return ptr;
|
|
593
|
+
};
|
|
594
|
+
const argc = this.argv.length;
|
|
595
|
+
const argvPtrs = [];
|
|
596
|
+
this.argv.forEach((arg) => {
|
|
597
|
+
argvPtrs.push(strPtr(arg));
|
|
598
|
+
});
|
|
599
|
+
argvPtrs.push(0);
|
|
600
|
+
const keys = Object.keys(this.env).sort();
|
|
601
|
+
keys.forEach((key) => {
|
|
602
|
+
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
603
|
+
});
|
|
604
|
+
argvPtrs.push(0);
|
|
605
|
+
const argv = offset;
|
|
606
|
+
argvPtrs.forEach((ptr) => {
|
|
607
|
+
this.mem.setUint32(offset, ptr, true);
|
|
608
|
+
this.mem.setUint32(offset + 4, 0, true);
|
|
609
|
+
offset += 8;
|
|
610
|
+
});
|
|
611
|
+
const wasmMinDataAddr = 4096 + 8192;
|
|
612
|
+
if (offset >= wasmMinDataAddr) {
|
|
613
|
+
throw new Error("total length of command line and environment variables exceeds limit");
|
|
614
|
+
}
|
|
615
|
+
this._inst.exports.run(argc, argv);
|
|
616
|
+
if (this.exited) {
|
|
617
|
+
this._resolveExitPromise();
|
|
618
|
+
}
|
|
619
|
+
await this._exitPromise;
|
|
620
|
+
}
|
|
621
|
+
_resume() {
|
|
622
|
+
if (this.exited) {
|
|
623
|
+
throw new Error("Go program has already exited");
|
|
624
|
+
}
|
|
625
|
+
this._inst.exports.resume();
|
|
626
|
+
if (this.exited) {
|
|
627
|
+
this._resolveExitPromise();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
_makeFuncWrapper(id) {
|
|
631
|
+
const go = this;
|
|
632
|
+
return function() {
|
|
633
|
+
const event = { id, this: this, args: arguments };
|
|
634
|
+
go._pendingEvent = event;
|
|
635
|
+
go._resume();
|
|
636
|
+
return event.result;
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
})();
|
|
641
|
+
|
|
642
|
+
// src/workers/walletUtils.ts
|
|
643
|
+
import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
|
|
644
|
+
var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
645
|
+
var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
646
|
+
async function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
647
|
+
const { data } = await ctx.mpcComputationClient.post("/wallets", {
|
|
648
|
+
userId,
|
|
649
|
+
walletId,
|
|
650
|
+
protocolId
|
|
651
|
+
});
|
|
652
|
+
return data;
|
|
653
|
+
}
|
|
654
|
+
async function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
|
|
655
|
+
const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
|
|
656
|
+
userId,
|
|
657
|
+
protocolId,
|
|
658
|
+
message,
|
|
659
|
+
signer
|
|
660
|
+
});
|
|
661
|
+
return data;
|
|
662
|
+
}
|
|
663
|
+
async function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
|
|
664
|
+
const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
|
|
665
|
+
userId,
|
|
666
|
+
protocolId,
|
|
667
|
+
transaction,
|
|
668
|
+
signer,
|
|
669
|
+
chainId
|
|
670
|
+
});
|
|
671
|
+
return data;
|
|
672
|
+
}
|
|
673
|
+
async function ed25519Keygen(ctx, userId) {
|
|
674
|
+
const { walletId, protocolId } = await ctx.client.createWallet(userId, {
|
|
675
|
+
scheme: WalletScheme.ED25519,
|
|
676
|
+
type: WalletType.SOLANA
|
|
677
|
+
});
|
|
678
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
679
|
+
try {
|
|
680
|
+
const newSigner = await new Promise(
|
|
681
|
+
(resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
682
|
+
if (err) {
|
|
683
|
+
reject(err);
|
|
684
|
+
}
|
|
685
|
+
resolve(result);
|
|
686
|
+
})
|
|
687
|
+
);
|
|
688
|
+
return { signer: newSigner, walletId };
|
|
689
|
+
} catch (e) {
|
|
690
|
+
throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
694
|
+
const { walletId, protocolId } = await ctx.client.createPregenWallet({
|
|
695
|
+
pregenIdentifier,
|
|
696
|
+
pregenIdentifierType,
|
|
697
|
+
scheme: WalletScheme.ED25519,
|
|
698
|
+
type: WalletType.SOLANA
|
|
699
|
+
});
|
|
700
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
701
|
+
try {
|
|
702
|
+
const newSigner = await new Promise(
|
|
703
|
+
(resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
704
|
+
if (err) {
|
|
705
|
+
reject(err);
|
|
706
|
+
}
|
|
707
|
+
resolve(result);
|
|
708
|
+
})
|
|
709
|
+
);
|
|
710
|
+
return { signer: newSigner, walletId };
|
|
711
|
+
} catch (e) {
|
|
712
|
+
throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
716
|
+
const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
|
|
717
|
+
try {
|
|
718
|
+
const base64Sig = await new Promise(
|
|
719
|
+
(resolve, reject) => globalThis.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
720
|
+
if (err) {
|
|
721
|
+
reject(err);
|
|
722
|
+
}
|
|
723
|
+
resolve(result);
|
|
724
|
+
})
|
|
725
|
+
);
|
|
726
|
+
return { signature: base64Sig };
|
|
727
|
+
} catch (e) {
|
|
728
|
+
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
async function keygen(ctx, userId, type, secretKey) {
|
|
732
|
+
const { walletId, protocolId } = await ctx.client.createWallet(userId, {
|
|
733
|
+
useTwoSigners: true,
|
|
734
|
+
scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
|
|
735
|
+
type,
|
|
736
|
+
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
737
|
+
});
|
|
738
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
739
|
+
return {
|
|
740
|
+
signer: (await keygenRequest(ctx, userId, walletId, protocolId)).signer,
|
|
741
|
+
walletId
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
745
|
+
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
746
|
+
const createAccountFn = ctx.useDKLS ? globalThis.dklsCreateAccount : globalThis.createAccountV2;
|
|
747
|
+
try {
|
|
748
|
+
const newSigner = await new Promise(
|
|
749
|
+
(resolve, reject) => createAccountFn(
|
|
750
|
+
signerConfigUser,
|
|
751
|
+
serverUrl,
|
|
752
|
+
protocolId,
|
|
753
|
+
secretKey,
|
|
754
|
+
() => {
|
|
755
|
+
},
|
|
756
|
+
// no-op for deprecated callback to update progress percentage
|
|
757
|
+
(err, result) => {
|
|
758
|
+
if (err) {
|
|
759
|
+
reject(err);
|
|
760
|
+
}
|
|
761
|
+
resolve(result);
|
|
762
|
+
}
|
|
763
|
+
)
|
|
764
|
+
);
|
|
765
|
+
return { signer: newSigner, walletId };
|
|
766
|
+
} catch (e) {
|
|
767
|
+
throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
async function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
|
|
771
|
+
const { walletId, protocolId } = await ctx.client.createPregenWallet({
|
|
772
|
+
pregenIdentifier,
|
|
773
|
+
pregenIdentifierType,
|
|
774
|
+
type,
|
|
775
|
+
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
776
|
+
});
|
|
777
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
778
|
+
const signerConfigUser = configDKLSBase(walletId, "USER", ctx.disableWebSockets);
|
|
779
|
+
try {
|
|
780
|
+
const newSigner = await new Promise(
|
|
781
|
+
(resolve, reject) => globalThis.dklsCreateAccount(
|
|
782
|
+
signerConfigUser,
|
|
783
|
+
serverUrl,
|
|
784
|
+
protocolId,
|
|
785
|
+
secretKey,
|
|
786
|
+
() => {
|
|
787
|
+
},
|
|
788
|
+
// no-op for deprecated callback to update progress percentage
|
|
789
|
+
(err, result) => {
|
|
790
|
+
if (err) {
|
|
791
|
+
reject(err);
|
|
792
|
+
}
|
|
793
|
+
resolve(result);
|
|
794
|
+
}
|
|
795
|
+
)
|
|
796
|
+
);
|
|
797
|
+
return { signer: newSigner, walletId };
|
|
798
|
+
} catch (e) {
|
|
799
|
+
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
async function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
|
|
803
|
+
const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(
|
|
804
|
+
userId,
|
|
805
|
+
walletId,
|
|
806
|
+
message,
|
|
807
|
+
null,
|
|
808
|
+
cosmosSignDoc
|
|
809
|
+
);
|
|
810
|
+
if (pendingTransactionId) {
|
|
811
|
+
return { pendingTransactionId };
|
|
812
|
+
}
|
|
813
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
814
|
+
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
815
|
+
}
|
|
816
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
817
|
+
const signMessageFn = ctx.useDKLS ? globalThis.dklsSignMessage : globalThis.signMessage;
|
|
818
|
+
const parsedShare = JSON.parse(share);
|
|
819
|
+
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
820
|
+
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
821
|
+
}
|
|
822
|
+
share = JSON.stringify(parsedShare);
|
|
823
|
+
try {
|
|
824
|
+
return await new Promise(
|
|
825
|
+
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
826
|
+
if (err) {
|
|
827
|
+
reject(err);
|
|
828
|
+
}
|
|
829
|
+
resolve({ signature: result });
|
|
830
|
+
})
|
|
831
|
+
);
|
|
832
|
+
} catch (e) {
|
|
833
|
+
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
837
|
+
const {
|
|
838
|
+
data: { protocolId, pendingTransactionId }
|
|
839
|
+
} = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
840
|
+
if (pendingTransactionId) {
|
|
841
|
+
return { pendingTransactionId };
|
|
842
|
+
}
|
|
843
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
844
|
+
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
845
|
+
}
|
|
846
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
847
|
+
const signTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
|
|
848
|
+
const parsedShare = JSON.parse(share);
|
|
849
|
+
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
850
|
+
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
851
|
+
}
|
|
852
|
+
share = JSON.stringify(parsedShare);
|
|
853
|
+
try {
|
|
854
|
+
return await new Promise(
|
|
855
|
+
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
856
|
+
if (err) {
|
|
857
|
+
reject(err);
|
|
858
|
+
}
|
|
859
|
+
resolve({ signature: result });
|
|
860
|
+
})
|
|
861
|
+
);
|
|
862
|
+
} catch (e) {
|
|
863
|
+
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
867
|
+
const {
|
|
868
|
+
data: { protocolId, pendingTransactionId }
|
|
869
|
+
} = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
870
|
+
if (pendingTransactionId) {
|
|
871
|
+
return { pendingTransactionId };
|
|
872
|
+
}
|
|
873
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
874
|
+
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
875
|
+
}
|
|
876
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
877
|
+
const sendTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
|
|
878
|
+
const parsedShare = JSON.parse(share);
|
|
879
|
+
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
880
|
+
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
881
|
+
}
|
|
882
|
+
share = JSON.stringify(parsedShare);
|
|
883
|
+
try {
|
|
884
|
+
return await new Promise(
|
|
885
|
+
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
886
|
+
if (err) {
|
|
887
|
+
reject(err);
|
|
888
|
+
}
|
|
889
|
+
resolve({ signature: result });
|
|
890
|
+
})
|
|
891
|
+
);
|
|
892
|
+
} catch (e) {
|
|
893
|
+
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
async function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
897
|
+
const {
|
|
898
|
+
data: { protocolId }
|
|
899
|
+
} = await ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId);
|
|
900
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
901
|
+
const refreshFn = ctx.useDKLS ? globalThis.dklsRefresh : globalThis.refresh;
|
|
902
|
+
const parsedShare = JSON.parse(share);
|
|
903
|
+
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
904
|
+
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
905
|
+
}
|
|
906
|
+
share = JSON.stringify(parsedShare);
|
|
907
|
+
try {
|
|
908
|
+
return await new Promise(
|
|
909
|
+
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
910
|
+
if (err) {
|
|
911
|
+
reject(err);
|
|
912
|
+
}
|
|
913
|
+
resolve({ protocolId, signer: result });
|
|
914
|
+
})
|
|
915
|
+
);
|
|
916
|
+
} catch (e) {
|
|
917
|
+
throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
async function getPrivateKey(ctx, share, walletId, userId) {
|
|
921
|
+
const paraShare = await ctx.client.getParaShare(userId, walletId);
|
|
922
|
+
if (!paraShare) {
|
|
923
|
+
return "";
|
|
924
|
+
}
|
|
925
|
+
try {
|
|
926
|
+
return await new Promise(
|
|
927
|
+
(resolve, reject) => globalThis.getPrivateKey(share, paraShare, (err, result) => {
|
|
928
|
+
if (err) {
|
|
929
|
+
reject(err);
|
|
930
|
+
}
|
|
931
|
+
resolve(result);
|
|
932
|
+
})
|
|
933
|
+
);
|
|
934
|
+
} catch (e) {
|
|
935
|
+
throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// src/workers/worker.ts
|
|
940
|
+
import {
|
|
941
|
+
getPortalBaseURL,
|
|
942
|
+
initClient,
|
|
943
|
+
mpcComputationClient,
|
|
944
|
+
paraVersion,
|
|
945
|
+
WalletType as WalletType2
|
|
946
|
+
} from "@getpara/core-sdk";
|
|
947
|
+
async function loadWasm(ctx, wasmOverride) {
|
|
948
|
+
if (typeof self === "undefined") {
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
const goWasm = new self.Go();
|
|
952
|
+
let wasmArrayBuffer = wasmOverride;
|
|
953
|
+
if (!wasmArrayBuffer) {
|
|
954
|
+
if (process.env.DISABLE_WASM_FETCH === "true") {
|
|
955
|
+
throw new Error("fetching wasm file is disabled");
|
|
956
|
+
}
|
|
957
|
+
const fetchedWasm = await fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
|
|
958
|
+
wasmArrayBuffer = await fetchedWasm.arrayBuffer();
|
|
959
|
+
}
|
|
960
|
+
const newRes = await WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
|
|
961
|
+
goWasm.run(newRes.instance);
|
|
962
|
+
}
|
|
963
|
+
async function executeMessage(ctx, message) {
|
|
964
|
+
const { functionType, params, returnObject } = message;
|
|
965
|
+
switch (functionType) {
|
|
966
|
+
case "KEYGEN": {
|
|
967
|
+
const { userId, secretKey, type = WalletType2.EVM } = params;
|
|
968
|
+
const keygenRes = await keygen(ctx, userId, type, secretKey);
|
|
969
|
+
return keygenRes;
|
|
970
|
+
}
|
|
971
|
+
case "SIGN_TRANSACTION": {
|
|
972
|
+
const { share, walletId, userId, tx, chainId } = params;
|
|
973
|
+
return signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
974
|
+
}
|
|
975
|
+
case "SEND_TRANSACTION": {
|
|
976
|
+
const { share, walletId, userId, tx, chainId } = params;
|
|
977
|
+
return sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
978
|
+
}
|
|
979
|
+
case "SIGN_MESSAGE": {
|
|
980
|
+
const { share, walletId, userId, message: message2, cosmosSignDoc } = params;
|
|
981
|
+
return signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc);
|
|
982
|
+
}
|
|
983
|
+
case "REFRESH": {
|
|
984
|
+
const { share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId } = params;
|
|
985
|
+
const { protocolId, signer } = await refresh(
|
|
986
|
+
ctx,
|
|
987
|
+
share,
|
|
988
|
+
walletId,
|
|
989
|
+
userId,
|
|
990
|
+
oldPartnerId,
|
|
991
|
+
newPartnerId,
|
|
992
|
+
keyShareProtocolId
|
|
993
|
+
);
|
|
994
|
+
return returnObject ? { protocolId, signer } : signer;
|
|
995
|
+
}
|
|
996
|
+
case "PREKEYGEN": {
|
|
997
|
+
const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
|
|
998
|
+
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
999
|
+
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
1000
|
+
pregenIdentifier = email;
|
|
1001
|
+
pregenIdentifierType = "EMAIL";
|
|
1002
|
+
}
|
|
1003
|
+
const keygenRes = await preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
1004
|
+
return keygenRes;
|
|
1005
|
+
}
|
|
1006
|
+
case "GET_PRIVATE_KEY": {
|
|
1007
|
+
const { share, walletId, userId } = params;
|
|
1008
|
+
return await getPrivateKey(ctx, share, walletId, userId);
|
|
1009
|
+
}
|
|
1010
|
+
case "ED25519_KEYGEN": {
|
|
1011
|
+
const { userId } = params;
|
|
1012
|
+
return ed25519Keygen(ctx, userId);
|
|
1013
|
+
}
|
|
1014
|
+
case "ED25519_SIGN": {
|
|
1015
|
+
const { share, walletId, userId, base64Bytes } = params;
|
|
1016
|
+
return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
1017
|
+
}
|
|
1018
|
+
case "ED25519_PREKEYGEN": {
|
|
1019
|
+
const { email } = params;
|
|
1020
|
+
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
1021
|
+
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
1022
|
+
pregenIdentifier = email;
|
|
1023
|
+
pregenIdentifierType = "EMAIL";
|
|
1024
|
+
}
|
|
1025
|
+
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
1026
|
+
}
|
|
1027
|
+
default: {
|
|
1028
|
+
throw new Error(`functionType: ${functionType} not supported`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
async function handleMessage(e, postMessage, useFetchAdapter) {
|
|
1033
|
+
const {
|
|
1034
|
+
env,
|
|
1035
|
+
apiKey,
|
|
1036
|
+
cosmosPrefix = "cosmos",
|
|
1037
|
+
offloadMPCComputationURL,
|
|
1038
|
+
disableWorkers,
|
|
1039
|
+
sessionCookie,
|
|
1040
|
+
useDKLS,
|
|
1041
|
+
disableWebSockets,
|
|
1042
|
+
wasmOverride
|
|
1043
|
+
} = e.data;
|
|
1044
|
+
if (!env) {
|
|
1045
|
+
return true;
|
|
1046
|
+
}
|
|
1047
|
+
const ctx = {
|
|
1048
|
+
env,
|
|
1049
|
+
apiKey,
|
|
1050
|
+
cosmosPrefix,
|
|
1051
|
+
client: initClient({
|
|
1052
|
+
env,
|
|
1053
|
+
version: paraVersion,
|
|
1054
|
+
apiKey,
|
|
1055
|
+
useFetchAdapter,
|
|
1056
|
+
retrieveSessionCookie: () => sessionCookie
|
|
1057
|
+
}),
|
|
1058
|
+
offloadMPCComputationURL,
|
|
1059
|
+
mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
|
|
1060
|
+
useDKLS,
|
|
1061
|
+
disableWebSockets: !!disableWebSockets,
|
|
1062
|
+
wasmOverride
|
|
1063
|
+
};
|
|
1064
|
+
if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
|
|
1065
|
+
await loadWasm(ctx, wasmOverride);
|
|
1066
|
+
}
|
|
1067
|
+
const result = await executeMessage(ctx, e.data);
|
|
1068
|
+
postMessage(result);
|
|
1069
|
+
return false;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// src/workers/workerWrapper.ts
|
|
1073
|
+
async function setupWorker(ctx, resFunction) {
|
|
1074
|
+
const onmessage = (event) => {
|
|
1075
|
+
if (event.data.functionType === "CUSTOM") {
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
resFunction(event.data);
|
|
1079
|
+
};
|
|
1080
|
+
if (ctx.disableWorkers) {
|
|
1081
|
+
const syncWorker = {
|
|
1082
|
+
postMessage: function(message) {
|
|
1083
|
+
(async function() {
|
|
1084
|
+
await handleMessage({ data: message }, (data) => onmessage({ data }), ctx.disableWorkers);
|
|
1085
|
+
})();
|
|
1086
|
+
},
|
|
1087
|
+
terminate: () => {
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
return syncWorker;
|
|
1092
|
+
}
|
|
1093
|
+
let worker;
|
|
1094
|
+
if (ctx.useLocalFiles) {
|
|
1095
|
+
throw new Error("useLocalFiles only supported locally");
|
|
1096
|
+
} else {
|
|
1097
|
+
const workerRes = await fetch(`${getPortalBaseURL2(ctx)}/static/js/mpcWorker-bundle.js`);
|
|
1098
|
+
const workerBlob = new Blob([await workerRes.text()], { type: "application/javascript" });
|
|
1099
|
+
const workerScriptURL = URL.createObjectURL(workerBlob);
|
|
1100
|
+
worker = new Worker(workerScriptURL);
|
|
1101
|
+
}
|
|
1102
|
+
worker.onmessage = onmessage;
|
|
1103
|
+
return worker;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// src/wallet/keygen.ts
|
|
1107
|
+
import { distributeNewShare, waitUntilTrue } from "@getpara/core-sdk";
|
|
1108
|
+
async function isKeygenComplete(ctx, userId, walletId) {
|
|
1109
|
+
const wallets = await ctx.client.getWallets(userId);
|
|
1110
|
+
const wallet = wallets.data.wallets.find((w) => w.id === walletId);
|
|
1111
|
+
return !!wallet.address;
|
|
1112
|
+
}
|
|
1113
|
+
async function isRefreshComplete(ctx, userId, walletId, partnerId, protocolId) {
|
|
1114
|
+
const { isDone } = await ctx.client.isRefreshDone(userId, walletId, partnerId, protocolId);
|
|
1115
|
+
return isDone;
|
|
1116
|
+
}
|
|
1117
|
+
async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
|
|
1118
|
+
const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
|
|
1119
|
+
const wallet = wallets.wallets.find((w) => w.id === walletId);
|
|
1120
|
+
return !!wallet.address;
|
|
1121
|
+
}
|
|
1122
|
+
function keygen2(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, emailProps = {}) {
|
|
1123
|
+
return new Promise(async (resolve) => {
|
|
1124
|
+
const worker = await setupWorker(ctx, async (res) => {
|
|
1125
|
+
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
1126
|
+
if (skipDistribute) {
|
|
1127
|
+
resolve({
|
|
1128
|
+
signer: res.signer,
|
|
1129
|
+
walletId: res.walletId,
|
|
1130
|
+
recoveryShare: null
|
|
1131
|
+
});
|
|
1132
|
+
worker.terminate();
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
const recoveryShare = await distributeNewShare({
|
|
1136
|
+
ctx,
|
|
1137
|
+
userId,
|
|
1138
|
+
walletId: res.walletId,
|
|
1139
|
+
userShare: res.signer,
|
|
1140
|
+
emailProps
|
|
1141
|
+
});
|
|
1142
|
+
resolve({
|
|
1143
|
+
signer: res.signer,
|
|
1144
|
+
walletId: res.walletId,
|
|
1145
|
+
recoveryShare
|
|
1146
|
+
});
|
|
1147
|
+
worker.terminate();
|
|
1148
|
+
});
|
|
1149
|
+
worker.postMessage({
|
|
1150
|
+
env: ctx.env,
|
|
1151
|
+
apiKey: ctx.apiKey,
|
|
1152
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1153
|
+
params: { userId, secretKey, type },
|
|
1154
|
+
functionType: "KEYGEN",
|
|
1155
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
1156
|
+
disableWorkers: ctx.disableWorkers,
|
|
1157
|
+
sessionCookie,
|
|
1158
|
+
useDKLS: ctx.useDKLS,
|
|
1159
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1160
|
+
wasmOverride: ctx.wasmOverride
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
function preKeygen2(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
1165
|
+
return new Promise(async (resolve) => {
|
|
1166
|
+
const worker = await setupWorker(ctx, async (res) => {
|
|
1167
|
+
await waitUntilTrue(
|
|
1168
|
+
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
1169
|
+
15e3,
|
|
1170
|
+
1e3
|
|
1171
|
+
);
|
|
1172
|
+
resolve({
|
|
1173
|
+
signer: res.signer,
|
|
1174
|
+
walletId: res.walletId,
|
|
1175
|
+
recoveryShare: null
|
|
1176
|
+
});
|
|
1177
|
+
worker.terminate();
|
|
1178
|
+
});
|
|
1179
|
+
const email = void 0;
|
|
1180
|
+
const params = { pregenIdentifier, pregenIdentifierType, type, secretKey, partnerId, email };
|
|
1181
|
+
if (pregenIdentifierType === "EMAIL") {
|
|
1182
|
+
params.email = pregenIdentifier;
|
|
1183
|
+
}
|
|
1184
|
+
worker.postMessage({
|
|
1185
|
+
env: ctx.env,
|
|
1186
|
+
apiKey: ctx.apiKey,
|
|
1187
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1188
|
+
params,
|
|
1189
|
+
functionType: "PREKEYGEN",
|
|
1190
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
1191
|
+
disableWorkers: ctx.disableWorkers,
|
|
1192
|
+
sessionCookie,
|
|
1193
|
+
useDKLS: ctx.useDKLS,
|
|
1194
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1195
|
+
wasmOverride: ctx.wasmOverride
|
|
1196
|
+
});
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
function refresh2(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
1200
|
+
return new Promise(async (resolve) => {
|
|
1201
|
+
const worker = await setupWorker(ctx, async (res) => {
|
|
1202
|
+
if (!await waitUntilTrue(async () => isRefreshComplete(ctx, userId, walletId, newPartnerId), 15e3, 1e3)) {
|
|
1203
|
+
throw new Error("refresh failed");
|
|
1204
|
+
}
|
|
1205
|
+
const { protocolId, signer } = res;
|
|
1206
|
+
resolve({
|
|
1207
|
+
signer,
|
|
1208
|
+
protocolId
|
|
1209
|
+
});
|
|
1210
|
+
worker.terminate();
|
|
1211
|
+
});
|
|
1212
|
+
worker.postMessage({
|
|
1213
|
+
env: ctx.env,
|
|
1214
|
+
apiKey: ctx.apiKey,
|
|
1215
|
+
params: { userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId },
|
|
1216
|
+
functionType: "REFRESH",
|
|
1217
|
+
disableWorkers: ctx.disableWorkers,
|
|
1218
|
+
sessionCookie,
|
|
1219
|
+
useDKLS: ctx.useDKLS,
|
|
1220
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1221
|
+
wasmOverride: ctx.wasmOverride,
|
|
1222
|
+
returnObject: true
|
|
1223
|
+
});
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
function ed25519Keygen2(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
1227
|
+
return new Promise(async (resolve) => {
|
|
1228
|
+
const worker = await setupWorker(ctx, async (res) => {
|
|
1229
|
+
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
1230
|
+
resolve({
|
|
1231
|
+
signer: res.signer,
|
|
1232
|
+
walletId: res.walletId,
|
|
1233
|
+
recoveryShare: null
|
|
1234
|
+
});
|
|
1235
|
+
worker.terminate();
|
|
1236
|
+
});
|
|
1237
|
+
worker.postMessage({
|
|
1238
|
+
env: ctx.env,
|
|
1239
|
+
apiKey: ctx.apiKey,
|
|
1240
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1241
|
+
params: { userId },
|
|
1242
|
+
functionType: "ED25519_KEYGEN",
|
|
1243
|
+
disableWorkers: ctx.disableWorkers,
|
|
1244
|
+
sessionCookie,
|
|
1245
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1246
|
+
wasmOverride: ctx.wasmOverride
|
|
1247
|
+
});
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
function ed25519PreKeygen2(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
1251
|
+
return new Promise(async (resolve) => {
|
|
1252
|
+
const worker = await setupWorker(ctx, async (res) => {
|
|
1253
|
+
await waitUntilTrue(
|
|
1254
|
+
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
1255
|
+
15e3,
|
|
1256
|
+
1e3
|
|
1257
|
+
);
|
|
1258
|
+
resolve({
|
|
1259
|
+
signer: res.signer,
|
|
1260
|
+
walletId: res.walletId,
|
|
1261
|
+
recoveryShare: null
|
|
1262
|
+
});
|
|
1263
|
+
worker.terminate();
|
|
1264
|
+
});
|
|
1265
|
+
const email = void 0;
|
|
1266
|
+
const params = { pregenIdentifier, pregenIdentifierType, email };
|
|
1267
|
+
if (pregenIdentifierType === "EMAIL") {
|
|
1268
|
+
params.email = pregenIdentifier;
|
|
1269
|
+
}
|
|
1270
|
+
worker.postMessage({
|
|
1271
|
+
env: ctx.env,
|
|
1272
|
+
apiKey: ctx.apiKey,
|
|
1273
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1274
|
+
params,
|
|
1275
|
+
functionType: "ED25519_PREKEYGEN",
|
|
1276
|
+
disableWorkers: ctx.disableWorkers,
|
|
1277
|
+
sessionCookie,
|
|
1278
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1279
|
+
wasmOverride: ctx.wasmOverride
|
|
1280
|
+
});
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// src/wallet/signing.ts
|
|
1285
|
+
async function signTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
1286
|
+
return await new Promise(async (resolve) => {
|
|
1287
|
+
const worker = await setupWorker(ctx, async (sendTransactionRes) => {
|
|
1288
|
+
resolve(sendTransactionRes);
|
|
1289
|
+
worker.terminate();
|
|
1290
|
+
});
|
|
1291
|
+
worker.postMessage({
|
|
1292
|
+
env: ctx.env,
|
|
1293
|
+
apiKey: ctx.apiKey,
|
|
1294
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1295
|
+
params: { share, walletId, userId, tx, chainId },
|
|
1296
|
+
functionType: "SIGN_TRANSACTION",
|
|
1297
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
1298
|
+
disableWorkers: ctx.disableWorkers,
|
|
1299
|
+
sessionCookie,
|
|
1300
|
+
useDKLS: isDKLS,
|
|
1301
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1302
|
+
wasmOverride: ctx.wasmOverride
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
async function sendTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
1307
|
+
return await new Promise(async (resolve) => {
|
|
1308
|
+
const worker = await setupWorker(ctx, async (sendTransactionRes) => {
|
|
1309
|
+
resolve(sendTransactionRes);
|
|
1310
|
+
worker.terminate();
|
|
1311
|
+
});
|
|
1312
|
+
worker.postMessage({
|
|
1313
|
+
env: ctx.env,
|
|
1314
|
+
apiKey: ctx.apiKey,
|
|
1315
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1316
|
+
params: { share, walletId, userId, tx, chainId },
|
|
1317
|
+
functionType: "SEND_TRANSACTION",
|
|
1318
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
1319
|
+
disableWorkers: ctx.disableWorkers,
|
|
1320
|
+
sessionCookie,
|
|
1321
|
+
useDKLS: isDKLS,
|
|
1322
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1323
|
+
wasmOverride: ctx.wasmOverride
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
async function signMessage2(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
|
|
1328
|
+
return await new Promise(async (resolve) => {
|
|
1329
|
+
const worker = await setupWorker(ctx, async (signMessageRes) => {
|
|
1330
|
+
resolve(signMessageRes);
|
|
1331
|
+
worker.terminate();
|
|
1332
|
+
});
|
|
1333
|
+
worker.postMessage({
|
|
1334
|
+
env: ctx.env,
|
|
1335
|
+
apiKey: ctx.apiKey,
|
|
1336
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1337
|
+
params: { share, walletId, userId, message, cosmosSignDoc },
|
|
1338
|
+
functionType: "SIGN_MESSAGE",
|
|
1339
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
1340
|
+
disableWorkers: ctx.disableWorkers,
|
|
1341
|
+
sessionCookie,
|
|
1342
|
+
useDKLS: isDKLS,
|
|
1343
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1344
|
+
wasmOverride: ctx.wasmOverride
|
|
1345
|
+
});
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
async function ed25519Sign2(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
1349
|
+
return await new Promise(async (resolve) => {
|
|
1350
|
+
const worker = await setupWorker(ctx, async (signMessageRes) => {
|
|
1351
|
+
resolve(signMessageRes);
|
|
1352
|
+
worker.terminate();
|
|
1353
|
+
});
|
|
1354
|
+
worker.postMessage({
|
|
1355
|
+
env: ctx.env,
|
|
1356
|
+
apiKey: ctx.apiKey,
|
|
1357
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1358
|
+
params: { share, walletId, userId, base64Bytes },
|
|
1359
|
+
functionType: "ED25519_SIGN",
|
|
1360
|
+
disableWorkers: ctx.disableWorkers,
|
|
1361
|
+
sessionCookie,
|
|
1362
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1363
|
+
wasmOverride: ctx.wasmOverride
|
|
1364
|
+
});
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// src/wallet/privateKey.ts
|
|
1369
|
+
async function getPrivateKey2(ctx, userId, walletId, share, sessionCookie) {
|
|
1370
|
+
return await new Promise(async (resolve) => {
|
|
1371
|
+
const worker = await setupWorker(ctx, async (res) => {
|
|
1372
|
+
resolve(res);
|
|
1373
|
+
worker.terminate();
|
|
1374
|
+
});
|
|
1375
|
+
worker.postMessage({
|
|
1376
|
+
env: ctx.env,
|
|
1377
|
+
apiKey: ctx.apiKey,
|
|
1378
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
1379
|
+
params: { share, walletId, userId },
|
|
1380
|
+
functionType: "GET_PRIVATE_KEY",
|
|
1381
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
1382
|
+
disableWorkers: ctx.disableWorkers,
|
|
1383
|
+
sessionCookie,
|
|
1384
|
+
useDKLS: ctx.useDKLS,
|
|
1385
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
1386
|
+
wasmOverride: ctx.wasmOverride
|
|
1387
|
+
});
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
// src/WebUtils.ts
|
|
1392
|
+
var WebUtils = class {
|
|
1393
|
+
constructor() {
|
|
1394
|
+
this.localStorage = new LocalStorage();
|
|
1395
|
+
this.sessionStorage = new SessionStorage();
|
|
1396
|
+
this.secureStorage = null;
|
|
1397
|
+
this.isSyncStorage = true;
|
|
1398
|
+
this.disableProviderModal = false;
|
|
1399
|
+
}
|
|
1400
|
+
getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
1401
|
+
return getPrivateKey2(ctx, userId, walletId, share, sessionCookie);
|
|
1402
|
+
}
|
|
1403
|
+
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps = {}) {
|
|
1404
|
+
return keygen2(ctx, userId, type, secretKey, true, sessionCookie, emailProps);
|
|
1405
|
+
}
|
|
1406
|
+
refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
1407
|
+
return refresh2(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId);
|
|
1408
|
+
}
|
|
1409
|
+
preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, sessionCookie) {
|
|
1410
|
+
return preKeygen2(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
|
|
1411
|
+
}
|
|
1412
|
+
signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
|
|
1413
|
+
return signMessage2(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc);
|
|
1414
|
+
}
|
|
1415
|
+
signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
1416
|
+
return signTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
1417
|
+
}
|
|
1418
|
+
sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
1419
|
+
return sendTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
1420
|
+
}
|
|
1421
|
+
signHash(_address, _hash) {
|
|
1422
|
+
throw new Error("not implemented");
|
|
1423
|
+
}
|
|
1424
|
+
ed25519Keygen(ctx, userId, sessionCookie, emailProps) {
|
|
1425
|
+
return ed25519Keygen2(ctx, userId, sessionCookie, emailProps);
|
|
1426
|
+
}
|
|
1427
|
+
ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
1428
|
+
return ed25519PreKeygen2(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie);
|
|
1429
|
+
}
|
|
1430
|
+
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
1431
|
+
return ed25519Sign2(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
1432
|
+
}
|
|
1433
|
+
openPopup(popupUrl, opts) {
|
|
1434
|
+
if (typeof window === "undefined") {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
if (opts) {
|
|
1438
|
+
const { type } = opts;
|
|
1439
|
+
const popUpWidth = 550;
|
|
1440
|
+
let popUpHeight;
|
|
1441
|
+
switch (type) {
|
|
1442
|
+
case PopupType.LOGIN_PASSKEY: {
|
|
1443
|
+
popUpHeight = 798;
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
case PopupType.CREATE_PASSKEY: {
|
|
1447
|
+
popUpHeight = 464;
|
|
1448
|
+
break;
|
|
1449
|
+
}
|
|
1450
|
+
case PopupType.SIGN_MESSAGE_REVIEW: {
|
|
1451
|
+
popUpHeight = 585;
|
|
1452
|
+
break;
|
|
1453
|
+
}
|
|
1454
|
+
case PopupType.SIGN_TRANSACTION_REVIEW: {
|
|
1455
|
+
popUpHeight = 750;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
case PopupType.OAUTH:
|
|
1459
|
+
default: {
|
|
1460
|
+
popUpHeight = 768;
|
|
1461
|
+
break;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
const dualScreenLeft = window.screenLeft !== void 0 ? window.screenLeft : window.screenX;
|
|
1465
|
+
const dualScreenTop = window.screenTop !== void 0 ? window.screenTop : window.screenY;
|
|
1466
|
+
const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
|
1467
|
+
const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
|
|
1468
|
+
const left = (width - popUpWidth) / 2 + dualScreenLeft;
|
|
1469
|
+
const top = (height - popUpHeight) / 2 + dualScreenTop;
|
|
1470
|
+
const windowFeatures = `toolbar=no, menubar=no, width=${popUpWidth},
|
|
1471
|
+
height=${popUpHeight}, top=${top}, left=${left}`;
|
|
1472
|
+
let popupWindow = window.open(popupUrl, type.toString(), windowFeatures);
|
|
1473
|
+
if (!popupWindow) {
|
|
1474
|
+
setTimeout(() => {
|
|
1475
|
+
popupWindow = window.open(popupUrl, "_blank");
|
|
1476
|
+
}, 0);
|
|
1477
|
+
}
|
|
1478
|
+
return popupWindow;
|
|
1479
|
+
} else {
|
|
1480
|
+
const popupWindow = window.open(popupUrl, "popup", "popup=true,width=400,height=500");
|
|
1481
|
+
if (!popupWindow) {
|
|
1482
|
+
setTimeout(() => {
|
|
1483
|
+
window.open(popupUrl, "_blank");
|
|
1484
|
+
}, 0);
|
|
1485
|
+
}
|
|
1486
|
+
return popupWindow;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
// src/ParaWeb.ts
|
|
1492
|
+
var Para = class extends ParaCore {
|
|
1493
|
+
constructor(env, apiKey, opts) {
|
|
1494
|
+
super(env, apiKey, opts);
|
|
1495
|
+
if (env !== Environment2.PROD && env !== Environment2.DEV) {
|
|
1496
|
+
Sentry.init({
|
|
1497
|
+
environment: env.toLowerCase(),
|
|
1498
|
+
dsn: "https://38f27d4836da617ab9e95cf66b9611d9@o4504568036720640.ingest.us.sentry.io/4508850812944384"
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
getPlatformUtils() {
|
|
1503
|
+
return new WebUtils();
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// src/index.ts
|
|
1508
|
+
import ParaCore2 from "@getpara/core-sdk";
|
|
1509
|
+
import {
|
|
1510
|
+
Environment as Environment4
|
|
1511
|
+
} from "@getpara/core-sdk";
|
|
1512
|
+
|
|
1513
|
+
// src/cryptography/webAuth.ts
|
|
1514
|
+
import base64url from "base64url";
|
|
1515
|
+
import * as cbor from "cbor-web";
|
|
1516
|
+
import forge from "node-forge";
|
|
1517
|
+
import { getPortalDomain } from "@getpara/core-sdk";
|
|
1518
|
+
var ES256_ALGORITHM = -7;
|
|
1519
|
+
var RS256_ALGORITHM = -257;
|
|
1520
|
+
function publicKeyCredentialToJSON(pubKeyCred) {
|
|
1521
|
+
if (pubKeyCred instanceof ArrayBuffer) {
|
|
1522
|
+
return base64url.encode(pubKeyCred);
|
|
1523
|
+
} else if (pubKeyCred instanceof Array) {
|
|
1524
|
+
return pubKeyCred.map(publicKeyCredentialToJSON);
|
|
1525
|
+
} else if (pubKeyCred instanceof Object) {
|
|
1526
|
+
const obj = {};
|
|
1527
|
+
for (const key in pubKeyCred) {
|
|
1528
|
+
obj[key] = publicKeyCredentialToJSON(pubKeyCred[key]);
|
|
1529
|
+
}
|
|
1530
|
+
return obj;
|
|
1531
|
+
} else return pubKeyCred;
|
|
1532
|
+
}
|
|
1533
|
+
function parseMakeCredAuthData(buffer) {
|
|
1534
|
+
const rpIdHash = buffer.slice(0, 32);
|
|
1535
|
+
buffer = buffer.slice(32);
|
|
1536
|
+
const flagsBuf = buffer.slice(0, 1);
|
|
1537
|
+
buffer = buffer.slice(1);
|
|
1538
|
+
const flags = flagsBuf[0];
|
|
1539
|
+
const counterBuf = buffer.slice(0, 4);
|
|
1540
|
+
buffer = buffer.slice(4);
|
|
1541
|
+
const counter = counterBuf.readUInt32BE(0);
|
|
1542
|
+
const aaguid = buffer.slice(0, 16);
|
|
1543
|
+
buffer = buffer.slice(16);
|
|
1544
|
+
const credIDLenBuf = buffer.slice(0, 2);
|
|
1545
|
+
buffer = buffer.slice(2);
|
|
1546
|
+
const credIDLen = credIDLenBuf.readUInt16BE(0);
|
|
1547
|
+
const credID = buffer.slice(0, credIDLen);
|
|
1548
|
+
buffer = buffer.slice(credIDLen);
|
|
1549
|
+
const COSEPublicKey = buffer;
|
|
1550
|
+
return {
|
|
1551
|
+
rpIdHash,
|
|
1552
|
+
flagsBuf,
|
|
1553
|
+
flags,
|
|
1554
|
+
counter,
|
|
1555
|
+
counterBuf,
|
|
1556
|
+
aaguid,
|
|
1557
|
+
credID,
|
|
1558
|
+
COSEPublicKey
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
function parseAttestationObject(attestationObject) {
|
|
1562
|
+
const attestationObjectBuffer = base64url.toBuffer(attestationObject);
|
|
1563
|
+
return cbor.decodeAllSync(attestationObjectBuffer)[0];
|
|
1564
|
+
}
|
|
1565
|
+
function COSEECDSAtoPKCS(COSEPublicKey) {
|
|
1566
|
+
const coseStruct = cbor.decodeAllSync(COSEPublicKey)[0];
|
|
1567
|
+
const tag = Buffer.from([4]);
|
|
1568
|
+
const x = coseStruct.get(-2);
|
|
1569
|
+
const y = coseStruct.get(-3);
|
|
1570
|
+
return Buffer.concat([tag, x, y]);
|
|
1571
|
+
}
|
|
1572
|
+
function COSERSAtoPKCS(COSEPublicKey) {
|
|
1573
|
+
const coseStruct = cbor.decodeAllSync(COSEPublicKey)[0];
|
|
1574
|
+
const n = coseStruct.get(-1);
|
|
1575
|
+
const e = coseStruct.get(-2);
|
|
1576
|
+
const nForge = forge.util.createBuffer(n.toString("binary"));
|
|
1577
|
+
const eForge = forge.util.createBuffer(e.toString("binary"));
|
|
1578
|
+
const publicKey = forge.pki.setRsaPublicKey(
|
|
1579
|
+
new forge.jsbn.BigInteger(nForge.toHex(), 16),
|
|
1580
|
+
new forge.jsbn.BigInteger(eForge.toHex(), 16)
|
|
1581
|
+
);
|
|
1582
|
+
return Buffer.from(forge.pki.publicKeyToPem(publicKey), "utf-8");
|
|
1583
|
+
}
|
|
1584
|
+
function parseCredentialCreationRes(creds, algorithm) {
|
|
1585
|
+
const parsedAttestation = parseAttestationObject(creds.response.attestationObject);
|
|
1586
|
+
const { COSEPublicKey, aaguid } = parseMakeCredAuthData(parsedAttestation.authData);
|
|
1587
|
+
if (algorithm === RS256_ALGORITHM) {
|
|
1588
|
+
return {
|
|
1589
|
+
cosePublicKey: base64url.encode(COSERSAtoPKCS(COSEPublicKey)),
|
|
1590
|
+
clientDataJSON: creds.response.clientDataJSON,
|
|
1591
|
+
aaguid: aaguid.toString("hex")
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
return {
|
|
1595
|
+
cosePublicKey: base64url.encode(COSEECDSAtoPKCS(COSEPublicKey)),
|
|
1596
|
+
clientDataJSON: creds.response.clientDataJSON,
|
|
1597
|
+
aaguid: aaguid.toString("hex")
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
function generateUserHandle() {
|
|
1601
|
+
const userHandle = new Uint8Array(32);
|
|
1602
|
+
window.crypto.getRandomValues(userHandle);
|
|
1603
|
+
return userHandle;
|
|
1604
|
+
}
|
|
1605
|
+
async function createCredential(env, userId, identifier, isE2E) {
|
|
1606
|
+
if (typeof navigator === "undefined") {
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
const userHandle = generateUserHandle();
|
|
1610
|
+
const createCredentialDefaultArgs = {
|
|
1611
|
+
publicKey: {
|
|
1612
|
+
authenticatorSelection: {
|
|
1613
|
+
authenticatorAttachment: "platform",
|
|
1614
|
+
requireResidentKey: true,
|
|
1615
|
+
residentKey: "required",
|
|
1616
|
+
userVerification: "required"
|
|
1617
|
+
},
|
|
1618
|
+
rp: {
|
|
1619
|
+
id: getPortalDomain(env, isE2E),
|
|
1620
|
+
name: "Para"
|
|
1621
|
+
},
|
|
1622
|
+
user: {
|
|
1623
|
+
id: userHandle,
|
|
1624
|
+
name: identifier,
|
|
1625
|
+
displayName: identifier
|
|
1626
|
+
},
|
|
1627
|
+
pubKeyCredParams: [
|
|
1628
|
+
{ type: "public-key", alg: ES256_ALGORITHM },
|
|
1629
|
+
// RS256_ALGORITHM should only be needed for windows hello
|
|
1630
|
+
{ type: "public-key", alg: RS256_ALGORITHM }
|
|
1631
|
+
],
|
|
1632
|
+
attestation: "direct",
|
|
1633
|
+
timeout: 6e4,
|
|
1634
|
+
// TODO: don't think we really get value from verifying this, but should revisit
|
|
1635
|
+
challenge: Buffer.from(userId, "utf-8")
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
const credential = await navigator.credentials.create(createCredentialDefaultArgs);
|
|
1639
|
+
const algorithm = credential.response.getPublicKeyAlgorithm ? credential.response.getPublicKeyAlgorithm() : ES256_ALGORITHM;
|
|
1640
|
+
const userHandleEncoded = base64url.encode(Buffer.from(userHandle));
|
|
1641
|
+
return {
|
|
1642
|
+
creds: publicKeyCredentialToJSON(credential),
|
|
1643
|
+
userHandle: userHandleEncoded,
|
|
1644
|
+
algorithm
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
async function generateSignature(env, challenge, allowedPublicKeys, isE2E) {
|
|
1648
|
+
const getCredentialDefaultArgs = {
|
|
1649
|
+
publicKey: {
|
|
1650
|
+
timeout: 6e4,
|
|
1651
|
+
challenge: Buffer.from(challenge, "base64"),
|
|
1652
|
+
allowCredentials: allowedPublicKeys.map((key) => ({
|
|
1653
|
+
id: base64url.toBuffer(key),
|
|
1654
|
+
type: "public-key"
|
|
1655
|
+
})),
|
|
1656
|
+
userVerification: "required",
|
|
1657
|
+
rpId: getPortalDomain(env, isE2E)
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
const assertation = await navigator.credentials.get(getCredentialDefaultArgs);
|
|
1661
|
+
return publicKeyCredentialToJSON(assertation);
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
// src/utils/truncateEthAddress.ts
|
|
1665
|
+
var truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/;
|
|
1666
|
+
var truncateEthAddress = (address) => {
|
|
1667
|
+
const match = address.match(truncateRegex);
|
|
1668
|
+
if (!match) return address;
|
|
1669
|
+
return `${match[1]}\u2026${match[2]}`;
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
// src/utils/isPasskeySupported.ts
|
|
1673
|
+
import { UAParser } from "ua-parser-js";
|
|
1674
|
+
var isPasskeySupported = (userAgent) => {
|
|
1675
|
+
const osName = new UAParser(userAgent).getOS().name?.toLowerCase();
|
|
1676
|
+
return !!osName && !["linux", "chrome os"].includes(osName);
|
|
1677
|
+
};
|
|
1678
|
+
|
|
1679
|
+
// src/utils/isMobile.ts
|
|
1680
|
+
function isAndroid() {
|
|
1681
|
+
return typeof navigator !== "undefined" && /android/i.test(navigator.userAgent);
|
|
1682
|
+
}
|
|
1683
|
+
function isSmallIOS() {
|
|
1684
|
+
return typeof navigator !== "undefined" && /iPhone|iPod/.test(navigator.userAgent);
|
|
1685
|
+
}
|
|
1686
|
+
function isLargeIOS() {
|
|
1687
|
+
return typeof navigator !== "undefined" && (/iPad/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
|
|
1688
|
+
}
|
|
1689
|
+
function isTablet() {
|
|
1690
|
+
return typeof navigator !== "undefined" && /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
|
|
1691
|
+
navigator.userAgent
|
|
1692
|
+
);
|
|
1693
|
+
}
|
|
1694
|
+
function isIOS() {
|
|
1695
|
+
return isSmallIOS() || isLargeIOS();
|
|
1696
|
+
}
|
|
1697
|
+
function isMobile() {
|
|
1698
|
+
return isAndroid() || isIOS();
|
|
1699
|
+
}
|
|
1700
|
+
function isSafari() {
|
|
1701
|
+
return typeof navigator !== "undefined" && /AppleWebKit/i.test(navigator.userAgent) && !/CriOS/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent);
|
|
1702
|
+
}
|
|
1703
|
+
function isIOSWebview() {
|
|
1704
|
+
const isStandalone = typeof navigator !== "undefined" && !navigator.standalone;
|
|
1705
|
+
return typeof navigator !== "undefined" && isIOS() && !isStandalone && !/safari/i.test(navigator.userAgent.toLowerCase());
|
|
1706
|
+
}
|
|
1707
|
+
function isMobileSafari() {
|
|
1708
|
+
return isMobile() && isSafari();
|
|
1709
|
+
}
|
|
1710
|
+
function isTelegram() {
|
|
1711
|
+
return typeof window !== "undefined" && (Boolean(window.TelegramWebviewProxy) || Boolean(window.Telegram) || Boolean(window.TelegramWebviewProxyProto));
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
// src/index.ts
|
|
1715
|
+
var src_default = Para;
|
|
1716
|
+
export {
|
|
1717
|
+
Environment4 as Environment,
|
|
1718
|
+
ParaCore2 as ParaCore,
|
|
1719
|
+
Para as ParaWeb,
|
|
1720
|
+
createCredential,
|
|
1721
|
+
src_default as default,
|
|
1722
|
+
generateSignature,
|
|
1723
|
+
isAndroid,
|
|
1724
|
+
isIOS,
|
|
1725
|
+
isIOSWebview,
|
|
1726
|
+
isLargeIOS,
|
|
1727
|
+
isMobile,
|
|
1728
|
+
isMobileSafari,
|
|
1729
|
+
isPasskeySupported,
|
|
1730
|
+
isSafari,
|
|
1731
|
+
isSmallIOS,
|
|
1732
|
+
isTablet,
|
|
1733
|
+
isTelegram,
|
|
1734
|
+
parseCredentialCreationRes,
|
|
1735
|
+
truncateEthAddress
|
|
1736
|
+
};
|