diff options
author | Fabio Berger <me@fabioberger.com> | 2017-12-07 10:52:48 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-12-07 10:52:48 +0800 |
commit | e8495b0c7bf58cb683f70cd66a983dbf909215c0 (patch) | |
tree | 552f5da749b4e05db5c7e3893c3e9c52402fc6f5 /packages/subproviders/src | |
parent | e80579a6055f75edac0fb0e948838495d6599bb5 (diff) | |
download | dexon-sol-tools-e8495b0c7bf58cb683f70cd66a983dbf909215c0.tar.gz dexon-sol-tools-e8495b0c7bf58cb683f70cd66a983dbf909215c0.tar.zst dexon-sol-tools-e8495b0c7bf58cb683f70cd66a983dbf909215c0.zip |
Simplify interface to signPersonalMessageAsync
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 |