From e85722807a58ead3fcb8b06bf5bcf33cea393483 Mon Sep 17 00:00:00 2001 From: Louis Aussedat Date: Wed, 27 Nov 2024 14:39:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(webhid):=20Fix=20invalid=20chan?= =?UTF-8?q?nel=20error=20when=20using=20multiple=20apps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/fuzzy-cats-enjoy.md | 5 +++++ .../hw-transport-webhid/src/TransportWebHID.ts | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/fuzzy-cats-enjoy.md diff --git a/.changeset/fuzzy-cats-enjoy.md b/.changeset/fuzzy-cats-enjoy.md new file mode 100644 index 000000000000..dd72b4daa012 --- /dev/null +++ b/.changeset/fuzzy-cats-enjoy.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/hw-transport-webhid": patch +--- + +Fix invalid channel when using multiple apps diff --git a/libs/ledgerjs/packages/hw-transport-webhid/src/TransportWebHID.ts b/libs/ledgerjs/packages/hw-transport-webhid/src/TransportWebHID.ts index 0ddb4ebdea0d..85031dde2a71 100644 --- a/libs/ledgerjs/packages/hw-transport-webhid/src/TransportWebHID.ts +++ b/libs/ledgerjs/packages/hw-transport-webhid/src/TransportWebHID.ts @@ -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"));