This commit is contained in:
2026-10-29 11:45:51 -04:00
parent b3a1179703
commit b427fa4217
35 changed files with 469 additions and 158 deletions
+16
View File
@@ -0,0 +1,16 @@
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<ChainIdentity> | undefined;
/** Derive the same public manifest as the node from this immutable browser build. */
export function expectedChainIdentity(): Promise<ChainIdentity> {
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;
}