import type { ProofOfWorkChallengeModel } from '@enbox/dwn-clients'; /** * Manages proof-of-work challenge difficulty and lifecycle based on solve rate. * Can have multiple instances each having their own desired solve rate and difficulty. */ export declare class ProofOfWorkManager { static readonly defaultMaximumAllowedHashValue = "000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; private challengeNonces; private readonly proofOfWorkOfLastMinute; private readonly challengeSeed?; private readonly difficultyIncreaseMultiplier; private currentMaximumAllowedHashValueAsBigInt; private readonly initialMaximumAllowedHashValueAsBigInt; private readonly desiredSolveCountPerMinute; /** * How often the challenge nonce is refreshed. */ challengeRefreshFrequencyInSeconds: number; /** * How often the difficulty is reevaluated. */ difficultyReevaluationFrequencyInSeconds: number; /** * The current maximum allowed hash value. */ get currentMaximumAllowedHashValue(): bigint; /** * The current proof-of-work solve rate. */ get currentSolveCountPerMinute(): number; private constructor(); /** * Creates a new ProofOfWorkManager instance. * @param input.difficultyIncreaseMultiplier How fast to increase difficulty when solve rate is higher than desired. Must be >= 1. * Defaults to 1 which means if the solve rate is 2x the desired solve rate, the difficulty will increase by 2x. * If set to 2, it means if the solve rate is 2x the desired solve rate, the difficulty will increase by 4x. * @param input.challengeRefreshFrequencyInSeconds How often the challenge nonce is refreshed. Defaults to 10 minutes. * @param input.difficultyReevaluationFrequencyInSeconds How often the difficulty is reevaluated. Defaults to 10 seconds. */ static create(input: { desiredSolveCountPerMinute: number; autoStart: boolean; initialMaximumAllowedHashValue?: string; difficultyIncreaseMultiplier?: number; challengeSeed?: string; challengeRefreshFrequencyInSeconds?: number; difficultyReevaluationFrequencyInSeconds?: number; }): Promise; /** * Starts the proof-of-work manager by starting the challenge nonce and difficulty refresh timers. */ start(): void; getProofOfWorkChallenge(): ProofOfWorkChallengeModel; /** * Verifies the proof-of-work meets the difficulty requirement. */ verifyProofOfWork(proofOfWork: { challengeNonce: string; responseNonce: string; requestData: string; }): Promise; /** * Records a successful proof-of-work. * Exposed for testing purposes. */ recordProofOfWork(proofOfWorkId: string): Promise; private periodicallyRefreshChallengeNonce; private periodicallyRefreshProofOfWorkDifficulty; private removeProofOfWorkOlderThanOneMinute; private refreshChallengeNonce; /** * Refreshes the difficulty by changing the max hash value. * The higher the number, the easier. Scale 1 (hardest) to 2^256 (easiest), represented in HEX. * * If solve rate rate is higher than expected, the difficulty will increase rapidly. * If solve rate is lower than expected, the difficulty will decrease gradually. * The difficulty will never be lower than the initial difficulty. */ private refreshMaximumAllowedHashValue; /** * Only used by refreshMaximumAllowedHashValue() to reduce the challenge difficulty gradually. */ private hashValueIncrementPerEvaluation; /** * Verifies that the supplied string is a HEX string. */ static isHexString(str: string): boolean; /** * Converts a BigInt to a 256 bit HEX string with padded preceding zeros (64 characters). */ private static bigIntToHexString; } //# sourceMappingURL=proof-of-work-manager.d.ts.map