@universis/signer-worker
v1.6.0
Published
Universis signer worker for server applications
Maintainers
Readme
@universis/signer-worker
Universis signer worker for server applications
Getting started
Install @universis/signer-worker
npm i @universis/signer-workerImportant note: Verify that Universis Signer is already installed as a service. Follow installation instructions to install and configure Universis Signer.
Configuration
Configure Universis api server to use SignerWorker service. Register @universis/signer-worker#SignerWorker under universis api server services section of application configuration:
{
"services": [
{
"serviceType": "@universis/signer-worker#SignerWorker"
}
]
}or configure Universis api server to use SignerService service.
{
"services": [
{
"serviceType": "@universis/signer-worker#SignerService"
}
]
}Sign documents
SignerService.signFile(context: DataContext, file: string, contentType?: string, options?: { timestampServer?: string, position?: string, reason?: string })
SignerService.signFile can be used for signing *.pdf files using a server instance of Universis Signer
For completing sign process, the signer service instance should be configured by adding settings/universis/signerService section at application configuration
{
"settings": {
"universis": {
"signerService": {
"user": "user",
"password": "password",
"host": "http://localhost:2465"
}
}
}
}
where host is the URL of the Universis Signer service, user and password are the credentials for the Universis Signer service.
Normally, the Universis Signer service which is running on http://localhost:2465, uses a PKCS12 store with secret key and certificate for signing.
In this case, the user and password are used to access the PKCS12 store. SignerService service will try to get valid certificates,
and select the first one that is valid for signing. Use the configuration setting thumbnail if you want to explicitly define
the certificate that should be used for signing.
{
"settings": {
"universis": {
"signerService": {
"user": "user",
"password": "password",
"host": "http://localhost:2465",
"thumbnail": "2d49be3b03db5d176482640549d5aaede84c925d"
}
}
}
}Sign data
SignerService.sign(context: DataContext, data: unknown, options?: { timestampServer?: string, reason?: string })
SignerService.sign method can be used for signing data.
The data can be any JSON-serializable object, and the method will return a signed version of the data.
The options parameter can include a timestampServer URL for timestamping the signature, a position string to specify the position of the signature in the document,
and a reason string to specify the reason for signing.
Example
import {SignerService} from '@universis/signer-worker';
function signJson(context: DataContext, data: unknown) {
const signerService = context.getApplication().getService(SignerService);
return signerService.sign(context, data, {
timestampServer: "http://timestamp.server.com",
reason: "Signing example data"
});
}
signJson(context, { message: "Hello, World!" })
.then(signedData => {
console.log("Signed data:", signedData);
})
.catch(error => {
console.error("Error signing data:", error);
});Remote Signer Worker
To use the remote signer worker, you need to configure the Universis API server to use the RemoteSignerWorker service. This service will communicate with the Universis Signer service running on a remote server. Register @universis/signer-worker#RemoteSignerWorker under universis api server services section of application configuration:
{
"services": [
{
"serviceType": "@universis/signer-worker#RemoteSignerWorker"
}
]
}This will allow the Universis API server to use the remote signer worker for signing operations. The remote signer worker will handle the communication with the Universis Signer service and perform the signing operations as needed.
The remote signer service host should be configured in the application settings:
{
"settings": {
"universis": {
"remoteSignerWorker": {
"host": "http://remote-signer-server:8480"
}
}
}
}Where host is the URL of the remote Universis Signer service.
Remote signer worker will expose the same methods under /services/remoteSigner as the local signer worker, allowing you to sign files and data in the same way as described above.
