Expose all identity proofs when building Account object

This commit is contained in:
silverpill 2022-11-10 17:31:33 +00:00
parent cd93858488
commit 38bb3e38e9
2 changed files with 21 additions and 15 deletions

View file

@ -23,6 +23,10 @@ pub struct DidKey {
pub struct MulticodecError;
impl DidKey {
pub fn key_multibase(&self) -> String {
encode_multibase_base58btc(&self.key)
}
pub fn from_ed25519_key(key: [u8; 32]) -> Self {
let prefixed_key = [
MULTICODEC_ED25519_PREFIX.to_vec(),
@ -99,8 +103,7 @@ impl FromStr for DidKey {
impl fmt::Display for DidKey {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let encoded_key = encode_multibase_base58btc(&self.key);
let did_str = format!("did:key:{}", encoded_key);
let did_str = format!("did:key:{}", self.key_multibase());
write!(formatter, "{}", did_str)
}
}

View file

@ -79,21 +79,24 @@ impl Account {
let mut identity_proofs = vec![];
for proof in profile.identity_proofs.clone().into_inner() {
let did_pkh = match proof.issuer {
Did::Pkh(did_pkh) => did_pkh,
_ => continue,
let (field_name, field_value) = match proof.issuer {
Did::Key(did_key) => {
("Key".to_string(), did_key.key_multibase())
},
Did::Pkh(did_pkh) => {
let field_name = did_pkh.currency()
.map(|currency| currency.field_name())
.unwrap_or("$".to_string());
(field_name, did_pkh.address)
}
};
// Skip proof if it doesn't map to field name
if let Some(currency) = did_pkh.currency() {
let field_name = currency.field_name();
let field = AccountField {
name: field_name,
value: did_pkh.address,
// Use current time because DID proofs are always valid
verified_at: Some(Utc::now()),
};
identity_proofs.push(field);
let field = AccountField {
name: field_name,
value: field_value,
// Use current time because DID proofs are always valid
verified_at: Some(Utc::now()),
};
identity_proofs.push(field);
};
let mut extra_fields = vec![];