Skip to content

Commit

Permalink
🐛 (webhid): Fix invalid channel error when using multiple apps
Browse files Browse the repository at this point in the history
  • Loading branch information
aussedatlo committed Nov 27, 2024
1 parent 9507d3c commit e857228
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-cats-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/hw-transport-webhid": patch
---

Fix invalid channel when using multiple apps
15 changes: 13 additions & 2 deletions libs/ledgerjs/packages/hw-transport-webhid/src/TransportWebHID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,19 @@ export default class TransportWebHID extends Transport {
let acc;

while (!(result = framing.getReducedResult(acc))) {
const buffer = await this.read();
acc = framing.reduceResponse(acc, buffer);
try {
const buffer = await this.read();
acc = framing.reduceResponse(acc, buffer);
} catch (e) {
if (e instanceof TransportError && e.id === "InvalidChannel") {
// this can happen if the device is connected
// on a different channel (like another app)
// in this case we just filter out the event
continue;
}

throw e;
}
}

log("apdu", "<= " + result.toString("hex"));
Expand Down

0 comments on commit e857228

Please sign in to comment.