Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const isEventMatchingFilter = (filter: SubscriptionFilter) => (event: Eve
}

export const getEventHash = async (event: Event | UnidentifiedEvent | UnsignedEvent): Promise<string> => {
const id = await secp256k1.utils.sha256(Buffer.from(JSON.stringify(serializeEvent(event))))
const id = await secp256k1.utils.sha256(new Uint8Array(Buffer.from(JSON.stringify(serializeEvent(event)))))

return Buffer.from(id).toString('hex')
}
Expand Down Expand Up @@ -160,15 +160,15 @@ export const encryptKind4Event = (
receiverPubkey: Pubkey,
) => (event: UnsignedEvent): UnsignedEvent => {
const key = secp256k1
.getSharedSecret(senderPrivkey, `02${receiverPubkey}`, true)
.getSharedSecret(typeof senderPrivkey === 'string' ? senderPrivkey : new Uint8Array(senderPrivkey), `02${receiverPubkey}`, true)
.subarray(1)

const iv = getRandomValues(new Uint8Array(16))

// deepcode ignore InsecureCipherNoIntegrity: NIP-04 Encrypted Direct Message uses aes-256-cbc
const cipher = createCipheriv(
'aes-256-cbc',
Buffer.from(key),
new Uint8Array(key),
iv,
)

Expand Down