Skip to content

chore(rust): update vetkeys examples to ic-vetkeys 0.8.1 and @icp-sdk/vetkeys 0.5.0 - #1456

Open
marc0olo wants to merge 4 commits into
masterfrom
chore/vetkeys-0.8.1-encrypted-maps-macro
Open

chore(rust): update vetkeys examples to ic-vetkeys 0.8.1 and @icp-sdk/vetkeys 0.5.0#1456
marc0olo wants to merge 4 commits into
masterfrom
chore/vetkeys-0.8.1-encrypted-maps-macro

Conversation

@marc0olo

@marc0olo marc0olo commented Jul 29, 2026

Copy link
Copy Markdown
Member

What

Updates the Rust vetKeys examples to the current library releases, adopts the new EncryptedMaps canister macro where it fits, and migrates the frontends for the 0.5.0 caching change.

Backend — ic-vetkeys 0.7.0 → 0.8.1

  • password_manager: the hand-written EncryptedMaps pass-through canister is replaced by the ic_vetkeys::export_encrypted_maps_canister! macro (backend/src/lib.rs, ~311 → ~30 lines). The canister owns the MemoryManager and passes EncryptedMaps its four Memory instances; the macro emits #[init]/#[post_upgrade] and every endpoint, so the Candid matches the @icp-sdk/vetkeys frontend by construction. backend.did regenerated — the interface is unchanged; the only delta is doc comments the newer crate emits into the Candid.
  • password_manager_with_metadata: version bump, plus a persistence fix — its METADATA stable map is now initialized with StableBTreeMap::init instead of ::new. ::new reset the map every time the thread-local was re-created after an upgrade, wiping all metadata; because the read path zips metadata against the (surviving) encrypted values, every password disappeared from the UI after an upgrade while the vault still listed as non-empty. init loads the persisted map.
  • basic_ibe, basic_timelock_ibe, basic_bls_signing: dependency version bump only.

Why password_manager_with_metadata keeps a hand-written canister

The macro is all-or-nothing. This example maintains a second, backend-authoritative metadata map that must stay 1:1 with the encrypted values, so it must not expose the plain insert_encrypted_value / remove_encrypted_value mutators the macro would generate (they'd let a value be written with no metadata row and desync the two stores). Filed upstream about closing that gap: dfinity/vetkeys#423.

Frontend — @icp-sdk/vetkeys ^0.5.0-beta.0^0.5.0

All 7 Rust frontends move to the final 0.5.0 release. 0.5.0 makes derived-key caching in-memory by default; the two password-manager frontends:

  • opt back into cross-reload persistence via IndexedDbDerivedKeyMaterialCache, namespaced per identity (vetkeys-<principal>) so one identity's keys are never served to another on the same origin;
  • call EncryptedMaps.clearCache() on logout to drop cached key material.

The other 5 (basic_*, encrypted_notes_app_vetkd) are version-bump only — they don't use the EncryptedMaps client.

Docs

Both password-manager READMEs updated: macro-vs-hand-written rationale, and a "derived-key caching" section explaining the IndexedDB opt-in and how to verify clearCache() on logout (the vetkeys-<principal> store is emptied, not deleted).

Scope

Rust examples only; the Motoko vetKeys examples are unchanged.

Verification

  • cargo check on all 5 backends; password_manager wasm build + candid-extractor diff against the committed .did (service surface identical).
  • npm run build on all 7 frontends against the real 0.5.0.
  • Manual end-to-end (local replica):
    • password_manager: create/read/share password; logout empties the vetkeys-<principal> cache; upgrade (--mode upgrade) preserves data and existing passwords still decrypt.
    • password_manager_with_metadata: metadata (timestamps, modification count, principal) persists across an upgrade.
    • basic_ibe: encrypt → fetch vetKey → decrypt.

🤖 Generated with Claude Code

marc0olo and others added 3 commits July 29, 2026 13:30
…/vetkeys 0.5.0

Backend (ic-vetkeys 0.7.0 -> 0.8.1):
- password_manager: replace the hand-written EncryptedMaps pass-through canister
  with the new `ic_vetkeys::export_encrypted_maps_canister!` macro (~311 -> ~30
  lines). The macro owns the endpoint set, so the Candid matches the frontend by
  construction. Regenerated backend.did (interface unchanged; the newer crate now
  emits doc comments into the Candid).
- basic_ibe, basic_timelock_ibe, basic_bls_signing, password_manager_with_metadata:
  version bump only (no breaking API changes since 0.7.0).
- password_manager_with_metadata deliberately stays hand-written: it keeps a
  second, backend-authoritative metadata map in sync with the encrypted values,
  so it must NOT expose the plain insert/remove mutators the macro would generate
  (they would let a value be written without its metadata row and desync the two
  stores). See dfinity/vetkeys issue linked in the PR.

Frontend (@icp-sdk/vetkeys ^0.5.0-beta.0 -> ^0.5.0):
- All 7 Rust frontends bumped to the final 0.5.0 release.
- password_manager and password_manager_with_metadata: opt back into IndexedDB
  persistence (in-memory is the new 0.5.0 default) via
  IndexedDbDerivedKeyMaterialCache, namespaced per identity, and call
  EncryptedMaps.clearCache() on logout to drop cached key material.

Motoko examples untouched (Rust-only change, per request).

Verified: cargo check on all 5 backends; wasm build + candid diff for
password_manager; npm build for all 7 frontends.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… on logout

Explain the IndexedDB opt-in (per-identity namespace) and that clearCache()
empties the derived-key-material store rather than deleting the database, so an
empty vetkeys-<principal> DB remaining is expected. Add the DevTools steps to
verify (incl. the Refresh-database gotcha) and clarify the unrelated
icp-sdk-<host> subnetNodeKeys DB.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…metadata

The METADATA StableBTreeMap was initialized with StableBTreeMap::new, which
overwrites the backing memory with an empty map every time the thread-local is
re-created after an upgrade. Because the read path zips the metadata iterator
against the (surviving) encrypted values, an empty metadata map made every
password disappear from the UI after an upgrade while the vault still listed as
non-empty. Use StableBTreeMap::init so the persisted map is loaded instead.

Pre-existing bug, unrelated to the 0.8.1 bump; surfaced during upgrade testing.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@marc0olo
marc0olo marked this pull request as ready for review July 29, 2026 13:13
@marc0olo
marc0olo requested a review from a team as a code owner July 29, 2026 13:13
@marc0olo
marc0olo requested a review from Copilot July 29, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Rust vetKeys examples to current ic-vetkeys / @icp-sdk/vetkeys releases, adopting the new export_encrypted_maps_canister! backend macro where applicable and adjusting password-manager frontends for the v0.5.0 derived-key caching behavior.

Changes:

  • Bump Rust backends to ic-vetkeys = 0.8.1, including migrating password_manager backend to the generated Encrypted Maps canister macro.
  • Update password-manager frontends to persist derived-key material via IndexedDbDerivedKeyMaterialCache and clear cached material on logout.
  • Bump all Rust vetKeys frontends from @icp-sdk/vetkeys ^0.5.0-beta.0 to ^0.5.0, plus related docs updates.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
rust/vetkeys/password_manager/README.md Document macro-generated backend and derived-key caching behavior.
rust/vetkeys/password_manager/frontend/src/store/auth.ts Clear EncryptedMaps cache on logout; adjust EncryptedMaps creation call signature.
rust/vetkeys/password_manager/frontend/src/lib/encrypted_maps.ts Create EncryptedMaps with per-principal IndexedDB cache; API updated to accept Identity.
rust/vetkeys/password_manager/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/password_manager/Cargo.toml Bump ic-vetkeys to 0.8.1.
rust/vetkeys/password_manager/backend/src/lib.rs Replace handwritten canister with ic_vetkeys::export_encrypted_maps_canister! macro usage.
rust/vetkeys/password_manager/backend/backend.did Regenerate .did (doc comments updated by newer crate).
rust/vetkeys/password_manager_with_metadata/README.md Explain why this example stays handwritten; document derived-key caching behavior.
rust/vetkeys/password_manager_with_metadata/frontend/src/store/auth.ts Clear derived-key material cache on logout; adjust PasswordManager creation call signature.
rust/vetkeys/password_manager_with_metadata/frontend/src/lib/password_manager.ts Update PasswordManager factory to take an Identity and wire cache namespacing.
rust/vetkeys/password_manager_with_metadata/frontend/src/lib/encrypted_maps.ts Create EncryptedMaps with per-principal IndexedDB cache.
rust/vetkeys/password_manager_with_metadata/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/password_manager_with_metadata/backend/src/lib.rs Fix metadata persistence by switching StableBTreeMap::new::init.
rust/vetkeys/password_manager_with_metadata/backend/Cargo.toml Bump ic-vetkeys to 0.8.1.
rust/vetkeys/encrypted_notes_app_vetkd/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/basic_vetkd/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/basic_timelock_ibe/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/basic_timelock_ibe/backend/Cargo.toml Bump ic-vetkeys to 0.8.1.
rust/vetkeys/basic_ibe/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/basic_ibe/backend/Cargo.toml Bump ic-vetkeys to 0.8.1.
rust/vetkeys/basic_bls_signing/frontend/package.json Bump @icp-sdk/vetkeys to ^0.5.0.
rust/vetkeys/basic_bls_signing/backend/Cargo.toml Bump ic-vetkeys to 0.8.1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rust/vetkeys/password_manager/frontend/src/store/auth.ts Outdated
Comment thread rust/vetkeys/password_manager/README.md Outdated
Comment thread rust/vetkeys/password_manager_with_metadata/README.md Outdated
Comment thread rust/vetkeys/password_manager/frontend/src/lib/encrypted_maps.ts Outdated
Comment thread rust/vetkeys/password_manager_with_metadata/frontend/src/lib/encrypted_maps.ts Outdated
Comment thread rust/vetkeys/password_manager/backend/src/lib.rs Outdated
…hing docs

Address PR review feedback:
- password_manager and password_manager_with_metadata: clear the derived-key
  cache best-effort on logout so sign-out still completes if IndexedDB is
  unavailable (private mode, quota, blocked storage).
- READMEs and code comments: refer to clearCache() as an instance method and
  drop the "identity change" wording — the apps only clear on logout, and the
  per-identity cache namespace already isolates identities.
- password_manager backend: reword the macro comment so the domain-separator
  string argument is no longer conflated with the config memory slot.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.

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.

3 participants