fix: replace @noble/curves/secp256k1 dynamic import with nostr-tools finalizeEvent

@noble/curves v2 dropped the ./secp256k1 subpath export. The manual
getEventHash + schnorr.sign + bytesToHex pattern is replaced with
nostr-tools' finalizeEvent() which handles id computation and signing
internally, with no external subpath dependencies. Also removes the
now-unused getEventHash import and bytesToHex helper.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-06-15 22:28:45 +07:00
parent 0b4fc341a1
commit 540eeead2f

View file

@ -1,16 +1,12 @@
import { useCallback, useMemo } from 'react';
import { useNostr } from '@nostrify/react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { nip44, nip19, getEventHash, generateSecretKey, getPublicKey } from 'nostr-tools';
import { nip44, nip19, generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools';
import type { NostrEvent } from '@nostrify/nostrify';
import { useCurrentUser } from './useCurrentUser';
import { useAppContext } from './useAppContext';
// Uint8Array → hex string (replaces @noble/hashes/utils which dropped ./utils in v2)
const bytesToHex = (bytes: Uint8Array): string =>
Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
// NIP-17 Message Types
export interface DirectMessage {
id: string;
@ -143,26 +139,14 @@ export function useSendDirectMessage() {
);
const encryptedSeal = nip44.v2.encrypt(sealJson, conversationKey);
// Create gift wrap event
const giftWrap: NostrEvent = {
id: '',
// Create gift wrap event and sign with ephemeral key
return finalizeEvent({
pubkey: ephemeralPubkey,
created_at: randomPastTimestamp(),
kind: GIFT_WRAP_KIND,
tags: [['p', targetPubkey]],
content: encryptedSeal,
sig: '',
};
// Calculate ID and sign with ephemeral key
giftWrap.id = getEventHash(giftWrap);
// Sign with ephemeral secret key using nostr-tools
const { schnorr } = await import('@noble/curves/secp256k1');
const sig = schnorr.sign(giftWrap.id, ephemeralSecretKey);
giftWrap.sig = bytesToHex(sig);
return giftWrap;
}, ephemeralSecretKey) as NostrEvent;
};
// 3. Create gift wraps for all recipients AND sender (so sender sees own messages)