summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/did.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-07 20:16:28 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-07 20:16:30 -0800
commit02cd7b33d090db2aa47126a4d1aeecb247e7b7ef (patch)
treee227c257cc6178e712ca6b8a821ca5d686db0a14 /adenosine-pds/src/did.rs
parent79869226250beff62dde2c57a8e6e16eaa893b75 (diff)
downloadadenosine-02cd7b33d090db2aa47126a4d1aeecb247e7b7ef.tar.gz
adenosine-02cd7b33d090db2aa47126a4d1aeecb247e7b7ef.zip
pds: refactor account creation, did docs, etc
To allow creating accounts from the CLI, and creating did:web accounts (as opposed to did:plc). Also a buch of config refactoring.
Diffstat (limited to 'adenosine-pds/src/did.rs')
-rw-r--r--adenosine-pds/src/did.rs98
1 files changed, 59 insertions, 39 deletions
diff --git a/adenosine-pds/src/did.rs b/adenosine-pds/src/did.rs
index 84cf4c2..74e4f68 100644
--- a/adenosine-pds/src/did.rs
+++ b/adenosine-pds/src/did.rs
@@ -90,45 +90,6 @@ impl CreateOp {
Did::from_str(&format!("did:plc:{}", &digest_b32[0..24])).unwrap()
}
- pub fn did_doc(&self) -> serde_json::Value {
- let did = self.did_plc();
- // TODO:
- let user_url = format!("https://{}.test", self.username);
- let key_type = "EcdsaSecp256r1VerificationKey2019";
- json!({
- "@context": [
- "https://www.w3.org/ns/did/v1",
- "https://w3id.org/security/suites/ecdsa-2019/v1"
- ],
- "id": did.to_string(),
- "alsoKnownAs": [ user_url ],
- "verificationMethod": [
- {
- "id": format!("{}#signingKey)", did),
- "type": key_type,
- "controller": did.to_string(),
- "publicKeyMultibase": self.signingKey
- },
- {
- "id": format!("{}#recoveryKey)", did),
- "type": key_type,
- "controller": did.to_string(),
- "publicKeyMultibase": self.recoveryKey
- }
- ],
- "assertionMethod": [ format!("{}#signingKey)", did)],
- "capabilityInvocation": [ format!("{}#signingKey)", did) ],
- "capabilityDelegation": [ format!("{}#signingKey)", did) ],
- "service": [
- {
- "id": format!("{}#atpPds)", did),
- "type": "AtpPersonalDataServer",
- "serviceEndpoint": self.service
- }
- ]
- })
- }
-
fn into_unsigned(self) -> UnsignedCreateOp {
UnsignedCreateOp {
op_type: self.op_type,
@@ -140,6 +101,18 @@ impl CreateOp {
}
}
+ pub fn did_doc(&self) -> serde_json::Value {
+ let meta = DidDocMeta {
+ did: self.did_plc(),
+ // TODO
+ user_url: format!("https://{}", self.username),
+ service_url: self.service.clone(),
+ recovery_didkey: self.recoveryKey.clone(),
+ signing_didkey: self.signingKey.clone(),
+ };
+ meta.did_doc()
+ }
+
/// This method only makes sense on the "genesis" create object
pub fn verify_self(&self) -> Result<()> {
let key = PubKey::from_did_key(&self.signingKey)?;
@@ -154,6 +127,53 @@ impl CreateOp {
}
}
+#[derive(Debug, PartialEq, Eq, Clone)]
+pub struct DidDocMeta {
+ pub did: Did,
+ pub user_url: String,
+ pub service_url: String,
+ pub recovery_didkey: String,
+ pub signing_didkey: String,
+}
+
+impl DidDocMeta {
+ pub fn did_doc(&self) -> serde_json::Value {
+ let key_type = "EcdsaSecp256r1VerificationKey2019";
+ json!({
+ "@context": [
+ "https://www.w3.org/ns/did/v1",
+ "https://w3id.org/security/suites/ecdsa-2019/v1"
+ ],
+ "id": self.did.to_string(),
+ "alsoKnownAs": [ self.user_url ],
+ "verificationMethod": [
+ {
+ "id": format!("{}#signingKey)", self.did),
+ "type": key_type,
+ "controller": self.did.to_string(),
+ "publicKeyMultibase": self.signing_didkey
+ },
+ {
+ "id": format!("{}#recoveryKey)", self.did),
+ "type": key_type,
+ "controller": self.did.to_string(),
+ "publicKeyMultibase": self.recovery_didkey
+ }
+ ],
+ "assertionMethod": [ format!("{}#signingKey)", self.did)],
+ "capabilityInvocation": [ format!("{}#signingKey)", self.did) ],
+ "capabilityDelegation": [ format!("{}#signingKey)", self.did) ],
+ "service": [
+ {
+ "id": format!("{}#atpPds)", self.did),
+ "type": "AtpPersonalDataServer",
+ "serviceEndpoint": self.service_url
+ }
+ ]
+ })
+ }
+}
+
#[test]
fn test_debug_did_signing() {
let op = UnsignedCreateOp {