From 6d7097eed51fe002e43b416f742d39f13fa39153 Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Fri, 23 Feb 2018 16:50:56 -0800 Subject: Add Trezor signatures --- .../protocol/Exchange/MixinSignatureValidator.sol | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'packages') 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); -- cgit v1.2.3