Skip to main content

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:

PathDescription
signature-sdk.jsES module wrapper. This is the package's default entry point.
signature-sdk.wasmThe SDK, compiled to WebAssembly. It is loaded by the wrapper.
signature-sdk.d.tsTypeScript 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​

MethodDescription
canDecryptChecks whether a decryption password or private key is set.
canEncryptChecks whether an encryption password or public key is set.
checkIntegrityChecks whether the signature has been tampered with.
checkSignedDataChecks a document hash against the one bound at capture.
exportIsoExports the signature in an ISO format.
generateSignatureGenerates a signature from captured strokes.
getAdditionalDataReturns additional data collected at capture.
getExtraDataReturns extra data stored in the signature.
getHeightReturns the signature height.
getLicenceReturns the name of the licence used for capture.
getSigDataReturns the signature data as bytes.
getTextDataReturns the signature data as text.
getWhenReturns the capture date.
getWhoReturns the signatory's name.
getWhyReturns the reason for signing.
getWidthReturns the signature width.
importIsoImports a signature in an ISO format.
isCapturedChecks whether the object contains a signature.
isCrossedOutChecks whether the signature is crossed out.
isEncryptedChecks whether the signature is encrypted.
isEvaluationChecks whether the licence is an evaluation licence.
isExternalChecks whether the signature was generated externally.
readEncodedBitmapBinaryReads signature data encoded in an image.
renderBitmapRenders an image of the signature.
setEncryptionPasswordSets a password for symmetric encryption.
setExtraDataStores extra data in the signature.
setLicenceSets the licence.
setLicenceEndPointSets the on premise licence server.
setLicenceProxyGets the licence through a proxy.
setPrivateKeySets a private key for decryption.
setPublicKeySets a public key for encryption.
setSigDataLoads signature data from bytes.
setTextDataLoads 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.None
  • sigSDK.HashType.MD5
  • sigSDK.HashType.SHA1
  • sigSDK.HashType.SHA224
  • sigSDK.HashType.SHA256
  • sigSDK.HashType.SHA384
  • sigSDK.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.