Skip to main content

JavaScript API

Introduction

The Signature SDK for JavaScript is based on WebAssembly, a binary instruction format supported by most of the major modern web browsers (see https://caniuse.com/wasm for more information about compatibility) and is distributed as two files:

  1. signature_sdk.wasm – This is the SDK itself.
  2. signature_sdk.js – This is the JavaScript wrapper.

Using the SDK via the website must be done on a web server due to security restrictions. It cannot be used directly from the local file system. Additionally, the connection must be secure (https) when using another URL other than localhost.

Firstly, the JavaScript needs to be imported from signature_sdk.wasm.

<script src="{path to the sdk}/signature_sdk.js"></script> <!-- signature SDK -->

Once the Signature SDK is imported, it is recommended to wait until the WebAssembly module is loaded:

Module.onRuntimeInitialized = function() {

    // put your code here

}

Once the module is loaded, you can create the signature object:

const sigObj = new Module.SigObj();

The Signature SDK for JavaScript requires a valid license. You may obtain either an evaluation license or commercial license at: https://developer.wacom.com/en-us/developer-dashboard/license-keys

Once you have a valid license, you can initialize the Signature SDK for JavaScript with the following code:

try {  

    if (await sigObj.setLicence("licence string"))  {

          console.log("Licence setted fine");

    } else {

          console.log("Invalid licence");

    }

} catch (e) {

    console.log("Licence error "+e.name);

}      

With the signature object properly configured, you can use the following methods.

Methods summary

Methods
canDecrypt
canEncrypt
checkIntegrity
checkSignedData
exportIso
generateSignature
getAdditionalData
getExtraData
getHeight
getLicence
getSigData
getTextData
getWhen
getWidth
getWho
getWhy
importIso
isCaptured
isCrossedOut
isEncrypted
isExternal
isEvaluation
ReadEncodedBitmapBinary
RenderBitmap
setExtraData
setEncryptionPassword
setLicence
setSigData
setTextData
setPrivateKey
setPublicKey

SigObj

The SigObj encapsulates a captured handwritten signature. When populated, it contains a wealth of data that fully describes both the static and dynamic characteristic of a signature and the context in which the signature was captured. A Signature object can be bound (at the moment of capture) to the host document or another data set to provide a means of determining whether or not any changes have been made subsequently, either maliciously or unintentionally.

Hash

The hash object is used to bind a signature to a document. For example: it is necessary to sign a PDF. To do this, we create a hash document using:

const hash = new Module.Hash(hashType);

where the hashType can be any of the following:

  • Module.HashType.None
  • Module.HashType.MD5
  • Module.HashType.SHA1
  • Module.HashType.SHA224
  • Module.HashType.SHA256
  • Module.HashType.SHA384
  • Module.HashType.SHA512

Then using the function add(byteArray) we add the content of the PDF.

hash.add(pdfContent);

AdditionalImportIsoData

This object is used to apport extra properties to the ISO format. These options are:

setWho(who)

Set the name of the person who signed, where the who parameter is a string.

setWhy(why)

Set the reason to sign, where the why parameter is a string.

setWhen(when)

Set the date when the signature was captured, where the when parameter is a JavaScript Date object.

putExtraData(key, value)

Put in additional data, where key is a string with the name of the extra data, and value is another string with its value.