Add a Go HTTP API with Ed25519 auth and invitation onboarding, user-scoped GeoJSON Point management, a Bun-tested @noble/ed25519 TypeScript client, static Vue/Vuetify frontend integration, and a Gitea CI workflow running both Go and Bun test suites. Made-with: Cursor
25 lines
843 B
TypeScript
25 lines
843 B
TypeScript
import { getPublicKeyAsync, signAsync } from "@noble/ed25519";
|
|
import { base64UrlToBytes, bytesToBase64Url, textToBytes } from "./encoding";
|
|
import type { StoredKeys } from "./types";
|
|
|
|
function randomPrivateKey(): Uint8Array {
|
|
const out = new Uint8Array(32);
|
|
crypto.getRandomValues(out);
|
|
return out;
|
|
}
|
|
|
|
export async function generateKeyPair(): Promise<StoredKeys> {
|
|
const privateKey = randomPrivateKey();
|
|
const publicKey = await getPublicKeyAsync(privateKey);
|
|
return {
|
|
publicKey: bytesToBase64Url(publicKey),
|
|
privateKey: bytesToBase64Url(privateKey),
|
|
};
|
|
}
|
|
|
|
export async function signMessage(privateKeyBase64: string, message: string): Promise<string> {
|
|
const privateKey = base64UrlToBytes(privateKeyBase64);
|
|
const signature = await signAsync(textToBytes(message), privateKey);
|
|
return bytesToBase64Url(signature);
|
|
}
|