Files
backend/libs/geo-api-client/src/keys.ts
Andriy Oblivantsev ef3957b618
CI / test (push) Successful in 4s
Demo app, collections/features CRUD, QR codes, docs
Demo app (web/):
- Collections: select, rename, remove (x button per row), delete
- Features: add point (lon/lat validation), remove, list in selected collection
- QR codes for pk (private) and pb (public) keys
- Restore public key from private key
- 409 Conflict handled for already-registered login
- Title: Momswap Geo Backend Use-Cases Test

Backend:
- PATCH /v1/collections/{id} for rename
- DELETE /v1/collections/{id}
- Clearer lon/lat validation errors (-180..180, -90..90)

Client:
- updateCollection, deleteCollection, derivePublicKey

Docs:
- docs/frontend-development.md (demo app, local dev)
- README links to all docs

Made-with: Cursor
2026-03-01 13:41:54 +00:00

31 lines
1.1 KiB
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 getPublicKeyFromPrivate(privateKeyBase64: string): Promise<string> {
const privateKey = base64UrlToBytes(privateKeyBase64);
const publicKey = await getPublicKeyAsync(privateKey);
return bytesToBase64Url(publicKey);
}
export async function signMessage(privateKeyBase64: string, message: string): Promise<string> {
const privateKey = base64UrlToBytes(privateKeyBase64);
const signature = await signAsync(textToBytes(message), privateKey);
return bytesToBase64Url(signature);
}