dwn-rs is a Rust-based implementation of the Decentralized Web Node (DWN) specification. This library provides the core traits and implementations necessary to interact with DWN services, designed to be used by other libraries and applications. It can be compiled for WebAssembly for use in web browsers or run natively.
dwn-rs aims to facilitate the development of decentralized web applications and services by providing a robust and easy-to-use DWN core library. Key features include:
- Core DWN types and traits
- Compatibility with WebAssembly and native environments
- Integration with the dwn-sdk-js for JavaScript interoperability
- Rust 1.75.0+
- cargo-make
- wasm-pack
To install cargo-make
, run:
$ cargo install cargo-make
To install wasm-pack
, run:
$ cargo install wasm-pack
To compile the project for WebAssembly, execute the following command:
$ cargo make build-wasm
To build and run the project in a native Rust environment, use:
$ cargo build
$ cargo run
Once you have compiled the project to WebAssembly, you can use the generated .wasm
file in your dwn-sdk-js
project to implement a store. Here's how to do it:
- Compile the Rust project to WASM:
Make sure you have built the WASM file using the following command:
$ cargo make build-wasm
- Copy the WASM file to your
dwn-sdk-js
project:
The compiled WASM file is usually located in the crates/dwn-rs-wasm/pks/
directory. Copy this file to an appropriate location in your dwn-sdk-js
project.
- Initialize the WASM stores in your JavaScript code:
Use the following code to load and utilize the WASM file in your JavaScript project:
import {
SurrealDataStore,
SurrealMessageStore,
SurrealEventLog,
SurrealResumableTaskStore,
EventStream,
init_tracing,
TracingLevel,
} from "../pkg/index.js";
// only needed in Node environments
import WebSocket from "isomorphic-ws";
global.WebSocket = WebSocket;
// only required if you want logging/tracing to the console
init_tracing(TracingLevel.Error);
let messageStore = new SurrealMessageStore();
await messageStore.connect("mem://");
let dataStore = new SurrealDataStore();
await dataStore.connect("mem://");
let eventLog = new SurrealEventLog();
await eventLog.connect("mem://");
let resumableTaskStore = new SurrealResumableTaskStore();
await t.connect("mem://");
let eventStream = new EventStream();
const dwn = await Dwn.create({
messageStore,
dataStore,
eventLog,
resumableTaskStore,
eventStream,
});
To connect to a remove SurrealDB server, use a connection string in the form: ws://<username>:<password>@<host>:<port>/<namespace>
.
The auth type (root
or namespace
) can be given with ?auth=<type>
. dwn-rs
requires the full namespace for tenanted operations.
- Run your project:
Ensure that your project is set up to serve the WASM file correctly and run your project as usual.
- Implement core DWN types and traits
- Compatibility with WebAssembly
- Integration with dwn-sdk-js
- Message store
- Data store
- Event Log
- Event Stream
- DWN Message processing
- JSONAPI service
- Light "DWN" proxy
- Data sharing protocols
We welcome contributions from the community! Please check out our contribution guidelines in the CONTRIBUTING.md
file and feel free to open issues or submit pull requests.
This project is licensed under the Apache License. See the LICENSE
file for more details.
Thanks to the Decentralized Identity Foundation (DIF) and the contributors to the DWN specification and companion guide for their invaluable resources and guidance.