magic-sdk 21.5.0-canary.689.7292618936.0 → 21.5.0-canary.689.7302803005.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.
Files changed (2) hide show
  1. package/dist/magic.js +1 -1
  2. package/package.json +4 -4
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 ve(pe.IncompatibleExtensions,t)}function Eo(e){let t=r=>{let o=r+1,a=o%10,l=o%100;return a===1&&l!==11?`${o}st`:a===2&&l!==12?`${o}nd`:a===3&&l!==13?`${o}rd`:`${o}th`};return new ve(pe.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
4
4
  Expected: \`${e.expected}\`
5
- Received: \`${e.received}\``)}function Gr(){return new Be(be.DuplicateIframe,"Duplicate iframes found.")}function _o(){return new Be(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 Io(){return new Be(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 De(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],l=o?` Use \`${o}\` instead.`:"",p=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${l}`;return new Be(be.DeprecationNotice,p)}function*wo(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var bo=wo();function jr(){return bo.next().value}var qr=Symbol("Payload pre-processed by Magic SDK");function Vr(e){return Object.defineProperty(e,qr,{value:!0,enumerable:!1}),e}function Ro(e){return!!e[qr]}function ut(e){var t,r,o;return Ro(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=jr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Vr(e)),e}function B(e,t=[]){return Vr({params:t,method:e,jsonrpc:"2.0",id:jr()})}var Lt=class{constructor(e){e instanceof Lt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):fo(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}}},Ao=Ei(_i()),So=class extends Ao.default{};function Kr(){let e=new So;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Hr=Symbol("isPromiEvent");function Ct(e){return!!e[Hr]}function Je(e){let t=Yr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=Kr(),a=Symbol("Promise.then"),l=Symbol("Promise.catch"),p=Symbol("Promise.finally"),h=(y,N)=>(..._)=>{let T=N[y].apply(N,_);return g(T)},g=y=>Object.assign(y,{[Hr]:!0,[a]:y[a]||y.then,[l]:y[l]||y.catch,[p]:y[p]||y.finally,then:h(a,y),catch:h(l,y),finally:h(p,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}function Yr(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var Te=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Re.MAGIC_HANDLE_REQUEST,ut(e)),r=Je((a,l)=>{t.then(p=>{if(o(),p.hasError)l(new Ue(p.payload.error));else if(p.hasResult)a(p.payload.result);else throw vo()}).catch(p=>{o(),l(p)})}),o=this.overlay.on(me.MAGIC_HANDLE_EVENT,a=>{var l;let{response:p}=a.data;if(p.id===e.id&&((l=p.result)==null?void 0:l.event)){let{event:h,params:g=[]}=p.result;r.emit(h,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=B(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function To(e,t){let[r]=e.split(".").map(Number);return r>=t}var xe={"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"},No=class extends Te{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&&To(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&De({method:"auth.loginWithMagicLink()",removalVersions:xe,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:l}=e,p=B(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:l}]);return this.request(p)}loginWithSMS(e){let{phoneNumber:t}=e,r=B(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,l=B(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),p=this.request(l);return!o&&p&&p.on(Ke.Retry,()=>{this.createIntermediaryEvent(Ke.Retry,l.id)()}),!r&&p&&(p.on(Ae.VerifyEmailOtp,h=>{this.createIntermediaryEvent(Ae.VerifyEmailOtp,l.id)(h)}),p.on(Ae.Cancel,()=>{this.createIntermediaryEvent(Ae.Cancel,l.id)()})),p}loginWithCredential(e){let t=e!=null?e:"";if(!e&&Y.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let r=B(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(r)}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}]);return this.request(o)}},Xr={};gi(Xr,{clear:()=>Mo,getItem:()=>se,iterate:()=>zr,key:()=>Lo,keys:()=>Co,length:()=>Oo,removeItem:()=>ke,setItem:()=>he});var ot;function _e(e){return(...t)=>X(this,null,function*(){return ot||(ot=yield Y.configureStorage()),yield ot.ready(),ot[e](...t)})}var se=_e("getItem"),he=_e("setItem"),ke=_e("removeItem"),Mo=_e("clear"),Oo=_e("length"),Lo=_e("key"),Co=_e("keys"),zr=_e("iterate");function $o(){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 Jr="STORE_KEY_PRIVATE_KEY",Tt="STORE_KEY_PUBLIC_JWK",Qr="ECDSA",Po="P-256",Do={name:Qr,namedCurve:Po};function ht(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function xo(){return X(this,null,function*(){let e=yield ko();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield se(Jr);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:$o()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:$r(JSON.stringify(a)),claims:$r(JSON.stringify(o))},p=Fo(`${l.protected}.${l.claims}`),h={name:Qr,hash:{name:"SHA-256"}},g=Wo(new Uint8Array(yield t.sign(h,r,p)));return`${l.protected}.${l.claims}.${g}`})}function ko(){return X(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}return(yield se(Tt))||(yield Uo()),se(Tt)})}function Uo(){return X(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Do,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield he(Jr,t.privateKey),yield he(Tt,r)})}function $r(e){return Zr(Bo(e))}function Fo(e){return new TextEncoder().encode(e)}function Zr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Bo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Wo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),Zr(t)}var $t="ds",Pt="ek",Dt="iv",xt="AES-GCM",Go=256;function kt(){return X(this,null,function*(){let e=[];yield zr((t,r,o)=>{r.startsWith(`${$t}_`)&&e.push(r)});for(let t of e)yield ke(t)})}function en(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 tn(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 jo(){return X(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield se(Dt))||e.getRandomValues(new Uint8Array(12))})}function qo(){return X(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield se(Pt))||(yield e.generateKey({name:xt,length:Go},!1,["encrypt","decrypt"]))})}function Vo(e,t){return X(this,null,function*(){let r=yield jo(),o=yield qo();if(!r||!o||!e)return;let a=tn(e),{subtle:l}=window.crypto,p=yield l.encrypt({name:xt,iv:r},o,a),h=en(p);yield he(`${$t}_${t}`,h),yield he(Pt,o),yield he(Dt,r)})}function Ko(e){return X(this,null,function*(){let t=yield se(`${$t}_${e}`),r=yield se(Dt),o=yield se(Pt);if(!r||!t||!o||!ht())return;let{subtle:a}=window.crypto,l=yield a.decrypt({name:xt,iv:r},o,tn(t));return en(l)})}function Qe(e,t){return t?new URL(e,t):new URL(e)}var Ho=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="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 Je((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?he(this.localForageIsLoggedInKey,!0):(ke(this.localForageIsLoggedInKey),r&&this.emitUserLoggedOut(!0))),e(a)}catch(r){t(r)}}))}logout(){return ke(this.localForageKey),ke(this.localForageIsLoggedInKey),kt(),Je((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)}getMetadata(){De({method:"user.getMetadata()",removalVersions:xe,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}updateEmail(e){De({method:"user.updateEmail()",removalVersions:xe,useInstead:"auth.updateEmailWithUI()"}).log();let{email:t,showUI:r=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Yo=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Je((t,r)=>X(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ue.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ue.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ue.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ue.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=B(O.Login,[o]),l=this.request(a);l.on(Ce.WalletSelected,h=>this.handleWalletSelected(kr(Nt({},h),{payloadId:a.id}))),l.on("id-token-created",h=>{e.emit("id-token-created",h)});let p=yield l;p.error&&r(p),t(p)}catch(o){r(o)}}));return e}showUI(){return this.request(B(O.ShowUI))}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*(){De({method:"wallet.getInfo()",removalVersions:xe,useInstead:"user.getInfo()"}).log();let e=yield se(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){De({method:"wallet.disconnect()",removalVersions:xe,useInstead:"user.logout()"}).log(),ke(this.localForageKey),kt();let e=B(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){De({method:"wallet.requestUserInfoWithUI()",removalVersions:xe,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 he(this.localForageKey,e.wallet),this.createIntermediaryEvent(Ce.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Ce.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 he(this.localForageKey,e);let r=B(O.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:at,createChainingEmitterMethod:$e}=Kr(),Xo=class extends Te{constructor(){super(...arguments),this.isMagic=!0,this.on=$e("on",this),this.once=$e("once",this),this.addListener=$e("addListener",this),this.off=$e("off",this),this.removeListener=$e("removeListener",this),this.removeAllListeners=$e("removeAllListeners",this),this.emit=at("emit"),this.eventNames=at("eventNames"),this.listeners=at("listeners"),this.listenerCount=at("listenerCount")}sendAsync(e,t){if(!t)throw Eo({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 o=ut(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>kr(Nt({},o.payload),{error:o.hasError?new Ue(o.payload.error):null})))});else{let r=ut(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Re.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Ue(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=_o();return r.log(),new Lt(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}`)}},Pr=["request","overlay","sdk"];function zo(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Te.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var rn=class extends Te{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Je,isPromiEvent:Ct,encodeJSON:Fr,decodeJSON:co,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:ut,storage:Xr};let e=[this,...zo(this)];Pr.forEach(t=>{let r=e.map(p=>Object.getOwnPropertyDescriptor(p,t)),o=r.findIndex(p=>!!p),a=o>0,l=r[o];l&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:l,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw go(t)}}))})}init(e){this.__is_initialized__||(Pr.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.`:"",l=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new ct(this,"DEPRECATION_NOTICE",l)}createWarning(e,t){return new ct(this,e,t)}createError(e,t,r){return new dt(this,e,t,r)}},Jo=class extends rn{},Se=class extends rn{};Se.Internal=Jo,Se.Anonymous="anonymous extension";var Qo=class extends Te{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 Dr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?eo(io(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function Zo(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(l=>{Dr(l)?(l.init(this),(l.name||l.name!==Se.Anonymous)&&(this[l.name]=l),l instanceof Se.Internal&&(lt(l.config)||(o[l.name]=l.config))):a.push(l)}):Object.keys(r).forEach(l=>{if(Dr(r[l])){r[l].init(this);let p=r[l];this[l]=p,p instanceof Se.Internal&&(lt(p.config)||(o[r[l].name]=p.config))}else a.push(r[l])}),a.length)throw yo(a);return o}var st=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw mo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Io().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=Qe((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new No(this),this.user=new Ho(this),this.wallet=new Yo(this),this.nft=new Qo(this),this.rpcProvider=new Xo(this);let l=ea.call(this,t);this.parameters=Fr(Nt({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:Qe(this.endpoint).host,sdk:po[Y.sdkName],version:a,ext:lt(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{})),this.networkHash=Zo(this.apiKey,t==null?void 0:t.network,lt(l)?void 0:l),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!st.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),st.__overlays__.set(this.parameters,e)}return st.__overlays__.get(this.parameters)}preload(){return X(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Ut=st;Ut.__overlays__=new Map;function ta(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function ra(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=ta(e,o);if(o&&a){let l=new Lt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function na(e,t,r){return X(this,null,function*(){var o;let a=yield se("rt"),l;if(Y.platform==="web")try{l=(o=yield se("jwt"))!=null?o:yield xo()}catch(g){console.error("webcrypto error",g)}let p={msgType:e,payload:t};l&&(p.jwt=l),l&&a&&(p.rt=a);let h=yield Ko(r);return h&&(p.deviceShare=h),p})}function ia(e){return X(this,null,function*(){!e.data.rt||(yield he("rt",e.data.rt))})}var nn=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 Yr((r,o)=>X(this,null,function*(){if(!this.isConnectedToInternet){let v=Ot();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],l=Array.isArray(t)?t.map(v=>v.id):[],p=yield na(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(p);let h=v=>y=>{var N;let{id:_,response:T}=ra(t,y);if(ia(y),((N=T==null?void 0:T.payload.error)==null?void 0:N.message)==="User denied account access.")kt();else if(y.data.deviceShare){let{deviceShare:L}=y.data;Vo(L,this.networkHash)}_&&T&&Array.isArray(t)&&l.includes(_)?(a.push(T),a.length===t.length&&(v(),r(a))):_&&T&&!Array.isArray(t)&&_===t.id&&(v(),r(T))},g=this.on(me.MAGIC_HANDLE_RESPONSE,h(()=>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(me.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(me.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(me.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Ft={};dr(Ft,{DeepLinkPage:()=>mr,DeviceVerificationEventEmit:()=>Ke,DeviceVerificationEventOnReceived:()=>Er,EthChainType:()=>_r,Events:()=>Ce,Extension:()=>Se,ExtensionError:()=>dt,ExtensionWarning:()=>ct,LoginWithEmailOTPEventEmit:()=>Ae,LoginWithEmailOTPEventOnReceived:()=>yr,LoginWithMagicLinkEventEmit:()=>vr,LoginWithMagicLinkEventOnReceived:()=>gr,MagicIncomingWindowMessage:()=>me,MagicOutgoingWindowMessage:()=>Re,MagicPayloadMethod:()=>O,RPCError:()=>Ue,RPCErrorCode:()=>Le,RecoveryMethodType:()=>Ir,SDKError:()=>ve,SDKErrorCode:()=>pe,SDKWarning:()=>Be,SDKWarningCode:()=>be,Wallets:()=>ue,isPromiEvent:()=>Ct});var vt=pr(an()),Wt=pr(ln());var oa={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function aa(e){for(let[t,r]of Object.entries(oa))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 mt=class extends nn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(sa(encodeURIComponent(this.parameters)))Gr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=Qe(this.endpoint).host,a.title="Secure Modal",a.src=Qe(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,aa(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(o=r.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(r)}})}showOverlay(){return Oe(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return Oe(this,null,function*(){var o;let r=yield this.iframe;r.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return Oe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Ot()})}};var la=Object.assign(Wr(Ut,{platform:"web",sdkName:"magic-sdk",version:"21.4.1",defaultEndpoint:"https://auth.magic.link/",ViewController:mt,configureStorage:()=>Oe(void 0,null,function*(){let e=vt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Wt),yield e.setDriver([vt.default.INDEXEDDB,vt.default.LOCALSTORAGE,Wt._driver]),e})}),ur({},Ft)),ca=la;return li(ua);})();
5
+ Received: \`${e.received}\``)}function Gr(){return new Be(be.DuplicateIframe,"Duplicate iframes found.")}function _o(){return new Be(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 Io(){return new Be(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 De(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],l=o?` Use \`${o}\` instead.`:"",p=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${l}`;return new Be(be.DeprecationNotice,p)}function*wo(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var bo=wo();function jr(){return bo.next().value}var qr=Symbol("Payload pre-processed by Magic SDK");function Vr(e){return Object.defineProperty(e,qr,{value:!0,enumerable:!1}),e}function Ro(e){return!!e[qr]}function ut(e){var t,r,o;return Ro(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=jr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Vr(e)),e}function B(e,t=[]){return Vr({params:t,method:e,jsonrpc:"2.0",id:jr()})}var Lt=class{constructor(e){e instanceof Lt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):fo(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}}},Ao=Ei(_i()),So=class extends Ao.default{};function Kr(){let e=new So;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Hr=Symbol("isPromiEvent");function Ct(e){return!!e[Hr]}function Je(e){let t=Yr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=Kr(),a=Symbol("Promise.then"),l=Symbol("Promise.catch"),p=Symbol("Promise.finally"),h=(y,N)=>(..._)=>{let T=N[y].apply(N,_);return g(T)},g=y=>Object.assign(y,{[Hr]:!0,[a]:y[a]||y.then,[l]:y[l]||y.catch,[p]:y[p]||y.finally,then:h(a,y),catch:h(l,y),finally:h(p,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}function Yr(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var Te=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Re.MAGIC_HANDLE_REQUEST,ut(e)),r=Je((a,l)=>{t.then(p=>{if(o(),p.hasError)l(new Ue(p.payload.error));else if(p.hasResult)a(p.payload.result);else throw vo()}).catch(p=>{o(),l(p)})}),o=this.overlay.on(me.MAGIC_HANDLE_EVENT,a=>{var l;let{response:p}=a.data;if(p.id===e.id&&((l=p.result)==null?void 0:l.event)){let{event:h,params:g=[]}=p.result;r.emit(h,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=B(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function To(e,t){let[r]=e.split(".").map(Number);return r>=t}var xe={"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"},No=class extends Te{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&&To(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&De({method:"auth.loginWithMagicLink()",removalVersions:xe,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:l}=e,p=B(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:l}]);return this.request(p)}loginWithSMS(e){let{phoneNumber:t}=e,r=B(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,l=B(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),p=this.request(l);return!o&&p&&p.on(Ke.Retry,()=>{this.createIntermediaryEvent(Ke.Retry,l.id)()}),!r&&p&&(p.on(Ae.VerifyEmailOtp,h=>{this.createIntermediaryEvent(Ae.VerifyEmailOtp,l.id)(h)}),p.on(Ae.Cancel,()=>{this.createIntermediaryEvent(Ae.Cancel,l.id)()})),p}loginWithCredential(e){let t=e!=null?e:"";if(!e&&Y.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let r=B(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(r)}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}]);return this.request(o)}},Xr={};gi(Xr,{clear:()=>Mo,getItem:()=>se,iterate:()=>zr,key:()=>Lo,keys:()=>Co,length:()=>Oo,removeItem:()=>ke,setItem:()=>he});var ot;function _e(e){return(...t)=>X(this,null,function*(){return ot||(ot=yield Y.configureStorage()),yield ot.ready(),ot[e](...t)})}var se=_e("getItem"),he=_e("setItem"),ke=_e("removeItem"),Mo=_e("clear"),Oo=_e("length"),Lo=_e("key"),Co=_e("keys"),zr=_e("iterate");function $o(){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 Jr="STORE_KEY_PRIVATE_KEY",Tt="STORE_KEY_PUBLIC_JWK",Qr="ECDSA",Po="P-256",Do={name:Qr,namedCurve:Po};function ht(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function xo(){return X(this,null,function*(){let e=yield ko();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield se(Jr);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:$o()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:$r(JSON.stringify(a)),claims:$r(JSON.stringify(o))},p=Fo(`${l.protected}.${l.claims}`),h={name:Qr,hash:{name:"SHA-256"}},g=Wo(new Uint8Array(yield t.sign(h,r,p)));return`${l.protected}.${l.claims}.${g}`})}function ko(){return X(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}return(yield se(Tt))||(yield Uo()),se(Tt)})}function Uo(){return X(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Do,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield he(Jr,t.privateKey),yield he(Tt,r)})}function $r(e){return Zr(Bo(e))}function Fo(e){return new TextEncoder().encode(e)}function Zr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Bo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Wo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),Zr(t)}var $t="ds",Pt="ek",Dt="iv",xt="AES-GCM",Go=256;function kt(){return X(this,null,function*(){let e=[];yield zr((t,r,o)=>{r.startsWith(`${$t}_`)&&e.push(r)});for(let t of e)yield ke(t)})}function en(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 tn(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 jo(){return X(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield se(Dt))||e.getRandomValues(new Uint8Array(12))})}function qo(){return X(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield se(Pt))||(yield e.generateKey({name:xt,length:Go},!1,["encrypt","decrypt"]))})}function Vo(e,t){return X(this,null,function*(){let r=yield jo(),o=yield qo();if(!r||!o||!e)return;let a=tn(e),{subtle:l}=window.crypto,p=yield l.encrypt({name:xt,iv:r},o,a),h=en(p);yield he(`${$t}_${t}`,h),yield he(Pt,o),yield he(Dt,r)})}function Ko(e){return X(this,null,function*(){let t=yield se(`${$t}_${e}`),r=yield se(Dt),o=yield se(Pt);if(!r||!t||!o||!ht())return;let{subtle:a}=window.crypto,l=yield a.decrypt({name:xt,iv:r},o,tn(t));return en(l)})}function Qe(e,t){return t?new URL(e,t):new URL(e)}var Ho=class extends Te{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 Je((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?he(this.localForageIsLoggedInKey,!0):ke(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return ke(this.localForageKey),ke(this.localForageIsLoggedInKey),kt(),Je((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)}getMetadata(){De({method:"user.getMetadata()",removalVersions:xe,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}updateEmail(e){De({method:"user.updateEmail()",removalVersions:xe,useInstead:"auth.updateEmailWithUI()"}).log();let{email:t,showUI:r=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Yo=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Je((t,r)=>X(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ue.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ue.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ue.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ue.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=B(O.Login,[o]),l=this.request(a);l.on(Ce.WalletSelected,h=>this.handleWalletSelected(kr(Nt({},h),{payloadId:a.id}))),l.on("id-token-created",h=>{e.emit("id-token-created",h)});let p=yield l;p.error&&r(p),t(p)}catch(o){r(o)}}));return e}showUI(){return this.request(B(O.ShowUI))}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*(){De({method:"wallet.getInfo()",removalVersions:xe,useInstead:"user.getInfo()"}).log();let e=yield se(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){De({method:"wallet.disconnect()",removalVersions:xe,useInstead:"user.logout()"}).log(),ke(this.localForageKey),kt();let e=B(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){De({method:"wallet.requestUserInfoWithUI()",removalVersions:xe,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 he(this.localForageKey,e.wallet),this.createIntermediaryEvent(Ce.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Ce.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 he(this.localForageKey,e);let r=B(O.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:at,createChainingEmitterMethod:$e}=Kr(),Xo=class extends Te{constructor(){super(...arguments),this.isMagic=!0,this.on=$e("on",this),this.once=$e("once",this),this.addListener=$e("addListener",this),this.off=$e("off",this),this.removeListener=$e("removeListener",this),this.removeAllListeners=$e("removeAllListeners",this),this.emit=at("emit"),this.eventNames=at("eventNames"),this.listeners=at("listeners"),this.listenerCount=at("listenerCount")}sendAsync(e,t){if(!t)throw Eo({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 o=ut(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>kr(Nt({},o.payload),{error:o.hasError?new Ue(o.payload.error):null})))});else{let r=ut(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Re.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Ue(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=_o();return r.log(),new Lt(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}`)}},Pr=["request","overlay","sdk"];function zo(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Te.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var rn=class extends Te{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Je,isPromiEvent:Ct,encodeJSON:Fr,decodeJSON:co,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:ut,storage:Xr};let e=[this,...zo(this)];Pr.forEach(t=>{let r=e.map(p=>Object.getOwnPropertyDescriptor(p,t)),o=r.findIndex(p=>!!p),a=o>0,l=r[o];l&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:l,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw go(t)}}))})}init(e){this.__is_initialized__||(Pr.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.`:"",l=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new ct(this,"DEPRECATION_NOTICE",l)}createWarning(e,t){return new ct(this,e,t)}createError(e,t,r){return new dt(this,e,t,r)}},Jo=class extends rn{},Se=class extends rn{};Se.Internal=Jo,Se.Anonymous="anonymous extension";var Qo=class extends Te{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 Dr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?eo(io(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function Zo(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(l=>{Dr(l)?(l.init(this),(l.name||l.name!==Se.Anonymous)&&(this[l.name]=l),l instanceof Se.Internal&&(lt(l.config)||(o[l.name]=l.config))):a.push(l)}):Object.keys(r).forEach(l=>{if(Dr(r[l])){r[l].init(this);let p=r[l];this[l]=p,p instanceof Se.Internal&&(lt(p.config)||(o[r[l].name]=p.config))}else a.push(r[l])}),a.length)throw yo(a);return o}var st=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw mo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Io().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=Qe((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new No(this),this.user=new Ho(this),this.wallet=new Yo(this),this.nft=new Qo(this),this.rpcProvider=new Xo(this);let l=ea.call(this,t);this.parameters=Fr(Nt({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:Qe(this.endpoint).host,sdk:po[Y.sdkName],version:a,ext:lt(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{})),this.networkHash=Zo(this.apiKey,t==null?void 0:t.network,lt(l)?void 0:l),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!st.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),st.__overlays__.set(this.parameters,e)}return st.__overlays__.get(this.parameters)}preload(){return X(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Ut=st;Ut.__overlays__=new Map;function ta(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function ra(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=ta(e,o);if(o&&a){let l=new Lt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function na(e,t,r){return X(this,null,function*(){var o;let a=yield se("rt"),l;if(Y.platform==="web")try{l=(o=yield se("jwt"))!=null?o:yield xo()}catch(g){console.error("webcrypto error",g)}let p={msgType:e,payload:t};l&&(p.jwt=l),l&&a&&(p.rt=a);let h=yield Ko(r);return h&&(p.deviceShare=h),p})}function ia(e){return X(this,null,function*(){!e.data.rt||(yield he("rt",e.data.rt))})}var nn=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 Yr((r,o)=>X(this,null,function*(){if(!this.isConnectedToInternet){let v=Ot();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],l=Array.isArray(t)?t.map(v=>v.id):[],p=yield na(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(p);let h=v=>y=>{var N;let{id:_,response:T}=ra(t,y);if(ia(y),((N=T==null?void 0:T.payload.error)==null?void 0:N.message)==="User denied account access.")kt();else if(y.data.deviceShare){let{deviceShare:L}=y.data;Vo(L,this.networkHash)}_&&T&&Array.isArray(t)&&l.includes(_)?(a.push(T),a.length===t.length&&(v(),r(a))):_&&T&&!Array.isArray(t)&&_===t.id&&(v(),r(T))},g=this.on(me.MAGIC_HANDLE_RESPONSE,h(()=>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(me.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(me.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(me.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Ft={};dr(Ft,{DeepLinkPage:()=>mr,DeviceVerificationEventEmit:()=>Ke,DeviceVerificationEventOnReceived:()=>Er,EthChainType:()=>_r,Events:()=>Ce,Extension:()=>Se,ExtensionError:()=>dt,ExtensionWarning:()=>ct,LoginWithEmailOTPEventEmit:()=>Ae,LoginWithEmailOTPEventOnReceived:()=>yr,LoginWithMagicLinkEventEmit:()=>vr,LoginWithMagicLinkEventOnReceived:()=>gr,MagicIncomingWindowMessage:()=>me,MagicOutgoingWindowMessage:()=>Re,MagicPayloadMethod:()=>O,RPCError:()=>Ue,RPCErrorCode:()=>Le,RecoveryMethodType:()=>Ir,SDKError:()=>ve,SDKErrorCode:()=>pe,SDKWarning:()=>Be,SDKWarningCode:()=>be,Wallets:()=>ue,isPromiEvent:()=>Ct});var vt=pr(an()),Wt=pr(ln());var oa={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function aa(e){for(let[t,r]of Object.entries(oa))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 mt=class extends nn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(sa(encodeURIComponent(this.parameters)))Gr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=Qe(this.endpoint).host,a.title="Secure Modal",a.src=Qe(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,aa(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(o=r.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(r)}})}showOverlay(){return Oe(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return Oe(this,null,function*(){var o;let r=yield this.iframe;r.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return Oe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Ot()})}};var la=Object.assign(Wr(Ut,{platform:"web",sdkName:"magic-sdk",version:"21.4.1",defaultEndpoint:"https://auth.magic.link/",ViewController:mt,configureStorage:()=>Oe(void 0,null,function*(){let e=vt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Wt),yield e.setDriver([vt.default.INDEXEDDB,vt.default.LOCALSTORAGE,Wt._driver]),e})}),ur({},Ft)),ca=la;return li(ua);})();
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": "21.5.0-canary.689.7292618936.0",
3
+ "version": "21.5.0-canary.689.7302803005.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": "17.5.0-canary.689.7292618936.0",
33
- "@magic-sdk/provider": "21.5.0-canary.689.7292618936.0",
32
+ "@magic-sdk/commons": "17.5.0-canary.689.7302803005.0",
33
+ "@magic-sdk/provider": "21.5.0-canary.689.7302803005.0",
34
34
  "@magic-sdk/types": "^17.3.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": "b0e69ce4ce60461b7e84ac68ddadf6e0d8b3ff43"
43
+ "gitHead": "dd47f5403061d39cf5de619886ab4f8f551f6bc3"
44
44
  }