Skip to content

Commit 4f01dfe

Browse files
🎨 (signer-btc): Reviews
1 parent 0663f38 commit 4f01dfe

File tree

6 files changed

+56
-13
lines changed

6 files changed

+56
-13
lines changed

apps/sample/src/components/SignerBtcView/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const SignerBtcView: React.FC<{ sessionId: string }> = ({
102102
},
103103
initialValues: {
104104
derivationPath: DEFAULT_DERIVATION_PATH,
105-
psbt: "70736274ff0104010101fb0402000000010204020000000105010100011004000000000103040100000001007102000000013daeeb9a92e7b5af90c787d53f0e60d2cf4cfd47bca9a0d8bc77a7464b024c0b00000000000000000002ff0300000000000016001402fe597c6ec0e2982712929bcf079a4e11d37e8d950b0000000000001600144dc432cb6a26c52a1e6ddd2bcf0ee49199fae0cc000000002206031869567d5e88d988ff7baf6827983f89530ddd79dbaeadaa6ec538a8f03dea8b18f5acc2fd540000800000008000000080000000000000000001011fff0300000000000016001402fe597c6ec0e2982712929bcf079a4e11d37e8d010e200cf08d04fa11ff024d5a50165ba65e495409b50ba6657788dfa15274adb682df010f0400000000000103086b01000000000000010416001429159115f12bb6a7e977439c83d3f8d555d72d5f00",
105+
psbt: "",
106106
},
107107
deviceModelId,
108108
} satisfies DeviceActionProps<

packages/signer/signer-btc/src/api/app-binder/SignPsbtDeviceActionTypes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type ExecuteDeviceActionReturnType,
55
type OpenAppDAError,
66
type OpenAppDARequiredInteraction,
7+
type UserInteractionRequired,
78
} from "@ledgerhq/device-management-kit";
89

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

25-
type SignPsbtDARequiredInteraction = OpenAppDARequiredInteraction;
26+
type SignPsbtDARequiredInteraction =
27+
| OpenAppDARequiredInteraction
28+
| UserInteractionRequired.SignTransaction;
2629

2730
export type SignPsbtDAIntermediateValue = {
2831
requiredUserInteraction: SignPsbtDARequiredInteraction;

packages/signer/signer-btc/src/internal/app-binder/command/GetWalletAddressCommand.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class GetWalletAddressCommand
4141
>
4242
{
4343
constructor(
44-
private readonly args: GetWalletAddressCommandArgs,
44+
private readonly _args: GetWalletAddressCommandArgs,
4545
private readonly _errorHelper = new CommandErrorHelper<
4646
GetWalletAddressCommandResponse,
4747
BtcErrorCodes
@@ -59,11 +59,11 @@ export class GetWalletAddressCommand
5959
p1: 0x00,
6060
p2: PROTOCOL_VERSION,
6161
})
62-
.addBufferToData(Uint8Array.from([this.args.display ? 1 : 0]))
63-
.addBufferToData(this.args.walletId)
64-
.addBufferToData(this.args.walletHmac)
65-
.addBufferToData(Uint8Array.from([this.args.change ? 1 : 0]))
66-
.add32BitUIntToData(this.args.addressIndex)
62+
.addBufferToData(Uint8Array.from([this._args.display ? 1 : 0]))
63+
.addBufferToData(this._args.walletId)
64+
.addBufferToData(this._args.walletHmac)
65+
.addBufferToData(Uint8Array.from([this._args.change ? 1 : 0]))
66+
.add32BitUIntToData(this._args.addressIndex)
6767
.build();
6868
}
6969

packages/signer/signer-btc/src/internal/app-binder/device-action/SignPsbt/SignPsbtDeviceAction.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("SignPsbtDeviceAction", () => {
7777
},
7878
{
7979
intermediateValue: {
80-
requiredUserInteraction: UserInteractionRequired.None,
80+
requiredUserInteraction: UserInteractionRequired.SignTransaction,
8181
},
8282
status: DeviceActionStatus.Pending,
8383
},
@@ -184,7 +184,7 @@ describe("SignPsbtDeviceAction", () => {
184184
{
185185
status: DeviceActionStatus.Pending,
186186
intermediateValue: {
187-
requiredUserInteraction: UserInteractionRequired.None,
187+
requiredUserInteraction: UserInteractionRequired.SignTransaction,
188188
},
189189
},
190190
{
@@ -235,7 +235,7 @@ describe("SignPsbtDeviceAction", () => {
235235
{
236236
status: DeviceActionStatus.Pending,
237237
intermediateValue: {
238-
requiredUserInteraction: UserInteractionRequired.None,
238+
requiredUserInteraction: UserInteractionRequired.SignTransaction,
239239
},
240240
},
241241
{
@@ -288,7 +288,7 @@ describe("SignPsbtDeviceAction", () => {
288288
{
289289
status: DeviceActionStatus.Pending,
290290
intermediateValue: {
291-
requiredUserInteraction: UserInteractionRequired.None,
291+
requiredUserInteraction: UserInteractionRequired.SignTransaction,
292292
},
293293
},
294294
{
@@ -341,7 +341,7 @@ describe("SignPsbtDeviceAction", () => {
341341
{
342342
status: DeviceActionStatus.Pending,
343343
intermediateValue: {
344-
requiredUserInteraction: UserInteractionRequired.None,
344+
requiredUserInteraction: UserInteractionRequired.SignTransaction,
345345
},
346346
},
347347
{

packages/signer/signer-btc/src/internal/app-binder/device-action/SignPsbt/SignPsbtDeviceAction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ export class SignPsbtDeviceAction extends XStateDeviceAction<
147147
],
148148
},
149149
SignPsbt: {
150+
entry: assign({
151+
intermediateValue: {
152+
requiredUserInteraction: UserInteractionRequired.SignTransaction,
153+
},
154+
}),
155+
exit: assign({
156+
intermediateValue: {
157+
requiredUserInteraction: UserInteractionRequired.None,
158+
},
159+
}),
150160
invoke: {
151161
id: "signPsbt",
152162
src: "signPsbt",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { DefaultDescriptorTemplate, DefaultWallet } from "@api/model/Wallet";
2+
import { type BtcAppBinder } from "@internal/app-binder/BtcAppBinder";
3+
4+
import { SignPsbtUseCase } from "./SignPsbtUseCase";
5+
6+
describe("SignPsbtUseCase", () => {
7+
it("should call signPsbt on appBinder with the correct arguments", () => {
8+
// Given
9+
const wallet = new DefaultWallet(
10+
"84'/0'/0'",
11+
DefaultDescriptorTemplate.NATIVE_SEGWIT,
12+
);
13+
const psbt = "some-psbt";
14+
const appBinder = {
15+
signPsbt: jest.fn(),
16+
};
17+
const signPsbtUseCase = new SignPsbtUseCase(
18+
appBinder as unknown as BtcAppBinder,
19+
);
20+
21+
// When
22+
signPsbtUseCase.execute(wallet, psbt);
23+
24+
// Then
25+
expect(appBinder.signPsbt).toHaveBeenCalledWith({
26+
wallet,
27+
psbt,
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)