UNPKG

@cronstamp/clientlib

Version:

Client library for cronstamp, a blockchain-based document timestamping and verification service.

102 lines 4.35 kB
import { Log } from '../util/logger.js'; import { Certificate, CertificateHelper } from '../certificate.js'; import { CronStampConfig, FullCronStampConfig } from '../util/config.js'; import { BlockchainName } from '../blockchains/blockchains.js'; export declare enum Step { INIT = 0,// load input data HASH_INPUT_DATA = 1,// hash data REQUEST_CALCULATE_SALT = 2,// calculate salted hash REQUEST_SUBMIT_DOCUMENT_HASH = 3,// submitted to api REQUEST_RECEIVE_PRECERT = 4,// precert received (this also contains a url to this precert as additional data) REQUEST_CREATE_CERTIFICATE_FOR_SINGLE_BLOCKCHAIN = 5,// after the root hash for a specific blockchain is successfully inserted into the blockchain and verified REQUEST_FULL_CERTIFICATE_SUCCEEDED = 6,// this only has type success and means a full certificate is available VERIFICATION_CHECK_CERTIFICATE_SYNTAX = 7,// check that required fields exists VERIFICATION_COMPARE_SALTED_HASHES = 8,// hash data and compare to certificate VERIFICATION_VERIFY_SINGLE_BLOCKCHAIN = 9,// verify individual blockchains. A success state means this blockchain is full verified. VERIFICATION_ALL_BLOCKCHAINS_SUCCEEDED = 10 } export declare enum MessageType { SUCCESS = 0,// step is successful ERROR = 1,// this is passed to the error handler, if provided and to the message handler otherwise PROGRESS = 2 } export declare enum AdditionalDataType { NONE = 0, PRECERT_URL = 1,// Url to cloud hosted precert (only valid a limited time) HTTP_RESPONSE_JSON = 2,// Json of http response for example when an error is returned by the api ERROR = 3,// error detail HASH = 4,// used for merkle tree root hash TIMESTAMP = 5,// time in blockchain, if there is a mismatch with certificate time PARSED_CERTIFICATE = 6,// successfully parsed certificate from file or string INVALID_SYNTAX_CERTIFICATE = 7,// used, when certificate is determined to have invalid syntax PROCESSED_BLOCKCHAIN = 8 } export declare enum InputDataType { STRING = 0, FILE = 1, HASH = 2 } export type InputData = { type: InputDataType; data: string | File; blockchainsToRequire?: BlockchainName[]; }; export type ErrorInfo = { rawError: Error; additionalDataType: AdditionalDataType; additionalData: any; type: ErrorTypes; }; export declare enum ErrorTypes { DOCUMENT_ALTERED = 0, TEMPORARY = 1, UNEXPECTED = 2 } export type ResultData = { step: Step; type: MessageType; blockchain: BlockchainName | undefined; currentCert: Certificate; message: string; additionalDataType: AdditionalDataType; additionalData: any; inputData: InputData & { certFileName: string; displayName: string; }; currentTime: Date; }; export declare abstract class CertificateProcess { config: FullCronStampConfig; protected inputData: InputData; protected certHelper: CertificateHelper; protected messageHandler: (data: ResultData) => boolean | void; protected errorHandler: (data: ResultData) => void; protected step: Step; protected currentBlockchain: BlockchainName | undefined; private started; protected cancelled: boolean; protected log: Log; protected constructor(data: InputData, moduleName: string); onMessage(handler: (data: ResultData) => boolean | void): this; onError(handler: (data: ResultData) => void): this; cancel(): void; configure(newConfig: CronStampConfig): this; /** * start process by handling input data * @returns last result data containing a success or error message */ start(): Promise<ResultData>; sendError(message: string, additionalDataType?: AdditionalDataType, additionalData?: any): ResultData; sendMessage(message: string, type: MessageType, additionalDataType?: AdditionalDataType, additionalData?: any): ResultData; protected handleException(exception: Error): ResultData; protected getIdentifier(): string; protected getShortName(): string; protected getInputDataName(): string; } export declare class ProcessError extends Error { additionalData: any; errorInfo: ErrorInfo; constructor(message: string, type: ErrorTypes, additionalDataType?: AdditionalDataType, additionalData?: any); } //# sourceMappingURL=manager.d.ts.map