Expose all identity proofs when building Account object
This commit is contained in:
parent
cd93858488
commit
38bb3e38e9
2 changed files with 21 additions and 15 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,22 +79,25 @@ 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,
|
||||
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![];
|
||||
for extra_field in profile.extra_fields.clone().into_inner() {
|
||||
|
|
Loading…
Reference in a new issue