This collection of libraries provides simple and safe ways to use different cryptographic primitives.
Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
These functions can be used to verify that a message was signed by the holder of the private keys of a given address.
recover(bytes32 hash, bytes signature) → addressinternal
Returns the address that signed a hashed message (
signature. This address can then be used for verification purposes.
ecrecover EVM opcode allows for malleable (non-unique) signatures:
this function rejects them by requiring the
s value to be in the lower
half order, and the
v value to be either 27 or 28.
(.note) This call does not revert if the signature is invalid, or if the signer is otherwise unable to be retrieved. In those scenarios, the zero address is returned.
hash must be the result of a hash operation for the
verification to be secure: it is possible to craft signatures that
recover to arbitrary addresses for non-hashed data. A safe way to ensure
this is by receiving a hash of the original message (which may otherwise)
be too long), and then calling
toEthSignedMessageHash on it.
toEthSignedMessageHash(bytes32 hash) → bytes32internal
Returns an Ethereum Signed Message, created from a
replicates the behavior of the
These functions deal with verification of Merkle trees (hash trees),
verify(bytes32 proof, bytes32 root, bytes32 leaf) → boolinternal
Returns true if a
leaf can be proved to be a part of a Merkle tree
root. For this, a
proof must be provided, containing
sibling hashes on the branch from the leaf to the root of the tree. Each
pair of leaves and each pair of pre-images are assumed to be sorted.