Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ceramicnetwork/js-dag-jose-utils
https://github.com/ceramicnetwork/js-dag-jose-utils
Last synced: about 19 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/ceramicnetwork/js-dag-jose-utils
- Owner: ceramicnetwork
- License: other
- Created: 2020-10-01T12:55:22.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-03T15:10:42.000Z (9 months ago)
- Last Synced: 2024-09-18T02:29:24.562Z (7 days ago)
- Language: TypeScript
- Size: 965 KB
- Stars: 9
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
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): Promise
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, 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
Decode a decrypted cleartext to an ipld object.### encodeIdentityCID(obj: Record): CID
Encode an ipld object as a CID that uses the identity hash.### decodeIdentityCID(cid: CID): Record
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