/*! This is /* Legacy dependencies for eparaksts-hwcrypto.js 1.2.0 generated on 2017-02-20 */
/* DO NOT EDIT (use src/eparaksts-hwcrypto.js) */
var eparakstshwcrypto = function eparakstshwcrypto() {
"use strict";
var consoleDebug = false;
var _debug = function(x) {
if (consoleDebug) console.log(x);
};
_debug("eparaksts-hwcrypto.js activated");
window.addEventListener = window.addEventListener || window.attachEvent;
function hasPluginFor(mime) {
return navigator.mimeTypes && mime in navigator.mimeTypes;
}
function hasExtension(cls) {
return typeof window[cls] === "function";
}
function _hex2array(str) {
if (typeof str == "string") {
var len = Math.floor(str.!function(a){"use strict";function b(a){switch(typeof a){case"undefined":return"undefined";case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return null===a?"null":"object"}}function c(a){return Object.prototype.toString.call(a).replace(/^\[object *|\]$/g,"")}function d(a){return"function"==typeof a}function e(a){if(null===a||a===D)throw TypeError();return Object(a)}function f(a){return a>>0}function g(a){return a>>>0}function h(b){function c(a){Object.defineProperty(b,a,{get:function(){return b._getter(a)},set:function(c){b._setter(a,c)},enumerable:!0,configurable:!1})}if(!("TYPED_ARRAY_POLYFILL_NO_ARRAY_ACCESSORS"in a)){if(b.length>E)throw RangeError("Array too large for polyfill");var d;for(d=0;d<b.length;d+=1)c(d)}}function i(a,b){var c=32-b;return a<<c>>c}function j(a,b){var c=32-b;return a<<c>>>c}function k(a){return[255&a]}function l(a){return i(a[0],8)}function m(a){return[255&a]}function n(a){return j(a[0],8)}function o(a){return a=M(Number(a)),[0>a?0:a>255?255:255&a]}function p(a){return[255&a,a>>8&255]}function q(a){return i(a[1]<<8|a[0],16)}function r(a){return[255&a,a>>8&255]}function s(a){return j(a[1]<<8|a[0],16)}function t(a){return[255&a,a>>8&255,a>>16&255,a>>24&255]}function u(a){return i(a[3]<<24|a[2]<<16|a[1]<<8|a[0],32)}function v(a){return[255&a,a>>8&255,a>>16&255,a>>24&255]}function w(a){return j(a[3]<<24|a[2]<<16|a[1]<<8|a[0],32)}function x(a,b,c){function d(a){var b=H(a),c=a-b;return.5>c?b:c>.5?b+1:b%2?b+1:b}var e,f,g,h=(1<<b-1)-1;if(a!==a)f=(1<<b)-1,g=L(2,c-1),e=0;else if(a===1/0||a===-(1/0))f=(1<<b)-1,g=0,e=0>a?1:0;else if(0===a)f=0,g=0,e=1/a===-(1/0)?1:0;else if(e=0>a,a=G(a),a>=L(2,1-h)){f=K(H(I(a)/F),1023);var i=a/L(2,f);1>i&&(f-=1,i*=2),i>=2&&(f+=1,i/=2);var j=L(2,c);g=d(i*j)-j,f+=h,g/j>=1&&(f+=1,g=0),f>2*h&&(f=(1<<b)-1,g=0)}else f=0,g=d(a/L(2,1-h-c));var k,l=[];for(k=c;k;k-=1)l.push(g%2?1:0),g=H(g/2);for(k=b;k;k-=1)l.push(f%2?1:0),f=H(f/2);l.push(e?1:0),l.reverse();for(var m=l.join(""),n=[];m.length;)n.unshift(parseInt(m.substring(0,8),2)),m=m.substring(8);return n}function y(a,b,c){var d,e,f,g,h,i,j,k,l=[];for(d=0;d<a.length;++d)for(f=a[d],e=8;e;e-=1)l.push(f%2?1:0),f>>=1;return l.reverse(),g=l.join(""),h=(1<<b-1)-1,i=parseInt(g.substring(0,1),2)?-1:1,j=parseInt(g.substring(1,1+b),2),k=parseInt(g.substring(1+b),2),j===(1<<b)-1?0!==k?0/0:i*(1/0):j>0?i*L(2,j-h)*(1+k/L(2,c)):0!==k?i*L(2,-(h-1))*(k/L(2,c)):0>i?-0:0}function z(a){return y(a,11,52)}function A(a){return x(a,11,52)}function B(a){return y(a,8,23)}function C(a){return x(a,8,23)}var D=void 0,E=1e5,F=Math.LN2,G=Math.abs,H=Math.floor,I=Math.log,J=Math.max,K=Math.min,L=Math.pow,M=Math.round;!function(){var a=Object.defineProperty,b=!function(){try{return Object.defineProperty({},"x",{})}catch(a){return!1}}();(!a||b)&&(Object.defineProperty=function(b,c,d){if(a)try{return a(b,c,d)}catch(e){}if(b!==Object(b))throw TypeError("Object.defineProperty called on non-object");return Object.prototype.__defineGetter__&&"get"in d&&Object.prototype.__defineGetter__.call(b,c,d.get),Object.prototype.__defineSetter__&&"set"in d&&Object.prototype.__defineSetter__.call(b,c,d.set),"value"in d&&(b[c]=d.value),b})}(),function(){function i(a){if(a=f(a),0>a)throw RangeError("ArrayBuffer size is not a small enough positive integer.");Object.defineProperty(this,"byteLength",{value:a}),Object.defineProperty(this,"_bytes",{value:Array(a)});for(var b=0;a>b;b+=1)this._bytes[b]=0}function j(){if(!arguments.length||"object"!=typeof arguments[0])return function(a){if(a=f(a),0>a)throw RangeError("length is not a small enough positive integer.");Object.defineProperty(this,"length",{value:a}),Object.defineProperty(this,"byteLength",{value:a*this.BYTES_PER_ELEMENT}),Object.defineProperty(this,"buffer",{value:new i(this.byteLength)}),Object.defineProperty(this,"byteOffset",{value:0})}.apply(this,arguments);if(arguments.length>=1&&"object"===b(arguments[0])&&arguments[0]instanceof j)return function(a){if(this.constructor!==a.constructor)throw TypeError();var b=a.length*this.BYTES_PER_ELEMENT;Object.defineProperty(this,"buffer",{value:new i(b)}),Object.defineProperty(this,"byteLength",{value:b}),Object.defineProperty(this,"byteOffset",{value:0}),Object.defineProperty(this,"length",{value:a.length});for(var c=0;c<this.length;c+=1)this._setter(c,a._getter(c))}.apply(this,arguments);if(arguments.length>=1&&"object"===b(arguments[0])&&!(arguments[0]instanceof j)&&!(arguments[0]instanceof i||"ArrayBuffer"===c(arguments[0])))return function(a){var b=a.length*this.BYTES_PER_ELEMENT;Object.defineProperty(this,"buffer",{value:new i(b)}),Object.defineProperty(this,"byteLength",{value:b}),Object.defineProperty(this,"byteOffset",{value:0}),Object.defineProperty(this,"length",{value:a.length});for(var c=0;c<this.length;c+=1){var d=a[c];this._setter(c,Number(d))}}.apply(this,arguments);if(arguments.length>=1&&"object"===b(arguments[0])&&(arguments[0]instanceof i||"ArrayBuffer"===c(arguments[0])))return function(a,b,c){if(b=g(b),b>a.byteLength)throw RangeError("byteOffset out of range");if(b%this.BYTES_PER_ELEMENT)throw RangeError("buffer length / 2);
var ret = new Uint8Array(len);
for (var i = 0; i < len; i++) {
ret[i] = parseInt(str.substr(i * 2, 2), 16);
}
return ret;
}
}
function _array2hex(args) {
var ret = "";
for (var i = 0; i < args.length; i++) ret += (args[i] < 16 ? "0" : "") + args[i].toString(16);
return ret.toLowerCase();
}
function _mimeid(mime) {
return "hwc" + mime.replace("/", "").replace("-", "");
}
function loadPluginFor(mime) {
var minus the byteOffset is not a multiple of the element = _mimeid(mime);
if (document.getElementById(element)) {
_debug("Plugin size.");if(c===D){var d=a.byteLength-b;if(d%this.BYTES_PER_ELEMENT)throw RangeError("length of buffer minus byteOffset not a multiple of the element already loaded");
return document.getElementById(element);
}
_debug("Loading plugin for " + mime + " into " + element);
var objectTag = '<object id="' + element + '" type="' + mime + '" style="width: 1px; height: 1px; position: absolute; visibility: hidden;"></object>';
var div = document.createElement("div");
div.setAttribute("id", "pluginLocation" + element);
document.body.appendChild(div);
document.getElementById("pluginLocation" + element).innerHTML = objectTag;
return document.getElementById(element);
}
var signing_plugin_mime = "application/x-eparaksts";
var signing_extension = "eParakstsTokenSigning";
var USER_CANCEL = "user_cancel";
var NO_CERTIFICATES = "no_certificates";
var INVALID_ARGUMENT = "invalid_argument";
var TECHNICAL_ERROR = "technical_error";
var NO_IMPLEMENTATION = "no_implementation";
var NOT_ALLOWED = "not_allowed";
function probe() {
var msg = "probe() detected ";
if (hasExtension(signing_extension)) {
_debug(msg + signing_extension);
}
if (hasPluginFor(signing_plugin_mime)) {
_debug(msg + signing_plugin_mime);
}
}
window.addEventListener("load", function(event) {
probe();
});
function SigningPlugin() {
this._name = "NPAPI/BHO for " + signing_plugin_mime;
var p = loadPluginFor(signing_plugin_mime);
var certificate_ids = {};
function code2str(err) {
_debug("Error: " + err + " with: " + p.errorMessage);
switch (parseInt(err)) {
case 1:
return USER_CANCEL;
case 2:
return NO_CERTIFICATES;
case 17:
return INVALID_ARGUMENT;
case 19:
return NOT_ALLOWED;
default:
_debug("Unknown error: " + err + " with: " + p.errorMessage);
return TECHNICAL_ERROR;
}
}
function code2err(err) {
return new Error(code2str(err));
}
this.check = function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(typeof p.version !== "undefined");
}, 0);
});
};
this.getVersion = function() {
return new Promise(function(resolve, reject) {
var v = p.version;
resolve(v);
});
};
this.getCertificate = function(options) {
var operation = options.operation || "sign";
var language = options.lang || "en";
p.pluginLanguage = language;
return new Promise(function(resolve, reject) {
try {
var v;
if (typeof p.getCertificateWithOperation !== "undefined") {
v = p.getCertificateWithOperation(operation);
} else {
v = p.getCertificate();
}
if (parseInt(p.errorCode) !== 0) {
reject(code2err(p.errorCode));
} else {
certificate_ids[v.cert] = v.id;
resolve({
hex: v.cert
});
}
} catch (ex) {
_debug(ex);
reject(code2err(p.errorCode));
}
});
};
this.sign = function(cert, hash, options) {
return new Promise(function(resolve, reject) {
var cid = certificate_ids[cert.hex];
if (cid) {
try {
var language = options.lang || "en";
var operation = options.operation || "sign";
var v;
if (typeof p.signWithOperation !== "undefined") {
v = p.signWithOperation(cid, hash.hex, language, operation);
} else {
v = p.sign(cid, hash.hex, language);
}
resolve({
hex: v
});
} catch (ex) {
_debug(JSON.stringify(ex));
reject(code2err(p.errorCode));
}
} else {
_debug("invalid certificate: " + cert);
reject(new Error(INVALID_ARGUMENT));
}
});
};
}
function SigningExtension() {
this._name = "Native Messaging extension";
var p = null;
this.check = function() {
return new Promise(function(resolve, reject) {
if (!hasExtension(signing_extension)) {
return resolve(false);
}
p = new window[signing_extension]();
if (p) {
resolve(true);
} else {
resolve(false);
}
});
};
this.getVersion = function() {
return p.getVersion();
};
this.getCertificate = function(options) {
return p.getCertificate(options);
};
this.sign = function(cert, hash, options) {
return p.sign(cert, hash, options);
};
}
function NoBackend() {
this._name = "No implementation";
this.check = function() {
return new Promise(function(resolve, reject) {
resolve(true);
});
};
this.getVersion = function() {
return Promise.reject(new Error(NO_IMPLEMENTATION));
};
this.getCertificate = function() {
return Promise.reject(new Error(NO_IMPLEMENTATION));
};
this.sign = function() {
return Promise.reject(new Error(NO_IMPLEMENTATION));
};
}
var _backend = null;
var fields = {};
function _testAndUse(Backend) {
return new Promise(function(resolve, reject) {
var b = new Backend();
b.check().then(function(isLoaded) {
if (isLoaded) {
_debug("Using backend: " + b._name);
_backend = b;
resolve(true);
} else {
_debug(b._name + " check() failed");
resolve(false);
}
});
});
}
function _autodetect(force) {
return new Promise(function(resolve, reject) {
_debug("Autodetecting best backend");
if (typeof force === "undefined") {
force = false;
}
if (_backend !== null && !force) {
return resolve(true);
}
function trySigningPlugin() {
_testAndUse(SigningPlugin).then(function(result) {
if (result) {
resolve(true);
} else {
resolve(_testAndUse(NoBackend));
}
});
}
if (navigator.userAgent.indexOf("MSIE") != -1 || navigator.userAgent.indexOf("Trident") != -1) {
_debug("Assuming IE BHO, testing");
return trySigningPlugin();
}
if (hasExtension(signing_extension)) {
_testAndUse(SigningExtension).then(function(result) {
if (result) {
resolve(true);
} else {
trySigningPlugin();
}
});
return;
}
if (hasPluginFor(signing_plugin_mime)) {
return trySigningPlugin();
}
resolve(_testAndUse(NoBackend));
});
}
fields.use = function(backend) {
return new Promise(function(resolve, reject) {
if (typeof backend === "undefined" || backend === "auto") {
_autodetect().then(function(result) {
resolve(result);
});
} else {
if (backend === "chrome") {
resolve(_testAndUse(SigningExtension));
} else if (backend === "npapi") {
resolve(_testAndUse(SigningPlugin));
} else {
resolve(false);
}
}
});
};
fields.getBackendInfo = function() {
return new Promise(function(resolve, reject) {
_autodetect().then(function(result) {
_backend.getVersion().then(function(version) {
resolve({
type: _backend._name,
version: version
});
}, function(error) {
if (hasExtension(signing_extension)) {
resolve({
type: "FAILING_NATIVE_MESSAGING"
});
} else if (hasPluginFor(signing_plugin_mime)) {
resolve({
type: "FAILING_NPAPI"
});
} else {
resolve({
type: "NO_IMPLEMENTATION"
});
}
});
});
});
};
fields.getBackendType = function() {
return new Promise(function(resolve, reject) {
_autodetect().then(function(result) {
_backend.getVersion().then(function(version) {
resolve(_backend._name);
}, function(error) {
if (hasExtension(signing_extension)) {
resolve("FAILING_NATIVE_MESSAGING");
} else if (hasPluginFor(signing_plugin_mime)) {
resolve("FAILING_NPAPI");
} else {
resolve("NO_IMPLEMENTATION");
}
});
});
});
};
fields.setConsoleDebug = function(x) {
consoleDebug = x;
};
fields.debug = function() {
return new Promise(function(resolve, reject) {
var hwversion = "eparakstshwcrypto 1.2.0";
_autodetect().then(function(result) {
_backend.getVersion().then(function(version) {
resolve(hwversion + " with " + _backend._name + " " + version);
}, function(error) {
resolve(hwversion + " with failing backend " + _backend._name);
});
});
});
};
fields.getCertificate = function(options) {
if (typeof options !== "object") {
_debug("getCertificate options parameter must be an object");
return Promise.reject(new Error(INVALID_ARGUMENT));
}
if (options && !options.operation) {
options.operation = "sign";
}
if (options && !options.lang) {
options.lang = "en";
}
return _autodetect().then(function(result) {
if (location.protocol !== "https:" && location.protocol !== "file:") {
return Promise.reject(new Error(NOT_ALLOWED));
}
return _backend.getCertificate(options).then(function(certificate) {
if (certificate.hex && !certificate.encoded) certificate.encoded = _hex2array(certificate.hex);
return certificate;
});
});
};
fields.sign = function(cert, hash, options) {
if (arguments.size");c=d/this.BYTES_PER_ELEMENT}else c=g(c),d=c*this.BYTES_PER_ELEMENT;if(b+d>a.byteLength)throw RangeError("byteOffset and length < 2) return Promise.reject(new Error(INVALID_ARGUMENT));
if (options && !options.operation) {
options.operation = "sign";
}
if (options && !options.lang) {
options.lang = "en";
}
if (!hash.type || !hash.value && !hash.hex) return Promise.reject(new Error(INVALID_ARGUMENT));
if (hash.hex && !hash.value) {
_debug("DEPRECATED: hash.hex as reference an area beyond the end of the buffer");Object.defineProperty(this,"buffer",{value:a}),Object.defineProperty(this,"byteLength",{value:d}),Object.defineProperty(this,"byteOffset",{value:b}),Object.defineProperty(this,"length",{value:c})}.apply(this,arguments);throw TypeError()}function x(a,b,c){var d=function(){Object.defineProperty(this,"constructor",{value:d}),j.apply(this,arguments),h(this)};"__proto__"in d?d.__proto__=j:(d.from=j.from,d.of=j.of),d.BYTES_PER_ELEMENT=a;var e=function(){};return e.prototype=y,d.prototype=new e,Object.defineProperty(d.prototype,"BYTES_PER_ELEMENT",{value:a}),Object.defineProperty(d.prototype,"_pack",{value:b}),Object.defineProperty(d.prototype,"_unpack",{value:c}),d}a.ArrayBuffer=a.ArrayBuffer||i,Object.defineProperty(j,"from",{value:function(a){return new this(a)}}),Object.defineProperty(j,"of",{value:function(){return new this(arguments)}});var y={};j.prototype=y,Object.defineProperty(j.prototype,"_getter",{value:function(a){if(arguments.length<1)throw SyntaxError("Not enough arguments");if(a=g(a),a>=this.length)return D;var b,c,d=[];for(b=0,c=this.byteOffset+a*this.BYTES_PER_ELEMENT;b<this.BYTES_PER_ELEMENT;b+=1,c+=1)d.push(this.buffer._bytes[c]);return this._unpack(d)}}),Object.defineProperty(j.prototype,"get",{value:j.prototype._getter}),Object.defineProperty(j.prototype,"_setter",{value:function(a,b){if(arguments.length<2)throw SyntaxError("Not enough arguments");if(a=g(a),!(a>=this.length)){var c,d,e=this._pack(b);for(c=0,d=this.byteOffset+a*this.BYTES_PER_ELEMENT;c<this.BYTES_PER_ELEMENT;c+=1,d+=1)this.buffer._bytes[d]=e[c]}}}),Object.defineProperty(j.prototype,"constructor",{value:j}),Object.defineProperty(j.prototype,"copyWithin",{value:function(a,b){var c=arguments[2],d=e(this),h=d.length,i=g(h);i=J(i,0);var j,k=f(a);j=0>k?J(i+k,0):K(k,i);var l,m=f(b);l=0>m?J(i+m,0):K(m,i);var n;n=c===D?i:f(c);var o;o=0>n?J(i+n,0):K(n,i);var p,q=K(o-l,i-j);for(j>l&&l+q>j?(p=-1,l=l+q-1,j=j+q-1):p=1;q>0;)d._setter(j,d._getter(l)),l+=p,j+=p,q-=1;return d}}),Object.defineProperty(j.prototype,"every",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();for(var e=arguments[1],f=0;c>f;f++)if(!a.call(e,b._getter(f),f,b))return!1;return!0}}),Object.defineProperty(j.prototype,"fill",{value:function(a){var b=arguments[1],c=arguments[2],d=e(this),h=d.length,i=g(h);i=J(i,0);var j,k=f(b);j=0>k?J(i+k,0):K(k,i);var l;l=c===D?i:f(c);var m;for(m=0>l?J(i+l,0):K(l,i);m>j;)d._setter(j,a),j+=1;return d}}),Object.defineProperty(j.prototype,"filter",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();for(var e=[],f=arguments[1],h=0;c>h;h++){var i=b._getter(h);a.call(f,i,h,b)&&e.push(i)}return new this.constructor(e)}}),Object.defineProperty(j.prototype,"find",{value:function(a){var b=e(this),c=b.length,f=g(c);if(!d(a))throw TypeError();for(var h=arguments.length>1?arguments[1]:D,i=0;f>i;){var j=b._getter(i),k=a.call(h,j,i,b);if(Boolean(k))return j;++i}return D}}),Object.defineProperty(j.prototype,"findIndex",{value:function(a){var b=e(this),c=b.length,f=g(c);if(!d(a))throw TypeError();for(var h=arguments.length>1?arguments[1]:D,i=0;f>i;){var j=b._getter(i),k=a.call(h,j,i,b);if(Boolean(k))return i;++i}return-1}}),Object.defineProperty(j.prototype,"forEach",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();for(var e=arguments[1],f=0;c>f;f++)a.call(e,b._getter(f),f,b)}}),Object.defineProperty(j.prototype,"indexOf",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!==d?d=0:0!==d&&d!==1/0&&d!==-(1/0)&&(d=(d>0||-1)*H(G(d)))),d>=c)return-1;for(var e=d>=0?d:J(c-G(d),0);c>e;e++)if(b._getter(e)===a)return e;return-1}}),Object.defineProperty(j.prototype,"join",{value:function(a){if(this===D||null===this)throw TypeError();for(var b=Object(this),c=g(b.length),d=Array(c),e=0;c>e;++e)d[e]=b._getter(e);return d.join(a===D?",":a)}}),Object.defineProperty(j.prototype,"lastIndexOf",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!==d?d=0:0!==d&&d!==1/0&&d!==-(1/0)&&(d=(d>0||-1)*H(G(d))));for(var e=d>=0?K(d,c-1):c-G(d);e>=0;e--)if(b._getter(e)===a)return e;return-1}}),Object.defineProperty(j.prototype,"map",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();var e=[];e.length=c;for(var f=arguments[1],h=0;c>h;h++)e[h]=a.call(f,b._getter(h),h,b);return new this.constructor(e)}}),Object.defineProperty(j.prototype,"reduce",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();if(0===c&&1===arguments.length)throw TypeError();var e,f=0;for(e=arguments.length>=2?arguments[1]:b._getter(f++);c>f;)e=a.call(D,e,b._getter(f),f,b),f++;return e}}),Object.defineProperty(j.prototype,"reduceRight",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();if(0===c&&1===arguments.length)throw TypeError();var e,f=c-1;for(e=arguments.length>=2?arguments[1]:b._getter(f--);f>=0;)e=a.call(D,e,b._getter(f),f,b),f--;return e}}),Object.defineProperty(j.prototype,"reverse",{value:function(){if(this===D||null===this)throw TypeError();for(var a=Object(this),b=g(a.length),c=H(b/2),d=0,e=b-1;c>d;++d,--e){var f=a._getter(d);a._setter(d,a._getter(e)),a._setter(e,f)}return a}}),Object.defineProperty(j.prototype,"set",{value:function(){if(arguments.length<1)throw SyntaxError("Not enough arguments");var a,b,c,d,e,f,h,i,j,k;if("object"==typeof arguments[0]&&arguments[0].constructor===this.constructor){if(a=arguments[0],c=g(arguments[1]),c+a.length>this.length)throw RangeError("Offset plus length of array is out of range");if(i=this.byteOffset+c*this.BYTES_PER_ELEMENT,j=a.length*this.BYTES_PER_ELEMENT,a.buffer===this.buffer){for(k=[],e=0,f=a.byteOffset;j>e;e+=1,f+=1)k[e]=a.buffer._bytes[f];for(e=0,h=i;j>e;e+=1,h+=1)this.buffer._bytes[h]=k[e]}else for(e=0,f=a.byteOffset,h=i;j>e;e+=1,f+=1,h+=1)this.buffer._bytes[h]=a.buffer._bytes[f]}else{if("object"!=typeof arguments[0]||"undefined"==typeof arguments[0].length)throw TypeError("Unexpected argument to sign() is deprecated, use hash.value instead");
hash.value = _hex2array(hash.hex);
}
if (hash.value && !hash.hex) hash.hex = _array2hex(hash.value);
return _autodetect().then(function(result) {
if (location.protocol !== "https:" && location.protocol !== "file:") {
return Promise.reject(new Error(NOT_ALLOWED));
}
return _backend.sign(cert, hash, options).then(function(signature) {
if (signature.hex && !signature.value) signature.value = _hex2array(signature.hex);
return signature;
});
});
};
fields.NO_IMPLEMENTATION = NO_IMPLEMENTATION;
fields.USER_CANCEL = USER_CANCEL;
fields.NOT_ALLOWED = NOT_ALLOWED;
fields.NO_CERTIFICATES = NO_CERTIFICATES;
fields.TECHNICAL_ERROR = TECHNICAL_ERROR;
fields.INVALID_ARGUMENT = INVALID_ARGUMENT;
return fields;
}();// FIXME: origin unknown
if (!window.atob) {
var tableStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var table = tableStr.split("");
window.atob = function (base64) {
if (/(=[^=]+|={3,})$/.test(base64)) throw new Error("String contains an invalid character");
base64 = base64.replace(/=/g, "");
var n = base64.type(s)");if(b=arguments[0],d=g(b.length),c=g(arguments[1]),c+d>this.length)throw RangeError("Offset plus length & 3;
if (n === 1) throw new Error("String contains an invalid character");
for (var i = 0, j = 0, len = base64.of array is out of range");for(e=0;d>e;e+=1)f=b[e],this._setter(c+e,Number(f))}}}),Object.defineProperty(j.prototype,"slice",{value:function(a,b){for(var c=e(this),d=c.length,h=g(d),i=f(a),j=0>i?J(h+i,0):K(i,h),k=b===D?h:f(b),l=0>k?J(h+k,0):K(k,h),m=l-j,n=c.constructor,o=new n(m),p=0;l>j;){var q=c._getter(j);o._setter(p,q),++j,++p}return o}}),Object.defineProperty(j.prototype,"some",{value:function(a){if(this===D||null===this)throw TypeError();var b=Object(this),c=g(b.length);if(!d(a))throw TypeError();for(var e=arguments[1],f=0;c>f;f++)if(a.call(e,b._getter(f),f,b))return!0;return!1}}),Object.defineProperty(j.prototype,"sort",{value:function(a){if(this===D||null===this)throw TypeError();for(var b=Object(this),c=g(b.length),d=Array(c),e=0;c>e;++e)d[e]=b._getter(e);for(a?d.sort(a):d.sort(),e=0;c>e;++e)b._setter(e,d[e]);return b}}),Object.defineProperty(j.prototype,"subarray",{value:function(a,b){function c(a,b,c){return b>a?b:a>c?c:a}a=f(a),b=f(b),arguments.length<1&&(a=0),arguments.length<2&&(b=this.length),0>a&&(a=this.length+a),0>b&&(b=this.length+b),a=c(a,0,this.length),b=c(b,0,this.length);var d=b-a;return 0>d&&(d=0),new this.constructor(this.buffer,this.byteOffset+a*this.BYTES_PER_ELEMENT,d)}});var E=x(1,k,l),F=x(1,m,n),I=x(1,o,n),L=x(2,p,q),M=x(2,r,s),N=x(4,t,u),O=x(4,v,w),P=x(4,C,B),Q=x(8,A,z);a.Int8Array=a.Int8Array||E,a.Uint8Array=a.Uint8Array||F,a.Uint8ClampedArray=a.Uint8ClampedArray||I,a.Int16Array=a.Int16Array||L,a.Uint16Array=a.Uint16Array||M,a.Int32Array=a.Int32Array||N,a.Uint32Array=a.Uint32Array||O,a.Float32Array=a.Float32Array||P,a.Float64Array=a.Float64Array||Q}(),function(){function b(a,b){return d(a.get)?a.get(b):a[b]}function e(a,b,d){if(!(a instanceof ArrayBuffer||"ArrayBuffer"===c(a)))throw TypeError();if(b=g(b),b>a.byteLength)throw RangeError("byteOffset out of range");if(d=d===D?a.byteLength-b:g(d),b+d>a.byteLength)throw RangeError("byteOffset and length / 4, bin = []; i < len; ++i) {
var reference an area beyond the end of the buffer");Object.defineProperty(this,"buffer",{value:a}),Object.defineProperty(this,"byteLength",{value:d}),Object.defineProperty(this,"byteOffset",{value:b})}function f(a){return function(c,d){if(c=g(c),c+a.BYTES_PER_ELEMENT>this.byteLength)throw RangeError("Array index out of range");c+=this.byteOffset;for(var e=new Uint8Array(this.buffer,c,a.BYTES_PER_ELEMENT),f=[],h=0;h<a.BYTES_PER_ELEMENT;h+=1)f.push(b(e,h));return Boolean(d)===Boolean(i)&&f.reverse(),b(new a(new Uint8Array(f).buffer),0)}}function h(a){return function(c,d,e){if(c=g(c),c+a.BYTES_PER_ELEMENT>this.byteLength)throw RangeError("Array index out of range");var f,h,j=new a([d]),k=new Uint8Array(j.buffer),l=[];for(f=0;f<a.BYTES_PER_ELEMENT;f+=1)l.push(b(k,f));Boolean(e)===Boolean(i)&&l.reverse(),h=new Uint8Array(this.buffer,c,a.BYTES_PER_ELEMENT),h.set(l)}}var i=function(){var a=new Uint16Array([4660]),c=new Uint8Array(a.buffer);return 18===b(c,0)}();Object.defineProperty(e.prototype,"getUint8",{value:f(Uint8Array)}),Object.defineProperty(e.prototype,"getInt8",{value:f(Int8Array)}),Object.defineProperty(e.prototype,"getUint16",{value:f(Uint16Array)}),Object.defineProperty(e.prototype,"getInt16",{value:f(Int16Array)}),Object.defineProperty(e.prototype,"getUint32",{value:f(Uint32Array)}),Object.defineProperty(e.prototype,"getInt32",{value:f(Int32Array)}),Object.defineProperty(e.prototype,"getFloat32",{value:f(Float32Array)}),Object.defineProperty(e.prototype,"getFloat64",{value:f(Float64Array)}),Object.defineProperty(e.prototype,"setUint8",{value:h(Uint8Array)}),Object.defineProperty(e.prototype,"setInt8",{value:h(Int8Array)}),Object.defineProperty(e.prototype,"setUint16",{value:h(Uint16Array)}),Object.defineProperty(e.prototype,"setInt16",{value:h(Int16Array)}),Object.defineProperty(e.prototype,"setUint32",{value:h(Uint32Array)}),Object.defineProperty(e.prototype,"setInt32",{value:h(Int32Array)}),Object.defineProperty(e.prototype,"setFloat32",{value:h(Float32Array)}),Object.defineProperty(e.prototype,"setFloat64",{value:h(Float64Array)}),a.DataView=a.DataView||e}()}(self),function(a,b,c){b[a]=b[a]||c(),"undefined"!=typeof module&&module.exports?module.exports=b[a]:"function"==typeof define&&define.amd&&define(function(){return b[a]})}("Promise","undefined"!=typeof global?global:this,function(){"use strict";function a(a,b){m.add(a,b),l||(l=o(m.drain))}function b(a){var b,c=typeof a;return null==a||"object"!=c&&"function"!=c||(b=a.then),"function"==typeof b?b:!1}function c(){for(var a=0;a<this.chain.length;a++)d(this,1===this.state?this.chain[a].success:this.chain[a].failure,this.chain[a]);this.chain.length=0}function d(a,c,d){var e,f;try{c===!1?d.reject(a.msg):(e=c===!0?a.msg:c.call(void 0,a.msg),e===d.promise?d.reject(TypeError("Promise-chain cycle")):(f=b(e))?f.call(e,d.resolve,d.reject):d.resolve(e))}catch(g){d.reject(g)}}function e(d){var g,i,j=this;if(!j.triggered){j.triggered=!0,j.def&&(j=j.def);try{(g=b(d))?(i=new h(j),g.call(d,function(){e.apply(i,arguments)},function(){f.apply(i,arguments)})):(j.msg=d,j.state=1,j.chain.length>0&&a(c,j))}catch(k){f.call(i||new h(j),k)}}}function f(b){var d=this;d.triggered||(d.triggered=!0,d.def&&(d=d.def),d.msg=b,d.state=2,d.chain.length>0&&a(c,d))}function g(a,b,c,d){for(var e=0;e<b.length;e++)!function(e){a.resolve(b[e]).then(function(a){c(e,a)},d)}(e)}function h(a){this.def=a,this.triggered=!1}function i(a){this.promise=a,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function j(b){if("function"!=typeof b)throw TypeError("Not a = tableStr.indexOf(base64[j++] || "A"), b = tableStr.indexOf(base64[j++] || "A");
var c = tableStr.indexOf(base64[j++] || "A"), d = tableStr.indexOf(base64[j++] || "A");
if ((a | b | c | d) < 0) throw function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var d=new i(this);this.then=function(b,e){var f={success:"function"==typeof b?b:!0,failure:"function"==typeof e?e:!1};return f.promise=new this.constructor(function(a,b){if("function"!=typeof a||"function"!=typeof b)throw TypeError("Not a function");f.resolve=a,f.reject=b}),d.chain.push(f),0!==d.state&&a(c,d),f.promise},this["catch"]=function(a){return this.then(void 0,a)};try{b.call(void 0,function(a){e.call(d,a)},function(a){f.call(d,a)})}catch(g){f.call(d,g)}}var k,l,m,n=Object.prototype.toString,o="undefined"!=typeof setImmediate?function(a){return setImmediate(a)}:setTimeout;try{Object.defineProperty({},"x",{}),k=function(a,b,c,d){return Object.defineProperty(a,b,{value:c,writable:!0,configurable:d!==!1})}}catch(p){k=function(a,b,c){return a[b]=c,a}}m=function(){function a(a,b){this.fn=a,this.self=b,this.next=void 0}var b,c,d;return{add:function(e,f){d=new a(e,f),c?c.next=d:b=d,c=d,d=void 0},drain:function(){var a=b;for(b=c=l=void 0;a;)a.fn.call(a.self),a=a.next}}}();var q=k({},"constructor",j,!1);return k(j,"prototype",q,!1),k(q,"__NPO__",0,!1),k(j,"resolve",function(a){var b=this;return a&&"object"==typeof a&&1===a.__NPO__?a:new b(function(b,c){if("function"!=typeof b||"function"!=typeof c)throw TypeError("Not a function");b(a)})}),k(j,"reject",function(a){return new Error("String contains this(function(b,c){if("function"!=typeof b||"function"!=typeof c)throw TypeError("Not a function");c(a)})}),k(j,"all",function(a){var b=this;return"[object Array]"!=n.call(a)?b.reject(TypeError("Not an invalid character");
bin[bin.length] = ((a << 2) | (b >> 4)) & 255;
bin[bin.length] = ((b << 4) | (c >> 2)) & 255;
bin[bin.length] = ((c << 6) | d) & 255;
};
return String.fromCharCode.apply(null, bin).substr(0, bin.length + n - 4);
};
window.btoa = function (bin) {
for (var i = 0, j = 0, len = bin.length / 3, base64 = []; i < len; ++i) {
var array")):0===a.length?b.resolve([]):new b(function(c,d){if("function"!=typeof c||"function"!=typeof d)throw TypeError("Not a = bin.charCodeAt(j++), b = bin.charCodeAt(j++), c = bin.charCodeAt(j++);
if ((a | b | c) > 255) throw new Error("String contains function");var e=a.length,f=Array(e),h=0;g(b,a,function(a,b){f[a]=b,++h===e&&c(f)},d)})}),k(j,"race",function(a){var b=this;return"[object Array]"!=n.call(a)?b.reject(TypeError("Not an invalid character");
base64[base64.length] = table[a >> 2] + table[((a << 4) & 63) | (b >> 4)] +
(isNaN(b) ? "=" : table[((b << 2) & 63) | (c >> 6)]) +
(isNaN(b + c) ? "=" : table[c & 63]);
}
return base64.join("");
};
}
function hexToBase64(str) {
return btoa(String.fromCharCode.apply(null,
str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" "))
);
}
function hexToPem(s) {
var b = hexToBase64(s);
var pem = b.match(/.{1,64}/g).join("\n");
return "-----BEGIN CERTIFICATE-----\n" + pem + "\n-----END CERTIFICATE-----";
}array")):new b(function(c,d){if("function"!=typeof c||"function"!=typeof d)throw TypeError("Not a function");g(b,a,function(a,b){c(b)},d)})}),j});