@ocap/resolver 1.31.9 → 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/esm/_virtual/rolldown_runtime.mjs +7 -0
- package/esm/api.d.mts +33 -5
- package/esm/api.mjs +939 -53
- package/esm/dashboard.d.mts +199 -0
- package/esm/dashboard.mjs +2481 -0
- package/esm/explorer.d.mts +29 -0
- package/esm/explorer.mjs +227 -0
- package/esm/follower.d.mts +277 -0
- package/esm/follower.mjs +2428 -0
- package/esm/hooks.mjs +1 -1
- package/esm/hotstuff-runtime.d.mts +271 -0
- package/esm/hotstuff-runtime.mjs +2668 -0
- package/esm/index.d.mts +79 -4
- package/esm/index.mjs +911 -174
- package/esm/node-preferences.d.mts +203 -0
- package/esm/node-preferences.mjs +1021 -0
- package/esm/replayer.d.mts +74 -0
- package/esm/replayer.mjs +394 -0
- package/esm/token-distribution.mjs +2 -2
- package/esm/token-flow.mjs +1 -1
- package/esm/types.d.mts +25 -2
- package/lib/api.cjs +941 -52
- package/lib/api.d.cts +33 -5
- package/lib/dashboard.cjs +2491 -0
- package/lib/dashboard.d.cts +199 -0
- package/lib/explorer.cjs +227 -0
- package/lib/explorer.d.cts +29 -0
- package/lib/follower.cjs +2434 -0
- package/lib/follower.d.cts +277 -0
- package/lib/hooks.cjs +1 -1
- package/lib/hotstuff-runtime.cjs +2671 -0
- package/lib/hotstuff-runtime.d.cts +271 -0
- package/lib/index.cjs +945 -174
- package/lib/index.d.cts +79 -4
- package/lib/node-preferences.cjs +1043 -0
- package/lib/node-preferences.d.cts +203 -0
- package/lib/replayer.cjs +395 -0
- package/lib/replayer.d.cts +74 -0
- package/lib/token-distribution.cjs +2 -2
- package/lib/token-flow.cjs +1 -1
- package/lib/types.d.cts +25 -2
- package/package.json +20 -14
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Request, RequestHandler, Response } from "express";
|
|
2
|
+
import { TNodeRole, TNodeWritePolicy } from "@ocap/types";
|
|
3
|
+
|
|
4
|
+
//#region src/node-preferences.d.ts
|
|
5
|
+
|
|
6
|
+
declare const MAX_BLOCKED_ACCOUNTS = 5000;
|
|
7
|
+
declare const MAX_TRUSTED_ACCOUNTS = 1000;
|
|
8
|
+
declare const MAX_RESERVED_SYMBOLS = 500;
|
|
9
|
+
declare const MAX_PEER_URLS = 32;
|
|
10
|
+
declare const MAX_MEMO_LENGTH = 256;
|
|
11
|
+
declare const MAX_CONFIG_BODY_BYTES: number;
|
|
12
|
+
type TPreferenceSource = 'env' | 'static' | 'preferences';
|
|
13
|
+
interface IBlockedAccountEntry {
|
|
14
|
+
address: string;
|
|
15
|
+
memo?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ITrustedAccountEntry {
|
|
18
|
+
address: string;
|
|
19
|
+
tolerance?: number;
|
|
20
|
+
memo?: string;
|
|
21
|
+
}
|
|
22
|
+
interface IReservedSymbolEntry {
|
|
23
|
+
symbol: string;
|
|
24
|
+
memo?: string;
|
|
25
|
+
}
|
|
26
|
+
interface ILedgerHealthThresholds {
|
|
27
|
+
checkpointLag: number;
|
|
28
|
+
checkpointAgeMs: number;
|
|
29
|
+
unfinalizedAgeMs: number;
|
|
30
|
+
}
|
|
31
|
+
interface INodeRuntimePreferences {
|
|
32
|
+
writePolicy?: TNodeWritePolicy;
|
|
33
|
+
txMaxRequest?: number;
|
|
34
|
+
pollIntervalMs?: number;
|
|
35
|
+
maxSyncLag?: number;
|
|
36
|
+
peerUrls?: string[];
|
|
37
|
+
healthThresholds?: Partial<ILedgerHealthThresholds>;
|
|
38
|
+
}
|
|
39
|
+
interface INodePreferencesFileSchema {
|
|
40
|
+
version?: number;
|
|
41
|
+
updatedAt?: string;
|
|
42
|
+
blockedAccounts?: Array<string | IBlockedAccountEntry>;
|
|
43
|
+
trustedAccounts?: Array<string | ITrustedAccountEntry>;
|
|
44
|
+
reservedSymbols?: Array<string | IReservedSymbolEntry>;
|
|
45
|
+
runtime?: INodeRuntimePreferences;
|
|
46
|
+
}
|
|
47
|
+
interface IAttributedBlockedAccount extends IBlockedAccountEntry {
|
|
48
|
+
source: TPreferenceSource;
|
|
49
|
+
mutable: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface IAttributedTrustedAccount extends ITrustedAccountEntry {
|
|
52
|
+
source: TPreferenceSource;
|
|
53
|
+
mutable: boolean;
|
|
54
|
+
}
|
|
55
|
+
interface IAttributedReservedSymbol extends IReservedSymbolEntry {
|
|
56
|
+
source: TPreferenceSource;
|
|
57
|
+
mutable: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface INodePreferencesSnapshot {
|
|
60
|
+
preferencesPath: string | null;
|
|
61
|
+
updatedAt: string | null;
|
|
62
|
+
blockedAccounts: IAttributedBlockedAccount[];
|
|
63
|
+
trustedAccounts: IAttributedTrustedAccount[];
|
|
64
|
+
reservedSymbols: IAttributedReservedSymbol[];
|
|
65
|
+
runtime: INodeRuntimePreferences;
|
|
66
|
+
}
|
|
67
|
+
interface ILegacyPreferencesResult {
|
|
68
|
+
reservedSymbols: IReservedSymbolEntry[];
|
|
69
|
+
trustedAccounts: ITrustedAccountEntry[];
|
|
70
|
+
blockedAccounts: IBlockedAccountEntry[];
|
|
71
|
+
}
|
|
72
|
+
declare class NodePreferencesError extends Error {
|
|
73
|
+
readonly code: string;
|
|
74
|
+
readonly status: number;
|
|
75
|
+
constructor(code: string, message: string, status?: number);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Constant-time token comparison over fixed-width SHA-256 digests so secret length is never leaked.
|
|
79
|
+
*/
|
|
80
|
+
declare function timingSafeTokenEqual(expected: unknown, provided: unknown): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Normalize DID / 0x / did:name address keys identically to HTTP `/blocked` lookup.
|
|
83
|
+
*/
|
|
84
|
+
declare function normalizeBlockedAccountKey(raw: unknown): string;
|
|
85
|
+
declare function isValidAccountAddressCandidate(raw: unknown): raw is string;
|
|
86
|
+
declare function isPrivateOrReservedIpAddress(rawIp: string): boolean;
|
|
87
|
+
type DnsLookupAllFn = (hostname: string) => Promise<Array<{
|
|
88
|
+
address: string;
|
|
89
|
+
family: number;
|
|
90
|
+
}>>;
|
|
91
|
+
/**
|
|
92
|
+
* Validate Follower `peerUrls` for strict HTTP(S) base URL hygiene and SSRF / DNS-rebinding safety.
|
|
93
|
+
*/
|
|
94
|
+
declare function validateFollowerPeerUrls(rawUrls: unknown, env?: Record<string, string | undefined>, dnsLookup?: DnsLookupAllFn): Promise<string[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Connect-time SSRF & DNS-rebinding guard for Follower / LeaderRouter outbound `fetch()` calls.
|
|
97
|
+
* Static operator-configured origins (`UPSTREAM_CHAIN_URL` / `CLUSTER_PEER_URLS` / `HOTSTUFF_VALIDATORS` from boot env)
|
|
98
|
+
* are explicitly allowlisted; any dynamically configured `peerUrl` is re-verified on every request (defeating `TTL=0`
|
|
99
|
+
* DNS rebinding) and, for `http:` DNS hosts, connected directly to the verified public IP with an explicit `Host` header
|
|
100
|
+
* so no second DNS resolution occurs.
|
|
101
|
+
*/
|
|
102
|
+
declare function createFollowerPeerFetchGuard(options: {
|
|
103
|
+
env?: Record<string, string | undefined>;
|
|
104
|
+
dnsLookup?: DnsLookupAllFn;
|
|
105
|
+
trustedStaticUrls?: Array<string | undefined | null>;
|
|
106
|
+
baseFetch?: typeof fetch;
|
|
107
|
+
}): typeof fetch;
|
|
108
|
+
/**
|
|
109
|
+
* Safely apply persisted `preferences.json` runtime overrides at node startup without crashing
|
|
110
|
+
* when `updateRuntimeConfig` is synchronous (`void`), while filtering role-inapplicable keys
|
|
111
|
+
* and validating Follower `peerUrls` against SSRF / DNS-rebinding rules.
|
|
112
|
+
*/
|
|
113
|
+
declare function applyBootRuntimePreferences(params: {
|
|
114
|
+
runtime?: {
|
|
115
|
+
role?: TNodeRole;
|
|
116
|
+
updateRuntimeConfig?: (patch: INodeRuntimePreferences) => Promise<void> | void;
|
|
117
|
+
} | null;
|
|
118
|
+
preferencesManager: NodePreferencesManager;
|
|
119
|
+
env?: Record<string, string | undefined>;
|
|
120
|
+
dnsLookup?: DnsLookupAllFn;
|
|
121
|
+
logger?: {
|
|
122
|
+
warn?: (...args: unknown[]) => void;
|
|
123
|
+
};
|
|
124
|
+
}): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Backward-compatible helper used by standalone chain startup (`loadPreferences(dataDir?)`).
|
|
127
|
+
* Unions immutable `CHAIN_*` env baseline with `<dataDir>/preferences.json` (when `dataDir` is passed)
|
|
128
|
+
* or `CHAIN_PREFERENCES_PATH` so an empty `preferences.json` array never wipes out env rules.
|
|
129
|
+
*/
|
|
130
|
+
declare function loadNodePreferences(dataDir?: string, env?: Record<string, string | undefined>): ILegacyPreferencesResult;
|
|
131
|
+
interface NodePreferencesManagerOptions {
|
|
132
|
+
dataDir?: string;
|
|
133
|
+
preferencesPath?: string;
|
|
134
|
+
env?: Record<string, string | undefined>;
|
|
135
|
+
staticBlockedAddresses?: string[];
|
|
136
|
+
baseReservedSymbols?: string[];
|
|
137
|
+
getNodeRole?: () => TNodeRole;
|
|
138
|
+
getConsensusMode?: () => 'single' | 'hotstuff';
|
|
139
|
+
dnsLookup?: DnsLookupAllFn;
|
|
140
|
+
onApply?: (snapshot: INodePreferencesSnapshot, meta: {
|
|
141
|
+
changedRuntimeKeys: string[];
|
|
142
|
+
requiresRestart: boolean;
|
|
143
|
+
}) => Promise<void> | void;
|
|
144
|
+
}
|
|
145
|
+
interface IUpdateNodePreferencesInput {
|
|
146
|
+
blockedAccounts?: Array<string | IBlockedAccountEntry>;
|
|
147
|
+
trustedAccounts?: Array<string | ITrustedAccountEntry>;
|
|
148
|
+
reservedSymbols?: Array<string | IReservedSymbolEntry>;
|
|
149
|
+
runtime?: INodeRuntimePreferences;
|
|
150
|
+
}
|
|
151
|
+
interface IUpdateNodePreferencesResult {
|
|
152
|
+
snapshot: INodePreferencesSnapshot;
|
|
153
|
+
requiresRestart: boolean;
|
|
154
|
+
changedRuntimeKeys: string[];
|
|
155
|
+
}
|
|
156
|
+
declare class NodePreferencesManager {
|
|
157
|
+
private readonly env;
|
|
158
|
+
private readonly preferencesPath;
|
|
159
|
+
private readonly staticBlockedAddresses;
|
|
160
|
+
private readonly baseReservedSymbols;
|
|
161
|
+
private readonly getNodeRoleFn;
|
|
162
|
+
private readonly getConsensusModeFn;
|
|
163
|
+
private readonly dnsLookup;
|
|
164
|
+
private onApplyFn?;
|
|
165
|
+
private fileState;
|
|
166
|
+
private snapshotCache;
|
|
167
|
+
private normalizedBlockedKeySet;
|
|
168
|
+
private normalizedReservedSymbolSet;
|
|
169
|
+
private writeChain;
|
|
170
|
+
constructor(options?: NodePreferencesManagerOptions);
|
|
171
|
+
setOnApply(fn: NodePreferencesManagerOptions['onApply']): void;
|
|
172
|
+
getPreferencesPath(): string | null;
|
|
173
|
+
reloadFromDiskSync(): INodePreferencesSnapshot;
|
|
174
|
+
reload(): Promise<INodePreferencesSnapshot>;
|
|
175
|
+
getSnapshot(): INodePreferencesSnapshot;
|
|
176
|
+
getBlockedAddresses(): string[];
|
|
177
|
+
getTrustedAccounts(): ITrustedAccountEntry[];
|
|
178
|
+
getEffectiveHealthThresholds(): ILedgerHealthThresholds;
|
|
179
|
+
isBlocked(address: string): boolean;
|
|
180
|
+
isReservedSymbol(symbol: string): boolean;
|
|
181
|
+
update(input: IUpdateNodePreferencesInput): Promise<IUpdateNodePreferencesResult>;
|
|
182
|
+
private atomicWritePreferencesFile;
|
|
183
|
+
private rebuildEffectiveSnapshot;
|
|
184
|
+
}
|
|
185
|
+
interface AdminAuthGuardOptions {
|
|
186
|
+
env?: Record<string, string | undefined>;
|
|
187
|
+
windowMs?: number;
|
|
188
|
+
maxFailedAttemptsPerIp?: number;
|
|
189
|
+
maxTrackedIps?: number;
|
|
190
|
+
}
|
|
191
|
+
interface IAdminAuthGuard {
|
|
192
|
+
isConfigured: () => boolean;
|
|
193
|
+
isAuthenticatedRequest: (req: Request) => boolean;
|
|
194
|
+
checkOptionalAdmin?: (req: Request, res: Response) => 'admin' | 'anonymous' | 'rate_limited';
|
|
195
|
+
requireAdmin: RequestHandler;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Constant-time SHA-256 admin auth guard with bounded per-IP failed-attempt rate limiting
|
|
199
|
+
* and CSRF Content-Type / custom-header enforcement on state-mutating methods.
|
|
200
|
+
*/
|
|
201
|
+
declare function createAdminAuthGuard(options?: AdminAuthGuardOptions): IAdminAuthGuard;
|
|
202
|
+
//#endregion
|
|
203
|
+
export { AdminAuthGuardOptions, DnsLookupAllFn, IAdminAuthGuard, IAttributedBlockedAccount, IAttributedReservedSymbol, IAttributedTrustedAccount, IBlockedAccountEntry, ILedgerHealthThresholds, ILegacyPreferencesResult, INodePreferencesFileSchema, INodePreferencesSnapshot, INodeRuntimePreferences, IReservedSymbolEntry, ITrustedAccountEntry, IUpdateNodePreferencesInput, IUpdateNodePreferencesResult, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, NodePreferencesError, NodePreferencesManager, NodePreferencesManagerOptions, TPreferenceSource, applyBootRuntimePreferences, createAdminAuthGuard, createFollowerPeerFetchGuard, isPrivateOrReservedIpAddress, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|