cleanup interaction helper

This commit is contained in:
Skillz4Killz
2021-10-12 16:15:16 +00:00
committed by GitHub
parent 2f971f511f
commit 1eca62df55
3 changed files with 1 additions and 2 deletions
@@ -0,0 +1,27 @@
export { verify } from "https://unpkg.com/@evan/wasm@0.0.65/target/ed25519/deno.js";
import { verify } from "./deps.ts";
export function verifySignature({ publicKey, signature, timestamp, body }: VerifySignatureOptions): {
isValid: boolean;
body: string;
} {
const isValid = verify(
hexToUint8Array(publicKey),
hexToUint8Array(signature),
new TextEncoder().encode(timestamp + body)
);
return { isValid, body };
}
/** Converts a hexadecimal string to Uint8Array. */
function hexToUint8Array(hex: string) {
return new Uint8Array(hex.match(/.{1,2}/g)!.map((val) => parseInt(val, 16)));
}
export interface VerifySignatureOptions {
publicKey: string;
signature: string;
timestamp: string;
body: string;
}