mirror of https://github.com/waku-org/js-rln.git
Merge pull request #34 from waku-org/chores/log-proof
This commit is contained in:
commit
6ecdc598d5
|
@ -10,7 +10,7 @@ import {
|
|||
import { RlnMessage, toRLNSignal } from "./message.js";
|
||||
import { MembershipKey, RLNInstance } from "./rln.js";
|
||||
|
||||
const log = debug("waku:message:rln-encoder");
|
||||
const log = debug("waku:rln:encoder");
|
||||
|
||||
export class RLNEncoder implements Encoder {
|
||||
public contentTopic: string;
|
||||
|
@ -30,7 +30,7 @@ export class RLNEncoder implements Encoder {
|
|||
async toWire(message: Partial<Message>): Promise<Uint8Array | undefined> {
|
||||
message.contentTopic = this.contentTopic;
|
||||
message.rateLimitProof = await this.generateProof(message);
|
||||
|
||||
log("Proof generated", message.rateLimitProof);
|
||||
return this.encoder.toWire(message);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ export class RLNEncoder implements Encoder {
|
|||
if (!protoMessage) return;
|
||||
|
||||
protoMessage.rateLimitProof = await this.generateProof(message);
|
||||
|
||||
log("Proof generated", message.rateLimitProof);
|
||||
return protoMessage;
|
||||
}
|
||||
|
||||
|
|
13
src/epoch.ts
13
src/epoch.ts
|
@ -1,21 +1,30 @@
|
|||
import debug from "debug";
|
||||
|
||||
const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
|
||||
|
||||
const log = debug("waku:rln:epoch");
|
||||
|
||||
export function dateToEpoch(
|
||||
timestamp: Date,
|
||||
epochUnitSeconds: number = DefaultEpochUnitSeconds
|
||||
): number {
|
||||
const time = timestamp.getTime();
|
||||
return Math.floor(time / 1000 / epochUnitSeconds);
|
||||
const epoch = Math.floor(time / 1000 / epochUnitSeconds);
|
||||
log("generated epoch", epoch);
|
||||
return epoch;
|
||||
}
|
||||
|
||||
export function epochIntToBytes(epoch: number): Uint8Array {
|
||||
const bytes = new Uint8Array(32);
|
||||
const db = new DataView(bytes.buffer);
|
||||
db.setUint32(0, epoch, true);
|
||||
log("encoded epoch", epoch, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export function epochBytesToInt(bytes: Uint8Array): number {
|
||||
const dv = new DataView(bytes.buffer);
|
||||
return dv.getUint32(0, true);
|
||||
const epoch = dv.getUint32(0, true);
|
||||
log("decoded epoch", epoch, bytes);
|
||||
return epoch;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue