mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 09:20:08 +00:00
27 lines
524 B
TypeScript
27 lines
524 B
TypeScript
import { Buffer } from 'node:buffer'
|
|
import nacl from 'tweetnacl'
|
|
|
|
export function verifySignature ({
|
|
publicKey,
|
|
signature,
|
|
timestamp,
|
|
body
|
|
}: VerifySignatureOptions): {
|
|
isValid: boolean
|
|
body: string
|
|
} {
|
|
const isValid = nacl.sign.detached.verify(
|
|
Buffer.from(timestamp + body),
|
|
Buffer.from(signature, 'hex'),
|
|
Buffer.from(publicKey, 'hex')
|
|
)
|
|
|
|
return { isValid, body }
|
|
}
|
|
export interface VerifySignatureOptions {
|
|
publicKey: string
|
|
signature: string
|
|
timestamp: string
|
|
body: string
|
|
}
|