-
Notifications
You must be signed in to change notification settings - Fork 20
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.
| /// Construct a [`Keypair`] from a 32-byte secret key. | ||
| #[must_use] | ||
| pub fn from_secret_key(secret: &[u8; 32]) -> Self { | ||
| Self(pkarr::Keypair::from_secret_key(secret)) | ||
| } |
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.
Missing secret key as [u8; 32] export.
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.
Good catch, working on this.
| impl TryFrom<&str> for PublicKey { | ||
| type Error = ParseError; | ||
|
|
||
| fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
| parse_public_key(value).map(Self) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&String> for PublicKey { | ||
| type Error = ParseError; | ||
|
|
||
| fn try_from(value: &String) -> Result<Self, Self::Error> { | ||
| parse_public_key(value).map(Self) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<String> for PublicKey { | ||
| type Error = ParseError; | ||
|
|
||
| fn try_from(value: String) -> Result<Self, Self::Error> { | ||
| parse_public_key(&value).map(Self) | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for PublicKey { | ||
| type Err = ParseError; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| parse_public_key(s).map(Self) | ||
| } | ||
| } |
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.
Asking ignorantly, are the TryFrom<&str or String or &String> even needed when one implements FromStr?
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.
This question makes sense. The explicit TryFrom<&str/String/&String> impls mirror the prior pkarr surface so existing calls using PublicKey::try_from(...) continue to compile without switching to FromStr::from_str; they’re intentionally redundant for API compatibility. We could go ahead a boyscout further but I fear there might be a rabbit hole somewhere around here.
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.
Makes sense
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
76aa1b7 to
5b31093
Compare
WIP: do not review.
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.