aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-28 17:28:27 +0800
committerFabio Berger <me@fabioberger.com>2017-12-28 17:28:27 +0800
commitf2976af734a9c9dfdbac16b22040e8bdd97aa426 (patch)
treebbe99ba9dded45c7f7409bff3a13bbf6c30f80b8
parentee463058f153fa7de7e7dc9fbe160999cbbb5b11 (diff)
downloaddexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.tar
dexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.tar.gz
dexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.tar.bz2
dexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.tar.lz
dexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.tar.xz
dexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.tar.zst
dexon-sol-tools-f2976af734a9c9dfdbac16b22040e8bdd97aa426.zip
Support both personal_sign and eth_sign
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts3
-rw-r--r--packages/subproviders/test/integration/ledger_subprovider_test.ts22
-rw-r--r--packages/subproviders/test/unit/ledger_subprovider_test.ts33
3 files changed, 55 insertions, 3 deletions
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index 653d0a792..a058e09ad 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -107,7 +107,8 @@ export class LedgerSubprovider extends Subprovider {
return;
case 'eth_sign':
- const data = payload.params[1];
+ case 'personal_sign':
+ const data = payload.method === 'eth_sign' ? payload.params[1] : payload.params[0];
try {
if (_.isUndefined(data)) {
throw new Error(LedgerSubproviderErrors.DataMissingForSignPersonalMessage);
diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts
index 169e15504..7f319ed4e 100644
--- a/packages/subproviders/test/integration/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts
@@ -85,7 +85,7 @@ describe('LedgerSubprovider', () => {
});
ledgerProvider.sendAsync(payload, callback);
});
- it('signs a personal message', (done: DoneCallback) => {
+ it('signs a personal message with eth_sign', (done: DoneCallback) => {
(async () => {
const messageHex = ethUtils.bufferToHex(ethUtils.toBuffer('hello world'));
const accounts = await ledgerSubprovider.getAccountsAsync();
@@ -105,6 +105,26 @@ describe('LedgerSubprovider', () => {
ledgerProvider.sendAsync(payload, callback);
})().catch(done);
});
+ it('signs a personal message with personal_sign', (done: DoneCallback) => {
+ (async () => {
+ const messageHex = ethUtils.bufferToHex(ethUtils.toBuffer('hello world'));
+ const accounts = await ledgerSubprovider.getAccountsAsync();
+ const signer = accounts[0];
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'personal_sign',
+ params: [messageHex, signer],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ expect(response.result.length).to.be.equal(132);
+ expect(response.result.substr(0, 2)).to.be.equal('0x');
+ done();
+ });
+ ledgerProvider.sendAsync(payload, callback);
+ })().catch(done);
+ });
it('signs a transaction', (done: DoneCallback) => {
const tx = {
to: '0xafa3f8684e54059998bc3a7b0d2b0da075154d66',
diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts
index 6160b9cc3..d493adf1e 100644
--- a/packages/subproviders/test/unit/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts
@@ -117,7 +117,7 @@ describe('LedgerSubprovider', () => {
});
provider.sendAsync(payload, callback);
});
- it('signs a personal message', (done: DoneCallback) => {
+ it('signs a personal message with eth_sign', (done: DoneCallback) => {
const messageHex = ethUtils.bufferToHex(ethUtils.toBuffer('hello world'));
const payload = {
jsonrpc: '2.0',
@@ -133,6 +133,22 @@ describe('LedgerSubprovider', () => {
});
provider.sendAsync(payload, callback);
});
+ it('signs a personal message with personal_sign', (done: DoneCallback) => {
+ const messageHex = ethUtils.bufferToHex(ethUtils.toBuffer('hello world'));
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'personal_sign',
+ params: [messageHex, '0x0000000000000000000000000000000000000000'],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ // tslint:disable-next-line:max-line-length
+ expect(response.result).to.be.equal('0xa6cc284bff14b42bdf5e9286730c152be91719d478605ec46b3bebcd0ae491480652a1a7b742ceb0213d1e744316e285f41f878d8af0b8e632cbca4c279132d001');
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
it('signs a transaction', (done: DoneCallback) => {
const tx = {
to: '0xafa3f8684e54059998bc3a7b0d2b0da075154d66',
@@ -172,6 +188,21 @@ describe('LedgerSubprovider', () => {
});
provider.sendAsync(payload, callback);
});
+ it('should throw if `data` param not hex when calling personal_sign', (done: DoneCallback) => {
+ const nonHexMessage = 'hello world';
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'personal_sign',
+ params: [nonHexMessage, '0x0000000000000000000000000000000000000000'],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => {
+ expect(err).to.not.be.a('null');
+ expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world');
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
it('should throw if `from` param missing when calling eth_sendTransaction', (done: DoneCallback) => {
const tx = {
to: '0xafa3f8684e54059998bc3a7b0d2b0da075154d66',