<!-- @format -->

# @dwn-protocol/id

Code Coverage
![Statements](https://img.shields.io/badge/statements-97.14%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-86.19%25-yellow.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-86.1%25-yellow.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-97.14%25-brightgreen.svg?style=flat)

## Introduction

This repository contains ID++ v1 backwards compatibilty and 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.

Proposals and issues for the specification itself should be submitted as pull requests.

## Documentation

* <a href="docs/index.html">ID Dwn Protocol</a>
* <a href="">ID Dwn Guide</a>
* <a href="wp.pdf">ID Dwn Whitepaper</a>
* <a href="https://ssid.dwn.vc">ID SSI API Docs</a>

## Installation

```bash
npm install @dwn-protocol/id
```

## Tests

To disable all tests

```bash
export TESTSOFF=true
```

## Usage

```javascript
import { 
  Dwn,
  DataStream,
  DidKeyResolver,
  DwnConfig,
  Jws,
  RecordsWrite,
  RecordsQuery,
  MessageStoreLevel
} from '@dwn-protocol/id';

let messageStore = new MessageStoreLevel({
  blockstoreLocation : 'BLOCKSTORE',
  indexLocation      : 'INDEX'
});

await messageStore.open();

// optional config
const config: DwnConfig = { messageStore };
const dwn = await Dwn.create(config);
// or 
const dwn = await Dwn.create();

// generate a did:key DID
const didKey = await DidKeyResolver.generate();

const signature = Jws.createSignatureInput(didKey);

// in node.js
const data = randomBytes(32);

// in web
const data = new Uint8Array(32);
window.crypto.getRandomValues(data);


const query = await RecordsWrite.create({
  data,
  dataFormat                  : 'application/json',
  published                   : true,
  protocol                    : 'authentication',
  schema                      : 'authentication/get',
  authorizationSignatureInput : signature
});

const dataStream = DataStream.fromBytes(data);
const response = await dwn.processMessage(didState.did, query.toJSON(), dataStream);

console.log('response', JSON.stringify(response));

```

_Note: built for node and browser environments_

## Architecture
>
>The diagram is a conceptual view, the actual component abstraction and names in the source code file may differ.

<img src="./images/id-architecture.png" alt="Architecture" width="700" >

## Project Resources

| Resource                                   | Description                                                                    |
| ------------------------------------------ | ------------------------------------------------------------------------------ |
| [CODEOWNERS](./CODEOWNERS)                 | Outlines the project lead(s)                                                   |
| [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) | Expected behavior for project contributors, promoting a welcoming environment |
| [CONTRIBUTING.md](./CONTRIBUTING.md)       | Developer guide to build, test, run, access CI, chat, discuss, file issues     |
| [GOVERNANCE.md](./GOVERNANCE.md)           | Project governance                                                             |
| [LICENSE](./LICENSE)                       | Apache License, Version 2.0                                                    |


NOTES 
@TODO implement winston for any logging transports

https://www.npmjs.com/package/winston