3id-test-helper 中文文档教程
3id Test Helper
用于生成 DID 和签署 Json Web 令牌 (JWT) 的库。 这个库用于运行测试,这样你就不需要登录到你的钱包,连接到 3box,然后签署 JWT。
Install
使用 npm:
$ npm install 3id-test-helper
API
创建类
const DidHelper = require('3id-test-helper')
const IPFS = require('ipfs')
const ipfs = await IPFS.create()
const testHelper = new DidHelper(ipfs)
生成 DID
const accounts = await testHelper.generateAccounts()
当您生成帐户时,您会创建随机的以太坊私钥,用于生成您的 DID。
您可以获得这些私钥并在测试中对它们进行硬编码,以便您可以重用相同的 DID。
const privateKeys = testHelper.getPrivateKeys()
const reusedDIDs = testHelper.generateAccounts(privateKeys)
签署 Json Web 令牌 (JWT)
重要提示:您传入的 did 必须由类生成。 当该类生成 DID 时,它会为 JWT 创建一个签名者。
const jwt = await testHelper.createJWTFromDID(did, payload)
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)