feat(connect): add tryToUnlock to ThpHandshakeInitRequest

This commit is contained in:
Marek Polak
2025-10-03 11:18:29 +02:00
committed by Marek Polák
parent bdd7b7bb61
commit a8aff3e3f8
3 changed files with 8 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ export const thpHandshake = async (device: Device) => {
// 2. Send the message HandshakeInitiationReq(host_ephemeral_pubkey) to the host.
const handshakeInit = await thpCall(device, 'ThpHandshakeInitRequest', {
key: hostEphemeralKeys.publicKey,
tryToUnlock: 0,
});
const { trezorEncryptedStaticPubkey } = handshakeInit.message;

View File

@@ -38,6 +38,9 @@ const getBytesFromField = (data: Record<string, unknown>, fieldName: string) =>
if (typeof value === 'string') {
return Buffer.from(value, 'hex');
}
if (typeof value === 'number') {
return Buffer.from([value]);
}
if (Buffer.isBuffer(value)) {
return value;
}
@@ -58,7 +61,9 @@ const handshakeInitRequestPayload = (data: Record<string, unknown>, _thpState: T
throw new Error('ThpHandshakeInitRequest missing key field');
}
return key;
const tryToUnlock = getBytesFromField(data, 'tryToUnlock') ?? Buffer.from([0]);
return Buffer.concat([key, tryToUnlock]);
};
const handshakeCompletionRequestPayload = (data: Record<string, unknown>) => {

View File

@@ -33,6 +33,7 @@ export type ThpCreateChannelResponse = {
export type ThpHandshakeInitRequest = {
key: Buffer;
tryToUnlock: 0 | 1;
};
export type ThpHandshakeInitResponse = {