aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r--packages/subproviders/src/globals.d.ts54
-rw-r--r--packages/subproviders/src/index.ts21
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts14
-rw-r--r--packages/subproviders/src/types.ts10
4 files changed, 46 insertions, 53 deletions
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 6f344dcd3..d59ee9e67 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -32,32 +32,38 @@ interface ECSignature {
r: string;
s: string;
}
-declare module 'ledgerco' {
- interface comm {
- close_async(): Promise<void>;
- }
- export class comm_node implements comm {
- public static create_async(timeoutMilliseconds?: number): Promise<comm_node>;
- public close_async(): Promise<void>;
- }
- export class comm_u2f implements comm {
- public static create_async(): Promise<comm_u2f>;
- public close_async(): Promise<void>;
- }
- export class eth {
- public comm: comm;
- constructor(comm: comm);
- public getAddress_async(
+
+interface LedgerTransport {
+ close(): Promise<void>;
+}
+
+declare module '@ledgerhq/hw-app-eth' {
+ class Eth {
+ public transport: LedgerTransport;
+ constructor(transport: LedgerTransport);
+ public getAddress(
path: string,
- display?: boolean,
- chaincode?: boolean,
+ boolDisplay?: boolean,
+ boolChaincode?: boolean,
): Promise<{ publicKey: string; address: string; chainCode: string }>;
- public signTransaction_async(path: string, rawTxHex: string): Promise<ECSignatureString>;
- public getAppConfiguration_async(): Promise<{
- arbitraryDataEnabled: number;
- version: string;
- }>;
- public signPersonalMessage_async(path: string, messageHex: string): Promise<ECSignature>;
+ public signTransaction(path: string, rawTxHex: string): Promise<ECSignatureString>;
+ public getAppConfiguration(): Promise<{ arbitraryDataEnabled: number; version: string }>;
+ public signPersonalMessage(path: string, messageHex: string): Promise<ECSignature>;
+ }
+ export default Eth;
+}
+
+declare module '@ledgerhq/hw-transport-u2f' {
+ export default class TransportU2F implements LedgerTransport {
+ public static create(): Promise<LedgerTransport>;
+ public close(): Promise<void>;
+ }
+}
+
+declare module '@ledgerhq/hw-transport-node-hid' {
+ export default class TransportNodeHid implements LedgerTransport {
+ public static create(): Promise<LedgerTransport>;
+ public close(): Promise<void>;
}
}
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index 4da405ec0..e22b6f5f3 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -1,8 +1,5 @@
-import {
- comm_node as LedgerNodeCommunication,
- comm_u2f as LedgerBrowserCommunication,
- eth as LedgerEthereumClientFn,
-} from 'ledgerco';
+import Eth from '@ledgerhq/hw-app-eth';
+import TransportU2F from '@ledgerhq/hw-transport-u2f';
import { LedgerEthereumClient } from './types';
@@ -19,17 +16,7 @@ export { ECSignature, LedgerWalletSubprovider, LedgerCommunicationClient, NonceS
* @return LedgerEthereumClient A browser client
*/
export async function ledgerEthereumBrowserClientFactoryAsync(): Promise<LedgerEthereumClient> {
- const ledgerConnection = await LedgerBrowserCommunication.create_async();
- const ledgerEthClient = new LedgerEthereumClientFn(ledgerConnection);
- return ledgerEthClient;
-}
-
-/**
- * A factory for creating a LedgerEthereumClient usable in a Node.js context.
- * @return LedgerEthereumClient A Node.js client
- */
-export async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
- const ledgerConnection = await LedgerNodeCommunication.create_async();
- const ledgerEthClient = new LedgerEthereumClientFn(ledgerConnection);
+ const ledgerConnection = await TransportU2F.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
return ledgerEthClient;
}
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index 5966a88bb..0a84caae3 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -19,7 +19,7 @@ import {
import { Subprovider } from './subprovider';
const DEFAULT_DERIVATION_PATH = `44'/60'/0'`;
-const NUM_ADDRESSES_TO_FETCH = 10;
+const DEFAULT_NUM_ADDRESSES_TO_FETCH = 10;
const ASK_FOR_ON_DEVICE_CONFIRMATION = false;
const SHOULD_GET_CHAIN_CODE = true;
@@ -129,12 +129,12 @@ export class LedgerSubprovider extends Subprovider {
return;
}
}
- public async getAccountsAsync(): Promise<string[]> {
+ public async getAccountsAsync(numberOfAccounts: number = DEFAULT_NUM_ADDRESSES_TO_FETCH): Promise<string[]> {
this._ledgerClientIfExists = await this._createLedgerClientAsync();
let ledgerResponse;
try {
- ledgerResponse = await this._ledgerClientIfExists.getAddress_async(
+ ledgerResponse = await this._ledgerClientIfExists.getAddress(
this._derivationPath,
this._shouldAlwaysAskForConfirmation,
SHOULD_GET_CHAIN_CODE,
@@ -148,7 +148,7 @@ export class LedgerSubprovider extends Subprovider {
hdKey.chainCode = new Buffer(ledgerResponse.chainCode, 'hex');
const accounts = [];
- for (let i = 0; i < NUM_ADDRESSES_TO_FETCH; i++) {
+ for (let i = 0; i < numberOfAccounts; i++) {
const derivedHDNode = hdKey.derive(`m/${i + this._derivationPathIndex}`);
const derivedPublicKey = derivedHDNode.publicKey;
const shouldSanitizePublicKey = true;
@@ -173,7 +173,7 @@ export class LedgerSubprovider extends Subprovider {
const txHex = tx.serialize().toString('hex');
try {
const derivationPath = this._getDerivationPath();
- const result = await this._ledgerClientIfExists.signTransaction_async(derivationPath, txHex);
+ const result = await this._ledgerClientIfExists.signTransaction(derivationPath, txHex);
// Store signature in transaction
tx.r = Buffer.from(result.r, 'hex');
tx.s = Buffer.from(result.s, 'hex');
@@ -199,7 +199,7 @@ export class LedgerSubprovider extends Subprovider {
this._ledgerClientIfExists = await this._createLedgerClientAsync();
try {
const derivationPath = this._getDerivationPath();
- const result = await this._ledgerClientIfExists.signPersonalMessage_async(
+ const result = await this._ledgerClientIfExists.signPersonalMessage(
derivationPath,
ethUtil.stripHexPrefix(data),
);
@@ -236,7 +236,7 @@ export class LedgerSubprovider extends Subprovider {
this._connectionLock.signal();
return;
}
- await this._ledgerClientIfExists.comm.close_async();
+ await this._ledgerClientIfExists.transport.close();
this._ledgerClientIfExists = undefined;
this._connectionLock.signal();
}
diff --git a/packages/subproviders/src/types.ts b/packages/subproviders/src/types.ts
index 65b7f6c8f..f49ac6107 100644
--- a/packages/subproviders/src/types.ts
+++ b/packages/subproviders/src/types.ts
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
export interface LedgerCommunicationClient {
- close_async: () => Promise<void>;
+ close: () => Promise<void>;
}
/*
@@ -12,14 +12,14 @@ export interface LedgerCommunicationClient {
export interface LedgerEthereumClient {
// shouldGetChainCode is defined as `true` instead of `boolean` because other types rely on the assumption
// that we get back the chain code and we don't have dependent types to express it properly
- getAddress_async: (
+ getAddress: (
derivationPath: string,
askForDeviceConfirmation: boolean,
shouldGetChainCode: true,
) => Promise<LedgerGetAddressResult>;
- signPersonalMessage_async: (derivationPath: string, messageHex: string) => Promise<ECSignature>;
- signTransaction_async: (derivationPath: string, txHex: string) => Promise<ECSignatureString>;
- comm: LedgerCommunicationClient;
+ signTransaction: (derivationPath: string, rawTxHex: string) => Promise<ECSignatureString>;
+ signPersonalMessage: (derivationPath: string, messageHex: string) => Promise<ECSignature>;
+ transport: LedgerCommunicationClient;
}
export interface ECSignatureString {