Skip to content
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

impl com.atproto.server.reserve_signing_key #4

Open
wants to merge 8 commits into
base: pds-drewmcarthur
Choose a base branch
from

Conversation

DrewMcArthur
Copy link
Owner

@DrewMcArthur DrewMcArthur commented Jul 20, 2024

changes

  • pulls mod actor_store from rsky-pds/src/repo/mod.rs into its own rsky-pds/src/repo/actor_store.rs
  • creates rsky-crypto/src/secp256k1/keypair.rs, implements Secp256k1Keypair
  • adds traits Didable, Signer, Keypair, and ExportableKeypair to rsky_crypto::types
  • adds ActorStoreConfig, pulling stuff from env
  • adds ActorStore::reserve_keypair(&self, did: Option<&str>) -> anyhow::Result<String>;
  • ran cargo fmt, which updated rsky-pds/src/repo/preference/mod.rs

todo

  • finish actor_store::assert_safe_path_part
  • clean up how ActorStore is initialized, match it with TS impl more?
  • add tests

Comment on lines 325 to 343
pub async fn reserve_keypair(&self, did: Option<&str>) -> Result<String> {
if let Some(did) = did {
assert_safe_path_part(&did);
let key_loc = Path::new(&self.reserved_key_dir).join(did);
let key = load_key(key_loc);
if key.is_ok() {
return Ok(key?.did()?);
}
}
let keypair = Secp256k1Keypair::create(Some(Secp256k1KeypairOptions {
exportable: Some(true),
}))
.await?;
let key_did = keypair.did()?;
let key_loc = Path::new(&self.reserved_key_dir).join(&key_did);
fs::create_dir_all(self.reserved_key_dir.clone())?;
fs::write(key_loc, keypair.export()?)?;
Ok(key_did)
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts impl for reference

would appreciate a second set of eyes here - i want to make sure that i understand the conditional flow of this function. it seems to me like if we have a did that we pass in, then we'd want to load the key at that path and return the did of that key. otherwise, we go and create a new key, save it to a location, and return that new did.

if that's correct, this should probably be rewritten as a match did { Some(did) => {...}, None => {...} } expression. right now, there's the case where we do pass a did, but loading the file fails, and we create a new key instead (i.e. the if condition on line 330 is false, ! key.is_ok()).

but i'm just not too sure i have the logic right here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant