Skip to content

Commit

Permalink
refactor: signPsbt, supportedMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Nov 12, 2024
1 parent 85af0e8 commit 746c10a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/background/messaging/rpc-methods/supported-methods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SupportedMethodsRequest } from '@shared/rpc/methods/supported-methods';
import type { SupportedMethodsRequest } from '@leather.io/rpc';

Check failure on line 1 in src/background/messaging/rpc-methods/supported-methods.ts

View workflow job for this annotation

GitHub Actions / typecheck

Module '"@leather.io/rpc"' has no exported member 'SupportedMethodsRequest'.

import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods';

import { makeSearchParamsWithDefaults } from '../messaging-utils';
Expand Down
21 changes: 8 additions & 13 deletions src/shared/rpc/methods/sign-psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { SigHash } from '@scure/btc-signer/transaction';
import * as yup from 'yup';

import { WalletDefaultNetworkConfigurationIds } from '@leather.io/models';
import {
SignatureHash as BtcKitSignatureHash,
DefineRpcMethod,
RpcRequest,
RpcResponse,
} from '@leather.io/rpc';
import { DefineRpcMethod, RpcRequest, RpcResponse, SignatureHash } from '@leather.io/rpc';

import {
accountSchema,
Expand All @@ -18,17 +13,17 @@ import {
} from './validation.utils';

// TODO: Revisit allowedSighash type if/when fixed in btc-signer
export type AllowedSighashTypes = BtcKitSignatureHash | SigHash;
export type AllowedSighashTypes = SignatureHash | SigHash;
// Pass all sighashTypes through as allowed to btc-signer
export const allSighashTypes = [
SigHash.DEFAULT,
BtcKitSignatureHash.ALL,
BtcKitSignatureHash.NONE,
BtcKitSignatureHash.SINGLE,
SignatureHash.ALL,
SignatureHash.NONE,
SignatureHash.SINGLE,
SigHash.ALL_ANYONECANPAY,
BtcKitSignatureHash.ALL_ANYONECANPAY,
BtcKitSignatureHash.NONE_ANYONECANPAY,
BtcKitSignatureHash.SINGLE_ANYONECANPAY,
SignatureHash.ALL_ANYONECANPAY,
SignatureHash.NONE_ANYONECANPAY,
SignatureHash.SINGLE_ANYONECANPAY,
];

const rpcSignPsbtParamsSchema = yup.object().shape({
Expand Down
10 changes: 0 additions & 10 deletions src/shared/rpc/methods/supported-methods.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/shared/rpc/rpc-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { SignStacksTransaction } from '@shared/rpc/methods/sign-stacks-transacti
import { Open } from './methods/open';
import { SignPsbt } from './methods/sign-psbt';
import { SignStacksMessage } from './methods/sign-stacks-message';
import { SupportedMethods } from './methods/supported-methods';

export type WalletMethodMap = LeatherRpcMethodMap &
Open &
SupportedMethods &
SignPsbt &
SignStacksTransaction &
SignStacksMessage;
Expand All @@ -24,7 +22,7 @@ export function makeRpcSuccessResponse<T extends WalletMethodNames>(
_method: T,
response: Omit<ExtractSuccessResponse<WalletMethodMap[T]['response']>, 'jsonrpc'>
): WalletMethodMap[T]['response'] {
// typecasting as there's a error stating jsonrpc prop is already there
// Typecasting as there's a error stating jsonrpc prop is already there
return { jsonrpc: '2.0', ...response } as WalletMethodMap[T]['response'];
}

Expand Down
12 changes: 3 additions & 9 deletions tests/specs/rpc-sign-psbt/sign-psbt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.describe('Sign PSBT', () => {
};

function initiatePsbtSigning(page: Page) {
return async (params: SignPsbtRequestParams & { broadcast?: boolean }) =>
return async (params: SignPsbtRequestParams) =>
page.evaluate(
async params =>
(window as any).LeatherProvider.request('signPsbt', {
Expand All @@ -79,10 +79,7 @@ test.describe('Sign PSBT', () => {

delete result.id;

test.expect(result).toEqual({
jsonrpc: '2.0',
result: { hex: signedAllPsbt },
});
test.expect(result).toEqual({ jsonrpc: '2.0', result: { hex: signedAllPsbt } });
});

test('that only requested inputs are signed', async ({ page, context }) => {
Expand All @@ -93,10 +90,7 @@ test.describe('Sign PSBT', () => {

delete result.id;

test.expect(result).toEqual({
jsonrpc: '2.0',
result: { hex: signedOnlyIndexZeroPsbt },
});
test.expect(result).toEqual({ jsonrpc: '2.0', result: { hex: signedOnlyIndexZeroPsbt } });
});

test('that the request can be signed and broadcast', async ({ page, context }) => {
Expand Down

0 comments on commit 746c10a

Please sign in to comment.