magic-sdk 28.0.4-canary.742.9142617582.0 → 28.0.4-canary.742.9144545513.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 \`${r.name}\` supports version(s) \`${o}\``:o||(t+=`
|
3
3
|
- Extension \`${r.name}\` does not support ${Y.platform} environments.`)}),new ye(me.IncompatibleExtensions,t)}function wo(e){let t=r=>{let o=r+1,a=o%10,s=o%100;return a===1&&s!==11?`${o}st`:a===2&&s!==12?`${o}nd`:a===3&&s!==13?`${o}rd`:`${o}th`};return new ye(me.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
4
4
|
Expected: \`${e.expected}\`
|
5
|
-
Received: \`${e.received}\``)}function qr(){return new Le(pe.DuplicateIframe,"Duplicate iframes found.")}function bo(){return new Le(pe.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 Ro(){return new Le(pe.ReactNativeEndpointConfiguration,`CUSTOM DOMAINS ARE NOT SUPPORTED WHEN USING MAGIC SDK WITH REACT NATIVE! The \`endpoint\` parameter SHOULD NOT be provided. The Magic \`<iframe>\` is automatically wrapped by a WebView pointed at \`${Y.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function Ye(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],s=o?` Use \`${o}\` instead.`:"",h=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${s}`;return new Le(pe.DeprecationNotice,h)}function*So(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Ao=So();function Kr(){return Ao.next().value}var Hr=Symbol("Payload pre-processed by Magic SDK");function Yr(e){return Object.defineProperty(e,Hr,{value:!0,enumerable:!1}),e}function No(e){return!!e[Hr]}function lt(e){var t,r,o;return No(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Kr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Yr(e)),e}function B(e,t=[]){return Yr({params:t,method:e,jsonrpc:"2.0",id:Kr()})}var Mt=class{constructor(e){e instanceof Mt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):po(e)?(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=e.result,this._error=e.error):(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=void 0,this._error=void 0)}applyError(e){return this._error=e,this}applyResult(e){return this._result=e,this}get hasError(){return typeof this._error!="undefined"&&this._error!==null}get hasResult(){return typeof this._result!="undefined"}get payload(){return{jsonrpc:this._jsonrpc,id:this._id,result:this._result,error:this._error}}},Oo=wi(bi()),To=class extends Oo.default{};function Xr(){let e=new To;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var zr=Symbol("isPromiEvent");function Ct(e){return!!e[zr]}function he(e){let t=Jr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=Xr(),a=Symbol("Promise.then"),s=Symbol("Promise.catch"),h=Symbol("Promise.finally"),m=(y,O)=>(..._)=>{let N=O[y].apply(O,_);return g(N)},g=y=>Object.assign(y,{[zr]:!0,[a]:y[a]||y.then,[s]:y[s]||y.catch,[h]:y[h]||y.finally,then:m(a,y),catch:m(s,y),finally:m(h,y),on:o("on",y),once:o("once",y),addListener:o("addListener",y),off:o("off",y),removeListener:o("removeListener",y),removeAllListeners:o("removeAllListeners",y),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),v=g(t.then(y=>(v.emit("done",y),v.emit("settled"),y),y=>{throw v.emit("error",y),v.emit("settled"),y}));return v}function Jr(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var be=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){if(this.sdk.thirdPartyWallet.isConnected&&e.method!==T.IntermediaryEvent&&e.method!==T.NFTCheckout&&e.method!==T.Login)return he((a,s)=>{this.sdk.thirdPartyWallet.requestOverride(e).then(a).catch(s)});let t=this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,lt(e)),r=he((a,s)=>{t.then(h=>{if(o(),h.hasError)s(new Ue(h.payload.error));else if(h.hasResult)a(h.payload.result);else throw Eo()}).catch(h=>{o(),s(h)})}),o=this.overlay.on(de.MAGIC_HANDLE_EVENT,a=>{var s;let{response:h}=a.data;if(h.id===e.id&&((s=h.result)==null?void 0:s.event)){let{event:m,params:g=[]}=h.result;r.emit(m,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=B(T.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Lo(e,t){let[r]=e.split(".").map(Number);return r>=t}var Xe={"magic-sdk":"v18.0.0","@magic-sdk/react-native":"v14.0.0","@magic-sdk/react-native-bare":"v19.0.0","@magic-sdk/react-native-expo":"v19.0.0"},Mo=class extends be{loginWithMagicLink(e){let t=Y.sdkName==="@magic-sdk/react-native"||Y.sdkName==="@magic-sdk/react-native-bare"||Y.sdkName==="@magic-sdk/react-native-expo";if(t&&Lo(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&Ye({method:"auth.loginWithMagicLink()",removalVersions:Xe,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:s}=e,h=B(this.sdk.testMode?T.LoginWithMagicLinkTestMode:T.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s}]);return this.request(h)}loginWithSMS(e){let{phoneNumber:t}=e,r=B(this.sdk.testMode?T.LoginWithSmsTestMode:T.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,s=B(this.sdk.testMode?T.LoginWithEmailOTPTestMode:T.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),h=this.request(s);return!o&&h&&h.on(Ve.Retry,()=>{this.createIntermediaryEvent(Ve.Retry,s.id)()}),!r&&h&&(h.on(Oe.VerifyEmailOtp,m=>{this.createIntermediaryEvent(Oe.VerifyEmailOtp,s.id)(m)}),h.on(Oe.Cancel,()=>{this.createIntermediaryEvent(Oe.Cancel,s.id)()})),h}loginWithCredential(e){let t=e!=null?e:"";if(!e&&Y.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let r=B(this.sdk.testMode?T.LoginWithCredentialTestMode:T.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=B(T.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=B(this.sdk.testMode?T.UpdateEmailTestMode:T.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(ve.Retry,()=>{this.createIntermediaryEvent(ve.Retry,o.id)()}),a.on(ve.Cancel,()=>{this.createIntermediaryEvent(ve.Cancel,o.id)()}),a.on(ve.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ve.VerifyEmailOtp,o.id)(s)}),a.on(ge.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ge.RetryWithNewEmail,o.id)(s)}),a.on(ge.Cancel,()=>{this.createIntermediaryEvent(ge.Cancel,o.id)()}),a.on(ge.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ge.VerifyEmailOtp,o.id)(s)})),a}},Qr={};_i(Qr,{clear:()=>Co,getItem:()=>ue,iterate:()=>Zr,key:()=>Po,keys:()=>Do,length:()=>$o,removeItem:()=>ut,setItem:()=>we});var it;function Re(e){return(...t)=>Z(this,null,function*(){return it||(it=yield Y.configureStorage()),yield it.ready(),it[e](...t)})}var ue=Re("getItem"),we=Re("setItem"),ut=Re("removeItem"),Co=Re("clear"),$o=Re("length"),Po=Re("key"),Do=Re("keys"),Zr=Re("iterate");function xo(){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 en="STORE_KEY_PRIVATE_KEY",Nt="STORE_KEY_PUBLIC_JWK",tn="ECDSA",Uo="P-256",ko={name:tn,namedCurve:Uo};function ht(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Fo(){return Z(this,null,function*(){let e=yield Bo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield ue(en);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:xo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:xr(JSON.stringify(a)),claims:xr(JSON.stringify(o))},h=Go(`${s.protected}.${s.claims}`),m={name:tn,hash:{name:"SHA-256"}},g=Vo(new Uint8Array(yield t.sign(m,r,h)));return`${s.protected}.${s.claims}.${g}`})}function Bo(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}return(yield ue(Nt))||(yield Wo()),ue(Nt)})}function Wo(){return Z(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(ko,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield we(en,t.privateKey),yield we(Nt,r)})}function xr(e){return rn(jo(e))}function Go(e){return new TextEncoder().encode(e)}function rn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function jo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Vo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),rn(t)}var $t="ds",Pt="ek",Dt="iv",xt="AES-GCM",qo=256;function Ut(){return Z(this,null,function*(){let e=[];yield Zr((t,r,o)=>{r.startsWith(`${$t}_`)&&e.push(r)});for(let t of e)yield ut(t)})}function nn(e){let t="",r=new Uint8Array(e),o=r.byteLength;for(let a=0;a<o;a++)t+=String.fromCharCode(r[a]);return window.btoa(t)}function on(e){let t=window.atob(e),r=t.length,o=new Uint8Array(r);for(let a=0;a<r;a++)o[a]=t.charCodeAt(a);return o.buffer}function Ko(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield ue(Dt))||e.getRandomValues(new Uint8Array(12))})}function Ho(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield ue(Pt))||(yield e.generateKey({name:xt,length:qo},!1,["encrypt","decrypt"]))})}function Yo(e,t){return Z(this,null,function*(){let r=yield Ko(),o=yield Ho();if(!r||!o||!e)return;let a=on(e),{subtle:s}=window.crypto,h=yield s.encrypt({name:xt,iv:r},o,a),m=nn(h);yield we(`${$t}_${t}`,m),yield we(Pt,o),yield we(Dt,r)})}function Xo(e){return Z(this,null,function*(){let t=yield ue(`${$t}_${e}`),r=yield ue(Dt),o=yield ue(Pt);if(!r||!t||!o||!ht())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:xt,iv:r},o,on(t));return nn(s)})}function Je(e,t){return t?new URL(e,t):new URL(e)}var zo=class extends be{constructor(){super(...arguments),this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=B(this.sdk.testMode?T.GetIdTokenTestMode:T.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=B(this.sdk.testMode?T.GenerateIdTokenTestMode:T.GenerateIdToken,[e]);return this.request(t)}getInfo(){let e=B(T.GetInfo,[]);return this.request(e)}isLoggedIn(){return he((e,t)=>Z(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield ue(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=B(this.sdk.testMode?T.IsLoggedInTestMode:T.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?we(this.localForageIsLoggedInKey,!0):ut(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return ut(this.localForageIsLoggedInKey),Ut(),he((e,t)=>Z(this,null,function*(){try{let r=B(this.sdk.testMode?T.LogoutTestMode:T.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=B(T.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=B(this.sdk.testMode?T.UserSettingsTestMode:T.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=B(this.sdk.testMode?T.RecoverAccountTestMode:T.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=B(T.RevealPK);return this.request(e)}getMetadata(){Ye({method:"user.getMetadata()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?T.GetMetadataTestMode:T.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Jo=class extends be{connectWithUI(e){let t=he((r,o)=>Z(this,null,function*(){try{let a=B(T.Login,[Ot({enabledWallets:this.sdk.thirdPartyWallet.enabledWallets},e)]),s=this.request(a);this.sdk.thirdPartyWallet.eventListeners.forEach(({event:m,callback:g})=>{s.on(m,()=>g(a.id))}),s.on("id-token-created",m=>{t.emit("id-token-created",m)});let h=yield s;h.error&&o(h),r(h)}catch(a){o(a)}}));return t}showUI(){return this.request(B(T.ShowUI))}showAddress(){return this.request(B(T.ShowAddress))}showSendTokensUI(){return this.request(B(T.ShowSendTokensUI))}showOnRamp(){return this.request(B(T.ShowOnRamp))}showNFTs(){return this.request(B(T.ShowNFTs))}showBalances(){return this.request(B(T.ShowBalances))}sendGaslessTransaction(e,t){return this.request(B(T.SendGaslessTransaction,[e,t]))}getInfo(){return Z(this,null,function*(){Ye({method:"wallet.getInfo()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=B(T.GetInfo,[]);return this.request(e)})}disconnect(){Ye({method:"wallet.disconnect()",removalVersions:Xe,useInstead:"user.logout()"}).log(),Ut();let e=B(T.Disconnect);return this.request(e)}requestUserInfoWithUI(e){Ye({method:"wallet.requestUserInfoWithUI()",removalVersions:Xe,useInstead:"user.requestUserInfoWithUI()"}).log();let t=B(T.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}},Qo=class extends be{constructor(){super(...arguments),this.eventListeners=[],this.enabledWallets={},this.isConnected=!1}resetState(){localStorage.removeItem("3pw_provider"),localStorage.removeItem("3pw_address"),localStorage.removeItem("3pw_chainId"),this.isConnected=!1}requestOverride(e){if(e.method===T.Login)return this.resetState(),super.request(e);if(e.method===T.GetInfo)return this.getInfo(e);if(e.method===T.IsLoggedIn)return this.isLoggedIn(e);if(e.method===T.Logout)return this.logout(e);switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalRequest(e);default:return this.resetState(),super.request(e)}}isLoggedIn(e){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalIsLoggedIn();default:return this.resetState(),super.request(e)}}getInfo(e){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalGetInfo();default:return this.resetState(),super.request(e)}}logout(e){let t=localStorage.getItem("3pw_provider");switch(this.resetState(),t){case"web3modal":return this.web3modalLogout();default:return super.request(e)}}web3modalRequest(e){return he((t,r)=>{this.sdk.web3modal.modal.getWalletProvider().request(e).then(t).catch(r)})}web3modalIsLoggedIn(){return he(e=>{setTimeout(()=>{let t=this.sdk.web3modal.modal.getIsConnected();e(t)},50)})}web3modalGetInfo(){return he(e=>{var t;let r=(t=this.sdk.web3modal.modal.getWalletInfo())==null?void 0:t.name,o=this.sdk.web3modal.modal.getAddress();e({publicAddress:o,email:null,issuer:`$did:ethr:${o}`,phoneNumber:null,isMfaEnabled:!1,recoveryFactors:[],walletType:r})})}web3modalLogout(){return he(e=>Z(this,null,function*(){var t;try{yield(t=this.sdk.web3modal.modal)==null?void 0:t.disconnect()}catch(r){console.error(r)}e(!0)}))}},{createBoundEmitterMethod:ot,createChainingEmitterMethod:De}=Xr(),Zo=class extends be{constructor(){super(...arguments),this.isMagic=!0,this.on=De("on",this),this.once=De("once",this),this.addListener=De("addListener",this),this.off=De("off",this),this.removeListener=De("removeListener",this),this.removeAllListeners=De("removeAllListeners",this),this.emit=ot("emit"),this.eventNames=ot("eventNames"),this.listeners=ot("listeners"),this.listenerCount=ot("listenerCount")}sendAsync(e,t){if(!t)throw wo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,e.map(r=>{let o=lt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>Br(Ot({},o.payload),{error:o.hasError?new Ue(o.payload.error):null})))});else{let r=lt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Ue(o.payload.error):null,o.payload)})}}send(e,t){if(typeof e=="string"){let o=B(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=bo();return r.log(),new Mt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=B(T.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}`)}},Ur=["request","overlay","sdk"];function ea(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==be.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var an=class extends be{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:he,isPromiEvent:Ct,encodeJSON:Gr,decodeJSON:ho,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:lt,storage:Qr};let e=[this,...ea(this)];Ur.forEach(t=>{let r=e.map(h=>Object.getOwnPropertyDescriptor(h,t)),o=r.findIndex(h=>!!h),a=o>0,s=r[o];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw _o(t)}}))})}init(e){this.__is_initialized__||(Ur.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new ct(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new ct(this,e,t)}createError(e,t,r){return new dt(this,e,t,r)}},ta=class extends an{},Te=class extends an{};Te.Internal=ta,Te.Anonymous="anonymous extension";var ra=class extends be{purchase(e){let t=B(T.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=B(T.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=B(T.NFTTransfer,[e]);return this.request(t)}};function kr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?no(so(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function na(e,t,r){return!t&&!r?`${e}_eth_mainnet`:r?`${e}_${JSON.stringify(r)}`:t?typeof t=="string"?`${e}_eth_${t}`:`${e}_${t.rpcUrl}_${t.chainId}_${t.chainType}`:`${e}_unknown`}function ia(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(s=>{kr(s)?(s.init(this),(s.name||s.name!==Te.Anonymous)&&(this[s.name]=s),s instanceof Te.Internal&&(st(s.config)||(o[s.name]=s.config))):a.push(s)}):Object.keys(r).forEach(s=>{if(kr(r[s])){r[s].init(this);let h=r[s];this[s]=h,h instanceof Te.Internal&&(st(h.config)||(o[r[s].name]=h.config))}else a.push(r[s])}),a.length)throw Io(a);return o}var at=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw yo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Ro().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=Je((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new Mo(this),this.user=new zo(this),this.wallet=new Jo(this),this.nft=new ra(this),this.thirdPartyWallet=new Qo(this),this.rpcProvider=new Zo(this);let s=ia.call(this,t);this.parameters=Gr(Br(Ot({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:Je(this.endpoint).host,sdk:go[Y.sdkName],version:a,ext:st(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=na(this.apiKey,t==null?void 0:t.network,st(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!at.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),at.__overlays__.set(this.parameters,e)}return at.__overlays__.get(this.parameters)}preload(){return Z(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},kt=at;kt.__overlays__=new Map;function oa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function aa(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=oa(e,o);if(o&&a){let s=new Mt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function sa(e,t,r){return Z(this,null,function*(){var o;let a=yield ue("rt"),s;if(Y.platform==="web")try{s=(o=yield ue("jwt"))!=null?o:yield Fo()}catch(g){console.error("webcrypto error",g)}let h={msgType:e,payload:t};s&&(h.jwt=s),s&&a&&(h.rt=a);let m=yield Xo(r);return m&&(h.deviceShare=m),h})}function ca(e){return Z(this,null,function*(){!e.data.rt||(yield we("rt",e.data.rt))})}var sn=class{constructor(e,t,r){this.endpoint=e,this.parameters=t,this.networkHash=r,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return Z(this,null,function*(){return Jr((r,o)=>Z(this,null,function*(){if(!this.isConnectedToInternet){let v=Lt();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],h=yield sa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(h);let m=v=>y=>{var O;let{id:_,response:N}=aa(t,y);if(ca(y),((O=N==null?void 0:N.payload.error)==null?void 0:O.message)==="User denied account access.")Ut();else if(y.data.deviceShare){let{deviceShare:M}=y.data;Yo(M,this.networkHash)}_&&N&&Array.isArray(t)&&s.includes(_)?(a.push(N),a.length===t.length&&(v(),r(a))):_&&N&&!Array.isArray(t)&&_===t.id&&(v(),r(N))},g=this.on(de.MAGIC_HANDLE_RESPONSE,m(()=>g()))}))})}on(e,t){let r=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&r(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{let t=this.on(de.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(de.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(de.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(de.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Le(pe.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Ft={};dr(Ft,{DeepLinkPage:()=>vr,DeviceVerificationEventEmit:()=>Ve,DeviceVerificationEventOnReceived:()=>_r,EthChainType:()=>br,Extension:()=>Te,ExtensionError:()=>dt,ExtensionWarning:()=>ct,LoginWithEmailOTPEventEmit:()=>Oe,LoginWithEmailOTPEventOnReceived:()=>Er,LoginWithMagicLinkEventEmit:()=>gr,LoginWithMagicLinkEventOnReceived:()=>yr,MagicIncomingWindowMessage:()=>de,MagicOutgoingWindowMessage:()=>Ne,MagicPayloadMethod:()=>T,RPCError:()=>Ue,RPCErrorCode:()=>Pe,RecencyCheckEventEmit:()=>ve,RecencyCheckEventOnReceived:()=>Ir,RecoveryMethodType:()=>Rr,SDKError:()=>ye,SDKErrorCode:()=>me,SDKWarning:()=>Le,SDKWarningCode:()=>pe,ThirdPartyWalletEvents:()=>pr,UpdateEmailEventEmit:()=>ge,UpdateEmailEventOnReceived:()=>wr,isPromiEvent:()=>Ct});var vt=mr(ln()),Wt=mr(fn());var la={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function ua(e){for(let[t,r]of Object.entries(la))e.style[t]=r}function fa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var pt=class extends sn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(fa(encodeURIComponent(this.parameters)))qr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=Je(this.endpoint).host,a.title="Secure Modal",a.src=Je(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,a.allow="identity-credentials-get; clipboard-read; clipboard-write",ua(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(o=r.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(r)}})}showOverlay(){return $e(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return $e(this,null,function*(){var o;let r=yield this.iframe;r.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return $e(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Lt()})}};var da=Object.assign(Vr(kt,{platform:"web",sdkName:"magic-sdk",version:"28.0.3",defaultEndpoint:"https://auth.magic.link/",ViewController:pt,configureStorage:()=>$e(void 0,null,function*(){let e=vt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Wt),yield e.setDriver([vt.default.INDEXEDDB,vt.default.LOCALSTORAGE,Wt._driver]),e})}),ur({},Ft)),ha=da;return fi(ma);})();
|
5
|
+
Received: \`${e.received}\``)}function qr(){return new Le(pe.DuplicateIframe,"Duplicate iframes found.")}function bo(){return new Le(pe.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 Ro(){return new Le(pe.ReactNativeEndpointConfiguration,`CUSTOM DOMAINS ARE NOT SUPPORTED WHEN USING MAGIC SDK WITH REACT NATIVE! The \`endpoint\` parameter SHOULD NOT be provided. The Magic \`<iframe>\` is automatically wrapped by a WebView pointed at \`${Y.defaultEndpoint}\`. Changing this default behavior will lead to unexpected results and potentially security-threatening bugs.`)}function Ye(e){let{method:t,removalVersions:r,useInstead:o}=e,a=r[Y.sdkName],s=o?` Use \`${o}\` instead.`:"",h=`\`${t}\` will be removed from \`${Y.sdkName}\` in version \`${a}\`.${s}`;return new Le(pe.DeprecationNotice,h)}function*So(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var Ao=So();function Kr(){return Ao.next().value}var Hr=Symbol("Payload pre-processed by Magic SDK");function Yr(e){return Object.defineProperty(e,Hr,{value:!0,enumerable:!1}),e}function No(e){return!!e[Hr]}function lt(e){var t,r,o;return No(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Kr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Yr(e)),e}function B(e,t=[]){return Yr({params:t,method:e,jsonrpc:"2.0",id:Kr()})}var Mt=class{constructor(e){e instanceof Mt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):po(e)?(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=e.result,this._error=e.error):(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=void 0,this._error=void 0)}applyError(e){return this._error=e,this}applyResult(e){return this._result=e,this}get hasError(){return typeof this._error!="undefined"&&this._error!==null}get hasResult(){return typeof this._result!="undefined"}get payload(){return{jsonrpc:this._jsonrpc,id:this._id,result:this._result,error:this._error}}},Oo=wi(bi()),To=class extends Oo.default{};function Xr(){let e=new To;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var zr=Symbol("isPromiEvent");function Ct(e){return!!e[zr]}function he(e){let t=Jr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=Xr(),a=Symbol("Promise.then"),s=Symbol("Promise.catch"),h=Symbol("Promise.finally"),m=(y,O)=>(..._)=>{let N=O[y].apply(O,_);return g(N)},g=y=>Object.assign(y,{[zr]:!0,[a]:y[a]||y.then,[s]:y[s]||y.catch,[h]:y[h]||y.finally,then:m(a,y),catch:m(s,y),finally:m(h,y),on:o("on",y),once:o("once",y),addListener:o("addListener",y),off:o("off",y),removeListener:o("removeListener",y),removeAllListeners:o("removeAllListeners",y),emit:r("emit"),eventNames:r("eventNames"),listeners:r("listeners"),listenerCount:r("listenerCount")}),v=g(t.then(y=>(v.emit("done",y),v.emit("settled"),y),y=>{throw v.emit("error",y),v.emit("settled"),y}));return v}function Jr(e){return new Promise((t,r)=>{let o=e(t,r);Promise.resolve(o).catch(r)})}var be=class{constructor(e){this.sdk=e}get overlay(){return this.sdk.overlay}request(e){if(this.sdk.thirdPartyWallet.isConnected&&e.method!==T.IntermediaryEvent&&e.method!==T.NFTCheckout&&e.method!==T.Login)return he((a,s)=>{this.sdk.thirdPartyWallet.requestOverride(e).then(a).catch(s)});let t=this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,lt(e)),r=he((a,s)=>{t.then(h=>{if(o(),h.hasError)s(new Ue(h.payload.error));else if(h.hasResult)a(h.payload.result);else throw Eo()}).catch(h=>{o(),s(h)})}),o=this.overlay.on(de.MAGIC_HANDLE_EVENT,a=>{var s;let{response:h}=a.data;if(h.id===e.id&&((s=h.result)==null?void 0:s.event)){let{event:m,params:g=[]}=h.result;r.emit(m,...g)}});return r}createIntermediaryEvent(e,t){return r=>{let o=B(T.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Lo(e,t){let[r]=e.split(".").map(Number);return r>=t}var Xe={"magic-sdk":"v18.0.0","@magic-sdk/react-native":"v14.0.0","@magic-sdk/react-native-bare":"v19.0.0","@magic-sdk/react-native-expo":"v19.0.0"},Mo=class extends be{loginWithMagicLink(e){let t=Y.sdkName==="@magic-sdk/react-native"||Y.sdkName==="@magic-sdk/react-native-bare"||Y.sdkName==="@magic-sdk/react-native-expo";if(t&&Lo(Y.version,19))throw new Error("loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.");t&&Ye({method:"auth.loginWithMagicLink()",removalVersions:Xe,useInstead:"auth.loginWithEmailOTP()"}).log();let{email:r,showUI:o=!0,redirectURI:a,overrides:s}=e,h=B(this.sdk.testMode?T.LoginWithMagicLinkTestMode:T.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s}]);return this.request(h)}loginWithSMS(e){let{phoneNumber:t}=e,r=B(this.sdk.testMode?T.LoginWithSmsTestMode:T.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,s=B(this.sdk.testMode?T.LoginWithEmailOTPTestMode:T.LoginWithEmailOTP,[{email:t,showUI:r,deviceCheckUI:o,overrides:a}]),h=this.request(s);return!o&&h&&h.on(Ve.Retry,()=>{this.createIntermediaryEvent(Ve.Retry,s.id)()}),!r&&h&&(h.on(Oe.VerifyEmailOtp,m=>{this.createIntermediaryEvent(Oe.VerifyEmailOtp,s.id)(m)}),h.on(Oe.Cancel,()=>{this.createIntermediaryEvent(Oe.Cancel,s.id)()})),h}loginWithCredential(e){let t=e!=null?e:"";if(!e&&Y.platform==="web"){t=window.location.search;let o=window.location.origin+window.location.pathname;window.history.replaceState(null,"",o)}let r=B(this.sdk.testMode?T.LoginWithCredentialTestMode:T.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=B(T.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=B(this.sdk.testMode?T.UpdateEmailTestMode:T.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(ve.Retry,()=>{this.createIntermediaryEvent(ve.Retry,o.id)()}),a.on(ve.Cancel,()=>{this.createIntermediaryEvent(ve.Cancel,o.id)()}),a.on(ve.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ve.VerifyEmailOtp,o.id)(s)}),a.on(ge.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ge.RetryWithNewEmail,o.id)(s)}),a.on(ge.Cancel,()=>{this.createIntermediaryEvent(ge.Cancel,o.id)()}),a.on(ge.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ge.VerifyEmailOtp,o.id)(s)})),a}},Qr={};_i(Qr,{clear:()=>Co,getItem:()=>ue,iterate:()=>Zr,key:()=>Po,keys:()=>Do,length:()=>$o,removeItem:()=>ut,setItem:()=>we});var it;function Re(e){return(...t)=>Z(this,null,function*(){return it||(it=yield Y.configureStorage()),yield it.ready(),it[e](...t)})}var ue=Re("getItem"),we=Re("setItem"),ut=Re("removeItem"),Co=Re("clear"),$o=Re("length"),Po=Re("key"),Do=Re("keys"),Zr=Re("iterate");function xo(){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 en="STORE_KEY_PRIVATE_KEY",Nt="STORE_KEY_PUBLIC_JWK",tn="ECDSA",Uo="P-256",ko={name:tn,namedCurve:Uo};function ht(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Fo(){return Z(this,null,function*(){let e=yield Bo();if(!e){console.info("unable to create public key or webcrypto is unsupported");return}let{subtle:t}=window.crypto,r=yield ue(en);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:xo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:xr(JSON.stringify(a)),claims:xr(JSON.stringify(o))},h=Go(`${s.protected}.${s.claims}`),m={name:tn,hash:{name:"SHA-256"}},g=Vo(new Uint8Array(yield t.sign(m,r,h)));return`${s.protected}.${s.claims}.${g}`})}function Bo(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}return(yield ue(Nt))||(yield Wo()),ue(Nt)})}function Wo(){return Z(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(ko,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield we(en,t.privateKey),yield we(Nt,r)})}function xr(e){return rn(jo(e))}function Go(e){return new TextEncoder().encode(e)}function rn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function jo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function Vo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),rn(t)}var $t="ds",Pt="ek",Dt="iv",xt="AES-GCM",qo=256;function Ut(){return Z(this,null,function*(){let e=[];yield Zr((t,r,o)=>{r.startsWith(`${$t}_`)&&e.push(r)});for(let t of e)yield ut(t)})}function nn(e){let t="",r=new Uint8Array(e),o=r.byteLength;for(let a=0;a<o;a++)t+=String.fromCharCode(r[a]);return window.btoa(t)}function on(e){let t=window.atob(e),r=t.length,o=new Uint8Array(r);for(let a=0;a<r;a++)o[a]=t.charCodeAt(a);return o.buffer}function Ko(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield ue(Dt))||e.getRandomValues(new Uint8Array(12))})}function Ho(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{subtle:e}=window.crypto;return(yield ue(Pt))||(yield e.generateKey({name:xt,length:qo},!1,["encrypt","decrypt"]))})}function Yo(e,t){return Z(this,null,function*(){let r=yield Ko(),o=yield Ho();if(!r||!o||!e)return;let a=on(e),{subtle:s}=window.crypto,h=yield s.encrypt({name:xt,iv:r},o,a),m=nn(h);yield we(`${$t}_${t}`,m),yield we(Pt,o),yield we(Dt,r)})}function Xo(e){return Z(this,null,function*(){let t=yield ue(`${$t}_${e}`),r=yield ue(Dt),o=yield ue(Pt);if(!r||!t||!o||!ht())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:xt,iv:r},o,on(t));return nn(s)})}function Je(e,t){return t?new URL(e,t):new URL(e)}var zo=class extends be{constructor(){super(...arguments),this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=B(this.sdk.testMode?T.GetIdTokenTestMode:T.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=B(this.sdk.testMode?T.GenerateIdTokenTestMode:T.GenerateIdToken,[e]);return this.request(t)}getInfo(){let e=B(T.GetInfo,[]);return this.request(e)}isLoggedIn(){return he((e,t)=>Z(this,null,function*(){try{let r=!1;this.sdk.useStorageCache&&(r=(yield ue(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=B(this.sdk.testMode?T.IsLoggedInTestMode:T.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?we(this.localForageIsLoggedInKey,!0):ut(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return ut(this.localForageIsLoggedInKey),Ut(),he((e,t)=>Z(this,null,function*(){try{let r=B(this.sdk.testMode?T.LogoutTestMode:T.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=B(T.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=B(this.sdk.testMode?T.UserSettingsTestMode:T.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=B(this.sdk.testMode?T.RecoverAccountTestMode:T.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=B(T.RevealPK);return this.request(e)}getMetadata(){Ye({method:"user.getMetadata()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=B(this.sdk.testMode?T.GetMetadataTestMode:T.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Jo=class extends be{connectWithUI(e){let t=he((r,o)=>Z(this,null,function*(){try{let a=B(T.Login,[Ot({enabledWallets:this.sdk.thirdPartyWallet.enabledWallets},e)]),s=this.request(a);this.sdk.thirdPartyWallet.eventListeners.forEach(({event:m,callback:g})=>{s.on(m,()=>g(a.id))}),s.on("id-token-created",m=>{t.emit("id-token-created",m)});let h=yield s;h.error&&o(h),r(h)}catch(a){o(a)}}));return t}showUI(){return this.request(B(T.ShowUI))}showAddress(){return this.request(B(T.ShowAddress))}showSendTokensUI(){return this.request(B(T.ShowSendTokensUI))}showOnRamp(){return this.request(B(T.ShowOnRamp))}showNFTs(){return this.request(B(T.ShowNFTs))}showBalances(){return this.request(B(T.ShowBalances))}sendGaslessTransaction(e,t){return this.request(B(T.SendGaslessTransaction,[e,t]))}getInfo(){Ye({method:"wallet.getInfo()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=B(T.GetInfo,[]);return this.request(e)}disconnect(){Ye({method:"wallet.disconnect()",removalVersions:Xe,useInstead:"user.logout()"}).log(),Ut();let e=B(T.Disconnect);return this.request(e)}requestUserInfoWithUI(e){Ye({method:"wallet.requestUserInfoWithUI()",removalVersions:Xe,useInstead:"user.requestUserInfoWithUI()"}).log();let t=B(T.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}},Qo=class extends be{constructor(){super(...arguments),this.eventListeners=[],this.enabledWallets={},this.isConnected=!1}resetState(){localStorage.removeItem("3pw_provider"),localStorage.removeItem("3pw_address"),localStorage.removeItem("3pw_chainId"),this.isConnected=!1}requestOverride(e){if(e.method===T.Login)return this.resetState(),super.request(e);if(e.method===T.GetInfo)return this.getInfo(e);if(e.method===T.IsLoggedIn)return this.isLoggedIn(e);if(e.method===T.Logout)return this.logout(e);switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalRequest(e);default:return this.resetState(),super.request(e)}}isLoggedIn(e){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalIsLoggedIn();default:return this.resetState(),super.request(e)}}getInfo(e){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalGetInfo();default:return this.resetState(),super.request(e)}}logout(e){let t=localStorage.getItem("3pw_provider");switch(this.resetState(),t){case"web3modal":return this.web3modalLogout();default:return super.request(e)}}web3modalRequest(e){return he((t,r)=>{this.sdk.web3modal.modal.getWalletProvider().request(e).then(t).catch(r)})}web3modalIsLoggedIn(){return he(e=>{setTimeout(()=>{let t=this.sdk.web3modal.modal.getIsConnected();e(t)},50)})}web3modalGetInfo(){return he(e=>{var t;let r=(t=this.sdk.web3modal.modal.getWalletInfo())==null?void 0:t.name,o=this.sdk.web3modal.modal.getAddress();e({publicAddress:o,email:null,issuer:`$did:ethr:${o}`,phoneNumber:null,isMfaEnabled:!1,recoveryFactors:[],walletType:r})})}web3modalLogout(){return he(e=>Z(this,null,function*(){try{yield this.sdk.web3modal.modal.disconnect()}catch(t){console.error(t)}e(!0)}))}},{createBoundEmitterMethod:ot,createChainingEmitterMethod:De}=Xr(),Zo=class extends be{constructor(){super(...arguments),this.isMagic=!0,this.on=De("on",this),this.once=De("once",this),this.addListener=De("addListener",this),this.off=De("off",this),this.removeListener=De("removeListener",this),this.removeAllListeners=De("removeAllListeners",this),this.emit=ot("emit"),this.eventNames=ot("eventNames"),this.listeners=ot("listeners"),this.listenerCount=ot("listenerCount")}sendAsync(e,t){if(!t)throw wo({procedure:"Magic.rpcProvider.sendAsync",argument:1,expected:"function",received:t===null?"null":typeof t});if(Array.isArray(e))this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,e.map(r=>{let o=lt(r);return this.prefixPayloadMethodForTestMode(o),o})).then(r=>{t(null,r.map(o=>Br(Ot({},o.payload),{error:o.hasError?new Ue(o.payload.error):null})))});else{let r=lt(e);this.prefixPayloadMethodForTestMode(r),this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,r).then(o=>{t(o.hasError?new Ue(o.payload.error):null,o.payload)})}}send(e,t){if(typeof e=="string"){let o=B(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=bo();return r.log(),new Mt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=B(T.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}`)}},Ur=["request","overlay","sdk"];function ea(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==be.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var an=class extends be{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:he,isPromiEvent:Ct,encodeJSON:Gr,decodeJSON:ho,createJsonRpcRequestPayload:B,standardizeJsonRpcRequestPayload:lt,storage:Qr};let e=[this,...ea(this)];Ur.forEach(t=>{let r=e.map(h=>Object.getOwnPropertyDescriptor(h,t)),o=r.findIndex(h=>!!h),a=o>0,s=r[o];s&&(this.__sdk_access_field_descriptors__.set(t,{descriptor:s,isPrototypeField:a}),Object.defineProperty(this,t,{configurable:!0,get:()=>{throw _o(t)}}))})}init(e){this.__is_initialized__||(Ur.forEach(t=>{if(this.__sdk_access_field_descriptors__.has(t)){let{descriptor:r,isPrototypeField:o}=this.__sdk_access_field_descriptors__.get(t);o?delete this[t]:Object.defineProperty(this,t,r)}}),this.sdk=e,this.__is_initialized__=!0)}createDeprecationWarning(e){let{method:t,removalVersion:r,useInstead:o}=e,a=o?` Use \`${o}\` instead.`:"",s=`\`${t}\` will be removed from this Extension in version \`${r}\`.${a}`;return new ct(this,"DEPRECATION_NOTICE",s)}createWarning(e,t){return new ct(this,e,t)}createError(e,t,r){return new dt(this,e,t,r)}},ta=class extends an{},Te=class extends an{};Te.Internal=ta,Te.Anonymous="anonymous extension";var ra=class extends be{purchase(e){let t=B(T.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=B(T.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=B(T.NFTTransfer,[e]);return this.request(t)}};function kr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?no(so(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function na(e,t,r){return!t&&!r?`${e}_eth_mainnet`:r?`${e}_${JSON.stringify(r)}`:t?typeof t=="string"?`${e}_eth_${t}`:`${e}_${t.rpcUrl}_${t.chainId}_${t.chainType}`:`${e}_unknown`}function ia(e){var t;let r=(t=e==null?void 0:e.extensions)!=null?t:[],o={},a=[];if(Array.isArray(r)?r.forEach(s=>{kr(s)?(s.init(this),(s.name||s.name!==Te.Anonymous)&&(this[s.name]=s),s instanceof Te.Internal&&(st(s.config)||(o[s.name]=s.config))):a.push(s)}):Object.keys(r).forEach(s=>{if(kr(r[s])){r[s].init(this);let h=r[s];this[s]=h,h instanceof Te.Internal&&(st(h.config)||(o[r[s].name]=h.config))}else a.push(r[s])}),a.length)throw Io(a);return o}var at=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw yo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&Ro().log();let{defaultEndpoint:o,version:a}=Y;this.testMode=!!(t!=null&&t.testMode),this.useStorageCache=!!(t!=null&&t.useStorageCache),this.endpoint=Je((r=t==null?void 0:t.endpoint)!=null?r:o).origin,this.auth=new Mo(this),this.user=new zo(this),this.wallet=new Jo(this),this.nft=new ra(this),this.thirdPartyWallet=new Qo(this),this.rpcProvider=new Zo(this);let s=ia.call(this,t);this.parameters=Gr(Br(Ot({API_KEY:this.apiKey,DOMAIN_ORIGIN:window.location?window.location.origin:"",ETH_NETWORK:t==null?void 0:t.network,host:Je(this.endpoint).host,sdk:go[Y.sdkName],version:a,ext:st(s)?void 0:s,locale:(t==null?void 0:t.locale)||"en_US"},Y.bundleId?{bundleId:Y.bundleId}:{}),{meta:t==null?void 0:t.meta})),this.networkHash=na(this.apiKey,t==null?void 0:t.network,st(s)?void 0:s),t!=null&&t.deferPreload||this.preload()}get overlay(){if(!at.__overlays__.has(this.parameters)){let e=new Y.ViewController(this.endpoint,this.parameters,this.networkHash);e.init(),at.__overlays__.set(this.parameters,e)}return at.__overlays__.get(this.parameters)}preload(){return Z(this,null,function*(){yield this.overlay.checkIsReadyForRequest})}},kt=at;kt.__overlays__=new Map;function oa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function aa(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=oa(e,o);if(o&&a){let s=new Mt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function sa(e,t,r){return Z(this,null,function*(){var o;let a=yield ue("rt"),s;if(Y.platform==="web")try{s=(o=yield ue("jwt"))!=null?o:yield Fo()}catch(g){console.error("webcrypto error",g)}let h={msgType:e,payload:t};s&&(h.jwt=s),s&&a&&(h.rt=a);let m=yield Xo(r);return m&&(h.deviceShare=m),h})}function ca(e){return Z(this,null,function*(){!e.data.rt||(yield we("rt",e.data.rt))})}var sn=class{constructor(e,t,r){this.endpoint=e,this.parameters=t,this.networkHash=r,this.messageHandlers=new Set,this.isConnectedToInternet=!0,this.checkIsReadyForRequest=this.waitForReady(),this.isReadyForRequest=!1,this.listen()}post(e,t){return Z(this,null,function*(){return Jr((r,o)=>Z(this,null,function*(){if(!this.isConnectedToInternet){let v=Lt();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],h=yield sa(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(h);let m=v=>y=>{var O;let{id:_,response:N}=aa(t,y);if(ca(y),((O=N==null?void 0:N.payload.error)==null?void 0:O.message)==="User denied account access.")Ut();else if(y.data.deviceShare){let{deviceShare:M}=y.data;Yo(M,this.networkHash)}_&&N&&Array.isArray(t)&&s.includes(_)?(a.push(N),a.length===t.length&&(v(),r(a))):_&&N&&!Array.isArray(t)&&_===t.id&&(v(),r(N))},g=this.on(de.MAGIC_HANDLE_RESPONSE,m(()=>g()))}))})}on(e,t){let r=t.bind(window),o=a=>{a.data.msgType===`${e}-${this.parameters}`&&r(a)};return this.messageHandlers.add(o),()=>this.messageHandlers.delete(o)}waitForReady(){return new Promise(e=>{let t=this.on(de.MAGIC_OVERLAY_READY,()=>{this.isReadyForRequest=!0,e(),t()})})}listen(){this.on(de.MAGIC_HIDE_OVERLAY,()=>{this.hideOverlay()}),this.on(de.MAGIC_SHOW_OVERLAY,()=>{this.showOverlay()}),this.on(de.MAGIC_SEND_PRODUCT_ANNOUNCEMENT,e=>{e.data.response.result.product_announcement&&new Le(pe.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var Ft={};dr(Ft,{DeepLinkPage:()=>vr,DeviceVerificationEventEmit:()=>Ve,DeviceVerificationEventOnReceived:()=>_r,EthChainType:()=>br,Extension:()=>Te,ExtensionError:()=>dt,ExtensionWarning:()=>ct,LoginWithEmailOTPEventEmit:()=>Oe,LoginWithEmailOTPEventOnReceived:()=>Er,LoginWithMagicLinkEventEmit:()=>gr,LoginWithMagicLinkEventOnReceived:()=>yr,MagicIncomingWindowMessage:()=>de,MagicOutgoingWindowMessage:()=>Ne,MagicPayloadMethod:()=>T,RPCError:()=>Ue,RPCErrorCode:()=>Pe,RecencyCheckEventEmit:()=>ve,RecencyCheckEventOnReceived:()=>Ir,RecoveryMethodType:()=>Rr,SDKError:()=>ye,SDKErrorCode:()=>me,SDKWarning:()=>Le,SDKWarningCode:()=>pe,ThirdPartyWalletEvents:()=>pr,UpdateEmailEventEmit:()=>ge,UpdateEmailEventOnReceived:()=>wr,isPromiEvent:()=>Ct});var vt=mr(ln()),Wt=mr(fn());var la={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function ua(e){for(let[t,r]of Object.entries(la))e.style[t]=r}function fa(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var pt=class extends sn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(fa(encodeURIComponent(this.parameters)))qr().log();else{let a=document.createElement("iframe");a.classList.add("magic-iframe"),a.dataset.magicIframeLabel=Je(this.endpoint).host,a.title="Secure Modal",a.src=Je(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,a.allow="identity-credentials-get; clipboard-read; clipboard-write",ua(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(o=r.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(r)}})}showOverlay(){return $e(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return $e(this,null,function*(){var o;let r=yield this.iframe;r.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return $e(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Lt()})}};var da=Object.assign(Vr(kt,{platform:"web",sdkName:"magic-sdk",version:"28.0.3",defaultEndpoint:"https://auth.magic.link/",ViewController:pt,configureStorage:()=>$e(void 0,null,function*(){let e=vt.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield e.defineDriver(Wt),yield e.setDriver([vt.default.INDEXEDDB,vt.default.LOCALSTORAGE,Wt._driver]),e})}),ur({},Ft)),ha=da;return fi(ma);})();
|
6
6
|
if (Magic && Magic.default != null) { Magic = Object.assign(Magic.default, Magic); delete Magic.default; }
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "magic-sdk",
|
3
|
-
"version": "28.0.4-canary.742.
|
3
|
+
"version": "28.0.4-canary.742.9144545513.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": "24.0.3-canary.742.
|
33
|
-
"@magic-sdk/provider": "28.0.3-canary.742.
|
34
|
-
"@magic-sdk/types": "24.0.2-canary.742.
|
32
|
+
"@magic-sdk/commons": "24.0.3-canary.742.9144545513.0",
|
33
|
+
"@magic-sdk/provider": "28.0.3-canary.742.9144545513.0",
|
34
|
+
"@magic-sdk/types": "24.0.2-canary.742.9144545513.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": "2b569334db876c4a162f053dff8ab1995d6ee21b"
|
44
44
|
}
|