xml-fiesta
Version:
Electronic signed document XML Protocol for Node & Browser
101 lines • 4.37 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var certificate_1 = require("./certificate");
var common_1 = require("./common");
var document_1 = require("./document");
var signature_1 = require("./signature");
var Transfer = (function (_super) {
__extends(Transfer, _super);
function Transfer(xml, options, transferData) {
var _this = _super.call(this, xml.file(), options) || this;
_this.prevAddress = transferData.prevAddress;
_this.currentAddress = transferData.currentAddress;
_this.dataBlockchain = transferData.dataBlockchain;
_this.xml = xml;
return _this;
}
Transfer.prototype.validEndorser = function (rootCertificates) {
var isValidHolder = this.validateHolderBinding(this.prevHolder, rootCertificates);
if (!isValidHolder) {
console.error("Transfer(validate endorser): holder is not valid");
return {
isValid: false,
error_code: "integrity",
};
}
var isConsistentWithBlockchain = this.prevAddress === this.dataBlockchain.prevAddress;
if (!isConsistentWithBlockchain) {
console.error("Transfer(validate endorser): Endorser address inconsistent with blockchain", {
prevAddress: this.prevAddress,
blockchainPrevAddress: this.dataBlockchain.prevAddress,
});
return {
isValid: false,
error_code: "inconsistent_with_blockchain",
};
}
return {
isValid: true,
};
};
Transfer.prototype.validEndorsee = function (rootCertificates) {
var isValidHolder = this.validateHolderBinding(this.currentHolder, rootCertificates);
if (!isValidHolder) {
console.error("Transfer(validate endorsee): holder is not valid");
return {
isValid: false,
error_code: "integrity",
};
}
var isConsistentWithBlockchain = this.currentAddress === this.dataBlockchain.currentAddress;
if (!isConsistentWithBlockchain) {
console.error("Transfer(validate endorsee): Endorsee address inconsistent with blockchain", {
currentAddress: this.currentAddress,
blockchainCurrentAddress: this.dataBlockchain.currentAddress,
});
return {
isValid: false,
error_code: "inconsistent_with_blockchain",
};
}
return {
isValid: true,
};
};
Transfer.prototype.validateHolderBinding = function (holder, rootCertificates) {
var certificate = new certificate_1.default(null, common_1.b64toHex(holder.binding[0].certificate[0]._));
var isCa = rootCertificates.some(function (rootCer) {
return certificate.isCa(rootCer.cer_hex);
});
var nodeSignature = holder.binding[0].signature[0];
var signatureData = {
signedAt: nodeSignature.$.signedAt,
signatureHex: common_1.b64toHex(nodeSignature._),
};
var signatureInstance = new signature_1.default(certificate.hex, signatureData.signatureHex, signatureData.signedAt, null, null);
var isValidSignature = signatureInstance.valid(nodeSignature.$.plaintext);
if (!isCa) {
console.error("Transfer(validate holder binding): Certificate is not a CA");
}
if (!isValidSignature) {
console.error("Transfer(validate holder binding): Signature validation failed");
}
return isCa && isValidSignature;
};
return Transfer;
}(document_1.default));
exports.default = Transfer;
//# sourceMappingURL=transfer.js.map