@getpara/web-sdk 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ParaWeb.d.ts +2 -1
- package/dist/index.js +3 -3
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/package.json +5 -4
package/dist/ParaWeb.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import ParaCore from '@getpara/core-sdk';
|
|
1
|
+
import ParaCore, { ConstructorOpts, Environment } from '@getpara/core-sdk';
|
|
2
2
|
import { WebUtils } from './WebUtils.js';
|
|
3
3
|
export declare class Para extends ParaCore {
|
|
4
|
+
constructor(env: Environment, apiKey?: string, opts?: ConstructorOpts);
|
|
4
5
|
protected getPlatformUtils(): WebUtils;
|
|
5
6
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export*from"@getpara/core-sdk";import
|
|
3
|
-
`);return r!=-1&&(console.log(o.substring(0,r)),o=o.substring(r+1)),n.length},write(s,n,r,l,g,u){if(r!==0||l!==n.length||g!==null){u(e());return}let d=this.writeSync(s,n);u(null,d)},chmod(s,n,r){r(e())},chown(s,n,r,l){l(e())},close(s,n){n(e())},fchmod(s,n,r){r(e())},fchown(s,n,r,l){l(e())},fstat(s,n){n(e())},fsync(s,n){n(null)},ftruncate(s,n,r){r(e())},lchown(s,n,r,l){l(e())},link(s,n,r){r(e())},lstat(s,n){n(e())},mkdir(s,n,r){r(e())},open(s,n,r,l){l(e())},read(s,n,r,l,g,u){u(e())},readdir(s,n){n(e())},readlink(s,n){n(e())},rename(s,n,r){r(e())},rmdir(s,n){n(e())},stat(s,n){n(e())},symlink(s,n,r){r(e())},truncate(s,n,r){r(e())},unlink(s,n){n(e())},utimes(s,n,r,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 i=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 o=(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),m=this.mem.getInt32(t+4,!0);return c+m*4294967296},r=t=>{let c=this.mem.getFloat64(t,!0);if(c===0)return;if(!isNaN(c))return c;let m=this.mem.getUint32(t,!0);return this._values[m]},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),m=n(t+8);return new Uint8Array(this._inst.exports.mem.buffer,c,m)},u=t=>{let c=n(t+0),m=n(t+8),p=new Array(m);for(let y=0;y<m;y++)p[y]=r(c+y*8);return p},d=t=>{let c=n(t+0),m=n(t+8);return a.decode(new DataView(this._inst.exports.mem.buffer,c,m))},f=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),m=n(t+16),p=this.mem.getInt32(t+24,!0);fs.writeSync(c,new Uint8Array(this._inst.exports.mem.buffer,m,p))},"runtime.resetMemoryDataView":t=>{t>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{t>>>=0,o(t+8,(f+performance.now())*1e6)},"runtime.walltime":t=>{t>>>=0;let c=new Date().getTime();o(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 m=this._values[c];this._values[c]=null,this._ids.delete(m),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(r(t+8),d(t+16));t=this._inst.exports.getsp()>>>0,l(t+32,c)},"syscall/js.valueSet":t=>{t>>>=0,Reflect.set(r(t+8),d(t+16),r(t+32))},"syscall/js.valueDelete":t=>{t>>>=0,Reflect.deleteProperty(r(t+8),d(t+16))},"syscall/js.valueIndex":t=>{t>>>=0,l(t+24,Reflect.get(r(t+8),n(t+16)))},"syscall/js.valueSetIndex":t=>{t>>>=0,Reflect.set(r(t+8),n(t+16),r(t+24))},"syscall/js.valueCall":t=>{t>>>=0;try{let c=r(t+8),m=Reflect.get(c,d(t+16)),p=u(t+32),y=Reflect.apply(m,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=r(t+8),m=u(t+16),p=Reflect.apply(c,void 0,m);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=r(t+8),m=u(t+16),p=Reflect.construct(c,m);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,o(t+16,parseInt(r(t+8).length))},"syscall/js.valuePrepareString":t=>{t>>>=0;let c=i.encode(String(r(t+8)));l(t+16,c),o(t+24,c.length)},"syscall/js.valueLoadString":t=>{t>>>=0;let c=r(t+8);g(t+16).set(c)},"syscall/js.valueInstanceOf":t=>{t>>>=0,this.mem.setUint8(t+24,r(t+8)instanceof r(t+16)?1:0)},"syscall/js.copyBytesToGo":t=>{t>>>=0;let c=g(t+8),m=r(t+32);if(!(m instanceof Uint8Array||m instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let p=m.subarray(0,c.length);c.set(p),o(t+40,p.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{t>>>=0;let c=r(t+8),m=g(t+16);if(!(c instanceof Uint8Array||c instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let p=m.subarray(0,c.length);c.set(p),o(t+40,p.length),this.mem.setUint8(t+48,1)},debug:t=>{console.log(t)}}}}async run(o){if(!(o instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=o,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,globalThis,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[globalThis,5],[this,6]]),this._idPool=[],this.exited=!1;let s=4096,n=f=>{let t=s,c=i.encode(f+"\0");return new Uint8Array(this.mem.buffer,s,c.length).set(c),s+=c.length,s%8!==0&&(s+=8-s%8),t},r=this.argv.length,l=[];this.argv.forEach(f=>{l.push(n(f))}),l.push(0),Object.keys(this.env).sort().forEach(f=>{l.push(n(`${f}=${this.env[f]}`))}),l.push(0);let u=s;if(l.forEach(f=>{this.mem.setUint32(s,f,!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(r,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(o){let s=this;return function(){let n={id:o,this:this,args:arguments};return s._pendingEvent=n,s._resume(),n.result}}}})();import{getBaseMPCNetworkUrl as h,WalletScheme as P,WalletType as W}from"@getpara/core-sdk";var ae=(e,i,a)=>`{"ServerUrl":"${e}", "WalletId": "${i}", "Id":"${a}", "Ids":["USER","CAPSULE"], "Threshold":1}`,K=(e,i,a)=>`{"walletId": "${e}", "id":"${i}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${a}}`;async function le(e,i,a,o){let{data:s}=await e.mpcComputationClient.post("/wallets",{userId:i,walletId:a,protocolId:o});return s}async function ce(e,i,a,o,s,n){let{data:r}=await e.mpcComputationClient.post(`/wallets/${a}/messages/sign`,{userId:i,protocolId:o,message:s,signer:n});return r}async function U(e,i,a,o,s,n,r){let{data:l}=await e.mpcComputationClient.post(`/wallets/${a}/transactions/send`,{userId:i,protocolId:o,transaction:s,signer:n,chainId:r});return l}async function _(e,i){let{walletId:a,protocolId:o}=await e.client.createWallet(i,{scheme:P.ED25519,type:W.SOLANA}),s=h(e.env,!e.disableWebSockets);return{signer:await new Promise((r,l)=>globalThis.ed25519CreateAccount(s,a,o,(g,u)=>{g&&l(g),r(u)})),walletId:a}}async function O(e,i,a){let{walletId:o,protocolId:s}=await e.client.createPregenWallet({pregenIdentifier:i,pregenIdentifierType:a,scheme:P.ED25519,type:W.SOLANA}),n=h(e.env,!e.disableWebSockets);return{signer:await new Promise((l,g)=>globalThis.ed25519CreateAccount(n,o,s,(u,d)=>{u&&g(u),l(d)})),walletId:o}}async function L(e,i,a,o,s){let{protocolId:n}=await e.client.preSignMessage(a,o,s,P.ED25519);return{signature:await new Promise((l,g)=>globalThis.ed25519Sign(i,n,s,(u,d)=>{u&&g(u),l(d)}))}}async function M(e,i,a,o){let{walletId:s,protocolId:n}=await e.client.createWallet(i,{useTwoSigners:!0,scheme:e.useDKLS?P.DKLS:P.CGGMP,type:a,cosmosPrefix:a===W.COSMOS?e.cosmosPrefix:void 0});if(e.offloadMPCComputationURL&&!e.useDKLS)return{signer:(await le(e,i,s,n)).signer,walletId:s};let r=h(e.env,!e.disableWebSockets),l=e.useDKLS?K(s,"USER",e.disableWebSockets):ae(r,s,"USER"),g=e.useDKLS?globalThis.dklsCreateAccount:globalThis.createAccountV2;return{signer:await new Promise((d,f)=>g(l,r,n,o,()=>{},(t,c)=>{t&&f(t),d(c)})),walletId:s}}async function D(e,i,a,o,s,n){let{walletId:r,protocolId:l}=await e.client.createPregenWallet({pregenIdentifier:a,pregenIdentifierType:o,type:s,cosmosPrefix:s===W.COSMOS?e.cosmosPrefix:void 0}),g=h(e.env,!e.disableWebSockets),u=K(r,"USER",e.disableWebSockets);return{signer:await new Promise((f,t)=>globalThis.dklsCreateAccount(u,g,l,n,()=>{},(c,m)=>{c&&t(c),f(m)})),walletId:r}}async function N(e,i,a,o,s,n){let{protocolId:r,pendingTransactionId:l}=await e.client.preSignMessage(o,a,s,null,n);if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return ce(e,o,a,r,s,i);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSignMessage:globalThis.signMessage,d=JSON.parse(i);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),i=JSON.stringify(d),new Promise((f,t)=>u(i,g,s,r,(c,m)=>{c&&t(c),f({signature:m})}))}async function B(e,i,a,o,s,n){let{data:{protocolId:r,pendingTransactionId:l}}=await e.client.signTransaction(o,a,{transaction:s,chainId:n});if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return U(e,o,a,r,s,i,n);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSendTransaction:globalThis.sendTransaction,d=JSON.parse(i);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),i=JSON.stringify(d),new Promise((f,t)=>u(i,g,s,n,r,(c,m)=>{c&&t(c),f({signature:m})}))}async function x(e,i,a,o,s,n){let{data:{protocolId:r,pendingTransactionId:l}}=await e.client.sendTransaction(o,a,{transaction:s,chainId:n});if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return U(e,o,a,r,s,i,n);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSendTransaction:globalThis.sendTransaction,d=JSON.parse(i);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),i=JSON.stringify(d),new Promise((f,t)=>u(i,g,s,n,r,(c,m)=>{c&&t(c),f({signature:m})}))}async function j(e,i,a,o,s,n,r){let{data:{protocolId:l}}=await e.client.refreshKeys(o,a,s,n,r),g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsRefresh:globalThis.refresh,d=JSON.parse(i);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),i=JSON.stringify(d),new Promise((f,t)=>u(i,g,l,(c,m)=>{c&&t(c),f({protocolId:l,signer:m})}))}async function G(e,i,a,o){let s=await e.client.getParaShare(o,a);return s?new Promise((n,r)=>globalThis.getPrivateKey(i,s,(l,g)=>{l&&r(l),n(g)})):""}import{getPortalBaseURL as ue,initClient as de,mpcComputationClient as me,paraVersion as fe,WalletType as H}from"@getpara/core-sdk";async function pe(e,i){if(typeof self>"u")return;let a=new self.Go,o=i;if(!o){if(process.env.DISABLE_WASM_FETCH==="true")throw new Error("fetching wasm file is disabled");o=await(await fetch(`${ue(e)}/static/js/main.wasm`,{mode:"cors"})).arrayBuffer()}let s=await WebAssembly.instantiate(o,a.importObject);a.run(s.instance)}async function we(e,i){let{functionType:a,params:o,returnObject:s}=i;switch(a){case"KEYGEN":{let{userId:n,secretKey:r,type:l=H.EVM}=o;return await M(e,n,l,r)}case"SIGN_TRANSACTION":{let{share:n,walletId:r,userId:l,tx:g,chainId:u}=o;return B(e,n,r,l,g,u)}case"SEND_TRANSACTION":{let{share:n,walletId:r,userId:l,tx:g,chainId:u}=o;return x(e,n,r,l,g,u)}case"SIGN_MESSAGE":{let{share:n,walletId:r,userId:l,message:g,cosmosSignDoc:u}=o;return N(e,n,r,l,g,u)}case"REFRESH":{let{share:n,walletId:r,userId:l,oldPartnerId:g,newPartnerId:u,keyShareProtocolId:d}=o,{protocolId:f,signer:t}=await j(e,n,r,l,g,u,d);return s?{protocolId:f,signer:t}:t}case"PREKEYGEN":{let{email:n,partnerId:r,secretKey:l,type:g=H.EVM}=o,{pregenIdentifier:u,pregenIdentifierType:d}=o;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(u=n,d="EMAIL"),await D(e,r,u,d,g,l)}case"GET_PRIVATE_KEY":{let{share:n,walletId:r,userId:l}=o;return await G(e,n,r,l)}case"ED25519_KEYGEN":{let{userId:n}=o;return _(e,n)}case"ED25519_SIGN":{let{share:n,walletId:r,userId:l,base64Bytes:g}=o;return L(e,n,l,r,g)}case"ED25519_PREKEYGEN":{let{email:n}=o,{pregenIdentifier:r,pregenIdentifierType:l}=o;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(r=n,l="EMAIL"),O(e,r,l)}default:throw new Error(`functionType: ${a} not supported`)}}async function V(e,i,a){let{env:o,apiKey:s,cosmosPrefix:n="cosmos",offloadMPCComputationURL:r,disableWorkers:l,sessionCookie:g,useDKLS:u,disableWebSockets:d,wasmOverride:f}=e.data;if(!o)return!0;let t={env:o,apiKey:s,cosmosPrefix:n,client:de({env:o,version:fe,apiKey:s,useFetchAdapter:a,retrieveSessionCookie:()=>g}),offloadMPCComputationURL:r,mpcComputationClient:r?me.initClient(r,!!l):void 0,useDKLS:u,disableWebSockets:!!d,wasmOverride:f};(!t.offloadMPCComputationURL||t.useDKLS)&&await pe(t,f);let c=await we(t,e.data);return i(c),!1}async function w(e,i){let a=s=>{s.data.functionType!=="CUSTOM"&&i(s.data)};if(e.disableWorkers)return{postMessage:function(n){(async function(){await V({data:n},r=>a({data:r}),e.disableWorkers)})()},terminate:()=>{}};let o;if(e.useLocalFiles)throw new Error("useLocalFiles only supported locally");{let s=await fetch(`${ye(e)}/static/js/mpcWorker-bundle.js`),n=new Blob([await s.text()],{type:"application/javascript"}),r=URL.createObjectURL(n);o=new Worker(r)}return o.onmessage=a,o}import{distributeNewShare as he,waitUntilTrue as k}from"@getpara/core-sdk";async function F(e,i,a){return!!(await e.client.getWallets(i)).data.wallets.find(n=>n.id===a).address}async function Se(e,i,a,o,s){let{isDone:n}=await e.client.isRefreshDone(i,a,o,s);return n}async function $(e,i,a,o){return!!(await e.client.getPregenWallets({[a]:[i]})).wallets.find(r=>r.id===o).address}function J(e,i,a,o,s=!1,n,r={}){return new Promise(async l=>{let g=await w(e,async u=>{if(await k(async()=>F(e,i,u.walletId),15e3,1e3),s){l({signer:u.signer,walletId:u.walletId,recoveryShare:null}),g.terminate();return}let d=await he({ctx:e,userId:i,walletId:u.walletId,userShare:u.signer,emailProps:r});l({signer:u.signer,walletId:u.walletId,recoveryShare:d}),g.terminate()});g.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{userId:i,secretKey:o,type:a},functionType:"KEYGEN",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:n,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function Y(e,i,a,o,s,n=!1,r,l){return new Promise(async g=>{let u=await w(e,async t=>{await k(async()=>$(e,i,a,t.walletId),15e3,1e3),g({signer:t.signer,walletId:t.walletId,recoveryShare:null}),u.terminate()}),f={pregenIdentifier:i,pregenIdentifierType:a,type:o,secretKey:s,partnerId:r,email:void 0};a==="EMAIL"&&(f.email=i),u.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:f,functionType:"PREKEYGEN",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:l,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function q(e,i,a,o,s,n,r,l){return new Promise(async g=>{let u=await w(e,async d=>{if(!await k(async()=>Se(e,a,o,r),15e3,1e3))throw new Error("refresh failed");let{protocolId:f,signer:t}=d;g({signer:t,protocolId:f}),u.terminate()});u.postMessage({env:e.env,apiKey:e.apiKey,params:{userId:a,walletId:o,share:s,oldPartnerId:n,newPartnerId:r,keyShareProtocolId:l},functionType:"REFRESH",disableWorkers:e.disableWorkers,sessionCookie:i,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride,returnObject:!0})})}function z(e,i,a,o={}){return new Promise(async s=>{let n=await w(e,async r=>{await k(async()=>F(e,i,r.walletId),15e3,1e3),s({signer:r.signer,walletId:r.walletId,recoveryShare:null}),n.terminate()});n.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{userId:i},functionType:"ED25519_KEYGEN",disableWorkers:e.disableWorkers,sessionCookie:a,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function Z(e,i,a,o){return new Promise(async s=>{let n=await w(e,async g=>{await k(async()=>$(e,i,a,g.walletId),15e3,1e3),s({signer:g.signer,walletId:g.walletId,recoveryShare:null}),n.terminate()}),l={pregenIdentifier:i,pregenIdentifierType:a,email:void 0};a==="EMAIL"&&(l.email=i),n.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:l,functionType:"ED25519_PREKEYGEN",disableWorkers:e.disableWorkers,sessionCookie:o,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function X(e,i,a,o,s,n,r,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:o,walletId:a,userId:i,tx:s,chainId:n},functionType:"SIGN_TRANSACTION",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:r,useDKLS:l,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function Q(e,i,a,o,s,n,r,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:o,walletId:a,userId:i,tx:s,chainId:n},functionType:"SEND_TRANSACTION",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:r,useDKLS:l,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function ee(e,i,a,o,s,n,r,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:o,walletId:a,userId:i,message:s,cosmosSignDoc:l},functionType:"SIGN_MESSAGE",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:n,useDKLS:r,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function te(e,i,a,o,s,n){return await new Promise(async r=>{let l=await w(e,async g=>{r(g),l.terminate()});l.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:o,walletId:a,userId:i,base64Bytes:s},functionType:"ED25519_SIGN",disableWorkers:e.disableWorkers,sessionCookie:n,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function ne(e,i,a,o,s){return await new Promise(async n=>{let r=await w(e,async l=>{n(l),r.terminate()});r.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:o,walletId:a,userId:i},functionType:"GET_PRIVATE_KEY",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:s,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}var E=class{constructor(){this.localStorage=new v;this.sessionStorage=new T;this.secureStorage=null;this.isSyncStorage=!0;this.disableProviderModal=!1}getPrivateKey(i,a,o,s,n){return ne(i,a,o,s,n)}keygen(i,a,o,s,n,r={}){return J(i,a,o,s,!0,n,r)}refresh(i,a,o,s,n,r,l,g){return q(i,a,o,s,n,r,l,g)}preKeygen(i,a,o,s,n,r,l){return Y(i,o,s,n,r,!1,a,l)}signMessage(i,a,o,s,n,r,l,g){return ee(i,a,o,s,n,r,l,g)}signTransaction(i,a,o,s,n,r,l,g){return X(i,a,o,s,n,r,l,g)}sendTransaction(i,a,o,s,n,r,l,g){return Q(i,a,o,s,n,r,l,g)}signHash(i,a){throw new Error("not implemented")}ed25519Keygen(i,a,o,s){return z(i,a,o,s)}ed25519PreKeygen(i,a,o,s){return Z(i,a,o,s)}ed25519Sign(i,a,o,s,n,r){return te(i,a,o,s,n,r)}openPopup(i,a){if(!(typeof window>"u"))if(a){let{type:o}=a,s=550,n;switch(o){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 r=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+r,f=(u-n)/2+l,t=`toolbar=no, menubar=no, width=${s},
|
|
4
|
-
height=${n}, top=${f}, left=${d}`,c=window.open(
|
|
2
|
+
export*from"@getpara/core-sdk";import*as re from"@sentry/browser";import Ce,{Environment as se}from"@getpara/core-sdk";import{PopupType as k}from"@getpara/core-sdk";var v=class{constructor(){this.get=r=>typeof window<"u"&&localStorage.getItem(r)||null;this.set=(r,a)=>{typeof window<"u"&&localStorage.setItem(r,a)};this.removeItem=r=>{typeof window<"u"&&localStorage.removeItem(r)};this.clear=r=>{if(typeof window<"u")for(let a=0;a<localStorage.length;a++){let o=localStorage.key(a);o&&o.startsWith(r)&&(localStorage.removeItem(o),a--)}}}};var T=class{constructor(){this.get=r=>typeof window<"u"&&sessionStorage.getItem(r)||null;this.set=(r,a)=>{typeof window<"u"&&sessionStorage.setItem(r,a)};this.removeItem=r=>{typeof window<"u"&&sessionStorage.removeItem(r)};this.clear=r=>{if(typeof window<"u")for(let a=0;a<sessionStorage.length;a++){let o=sessionStorage.key(a);o&&o.startsWith(r)&&(sessionStorage.removeItem(o),a--)}}}};import{getPortalBaseURL as Se}from"@getpara/core-sdk";(()=>{let e=()=>{let o=new Error("not implemented");return o.code="ENOSYS",o};if(!globalThis.fs){let o="";globalThis.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(s,n){o+=a.decode(n);let i=o.lastIndexOf(`
|
|
3
|
+
`);return i!=-1&&(console.log(o.substring(0,i)),o=o.substring(i+1)),n.length},write(s,n,i,l,g,u){if(i!==0||l!==n.length||g!==null){u(e());return}let d=this.writeSync(s,n);u(null,d)},chmod(s,n,i){i(e())},chown(s,n,i,l){l(e())},close(s,n){n(e())},fchmod(s,n,i){i(e())},fchown(s,n,i,l){l(e())},fstat(s,n){n(e())},fsync(s,n){n(null)},ftruncate(s,n,i){i(e())},lchown(s,n,i,l){l(e())},link(s,n,i){i(e())},lstat(s,n){n(e())},mkdir(s,n,i){i(e())},open(s,n,i,l){l(e())},read(s,n,i,l,g,u){u(e())},readdir(s,n){n(e())},readlink(s,n){n(e())},rename(s,n,i){i(e())},rmdir(s,n){n(e())},stat(s,n){n(e())},symlink(s,n,i){i(e())},truncate(s,n,i){i(e())},unlink(s,n){n(e())},utimes(s,n,i,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 o=(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),m=this.mem.getInt32(t+4,!0);return c+m*4294967296},i=t=>{let c=this.mem.getFloat64(t,!0);if(c===0)return;if(!isNaN(c))return c;let m=this.mem.getUint32(t,!0);return this._values[m]},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),m=n(t+8);return new Uint8Array(this._inst.exports.mem.buffer,c,m)},u=t=>{let c=n(t+0),m=n(t+8),p=new Array(m);for(let y=0;y<m;y++)p[y]=i(c+y*8);return p},d=t=>{let c=n(t+0),m=n(t+8);return a.decode(new DataView(this._inst.exports.mem.buffer,c,m))},f=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),m=n(t+16),p=this.mem.getInt32(t+24,!0);fs.writeSync(c,new Uint8Array(this._inst.exports.mem.buffer,m,p))},"runtime.resetMemoryDataView":t=>{t>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{t>>>=0,o(t+8,(f+performance.now())*1e6)},"runtime.walltime":t=>{t>>>=0;let c=new Date().getTime();o(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 m=this._values[c];this._values[c]=null,this._ids.delete(m),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(i(t+8),d(t+16));t=this._inst.exports.getsp()>>>0,l(t+32,c)},"syscall/js.valueSet":t=>{t>>>=0,Reflect.set(i(t+8),d(t+16),i(t+32))},"syscall/js.valueDelete":t=>{t>>>=0,Reflect.deleteProperty(i(t+8),d(t+16))},"syscall/js.valueIndex":t=>{t>>>=0,l(t+24,Reflect.get(i(t+8),n(t+16)))},"syscall/js.valueSetIndex":t=>{t>>>=0,Reflect.set(i(t+8),n(t+16),i(t+24))},"syscall/js.valueCall":t=>{t>>>=0;try{let c=i(t+8),m=Reflect.get(c,d(t+16)),p=u(t+32),y=Reflect.apply(m,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=i(t+8),m=u(t+16),p=Reflect.apply(c,void 0,m);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=i(t+8),m=u(t+16),p=Reflect.construct(c,m);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,o(t+16,parseInt(i(t+8).length))},"syscall/js.valuePrepareString":t=>{t>>>=0;let c=r.encode(String(i(t+8)));l(t+16,c),o(t+24,c.length)},"syscall/js.valueLoadString":t=>{t>>>=0;let c=i(t+8);g(t+16).set(c)},"syscall/js.valueInstanceOf":t=>{t>>>=0,this.mem.setUint8(t+24,i(t+8)instanceof i(t+16)?1:0)},"syscall/js.copyBytesToGo":t=>{t>>>=0;let c=g(t+8),m=i(t+32);if(!(m instanceof Uint8Array||m instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let p=m.subarray(0,c.length);c.set(p),o(t+40,p.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{t>>>=0;let c=i(t+8),m=g(t+16);if(!(c instanceof Uint8Array||c instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let p=m.subarray(0,c.length);c.set(p),o(t+40,p.length),this.mem.setUint8(t+48,1)},debug:t=>{console.log(t)}}}}async run(o){if(!(o instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=o,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,globalThis,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[globalThis,5],[this,6]]),this._idPool=[],this.exited=!1;let s=4096,n=f=>{let t=s,c=r.encode(f+"\0");return new Uint8Array(this.mem.buffer,s,c.length).set(c),s+=c.length,s%8!==0&&(s+=8-s%8),t},i=this.argv.length,l=[];this.argv.forEach(f=>{l.push(n(f))}),l.push(0),Object.keys(this.env).sort().forEach(f=>{l.push(n(`${f}=${this.env[f]}`))}),l.push(0);let u=s;if(l.forEach(f=>{this.mem.setUint32(s,f,!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(i,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(o){let s=this;return function(){let n={id:o,this:this,args:arguments};return s._pendingEvent=n,s._resume(),n.result}}}})();import{getBaseMPCNetworkUrl as h,WalletScheme as P,WalletType as W}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,o){let{data:s}=await e.mpcComputationClient.post("/wallets",{userId:r,walletId:a,protocolId:o});return s}async function ue(e,r,a,o,s,n){let{data:i}=await e.mpcComputationClient.post(`/wallets/${a}/messages/sign`,{userId:r,protocolId:o,message:s,signer:n});return i}async function O(e,r,a,o,s,n,i){let{data:l}=await e.mpcComputationClient.post(`/wallets/${a}/transactions/send`,{userId:r,protocolId:o,transaction:s,signer:n,chainId:i});return l}async function U(e,r){let{walletId:a,protocolId:o}=await e.client.createWallet(r,{scheme:P.ED25519,type:W.SOLANA}),s=h(e.env,!e.disableWebSockets);return{signer:await new Promise((i,l)=>globalThis.ed25519CreateAccount(s,a,o,(g,u)=>{g&&l(g),i(u)})),walletId:a}}async function _(e,r,a){let{walletId:o,protocolId:s}=await e.client.createPregenWallet({pregenIdentifier:r,pregenIdentifierType:a,scheme:P.ED25519,type:W.SOLANA}),n=h(e.env,!e.disableWebSockets);return{signer:await new Promise((l,g)=>globalThis.ed25519CreateAccount(n,o,s,(u,d)=>{u&&g(u),l(d)})),walletId:o}}async function L(e,r,a,o,s){let{protocolId:n}=await e.client.preSignMessage(a,o,s,P.ED25519);return{signature:await new Promise((l,g)=>globalThis.ed25519Sign(r,n,s,(u,d)=>{u&&g(u),l(d)}))}}async function D(e,r,a,o){let{walletId:s,protocolId:n}=await e.client.createWallet(r,{useTwoSigners:!0,scheme:e.useDKLS?P.DKLS:P.CGGMP,type:a,cosmosPrefix:a===W.COSMOS?e.cosmosPrefix:void 0});if(e.offloadMPCComputationURL&&!e.useDKLS)return{signer:(await ge(e,r,s,n)).signer,walletId:s};let i=h(e.env,!e.disableWebSockets),l=e.useDKLS?K(s,"USER",e.disableWebSockets):ce(i,s,"USER"),g=e.useDKLS?globalThis.dklsCreateAccount:globalThis.createAccountV2;return{signer:await new Promise((d,f)=>g(l,i,n,o,()=>{},(t,c)=>{t&&f(t),d(c)})),walletId:s}}async function M(e,r,a,o,s,n){let{walletId:i,protocolId:l}=await e.client.createPregenWallet({pregenIdentifier:a,pregenIdentifierType:o,type:s,cosmosPrefix:s===W.COSMOS?e.cosmosPrefix:void 0}),g=h(e.env,!e.disableWebSockets),u=K(i,"USER",e.disableWebSockets);return{signer:await new Promise((f,t)=>globalThis.dklsCreateAccount(u,g,l,n,()=>{},(c,m)=>{c&&t(c),f(m)})),walletId:i}}async function N(e,r,a,o,s,n){let{protocolId:i,pendingTransactionId:l}=await e.client.preSignMessage(o,a,s,null,n);if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return ue(e,o,a,i,s,r);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSignMessage:globalThis.signMessage,d=JSON.parse(r);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d),new Promise((f,t)=>u(r,g,s,i,(c,m)=>{c&&t(c),f({signature:m})}))}async function B(e,r,a,o,s,n){let{data:{protocolId:i,pendingTransactionId:l}}=await e.client.signTransaction(o,a,{transaction:s,chainId:n});if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return O(e,o,a,i,s,r,n);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSendTransaction:globalThis.sendTransaction,d=JSON.parse(r);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d),new Promise((f,t)=>u(r,g,s,n,i,(c,m)=>{c&&t(c),f({signature:m})}))}async function x(e,r,a,o,s,n){let{data:{protocolId:i,pendingTransactionId:l}}=await e.client.sendTransaction(o,a,{transaction:s,chainId:n});if(l)return{pendingTransactionId:l};if(e.offloadMPCComputationURL&&!e.useDKLS)return O(e,o,a,i,s,r,n);let g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsSendTransaction:globalThis.sendTransaction,d=JSON.parse(r);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d),new Promise((f,t)=>u(r,g,s,n,i,(c,m)=>{c&&t(c),f({signature:m})}))}async function j(e,r,a,o,s,n,i){let{data:{protocolId:l}}=await e.client.refreshKeys(o,a,s,n,i),g=h(e.env,!e.disableWebSockets),u=e.useDKLS?globalThis.dklsRefresh:globalThis.refresh,d=JSON.parse(r);return!d.disableWebSockets!=!e.disableWebSockets&&(d.disableWebSockets=e.disableWebSockets),r=JSON.stringify(d),new Promise((f,t)=>u(r,g,l,(c,m)=>{c&&t(c),f({protocolId:l,signer:m})}))}async function G(e,r,a,o){let s=await e.client.getParaShare(o,a);return s?new Promise((n,i)=>globalThis.getPrivateKey(r,s,(l,g)=>{l&&i(l),n(g)})):""}import{getPortalBaseURL as me,initClient as fe,mpcComputationClient as pe,paraVersion as we,WalletType as H}from"@getpara/core-sdk";async function ye(e,r){if(typeof self>"u")return;let a=new self.Go,o=r;if(!o){if(process.env.DISABLE_WASM_FETCH==="true")throw new Error("fetching wasm file is disabled");o=await(await fetch(`${me(e)}/static/js/main.wasm`,{mode:"cors"})).arrayBuffer()}let s=await WebAssembly.instantiate(o,a.importObject);a.run(s.instance)}async function he(e,r){let{functionType:a,params:o,returnObject:s}=r;switch(a){case"KEYGEN":{let{userId:n,secretKey:i,type:l=H.EVM}=o;return await D(e,n,l,i)}case"SIGN_TRANSACTION":{let{share:n,walletId:i,userId:l,tx:g,chainId:u}=o;return B(e,n,i,l,g,u)}case"SEND_TRANSACTION":{let{share:n,walletId:i,userId:l,tx:g,chainId:u}=o;return x(e,n,i,l,g,u)}case"SIGN_MESSAGE":{let{share:n,walletId:i,userId:l,message:g,cosmosSignDoc:u}=o;return N(e,n,i,l,g,u)}case"REFRESH":{let{share:n,walletId:i,userId:l,oldPartnerId:g,newPartnerId:u,keyShareProtocolId:d}=o,{protocolId:f,signer:t}=await j(e,n,i,l,g,u,d);return s?{protocolId:f,signer:t}:t}case"PREKEYGEN":{let{email:n,partnerId:i,secretKey:l,type:g=H.EVM}=o,{pregenIdentifier:u,pregenIdentifierType:d}=o;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(u=n,d="EMAIL"),await M(e,i,u,d,g,l)}case"GET_PRIVATE_KEY":{let{share:n,walletId:i,userId:l}=o;return await G(e,n,i,l)}case"ED25519_KEYGEN":{let{userId:n}=o;return U(e,n)}case"ED25519_SIGN":{let{share:n,walletId:i,userId:l,base64Bytes:g}=o;return L(e,n,l,i,g)}case"ED25519_PREKEYGEN":{let{email:n}=o,{pregenIdentifier:i,pregenIdentifierType:l}=o;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(i=n,l="EMAIL"),_(e,i,l)}default:throw new Error(`functionType: ${a} not supported`)}}async function V(e,r,a){let{env:o,apiKey:s,cosmosPrefix:n="cosmos",offloadMPCComputationURL:i,disableWorkers:l,sessionCookie:g,useDKLS:u,disableWebSockets:d,wasmOverride:f}=e.data;if(!o)return!0;let t={env:o,apiKey:s,cosmosPrefix:n,client:fe({env:o,version:we,apiKey:s,useFetchAdapter:a,retrieveSessionCookie:()=>g}),offloadMPCComputationURL:i,mpcComputationClient:i?pe.initClient(i,!!l):void 0,useDKLS:u,disableWebSockets:!!d,wasmOverride:f};(!t.offloadMPCComputationURL||t.useDKLS)&&await ye(t,f);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 V({data:n},i=>a({data:i}),e.disableWorkers)})()},terminate:()=>{}};let o;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"}),i=URL.createObjectURL(n);o=new Worker(i)}return o.onmessage=a,o}import{distributeNewShare as be,waitUntilTrue as C}from"@getpara/core-sdk";async function F(e,r,a){return!!(await e.client.getWallets(r)).data.wallets.find(n=>n.id===a).address}async function Pe(e,r,a,o,s){let{isDone:n}=await e.client.isRefreshDone(r,a,o,s);return n}async function $(e,r,a,o){return!!(await e.client.getPregenWallets({[a]:[r]})).wallets.find(i=>i.id===o).address}function J(e,r,a,o,s=!1,n,i={}){return new Promise(async l=>{let g=await w(e,async u=>{if(await C(async()=>F(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:i});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:o,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,o,s,n=!1,i,l){return new Promise(async g=>{let u=await w(e,async t=>{await C(async()=>$(e,r,a,t.walletId),15e3,1e3),g({signer:t.signer,walletId:t.walletId,recoveryShare:null}),u.terminate()}),f={pregenIdentifier:r,pregenIdentifierType:a,type:o,secretKey:s,partnerId:i,email:void 0};a==="EMAIL"&&(f.email=r),u.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:f,functionType:"PREKEYGEN",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:l,useDKLS:e.useDKLS,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}function q(e,r,a,o,s,n,i,l){return new Promise(async g=>{let u=await w(e,async d=>{if(!await C(async()=>Pe(e,a,o,i),15e3,1e3))throw new Error("refresh failed");let{protocolId:f,signer:t}=d;g({signer:t,protocolId:f}),u.terminate()});u.postMessage({env:e.env,apiKey:e.apiKey,params:{userId:a,walletId:o,share:s,oldPartnerId:n,newPartnerId:i,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,o={}){return new Promise(async s=>{let n=await w(e,async i=>{await C(async()=>F(e,r,i.walletId),15e3,1e3),s({signer:i.signer,walletId:i.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,o){return new Promise(async s=>{let n=await w(e,async g=>{await C(async()=>$(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:o,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function X(e,r,a,o,s,n,i,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:o,walletId:a,userId:r,tx:s,chainId:n},functionType:"SIGN_TRANSACTION",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:i,useDKLS:l,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function Q(e,r,a,o,s,n,i,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:o,walletId:a,userId:r,tx:s,chainId:n},functionType:"SEND_TRANSACTION",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:i,useDKLS:l,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function ee(e,r,a,o,s,n,i,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:o,walletId:a,userId:r,message:s,cosmosSignDoc:l},functionType:"SIGN_MESSAGE",offloadMPCComputationURL:e.offloadMPCComputationURL,disableWorkers:e.disableWorkers,sessionCookie:n,useDKLS:i,disableWebSockets:e.disableWebSockets,wasmOverride:e.wasmOverride})})}async function te(e,r,a,o,s,n){return await new Promise(async i=>{let l=await w(e,async g=>{i(g),l.terminate()});l.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:o,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,o,s){return await new Promise(async n=>{let i=await w(e,async l=>{n(l),i.terminate()});i.postMessage({env:e.env,apiKey:e.apiKey,cosmosPrefix:e.cosmosPrefix,params:{share:o,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 E=class{constructor(){this.localStorage=new v;this.sessionStorage=new T;this.secureStorage=null;this.isSyncStorage=!0;this.disableProviderModal=!1}getPrivateKey(r,a,o,s,n){return ne(r,a,o,s,n)}keygen(r,a,o,s,n,i={}){return J(r,a,o,s,!0,n,i)}refresh(r,a,o,s,n,i,l,g){return q(r,a,o,s,n,i,l,g)}preKeygen(r,a,o,s,n,i,l){return Y(r,o,s,n,i,!1,a,l)}signMessage(r,a,o,s,n,i,l,g){return ee(r,a,o,s,n,i,l,g)}signTransaction(r,a,o,s,n,i,l,g){return X(r,a,o,s,n,i,l,g)}sendTransaction(r,a,o,s,n,i,l,g){return Q(r,a,o,s,n,i,l,g)}signHash(r,a){throw new Error("not implemented")}ed25519Keygen(r,a,o,s){return z(r,a,o,s)}ed25519PreKeygen(r,a,o,s){return Z(r,a,o,s)}ed25519Sign(r,a,o,s,n,i){return te(r,a,o,s,n,i)}openPopup(r,a){if(!(typeof window>"u"))if(a){let{type:o}=a,s=550,n;switch(o){case k.LOGIN_PASSKEY:{n=798;break}case k.CREATE_PASSKEY:{n=464;break}case k.SIGN_MESSAGE_REVIEW:{n=585;break}case k.SIGN_TRANSACTION_REVIEW:{n=750;break}case k.OAUTH:default:{n=768;break}}let i=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+i,f=(u-n)/2+l,t=`toolbar=no, menubar=no, width=${s},
|
|
4
|
+
height=${n}, top=${f}, left=${d}`,c=window.open(r,o.toString(),t);return c||setTimeout(()=>{c=window.open(r,"_blank")},0),c}else{let o=window.open(r,"popup","popup=true,width=400,height=500");return o||setTimeout(()=>{window.open(r,"_blank")},0),o}}};var I=class extends Ce{constructor(r,a,o){super(r,a,o),r!==se.PROD&&r!==se.DEV&&re.init({environment:r.toLowerCase(),dsn:"https://38f27d4836da617ab9e95cf66b9611d9@o4504568036720640.ingest.us.sentry.io/4508850812944384"})}getPlatformUtils(){return new E}};import Dt from"@getpara/core-sdk";import{Environment as jt}from"@getpara/core-sdk";import b from"base64url";import*as A from"cbor-web";import S from"node-forge";import{getPortalDomain as oe}from"@getpara/core-sdk";var ie=-7,ae=-257;function R(e){if(e instanceof ArrayBuffer)return b.encode(e);if(e instanceof Array)return e.map(R);if(e instanceof Object){let r={};for(let a in e)r[a]=R(e[a]);return r}else return e}function ke(e){let r=e.slice(0,32);e=e.slice(32);let a=e.slice(0,1);e=e.slice(1);let o=a[0],s=e.slice(0,4);e=e.slice(4);let n=s.readUInt32BE(0),i=e.slice(0,16);e=e.slice(16);let l=e.slice(0,2);e=e.slice(2);let g=l.readUInt16BE(0),u=e.slice(0,g);return e=e.slice(g),{rpIdHash:r,flagsBuf:a,flags:o,counter:n,counterBuf:s,aaguid:i,credID:u,COSEPublicKey:e}}function ve(e){let r=b.toBuffer(e);return A.decodeAllSync(r)[0]}function Te(e){let r=A.decodeAllSync(e)[0],a=Buffer.from([4]),o=r.get(-2),s=r.get(-3);return Buffer.concat([a,o,s])}function We(e){let r=A.decodeAllSync(e)[0],a=r.get(-1),o=r.get(-2),s=S.util.createBuffer(a.toString("binary")),n=S.util.createBuffer(o.toString("binary")),i=S.pki.setRsaPublicKey(new S.jsbn.BigInteger(s.toHex(),16),new S.jsbn.BigInteger(n.toHex(),16));return Buffer.from(S.pki.publicKeyToPem(i),"utf-8")}function Ee(e,r){let a=ve(e.response.attestationObject),{COSEPublicKey:o,aaguid:s}=ke(a.authData);return r===ae?{cosePublicKey:b.encode(We(o)),clientDataJSON:e.response.clientDataJSON,aaguid:s.toString("hex")}:{cosePublicKey:b.encode(Te(o)),clientDataJSON:e.response.clientDataJSON,aaguid:s.toString("hex")}}function Ie(){let e=new Uint8Array(32);return window.crypto.getRandomValues(e),e}async function Re(e,r,a,o){if(typeof navigator>"u")return;let s=Ie(),n={publicKey:{authenticatorSelection:{authenticatorAttachment:"platform",requireResidentKey:!0,residentKey:"required",userVerification:"required"},rp:{id:oe(e,o),name:"Para"},user:{id:s,name:a,displayName:a},pubKeyCredParams:[{type:"public-key",alg:ie},{type:"public-key",alg:ae}],attestation:"direct",timeout:6e4,challenge:Buffer.from(r,"utf-8")}},i=await navigator.credentials.create(n),l=i.response.getPublicKeyAlgorithm?i.response.getPublicKeyAlgorithm():ie,g=b.encode(Buffer.from(s));return{creds:R(i),userHandle:g,algorithm:l}}async function Ae(e,r,a,o){let s={publicKey:{timeout:6e4,challenge:Buffer.from(r,"base64"),allowCredentials:a.map(i=>({id:b.toBuffer(i),type:"public-key"})),userVerification:"required",rpId:oe(e,o)}},n=await navigator.credentials.get(s);return R(n)}var Ke=/^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/,Oe=e=>{let r=e.match(Ke);return r?`${r[1]}\u2026${r[2]}`:e};function Ue(){return typeof navigator<"u"&&/android/i.test(navigator.userAgent)}function _e(){return typeof navigator<"u"&&/iPhone|iPod/.test(navigator.userAgent)}function Le(){return typeof navigator<"u"&&(/iPad/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1)}function Rt(){return typeof navigator<"u"&&/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(navigator.userAgent)}function le(){return _e()||Le()}function De(){return Ue()||le()}function Me(){return typeof navigator<"u"&&/AppleWebKit/i.test(navigator.userAgent)&&!/CriOS/i.test(navigator.userAgent)&&!/Chrome/i.test(navigator.userAgent)}function At(){let e=typeof navigator<"u"&&!navigator.standalone;return typeof navigator<"u"&&le()&&!e&&!/safari/i.test(navigator.userAgent.toLowerCase())}function Kt(){return De()&&Me()}function Ot(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}var Mt=I;export{jt as Environment,Dt as ParaCore,I as ParaWeb,Re as createCredential,Mt as default,Ae as generateSignature,Ue as isAndroid,le as isIOS,At as isIOSWebview,Le as isLargeIOS,De as isMobile,Kt as isMobileSafari,Me as isSafari,_e as isSmallIOS,Rt as isTablet,Ot as isTelegram,Ee as parseCredentialCreationRes,Oe as truncateEthAddress};
|
package/dist/index.js.br
CHANGED
|
Binary file
|
package/dist/index.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/web-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"wasm_exec.js"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@getpara/core-sdk": "1.
|
|
12
|
-
"@getpara/user-management-client": "1.
|
|
11
|
+
"@getpara/core-sdk": "1.4.0",
|
|
12
|
+
"@getpara/user-management-client": "1.4.0",
|
|
13
|
+
"@sentry/browser": "^9.1.0",
|
|
13
14
|
"assert": "^2.1.0",
|
|
14
15
|
"base64url": "3.0.1",
|
|
15
16
|
"buffer": "6.0.3",
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"dist",
|
|
38
39
|
"package.json"
|
|
39
40
|
],
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "b7610939d5a0121729be24c38d418eb45760258a"
|
|
41
42
|
}
|