-
Notifications
You must be signed in to change notification settings - Fork 435
chore(vetkeys): split basic_bls_signing into self-contained motoko + rust examples #1444
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
8
commits into
master
Choose a base branch
from
chore/split-vetkeys-basic-bls-signing
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
8 commits
Select commit
Hold shift + click to select a range
977975c
chore(vetkeys): split basic_bls_signing into self-contained motoko + …
marc0olo 318b478
chore(vetkeys/basic_bls_signing): rust v3.3.0, package `backend`, dro…
marc0olo 3ccafef
fix(vetkeys/basic_bls_signing): explicit persistent actor class; drop…
marc0olo 01fa53f
chore(vetkeys/basic_bls_signing): keep flag-based persistence; drop r…
marc0olo ec3b9da
docs(vetkeys/basic_bls_signing): drop "smart contract" web3 jargon
marc0olo 27be51b
docs(vetkeys/basic_bls_signing): drop "dapp", fix security link
marc0olo 36a5dc4
docs(vetkeys/basic_bls_signing): fix outdated "stable" comment termin…
marc0olo 99946f9
refactor(vetkeys/basic_bls_signing): rename domain separator to drop …
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,82 @@ | ||
| # Threshold BLS Signatures (Motoko) | ||
|
|
||
| [View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/vetkeys/basic_bls_signing) | ||
|
|
||
| Also available in: [Rust](../../../rust/vetkeys/basic_bls_signing) | ||
|
|
||
| The **Basic BLS signing** example demonstrates how to use **[VetKeys](https://docs.internetcomputer.org/concepts/vetkeys)** to implement a threshold BLS signing service on the **Internet Computer (IC)**, where every authenticated user can ask the canister to produce signatures, with the **Internet Identity Principal** identifying the signer. The canister ensures a user can only produce signatures for their own principal, not for someone else's. Furthermore, the vetKeys in this app can only be produced upon a user request, as specified in the canister code — the canister cannot produce signatures for arbitrary users or messages. | ||
|
|
||
| To confirm 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. | ||
|
|
||
|  | ||
|
|
||
| ## Features | ||
|
|
||
| - **Signer Authorization**: Only authorized users can produce signatures, and only for their own identity. | ||
| - **Frontend Signature Verification**: Any user can publish a signature from their principal in the canister storage, and the frontend automatically checks its validity. | ||
|
|
||
| ## 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` | ||
|
|
||
| ### (Optionally) choose a different master key | ||
|
|
||
| This example uses `test_key_1` by default. To use a different [available master key](https://docs.internetcomputer.org/concepts/vetkeys/#api-overview), change the `init_args` value in `icp.yaml` before deploying. | ||
|
|
||
| ### Install | ||
|
|
||
| ```bash | ||
| git clone https://github.com/dfinity/examples | ||
| cd examples/motoko/vetkeys/basic_bls_signing | ||
| ``` | ||
|
|
||
| ### 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: | ||
| - Produces BLS signatures upon a user request. | ||
| - Lets users retrieve the public key used to verify their signatures. | ||
| - Lets users store signatures (real or fake) in a log data structure. | ||
|
|
||
| ### Frontend (`frontend/`) | ||
|
|
||
| A vanilla TypeScript application providing a simple interface for signing, showing the signatures stored in the canister, and verifying a signature. Canister bindings are generated from `backend/backend.did` at build time by the `@icp-sdk/bindgen` Vite plugin. | ||
|
|
||
| ## Updating the Candid interface | ||
|
|
||
| `backend/backend.did` defines the backend's public interface; the frontend bindings are generated from it during the build. If you change the backend's public API, regenerate it: | ||
|
|
||
| ```bash | ||
| mops generate candid backend | ||
| ``` | ||
|
|
||
| ## Additional resources | ||
|
|
||
| - **[What are VetKeys](https://docs.internetcomputer.org/concepts/vetkeys)** — more information about VetKeys and VetKD. | ||
| - [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
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,13 @@ | ||
| type _anon_class_13_1 = | ||
| service { | ||
| getMySignatures: () -> (vec Signature) query; | ||
| getMyVerificationKey: () -> (blob); | ||
| signMessage: (message: text) -> (blob); | ||
| }; | ||
| type Signature = | ||
| record { | ||
| message: text; | ||
| signature: blob; | ||
| timestamp: nat64; | ||
| }; | ||
| service : (keyName: text) -> _anon_class_13_1 |
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,3 @@ | ||
| node_modules/ | ||
| dist/ | ||
| src/bindings/ |
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,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>VetKeys: Basic BLS Signing</title> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/main.ts"></script> | ||
| </body> | ||
| </html> |
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,20 @@ | ||
| { | ||
| "name": "frontend", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "prebuild": "npm i --include=dev", | ||
| "build": "vite build", | ||
| "dev": "vite" | ||
| }, | ||
| "dependencies": { | ||
| "@icp-sdk/auth": "^7.1.0", | ||
| "@icp-sdk/core": "^5.4.0", | ||
| "@icp-sdk/vetkeys": "^0.5.0-beta.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@icp-sdk/bindgen": "~0.2.2", | ||
| "typescript": "~5.7.2", | ||
| "vite": "^6.4.1" | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
motoko/vetkeys/basic_bls_signing/frontend/public/.ic-assets.json5
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,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';object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;", | ||
| }, | ||
| allow_raw_access: false | ||
| }, | ||
| ] |
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.