feat(protocol): add THP protobuf types and state

This commit is contained in:
Szymon Lesisz
2024-06-26 18:35:48 +02:00
committed by martin
parent 7951ed9c76
commit 5838888e83
7 changed files with 62 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
export * as v1 from './protocol-v1';
export * as v2 from './protocol-v2';
export * as bridge from './protocol-bridge';
export * as thp from './protocol-thp';
export * as trzd from './protocol-trzd';
export * from './errors';
export * from './types';

View File

@@ -0,0 +1,23 @@
import { ThpDeviceProperties } from './messages';
export type ThpStateSerialized = {
properties?: ThpDeviceProperties;
};
export class ThpState {
private _properties?: ThpDeviceProperties;
get properties() {
return this._properties;
}
setThpProperties(props: ThpDeviceProperties) {
this._properties = props;
}
serialize(): ThpStateSerialized {
return {
properties: this._properties,
};
}
}

View File

@@ -0,0 +1,5 @@
export * from './messages';
export { ThpState } from './ThpState';
export const name = 'thp';

View File

@@ -0,0 +1,2 @@
export * from './protobufTypes';
export * from './messageTypes';

View File

@@ -0,0 +1,3 @@
import type { ThpCredentialResponse } from './protobufTypes';
export type ThpCredentials = ThpCredentialResponse & { autoconnect?: boolean };

View File

@@ -0,0 +1,21 @@
// This file is auto generated by @trezor/protobuf package
export enum ThpPairingMethod {
SkipPairing = 1,
CodeEntry = 2,
QrCode = 3,
NFC = 4,
}
export type ThpDeviceProperties = {
internal_model: string;
model_variant: number;
protocol_version_major: number;
protocol_version_minor: number;
pairing_methods: ThpPairingMethod[];
};
export type ThpCredentialResponse = {
trezor_static_pubkey: string;
credential: string;
};

View File

@@ -1,3 +1,10 @@
export type {
ThpDeviceProperties,
ThpPairingMethod,
ThpCredentials,
} from './protocol-thp/messages';
export type { ThpState, ThpStateSerialized } from './protocol-thp/ThpState';
export type TransportProtocolDecode = (bytes: Buffer) => {
header: Buffer;
length: number;