-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Did peer refactoring, new display macro (#1034)
* Did peer refactoring, add examples, new display macro (#1034) Signed-off-by: Patrik Stas <[email protected]>
- Loading branch information
1 parent
4e65aec
commit 88f6e8e
Showing
52 changed files
with
548 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use display_as_json::Display; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default, Display)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct ExtraFieldsAIP1 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
extern crate display_as_json; | ||
|
||
pub mod error; | ||
pub mod extra_fields; | ||
// TODO: Remove once migration is done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# did_peer | ||
|
||
## Overview | ||
Rust crate for creation, parsing, validation, and resolution of [Peer DIDs](https://identity.foundation/peer-did-method-spec). | ||
Peer DIDs are a special type of decentralized identifiers designed for direct peer-to-peer interactions, without the | ||
need for a blockchain or other centralized registry. | ||
|
||
## Features | ||
- **Numalgo Support**: The library implements various version of did:peer. The different versions are referred to as "numalgos". | ||
Currently supports numalgo 1, 2, and 3. | ||
- **DID Parsing**: Capability to parse `did:peer` strings, ensuring they comply with the Peer DID specifications. | ||
- **DID Creation from DIDDoc**: Functionality to create `did:peer` identifiers from DID documents. | ||
- **Numalgo Conversion**: Ability to convert between different numalgos, specifically from Numalgo 2 to Numalgo 3. | ||
- **Validation**: Verification that DIDs adhere to the required specifications and format. | ||
|
||
## Getting Started | ||
### Installation | ||
Add the Peer DID library as a dependency in your `Cargo.toml` file: | ||
```toml | ||
[dependencies] | ||
peer_did = { tag = "0.61.0", git = "https://github.com/hyperledger/aries-vcx" } | ||
``` | ||
|
||
## Demo | ||
To get you off the ground, have a look at the [demo](./examples/demo.rs). It demonstrates how to create, parse. You can | ||
run the demo with the following command: | ||
```bash | ||
cargo run --example demo | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::error::Error; | ||
|
||
use did_doc::schema::{ | ||
did_doc::DidDocument, | ||
service::ServiceBuilder, | ||
types::{uri::Uri, url::Url}, | ||
verification_method::{VerificationMethod, VerificationMethodType}, | ||
}; | ||
use did_doc_sov::extra_fields::{didcommv1::ExtraFieldsDidCommV1, ExtraFieldsSov, KeyKind}; | ||
use did_parser::{Did, DidUrl}; | ||
use did_peer::peer_did::{ | ||
numalgos::{numalgo2::Numalgo2, numalgo3::Numalgo3}, | ||
PeerDid, | ||
}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
demo() | ||
} | ||
|
||
fn demo() -> Result<(), Box<dyn Error>> { | ||
let recipient_key = KeyKind::Value("foo".to_string()); | ||
let sov_service_extra = ExtraFieldsSov::DIDCommV1( | ||
ExtraFieldsDidCommV1::builder() | ||
.set_recipient_keys(vec![recipient_key]) | ||
.build(), | ||
); | ||
let service = ServiceBuilder::<ExtraFieldsSov>::new( | ||
Uri::new("xyz://example.org")?, | ||
Url::new("http://example.org")?, | ||
sov_service_extra, | ||
) | ||
.add_service_type("DIDCommMessaging".to_string())? | ||
.build(); | ||
|
||
let did_url = DidUrl::parse("did:foo:bar#key-1".into())?; | ||
let did = Did::parse("did:foo:bar".into())?; | ||
let verification_method = VerificationMethod::builder( | ||
did_url, | ||
did.clone(), | ||
VerificationMethodType::Ed25519VerificationKey2018, | ||
) | ||
.add_public_key_base64("Zm9vYmFyCg".to_string()) | ||
.build(); | ||
|
||
let ddo = DidDocument::builder(did) | ||
.add_verification_method(verification_method) | ||
.add_service(service) | ||
.build(); | ||
println!("Did document: \n{}", serde_json::to_string_pretty(&ddo)?); | ||
|
||
let peer_did_2 = PeerDid::<Numalgo2>::from_did_doc(ddo.clone())?; | ||
println!("as did:peer numalgo(2): {}", peer_did_2); | ||
|
||
let peer_did_3 = PeerDid::<Numalgo3>::from_did_doc(ddo)?; | ||
println!("as did:peer numalgo(3): {}", peer_did_3); | ||
|
||
let peer_did_3_v2 = peer_did_2.to_numalgo3()?; | ||
println!( | ||
"as did:peer numalgo(2) converted to numalgo(3): {}", | ||
peer_did_3_v2 | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn demo_test() -> Result<(), Box<dyn Error>> { | ||
demo() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
extern crate display_as_json; | ||
|
||
pub mod error; | ||
mod numalgos; | ||
pub mod peer_did; | ||
pub mod peer_did_resolver; | ||
pub mod resolver; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.