Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ vetkd_public_key : (vetkd_public_key_args) -> (vetkd_public_key_result);
vetkd_derive_key : (vetkd_derive_key_args) -> (vetkd_derive_key_result);
```

For more documentation on vetKeys and the management canister API, see the [vetKeys documentation](https://internetcomputer.org/docs/building-apps/network-features/vetkeys/introduction).
For more documentation on vetKeys and the management canister API, see the [vetKeys documentation](https://docs.internetcomputer.org/building-apps/network-features/vetkeys/introduction).

Please share your feedback on the [developer forum](https://forum.dfinity.org/t/threshold-key-derivation-privacy-on-the-ic/16560/179).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ PWD:=$(shell pwd)
.PHONY: compile-wasm
.SILENT: compile-wasm
compile-wasm:
dfx build --check
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
CUSTOM_WASM_PATH=$(PWD)/.dfx/local/canisters/ic_vetkeys_encrypted_maps_canister/ic_vetkeys_encrypted_maps_canister.wasm cargo test -p ic-vetkeys-encrypted-maps-canister
@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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
canisters:
- name: ic_vetkeys_encrypted_maps_canister
recipe:
type: "@dfinity/motoko@v4.1.0"
configuration:
main: src/Main.mo
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[toolchain]
moc = "1.5.0"

[package]
name = "ic-vetkeys-encrypted-maps-canister"
version = "0.1.0"
Expand Down
5 changes: 3 additions & 2 deletions backend/mo/canisters/ic_vetkeys_manager_canister/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ PWD:=$(shell pwd)
.PHONY: compile-wasm
.SILENT: compile-wasm
compile-wasm:
dfx build --check
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
CUSTOM_WASM_PATH=$(PWD)/.dfx/local/canisters/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.wasm cargo test -p ic-vetkeys-manager-canister
@echo "Testing Motoko canister WASM: $(PWD)/.icp/cache/artifacts/ic_vetkeys_manager_canister"
CUSTOM_WASM_PATH=$(PWD)/.icp/cache/artifacts/ic_vetkeys_manager_canister cargo test -p ic-vetkeys-manager-canister
14 changes: 0 additions & 14 deletions backend/mo/canisters/ic_vetkeys_manager_canister/dfx.json

This file was deleted.

6 changes: 6 additions & 0 deletions backend/mo/canisters/ic_vetkeys_manager_canister/icp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
canisters:
- name: ic_vetkeys_manager_canister
recipe:
type: "@dfinity/motoko@v4.1.0"
configuration:
main: src/Main.mo
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[toolchain]
moc = "1.5.0"

[package]
name = "ic-vetkeys-manager-canister"
version = "0.1.0"
Expand All @@ -10,4 +13,4 @@ license = "Apache-2.0"

[dependencies]
base = "0.14.6"
ic-vetkeys = "0.3.0"
ic-vetkeys = "0.4.0"
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import Blob "mo:base/Blob";
import Result "mo:base/Result";
import Array "mo:base/Array";

actor class (keyName : Text) {
var keyManager = IcVetkeys.KeyManager.KeyManager<Types.AccessRights>({ curve = #bls12_381_g2; name = keyName }, "key manager", Types.accessRightsOperations());
persistent actor class (keyName : Text) {
let keyManagerState = IcVetkeys.KeyManager.newKeyManagerState<Types.AccessRights>({ curve = #bls12_381_g2; name = keyName }, "key manager");
transient let keyManager = IcVetkeys.KeyManager.KeyManager<Types.AccessRights>(keyManagerState, 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 };
Expand Down
3 changes: 3 additions & 0 deletions backend/mo/ic_vetkeys/mops.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[toolchain]
moc = "1.5.0"

[package]
name = "ic-vetkeys"
version = "0.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ ROOT_DIR := $(shell git rev-parse --show-toplevel)
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
Expand All @@ -14,4 +19,4 @@ extract-candid: compile-wasm
.SILENT: clean
clean:
cargo clean
rm -rf .dfx
rm -rf .icp/cache

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ fn should_access_map_values() {
let map_name = random_map_name(rng);

let mut authorized_users = vec![(caller, AccessRights::ReadWriteManage)];
let mut keyvals = vec![];
let mut keyvals: BTreeMap<ByteBuf, ByteBuf> = BTreeMap::new();

for _ in 0..3 {
let map_key = random_map_key(rng);
Expand Down Expand Up @@ -697,7 +697,7 @@ fn should_access_map_values() {
authorized_users.push((user_to_be_added, access_rights));
}

keyvals.push((map_key, encrypted_value));
keyvals.insert(map_key, encrypted_value);
}

for (map_key, encrypted_value) in keyvals.clone() {
Expand All @@ -714,7 +714,7 @@ fn should_access_map_values() {
}

for (user, _access_rights) in authorized_users.clone() {
let expected_map = BTreeMap::from_iter(keyvals.clone());
let expected_map = keyvals.clone();
let computed_map_single = BTreeMap::from_iter(
env.query::<Result<Vec<(ByteBuf, ByteBuf)>, String>>(
user,
Expand Down Expand Up @@ -984,7 +984,7 @@ impl TestEnvironment {
pic.install_canister(
example_canister_id,
example_wasm_bytes,
encode_one("dfx_test_key").unwrap(),
encode_one("test_key_1").unwrap(),
None,
);

Expand Down Expand Up @@ -1032,14 +1032,20 @@ impl TestEnvironment {

fn load_encrypted_maps_example_canister_wasm() -> Vec<u8> {
let wasm_path_string = match std::env::var("CUSTOM_WASM_PATH") {
Ok(path) if !path.is_empty() => path,
Ok(path) if !path.is_empty() => {
assert!(
Path::new(&path).exists(),
"CUSTOM_WASM_PATH is set to '{}' but the file does not exist; run `make compile-wasm` first",
path
);
path
}
_ => format!(
"{}/target/wasm32-unknown-unknown/release/ic_vetkeys_encrypted_maps_canister.wasm",
git_root_dir()
),
};
let wasm_path = Path::new(&wasm_path_string);
std::fs::read(wasm_path)
std::fs::read(&wasm_path_string)
.expect("wasm does not exist - run `cargo build --release --target wasm32-unknown-unknown`")
}

Expand Down
6 changes: 5 additions & 1 deletion backend/rs/canisters/ic_vetkeys_manager_canister/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ ROOT_DIR := $(shell git rev-parse --show-toplevel)
compile-wasm:
cargo build --release --target wasm32-unknown-unknown

.PHONY: test
.SILENT: test
test: compile-wasm
cargo test -p ic-vetkeys-manager-canister

.PHONY: extract-candid
.SILENT: extract-candid
extract-candid: compile-wasm
candid-extractor $(ROOT_DIR)/target/wasm32-unknown-unknown/release/ic_vetkeys_manager_canister.wasm > ic_vetkeys_manager_canister.did

10 changes: 0 additions & 10 deletions backend/rs/canisters/ic_vetkeys_manager_canister/dfx.json

This file was deleted.

14 changes: 10 additions & 4 deletions backend/rs/canisters/ic_vetkeys_manager_canister/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl TestEnvironment {
pic.install_canister(
example_canister_id,
example_wasm_bytes,
encode_one("dfx_test_key").unwrap(),
encode_one("test_key_1").unwrap(),
None,
);

Expand Down Expand Up @@ -579,14 +579,20 @@ impl TestEnvironment {

fn load_key_manager_example_canister_wasm() -> Vec<u8> {
let wasm_path_string = match std::env::var("CUSTOM_WASM_PATH") {
Ok(path) if !path.is_empty() => path,
Ok(path) if !path.is_empty() => {
assert!(
Path::new(&path).exists(),
"CUSTOM_WASM_PATH is set to '{}' but the file does not exist; run `make compile-wasm` first",
path
);
path
}
_ => format!(
"{}/target/wasm32-unknown-unknown/release/ic_vetkeys_manager_canister.wasm",
git_root_dir()
),
};
let wasm_path = Path::new(&wasm_path_string);
std::fs::read(wasm_path)
std::fs::read(&wasm_path_string)
.expect("wasm does not exist - run `cargo build --release --target wasm32-unknown-unknown`")
}

Expand Down
19 changes: 19 additions & 0 deletions backend/rs/canisters/icp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
canisters:
- name: ic_vetkeys_manager_canister
recipe:
type: "@dfinity/rust@v3.2.0"
configuration:
package: ic-vetkeys-manager-canister
candid: ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did
init_args:
type: text
value: "(\"test_key_1\")"
- name: ic_vetkeys_encrypted_maps_canister
recipe:
type: "@dfinity/rust@v3.2.0"
configuration:
package: ic-vetkeys-encrypted-maps-canister
candid: ic_vetkeys_encrypted_maps_canister/ic_vetkeys_encrypted_maps_canister.did
init_args:
type: text
value: "(\"test_key_1\")"
16 changes: 11 additions & 5 deletions backend/rs/canisters/tests/tests/sign_with_bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn bls_signature_should_be_valid_and_equal_to_decrypted_vetkey() {
let context = random_bytes(rng, 10);
let key_id = VetKDKeyId {
curve: VetKDCurve::Bls12_381_G2,
name: "dfx_test_key".to_string(),
name: "test_key_1".to_string(),
};
let transport_secret_key = random_transport_key(rng);
let transport_public_key = transport_secret_key.public_key();
Expand Down Expand Up @@ -56,7 +56,7 @@ fn bls_public_key_should_be_equal_to_verification_key() {
let context = random_bytes(rng, 10);
let key_id = VetKDKeyId {
curve: VetKDCurve::Bls12_381_G2,
name: "dfx_test_key".to_string(),
name: "test_key_1".to_string(),
};
let bls_public_key: Vec<u8> = env.update(
Principal::anonymous(),
Expand Down Expand Up @@ -114,14 +114,20 @@ impl TestEnvironment {

fn load_canister_wasm() -> Vec<u8> {
let wasm_path_string = match std::env::var("CUSTOM_WASM_PATH") {
Ok(path) if !path.is_empty() => path,
Ok(path) if !path.is_empty() => {
assert!(
Path::new(&path).exists(),
"CUSTOM_WASM_PATH is set to '{}' but the file does not exist; run `make compile-wasm` first",
path
);
path
}
_ => format!(
"{}/target/wasm32-unknown-unknown/release/ic_vetkeys_canisters_tests.wasm",
git_root_dir()
),
};
let wasm_path = Path::new(&wasm_path_string);
std::fs::read(wasm_path)
std::fs::read(&wasm_path_string)
.expect("wasm does not exist - run `cargo build --release --target wasm32-unknown-unknown`")
}

Expand Down
8 changes: 0 additions & 8 deletions dfx.json

This file was deleted.

Loading
Loading