Skip to main content

Try it Live

Run Authorization examples in the interactive playground

WASM

WebAssembly bindings for authorization operations.

Overview

WASM bindings provide lightweight access to Zig implementation of authorization operations. These functions offer potential performance benefits for compute-intensive operations. Implementation: TypeScript bindings to Zig authorization.zig via WASM

Functions

validateWasm

Validate authorization structure via WASM.
Parameters:
  • auth: Authorization to validate
Throws: Error if authorization invalid Equivalent to: Authorization.validate.call(auth) but uses WASM implementation

Usage

Implementation

TypeScript Binding:
Zig Implementation:

signingHashWasm

Calculate signing hash via WASM.
Parameters:
  • chainId: Chain ID
  • address: Target address
  • nonce: Nonce
Returns: 32-byte signing hash Equivalent to: Authorization.hash.call({ chainId, address, nonce }) but uses WASM

Usage

Implementation

TypeScript Binding:
Zig Implementation:

authorityWasm

Recover authority (signer) via WASM.
Parameters:
  • auth: Authorization to recover from
Returns: Recovered authority address Throws: Error if recovery fails Equivalent to: Authorization.verify.call(auth) but uses WASM

Usage

Implementation

TypeScript Binding:
Zig Implementation:

gasCostWasm

Calculate gas cost via WASM.
Parameters:
  • authCount: Number of authorizations
  • emptyAccounts: Number of empty accounts
Returns: Gas cost as bigint Equivalent to: Authorization.calculateGasCost.call(authList, emptyAccounts) but uses WASM

Usage

Implementation

TypeScript Binding:
Zig Implementation:

Performance Comparison

JavaScript vs WASM

Typical performance (relative): Note: Actual performance depends on:
  • JavaScript engine
  • WASM runtime
  • Hardware
  • Input size

When to Use WASM

Use WASM for:
  • High-throughput validation
  • Batch processing many authorizations
  • Performance-critical paths
  • Server-side processing
Use JavaScript for:
  • Simple operations
  • One-off validations
  • Browser environments without WASM
  • Debugging (better stack traces)

Usage Patterns

Conditional WASM Usage

Use WASM when available, fallback to JS:

Batch Processing with WASM

Process multiple authorizations efficiently:

Mixed Operations

Combine WASM and JS operations:

Performance Monitoring

Compare WASM vs JS performance:

Error Handling

WASM Errors

WASM functions throw JavaScript errors:

Error Compatibility

WASM errors match JavaScript error messages:

WASM Loading

Automatic Loading

WASM module loads automatically:

Manual Loading

Load WASM explicitly if needed:

Browser Compatibility

WASM Support

Modern browsers support WASM:
  • Chrome 57+
  • Firefox 52+
  • Safari 11+
  • Edge 16+

Feature Detection

Check WASM availability:

Testing

Test WASM Functions

Test JS/WASM Equivalence

Verify WASM produces same results as JS:

Optimization Tips

  1. Batch operations - Process multiple auths in sequence
  2. Reuse WASM module - Module loaded once
  3. Profile first - Measure before optimizing
  4. Consider overhead - WASM call overhead may exceed benefit for simple operations

See Also