import { blake2bResetForShortMessage , blake2bCompress , Context } from "./blake2b/blake2b64" ; const CHALLENGE_SIZE_BYTES = 128 ; const HASH_SIZE_BYTES = 32 ; param input param threshold export function solveBlake2bEfficient ( input , threshold , n ) { if ( input . length != CHALLENGE_SIZE_BYTES ) { throw new Error ( "Invalid input" ) ; } const arrayPtr = changetype < usize > ( input ) ; const bufferPtr = load < u32 > ( arrayPtr ) ; const ctx = new Context ( HASH_SIZE_BYTES ) ; const h = ctx . h ; ctx . t = CHALLENGE_SIZE_BYTES ; const start = load < u32 > ( bufferPtr + 124 ) ; const end = start + n ; for ( let i = start ; i < end ; i ++ ) { store < u32 > ( bufferPtr + 124 , i ) ; blake2bResetForShortMessage ( ctx ) ; blake2bCompress ( ctx , true , bufferPtr ) ; if ( ( unchecked ( h [ 0 ] ) as u32 ) < threshold ) { return Uint8Array . wrap ( h . buffer ) ; } } return new Uint8Array ( 0 ) ; }