β οΈ Retired / Do Not Use
This repository contains incomplete, insecure experimental code. It is no longer maintained and will be archived. Please do not rely on this project for any production or sensitive use cases.
efsec is an in-progress, experimental end-to-end encryption library providing a high-level TypeScript interface to the Matrix E2E encryption standards. It builds on top of @matrix-org/matrix-sdk-crypto-wasm (Matrixβs audited cryptographic implementation), offering both convenience wrappers and direct access to the underlying cryptographic primitives.
β οΈ Development status: efsec is not yet production-ready. Itβs an exploratory reference implementation under active development. Security audits are ongoing; do not use efsec in applications that handle sensitive data in production environments.
- β Matrix-compliant β follows Matrix E2E encryption specifications
- β Dual API β simple wrappers and direct Matrix SDK access
- β Zero-knowledge architecture β private keys never leave the client device
- β Olm & Megolm β secure one-to-one and group messaging
- β X3DH key exchange β modern authenticated key agreement
- β Double Ratchet β forward + backward secrecy for all messages
- β Secure storage β IndexedDB key persistence
- β TypeScript-first β strong types and structured error handling
- β Audited core β backed by Matrixβs formally reviewed crypto libraries
npm install efsecimport {
initializeWasm,
generateIdentityKeyPair,
generateOneTimePreKeys,
createOutboundSession,
encryptMessage,
decryptMessage,
KeyStore
} from "efsec";
await initializeWasm();
// Generate identity keys
const identityKeys = await generateIdentityKeyPair();
console.log("Curve25519:", identityKeys.curve25519.key);
console.log("Ed25519:", identityKeys.ed25519.key);
// Generate pre-keys for X3DH
const oneTimeKeys = await generateOneTimePreKeys(50);
// Secure local key storage
const keyStore = new KeyStore();
await keyStore.initialize();
await keyStore.storeIdentityKeys("device-1", identityKeys);
// Encrypt / decrypt
const session = await createOutboundSession(identityKeys, recipientBundle);
const message = { content: "Hello!", timestamp: Date.now(), id: "msg-1" };
const encrypted = await encryptMessage(session, message);
const decrypted = await decryptMessage(session, encrypted);import * as MatrixCrypto from "@matrix-org/matrix-sdk-crypto-wasm";
await MatrixCrypto.initAsync();
const olmMachine = await MatrixCrypto.OlmMachine.initialize(
new MatrixCrypto.UserId("@user:domain.com"),
new MatrixCrypto.DeviceId("DEVICE123")
);
const keys = olmMachine.identityKeys;
console.log(keys.curve25519.toBase64(), keys.ed25519.toBase64());efsec offers secure IndexedDB-based key persistence:
import { KeyStore } from "efsec";
const keyStore = new KeyStore();
await keyStore.initialize();
const deviceId = "device-1";
const identityKeys = await generateIdentityKeyPair();
await keyStore.storeIdentityKeys(deviceId, identityKeys);
const storedKeys = await keyStore.getIdentityKeys(deviceId);
// Export / import for backups
const backup = await keyStore.exportData(deviceId);
await keyStore.importData(backup);| Function | Description |
|---|---|
initializeWasm() |
Initialize the Matrix crypto WASM module. |
generateIdentityKeyPair() |
Create Matrix-compliant Curve25519 + Ed25519 keys. |
generateOneTimePreKeys(count?) |
Generate pre-keys for X3DH sessions. |
| Function | Description |
|---|---|
createOutboundSession() |
Create an outbound X3DH session. |
encryptMessage() |
Encrypt a plaintext message using Double Ratchet / Megolm. |
decryptMessage() |
Decrypt messages while maintaining forward secrecy. |
| Function | Description |
|---|---|
createOutboundGroupSession() |
Start a new group encryption session. |
createInboundGroupSessionFromKey() |
Import a shared group session key. |
KeyStore β secure IndexedDB store for device identity + session state.
efsec uses a dual-layer design:
- High-level API β ergonomic wrappers for common tasks.
- Direct SDK access β full Matrix control via
@matrix-org/matrix-sdk-crypto-wasm.
This approach lets developers:
- Prototype quickly using simple wrappers.
- Transition smoothly to full Matrix primitives.
- Stay 100% protocol-compatible throughout.
import { initializeWasm, generateIdentityKeyPair, KeyStore } from "efsec";
import * as MatrixCrypto from "@matrix-org/matrix-sdk-crypto-wasm";
await initializeWasm();
const identityKeys = await generateIdentityKeyPair();
const store = new KeyStore();
await store.storeIdentityKeys("device-1", identityKeys);
const olmMachine = await MatrixCrypto.OlmMachine.initialize(
new MatrixCrypto.UserId("@user:example.com"),
new MatrixCrypto.DeviceId("DEVICE123")
);
const requests = await olmMachine.outgoingRequests();
for (const req of requests) {
if (req.type === MatrixCrypto.RequestType.KeysUpload) {
const res = await fetch("/matrix/keys/upload", {
method: "POST",
body: req.body
});
await olmMachine.markRequestAsSent(req.id, req.type, await res.text());
}
}efsec defines clear error classes for predictable behavior:
import { DecryptionError, SessionError, KeyError } from "efsec";
try {
const plaintext = await decryptMessage(session, encrypted);
} catch (err) {
if (err instanceof DecryptionError) console.error("Decryption failed", err);
if (err instanceof SessionError) console.error("Session error", err);
if (err instanceof KeyError) console.error("Key error", err);
}Common scenarios:
DecryptionErrorβ wrong session or corrupted ciphertextSessionErrorβ invalid session stateKeyErrorβ missing or malformed key data
Requirements:
- IndexedDB
- Web Crypto API
- WebAssembly
- ES2022 modules
| Browser | Min Version |
|---|---|
| Chrome | 88+ |
| Firefox | 90+ |
| Safari | 14+ |
| Edge | 88+ |
efsecβs cryptography builds on formally audited Matrix libraries:
- Matrix SDK Crypto:
@matrix-org/matrix-sdk-crypto-wasm - Vodozemac: audited by Least Authority
- Matrix E2E Spec: peer-reviewed and publicly maintained
All private-key operations occur client-side. Server components have zero knowledge of plaintext or key material.
Security researchers are welcome to review efsecβs wrapper layer β see SECURITY.md for guidelines.
Found a potential vulnerability? Please review our SECURITY.md for private reporting instructions.
GPL v3 or later β see LICENSE.
efsec is free software: you can redistribute or modify it under the terms of the GNU General Public License v3 or (at your option) any later version.
- Fork the repo
- Create a feature branch
- Add tests
- Run
npm test(coming soon) - Submit a pull request
For major changes, open an issue first to discuss direction.
See CHANGELOG.md for version history.
- Repository: https://github.com/efchatnet/efsec
- Issues: https://github.com/efchatnet/efsec/issues
- Security policy: SECURITY.md
- License: GPL-3.0-or-later
Disclaimer: efsec is experimental software under active development. Do not deploy it in production or rely on it for protecting confidential data without an independent security audit.