crosscode: scripts/products/website.sh (ports 5300/3300, uploads in the export), crosscode add <church> website (needs Accounts; www.<address> or the Cross Code address), one install_app for Accounts and the Website, env template copy, bats tests. Backend: Hub client (protocol v2, product website), crosscode.link/1 with automatic connect to the church's Accounts, sign-in through @crosscode/auth-client with the Website's own session and roles, the first Owner from HUB_ADMIN_EMAIL (verified), 2FA for Owners and Admins, back-channel logout, Accounts' user.* calls, and the church export. Frontend: admin sign-in/out and the sign-in problem page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.7 KiB
TypeScript
35 lines
1.7 KiB
TypeScript
/**
|
|
* This install's Ed25519 key pair and the church's other installs as the Hub last listed them
|
|
* (as Cross Events 2.4's links/store.ts). Settings: hub_private_key (encrypted), hub_public_key,
|
|
* hub_linked_products.
|
|
*/
|
|
import { hub } from '@crosscode/contracts';
|
|
import { ed25519PublicToPem, generateEd25519 } from '@crosscode/contracts/signing';
|
|
import type { Ctx } from '../context.js';
|
|
|
|
type LinkedProduct = hub.LinkedProduct;
|
|
|
|
export async function keyPair(ctx: Ctx): Promise<{ publicKeyPem: string; privateKeyPem: string }> {
|
|
const [priv, pub] = await Promise.all([ctx.settings.get('hub_private_key'), ctx.settings.get('hub_public_key')]);
|
|
if (priv && pub) return { privateKeyPem: priv, publicKeyPem: pub };
|
|
const pair = generateEd25519();
|
|
const publicKeyPem = ed25519PublicToPem(pair.publicKey);
|
|
await ctx.settings.setMany({ hub_private_key: pair.privateKeyPem, hub_public_key: publicKeyPem });
|
|
return { privateKeyPem: pair.privateKeyPem, publicKeyPem };
|
|
}
|
|
|
|
export async function linkedProducts(ctx: Ctx): Promise<LinkedProduct[]> {
|
|
const list = await ctx.settings.json<unknown[]>('hub_linked_products', []);
|
|
return Array.isArray(list) ? (list.filter((l) => hub.linkedProductSchema.safeParse(l).success) as LinkedProduct[]) : [];
|
|
}
|
|
|
|
export async function saveLinkedProducts(ctx: Ctx, list: unknown): Promise<void> {
|
|
if (!Array.isArray(list)) return;
|
|
const clean = list.map((l) => hub.linkedProductSchema.safeParse(l)).filter((r) => r.success).map((r) => r.data).slice(0, 10);
|
|
await ctx.settings.set('hub_linked_products', JSON.stringify(clean));
|
|
}
|
|
|
|
export async function listedProduct(ctx: Ctx, installId: string): Promise<LinkedProduct | null> {
|
|
return (await linkedProducts(ctx)).find((l) => l.installId === installId) ?? null;
|
|
}
|