1.0.5 • Published 4 years ago

3id-test-helper v1.0.5

Weekly downloads
33
License
ISC
Repository
github
Last release
4 years ago

3id Test Helper

A library to generate DIDs and sign Json Web Tokens (JWTs). This library is meant for running tests so that you do not need to log in to your wallet, connect to 3box and then sign JWTs.

Install

Using npm:

$ npm install 3id-test-helper

API

Create the class

const DidHelper = require('3id-test-helper')
const IPFS = require('ipfs')

const ipfs = await IPFS.create()
const testHelper = new DidHelper(ipfs)

Generate DIDs

const accounts = await testHelper.generateAccounts()

When you generate accounts, you create random Ethereum private keys which are used to generate your DIDs.

You can get those private keys and hardcode them in your tests so you can reuse the same DIDs.

const privateKeys = testHelper.getPrivateKeys()
const reusedDIDs = testHelper.generateAccounts(privateKeys)

Signing Json Web Tokens (JWTs)

Important: The did you pass in must have been generated by the class. When the class generates the DIDs, it creates a signer for JWTs.

const jwt = await testHelper.createJWTFromDID(did, payload)