-
Notifications
You must be signed in to change notification settings - Fork 435
chore(vetkeys): split encrypted_notes_app_vetkd into self-contained motoko + rust examples #1445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marc0olo
wants to merge
7
commits into
master
Choose a base branch
from
chore/split-vetkeys-encrypted-notes-app-vetkd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
660eae7
chore(vetkeys): split encrypted_notes_app_vetkd into self-contained m…
marc0olo 8b38eea
ci(vetkeys/encrypted_notes): drop test.sh, deploy-only CI
marc0olo 4dbfb9f
chore(vetkeys/encrypted_notes): rust v3.3.0, package `backend`
marc0olo adacdd8
docs(vetkeys/encrypted_notes): fix API links, condense security check…
marc0olo db7ec95
docs(vetkeys/encrypted_notes): refresh doc links, fix stable terminol…
marc0olo 7245fcc
docs(vetkeys/encrypted_notes): restore done-vs-future in security che…
marc0olo 41025a0
refactor(vetkeys/encrypted_notes): drop legacy preupgrade/postupgrade…
marc0olo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Encrypted Notes: vetKD (Motoko) | ||
|
|
||
| [View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/vetkeys/encrypted_notes_app_vetkd) | ||
|
|
||
| Also available in: [Rust](../../../rust/vetkeys/encrypted_notes_app_vetkd) | ||
|
|
||
| Encrypted notes is an example app for authoring and storing confidential information on the Internet Computer (ICP) in the form of short pieces of text. Users can create and access their notes via any number of automatically synchronized devices authenticated via Internet Identity (II). Notes are stored confidentially using vetKeys. The end-to-end encryption is performed by the app's frontend. | ||
|
|
||
| In particular, the notes are encrypted with an AES key that is derived (directly in the browser) from a note-ID-specific vetKey obtained from the backend canister (in encrypted form, using an ephemeral transport key), which itself obtains it from the vetKD system API. This way, there is no need for any device management in the app, plus sharing of notes becomes possible. | ||
|
|
||
| The vetKey used to encrypt and decrypt a note is note-ID-specific (and not, for example, principal-specific) to enable the sharing of notes between users. The derived AES keys are stored as non-extractable CryptoKeys in an IndexedDB in the browser for efficiency so that their respective vetKey only has to be fetched from the server once. | ||
|
|
||
| ## Build and deploy from the command line | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Install [Node.js](https://nodejs.org/en/download/) | ||
| - Install [icp-cli](https://cli.internetcomputer.org): `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` | ||
| - Install [ic-mops](https://mops.one): `npm install -g ic-mops` | ||
|
|
||
| ### Install | ||
|
|
||
| ```bash | ||
| git clone https://github.com/dfinity/examples | ||
| cd examples/motoko/vetkeys/encrypted_notes_app_vetkd | ||
| ``` | ||
|
|
||
| ### Deploy | ||
|
|
||
| ```bash | ||
| icp network start -d | ||
| icp deploy | ||
| ``` | ||
|
|
||
| Open the frontend URL printed by `icp deploy`. | ||
|
|
||
| To run the frontend in development mode with hot reloading (after `icp deploy`): | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| ``` | ||
|
|
||
| When done, stop the local network to free up the port for other projects: | ||
|
|
||
| ```bash | ||
| icp network stop | ||
| ``` | ||
|
|
||
| ## Example components | ||
|
|
||
| ### Backend (`backend/`) | ||
|
|
||
| A single Motoko canister that stores encrypted notes. It is deployed automatically with `icp deploy`. | ||
|
|
||
| ### Frontend (`frontend/`) | ||
|
|
||
| A **Svelte** application providing a user-friendly interface for managing encrypted notes. Canister bindings are generated from `backend/backend.did` at build time by the `@icp-sdk/bindgen` Vite plugin. | ||
|
|
||
| ## Limitations | ||
|
|
||
| This example app does not implement key rotation, which is strongly recommended in a production environment. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| If you run into issues, clearing all the application-specific IndexedDBs in the browser might help. For example in Chrome, go to Inspect → Application → Local Storage → Clear All, and then reload. | ||
|
|
||
| ## API level | ||
|
|
||
| This example intentionally uses the **raw vetKD management canister API** (`encryptedSymmetricKeyForNote`, `symmetricKeyVerificationKeyForNote`) to demonstrate how vetKD works at the protocol level. | ||
|
|
||
| For most applications, the higher-level [`EncryptedMaps`](https://github.com/dfinity/vetkeys/tree/main/frontend/ic_vetkeys/src/encrypted_maps) abstraction from `@icp-sdk/vetkeys` is the recommended approach — it handles key derivation, caching, and access control internally without requiring a custom crypto layer. See the **VetKD Password Manager** ([`../password_manager`](../password_manager)) and **Password Manager with Metadata** ([`../password_manager_with_metadata`](../password_manager_with_metadata)) examples for how `EncryptedMaps` is used in practice. | ||
|
|
||
| ## Additional resources | ||
|
|
||
| - **[What are VetKeys](https://docs.internetcomputer.org/concepts/vetkeys)** — more information about VetKeys and VetKD. | ||
| - [Security checklist for this example](security-checklist.md) | ||
| - [Security best practices](https://docs.internetcomputer.org/guides/security/overview/) |
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
23 changes: 23 additions & 0 deletions
23
motoko/vetkeys/encrypted_notes_app_vetkd/backend/backend.did
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| type _anon_class_17_1 = | ||
| service { | ||
| addUser: (note_id: NoteId, user: PrincipalName) -> (); | ||
| createNote: () -> (NoteId); | ||
| deleteNote: (note_id: NoteId) -> (); | ||
| encryptedSymmetricKeyForNote: (note_id: NoteId, transport_public_key: | ||
| blob) -> (text); | ||
| getNotes: () -> (vec EncryptedNote); | ||
| removeUser: (note_id: NoteId, user: PrincipalName) -> (); | ||
| symmetricKeyVerificationKeyForNote: () -> (text); | ||
| updateNote: (id: NoteId, encryptedText: text) -> (); | ||
| whoami: () -> (text); | ||
| }; | ||
| type PrincipalName = text; | ||
| type NoteId = nat; | ||
| type EncryptedNote = | ||
| record { | ||
| encryptedText: text; | ||
| id: nat; | ||
| owner: PrincipalName; | ||
| users: vec PrincipalName; | ||
| }; | ||
| service : (keyName: text) -> _anon_class_17_1 |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.