╭╯ ECDSA256
Introduction
This library provides functionality for ECDSA verification over any 256-bit curve.
For more information about the logic behind the contract implementation, please refer to the OpenZeppelin documentation, particularly the verifySolidity function.
Functions
To use the ECDSA256 library, you need to import it.
import "@solarity/solidity-lib/libs/crypto/ECDSA256.sol";
And optionally bind it to the type with the using statement.
using ECDSA256 for *;
verify
function verify(
EC256.Curve memory ec,
bytes32 hashedMessage_,
bytes memory signature_,
bytes memory pubKey_
) internal view returns (bool);
Description
The function to verify the ECDSA signature.
Parameters:
| Name | Type | Description |
|---|---|---|
ec | struct EC256.Curve | The 256-bit curve parameters |
hashedMessage | bytes32 | The already hashed message to be verified |
signature | bytes | The ECDSA signature. Equals to bytes(r) + bytes(s) |
pubKey | bytes | The full public key of a signer. Equals to bytes(x) + bytes(y). Note that signatures only from the lower part of the curve are accepted. If your s > n / 2, change it to s = n - s |
Example
function verifySECP256r1(
bytes memory message_,
bytes memory signature_,
bytes memory pubKey_
) external view returns (bool) {
EC256.Curve memory curveParams_ =
EC256.Curve({
a: 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC,
b: 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B,
gx: 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296,
gy: 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5,
p: 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF,
n: 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551
});
return curveParams_.verify(sha256(message_), signature_, pubKey_);
}