# did-doc

> DID Document creation library

Latest version **1.0.0** (published 2022-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install did-doc
pnpm add did-doc
yarn add did-doc
bun add did-doc
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-08-28 |
| First published | 2022-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 58.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Upkeep |
| Maintainers | misterupkeep |
| Keywords | DID, document |

## Links

- npm: https://www.npmjs.com/package/did-doc
- npm.io page: https://npm.io/package/did-doc

## Dependencies (1)

- [did-resolver](https://npm.io/package/did-resolver.md) ^4.0.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-08-28

## README

# did-doc

A simple class and type export to facilitate dealing with DID documents. More up
to date than other libraries out there (for now, probably).

## API

The library exports a `DIDDocument` class, as well as an `IDIDDocument`
TypeScript interface, as well as `Service` and `VerificationMethod` interfaces.

### DIDDocument

The `DIDDocument` class contains all the fields of the `IDIDDocument` interface:
```ts
export interface IDIDDocument {
  "@context"?: "https://www.w3.org/ns/did/v1" | string | string[];
  id: string;
  alsoKnownAs?: string[];
  controller?: string | string[];
  verificationMethod?: VerificationMethod[];
  service?: Service[];
}
```

The `DIDDocument` constructor:
```ts
constructor(id: string, opts: Omit<DIDDocument, "id"> = {})
```

The class also has a few helper functions:
```ts
/**
 * Adds to a top level field in the document named `set`. Will create it, if
 * it doesn't exist already.
 * @throws Will throw if there exists an object in the set wth the same `id` as `item.id`
 */
addToSet(set: string, item: Record<string, any>): void

/**
 * Add a new verification method to the document.
 * @throws Will throw if a method with the same ID already exists in the document
 * @param {Object} method
 * @param {string} method.id Method ID
 * @param {string} method.type Method type
 * @param {string} [method.controller] Method controller DID. If left out, will be set to the document's ID.
 */
addVerificationMethod(method: {
  id: string;
  type: string;
  controller?: string;
}): void
```

The class also has a static `isDoc(doc): boolean` validation function.

---
_Source: https://npm.io/package/did-doc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
