feat(encryption): add isomorphic end-to-end encryption package - #6
Merged
Conversation
Add @arkstack/encryption, a zero-dependency package built entirely on the Web Crypto API so the same code runs in Node, Deno, Bun, browsers and workers. A value encrypted on the server decrypts in the browser and the other way around. - Cipher: AES-256-GCM with optional additional authenticated data - EncryptionKey: generate, hash from secret, PBKDF2 derive, HKDF expand, fingerprint, constant-time compare - Keys: key and identity generation plus constant-time comparison helpers - KeyPair: ECDH P-256 identities serialised as base64url SPKI/PKCS#8 - SecureChannel: two-party E2E, shared key derived locally on both sides - SealedBox: anonymous encryption to a public key - NodeCipher: synchronous node:crypto cipher behind its own entry point, emitting byte-identical payloads, so browser bundles never pull in node:crypto Encryption in @arkstack/common now wraps the package rather than owning an implementation. encrypt() and decrypt() keep their synchronous signatures, key derivation and payload format, so stored ciphertexts and existing call sites are unaffected; the added key argument is optional. Async, key-management and E2E methods are new surface. APP_KEY is itself 32 base64url bytes, which the library would otherwise treat as raw key material rather than a passphrase, so the wrapper routes through NodeCipher.fromSecret() to keep hashing it with SHA-256. encryption-compat.test.ts pins the wrapper against the previous implementation, reproduced verbatim from git history, in both directions.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add @arkstack/encryption, a zero-dependency package built entirely on the
Web Crypto API so the same code runs in Node, Deno, Bun, browsers and
workers. A value encrypted on the server decrypts in the browser and the
other way around.
fingerprint, constant-time compare
emitting byte-identical payloads, so browser bundles never pull in
node:crypto
Encryption in @arkstack/common now wraps the package rather than owning
an implementation. encrypt() and decrypt() keep their synchronous
signatures, key derivation and payload format, so stored ciphertexts and
existing call sites are unaffected; the added key argument is optional.
Async, key-management and E2E methods are new surface.
APP_KEY is itself 32 base64url bytes, which the library would otherwise
treat as raw key material rather than a passphrase, so the wrapper routes
through NodeCipher.fromSecret() to keep hashing it with SHA-256.
encryption-compat.test.ts pins the wrapper against the previous
implementation, reproduced verbatim from git history, in both directions.