magic-sdk 28.0.1 → 28.0.2-canary.735.8493510510.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/magic.js +1 -1
- package/package.json +4 -4
package/dist/magic.js
CHANGED
@@ -2,5 +2,5 @@
|
|
2
2
|
- Extension \`${r.name}\` supports version(s) \`${o}\``:o||(t+=`
|
3
3
|
- Extension \`${r.name}\` does not support ${Y.platform} environments.`)}),new Ee(pe.IncompatibleExtensions,t)}function bo(e){let t=r=>{let o=r+1,a=o%10,s=o%100;return a===1&&s!==11?`${o}st`:a===2&&s!==12?`${o}nd`:a===3&&s!==13?`${o}rd`:`${o}th`};return new Ee(pe.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
4
4
|
Expected: \`${e.expected}\`
|
5
|
-
Received: \`${e.received}\``)}function qr(){return new Oe(ve.DuplicateIframe,"Duplicate iframes found.")}function Ro(){return new Oe(ve.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 Ao(){return new Oe(ve.ReactNativeEndpointConfiguration,`CUSTOM DOMAINS ARE NOT SUPPORTED WHEN USING MAGIC SDK WITH REACT NATIVE! The \`endpoint\` parameter SHOULD NOT be provided. The Magic \`<iframe>\` is automatically wrapped by a WebView pointed at \`${Y.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function ze(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],s=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${s}`;return new Oe(ve.DeprecationNotice,m)}function*So(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var No=So();function Hr(){return No.next().value}var Yr=Symbol("Payload pre-processed by Magic SDK");function Xr(e){return Object.defineProperty(e,Yr,{value:!0,enumerable:!1}),e}function To(e){return!!e[Yr]}function dt(e){var t,r,o;return To(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Hr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Xr(e)),e}function W(e,t=[]){return Xr({params:t,method:e,jsonrpc:"2.0",id:Hr()})}var $t=class{constructor(e){e instanceof $t?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):vo(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}}},Oo=bi(Ri()),Mo=class extends Oo.default{};function zr(){let e=new Mo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Jr=Symbol("isPromiEvent");function Dt(e){return!!e[Jr]}function Ze(e){let t=Qr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=zr(),a=Symbol("Promise.then"),s=Symbol("Promise.catch"),m=Symbol("Promise.finally"),h=(y,T)=>(..._)=>{let N=T[y].apply(T,_);return g(N)},g=y=>Object.assign(y,{[Jr]:!0,[a]:y[a]||y.then,[s]:y[s]||y.catch,[m]:y[m]||y.finally,then:h(a,y),catch:h(s,y),finally:h(m,y),on:o("on",y),once:o("once",y),addListener:o("addListener",y),off:o("off",y),removeListener:o("removeListener",y),removeAllListeners:o("removeAllListeners",y),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),v=g(t.then(y=>(v.emit("done",y),v.emit("settled"),y),y=>{throw v.emit("error",y),v.emit("settled"),y}));return v}function Qr(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var Me=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Se.MAGIC_HANDLE_REQUEST,dt(e)),r=Ze((a,s)=>{t.then(m=>{if(o(),m.hasError)s(new Fe(m.payload.error));else if(m.hasResult)a(m.payload.result);else throw _o()}).catch(m=>{o(),s(m)})}),o=this.overlay.on(he.MAGIC_HANDLE_EVENT,a=>{var s;let{response:m}=a.data;if(m.id===e.id&&((s=m.result)==null?void 0:s.event)){let{event:h,params:g=[]}=m.result;r.emit(h,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=W(M.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Lo(e,t){let[r]=e.split(".").map(Number);return r>=t}var Je={"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"},Co=class extends Me{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&&Lo(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&ze({method:"auth.loginWithMagicLink()",removalVersions:Je,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:s}=e,m=W(this.sdk.testMode?M.LoginWithMagicLinkTestMode:M.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s}]);return this.request(m)}loginWithSMS(e){let{phoneNumber:t}=e,r=W(this.sdk.testMode?M.LoginWithSmsTestMode:M.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,s=W(this.sdk.testMode?M.LoginWithEmailOTPTestMode:M.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),m=this.request(s);return!o&&m&&m.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.Retry,s.id)()}),!r&&m&&(m.on(Ne.VerifyEmailOtp,h=>{this.createIntermediaryEvent(Ne.VerifyEmailOtp,s.id)(h)}),m.on(Ne.Cancel,()=>{this.createIntermediaryEvent(Ne.Cancel,s.id)()})),m}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?M.LoginWithCredentialTestMode:M.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(M.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=W(this.sdk.testMode?M.UpdateEmailTestMode:M.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(ge.Retry,()=>{this.createIntermediaryEvent(ge.Retry,o.id)()}),a.on(ge.Cancel,()=>{this.createIntermediaryEvent(ge.Cancel,o.id)()}),a.on(ge.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ge.VerifyEmailOtp,o.id)(s)}),a.on(ye.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ye.RetryWithNewEmail,o.id)(s)}),a.on(ye.Cancel,()=>{this.createIntermediaryEvent(ye.Cancel,o.id)()}),a.on(ye.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ye.VerifyEmailOtp,o.id)(s)})),a}},Zr={};Ii(Zr,{clear:()=>Po,getItem:()=>se,iterate:()=>en,key:()=>Do,keys:()=>xo,length:()=>$o,removeItem:()=>ke,setItem:()=>me});var st;function be(e){return(...t)=>X(this,null,function*(){return st||(st=yield Y.configureStorage()),yield st.ready(),st[e](...t)})}var se=be("getItem"),me=be("setItem"),ke=be("removeItem"),Po=be("clear"),$o=be("length"),Do=be("key"),xo=be("keys"),en=be("iterate");function Uo(){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 tn="STORE_KEY_PRIVATE_KEY",Ot="STORE_KEY_PUBLIC_JWK",rn="ECDSA",ko="P-256",Fo={name:rn,namedCurve:ko};function pt(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Wo(){return X(this,null,function*(){let e=yield Bo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield se(tn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Uo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:kr(JSON.stringify(a)),claims:kr(JSON.stringify(o))},m=jo(`${s.protected}.${s.claims}`),h={name:rn,hash:{name:"SHA-256"}},g=Ko(new Uint8Array(yield t.sign(h,r,m)));return`${s.protected}.${s.claims}.${g}`})}function Bo(){return X(this,null,function*(){if(!pt()){console.info("webcrypto is not supported");return}return(yield se(Ot))||(yield Go()),se(Ot)})}function Go(){return X(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Fo,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield me(tn,t.privateKey),yield me(Ot,r)})}function kr(e){return nn(Vo(e))}function jo(e){return new TextEncoder().encode(e)}function nn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Vo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Ko(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),nn(t)}var xt="ds",Ut="ek",kt="iv",Ft="AES-GCM",qo=256;function Wt(){return X(this,null,function*(){let e=[];yield en((t,r,o)=>{r.startsWith(`${xt}_`)&&e.push(r)});for(let t of e)yield ke(t)})}function on(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 an(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 Ho(){return X(this,null,function*(){if(!pt()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield se(kt))||e.getRandomValues(new Uint8Array(12))})}function Yo(){return X(this,null,function*(){if(!pt()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield se(Ut))||(yield e.generateKey({name:Ft,length:qo},!1,["encrypt","decrypt"]))})}function Xo(e,t){return X(this,null,function*(){let r=yield Ho(),o=yield Yo();if(!r||!o||!e)return;let a=an(e),{subtle:s}=window.crypto,m=yield s.encrypt({name:Ft,iv:r},o,a),h=on(m);yield me(`${xt}_${t}`,h),yield me(Ut,o),yield me(kt,r)})}function zo(e){return X(this,null,function*(){let t=yield se(`${xt}_${e}`),r=yield se(kt),o=yield se(Ut);if(!r||!t||!o||!pt())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:Ft,iv:r},o,an(t));return on(s)})}function et(e,t){return t?new URL(e,t):new URL(e)}var Jo=class extends Me{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=W(this.sdk.testMode?M.GetIdTokenTestMode:M.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?M.GenerateIdTokenTestMode:M.GenerateIdToken,[e]);return this.request(t)}getInfo(){return X(this,null,function*(){let e=yield se(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){return Ze((e,t)=>X(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield se(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=W(this.sdk.testMode?M.IsLoggedInTestMode:M.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?me(this.localForageIsLoggedInKey,!0):ke(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return ke(this.localForageKey),ke(this.localForageIsLoggedInKey),Wt(),Ze((e,t)=>X(this,null,function*(){try{let r=W(this.sdk.testMode?M.LogoutTestMode:M.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?M.UserSettingsTestMode:M.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?M.RecoverAccountTestMode:M.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=W(M.RevealPrivateKey);return this.request(e)}getMetadata(){ze({method:"user.getMetadata()",removalVersions:Je,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?M.GetMetadataTestMode:M.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Qo=class extends Me{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Ze((t,r)=>X(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ue.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ue.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ue.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ue.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=W(M.Login,[o]),s=this.request(a);s.on(De.WalletSelected,h=>this.handleWalletSelected(Lt(Mt({},h),{payloadId:a.id}))),s.on("id-token-created",h=>{e.emit("id-token-created",h)});let m=yield s;m.error&&r(m),t(m)}catch(o){r(o)}}));return e}showUI(){return this.request(W(M.ShowUI))}showAddress(){return this.request(W(M.ShowAddress))}showSendTokensUI(){return this.request(W(M.ShowSendTokensUI))}showOnRamp(){return this.request(W(M.ShowOnRamp))}showNFTs(){return this.request(W(M.ShowNFTs))}showBalances(){return this.request(W(M.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(M.SendGaslessTransaction,[e,t]))}getInfo(){return X(this,null,function*(){ze({method:"wallet.getInfo()",removalVersions:Je,useInstead:"user.getInfo()"}).log();let e=yield se(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){ze({method:"wallet.disconnect()",removalVersions:Je,useInstead:"user.logout()"}).log(),ke(this.localForageKey),Wt();let e=W(M.Disconnect);return this.request(e)}requestUserInfoWithUI(e){ze({method:"wallet.requestUserInfoWithUI()",removalVersions:Je,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return X(this,null,function*(){switch(yield se(this.localForageKey)){case ue.MetaMask:return this.getMetaMaskProvider();case ue.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isMetaMask)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(o=>o==null?void 0:o.isMetaMask))}isMetaMaskBrowser(){return this.isMobile()&&this.isMetaMaskInstalled()}getMetaMaskProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isMetaMask))||window.ethereum}connectToMetaMask(){if(this.isMobile()&&!this.isMetaMaskInstalled()){let e=`https://metamask.app.link/dapp/${window.location.href.replace(/(^\w+:|^)\/\//,"")}`;window.location.href=e}return this.getMetaMaskProvider().request({method:"eth_requestAccounts"})}isCoinbaseWalletInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isCoinbaseWallet)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(o=>o==null?void 0:o.isCoinbaseWallet))}isCoinbaseWalletBrowser(){var e;return!!((e=window.ethereum)!=null&&e.isCoinbaseBrowser)}getCoinbaseProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let e=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=e}return this.getCoinbaseProvider().request({method:"eth_requestAccounts"})}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)}getUserEnv(){return{env:{isMetaMaskInstalled:this.isMetaMaskInstalled(),isCoinbaseWalletInstalled:this.isCoinbaseWalletInstalled()}}}connectToThirdPartyWallet(e){switch(e){case ue.MetaMask:return this.connectToMetaMask();case ue.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=W("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return X(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield me(this.localForageKey,e.wallet),this.createIntermediaryEvent(De.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(De.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return X(this,null,function*(){let t;e===ue.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ue.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield me(this.localForageKey,e);let r=W(M.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:lt,createChainingEmitterMethod:xe}=zr(),Zo=class extends Me{constructor(){super(...arguments),this.isMagic=!0,this.on=xe("on",this),this.once=xe("once",this),this.addListener=xe("addListener",this),this.off=xe("off",this),this.removeListener=xe("removeListener",this),this.removeAllListeners=xe("removeAllListeners",this),this.emit=lt("emit"),this.eventNames=lt("eventNames"),this.listeners=lt("listeners"),this.listenerCount=lt("listenerCount")}sendAsync(e,t){if(!t)throw bo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Se.MAGIC_HANDLE_REQUEST,e.map(r=>{let o=dt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>Lt(Mt({},o.payload),{error:o.hasError?new Fe(o.payload.error):null})))});else{let r=dt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Se.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Fe(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=Ro();return r.log(),new $t(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(M.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}`)}},Fr=["request","overlay","sdk"];function ea(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Me.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var sn=class extends Me{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Ze,isPromiEvent:Dt,encodeJSON:jr,decodeJSON:mo,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:dt,storage:Zr};let e=[this,...ea(this)];Fr.forEach(t=>{let r=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=r.findIndex(m=>!!m),a=o>0,s=r[o];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Io(t)}}))})}init(e){this.__is_initialized__||(Fr.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new ft(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new ft(this,e,t)}createError(e,t,r){return new mt(this,e,t,r)}},ta=class extends sn{},Te=class extends sn{};Te.Internal=ta,Te.Anonymous="anonymous extension";var ra=class extends Me{purchase(e){let t=W(M.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(M.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(M.NFTTransfer,[e]);return this.request(t)}};function Wr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?io(lo(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function na(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 ia(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(s=>{Wr(s)?(s.init(this),(s.name||s.name!==Te.Anonymous)&&(this[s.name]=s),s instanceof Te.Internal&&(ut(s.config)||(o[s.name]=s.config))):a.push(s)}):Object.keys(r).forEach(s=>{if(Wr(r[s])){r[s].init(this);let m=r[s];this[s]=m,m instanceof Te.Internal&&(ut(m.config)||(o[r[s].name]=m.config))}else a.push(r[s])}),a.length)throw wo(a);return o}var ct=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw Eo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Ao().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=et((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new Co(this),this.user=new Jo(this),this.wallet=new Qo(this),this.nft=new ra(this),this.rpcProvider=new Zo(this);let s=ia.call(this,t);this.parameters=jr(Lt(Mt({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:et(this.endpoint).host,sdk:yo[Y.sdkName],version:a,ext:ut(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=na(this.apiKey,t==null?void 0:t.network,ut(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!ct.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),ct.__overlays__.set(this.parameters,e)}return ct.__overlays__.get(this.parameters)}preload(){return X(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Bt=ct;Bt.__overlays__=new Map;function oa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function aa(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=oa(e,o);if(o&&a){let s=new $t(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function sa(e,t,r){return X(this,null,function*(){var o;let a=yield se("rt"),s;if(Y.platform==="web")try{s=(o=yield se("jwt"))!=null?o:yield Wo()}catch(g){console.error("webcrypto error",g)}let m={msgType:e,payload:t};s&&(m.jwt=s),s&&a&&(m.rt=a);let h=yield zo(r);return h&&(m.deviceShare=h),m})}function la(e){return X(this,null,function*(){!e.data.rt||(yield me("rt",e.data.rt))})}var ln=class{constructor(e,t,r){this.endpoint=e,this.parameters=t,this.networkHash=r,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return X(this,null,function*(){return Qr((r,o)=>X(this,null,function*(){if(!this.isConnectedToInternet){let v=Pt();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],m=yield sa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(m);let h=v=>y=>{var T;let{id:_,response:N}=aa(t,y);if(la(y),((T=N==null?void 0:N.payload.error)==null?void 0:T.message)==="User denied account access.")Wt();else if(y.data.deviceShare){let{deviceShare:L}=y.data;Xo(L,this.networkHash)}_&&N&&Array.isArray(t)&&s.includes(_)?(a.push(N),a.length===t.length&&(v(),r(a))):_&&N&&!Array.isArray(t)&&_===t.id&&(v(),r(N))},g=this.on(he.MAGIC_HANDLE_RESPONSE,h(()=>g()))}))})}on(e,t){let r=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&r(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{let t=this.on(he.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(he.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(he.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(he.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Oe(ve.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Gt={};pr(Gt,{DeepLinkPage:()=>yr,DeviceVerificationEventEmit:()=>qe,DeviceVerificationEventOnReceived:()=>wr,EthChainType:()=>Ar,Events:()=>De,Extension:()=>Te,ExtensionError:()=>mt,ExtensionWarning:()=>ft,LoginWithEmailOTPEventEmit:()=>Ne,LoginWithEmailOTPEventOnReceived:()=>Ir,LoginWithMagicLinkEventEmit:()=>Er,LoginWithMagicLinkEventOnReceived:()=>_r,MagicIncomingWindowMessage:()=>he,MagicOutgoingWindowMessage:()=>Se,MagicPayloadMethod:()=>M,RPCError:()=>Fe,RPCErrorCode:()=>$e,RecencyCheckEventEmit:()=>ge,RecencyCheckEventOnReceived:()=>br,RecoveryMethodType:()=>Sr,SDKError:()=>Ee,SDKErrorCode:()=>pe,SDKWarning:()=>Oe,SDKWarningCode:()=>ve,UpdateEmailEventEmit:()=>ye,UpdateEmailEventOnReceived:()=>Rr,Wallets:()=>ue,isPromiEvent:()=>Dt});var yt=gr(un()),Vt=gr(dn());var ca={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function ua(e){for(let[t,r]of Object.entries(ca))e.style[t]=r}function fa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var gt=class extends ln{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(fa(encodeURIComponent(this.parameters)))qr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=et(this.endpoint).host,a.title="Secure Modal",a.src=et(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,ua(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 Pe(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return Pe(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 Pe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Pt()})}};var da=Object.assign(Kr(Bt,{platform:"web",sdkName:"magic-sdk",version:"28.0.1",defaultEndpoint:"https://auth.magic.link/",ViewController:gt,configureStorage:()=>Pe(void 0,null,function*(){let e=yt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Vt),yield e.setDriver([yt.default.INDEXEDDB,yt.default.LOCALSTORAGE,Vt._driver]),e})}),hr({},Gt)),ha=da;return di(ma);})();
|
5
|
+
Received: \`${e.received}\``)}function qr(){return new Oe(ve.DuplicateIframe,"Duplicate iframes found.")}function Ro(){return new Oe(ve.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 Ao(){return new Oe(ve.ReactNativeEndpointConfiguration,`CUSTOM DOMAINS ARE NOT SUPPORTED WHEN USING MAGIC SDK WITH REACT NATIVE! The \`endpoint\` parameter SHOULD NOT be provided. The Magic \`<iframe>\` is automatically wrapped by a WebView pointed at \`${Y.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function ze(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],s=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${s}`;return new Oe(ve.DeprecationNotice,m)}function*So(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var No=So();function Hr(){return No.next().value}var Yr=Symbol("Payload pre-processed by Magic SDK");function Xr(e){return Object.defineProperty(e,Yr,{value:!0,enumerable:!1}),e}function To(e){return!!e[Yr]}function dt(e){var t,r,o;return To(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Hr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Xr(e)),e}function W(e,t=[]){return Xr({params:t,method:e,jsonrpc:"2.0",id:Hr()})}var $t=class{constructor(e){e instanceof $t?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):vo(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}}},Oo=bi(Ri()),Mo=class extends Oo.default{};function zr(){let e=new Mo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Jr=Symbol("isPromiEvent");function Dt(e){return!!e[Jr]}function Ze(e){let t=Qr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=zr(),a=Symbol("Promise.then"),s=Symbol("Promise.catch"),m=Symbol("Promise.finally"),h=(y,T)=>(..._)=>{let N=T[y].apply(T,_);return g(N)},g=y=>Object.assign(y,{[Jr]:!0,[a]:y[a]||y.then,[s]:y[s]||y.catch,[m]:y[m]||y.finally,then:h(a,y),catch:h(s,y),finally:h(m,y),on:o("on",y),once:o("once",y),addListener:o("addListener",y),off:o("off",y),removeListener:o("removeListener",y),removeAllListeners:o("removeAllListeners",y),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),v=g(t.then(y=>(v.emit("done",y),v.emit("settled"),y),y=>{throw v.emit("error",y),v.emit("settled"),y}));return v}function Qr(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var Me=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Se.MAGIC_HANDLE_REQUEST,dt(e)),r=Ze((a,s)=>{t.then(m=>{if(o(),m.hasError)s(new Fe(m.payload.error));else if(m.hasResult)a(m.payload.result);else throw _o()}).catch(m=>{o(),s(m)})}),o=this.overlay.on(he.MAGIC_HANDLE_EVENT,a=>{var s;let{response:m}=a.data;if(m.id===e.id&&((s=m.result)==null?void 0:s.event)){let{event:h,params:g=[]}=m.result;r.emit(h,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=W(M.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Lo(e,t){let[r]=e.split(".").map(Number);return r>=t}var Je={"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"},Co=class extends Me{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&&Lo(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&ze({method:"auth.loginWithMagicLink()",removalVersions:Je,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:s}=e,m=W(this.sdk.testMode?M.LoginWithMagicLinkTestMode:M.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s}]);return this.request(m)}loginWithSMS(e){let{phoneNumber:t}=e,r=W(this.sdk.testMode?M.LoginWithSmsTestMode:M.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,s=W(this.sdk.testMode?M.LoginWithEmailOTPTestMode:M.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),m=this.request(s);return!o&&m&&m.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.Retry,s.id)()}),!r&&m&&(m.on(Ne.VerifyEmailOtp,h=>{this.createIntermediaryEvent(Ne.VerifyEmailOtp,s.id)(h)}),m.on(Ne.Cancel,()=>{this.createIntermediaryEvent(Ne.Cancel,s.id)()})),m}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?M.LoginWithCredentialTestMode:M.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(M.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=W(this.sdk.testMode?M.UpdateEmailTestMode:M.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(ge.Retry,()=>{this.createIntermediaryEvent(ge.Retry,o.id)()}),a.on(ge.Cancel,()=>{this.createIntermediaryEvent(ge.Cancel,o.id)()}),a.on(ge.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ge.VerifyEmailOtp,o.id)(s)}),a.on(ye.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ye.RetryWithNewEmail,o.id)(s)}),a.on(ye.Cancel,()=>{this.createIntermediaryEvent(ye.Cancel,o.id)()}),a.on(ye.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ye.VerifyEmailOtp,o.id)(s)})),a}},Zr={};Ii(Zr,{clear:()=>Po,getItem:()=>se,iterate:()=>en,key:()=>Do,keys:()=>xo,length:()=>$o,removeItem:()=>ke,setItem:()=>me});var st;function be(e){return(...t)=>X(this,null,function*(){return st||(st=yield Y.configureStorage()),yield st.ready(),st[e](...t)})}var se=be("getItem"),me=be("setItem"),ke=be("removeItem"),Po=be("clear"),$o=be("length"),Do=be("key"),xo=be("keys"),en=be("iterate");function Uo(){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 tn="STORE_KEY_PRIVATE_KEY",Ot="STORE_KEY_PUBLIC_JWK",rn="ECDSA",ko="P-256",Fo={name:rn,namedCurve:ko};function pt(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Wo(){return X(this,null,function*(){let e=yield Bo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield se(tn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Uo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:kr(JSON.stringify(a)),claims:kr(JSON.stringify(o))},m=jo(`${s.protected}.${s.claims}`),h={name:rn,hash:{name:"SHA-256"}},g=Ko(new Uint8Array(yield t.sign(h,r,m)));return`${s.protected}.${s.claims}.${g}`})}function Bo(){return X(this,null,function*(){if(!pt()){console.info("webcrypto is not supported");return}return(yield se(Ot))||(yield Go()),se(Ot)})}function Go(){return X(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Fo,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield me(tn,t.privateKey),yield me(Ot,r)})}function kr(e){return nn(Vo(e))}function jo(e){return new TextEncoder().encode(e)}function nn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Vo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Ko(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),nn(t)}var xt="ds",Ut="ek",kt="iv",Ft="AES-GCM",qo=256;function Wt(){return X(this,null,function*(){let e=[];yield en((t,r,o)=>{r.startsWith(`${xt}_`)&&e.push(r)});for(let t of e)yield ke(t)})}function on(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 an(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 Ho(){return X(this,null,function*(){if(!pt()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield se(kt))||e.getRandomValues(new Uint8Array(12))})}function Yo(){return X(this,null,function*(){if(!pt()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield se(Ut))||(yield e.generateKey({name:Ft,length:qo},!1,["encrypt","decrypt"]))})}function Xo(e,t){return X(this,null,function*(){let r=yield Ho(),o=yield Yo();if(!r||!o||!e)return;let a=an(e),{subtle:s}=window.crypto,m=yield s.encrypt({name:Ft,iv:r},o,a),h=on(m);yield me(`${xt}_${t}`,h),yield me(Ut,o),yield me(kt,r)})}function zo(e){return X(this,null,function*(){let t=yield se(`${xt}_${e}`),r=yield se(kt),o=yield se(Ut);if(!r||!t||!o||!pt())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:Ft,iv:r},o,an(t));return on(s)})}function et(e,t){return t?new URL(e,t):new URL(e)}var Jo=class extends Me{constructor(){super(...arguments),this.localForageKey="mc_active_wallet",this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=W(this.sdk.testMode?M.GetIdTokenTestMode:M.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?M.GenerateIdTokenTestMode:M.GenerateIdToken,[e]);return this.request(t)}getInfo(){return X(this,null,function*(){let e=yield se(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){return Ze((e,t)=>X(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield se(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=W(this.sdk.testMode?M.IsLoggedInTestMode:M.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?me(this.localForageIsLoggedInKey,!0):ke(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return ke(this.localForageKey),ke(this.localForageIsLoggedInKey),Wt(),Ze((e,t)=>X(this,null,function*(){try{let r=W(this.sdk.testMode?M.LogoutTestMode:M.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?M.UserSettingsTestMode:M.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?M.RecoverAccountTestMode:M.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=W(M.RevealPrivateKey);return this.request(e)}revealPrivateKey2(){let e=W(M.RevealPrivateKey);return this.request(e)}revealPrivateKeyFake(e){let t=W(this.sdk.testMode?M.UserSettingsTestMode:M.UserSettings,[e]);return this.request(t)}getMetadata(){ze({method:"user.getMetadata()",removalVersions:Je,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?M.GetMetadataTestMode:M.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Qo=class extends Me{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Ze((t,r)=>X(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ue.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ue.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ue.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ue.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=W(M.Login,[o]),s=this.request(a);s.on(De.WalletSelected,h=>this.handleWalletSelected(Lt(Mt({},h),{payloadId:a.id}))),s.on("id-token-created",h=>{e.emit("id-token-created",h)});let m=yield s;m.error&&r(m),t(m)}catch(o){r(o)}}));return e}showUI(){return this.request(W(M.ShowUI))}showAddress(){return this.request(W(M.ShowAddress))}showSendTokensUI(){return this.request(W(M.ShowSendTokensUI))}showOnRamp(){return this.request(W(M.ShowOnRamp))}showNFTs(){return this.request(W(M.ShowNFTs))}showBalances(){return this.request(W(M.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(M.SendGaslessTransaction,[e,t]))}getInfo(){return X(this,null,function*(){ze({method:"wallet.getInfo()",removalVersions:Je,useInstead:"user.getInfo()"}).log();let e=yield se(this.localForageKey),t=W(M.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){ze({method:"wallet.disconnect()",removalVersions:Je,useInstead:"user.logout()"}).log(),ke(this.localForageKey),Wt();let e=W(M.Disconnect);return this.request(e)}requestUserInfoWithUI(e){ze({method:"wallet.requestUserInfoWithUI()",removalVersions:Je,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(M.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return X(this,null,function*(){switch(yield se(this.localForageKey)){case ue.MetaMask:return this.getMetaMaskProvider();case ue.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isMetaMask)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(o=>o==null?void 0:o.isMetaMask))}isMetaMaskBrowser(){return this.isMobile()&&this.isMetaMaskInstalled()}getMetaMaskProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isMetaMask))||window.ethereum}connectToMetaMask(){if(this.isMobile()&&!this.isMetaMaskInstalled()){let e=`https://metamask.app.link/dapp/${window.location.href.replace(/(^\w+:|^)\/\//,"")}`;window.location.href=e}return this.getMetaMaskProvider().request({method:"eth_requestAccounts"})}isCoinbaseWalletInstalled(){var e,t,r;return((e=window.ethereum)==null?void 0:e.isCoinbaseWallet)||!!((r=(t=window.ethereum)==null?void 0:t.providers)!=null&&r.find(o=>o==null?void 0:o.isCoinbaseWallet))}isCoinbaseWalletBrowser(){var e;return!!((e=window.ethereum)!=null&&e.isCoinbaseBrowser)}getCoinbaseProvider(){var e,t;return((t=(e=window.ethereum)==null?void 0:e.providers)==null?void 0:t.find(r=>r==null?void 0:r.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let e=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=e}return this.getCoinbaseProvider().request({method:"eth_requestAccounts"})}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)}getUserEnv(){return{env:{isMetaMaskInstalled:this.isMetaMaskInstalled(),isCoinbaseWalletInstalled:this.isCoinbaseWalletInstalled()}}}connectToThirdPartyWallet(e){switch(e){case ue.MetaMask:return this.connectToMetaMask();case ue.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=W("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return X(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield me(this.localForageKey,e.wallet),this.createIntermediaryEvent(De.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(De.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return X(this,null,function*(){let t;e===ue.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ue.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield me(this.localForageKey,e);let r=W(M.AutoConnect,[{wallet:e,address:t}]);return this.request(r)})}},{createBoundEmitterMethod:lt,createChainingEmitterMethod:xe}=zr(),Zo=class extends Me{constructor(){super(...arguments),this.isMagic=!0,this.on=xe("on",this),this.once=xe("once",this),this.addListener=xe("addListener",this),this.off=xe("off",this),this.removeListener=xe("removeListener",this),this.removeAllListeners=xe("removeAllListeners",this),this.emit=lt("emit"),this.eventNames=lt("eventNames"),this.listeners=lt("listeners"),this.listenerCount=lt("listenerCount")}sendAsync(e,t){if(!t)throw bo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Se.MAGIC_HANDLE_REQUEST,e.map(r=>{let o=dt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>Lt(Mt({},o.payload),{error:o.hasError?new Fe(o.payload.error):null})))});else{let r=dt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Se.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Fe(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=Ro();return r.log(),new $t(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(M.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}`)}},Fr=["request","overlay","sdk"];function ea(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==Me.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var sn=class extends Me{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Ze,isPromiEvent:Dt,encodeJSON:jr,decodeJSON:mo,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:dt,storage:Zr};let e=[this,...ea(this)];Fr.forEach(t=>{let r=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=r.findIndex(m=>!!m),a=o>0,s=r[o];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw Io(t)}}))})}init(e){this.__is_initialized__||(Fr.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new ft(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new ft(this,e,t)}createError(e,t,r){return new mt(this,e,t,r)}},ta=class extends sn{},Te=class extends sn{};Te.Internal=ta,Te.Anonymous="anonymous extension";var ra=class extends Me{purchase(e){let t=W(M.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(M.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(M.NFTTransfer,[e]);return this.request(t)}};function Wr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?io(lo(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function na(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 ia(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(s=>{Wr(s)?(s.init(this),(s.name||s.name!==Te.Anonymous)&&(this[s.name]=s),s instanceof Te.Internal&&(ut(s.config)||(o[s.name]=s.config))):a.push(s)}):Object.keys(r).forEach(s=>{if(Wr(r[s])){r[s].init(this);let m=r[s];this[s]=m,m instanceof Te.Internal&&(ut(m.config)||(o[r[s].name]=m.config))}else a.push(r[s])}),a.length)throw wo(a);return o}var ct=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw Eo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Ao().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=et((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new Co(this),this.user=new Jo(this),this.wallet=new Qo(this),this.nft=new ra(this),this.rpcProvider=new Zo(this);let s=ia.call(this,t);this.parameters=jr(Lt(Mt({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:et(this.endpoint).host,sdk:yo[Y.sdkName],version:a,ext:ut(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=na(this.apiKey,t==null?void 0:t.network,ut(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!ct.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),ct.__overlays__.set(this.parameters,e)}return ct.__overlays__.get(this.parameters)}preload(){return X(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},Bt=ct;Bt.__overlays__=new Map;function oa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function aa(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=oa(e,o);if(o&&a){let s=new $t(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function sa(e,t,r){return X(this,null,function*(){var o;let a=yield se("rt"),s;if(Y.platform==="web")try{s=(o=yield se("jwt"))!=null?o:yield Wo()}catch(g){console.error("webcrypto error",g)}let m={msgType:e,payload:t};s&&(m.jwt=s),s&&a&&(m.rt=a);let h=yield zo(r);return h&&(m.deviceShare=h),m})}function la(e){return X(this,null,function*(){!e.data.rt||(yield me("rt",e.data.rt))})}var ln=class{constructor(e,t,r){this.endpoint=e,this.parameters=t,this.networkHash=r,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return X(this,null,function*(){return Qr((r,o)=>X(this,null,function*(){if(!this.isConnectedToInternet){let v=Pt();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],m=yield sa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(m);let h=v=>y=>{var T;let{id:_,response:N}=aa(t,y);if(la(y),((T=N==null?void 0:N.payload.error)==null?void 0:T.message)==="User denied account access.")Wt();else if(y.data.deviceShare){let{deviceShare:L}=y.data;Xo(L,this.networkHash)}_&&N&&Array.isArray(t)&&s.includes(_)?(a.push(N),a.length===t.length&&(v(),r(a))):_&&N&&!Array.isArray(t)&&_===t.id&&(v(),r(N))},g=this.on(he.MAGIC_HANDLE_RESPONSE,h(()=>g()))}))})}on(e,t){let r=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&r(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{let t=this.on(he.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(he.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(he.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(he.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Oe(ve.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Gt={};pr(Gt,{DeepLinkPage:()=>yr,DeviceVerificationEventEmit:()=>qe,DeviceVerificationEventOnReceived:()=>wr,EthChainType:()=>Ar,Events:()=>De,Extension:()=>Te,ExtensionError:()=>mt,ExtensionWarning:()=>ft,LoginWithEmailOTPEventEmit:()=>Ne,LoginWithEmailOTPEventOnReceived:()=>Ir,LoginWithMagicLinkEventEmit:()=>Er,LoginWithMagicLinkEventOnReceived:()=>_r,MagicIncomingWindowMessage:()=>he,MagicOutgoingWindowMessage:()=>Se,MagicPayloadMethod:()=>M,RPCError:()=>Fe,RPCErrorCode:()=>$e,RecencyCheckEventEmit:()=>ge,RecencyCheckEventOnReceived:()=>br,RecoveryMethodType:()=>Sr,SDKError:()=>Ee,SDKErrorCode:()=>pe,SDKWarning:()=>Oe,SDKWarningCode:()=>ve,UpdateEmailEventEmit:()=>ye,UpdateEmailEventOnReceived:()=>Rr,Wallets:()=>ue,isPromiEvent:()=>Dt});var yt=gr(un()),Vt=gr(dn());var ca={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function ua(e){for(let[t,r]of Object.entries(ca))e.style[t]=r}function fa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var gt=class extends ln{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(fa(encodeURIComponent(this.parameters)))qr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=et(this.endpoint).host,a.title="Secure Modal",a.src=et(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,ua(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 Pe(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return Pe(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 Pe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Pt()})}};var da=Object.assign(Kr(Bt,{platform:"web",sdkName:"magic-sdk",version:"28.0.1",defaultEndpoint:"https://auth.magic.link/",ViewController:gt,configureStorage:()=>Pe(void 0,null,function*(){let e=yt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Vt),yield e.setDriver([yt.default.INDEXEDDB,yt.default.LOCALSTORAGE,Vt._driver]),e})}),hr({},Gt)),ha=da;return di(ma);})();
|
6
6
|
if (Magic && Magic.default != null) { Magic = Object.assign(Magic.default, Magic); delete Magic.default; }
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "magic-sdk",
|
3
|
-
"version": "28.0.
|
3
|
+
"version": "28.0.2-canary.735.8493510510.0",
|
4
4
|
"description": "Passwordless authentication for the web.",
|
5
5
|
"author": "Magic Labs <team@magic.link> (https://magic.link/)",
|
6
6
|
"license": "MIT",
|
@@ -29,8 +29,8 @@
|
|
29
29
|
]
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@magic-sdk/commons": "
|
33
|
-
"@magic-sdk/provider": "
|
32
|
+
"@magic-sdk/commons": "24.0.2-canary.735.8493510510.0",
|
33
|
+
"@magic-sdk/provider": "28.0.2-canary.735.8493510510.0",
|
34
34
|
"@magic-sdk/types": "^24.0.0",
|
35
35
|
"localforage": "^1.7.4"
|
36
36
|
},
|
@@ -40,5 +40,5 @@
|
|
40
40
|
"@babel/runtime": "^7.9.6",
|
41
41
|
"localforage-driver-memory": "^1.0.5"
|
42
42
|
},
|
43
|
-
"gitHead": "
|
43
|
+
"gitHead": "2afac35608dc233039416e810f412c347b7ee967"
|
44
44
|
}
|