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

View file

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