V2.1 (#21)
Working version Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
Executable
+16
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user