Ethereum authorization primitives

This no_std, allocation-free crate composes the existing hash and secp256k1 families for ordinary Ethereum message authorization. It performs no IC calls, JSON parsing, network access or ambient random generation. Applications own their exact EIP-712 schema, permissions, lifetime, nonce and replay policy.

  • Address and Word are fixed 20-byte and 32-byte arrays.
  • address_from_public_key validates a compressed or uncompressed SEC1 point, hashes its uncompressed X/Y bytes with Ethereum Keccak-256, and returns the final twenty bytes. The SEC1 0x04 prefix is not hashed.
  • word_u64, word_u128, word_address and word_bool produce standard ABI words. Integers are big-endian and left zero padded; bytes32 values already have the required word representation.
  • hash_words streams exact words without concatenation. For hashStruct, pass the schema's type hash first. Dynamic bytes/string fields use their Keccak hashes; nested structs use their own struct hash.
  • eip712_digest implements Keccak-256 of 0x1901 || domain || struct_hash. Callers must construct and authenticate the expected domain themselves.
  • verify_prehash_with_public_key accepts exactly 64 compact r || s bytes, requires canonical nonzero in-range scalars and low S, validates the supplied SEC1 public-key hint, and checks both the derived expected Ethereum address and the standard ECDSA equation using RSX's existing verifier.

The public-key hint is not trusted authority. A browser can recover it locally from a MetaMask signature, but the verifier still derives/checks the expected address and verifies the signature over the application's reconstructed digest. Changing a signature, key, address or signed digest cannot reuse an accepted result: no verification cache exists. This avoids a separate backend recovery operation without changing the standard ECDSA equation.

RsvSignature::from_bytes is a separate parser for wallet-returned 65-byte r || s || v, accepting only v = 0/1 or 27/28 and normalizing it to parity. It checks scalar/low-S syntax, not the recovery equation. Its parity is for local recovery; the backend hint verifier does not accept RSV input. EIP-155 transaction v values, EIP-2098 compact signatures and experimental explicit-R encodings are distinct formats and are rejected by this parser.

Standards and validation

The format follows EIP-712. The crate does not implement smart-contract wallet EIP-1271 validation, an EVM, a wallet SDK or application session management. Ethereum Keccak-256 cannot be replaced with SHA3-256 or BLAKE3. Existing low-S policy and exact SEC1 validation remain authoritative; high-S input is rejected rather than silently normalized.

Module tests reconstruct the standard Ether Mail example and check its known domain/struct/final hashes. Three independent standard signature vectors use public deterministic keys 1, 2 and 17, generated with @noble/curves = 2.4.0 and @noble/hashes = 2.4.0 (prehash: false, lowS: true). Their recorded public inputs are in provenance/vectors.json; no application secrets occur. Tests also cover exact word layout, compressed/uncompressed points, wrong address/key/digest/signature, invalid points/scalars/lengths, high S, supported and invalid v values, and separation of parsing from recovery verification.

This is a composition of existing cryptography, not a new signature scheme. Native vectors do not establish IC instruction costs or application security.