# dag-jose-utils

> Utility functions for the dag-jose ipld codec

Latest version **4.0.0** (published 2024-01-03) · (Apache-2.0 OR MIT) license · 0 weekly downloads

## Install

```sh
npm install dag-jose-utils
pnpm add dag-jose-utils
yarn add dag-jose-utils
bun add dag-jose-utils
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-01-03 |
| First published | 2020-10-01 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | 3Box Labs |
| Maintainers | ceramic-velvetshark, cb3box, jpham2023, npm.3box, smrz2001, oed, paul_lecam, stbrody, ukstv |
| Keywords | ipld, ipfs, jose, dag, cbor |

## Links

- npm: https://www.npmjs.com/package/dag-jose-utils
- Repository: https://github.com/ceramicnetwork/js-dag-jose-utils
- Homepage: https://github.com/ceramicnetwork/js-dag-jose-utils#readme
- Issues: https://github.com/ceramicnetwork/js-dag-jose-utils/issues
- npm.io page: https://npm.io/package/dag-jose-utils

## Dependencies (2)

- [multiformats](https://npm.io/package/multiformats.md) ^13.0.0
- [@ipld/dag-cbor](https://npm.io/package/@ipld/dag-cbor.md) ^9.0.7

## Recent versions

- 4.0.0 (latest) — 2024-01-03
- 3.0.0-alpha.0 (next) — 2023-02-14
- 3.0.0 — 2023-02-24
- 2.0.0 — 2022-04-19
- 2.0.0-rc.0 — 2022-04-08
- 2.0.0-alpha.1 — 2021-12-24
- 2.0.0-alpha.0 — 2021-11-30
- 1.0.0 — 2021-05-31
- 0.1.1 — 2021-04-08
- 0.1.0 — 2020-10-01

## README

# dag-jose-utils

This library provides utilities for using the [DAG-JOSE](https://github.com/ceramicnetwork/js-dag-jose) IPLD codec. It uses [DAG-CBOR](https://github.com/ipld/js-dag-cbor) to encode payloads and cleartexts to CIDs.

## Installation
First install the package
```
$ npm i --save dag-jose-utils
```

## Importing
```ts
import {
  encodePayload,
  prepareCleartext,
  decodeCleartext,
  encodeIdentityCID,
  decodeIdentityCID,
  toJWSPayload,
  toJWSStrings
} from 'dag-jose-utils'
```

## API

### EncodedPayload
```ts
interface EncodedPayload {
  cid: CID
  linkedBlock: Uint8Array
}
```

### encodePayload(payload: Record<string, any>): Promise<EncodedPayload>
Prepares a payload to be signed in a JWS. Note that you will need to encode the `encodePayload.cid.bytes` as `base64url` before signing.

### prepareCleartext(cleartext: Record<string, any>, blockSize?: number): Uint8Array
Prepares a cleartext object to be encrypted in a JWE. By default the blockSize for padding is 24.

### decodeCleartext(b: Uint8Array): Record<string, any>
Decode a decrypted cleartext to an ipld object.

### encodeIdentityCID(obj: Record<string, any>): CID
Encode an ipld object as a CID that uses the identity hash.

### decodeIdentityCID(cid: CID): Record<string, any>
Decode an ipld object from a CID that uses the identity hash.

### toJWSPayload(payload: EncodedPayload | CID): string
Transform an `EncodedPayload` (from `encodePayload()`) or a CID into a JWS string for use with `createJWS()` in [did-jwt](https://github.com/decentralized-identity/did-jwt). The string form is simply the Base64url encoded form of the CID's byte representation.

### toJWSStrings(jose: any): string[]
Transform a `DagJWS` object from ipld-dag-jose into an array of strings for each signature in the object. The strings can then be verified using `verifyJWS()` in [did-jwt](https://github.com/decentralized-identity/did-jwt).

## Maintainer
[Joel Thorstensson](https://github.com/oed)

## License
MIT or APACHE

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