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)
- Namespace API
- Factory API
unsigned: Unsigned authorization to hash
Implementation Details
RLP Encoding:- Encode chainId as compact bigint (remove leading zeros)
- Encode address as 20-byte array
- Encode nonce as compact bigint
- Wrap in RLP list structure
- Prepend MAGIC_BYTE (0x05)
- Apply Keccak-256
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:- Hash unsigned authorization
- Sign hash with secp256k1
- Recover yParity by attempting recovery
- Return Authorization.Item with signature
- Namespace API
- Factory API
unsigned: Authorization to signprivateKey: 32-byte secp256k1 private key
Implementation Details
Signing Process:-
Hash Authorization
-
Sign with secp256k1
-
Convert to bigint
-
Recover yParity
-
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:- Validate authorization structure
- Hash unsigned portion
- Recover public key from signature
- Derive address from public key
- Namespace API
- Factory API
auth: Signed authorization to verify
ValidationError if validation fails or recovery failsExample:Implementation Details
Verification Process:-
Validate Structure
-
Hash Unsigned Portion
-
Convert Signature to Bytes
-
Recover Public Key
-
Derive Address
ECDSA Recovery
Public key recovery uses ECDSA mathematics: Given signature (r, s, v) and message hash h:- Compute point R from r and v
- Compute s_inv = s^-1 mod n
- Recover public key: Q = s_inv * (h * G + r * R)
- Derive address from Q
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
| Operation | Time | Notes |
|---|---|---|
hash | O(1) | RLP encode + keccak256 |
sign | O(1) | secp256k1 signing |
verify | O(1) | Public key recovery |
Optimization Tips
- Cache hashes - Reuse hash if signing same unsigned multiple times
- Batch verification - Process multiple auths together
- Pre-validate - Call validate() before verify() to fail fast
- 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
- Validation - Signature validation
- Constructors - Creating unsigned authorizations
- Processing - Processing signed authorizations
- EIP-7702 - Specification details

