/**
* App identity + storage namespace, the two things this app owns.
*
* APP_SALT namespaces every cryptographic derivation — two apps with identical
* room secrets never meet. NS namespaces every persistent browser store
* (localStorage keys, IndexedDB databases) so two apps built on the same p2p
* template can share an origin without sharing identity seeds, TOFU bindings,
* or block stores. Override with VITE_STORAGE_NS only if you need a specific
* prefix.
*
* OrbitDB's per-room directory is NOT namespaced here: it embeds the roomId,
* which is already salt-derived and therefore fork-unique (lib/log.ts).
*/
import type { RelayConfig } from "./lib/descriptor";
export const APP_SALT: string = import.meta.env.VITE_APP_SALT ?? "cautpartener.ro/v1";
export const NS: string = import.meta.env.VITE_STORAGE_NS ?? "cautpartener";
/** localStorage key inside this app's namespace, e.g. nsKey("id") → "<ns>:id". */
export const nsKey = (k: string): string => `${NS}:${k}`;
/** IndexedDB database name inside this app's namespace, e.g. nsDb("blocks"). */
export const nsDb = (d: string): string => `${NS}-${d}`;
/**
* Baked-in relay/mailbox FALLBACKS. Boot always asks the relay host's
* /.well-known/ap2p descriptor first (probeRelay in main.ts, single fetch)
* so the operator can rotate the PeerId, TURN endpoint or mailbox without a
* client release; these values only win when that fetch fails (offline,
* captive portal, static IPFS mirror without the relay reachable).
*/
export const RELAY_DEFAULTS: RelayConfig = {
relayMultiaddr:
import.meta.env.VITE_RELAY_MULTIADDR ??
"/dns4/signal.cautpartener.ro/tcp/443/tls/ws/p2p/12D3KooWKqgi6jXB9yrrXJ6zC1iNodRNJDHNrssKD1xrYeGzshcV",
turnCredsUrl: import.meta.env.VITE_TURN_CREDS_URL ?? "https://signal.cautpartener.ro/turn-credentials",
discoveryTopic: import.meta.env.VITE_DISCOVERY_TOPIC ?? "_peer-discovery._p2p._pubsub",
mailbox: {
baseUrl: import.meta.env.VITE_MAILBOX_URL ?? "https://signal.cautpartener.ro/mailbox/v1",
credsUrl: import.meta.env.VITE_MAILBOX_CREDS_URL ?? "https://signal.cautpartener.ro/mailbox-credentials",
maxMessageKb: 64,
},
};
/**
* Server-side limits the UI must respect. DEFAULTS ONLY — the real values are
* read from the /.well-known/ap2p descriptor at boot (main.ts) and updated
* here; UI logic must always read this store, never hardcode 168/64.
*/
export const RuntimeLimits: { ttlHours: number; maxMessageKb: number } = {
ttlHours: 168,
maxMessageKb: 64,
};
export function updateRuntimeLimits(patch: Partial<typeof RuntimeLimits>): void {
if (typeof patch.ttlHours === "number" && patch.ttlHours > 0) RuntimeLimits.ttlHours = patch.ttlHours;
if (typeof patch.maxMessageKb === "number" && patch.maxMessageKb > 0) RuntimeLimits.maxMessageKb = patch.maxMessageKb;
}