ctjs
Version:
CTjs is a full set of classes necessary to work with any kind of Certificate Transparency log (V1 as from RFC6962, or V2 as from RFC6962-bis). In CTjs you could find all necessary validation/verification functions for all related data shipped with full-fe
127 lines (114 loc) • 4.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _pvutils = require("pvutils");
var _utils = require("./utils.js");
var _BaseClass = require("./BaseClass.js");
//**************************************************************************************
class InclusionProofDataV2 extends _BaseClass.BaseClass {
//**********************************************************************************
/**
* Constructor for InclusionProofDataV2 class
* @param {Object} [parameters={}]
* @property {Object} [schema] asn1js parsed value
*/
constructor(parameters = {}) {
super(parameters);
//region Internal properties of the object
/**
* @type {String}
* @description logID OID representing used Certificate Transparency Log
*/
this.logID = (0, _pvutils.getParametersValue)(parameters, "logID", InclusionProofDataV2.constants("logID"));
/**
* @type {Number}
* @description treeSize The size of the tree on which this inclusion proof is based
*/
this.treeSize = (0, _pvutils.getParametersValue)(parameters, "treeSize", InclusionProofDataV2.constants("treeSize"));
/**
* @type {Number}
* @description leafIndex The 0-based index of the log entry corresponding to this inclusion proof
*/
this.leafIndex = (0, _pvutils.getParametersValue)(parameters, "leafIndex", InclusionProofDataV2.constants("leafIndex"));
/**
* @type {Array.<ArrayBuffer>}
* @description inclusionPath
*/
this.inclusionPath = (0, _pvutils.getParametersValue)(parameters, "inclusionPath", InclusionProofDataV2.constants("inclusionPath"));
//endregion
}
//**********************************************************************************
/**
* Return value for a constant by name
* @param {string} name String name for a constant
*/
static constants(name) {
switch (name) {
case "logID":
return "";
case "treeSize":
case "leafIndex":
return 0;
case "inclusionPath":
return [];
default:
throw new Error(`Invalid constant name for InclusionProofDataV2 class: ${name}`);
}
}
//**********************************************************************************
/**
* Convert SeqStream data into current class
* @param {!SeqStream} stream
*/
fromStream(stream) {
this.logID = _utils.utils.getOID(stream, "InclusionProofDataV2");
this.treeSize = _utils.utils.getUint64(stream);
this.leafIndex = _utils.utils.getUint64(stream);
let pathLength = stream.getUint16();
while (pathLength) {
const hashLength = stream.getBlock(1)[0];
this.inclusionPath.push(new Uint8Array(stream.getBlock(hashLength)).buffer.slice(0));
pathLength--;
}
}
//**********************************************************************************
/**
* Convert current object to SeqStream data
* @param {!SeqStream} stream
* @returns {boolean} Result of the function
*/
toStream(stream) {
_utils.utils.appendOID(this.logID, stream);
_utils.utils.appendUint64(this.treeSize, stream);
_utils.utils.appendUint64(this.leafIndex, stream);
stream.appendUint16(this.inclusionPath.length);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = this.inclusionPath[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const inclusion = _step.value;
stream.appendChar(inclusion.byteLength);
stream.appendView(new Uint8Array(inclusion));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return true;
}
//**********************************************************************************
}
exports.default = InclusionProofDataV2; //**************************************************************************************
//# sourceMappingURL=InclusionProofDataV2.js.map