mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-07 07:47:59 +01:00
chore(protobuf): update THP MessageType enum
This commit is contained in:
@@ -8,6 +8,7 @@ type Definition = {
|
||||
reserved?: unknown[];
|
||||
options?: Record<string, unknown>;
|
||||
valuesOptions?: Record<string, unknown>;
|
||||
values?: Record<string, unknown>;
|
||||
rule?: string;
|
||||
type?: string;
|
||||
extend?: string;
|
||||
|
||||
@@ -47,6 +47,29 @@ const buildThpTypes = (json: ReturnType<typeof buildDefinitions>) => {
|
||||
fs.writeFileSync(`${DIST}/protobufTypes.ts`, content);
|
||||
};
|
||||
|
||||
// merge ThpMessageType into MessageType
|
||||
// ThpMessageType is defined in thp.proto file
|
||||
// MessageType is defined in common messages.proto file
|
||||
const modifyMessageType = (proto: ReturnType<typeof buildDefinitions>) => {
|
||||
const messageTypeEnum = proto.nested?.['MessageType'];
|
||||
const messageTypeDuplicates = ['ButtonRequest', 'Cancel']; // exclude defined in both messages.proto and thp.proto
|
||||
const thpMessageTypeEnum = proto.nested?.['ThpMessageType'];
|
||||
const thpMessageType = thpMessageTypeEnum?.values;
|
||||
if (messageTypeEnum && thpMessageType) {
|
||||
Object.keys(thpMessageType).forEach(key => {
|
||||
// replace key `ThpMessageType_XXX` > `XXX`
|
||||
const newKey = key.replace('ThpMessageType_', '');
|
||||
const value = thpMessageType[key];
|
||||
// add new key to MessageType
|
||||
if (!messageTypeDuplicates.includes(newKey)) {
|
||||
messageTypeEnum.values![newKey] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
// remove ThpMessageType enum
|
||||
delete proto.nested?.['ThpMessageType'];
|
||||
};
|
||||
|
||||
const run = () => {
|
||||
const [protoDir] = process.argv.slice(2);
|
||||
const defs = buildDefinitions(protoDir, {
|
||||
@@ -54,6 +77,7 @@ const run = () => {
|
||||
onlyPackages: ['', 'thp'], // empty package == messages.proto file (MessageType definitions), see buildDefinitions function
|
||||
});
|
||||
|
||||
modifyMessageType(defs);
|
||||
buildThpDefinitions(defs);
|
||||
buildThpTypes(defs);
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ 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 },
|
||||
internal_model: { rule: 'required', type: 'string', id: 1 },
|
||||
model_variant: { type: 'uint32', id: 2, options: { default: 0 } },
|
||||
protocol_version_major: { rule: 'required', type: 'uint32', id: 3 },
|
||||
protocol_version_minor: { rule: 'required', type: 'uint32', id: 4 },
|
||||
pairing_methods: {
|
||||
rule: 'repeated',
|
||||
type: 'ThpPairingMethod',
|
||||
@@ -22,60 +22,68 @@ export const getProtobufDefinitions = () => ({
|
||||
ThpCreateNewSession: {
|
||||
fields: {
|
||||
passphrase: { type: 'string', id: 1 },
|
||||
on_device: { type: 'bool', id: 2 },
|
||||
derive_cardano: { type: 'bool', id: 3 },
|
||||
on_device: { type: 'bool', id: 2, options: { default: false } },
|
||||
derive_cardano: { type: 'bool', id: 3, options: { default: false } },
|
||||
},
|
||||
},
|
||||
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 } },
|
||||
ThpSelectMethod: {
|
||||
fields: { selected_pairing_method: { rule: 'required', type: 'ThpPairingMethod', id: 1 } },
|
||||
},
|
||||
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 } } },
|
||||
ThpPairingPreparationsFinished: { fields: {} },
|
||||
ThpCodeEntryCommitment: { fields: { commitment: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpCodeEntryChallenge: { fields: { challenge: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpCodeEntryCpaceTrezor: {
|
||||
fields: { cpace_trezor_public_key: { rule: 'required', type: 'bytes', id: 1 } },
|
||||
},
|
||||
ThpCodeEntryCpaceHostTag: {
|
||||
fields: {
|
||||
cpace_host_public_key: { rule: 'required', type: 'bytes', id: 1 },
|
||||
tag: { rule: 'required', type: 'bytes', id: 2 },
|
||||
},
|
||||
},
|
||||
ThpCodeEntrySecret: { fields: { secret: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpQrCodeTag: { fields: { tag: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpQrCodeSecret: { fields: { secret: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpNfcTagHost: { fields: { tag: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpNfcTagTrezor: { fields: { tag: { rule: 'required', type: 'bytes', id: 1 } } },
|
||||
ThpCredentialRequest: {
|
||||
fields: {
|
||||
host_static_pubkey: { type: 'bytes', id: 1 },
|
||||
autoconnect: { type: 'bool', id: 2 },
|
||||
host_static_pubkey: { rule: 'required', type: 'bytes', id: 1 },
|
||||
autoconnect: { type: 'bool', id: 2, options: { default: false } },
|
||||
credential: { type: 'bytes', id: 3 },
|
||||
},
|
||||
},
|
||||
ThpCredentialResponse: {
|
||||
fields: {
|
||||
trezor_static_pubkey: { type: 'bytes', id: 1 },
|
||||
credential: { type: 'bytes', id: 2 },
|
||||
trezor_static_pubkey: { rule: 'required', type: 'bytes', id: 1 },
|
||||
credential: { rule: 'required', type: 'bytes', id: 2 },
|
||||
},
|
||||
},
|
||||
ThpEndRequest: { fields: {} },
|
||||
ThpEndResponse: { fields: {} },
|
||||
MessageType: {
|
||||
options: { '(has_bitcoin_only_values)': true, '(wire_enum)': true },
|
||||
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,
|
||||
ThpCredentialRequest: 1016,
|
||||
ThpCredentialResponse: 1017,
|
||||
ThpPairingRequest: 1008,
|
||||
ThpPairingRequestApproved: 1009,
|
||||
ThpSelectMethod: 1010,
|
||||
ThpPairingPreparationsFinished: 1011,
|
||||
ThpEndRequest: 1018,
|
||||
ThpEndResponse: 1019,
|
||||
ThpCodeEntryCommitment: 1024,
|
||||
ThpCodeEntryChallenge: 1025,
|
||||
ThpCodeEntryCpaceTrezor: 1026,
|
||||
ThpCodeEntryCpaceHostTag: 1027,
|
||||
ThpCodeEntrySecret: 1028,
|
||||
ThpQrCodeTag: 1032,
|
||||
ThpQrCodeSecret: 1033,
|
||||
ThpNfcTagHost: 1040,
|
||||
ThpNfcTagTrezor: 1041,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user