diff --git a/rust/vetkeys/password_manager/README.md b/rust/vetkeys/password_manager/README.md
new file mode 100644
index 000000000..d44ee8663
--- /dev/null
+++ b/rust/vetkeys/password_manager/README.md
@@ -0,0 +1,59 @@
+# VetKey Password Manager
+
+| Motoko backend | [](http://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/vetkeys/password_manager/motoko)|
+| --- | --- |
+| Rust backend | [](http://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/vetkeys/password_manager/rust) |
+
+The **VetKey Password Manager** is an example application demonstrating how to use **VetKeys** and **Encrypted Maps** to build a secure, decentralized password manager on the **Internet Computer (IC)**. This application allows users to create password vaults, store encrypted passwords, and share vaults with other users via their **Internet Identity Principal**.
+
+## Features
+
+- **Secure Password Storage**: Uses VetKey to encrypt passwords before storing them in Encrypted Maps.
+- **Vault-Based Organization**: Users can create multiple vaults, each containing multiple passwords.
+- **Access Control**: Vaults can be shared with other users via their **Internet Identity Principal**.
+
+## Setup
+
+### Prerequisites
+
+- [Local Internet Computer dev environment](https://internetcomputer.org/docs/building-apps/getting-started/install)
+- [npm](https://www.npmjs.com/package/npm)
+
+### (Optionally) Choose a Different Master Key
+
+This example uses `test_key_1` by default. To use a different [available master key](https://internetcomputer.org/docs/building-apps/network-features/vetkeys/api#available-master-keys), change the `"init_arg": "(\"test_key_1\")"` line in `dfx.json` to the desired key before running `dfx deploy` in the next step.
+
+### Deploy the Canisters Locally
+If you want to deploy this project locally with a Motoko backend, then run:
+```bash
+dfx start --background && dfx deploy
+```
+from the `motoko` folder.
+
+To use the Rust backend instead of Motoko, run the same command in the `rust` folder.
+
+## Running the Project
+
+### Backend
+
+The backend consists of an **Encrypted Maps**-enabled canister that securely stores passwords. It is automatically deployed with `dfx deploy`.
+
+### Frontend
+
+The frontend is a **Svelte** application providing a user-friendly interface for managing vaults and passwords.
+
+To run the frontend in development mode with hot reloading:
+
+```bash
+npm run dev
+```
+
+## Limitations
+
+This example dapp does not implement key rotation, which is strongly recommended in a production environment.
+Key rotation involves periodically changing encryption keys and re-encrypting data to enhance security.
+In a production dapp, key rotation would be useful to limit the impact of potential key compromise if a malicious party gains access to a key, or to limit access when users are added or removed from note sharing.
+
+## Additional Resources
+
+- **[Password Manager with Metadata](../password_manager_with_metadata/)** - If you need to store additional metadata alongside passwords.
diff --git a/rust/vetkeys/password_manager/frontend/.prettierignore b/rust/vetkeys/password_manager/frontend/.prettierignore
new file mode 100644
index 000000000..987c28939
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/.prettierignore
@@ -0,0 +1,7 @@
+# Ignore artifacts:
+build
+coverage
+dist
+README.md
+**/declarations/
+
diff --git a/rust/vetkeys/password_manager/frontend/.prettierrc b/rust/vetkeys/password_manager/frontend/.prettierrc
new file mode 100644
index 000000000..2b9bd83ee
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/.prettierrc
@@ -0,0 +1,5 @@
+{
+ "plugins": ["prettier-plugin-svelte"],
+ "tabWidth": 4,
+ "overrides": [{ "files": ["*.svelte"], "options": { "parser": "svelte" } }]
+}
diff --git a/rust/vetkeys/password_manager/frontend/README.md b/rust/vetkeys/password_manager/frontend/README.md
new file mode 100644
index 000000000..134a1abb0
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/README.md
@@ -0,0 +1,17 @@
+# VetKD Password Manager frontend
+Uses the defaults provided by the devkit to implement a VetKD-based password
+manager. This utilizes the encrypted maps canister example to realize the
+password manager, i.e., there is no dedicated canister implementation, only the
+frontend implementation that uses all defaults from the SDK.
+
+## Step 1: Deploy `encrypted_maps_example` canister and the internet identity canister.
+
+## Step 2: Tell `frontend` what canisters to communicate with, so the following environment variables must be defined. For a local deployment, one can run `deploy_locally.sh` from that folder.
+* `CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER`
+
+## Step 3: Deploy frontend. This returns a link that can be used to access the frontend from the asset canister.
+```shell
+dfx deploy www
+```
+Note: if this returns a URL with the IP `0.0.0.0` and the fronetned does not
+work, a potential fix is to replace it with `localhost`.
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/frontend/eslint.config.mjs b/rust/vetkeys/password_manager/frontend/eslint.config.mjs
new file mode 100644
index 000000000..96aee8e5c
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/eslint.config.mjs
@@ -0,0 +1,56 @@
+// @ts-check
+
+import eslint from "@eslint/js";
+import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
+import globals from "globals";
+import tseslint from "typescript-eslint";
+import svelteConfig from "./svelte.config.js";
+import svelte from "eslint-plugin-svelte";
+
+export default tseslint.config(
+ eslint.configs.recommended,
+ tseslint.configs.recommendedTypeChecked,
+ ...svelte.configs.recommended,
+ eslintPluginPrettierRecommended,
+ {
+ languageOptions: {
+ parserOptions: {
+ projectService: {
+ defaultProject: "./tsconfig.json",
+ },
+ tsconfigRootDir: import.meta.dirname,
+ },
+ globals: {
+ ...globals.browser,
+ ...globals.es2020,
+ },
+ },
+ },
+ {
+ files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"],
+ languageOptions: {
+ parserOptions: {
+ projectService: true,
+ extraFileExtensions: [".svelte"],
+ parser: tseslint.parser,
+ svelteConfig,
+ },
+ },
+ },
+ {
+ ignores: [
+ "dist/",
+ "src/declarations",
+ "*.config.js",
+ "*.config.cjs",
+ "*.config.mjs",
+ "*.config.ts",
+ ],
+ },
+ {
+ rules: {
+ "@typescript-eslint/no-unsafe-argument": "off",
+ "@typescript-eslint/no-unsafe-member-access": "off",
+ },
+ },
+);
diff --git a/rust/vetkeys/password_manager/frontend/index.html b/rust/vetkeys/password_manager/frontend/index.html
new file mode 100644
index 000000000..89d2ddc2a
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/index.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+ VetKeys Password Manager
+
+
+
+
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/package.json b/rust/vetkeys/password_manager/frontend/package.json
new file mode 100644
index 000000000..2c2bd3812
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/package.json
@@ -0,0 +1,47 @@
+{
+ "name": "password-manager-frontend",
+ "version": "0.1.0",
+ "type": "module",
+ "scripts": {
+ "dev": "vite",
+ "build": "vite build",
+ "lint": "eslint",
+ "prettier": "prettier --write .",
+ "prettier-check": "prettier --check .",
+ "preview": "vite preview"
+ },
+ "devDependencies": {
+ "@rollup/plugin-typescript": "^12.1.2",
+ "@tsconfig/svelte": "^5.0.4",
+ "@typewriter/delta": "^1.2.4",
+ "daisyui": "^4.12.23",
+ "eslint-config-prettier": "^10.1.5",
+ "eslint-plugin-prettier": "^5.2.6",
+ "eslint-plugin-svelte": "^3.5.1",
+ "globals": "^16.0.0",
+ "prettier-plugin-svelte": "^3.4.0",
+ "svelte": "^4.2.19",
+ "tslib": "^2.8.1",
+ "typescript-eslint": "^8.35.1",
+ "vite": "^5.4.21",
+ "vite-plugin-environment": "^1.1.3"
+ },
+ "dependencies": {
+ "@dfinity/agent": "^2.3.0",
+ "@dfinity/auth-client": "^2.3.0",
+ "@dfinity/candid": "^2.3.0",
+ "@dfinity/identity": "^2.3.0",
+ "@dfinity/principal": "^2.3.0",
+ "@dfinity/vetkeys": "^0.3.0",
+ "@popperjs/core": "^2.11.8",
+ "@sveltejs/vite-plugin-svelte": "^3.0.2",
+ "@tailwindcss/postcss": "^4.0.6",
+ "@tailwindcss/vite": "^4.0.0",
+ "autoprefixer": "^10.4.20",
+ "rollup-plugin-css-only": "^4.5.2",
+ "svelte-icons": "^2.1.0",
+ "svelte-spa-router": "^4.0.1",
+ "tailwindcss": "^3.0.17",
+ "typewriter-editor": "^0.9.4"
+ }
+}
diff --git a/rust/vetkeys/password_manager/frontend/public/.ic-assets.json5 b/rust/vetkeys/password_manager/frontend/public/.ic-assets.json5
new file mode 100644
index 000000000..a57140a5e
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/public/.ic-assets.json5
@@ -0,0 +1,10 @@
+[
+ {
+ match: "**/*",
+ security_policy: "hardened",
+ headers: {
+ "Content-Security-Policy": "default-src 'self';script-src 'self';connect-src 'self' http://localhost:* https://icp0.io https://*.icp0.io https://icp-api.io;img-src 'self' data:;style-src * 'unsafe-inline';object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
+ },
+ allow_raw_access: false
+ },
+]
diff --git a/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_label-stripe-dark-text.png b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_label-stripe-dark-text.png
new file mode 100644
index 000000000..1a227a2b0
Binary files /dev/null and b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_label-stripe-dark-text.png differ
diff --git a/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_label-stripe-white-text.png b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_label-stripe-white-text.png
new file mode 100644
index 000000000..e1da19855
Binary files /dev/null and b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_label-stripe-white-text.png differ
diff --git a/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_transparent-dark-text.png b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_transparent-dark-text.png
new file mode 100644
index 000000000..90029c464
Binary files /dev/null and b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_transparent-dark-text.png differ
diff --git a/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_transparent-white-text.png b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_transparent-white-text.png
new file mode 100644
index 000000000..f1a2d8081
Binary files /dev/null and b/rust/vetkeys/password_manager/frontend/public/img/ic-badge-powered-by-crypto_transparent-white-text.png differ
diff --git a/rust/vetkeys/password_manager/frontend/public/vite.svg b/rust/vetkeys/password_manager/frontend/public/vite.svg
new file mode 100644
index 000000000..e7b8dfb1b
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/public/vite.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/frontend/src/App.svelte b/rust/vetkeys/password_manager/frontend/src/App.svelte
new file mode 100644
index 000000000..ed34e5e20
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/App.svelte
@@ -0,0 +1,13 @@
+
+
+{#if $auth.state === "initialized"}
+
+{:else}
+
+{/if}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/app.css b/rust/vetkeys/password_manager/frontend/src/app.css
new file mode 100644
index 000000000..b5c61c956
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/app.css
@@ -0,0 +1,3 @@
+@tailwind base;
+@tailwind components;
+@tailwind utilities;
diff --git a/rust/vetkeys/password_manager/frontend/src/assets/svelte.svg b/rust/vetkeys/password_manager/frontend/src/assets/svelte.svg
new file mode 100644
index 000000000..c5e08481f
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/assets/svelte.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Disclaimer.svelte b/rust/vetkeys/password_manager/frontend/src/components/Disclaimer.svelte
new file mode 100644
index 000000000..2ded84f8f
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Disclaimer.svelte
@@ -0,0 +1,26 @@
+
+
+{#if !isDismissed}
+
+{/if}
diff --git a/rust/vetkeys/password_manager/frontend/src/components/DisclaimerCopy.svelte b/rust/vetkeys/password_manager/frontend/src/components/DisclaimerCopy.svelte
new file mode 100644
index 000000000..336ffde7d
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/DisclaimerCopy.svelte
@@ -0,0 +1,5 @@
+
+
+Disclaimer: This sample dapp is intended exclusively for experimental
+purpose. You are advised not to use this dapp for storing your critical data such
+as keys or passwords.
diff --git a/rust/vetkeys/password_manager/frontend/src/components/EditPassword.svelte b/rust/vetkeys/password_manager/frontend/src/components/EditPassword.svelte
new file mode 100644
index 000000000..73cc65f46
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/EditPassword.svelte
@@ -0,0 +1,309 @@
+
+
+{#if editedPassword.parentVaultName.length > 0}
+
+ Edit password
+
+ {#if !deleting}
+
+ {/if}
+
+ {deleting ? "Deleting..." : ""}
+
+
+
+ {#if $vaultsStore.state === "loaded"}
+
+
+
+
+
+
+
+
+ Back
+
+
+ {updating ? "Saving..." : "Save"}
+
+ {:else if $vaultsStore.state === "loading"}
+ Loading password...
+ {/if}
+
+{:else}
+
+
+ {#if $vaultsStore.state === "loading"}
+
+ Loading password...
+ {:else if $vaultsStore.state === "loaded"}
+ Could not find password.
+ {/if}
+
+{/if}
diff --git a/rust/vetkeys/password_manager/frontend/src/components/EditVault.svelte b/rust/vetkeys/password_manager/frontend/src/components/EditVault.svelte
new file mode 100644
index 000000000..5c156fcc8
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/EditVault.svelte
@@ -0,0 +1,86 @@
+
+
+{#if editedVault}
+
+ Edit vault
+
+ {#if !deleting}
+
+ {/if}
+
+ {deleting ? "Deleting..." : ""}
+
+
+
+ {#if $vaultsStore.state === "loaded"}
+
+
+ {:else if $vaultsStore.state === "loading"}
+ Loading vaults...
+ {/if}
+
+{:else}
+
+
+ {#if $vaultsStore.state === "loading"}
+
+ Loading vault...
+ {:else if $vaultsStore.state === "loaded"}
+ Could not find vault.
+ {/if}
+
+{/if}
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Header.svelte b/rust/vetkeys/password_manager/frontend/src/components/Header.svelte
new file mode 100644
index 000000000..9245e48b6
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Header.svelte
@@ -0,0 +1,27 @@
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Hero.svelte b/rust/vetkeys/password_manager/frontend/src/components/Hero.svelte
new file mode 100644
index 000000000..3f7ba7b22
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Hero.svelte
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Password Manager
+
+
+ Your private passwords on the Internet Computer.
+
+
+ A safe place to store your personal lists, thoughts, ideas or
+ passphrases and much more...
+
+
+ {#if auth.state === "initializing-auth"}
+
+
+ Initializing...
+
+ {:else if auth.state === "anonymous"}
+
login()}
+ >Please login to start storing passwords
+ {:else if auth.state === "error"}
+
An error occurred.
+ {/if}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/LayoutAuthenticated.svelte b/rust/vetkeys/password_manager/frontend/src/components/LayoutAuthenticated.svelte
new file mode 100644
index 000000000..090735f21
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/LayoutAuthenticated.svelte
@@ -0,0 +1,29 @@
+
+
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/NewPassword.svelte b/rust/vetkeys/password_manager/frontend/src/components/NewPassword.svelte
new file mode 100644
index 000000000..7270bc0bb
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/NewPassword.svelte
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {creating ? "Adding..." : "Add password"}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Notifications.svelte b/rust/vetkeys/password_manager/frontend/src/components/Notifications.svelte
new file mode 100644
index 000000000..af1b01eb5
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Notifications.svelte
@@ -0,0 +1,22 @@
+
+
+
+ {#each $notifications as n (n.id)}
+
+ {/each}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Password.svelte b/rust/vetkeys/password_manager/frontend/src/components/Password.svelte
new file mode 100644
index 000000000..9b30c30a2
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Password.svelte
@@ -0,0 +1,106 @@
+
+
+
+
+ Password: {password.passwordName}
+
+
+ {#if $vaultsStore.state === "loaded" && $vaultsStore.list.length > 0}
+ New password
+ {/if}
+
+
+
+
+ {#if $vaultsStore.state === "loading"}
+
+ Loading password...
+ {:else if $vaultsStore.state === "loaded"}
+ {#if password.parentVaultName === ""}
+
+ There is no such password in this vault.
+
+
+ {:else}
+
+
+
+ {password.passwordName}: "{password.content}"
+
+
+
+ {/if}
+
+
+ {/if}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/PasswordEditor.svelte b/rust/vetkeys/password_manager/frontend/src/components/PasswordEditor.svelte
new file mode 100644
index 000000000..a27c1ba12
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/PasswordEditor.svelte
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Passwords.svelte b/rust/vetkeys/password_manager/frontend/src/components/Passwords.svelte
new file mode 100644
index 000000000..70e7f30b3
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Passwords.svelte
@@ -0,0 +1,79 @@
+
+
+
+ Your passwords
+
+ {#if $vaultsStore.state === "loaded" && $vaultsStore.list.length > 0}
+ New Password
+ {/if}
+
+
+
+ {#if $vaultsStore.state === "loading"}
+
+ Loading passwords...
+ {:else if $vaultsStore.state === "loaded"}
+ {#if $vaultsStore.list.length > 0}
+
+
+
+
+
+ {#each filteredVaults as vault (vault.name)}
+ {#each Array.from(vault.passwords.map(([, password]) => password)) as password (password.passwordName)}
+
+ {/each}
+ {/each}
+
+ {:else}
+ You don't have any notes.
+
+ {/if}
+ {:else if $vaultsStore.state === "error"}
+ Could not load passwords.
+ {/if}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/SharingEditor.svelte b/rust/vetkeys/password_manager/frontend/src/components/SharingEditor.svelte
new file mode 100644
index 000000000..53d6b644f
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/SharingEditor.svelte
@@ -0,0 +1,218 @@
+
+
+Users
+{#if canManage}
+
+ Add users by their principal to allow them viewing or editing the vault.
+
+{:else}
+
+ This vault is shared with you. It is
+ owned by {editedVault.owner} .
+
+ Users with whom the vault is shared:
+{/if}
+
+ {#each editedVault.users as sharing (sharing[0].toText())}
+
{
+ void remove(sharing[0]);
+ }}
+ disabled={adding || removing || !canManage}
+ >
+ {accessRightsToString(sharing[1])} {sharing[0]}
+
+
+
+
+ {/each}
+
+
+ user[0].compareTo(Principal.fromText(newSharing)) === "eq",
+ )) ||
+ adding ||
+ removing}
+ hidden={!canManage}
+ >
+ read
+ read-write
+ read-write-manage
+
+
+ user[0].compareTo(Principal.fromText(newSharing)) === "eq",
+ )) ||
+ adding ||
+ removing}
+ >{adding ? "Adding..." : removing ? "Removing... " : "Add"}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/SidebarLayout.svelte b/rust/vetkeys/password_manager/frontend/src/components/SidebarLayout.svelte
new file mode 100644
index 000000000..94959e666
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/SidebarLayout.svelte
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+ VetKD Password Manager
+
+
+
My Principal:
+
+ {$auth.state === "initialized"
+ ? $auth.client.getIdentity().getPrincipal().toText()
+ : Principal.anonymous().toText()}
+
+
+
+
+
+
+
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Spinner.svelte b/rust/vetkeys/password_manager/frontend/src/components/Spinner.svelte
new file mode 100644
index 000000000..cc26ba251
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Spinner.svelte
@@ -0,0 +1,5 @@
+
+
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Vault.svelte b/rust/vetkeys/password_manager/frontend/src/components/Vault.svelte
new file mode 100644
index 000000000..5c578a5fa
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Vault.svelte
@@ -0,0 +1,143 @@
+
+
+
+
+
+
+
+ Vault: {vault.name}
+
+
+ {#if $vaultsStore.state === "loaded" && $vaultsStore.list.length > 0}
+ New password
+ {/if}
+
+
+
+
+ {#if $vaultsStore.state === "loading"}
+
+ Loading vault...
+ {:else if $vaultsStore.state === "loaded"}
+
+
+ {vaultSummary}
+
+
+
+
+
+
+
+
+
Passwords
+
+ {#if vault.passwords.length === 0}
+
+ You don't have any passwords in this vault.
+
+
+ {:else}
+
+ {/if}
+
+
+ {/if}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/components/Vaults.svelte b/rust/vetkeys/password_manager/frontend/src/components/Vaults.svelte
new file mode 100644
index 000000000..fc99e9b3f
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/components/Vaults.svelte
@@ -0,0 +1,90 @@
+
+
+
+ Your vaults
+
+ {#if $vaultsStore.state === "loaded" && $vaultsStore.list.length > 0}
+ New password
+ {/if}
+
+
+
+ {#if $vaultsStore.state === "loading"}
+
+ Loading vaults...
+ {:else if $vaultsStore.state === "loaded"}
+ {#if $vaultsStore.list.length > 0}
+
+
+
+
+
+ {:else}
+
+ You don't have any vaults.
+
+
+ {/if}
+ {:else if $vaultsStore.state === "error"}
+ Could not load vaults.
+ {/if}
+
diff --git a/rust/vetkeys/password_manager/frontend/src/lib/encrypted_maps.ts b/rust/vetkeys/password_manager/frontend/src/lib/encrypted_maps.ts
new file mode 100644
index 000000000..2b2c7e071
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/lib/encrypted_maps.ts
@@ -0,0 +1,43 @@
+import "./init.ts";
+import { HttpAgent, type HttpAgentOptions } from "@dfinity/agent";
+import {
+ DefaultEncryptedMapsClient,
+ EncryptedMaps,
+} from "@dfinity/vetkeys/encrypted_maps";
+
+export async function createEncryptedMaps(
+ agentOptions?: HttpAgentOptions,
+): Promise {
+ const host =
+ process.env.DFX_NETWORK === "ic"
+ ? `https://${process.env.CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER}.ic0.app`
+ : "http://localhost:4943";
+ const hostOptions = { host };
+
+ if (!agentOptions) {
+ agentOptions = hostOptions;
+ } else {
+ agentOptions.host = hostOptions.host;
+ }
+
+ const agent = await HttpAgent.create({ ...agentOptions });
+ // Fetch root key for certificate validation during development
+ if (process.env.NODE_ENV !== "production") {
+ console.log(`Dev environment - fetching root key...`);
+
+ agent.fetchRootKey().catch((err) => {
+ console.warn(
+ "Unable to fetch root key. Check to ensure that your local replica is running",
+ );
+ console.error(err);
+ });
+ }
+
+ // Creates an actor with using the candid interface and the HttpAgent
+ return new EncryptedMaps(
+ new DefaultEncryptedMapsClient(
+ agent,
+ process.env.CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER,
+ ),
+ );
+}
diff --git a/rust/vetkeys/password_manager/frontend/src/lib/init.ts b/rust/vetkeys/password_manager/frontend/src/lib/init.ts
new file mode 100644
index 000000000..062c8af94
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/lib/init.ts
@@ -0,0 +1 @@
+window.global ||= window;
diff --git a/rust/vetkeys/password_manager/frontend/src/lib/password.ts b/rust/vetkeys/password_manager/frontend/src/lib/password.ts
new file mode 100644
index 000000000..e37c46204
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/lib/password.ts
@@ -0,0 +1,56 @@
+import type { Principal } from "@dfinity/principal";
+
+export interface PasswordModel {
+ owner: Principal;
+ parentVaultName: string;
+ passwordName: string;
+ content: string;
+}
+
+export function passwordFromContent(
+ owner: Principal,
+ parentVaultName: string,
+ passwordName: string,
+ content: string,
+): PasswordModel {
+ return {
+ owner,
+ parentVaultName,
+ passwordName,
+ content,
+ };
+}
+
+export function summarize(note: PasswordModel, maxLength = 50) {
+ const div = document.createElement("div");
+ div.innerHTML = note.content;
+
+ let text = div.innerText;
+ const title = extractTitleFromDomEl(div);
+ if (title) {
+ text = text.replace(title, "");
+ }
+
+ return text.slice(0, maxLength) + (text.length > maxLength ? "..." : "");
+}
+
+function extractTitleFromDomEl(el: HTMLElement): string {
+ const title = el.querySelector("h1");
+ if (title) {
+ return title.innerText;
+ }
+
+ const blockElements = el.querySelectorAll("h1,h2,p,li");
+ for (const el of blockElements) {
+ if (el.textContent && el.textContent.trim().length > 0) {
+ return el.textContent.trim();
+ }
+ }
+ return "";
+}
+
+export function extractTitle(html: string) {
+ const div = document.createElement("div");
+ div.innerHTML = html;
+ return extractTitleFromDomEl(div);
+}
diff --git a/rust/vetkeys/password_manager/frontend/src/lib/sleep.ts b/rust/vetkeys/password_manager/frontend/src/lib/sleep.ts
new file mode 100644
index 000000000..38caca0c1
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/lib/sleep.ts
@@ -0,0 +1,3 @@
+export function sleep(ms: number) {
+ return new Promise((resolve) => setTimeout(resolve, ms));
+}
diff --git a/rust/vetkeys/password_manager/frontend/src/lib/vault.ts b/rust/vetkeys/password_manager/frontend/src/lib/vault.ts
new file mode 100644
index 000000000..02dc5b712
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/lib/vault.ts
@@ -0,0 +1,60 @@
+import type { Principal } from "@dfinity/principal";
+import type { PasswordModel } from "./password";
+import type { AccessRights } from "@dfinity/vetkeys/encrypted_maps";
+
+export interface VaultModel {
+ owner: Principal;
+ name: string;
+ passwords: Array<[string, PasswordModel]>;
+ users: Array<[Principal, AccessRights]>;
+}
+
+export function vaultFromContent(
+ owner: Principal,
+ name: string,
+ passwords: Array<[string, PasswordModel]>,
+ users: Array<[Principal, AccessRights]>,
+): VaultModel {
+ return { owner, name, passwords, users };
+}
+
+export function summarize(vault: VaultModel, maxLength = 1500) {
+ const div = document.createElement("div");
+
+ div.innerHTML +=
+ "Owner: " +
+ vault.owner.toString() +
+ ", " +
+ vault.users.length +
+ " users";
+ div.innerHTML += ", " + vault.passwords.length + " passwords.\n";
+
+ let text = div.innerText;
+ const title = extractTitleFromDomEl(div);
+ if (title) {
+ text = text.replace(title, "");
+ }
+
+ return text.slice(0, maxLength) + (text.length > maxLength ? "..." : "");
+}
+
+function extractTitleFromDomEl(el: HTMLElement): string {
+ const title = el.querySelector("h1");
+ if (title) {
+ return title.innerText;
+ }
+
+ const blockElements = el.querySelectorAll("h1,h2,p,li");
+ for (const el of blockElements) {
+ if (el.textContent && el.textContent?.trim().length > 0) {
+ return el.textContent.trim();
+ }
+ }
+ return "";
+}
+
+export function extractTitle(html: string) {
+ const div = document.createElement("div");
+ div.innerHTML = html;
+ return extractTitleFromDomEl(div);
+}
diff --git a/rust/vetkeys/password_manager/frontend/src/main.ts b/rust/vetkeys/password_manager/frontend/src/main.ts
new file mode 100644
index 000000000..ff634fcc2
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/main.ts
@@ -0,0 +1,8 @@
+import "./app.css";
+import App from "./App.svelte";
+
+const app = new App({
+ target: document.body,
+});
+
+export default app;
diff --git a/rust/vetkeys/password_manager/frontend/src/store/auth.ts b/rust/vetkeys/password_manager/frontend/src/store/auth.ts
new file mode 100644
index 000000000..ec6547c8b
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/store/auth.ts
@@ -0,0 +1,116 @@
+import "../lib/init.ts";
+import { get, writable } from "svelte/store";
+import { AuthClient } from "@dfinity/auth-client";
+import type { JsonnableDelegationChain } from "@dfinity/identity/lib/cjs/identity/delegation";
+import { replace } from "svelte-spa-router";
+import { createEncryptedMaps } from "../lib/encrypted_maps.js";
+import { EncryptedMaps } from "@dfinity/vetkeys/encrypted_maps";
+
+export type AuthState =
+ | {
+ state: "initializing-auth";
+ }
+ | {
+ state: "anonymous";
+ client: AuthClient;
+ }
+ | {
+ state: "initialized";
+ encryptedMaps: EncryptedMaps;
+ client: AuthClient;
+ }
+ | {
+ state: "error";
+ error: string;
+ };
+
+export const auth = writable({
+ state: "initializing-auth",
+});
+
+async function initAuth() {
+ const client = await AuthClient.create();
+ if (await client.isAuthenticated()) {
+ void authenticate(client);
+ } else {
+ auth.update(() => ({
+ state: "anonymous",
+ client,
+ }));
+ }
+}
+
+void initAuth();
+
+export function login() {
+ const currentAuth = get(auth);
+
+ if (currentAuth.state === "anonymous") {
+ void currentAuth.client.login({
+ maxTimeToLive: BigInt(1800) * BigInt(1_000_000_000),
+ identityProvider:
+ process.env.DFX_NETWORK === "ic"
+ ? "https://identity.ic0.app/#authorize"
+ : `http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize`,
+ onSuccess: () => authenticate(currentAuth.client),
+ });
+ }
+}
+
+export async function logout() {
+ const currentAuth = get(auth);
+
+ if (currentAuth.state === "initialized") {
+ await currentAuth.client.logout();
+ auth.update(() => ({
+ state: "anonymous",
+ client: currentAuth.client,
+ }));
+ void replace("/");
+ }
+}
+
+export async function authenticate(client: AuthClient) {
+ handleSessionTimeout();
+
+ try {
+ const encryptedMaps = await createEncryptedMaps({
+ identity: client.getIdentity(),
+ });
+
+ auth.update(() => ({
+ state: "initialized",
+ encryptedMaps,
+ client,
+ }));
+ } catch (e) {
+ auth.update(() => ({
+ state: "error",
+ error: (e as Error).message || "An error occurred",
+ }));
+ }
+}
+
+// set a timer when the II session will expire and log the user out
+function handleSessionTimeout() {
+ // upon login the localstorage items may not be set, wait for next tick
+ setTimeout(() => {
+ try {
+ const delegation = JSON.parse(
+ window.localStorage.getItem("ic-delegation") || "{}",
+ ) as JsonnableDelegationChain;
+
+ const expirationTimeMs =
+ Number.parseInt(
+ delegation.delegations[0].delegation.expiration,
+ 16,
+ ) / 1000000;
+
+ setTimeout(() => {
+ void logout();
+ }, expirationTimeMs - Date.now());
+ } catch {
+ console.error("Could not handle delegation expiry.");
+ }
+ });
+}
diff --git a/rust/vetkeys/password_manager/frontend/src/store/draft.ts b/rust/vetkeys/password_manager/frontend/src/store/draft.ts
new file mode 100644
index 000000000..05835819e
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/store/draft.ts
@@ -0,0 +1,36 @@
+import { writable } from "svelte/store";
+import { auth } from "./auth";
+
+interface DraftModel {
+ content: string;
+}
+
+let initialDraft: DraftModel = {
+ content: "",
+};
+
+try {
+ const getDraft = localStorage.getItem("draft");
+ if (getDraft) {
+ const savedDraft: DraftModel = JSON.parse(getDraft) as DraftModel;
+ if ("content" in savedDraft && "tags" in savedDraft) {
+ initialDraft = savedDraft;
+ }
+ } else {
+ throw new Error("Draft not found");
+ }
+} catch {
+ // ignore error
+}
+
+export const draft = writable(initialDraft);
+
+draft.subscribe((draft) => {
+ localStorage.setItem("draft", JSON.stringify(draft));
+});
+
+auth.subscribe(($auth) => {
+ if ($auth.state === "anonymous") {
+ draft.set(initialDraft);
+ }
+});
diff --git a/rust/vetkeys/password_manager/frontend/src/store/notifications.ts b/rust/vetkeys/password_manager/frontend/src/store/notifications.ts
new file mode 100644
index 000000000..d87630153
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/store/notifications.ts
@@ -0,0 +1,30 @@
+import { writable } from "svelte/store";
+
+export interface Notification {
+ type: "error" | "info" | "success";
+ message: string;
+ id: number;
+}
+
+export type NewNotification = Omit;
+
+let nextId = 0;
+
+export const notifications = writable([]);
+
+export function addNotification(notification: NewNotification, timeout = 2000) {
+ const id = nextId++;
+
+ notifications.update(($n) => [...$n, { ...notification, id }]);
+
+ setTimeout(() => {
+ notifications.update(($n) => $n.filter((n) => n.id != id));
+ }, timeout);
+}
+
+export function showError(e: Error, message: string): never {
+ addNotification({ type: "error", message });
+ console.error(e);
+ console.error(e.stack);
+ throw e;
+}
diff --git a/rust/vetkeys/password_manager/frontend/src/store/vaults.ts b/rust/vetkeys/password_manager/frontend/src/store/vaults.ts
new file mode 100644
index 000000000..0abfadf65
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/store/vaults.ts
@@ -0,0 +1,166 @@
+import { writable } from "svelte/store";
+import { passwordFromContent, type PasswordModel } from "../lib/password";
+import { vaultFromContent, type VaultModel } from "../lib/vault";
+import { auth } from "./auth";
+import { showError } from "./notifications";
+import {
+ type AccessRights,
+ EncryptedMaps,
+} from "@dfinity/vetkeys/encrypted_maps";
+import type { Principal } from "@dfinity/principal";
+
+export const vaultsStore = writable<
+ | {
+ state: "uninitialized";
+ }
+ | {
+ state: "loading";
+ }
+ | {
+ state: "loaded";
+ list: VaultModel[];
+ }
+ | {
+ state: "error";
+ }
+>({ state: "uninitialized" });
+
+let vaultPollerHandle: ReturnType | null;
+
+function updateVaults(vaults: VaultModel[]) {
+ vaultsStore.set({
+ state: "loaded",
+ list: vaults,
+ });
+}
+
+export async function refreshVaults(encryptedMaps: EncryptedMaps) {
+ const allMaps = await encryptedMaps.getAllAccessibleMaps();
+ const vaults = allMaps.map((mapData) => {
+ const vaultName = new TextDecoder().decode(mapData.mapName);
+ const passwords = new Array<[string, PasswordModel]>();
+ for (const [passwordNameBytes, data] of mapData.keyvals) {
+ const passwordName = new TextDecoder().decode(passwordNameBytes);
+ const passwordContent = new TextDecoder().decode(
+ Uint8Array.from(data),
+ );
+ const password = passwordFromContent(
+ mapData.mapOwner,
+ vaultName,
+ passwordName,
+ passwordContent,
+ );
+ passwords.push([passwordName, password]);
+ }
+ return vaultFromContent(
+ mapData.mapOwner,
+ vaultName,
+ passwords,
+ mapData.accessControl,
+ );
+ });
+
+ updateVaults(vaults);
+}
+
+export async function addPassword(
+ password: PasswordModel,
+ encryptedMaps: EncryptedMaps,
+) {
+ await encryptedMaps.setValue(
+ password.owner,
+ new TextEncoder().encode(password.parentVaultName),
+ new TextEncoder().encode(password.passwordName),
+ new TextEncoder().encode(password.content),
+ );
+}
+
+export async function removePassword(
+ password: PasswordModel,
+ encryptedMaps: EncryptedMaps,
+) {
+ await encryptedMaps.removeEncryptedValue(
+ password.owner,
+ new TextEncoder().encode(password.parentVaultName),
+ new TextEncoder().encode(password.passwordName),
+ );
+}
+
+export async function updatePassword(
+ password: PasswordModel,
+ encryptedMaps: EncryptedMaps,
+) {
+ await encryptedMaps.setValue(
+ password.owner,
+ new TextEncoder().encode(password.parentVaultName),
+ new TextEncoder().encode(password.passwordName),
+ new TextEncoder().encode(password.content),
+ );
+}
+
+export async function addUser(
+ owner: Principal,
+ vaultName: string,
+ user: Principal,
+ userRights: AccessRights,
+ encryptedMaps: EncryptedMaps,
+) {
+ await encryptedMaps.setUserRights(
+ owner,
+ new TextEncoder().encode(vaultName),
+ user,
+ userRights,
+ );
+}
+
+export async function removeUser(
+ owner: Principal,
+ vaultName: string,
+ user: Principal,
+ encryptedMaps: EncryptedMaps,
+) {
+ await encryptedMaps.removeUser(
+ owner,
+ new TextEncoder().encode(vaultName),
+ user,
+ );
+}
+
+auth.subscribe((auth) => {
+ void (async () => {
+ if (auth && auth.state === "initialized") {
+ if (vaultPollerHandle !== null) {
+ clearInterval(vaultPollerHandle);
+ vaultPollerHandle = null;
+ }
+
+ vaultsStore.set({
+ state: "loading",
+ });
+ try {
+ await refreshVaults(auth.encryptedMaps).catch((e: Error) =>
+ showError(e, "Could not poll vaults."),
+ );
+
+ vaultPollerHandle = setInterval(() => {
+ void (async () => {
+ await refreshVaults(auth.encryptedMaps).catch(
+ (e: Error) =>
+ showError(e, "Could not poll vaults."),
+ );
+ });
+ }, 3000);
+ } catch {
+ vaultsStore.set({
+ state: "error",
+ });
+ }
+ } else if (auth.state === "anonymous" && vaultPollerHandle !== null) {
+ clearInterval(vaultPollerHandle);
+ vaultPollerHandle = null;
+ vaultsStore.set({
+ state: "uninitialized",
+ });
+ }
+ })();
+});
diff --git a/rust/vetkeys/password_manager/frontend/src/vite-env.d.ts b/rust/vetkeys/password_manager/frontend/src/vite-env.d.ts
new file mode 100644
index 000000000..4078e7476
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/src/vite-env.d.ts
@@ -0,0 +1,2 @@
+///
+///
diff --git a/rust/vetkeys/password_manager/frontend/svelte.config.js b/rust/vetkeys/password_manager/frontend/svelte.config.js
new file mode 100644
index 000000000..b0683fd24
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/svelte.config.js
@@ -0,0 +1,7 @@
+import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
+
+export default {
+ // Consult https://svelte.dev/docs#compile-time-svelte-preprocess
+ // for more information about preprocessors
+ preprocess: vitePreprocess(),
+}
diff --git a/rust/vetkeys/password_manager/frontend/tailwind.config.cjs b/rust/vetkeys/password_manager/frontend/tailwind.config.cjs
new file mode 100644
index 000000000..4bcec2567
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/tailwind.config.cjs
@@ -0,0 +1,6 @@
+import daisyui from "daisyui";
+
+export default {
+ content: ["./index.html", "./src/**/*.{svelte,js,ts,jsx,tsx}"],
+ plugins: [daisyui],
+};
diff --git a/rust/vetkeys/password_manager/frontend/tsconfig.json b/rust/vetkeys/password_manager/frontend/tsconfig.json
new file mode 100644
index 000000000..2f9865d46
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/tsconfig.json
@@ -0,0 +1,25 @@
+{
+ "extends": "@tsconfig/svelte/tsconfig.json",
+ "compilerOptions": {
+ "target": "ES2020",
+ "useDefineForClassFields": true,
+ "module": "ES2020",
+ "lib": [
+ "ES2020",
+ "DOM",
+ "DOM.Iterable"
+ ],
+ "skipLibCheck": true,
+ /* Bundler mode */
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "isolatedModules": true,
+ "moduleDetection": "force",
+ "noEmit": true,
+ "noUncheckedSideEffectImports": true
+ },
+ "include": [
+ "src"
+ ]
+ }
+
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/frontend/vite.config.ts b/rust/vetkeys/password_manager/frontend/vite.config.ts
new file mode 100644
index 000000000..811003329
--- /dev/null
+++ b/rust/vetkeys/password_manager/frontend/vite.config.ts
@@ -0,0 +1,44 @@
+import { defineConfig } from 'vite'
+import { svelte } from '@sveltejs/vite-plugin-svelte'
+import tailwindcss from 'tailwindcss'
+import autoprefixer from "autoprefixer";
+import css from 'rollup-plugin-css-only';
+import typescript from '@rollup/plugin-typescript';
+import environment from 'vite-plugin-environment';
+import path from 'path';
+
+// https://vite.dev/config/
+export default defineConfig({
+ plugins: [
+ svelte(),
+ css({ output: "bundle.css" }),
+ typescript({
+ inlineSources: true,
+ }),
+ environment("all", { prefix: "CANISTER_" }),
+ environment("all", { prefix: "DFX_" }),
+ ],
+ css: {
+ postcss: {
+ plugins: [autoprefixer(), tailwindcss()],
+ }
+ },
+ build: {
+ sourcemap: true,
+ rollupOptions: {
+ output: {
+ inlineDynamicImports: true,
+ },
+ },
+ },
+ resolve: {
+ alias: {
+ 'ic_vetkeys': path.resolve(__dirname, '../../../frontend/ic_vetkeys/src'),
+ 'ic_vetkeys/encrypted_maps': path.resolve(__dirname, '../../../frontend/ic_vetkeys/src/encrypted_maps'),
+ }
+ },
+ root: "./",
+ server: {
+ hmr: false
+ }
+})
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/motoko/backend/.prettierrc b/rust/vetkeys/password_manager/motoko/backend/.prettierrc
new file mode 100644
index 000000000..a42bc32c3
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/backend/.prettierrc
@@ -0,0 +1,8 @@
+{
+ "overrides": [{
+ "files": "*.mo",
+ "options": {
+ "tabWidth": 4
+ }
+ }]
+ }
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/motoko/backend/Makefile b/rust/vetkeys/password_manager/motoko/backend/Makefile
new file mode 100644
index 000000000..ffaeb9642
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/backend/Makefile
@@ -0,0 +1,14 @@
+PWD:=$(shell pwd)
+
+.PHONY: compile-wasm
+.SILENT: compile-wasm
+compile-wasm:
+ icp build
+
+# Test the APIs of this canister using the respective Rust canister tests.
+# This has the advantage that the tests are consistent (less room for bugs by having only one implementation of the tests) and the checked expected behavior is consistent across Rust and Motoko.
+.PHONY: test
+.SILENT: test
+test: compile-wasm
+ @echo "Testing Motoko canister WASM: $(PWD)/.icp/cache/artifacts/ic_vetkeys_encrypted_maps_canister"
+ CUSTOM_WASM_PATH=$(PWD)/.icp/cache/artifacts/ic_vetkeys_encrypted_maps_canister cargo test -p ic-vetkeys-encrypted-maps-canister
diff --git a/rust/vetkeys/password_manager/motoko/backend/README.md b/rust/vetkeys/password_manager/motoko/backend/README.md
new file mode 100644
index 000000000..71f0ac924
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/backend/README.md
@@ -0,0 +1,7 @@
+# ic-vetkeys-encrypted-maps-canister
+
+The canister implemented in this folder directly exposes the methods of the encrypted maps.
+This is useful for:
+
+1. running canister tests
+2. implementing dapps that only require encrypted maps
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/motoko/backend/icp.yaml b/rust/vetkeys/password_manager/motoko/backend/icp.yaml
new file mode 100644
index 000000000..b4101fe9c
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/backend/icp.yaml
@@ -0,0 +1,7 @@
+canisters:
+ - name: ic_vetkeys_encrypted_maps_canister
+ recipe:
+ type: "@dfinity/motoko@v4.1.0"
+ configuration:
+ main: src/Main.mo
+ args: --enhanced-orthogonal-persistence
diff --git a/rust/vetkeys/password_manager/motoko/backend/mops.toml b/rust/vetkeys/password_manager/motoko/backend/mops.toml
new file mode 100644
index 000000000..8cc38c25d
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/backend/mops.toml
@@ -0,0 +1,16 @@
+[toolchain]
+moc = "1.5.0"
+
+[package]
+name = "ic-vetkeys-encrypted-maps-canister"
+version = "0.1.0"
+repository = "https://github.com/dfinity/vetkeys/backend/mo/canisters/ic_vetkeys_encrypted_maps_canister"
+keywords = [
+ "vetkeys,vetkd,encryption,privacy,signature,BLS,key ",
+ "derivation,IBE"
+]
+license = "Apache-2.0"
+
+[dependencies]
+base = "0.14.6"
+ic-vetkeys = "0.4.0"
diff --git a/rust/vetkeys/password_manager/motoko/backend/src/Main.mo b/rust/vetkeys/password_manager/motoko/backend/src/Main.mo
new file mode 100644
index 000000000..ad0c468bf
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/backend/src/Main.mo
@@ -0,0 +1,221 @@
+import IcVetkeys "mo:ic-vetkeys";
+import Types "mo:ic-vetkeys/Types";
+import Principal "mo:base/Principal";
+import Text "mo:base/Text";
+import Blob "mo:base/Blob";
+import Result "mo:base/Result";
+import Array "mo:base/Array";
+
+persistent actor class (keyName : Text) {
+ let encryptedMapsState = IcVetkeys.EncryptedMaps.newEncryptedMapsState({ curve = #bls12_381_g2; name = keyName }, "password_manager_example_dapp");
+ transient let encryptedMaps = IcVetkeys.EncryptedMaps.EncryptedMaps(encryptedMapsState, Types.accessRightsOperations());
+
+ /// In this canister, we use the `ByteBuf` type to represent blobs. The reason is that we want to be consistent with the Rust canister implementation.
+ /// Unfortunately, the `Blob` type cannot be serialized/deserialized in the current Rust implementation efficiently without nesting it in another type.
+ public type ByteBuf = { inner : Blob };
+
+ public type EncryptedMapData = {
+ map_owner : Principal;
+ map_name : ByteBuf;
+ keyvals : [(ByteBuf, ByteBuf)];
+ access_control : [(Principal, Types.AccessRights)];
+ };
+
+ /// The result type compatible with Rust's `Result`.
+ public type Result = {
+ #Ok : Ok;
+ #Err : Err;
+ };
+
+ public query (msg) func get_accessible_shared_map_names() : async [(Principal, ByteBuf)] {
+ Array.map<(Principal, Blob), (Principal, ByteBuf)>(
+ encryptedMaps.getAccessibleSharedMapNames(msg.caller),
+
+ func((principal, blob) : (Principal, Blob)) {
+ (principal, { inner = blob });
+ },
+ );
+ };
+
+ public query (msg) func get_shared_user_access_for_map(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ ) : async Result<[(Principal, Types.AccessRights)], Text> {
+ convertResult(encryptedMaps.getSharedUserAccessForMap(msg.caller, (map_owner, map_name.inner)));
+ };
+
+ public query (msg) func get_encrypted_values_for_map(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ ) : async Result<[(ByteBuf, ByteBuf)], Text> {
+ let result = encryptedMaps.getEncryptedValuesForMap(msg.caller, (map_owner, map_name.inner));
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(values)) {
+ #Ok(
+ Array.map<(Blob, Blob), (ByteBuf, ByteBuf)>(
+ values,
+ func((blob1, blob2) : (Blob, Blob)) {
+ ({ inner = blob1 }, { inner = blob2 });
+ },
+ )
+ );
+ };
+ };
+ };
+
+ public query (msg) func get_all_accessible_encrypted_values() : async [((Principal, ByteBuf), [(ByteBuf, ByteBuf)])] {
+ Array.map<((Principal, Blob), [(Blob, Blob)]), ((Principal, ByteBuf), [(ByteBuf, ByteBuf)])>(
+ encryptedMaps.getAllAccessibleEncryptedValues(msg.caller),
+ func(((owner, map_name), values) : ((Principal, Blob), [(Blob, Blob)])) {
+ (
+ (owner, { inner = map_name }),
+ Array.map<(Blob, Blob), (ByteBuf, ByteBuf)>(
+ values,
+ func((blob1, blob2) : (Blob, Blob)) {
+ ({ inner = blob1 }, { inner = blob2 });
+ },
+ ),
+ );
+ },
+ );
+ };
+
+ public query (msg) func get_all_accessible_encrypted_maps() : async [EncryptedMapData] {
+ Array.map, EncryptedMapData>(
+ encryptedMaps.getAllAccessibleEncryptedMaps(msg.caller),
+ func(map : IcVetkeys.EncryptedMaps.EncryptedMapData) : EncryptedMapData {
+ {
+ map_owner = map.map_owner;
+ map_name = { inner = map.map_name };
+ keyvals = Array.map<(Blob, Blob), (ByteBuf, ByteBuf)>(
+ map.keyvals,
+ func((blob1, blob2) : (Blob, Blob)) {
+ ({ inner = blob1 }, { inner = blob2 });
+ },
+ );
+ access_control = map.access_control;
+ };
+ },
+ );
+ };
+
+ public query (msg) func get_encrypted_value(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ map_key : ByteBuf,
+ ) : async Result {
+ let result = encryptedMaps.getEncryptedValue(msg.caller, (map_owner, map_name.inner), map_key.inner);
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(null)) { #Ok(null) };
+ case (#ok(?blob)) { #Ok(?{ inner = blob }) };
+ };
+ };
+
+ public shared (msg) func remove_map_values(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ ) : async Result<[ByteBuf], Text> {
+ let result = encryptedMaps.removeMapValues(msg.caller, (map_owner, map_name.inner));
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(values)) {
+ #Ok(
+ Array.map(
+ values,
+ func(blob : Blob) : ByteBuf {
+ { inner = blob };
+ },
+ )
+ );
+ };
+ };
+ };
+
+ public query (msg) func get_owned_non_empty_map_names() : async [ByteBuf] {
+ Array.map(
+ encryptedMaps.getOwnedNonEmptyMapNames(msg.caller),
+ func(blob : Blob) : ByteBuf {
+ { inner = blob };
+ },
+ );
+ };
+
+ public shared (msg) func insert_encrypted_value(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ map_key : ByteBuf,
+ value : ByteBuf,
+ ) : async Result {
+ let result = encryptedMaps.insertEncryptedValue(msg.caller, (map_owner, map_name.inner), map_key.inner, value.inner);
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(null)) { #Ok(null) };
+ case (#ok(?blob)) { #Ok(?{ inner = blob }) };
+ };
+ };
+
+ public shared (msg) func remove_encrypted_value(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ map_key : ByteBuf,
+ ) : async Result {
+ let result = encryptedMaps.removeEncryptedValue(msg.caller, (map_owner, map_name.inner), map_key.inner);
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(null)) { #Ok(null) };
+ case (#ok(?blob)) { #Ok(?{ inner = blob }) };
+ };
+ };
+
+ public shared func get_vetkey_verification_key() : async ByteBuf {
+ let inner = await encryptedMaps.getVetkeyVerificationKey();
+ { inner };
+ };
+
+ public shared (msg) func get_encrypted_vetkey(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ transport_key : ByteBuf,
+ ) : async Result {
+ let result = await encryptedMaps.getEncryptedVetkey(msg.caller, (map_owner, map_name.inner), transport_key.inner);
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(vetkey)) { #Ok({ inner = vetkey }) };
+ };
+ };
+
+ public query (msg) func get_user_rights(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ user : Principal,
+ ) : async Result {
+ convertResult(encryptedMaps.getUserRights(msg.caller, (map_owner, map_name.inner), user));
+ };
+
+ public shared (msg) func set_user_rights(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ user : Principal,
+ access_rights : Types.AccessRights,
+ ) : async Result {
+ convertResult(encryptedMaps.setUserRights(msg.caller, (map_owner, map_name.inner), user, access_rights));
+ };
+
+ public shared (msg) func remove_user(
+ map_owner : Principal,
+ map_name : ByteBuf,
+ user : Principal,
+ ) : async Result {
+ convertResult(encryptedMaps.removeUser(msg.caller, (map_owner, map_name.inner), user));
+ };
+
+ /// Convert to the result type compatible with Rust's `Result`
+ private func convertResult(result : Result.Result) : Result {
+ switch (result) {
+ case (#err(e)) { #Err(e) };
+ case (#ok(o)) { #Ok(o) };
+ };
+ };
+};
diff --git a/rust/vetkeys/password_manager/motoko/dfx.json b/rust/vetkeys/password_manager/motoko/dfx.json
new file mode 100644
index 000000000..3118676e7
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/dfx.json
@@ -0,0 +1,37 @@
+{
+ "canisters": {
+ "ic_vetkeys_encrypted_maps_canister": {
+ "main": "backend/src/Main.mo",
+ "type": "motoko",
+ "args": "--enhanced-orthogonal-persistence",
+ "init_arg": "(\"test_key_1\")"
+ },
+ "internet-identity": {
+ "candid": "https://github.com/dfinity/internet-identity/releases/download/release-2026-03-16/internet_identity.did",
+ "type": "custom",
+ "specified_id": "rdmx6-jaaaa-aaaaa-aaadq-cai",
+ "remote": {
+ "id": {
+ "ic": "rdmx6-jaaaa-aaaaa-aaadq-cai"
+ }
+ },
+ "wasm": "https://github.com/dfinity/internet-identity/releases/download/release-2026-03-16/internet_identity_dev.wasm.gz"
+ },
+ "www": {
+ "dependencies": ["ic_vetkeys_encrypted_maps_canister", "internet-identity"],
+ "build": ["cd frontend && npm i --include=dev && npm run build && cd - && rm -r dist > /dev/null 2>&1; mv frontend/dist ./"],
+ "frontend": {
+ "entrypoint": "dist/index.html"
+ },
+ "source": ["dist/"],
+ "type": "assets",
+ "output_env_file": "frontend/.env"
+ }
+ },
+ "defaults": {
+ "build": {
+ "packtool": "npx ic-mops sources",
+ "args": ""
+ }
+ }
+}
diff --git a/rust/vetkeys/password_manager/motoko/frontend b/rust/vetkeys/password_manager/motoko/frontend
new file mode 120000
index 000000000..af288785f
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/frontend
@@ -0,0 +1 @@
+../frontend
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/motoko/mops.toml b/rust/vetkeys/password_manager/motoko/mops.toml
new file mode 100644
index 000000000..593456675
--- /dev/null
+++ b/rust/vetkeys/password_manager/motoko/mops.toml
@@ -0,0 +1,13 @@
+[package]
+name = "ic-vetkeys-encrypted-maps-canister"
+version = "0.1.0"
+repository = "https://github.com/dfinity/vetkeys/examples/password_manager/motoko"
+keywords = [
+ "vetkeys,vetkd,encryption,privacy,signature,BLS,key ",
+ "derivation,IBE"
+]
+license = "Apache-2.0"
+
+[dependencies]
+base = "0.14.6"
+ic-vetkeys = "0.4.0"
diff --git a/rust/vetkeys/password_manager/rust/Cargo.toml b/rust/vetkeys/password_manager/rust/Cargo.toml
new file mode 100644
index 000000000..0169acf9f
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/Cargo.toml
@@ -0,0 +1,13 @@
+[workspace]
+members = ["backend"]
+resolver = "2"
+
+[workspace.dependencies]
+ic-cdk = "0.19.0"
+ic-stable-structures = "0.7.0"
+ic-vetkeys = "0.6.0"
+
+[profile.release]
+lto = true
+opt-level = 'z'
+panic = 'abort'
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/rust/backend/Cargo.toml b/rust/vetkeys/password_manager/rust/backend/Cargo.toml
new file mode 100644
index 000000000..cb662f05f
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/backend/Cargo.toml
@@ -0,0 +1,29 @@
+[package]
+name = "ic-vetkeys-encrypted-maps-canister"
+authors = ["DFINITY Stiftung"]
+version = "0.1.0"
+edition = "2021"
+license = "Apache-2.0"
+description = "# Basic Identity Based Encryption"
+repository = "https://github.com/dfinity/vetkeys"
+rust-version = "1.85.0"
+
+[lib]
+path = "src/lib.rs"
+crate-type = ["cdylib"]
+
+[dependencies]
+candid = "0.10.2"
+ic-cdk = { workspace = true }
+ic-dummy-getrandom-for-wasm = "0.1.0"
+ic-stable-structures = { workspace = true }
+ic-vetkeys = { workspace = true }
+serde = "1.0.217"
+
+[dev-dependencies]
+assert_matches = "1.5.0"
+pocket-ic = "9.0.0"
+rand = "0.8.5"
+rand_chacha = "0.3.1"
+reqwest = "0.12.12"
+strum = "0.27.1"
diff --git a/rust/vetkeys/password_manager/rust/backend/Makefile b/rust/vetkeys/password_manager/rust/backend/Makefile
new file mode 100644
index 000000000..b6dc7595e
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/backend/Makefile
@@ -0,0 +1,22 @@
+ROOT_DIR := $(shell git rev-parse --show-toplevel)
+
+.PHONY: compile-wasm
+.SILENT: compile-wasm
+compile-wasm:
+ cargo build --release --target wasm32-unknown-unknown
+
+.PHONY: test
+.SILENT: test
+test: compile-wasm
+ cargo test -p ic-vetkeys-encrypted-maps-canister
+
+.PHONY: extract-candid
+.SILENT: extract-candid
+extract-candid: compile-wasm
+ candid-extractor $(ROOT_DIR)/target/wasm32-unknown-unknown/release/ic_vetkeys_encrypted_maps_canister.wasm > ic_vetkeys_encrypted_maps_canister.did
+
+.PHONY: clean
+.SILENT: clean
+clean:
+ cargo clean
+ rm -rf .icp/cache
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/rust/backend/README.md b/rust/vetkeys/password_manager/rust/backend/README.md
new file mode 100644
index 000000000..71f0ac924
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/backend/README.md
@@ -0,0 +1,7 @@
+# ic-vetkeys-encrypted-maps-canister
+
+The canister implemented in this folder directly exposes the methods of the encrypted maps.
+This is useful for:
+
+1. running canister tests
+2. implementing dapps that only require encrypted maps
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/rust/backend/ic_vetkeys_encrypted_maps_canister.did b/rust/vetkeys/password_manager/rust/backend/ic_vetkeys_encrypted_maps_canister.did
new file mode 100644
index 000000000..f30499fd1
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/backend/ic_vetkeys_encrypted_maps_canister.did
@@ -0,0 +1,41 @@
+type AccessRights = variant { Read; ReadWrite; ReadWriteManage };
+type ByteBuf = record { inner : blob };
+type EncryptedMapData = record {
+ access_control : vec record { principal; AccessRights };
+ keyvals : vec record { ByteBuf; ByteBuf };
+ map_name : ByteBuf;
+ map_owner : principal;
+};
+type Result = variant { Ok : opt ByteBuf; Err : text };
+type Result_1 = variant { Ok : vec record { ByteBuf; ByteBuf }; Err : text };
+type Result_2 = variant { Ok : ByteBuf; Err : text };
+type Result_3 = variant {
+ Ok : vec record { principal; AccessRights };
+ Err : text;
+};
+type Result_4 = variant { Ok : opt AccessRights; Err : text };
+type Result_5 = variant { Ok : vec ByteBuf; Err : text };
+service : (text) -> {
+ get_accessible_shared_map_names : () -> (
+ vec record { principal; ByteBuf },
+ ) query;
+ get_all_accessible_encrypted_maps : () -> (vec EncryptedMapData) query;
+ get_all_accessible_encrypted_values : () -> (
+ vec record {
+ record { principal; ByteBuf };
+ vec record { ByteBuf; ByteBuf };
+ },
+ ) query;
+ get_encrypted_value : (principal, ByteBuf, ByteBuf) -> (Result) query;
+ get_encrypted_values_for_map : (principal, ByteBuf) -> (Result_1) query;
+ get_encrypted_vetkey : (principal, ByteBuf, ByteBuf) -> (Result_2);
+ get_owned_non_empty_map_names : () -> (vec ByteBuf) query;
+ get_shared_user_access_for_map : (principal, ByteBuf) -> (Result_3) query;
+ get_user_rights : (principal, ByteBuf, principal) -> (Result_4) query;
+ get_vetkey_verification_key : () -> (ByteBuf);
+ insert_encrypted_value : (principal, ByteBuf, ByteBuf, ByteBuf) -> (Result);
+ remove_encrypted_value : (principal, ByteBuf, ByteBuf) -> (Result);
+ remove_map_values : (principal, ByteBuf) -> (Result_5);
+ remove_user : (principal, ByteBuf, principal) -> (Result_4);
+ set_user_rights : (principal, ByteBuf, principal, AccessRights) -> (Result_4);
+}
diff --git a/rust/vetkeys/password_manager/rust/backend/src/lib.rs b/rust/vetkeys/password_manager/rust/backend/src/lib.rs
new file mode 100644
index 000000000..ee4034817
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/backend/src/lib.rs
@@ -0,0 +1,298 @@
+use std::cell::RefCell;
+
+use candid::Principal;
+use ic_cdk::management_canister::{VetKDCurve, VetKDKeyId};
+use ic_cdk::{init, query, update};
+use ic_stable_structures::memory_manager::{MemoryId, MemoryManager, VirtualMemory};
+use ic_stable_structures::storable::Blob;
+use ic_stable_structures::DefaultMemoryImpl;
+use ic_vetkeys::encrypted_maps::{EncryptedMapData, EncryptedMaps, VetKey, VetKeyVerificationKey};
+use ic_vetkeys::types::{AccessRights, ByteBuf, EncryptedMapValue, TransportKey};
+
+type Memory = VirtualMemory;
+type MapId = (Principal, ByteBuf);
+
+thread_local! {
+ static MEMORY_MANAGER: RefCell> =
+ RefCell::new(MemoryManager::init(DefaultMemoryImpl::default()));
+ static ENCRYPTED_MAPS: RefCell>> =
+ const { RefCell::new(None) };
+}
+
+#[init]
+fn init(key_name: String) {
+ let key_id = VetKDKeyId {
+ curve: VetKDCurve::Bls12_381_G2,
+ name: key_name,
+ };
+ ENCRYPTED_MAPS.with_borrow_mut(|encrypted_maps| {
+ encrypted_maps.replace(EncryptedMaps::init(
+ "encrypted_maps_dapp",
+ key_id,
+ id_to_memory(0),
+ id_to_memory(1),
+ id_to_memory(2),
+ id_to_memory(3),
+ ))
+ });
+}
+
+#[query]
+fn get_accessible_shared_map_names() -> Vec<(Principal, ByteBuf)> {
+ ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_accessible_shared_map_names(ic_cdk::api::msg_caller())
+ .into_iter()
+ .map(|map_id| (map_id.0, ByteBuf::from(map_id.1.as_ref().to_vec())))
+ .collect()
+ })
+}
+
+#[query]
+fn get_shared_user_access_for_map(
+ key_owner: Principal,
+ key_name: ByteBuf,
+) -> Result, String> {
+ let key_name = bytebuf_to_blob(key_name)?;
+ let key_id = (key_owner, key_name);
+ ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_shared_user_access_for_map(ic_cdk::api::msg_caller(), key_id)
+ })
+}
+
+#[query]
+fn get_encrypted_values_for_map(
+ map_owner: Principal,
+ map_name: ByteBuf,
+) -> Result, String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ let result = ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_encrypted_values_for_map(ic_cdk::api::msg_caller(), map_id)
+ });
+ result.map(|map_values| {
+ map_values
+ .into_iter()
+ .map(|(key, value)| (ByteBuf::from(key.as_slice().to_vec()), value))
+ .collect()
+ })
+}
+
+#[query]
+fn get_all_accessible_encrypted_values() -> Vec<(MapId, Vec<(ByteBuf, EncryptedMapValue)>)> {
+ ENCRYPTED_MAPS
+ .with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_all_accessible_encrypted_values(ic_cdk::api::msg_caller())
+ })
+ .into_iter()
+ .map(|((owner, map_name), encrypted_values)| {
+ (
+ (owner, ByteBuf::from(map_name.as_ref().to_vec())),
+ encrypted_values
+ .into_iter()
+ .map(|(key, value)| (ByteBuf::from(key.as_ref().to_vec()), value))
+ .collect(),
+ )
+ })
+ .collect()
+}
+
+#[query]
+fn get_all_accessible_encrypted_maps() -> Vec> {
+ ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_all_accessible_encrypted_maps(ic_cdk::api::msg_caller())
+ })
+}
+
+#[query]
+fn get_encrypted_value(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ map_key: ByteBuf,
+) -> Result, String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps.as_ref().unwrap().get_encrypted_value(
+ ic_cdk::api::msg_caller(),
+ map_id,
+ bytebuf_to_blob(map_key)?,
+ )
+ })
+}
+
+#[update]
+fn remove_map_values(
+ map_owner: Principal,
+ map_name: ByteBuf,
+) -> Result, String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ let result = ENCRYPTED_MAPS.with_borrow_mut(|encrypted_maps| {
+ encrypted_maps
+ .as_mut()
+ .unwrap()
+ .remove_map_values(ic_cdk::api::msg_caller(), map_id)
+ });
+ result.map(|removed| {
+ removed
+ .into_iter()
+ .map(|key| ByteBuf::from(key.as_ref().to_vec()))
+ .collect()
+ })
+}
+
+#[query]
+fn get_owned_non_empty_map_names() -> Vec {
+ ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_owned_non_empty_map_names(ic_cdk::api::msg_caller())
+ .into_iter()
+ .map(|map_name| ByteBuf::from(map_name.as_slice().to_vec()))
+ .collect()
+ })
+}
+
+#[update]
+fn insert_encrypted_value(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ map_key: ByteBuf,
+ value: EncryptedMapValue,
+) -> Result, String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ ENCRYPTED_MAPS.with_borrow_mut(|encrypted_maps| {
+ encrypted_maps.as_mut().unwrap().insert_encrypted_value(
+ ic_cdk::api::msg_caller(),
+ map_id,
+ bytebuf_to_blob(map_key)?,
+ value,
+ )
+ })
+}
+
+#[update]
+fn remove_encrypted_value(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ map_key: ByteBuf,
+) -> Result , String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ ENCRYPTED_MAPS.with_borrow_mut(|encrypted_maps| {
+ encrypted_maps.as_mut().unwrap().remove_encrypted_value(
+ ic_cdk::api::msg_caller(),
+ map_id,
+ bytebuf_to_blob(map_key)?,
+ )
+ })
+}
+
+#[update]
+async fn get_vetkey_verification_key() -> VetKeyVerificationKey {
+ ENCRYPTED_MAPS
+ .with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_vetkey_verification_key()
+ })
+ .await
+}
+
+#[update]
+async fn get_encrypted_vetkey(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ transport_key: TransportKey,
+) -> Result {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ Ok(ENCRYPTED_MAPS
+ .with_borrow(|encrypted_maps| {
+ encrypted_maps.as_ref().unwrap().get_encrypted_vetkey(
+ ic_cdk::api::msg_caller(),
+ map_id,
+ transport_key,
+ )
+ })?
+ .await)
+}
+
+#[query]
+fn get_user_rights(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ user: Principal,
+) -> Result, String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ ENCRYPTED_MAPS.with_borrow(|encrypted_maps| {
+ encrypted_maps
+ .as_ref()
+ .unwrap()
+ .get_user_rights(ic_cdk::api::msg_caller(), map_id, user)
+ })
+}
+
+#[update]
+fn set_user_rights(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ user: Principal,
+ access_rights: AccessRights,
+) -> Result , String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ ENCRYPTED_MAPS.with_borrow_mut(|encrypted_maps| {
+ encrypted_maps.as_mut().unwrap().set_user_rights(
+ ic_cdk::api::msg_caller(),
+ map_id,
+ user,
+ access_rights,
+ )
+ })
+}
+
+#[update]
+fn remove_user(
+ map_owner: Principal,
+ map_name: ByteBuf,
+ user: Principal,
+) -> Result , String> {
+ let map_name = bytebuf_to_blob(map_name)?;
+ let map_id = (map_owner, map_name);
+ ENCRYPTED_MAPS.with_borrow_mut(|encrypted_maps| {
+ encrypted_maps
+ .as_mut()
+ .unwrap()
+ .remove_user(ic_cdk::api::msg_caller(), map_id, user)
+ })
+}
+
+fn bytebuf_to_blob(buf: ByteBuf) -> Result, String> {
+ Blob::try_from(buf.as_ref()).map_err(|_| "too large input".to_string())
+}
+
+fn id_to_memory(id: u8) -> Memory {
+ MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(id)))
+}
+
+ic_cdk::export_candid!();
diff --git a/rust/vetkeys/password_manager/rust/dfx.json b/rust/vetkeys/password_manager/rust/dfx.json
new file mode 100644
index 000000000..356bdb3f5
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/dfx.json
@@ -0,0 +1,31 @@
+{
+ "canisters": {
+ "ic_vetkeys_encrypted_maps_canister": {
+ "candid": "backend/ic_vetkeys_encrypted_maps_canister.did",
+ "package": "ic-vetkeys-encrypted-maps-canister",
+ "type": "rust",
+ "init_arg": "(\"test_key_1\")"
+ },
+ "internet-identity": {
+ "candid": "https://github.com/dfinity/internet-identity/releases/download/release-2026-03-16/internet_identity.did",
+ "type": "custom",
+ "specified_id": "rdmx6-jaaaa-aaaaa-aaadq-cai",
+ "remote": {
+ "id": {
+ "ic": "rdmx6-jaaaa-aaaaa-aaadq-cai"
+ }
+ },
+ "wasm": "https://github.com/dfinity/internet-identity/releases/download/release-2026-03-16/internet_identity_dev.wasm.gz"
+ },
+ "www": {
+ "dependencies": ["ic_vetkeys_encrypted_maps_canister", "internet-identity"],
+ "build": ["cd frontend && npm i --include=dev && npm run build && cd - && rm -r dist > /dev/null 2>&1; mv frontend/dist ./"],
+ "frontend": {
+ "entrypoint": "dist/index.html"
+ },
+ "source": ["dist/"],
+ "type": "assets",
+ "output_env_file": "frontend/.env"
+ }
+ }
+}
diff --git a/rust/vetkeys/password_manager/rust/frontend b/rust/vetkeys/password_manager/rust/frontend
new file mode 120000
index 000000000..af288785f
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/frontend
@@ -0,0 +1 @@
+../frontend
\ No newline at end of file
diff --git a/rust/vetkeys/password_manager/rust/rust-toolchain.toml b/rust/vetkeys/password_manager/rust/rust-toolchain.toml
new file mode 100644
index 000000000..2a2058b04
--- /dev/null
+++ b/rust/vetkeys/password_manager/rust/rust-toolchain.toml
@@ -0,0 +1,4 @@
+[toolchain]
+channel = "1.88.0"
+targets = ["wasm32-unknown-unknown"]
+profile = "default"
\ No newline at end of file