Repository navigation
feat(crypto): add SDK encryption utilities with key rotation (#1320) - #1370
Merged
Kingsman-99 merged 2 commits intoNov 23, 2026
Merged
Kingsman-99 merged 2 commits into
Kingsman-99 merged 2 commits into
Conversation
|
@Phantomcall Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
6 tasks
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 SDK encryption utilities with key management and rotation (#1320)
Summary
Adds a self-contained, Web Crypto based encryption layer for sensitive SDK data. Unlike the payment-specific
PaymentEncryptor, these utilities are generic, browser-compatible, versioned, and designed around safe keyrotation with a bounded, secret-free tracking trail.
What changed
src/encryptionUtils.tsSdkEncryptorencrypts strings and JSON values with AES-256-GCM, generating a fresh 12-byte IV per payload and emitting a versionedEncryptedEnvelope(version,keyVersion,iv,ciphertext,tag).keyVersionor envelope version fails authentication instead of silently decrypting with the wrong key.deriveEncryptionKey()derives a 256-bit key from a passphrase with PBKDF2-SHA256 (configurable iterations, 16-byte minimum salt);generateSalt()creates random salts.EncryptionKeyManagerprovides versioned key registration, activation, retirement and atomicrotate(). Retired keys remain readable for old ciphertext but can never be used for new encryption or re-activated.reencrypt()migrates ciphertext to the current key after rotation without exposing plaintext in logs.EncryptionUtilityError,KeyNotFoundError,DecryptionFailedError) and strict key-length/version validation.stats()andeventsTrail()expose bounded, key-material-free operation counters for tracking; never payloads or key bytes.src/index.tsfor the encryptor, key manager, helpers, errors, constants and public types.test/encryptionUtils.test.tscover deterministic key derivation, validation, retirement rules, round-trips, JSON helpers, tamper/wrong-key rejection, rotation and migration, and bounded tracking.Acceptance criteria addressed
reencrypt()of existing payloads while old keys stay readable.Tests and typecheck
The repository's
npm run lintwas already failing before this change due to pre-existing syntax errors and merge-conflict markers in unrelated files (src/abiCache.ts,src/priceOracle.ts,src/upgradeMigrationRunner.ts,src/validators/deadlineValidator.ts,src/types/templates.ts). This change introduces no new TypeScript errors.Backwards compatibility
Additive only; no existing module or API is modified.
closes #1320