From 6cf0ff3c3c860cdf786e58f861fa6c90607256aa Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Thu, 26 Oct 2023 10:49:39 -0700 Subject: [PATCH] Add createEvent and now --- package.json | 2 +- src/util/nostr.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8bc0740..918e76a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paravel", - "version": "0.3.7", + "version": "0.3.8", "description": "Yet another toolkit for nostr", "author": "hodlbod", "license": "MIT", diff --git a/src/util/nostr.ts b/src/util/nostr.ts index 3c0ccd2..506e798 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -2,6 +2,11 @@ import type {Event} from 'nostr-tools' import {verifySignature, getEventHash, matchFilter as nostrToolsMatchFilter} from 'nostr-tools' import {cached} from "./LRUCache" +// =========================================================================== +// General-purpose + +const now = () => Math.round(Date.now() / 1000) + // =========================================================================== // Relays @@ -44,6 +49,9 @@ export const toNostrURI = (s: string) => `nostr:${s}` // =========================================================================== // Events +export const createEvent = (kind: number, {content = "", tags = [], created_at = now()}) => + ({kind, content, tags, created_at}) + export const hasValidSignature = cached({ maxSize: 10000, getKey: ([e]: any[]) => [getEventHash(e), e.sig].join(":"),