index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.verifyTSATimestamp = verifyTSATimestamp;
  4. exports.verifyTLogTimestamp = verifyTLogTimestamp;
  5. const error_1 = require("../error");
  6. const checkpoint_1 = require("./checkpoint");
  7. const merkle_1 = require("./merkle");
  8. const set_1 = require("./set");
  9. const tsa_1 = require("./tsa");
  10. function verifyTSATimestamp(timestamp, data, timestampAuthorities) {
  11. (0, tsa_1.verifyRFC3161Timestamp)(timestamp, data, timestampAuthorities);
  12. return {
  13. type: 'timestamp-authority',
  14. logID: timestamp.signerSerialNumber,
  15. timestamp: timestamp.signingTime,
  16. };
  17. }
  18. function verifyTLogTimestamp(entry, tlogAuthorities) {
  19. let inclusionVerified = false;
  20. if (isTLogEntryWithInclusionPromise(entry)) {
  21. (0, set_1.verifyTLogSET)(entry, tlogAuthorities);
  22. inclusionVerified = true;
  23. }
  24. if (isTLogEntryWithInclusionProof(entry)) {
  25. (0, merkle_1.verifyMerkleInclusion)(entry);
  26. (0, checkpoint_1.verifyCheckpoint)(entry, tlogAuthorities);
  27. inclusionVerified = true;
  28. }
  29. if (!inclusionVerified) {
  30. throw new error_1.VerificationError({
  31. code: 'TLOG_MISSING_INCLUSION_ERROR',
  32. message: 'inclusion could not be verified',
  33. });
  34. }
  35. return {
  36. type: 'transparency-log',
  37. logID: entry.logId.keyId,
  38. timestamp: new Date(Number(entry.integratedTime) * 1000),
  39. };
  40. }
  41. function isTLogEntryWithInclusionPromise(entry) {
  42. return entry.inclusionPromise !== undefined;
  43. }
  44. function isTLogEntryWithInclusionProof(entry) {
  45. return entry.inclusionProof !== undefined;
  46. }