Skip to main content

Try it Live

Run Signature examples in the interactive playground

WASM

WebAssembly bindings for signature operations.

Overview

Signature primitive is pure TypeScript without WASM bindings. Cryptographic operations (signing, verification, key recovery) are handled by the crypto module, which provides both native and WASM implementations.

Architecture

Signature Primitive (TypeScript)

The Signature primitive provides:
  • Type definitions (BrandedSignature)
  • Format conversions (compact, DER)
  • Validation (canonicality checking)
  • Component extraction (getR, getS, getV)
Implementation: Pure TypeScript Location: src/primitives/Signature/ No WASM: Signature manipulation doesn’t require WASM

Crypto Module (Zig + WASM)

Cryptographic operations provided by crypto module:
  • Signing (secp256k1, P-256, Ed25519)
  • Verification
  • Public key recovery
  • Key generation
Implementation: Zig with WASM bindings Location: src/crypto/ WASM Available: Yes (via crypto module)

Usage Pattern

Why No WASM for Signature?

Signature Operations Are Fast

Signature primitive operations are simple byte manipulations:
Performance: These operations take microseconds in JavaScript. WASM Overhead: WASM call overhead would be larger than operation cost.

WASM Shines for Crypto Operations

Performance Comparison

Signature Primitive (TypeScript)

OperationTypeScriptWASM (hypothetical)Winner
fromSecp256k10.001ms0.005ms (call overhead)TypeScript
normalize0.005ms0.010ms (call overhead)TypeScript
toDER0.010ms0.015ms (call overhead)TypeScript
isCanonical0.001ms0.005ms (call overhead)TypeScript

Crypto Operations (via crypto module)

OperationTypeScriptWASMWinner
sign0.5ms0.1msWASM (5x)
verify1.0ms0.15msWASM (6.7x)
recover1.5ms0.12msWASM (12.5x)

Integration with Crypto Module

Signing (WASM)

Verification (WASM)

Recovery (WASM)

Complete Example

End-to-End Signature Flow

Crypto Module WASM API

secp256k1 WASM

P-256 WASM

Ed25519 WASM

Build Configuration

Crypto Module WASM Build

Tree-Shaking

Bundle Sizes

Signature Primitive (TypeScript)

Crypto Module WASM

When to Use WASM

Use TypeScript (Signature Primitive)

  • Format conversions (DER, compact)
  • Component extraction (getR, getS, getV)
  • Validation (isCanonical, normalize)
  • Type checking (is, equals)
  • Serialization
Reason: These operations are simple byte manipulations, faster in TypeScript.

Use WASM (Crypto Module)

  • Signing messages
  • Verifying signatures
  • Recovering public keys
  • Key generation
  • Key derivation
Reason: These operations involve expensive elliptic curve arithmetic.

Migration Guide

Before (hypothetical WASM signature primitive)

After (actual TypeScript + crypto WASM)

Benefits:
  • No WASM call overhead for simple operations
  • Synchronous API for signature primitive
  • WASM where it matters (crypto operations)

Browser Support

TypeScript (Signature Primitive)

  • All modern browsers
  • Node.js 14+
  • Deno
  • Bun
No special requirements

WASM (Crypto Module)

  • Chrome 57+
  • Firefox 52+
  • Safari 11+
  • Edge 16+
Feature detection:

See Also