import type { DB, DBTransaction, LevelPath, KeyPath } from '@matrixai/db'; import type { ClaimInput } from './types.js'; import type KeyRing from '../keys/KeyRing.js'; import type { ClaimId, Claim, ClaimHeaderSignature, SignedClaim } from '../claims/types.js'; import Logger from '@matrixai/logger'; import { createDestroyStartStop } from '@matrixai/async-init'; import Token from '../tokens/Token.js'; interface Sigchain extends createDestroyStartStop.CreateDestroyStartStop { } declare class Sigchain { static createSigchain({ db, keyRing, logger, fresh, }: { db: DB; keyRing: KeyRing; logger?: Logger; fresh?: boolean; }): Promise; protected logger: Logger; protected keyRing: KeyRing; protected db: DB; protected generateClaimId: () => ClaimId; protected generateSequenceNumber: () => number; protected dbPath: LevelPath; protected dbClaimsPath: LevelPath; protected dbSignaturesPath: LevelPath; /** * Maintain last `ClaimId` to preserve monotonicity across process restarts. * The `ClaimId` provides a globally unique ID that is time-sortable. * `Sigchain/lastClaimId -> {raw(ClaimId)}` */ protected dbLastClaimIdPath: KeyPath; /** * Maintain last sequence number to preserve monotonicity across process restarts. * The sequence number provides cardinal and ordinal information regarding a claim. * `Sigchain/lastSequenceNumber -> {SequenceNumber}}` */ protected dbLastSequenceNumberPath: KeyPath; constructor({ db, keyRing, logger, }: { db: DB; keyRing: KeyRing; logger: Logger; }); start({ fresh, }?: { fresh?: boolean; }): Promise; stop(): Promise; destroy(): Promise; /** * Gets the last claim ID for preserving monotonicity over restarts */ getLastClaimId(tran?: DBTransaction): Promise; /** * Gets the last sequence number for preserving monotonicity over restarts */ getLastSequenceNumber(tran?: DBTransaction): Promise; /** * Call this method when the `KeyRing` changes * This should be replaced with rxjs later */ onKeyRingChange(): Promise; getLastClaim(tran?: DBTransaction): Promise<[ClaimId, Claim] | undefined>; getLastSignedClaim(tran?: DBTransaction): Promise<[ClaimId, SignedClaim] | undefined>; /** * Get a claim according to the `ClaimId` */ getClaim(claimId: ClaimId, tran?: DBTransaction): Promise; /** * Get a signed claim according to the `ClaimId` */ getSignedClaim(claimId: ClaimId, tran?: DBTransaction): Promise; /** * Get a claim signatures according to the `ClaimId` */ getSignatures(claimId: ClaimId, tran?: DBTransaction): Promise>; /** * Get claims */ getClaims({ order, seek, limit, }?: { order?: 'asc' | 'desc'; seek?: ClaimId; limit?: number; }, tran?: DBTransaction): AsyncGenerator<[ClaimId, Claim]>; /** * Get signed claims */ getSignedClaims({ order, seek, limit, }?: { order?: 'asc' | 'desc'; seek?: ClaimId; limit?: number; }, tran?: DBTransaction): AsyncGenerator<[ClaimId, SignedClaim]>; /** * Appends a claim (of any type) to the sigchain. * For `ClaimInput`, it will be JSON encoded. * Remember that `undefined` properties are deleted. * While `undefined` values in arrays are converted to `null`. */ addClaim(data: ClaimInput, date?: Date, signingHook?: (token: Token) => Promise>, tran?: DBTransaction): Promise<[ClaimId, SignedClaim]>; /** * Mutually exclude the last claim ID. * Use this to ensure claim appending is serialised. */ protected lockLastClaimId(tran: DBTransaction): Promise; } export default Sigchain;