TAP-WASM
Lightweight WebAssembly bindings for the Transaction Authorization Protocol (TAP), focusing on cryptographic operations that cannot be performed natively in JavaScript.
Features
- Cryptographic Operations Only: Focused on signing/verification that requires WASM
- DIDComm v2 Support: Pack and unpack messages with JWS signatures
- Multiple Key Types: Ed25519, P-256, and secp256k1 support
- TypeScript Ready: Full type definitions included
- Optimized Size: Minimal API surface for smaller bundles (~272KB gzipped)
Purpose
The TAP WASM module provides a minimal set of cryptographic operations for TAP messages:
- Key Management: Generate, import, and export cryptographic keys
- Message Signing: Pack messages with DIDComm v2 JWS signatures
- Signature Verification: Unpack and verify signed messages
Message creation, structuring, and business logic are handled by the TypeScript SDK (@taprsvp/agent), keeping the WASM bundle focused and small.
Installation
For most users, install the TypeScript SDK which includes the WASM module:
For direct WASM usage (advanced):
Basic Usage
TypeScript/JavaScript (Recommended)
Use the TypeScript SDK for a complete TAP implementation:
import from '@taprsvp/agent';
;
Direct WASM Usage (Advanced)
For direct WASM usage without the TypeScript SDK:
import init from 'tap-wasm';
;
API Reference
WasmTapAgent
The core WASM agent providing cryptographic operations.
Creation
// Create with auto-generated keys
const agent = ;
// Create from existing private key
const agent = await ;
Key Management
// Get agent's DID
const did = agent.;
// Export keys
const privateKey = agent.; // Hex string
const publicKey = agent.; // Hex string
// Get nickname
const nickname = agent.; // Optional string
Message Operations
// Pack (sign) a message
const packedResult = await agent.;
// Returns: { message: string, metadata: {...} }
// Unpack (verify) a message
const unpacked = await agent.;
// Returns: { id, type, from, to, body, ... }
Utility Functions
import from 'tap-wasm';
// Generate UUID
const uuid = ;
// Generate private key
const privateKey = ; // Returns hex string
Key Types
Supported cryptographic key types:
- Ed25519: Fast, secure, recommended for most use cases
- P256: NIST standard, good compatibility
- Secp256k1: Bitcoin/Ethereum compatible
Integration with TypeScript SDK
The TypeScript SDK (@taprsvp/agent) provides:
- Message creation and structuring
- Type safety and validation
- DID resolution
- Business logic
While WASM provides:
- Cryptographic key operations
- Message signing (pack)
- Signature verification (unpack)
This separation keeps the WASM bundle small while providing a complete TAP implementation.
Building from Source
# Clone repository
# Build WASM
# Output in pkg/ directory
Performance
- WASM module: ~272KB gzipped
- Pack operation: < 5ms typical
- Unpack operation: < 5ms typical
- Key generation: < 2ms typical
License
MIT License