aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-08 01:42:50 +0800
committerFabio Berger <me@fabioberger.com>2017-12-08 01:42:50 +0800
commit215e33fa6c1ca3c27712f5253daeaebf590f8983 (patch)
treecfee907308158726196d4edfebd7a9bc7064e76b /packages/subproviders/src
parent3d12b84f1d1ecf8eb6fa145f4bf124f0b7b484c1 (diff)
parentbe17b75ad3e043df6f4ff05ead0627cb9a45d93b (diff)
downloaddexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.tar
dexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.tar.gz
dexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.tar.bz2
dexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.tar.lz
dexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.tar.xz
dexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.tar.zst
dexon-sol-tools-215e33fa6c1ca3c27712f5253daeaebf590f8983.zip
Merge branch 'feature/addSubproviders' into feature/portal-ledger-support
* feature/addSubproviders: remove unneeded reset Use rejectedWith Add missing calls to configure remove unneeded type assertions remove unused type Simplify interface to signPersonalMessageAsync Fix unit test Fix ethereumjs-tx declaration and import Use assert.isHexString Add type defs for ledgerco and ethereumjs-tx Make test only run unit tests since cannot run integration tests on CI Improve README Fix version and remove the UMD build Fix tslint error
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r--packages/subproviders/src/globals.d.ts48
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts37
-rw-r--r--packages/subproviders/src/types.ts7
3 files changed, 48 insertions, 44 deletions
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 362587e08..520ca9232 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -1,27 +1,56 @@
/// <reference types='chai-typescript-typings' />
/// <reference types='chai-as-promised-typescript-typings' />
declare module 'dirty-chai';
-declare module 'ledgerco';
-declare module 'ethereumjs-tx';
declare module 'es6-promisify';
// tslint:disable:max-classes-per-file
// tslint:disable:class-name
// tslint:disable:completed-docs
+// Ethereumjs-tx declarations
+declare module 'ethereumjs-tx' {
+ class EthereumTx {
+ public raw: Buffer[];
+ public r: Buffer;
+ public s: Buffer;
+ public v: Buffer;
+ public serialize(): Buffer;
+ constructor(txParams: any);
+ }
+ export = EthereumTx;
+}
+
// Ledgerco declarations
+interface ECSignatureString {
+ v: string;
+ r: string;
+ s: string;
+}
+interface ECSignature {
+ v: number;
+ r: string;
+ s: string;
+}
declare module 'ledgerco' {
interface comm {
- close_async: Promise<void>;
- create_async: Promise<void>;
+ close_async(): Promise<void>;
}
export class comm_node implements comm {
- public create_async: Promise<void>;
- public close_async: Promise<void>;
+ public static create_async(timeoutMilliseconds?: number): Promise<comm_node>;
+ public close_async(): Promise<void>;
}
export class comm_u2f implements comm {
- public create_async: Promise<void>;
- public close_async: Promise<void>;
+ public static create_async(): Promise<comm_u2f>;
+ public close_async(): Promise<void>;
+ }
+ export class eth {
+ public comm: comm;
+ constructor(comm: comm);
+ public getAddress_async(path: string, display?: boolean, chaincode?: boolean):
+ Promise<{publicKey: string; address: 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>;
}
}
@@ -66,6 +95,3 @@ declare module 'web3-provider-engine' {
}
export = Web3ProviderEngine;
}
-// tslint:enable:max-classes-per-file
-// tslint:enable:class-name
-// tslint:enable:completed-docs
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index ccc94d76f..83c5b6867 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -1,6 +1,7 @@
+import {assert} from '@0xproject/assert';
import promisify = require('es6-promisify');
import {isAddress} from 'ethereum-address';
-import * as EthereumTx from 'ethereumjs-tx';
+import EthereumTx = require('ethereumjs-tx');
import ethUtil = require('ethereumjs-util');
import * as ledger from 'ledgerco';
import * as _ from 'lodash';
@@ -14,7 +15,6 @@ import {
LedgerSubproviderErrors,
PartialTxParams,
ResponseWithTxParams,
- SignPersonalMessageParams,
} from '../types';
import {Subprovider} from './subprovider';
@@ -46,17 +46,6 @@ export class LedgerSubprovider extends Subprovider {
const isValid = nonPrefixed.match(HEX_REGEX);
return isValid;
}
- private static validatePersonalMessage(msgParams: PartialTxParams) {
- if (_.isUndefined(msgParams.from) || !isAddress(msgParams.from)) {
- throw new Error(LedgerSubproviderErrors.FromAddressMissingOrInvalid);
- }
- if (_.isUndefined(msgParams.data)) {
- throw new Error(LedgerSubproviderErrors.DataMissingForSignPersonalMessage);
- }
- if (!LedgerSubprovider.isValidHex(msgParams.data)) {
- throw new Error(LedgerSubproviderErrors.DataNotValidHexForSignPersonalMessage);
- }
- }
private static validateSender(sender: string) {
if (_.isUndefined(sender) || !isAddress(sender)) {
throw new Error(LedgerSubproviderErrors.SenderInvalidOrNotSupplied);
@@ -132,17 +121,13 @@ export class LedgerSubprovider extends Subprovider {
return;
case 'personal_sign':
- // non-standard "extraParams" to be appended to our "msgParams" obj
- // good place for metadata
- const extraParams = payload.params[2] || {};
- const msgParams = _.assign({}, extraParams, {
- from: payload.params[1],
- data: payload.params[0],
- });
-
+ const data = payload.params[0];
try {
- LedgerSubprovider.validatePersonalMessage(msgParams);
- const ecSignatureHex = await this.signPersonalMessageAsync(msgParams);
+ if (_.isUndefined(data)) {
+ throw new Error(LedgerSubproviderErrors.DataMissingForSignPersonalMessage);
+ }
+ assert.isHexString('data', data);
+ const ecSignatureHex = await this.signPersonalMessageAsync(data);
end(null, ecSignatureHex);
} catch (err) {
end(err);
@@ -208,12 +193,12 @@ export class LedgerSubprovider extends Subprovider {
throw err;
}
}
- public async signPersonalMessageAsync(msgParams: SignPersonalMessageParams): Promise<string> {
+ public async signPersonalMessageAsync(data: string): Promise<string> {
this._ledgerClientIfExists = await this.createLedgerClientAsync();
try {
const derivationPath = this.getDerivationPath();
const result = await this._ledgerClientIfExists.signPersonalMessage_async(
- derivationPath, ethUtil.stripHexPrefix(msgParams.data));
+ derivationPath, ethUtil.stripHexPrefix(data));
const v = result.v - 27;
let vHex = v.toString(16);
if (vHex.length < 2) {
@@ -251,7 +236,7 @@ export class LedgerSubprovider extends Subprovider {
this._ledgerClientIfExists = undefined;
this._connectionLock.signal();
}
- private async sendTransactionAsync(txParams: PartialTxParams): Promise<any> {
+ private async sendTransactionAsync(txParams: PartialTxParams): Promise<Web3.JSONRPCResponsePayload> {
await this._nonceLock.wait();
try {
// fill in the extras
diff --git a/packages/subproviders/src/types.ts b/packages/subproviders/src/types.ts
index 4564c5229..38dc1e67e 100644
--- a/packages/subproviders/src/types.ts
+++ b/packages/subproviders/src/types.ts
@@ -2,8 +2,6 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
export interface LedgerCommunicationClient {
- exchange: (apduHex: string, statusList: number[]) => Promise<any[]>;
- setScrambleKey: (key: string) => void;
close_async: () => Promise<void>;
}
@@ -74,10 +72,6 @@ export interface LedgerWalletSubprovider {
setPathIndex: (pathIndex: number) => void;
}
-export interface SignPersonalMessageParams {
- data: string;
-}
-
export interface PartialTxParams {
nonce: string;
gasPrice?: string;
@@ -109,7 +103,6 @@ export enum LedgerSubproviderErrors {
TooOldLedgerFirmware = 'TOO_OLD_LEDGER_FIRMWARE',
FromAddressMissingOrInvalid = 'FROM_ADDRESS_MISSING_OR_INVALID',
DataMissingForSignPersonalMessage = 'DATA_MISSING_FOR_SIGN_PERSONAL_MESSAGE',
- DataNotValidHexForSignPersonalMessage = 'DATA_NOT_VALID_HEX_FOR_SIGN_PERSONAL_MESSAGE',
SenderInvalidOrNotSupplied = 'SENDER_INVALID_OR_NOT_SUPPLIED',
MultipleOpenConnectionsDisallowed = 'MULTIPLE_OPEN_CONNECTIONS_DISALLOWED',
}