Skip to content

Commit

Permalink
fix(did_parser): Add readme and simple example (#1047) (#1051)
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Prazak <o.prazak5@seznam.cz>
  • Loading branch information
xprazak2 committed Nov 8, 2023
1 parent 9bb6bf5 commit ed4ee6b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions did_parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# did_parser

## Overview
Rust crate for parsing [DIDs](https://www.w3.org/TR/did-core/#did-syntax) and [DID URLs](https://www.w3.org/TR/did-core/#did-url-syntax).

## Features
- **DID Parsing**: Capability to parse `did:` strings, ensuring they comply with the DID specifications.
- **DID URL**: Functionality to parse DID URLs.

## Getting Started
### Installation
Add the did_parser library as a dependency in your `Cargo.toml` file:
```toml
[dependencies]
did_parser = { 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 a basic functionality. You can run the demo with the following command:
```bash
cargo run --example demo
```

19 changes: 19 additions & 0 deletions did_parser/examples/demo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use did_parser::{Did, DidUrl};

fn main() {
// parse a string into DID
let did = Did::parse("did:web:w3c-ccg.github.io".into()).unwrap();
println!("{:?}", did.did());
println!("{:?}", did.method());
println!("{:?}", did.id());

// parse a string into DID URL
let did_url =
DidUrl::parse("did:example:123456789abcdefghi/foo;param=value?query=value".into()).unwrap();
println!("{:?}", did_url.did());
println!("{:?}", did_url.did_url());
println!("{:?}", did_url.method());
println!("{:?}", did_url.id());
println!("{:?}", did_url.path());
println!("{:?}", did_url.queries());
}

0 comments on commit ed4ee6b

Please sign in to comment.