JavaScript API
Introduction
The Signature SDK for JavaScript is built on WebAssembly, a binary instruction format supported by all major modern web browsers (see https://caniuse.com/wasm).
It is installed from Cloudsmith as the @wacom/signature-sdk npm package.
The package contains the following files:
| Path | Description |
|---|---|
signature-sdk.js | ES module wrapper. This is the package's default entry point. |
signature-sdk.wasm | The SDK, compiled to WebAssembly. It is loaded by the wrapper. |
signature-sdk.d.ts | TypeScript type definitions. |
dist/ | CommonJS (signature-sdk.cjs) and UMD (signature-sdk.umd.cjs) bundles. |
Due to WebAssembly security restrictions, the SDK must be served from a web server and cannot be opened directly from the local file system.
WebHID, which is required for STU tablets, also needs a secure context: use localhost during development, and https for any other URL.
Loading the SDK
Only the JavaScript wrapper needs to be imported. Calling the default export loads the WebAssembly module and returns the SDK module:
import SigSDK from "@wacom/signature-sdk";
const sigSDK = await SigSDK();
The .wasm file must be served alongside your application.
For example, the sample demos use vite-plugin-static-copy to copy it into the build output.
All classes and enumerations are available on the SDK module, for example sigSDK.SigObj, sigSDK.Hash and sigSDK.KeyType.
The SDK version is available as sigSDK.VERSION.
Licensing
The Signature SDK for JavaScript requires a valid licence. You can obtain an evaluation or commercial licence from the Developer Dashboard.
The licence is transaction-based and has two components: a key and a secret. First, create a signature object. Then, set the licence with setLicence:
const sigObj = new sigSDK.SigObj();
try {
if (await sigObj.setLicence(key, secret)) {
console.log("Licence set");
} else {
console.log("Invalid licence");
}
} catch (e) {
console.log("Licence error " + e);
}
Calling setLicence from the browser exposes the key and secret publicly.
To keep them private, host a licence proxy on your server and call setLicenceProxy instead.
For on premise licensing, see On premise licensing.
With the signature object configured, you can use the following methods.
Methods summary
| Method | Description |
|---|---|
| canDecrypt | Checks whether a decryption password or private key is set. |
| canEncrypt | Checks whether an encryption password or public key is set. |
| checkIntegrity | Checks whether the signature has been tampered with. |
| checkSignedData | Checks a document hash against the one bound at capture. |
| exportIso | Exports the signature in an ISO format. |
| generateSignature | Generates a signature from captured strokes. |
| getAdditionalData | Returns additional data collected at capture. |
| getExtraData | Returns extra data stored in the signature. |
| getHeight | Returns the signature height. |
| getLicence | Returns the name of the licence used for capture. |
| getSigData | Returns the signature data as bytes. |
| getTextData | Returns the signature data as text. |
| getWhen | Returns the capture date. |
| getWho | Returns the signatory's name. |
| getWhy | Returns the reason for signing. |
| getWidth | Returns the signature width. |
| importIso | Imports a signature in an ISO format. |
| isCaptured | Checks whether the object contains a signature. |
| isCrossedOut | Checks whether the signature is crossed out. |
| isEncrypted | Checks whether the signature is encrypted. |
| isEvaluation | Checks whether the licence is an evaluation licence. |
| isExternal | Checks whether the signature was generated externally. |
| readEncodedBitmapBinary | Reads signature data encoded in an image. |
| renderBitmap | Renders an image of the signature. |
| setEncryptionPassword | Sets a password for symmetric encryption. |
| setExtraData | Stores extra data in the signature. |
| setLicence | Sets the licence. |
| setLicenceEndPoint | Sets the on premise licence server. |
| setLicenceProxy | Gets the licence through a proxy. |
| setPrivateKey | Sets a private key for decryption. |
| setPublicKey | Sets a public key for encryption. |
| setSigData | Loads signature data from bytes. |
| setTextData | Loads signature data from text. |
SigObj
The SigObj encapsulates a captured handwritten signature.
When populated, it contains data that fully describes both the static and dynamic characteristics of a signature, and the context in which it was captured.
A signature object can be bound to the host document, or another data set, at the moment of capture.
This makes it possible to determine whether any changes have been made since, either maliciously or unintentionally.
Hash
The Hash object binds a signature to a document, for example a PDF that is being signed.
First, create a hash object:
const hash = new sigSDK.Hash(hashType);
hashType is one of the following values:
sigSDK.HashType.NonesigSDK.HashType.MD5sigSDK.HashType.SHA1sigSDK.HashType.SHA224sigSDK.HashType.SHA256sigSDK.HashType.SHA384sigSDK.HashType.SHA512
Then, add the content of the document with add:
await hash.add(pdfContent);
AdditionalImportIsoData
The AdditionalImportIsoData object adds properties that the ISO format does not store when a signature is imported with importIso.
It has the following methods:
setWho(who)
Sets the name of the signatory. who is a string.
setWhy(why)
Sets the reason for signing. why is a string.
setWhen(when)
Sets the date when the signature was captured. when is a JavaScript Date object.
putExtraData(key, value)
Adds extra data. key is a string with the name of the extra data, and value is a string with its value.
Further components
The SDK module also includes components for capturing signatures:
- Wizard control - Interactive screens on STU signature pads. See the JavaScript Wizard API.
- SigCaptDialog and StuCaptDialog - Signature capture dialogs for pointer devices and STU pads.
- STUDevice - Access to STU pads through WebHID.