3id-test-helper

Generate 3IDs and signers for testing

Usage no npm install needed!

<script type="module">
  import idTestHelper from 'https://cdn.skypack.dev/3id-test-helper';
</script>

README

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)