Hedera.Crypto.Secp256k1 (Hedera v0.8.0)

Copy Markdown View Source

secp256k1 helpers for Hedera's ECDSA signature convention: signatures are the 64-byte raw r ‖ s form with s normalized to the lower half of the curve order (low-S, as required by Hedera/Ethereum), and public keys are the 33-byte compressed form on the wire. OpenSSL (via OTP :crypto) produces DER signatures and uncompressed points, which these functions convert.

Summary

Functions

Compress an uncompressed secp256k1 point (0x04 ‖ X ‖ Y) to 33 bytes.

Convert a DER ECDSA signature to canonical 64-byte r ‖ s (low-S).

Convert a canonical 64-byte r ‖ s signature to DER.

Recover the public key point {x, y} from (r, s, z, recid), or :error.

The EIP-1559 recovery id (yParity, 0 or 1) for a signature <<r::256, s::256>> over the 32-byte message hash z, given the signer's public key (33-byte compressed or 65-byte uncompressed). Recovers the public key for each candidate parity and returns the one that reproduces the signer — or :error.

Functions

compress(compressed)

@spec compress(binary()) :: binary()

Compress an uncompressed secp256k1 point (0x04 ‖ X ‖ Y) to 33 bytes.

der_to_raw(other)

@spec der_to_raw(binary()) :: binary()

Convert a DER ECDSA signature to canonical 64-byte r ‖ s (low-S).

raw_to_der(arg)

@spec raw_to_der(binary()) :: binary()

Convert a canonical 64-byte r ‖ s signature to DER.

recover(r, s, z, recid)

@spec recover(integer(), integer(), integer(), 0 | 1) ::
  {integer(), integer()} | :error

Recover the public key point {x, y} from (r, s, z, recid), or :error.

recovery_id(arg, z, public_key)

@spec recovery_id(binary(), binary(), binary()) :: 0 | 1 | :error

The EIP-1559 recovery id (yParity, 0 or 1) for a signature <<r::256, s::256>> over the 32-byte message hash z, given the signer's public key (33-byte compressed or 65-byte uncompressed). Recovers the public key for each candidate parity and returns the one that reproduces the signer — or :error.