Skip to content

Commit

Permalink
Extend vetKD IBE demo with Internet Identity login
Browse files Browse the repository at this point in the history
  • Loading branch information
fspreiss committed Aug 11, 2023
1 parent d54cd27 commit 73b082a
Show file tree
Hide file tree
Showing 14 changed files with 515 additions and 85 deletions.
11 changes: 11 additions & 0 deletions motoko/vetkd/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
"dist/app_frontend_js/"
],
"type": "assets"
},
"internet_identity": {
"type": "custom",
"candid": "https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity.did",
"wasm": "https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_dev.wasm.gz",
"remote": {
"id": {
"ic": "rdmx6-jaaaa-aaaaa-aaadq-cai"
}
},
"frontend": {}
}
},
"defaults": {
Expand Down
154 changes: 139 additions & 15 deletions motoko/vetkd/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions motoko/vetkd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@dfinity/agent": "^0.15.6",
"@dfinity/auth-client": "^0.15.6",
"@dfinity/candid": "^0.15.6",
"@dfinity/principal": "^0.15.6",
"ic-vetkd-utils": "file:ic-vetkd-utils-0.1.0.tgz"
Expand Down
5 changes: 5 additions & 0 deletions motoko/vetkd/src/app_backend/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Text "mo:base/Text";
import Blob "mo:base/Blob";
import Array "mo:base/Array";
import Hex "./utils/Hex";
import Debug "mo:base/Debug";

actor {
type VETKD_SYSTEM_API = actor {
Expand Down Expand Up @@ -40,6 +41,8 @@ actor {
};

public shared ({ caller }) func encrypted_symmetric_key_for_caller(encryption_public_key : Blob) : async Text {
Debug.print("encrypted_symmetric_key_for_caller: caller: " # debug_show (caller));

let { encrypted_key } = await vetkd_system_api.vetkd_encrypted_key({
derivation_id = Principal.toBlob(caller);
public_key_derivation_path = Array.make(Text.encodeUtf8("symmetric_key"));
Expand All @@ -59,6 +62,8 @@ actor {
};

public shared ({ caller }) func encrypted_ibe_decryption_key_for_caller(encryption_public_key : Blob) : async Text {
Debug.print("encrypted_ibe_decryption_key_for_caller: caller: " # debug_show (caller));

let { encrypted_key } = await vetkd_system_api.vetkd_encrypted_key({
derivation_id = Principal.toBlob(caller);
public_key_derivation_path = Array.make(Text.encodeUtf8("ibe_encryption"));
Expand Down
11 changes: 9 additions & 2 deletions motoko/vetkd/src/app_frontend_js/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ form {
justify-content: center;
gap: 0.5em;
flex-flow: row wrap;
max-width: 40vw;
max-width: 50vw;
margin: auto;
align-items: baseline;
}
Expand All @@ -30,9 +30,16 @@ button[type="submit"] {
text-align: center;
}

#login_form {
margin-bottom: 2em;
}

#symmetric_encryption_demo {
text-align: center;
}

#ibedemo {
text-align: center;
margin-top: 2em;
}

#get_symmetric_key_result {
Expand Down
16 changes: 12 additions & 4 deletions motoko/vetkd/src/app_frontend_js/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

<body>
<main>
<h1 id="vetkddemo">vetKD Demo: Encryption with symmetric (AES-GCM-256) key</h1>
<h1 id="vetkddemo">vetKD Demo</h1>
<form id="login_form">
<label for="login" id="principal"></label>
<button id="login">Login (optional)</button>
</form>
<hr />
<h2 id="symmetric_encryption_demo">Encryption with symmetric (AES-GCM-256) key</h1>
<form action="#" id="get_symmetric_key_form">
<button type="submit">Fetch symmetric key for local usage</button>
</form>
Expand All @@ -30,17 +36,19 @@ <h1 id="vetkddemo">vetKD Demo: Encryption with symmetric (AES-GCM-256) key</h1>
</form>
<section id="decrypt_result"></section>
<hr />
<h1 id="ibedemo">vetKD Demo: Identity-Based Encryption (IBE)</h1>
<h2 id="ibedemo">Identity-Based Encryption (IBE)</h1>
<form action="#" id="ibe_encrypt_form">
<label for="ibe_plaintext">Plaintext:</label>
<input type="text" id="ibe_plaintext"><br><br>
<button type="submit" id="ibe_encrypt" disabled="true">IBE-encrypt for myself</button>
<label for="ibe_principal">Encrypt for principal:</label>
<input type="text" id="ibe_principal"><br><br>
<button type="submit" id="ibe_encrypt" disabled="true">IBE-encrypt</button>
</form>
<section id="ibe_encrypt_result"></section>
<form action="#" id="ibe_decrypt_form">
<label for="ibe_ciphertext">Ciphertext:</label>
<input type="text" id="ibe_ciphertext"><br><br>
<button type="submit" id="ibe_decrypt" disabled="true">IBE-decrypt for myself</button>
<button type="submit" id="ibe_decrypt" disabled="true">IBE-decrypt (for myself)</button>
</form>
<section id="ibe_decrypt_result"></section>
<hr />
Expand Down
Loading

0 comments on commit 73b082a

Please sign in to comment.