Skip to content

Commit d25636a

Browse files
clarifying readme examples (#221)
* clarifying readme examples * audit fix from npm * minor updates to README * refactored and exposes more utility methods and updated README --------- Co-authored-by: Henry Tsai <[email protected]>
1 parent ea39368 commit d25636a

17 files changed

+6111
-79
lines changed

README.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
# Decentralized Web Node (DWN) SDK
44

55
Code Coverage
6-
![Statements](https://img.shields.io/badge/statements-94.85%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-94.53%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-92.04%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-94.85%25-brightgreen.svg?style=flat)
6+
![Statements](https://img.shields.io/badge/statements-94.88%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-94.56%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-92.13%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-94.88%25-brightgreen.svg?style=flat)
77

88
## Introduction
99

1010
This repository contains a reference implementation of Decentralized Web Node (DWN) as per the [specification](https://identity.foundation/decentralized-web-node/spec/). This specification is in a draft state and very much so a WIP. For the foreseeable future, a lot of the work on DWN will be split across this repo and the repo that houses the specification, which you can find [here](https://github.com/decentralized-identity/decentralized-web-node). The current goal is to produce a beta implementation by March 2023. This won't include all interfaces described in the DWN spec, but will be enough to begin building applications.
1111

12+
This project is used as a dependency by several other projects.
13+
1214
Proposals and issues for the specification itself should be submitted as pull requests to the [spec repo](https://github.com/decentralized-identity/decentralized-web-node).
1315

1416
## Installation
@@ -22,12 +24,53 @@ npm install @tbd54566975/dwn-sdk-js
2224
[API docs](https://tbd54566975.github.io/dwn-sdk-js/)
2325

2426
```javascript
25-
import { Dwn } from '@tbd54566975/dwn-sdk-js';
2627

27-
// cool things
28+
import { Dwn, DataStream, DidKeyResolver, Jws, RecordsWrite, RecordsQuery } from '@tbd54566975/dwn-sdk-js';
29+
30+
export const dwn = await Dwn.create({});
31+
32+
...
33+
const didKey = await DidKeyResolver.generate(); // generate a did:key DID
34+
const signatureMaterial = Jws.createSignatureInput(didKey);
35+
const data = randomBytes(32); // in node.js
36+
// or in web
37+
// const data = new Uint8Array(32);
38+
// window.crypto.getRandomValues(data);
39+
40+
const query = await RecordsWrite.create({
41+
data,
42+
dataFormat : 'application/json',
43+
published : true,
44+
protocol : 'yeeter',
45+
schema : 'yeeter/post',
46+
authorizationSignatureInput : signatureMaterial
47+
});
48+
49+
const dataStream = DataStream.fromBytes(data);
50+
const result = await dwn.processMessage(didState.did, query.toJSON(), dataStream);
51+
2852
```
2953

30-
_Note: Works in both node and browser environments_
54+
With a web wallet installed:
55+
```javascript
56+
57+
const result = await window.web5.dwn.processMessage({
58+
method : 'RecordsQuery',
59+
message : {
60+
filter: {
61+
schema: 'http://some-schema-registry.org/todo'
62+
},
63+
dateSort: 'createdAscending'
64+
}
65+
});
66+
```
67+
68+
## Some projects that use this library:
69+
70+
* [Example CLI](https://github.com/TBD54566975/dwn-cli)
71+
* [Example with a web wallet](https://github.com/TBD54566975/incubating-web5-labs/)
72+
* [Server side aggregator](https://github.com/TBD54566975/dwn-server)
73+
3174

3275
## Project Resources
3376

0 commit comments

Comments
 (0)