diff --git a/dnas/trusted/zomes/coordinator/trusted/src/gpg_key_dist.rs b/dnas/trusted/zomes/coordinator/trusted/src/gpg_key_dist.rs index cbaa395..175ff21 100644 --- a/dnas/trusted/zomes/coordinator/trusted/src/gpg_key_dist.rs +++ b/dnas/trusted/zomes/coordinator/trusted/src/gpg_key_dist.rs @@ -1,3 +1,4 @@ +use crate::convert_to_app_entry_type; use hdk::prelude::*; use trusted_integrity::prelude::*; @@ -57,8 +58,8 @@ pub struct SearchKeysRequest { #[derive(Serialize, Deserialize, Debug, Clone, SerializedBytes)] pub struct SearchKeysResponse { - pub key: Record, - pub key_collection_count: usize, + pub gpg_key_dist: GpgKeyDist, + pub reference_count: usize, } #[hdk_extern] @@ -95,13 +96,15 @@ pub fn search_keys(request: SearchKeysRequest) -> ExternResult { + // TODO permissible to have a key in multiple collections so this count needs to be a + // get + filter to unique agents let link_count = count_links(LinkQuery::new( target, LinkTypes::GpgKeyDistToKeyCollection.try_into_filter()?, ))?; out.push(SearchKeysResponse { - key: r, - key_collection_count: link_count, + gpg_key_dist: convert_to_app_entry_type(r)?, + reference_count: link_count, }); } _ => { diff --git a/dnas/trusted/zomes/coordinator/trusted/src/lib.rs b/dnas/trusted/zomes/coordinator/trusted/src/lib.rs index 3b3db54..fe43a08 100644 --- a/dnas/trusted/zomes/coordinator/trusted/src/lib.rs +++ b/dnas/trusted/zomes/coordinator/trusted/src/lib.rs @@ -101,3 +101,18 @@ fn get_entry_for_action(action_hash: &ActionHash) -> ExternResult(record: Record) -> ExternResult +where + T: TryFrom, +{ + record + .entry() + .as_option() + .and_then(|e| e.as_app_entry()) + .and_then(|e| -> Option { e.clone().into_sb().try_into().ok() }) + .ok_or(wasm_error!(WasmErrorInner::Guest(format!( + "Could not convert record to: {:?}", + std::any::type_name::() + )))) +} diff --git a/tests/src/trusted/trusted/gpg-key-dist.test.ts b/tests/src/trusted/trusted/gpg-key-dist.test.ts index aa272d1..274b442 100644 --- a/tests/src/trusted/trusted/gpg-key-dist.test.ts +++ b/tests/src/trusted/trusted/gpg-key-dist.test.ts @@ -66,9 +66,8 @@ test('Search for a key', async () => { }, }); assert.equal(1, responses.length); - const decoded = (decode((responses[0].key.entry as any).Present.entry) as any); - assert.equal("Alice", decoded.name); - assert.equal(sampleGpgKey().trim(), decoded.public_key); + assert.equal("Alice", responses[0].gpg_key_dist.name); + assert.equal(sampleGpgKey().trim(), responses[0].gpg_key_dist.public_key); }); }); @@ -109,8 +108,7 @@ test('Search for a key which is in another agent collection', async () => { }, }); assert.equal(1, responses.length); - const decoded = (decode((responses[0].key.entry as any).Present.entry) as any); - assert.equal("Alice", decoded.name); - assert.equal(1, responses[0].key_collection_count); + assert.equal("Alice", responses[0].gpg_key_dist.name); + assert.equal(1, responses[0].reference_count); }); }); diff --git a/ui/src/component/KeyList.vue b/ui/src/component/KeyList.vue index 267e6a8..e3747af 100644 --- a/ui/src/component/KeyList.vue +++ b/ui/src/component/KeyList.vue @@ -39,6 +39,9 @@ const copyFingerprint = (keyDist: GpgKeyDist) => { Name Email Expiry + + References + Fingerprint Action @@ -48,6 +51,9 @@ const copyFingerprint = (keyDist: GpgKeyDist) => { {{ k.name }} {{ k.email ?? "-" }} {{ k.expires_at ? formatDistanceToNow(k.expires_at) : "-" }} + + {{ k.reference_count ?? "unknown" }} + diff --git a/ui/src/trusted/trusted/SearchKeys.vue b/ui/src/trusted/trusted/SearchKeys.vue index 9aaebf4..f578f6e 100644 --- a/ui/src/trusted/trusted/SearchKeys.vue +++ b/ui/src/trusted/trusted/SearchKeys.vue @@ -1,8 +1,7 @@