@human.tech/waap-sdk 1.2.1 → 1.2.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/CHANGELOG.md +6 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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("@mysten/wallet-standard"),a=require("react");function s(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 c(){return c=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},c.apply(null,arguments)}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function l(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,f(e,t)}function d(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(d=function(){return!!e})()}function f(e,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},f(e,t)}function h(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function m(e){var t="function"==typeof Map?new Map:void 0;return m=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(d())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&f(i,n.prototype),i}(e,arguments,u(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,e)},m(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 g=/*#__PURE__*/function(e){function t(){return e.call(this)||this}return l(t,e),t}(n.EventEmitter),p=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)}},v={styles:{darkMode:!1}};function w(e,t,n){if(!e.s){if(n instanceof y){if(!n.s)return void(n.o=w.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(w.bind(null,e,t),w.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var y=/*#__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{w(r,1,o(this.v))}catch(e){w(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?w(r,1,t?t(i):i):n?w(r,1,n(i)):w(r,2,i)}catch(e){w(r,2,e)}},r},e}();function E(e){return e instanceof y&&1&e.s}var M=/*#__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 s(require("@reown/appkit"))})).then(function(t){var n=t.createAppKit;return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return s(require("@reown/appkit/networks"))})).then(function(t){var r=t.mainnet,o=t.sepolia,a=t.optimism,s=t.arbitrum,c=t.polygon,u=t.gnosis,l=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,c,u,l,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(E(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!E(o)){r=1;break}o=o.s}}var a=new y,s=w.bind(null,a,2);return(0===r?i.then(u):1===r?o.then(c):(void 0).then(function(){(i=e())?i.then?i.then(u).then(void 0,s):u(i):w(a,1,o)})).then(void 0,s),a;function c(t){o=t;do{if(!(i=e())||E(i)&&!i.v)return void w(a,1,o);if(i.then)return void i.then(u).then(void 0,s);E(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,s)}function u(e){e?(o=n())&&o.then?o.then(c).then(void 0,s):c(o):w(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}();M.instance=null,M.projectId=void 0,M.chains=[1,10,100,137,8453,43114,42161,42220,84532,11155111];var P=["silkOptions"],_=/*#__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=e.silkOptions,i=c({},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,P),{target:"silk",messageType:r.SILK_MESSAGE_TYPE.request},n&&{silkOptions:n});return Promise.resolve(r.generateMessageId(i)).then(function(e){return t.iframeWindow.postMessage(c({},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 c,u,l;try{if("undefined"!=typeof process&&process,e.origin!==t.walletOrigin)return}catch(n){if(e.origin!==t.walletOrigin)return}if((null==(c=e.data)?void 0:c.messageType)===r.SILK_MESSAGE_TYPE.request)i(e.data);else if((null==(u=e.data)?void 0:u.messageType)===r.SILK_MESSAGE_TYPE.response)n(e.data);else if((null==(l=e.data)?void 0:l.messageType)===r.SILK_MESSAGE_TYPE.notification){var d,f,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!=(h=e.data)&&null!=(h=h.data)&&null!=(h=h.type)&&h.startsWith("waap_sign_")||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 I(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var T=["waap","human","injected","walletconnect"];function b(e,t,n){if(!e.s){if(n instanceof A){if(!n.s)return void(n.o=b.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(b.bind(null,e,t),b.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var A=/*#__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{b(r,1,o(this.v))}catch(e){b(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?b(r,1,t?t(i):i):n?b(r,1,n(i)):b(r,2,i)}catch(e){b(r,2,e)}},r},e}(),S=/*#__PURE__*/function(e){function i(t,i,o,a,s,u,l){var d;return void 0===u&&(u=!1),void 0===l&&(l=!1),(d=e.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.asyncTxs=!1,d.legacyAsyncSigning=!1,d.persistedMethods=void 0,d.internalEventEmitter=new n.EventEmitter,d.asyncTxs=u,d.legacyAsyncSigning=l,d.uiMessageManager=new g,d.walletMessageManager=new _(t,!!s),d.config=c({},v,o||{}),d.persistedMethods={login:d.login.bind(d),logout:d.logout.bind(d),getLoginMethod:d.getLoginMethod.bind(d),walletMessageManager:d.walletMessageManager,internalEventEmitter:d.internalEventEmitter,uiMessageManager:d.uiMessageManager,portal:d.portal.bind(d),requestEmail:d.requestEmail.bind(d),requestSBT:d.requestSBT.bind(d),requestPermissionToken:d.requestPermissionToken.bind(d),orcid:d.orcid.bind(d),enable:d.enable.bind(d),isConnected:d.isConnected.bind(d),toggleDarkMode:d.toggleDarkMode.bind(d),silkRequest:d.request.bind(d),waaPRequest:d.request.bind(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===r.SILK_METHOD.show_modal?d.uiMessageManager.emit(exports.UI_EVENT_NAMES.show_modal):e.method===r.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]:[]))},onAsyncTxNotification:function(e){d.emit(e.type,e.payload)}}),i&&d.walletMessageManager.pingIframe().then(function(){return p({method:r.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)}),a&&(console.log(" =========== project =========== ",a),d.walletMessageManager.pingIframe().then(function(){return p({method:r.SILK_METHOD.set_project,params:[a,window.location.origin]},!1,d.walletMessageManager,d.internalEventEmitter)})),o&&d.walletMessageManager.pingIframe().then(function(){return p({method:r.SILK_METHOD.set_custom_config,params:[o]},!1,d.walletMessageManager,d.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),d}l(i,e);var o=i.prototype;return o.initializeWalletConnect=function(){try{var e=this,t=I(function(){return Promise.resolve(M.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.asyncTxs||e.async,o=i||e.withPT?n.legacyAsyncSigning?{asyncSigning:i||void 0,withPT:e.withPT}:{async:i,withPT:e.withPT}:void 0;return Promise.resolve(p(e,t.rpcMethodRequiresUI(e.method),n.walletMessageManager,n.internalEventEmitter,o)).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=I(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(p({method:r.SILK_METHOD.login,params:[i]},!0,n.walletMessageManager,n.internalEventEmitter)).then(function(e){var r=function(e){if(null==e)return null;if("string"==typeof e){if(T.includes(e))return e;throw new Error('[EthereumProvider] Unexpected login method: "'+e+'". Expected one of: '+T.join(", "))}if("object"==typeof e&&"loginMethod"in e&&"string"==typeof e.loginMethod){var t=e.loginMethod;if(console.warn('[EthereumProvider] Received object login response. Normalizing "'+t+'" to string. This is unexpected for the web SDK.'),T.includes(t))return t;throw new Error('[EthereumProvider] Unknown loginMethod in object: "'+t+'". Expected one of: '+T.join(", "))}throw new Error("[EthereumProvider] Unexpected login response: "+JSON.stringify(e)+" (type: "+typeof e+")")}(e);if(null===r)return null;var i=function(e,t){var n,r=-1;e:{for(var i=0;i<t.length;i++){var o=t[i][0];if(o){var a=o();if(a&&a.then)break e;if(a===e){r=i;break}}else r=i}if(-1!==r){do{for(var s=t[r][1];!s;)r++,s=t[r][1];var c=s();if(c&&c.then){n=!0;break e}var u=t[r][2];r++}while(u&&!u());return c}}var l=new A,d=b.bind(null,l,2);return(n?c.then(f):a.then(function n(a){for(;;){if(a===e){r=i;break}if(++i===t.length){if(-1!==r)break;return void b(l,1,c)}if(o=t[i][0]){if((a=o())&&a.then)return void a.then(n).then(void 0,d)}else r=i}do{for(var s=t[r][1];!s;)r++,s=t[r][1];var c=s();if(c&&c.then)return void c.then(f).then(void 0,d);var u=t[r][2];r++}while(u&&!u());b(l,1,c)})).then(void 0,d),l;function f(e){for(;;){var n=t[r][2];if(!n||n())break;r++;for(var i=t[r][1];!i;)r++,i=t[r][1];if((e=i())&&e.then)return void e.then(f).then(void 0,d)}b(l,1,e)}}(r,[[function(){return"waap"}],[function(){return"human"},function(){localStorage.setItem(window.location.origin+"-connected","waap"),n.setupWaaP()}],[function(){return"injected"},function(){t&&(localStorage.setItem(window.location.origin+"-connected","injected"),n.setupInjectedWallet(t))}],[function(){return"walletconnect"},function(){var e=function(){var e=M.getWalletProvider();n.setupWalletConnect(e)};localStorage.setItem(window.location.origin+"-connected","walletconnect");var t=function(){if(!M.isConnected())return Promise.resolve(n.walletConnectProvider.open({view:"Connect"})).then(function(){return Promise.resolve(M.listenToAccountChangeEvent()).then(function(){})})}();return t&&t.then?t.then(e):e()}]]);return i&&i.then?i.then(function(){return r}):r})})},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 p({method:r.SILK_METHOD.logout},!1,e.walletMessageManager,e.internalEventEmitter)}e.cleanupInvalidLoginState();var n=I(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=c({},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=c({},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=c({},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=c({},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=c({},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(p({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 I(function(){function e(){return Promise.resolve(M.waitForReadyAndCheckConnection()).then(function(e){if(e){var r=M.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(M.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 M.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 p({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 p({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 p({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 p({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 p({method:r.SILK_METHOD.silk_requestEmail},!0,e.walletMessageManager,e.internalEventEmitter)})}catch(e){return Promise.reject(e)}},o.requestPermissionToken=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return p({method:r.SILK_METHOD.waap_requestPermissionToken,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},o.requestSBT=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return p({method:r.SILK_METHOD.silk_requestSbt,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},i}(n.EventEmitter),C="waap-wallet",O="waap-component-container",k="undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof HTMLElement;function x(){return!(!k||!document.getElementById(O)&&!document.querySelector(C))}function j(){return k?document.getElementById(O)||document.querySelector(C):null}exports.WaaP=void 0,k?(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=O,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__*/m(HTMLElement)),"undefined"==typeof customElements||customElements.get(C)||customElements.define(C,exports.WaaP)):exports.WaaP=function(){};var L="waap-wallet-iframe-container",W="waap-wallet-iframe-wrapper",q="waap-wallet-iframe",N=function(){return document.getElementById(L)||document.getElementById("silk-wallet-iframe-container")},R=function(){return document.getElementById(W)||document.getElementById("silk-wallet-iframe-wrapper")},D=function(){return document.getElementById(q)||document.getElementById("silk-wallet-iframe")},H=L,K=W,B=q,F=function(e){var n=window.document.createElement("iframe");return n.id=B,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},U=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=R();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)}},J=/*#__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=c({},v,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);function z(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var G=/*#__PURE__*/function(){function e(e,t){var i,o=this,a=this;void 0===t&&(t={}),this.name="WaaP",this.version="1.0.0",this.icon="data:image/webp;base64,UklGRpoDAABXRUJQVlA4WAoAAAAQAAAAYwAAYwAAQUxQSDMDAAABJyAQSOFmFxERA8TatqpGoimANbEAxlBAPhSgQP9FyXv3vkcFEf134EZS5DREhGvTM8z0ki8stMRvK4cm8bk5rIu3xNbvkgPk4K6ti5IHquRQnLi6KrdBb81hdyF1jTLM1CW425943iba38/djOcG+dg85p/KXGd/g7+xAzJ2VPWTS8R+q65uA1ZcwG3iZ4urjw9Lh4xn83n3gZmQQ3VMVGEO6D403jdr81Ml1OISAAf7RGImBHISwQ5zCJonTuEyOyP7Sga4cDcjMPgXuiK9cUpaGrIDJtH4iAB25utB8O0DDztOKTr8u9hpX0jrx6k8UM5eAlqsynNxlX9tPRLQEtySKwcDOIDnMqEcek1UnylVNac4r0mlypNvhmCNODlhUXuT4fxTQyrDKY0uyV+gi0iiLLpY76A08C/IX8GQoYb8PcVxK7HkZkT5IjAF4gZicOfJW1ovJjyAlYVPlM6BkkHGI0fniAIZIXC0CbAM92BB8SBznU0ITYLr9XkfnKlDgV8170HGMWwitY51+zxcgkftLD4RLh4HSTIa3QzRWKxlaHZTz21s6GLxnBmjogkVilW4kuaMMMGUfgkZ1JhrBSEANrEDMwucAXgbTqIExY3FYRMdtkQRDFjD6BKtJ2GWTopGRY4P9DBkdE4rp9LJHuYhju45oeVZVv3zNmVdZiIOffHDppOz0Q34p0e/+nXy7JmF1846lmF2ZombLt8pgZpbPNeqpJSVJ0bGd4cH8dUNflNPfdQVXUkC95UQS0ZGfDmOJgjs3IyVOExZBEsxONd080gYK/ftQ2nbYaqGW89Hu7M6avmzXEjhO4G8O8ae8gwWtwZsyp8v8j/ys5H7bM+unOfurO4bbbL4v865Nb8s98Ld2X9yg6tLBQanMP8fhplOMMN8fiNDzTvNOMXGuYzejo12vY7s3clhXwgDPuBIcxi9QZftbKVxAjLCcVQdRxGR1QknhCs3GuieMLzfrrC9RhfJgVpcXRn71nZfEjsiYy/Ca1J7ch0clK64ReH3G/s2cekpP+BIx2YteMvSoLy6G9FCgd1nvF/VoVRtJoNJNLQ0RM3BXY9WgPbcHF78swAAVlA4IEAAAACwBQCdASpkAGQAPpFIoUylpCMiIKgAsBIJaW7hc+AAY2upvcReWAa6m9xF5YBrqb3EXlgGngAA/v81aVcAAAAA",this._accounts=[],this._chains=["sui:mainnet","sui:testnet","sui:devnet"],this.walletMessageManager=void 0,this.uiMessageManager=void 0,this.internalEventEmitter=new n.EventEmitter,this.changeListeners=new Set;var s=null!=(i=t.useStaging)&&i;this.walletMessageManager=new _(e,s),this.uiMessageManager=new g,t.referralCode&&this.walletMessageManager.pingIframe().then(function(){a.postRequestAndWait({method:r.SILK_METHOD.set_points_referral_code,params:[t.referralCode],interactionRequired:!1}).catch(function(e){return console.error("Error setting referral code:",e)})}),t.project&&this.walletMessageManager.pingIframe().then(function(){a.postRequestAndWait({method:r.SILK_METHOD.set_project,params:[t.project,window.location.origin],interactionRequired:!1}).catch(function(e){return console.error("Error setting project:",e)})}),t.config&&this.walletMessageManager.pingIframe().then(function(){a.postRequestAndWait({method:r.SILK_METHOD.set_custom_config,params:[t.config],interactionRequired:!1}).catch(function(e){return console.error("Error setting custom config:",e)})}),this.walletMessageManager.addListener({handleResponse:function(e){a.internalEventEmitter.emit(e.id,e)},handleRequest:function(e){e.method===r.SILK_METHOD.show_modal?a.uiMessageManager.emit(exports.UI_EVENT_NAMES.show_modal):e.method===r.SILK_METHOD.hide_modal&&a.uiMessageManager.emit(exports.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){try{var t=z(function(){return Promise.resolve(o.refreshAccounts()).then(function(e){o.notifyChange({accounts:e.accounts})})},function(e){console.error("Failed to refresh Sui accounts:",e),o._accounts=[],o.notifyChange({accounts:[]})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}})}var t,i,o=e.prototype;return o.refreshAccounts=function(){try{var e=this;return Promise.resolve(z(function(){return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(e.postRequestAndWait({method:"sui_connect",params:[{silent:!0}],interactionRequired:!1})).then(function(t){var n;if(t.error)return e._accounts=[],{accounts:[]};var r=(null==(n=t.data)?void 0:n.accounts)||[];return e._accounts=r,{accounts:e._accounts}})})},function(){return e._accounts=[],{accounts:[]}}))}catch(e){return Promise.reject(e)}},o.connect=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(t.postRequestAndWait({method:"sui_connect",params:[e||{}],interactionRequired:!(null!=e&&e.silent)})).then(function(e){var n;if(e.error)throw new Error(e.error.message||"Failed to connect");var r=(null==(n=e.data)?void 0:n.accounts)||[];return t._accounts=r,t.notifyChange({accounts:t._accounts}),{accounts:t._accounts}})})}catch(e){return Promise.reject(e)}},o.disconnect=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(e.postRequestAndWait({method:"sui_disconnect",params:[],interactionRequired:!1})).then(function(){e._accounts=[],e.notifyChange({accounts:[]})})})}catch(e){return Promise.reject(e)}},o.signPersonalMessage=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){var n=e.account.address;if(!t._accounts.some(function(e){return e.address===n}))throw new Error("Account "+n+" is not connected");return Promise.resolve(t.postRequestAndWait({method:"sui_signPersonalMessage",params:[{message:Array.from(e.message),account:n,chain:e.chain}],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to sign message");return{bytes:e.data.bytes,signature:e.data.signature}})})}catch(e){return Promise.reject(e)}},o.resolveTransactionBytes=function(e,t){void 0===t&&(t="sui:mainnet");try{var n;if(e instanceof Uint8Array)return Promise.resolve(e);if(Array.isArray(e))return Promise.resolve(new Uint8Array(e));if("string"!=typeof e){if(e&&"object"==typeof e){var r=function(t){var r;if(n)return t;function i(t){var n;if(r)return t;function i(t){if(n)return t;if("function"==typeof e.getData)try{var r=e.getData();if(r instanceof Uint8Array)return r}catch(e){console.warn("[SuiWallet] getData() failed:",e)}throw new Error("Unsupported transaction format. Keys: "+Object.keys(e).join(", "))}var o=function(){if("function"==typeof e.toJSON)return z(function(){return Promise.resolve(e.toJSON()).then(function(e){if("string"==typeof e)try{var t=Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)});return n=1,t}catch(t){try{var r=JSON.parse(e);if(r.bytes&&"string"==typeof r.bytes){var i=Uint8Array.from(atob(r.bytes),function(e){return e.charCodeAt(0)});return n=1,i}}catch(e){}}})},function(e){console.warn("[SuiWallet] toJSON() failed:",e)})}();return o&&o.then?o.then(i):i(o)}var o=function(){if("function"==typeof e.serialize)return z(function(){return Promise.resolve(e.serialize()).then(function(e){if("string"==typeof e){var t=Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)});return r=1,t}if(e instanceof Uint8Array)return r=1,e})},function(e){console.warn("[SuiWallet] serialize() failed:",e)})}();return o&&o.then?o.then(i):i(o)},i=function(){if("function"==typeof e.build)return z(function(){return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return s(require("@mysten/sui/client"))})).then(function(r){var i="mainnet";"sui:testnet"===t?i="testnet":"sui:devnet"===t?i="devnet":"sui:localnet"===t&&(i="localnet");var o=new(0,r.SuiClient)({url:(0,r.getFullnodeUrl)(i)});return Promise.resolve(e.build({client:o})).then(function(e){return n=1,e})})},function(e){throw console.warn("[SuiWallet] Failed to build transaction object:",e),new Error("Failed to build transaction: "+(e instanceof Error?e.message:String(e)))})}();return Promise.resolve(i&&i.then?i.then(r):r(i))}throw new Error("Unsupported transaction format: "+typeof e+". Please pass Uint8Array bytes or a Transaction object.")}try{return Promise.resolve(Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)}))}catch(e){throw new Error("Transaction string must be base64 encoded bytes. If you have a serialized transaction JSON, please build it to bytes first.")}}catch(e){return Promise.reject(e)}},o.signTransaction=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){var n=e.account.address;if(!t._accounts.some(function(e){return e.address===n}))throw new Error("Account "+n+" is not connected");return Promise.resolve(t.resolveTransactionBytes(e.transaction,e.chain)).then(function(r){return Promise.resolve(t.postRequestAndWait({method:"sui_signTransaction",params:[{transaction:Array.from(r),account:n,chain:e.chain}],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to sign transaction");return{bytes:e.data.bytes,signature:e.data.signature}})})})}catch(e){return Promise.reject(e)}},o.signAndExecuteTransaction=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){var n=e.account.address;if(!t._accounts.some(function(e){return e.address===n}))throw new Error("Account "+n+" is not connected");return Promise.resolve(t.resolveTransactionBytes(e.transaction,e.chain)).then(function(r){return Promise.resolve(t.postRequestAndWait({method:"sui_signAndExecuteTransaction",params:[{transaction:Array.from(r),account:n,chain:e.chain,options:e.options,requestType:e.requestType}],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to sign and execute transaction");return e.data})})})}catch(e){return Promise.reject(e)}},o.switchChain=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){if(!t._chains.includes(e.chain))throw new Error("Chain "+e.chain+" is not supported");return Promise.resolve(t.postRequestAndWait({method:"sui_switchChain",params:[e],interactionRequired:!1})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to switch chain");t.notifyChange({chains:t._chains,accounts:t._accounts})})})}catch(e){return Promise.reject(e)}},o.on=function(e,t){var n=this;return"change"===e?(this.changeListeners.add(t),function(){n.changeListeners.delete(t)}):function(){}},o.signTransactionBlock=function(e){try{return Promise.resolve(this.signTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain}))}catch(e){return Promise.reject(e)}},o.signAndExecuteTransactionBlock=function(e){try{return Promise.resolve(this.signAndExecuteTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain,options:e.options,requestType:e.requestType}))}catch(e){return Promise.reject(e)}},o.requestEmail=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(e.postRequestAndWait({method:r.SILK_METHOD.silk_requestEmail,params:[],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to request email");return e.data})})}catch(e){return Promise.reject(e)}},o.postRequestAndWait=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.postSilkRequest({method:e.method,params:e.params,interactionRequired:e.interactionRequired})).then(function(e){return new Promise(function(n){t.internalEventEmitter.once(e,function(e){n(e)})})})}catch(e){return Promise.reject(e)}},o.notifyChange=function(e){Array.from(this.changeListeners).forEach(function(t){t(e)})},t=e,(i=[{key:"chains",get:function(){return this._chains}},{key:"accounts",get:function(){return this._accounts}},{key:"ui",get:function(){return this.uiMessageManager}},{key:"features",get:function(){return{"standard:connect":{version:"1.0.0",connect:this.connect.bind(this)},"standard:disconnect":{version:"1.0.0",disconnect:this.disconnect.bind(this)},"standard:events":{version:"1.0.0",on:this.on.bind(this)},"sui:signPersonalMessage":{version:"1.1.0",signPersonalMessage:this.signPersonalMessage.bind(this)},"sui:signTransaction":{version:"2.0.0",signTransaction:this.signTransaction.bind(this)},"sui:signAndExecuteTransaction":{version:"1.0.0",signAndExecuteTransaction:this.signAndExecuteTransaction.bind(this)},"sui:signTransactionBlock":{version:"2.0.0",signTransactionBlock:this.signTransactionBlock.bind(this)},"sui:signAndExecuteTransactionBlock":{version:"1.0.0",signAndExecuteTransactionBlock:this.signAndExecuteTransactionBlock.bind(this)},"sui:switchChain":{version:"1.0.0",switchChain:this.switchChain.bind(this)}}}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,h(r.key),r)}}(t.prototype,i),Object.defineProperty(t,"prototype",{writable:!1}),t}(),V="waap-wallet-iframe-container",Y="waap-wallet-iframe",Q=function(){return document.getElementById(V)||document.getElementById("silk-wallet-iframe-container")},X="waap-wallet-iframe-wrapper";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=S,exports.EthereumProviderExtension=J,exports.SilkWalletConnect=M,exports.UIMessageManager=g,exports.WaaPSuiWallet=G,exports.WaaPWalletConnect=M,exports.WalletMessageManager=_,exports.handleWalletRequestAndResponse=p,exports.initWaaP=function(e){var t;void 0===e&&(e={}),t=!!e.useStaging,x()?function(e){var t=j();if(!t)throw new Error("WaaP component not found in DOM");if(!D()){var n=window.document.createElement("div");n.id=K,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=F(e);U(e,r),setTimeout(function(){var e=R();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),t.appendChild(n)}}(t):function(e){if(!N()){var t=window.document.createElement("div");t.id=H,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="9999999999",t.style.display="none";var n=window.document.createElement("div");n.id=K,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=F(e);U(e,r),setTimeout(function(){var e=R();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),window.document.body.appendChild(t)}}(t);var n=D();if(!n)throw new Error("WaaP iframe does not exist on page");var r=x();e.walletConnectProjectId&&M.setProjectId(e.walletConnectProjectId);var i=e.referralCode,o=e.config,a=e.project,s=e.asyncTxs,c=e.asyncSigning;c&&!s&&console.warn("[WaaP SDK] `asyncSigning` is deprecated. Use `asyncTxs` instead.");var u=new S(n.contentWindow,i,o||{},a||{},e.useStaging,s||c||!1),l=r?"component":"modal";return u.uiMessageManager.on(exports.UI_EVENT_NAMES.show_modal,function(){var e=x(),t=e?"component":"modal",n=R();if(t!==l&&n)if(l=t,e){var r=j();r&&r.appendChild(n)}else{var i=N();i||((i=window.document.createElement("div")).id=H,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="9999999999",window.document.body.appendChild(i)),i.appendChild(n)}var o=N();e&&n?n.style.display="flex":o&&(o.style.display="flex")}),u.uiMessageManager.on(exports.UI_EVENT_NAMES.hide_modal,function(){var e=x(),t=R(),n=N();e&&t?t.style.display="none":n&&(n.style.display="none")}),window.silk=u,window.waap=u,u},exports.initWaaPSui=function(e){var n;void 0===e&&(e={}),function(e){if(!Q()){var n=document.createElement("div");n.id=V,n.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n display: none;\n align-items: center;\n justify-content: center;\n background-color: rgba(0, 0, 0, 0.5);\n z-index: 9999999999;\n ";var r=document.createElement("div");r.id=X,r.style.cssText="\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0;\n margin: 0;\n height: 600px;\n width: 380px;\n ",n.appendChild(r);var i=document.createElement("iframe");i.id=Y,i.src=(e?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2)+"/iframe",i.style.cssText="\n width: 100%;\n height: 100%;\n border: none;\n border-radius: 24px;\n background: transparent;\n ",r.appendChild(i),function(e){window.addEventListener("message",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=document.getElementById(X)||document.getElementById("silk-wallet-iframe-wrapper");o&&(o.style.height=Math.floor(r)+"px",o.style.width=Math.floor(i)+"px")}}})}(e),document.body.appendChild(n)}}(null!=(n=e.useStaging)&&n);var r=Q(),i=document.getElementById(Y)||document.getElementById("silk-wallet-iframe");if(!r||!i)throw new Error("Failed to create WaaP iframe");var o=new G(i.contentWindow,e);return o.ui.on(exports.UI_EVENT_NAMES.show_modal,function(){r.style.display="flex",document.querySelectorAll('[data-dapp-kit][class*="overlay"]').forEach(function(e){e.style.display="none"})}),o.ui.on(exports.UI_EVENT_NAMES.hide_modal,function(){r.style.display="none",document.querySelectorAll('[data-dapp-kit][class*="overlay"]').forEach(function(e){e.style.display=""})}),o},exports.registerWaaPSuiWallet=function(e,t){void 0===t&&(t={});var n=new G(e,t);return o.registerWallet(n),n},exports.useWaapTransaction=function(e){var t=a.useState(new Map),n=t[0],r=t[1],i=a.useRef(e);a.useEffect(function(){i.current=e},[e]),a.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.txHash,{status:"signed",txHash:e.txHash,pendingTxId:e.txHash,signature:e.signature,serializedTx:e.serializedTx}),n}),null==(t=i.current)||null==t.onSigned||t.onSigned(e)},n=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.txHash);return r&&n.set(e.txHash,c({},r,{status:"tx_pending"})),n}),null==(t=i.current)||null==t.onTxPending||t.onTxPending(e)},o=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.txHash);return r&&n.set(e.txHash,c({},r,{status:"confirmed",receipt:e.receipt})),n}),null==(t=i.current)||null==t.onConfirmed||t.onConfirmed(e)},a=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.txHash);return r&&n.set(e.txHash,c({},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_complete",t),e.on("waap_tx_pending",n),e.on("waap_tx_confirmed",o),e.on("waap_tx_failed",a),function(){null==e.removeListener||e.removeListener("waap_sign_complete",t),null==e.removeListener||e.removeListener("waap_tx_pending",n),null==e.removeListener||e.removeListener("waap_tx_confirmed",o),null==e.removeListener||e.removeListener("waap_tx_failed",a)}}console.warn("[useWaapTransaction] WaaP provider not found. Make sure initWaaP() was called.")},[]);var o=a.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_sendTransaction",params:e}))}catch(e){return Promise.reject(e)}},[]),s=a.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)}},[]),u=Array.from(n.values()).some(function(e){return"signed"===e.status||"tx_pending"===e.status});return{sendTransaction:o,signTransaction:s,pendingTransactions:n,isAnyPending:u}};
|
|
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("@mysten/wallet-standard"),a=require("react");function s(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 c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(){return u=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},u.apply(null,arguments)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function d(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,h(e,t)}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(f=function(){return!!e})()}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function m(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function g(e){var t="function"==typeof Map?new Map:void 0;return g=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(f())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&h(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}}),h(n,e)},g(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 d(t,e),t}(n.EventEmitter),v=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)}},w={styles:{darkMode:!1}};function y(e,t,n){if(!e.s){if(n instanceof E){if(!n.s)return void(n.o=y.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(y.bind(null,e,t),y.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var E=/*#__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{y(r,1,o(this.v))}catch(e){y(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?y(r,1,t?t(i):i):n?y(r,1,n(i)):y(r,2,i)}catch(e){y(r,2,e)}},r},e}();function M(e){return e instanceof E&&1&e.s}var P=/*#__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 s(require("@reown/appkit"))})).then(function(t){var n=t.createAppKit;return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return s(require("@reown/appkit/networks"))})).then(function(t){var r=t.mainnet,o=t.sepolia,a=t.optimism,s=t.arbitrum,c=t.polygon,u=t.gnosis,l=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,c,u,l,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(M(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!M(o)){r=1;break}o=o.s}}var a=new E,s=y.bind(null,a,2);return(0===r?i.then(u):1===r?o.then(c):(void 0).then(function(){(i=e())?i.then?i.then(u).then(void 0,s):u(i):y(a,1,o)})).then(void 0,s),a;function c(t){o=t;do{if(!(i=e())||M(i)&&!i.v)return void y(a,1,o);if(i.then)return void i.then(u).then(void 0,s);M(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,s)}function u(e){e?(o=n())&&o.then?o.then(c).then(void 0,s):c(o):y(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}();P.instance=null,P.projectId=void 0,P.chains=[1,10,100,137,8453,43114,42161,42220,84532,11155111];var _=["silkOptions"],I=/*#__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=e.silkOptions,i=u({},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(u({},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 c,u,l;try{if("undefined"!=typeof process&&process,e.origin!==t.walletOrigin)return}catch(n){if(e.origin!==t.walletOrigin)return}if((null==(c=e.data)?void 0:c.messageType)===r.SILK_MESSAGE_TYPE.request)i(e.data);else if((null==(u=e.data)?void 0:u.messageType)===r.SILK_MESSAGE_TYPE.response)n(e.data);else if((null==(l=e.data)?void 0:l.messageType)===r.SILK_MESSAGE_TYPE.notification){var d,f,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!=(h=e.data)&&null!=(h=h.data)&&null!=(h=h.type)&&h.startsWith("waap_sign_")||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 T(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var b=["waap","human","injected","walletconnect"];function A(e,t,n){if(!e.s){if(n instanceof S){if(!n.s)return void(n.o=A.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(A.bind(null,e,t),A.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var S=/*#__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{A(r,1,o(this.v))}catch(e){A(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?A(r,1,t?t(i):i):n?A(r,1,n(i)):A(r,2,i)}catch(e){A(r,2,e)}},r},e}(),C=/*#__PURE__*/function(e){function i(t,i,o,a,s,l,d){var f;return void 0===l&&(l=!1),void 0===d&&(d=!1),(f=e.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.asyncTxs=!1,f.legacyAsyncSigning=!1,f.persistedMethods=void 0,f.internalEventEmitter=new n.EventEmitter,f.asyncTxs=l,f.legacyAsyncSigning=d,f.uiMessageManager=new p,f.walletMessageManager=new I(t,!!s),f.config=u({},w,o||{}),f.persistedMethods={login:f.login.bind(c(f)),logout:f.logout.bind(c(f)),getLoginMethod:f.getLoginMethod.bind(c(f)),walletMessageManager:f.walletMessageManager,internalEventEmitter:f.internalEventEmitter,uiMessageManager:f.uiMessageManager,portal:f.portal.bind(c(f)),requestEmail:f.requestEmail.bind(c(f)),requestSBT:f.requestSBT.bind(c(f)),requestPermissionToken:f.requestPermissionToken.bind(c(f)),orcid:f.orcid.bind(c(f)),enable:f.enable.bind(c(f)),isConnected:f.isConnected.bind(c(f)),toggleDarkMode:f.toggleDarkMode.bind(c(f)),silkRequest:f.request.bind(c(f)),waaPRequest:f.request.bind(c(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(e){e.method===r.SILK_METHOD.show_modal?f.uiMessageManager.emit(exports.UI_EVENT_NAMES.show_modal):e.method===r.SILK_METHOD.hide_modal&&f.uiMessageManager.emit(exports.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){f.currentAccount!==e&&(f.currentAccount=e,f.emit("accountsChanged",e?[e]:[]))},onAsyncTxNotification:function(e){f.emit(e.type,e.payload)}}),i&&f.walletMessageManager.pingIframe().then(function(){return v({method:r.SILK_METHOD.set_points_referral_code,params:[i]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error setting referral code in Silk iframe:",e)}),a&&(console.log(" =========== project =========== ",a),f.walletMessageManager.pingIframe().then(function(){return v({method:r.SILK_METHOD.set_project,params:[a,window.location.origin]},!1,f.walletMessageManager,f.internalEventEmitter)})),o&&f.walletMessageManager.pingIframe().then(function(){return v({method:r.SILK_METHOD.set_custom_config,params:[o]},!1,f.walletMessageManager,f.internalEventEmitter)}).catch(function(e){console.error("Error setting custom config in Silk iframe:",e)}),f}d(i,e);var o=i.prototype;return o.initializeWalletConnect=function(){try{var e=this,t=T(function(){return Promise.resolve(P.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.asyncTxs||e.async,o=i||e.withPT?n.legacyAsyncSigning?{asyncSigning:i||void 0,withPT:e.withPT}:{async:i,withPT:e.withPT}:void 0;return Promise.resolve(v(e,t.rpcMethodRequiresUI(e.method),n.walletMessageManager,n.internalEventEmitter,o)).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=T(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(v({method:r.SILK_METHOD.login,params:[i]},!0,n.walletMessageManager,n.internalEventEmitter)).then(function(e){var r=function(e){if(null==e)return null;if("string"==typeof e){if(b.includes(e))return e;throw new Error('[EthereumProvider] Unexpected login method: "'+e+'". Expected one of: '+b.join(", "))}if("object"==typeof e&&"loginMethod"in e&&"string"==typeof e.loginMethod){var t=e.loginMethod;if(console.warn('[EthereumProvider] Received object login response. Normalizing "'+t+'" to string. This is unexpected for the web SDK.'),b.includes(t))return t;throw new Error('[EthereumProvider] Unknown loginMethod in object: "'+t+'". Expected one of: '+b.join(", "))}throw new Error("[EthereumProvider] Unexpected login response: "+JSON.stringify(e)+" (type: "+typeof e+")")}(e);if(null===r)return null;var i=function(e,t){var n,r=-1;e:{for(var i=0;i<t.length;i++){var o=t[i][0];if(o){var a=o();if(a&&a.then)break e;if(a===e){r=i;break}}else r=i}if(-1!==r){do{for(var s=t[r][1];!s;)r++,s=t[r][1];var c=s();if(c&&c.then){n=!0;break e}var u=t[r][2];r++}while(u&&!u());return c}}var l=new S,d=A.bind(null,l,2);return(n?c.then(f):a.then(function n(a){for(;;){if(a===e){r=i;break}if(++i===t.length){if(-1!==r)break;return void A(l,1,c)}if(o=t[i][0]){if((a=o())&&a.then)return void a.then(n).then(void 0,d)}else r=i}do{for(var s=t[r][1];!s;)r++,s=t[r][1];var c=s();if(c&&c.then)return void c.then(f).then(void 0,d);var u=t[r][2];r++}while(u&&!u());A(l,1,c)})).then(void 0,d),l;function f(e){for(;;){var n=t[r][2];if(!n||n())break;r++;for(var i=t[r][1];!i;)r++,i=t[r][1];if((e=i())&&e.then)return void e.then(f).then(void 0,d)}A(l,1,e)}}(r,[[function(){return"waap"}],[function(){return"human"},function(){localStorage.setItem(window.location.origin+"-connected","waap"),n.setupWaaP()}],[function(){return"injected"},function(){t&&(localStorage.setItem(window.location.origin+"-connected","injected"),n.setupInjectedWallet(t))}],[function(){return"walletconnect"},function(){var e=function(){var e=P.getWalletProvider();n.setupWalletConnect(e)};localStorage.setItem(window.location.origin+"-connected","walletconnect");var t=function(){if(!P.isConnected())return Promise.resolve(n.walletConnectProvider.open({view:"Connect"})).then(function(){return Promise.resolve(P.listenToAccountChangeEvent()).then(function(){})})}();return t&&t.then?t.then(e):e()}]]);return i&&i.then?i.then(function(){return r}):r})})},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 v({method:r.SILK_METHOD.logout},!1,e.walletMessageManager,e.internalEventEmitter)}e.cleanupInvalidLoginState();var n=T(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=u({},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=u({},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=u({},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=u({},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=u({},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(v({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 T(function(){function e(){return Promise.resolve(P.waitForReadyAndCheckConnection()).then(function(e){if(e){var r=P.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(P.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 P.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 v({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 v({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 v({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 v({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 v({method:r.SILK_METHOD.silk_requestEmail},!0,e.walletMessageManager,e.internalEventEmitter)})}catch(e){return Promise.reject(e)}},o.requestPermissionToken=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return v({method:r.SILK_METHOD.waap_requestPermissionToken,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},o.requestSBT=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return v({method:r.SILK_METHOD.silk_requestSbt,params:[e]},!0,t.walletMessageManager,t.internalEventEmitter)})}catch(e){return Promise.reject(e)}},i}(n.EventEmitter),O="waap-wallet",k="waap-component-container",x="undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof HTMLElement;function j(){return!(!x||!document.getElementById(k)&&!document.querySelector(O))}function L(){return x?document.getElementById(k)||document.querySelector(O):null}exports.WaaP=void 0,x?(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=k,t}d(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__*/g(HTMLElement)),"undefined"==typeof customElements||customElements.get(O)||customElements.define(O,exports.WaaP)):exports.WaaP=function(){};var W="waap-wallet-iframe-container",q="waap-wallet-iframe-wrapper",N="waap-wallet-iframe",R=function(){return document.getElementById(W)||document.getElementById("silk-wallet-iframe-container")},D=function(){return document.getElementById(q)||document.getElementById("silk-wallet-iframe-wrapper")},H=function(){return document.getElementById(N)||document.getElementById("silk-wallet-iframe")},K=W,B=q,F=N,U=function(e){var n=window.document.createElement("iframe");return n.id=F,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},J=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=D();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)}},z=/*#__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=u({},w,t||{}),n}d(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);function G(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var V=/*#__PURE__*/function(){function e(e,t){var i,o=this,a=this;void 0===t&&(t={}),this.name="WaaP",this.version="1.0.0",this.icon="data:image/webp;base64,UklGRpoDAABXRUJQVlA4WAoAAAAQAAAAYwAAYwAAQUxQSDMDAAABJyAQSOFmFxERA8TatqpGoimANbEAxlBAPhSgQP9FyXv3vkcFEf134EZS5DREhGvTM8z0ki8stMRvK4cm8bk5rIu3xNbvkgPk4K6ti5IHquRQnLi6KrdBb81hdyF1jTLM1CW425943iba38/djOcG+dg85p/KXGd/g7+xAzJ2VPWTS8R+q65uA1ZcwG3iZ4urjw9Lh4xn83n3gZmQQ3VMVGEO6D403jdr81Ml1OISAAf7RGImBHISwQ5zCJonTuEyOyP7Sga4cDcjMPgXuiK9cUpaGrIDJtH4iAB25utB8O0DDztOKTr8u9hpX0jrx6k8UM5eAlqsynNxlX9tPRLQEtySKwcDOIDnMqEcek1UnylVNac4r0mlypNvhmCNODlhUXuT4fxTQyrDKY0uyV+gi0iiLLpY76A08C/IX8GQoYb8PcVxK7HkZkT5IjAF4gZicOfJW1ovJjyAlYVPlM6BkkHGI0fniAIZIXC0CbAM92BB8SBznU0ITYLr9XkfnKlDgV8170HGMWwitY51+zxcgkftLD4RLh4HSTIa3QzRWKxlaHZTz21s6GLxnBmjogkVilW4kuaMMMGUfgkZ1JhrBSEANrEDMwucAXgbTqIExY3FYRMdtkQRDFjD6BKtJ2GWTopGRY4P9DBkdE4rp9LJHuYhju45oeVZVv3zNmVdZiIOffHDppOz0Q34p0e/+nXy7JmF1846lmF2ZombLt8pgZpbPNeqpJSVJ0bGd4cH8dUNflNPfdQVXUkC95UQS0ZGfDmOJgjs3IyVOExZBEsxONd080gYK/ftQ2nbYaqGW89Hu7M6avmzXEjhO4G8O8ae8gwWtwZsyp8v8j/ys5H7bM+unOfurO4bbbL4v865Nb8s98Ld2X9yg6tLBQanMP8fhplOMMN8fiNDzTvNOMXGuYzejo12vY7s3clhXwgDPuBIcxi9QZftbKVxAjLCcVQdRxGR1QknhCs3GuieMLzfrrC9RhfJgVpcXRn71nZfEjsiYy/Ca1J7ch0clK64ReH3G/s2cekpP+BIx2YteMvSoLy6G9FCgd1nvF/VoVRtJoNJNLQ0RM3BXY9WgPbcHF78swAAVlA4IEAAAACwBQCdASpkAGQAPpFIoUylpCMiIKgAsBIJaW7hc+AAY2upvcReWAa6m9xF5YBrqb3EXlgGngAA/v81aVcAAAAA",this._accounts=[],this._chains=["sui:mainnet","sui:testnet","sui:devnet"],this.walletMessageManager=void 0,this.uiMessageManager=void 0,this.internalEventEmitter=new n.EventEmitter,this.changeListeners=new Set;var s=null!=(i=t.useStaging)&&i;this.walletMessageManager=new I(e,s),this.uiMessageManager=new p,t.referralCode&&this.walletMessageManager.pingIframe().then(function(){a.postRequestAndWait({method:r.SILK_METHOD.set_points_referral_code,params:[t.referralCode],interactionRequired:!1}).catch(function(e){return console.error("Error setting referral code:",e)})}),t.project&&this.walletMessageManager.pingIframe().then(function(){a.postRequestAndWait({method:r.SILK_METHOD.set_project,params:[t.project,window.location.origin],interactionRequired:!1}).catch(function(e){return console.error("Error setting project:",e)})}),t.config&&this.walletMessageManager.pingIframe().then(function(){a.postRequestAndWait({method:r.SILK_METHOD.set_custom_config,params:[t.config],interactionRequired:!1}).catch(function(e){return console.error("Error setting custom config:",e)})}),this.walletMessageManager.addListener({handleResponse:function(e){a.internalEventEmitter.emit(e.id,e)},handleRequest:function(e){e.method===r.SILK_METHOD.show_modal?a.uiMessageManager.emit(exports.UI_EVENT_NAMES.show_modal):e.method===r.SILK_METHOD.hide_modal&&a.uiMessageManager.emit(exports.UI_EVENT_NAMES.hide_modal)},onAccountChanged:function(e){try{var t=G(function(){return Promise.resolve(o.refreshAccounts()).then(function(e){o.notifyChange({accounts:e.accounts})})},function(e){console.error("Failed to refresh Sui accounts:",e),o._accounts=[],o.notifyChange({accounts:[]})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}})}var t,i,o=e.prototype;return o.refreshAccounts=function(){try{var e=this;return Promise.resolve(G(function(){return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(e.postRequestAndWait({method:"sui_connect",params:[{silent:!0}],interactionRequired:!1})).then(function(t){var n;if(t.error)return e._accounts=[],{accounts:[]};var r=(null==(n=t.data)?void 0:n.accounts)||[];return e._accounts=r,{accounts:e._accounts}})})},function(){return e._accounts=[],{accounts:[]}}))}catch(e){return Promise.reject(e)}},o.connect=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(t.postRequestAndWait({method:"sui_connect",params:[e||{}],interactionRequired:!(null!=e&&e.silent)})).then(function(e){var n;if(e.error)throw new Error(e.error.message||"Failed to connect");var r=(null==(n=e.data)?void 0:n.accounts)||[];return t._accounts=r,t.notifyChange({accounts:t._accounts}),{accounts:t._accounts}})})}catch(e){return Promise.reject(e)}},o.disconnect=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(e.postRequestAndWait({method:"sui_disconnect",params:[],interactionRequired:!1})).then(function(){e._accounts=[],e.notifyChange({accounts:[]})})})}catch(e){return Promise.reject(e)}},o.signPersonalMessage=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){var n=e.account.address;if(!t._accounts.some(function(e){return e.address===n}))throw new Error("Account "+n+" is not connected");return Promise.resolve(t.postRequestAndWait({method:"sui_signPersonalMessage",params:[{message:Array.from(e.message),account:n,chain:e.chain}],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to sign message");return{bytes:e.data.bytes,signature:e.data.signature}})})}catch(e){return Promise.reject(e)}},o.resolveTransactionBytes=function(e,t){void 0===t&&(t="sui:mainnet");try{var n;if(e instanceof Uint8Array)return Promise.resolve(e);if(Array.isArray(e))return Promise.resolve(new Uint8Array(e));if("string"!=typeof e){if(e&&"object"==typeof e){var r=function(t){var r;if(n)return t;function i(t){var n;if(r)return t;function i(t){if(n)return t;if("function"==typeof e.getData)try{var r=e.getData();if(r instanceof Uint8Array)return r}catch(e){console.warn("[SuiWallet] getData() failed:",e)}throw new Error("Unsupported transaction format. Keys: "+Object.keys(e).join(", "))}var o=function(){if("function"==typeof e.toJSON)return G(function(){return Promise.resolve(e.toJSON()).then(function(e){if("string"==typeof e)try{var t=Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)});return n=1,t}catch(t){try{var r=JSON.parse(e);if(r.bytes&&"string"==typeof r.bytes){var i=Uint8Array.from(atob(r.bytes),function(e){return e.charCodeAt(0)});return n=1,i}}catch(e){}}})},function(e){console.warn("[SuiWallet] toJSON() failed:",e)})}();return o&&o.then?o.then(i):i(o)}var o=function(){if("function"==typeof e.serialize)return G(function(){return Promise.resolve(e.serialize()).then(function(e){if("string"==typeof e){var t=Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)});return r=1,t}if(e instanceof Uint8Array)return r=1,e})},function(e){console.warn("[SuiWallet] serialize() failed:",e)})}();return o&&o.then?o.then(i):i(o)},i=function(){if("function"==typeof e.build)return G(function(){return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return s(require("@mysten/sui/client"))})).then(function(r){var i="mainnet";"sui:testnet"===t?i="testnet":"sui:devnet"===t?i="devnet":"sui:localnet"===t&&(i="localnet");var o=new(0,r.SuiClient)({url:(0,r.getFullnodeUrl)(i)});return Promise.resolve(e.build({client:o})).then(function(e){return n=1,e})})},function(e){throw console.warn("[SuiWallet] Failed to build transaction object:",e),new Error("Failed to build transaction: "+(e instanceof Error?e.message:String(e)))})}();return Promise.resolve(i&&i.then?i.then(r):r(i))}throw new Error("Unsupported transaction format: "+typeof e+". Please pass Uint8Array bytes or a Transaction object.")}try{return Promise.resolve(Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)}))}catch(e){throw new Error("Transaction string must be base64 encoded bytes. If you have a serialized transaction JSON, please build it to bytes first.")}}catch(e){return Promise.reject(e)}},o.signTransaction=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){var n=e.account.address;if(!t._accounts.some(function(e){return e.address===n}))throw new Error("Account "+n+" is not connected");return Promise.resolve(t.resolveTransactionBytes(e.transaction,e.chain)).then(function(r){return Promise.resolve(t.postRequestAndWait({method:"sui_signTransaction",params:[{transaction:Array.from(r),account:n,chain:e.chain}],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to sign transaction");return{bytes:e.data.bytes,signature:e.data.signature}})})})}catch(e){return Promise.reject(e)}},o.signAndExecuteTransaction=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){var n=e.account.address;if(!t._accounts.some(function(e){return e.address===n}))throw new Error("Account "+n+" is not connected");return Promise.resolve(t.resolveTransactionBytes(e.transaction,e.chain)).then(function(r){return Promise.resolve(t.postRequestAndWait({method:"sui_signAndExecuteTransaction",params:[{transaction:Array.from(r),account:n,chain:e.chain,options:e.options,requestType:e.requestType}],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to sign and execute transaction");return e.data})})})}catch(e){return Promise.reject(e)}},o.switchChain=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.pingIframe()).then(function(){if(!t._chains.includes(e.chain))throw new Error("Chain "+e.chain+" is not supported");return Promise.resolve(t.postRequestAndWait({method:"sui_switchChain",params:[e],interactionRequired:!1})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to switch chain");t.notifyChange({chains:t._chains,accounts:t._accounts})})})}catch(e){return Promise.reject(e)}},o.on=function(e,t){var n=this;return"change"===e?(this.changeListeners.add(t),function(){n.changeListeners.delete(t)}):function(){}},o.signTransactionBlock=function(e){try{return Promise.resolve(this.signTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain}))}catch(e){return Promise.reject(e)}},o.signAndExecuteTransactionBlock=function(e){try{return Promise.resolve(this.signAndExecuteTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain,options:e.options,requestType:e.requestType}))}catch(e){return Promise.reject(e)}},o.requestEmail=function(){try{var e=this;return Promise.resolve(e.walletMessageManager.pingIframe()).then(function(){return Promise.resolve(e.postRequestAndWait({method:r.SILK_METHOD.silk_requestEmail,params:[],interactionRequired:!0})).then(function(e){if(e.error)throw new Error(e.error.message||"Failed to request email");return e.data})})}catch(e){return Promise.reject(e)}},o.postRequestAndWait=function(e){try{var t=this;return Promise.resolve(t.walletMessageManager.postSilkRequest({method:e.method,params:e.params,interactionRequired:e.interactionRequired})).then(function(e){return new Promise(function(n){t.internalEventEmitter.once(e,function(e){n(e)})})})}catch(e){return Promise.reject(e)}},o.notifyChange=function(e){Array.from(this.changeListeners).forEach(function(t){t(e)})},t=e,(i=[{key:"chains",get:function(){return this._chains}},{key:"accounts",get:function(){return this._accounts}},{key:"ui",get:function(){return this.uiMessageManager}},{key:"features",get:function(){return{"standard:connect":{version:"1.0.0",connect:this.connect.bind(this)},"standard:disconnect":{version:"1.0.0",disconnect:this.disconnect.bind(this)},"standard:events":{version:"1.0.0",on:this.on.bind(this)},"sui:signPersonalMessage":{version:"1.1.0",signPersonalMessage:this.signPersonalMessage.bind(this)},"sui:signTransaction":{version:"2.0.0",signTransaction:this.signTransaction.bind(this)},"sui:signAndExecuteTransaction":{version:"1.0.0",signAndExecuteTransaction:this.signAndExecuteTransaction.bind(this)},"sui:signTransactionBlock":{version:"2.0.0",signTransactionBlock:this.signTransactionBlock.bind(this)},"sui:signAndExecuteTransactionBlock":{version:"1.0.0",signAndExecuteTransactionBlock:this.signAndExecuteTransactionBlock.bind(this)},"sui:switchChain":{version:"1.0.0",switchChain:this.switchChain.bind(this)}}}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,m(r.key),r)}}(t.prototype,i),Object.defineProperty(t,"prototype",{writable:!1}),e}(),Y="waap-wallet-iframe-container",Q="waap-wallet-iframe",X=function(){return document.getElementById(Y)||document.getElementById("silk-wallet-iframe-container")},Z="waap-wallet-iframe-wrapper";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=C,exports.EthereumProviderExtension=z,exports.SilkWalletConnect=P,exports.UIMessageManager=p,exports.WaaPSuiWallet=V,exports.WaaPWalletConnect=P,exports.WalletMessageManager=I,exports.handleWalletRequestAndResponse=v,exports.initWaaP=function(e){var t;void 0===e&&(e={}),t=!!e.useStaging,j()?function(e){var t=L();if(!t)throw new Error("WaaP component not found in DOM");if(!H()){var n=window.document.createElement("div");n.id=B,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=U(e);J(e,r),setTimeout(function(){var e=D();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),t.appendChild(n)}}(t):function(e){if(!R()){var t=window.document.createElement("div");t.id=K,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="9999999999",t.style.display="none";var n=window.document.createElement("div");n.id=B,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=U(e);J(e,r),setTimeout(function(){var e=D();e&&(e.style.height="600px",e.style.width="380px")},100),n.appendChild(r),window.document.body.appendChild(t)}}(t);var n=H();if(!n)throw new Error("WaaP iframe does not exist on page");var r=j();e.walletConnectProjectId&&P.setProjectId(e.walletConnectProjectId);var i=e.referralCode,o=e.config,a=e.project,s=e.asyncTxs,c=e.asyncSigning;c&&!s&&console.warn("[WaaP SDK] `asyncSigning` is deprecated. Use `asyncTxs` instead.");var u=new C(n.contentWindow,i,o||{},a||{},e.useStaging,s||c||!1,!!c&&!s),l=r?"component":"modal";return u.uiMessageManager.on(exports.UI_EVENT_NAMES.show_modal,function(){var e=j(),t=e?"component":"modal",n=D();if(t!==l&&n)if(l=t,e){var r=L();r&&r.appendChild(n)}else{var i=R();i||((i=window.document.createElement("div")).id=K,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="9999999999",window.document.body.appendChild(i)),i.appendChild(n)}var o=R();e&&n?n.style.display="flex":o&&(o.style.display="flex")}),u.uiMessageManager.on(exports.UI_EVENT_NAMES.hide_modal,function(){var e=j(),t=D(),n=R();e&&t?t.style.display="none":n&&(n.style.display="none")}),window.silk=u,window.waap=u,u},exports.initWaaPSui=function(e){var n;void 0===e&&(e={}),function(e){if(!X()){var n=document.createElement("div");n.id=Y,n.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n display: none;\n align-items: center;\n justify-content: center;\n background-color: rgba(0, 0, 0, 0.5);\n z-index: 9999999999;\n ";var r=document.createElement("div");r.id=Z,r.style.cssText="\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0;\n margin: 0;\n height: 600px;\n width: 380px;\n ",n.appendChild(r);var i=document.createElement("iframe");i.id=Q,i.src=(e?t.silkWalletAppOrigin2Staging:t.silkWalletAppOrigin2)+"/iframe",i.style.cssText="\n width: 100%;\n height: 100%;\n border: none;\n border-radius: 24px;\n background: transparent;\n ",r.appendChild(i),function(e){window.addEventListener("message",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=document.getElementById(Z)||document.getElementById("silk-wallet-iframe-wrapper");o&&(o.style.height=Math.floor(r)+"px",o.style.width=Math.floor(i)+"px")}}})}(e),document.body.appendChild(n)}}(null!=(n=e.useStaging)&&n);var r=X(),i=document.getElementById(Q)||document.getElementById("silk-wallet-iframe");if(!r||!i)throw new Error("Failed to create WaaP iframe");var o=new V(i.contentWindow,e);return o.ui.on(exports.UI_EVENT_NAMES.show_modal,function(){r.style.display="flex",document.querySelectorAll('[data-dapp-kit][class*="overlay"]').forEach(function(e){e.style.display="none"})}),o.ui.on(exports.UI_EVENT_NAMES.hide_modal,function(){r.style.display="none",document.querySelectorAll('[data-dapp-kit][class*="overlay"]').forEach(function(e){e.style.display=""})}),o},exports.registerWaaPSuiWallet=function(e,t){void 0===t&&(t={});var n=new V(e,t);return o.registerWallet(n),n},exports.useWaapTransaction=function(e){var t=a.useState(new Map),n=t[0],r=t[1],i=a.useRef(e);a.useEffect(function(){i.current=e},[e]),a.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.txHash,{status:"signed",txHash:e.txHash,pendingTxId:e.txHash,signature:e.signature,serializedTx:e.serializedTx}),n}),null==(t=i.current)||null==t.onSigned||t.onSigned(e)},n=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.txHash);return r&&n.set(e.txHash,u({},r,{status:"tx_pending"})),n}),null==(t=i.current)||null==t.onTxPending||t.onTxPending(e)},o=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.txHash);return r&&n.set(e.txHash,u({},r,{status:"confirmed",receipt:e.receipt})),n}),null==(t=i.current)||null==t.onConfirmed||t.onConfirmed(e)},a=function(e){var t;r(function(t){var n=new Map(t),r=n.get(e.txHash);return r&&n.set(e.txHash,u({},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_complete",t),e.on("waap_tx_pending",n),e.on("waap_tx_confirmed",o),e.on("waap_tx_failed",a),function(){null==e.removeListener||e.removeListener("waap_sign_complete",t),null==e.removeListener||e.removeListener("waap_tx_pending",n),null==e.removeListener||e.removeListener("waap_tx_confirmed",o),null==e.removeListener||e.removeListener("waap_tx_failed",a)}}console.warn("[useWaapTransaction] WaaP provider not found. Make sure initWaaP() was called.")},[]);var o=a.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_sendTransaction",params:e}))}catch(e){return Promise.reject(e)}},[]),s=a.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"signed"===e.status||"tx_pending"===e.status});return{sendTransaction:o,signTransaction:s,pendingTransactions:n,isAnyPending:c}};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|