git ssb

0+

Spruce git-ssb bridge / ssi



Commit 685046a9058c94132ce30d967359cc52f8d52816

Add DID operations

Charles E. Lehner committed on 3/1/2022, 3:46:58 PM
Parent: c9bc80e38081223b6696e5a619c8fbaa5ca29490

Files changed

Cargo.tomlchanged
src/did.rschanged
Cargo.tomlView
@@ -79,8 +79,9 @@
7979 flate2 = "1.0"
8080 bitvec = "0.20"
8181 clear_on_drop = "0.2.4"
8282 url = { version = "2.2", features = ["serde"] }
83 +anyhow = "1.0"
8384 rand_xorshift = "0.3"
8485 bech32 = "0.8"
8586 snarkvm-dpc = { version = "0.7.9", optional = true }
8687 snarkvm-algorithms = { version= "0.7.9", optional = true }
src/did.rsView
@@ -4,8 +4,9 @@
44 //!
55 //! [did-core]: https://www.w3.org/TR/did-core/
66
77 use crate::caip10::BlockchainAccountId;
8 +use anyhow::{bail, Result as AResult};
89 use std::collections::BTreeMap as Map;
910 use std::collections::HashMap;
1011 use std::convert::TryFrom;
1112 use std::fmt;
@@ -385,8 +386,92 @@
385386 #[serde(flatten)]
386387 pub property_set: Option<Map<String, Value>>,
387388 }
388389
390 +/// DID Create Operation
391 +///
392 +/// <https://identity.foundation/did-registration/#create>
393 +pub struct DIDCreate {
394 + pub update_key: Option<JWK>,
395 + pub recovery_key: Option<JWK>,
396 + pub verification_key: Option<JWK>,
397 + pub options: Value,
398 +}
399 +
400 +/// DID Update Operation
401 +///
402 +/// <https://identity.foundation/did-registration/#update>
403 +pub struct DIDUpdate {
404 + pub did: String,
405 + pub update_key: Option<JWK>,
406 + pub new_update_key: Option<JWK>,
407 + pub operation: DIDDocumentOperation,
408 + pub options: Value,
409 +}
410 +
411 +/// DID Recover Operation
412 +///
413 +/// <https://www.w3.org/TR/did-core/#did-recovery>
414 +pub struct DIDRecover {
415 + pub did: String,
416 + pub recovery_key: Option<JWK>,
417 + pub new_update_key: Option<JWK>,
418 + pub new_recovery_key: Option<JWK>,
419 + pub new_verification_key: Option<JWK>,
420 + pub options: Value,
421 +}
422 +
423 +/// DID Deactivate Operation
424 +///
425 +/// <https://identity.foundation/did-registration/#deactivate>
426 +pub struct DIDDeactivate {
427 + pub did: String,
428 + pub key: Option<JWK>,
429 + pub options: Value,
430 +}
431 +
432 +/// DID Document Operation
433 +///
434 +/// This should represent [didDocument][dd] and [didDocumentOperation][ddo] specified by DID
435 +/// Registration.
436 +///
437 +/// [dd]: https://identity.foundation/did-registration/#diddocumentoperation
438 +/// [ddo]: https://identity.foundation/did-registration/#diddocument
439 +#[derive(Debug, Serialize, Deserialize, Clone)]
440 +#[serde(tag = "didDocumentOperation", content = "didDocument")]
441 +#[serde(rename_all = "camelCase")]
442 +pub enum DIDDocumentOperation {
443 + /// Set the contents of the DID document
444 + ///
445 + /// setDidDocument operation defined by DIF DID Registration
446 + SetDidDocument(Document),
447 +
448 + /// Add properties to the DID document
449 + ///
450 + /// addToDidDocument operation defined by DIF DID Registration
451 + AddToDidDocument(HashMap<String, Value>),
452 +
453 + /// Remove properties from the DID document
454 + ///
455 + /// removeFromDidDocument operation defined by DIF Registration
456 + RemoveFromDidDocument(Vec<String>),
457 +
458 + /// Add or update a verification method in the DID document
459 + SetVerificationMethod {
460 + vmm: VerificationMethodMap,
461 + purposes: Vec<VerificationRelationship>,
462 + },
463 +
464 + /// Add or update a service map in the DID document
465 + SetService(Service),
466 +
467 + /// Remove a verification method in the DID document
468 + RemoveVerificationMethod(DIDURL),
469 +
470 + /// Add or update a service map in the DID document
471 + RemoveService(DIDURL),
472 +}
473 +
389474 /// An implementation of a [DID method](https://www.w3.org/TR/did-core/#dfn-did-methods).
390475 ///
391476 /// Depends on the [DIDResolver][] trait.
392477 /// Also includes functionality to [generate][DIDMethod::generate] DIDs.
@@ -406,8 +491,28 @@
406491 fn generate(&self, _source: &Source) -> Option<String> {
407492 None
408493 }
409494
495 + /// Create a DID
496 + fn create(&self, _create: DIDCreate) -> AResult<DIDMethodTransaction> {
497 + bail!("Create operation not implemented for DID Method");
498 + }
499 +
500 + /// Update a DID
501 + fn update(&self, _update: DIDUpdate) -> AResult<DIDMethodTransaction> {
502 + bail!("Update operation not implemented for DID Method");
503 + }
504 +
505 + /// Recover a DID
506 + fn recover(&self, _recover: DIDRecover) -> AResult<DIDMethodTransaction> {
507 + bail!("Recover operation not implemented for DID Method");
508 + }
509 +
510 + /// Deactivate a DID
511 + fn deactivate(&self, _deactivate: DIDDeactivate) -> AResult<DIDMethodTransaction> {
512 + bail!("Deactivate operation not implemented for DID Method");
513 + }
514 +
410515 /// Upcast the DID method as a DID resolver.
411516 ///
412517 /// This is a workaround for [not being able to cast a trait object to a supertrait object](https://github.com/rust-lang/rfcs/issues/2765).
413518 ///

Built with git-ssb-web