-
Notifications
You must be signed in to change notification settings - Fork 6
feat: CRP-2757 add key manager canister for motoko #82
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d87321e
add key manager canister for motoko
altkdf 55d828f
makefile
altkdf 9d8059c
minor fixes in makefile
altkdf 6a8ffcf
fix how user rights are checked in Rust
altkdf 69fa926
fix permissions in test
altkdf 7871c33
Merge branch 'main' into alex/mo-key-manager-canister
altkdf 3163e99
add comment
altkdf c8d3803
address more comments
altkdf 85c9a4e
Merge branch 'main' into alex/mo-key-manager-canister
altkdf 05e0b62
add cycles for vetkey derivation call
altkdf aa5f8a0
add comment
altkdf 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,11 @@ | ||
| PWD:=$(shell pwd) | ||
|
|
||
| .PHONY: compile-wasm | ||
| .SILENT: compile-wasm | ||
| compile-wasm: | ||
| dfx build --check | ||
|
|
||
| .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 | ||
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,9 @@ | ||
| { | ||
| "canisters": { | ||
| "ic_vetkeys_manager_canister": { | ||
| "main": "src/Main.mo", | ||
| "type": "motoko", | ||
| "args": "--enhanced-orthogonal-persistence" | ||
| } | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
backend/mo/canisters/ic_vetkeys_manager_canister/src/Main.mo
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,81 @@ | ||
| import { KeyManager } "../../../ic_vetkeys/src"; | ||
| import Types "../../../ic_vetkeys/src/Types"; | ||
| import Principal "mo:base/Principal"; | ||
| import Text "mo:base/Text"; | ||
| import Blob "mo:base/Blob"; | ||
| import Result "mo:base/Result"; | ||
|
|
||
| actor { | ||
| var keyManager = KeyManager.KeyManager<Types.AccessRights>("key_manager", Types.accessRightsOperations()); | ||
| public type ByteBuf = { inner : Blob }; | ||
|
fspreiss marked this conversation as resolved.
|
||
| public type Result<Ok, Err> = { | ||
| #Ok : Ok; | ||
| #Err : Err; | ||
| }; | ||
|
altkdf marked this conversation as resolved.
|
||
|
|
||
| public query (msg) func get_accessible_shared_key_ids() : async [(Principal, Blob)] { | ||
|
fspreiss marked this conversation as resolved.
Outdated
|
||
| keyManager.getAccessibleSharedKeyIds(msg.caller); | ||
| }; | ||
|
|
||
| public query (msg) func get_shared_user_access_for_key( | ||
| key_owner : Principal, | ||
| key_name : Blob, | ||
|
fspreiss marked this conversation as resolved.
Outdated
|
||
| ) : async Result<[(Principal, Types.AccessRights)], Text> { | ||
| convertResult(keyManager.getSharedUserAccessForKey(msg.caller, (key_owner, key_name))); | ||
| }; | ||
|
|
||
| public shared func get_vetkey_verification_key() : async ByteBuf { | ||
|
fspreiss marked this conversation as resolved.
|
||
| let inner = await keyManager.getVetkeyVerificationKey(); | ||
| { inner }; | ||
| }; | ||
|
|
||
| public shared (msg) func get_encrypted_vetkey( | ||
| key_owner : Principal, | ||
| key_name : ByteBuf, | ||
| transport_key : ByteBuf, | ||
| ) : async Result<ByteBuf, Text> { | ||
| let vetkeyBytebuf = await keyManager.getEncryptedVetkey(msg.caller, (key_owner, key_name.inner), transport_key.inner); | ||
| switch (vetkeyBytebuf) { | ||
| case (#err(e)) { #Err(e) }; | ||
| case (#ok(inner)) { #Ok({ inner }) }; | ||
| }; | ||
|
fspreiss marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| public query (msg) func get_user_rights( | ||
| key_owner : Principal, | ||
| key_name : ByteBuf, | ||
| user : Principal, | ||
| ) : async Result<?Types.AccessRights, Text> { | ||
| convertResult(keyManager.getUserRights(msg.caller, (key_owner, key_name.inner), user)); | ||
| }; | ||
|
|
||
| public shared (msg) func set_user_rights( | ||
| key_owner : Principal, | ||
| key_name : ByteBuf, | ||
| user : Principal, | ||
| access_rights : Types.AccessRights, | ||
| ) : async Result<?Types.AccessRights, Text> { | ||
| convertResult(keyManager.setUserRights(msg.caller, (key_owner, key_name.inner), user, access_rights)); | ||
| }; | ||
|
|
||
| public shared (msg) func remove_user( | ||
| key_owner : Principal, | ||
| key_name : ByteBuf, | ||
| user : Principal, | ||
| ) : async Result<?Types.AccessRights, Text> { | ||
| convertResult(keyManager.removeUserRights(msg.caller, (key_owner, key_name.inner), user)); | ||
| }; | ||
|
|
||
| // Testing API | ||
| public func set_vetkd_testing_canister_id(vetkd_testing_canister : Principal) { | ||
| keyManager.setVetKDTestingCanister(Principal.toText(vetkd_testing_canister)); | ||
| }; | ||
|
|
||
| /// Convert to the result type compatible with Rust's `Result` | ||
| private func convertResult<Ok, Err>(result : Result.Result<Ok, Err>) : Result<Ok, Err> { | ||
| switch (result) { | ||
| case (#err(e)) { #Err(e) }; | ||
| case (#ok(o)) { #Ok(o) }; | ||
| }; | ||
| }; | ||
| }; | ||
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
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
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
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
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.