Skip to content

Commit

Permalink
version b
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski committed Mar 28, 2024
1 parent a65f782 commit f1f4912
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions packages/hardware-ledger/src/LedgerKeyAgent.ts
Expand Up @@ -168,11 +168,10 @@ const isMultiSig = (tx: Transaction): boolean => {
return result;
};

type LedgerConnectionWithCommunicationTypeAndDevicePath = {
communicationType: CommunicationType;
device?: LedgerDevice;
type DeviceConnectionWithInitializationParams = {
deviceConnection: LedgerConnection;
nodeHidDevicePath?: string;
communicationType: CommunicationType;
nodeHidDevicePathOrDevice: LedgerDevice | string | undefined;
};

type OpenTransportForDeviceParams = {
Expand All @@ -183,7 +182,7 @@ type OpenTransportForDeviceParams = {
export class LedgerKeyAgent extends KeyAgentBase {
readonly deviceConnection?: LedgerConnection;
readonly #communicationType: CommunicationType;
static deviceConnections: LedgerConnectionWithCommunicationTypeAndDevicePath[] = [];
static deviceConnections: DeviceConnectionWithInitializationParams[] = [];

constructor({ deviceConnection, ...serializableData }: LedgerKeyAgentProps, dependencies: KeyAgentDependencies) {
super({ ...serializableData, __typename: KeyAgentType.Ledger }, dependencies);
Expand All @@ -193,14 +192,12 @@ export class LedgerKeyAgent extends KeyAgentBase {

private static async findConnectionByCommunicationTypeAndDevicePath(
communicationType: CommunicationType,
nodeHidDevicePath?: string,
device?: LedgerDevice
nodeHidDevicePathOrDevice?: LedgerDevice | string
): Promise<LedgerConnection | null> {
const matchingConnectionData = this.deviceConnections?.find(
(connection) =>
connection.communicationType === communicationType &&
connection.nodeHidDevicePath === nodeHidDevicePath &&
connection.device === device
connection.nodeHidDevicePathOrDevice === nodeHidDevicePathOrDevice
);
if (!matchingConnectionData) return null;

Expand Down Expand Up @@ -331,8 +328,7 @@ export class LedgerKeyAgent extends KeyAgentBase {

const matchingOpenConnection = await this.findConnectionByCommunicationTypeAndDevicePath(
communicationType,
nodeHidDevicePath,
device
nodeHidDevicePathOrDevice
);
if (matchingOpenConnection) return matchingOpenConnection;

Expand All @@ -352,9 +348,8 @@ export class LedgerKeyAgent extends KeyAgentBase {
const newConnection = await LedgerKeyAgent.createDeviceConnection(transport);
this.deviceConnections.push({
communicationType,
device,
deviceConnection: newConnection,
nodeHidDevicePath
nodeHidDevicePathOrDevice
});

return newConnection;
Expand Down

0 comments on commit f1f4912

Please sign in to comment.