UNPKG

@waku/rln

Version:

RLN (Rate Limiting Nullifier) implementation for Waku

23 lines 882 B
import { Logger } from "@waku/utils"; const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds const log = new Logger("waku:rln:epoch"); export function dateToEpoch(timestamp, epochUnitSeconds = DefaultEpochUnitSeconds) { const time = timestamp.getTime(); const epoch = Math.floor(time / 1000 / epochUnitSeconds); log.info("generated epoch", epoch); return epoch; } export function epochIntToBytes(epoch) { const bytes = new Uint8Array(32); const db = new DataView(bytes.buffer); db.setUint32(0, epoch, true); log.info("encoded epoch", epoch, bytes); return bytes; } export function epochBytesToInt(bytes) { const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); const epoch = dv.getUint32(0, true); log.info("decoded epoch", epoch, bytes); return epoch; } //# sourceMappingURL=epoch.js.map