import { HashAlgorithm } from '@pigi/core-utils' ; import { Decider , Decision , HashPreimageDBInterface } from '../../types' ; import { CannotDecideError } from './utils' ; export interface HashInput { hash : string ; } /**
 * Decider that determines whether the provided witness is the preimage to the hash in question.
 */ export class HashPreimageExistenceDecider implements Decider { constructor ( private readonly db , private readonly hashAlgorithm ) { } public async decide ( input , _noCache ? ) { const preimage = await this . db . getPreimage ( input . hash , this . hashAlgorithm ) ; if ( ! preimage ) { throw new CannotDecideError ( `No preimage is stored for hash [${ JSON . stringify ( input ) }], so we cannot decide whether a preimage exists for the hash.` ) ; } return this . constructDecision ( preimage , input . hash , true ) ; } param preimage param hash param outcome returns private constructDecision ( preimage , hash , outcome ) { return { outcome , justification : [ { implication : { decider : this , input : { hash , } , } , implicationWitness : { preimage , } , } , ] , } ; } }