magic-sdk 21.0.0 → 21.1.0-canary.643.6567644654.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 +5 -5
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 pe(de.IncompatibleExtensions,t)}function co(e){let t=n=>{let o=n+1,s=o%10,l=o%100;return s===1&&l!==11?`${o}st`:s===2&&l!==12?`${o}nd`:s===3&&l!==13?`${o}rd`:`${o}th`};return new pe(de.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
4
4
|
Expected: \`${e.expected}\`
|
5
|
-
Received: \`${e.received}\``)}function xr(){return new Be(we.DuplicateIframe,"Duplicate iframes found.")}function uo(){return new Be(we.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 fo(){return new Be(we.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 $e(e){let{method:t,removalVersions:n,useInstead:o}=e,s=n[H.sdkName],l=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${H.sdkName}\` in version \`${s}\`.${l}`;return new Be(we.DeprecationNotice,m)}function*ho(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var po=ho();function Ur(){return po.next().value}var kr=Symbol("Payload pre-processed by Magic SDK");function Br(e){return Object.defineProperty(e,kr,{value:!0,enumerable:!1}),e}function mo(e){return!!e[kr]}function st(e){var t,n,o;return mo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Ur(),e.method=(n=e.method)!=null?n:"noop",e.params=(o=e.params)!=null?o:[],Br(e)),e}function W(e,t=[]){return Br({params:t,method:e,jsonrpc:"2.0",id:Ur()})}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):ro(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}}},vo=ui(fi()),go=class extends vo.default{};function Wr(){let e=new go;return{emitter:e,createChainingEmitterMethod:(t,n)=>(...o)=>(e[t].apply(e,o),n),createBoundEmitterMethod:t=>(...n)=>e[t].apply(e,n)}}var Fr=Symbol("isPromiEvent");function Nt(e){return!!e[Fr]}function Mt(e){let t=Gr(e),{createBoundEmitterMethod:n,createChainingEmitterMethod:o}=Wr(),s=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,{[Fr]:!0,[s]:y[s]||y.then,[l]:y[l]||y.catch,[m]:y[m]||y.finally,then:h(s,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 Gr(e){return new Promise((t,n)=>{let o=e(t,n);Promise.resolve(o).catch(n)})}var Se=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(be.MAGIC_HANDLE_REQUEST,st(e)),n=Mt((s,l)=>{t.then(m=>{if(o(),m.hasError)l(new xe(m.payload.error));else if(m.hasResult)s(m.payload.result);else throw ao()}).catch(m=>{o(),l(m)})}),o=this.overlay.on(he.MAGIC_HANDLE_EVENT,s=>{var l;let{response:m}=s.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=W(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:n}]);this.request(o)}}};function yo(e,t){let[n]=e.split(".").map(Number);return n>=t}var De={"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"},Eo=class extends Se{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&&yo(H.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&$e({method:"auth.loginWithMagicLink()",removalVersions:De,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:n,showUI:o=!0,redirectURI:s}=e,l=W(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:n,showUI:o,redirectURI:s}]);return this.request(l)}loginWithSMS(e){let{phoneNumber:t}=e,n=W(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,s=W(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:n,deviceCheckUI:o}]),l=this.request(s);return!o&&l&&l.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.Retry,s.id)()}),!n&&l&&(l.on(Re.VerifyEmailOtp,m=>{this.createIntermediaryEvent(Re.VerifyEmailOtp,s.id)(m)}),l.on(Re.Cancel,()=>{this.createIntermediaryEvent(Re.Cancel,s.id)()})),l}loginWithCredential(e){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=W(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(n)}setAuthorizationToken(e){let t=W(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:n=!0}=e,o=W(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:n}]);return this.request(o)}},jr={};li(jr,{clear:()=>_o,getItem:()=>ye,iterate:()=>Ro,key:()=>wo,keys:()=>bo,length:()=>Io,removeItem:()=>Ot,setItem:()=>Ue});var nt;function Ee(e){return(...t)=>ae(this,null,function*(){return nt||(nt=yield H.configureStorage()),yield nt.ready(),nt[e](...t)})}var ye=Ee("getItem"),Ue=Ee("setItem"),Ot=Ee("removeItem"),_o=Ee("clear"),Io=Ee("length"),wo=Ee("key"),bo=Ee("keys"),Ro=Ee("iterate"),Ao=class extends Se{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}getIdToken(e){let t=W(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return ae(this,null,function*(){let e=yield ye(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){let e=W(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn);return this.request(e)}logout(){Ot(this.localForageKey);let e=W(this.sdk.testMode?O.LogoutTestMode:O.Logout);return this.request(e)}requestInfoWithUI(e){let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?O.RecoverAccountTestMode:O.RecoverAccount,[e]);return this.request(t)}getMetadata(){$e({method:"user.getMetadata()",removalVersions:De,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}updateEmail(e){$e({method:"user.updateEmail()",removalVersions:De,useInstead:"auth.updateEmailWithUI()"}).log();let{email:t,showUI:n=!0}=e,o=W(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 So(){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 Vr="STORE_KEY_PRIVATE_KEY",Rt="STORE_KEY_PUBLIC_JWK",qr="ECDSA",To="P-256",No={name:qr,namedCurve:To};function Mo(){return ae(this,null,function*(){let e=yield Oo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,n=yield ye(Vr);if(!n||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:So()},s={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:Sr(JSON.stringify(s)),claims:Sr(JSON.stringify(o))},m=Co(`${l.protected}.${l.claims}`),h={name:qr,hash:{name:"SHA-256"}},v=Do(new Uint8Array(yield t.sign(h,n,m)));return`${l.protected}.${l.claims}.${v}`})}function Oo(){return ae(this,null,function*(){if(!Po()){console.info("webcrypto is not supported");return}return(yield ye(Rt))||(yield Lo()),ye(Rt)})}function Lo(){return ae(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(No,!1,["sign"]),n=yield e.exportKey("jwk",t.publicKey);yield Ue(Vr,t.privateKey),yield Ue(Rt,n)})}function Po(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Sr(e){return Kr($o(e))}function Co(e){return new TextEncoder().encode(e)}function Kr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function $o(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function Do(e){let t="";return e.forEach(n=>{t+=String.fromCharCode(n)}),Kr(t)}var xo=class extends Se{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(),s=W(O.Login,[o]),l=this.request(s);l.on(Le.WalletSelected,h=>this.handleWalletSelected(Or(At({},h),{payloadId:s.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(W(O.ShowUI))}showAddress(){return this.request(W(O.ShowAddress))}showSendTokensUI(){return this.request(W(O.ShowSendTokensUI))}showOnRamp(){return this.request(W(O.ShowOnRamp))}showNFTs(){return this.request(W(O.ShowNFTs))}showBalances(){return this.request(W(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(O.SendGaslessTransaction,[e,t]))}getInfo(){return ae(this,null,function*(){$e({method:"wallet.getInfo()",removalVersions:De,useInstead:"user.getInfo()"}).log();let e=yield ye(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){$e({method:"wallet.disconnect()",removalVersions:De,useInstead:"user.logout()"}).log(),Ot(this.localForageKey);let e=W(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){$e({method:"wallet.requestUserInfoWithUI()",removalVersions:De,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return ae(this,null,function*(){switch(yield ye(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=W("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(Le.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Le.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=W(O.AutoConnect,[{wallet:e,address:t}]);return this.request(n)})}},{createBoundEmitterMethod:it,createChainingEmitterMethod:Pe}=Wr(),Uo=class extends Se{constructor(){super(...arguments),this.isMagic=!0,this.on=Pe("on",this),this.once=Pe("once",this),this.addListener=Pe("addListener",this),this.off=Pe("off",this),this.removeListener=Pe("removeListener",this),this.removeAllListeners=Pe("removeAllListeners",this),this.emit=it("emit"),this.eventNames=it("eventNames"),this.listeners=it("listeners"),this.listenerCount=it("listenerCount")}sendAsync(e,t){if(!t)throw co({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(be.MAGIC_HANDLE_REQUEST,e.map(n=>{let o=st(n);return this.prefixPayloadMethodForTestMode(o),o})).then(n=>{t(null,n.map(o=>Or(At({},o.payload),{error:o.hasError?new xe(o.payload.error):null})))});else{let n=st(e);this.prefixPayloadMethodForTestMode(n),this.overlay.post(be.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=W(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let n=uo();return n.log(),new Tt(e).applyError({code:-32603,message:n.rawMessage}).payload}enable(){let e=W(O.Login);return this.request(e)}request(e){return this.prefixPayloadMethodForTestMode(e),super.request(e)}prefixPayloadMethodForTestMode(e){let t="testMode/eth/";this.sdk.testMode&&(e.method=`${t}${e.method}`)}},Tr=["request","overlay","sdk"];function ko(e){let t=Object.getPrototypeOf(e),n=[t];for(;t!==Se.prototype;)t=Object.getPrototypeOf(t),n.push(t);return n}var Yr=class extends Se{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Mt,isPromiEvent:Nt,encodeJSON:Pr,decodeJSON:eo,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:st,storage:jr};let e=[this,...ko(this)];Tr.forEach(t=>{let n=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=n.findIndex(m=>!!m),s=o>0,l=n[o];l&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:l,isPrototypeField:s}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw so(t)}}))})}init(e){this.__is_initialized__||(Tr.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,s=o?` Use \`${o}\` instead.`:"",l=`\`${t}\` will be removed from this Extension in version \`${n}\`.${s}`;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 Yr{},Ae=class extends Yr{};Ae.Internal=Bo,Ae.Anonymous="anonymous extension";var Wo=class extends Se{purchase(e){let t=W(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(O.NFTTransfer,[e]);return this.request(t)}};function Nr(e){return e.compat&&e.compat[H.sdkName]!=null?typeof e.compat[H.sdkName]=="string"?qi(Xi(H.version),e.compat[H.sdkName]):!!e.compat[H.sdkName]:!0}function Fo(e){var t;let n=(t=e==null?void 0:e.extensions)!=null?t:[],o={},s=[];if(Array.isArray(n)?n.forEach(l=>{Nr(l)?(l.init(this),(l.name||l.name!==Ae.Anonymous)&&(this[l.name]=l),l instanceof Ae.Internal&&(bt(l.config)||(o[l.name]=l.config))):s.push(l)}):Object.keys(n).forEach(l=>{if(Nr(n[l])){n[l].init(this);let m=n[l];this[l]=m,m instanceof Ae.Internal&&(bt(m.config)||(o[n[l].name]=m.config))}else s.push(n[l])}),s.length)throw lo(s);return o}var ot=class{constructor(e,t){this.apiKey=e;var n;if(!e)throw oo();H.platform==="react-native"&&(t==null?void 0:t.endpoint)&&fo().log();let{defaultEndpoint:o,version:s}=H;this.testMode=!!(t!=null&&t.testMode),this.endpoint=ze((n=t==null?void 0:t.endpoint)!=null?n:o).origin,this.auth=new Eo(this),this.user=new Ao(this),this.wallet=new xo(this),this.nft=new Wo(this),this.rpcProvider=new Uo(this);let l=Fo.call(this,t);this.parameters=Pr(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:io[H.sdkName],version:s,ext:bt(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},H.bundleId?{bundleId:H.bundleId}:{})),t!=null&&t.deferPreload||this.preload()}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})}},Lt=ot;Lt.__overlays__=new Map;function Go(e,t){return t&&Array.isArray(e)?e.find(n=>n.id===t):e}function jo(e,t){var n;let o=(n=t.data.response)==null?void 0:n.id,s=Go(e,o);if(o&&s){let l=new Tt(s).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function Vo(e,t){return ae(this,null,function*(){let n=yield ye("rt"),o;if(H.platform==="web")try{o=yield Mo()}catch(s){console.error("webcrypto error",s)}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 Hr=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 Gr(n=>ae(this,null,function*(){yield this.ready;let o=[],s=Array.isArray(t)?t.map(v=>v.id):[],l=yield Vo(`${e}-${this.parameters}`,t);yield this._post(l);let m=v=>g=>{let{id:y,response:T}=jo(t,g);qo(g),y&&T&&Array.isArray(t)&&s.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(he.MAGIC_HANDLE_RESPONSE,m(()=>h()))}))})}on(e,t){let n=t.bind(window),o=s=>{s.data.msgType===`${e}-${this.parameters}`&&n(s)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{this.on(he.MAGIC_OVERLAY_READY,()=>e())})}listen(){this.on(he.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(he.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Pt={};or(Pt,{DeepLinkPage:()=>lr,DeviceVerificationEventEmit:()=>qe,DeviceVerificationEventOnReceived:()=>dr,EthChainType:()=>hr,Events:()=>Le,Extension:()=>Ae,ExtensionError:()=>ct,ExtensionWarning:()=>at,LoginWithEmailOTPEventEmit:()=>Re,LoginWithEmailOTPEventOnReceived:()=>fr,LoginWithMagicLinkEventEmit:()=>cr,LoginWithMagicLinkEventOnReceived:()=>ur,MagicIncomingWindowMessage:()=>he,MagicOutgoingWindowMessage:()=>be,MagicPayloadMethod:()=>O,RPCError:()=>xe,RPCErrorCode:()=>Oe,RecoveryMethodType:()=>pr,SDKError:()=>pe,SDKErrorCode:()=>de,SDKWarning:()=>Be,SDKWarningCode:()=>we,Wallets:()=>ce,isPromiEvent:()=>Nt});var dt=sr(zr()),$t=sr(Qr());var Ko={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function Yo(e){for(let[t,n]of Object.entries(Ko))e.style[t]=n}function Ho(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(n=>n.src.includes(e)))}var ft=class extends Hr{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(n=>{let o=()=>{if(Ho(encodeURIComponent(this.parameters)))xr().log();else{let s=document.createElement("iframe");s.classList.add("magic-iframe"),s.dataset.magicIframeLabel=ze(this.endpoint).host,s.title="Secure Modal",s.src=ze(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,Yo(s),document.body.appendChild(s),n(s)}};["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 s of this.messageHandlers.values())s(n)}})}showOverlay(){return Me(this,null,function*(){let n=yield this.iframe;n.style.display="block",this.activeElement=document.activeElement,n.focus()})}hideOverlay(){return Me(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 Me(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(n,this.endpoint);else throw Dr()})}};var Xo=Object.assign($r(Lt,{platform:"web",sdkName:"magic-sdk",version:"21.0.0",defaultEndpoint:"https://auth.magic.link/",ViewController:ft,configureStorage:()=>Me(void 0,null,function*(){let e=dt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver($t),yield e.setDriver([dt.default.INDEXEDDB,dt.default.LOCALSTORAGE,$t._driver]),e})}),nr({},Pt)),zo=Xo;return Zn(Jo);})();
|
5
|
+
Received: \`${e.received}\``)}function xr(){return new Be(we.DuplicateIframe,"Duplicate iframes found.")}function uo(){return new Be(we.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 fo(){return new Be(we.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 $e(e){let{method:t,removalVersions:n,useInstead:o}=e,s=n[H.sdkName],l=o?` Use \`${o}\` instead.`:"",m=`\`${t}\` will be removed from \`${H.sdkName}\` in version \`${s}\`.${l}`;return new Be(we.DeprecationNotice,m)}function*ho(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var po=ho();function Ur(){return po.next().value}var kr=Symbol("Payload pre-processed by Magic SDK");function Br(e){return Object.defineProperty(e,kr,{value:!0,enumerable:!1}),e}function mo(e){return!!e[kr]}function st(e){var t,n,o;return mo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Ur(),e.method=(n=e.method)!=null?n:"noop",e.params=(o=e.params)!=null?o:[],Br(e)),e}function W(e,t=[]){return Br({params:t,method:e,jsonrpc:"2.0",id:Ur()})}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):ro(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}}},vo=ui(fi()),go=class extends vo.default{};function Wr(){let e=new go;return{emitter:e,createChainingEmitterMethod:(t,n)=>(...o)=>(e[t].apply(e,o),n),createBoundEmitterMethod:t=>(...n)=>e[t].apply(e,n)}}var Fr=Symbol("isPromiEvent");function Nt(e){return!!e[Fr]}function Mt(e){let t=Gr(e),{createBoundEmitterMethod:n,createChainingEmitterMethod:o}=Wr(),s=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,{[Fr]:!0,[s]:y[s]||y.then,[l]:y[l]||y.catch,[m]:y[m]||y.finally,then:h(s,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 Gr(e){return new Promise((t,n)=>{let o=e(t,n);Promise.resolve(o).catch(n)})}var Se=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){let t=this.overlay.post(be.MAGIC_HANDLE_REQUEST,st(e)),n=Mt((s,l)=>{t.then(m=>{if(o(),m.hasError)l(new xe(m.payload.error));else if(m.hasResult)s(m.payload.result);else throw ao()}).catch(m=>{o(),l(m)})}),o=this.overlay.on(he.MAGIC_HANDLE_EVENT,s=>{var l;let{response:m}=s.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=W(O.IntermediaryEvent,[{payloadId:t,eventType:e,args:n}]);this.request(o)}}};function yo(e,t){let[n]=e.split(".").map(Number);return n>=t}var De={"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"},Eo=class extends Se{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&&yo(H.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&$e({method:"auth.loginWithMagicLink()",removalVersions:De,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:n,showUI:o=!0,redirectURI:s,overrides:l}=e,m=W(this.sdk.testMode?O.LoginWithMagicLinkTestMode:O.LoginWithMagicLink,[{email:n,showUI:o,redirectURI:s,overrides:l}]);return this.request(m)}loginWithSMS(e){let{phoneNumber:t}=e,n=W(this.sdk.testMode?O.LoginWithSmsTestMode:O.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(n)}loginWithEmailOTP(e){let{email:t,showUI:n,deviceCheckUI:o,overrides:s}=e,l=W(this.sdk.testMode?O.LoginWithEmailOTPTestMode:O.LoginWithEmailOTP,[{email:t,showUI:n,deviceCheckUI:o,overrides:s}]),m=this.request(l);return!o&&m&&m.on(qe.Retry,()=>{this.createIntermediaryEvent(qe.Retry,l.id)()}),!n&&m&&(m.on(Re.VerifyEmailOtp,h=>{this.createIntermediaryEvent(Re.VerifyEmailOtp,l.id)(h)}),m.on(Re.Cancel,()=>{this.createIntermediaryEvent(Re.Cancel,l.id)()})),m}loginWithCredential(e){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=W(this.sdk.testMode?O.LoginWithCredentialTestMode:O.LoginWithCredential,[t]);return this.request(n)}setAuthorizationToken(e){let t=W(O.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:n=!0}=e,o=W(this.sdk.testMode?O.UpdateEmailTestMode:O.UpdateEmail,[{email:t,showUI:n}]);return this.request(o)}},jr={};li(jr,{clear:()=>_o,getItem:()=>ye,iterate:()=>Ro,key:()=>wo,keys:()=>bo,length:()=>Io,removeItem:()=>Ot,setItem:()=>Ue});var nt;function Ee(e){return(...t)=>ae(this,null,function*(){return nt||(nt=yield H.configureStorage()),yield nt.ready(),nt[e](...t)})}var ye=Ee("getItem"),Ue=Ee("setItem"),Ot=Ee("removeItem"),_o=Ee("clear"),Io=Ee("length"),wo=Ee("key"),bo=Ee("keys"),Ro=Ee("iterate"),Ao=class extends Se{constructor(){super(...arguments),this.localForageKey="mc_active_wallet"}getIdToken(e){let t=W(this.sdk.testMode?O.GetIdTokenTestMode:O.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?O.GenerateIdTokenTestMode:O.GenerateIdToken,[e]);return this.request(t)}getInfo(){return ae(this,null,function*(){let e=yield ye(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}isLoggedIn(){let e=W(this.sdk.testMode?O.IsLoggedInTestMode:O.IsLoggedIn);return this.request(e)}logout(){Ot(this.localForageKey);let e=W(this.sdk.testMode?O.LogoutTestMode:O.Logout);return this.request(e)}requestInfoWithUI(e){let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?O.UserSettingsTestMode:O.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?O.RecoverAccountTestMode:O.RecoverAccount,[e]);return this.request(t)}getMetadata(){$e({method:"user.getMetadata()",removalVersions:De,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?O.GetMetadataTestMode:O.GetMetadata);return this.request(e)}updateEmail(e){$e({method:"user.updateEmail()",removalVersions:De,useInstead:"auth.updateEmailWithUI()"}).log();let{email:t,showUI:n=!0}=e,o=W(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 So(){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 Vr="STORE_KEY_PRIVATE_KEY",Rt="STORE_KEY_PUBLIC_JWK",qr="ECDSA",To="P-256",No={name:qr,namedCurve:To};function Mo(){return ae(this,null,function*(){let e=yield Oo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,n=yield ye(Vr);if(!n||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:So()},s={typ:"dpop+jwt",alg:"ES256",jwk:e},l={protected:Sr(JSON.stringify(s)),claims:Sr(JSON.stringify(o))},m=Co(`${l.protected}.${l.claims}`),h={name:qr,hash:{name:"SHA-256"}},v=Do(new Uint8Array(yield t.sign(h,n,m)));return`${l.protected}.${l.claims}.${v}`})}function Oo(){return ae(this,null,function*(){if(!Po()){console.info("webcrypto is not supported");return}return(yield ye(Rt))||(yield Lo()),ye(Rt)})}function Lo(){return ae(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(No,!1,["sign"]),n=yield e.exportKey("jwk",t.publicKey);yield Ue(Vr,t.privateKey),yield Ue(Rt,n)})}function Po(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Sr(e){return Kr($o(e))}function Co(e){return new TextEncoder().encode(e)}function Kr(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function $o(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function Do(e){let t="";return e.forEach(n=>{t+=String.fromCharCode(n)}),Kr(t)}var xo=class extends Se{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(),s=W(O.Login,[o]),l=this.request(s);l.on(Le.WalletSelected,h=>this.handleWalletSelected(Or(At({},h),{payloadId:s.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(W(O.ShowUI))}showAddress(){return this.request(W(O.ShowAddress))}showSendTokensUI(){return this.request(W(O.ShowSendTokensUI))}showOnRamp(){return this.request(W(O.ShowOnRamp))}showNFTs(){return this.request(W(O.ShowNFTs))}showBalances(){return this.request(W(O.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(O.SendGaslessTransaction,[e,t]))}getInfo(){return ae(this,null,function*(){$e({method:"wallet.getInfo()",removalVersions:De,useInstead:"user.getInfo()"}).log();let e=yield ye(this.localForageKey),t=W(O.GetInfo,[{walletType:e}]);return this.request(t)})}disconnect(){$e({method:"wallet.disconnect()",removalVersions:De,useInstead:"user.logout()"}).log(),Ot(this.localForageKey);let e=W(O.Disconnect);return this.request(e)}requestUserInfoWithUI(e){$e({method:"wallet.requestUserInfoWithUI()",removalVersions:De,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(O.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}getProvider(){return ae(this,null,function*(){switch(yield ye(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=W("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(Le.WalletConnected,e.payloadId)(t)}catch(t){console.error(t),this.createIntermediaryEvent(Le.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=W(O.AutoConnect,[{wallet:e,address:t}]);return this.request(n)})}},{createBoundEmitterMethod:it,createChainingEmitterMethod:Pe}=Wr(),Uo=class extends Se{constructor(){super(...arguments),this.isMagic=!0,this.on=Pe("on",this),this.once=Pe("once",this),this.addListener=Pe("addListener",this),this.off=Pe("off",this),this.removeListener=Pe("removeListener",this),this.removeAllListeners=Pe("removeAllListeners",this),this.emit=it("emit"),this.eventNames=it("eventNames"),this.listeners=it("listeners"),this.listenerCount=it("listenerCount")}sendAsync(e,t){if(!t)throw co({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(be.MAGIC_HANDLE_REQUEST,e.map(n=>{let o=st(n);return this.prefixPayloadMethodForTestMode(o),o})).then(n=>{t(null,n.map(o=>Or(At({},o.payload),{error:o.hasError?new xe(o.payload.error):null})))});else{let n=st(e);this.prefixPayloadMethodForTestMode(n),this.overlay.post(be.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=W(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let n=uo();return n.log(),new Tt(e).applyError({code:-32603,message:n.rawMessage}).payload}enable(){let e=W(O.Login);return this.request(e)}request(e){return this.prefixPayloadMethodForTestMode(e),super.request(e)}prefixPayloadMethodForTestMode(e){let t="testMode/eth/";this.sdk.testMode&&(e.method=`${t}${e.method}`)}},Tr=["request","overlay","sdk"];function ko(e){let t=Object.getPrototypeOf(e),n=[t];for(;t!==Se.prototype;)t=Object.getPrototypeOf(t),n.push(t);return n}var Yr=class extends Se{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:Mt,isPromiEvent:Nt,encodeJSON:Pr,decodeJSON:eo,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:st,storage:jr};let e=[this,...ko(this)];Tr.forEach(t=>{let n=e.map(m=>Object.getOwnPropertyDescriptor(m,t)),o=n.findIndex(m=>!!m),s=o>0,l=n[o];l&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:l,isPrototypeField:s}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw so(t)}}))})}init(e){this.__is_initialized__||(Tr.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,s=o?` Use \`${o}\` instead.`:"",l=`\`${t}\` will be removed from this Extension in version \`${n}\`.${s}`;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 Yr{},Ae=class extends Yr{};Ae.Internal=Bo,Ae.Anonymous="anonymous extension";var Wo=class extends Se{purchase(e){let t=W(O.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(O.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(O.NFTTransfer,[e]);return this.request(t)}};function Nr(e){return e.compat&&e.compat[H.sdkName]!=null?typeof e.compat[H.sdkName]=="string"?qi(Xi(H.version),e.compat[H.sdkName]):!!e.compat[H.sdkName]:!0}function Fo(e){var t;let n=(t=e==null?void 0:e.extensions)!=null?t:[],o={},s=[];if(Array.isArray(n)?n.forEach(l=>{Nr(l)?(l.init(this),(l.name||l.name!==Ae.Anonymous)&&(this[l.name]=l),l instanceof Ae.Internal&&(bt(l.config)||(o[l.name]=l.config))):s.push(l)}):Object.keys(n).forEach(l=>{if(Nr(n[l])){n[l].init(this);let m=n[l];this[l]=m,m instanceof Ae.Internal&&(bt(m.config)||(o[n[l].name]=m.config))}else s.push(n[l])}),s.length)throw lo(s);return o}var ot=class{constructor(e,t){this.apiKey=e;var n;if(!e)throw oo();H.platform==="react-native"&&(t==null?void 0:t.endpoint)&&fo().log();let{defaultEndpoint:o,version:s}=H;this.testMode=!!(t!=null&&t.testMode),this.endpoint=ze((n=t==null?void 0:t.endpoint)!=null?n:o).origin,this.auth=new Eo(this),this.user=new Ao(this),this.wallet=new xo(this),this.nft=new Wo(this),this.rpcProvider=new Uo(this);let l=Fo.call(this,t);this.parameters=Pr(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:io[H.sdkName],version:s,ext:bt(l)?void 0:l,locale:(t==null?void 0:t.locale)||"en_US"},H.bundleId?{bundleId:H.bundleId}:{})),t!=null&&t.deferPreload||this.preload()}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})}},Lt=ot;Lt.__overlays__=new Map;function Go(e,t){return t&&Array.isArray(e)?e.find(n=>n.id===t):e}function jo(e,t){var n;let o=(n=t.data.response)==null?void 0:n.id,s=Go(e,o);if(o&&s){let l=new Tt(s).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:l}}return{}}function Vo(e,t){return ae(this,null,function*(){let n=yield ye("rt"),o;if(H.platform==="web")try{o=yield Mo()}catch(s){console.error("webcrypto error",s)}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 Hr=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 Gr(n=>ae(this,null,function*(){yield this.ready;let o=[],s=Array.isArray(t)?t.map(v=>v.id):[],l=yield Vo(`${e}-${this.parameters}`,t);yield this._post(l);let m=v=>g=>{let{id:y,response:T}=jo(t,g);qo(g),y&&T&&Array.isArray(t)&&s.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(he.MAGIC_HANDLE_RESPONSE,m(()=>h()))}))})}on(e,t){let n=t.bind(window),o=s=>{s.data.msgType===`${e}-${this.parameters}`&&n(s)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{this.on(he.MAGIC_OVERLAY_READY,()=>e())})}listen(){this.on(he.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(he.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()})}};var Pt={};or(Pt,{DeepLinkPage:()=>lr,DeviceVerificationEventEmit:()=>qe,DeviceVerificationEventOnReceived:()=>dr,EthChainType:()=>hr,Events:()=>Le,Extension:()=>Ae,ExtensionError:()=>ct,ExtensionWarning:()=>at,LoginWithEmailOTPEventEmit:()=>Re,LoginWithEmailOTPEventOnReceived:()=>fr,LoginWithMagicLinkEventEmit:()=>cr,LoginWithMagicLinkEventOnReceived:()=>ur,MagicIncomingWindowMessage:()=>he,MagicOutgoingWindowMessage:()=>be,MagicPayloadMethod:()=>O,RPCError:()=>xe,RPCErrorCode:()=>Oe,RecoveryMethodType:()=>pr,SDKError:()=>pe,SDKErrorCode:()=>de,SDKWarning:()=>Be,SDKWarningCode:()=>we,Wallets:()=>ce,isPromiEvent:()=>Nt});var dt=sr(zr()),$t=sr(Qr());var Ko={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function Yo(e){for(let[t,n]of Object.entries(Ko))e.style[t]=n}function Ho(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(n=>n.src.includes(e)))}var ft=class extends Hr{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(n=>{let o=()=>{if(Ho(encodeURIComponent(this.parameters)))xr().log();else{let s=document.createElement("iframe");s.classList.add("magic-iframe"),s.dataset.magicIframeLabel=ze(this.endpoint).host,s.title="Secure Modal",s.src=ze(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,Yo(s),document.body.appendChild(s),n(s)}};["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 s of this.messageHandlers.values())s(n)}})}showOverlay(){return Me(this,null,function*(){let n=yield this.iframe;n.style.display="block",this.activeElement=document.activeElement,n.focus()})}hideOverlay(){return Me(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 Me(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(n,this.endpoint);else throw Dr()})}};var Xo=Object.assign($r(Lt,{platform:"web",sdkName:"magic-sdk",version:"21.0.0",defaultEndpoint:"https://auth.magic.link/",ViewController:ft,configureStorage:()=>Me(void 0,null,function*(){let e=dt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver($t),yield e.setDriver([dt.default.INDEXEDDB,dt.default.LOCALSTORAGE,$t._driver]),e})}),nr({},Pt)),zo=Xo;return Zn(Jo);})();
|
6
6
|
if (Magic && Magic.default != null) { Magic = Object.assign(Magic.default, Magic); delete Magic.default; }
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "magic-sdk",
|
3
|
-
"version": "21.0.0",
|
3
|
+
"version": "21.1.0-canary.643.6567644654.0",
|
4
4
|
"description": "Passwordless authentication for the web.",
|
5
5
|
"author": "Magic Labs <team@magic.link> (https://magic.link/)",
|
6
6
|
"license": "MIT",
|
@@ -29,9 +29,9 @@
|
|
29
29
|
]
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@magic-sdk/commons": "
|
33
|
-
"@magic-sdk/provider": "
|
34
|
-
"@magic-sdk/types": "
|
32
|
+
"@magic-sdk/commons": "17.1.0-canary.643.6567644654.0",
|
33
|
+
"@magic-sdk/provider": "21.1.0-canary.643.6567644654.0",
|
34
|
+
"@magic-sdk/types": "17.1.0-canary.643.6567644654.0",
|
35
35
|
"localforage": "^1.7.4"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
@@ -40,5 +40,5 @@
|
|
40
40
|
"@babel/runtime": "^7.9.6",
|
41
41
|
"localforage-driver-memory": "^1.0.5"
|
42
42
|
},
|
43
|
-
"gitHead": "
|
43
|
+
"gitHead": "8001468a1ad1cd0b7b1d5208432f153b4895b36c"
|
44
44
|
}
|