From 6841f849b38f4d07521a83250138bec30c60adb6 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Tue, 12 Nov 2024 14:02:07 -0300 Subject: [PATCH] refactor: remove btckit --- src/app/pages/rpc-get-addresses/use-get-addresses.ts | 2 +- .../rpc-sign-bip322-message/use-sign-bip322-message.ts | 2 +- src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx | 2 +- .../use-rpc-sign-stacks-message.ts | 3 ++- .../use-rpc-sign-stacks-transaction.ts | 4 +++- .../store/accounts/blockchain/bitcoin/bitcoin.hooks.ts | 2 +- src/background/messaging/rpc-message-handler.ts | 2 +- src/background/messaging/rpc-methods/get-addresses.ts | 2 +- src/background/messaging/rpc-methods/send-transfer.ts | 3 +-- src/background/messaging/rpc-methods/sign-message.ts | 4 +--- src/background/messaging/rpc-methods/sign-psbt.ts | 2 +- .../messaging/rpc-methods/sign-stacks-message.ts | 3 +-- .../messaging/rpc-methods/sign-stacks-transaction.ts | 2 +- src/inpage/inpage.ts | 5 +++-- src/shared/rpc/methods/open.ts | 2 +- src/shared/rpc/methods/send-transfer.ts | 8 ++++++-- src/shared/rpc/methods/sign-message.ts | 2 +- src/shared/rpc/methods/sign-stacks-message.ts | 7 +++---- src/shared/rpc/methods/sign-stacks-transaction.ts | 3 ++- src/shared/rpc/methods/supported-methods.ts | 2 +- src/shared/rpc/rpc-methods.ts | 6 ++---- test-app/src/components/debugger.tsx | 4 +--- tests/specs/rpc-sign-psbt/sign-psbt.spec.ts | 2 +- 23 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/app/pages/rpc-get-addresses/use-get-addresses.ts b/src/app/pages/rpc-get-addresses/use-get-addresses.ts index fdb511b599e..6a3b8e5b21c 100644 --- a/src/app/pages/rpc-get-addresses/use-get-addresses.ts +++ b/src/app/pages/rpc-get-addresses/use-get-addresses.ts @@ -1,7 +1,7 @@ -import { BtcAddress } from '@btckit/types'; import { bytesToHex } from '@stacks/common'; import { ecdsaPublicKeyToSchnorr } from '@leather.io/bitcoin'; +import { BtcAddress } from '@leather.io/rpc'; import { logger } from '@shared/logger'; import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; diff --git a/src/app/pages/rpc-sign-bip322-message/use-sign-bip322-message.ts b/src/app/pages/rpc-sign-bip322-message/use-sign-bip322-message.ts index bfe25130ce9..f0f87bc4403 100644 --- a/src/app/pages/rpc-sign-bip322-message/use-sign-bip322-message.ts +++ b/src/app/pages/rpc-sign-bip322-message/use-sign-bip322-message.ts @@ -1,10 +1,10 @@ import { useMemo, useState } from 'react'; -import { PaymentTypes, RpcErrorCode } from '@btckit/types'; import * as btc from '@scure/btc-signer'; import * as bitcoin from 'bitcoinjs-lib'; import { signBip322MessageSimple } from '@leather.io/bitcoin'; +import { PaymentTypes, RpcErrorCode } from '@leather.io/rpc'; import { logger } from '@shared/logger'; import { makeRpcErrorResponse, makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; diff --git a/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx b/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx index 5cce22117c7..f7bc20570f0 100644 --- a/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx +++ b/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx @@ -1,6 +1,5 @@ import { useNavigate } from 'react-router-dom'; -import { RpcErrorCode } from '@btckit/types'; import { hexToBytes } from '@noble/hashes/utils'; import { bytesToHex } from '@stacks/common'; @@ -10,6 +9,7 @@ import { useCalculateBitcoinFiatValue, useCryptoCurrencyMarketDataMeanAverage, } from '@leather.io/query'; +import { RpcErrorCode } from '@leather.io/rpc'; import { formatMoney, formatMoneyPadded, diff --git a/src/app/pages/rpc-sign-stacks-message/use-rpc-sign-stacks-message.ts b/src/app/pages/rpc-sign-stacks-message/use-rpc-sign-stacks-message.ts index 92bc3df3dbe..be517258c78 100644 --- a/src/app/pages/rpc-sign-stacks-message/use-rpc-sign-stacks-message.ts +++ b/src/app/pages/rpc-sign-stacks-message/use-rpc-sign-stacks-message.ts @@ -1,9 +1,10 @@ import { useMemo } from 'react'; -import { RpcErrorCode } from '@btckit/types'; import { StacksNetwork } from '@stacks/network'; import { deserializeCV } from '@stacks/transactions'; +import { RpcErrorCode } from '@leather.io/rpc'; + import { makeRpcErrorResponse, makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; import { isSignableMessageType, diff --git a/src/app/pages/rpc-sign-stacks-transaction/use-rpc-sign-stacks-transaction.ts b/src/app/pages/rpc-sign-stacks-transaction/use-rpc-sign-stacks-transaction.ts index 903cb634650..08053214884 100644 --- a/src/app/pages/rpc-sign-stacks-transaction/use-rpc-sign-stacks-transaction.ts +++ b/src/app/pages/rpc-sign-stacks-transaction/use-rpc-sign-stacks-transaction.ts @@ -1,9 +1,10 @@ import { useMemo } from 'react'; -import { RpcErrorCode } from '@btckit/types'; import { bytesToHex } from '@stacks/common'; import { MultiSigSpendingCondition, deserializeTransaction } from '@stacks/transactions'; +import { RpcErrorCode } from '@leather.io/rpc'; + import { makeRpcErrorResponse, makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; import { closeWindow } from '@shared/utils'; @@ -36,6 +37,7 @@ function useRpcSignStacksTransactionParams() { export function useRpcSignStacksTransaction() { const { origin, requestId, tabId, stacksTransaction, isMultisig, txSender } = useRpcSignStacksTransactionParams(); + const signStacksTx = useSignStacksTransaction(); const wasSignedByOtherOwners = isMultisig && diff --git a/src/app/store/accounts/blockchain/bitcoin/bitcoin.hooks.ts b/src/app/store/accounts/blockchain/bitcoin/bitcoin.hooks.ts index 753995d153e..4362f69374e 100644 --- a/src/app/store/accounts/blockchain/bitcoin/bitcoin.hooks.ts +++ b/src/app/store/accounts/blockchain/bitcoin/bitcoin.hooks.ts @@ -1,4 +1,3 @@ -import { PaymentTypes } from '@btckit/types'; import { bytesToHex } from '@noble/hashes/utils'; import * as btc from '@scure/btc-signer'; import { Psbt } from 'bitcoinjs-lib'; @@ -13,6 +12,7 @@ import { } from '@leather.io/bitcoin'; import { extractAddressIndexFromPath } from '@leather.io/crypto'; import { bitcoinNetworkToNetworkMode } from '@leather.io/models'; +import { PaymentTypes } from '@leather.io/rpc'; import { isNumber, isUndefined } from '@leather.io/utils'; import { diff --git a/src/background/messaging/rpc-message-handler.ts b/src/background/messaging/rpc-message-handler.ts index b6ad1407ad0..9898f8efcf3 100644 --- a/src/background/messaging/rpc-message-handler.ts +++ b/src/background/messaging/rpc-message-handler.ts @@ -1,4 +1,4 @@ -import { RpcErrorCode } from '@btckit/types'; +import { RpcErrorCode } from '@leather.io/rpc'; import { WalletRequests, makeRpcErrorResponse } from '@shared/rpc/rpc-methods'; diff --git a/src/background/messaging/rpc-methods/get-addresses.ts b/src/background/messaging/rpc-methods/get-addresses.ts index 0582ee9dce3..4085aa7d1d0 100644 --- a/src/background/messaging/rpc-methods/get-addresses.ts +++ b/src/background/messaging/rpc-methods/get-addresses.ts @@ -1,4 +1,4 @@ -import { GetAddressesRequest, RpcErrorCode } from '@btckit/types'; +import { GetAddressesRequest, RpcErrorCode } from '@leather.io/rpc'; import { RouteUrls } from '@shared/route-urls'; import { makeRpcErrorResponse } from '@shared/rpc/rpc-methods'; diff --git a/src/background/messaging/rpc-methods/send-transfer.ts b/src/background/messaging/rpc-methods/send-transfer.ts index 973cf733465..3662263a6f3 100644 --- a/src/background/messaging/rpc-methods/send-transfer.ts +++ b/src/background/messaging/rpc-methods/send-transfer.ts @@ -1,5 +1,4 @@ -import { RpcErrorCode, type RpcRequest, type SendTransferRequestParams } from '@btckit/types'; - +import { RpcErrorCode, type RpcRequest, type SendTransferRequestParams } from '@leather.io/rpc'; import { isUndefined } from '@leather.io/utils'; import { RouteUrls } from '@shared/route-urls'; diff --git a/src/background/messaging/rpc-methods/sign-message.ts b/src/background/messaging/rpc-methods/sign-message.ts index e795c7ab135..558f0a6839b 100644 --- a/src/background/messaging/rpc-methods/sign-message.ts +++ b/src/background/messaging/rpc-methods/sign-message.ts @@ -1,7 +1,5 @@ -import { PaymentTypes, RpcErrorCode } from '@btckit/types'; -import { SignMessageRequest } from '@btckit/types/dist/types/methods/sign-message'; - import { isSupportedMessageSigningPaymentType } from '@leather.io/bitcoin'; +import { PaymentTypes, RpcErrorCode, type SignMessageRequest } from '@leather.io/rpc'; import { isDefined, isUndefined } from '@leather.io/utils'; import { RouteUrls } from '@shared/route-urls'; diff --git a/src/background/messaging/rpc-methods/sign-psbt.ts b/src/background/messaging/rpc-methods/sign-psbt.ts index 51567ef8502..6378b3b288c 100644 --- a/src/background/messaging/rpc-methods/sign-psbt.ts +++ b/src/background/messaging/rpc-methods/sign-psbt.ts @@ -1,7 +1,7 @@ -import { RpcErrorCode } from '@btckit/types'; import * as btc from '@scure/btc-signer'; import { hexToBytes } from '@stacks/common'; +import { RpcErrorCode } from '@leather.io/rpc'; import { ensureArray, isDefined, isUndefined } from '@leather.io/utils'; import { RouteUrls } from '@shared/route-urls'; diff --git a/src/background/messaging/rpc-methods/sign-stacks-message.ts b/src/background/messaging/rpc-methods/sign-stacks-message.ts index d9eede1020c..a68d6a7b37a 100644 --- a/src/background/messaging/rpc-methods/sign-stacks-message.ts +++ b/src/background/messaging/rpc-methods/sign-stacks-message.ts @@ -1,5 +1,4 @@ -import { RpcErrorCode } from '@btckit/types'; - +import { RpcErrorCode } from '@leather.io/rpc'; import { isDefined, isUndefined } from '@leather.io/utils'; import { RouteUrls } from '@shared/route-urls'; diff --git a/src/background/messaging/rpc-methods/sign-stacks-transaction.ts b/src/background/messaging/rpc-methods/sign-stacks-transaction.ts index 11a2d9d2542..e80a4b50aca 100644 --- a/src/background/messaging/rpc-methods/sign-stacks-transaction.ts +++ b/src/background/messaging/rpc-methods/sign-stacks-transaction.ts @@ -1,4 +1,3 @@ -import { RpcErrorCode } from '@btckit/types'; import { bytesToHex } from '@stacks/common'; import { TransactionTypes } from '@stacks/connect'; import { @@ -17,6 +16,7 @@ import { } from '@stacks/transactions'; import { createUnsecuredToken } from 'jsontokens'; +import { RpcErrorCode } from '@leather.io/rpc'; import { isDefined, isUndefined } from '@leather.io/utils'; import { RouteUrls } from '@shared/route-urls'; diff --git a/src/inpage/inpage.ts b/src/inpage/inpage.ts index e72c9668a80..aac177d5b9a 100644 --- a/src/inpage/inpage.ts +++ b/src/inpage/inpage.ts @@ -1,6 +1,7 @@ -import { RpcRequest } from '@btckit/types'; import type { StacksProvider } from '@stacks/connect'; +import { RpcRequest } from '@leather.io/rpc'; + import { BRANCH, COMMIT_SHA } from '@shared/environment'; import { AuthenticationRequestEventDetails, @@ -337,6 +338,6 @@ try { } // Legacy product provider objects -if (typeof window.btc === 'undefined') { +if (typeof (window as any).btc === 'undefined') { (window as any).btc = warnAboutDeprecatedProvider(provider); } diff --git a/src/shared/rpc/methods/open.ts b/src/shared/rpc/methods/open.ts index 673aa2f091a..9cf757d1d06 100644 --- a/src/shared/rpc/methods/open.ts +++ b/src/shared/rpc/methods/open.ts @@ -1,4 +1,4 @@ -import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types'; +import { DefineRpcMethod, RpcRequest, RpcResponse } from '@leather.io/rpc'; export type OpenRequest = RpcRequest<'open'>; diff --git a/src/shared/rpc/methods/send-transfer.ts b/src/shared/rpc/methods/send-transfer.ts index d2c94ae429e..4835b4f203a 100644 --- a/src/shared/rpc/methods/send-transfer.ts +++ b/src/shared/rpc/methods/send-transfer.ts @@ -1,7 +1,11 @@ import type { SendTransferRequestParams } from '@btckit/types'; import { z } from 'zod'; -import { type BitcoinNetworkModes, type DefaultNetworkConfigurations } from '@leather.io/models'; +import { + type AllowAdditionalProperties, + type BitcoinNetworkModes, + type DefaultNetworkConfigurations, +} from '@leather.io/models'; import { uniqueArray } from '@leather.io/utils'; import { FormErrorMessages } from '@shared/error-messages'; @@ -94,7 +98,7 @@ interface TransferRecipientParam { amount: string; } -export interface RpcSendTransferParams { +export interface RpcSendTransferParams extends AllowAdditionalProperties { account?: number; recipients: TransferRecipientParam[]; network: string; diff --git a/src/shared/rpc/methods/sign-message.ts b/src/shared/rpc/methods/sign-message.ts index 22d83a90f82..925757f212a 100644 --- a/src/shared/rpc/methods/sign-message.ts +++ b/src/shared/rpc/methods/sign-message.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -import type { PaymentTypes } from '@leather.io/rpc'; +import { PaymentTypes } from '@leather.io/rpc'; import { defaultNetworkIdSchema } from '../rpc-schemas'; import { diff --git a/src/shared/rpc/methods/sign-stacks-message.ts b/src/shared/rpc/methods/sign-stacks-message.ts index 78a73dd3dd1..26b432f9c6d 100644 --- a/src/shared/rpc/methods/sign-stacks-message.ts +++ b/src/shared/rpc/methods/sign-stacks-message.ts @@ -1,17 +1,16 @@ -import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types'; import { StacksNetworks } from '@stacks/network'; import { z } from 'zod'; -import { formatValidationErrors, getRpcParamErrors, validateRpcParams } from './validation.utils'; +import { DefineRpcMethod, RpcRequest, RpcResponse, stxMessageSigningTypes } from '@leather.io/rpc'; -const SignedMessageTypeArray = ['utf8', 'structured'] as const; +import { formatValidationErrors, getRpcParamErrors, validateRpcParams } from './validation.utils'; // TODO: refactor to use .discriminatedUnion const rpcSignStacksMessageParamsSchema = z.object({ network: z.enum(StacksNetworks).optional(), message: z.string(), domain: z.string().optional(), - messageType: z.enum(SignedMessageTypeArray), + messageType: z.enum(stxMessageSigningTypes), }); export function validateRpcSignStacksMessageParams(obj: unknown) { diff --git a/src/shared/rpc/methods/sign-stacks-transaction.ts b/src/shared/rpc/methods/sign-stacks-transaction.ts index 8b01e65904a..22d19a51108 100644 --- a/src/shared/rpc/methods/sign-stacks-transaction.ts +++ b/src/shared/rpc/methods/sign-stacks-transaction.ts @@ -1,7 +1,8 @@ -import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types'; import { StacksNetworks } from '@stacks/network'; import { z } from 'zod'; +import { DefineRpcMethod, RpcRequest, RpcResponse } from '@leather.io/rpc'; + import { formatValidationErrors, getRpcParamErrors, validateRpcParams } from './validation.utils'; const rpcSignStacksTransactionParamsSchema = z.object({ diff --git a/src/shared/rpc/methods/supported-methods.ts b/src/shared/rpc/methods/supported-methods.ts index 7a1b112b005..f51d65df2de 100644 --- a/src/shared/rpc/methods/supported-methods.ts +++ b/src/shared/rpc/methods/supported-methods.ts @@ -1,4 +1,4 @@ -import { DefineRpcMethod, RpcRequest, RpcSuccessResponse } from '@btckit/types'; +import { DefineRpcMethod, RpcRequest, RpcSuccessResponse } from '@leather.io/rpc'; export type SupportedMethodsRequest = RpcRequest<'supportedMethods'>; diff --git a/src/shared/rpc/rpc-methods.ts b/src/shared/rpc/rpc-methods.ts index 30f3db9acdb..03f3e0fa1b9 100644 --- a/src/shared/rpc/rpc-methods.ts +++ b/src/shared/rpc/rpc-methods.ts @@ -1,6 +1,5 @@ -import { BtcKitMethodMap, ExtractErrorResponse, ExtractSuccessResponse } from '@btckit/types'; - import type { ValueOf } from '@leather.io/models'; +import { ExtractErrorResponse, ExtractSuccessResponse, LeatherRpcMethodMap } from '@leather.io/rpc'; import { SignStacksTransaction } from '@shared/rpc/methods/sign-stacks-transaction'; @@ -9,8 +8,7 @@ import { SignPsbt } from './methods/sign-psbt'; import { SignStacksMessage } from './methods/sign-stacks-message'; import { SupportedMethods } from './methods/supported-methods'; -// Supports BtcKit methods, as well as custom Leather methods -export type WalletMethodMap = BtcKitMethodMap & +export type WalletMethodMap = LeatherRpcMethodMap & Open & SupportedMethods & SignPsbt & diff --git a/test-app/src/components/debugger.tsx b/test-app/src/components/debugger.tsx index 54eae6b145a..31d72c23528 100644 --- a/test-app/src/components/debugger.tsx +++ b/test-app/src/components/debugger.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; -import '@btckit/types'; import { demoTokenContract } from '@common/contracts'; import { useSTXAddress } from '@common/use-stx-address'; import { @@ -448,8 +447,7 @@ export const Debugger = () => { mt={3} onClick={() => { console.log('requesting'); - window.btc - ?.request('getAddresses') + window.LeatherProvider?.request('getAddresses') .then(resp => { console.log({ sucesss: resp }); }) diff --git a/tests/specs/rpc-sign-psbt/sign-psbt.spec.ts b/tests/specs/rpc-sign-psbt/sign-psbt.spec.ts index 306ec601320..05d24efc1ff 100644 --- a/tests/specs/rpc-sign-psbt/sign-psbt.spec.ts +++ b/tests/specs/rpc-sign-psbt/sign-psbt.spec.ts @@ -1,7 +1,7 @@ -import { SignPsbtRequestParams } from '@btckit/types'; import { BrowserContext, Page } from '@playwright/test'; import { WalletDefaultNetworkConfigurationIds } from '@leather.io/models'; +import { SignPsbtRequestParams } from '@leather.io/rpc'; import { test } from '../../fixtures/fixtures';