magic-sdk 21.3.2-canary.678.7093911072.0 → 21.3.2-canary.678.7094079897.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 +5 -5
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(he.IncompatibleExtensions,t)}function go(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(he.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
4
4
  Expected: \`${e.expected}\`
5
- Received: \`${e.received}\``)}function Wr(){return new Be(be.DuplicateIframe,"Duplicate iframes found.")}function yo(){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 Eo(){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*_o(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Io=_o();function Fr(){return Io.next().value}var Gr=Symbol("Payload pre-processed by Magic SDK");function jr(e){return Object.defineProperty(e,Gr,{value:!0,enumerable:!1}),e}function wo(e){return!!e[Gr]}function lt(e){var t,r,o;return wo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Fr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],jr(e)),e}function W(e,t=[]){return jr({params:t,method:e,jsonrpc:"2.0",id:Fr()})}var Ot=class{constructor(e){e instanceof Ot?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):co(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}}},bo=gi(yi()),Ro=class extends bo.default{};function Vr(){let e=new Ro;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var qr=Symbol("isPromiEvent");function Lt(e){return!!e[qr]}function $t(e){let t=Kr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=Vr(),a=Symbol("Promise.then"),l=Symbol("Promise.catch"),p=Symbol("Promise.finally"),h=(y,T)=>(..._)=>{let N=T[y].apply(T,_);return g(N)},g=y=>Object.assign(y,{[qr]:!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 Kr(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,lt(e)),r=$t((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 po()}).catch(p=>{o(),l(p)})}),o=this.overlay.on(pe.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=W(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Ao(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"},So=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&&Ao(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=W(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=W(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=W(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),p=this.request(l);return!o&&p&&p.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.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=W(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=W(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}},Hr={};mi(Hr,{clear:()=>To,getItem:()=>fe,iterate:()=>Yr,key:()=>Mo,keys:()=>Oo,length:()=>No,removeItem:()=>ft,setItem:()=>me});var nt;function _e(e){return(...t)=>J(this,null,function*(){return nt||(nt=yield Y.configureStorage()),yield nt.ready(),nt[e](...t)})}var fe=_e("getItem"),me=_e("setItem"),ft=_e("removeItem"),To=_e("clear"),No=_e("length"),Mo=_e("key"),Oo=_e("keys"),Yr=_e("iterate");function Lo(){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 Xr="STORE_KEY_PRIVATE_KEY",St="STORE_KEY_PUBLIC_JWK",zr="ECDSA",$o="P-256",Co={name:zr,namedCurve:$o};function dt(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Po(){return J(this,null,function*(){let e=yield Do();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield fe(Xr);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Lo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:Lr(JSON.stringify(a)),claims:Lr(JSON.stringify(o))},p=Uo(`${l.protected}.${l.claims}`),h={name:zr,hash:{name:"SHA-256"}},g=Bo(new Uint8Array(yield t.sign(h,r,p)));return`${l.protected}.${l.claims}.${g}`})}function Do(){return J(this,null,function*(){if(!dt()){console.info("webcrypto is not supported");return}return(yield fe(St))||(yield xo()),fe(St)})}function xo(){return J(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Co,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield me(Xr,t.privateKey),yield me(St,r)})}function Lr(e){return Jr(ko(e))}function Uo(e){return new TextEncoder().encode(e)}function Jr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function ko(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Bo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),Jr(t)}var Ct="ds",Qr="ek",Zr="iv",Pt="AES-GCM",Wo=256;function Dt(){Yr((e,t,r)=>{t.startsWith(`${Ct}_`)&&ft(t)})}function Fo(e){let t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let o=0,a=e.length;o<a;o++)r[o]=e.charCodeAt(o);return t}function Go(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 jo(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 Vo(e){return new TextDecoder("utf-8").decode(e)}function qo(){return J(this,null,function*(){if(!dt()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return e?e.getRandomValues(new Uint8Array(12)):void 0})}function Ko(){return J(this,null,function*(){if(!dt()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return e?e.generateKey({name:Pt,length:Wo},!1,["encrypt","decrypt"]):void 0})}function Ho(e){return J(this,null,function*(){let t=yield qo(),r=yield Ko();if(!t||!r||!e)return{iv:void 0,encryptionKey:void 0,encryptedDeviceShare:void 0};let{subtle:o}=window.crypto,a=Go(yield o.encrypt({name:Pt,iv:t},r,Fo(e)));return{encryptionKey:r,encryptedDeviceShare:a,iv:t}})}function Yo(e,t,r){return J(this,null,function*(){if(!e||!dt())return;let o=new Uint8Array(r.split(",").map(Number)),{subtle:a}=window.crypto;if(!o||!e||!t||!a)return;let l=yield a.decrypt({name:Pt,iv:o},t,jo(e));return Vo(l)})}var Xo=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}getIdToken(e){let t=W(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return J(this,null,function*(){let e=yield fe(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){let e=W(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn);return this.request(e)}logout(){ft(this.localForageKey),Dt();let e=W(this.sdk.testMode?O.LogoutTestMode:O.Logout);return this.request(e)}requestInfoWithUI(e){let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(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=W(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=W(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}};function ze(e,t){return t?new URL(e,t):new URL(e)}var zo=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=$t((t,r)=>J(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ce.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ce.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ce.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ce.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=W(O.Login,[o]),l=this.request(a);l.on($e.WalletSelected,h=>this.handleWalletSelected(Dr(Tt({},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(W(O.ShowUI))}showAddress(){return this.request(W(O.ShowAddress))}showSendTokensUI(){return this.request(W(O.ShowSendTokensUI))}showOnRamp(){return this.request(W(O.ShowOnRamp))}showNFTs(){return this.request(W(O.ShowNFTs))}showBalances(){return this.request(W(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(O.SendGaslessTransaction,[e,t]))}getInfo(){return J(this,null,function*(){De({method:"wallet.getInfo()",removalVersions:xe,useInstead:"user.getInfo()"}).log();let e=yield fe(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){De({method:"wallet.disconnect()",removalVersions:xe,useInstead:"user.logout()"}).log(),ft(this.localForageKey),Dt();let e=W(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){De({method:"wallet.requestUserInfoWithUI()",removalVersions:xe,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return J(this,null,function*(){switch(yield fe(this.localForageKey)){case ce.MetaMask:return this.getMetaMaskProvider();case ce.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 ce.MetaMask:return this.connectToMetaMask();case ce.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=W("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return J(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield me(this.localForageKey,e.wallet),this.createIntermediaryEvent($e.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent($e.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return J(this,null,function*(){let t;e===ce.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ce.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield me(this.localForageKey,e);let r=W(O.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:it,createChainingEmitterMethod:Ce}=Vr(),Jo=class extends Te{constructor(){super(...arguments),this.isMagic=!0,this.on=Ce("on",this),this.once=Ce("once",this),this.addListener=Ce("addListener",this),this.off=Ce("off",this),this.removeListener=Ce("removeListener",this),this.removeAllListeners=Ce("removeAllListeners",this),this.emit=it("emit"),this.eventNames=it("eventNames"),this.listeners=it("listeners"),this.listenerCount=it("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 o=lt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>Dr(Tt({},o.payload),{error:o.hasError?new Ue(o.payload.error):null})))});else{let r=lt(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=W(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=yo();return r.log(),new Ot(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(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}`)}},$r=["request","overlay","sdk"];function Qo(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Te.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var en=class extends Te{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:$t,isPromiEvent:Lt,encodeJSON:Ur,decodeJSON:so,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:lt,storage:Hr};let e=[this,...Qo(this)];$r.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 mo(t)}}))})}init(e){this.__is_initialized__||($r.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 st(this,"DEPRECATION_NOTICE",l)}createWarning(e,t){return new st(this,e,t)}createError(e,t,r){return new ut(this,e,t,r)}},Zo=class extends en{},Se=class extends en{};Se.Internal=Zo,Se.Anonymous="anonymous extension";var ea=class extends Te{purchase(e){let t=W(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(O.NFTTransfer,[e]);return this.request(t)}};function Cr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?Qi(ro(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function ta(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 ra(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(l=>{Cr(l)?(l.init(this),(l.name||l.name!==Se.Anonymous)&&(this[l.name]=l),l instanceof Se.Internal&&(at(l.config)||(o[l.name]=l.config))):a.push(l)}):Object.keys(r).forEach(l=>{if(Cr(r[l])){r[l].init(this);let p=r[l];this[l]=p,p instanceof Se.Internal&&(at(p.config)||(o[r[l].name]=p.config))}else a.push(r[l])}),a.length)throw vo(a);return o}var ot=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw ho();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Eo().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.endpoint=ze((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new So(this),this.user=new Xo(this),this.wallet=new zo(this),this.nft=new ea(this),this.rpcProvider=new Jo(this);let l=ra.call(this,t);this.parameters=Ur(Tt({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:ze(this.endpoint).host,sdk:fo[Y.sdkName],version:a,ext:at(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{})),this.networkHash=ta(this.apiKey,t==null?void 0:t.network,at(l)?void 0:l),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!ot.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),ot.__overlays__.set(this.parameters,e)}return ot.__overlays__.get(this.parameters)}preload(){return J(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},xt=ot;xt.__overlays__=new Map;function na(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function ia(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=na(e,o);if(o&&a){let l=new Ot(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function oa(e,t,r){return J(this,null,function*(){var o;let a=yield fe("rt"),l;if(Y.platform==="web")try{l=(o=yield fe("jwt"))!=null?o:yield Po()}catch(y){console.error("webcrypto error",y)}let p={msgType:e,payload:t};l&&(p.jwt=l),l&&a&&(p.rt=a);let h=yield fe(`${Ct}_${r}`),g=yield fe(Zr),v=yield fe(Qr);if(h&&g&&v){let y=yield Yo(h,v,g);p.deviceShare=y}return p})}function aa(e){return J(this,null,function*(){!e.data.rt||(yield me("rt",e.data.rt))})}function sa(e,t){return J(this,null,function*(){if(!e.data.deviceShare)return;let r=e.data.deviceShare,{encryptionKey:o,encryptedDeviceShare:a,iv:l}=yield Ho(r);!o||!a||!l||(yield me(`${Ct}_${t}`,a),yield me(Qr,o),yield me(Zr,l))})}var tn=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.listen()}post(e,t){return J(this,null,function*(){return Kr((r,o)=>J(this,null,function*(){if(!this.isConnectedToInternet){let v=Mt();o(v)}yield this.checkIsReadyForRequest;let a=[],l=Array.isArray(t)?t.map(v=>v.id):[],p=yield oa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(p);let h=v=>y=>{var T;let{id:_,response:N}=ia(t,y);aa(y),((T=y.data.response.error)==null?void 0:T.message)==="User denied account access."?Dt():sa(y,this.networkHash),_&&N&&Array.isArray(t)&&l.includes(_)?(a.push(N),a.length===t.length&&(v(),r(a))):_&&N&&!Array.isArray(t)&&_===t.id&&(v(),r(N))},g=this.on(pe.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=>{this.on(pe.MAGIC_OVERLAY_READY,()=>{e()})})}listen(){this.on(pe.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(pe.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Ut={};ur(Ut,{DeepLinkPage:()=>hr,DeviceVerificationEventEmit:()=>qe,DeviceVerificationEventOnReceived:()=>gr,EthChainType:()=>yr,Events:()=>$e,Extension:()=>Se,ExtensionError:()=>ut,ExtensionWarning:()=>st,LoginWithEmailOTPEventEmit:()=>Ae,LoginWithEmailOTPEventOnReceived:()=>vr,LoginWithMagicLinkEventEmit:()=>pr,LoginWithMagicLinkEventOnReceived:()=>mr,MagicIncomingWindowMessage:()=>pe,MagicOutgoingWindowMessage:()=>Re,MagicPayloadMethod:()=>O,RPCError:()=>Ue,RPCErrorCode:()=>Le,RecoveryMethodType:()=>Er,SDKError:()=>ve,SDKErrorCode:()=>he,SDKWarning:()=>Be,SDKWarningCode:()=>be,Wallets:()=>ce,isPromiEvent:()=>Lt});var mt=dr(nn()),Bt=dr(an());var la={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function ca(e){for(let[t,r]of Object.entries(la))e.style[t]=r}function ua(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var pt=class extends tn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(ua(encodeURIComponent(this.parameters)))Wr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=ze(this.endpoint).host,a.title="Secure Modal",a.src=ze(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,ca(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 Mt()})}};var fa=Object.assign(Br(xt,{platform:"web",sdkName:"magic-sdk",version:"21.3.1",defaultEndpoint:"https://auth.magic.link/",ViewController:pt,configureStorage:()=>Oe(void 0,null,function*(){let e=mt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Bt),yield e.setDriver([mt.default.INDEXEDDB,mt.default.LOCALSTORAGE,Bt._driver]),e})}),lr({},Ut)),da=fa;return ai(ha);})();
5
+ Received: \`${e.received}\``)}function Wr(){return new Be(be.DuplicateIframe,"Duplicate iframes found.")}function yo(){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 Eo(){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*_o(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Io=_o();function Fr(){return Io.next().value}var Gr=Symbol("Payload pre-processed by Magic SDK");function jr(e){return Object.defineProperty(e,Gr,{value:!0,enumerable:!1}),e}function wo(e){return!!e[Gr]}function lt(e){var t,r,o;return wo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Fr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],jr(e)),e}function W(e,t=[]){return jr({params:t,method:e,jsonrpc:"2.0",id:Fr()})}var Ot=class{constructor(e){e instanceof Ot?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):co(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}}},bo=gi(yi()),Ro=class extends bo.default{};function Vr(){let e=new Ro;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var qr=Symbol("isPromiEvent");function Lt(e){return!!e[qr]}function $t(e){let t=Kr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=Vr(),a=Symbol("Promise.then"),l=Symbol("Promise.catch"),p=Symbol("Promise.finally"),h=(y,T)=>(..._)=>{let N=T[y].apply(T,_);return g(N)},g=y=>Object.assign(y,{[qr]:!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 Kr(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,lt(e)),r=$t((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 po()}).catch(p=>{o(),l(p)})}),o=this.overlay.on(pe.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=W(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Ao(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"},So=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&&Ao(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=W(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=W(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=W(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),p=this.request(l);return!o&&p&&p.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.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=W(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=W(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}},Hr={};mi(Hr,{clear:()=>To,getItem:()=>fe,iterate:()=>Yr,key:()=>Mo,keys:()=>Oo,length:()=>No,removeItem:()=>ft,setItem:()=>me});var nt;function _e(e){return(...t)=>J(this,null,function*(){return nt||(nt=yield Y.configureStorage()),yield nt.ready(),nt[e](...t)})}var fe=_e("getItem"),me=_e("setItem"),ft=_e("removeItem"),To=_e("clear"),No=_e("length"),Mo=_e("key"),Oo=_e("keys"),Yr=_e("iterate");function Lo(){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 Xr="STORE_KEY_PRIVATE_KEY",St="STORE_KEY_PUBLIC_JWK",zr="ECDSA",$o="P-256",Co={name:zr,namedCurve:$o};function dt(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Po(){return J(this,null,function*(){let e=yield Do();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield fe(Xr);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Lo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:Lr(JSON.stringify(a)),claims:Lr(JSON.stringify(o))},p=Uo(`${l.protected}.${l.claims}`),h={name:zr,hash:{name:"SHA-256"}},g=Bo(new Uint8Array(yield t.sign(h,r,p)));return`${l.protected}.${l.claims}.${g}`})}function Do(){return J(this,null,function*(){if(!dt()){console.info("webcrypto is not supported");return}return(yield fe(St))||(yield xo()),fe(St)})}function xo(){return J(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Co,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield me(Xr,t.privateKey),yield me(St,r)})}function Lr(e){return Jr(ko(e))}function Uo(e){return new TextEncoder().encode(e)}function Jr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function ko(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Bo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),Jr(t)}var Ct="ds",Qr="ek",Zr="iv",Pt="AES-GCM",Wo=256;function Dt(){Yr((e,t,r)=>{t.startsWith(`${Ct}_`)&&ft(t)})}function Fo(e){let t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let o=0,a=e.length;o<a;o++)r[o]=e.charCodeAt(o);return t}function Go(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 jo(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 Vo(e){return new TextDecoder("utf-8").decode(e)}function qo(){return J(this,null,function*(){if(!dt()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return e?e.getRandomValues(new Uint8Array(12)):void 0})}function Ko(){return J(this,null,function*(){if(!dt()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return e?e.generateKey({name:Pt,length:Wo},!1,["encrypt","decrypt"]):void 0})}function Ho(e){return J(this,null,function*(){let t=yield qo(),r=yield Ko();if(!t||!r||!e)return{iv:void 0,encryptionKey:void 0,encryptedDeviceShare:void 0};let{subtle:o}=window.crypto,a=yield o.encrypt({name:Pt,iv:t},r,Fo(e)),l=Go(a);return{encryptionKey:r,encryptedDeviceShare:l,iv:JSON.stringify(Array.from(t))}})}function Yo(e,t,r){return J(this,null,function*(){if(!e||!dt())return;let o=new Uint8Array(JSON.parse(r)),{subtle:a}=window.crypto;if(!o||!e||!t||!a)return;let l=yield a.decrypt({name:Pt,iv:o},t,jo(e));return Vo(l)})}var Xo=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}getIdToken(e){let t=W(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return J(this,null,function*(){let e=yield fe(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){let e=W(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn);return this.request(e)}logout(){ft(this.localForageKey),Dt();let e=W(this.sdk.testMode?O.LogoutTestMode:O.Logout);return this.request(e)}requestInfoWithUI(e){let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(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=W(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=W(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}};function ze(e,t){return t?new URL(e,t):new URL(e)}var zo=class extends Te{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=$t((t,r)=>J(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ce.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ce.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ce.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ce.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=W(O.Login,[o]),l=this.request(a);l.on($e.WalletSelected,h=>this.handleWalletSelected(Dr(Tt({},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(W(O.ShowUI))}showAddress(){return this.request(W(O.ShowAddress))}showSendTokensUI(){return this.request(W(O.ShowSendTokensUI))}showOnRamp(){return this.request(W(O.ShowOnRamp))}showNFTs(){return this.request(W(O.ShowNFTs))}showBalances(){return this.request(W(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(O.SendGaslessTransaction,[e,t]))}getInfo(){return J(this,null,function*(){De({method:"wallet.getInfo()",removalVersions:xe,useInstead:"user.getInfo()"}).log();let e=yield fe(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){De({method:"wallet.disconnect()",removalVersions:xe,useInstead:"user.logout()"}).log(),ft(this.localForageKey),Dt();let e=W(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){De({method:"wallet.requestUserInfoWithUI()",removalVersions:xe,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return J(this,null,function*(){switch(yield fe(this.localForageKey)){case ce.MetaMask:return this.getMetaMaskProvider();case ce.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 ce.MetaMask:return this.connectToMetaMask();case ce.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=W("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return J(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield me(this.localForageKey,e.wallet),this.createIntermediaryEvent($e.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent($e.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return J(this,null,function*(){let t;e===ce.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ce.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield me(this.localForageKey,e);let r=W(O.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:it,createChainingEmitterMethod:Ce}=Vr(),Jo=class extends Te{constructor(){super(...arguments),this.isMagic=!0,this.on=Ce("on",this),this.once=Ce("once",this),this.addListener=Ce("addListener",this),this.off=Ce("off",this),this.removeListener=Ce("removeListener",this),this.removeAllListeners=Ce("removeAllListeners",this),this.emit=it("emit"),this.eventNames=it("eventNames"),this.listeners=it("listeners"),this.listenerCount=it("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 o=lt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>Dr(Tt({},o.payload),{error:o.hasError?new Ue(o.payload.error):null})))});else{let r=lt(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=W(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=yo();return r.log(),new Ot(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(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}`)}},$r=["request","overlay","sdk"];function Qo(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Te.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var en=class extends Te{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:$t,isPromiEvent:Lt,encodeJSON:Ur,decodeJSON:so,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:lt,storage:Hr};let e=[this,...Qo(this)];$r.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 mo(t)}}))})}init(e){this.__is_initialized__||($r.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 st(this,"DEPRECATION_NOTICE",l)}createWarning(e,t){return new st(this,e,t)}createError(e,t,r){return new ut(this,e,t,r)}},Zo=class extends en{},Se=class extends en{};Se.Internal=Zo,Se.Anonymous="anonymous extension";var ea=class extends Te{purchase(e){let t=W(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(O.NFTTransfer,[e]);return this.request(t)}};function Cr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?Qi(ro(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function ta(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 ra(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(l=>{Cr(l)?(l.init(this),(l.name||l.name!==Se.Anonymous)&&(this[l.name]=l),l instanceof Se.Internal&&(at(l.config)||(o[l.name]=l.config))):a.push(l)}):Object.keys(r).forEach(l=>{if(Cr(r[l])){r[l].init(this);let p=r[l];this[l]=p,p instanceof Se.Internal&&(at(p.config)||(o[r[l].name]=p.config))}else a.push(r[l])}),a.length)throw vo(a);return o}var ot=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw ho();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Eo().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.endpoint=ze((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new So(this),this.user=new Xo(this),this.wallet=new zo(this),this.nft=new ea(this),this.rpcProvider=new Jo(this);let l=ra.call(this,t);this.parameters=Ur(Tt({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:ze(this.endpoint).host,sdk:fo[Y.sdkName],version:a,ext:at(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{})),this.networkHash=ta(this.apiKey,t==null?void 0:t.network,at(l)?void 0:l),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!ot.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),ot.__overlays__.set(this.parameters,e)}return ot.__overlays__.get(this.parameters)}preload(){return J(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},xt=ot;xt.__overlays__=new Map;function na(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function ia(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=na(e,o);if(o&&a){let l=new Ot(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function oa(e,t,r){return J(this,null,function*(){var o;let a=yield fe("rt"),l;if(Y.platform==="web")try{l=(o=yield fe("jwt"))!=null?o:yield Po()}catch(y){console.error("webcrypto error",y)}let p={msgType:e,payload:t};l&&(p.jwt=l),l&&a&&(p.rt=a);let h=yield fe(`${Ct}_${r}`),g=yield fe(Zr),v=yield fe(Qr);if(h&&g&&v){let y=yield Yo(h,v,g);p.deviceShare=y}return p})}function aa(e){return J(this,null,function*(){!e.data.rt||(yield me("rt",e.data.rt))})}function sa(e,t){return J(this,null,function*(){if(!e.data.deviceShare)return;let r=e.data.deviceShare,{encryptionKey:o,encryptedDeviceShare:a,iv:l}=yield Ho(r);!o||!a||!l||(console.warn("encryptedDeviceShare",a),yield me(`${Ct}_${t}`,a),yield me(Qr,o),yield me(Zr,l))})}var tn=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.listen()}post(e,t){return J(this,null,function*(){return Kr((r,o)=>J(this,null,function*(){if(!this.isConnectedToInternet){let v=Mt();o(v)}yield this.checkIsReadyForRequest;let a=[],l=Array.isArray(t)?t.map(v=>v.id):[],p=yield oa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(p);let h=v=>y=>{var T;let{id:_,response:N}=ia(t,y);aa(y),((T=y.data.response.error)==null?void 0:T.message)==="User denied account access."?Dt():sa(y,this.networkHash),_&&N&&Array.isArray(t)&&l.includes(_)?(a.push(N),a.length===t.length&&(v(),r(a))):_&&N&&!Array.isArray(t)&&_===t.id&&(v(),r(N))},g=this.on(pe.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=>{this.on(pe.MAGIC_OVERLAY_READY,()=>{e()})})}listen(){this.on(pe.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(pe.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Ut={};ur(Ut,{DeepLinkPage:()=>hr,DeviceVerificationEventEmit:()=>qe,DeviceVerificationEventOnReceived:()=>gr,EthChainType:()=>yr,Events:()=>$e,Extension:()=>Se,ExtensionError:()=>ut,ExtensionWarning:()=>st,LoginWithEmailOTPEventEmit:()=>Ae,LoginWithEmailOTPEventOnReceived:()=>vr,LoginWithMagicLinkEventEmit:()=>pr,LoginWithMagicLinkEventOnReceived:()=>mr,MagicIncomingWindowMessage:()=>pe,MagicOutgoingWindowMessage:()=>Re,MagicPayloadMethod:()=>O,RPCError:()=>Ue,RPCErrorCode:()=>Le,RecoveryMethodType:()=>Er,SDKError:()=>ve,SDKErrorCode:()=>he,SDKWarning:()=>Be,SDKWarningCode:()=>be,Wallets:()=>ce,isPromiEvent:()=>Lt});var mt=dr(nn()),Bt=dr(an());var la={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function ca(e){for(let[t,r]of Object.entries(la))e.style[t]=r}function ua(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var pt=class extends tn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(ua(encodeURIComponent(this.parameters)))Wr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=ze(this.endpoint).host,a.title="Secure Modal",a.src=ze(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,ca(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 Mt()})}};var fa=Object.assign(Br(xt,{platform:"web",sdkName:"magic-sdk",version:"21.3.1",defaultEndpoint:"https://auth.magic.link/",ViewController:pt,configureStorage:()=>Oe(void 0,null,function*(){let e=mt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Bt),yield e.setDriver([mt.default.INDEXEDDB,mt.default.LOCALSTORAGE,Bt._driver]),e})}),lr({},Ut)),da=fa;return ai(ha);})();
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.3.2-canary.678.7093911072.0",
3
+ "version": "21.3.2-canary.678.7094079897.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,9 +29,9 @@
29
29
  ]
30
30
  },
31
31
  "dependencies": {
32
- "@magic-sdk/commons": "17.3.2-canary.678.7093911072.0",
33
- "@magic-sdk/provider": "21.3.2-canary.678.7093911072.0",
34
- "@magic-sdk/types": "17.2.1-canary.678.7093911072.0",
32
+ "@magic-sdk/commons": "17.3.2-canary.678.7094079897.0",
33
+ "@magic-sdk/provider": "21.3.2-canary.678.7094079897.0",
34
+ "@magic-sdk/types": "17.2.1-canary.678.7094079897.0",
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": "6d96b2d4cff7235a5fba3db3a9eecba0fcfd7b4f"
43
+ "gitHead": "cf734e0d787fd2cb7fe6a38b5fc505651967719a"
44
44
  }