Skip to content

Commit db6b6f9

Browse files
committed
resolve typescript buffer-to-uint8array type mismatches
1 parent 6c82d8b commit db6b6f9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils/event.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const isEventMatchingFilter = (filter: SubscriptionFilter) => (event: Eve
105105
}
106106

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

110110
return Buffer.from(id).toString('hex')
111111
}
@@ -162,15 +162,15 @@ export const encryptKind4Event = (
162162
receiverPubkey: Pubkey,
163163
) => (event: UnsignedEvent): UnsignedEvent => {
164164
const key = secp256k1
165-
.getSharedSecret(senderPrivkey, `02${receiverPubkey}`, true)
165+
.getSharedSecret(typeof senderPrivkey === 'string' ? senderPrivkey : new Uint8Array(senderPrivkey), `02${receiverPubkey}`, true)
166166
.subarray(1)
167167

168168
const iv = getRandomValues(new Uint8Array(16))
169169

170170
// deepcode ignore InsecureCipherNoIntegrity: NIP-04 Encrypted Direct Message uses aes-256-cbc
171171
const cipher = createCipheriv(
172172
'aes-256-cbc',
173-
Buffer.from(key),
173+
new Uint8Array(key),
174174
iv,
175175
)
176176

0 commit comments

Comments
 (0)