import { blake2b256 } from "thor-devkit" ; export function newFilter ( bits , k ) { const nBits = bits . length * 8 ; return { contains ( key ) { let hash = blake2b256 ( key ) . readUInt32BE ( 0 ) ; const delta = ( hash >>> 17 ) | ( hash << 15 >>> 0 ) ; for ( let i = 0 ; i < k ; i ++ ) { const bitPos = hash % nBits ; const index = bitPos >>> 3 ; const bit = 1 << ( bitPos % 8 ) ; if ( ! ( bits [ index ] & bit ) ) { return false ; } hash = ( hash + delta ) >>> 0 ; } return true ; } } ; }