@magic-sdk/provider 18.4.1 → 18.4.2-canary.593.5648237905.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -2,5 +2,5 @@
2
2
  - Extension \`${t.name}\` supports version(s) \`${r}\``:r||(e+=`
3
3
  - Extension \`${t.name}\` does not support ${m.platform} environments.`)}),new C(N.SDKErrorCode.IncompatibleExtensions,e)}function Je(n){let e=t=>{let r=t+1,o=r%10,s=r%100;return o===1&&s!==11?`${r}st`:o===2&&s!==12?`${r}nd`:o===3&&s!==13?`${r}rd`:`${r}th`};return new C(N.SDKErrorCode.InvalidArgument,`Invalid ${e(n.argument)} argument given to \`${n.procedure}\`.
4
4
  Expected: \`${n.expected}\`
5
- Received: \`${n.received}\``)}function $n(){return new F(N.SDKWarningCode.DuplicateIframe,"Duplicate iframes found.")}function Fe(){return new F(N.SDKWarningCode.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 Ge(){return new F(N.SDKWarningCode.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 \`${m.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function v(n){let{method:e,removalVersions:t,useInstead:r}=n,o=t[m.sdkName],s=r?` Use \`${r}\` instead.`:"",a=`\`${e}\` will be removed from \`${m.sdkName}\` in version \`${o}\`.${s}`;return new F(N.SDKWarningCode.DeprecationNotice,a)}var $=require("@magic-sdk/types");var H=require("@magic-sdk/types");function*An(){let n=0;for(;;)n<Number.MAX_SAFE_INTEGER?yield++n:n=0}var Cn=An();function ge(){return Cn.next().value}var gt=Symbol("Payload pre-processed by Magic SDK");function yt(n){return Object.defineProperty(n,gt,{value:!0,enumerable:!1}),n}function Sn(n){return!!n[gt]}function K(n){var e,t,r;return Sn(n)||(n.jsonrpc=(e=n.jsonrpc)!=null?e:"2.0",n.id=ge(),n.method=(t=n.method)!=null?t:"noop",n.params=(r=n.params)!=null?r:[],yt(n)),n}function p(n,e=[]){return yt({params:e,method:n,jsonrpc:"2.0",id:ge()})}var W=class{constructor(e){e instanceof W?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):_e(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}}};var Tt=kt(vt()),Re=class extends Tt.default{};function oe(){let n=new Re;return{emitter:n,createChainingEmitterMethod:(r,o)=>(...s)=>(n[r].apply(n,s),o),createBoundEmitterMethod:r=>(...o)=>n[r].apply(n,o)}}var It=Symbol("isPromiEvent");function je(n){return!!n[It]}function j(n){let e=ve(n),{createBoundEmitterMethod:t,createChainingEmitterMethod:r}=oe(),o=Symbol("Promise.then"),s=Symbol("Promise.catch"),a=Symbol("Promise.finally"),i=(u,d)=>(...w)=>{let q=d[u].apply(d,w);return l(q)},l=u=>Object.assign(u,{[It]:!0,[o]:u[o]||u.then,[s]:u[s]||u.catch,[a]:u[a]||u.finally,then:i(o,u),catch:i(s,u),finally:i(a,u),on:r("on",u),once:r("once",u),addListener:r("addListener",u),off:r("off",u),removeListener:r("removeListener",u),removeAllListeners:r("removeAllListeners",u),emit:t("emit"),eventNames:t("eventNames"),listeners:t("listeners"),listenerCount:t("listenerCount")}),c=l(e.then(u=>(c.emit("done",u),c.emit("settled"),u),u=>{throw c.emit("error",u),c.emit("settled"),u}));return c}function ve(n){return new Promise((e,t)=>{let r=n(e,t);Promise.resolve(r).catch(t)})}var M=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(H.MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST,K(e)),r=j((s,a)=>{t.then(i=>{if(o(),i.hasError)a(new S(i.payload.error));else if(i.hasResult)s(i.payload.result);else throw De()}).catch(i=>{o(),a(i)})}),o=this.overlay.on(H.MagicIncomingWindowMessage.MAGIC_HANDLE_EVENT,s=>{var i;let{response:a}=s.data;if(a.id===e.id&&((i=a.result)==null?void 0:i.event)){let{event:l,params:c=[]}=a.result;r.emit(l,...c)}});return r}createIntermediaryEvent(e,t){return o=>{let s=p(H.MagicPayloadMethod.IntermediaryEvent,[{payloadId:t,eventType:e,args:o}]);this.request(s)}}};function Be(n,e){let[t]=n.split(".").map(Number);return t>=e}var x={"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"},Te=class extends M{loginWithMagicLink(e){let t=m.sdkName==="@magic-sdk/react-native"||m.sdkName==="@magic-sdk/react-native-bare"||m.sdkName==="@magic-sdk/react-native-expo";if(t&&Be(m.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");v({method:"auth.loginWithMagicLink()",removalVersions:x,useInstead:t?"@magic-ext/auth auth.loginWithEmailOTP()":"@magic-ext/auth auth.loginWithMagicLink()"}).log();let{email:r,showUI:o=!0,redirectURI:s}=e,a=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithMagicLinkTestMode:$.MagicPayloadMethod.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:s}]);return this.request(a)}loginWithSMS(e){v({method:"auth.loginWithSMS()",removalVersions:x,useInstead:"@magic-ext/auth auth.loginWithSMS()"}).log();let{phoneNumber:t}=e,r=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithSmsTestMode:$.MagicPayloadMethod.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){v({method:"auth.loginWithEmailOTP()",removalVersions:x,useInstead:"@magic-ext/auth auth.loginWithEmailOTP()"}).log();let{email:t,showUI:r}=e,o=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithEmailOTPTestMode:$.MagicPayloadMethod.LoginWithEmailOTP,[{email:t,showUI:r}]);if(!r){let s=this.request(o);return s&&(s.on("verify-email-otp",a=>{this.createIntermediaryEvent("verify-email-otp",o.id)(a)}),s.on("cancel",()=>{this.createIntermediaryEvent("cancel",o.id)()})),s}return this.request(o)}loginWithCredential(e){v({method:"auth.loginWithCredential()",removalVersions:x,useInstead:"@magic-ext/auth auth.loginWithCredential()"}).log();let t=e!=null?e:"";if(!e&&m.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let r=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithCredentialTestMode:$.MagicPayloadMethod.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){v({method:"auth.setAuthorizationToken()",removalVersions:x,useInstead:"@magic-ext/auth auth.setAuthorizationToken()"}).log();let t=p($.MagicPayloadMethod.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){v({method:"auth.updateEmailWithUI()",removalVersions:x,useInstead:"@magic-ext/auth auth.updateEmailWithUI()"}).log();let{email:t,showUI:r=!0}=e,o=p(this.sdk.testMode?$.MagicPayloadMethod.UpdateEmailTestMode:$.MagicPayloadMethod.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}updatePhoneNumberWithUI(){v({method:"auth.updatePhoneNumberWithUI()",removalVersions:x,useInstead:"@magic-ext/auth auth.updatePhoneNumberWithUI()"}).log();let e=p(this.sdk.testMode?$.MagicPayloadMethod.UpdatePhoneNumberTestMode:$.MagicPayloadMethod.UpdatePhoneNumber);return this.request(e)}};var g=require("@magic-sdk/types");var z={};tt(z,{clear:()=>_n,getItem:()=>A,iterate:()=>Wn,key:()=>qn,keys:()=>Dn,length:()=>kn,removeItem:()=>J,setItem:()=>k});var Ie;function U(n){return(...e)=>E(this,null,function*(){return Ie||(Ie=yield m.configureStorage()),yield Ie.ready(),Ie[n](...e)})}var A=U("getItem"),k=U("setItem"),J=U("removeItem"),_n=U("clear"),kn=U("length"),qn=U("key"),Dn=U("keys"),Wn=U("iterate");var Pe=class extends M{constructor(){super(...arguments);this.localForageKey="mc_active_wallet"}getIdToken(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.GetIdTokenTestMode:g.MagicPayloadMethod.GetIdToken,[t]);return this.request(r)}generateIdToken(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.GenerateIdTokenTestMode:g.MagicPayloadMethod.GenerateIdToken,[t]);return this.request(r)}getInfo(){return E(this,null,function*(){let t=yield A(this.localForageKey),r=p(g.MagicPayloadMethod.GetInfo,[{walletType:t}]);return this.request(r)})}isLoggedIn(){let t=p(this.sdk.testMode?g.MagicPayloadMethod.IsLoggedInTestMode:g.MagicPayloadMethod.IsLoggedIn);return this.request(t)}logout(){J(this.localForageKey);let t=p(this.sdk.testMode?g.MagicPayloadMethod.LogoutTestMode:g.MagicPayloadMethod.Logout);return this.request(t)}requestInfoWithUI(t){let r=p(g.MagicPayloadMethod.RequestUserInfoWithUI,t?[t]:[]);return this.request(r)}showSettings(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.UserSettingsTestMode:g.MagicPayloadMethod.UserSettings,[t]);return this.request(r)}recoverAccount(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.RecoverAccountTestMode:g.MagicPayloadMethod.RecoverAccount,[t]);return this.request(r)}getMetadata(){v({method:"user.getMetadata()",removalVersions:x,useInstead:"user.getInfo()"}).log();let t=p(this.sdk.testMode?g.MagicPayloadMethod.GetMetadataTestMode:g.MagicPayloadMethod.GetMetadata);return this.request(t)}updateEmail(t){v({method:"user.updateEmail()",removalVersions:x,useInstead:"auth.updateEmailWithUI()"}).log();let{email:r,showUI:o=!0}=t,s=p(this.sdk.testMode?g.MagicPayloadMethod.UpdateEmailTestMode:g.MagicPayloadMethod.UpdateEmail,[{email:r,showUI:o}]);return this.request(s)}updatePhoneNumber(){v({method:"user.updatePhoneNumber()",removalVersions:x,useInstead:"auth.updatePhoneNumberWithUI()"}).log();let t=p(this.sdk.testMode?g.MagicPayloadMethod.UpdatePhoneNumberTestMode:g.MagicPayloadMethod.UpdatePhoneNumber);return this.request(t)}};var f=require("@magic-sdk/types");function be(n,e){return e?new URL(n,e):new URL(n)}function Ve(){let n=window.crypto.getRandomValues(new Uint8Array(16));n[6]=n[6]&15|64,n[8]=n[8]&191|128;let e="";return e+=n[0].toString(16),e+=n[1].toString(16),e+=n[2].toString(16),e+=n[3].toString(16),e+="-",e+=n[4].toString(16),e+=n[5].toString(16),e+="-",e+=n[6].toString(16),e+=n[7].toString(16),e+="-",e+=n[8].toString(16),e+=n[9].toString(16),e+="-",e+=n[10].toString(16),e+=n[11].toString(16),e+=n[12].toString(16),e+=n[13].toString(16),e+=n[14].toString(16),e+=n[15].toString(16),e}var Me="STORE_KEY_PRIVATE_KEY",ie="STORE_KEY_PUBLIC_JWK",Xe="ECDSA",bt="P-256",Un={name:Xe,namedCurve:bt},Jn={name:Xe,namedCurve:bt};function Fn(){J(ie),J(Me)}function He(){return E(this,null,function*(){let n=yield Gn();if(!n){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:e}=window.crypto,t=yield A(Me);if(!t||!e){console.info("unable to find private key or webcrypto unsupported");return}let r={iat:Math.floor(new Date().getTime()/1e3),jti:Ve()},o={typ:"dpop+jwt",alg:"ES256",jwk:n},s={protected:Pt(JSON.stringify(o)),claims:Pt(JSON.stringify(r))},a=Bn(`${s.protected}.${s.claims}`),i={name:Xe,hash:{name:"SHA-256"}},l=Xn(new Uint8Array(yield e.sign(i,t,a)));return`${s.protected}.${s.claims}.${l}`})}function Gn(){return E(this,null,function*(){if(!jn()){console.info("webcrypto is not supported");return}return(yield A(ie))||(yield Kn()),A(ie)})}function Kn(){return E(this,null,function*(){let n=null,{subtle:e}=window.crypto,t=yield e.generateKey(Un,!0,["sign"]),r=yield e.exportKey("jwk",t.privateKey);n=yield e.exportKey("jwk",t.publicKey);let o=yield e.importKey("jwk",r,Jn,!1,["sign"]);yield k(Me,o),yield k(ie,n)})}function jn(){let n=typeof window!="undefined"&&!!window.crypto,e=n&&!!window.crypto.subtle;return n&&e}function Pt(n){return Mt(Vn(n))}function Bn(n){return new TextEncoder().encode(n)}function Mt(n){return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Vn(n){return encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Xn(n){let e="";return n.forEach(t=>{e+=String.fromCharCode(t)}),Mt(e)}var xe=class extends M{constructor(){super(...arguments);this.localForageKey="mc_active_wallet"}connectWithUI(){let t=j((r,o)=>E(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(f.Wallets.MetaMask))){let c=yield this.autoConnectIfWalletBrowser(f.Wallets.MetaMask);r(c);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(f.Wallets.CoinbaseWallet))){let c=yield this.autoConnectIfWalletBrowser(f.Wallets.CoinbaseWallet);r(c);return}let s=this.getUserEnv(),a=p(f.MagicPayloadMethod.Login,[s]),i=this.request(a);i.on(f.Events.WalletSelected,c=>this.handleWalletSelected(de(B({},c),{payloadId:a.id}))),i.on("id-token-created",c=>{t.emit("id-token-created",c)});let l=yield i;l.error&&o(l),r(l)}catch(s){o(s)}}));return t}showUI(){let t=p(f.MagicPayloadMethod.ShowUI);return this.request(t)}getInfo(){return E(this,null,function*(){v({method:"wallet.getInfo()",removalVersions:x,useInstead:"user.getInfo()"}).log();let t=yield A(this.localForageKey),r=p(f.MagicPayloadMethod.GetInfo,[{walletType:t}]);return this.request(r)})}disconnect(){v({method:"wallet.disconnect()",removalVersions:x,useInstead:"user.logout()"}).log(),J(this.localForageKey);let t=p(f.MagicPayloadMethod.Disconnect);return this.request(t)}requestUserInfoWithUI(t){v({method:"wallet.requestUserInfoWithUI()",removalVersions:x,useInstead:"user.requestUserInfoWithUI()"}).log();let r=p(f.MagicPayloadMethod.RequestUserInfoWithUI,t?[t]:[]);return this.request(r)}getProvider(){return E(this,null,function*(){switch(yield A(this.localForageKey)){case f.Wallets.MetaMask:return this.getMetaMaskProvider();case f.Wallets.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var t,r,o;return((t=window.ethereum)==null?void 0:t.isMetaMask)||!!((o=(r=window.ethereum)==null?void 0:r.providers)!=null&&o.find(s=>s==null?void 0:s.isMetaMask))}isMetaMaskBrowser(){return this.isMobile()&&this.isMetaMaskInstalled()}getMetaMaskProvider(){var t,r;return((r=(t=window.ethereum)==null?void 0:t.providers)==null?void 0:r.find(o=>o==null?void 0:o.isMetaMask))||window.ethereum}connectToMetaMask(){if(this.isMobile()&&!this.isMetaMaskInstalled()){let t=`https://metamask.app.link/dapp/${window.location.href.replace(/(^\w+:|^)\/\//,"")}`;window.location.href=t}return this.getMetaMaskProvider().request({method:"eth_requestAccounts"})}isCoinbaseWalletInstalled(){var t,r,o;return((t=window.ethereum)==null?void 0:t.isCoinbaseWallet)||!!((o=(r=window.ethereum)==null?void 0:r.providers)!=null&&o.find(s=>s==null?void 0:s.isCoinbaseWallet))}isCoinbaseWalletBrowser(){var t;return!!((t=window.ethereum)!=null&&t.isCoinbaseBrowser)}getCoinbaseProvider(){var t,r;return((r=(t=window.ethereum)==null?void 0:t.providers)==null?void 0:r.find(o=>o==null?void 0:o.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let r=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=r}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(t){switch(t){case f.Wallets.MetaMask:return this.connectToMetaMask();case f.Wallets.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${t}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(t){let r=p("mc_is_wallet_enabled",[{wallet:t}]);return this.request(r)}handleWalletSelected(t){return E(this,null,function*(){try{let r=yield this.connectToThirdPartyWallet(t.wallet);yield k(this.localForageKey,t.wallet),this.createIntermediaryEvent(f.Events.WalletConnected,t.payloadId)(r)}catch(r){console.error(r),this.createIntermediaryEvent(f.Events.WalletRejected,t.payloadId)()}})}autoConnectIfWalletBrowser(t){return E(this,null,function*(){let r;t===f.Wallets.MetaMask&&(r=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),t===f.Wallets.CoinbaseWallet&&(r=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield k(this.localForageKey,t);let o=p(f.MagicPayloadMethod.AutoConnect,[{wallet:t,address:r}]);return this.request(o)})}};var ae=require("@magic-sdk/types");var{createBoundEmitterMethod:we,createChainingEmitterMethod:Y}=oe(),Ne=class extends M{constructor(){super(...arguments);this.isMagic=!0;this.on=Y("on",this);this.once=Y("once",this);this.addListener=Y("addListener",this);this.off=Y("off",this);this.removeListener=Y("removeListener",this);this.removeAllListeners=Y("removeAllListeners",this);this.emit=we("emit");this.eventNames=we("eventNames");this.listeners=we("listeners");this.listenerCount=we("listenerCount")}sendAsync(t,r){if(!r)throw Je({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:r===null?"null":typeof r});if(Array.isArray(t))this.overlay.post(ae.MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST,t.map(o=>{let s=K(o);return this.prefixPayloadMethodForTestMode(s),s})).then(o=>{r(null,o.map(s=>de(B({},s.payload),{error:s.hasError?new S(s.payload.error):null})))});else{let o=K(t);this.prefixPayloadMethodForTestMode(o),this.overlay.post(ae.MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST,o).then(s=>{r(s.hasError?new S(s.payload.error):null,s.payload)})}}send(t,r){if(typeof t=="string"){let s=p(t,Array.isArray(r)?r:[]);return this.request(s)}if(Array.isArray(t)||!!r){this.sendAsync(t,r);return}let o=Fe();return o.log(),new W(t).applyError({code:-32603,message:o.rawMessage}).payload}enable(){let t=p(ae.MagicPayloadMethod.Login);return this.request(t)}request(t){return this.prefixPayloadMethodForTestMode(t),super.request(t)}prefixPayloadMethodForTestMode(t){let r="testMode/eth/";this.sdk.testMode&&(t.method=`${r}${t.method}`)}};var xt=["request","overlay","sdk"];function Hn(n){let e=Object.getPrototypeOf(n),t=[e];for(;e!==M.prototype;)e=Object.getPrototypeOf(e),t.push(e);return t}var $e=class extends M{constructor(){super(void 0);this.__sdk_access_field_descriptors__=new Map;this.__is_initialized__=!1;this.utils={createPromiEvent:j,isPromiEvent:je,encodeJSON:ne,decodeJSON:Oe,createJsonRpcRequestPayload:p,standardizeJsonRpcRequestPayload:K,storage:z};let t=[this,...Hn(this)];xt.forEach(r=>{let o=t.map(l=>Object.getOwnPropertyDescriptor(l,r)),s=o.findIndex(l=>!!l),a=s>0,i=o[s];i&&(this.__sdk_access_field_descriptors__.set(r,{descriptor:i,isPrototypeField:a}),Object.defineProperty(this,r,{configurable:!0,get:()=>{throw We(r)}}))})}init(t){this.__is_initialized__||(xt.forEach(r=>{if(this.__sdk_access_field_descriptors__.has(r)){let{descriptor:o,isPrototypeField:s}=this.__sdk_access_field_descriptors__.get(r);s?delete this[r]:Object.defineProperty(this,r,o)}}),this.sdk=t,this.__is_initialized__=!0)}createDeprecationWarning(t){let{method:r,removalVersion:o,useInstead:s}=t,a=s?` Use \`${s}\` instead.`:"",i=`\`${r}\` will be removed from this Extension in version \`${o}\`.${a}`;return new X(this,"DEPRECATION_NOTICE",i)}createWarning(t,r){return new X(this,t,r)}createError(t,r,o){return new G(this,t,r,o)}},ze=class extends $e{},L=class extends $e{};L.Internal=ze,L.Anonymous="anonymous extension";var Ye=require("@magic-sdk/types");var Ae=class extends M{purchase(e){let t=p(Ye.MagicPayloadMethod.NFTPurchase,[e]);return this.request(t)}checkout(e){return E(this,null,function*(){let t=p(Ye.MagicPayloadMethod.NFTCheckout,[e]);return this.request(t)})}};function wt(n){return n.compat&&n.compat[m.sdkName]!=null?typeof n.compat[m.sdkName]=="string"?mt(ht(m.version),n.compat[m.sdkName]):!!n.compat[m.sdkName]:!0}function zn(n){var o;let e=(o=n==null?void 0:n.extensions)!=null?o:[],t={},r=[];if(Array.isArray(e)?e.forEach(s=>{wt(s)?(s.init(this),(s.name||s.name!==L.Anonymous)&&(this[s.name]=s),s instanceof L.Internal&&(re(s.config)||(t[s.name]=s.config))):r.push(s)}):Object.keys(e).forEach(s=>{if(wt(e[s])){e[s].init(this);let a=e[s];this[s]=a,a instanceof L.Internal&&(re(a.config)||(t[e[s].name]=a.config))}else r.push(e[s])}),r.length)throw Ue(r);return t}var ce=class{constructor(e,t){this.apiKey=e;var a;if(!e)throw qe();m.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Ge().log();let{defaultEndpoint:r,version:o}=m;this.testMode=!!(t!=null&&t.testMode),this.endpoint=be((a=t==null?void 0:t.endpoint)!=null?a:r).origin,this.auth=new Te(this),this.user=new Pe(this),this.wallet=new xe(this),this.nft=new Ae(this),this.rpcProvider=new Ne(this);let s=zn.call(this,t);this.parameters=ne(B({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:be(this.endpoint).host,sdk:ft[m.sdkName],version:o,ext:re(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},m.bundleId?{bundleId:m.bundleId}:{}))}get overlay(){if(!ce.__overlays__.has(this.parameters)){let e=new m.ViewController(this.endpoint,this.parameters);e.init(),ce.__overlays__.set(this.parameters,e)}return ce.__overlays__.get(this.parameters)}preload(){return E(this,null,function*(){yield this.overlay.ready})}},le=ce;le.__overlays__=new Map;var ue=require("@magic-sdk/types");function Yn(n,e){return e&&Array.isArray(n)?n.find(t=>t.id===e):n}function Zn(n,e){var o;let t=(o=e.data.response)==null?void 0:o.id,r=Yn(n,t);if(t&&r){let s=new W(r).applyResult(e.data.response.result).applyError(e.data.response.error);return{id:t,response:s}}return{}}function Qn(n,e){return E(this,null,function*(){let t=yield A("rt"),r;if(m.platform==="web")try{r=yield He()}catch(o){console.error("webcrypto error",o)}return r?t?{msgType:n,payload:e,jwt:r,rt:t}:{msgType:n,payload:e,jwt:r}:{msgType:n,payload:e}})}function er(n){return E(this,null,function*(){!n.data.rt||(yield k("rt",n.data.rt))})}var Ce=class{constructor(e,t){this.endpoint=e;this.parameters=t;this.messageHandlers=new Set;this.ready=this.waitForReady(),this.listen()}post(e,t){return E(this,null,function*(){return ve(r=>E(this,null,function*(){yield this.ready;let o=[],s=Array.isArray(t)?t.map(c=>c.id):[],a=yield Qn(`${e}-${this.parameters}`,t);yield this._post(a);let i=c=>u=>{let{id:d,response:w}=Zn(t,u);er(u),d&&w&&Array.isArray(t)&&s.includes(d)?(o.push(w),o.length===t.length&&(c(),r(o))):d&&w&&!Array.isArray(t)&&d===t.id&&(c(),r(w))},l=this.on(ue.MagicIncomingWindowMessage.MAGIC_HANDLE_RESPONSE,i(()=>l()))}))})}on(e,t){let r=t.bind(window),o=s=>{s.data.msgType===`${e}-${this.parameters}`&&r(s)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{this.on(ue.MagicIncomingWindowMessage.MAGIC_OVERLAY_READY,()=>e())})}listen(){this.on(ue.MagicIncomingWindowMessage.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(ue.MagicIncomingWindowMessage.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};
5
+ Received: \`${n.received}\``)}function $n(){return new F(N.SDKWarningCode.DuplicateIframe,"Duplicate iframes found.")}function Fe(){return new F(N.SDKWarningCode.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 Ge(){return new F(N.SDKWarningCode.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 \`${m.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function v(n){let{method:e,removalVersions:t,useInstead:r}=n,o=t[m.sdkName],s=r?` Use \`${r}\` instead.`:"",a=`\`${e}\` will be removed from \`${m.sdkName}\` in version \`${o}\`.${s}`;return new F(N.SDKWarningCode.DeprecationNotice,a)}var $=require("@magic-sdk/types");var H=require("@magic-sdk/types");function*An(){let n=0;for(;;)n<Number.MAX_SAFE_INTEGER?yield++n:n=0}var Cn=An();function ge(){return Cn.next().value}var gt=Symbol("Payload pre-processed by Magic SDK");function yt(n){return Object.defineProperty(n,gt,{value:!0,enumerable:!1}),n}function Sn(n){return!!n[gt]}function K(n){var e,t,r;return Sn(n)||(n.jsonrpc=(e=n.jsonrpc)!=null?e:"2.0",n.id=ge(),n.method=(t=n.method)!=null?t:"noop",n.params=(r=n.params)!=null?r:[],yt(n)),n}function p(n,e=[]){return yt({params:e,method:n,jsonrpc:"2.0",id:ge()})}var W=class{constructor(e){e instanceof W?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):_e(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}}};var Tt=kt(vt()),Re=class extends Tt.default{};function oe(){let n=new Re;return{emitter:n,createChainingEmitterMethod:(r,o)=>(...s)=>(n[r].apply(n,s),o),createBoundEmitterMethod:r=>(...o)=>n[r].apply(n,o)}}var It=Symbol("isPromiEvent");function je(n){return!!n[It]}function j(n){let e=ve(n),{createBoundEmitterMethod:t,createChainingEmitterMethod:r}=oe(),o=Symbol("Promise.then"),s=Symbol("Promise.catch"),a=Symbol("Promise.finally"),i=(u,d)=>(...w)=>{let q=d[u].apply(d,w);return l(q)},l=u=>Object.assign(u,{[It]:!0,[o]:u[o]||u.then,[s]:u[s]||u.catch,[a]:u[a]||u.finally,then:i(o,u),catch:i(s,u),finally:i(a,u),on:r("on",u),once:r("once",u),addListener:r("addListener",u),off:r("off",u),removeListener:r("removeListener",u),removeAllListeners:r("removeAllListeners",u),emit:t("emit"),eventNames:t("eventNames"),listeners:t("listeners"),listenerCount:t("listenerCount")}),c=l(e.then(u=>(c.emit("done",u),c.emit("settled"),u),u=>{throw c.emit("error",u),c.emit("settled"),u}));return c}function ve(n){return new Promise((e,t)=>{let r=n(e,t);Promise.resolve(r).catch(t)})}var M=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(H.MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST,K(e)),r=j((s,a)=>{t.then(i=>{if(o(),i.hasError)a(new S(i.payload.error));else if(i.hasResult)s(i.payload.result);else throw De()}).catch(i=>{o(),a(i)})}),o=this.overlay.on(H.MagicIncomingWindowMessage.MAGIC_HANDLE_EVENT,s=>{var i;let{response:a}=s.data;if(a.id===e.id&&((i=a.result)==null?void 0:i.event)){let{event:l,params:c=[]}=a.result;r.emit(l,...c)}});return r}createIntermediaryEvent(e,t){return o=>{let s=p(H.MagicPayloadMethod.IntermediaryEvent,[{payloadId:t,eventType:e,args:o}]);this.request(s)}}};function Be(n,e){let[t]=n.split(".").map(Number);return t>=e}var x={"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"},Te=class extends M{loginWithMagicLink(e){let t=m.sdkName==="@magic-sdk/react-native"||m.sdkName==="@magic-sdk/react-native-bare"||m.sdkName==="@magic-sdk/react-native-expo";if(t&&Be(m.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");v({method:"auth.loginWithMagicLink()",removalVersions:x,useInstead:t?"@magic-ext/auth auth.loginWithEmailOTP()":"@magic-ext/auth auth.loginWithMagicLink()"}).log();let{email:r,showUI:o=!0,redirectURI:s}=e,a=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithMagicLinkTestMode:$.MagicPayloadMethod.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:s}]);return this.request(a)}loginWithSMS(e){v({method:"auth.loginWithSMS()",removalVersions:x,useInstead:"@magic-ext/auth auth.loginWithSMS()"}).log();let{phoneNumber:t}=e,r=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithSmsTestMode:$.MagicPayloadMethod.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){v({method:"auth.loginWithEmailOTP()",removalVersions:x,useInstead:"@magic-ext/auth auth.loginWithEmailOTP()"}).log();let{email:t,showUI:r}=e,o=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithEmailOTPTestMode:$.MagicPayloadMethod.LoginWithEmailOTP,[{email:t,showUI:r}]);if(!r){let s=this.request(o);return s&&(s.on("verify-email-otp",a=>{this.createIntermediaryEvent("verify-email-otp",o.id)(a)}),s.on("cancel",()=>{this.createIntermediaryEvent("cancel",o.id)()})),s}return this.request(o)}loginWithCredential(e){v({method:"auth.loginWithCredential()",removalVersions:x,useInstead:"@magic-ext/auth auth.loginWithCredential()"}).log();let t=e!=null?e:"";if(!e&&m.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let r=p(this.sdk.testMode?$.MagicPayloadMethod.LoginWithCredentialTestMode:$.MagicPayloadMethod.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){v({method:"auth.setAuthorizationToken()",removalVersions:x,useInstead:"@magic-ext/auth auth.setAuthorizationToken()"}).log();let t=p($.MagicPayloadMethod.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){v({method:"auth.updateEmailWithUI()",removalVersions:x,useInstead:"@magic-ext/auth auth.updateEmailWithUI()"}).log();let{email:t,showUI:r=!0}=e,o=p(this.sdk.testMode?$.MagicPayloadMethod.UpdateEmailTestMode:$.MagicPayloadMethod.UpdateEmail,[{email:t,showUI:r}]);return this.request(o)}updatePhoneNumberWithUI(){v({method:"auth.updatePhoneNumberWithUI()",removalVersions:x,useInstead:"@magic-ext/auth auth.updatePhoneNumberWithUI()"}).log();let e=p(this.sdk.testMode?$.MagicPayloadMethod.UpdatePhoneNumberTestMode:$.MagicPayloadMethod.UpdatePhoneNumber);return this.request(e)}};var g=require("@magic-sdk/types");var z={};tt(z,{clear:()=>_n,getItem:()=>A,iterate:()=>Wn,key:()=>qn,keys:()=>Dn,length:()=>kn,removeItem:()=>J,setItem:()=>k});var Ie;function U(n){return(...e)=>E(this,null,function*(){return Ie||(Ie=yield m.configureStorage()),yield Ie.ready(),Ie[n](...e)})}var A=U("getItem"),k=U("setItem"),J=U("removeItem"),_n=U("clear"),kn=U("length"),qn=U("key"),Dn=U("keys"),Wn=U("iterate");var Pe=class extends M{constructor(){super(...arguments);this.localForageKey="mc_active_wallet"}getIdToken(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.GetIdTokenTestMode:g.MagicPayloadMethod.GetIdToken,[t]);return this.request(r)}generateIdToken(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.GenerateIdTokenTestMode:g.MagicPayloadMethod.GenerateIdToken,[t]);return this.request(r)}getInfo(){return E(this,null,function*(){let t=yield A(this.localForageKey),r=p(g.MagicPayloadMethod.GetInfo,[{walletType:t}]);return this.request(r)})}isLoggedIn(){let t=p(this.sdk.testMode?g.MagicPayloadMethod.IsLoggedInTestMode:g.MagicPayloadMethod.IsLoggedIn);return this.request(t)}logout(){J(this.localForageKey);let t=p(this.sdk.testMode?g.MagicPayloadMethod.LogoutTestMode:g.MagicPayloadMethod.Logout);return this.request(t)}requestInfoWithUI(t){let r=p(g.MagicPayloadMethod.RequestUserInfoWithUI,t?[t]:[]);return this.request(r)}showSettings(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.UserSettingsTestMode:g.MagicPayloadMethod.UserSettings,[t]);return this.request(r)}recoverAccount(t){let r=p(this.sdk.testMode?g.MagicPayloadMethod.RecoverAccountTestMode:g.MagicPayloadMethod.RecoverAccount,[t]);return this.request(r)}getMetadata(){v({method:"user.getMetadata()",removalVersions:x,useInstead:"user.getInfo()"}).log();let t=p(this.sdk.testMode?g.MagicPayloadMethod.GetMetadataTestMode:g.MagicPayloadMethod.GetMetadata);return this.request(t)}updateEmail(t){v({method:"user.updateEmail()",removalVersions:x,useInstead:"auth.updateEmailWithUI()"}).log();let{email:r,showUI:o=!0}=t,s=p(this.sdk.testMode?g.MagicPayloadMethod.UpdateEmailTestMode:g.MagicPayloadMethod.UpdateEmail,[{email:r,showUI:o}]);return this.request(s)}updatePhoneNumber(){v({method:"user.updatePhoneNumber()",removalVersions:x,useInstead:"auth.updatePhoneNumberWithUI()"}).log();let t=p(this.sdk.testMode?g.MagicPayloadMethod.UpdatePhoneNumberTestMode:g.MagicPayloadMethod.UpdatePhoneNumber);return this.request(t)}};var f=require("@magic-sdk/types");function be(n,e){return e?new URL(n,e):new URL(n)}function Ve(){let n=window.crypto.getRandomValues(new Uint8Array(16));n[6]=n[6]&15|64,n[8]=n[8]&191|128;let e="";return e+=n[0].toString(16),e+=n[1].toString(16),e+=n[2].toString(16),e+=n[3].toString(16),e+="-",e+=n[4].toString(16),e+=n[5].toString(16),e+="-",e+=n[6].toString(16),e+=n[7].toString(16),e+="-",e+=n[8].toString(16),e+=n[9].toString(16),e+="-",e+=n[10].toString(16),e+=n[11].toString(16),e+=n[12].toString(16),e+=n[13].toString(16),e+=n[14].toString(16),e+=n[15].toString(16),e}var Me="STORE_KEY_PRIVATE_KEY",ie="STORE_KEY_PUBLIC_JWK",Xe="ECDSA",bt="P-256",Un={name:Xe,namedCurve:bt},Jn={name:Xe,namedCurve:bt};function Fn(){J(ie),J(Me)}function He(){return E(this,null,function*(){let n=yield Gn();if(!n){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:e}=window.crypto,t=yield A(Me);if(!t||!e){console.info("unable to find private key or webcrypto unsupported");return}let r={iat:Math.floor(new Date().getTime()/1e3),jti:Ve()},o={typ:"dpop+jwt",alg:"ES256",jwk:n},s={protected:Pt(JSON.stringify(o)),claims:Pt(JSON.stringify(r))},a=Bn(`${s.protected}.${s.claims}`),i={name:Xe,hash:{name:"SHA-256"}},l=Xn(new Uint8Array(yield e.sign(i,t,a)));return`${s.protected}.${s.claims}.${l}`})}function Gn(){return E(this,null,function*(){if(!jn()){console.info("webcrypto is not supported");return}return(yield A(ie))||(yield Kn()),A(ie)})}function Kn(){return E(this,null,function*(){let n=null,{subtle:e}=window.crypto,t=yield e.generateKey(Un,!0,["sign"]),r=yield e.exportKey("jwk",t.privateKey);n=yield e.exportKey("jwk",t.publicKey);let o=yield e.importKey("jwk",r,Jn,!1,["sign"]);yield k(Me,o),yield k(ie,n)})}function jn(){let n=typeof window!="undefined"&&!!window.crypto,e=n&&!!window.crypto.subtle;return n&&e}function Pt(n){return Mt(Vn(n))}function Bn(n){return new TextEncoder().encode(n)}function Mt(n){return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Vn(n){return encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Xn(n){let e="";return n.forEach(t=>{e+=String.fromCharCode(t)}),Mt(e)}var xe=class extends M{constructor(){super(...arguments);this.localForageKey="mc_active_wallet"}connectWithUI(){let t=j((r,o)=>E(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(f.Wallets.MetaMask))){let c=yield this.autoConnectIfWalletBrowser(f.Wallets.MetaMask);r(c);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(f.Wallets.CoinbaseWallet))){let c=yield this.autoConnectIfWalletBrowser(f.Wallets.CoinbaseWallet);r(c);return}let s=this.getUserEnv(),a=p(f.MagicPayloadMethod.Login,[s]),i=this.request(a);i.on(f.Events.WalletSelected,c=>this.handleWalletSelected(de(B({},c),{payloadId:a.id}))),i.on("id-token-created",c=>{t.emit("id-token-created",c)});let l=yield i;l.error&&o(l),r(l)}catch(s){o(s)}}));return t}showUI(){let t=p(f.MagicPayloadMethod.ShowUI);return this.request(t)}getInfo(){return E(this,null,function*(){v({method:"wallet.getInfo()",removalVersions:x,useInstead:"user.getInfo()"}).log();let t=yield A(this.localForageKey),r=p(f.MagicPayloadMethod.GetInfo,[{walletType:t}]);return this.request(r)})}disconnect(){v({method:"wallet.disconnect()",removalVersions:x,useInstead:"user.logout()"}).log(),J(this.localForageKey);let t=p(f.MagicPayloadMethod.Disconnect);return this.request(t)}requestUserInfoWithUI(t){v({method:"wallet.requestUserInfoWithUI()",removalVersions:x,useInstead:"user.requestUserInfoWithUI()"}).log();let r=p(f.MagicPayloadMethod.RequestUserInfoWithUI,t?[t]:[]);return this.request(r)}getProvider(){return E(this,null,function*(){switch(yield A(this.localForageKey)){case f.Wallets.MetaMask:return this.getMetaMaskProvider();case f.Wallets.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var t,r,o;return((t=window.ethereum)==null?void 0:t.isMetaMask)||!!((o=(r=window.ethereum)==null?void 0:r.providers)!=null&&o.find(s=>s==null?void 0:s.isMetaMask))}isMetaMaskBrowser(){return this.isMobile()&&this.isMetaMaskInstalled()}getMetaMaskProvider(){var t,r;return((r=(t=window.ethereum)==null?void 0:t.providers)==null?void 0:r.find(o=>o==null?void 0:o.isMetaMask))||window.ethereum}connectToMetaMask(){if(this.isMobile()&&!this.isMetaMaskInstalled()){let t=`https://metamask.app.link/dapp/${window.location.href.replace(/(^\w+:|^)\/\//,"")}`;window.location.href=t}return this.getMetaMaskProvider().request({method:"eth_requestAccounts"})}isCoinbaseWalletInstalled(){var t,r,o;return((t=window.ethereum)==null?void 0:t.isCoinbaseWallet)||!!((o=(r=window.ethereum)==null?void 0:r.providers)!=null&&o.find(s=>s==null?void 0:s.isCoinbaseWallet))}isCoinbaseWalletBrowser(){var t;return!!((t=window.ethereum)!=null&&t.isCoinbaseBrowser)}getCoinbaseProvider(){var t,r;return((r=(t=window.ethereum)==null?void 0:t.providers)==null?void 0:r.find(o=>o==null?void 0:o.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let r=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=r}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(t){switch(t){case f.Wallets.MetaMask:return this.connectToMetaMask();case f.Wallets.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${t}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(t){let r=p("mc_is_wallet_enabled",[{wallet:t}]);return this.request(r)}handleWalletSelected(t){return E(this,null,function*(){try{let r=yield this.connectToThirdPartyWallet(t.wallet);yield k(this.localForageKey,t.wallet),this.createIntermediaryEvent(f.Events.WalletConnected,t.payloadId)(r)}catch(r){console.error(r),this.createIntermediaryEvent(f.Events.WalletRejected,t.payloadId)()}})}autoConnectIfWalletBrowser(t){return E(this,null,function*(){let r;t===f.Wallets.MetaMask&&(r=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),t===f.Wallets.CoinbaseWallet&&(r=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield k(this.localForageKey,t);let o=p(f.MagicPayloadMethod.AutoConnect,[{wallet:t,address:r}]);return this.request(o)})}};var ae=require("@magic-sdk/types");var{createBoundEmitterMethod:we,createChainingEmitterMethod:Y}=oe(),Ne=class extends M{constructor(){super(...arguments);this.isMagic=!0;this.on=Y("on",this);this.once=Y("once",this);this.addListener=Y("addListener",this);this.off=Y("off",this);this.removeListener=Y("removeListener",this);this.removeAllListeners=Y("removeAllListeners",this);this.emit=we("emit");this.eventNames=we("eventNames");this.listeners=we("listeners");this.listenerCount=we("listenerCount")}sendAsync(t,r){if(!r)throw Je({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:r===null?"null":typeof r});if(Array.isArray(t))this.overlay.post(ae.MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST,t.map(o=>{let s=K(o);return this.prefixPayloadMethodForTestMode(s),s})).then(o=>{r(null,o.map(s=>de(B({},s.payload),{error:s.hasError?new S(s.payload.error):null})))});else{let o=K(t);this.prefixPayloadMethodForTestMode(o),this.overlay.post(ae.MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST,o).then(s=>{r(s.hasError?new S(s.payload.error):null,s.payload)})}}send(t,r){if(typeof t=="string"){let s=p(t,Array.isArray(r)?r:[]);return this.request(s)}if(Array.isArray(t)||!!r){this.sendAsync(t,r);return}let o=Fe();return o.log(),new W(t).applyError({code:-32603,message:o.rawMessage}).payload}enable(){let t=p(ae.MagicPayloadMethod.Login);return this.request(t)}request(t){return this.prefixPayloadMethodForTestMode(t),super.request(t)}prefixPayloadMethodForTestMode(t){let r="testMode/eth/";this.sdk.testMode&&(t.method=`${r}${t.method}`)}};var xt=["request","overlay","sdk"];function Hn(n){let e=Object.getPrototypeOf(n),t=[e];for(;e!==M.prototype;)e=Object.getPrototypeOf(e),t.push(e);return t}var $e=class extends M{constructor(){super(void 0);this.__sdk_access_field_descriptors__=new Map;this.__is_initialized__=!1;this.utils={createPromiEvent:j,isPromiEvent:je,encodeJSON:ne,decodeJSON:Oe,createJsonRpcRequestPayload:p,standardizeJsonRpcRequestPayload:K,storage:z};let t=[this,...Hn(this)];xt.forEach(r=>{let o=t.map(l=>Object.getOwnPropertyDescriptor(l,r)),s=o.findIndex(l=>!!l),a=s>0,i=o[s];i&&(this.__sdk_access_field_descriptors__.set(r,{descriptor:i,isPrototypeField:a}),Object.defineProperty(this,r,{configurable:!0,get:()=>{throw We(r)}}))})}init(t){this.__is_initialized__||(xt.forEach(r=>{if(this.__sdk_access_field_descriptors__.has(r)){let{descriptor:o,isPrototypeField:s}=this.__sdk_access_field_descriptors__.get(r);s?delete this[r]:Object.defineProperty(this,r,o)}}),this.sdk=t,this.__is_initialized__=!0)}createDeprecationWarning(t){let{method:r,removalVersion:o,useInstead:s}=t,a=s?` Use \`${s}\` instead.`:"",i=`\`${r}\` will be removed from this Extension in version \`${o}\`.${a}`;return new X(this,"DEPRECATION_NOTICE",i)}createWarning(t,r){return new X(this,t,r)}createError(t,r,o){return new G(this,t,r,o)}},ze=class extends $e{},L=class extends $e{};L.Internal=ze,L.Anonymous="anonymous extension";var Ye=require("@magic-sdk/types");var Ae=class extends M{purchase(e){let t=p(Ye.MagicPayloadMethod.NFTPurchase,[e]);return this.request(t)}checkout(e){return E(this,null,function*(){let t=p(Ye.MagicPayloadMethod.NFTCheckout,[e]);return this.request(t)})}};function wt(n){return n.compat&&n.compat[m.sdkName]!=null?typeof n.compat[m.sdkName]=="string"?mt(ht(m.version),n.compat[m.sdkName]):!!n.compat[m.sdkName]:!0}function zn(n){var o;let e=(o=n==null?void 0:n.extensions)!=null?o:[],t={},r=[];if(Array.isArray(e)?e.forEach(s=>{wt(s)?(s.init(this),(s.name||s.name!==L.Anonymous)&&(this[s.name]=s),s instanceof L.Internal&&(re(s.config)||(t[s.name]=s.config))):r.push(s)}):Object.keys(e).forEach(s=>{if(wt(e[s])){e[s].init(this);let a=e[s];this[s]=a,a instanceof L.Internal&&(re(a.config)||(t[e[s].name]=a.config))}else r.push(e[s])}),r.length)throw Ue(r);return t}var ce=class{constructor(e,t){this.apiKey=e;var i,l;if(!e)throw qe();m.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Ge().log();let{defaultEndpoint:r,defaultNFTEndpoint:o,version:s}=m;this.testMode=!!(t!=null&&t.testMode),this.endpoint=be((i=t==null?void 0:t.endpoint)!=null?i:r).origin,this.auth=new Te(this),this.user=new Pe(this),this.wallet=new xe(this),this.nft=new Ae(this),this.rpcProvider=new Ne(this);let a=zn.call(this,t);this.parameters=ne(B({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,nftEndpoint:(l=t==null?void 0:t.nftEndpoint)!=null?l:o,host:be(this.endpoint).host,sdk:ft[m.sdkName],version:s,ext:re(a)?void 0:a,locale:(t==null?void 0:t.locale)||"en_US"},m.bundleId?{bundleId:m.bundleId}:{}))}get overlay(){if(!ce.__overlays__.has(this.parameters)){let e=new m.ViewController(this.endpoint,this.parameters);e.init(),ce.__overlays__.set(this.parameters,e)}return ce.__overlays__.get(this.parameters)}preload(){return E(this,null,function*(){yield this.overlay.ready})}},le=ce;le.__overlays__=new Map;var ue=require("@magic-sdk/types");function Yn(n,e){return e&&Array.isArray(n)?n.find(t=>t.id===e):n}function Zn(n,e){var o;let t=(o=e.data.response)==null?void 0:o.id,r=Yn(n,t);if(t&&r){let s=new W(r).applyResult(e.data.response.result).applyError(e.data.response.error);return{id:t,response:s}}return{}}function Qn(n,e){return E(this,null,function*(){let t=yield A("rt"),r;if(m.platform==="web")try{r=yield He()}catch(o){console.error("webcrypto error",o)}return r?t?{msgType:n,payload:e,jwt:r,rt:t}:{msgType:n,payload:e,jwt:r}:{msgType:n,payload:e}})}function er(n){return E(this,null,function*(){!n.data.rt||(yield k("rt",n.data.rt))})}var Ce=class{constructor(e,t){this.endpoint=e;this.parameters=t;this.messageHandlers=new Set;this.ready=this.waitForReady(),this.listen()}post(e,t){return E(this,null,function*(){return ve(r=>E(this,null,function*(){yield this.ready;let o=[],s=Array.isArray(t)?t.map(c=>c.id):[],a=yield Qn(`${e}-${this.parameters}`,t);yield this._post(a);let i=c=>u=>{let{id:d,response:w}=Zn(t,u);er(u),d&&w&&Array.isArray(t)&&s.includes(d)?(o.push(w),o.length===t.length&&(c(),r(o))):d&&w&&!Array.isArray(t)&&d===t.id&&(c(),r(w))},l=this.on(ue.MagicIncomingWindowMessage.MAGIC_HANDLE_RESPONSE,i(()=>l()))}))})}on(e,t){let r=t.bind(window),o=s=>{s.data.msgType===`${e}-${this.parameters}`&&r(s)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{this.on(ue.MagicIncomingWindowMessage.MAGIC_OVERLAY_READY,()=>e())})}listen(){this.on(ue.MagicIncomingWindowMessage.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(ue.MagicIncomingWindowMessage.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};
6
6
  //# sourceMappingURL=index.js.map