Giter VIP home page Giter VIP logo

js-dag-jose-utils's Introduction

dag-jose-utils

This library provides utilities for using the DAG-JOSE IPLD codec. It uses DAG-CBOR to encode payloads and cleartexts to CIDs.

Installation

First install the package

$ npm i --save dag-jose-utils

Importing

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

API

EncodedPayload

interface EncodedPayload {
  cid: CID
  linkedBlock: Uint8Array
}

encodePayload(payload: Record<string, any>): 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<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. 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.

Maintainer

Joel Thorstensson

License

MIT or APACHE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.