Skip to content
/ dwn-rs Public

Store implementation for dwn-sdk-js

License

Notifications You must be signed in to change notification settings

enmand/dwn-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

dwn-rs πŸŒπŸš€

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.

Project Description πŸ“

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

Requirements πŸ› οΈ

To install cargo-make, run:

$ cargo install cargo-make

To install wasm-pack, run:

$ cargo install wasm-pack

Building and Running 🚧

Building for WebAssembly 🌐

To compile the project for WebAssembly, execute the following command:

$ cargo make build-wasm

Running in Pure Rust πŸ¦€ (WIP)

To build and run the project in a native Rust environment, use:

$ cargo build
$ cargo run

Integration with dwn-sdk-js πŸŒπŸ—„οΈ

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:

  1. Compile the Rust project to WASM:

Make sure you have built the WASM file using the following command:

$ cargo make build-wasm
  1. 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.

  1. 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.

  1. Run your project:

Ensure that your project is set up to serve the WASM file correctly and run your project as usual.

Roadmap πŸ—ΊοΈ

Core Features

  • 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

Functional Requirements

  • Data sharing protocols

Contributions 🀝

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.

License πŸ“œ

This project is licensed under the Apache License. See the LICENSE file for more details.

Acknowledgements πŸ™

Thanks to the Decentralized Identity Foundation (DIF) and the contributors to the DWN specification and companion guide for their invaluable resources and guidance.

About

Store implementation for dwn-sdk-js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •