Skip to content

Commit b68972d

Browse files
Merge pull request #1323 from dfinity/vetkeys-examples
feat: add basic vetkeys examples
2 parents fc2f4e1 + a04e4e0 commit b68972d

193 files changed

Lines changed: 10693 additions & 9 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

motoko/vetkeys/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# vetKeys Examples
1+
# VetKeys Examples (Motoko)
22

3-
## Basic Examples
4-
- **[Password Manager](https://github.com/dfinity/vetkeys/tree/main/examples/password_manager)** - A secure, decentralized password manager using Encrypted Maps for vault-based password storage and sharing.
5-
- **[Password Manager with Metadata](https://github.com/dfinity/vetkeys/tree/main/examples/password_manager_with_metadata)** - Extends the basic password manager to support unencrypted metadata alongside encrypted passwords.
6-
- **[Encrypted Notes](https://github.com/dfinity/vetkeys/tree/main/examples/encrypted_notes_dapp_vetkd)** - A secure note-taking application that uses vetKeys for encryption and enables sharing notes between users without device management.
3+
The VetKeys examples (including Motoko backends) are located in [`rust/vetkeys/`](../../rust/vetkeys/).
74

8-
## Advanced Examples
5+
Each example that supports a Motoko backend has a `motoko/` subdirectory alongside its `rust/` backend:
96

10-
- **[Threshold BLS Signature](https://github.com/dfinity/vetkeys/tree/main/examples/basic_bls_signing)** - Demonstrates how to use vetKeys to create a threshold BLS signing service.
11-
12-
- **[Identity-Basic Encryption (IBE)](https://github.com/dfinity/vetkeys/tree/main/examples/basic_ibe)** - Shows how to implement secure messaging using Identity Based Encryption with Internet Identity Principals as encryption keys.
7+
- [Basic BLS Signing](../../rust/vetkeys/basic_bls_signing/) — Motoko + Rust
8+
- [Basic IBE](../../rust/vetkeys/basic_ibe/) — Motoko + Rust
9+
- [Encrypted Notes](../../rust/vetkeys/encrypted_notes_dapp_vetkd/) — Motoko + Rust
10+
- [Password Manager](../../rust/vetkeys/password_manager/) — Motoko + Rust
11+
- [Password Manager with Metadata](../../rust/vetkeys/password_manager_with_metadata/) — Motoko + Rust
12+
- [Basic Timelock IBE](../../rust/vetkeys/basic_timelock_ibe/) — Rust only
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Threshold BLS Signatures
2+
3+
| Motoko backend | [![](https://icp.ninja/assets/open.svg)](http://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/vetkeys/basic_bls_signing/motoko)|
4+
| --- | --- |
5+
| Rust backend | [![](https://icp.ninja/assets/open.svg)](http://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/vetkeys/basic_bls_signing/rust) |
6+
7+
The **Basic BLS signing** example demonstrates how to use **[vetKeys](https://internetcomputer.org/docs/building-apps/network-features/vetkeys/introduction)** to implement a threshold BLS signing service on the **Internet Computer (IC)**, where every authenticated user can ask the canister (IC smart contract) to produce signatures, where the **Internet Identity Principal** identifies the signer. This canister ensures that users can only produce signature for their own principal and not for someone else's principal. Furthermore, the vetKeys in this dapp can only be produced upon a user request, as specified in the canister code, meaning that the canister cannot produce signatures for arbitrary users or messages.
8+
9+
For confirming that the canister can only produce signatures in the intended way, users need to inspect the code installed in the canister. For this, it is crucial that canisters using VetKeys have their code public.
10+
11+
![UI Screenshot](ui_screenshot.png)
12+
13+
## Features
14+
15+
- **Signer Authorization**: Only authorized users can produce signatures and only for their own identity.
16+
- **Frontend Signature Verification**: Any user can publish any signature from their principal in the canister storage and the frontend automatically checks the signature validity.
17+
18+
## Setup
19+
20+
### Prerequisites
21+
22+
- [Internet Computer software development kit](https://internetcomputer.org/docs/building-apps/getting-started/install)
23+
- [npm](https://www.npmjs.com/package/npm)
24+
25+
### (Optionally) Choose a Different Master Key
26+
27+
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.
28+
29+
### Deploy the Canisters Locally
30+
31+
If you want to deploy this project locally with a Motoko backend, then run:
32+
```bash
33+
dfx start --background && dfx deploy
34+
```
35+
from the `motoko` folder.
36+
37+
To use the Rust backend instead of Motoko, run the same command in the `rust` folder.
38+
39+
## Example Components
40+
41+
### Backend
42+
43+
The backend consists of a canister that:
44+
* Produces signatures upon a user request.
45+
* Allows users to retrieve the root public key that can be used to check any user's signature for this canister.
46+
* Allows users to store signatures (real or fake) in a log datastructure.
47+
48+
### Frontend
49+
50+
The frontend is a vanilla typescript application providing a simple interface for signing, showing the signatures stored in the canister, and publishing a signature.
51+
52+
To run the frontend in development mode with hot reloading (after running `dfx deploy`):
53+
54+
```bash
55+
npm run dev
56+
```
57+
58+
## Additional Resources
59+
60+
- **[What are VetKeys](https://internetcomputer.org/docs/building-apps/network-features/encryption/vetkeys)** - For more information about VetKeys and VetKD.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
tseslint.configs.recommendedTypeChecked,
10+
eslintPluginPrettierRecommended,
11+
{
12+
languageOptions: {
13+
parserOptions: {
14+
project: true,
15+
tsconfigRootDir: import.meta.dirname,
16+
},
17+
},
18+
},
19+
{
20+
ignores: [
21+
"dist/",
22+
"src/declarations",
23+
"coverage/",
24+
"*.config.js",
25+
"*.config.cjs",
26+
"*.config.mjs",
27+
"*.config.ts",
28+
],
29+
}
30+
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>VetKeys: Basic BLS Signing</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "basic_bls_signing_frontend",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "npm run build:bindings && vite",
8+
"build": "npm run build:bindings && tsc && vite build",
9+
"build:bindings": "cd scripts && ./gen_bindings.sh",
10+
"preview": "vite preview",
11+
"lint": "eslint"
12+
},
13+
"devDependencies": {
14+
"@eslint/js": "^9.24.0",
15+
"@rollup/plugin-typescript": "^12.1.2",
16+
"@types/node": "^24.0.10",
17+
"eslint": "^9.24.0",
18+
"eslint-config-prettier": "^10.1.5",
19+
"eslint-plugin-prettier": "^5.4.0",
20+
"tslib": "^2.8.1",
21+
"typescript": "~5.7.2",
22+
"typescript-eslint": "^8.35.1",
23+
"vite": "^6.4.1",
24+
"vite-plugin-environment": "^1.1.3"
25+
},
26+
"dependencies": {
27+
"@dfinity/auth-client": "^2.4.1",
28+
"@dfinity/principal": "^2.4.1",
29+
"@dfinity/vetkeys": "^0.3.0"
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
match: "**/*",
4+
security_policy: "hardened",
5+
headers: {
6+
"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';object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
7+
},
8+
allow_raw_access: false
9+
},
10+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
cd ../../backend && make extract-candid
4+
5+
cd .. && dfx generate basic_bls_signing || exit 1
6+
7+
rm -r frontend/src/declarations/basic_bls_signing > /dev/null 2>&1 || true
8+
9+
mkdir -p frontend/src/declarations/basic_bls_signing
10+
mv src/declarations/basic_bls_signing frontend/src/declarations
11+
rmdir -p src/declarations > /dev/null 2>&1 || true
12+
13+
# dfx 0.31+ generates @icp-sdk/core imports; rewrite to @dfinity/* to match deps
14+
find frontend/src/declarations -type f \( -name '*.ts' -o -name '*.js' \) -exec \
15+
perl -i -pe 's|\@icp-sdk/core/agent|\@dfinity/agent|g; s|\@icp-sdk/core/principal|\@dfinity/principal|g; s|\@icp-sdk/core/candid|\@dfinity/candid|g' {} +

0 commit comments

Comments
 (0)