remove buffer usage everywhere.

This commit is contained in:
fiatjaf
2022-12-21 16:04:09 -03:00
parent 41a1614d89
commit 89ae21f796
3 changed files with 12 additions and 12 deletions

View File

@@ -1,8 +1,8 @@
import {Buffer} from 'buffer'
// @ts-ignore
import * as secp256k1 from '@noble/secp256k1'
import {sha256} from '@noble/hashes/sha256'
import {utf8Encoder} from './utils'
export type Event = {
id?: string
sig?: string
@@ -35,8 +35,8 @@ export function serializeEvent(evt: Event): string {
}
export function getEventHash(event: Event): string {
let eventHash = sha256(Buffer.from(serializeEvent(event)))
return Buffer.from(eventHash).toString('hex')
let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)))
return secp256k1.utils.bytesToHex(eventHash)
}
export function validateEvent(event: Event): boolean {
@@ -63,7 +63,7 @@ export function verifySignature(
}
export async function signEvent(event: Event, key: string): Promise<string> {
return Buffer.from(
return secp256k1.utils.bytesToHex(
await secp256k1.schnorr.sign(event.id || getEventHash(event), key)
).toString('hex')
)
}