mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-07 07:47:59 +01:00
fix(protocol): ignore unexpected chunks in ThpAck after send
This commit is contained in:
@@ -198,8 +198,6 @@ export const decodeSendAck = (decodedMessage: MessageV2) => {
|
||||
if (magic === THP_READ_ACK_HEADER_BYTE) {
|
||||
return decodeReadAck();
|
||||
}
|
||||
|
||||
throw new Error('Unexpected send response: ' + magic);
|
||||
};
|
||||
|
||||
// Decode protocol-v2 message from thp receive process
|
||||
|
||||
@@ -96,15 +96,14 @@ describe('protocol-thp', () => {
|
||||
});
|
||||
|
||||
it('decodeSendAck', () => {
|
||||
const thpError2 = decodeSendAck(decodeV2(Buffer.from('42122200050270303cfa', 'hex')));
|
||||
expect(thpError2.type).toBe('ThpError');
|
||||
const thpError = decodeSendAck(decodeV2(Buffer.from('42122200050270303cfa', 'hex')));
|
||||
expect(thpError?.type).toBe('ThpError');
|
||||
|
||||
const ack = decodeSendAck(decodeV2(Buffer.from('2812340004e98c8599', 'hex')));
|
||||
expect(ack.type).toBe('ThpAck');
|
||||
expect(ack?.type).toBe('ThpAck');
|
||||
|
||||
expect(() => decodeSendAck(decodeV2(Buffer.from('40ffff0004f9215951', 'hex')))).toThrow(
|
||||
'Unexpected send response',
|
||||
);
|
||||
const unexpected = decodeSendAck(decodeV2(Buffer.from('40ffff0004f9215951', 'hex')));
|
||||
expect(unexpected).toBe(undefined);
|
||||
|
||||
expect(() => decodeSendAck(decodeV2(Buffer.from('40ffff000499999999', 'hex')))).toThrow(
|
||||
'Invalid CRC',
|
||||
|
||||
@@ -94,7 +94,7 @@ export const sendThpMessage = async ({
|
||||
// parse and check the result
|
||||
const decodedResult = protocolThp.decodeSendAck(protocolV2.decode(result.payload));
|
||||
// fail on ThpError
|
||||
if (decodedResult.type === 'ThpError') {
|
||||
if (decodedResult?.type === 'ThpError') {
|
||||
const { code, message } = decodedResult.message;
|
||||
|
||||
return error({ error: code, message });
|
||||
|
||||
Reference in New Issue
Block a user