WebAssembly bindings for the PQC Binary Format library, providing a standardized binary format for post-quantum cryptography encrypted data interchange in JavaScript/TypeScript environments.
# Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build for different targets
npm run build # Web (ES modules)
npm run build:nodejs # Node.js
npm run build:bundler # Webpack/Rollup/Parcel- Node.js 16 or higher
- Rust 1.75 or higher
- wasm-pack
import init, {
WasmAlgorithm,
WasmEncParameters,
WasmPqcMetadata,
WasmPqcBinaryFormat,
WasmFormatFlags,
getVersion,
getBinaryVersion
} from './pqc_binary_format.js';
// Initialize WASM module
await init();
// Create algorithm
const algorithm = new WasmAlgorithm('hybrid');
// Create encryption parameters
const encParams = new WasmEncParameters(
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), // IV
new Uint8Array(16) // Auth tag
);
// Create metadata
const metadata = new WasmPqcMetadata(encParams);
// Create PQC Binary Format
const pqcFormat = new WasmPqcBinaryFormat(
algorithm,
metadata,
new Uint8Array([1, 2, 3, 4, 5])
);
// Serialize to bytes
const serialized = pqcFormat.toBytes();
console.log(`Serialized size: ${serialized.length} bytes`);
// Deserialize from bytes
const deserialized = WasmPqcBinaryFormat.fromBytes(serialized);
console.log(`Algorithm: ${deserialized.algorithm.name}`);
console.log(`Data: ${deserialized.data.length} bytes`);
// Validate
deserialized.validate();
console.log('✓ Validation passed');const { WasmAlgorithm, WasmPqcBinaryFormat, ...rest } = require('./pqc_binary_format');
// Same API as web versionInitialize the WASM module. Must be called before using any other functions.
Get library version string.
Get binary format version number.
Algorithm wrapper for WASM.
Constructor: new WasmAlgorithm(name: string)
Supported algorithms: "classical", "hybrid", "post-quantum", "ml-kem-1024", "multi-algorithm", "multi-kem", "multi-kem-triple", "quad-layer", "pq3-stack", "lattice-code-hybrid"
Properties:
name: string- Algorithm nameid: number- Algorithm ID
Static Methods:
supportedAlgorithms(): string[]- Get list of supported algorithm names
Encryption parameters.
Constructor: new WasmEncParameters(iv: Uint8Array, tag: Uint8Array)
Properties:
iv: Uint8Array- IV/noncetag: Uint8Array- Authentication tag
Key encapsulation mechanism parameters.
Constructor: new WasmKemParameters(publicKey: Uint8Array, ciphertext: Uint8Array)
Properties:
publicKey: Uint8Array- Public keyciphertext: Uint8Array- Ciphertext/encapsulated key
Digital signature parameters.
Constructor: new WasmSigParameters(publicKey: Uint8Array, signature: Uint8Array)
Properties:
publicKey: Uint8Array- Public keysignature: Uint8Array- Signature
Compression parameters.
Constructor: new WasmCompressionParameters(algorithm: string, level: number, originalSize: number)
Properties:
algorithm: string- Compression algorithmlevel: number- Compression leveloriginalSize: number- Original size before compression
Metadata container.
Constructor: new WasmPqcMetadata(encParams: WasmEncParameters)
Methods:
setKemParams(kemParams: WasmKemParameters): void- Set KEM parameterssetSigParams(sigParams: WasmSigParameters): void- Set signature parameterssetCompressionParams(compressionParams: WasmCompressionParameters): void- Set compression parameters
Feature flags.
Constructor: new WasmFormatFlags()
Methods:
withCompression(): WasmFormatFlags- Enable compression flagwithStreaming(): WasmFormatFlags- Enable streaming flagwithAdditionalAuth(): WasmFormatFlags- Enable additional auth flagwithExperimental(): WasmFormatFlags- Enable experimental features flaghasCompression(): boolean- Check compression flaghasStreaming(): boolean- Check streaming flaghasAdditionalAuth(): boolean- Check additional auth flaghasExperimental(): boolean- Check experimental features flag
Main PQC binary format class.
Constructor: new WasmPqcBinaryFormat(algorithm: WasmAlgorithm, metadata: WasmPqcMetadata, data: Uint8Array)
Static Methods:
fromBytes(data: Uint8Array): WasmPqcBinaryFormat- Deserialize from byteswithFlags(algorithm: WasmAlgorithm, flags: WasmFormatFlags, metadata: WasmPqcMetadata, data: Uint8Array): WasmPqcBinaryFormat- Create with flags
Methods:
toBytes(): Uint8Array- Serialize to bytesvalidate(): void- Validate format structure (throws on error)totalSize(): number- Get total serialized size
Properties:
algorithm: WasmAlgorithm- Algorithm useddata: Uint8Array- Encrypted dataflags: WasmFormatFlags- Format flags
See example.js for comprehensive examples including:
- Basic encryption format
- Format with KEM parameters
- Format with feature flags
- Algorithm comparison
- Cross-platform interoperability
# Run example (Node.js)
node example.js
# Or in browser
# Serve the directory and open index.htmlTypeScript definitions are automatically generated by wasm-bindgen. Import types as:
import init, {
WasmAlgorithm,
WasmPqcBinaryFormat,
// ... other types
} from './pqc_binary_format';Licensed under either of:
- MIT License
- Apache License, Version 2.0
at your option.