magic-sdk 29.0.2-canary.863.14002899530.0 → 29.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/es/index.js +1 -1
- package/dist/es/index.js.map +2 -2
- package/dist/es/index.mjs +1 -1
- package/dist/es/index.mjs.map +2 -2
- package/dist/magic.js +1 -1
- package/package.json +5 -5
package/dist/magic.js
CHANGED
@@ -2,5 +2,5 @@
|
|
2
2
|
- Extension \`${r.name}\` supports version(s) \`${i}\``:i||(t+=`
|
3
3
|
- Extension \`${r.name}\` does not support ${Y.platform} environments.`)}),new we(Ee.IncompatibleExtensions,t)}function Go(e){let t=r=>{let i=r+1,o=i%10,s=i%100;return o===1&&s!==11?`${i}st`:o===2&&s!==12?`${i}nd`:o===3&&s!==13?`${i}rd`:`${i}th`};return new we(Ee.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
4
4
|
Expected: \`${e.expected}\`
|
5
|
-
Received: \`${e.received}\``)}function ln(){return new Fe(be.DuplicateIframe,"Duplicate iframes found.")}function Vo(){return new Fe(be.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 jo(){return new Fe(be.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 Ho(e){let{method:t,removalVersions:r,useInstead:i}=e,o=r[Y.sdkName],s=i?` Use \`${i}\` instead.`:"",m=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${o}\`.${s}`;return new Fe(be.DeprecationNotice,m)}function*qo(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Ko=qo();function un(){return Ko.next().value}var dn=Symbol("Payload pre-processed by Magic SDK");function fn(e){return Object.defineProperty(e,dn,{value:!0,enumerable:!1}),e}function Yo(e){return!!e[dn]}function pt(e){var t,r,i;return Yo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=un(),e.method=(r=e.method)!=null?r:"noop",e.params=(i=e.params)!=null?i:[],fn(e)),e}function G(e,t=[]){return fn({params:t,method:e,jsonrpc:"2.0",id:un()})}var Wt=class{constructor(e){e instanceof Wt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):$o(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}}},Xo=Gi(Vi()),zo=class extends Xo.default{};function hn(){let e=new zo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...i)=>(e[t].apply(e,i),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var mn=Symbol("isPromiEvent");function Bt(e){return!!e[mn]}function Ie(e){let t=vn(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:i}=hn(),o=Symbol("Promise.then"),s=Symbol("Promise.catch"),m=Symbol("Promise.finally"),f=(g,N)=>(..._)=>{let O=N[g].apply(N,_);return p(O)},p=g=>Object.assign(g,{[mn]:!0,[o]:g[o]||g.then,[s]:g[s]||g.catch,[m]:g[m]||g.finally,then:f(o,g),catch:f(s,g),finally:f(m,g),on:i("on",g),once:i("once",g),addListener:i("addListener",g),off:i("off",g),removeListener:i("removeListener",g),removeAllListeners:i("removeAllListeners",g),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),y=p(t.then(g=>(y.emit("done",g),y.emit("settled"),g),g=>{throw y.emit("error",g),y.emit("settled"),g}));return y.on(st.ClosedByUser,()=>{y.emit(at.ClosedByUser)}),y}function vn(e){return new Promise((t,r)=>{let i=e(t,r);Promise.resolve(i).catch(r)})}var Le=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){if(this.sdk.thirdPartyWallets.isConnected&&!Dt.includes(e.method))return Ie((o,s)=>{this.sdk.thirdPartyWallets.requestOverride(e).then(o).catch(s)});let t=this.overlay.post(Re.MAGIC_HANDLE_REQUEST,pt(e)),r=Ie((o,s)=>{t.then(m=>{if(i(),m.hasError)s(new je(m.payload.error));else if(m.hasResult)o(m.payload.result);else throw ko()}).catch(m=>{i(),s(m)})}),i=this.overlay.on(he.MAGIC_HANDLE_EVENT,o=>{var s;let{response:m}=o.data;if(m.id===e.id&&((s=m.result)==null?void 0:s.event)){let{event:f,params:p=[]}=m.result;r.emit(f,...p)}});return r}createIntermediaryEvent(e,t){return r=>{let i=G(L.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(i)}}};function Jo(e,t){let[r]=e.split(".").map(Number);return r>=t}var Qo={"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"},Zo=class extends Le{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&&Jo(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&Ho({method:"auth.loginWithMagicLink()",removalVersions:Qo,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:i=!0,redirectURI:o,overrides:s,lifespan:m}=e,f=G(this.sdk.testMode?L.LoginWithMagicLinkTestMode:L.LoginWithMagicLink,[{email:r,showUI:i,redirectURI:o,overrides:s,lifespan:m}]);return this.request(f)}loginWithSMS(e){let{phoneNumber:t,showUI:r=!0,lifespan:i}=e,o=G(this.sdk.testMode?L.LoginWithSmsTestMode:L.LoginWithSms,[{phoneNumber:t,showUI:r,lifespan:i}]),s=this.request(o);return!r&&s&&(s.on(De.VerifySmsOtp,m=>{this.createIntermediaryEvent(De.VerifySmsOtp,o.id)(m)}),s.on(De.Cancel,()=>{this.createIntermediaryEvent(De.Cancel,o.id)()})),s}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:i,overrides:o,lifespan:s}=e,m=G(this.sdk.testMode?L.LoginWithEmailOTPTestMode:L.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:i,overrides:o,lifespan:s}]),f=this.request(m);return!i&&f&&f.on(Je.Retry,()=>{this.createIntermediaryEvent(Je.Retry,m.id)()}),!r&&f&&(f.on(de.VerifyEmailOtp,p=>{this.createIntermediaryEvent(de.VerifyEmailOtp,m.id)(p)}),f.on(de.VerifyMFACode,p=>{this.createIntermediaryEvent(de.VerifyMFACode,m.id)(p)}),f.on(de.LostDevice,()=>{this.createIntermediaryEvent(de.LostDevice,m.id)()}),f.on(de.VerifyRecoveryCode,p=>{this.createIntermediaryEvent(de.VerifyRecoveryCode,m.id)(p)}),f.on(de.Cancel,()=>{this.createIntermediaryEvent(de.Cancel,m.id)()})),f}loginWithCredential(e){let{credentialOrQueryString:t,lifespan:r}=e||{},i=t!=null?t:"";if(!t&&Y.platform==="web"){i=window.location.search;let s=window.location.origin+window.location.pathname;window.history.replaceState(null,"",s)}let o=G(this.sdk.testMode?L.LoginWithCredentialTestMode:L.LoginWithCredential,[i,r]);return this.request(o)}setAuthorizationToken(e){let t=G(L.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,i=G(this.sdk.testMode?L.UpdateEmailTestMode:L.UpdateEmail,[{email:t,showUI:r}]),o=this.request(i);return r||(o.on(ue.Retry,()=>{this.createIntermediaryEvent(ue.Retry,i.id)()}),o.on(ue.Cancel,()=>{this.createIntermediaryEvent(ue.Cancel,i.id)()}),o.on(ue.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ue.VerifyEmailOtp,i.id)(s)}),o.on(ue.VerifyMFACode,s=>{this.createIntermediaryEvent(ue.VerifyMFACode,i.id)(s)}),o.on(ne.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ne.RetryWithNewEmail,i.id)(s)}),o.on(ne.Cancel,()=>{this.createIntermediaryEvent(ne.Cancel,i.id)()}),o.on(ne.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ne.VerifyEmailOtp,i.id)(s)})),o}},pn={};Wi(pn,{clear:()=>ea,getItem:()=>me,iterate:()=>yn,key:()=>ra,keys:()=>na,length:()=>ta,removeItem:()=>yt,setItem:()=>Te});var dt;function Me(e){return(...t)=>Z(this,null,function*(){return dt||(dt=yield Y.configureStorage()),yield dt.ready(),dt[e](...t)})}var me=Me("getItem"),Te=Me("setItem"),yt=Me("removeItem"),ea=Me("clear"),ta=Me("length"),ra=Me("key"),na=Me("keys"),yn=Me("iterate");function ia(){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 gn="STORE_KEY_PRIVATE_KEY",Ut="STORE_KEY_PUBLIC_JWK",En="ECDSA",oa="P-256",aa={name:En,namedCurve:oa};function It(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function sa(){return Z(this,null,function*(){let e=yield ca();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield me(gn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let i={iat:Math.floor(new Date().getTime()/1e3),jti:ia()},o={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:Zr(JSON.stringify(o)),claims:Zr(JSON.stringify(i))},m=ua(`${s.protected}.${s.claims}`),f={name:En,hash:{name:"SHA-256"}},p=fa(new Uint8Array(yield t.sign(f,r,m)));return`${s.protected}.${s.claims}.${p}`})}function ca(){return Z(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}return(yield me(Ut))||(yield la()),me(Ut)})}function la(){return Z(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(aa,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield Te(gn,t.privateKey),yield Te(Ut,r)})}function Zr(e){return _n(da(e))}function ua(e){return new TextEncoder().encode(e)}function _n(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function da(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function fa(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),_n(t)}var Gt="ds",Vt="ek",jt="iv",Ht="AES-GCM",ha=256;function In(){return Z(this,null,function*(){let e=[];yield yn((t,r,i)=>{r.startsWith(`${Gt}_`)&&e.push(r)});for(let t of e)yield yt(t)})}function wn(e){let t="",r=new Uint8Array(e),i=r.byteLength;for(let o=0;o<i;o++)t+=String.fromCharCode(r[o]);return window.btoa(t)}function bn(e){let t=window.atob(e),r=t.length,i=new Uint8Array(r);for(let o=0;o<r;o++)i[o]=t.charCodeAt(o);return i.buffer}function ma(){return Z(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield me(jt))||e.getRandomValues(new Uint8Array(12))})}function va(){return Z(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield me(Vt))||(yield e.generateKey({name:Ht,length:ha},!1,["encrypt","decrypt"]))})}function pa(e,t){return Z(this,null,function*(){let r=yield ma(),i=yield va();if(!r||!i||!e)return;let o=bn(e),{subtle:s}=window.crypto,m=yield s.encrypt({name:Ht,iv:r},i,o),f=wn(m);yield Te(`${Gt}_${t}`,f),yield Te(Vt,i),yield Te(jt,r)})}function ya(e){return Z(this,null,function*(){let t=yield me(`${Gt}_${e}`),r=yield me(jt),i=yield me(Vt);if(!r||!t||!i||!It())return;let{subtle:o}=window.crypto,s=yield o.decrypt({name:Ht,iv:r},i,bn(t));return wn(s)})}function rt(e,t){return t?new URL(e,t):new URL(e)}var ga=class extends Le{constructor(){super(...arguments),this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=G(this.sdk.testMode?L.GetIdTokenTestMode:L.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=G(this.sdk.testMode?L.GenerateIdTokenTestMode:L.GenerateIdToken,[e]);return this.request(t)}getInfo(){let e=G(L.GetInfo,[]);return this.request(e)}isLoggedIn(){return Ie((e,t)=>Z(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield me(this.localForageIsLoggedInKey))==="true",r&&e(!0));let i=G(this.sdk.testMode?L.IsLoggedInTestMode:L.IsLoggedIn),o=yield this.request(i);this.sdk.useStorageCache&&(o?Te(this.localForageIsLoggedInKey,!0):yt(this.localForageIsLoggedInKey),r&&!o&&this.emitUserLoggedOut(!0)),e(o)}catch(r){t(r)}}))}logout(){return yt(this.localForageIsLoggedInKey),In(),Ie((e,t)=>Z(this,null,function*(){try{let r=G(this.sdk.testMode?L.LogoutTestMode:L.Logout),i=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(i),e(i)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=G(L.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let{showUI:t=!0}=e||{},r=G(this.sdk.testMode?L.UserSettingsTestMode:L.UserSettings,[e]),i=this.request(r);return!t&&i&&(i.on(ye.SendNewPhoneNumber,o=>{this.createIntermediaryEvent(ye.SendNewPhoneNumber,r.id)(o)}),i.on(ye.SendOtpCode,o=>{this.createIntermediaryEvent(ye.SendOtpCode,r.id)(o)}),i.on(ye.StartEditPhoneNumber,()=>{this.createIntermediaryEvent(ye.StartEditPhoneNumber,r.id)()}),i.on(ye.Cancel,()=>{this.createIntermediaryEvent(ye.Cancel,r.id)()}),i.on(ue.VerifyEmailOtp,o=>{this.createIntermediaryEvent(ue.VerifyEmailOtp,r.id)(o)})),i}recoverAccount(e){let{email:t,showUI:r}=e,i=G(this.sdk.testMode?L.RecoverAccountTestMode:L.RecoverAccount,[{email:t,showUI:r}]),o=this.request(i);return!r&&o&&(o.on(ge.Cancel,()=>{this.createIntermediaryEvent(ge.Cancel,i.id)()}),o.on(ge.ResendSms,()=>{this.createIntermediaryEvent(ge.ResendSms,i.id)()}),o.on(ge.VerifyOtp,s=>{this.createIntermediaryEvent(ge.VerifyOtp,i.id)(s)}),o.on(ge.UpdateEmail,s=>{this.createIntermediaryEvent(ge.UpdateEmail,i.id)(s)}),o.on(ne.Cancel,()=>{this.createIntermediaryEvent(ne.Cancel,i.id)()}),o.on(ne.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ne.RetryWithNewEmail,i.id)(s)}),o.on(ne.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ne.VerifyEmailOtp,i.id)(s)})),o}revealPrivateKey(){let e=G(L.RevealPK);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}enableMFA(e){let{showUI:t=!0}=e,r=G(L.EnableMFA,[{showUI:t}]),i=this.request(r);return!t&&i&&(i.on($e.VerifyMFACode,o=>{this.createIntermediaryEvent($e.VerifyMFACode,r.id)(o)}),i.on($e.Cancel,()=>{this.createIntermediaryEvent($e.Cancel,r.id)()})),i}disableMFA(e){let{showUI:t=!0}=e,r=G(L.DisableMFA,[{showUI:t}]),i=this.request(r);return!t&&i&&(i.on(Se.VerifyMFACode,o=>{this.createIntermediaryEvent(Se.VerifyMFACode,r.id)(o)}),i.on(Se.LostDevice,o=>{this.createIntermediaryEvent(Se.LostDevice,r.id)(o)}),i.on(Se.Cancel,()=>{this.createIntermediaryEvent(Se.Cancel,r.id)()})),i}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Ea=class extends Le{connectWithUI(e){let t=Ie((r,i)=>Z(this,null,function*(){try{let o=G(L.Login,[Et({enabledWallets:this.sdk.thirdPartyWallets.enabledWallets},e)]),s=this.request(o);this.sdk.thirdPartyWallets.eventListeners.forEach(({event:f,callback:p})=>{s.on(f,()=>p(o.id))}),s.on("id-token-created",f=>{t.emit("id-token-created",f)});let m=yield s;m.error&&i(m),r(m)}catch(o){i(o)}}));return t}showUI(e){return this.request(G(L.ShowUI,[e]))}showAddress(){return this.request(G(L.ShowAddress))}showSendTokensUI(){return this.request(G(L.ShowSendTokensUI))}showOnRamp(){return this.request(G(L.ShowOnRamp))}showNFTs(){return this.request(G(L.ShowNFTs))}showBalances(){return this.request(G(L.ShowBalances))}sendGaslessTransaction(e,t){return this.request(G(L.SendGaslessTransaction,[e,t]))}},_a=class extends Le{constructor(){super(...arguments),this.eventListeners=[],this.enabledWallets={},this.isConnected=!1}resetThirdPartyWalletState(){localStorage.removeItem(_e.PROVIDER),localStorage.removeItem(_e.ADDRESS),localStorage.removeItem(_e.CHAIN_ID),this.isConnected=!1}requestOverride(e){if(e.method===L.Login)return this.resetThirdPartyWalletState(),super.request(e);if(e.method===L.GetInfo)return this.getInfo(e);if(e.method===L.IsLoggedIn)return this.isLoggedIn(e);if(e.method===L.Logout)return this.logout(e);switch(localStorage.getItem(_e.PROVIDER)){case"web3modal":return this.web3modalRequest(e);default:return this.resetThirdPartyWalletState(),super.request(e)}}isLoggedIn(e){switch(localStorage.getItem(_e.PROVIDER)){case"web3modal":return this.web3modalIsLoggedIn();default:return this.resetThirdPartyWalletState(),super.request(e)}}getInfo(e){switch(localStorage.getItem(_e.PROVIDER)){case"web3modal":return this.web3modalGetInfo();default:return this.resetThirdPartyWalletState(),super.request(e)}}logout(e){let t=localStorage.getItem(_e.PROVIDER);switch(this.resetThirdPartyWalletState(),t){case"web3modal":return this.web3modalLogout();default:return super.request(e)}}web3modalRequest(e){return Ie((t,r)=>{this.sdk.web3modal.modal.getWalletProvider().request(e).then(t).catch(r)})}web3modalIsLoggedIn(){return Ie(e=>{let t=this.sdk.web3modal.modal.getStatus();if(t==="connected"&&e(!0),t==="disconnected"&&(this.resetThirdPartyWalletState(),e(!1)),t==="reconnecting"){let r=this.sdk.web3modal.modal.subscribeProvider(({status:i})=>{i==="connected"&&(r(),e(!0)),i==="disconnected"&&(r(),this.resetThirdPartyWalletState(),e(!1))})}})}formatWeb3modalGetInfoResponse(){var e;let t=(e=this.sdk.web3modal.modal.getWalletInfo())==null?void 0:e.name,r=this.sdk.web3modal.modal.getAddress();return{publicAddress:r,email:null,issuer:`did:ethr:${r}`,phoneNumber:null,isMfaEnabled:!1,recoveryFactors:[],walletType:t||"web3modal"}}web3modalGetInfo(){return Ie((e,t)=>{let r=this.sdk.web3modal.modal.getStatus();if(r==="connected"&&e(this.formatWeb3modalGetInfoResponse()),r==="disconnected"&&(this.resetThirdPartyWalletState(),t("Magic RPC Error: [-32603] Internal error: User denied account access.")),r==="reconnecting"){let i=this.sdk.web3modal.modal.subscribeProvider(({status:o})=>{o==="connected"&&(i(),e(this.formatWeb3modalGetInfoResponse())),o==="disconnected"&&(i(),this.resetThirdPartyWalletState(),t("Magic RPC Error: [-32603] Internal error: User denied account access."))})}})}web3modalLogout(){return Ie(e=>Z(this,null,function*(){try{yield this.sdk.web3modal.modal.disconnect()}catch(t){console.error(t)}e(!0)}))}},{createBoundEmitterMethod:ft,createChainingEmitterMethod:Ge}=hn(),Ia=class extends Le{constructor(){super(...arguments),this.isMagic=!0,this.on=Ge("on",this),this.once=Ge("once",this),this.addListener=Ge("addListener",this),this.off=Ge("off",this),this.removeListener=Ge("removeListener",this),this.removeAllListeners=Ge("removeAllListeners",this),this.emit=ft("emit"),this.eventNames=ft("eventNames"),this.listeners=ft("listeners"),this.listenerCount=ft("listenerCount")}sendAsync(e,t){if(!t)throw Go({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Re.MAGIC_HANDLE_REQUEST,e.map(r=>{let i=pt(r);return this.prefixPayloadMethodForTestMode(i),i})).then(r=>{t(null,r.map(i=>xt(Et({},i.payload),{error:i.hasError?new je(i.payload.error):null})))});else{let r=pt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Re.MAGIC_HANDLE_REQUEST,r).then(i=>{t(i.hasError?new je(i.payload.error):null,i.payload)})}}send(e,t){if(typeof e=="string"){let i=G(e,Array.isArray(t)?t:[]);return this.request(i)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=Vo();return r.log(),new Wt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=G(L.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}`)}},en=["request","overlay","sdk"];function wa(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Le.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var Rn=class extends Le{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Ie,isPromiEvent:Bt,encodeJSON:on,decodeJSON:Po,createJsonRpcRequestPayload:G,standardizeJsonRpcRequestPayload:pt,storage:pn};let e=[this,...wa(this)];en.forEach(t=>{let r=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),i=r.findIndex(m=>!!m),o=i>0,s=r[i];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:o}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Wo(t)}}))})}init(e){this.__is_initialized__||(en.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:i}=this.__sdk_access_field_descriptors__.get(t);i?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:i}=e,o=i?` Use \`${i}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${o}`;return new vt(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new vt(this,e,t)}createError(e,t,r){return new _t(this,e,t,r)}},ba=class extends Rn{},xe=class extends Rn{};xe.Internal=ba,xe.Anonymous="anonymous extension";var Ra=class extends Le{purchase(e){let t=G(L.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=this.sdk.thirdPartyWallets.isConnected,r=G(L.NFTCheckout,[xt(Et({},e),{walletProvider:t?"web3modal":"magic"})]),i=this.request(r);return t&&(i.on(Ue.Initiated,o=>Z(this,null,function*(){try{let s=yield this.request({method:"eth_sendTransaction",params:[o]});this.createIntermediaryEvent(Ue.Success,r.id)(s)}catch(s){this.createIntermediaryEvent(Ue.Failure,r.id)()}})),i.on(Ue.Disconnect,()=>{this.sdk.thirdPartyWallets.resetThirdPartyWalletState(),i.emit("disconnect")})),i}transfer(e){let t=G(L.NFTTransfer,[e]);return this.request(t)}};function tn(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?Ro(No(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function Sa(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 Aa(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],i={},o=[];if(Array.isArray(r)?r.forEach(s=>{tn(s)?(s.init(this),(s.name||s.name!==xe.Anonymous)&&(this[s.name]=s),s instanceof xe.Internal&&(mt(s.config)||(i[s.name]=s.config))):o.push(s)}):Object.keys(r).forEach(s=>{if(tn(r[s])){r[s].init(this);let m=r[s];this[s]=m,m instanceof xe.Internal&&(mt(m.config)||(i[r[s].name]=m.config))}else o.push(r[s])}),o.length)throw Bo(o);return i}var ht=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw Fo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&jo().log();let{defaultEndpoint:i,version:o}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=rt((r=t==null?void 0:t.endpoint)!=null?r:i).origin,this.auth=new Zo(this),this.user=new ga(this),this.wallet=new Ea(this),this.nft=new Ra(this),this.thirdPartyWallets=new _a(this),this.rpcProvider=new Ia(this);let s=Aa.call(this,t);this.parameters=on(xt(Et({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:rt(this.endpoint).host,sdk:xo[Y.sdkName],version:o,ext:mt(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=Sa(this.apiKey,t==null?void 0:t.network,mt(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!ht.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),ht.__overlays__.set(this.parameters,e)}return ht.__overlays__.get(this.parameters)}preload(){return Z(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},qt=ht;qt.__overlays__=new Map;function Oa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function Na(e,t){var r;let i=(r=t.data.response)==null?void 0:r.id,o=Oa(e,i);if(i&&o){let s=new Wt(o).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:i,response:s}}return{}}function Ta(e,t,r){return Z(this,null,function*(){var i;let o=yield me("rt"),s;if(Y.platform==="web")try{s=(i=yield me("jwt"))!=null?i:yield sa()}catch(p){console.error("webcrypto error",p)}let m={msgType:e,payload:t};s&&(m.jwt=s),s&&o&&(m.rt=o);let f=yield ya(r);return f&&(m.deviceShare=f),m})}function La(e){return Z(this,null,function*(){!e.data.rt||(yield Te("rt",e.data.rt))})}var Sn=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 Z(this,null,function*(){return vn((r,i)=>Z(this,null,function*(){if(!this.isConnectedToInternet){let y=kt();i(y)}this.isReadyForRequest||(yield this.waitForReady());let o=[],s=Array.isArray(t)?t.map(y=>y.id):[],m=yield Ta(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(m);let f=y=>g=>{var N;let{id:_,response:O}=Na(t,g);if(La(g),((N=O==null?void 0:O.payload.error)==null?void 0:N.message)==="User denied account access.")In();else if(g.data.deviceShare){let{deviceShare:M}=g.data;pa(M,this.networkHash)}_&&O&&Array.isArray(t)&&s.includes(_)?(o.push(O),o.length===t.length&&(y(),r(o))):_&&O&&!Array.isArray(t)&&_===t.id&&(y(),r(O))},p=this.on(he.MAGIC_HANDLE_RESPONSE,f(()=>p()))}))})}on(e,t){let r=t.bind(window),i=o=>{o.data.msgType===`${e}-${this.parameters}`&&r(o)};return this.messageHandlers.add(i),()=>this.messageHandlers.delete(i)}waitForReady(){return new Promise(e=>{let t=this.on(he.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(he.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(he.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(he.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Fe(be.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Kt={};_r(Kt,{AuthEventOnReceived:()=>Cr,DeepLinkPage:()=>Rr,DeviceVerificationEventEmit:()=>Je,DeviceVerificationEventOnReceived:()=>Tr,DisableMFAEventEmit:()=>Se,DisableMFAEventOnReceived:()=>$r,EnableMFAEventEmit:()=>$e,EnableMFAEventOnReceived:()=>Dr,EthChainType:()=>Ur,Extension:()=>xe,ExtensionError:()=>_t,ExtensionWarning:()=>vt,FarcasterLoginEventEmit:()=>Pr,LocalStorageKeys:()=>_e,LoginWithEmailOTPEventEmit:()=>de,LoginWithEmailOTPEventOnReceived:()=>Nr,LoginWithMagicLinkEventEmit:()=>Sr,LoginWithMagicLinkEventOnReceived:()=>Ar,LoginWithSmsOTPEventEmit:()=>De,LoginWithSmsOTPEventOnReceived:()=>Or,MagicIncomingWindowMessage:()=>he,MagicOutgoingWindowMessage:()=>Re,MagicPayloadMethod:()=>L,NftCheckoutIntermediaryEvents:()=>Ue,RPCError:()=>je,RPCErrorCode:()=>Be,RecencyCheckEventEmit:()=>ue,RecencyCheckEventOnReceived:()=>Lr,RecoverAccountEventEmit:()=>ge,RecoverAccountEventOnReceived:()=>kr,RecoveryFactorEventEmit:()=>ye,RecoveryFactorEventOnReceived:()=>xr,RecoveryMethodType:()=>Fr,SDKError:()=>we,SDKErrorCode:()=>Ee,SDKWarning:()=>Fe,SDKWarningCode:()=>be,ThirdPartyWalletEvents:()=>br,UiEventsEmit:()=>Br,UpdateEmailEventEmit:()=>ne,UpdateEmailEventOnReceived:()=>Mr,UserEventsEmit:()=>at,UserEventsOnReceived:()=>st,WalletEventOnReceived:()=>Wr,isPromiEvent:()=>Bt,routeToMagicMethods:()=>Dt});var Rt=wr(On()),Xt=wr(Tn());var Ma={display:"block",visibility:"hidden",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",opacity:"0",zIndex:"-1"};function Ca(e){for(let[t,r]of Object.entries(Ma))e.style[t]=r}function Pa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var Da=1e3,Mn=60*Da,Ln=5*Mn,$a=60*Mn,bt=class extends Sn{constructor(){super(...arguments);this.activeElement=null;this.lastPongTime=null;this.heartbeatIntervalTimer=null;this.heartbeatDebounce=Ua(()=>this.heartBeatCheck(),$a)}getIframeSrc(){return rt(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href}init(){this.test="hello",this.iframe=new Promise(r=>{let i=()=>{if(Pa(encodeURIComponent(this.parameters)))ln().log();else{let o=document.createElement("iframe");o.classList.add("magic-iframe"),o.dataset.magicIframeLabel=rt(this.endpoint).host,o.title="Secure Modal",o.src=this.getIframeSrc(),o.allow="clipboard-read; clipboard-write",Ca(o),document.body.appendChild(o),r(o)}};["loaded","interactive","complete"].includes(document.readyState)?i():window.addEventListener("load",i,!1)}),this.iframe.then(r=>{r instanceof HTMLIFrameElement&&r.addEventListener("load",()=>pe(this,null,function*(){this.heartbeatDebounce()}))}),window.addEventListener("message",r=>{var i;if(r.origin===this.endpoint&&r.data.msgType&&(r.data.msgType.includes(he.MAGIC_PONG)&&(this.lastPongTime=Date.now()),r.data&&this.messageHandlers.size)){r.data.response=(i=r.data.response)!=null?i:{},this.stopHeartBeat();for(let o of this.messageHandlers.values())o(r)}}),window.addEventListener("beforeunload",()=>{this.stopHeartBeat()})}showOverlay(){return pe(this,null,function*(){let r=yield this.iframe;r.style.visibility="visible",r.style.zIndex="2147483647",r.style.opacity="1",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return pe(this,null,function*(){var i;let r=yield this.iframe;r.style.visibility="hidden",r.style.zIndex="-1",r.style.opacity="0",(i=this.activeElement)!=null&&i.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return pe(this,null,function*(){let i=yield this.checkIframeExistsInDOM();if(!i)throw this.init(),cn();if(i&&i.contentWindow)i.contentWindow.postMessage(r,this.endpoint);else throw kt()})}heartBeatCheck(){let r=!0,i=()=>pe(this,null,function*(){let o={msgType:`${Re.MAGIC_PING}-${this.parameters}`,payload:[]};yield this._post(o)});this.heartbeatIntervalTimer=setInterval(()=>pe(this,null,function*(){if(this.lastPongTime){if(Date.now()-this.lastPongTime>Ln*2){this.reloadIframe(),r=!0;return}}else if(!r){this.reloadIframe(),r=!0;return}yield i(),r=!1}),Ln)}stopHeartBeat(){this.heartbeatDebounce(),this.lastPongTime=null,this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}reloadIframe(){return pe(this,null,function*(){let r=yield this.iframe;this.stopHeartBeat(),r?r.src=this.getIframeSrc():(this.init(),console.warn("Magic SDK: Modal lost, re-initiating"))})}checkIframeExistsInDOM(){return pe(this,null,function*(){return[].slice.call(document.querySelectorAll(".magic-iframe")).find(i=>i.src.includes(encodeURIComponent(this.parameters)))})}};function Ua(e,t){let r=null;return function(...i){r&&clearTimeout(r),r=setTimeout(()=>{e(...i)},t)}}var xa=Object.assign(sn(qt,{platform:"web",sdkName:"magic-sdk",version:"29.0.1",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})}),gr({},Kt)),Fa=xa;return Mi(ka);})();
|
5
|
+
Received: \`${e.received}\``)}function ln(){return new Fe(be.DuplicateIframe,"Duplicate iframes found.")}function Vo(){return new Fe(be.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 jo(){return new Fe(be.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 Ho(e){let{method:t,removalVersions:r,useInstead:i}=e,o=r[Y.sdkName],s=i?` Use \`${i}\` instead.`:"",m=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${o}\`.${s}`;return new Fe(be.DeprecationNotice,m)}function*qo(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Ko=qo();function un(){return Ko.next().value}var dn=Symbol("Payload pre-processed by Magic SDK");function fn(e){return Object.defineProperty(e,dn,{value:!0,enumerable:!1}),e}function Yo(e){return!!e[dn]}function pt(e){var t,r,i;return Yo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=un(),e.method=(r=e.method)!=null?r:"noop",e.params=(i=e.params)!=null?i:[],fn(e)),e}function G(e,t=[]){return fn({params:t,method:e,jsonrpc:"2.0",id:un()})}var Wt=class{constructor(e){e instanceof Wt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):$o(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}}},Xo=Gi(Vi()),zo=class extends Xo.default{};function hn(){let e=new zo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...i)=>(e[t].apply(e,i),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var mn=Symbol("isPromiEvent");function Bt(e){return!!e[mn]}function Ie(e){let t=vn(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:i}=hn(),o=Symbol("Promise.then"),s=Symbol("Promise.catch"),m=Symbol("Promise.finally"),f=(g,N)=>(..._)=>{let O=N[g].apply(N,_);return p(O)},p=g=>Object.assign(g,{[mn]:!0,[o]:g[o]||g.then,[s]:g[s]||g.catch,[m]:g[m]||g.finally,then:f(o,g),catch:f(s,g),finally:f(m,g),on:i("on",g),once:i("once",g),addListener:i("addListener",g),off:i("off",g),removeListener:i("removeListener",g),removeAllListeners:i("removeAllListeners",g),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),y=p(t.then(g=>(y.emit("done",g),y.emit("settled"),g),g=>{throw y.emit("error",g),y.emit("settled"),g}));return y.on(st.ClosedByUser,()=>{y.emit(at.ClosedByUser)}),y}function vn(e){return new Promise((t,r)=>{let i=e(t,r);Promise.resolve(i).catch(r)})}var Le=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){if(this.sdk.thirdPartyWallets.isConnected&&!Dt.includes(e.method))return Ie((o,s)=>{this.sdk.thirdPartyWallets.requestOverride(e).then(o).catch(s)});let t=this.overlay.post(Re.MAGIC_HANDLE_REQUEST,pt(e)),r=Ie((o,s)=>{t.then(m=>{if(i(),m.hasError)s(new je(m.payload.error));else if(m.hasResult)o(m.payload.result);else throw ko()}).catch(m=>{i(),s(m)})}),i=this.overlay.on(he.MAGIC_HANDLE_EVENT,o=>{var s;let{response:m}=o.data;if(m.id===e.id&&((s=m.result)==null?void 0:s.event)){let{event:f,params:p=[]}=m.result;r.emit(f,...p)}});return r}createIntermediaryEvent(e,t){return r=>{let i=G(L.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(i)}}};function Jo(e,t){let[r]=e.split(".").map(Number);return r>=t}var Qo={"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"},Zo=class extends Le{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&&Jo(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&Ho({method:"auth.loginWithMagicLink()",removalVersions:Qo,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:i=!0,redirectURI:o,overrides:s,lifespan:m}=e,f=G(this.sdk.testMode?L.LoginWithMagicLinkTestMode:L.LoginWithMagicLink,[{email:r,showUI:i,redirectURI:o,overrides:s,lifespan:m}]);return this.request(f)}loginWithSMS(e){let{phoneNumber:t,showUI:r=!0,lifespan:i}=e,o=G(this.sdk.testMode?L.LoginWithSmsTestMode:L.LoginWithSms,[{phoneNumber:t,showUI:r,lifespan:i}]),s=this.request(o);return!r&&s&&(s.on(De.VerifySmsOtp,m=>{this.createIntermediaryEvent(De.VerifySmsOtp,o.id)(m)}),s.on(De.Cancel,()=>{this.createIntermediaryEvent(De.Cancel,o.id)()})),s}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:i,overrides:o,lifespan:s}=e,m=G(this.sdk.testMode?L.LoginWithEmailOTPTestMode:L.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:i,overrides:o,lifespan:s}]),f=this.request(m);return!i&&f&&f.on(Je.Retry,()=>{this.createIntermediaryEvent(Je.Retry,m.id)()}),!r&&f&&(f.on(de.VerifyEmailOtp,p=>{this.createIntermediaryEvent(de.VerifyEmailOtp,m.id)(p)}),f.on(de.VerifyMFACode,p=>{this.createIntermediaryEvent(de.VerifyMFACode,m.id)(p)}),f.on(de.LostDevice,()=>{this.createIntermediaryEvent(de.LostDevice,m.id)()}),f.on(de.VerifyRecoveryCode,p=>{this.createIntermediaryEvent(de.VerifyRecoveryCode,m.id)(p)}),f.on(de.Cancel,()=>{this.createIntermediaryEvent(de.Cancel,m.id)()})),f}loginWithCredential(e){let{credentialOrQueryString:t,lifespan:r}=e||{},i=t!=null?t:"";if(!t&&Y.platform==="web"){i=window.location.search;let s=window.location.origin+window.location.pathname;window.history.replaceState(null,"",s)}let o=G(this.sdk.testMode?L.LoginWithCredentialTestMode:L.LoginWithCredential,[i,r]);return this.request(o)}setAuthorizationToken(e){let t=G(L.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,i=G(this.sdk.testMode?L.UpdateEmailTestMode:L.UpdateEmail,[{email:t,showUI:r}]),o=this.request(i);return r||(o.on(ue.Retry,()=>{this.createIntermediaryEvent(ue.Retry,i.id)()}),o.on(ue.Cancel,()=>{this.createIntermediaryEvent(ue.Cancel,i.id)()}),o.on(ue.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ue.VerifyEmailOtp,i.id)(s)}),o.on(ue.VerifyMFACode,s=>{this.createIntermediaryEvent(ue.VerifyMFACode,i.id)(s)}),o.on(ne.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ne.RetryWithNewEmail,i.id)(s)}),o.on(ne.Cancel,()=>{this.createIntermediaryEvent(ne.Cancel,i.id)()}),o.on(ne.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ne.VerifyEmailOtp,i.id)(s)})),o}},pn={};Wi(pn,{clear:()=>ea,getItem:()=>me,iterate:()=>yn,key:()=>ra,keys:()=>na,length:()=>ta,removeItem:()=>yt,setItem:()=>Te});var dt;function Me(e){return(...t)=>Z(this,null,function*(){return dt||(dt=yield Y.configureStorage()),yield dt.ready(),dt[e](...t)})}var me=Me("getItem"),Te=Me("setItem"),yt=Me("removeItem"),ea=Me("clear"),ta=Me("length"),ra=Me("key"),na=Me("keys"),yn=Me("iterate");function ia(){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 gn="STORE_KEY_PRIVATE_KEY",Ut="STORE_KEY_PUBLIC_JWK",En="ECDSA",oa="P-256",aa={name:En,namedCurve:oa};function It(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function sa(){return Z(this,null,function*(){let e=yield ca();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield me(gn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let i={iat:Math.floor(new Date().getTime()/1e3),jti:ia()},o={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:Zr(JSON.stringify(o)),claims:Zr(JSON.stringify(i))},m=ua(`${s.protected}.${s.claims}`),f={name:En,hash:{name:"SHA-256"}},p=fa(new Uint8Array(yield t.sign(f,r,m)));return`${s.protected}.${s.claims}.${p}`})}function ca(){return Z(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}return(yield me(Ut))||(yield la()),me(Ut)})}function la(){return Z(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(aa,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield Te(gn,t.privateKey),yield Te(Ut,r)})}function Zr(e){return _n(da(e))}function ua(e){return new TextEncoder().encode(e)}function _n(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function da(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function fa(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),_n(t)}var Gt="ds",Vt="ek",jt="iv",Ht="AES-GCM",ha=256;function In(){return Z(this,null,function*(){let e=[];yield yn((t,r,i)=>{r.startsWith(`${Gt}_`)&&e.push(r)});for(let t of e)yield yt(t)})}function wn(e){let t="",r=new Uint8Array(e),i=r.byteLength;for(let o=0;o<i;o++)t+=String.fromCharCode(r[o]);return window.btoa(t)}function bn(e){let t=window.atob(e),r=t.length,i=new Uint8Array(r);for(let o=0;o<r;o++)i[o]=t.charCodeAt(o);return i.buffer}function ma(){return Z(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield me(jt))||e.getRandomValues(new Uint8Array(12))})}function va(){return Z(this,null,function*(){if(!It()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield me(Vt))||(yield e.generateKey({name:Ht,length:ha},!1,["encrypt","decrypt"]))})}function pa(e,t){return Z(this,null,function*(){let r=yield ma(),i=yield va();if(!r||!i||!e)return;let o=bn(e),{subtle:s}=window.crypto,m=yield s.encrypt({name:Ht,iv:r},i,o),f=wn(m);yield Te(`${Gt}_${t}`,f),yield Te(Vt,i),yield Te(jt,r)})}function ya(e){return Z(this,null,function*(){let t=yield me(`${Gt}_${e}`),r=yield me(jt),i=yield me(Vt);if(!r||!t||!i||!It())return;let{subtle:o}=window.crypto,s=yield o.decrypt({name:Ht,iv:r},i,bn(t));return wn(s)})}function rt(e,t){return t?new URL(e,t):new URL(e)}var ga=class extends Le{constructor(){super(...arguments),this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=G(this.sdk.testMode?L.GetIdTokenTestMode:L.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=G(this.sdk.testMode?L.GenerateIdTokenTestMode:L.GenerateIdToken,[e]);return this.request(t)}getInfo(){let e=G(L.GetInfo,[]);return this.request(e)}isLoggedIn(){return Ie((e,t)=>Z(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield me(this.localForageIsLoggedInKey))==="true",r&&e(!0));let i=G(this.sdk.testMode?L.IsLoggedInTestMode:L.IsLoggedIn),o=yield this.request(i);this.sdk.useStorageCache&&(o?Te(this.localForageIsLoggedInKey,!0):yt(this.localForageIsLoggedInKey),r&&!o&&this.emitUserLoggedOut(!0)),e(o)}catch(r){t(r)}}))}logout(){return yt(this.localForageIsLoggedInKey),In(),Ie((e,t)=>Z(this,null,function*(){try{let r=G(this.sdk.testMode?L.LogoutTestMode:L.Logout),i=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(i),e(i)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=G(L.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let{showUI:t=!0}=e||{},r=G(this.sdk.testMode?L.UserSettingsTestMode:L.UserSettings,[e]),i=this.request(r);return!t&&i&&(i.on(ye.SendNewPhoneNumber,o=>{this.createIntermediaryEvent(ye.SendNewPhoneNumber,r.id)(o)}),i.on(ye.SendOtpCode,o=>{this.createIntermediaryEvent(ye.SendOtpCode,r.id)(o)}),i.on(ye.StartEditPhoneNumber,()=>{this.createIntermediaryEvent(ye.StartEditPhoneNumber,r.id)()}),i.on(ye.Cancel,()=>{this.createIntermediaryEvent(ye.Cancel,r.id)()}),i.on(ue.VerifyEmailOtp,o=>{this.createIntermediaryEvent(ue.VerifyEmailOtp,r.id)(o)})),i}recoverAccount(e){let{email:t,showUI:r}=e,i=G(this.sdk.testMode?L.RecoverAccountTestMode:L.RecoverAccount,[{email:t,showUI:r}]),o=this.request(i);return!r&&o&&(o.on(ge.Cancel,()=>{this.createIntermediaryEvent(ge.Cancel,i.id)()}),o.on(ge.ResendSms,()=>{this.createIntermediaryEvent(ge.ResendSms,i.id)()}),o.on(ge.VerifyOtp,s=>{this.createIntermediaryEvent(ge.VerifyOtp,i.id)(s)}),o.on(ge.UpdateEmail,s=>{this.createIntermediaryEvent(ge.UpdateEmail,i.id)(s)}),o.on(ne.Cancel,()=>{this.createIntermediaryEvent(ne.Cancel,i.id)()}),o.on(ne.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ne.RetryWithNewEmail,i.id)(s)}),o.on(ne.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ne.VerifyEmailOtp,i.id)(s)})),o}revealPrivateKey(){let e=G(L.RevealPK);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}enableMFA(e){let{showUI:t=!0}=e,r=G(L.EnableMFA,[{showUI:t}]),i=this.request(r);return!t&&i&&(i.on($e.VerifyMFACode,o=>{this.createIntermediaryEvent($e.VerifyMFACode,r.id)(o)}),i.on($e.Cancel,()=>{this.createIntermediaryEvent($e.Cancel,r.id)()})),i}disableMFA(e){let{showUI:t=!0}=e,r=G(L.DisableMFA,[{showUI:t}]),i=this.request(r);return!t&&i&&(i.on(Se.VerifyMFACode,o=>{this.createIntermediaryEvent(Se.VerifyMFACode,r.id)(o)}),i.on(Se.LostDevice,o=>{this.createIntermediaryEvent(Se.LostDevice,r.id)(o)}),i.on(Se.Cancel,()=>{this.createIntermediaryEvent(Se.Cancel,r.id)()})),i}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Ea=class extends Le{connectWithUI(e){let t=Ie((r,i)=>Z(this,null,function*(){try{let o=G(L.Login,[Et({enabledWallets:this.sdk.thirdPartyWallets.enabledWallets},e)]),s=this.request(o);this.sdk.thirdPartyWallets.eventListeners.forEach(({event:f,callback:p})=>{s.on(f,()=>p(o.id))}),s.on("id-token-created",f=>{t.emit("id-token-created",f)});let m=yield s;m.error&&i(m),r(m)}catch(o){i(o)}}));return t}showUI(e){return this.request(G(L.ShowUI,[e]))}showAddress(){return this.request(G(L.ShowAddress))}showSendTokensUI(){return this.request(G(L.ShowSendTokensUI))}showOnRamp(){return this.request(G(L.ShowOnRamp))}showNFTs(){return this.request(G(L.ShowNFTs))}showBalances(){return this.request(G(L.ShowBalances))}sendGaslessTransaction(e,t){return this.request(G(L.SendGaslessTransaction,[e,t]))}},_a=class extends Le{constructor(){super(...arguments),this.eventListeners=[],this.enabledWallets={},this.isConnected=!1}resetThirdPartyWalletState(){localStorage.removeItem(_e.PROVIDER),localStorage.removeItem(_e.ADDRESS),localStorage.removeItem(_e.CHAIN_ID),this.isConnected=!1}requestOverride(e){if(e.method===L.Login)return this.resetThirdPartyWalletState(),super.request(e);if(e.method===L.GetInfo)return this.getInfo(e);if(e.method===L.IsLoggedIn)return this.isLoggedIn(e);if(e.method===L.Logout)return this.logout(e);switch(localStorage.getItem(_e.PROVIDER)){case"web3modal":return this.web3modalRequest(e);default:return this.resetThirdPartyWalletState(),super.request(e)}}isLoggedIn(e){switch(localStorage.getItem(_e.PROVIDER)){case"web3modal":return this.web3modalIsLoggedIn();default:return this.resetThirdPartyWalletState(),super.request(e)}}getInfo(e){switch(localStorage.getItem(_e.PROVIDER)){case"web3modal":return this.web3modalGetInfo();default:return this.resetThirdPartyWalletState(),super.request(e)}}logout(e){let t=localStorage.getItem(_e.PROVIDER);switch(this.resetThirdPartyWalletState(),t){case"web3modal":return this.web3modalLogout();default:return super.request(e)}}web3modalRequest(e){return Ie((t,r)=>{this.sdk.web3modal.modal.getWalletProvider().request(e).then(t).catch(r)})}web3modalIsLoggedIn(){return Ie(e=>{let t=this.sdk.web3modal.modal.getStatus();if(t==="connected"&&e(!0),t==="disconnected"&&(this.resetThirdPartyWalletState(),e(!1)),t==="reconnecting"){let r=this.sdk.web3modal.modal.subscribeProvider(({status:i})=>{i==="connected"&&(r(),e(!0)),i==="disconnected"&&(r(),this.resetThirdPartyWalletState(),e(!1))})}})}formatWeb3modalGetInfoResponse(){var e;let t=(e=this.sdk.web3modal.modal.getWalletInfo())==null?void 0:e.name,r=this.sdk.web3modal.modal.getAddress();return{publicAddress:r,email:null,issuer:`did:ethr:${r}`,phoneNumber:null,isMfaEnabled:!1,recoveryFactors:[],walletType:t||"web3modal"}}web3modalGetInfo(){return Ie((e,t)=>{let r=this.sdk.web3modal.modal.getStatus();if(r==="connected"&&e(this.formatWeb3modalGetInfoResponse()),r==="disconnected"&&(this.resetThirdPartyWalletState(),t("Magic RPC Error: [-32603] Internal error: User denied account access.")),r==="reconnecting"){let i=this.sdk.web3modal.modal.subscribeProvider(({status:o})=>{o==="connected"&&(i(),e(this.formatWeb3modalGetInfoResponse())),o==="disconnected"&&(i(),this.resetThirdPartyWalletState(),t("Magic RPC Error: [-32603] Internal error: User denied account access."))})}})}web3modalLogout(){return Ie(e=>Z(this,null,function*(){try{yield this.sdk.web3modal.modal.disconnect()}catch(t){console.error(t)}e(!0)}))}},{createBoundEmitterMethod:ft,createChainingEmitterMethod:Ge}=hn(),Ia=class extends Le{constructor(){super(...arguments),this.isMagic=!0,this.on=Ge("on",this),this.once=Ge("once",this),this.addListener=Ge("addListener",this),this.off=Ge("off",this),this.removeListener=Ge("removeListener",this),this.removeAllListeners=Ge("removeAllListeners",this),this.emit=ft("emit"),this.eventNames=ft("eventNames"),this.listeners=ft("listeners"),this.listenerCount=ft("listenerCount")}sendAsync(e,t){if(!t)throw Go({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Re.MAGIC_HANDLE_REQUEST,e.map(r=>{let i=pt(r);return this.prefixPayloadMethodForTestMode(i),i})).then(r=>{t(null,r.map(i=>xt(Et({},i.payload),{error:i.hasError?new je(i.payload.error):null})))});else{let r=pt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Re.MAGIC_HANDLE_REQUEST,r).then(i=>{t(i.hasError?new je(i.payload.error):null,i.payload)})}}send(e,t){if(typeof e=="string"){let i=G(e,Array.isArray(t)?t:[]);return this.request(i)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=Vo();return r.log(),new Wt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=G(L.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}`)}},en=["request","overlay","sdk"];function wa(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Le.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var Rn=class extends Le{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Ie,isPromiEvent:Bt,encodeJSON:on,decodeJSON:Po,createJsonRpcRequestPayload:G,standardizeJsonRpcRequestPayload:pt,storage:pn};let e=[this,...wa(this)];en.forEach(t=>{let r=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),i=r.findIndex(m=>!!m),o=i>0,s=r[i];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:o}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Wo(t)}}))})}init(e){this.__is_initialized__||(en.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:i}=this.__sdk_access_field_descriptors__.get(t);i?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:i}=e,o=i?` Use \`${i}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${o}`;return new vt(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new vt(this,e,t)}createError(e,t,r){return new _t(this,e,t,r)}},ba=class extends Rn{},xe=class extends Rn{};xe.Internal=ba,xe.Anonymous="anonymous extension";var Ra=class extends Le{purchase(e){let t=G(L.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=this.sdk.thirdPartyWallets.isConnected,r=G(L.NFTCheckout,[xt(Et({},e),{walletProvider:t?"web3modal":"magic"})]),i=this.request(r);return t&&(i.on(Ue.Initiated,o=>Z(this,null,function*(){try{let s=yield this.request({method:"eth_sendTransaction",params:[o]});this.createIntermediaryEvent(Ue.Success,r.id)(s)}catch(s){this.createIntermediaryEvent(Ue.Failure,r.id)()}})),i.on(Ue.Disconnect,()=>{this.sdk.thirdPartyWallets.resetThirdPartyWalletState(),i.emit("disconnect")})),i}transfer(e){let t=G(L.NFTTransfer,[e]);return this.request(t)}};function tn(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?Ro(No(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function Sa(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 Aa(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],i={},o=[];if(Array.isArray(r)?r.forEach(s=>{tn(s)?(s.init(this),(s.name||s.name!==xe.Anonymous)&&(this[s.name]=s),s instanceof xe.Internal&&(mt(s.config)||(i[s.name]=s.config))):o.push(s)}):Object.keys(r).forEach(s=>{if(tn(r[s])){r[s].init(this);let m=r[s];this[s]=m,m instanceof xe.Internal&&(mt(m.config)||(i[r[s].name]=m.config))}else o.push(r[s])}),o.length)throw Bo(o);return i}var ht=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw Fo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&jo().log();let{defaultEndpoint:i,version:o}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=rt((r=t==null?void 0:t.endpoint)!=null?r:i).origin,this.auth=new Zo(this),this.user=new ga(this),this.wallet=new Ea(this),this.nft=new Ra(this),this.thirdPartyWallets=new _a(this),this.rpcProvider=new Ia(this);let s=Aa.call(this,t);this.parameters=on(xt(Et({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:rt(this.endpoint).host,sdk:xo[Y.sdkName],version:o,ext:mt(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=Sa(this.apiKey,t==null?void 0:t.network,mt(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!ht.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),ht.__overlays__.set(this.parameters,e)}return ht.__overlays__.get(this.parameters)}preload(){return Z(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},qt=ht;qt.__overlays__=new Map;function Oa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function Na(e,t){var r;let i=(r=t.data.response)==null?void 0:r.id,o=Oa(e,i);if(i&&o){let s=new Wt(o).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:i,response:s}}return{}}function Ta(e,t,r){return Z(this,null,function*(){var i;let o=yield me("rt"),s;if(Y.platform==="web")try{s=(i=yield me("jwt"))!=null?i:yield sa()}catch(p){console.error("webcrypto error",p)}let m={msgType:e,payload:t};s&&(m.jwt=s),s&&o&&(m.rt=o);let f=yield ya(r);return f&&(m.deviceShare=f),m})}function La(e){return Z(this,null,function*(){!e.data.rt||(yield Te("rt",e.data.rt))})}var Sn=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 Z(this,null,function*(){return vn((r,i)=>Z(this,null,function*(){if(!this.isConnectedToInternet){let y=kt();i(y)}this.isReadyForRequest||(yield this.waitForReady());let o=[],s=Array.isArray(t)?t.map(y=>y.id):[],m=yield Ta(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(m);let f=y=>g=>{var N;let{id:_,response:O}=Na(t,g);if(La(g),((N=O==null?void 0:O.payload.error)==null?void 0:N.message)==="User denied account access.")In();else if(g.data.deviceShare){let{deviceShare:M}=g.data;pa(M,this.networkHash)}_&&O&&Array.isArray(t)&&s.includes(_)?(o.push(O),o.length===t.length&&(y(),r(o))):_&&O&&!Array.isArray(t)&&_===t.id&&(y(),r(O))},p=this.on(he.MAGIC_HANDLE_RESPONSE,f(()=>p()))}))})}on(e,t){let r=t.bind(window),i=o=>{o.data.msgType===`${e}-${this.parameters}`&&r(o)};return this.messageHandlers.add(i),()=>this.messageHandlers.delete(i)}waitForReady(){return new Promise(e=>{let t=this.on(he.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(he.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(he.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(he.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Fe(be.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Kt={};_r(Kt,{AuthEventOnReceived:()=>Cr,DeepLinkPage:()=>Rr,DeviceVerificationEventEmit:()=>Je,DeviceVerificationEventOnReceived:()=>Tr,DisableMFAEventEmit:()=>Se,DisableMFAEventOnReceived:()=>$r,EnableMFAEventEmit:()=>$e,EnableMFAEventOnReceived:()=>Dr,EthChainType:()=>Ur,Extension:()=>xe,ExtensionError:()=>_t,ExtensionWarning:()=>vt,FarcasterLoginEventEmit:()=>Pr,LocalStorageKeys:()=>_e,LoginWithEmailOTPEventEmit:()=>de,LoginWithEmailOTPEventOnReceived:()=>Nr,LoginWithMagicLinkEventEmit:()=>Sr,LoginWithMagicLinkEventOnReceived:()=>Ar,LoginWithSmsOTPEventEmit:()=>De,LoginWithSmsOTPEventOnReceived:()=>Or,MagicIncomingWindowMessage:()=>he,MagicOutgoingWindowMessage:()=>Re,MagicPayloadMethod:()=>L,NftCheckoutIntermediaryEvents:()=>Ue,RPCError:()=>je,RPCErrorCode:()=>Be,RecencyCheckEventEmit:()=>ue,RecencyCheckEventOnReceived:()=>Lr,RecoverAccountEventEmit:()=>ge,RecoverAccountEventOnReceived:()=>kr,RecoveryFactorEventEmit:()=>ye,RecoveryFactorEventOnReceived:()=>xr,RecoveryMethodType:()=>Fr,SDKError:()=>we,SDKErrorCode:()=>Ee,SDKWarning:()=>Fe,SDKWarningCode:()=>be,ThirdPartyWalletEvents:()=>br,UiEventsEmit:()=>Br,UpdateEmailEventEmit:()=>ne,UpdateEmailEventOnReceived:()=>Mr,UserEventsEmit:()=>at,UserEventsOnReceived:()=>st,WalletEventOnReceived:()=>Wr,isPromiEvent:()=>Bt,routeToMagicMethods:()=>Dt});var Rt=wr(On()),Xt=wr(Tn());var Ma={display:"block",visibility:"hidden",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",opacity:"0",zIndex:"-1"};function Ca(e){for(let[t,r]of Object.entries(Ma))e.style[t]=r}function Pa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var Da=1e3,Mn=60*Da,Ln=5*Mn,$a=60*Mn,bt=class extends Sn{constructor(){super(...arguments);this.activeElement=null;this.lastPongTime=null;this.heartbeatIntervalTimer=null;this.heartbeatDebounce=Ua(()=>this.heartBeatCheck(),$a)}getIframeSrc(){return rt(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href}init(){this.test="hello",this.iframe=new Promise(r=>{let i=()=>{if(Pa(encodeURIComponent(this.parameters)))ln().log();else{let o=document.createElement("iframe");o.classList.add("magic-iframe"),o.dataset.magicIframeLabel=rt(this.endpoint).host,o.title="Secure Modal",o.src=this.getIframeSrc(),o.allow="clipboard-read; clipboard-write",Ca(o),document.body.appendChild(o),r(o)}};["loaded","interactive","complete"].includes(document.readyState)?i():window.addEventListener("load",i,!1)}),this.iframe.then(r=>{r instanceof HTMLIFrameElement&&r.addEventListener("load",()=>pe(this,null,function*(){this.heartbeatDebounce()}))}),window.addEventListener("message",r=>{var i;if(r.origin===this.endpoint&&r.data.msgType&&(r.data.msgType.includes(he.MAGIC_PONG)&&(this.lastPongTime=Date.now()),r.data&&this.messageHandlers.size)){r.data.response=(i=r.data.response)!=null?i:{},this.stopHeartBeat();for(let o of this.messageHandlers.values())o(r)}}),window.addEventListener("beforeunload",()=>{this.stopHeartBeat()})}showOverlay(){return pe(this,null,function*(){let r=yield this.iframe;r.style.visibility="visible",r.style.zIndex="2147483647",r.style.opacity="1",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return pe(this,null,function*(){var i;let r=yield this.iframe;r.style.visibility="hidden",r.style.zIndex="-1",r.style.opacity="0",(i=this.activeElement)!=null&&i.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return pe(this,null,function*(){let i=yield this.checkIframeExistsInDOM();if(!i)throw this.init(),cn();if(i&&i.contentWindow)i.contentWindow.postMessage(r,this.endpoint);else throw kt()})}heartBeatCheck(){let r=!0,i=()=>pe(this,null,function*(){let o={msgType:`${Re.MAGIC_PING}-${this.parameters}`,payload:[]};yield this._post(o)});this.heartbeatIntervalTimer=setInterval(()=>pe(this,null,function*(){if(this.lastPongTime){if(Date.now()-this.lastPongTime>Ln*2){this.reloadIframe(),r=!0;return}}else if(!r){this.reloadIframe(),r=!0;return}yield i(),r=!1}),Ln)}stopHeartBeat(){this.heartbeatDebounce(),this.lastPongTime=null,this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}reloadIframe(){return pe(this,null,function*(){let r=yield this.iframe;this.stopHeartBeat(),r?r.src=this.getIframeSrc():(this.init(),console.warn("Magic SDK: Modal lost, re-initiating"))})}checkIframeExistsInDOM(){return pe(this,null,function*(){return[].slice.call(document.querySelectorAll(".magic-iframe")).find(i=>i.src.includes(encodeURIComponent(this.parameters)))})}};function Ua(e,t){let r=null;return function(...i){r&&clearTimeout(r),r=setTimeout(()=>{e(...i)},t)}}var xa=Object.assign(sn(qt,{platform:"web",sdkName:"magic-sdk",version:"29.0.2",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})}),gr({},Kt)),Fa=xa;return Mi(ka);})();
|
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": "29.0.2
|
3
|
+
"version": "29.0.2",
|
4
4
|
"description": "Passwordless authentication for the web.",
|
5
5
|
"author": "Magic Labs <team@magic.link> (https://magic.link/)",
|
6
6
|
"license": "MIT",
|
@@ -29,9 +29,9 @@
|
|
29
29
|
]
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@magic-sdk/commons": "25.0.2
|
33
|
-
"@magic-sdk/provider": "29.0.2
|
34
|
-
"@magic-sdk/types": "24.18.1
|
32
|
+
"@magic-sdk/commons": "^25.0.2",
|
33
|
+
"@magic-sdk/provider": "^29.0.2",
|
34
|
+
"@magic-sdk/types": "^24.18.1",
|
35
35
|
"localforage": "^1.7.4"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
@@ -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": "b82e4fa7e3d0b9bc4572085a6ab68ae2b93b6458"
|
44
44
|
}
|