Skip to content

Commit

Permalink
🎨 (signer-btc): Reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabbech-ledger committed Jan 10, 2025
1 parent 0663f38 commit 4f01dfe
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/sample/src/components/SignerBtcView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const SignerBtcView: React.FC<{ sessionId: string }> = ({
},
initialValues: {
derivationPath: DEFAULT_DERIVATION_PATH,
psbt: "70736274ff0104010101fb0402000000010204020000000105010100011004000000000103040100000001007102000000013daeeb9a92e7b5af90c787d53f0e60d2cf4cfd47bca9a0d8bc77a7464b024c0b00000000000000000002ff0300000000000016001402fe597c6ec0e2982712929bcf079a4e11d37e8d950b0000000000001600144dc432cb6a26c52a1e6ddd2bcf0ee49199fae0cc000000002206031869567d5e88d988ff7baf6827983f89530ddd79dbaeadaa6ec538a8f03dea8b18f5acc2fd540000800000008000000080000000000000000001011fff0300000000000016001402fe597c6ec0e2982712929bcf079a4e11d37e8d010e200cf08d04fa11ff024d5a50165ba65e495409b50ba6657788dfa15274adb682df010f0400000000000103086b01000000000000010416001429159115f12bb6a7e977439c83d3f8d555d72d5f00",
psbt: "",
},
deviceModelId,
} satisfies DeviceActionProps<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type ExecuteDeviceActionReturnType,
type OpenAppDAError,
type OpenAppDARequiredInteraction,
type UserInteractionRequired,
} from "@ledgerhq/device-management-kit";

import { type Psbt } from "@api/model/Psbt";
Expand All @@ -22,7 +23,9 @@ export type SignPsbtDAError =
| OpenAppDAError
| CommandErrorResult<BtcErrorCodes>["error"];

type SignPsbtDARequiredInteraction = OpenAppDARequiredInteraction;
type SignPsbtDARequiredInteraction =
| OpenAppDARequiredInteraction
| UserInteractionRequired.SignTransaction;

export type SignPsbtDAIntermediateValue = {
requiredUserInteraction: SignPsbtDARequiredInteraction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class GetWalletAddressCommand
>
{
constructor(
private readonly args: GetWalletAddressCommandArgs,
private readonly _args: GetWalletAddressCommandArgs,
private readonly _errorHelper = new CommandErrorHelper<
GetWalletAddressCommandResponse,
BtcErrorCodes
Expand All @@ -59,11 +59,11 @@ export class GetWalletAddressCommand
p1: 0x00,
p2: PROTOCOL_VERSION,
})
.addBufferToData(Uint8Array.from([this.args.display ? 1 : 0]))
.addBufferToData(this.args.walletId)
.addBufferToData(this.args.walletHmac)
.addBufferToData(Uint8Array.from([this.args.change ? 1 : 0]))
.add32BitUIntToData(this.args.addressIndex)
.addBufferToData(Uint8Array.from([this._args.display ? 1 : 0]))
.addBufferToData(this._args.walletId)
.addBufferToData(this._args.walletHmac)
.addBufferToData(Uint8Array.from([this._args.change ? 1 : 0]))
.add32BitUIntToData(this._args.addressIndex)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("SignPsbtDeviceAction", () => {
},
{
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.None,
requiredUserInteraction: UserInteractionRequired.SignTransaction,
},
status: DeviceActionStatus.Pending,
},
Expand Down Expand Up @@ -184,7 +184,7 @@ describe("SignPsbtDeviceAction", () => {
{
status: DeviceActionStatus.Pending,
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.None,
requiredUserInteraction: UserInteractionRequired.SignTransaction,
},
},
{
Expand Down Expand Up @@ -235,7 +235,7 @@ describe("SignPsbtDeviceAction", () => {
{
status: DeviceActionStatus.Pending,
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.None,
requiredUserInteraction: UserInteractionRequired.SignTransaction,
},
},
{
Expand Down Expand Up @@ -288,7 +288,7 @@ describe("SignPsbtDeviceAction", () => {
{
status: DeviceActionStatus.Pending,
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.None,
requiredUserInteraction: UserInteractionRequired.SignTransaction,
},
},
{
Expand Down Expand Up @@ -341,7 +341,7 @@ describe("SignPsbtDeviceAction", () => {
{
status: DeviceActionStatus.Pending,
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.None,
requiredUserInteraction: UserInteractionRequired.SignTransaction,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ export class SignPsbtDeviceAction extends XStateDeviceAction<
],
},
SignPsbt: {
entry: assign({
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.SignTransaction,
},
}),
exit: assign({
intermediateValue: {
requiredUserInteraction: UserInteractionRequired.None,
},
}),
invoke: {
id: "signPsbt",
src: "signPsbt",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DefaultDescriptorTemplate, DefaultWallet } from "@api/model/Wallet";
import { type BtcAppBinder } from "@internal/app-binder/BtcAppBinder";

import { SignPsbtUseCase } from "./SignPsbtUseCase";

describe("SignPsbtUseCase", () => {
it("should call signPsbt on appBinder with the correct arguments", () => {
// Given
const wallet = new DefaultWallet(
"84'/0'/0'",
DefaultDescriptorTemplate.NATIVE_SEGWIT,
);
const psbt = "some-psbt";
const appBinder = {
signPsbt: jest.fn(),
};
const signPsbtUseCase = new SignPsbtUseCase(
appBinder as unknown as BtcAppBinder,
);

// When
signPsbtUseCase.execute(wallet, psbt);

// Then
expect(appBinder.signPsbt).toHaveBeenCalledWith({
wallet,
psbt,
});
});
});

0 comments on commit 4f01dfe

Please sign in to comment.