-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add pubky keys type #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
242ba73 to
acb6c77
Compare
|
Nice, I was about to look into a similar PR, glad this is already in place. Can you please add a way to get from a For example: impl Keypair {
fn pubky_id(&self) -> Result<PubkyId, String> {
PubkyId::try_from(self.public_key().to_z32().as_str())
}
}which allows // Before (verbose)
let pubky_id = PubkyId::try_from(&keypair.public_key().to_z32())?;
// After (concise)
let pubky_id = keypair.pubky_id()?; |
This would introduce a dependency on |
4f9d2e7 to
2a51a79
Compare
5c0a77e to
b563ea4
Compare
|
@SeverinAlexB Marking as ready for review here. No rush:
|
SeverinAlexB
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good. No idea if this will lead to accidental breaking changes in the homeserver.
Does the new KeyPair/PublicKey have the same lib export path as the old one? Maybe it is better to export it in a different path so one needs to explicitly upgrade to the new KeyPair/PublicKey so the dev can check each case.
yeha, good question. The wrapper keep the same public export locations ( Overall, |
706a598 to
cc55c1e
Compare
|
Merged main and fixes a myriad of conflicts and problems that rose from working in paralell with the new signup/signin authflow:
|
f9fe9f7 to
dbdc988
Compare
1510562 to
cecdc58
Compare
cecdc58 to
5dac082
Compare
SeverinAlexB
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments but I think most of it is good.
Did you ever close the prod or staging database and tested it with the data there to find issues?
| #[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| #[serde(transparent)] | ||
| pub struct PublicKey(pkarr::PublicKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if is_prefixed_pubky(s) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I see this correctly that the new pubky prefixed keys are not supported in pubky_host?
| impl Deref for PublicKey { | ||
| type Target = pkarr::PublicKey; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Returns true if the value is in `pubky<z32>` form. | ||
| pub fn is_prefixed_pubky(value: &str) -> bool { | ||
| matches!(value.strip_prefix("pubky"), Some(stripped) if stripped.len() == 52) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Shouldn't this be a static method that belongs to the PublicKey like PublicKey::is_pubky_prefixed(key: &str)?
| /// Export the secret key bytes. | ||
| #[must_use] | ||
| pub fn secret_key(&self) -> [u8; 32] { | ||
| let mut out = [0u8; 32]; | ||
| out.copy_from_slice(self.0.secret_key().as_ref()); | ||
| out | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fn parse_public_key(value: &str) -> Result<pkarr::PublicKey, ParseError> { | ||
| let raw = if is_prefixed_pubky(value) { | ||
| value.strip_prefix("pubky").unwrap_or(value) | ||
| } else { | ||
| value | ||
| }; | ||
| pkarr::PublicKey::try_from(raw.to_string()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Similar to the is_prefixed_pubky, shouldn't this be a static method on PublicKey?
| #[must_use] | ||
| pub const fn as_inner(&self) -> &pkarr::PublicKey { | ||
| &self.0 | ||
| } | ||
|
|
||
| /// Extract the inner [`pkarr::PublicKey`]. | ||
| #[must_use] | ||
| pub fn into_inner(self) -> pkarr::PublicKey { | ||
| self.0 | ||
| } | ||
|
|
||
| /// Return the raw z-base32 representation without the `pubky` prefix. | ||
| #[must_use] | ||
| pub fn z32(&self) -> String { | ||
| self.0.to_string() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing you need to change, just a comment:
I find the introduction of the #[must_use] tag really weird. For me, this feels like it clutters the code unnecessarily. Feels like a rust language downgrade.



PublicKey/Keypairwrappers inpubky-common::crypto::keysso every crate displays identifiers aspubky<z32>by default while still exposing.z32()for raw hostnames and registry usage.pubky...as default prefix for the public key identifier. This will be easy to change if the product team decides otherwise.pkarrkey usages across the workspace (SDK, JS bindings, homeserver, testnet) with the shared wrappers to guarantee consistent formatting and serde behavior. Thepkarr-republisherkeeps usingpkarrkeys.pubky-sdk, keeping documentation and examples aligned with the new display defaults.