@keeex/tsr
Version:
Manipulate data related to TSR with pki.js
132 lines (131 loc) • 3.78 kB
TypeScript
/**
* @license
* @preserve
*
* KeeeX SAS Public code
* https://keeex.me
* Copyright 2013-2024 KeeeX All Rights Reserved.
*
* These computer program listings and specifications, herein,
* are and remain the property of KeeeX SAS. The intellectual
* and technical concepts herein are proprietary to KeeeX SAS
* and may be covered by EU and foreign patents,
* patents in process, trade secrets and copyright law.
*
* These listings are published as a way to provide third party
* with the ability to process KeeeX data.
* As such, support for public inquiries is limited.
* They are provided "as-is", without warrany of any kind.
*
* They shall not be reproduced or copied or used in whole or
* in part as the basis for manufacture or sale of items unless
* prior written permission is obtained from KeeeX SAS.
*
* For a license agreement, please contact:
* <mailto: contact@keeex.net>
*
*/
import * as digest from "@keeex/crypto/digest.js";
import * as pkijs from "pkijs";
/**
* Provide the pre-computed digest of a message.
*
* @public
*/
export interface MessageInputDigest {
type: "digest";
/** Pre-computed digest of the actual message (array or hex representation) */
value: Uint8Array | string;
algorithm: digest.Algorithms;
}
/**
* Provide the full message content, to be hashed to produce a digest.
*
* @public
*/
export interface MessageInputData {
type: "data";
/** Actual message to timestamp
*
* The digest will be computed according to the algorithm set.
* Strings will be interpreted as UTF-8 input.
*/
value: Uint8Array | string;
algorithm: digest.Algorithms;
}
/** @public */
export interface MessageInputImprint {
type: "imprint";
value: pkijs.MessageImprint;
}
export type MessageInput = MessageInputDigest | MessageInputData | MessageInputImprint;
export interface SignerInput {
certificate: pkijs.Certificate;
privateKey?: CryptoKey;
}
export interface AccuracyInfo {
seconds: number;
millis: number;
micros: number;
}
/** All the inputs needed to generate a TSR response */
export interface TimestampInput {
serialNumber: number | bigint;
policy: string;
query: MessageInput;
digestAlgorithm: digest.Algorithms;
signers: SignerInput | Array<SignerInput>;
genTime: Date;
accuracy?: AccuracyInfo;
ordering?: boolean;
tsaCert: pkijs.Certificate;
/**
* List of certificates to embed in the TSR
*
* Must start with the signing certificate.
*/
certificatesChain?: Array<pkijs.Certificate>;
status: pkijs.PKIStatus;
}
/**
* Data from a granted TSR.
*
* @public
*/
export interface ExtractedTsrInfoGranted {
/** Algorithm used to digest the message */
digest: digest.Algorithms;
/** TSA policy */
policy: string;
/** Algorithm used to hash the TSR for signature */
signatureDigest: digest.Algorithms;
/** Digest of the message */
subject: Uint8Array;
/** Date of the TSR */
date: Date;
/** Certificate's serial number */
serialNumber: bigint;
/** Name of the TSA */
tsa: string;
/** Accuracy of the certification authority (in seconds) */
accuracyInSeconds: number | null;
/** True if the certificate was granted */
granted: true;
}
/**
* Data from a rejected TSR
*
* @public
*/
export interface ExtractedTsrInfoRejected {
granted: false;
}
export type ExtractedTsrInfo = ExtractedTsrInfoGranted | ExtractedTsrInfoRejected;
/** Verified data from a TSR */
export interface VerifiedTsrInfo {
/** Only true if the signature is valid and was verified to come from the given CA */
valid: boolean;
signers?: Array<pkijs.Certificate>;
tsrInfo?: ExtractedTsrInfo;
error?: Error;
}