Skip to main content

Try it Live

Run Authorization examples in the interactive playground

Signing & Verification

Authorization hashing, signing, and signature verification.

hash

Calculate signing hash for unsigned authorization. Formula: keccak256(MAGIC_BYTE || rlp([chainId, address, nonce])) Where:
  • MAGIC_BYTE = 0x05 (EIP-7702 identifier)
  • RLP encoding uses compact representation (no leading zeros)
Parameters:
  • unsigned: Unsigned authorization to hash
Returns: 32-byte hash to signExample:

Implementation Details

RLP Encoding:
  1. Encode chainId as compact bigint (remove leading zeros)
  2. Encode address as 20-byte array
  3. Encode nonce as compact bigint
  4. Wrap in RLP list structure
Hashing:
  1. Prepend MAGIC_BYTE (0x05)
  2. Apply Keccak-256
Example:

Why MAGIC_BYTE?

EIP-7702 uses 0x05 to:
  • Prevent cross-protocol replay attacks
  • Distinguish from other signing formats (EIP-191, EIP-712)
  • Ensure unique hash domain

sign

Create signed authorization from unsigned authorization. Process:
  1. Hash unsigned authorization
  2. Sign hash with secp256k1
  3. Recover yParity by attempting recovery
  4. Return Authorization.Item with signature
Parameters:
  • unsigned: Authorization to sign
  • privateKey: 32-byte secp256k1 private key
Returns: Signed Authorization.ItemExample:

Implementation Details

Signing Process:
  1. Hash Authorization
  2. Sign with secp256k1
  3. Convert to bigint
  4. Recover yParity
  5. Return signed authorization

Signature Determinism

secp256k1 signing is deterministic (RFC 6979):
  • Same private key + message always produces same signature
  • Prevents nonce reuse attacks
  • Signatures are reproducible

verify

Recover authority (signer) from authorization signature. Process:
  1. Validate authorization structure
  2. Hash unsigned portion
  3. Recover public key from signature
  4. Derive address from public key
Parameters:
  • auth: Signed authorization to verify
Returns: Recovered signer address (authority)Throws: ValidationError if validation fails or recovery failsExample:

Implementation Details

Verification Process:
  1. Validate Structure
  2. Hash Unsigned Portion
  3. Convert Signature to Bytes
  4. Recover Public Key
  5. Derive Address

ECDSA Recovery

Public key recovery uses ECDSA mathematics: Given signature (r, s, v) and message hash h:
  1. Compute point R from r and v
  2. Compute s_inv = s^-1 mod n
  3. Recover public key: Q = s_inv * (h * G + r * R)
  4. Derive address from Q
The yParity (v) indicates which of two possible points to use.

Complete Signing Flow

Create, Sign, Verify

Signature Security

Private Key Safety

Never expose private keys:

Nonce Management

Use correct nonce to prevent signature reuse:

Chain ID Protection

Always use correct chain ID:

Signature Malleability

sign() automatically creates non-malleable signatures (s ≤ N/2):

Advanced Patterns

Batch Signing

Sign multiple authorizations:

Verify Batch

Verify all signatures and collect authorities:

Pre-compute Hash

Pre-compute signing hash for UI display:

Verify Expected Signer

Verify signature is from expected account:

Performance

Operation Costs

All operations are constant time with respect to input size.

Optimization Tips

  1. Cache hashes - Reuse hash if signing same unsigned multiple times
  2. Batch verification - Process multiple auths together
  3. Pre-validate - Call validate() before verify() to fail fast
  4. Parallel signing - Sign multiple auths in parallel (if private key allows)

Benchmarks

Typical performance (actual values depend on hardware):

Testing

Test Signing & Verification

Test Hash Determinism

See Also