Skip to content

refactor: make walletkit-db a generic encrypted sqlite crate#396

Closed
danielle-tfh wants to merge 2 commits into
mainfrom
extract-walletkit-secure-store
Closed

refactor: make walletkit-db a generic encrypted sqlite crate#396
danielle-tfh wants to merge 2 commits into
mainfrom
extract-walletkit-secure-store

Conversation

@danielle-tfh
Copy link
Copy Markdown
Contributor

@danielle-tfh danielle-tfh commented May 5, 2026

Motivation

OrbKit's planned OrbPcpStore needs a reusable encrypted SQLite crate rather than a credential-store-specific storage stack. Reference: OrbKit Outline.

What changed

walletkit-db is narrowed to one responsibility: a generic encrypted SQLite (sqlite3mc) wrapper.

  • The public database surface now lives under walletkit_db::sqlite.
  • The crate keeps safe connection / transaction / statement types plus encrypted open, integrity-check, and plaintext copy helpers.
  • Plaintext export/import now takes caller-supplied table lists instead of hard-coding credential tables.

The credential-store-specific storage policy stays in walletkit-core:

  • account-key envelope handling
  • cross-process storage lock
  • vault blob schema and content-id convention
  • vault backup table selection

Host-facing FFI does not change.

Why this shape

The shared layer for OrbKit is the encrypted database machinery, not the higher-level storage lifecycle.

This keeps the boundary simple:

  • walletkit-db owns database mechanics
  • consumer crates own schema and storage policy

On-disk format

No intended credential-storage format change in this refactor. Existing envelope, content-id, vault schema, and backup behavior stay the same.

Verification

  • cargo fmt
  • cargo test -p walletkit-db
  • cargo check -p walletkit-core --lib
  • cargo test -p walletkit-core storage:: --lib --features embed-zkeys

@danielle-tfh danielle-tfh marked this pull request as draft May 5, 2026 15:49
@danielle-tfh danielle-tfh reopened this May 5, 2026
@danielle-tfh danielle-tfh marked this pull request as ready for review May 6, 2026 11:13
@danielle-tfh danielle-tfh changed the title refactor: extract walletkit-secure-store crate refactor: expand walletkit-db with vault primitives May 6, 2026
@danielle-tfh danielle-tfh changed the title refactor: expand walletkit-db with vault primitives refactor: make walletkit-db a generic encrypted sqlite crate May 7, 2026
@danielle-tfh danielle-tfh force-pushed the extract-walletkit-secure-store branch from d9a2908 to 34cf1a0 Compare May 7, 2026 13:35
- README: rewrite walletkit-db blurb to generic-only; drop dangling
  sub-crate README pointer.
- walletkit-db: re-export public types at crate root (Connection,
  Transaction, Statement, Row, StepResult, Value, cipher) and alias
  Error/Result back to DbError/DbResult for back-compat and to remove
  per-call-site aliasing in consumers.
- vault: revert compute_content_id signature back to BlobKind (was
  weakened to u8 for no boundary reason); restore BlobKind::as_i64()
  and simplify the i64 cast call sites.
- credential_storage: drop dead Ok(self.lock.lock()?) wrap.
- vault: move BACKUP_TABLES into vault/schema.rs next to the schema
  it mirrors; revert blob_objects/credential_records ordering churn.
- keys: relocate the 'Key structure' architecture doc block that was
  deleted from traits.rs in this refactor.
- walletkit-db tests: add round-trip and non-empty-destination
  rejection coverage for cipher::export/import_plaintext_copy with a
  generic table.
- docs: fix private intra-doc link to ffi module.

Verified: cargo fmt, cargo clippy (all/default/no-default features),
cargo test --workspace --lib (--features legacy-nullifiers,v3),
cargo build --no-default-features, cargo deny (bans/licenses/sources),
cargo doc --all-features (RUSTDOCFLAGS=-Dwarnings) all pass.
@danielle-tfh
Copy link
Copy Markdown
Contributor Author

Superseded by #400, which expands walletkit-db into the shared storage-primitives crate (the framing OrbKit needs) instead of narrowing it. The genericized backup-tables work from this PR is preserved in #400.

danielle-tfh added a commit that referenced this pull request May 13, 2026
1. error.rs: restore 1-1 From<walletkit_db::StoreError> variant mapping. The previous Self::VaultDb(err.to_string()) collapse erased variant identity that hosts depend on for UX (Crypto vs InvalidEnvelope vs Keystore vs CorruptedVault, etc.). keys.rs tests restored to match specific variants.

2. blobs::get(conn, cid: &[u8]): lax input — accept any byte slice so callers reading content_id out of another table column (Vec<u8> from column_blob) don't need copy_from_slice into a [u8; 32].

3. tests.rs: new test_key_envelope_cbor_bytes_frozen asserting the canonical KeyEnvelope serializes to a hard-coded hex string. Round-trip alone misses field-order or type drift; this catches it.

4. lib.rs: drop KeyEnvelope from public re-exports — fields are pub(crate), so external consumers couldn't read them anyway; only init_or_open_envelope_key is the surface.

5. blobs::delete(conn, cid: &[u8]): orphan-blob GC. Consumers handling status transitions (status: Enrolled → Unverified, etc.) call this instead of writing raw SQL.

6. README.md: walletkit-db description matches Cargo.toml ("Encrypted on-device storage primitives ...") — old wording was stale from the pre-refactor PR #396 framing.

7. vault/mod.rs: drop the redundant let conn = &self.conn aliasing introduced during the refactor.

8. traits.rs: tighten the doc note about consumer adapters — orphan rule blocks a blanket impl across crates, so consumers need a small newtype.

Verified: cargo fmt, cargo clippy -D warnings (all/default/no-default-features), cargo test --workspace --lib --features walletkit-core/legacy-nullifiers --features walletkit-core/v3 (123 + 19 = 142 tests), cargo doc -Dwarnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant