dag-jose-utils
Version:
Utility functions for the dag-jose ipld codec
60 lines (45 loc) • 2 kB
Markdown
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.
First install the package
```
$ npm i --save dag-jose-utils
```
```ts
import {
encodePayload,
prepareCleartext,
decodeCleartext,
encodeIdentityCID,
decodeIdentityCID,
toJWSPayload,
toJWSStrings
} from 'dag-jose-utils'
```
```ts
interface EncodedPayload {
cid: CID
linkedBlock: Uint8Array
}
```
Prepares a payload to be signed in a JWS. Note that you will need to encode the `encodePayload.cid.bytes` as `base64url` before signing.
Prepares a cleartext object to be encrypted in a JWE. By default the blockSize for padding is 24.
Decode a decrypted cleartext to an ipld object.
Encode an ipld object as a CID that uses the identity hash.
Decode an ipld object from a CID that uses the identity hash.
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.
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).
[ ](https://github.com/oed)
MIT or APACHE
This library provides utilities