-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: pds-drewmcarthur
Are you sure you want to change the base?
impl com.atproto.server.reserve_signing_key
#4
Conversation
…rewmcarthur-reserve-signing-key
…pds-drewmcarthur-reserve-signing-key
rsky-pds/src/repo/actor_store.rs
Outdated
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) | ||
} |
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.
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.
…pds-drewmcarthur-reserve-signing-key
…pds-drewmcarthur-reserve-signing-key
changes
mod actor_store
fromrsky-pds/src/repo/mod.rs
into its ownrsky-pds/src/repo/actor_store.rs
rsky-crypto/src/secp256k1/keypair.rs
, implementsSecp256k1Keypair
Didable
,Signer
,Keypair
, andExportableKeypair
torsky_crypto::types
ActorStoreConfig
, pulling stuff fromenv
ActorStore::reserve_keypair(&self, did: Option<&str>) -> anyhow::Result<String>;
cargo fmt
, which updatedrsky-pds/src/repo/preference/mod.rs
todo
actor_store::assert_safe_path_part
ActorStore
is initialized, match it with TS impl more?