Skip to content

Commit

Permalink
Refactor keyring to split bridge logic (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergarces authored Jun 15, 2023
1 parent 2b92728 commit c8f8a4e
Show file tree
Hide file tree
Showing 7 changed files with 1,114 additions and 605 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ module.exports = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 59.25,
functions: 81.94,
lines: 78.54,
statements: 78.49,
branches: 65.42,
functions: 88.57,
lines: 81.57,
statements: 81.49,
},
},

Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './ledger-bridge-keyring';
export * from './ledger-keyring';
export * from './ledger-iframe-bridge';
export * from './ledger-bridge';
54 changes: 54 additions & 0 deletions src/ledger-bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';

export type GetPublicKeyParams = { hdPath: string };
export type GetPublicKeyResponse = Awaited<
ReturnType<LedgerHwAppEth['getAddress']>
> & {
chainCode: string;
};

export type LedgerSignTransactionParams = { hdPath: string; tx: string };
export type LedgerSignTransactionResponse = Awaited<
ReturnType<LedgerHwAppEth['signTransaction']>
>;

export type LedgerSignMessageParams = { hdPath: string; message: string };
export type LedgerSignMessageResponse = Awaited<
ReturnType<LedgerHwAppEth['signPersonalMessage']>
>;

export type LedgerSignTypedDataParams = {
hdPath: string;
domainSeparatorHex: string;
hashStructMessageHex: string;
};
export type LedgerSignTypedDataResponse = Awaited<
ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>
>;

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface LedgerBridge {
isDeviceConnected: boolean;

init(bridgeUrl: string): Promise<void>;

destroy(): Promise<void>;

attemptMakeApp(): Promise<boolean>;

updateTransportMethod(transportType: string): Promise<boolean>;

getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;

deviceSignTransaction(
params: LedgerSignTransactionParams,
): Promise<LedgerSignTransactionResponse>;

deviceSignMessage(
params: LedgerSignMessageParams,
): Promise<LedgerSignMessageResponse>;

deviceSignTypedData(
params: LedgerSignTypedDataParams,
): Promise<LedgerSignTypedDataResponse>;
}
Loading

0 comments on commit c8f8a4e

Please sign in to comment.