| 34 | * Result is the same regardless of which party computes it: conv(a, B) == conv(b, A) |
| 35 | */ |
| 36 | export function getConversationKey(privateKeyHex: string, publicKeyHex: string): Buffer { |
| 37 | // ECDH: unhashed 32-byte x coordinate of the shared point |
| 38 | const shared = secp256k1.getSharedSecret(privateKeyHex, `02${publicKeyHex}`, true) |
| 39 | const sharedX = Buffer.from(shared).subarray(1) // strip 0x02 prefix |
| 40 | |
| 41 | return hkdfExtract(Buffer.from('nip44-v2'), sharedX) |
| 42 | } |
| 43 | |
| 44 | function getMessageKeys( |
| 45 | conversationKey: Buffer, |