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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
canisters:
- name: ic_vetkeys_encrypted_maps_canister
recipe:
type: "@dfinity/motoko@v4.1.0"
configuration:
main: src/Main.mo
# v5.0.0 delegates the build to mops, which reads the canister entry point
# and toolchain (moc 1.9.0, required for the mixin) from mops.toml.
type: "@dfinity/motoko@v5.0.0"
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"version": 3,
"mopsTomlDepsHash": "f74b78cc83fb1433d7dac1ef95bf4cbf8101b43b15f657f7a5cf51d913641d53",
"mopsTomlDepsHash": "a3e2b30f19c389044292be0d3eafdef0d513c57294989270c6b82dbfd609962e",
"deps": {
"core": "2.4.0",
"ic-vetkeys": "0.4.0",
"base": "0.14.9"
"ic-vetkeys": "../../ic_vetkeys"
},
"hashes": {
"core@2.4.0": {
Expand Down Expand Up @@ -64,71 +63,6 @@
"core@2.4.0/src/pure/Queue.mo": "ed0bd0968457ea3bb24c5367f0dbdb159cfe950d0e2666224985e57a784fae3b",
"core@2.4.0/src/pure/RealTimeQueue.mo": "af133ae61c69ce4e00db5e9db53ddeccad84373fef82a156c85360c2426349dd",
"core@2.4.0/src/pure/Set.mo": "f0155b1d548cbc8889fcff75ef52f0cab7998b034621e4faac8d3b79d7bbac07"
},
"ic-vetkeys@0.4.0": {
"ic-vetkeys@0.4.0/src/ManagementCanister.mo": "9e2d77fef32fbe76c7dedfed8513a25ab680e3eb1a13b8568231355d8d7c53e4",
"ic-vetkeys@0.4.0/README.md": "caa7385ff105fbc70e9875221a85d0e0db1b401f60d959d7b38c345a00311cd5",
"ic-vetkeys@0.4.0/src/Types.mo": "dc41da19ba8df04028df590064e0daca0573054f6913108341e69ced61cc045c",
"ic-vetkeys@0.4.0/src/lib.mo": "ec087d82cc47dbd4ab75670e26cdf93ddbb932d3d990bfa4de24fbb5c0f1bdd9",
"ic-vetkeys@0.4.0/LICENSE": "a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9",
"ic-vetkeys@0.4.0/mops.toml": "d8323219d0345ea09393235ffbb77235ea60ca330f7e30bc9abf5aa4252044e4",
"ic-vetkeys@0.4.0/src/encrypted_maps/EncryptedMaps.mo": "f20eb6fd2d2f500bbb9cf700968cf4392e08ebca931c9cba82473a568dfb7153",
"ic-vetkeys@0.4.0/src/key_manager/KeyManager.mo": "d1655daf68ce1f8798fc06e53a24695b50d2ccf9562fa2a284aa3ccf17302ec8"
},
"base@0.14.9": {
"base@0.14.9/src/Blob.mo": "9d4b10667080778bca66cb534f1e0a1477e5247a970170f4ba19e7c58cc4939d",
"base@0.14.9/NOTICE": "3960a8d25fa5fc909325817b08b36c1146970930ca15b6352f8ea6db803cab47",
"base@0.14.9/src/Array.mo": "b8b182ec7522daf79160a00e34a7ea558369c32c2b67a6ed339fa2e56ce60835",
"base@0.14.9/LICENSE": "166bd8e8cf7790087d1fd18a9fa4d060cc0d0b3e5ab30689aa5f3a59a93386bf",
"base@0.14.9/mops.toml": "ef683701e561e41a4f307e3d30b8d78db6990132e49d3a128e4d789c2662fba4",
"base@0.14.9/README.md": "f45244a47229456939321014b550e3360b4f8c4d0fd60aa60bbba7e9eacbc8de",
"base@0.14.9/src/AssocList.mo": "07a92db12c36ba96baf3fb45ac76662407ca5d6cee7aedb01fa8ed6d9ee98cf4",
"base@0.14.9/src/Buffer.mo": "7ad75dec25ea37e964c536d6bb86ed90cc48047feedb57c9ded359bea49045f7",
"base@0.14.9/src/Bool.mo": "65faf01dc6e3609ed2f729b813811506951adcce71c081fc6edcdbae4c8b1169",
"base@0.14.9/src/CertifiedData.mo": "51a205989529f6b4fe788f78be0de2da1cb96f6532aac8accccbf4421cce3d06",
"base@0.14.9/src/Char.mo": "dc34cfe3482b92134e5604629377b4236367f2f31d8a82b81084ca5cadf31c2e",
"base@0.14.9/src/Debug.mo": "b1c97f53827eb8f5476c663fba8d4ec54a69980c15f7b9c74335d9bf8be0a973",
"base@0.14.9/src/Deque.mo": "39da68fb8f19fb497aa3db769ffe2cb740cab54e6d82264052de505edac9b17b",
"base@0.14.9/src/Error.mo": "a5045ea30d25ac7d731a18ddae6a60fd28790971881dfe6e8560f212d95df614",
"base@0.14.9/src/ExperimentalCycles.mo": "fd11de67a95517979c18f850d3b7da370858f508b54e8d2d3b081dd7240355c6",
"base@0.14.9/src/ExperimentalStableMemory.mo": "70330ae4d113e15d1d211c8ea229bc0a6fc6c014f5fece58aea0de90c82e4fff",
"base@0.14.9/src/ExperimentalInternetComputer.mo": "00ffec3506f3bd66a3ed72e70d2c98e24c0d98be2750d35b8109e00d3aee453d",
"base@0.14.9/src/Float.mo": "36d61a5e1ca108ae28a168d507c6d99b7e5fc11be600f687ea6bcd7fe3db84fe",
"base@0.14.9/src/Int.mo": "3dc2fe075ca553d92cb8178f3216a591233376ffb591d42a8f08bd86c7b5cea6",
"base@0.14.9/src/Heap.mo": "517b746ca16d80b9b7cf3fc6c2883854d4cb240bd494a888fb65ac02441f769b",
"base@0.14.9/src/Func.mo": "bea8bcb92707a255814e0a7d79c238e490860c38001438612948704027f05bec",
"base@0.14.9/src/Hash.mo": "99d7add2ed6e82cf482593ac85edd231d507ef542608cd42fec1cc6d764906e9",
"base@0.14.9/src/HashMap.mo": "639c3377687ef59c22ac8df7ef5b26cf6c9689a356ea1ac9fbe215819db59adf",
"base@0.14.9/src/Int32.mo": "bcb4775ef68e0b2b5b872771abcda8eaef4e0a126562b0877e91b3a1ebaaffd6",
"base@0.14.9/src/Int16.mo": "586617af6cef687bd05cd29cd0c785b366ad5ad2b871151f909de76671b755c3",
"base@0.14.9/src/Int8.mo": "dfdaf280fe2a1b7524cf82116ccdeea5c70cb27046b8addd3c3d9f387b17f594",
"base@0.14.9/src/Int64.mo": "7cfa15c6a8b777fb5f67e841da3d0960a5ef43c66d46acdf354e8a7dfac57d2d",
"base@0.14.9/src/Iter.mo": "140291f243dfcfdbedb54a264cce76b7481eeb8767224a41fa9951beaf067b67",
"base@0.14.9/src/IterType.mo": "1b6361f1b7ee81d1974719c8464c8c574aaee992c37c3c7b6c39f107a58af01c",
"base@0.14.9/src/Nat.mo": "d2d24f2b42365b3a54c8bb3cf467b94d1ec7f3271a7d0f671986c04a39a8b844",
"base@0.14.9/src/Nat16.mo": "42483fe26ec90fcfc5d90e82df945ea128d10145dada4ee8f68ee85e62f17841",
"base@0.14.9/src/List.mo": "d13e77eb05b4edcca55e7cc5ee7ce5018c5a137a7a67708e8eb54967c38673fb",
"base@0.14.9/src/Nat32.mo": "7919cf0598707ae3628d70caa3bb44c04e3bd940752b85481f4f071cde89b66a",
"base@0.14.9/src/Nat64.mo": "dce2861f9674d6301fb2b98475460e85b3d245537c52e3c7a90fac257e5c96f0",
"base@0.14.9/src/Nat8.mo": "b9266d0b5e284288beeca990963cb7a8c9492d69771c656d0501507a613802ba",
"base@0.14.9/src/None.mo": "b204a4964519117e6fa8ee82da5653376988cf618fc397205dfc8ea58f60d2d1",
"base@0.14.9/src/Order.mo": "d8c76128271612469d052520f10af726556df78688729f9856b62ea292e0f43f",
"base@0.14.9/src/OrderedMap.mo": "d743491a4dca60fb446144617a1e813019ec1c9c345281144bc5103061fb2eb0",
"base@0.14.9/src/Option.mo": "72c9ddc183b6248375e0f96efd33881a130a465f97e6a3a553ffe8f16bb5fba7",
"base@0.14.9/src/OrderedSet.mo": "44d4fd4e3b9587124996daebf52ec81cb83a350d02b56f1ab097f1ad3fef0e41",
"base@0.14.9/src/Prelude.mo": "7b4ea84cb683203c68d6135b524ca5587a1b23436d6733e0aaf723d36be4aa85",
"base@0.14.9/src/Principal.mo": "5e50eba952b7de62450264a2ece0af6edadd0b6dd4c8cfd2e432ca66022f70ab",
"base@0.14.9/src/RBTree.mo": "3e5766dbdc21e358f407718bd9a210af5a5dfb7a10843fe0e09b005fd3f4a07a",
"base@0.14.9/src/Region.mo": "6ca3019aed15ad442a3a794000ac245b2bcbd846033966e446dc1a29986dbf0b",
"base@0.14.9/src/Text.mo": "d21beb556b69c6a21bb2ba87830b132c4f46ec2f97abb2c34187198dc5a58818",
"base@0.14.9/src/Stack.mo": "4b2681e9ed562b02840b7a46b58e66b695a725f31b94f6c9952e95e81b703b84",
"base@0.14.9/src/Result.mo": "4aa00198ee36ea3b60519f9c350e1c17b14b6ffa005b6d4edcff36a0a206f3af",
"base@0.14.9/src/Time.mo": "4e2a6126d0a2b0b862735adbde93620a70cb388af25a87c7b853650abd0743ab",
"base@0.14.9/src/Random.mo": "15f6fd50d10a9eb401c3f18f19874fb334fec309e94499a46a0a876037dca266",
"base@0.14.9/src/Timer.mo": "e6302739637537d10fd84b6d0c7d79ac85f791d62d0e61090f9b93be8b8b8ced",
"base@0.14.9/src/TrieMap.mo": "6d69d887006cd1dff09331473f258141bccb251a04a3a8221b65720a4bf237ac",
"base@0.14.9/src/Trie.mo": "63c0fbe6d48808630c7edf51d66140b8b2a43a734e425ab854234126e242cb07",
"base@0.14.9/src/TrieSet.mo": "29b3314f43fad714fc7b68cc3b0dde00a7d8b02b6431afd7fe12304dc14f9612"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
moc = "1.6.0"
moc = "1.9.0"

[moc]
args = ["-W=M0236,M0237,M0223"]
Expand All @@ -19,4 +19,4 @@ main = "src/Main.mo"

[dependencies]
core = "2.4.0"
ic-vetkeys = "0.4.0"
ic-vetkeys = "../../ic_vetkeys"
215 changes: 6 additions & 209 deletions backend/mo/canisters/ic_vetkeys_encrypted_maps_canister/src/Main.mo
Original file line number Diff line number Diff line change
@@ -1,212 +1,9 @@
import IcVetkeys "mo:ic-vetkeys";
import Types "mo:ic-vetkeys/Types";
import Principal "mo:core/Principal";
import Text "mo:core/Text";
import Blob "mo:core/Blob";
import Result "mo:core/Result";
import Array "mo:core/Array";
import EncryptedMapsCanister "mo:ic-vetkeys/encrypted_maps/Canister";

// This canister is a thin reference wrapper around the `ic-vetkeys`
// EncryptedMaps library. The entire canister interface is provided by the
// library mixin, which guarantees the exposed Candid matches what the
// `@icp-sdk/vetkeys` frontend expects.
persistent actor class (keyName : Text) {
let encryptedMapsState = IcVetkeys.EncryptedMaps.newEncryptedMapsState<Types.AccessRights>({ curve = #bls12_381_g2; name = keyName }, "password_manager_example_dapp");
transient let encryptedMaps = IcVetkeys.EncryptedMaps.EncryptedMaps(encryptedMapsState, 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 };

public type EncryptedMapData = {
map_owner : Principal;
map_name : ByteBuf;
keyvals : [(ByteBuf, ByteBuf)];
access_control : [(Principal, Types.AccessRights)];
};

/// The result type compatible with Rust's `Result`.
public type Result<Ok, Err> = {
#Ok : Ok;
#Err : Err;
};

public query (msg) func get_accessible_shared_map_names() : async [(Principal, ByteBuf)] {
encryptedMaps.getAccessibleSharedMapNames(msg.caller).map<(Principal, Blob), (Principal, ByteBuf)>(
func((principal, blob) : (Principal, Blob)) {
(principal, { inner = blob });
}
);
};

public query (msg) func get_shared_user_access_for_map(
map_owner : Principal,
map_name : ByteBuf,
) : async Result<[(Principal, Types.AccessRights)], Text> {
convertResult(encryptedMaps.getSharedUserAccessForMap(msg.caller, (map_owner, map_name.inner)));
};

public query (msg) func get_encrypted_values_for_map(
map_owner : Principal,
map_name : ByteBuf,
) : async Result<[(ByteBuf, ByteBuf)], Text> {
let result = encryptedMaps.getEncryptedValuesForMap(msg.caller, (map_owner, map_name.inner));
switch (result) {
case (#err(e)) { #Err(e) };
case (#ok(values)) {
#Ok(
values.map<(Blob, Blob), (ByteBuf, ByteBuf)>(
func((blob1, blob2) : (Blob, Blob)) {
({ inner = blob1 }, { inner = blob2 });
}
)
);
};
};
};

public query (msg) func get_all_accessible_encrypted_values() : async [((Principal, ByteBuf), [(ByteBuf, ByteBuf)])] {
encryptedMaps.getAllAccessibleEncryptedValues(msg.caller).map<((Principal, Blob), [(Blob, Blob)]), ((Principal, ByteBuf), [(ByteBuf, ByteBuf)])>(
func(((owner, map_name), values) : ((Principal, Blob), [(Blob, Blob)])) {
(
(owner, { inner = map_name }),
values.map<(Blob, Blob), (ByteBuf, ByteBuf)>(
func((blob1, blob2) : (Blob, Blob)) {
({ inner = blob1 }, { inner = blob2 });
}
),
);
}
);
};

public query (msg) func get_all_accessible_encrypted_maps() : async [EncryptedMapData] {
encryptedMaps.getAllAccessibleEncryptedMaps(msg.caller).map<IcVetkeys.EncryptedMaps.EncryptedMapData<Types.AccessRights>, EncryptedMapData>(
func(map : IcVetkeys.EncryptedMaps.EncryptedMapData<Types.AccessRights>) : EncryptedMapData {
{
map_owner = map.map_owner;
map_name = { inner = map.map_name };
keyvals = map.keyvals.map<(Blob, Blob), (ByteBuf, ByteBuf)>(
func((blob1, blob2) : (Blob, Blob)) {
({ inner = blob1 }, { inner = blob2 });
}
);
access_control = map.access_control;
};
}
);
};

public query (msg) func get_encrypted_value(
map_owner : Principal,
map_name : ByteBuf,
map_key : ByteBuf,
) : async Result<?ByteBuf, Text> {
let result = encryptedMaps.getEncryptedValue(msg.caller, (map_owner, map_name.inner), map_key.inner);
switch (result) {
case (#err(e)) { #Err(e) };
case (#ok(null)) { #Ok(null) };
case (#ok(?blob)) { #Ok(?{ inner = blob }) };
};
};

public shared (msg) func remove_map_values(
map_owner : Principal,
map_name : ByteBuf,
) : async Result<[ByteBuf], Text> {
let result = encryptedMaps.removeMapValues(msg.caller, (map_owner, map_name.inner));
switch (result) {
case (#err(e)) { #Err(e) };
case (#ok(values)) {
#Ok(
values.map<Blob, ByteBuf>(
func(blob : Blob) : ByteBuf {
{ inner = blob };
}
)
);
};
};
};

public query (msg) func get_owned_non_empty_map_names() : async [ByteBuf] {
encryptedMaps.getOwnedNonEmptyMapNames(msg.caller).map<Blob, ByteBuf>(
func(blob : Blob) : ByteBuf {
{ inner = blob };
}
);
};

public shared (msg) func insert_encrypted_value(
map_owner : Principal,
map_name : ByteBuf,
map_key : ByteBuf,
value : ByteBuf,
) : async Result<?ByteBuf, Text> {
let result = encryptedMaps.insertEncryptedValue(msg.caller, (map_owner, map_name.inner), map_key.inner, value.inner);
switch (result) {
case (#err(e)) { #Err(e) };
case (#ok(null)) { #Ok(null) };
case (#ok(?blob)) { #Ok(?{ inner = blob }) };
};
};

public shared (msg) func remove_encrypted_value(
map_owner : Principal,
map_name : ByteBuf,
map_key : ByteBuf,
) : async Result<?ByteBuf, Text> {
let result = encryptedMaps.removeEncryptedValue(msg.caller, (map_owner, map_name.inner), map_key.inner);
switch (result) {
case (#err(e)) { #Err(e) };
case (#ok(null)) { #Ok(null) };
case (#ok(?blob)) { #Ok(?{ inner = blob }) };
};
};

public shared func get_vetkey_verification_key() : async ByteBuf {
let inner = await encryptedMaps.getVetkeyVerificationKey();
{ inner };
};

public shared (msg) func get_encrypted_vetkey(
map_owner : Principal,
map_name : ByteBuf,
transport_key : ByteBuf,
) : async Result<ByteBuf, Text> {
let result = await encryptedMaps.getEncryptedVetkey(msg.caller, (map_owner, map_name.inner), transport_key.inner);
switch (result) {
case (#err(e)) { #Err(e) };
case (#ok(vetkey)) { #Ok({ inner = vetkey }) };
};
};

public query (msg) func get_user_rights(
map_owner : Principal,
map_name : ByteBuf,
user : Principal,
) : async Result<?Types.AccessRights, Text> {
convertResult(encryptedMaps.getUserRights(msg.caller, (map_owner, map_name.inner), user));
};

public shared (msg) func set_user_rights(
map_owner : Principal,
map_name : ByteBuf,
user : Principal,
access_rights : Types.AccessRights,
) : async Result<?Types.AccessRights, Text> {
convertResult(encryptedMaps.setUserRights(msg.caller, (map_owner, map_name.inner), user, access_rights));
};

public shared (msg) func remove_user(
map_owner : Principal,
map_name : ByteBuf,
user : Principal,
) : async Result<?Types.AccessRights, Text> {
convertResult(encryptedMaps.removeUser(msg.caller, (map_owner, map_name.inner), user));
};

/// 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) };
};
};
include EncryptedMapsCanister(keyName, "password_manager_example_dapp");
};
2 changes: 1 addition & 1 deletion backend/mo/ic_vetkeys/mops.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ keywords = [
license = "Apache-2.0"

[toolchain]
moc = "1.6.0"
moc = "1.9.0"

[moc]
args = [ "-W=M0236,M0237,M0223" ]
Expand Down
Loading
Loading