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