aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-02-24 08:50:56 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit6d7097eed51fe002e43b416f742d39f13fa39153 (patch)
treee143923af4635af1a26c38251baa0fc15fae35b1 /packages/contracts
parent55da59a5370777328feeeb2aad438ed83eb7a8f4 (diff)
downloaddexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.tar
dexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.tar.gz
dexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.tar.bz2
dexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.tar.lz
dexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.tar.xz
dexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.tar.zst
dexon-sol-tools-6d7097eed51fe002e43b416f742d39f13fa39153.zip
Add Trezor signatures
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol23
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
index 0a99168eb..20c9abcb8 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
@@ -31,6 +31,7 @@ contract MixinSignatureValidator is
Caller,
Ecrecover,
EIP712,
+ Trezor,
Contract
}
@@ -107,6 +108,28 @@ contract MixinSignatureValidator is
isValid = signer == recovered;
return isValid;
+ // Signature from Trezor hardware wallet
+ // It differs from web3.eth_sign in the encoding of message length
+ // (Bitcoin varint encoding vs ascii-decimal, the later is not
+ // self-terminating which leads to ambiguities).
+ // See also:
+ // https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
+ // https://github.com/trezor/trezor-mcu/blob/master/firmware/ethereum.c#L602
+ // https://github.com/trezor/trezor-mcu/blob/master/firmware/crypto.c#L36
+ } else if (signatureType == SignatureType.Trezor) {
+ require(signature.length == 66);
+ v = uint8(signature[1]);
+ r = get32(signature, 2);
+ s = get32(signature, 34);
+ recovered = ecrecover(
+ keccak256("\x19Ethereum Signed Message:\n\x41", hash),
+ v,
+ r,
+ s
+ );
+ isValid = signer == recovered;
+ return isValid;
+
// Signature verified by signer contract
} else if (signatureType == SignatureType.Contract) {
isValid = ISigner(signer).isValidSignature(hash, signature);