Skip to main content

Try it Live

Run Authorization examples in the interactive playground

Validation

Authorization structure and signature validation.

validate

Validate authorization structure and signature parameters.
Parameters:
  • auth: Authorization to validate
Throws: Authorization.ValidationError if invalid Validation Checks:
  1. Chain ID must be non-zero
  2. Address cannot be zero address
  3. yParity must be 0 or 1
  4. Signature r must be non-zero
  5. Signature s must be non-zero
  6. r must be < SECP256K1_N (curve order)
  7. s must be ≤ SECP256K1_HALF_N (prevents malleable signatures)

Basic Usage

Validation Errors

ValidationError

Error Messages:
  • "Chain ID must be non-zero" - chainId is 0
  • "Address cannot be zero address" - address is 0x0000…0000
  • "yParity must be 0 or 1" - yParity not 0 or 1
  • "Signature r cannot be zero" - r is 0
  • "Signature s cannot be zero" - s is 0
  • "Signature r must be less than curve order" - r >= SECP256K1_N
  • "Signature s too high (malleable signature)" - s > SECP256K1_HALF_N

Validation Rules

Chain ID

Chain ID must be non-zero to indicate which chain authorization is valid on.
Rationale: Zero chain ID is reserved and indicates invalid authorization.

Zero Address

Address cannot be zero address (0x0000…0000).
Rationale: Zero address has no code and delegation would be meaningless.

yParity

yParity must be 0 or 1 (ECDSA signature parity bit).
Rationale: ECDSA signatures have two possible y-coordinates (even/odd). yParity indicates which.

Signature r

Signature r must be non-zero and less than curve order.
Rationale: r is ECDSA signature component and must be in valid range [1, N-1].

Signature s

Signature s must be non-zero and at most SECP256K1_HALF_N.
Rationale: Restricting s ≤ N/2 prevents signature malleability. For any valid signature (r, s), there exists another valid signature (r, -s mod N). Requiring s ≤ N/2 ensures only one canonical signature.

Malleability Prevention

What is Signature Malleability?

ECDSA signatures have inherent malleability: given valid signature (r, s), signature (r, N - s) is also valid for same message. Without malleability protection:

Protection

validate() rejects high s values:

Normalizing High s

If you receive signature with high s, normalize it:

Validation Patterns

Validate Before Processing

Always validate before any operations:

Batch Validation

Validate entire authorization list:

Early Validation

Validate as soon as authorization is received:

Validation with Type Guards

Combine type guards with validation:

Error Handling

Handle specific validation errors:

Performance

Validation Cost

Validation is O(1) with constant-time checks:

Optimization

Validation is already optimized. For batch validation, consider:

Testing

Valid Authorization

Invalid Cases

See Also