Skip to content

Commit

Permalink
Add example and readme.md for did_peer crate
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Oct 31, 2023
1 parent 9570ba2 commit 4b17e8b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy --tests --all-features
cargo clippy --examples --tests --all-features
env:
RUSTFLAGS: -D warnings

Expand Down Expand Up @@ -354,7 +354,7 @@ jobs:
rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSON }}
- name: "Run resolver tests"
run: |
RUST_TEST_THREADS=1 cargo test -p did_doc -p did_parser -p did_resolver -p did_resolver_registry -p did_resolver_sov -p did_resolver_web -p did_doc_sov -p did_key -p did_peer --test "*"
RUST_TEST_THREADS=1 cargo test --examples -p did_doc -p did_parser -p did_resolver -p did_resolver_registry -p did_resolver_sov -p did_resolver_web -p did_doc_sov -p did_key -p did_peer --test "*"
test-integration-node-wrapper:
needs: workflow-setup
Expand Down
37 changes: 37 additions & 0 deletions did_peer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# did_peer

## Overview

The Peer DID Rust Library is a comprehensive toolkit for handling decentralized identifiers (DIDs) in a peer-to-peer manner. This library is implemented in Rust and allows for the creation, parsing, validation, and resolution of Peer DIDs. 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 numerical algorithms (numalgos) for DID creation and resolution. 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**: Comprehensive mechanisms to validate that DIDs adhere to the required specifications and format.

## Getting Started

### Prerequisites

Ensure that you have Rust and Cargo installed on your system. You can install them from the official [Rust website](https://www.rust-lang.org/).

### 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
```


12 changes: 11 additions & 1 deletion did_peer/tests/demo.rs → did_peer/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use did_peer::peer_did::{
PeerDid,
};

#[test]
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(
Expand Down Expand Up @@ -47,10 +50,17 @@ fn demo() -> Result<(), Box<dyn Error>> {

let peer_did_2 = PeerDid::<Numalgo2>::from_did_doc(ddo.clone())?;
println!("PeerDid numalgo(2): {}", peer_did_2);

let peer_did_3 = PeerDid::<Numalgo3>::from_did_doc(ddo)?;
println!("PeerDid numalgo(3): {}", peer_did_3);

let peer_did_3_v2 = peer_did_2.to_numalgo3()?;
println!("Converted PeerDid numalgo(3): {}", peer_did_3_v2);

Ok(())
}

#[test]
fn demo_test() -> Result<(), Box<dyn Error>> {
demo()
}

0 comments on commit 4b17e8b

Please sign in to comment.