Skip to content

Commit 34c7368

Browse files
committed
♻️ (signer-zcash): Address PR review comments
1 parent 5f63ab1 commit 34c7368

18 files changed

Lines changed: 105 additions & 58 deletions

packages/signer/signer-zcash/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"dependencies": {
4141
"@ledgerhq/signer-utils": "workspace:^",
42+
"@noble/hashes": "^1.8.0",
4243
"inversify": "catalog:",
4344
"purify-ts": "catalog:",
4445
"reflect-metadata": "catalog:",

packages/signer/signer-zcash/src/api/model/CreateTransactionArg.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export type LegacyTransaction = {
1515
inputs: LegacyTransactionInput[];
1616
outputs?: LegacyTransactionOutput[];
1717
locktime?: Uint8Array;
18-
//witness?: Uint8Array;
1918
timestamp?: Uint8Array;
2019
nVersionGroupId?: Uint8Array;
2120
nExpiryHeight?: Uint8Array;

packages/signer/signer-zcash/src/internal/app-binder/ZcashAppBinder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type ExecuteDeviceActionTaskCallArgs = {
5252
deviceAction: CallTaskInAppDeviceAction<
5353
unknown,
5454
DmkError,
55-
UserInteractionRequired.None | UserInteractionRequired.None
55+
UserInteractionRequired.None | UserInteractionRequired.SignTransaction
5656
>;
5757
};
5858

packages/signer/signer-zcash/src/internal/app-binder/command/GetTrustedInputCommand.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("GetTrustedInputCommand", () => {
3333
expect(apdu.getRawApdu()).toEqual(
3434
new Uint8Array([
3535
0xe0, // CLA
36-
0x42, // INS.GET_TRUSTED_INPUT
36+
0x42, // GET_TRUSTED_INPUT
3737
0x80, // P1.NEXT
3838
0x00, // P2.DEFAULT
3939
0x03, // data length

packages/signer/signer-zcash/src/internal/app-binder/command/GetTrustedInputCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type GetTrustedInputCommandResponse = ApduResponse;
3333
* The length of the prefix for the index lookup in bytes.
3434
*/
3535
export const INDEX_LOOKUP_PREFIX_LENGTH = 4;
36-
const GET_TRUSTED_INPUT_INS = 0x42;
36+
const GET_TRUSTED_INPUT = 0x42;
3737

3838
export class GetTrustedInputCommand
3939
implements
@@ -77,7 +77,7 @@ export class GetTrustedInputCommand
7777

7878
const getTrustedInputCommandArgs: ApduBuilderArgs = {
7979
cla: ZCASH_CLA,
80-
ins: GET_TRUSTED_INPUT_INS,
80+
ins: GET_TRUSTED_INPUT,
8181
p1: firstRound ? P1.FIRST : P1.NEXT,
8282
p2: P2.DEFAULT,
8383
};

packages/signer/signer-zcash/src/internal/app-binder/command/HashOutputFullCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { CommandErrorHelper } from "@ledgerhq/signer-utils";
1111
import { Maybe } from "purify-ts";
1212

1313
import {
14-
INS,
1514
P1,
1615
P2,
1716
ZCASH_CLA,
@@ -23,6 +22,8 @@ import {
2322
type ZcashErrorCodes,
2423
} from "./utils/zcashApplicationErrors";
2524

25+
const FINALIZE_INPUT = 0x4a;
26+
2627
export type HashOutputFullCommandArgs = {
2728
outputChunk: Uint8Array;
2829
isLastChunk: boolean;
@@ -50,7 +51,7 @@ export class HashOutputFullCommand
5051
getApdu(): Apdu {
5152
const apduArgs: ApduBuilderArgs = {
5253
cla: ZCASH_CLA,
53-
ins: INS.FINALIZE_INPUT,
54+
ins: FINALIZE_INPUT,
5455
p1: this.args.isLastChunk ? P1.NEXT : P1.FIRST,
5556
p2: P2.DEFAULT,
5657
};

packages/signer/signer-zcash/src/internal/app-binder/command/ProvideOutputFullChangePathCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { Maybe } from "purify-ts";
1515

1616
import {
17-
INS,
1817
P1,
1918
P2,
2019
ZCASH_CLA,
@@ -26,6 +25,8 @@ import {
2625
type ZcashErrorCodes,
2726
} from "./utils/zcashApplicationErrors";
2827

28+
const FINALIZE_INPUT = 0x4a;
29+
2930
export type ProvideOutputFullChangePathCommandArgs = {
3031
derivationPath: string;
3132
};
@@ -52,7 +53,7 @@ export class ProvideOutputFullChangePathCommand
5253
getApdu(): Apdu {
5354
const apduArgs: ApduBuilderArgs = {
5455
cla: ZCASH_CLA,
55-
ins: INS.FINALIZE_INPUT,
56+
ins: FINALIZE_INPUT,
5657
p1: P1.CHANGE_PATH,
5758
p2: P2.DEFAULT,
5859
};

packages/signer/signer-zcash/src/internal/app-binder/command/SignTransactionCommand.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ describe("SignTransactionCommand", () => {
1212
derivationPath: "44'/133'/0'/0/0",
1313
lockTime: 1,
1414
sigHashType: 0x01,
15-
expiryHeight: new Uint8Array([0x01, 0x02, 0x03, 0x04]),
16-
additionals: ["zcash"],
15+
expiryHeight: Buffer.from([0x01, 0x02, 0x03, 0x04]),
1716
});
1817

1918
const apdu = command.getApdu().getRawApdu();
@@ -27,6 +26,7 @@ describe("SignTransactionCommand", () => {
2726
derivationPath: "44'/133'/0'/0/0",
2827
lockTime: 0,
2928
sigHashType: 0x01,
29+
expiryHeight: Buffer.alloc(4, 0),
3030
});
3131
const response = command.parseResponse(
3232
new ApduResponse({
@@ -44,11 +44,12 @@ describe("SignTransactionCommand", () => {
4444
);
4545
});
4646

47-
it("appends 4-byte zero expiry when expiryHeight omitted (no additionals required)", () => {
47+
it("appends 4-byte expiry height from task-normalized buffer", () => {
4848
const command = new SignTransactionCommand({
4949
derivationPath: "44'/133'/0'/1/2",
5050
lockTime: 0,
5151
sigHashType: 0x01,
52+
expiryHeight: Buffer.alloc(4, 0),
5253
});
5354

5455
expect(Buffer.from(command.getApdu().getRawApdu()).toString("hex")).toBe(
@@ -61,6 +62,7 @@ describe("SignTransactionCommand", () => {
6162
derivationPath: "44'/133'/0'/0/0",
6263
lockTime: 0,
6364
sigHashType: 0x01,
65+
expiryHeight: Buffer.alloc(4, 0),
6466
});
6567
const result = command.parseResponse(
6668
new ApduResponse({

packages/signer/signer-zcash/src/internal/app-binder/command/SignTransactionCommand.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export type SignTransactionCommandArgs = {
2828
derivationPath: string;
2929
lockTime: number;
3030
sigHashType: number;
31-
expiryHeight?: Uint8Array;
32-
additionals?: string[];
31+
expiryHeight: Buffer;
3332
};
3433

3534
export type SignTransactionCommandResponse = {
@@ -59,11 +58,6 @@ export class SignTransactionCommand
5958
const lockTimeBuffer = Buffer.alloc(4);
6059
lockTimeBuffer.writeUInt32BE(lockTime, 0);
6160

62-
const expiryBytes =
63-
expiryHeight !== undefined && expiryHeight.byteLength > 0
64-
? Buffer.from(expiryHeight)
65-
: null;
66-
6761
const apduArgs: ApduBuilderArgs = {
6862
cla: ZCASH_CLA,
6963
ins: 0x48,
@@ -81,13 +75,7 @@ export class SignTransactionCommand
8175
.addBufferToData(lockTimeBuffer)
8276
.add8BitUIntToData(sigHashType);
8377

84-
if (expiryBytes) {
85-
builder.addBufferToData(expiryBytes);
86-
} else {
87-
// Zcash app SIGN (`0x48`) always expects 4-byte expiry height after sighash type;
88-
// use zero when omitted (6700 WrongLength if callers omit `additionals` / expiry).
89-
builder.addBufferToData(Buffer.alloc(4, 0));
90-
}
78+
builder.addBufferToData(expiryHeight);
9179
return builder.build();
9280
}
9381

packages/signer/signer-zcash/src/internal/app-binder/command/StartUntrustedHashTransactionInputCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { CommandErrorHelper } from "@ledgerhq/signer-utils";
1111
import { Maybe } from "purify-ts";
1212

1313
import {
14-
INS,
1514
P1,
1615
P2,
1716
ZCASH_CLA,
@@ -23,6 +22,8 @@ import {
2322
type ZcashErrorCodes,
2423
} from "./utils/zcashApplicationErrors";
2524

25+
const START_UNTRUSTED_HASH_TRANSACTION_INPUT = 0x44;
26+
2627
export type StartUntrustedHashTransactionInputCommandArgs = {
2728
newTransaction: boolean;
2829
firstRound: boolean;
@@ -53,7 +54,7 @@ export class StartUntrustedHashTransactionInputCommand
5354
getApdu(): Apdu {
5455
const apduArgs: ApduBuilderArgs = {
5556
cla: ZCASH_CLA,
56-
ins: INS.START_UNTRUSTED_HASH_TRANSACTION_INPUT,
57+
ins: START_UNTRUSTED_HASH_TRANSACTION_INPUT,
5758
p1: this.args.firstRound ? P1.FIRST : P1.NEXT,
5859
p2: this.args.newTransaction ? P2.SAPLING : P2.HASH_INPUT_CONTINUE,
5960
};

0 commit comments

Comments
 (0)