@human.tech/waap-sdk 1.0.2 → 1.0.3

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/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@human.tech/waap-constants"),require("events"),require("@human.tech/waap-interface-core"),require("@reown/appkit-adapter-ethers")):"function"==typeof define&&define.amd?define(["exports","@human.tech/waap-constants","events","@human.tech/waap-interface-core","@reown/appkit-adapter-ethers"],t):t((e||self).waapSdk={},e.waapConstants,e.events,e.waapInterfaceCore,e.appkitAdapterEthers)}(this,function(e,t,n,r,i){function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(null,arguments)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function l(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function d(e){var t="function"==typeof Map?new Map:void 0;return d=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(c())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&u(i,n.prototype),i}(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)},d(e)}var f,h=/*#__PURE__*/function(){function e(e,n){this.iframeWindow=null,this.walletOrigin=void 0,this.iframeWindow=e,this.walletOrigin=n?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2}var n=e.prototype;return n.postSilkNotification=function(e){this.iframeWindow.postMessage({target:"silk",messageType:r.SILK_MESSAGE_TYPE.notification,data:e},this.walletOrigin)},n.postReadyNotification=function(){this.postSilkNotification(r.SILK_NOTIFICATION.ready)},n.postConnectNotification=function(){this.postSilkNotification(r.SILK_NOTIFICATION.connect)},n.pingIframe=function(){var e=this;return new Promise(function(t,n){setTimeout(function(){return n("Wallet ping timed out.")},1e4),window.addEventListener("message",function e(n){"silk"===n.data.target&&n.data.messageType===r.SILK_MESSAGE_TYPE.notification&&n.data.data===r.SILK_NOTIFICATION.ready&&(window.removeEventListener("message",e),t())}),e.postReadyNotification()})},n.postSilkRequest=function(e){try{var t=this,n=a({},e,{target:"silk",messageType:r.SILK_MESSAGE_TYPE.request});return Promise.resolve(r.generateMessageId(n)).then(function(e){return t.iframeWindow.postMessage(a({},n,{id:e}),t.walletOrigin),e})}catch(e){return Promise.reject(e)}},n.addListener=function(e){var t=this,n=e.handleResponse,i=e.handleRequest,o=e.onReceiveConnectNotif,a=e.onAccountChanged;window.addEventListener("message",function(e){var s,l,c;try{if("undefined"!=typeof process&&process,e.origin!==t.walletOrigin)return}catch(n){if(e.origin!==t.walletOrigin)return}if((null==(s=e.data)?void 0:s.messageType)===r.SILK_MESSAGE_TYPE.request)i(e.data);else if((null==(l=e.data)?void 0:l.messageType)===r.SILK_MESSAGE_TYPE.response)n(e.data);else if((null==(c=e.data)?void 0:c.messageType)===r.SILK_MESSAGE_TYPE.notification){var u,d;(null==(u=e.data)?void 0:u.data)===r.SILK_NOTIFICATION.connect?null==o||o():(null==(d=e.data)||null==(d=d.data)?void 0:d.type)===r.SILK_NOTIFICATION.account_changed&&a&&a(e.data.data.account)}})},e}();e.UI_EVENT_NAMES=void 0,(f=e.UI_EVENT_NAMES||(e.UI_EVENT_NAMES={})).show_modal="show_modal",f.hide_modal="hide_modal";var m=/*#__PURE__*/function(e){function t(){return e.call(this)||this}return l(t,e),t}(n.EventEmitter),g=function(e,t,n,r){try{return Promise.resolve(n.postSilkRequest({method:e.method,params:e.params,interactionRequired:t})).then(function(e){return new Promise(function(t,n){r.once(e,function(e){e.error?n(e.error):t(e.data)})})})}catch(e){return Promise.reject(e)}},p={styles:{darkMode:!1}};function v(e,t,n){if(!e.s){if(n instanceof w){if(!n.s)return void(n.o=v.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(v.bind(null,e,t),v.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var w=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{v(r,1,o(this.v))}catch(e){v(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?v(r,1,t?t(i):i):n?v(r,1,n(i)):v(r,2,i)}catch(e){v(r,2,e)}},r},e}();function y(e){return e instanceof w&&1&e.s}var E=/*#__PURE__*/function(){function e(){}return e.setProjectId=function(e){this.projectId=e},e.getProjectIdFromEnv=function(){try{if("undefined"!=typeof process&&process.env)return process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID||process.env.VITE_WALLET_CONNECT_PROJECT_ID||process.env.REACT_APP_WALLET_CONNECT_PROJECT_ID||process.env.WALLET_CONNECT_PROJECT_ID}catch(e){return}},e.getInstance=function(){try{var e=this;return"undefined"==typeof window||"undefined"==typeof document?Promise.resolve(null):Promise.resolve(import("@reown/appkit")).then(function(t){var n=t.createAppKit;return Promise.resolve(import("@reown/appkit/networks")).then(function(t){var r=t.mainnet,o=t.sepolia,a=t.optimism,s=t.arbitrum,l=t.polygon,c=t.gnosis,u=t.avalanche,d=t.aurora,f=t.fantom,h=t.base,m=t.celo;try{var g={name:"Human Wallet",description:"Silk lets you create human keys for web3 wallets that are recoverable with private identity proofs and secured by zero trust protocols.",url:window.location.origin,icons:["https://imagedelivery.net/_aTEfDRm7z3tKgu9JhfeKA/f11f5753-616a-4aa0-2aee-9b75befea700/sm"]},p=e.projectId||e.getProjectIdFromEnv();return p?(e.projectId=p,e.instance||(e.instance=n({adapters:[new i.EthersAdapter],projectId:p,metadata:g,networks:[r,o,s,a,l,c,u,d,f,h,m],features:{socials:!1,email:!1}})),e.instance):(console.error('WalletConnect project ID not found. Please set it using one of these methods:\n1. Pass walletConnectProjectId when calling initSilk\n2. Call SilkWalletConnect.setProjectId("your-project-id")\n3. Set WALLET_CONNECT_PROJECT_ID (NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID for Next projects) environment variable'),null)}catch(e){return console.error("Error importing or initializing WalletConnect:",e),null}})})}catch(e){return Promise.reject(e)}},e.listenToAccountChangeEvent=function(){try{var e=this;return Promise.resolve(new Promise(function(t){e.instance.subscribeAccount(function(e){null!=e&&e.isConnected&&t()})})).then(function(){})}catch(e){return Promise.reject(e)}},e.waitForReadyAndCheckConnection=function(){try{var e=this;if(!e.instance)return Promise.resolve(!1);var t=!1,n=0,r=function(e,t,n){for(var r;;){var i=e();if(y(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!y(o)){r=1;break}o=o.s}if(t){var a=t();if(a&&a.then&&!y(a)){r=2;break}}}var s=new w,l=v.bind(null,s,2);return(0===r?i.then(u):1===r?o.then(c):a.then(d)).then(void 0,l),s;function c(r){o=r;do{if(t&&(a=t())&&a.then&&!y(a))return void a.then(d).then(void 0,l);if(!(i=e())||y(i)&&!i.v)return void v(s,1,o);if(i.then)return void i.then(u).then(void 0,l);y(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,l)}function u(e){e?(o=n())&&o.then?o.then(c).then(void 0,l):c(o):v(s,1,o)}function d(){(i=e())?i.then?i.then(u).then(void 0,l):u(i):v(s,1,o)}}(function(){return!t&&n<15},void 0,function(){var r=n<5?500:1e3;return Promise.resolve(new Promise(function(e){return setTimeout(e,r)})).then(function(){t=e.instance.getIsConnectedState(),n++,console.log("WalletConnect connection check attempt "+n+": "+t)})});return Promise.resolve(r&&r.then?r.then(function(){return t}):t)}catch(e){return Promise.reject(e)}},e.isConnected=function(){var e,t;return null!=(e=null==(t=this.instance)?void 0:t.getIsConnectedState())&&e},e.getWalletProvider=function(){var e,t;return null!=(e=null==(t=this.instance)?void 0:t.getWalletProvider())?e:null},e}();function M(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}E.instance=null,E.projectId=void 0,E.chains=[1,10,100,137,8453,43114,42161,42220,84532,11155111];var _=/*#__PURE__*/function(i){function s(t,s,l,c,u,d){var f;return(f=i.call(this)||this).isSilk=!0,f.isWaaP=!0,f.connected=!1,f.walletMessageManager=void 0,f.uiMessageManager=void 0,f.config=void 0,f.currentAccount=null,f.walletConnectProvider=null,f.persistedMethods=void 0,f.internalEventEmitter=new n.EventEmitter,f.uiMessageManager=new m,f.walletMessageManager=new h(t,!!u),f.config=a({},p,l||{}),f.persistedMethods={login:f.login.bind(o(f)),logout:f.logout.bind(o(f)),getLoginMethod:f.getLoginMethod.bind(o(f)),walletMessageManager:f.walletMessageManager,internalEventEmitter:f.internalEventEmitter,uiMessageManager:f.uiMessageManager,portal:f.portal.bind(o(f)),requestEmail:f.requestEmail.bind(o(f)),requestSBT:f.requestSBT.bind(o(f)),orcid:f.orcid.bind(o(f)),enable:f.enable.bind(o(f)),isConnected:f.isConnected.bind(o(f)),toggleDarkMode:f.toggleDarkMode.bind(o(f)),silkRequest:f.request.bind(o(f)),waaPRequest:f.request.bind(o(f))},f.walletMessageManager.addListener({onReceiveConnectNotif:function(){console.log("onReceiveConnectNotif"),f.connected=!0,f.emit("connect")},handleResponse:function(e){return f.internalEventEmitter.emit(e.id,e)},handleRequest:function(t){t.method===r.SILK_METHOD.show_modal?f.uiMessageManager.emit(e.UI_EVENT_NAMES.show_modal):t.method===r.SILK_METHOD.hide_modal&&f.uiMessageManager.emit(e.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){f.currentAccount!==e&&(f.currentAccount=e,f.emit("accountsChanged",e?[e]:[]))}}),s&&f.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.set_points_referral_code,params:[s]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error setting referral code in Silk iframe:",e)}),c&&f.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.set_project,params:[c,window.location.origin]},!1,f.walletMessageManager,f.internalEventEmitter)}),l&&f.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.set_custom_config,params:[l]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),d&&f.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.force_iframe,params:[!0]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error forcing iframe in Silk iframe:",e)}),f}l(s,i);var c=s.prototype;return c.initializeWalletConnect=function(){try{var e=this,t=M(function(){return Promise.resolve(E.getInstance()).then(function(t){e.walletConnectProvider=t,console.log("WalletConnect provider initialized")})},function(t){console.error("Failed to initialize WalletConnect provider:",t),e.walletConnectProvider=null});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},c.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},c.isConnected=function(){return this.connected},c.request=function(e){try{var n=this;return Object.keys(r.JSON_RPC_METHOD).includes(e.method)?Promise.resolve(n.attemptAutoConnect(e.method)).then(function(i){return null!==i?i:function(e){try{var t;if(!e||!Array.isArray(e))return!1;var n=JSON.parse("string"==typeof e[1]?e[1]:JSON.stringify(e[1]));return"SafeTx"===n.primaryType&&void 0!==(null==(t=n.domain)?void 0:t.verifyingContract)&&n.message&&"to"in n.message&&"value"in n.message&&"safeTxGas"in n.message&&"baseGas"in n.message&&"gasPrice"in n.message&&"nonce"in n.message}catch(e){return!1}}(e.params)&&e.method!==r.JSON_RPC_METHOD.eth_signTypedData_v4?Promise.reject({error:"Safe transactions must be signed using eth_signTypedData_v4"}):Promise.resolve(n.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(g(e,t.rpcMethodRequiresUI(e.method),n.walletMessageManager,n.internalEventEmitter)).then(function(t){var i=function(){if((e.method===r.JSON_RPC_METHOD.wallet_switchEthereumChain||e.method===r.JSON_RPC_METHOD.wallet_addEthereumChain)&&null===t){var i;n.emit("chainChanged",null==(i=e.params)||null==(i=i[0])?void 0:i.chainId);var o=M(function(){return Promise.resolve(n.request({method:"eth_accounts"})).then(function(t){var r,i;t&&t.length>0&&(n.currentAccount=t[0],n.emit("accountsChanged",t),n.emit("connect",{chainId:null==(r=e.params)||null==(r=r[0])?void 0:r.chainId}),console.log("[EthereumProvider] Re-emitted accounts and connect after chain switch:",{accounts:t,chainId:null==(i=e.params)||null==(i=i[0])?void 0:i.chainId}))})},function(t){var r;console.warn("[EthereumProvider] Failed to get accounts after chain switch:",t),n.currentAccount&&(n.emit("accountsChanged",[n.currentAccount]),n.emit("connect",{chainId:null==(r=e.params)||null==(r=r[0])?void 0:r.chainId}))});if(o&&o.then)return o.then(function(){})}}();return i&&i.then?i.then(function(){return t}):t})})}):Promise.reject({error:"Not implemented ("+e.method+")"})}catch(e){return Promise.reject(e)}},c.login=function(e){try{var t=function(){var t=e||window.ethereum,i=t&&function(e){return!(null==e||!e.isMetaMask||e.isApexWallet||e.isAvalanche||e.isBitKeep||e.isBlockWallet||e.isMathWallet||e.isOkxWallet||e.isOKExWallet||e.isOneInchIOSWallet||e.isOneInchAndroidWallet||e.isOpera||e.isPortal||e.isRabby||e.isDefiant||e.isTokenPocket||e.isTokenary||e.isZerion)}(t)?"MetaMask":"Browser Wallet";return Promise.resolve(n.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(g({method:r.SILK_METHOD.login,params:[i]},!0,n.walletMessageManager,n.internalEventEmitter)).then(function(e){"string"==typeof e&&e.includes("waap")&&(localStorage.setItem(window.location.origin+"-connected","waap"),n.setupWaaP()),"string"==typeof e&&e.includes("injected")&&t&&(localStorage.setItem(window.location.origin+"-connected","injected"),n.setupInjectedWallet(t));var r=function(){if("string"==typeof e&&e.includes("walletconnect")){var t=function(){var e=E.getWalletProvider();n.setupWalletConnect(e)};localStorage.setItem(window.location.origin+"-connected","walletconnect");var r=function(){if(!E.isConnected())return Promise.resolve(n.walletConnectProvider.open({view:"Connect"})).then(function(){return Promise.resolve(E.listenToAccountChangeEvent()).then(function(){})})}();return r&&r.then?r.then(t):t()}}();return r&&r.then?r.then(function(){return e}):e})})},n=this;if("undefined"==typeof window||"undefined"==typeof document)return Promise.resolve(null);var i=function(e){if(null!=(e=n.config.authenticationMethods)&&e.includes("wallet")&&!n.walletConnectProvider)return Promise.resolve(n.initializeWalletConnect()).then(function(){})}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},c.logout=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){function t(){return g({method:r.SILK_METHOD.logout},!1,e.walletMessageManager,e.internalEventEmitter)}e.cleanupInvalidLoginState();var n=M(function(){var t=function(){if(e.walletConnectProvider)return Promise.resolve(e.walletConnectProvider.disconnect()).then(function(){})}();if(t&&t.then)return t.then(function(){})},function(e){console.error("Error disconnecting from WalletConnect:",e)});return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},c.cleanupInvalidLoginState=function(){try{localStorage.removeItem(window.location.origin+"-connected")}catch(e){console.warn("Could not clean up login state:",e)}},c.setupWaaP=function(){var e=a({},this.persistedMethods,{isWaaP:!0,request:this.request.bind(this)});window.silk=e,window.waap=e},c.setupInjectedWallet=function(e){var t,n,r,i,o,s=a({},this.persistedMethods,e,{isSilk:!0,connected:null!=(t=e.connected)&&t,on:null!=(n=null==(r=e.on)?void 0:r.bind(e))?n:function(){},removeListener:null!=(i=null==(o=e.removeListener)?void 0:o.bind(e))?i:function(){},request:e.request.bind(e)});window.silk=s,window.waap=s},c.setupWalletConnect=function(e){var t,n,r,i,o=a({},this.persistedMethods,e,{isSilk:!0,connected:!0,on:null!=(t=null==(n=e.on)?void 0:n.bind(e))?t:function(){},removeListener:null!=(r=null==(i=e.removeListener)?void 0:i.bind(e))?r:function(){},request:e.request.bind(e)});window.silk=o,window.waap=o},c.setupAutoConnectInjected=function(e){var t,n,r,i,o,s=a({},this.persistedMethods,e,{isSilk:!1,connected:null!=(t=null==e.isConnected?void 0:e.isConnected())&&t,on:null!=(n=null==(r=e.on)?void 0:r.bind(e))?n:function(){},removeListener:null!=(i=null==(o=e.removeListener)?void 0:o.bind(e))?i:function(){},request:e.request.bind(e)});window.silk=s,window.waap=s},c.setupAutoConnectWalletConnect=function(e){var t,n,r,i,o=a({},this.persistedMethods,e,{isSilk:!1,connected:!0,on:null!=(t=null==(n=e.on)?void 0:n.bind(e))?t:function(){},removeListener:null!=(r=null==(i=e.removeListener)?void 0:i.bind(e))?r:function(){},request:e.request.bind(e)});window.silk=o,window.waap=o},c.attemptAutoConnect=function(e){try{var t,n=this;if("eth_requestAccounts"!==e&&"eth_accounts"!==e)return Promise.resolve(null);n.walletMessageManager.pingIframe().then(function(){try{return Promise.resolve(g({method:r.SILK_METHOD.auto_conn,params:[window.location.origin]},!1,n.walletMessageManager,n.internalEventEmitter)).then(function(){})}catch(e){return Promise.reject(e)}});var i=n.getLoginMethod(),o=function(){if("injected"!==i||!window.ethereum)return function(){if("walletconnect"===i)return M(function(){function e(){return Promise.resolve(E.waitForReadyAndCheckConnection()).then(function(e){if(e){var r=E.getWalletProvider();n.setupAutoConnectWalletConnect(r);var i=r.request({method:"eth_requestAccounts"});return t=1,i}return console.log("WalletConnect not connected, cleaning up and falling through to normal flow"),n.cleanupInvalidLoginState(),t=1,null})}var r=function(){if(!n.walletConnectProvider)return Promise.resolve(E.getInstance()).then(function(e){n.walletConnectProvider=e})}();return r&&r.then?r.then(e):e()},function(e){return console.warn("WalletConnect auto-connect failed:",e),n.cleanupInvalidLoginState(),t=1,null})}();try{n.setupAutoConnectInjected(window.ethereum);var e=window.ethereum.request({method:"eth_requestAccounts"});return t=1,e}catch(e){return console.warn("Injected wallet auto-connect failed:",e),n.cleanupInvalidLoginState(),t=1,null}}();return Promise.resolve(o&&o.then?o.then(function(e){return t?e:null}):t?o:null)}catch(e){return Promise.reject(e)}},c.getLoginMethod=function(){if("undefined"==typeof window||"undefined"==typeof localStorage)return null;try{var e=localStorage.getItem(window.location.origin+"-connected");if(!e)return null;if(!["waap","human","injected","walletconnect"].includes(e))return this.cleanupInvalidLoginState(),null;switch(e){case"injected":return window.ethereum?"injected":(this.cleanupInvalidLoginState(),null);case"walletconnect":try{return E.isConnected()?"walletconnect":(this.cleanupInvalidLoginState(),null)}catch(e){return this.cleanupInvalidLoginState(),null}case"waap":return"waap";case"human":return"human";default:return this.cleanupInvalidLoginState(),null}}catch(e){return console.warn("Error checking login method:",e),this.cleanupInvalidLoginState(),null}},c.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,e.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.set_custom_config,params:[e.config]},!1,e.walletMessageManager,e.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),Promise.resolve()}catch(e){return Promise.reject(e)}},c.safe=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.safe},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},c.orcid=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return g({method:r.SILK_METHOD.orcid},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},c.portal=function(e,t,n){try{var i=this;return Promise.resolve(i.walletMessageManager.pingIframe()).then(function(){var o;switch(t){case"get":o="gastank"===e?r.SILK_METHOD.gastank_get_settings:r.SILK_METHOD.customization_get;break;case"update":o="gastank"===e?r.SILK_METHOD.gastank_update_settings:r.SILK_METHOD.customization_update;break;case"topup":o=r.SILK_METHOD.gastank_topup;break;case"init":o=r.SILK_METHOD.project_init}return g({method:o,params:[n,window.location.origin]},"get"!==t&&"customization"!==e,i.walletMessageManager,i.internalEventEmitter)})}catch(e){return Promise.reject(e)}},c.requestEmail=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return g({method:r.SILK_METHOD.silk_requestEmail},!0,e.walletMessageManager,e.internalEventEmitter)})}catch(e){return Promise.reject(e)}},c.requestSBT=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return g({method:r.SILK_METHOD.silk_requestSbt,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},s}(n.EventEmitter),I="waap-wallet",P="waap-component-container",C="undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof HTMLElement;function S(){return!(!C||!document.getElementById(P)&&!document.querySelector(I))}function T(){return C?document.getElementById(P)||document.querySelector(I):null}e.WaaP=void 0,C?(e.WaaP=/*#__PURE__*/function(e){function t(){var t;return(t=e.call(this)||this).style.display&&""!==t.style.display||(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center"),t.style.width&&""!==t.style.width||(t.style.width="100%"),t.style.height&&""!==t.style.height||(t.style.height="100%"),t.id=P,t}l(t,e);var n=t.prototype;return n.connectedCallback=function(){this.setAttribute("data-waap-mounted","true")},n.disconnectedCallback=function(){this.removeAttribute("data-waap-mounted")},t}(/*#__PURE__*/d(HTMLElement)),"undefined"==typeof customElements||customElements.get(I)||customElements.define(I,e.WaaP)):e.WaaP=function(){};var O="waap-wallet-iframe-container",b="waap-wallet-iframe-wrapper",k="waap-wallet-iframe",L=function(){return document.getElementById(O)||document.getElementById("silk-wallet-iframe-container")},j=function(){return document.getElementById(b)||document.getElementById("silk-wallet-iframe-wrapper")},A=function(){return document.getElementById(k)||document.getElementById("silk-wallet-iframe")},W=O,N=b,q=k,D=function(e){var n=window.document.createElement("iframe");return n.id=q,n.src=(e?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2)+"/iframe",console.log("iframe.src: ",n.src),n.style.width="100%",n.style.height="100%",n.style.border="none",n.style.borderRadius="24px",n.style.backgroundColor="transparent",n.style.background="transparent",n.style.padding="0",n.style.margin="0",n},R=function(e,n){var r=function(n){if(n.origin===(e?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2)&&n.data&&"object"==typeof n.data&&"silk-iframe-size"===n.data.type){var r=n.data.height,i=n.data.width;if("number"==typeof r&&"number"==typeof i&&!(r<50||r>2e3)&&!(i<50||i>2e3)&&Number.isFinite(r)&&Number.isFinite(i)){var o=j();o&&(o.style.height=Math.floor(r)+"px",o.style.width=Math.floor(i)+"px")}}};window.addEventListener("message",r),n.__silkCleanup=function(){window.removeEventListener("message",r)}},K=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this)||this).isSilk=!0,n.connected=!1,n.config=void 0,n.config=a({},p,t||{}),n}l(t,e);var n=t.prototype;return n.sendToExtension=function(e){return new Promise(function(t,n){window.postMessage({type:"FROM_PAGE",request:e},"*"),window.addEventListener("message",function(e){"FROM_EXTENSION"===e.data.type&&(e.data.error?n(e.data.error):t(e.data.result))})})},n.request=function(e){try{var t=this;return Object.keys(r.JSON_RPC_METHOD).includes(e.method)?Promise.resolve(t.sendToExtension(e)).then(function(n){var i;return e.method!==r.JSON_RPC_METHOD.wallet_switchEthereumChain&&e.method!==r.JSON_RPC_METHOD.wallet_addEthereumChain||null!==n||t.emit("chainChanged",null==(i=e.params)||null==(i=i[0])?void 0:i.chainId),n}):Promise.reject({error:"Not implemented ("+e.method+")"})}catch(e){return Promise.reject(e)}},n.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},n.isConnected=function(){return this.connected},n.login=function(){try{return Promise.resolve(this.sendToExtension({method:r.SILK_METHOD.login}))}catch(e){return Promise.reject(e)}},n.requestSBT=function(e){try{return Promise.resolve(this.sendToExtension({method:r.SILK_METHOD.silk_requestSbt,params:[e]}))}catch(e){return Promise.reject(e)}},n.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,Promise.resolve(e.sendToExtension({method:r.SILK_METHOD.set_custom_config,params:[e.config]})).then(function(){})}catch(e){return Promise.reject(e)}},n.safe=function(){try{return Promise.resolve(this.sendToExtension({method:r.SILK_METHOD.safe}))}catch(e){return Promise.reject(e)}},t}(n.EventEmitter);Object.defineProperty(e,"rpcMethodRequiresUI",{enumerable:!0,get:function(){return t.rpcMethodRequiresUI}}),Object.defineProperty(e,"SILK_METHOD",{enumerable:!0,get:function(){return r.SILK_METHOD}}),Object.defineProperty(e,"WAAP_METHOD",{enumerable:!0,get:function(){return r.SILK_METHOD}}),e.EthereumProvider=_,e.EthereumProviderExtension=K,e.SilkWalletConnect=E,e.UIMessageManager=m,e.WaaPWalletConnect=E,e.WalletMessageManager=h,e.handleWalletRequestAndResponse=g,e.initWaaP=function(t){var n;void 0===t&&(t={}),n=!!t.useStaging,S()?function(e){var t=T();if(!t)throw new Error("WaaP component not found in DOM");if(!A()){var n=window.document.createElement("div");n.id=N,n.style.position="relative",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.padding="0",n.style.margin="0",n.style.height="600px",n.style.width="380px";var r=D(e);R(e,r),setTimeout(function(){var e=j();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),t.appendChild(n)}}(n):function(e){if(!L()){var t=window.document.createElement("div");t.id=W,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.right="0",t.style.bottom="0",t.style.width="100%",t.style.height="100%",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.backgroundColor="rgba(0, 0, 0, 0.5)",t.style.zIndex="99999",t.style.display="none";var n=window.document.createElement("div");n.id=N,n.style.position="relative",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.padding="0",n.style.margin="0",n.style.height="600px",n.style.width="380px",t.appendChild(n);var r=D(e);R(e,r),setTimeout(function(){var e=j();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),window.document.body.appendChild(t)}}(n);var r=A();if(!r)throw new Error("WaaP iframe does not exist on page");var i=S();L(),T(),j(),t.walletConnectProjectId&&E.setProjectId(t.walletConnectProjectId);var o=new _(r.contentWindow,t.referralCode,t.config||{},t.project||{},t.useStaging,t.forceIframe),a=i?"component":"modal";return o.uiMessageManager.on(e.UI_EVENT_NAMES.show_modal,function(){var e=S(),t=e?"component":"modal",n=j();if(t!==a&&n)if(a=t,e){var r=T();r&&r.appendChild(n)}else{var i=L();i||((i=window.document.createElement("div")).id=W,i.style.position="fixed",i.style.top="0",i.style.left="0",i.style.right="0",i.style.bottom="0",i.style.width="100%",i.style.height="100%",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.backgroundColor="rgba(0, 0, 0, 0.5)",i.style.zIndex="99999",window.document.body.appendChild(i)),i.appendChild(n)}var o=L();e&&n?n.style.display="flex":o&&(o.style.display="flex")}),o.uiMessageManager.on(e.UI_EVENT_NAMES.hide_modal,function(){var e=S(),t=j(),n=L();e&&t?t.style.display="none":n&&(n.style.display="none")}),window.silk=o,window.waap=o,o}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@human.tech/waap-constants"),require("events"),require("@human.tech/waap-interface-core"),require("@reown/appkit-adapter-ethers")):"function"==typeof define&&define.amd?define(["exports","@human.tech/waap-constants","events","@human.tech/waap-interface-core","@reown/appkit-adapter-ethers"],t):t((e||self).waapSdk={},e.waapConstants,e.events,e.waapInterfaceCore,e.appkitAdapterEthers)}(this,function(e,t,n,r,i){function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(null,arguments)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function l(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function d(e){var t="function"==typeof Map?new Map:void 0;return d=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(c())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&u(i,n.prototype),i}(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)},d(e)}var f;e.UI_EVENT_NAMES=void 0,(f=e.UI_EVENT_NAMES||(e.UI_EVENT_NAMES={})).show_modal="show_modal",f.hide_modal="hide_modal";var h=/*#__PURE__*/function(e){function t(){return e.call(this)||this}return l(t,e),t}(n.EventEmitter),m=function(e,t,n,r){try{return Promise.resolve(n.postSilkRequest({method:e.method,params:e.params,interactionRequired:t})).then(function(e){return new Promise(function(t,n){r.once(e,function(e){e.error?n(e.error):t(e.data)})})})}catch(e){return Promise.reject(e)}},g={styles:{darkMode:!1}};function p(e,t,n){if(!e.s){if(n instanceof v){if(!n.s)return void(n.o=p.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(p.bind(null,e,t),p.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var v=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{p(r,1,o(this.v))}catch(e){p(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?p(r,1,t?t(i):i):n?p(r,1,n(i)):p(r,2,i)}catch(e){p(r,2,e)}},r},e}();function w(e){return e instanceof v&&1&e.s}var y=/*#__PURE__*/function(){function e(){}return e.setProjectId=function(e){this.projectId=e},e.getProjectIdFromEnv=function(){try{if("undefined"!=typeof process&&process.env)return process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID||process.env.VITE_WALLET_CONNECT_PROJECT_ID||process.env.REACT_APP_WALLET_CONNECT_PROJECT_ID||process.env.WALLET_CONNECT_PROJECT_ID}catch(e){return}},e.getInstance=function(){try{var e=this;return"undefined"==typeof window||"undefined"==typeof document?Promise.resolve(null):Promise.resolve(import("@reown/appkit")).then(function(t){var n=t.createAppKit;return Promise.resolve(import("@reown/appkit/networks")).then(function(t){var r=t.mainnet,o=t.sepolia,a=t.optimism,s=t.arbitrum,l=t.polygon,c=t.gnosis,u=t.avalanche,d=t.aurora,f=t.fantom,h=t.base,m=t.celo;try{var g={name:"Human Wallet",description:"Silk lets you create human keys for web3 wallets that are recoverable with private identity proofs and secured by zero trust protocols.",url:window.location.origin,icons:["https://imagedelivery.net/_aTEfDRm7z3tKgu9JhfeKA/f11f5753-616a-4aa0-2aee-9b75befea700/sm"]},p=e.projectId||e.getProjectIdFromEnv();return p?(e.projectId=p,e.instance||(e.instance=n({adapters:[new i.EthersAdapter],projectId:p,metadata:g,networks:[r,o,s,a,l,c,u,d,f,h,m],features:{socials:!1,email:!1}})),e.instance):(console.error('WalletConnect project ID not found. Please set it using one of these methods:\n1. Pass walletConnectProjectId when calling initSilk\n2. Call SilkWalletConnect.setProjectId("your-project-id")\n3. Set WALLET_CONNECT_PROJECT_ID (NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID for Next projects) environment variable'),null)}catch(e){return console.error("Error importing or initializing WalletConnect:",e),null}})})}catch(e){return Promise.reject(e)}},e.listenToAccountChangeEvent=function(){try{var e=this;return Promise.resolve(new Promise(function(t){e.instance.subscribeAccount(function(e){null!=e&&e.isConnected&&t()})})).then(function(){})}catch(e){return Promise.reject(e)}},e.waitForReadyAndCheckConnection=function(){try{var e=this;if(!e.instance)return Promise.resolve(!1);var t=!1,n=0,r=function(e,t,n){for(var r;;){var i=e();if(w(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!w(o)){r=1;break}o=o.s}}var a=new v,s=p.bind(null,a,2);return(0===r?i.then(c):1===r?o.then(l):(void 0).then(function(){(i=e())?i.then?i.then(c).then(void 0,s):c(i):p(a,1,o)})).then(void 0,s),a;function l(t){o=t;do{if(!(i=e())||w(i)&&!i.v)return void p(a,1,o);if(i.then)return void i.then(c).then(void 0,s);w(o=n())&&(o=o.v)}while(!o||!o.then);o.then(l).then(void 0,s)}function c(e){e?(o=n())&&o.then?o.then(l).then(void 0,s):l(o):p(a,1,o)}}(function(){return!t&&n<15},0,function(){var r=n<5?500:1e3;return Promise.resolve(new Promise(function(e){return setTimeout(e,r)})).then(function(){t=e.instance.getIsConnectedState(),n++,console.log("WalletConnect connection check attempt "+n+": "+t)})});return Promise.resolve(r&&r.then?r.then(function(){return t}):t)}catch(e){return Promise.reject(e)}},e.isConnected=function(){var e,t;return null!=(e=null==(t=this.instance)?void 0:t.getIsConnectedState())&&e},e.getWalletProvider=function(){var e,t;return null!=(e=null==(t=this.instance)?void 0:t.getWalletProvider())?e:null},e}();y.instance=null,y.projectId=void 0,y.chains=[1,10,100,137,8453,43114,42161,42220,84532,11155111];var E=/*#__PURE__*/function(){function e(e,n){this.iframeWindow=null,this.walletOrigin=void 0,this.iframeWindow=e,this.walletOrigin=n?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2}var n=e.prototype;return n.postSilkNotification=function(e){this.iframeWindow.postMessage({target:"silk",messageType:r.SILK_MESSAGE_TYPE.notification,data:e},this.walletOrigin)},n.postReadyNotification=function(){this.postSilkNotification(r.SILK_NOTIFICATION.ready)},n.postConnectNotification=function(){this.postSilkNotification(r.SILK_NOTIFICATION.connect)},n.pingIframe=function(){var e=this;return new Promise(function(t,n){setTimeout(function(){return n("Wallet ping timed out.")},1e4),window.addEventListener("message",function e(n){"silk"===n.data.target&&n.data.messageType===r.SILK_MESSAGE_TYPE.notification&&n.data.data===r.SILK_NOTIFICATION.ready&&(window.removeEventListener("message",e),t())}),e.postReadyNotification()})},n.postSilkRequest=function(e){try{var t=this,n=a({},e,{target:"silk",messageType:r.SILK_MESSAGE_TYPE.request});return Promise.resolve(r.generateMessageId(n)).then(function(e){return t.iframeWindow.postMessage(a({},n,{id:e}),t.walletOrigin),e})}catch(e){return Promise.reject(e)}},n.addListener=function(e){var t=this,n=e.handleResponse,i=e.handleRequest,o=e.onReceiveConnectNotif,a=e.onAccountChanged;window.addEventListener("message",function(e){var s,l,c;try{if("undefined"!=typeof process&&process,e.origin!==t.walletOrigin)return}catch(n){if(e.origin!==t.walletOrigin)return}if((null==(s=e.data)?void 0:s.messageType)===r.SILK_MESSAGE_TYPE.request)i(e.data);else if((null==(l=e.data)?void 0:l.messageType)===r.SILK_MESSAGE_TYPE.response)n(e.data);else if((null==(c=e.data)?void 0:c.messageType)===r.SILK_MESSAGE_TYPE.notification){var u,d;(null==(u=e.data)?void 0:u.data)===r.SILK_NOTIFICATION.connect?null==o||o():(null==(d=e.data)||null==(d=d.data)?void 0:d.type)===r.SILK_NOTIFICATION.account_changed&&a&&a(e.data.data.account)}})},e}();function M(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var _=/*#__PURE__*/function(i){function s(t,s,l,c,u,d){var f;return(f=i.call(this)||this).isSilk=!0,f.isWaaP=!0,f.connected=!1,f.walletMessageManager=void 0,f.uiMessageManager=void 0,f.config=void 0,f.currentAccount=null,f.walletConnectProvider=null,f.persistedMethods=void 0,f.internalEventEmitter=new n.EventEmitter,f.uiMessageManager=new h,f.walletMessageManager=new E(t,!!u),f.config=a({},g,l||{}),f.persistedMethods={login:f.login.bind(o(f)),logout:f.logout.bind(o(f)),getLoginMethod:f.getLoginMethod.bind(o(f)),walletMessageManager:f.walletMessageManager,internalEventEmitter:f.internalEventEmitter,uiMessageManager:f.uiMessageManager,portal:f.portal.bind(o(f)),requestEmail:f.requestEmail.bind(o(f)),requestSBT:f.requestSBT.bind(o(f)),orcid:f.orcid.bind(o(f)),enable:f.enable.bind(o(f)),isConnected:f.isConnected.bind(o(f)),toggleDarkMode:f.toggleDarkMode.bind(o(f)),silkRequest:f.request.bind(o(f)),waaPRequest:f.request.bind(o(f))},f.walletMessageManager.addListener({onReceiveConnectNotif:function(){console.log("onReceiveConnectNotif"),f.connected=!0,f.emit("connect")},handleResponse:function(e){return f.internalEventEmitter.emit(e.id,e)},handleRequest:function(t){t.method===r.SILK_METHOD.show_modal?f.uiMessageManager.emit(e.UI_EVENT_NAMES.show_modal):t.method===r.SILK_METHOD.hide_modal&&f.uiMessageManager.emit(e.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){f.currentAccount!==e&&(f.currentAccount=e,f.emit("accountsChanged",e?[e]:[]))}}),s&&f.walletMessageManager.pingIframe().then(function(){return m({method:r.SILK_METHOD.set_points_referral_code,params:[s]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error setting referral code in Silk iframe:",e)}),c&&f.walletMessageManager.pingIframe().then(function(){return m({method:r.SILK_METHOD.set_project,params:[c,window.location.origin]},!1,f.walletMessageManager,f.internalEventEmitter)}),l&&f.walletMessageManager.pingIframe().then(function(){return m({method:r.SILK_METHOD.set_custom_config,params:[l]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),f}l(s,i);var c=s.prototype;return c.initializeWalletConnect=function(){try{var e=this,t=M(function(){return Promise.resolve(y.getInstance()).then(function(t){e.walletConnectProvider=t,console.log("WalletConnect provider initialized")})},function(t){console.error("Failed to initialize WalletConnect provider:",t),e.walletConnectProvider=null});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},c.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},c.isConnected=function(){return this.connected},c.request=function(e){try{var n=this;return Object.keys(r.JSON_RPC_METHOD).includes(e.method)?Promise.resolve(n.attemptAutoConnect(e.method)).then(function(i){return null!==i?i:function(e){try{var t;if(!e||!Array.isArray(e))return!1;var n=JSON.parse("string"==typeof e[1]?e[1]:JSON.stringify(e[1]));return"SafeTx"===n.primaryType&&void 0!==(null==(t=n.domain)?void 0:t.verifyingContract)&&n.message&&"to"in n.message&&"value"in n.message&&"safeTxGas"in n.message&&"baseGas"in n.message&&"gasPrice"in n.message&&"nonce"in n.message}catch(e){return!1}}(e.params)&&e.method!==r.JSON_RPC_METHOD.eth_signTypedData_v4?Promise.reject({error:"Safe transactions must be signed using eth_signTypedData_v4"}):Promise.resolve(n.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(m(e,t.rpcMethodRequiresUI(e.method),n.walletMessageManager,n.internalEventEmitter)).then(function(t){var i=function(){if((e.method===r.JSON_RPC_METHOD.wallet_switchEthereumChain||e.method===r.JSON_RPC_METHOD.wallet_addEthereumChain)&&null===t){var i;n.emit("chainChanged",null==(i=e.params)||null==(i=i[0])?void 0:i.chainId);var o=M(function(){return Promise.resolve(n.request({method:"eth_accounts"})).then(function(t){var r,i;t&&t.length>0&&(n.currentAccount=t[0],n.emit("accountsChanged",t),n.emit("connect",{chainId:null==(r=e.params)||null==(r=r[0])?void 0:r.chainId}),console.log("[EthereumProvider] Re-emitted accounts and connect after chain switch:",{accounts:t,chainId:null==(i=e.params)||null==(i=i[0])?void 0:i.chainId}))})},function(t){var r;console.warn("[EthereumProvider] Failed to get accounts after chain switch:",t),n.currentAccount&&(n.emit("accountsChanged",[n.currentAccount]),n.emit("connect",{chainId:null==(r=e.params)||null==(r=r[0])?void 0:r.chainId}))});if(o&&o.then)return o.then(function(){})}}();return i&&i.then?i.then(function(){return t}):t})})}):Promise.reject({error:"Not implemented ("+e.method+")"})}catch(e){return Promise.reject(e)}},c.login=function(e){try{var t=function(){var t=e||window.ethereum,i=t&&function(e){return!(null==e||!e.isMetaMask||e.isApexWallet||e.isAvalanche||e.isBitKeep||e.isBlockWallet||e.isMathWallet||e.isOkxWallet||e.isOKExWallet||e.isOneInchIOSWallet||e.isOneInchAndroidWallet||e.isOpera||e.isPortal||e.isRabby||e.isDefiant||e.isTokenPocket||e.isTokenary||e.isZerion)}(t)?"MetaMask":"Browser Wallet";return Promise.resolve(n.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(m({method:r.SILK_METHOD.login,params:[i]},!0,n.walletMessageManager,n.internalEventEmitter)).then(function(e){"string"==typeof e&&e.includes("waap")&&(localStorage.setItem(window.location.origin+"-connected","waap"),n.setupWaaP()),"string"==typeof e&&e.includes("injected")&&t&&(localStorage.setItem(window.location.origin+"-connected","injected"),n.setupInjectedWallet(t));var r=function(){if("string"==typeof e&&e.includes("walletconnect")){var t=function(){var e=y.getWalletProvider();n.setupWalletConnect(e)};localStorage.setItem(window.location.origin+"-connected","walletconnect");var r=function(){if(!y.isConnected())return Promise.resolve(n.walletConnectProvider.open({view:"Connect"})).then(function(){return Promise.resolve(y.listenToAccountChangeEvent()).then(function(){})})}();return r&&r.then?r.then(t):t()}}();return r&&r.then?r.then(function(){return e}):e})})},n=this;if("undefined"==typeof window||"undefined"==typeof document)return Promise.resolve(null);var i=function(e){if(null!=(e=n.config.authenticationMethods)&&e.includes("wallet")&&!n.walletConnectProvider)return Promise.resolve(n.initializeWalletConnect()).then(function(){})}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},c.logout=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){function t(){return m({method:r.SILK_METHOD.logout},!1,e.walletMessageManager,e.internalEventEmitter)}e.cleanupInvalidLoginState();var n=M(function(){var t=function(){if(e.walletConnectProvider)return Promise.resolve(e.walletConnectProvider.disconnect()).then(function(){})}();if(t&&t.then)return t.then(function(){})},function(e){console.error("Error disconnecting from WalletConnect:",e)});return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},c.cleanupInvalidLoginState=function(){try{localStorage.removeItem(window.location.origin+"-connected")}catch(e){console.warn("Could not clean up login state:",e)}},c.setupWaaP=function(){var e=a({},this.persistedMethods,{isWaaP:!0,request:this.request.bind(this)});window.silk=e,window.waap=e},c.setupInjectedWallet=function(e){var t,n,r,i,o,s=a({},this.persistedMethods,e,{isSilk:!0,connected:null!=(t=e.connected)&&t,on:null!=(n=null==(r=e.on)?void 0:r.bind(e))?n:function(){},removeListener:null!=(i=null==(o=e.removeListener)?void 0:o.bind(e))?i:function(){},request:e.request.bind(e)});window.silk=s,window.waap=s},c.setupWalletConnect=function(e){var t,n,r,i,o=a({},this.persistedMethods,e,{isSilk:!0,connected:!0,on:null!=(t=null==(n=e.on)?void 0:n.bind(e))?t:function(){},removeListener:null!=(r=null==(i=e.removeListener)?void 0:i.bind(e))?r:function(){},request:e.request.bind(e)});window.silk=o,window.waap=o},c.setupAutoConnectInjected=function(e){var t,n,r,i,o,s=a({},this.persistedMethods,e,{isSilk:!1,connected:null!=(t=null==e.isConnected?void 0:e.isConnected())&&t,on:null!=(n=null==(r=e.on)?void 0:r.bind(e))?n:function(){},removeListener:null!=(i=null==(o=e.removeListener)?void 0:o.bind(e))?i:function(){},request:e.request.bind(e)});window.silk=s,window.waap=s},c.setupAutoConnectWalletConnect=function(e){var t,n,r,i,o=a({},this.persistedMethods,e,{isSilk:!1,connected:!0,on:null!=(t=null==(n=e.on)?void 0:n.bind(e))?t:function(){},removeListener:null!=(r=null==(i=e.removeListener)?void 0:i.bind(e))?r:function(){},request:e.request.bind(e)});window.silk=o,window.waap=o},c.attemptAutoConnect=function(e){try{var t,n=this;if("eth_requestAccounts"!==e&&"eth_accounts"!==e)return Promise.resolve(null);n.walletMessageManager.pingIframe().then(function(){try{return Promise.resolve(m({method:r.SILK_METHOD.auto_conn,params:[window.location.origin]},!1,n.walletMessageManager,n.internalEventEmitter)).then(function(){})}catch(e){return Promise.reject(e)}});var i=n.getLoginMethod(),o=function(){if("injected"!==i||!window.ethereum)return function(){if("walletconnect"===i)return M(function(){function e(){return Promise.resolve(y.waitForReadyAndCheckConnection()).then(function(e){if(e){var r=y.getWalletProvider();n.setupAutoConnectWalletConnect(r);var i=r.request({method:"eth_requestAccounts"});return t=1,i}return console.log("WalletConnect not connected, cleaning up and falling through to normal flow"),n.cleanupInvalidLoginState(),t=1,null})}var r=function(){if(!n.walletConnectProvider)return Promise.resolve(y.getInstance()).then(function(e){n.walletConnectProvider=e})}();return r&&r.then?r.then(e):e()},function(e){return console.warn("WalletConnect auto-connect failed:",e),n.cleanupInvalidLoginState(),t=1,null})}();try{n.setupAutoConnectInjected(window.ethereum);var e=window.ethereum.request({method:"eth_requestAccounts"});return t=1,e}catch(e){return console.warn("Injected wallet auto-connect failed:",e),n.cleanupInvalidLoginState(),t=1,null}}();return Promise.resolve(o&&o.then?o.then(function(e){return t?e:null}):t?o:null)}catch(e){return Promise.reject(e)}},c.getLoginMethod=function(){if("undefined"==typeof window||"undefined"==typeof localStorage)return null;try{var e=localStorage.getItem(window.location.origin+"-connected");if(!e)return null;if(!["waap","human","injected","walletconnect"].includes(e))return this.cleanupInvalidLoginState(),null;switch(e){case"injected":return window.ethereum?"injected":(this.cleanupInvalidLoginState(),null);case"walletconnect":try{return y.isConnected()?"walletconnect":(this.cleanupInvalidLoginState(),null)}catch(e){return this.cleanupInvalidLoginState(),null}case"waap":return"waap";case"human":return"human";default:return this.cleanupInvalidLoginState(),null}}catch(e){return console.warn("Error checking login method:",e),this.cleanupInvalidLoginState(),null}},c.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,e.walletMessageManager.pingIframe().then(function(){return m({method:r.SILK_METHOD.set_custom_config,params:[e.config]},!1,e.walletMessageManager,e.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),Promise.resolve()}catch(e){return Promise.reject(e)}},c.safe=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return m({method:r.SILK_METHOD.safe},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},c.orcid=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return m({method:r.SILK_METHOD.orcid},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},c.portal=function(e,t,n){try{var i=this;return Promise.resolve(i.walletMessageManager.pingIframe()).then(function(){var o;switch(t){case"get":o="gastank"===e?r.SILK_METHOD.gastank_get_settings:r.SILK_METHOD.customization_get;break;case"update":o="gastank"===e?r.SILK_METHOD.gastank_update_settings:r.SILK_METHOD.customization_update;break;case"topup":o=r.SILK_METHOD.gastank_topup;break;case"init":o=r.SILK_METHOD.project_init}return m({method:o,params:[n,window.location.origin]},"get"!==t&&"customization"!==e,i.walletMessageManager,i.internalEventEmitter)})}catch(e){return Promise.reject(e)}},c.requestEmail=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return m({method:r.SILK_METHOD.silk_requestEmail},!0,e.walletMessageManager,e.internalEventEmitter)})}catch(e){return Promise.reject(e)}},c.requestSBT=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return m({method:r.SILK_METHOD.silk_requestSbt,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},s}(n.EventEmitter),I="waap-wallet",P="waap-component-container",C="undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof HTMLElement;function S(){return!(!C||!document.getElementById(P)&&!document.querySelector(I))}function T(){return C?document.getElementById(P)||document.querySelector(I):null}e.WaaP=void 0,C?(e.WaaP=/*#__PURE__*/function(e){function t(){var t;return(t=e.call(this)||this).style.display&&""!==t.style.display||(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center"),t.style.width&&""!==t.style.width||(t.style.width="100%"),t.style.height&&""!==t.style.height||(t.style.height="100%"),t.id=P,t}l(t,e);var n=t.prototype;return n.connectedCallback=function(){this.setAttribute("data-waap-mounted","true")},n.disconnectedCallback=function(){this.removeAttribute("data-waap-mounted")},t}(/*#__PURE__*/d(HTMLElement)),"undefined"==typeof customElements||customElements.get(I)||customElements.define(I,e.WaaP)):e.WaaP=function(){};var O="waap-wallet-iframe-container",b="waap-wallet-iframe-wrapper",k="waap-wallet-iframe",L=function(){return document.getElementById(O)||document.getElementById("silk-wallet-iframe-container")},j=function(){return document.getElementById(b)||document.getElementById("silk-wallet-iframe-wrapper")},A=function(){return document.getElementById(k)||document.getElementById("silk-wallet-iframe")},W=O,N=b,q=k,D=function(e){var n=window.document.createElement("iframe");return n.id=q,n.src=(e?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2)+"/iframe",console.log("iframe.src: ",n.src),n.style.width="100%",n.style.height="100%",n.style.border="none",n.style.borderRadius="24px",n.style.backgroundColor="transparent",n.style.background="transparent",n.style.padding="0",n.style.margin="0",n},R=function(e,n){var r=function(n){if(n.origin===(e?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2)&&n.data&&"object"==typeof n.data&&"silk-iframe-size"===n.data.type){var r=n.data.height,i=n.data.width;if("number"==typeof r&&"number"==typeof i&&!(r<50||r>2e3)&&!(i<50||i>2e3)&&Number.isFinite(r)&&Number.isFinite(i)){var o=j();o&&(o.style.height=Math.floor(r)+"px",o.style.width=Math.floor(i)+"px")}}};window.addEventListener("message",r),n.__silkCleanup=function(){window.removeEventListener("message",r)}},K=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this)||this).isSilk=!0,n.connected=!1,n.config=void 0,n.config=a({},g,t||{}),n}l(t,e);var n=t.prototype;return n.sendToExtension=function(e){return new Promise(function(t,n){window.postMessage({type:"FROM_PAGE",request:e},"*"),window.addEventListener("message",function(e){"FROM_EXTENSION"===e.data.type&&(e.data.error?n(e.data.error):t(e.data.result))})})},n.request=function(e){try{var t=this;return Object.keys(r.JSON_RPC_METHOD).includes(e.method)?Promise.resolve(t.sendToExtension(e)).then(function(n){var i;return e.method!==r.JSON_RPC_METHOD.wallet_switchEthereumChain&&e.method!==r.JSON_RPC_METHOD.wallet_addEthereumChain||null!==n||t.emit("chainChanged",null==(i=e.params)||null==(i=i[0])?void 0:i.chainId),n}):Promise.reject({error:"Not implemented ("+e.method+")"})}catch(e){return Promise.reject(e)}},n.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},n.isConnected=function(){return this.connected},n.login=function(){try{return Promise.resolve(this.sendToExtension({method:r.SILK_METHOD.login}))}catch(e){return Promise.reject(e)}},n.requestSBT=function(e){try{return Promise.resolve(this.sendToExtension({method:r.SILK_METHOD.silk_requestSbt,params:[e]}))}catch(e){return Promise.reject(e)}},n.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,Promise.resolve(e.sendToExtension({method:r.SILK_METHOD.set_custom_config,params:[e.config]})).then(function(){})}catch(e){return Promise.reject(e)}},n.safe=function(){try{return Promise.resolve(this.sendToExtension({method:r.SILK_METHOD.safe}))}catch(e){return Promise.reject(e)}},t}(n.EventEmitter);Object.defineProperty(e,"rpcMethodRequiresUI",{enumerable:!0,get:function(){return t.rpcMethodRequiresUI}}),Object.defineProperty(e,"SILK_METHOD",{enumerable:!0,get:function(){return r.SILK_METHOD}}),Object.defineProperty(e,"WAAP_METHOD",{enumerable:!0,get:function(){return r.SILK_METHOD}}),e.EthereumProvider=_,e.EthereumProviderExtension=K,e.SilkWalletConnect=y,e.UIMessageManager=h,e.WaaPWalletConnect=y,e.WalletMessageManager=E,e.handleWalletRequestAndResponse=m,e.initWaaP=function(t){var n;void 0===t&&(t={}),n=!!t.useStaging,S()?function(e){var t=T();if(!t)throw new Error("WaaP component not found in DOM");if(!A()){var n=window.document.createElement("div");n.id=N,n.style.position="relative",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.padding="0",n.style.margin="0",n.style.height="600px",n.style.width="380px";var r=D(e);R(e,r),setTimeout(function(){var e=j();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),t.appendChild(n)}}(n):function(e){if(!L()){var t=window.document.createElement("div");t.id=W,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.right="0",t.style.bottom="0",t.style.width="100%",t.style.height="100%",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.backgroundColor="rgba(0, 0, 0, 0.5)",t.style.zIndex="99999",t.style.display="none";var n=window.document.createElement("div");n.id=N,n.style.position="relative",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.padding="0",n.style.margin="0",n.style.height="600px",n.style.width="380px",t.appendChild(n);var r=D(e);R(e,r),setTimeout(function(){var e=j();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),window.document.body.appendChild(t)}}(n);var r=A();if(!r)throw new Error("WaaP iframe does not exist on page");var i=S();t.walletConnectProjectId&&y.setProjectId(t.walletConnectProjectId);var o=new _(r.contentWindow,t.referralCode,t.config||{},t.project||{},t.useStaging),a=i?"component":"modal";return o.uiMessageManager.on(e.UI_EVENT_NAMES.show_modal,function(){var e=S(),t=e?"component":"modal",n=j();if(t!==a&&n)if(a=t,e){var r=T();r&&r.appendChild(n)}else{var i=L();i||((i=window.document.createElement("div")).id=W,i.style.position="fixed",i.style.top="0",i.style.left="0",i.style.right="0",i.style.bottom="0",i.style.width="100%",i.style.height="100%",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.backgroundColor="rgba(0, 0, 0, 0.5)",i.style.zIndex="99999",window.document.body.appendChild(i)),i.appendChild(n)}var o=L();e&&n?n.style.display="flex":o&&(o.style.display="flex")}),o.uiMessageManager.on(e.UI_EVENT_NAMES.hide_modal,function(){var e=S(),t=j(),n=L();e&&t?t.style.display="none":n&&(n.style.display="none")}),window.silk=o,window.waap=o,o}});
2
2
  //# sourceMappingURL=index.umd.js.map