magic-sdk 28.0.4-canary.742.8818388531.0 → 28.0.4-canary.742.8822704945.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 ge(he.IncompatibleExtensions,t)}function bo(e){let t=r=>{let o=r+1,a=o%10,s=o%100;return a===1&&s!==11?`${o}st`:a===2&&s!==12?`${o}nd`:a===3&&s!==13?`${o}rd`:`${o}th`};return new ge(he.InvalidArgument,`Invalid ${t(e.argument)} argument given to \`${e.procedure}\`.
|
4
4
|
Expected: \`${e.expected}\`
|
5
|
-
Received: \`${e.received}\``)}function Kr(){return new Le(me.DuplicateIframe,"Duplicate iframes found.")}function Ro(){return new Le(me.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 So(){return new Le(me.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(me.DeprecationNotice,h)}function*Ao(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var No=Ao();function Hr(){return No.next().value}var Yr=Symbol("Payload pre-processed by Magic SDK");function Xr(e){return Object.defineProperty(e,Yr,{value:!0,enumerable:!1}),e}function Oo(e){return!!e[Yr]}function lt(e){var t,r,o;return Oo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Hr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Xr(e)),e}function W(e,t=[]){return Xr({params:t,method:e,jsonrpc:"2.0",id:Hr()})}var Lt=class{constructor(e){e instanceof Lt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):vo(e)?(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=e.result,this._error=e.error):(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=void 0,this._error=void 0)}applyError(e){return this._error=e,this}applyResult(e){return this._result=e,this}get hasError(){return typeof this._error!="undefined"&&this._error!==null}get hasResult(){return typeof this._result!="undefined"}get payload(){return{jsonrpc:this._jsonrpc,id:this._id,result:this._result,error:this._error}}},To=bi(Ri()),Lo=class extends To.default{};function zr(){let e=new Lo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Jr=Symbol("isPromiEvent");function Mt(e){return!!e[Jr]}function we(e){let t=Qr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=zr(),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,{[Jr]:!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 Qr(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&&!Object.values(L).includes(e.method))return we((a,s)=>{this.sdk.thirdPartyWallet.requestOverride(e).then(a).catch(s)});let t=this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,lt(e)),r=we((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 _o()}).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=W(L.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Mo(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"},Co=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&&Mo(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=W(this.sdk.testMode?L.LoginWithMagicLinkTestMode:L.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s}]);return this.request(h)}loginWithSMS(e){let{phoneNumber:t}=e,r=W(this.sdk.testMode?L.LoginWithSmsTestMode:L.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,s=W(this.sdk.testMode?L.LoginWithEmailOTPTestMode:L.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=W(this.sdk.testMode?L.LoginWithCredentialTestMode:L.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(L.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=W(this.sdk.testMode?L.UpdateEmailTestMode:L.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(pe.Retry,()=>{this.createIntermediaryEvent(pe.Retry,o.id)()}),a.on(pe.Cancel,()=>{this.createIntermediaryEvent(pe.Cancel,o.id)()}),a.on(pe.VerifyEmailOtp,s=>{this.createIntermediaryEvent(pe.VerifyEmailOtp,o.id)(s)}),a.on(ve.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ve.RetryWithNewEmail,o.id)(s)}),a.on(ve.Cancel,()=>{this.createIntermediaryEvent(ve.Cancel,o.id)()}),a.on(ve.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ve.VerifyEmailOtp,o.id)(s)})),a}},Zr={};Ii(Zr,{clear:()=>Po,getItem:()=>ue,iterate:()=>en,key:()=>Do,keys:()=>xo,length:()=>$o,removeItem:()=>ut,setItem:()=>Ie});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"),Ie=Re("setItem"),ut=Re("removeItem"),Po=Re("clear"),$o=Re("length"),Do=Re("key"),xo=Re("keys"),en=Re("iterate");function Uo(){let e=window.crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&191|128;let t="";return t+=e[0].toString(16),t+=e[1].toString(16),t+=e[2].toString(16),t+=e[3].toString(16),t+="-",t+=e[4].toString(16),t+=e[5].toString(16),t+="-",t+=e[6].toString(16),t+=e[7].toString(16),t+="-",t+=e[8].toString(16),t+=e[9].toString(16),t+="-",t+=e[10].toString(16),t+=e[11].toString(16),t+=e[12].toString(16),t+=e[13].toString(16),t+=e[14].toString(16),t+=e[15].toString(16),t}var tn="STORE_KEY_PRIVATE_KEY",Nt="STORE_KEY_PUBLIC_JWK",rn="ECDSA",ko="P-256",Fo={name:rn,namedCurve:ko};function ht(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Wo(){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(tn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Uo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:xr(JSON.stringify(a)),claims:xr(JSON.stringify(o))},h=jo(`${s.protected}.${s.claims}`),m={name:rn,hash:{name:"SHA-256"}},g=qo(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 Go()),ue(Nt)})}function Go(){return Z(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Fo,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield Ie(tn,t.privateKey),yield Ie(Nt,r)})}function xr(e){return nn(Vo(e))}function jo(e){return new TextEncoder().encode(e)}function nn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Vo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function qo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),nn(t)}var Ct="ds",Pt="ek",$t="iv",Dt="AES-GCM",Ko=256;function xt(){return Z(this,null,function*(){let e=[];yield en((t,r,o)=>{r.startsWith(`${Ct}_`)&&e.push(r)});for(let t of e)yield ut(t)})}function on(e){let t="",r=new Uint8Array(e),o=r.byteLength;for(let a=0;a<o;a++)t+=String.fromCharCode(r[a]);return window.btoa(t)}function an(e){let t=window.atob(e),r=t.length,o=new Uint8Array(r);for(let a=0;a<r;a++)o[a]=t.charCodeAt(a);return o.buffer}function Ho(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield ue($t))||e.getRandomValues(new Uint8Array(12))})}function Yo(){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:Dt,length:Ko},!1,["encrypt","decrypt"]))})}function Xo(e,t){return Z(this,null,function*(){let r=yield Ho(),o=yield Yo();if(!r||!o||!e)return;let a=an(e),{subtle:s}=window.crypto,h=yield s.encrypt({name:Dt,iv:r},o,a),m=on(h);yield Ie(`${Ct}_${t}`,m),yield Ie(Pt,o),yield Ie($t,r)})}function zo(e){return Z(this,null,function*(){let t=yield ue(`${Ct}_${e}`),r=yield ue($t),o=yield ue(Pt);if(!r||!t||!o||!ht())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:Dt,iv:r},o,an(t));return on(s)})}function Je(e,t){return t?new URL(e,t):new URL(e)}var Jo=class extends be{constructor(){super(...arguments),this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=W(this.sdk.testMode?L.GetIdTokenTestMode:L.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?L.GenerateIdTokenTestMode:L.GenerateIdToken,[e]);return this.request(t)}getInfo(){if(this.sdk.thirdPartyWallet.isConnected)return this.sdk.thirdPartyWallet.getInfo();let e=W(L.GetInfo,[]);return this.request(e)}isLoggedIn(){return we((e,t)=>Z(this,null,function*(){try{if(this.sdk.thirdPartyWallet.isConnected){let s=yield this.sdk.thirdPartyWallet.isLoggedIn();e(s)}let r=!1;this.sdk.useStorageCache&&(r=(yield ue(this.localForageIsLoggedInKey))==="true",r&&e(!0));let o=W(this.sdk.testMode?L.IsLoggedInTestMode:L.IsLoggedIn),a=yield this.request(o);this.sdk.useStorageCache&&(a?Ie(this.localForageIsLoggedInKey,!0):ut(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){t(r)}}))}logout(){return ut(this.localForageIsLoggedInKey),xt(),we((e,t)=>Z(this,null,function*(){try{this.sdk.thirdPartyWallet.isConnected&&(yield this.sdk.thirdPartyWallet.logout(),e(!0));let r=W(this.sdk.testMode?L.LogoutTestMode:L.Logout),o=yield this.request(r);this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){t(r)}}))}requestInfoWithUI(e){let t=W(L.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?L.UserSettingsTestMode:L.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?L.RecoverAccountTestMode:L.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=W(L.RevealPK);return this.request(e)}getMetadata(){Ye({method:"user.getMetadata()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?L.GetMetadataTestMode:L.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Qo=class extends be{connectWithUI(){let e=we((t,r)=>Z(this,null,function*(){try{let o=W(L.Login,[this.sdk.thirdPartyWallet.enabledWallets]),a=this.request(o);this.sdk.thirdPartyWallet.eventListeners.forEach(({event:h,callback:m})=>{a.on(h,()=>m(o.id))}),a.on("id-token-created",h=>{e.emit("id-token-created",h)});let s=yield a;s.error&&r(s),t(s)}catch(o){r(o)}}));return e}showUI(){return this.request(W(L.ShowUI))}showAddress(){return this.request(W(L.ShowAddress))}showSendTokensUI(){return this.request(W(L.ShowSendTokensUI))}showOnRamp(){return this.request(W(L.ShowOnRamp))}showNFTs(){return this.request(W(L.ShowNFTs))}showBalances(){return this.request(W(L.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(L.SendGaslessTransaction,[e,t]))}getInfo(){return Z(this,null,function*(){Ye({method:"wallet.getInfo()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=W(L.GetInfo,[]);return this.request(e)})}disconnect(){Ye({method:"wallet.disconnect()",removalVersions:Xe,useInstead:"user.logout()"}).log(),xt();let e=W(L.Disconnect);return this.request(e)}requestUserInfoWithUI(e){Ye({method:"wallet.requestUserInfoWithUI()",removalVersions:Xe,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(L.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}},Zo=class extends be{constructor(){super(...arguments),this.eventListeners=[],this.enabledWallets={},this.isConnected=!!localStorage.getItem("3pw_address")}getInfo(){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalGetInfo();default:return null}}isLoggedIn(){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalIsLoggedIn();default:return null}}logout(){let e=localStorage.getItem("3pw_provider");switch(localStorage.removeItem("3pw_provider"),localStorage.removeItem("3pw_address"),localStorage.removeItem("3pw_chainId"),this.isConnected=!1,e){case"web3modal":return this.web3modalLogout();default:return!0}}requestOverride(e){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalRequest(e);default:return null}}web3modalGetInfo(){return we(e=>{let t=this.sdk.web3modal.modal.getWalletInfo().name,r=this.sdk.web3modal.modal.getAddress()||localStorage.getItem("3pw_address");e({publicAddress:r,email:null,issuer:`$did:ethr:${r}`,phoneNumber:null,isMfaEnabled:!1,recoveryFactors:[],walletType:t})})}web3modalIsLoggedIn(){return we(e=>{setTimeout(()=>{let t=this.sdk.web3modal.modal.getIsConnected();e(t)},50)})}web3modalRequest(e){return this.sdk.web3modal.modal.getWalletProvider().request(e)}web3modalLogout(){var e;return(e=this.sdk.web3modal.modal)==null?void 0:e.disconnect()}},{createBoundEmitterMethod:ot,createChainingEmitterMethod:De}=zr(),ea=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 bo({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(Wr({},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=W(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=Ro();return r.log(),new Lt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(L.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 ta(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==be.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var sn=class extends be{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:we,isPromiEvent:Mt,encodeJSON:jr,decodeJSON:mo,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:lt,storage:Zr};let e=[this,...ta(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 Io(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)}},ra=class extends sn{},Te=class extends sn{};Te.Internal=ra,Te.Anonymous="anonymous extension";var na=class extends be{purchase(e){let t=W(L.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(L.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(L.NFTTransfer,[e]);return this.request(t)}};function kr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?io(co(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function ia(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 oa(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 wo(a);return o}var at=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw Eo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&So().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 Co(this),this.user=new Jo(this),this.wallet=new Qo(this),this.nft=new na(this),this.thirdPartyWallet=new Zo(this),this.rpcProvider=new ea(this);let s=oa.call(this,t);this.parameters=jr(Br(Wr({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:yo[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=ia(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})}},Ut=at;Ut.__overlays__=new Map;function aa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function sa(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=aa(e,o);if(o&&a){let s=new Lt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function ca(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 Wo()}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 zo(r);return m&&(h.deviceShare=m),h})}function la(e){return Z(this,null,function*(){!e.data.rt||(yield Ie("rt",e.data.rt))})}var cn=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 Qr((r,o)=>Z(this,null,function*(){if(!this.isConnectedToInternet){let v=Tt();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],h=yield ca(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(h);let m=v=>y=>{var O;let{id:_,response:N}=sa(t,y);if(la(y),((O=N==null?void 0:N.payload.error)==null?void 0:O.message)==="User denied account access.")xt();else if(y.data.deviceShare){let{deviceShare:M}=y.data;Xo(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(me.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var kt={};fr(kt,{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:()=>L,RPCError:()=>Ue,RPCErrorCode:()=>$e,RecencyCheckEventEmit:()=>pe,RecencyCheckEventOnReceived:()=>Ir,RecoveryMethodType:()=>Rr,SDKError:()=>ge,SDKErrorCode:()=>he,SDKWarning:()=>Le,SDKWarningCode:()=>me,ThirdPartyWalletEvents:()=>pr,UpdateEmailEventEmit:()=>ve,UpdateEmailEventOnReceived:()=>wr,Wallets:()=>mr,isPromiEvent:()=>Mt});var vt=hr(un()),Wt=hr(dn());var ua={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function fa(e){for(let[t,r]of Object.entries(ua))e.style[t]=r}function da(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var pt=class extends cn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(da(encodeURIComponent(this.parameters)))Kr().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="clipboard-read; clipboard-write",fa(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(o=r.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(r)}})}showOverlay(){return Pe(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return Pe(this,null,function*(){var o;let r=yield this.iframe;r.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return Pe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Tt()})}};var ha=Object.assign(qr(Ut,{platform:"web",sdkName:"magic-sdk",version:"28.0.3",defaultEndpoint:"https://auth.magic.link/",ViewController:pt,configureStorage:()=>Pe(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})}),lr({},kt)),ma=ha;return di(pa);})();
|
5
|
+
Received: \`${e.received}\``)}function Kr(){return new Le(me.DuplicateIframe,"Duplicate iframes found.")}function Ro(){return new Le(me.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 So(){return new Le(me.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(me.DeprecationNotice,h)}function*Ao(){let e=0;for(;;)e<Number.MAX_SAFE_INTEGER?yield++e:e=0}var No=Ao();function Hr(){return No.next().value}var Yr=Symbol("Payload pre-processed by Magic SDK");function Xr(e){return Object.defineProperty(e,Yr,{value:!0,enumerable:!1}),e}function Oo(e){return!!e[Yr]}function lt(e){var t,r,o;return Oo(e)||(e.jsonrpc=(t=e.jsonrpc)!=null?t:"2.0",e.id=Hr(),e.method=(r=e.method)!=null?r:"noop",e.params=(o=e.params)!=null?o:[],Xr(e)),e}function W(e,t=[]){return Xr({params:t,method:e,jsonrpc:"2.0",id:Hr()})}var Lt=class{constructor(e){e instanceof Lt?(this._jsonrpc=e.payload.jsonrpc,this._id=e.payload.id,this._result=e.payload.result,this._error=e.payload.error):vo(e)?(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=e.result,this._error=e.error):(this._jsonrpc=e.jsonrpc,this._id=e.id,this._result=void 0,this._error=void 0)}applyError(e){return this._error=e,this}applyResult(e){return this._result=e,this}get hasError(){return typeof this._error!="undefined"&&this._error!==null}get hasResult(){return typeof this._result!="undefined"}get payload(){return{jsonrpc:this._jsonrpc,id:this._id,result:this._result,error:this._error}}},To=bi(Ri()),Lo=class extends To.default{};function zr(){let e=new Lo;return{emitter:e,createChainingEmitterMethod:(t,r)=>(...o)=>(e[t].apply(e,o),r),createBoundEmitterMethod:t=>(...r)=>e[t].apply(e,r)}}var Jr=Symbol("isPromiEvent");function Mt(e){return!!e[Jr]}function we(e){let t=Qr(e),{createBoundEmitterMethod:r,createChainingEmitterMethod:o}=zr(),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,{[Jr]:!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 Qr(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&&!Object.values(L).includes(e.method))return we((a,s)=>{this.sdk.thirdPartyWallet.requestOverride(e).then(a).catch(s)});let t=this.overlay.post(Ne.MAGIC_HANDLE_REQUEST,lt(e)),r=we((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 _o()}).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=W(L.IntermediaryEvent,[{payloadId:t,eventType:e,args:r}]);this.request(o)}}};function Mo(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"},Co=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&&Mo(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=W(this.sdk.testMode?L.LoginWithMagicLinkTestMode:L.LoginWithMagicLink,[{email:r,showUI:o,redirectURI:a,overrides:s}]);return this.request(h)}loginWithSMS(e){let{phoneNumber:t}=e,r=W(this.sdk.testMode?L.LoginWithSmsTestMode:L.LoginWithSms,[{phoneNumber:t,showUI:!0}]);return this.request(r)}loginWithEmailOTP(e){let{email:t,showUI:r,deviceCheckUI:o,overrides:a}=e,s=W(this.sdk.testMode?L.LoginWithEmailOTPTestMode:L.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=W(this.sdk.testMode?L.LoginWithCredentialTestMode:L.LoginWithCredential,[t]);return this.request(r)}setAuthorizationToken(e){let t=W(L.SetAuthorizationToken,[{jwt:e}]);return this.request(t)}updateEmailWithUI(e){let{email:t,showUI:r=!0}=e,o=W(this.sdk.testMode?L.UpdateEmailTestMode:L.UpdateEmail,[{email:t,showUI:r}]),a=this.request(o);return r||(a.on(pe.Retry,()=>{this.createIntermediaryEvent(pe.Retry,o.id)()}),a.on(pe.Cancel,()=>{this.createIntermediaryEvent(pe.Cancel,o.id)()}),a.on(pe.VerifyEmailOtp,s=>{this.createIntermediaryEvent(pe.VerifyEmailOtp,o.id)(s)}),a.on(ve.RetryWithNewEmail,s=>{this.createIntermediaryEvent(ve.RetryWithNewEmail,o.id)(s)}),a.on(ve.Cancel,()=>{this.createIntermediaryEvent(ve.Cancel,o.id)()}),a.on(ve.VerifyEmailOtp,s=>{this.createIntermediaryEvent(ve.VerifyEmailOtp,o.id)(s)})),a}},Zr={};Ii(Zr,{clear:()=>Po,getItem:()=>ue,iterate:()=>en,key:()=>Do,keys:()=>xo,length:()=>$o,removeItem:()=>ut,setItem:()=>Ie});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"),Ie=Re("setItem"),ut=Re("removeItem"),Po=Re("clear"),$o=Re("length"),Do=Re("key"),xo=Re("keys"),en=Re("iterate");function Uo(){let e=window.crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&191|128;let t="";return t+=e[0].toString(16),t+=e[1].toString(16),t+=e[2].toString(16),t+=e[3].toString(16),t+="-",t+=e[4].toString(16),t+=e[5].toString(16),t+="-",t+=e[6].toString(16),t+=e[7].toString(16),t+="-",t+=e[8].toString(16),t+=e[9].toString(16),t+="-",t+=e[10].toString(16),t+=e[11].toString(16),t+=e[12].toString(16),t+=e[13].toString(16),t+=e[14].toString(16),t+=e[15].toString(16),t}var tn="STORE_KEY_PRIVATE_KEY",Nt="STORE_KEY_PUBLIC_JWK",rn="ECDSA",ko="P-256",Fo={name:rn,namedCurve:ko};function ht(){let e=typeof window!="undefined"&&!!window.crypto,t=e&&!!window.crypto.subtle;return e&&t}function Wo(){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(tn);if(!r||!t){console.info("unable to find private key or webcrypto unsupported");return}let o={iat:Math.floor(new Date().getTime()/1e3),jti:Uo()},a={typ:"dpop+jwt",alg:"ES256",jwk:e},s={protected:xr(JSON.stringify(a)),claims:xr(JSON.stringify(o))},h=jo(`${s.protected}.${s.claims}`),m={name:rn,hash:{name:"SHA-256"}},g=qo(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 Go()),ue(Nt)})}function Go(){return Z(this,null,function*(){let{subtle:e}=window.crypto,t=yield e.generateKey(Fo,!1,["sign"]),r=yield e.exportKey("jwk",t.publicKey);yield Ie(tn,t.privateKey),yield Ie(Nt,r)})}function xr(e){return nn(Vo(e))}function jo(e){return new TextEncoder().encode(e)}function nn(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Vo(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function qo(e){let t="";return e.forEach(r=>{t+=String.fromCharCode(r)}),nn(t)}var Ct="ds",Pt="ek",$t="iv",Dt="AES-GCM",Ko=256;function xt(){return Z(this,null,function*(){let e=[];yield en((t,r,o)=>{r.startsWith(`${Ct}_`)&&e.push(r)});for(let t of e)yield ut(t)})}function on(e){let t="",r=new Uint8Array(e),o=r.byteLength;for(let a=0;a<o;a++)t+=String.fromCharCode(r[a]);return window.btoa(t)}function an(e){let t=window.atob(e),r=t.length,o=new Uint8Array(r);for(let a=0;a<r;a++)o[a]=t.charCodeAt(a);return o.buffer}function Ho(){return Z(this,null,function*(){if(!ht()){console.info("webcrypto is not supported");return}let{crypto:e}=window;return(yield ue($t))||e.getRandomValues(new Uint8Array(12))})}function Yo(){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:Dt,length:Ko},!1,["encrypt","decrypt"]))})}function Xo(e,t){return Z(this,null,function*(){let r=yield Ho(),o=yield Yo();if(!r||!o||!e)return;let a=an(e),{subtle:s}=window.crypto,h=yield s.encrypt({name:Dt,iv:r},o,a),m=on(h);yield Ie(`${Ct}_${t}`,m),yield Ie(Pt,o),yield Ie($t,r)})}function zo(e){return Z(this,null,function*(){let t=yield ue(`${Ct}_${e}`),r=yield ue($t),o=yield ue(Pt);if(!r||!t||!o||!ht())return;let{subtle:a}=window.crypto,s=yield a.decrypt({name:Dt,iv:r},o,an(t));return on(s)})}function Je(e,t){return t?new URL(e,t):new URL(e)}var Jo=class extends be{constructor(){super(...arguments),this.localForageIsLoggedInKey="magic_auth_is_logged_in",this.userLoggedOutCallbacks=[]}getIdToken(e){let t=W(this.sdk.testMode?L.GetIdTokenTestMode:L.GetIdToken,[e]);return this.request(t)}generateIdToken(e){let t=W(this.sdk.testMode?L.GenerateIdTokenTestMode:L.GenerateIdToken,[e]);return this.request(t)}getInfo(){if(this.sdk.thirdPartyWallet.isConnected)return this.sdk.thirdPartyWallet.getInfo();let e=W(L.GetInfo,[]);return this.request(e)}isLoggedIn(){return we((e,t)=>Z(this,null,function*(){try{if(this.sdk.thirdPartyWallet.isConnected){let s=yield this.sdk.thirdPartyWallet.isLoggedIn();return e(s)}let r=!1;if(this.sdk.useStorageCache&&(r=(yield ue(this.localForageIsLoggedInKey))==="true",r))return e(!0);let o=W(this.sdk.testMode?L.IsLoggedInTestMode:L.IsLoggedIn),a=yield this.request(o);return this.sdk.useStorageCache&&(a?Ie(this.localForageIsLoggedInKey,!0):ut(this.localForageIsLoggedInKey),r&&!a&&this.emitUserLoggedOut(!0)),e(a)}catch(r){return t(r)}}))}logout(){return ut(this.localForageIsLoggedInKey),xt(),we((e,t)=>Z(this,null,function*(){try{if(this.sdk.thirdPartyWallet.isConnected)return yield this.sdk.thirdPartyWallet.logout(),e(!0);let r=W(this.sdk.testMode?L.LogoutTestMode:L.Logout),o=yield this.request(r);return this.sdk.useStorageCache&&this.emitUserLoggedOut(o),e(o)}catch(r){return t(r)}}))}requestInfoWithUI(e){let t=W(L.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}showSettings(e){let t=W(this.sdk.testMode?L.UserSettingsTestMode:L.UserSettings,[e]);return this.request(t)}recoverAccount(e){let t=W(this.sdk.testMode?L.RecoverAccountTestMode:L.RecoverAccount,[e]);return this.request(t)}revealPrivateKey(){let e=W(L.RevealPK);return this.request(e)}getMetadata(){Ye({method:"user.getMetadata()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=W(this.sdk.testMode?L.GetMetadataTestMode:L.GetMetadata);return this.request(e)}onUserLoggedOut(e){this.userLoggedOutCallbacks.push(e)}emitUserLoggedOut(e){this.userLoggedOutCallbacks.forEach(t=>{t(e)})}},Qo=class extends be{connectWithUI(){let e=we((t,r)=>Z(this,null,function*(){try{let o=W(L.Login,[this.sdk.thirdPartyWallet.enabledWallets]),a=this.request(o);this.sdk.thirdPartyWallet.eventListeners.forEach(({event:h,callback:m})=>{a.on(h,()=>m(o.id))}),a.on("id-token-created",h=>{e.emit("id-token-created",h)});let s=yield a;s.error&&r(s),t(s)}catch(o){r(o)}}));return e}showUI(){return this.request(W(L.ShowUI))}showAddress(){return this.request(W(L.ShowAddress))}showSendTokensUI(){return this.request(W(L.ShowSendTokensUI))}showOnRamp(){return this.request(W(L.ShowOnRamp))}showNFTs(){return this.request(W(L.ShowNFTs))}showBalances(){return this.request(W(L.ShowBalances))}sendGaslessTransaction(e,t){return this.request(W(L.SendGaslessTransaction,[e,t]))}getInfo(){return Z(this,null,function*(){Ye({method:"wallet.getInfo()",removalVersions:Xe,useInstead:"user.getInfo()"}).log();let e=W(L.GetInfo,[]);return this.request(e)})}disconnect(){Ye({method:"wallet.disconnect()",removalVersions:Xe,useInstead:"user.logout()"}).log(),xt();let e=W(L.Disconnect);return this.request(e)}requestUserInfoWithUI(e){Ye({method:"wallet.requestUserInfoWithUI()",removalVersions:Xe,useInstead:"user.requestUserInfoWithUI()"}).log();let t=W(L.RequestUserInfoWithUI,e?[e]:[]);return this.request(t)}},Zo=class extends be{constructor(){super(...arguments),this.eventListeners=[],this.enabledWallets={},this.isConnected=!!localStorage.getItem("3pw_address")}getInfo(){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalGetInfo();default:return null}}isLoggedIn(){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalIsLoggedIn();default:return null}}resetState(){localStorage.removeItem("3pw_provider"),localStorage.removeItem("3pw_address"),localStorage.removeItem("3pw_chainId"),this.isConnected=!1}logout(){let e=localStorage.getItem("3pw_provider");switch(this.resetState(),e){case"web3modal":return this.web3modalLogout();default:return!0}}requestOverride(e){switch(localStorage.getItem("3pw_provider")){case"web3modal":return this.web3modalRequest(e);default:return null}}web3modalGetInfo(){return we(e=>{let t=this.sdk.web3modal.modal.getWalletInfo().name,r=this.sdk.web3modal.modal.getAddress();e({publicAddress:r,email:null,issuer:`$did:ethr:${r}`,phoneNumber:null,isMfaEnabled:!1,recoveryFactors:[],walletType:t})})}web3modalIsLoggedIn(){return we(e=>{setTimeout(()=>{let t=this.sdk.web3modal.modal.getIsConnected();e(t)},50)})}web3modalRequest(e){return this.sdk.web3modal.modal.getWalletProvider().request(e)}web3modalLogout(){var e;return(e=this.sdk.web3modal.modal)==null?void 0:e.disconnect()}},{createBoundEmitterMethod:ot,createChainingEmitterMethod:De}=zr(),ea=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 bo({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(Wr({},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=W(e,Array.isArray(t)?t:[]);return this.request(o)}if(Array.isArray(e)||!!t){this.sendAsync(e,t);return}let r=Ro();return r.log(),new Lt(e).applyError({code:-32603,message:r.rawMessage}).payload}enable(){let e=W(L.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 ta(e){let t=Object.getPrototypeOf(e),r=[t];for(;t!==be.prototype;)t=Object.getPrototypeOf(t),r.push(t);return r}var sn=class extends be{constructor(){super(void 0),this.__sdk_access_field_descriptors__=new Map,this.__is_initialized__=!1,this.utils={createPromiEvent:we,isPromiEvent:Mt,encodeJSON:jr,decodeJSON:mo,createJsonRpcRequestPayload:W,standardizeJsonRpcRequestPayload:lt,storage:Zr};let e=[this,...ta(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 Io(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)}},ra=class extends sn{},Te=class extends sn{};Te.Internal=ra,Te.Anonymous="anonymous extension";var na=class extends be{purchase(e){let t=W(L.NFTPurchase,[e]);return this.request(t)}checkout(e){let t=W(L.NFTCheckout,[e]);return this.request(t)}transfer(e){let t=W(L.NFTTransfer,[e]);return this.request(t)}};function kr(e){return e.compat&&e.compat[Y.sdkName]!=null?typeof e.compat[Y.sdkName]=="string"?io(co(Y.version),e.compat[Y.sdkName]):!!e.compat[Y.sdkName]:!0}function ia(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 oa(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 wo(a);return o}var at=class{constructor(e,t){this.apiKey=e;var r;if(!e)throw Eo();Y.platform==="react-native"&&(t==null?void 0:t.endpoint)&&So().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 Co(this),this.user=new Jo(this),this.wallet=new Qo(this),this.nft=new na(this),this.thirdPartyWallet=new Zo(this),this.rpcProvider=new ea(this);let s=oa.call(this,t);this.parameters=jr(Br(Wr({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:yo[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=ia(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})}},Ut=at;Ut.__overlays__=new Map;function aa(e,t){return t&&Array.isArray(e)?e.find(r=>r.id===t):e}function sa(e,t){var r;let o=(r=t.data.response)==null?void 0:r.id,a=aa(e,o);if(o&&a){let s=new Lt(a).applyResult(t.data.response.result).applyError(t.data.response.error);return{id:o,response:s}}return{}}function ca(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 Wo()}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 zo(r);return m&&(h.deviceShare=m),h})}function la(e){return Z(this,null,function*(){!e.data.rt||(yield Ie("rt",e.data.rt))})}var cn=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 Qr((r,o)=>Z(this,null,function*(){if(!this.isConnectedToInternet){let v=Tt();o(v)}this.isReadyForRequest||(yield this.waitForReady());let a=[],s=Array.isArray(t)?t.map(v=>v.id):[],h=yield ca(`${e}-${this.parameters}`,t,this.networkHash);yield this._post(h);let m=v=>y=>{var O;let{id:_,response:N}=sa(t,y);if(la(y),((O=N==null?void 0:N.payload.error)==null?void 0:O.message)==="User denied account access.")xt();else if(y.data.deviceShare){let{deviceShare:M}=y.data;Xo(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(me.ProductAnnouncement,e.data.response.result.product_announcement).log()})}};var kt={};fr(kt,{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:()=>L,RPCError:()=>Ue,RPCErrorCode:()=>$e,RecencyCheckEventEmit:()=>pe,RecencyCheckEventOnReceived:()=>Ir,RecoveryMethodType:()=>Rr,SDKError:()=>ge,SDKErrorCode:()=>he,SDKWarning:()=>Le,SDKWarningCode:()=>me,ThirdPartyWalletEvents:()=>pr,UpdateEmailEventEmit:()=>ve,UpdateEmailEventOnReceived:()=>wr,Wallets:()=>mr,isPromiEvent:()=>Mt});var vt=hr(un()),Wt=hr(dn());var ua={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};function fa(e){for(let[t,r]of Object.entries(ua))e.style[t]=r}function da(e){let t=[].slice.call(document.querySelectorAll(".magic-iframe"));return Boolean(t.find(r=>r.src.includes(e)))}var pt=class extends cn{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(r=>{let o=()=>{if(da(encodeURIComponent(this.parameters)))Kr().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="clipboard-read; clipboard-write",fa(a),document.body.appendChild(a),r(a)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}),window.addEventListener("message",r=>{var o;if(r.origin===this.endpoint&&r.data&&r.data.msgType&&this.messageHandlers.size){r.data.response=(o=r.data.response)!=null?o:{};for(let a of this.messageHandlers.values())a(r)}})}showOverlay(){return Pe(this,null,function*(){let r=yield this.iframe;r.style.display="block",this.activeElement=document.activeElement,r.focus()})}hideOverlay(){return Pe(this,null,function*(){var o;let r=yield this.iframe;r.style.display="none",(o=this.activeElement)!=null&&o.focus&&this.activeElement.focus(),this.activeElement=null})}_post(r){return Pe(this,null,function*(){let o=yield this.iframe;if(o&&o.contentWindow)o.contentWindow.postMessage(r,this.endpoint);else throw Tt()})}};var ha=Object.assign(qr(Ut,{platform:"web",sdkName:"magic-sdk",version:"28.0.3",defaultEndpoint:"https://auth.magic.link/",ViewController:pt,configureStorage:()=>Pe(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})}),lr({},kt)),ma=ha;return di(pa);})();
|
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.8822704945.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.8822704945.0",
|
33
|
+
"@magic-sdk/provider": "28.0.3-canary.742.8822704945.0",
|
34
|
+
"@magic-sdk/types": "24.0.2-canary.742.8822704945.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": "5db3f11b5e5ec1c19b05444ce3918f115fdf69b1"
|
44
44
|
}
|