import { CONSENSUS, MAX_TARGET, NETWORK } from './testnet.ts'; import { NETWORK_GENESIS_TIME } from './network.ts'; export type ChainIdentity = { chainId: string; genesis: string }; let identity: Promise | undefined; /** Derive the same public manifest as the node from this immutable browser build. */ export function expectedChainIdentity(): Promise { if (!identity) identity = (async () => { const digestHex = async (value: string) => Array.from(new Uint8Array(await crypto.subtle.digest( 'SHA-256', new TextEncoder().encode(value))), byte => byte.toString(16).padStart(2, '0')).join(''); const chainId = await digestHex(JSON.stringify([NETWORK, CONSENSUS, NETWORK_GENESIS_TIME, MAX_TARGET])); return { chainId, genesis: await digestHex(`${NETWORK}:genesis:${chainId}`) }; })(); return identity; }