diff options
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r-- | packages/subproviders/src/subproviders/ledger.ts | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts index c8fa7fd5a..30d8d574f 100644 --- a/packages/subproviders/src/subproviders/ledger.ts +++ b/packages/subproviders/src/subproviders/ledger.ts @@ -47,15 +47,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); - } - assert.isHexString('data', msgParams.data); - } private static validateSender(sender: string) { if (_.isUndefined(sender) || !isAddress(sender)) { throw new Error(LedgerSubproviderErrors.SenderInvalidOrNotSupplied); @@ -131,17 +122,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); @@ -207,12 +194,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) { @@ -250,7 +237,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 |