@human.tech/waap-sdk 1.0.2 → 1.0.4-staging.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.
@@ -0,0 +1,76 @@
1
+ import type { AsyncSignPendingEvent, Async2faRequiredEvent, AsyncSignCompleteEvent, AsyncSignFailedEvent, AsyncTxPendingEvent, AsyncTxConfirmedEvent, AsyncTxFailedEvent, AsyncTxResponse } from '@human.tech/waap-interface-core';
2
+ import type { RequestArguments } from '../lib/provider/types.js';
3
+ /**
4
+ * Transaction state tracked by the hook
5
+ */
6
+ interface TxState {
7
+ status: 'pending' | 'signing' | '2fa' | 'signed' | 'tx_pending' | 'confirmed' | 'failed';
8
+ pendingTxId: string;
9
+ txRequest?: AsyncSignPendingEvent['txRequest'];
10
+ signature?: string;
11
+ serializedTx?: string | null;
12
+ txHash?: string;
13
+ receipt?: AsyncTxConfirmedEvent['receipt'];
14
+ error?: string;
15
+ stage?: AsyncTxFailedEvent['stage'];
16
+ }
17
+ /**
18
+ * Options for useWaapTransaction hook
19
+ */
20
+ interface UseWaapTransactionOptions {
21
+ onPending?: (event: AsyncSignPendingEvent) => void;
22
+ on2faRequired?: (event: Async2faRequiredEvent) => void;
23
+ onSigned?: (event: AsyncSignCompleteEvent) => void;
24
+ onSignFailed?: (event: AsyncSignFailedEvent) => void;
25
+ onTxPending?: (event: AsyncTxPendingEvent) => void;
26
+ onConfirmed?: (event: AsyncTxConfirmedEvent) => void;
27
+ onFailed?: (event: AsyncTxFailedEvent) => void;
28
+ }
29
+ /**
30
+ * Return type for useWaapTransaction hook
31
+ */
32
+ interface UseWaapTransactionReturn {
33
+ /**
34
+ * Send a transaction using eth_sendTransaction
35
+ * Returns immediately with pendingTxId when asyncSigning is enabled
36
+ */
37
+ sendTransaction: (txRequest: RequestArguments['params']) => Promise<string | AsyncTxResponse>;
38
+ /**
39
+ * Sign a transaction without broadcasting using eth_signTransaction
40
+ * Returns immediately with pendingTxId when asyncSigning is enabled
41
+ */
42
+ signTransaction: (txRequest: RequestArguments['params']) => Promise<string | AsyncTxResponse>;
43
+ /**
44
+ * Map of pending transaction IDs to their current state
45
+ */
46
+ pendingTransactions: Map<string, TxState>;
47
+ /**
48
+ * Whether there are any pending transactions
49
+ */
50
+ isAnyPending: boolean;
51
+ }
52
+ /**
53
+ * React hook for handling async transaction signing with WaaP SDK.
54
+ *
55
+ * This hook provides:
56
+ * - sendTransaction/signTransaction methods that work with asyncSigning mode
57
+ * - State tracking for pending transactions
58
+ * - Callbacks for transaction lifecycle events
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * const { sendTransaction, pendingTransactions, isAnyPending } = useWaapTransaction({
63
+ * onPending: ({ pendingTxId }) => console.log('Pending:', pendingTxId),
64
+ * onSigned: ({ txHash }) => console.log('Signed:', txHash),
65
+ * onConfirmed: ({ receipt }) => console.log('Confirmed:', receipt),
66
+ * onFailed: ({ error }) => console.error('Failed:', error)
67
+ * });
68
+ *
69
+ * const handleSend = async () => {
70
+ * const result = await sendTransaction([{ to: '0x...', value: '0x...' }]);
71
+ * // When asyncSigning=true, result is { pendingTxId, status: 'pending' }
72
+ * };
73
+ * ```
74
+ */
75
+ export declare function useWaapTransaction(options?: UseWaapTransactionOptions): UseWaapTransactionReturn;
76
+ export type { TxState, UseWaapTransactionOptions, UseWaapTransactionReturn };
package/dist/index.d.ts CHANGED
@@ -9,3 +9,5 @@ export { EthereumProvider } from './lib/provider/EthereumProvider.js';
9
9
  export { rpcMethodRequiresUI, handleWalletRequestAndResponse } from './lib/provider/requests.js';
10
10
  export { UI_EVENT_NAMES } from './lib/UIMessageManager.js';
11
11
  export { CredentialType, SILK_METHOD, SILK_METHOD as WAAP_METHOD, SocialProvider, AuthenticationMethod, ProjectConfig, StylesConfig } from '@human.tech/waap-interface-core';
12
+ export { useWaapTransaction, type TxState, type UseWaapTransactionOptions, type UseWaapTransactionReturn } from './hooks/useWaapTransaction.js';
13
+ export type { AsyncEventType, AsyncSignPendingEvent, Async2faRequiredEvent, AsyncSignCompleteEvent, AsyncSignFailedEvent, AsyncTxPendingEvent, AsyncTxConfirmedEvent, AsyncTxFailedEvent, AsyncEvent, AsyncTxResponse, SilkOptions } from '@human.tech/waap-interface-core';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("@human.tech/waap-constants"),t=require("events"),n=require("@human.tech/waap-interface-core"),r=require("@reown/appkit-adapter-ethers");function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}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 t(t,n){this.iframeWindow=null,this.walletOrigin=void 0,this.iframeWindow=t,this.walletOrigin=n?e.silkWalletAppOrigin2Staging:e.silkWalletAppOrigin2}var r=t.prototype;return r.postSilkNotification=function(e){this.iframeWindow.postMessage({target:"silk",messageType:n.SILK_MESSAGE_TYPE.notification,data:e},this.walletOrigin)},r.postReadyNotification=function(){this.postSilkNotification(n.SILK_NOTIFICATION.ready)},r.postConnectNotification=function(){this.postSilkNotification(n.SILK_NOTIFICATION.connect)},r.pingIframe=function(){var e=this;return new Promise(function(t,r){setTimeout(function(){return r("Wallet ping timed out.")},1e4),window.addEventListener("message",function e(r){"silk"===r.data.target&&r.data.messageType===n.SILK_MESSAGE_TYPE.notification&&r.data.data===n.SILK_NOTIFICATION.ready&&(window.removeEventListener("message",e),t())}),e.postReadyNotification()})},r.postSilkRequest=function(e){try{var t=this,r=a({},e,{target:"silk",messageType:n.SILK_MESSAGE_TYPE.request});return Promise.resolve(n.generateMessageId(r)).then(function(e){return t.iframeWindow.postMessage(a({},r,{id:e}),t.walletOrigin),e})}catch(e){return Promise.reject(e)}},r.addListener=function(e){var t=this,r=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)===n.SILK_MESSAGE_TYPE.request)i(e.data);else if((null==(l=e.data)?void 0:l.messageType)===n.SILK_MESSAGE_TYPE.response)r(e.data);else if((null==(c=e.data)?void 0:c.messageType)===n.SILK_MESSAGE_TYPE.notification){var u,d;(null==(u=e.data)?void 0:u.data)===n.SILK_NOTIFICATION.connect?null==o||o():(null==(d=e.data)||null==(d=d.data)?void 0:d.type)===n.SILK_NOTIFICATION.account_changed&&a&&a(e.data.data.account)}})},t}();exports.UI_EVENT_NAMES=void 0,(f=exports.UI_EVENT_NAMES||(exports.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}(t.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(Promise.resolve().then(function(){/*#__PURE__*/return i(require("@reown/appkit"))})).then(function(t){var n=t.createAppKit;return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return i(require("@reown/appkit/networks"))})).then(function(t){var i=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 r.EthersAdapter],projectId:p,metadata:g,networks:[i,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(r){function i(e,i,s,l,c,u){var d;return(d=r.call(this)||this).isSilk=!0,d.isWaaP=!0,d.connected=!1,d.walletMessageManager=void 0,d.uiMessageManager=void 0,d.config=void 0,d.currentAccount=null,d.walletConnectProvider=null,d.persistedMethods=void 0,d.internalEventEmitter=new t.EventEmitter,d.uiMessageManager=new m,d.walletMessageManager=new h(e,!!c),d.config=a({},p,s||{}),d.persistedMethods={login:d.login.bind(o(d)),logout:d.logout.bind(o(d)),getLoginMethod:d.getLoginMethod.bind(o(d)),walletMessageManager:d.walletMessageManager,internalEventEmitter:d.internalEventEmitter,uiMessageManager:d.uiMessageManager,portal:d.portal.bind(o(d)),requestEmail:d.requestEmail.bind(o(d)),requestSBT:d.requestSBT.bind(o(d)),orcid:d.orcid.bind(o(d)),enable:d.enable.bind(o(d)),isConnected:d.isConnected.bind(o(d)),toggleDarkMode:d.toggleDarkMode.bind(o(d)),silkRequest:d.request.bind(o(d)),waaPRequest:d.request.bind(o(d))},d.walletMessageManager.addListener({onReceiveConnectNotif:function(){console.log("onReceiveConnectNotif"),d.connected=!0,d.emit("connect")},handleResponse:function(e){return d.internalEventEmitter.emit(e.id,e)},handleRequest:function(e){e.method===n.SILK_METHOD.show_modal?d.uiMessageManager.emit(exports.UI_EVENT_NAMES.show_modal):e.method===n.SILK_METHOD.hide_modal&&d.uiMessageManager.emit(exports.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){d.currentAccount!==e&&(d.currentAccount=e,d.emit("accountsChanged",e?[e]:[]))}}),i&&d.walletMessageManager.pingIframe().then(function(){return g({method:n.SILK_METHOD.set_points_referral_code,params:[i]},!1,d.walletMessageManager,d.internalEventEmitter)}).catch(function(e){console.error("Error setting referral code in Silk iframe:",e)}),l&&d.walletMessageManager.pingIframe().then(function(){return g({method:n.SILK_METHOD.set_project,params:[l,window.location.origin]},!1,d.walletMessageManager,d.internalEventEmitter)}),s&&d.walletMessageManager.pingIframe().then(function(){return g({method:n.SILK_METHOD.set_custom_config,params:[s]},!1,d.walletMessageManager,d.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),u&&d.walletMessageManager.pingIframe().then(function(){return g({method:n.SILK_METHOD.force_iframe,params:[!0]},!1,d.walletMessageManager,d.internalEventEmitter)}).catch(function(e){console.error("Error forcing iframe in Silk iframe:",e)}),d}l(i,r);var s=i.prototype;return s.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)}},s.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},s.isConnected=function(){return this.connected},s.request=function(t){try{var r=this;return Object.keys(n.JSON_RPC_METHOD).includes(t.method)?Promise.resolve(r.attemptAutoConnect(t.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}}(t.params)&&t.method!==n.JSON_RPC_METHOD.eth_signTypedData_v4?Promise.reject({error:"Safe transactions must be signed using eth_signTypedData_v4"}):Promise.resolve(r.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(g(t,e.rpcMethodRequiresUI(t.method),r.walletMessageManager,r.internalEventEmitter)).then(function(e){var i=function(){if((t.method===n.JSON_RPC_METHOD.wallet_switchEthereumChain||t.method===n.JSON_RPC_METHOD.wallet_addEthereumChain)&&null===e){var i;r.emit("chainChanged",null==(i=t.params)||null==(i=i[0])?void 0:i.chainId);var o=M(function(){return Promise.resolve(r.request({method:"eth_accounts"})).then(function(e){var n,i;e&&e.length>0&&(r.currentAccount=e[0],r.emit("accountsChanged",e),r.emit("connect",{chainId:null==(n=t.params)||null==(n=n[0])?void 0:n.chainId}),console.log("[EthereumProvider] Re-emitted accounts and connect after chain switch:",{accounts:e,chainId:null==(i=t.params)||null==(i=i[0])?void 0:i.chainId}))})},function(e){var n;console.warn("[EthereumProvider] Failed to get accounts after chain switch:",e),r.currentAccount&&(r.emit("accountsChanged",[r.currentAccount]),r.emit("connect",{chainId:null==(n=t.params)||null==(n=n[0])?void 0:n.chainId}))});if(o&&o.then)return o.then(function(){})}}();return i&&i.then?i.then(function(){return e}):e})})}):Promise.reject({error:"Not implemented ("+t.method+")"})}catch(e){return Promise.reject(e)}},s.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(r.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(g({method:n.SILK_METHOD.login,params:[i]},!0,r.walletMessageManager,r.internalEventEmitter)).then(function(e){"string"==typeof e&&e.includes("waap")&&(localStorage.setItem(window.location.origin+"-connected","waap"),r.setupWaaP()),"string"==typeof e&&e.includes("injected")&&t&&(localStorage.setItem(window.location.origin+"-connected","injected"),r.setupInjectedWallet(t));var n=function(){if("string"==typeof e&&e.includes("walletconnect")){var t=function(){var e=E.getWalletProvider();r.setupWalletConnect(e)};localStorage.setItem(window.location.origin+"-connected","walletconnect");var n=function(){if(!E.isConnected())return Promise.resolve(r.walletConnectProvider.open({view:"Connect"})).then(function(){return Promise.resolve(E.listenToAccountChangeEvent()).then(function(){})})}();return n&&n.then?n.then(t):t()}}();return n&&n.then?n.then(function(){return e}):e})})},r=this;if("undefined"==typeof window||"undefined"==typeof document)return Promise.resolve(null);var i=function(e){if(null!=(e=r.config.authenticationMethods)&&e.includes("wallet")&&!r.walletConnectProvider)return Promise.resolve(r.initializeWalletConnect()).then(function(){})}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},s.logout=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){function t(){return g({method:n.SILK_METHOD.logout},!1,e.walletMessageManager,e.internalEventEmitter)}e.cleanupInvalidLoginState();var r=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 r&&r.then?r.then(t):t()})}catch(e){return Promise.reject(e)}},s.cleanupInvalidLoginState=function(){try{localStorage.removeItem(window.location.origin+"-connected")}catch(e){console.warn("Could not clean up login state:",e)}},s.setupWaaP=function(){var e=a({},this.persistedMethods,{isWaaP:!0,request:this.request.bind(this)});window.silk=e,window.waap=e},s.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},s.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},s.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},s.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},s.attemptAutoConnect=function(e){try{var t,r=this;if("eth_requestAccounts"!==e&&"eth_accounts"!==e)return Promise.resolve(null);r.walletMessageManager.pingIframe().then(function(){try{return Promise.resolve(g({method:n.SILK_METHOD.auto_conn,params:[window.location.origin]},!1,r.walletMessageManager,r.internalEventEmitter)).then(function(){})}catch(e){return Promise.reject(e)}});var i=r.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 n=E.getWalletProvider();r.setupAutoConnectWalletConnect(n);var i=n.request({method:"eth_requestAccounts"});return t=1,i}return console.log("WalletConnect not connected, cleaning up and falling through to normal flow"),r.cleanupInvalidLoginState(),t=1,null})}var n=function(){if(!r.walletConnectProvider)return Promise.resolve(E.getInstance()).then(function(e){r.walletConnectProvider=e})}();return n&&n.then?n.then(e):e()},function(e){return console.warn("WalletConnect auto-connect failed:",e),r.cleanupInvalidLoginState(),t=1,null})}();try{r.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),r.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)}},s.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}},s.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,e.walletMessageManager.pingIframe().then(function(){return g({method:n.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)}},s.safe=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return g({method:n.SILK_METHOD.safe},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},s.orcid=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return g({method:n.SILK_METHOD.orcid},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},s.portal=function(e,t,r){try{var i=this;return Promise.resolve(i.walletMessageManager.pingIframe()).then(function(){var o;switch(t){case"get":o="gastank"===e?n.SILK_METHOD.gastank_get_settings:n.SILK_METHOD.customization_get;break;case"update":o="gastank"===e?n.SILK_METHOD.gastank_update_settings:n.SILK_METHOD.customization_update;break;case"topup":o=n.SILK_METHOD.gastank_topup;break;case"init":o=n.SILK_METHOD.project_init}return g({method:o,params:[r,window.location.origin]},"get"!==t&&"customization"!==e,i.walletMessageManager,i.internalEventEmitter)})}catch(e){return Promise.reject(e)}},s.requestEmail=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return g({method:n.SILK_METHOD.silk_requestEmail},!0,e.walletMessageManager,e.internalEventEmitter)})}catch(e){return Promise.reject(e)}},s.requestSBT=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return g({method:n.SILK_METHOD.silk_requestSbt,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},i}(t.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 O(){return C?document.getElementById(P)||document.querySelector(I):null}exports.WaaP=void 0,C?(exports.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,exports.WaaP)):exports.WaaP=function(){};var T="waap-wallet-iframe-container",b="waap-wallet-iframe-wrapper",k="waap-wallet-iframe",L=function(){return document.getElementById(T)||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=T,N=b,x=k,q=function(t){var n=window.document.createElement("iframe");return n.id=x,n.src=(t?e.silkWalletAppOrigin2Staging:e.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},D=function(t,n){var r=function(n){if(n.origin===(t?e.silkWalletAppOrigin2Staging:e.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)}},R=/*#__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 r=t.prototype;return r.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))})})},r.request=function(e){try{var t=this;return Object.keys(n.JSON_RPC_METHOD).includes(e.method)?Promise.resolve(t.sendToExtension(e)).then(function(r){var i;return e.method!==n.JSON_RPC_METHOD.wallet_switchEthereumChain&&e.method!==n.JSON_RPC_METHOD.wallet_addEthereumChain||null!==r||t.emit("chainChanged",null==(i=e.params)||null==(i=i[0])?void 0:i.chainId),r}):Promise.reject({error:"Not implemented ("+e.method+")"})}catch(e){return Promise.reject(e)}},r.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},r.isConnected=function(){return this.connected},r.login=function(){try{return Promise.resolve(this.sendToExtension({method:n.SILK_METHOD.login}))}catch(e){return Promise.reject(e)}},r.requestSBT=function(e){try{return Promise.resolve(this.sendToExtension({method:n.SILK_METHOD.silk_requestSbt,params:[e]}))}catch(e){return Promise.reject(e)}},r.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,Promise.resolve(e.sendToExtension({method:n.SILK_METHOD.set_custom_config,params:[e.config]})).then(function(){})}catch(e){return Promise.reject(e)}},r.safe=function(){try{return Promise.resolve(this.sendToExtension({method:n.SILK_METHOD.safe}))}catch(e){return Promise.reject(e)}},t}(t.EventEmitter);Object.defineProperty(exports,"rpcMethodRequiresUI",{enumerable:!0,get:function(){return e.rpcMethodRequiresUI}}),Object.defineProperty(exports,"SILK_METHOD",{enumerable:!0,get:function(){return n.SILK_METHOD}}),Object.defineProperty(exports,"WAAP_METHOD",{enumerable:!0,get:function(){return n.SILK_METHOD}}),exports.EthereumProvider=_,exports.EthereumProviderExtension=R,exports.SilkWalletConnect=E,exports.UIMessageManager=m,exports.WaaPWalletConnect=E,exports.WalletMessageManager=h,exports.handleWalletRequestAndResponse=g,exports.initWaaP=function(e){var t;void 0===e&&(e={}),t=!!e.useStaging,S()?function(e){var t=O();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=q(e);D(e,r),setTimeout(function(){var e=j();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),t.appendChild(n)}}(t):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=q(e);D(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)}}(t);var n=A();if(!n)throw new Error("WaaP iframe does not exist on page");var r=S();L(),O(),j(),e.walletConnectProjectId&&E.setProjectId(e.walletConnectProjectId);var i=new _(n.contentWindow,e.referralCode,e.config||{},e.project||{},e.useStaging,e.forceIframe),o=r?"component":"modal";return i.uiMessageManager.on(exports.UI_EVENT_NAMES.show_modal,function(){var e=S(),t=e?"component":"modal",n=j();if(t!==o&&n)if(o=t,e){var r=O();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 a=L();e&&n?n.style.display="flex":a&&(a.style.display="flex")}),i.uiMessageManager.on(exports.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=i,window.waap=i,i};
1
+ var e,t=require("@human.tech/waap-constants"),n=require("events"),r=require("@human.tech/waap-interface-core"),i=require("@reown/appkit-adapter-ethers"),o=require("react");function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}function s(){return s=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},s.apply(null,arguments)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function f(e){var t="function"==typeof Map?new Map:void 0;return f=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(u())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&d(i,n.prototype),i}(e,arguments,l(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),d(n,e)},f(e)}exports.UI_EVENT_NAMES=void 0,(e=exports.UI_EVENT_NAMES||(exports.UI_EVENT_NAMES={})).show_modal="show_modal",e.hide_modal="hide_modal";var p=/*#__PURE__*/function(e){function t(){return e.call(this)||this}return c(t,e),t}(n.EventEmitter),h=function(e,t,n,r,i){try{return Promise.resolve(n.postSilkRequest({method:e.method,params:e.params,interactionRequired:t,silkOptions:i})).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)}},m={styles:{darkMode:!1}};function g(e,t,n){if(!e.s){if(n instanceof v){if(!n.s)return void(n.o=g.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(g.bind(null,e,t),g.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{g(r,1,o(this.v))}catch(e){g(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?g(r,1,t?t(i):i):n?g(r,1,n(i)):g(r,2,i)}catch(e){g(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(Promise.resolve().then(function(){/*#__PURE__*/return a(require("@reown/appkit"))})).then(function(t){var n=t.createAppKit;return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("@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,p=t.base,h=t.celo;try{var m={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"]},g=e.projectId||e.getProjectIdFromEnv();return g?(e.projectId=g,e.instance||(e.instance=n({adapters:[new i.EthersAdapter],projectId:g,metadata:m,networks:[r,o,s,a,l,c,u,d,f,p,h],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=g.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):g(a,1,o)})).then(void 0,s),a;function l(t){o=t;do{if(!(i=e())||w(i)&&!i.v)return void g(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):g(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 _=["silkOptions"],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);var i=function(e){"silk"===e.data.target&&e.data.messageType===r.SILK_MESSAGE_TYPE.notification&&e.data.data===r.SILK_NOTIFICATION.ready&&(window.removeEventListener("message",i),t())};window.addEventListener("message",i),e.postReadyNotification()})},n.postSilkRequest=function(e){try{var t=this,n=e.silkOptions,i=s({},function(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(-1!==t.indexOf(r))continue;n[r]=e[r]}return n}(e,_),{target:"silk",messageType:r.SILK_MESSAGE_TYPE.request},n&&{silkOptions:n});return Promise.resolve(r.generateMessageId(i)).then(function(e){return t.iframeWindow.postMessage(s({},i,{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,s=e.onAsyncTxNotification;window.addEventListener("message",function(e){var l,c,u;try{if("undefined"!=typeof process&&process,e.origin!==t.walletOrigin)return}catch(n){if(e.origin!==t.walletOrigin)return}if((null==(l=e.data)?void 0:l.messageType)===r.SILK_MESSAGE_TYPE.request)i(e.data);else if((null==(c=e.data)?void 0:c.messageType)===r.SILK_MESSAGE_TYPE.response)n(e.data);else if((null==(u=e.data)?void 0:u.messageType)===r.SILK_MESSAGE_TYPE.notification){var d,f,p,h,m;(null==(d=e.data)?void 0:d.data)===r.SILK_NOTIFICATION.connect?null==o||o():(null==(f=e.data)||null==(f=f.data)?void 0:f.type)===r.SILK_NOTIFICATION.account_changed&&a?a(e.data.data.account):(null!=(p=e.data)&&null!=(p=p.data)&&null!=(p=p.type)&&p.startsWith("waap_sign_")||null!=(h=e.data)&&null!=(h=h.data)&&null!=(h=h.type)&&h.startsWith("waap_2fa_")||null!=(m=e.data)&&null!=(m=m.data)&&null!=(m=m.type)&&m.startsWith("waap_tx_"))&&s&&s({type:e.data.data.type,payload:e.data.data.payload})}})},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 P=/*#__PURE__*/function(e){function i(t,i,o,a,l,c){var u;return void 0===c&&(c=!1),(u=e.call(this)||this).isSilk=!0,u.isWaaP=!0,u.connected=!1,u.walletMessageManager=void 0,u.uiMessageManager=void 0,u.config=void 0,u.currentAccount=null,u.walletConnectProvider=null,u.asyncSigning=!1,u.persistedMethods=void 0,u.internalEventEmitter=new n.EventEmitter,u.asyncSigning=c,u.uiMessageManager=new p,u.walletMessageManager=new E(t,!!l),u.config=s({},m,o||{}),u.persistedMethods={login:u.login.bind(u),logout:u.logout.bind(u),getLoginMethod:u.getLoginMethod.bind(u),walletMessageManager:u.walletMessageManager,internalEventEmitter:u.internalEventEmitter,uiMessageManager:u.uiMessageManager,portal:u.portal.bind(u),requestEmail:u.requestEmail.bind(u),requestSBT:u.requestSBT.bind(u),orcid:u.orcid.bind(u),enable:u.enable.bind(u),isConnected:u.isConnected.bind(u),toggleDarkMode:u.toggleDarkMode.bind(u),silkRequest:u.request.bind(u),waaPRequest:u.request.bind(u)},u.walletMessageManager.addListener({onReceiveConnectNotif:function(){console.log("onReceiveConnectNotif"),u.connected=!0,u.emit("connect")},handleResponse:function(e){return u.internalEventEmitter.emit(e.id,e)},handleRequest:function(e){e.method===r.SILK_METHOD.show_modal?u.uiMessageManager.emit(exports.UI_EVENT_NAMES.show_modal):e.method===r.SILK_METHOD.hide_modal&&u.uiMessageManager.emit(exports.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){u.currentAccount!==e&&(u.currentAccount=e,u.emit("accountsChanged",e?[e]:[]))},onAsyncTxNotification:function(e){u.emit(e.type,e.payload)}}),i&&u.walletMessageManager.pingIframe().then(function(){return h({method:r.SILK_METHOD.set_points_referral_code,params:[i]},!1,u.walletMessageManager,u.internalEventEmitter)}).catch(function(e){console.error("Error setting referral code in Silk iframe:",e)}),a&&u.walletMessageManager.pingIframe().then(function(){return h({method:r.SILK_METHOD.set_project,params:[a,window.location.origin]},!1,u.walletMessageManager,u.internalEventEmitter)}),o&&u.walletMessageManager.pingIframe().then(function(){return h({method:r.SILK_METHOD.set_custom_config,params:[o]},!1,u.walletMessageManager,u.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),u}c(i,e);var o=i.prototype;return o.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)}},o.enable=function(){try{return Promise.resolve(this.request({method:"eth_requestAccounts"}))}catch(e){return Promise.reject(e)}},o.isConnected=function(){return this.connected},o.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(){var i=(e.method===r.JSON_RPC_METHOD.eth_sendTransaction||e.method===r.JSON_RPC_METHOD.eth_signTransaction||e.method===r.JSON_RPC_METHOD.eth_signTypedData_v4||e.method===r.JSON_RPC_METHOD.personal_sign)&&n.asyncSigning||e.async?{asyncSigning:!0}:void 0;return Promise.resolve(h(e,t.rpcMethodRequiresUI(e.method),n.walletMessageManager,n.internalEventEmitter,i)).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)}},o.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(h({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)}},o.logout=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){function t(){return h({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)}},o.cleanupInvalidLoginState=function(){try{localStorage.removeItem(window.location.origin+"-connected")}catch(e){console.warn("Could not clean up login state:",e)}},o.setupWaaP=function(){var e=s({},this.persistedMethods,{isWaaP:!0,on:this.on.bind(this),removeListener:this.removeListener.bind(this),request:this.request.bind(this)});window.silk=e,window.waap=e},o.setupInjectedWallet=function(e){var t,n,r,i,o,a=s({},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=a,window.waap=a},o.setupWalletConnect=function(e){var t,n,r,i,o=s({},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},o.setupAutoConnectInjected=function(e){var t,n,r,i,o,a=s({},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=a,window.waap=a},o.setupAutoConnectWalletConnect=function(e){var t,n,r,i,o=s({},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},o.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(h({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)}},o.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}},o.toggleDarkMode=function(){try{var e=this;return e.config.styles.darkMode=!e.config.styles.darkMode,e.walletMessageManager.pingIframe().then(function(){return h({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)}},o.safe=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return h({method:r.SILK_METHOD.safe},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},o.orcid=function(){try{var e=this;return e.walletMessageManager.pingIframe().then(function(){return h({method:r.SILK_METHOD.orcid},!0,e.walletMessageManager,e.internalEventEmitter)}),Promise.resolve()}catch(e){return Promise.reject(e)}},o.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 h({method:o,params:[n,window.location.origin]},"get"!==t&&"customization"!==e,i.walletMessageManager,i.internalEventEmitter)})}catch(e){return Promise.reject(e)}},o.requestEmail=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return h({method:r.SILK_METHOD.silk_requestEmail},!0,e.walletMessageManager,e.internalEventEmitter)})}catch(e){return Promise.reject(e)}},o.requestSBT=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return h({method:r.SILK_METHOD.silk_requestSbt,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},i}(n.EventEmitter),I="waap-wallet",T="waap-component-container",S="undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof HTMLElement;function C(){return!(!S||!document.getElementById(T)&&!document.querySelector(I))}function O(){return S?document.getElementById(T)||document.querySelector(I):null}exports.WaaP=void 0,S?(exports.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=T,t}c(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__*/f(HTMLElement)),"undefined"==typeof customElements||customElements.get(I)||customElements.define(I,exports.WaaP)):exports.WaaP=function(){};var b="waap-wallet-iframe-container",L="waap-wallet-iframe-wrapper",x="waap-wallet-iframe",k=function(){return document.getElementById(b)||document.getElementById("silk-wallet-iframe-container")},j=function(){return document.getElementById(L)||document.getElementById("silk-wallet-iframe-wrapper")},A=function(){return document.getElementById(x)||document.getElementById("silk-wallet-iframe")},W=b,N=L,q=x,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)}},H=/*#__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=s({},m,t||{}),n}c(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(exports,"rpcMethodRequiresUI",{enumerable:!0,get:function(){return t.rpcMethodRequiresUI}}),Object.defineProperty(exports,"SILK_METHOD",{enumerable:!0,get:function(){return r.SILK_METHOD}}),Object.defineProperty(exports,"WAAP_METHOD",{enumerable:!0,get:function(){return r.SILK_METHOD}}),exports.EthereumProvider=P,exports.EthereumProviderExtension=H,exports.SilkWalletConnect=y,exports.UIMessageManager=p,exports.WaaPWalletConnect=y,exports.WalletMessageManager=E,exports.handleWalletRequestAndResponse=h,exports.initWaaP=function(e){var t;void 0===e&&(e={}),t=!!e.useStaging,C()?function(e){var t=O();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)}}(t):function(e){if(!k()){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)}}(t);var n=A();if(!n)throw new Error("WaaP iframe does not exist on page");var r=C();e.walletConnectProjectId&&y.setProjectId(e.walletConnectProjectId);var i=new P(n.contentWindow,e.referralCode,e.config||{},e.project||{},e.useStaging,e.asyncSigning||!1),o=r?"component":"modal";return i.uiMessageManager.on(exports.UI_EVENT_NAMES.show_modal,function(){var e=C(),t=e?"component":"modal",n=j();if(t!==o&&n)if(o=t,e){var r=O();r&&r.appendChild(n)}else{var i=k();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 a=k();e&&n?n.style.display="flex":a&&(a.style.display="flex")}),i.uiMessageManager.on(exports.UI_EVENT_NAMES.hide_modal,function(){var e=C(),t=j(),n=k();e&&t?t.style.display="none":n&&(n.style.display="none")}),window.silk=i,window.waap=i,i},exports.useWaapTransaction=function(e){var t=o.useState(new Map),n=t[0],r=t[1],i=o.useRef(e);o.useEffect(function(){i.current=e},[e]),o.useEffect(function(){var e=window.waap||window.silk;if(e){var t=function(e){var t;r(function(t){var n=new Map(t);return n.set(e.pendingTxId,{status:"pending",pendingTxId:e.pendingTxId,txRequest:e.txRequest}),n}),null==(t=i.current)||null==t.onPending||t.onPending(e)},n=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.pendingTxId);return r&&n.set(e.pendingTxId,s({},r,{status:"2fa"})),n}),null==(t=i.current)||null==t.on2faRequired||t.on2faRequired(e)},o=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.pendingTxId);return r&&n.set(e.pendingTxId,s({},r,{status:"signed",signature:e.signature,serializedTx:e.serializedTx})),n}),null==(t=i.current)||null==t.onSigned||t.onSigned(e)},a=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.pendingTxId);return r&&n.set(e.pendingTxId,s({},r,{status:"failed",error:e.error})),n}),null==(t=i.current)||null==t.onSignFailed||t.onSignFailed(e)},l=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.pendingTxId);return r&&n.set(e.pendingTxId,s({},r,{status:"tx_pending",txHash:e.txHash})),n}),null==(t=i.current)||null==t.onTxPending||t.onTxPending(e)},c=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.pendingTxId);return r&&n.set(e.pendingTxId,s({},r,{status:"confirmed",txHash:e.txHash,receipt:e.receipt})),n}),null==(t=i.current)||null==t.onConfirmed||t.onConfirmed(e)},u=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.pendingTxId);return r&&n.set(e.pendingTxId,s({},r,{status:"failed",error:e.error,stage:e.stage})),n}),null==(t=i.current)||null==t.onFailed||t.onFailed(e)};return e.on("waap_sign_pending",t),e.on("waap_2fa_required",n),e.on("waap_sign_complete",o),e.on("waap_sign_failed",a),e.on("waap_tx_pending",l),e.on("waap_tx_confirmed",c),e.on("waap_tx_failed",u),function(){null==e.removeListener||e.removeListener("waap_sign_pending",t),null==e.removeListener||e.removeListener("waap_2fa_required",n),null==e.removeListener||e.removeListener("waap_sign_complete",o),null==e.removeListener||e.removeListener("waap_sign_failed",a),null==e.removeListener||e.removeListener("waap_tx_pending",l),null==e.removeListener||e.removeListener("waap_tx_confirmed",c),null==e.removeListener||e.removeListener("waap_tx_failed",u)}}console.warn("[useWaapTransaction] WaaP provider not found. Make sure initWaaP() was called.")},[]);var a=o.useCallback(function(e){try{var t=window.waap||window.silk;if(!t)throw new Error("WaaP provider not found");return console.log("sendTransaction",e),Promise.resolve(t.request({method:"eth_sendTransaction",params:e}))}catch(e){return Promise.reject(e)}},[]),l=o.useCallback(function(e){try{var t=window.waap||window.silk;if(!t)throw new Error("WaaP provider not found");return Promise.resolve(t.request({method:"eth_signTransaction",params:e}))}catch(e){return Promise.reject(e)}},[]),c=Array.from(n.values()).some(function(e){return"pending"===e.status||"signing"===e.status||"2fa"===e.status||"signed"===e.status||"tx_pending"===e.status});return{sendTransaction:a,signTransaction:l,pendingTransactions:n,isAnyPending:c}};
2
2
  //# sourceMappingURL=index.js.map