@human.tech/waap-sdk 1.2.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/dist/index.d.mts +967 -0
- package/dist/index.d.ts +967 -15
- package/dist/index.js +2191 -2
- package/dist/index.mjs +2162 -0
- package/package.json +18 -36
- package/dist/hooks/useWaapTransaction.d.ts +0 -84
- package/dist/index.js.map +0 -1
- package/dist/index.modern.mjs +0 -2
- package/dist/index.modern.mjs.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/lib/UIMessageManager.d.ts +0 -19
- package/dist/lib/WalletConnect.d.ts +0 -30
- package/dist/lib/WalletMessageManager.d.ts +0 -59
- package/dist/lib/provider/EthereumProvider.d.ts +0 -108
- package/dist/lib/provider/EthereumProviderExtension.d.ts +0 -26
- package/dist/lib/provider/requests.d.ts +0 -17
- package/dist/lib/provider/types.d.ts +0 -49
- package/dist/lib/provider/utils.d.ts +0 -4
- package/dist/lib/sui/SuiWallet.d.ts +0 -182
- package/dist/lib/sui/index.d.ts +0 -7
- package/dist/lib/sui/init.d.ts +0 -30
- package/dist/lib/sui/register.d.ts +0 -39
- package/dist/lib/sui/types.d.ts +0 -284
- package/dist/ui/WaapComponent.d.ts +0 -37
- package/dist/ui/index.d.ts +0 -11
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2191 @@
|
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
EthereumProvider: () => EthereumProvider,
|
|
34
|
+
EthereumProviderExtension: () => EthereumProviderExtension,
|
|
35
|
+
SILK_METHOD: () => import_waap_interface_core5.SILK_METHOD,
|
|
36
|
+
SilkWalletConnect: () => SilkWalletConnect,
|
|
37
|
+
UIMessageManager: () => UIMessageManager,
|
|
38
|
+
UI_EVENT_NAMES: () => UI_EVENT_NAMES,
|
|
39
|
+
WAAP_METHOD: () => import_waap_interface_core5.SILK_METHOD,
|
|
40
|
+
WaaP: () => WaapWalletElement,
|
|
41
|
+
WaaPSuiWallet: () => WaaPSuiWallet,
|
|
42
|
+
WaaPWalletConnect: () => SilkWalletConnect,
|
|
43
|
+
WalletMessageManager: () => WalletMessageManager,
|
|
44
|
+
handleWalletRequestAndResponse: () => handleWalletRequestAndResponse,
|
|
45
|
+
initWaaP: () => initWaaP,
|
|
46
|
+
initWaaPSui: () => initWaaPSui,
|
|
47
|
+
registerWaaPSuiWallet: () => registerWaaPSuiWallet,
|
|
48
|
+
rpcMethodRequiresUI: () => import_waap_constants.rpcMethodRequiresUI,
|
|
49
|
+
useWaapTransaction: () => useWaapTransaction
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(index_exports);
|
|
52
|
+
|
|
53
|
+
// src/ui/index.ts
|
|
54
|
+
var import_waap_constants3 = require("@human.tech/waap-constants");
|
|
55
|
+
|
|
56
|
+
// src/lib/provider/EthereumProvider.ts
|
|
57
|
+
var import_events2 = require("events");
|
|
58
|
+
var import_waap_interface_core2 = require("@human.tech/waap-interface-core");
|
|
59
|
+
|
|
60
|
+
// src/lib/UIMessageManager.ts
|
|
61
|
+
var import_events = require("events");
|
|
62
|
+
var UI_EVENT_NAMES = /* @__PURE__ */ ((UI_EVENT_NAMES2) => {
|
|
63
|
+
UI_EVENT_NAMES2["show_modal"] = "show_modal";
|
|
64
|
+
UI_EVENT_NAMES2["hide_modal"] = "hide_modal";
|
|
65
|
+
return UI_EVENT_NAMES2;
|
|
66
|
+
})(UI_EVENT_NAMES || {});
|
|
67
|
+
var UIMessageManager = class extends import_events.EventEmitter {
|
|
68
|
+
constructor() {
|
|
69
|
+
super();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/lib/provider/requests.ts
|
|
74
|
+
var import_waap_constants = require("@human.tech/waap-constants");
|
|
75
|
+
async function handleWalletRequestAndResponse(args, interactionRequired, walletMessageManager, internalProviderEventEmitter, silkOptions) {
|
|
76
|
+
const method = args.method;
|
|
77
|
+
const params = args.params;
|
|
78
|
+
const id = await walletMessageManager.postSilkRequest({
|
|
79
|
+
method,
|
|
80
|
+
params,
|
|
81
|
+
interactionRequired,
|
|
82
|
+
silkOptions
|
|
83
|
+
});
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
internalProviderEventEmitter.once(id, (response) => {
|
|
86
|
+
if (response.error) reject(response.error);
|
|
87
|
+
else resolve(response.data);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/lib/provider/utils.ts
|
|
93
|
+
function isMetaMask(provider) {
|
|
94
|
+
if (!(provider == null ? void 0 : provider.isMetaMask)) return false;
|
|
95
|
+
if (provider.isApexWallet) return false;
|
|
96
|
+
if (provider.isAvalanche) return false;
|
|
97
|
+
if (provider.isBitKeep) return false;
|
|
98
|
+
if (provider.isBlockWallet) return false;
|
|
99
|
+
if (provider.isMathWallet) return false;
|
|
100
|
+
if (provider.isOkxWallet || provider.isOKExWallet) return false;
|
|
101
|
+
if (provider.isOneInchIOSWallet || provider.isOneInchAndroidWallet) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (provider.isOpera) return false;
|
|
105
|
+
if (provider.isPortal) return false;
|
|
106
|
+
if (provider.isRabby) return false;
|
|
107
|
+
if (provider.isDefiant) return false;
|
|
108
|
+
if (provider.isTokenPocket) return false;
|
|
109
|
+
if (provider.isTokenary) return false;
|
|
110
|
+
if (provider.isZerion) return false;
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
function isSafeTransaction(params) {
|
|
114
|
+
var _a;
|
|
115
|
+
try {
|
|
116
|
+
if (!params || !Array.isArray(params)) return false;
|
|
117
|
+
const typedData = JSON.parse(
|
|
118
|
+
typeof params[1] === "string" ? params[1] : JSON.stringify(params[1])
|
|
119
|
+
);
|
|
120
|
+
return typedData.primaryType === "SafeTx" && ((_a = typedData.domain) == null ? void 0 : _a.verifyingContract) !== void 0 && typedData.message && "to" in typedData.message && "value" in typedData.message && "safeTxGas" in typedData.message && "baseGas" in typedData.message && "gasPrice" in typedData.message && "nonce" in typedData.message;
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var defaultConfig = {
|
|
126
|
+
styles: {
|
|
127
|
+
darkMode: false
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/lib/WalletConnect.ts
|
|
132
|
+
var import_appkit_adapter_ethers = require("@reown/appkit-adapter-ethers");
|
|
133
|
+
var SilkWalletConnect = class {
|
|
134
|
+
static instance = null;
|
|
135
|
+
static projectId = void 0;
|
|
136
|
+
// Ethereum, Optimism, Gnosis, Polygon, Base, Avalanche, Arbitrum, Celo, Base Sepolia, Sepolia
|
|
137
|
+
static chains = [
|
|
138
|
+
1,
|
|
139
|
+
10,
|
|
140
|
+
100,
|
|
141
|
+
137,
|
|
142
|
+
8453,
|
|
143
|
+
43114,
|
|
144
|
+
42161,
|
|
145
|
+
42220,
|
|
146
|
+
84532,
|
|
147
|
+
11155111
|
|
148
|
+
];
|
|
149
|
+
// private static optionalChains: AppKitNetwork[]
|
|
150
|
+
/**
|
|
151
|
+
* Set the WalletConnect project ID programmatically
|
|
152
|
+
* Use this if environment variables aren't working in your setup
|
|
153
|
+
*
|
|
154
|
+
* @param id - The WalletConnect project ID to use
|
|
155
|
+
*/
|
|
156
|
+
static setProjectId(id) {
|
|
157
|
+
this.projectId = id;
|
|
158
|
+
}
|
|
159
|
+
// /**
|
|
160
|
+
// * Set the optional chains to use for WalletConnect
|
|
161
|
+
// *
|
|
162
|
+
// * @param chains - The optional chains to use (number[])
|
|
163
|
+
// */
|
|
164
|
+
// static setOptionalChains(chains: AppKitNetwork[]) {
|
|
165
|
+
// SilkWalletConnect.optionalChains = chains
|
|
166
|
+
// }
|
|
167
|
+
static getProjectIdFromEnv() {
|
|
168
|
+
try {
|
|
169
|
+
if (typeof process !== "undefined" && process.env) {
|
|
170
|
+
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;
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
static async getInstance() {
|
|
178
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const { createAppKit } = await import("@reown/appkit");
|
|
182
|
+
const {
|
|
183
|
+
mainnet,
|
|
184
|
+
sepolia,
|
|
185
|
+
optimism,
|
|
186
|
+
arbitrum,
|
|
187
|
+
optimismGoerli,
|
|
188
|
+
polygon,
|
|
189
|
+
gnosis,
|
|
190
|
+
avalanche,
|
|
191
|
+
aurora,
|
|
192
|
+
fantom,
|
|
193
|
+
base,
|
|
194
|
+
celo
|
|
195
|
+
} = await import("@reown/appkit/networks");
|
|
196
|
+
try {
|
|
197
|
+
const metadata = {
|
|
198
|
+
name: "Human Wallet",
|
|
199
|
+
description: "Silk lets you create human keys for web3 wallets that are recoverable with private identity proofs and secured by zero trust protocols.",
|
|
200
|
+
url: window.location.origin,
|
|
201
|
+
// origin must match your domain & subdomain
|
|
202
|
+
icons: [
|
|
203
|
+
"https://imagedelivery.net/_aTEfDRm7z3tKgu9JhfeKA/f11f5753-616a-4aa0-2aee-9b75befea700/sm"
|
|
204
|
+
]
|
|
205
|
+
};
|
|
206
|
+
const projectId = this.projectId || this.getProjectIdFromEnv();
|
|
207
|
+
if (!projectId) {
|
|
208
|
+
console.error(
|
|
209
|
+
'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'
|
|
210
|
+
);
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
this.projectId = projectId;
|
|
214
|
+
if (!this.instance) {
|
|
215
|
+
this.instance = createAppKit({
|
|
216
|
+
adapters: [new import_appkit_adapter_ethers.EthersAdapter()],
|
|
217
|
+
projectId,
|
|
218
|
+
metadata,
|
|
219
|
+
networks: [
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
mainnet,
|
|
222
|
+
sepolia,
|
|
223
|
+
arbitrum,
|
|
224
|
+
optimism,
|
|
225
|
+
polygon,
|
|
226
|
+
gnosis,
|
|
227
|
+
avalanche,
|
|
228
|
+
aurora,
|
|
229
|
+
fantom,
|
|
230
|
+
base,
|
|
231
|
+
celo
|
|
232
|
+
],
|
|
233
|
+
features: {
|
|
234
|
+
socials: false,
|
|
235
|
+
email: false
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return this.instance;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
console.error("Error importing or initializing WalletConnect:", error);
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
static async listenToAccountChangeEvent() {
|
|
246
|
+
await new Promise((resolve) => {
|
|
247
|
+
const unsubscribe = this.instance.subscribeAccount(
|
|
248
|
+
(accountState) => {
|
|
249
|
+
if (accountState == null ? void 0 : accountState.isConnected) {
|
|
250
|
+
resolve();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Wait for WalletConnect to be properly initialized and connected
|
|
258
|
+
* @returns Promise<boolean> - true if connected, false if timeout reached
|
|
259
|
+
*/
|
|
260
|
+
static async waitForReadyAndCheckConnection() {
|
|
261
|
+
if (!this.instance) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
let isConnected = false;
|
|
265
|
+
let attempts = 0;
|
|
266
|
+
const maxAttempts = 15;
|
|
267
|
+
while (!isConnected && attempts < maxAttempts) {
|
|
268
|
+
const delay = attempts < 5 ? 500 : 1e3;
|
|
269
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
270
|
+
isConnected = this.instance.getIsConnectedState();
|
|
271
|
+
attempts++;
|
|
272
|
+
console.log(
|
|
273
|
+
`WalletConnect connection check attempt ${attempts}: ${isConnected}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
return isConnected;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Check if WalletConnect is currently connected (immediate check, no waiting)
|
|
280
|
+
* @returns boolean - true if connected, false otherwise
|
|
281
|
+
*/
|
|
282
|
+
static isConnected() {
|
|
283
|
+
var _a;
|
|
284
|
+
return ((_a = this.instance) == null ? void 0 : _a.getIsConnectedState()) ?? false;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Get the wallet provider from the WalletConnect instance
|
|
288
|
+
* @returns The wallet provider or null if not available
|
|
289
|
+
*/
|
|
290
|
+
static getWalletProvider() {
|
|
291
|
+
var _a;
|
|
292
|
+
return ((_a = this.instance) == null ? void 0 : _a.getWalletProvider()) ?? null;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/lib/WalletMessageManager.ts
|
|
297
|
+
var import_waap_interface_core = require("@human.tech/waap-interface-core");
|
|
298
|
+
var import_waap_constants2 = require("@human.tech/waap-constants");
|
|
299
|
+
var WalletMessageManager = class {
|
|
300
|
+
iframeWindow = null;
|
|
301
|
+
walletOrigin;
|
|
302
|
+
constructor(iframeWindow, useStaging) {
|
|
303
|
+
this.iframeWindow = iframeWindow;
|
|
304
|
+
this.walletOrigin = useStaging ? import_waap_constants2.silkWalletAppOrigin2Staging : import_waap_constants2.silkWalletAppOrigin2;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Post a Silk notification to the given iframeWindow
|
|
308
|
+
*/
|
|
309
|
+
postSilkNotification(data) {
|
|
310
|
+
this.iframeWindow.postMessage(
|
|
311
|
+
{
|
|
312
|
+
target: "silk",
|
|
313
|
+
messageType: import_waap_interface_core.SILK_MESSAGE_TYPE.notification,
|
|
314
|
+
data
|
|
315
|
+
},
|
|
316
|
+
this.walletOrigin
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
postReadyNotification() {
|
|
320
|
+
this.postSilkNotification(import_waap_interface_core.SILK_NOTIFICATION.ready);
|
|
321
|
+
}
|
|
322
|
+
postConnectNotification() {
|
|
323
|
+
this.postSilkNotification(import_waap_interface_core.SILK_NOTIFICATION.connect);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Post a 'ready' notification to the iframe, and wait
|
|
327
|
+
* for the iframe to respond with a 'ready' notification.
|
|
328
|
+
*/
|
|
329
|
+
pingIframe() {
|
|
330
|
+
return new Promise((resolve, reject) => {
|
|
331
|
+
setTimeout(() => reject("Wallet ping timed out."), 1e4);
|
|
332
|
+
const eventHandler = (event) => {
|
|
333
|
+
if (event.data.target === "silk" && event.data.messageType === import_waap_interface_core.SILK_MESSAGE_TYPE.notification && event.data.data === import_waap_interface_core.SILK_NOTIFICATION.ready) {
|
|
334
|
+
window.removeEventListener("message", eventHandler);
|
|
335
|
+
resolve();
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
window.addEventListener("message", eventHandler);
|
|
339
|
+
this.postReadyNotification();
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Post a SilkRequest to the iframeWindow. Don't wait for a response.
|
|
344
|
+
*/
|
|
345
|
+
async postSilkRequest(req) {
|
|
346
|
+
const { silkOptions, ...restReq } = req;
|
|
347
|
+
const baseRequest = {
|
|
348
|
+
...restReq,
|
|
349
|
+
target: "silk",
|
|
350
|
+
messageType: import_waap_interface_core.SILK_MESSAGE_TYPE.request,
|
|
351
|
+
// Include silkOptions for transaction methods
|
|
352
|
+
...silkOptions && { silkOptions }
|
|
353
|
+
};
|
|
354
|
+
const id = await (0, import_waap_interface_core.generateMessageId)(baseRequest);
|
|
355
|
+
this.iframeWindow.postMessage({ ...baseRequest, id }, this.walletOrigin);
|
|
356
|
+
return id;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Add a message listener to the window in which this is called (which should be the top frame).
|
|
360
|
+
* It handles all messages from the Silk iframe posted to the top frame.
|
|
361
|
+
* @param config - Configuration that includes callbacks for handling specific messages.
|
|
362
|
+
*/
|
|
363
|
+
addListener(config) {
|
|
364
|
+
const {
|
|
365
|
+
handleResponse,
|
|
366
|
+
handleRequest,
|
|
367
|
+
onReceiveConnectNotif,
|
|
368
|
+
onAccountChanged,
|
|
369
|
+
onAsyncTxNotification
|
|
370
|
+
} = config;
|
|
371
|
+
window.addEventListener("message", (event) => {
|
|
372
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
373
|
+
try {
|
|
374
|
+
const origin = typeof process !== "undefined" && process.env && process.env.NODE_ENV === "test" ? "http://127.0.0.1:3000" : event.origin;
|
|
375
|
+
if (origin !== this.walletOrigin) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (event.origin !== this.walletOrigin) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (((_a = event.data) == null ? void 0 : _a.messageType) === import_waap_interface_core.SILK_MESSAGE_TYPE.request) {
|
|
384
|
+
handleRequest(event.data);
|
|
385
|
+
} else if (((_b = event.data) == null ? void 0 : _b.messageType) === import_waap_interface_core.SILK_MESSAGE_TYPE.response) {
|
|
386
|
+
handleResponse(event.data);
|
|
387
|
+
} else if (((_c = event.data) == null ? void 0 : _c.messageType) === import_waap_interface_core.SILK_MESSAGE_TYPE.notification) {
|
|
388
|
+
if (((_d = event.data) == null ? void 0 : _d.data) === import_waap_interface_core.SILK_NOTIFICATION.connect) {
|
|
389
|
+
onReceiveConnectNotif == null ? void 0 : onReceiveConnectNotif();
|
|
390
|
+
} else if (((_f = (_e = event.data) == null ? void 0 : _e.data) == null ? void 0 : _f.type) === import_waap_interface_core.SILK_NOTIFICATION.account_changed && onAccountChanged) {
|
|
391
|
+
onAccountChanged(event.data.data.account);
|
|
392
|
+
} else if ((((_i = (_h = (_g = event.data) == null ? void 0 : _g.data) == null ? void 0 : _h.type) == null ? void 0 : _i.startsWith("waap_sign_")) || ((_l = (_k = (_j = event.data) == null ? void 0 : _j.data) == null ? void 0 : _k.type) == null ? void 0 : _l.startsWith("waap_tx_"))) && onAsyncTxNotification) {
|
|
393
|
+
onAsyncTxNotification({
|
|
394
|
+
type: event.data.data.type,
|
|
395
|
+
payload: event.data.data.payload
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var WalletMessageManager_default = WalletMessageManager;
|
|
403
|
+
|
|
404
|
+
// src/lib/provider/EthereumProvider.ts
|
|
405
|
+
var VALID_LOGIN_METHODS = [
|
|
406
|
+
"waap",
|
|
407
|
+
"human",
|
|
408
|
+
"injected",
|
|
409
|
+
"walletconnect"
|
|
410
|
+
];
|
|
411
|
+
function normalizeLoginResponse(response) {
|
|
412
|
+
if (response === null || response === void 0) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
if (typeof response === "string") {
|
|
416
|
+
if (VALID_LOGIN_METHODS.includes(response)) {
|
|
417
|
+
return response;
|
|
418
|
+
}
|
|
419
|
+
throw new Error(
|
|
420
|
+
`[EthereumProvider] Unexpected login method: "${response}". Expected one of: ${VALID_LOGIN_METHODS.join(", ")}`
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
if (typeof response === "object" && "loginMethod" in response && typeof response.loginMethod === "string") {
|
|
424
|
+
const method = response.loginMethod;
|
|
425
|
+
console.warn(
|
|
426
|
+
`[EthereumProvider] Received object login response. Normalizing "${method}" to string. This is unexpected for the web SDK.`
|
|
427
|
+
);
|
|
428
|
+
if (VALID_LOGIN_METHODS.includes(method)) {
|
|
429
|
+
return method;
|
|
430
|
+
}
|
|
431
|
+
throw new Error(
|
|
432
|
+
`[EthereumProvider] Unknown loginMethod in object: "${method}". Expected one of: ${VALID_LOGIN_METHODS.join(", ")}`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
throw new Error(
|
|
436
|
+
`[EthereumProvider] Unexpected login response: ${JSON.stringify(
|
|
437
|
+
response
|
|
438
|
+
)} (type: ${typeof response})`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
var EthereumProvider = class extends import_events2.EventEmitter {
|
|
442
|
+
isSilk = true;
|
|
443
|
+
isWaaP = true;
|
|
444
|
+
connected = false;
|
|
445
|
+
walletMessageManager;
|
|
446
|
+
uiMessageManager;
|
|
447
|
+
config;
|
|
448
|
+
currentAccount = null;
|
|
449
|
+
walletConnectProvider = null;
|
|
450
|
+
/**
|
|
451
|
+
* When true, eth_sendTransaction resolves with the pre-calculated tx hash
|
|
452
|
+
* after signing. Broadcasting continues in the background with events.
|
|
453
|
+
*/
|
|
454
|
+
asyncTxs = false;
|
|
455
|
+
/**
|
|
456
|
+
* When true, sends `asyncSigning: true` in silkOptions instead of `async: true`.
|
|
457
|
+
* This mimics the v1 SDK protocol for backward compatibility testing.
|
|
458
|
+
* @internal
|
|
459
|
+
*/
|
|
460
|
+
legacyAsyncSigning = false;
|
|
461
|
+
persistedMethods;
|
|
462
|
+
/**
|
|
463
|
+
* We use the internalEventEmitter to emit as events
|
|
464
|
+
* Silk messages posted to the window.
|
|
465
|
+
*/
|
|
466
|
+
internalEventEmitter = new import_events2.EventEmitter();
|
|
467
|
+
/**
|
|
468
|
+
* @param iframeWindow - The contentWindow of the iframe of the Silk website.
|
|
469
|
+
* @param referralCode - Silk points referral code
|
|
470
|
+
* @param customConfig - Silk custom UI configuration
|
|
471
|
+
* @param project - Silk project configuration
|
|
472
|
+
* @param useStaging - Whether to use the staging environment
|
|
473
|
+
* @param asyncTxs - When true, eth_sendTransaction resolves with tx hash after signing
|
|
474
|
+
* @param legacyAsyncSigning - When true, sends asyncSigning in silkOptions (v1 compat)
|
|
475
|
+
*/
|
|
476
|
+
constructor(iframeWindow, referralCode, customConfig, project, useStaging, asyncTxs = false, legacyAsyncSigning = false) {
|
|
477
|
+
super();
|
|
478
|
+
this.asyncTxs = asyncTxs;
|
|
479
|
+
this.legacyAsyncSigning = legacyAsyncSigning;
|
|
480
|
+
this.uiMessageManager = new UIMessageManager();
|
|
481
|
+
this.walletMessageManager = new WalletMessageManager_default(
|
|
482
|
+
iframeWindow,
|
|
483
|
+
!!useStaging
|
|
484
|
+
);
|
|
485
|
+
this.config = {
|
|
486
|
+
...defaultConfig,
|
|
487
|
+
...customConfig || {}
|
|
488
|
+
// Override with customConfig if provided
|
|
489
|
+
};
|
|
490
|
+
this.persistedMethods = {
|
|
491
|
+
login: this.login.bind(this),
|
|
492
|
+
logout: this.logout.bind(this),
|
|
493
|
+
getLoginMethod: this.getLoginMethod.bind(this),
|
|
494
|
+
walletMessageManager: this.walletMessageManager,
|
|
495
|
+
internalEventEmitter: this.internalEventEmitter,
|
|
496
|
+
uiMessageManager: this.uiMessageManager,
|
|
497
|
+
portal: this.portal.bind(this),
|
|
498
|
+
requestEmail: this.requestEmail.bind(this),
|
|
499
|
+
requestSBT: this.requestSBT.bind(this),
|
|
500
|
+
requestPermissionToken: this.requestPermissionToken.bind(this),
|
|
501
|
+
orcid: this.orcid.bind(this),
|
|
502
|
+
enable: this.enable.bind(this),
|
|
503
|
+
isConnected: this.isConnected.bind(this),
|
|
504
|
+
toggleDarkMode: this.toggleDarkMode.bind(this),
|
|
505
|
+
// We leave this silkRequest separate and never changing so that
|
|
506
|
+
// we can still call the original request method if needed no matter
|
|
507
|
+
// the current provider
|
|
508
|
+
silkRequest: this.request.bind(this),
|
|
509
|
+
waaPRequest: this.request.bind(this)
|
|
510
|
+
};
|
|
511
|
+
this.walletMessageManager.addListener({
|
|
512
|
+
onReceiveConnectNotif: () => {
|
|
513
|
+
console.log("onReceiveConnectNotif");
|
|
514
|
+
this.connected = true;
|
|
515
|
+
this.emit("connect");
|
|
516
|
+
},
|
|
517
|
+
handleResponse: (response) => this.internalEventEmitter.emit(response.id, response),
|
|
518
|
+
handleRequest: (request) => {
|
|
519
|
+
if (request.method === import_waap_interface_core2.SILK_METHOD.show_modal) {
|
|
520
|
+
this.uiMessageManager.emit("show_modal" /* show_modal */);
|
|
521
|
+
} else if (request.method === import_waap_interface_core2.SILK_METHOD.hide_modal) {
|
|
522
|
+
this.uiMessageManager.emit("hide_modal" /* hide_modal */);
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
onAccountChanged: (newAccount) => {
|
|
526
|
+
if (this.currentAccount !== newAccount) {
|
|
527
|
+
this.currentAccount = newAccount;
|
|
528
|
+
this.emit("accountsChanged", newAccount ? [newAccount] : []);
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
onAsyncTxNotification: (notification) => {
|
|
532
|
+
this.emit(notification.type, notification.payload);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
if (referralCode) {
|
|
536
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
537
|
+
return handleWalletRequestAndResponse(
|
|
538
|
+
{
|
|
539
|
+
method: import_waap_interface_core2.SILK_METHOD.set_points_referral_code,
|
|
540
|
+
params: [referralCode]
|
|
541
|
+
},
|
|
542
|
+
false,
|
|
543
|
+
this.walletMessageManager,
|
|
544
|
+
this.internalEventEmitter
|
|
545
|
+
);
|
|
546
|
+
}).catch((error) => {
|
|
547
|
+
console.error("Error setting referral code in Silk iframe:", error);
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
if (project) {
|
|
551
|
+
console.log(" =========== project =========== ", project);
|
|
552
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
553
|
+
return handleWalletRequestAndResponse(
|
|
554
|
+
{
|
|
555
|
+
method: import_waap_interface_core2.SILK_METHOD.set_project,
|
|
556
|
+
params: [project, window.location.origin]
|
|
557
|
+
},
|
|
558
|
+
false,
|
|
559
|
+
this.walletMessageManager,
|
|
560
|
+
this.internalEventEmitter
|
|
561
|
+
);
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (customConfig) {
|
|
565
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
566
|
+
return handleWalletRequestAndResponse(
|
|
567
|
+
{
|
|
568
|
+
method: import_waap_interface_core2.SILK_METHOD.set_custom_config,
|
|
569
|
+
params: [customConfig]
|
|
570
|
+
},
|
|
571
|
+
false,
|
|
572
|
+
this.walletMessageManager,
|
|
573
|
+
this.internalEventEmitter
|
|
574
|
+
);
|
|
575
|
+
}).catch((error) => {
|
|
576
|
+
console.error("Error setting custom config in Silk iframe:", error);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async initializeWalletConnect() {
|
|
581
|
+
try {
|
|
582
|
+
this.walletConnectProvider = await SilkWalletConnect.getInstance();
|
|
583
|
+
console.log("WalletConnect provider initialized");
|
|
584
|
+
} catch (error) {
|
|
585
|
+
console.error("Failed to initialize WalletConnect provider:", error);
|
|
586
|
+
this.walletConnectProvider = null;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
async enable() {
|
|
590
|
+
return this.request({ method: "eth_requestAccounts" });
|
|
591
|
+
}
|
|
592
|
+
isConnected() {
|
|
593
|
+
return this.connected;
|
|
594
|
+
}
|
|
595
|
+
async request(args) {
|
|
596
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
597
|
+
if (!Object.keys(import_waap_interface_core2.JSON_RPC_METHOD).includes(
|
|
598
|
+
args.method
|
|
599
|
+
)) {
|
|
600
|
+
return Promise.reject({ error: `Not implemented (${args.method})` });
|
|
601
|
+
}
|
|
602
|
+
const autoConnectResult = await this.attemptAutoConnect(args.method);
|
|
603
|
+
if (autoConnectResult !== null) {
|
|
604
|
+
return autoConnectResult;
|
|
605
|
+
}
|
|
606
|
+
const isSafeTx = isSafeTransaction(args.params);
|
|
607
|
+
if (isSafeTx) {
|
|
608
|
+
if (args.method !== import_waap_interface_core2.JSON_RPC_METHOD.eth_signTypedData_v4) {
|
|
609
|
+
return Promise.reject({
|
|
610
|
+
error: "Safe transactions must be signed using eth_signTypedData_v4"
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
await this.walletMessageManager.pingIframe();
|
|
615
|
+
const isTxMethod = args.method === import_waap_interface_core2.JSON_RPC_METHOD.eth_sendTransaction || args.method === import_waap_interface_core2.JSON_RPC_METHOD.eth_signTransaction || args.method === import_waap_interface_core2.JSON_RPC_METHOD.eth_signTypedData_v4 || args.method === import_waap_interface_core2.JSON_RPC_METHOD.personal_sign;
|
|
616
|
+
const isAsync = isTxMethod && this.asyncTxs || args.async;
|
|
617
|
+
const silkOptions = isAsync || args.withPT ? this.legacyAsyncSigning ? {
|
|
618
|
+
// v1 SDK protocol: send asyncSigning instead of async
|
|
619
|
+
asyncSigning: isAsync || void 0,
|
|
620
|
+
withPT: args.withPT
|
|
621
|
+
} : {
|
|
622
|
+
async: isAsync,
|
|
623
|
+
withPT: args.withPT
|
|
624
|
+
} : void 0;
|
|
625
|
+
const response = await handleWalletRequestAndResponse(
|
|
626
|
+
args,
|
|
627
|
+
(0, import_waap_constants.rpcMethodRequiresUI)(args.method),
|
|
628
|
+
this.walletMessageManager,
|
|
629
|
+
this.internalEventEmitter,
|
|
630
|
+
silkOptions
|
|
631
|
+
);
|
|
632
|
+
if ((args.method === import_waap_interface_core2.JSON_RPC_METHOD.wallet_switchEthereumChain || args.method === import_waap_interface_core2.JSON_RPC_METHOD.wallet_addEthereumChain) && response === null) {
|
|
633
|
+
this.emit(
|
|
634
|
+
"chainChanged",
|
|
635
|
+
(_b = (_a = args.params) == null ? void 0 : _a[0]) == null ? void 0 : _b.chainId
|
|
636
|
+
);
|
|
637
|
+
try {
|
|
638
|
+
const accounts = await this.request({
|
|
639
|
+
method: "eth_accounts"
|
|
640
|
+
});
|
|
641
|
+
if (accounts && accounts.length > 0) {
|
|
642
|
+
this.currentAccount = accounts[0];
|
|
643
|
+
this.emit("accountsChanged", accounts);
|
|
644
|
+
this.emit("connect", {
|
|
645
|
+
chainId: (_d = (_c = args.params) == null ? void 0 : _c[0]) == null ? void 0 : _d.chainId
|
|
646
|
+
});
|
|
647
|
+
console.log(
|
|
648
|
+
"[EthereumProvider] Re-emitted accounts and connect after chain switch:",
|
|
649
|
+
{
|
|
650
|
+
accounts,
|
|
651
|
+
chainId: (_f = (_e = args.params) == null ? void 0 : _e[0]) == null ? void 0 : _f.chainId
|
|
652
|
+
}
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
} catch (error) {
|
|
656
|
+
console.warn(
|
|
657
|
+
"[EthereumProvider] Failed to get accounts after chain switch:",
|
|
658
|
+
error
|
|
659
|
+
);
|
|
660
|
+
if (this.currentAccount) {
|
|
661
|
+
this.emit("accountsChanged", [this.currentAccount]);
|
|
662
|
+
this.emit("connect", {
|
|
663
|
+
chainId: (_h = (_g = args.params) == null ? void 0 : _g[0]) == null ? void 0 : _h.chainId
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return response;
|
|
669
|
+
}
|
|
670
|
+
async login(customProvider) {
|
|
671
|
+
var _a;
|
|
672
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
if (((_a = this.config.authenticationMethods) == null ? void 0 : _a.includes("wallet")) && !this.walletConnectProvider) {
|
|
676
|
+
await this.initializeWalletConnect();
|
|
677
|
+
}
|
|
678
|
+
const provider = customProvider || window.ethereum;
|
|
679
|
+
const providerWalletName = provider && isMetaMask(provider) ? "MetaMask" : "Browser Wallet";
|
|
680
|
+
await this.walletMessageManager.pingIframe();
|
|
681
|
+
const rawResponse = await handleWalletRequestAndResponse(
|
|
682
|
+
{ method: import_waap_interface_core2.SILK_METHOD.login, params: [providerWalletName] },
|
|
683
|
+
true,
|
|
684
|
+
this.walletMessageManager,
|
|
685
|
+
this.internalEventEmitter
|
|
686
|
+
);
|
|
687
|
+
const loginMethod = normalizeLoginResponse(rawResponse);
|
|
688
|
+
if (loginMethod === null) {
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
switch (loginMethod) {
|
|
692
|
+
case "waap":
|
|
693
|
+
case "human":
|
|
694
|
+
localStorage.setItem(`${window.location.origin}-connected`, "waap");
|
|
695
|
+
this.setupWaaP();
|
|
696
|
+
break;
|
|
697
|
+
case "injected":
|
|
698
|
+
if (provider) {
|
|
699
|
+
localStorage.setItem(
|
|
700
|
+
`${window.location.origin}-connected`,
|
|
701
|
+
"injected"
|
|
702
|
+
);
|
|
703
|
+
this.setupInjectedWallet(provider);
|
|
704
|
+
}
|
|
705
|
+
break;
|
|
706
|
+
case "walletconnect": {
|
|
707
|
+
localStorage.setItem(
|
|
708
|
+
`${window.location.origin}-connected`,
|
|
709
|
+
"walletconnect"
|
|
710
|
+
);
|
|
711
|
+
if (!SilkWalletConnect.isConnected()) {
|
|
712
|
+
await this.walletConnectProvider.open({ view: "Connect" });
|
|
713
|
+
await SilkWalletConnect.listenToAccountChangeEvent();
|
|
714
|
+
}
|
|
715
|
+
const wcProvider = SilkWalletConnect.getWalletProvider();
|
|
716
|
+
this.setupWalletConnect(wcProvider);
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return loginMethod;
|
|
721
|
+
}
|
|
722
|
+
async logout() {
|
|
723
|
+
await this.walletMessageManager.pingIframe();
|
|
724
|
+
this.cleanupInvalidLoginState();
|
|
725
|
+
try {
|
|
726
|
+
if (this.walletConnectProvider) {
|
|
727
|
+
await this.walletConnectProvider.disconnect();
|
|
728
|
+
}
|
|
729
|
+
} catch (error) {
|
|
730
|
+
console.error("Error disconnecting from WalletConnect:", error);
|
|
731
|
+
}
|
|
732
|
+
return handleWalletRequestAndResponse(
|
|
733
|
+
{ method: import_waap_interface_core2.SILK_METHOD.logout },
|
|
734
|
+
false,
|
|
735
|
+
this.walletMessageManager,
|
|
736
|
+
this.internalEventEmitter
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
cleanupInvalidLoginState() {
|
|
740
|
+
try {
|
|
741
|
+
localStorage.removeItem(`${window.location.origin}-connected`);
|
|
742
|
+
} catch (error) {
|
|
743
|
+
console.warn("Could not clean up login state:", error);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Helper method to set up window.waap for WaaP
|
|
748
|
+
*/
|
|
749
|
+
setupWaaP() {
|
|
750
|
+
const provider = {
|
|
751
|
+
...this.persistedMethods,
|
|
752
|
+
isWaaP: true,
|
|
753
|
+
on: this.on.bind(this),
|
|
754
|
+
removeListener: this.removeListener.bind(this),
|
|
755
|
+
request: this.request.bind(this)
|
|
756
|
+
};
|
|
757
|
+
window.silk = provider;
|
|
758
|
+
window.waap = provider;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Helper method to set up window.silk for injected wallets (e.g., MetaMask)
|
|
762
|
+
*/
|
|
763
|
+
setupInjectedWallet(provider) {
|
|
764
|
+
var _a, _b;
|
|
765
|
+
const injectedProvider = {
|
|
766
|
+
...this.persistedMethods,
|
|
767
|
+
...provider,
|
|
768
|
+
isSilk: true,
|
|
769
|
+
connected: provider.connected ?? false,
|
|
770
|
+
on: ((_a = provider.on) == null ? void 0 : _a.bind(provider)) ?? (() => {
|
|
771
|
+
}),
|
|
772
|
+
removeListener: ((_b = provider.removeListener) == null ? void 0 : _b.bind(provider)) ?? (() => {
|
|
773
|
+
}),
|
|
774
|
+
request: provider.request.bind(provider)
|
|
775
|
+
};
|
|
776
|
+
window.silk = injectedProvider;
|
|
777
|
+
window.waap = injectedProvider;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Helper method to set up window.silk for WalletConnect
|
|
781
|
+
*/
|
|
782
|
+
setupWalletConnect(provider) {
|
|
783
|
+
var _a, _b;
|
|
784
|
+
const walletConnectProvider = {
|
|
785
|
+
...this.persistedMethods,
|
|
786
|
+
...provider,
|
|
787
|
+
isSilk: true,
|
|
788
|
+
connected: true,
|
|
789
|
+
on: ((_a = provider.on) == null ? void 0 : _a.bind(provider)) ?? (() => {
|
|
790
|
+
}),
|
|
791
|
+
removeListener: ((_b = provider.removeListener) == null ? void 0 : _b.bind(provider)) ?? (() => {
|
|
792
|
+
}),
|
|
793
|
+
request: provider.request.bind(provider)
|
|
794
|
+
};
|
|
795
|
+
window.silk = walletConnectProvider;
|
|
796
|
+
window.waap = walletConnectProvider;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Helper method to set up window.silk for auto-connect with injected wallets
|
|
800
|
+
*/
|
|
801
|
+
setupAutoConnectInjected(provider) {
|
|
802
|
+
var _a, _b, _c;
|
|
803
|
+
const injectedProvider = {
|
|
804
|
+
...this.persistedMethods,
|
|
805
|
+
...provider,
|
|
806
|
+
isSilk: false,
|
|
807
|
+
// @ts-ignore
|
|
808
|
+
connected: ((_a = provider.isConnected) == null ? void 0 : _a.call(provider)) ?? false,
|
|
809
|
+
// @ts-ignore
|
|
810
|
+
on: ((_b = provider.on) == null ? void 0 : _b.bind(provider)) ?? (() => {
|
|
811
|
+
}),
|
|
812
|
+
removeListener: (
|
|
813
|
+
// @ts-ignore
|
|
814
|
+
((_c = provider.removeListener) == null ? void 0 : _c.bind(provider)) ?? (() => {
|
|
815
|
+
})
|
|
816
|
+
),
|
|
817
|
+
// @ts-ignore
|
|
818
|
+
request: provider.request.bind(provider)
|
|
819
|
+
};
|
|
820
|
+
window.silk = injectedProvider;
|
|
821
|
+
window.waap = injectedProvider;
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Helper method to set up window.silk for auto-connect with WalletConnect
|
|
825
|
+
*/
|
|
826
|
+
setupAutoConnectWalletConnect(provider) {
|
|
827
|
+
var _a, _b;
|
|
828
|
+
const walletConnectProvider = {
|
|
829
|
+
...this.persistedMethods,
|
|
830
|
+
...provider,
|
|
831
|
+
isSilk: false,
|
|
832
|
+
connected: true,
|
|
833
|
+
on: ((_a = provider.on) == null ? void 0 : _a.bind(provider)) ?? (() => {
|
|
834
|
+
}),
|
|
835
|
+
removeListener: ((_b = provider.removeListener) == null ? void 0 : _b.bind(provider)) ?? (() => {
|
|
836
|
+
}),
|
|
837
|
+
request: provider.request.bind(provider)
|
|
838
|
+
};
|
|
839
|
+
window.silk = walletConnectProvider;
|
|
840
|
+
window.waap = walletConnectProvider;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Attempts to auto-connect using previously stored login method
|
|
844
|
+
* @param method - The RPC method being called
|
|
845
|
+
* @returns Promise<unknown> if auto-connect succeeds, null if it should fall through to normal flow
|
|
846
|
+
*/
|
|
847
|
+
async attemptAutoConnect(method) {
|
|
848
|
+
if (method !== "eth_requestAccounts" && method !== "eth_accounts") {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
this.walletMessageManager.pingIframe().then(async () => {
|
|
852
|
+
await handleWalletRequestAndResponse(
|
|
853
|
+
{
|
|
854
|
+
method: import_waap_interface_core2.SILK_METHOD.auto_conn,
|
|
855
|
+
params: [window.location.origin]
|
|
856
|
+
},
|
|
857
|
+
false,
|
|
858
|
+
this.walletMessageManager,
|
|
859
|
+
this.internalEventEmitter
|
|
860
|
+
);
|
|
861
|
+
});
|
|
862
|
+
const loginMethod = this.getLoginMethod();
|
|
863
|
+
if (loginMethod === "injected" && window.ethereum) {
|
|
864
|
+
try {
|
|
865
|
+
this.setupAutoConnectInjected(window.ethereum);
|
|
866
|
+
return window.ethereum.request({
|
|
867
|
+
method: "eth_requestAccounts"
|
|
868
|
+
});
|
|
869
|
+
} catch (error) {
|
|
870
|
+
console.warn("Injected wallet auto-connect failed:", error);
|
|
871
|
+
this.cleanupInvalidLoginState();
|
|
872
|
+
return null;
|
|
873
|
+
}
|
|
874
|
+
} else if (loginMethod === "walletconnect") {
|
|
875
|
+
try {
|
|
876
|
+
if (!this.walletConnectProvider) {
|
|
877
|
+
this.walletConnectProvider = await SilkWalletConnect.getInstance();
|
|
878
|
+
}
|
|
879
|
+
const isConnected = await SilkWalletConnect.waitForReadyAndCheckConnection();
|
|
880
|
+
if (isConnected) {
|
|
881
|
+
const provider = SilkWalletConnect.getWalletProvider();
|
|
882
|
+
this.setupAutoConnectWalletConnect(provider);
|
|
883
|
+
return provider.request({
|
|
884
|
+
method: "eth_requestAccounts"
|
|
885
|
+
});
|
|
886
|
+
} else {
|
|
887
|
+
console.log(
|
|
888
|
+
"WalletConnect not connected, cleaning up and falling through to normal flow"
|
|
889
|
+
);
|
|
890
|
+
this.cleanupInvalidLoginState();
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
} catch (error) {
|
|
894
|
+
console.warn("WalletConnect auto-connect failed:", error);
|
|
895
|
+
this.cleanupInvalidLoginState();
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
getLoginMethod() {
|
|
902
|
+
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
try {
|
|
906
|
+
const stored = localStorage.getItem(`${window.location.origin}-connected`);
|
|
907
|
+
if (!stored) {
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
if (!["waap", "human", "injected", "walletconnect"].includes(stored)) {
|
|
911
|
+
this.cleanupInvalidLoginState();
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
switch (stored) {
|
|
915
|
+
case "injected":
|
|
916
|
+
if (!window.ethereum) {
|
|
917
|
+
this.cleanupInvalidLoginState();
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
return "injected";
|
|
921
|
+
case "walletconnect":
|
|
922
|
+
try {
|
|
923
|
+
if (!SilkWalletConnect.isConnected()) {
|
|
924
|
+
this.cleanupInvalidLoginState();
|
|
925
|
+
return null;
|
|
926
|
+
}
|
|
927
|
+
return "walletconnect";
|
|
928
|
+
} catch (error) {
|
|
929
|
+
this.cleanupInvalidLoginState();
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
case "waap":
|
|
933
|
+
return "waap";
|
|
934
|
+
case "human":
|
|
935
|
+
return "human";
|
|
936
|
+
default:
|
|
937
|
+
this.cleanupInvalidLoginState();
|
|
938
|
+
return null;
|
|
939
|
+
}
|
|
940
|
+
} catch (error) {
|
|
941
|
+
console.warn("Error checking login method:", error);
|
|
942
|
+
this.cleanupInvalidLoginState();
|
|
943
|
+
return null;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
async toggleDarkMode() {
|
|
947
|
+
this.config.styles.darkMode = !this.config.styles.darkMode;
|
|
948
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
949
|
+
return handleWalletRequestAndResponse(
|
|
950
|
+
{
|
|
951
|
+
method: import_waap_interface_core2.SILK_METHOD.set_custom_config,
|
|
952
|
+
params: [this.config]
|
|
953
|
+
},
|
|
954
|
+
false,
|
|
955
|
+
this.walletMessageManager,
|
|
956
|
+
this.internalEventEmitter
|
|
957
|
+
);
|
|
958
|
+
}).catch((error) => {
|
|
959
|
+
console.error("Error setting custom config in Silk iframe:", error);
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
async safe() {
|
|
963
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
964
|
+
return handleWalletRequestAndResponse(
|
|
965
|
+
{ method: import_waap_interface_core2.SILK_METHOD.safe },
|
|
966
|
+
true,
|
|
967
|
+
this.walletMessageManager,
|
|
968
|
+
this.internalEventEmitter
|
|
969
|
+
);
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
async orcid() {
|
|
973
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
974
|
+
return handleWalletRequestAndResponse(
|
|
975
|
+
{ method: import_waap_interface_core2.SILK_METHOD.orcid },
|
|
976
|
+
true,
|
|
977
|
+
this.walletMessageManager,
|
|
978
|
+
this.internalEventEmitter
|
|
979
|
+
);
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* INTERNAL METHOD: Gas tank administration operations
|
|
984
|
+
* This method is ONLY accessible from the Dev Portal domain
|
|
985
|
+
* It's not included in the public typing to hide it from regular dApps
|
|
986
|
+
*/
|
|
987
|
+
async portal(feature, operation, payload) {
|
|
988
|
+
await this.walletMessageManager.pingIframe();
|
|
989
|
+
let methodName;
|
|
990
|
+
switch (operation) {
|
|
991
|
+
case "get":
|
|
992
|
+
methodName = feature === "gastank" ? import_waap_interface_core2.SILK_METHOD.gastank_get_settings : import_waap_interface_core2.SILK_METHOD.customization_get;
|
|
993
|
+
break;
|
|
994
|
+
case "update":
|
|
995
|
+
methodName = feature === "gastank" ? import_waap_interface_core2.SILK_METHOD.gastank_update_settings : import_waap_interface_core2.SILK_METHOD.customization_update;
|
|
996
|
+
break;
|
|
997
|
+
case "topup":
|
|
998
|
+
methodName = import_waap_interface_core2.SILK_METHOD.gastank_topup;
|
|
999
|
+
break;
|
|
1000
|
+
case "init":
|
|
1001
|
+
methodName = import_waap_interface_core2.SILK_METHOD.project_init;
|
|
1002
|
+
break;
|
|
1003
|
+
}
|
|
1004
|
+
const interactionRequired = operation !== "get" && feature !== "customization";
|
|
1005
|
+
return handleWalletRequestAndResponse(
|
|
1006
|
+
{
|
|
1007
|
+
method: methodName,
|
|
1008
|
+
params: [payload, window.location.origin]
|
|
1009
|
+
},
|
|
1010
|
+
interactionRequired,
|
|
1011
|
+
// Only open modal for update operations
|
|
1012
|
+
this.walletMessageManager,
|
|
1013
|
+
this.internalEventEmitter
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
async requestEmail() {
|
|
1017
|
+
await this.walletMessageManager.pingIframe();
|
|
1018
|
+
return handleWalletRequestAndResponse(
|
|
1019
|
+
{ method: import_waap_interface_core2.SILK_METHOD.silk_requestEmail },
|
|
1020
|
+
true,
|
|
1021
|
+
this.walletMessageManager,
|
|
1022
|
+
this.internalEventEmitter
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Request a Permission Token from the user.
|
|
1027
|
+
* Allows pre-authorized transactions without individual confirmations.
|
|
1028
|
+
* @param params - Permission token parameters (allowed addresses, chain, limits, expiry)
|
|
1029
|
+
* @returns Promise<RequestPermissionTokenResult>
|
|
1030
|
+
*/
|
|
1031
|
+
async requestPermissionToken(params) {
|
|
1032
|
+
await this.walletMessageManager.pingIframe();
|
|
1033
|
+
return handleWalletRequestAndResponse(
|
|
1034
|
+
{
|
|
1035
|
+
method: import_waap_interface_core2.SILK_METHOD.waap_requestPermissionToken,
|
|
1036
|
+
params: [params]
|
|
1037
|
+
},
|
|
1038
|
+
true,
|
|
1039
|
+
// Requires UI for user approval
|
|
1040
|
+
this.walletMessageManager,
|
|
1041
|
+
this.internalEventEmitter
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Prompt the user to mint a Zeronym SBT.
|
|
1046
|
+
* @returns string or null - The address of the owner of the SBT, or null
|
|
1047
|
+
* if the user already minted the SBT.
|
|
1048
|
+
*/
|
|
1049
|
+
async requestSBT(type) {
|
|
1050
|
+
await this.walletMessageManager.pingIframe();
|
|
1051
|
+
return handleWalletRequestAndResponse(
|
|
1052
|
+
{
|
|
1053
|
+
method: import_waap_interface_core2.SILK_METHOD.silk_requestSbt,
|
|
1054
|
+
params: [type]
|
|
1055
|
+
},
|
|
1056
|
+
true,
|
|
1057
|
+
this.walletMessageManager,
|
|
1058
|
+
this.internalEventEmitter
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
// src/ui/WaapComponent.ts
|
|
1064
|
+
var WAAP_COMPONENT_TAG_NAME = "waap-wallet";
|
|
1065
|
+
var WAAP_COMPONENT_CONTAINER_ID = "waap-component-container";
|
|
1066
|
+
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined" && typeof HTMLElement !== "undefined";
|
|
1067
|
+
var WaapWalletElement;
|
|
1068
|
+
if (isBrowser) {
|
|
1069
|
+
WaapWalletElement = class extends HTMLElement {
|
|
1070
|
+
constructor() {
|
|
1071
|
+
super();
|
|
1072
|
+
if (!this.style.display || this.style.display === "") {
|
|
1073
|
+
this.style.display = "flex";
|
|
1074
|
+
this.style.alignItems = "center";
|
|
1075
|
+
this.style.justifyContent = "center";
|
|
1076
|
+
}
|
|
1077
|
+
if (!this.style.width || this.style.width === "") {
|
|
1078
|
+
this.style.width = "100%";
|
|
1079
|
+
}
|
|
1080
|
+
if (!this.style.height || this.style.height === "") {
|
|
1081
|
+
this.style.height = "100%";
|
|
1082
|
+
}
|
|
1083
|
+
this.id = WAAP_COMPONENT_CONTAINER_ID;
|
|
1084
|
+
}
|
|
1085
|
+
connectedCallback() {
|
|
1086
|
+
this.setAttribute("data-waap-mounted", "true");
|
|
1087
|
+
}
|
|
1088
|
+
disconnectedCallback() {
|
|
1089
|
+
this.removeAttribute("data-waap-mounted");
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
if (typeof customElements !== "undefined" && !customElements.get(WAAP_COMPONENT_TAG_NAME)) {
|
|
1093
|
+
customElements.define(WAAP_COMPONENT_TAG_NAME, WaapWalletElement);
|
|
1094
|
+
}
|
|
1095
|
+
} else {
|
|
1096
|
+
WaapWalletElement = class {
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function hasWaapComponent() {
|
|
1100
|
+
if (!isBrowser) return false;
|
|
1101
|
+
return !!document.getElementById(WAAP_COMPONENT_CONTAINER_ID) || !!document.querySelector(WAAP_COMPONENT_TAG_NAME);
|
|
1102
|
+
}
|
|
1103
|
+
function getWaapComponentContainer() {
|
|
1104
|
+
if (!isBrowser) return null;
|
|
1105
|
+
return document.getElementById(WAAP_COMPONENT_CONTAINER_ID) || document.querySelector(WAAP_COMPONENT_TAG_NAME);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/ui/index.ts
|
|
1109
|
+
var LEGACY_IFRAME_CONTAINER_ID = "silk-wallet-iframe-container";
|
|
1110
|
+
var LEGACY_IFRAME_WRAPPER_ID = "silk-wallet-iframe-wrapper";
|
|
1111
|
+
var LEGACY_IFRAME_ID = "silk-wallet-iframe";
|
|
1112
|
+
var NEW_IFRAME_CONTAINER_ID = "waap-wallet-iframe-container";
|
|
1113
|
+
var NEW_IFRAME_WRAPPER_ID = "waap-wallet-iframe-wrapper";
|
|
1114
|
+
var NEW_IFRAME_ID = "waap-wallet-iframe";
|
|
1115
|
+
var getIframeContainer = () => {
|
|
1116
|
+
return document.getElementById(NEW_IFRAME_CONTAINER_ID) || document.getElementById(LEGACY_IFRAME_CONTAINER_ID);
|
|
1117
|
+
};
|
|
1118
|
+
var getIframeWrapper = () => {
|
|
1119
|
+
return document.getElementById(NEW_IFRAME_WRAPPER_ID) || document.getElementById(LEGACY_IFRAME_WRAPPER_ID);
|
|
1120
|
+
};
|
|
1121
|
+
var getIframe = () => {
|
|
1122
|
+
return document.getElementById(NEW_IFRAME_ID) || document.getElementById(LEGACY_IFRAME_ID);
|
|
1123
|
+
};
|
|
1124
|
+
var iframeContainerId = NEW_IFRAME_CONTAINER_ID;
|
|
1125
|
+
var iframeWrapperId = NEW_IFRAME_WRAPPER_ID;
|
|
1126
|
+
var iframeId = NEW_IFRAME_ID;
|
|
1127
|
+
var createIframeElement = (useStaging) => {
|
|
1128
|
+
const iframe = window.document.createElement("iframe");
|
|
1129
|
+
iframe.id = iframeId;
|
|
1130
|
+
iframe.src = `${useStaging ? import_waap_constants3.silkWalletAppOrigin2Staging : import_waap_constants3.silkWalletAppOrigin2}/iframe`;
|
|
1131
|
+
console.log("iframe.src: ", iframe.src);
|
|
1132
|
+
iframe.style.width = "100%";
|
|
1133
|
+
iframe.style.height = "100%";
|
|
1134
|
+
iframe.style.border = "none";
|
|
1135
|
+
iframe.style.borderRadius = "24px";
|
|
1136
|
+
iframe.style.backgroundColor = "transparent";
|
|
1137
|
+
iframe.style.background = "transparent";
|
|
1138
|
+
iframe.style.padding = "0";
|
|
1139
|
+
iframe.style.margin = "0";
|
|
1140
|
+
return iframe;
|
|
1141
|
+
};
|
|
1142
|
+
var setupIframeMessageListener = (useStaging, iframe) => {
|
|
1143
|
+
const handleIframeMessage = (event) => {
|
|
1144
|
+
const expectedOrigin = useStaging ? import_waap_constants3.silkWalletAppOrigin2Staging : import_waap_constants3.silkWalletAppOrigin2;
|
|
1145
|
+
if (event.origin !== expectedOrigin) return;
|
|
1146
|
+
if (!event.data || typeof event.data !== "object") return;
|
|
1147
|
+
if (event.data.type !== "silk-iframe-size") return;
|
|
1148
|
+
const contentHeight = event.data.height;
|
|
1149
|
+
const contentWidth = event.data.width;
|
|
1150
|
+
const maxDimension = 2e3;
|
|
1151
|
+
const minDimension = 50;
|
|
1152
|
+
if (typeof contentHeight !== "number" || typeof contentWidth !== "number")
|
|
1153
|
+
return;
|
|
1154
|
+
if (contentHeight < minDimension || contentHeight > maxDimension) return;
|
|
1155
|
+
if (contentWidth < minDimension || contentWidth > maxDimension) return;
|
|
1156
|
+
if (!Number.isFinite(contentHeight) || !Number.isFinite(contentWidth))
|
|
1157
|
+
return;
|
|
1158
|
+
const iframeWrapper = getIframeWrapper();
|
|
1159
|
+
if (!iframeWrapper) return;
|
|
1160
|
+
iframeWrapper.style.height = `${Math.floor(contentHeight)}px`;
|
|
1161
|
+
iframeWrapper.style.width = `${Math.floor(contentWidth)}px`;
|
|
1162
|
+
};
|
|
1163
|
+
window.addEventListener("message", handleIframeMessage);
|
|
1164
|
+
iframe.__silkCleanup = () => {
|
|
1165
|
+
window.removeEventListener("message", handleIframeMessage);
|
|
1166
|
+
};
|
|
1167
|
+
};
|
|
1168
|
+
var createComponentModeIframe = (useStaging) => {
|
|
1169
|
+
const componentContainer = getWaapComponentContainer();
|
|
1170
|
+
if (!componentContainer) {
|
|
1171
|
+
throw new Error("WaaP component not found in DOM");
|
|
1172
|
+
}
|
|
1173
|
+
if (getIframe()) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
const iframeWrapper = window.document.createElement("div");
|
|
1177
|
+
iframeWrapper.id = iframeWrapperId;
|
|
1178
|
+
iframeWrapper.style.position = "relative";
|
|
1179
|
+
iframeWrapper.style.display = "flex";
|
|
1180
|
+
iframeWrapper.style.alignItems = "center";
|
|
1181
|
+
iframeWrapper.style.justifyContent = "center";
|
|
1182
|
+
iframeWrapper.style.padding = "0";
|
|
1183
|
+
iframeWrapper.style.margin = "0";
|
|
1184
|
+
iframeWrapper.style.height = "600px";
|
|
1185
|
+
iframeWrapper.style.width = "380px";
|
|
1186
|
+
const iframe = createIframeElement(useStaging);
|
|
1187
|
+
setupIframeMessageListener(useStaging, iframe);
|
|
1188
|
+
setTimeout(() => {
|
|
1189
|
+
const wrapper = getIframeWrapper();
|
|
1190
|
+
if (wrapper) {
|
|
1191
|
+
wrapper.style.height = "600px";
|
|
1192
|
+
wrapper.style.width = "380px";
|
|
1193
|
+
}
|
|
1194
|
+
}, 100);
|
|
1195
|
+
iframeWrapper.appendChild(iframe);
|
|
1196
|
+
componentContainer.appendChild(iframeWrapper);
|
|
1197
|
+
};
|
|
1198
|
+
var createModalModeIframe = (useStaging) => {
|
|
1199
|
+
if (getIframeContainer()) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
const container = window.document.createElement("div");
|
|
1203
|
+
container.id = iframeContainerId;
|
|
1204
|
+
container.style.position = "fixed";
|
|
1205
|
+
container.style.top = "0";
|
|
1206
|
+
container.style.left = "0";
|
|
1207
|
+
container.style.right = "0";
|
|
1208
|
+
container.style.bottom = "0";
|
|
1209
|
+
container.style.width = "100%";
|
|
1210
|
+
container.style.height = "100%";
|
|
1211
|
+
container.style.display = "flex";
|
|
1212
|
+
container.style.alignItems = "center";
|
|
1213
|
+
container.style.justifyContent = "center";
|
|
1214
|
+
container.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
1215
|
+
container.style.zIndex = "9999999999";
|
|
1216
|
+
container.style.display = "none";
|
|
1217
|
+
const iframeWrapper = window.document.createElement("div");
|
|
1218
|
+
iframeWrapper.id = iframeWrapperId;
|
|
1219
|
+
iframeWrapper.style.position = "relative";
|
|
1220
|
+
iframeWrapper.style.display = "flex";
|
|
1221
|
+
iframeWrapper.style.alignItems = "center";
|
|
1222
|
+
iframeWrapper.style.justifyContent = "center";
|
|
1223
|
+
iframeWrapper.style.padding = "0";
|
|
1224
|
+
iframeWrapper.style.margin = "0";
|
|
1225
|
+
iframeWrapper.style.height = "600px";
|
|
1226
|
+
iframeWrapper.style.width = "380px";
|
|
1227
|
+
container.appendChild(iframeWrapper);
|
|
1228
|
+
const iframe = createIframeElement(useStaging);
|
|
1229
|
+
setupIframeMessageListener(useStaging, iframe);
|
|
1230
|
+
setTimeout(() => {
|
|
1231
|
+
const wrapper = getIframeWrapper();
|
|
1232
|
+
if (wrapper) {
|
|
1233
|
+
wrapper.style.height = "600px";
|
|
1234
|
+
wrapper.style.width = "380px";
|
|
1235
|
+
}
|
|
1236
|
+
}, 100);
|
|
1237
|
+
iframeWrapper.appendChild(iframe);
|
|
1238
|
+
window.document.body.appendChild(container);
|
|
1239
|
+
};
|
|
1240
|
+
var createSilkIframe = (useStaging) => {
|
|
1241
|
+
if (hasWaapComponent()) {
|
|
1242
|
+
createComponentModeIframe(useStaging);
|
|
1243
|
+
} else {
|
|
1244
|
+
createModalModeIframe(useStaging);
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
var initWaaP = (params = {}) => {
|
|
1248
|
+
createSilkIframe(!!params.useStaging);
|
|
1249
|
+
const iframe = getIframe();
|
|
1250
|
+
if (!iframe) {
|
|
1251
|
+
throw new Error("WaaP iframe does not exist on page");
|
|
1252
|
+
}
|
|
1253
|
+
const isComponentMode = hasWaapComponent();
|
|
1254
|
+
if (params.walletConnectProjectId) {
|
|
1255
|
+
SilkWalletConnect.setProjectId(params.walletConnectProjectId);
|
|
1256
|
+
}
|
|
1257
|
+
const { referralCode, config, project, asyncTxs, asyncSigning } = params;
|
|
1258
|
+
if (asyncSigning && !asyncTxs) {
|
|
1259
|
+
console.warn(
|
|
1260
|
+
"[WaaP SDK] `asyncSigning` is deprecated. Use `asyncTxs` instead."
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
const contentWindow = iframe.contentWindow;
|
|
1264
|
+
const isLegacyAsyncSigning = !!asyncSigning && !asyncTxs;
|
|
1265
|
+
const silkEthereumProvider = new EthereumProvider(
|
|
1266
|
+
contentWindow,
|
|
1267
|
+
referralCode,
|
|
1268
|
+
config || {},
|
|
1269
|
+
project || {},
|
|
1270
|
+
params.useStaging,
|
|
1271
|
+
asyncTxs || asyncSigning || false,
|
|
1272
|
+
isLegacyAsyncSigning
|
|
1273
|
+
);
|
|
1274
|
+
let currentMode = isComponentMode ? "component" : "modal";
|
|
1275
|
+
silkEthereumProvider.uiMessageManager.on("show_modal" /* show_modal */, () => {
|
|
1276
|
+
const nowComponentMode = hasWaapComponent();
|
|
1277
|
+
const newMode = nowComponentMode ? "component" : "modal";
|
|
1278
|
+
const iframeWrapper = getIframeWrapper();
|
|
1279
|
+
if (newMode !== currentMode && iframeWrapper) {
|
|
1280
|
+
currentMode = newMode;
|
|
1281
|
+
if (nowComponentMode) {
|
|
1282
|
+
const componentContainer = getWaapComponentContainer();
|
|
1283
|
+
if (componentContainer) {
|
|
1284
|
+
componentContainer.appendChild(iframeWrapper);
|
|
1285
|
+
}
|
|
1286
|
+
} else {
|
|
1287
|
+
let modalContainer = getIframeContainer();
|
|
1288
|
+
if (!modalContainer) {
|
|
1289
|
+
modalContainer = window.document.createElement("div");
|
|
1290
|
+
modalContainer.id = iframeContainerId;
|
|
1291
|
+
modalContainer.style.position = "fixed";
|
|
1292
|
+
modalContainer.style.top = "0";
|
|
1293
|
+
modalContainer.style.left = "0";
|
|
1294
|
+
modalContainer.style.right = "0";
|
|
1295
|
+
modalContainer.style.bottom = "0";
|
|
1296
|
+
modalContainer.style.width = "100%";
|
|
1297
|
+
modalContainer.style.height = "100%";
|
|
1298
|
+
modalContainer.style.display = "flex";
|
|
1299
|
+
modalContainer.style.alignItems = "center";
|
|
1300
|
+
modalContainer.style.justifyContent = "center";
|
|
1301
|
+
modalContainer.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
1302
|
+
modalContainer.style.zIndex = "9999999999";
|
|
1303
|
+
window.document.body.appendChild(modalContainer);
|
|
1304
|
+
}
|
|
1305
|
+
modalContainer.appendChild(iframeWrapper);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
const container = getIframeContainer();
|
|
1309
|
+
if (nowComponentMode && iframeWrapper) {
|
|
1310
|
+
iframeWrapper.style.display = "flex";
|
|
1311
|
+
} else if (container) {
|
|
1312
|
+
container.style.display = "flex";
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
silkEthereumProvider.uiMessageManager.on("hide_modal" /* hide_modal */, () => {
|
|
1316
|
+
const isComponentMode2 = hasWaapComponent();
|
|
1317
|
+
const iframeWrapper = getIframeWrapper();
|
|
1318
|
+
const container = getIframeContainer();
|
|
1319
|
+
if (isComponentMode2 && iframeWrapper) {
|
|
1320
|
+
iframeWrapper.style.display = "none";
|
|
1321
|
+
} else if (container) {
|
|
1322
|
+
container.style.display = "none";
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
window.silk = silkEthereumProvider;
|
|
1326
|
+
window.waap = silkEthereumProvider;
|
|
1327
|
+
return silkEthereumProvider;
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
// src/lib/provider/EthereumProviderExtension.ts
|
|
1331
|
+
var import_waap_interface_core3 = require("@human.tech/waap-interface-core");
|
|
1332
|
+
var import_events3 = require("events");
|
|
1333
|
+
var EthereumProviderExtension = class extends import_events3.EventEmitter {
|
|
1334
|
+
isSilk = true;
|
|
1335
|
+
connected = false;
|
|
1336
|
+
config;
|
|
1337
|
+
constructor(customConfig) {
|
|
1338
|
+
super();
|
|
1339
|
+
this.config = {
|
|
1340
|
+
...defaultConfig,
|
|
1341
|
+
...customConfig || {}
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
// Send a message to the background script via `chrome.runtime.sendMessage`
|
|
1345
|
+
sendToExtension(args) {
|
|
1346
|
+
return new Promise((resolve, reject) => {
|
|
1347
|
+
window.postMessage({ type: "FROM_PAGE", request: args }, "*");
|
|
1348
|
+
window.addEventListener("message", (event) => {
|
|
1349
|
+
if (event.data.type === "FROM_EXTENSION") {
|
|
1350
|
+
if (event.data.error) reject(event.data.error);
|
|
1351
|
+
else resolve(event.data.result);
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
// EIP-1193 `request` method implementation
|
|
1357
|
+
async request(args) {
|
|
1358
|
+
var _a, _b;
|
|
1359
|
+
if (!Object.keys(import_waap_interface_core3.JSON_RPC_METHOD).includes(args.method)) {
|
|
1360
|
+
return Promise.reject({ error: `Not implemented (${args.method})` });
|
|
1361
|
+
}
|
|
1362
|
+
const response = await this.sendToExtension(args);
|
|
1363
|
+
if ((args.method === import_waap_interface_core3.JSON_RPC_METHOD.wallet_switchEthereumChain || args.method === import_waap_interface_core3.JSON_RPC_METHOD.wallet_addEthereumChain) && response === null) {
|
|
1364
|
+
this.emit(
|
|
1365
|
+
"chainChanged",
|
|
1366
|
+
(_b = (_a = args.params) == null ? void 0 : _a[0]) == null ? void 0 : _b.chainId
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
return response;
|
|
1370
|
+
}
|
|
1371
|
+
// Enable method that dApps use to request accounts
|
|
1372
|
+
async enable() {
|
|
1373
|
+
return this.request({ method: "eth_requestAccounts" });
|
|
1374
|
+
}
|
|
1375
|
+
// Check if the provider is connected
|
|
1376
|
+
isConnected() {
|
|
1377
|
+
return this.connected;
|
|
1378
|
+
}
|
|
1379
|
+
// Example of a custom method to handle login requests
|
|
1380
|
+
async login() {
|
|
1381
|
+
return this.sendToExtension({ method: import_waap_interface_core3.SILK_METHOD.login });
|
|
1382
|
+
}
|
|
1383
|
+
// Example of requesting an SBT (Soulbound Token)
|
|
1384
|
+
async requestSBT(type) {
|
|
1385
|
+
return this.sendToExtension({
|
|
1386
|
+
method: import_waap_interface_core3.SILK_METHOD.silk_requestSbt,
|
|
1387
|
+
params: [type]
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
// Example of toggling dark mode as part of custom config
|
|
1391
|
+
async toggleDarkMode() {
|
|
1392
|
+
this.config.styles.darkMode = !this.config.styles.darkMode;
|
|
1393
|
+
await this.sendToExtension({
|
|
1394
|
+
method: import_waap_interface_core3.SILK_METHOD.set_custom_config,
|
|
1395
|
+
params: [this.config]
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
async safe() {
|
|
1399
|
+
return this.sendToExtension({ method: import_waap_interface_core3.SILK_METHOD.safe });
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
// src/lib/sui/SuiWallet.ts
|
|
1404
|
+
var import_events4 = require("events");
|
|
1405
|
+
var import_waap_interface_core4 = require("@human.tech/waap-interface-core");
|
|
1406
|
+
var WAAP_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";
|
|
1407
|
+
var WaaPSuiWallet = class {
|
|
1408
|
+
name = "WaaP";
|
|
1409
|
+
version = "1.0.0";
|
|
1410
|
+
icon = WAAP_ICON;
|
|
1411
|
+
_accounts = [];
|
|
1412
|
+
_chains = ["sui:mainnet", "sui:testnet", "sui:devnet"];
|
|
1413
|
+
walletMessageManager;
|
|
1414
|
+
uiMessageManager;
|
|
1415
|
+
internalEventEmitter = new import_events4.EventEmitter();
|
|
1416
|
+
changeListeners = /* @__PURE__ */ new Set();
|
|
1417
|
+
/**
|
|
1418
|
+
* Creates a new WaaPSuiWallet instance.
|
|
1419
|
+
*
|
|
1420
|
+
* @param iframeWindow - The contentWindow of the WaaP iframe
|
|
1421
|
+
* @param options - Initialization options
|
|
1422
|
+
*/
|
|
1423
|
+
constructor(iframeWindow, options = {}) {
|
|
1424
|
+
const useStaging = options.useStaging ?? false;
|
|
1425
|
+
this.walletMessageManager = new WalletMessageManager_default(iframeWindow, useStaging);
|
|
1426
|
+
this.uiMessageManager = new UIMessageManager();
|
|
1427
|
+
if (options.referralCode) {
|
|
1428
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
1429
|
+
this.postRequestAndWait({
|
|
1430
|
+
method: import_waap_interface_core4.SILK_METHOD.set_points_referral_code,
|
|
1431
|
+
params: [options.referralCode],
|
|
1432
|
+
interactionRequired: false
|
|
1433
|
+
}).catch((err) => console.error("Error setting referral code:", err));
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
if (options.project) {
|
|
1437
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
1438
|
+
this.postRequestAndWait({
|
|
1439
|
+
method: import_waap_interface_core4.SILK_METHOD.set_project,
|
|
1440
|
+
params: [options.project, window.location.origin],
|
|
1441
|
+
interactionRequired: false
|
|
1442
|
+
}).catch((err) => console.error("Error setting project:", err));
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
if (options.config) {
|
|
1446
|
+
this.walletMessageManager.pingIframe().then(() => {
|
|
1447
|
+
this.postRequestAndWait({
|
|
1448
|
+
method: import_waap_interface_core4.SILK_METHOD.set_custom_config,
|
|
1449
|
+
params: [options.config],
|
|
1450
|
+
interactionRequired: false
|
|
1451
|
+
}).catch((err) => console.error("Error setting custom config:", err));
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
this.walletMessageManager.addListener({
|
|
1455
|
+
handleResponse: (response) => {
|
|
1456
|
+
this.internalEventEmitter.emit(response.id, response);
|
|
1457
|
+
},
|
|
1458
|
+
handleRequest: (request) => {
|
|
1459
|
+
if (request.method === import_waap_interface_core4.SILK_METHOD.show_modal) {
|
|
1460
|
+
this.uiMessageManager.emit("show_modal" /* show_modal */);
|
|
1461
|
+
} else if (request.method === import_waap_interface_core4.SILK_METHOD.hide_modal) {
|
|
1462
|
+
this.uiMessageManager.emit("hide_modal" /* hide_modal */);
|
|
1463
|
+
}
|
|
1464
|
+
},
|
|
1465
|
+
onAccountChanged: async (newAccount) => {
|
|
1466
|
+
try {
|
|
1467
|
+
const result = await this.refreshAccounts();
|
|
1468
|
+
this.notifyChange({ accounts: result.accounts });
|
|
1469
|
+
} catch (error) {
|
|
1470
|
+
console.error("Failed to refresh Sui accounts:", error);
|
|
1471
|
+
this._accounts = [];
|
|
1472
|
+
this.notifyChange({ accounts: [] });
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Refresh accounts by making a silent connect request.
|
|
1479
|
+
* Used internally when account changes are detected.
|
|
1480
|
+
*/
|
|
1481
|
+
async refreshAccounts() {
|
|
1482
|
+
var _a;
|
|
1483
|
+
try {
|
|
1484
|
+
await this.walletMessageManager.pingIframe();
|
|
1485
|
+
const response = await this.postRequestAndWait({
|
|
1486
|
+
method: "sui_connect",
|
|
1487
|
+
params: [{ silent: true }],
|
|
1488
|
+
interactionRequired: false
|
|
1489
|
+
});
|
|
1490
|
+
if (response.error) {
|
|
1491
|
+
this._accounts = [];
|
|
1492
|
+
return { accounts: [] };
|
|
1493
|
+
}
|
|
1494
|
+
const accounts = ((_a = response.data) == null ? void 0 : _a.accounts) || [];
|
|
1495
|
+
this._accounts = accounts;
|
|
1496
|
+
return { accounts: this._accounts };
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
this._accounts = [];
|
|
1499
|
+
return { accounts: [] };
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Supported chains.
|
|
1504
|
+
*/
|
|
1505
|
+
get chains() {
|
|
1506
|
+
return this._chains;
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Connected accounts.
|
|
1510
|
+
*/
|
|
1511
|
+
get accounts() {
|
|
1512
|
+
return this._accounts;
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* UI message manager for showing/hiding modal.
|
|
1516
|
+
*/
|
|
1517
|
+
get ui() {
|
|
1518
|
+
return this.uiMessageManager;
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Connect to the wallet.
|
|
1522
|
+
*/
|
|
1523
|
+
async connect(input) {
|
|
1524
|
+
var _a;
|
|
1525
|
+
await this.walletMessageManager.pingIframe();
|
|
1526
|
+
const response = await this.postRequestAndWait({
|
|
1527
|
+
method: "sui_connect",
|
|
1528
|
+
params: [input || {}],
|
|
1529
|
+
interactionRequired: !(input == null ? void 0 : input.silent)
|
|
1530
|
+
});
|
|
1531
|
+
if (response.error) {
|
|
1532
|
+
throw new Error(response.error.message || "Failed to connect");
|
|
1533
|
+
}
|
|
1534
|
+
const accounts = ((_a = response.data) == null ? void 0 : _a.accounts) || [];
|
|
1535
|
+
this._accounts = accounts;
|
|
1536
|
+
this.notifyChange({ accounts: this._accounts });
|
|
1537
|
+
return { accounts: this._accounts };
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Disconnect from the wallet.
|
|
1541
|
+
*/
|
|
1542
|
+
async disconnect() {
|
|
1543
|
+
await this.walletMessageManager.pingIframe();
|
|
1544
|
+
await this.postRequestAndWait({
|
|
1545
|
+
method: "sui_disconnect",
|
|
1546
|
+
params: [],
|
|
1547
|
+
interactionRequired: false
|
|
1548
|
+
});
|
|
1549
|
+
this._accounts = [];
|
|
1550
|
+
this.notifyChange({ accounts: [] });
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Sign a personal message.
|
|
1554
|
+
*
|
|
1555
|
+
* @param input - Sign personal message input
|
|
1556
|
+
* @returns Signed message result with bytes and signature
|
|
1557
|
+
*/
|
|
1558
|
+
async signPersonalMessage(input) {
|
|
1559
|
+
await this.walletMessageManager.pingIframe();
|
|
1560
|
+
const accountAddress = input.account.address;
|
|
1561
|
+
const isConnected = this._accounts.some((a) => a.address === accountAddress);
|
|
1562
|
+
if (!isConnected) {
|
|
1563
|
+
throw new Error(`Account ${accountAddress} is not connected`);
|
|
1564
|
+
}
|
|
1565
|
+
const response = await this.postRequestAndWait({
|
|
1566
|
+
method: "sui_signPersonalMessage",
|
|
1567
|
+
params: [{
|
|
1568
|
+
message: Array.from(input.message),
|
|
1569
|
+
account: accountAddress,
|
|
1570
|
+
chain: input.chain
|
|
1571
|
+
}],
|
|
1572
|
+
interactionRequired: true
|
|
1573
|
+
});
|
|
1574
|
+
if (response.error) {
|
|
1575
|
+
throw new Error(response.error.message || "Failed to sign message");
|
|
1576
|
+
}
|
|
1577
|
+
return {
|
|
1578
|
+
bytes: response.data.bytes,
|
|
1579
|
+
signature: response.data.signature
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Extract the destination addresses from BCS-serialized Sui transaction bytes.
|
|
1584
|
+
*
|
|
1585
|
+
* Unlike EVM transactions where `to` is a top-level field, Sui transaction
|
|
1586
|
+
* destinations are embedded in BCS-encoded programmable transaction blocks.
|
|
1587
|
+
* We deserialize with Transaction.from() and inspect TransferObjects commands.
|
|
1588
|
+
*
|
|
1589
|
+
* Only TransferObjects destinations are extracted — MoveCall package addresses
|
|
1590
|
+
* are not user-facing recipients and should not be validated against a PT's
|
|
1591
|
+
* allowedAddresses list.
|
|
1592
|
+
*
|
|
1593
|
+
* Returns an empty array if no TransferObjects are found or deserialization fails.
|
|
1594
|
+
*/
|
|
1595
|
+
async extractTransferAddresses(txBytes) {
|
|
1596
|
+
try {
|
|
1597
|
+
const { Transaction } = await import("@mysten/sui/transactions");
|
|
1598
|
+
const tx = Transaction.from(txBytes);
|
|
1599
|
+
const data = tx.getData();
|
|
1600
|
+
const addresses = [];
|
|
1601
|
+
for (const command of data.commands) {
|
|
1602
|
+
if (command.$kind !== "TransferObjects") continue;
|
|
1603
|
+
const addrArg = command.TransferObjects.address;
|
|
1604
|
+
if (addrArg.$kind !== "Input") continue;
|
|
1605
|
+
const inputIndex = addrArg.Input;
|
|
1606
|
+
const input = data.inputs[inputIndex];
|
|
1607
|
+
if (!input || input.$kind !== "Pure") continue;
|
|
1608
|
+
const bytes = Uint8Array.from(atob(input.Pure.bytes), (c) => c.charCodeAt(0));
|
|
1609
|
+
if (bytes.length !== 32) continue;
|
|
1610
|
+
const hex = "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1611
|
+
addresses.push(hex);
|
|
1612
|
+
}
|
|
1613
|
+
return addresses;
|
|
1614
|
+
} catch {
|
|
1615
|
+
return [];
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Helper to resolve transaction bytes from various input formats.
|
|
1620
|
+
* If the input is a Transaction/TransactionBlock object, it builds it.
|
|
1621
|
+
*/
|
|
1622
|
+
async resolveTransactionBytes(tx, chain = "sui:mainnet") {
|
|
1623
|
+
if (tx instanceof Uint8Array) {
|
|
1624
|
+
return tx;
|
|
1625
|
+
} else if (Array.isArray(tx)) {
|
|
1626
|
+
return new Uint8Array(tx);
|
|
1627
|
+
} else if (typeof tx === "string") {
|
|
1628
|
+
try {
|
|
1629
|
+
return Uint8Array.from(atob(tx), (c) => c.charCodeAt(0));
|
|
1630
|
+
} catch {
|
|
1631
|
+
throw new Error("Transaction string must be base64 encoded bytes. If you have a serialized transaction JSON, please build it to bytes first.");
|
|
1632
|
+
}
|
|
1633
|
+
} else if (tx && typeof tx === "object") {
|
|
1634
|
+
if (typeof tx.build === "function") {
|
|
1635
|
+
try {
|
|
1636
|
+
const { getFullnodeUrl, SuiClient } = await import("@mysten/sui/client");
|
|
1637
|
+
let network = "mainnet";
|
|
1638
|
+
if (chain === "sui:testnet") network = "testnet";
|
|
1639
|
+
else if (chain === "sui:devnet") network = "devnet";
|
|
1640
|
+
else if (chain === "sui:localnet") network = "localnet";
|
|
1641
|
+
const url = getFullnodeUrl(network);
|
|
1642
|
+
const client = new SuiClient({ url });
|
|
1643
|
+
const builtBytes = await tx.build({ client });
|
|
1644
|
+
return builtBytes;
|
|
1645
|
+
} catch (e) {
|
|
1646
|
+
console.warn("[SuiWallet] Failed to build transaction object:", e);
|
|
1647
|
+
throw new Error(`Failed to build transaction: ${e instanceof Error ? e.message : String(e)}`);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
if (typeof tx.serialize === "function") {
|
|
1651
|
+
try {
|
|
1652
|
+
const serialized = await tx.serialize();
|
|
1653
|
+
if (typeof serialized === "string") {
|
|
1654
|
+
return Uint8Array.from(atob(serialized), (c) => c.charCodeAt(0));
|
|
1655
|
+
} else if (serialized instanceof Uint8Array) {
|
|
1656
|
+
return serialized;
|
|
1657
|
+
}
|
|
1658
|
+
} catch (e) {
|
|
1659
|
+
console.warn("[SuiWallet] serialize() failed:", e);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
if (typeof tx.toJSON === "function") {
|
|
1663
|
+
try {
|
|
1664
|
+
const json = await tx.toJSON();
|
|
1665
|
+
if (typeof json === "string") {
|
|
1666
|
+
try {
|
|
1667
|
+
return Uint8Array.from(atob(json), (c) => c.charCodeAt(0));
|
|
1668
|
+
} catch {
|
|
1669
|
+
try {
|
|
1670
|
+
const parsed = JSON.parse(json);
|
|
1671
|
+
if (parsed.bytes && typeof parsed.bytes === "string") {
|
|
1672
|
+
return Uint8Array.from(atob(parsed.bytes), (c) => c.charCodeAt(0));
|
|
1673
|
+
}
|
|
1674
|
+
} catch {
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
} catch (e) {
|
|
1679
|
+
console.warn("[SuiWallet] toJSON() failed:", e);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
if (typeof tx.getData === "function") {
|
|
1683
|
+
try {
|
|
1684
|
+
const data = tx.getData();
|
|
1685
|
+
if (data instanceof Uint8Array) return data;
|
|
1686
|
+
} catch (e) {
|
|
1687
|
+
console.warn("[SuiWallet] getData() failed:", e);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
throw new Error(`Unsupported transaction format. Keys: ${Object.keys(tx).join(", ")}`);
|
|
1691
|
+
} else {
|
|
1692
|
+
throw new Error(`Unsupported transaction format: ${typeof tx}. Please pass Uint8Array bytes or a Transaction object.`);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Sign a transaction.
|
|
1697
|
+
*
|
|
1698
|
+
* @param input - Sign transaction input with transaction
|
|
1699
|
+
* @returns Signed transaction result with bytes and signature
|
|
1700
|
+
*/
|
|
1701
|
+
async signTransaction(input) {
|
|
1702
|
+
await this.walletMessageManager.pingIframe();
|
|
1703
|
+
const accountAddress = input.account.address;
|
|
1704
|
+
const isConnected = this._accounts.some((a) => a.address === accountAddress);
|
|
1705
|
+
if (!isConnected) {
|
|
1706
|
+
throw new Error(`Account ${accountAddress} is not connected`);
|
|
1707
|
+
}
|
|
1708
|
+
const txBytes = await this.resolveTransactionBytes(input.transaction, input.chain);
|
|
1709
|
+
const response = await this.postRequestAndWait({
|
|
1710
|
+
method: "sui_signTransaction",
|
|
1711
|
+
params: [{
|
|
1712
|
+
transaction: Array.from(txBytes),
|
|
1713
|
+
account: accountAddress,
|
|
1714
|
+
chain: input.chain
|
|
1715
|
+
}],
|
|
1716
|
+
interactionRequired: true
|
|
1717
|
+
});
|
|
1718
|
+
if (response.error) {
|
|
1719
|
+
throw new Error(response.error.message || "Failed to sign transaction");
|
|
1720
|
+
}
|
|
1721
|
+
return {
|
|
1722
|
+
bytes: response.data.bytes,
|
|
1723
|
+
signature: response.data.signature
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Sign and execute a transaction.
|
|
1728
|
+
*
|
|
1729
|
+
* @param input - Sign and execute transaction input
|
|
1730
|
+
*/
|
|
1731
|
+
async signAndExecuteTransaction(input) {
|
|
1732
|
+
await this.walletMessageManager.pingIframe();
|
|
1733
|
+
const accountAddress = input.account.address;
|
|
1734
|
+
const isConnected = this._accounts.some((a) => a.address === accountAddress);
|
|
1735
|
+
if (!isConnected) {
|
|
1736
|
+
throw new Error(`Account ${accountAddress} is not connected`);
|
|
1737
|
+
}
|
|
1738
|
+
const txBytes = await this.resolveTransactionBytes(input.transaction, input.chain);
|
|
1739
|
+
const toAddresses = await this.extractTransferAddresses(txBytes);
|
|
1740
|
+
const response = await this.postRequestAndWait({
|
|
1741
|
+
method: "sui_signAndExecuteTransaction",
|
|
1742
|
+
params: [{
|
|
1743
|
+
transaction: Array.from(txBytes),
|
|
1744
|
+
account: accountAddress,
|
|
1745
|
+
chain: input.chain,
|
|
1746
|
+
options: input.options,
|
|
1747
|
+
requestType: input.requestType,
|
|
1748
|
+
toAddresses: toAddresses.length > 0 ? toAddresses : void 0
|
|
1749
|
+
}],
|
|
1750
|
+
interactionRequired: true
|
|
1751
|
+
});
|
|
1752
|
+
if (response.error) {
|
|
1753
|
+
throw new Error(response.error.message || "Failed to sign and execute transaction");
|
|
1754
|
+
}
|
|
1755
|
+
return response.data;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Switch the active chain.
|
|
1759
|
+
*/
|
|
1760
|
+
async switchChain(input) {
|
|
1761
|
+
await this.walletMessageManager.pingIframe();
|
|
1762
|
+
if (!this._chains.includes(input.chain)) {
|
|
1763
|
+
throw new Error(`Chain ${input.chain} is not supported`);
|
|
1764
|
+
}
|
|
1765
|
+
const response = await this.postRequestAndWait({
|
|
1766
|
+
method: "sui_switchChain",
|
|
1767
|
+
params: [input],
|
|
1768
|
+
interactionRequired: false
|
|
1769
|
+
});
|
|
1770
|
+
if (response.error) {
|
|
1771
|
+
throw new Error(response.error.message || "Failed to switch chain");
|
|
1772
|
+
}
|
|
1773
|
+
this.notifyChange({ chains: this._chains, accounts: this._accounts });
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Subscribe to wallet change events.
|
|
1777
|
+
*
|
|
1778
|
+
* @param event - Event name (currently only 'change')
|
|
1779
|
+
* @param listener - Event listener callback
|
|
1780
|
+
* @returns Unsubscribe function
|
|
1781
|
+
*/
|
|
1782
|
+
on(event, listener) {
|
|
1783
|
+
if (event === "change") {
|
|
1784
|
+
this.changeListeners.add(listener);
|
|
1785
|
+
return () => {
|
|
1786
|
+
this.changeListeners.delete(listener);
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
return () => {
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Wallet Standard features property.
|
|
1794
|
+
* Required by @mysten/wallet-standard registerWallet.
|
|
1795
|
+
*/
|
|
1796
|
+
get features() {
|
|
1797
|
+
return {
|
|
1798
|
+
"standard:connect": {
|
|
1799
|
+
version: "1.0.0",
|
|
1800
|
+
connect: this.connect.bind(this)
|
|
1801
|
+
},
|
|
1802
|
+
"standard:disconnect": {
|
|
1803
|
+
version: "1.0.0",
|
|
1804
|
+
disconnect: this.disconnect.bind(this)
|
|
1805
|
+
},
|
|
1806
|
+
"standard:events": {
|
|
1807
|
+
version: "1.0.0",
|
|
1808
|
+
on: this.on.bind(this)
|
|
1809
|
+
},
|
|
1810
|
+
"sui:signPersonalMessage": {
|
|
1811
|
+
version: "1.1.0",
|
|
1812
|
+
signPersonalMessage: this.signPersonalMessage.bind(this)
|
|
1813
|
+
},
|
|
1814
|
+
"sui:signTransaction": {
|
|
1815
|
+
version: "2.0.0",
|
|
1816
|
+
signTransaction: this.signTransaction.bind(this)
|
|
1817
|
+
},
|
|
1818
|
+
"sui:signAndExecuteTransaction": {
|
|
1819
|
+
version: "1.0.0",
|
|
1820
|
+
signAndExecuteTransaction: this.signAndExecuteTransaction.bind(this)
|
|
1821
|
+
},
|
|
1822
|
+
"sui:signTransactionBlock": {
|
|
1823
|
+
version: "2.0.0",
|
|
1824
|
+
signTransactionBlock: this.signTransactionBlock.bind(this)
|
|
1825
|
+
},
|
|
1826
|
+
"sui:signAndExecuteTransactionBlock": {
|
|
1827
|
+
version: "1.0.0",
|
|
1828
|
+
signAndExecuteTransactionBlock: this.signAndExecuteTransactionBlock.bind(this)
|
|
1829
|
+
},
|
|
1830
|
+
"sui:switchChain": {
|
|
1831
|
+
version: "1.0.0",
|
|
1832
|
+
switchChain: this.switchChain.bind(this)
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Legacy method for signing a transaction block.
|
|
1838
|
+
* Maps to signTransaction.
|
|
1839
|
+
*/
|
|
1840
|
+
async signTransactionBlock(input) {
|
|
1841
|
+
return this.signTransaction({
|
|
1842
|
+
transaction: input.transactionBlock,
|
|
1843
|
+
account: input.account,
|
|
1844
|
+
chain: input.chain
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Legacy method for signing and executing a transaction block.
|
|
1849
|
+
* Maps to signAndExecuteTransaction.
|
|
1850
|
+
*/
|
|
1851
|
+
async signAndExecuteTransactionBlock(input) {
|
|
1852
|
+
return this.signAndExecuteTransaction({
|
|
1853
|
+
transaction: input.transactionBlock,
|
|
1854
|
+
account: input.account,
|
|
1855
|
+
chain: input.chain,
|
|
1856
|
+
options: input.options,
|
|
1857
|
+
requestType: input.requestType
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Request a Permission Token from the user.
|
|
1862
|
+
* Allows pre-authorised batches of Sui transactions without individual confirmations.
|
|
1863
|
+
*
|
|
1864
|
+
* @param params - Allowed addresses, chainId (e.g. "sui:mainnet"), spend limit, expiry
|
|
1865
|
+
*/
|
|
1866
|
+
async requestPermissionToken(params) {
|
|
1867
|
+
await this.walletMessageManager.pingIframe();
|
|
1868
|
+
const response = await this.postRequestAndWait({
|
|
1869
|
+
method: import_waap_interface_core4.SILK_METHOD.waap_requestPermissionToken,
|
|
1870
|
+
params: [params],
|
|
1871
|
+
interactionRequired: true
|
|
1872
|
+
});
|
|
1873
|
+
if (response.error) {
|
|
1874
|
+
throw new Error(response.error.message || "Failed to request permission token");
|
|
1875
|
+
}
|
|
1876
|
+
return response.data;
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Request the user's email address.
|
|
1880
|
+
*
|
|
1881
|
+
* @returns Promise resolving to the user's email address
|
|
1882
|
+
*/
|
|
1883
|
+
async requestEmail() {
|
|
1884
|
+
await this.walletMessageManager.pingIframe();
|
|
1885
|
+
const response = await this.postRequestAndWait({
|
|
1886
|
+
method: import_waap_interface_core4.SILK_METHOD.silk_requestEmail,
|
|
1887
|
+
params: [],
|
|
1888
|
+
interactionRequired: true
|
|
1889
|
+
});
|
|
1890
|
+
if (response.error) {
|
|
1891
|
+
throw new Error(response.error.message || "Failed to request email");
|
|
1892
|
+
}
|
|
1893
|
+
return response.data;
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Post a request to the iframe and wait for response.
|
|
1897
|
+
*/
|
|
1898
|
+
async postRequestAndWait(args) {
|
|
1899
|
+
const id = await this.walletMessageManager.postSilkRequest({
|
|
1900
|
+
method: args.method,
|
|
1901
|
+
params: args.params,
|
|
1902
|
+
interactionRequired: args.interactionRequired
|
|
1903
|
+
});
|
|
1904
|
+
return new Promise((resolve) => {
|
|
1905
|
+
this.internalEventEmitter.once(id, (response) => {
|
|
1906
|
+
resolve(response);
|
|
1907
|
+
});
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Notify all change listeners.
|
|
1912
|
+
*/
|
|
1913
|
+
notifyChange(properties) {
|
|
1914
|
+
Array.from(this.changeListeners).forEach((listener) => {
|
|
1915
|
+
listener(properties);
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
|
|
1920
|
+
// src/lib/sui/init.ts
|
|
1921
|
+
var import_waap_constants4 = require("@human.tech/waap-constants");
|
|
1922
|
+
var IFRAME_CONTAINER_ID = "waap-wallet-iframe-container";
|
|
1923
|
+
var IFRAME_ID = "waap-wallet-iframe";
|
|
1924
|
+
var LEGACY_IFRAME_CONTAINER_ID2 = "silk-wallet-iframe-container";
|
|
1925
|
+
var LEGACY_IFRAME_ID2 = "silk-wallet-iframe";
|
|
1926
|
+
var getIframeContainer2 = () => {
|
|
1927
|
+
return document.getElementById(IFRAME_CONTAINER_ID) || document.getElementById(LEGACY_IFRAME_CONTAINER_ID2);
|
|
1928
|
+
};
|
|
1929
|
+
var getIframe2 = () => {
|
|
1930
|
+
return document.getElementById(IFRAME_ID) || document.getElementById(LEGACY_IFRAME_ID2);
|
|
1931
|
+
};
|
|
1932
|
+
var IFRAME_WRAPPER_ID = "waap-wallet-iframe-wrapper";
|
|
1933
|
+
var LEGACY_IFRAME_WRAPPER_ID2 = "silk-wallet-iframe-wrapper";
|
|
1934
|
+
var getIframeWrapper2 = () => {
|
|
1935
|
+
return document.getElementById(IFRAME_WRAPPER_ID) || document.getElementById(LEGACY_IFRAME_WRAPPER_ID2);
|
|
1936
|
+
};
|
|
1937
|
+
var setupIframeMessageListener2 = (useStaging) => {
|
|
1938
|
+
const handleIframeMessage = (event) => {
|
|
1939
|
+
const expectedOrigin = useStaging ? import_waap_constants4.silkWalletAppOrigin2Staging : import_waap_constants4.silkWalletAppOrigin2;
|
|
1940
|
+
if (event.origin !== expectedOrigin) return;
|
|
1941
|
+
if (!event.data || typeof event.data !== "object") return;
|
|
1942
|
+
if (event.data.type !== "silk-iframe-size") return;
|
|
1943
|
+
const contentHeight = event.data.height;
|
|
1944
|
+
const contentWidth = event.data.width;
|
|
1945
|
+
const maxDimension = 2e3;
|
|
1946
|
+
const minDimension = 50;
|
|
1947
|
+
if (typeof contentHeight !== "number" || typeof contentWidth !== "number")
|
|
1948
|
+
return;
|
|
1949
|
+
if (contentHeight < minDimension || contentHeight > maxDimension) return;
|
|
1950
|
+
if (contentWidth < minDimension || contentWidth > maxDimension) return;
|
|
1951
|
+
if (!Number.isFinite(contentHeight) || !Number.isFinite(contentWidth))
|
|
1952
|
+
return;
|
|
1953
|
+
const iframeWrapper = getIframeWrapper2();
|
|
1954
|
+
if (!iframeWrapper) return;
|
|
1955
|
+
iframeWrapper.style.height = `${Math.floor(contentHeight)}px`;
|
|
1956
|
+
iframeWrapper.style.width = `${Math.floor(contentWidth)}px`;
|
|
1957
|
+
};
|
|
1958
|
+
window.addEventListener("message", handleIframeMessage);
|
|
1959
|
+
};
|
|
1960
|
+
var createWaapIframe = (useStaging) => {
|
|
1961
|
+
if (getIframeContainer2()) {
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
const container = document.createElement("div");
|
|
1965
|
+
container.id = IFRAME_CONTAINER_ID;
|
|
1966
|
+
container.style.cssText = `
|
|
1967
|
+
position: fixed;
|
|
1968
|
+
top: 0;
|
|
1969
|
+
left: 0;
|
|
1970
|
+
right: 0;
|
|
1971
|
+
bottom: 0;
|
|
1972
|
+
width: 100%;
|
|
1973
|
+
height: 100%;
|
|
1974
|
+
display: none;
|
|
1975
|
+
align-items: center;
|
|
1976
|
+
justify-content: center;
|
|
1977
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
1978
|
+
z-index: 9999999999;
|
|
1979
|
+
`;
|
|
1980
|
+
const wrapper = document.createElement("div");
|
|
1981
|
+
wrapper.id = IFRAME_WRAPPER_ID;
|
|
1982
|
+
wrapper.style.cssText = `
|
|
1983
|
+
position: relative;
|
|
1984
|
+
display: flex;
|
|
1985
|
+
align-items: center;
|
|
1986
|
+
justify-content: center;
|
|
1987
|
+
padding: 0;
|
|
1988
|
+
margin: 0;
|
|
1989
|
+
height: 600px;
|
|
1990
|
+
width: 380px;
|
|
1991
|
+
`;
|
|
1992
|
+
container.appendChild(wrapper);
|
|
1993
|
+
const iframe = document.createElement("iframe");
|
|
1994
|
+
iframe.id = IFRAME_ID;
|
|
1995
|
+
iframe.src = `${useStaging ? import_waap_constants4.silkWalletAppOrigin2Staging : import_waap_constants4.silkWalletAppOrigin2}/iframe`;
|
|
1996
|
+
iframe.style.cssText = `
|
|
1997
|
+
width: 100%;
|
|
1998
|
+
height: 100%;
|
|
1999
|
+
border: none;
|
|
2000
|
+
border-radius: 24px;
|
|
2001
|
+
background: transparent;
|
|
2002
|
+
`;
|
|
2003
|
+
wrapper.appendChild(iframe);
|
|
2004
|
+
setupIframeMessageListener2(useStaging);
|
|
2005
|
+
document.body.appendChild(container);
|
|
2006
|
+
};
|
|
2007
|
+
function initWaaPSui(options = {}) {
|
|
2008
|
+
const useStaging = options.useStaging ?? false;
|
|
2009
|
+
createWaapIframe(useStaging);
|
|
2010
|
+
const container = getIframeContainer2();
|
|
2011
|
+
const iframe = getIframe2();
|
|
2012
|
+
if (!container || !iframe) {
|
|
2013
|
+
throw new Error("Failed to create WaaP iframe");
|
|
2014
|
+
}
|
|
2015
|
+
const contentWindow = iframe.contentWindow;
|
|
2016
|
+
const suiWallet = new WaaPSuiWallet(contentWindow, options);
|
|
2017
|
+
suiWallet.ui.on("show_modal" /* show_modal */, () => {
|
|
2018
|
+
container.style.display = "flex";
|
|
2019
|
+
const dappKitOverlays = document.querySelectorAll('[data-dapp-kit][class*="overlay"]');
|
|
2020
|
+
dappKitOverlays.forEach((overlay) => {
|
|
2021
|
+
overlay.style.display = "none";
|
|
2022
|
+
});
|
|
2023
|
+
});
|
|
2024
|
+
suiWallet.ui.on("hide_modal" /* hide_modal */, () => {
|
|
2025
|
+
container.style.display = "none";
|
|
2026
|
+
const dappKitOverlays = document.querySelectorAll('[data-dapp-kit][class*="overlay"]');
|
|
2027
|
+
dappKitOverlays.forEach((overlay) => {
|
|
2028
|
+
overlay.style.display = "";
|
|
2029
|
+
});
|
|
2030
|
+
});
|
|
2031
|
+
return suiWallet;
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
// src/lib/sui/register.ts
|
|
2035
|
+
var import_wallet_standard = require("@mysten/wallet-standard");
|
|
2036
|
+
function registerWaaPSuiWallet(iframeWindow, options = {}) {
|
|
2037
|
+
const wallet = new WaaPSuiWallet(iframeWindow, options);
|
|
2038
|
+
(0, import_wallet_standard.registerWallet)(wallet);
|
|
2039
|
+
return wallet;
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
// src/index.ts
|
|
2043
|
+
var import_waap_interface_core5 = require("@human.tech/waap-interface-core");
|
|
2044
|
+
|
|
2045
|
+
// src/hooks/useWaapTransaction.ts
|
|
2046
|
+
var import_react = require("react");
|
|
2047
|
+
function useWaapTransaction(options) {
|
|
2048
|
+
const [pendingTransactions, setPendingTransactions] = (0, import_react.useState)(/* @__PURE__ */ new Map());
|
|
2049
|
+
const optionsRef = (0, import_react.useRef)(options);
|
|
2050
|
+
(0, import_react.useEffect)(() => {
|
|
2051
|
+
optionsRef.current = options;
|
|
2052
|
+
}, [options]);
|
|
2053
|
+
(0, import_react.useEffect)(() => {
|
|
2054
|
+
const provider = window.waap || window.silk;
|
|
2055
|
+
if (!provider) {
|
|
2056
|
+
console.warn(
|
|
2057
|
+
"[useWaapTransaction] WaaP provider not found. Make sure initWaaP() was called."
|
|
2058
|
+
);
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
const handleSignComplete = (event) => {
|
|
2062
|
+
var _a, _b;
|
|
2063
|
+
setPendingTransactions((prev) => {
|
|
2064
|
+
const next = new Map(prev);
|
|
2065
|
+
next.set(event.txHash, {
|
|
2066
|
+
status: "signed",
|
|
2067
|
+
txHash: event.txHash,
|
|
2068
|
+
pendingTxId: event.txHash,
|
|
2069
|
+
signature: event.signature,
|
|
2070
|
+
serializedTx: event.serializedTx
|
|
2071
|
+
});
|
|
2072
|
+
return next;
|
|
2073
|
+
});
|
|
2074
|
+
(_b = (_a = optionsRef.current) == null ? void 0 : _a.onSigned) == null ? void 0 : _b.call(_a, event);
|
|
2075
|
+
};
|
|
2076
|
+
const handleTxPending = (event) => {
|
|
2077
|
+
var _a, _b;
|
|
2078
|
+
setPendingTransactions((prev) => {
|
|
2079
|
+
const next = new Map(prev);
|
|
2080
|
+
const existing = next.get(event.txHash);
|
|
2081
|
+
if (existing) {
|
|
2082
|
+
next.set(event.txHash, {
|
|
2083
|
+
...existing,
|
|
2084
|
+
status: "tx_pending"
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
return next;
|
|
2088
|
+
});
|
|
2089
|
+
(_b = (_a = optionsRef.current) == null ? void 0 : _a.onTxPending) == null ? void 0 : _b.call(_a, event);
|
|
2090
|
+
};
|
|
2091
|
+
const handleConfirmed = (event) => {
|
|
2092
|
+
var _a, _b;
|
|
2093
|
+
setPendingTransactions((prev) => {
|
|
2094
|
+
const next = new Map(prev);
|
|
2095
|
+
const existing = next.get(event.txHash);
|
|
2096
|
+
if (existing) {
|
|
2097
|
+
next.set(event.txHash, {
|
|
2098
|
+
...existing,
|
|
2099
|
+
status: "confirmed",
|
|
2100
|
+
receipt: event.receipt
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
return next;
|
|
2104
|
+
});
|
|
2105
|
+
(_b = (_a = optionsRef.current) == null ? void 0 : _a.onConfirmed) == null ? void 0 : _b.call(_a, event);
|
|
2106
|
+
};
|
|
2107
|
+
const handleTxFailed = (event) => {
|
|
2108
|
+
var _a, _b;
|
|
2109
|
+
setPendingTransactions((prev) => {
|
|
2110
|
+
const next = new Map(prev);
|
|
2111
|
+
const existing = next.get(event.txHash);
|
|
2112
|
+
if (existing) {
|
|
2113
|
+
next.set(event.txHash, {
|
|
2114
|
+
...existing,
|
|
2115
|
+
status: "failed",
|
|
2116
|
+
error: event.error,
|
|
2117
|
+
stage: event.stage
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
return next;
|
|
2121
|
+
});
|
|
2122
|
+
(_b = (_a = optionsRef.current) == null ? void 0 : _a.onFailed) == null ? void 0 : _b.call(_a, event);
|
|
2123
|
+
};
|
|
2124
|
+
provider.on("waap_sign_complete", handleSignComplete);
|
|
2125
|
+
provider.on("waap_tx_pending", handleTxPending);
|
|
2126
|
+
provider.on("waap_tx_confirmed", handleConfirmed);
|
|
2127
|
+
provider.on("waap_tx_failed", handleTxFailed);
|
|
2128
|
+
return () => {
|
|
2129
|
+
var _a, _b, _c, _d;
|
|
2130
|
+
(_a = provider.removeListener) == null ? void 0 : _a.call(provider, "waap_sign_complete", handleSignComplete);
|
|
2131
|
+
(_b = provider.removeListener) == null ? void 0 : _b.call(provider, "waap_tx_pending", handleTxPending);
|
|
2132
|
+
(_c = provider.removeListener) == null ? void 0 : _c.call(provider, "waap_tx_confirmed", handleConfirmed);
|
|
2133
|
+
(_d = provider.removeListener) == null ? void 0 : _d.call(provider, "waap_tx_failed", handleTxFailed);
|
|
2134
|
+
};
|
|
2135
|
+
}, []);
|
|
2136
|
+
const sendTransaction = (0, import_react.useCallback)(
|
|
2137
|
+
async (txRequest) => {
|
|
2138
|
+
const provider = window.waap || window.silk;
|
|
2139
|
+
if (!provider) {
|
|
2140
|
+
throw new Error("WaaP provider not found");
|
|
2141
|
+
}
|
|
2142
|
+
return provider.request({
|
|
2143
|
+
method: "eth_sendTransaction",
|
|
2144
|
+
params: txRequest
|
|
2145
|
+
});
|
|
2146
|
+
},
|
|
2147
|
+
[]
|
|
2148
|
+
);
|
|
2149
|
+
const signTransaction = (0, import_react.useCallback)(
|
|
2150
|
+
async (txRequest) => {
|
|
2151
|
+
const provider = window.waap || window.silk;
|
|
2152
|
+
if (!provider) {
|
|
2153
|
+
throw new Error("WaaP provider not found");
|
|
2154
|
+
}
|
|
2155
|
+
return provider.request({
|
|
2156
|
+
method: "eth_signTransaction",
|
|
2157
|
+
params: txRequest
|
|
2158
|
+
});
|
|
2159
|
+
},
|
|
2160
|
+
[]
|
|
2161
|
+
);
|
|
2162
|
+
const isAnyPending = Array.from(pendingTransactions.values()).some(
|
|
2163
|
+
(tx) => tx.status === "signed" || tx.status === "tx_pending"
|
|
2164
|
+
);
|
|
2165
|
+
return {
|
|
2166
|
+
sendTransaction,
|
|
2167
|
+
signTransaction,
|
|
2168
|
+
pendingTransactions,
|
|
2169
|
+
isAnyPending
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2173
|
+
0 && (module.exports = {
|
|
2174
|
+
EthereumProvider,
|
|
2175
|
+
EthereumProviderExtension,
|
|
2176
|
+
SILK_METHOD,
|
|
2177
|
+
SilkWalletConnect,
|
|
2178
|
+
UIMessageManager,
|
|
2179
|
+
UI_EVENT_NAMES,
|
|
2180
|
+
WAAP_METHOD,
|
|
2181
|
+
WaaP,
|
|
2182
|
+
WaaPSuiWallet,
|
|
2183
|
+
WaaPWalletConnect,
|
|
2184
|
+
WalletMessageManager,
|
|
2185
|
+
handleWalletRequestAndResponse,
|
|
2186
|
+
initWaaP,
|
|
2187
|
+
initWaaPSui,
|
|
2188
|
+
registerWaaPSuiWallet,
|
|
2189
|
+
rpcMethodRequiresUI,
|
|
2190
|
+
useWaapTransaction
|
|
2191
|
+
});
|