This project implements a BullJs worker for signing verifiable credentials (VCs) in a background job processing environment.
Install the required dependencies:
npm install https://github.com/RadicalLedger/zedeid-ss-bulk-signer
or
yarn add https://github.com/RadicalLedger/zedeid-ss-bulk-signer
Make sure you have a Redis server running, as BullJs requires Redis for job queueing and processing. You can download and install Redis from here or use a cloud service like Redis Labs.
By creating an instance of the Queue class with the specified queueName and connection options, you are initializing a BullJs queue that can be used for processing tasks asynchronously.
import { Queue } from 'zedeid-ss-bulk-signer';
const config = {
// ... other configurations
redisConnection: {
host: 'localhost',
port: 6379
},
queueName: 'vc-signing-queue' // Name for your queue
};
const queue = new Queue(config.queueName, {
connection: config.redisConnection
});
const jobData = {
id: 123 // Unique identifier for the VC signing job
// Other data relevant to VC signing
};
await queue.add('sign-vc', jobData);
This worker class handles the signing of verifiable credentials using BullJs for job processing.
name
: The name of the queue.vcOptions
: The options for signing verifiable credentials. See below for details.workerOptions
: The options for the BullJs worker.
issuerPrivateKeyLoader
: The private key of the issuer for signing the verifiable credential.issuanceDate
: (Optional) The issuance date of the verifiable credential. Defaults to the current date and time.suite
: The suite used for signing the verifiable credential.vcLoader
: The function used for loading the verifiable credentials.documentLoader
: The document loader function for loading JSON-LD documents.callback
: The callback function to handle the result of signing the verifiable credential.
This method handles the processing of a job by signing the verifiable credentials.
Parameters:
job
: The job to be processed.
Returns:
- A promise that resolves when the handler is done.
This method returns the BullMq worker instance.
Returns:
- The BullMq worker instance.
This method closes the worker and returns a promise that resolves when the worker is closed.
Returns:
- A promise that resolves when the worker is closed.
import { Worker } from 'zedeid-ss-bulk-signer';
// Define the options for signing verifiable credentials
const vcOptions = {
issuerPrivateKeyLoader: async (job) => { ... }, // Issuer's private key
suite: '...', // Cryptographic suite
loader: async (job) => { ... }, // Function to load VC for signing
documentLoader: async (uri) => { ... }, // Function to load referenced documents
callback: async (err, data) => { ... }, // Callback for signed VCs or errors
};
// Define the options for the worker
const workerOptions = {
connection: {
host: '...' // Redis connection host
port: '...' // Redis connection port
}
}
// Create a new instance of the Worker class
const worker = new Worker('workerName', vcOptions, workerOptions);
// The worker will start processing jobs immediately
This project uses BullJS, a Redis-backed queue library for Node.js, to handle job queueing and processing. For more information on BullJS, visit the official documentation.