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", "name": "paravel",
"version": "0.3.7", "version": "0.3.8",
"description": "Yet another toolkit for nostr", "description": "Yet another toolkit for nostr",
"author": "hodlbod", "author": "hodlbod",
"license": "MIT", "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 {verifySignature, getEventHash, matchFilter as nostrToolsMatchFilter} from 'nostr-tools'
import {cached} from "./LRUCache" import {cached} from "./LRUCache"
// ===========================================================================
// General-purpose
const now = () => Math.round(Date.now() / 1000)
// =========================================================================== // ===========================================================================
// Relays // Relays
@@ -44,6 +49,9 @@ export const toNostrURI = (s: string) => `nostr:${s}`
// =========================================================================== // ===========================================================================
// Events // Events
export const createEvent = (kind: number, {content = "", tags = [], created_at = now()}) =>
({kind, content, tags, created_at})
export const hasValidSignature = cached({ export const hasValidSignature = cached({
maxSize: 10000, maxSize: 10000,
getKey: ([e]: any[]) => [getEventHash(e), e.sig].join(":"), getKey: ([e]: any[]) => [getEventHash(e), e.sig].join(":"),