magic-sdk 28.13.0-canary.816.11344317837.0 → 28.13.0-canary.816.11362588320.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 CHANGED
@@ -2,5 +2,5 @@
2
2
  - Extension \`${r.name}\` supports version(s) \`${o}\``:o||(t+=`
3
3
  - Extension \`${r.name}\` does not support ${Y.platform} environments.`)}),new be(ge.IncompatibleExtensions,t)}function Fo(e){let t=r=>{let o=r+1,a=o%10,s=o%100;return a===1&&s!==11?`${o}st`:a===2&&s!==12?`${o}nd`:a===3&&s!==13?`${o}rd`:`${o}th`};return new be(ge.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
4
4
  Expected: \`${e.expected}\`
5
- Received: \`${e.received}\``)}function an(){return new Pe(ye.DuplicateIframe,"Duplicate iframes found.")}function ko(){return new Pe(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 Bo(){return new Pe(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 \`${Y.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function Ze(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],s=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${s}`;return new Pe(ye.DeprecationNotice,m)}function*Wo(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Go=Wo();function sn(){return Go.next().value}var ln=Symbol("Payload pre-processed by Magic SDK");function cn(e){return Object.defineProperty(e,ln,{value:!0,enumerable:!1}),e}function jo(e){return!!e[ln]}function gt(e){var t,r,o;return jo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=sn(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],cn(e)),e}function B(e,t=[]){return cn({params:t,method:e,jsonrpc:"2.0",id:sn()})}var kt=class{constructor(e){e instanceof kt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):Lo(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}}},Vo=Fi(ki()),qo=class extends Vo.default{};function un(){let e=new qo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var fn=Symbol("isPromiEvent");function Bt(e){return!!e[fn]}function rt(e){let t=dn(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=un(),a=Symbol("Promise.then"),s=Symbol("Promise.catch"),m=Symbol("Promise.finally"),d=(y,M)=>(..._)=>{let T=M[y].apply(M,_);return g(T)},g=y=>Object.assign(y,{[fn]:!0,[a]:y[a]||y.then,[s]:y[s]||y.catch,[m]:y[m]||y.finally,then:d(a,y),catch:d(s,y),finally:d(m,y),on:o("on",y),once:o("once",y),addListener:o("addListener",y),off:o("off",y),removeListener:o("removeListener",y),removeAllListeners:o("removeAllListeners",y),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),v=g(t.then(y=>(v.emit("done",y),v.emit("settled"),y),y=>{throw v.emit("error",y),v.emit("settled"),y}));return v.on(lt.ClosedByUser,()=>{v.emit(st.ClosedByUser)}),v}function dn(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var $e=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Ee.MAGIC_HANDLE_REQUEST,gt(e)),r=rt((a,s)=>{t.then(m=>{if(o(),m.hasError)s(new Ge(m.payload.error));else if(m.hasResult)a(m.payload.result);else throw Do()}).catch(m=>{o(),s(m)})}),o=this.overlay.on(de.MAGIC_HANDLE_EVENT,a=>{var s;let{response:m}=a.data;if(m.id===e.id&&((s=m.result)==null?void 0:s.event)){let{event:d,params:g=[]}=m.result;r.emit(d,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=B(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Ko(e,t){let[r]=e.split(".").map(Number);return r>=t}var et={"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"},Ho=class extends $e{loginWithMagicLink(e){let t=Y.sdkName==="@magic-sdk/react-native"||Y.sdkName==="@magic-sdk/react-native-bare"||Y.sdkName==="@magic-sdk/react-native-expo";if(t&&Ko(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&Ze({method:"auth.loginWithMagicLink()",removalVersions:et,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:s,lifespan:m}=e,d=B(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s,lifespan:m}]);return this.request(d)}loginWithSMS(e){let{phoneNumber:t,showUI:r=!0,lifespan:o}=e,a=B(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:r,lifespan:o}]),s=this.request(a);return!r&&s&&(s.on(Oe.VerifySmsOtp,m=>{this.createIntermediaryEvent(Oe.VerifySmsOtp,a.id)(m)}),s.on(Oe.Cancel,()=>{this.createIntermediaryEvent(Oe.Cancel,a.id)()})),s}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a,lifespan:s}=e,m=B(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a,lifespan:s}]),d=this.request(m);return!o&&d&&d.on(Xe.Retry,()=>{this.createIntermediaryEvent(Xe.Retry,m.id)()}),!r&&d&&(d.on(_e.VerifyEmailOtp,g=>{this.createIntermediaryEvent(_e.VerifyEmailOtp,m.id)(g)}),d.on(_e.VerifyMFACode,g=>{this.createIntermediaryEvent(_e.VerifyMFACode,m.id)(g)}),d.on(_e.Cancel,()=>{this.createIntermediaryEvent(_e.Cancel,m.id)()})),d}loginWithCredential(e){let{credentialOrQueryString:t,lifespan:r}=e||{},o=t!=null?t:"";if(!t&&Y.platform==="web"){o=window.location.search;let s=window.location.origin+window.location.pathname;window.history.replaceState(null,"",s)}let a=B(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[o,r]);return this.request(a)}setAuthorizationToken(e){let t=B(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(me.Retry,()=>{this.createIntermediaryEvent(me.Retry,o.id)()}),a.on(me.Cancel,()=>{this.createIntermediaryEvent(me.Cancel,o.id)()}),a.on(me.VerifyEmailOtp,s=>{this.createIntermediaryEvent(me.VerifyEmailOtp,o.id)(s)}),a.on(me.VerifyMFACode,s=>{this.createIntermediaryEvent(me.VerifyMFACode,o.id)(s)}),a.on(Ie.RetryWithNewEmail,s=>{this.createIntermediaryEvent(Ie.RetryWithNewEmail,o.id)(s)}),a.on(Ie.Cancel,()=>{this.createIntermediaryEvent(Ie.Cancel,o.id)()}),a.on(Ie.VerifyEmailOtp,s=>{this.createIntermediaryEvent(Ie.VerifyEmailOtp,o.id)(s)})),a}},hn={};Ui(hn,{clear:()=>Yo,getItem:()=>se,iterate:()=>mn,key:()=>zo,keys:()=>Jo,length:()=>Xo,removeItem:()=>We,setItem:()=>ve});var dt;function Te(e){return(...t)=>X(this,null,function*(){return dt||(dt=yield Y.configureStorage()),yield dt.ready(),dt[e](...t)})}var se=Te("getItem"),ve=Te("setItem"),We=Te("removeItem"),Yo=Te("clear"),Xo=Te("length"),zo=Te("key"),Jo=Te("keys"),mn=Te("iterate");function Qo(){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 pn="STORE_KEY_PRIVATE_KEY",Dt="STORE_KEY_PUBLIC_JWK",vn="ECDSA",Zo="P-256",ea={name:vn,namedCurve:Zo};function It(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function ta(){return X(this,null,function*(){let e=yield ra();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield se(pn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Qo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:Jr(JSON.stringify(a)),claims:Jr(JSON.stringify(o))},m=ia(`${s.protected}.${s.claims}`),d={name:vn,hash:{name:"SHA-256"}},g=aa(new Uint8Array(yield t.sign(d,r,m)));return`${s.protected}.${s.claims}.${g}`})}function ra(){return X(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}return(yield se(Dt))||(yield na()),se(Dt)})}function na(){return X(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(ea,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield ve(pn,t.privateKey),yield ve(Dt,r)})}function Jr(e){return gn(oa(e))}function ia(e){return new TextEncoder().encode(e)}function gn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function oa(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function aa(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),gn(t)}var Wt="ds",Gt="ek",jt="iv",Vt="AES-GCM",sa=256;function qt(){return X(this,null,function*(){let e=[];yield mn((t,r,o)=>{r.startsWith(`${Wt}_`)&&e.push(r)});for(let t of e)yield We(t)})}function yn(e){let t="",r=new Uint8Array(e),o=r.byteLength;for(let a=0;a<o;a++)t+=String.fromCharCode(r[a]);return window.btoa(t)}function En(e){let t=window.atob(e),r=t.length,o=new Uint8Array(r);for(let a=0;a<r;a++)o[a]=t.charCodeAt(a);return o.buffer}function la(){return X(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield se(jt))||e.getRandomValues(new Uint8Array(12))})}function ca(){return X(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield se(Gt))||(yield e.generateKey({name:Vt,length:sa},!1,["encrypt","decrypt"]))})}function ua(e,t){return X(this,null,function*(){let r=yield la(),o=yield ca();if(!r||!o||!e)return;let a=En(e),{subtle:s}=window.crypto,m=yield s.encrypt({name:Vt,iv:r},o,a),d=yn(m);yield ve(`${Wt}_${t}`,d),yield ve(Gt,o),yield ve(jt,r)})}function fa(e){return X(this,null,function*(){let t=yield se(`${Wt}_${e}`),r=yield se(jt),o=yield se(Gt);if(!r||!t||!o||!It())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:Vt,iv:r},o,En(t));return yn(s)})}function nt(e,t){return t?new URL(e,t):new URL(e)}var da=class extends $e{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=B(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=B(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return X(this,null,function*(){let e=yield se(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){return rt((e,t)=>X(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield se(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=B(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?ve(this.localForageIsLoggedInKey,!0):We(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return We(this.localForageKey),We(this.localForageIsLoggedInKey),qt(),rt((e,t)=>X(this,null,function*(){try{let r=B(this.sdk.testMode?O.LogoutTestMode:O.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=B(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=B(this.sdk.testMode?O.RecoverAccountTestMode:O.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=B(O.RevealPK);return this.request(e)}getMetadata(){Ze({method:"user.getMetadata()",removalVersions:et,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}enableMFA(e){let{showUI:t=!0}=e,r=B(O.EnableMFA,[{showUI:t}]),o=this.request(r);return!t&&o&&(o.on(Le.VerifyMFACode,a=>{this.createIntermediaryEvent(Le.VerifyMFACode,r.id)(a)}),o.on(Le.Cancel,()=>{this.createIntermediaryEvent(Le.Cancel,r.id)()})),o}disableMFA(e){let{showUI:t=!0}=e,r=B(O.DisableMFA,[{showUI:t}]),o=this.request(r);return!t&&o&&(o.on(we.VerifyMFACode,a=>{this.createIntermediaryEvent(we.VerifyMFACode,r.id)(a)}),o.on(we.LostDevice,a=>{this.createIntermediaryEvent(we.LostDevice,r.id)(a)}),o.on(we.Cancel,()=>{this.createIntermediaryEvent(we.Cancel,r.id)()})),o}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},ha=class extends $e{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=rt((t,r)=>X(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ue.MetaMask))){let d=yield this.autoConnectIfWalletBrowser(ue.MetaMask);t(d);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ue.CoinbaseWallet))){let d=yield this.autoConnectIfWalletBrowser(ue.CoinbaseWallet);t(d);return}let o=this.getUserEnv(),a=B(O.Login,[o]),s=this.request(a);s.on(Fe.WalletSelected,d=>this.handleWalletSelected(xt(Ut({},d),{payloadId:a.id}))),s.on("id-token-created",d=>{e.emit("id-token-created",d)});let m=yield s;m.error&&r(m),t(m)}catch(o){r(o)}}));return e}showUI(e){return this.request(B(O.ShowUI,[e]))}showAddress(){return this.request(B(O.ShowAddress))}showSendTokensUI(){return this.request(B(O.ShowSendTokensUI))}showOnRamp(){return this.request(B(O.ShowOnRamp))}showNFTs(){return this.request(B(O.ShowNFTs))}showBalances(){return this.request(B(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(B(O.SendGaslessTransaction,[e,t]))}getInfo(){return X(this,null,function*(){Ze({method:"wallet.getInfo()",removalVersions:et,useInstead:"user.getInfo()"}).log();let e=yield se(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){Ze({method:"wallet.disconnect()",removalVersions:et,useInstead:"user.logout()"}).log(),We(this.localForageKey),qt();let e=B(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){Ze({method:"wallet.requestUserInfoWithUI()",removalVersions:et,useInstead:"user.requestUserInfoWithUI()"}).log();let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return X(this,null,function*(){switch(yield se(this.localForageKey)){case ue.MetaMask:return this.getMetaMaskProvider();case ue.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(o=>o==null?void 0:o.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(o=>o==null?void 0:o.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 ue.MetaMask:return this.connectToMetaMask();case ue.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=B("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return X(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield ve(this.localForageKey,e.wallet),this.createIntermediaryEvent(Fe.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Fe.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return X(this,null,function*(){let t;e===ue.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ue.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield ve(this.localForageKey,e);let r=B(O.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:ht,createChainingEmitterMethod:ke}=un(),ma=class extends $e{constructor(){super(...arguments),this.isMagic=!0,this.on=ke("on",this),this.once=ke("once",this),this.addListener=ke("addListener",this),this.off=ke("off",this),this.removeListener=ke("removeListener",this),this.removeAllListeners=ke("removeAllListeners",this),this.emit=ht("emit"),this.eventNames=ht("eventNames"),this.listeners=ht("listeners"),this.listenerCount=ht("listenerCount")}sendAsync(e,t){if(!t)throw Fo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Ee.MAGIC_HANDLE_REQUEST,e.map(r=>{let o=gt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>xt(Ut({},o.payload),{error:o.hasError?new Ge(o.payload.error):null})))});else{let r=gt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Ee.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Ge(o.payload.error):null,o.payload)})}}send(e,t){if(typeof e=="string"){let o=B(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=ko();return r.log(),new kt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=B(O.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}`)}},Qr=["request","overlay","sdk"];function pa(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==$e.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var _n=class extends $e{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:rt,isPromiEvent:Bt,encodeJSON:rn,decodeJSON:No,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:gt,storage:hn};let e=[this,...pa(this)];Qr.forEach(t=>{let r=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=r.findIndex(m=>!!m),a=o>0,s=r[o];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Uo(t)}}))})}init(e){this.__is_initialized__||(Qr.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new vt(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new vt(this,e,t)}createError(e,t,r){return new Et(this,e,t,r)}},va=class extends _n{},Ce=class extends _n{};Ce.Internal=va,Ce.Anonymous="anonymous extension";var ga=class extends $e{purchase(e){let t=B(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=B(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=B(O.NFTTransfer,[e]);return this.request(t)}};function Zr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?_o(Ro(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function ya(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 Ea(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(s=>{Zr(s)?(s.init(this),(s.name||s.name!==Ce.Anonymous)&&(this[s.name]=s),s instanceof Ce.Internal&&(pt(s.config)||(o[s.name]=s.config))):a.push(s)}):Object.keys(r).forEach(s=>{if(Zr(r[s])){r[s].init(this);let m=r[s];this[s]=m,m instanceof Ce.Internal&&(pt(m.config)||(o[r[s].name]=m.config))}else a.push(r[s])}),a.length)throw xo(a);return o}var mt=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw $o();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Bo().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=nt((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new Ho(this),this.user=new da(this),this.wallet=new ha(this),this.nft=new ga(this),this.rpcProvider=new ma(this);let s=Ea.call(this,t);this.parameters=rn(xt(Ut({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:nt(this.endpoint).host,sdk:Po[Y.sdkName],version:a,ext:pt(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=ya(this.apiKey,t==null?void 0:t.network,pt(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!mt.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),mt.__overlays__.set(this.parameters,e)}return mt.__overlays__.get(this.parameters)}preload(){return X(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Kt=mt;Kt.__overlays__=new Map;function _a(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function Ia(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=_a(e,o);if(o&&a){let s=new kt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function wa(e,t,r){return X(this,null,function*(){var o;let a=yield se("rt"),s;if(Y.platform==="web")try{s=(o=yield se("jwt"))!=null?o:yield ta()}catch(g){console.error("webcrypto error",g)}let m={msgType:e,payload:t};s&&(m.jwt=s),s&&a&&(m.rt=a);let d=yield fa(r);return d&&(m.deviceShare=d),m})}function ba(e){return X(this,null,function*(){!e.data.rt||(yield ve("rt",e.data.rt))})}var In=class{constructor(e,t,r){this.endpoint=e,this.parameters=t,this.networkHash=r,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return X(this,null,function*(){return dn((r,o)=>X(this,null,function*(){if(!this.isConnectedToInternet){let v=_t();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],m=yield wa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(m);let d=v=>y=>{var M;let{id:_,response:T}=Ia(t,y);if(ba(y),((M=T==null?void 0:T.payload.error)==null?void 0:M.message)==="User denied account access.")qt();else if(y.data.deviceShare){let{deviceShare:L}=y.data;ua(L,this.networkHash)}_&&T&&Array.isArray(t)&&s.includes(_)?(a.push(T),a.length===t.length&&(v(),r(a))):_&&T&&!Array.isArray(t)&&_===t.id&&(v(),r(T))},g=this.on(de.MAGIC_HANDLE_RESPONSE,d(()=>g()))}))})}on(e,t){let r=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&r(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{let t=this.on(de.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()});setTimeout(()=>{this.isReadyForRequest=!0,e(),t()},15e3)})}listen(){this.on(de.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(de.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(de.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Pe(ye.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Ht={};_r(Ht,{AuthEventOnReceived:()=>Lr,DeepLinkPage:()=>br,DeviceVerificationEventEmit:()=>Xe,DeviceVerificationEventOnReceived:()=>Mr,DisableMFAEventEmit:()=>we,DisableMFAEventOnReceived:()=>$r,EnableMFAEventEmit:()=>Le,EnableMFAEventOnReceived:()=>Pr,EthChainType:()=>Dr,Events:()=>Fe,Extension:()=>Ce,ExtensionError:()=>Et,ExtensionWarning:()=>vt,FarcasterLoginEventEmit:()=>Cr,LoginWithEmailOTPEventEmit:()=>_e,LoginWithEmailOTPEventOnReceived:()=>Tr,LoginWithMagicLinkEventEmit:()=>Rr,LoginWithMagicLinkEventOnReceived:()=>Ar,LoginWithSmsOTPEventEmit:()=>Oe,LoginWithSmsOTPEventOnReceived:()=>Sr,MagicIncomingWindowMessage:()=>de,MagicOutgoingWindowMessage:()=>Ee,MagicPayloadMethod:()=>O,NftCheckoutIntermediaryEvents:()=>xr,RPCError:()=>Ge,RPCErrorCode:()=>xe,RecencyCheckEventEmit:()=>me,RecencyCheckEventOnReceived:()=>Nr,RecoveryMethodType:()=>Ur,SDKError:()=>be,SDKErrorCode:()=>ge,SDKWarning:()=>Pe,SDKWarningCode:()=>ye,UiEventsEmit:()=>kr,UpdateEmailEventEmit:()=>Ie,UpdateEmailEventOnReceived:()=>Or,UserEventsEmit:()=>st,UserEventsOnReceived:()=>lt,WalletEventOnReceived:()=>Fr,Wallets:()=>ue,isPromiEvent:()=>Bt});var Rt=wr(bn()),Xt=wr(An());var Ra={display:"block",visibility:"hidden",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647",opacity:"0"};function Aa(e){for(let[t,r]of Object.entries(Ra))e.style[t]=r}function Sa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var Sn=1e3,Tn=60*Sn,Ta=15*Sn,Ma=2*Tn,Na=60*Tn,bt=class extends In{constructor(){super(...arguments);this.activeElement=null;this.lastPingTime=Date.now();this.intervalTimer=null;this.timeoutTimer=null}getIframeSrc(){return nt(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(Sa(encodeURIComponent(this.parameters)))an().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=nt(this.endpoint).host,a.title="Secure Modal",a.src=this.getIframeSrc(),a.allow="clipboard-read; clipboard-write",Aa(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),this.iframe.then(r=>{r.addEventListener("load",()=>pe(this,null,function*(){yield this.startHeartBeat()}))}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.msgType.includes(de.MAGIC_PONG)&&(this.lastPingTime=Date.now()),r.data.response=(o=r.data.response)!=null?o:{};for(let s of this.messageHandlers.values())s(r)}}),window.addEventListener("beforeunload",()=>{this.stopHeartBeat()})}showOverlay(){return pe(this,null,function*(){let r=yield this.iframe;r.style.visibility="visible",r.style.opacity="1",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return pe(this,null,function*(){var o;let r=yield this.iframe;r.style.visibility="hidden",r.style.opacity="0",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return pe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw _t()})}heartBeatCheck(){this.intervalTimer=setInterval(()=>pe(this,null,function*(){let r={msgType:`${Ee.MAGIC_PING}-${this.parameters}`,payload:[]};yield this._post(r),Date.now()-this.lastPingTime>Ta&&(yield this.reloadIframe(),this.lastPingTime=Date.now())}),Ma)}startHeartBeat(){return pe(this,null,function*(){(yield this.iframe)&&(this.timeoutTimer=setTimeout(()=>this.heartBeatCheck(),Na))})}stopHeartBeat(){this.timeoutTimer&&(clearTimeout(this.timeoutTimer),this.timeoutTimer=null),this.intervalTimer&&(clearInterval(this.intervalTimer),this.intervalTimer=null)}reloadIframe(){return pe(this,null,function*(){let r=yield this.iframe;if(r)r.src="",r.src=this.getIframeSrc();else throw _t()})}};var Oa=Object.assign(on(Kt,{platform:"web",sdkName:"magic-sdk",version:"28.12.0",defaultEndpoint:"https://auth.magic.link/",ViewController:bt,configureStorage:()=>pe(void 0,null,function*(){let e=Rt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Xt),yield e.setDriver([Rt.default.INDEXEDDB,Rt.default.LOCALSTORAGE,Xt._driver]),e})}),yr({},Ht)),La=Oa;return Ti(Ca);})();
5
+ Received: \`${e.received}\``)}function an(){return new Pe(ye.DuplicateIframe,"Duplicate iframes found.")}function ko(){return new Pe(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 Bo(){return new Pe(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 \`${Y.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function Ze(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],s=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${s}`;return new Pe(ye.DeprecationNotice,m)}function*Wo(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Go=Wo();function sn(){return Go.next().value}var ln=Symbol("Payload pre-processed by Magic SDK");function cn(e){return Object.defineProperty(e,ln,{value:!0,enumerable:!1}),e}function jo(e){return!!e[ln]}function gt(e){var t,r,o;return jo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=sn(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],cn(e)),e}function B(e,t=[]){return cn({params:t,method:e,jsonrpc:"2.0",id:sn()})}var kt=class{constructor(e){e instanceof kt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):Lo(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}}},Vo=Fi(ki()),qo=class extends Vo.default{};function un(){let e=new qo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var fn=Symbol("isPromiEvent");function Bt(e){return!!e[fn]}function rt(e){let t=dn(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=un(),a=Symbol("Promise.then"),s=Symbol("Promise.catch"),m=Symbol("Promise.finally"),d=(y,M)=>(..._)=>{let T=M[y].apply(M,_);return g(T)},g=y=>Object.assign(y,{[fn]:!0,[a]:y[a]||y.then,[s]:y[s]||y.catch,[m]:y[m]||y.finally,then:d(a,y),catch:d(s,y),finally:d(m,y),on:o("on",y),once:o("once",y),addListener:o("addListener",y),off:o("off",y),removeListener:o("removeListener",y),removeAllListeners:o("removeAllListeners",y),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),v=g(t.then(y=>(v.emit("done",y),v.emit("settled"),y),y=>{throw v.emit("error",y),v.emit("settled"),y}));return v.on(lt.ClosedByUser,()=>{v.emit(st.ClosedByUser)}),v}function dn(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var $e=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Ee.MAGIC_HANDLE_REQUEST,gt(e)),r=rt((a,s)=>{t.then(m=>{if(o(),m.hasError)s(new Ge(m.payload.error));else if(m.hasResult)a(m.payload.result);else throw Do()}).catch(m=>{o(),s(m)})}),o=this.overlay.on(de.MAGIC_HANDLE_EVENT,a=>{var s;let{response:m}=a.data;if(m.id===e.id&&((s=m.result)==null?void 0:s.event)){let{event:d,params:g=[]}=m.result;r.emit(d,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=B(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Ko(e,t){let[r]=e.split(".").map(Number);return r>=t}var et={"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"},Ho=class extends $e{loginWithMagicLink(e){let t=Y.sdkName==="@magic-sdk/react-native"||Y.sdkName==="@magic-sdk/react-native-bare"||Y.sdkName==="@magic-sdk/react-native-expo";if(t&&Ko(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&Ze({method:"auth.loginWithMagicLink()",removalVersions:et,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:s,lifespan:m}=e,d=B(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s,lifespan:m}]);return this.request(d)}loginWithSMS(e){let{phoneNumber:t,showUI:r=!0,lifespan:o}=e,a=B(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:r,lifespan:o}]),s=this.request(a);return!r&&s&&(s.on(Oe.VerifySmsOtp,m=>{this.createIntermediaryEvent(Oe.VerifySmsOtp,a.id)(m)}),s.on(Oe.Cancel,()=>{this.createIntermediaryEvent(Oe.Cancel,a.id)()})),s}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a,lifespan:s}=e,m=B(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a,lifespan:s}]),d=this.request(m);return!o&&d&&d.on(Xe.Retry,()=>{this.createIntermediaryEvent(Xe.Retry,m.id)()}),!r&&d&&(d.on(_e.VerifyEmailOtp,g=>{this.createIntermediaryEvent(_e.VerifyEmailOtp,m.id)(g)}),d.on(_e.VerifyMFACode,g=>{this.createIntermediaryEvent(_e.VerifyMFACode,m.id)(g)}),d.on(_e.Cancel,()=>{this.createIntermediaryEvent(_e.Cancel,m.id)()})),d}loginWithCredential(e){let{credentialOrQueryString:t,lifespan:r}=e||{},o=t!=null?t:"";if(!t&&Y.platform==="web"){o=window.location.search;let s=window.location.origin+window.location.pathname;window.history.replaceState(null,"",s)}let a=B(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[o,r]);return this.request(a)}setAuthorizationToken(e){let t=B(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(me.Retry,()=>{this.createIntermediaryEvent(me.Retry,o.id)()}),a.on(me.Cancel,()=>{this.createIntermediaryEvent(me.Cancel,o.id)()}),a.on(me.VerifyEmailOtp,s=>{this.createIntermediaryEvent(me.VerifyEmailOtp,o.id)(s)}),a.on(me.VerifyMFACode,s=>{this.createIntermediaryEvent(me.VerifyMFACode,o.id)(s)}),a.on(Ie.RetryWithNewEmail,s=>{this.createIntermediaryEvent(Ie.RetryWithNewEmail,o.id)(s)}),a.on(Ie.Cancel,()=>{this.createIntermediaryEvent(Ie.Cancel,o.id)()}),a.on(Ie.VerifyEmailOtp,s=>{this.createIntermediaryEvent(Ie.VerifyEmailOtp,o.id)(s)})),a}},hn={};Ui(hn,{clear:()=>Yo,getItem:()=>se,iterate:()=>mn,key:()=>zo,keys:()=>Jo,length:()=>Xo,removeItem:()=>We,setItem:()=>ve});var dt;function Te(e){return(...t)=>X(this,null,function*(){return dt||(dt=yield Y.configureStorage()),yield dt.ready(),dt[e](...t)})}var se=Te("getItem"),ve=Te("setItem"),We=Te("removeItem"),Yo=Te("clear"),Xo=Te("length"),zo=Te("key"),Jo=Te("keys"),mn=Te("iterate");function Qo(){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 pn="STORE_KEY_PRIVATE_KEY",Dt="STORE_KEY_PUBLIC_JWK",vn="ECDSA",Zo="P-256",ea={name:vn,namedCurve:Zo};function It(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function ta(){return X(this,null,function*(){let e=yield ra();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield se(pn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Qo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:Jr(JSON.stringify(a)),claims:Jr(JSON.stringify(o))},m=ia(`${s.protected}.${s.claims}`),d={name:vn,hash:{name:"SHA-256"}},g=aa(new Uint8Array(yield t.sign(d,r,m)));return`${s.protected}.${s.claims}.${g}`})}function ra(){return X(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}return(yield se(Dt))||(yield na()),se(Dt)})}function na(){return X(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(ea,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield ve(pn,t.privateKey),yield ve(Dt,r)})}function Jr(e){return gn(oa(e))}function ia(e){return new TextEncoder().encode(e)}function gn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function oa(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function aa(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),gn(t)}var Wt="ds",Gt="ek",jt="iv",Vt="AES-GCM",sa=256;function qt(){return X(this,null,function*(){let e=[];yield mn((t,r,o)=>{r.startsWith(`${Wt}_`)&&e.push(r)});for(let t of e)yield We(t)})}function yn(e){let t="",r=new Uint8Array(e),o=r.byteLength;for(let a=0;a<o;a++)t+=String.fromCharCode(r[a]);return window.btoa(t)}function En(e){let t=window.atob(e),r=t.length,o=new Uint8Array(r);for(let a=0;a<r;a++)o[a]=t.charCodeAt(a);return o.buffer}function la(){return X(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield se(jt))||e.getRandomValues(new Uint8Array(12))})}function ca(){return X(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield se(Gt))||(yield e.generateKey({name:Vt,length:sa},!1,["encrypt","decrypt"]))})}function ua(e,t){return X(this,null,function*(){let r=yield la(),o=yield ca();if(!r||!o||!e)return;let a=En(e),{subtle:s}=window.crypto,m=yield s.encrypt({name:Vt,iv:r},o,a),d=yn(m);yield ve(`${Wt}_${t}`,d),yield ve(Gt,o),yield ve(jt,r)})}function fa(e){return X(this,null,function*(){let t=yield se(`${Wt}_${e}`),r=yield se(jt),o=yield se(Gt);if(!r||!t||!o||!It())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:Vt,iv:r},o,En(t));return yn(s)})}function nt(e,t){return t?new URL(e,t):new URL(e)}var da=class extends $e{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=B(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=B(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return X(this,null,function*(){let e=yield se(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){return rt((e,t)=>X(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield se(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=B(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?ve(this.localForageIsLoggedInKey,!0):We(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return We(this.localForageKey),We(this.localForageIsLoggedInKey),qt(),rt((e,t)=>X(this,null,function*(){try{let r=B(this.sdk.testMode?O.LogoutTestMode:O.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=B(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=B(this.sdk.testMode?O.RecoverAccountTestMode:O.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=B(O.RevealPK);return this.request(e)}getMetadata(){Ze({method:"user.getMetadata()",removalVersions:et,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}enableMFA(e){let{showUI:t=!0}=e,r=B(O.EnableMFA,[{showUI:t}]),o=this.request(r);return!t&&o&&(o.on(Le.VerifyMFACode,a=>{this.createIntermediaryEvent(Le.VerifyMFACode,r.id)(a)}),o.on(Le.Cancel,()=>{this.createIntermediaryEvent(Le.Cancel,r.id)()})),o}disableMFA(e){let{showUI:t=!0}=e,r=B(O.DisableMFA,[{showUI:t}]),o=this.request(r);return!t&&o&&(o.on(we.VerifyMFACode,a=>{this.createIntermediaryEvent(we.VerifyMFACode,r.id)(a)}),o.on(we.LostDevice,a=>{this.createIntermediaryEvent(we.LostDevice,r.id)(a)}),o.on(we.Cancel,()=>{this.createIntermediaryEvent(we.Cancel,r.id)()})),o}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},ha=class extends $e{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=rt((t,r)=>X(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ue.MetaMask))){let d=yield this.autoConnectIfWalletBrowser(ue.MetaMask);t(d);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ue.CoinbaseWallet))){let d=yield this.autoConnectIfWalletBrowser(ue.CoinbaseWallet);t(d);return}let o=this.getUserEnv(),a=B(O.Login,[o]),s=this.request(a);s.on(Fe.WalletSelected,d=>this.handleWalletSelected(xt(Ut({},d),{payloadId:a.id}))),s.on("id-token-created",d=>{e.emit("id-token-created",d)});let m=yield s;m.error&&r(m),t(m)}catch(o){r(o)}}));return e}showUI(e){return this.request(B(O.ShowUI,[e]))}showAddress(){return this.request(B(O.ShowAddress))}showSendTokensUI(){return this.request(B(O.ShowSendTokensUI))}showOnRamp(){return this.request(B(O.ShowOnRamp))}showNFTs(){return this.request(B(O.ShowNFTs))}showBalances(){return this.request(B(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(B(O.SendGaslessTransaction,[e,t]))}getInfo(){return X(this,null,function*(){Ze({method:"wallet.getInfo()",removalVersions:et,useInstead:"user.getInfo()"}).log();let e=yield se(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){Ze({method:"wallet.disconnect()",removalVersions:et,useInstead:"user.logout()"}).log(),We(this.localForageKey),qt();let e=B(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){Ze({method:"wallet.requestUserInfoWithUI()",removalVersions:et,useInstead:"user.requestUserInfoWithUI()"}).log();let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return X(this,null,function*(){switch(yield se(this.localForageKey)){case ue.MetaMask:return this.getMetaMaskProvider();case ue.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(o=>o==null?void 0:o.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(o=>o==null?void 0:o.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 ue.MetaMask:return this.connectToMetaMask();case ue.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=B("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return X(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield ve(this.localForageKey,e.wallet),this.createIntermediaryEvent(Fe.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Fe.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return X(this,null,function*(){let t;e===ue.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ue.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield ve(this.localForageKey,e);let r=B(O.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:ht,createChainingEmitterMethod:ke}=un(),ma=class extends $e{constructor(){super(...arguments),this.isMagic=!0,this.on=ke("on",this),this.once=ke("once",this),this.addListener=ke("addListener",this),this.off=ke("off",this),this.removeListener=ke("removeListener",this),this.removeAllListeners=ke("removeAllListeners",this),this.emit=ht("emit"),this.eventNames=ht("eventNames"),this.listeners=ht("listeners"),this.listenerCount=ht("listenerCount")}sendAsync(e,t){if(!t)throw Fo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Ee.MAGIC_HANDLE_REQUEST,e.map(r=>{let o=gt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>xt(Ut({},o.payload),{error:o.hasError?new Ge(o.payload.error):null})))});else{let r=gt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Ee.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Ge(o.payload.error):null,o.payload)})}}send(e,t){if(typeof e=="string"){let o=B(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=ko();return r.log(),new kt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=B(O.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}`)}},Qr=["request","overlay","sdk"];function pa(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==$e.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var _n=class extends $e{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:rt,isPromiEvent:Bt,encodeJSON:rn,decodeJSON:No,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:gt,storage:hn};let e=[this,...pa(this)];Qr.forEach(t=>{let r=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=r.findIndex(m=>!!m),a=o>0,s=r[o];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Uo(t)}}))})}init(e){this.__is_initialized__||(Qr.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new vt(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new vt(this,e,t)}createError(e,t,r){return new Et(this,e,t,r)}},va=class extends _n{},Ce=class extends _n{};Ce.Internal=va,Ce.Anonymous="anonymous extension";var ga=class extends $e{purchase(e){let t=B(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=B(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=B(O.NFTTransfer,[e]);return this.request(t)}};function Zr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?_o(Ro(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function ya(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 Ea(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(s=>{Zr(s)?(s.init(this),(s.name||s.name!==Ce.Anonymous)&&(this[s.name]=s),s instanceof Ce.Internal&&(pt(s.config)||(o[s.name]=s.config))):a.push(s)}):Object.keys(r).forEach(s=>{if(Zr(r[s])){r[s].init(this);let m=r[s];this[s]=m,m instanceof Ce.Internal&&(pt(m.config)||(o[r[s].name]=m.config))}else a.push(r[s])}),a.length)throw xo(a);return o}var mt=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw $o();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Bo().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=nt((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new Ho(this),this.user=new da(this),this.wallet=new ha(this),this.nft=new ga(this),this.rpcProvider=new ma(this);let s=Ea.call(this,t);this.parameters=rn(xt(Ut({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:nt(this.endpoint).host,sdk:Po[Y.sdkName],version:a,ext:pt(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=ya(this.apiKey,t==null?void 0:t.network,pt(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!mt.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),mt.__overlays__.set(this.parameters,e)}return mt.__overlays__.get(this.parameters)}preload(){return X(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Kt=mt;Kt.__overlays__=new Map;function _a(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function Ia(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=_a(e,o);if(o&&a){let s=new kt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function wa(e,t,r){return X(this,null,function*(){var o;let a=yield se("rt"),s;if(Y.platform==="web")try{s=(o=yield se("jwt"))!=null?o:yield ta()}catch(g){console.error("webcrypto error",g)}let m={msgType:e,payload:t};s&&(m.jwt=s),s&&a&&(m.rt=a);let d=yield fa(r);return d&&(m.deviceShare=d),m})}function ba(e){return X(this,null,function*(){!e.data.rt||(yield ve("rt",e.data.rt))})}var In=class{constructor(e,t,r){this.endpoint=e,this.parameters=t,this.networkHash=r,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return X(this,null,function*(){return dn((r,o)=>X(this,null,function*(){if(!this.isConnectedToInternet){let v=_t();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],m=yield wa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(m);let d=v=>y=>{var M;let{id:_,response:T}=Ia(t,y);if(ba(y),((M=T==null?void 0:T.payload.error)==null?void 0:M.message)==="User denied account access.")qt();else if(y.data.deviceShare){let{deviceShare:L}=y.data;ua(L,this.networkHash)}_&&T&&Array.isArray(t)&&s.includes(_)?(a.push(T),a.length===t.length&&(v(),r(a))):_&&T&&!Array.isArray(t)&&_===t.id&&(v(),r(T))},g=this.on(de.MAGIC_HANDLE_RESPONSE,d(()=>g()))}))})}on(e,t){let r=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&r(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{let t=this.on(de.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()});setTimeout(()=>{this.isReadyForRequest=!0,e(),t()},15e3)})}listen(){this.on(de.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(de.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(de.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Pe(ye.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Ht={};_r(Ht,{AuthEventOnReceived:()=>Lr,DeepLinkPage:()=>br,DeviceVerificationEventEmit:()=>Xe,DeviceVerificationEventOnReceived:()=>Mr,DisableMFAEventEmit:()=>we,DisableMFAEventOnReceived:()=>$r,EnableMFAEventEmit:()=>Le,EnableMFAEventOnReceived:()=>Pr,EthChainType:()=>Dr,Events:()=>Fe,Extension:()=>Ce,ExtensionError:()=>Et,ExtensionWarning:()=>vt,FarcasterLoginEventEmit:()=>Cr,LoginWithEmailOTPEventEmit:()=>_e,LoginWithEmailOTPEventOnReceived:()=>Tr,LoginWithMagicLinkEventEmit:()=>Rr,LoginWithMagicLinkEventOnReceived:()=>Ar,LoginWithSmsOTPEventEmit:()=>Oe,LoginWithSmsOTPEventOnReceived:()=>Sr,MagicIncomingWindowMessage:()=>de,MagicOutgoingWindowMessage:()=>Ee,MagicPayloadMethod:()=>O,NftCheckoutIntermediaryEvents:()=>xr,RPCError:()=>Ge,RPCErrorCode:()=>xe,RecencyCheckEventEmit:()=>me,RecencyCheckEventOnReceived:()=>Nr,RecoveryMethodType:()=>Ur,SDKError:()=>be,SDKErrorCode:()=>ge,SDKWarning:()=>Pe,SDKWarningCode:()=>ye,UiEventsEmit:()=>kr,UpdateEmailEventEmit:()=>Ie,UpdateEmailEventOnReceived:()=>Or,UserEventsEmit:()=>st,UserEventsOnReceived:()=>lt,WalletEventOnReceived:()=>Fr,Wallets:()=>ue,isPromiEvent:()=>Bt});var Rt=wr(bn()),Xt=wr(An());var Ra={display:"block",visibility:"hidden",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647",opacity:"0"};function Aa(e){for(let[t,r]of Object.entries(Ra))e.style[t]=r}function Sa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var Sn=1e3,Tn=60*Sn,Ta=15*Sn,Ma=2*Tn,Na=60*Tn,bt=class extends In{constructor(){super(...arguments);this.activeElement=null;this.lastPingTime=Date.now();this.intervalTimer=null;this.timeoutTimer=null}getIframeSrc(){return nt(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(Sa(encodeURIComponent(this.parameters)))an().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=nt(this.endpoint).host,a.title="Secure Modal",a.src=this.getIframeSrc(),a.allow="clipboard-read; clipboard-write",Aa(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),this.iframe.then(r=>{r instanceof HTMLIFrameElement&&r.addEventListener("load",()=>pe(this,null,function*(){yield this.startHeartBeat()}))}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.msgType.includes(de.MAGIC_PONG)&&(this.lastPingTime=Date.now()),r.data.response=(o=r.data.response)!=null?o:{};for(let s of this.messageHandlers.values())s(r)}}),window.addEventListener("beforeunload",()=>{this.stopHeartBeat()})}showOverlay(){return pe(this,null,function*(){let r=yield this.iframe;r.style.visibility="visible",r.style.opacity="1",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return pe(this,null,function*(){var o;let r=yield this.iframe;r.style.visibility="hidden",r.style.opacity="0",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return pe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw _t()})}heartBeatCheck(){this.intervalTimer=setInterval(()=>pe(this,null,function*(){let r={msgType:`${Ee.MAGIC_PING}-${this.parameters}`,payload:[]};yield this._post(r),Date.now()-this.lastPingTime>Ta&&(yield this.reloadIframe(),this.lastPingTime=Date.now())}),Ma)}startHeartBeat(){return pe(this,null,function*(){(yield this.iframe)&&(this.timeoutTimer=setTimeout(()=>this.heartBeatCheck(),Na))})}stopHeartBeat(){this.timeoutTimer&&(clearTimeout(this.timeoutTimer),this.timeoutTimer=null),this.intervalTimer&&(clearInterval(this.intervalTimer),this.intervalTimer=null)}reloadIframe(){return pe(this,null,function*(){let r=yield this.iframe;if(r)r.src=this.getIframeSrc();else throw _t()})}};var Oa=Object.assign(on(Kt,{platform:"web",sdkName:"magic-sdk",version:"28.12.0",defaultEndpoint:"https://auth.magic.link/",ViewController:bt,configureStorage:()=>pe(void 0,null,function*(){let e=Rt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Xt),yield e.setDriver([Rt.default.INDEXEDDB,Rt.default.LOCALSTORAGE,Xt._driver]),e})}),yr({},Ht)),La=Oa;return Ti(Ca);})();
6
6
  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.13.0-canary.816.11344317837.0",
3
+ "version": "28.13.0-canary.816.11362588320.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.13.0-canary.816.11344317837.0",
33
- "@magic-sdk/provider": "28.13.0-canary.816.11344317837.0",
32
+ "@magic-sdk/commons": "^24.12.0",
33
+ "@magic-sdk/provider": "^28.12.0",
34
34
  "@magic-sdk/types": "^24.10.0",
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": "a9b681d3ce298d407773569026626971db86efd9"
43
+ "gitHead": "a03b8f93442ba87cc52c0e0a79b53a8debe8c6c7"
44
44
  }