MobbSign Cordova: Signing Documents
Document Signing
As seen in the previous section, a document sign process can be performed after the SDK has been initialized. It can be executed as shown in this example:
const license = "<YOUR LICENSE>";
const b64EncodedFile;
// Here go your read file and encode code...
const onStartSuccess = () => {
MobbSignAPI.setSignDocumentInterface(signDocumentInterfaceName, console.log, console.error)
MobbSignAPI.signDocument(b64EncodedFile, console.log, console.error);
};
MobbSignAPI.initMobbSignWithLicense(license, onStartSuccess, console.error);
NOTE: You must call
signDocument
with a base 64 encoded file.
Let's analyze the workflow:
First of all,
MobbScanAPI.setSignDocumentInterface
should be called to decide which interface use to sign document, by default we have the example exposed in Customize UI. If everything goes well, this method will send you an OK message.After that, if you want, you can set listeners for MobbSign events like
OnDocumentShown
,OnSignatureAcquired
,OnSignatureDeleted
,OnBackButtonPressed
,OnSignButtonPressed
,OnProcessEnd
orOnErrorOccurred
. These functions will be called when the specific event is launched.Finally, you can call
signDocument
with the base 64 encoded file. In this moment, you will see the interface appears. After that events can be sent.
NOTE: You must put
mobbsign.key
file with you key in the assets folder of the platform, in case you are developing for Android, or in Resources folder, in case you are developing for iOS. This can be changed if you modify the default signing interface or if you put your own interface, which has been built following the steps specified in Customize UI.
The methods that set the listeners will be discussed from here.
setOnDocumentShownListener
This method sets a function that will be called when the document passed in signDocument
method is shown.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnDocumentShown
event. That method will receive an object with a boolean callededitable
.failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnDocumentSignedListener
This method sets a function that will be called when the document is signed.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnDocumentSigned
event. That method will receive an object with:document
: The document in a base64 format.encryptedSignatureData
: The signature in a base64 format.signatureBitmap
: The encrypted signature in a base64 format.signaturePage
: The page of the signature.signatureCoord
: The coords of the signature in an object.
failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnSignatureAcquiredListener
This method sets a function that will be called when a signature is acquired.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnSignatureAcquired
event.failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnSignatureDeletedListener
This method sets a function that will be called when a signature is deleted.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnSignatureDeleted
event.failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnBackButtonPressedListener
This method sets a function that will be called when the back button is pressed.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnBackButtonPressed
event.failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnSignButtonPressedListener
This method sets a function that will be called when the sign button is pressed.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnSignButtonPressed
event.failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnProcessEndListener
This method sets a function that will be called when the signing process ends.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnProcessEnd
event.failureCallback
: A function that will be executed if some error takes place during this method execution.
setOnErrorOccurredListener
This method sets a function that will be called when an error occurred in the signing process.
This method has the following arguments:
successCallback
: A function that will be executed when MobbSign receive theOnErrorOccurred
event.failureCallback
: A function that will be executed if some error takes place during this method execution.
Sign with electronic certificate
From the version v3.5.0
the MobbSign plugin allows the developers to sign the document with the with the new biometric signature sealed online.
If you need to use it, you must follow these steps:
Configure the server
WARNING! This method must be called everytime that you are going to perform a new signature.
The first thing you have to do, is configure the server that you are going to use for the online signature. For this porpuse, you have to invoke the method configureSignatureServer
as you see below:
var SIGNATURE_SERVER_HOST = "URL_OF_THE_SIGNATURE_SERVER";
var SIGNATURE_SERVER_AUTHORIZATION = "YOUR_AUTHORIZATION_TOKEN";
var SIGNATURE_SERVER_CLIENT_ID = "YOUR_USER_IDENTIFIER";
var SIGNATURE_SERVER_USER_TOKEN = "YOUR_SIGNATURE_TOKEN";
MobbSignAPI.configureSignatureServer(SIGNATURE_SERVER_HOST, SIGNATURE_SERVER_AUTHORIZATION, SIGNATURE_SERVER_CLIENT_ID, SIGNATURE_SERVER_USER_TOKEN, success, failure);
The parameters that you are going to need are those:
Note: These are configuration parameters specific for each client, and we will provide to you. In the case that you don't have any of them, please let us know.
- SIGNATURE_SERVER_HOST is the server url where the signature will be sign with the certificate.
- SIGNATURE_SERVER_AUTHORIZATION is a token that you need to set in order to ensure that you are allowed to perform an online signature. This adds a security layer over the proccess.
- SIGNATURE_SERVER_CLIENT_ID is a token that identify you as a client of
MobbSign
. - SIGNATURE_SERVER_USER_TOKEN is a token that will be used for some specific processes. It depends of the integration, it can be filled or not. If you don't need it, pleas fill it with a "";
Configure the signature
WARNING! This method must be called everytime that you are going to perform a new signature.
Once you have configurated the server, you need to configure the signature so the MobbSign SDK performs an online signature instead of an offline one. For it, first you need to create an instance of SignatureConfiguration
, as you can see here:
var sConfiguration = new SignatureConfiguration();
sConfiguration.signatureType = "BIOMETRIC_WITH_CERTIFICATE";
sConfiguration.timestampToSignature = true;
The parameters of this object are those:
- timestampToSignature indicates if you want to add a timestamp to your online signature. The default value es
false
. - timestampToSignature indicates if you want to add a timestamp to you online signature. The default value es
false
.
Once you have created the signatue configuration object, you can call to the configureNextSignature
method:
var sConfiguration = new SignatureConfiguration();
sConfiguration.signatureType = "BIOMETRIC_WITH_CERTIFICATE";
sConfiguration.timestampToSignature = true;
MobbSignAPI.configureNextSignature(sConfiguration, success, failure);
Loading a stored document
If the online signature fails for some reason, either a connection error or a server problem, the document will be stored in a database on the application. You can load it and try to sign it again, or add more signatures if you want to.
When an error happens, the listener onErrorOcurred
will be invoked, providing you the internalDocumentId
. This value is an identifier of the document that you tried to sign, and that you will need for loading.
For loading a stored document, you need to invoke this method, providing the internalDocumentId
:
MobbSignAPI.loadPDFDocumentInternallyStored("THE_DOCUMENT_ID", success, failure);
After this, the signature interface will be loaded with the stored document in the same conditions that it will stored, and with all the signatures, ready to be online signed.