numeric.py 499 B

1234567891011121314151617
  1. from eth_keys.constants import (
  2. SECPK1_N,
  3. )
  4. def int_to_byte(value: int) -> bytes:
  5. return bytes([value])
  6. def coerce_low_s(value: int) -> int:
  7. """
  8. Coerce the s component of an ECDSA signature into its low-s form.
  9. See https://bitcoin.stackexchange.com/questions/83408/in-ecdsa-why-is-r-%E2%88%92s-mod-n-complementary-to-r-s # noqa: E501
  10. or https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.md.
  11. """ # blocklint: pragma
  12. return min(value, -value % SECPK1_N)