Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/hdwallet-keepkey/src/zcash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("zcashSignPczt", () => {
calls.push(mtype);

if (calls.length === 1) {
// eslint-disable-next-line jest/no-conditional-expect
expect(mtype).toBe(Messages.MessageType.MESSAGETYPE_ZCASHSIGNPCZT);
const ack = new ZcashMessages.ZcashPCZTActionAck();
ack.setNextIndex(0);
Expand All @@ -50,7 +51,11 @@ describe("zcashSignPczt", () => {

if (calls.length >= 2 && calls.length <= 4) {
const expectedInputIndex = calls.length - 2;
// The mock implements a protocol state-machine; per-step assertions
// here verify the host sent the right message at the right time.
// eslint-disable-next-line jest/no-conditional-expect
expect(mtype).toBe(Messages.MessageType.MESSAGETYPE_ZCASHTRANSPARENTINPUT);
// eslint-disable-next-line jest/no-conditional-expect
expect(msg.getIndex()).toBe(expectedInputIndex);

const sig = new ZcashMessages.ZcashTransparentSig();
Expand Down
16 changes: 12 additions & 4 deletions packages/hdwallet-keepkey/src/zcash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,21 @@ export async function zcashSignPczt(

for (let signedCount = 0; signedCount < nTransparentInputs; signedCount++) {
if (inputIndex === 0xff) {
throw new Error(`zcash: device finished transparent inputs after ${signedCount}, expected ${nTransparentInputs}`);
throw new Error(
`zcash: device finished transparent inputs after ${signedCount}, expected ${nTransparentInputs}`
);
}
if (inputIndex >= nTransparentInputs) {
throw new Error(`zcash: device requested transparent input ${inputIndex}, only ${nTransparentInputs} provided`);
throw new Error(
`zcash: device requested transparent input ${inputIndex}, only ${nTransparentInputs} provided`
);
}

const input = transparentInputs[inputIndex];
if (input.index !== inputIndex) {
throw new Error(`zcash: transparent input descriptor index mismatch: requested ${inputIndex}, got ${input.index}`);
throw new Error(
`zcash: transparent input descriptor index mismatch: requested ${inputIndex}, got ${input.index}`
);
}

const inputMsg = new ZcashMessages.ZcashTransparentInput();
Expand Down Expand Up @@ -228,7 +234,9 @@ export async function zcashSignPczt(
const nextIndex = sigResp.hasNextIndex() ? sigResp.getNextIndex() : signedCount + 1;
if (signedCount < nTransparentInputs - 1) {
if (nextIndex === 0xff) {
throw new Error(`zcash: device finished transparent inputs after ${signedCount + 1}, expected ${nTransparentInputs}`);
throw new Error(
`zcash: device finished transparent inputs after ${signedCount + 1}, expected ${nTransparentInputs}`
);
}
inputIndex = nextIndex ?? signedCount + 1;
} else if (nextIndex !== undefined && nextIndex !== 0xff) {
Expand Down
Loading