magic-sdk 28.0.5-canary.747.9406920229.0 → 28.0.5-canary.747.9407043010.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/magic.js +1 -1
- package/package.json +4 -4
package/dist/magic.js
CHANGED
@@ -8,5 +8,5 @@
|
|
8
8
|
- Extension \`${r.name}\` supports version(s) \`${n}\``:n||(t+=`
|
9
9
|
- Extension \`${r.name}\` does not support ${ee.platform} environments.`)}),new et(Ke.IncompatibleExtensions,t)}function _d(e){let t=r=>{let n=r+1,o=n%10,i=n%100;return o===1&&i!==11?`${n}st`:o===2&&i!==12?`${n}nd`:o===3&&i!==13?`${n}rd`:`${n}th`};return new et(Ke.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
10
10
|
Expected: \`${e.expected}\`
|
11
|
-
Received: \`${e.received}\``)}function As(){return new Et(Ye.DuplicateIframe,"Duplicate iframes found.")}function Sd(){return new Et(Ye.SyncWeb3Method,"Non-async web3 methods are deprecated in web3 > 1.0 and are not supported by the Magic web3 provider. Please use an async method instead.")}function Id(){return new Et(Ye.ReactNativeEndpointConfiguration,`CUSTOM DOMAINS ARE NOT SUPPORTED WHEN USING MAGIC SDK WITH REACT NATIVE! The \`endpoint\` parameter SHOULD NOT be provided. The Magic \`<iframe>\` is automatically wrapped by a WebView pointed at \`${ee.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function xr(e){let{method:t,removalVersions:r,useInstead:n}=e,o=r[ee.sdkName],i=n?` Use \`${n}\` instead.`:"",a=`\`${t}\` will be removed from \`${ee.sdkName}\` in version \`${o}\`.${i}`;return new Et(Ye.DeprecationNotice,a)}function*wd(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var xd=wd();function Ls(){return xd.next().value}var Ns=Symbol("Payload pre-processed by Magic SDK");function Ms(e){return Object.defineProperty(e,Ns,{value:!0,enumerable:!1}),e}function Td(e){return!!e[Ns]}function wn(e){var t,r,n;return Td(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Ls(),e.method=(r=e.method)!=null?r:"noop",e.params=(n=e.params)!=null?n:[],Ms(e)),e}function W(e,t=[]){return Ms({params:t,method:e,jsonrpc:"2.0",id:Ls()})}var $o=class{constructor(e){e instanceof $o?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):md(e)?(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=e.result,this._error=e.error):(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=void 0,this._error=void 0)}applyError(e){return this._error=e,this}applyResult(e){return this._result=e,this}get hasError(){return typeof this._error!="undefined"&&this._error!==null}get hasResult(){return typeof this._result!="undefined"}get payload(){return{jsonrpc:this._jsonrpc,id:this._id,result:this._result,error:this._error}}},Rd=Sf(If()),Od=class extends Rd.default{};function ks(){let e=new Od;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...n)=>(e[t].apply(e,n),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Ps=Symbol("isPromiEvent");function Fo(e){return!!e[Ps]}function Or(e){let t=Ds(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:n}=ks(),o=Symbol("Promise.then"),i=Symbol("Promise.catch"),a=Symbol("Promise.finally"),c=(p,g)=>(...y)=>{let I=g[p].apply(g,y);return f(I)},f=p=>Object.assign(p,{[Ps]:!0,[o]:p[o]||p.then,[i]:p[i]||p.catch,[a]:p[a]||p.finally,then:c(o,p),catch:c(i,p),finally:c(a,p),on:n("on",p),once:n("once",p),addListener:n("addListener",p),off:n("off",p),removeListener:n("removeListener",p),removeAllListeners:n("removeAllListeners",p),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),l=f(t.then(p=>(l.emit("done",p),l.emit("settled"),p),p=>{throw l.emit("error",p),l.emit("settled"),p}));return l}function Ds(e){return new Promise((t,r)=>{let n=e(t,r);Promise.resolve(n).catch(r)})}var bt=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(lt.MAGIC_HANDLE_REQUEST,wn(e)),r=Or((o,i)=>{t.then(a=>{if(n(),a.hasError)i(new Jt(a.payload.error));else if(a.hasResult)o(a.payload.result);else throw yd()}).catch(a=>{n(),i(a)})}),n=this.overlay.on(Be.MAGIC_HANDLE_EVENT,o=>{var i;let{response:a}=o.data;if(a.id===e.id&&((i=a.result)==null?void 0:i.event)){let{event:c,params:f=[]}=a.result;r.emit(c,...f)}});return r}createIntermediaryEvent(e,t){return r=>{let n=W(M.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(n)}}};function Cd(e,t){let[r]=e.split(".").map(Number);return r>=t}var Tr={"magic-sdk":"v18.0.0","@magic-sdk/react-native":"v14.0.0","@magic-sdk/react-native-bare":"v19.0.0","@magic-sdk/react-native-expo":"v19.0.0"},Ad=class extends bt{loginWithMagicLink(e){let t=ee.sdkName==="@magic-sdk/react-native"||ee.sdkName==="@magic-sdk/react-native-bare"||ee.sdkName==="@magic-sdk/react-native-expo";if(t&&Cd(ee.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&xr({method:"auth.loginWithMagicLink()",removalVersions:Tr,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:n=!0,redirectURI:o,overrides:i}=e,a=W(this.sdk.testMode?M.LoginWithMagicLinkTestMode:M.LoginWithMagicLink,[{email:r,showUI:n,redirectURI:o,overrides:i}]);return this.request(a)}loginWithSMS(e){let{phoneNumber:t}=e,r=W(this.sdk.testMode?M.LoginWithSmsTestMode:M.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:n,overrides:o}=e,i=W(this.sdk.testMode?M.LoginWithEmailOTPTestMode:M.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:n,overrides:o}]),a=this.request(i);return!n&&a&&a.on(or.Retry,()=>{this.createIntermediaryEvent(or.Retry,i.id)()}),!r&&a&&(a.on(ft.VerifyEmailOtp,c=>{this.createIntermediaryEvent(ft.VerifyEmailOtp,i.id)(c)}),a.on(ft.Cancel,()=>{this.createIntermediaryEvent(ft.Cancel,i.id)()})),a}loginWithCredential(e){let t=e!=null?e:"";if(!e&&ee.platform==="web"){t=window.location.search;let n=window.location.origin+window.location.pathname;window.history.replaceState(null,"",n)}let r=W(this.sdk.testMode?M.LoginWithCredentialTestMode:M.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(M.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,n=W(this.sdk.testMode?M.UpdateEmailTestMode:M.UpdateEmail,[{email:t,showUI:r}]),o=this.request(n);return r||(o.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.Retry,n.id)()}),o.on(qe.Cancel,()=>{this.createIntermediaryEvent(qe.Cancel,n.id)()}),o.on(qe.VerifyEmailOtp,i=>{this.createIntermediaryEvent(qe.VerifyEmailOtp,n.id)(i)}),o.on(Ve.RetryWithNewEmail,i=>{this.createIntermediaryEvent(Ve.RetryWithNewEmail,n.id)(i)}),o.on(Ve.Cancel,()=>{this.createIntermediaryEvent(Ve.Cancel,n.id)()}),o.on(Ve.VerifyEmailOtp,i=>{this.createIntermediaryEvent(Ve.VerifyEmailOtp,n.id)(i)})),o}},Us={};bf(Us,{clear:()=>Ld,getItem:()=>ge,iterate:()=>Bs,key:()=>Md,keys:()=>kd,length:()=>Nd,removeItem:()=>Xt,setItem:()=>He});var En;function st(e){return(...t)=>ne(this,null,function*(){return En||(En=yield ee.configureStorage()),yield En.ready(),En[e](...t)})}var ge=st("getItem"),He=st("setItem"),Xt=st("removeItem"),Ld=st("clear"),Nd=st("length"),Md=st("key"),kd=st("keys"),Bs=st("iterate");function Pd(){let e=window.crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&191|128;let t="";return t+=e[0].toString(16),t+=e[1].toString(16),t+=e[2].toString(16),t+=e[3].toString(16),t+="-",t+=e[4].toString(16),t+=e[5].toString(16),t+="-",t+=e[6].toString(16),t+=e[7].toString(16),t+="-",t+=e[8].toString(16),t+=e[9].toString(16),t+="-",t+=e[10].toString(16),t+=e[11].toString(16),t+=e[12].toString(16),t+=e[13].toString(16),t+=e[14].toString(16),t+=e[15].toString(16),t}var $s="STORE_KEY_PRIVATE_KEY",ko="STORE_KEY_PUBLIC_JWK",Fs="ECDSA",Dd="P-256",Ud={name:Fs,namedCurve:Dd};function Rn(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Bd(){return ne(this,null,function*(){let e=yield $d();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield ge($s);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let n={iat:Math.floor(new Date().getTime()/1e3),jti:Pd()},o={typ:"dpop+jwt",alg:"ES256",jwk:e},i={protected:_s(JSON.stringify(o)),claims:_s(JSON.stringify(n))},a=Gd(`${i.protected}.${i.claims}`),c={name:Fs,hash:{name:"SHA-256"}},f=Wd(new Uint8Array(yield t.sign(c,r,a)));return`${i.protected}.${i.claims}.${f}`})}function $d(){return ne(this,null,function*(){if(!Rn()){console.info("webcrypto is not supported");return}return(yield ge(ko))||(yield Fd()),ge(ko)})}function Fd(){return ne(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Ud,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield He($s,t.privateKey),yield He(ko,r)})}function _s(e){return Gs(jd(e))}function Gd(e){return new TextEncoder().encode(e)}function Gs(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function jd(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Wd(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),Gs(t)}var Go="ds",jo="ek",Wo="iv",Ho="AES-GCM",Hd=256;function Ko(){return ne(this,null,function*(){let e=[];yield Bs((t,r,n)=>{r.startsWith(`${Go}_`)&&e.push(r)});for(let t of e)yield Xt(t)})}function js(e){let t="",r=new Uint8Array(e),n=r.byteLength;for(let o=0;o<n;o++)t+=String.fromCharCode(r[o]);return window.btoa(t)}function Ws(e){let t=window.atob(e),r=t.length,n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t.charCodeAt(o);return n.buffer}function Kd(){return ne(this,null,function*(){if(!Rn()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield ge(Wo))||e.getRandomValues(new Uint8Array(12))})}function Yd(){return ne(this,null,function*(){if(!Rn()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield ge(jo))||(yield e.generateKey({name:Ho,length:Hd},!1,["encrypt","decrypt"]))})}function qd(e,t){return ne(this,null,function*(){let r=yield Kd(),n=yield Yd();if(!r||!n||!e)return;let o=Ws(e),{subtle:i}=window.crypto,a=yield i.encrypt({name:Ho,iv:r},n,o),c=js(a);yield He(`${Go}_${t}`,c),yield He(jo,n),yield He(Wo,r)})}function Vd(e){return ne(this,null,function*(){let t=yield ge(`${Go}_${e}`),r=yield ge(Wo),n=yield ge(jo);if(!r||!t||!n||!Rn())return;let{subtle:o}=window.crypto,i=yield o.decrypt({name:Ho,iv:r},n,Ws(t));return js(i)})}function Cr(e,t){return t?new URL(e,t):new URL(e)}var zd=class extends bt{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=W(this.sdk.testMode?M.GetIdTokenTestMode:M.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?M.GenerateIdTokenTestMode:M.GenerateIdToken,[e]);return this.request(t)}getInfo(){return ne(this,null,function*(){let e=yield ge(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){return Or((e,t)=>ne(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield ge(this.localForageIsLoggedInKey))==="true",r&&e(!0));let n=W(this.sdk.testMode?M.IsLoggedInTestMode:M.IsLoggedIn),o=yield this.request(n);this.sdk.useStorageCache&&(o?He(this.localForageIsLoggedInKey,!0):Xt(this.localForageIsLoggedInKey),r&&!o&&this.emitUserLoggedOut(!0)),e(o)}catch(r){t(r)}}))}logout(){return Xt(this.localForageKey),Xt(this.localForageIsLoggedInKey),Ko(),Or((e,t)=>ne(this,null,function*(){try{let r=W(this.sdk.testMode?M.LogoutTestMode:M.Logout),n=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(n),e(n)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?M.UserSettingsTestMode:M.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?M.RecoverAccountTestMode:M.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=W(M.RevealPK);return this.request(e)}getMetadata(){xr({method:"user.getMetadata()",removalVersions:Tr,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?M.GetMetadataTestMode:M.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Xd=class extends bt{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Or((t,r)=>ne(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(Se.MetaMask))){let c=yield this.autoConnectIfWalletBrowser(Se.MetaMask);t(c);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(Se.CoinbaseWallet))){let c=yield this.autoConnectIfWalletBrowser(Se.CoinbaseWallet);t(c);return}let n=this.getUserEnv(),o=W(M.Login,[n]),i=this.request(o);i.on(xt.WalletSelected,c=>this.handleWalletSelected(Do(Po({},c),{payloadId:o.id}))),i.on("id-token-created",c=>{e.emit("id-token-created",c)});let a=yield i;a.error&&r(a),t(a)}catch(n){r(n)}}));return e}showUI(){return this.request(W(M.ShowUI))}showAddress(){return this.request(W(M.ShowAddress))}showSendTokensUI(){return this.request(W(M.ShowSendTokensUI))}showOnRamp(){return this.request(W(M.ShowOnRamp))}showNFTs(){return this.request(W(M.ShowNFTs))}showBalances(){return this.request(W(M.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(M.SendGaslessTransaction,[e,t]))}getInfo(){return ne(this,null,function*(){xr({method:"wallet.getInfo()",removalVersions:Tr,useInstead:"user.getInfo()"}).log();let e=yield ge(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){xr({method:"wallet.disconnect()",removalVersions:Tr,useInstead:"user.logout()"}).log(),Xt(this.localForageKey),Ko();let e=W(M.Disconnect);return this.request(e)}requestUserInfoWithUI(e){xr({method:"wallet.requestUserInfoWithUI()",removalVersions:Tr,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return ne(this,null,function*(){switch(yield ge(this.localForageKey)){case Se.MetaMask:return this.getMetaMaskProvider();case Se.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isMetaMask)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(n=>n==null?void 0:n.isMetaMask))}isMetaMaskBrowser(){return this.isMobile()&&this.isMetaMaskInstalled()}getMetaMaskProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isMetaMask))||window.ethereum}connectToMetaMask(){if(this.isMobile()&&!this.isMetaMaskInstalled()){let e=`https://metamask.app.link/dapp/${window.location.href.replace(/(^\w+:|^)\/\//,"")}`;window.location.href=e}return this.getMetaMaskProvider().request({method:"eth_requestAccounts"})}isCoinbaseWalletInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isCoinbaseWallet)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(n=>n==null?void 0:n.isCoinbaseWallet))}isCoinbaseWalletBrowser(){var e;return!!((e=window.ethereum)!=null&&e.isCoinbaseBrowser)}getCoinbaseProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let e=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=e}return this.getCoinbaseProvider().request({method:"eth_requestAccounts"})}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)}getUserEnv(){return{env:{isMetaMaskInstalled:this.isMetaMaskInstalled(),isCoinbaseWalletInstalled:this.isCoinbaseWalletInstalled()}}}connectToThirdPartyWallet(e){switch(e){case Se.MetaMask:return this.connectToMetaMask();case Se.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=W("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return ne(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield He(this.localForageKey,e.wallet),this.createIntermediaryEvent(xt.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(xt.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return ne(this,null,function*(){let t;e===Se.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===Se.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield He(this.localForageKey,e);let r=W(M.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:bn,createChainingEmitterMethod:Vt}=ks(),Jd=class extends bt{constructor(){super(...arguments),this.isMagic=!0,this.on=Vt("on",this),this.once=Vt("once",this),this.addListener=Vt("addListener",this),this.off=Vt("off",this),this.removeListener=Vt("removeListener",this),this.removeAllListeners=Vt("removeAllListeners",this),this.emit=bn("emit"),this.eventNames=bn("eventNames"),this.listeners=bn("listeners"),this.listenerCount=bn("listenerCount")}sendAsync(e,t){if(!t)throw _d({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(lt.MAGIC_HANDLE_REQUEST,e.map(r=>{let n=wn(r);return this.prefixPayloadMethodForTestMode(n),n})).then(r=>{t(null,r.map(n=>Do(Po({},n.payload),{error:n.hasError?new Jt(n.payload.error):null})))});else{let r=wn(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(lt.MAGIC_HANDLE_REQUEST,r).then(n=>{t(n.hasError?new Jt(n.payload.error):null,n.payload)})}}send(e,t){if(typeof e=="string"){let n=W(e,Array.isArray(t)?t:[]);return this.request(n)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=Sd();return r.log(),new $o(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(M.Login);return this.request(e)}request(e){return this.prefixPayloadMethodForTestMode(e),super.request(e)}prefixPayloadMethodForTestMode(e){let t="testMode/eth/";this.sdk.testMode&&(e.method=`${t}${e.method}`)}},Ss=["request","overlay","sdk"];function Zd(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==bt.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var Hs=class extends bt{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Or,isPromiEvent:Fo,encodeJSON:Rs,decodeJSON:dd,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:wn,storage:Us};let e=[this,...Zd(this)];Ss.forEach(t=>{let r=e.map(a=>Object.getOwnPropertyDescriptor(a,t)),n=r.findIndex(a=>!!a),o=n>0,i=r[n];i&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:i,isPrototypeField:o}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Ed(t)}}))})}init(e){this.__is_initialized__||(Ss.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:n}=this.__sdk_access_field_descriptors__.get(t);n?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:n}=e,o=n?` Use \`${n}\` instead.`:"",i=`\`${t}\` will be removed from this Extension in version \`${r}\`.${o}`;return new In(this,"DEPRECATION_NOTICE",i)}createWarning(e,t){return new In(this,e,t)}createError(e,t,r){return new Tn(this,e,t,r)}},Qd=class extends Hs{},yt=class extends Hs{};yt.Internal=Qd,yt.Anonymous="anonymous extension";var ep=class extends bt{purchase(e){let t=W(M.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(M.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(M.NFTTransfer,[e]);return this.request(t)}};function Is(e){return e.compat&&e.compat[ee.sdkName]!=null?typeof e.compat[ee.sdkName]=="string"?nd(sd(ee.version),e.compat[ee.sdkName]):!!e.compat[ee.sdkName]:!0}function tp(e,t,r){return!t&&!r?`${e}_eth_mainnet`:r?`${e}_${JSON.stringify(r)}`:t?typeof t=="string"?`${e}_eth_${t}`:`${e}_${t.rpcUrl}_${t.chainId}_${t.chainType}`:`${e}_unknown`}function rp(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],n={},o=[];if(Array.isArray(r)?r.forEach(i=>{Is(i)?(i.init(this),(i.name||i.name!==yt.Anonymous)&&(this[i.name]=i),i instanceof yt.Internal&&(Sn(i.config)||(n[i.name]=i.config))):o.push(i)}):Object.keys(r).forEach(i=>{if(Is(r[i])){r[i].init(this);let a=r[i];this[i]=a,a instanceof yt.Internal&&(Sn(a.config)||(n[r[i].name]=a.config))}else o.push(r[i])}),o.length)throw bd(o);return n}var _n=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw gd();ee.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Id().log();let{defaultEndpoint:n,version:o}=ee;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=Cr((r=t==null?void 0:t.endpoint)!=null?r:n).origin,this.externalLogger=t==null?void 0:t.externalLogger,this.auth=new Ad(this),this.user=new zd(this),this.wallet=new Xd(this),this.nft=new ep(this),this.rpcProvider=new Jd(this);let i=rp.call(this,t);this.parameters=Rs(Do(Po({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:Cr(this.endpoint).host,sdk:vd[ee.sdkName],version:o,ext:Sn(i)?void 0:i,locale:(t==null?void 0:t.locale)||"en_US"},ee.bundleId?{bundleId:ee.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=tp(this.apiKey,t==null?void 0:t.network,Sn(i)?void 0:i),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!_n.__overlays__.has(this.parameters)){let e=new ee.ViewController(this.endpoint,this.parameters,this.networkHash,this.externalLogger);e.init(),_n.__overlays__.set(this.parameters,e)}return _n.__overlays__.get(this.parameters)}preload(){return ne(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Yo=_n;Yo.__overlays__=new Map;var ws=(e,t={})=>{_r.logger.log(e,{data:t})};_r.init({clientToken:"pubabac4d3c893a1ad69023911f42fce019",service:"movement"});function np(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function op(e,t){var r;let n=(r=t.data.response)==null?void 0:r.id,o=np(e,n);if(n&&o){let i=new $o(o).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:n,response:i}}return{}}function ip(e,t,r){return ne(this,null,function*(){var n;let o=yield ge("rt"),i;if(ee.platform==="web")try{i=(n=yield ge("jwt"))!=null?n:yield Bd()}catch(f){console.error("webcrypto error",f)}let a={msgType:e,payload:t};i&&(a.jwt=i),i&&o&&(a.rt=o);let c=yield Vd(r);return c&&(a.deviceShare=c),a})}function ap(e){return ne(this,null,function*(){!e.data.rt||(yield He("rt",e.data.rt))})}var Ks=class{constructor(e,t,r,n){this.endpoint=e,this.parameters=t,this.networkHash=r,this.externalLogger=n,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return ne(this,null,function*(){return Ds((r,n)=>ne(this,null,function*(){var o,i;if(!this.isConnectedToInternet){let g=Bo();n(g)}this.isReadyForRequest||(ws("waiting for ready",{msgType:e,payload:t}),(o=this.externalLogger)==null||o.log("waiting for ready",{msgType:e,payload:t}),yield this.waitForReady(),ws("ready for requests",{msgType:e,payload:t}),(i=this.externalLogger)==null||i.log("ready for requests",{msgType:e,payload:t}));let a=[],c=Array.isArray(t)?t.map(g=>g.id):[],f=yield ip(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(f);let l=g=>y=>{var I;let{id:C,response:A}=op(t,y);if(ap(y),((I=A==null?void 0:A.payload.error)==null?void 0:I.message)==="User denied account access.")Ko();else if(y.data.deviceShare){let{deviceShare:L}=y.data;qd(L,this.networkHash)}C&&A&&Array.isArray(t)&&c.includes(C)?(a.push(A),a.length===t.length&&(g(),r(a))):C&&A&&!Array.isArray(t)&&C===t.id&&(g(),r(A))},p=this.on(Be.MAGIC_HANDLE_RESPONSE,l(()=>p()))}))})}on(e,t){let r=t.bind(window),n=o=>{o.data.msgType===`${e}-${this.parameters}`&&r(o)};return this.messageHandlers.add(n),()=>this.messageHandlers.delete(n)}waitForReady(){return new Promise(e=>{let t=this.on(Be.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(Be.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(Be.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(Be.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Et(Ye.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var qo={};bi(qo,{AuthEventOnReceived:()=>Ai,DeepLinkPage:()=>Ii,DeviceVerificationEventEmit:()=>or,DeviceVerificationEventOnReceived:()=>Ri,EthChainType:()=>Li,Events:()=>xt,Extension:()=>yt,ExtensionError:()=>Tn,ExtensionWarning:()=>In,LoginWithEmailOTPEventEmit:()=>ft,LoginWithEmailOTPEventOnReceived:()=>Ti,LoginWithMagicLinkEventEmit:()=>wi,LoginWithMagicLinkEventOnReceived:()=>xi,MagicIncomingWindowMessage:()=>Be,MagicOutgoingWindowMessage:()=>lt,MagicPayloadMethod:()=>M,RPCError:()=>Jt,RPCErrorCode:()=>wt,RecencyCheckEventEmit:()=>qe,RecencyCheckEventOnReceived:()=>Oi,RecoveryMethodType:()=>Ni,SDKError:()=>et,SDKErrorCode:()=>Ke,SDKWarning:()=>Et,SDKWarningCode:()=>Ye,UpdateEmailEventEmit:()=>Ve,UpdateEmailEventOnReceived:()=>Ci,WalletEventOnReceived:()=>Mi,Wallets:()=>Se,isPromiEvent:()=>Fo});var An=Si(qs()),zo=Si(zs());var sp={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function up(e){for(let[t,r]of Object.entries(sp))e.style[t]=r}function cp(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var Cn=class extends Ks{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let n=()=>{if(cp(encodeURIComponent(this.parameters)))As().log();else{let o=document.createElement("iframe");o.classList.add("magic-iframe"),o.dataset.magicIframeLabel=Cr(this.endpoint).host,o.title="Secure Modal",o.src=Cr(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,o.allow="clipboard-read; clipboard-write",up(o),document.body.appendChild(o),r(o)}};["loaded","interactive","complete"].includes(document.readyState)?n():window.addEventListener("load",n,!1)}),window.addEventListener("message",r=>{var n;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(n=r.data.response)!=null?n:{};for(let o of this.messageHandlers.values())o(r)}})}showOverlay(){return It(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return It(this,null,function*(){var n;let r=yield this.iframe;r.style.display="none",(n=this.activeElement)!=null&&n.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return It(this,null,function*(){let n=yield this.iframe;if(n&&n.contentWindow)n.contentWindow.postMessage(r,this.endpoint);else throw Bo()})}};var lp=Object.assign(Cs(Yo,{platform:"web",sdkName:"magic-sdk",version:"28.0.4",defaultEndpoint:"https://auth.magic.link/",ViewController:Cn,configureStorage:()=>It(void 0,null,function*(){let e=An.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(zo),yield e.setDriver([An.default.INDEXEDDB,An.default.LOCALSTORAGE,zo._driver]),e})}),yi({},qo)),fp=lp;return zu(dp);})();
|
11
|
+
Received: \`${e.received}\``)}function As(){return new Et(Ye.DuplicateIframe,"Duplicate iframes found.")}function Sd(){return new Et(Ye.SyncWeb3Method,"Non-async web3 methods are deprecated in web3 > 1.0 and are not supported by the Magic web3 provider. Please use an async method instead.")}function Id(){return new Et(Ye.ReactNativeEndpointConfiguration,`CUSTOM DOMAINS ARE NOT SUPPORTED WHEN USING MAGIC SDK WITH REACT NATIVE! The \`endpoint\` parameter SHOULD NOT be provided. The Magic \`<iframe>\` is automatically wrapped by a WebView pointed at \`${ee.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function xr(e){let{method:t,removalVersions:r,useInstead:n}=e,o=r[ee.sdkName],i=n?` Use \`${n}\` instead.`:"",a=`\`${t}\` will be removed from \`${ee.sdkName}\` in version \`${o}\`.${i}`;return new Et(Ye.DeprecationNotice,a)}function*wd(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var xd=wd();function Ls(){return xd.next().value}var Ns=Symbol("Payload pre-processed by Magic SDK");function Ms(e){return Object.defineProperty(e,Ns,{value:!0,enumerable:!1}),e}function Td(e){return!!e[Ns]}function wn(e){var t,r,n;return Td(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Ls(),e.method=(r=e.method)!=null?r:"noop",e.params=(n=e.params)!=null?n:[],Ms(e)),e}function W(e,t=[]){return Ms({params:t,method:e,jsonrpc:"2.0",id:Ls()})}var $o=class{constructor(e){e instanceof $o?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):md(e)?(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=e.result,this._error=e.error):(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=void 0,this._error=void 0)}applyError(e){return this._error=e,this}applyResult(e){return this._result=e,this}get hasError(){return typeof this._error!="undefined"&&this._error!==null}get hasResult(){return typeof this._result!="undefined"}get payload(){return{jsonrpc:this._jsonrpc,id:this._id,result:this._result,error:this._error}}},Rd=Sf(If()),Od=class extends Rd.default{};function ks(){let e=new Od;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...n)=>(e[t].apply(e,n),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Ps=Symbol("isPromiEvent");function Fo(e){return!!e[Ps]}function Or(e){let t=Ds(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:n}=ks(),o=Symbol("Promise.then"),i=Symbol("Promise.catch"),a=Symbol("Promise.finally"),c=(p,g)=>(...y)=>{let I=g[p].apply(g,y);return f(I)},f=p=>Object.assign(p,{[Ps]:!0,[o]:p[o]||p.then,[i]:p[i]||p.catch,[a]:p[a]||p.finally,then:c(o,p),catch:c(i,p),finally:c(a,p),on:n("on",p),once:n("once",p),addListener:n("addListener",p),off:n("off",p),removeListener:n("removeListener",p),removeAllListeners:n("removeAllListeners",p),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),l=f(t.then(p=>(l.emit("done",p),l.emit("settled"),p),p=>{throw l.emit("error",p),l.emit("settled"),p}));return l}function Ds(e){return new Promise((t,r)=>{let n=e(t,r);Promise.resolve(n).catch(r)})}var bt=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(lt.MAGIC_HANDLE_REQUEST,wn(e)),r=Or((o,i)=>{t.then(a=>{if(n(),a.hasError)i(new Jt(a.payload.error));else if(a.hasResult)o(a.payload.result);else throw yd()}).catch(a=>{n(),i(a)})}),n=this.overlay.on(Be.MAGIC_HANDLE_EVENT,o=>{var i;let{response:a}=o.data;if(a.id===e.id&&((i=a.result)==null?void 0:i.event)){let{event:c,params:f=[]}=a.result;r.emit(c,...f)}});return r}createIntermediaryEvent(e,t){return r=>{let n=W(M.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(n)}}};function Cd(e,t){let[r]=e.split(".").map(Number);return r>=t}var Tr={"magic-sdk":"v18.0.0","@magic-sdk/react-native":"v14.0.0","@magic-sdk/react-native-bare":"v19.0.0","@magic-sdk/react-native-expo":"v19.0.0"},Ad=class extends bt{loginWithMagicLink(e){let t=ee.sdkName==="@magic-sdk/react-native"||ee.sdkName==="@magic-sdk/react-native-bare"||ee.sdkName==="@magic-sdk/react-native-expo";if(t&&Cd(ee.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&xr({method:"auth.loginWithMagicLink()",removalVersions:Tr,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:n=!0,redirectURI:o,overrides:i}=e,a=W(this.sdk.testMode?M.LoginWithMagicLinkTestMode:M.LoginWithMagicLink,[{email:r,showUI:n,redirectURI:o,overrides:i}]);return this.request(a)}loginWithSMS(e){let{phoneNumber:t}=e,r=W(this.sdk.testMode?M.LoginWithSmsTestMode:M.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:n,overrides:o}=e,i=W(this.sdk.testMode?M.LoginWithEmailOTPTestMode:M.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:n,overrides:o}]),a=this.request(i);return!n&&a&&a.on(or.Retry,()=>{this.createIntermediaryEvent(or.Retry,i.id)()}),!r&&a&&(a.on(ft.VerifyEmailOtp,c=>{this.createIntermediaryEvent(ft.VerifyEmailOtp,i.id)(c)}),a.on(ft.Cancel,()=>{this.createIntermediaryEvent(ft.Cancel,i.id)()})),a}loginWithCredential(e){let t=e!=null?e:"";if(!e&&ee.platform==="web"){t=window.location.search;let n=window.location.origin+window.location.pathname;window.history.replaceState(null,"",n)}let r=W(this.sdk.testMode?M.LoginWithCredentialTestMode:M.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(M.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,n=W(this.sdk.testMode?M.UpdateEmailTestMode:M.UpdateEmail,[{email:t,showUI:r}]),o=this.request(n);return r||(o.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.Retry,n.id)()}),o.on(qe.Cancel,()=>{this.createIntermediaryEvent(qe.Cancel,n.id)()}),o.on(qe.VerifyEmailOtp,i=>{this.createIntermediaryEvent(qe.VerifyEmailOtp,n.id)(i)}),o.on(Ve.RetryWithNewEmail,i=>{this.createIntermediaryEvent(Ve.RetryWithNewEmail,n.id)(i)}),o.on(Ve.Cancel,()=>{this.createIntermediaryEvent(Ve.Cancel,n.id)()}),o.on(Ve.VerifyEmailOtp,i=>{this.createIntermediaryEvent(Ve.VerifyEmailOtp,n.id)(i)})),o}},Us={};bf(Us,{clear:()=>Ld,getItem:()=>ge,iterate:()=>Bs,key:()=>Md,keys:()=>kd,length:()=>Nd,removeItem:()=>Xt,setItem:()=>He});var En;function st(e){return(...t)=>ne(this,null,function*(){return En||(En=yield ee.configureStorage()),yield En.ready(),En[e](...t)})}var ge=st("getItem"),He=st("setItem"),Xt=st("removeItem"),Ld=st("clear"),Nd=st("length"),Md=st("key"),kd=st("keys"),Bs=st("iterate");function Pd(){let e=window.crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&191|128;let t="";return t+=e[0].toString(16),t+=e[1].toString(16),t+=e[2].toString(16),t+=e[3].toString(16),t+="-",t+=e[4].toString(16),t+=e[5].toString(16),t+="-",t+=e[6].toString(16),t+=e[7].toString(16),t+="-",t+=e[8].toString(16),t+=e[9].toString(16),t+="-",t+=e[10].toString(16),t+=e[11].toString(16),t+=e[12].toString(16),t+=e[13].toString(16),t+=e[14].toString(16),t+=e[15].toString(16),t}var $s="STORE_KEY_PRIVATE_KEY",ko="STORE_KEY_PUBLIC_JWK",Fs="ECDSA",Dd="P-256",Ud={name:Fs,namedCurve:Dd};function Rn(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Bd(){return ne(this,null,function*(){let e=yield $d();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield ge($s);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let n={iat:Math.floor(new Date().getTime()/1e3),jti:Pd()},o={typ:"dpop+jwt",alg:"ES256",jwk:e},i={protected:_s(JSON.stringify(o)),claims:_s(JSON.stringify(n))},a=Gd(`${i.protected}.${i.claims}`),c={name:Fs,hash:{name:"SHA-256"}},f=Wd(new Uint8Array(yield t.sign(c,r,a)));return`${i.protected}.${i.claims}.${f}`})}function $d(){return ne(this,null,function*(){if(!Rn()){console.info("webcrypto is not supported");return}return(yield ge(ko))||(yield Fd()),ge(ko)})}function Fd(){return ne(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Ud,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield He($s,t.privateKey),yield He(ko,r)})}function _s(e){return Gs(jd(e))}function Gd(e){return new TextEncoder().encode(e)}function Gs(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function jd(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Wd(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),Gs(t)}var Go="ds",jo="ek",Wo="iv",Ho="AES-GCM",Hd=256;function Ko(){return ne(this,null,function*(){let e=[];yield Bs((t,r,n)=>{r.startsWith(`${Go}_`)&&e.push(r)});for(let t of e)yield Xt(t)})}function js(e){let t="",r=new Uint8Array(e),n=r.byteLength;for(let o=0;o<n;o++)t+=String.fromCharCode(r[o]);return window.btoa(t)}function Ws(e){let t=window.atob(e),r=t.length,n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t.charCodeAt(o);return n.buffer}function Kd(){return ne(this,null,function*(){if(!Rn()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield ge(Wo))||e.getRandomValues(new Uint8Array(12))})}function Yd(){return ne(this,null,function*(){if(!Rn()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield ge(jo))||(yield e.generateKey({name:Ho,length:Hd},!1,["encrypt","decrypt"]))})}function qd(e,t){return ne(this,null,function*(){let r=yield Kd(),n=yield Yd();if(!r||!n||!e)return;let o=Ws(e),{subtle:i}=window.crypto,a=yield i.encrypt({name:Ho,iv:r},n,o),c=js(a);yield He(`${Go}_${t}`,c),yield He(jo,n),yield He(Wo,r)})}function Vd(e){return ne(this,null,function*(){let t=yield ge(`${Go}_${e}`),r=yield ge(Wo),n=yield ge(jo);if(!r||!t||!n||!Rn())return;let{subtle:o}=window.crypto,i=yield o.decrypt({name:Ho,iv:r},n,Ws(t));return js(i)})}function Cr(e,t){return t?new URL(e,t):new URL(e)}var zd=class extends bt{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=W(this.sdk.testMode?M.GetIdTokenTestMode:M.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?M.GenerateIdTokenTestMode:M.GenerateIdToken,[e]);return this.request(t)}getInfo(){return ne(this,null,function*(){let e=yield ge(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){return Or((e,t)=>ne(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield ge(this.localForageIsLoggedInKey))==="true",r&&e(!0));let n=W(this.sdk.testMode?M.IsLoggedInTestMode:M.IsLoggedIn),o=yield this.request(n);this.sdk.useStorageCache&&(o?He(this.localForageIsLoggedInKey,!0):Xt(this.localForageIsLoggedInKey),r&&!o&&this.emitUserLoggedOut(!0)),e(o)}catch(r){t(r)}}))}logout(){return Xt(this.localForageKey),Xt(this.localForageIsLoggedInKey),Ko(),Or((e,t)=>ne(this,null,function*(){try{let r=W(this.sdk.testMode?M.LogoutTestMode:M.Logout),n=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(n),e(n)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?M.UserSettingsTestMode:M.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?M.RecoverAccountTestMode:M.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=W(M.RevealPK);return this.request(e)}getMetadata(){xr({method:"user.getMetadata()",removalVersions:Tr,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?M.GetMetadataTestMode:M.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Xd=class extends bt{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Or((t,r)=>ne(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(Se.MetaMask))){let c=yield this.autoConnectIfWalletBrowser(Se.MetaMask);t(c);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(Se.CoinbaseWallet))){let c=yield this.autoConnectIfWalletBrowser(Se.CoinbaseWallet);t(c);return}let n=this.getUserEnv(),o=W(M.Login,[n]),i=this.request(o);i.on(xt.WalletSelected,c=>this.handleWalletSelected(Do(Po({},c),{payloadId:o.id}))),i.on("id-token-created",c=>{e.emit("id-token-created",c)});let a=yield i;a.error&&r(a),t(a)}catch(n){r(n)}}));return e}showUI(){return this.request(W(M.ShowUI))}showAddress(){return this.request(W(M.ShowAddress))}showSendTokensUI(){return this.request(W(M.ShowSendTokensUI))}showOnRamp(){return this.request(W(M.ShowOnRamp))}showNFTs(){return this.request(W(M.ShowNFTs))}showBalances(){return this.request(W(M.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(M.SendGaslessTransaction,[e,t]))}getInfo(){return ne(this,null,function*(){xr({method:"wallet.getInfo()",removalVersions:Tr,useInstead:"user.getInfo()"}).log();let e=yield ge(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){xr({method:"wallet.disconnect()",removalVersions:Tr,useInstead:"user.logout()"}).log(),Xt(this.localForageKey),Ko();let e=W(M.Disconnect);return this.request(e)}requestUserInfoWithUI(e){xr({method:"wallet.requestUserInfoWithUI()",removalVersions:Tr,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return ne(this,null,function*(){switch(yield ge(this.localForageKey)){case Se.MetaMask:return this.getMetaMaskProvider();case Se.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isMetaMask)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(n=>n==null?void 0:n.isMetaMask))}isMetaMaskBrowser(){return this.isMobile()&&this.isMetaMaskInstalled()}getMetaMaskProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isMetaMask))||window.ethereum}connectToMetaMask(){if(this.isMobile()&&!this.isMetaMaskInstalled()){let e=`https://metamask.app.link/dapp/${window.location.href.replace(/(^\w+:|^)\/\//,"")}`;window.location.href=e}return this.getMetaMaskProvider().request({method:"eth_requestAccounts"})}isCoinbaseWalletInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isCoinbaseWallet)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(n=>n==null?void 0:n.isCoinbaseWallet))}isCoinbaseWalletBrowser(){var e;return!!((e=window.ethereum)!=null&&e.isCoinbaseBrowser)}getCoinbaseProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let e=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=e}return this.getCoinbaseProvider().request({method:"eth_requestAccounts"})}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)}getUserEnv(){return{env:{isMetaMaskInstalled:this.isMetaMaskInstalled(),isCoinbaseWalletInstalled:this.isCoinbaseWalletInstalled()}}}connectToThirdPartyWallet(e){switch(e){case Se.MetaMask:return this.connectToMetaMask();case Se.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=W("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return ne(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield He(this.localForageKey,e.wallet),this.createIntermediaryEvent(xt.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(xt.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return ne(this,null,function*(){let t;e===Se.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===Se.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield He(this.localForageKey,e);let r=W(M.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:bn,createChainingEmitterMethod:Vt}=ks(),Jd=class extends bt{constructor(){super(...arguments),this.isMagic=!0,this.on=Vt("on",this),this.once=Vt("once",this),this.addListener=Vt("addListener",this),this.off=Vt("off",this),this.removeListener=Vt("removeListener",this),this.removeAllListeners=Vt("removeAllListeners",this),this.emit=bn("emit"),this.eventNames=bn("eventNames"),this.listeners=bn("listeners"),this.listenerCount=bn("listenerCount")}sendAsync(e,t){if(!t)throw _d({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(lt.MAGIC_HANDLE_REQUEST,e.map(r=>{let n=wn(r);return this.prefixPayloadMethodForTestMode(n),n})).then(r=>{t(null,r.map(n=>Do(Po({},n.payload),{error:n.hasError?new Jt(n.payload.error):null})))});else{let r=wn(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(lt.MAGIC_HANDLE_REQUEST,r).then(n=>{t(n.hasError?new Jt(n.payload.error):null,n.payload)})}}send(e,t){if(typeof e=="string"){let n=W(e,Array.isArray(t)?t:[]);return this.request(n)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=Sd();return r.log(),new $o(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(M.Login);return this.request(e)}request(e){return this.prefixPayloadMethodForTestMode(e),super.request(e)}prefixPayloadMethodForTestMode(e){let t="testMode/eth/";this.sdk.testMode&&(e.method=`${t}${e.method}`)}},Ss=["request","overlay","sdk"];function Zd(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==bt.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var Hs=class extends bt{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Or,isPromiEvent:Fo,encodeJSON:Rs,decodeJSON:dd,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:wn,storage:Us};let e=[this,...Zd(this)];Ss.forEach(t=>{let r=e.map(a=>Object.getOwnPropertyDescriptor(a,t)),n=r.findIndex(a=>!!a),o=n>0,i=r[n];i&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:i,isPrototypeField:o}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Ed(t)}}))})}init(e){this.__is_initialized__||(Ss.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:n}=this.__sdk_access_field_descriptors__.get(t);n?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:n}=e,o=n?` Use \`${n}\` instead.`:"",i=`\`${t}\` will be removed from this Extension in version \`${r}\`.${o}`;return new In(this,"DEPRECATION_NOTICE",i)}createWarning(e,t){return new In(this,e,t)}createError(e,t,r){return new Tn(this,e,t,r)}},Qd=class extends Hs{},yt=class extends Hs{};yt.Internal=Qd,yt.Anonymous="anonymous extension";var ep=class extends bt{purchase(e){let t=W(M.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(M.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(M.NFTTransfer,[e]);return this.request(t)}};function Is(e){return e.compat&&e.compat[ee.sdkName]!=null?typeof e.compat[ee.sdkName]=="string"?nd(sd(ee.version),e.compat[ee.sdkName]):!!e.compat[ee.sdkName]:!0}function tp(e,t,r){return!t&&!r?`${e}_eth_mainnet`:r?`${e}_${JSON.stringify(r)}`:t?typeof t=="string"?`${e}_eth_${t}`:`${e}_${t.rpcUrl}_${t.chainId}_${t.chainType}`:`${e}_unknown`}function rp(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],n={},o=[];if(Array.isArray(r)?r.forEach(i=>{Is(i)?(i.init(this),(i.name||i.name!==yt.Anonymous)&&(this[i.name]=i),i instanceof yt.Internal&&(Sn(i.config)||(n[i.name]=i.config))):o.push(i)}):Object.keys(r).forEach(i=>{if(Is(r[i])){r[i].init(this);let a=r[i];this[i]=a,a instanceof yt.Internal&&(Sn(a.config)||(n[r[i].name]=a.config))}else o.push(r[i])}),o.length)throw bd(o);return n}var _n=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw gd();ee.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Id().log();let{defaultEndpoint:n,version:o}=ee;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=Cr((r=t==null?void 0:t.endpoint)!=null?r:n).origin,this.externalLogger=t==null?void 0:t.externalLogger,this.auth=new Ad(this),this.user=new zd(this),this.wallet=new Xd(this),this.nft=new ep(this),this.rpcProvider=new Jd(this);let i=rp.call(this,t);this.parameters=Rs(Do(Po({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:Cr(this.endpoint).host,sdk:vd[ee.sdkName],version:o,ext:Sn(i)?void 0:i,locale:(t==null?void 0:t.locale)||"en_US"},ee.bundleId?{bundleId:ee.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=tp(this.apiKey,t==null?void 0:t.network,Sn(i)?void 0:i),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!_n.__overlays__.has(this.parameters)){let e=new ee.ViewController(this.endpoint,this.parameters,this.networkHash,this.externalLogger);e.init(),_n.__overlays__.set(this.parameters,e)}return _n.__overlays__.get(this.parameters)}preload(){return ne(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Yo=_n;Yo.__overlays__=new Map;var ws=(e,t={})=>{_r.logger.log(e,{data:t})};_r.init({clientToken:"pubabac4d3c893a1ad69023911f42fce019",service:"movement"});function np(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function op(e,t){var r;let n=(r=t.data.response)==null?void 0:r.id,o=np(e,n);if(n&&o){let i=new $o(o).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:n,response:i}}return{}}function ip(e,t,r){return ne(this,null,function*(){var n;let o=yield ge("rt"),i;if(ee.platform==="web")try{i=(n=yield ge("jwt"))!=null?n:yield Bd()}catch(f){console.error("webcrypto error",f)}let a={msgType:e,payload:t};i&&(a.jwt=i),i&&o&&(a.rt=o);let c=yield Vd(r);return c&&(a.deviceShare=c),a})}function ap(e){return ne(this,null,function*(){!e.data.rt||(yield He("rt",e.data.rt))})}var Ks=class{constructor(e,t,r,n){this.endpoint=e,this.parameters=t,this.networkHash=r,this.externalLogger=n,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return ne(this,null,function*(){return Ds((r,n)=>ne(this,null,function*(){var o,i;if(!this.isConnectedToInternet){let g=Bo();n(g)}this.isReadyForRequest||(console.log("waiting for ready"),ws("waiting for ready",{msgType:e,payload:t}),(o=this.externalLogger)==null||o.log("waiting for ready",{msgType:e,payload:t}),yield this.waitForReady(),console.log("ready for requests"),ws("ready for requests",{msgType:e,payload:t}),(i=this.externalLogger)==null||i.log("ready for requests",{msgType:e,payload:t}));let a=[],c=Array.isArray(t)?t.map(g=>g.id):[],f=yield ip(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(f);let l=g=>y=>{var I;let{id:C,response:A}=op(t,y);if(ap(y),((I=A==null?void 0:A.payload.error)==null?void 0:I.message)==="User denied account access.")Ko();else if(y.data.deviceShare){let{deviceShare:L}=y.data;qd(L,this.networkHash)}C&&A&&Array.isArray(t)&&c.includes(C)?(a.push(A),a.length===t.length&&(g(),r(a))):C&&A&&!Array.isArray(t)&&C===t.id&&(g(),r(A))},p=this.on(Be.MAGIC_HANDLE_RESPONSE,l(()=>p()))}))})}on(e,t){let r=t.bind(window),n=o=>{o.data.msgType===`${e}-${this.parameters}`&&r(o)};return this.messageHandlers.add(n),()=>this.messageHandlers.delete(n)}waitForReady(){return new Promise(e=>{let t=this.on(Be.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(Be.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(Be.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(Be.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Et(Ye.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var qo={};bi(qo,{AuthEventOnReceived:()=>Ai,DeepLinkPage:()=>Ii,DeviceVerificationEventEmit:()=>or,DeviceVerificationEventOnReceived:()=>Ri,EthChainType:()=>Li,Events:()=>xt,Extension:()=>yt,ExtensionError:()=>Tn,ExtensionWarning:()=>In,LoginWithEmailOTPEventEmit:()=>ft,LoginWithEmailOTPEventOnReceived:()=>Ti,LoginWithMagicLinkEventEmit:()=>wi,LoginWithMagicLinkEventOnReceived:()=>xi,MagicIncomingWindowMessage:()=>Be,MagicOutgoingWindowMessage:()=>lt,MagicPayloadMethod:()=>M,RPCError:()=>Jt,RPCErrorCode:()=>wt,RecencyCheckEventEmit:()=>qe,RecencyCheckEventOnReceived:()=>Oi,RecoveryMethodType:()=>Ni,SDKError:()=>et,SDKErrorCode:()=>Ke,SDKWarning:()=>Et,SDKWarningCode:()=>Ye,UpdateEmailEventEmit:()=>Ve,UpdateEmailEventOnReceived:()=>Ci,WalletEventOnReceived:()=>Mi,Wallets:()=>Se,isPromiEvent:()=>Fo});var An=Si(qs()),zo=Si(zs());var sp={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function up(e){for(let[t,r]of Object.entries(sp))e.style[t]=r}function cp(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var Cn=class extends Ks{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let n=()=>{if(cp(encodeURIComponent(this.parameters)))As().log();else{let o=document.createElement("iframe");o.classList.add("magic-iframe"),o.dataset.magicIframeLabel=Cr(this.endpoint).host,o.title="Secure Modal",o.src=Cr(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,o.allow="clipboard-read; clipboard-write",up(o),document.body.appendChild(o),r(o)}};["loaded","interactive","complete"].includes(document.readyState)?n():window.addEventListener("load",n,!1)}),window.addEventListener("message",r=>{var n;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(n=r.data.response)!=null?n:{};for(let o of this.messageHandlers.values())o(r)}})}showOverlay(){return It(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return It(this,null,function*(){var n;let r=yield this.iframe;r.style.display="none",(n=this.activeElement)!=null&&n.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return It(this,null,function*(){let n=yield this.iframe;if(n&&n.contentWindow)n.contentWindow.postMessage(r,this.endpoint);else throw Bo()})}};var lp=Object.assign(Cs(Yo,{platform:"web",sdkName:"magic-sdk",version:"28.0.4",defaultEndpoint:"https://auth.magic.link/",ViewController:Cn,configureStorage:()=>It(void 0,null,function*(){let e=An.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(zo),yield e.setDriver([An.default.INDEXEDDB,An.default.LOCALSTORAGE,zo._driver]),e})}),yi({},qo)),fp=lp;return zu(dp);})();
|
12
12
|
if (Magic && Magic.default != null) { Magic = Object.assign(Magic.default, Magic); delete Magic.default; }
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "magic-sdk",
|
3
|
-
"version": "28.0.5-canary.747.
|
3
|
+
"version": "28.0.5-canary.747.9407043010.0",
|
4
4
|
"description": "Passwordless authentication for the web.",
|
5
5
|
"author": "Magic Labs <team@magic.link> (https://magic.link/)",
|
6
6
|
"license": "MIT",
|
@@ -29,8 +29,8 @@
|
|
29
29
|
]
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@magic-sdk/commons": "24.0.4-canary.747.
|
33
|
-
"@magic-sdk/provider": "28.0.4-canary.747.
|
32
|
+
"@magic-sdk/commons": "24.0.4-canary.747.9407043010.0",
|
33
|
+
"@magic-sdk/provider": "28.0.4-canary.747.9407043010.0",
|
34
34
|
"@magic-sdk/types": "^24.0.2",
|
35
35
|
"localforage": "^1.7.4"
|
36
36
|
},
|
@@ -40,5 +40,5 @@
|
|
40
40
|
"@babel/runtime": "^7.9.6",
|
41
41
|
"localforage-driver-memory": "^1.0.5"
|
42
42
|
},
|
43
|
-
"gitHead": "
|
43
|
+
"gitHead": "45cbefcf1463682068d75472d1767251b9ad772c"
|
44
44
|
}
|