Edit in JSFiddle

// ------------------------------------------------------------------------------------------
// LacunaWebPKI: first example

var pki = new LacunaWebPKI('ASYAanNmaWRkbGUubmV0LHdlYnBraS5sYWN1bmFzb2Z0d2FyZS5jb20AAAABClKvO1J22vAD+YmfANiKQLbcLE1lNraPKCel6tRM+ZxR+h6M/crtJYRRVGGz7hrdbM0Y0mfTu15RMYGqQMi1QNZS6GrT4vNzIayv552Fl0EFWQA7jWlctUwfYoHRHVEnCNx9YGXDiA9+yDoGlVwgTR7fjzNeS3Fen1MVIyKBF464gN0JvdiCRJMI47JGVDkPmKjcrYIvJs6y5Lg25RW4ZnBKVruS+HR2s3k8ZrV4y4RCQE4UYMKbukF9vsF+JqAEifRlPq2xLcrNdxBveVDSXS/LRHAcrZrMM+Iw4A79jl0ngWPcy+CwinAhT+3dxVo5ZWMRQFpmTkylEMDvTjV9wQ==');

function start() {
    log('Initializing component ...');
    pki.init(onWebPkiReady);
}

function onWebPkiReady () {
    log('Component ready, listing certificates ...');
    pki.listCertificates().success(function (certs) {
        log(certs.length + ' certificates found.');
        var select = $('#certificateSelect');
        $.each(certs, function() {
            select.append(
                $('<option />')
                .val(this.thumbprint)
                .text(this.subjectName + ' (issued by ' + this.issuerName + ')')
            );
        });
    });
}

function readCert() {
    var selectedCertThumb = $('#certificateSelect').val();
    log('Reading certificate: ' + selectedCertThumb);
    pki.readCertificate(selectedCertThumb).success(function (certEncoding) {
        log('Result: ' + certEncoding);
    });
}

function signData() {
    var selectedCertThumb = $('#certificateSelect').val();
    log('Signing data with certificate: ' + selectedCertThumb);
    pki.signData({
        thumbprint: selectedCertThumb,
        data: 'SGVsbG8sIFdvcmxkIQ==', // ASCII encoding of the string "Hello, World!", encoded in Base64
        digestAlgorithm: 'SHA-256'
    }).success(function (signature) {
        log('Result: ' + signature);
    });
}

function signHash() {
    var selectedCertThumb = $('#certificateSelect').val();
    log('Signing hash with certificate: ' + selectedCertThumb);
    pki.signHash({
        thumbprint: selectedCertThumb,
        hash: '3/1gIbsr1bCvZ2KQgJ7DpTGR3YHH9wpLKGiKNiGCmG8=', // Base64 encoding of the SHA-256 digest of the ASCII encoding of the string "Hello, World!"
        digestAlgorithm: 'SHA-256'
    }).success(function (signature) {
        log('Result: ' + signature);
    });
}

function log(message) {
    $('#logPanel').append('<p>' + message + '</p>');
    if (window.console) {
        window.console.log(message);
    }    
}

$(function() {
    $('#readCertButton').click(readCert);
    $('#signDataButton').click(signData);
    $('#signHashButton').click(signHash);
    start();
});
<select id="certificateSelect"></select><br><br>
<button id="readCertButton" type="button">Read Cert</button>
<button id="signDataButton" type="button">Sign Data</button>
<button id="signHashButton" type="button">Sign Hash</button>
<div id="logPanel"></div>

              

External resources loaded into this fiddle: