Add createEvent and now

This commit is contained in:
Jon Staab
2023-10-26 10:49:39 -07:00
parent 77dc2144d3
commit 6cf0ff3c3c
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "paravel",
"version": "0.3.7",
"version": "0.3.8",
"description": "Yet another toolkit for nostr",
"author": "hodlbod",
"license": "MIT",
+8
View File
@@ -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(":"),