feat(wallet): add custodial wallet persistence, status transitions, and KMS references - #146
Merged
3m1n3nc3 merged 2 commits intoAug 22, 2026
Conversation
…nd KMS references
… transitions test
7 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.
Why This PR Exists
Learnault requires managed Stellar custodial wallet persistence without storing plaintext private signing keys or seeds in the database, API payloads, or audit logs. This PR establishes non-custodial-at-rest wallet persistence and KMS reference models backed by an envelope-encrypted Key Management Service abstraction. It enforces strict database uniqueness constraints, explicit state transition guards, and zero plaintext secret leakage across all application layers.
What Was Wrong
What This PR Does
prisma/schema.prisma,migration.sql) — DefinedWalletandManagedKeyReferencemodels storing only network, custody, public key, status, and opaque KMS URIs (kms://...) with unique constraints onuserId,publicKey,managedKeyReferenceId, andopaqueReference.src/services/kms/) — ImplementedSensitiveValue(private#valuewith.toString()/.toJSON()redaction),KmsSecretStoreinterface, andInMemoryEnvelopeKmsutilizing AES-256-GCM envelope encryption with test lifecycle hooks.src/types/wallet-provisioning.types.ts) — ExtendedWALLET_STATUSESwith full lifecycle states (RESERVED,PROVISIONING,RETRYABLE,ACTIVE,EXPORTING,MIGRATED,FAILED,DISABLED) and addedWALLET_TRANSITIONSmap withcanTransitionWallet()andassertValidWalletTransition()guards.src/types/wallet-provisioning.types.ts) — Enforced thatPublicWalletandtoPublicWallet()strictly exclude all internal KMS references (managedKeyReferenceId,opaqueReference,keyVersion).tests/unit/wallet-transitions.test.ts,tests/wallet-secret-scan.test.ts) — Added comprehensive unit tests for all valid/invalid transitions and regex/AST scanning ensuring zero plaintext secret columns in schema and DTOs.Testing
tests/unit/wallet-transitions.test.ts— Passed (valid lifecycle paths, invalid jumps, and guard exceptions verified)tests/wallet-secret-scan.test.ts— Passed (0 plaintext secret columns, 0 leaked seeds in docs/DTOs)tests/wallet-provisioning.service.test.ts— Passed (concurrent reservations, KMS idempotency, DB finalization recovery)tests/wallet-self-custody-export.service.test.ts— Passed (step-up auth, KMS secret delivery, custody migration, KMS key deletion)Out of Scope
Closes #135