aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-08-24 17:42:20 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-08-25 05:40:00 +0800
commit241534a63dab54172326ec71d6b5e78733bb24c6 (patch)
treeb5a903a14895e672d9a5f1a705e360cb4d17958e
parent1932aff35c6b07093534cde66dec63c5f919fcf0 (diff)
downloaddexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.tar
dexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.tar.gz
dexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.tar.bz2
dexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.tar.lz
dexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.tar.xz
dexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.tar.zst
dexon-sol-tools-241534a63dab54172326ec71d6b5e78733bb24c6.zip
Fixed trezor personal message in client+contracts; added a test using message signed by Trezor One (firmware v1.6.2)
-rw-r--r--packages/contracts/test/exchange/signature_validator.ts18
-rw-r--r--packages/order-utils/src/signature_utils.ts2
2 files changed, 19 insertions, 1 deletions
diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts
index 9113e5248..a318d1f79 100644
--- a/packages/contracts/test/exchange/signature_validator.ts
+++ b/packages/contracts/test/exchange/signature_validator.ts
@@ -447,6 +447,24 @@ describe('MixinSignatureValidator', () => {
);
expect(isValidSignature).to.be.false();
});
+
+ it('should return true when message was signed by a Trezor One (firmware version 1.6.2)', async () => {
+ // messageHash translates to 0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b
+ const messageHash = ethUtil.bufferToHex(ethUtil.toBuffer('++++++++++++++++++++++++++++++++'));
+ const signer = '0xc28b145f10f0bcf0fc000e778615f8fd73490bad';
+ const v = ethUtil.toBuffer('0x1c');
+ const r = ethUtil.toBuffer('0x7b888b596ccf87f0bacab0dcb483124973f7420f169b4824d7a12534ac1e9832');
+ const s = ethUtil.toBuffer('0x0c8e14f7edc01459e13965f1da56e0c23ed11e2cca932571eee1292178f90424');
+ const trezorSignatureType = ethUtil.toBuffer(`0x${SignatureType.EthSign}`);
+ const signature = Buffer.concat([v, r, s, trezorSignatureType]);
+ const signatureHex = ethUtil.bufferToHex(signature);
+ const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync(
+ messageHash,
+ signer,
+ signatureHex,
+ );
+ expect(isValidSignature).to.be.true();
+ });
});
describe('setSignatureValidatorApproval', () => {
diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts
index 23577efdc..c18e895f5 100644
--- a/packages/order-utils/src/signature_utils.ts
+++ b/packages/order-utils/src/signature_utils.ts
@@ -347,7 +347,7 @@ export const signatureUtils = {
};
function hashTrezorPersonalMessage(message: Buffer): Buffer {
- const prefix = ethUtil.toBuffer('\x19Ethereum Signed Message:\n' + String.fromCharCode(message.byteLength));
+ const prefix = ethUtil.toBuffer('\x19Ethereum Signed Message:\n' + message.byteLength);
return ethUtil.sha3(Buffer.concat([prefix, message]));
}