@tectonic-labs/bedrock-wasm
v0.2.0
Published
Bedrock WASM library for post-quantum cryptography
Downloads
113
Readme
@tectonic-labs/bedrock-wasm
WebAssembly bindings for the Bedrock post-quantum cryptography library. Provides quantum-resistant signature schemes for JavaScript/TypeScript applications.
Installation
npm install @tectonic-labs/bedrock-wasmQuick Start
import { initBedrock, FalconScheme } from "@tectonic-labs/bedrock-wasm";
// Initialize the library (loads WASM)
const bedrock = await initBedrock();
// Generate an ETHFALCON keypair
const keypair = bedrock.generateFnDsaKeypair(FalconScheme.ETH_FALCON);
// Sign a message
const message = new TextEncoder().encode("Hello, quantum-safe world!");
const signature = bedrock.signFnDsa(keypair.secret_key, message);
// Verify the signature
const isValid = bedrock.verifyFnDsa(keypair.public_key, signature, message);
console.log("Valid:", isValid); // trueFeatures
- Post-Quantum Signatures: FN-DSA (Falcon) and ML-DSA (Dilithium) NIST-standardized schemes
- Ethereum Integration: ETHFALCON with Solidity-compatible format conversion
- Classical Signatures: ECDSA secp256k1 (Bitcoin/Ethereum compatible)
- HD Wallet: BIP-39 mnemonic with hierarchical deterministic key derivation
- Multi-Platform: Works in browsers, Node.js, bundlers, and browser extensions
- TypeScript: Full type definitions included
Browser Extensions
For browser extensions that need to load WASM from extension URLs:
import { initBedrock } from "@tectonic-labs/bedrock-wasm";
// Option 1: Pre-fetch WASM bytes (recommended)
const wasmBinary = await fetch(browser.runtime.getURL("wasm/bedrock-wasm.wasm")).then((r) =>
r.arrayBuffer()
);
const bedrock = await initBedrock({ wasmBinary });
// Option 2: Custom URL resolver
const bedrock = await initBedrock({
locateFile: (path) => browser.runtime.getURL(`wasm/${path}`)
});Supported Schemes
Post-Quantum Signatures (NIST Standardized)
| Scheme | Type | Security Level | Constant |
| ----------- | ------ | ------------------- | -------------------------- |
| Falcon-512 | FN-DSA | NIST Level 1 | FalconScheme.FALCON_512 |
| Falcon-1024 | FN-DSA | NIST Level 5 | FalconScheme.FALCON_1024 |
| ETHFALCON | FN-DSA | Ethereum-compatible | FalconScheme.ETH_FALCON |
| ML-DSA-44 | ML-DSA | NIST Level 2 | MlDsaScheme.ML_DSA_44 |
| ML-DSA-65 | ML-DSA | NIST Level 3 | MlDsaScheme.ML_DSA_65 |
| ML-DSA-87 | ML-DSA | NIST Level 5 | MlDsaScheme.ML_DSA_87 |
HD Wallet Schemes
| Scheme | Constant |
| --------------- | ------------------------------------ |
| ECDSA secp256k1 | HHDSignatureScheme.ECDSA_SECP256K1 |
| Falcon-512 | HHDSignatureScheme.FALCON512 |
| ML-DSA-44 | HHDSignatureScheme.MLDSA44 |
| ML-DSA-65 | HHDSignatureScheme.MLDSA65 |
| ML-DSA-87 | HHDSignatureScheme.MLDSA87 |
API Reference
Initialization
import { initBedrock } from "@tectonic-labs/bedrock-wasm";
// Standard initialization
const bedrock = await initBedrock();
// With custom WASM loading (browser extensions)
const bedrock = await initBedrock({ wasmBinary: arrayBuffer });
const bedrock = await initBedrock({ locateFile: (path) => customUrl });FN-DSA (Falcon) Operations
import { FalconScheme } from "@tectonic-labs/bedrock-wasm";
// Generate keypair
const keypair = bedrock.generateFnDsaKeypair(FalconScheme.ETH_FALCON);
// Generate from seed (deterministic)
const seed = new Uint8Array(48); // 48-byte seed
const keypair = bedrock.generateFnDsaKeypairFromSeed(FalconScheme.ETH_FALCON, seed);
// Sign message
const signature = bedrock.signFnDsa(keypair.secret_key, message);
// Verify signature
const isValid = bedrock.verifyFnDsa(keypair.public_key, signature, message);ETHFALCON Solidity Format Conversion
Convert keys and signatures to 1024-byte Solidity-compatible format for smart contract interactions:
import { FalconScheme } from "@tectonic-labs/bedrock-wasm";
// Generate ETHFALCON keypair
const keypair = bedrock.generateFnDsaKeypair(FalconScheme.ETH_FALCON);
const signature = bedrock.signFnDsa(keypair.secret_key, message);
// Convert to Solidity format (1024 bytes each)
const solidityPubKey = bedrock.toEthFalconVerifyingKey(keypair.public_key);
const soliditySig = bedrock.toEthFalconSignature(signature);
// Convert to hex for contract calls
const pubKeyHex =
"0x" +
Array.from(solidityPubKey)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
const sigHex =
"0x" +
Array.from(soliditySig)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");ML-DSA (Dilithium) Operations
import { MlDsaScheme } from "@tectonic-labs/bedrock-wasm";
// Generate keypair
const keypair = bedrock.generateMlDsaKeypair(MlDsaScheme.ML_DSA_65);
// Sign message
const signature = bedrock.signMlDsa(keypair.secret_key, message);
// Verify signature
const isValid = bedrock.verifyMlDsa(keypair.public_key, signature, message);Generic API
Auto-detects the scheme from the key format:
// Generate keypair by scheme name
const keypair = bedrock.genericKeypair("ETHFALCON");
// Supported: "FN-DSA-512", "FN-DSA-1024", "ETHFALCON", "ML-DSA-44", "ML-DSA-65", "ML-DSA-87"
// Sign (scheme auto-detected from secret key)
const signature = bedrock.genericSign(keypair.secret_key, message);
// Verify (scheme auto-detected from public key)
const isValid = bedrock.genericVerify(keypair.public_key, signature, message);HD Wallet Operations
import { HHDSignatureScheme } from "@tectonic-labs/bedrock-wasm";
// Generate a new 24-word mnemonic
const mnemonic = bedrock.generateMnemonic();
// Validate a mnemonic
const isValid = bedrock.validateMnemonic(mnemonic);
// Create wallet with specific schemes
const schemes = [HHDSignatureScheme.ECDSA_SECP256K1, HHDSignatureScheme.FALCON512];
// Create new wallet (generates random mnemonic)
const handle = bedrock.hhdWalletNew(schemes);
// Or restore from existing mnemonic
const handle = bedrock.hhdWalletNewFromMnemonic(mnemonic, schemes, optionalPassword);
// Get wallet mnemonic
const mnemonic = bedrock.hhdWalletMnemonic(handle);
// Derive keypairs at index (deterministic)
const ecdsaKeypair = bedrock.hhdWalletDeriveEcdsaSecp256k1Keypair(handle, 0);
const falconKeypair = bedrock.hhdWalletDeriveFnDsa512Keypair(handle, 0);
const mldsaKeypair = bedrock.hhdWalletDeriveMlDsa65(handle, 0);
// Clean up when done (important!)
bedrock.hhdWalletFree(handle);Key Encoding
| Data Type | TypeScript Type | Format |
| -------------------- | ---------------------- | --------------------------------------------- |
| ECDSA keypair | EcdsaKeypair | { public_key, secret_key } (hex strings) |
| Post-quantum keys | PostQuantumKey | { value, scheme } (hex-encoded value) |
| Post-quantum keypair | PostQuantumKeypair | { public_key, secret_key } (PostQuantumKey) |
| Signatures | PostQuantumSignature | { value, scheme } (hex-encoded value) |
| Master seeds | MasterSeeds | { [schemeId]: hexSeed } |
Working with Keys
// Keys are hex-encoded (no 0x prefix)
const keypair = bedrock.generateFnDsaKeypair(FalconScheme.ETH_FALCON);
console.log(keypair.public_key.value); // hex string
console.log(keypair.public_key.scheme); // "ETHFALCON"
// Convert hex to bytes
function hexToBytes(hex) {
const bytes = new Uint8Array(hex.length / 2);
for (let i = 0; i < bytes.length; i++) {
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
}
return bytes;
}
const publicKeyBytes = hexToBytes(keypair.public_key.value);TypeScript
Full type definitions are included:
import {
initBedrock,
BedrockWasm,
FalconScheme,
MlDsaScheme,
HHDSignatureScheme,
// Type interfaces
PostQuantumKey,
PostQuantumKeypair,
PostQuantumSignature,
EcdsaKeypair,
MasterSeeds,
InitBedrockOptions
} from "@tectonic-labs/bedrock-wasm";
const bedrock: BedrockWasm = await initBedrock();
// All methods have proper return types
const keypair: PostQuantumKeypair = bedrock.generateFnDsaKeypair(FalconScheme.ETH_FALCON);
const signature: PostQuantumSignature = bedrock.signFnDsa(keypair.secret_key, message);
const solidityKey: Uint8Array = bedrock.toEthFalconVerifyingKey(keypair.public_key);Environment Support
The package automatically selects the correct build for your environment:
| Environment | Import resolves to |
| ------------------ | ------------------------------------------------------------------ |
| Browser | dist/web/ |
| Bundlers | dist/web/ (via browser export condition) |
| Node.js | dist/nodejs/ |
| Browser Extensions | Use initBedrock({ wasmBinary }) or initBedrock({ locateFile }) |
License
MIT
