@ocap/chain-node 0.0.0-stage → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -2
- package/esm/access-log.d.mts +34 -0
- package/esm/access-log.mjs +71 -0
- package/esm/env.d.mts +32 -0
- package/esm/env.mjs +218 -0
- package/esm/index.d.mts +5 -0
- package/esm/index.mjs +5 -0
- package/esm/standalone-env.d.mts +39 -0
- package/esm/standalone-env.mjs +71 -0
- package/esm/start-chain-node.d.mts +14 -0
- package/esm/start-chain-node.mjs +1102 -0
- package/esm/test-hooks-token.d.mts +12 -0
- package/esm/test-hooks-token.mjs +21 -0
- package/esm/testing.d.mts +13 -0
- package/esm/testing.mjs +23 -0
- package/esm/types.d.mts +293 -0
- package/esm/types.mjs +1 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/access-log.cjs +73 -0
- package/lib/access-log.d.cts +34 -0
- package/lib/env.cjs +221 -0
- package/lib/env.d.cts +32 -0
- package/lib/index.cjs +13 -0
- package/lib/index.d.cts +5 -0
- package/lib/standalone-env.cjs +76 -0
- package/lib/standalone-env.d.cts +39 -0
- package/lib/start-chain-node.cjs +1112 -0
- package/lib/start-chain-node.d.cts +14 -0
- package/lib/test-hooks-token.cjs +24 -0
- package/lib/test-hooks-token.d.cts +12 -0
- package/lib/testing.cjs +23 -0
- package/lib/testing.d.cts +13 -0
- package/lib/types.cjs +0 -0
- package/lib/types.d.cts +293 -0
- package/package.json +78 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isValid } from "@arcblock/did";
|
|
2
|
+
|
|
3
|
+
//#region src/standalone-env.ts
|
|
4
|
+
/**
|
|
5
|
+
* Standalone (non-Blocklet-Server) env helpers shared by the chain apps (#1923, docs/ops/chain-env-mapping.md).
|
|
6
|
+
*
|
|
7
|
+
* Kept free of runtime imports beyond `@arcblock/did` so app key-derivation code can require this module
|
|
8
|
+
* (`@ocap/chain-node/lib/standalone-env.js`) without loading the node runtime.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Standalone replacement for the Blocklet Server app DID that seeds the trusted-storage wallet.
|
|
12
|
+
* Returns '' when unset/blank so callers fall back to BLOCKLET_APP_PID / BLOCKLET_APP_ID / moderator exactly as
|
|
13
|
+
* before. The subject is hashed as a raw string by `fromAppDid`, so a `did:abt:` prefix or a typo would silently
|
|
14
|
+
* yield a different trusted key: only a bare, valid DID address is accepted.
|
|
15
|
+
*/
|
|
16
|
+
function resolveTrustedSubject(env = process.env) {
|
|
17
|
+
const subject = String(env.CHAIN_TRUSTED_SUBJECT || "").trim();
|
|
18
|
+
if (!subject) return "";
|
|
19
|
+
if (/^did:/i.test(subject) || !isValid(subject)) throw new Error("Invalid CHAIN_TRUSTED_SUBJECT: must be a bare DID address (no \"did:abt:\" prefix)");
|
|
20
|
+
return subject;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Standalone-only replacements for Blocklet Server variables. Blocklet Server sets none of them on beta or main
|
|
24
|
+
* (checked against both live process envs), so seeing one means the operator runs (or migrates to) a standalone
|
|
25
|
+
* env file. `CHAIN_VAULT_PSK` is deliberately not a marker: main's blocklet.yml declares it, so it is present there.
|
|
26
|
+
*/
|
|
27
|
+
const STANDALONE_ENV_MARKERS = [
|
|
28
|
+
"CHAIN_DATA_DIR",
|
|
29
|
+
"CHAIN_PORT",
|
|
30
|
+
"CHAIN_SK",
|
|
31
|
+
"CHAIN_MODERATOR_PK",
|
|
32
|
+
"CHAIN_TRUSTED_SUBJECT"
|
|
33
|
+
];
|
|
34
|
+
/** Blocklet Server variables both chain apps still read as fallbacks behind a CHAIN_* variable. */
|
|
35
|
+
const BLOCKLET_ENV_CHAIN_FALLBACKS = new Set([
|
|
36
|
+
"BLOCKLET_APP_ASK",
|
|
37
|
+
"BLOCKLET_APP_DIR",
|
|
38
|
+
"BLOCKLET_APP_ID",
|
|
39
|
+
"BLOCKLET_APP_PID",
|
|
40
|
+
"BLOCKLET_APP_PK",
|
|
41
|
+
"BLOCKLET_APP_PPK",
|
|
42
|
+
"BLOCKLET_APP_PSK",
|
|
43
|
+
"BLOCKLET_APP_SK",
|
|
44
|
+
"BLOCKLET_DATA_DIR",
|
|
45
|
+
"BLOCKLET_PORT"
|
|
46
|
+
]);
|
|
47
|
+
/**
|
|
48
|
+
* Detect a standalone env that still carries Blocklet Server variables, so two key sources are never mixed
|
|
49
|
+
* silently. Returns null under Blocklet Server (no standalone marker) and for a clean standalone env.
|
|
50
|
+
* Only variable names are returned, never values.
|
|
51
|
+
*/
|
|
52
|
+
function findBlockletEnvLeftovers(env = process.env, { readByChain = BLOCKLET_ENV_CHAIN_FALLBACKS } = {}) {
|
|
53
|
+
const isSet = (k) => String(env[k] ?? "").trim() !== "";
|
|
54
|
+
const standaloneMarkers = STANDALONE_ENV_MARKERS.filter(isSet);
|
|
55
|
+
if (!standaloneMarkers.length) return null;
|
|
56
|
+
const leftovers = Object.keys(env).filter((k) => /^(BLOCKLET_|ABT_NODE_)/.test(k) && isSet(k)).sort();
|
|
57
|
+
if (!leftovers.length) return null;
|
|
58
|
+
const read = new Set(readByChain);
|
|
59
|
+
return {
|
|
60
|
+
standaloneMarkers,
|
|
61
|
+
leftovers,
|
|
62
|
+
readByChain: leftovers.filter((k) => read.has(k))
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function formatBlockletEnvLeftoversWarning({ standaloneMarkers, leftovers, readByChain }) {
|
|
66
|
+
const read = readByChain.length ? ` ${readByChain.join(", ")} still feed key/path fallbacks when the CHAIN_* equivalent is unset.` : "";
|
|
67
|
+
return `[chain] standalone env (${standaloneMarkers.join(", ")}) also carries Blocklet Server variables: ${leftovers.join(", ")}.${read} Remove them so CHAIN_* is the only source (docs/ops/chain-env-mapping.md, #1923)`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { BLOCKLET_ENV_CHAIN_FALLBACKS, STANDALONE_ENV_MARKERS, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, resolveTrustedSubject };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChainNodeTestHooks, ChainProfile, RunningChainNode, StartChainNodeOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/start-chain-node.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Boot a unified OCAP chain node (`validator`, `follower`, or `hotstuff`) with a 12-step LIFO rollback guard
|
|
7
|
+
* and 9-step reverse graceful shutdown (`docs/chain-node-design.md` §2.3–§2.4).
|
|
8
|
+
*/
|
|
9
|
+
declare function startChainNode(options: StartChainNodeOptions): Promise<RunningChainNode>;
|
|
10
|
+
declare function startChainNode(profile: ChainProfile & {
|
|
11
|
+
testHooks?: ChainNodeTestHooks;
|
|
12
|
+
}): Promise<RunningChainNode>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { startChainNode };
|