From 154d6678a88659e45822a3ad985aabad0cab5f1b Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Wed, 15 May 2024 11:13:30 +0200 Subject: [PATCH 01/13] fix: publicKey resolution --- .../communication-client/WalletConnectCommunicationClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 52c3ef20c..9e3782669 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -443,7 +443,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.SIGN, params: { - account: account, + account: account.startsWith('edpk') ? await getAddressFromPublicKey(account) : account, payload: signPayloadRequest.payload } } @@ -509,7 +509,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.OPERATION_REQUEST, params: { - account, + account: account.startsWith('edpk') ? await getAddressFromPublicKey(account) : account, operations: operationRequest.operationDetails } } From b6f81952d13f9219f2d24c26830deb99edf71563 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Wed, 15 May 2024 11:20:08 +0200 Subject: [PATCH 02/13] fix: network type --- examples/dapp.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dapp.html b/examples/dapp.html index 8f33e4a2c..a2ff931e8 100644 --- a/examples/dapp.html +++ b/examples/dapp.html @@ -234,7 +234,7 @@ }, featuredWallets: ['kukai', 'metamask', 'airgap'], network: { - type: beacon.NetworkType.MAINNET + type: beacon.NetworkType.GHOSTNET }, enableMetrics: true // matrixNodes: ['test.papers.tech', 'test2.papers.tech', 'matrix.papers.tech'] From e6678d3fbe82c6c9efe8c0dfbf590cb17a22eb48 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 31 May 2024 10:32:56 +0200 Subject: [PATCH 03/13] chore: migrate kukai web to WC --- packages/beacon-ui/src/ui/alert/index.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/beacon-ui/src/ui/alert/index.tsx b/packages/beacon-ui/src/ui/alert/index.tsx index ba8936f99..c988f92e6 100644 --- a/packages/beacon-ui/src/ui/alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/index.tsx @@ -489,10 +489,7 @@ const openAlert = async (config: AlertConfig): Promise => { let link = '' - if ( - wallet.supportedInteractionStandards?.includes('wallet_connect') && - !wallet.name.toLowerCase().includes('kukai') - ) { + if (wallet.supportedInteractionStandards?.includes('wallet_connect')) { const uri = await generateLink() if (!uri) { @@ -586,10 +583,7 @@ const openAlert = async (config: AlertConfig): Promise => { }) ) - if ( - (wallet?.types.includes('web') && wallet?.types.length === 1) || - (isAndroid(window) && wallet?.name.toLowerCase().includes('kukai')) - ) { + if (wallet?.types.includes('web') && wallet?.types.length === 1) { handleNewTab(config, wallet) return } From bbf3be65ea6b03e2e3a4974e07efd75b9bf47c41 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 31 May 2024 10:49:10 +0200 Subject: [PATCH 04/13] feat: add sdk version in sessionProperties --- .../WalletConnectCommunicationClient.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 9e3782669..1daaec4a7 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -4,7 +4,8 @@ import { Serializer, ClientEvents, Logger, - WCStorage + WCStorage, + SDK_VERSION } from '@airgap/beacon-core' import Client from '@walletconnect/sign-client' import { ProposalTypes, SessionTypes, SignClientTypes } from '@walletconnect/types' @@ -48,6 +49,7 @@ import { import { generateGUID, getAddressFromPublicKey } from '@airgap/beacon-utils' const TEZOS_PLACEHOLDER = 'tezos' +const BEACON_SDK_VERSION = 'beacon_sdk_version' const logger = new Logger('WalletConnectCommunicationClient') export interface PermissionScopeParam { @@ -623,6 +625,9 @@ export class WalletConnectCommunicationClient extends CommunicationClient { }, optionalNamespaces: { [TEZOS_PLACEHOLDER]: this.permissionScopeParamsToNamespaces(optionalPermissionScopeParams) + }, + sessionProperties: { + [BEACON_SDK_VERSION]: SDK_VERSION } } @@ -1015,6 +1020,9 @@ export class WalletConnectCommunicationClient extends CommunicationClient { optionalNamespaces: { [TEZOS_PLACEHOLDER]: this.permissionScopeParamsToNamespaces(optionalPermissionScopeParams) }, + sessionProperties: { + [BEACON_SDK_VERSION]: SDK_VERSION + }, pairingTopic } From 7b86f535aaae571b634019658d5fea344e72cdd9 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 31 May 2024 10:59:08 +0200 Subject: [PATCH 05/13] feat: add isPublicKey --- .../WalletConnectCommunicationClient.ts | 10 +++++----- packages/beacon-utils/src/index.ts | 3 ++- packages/beacon-utils/src/utils/crypto.ts | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 1daaec4a7..51974c120 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -46,7 +46,7 @@ import { StorageKey, TransportType } from '@airgap/beacon-types' -import { generateGUID, getAddressFromPublicKey } from '@airgap/beacon-utils' +import { generateGUID, getAddressFromPublicKey, isPublicKey } from '@airgap/beacon-utils' const TEZOS_PLACEHOLDER = 'tezos' const BEACON_SDK_VERSION = 'beacon_sdk_version' @@ -351,7 +351,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { const accounts = this.getTezosNamespace(session.namespaces).accounts const addressOrPbk = accounts[0].split(':', 3)[2] - if (addressOrPbk.startsWith('edpk')) { + if (isPublicKey(addressOrPbk)) { publicKey = addressOrPbk } else { if (network.type !== this.wcOptions.network) { @@ -445,7 +445,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.SIGN, params: { - account: account.startsWith('edpk') ? await getAddressFromPublicKey(account) : account, + account: isPublicKey(account) ? await getAddressFromPublicKey(account) : account, payload: signPayloadRequest.payload } } @@ -511,7 +511,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.OPERATION_REQUEST, params: { - account: account.startsWith('edpk') ? await getAddressFromPublicKey(account) : account, + account: isPublicKey(account) ? await getAddressFromPublicKey(account) : account, operations: operationRequest.operationDetails } } @@ -800,7 +800,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.activeNetwork = chainId - if (addressOrPbk.startsWith('edpk')) { + if (isPublicKey(addressOrPbk)) { publicKey = addressOrPbk this.activeAccount = await getAddressFromPublicKey(publicKey) } else { diff --git a/packages/beacon-utils/src/index.ts b/packages/beacon-utils/src/index.ts index 94d03b2ab..3be8f7f97 100644 --- a/packages/beacon-utils/src/index.ts +++ b/packages/beacon-utils/src/index.ts @@ -13,7 +13,8 @@ export { signMessage, isValidAddress, prefixPublicKey, - encodePoeChallengePayload + encodePoeChallengePayload, + isPublicKey } from './utils/crypto' export { generateGUID } from './utils/generate-uuid' diff --git a/packages/beacon-utils/src/utils/crypto.ts b/packages/beacon-utils/src/utils/crypto.ts index f8fb81453..f08b59bbb 100644 --- a/packages/beacon-utils/src/utils/crypto.ts +++ b/packages/beacon-utils/src/utils/crypto.ts @@ -292,4 +292,18 @@ export function encodePoeChallengePayload(payload: string) { ) } +export function isPublicKey(publicKey: string) { + const ed25519Regex = /^edpk[1-9A-HJ-NP-Za-km-z]{50}$/ + const secp256k1Regex = /^sppk[1-9A-HJ-NP-Za-km-z]{50}$/ + const p256Regex = /^p2pk[1-9A-HJ-NP-Za-km-z]{50}$/ + const bls12_381Regex = /^BLpk[1-9A-HJ-NP-Za-km-z]{50}$/ + + return ( + ed25519Regex.test(publicKey) || + secp256k1Regex.test(publicKey) || + p256Regex.test(publicKey) || + bls12_381Regex.test(publicKey) + ) +} + /* eslint-enable prefer-arrow/prefer-arrow-functions */ From 982dd58e09904437ef053b2ec868430ea0319f75 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 31 May 2024 11:26:31 +0200 Subject: [PATCH 06/13] feat: add tz4 --- packages/beacon-utils/src/utils/crypto.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/beacon-utils/src/utils/crypto.ts b/packages/beacon-utils/src/utils/crypto.ts index f08b59bbb..e57b51618 100644 --- a/packages/beacon-utils/src/utils/crypto.ts +++ b/packages/beacon-utils/src/utils/crypto.ts @@ -169,6 +169,11 @@ export async function getAddressFromPublicKey(publicKey: string): Promise Date: Fri, 31 May 2024 11:27:06 +0200 Subject: [PATCH 07/13] fix: typo --- packages/beacon-transport-walletconnect/src/error.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/error.ts b/packages/beacon-transport-walletconnect/src/error.ts index b667fb44b..0ea2b3e1e 100644 --- a/packages/beacon-transport-walletconnect/src/error.ts +++ b/packages/beacon-transport-walletconnect/src/error.ts @@ -85,7 +85,7 @@ export class ActiveAccountUnspecified extends Error { /** * @category Error - * @description Error that indicates the combinaison pkh-network is not part of the active session + * @description Error that indicates the combinatison pkh-network is not part of the active session */ export class InvalidNetworkOrAccount extends Error { name = 'InvalidNetworkOrAccount' @@ -95,7 +95,7 @@ export class InvalidNetworkOrAccount extends Error { public pkh: string ) { super( - `No permission. The combinaison "${network}" and "${pkh}" is not part of the active session.` + `No permission. The combinatison "${network}" and "${pkh}" is not part of the active session.` ) } } From 066682b6fcadb4e9634568145cafd93e4c51f8a4 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 31 May 2024 11:27:59 +0200 Subject: [PATCH 08/13] fix: typo --- packages/beacon-transport-walletconnect/src/error.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/error.ts b/packages/beacon-transport-walletconnect/src/error.ts index 0ea2b3e1e..8dfd63b3b 100644 --- a/packages/beacon-transport-walletconnect/src/error.ts +++ b/packages/beacon-transport-walletconnect/src/error.ts @@ -85,7 +85,7 @@ export class ActiveAccountUnspecified extends Error { /** * @category Error - * @description Error that indicates the combinatison pkh-network is not part of the active session + * @description Error that indicates the combination pkh-network is not part of the active session */ export class InvalidNetworkOrAccount extends Error { name = 'InvalidNetworkOrAccount' @@ -95,7 +95,7 @@ export class InvalidNetworkOrAccount extends Error { public pkh: string ) { super( - `No permission. The combinatison "${network}" and "${pkh}" is not part of the active session.` + `No permission. The combination "${network}" and "${pkh}" is not part of the active session.` ) } } From a44a1fbb0c4f801550fd99dbd8421026162b643e Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 31 May 2024 11:42:42 +0200 Subject: [PATCH 09/13] fix: address or pbk --- .../WalletConnectCommunicationClient.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 51974c120..fd0c443d7 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -101,7 +101,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { public signClient: Client | undefined public storage: WCStorage = new WCStorage() private session: SessionTypes.Struct | undefined - private activeAccount: string | undefined + private activeAccountOrPbk: string | undefined private activeNetwork: string | undefined readonly disconnectionEvents: Set = new Set() private pingInterval: NodeJS.Timeout | undefined @@ -403,7 +403,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { throw new MissingRequiredScope(PermissionScopeMethods.GET_ACCOUNTS) } - if (this.activeAccount) { + if (this.activeAccountOrPbk) { try { await this.openSession() } catch (error: any) { @@ -679,7 +679,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { if (session?.controller !== this.session?.controller) { logger.debug('Controller doesnt match, closing active session', [session.pairingTopic]) - this.activeAccount && this.closeActiveSession(this.activeAccount, false) + this.activeAccountOrPbk && this.closeActiveSession(this.activeAccountOrPbk, false) this.session = undefined // close the previous session } @@ -799,14 +799,10 @@ export class WalletConnectCommunicationClient extends CommunicationClient { let publicKey: string | undefined this.activeNetwork = chainId + this.activeAccountOrPbk = addressOrPbk - if (isPublicKey(addressOrPbk)) { - publicKey = addressOrPbk - this.activeAccount = await getAddressFromPublicKey(publicKey) - } else { - this.activeAccount = addressOrPbk + if (!isPublicKey(addressOrPbk)) { const result = await this.fetchAccounts(session.topic, `${TEZOS_PLACEHOLDER}:${chainId}`) - publicKey = result?.find(({ address: _address }) => addressOrPbk === _address)?.pubkey } @@ -847,7 +843,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { session = await this.onPairingClosed(signClient, trigger.topic) } - if (!this.activeAccount) { + if (!this.activeAccountOrPbk) { const fun = this.eventHandlers.get(ClientEvents.RESET_STATE) fun && fun(TransportType.WALLETCONNECT) } @@ -1039,7 +1035,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { // if I have successfully opened a session and I already have one opened if (session?.controller !== this.session?.controller) { logger.debug('Controller doesnt match, closing active session', [pairingTopic]) - this.activeAccount && this.closeActiveSession(this.activeAccount, false) + this.activeAccountOrPbk && this.closeActiveSession(this.activeAccountOrPbk, false) this.session = undefined // close the previous session } @@ -1269,7 +1265,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { private setDefaultAccountAndNetwork() { const activeAccount = this.getAccounts() if (activeAccount.length) { - this.activeAccount = activeAccount[0] + this.activeAccountOrPbk = activeAccount[0] } const activeNetwork = this.getNetworks() if (activeNetwork.length) { @@ -1376,16 +1372,16 @@ export class WalletConnectCommunicationClient extends CommunicationClient { * @error ActiveAccountUnspecified thrown when there are multiple Tezos account in the session and none is set as the active one */ async getPKH() { - if (!this.activeAccount) { + if (!this.activeAccountOrPbk) { this.getSession() throw new ActiveAccountUnspecified() } - return this.activeAccount + return this.activeAccountOrPbk } private clearState() { this.session = undefined - this.activeAccount = undefined + this.activeAccountOrPbk = undefined this.activeNetwork = undefined } } From 10944b177e0365915236d83bf852b99a83117cb3 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Thu, 6 Jun 2024 15:36:41 +0200 Subject: [PATCH 10/13] fix: validation --- .../WalletConnectCommunicationClient.ts | 14 ++++++++--- packages/beacon-utils/src/utils/crypto.ts | 25 ++++++++++--------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index fd0c443d7..1198575fb 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -351,7 +351,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { const accounts = this.getTezosNamespace(session.namespaces).accounts const addressOrPbk = accounts[0].split(':', 3)[2] - if (isPublicKey(addressOrPbk)) { + if (await isPublicKey(addressOrPbk)) { publicKey = addressOrPbk } else { if (network.type !== this.wcOptions.network) { @@ -445,7 +445,9 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.SIGN, params: { - account: isPublicKey(account) ? await getAddressFromPublicKey(account) : account, + account: (await isPublicKey(account)) + ? await getAddressFromPublicKey(account) + : account, payload: signPayloadRequest.payload } } @@ -511,7 +513,9 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.OPERATION_REQUEST, params: { - account: isPublicKey(account) ? await getAddressFromPublicKey(account) : account, + account: (await isPublicKey(account)) + ? await getAddressFromPublicKey(account) + : account, operations: operationRequest.operationDetails } } @@ -801,9 +805,11 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.activeNetwork = chainId this.activeAccountOrPbk = addressOrPbk - if (!isPublicKey(addressOrPbk)) { + if (!(await isPublicKey(addressOrPbk))) { const result = await this.fetchAccounts(session.topic, `${TEZOS_PLACEHOLDER}:${chainId}`) publicKey = result?.find(({ address: _address }) => addressOrPbk === _address)?.pubkey + } else { + publicKey = addressOrPbk } if (!publicKey) { diff --git a/packages/beacon-utils/src/utils/crypto.ts b/packages/beacon-utils/src/utils/crypto.ts index e57b51618..75fa9e9d7 100644 --- a/packages/beacon-utils/src/utils/crypto.ts +++ b/packages/beacon-utils/src/utils/crypto.ts @@ -297,18 +297,19 @@ export function encodePoeChallengePayload(payload: string) { ) } -export function isPublicKey(publicKey: string) { - const ed25519Regex = /^edpk[1-9A-HJ-NP-Za-km-z]{50}$/ - const secp256k1Regex = /^sppk[1-9A-HJ-NP-Za-km-z]{50}$/ - const p256Regex = /^p2pk[1-9A-HJ-NP-Za-km-z]{50}$/ - const bls12_381Regex = /^BLpk[1-9A-HJ-NP-Za-km-z]{50}$/ - - return ( - ed25519Regex.test(publicKey) || - secp256k1Regex.test(publicKey) || - p256Regex.test(publicKey) || - bls12_381Regex.test(publicKey) - ) +export async function isPublicKey(publicKey: string) { + if (!publicKey) { + return false + } + + try { + await getAddressFromPublicKey(publicKey) + } catch (err: any) { + console.error(err.message) + return false + } + + return true } /* eslint-enable prefer-arrow/prefer-arrow-functions */ From 367925e5778abcec56e5fbe6ff4cc4257d435347 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Thu, 6 Jun 2024 15:37:46 +0200 Subject: [PATCH 11/13] fix: remove log --- packages/beacon-utils/src/utils/crypto.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/beacon-utils/src/utils/crypto.ts b/packages/beacon-utils/src/utils/crypto.ts index 75fa9e9d7..30b877f9a 100644 --- a/packages/beacon-utils/src/utils/crypto.ts +++ b/packages/beacon-utils/src/utils/crypto.ts @@ -304,8 +304,7 @@ export async function isPublicKey(publicKey: string) { try { await getAddressFromPublicKey(publicKey) - } catch (err: any) { - console.error(err.message) + } catch { return false } From 7ec4cecc01d9d8bee38869dbe29cb3d7c03d672d Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Thu, 6 Jun 2024 16:17:37 +0200 Subject: [PATCH 12/13] fix: check --- .../WalletConnectCommunicationClient.ts | 14 +++++-------- packages/beacon-utils/src/index.ts | 2 +- packages/beacon-utils/src/utils/crypto.ts | 21 ++++++++++++------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 1198575fb..3fcffd3a0 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -46,7 +46,7 @@ import { StorageKey, TransportType } from '@airgap/beacon-types' -import { generateGUID, getAddressFromPublicKey, isPublicKey } from '@airgap/beacon-utils' +import { generateGUID, getAddressFromPublicKey, isPublicKeySC } from '@airgap/beacon-utils' const TEZOS_PLACEHOLDER = 'tezos' const BEACON_SDK_VERSION = 'beacon_sdk_version' @@ -351,7 +351,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { const accounts = this.getTezosNamespace(session.namespaces).accounts const addressOrPbk = accounts[0].split(':', 3)[2] - if (await isPublicKey(addressOrPbk)) { + if (isPublicKeySC(addressOrPbk)) { publicKey = addressOrPbk } else { if (network.type !== this.wcOptions.network) { @@ -445,9 +445,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.SIGN, params: { - account: (await isPublicKey(account)) - ? await getAddressFromPublicKey(account) - : account, + account: isPublicKeySC(account) ? await getAddressFromPublicKey(account) : account, payload: signPayloadRequest.payload } } @@ -513,9 +511,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { request: { method: PermissionScopeMethods.OPERATION_REQUEST, params: { - account: (await isPublicKey(account)) - ? await getAddressFromPublicKey(account) - : account, + account: isPublicKeySC(account) ? await getAddressFromPublicKey(account) : account, operations: operationRequest.operationDetails } } @@ -805,7 +801,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.activeNetwork = chainId this.activeAccountOrPbk = addressOrPbk - if (!(await isPublicKey(addressOrPbk))) { + if (!isPublicKeySC(addressOrPbk)) { const result = await this.fetchAccounts(session.topic, `${TEZOS_PLACEHOLDER}:${chainId}`) publicKey = result?.find(({ address: _address }) => addressOrPbk === _address)?.pubkey } else { diff --git a/packages/beacon-utils/src/index.ts b/packages/beacon-utils/src/index.ts index 3be8f7f97..9b036e429 100644 --- a/packages/beacon-utils/src/index.ts +++ b/packages/beacon-utils/src/index.ts @@ -14,7 +14,7 @@ export { isValidAddress, prefixPublicKey, encodePoeChallengePayload, - isPublicKey + isPublicKeySC } from './utils/crypto' export { generateGUID } from './utils/generate-uuid' diff --git a/packages/beacon-utils/src/utils/crypto.ts b/packages/beacon-utils/src/utils/crypto.ts index 30b877f9a..0778e774a 100644 --- a/packages/beacon-utils/src/utils/crypto.ts +++ b/packages/beacon-utils/src/utils/crypto.ts @@ -297,18 +297,23 @@ export function encodePoeChallengePayload(payload: string) { ) } -export async function isPublicKey(publicKey: string) { +/** + * Shallow Check (SC): Perform a superficial check to determine if the string contains a public key. + * Do not use this function to validate the key itself. + * @param publicKey the public key to analyze + * @returns true if it contains a known prefix, false otherwise + */ +export function isPublicKeySC(publicKey: string): boolean { if (!publicKey) { return false } - try { - await getAddressFromPublicKey(publicKey) - } catch { - return false - } - - return true + return ( + publicKey.startsWith('edpk') || + publicKey.startsWith('sppk') || + publicKey.startsWith('p2pk') || + publicKey.startsWith('BLpk') + ) } /* eslint-enable prefer-arrow/prefer-arrow-functions */ From 3d6426a5ed15c0c7a8ffa88ee766b1f8be2869b6 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Tue, 11 Jun 2024 11:52:05 +0200 Subject: [PATCH 13/13] Revert "chore: migrate kukai web to WC" This reverts commit e6678d3fbe82c6c9efe8c0dfbf590cb17a22eb48. --- packages/beacon-ui/src/ui/alert/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/beacon-ui/src/ui/alert/index.tsx b/packages/beacon-ui/src/ui/alert/index.tsx index c988f92e6..ba8936f99 100644 --- a/packages/beacon-ui/src/ui/alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/index.tsx @@ -489,7 +489,10 @@ const openAlert = async (config: AlertConfig): Promise => { let link = '' - if (wallet.supportedInteractionStandards?.includes('wallet_connect')) { + if ( + wallet.supportedInteractionStandards?.includes('wallet_connect') && + !wallet.name.toLowerCase().includes('kukai') + ) { const uri = await generateLink() if (!uri) { @@ -583,7 +586,10 @@ const openAlert = async (config: AlertConfig): Promise => { }) ) - if (wallet?.types.includes('web') && wallet?.types.length === 1) { + if ( + (wallet?.types.includes('web') && wallet?.types.length === 1) || + (isAndroid(window) && wallet?.name.toLowerCase().includes('kukai')) + ) { handleNewTab(config, wallet) return }