feat(protocol): add THP protobuf definitions and types

This commit is contained in:
Szymon Lesisz
2024-06-26 18:35:48 +02:00
committed by Szymon Lesisz
parent 2c9b86dbd5
commit b5cb747767
4 changed files with 215 additions and 1 deletions

View File

@@ -1,2 +1,3 @@
export * from './protobufTypes';
export { getProtobufDefinitions } from './protobufDefinitions';
export * from './messageTypes';
export * from './protobufTypes';

View File

@@ -32,11 +32,54 @@ export type ThpCreateChannelResponse = {
handshakeHash: Buffer;
};
export type ThpHandshakeInitRequest = {
key: Buffer;
};
export type ThpHandshakeInitResponse = {
handshakeHash: Buffer;
trezorEphemeralPubkey: Buffer;
trezorEncryptedStaticPubkey: Buffer;
trezorMaskedStaticPubkey: Buffer;
tag: Buffer;
hostEncryptedStaticPubkey: Buffer;
hostKey: Buffer;
trezorKey: Buffer;
};
export type ThpHandshakeCompletionRequest = {
hostPubkey: Buffer;
encryptedPayload: Buffer;
};
export type ThpHandshakeCompletionResponse = {
state: 0 | 1;
tag: Buffer;
};
export type ThpMessageType = ThpProtobufMessageType & {
ThpError: ThpError;
ThpAck: ThpAck;
ThpCreateChannelRequest: ThpCreateChannelRequest;
ThpCreateChannelResponse: ThpCreateChannelResponse;
ThpHandshakeInitRequest: ThpHandshakeInitRequest;
ThpHandshakeInitResponse: ThpHandshakeInitResponse;
ThpHandshakeCompletionRequest: ThpHandshakeCompletionRequest;
ThpHandshakeCompletionResponse: ThpHandshakeCompletionResponse;
};
export type ThpHandshakeCredentials = {
pairingMethods: ThpDeviceProperties['pairing_methods'];
handshakeHash: Buffer;
handshakeCommitment: Buffer;
codeEntryChallenge: Buffer;
trezorEncryptedStaticPubkey: Buffer;
hostEncryptedStaticPubkey: Buffer;
staticKey: Buffer;
hostStaticPublicKey: Buffer;
hostKey: Buffer;
trezorKey: Buffer;
trezorCpacePublicKey: Buffer;
};
export type ThpCredentials = ThpCredentialResponse & { autoconnect?: boolean };

View File

@@ -0,0 +1,81 @@
// This file is auto generated by @trezor/protobuf package
export const getProtobufDefinitions = () => ({
ThpPairingMethod: { values: { SkipPairing: 1, CodeEntry: 2, QrCode: 3, NFC: 4 } },
ThpDeviceProperties: {
fields: {
internal_model: { type: 'string', id: 1 },
model_variant: { type: 'uint32', id: 2 },
protocol_version_major: { type: 'uint32', id: 3 },
protocol_version_minor: { type: 'uint32', id: 4 },
pairing_methods: {
rule: 'repeated',
type: 'ThpPairingMethod',
id: 5,
options: { packed: false },
},
},
},
ThpHandshakeCompletionReqNoisePayload: {
fields: { host_pairing_credential: { type: 'bytes', id: 1 } },
},
ThpCreateNewSession: {
fields: {
passphrase: { type: 'string', id: 1 },
on_device: { type: 'bool', id: 2 },
derive_cardano: { type: 'bool', id: 3 },
},
},
ThpPairingRequest: { fields: { host_name: { type: 'string', id: 1 } } },
ThpPairingRequestApproved: { fields: {} },
ThpSelectMethod: { fields: { selected_pairing_method: { type: 'ThpPairingMethod', id: 1 } } },
ThpPairingPreparationsFinished: { fields: {} },
ThpCodeEntryCommitment: { fields: { commitment: { type: 'bytes', id: 1 } } },
ThpCodeEntryChallenge: { fields: { challenge: { type: 'bytes', id: 1 } } },
ThpCodeEntryCpaceTrezor: { fields: { cpace_trezor_public_key: { type: 'bytes', id: 1 } } },
ThpCodeEntryCpaceHostTag: {
fields: { cpace_host_public_key: { type: 'bytes', id: 1 }, tag: { type: 'bytes', id: 2 } },
},
ThpCodeEntrySecret: { fields: { secret: { type: 'bytes', id: 1 } } },
ThpQrCodeTag: { fields: { tag: { type: 'bytes', id: 1 } } },
ThpQrCodeSecret: { fields: { secret: { type: 'bytes', id: 1 } } },
ThpNfcTagHost: { fields: { tag: { type: 'bytes', id: 1 } } },
ThpNfcTagTrezor: { fields: { tag: { type: 'bytes', id: 1 } } },
ThpCredentialRequest: {
fields: {
host_static_pubkey: { type: 'bytes', id: 1 },
autoconnect: { type: 'bool', id: 2 },
credential: { type: 'bytes', id: 3 },
},
},
ThpCredentialResponse: {
fields: {
trezor_static_pubkey: { type: 'bytes', id: 1 },
credential: { type: 'bytes', id: 2 },
},
},
ThpEndRequest: { fields: {} },
ThpEndResponse: { fields: {} },
MessageType: {
values: {
ThpCreateNewSession: 1000,
ThpPairingRequest: 1006,
ThpPairingRequestApproved: 1007,
ThpSelectMethod: 1008,
ThpPairingPreparationsFinished: 1009,
ThpCredentialRequest: 1010,
ThpCredentialResponse: 1011,
ThpEndRequest: 1012,
ThpEndResponse: 1013,
ThpCodeEntryCommitment: 1016,
ThpCodeEntryChallenge: 1017,
ThpCodeEntryCpaceTrezor: 1018,
ThpCodeEntryCpaceHostTag: 1019,
ThpCodeEntrySecret: 1020,
ThpQrCodeTag: 1024,
ThpQrCodeSecret: 1025,
ThpNfcTagHost: 1032,
ThpNfcTagTrezor: 1033,
},
},
});

View File

@@ -15,11 +15,100 @@ export type ThpDeviceProperties = {
pairing_methods: ThpPairingMethod[];
};
export type ThpHandshakeCompletionReqNoisePayload = {
host_pairing_credential?: string;
};
// ThpCreateNewSession replacement
// either passphrase or on_device needs to be present
export type ThpCreateNewSession = { derive_cardano?: boolean } & (
| { passphrase: string; on_device?: undefined }
| { passphrase?: undefined; on_device: boolean }
);
export type ThpPairingRequest = {
host_name: string;
};
export type ThpPairingRequestApproved = {};
export type ThpSelectMethod = {
selected_pairing_method: ThpPairingMethod;
};
export type ThpPairingPreparationsFinished = {};
export type ThpCodeEntryCommitment = {
commitment: string;
};
export type ThpCodeEntryChallenge = {
challenge: string;
};
export type ThpCodeEntryCpaceTrezor = {
cpace_trezor_public_key: string;
};
export type ThpCodeEntryCpaceHostTag = {
cpace_host_public_key: string;
tag: string;
};
export type ThpCodeEntrySecret = {
secret: string;
};
export type ThpQrCodeTag = {
tag: string;
};
export type ThpQrCodeSecret = {
secret: string;
};
export type ThpNfcTagHost = {
tag: string;
};
export type ThpNfcTagTrezor = {
tag: string;
};
export type ThpCredentialRequest = {
host_static_pubkey: string;
autoconnect: boolean;
credential?: string;
};
export type ThpCredentialResponse = {
trezor_static_pubkey: string;
credential: string;
};
export type ThpEndRequest = {};
export type ThpEndResponse = {};
export type ThpProtobufMessageType = {
ThpDeviceProperties: ThpDeviceProperties;
ThpHandshakeCompletionReqNoisePayload: ThpHandshakeCompletionReqNoisePayload;
ThpCreateNewSession: ThpCreateNewSession;
ThpPairingRequest: ThpPairingRequest;
ThpPairingRequestApproved: ThpPairingRequestApproved;
ThpSelectMethod: ThpSelectMethod;
ThpPairingPreparationsFinished: ThpPairingPreparationsFinished;
ThpCodeEntryCommitment: ThpCodeEntryCommitment;
ThpCodeEntryChallenge: ThpCodeEntryChallenge;
ThpCodeEntryCpaceTrezor: ThpCodeEntryCpaceTrezor;
ThpCodeEntryCpaceHostTag: ThpCodeEntryCpaceHostTag;
ThpCodeEntrySecret: ThpCodeEntrySecret;
ThpQrCodeTag: ThpQrCodeTag;
ThpQrCodeSecret: ThpQrCodeSecret;
ThpNfcTagHost: ThpNfcTagHost;
ThpNfcTagTrezor: ThpNfcTagTrezor;
ThpCredentialRequest: ThpCredentialRequest;
ThpCredentialResponse: ThpCredentialResponse;
ThpEndRequest: ThpEndRequest;
ThpEndResponse: ThpEndResponse;
};