Skip to content

Commit c907642

Browse files
committed
fix: resolve typescript buffer-to-uint8array type mismatches
Fixes #444
1 parent 12688ec commit c907642

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
@@ -103,7 +103,7 @@ export const isEventMatchingFilter = (filter: SubscriptionFilter) => (event: Eve
103103
}
104104

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

108108
return Buffer.from(id).toString('hex')
109109
}
@@ -160,15 +160,15 @@ export const encryptKind4Event = (
160160
receiverPubkey: Pubkey,
161161
) => (event: UnsignedEvent): UnsignedEvent => {
162162
const key = secp256k1
163-
.getSharedSecret(senderPrivkey, `02${receiverPubkey}`, true)
163+
.getSharedSecret(typeof senderPrivkey === 'string' ? senderPrivkey : new Uint8Array(senderPrivkey), `02${receiverPubkey}`, true)
164164
.subarray(1)
165165

166166
const iv = getRandomValues(new Uint8Array(16))
167167

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

0 commit comments

Comments
 (0)