Skip to content

Commit

Permalink
refactor: remove btckit
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Nov 25, 2024
1 parent 6704ac5 commit 6841f84
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 37 deletions.
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
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 @@ -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);
}
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

0 comments on commit 6841f84

Please sign in to comment.