diff --git a/crates/username_registry_coordinator/src/external_id_attestation.rs b/crates/username_registry_coordinator/src/external_id_attestation.rs index d90499c..c735931 100644 --- a/crates/username_registry_coordinator/src/external_id_attestation.rs +++ b/crates/username_registry_coordinator/src/external_id_attestation.rs @@ -4,7 +4,7 @@ use holoom_types::{ IngestExternalIdAttestationRequestPayload, LocalHoloomSignal, RejectExternalIdRequestPayload, RemoteHoloomSignal, SendExternalIdAttestationRequestPayload, }; -use username_registry_integrity::{EntryTypes, LinkTypes}; +use username_registry_integrity::{EntryTypes, LinkTypes, UnitEntryTypes}; use username_registry_utils::{get_authority_agent, hash_identifier}; #[hdk_extern] @@ -99,14 +99,21 @@ pub fn reject_external_id_request(payload: RejectExternalIdRequestPayload) -> Ex #[hdk_extern] pub fn create_external_id_attestation(attestation: ExternalIdAttestation) -> ExternResult { - let base_address = attestation.internal_pubkey.clone(); + let agent = attestation.internal_pubkey.clone(); + let external_id_hash = hash_identifier(attestation.external_id.clone())?; let attestation_action_hash = create_entry(EntryTypes::ExternalIdAttestation(attestation))?; create_link( - base_address, + agent, attestation_action_hash.clone(), LinkTypes::AgentToExternalIdAttestation, (), )?; + create_link( + external_id_hash, + attestation_action_hash.clone(), + LinkTypes::ExternalIdToAttestation, + (), + )?; let record = get(attestation_action_hash, GetOptions::default())?.ok_or(wasm_error!( WasmErrorInner::Guest(String::from( "Could not find the newly created ExternalIdAttestation" @@ -116,6 +123,12 @@ pub fn create_external_id_attestation(attestation: ExternalIdAttestation) -> Ext Ok(record) } +#[hdk_extern] +pub fn get_external_id_attestation(external_id_ah: ActionHash) -> ExternResult> { + get(external_id_ah, GetOptions::default()) +} + +#[hdk_extern] pub fn get_external_id_attestations_for_agent( agent_pubkey: AgentPubKey, ) -> ExternResult> { @@ -134,6 +147,7 @@ pub fn get_external_id_attestations_for_agent( Ok(maybe_records.into_iter().flatten().collect()) } +#[hdk_extern] pub fn get_attestation_for_external_id(external_id: String) -> ExternResult> { let base = hash_identifier(external_id)?; let mut links = get_links(base, LinkTypes::ExternalIdToAttestation, None)?; @@ -148,3 +162,23 @@ pub fn get_attestation_for_external_id(external_id: String) -> ExternResult ExternResult> { + if agent_info()?.agent_initial_pubkey != get_authority_agent()? { + return Err(wasm_error!(WasmErrorInner::Guest( + "Only callable by authority agent".into() + ))); + } + let entry_type: EntryType = UnitEntryTypes::ExternalIdAttestation + .try_into() + .expect("ExternalIdAttestation is an entry type"); + let filter = ChainQueryFilter::default() + .entry_type(entry_type) + .include_entries(false); + let ahs = query(filter)? + .into_iter() + .map(|record| record.action_address().to_owned()) + .collect(); + Ok(ahs) +}