mirror of
https://github.com/selfxyz/self.git
synced 2026-02-21 03:00:36 -05:00
Co-authored-by: seshanthS <seshanth@protonmail.com> Co-authored-by: turnoffthiscomputer <colin.remi07@gmail.com> Co-authored-by: thomas-senechal <thomas.senechal@pm.me> Co-authored-by: motemotech <i.am.nicoshark@gmail.com> Co-authored-by: turnoffthiscomputer <98749896+remicolin@users.noreply.github.com> Co-authored-by: ayman <aymanshaik1015@gmail.com>
16 lines
517 B
TypeScript
16 lines
517 B
TypeScript
import { randomBytes, toBigInt, toBeHex, zeroPadValue } from "ethers";
|
|
|
|
export function generateRandomFieldElement(): string {
|
|
const FIELD_PRIME = BigInt(
|
|
"21888242871839275222246405745257275088696311157297823662689037894645226208583"
|
|
);
|
|
|
|
const fieldElement = zeroPadValue(toBeHex(toBigInt(randomBytes(32)) % FIELD_PRIME), 32);
|
|
|
|
return fieldElement;
|
|
}
|
|
|
|
export function getStartOfDayTimestamp(timestamp: number): number {
|
|
const dayInSeconds = 86400;
|
|
return timestamp - (timestamp % dayInSeconds);
|
|
} |