From 540eeead2fdd2663d302fffa2318fde8def42fcc Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Mon, 15 Jun 2026 22:28:45 +0700 Subject: [PATCH] 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 --- src/hooks/useDirectMessages.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/hooks/useDirectMessages.ts b/src/hooks/useDirectMessages.ts index d3598cf..621bd27 100644 --- a/src/hooks/useDirectMessages.ts +++ b/src/hooks/useDirectMessages.ts @@ -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)