6. Compute signatures with a card reader
Computing signatures is similar to reading data, but instead of using the DataKindHints
the SignatureKindHints
are used.
To compute a signature, follow the example below:
import { Encoding } from 'connective-wrapper';
let cardReader: CardReader;
let cardHandler: CardHandler;
pluginApi.getCardReader(BeID.cardInfo)
.then((cardReadersWithBeID) => {
cardReader = cardReadersWithBeID[0];
cardHandler = pluginApi.getCardHandler(cardReader);
})
.then(() => {
const dataToSign: Uint8Array; // some Uint8Array containing the raw data that needs to be signed
return cardHandler.computeSignature(cardReader, BeID.SignatureKindHints.NonRepudiation, dataToSign);
})
.then((signature: Uint8Array) => {
// the Encoding utils class can be used to encode/decode raw data
console.log(Encoding.encodeAsBase64String(signature));
})
.catch((e: Error) => {
if (e instanceof Exceptions.InvalidPinException) {
// computing signatures will require to user to authenticate via a pin code (usually)
// if this fails an InvalidPinException will be thrown. This exception contains the amount of remaining tries
// and wether or not the card was blocked (no more pin retries available)
} else if (e instanceof Exceptions.OperationCanceledException) {
// if the user cancels the pin input (or waits too long) an OperationCanceledException will be thrown
} else {
// ...
}
})