From 3fd71b7d29edc5fdf43dae952a211f54b5d2fd03 Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Fri, 16 Feb 2024 18:00:06 +0800 Subject: [PATCH 1/7] Add rpc-get-xpub method --- .../rpc-get-addresses/use-request-accounts.ts | 1 - .../components/get-xpub.layout.tsx | 54 +++++++++++++++ src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx | 22 +++++++ .../rpc-get-xpub/use-request-accounts.ts | 65 +++++++++++++++++++ src/app/routes/rpc-routes.tsx | 9 +++ .../messaging/rpc-message-handler.ts | 6 ++ .../messaging/rpc-methods/get-xpub.ts | 30 +++++++++ src/shared/route-urls.ts | 1 + src/shared/rpc/methods/get-xpub.ts | 8 +++ src/shared/rpc/rpc-methods.ts | 4 +- 10 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx create mode 100644 src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx create mode 100644 src/app/pages/rpc-get-xpub/use-request-accounts.ts create mode 100644 src/background/messaging/rpc-methods/get-xpub.ts create mode 100644 src/shared/rpc/methods/get-xpub.ts diff --git a/src/app/pages/rpc-get-addresses/use-request-accounts.ts b/src/app/pages/rpc-get-addresses/use-request-accounts.ts index f365d46b723..e25875eadf3 100644 --- a/src/app/pages/rpc-get-addresses/use-request-accounts.ts +++ b/src/app/pages/rpc-get-addresses/use-request-accounts.ts @@ -43,7 +43,6 @@ export function useGetAddresses() { publicKey: bytesToHex(nativeSegwitSigner.publicKey), derivationPath: nativeSegwitSigner.derivationPath, }; - keysToIncludeInResponse.push(nativeSegwitAddressResponse); } diff --git a/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx b/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx new file mode 100644 index 00000000000..aeeb6a798ed --- /dev/null +++ b/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx @@ -0,0 +1,54 @@ +import { Box, Flex, styled } from 'leather-styles/jsx'; + +import { RequesterFlag } from '@app/components/requester-flag'; +import { Button } from '@app/ui/components/button/button'; +import { LeatherIcon } from '@app/ui/components/icons/leather-icon'; +import { LeatherLIcon } from '@app/ui/components/icons/leather-l-icon'; + +interface GetXpubLayoutProps { + requester: string; + onUserApproveGetXpub(): void; +} +export function GetXpubLayout(props: GetXpubLayoutProps) { + const { requester, onUserApproveGetXpub } = props; + + return ( + + + + + + Connect your account to + + + + + + + + + By connecting you give permission to {requester} to view Xpub of this account + + + + ); +} diff --git a/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx b/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx new file mode 100644 index 00000000000..2399626d2fc --- /dev/null +++ b/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx @@ -0,0 +1,22 @@ +import { closeWindow } from '@shared/utils'; + +import { GetXpubLayout } from './components/get-xpub.layout'; +import { useGetXpub } from './use-request-accounts'; + +export function RpcGetXpub() { + const { origin, onUserApproveGetXpub } = useGetXpub(); + + if (origin === null) { + closeWindow(); + throw new Error('Origin is null'); + } + + const requester = new URL(origin).host; + + return ( + + ); +} diff --git a/src/app/pages/rpc-get-xpub/use-request-accounts.ts b/src/app/pages/rpc-get-xpub/use-request-accounts.ts new file mode 100644 index 00000000000..d729336c246 --- /dev/null +++ b/src/app/pages/rpc-get-xpub/use-request-accounts.ts @@ -0,0 +1,65 @@ +import {logger} from '@shared/logger'; +import {makeRpcSuccessResponse} from '@shared/rpc/rpc-methods'; +import {closeWindow} from '@shared/utils'; +import {useAnalytics} from '@app/common/hooks/analytics/use-analytics'; +import {useRpcRequestParams} from '@app/common/rpc-helpers'; +import {useCurrentAccountNativeSegwitSigner} from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; +import {useCurrentAccountTaprootSigner} from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks'; +import {useAppPermissions} from '@app/store/app-permissions/app-permissions.slice'; + + +export function useGetXpub() { + const analytics = useAnalytics(); + + const permissions = useAppPermissions(); + const {tabId, origin, requestId} = useRpcRequestParams(); + + const createNativeSegwitSigner = useCurrentAccountNativeSegwitSigner(); + const createTaprootSigner = useCurrentAccountTaprootSigner(); + + + return { + origin, + onUserApproveGetXpub() { + if (!tabId || !origin) { + logger.error('Cannot give app accounts: missing tabId, origin'); + return; + } + + const keysToIncludeInResponse = []; + + if (createNativeSegwitSigner) { + const nativeSegwitSigner = createNativeSegwitSigner(0); + + const nativeSegwitXpubResponse: any = { + symbol: 'BTC', + type: 'p2wpkh', + xpub: nativeSegwitSigner.keychain.publicExtendedKey, + }; + + keysToIncludeInResponse.push(nativeSegwitXpubResponse); + } + + if (createTaprootSigner) { + const taprootSigner = createTaprootSigner(0); + const taprootXpubResponse: any = { + symbol: 'BTC', + type: 'p2tr', + xpub: taprootSigner.keychain.publicExtendedKey, + }; + keysToIncludeInResponse.push(taprootXpubResponse); + } + + void analytics.track('user_approved_get_xpub', {origin}); + permissions.hasRequestedAccounts(origin); + chrome.tabs.sendMessage( + tabId, + makeRpcSuccessResponse('getXpub', { + id: requestId, + result: {xpubs: keysToIncludeInResponse as any}, + }) + ); + closeWindow(); + }, + }; +} diff --git a/src/app/routes/rpc-routes.tsx b/src/app/routes/rpc-routes.tsx index 8893db05c47..eb722e8bd2d 100644 --- a/src/app/routes/rpc-routes.tsx +++ b/src/app/routes/rpc-routes.tsx @@ -6,6 +6,7 @@ import { RouteUrls } from '@shared/route-urls'; import { ledgerBitcoinTxSigningRoutes } from '@app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container'; import { ledgerStacksMessageSigningRoutes } from '@app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg.routes'; import { RpcGetAddresses } from '@app/pages/rpc-get-addresses/rpc-get-addresses'; +import { RpcGetXpub } from '@app/pages/rpc-get-xpub/rpc-get-xpub'; import { rpcSendTransferRoutes } from '@app/pages/rpc-send-transfer/rpc-send-transfer.routes'; import { RpcSignPsbt } from '@app/pages/rpc-sign-psbt/rpc-sign-psbt'; import { RpcSignPsbtSummary } from '@app/pages/rpc-sign-psbt/rpc-sign-psbt-summary'; @@ -24,6 +25,14 @@ export const rpcRequestRoutes = ( } /> + + + + } + /> {rpcSendTransferRoutes} ; + +type GetXpubResponse = RpcResponse<{ xpubs: [] }>; + +export type GetXpub = DefineRpcMethod; diff --git a/src/shared/rpc/rpc-methods.ts b/src/shared/rpc/rpc-methods.ts index 74460b67f7a..cce936f5e79 100644 --- a/src/shared/rpc/rpc-methods.ts +++ b/src/shared/rpc/rpc-methods.ts @@ -7,6 +7,7 @@ import { AcceptBitcoinContract } from './methods/accept-bitcoin-contract'; import { SignPsbt } from './methods/sign-psbt'; import { SignStacksMessage } from './methods/sign-stacks-message'; import { SupportedMethods } from './methods/supported-methods'; +import {GetXpub} from "@shared/rpc/methods/get-xpub"; // Supports BtcKit methods, as well as custom Leather methods export type WalletMethodMap = BtcKitMethodMap & @@ -14,7 +15,8 @@ export type WalletMethodMap = BtcKitMethodMap & SignPsbt & AcceptBitcoinContract & SignStacksTransaction & - SignStacksMessage; + SignStacksMessage & + GetXpub; export type WalletRequests = ValueOf['request']; export type WalletResponses = ValueOf['response']; From 671e98c2231ba616c240a8740965051fbbaff9c3 Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Mon, 19 Feb 2024 16:17:01 +0800 Subject: [PATCH 2/7] Derive native segwit account from root --- .../rpc-get-xpub/use-request-accounts.ts | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/app/pages/rpc-get-xpub/use-request-accounts.ts b/src/app/pages/rpc-get-xpub/use-request-accounts.ts index d729336c246..d01f32be29a 100644 --- a/src/app/pages/rpc-get-xpub/use-request-accounts.ts +++ b/src/app/pages/rpc-get-xpub/use-request-accounts.ts @@ -3,9 +3,11 @@ import {makeRpcSuccessResponse} from '@shared/rpc/rpc-methods'; import {closeWindow} from '@shared/utils'; import {useAnalytics} from '@app/common/hooks/analytics/use-analytics'; import {useRpcRequestParams} from '@app/common/rpc-helpers'; -import {useCurrentAccountNativeSegwitSigner} from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; -import {useCurrentAccountTaprootSigner} from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks'; import {useAppPermissions} from '@app/store/app-permissions/app-permissions.slice'; +import {useCurrentAccountIndex} from "@app/store/accounts/account"; +import {useDefaultWalletSecretKey} from "@app/store/in-memory-key/in-memory-key.selectors"; +import {mnemonicToRootNode} from "@app/common/keychain/keychain"; +import {deriveNativeSegwitAccountFromRootKeychain} from "@shared/crypto/bitcoin/p2wpkh-address-gen"; export function useGetXpub() { @@ -14,9 +16,9 @@ export function useGetXpub() { const permissions = useAppPermissions(); const {tabId, origin, requestId} = useRpcRequestParams(); - const createNativeSegwitSigner = useCurrentAccountNativeSegwitSigner(); - const createTaprootSigner = useCurrentAccountTaprootSigner(); - + const currentAccountIndex = useCurrentAccountIndex(); + const secretKey = useDefaultWalletSecretKey(); + const rootKey = secretKey ? mnemonicToRootNode(secretKey) : null; return { origin, @@ -28,28 +30,19 @@ export function useGetXpub() { const keysToIncludeInResponse = []; - if (createNativeSegwitSigner) { - const nativeSegwitSigner = createNativeSegwitSigner(0); + if (rootKey) { + const createBitcoinAccount = deriveNativeSegwitAccountFromRootKeychain(rootKey, 'mainnet'); + const currentBitcoinAccount = createBitcoinAccount(currentAccountIndex); const nativeSegwitXpubResponse: any = { symbol: 'BTC', type: 'p2wpkh', - xpub: nativeSegwitSigner.keychain.publicExtendedKey, + xpub: currentBitcoinAccount.keychain.publicExtendedKey, }; keysToIncludeInResponse.push(nativeSegwitXpubResponse); } - if (createTaprootSigner) { - const taprootSigner = createTaprootSigner(0); - const taprootXpubResponse: any = { - symbol: 'BTC', - type: 'p2tr', - xpub: taprootSigner.keychain.publicExtendedKey, - }; - keysToIncludeInResponse.push(taprootXpubResponse); - } - void analytics.track('user_approved_get_xpub', {origin}); permissions.hasRequestedAccounts(origin); chrome.tabs.sendMessage( From 8ff3dd8c74a0326f7bd359f16ae65c74d7b56abc Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Mon, 19 Feb 2024 16:21:07 +0800 Subject: [PATCH 3/7] Omit unrelated commit --- src/app/pages/rpc-get-addresses/use-request-accounts.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/pages/rpc-get-addresses/use-request-accounts.ts b/src/app/pages/rpc-get-addresses/use-request-accounts.ts index e25875eadf3..fa00bd00b29 100644 --- a/src/app/pages/rpc-get-addresses/use-request-accounts.ts +++ b/src/app/pages/rpc-get-addresses/use-request-accounts.ts @@ -43,6 +43,7 @@ export function useGetAddresses() { publicKey: bytesToHex(nativeSegwitSigner.publicKey), derivationPath: nativeSegwitSigner.derivationPath, }; + keysToIncludeInResponse.push(nativeSegwitAddressResponse); } From 6b4d2c8bde5f4b185bf60c2354e78e320ccbea77 Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Mon, 19 Feb 2024 16:22:11 +0800 Subject: [PATCH 4/7] Omit unrelated commit --- src/app/pages/rpc-get-addresses/use-request-accounts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/rpc-get-addresses/use-request-accounts.ts b/src/app/pages/rpc-get-addresses/use-request-accounts.ts index fa00bd00b29..f365d46b723 100644 --- a/src/app/pages/rpc-get-addresses/use-request-accounts.ts +++ b/src/app/pages/rpc-get-addresses/use-request-accounts.ts @@ -43,7 +43,7 @@ export function useGetAddresses() { publicKey: bytesToHex(nativeSegwitSigner.publicKey), derivationPath: nativeSegwitSigner.derivationPath, }; - + keysToIncludeInResponse.push(nativeSegwitAddressResponse); } From e06ee175052f0c1cff4608060b19f6830a10c75d Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Mon, 8 Apr 2024 10:12:35 +0800 Subject: [PATCH 5/7] Add test --- tests/mocks/constants.ts | 3 ++ tests/specs/rpc-get-xpub/get-xpub.spec.ts | 47 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/specs/rpc-get-xpub/get-xpub.spec.ts diff --git a/tests/mocks/constants.ts b/tests/mocks/constants.ts index af9b99da5a2..a4706771504 100644 --- a/tests/mocks/constants.ts +++ b/tests/mocks/constants.ts @@ -11,6 +11,9 @@ export const TEST_ACCOUNT_1_STX_ADDRESS = 'SPS8CKF63P16J28AYF7PXW9E5AACH0NZNTEFW export const TEST_ACCOUNT_2_STX_ADDRESS = 'SPXH3HNBPM5YP15VH16ZXZ9AX6CK289K3MCXRKCB'; export const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS = 'STXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P'; +// Account extended public keys +export const TEST_ACCOUNT_1_XPUB = "xpub6BuKrNqTrGfsy8VAAdUW2KCxbHywuSKjg7hZuAXERXDv7GfuxUgUWdVRKNsgujcwdjEHCjaXWouPKi1m5gMgdWX8JpRcyMkrSxPe4Da3Lx8" + // Account public keys export const TEST_ACCOUNT_1_PUBKEY = '02b6b0afe5f620bc8e532b640b148dd9dea0ed19d11f8ab420fcce488fe3974893'; diff --git a/tests/specs/rpc-get-xpub/get-xpub.spec.ts b/tests/specs/rpc-get-xpub/get-xpub.spec.ts new file mode 100644 index 00000000000..a9102527bb7 --- /dev/null +++ b/tests/specs/rpc-get-xpub/get-xpub.spec.ts @@ -0,0 +1,47 @@ +import {BrowserContext, Page} from '@playwright/test'; +import {test} from '../../fixtures/fixtures'; +import {TEST_ACCOUNT_1_XPUB} from "@tests/mocks/constants"; + +test.describe('RPC get Xpub', () => { + test.beforeEach(async ({extensionId, globalPage, onboardingPage, page}) => { + await globalPage.setupAndUseApiCalls(extensionId); + await onboardingPage.signInWithTestAccount(extensionId); + await page.goto('localhost:3000', {waitUntil: 'networkidle'}); + }); + + function checkVisibleContent(context: BrowserContext) { + return async (buttonToPress: 'Cancel' | 'Confirm') => { + const popup = await context.waitForEvent('page'); + await popup.waitForTimeout(500); + const btn = popup.locator('text="Connect Leather"'); + + if (buttonToPress === 'Confirm') { + await btn.click(); + } else { + await popup.close(); + } + }; + } + + function initiateRPCGetXpub(page: Page) { + return async () => + page.evaluate( + async () => + (window as any).LeatherProvider.request('getXpub') + .catch((e: unknown) => e) + ); + } + + test('that xpub is correct', async ({ + page, + context, + }) => { + const xpub = TEST_ACCOUNT_1_XPUB; + const [result] = await Promise.all([ + initiateRPCGetXpub(page)(), + checkVisibleContent(context)('Confirm'), + ]); + + test.expect(result.result.xpubs[0].xpub).toEqual(xpub); + }); +}); From 2a4180032c29e943dcb0c4d50002e54e0a5cfebd Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Mon, 8 Apr 2024 10:26:48 +0800 Subject: [PATCH 6/7] Format code style --- src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx | 7 +---- .../rpc-get-xpub/use-request-accounts.ts | 30 +++++++++---------- .../messaging/rpc-message-handler.ts | 2 +- .../messaging/rpc-methods/get-xpub.ts | 2 +- src/shared/rpc/methods/get-xpub.ts | 1 - src/shared/rpc/rpc-methods.ts | 2 +- tests/mocks/constants.ts | 3 +- tests/specs/rpc-get-xpub/get-xpub.spec.ts | 22 ++++++-------- 8 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx b/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx index 2399626d2fc..6dc910fcabb 100644 --- a/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx +++ b/src/app/pages/rpc-get-xpub/rpc-get-xpub.tsx @@ -13,10 +13,5 @@ export function RpcGetXpub() { const requester = new URL(origin).host; - return ( - - ); + return ; } diff --git a/src/app/pages/rpc-get-xpub/use-request-accounts.ts b/src/app/pages/rpc-get-xpub/use-request-accounts.ts index d01f32be29a..dcd4f083fc4 100644 --- a/src/app/pages/rpc-get-xpub/use-request-accounts.ts +++ b/src/app/pages/rpc-get-xpub/use-request-accounts.ts @@ -1,20 +1,20 @@ -import {logger} from '@shared/logger'; -import {makeRpcSuccessResponse} from '@shared/rpc/rpc-methods'; -import {closeWindow} from '@shared/utils'; -import {useAnalytics} from '@app/common/hooks/analytics/use-analytics'; -import {useRpcRequestParams} from '@app/common/rpc-helpers'; -import {useAppPermissions} from '@app/store/app-permissions/app-permissions.slice'; -import {useCurrentAccountIndex} from "@app/store/accounts/account"; -import {useDefaultWalletSecretKey} from "@app/store/in-memory-key/in-memory-key.selectors"; -import {mnemonicToRootNode} from "@app/common/keychain/keychain"; -import {deriveNativeSegwitAccountFromRootKeychain} from "@shared/crypto/bitcoin/p2wpkh-address-gen"; - +import { deriveNativeSegwitAccountFromRootKeychain } from '@shared/crypto/bitcoin/p2wpkh-address-gen'; +import { logger } from '@shared/logger'; +import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; +import { closeWindow } from '@shared/utils'; + +import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; +import { mnemonicToRootNode } from '@app/common/keychain/keychain'; +import { useRpcRequestParams } from '@app/common/rpc-helpers'; +import { useCurrentAccountIndex } from '@app/store/accounts/account'; +import { useAppPermissions } from '@app/store/app-permissions/app-permissions.slice'; +import { useDefaultWalletSecretKey } from '@app/store/in-memory-key/in-memory-key.selectors'; export function useGetXpub() { const analytics = useAnalytics(); const permissions = useAppPermissions(); - const {tabId, origin, requestId} = useRpcRequestParams(); + const { tabId, origin, requestId } = useRpcRequestParams(); const currentAccountIndex = useCurrentAccountIndex(); const secretKey = useDefaultWalletSecretKey(); @@ -32,7 +32,7 @@ export function useGetXpub() { if (rootKey) { const createBitcoinAccount = deriveNativeSegwitAccountFromRootKeychain(rootKey, 'mainnet'); - const currentBitcoinAccount = createBitcoinAccount(currentAccountIndex); + const currentBitcoinAccount = createBitcoinAccount(currentAccountIndex); const nativeSegwitXpubResponse: any = { symbol: 'BTC', @@ -43,13 +43,13 @@ export function useGetXpub() { keysToIncludeInResponse.push(nativeSegwitXpubResponse); } - void analytics.track('user_approved_get_xpub', {origin}); + void analytics.track('user_approved_get_xpub', { origin }); permissions.hasRequestedAccounts(origin); chrome.tabs.sendMessage( tabId, makeRpcSuccessResponse('getXpub', { id: requestId, - result: {xpubs: keysToIncludeInResponse as any}, + result: { xpubs: keysToIncludeInResponse as any }, }) ); closeWindow(); diff --git a/src/background/messaging/rpc-message-handler.ts b/src/background/messaging/rpc-message-handler.ts index b70e92cc138..8a3c4c6fcc8 100644 --- a/src/background/messaging/rpc-message-handler.ts +++ b/src/background/messaging/rpc-message-handler.ts @@ -2,6 +2,7 @@ import { RpcErrorCode } from '@btckit/types'; import { WalletRequests, makeRpcErrorResponse } from '@shared/rpc/rpc-methods'; +import { rpcGetXpub } from '@background/messaging/rpc-methods/get-xpub'; import { rpcSignStacksTransaction } from '@background/messaging/rpc-methods/sign-stacks-transaction'; import { getTabIdFromPort } from './messaging-utils'; @@ -12,7 +13,6 @@ import { rpcSignMessage } from './rpc-methods/sign-message'; import { rpcSignPsbt } from './rpc-methods/sign-psbt'; import { rpcSignStacksMessage } from './rpc-methods/sign-stacks-message'; import { rpcSupportedMethods } from './rpc-methods/supported-methods'; -import {rpcGetXpub} from "@background/messaging/rpc-methods/get-xpub"; export async function rpcMessageHandler(message: WalletRequests, port: chrome.runtime.Port) { switch (message.method) { diff --git a/src/background/messaging/rpc-methods/get-xpub.ts b/src/background/messaging/rpc-methods/get-xpub.ts index 17a31dadaea..3e6a90602ad 100644 --- a/src/background/messaging/rpc-methods/get-xpub.ts +++ b/src/background/messaging/rpc-methods/get-xpub.ts @@ -1,6 +1,7 @@ import { RpcErrorCode } from '@btckit/types'; import { RouteUrls } from '@shared/route-urls'; +import { GetXpubRequest } from '@shared/rpc/methods/get-xpub'; import { makeRpcErrorResponse } from '@shared/rpc/rpc-methods'; import { @@ -8,7 +9,6 @@ import { makeSearchParamsWithDefaults, triggerRequestWindowOpen, } from '../messaging-utils'; -import {GetXpubRequest} from "@shared/rpc/methods/get-xpub"; export async function rpcGetXpub(message: GetXpubRequest, port: chrome.runtime.Port) { const { urlParams, tabId } = makeSearchParamsWithDefaults(port, [['requestId', message.id]]); diff --git a/src/shared/rpc/methods/get-xpub.ts b/src/shared/rpc/methods/get-xpub.ts index df8125e5f40..224e18a6bd6 100644 --- a/src/shared/rpc/methods/get-xpub.ts +++ b/src/shared/rpc/methods/get-xpub.ts @@ -1,6 +1,5 @@ import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types'; - export type GetXpubRequest = RpcRequest<'getXpub'>; type GetXpubResponse = RpcResponse<{ xpubs: [] }>; diff --git a/src/shared/rpc/rpc-methods.ts b/src/shared/rpc/rpc-methods.ts index cce936f5e79..282177d46d0 100644 --- a/src/shared/rpc/rpc-methods.ts +++ b/src/shared/rpc/rpc-methods.ts @@ -1,5 +1,6 @@ import { BtcKitMethodMap, ExtractErrorResponse, ExtractSuccessResponse } from '@btckit/types'; +import { GetXpub } from '@shared/rpc/methods/get-xpub'; import { SignStacksTransaction } from '@shared/rpc/methods/sign-stacks-transaction'; import { ValueOf } from '@shared/utils/type-utils'; @@ -7,7 +8,6 @@ import { AcceptBitcoinContract } from './methods/accept-bitcoin-contract'; import { SignPsbt } from './methods/sign-psbt'; import { SignStacksMessage } from './methods/sign-stacks-message'; import { SupportedMethods } from './methods/supported-methods'; -import {GetXpub} from "@shared/rpc/methods/get-xpub"; // Supports BtcKit methods, as well as custom Leather methods export type WalletMethodMap = BtcKitMethodMap & diff --git a/tests/mocks/constants.ts b/tests/mocks/constants.ts index a4706771504..8075a29b554 100644 --- a/tests/mocks/constants.ts +++ b/tests/mocks/constants.ts @@ -12,7 +12,8 @@ export const TEST_ACCOUNT_2_STX_ADDRESS = 'SPXH3HNBPM5YP15VH16ZXZ9AX6CK289K3MCXR export const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS = 'STXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P'; // Account extended public keys -export const TEST_ACCOUNT_1_XPUB = "xpub6BuKrNqTrGfsy8VAAdUW2KCxbHywuSKjg7hZuAXERXDv7GfuxUgUWdVRKNsgujcwdjEHCjaXWouPKi1m5gMgdWX8JpRcyMkrSxPe4Da3Lx8" +export const TEST_ACCOUNT_1_XPUB = + 'xpub6BuKrNqTrGfsy8VAAdUW2KCxbHywuSKjg7hZuAXERXDv7GfuxUgUWdVRKNsgujcwdjEHCjaXWouPKi1m5gMgdWX8JpRcyMkrSxPe4Da3Lx8'; // Account public keys export const TEST_ACCOUNT_1_PUBKEY = diff --git a/tests/specs/rpc-get-xpub/get-xpub.spec.ts b/tests/specs/rpc-get-xpub/get-xpub.spec.ts index a9102527bb7..1ee28b4141d 100644 --- a/tests/specs/rpc-get-xpub/get-xpub.spec.ts +++ b/tests/specs/rpc-get-xpub/get-xpub.spec.ts @@ -1,12 +1,13 @@ -import {BrowserContext, Page} from '@playwright/test'; -import {test} from '../../fixtures/fixtures'; -import {TEST_ACCOUNT_1_XPUB} from "@tests/mocks/constants"; +import { BrowserContext, Page } from '@playwright/test'; +import { TEST_ACCOUNT_1_XPUB } from '@tests/mocks/constants'; + +import { test } from '../../fixtures/fixtures'; test.describe('RPC get Xpub', () => { - test.beforeEach(async ({extensionId, globalPage, onboardingPage, page}) => { + test.beforeEach(async ({ extensionId, globalPage, onboardingPage, page }) => { await globalPage.setupAndUseApiCalls(extensionId); await onboardingPage.signInWithTestAccount(extensionId); - await page.goto('localhost:3000', {waitUntil: 'networkidle'}); + await page.goto('localhost:3000', { waitUntil: 'networkidle' }); }); function checkVisibleContent(context: BrowserContext) { @@ -25,17 +26,12 @@ test.describe('RPC get Xpub', () => { function initiateRPCGetXpub(page: Page) { return async () => - page.evaluate( - async () => - (window as any).LeatherProvider.request('getXpub') - .catch((e: unknown) => e) + page.evaluate(async () => + (window as any).LeatherProvider.request('getXpub').catch((e: unknown) => e) ); } - test('that xpub is correct', async ({ - page, - context, - }) => { + test('that xpub is correct', async ({ page, context }) => { const xpub = TEST_ACCOUNT_1_XPUB; const [result] = await Promise.all([ initiateRPCGetXpub(page)(), From 54aebad387608509dfa6c884b13e72e269be0e01 Mon Sep 17 00:00:00 2001 From: Vin Lim Date: Mon, 15 Apr 2024 10:53:40 +0800 Subject: [PATCH 7/7] Fix incorrect component imported --- src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx b/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx index aeeb6a798ed..b2329960aa7 100644 --- a/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx +++ b/src/app/pages/rpc-get-xpub/components/get-xpub.layout.tsx @@ -2,8 +2,8 @@ import { Box, Flex, styled } from 'leather-styles/jsx'; import { RequesterFlag } from '@app/components/requester-flag'; import { Button } from '@app/ui/components/button/button'; -import { LeatherIcon } from '@app/ui/components/icons/leather-icon'; -import { LeatherLIcon } from '@app/ui/components/icons/leather-l-icon'; +import { LettermarkIcon } from '@app/ui/icons'; +import { LogomarkIcon } from '@app/ui/icons/logomark-icon'; interface GetXpubLayoutProps { requester: string; @@ -23,7 +23,7 @@ export function GetXpubLayout(props: GetXpubLayoutProps) { gap="space.06" > - + Connect your account to @@ -31,7 +31,7 @@ export function GetXpubLayout(props: GetXpubLayoutProps) {