From 1708dd37c2f3683b6f231eca5a828336064d6b91 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 2 Oct 2024 18:24:25 -0400 Subject: [PATCH 1/4] use walletkit --- ios/Podfile.lock | 4 +- package.json | 10 +- src/walletConnect/index.tsx | 81 ++++++++----- yarn.lock | 226 +++++++++++------------------------- 4 files changed, 123 insertions(+), 198 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 32d0852c36a..6771cbd3530 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1177,7 +1177,7 @@ PODS: - React-Core - react-native-cloud-fs (2.6.2): - React - - react-native-compat (2.15.1): + - react-native-compat (2.17.0): - DoubleConversion - glog - hermes-engine @@ -2352,7 +2352,7 @@ SPEC CHECKSUMS: react-native-cameraroll: b5ce04a1ee4081d7eea921918de979f0b41d8e22 react-native-change-icon: ea9bb7255b09e89f41cbf282df16eade91ab1833 react-native-cloud-fs: c90379f513b8d7ad5cfed610ccf50f27d837016e - react-native-compat: 408a4b320fa4426f2c25ab74ed5764be6b3eb5aa + react-native-compat: 4e82fe33d1af54feba2f25d3d88f2b4d8e5c2b78 react-native-get-random-values: 1404bd5cc0ab0e287f75ee1c489555688fc65f89 react-native-ios-context-menu: e529171ba760a1af7f2ef0729f5a7f4d226171c5 react-native-mail: a864fb211feaa5845c6c478a3266de725afdce89 diff --git a/package.json b/package.json index 8418907307e..faf9002bddd 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "@react-navigation/material-top-tabs": "6.6.2", "@react-navigation/native": "6.1.17", "@react-navigation/stack": "6.3.29", + "@reown/walletkit": "^1.0.0", "@reservoir0x/reservoir-sdk": "2.3.0", "@rudderstack/rudder-sdk-react-native": "1.12.1", "@sentry/react-native": "5.31.1", @@ -140,12 +141,11 @@ "@unstoppabledomains/resolution": "7.1.4", "@wagmi/chains": "1.8.0", "@walletconnect/client": "1.8.0", - "@walletconnect/core": "2.15.1", + "@walletconnect/core": "2.17.0", "@walletconnect/legacy-utils": "2.0.0", - "@walletconnect/react-native-compat": "2.15.1", - "@walletconnect/types": "2.15.1", - "@walletconnect/utils": "2.15.1", - "@walletconnect/web3wallet": "1.14.1", + "@walletconnect/react-native-compat": "2.17.0", + "@walletconnect/types": "2.17.0", + "@walletconnect/utils": "2.17.0", "assert": "1.5.0", "async-mutex": "0.3.2", "asyncstorage-down": "4.2.0", diff --git a/src/walletConnect/index.tsx b/src/walletConnect/index.tsx index a34dcf2e1b0..496bd561896 100644 --- a/src/walletConnect/index.tsx +++ b/src/walletConnect/index.tsx @@ -9,7 +9,7 @@ import { formatJsonRpcResult, formatJsonRpcError } from '@json-rpc-tools/utils'; import { gretch } from 'gretchen'; import messaging from '@react-native-firebase/messaging'; import WalletConnectCore, { Core } from '@walletconnect/core'; -import Client, { Web3Wallet, Web3WalletTypes } from '@walletconnect/web3wallet'; +import { WalletKit, WalletKitTypes, IWalletKit } from '@reown/walletkit'; import { isHexString } from '@ethersproject/bytes'; import { toUtf8String } from '@ethersproject/strings'; @@ -96,20 +96,20 @@ let lastConnector: string | undefined = undefined; let walletConnectCore: WalletConnectCore | undefined; -let web3WalletClient: ReturnType<(typeof Web3Wallet)['init']> | undefined; +let walletKitClient: ReturnType<(typeof WalletKit)['init']> | undefined; -let initPromise: Promise | undefined = undefined; +let initPromise: Promise | undefined = undefined; -let syncWeb3WalletClient: Client | undefined = undefined; +let syncWalletKitClient: IWalletKit | undefined = undefined; export const initializeWCv2 = async () => { if (!walletConnectCore) { walletConnectCore = new Core({ projectId: WC_PROJECT_ID }); } - if (!web3WalletClient) { + if (!walletKitClient) { // eslint-disable-next-line require-atomic-updates - web3WalletClient = Web3Wallet.init({ + walletKitClient = WalletKit.init({ core: walletConnectCore, metadata: { name: '🌈 Rainbow', @@ -124,10 +124,10 @@ export const initializeWCv2 = async () => { }); } - return web3WalletClient; + return walletKitClient; }; -export async function getWeb3WalletClient() { +export async function getWalletKitClient() { if (!initPromise) { initPromise = initializeWCv2(); } @@ -196,7 +196,7 @@ export function parseRPCParams({ method, params }: RPCPayload): { /** * Better signature for this type of function * - * @see https://docs.walletconnect.com/2.0/web/web3wallet/wallet-usage#-namespaces-builder-util + * @see https://docs.walletconnect.com/2.0/web/walletKit/wallet-usage#-namespaces-builder-util */ export function getApprovedNamespaces(props: Parameters[0]): | { @@ -303,7 +303,7 @@ async function rejectProposal({ proposal, reason, }: { - proposal: Web3WalletTypes.SessionProposal; + proposal: WalletKitTypes.SessionProposal; reason: Parameters[0]; }) { logger.warn(`[walletConnect]: session approval denied`, { @@ -311,7 +311,7 @@ async function rejectProposal({ proposal, }); - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); const { id, proposer } = proposal.params; await client.rejectSession({ id, reason: getSdkError(reason) }); @@ -323,11 +323,11 @@ async function rejectProposal({ } // listen for THIS topic pairing, and clear timeout if received -function trackTopicHandler(proposal: Web3WalletTypes.SessionProposal | Web3WalletTypes.AuthRequest) { +function trackTopicHandler(proposal: WalletKitTypes.SessionProposal | WalletKitTypes.AuthRequest) { logger.debug(`[walletConnect]: pair: handler`, { proposal }); const { metadata } = - (proposal as Web3WalletTypes.SessionProposal).params.proposer || (proposal as Web3WalletTypes.AuthRequest).params.requester; + (proposal as WalletKitTypes.SessionProposal).params.proposer || (proposal as WalletKitTypes.AuthRequest).params.requester; analytics.track(analytics.event.wcNewPairing, { dappName: metadata.name, @@ -344,7 +344,7 @@ export async function pair({ uri, connector }: { uri: string; connector?: string */ const { topic, ...rest } = parseUri(uri); - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); logger.debug(`[walletConnect]: pair: parsed uri`, { topic, rest }); @@ -355,16 +355,16 @@ export async function pair({ uri, connector }: { uri: string; connector?: string export async function initListeners() { PerformanceTracking.startMeasuring(PerformanceMetrics.initializeWalletconnect); - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); PerformanceTracking.finishMeasuring(PerformanceMetrics.initializeWalletconnect); - syncWeb3WalletClient = client; + syncWalletKitClient = client; - logger.debug(`[walletConnect]: web3WalletClient initialized, initListeners`, {}, logger.DebugContext.walletconnect); + logger.debug(`[walletConnect]: walletKitClient initialized, initListeners`, {}, logger.DebugContext.walletconnect); client.on('session_proposal', onSessionProposal); client.on('session_request', onSessionRequest); - client.on('auth_request', onAuthRequest); + client.on('session_authenticate', onSessionAuthenticate); client.on('session_delete', () => { logger.debug(`[walletConnect]: session_delete`, {}, logger.DebugContext.walletconnect); @@ -379,7 +379,7 @@ export async function initWalletConnectPushNotifications() { const token = await getFCMToken(); if (token) { - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); const client_id = await client.core.crypto.getClientId(); // initial subscription @@ -429,7 +429,7 @@ async function subscribeToEchoServer({ client_id, token }: { client_id: string; } } -export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposal) { +export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal) { try { trackTopicHandler(proposal); @@ -468,10 +468,15 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa verifiedData, timedOut: false, callback: async (approved, approvedChainId, accountAddress) => { - const client = await getWeb3WalletClient(); + console.log('[WC DEBUG] executing callback'); + const client = await getWalletKitClient(); + console.log('[WC DEBUG] got client'); + const { id, proposer, requiredNamespaces } = proposal.params; if (approved) { + console.log('[WC DEBUG] approved true'); + logger.debug( `[walletConnect]: session approved`, { @@ -502,7 +507,11 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa logger.debug(`[walletConnect]: session approved namespaces`, { namespaces }, logger.DebugContext.walletconnect); try { + console.log('[WC DEBUG] try'); + if (namespaces.success) { + console.log('[WC DEBUG] namespaces success'); + /** * This is equivalent handling of setPendingRequest and * walletConnectApproveSession, since setPendingRequest is only used @@ -516,6 +525,8 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa namespaces: namespaces.result, }); + console.log('[WC DEBUG] session approved'); + // let the ConnectedDappsSheet know we've got a new one events.emit('walletConnectV2SessionCreated'); @@ -533,6 +544,8 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa }); } } else { + console.log('[WC DEBUG] rejected proposal'); + await rejectProposal({ proposal, reason: 'INVALID_SESSION_SETTLE_REQUEST', @@ -546,6 +559,8 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa }); } } catch (e) { + console.log('[WC DEBUG] catch', e); + setHasPendingDeeplinkPendingRedirect(false); Alert({ @@ -566,6 +581,8 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa }); } } else if (!approved) { + console.log('[WC DEBUG] not approved'); + await rejectProposal({ proposal, reason: 'USER_REJECTED' }); } }, @@ -592,7 +609,7 @@ export async function onSessionProposal(proposal: Web3WalletTypes.SessionProposa // For WC v2 export async function onSessionRequest(event: SignClientTypes.EventArguments['session_request']) { setHasPendingDeeplinkPendingRedirect(true); - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); logger.debug(`[walletConnect]: session_request`, {}, logger.DebugContext.walletconnect); @@ -808,7 +825,7 @@ export async function handleSessionRequestResponse( success: Boolean(result), }); - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); const { topic, id } = sessionRequestEvent; if (result) { const payload = { @@ -829,10 +846,10 @@ export async function handleSessionRequestResponse( store.dispatch(removeRequest(sessionRequestEvent.id)); } -export async function onAuthRequest(event: Web3WalletTypes.AuthRequest) { +export async function onSessionAuthenticate(event: WalletKitTypes.AuthRequest) { trackTopicHandler(event); - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); logger.debug(`[walletConnect]: auth_request`, { event }, logger.DebugContext.walletconnect); @@ -929,7 +946,7 @@ export async function onAuthRequest(event: Web3WalletTypes.AuthRequest) { // need to prefetch dapp metadata since portal is static const url = - // @ts-ignore Web3WalletTypes.AuthRequest type is missing VerifyContext + // @ts-ignore WalletKitTypes.AuthRequest type is missing VerifyContext event?.verifyContext?.origin || event.params.requester.metadata.url; const metadata = await fetchDappMetadata({ url, status: true }); @@ -939,7 +956,7 @@ export async function onAuthRequest(event: Web3WalletTypes.AuthRequest) { AuthRequest({ authenticate, requesterMeta: event.params.requester.metadata, - // @ts-ignore Web3WalletTypes.AuthRequest type is missing VerifyContext + // @ts-ignore WalletKitTypes.AuthRequest type is missing VerifyContext verifiedData: event?.verifyContext, }), { sheetHeight: IS_ANDROID ? 560 : 520 + (isScam ? 40 : 0) } @@ -950,7 +967,7 @@ export async function onAuthRequest(event: Web3WalletTypes.AuthRequest) { * Returns all active settings in a type-safe manner. */ export async function getAllActiveSessions() { - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); return Object.values(client?.getActiveSessions() || {}) || []; } @@ -959,7 +976,7 @@ export async function getAllActiveSessions() { * in a type-safe manner. */ export function getAllActiveSessionsSync() { - return Object.values(syncWeb3WalletClient?.getActiveSessions() || {}) || []; + return Object.values(syncWalletKitClient?.getActiveSessions() || {}) || []; } /** @@ -967,7 +984,7 @@ export function getAllActiveSessionsSync() { */ export async function addAccountToSession(session: SessionTypes.Struct, { address }: { address?: string }) { try { - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); const namespaces: Parameters[0]['namespaces'] = {}; @@ -1028,7 +1045,7 @@ export async function addAccountToSession(session: SessionTypes.Struct, { addres export async function changeAccount(session: SessionTypes.Struct, { address }: { address?: string }) { try { - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); /* * Before we can effectively switch accounts, we need to add the account to @@ -1076,7 +1093,7 @@ export async function changeAccount(session: SessionTypes.Struct, { address }: { * within a dapp is handled internally by WC v2. */ export async function disconnectSession(session: SessionTypes.Struct) { - const client = await getWeb3WalletClient(); + const client = await getWalletKitClient(); await client.disconnectSession({ topic: session.topic, diff --git a/yarn.lock b/yarn.lock index ae432be3ab8..570738be361 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5164,6 +5164,21 @@ __metadata: languageName: node linkType: hard +"@reown/walletkit@npm:^1.0.0": + version: 1.1.0 + resolution: "@reown/walletkit@npm:1.1.0" + dependencies: + "@walletconnect/core": "npm:2.17.0" + "@walletconnect/jsonrpc-provider": "npm:1.0.14" + "@walletconnect/jsonrpc-utils": "npm:1.0.8" + "@walletconnect/logger": "npm:2.1.2" + "@walletconnect/sign-client": "npm:2.17.0" + "@walletconnect/types": "npm:2.17.0" + "@walletconnect/utils": "npm:2.17.0" + checksum: 10c0/1079b626bb978d086054ca2e2a53ada84209616726281c3f1ae06c7a5fb3bf4e1001fc5e6c651cbd2138720ec6c1c74e42aff371d79500a35bee4aa1eed1c3db + languageName: node + linkType: hard + "@reservoir0x/reservoir-sdk@npm:2.3.0": version: 2.3.0 resolution: "@reservoir0x/reservoir-sdk@npm:2.3.0" @@ -5838,7 +5853,7 @@ __metadata: languageName: node linkType: hard -"@stablelib/sha256@npm:1.0.1, @stablelib/sha256@npm:^1.0.1": +"@stablelib/sha256@npm:1.0.1": version: 1.0.1 resolution: "@stablelib/sha256@npm:1.0.1" dependencies: @@ -7051,27 +7066,6 @@ __metadata: languageName: node linkType: hard -"@walletconnect/auth-client@npm:2.1.2": - version: 2.1.2 - resolution: "@walletconnect/auth-client@npm:2.1.2" - dependencies: - "@ethersproject/hash": "npm:^5.7.0" - "@ethersproject/transactions": "npm:^5.7.0" - "@stablelib/random": "npm:^1.0.2" - "@stablelib/sha256": "npm:^1.0.1" - "@walletconnect/core": "npm:^2.10.1" - "@walletconnect/events": "npm:^1.0.1" - "@walletconnect/heartbeat": "npm:^1.2.1" - "@walletconnect/jsonrpc-utils": "npm:^1.0.8" - "@walletconnect/logger": "npm:^2.0.1" - "@walletconnect/time": "npm:^1.0.2" - "@walletconnect/utils": "npm:^2.10.1" - events: "npm:^3.3.0" - isomorphic-unfetch: "npm:^3.1.0" - checksum: 10c0/7c57ab68672cb7f1e89e9ac1607d3aa716f7d728d9c66937bee6f94df0f25c67f76db13cd7ac0e56ace1c4d872c5d126b4ab25f4251424aa6c481317ef37103f - languageName: node - linkType: hard - "@walletconnect/browser-utils@npm:^1.8.0": version: 1.8.0 resolution: "@walletconnect/browser-utils@npm:1.8.0" @@ -7097,9 +7091,9 @@ __metadata: languageName: node linkType: hard -"@walletconnect/core@npm:2.15.1": - version: 2.15.1 - resolution: "@walletconnect/core@npm:2.15.1" +"@walletconnect/core@npm:2.17.0": + version: 2.17.0 + resolution: "@walletconnect/core@npm:2.17.0" dependencies: "@walletconnect/heartbeat": "npm:1.2.2" "@walletconnect/jsonrpc-provider": "npm:1.0.14" @@ -7112,12 +7106,12 @@ __metadata: "@walletconnect/relay-auth": "npm:1.0.4" "@walletconnect/safe-json": "npm:1.0.2" "@walletconnect/time": "npm:1.0.2" - "@walletconnect/types": "npm:2.15.1" - "@walletconnect/utils": "npm:2.15.1" + "@walletconnect/types": "npm:2.17.0" + "@walletconnect/utils": "npm:2.17.0" events: "npm:3.3.0" lodash.isequal: "npm:4.5.0" uint8arrays: "npm:3.1.0" - checksum: 10c0/3c831303bffcc360bb7d2f6e71b9928e73039e34e582e8da3f03dbc67e7876cf3ff89491ec9bad7ae31c3c3706ea6e44d2cd1be501349e882739a5184e917797 + checksum: 10c0/34ae5b9b68c08c1dd3ebb2a6ebff8697307e76fbfe4d6b51d5d090da5cd1613e1c66fa5ac3a87c914333458d7b5bf075bb664292f6b2c7d438c72f706d87416d languageName: node linkType: hard @@ -7132,31 +7126,6 @@ __metadata: languageName: node linkType: hard -"@walletconnect/core@npm:^2.10.1": - version: 2.13.3 - resolution: "@walletconnect/core@npm:2.13.3" - dependencies: - "@walletconnect/heartbeat": "npm:1.2.2" - "@walletconnect/jsonrpc-provider": "npm:1.0.14" - "@walletconnect/jsonrpc-types": "npm:1.0.4" - "@walletconnect/jsonrpc-utils": "npm:1.0.8" - "@walletconnect/jsonrpc-ws-connection": "npm:1.0.14" - "@walletconnect/keyvaluestorage": "npm:1.1.1" - "@walletconnect/logger": "npm:2.1.2" - "@walletconnect/relay-api": "npm:1.0.10" - "@walletconnect/relay-auth": "npm:1.0.4" - "@walletconnect/safe-json": "npm:1.0.2" - "@walletconnect/time": "npm:1.0.2" - "@walletconnect/types": "npm:2.13.3" - "@walletconnect/utils": "npm:2.13.3" - events: "npm:3.3.0" - isomorphic-unfetch: "npm:3.1.0" - lodash.isequal: "npm:4.5.0" - uint8arrays: "npm:3.1.0" - checksum: 10c0/1f2ce950997330e89f2a773291426cb3cfe994227300ee74c683f6af282ac5069689406bf05ad752d443024802d570a2ae2f93b65e45439849453734122936c9 - languageName: node - linkType: hard - "@walletconnect/crypto@npm:^1.0.2": version: 1.0.3 resolution: "@walletconnect/crypto@npm:1.0.3" @@ -7201,7 +7170,7 @@ __metadata: languageName: node linkType: hard -"@walletconnect/heartbeat@npm:1.2.2, @walletconnect/heartbeat@npm:^1.2.1": +"@walletconnect/heartbeat@npm:1.2.2": version: 1.2.2 resolution: "@walletconnect/heartbeat@npm:1.2.2" dependencies: @@ -7308,7 +7277,7 @@ __metadata: languageName: node linkType: hard -"@walletconnect/logger@npm:2.1.2, @walletconnect/logger@npm:^2.0.1": +"@walletconnect/logger@npm:2.1.2": version: 2.1.2 resolution: "@walletconnect/logger@npm:2.1.2" dependencies: @@ -7330,9 +7299,9 @@ __metadata: languageName: node linkType: hard -"@walletconnect/react-native-compat@npm:2.15.1": - version: 2.15.1 - resolution: "@walletconnect/react-native-compat@npm:2.15.1" +"@walletconnect/react-native-compat@npm:2.17.0": + version: 2.17.0 + resolution: "@walletconnect/react-native-compat@npm:2.17.0" dependencies: events: "npm:3.3.0" fast-text-encoding: "npm:1.0.6" @@ -7345,16 +7314,7 @@ __metadata: peerDependenciesMeta: expo-application: optional: true - checksum: 10c0/996452a58797b811b4417c649943602decadb5cbe4dd2717f1aaaed42df0bebcbaeda81e43754d62c319d335702d9e1cb8161e9102ce1bd25354e41588b26b97 - languageName: node - linkType: hard - -"@walletconnect/relay-api@npm:1.0.10": - version: 1.0.10 - resolution: "@walletconnect/relay-api@npm:1.0.10" - dependencies: - "@walletconnect/jsonrpc-types": "npm:^1.0.2" - checksum: 10c0/2709bbe45f60579cd2e1c74b0fd03c36ea409cd8a9117e00a7485428d0c9ba7eb02e525c21e5286db2b6ce563b1d29053b0249c2ed95f8adcf02b11e54f61fcd + checksum: 10c0/936f93b2f96fcd4f0eb4df4de19c20f76b0daec5568c49fe7e346157b9486e2c4a8f538d9094e5902a9eae736eb64d42e6be77009fbed1364e63ff22fca67743 languageName: node linkType: hard @@ -7397,20 +7357,20 @@ __metadata: languageName: node linkType: hard -"@walletconnect/sign-client@npm:2.15.1": - version: 2.15.1 - resolution: "@walletconnect/sign-client@npm:2.15.1" +"@walletconnect/sign-client@npm:2.17.0": + version: 2.17.0 + resolution: "@walletconnect/sign-client@npm:2.17.0" dependencies: - "@walletconnect/core": "npm:2.15.1" + "@walletconnect/core": "npm:2.17.0" "@walletconnect/events": "npm:1.0.1" "@walletconnect/heartbeat": "npm:1.2.2" "@walletconnect/jsonrpc-utils": "npm:1.0.8" "@walletconnect/logger": "npm:2.1.2" "@walletconnect/time": "npm:1.0.2" - "@walletconnect/types": "npm:2.15.1" - "@walletconnect/utils": "npm:2.15.1" + "@walletconnect/types": "npm:2.17.0" + "@walletconnect/utils": "npm:2.17.0" events: "npm:3.3.0" - checksum: 10c0/4ff66239c2994cb501cd1830b2cbc2ecf854799cfc4d100cc6af3523f8524daead7c08daa7dba944def79640515ccabe2250f700e0be1a07dfee5c3668aa2dee + checksum: 10c0/48f7d13b3db49584a40dc2653f49fabadd100a324e2213476b8d9e4d6fe0808a08ae14103d2e5b609abff3115197003d8570d606275dbd0f6774d0d49da10c61 languageName: node linkType: hard @@ -7434,23 +7394,9 @@ __metadata: languageName: node linkType: hard -"@walletconnect/types@npm:2.13.3": - version: 2.13.3 - resolution: "@walletconnect/types@npm:2.13.3" - dependencies: - "@walletconnect/events": "npm:1.0.1" - "@walletconnect/heartbeat": "npm:1.2.2" - "@walletconnect/jsonrpc-types": "npm:1.0.4" - "@walletconnect/keyvaluestorage": "npm:1.1.1" - "@walletconnect/logger": "npm:2.1.2" - events: "npm:3.3.0" - checksum: 10c0/b12e92e39fa2fd9dbdfbef62265c7f5e5aa1d824b6db68ea5ce4fa9ed56c9fcdf6d93fbc6ffeb57169cff4082d475899739377b91f2b13f5209c8ccb66c47d6e - languageName: node - linkType: hard - -"@walletconnect/types@npm:2.15.1": - version: 2.15.1 - resolution: "@walletconnect/types@npm:2.15.1" +"@walletconnect/types@npm:2.17.0": + version: 2.17.0 + resolution: "@walletconnect/types@npm:2.17.0" dependencies: "@walletconnect/events": "npm:1.0.1" "@walletconnect/heartbeat": "npm:1.2.2" @@ -7458,7 +7404,7 @@ __metadata: "@walletconnect/keyvaluestorage": "npm:1.1.1" "@walletconnect/logger": "npm:2.1.2" events: "npm:3.3.0" - checksum: 10c0/0666874a4acd9326f2554542936a88f6df50ca958440254ab605dca81d57cdaf839b05cac983ad194f4ed44734d07d564f4277156556cadac07302e8dd86aa4d + checksum: 10c0/bdc0c062da1edb4410882d9cfca1bb30eb0afd7caea90d5e7a66eaf15e28380e9ef97635cd5e5a017947f4c814c1f780622b4d8946b11a335d415ae066ec7ade languageName: node linkType: hard @@ -7469,31 +7415,9 @@ __metadata: languageName: node linkType: hard -"@walletconnect/utils@npm:2.13.3, @walletconnect/utils@npm:^2.10.1": - version: 2.13.3 - resolution: "@walletconnect/utils@npm:2.13.3" - dependencies: - "@stablelib/chacha20poly1305": "npm:1.0.1" - "@stablelib/hkdf": "npm:1.0.1" - "@stablelib/random": "npm:1.0.2" - "@stablelib/sha256": "npm:1.0.1" - "@stablelib/x25519": "npm:1.0.3" - "@walletconnect/relay-api": "npm:1.0.10" - "@walletconnect/safe-json": "npm:1.0.2" - "@walletconnect/time": "npm:1.0.2" - "@walletconnect/types": "npm:2.13.3" - "@walletconnect/window-getters": "npm:1.0.1" - "@walletconnect/window-metadata": "npm:1.0.1" - detect-browser: "npm:5.3.0" - query-string: "npm:7.1.3" - uint8arrays: "npm:3.1.0" - checksum: 10c0/d33d66f306612637ed29f113c3cf6fd28f2a0c1062f88eafde2e9d2689859418725be0591c14d8a38ba24f56b70874117d47a6aa7ce0c1efa16e6eb6e3b79aad - languageName: node - linkType: hard - -"@walletconnect/utils@npm:2.15.1": - version: 2.15.1 - resolution: "@walletconnect/utils@npm:2.15.1" +"@walletconnect/utils@npm:2.17.0": + version: 2.17.0 + resolution: "@walletconnect/utils@npm:2.17.0" dependencies: "@stablelib/chacha20poly1305": "npm:1.0.1" "@stablelib/hkdf": "npm:1.0.1" @@ -7501,15 +7425,17 @@ __metadata: "@stablelib/sha256": "npm:1.0.1" "@stablelib/x25519": "npm:1.0.3" "@walletconnect/relay-api": "npm:1.0.11" + "@walletconnect/relay-auth": "npm:1.0.4" "@walletconnect/safe-json": "npm:1.0.2" "@walletconnect/time": "npm:1.0.2" - "@walletconnect/types": "npm:2.15.1" + "@walletconnect/types": "npm:2.17.0" "@walletconnect/window-getters": "npm:1.0.1" "@walletconnect/window-metadata": "npm:1.0.1" detect-browser: "npm:5.3.0" + elliptic: "npm:^6.5.7" query-string: "npm:7.1.3" uint8arrays: "npm:3.1.0" - checksum: 10c0/bde087f530f91502ba26c9553abd464234adb5738c7e10cfbdd275699d630a81601b5928abeeb77abe29e88238a4067a1bd1c5159f04b49178452066c82d99ae + checksum: 10c0/d1da74b2cd7af35f16d735fe408cfc820c611b2709bd00899e4e91b0b0a6dcd8f344f97df34d0ef8cabc121619a40b62118ffa2aa233ddba9863d1ba23480a0c languageName: node linkType: hard @@ -7528,22 +7454,6 @@ __metadata: languageName: node linkType: hard -"@walletconnect/web3wallet@npm:1.14.1": - version: 1.14.1 - resolution: "@walletconnect/web3wallet@npm:1.14.1" - dependencies: - "@walletconnect/auth-client": "npm:2.1.2" - "@walletconnect/core": "npm:2.15.1" - "@walletconnect/jsonrpc-provider": "npm:1.0.14" - "@walletconnect/jsonrpc-utils": "npm:1.0.8" - "@walletconnect/logger": "npm:2.1.2" - "@walletconnect/sign-client": "npm:2.15.1" - "@walletconnect/types": "npm:2.15.1" - "@walletconnect/utils": "npm:2.15.1" - checksum: 10c0/1918cb3319036fef3ed5565a607b230e083ea37b12a067df22f1bc81ab34fcf9a48d7ff2f4eb9dbd16066432f0e53460db727466b976e009bab378db5b4da1f6 - languageName: node - linkType: hard - "@walletconnect/window-getters@npm:1.0.0": version: 1.0.0 resolution: "@walletconnect/window-getters@npm:1.0.0" @@ -7904,6 +7814,7 @@ __metadata: "@react-navigation/material-top-tabs": "npm:6.6.2" "@react-navigation/native": "npm:6.1.17" "@react-navigation/stack": "npm:6.3.29" + "@reown/walletkit": "npm:^1.0.0" "@reservoir0x/reservoir-sdk": "npm:2.3.0" "@rnx-kit/align-deps": "npm:2.2.4" "@rudderstack/rudder-sdk-react-native": "npm:1.12.1" @@ -7935,12 +7846,11 @@ __metadata: "@unstoppabledomains/resolution": "npm:7.1.4" "@wagmi/chains": "npm:1.8.0" "@walletconnect/client": "npm:1.8.0" - "@walletconnect/core": "npm:2.15.1" + "@walletconnect/core": "npm:2.17.0" "@walletconnect/legacy-utils": "npm:2.0.0" - "@walletconnect/react-native-compat": "npm:2.15.1" - "@walletconnect/types": "npm:2.15.1" - "@walletconnect/utils": "npm:2.15.1" - "@walletconnect/web3wallet": "npm:1.14.1" + "@walletconnect/react-native-compat": "npm:2.17.0" + "@walletconnect/types": "npm:2.17.0" + "@walletconnect/utils": "npm:2.17.0" assert: "npm:1.5.0" ast-parser: "npm:0.0.5" async-mutex: "npm:0.3.2" @@ -12159,6 +12069,21 @@ __metadata: languageName: node linkType: hard +"elliptic@npm:^6.5.7": + version: 6.5.7 + resolution: "elliptic@npm:6.5.7" + dependencies: + bn.js: "npm:^4.11.9" + brorand: "npm:^1.1.0" + hash.js: "npm:^1.0.0" + hmac-drbg: "npm:^1.0.1" + inherits: "npm:^2.0.4" + minimalistic-assert: "npm:^1.0.1" + minimalistic-crypto-utils: "npm:^1.0.1" + checksum: 10c0/799959b6c54ea3564e8961f35abdf8c77e37617f3051614b05ab1fb6a04ddb65bd1caa75ed1bae375b15dda312a0f79fed26ebe76ecf05c5a7af244152a601b8 + languageName: node + linkType: hard + "emittery@npm:^0.13.1": version: 0.13.1 resolution: "emittery@npm:0.13.1" @@ -15914,16 +15839,6 @@ __metadata: languageName: node linkType: hard -"isomorphic-unfetch@npm:3.1.0, isomorphic-unfetch@npm:^3.1.0": - version: 3.1.0 - resolution: "isomorphic-unfetch@npm:3.1.0" - dependencies: - node-fetch: "npm:^2.6.1" - unfetch: "npm:^4.2.0" - checksum: 10c0/d3b61fca06304db692b7f76bdfd3a00f410e42cfa7403c3b250546bf71589d18cf2f355922f57198e4cc4a9872d3647b20397a5c3edf1a347c90d57c83cf2a89 - languageName: node - linkType: hard - "isows@npm:1.0.3": version: 1.0.3 resolution: "isows@npm:1.0.3" @@ -18902,7 +18817,7 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:^2.2.0, node-fetch@npm:^2.6.0, node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7": +"node-fetch@npm:^2.2.0, node-fetch@npm:^2.6.0, node-fetch@npm:^2.6.7": version: 2.7.0 resolution: "node-fetch@npm:2.7.0" dependencies: @@ -24859,13 +24774,6 @@ react-native-safe-area-view@rainbow-me/react-native-safe-area-view: languageName: node linkType: hard -"unfetch@npm:^4.2.0": - version: 4.2.0 - resolution: "unfetch@npm:4.2.0" - checksum: 10c0/a5c0a896a6f09f278b868075aea65652ad185db30e827cb7df45826fe5ab850124bf9c44c4dafca4bf0c55a0844b17031e8243467fcc38dd7a7d435007151f1b - languageName: node - linkType: hard - "unicode-canonical-property-names-ecmascript@npm:^2.0.0": version: 2.0.0 resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0" From 789d6acf40f7bbbb018d23c1bcc76dba1428d9ec Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Thu, 3 Oct 2024 16:14:12 -0400 Subject: [PATCH 2/4] linting --- src/walletConnect/index.tsx | 16 +++++++++++----- src/walletConnect/sheets/AuthRequest.tsx | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/walletConnect/index.tsx b/src/walletConnect/index.tsx index 496bd561896..112fbcdcac3 100644 --- a/src/walletConnect/index.tsx +++ b/src/walletConnect/index.tsx @@ -323,11 +323,10 @@ async function rejectProposal({ } // listen for THIS topic pairing, and clear timeout if received -function trackTopicHandler(proposal: WalletKitTypes.SessionProposal | WalletKitTypes.AuthRequest) { +function trackTopicHandler(proposal: WalletKitTypes.SessionProposal) { logger.debug(`[walletConnect]: pair: handler`, { proposal }); - const { metadata } = - (proposal as WalletKitTypes.SessionProposal).params.proposer || (proposal as WalletKitTypes.AuthRequest).params.requester; + const { metadata } = (proposal as WalletKitTypes.SessionProposal).params.proposer; analytics.track(analytics.event.wcNewPairing, { dappName: metadata.name, @@ -846,7 +845,9 @@ export async function handleSessionRequestResponse( store.dispatch(removeRequest(sessionRequestEvent.id)); } -export async function onSessionAuthenticate(event: WalletKitTypes.AuthRequest) { +export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthenticate) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Can be fixed once we wipe wc v1 from the codebase trackTopicHandler(event); const client = await getWalletKitClient(); @@ -862,6 +863,8 @@ export async function onSessionAuthenticate(event: WalletKitTypes.AuthRequest) { // exit early if possible if (selectedWallet?.type === WalletTypes.readOnly) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Can be fixed once we wipe wc v1 from the codebase await client.respondAuthRequest( { id: event.id, @@ -892,7 +895,8 @@ export async function onSessionAuthenticate(event: WalletKitTypes.AuthRequest) { return undefined; } - + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Can be fixed once we wipe wc v1 from the codebase const message = client.formatMessage(event.params.cacaoPayload, iss); // prompt the user to sign the message return wallet.signMessage(message); @@ -921,6 +925,8 @@ export async function onSessionAuthenticate(event: WalletKitTypes.AuthRequest) { } // respond to WC + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Can be fixed once we wipe wc v1 from the codebase await client.respondAuthRequest( { id: event.id, diff --git a/src/walletConnect/sheets/AuthRequest.tsx b/src/walletConnect/sheets/AuthRequest.tsx index 7c7eefb5936..338acad39b4 100644 --- a/src/walletConnect/sheets/AuthRequest.tsx +++ b/src/walletConnect/sheets/AuthRequest.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { useNavigation } from '@react-navigation/native'; -import { Web3WalletTypes } from '@walletconnect/web3wallet'; import { Box, Text, Separator, BackgroundProvider, AccentColorProvider } from '@/design-system'; import ButtonPressAnimation from '@/components/animations/ButtonPressAnimation'; @@ -19,13 +18,14 @@ import { Verify } from '@walletconnect/types'; import { useDappMetadata } from '@/resources/metadata/dapp'; import { DAppStatus } from '@/graphql/__generated__/metadata'; import { InfoAlert } from '@/components/info-alert/info-alert'; +import { WalletKitTypes } from '@reown/walletkit'; export function AuthRequest({ requesterMeta, authenticate, verifiedData, }: { - requesterMeta: Web3WalletTypes.AuthRequest['params']['requester']['metadata']; + requesterMeta: WalletKitTypes.SessionProposal['params']['proposer']['metadata']; authenticate: AuthRequestAuthenticateSignature; verifiedData?: Verify.Context['verified']; }) { From b8f76a3d5fd43616e12b725370f9c3561d81f49b Mon Sep 17 00:00:00 2001 From: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:44:13 -0400 Subject: [PATCH 3/4] cleanup walletkit ts-ignores (#6172) Co-authored-by: Matthew Wall --- src/walletConnect/index.tsx | 64 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/walletConnect/index.tsx b/src/walletConnect/index.tsx index 112fbcdcac3..03e5c936871 100644 --- a/src/walletConnect/index.tsx +++ b/src/walletConnect/index.tsx @@ -323,10 +323,10 @@ async function rejectProposal({ } // listen for THIS topic pairing, and clear timeout if received -function trackTopicHandler(proposal: WalletKitTypes.SessionProposal) { +function trackTopicHandler(proposal: WalletKitTypes.SessionProposal | WalletKitTypes.SessionAuthenticate) { logger.debug(`[walletConnect]: pair: handler`, { proposal }); - const { metadata } = (proposal as WalletKitTypes.SessionProposal).params.proposer; + const { metadata } = 'proposer' in proposal.params ? proposal.params.proposer : proposal.params.requester; analytics.track(analytics.event.wcNewPairing, { dappName: metadata.name, @@ -613,7 +613,9 @@ export async function onSessionRequest(event: SignClientTypes.EventArguments['se logger.debug(`[walletConnect]: session_request`, {}, logger.DebugContext.walletconnect); const { id, topic } = event; - const { method, params } = event.params.request; + const { method: _method, params } = event.params.request; + + const method = _method as RPCMethod; logger.debug(`[walletConnect]: session_request method`, { method, params }, logger.DebugContext.walletconnect); @@ -631,10 +633,10 @@ export async function onSessionRequest(event: SignClientTypes.EventArguments['se }); return; } - if (isSupportedMethod(method as RPCMethod)) { - const isSigningMethod = isSupportedSigningMethod(method as RPCMethod); + if (isSupportedMethod(method)) { + const isSigningMethod = isSupportedSigningMethod(method); const { address, message } = parseRPCParams({ - method: method as RPCMethod, + method, params, }); if (!address) { @@ -846,8 +848,6 @@ export async function handleSessionRequestResponse( } export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthenticate) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore Can be fixed once we wipe wc v1 from the codebase trackTopicHandler(event); const client = await getWalletKitClient(); @@ -857,24 +857,23 @@ export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthent const authenticate: AuthRequestAuthenticateSignature = async ({ address }) => { try { const { wallets } = store.getState().wallets; - const selectedWallet = findWalletWithAccount(wallets!, address); + const selectedWallet = findWalletWithAccount(wallets || {}, address); const isHardwareWallet = selectedWallet?.type === WalletTypes.bluetooth; const iss = `did:pkh:eip155:1:${address}`; // exit early if possible if (selectedWallet?.type === WalletTypes.readOnly) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore Can be fixed once we wipe wc v1 from the codebase - await client.respondAuthRequest( - { + await client.respondSessionRequest({ + topic: event.topic, + response: { id: event.id, error: { code: 0, message: `Wallet is read-only`, }, + jsonrpc: '2.0', }, - iss - ); + }); return { success: false, @@ -895,9 +894,10 @@ export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthent return undefined; } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore Can be fixed once we wipe wc v1 from the codebase - const message = client.formatMessage(event.params.cacaoPayload, iss); + const message = client.formatAuthMessage({ + iss, + request: event.params.authPayload, + }); // prompt the user to sign the message return wallet.signMessage(message); }; @@ -925,18 +925,19 @@ export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthent } // respond to WC - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore Can be fixed once we wipe wc v1 from the codebase - await client.respondAuthRequest( - { + await client.respondSessionRequest({ + topic: event.topic, + response: { id: event.id, - signature: { - s: signature, - t: 'eip191', - }, + result: JSON.stringify({ + signature: { + s: signature, + t: 'eip191', + }, + }), + jsonrpc: '2.0', }, - iss - ); + }); // only handled on success maybeGoBackAndClearHasPendingRedirect({ delay: 300 }); @@ -951,9 +952,7 @@ export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthent }; // need to prefetch dapp metadata since portal is static - const url = - // @ts-ignore WalletKitTypes.AuthRequest type is missing VerifyContext - event?.verifyContext?.origin || event.params.requester.metadata.url; + const url = event?.verifyContext?.verified?.origin || event.params.requester.metadata.url; const metadata = await fetchDappMetadata({ url, status: true }); const isScam = metadata.status === DAppStatus.Scam; @@ -962,8 +961,7 @@ export async function onSessionAuthenticate(event: WalletKitTypes.SessionAuthent AuthRequest({ authenticate, requesterMeta: event.params.requester.metadata, - // @ts-ignore WalletKitTypes.AuthRequest type is missing VerifyContext - verifiedData: event?.verifyContext, + verifiedData: event?.verifyContext.verified, }), { sheetHeight: IS_ANDROID ? 560 : 520 + (isScam ? 40 : 0) } ); From d5a6f1a6f8de6b4630e8e51f3be3d2a10cdd63ed Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Fri, 4 Oct 2024 12:48:57 -0400 Subject: [PATCH 4/4] remove console logs --- src/walletConnect/index.tsx | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/walletConnect/index.tsx b/src/walletConnect/index.tsx index 03e5c936871..b52e241ea58 100644 --- a/src/walletConnect/index.tsx +++ b/src/walletConnect/index.tsx @@ -467,15 +467,11 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal verifiedData, timedOut: false, callback: async (approved, approvedChainId, accountAddress) => { - console.log('[WC DEBUG] executing callback'); const client = await getWalletKitClient(); - console.log('[WC DEBUG] got client'); const { id, proposer, requiredNamespaces } = proposal.params; if (approved) { - console.log('[WC DEBUG] approved true'); - logger.debug( `[walletConnect]: session approved`, { @@ -506,11 +502,7 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal logger.debug(`[walletConnect]: session approved namespaces`, { namespaces }, logger.DebugContext.walletconnect); try { - console.log('[WC DEBUG] try'); - if (namespaces.success) { - console.log('[WC DEBUG] namespaces success'); - /** * This is equivalent handling of setPendingRequest and * walletConnectApproveSession, since setPendingRequest is only used @@ -524,8 +516,6 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal namespaces: namespaces.result, }); - console.log('[WC DEBUG] session approved'); - // let the ConnectedDappsSheet know we've got a new one events.emit('walletConnectV2SessionCreated'); @@ -543,8 +533,6 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal }); } } else { - console.log('[WC DEBUG] rejected proposal'); - await rejectProposal({ proposal, reason: 'INVALID_SESSION_SETTLE_REQUEST', @@ -558,8 +546,6 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal }); } } catch (e) { - console.log('[WC DEBUG] catch', e); - setHasPendingDeeplinkPendingRedirect(false); Alert({ @@ -580,8 +566,6 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal }); } } else if (!approved) { - console.log('[WC DEBUG] not approved'); - await rejectProposal({ proposal, reason: 'USER_REJECTED' }); } },