Xlink: Secure Machine-to-Machine
APIs have keys. ACIs have identity. Xlink is an Authenticated Cryptographic Interface — one-time identity setup replaces ongoing key rotation, gateway configuration, and middleware management. Post-quantum hybrid cryptographic identity (Ed25519 + ML-KEM-768 always-on, ML-DSA-65 opt-in) + encrypted envelopes + optional information-theoretic split-channel. Zero npm dependencies.
Executive Summary
Xlink gives every AI agent, microservice, and IoT device a cryptographic identity and a way to exchange messages that are encrypted, signed, and replay-protected — in under 50 lines of code.
Two functions cover 80% of use cases: Agent.create() generates an Ed25519 + X25519 identity with hybrid post-quantum key exchange (X25519 + ML-KEM-768, always-on) and registers it with a trust registry. agent.send() encrypts a payload with AES-256-GCM, signs it with Ed25519 (+ ML-DSA-65 when postQuantumSig: true), and delivers it via any transport adapter. The receiver verifies signatures, checks replay protection, validates scope, and decrypts — automatically.
When you need information-theoretic security, split-channel mode shards messages via XorIDA (threshold sharing over GF(2)) and routes each share independently. An attacker who compromises any single channel learns nothing about the plaintext — not computationally hard to break, but mathematically impossible.
Zero configuration out of the box. Zero npm runtime dependencies. Runs anywhere the Web Crypto API is available — Node.js, Deno, Bun, Cloudflare Workers, browsers. Dual ESM and CJS builds ship in a single package.
The Problem
Machine-to-machine security today is a patchwork of API keys, OAuth client credentials, mTLS certificates, and API gateways — each with its own rotation schedule, configuration surface, and failure modes.
API keys leak. They end up in logs, git commits, environment variables shared over Slack, and CI pipelines with overly broad access. Rotation means touching every service that holds the key — a manual, error-prone process.
OAuth is complex. Client credentials flow requires token endpoints, scopes, refresh logic, and revocation. Every new service needs a registration, a secret, and a grant configuration.
mTLS certs expire. Certificate lifecycle management is a full-time job. Renewal failures cause outages. CA compromise is a single point of failure for the entire mesh.
Gateways add latency and cost. Centralized API gateways become bottlenecks, introduce single points of failure, and charge per-request fees that scale with traffic.
| Property | API Keys | OAuth 2.0 | mTLS | Xlink |
|---|---|---|---|---|
| Initial setup | Minutes | Hours | Days | 5 lines |
| Key rotation | Manual | Token refresh | Cert renewal | Never* |
| E2E encryption | No | No | Transport only | Yes |
| Forward secrecy | No | No | Optional | Auto ECDH |
| Non-repudiation | No | No | No | Ed25519 + ML-DSA-65 |
| Replay prevention | No | Partial | Partial | Nonce store |
| Info-theoretic mode | No | No | No | XorIDA split |
| npm dependencies | Varies | 10-50+ | OS-level | 0 |
* Ed25519 identity keys are permanent. No expiry, no renewal. New identity = new DID. See Limitations for details.
The Old Way
The New Way
Real-World Use Cases
Six scenarios where Xlink replaces traditional API key management with Authenticated Cryptographic Interfaces.
Each sensor gets a deterministic identity from a factory-burned seed. Signed telemetry envelopes flow to gateways. No API keys to rotate across 10,000 devices.
Agent.fromSeed() + createSignedEnvelope()AI agents negotiate tasks via encrypted envelopes with scope-based authorization. The orchestrator verifies each agent’s identity before dispatching work.
Agent.create() + agent.send() + scopesServices authenticate via DID instead of shared secrets. ECDH forward secrecy protects inter-service traffic. No certificate authority to manage.
HttpsTransportAdapter + MemoryTrustRegistryPHI travels via split-channel — any single intercepted channel reveals zero patient data. HIPAA compliance by mathematical guarantee, not policy alone.
splitChannel: true + 2-of-3 thresholdOrder routing with non-repudiation. Ed25519 signatures provide cryptographic proof of trade instructions. Timestamp validation prevents replay attacks.
Ed25519 non-repudiation + 30s windowSplit-channel with 3-of-5 threshold across classified and unclassified networks. Information-theoretic security exceeds AES-256 — quantum-proof by construction.
splitChannelConfig: { totalShares: 5, threshold: 3 }Solution Architecture
Six composable modules. Each can be used independently or combined through the high-level Agent ACI.
The One-Time Setup
Five lines of code. No configuration files, no gateway dashboards, no certificate authorities.
import { Agent, MemoryTrustRegistry, HttpsTransportAdapter } from '@xail/agent-sdk'; const registry = new MemoryTrustRegistry(); const transport = new HttpsTransportAdapter({ baseUrl: 'https://api.example.com' }); const agent = (await Agent.create({ name: 'MyService', registry, transport })).value!; // That's it. agent.did is your identity. agent.send() encrypts + signs + delivers. await agent.send({ to: recipientDid, payload: { action: 'hello' }, scope: 'chat' });
Forward Secrecy
Hybrid post-quantum key agreement: X25519 ECDH + ML-KEM-768 KEM (always-on for v2+ agents). Ephemeral key pairs provide forward secrecy.
The sender generates a fresh ephemeral X25519 key pair per message. The shared secret is derived from the sender's ephemeral private key and the recipient's static X25519 public key. The ephemeral public key is included in the envelope so the receiver can derive the same shared secret.
Compromise of long-term keys does not reveal past messages. Each message uses a unique shared secret derived from a unique ephemeral key pair. Past messages are protected even if both parties' long-term keys are later compromised.
Split-Channel Mode
Information-theoretic security via XorIDA threshold secret sharing. One-line opt-in.
When splitChannel: true is set on agent.send(), the plaintext is split into N shares (default 3) using XorIDA over GF(2), with a reconstruction threshold of K (default 2). Each share is independently encrypted, signed, and transmitted via separate channels.
await agent.send({ to: recipientDid, payload: { secret: 'classified-data' }, scope: 'secure', splitChannel: true, splitChannelConfig: { totalShares: 3, threshold: 2 }, });
Identity & Persistence
Ed25519 signing + X25519 key agreement via Web Crypto API. Hybrid post-quantum: ML-KEM-768 for key exchange (always-on), ML-DSA-65 for signatures (opt-in). Multiple persistence strategies for different environments.
DID:key Format
Each agent identity is encoded as a did:key DID string: did:key:z6Mk.... The DID embeds the raw Ed25519 public key with a multicodec prefix (0xed01) and base58btc encoding. Anyone with the DID can verify signatures without a network lookup.
Persistence Strategies
Complete Flow
End-to-end: identity creation through message delivery and verification.
Sender Pipeline
1. Agent.create() generates Ed25519 + X25519 keys (+ ML-DSA-65 keys when postQuantumSig: true) and registers with the trust registry.
2. agent.send() resolves the recipient DID from the registry.
3. Hybrid key exchange: X25519 ECDH + ML-KEM-768 KEM, combined via HKDF-SHA256 (always-on for v2+ agents). SHA-256 fallback for v1 peers.
4. Payload encrypted with AES-256-GCM (12-byte IV, fresh per message).
5. Ciphertext signed with Ed25519 (+ ML-DSA-65 dual signature in v3 envelopes).
6. Envelope assembled: v2/v3, sender DID, recipient DID, timestamp, nonce, scope, payload, signature(s), ephemeralPub, kemCiphertext.
7. Transport adapter delivers the envelope.
Receiver Pipeline
8. agent.receive() validates envelope version (v1/v2/v3) and algorithm.
9. Timestamp checked against configurable window (default 30s).
10. Nonce checked against NonceStore — rejects duplicates (replay prevention).
11. Sender DID resolved from trust registry — must be registered and not revoked.
12. Ed25519 signature verified. ML-DSA-65 signature also verified if present (v3 envelopes).
13. Sender's scope validated against the claimed scope in the envelope.
14. Shared key derived via hybrid KEM (X25519 + ML-KEM-768) or SHA-256 fallback for v1.
15. Payload decrypted with AES-256-GCM.
16. JSON parsed and returned as AgentMessage.
Integration Patterns
Four patterns for different deployment contexts.
Express Middleware
import express from 'express'; const app = express(); // Verify incoming agent envelopes app.post('/api/messages', agent.middleware(), (req, res) => { const msg = req.agentMessage; console.log('From:', msg.sender, 'Scope:', msg.scope); res.json({ ok: true }); });
Registry Auth Middleware
import { createRegistryAuthMiddleware } from '@xail/agent-sdk'; // GET /registry/resolve/:did → public (no auth) // POST /registry/register → requires Bearer token app.use('/registry', createRegistryAuthMiddleware(process.env.REGISTRY_ADMIN_TOKEN));
IoT Composable Pattern
import { generateIdentity, createSignedEnvelope, splitForChannel } from '@xail/agent-sdk'; const id = (await generateIdentity()).value!; const reading = new TextEncoder().encode(JSON.stringify({ temp: 22.5 })); // Signed-only envelope (no encryption, integrity-only) const envelope = await createSignedEnvelope({ senderDid: id.did, recipientDid: gatewayDid, scope: 'telemetry', plaintext: reading, privateKey: id.privateKey, }); // Or split across channels for redundancy const shares = await splitForChannel(reading, { totalShares: 3, threshold: 2 });
Signed-Only Telemetry
// Gateway accepts both encrypted and signed-only envelopes const msg = await gateway.receive(envelope, { allowCleartext: true }); if (msg.ok) { console.log(msg.value.payload); // works for both modes }
Security Properties
Seven layers of defense. Each independently verifiable.
| Property | Mechanism | Guarantee |
|---|---|---|
| Confidentiality | AES-256-GCM per message | Payload encrypted in transit and at rest |
| Authentication | Ed25519 + ML-DSA-65 (dual) | Sender identity verified on every envelope (PQ-safe with opt-in) |
| Integrity | Encrypt-then-sign | Any modification fails verification |
| Non-repudiation | Ed25519 + ML-DSA-65 dual signature | Sender cannot deny sending (quantum-safe with opt-in) |
| Forward secrecy | X25519 + ML-KEM-768 hybrid | Post-quantum forward secrecy (always-on) |
| Replay prevention | Nonce store + timestamp | Duplicate envelopes rejected |
| Info-theoretic | XorIDA split-channel | K-1 shares reveal zero bits |
Supply Chain Security
Zero npm runtime dependencies. The SDK depends only on workspace packages (@xail/shared, @xail/crypto) which are part of the same monorepo. No third-party code executes at runtime. This eliminates the entire class of supply chain attacks from compromised npm packages.
Comparison to Alternatives
| Property | Xlink | TLS | Signal Protocol |
|---|---|---|---|
| E2E encryption | Yes | Transport only | Yes |
| Forward secrecy | Yes (Hybrid PQ KEM) | Yes (DHE) | Yes (Ratchet) |
| Info-theoretic | Yes (XorIDA) | No | No |
| Non-repudiation | Ed25519 + ML-DSA-65 | No | No |
| Replay prevention | Nonce store | Seq numbers | Chain keys |
| Zero npm deps | Yes | N/A | No |
| M2M focused | Yes | General | Person-to-person |
Benchmarks
Performance characteristics measured on Node.js 22, Apple M2.
| Operation | Time | Notes |
|---|---|---|
| Ed25519 keygen | <1ms | Web Crypto API native |
| X25519 keygen | <1ms | Web Crypto API native |
| ECDH key agreement | <1ms | Ephemeral + derive |
| AES-256-GCM encrypt (1KB) | <0.5ms | Hardware-accelerated |
| Ed25519 sign | <0.5ms | Covers ciphertext bytes |
| Full send pipeline (Xchange) | ~1ms | Random key + encrypt + XorIDA split + sign |
| Full receive pipeline (Xchange) | ~1ms | Verify + reconstruct + HMAC + decrypt |
| XorIDA split (1MB, 3 shares) | ~52ms | GF(2) — 15x faster than Shamir's at 1MB |
| XorIDA reconstruct (1MB) | ~33ms | Including HMAC verification |
| Nonce check (memory) | <0.1ms | Map lookup + TTL check |
XorIDA vs AES-256-GCM — API Payload Performance
Typical ACI traffic — auth tokens, JSON responses, webhooks, chat messages — is under 1 KB. At these sizes, XorIDA’s simple XOR-only arithmetic completes a full split-and-reconstruct roundtrip 2–11× faster than AES-256-GCM can encrypt-and-decrypt, while providing strictly stronger (information-theoretic) security.
256-Byte Roundtrip — Visual Comparison
Shorter bar = faster. 256B payload, 2,000 iterations, median roundtrip time.
Full Comparison — API Payload Sizes
| Payload | XorIDA 2-of-2 | XorIDA 2-of-3 | AES-256-GCM | Ratio (2-of-2) | Real-World Example |
|---|---|---|---|---|---|
| 64B | 14µs | 17µs | 160µs | 11.4× faster | IoT sensor reading, heartbeat |
| 128B | 23µs | 26µs | 160µs | 7.0× faster | Auth token, session ticket |
| 256B | 35µs | 41µs | 122µs | 3.5× faster | Chat message, SMS-length payload |
| 512B | 34µs | 39µs | 138µs | 4.0× faster | Webhook, API key exchange |
| 1KB | 58µs | 107µs | 140µs | 2.4× faster | REST API JSON response |
| 2KB | 211µs | 262µs | 142µs | 1.5× slower | GraphQL response |
| 4KB | 340µs | 313µs | 134µs | 2.5× slower | Large API response |
| 8KB | 644µs | 883µs | 227µs | 2.8× slower | Crossover zone |
Node.js 22 • 2,000 iterations per size • Median roundtrip (split+reconstruct / encrypt+decrypt)
Xlink vs Competitors — API Crypto Overhead
Full send + receive roundtrip measured end-to-end with real crypto operations. Competitor estimates use our measured primitive timings (same algorithms, same JS runtime) as reference. Xlink uses split-channel (2-of-3); competitors use single-channel delivery.
256-Byte API Payload — Full Roundtrip
Shorter bar = faster. 256B payload, 200 iterations, median roundtrip time.
Full Comparison — All API Payload Sizes
| Payload | Xlink | Tuta | Signal | Apple PQ3 | Use Case |
|---|---|---|---|---|---|
| 64B | 2.0ms | 4.2ms | 5.0ms | 5.0ms | Auth token, session ID |
| 128B | 1.8ms | 4.2ms | 5.0ms | 5.0ms | Webhook notification |
| 256B | 1.9ms | 4.2ms | 5.0ms | 5.0ms | Small JSON response |
| 512B | 1.8ms | 4.2ms | 5.0ms | 5.0ms | API request body |
| 1KB | 1.9ms | 4.2ms | 5.0ms | 5.0ms | Large JSON / config |
| 2KB | 1.9ms | 4.2ms | 5.0ms | 5.0ms | Batch API response |
| 4KB | 2.5ms | 4.2ms | 5.0ms | 5.0ms | Document payload |
| 8KB | 3.7ms | 4.3ms | 5.1ms | 5.1ms | Rich API response |
Node.js 22 • 200 iterations per size • Median send+receive roundtrip • 2-of-3 split
Crypto Overhead as % of Total API Latency (256B)
| Network Latency | Xlink | Tuta | Signal |
|---|---|---|---|
| Local (1ms) | 65.9% | 80.8% | 83.3% |
| Regional (10ms) | 16.2% | 29.6% | 33.3% |
| Cross-region (50ms) | 3.7% | 7.7% | 9.1% |
| Global (150ms) | 1.3% | 2.7% | 3.2% |
Lower % = less crypto tax on your API calls. At 10ms+ latency, Xlink overhead is negligible.
Security vs Performance
Ranked by roundtrip speed at 256B. Xlink is the fastest system with post-quantum protection—and the only one providing information-theoretic security.
| # | System | Roundtrip | Security Model | PQ Protection |
|---|---|---|---|---|
| 1 | Xlink | 1.9ms | Information-theoretic | ✓ Unconditional |
| 2 | Tuta | 4.2ms | Computational | ✓ Kyber KEM only |
| 3 | Signal | 5.0ms | Hybrid computational | ✓ Kyber KEM only |
| 4 | Apple PQ3 | 5.0ms | Hybrid computational | ✓ Kyber KEM only |
Honest Limitations
Eight known limitations documented transparently. No product is perfect — here is what Xlink does not do.
| Limitation | Impact | Mitigation |
|---|---|---|
| Cleartext headers | Sender/recipient DIDs, scope, timestamp visible to network observers. Traffic analysis possible. | Payload is encrypted. Use TLS for transport-level protection of headers. |
| No push revocation | Revoked agents' in-flight messages may be processed before receiver re-checks registry. | Keep timestamp windows short (default 30s). |
| No key rotation | Ed25519 identity keys are permanent. No built-in rotation protocol. | Create new identity and re-register. Old DID becomes unused. |
| SHA-256 fallback | When ECDH unavailable, shared key is deterministic. Not forward-secret. | Ensure both parties publish X25519 keys for automatic ECDH upgrade. |
| Ephemeral nonce store | MemoryNonceStore clears on process restart. Replays within timestamp window succeed. | Use RedisNonceStore for production deployments. |
| Clock dependency | Timestamp validation assumes synchronized clocks. Large skew causes false rejections. | Use NTP. Increase timestampWindowMs for high-latency networks. |
| No payload size limits | SDK does not enforce maximum payload size. Large payloads can exhaust memory. | Validate payload size at application layer before calling send(). |
| Registry trust | Compromised registry can substitute public keys or modify scopes. | Use createRegistryAuthMiddleware() with bearer token auth on writes. |
Post-Quantum Security
Xlink is end-to-end post-quantum. XorIDA payload splitting is information-theoretically quantum-safe. Key exchange uses hybrid X25519 + ML-KEM-768 (always-on, FIPS 203). Signatures use dual Ed25519 + ML-DSA-65 (opt-in via postQuantumSig: true, FIPS 204). All three cryptographic layers — payload, key exchange, and authentication — have quantum-safe implementations deployed.
Two Security Layers
The Xlink architecture has two distinct cryptographic layers with different quantum profiles:
| Layer | Current | Quantum Status | Upgrade Path |
|---|---|---|---|
| Payload (XorIDA) | GF(2) threshold sharing | Quantum-safe now | No change needed |
| Symmetric encryption | AES-256-GCM | Quantum-safe now | No change needed |
| Key establishment | X25519 + ML-KEM-768 (hybrid) | Hybrid PQ — Phase 1 live | Phase 1 deployed (v2 envelopes) |
| Identity / signatures | Ed25519 + ML-DSA-65 (dual) | Hybrid PQ — Phase 2 deployed (opt-in) | Phase 2 deployed (v3 envelopes) |
Migration Strategy
The upgrade follows a three-phase hybrid-first approach. Each phase maintains backward compatibility with the previous one.
Algorithm Profile
| Function | Algorithm | Standard | Key / Sig Size |
|---|---|---|---|
| KEM (Phase 1+) | ML-KEM-768 | FIPS 203 | 1,184 B pub / 1,088 B ct |
| Hybrid KEM | X25519 + ML-KEM-768 | IETF draft | HKDF over both shared secrets |
| Signature (Phase 2, deployed) | ML-DSA-65 | FIPS 204 | 1,952 B pub / 3,309 B sig |
| Symmetric | AES-256-GCM | NIST SP 800-38D | Unchanged |
| Payload splitting | XorIDA GF(2) | Patent-protected | Unchanged |
Latency Impact
Post-quantum operations add minimal computational overhead. The dominant latency remains network I/O, not cryptography.
| Operation | Current (Classical) | Hybrid (Phase 1) | Delta |
|---|---|---|---|
| Key exchange | <0.1ms (X25519) | ~0.3ms (X25519 + ML-KEM) | +0.2ms |
| Sign | <0.1ms (Ed25519) | ~1.1ms (Ed25519 + ML-DSA) | +1.0ms |
| Verify | <0.2ms (Ed25519) | ~0.7ms (Ed25519 + ML-DSA) | +0.5ms |
| Full handshake | ~0.4ms | ~2.1ms | +1.7ms |
| Envelope overhead | ~128 bytes | ~6,340 bytes | +6.1 KB |
Envelope Version
The envelope format uses a v2 version tag signaling hybrid PQ support. Agents negotiate capabilities automatically:
- v1 agents communicate using classical crypto (X25519-only ECDH)
- v2 agents communicate using hybrid PQ + classical crypto (X25519 + ML-KEM-768)
- v2 agents automatically fall back to v1 when communicating with v1 peers
- v3 agents add dual signatures (Ed25519 + ML-DSA-65) — deployed, opt-in via
postQuantumSig: true
postQuantumSig: true).
Protocol Security Stack
The Xlink protocol secures messages at three independent cryptographic layers. Each layer addresses a different threat surface. Together, they provide full-stack quantum safety with no single point of cryptographic failure.
Three-Layer Architecture
| Layer | Function | Algorithm | Standard | Quantum Status |
|---|---|---|---|---|
| Payload | Message confidentiality | XorIDA threshold sharing over GF(2) | Proprietary (patented) | Immune |
| Key Exchange | Session key establishment | X25519 + ML-KEM-768 (hybrid) | FIPS 203 | Quantum-safe |
| Authentication | Identity verification & integrity | Ed25519 + ML-DSA-65 (dual) | FIPS 204 | Quantum-safe |
Layer 1 — Payload (Information-Theoretic)
XorIDA splits the plaintext into threshold shares using XOR operations over GF(2). Each share is individually indistinguishable from random noise. No computation — classical or quantum — can extract information from fewer than k shares. This is not computational hardness; it is a mathematical proof. The payload layer is immune to harvest-now-decrypt-later attacks because there is no key to break, no structure to exploit, and no algorithm that reduces the problem.
Layer 2 — Key Exchange (Hybrid Post-Quantum KEM)
Session keys are established using a hybrid key encapsulation mechanism: classical X25519 ECDH combined with ML-KEM-768 (FIPS 203, formerly CRYSTALS-Kyber). Both shared secrets are combined via HKDF-SHA256 to derive the session key. The session key is secure as long as either X25519 or ML-KEM-768 remains unbroken — defense in depth. Hybrid KEM is live in v2 envelopes (Phase 1, deployed).
Layer 3 — Authentication (Dual Signatures)
Message authentication and sender identity use dual signatures: classical Ed25519 plus post-quantum ML-DSA-65 (FIPS 204). Both signatures must verify for the message to be accepted. ML-DSA-65 signatures are opt-in via postQuantumSig: true in the agent configuration. When enabled, v3 envelopes carry both signatures. Classical-only agents continue to work with v1/v2 envelopes.
Envelope Version Progression
- v1 — Classical only. X25519 ECDH key exchange, Ed25519 signatures.
- v2 — Hybrid PQ KEM. X25519 + ML-KEM-768 key exchange, Ed25519 signatures. Backward-compatible with v1 peers.
- v3 — Full PQ. Hybrid KEM + dual signatures (Ed25519 + ML-DSA-65). Backward-compatible with v1/v2 peers.
Agents negotiate capabilities automatically. A v3 agent communicating with a v1 peer falls back to v1 envelope format. No developer action required — the protocol handles version negotiation internally.
postQuantumSig: true, all three cryptographic layers are quantum-safe. The payload is information-theoretically immune. Key exchange uses hybrid PQ KEM (FIPS 203). Authentication uses dual PQ signatures (FIPS 204). All 68 ACIs inherit this protection by updating one dependency.
Implementation Details
Deep-dive into error handling, trust registry, nonce store, transport adapters, and the complete ACI surface.
Error Hierarchy
Typed error classes for structured error handling. Supplementary to the Result<T,E> string code pattern.
XlinkError // Base class (code, subCode, docUrl) ├── XlinkIdentityError // Ed25519/X25519 keygen, sign, verify, DID ├── XlinkEnvelopeError // Envelope create, encrypt, decrypt, parse ├── XlinkTransportError // Send failures, network, timeouts ├── XlinkRegistryError // Lookup, registration, revocation ├── XlinkKeyAgreementError // X25519 ECDH derivation ├── XlinkSplitChannelError // XorIDA split, reconstruct, HMAC └── XlinkAgentError // High-level Agent lifecycle
import { toXlinkError, isXlinkError } from '@xail/agent-sdk'; const result = await agent.receive(envelope); if (!result.ok) { const err = toXlinkError(result.error); console.log(err.code); // 'DECRYPT_FAILED' console.log(err.subCode); // 'KEY_AGREEMENT' console.log(err.docUrl); // 'https://xail.io/sdk/index/docs/packages/xlink#envelope' console.log(err.name); // 'XlinkEnvelopeError' }
Trust Registry
Three implementations covering development through production.
Nonce Store
Replay prevention via unique nonce tracking. Every envelope carries a cryptographic 16-byte nonce.
Transport Adapters
Pluggable delivery mechanism. Two built-in adapters plus a custom interface.
interface XailTransportAdapter { send(envelope: TransportEnvelope, to: string): Promise<Result<void, TransportError>>; onReceive(handler: (envelope: TransportEnvelope) => void): void; dispose(): void; }
Full ACI Surface
Complete Authenticated Cryptographic Interface organized by module.
Agent
Generate identity, register with registry, wire transport. Primary factory.
Restore from persisted PKCS8 identity. Skips keygen + registration.
Synchronous construction from pre-built components. No async, no Result.
Deterministic identity from 32-byte seed via HKDF-SHA256. IoT factory provisioning.
Encrypt, sign, and deliver. Auto ECDH when available. Optional split-channel.
Verify version, timestamp, nonce, sender, signature, scope. Decrypt. Parse.
Identity
Ed25519 + X25519 keypair generation via Web Crypto API. ML-DSA-65 keys when postQuantumSig: true.
PKCS8 DER export/import for identity persistence.
HKDF-SHA256 deterministic derivation from 32-byte seed.
Envelope
Encrypted or signed-only envelope creation.
Validation and deserialization from unknown input.
Split-Channel
XorIDA split with HMAC integrity. Default: 3 shares, threshold 2.
Reconstruct from K+ shares. HMAC verified before returning plaintext.
Key Agreement
Hybrid X25519 + ML-KEM-768 key agreement with ephemeral key pair per message.
Error Taxonomy
Complete error code table with sub-codes and error classes.
| Code | Class | When |
|---|---|---|
| IDENTITY_FAILED | Agent | Identity generation fails during create() |
| REGISTRATION_FAILED | Agent | Registry rejects registration |
| REGISTRATION_FAILED:ALREADY_REGISTERED | Agent | DID already exists in registry |
| VERIFICATION_FAILED:SIGNATURE_MISMATCH | Agent | Ed25519 signature does not match |
| VERIFICATION_FAILED:DID_NOT_IN_REGISTRY | Agent | Sender DID not found in registry |
| REPLAY_DETECTED | Agent | Duplicate nonce (replay attack) |
| TIMESTAMP_EXPIRED | Agent | Envelope outside timestamp window |
| SCOPE_DENIED | Agent | Sender lacks required scope |
| DECRYPT_FAILED:KEY_AGREEMENT | Envelope | ECDH derivation fails |
| DECRYPT_FAILED:DECRYPTION | Envelope | AES-GCM decryption fails |
| DECRYPT_FAILED:PARSE | Envelope | Decrypted bytes not valid JSON |
| SEND_FAILED:BELOW_THRESHOLD | Transport | Split: fewer than K shares delivered |
| HMAC_VERIFICATION_FAILED | SplitChannel | Share HMAC check fails |
| INSUFFICIENT_SHARES | SplitChannel | Fewer than threshold shares |
| INCONSISTENT_SHARES | SplitChannel | Mismatched groupId or params |
| INVALID_KEY_LENGTH:EXPECTED_32 | KeyAgreement | X25519 key not 32 bytes |
Codebase Stats
Xlink v0.1.0 — Gold Standard Bronze tier achieved.
Module Inventory
| Module | Source File | Purpose |
|---|---|---|
| Identity | identity.ts | Ed25519 + X25519 keygen, DID, PKCS8, sign/verify |
| Envelope | envelope.ts | v1 create/decrypt/serialize/validate |
| Agent | agent.ts | Top-level ACI (create, send, receive, middleware) |
| Split-Channel | split-channel.ts | XorIDA bridge: split, reconstruct, HMAC |
| Key Agreement | key-agreement.ts | X25519 ECDH ephemeral key agreement |
| Nonce Store | nonce-store.ts | MemoryNonceStore for replay prevention |
| Redis Nonce | redis-nonce-store.ts | RedisNonceStore for distributed deployments |
| Trust Registry | trust-registry.ts | Memory + HTTP registry |
| DID:web | did-web.ts | W3C did:web resolver |
| Transport | transport.ts | Interface + HTTPS adapter |
| Gateway | gateway-transport.ts | Xail inbox gateway delivery |
| Middleware | registry-middleware.ts | Express auth middleware for registry |
| Errors | errors.ts | Error class hierarchy (XlinkError + 7) |
| Verify | verify.ts | Lightweight verify-only sub-path |
Documentation
22 documentation files including: SECURITY.md, CHANGELOG.md, QUICKSTART.md, MIGRATION.md, CONTRIBUTING.md, AGENTS.md, threat model, data flow diagrams, security whitepaper, failure modes, Gold Standard assessment, and 4 example scripts.