Thales Web Connect

 

CAP

Compute CAP tokens via PCSC SConnect Wrapper

Once a PCSC instance has been created after a call to the init function, your page is able to trigger an operation on smart card insertion (see the "initialization" and "detection" pages for more details).

The CAP generation function is not exposed by the top level PCSC API. When a smart card is inserted into the reader and validated as usable, a connection instance is automatically created by the PCSC library. The connection instance exposes all functions for CAP operations.

The first step is to get the connection instance. A reference to this instance is passed as an argument to the connection callback provided in the init function. This reference can also be retrieved directly when the function getConnection is called.

The connection instance exposes three CAP functions:

  • cap_mode1 function generates a CAP mode1 token
  • cap_mode2 function generates a CAP mode2 token
  • cap_mode3 function generates a CAP mode3 token

Because the card holder have to validate the transaction parameter used for token generation, each CAP function is asynchronous. The final result is reported to the web page by the callback provided as a CAP function parameter.

function sendCommandCAP() {
    // You can get these values from the user in the webpage, for example...
    const capMode = "1";
    const sUnpredictableNumber = document.getElementById("idUnpredictableNumber").value;
    const sAmount = document.getElementById("idAmount").value;
    const sCurrency = document.getElementById("idCurrency").value;
    const sPassCode = document.getElementById("idPassCode").value;
    const aTdsData = ["12345", "123"];

    switch (md) {
        case "1":
            cap_mode1(resultCallback, sUnpredictableNumber, sAmount, sCurrency, sPassCode);
            break;
        case "2":
            cap_mode2(resultCallback, aTdsData, sPassCode);
            break;
        case "3":
            cap_mode3(resultCallback, sUnpredictableNumber, aTdsData, sPassCode);
            break;
    }
}

// Callback to handle the return value from the CAP function
var resultCallback = {
    success: function (a_sToken, a_sUmpredictableNumber) {
        // Reset the token display on the HTML page
        let sMessage = "Your token " + a_sToken + " has been successfully generated";

        // From specific PCR ar Ezio InBranch the cardholder can specify
        // the umpredictable number directly from the PCR (you only to send
        // the CAP Mode3 command with a 'FFFFFFFF' template as umpredictable number).
        // In this case, the 'success' function must manage a new and last parameter to
        // get the value typed by the cardholder
        if (a_sUmpredictableNumber) {
            sMessage += "
The card holder has specified " + a_sUmpredictableNumber + " as umpredictable number"; } console.log('CAP success - ' + sMessage); }, failure: function (a_oError) { const sMessage = `Your token has NOT been generated : [${a_oError.errorCode}] ${a_oError.message}` console.log('CAP failure - ' + sMessage); } };

Try it!

Enter the required data to generate your CAP token, and click the button to send the CAP command.