Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/remove btc kit references #5963

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/pages/rpc-get-addresses/use-get-addresses.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -10,6 +9,7 @@ import {
useCalculateBitcoinFiatValue,
useCryptoCurrencyMarketDataMeanAverage,
} from '@leather.io/query';
import { RpcErrorCode } from '@leather.io/rpc';
import {
formatMoney,
formatMoneyPadded,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -36,6 +37,7 @@ function useRpcSignStacksTransactionParams() {
export function useRpcSignStacksTransaction() {
const { origin, requestId, tabId, stacksTransaction, isMultisig, txSender } =
useRpcSignStacksTransactionParams();

const signStacksTx = useSignStacksTransaction();
const wasSignedByOtherOwners =
isMultisig &&
Expand Down
2 changes: 1 addition & 1 deletion src/app/store/accounts/blockchain/bitcoin/bitcoin.hooks.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/background/messaging/rpc-message-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RpcErrorCode } from '@btckit/types';
import { RpcErrorCode } from '@leather.io/rpc';

import { WalletRequests, makeRpcErrorResponse } from '@shared/rpc/rpc-methods';

Expand Down
2 changes: 1 addition & 1 deletion src/background/messaging/rpc-methods/get-addresses.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 1 addition & 2 deletions src/background/messaging/rpc-methods/send-transfer.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,7 +41,7 @@

// Legacy params support for backward compatibility
const params = validateRpcSendTransferLegacyParams(message.params)
? convertRpcSendTransferLegacyParamsToNew(message.params as RpcSendTransferParamsLegacy)

Check failure on line 44 in src/background/messaging/rpc-methods/send-transfer.ts

View workflow job for this annotation

GitHub Actions / typecheck

Conversion of type 'SendTransferRequestParams | RpcSendTransferParams' to type 'RpcSendTransferParamsLegacy' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
: (message.params as RpcSendTransferParams);

if (!validateRpcSendTransferParams(params)) {
Expand Down
4 changes: 1 addition & 3 deletions src/background/messaging/rpc-methods/sign-message.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/background/messaging/rpc-methods/sign-psbt.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 1 addition & 2 deletions src/background/messaging/rpc-methods/sign-stacks-message.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RpcErrorCode } from '@btckit/types';
import { bytesToHex } from '@stacks/common';
import { TransactionTypes } from '@stacks/connect';
import {
Expand All @@ -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';
Expand Down
5 changes: 3 additions & 2 deletions src/inpage/inpage.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -247,7 +248,7 @@
params?: Record<string, any>
): Promise<WalletMethodMap[T]['response']> {
const id = crypto.randomUUID();
const rpcRequest: RpcRequest<T> = {

Check failure on line 251 in src/inpage/inpage.ts

View workflow job for this annotation

GitHub Actions / typecheck

Type '{ jsonrpc: string; id: `${string}-${string}-${string}-${string}-${string}`; method: T; params: Record<string, any> | undefined; }' is not assignable to type 'RpcRequest<T>'.
jsonrpc: '2.0',
id,
method,
Expand Down Expand Up @@ -337,6 +338,6 @@
}

// Legacy product provider objects
if (typeof window.btc === 'undefined') {
if (typeof (window as any).btc === 'undefined') {
(window as any).btc = warnAboutDeprecatedProvider(provider);
}
2 changes: 1 addition & 1 deletion src/shared/rpc/methods/open.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types';
import { DefineRpcMethod, RpcRequest, RpcResponse } from '@leather.io/rpc';

export type OpenRequest = RpcRequest<'open'>;

Expand Down
8 changes: 6 additions & 2 deletions src/shared/rpc/methods/send-transfer.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -94,7 +98,7 @@ interface TransferRecipientParam {
amount: string;
}

export interface RpcSendTransferParams {
export interface RpcSendTransferParams extends AllowAdditionalProperties {
account?: number;
recipients: TransferRecipientParam[];
network: string;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/rpc/methods/sign-message.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/shared/rpc/methods/sign-stacks-message.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/rpc/methods/sign-stacks-transaction.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/shared/rpc/methods/supported-methods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefineRpcMethod, RpcRequest, RpcSuccessResponse } from '@btckit/types';
import { DefineRpcMethod, RpcRequest, RpcSuccessResponse } from '@leather.io/rpc';

export type SupportedMethodsRequest = RpcRequest<'supportedMethods'>;

Expand Down
6 changes: 2 additions & 4 deletions src/shared/rpc/rpc-methods.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 &
Expand Down
4 changes: 1 addition & 3 deletions test-app/src/components/debugger.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 });
})
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/rpc-sign-psbt/sign-psbt.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -73,7 +73,7 @@
context,
}) => {
const [result] = await Promise.all([
initiatePsbtSigning(page)(signAllParams),

Check failure on line 76 in tests/specs/rpc-sign-psbt/sign-psbt.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ hex: string; network: WalletDefaultNetworkConfigurationIds; }' is not assignable to parameter of type 'SignPsbtRequestParams & { broadcast?: boolean | undefined; }'.
clickActionButton(context)('Confirm'),
]);

Expand All @@ -87,7 +87,7 @@

test('that only requested inputs are signed', async ({ page, context }) => {
const [result] = await Promise.all([
initiatePsbtSigning(page)({ ...signAllParams, signAtIndex: 0 }),

Check failure on line 90 in tests/specs/rpc-sign-psbt/sign-psbt.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ signAtIndex: number; hex: string; network: WalletDefaultNetworkConfigurationIds; }' is not assignable to parameter of type 'SignPsbtRequestParams & { broadcast?: boolean | undefined; }'.
clickActionButton(context)('Confirm'),
]);

Expand Down Expand Up @@ -121,7 +121,7 @@

test('that the request to sign can be canceled', async ({ page, context }) => {
const [result] = await Promise.all([
initiatePsbtSigning(page)(signAllParams),

Check failure on line 124 in tests/specs/rpc-sign-psbt/sign-psbt.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ hex: string; network: WalletDefaultNetworkConfigurationIds; }' is not assignable to parameter of type 'SignPsbtRequestParams & { broadcast?: boolean | undefined; }'.
clickActionButton(context)('Cancel'),
]);

Expand All @@ -141,7 +141,7 @@
context,
}) => {
const [result] = await Promise.all([
initiatePsbtSigning(page)({ ...signAllParams, signAtIndex: 4 }),

Check failure on line 144 in tests/specs/rpc-sign-psbt/sign-psbt.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ signAtIndex: number; hex: string; network: WalletDefaultNetworkConfigurationIds; }' is not assignable to parameter of type 'SignPsbtRequestParams & { broadcast?: boolean | undefined; }'.
clickActionButton(context)('Confirm'),
clickErrorCloseWindowButton(context),
]);
Expand Down
Loading