magic-sdk 20.0.0 → 20.0.1-canary.522b998.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 \`${n.name}\` supports version(s) \`${o}\``:o||(t+=`
|
3
3
|
- Extension \`${n.name}\` does not support ${H.platform} environments.`)}),new ve(pe.IncompatibleExtensions,t)}function uo(e){let t=n=>{let o=n+1,a=o%10,l=o%100;return a===1&&l!==11?`${o}st`:a===2&&l!==12?`${o}nd`:a===3&&l!==13?`${o}rd`:`${o}th`};return new ve(pe.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
4
4
|
Expected: \`${e.expected}\`
|
5
|
-
Received: \`${e.received}\``)}function Ur(){return new We(Re.DuplicateIframe,"Duplicate iframes found.")}function fo(){return new We(Re.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 ho(){return new We(Re.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 \`${H.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function de(e){let{method:t,removalVersions:n,useInstead:o}=e,a=n[H.sdkName],l=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${H.sdkName}\` in version \`${a}\`.${l}`;return new We(Re.DeprecationNotice,m)}function*po(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var mo=po();function kr(){return mo.next().value}var Wr=Symbol("Payload pre-processed by Magic SDK");function Br(e){return Object.defineProperty(e,Wr,{value:!0,enumerable:!1}),e}function vo(e){return!!e[Wr]}function st(e){var t,n,o;return vo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=kr(),e.method=(n=e.method)!=null?n:"noop",e.params=(o=e.params)!=null?o:[],Br(e)),e}function B(e,t=[]){return Br({params:t,method:e,jsonrpc:"2.0",id:kr()})}var Tt=class{constructor(e){e instanceof Tt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):no(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}}},go=fi(di()),yo=class extends go.default{};function Fr(){let e=new yo;return{emitter:e,createChainingEmitterMethod:(t,n)=>(...o)=>(e[t].apply(e,o),n),createBoundEmitterMethod:t=>(...n)=>e[t].apply(e,n)}}var Gr=Symbol("isPromiEvent");function Nt(e){return!!e[Gr]}function Mt(e){let t=jr(e),{createBoundEmitterMethod:n,createChainingEmitterMethod:o}=Fr(),a=Symbol("Promise.then"),l=Symbol("Promise.catch"),m=Symbol("Promise.finally"),h=(y,T)=>(...I)=>{let N=T[y].apply(T,I);return v(N)},v=y=>Object.assign(y,{[Gr]:!0,[a]:y[a]||y.then,[l]:y[l]||y.catch,[m]:y[m]||y.finally,then:h(a,y),catch:h(l,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:n("emit"),eventNames:n("eventNames"),listeners:n("listeners"),listenerCount:n("listenerCount")}),g=v(t.then(y=>(g.emit("done",y),g.emit("settled"),y),y=>{throw g.emit("error",y),g.emit("settled"),y}));return g}function jr(e){return new Promise((t,n)=>{let o=e(t,n);Promise.resolve(o).catch(n)})}var Ne=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Ae.MAGIC_HANDLE_REQUEST,st(e)),n=Mt((a,l)=>{t.then(m=>{if(o(),m.hasError)l(new xe(m.payload.error));else if(m.hasResult)a(m.payload.result);else throw so()}).catch(m=>{o(),l(m)})}),o=this.overlay.on(me.MAGIC_HANDLE_EVENT,a=>{var l;let{response:m}=a.data;if(m.id===e.id&&((l=m.result)==null?void 0:l.event)){let{event:h,params:v=[]}=m.result;n.emit(h,...v)}});return n}createIntermediaryEvent(e,t){return n=>{let o=B(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:n}]);this.request(o)}}};function Eo(e,t){let[n]=e.split(".").map(Number);return n>=t}var he={"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"},_o=class extends Ne{loginWithMagicLink(e){let t=H.sdkName==="@magic-sdk/react-native"||H.sdkName==="@magic-sdk/react-native-bare"||H.sdkName==="@magic-sdk/react-native-expo";if(t&&Eo(H.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");de({method:"auth.loginWithMagicLink()",removalVersions:he,useInstead:t?"@magic-ext/auth auth.loginWithEmailOTP()":"@magic-ext/auth auth.loginWithMagicLink()"}).log();let{email:n,showUI:o=!0,redirectURI:a}=e,l=B(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:n,showUI:o,redirectURI:a}]);return this.request(l)}loginWithSMS(e){de({method:"auth.loginWithSMS()",removalVersions:he,useInstead:"@magic-ext/auth auth.loginWithSMS()"}).log();let{phoneNumber:t}=e,n=B(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(n)}loginWithEmailOTP(e){let{email:t,showUI:n,deviceCheckUI:o}=e,a=B(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:n,deviceCheckUI:o}]),l=this.request(a);return!o&&l&&l.on(Ke.Retry,()=>{this.createIntermediaryEvent(Ke.Retry,a.id)()}),!n&&l&&(l.on(Se.VerifyEmailOtp,m=>{this.createIntermediaryEvent(Se.VerifyEmailOtp,a.id)(m)}),l.on(Se.Cancel,()=>{this.createIntermediaryEvent(Se.Cancel,a.id)()})),l}loginWithCredential(e){de({method:"auth.loginWithCredential()",removalVersions:he,useInstead:"@magic-ext/auth auth.loginWithCredential()"}).log();let t=e!=null?e:"";if(!e&&H.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let n=B(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(n)}setAuthorizationToken(e){de({method:"auth.setAuthorizationToken()",removalVersions:he,useInstead:"@magic-ext/auth auth.setAuthorizationToken()"}).log();let t=B(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){de({method:"auth.updateEmailWithUI()",removalVersions:he,useInstead:"@magic-ext/auth auth.updateEmailWithUI()"}).log();let{email:t,showUI:n=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:n}]);return this.request(o)}},Vr={};ci(Vr,{clear:()=>Io,getItem:()=>_e,iterate:()=>Ao,key:()=>bo,keys:()=>Ro,length:()=>wo,removeItem:()=>Ot,setItem:()=>Ue});var nt;function Ie(e){return(...t)=>ae(this,null,function*(){return nt||(nt=yield H.configureStorage()),yield nt.ready(),nt[e](...t)})}var _e=Ie("getItem"),Ue=Ie("setItem"),Ot=Ie("removeItem"),Io=Ie("clear"),wo=Ie("length"),bo=Ie("key"),Ro=Ie("keys"),Ao=Ie("iterate"),So=class extends Ne{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}getIdToken(e){let t=B(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=B(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return ae(this,null,function*(){let e=yield _e(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){let e=B(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn);return this.request(e)}logout(){Ot(this.localForageKey);let e=B(this.sdk.testMode?O.LogoutTestMode:O.Logout);return this.request(e)}requestInfoWithUI(e){let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=B(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=B(this.sdk.testMode?O.RecoverAccountTestMode:O.RecoverAccount,[e]);return this.request(t)}getMetadata(){de({method:"user.getMetadata()",removalVersions:he,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}updateEmail(e){de({method:"user.updateEmail()",removalVersions:he,useInstead:"auth.updateEmailWithUI()"}).log();let{email:t,showUI:n=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:n}]);return this.request(o)}};function ze(e,t){return t?new URL(e,t):new URL(e)}function To(){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 Kr="STORE_KEY_PRIVATE_KEY",Rt="STORE_KEY_PUBLIC_JWK",Lt="ECDSA",qr="P-256",No={name:Lt,namedCurve:qr},Mo={name:Lt,namedCurve:qr};function Oo(){return ae(this,null,function*(){let e=yield Lo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,n=yield _e(Kr);if(!n||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:To()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:Tr(JSON.stringify(a)),claims:Tr(JSON.stringify(o))},m=$o(`${l.protected}.${l.claims}`),h={name:Lt,hash:{name:"SHA-256"}},v=xo(new Uint8Array(yield t.sign(h,n,m)));return`${l.protected}.${l.claims}.${v}`})}function Lo(){return ae(this,null,function*(){if(!Co()){console.info("webcrypto is not supported");return}return(yield _e(Rt))||(yield Po()),_e(Rt)})}function Po(){return ae(this,null,function*(){let e=null,{subtle:t}=window.crypto,n=yield t.generateKey(No,!0,["sign"]),o=yield t.exportKey("jwk",n.privateKey);e=yield t.exportKey("jwk",n.publicKey);let a=yield t.importKey("jwk",o,Mo,!1,["sign"]);yield Ue(Kr,a),yield Ue(Rt,e)})}function Co(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Tr(e){return Yr(Do(e))}function $o(e){return new TextEncoder().encode(e)}function Yr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Do(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function xo(e){let t="";return e.forEach(n=>{t+=String.fromCharCode(n)}),Yr(t)}var Uo=class extends Ne{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Mt((t,n)=>ae(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ce.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ce.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ce.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ce.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=B(O.Login,[o]),l=this.request(a);l.on(Ce.WalletSelected,h=>this.handleWalletSelected(Lr(At({},h),{payloadId:a.id}))),l.on("id-token-created",h=>{e.emit("id-token-created",h)});let m=yield l;m.error&&n(m),t(m)}catch(o){n(o)}}));return e}showUI(){return this.request(B(O.ShowUI))}showAddress(){return this.request(B(O.ShowAddress))}showSendTokensUI(){return this.request(B(O.ShowSendTokensUI))}showOnRamp(){return this.request(B(O.ShowOnRamp))}showNFTs(){return this.request(B(O.ShowNFTs))}showBalances(){return this.request(B(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(B(O.SendGaslessTransaction,[[e,t]]))}getInfo(){return ae(this,null,function*(){de({method:"wallet.getInfo()",removalVersions:he,useInstead:"user.getInfo()"}).log();let e=yield _e(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){de({method:"wallet.disconnect()",removalVersions:he,useInstead:"user.logout()"}).log(),Ot(this.localForageKey);let e=B(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){de({method:"wallet.requestUserInfoWithUI()",removalVersions:he,useInstead:"user.requestUserInfoWithUI()"}).log();let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return ae(this,null,function*(){switch(yield _e(this.localForageKey)){case ce.MetaMask:return this.getMetaMaskProvider();case ce.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var e,t,n;return((e=window.ethereum)==null?void 0:e.isMetaMask)||!!((n=(t=window.ethereum)==null?void 0:t.providers)!=null&&n.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(n=>n==null?void 0:n.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,n;return((e=window.ethereum)==null?void 0:e.isCoinbaseWallet)||!!((n=(t=window.ethereum)==null?void 0:t.providers)!=null&&n.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(n=>n==null?void 0:n.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let e=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=e}return this.getCoinbaseProvider().request({method:"eth_requestAccounts"})}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)}getUserEnv(){return{env:{isMetaMaskInstalled:this.isMetaMaskInstalled(),isCoinbaseWalletInstalled:this.isCoinbaseWalletInstalled()}}}connectToThirdPartyWallet(e){switch(e){case ce.MetaMask:return this.connectToMetaMask();case ce.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=B("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return ae(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield Ue(this.localForageKey,e.wallet),this.createIntermediaryEvent(Ce.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Ce.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return ae(this,null,function*(){let t;e===ce.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ce.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield Ue(this.localForageKey,e);let n=B(O.AutoConnect,[{wallet:e,address:t}]);return this.request(n)})}},{createBoundEmitterMethod:it,createChainingEmitterMethod:$e}=Fr(),ko=class extends Ne{constructor(){super(...arguments),this.isMagic=!0,this.on=$e("on",this),this.once=$e("once",this),this.addListener=$e("addListener",this),this.off=$e("off",this),this.removeListener=$e("removeListener",this),this.removeAllListeners=$e("removeAllListeners",this),this.emit=it("emit"),this.eventNames=it("eventNames"),this.listeners=it("listeners"),this.listenerCount=it("listenerCount")}sendAsync(e,t){if(!t)throw uo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Ae.MAGIC_HANDLE_REQUEST,e.map(n=>{let o=st(n);return this.prefixPayloadMethodForTestMode(o),o})).then(n=>{t(null,n.map(o=>Lr(At({},o.payload),{error:o.hasError?new xe(o.payload.error):null})))});else{let n=st(e);this.prefixPayloadMethodForTestMode(n),this.overlay.post(Ae.MAGIC_HANDLE_REQUEST,n).then(o=>{t(o.hasError?new xe(o.payload.error):null,o.payload)})}}send(e,t){if(typeof e=="string"){let o=B(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let n=fo();return n.log(),new Tt(e).applyError({code:-32603,message:n.rawMessage}).payload}enable(){let e=B(O.Login);return this.request(e)}request(e){return this.prefixPayloadMethodForTestMode(e),super.request(e)}prefixPayloadMethodForTestMode(e){let t="testMode/eth/";this.sdk.testMode&&(e.method=`${t}${e.method}`)}},Nr=["request","overlay","sdk"];function Wo(e){let t=Object.getPrototypeOf(e),n=[t];for(;t!==Ne.prototype;)t=Object.getPrototypeOf(t),n.push(t);return n}var Hr=class extends Ne{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Mt,isPromiEvent:Nt,encodeJSON:Cr,decodeJSON:to,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:st,storage:Vr};let e=[this,...Wo(this)];Nr.forEach(t=>{let n=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=n.findIndex(m=>!!m),a=o>0,l=n[o];l&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:l,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw lo(t)}}))})}init(e){this.__is_initialized__||(Nr.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:n,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,n)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:n,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",l=`\`${t}\` will be removed from this Extension in version \`${n}\`.${a}`;return new at(this,"DEPRECATION_NOTICE",l)}createWarning(e,t){return new at(this,e,t)}createError(e,t,n){return new ct(this,e,t,n)}},Bo=class extends Hr{},Te=class extends Hr{};Te.Internal=Bo,Te.Anonymous="anonymous extension";var Fo=class extends Ne{purchase(e){let t=B(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=B(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=B(O.NFTTransfer,[e]);return this.request(t)}};function Mr(e){return e.compat&&e.compat[H.sdkName]!=null?typeof e.compat[H.sdkName]=="string"?qi(zi(H.version),e.compat[H.sdkName]):!!e.compat[H.sdkName]:!0}function Go(e){var t;let n=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(n)?n.forEach(l=>{Mr(l)?(l.init(this),(l.name||l.name!==Te.Anonymous)&&(this[l.name]=l),l instanceof Te.Internal&&(bt(l.config)||(o[l.name]=l.config))):a.push(l)}):Object.keys(n).forEach(l=>{if(Mr(n[l])){n[l].init(this);let m=n[l];this[l]=m,m instanceof Te.Internal&&(bt(m.config)||(o[n[l].name]=m.config))}else a.push(n[l])}),a.length)throw co(a);return o}var ot=class{constructor(e,t){this.apiKey=e;var n;if(!e)throw ao();H.platform==="react-native"&&(t==null?void 0:t.endpoint)&&ho().log();let{defaultEndpoint:o,version:a}=H;this.testMode=!!(t!=null&&t.testMode),this.endpoint=ze((n=t==null?void 0:t.endpoint)!=null?n:o).origin,this.auth=new _o(this),this.user=new So(this),this.wallet=new Uo(this),this.nft=new Fo(this),this.rpcProvider=new ko(this);let l=Go.call(this,t);this.parameters=Cr(At({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:ze(this.endpoint).host,sdk:oo[H.sdkName],version:a,ext:bt(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},H.bundleId?{bundleId:H.bundleId}:{}))}get overlay(){if(!ot.__overlays__.has(this.parameters)){let e=new H.ViewController(this.endpoint,this.parameters);e.init(),ot.__overlays__.set(this.parameters,e)}return ot.__overlays__.get(this.parameters)}preload(){return ae(this,null,function*(){yield this.overlay.ready})}},Pt=ot;Pt.__overlays__=new Map;function jo(e,t){return t&&Array.isArray(e)?e.find(n=>n.id===t):e}function Vo(e,t){var n;let o=(n=t.data.response)==null?void 0:n.id,a=jo(e,o);if(o&&a){let l=new Tt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function Ko(e,t){return ae(this,null,function*(){let n=yield _e("rt"),o;if(H.platform==="web")try{o=yield Oo()}catch(a){console.error("webcrypto error",a)}return o?n?{msgType:e,payload:t,jwt:o,rt:n}:{msgType:e,payload:t,jwt:o}:{msgType:e,payload:t}})}function qo(e){return ae(this,null,function*(){!e.data.rt||(yield Ue("rt",e.data.rt))})}var Xr=class{constructor(e,t){this.endpoint=e,this.parameters=t,this.messageHandlers=new Set,this.ready=this.waitForReady(),this.listen()}post(e,t){return ae(this,null,function*(){return jr(n=>ae(this,null,function*(){yield this.ready;let o=[],a=Array.isArray(t)?t.map(v=>v.id):[],l=yield Ko(`${e}-${this.parameters}`,t);yield this._post(l);let m=v=>g=>{let{id:y,response:T}=Vo(t,g);qo(g),y&&T&&Array.isArray(t)&&a.includes(y)?(o.push(T),o.length===t.length&&(v(),n(o))):y&&T&&!Array.isArray(t)&&y===t.id&&(v(),n(T))},h=this.on(me.MAGIC_HANDLE_RESPONSE,m(()=>h()))}))})}on(e,t){let n=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&n(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{this.on(me.MAGIC_OVERLAY_READY,()=>e())})}listen(){this.on(me.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(me.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Ct={};ar(Ct,{DeepLinkPage:()=>cr,DeviceVerificationEventEmit:()=>Ke,DeviceVerificationEventOnReceived:()=>hr,EthChainType:()=>pr,Events:()=>Ce,Extension:()=>Te,ExtensionError:()=>ct,ExtensionWarning:()=>at,LoginWithEmailOTPEventEmit:()=>Se,LoginWithEmailOTPEventOnReceived:()=>dr,LoginWithMagicLinkEventEmit:()=>ur,LoginWithMagicLinkEventOnReceived:()=>fr,MagicIncomingWindowMessage:()=>me,MagicOutgoingWindowMessage:()=>Ae,MagicPayloadMethod:()=>O,RPCError:()=>xe,RPCErrorCode:()=>Pe,RecoveryMethodType:()=>mr,SDKError:()=>ve,SDKErrorCode:()=>pe,SDKWarning:()=>We,SDKWarningCode:()=>Re,Wallets:()=>ce,isPromiEvent:()=>Nt});var dt=lr(Jr()),Dt=lr(Zr());var Yo={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function Ho(e){for(let[t,n]of Object.entries(Yo))e.style[t]=n}function Xo(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(n=>n.src.includes(e)))}var ft=class extends Xr{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(n=>{let o=()=>{if(Xo(encodeURIComponent(this.parameters)))Ur().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=ze(this.endpoint).host,a.title="Secure Modal",a.src=ze(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,Ho(a),document.body.appendChild(a),n(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",n=>{var o;if(n.origin===this.endpoint&&n.data&&n.data.msgType&&this.messageHandlers.size){n.data.response=(o=n.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(n)}})}showOverlay(){return Le(this,null,function*(){let n=yield this.iframe;n.style.display="block",this.activeElement=document.activeElement,n.focus()})}hideOverlay(){return Le(this,null,function*(){var o;let n=yield this.iframe;n.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(n){return Le(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(n,this.endpoint);else throw xr()})}};var zo=Object.assign(Dr(Pt,{platform:"web",sdkName:"magic-sdk",version:"20.0.0",defaultEndpoint:"https://auth.magic.link/",ViewController:ft,configureStorage:()=>Le(void 0,null,function*(){let e=dt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Dt),yield e.setDriver([dt.default.INDEXEDDB,dt.default.LOCALSTORAGE,Dt._driver]),e})}),ir({},Ct)),Jo=zo;return ei(Qo);})();
|
5
|
+
Received: \`${e.received}\``)}function Ur(){return new We(Re.DuplicateIframe,"Duplicate iframes found.")}function fo(){return new We(Re.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 ho(){return new We(Re.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 \`${H.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function de(e){let{method:t,removalVersions:n,useInstead:o}=e,a=n[H.sdkName],l=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${H.sdkName}\` in version \`${a}\`.${l}`;return new We(Re.DeprecationNotice,m)}function*po(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var mo=po();function kr(){return mo.next().value}var Wr=Symbol("Payload pre-processed by Magic SDK");function Br(e){return Object.defineProperty(e,Wr,{value:!0,enumerable:!1}),e}function vo(e){return!!e[Wr]}function st(e){var t,n,o;return vo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=kr(),e.method=(n=e.method)!=null?n:"noop",e.params=(o=e.params)!=null?o:[],Br(e)),e}function B(e,t=[]){return Br({params:t,method:e,jsonrpc:"2.0",id:kr()})}var Tt=class{constructor(e){e instanceof Tt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):no(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}}},go=fi(di()),yo=class extends go.default{};function Fr(){let e=new yo;return{emitter:e,createChainingEmitterMethod:(t,n)=>(...o)=>(e[t].apply(e,o),n),createBoundEmitterMethod:t=>(...n)=>e[t].apply(e,n)}}var Gr=Symbol("isPromiEvent");function Nt(e){return!!e[Gr]}function Mt(e){let t=jr(e),{createBoundEmitterMethod:n,createChainingEmitterMethod:o}=Fr(),a=Symbol("Promise.then"),l=Symbol("Promise.catch"),m=Symbol("Promise.finally"),h=(y,T)=>(...I)=>{let N=T[y].apply(T,I);return v(N)},v=y=>Object.assign(y,{[Gr]:!0,[a]:y[a]||y.then,[l]:y[l]||y.catch,[m]:y[m]||y.finally,then:h(a,y),catch:h(l,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:n("emit"),eventNames:n("eventNames"),listeners:n("listeners"),listenerCount:n("listenerCount")}),g=v(t.then(y=>(g.emit("done",y),g.emit("settled"),y),y=>{throw g.emit("error",y),g.emit("settled"),y}));return g}function jr(e){return new Promise((t,n)=>{let o=e(t,n);Promise.resolve(o).catch(n)})}var Ne=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(Ae.MAGIC_HANDLE_REQUEST,st(e)),n=Mt((a,l)=>{t.then(m=>{if(o(),m.hasError)l(new xe(m.payload.error));else if(m.hasResult)a(m.payload.result);else throw so()}).catch(m=>{o(),l(m)})}),o=this.overlay.on(me.MAGIC_HANDLE_EVENT,a=>{var l;let{response:m}=a.data;if(m.id===e.id&&((l=m.result)==null?void 0:l.event)){let{event:h,params:v=[]}=m.result;n.emit(h,...v)}});return n}createIntermediaryEvent(e,t){return n=>{let o=B(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:n}]);this.request(o)}}};function Eo(e,t){let[n]=e.split(".").map(Number);return n>=t}var he={"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"},_o=class extends Ne{loginWithMagicLink(e){let t=H.sdkName==="@magic-sdk/react-native"||H.sdkName==="@magic-sdk/react-native-bare"||H.sdkName==="@magic-sdk/react-native-expo";if(t&&Eo(H.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");de({method:"auth.loginWithMagicLink()",removalVersions:he,useInstead:t?"@magic-ext/auth auth.loginWithEmailOTP()":"@magic-ext/auth auth.loginWithMagicLink()"}).log();let{email:n,showUI:o=!0,redirectURI:a}=e,l=B(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:n,showUI:o,redirectURI:a}]);return this.request(l)}loginWithSMS(e){de({method:"auth.loginWithSMS()",removalVersions:he,useInstead:"@magic-ext/auth auth.loginWithSMS()"}).log();let{phoneNumber:t}=e,n=B(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(n)}loginWithEmailOTP(e){let{email:t,showUI:n,deviceCheckUI:o}=e,a=B(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:n,deviceCheckUI:o}]),l=this.request(a);return!o&&l&&l.on(Ke.Retry,()=>{this.createIntermediaryEvent(Ke.Retry,a.id)()}),!n&&l&&(l.on(Se.VerifyEmailOtp,m=>{this.createIntermediaryEvent(Se.VerifyEmailOtp,a.id)(m)}),l.on(Se.Cancel,()=>{this.createIntermediaryEvent(Se.Cancel,a.id)()})),l}loginWithCredential(e){de({method:"auth.loginWithCredential()",removalVersions:he,useInstead:"@magic-ext/auth auth.loginWithCredential()"}).log();let t=e!=null?e:"";if(!e&&H.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let n=B(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(n)}setAuthorizationToken(e){de({method:"auth.setAuthorizationToken()",removalVersions:he,useInstead:"@magic-ext/auth auth.setAuthorizationToken()"}).log();let t=B(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){de({method:"auth.updateEmailWithUI()",removalVersions:he,useInstead:"@magic-ext/auth auth.updateEmailWithUI()"}).log();let{email:t,showUI:n=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:n}]);return this.request(o)}},Vr={};ci(Vr,{clear:()=>Io,getItem:()=>_e,iterate:()=>Ao,key:()=>bo,keys:()=>Ro,length:()=>wo,removeItem:()=>Ot,setItem:()=>Ue});var nt;function Ie(e){return(...t)=>ae(this,null,function*(){return nt||(nt=yield H.configureStorage()),yield nt.ready(),nt[e](...t)})}var _e=Ie("getItem"),Ue=Ie("setItem"),Ot=Ie("removeItem"),Io=Ie("clear"),wo=Ie("length"),bo=Ie("key"),Ro=Ie("keys"),Ao=Ie("iterate"),So=class extends Ne{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}getIdToken(e){let t=B(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=B(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return ae(this,null,function*(){let e=yield _e(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){let e=B(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn);return this.request(e)}logout(){Ot(this.localForageKey);let e=B(this.sdk.testMode?O.LogoutTestMode:O.Logout);return this.request(e)}requestInfoWithUI(e){let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=B(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=B(this.sdk.testMode?O.RecoverAccountTestMode:O.RecoverAccount,[e]);return this.request(t)}getMetadata(){de({method:"user.getMetadata()",removalVersions:he,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}updateEmail(e){de({method:"user.updateEmail()",removalVersions:he,useInstead:"auth.updateEmailWithUI()"}).log();let{email:t,showUI:n=!0}=e,o=B(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:n}]);return this.request(o)}};function ze(e,t){return t?new URL(e,t):new URL(e)}function To(){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 Kr="STORE_KEY_PRIVATE_KEY",Rt="STORE_KEY_PUBLIC_JWK",Lt="ECDSA",qr="P-256",No={name:Lt,namedCurve:qr},Mo={name:Lt,namedCurve:qr};function Oo(){return ae(this,null,function*(){let e=yield Lo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,n=yield _e(Kr);if(!n||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:To()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:Tr(JSON.stringify(a)),claims:Tr(JSON.stringify(o))},m=$o(`${l.protected}.${l.claims}`),h={name:Lt,hash:{name:"SHA-256"}},v=xo(new Uint8Array(yield t.sign(h,n,m)));return`${l.protected}.${l.claims}.${v}`})}function Lo(){return ae(this,null,function*(){if(!Co()){console.info("webcrypto is not supported");return}return(yield _e(Rt))||(yield Po()),_e(Rt)})}function Po(){return ae(this,null,function*(){let e=null,{subtle:t}=window.crypto,n=yield t.generateKey(No,!0,["sign"]),o=yield t.exportKey("jwk",n.privateKey);e=yield t.exportKey("jwk",n.publicKey);let a=yield t.importKey("jwk",o,Mo,!1,["sign"]);yield Ue(Kr,a),yield Ue(Rt,e)})}function Co(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Tr(e){return Yr(Do(e))}function $o(e){return new TextEncoder().encode(e)}function Yr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Do(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function xo(e){let t="";return e.forEach(n=>{t+=String.fromCharCode(n)}),Yr(t)}var Uo=class extends Ne{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}connectWithUI(){let e=Mt((t,n)=>ae(this,null,function*(){try{if(this.isMetaMaskBrowser()&&(yield this.isWalletEnabled(ce.MetaMask))){let h=yield this.autoConnectIfWalletBrowser(ce.MetaMask);t(h);return}if(this.isCoinbaseWalletBrowser()&&(yield this.isWalletEnabled(ce.CoinbaseWallet))){let h=yield this.autoConnectIfWalletBrowser(ce.CoinbaseWallet);t(h);return}let o=this.getUserEnv(),a=B(O.Login,[o]),l=this.request(a);l.on(Ce.WalletSelected,h=>this.handleWalletSelected(Lr(At({},h),{payloadId:a.id}))),l.on("id-token-created",h=>{e.emit("id-token-created",h)});let m=yield l;m.error&&n(m),t(m)}catch(o){n(o)}}));return e}showUI(){return this.request(B(O.ShowUI))}showAddress(){return this.request(B(O.ShowAddress))}showSendTokensUI(){return this.request(B(O.ShowSendTokensUI))}showOnRamp(){return this.request(B(O.ShowOnRamp))}showNFTs(){return this.request(B(O.ShowNFTs))}showBalances(){return this.request(B(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(B(O.SendGaslessTransaction,[e,t]))}getInfo(){return ae(this,null,function*(){de({method:"wallet.getInfo()",removalVersions:he,useInstead:"user.getInfo()"}).log();let e=yield _e(this.localForageKey),t=B(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){de({method:"wallet.disconnect()",removalVersions:he,useInstead:"user.logout()"}).log(),Ot(this.localForageKey);let e=B(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){de({method:"wallet.requestUserInfoWithUI()",removalVersions:he,useInstead:"user.requestUserInfoWithUI()"}).log();let t=B(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return ae(this,null,function*(){switch(yield _e(this.localForageKey)){case ce.MetaMask:return this.getMetaMaskProvider();case ce.CoinbaseWallet:return this.getCoinbaseProvider();default:return this.sdk.rpcProvider}})}isMetaMaskInstalled(){var e,t,n;return((e=window.ethereum)==null?void 0:e.isMetaMask)||!!((n=(t=window.ethereum)==null?void 0:t.providers)!=null&&n.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(n=>n==null?void 0:n.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,n;return((e=window.ethereum)==null?void 0:e.isCoinbaseWallet)||!!((n=(t=window.ethereum)==null?void 0:t.providers)!=null&&n.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(n=>n==null?void 0:n.isCoinbaseWallet))||window.ethereum}connectToCoinbaseWallet(){if(this.isMobile()&&!this.isCoinbaseWalletBrowser()){let e=`https://go.cb-w.com/dapp?cb_url=${encodeURIComponent(window.location.href)}`;window.location.href=e}return this.getCoinbaseProvider().request({method:"eth_requestAccounts"})}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)}getUserEnv(){return{env:{isMetaMaskInstalled:this.isMetaMaskInstalled(),isCoinbaseWalletInstalled:this.isCoinbaseWalletInstalled()}}}connectToThirdPartyWallet(e){switch(e){case ce.MetaMask:return this.connectToMetaMask();case ce.CoinbaseWallet:return this.connectToCoinbaseWallet();default:throw new Error(`Invalid provider: ${e}. Must be one of "metamask" or "coinbase_wallet".`)}}isWalletEnabled(e){let t=B("mc_is_wallet_enabled",[{wallet:e}]);return this.request(t)}handleWalletSelected(e){return ae(this,null,function*(){try{let t=yield this.connectToThirdPartyWallet(e.wallet);yield Ue(this.localForageKey,e.wallet),this.createIntermediaryEvent(Ce.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Ce.WalletRejected,e.payloadId)()}})}autoConnectIfWalletBrowser(e){return ae(this,null,function*(){let t;e===ce.MetaMask&&(t=yield this.getMetaMaskProvider().request({method:"eth_requestAccounts"})),e===ce.CoinbaseWallet&&(t=yield this.getCoinbaseProvider().request({method:"eth_requestAccounts"})),yield Ue(this.localForageKey,e);let n=B(O.AutoConnect,[{wallet:e,address:t}]);return this.request(n)})}},{createBoundEmitterMethod:it,createChainingEmitterMethod:$e}=Fr(),ko=class extends Ne{constructor(){super(...arguments),this.isMagic=!0,this.on=$e("on",this),this.once=$e("once",this),this.addListener=$e("addListener",this),this.off=$e("off",this),this.removeListener=$e("removeListener",this),this.removeAllListeners=$e("removeAllListeners",this),this.emit=it("emit"),this.eventNames=it("eventNames"),this.listeners=it("listeners"),this.listenerCount=it("listenerCount")}sendAsync(e,t){if(!t)throw uo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Ae.MAGIC_HANDLE_REQUEST,e.map(n=>{let o=st(n);return this.prefixPayloadMethodForTestMode(o),o})).then(n=>{t(null,n.map(o=>Lr(At({},o.payload),{error:o.hasError?new xe(o.payload.error):null})))});else{let n=st(e);this.prefixPayloadMethodForTestMode(n),this.overlay.post(Ae.MAGIC_HANDLE_REQUEST,n).then(o=>{t(o.hasError?new xe(o.payload.error):null,o.payload)})}}send(e,t){if(typeof e=="string"){let o=B(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let n=fo();return n.log(),new Tt(e).applyError({code:-32603,message:n.rawMessage}).payload}enable(){let e=B(O.Login);return this.request(e)}request(e){return this.prefixPayloadMethodForTestMode(e),super.request(e)}prefixPayloadMethodForTestMode(e){let t="testMode/eth/";this.sdk.testMode&&(e.method=`${t}${e.method}`)}},Nr=["request","overlay","sdk"];function Wo(e){let t=Object.getPrototypeOf(e),n=[t];for(;t!==Ne.prototype;)t=Object.getPrototypeOf(t),n.push(t);return n}var Hr=class extends Ne{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Mt,isPromiEvent:Nt,encodeJSON:Cr,decodeJSON:to,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:st,storage:Vr};let e=[this,...Wo(this)];Nr.forEach(t=>{let n=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=n.findIndex(m=>!!m),a=o>0,l=n[o];l&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:l,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw lo(t)}}))})}init(e){this.__is_initialized__||(Nr.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:n,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,n)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:n,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",l=`\`${t}\` will be removed from this Extension in version \`${n}\`.${a}`;return new at(this,"DEPRECATION_NOTICE",l)}createWarning(e,t){return new at(this,e,t)}createError(e,t,n){return new ct(this,e,t,n)}},Bo=class extends Hr{},Te=class extends Hr{};Te.Internal=Bo,Te.Anonymous="anonymous extension";var Fo=class extends Ne{purchase(e){let t=B(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=B(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=B(O.NFTTransfer,[e]);return this.request(t)}};function Mr(e){return e.compat&&e.compat[H.sdkName]!=null?typeof e.compat[H.sdkName]=="string"?qi(zi(H.version),e.compat[H.sdkName]):!!e.compat[H.sdkName]:!0}function Go(e){var t;let n=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(n)?n.forEach(l=>{Mr(l)?(l.init(this),(l.name||l.name!==Te.Anonymous)&&(this[l.name]=l),l instanceof Te.Internal&&(bt(l.config)||(o[l.name]=l.config))):a.push(l)}):Object.keys(n).forEach(l=>{if(Mr(n[l])){n[l].init(this);let m=n[l];this[l]=m,m instanceof Te.Internal&&(bt(m.config)||(o[n[l].name]=m.config))}else a.push(n[l])}),a.length)throw co(a);return o}var ot=class{constructor(e,t){this.apiKey=e;var n;if(!e)throw ao();H.platform==="react-native"&&(t==null?void 0:t.endpoint)&&ho().log();let{defaultEndpoint:o,version:a}=H;this.testMode=!!(t!=null&&t.testMode),this.endpoint=ze((n=t==null?void 0:t.endpoint)!=null?n:o).origin,this.auth=new _o(this),this.user=new So(this),this.wallet=new Uo(this),this.nft=new Fo(this),this.rpcProvider=new ko(this);let l=Go.call(this,t);this.parameters=Cr(At({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:ze(this.endpoint).host,sdk:oo[H.sdkName],version:a,ext:bt(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},H.bundleId?{bundleId:H.bundleId}:{}))}get overlay(){if(!ot.__overlays__.has(this.parameters)){let e=new H.ViewController(this.endpoint,this.parameters);e.init(),ot.__overlays__.set(this.parameters,e)}return ot.__overlays__.get(this.parameters)}preload(){return ae(this,null,function*(){yield this.overlay.ready})}},Pt=ot;Pt.__overlays__=new Map;function jo(e,t){return t&&Array.isArray(e)?e.find(n=>n.id===t):e}function Vo(e,t){var n;let o=(n=t.data.response)==null?void 0:n.id,a=jo(e,o);if(o&&a){let l=new Tt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function Ko(e,t){return ae(this,null,function*(){let n=yield _e("rt"),o;if(H.platform==="web")try{o=yield Oo()}catch(a){console.error("webcrypto error",a)}return o?n?{msgType:e,payload:t,jwt:o,rt:n}:{msgType:e,payload:t,jwt:o}:{msgType:e,payload:t}})}function qo(e){return ae(this,null,function*(){!e.data.rt||(yield Ue("rt",e.data.rt))})}var Xr=class{constructor(e,t){this.endpoint=e,this.parameters=t,this.messageHandlers=new Set,this.ready=this.waitForReady(),this.listen()}post(e,t){return ae(this,null,function*(){return jr(n=>ae(this,null,function*(){yield this.ready;let o=[],a=Array.isArray(t)?t.map(v=>v.id):[],l=yield Ko(`${e}-${this.parameters}`,t);yield this._post(l);let m=v=>g=>{let{id:y,response:T}=Vo(t,g);qo(g),y&&T&&Array.isArray(t)&&a.includes(y)?(o.push(T),o.length===t.length&&(v(),n(o))):y&&T&&!Array.isArray(t)&&y===t.id&&(v(),n(T))},h=this.on(me.MAGIC_HANDLE_RESPONSE,m(()=>h()))}))})}on(e,t){let n=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&n(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{this.on(me.MAGIC_OVERLAY_READY,()=>e())})}listen(){this.on(me.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(me.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Ct={};ar(Ct,{DeepLinkPage:()=>cr,DeviceVerificationEventEmit:()=>Ke,DeviceVerificationEventOnReceived:()=>hr,EthChainType:()=>pr,Events:()=>Ce,Extension:()=>Te,ExtensionError:()=>ct,ExtensionWarning:()=>at,LoginWithEmailOTPEventEmit:()=>Se,LoginWithEmailOTPEventOnReceived:()=>dr,LoginWithMagicLinkEventEmit:()=>ur,LoginWithMagicLinkEventOnReceived:()=>fr,MagicIncomingWindowMessage:()=>me,MagicOutgoingWindowMessage:()=>Ae,MagicPayloadMethod:()=>O,RPCError:()=>xe,RPCErrorCode:()=>Pe,RecoveryMethodType:()=>mr,SDKError:()=>ve,SDKErrorCode:()=>pe,SDKWarning:()=>We,SDKWarningCode:()=>Re,Wallets:()=>ce,isPromiEvent:()=>Nt});var dt=lr(Jr()),Dt=lr(Zr());var Yo={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function Ho(e){for(let[t,n]of Object.entries(Yo))e.style[t]=n}function Xo(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(n=>n.src.includes(e)))}var ft=class extends Xr{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(n=>{let o=()=>{if(Xo(encodeURIComponent(this.parameters)))Ur().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=ze(this.endpoint).host,a.title="Secure Modal",a.src=ze(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,Ho(a),document.body.appendChild(a),n(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",n=>{var o;if(n.origin===this.endpoint&&n.data&&n.data.msgType&&this.messageHandlers.size){n.data.response=(o=n.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(n)}})}showOverlay(){return Le(this,null,function*(){let n=yield this.iframe;n.style.display="block",this.activeElement=document.activeElement,n.focus()})}hideOverlay(){return Le(this,null,function*(){var o;let n=yield this.iframe;n.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(n){return Le(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(n,this.endpoint);else throw xr()})}};var zo=Object.assign(Dr(Pt,{platform:"web",sdkName:"magic-sdk",version:"20.0.0",defaultEndpoint:"https://auth.magic.link/",ViewController:ft,configureStorage:()=>Le(void 0,null,function*(){let e=dt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Dt),yield e.setDriver([dt.default.INDEXEDDB,dt.default.LOCALSTORAGE,Dt._driver]),e})}),ir({},Ct)),Jo=zo;return ei(Qo);})();
|
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": "20.0.0",
|
3
|
+
"version": "20.0.1-canary.522b998.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": "16.0.1-canary.522b998.0",
|
33
|
+
"@magic-sdk/provider": "20.0.1-canary.522b998.0",
|
34
34
|
"@magic-sdk/types": "^17.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": "522b99893457342c6d65d398f71bb84f08d7efc4"
|
44
44
|
}
|