Add Trezor signatures
This commit is contained in:
committed by
Amir Bandeali
parent
55da59a537
commit
6d7097eed5
@@ -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);
|
||||
|
Reference in New Issue
Block a user