| |
| |
| |
| |
|
|
|
|
| import { createHash, createPublicKey, verify } from "crypto";
|
|
|
| |
| |
|
|
| export function sha256(data: Buffer): string {
|
| return createHash("sha256").update(data).digest("hex");
|
| }
|
|
|
| |
| |
|
|
| export function verifySha256(data: Buffer, expectedHash: string): boolean {
|
| const actual = sha256(data);
|
| return actual === expectedHash;
|
| }
|
|
|
| |
| |
|
|
| export function verifyEd25519(data: Buffer, signature: Buffer, publicKeyDer: Buffer): boolean {
|
| try {
|
| const key = createPublicKey(publicKeyDer);
|
| return verify(null, data, key, signature);
|
| } catch {
|
| return false;
|
| }
|
| }
|
|
|