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:
parent
0b4fc341a1
commit
540eeead2f
1 changed files with 4 additions and 20 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue