Skip to content

Commit

Permalink
Add pumpx identity (#3172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kailai-Wang authored Nov 8, 2024
1 parent ae3abae commit 3032559
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
36 changes: 33 additions & 3 deletions common/primitives/core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ pub enum Identity {

#[codec(index = 8)]
Google(IdentityString),

#[codec(index = 9)]
Pumpx(IdentityString),
}

impl Identity {
Expand All @@ -313,6 +316,7 @@ impl Identity {
| Self::Github(..)
| Self::Email(..)
| Self::Google(..)
| Self::Pumpx(..)
)
}

Expand Down Expand Up @@ -349,7 +353,8 @@ impl Identity {
| Identity::Discord(_)
| Identity::Github(_)
| Identity::Email(_)
| Identity::Google(_) => Vec::new(),
| Identity::Google(_)
| Identity::Pumpx(_) => Vec::new(),
}
}

Expand All @@ -366,7 +371,8 @@ impl Identity {
| Identity::Discord(_)
| Identity::Github(_)
| Identity::Email(_)
| Identity::Google(_) => networks.is_empty(),
| Identity::Google(_)
| Identity::Pumpx(_) => networks.is_empty(),
}
}

Expand All @@ -388,7 +394,8 @@ impl Identity {
| Identity::Discord(_)
| Identity::Github(_)
| Identity::Email(_)
| Identity::Google(_) => None,
| Identity::Google(_)
| Identity::Pumpx(_) => None,
}
}

Expand Down Expand Up @@ -455,6 +462,10 @@ impl Identity {
return Ok(Identity::Google(IdentityString::new(
v[1].as_bytes().to_vec(),
)));
} else if v[0] == "pumpx" {
return Ok(Identity::Pumpx(IdentityString::new(
v[1].as_bytes().to_vec(),
)));
} else {
return Err("Unknown did type");
}
Expand Down Expand Up @@ -500,6 +511,11 @@ impl Identity {
str::from_utf8(handle.inner_ref())
.map_err(|_| "google handle conversion error")?
),
Identity::Pumpx(handle) => format!(
"pumpx:{}",
str::from_utf8(handle.inner_ref())
.map_err(|_| "pumpx handle conversion error")?
),
}
))
}
Expand Down Expand Up @@ -588,6 +604,7 @@ mod tests {
Identity::Bitcoin(..) => false,
Identity::Solana(..) => false,
Identity::Google(..) => true,
Identity::Pumpx(..) => true,
}
)
})
Expand All @@ -608,6 +625,7 @@ mod tests {
Identity::Bitcoin(..) => true,
Identity::Solana(..) => true,
Identity::Google(..) => false,
Identity::Pumpx(..) => false,
}
)
})
Expand All @@ -628,6 +646,7 @@ mod tests {
Identity::Bitcoin(..) => false,
Identity::Solana(..) => false,
Identity::Google(..) => false,
Identity::Pumpx(..) => false,
}
)
})
Expand All @@ -648,6 +667,7 @@ mod tests {
Identity::Bitcoin(..) => false,
Identity::Solana(..) => false,
Identity::Google(..) => false,
Identity::Pumpx(..) => false,
}
)
})
Expand All @@ -668,6 +688,7 @@ mod tests {
Identity::Bitcoin(..) => true,
Identity::Solana(..) => false,
Identity::Google(..) => false,
Identity::Pumpx(..) => false,
}
)
})
Expand All @@ -688,6 +709,7 @@ mod tests {
Identity::Bitcoin(..) => false,
Identity::Solana(..) => true,
Identity::Google(..) => false,
Identity::Pumpx(..) => false,
}
)
})
Expand Down Expand Up @@ -830,4 +852,12 @@ mod tests {
assert_eq!(identity.to_did().unwrap(), did_str);
assert_eq!(Identity::from_did(did_str).unwrap(), identity);
}

#[test]
fn test_pumpx_did() {
let identity = Identity::Pumpx(IdentityString::new("12345678".as_bytes().to_vec()));
let did_str = "did:litentry:pumpx:12345678";
assert_eq!(identity.to_did().unwrap(), did_str);
assert_eq!(Identity::from_did(did_str).unwrap(), identity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub fn identity_with_networks_to_token(identity: &IdentityNetworkTuple) -> Token
Identity::Solana(addr) => (6, addr.as_ref().to_vec()),
Identity::Email(str) => (7, str.inner_ref().to_vec()),
Identity::Google(str) => (8, str.inner_ref().to_vec()),
Identity::Pumpx(str) => (9, str.inner_ref().to_vec()),
};
let networks: Vec<Token> = identity.1.iter().map(network_to_token).collect();
Token::Tuple(vec![Token::Uint(type_index.into()), Token::Bytes(value), Token::Array(networks)])
Expand Down
1 change: 1 addition & 0 deletions tee-worker/identity/service/src/prometheus_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ fn handle_stf_call_request(req: RequestType, time: f64) {
Identity::Bitcoin(_) => "Bitcoin".into(),
Identity::Solana(_) => "Solana".into(),
Identity::Google(_) => "Google".into(),
Identity::Pumpx(_) => "Pumpx".into(),
},
};
inc_stf_calls(category, &label);
Expand Down

0 comments on commit 3032559

Please sign in to comment.