@caelum-tech/verifier-client
v1.2.0
Published
Client for verification daemon for Distributed Identities (DIDs)
Downloads
9
Readme
Caelum Verifier Client
Javascript client for connecting to the Caelum Verifier Daemon via Matrix
|Branch|Pipeline|Coverage|
|:-:|:-:|:-:|
|master
|||
Run tests
Install dependencies
npm i
Run the tests
npm test
Usage
npm install -s @caelum-tech/verifier-client
const Client = require('@caelum-tech/verifier-client')
// implement callback function to receive responses from the verification bot
// event: the Matrix event containing the message
// data: whatever data you need to pass along
function callback (event, data) => {
const body = event.content.body
let credential
try {
credential = JSON.parse(body)
} catch (e) {}
if (credential) {
// The proof will be included in the credential
console.log(credential.proof[1])
} else {
// Other messages sent by the daemon (email sent, errors, etc)
console.log(body)
}
}
// your credential to verify
const credential = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1'
],
type: [
'VerifiableCredential',
'EmailCredential'
]
// etc
}
// Instantiate the client object
client = new Client()
For validated Matrix users
// Use an existing Matrix session token for a verified Matrix account
await client.init(matrixServerURL, accessToken, userId)
// Creates a new room, invites the verifier bot, sends credential, specifies callback for results, pass along my own data needed
const { roomId, eventId } = await client.submitCredentialForVerification(botMatrixId, credential, callback, 'myData')
// ... when finished...
// the client leaves the room (and quits getting callbacks)
client.leave(roomId)
// Shut down the client connection to Matrix
await client.close()
For Guest users (who have no existing Matrix account)
// Use an existing Matrix session token for a verified Matrix account
await client.submitCredentialForVerificationAsGuest(config.matrixServerURL, '#lorena-lobby-test:matrix.org', 'verifyEmail!', credential, responseRoomCallback)
Finally...
// the client leaves the room (and quits getting callbacks)
// This can be called from within the responseRoomCallback
client.leave(roomId)
// Shut down the client connection to Matrix
await client.close()