aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/subproviders/package.json4
-rw-r--r--packages/subproviders/src/globals.d.ts22
-rw-r--r--packages/subproviders/src/index.ts30
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts8
-rw-r--r--packages/subproviders/src/types.ts44
5 files changed, 76 insertions, 32 deletions
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index ec0642bce..7c02b5745 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -21,12 +21,14 @@
"@0xproject/assert": "^0.1.0",
"@0xproject/types": "^0.3.0",
"@0xproject/utils": "^0.4.0",
+ "@ledgerhq/hw-app-eth": "^4.3.0",
+ "@ledgerhq/hw-transport": "^4.3.0",
+ "@ledgerhq/hw-transport-u2f": "^4.3.0",
"bn.js": "^4.11.8",
"es6-promisify": "^5.0.0",
"ethereumjs-tx": "^1.3.3",
"ethereumjs-util": "^5.1.1",
"hdkey": "^0.7.1",
- "ledgerco": "0xProject/ledger-node-js-api",
"lodash": "^4.17.4",
"semaphore-async-await": "^1.5.1",
"web3": "^0.20.0",
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 6f344dcd3..0c8b3fed3 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -32,6 +32,28 @@ interface ECSignature {
r: string;
s: string;
}
+
+interface LedgerTransport {
+ close(): Promise<void>
+}
+
+declare module '@ledgerhq/hw-app-eth' {
+ export class Eth {
+ constructor(transport: LedgerTransport);
+ public getAddress(path: string, boolDisplay?: boolean, boolChaincode?: boolean): Promise<{ publicKey: string; address: string; chainCode: string }>;
+ public signTransaction(path: string, rawTxHex: string): Promise<ECSignatureString>;
+ public getAppConfiguration(): Promise<{ arbitraryDataEnabled: number; version: string; }>;
+ public signPersonalMessage(path: string, messageHex: string): Promise<ECSignature>;
+ transport: LedgerTransport;
+ }
+}
+declare module '@ledgerhq/hw-transport-u2f' {
+ export class TransportU2F implements LedgerTransport {
+ public static create(): Promise<TransportU2F>;
+ public close(): Promise<void>;
+ }
+}
+
declare module 'ledgerco' {
interface comm {
close_async(): Promise<void>;
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index 4da405ec0..566743fd0 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -1,8 +1,10 @@
import {
- comm_node as LedgerNodeCommunication,
- comm_u2f as LedgerBrowserCommunication,
- eth as LedgerEthereumClientFn,
-} from 'ledgerco';
+ Eth as LedgerEthereumClientFn,
+} from '@ledgerhq/hw-app-eth';
+
+import {
+ TransportU2F as LedgerBrowserCommunication,
+} from '@ledgerhq/hw-transport-u2f';
import { LedgerEthereumClient } from './types';
@@ -19,17 +21,17 @@ export { ECSignature, LedgerWalletSubprovider, LedgerCommunicationClient, NonceS
* @return LedgerEthereumClient A browser client
*/
export async function ledgerEthereumBrowserClientFactoryAsync(): Promise<LedgerEthereumClient> {
- const ledgerConnection = await LedgerBrowserCommunication.create_async();
+ const ledgerConnection = await LedgerBrowserCommunication.create();
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);
- 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);
+// return ledgerEthClient;
+// }
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index 85cdf0efc..0a84caae3 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -134,7 +134,7 @@ export class LedgerSubprovider extends Subprovider {
let ledgerResponse;
try {
- ledgerResponse = await this._ledgerClientIfExists.getAddress_async(
+ ledgerResponse = await this._ledgerClientIfExists.getAddress(
this._derivationPath,
this._shouldAlwaysAskForConfirmation,
SHOULD_GET_CHAIN_CODE,
@@ -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..785547a22 100644
--- a/packages/subproviders/src/types.ts
+++ b/packages/subproviders/src/types.ts
@@ -1,7 +1,25 @@
import * as _ from 'lodash';
+declare class LedgerTransport {
+ // tslint:disable-next-line:async-suffix
+ public static create(): Promise<LedgerTransport>;
+ // tslint:disable-next-line:async-suffix
+ public static close(): Promise<void>;
+}
+
export interface LedgerCommunicationClient {
- close_async: () => Promise<void>;
+ close: () => Promise<void>;
+}
+
+export interface LedgerEthereumClient {
+ getAddress: (
+ derivationPath: string,
+ askForDeviceConfirmation?: boolean,
+ shouldGetChainCode?: boolean,
+ ) => Promise<{ publicKey: string; address: string; chainCode: string }>;
+ signTransaction: (derivationPath: string, rawTxHex: string) => Promise<ECSignatureString>;
+ signPersonalMessage: (derivationPath: string, messageHex: string) => Promise<ECSignature>;
+ transport: LedgerCommunicationClient;
}
/*
@@ -9,18 +27,18 @@ export interface LedgerCommunicationClient {
* It uses an internal LedgerCommunicationClient to relay these requests. Currently
* NodeJs and Browser communication are supported.
*/
-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: (
- 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;
-}
+// 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: (
+// 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;
+// }
export interface ECSignatureString {
v: string;