nappup 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +0,0 @@
1
- import { schnorr } from '@noble/curves/secp256k1.js'
2
- import { sha256 } from '@noble/hashes/sha2.js'
3
- import { bytesToBase16, base16ToBytes } from '#helpers/base16.js'
4
- import { getPublicKey } from 'nostr-tools/pure'
5
-
6
- function serializeEvent (event) {
7
- return JSON.stringify([
8
- 0,
9
- event.pubkey,
10
- event.created_at,
11
- event.kind,
12
- event.tags,
13
- event.content
14
- ])
15
- }
16
-
17
- function getEventHash (event) {
18
- return sha256(new TextEncoder().encode(serializeEvent(event)))
19
- }
20
-
21
- function getSignature (eventHash, privkey) {
22
- return bytesToBase16(schnorr.sign(eventHash, privkey))
23
- }
24
-
25
- export function finalizeEvent (event, privkey, withSig = true) {
26
- event.pubkey ??= getPublicKey(privkey)
27
- const eventHash = event.id ? base16ToBytes(event.id) : getEventHash(event)
28
- event.id ??= bytesToBase16(eventHash)
29
- if (withSig) event.sig ??= getSignature(eventHash, privkey)
30
- else delete event.sig
31
- return event
32
- }