Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unavi-xyz/dwn
Rust implementation of the Decentralized Web Node specification.
https://github.com/unavi-xyz/dwn
decentralized-web-node did dwn rust
Last synced: 29 days ago
JSON representation
Rust implementation of the Decentralized Web Node specification.
- Host: GitHub
- URL: https://github.com/unavi-xyz/dwn
- Owner: unavi-xyz
- License: gpl-3.0
- Created: 2023-12-16T02:42:40.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-23T07:49:15.000Z (almost 1 year ago)
- Last Synced: 2023-12-23T10:12:12.033Z (almost 1 year ago)
- Topics: decentralized-web-node, did, dwn, rust
- Language: Rust
- Homepage: https://crates.io/crates/dwn
- Size: 121 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dwn
Rust implementation of a [Decentralized Web Node](https://identity.foundation/decentralized-web-node/spec/).
The DWN spec is a work-in-progress and often out of date from other implementations,
so it is treated more as a loose guide rather than an absolute set of rules to follow.## Example
```rust
use dwn::{
core::{message::{descriptor::{RecordsReadBuilder, RecordsWriteBuilder}, mime::TEXT_PLAIN}, reply::Reply},
stores::NativeDbStore,
Actor,
Dwn
};
use xdid::methods::key::{p256::P256KeyPair, DidKeyPair, PublicKey};#[tokio::main]
async fn main() {
// Create a local in-memory DWN.
let store = NativeDbStore::new_in_memory().unwrap();
let mut dwn = Dwn::from(store);
// Create a new did:key.
let key = P256KeyPair::generate();
let did = key.public().to_did();
// Create an actor to sign messages on behalf of our DID.
let mut actor = Actor::new(did.clone());
actor.auth_key = Some(key.clone().into());
actor.sign_key = Some(key.into());
// Prepare to write a new record to the DWN.
let mut msg = RecordsWriteBuilder::default()
.data(TEXT_PLAIN, "Hello, world!".as_bytes().to_vec())
.published(true)
.build()
.unwrap();
let record_id = msg.record_id.clone();
// Authorize the message using the actor.
actor.authorize(&mut msg).unwrap();
// Process the message at our DID's DWN.
dwn.process_message(&did, msg.clone()).await.unwrap();
// We can now read the record using its ID.
let read = RecordsReadBuilder::new(record_id.clone())
.build()
.unwrap();
let reply = dwn.process_message(&did, read).await.unwrap();let found = match reply {
Some(Reply::RecordsRead(r)) => r.entry.unwrap(),
_ => panic!("invalid reply"),
};assert_eq!(found, msg);
}
```