Mainnet
This commit is contained in:
+30
-5
@@ -1,16 +1,41 @@
|
||||
/** Selection is fixed at server startup / browser build, never learned from an untrusted RPC. */
|
||||
export type NetworkProfile = 'testnet' | 'mainnet';
|
||||
export function networkProfile(value: string | undefined): NetworkProfile {
|
||||
const profile = value ?? 'testnet';
|
||||
const profile = value ?? 'mainnet';
|
||||
if (profile !== 'testnet' && profile !== 'mainnet') {
|
||||
throw new Error('WIKIDECK_NETWORK must be testnet or mainnet');
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
export const PROFILE = networkProfile(typeof process !== 'undefined' && process.versions?.node
|
||||
const isNodeRuntime = typeof process !== 'undefined' && !!process.versions?.node;
|
||||
export const PROFILE = networkProfile(isNodeRuntime
|
||||
? process.env.WIKIDECK_NETWORK : import.meta.env?.VITE_WIKIDECK_NETWORK);
|
||||
export const IS_MAINNET = PROFILE === 'mainnet';
|
||||
export const NETWORK = IS_MAINNET ? 'wikideck-randomx-mainnet-1' as const : 'wikideck-randomx-testnet-6' as const;
|
||||
// Candidate mainnet genesis: 2027-01-01 00:00 UTC. NOT a commitment to a launch date.
|
||||
export const NETWORK_GENESIS_TIME = IS_MAINNET ? 1_798_761_600 : 1_792_411_200;
|
||||
export const NETWORK_LABEL = IS_MAINNET ? 'MAINNET CANDIDATE' : 'TESTNET';
|
||||
const TESTNET_GENESIS_TIME = 1_792_411_200;
|
||||
const DEFAULT_MAINNET_GENESIS_TIME = 1_798_761_600; // 2027-01-01 UTC candidate; deployment must freeze one value.
|
||||
function genesisTime(raw: string | undefined, profile: NetworkProfile): number {
|
||||
const value = raw ?? String(profile === 'mainnet' ? DEFAULT_MAINNET_GENESIS_TIME : TESTNET_GENESIS_TIME);
|
||||
if (!/^(0|[1-9]\d{8,10})$/.test(value)) throw new Error('WIKIDECK_GENESIS_TIME must be a canonical Unix-seconds integer');
|
||||
const parsed = Number(value);
|
||||
if (!Number.isSafeInteger(parsed) || parsed < 1_700_000_000 || parsed > 4_102_444_800) {
|
||||
throw new Error('WIKIDECK_GENESIS_TIME is outside the supported range');
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
export const NETWORK_GENESIS_TIME = genesisTime(isNodeRuntime
|
||||
? process.env.WIKIDECK_GENESIS_TIME : import.meta.env?.VITE_WIKIDECK_GENESIS_TIME, PROFILE);
|
||||
if (isNodeRuntime) {
|
||||
const imageProfile = process.env.WIKIDECK_IMAGE_NETWORK;
|
||||
const imageGenesisTime = process.env.WIKIDECK_IMAGE_GENESIS_TIME;
|
||||
if (imageProfile !== undefined && imageProfile !== PROFILE) {
|
||||
throw new Error('Runtime network profile does not match the immutable image manifest');
|
||||
}
|
||||
if (imageGenesisTime !== undefined && Number(imageGenesisTime) !== NETWORK_GENESIS_TIME) {
|
||||
throw new Error('Runtime genesis time does not match the immutable image manifest');
|
||||
}
|
||||
if (imageGenesisTime !== undefined && !/^(0|[1-9]\d{8,10})$/.test(imageGenesisTime)) {
|
||||
throw new Error('Image genesis time manifest is malformed');
|
||||
}
|
||||
}
|
||||
export const NETWORK_LABEL = IS_MAINNET ? 'MAINNET' : 'TESTNET';
|
||||
|
||||
Reference in New Issue
Block a user