Working version Reviewed-on: WikiDeck/wikideck#21
This commit is contained in:
2026-11-01 22:07:51 +00:00
parent 1edf2e6200
commit 636f5b9c77
80 changed files with 4065 additions and 549 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;
}