@tamga-network/onboard 0.0.0-stage → 0.8.3
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/LICENSE +190 -0
- package/README.md +160 -2
- package/lib/application.d.ts +116 -0
- package/lib/application.d.ts.map +1 -0
- package/lib/application.js +262 -0
- package/lib/application.js.map +1 -0
- package/lib/checks.d.ts +124 -0
- package/lib/checks.d.ts.map +1 -0
- package/lib/checks.js +1028 -0
- package/lib/checks.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +515 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/keys.d.ts +116 -0
- package/lib/keys.d.ts.map +1 -0
- package/lib/keys.js +274 -0
- package/lib/keys.js.map +1 -0
- package/lib/mcp.d.ts +240 -0
- package/lib/mcp.d.ts.map +1 -0
- package/lib/mcp.js +459 -0
- package/lib/mcp.js.map +1 -0
- package/lib/network.d.ts +22 -0
- package/lib/network.d.ts.map +1 -0
- package/lib/network.js +37 -0
- package/lib/network.js.map +1 -0
- package/lib/node.d.ts +200 -0
- package/lib/node.d.ts.map +1 -0
- package/lib/node.js +931 -0
- package/lib/node.js.map +1 -0
- package/lib/paths.d.ts +12 -0
- package/lib/paths.d.ts.map +1 -0
- package/lib/paths.js +60 -0
- package/lib/paths.js.map +1 -0
- package/lib/rules.d.ts +65 -0
- package/lib/rules.d.ts.map +1 -0
- package/lib/rules.js +357 -0
- package/lib/rules.js.map +1 -0
- package/package.json +47 -4
package/lib/node.js
ADDED
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tamga-onboard node` — devletin / işletmecinin Besu düğümü için katılım adımları (ADR-0052, ARCH-0002 §6 ve §10). Zincire, izin
|
|
3
|
+
* listesine ve ağa YAZMAZ; düğüme yalnız okuyan JSON-RPC çağrıları gönderir.
|
|
4
|
+
*
|
|
5
|
+
* init düğüm anahtarı (secp256k1, Besu `key` biçimi: `0x` + 64 onaltılık) BU bilgisayarda üretilir; özel anahtar dosyası
|
|
6
|
+
* keys komutunun korumalarıyla yazılır (yalnız sahibi; Windows'ta icacls; bulut eşitleme klasörü reddi; üzerine yazmama).
|
|
7
|
+
* enode açık anahtarı ve validator adresi (Keccak-256 → son 20 bayt) türetilir; Besu yapılandırma şablonu (izinli kip,
|
|
8
|
+
* RPC yalnız loopback, P2P yalnız belirli iç arayüz — 0.0.0.0 değil) ve genesis yönergesi yazılır.
|
|
9
|
+
* declare `tamga-node-declaration/1` bildirimi (network/permissions şeması; kişisel veri yok, iletişim kurumun görev adresi).
|
|
10
|
+
* check kurumun KENDİ düğümüne karşı salt-okur denetimler (operatörün düğüm denetim listesinin dışarıdan / yerelden
|
|
11
|
+
* yapılabilenleri). Hiçbir durum değiştiren yöntem çağrılmaz (oy, izin yükleme, eş ekleme, işlem yok).
|
|
12
|
+
* Uç adresleri yalnız kullanıcının verdiği adreslerdir (dosyadan adres okunmaz; besu.toml'dan yalnız loopback RPC portu türetilir).
|
|
13
|
+
*/
|
|
14
|
+
import { createECDH } from "node:crypto";
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { request as httpRequest } from "node:http";
|
|
17
|
+
import { request as httpsRequest } from "node:https";
|
|
18
|
+
import { isIP } from "node:net";
|
|
19
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
20
|
+
import { clean, isPrivateAddress } from "./checks.js";
|
|
21
|
+
import { syncedFolder, writePrivateKey } from "./keys.js";
|
|
22
|
+
import { realResolve, within } from "./paths.js";
|
|
23
|
+
// ───────────────────────────── anahtar ─────────────────────────────
|
|
24
|
+
export const NODE_DECLARATION_FORMAT = "tamga-node-declaration/1";
|
|
25
|
+
const hex = (b) => Buffer.from(b).toString("hex");
|
|
26
|
+
/** secp256k1 özel anahtarından (32 bayt) enode açık anahtarı (128 onaltılık, 04 öneki yok) ve adres (0x + 40 onaltılık). */
|
|
27
|
+
export function nodeIdentity(privateKey) {
|
|
28
|
+
if (privateKey.length !== 32)
|
|
29
|
+
throw new Error("düğüm anahtarı 32 bayt olmalı");
|
|
30
|
+
const e = createECDH("secp256k1");
|
|
31
|
+
e.setPrivateKey(Buffer.from(privateKey)); // aralık dışı (0 ya da ≥ n) → hata
|
|
32
|
+
const pub = e.getPublicKey(); // 65 bayt, 04 || x || y
|
|
33
|
+
return { publicKey: hex(pub.subarray(1)), address: nodeAddressOf(hex(pub.subarray(1))) };
|
|
34
|
+
}
|
|
35
|
+
/** Açık anahtardan düğüm adresi (QBFT doğrulayıcı adresi = düğüm anahtarının adresi; ADR-0052 K2 eşleşme kuralı). */
|
|
36
|
+
export function nodeAddressOf(publicKeyHex) {
|
|
37
|
+
const k = normalizePublicKey(publicKeyHex);
|
|
38
|
+
if (!k)
|
|
39
|
+
throw new Error("açık anahtar 128 onaltılık karakter olmalı");
|
|
40
|
+
return "0x" + hex(keccak_256(Buffer.from(k, "hex")).subarray(12));
|
|
41
|
+
}
|
|
42
|
+
/** `0x`, `04` öneki ve büyük harf kabul edilir; şemanın biçimine (128 küçük onaltılık) çevrilir. Geçersizse null. */
|
|
43
|
+
export function normalizePublicKey(s) {
|
|
44
|
+
let k = String(s ?? "")
|
|
45
|
+
.trim()
|
|
46
|
+
.toLowerCase()
|
|
47
|
+
.replace(/^0x/, "");
|
|
48
|
+
if (k.length === 130 && k.startsWith("04"))
|
|
49
|
+
k = k.slice(2);
|
|
50
|
+
return /^[0-9a-f]{128}$/.test(k) ? k : null;
|
|
51
|
+
}
|
|
52
|
+
/** Yeni düğüm anahtarı: 32 rastgele bayt (Node'un CSPRNG'si), Besu `key` dosyası biçimi. */
|
|
53
|
+
export function generateNodeKey() {
|
|
54
|
+
const e = createECDH("secp256k1");
|
|
55
|
+
e.generateKeys();
|
|
56
|
+
const d = Buffer.alloc(32);
|
|
57
|
+
const raw = e.getPrivateKey();
|
|
58
|
+
raw.copy(d, 32 - raw.length);
|
|
59
|
+
const id = nodeIdentity(d);
|
|
60
|
+
const keyFile = "0x" + d.toString("hex");
|
|
61
|
+
d.fill(0);
|
|
62
|
+
return { keyFile, ...id };
|
|
63
|
+
}
|
|
64
|
+
/** Besu enode URL'si (IPv6 köşeli parantezde). */
|
|
65
|
+
export const enodeOf = (publicKey, ip, port) => `enode://${publicKey}@${ip.includes(":") ? `[${ip.toLowerCase()}]` : ip}:${port}`;
|
|
66
|
+
/** `0x7099…79c8` — raporda adres kısaltılır. */
|
|
67
|
+
export const shortAddr = (a) => (a.length > 12 ? `${a.slice(0, 6)}…${a.slice(-4)}` : a);
|
|
68
|
+
// ───────────────────────────── adres kuralları ─────────────────────────────
|
|
69
|
+
const IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
|
|
70
|
+
const IPV6 = /^[0-9a-f:]+$/i;
|
|
71
|
+
/** Bildirim şemasıyla aynı: IPv4 değişmezi ya da (noktasız) IPv6 değişmezi. */
|
|
72
|
+
export const ipLiteralOk = (ip) => typeof ip === "string" && (IPV4.test(ip) || (ip.includes(":") && IPV6.test(ip) && isIP(ip) === 6));
|
|
73
|
+
const UNSPECIFIED = (ip) => ip === "0.0.0.0" || /^(0*:)*:?0*$/.test(ip) || ip === "::";
|
|
74
|
+
/** Yerel / özel ağ adresi — belgeleme aralıkları (192.0.2/24, 198.51.100/24, 203.0.113/24, 2001:db8::/32; örneklerde) hariç. */
|
|
75
|
+
const unreachable = (ip) => isPrivateAddress(ip) && !/^(192\.0\.2|198\.51\.100|203\.0\.113)\./.test(ip) && !/^2001:0?db8:/i.test(ip);
|
|
76
|
+
export const isLoopback = (ip) => /^127\./.test(ip) || ip === "::1" || /^::ffff:127\./i.test(ip) || ip.toLowerCase() === "localhost";
|
|
77
|
+
const portOk = (n) => Number.isInteger(n) && n >= 1 && n <= 65535;
|
|
78
|
+
export const STATE_RE = /^[A-Z]{2}$/;
|
|
79
|
+
const NAME_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
80
|
+
const PROFILE_KEYS = ["state", "role", "node_public_key", "address", "ip", "interface", "p2p_port", "rpc_port"];
|
|
81
|
+
export function validateNodeInit(i) {
|
|
82
|
+
const p = [];
|
|
83
|
+
const w = [];
|
|
84
|
+
if (typeof i.state !== "string" || !STATE_RE.test(i.state))
|
|
85
|
+
p.push("state: iki büyük harf (Governance üye kodu, ör. TR)");
|
|
86
|
+
if (i.role !== "validator" && i.role !== "rpc")
|
|
87
|
+
p.push("role: validator | rpc");
|
|
88
|
+
if (!ipLiteralOk(i.ip))
|
|
89
|
+
p.push("ip: ilan edilen P2P adresi, IPv4 ya da IPv6 değişmezi (DNS adı değil)");
|
|
90
|
+
else if (UNSPECIFIED(i.ip))
|
|
91
|
+
p.push("ip: 0.0.0.0 / :: ilan edilemez — eşlerin bağlanacağı gerçek adres");
|
|
92
|
+
else if (unreachable(i.ip))
|
|
93
|
+
w.push(`ip ${i.ip} yerel / özel ağ adresi: yalnız yerel denemede ya da işletmecilerin ortak özel ağında çalışır; başka işletmecinin düğümü bu adrese ulaşamayabilir`);
|
|
94
|
+
const itf = i.interface ?? i.ip;
|
|
95
|
+
if (!ipLiteralOk(itf))
|
|
96
|
+
p.push("interface: P2P'nin dinleyeceği iç arayüzün adresi (IPv4 / IPv6 değişmezi)");
|
|
97
|
+
else if (UNSPECIFIED(itf))
|
|
98
|
+
p.push("interface: 0.0.0.0 / :: kabul edilmez — P2P bütün arayüzlerde dinlemez; yalnız eşlerin geldiği iç arayüzün adresi (p2p-interface)");
|
|
99
|
+
for (const [n, v] of [
|
|
100
|
+
["p2p-port", i.p2pPort ?? 30303],
|
|
101
|
+
["rpc-port", i.rpcPort ?? 8545],
|
|
102
|
+
])
|
|
103
|
+
if (!portOk(v))
|
|
104
|
+
p.push(`${n}: 1–65535`);
|
|
105
|
+
if ((i.p2pPort ?? 30303) === (i.rpcPort ?? 8545))
|
|
106
|
+
p.push("p2p-port ile rpc-port aynı olamaz");
|
|
107
|
+
return { problems: p, warnings: w };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Besu yapılandırma şablonu. Ağa bağlanma bilgisi (static-nodes, genesis, izin listesi) işletmecilerden gelir; yollar düğüm
|
|
111
|
+
* klasörüne göredir (TOML'da ileri eğik çizgi). Kesin kurallar: RPC yalnız 127.0.0.1 (LP5; dışarıya network/rpc-proxy mTLS +
|
|
112
|
+
* eth/net/web3 süzgeci), P2P yalnız belirli iç arayüzde (0.0.0.0 değil — `p2p-host` yalnız ilan edilen adrestir, dinlenen arayüzü
|
|
113
|
+
* `p2p-interface` belirler; ikisi ayrı ayarlanmazsa Besu bütün arayüzlerde dinler), keşif kapalı (statik eşler), iki izin bayrağı
|
|
114
|
+
* açık (LP1), WebSocket / GraphQL kapalı.
|
|
115
|
+
*/
|
|
116
|
+
export function besuTomlTemplate(dir, p) {
|
|
117
|
+
const f = (name) => `${realResolve(dir).replace(/\\/g, "/")}/${name}`;
|
|
118
|
+
return `# Tamga Network — Besu düğüm yapılandırması (şablon: tamga-onboard node init). ${p.state} · ${p.role}
|
|
119
|
+
# Kontrol: tamga-onboard node check --config besu.toml. Ayrıntı: ARCH-0002 §6, ADR-0052.
|
|
120
|
+
# genesis.json, static-nodes.json ve permissions_config.toml bu araçla üretilmez (aşağıdaki yorumlar).
|
|
121
|
+
|
|
122
|
+
data-path="${f("data")}"
|
|
123
|
+
# genesis.json: ağın işletmecilerinden alınır, sha256 özeti en az iki işletmeciyle bant dışı karşılaştırılır
|
|
124
|
+
genesis-file="${f("genesis.json")}"
|
|
125
|
+
# özel anahtar: yalnız bu makinede, yalnız sahibine okunur; yedeği şifreli ve çevrimdışı
|
|
126
|
+
node-private-key-file="${f("key")}"
|
|
127
|
+
|
|
128
|
+
# P2P — ilan edilen adres (bildirimdeki ip) ve DİNLENEN arayüz ayrı ayrı. p2p-interface 0.0.0.0 OLMAZ: yalnız eşlerin geldiği
|
|
129
|
+
# iç arayüz. Güvenlik duvarında P2P portu yalnız izin listesindeki eşlerin IP'lerine açık.
|
|
130
|
+
p2p-host="${p.ip}"
|
|
131
|
+
p2p-interface="${p.interface}"
|
|
132
|
+
p2p-port=${p.p2p_port}
|
|
133
|
+
discovery-enabled=false
|
|
134
|
+
# static-nodes.json: işletmecilerin verdiği validator enode'ları (enode://<anahtar>@<ip>:<port>)
|
|
135
|
+
static-nodes-file="${f("static-nodes.json")}"
|
|
136
|
+
|
|
137
|
+
# JSON-RPC — YALNIZ 127.0.0.1. QBFT / PERM / ADMIN yalnız bu makineden (oy, izin listesi yükleme). Dışarıya yalnız ETH, NET, WEB3:
|
|
138
|
+
# nginx (TLS 1.3 + zorunlu istemci sertifikası) → yöntem süzgeci (network/rpc-proxy/filter.mjs) → bu uç.
|
|
139
|
+
rpc-http-enabled=true
|
|
140
|
+
rpc-http-host="127.0.0.1"
|
|
141
|
+
rpc-http-port=${p.rpc_port}
|
|
142
|
+
rpc-http-api=["ETH","NET","WEB3","QBFT","PERM","ADMIN"]
|
|
143
|
+
host-allowlist=["localhost","127.0.0.1"]
|
|
144
|
+
rpc-ws-enabled=false
|
|
145
|
+
graphql-http-enabled=false
|
|
146
|
+
min-gas-price=0
|
|
147
|
+
|
|
148
|
+
# Yerel izinlendirme (ADR-0052 K1): iki liste de açık, aynı dosya. Dosya ELLE YAZILMAZ — zincirden üretilir:
|
|
149
|
+
# npm run trust:chain-permissions -- render --operator ${p.state} --out permissions_config.rendered.toml
|
|
150
|
+
# sonra kopyalanır ve perm_reloadPermissionsFromFile (yalnız 127.0.0.1) ile yüklenir; trust:chain-permissions check denetler.
|
|
151
|
+
permissions-nodes-config-file-enabled=true
|
|
152
|
+
permissions-nodes-config-file="${f("permissions_config.toml")}"
|
|
153
|
+
permissions-accounts-config-file-enabled=true
|
|
154
|
+
permissions-accounts-config-file="${f("permissions_config.toml")}"
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
/** `node init` sonrasında yapılacaklar (genesis yönergesi dahil). */
|
|
158
|
+
export function nodeNextSteps(p) {
|
|
159
|
+
return [
|
|
160
|
+
"Genesis bu araçla üretilmez ve indirilmez: ağın genesis.json dosyasını katılım yazışmasında bildirilen kanaldan, ağın işletmecilerinden alın; sha256 özetini en az iki ayrı işletmeciyle başka bir kanaldan karşılaştırın — özet aynı değilse düğümü başlatmayın. Düğüm çalışınca `node check --chain-rpc <işletmecinin ucu>` genesis blok özetini de karşılaştırır.",
|
|
161
|
+
"Gerçek Tamga zinciri bugün kurulu değildir (ikinci bağımsız işletmeci ve eşik olmadan kurulmaz); bu adımlar hazırlık ve yerel deneme içindir.",
|
|
162
|
+
`Bildirim: tamga-onboard node declare <klasör> --contact <kurumun görev adresi> → operatöre gönderin (özel anahtar ASLA gönderilmez).${p.role === "validator" ? ` Governance'a bildirilecek validator adresi: ${p.address}.` : ""}`,
|
|
163
|
+
"static-nodes.json: işletmecilerin verdiği validator enode'larıyla yazın (keşif kapalıdır).",
|
|
164
|
+
`İzin listesi: trust:chain-permissions render --operator ${p.state} ile zincirden üretilir; elle yazılmaz.`,
|
|
165
|
+
"RPC'yi dışarı açmayın; dış okuma gerekiyorsa network/rpc-proxy (nginx mTLS + eth/net/web3 süzgeci).",
|
|
166
|
+
"Düğüm başlayınca: tamga-onboard node check <klasör> [--chain-rpc <ağdaki bir uç>] [--public-rpc <dış uç>] [--permissions-file <çizim>]",
|
|
167
|
+
p.role === "validator"
|
|
168
|
+
? "Validator olmak: önce tam düğüm olarak eşleşip senkron olun; ekleme oyunu mevcut validator'lar kendi düğümlerinde verir (bu araç oy vermez)."
|
|
169
|
+
: "RPC düğümü yalnız sizin izin listenize girer (render --operator); öteki işletmecilerin listesine girmez.",
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Düğüm klasörünü yazar: `key` (özel anahtar; yalnız sahibi), `key.pub`, `node.json`, `besu.toml`, `.gitignore`. Dosyalardan biri
|
|
174
|
+
* bile varsa hiçbiri yazılmaz. Bulut eşitleme klasöründe (OneDrive vb.) yalnız `allowSynced` ile. Ağa bağlanmaz.
|
|
175
|
+
*/
|
|
176
|
+
export function initNode(dir, i, o = {}) {
|
|
177
|
+
const v = validateNodeInit(i);
|
|
178
|
+
if (v.problems.length)
|
|
179
|
+
throw new Error(v.problems.join("; "));
|
|
180
|
+
const synced = syncedFolder(dir, o.env);
|
|
181
|
+
if (synced && !o.allowSynced)
|
|
182
|
+
throw new Error(`düğüm klasörü bulut eşitleme klasöründe (${synced}): düğüm anahtarı kurum dışındaki bir sunucuya kopyalanır — eşitlenmeyen bir klasör seçin (ya da bilerek --allow-synced)`);
|
|
183
|
+
const names = ["key", "key.pub", "node.json", "besu.toml"];
|
|
184
|
+
const clash = names.filter((f) => existsSync(within(dir, f)));
|
|
185
|
+
if (clash.length)
|
|
186
|
+
throw new Error(`zaten var (üzerine yazılmaz; yeni anahtar gerekiyorsa eski dosyaları kendiniz taşıyın): ${clash.join(", ")}`);
|
|
187
|
+
mkdirSync(dir, { recursive: true });
|
|
188
|
+
within(dir, "key"); // oluşturulduktan sonra da (bağ yarışı) klasörün içinde mi
|
|
189
|
+
const k = generateNodeKey();
|
|
190
|
+
const profile = {
|
|
191
|
+
state: i.state,
|
|
192
|
+
role: i.role,
|
|
193
|
+
node_public_key: k.publicKey,
|
|
194
|
+
address: k.address,
|
|
195
|
+
ip: i.ip,
|
|
196
|
+
interface: i.interface ?? i.ip,
|
|
197
|
+
p2p_port: i.p2pPort ?? 30303,
|
|
198
|
+
rpc_port: i.rpcPort ?? 8545,
|
|
199
|
+
};
|
|
200
|
+
const keyPath = within(dir, "key");
|
|
201
|
+
writePrivateKey(keyPath, k.keyFile, { platform: o.platform });
|
|
202
|
+
const w = (f, s) => writeFileSync(within(dir, f), s, { flag: "wx" });
|
|
203
|
+
w("key.pub", `0x${k.publicKey}\n`);
|
|
204
|
+
w("node.json", JSON.stringify(profile, null, 2) + "\n");
|
|
205
|
+
w("besu.toml", besuTomlTemplate(dir, profile));
|
|
206
|
+
const gi = within(dir, ".gitignore");
|
|
207
|
+
if (!existsSync(gi))
|
|
208
|
+
writeFileSync(gi, "# düğüm anahtarı ve zincir verisi depoya girmez\nkey\ndata/\n");
|
|
209
|
+
const warnings = [...v.warnings];
|
|
210
|
+
warnings.push("düğüm anahtarı yazılım anahtarıdır (Besu düğüm anahtarı dosyası parolayla şifrelenemez): dosya yalnız sahibine okunur — yedeği şifreli ve çevrimdışı tutun; kimseyle paylaşmayın");
|
|
211
|
+
if (synced)
|
|
212
|
+
warnings.push(`anahtar bulut eşitleme klasöründe (${synced}) — açık onayla yazıldı; eşitlemeyi kapatın`);
|
|
213
|
+
return {
|
|
214
|
+
dir,
|
|
215
|
+
key: keyPath,
|
|
216
|
+
files: names,
|
|
217
|
+
profile,
|
|
218
|
+
enode: enodeOf(profile.node_public_key, profile.ip, profile.p2p_port),
|
|
219
|
+
warnings,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/** Düğüm klasörünü okur (`node.json`; bilinmeyen alan ya da bozuk değer → hata). Özel anahtar okunmaz. */
|
|
223
|
+
export function readNodeDir(dir) {
|
|
224
|
+
const pf = within(dir, "node.json");
|
|
225
|
+
if (!existsSync(pf))
|
|
226
|
+
throw new Error(`${pf} yok — önce: tamga-onboard node init`);
|
|
227
|
+
let raw;
|
|
228
|
+
try {
|
|
229
|
+
raw = JSON.parse(readFileSync(pf, "utf8"));
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
throw new Error("node.json okunamadı (JSON değil)");
|
|
233
|
+
}
|
|
234
|
+
const bad = Object.keys(raw ?? {}).filter((k) => !PROFILE_KEYS.includes(k));
|
|
235
|
+
if (bad.length)
|
|
236
|
+
throw new Error(`node.json: bilinmeyen alan: ${bad.map(clean).join(", ")}`);
|
|
237
|
+
const v = validateNodeInit({
|
|
238
|
+
state: raw.state,
|
|
239
|
+
role: raw.role,
|
|
240
|
+
ip: raw.ip,
|
|
241
|
+
interface: raw.interface,
|
|
242
|
+
p2pPort: raw.p2p_port,
|
|
243
|
+
rpcPort: raw.rpc_port,
|
|
244
|
+
});
|
|
245
|
+
const pk = normalizePublicKey(raw.node_public_key);
|
|
246
|
+
if (!pk)
|
|
247
|
+
v.problems.push("node_public_key geçersiz");
|
|
248
|
+
else if (nodeAddressOf(pk) !== String(raw.address).toLowerCase())
|
|
249
|
+
v.problems.push("address açık anahtarla eşleşmiyor");
|
|
250
|
+
if (v.problems.length)
|
|
251
|
+
throw new Error(`node.json geçersiz: ${v.problems.join("; ")}`);
|
|
252
|
+
const profile = { ...raw, node_public_key: pk };
|
|
253
|
+
const cp = within(dir, "besu.toml");
|
|
254
|
+
if (!existsSync(cp))
|
|
255
|
+
return { profile };
|
|
256
|
+
return { profile, config: readToml(cp), configPath: cp };
|
|
257
|
+
}
|
|
258
|
+
const DECL_KEYS = ["$schema", "format", "state", "role", "node_public_key", "ip", "p2p_port", "contact"];
|
|
259
|
+
const CONTACT = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$|^https:\/\/[^\s]+$/i;
|
|
260
|
+
/** Kurumların görev posta kutularında sık görülen yerel bölümler (bunlar dışındaki e-postada uyarı: kişi adı olmasın) */
|
|
261
|
+
const ROLE_MAILBOX = /^(noc|soc|ops|operations?|operator|it|bt|bilgi-?islem|bidb|support|destek|help|helpdesk|info|bilgi|security|guvenlik|cert|csirt|sysadmin|admin|network|ag|blockchain|zincir|tamga|node|nodes|validator|contact|iletisim|kep|infra|altyapi)([._+-][a-z0-9]+)*$/i;
|
|
262
|
+
/**
|
|
263
|
+
* `tamga-node-declaration/1` doğrulaması — `network/permissions/schema/node-declaration.schema.json` ile aynı kurallar (test ikisini
|
|
264
|
+
* birlikte dener). Hata listesi boşsa geçerli.
|
|
265
|
+
*/
|
|
266
|
+
export function validateNodeDeclaration(x) {
|
|
267
|
+
const errs = [];
|
|
268
|
+
if (typeof x !== "object" || x === null || Array.isArray(x))
|
|
269
|
+
return ["nesne değil"];
|
|
270
|
+
const o = x;
|
|
271
|
+
for (const k of Object.keys(o))
|
|
272
|
+
if (!DECL_KEYS.includes(k))
|
|
273
|
+
errs.push(`bilinmeyen alan: ${clean(k)}`);
|
|
274
|
+
if (o.format !== NODE_DECLARATION_FORMAT)
|
|
275
|
+
errs.push(`format "${NODE_DECLARATION_FORMAT}" olmalı`);
|
|
276
|
+
if (typeof o.state !== "string" || !STATE_RE.test(o.state))
|
|
277
|
+
errs.push("state: iki büyük harf (ISO 3166-1)");
|
|
278
|
+
if (o.role !== "validator" && o.role !== "rpc")
|
|
279
|
+
errs.push("role: validator | rpc");
|
|
280
|
+
if (typeof o.node_public_key !== "string" || !/^[0-9a-f]{128}$/.test(o.node_public_key))
|
|
281
|
+
errs.push("node_public_key: 128 küçük onaltılık karakter (04 öneki ve 0x olmadan)");
|
|
282
|
+
if (typeof o.ip !== "string" || !ipLiteralOk(o.ip))
|
|
283
|
+
errs.push("ip: IPv4 ya da IPv6 değişmezi");
|
|
284
|
+
if (!portOk(o.p2p_port))
|
|
285
|
+
errs.push("p2p_port: 1–65535");
|
|
286
|
+
if (typeof o.contact !== "string" || o.contact.length > 254 || !CONTACT.test(o.contact))
|
|
287
|
+
errs.push("contact: kurumun görev e-postası ya da https adresi");
|
|
288
|
+
return errs;
|
|
289
|
+
}
|
|
290
|
+
/** Bildirimi kurar ve doğrular. Kişi adına benzeyen iletişim adresinde uyarı (görev adresi olmalı). */
|
|
291
|
+
export function buildNodeDeclaration(i) {
|
|
292
|
+
const pk = normalizePublicKey(i.node_public_key);
|
|
293
|
+
const contact = String(i.contact ?? "").trim();
|
|
294
|
+
const d = {
|
|
295
|
+
format: NODE_DECLARATION_FORMAT,
|
|
296
|
+
state: i.state,
|
|
297
|
+
role: i.role,
|
|
298
|
+
node_public_key: pk ?? String(i.node_public_key ?? ""),
|
|
299
|
+
ip: typeof i.ip === "string" ? i.ip.toLowerCase() : i.ip,
|
|
300
|
+
p2p_port: i.p2p_port,
|
|
301
|
+
contact,
|
|
302
|
+
};
|
|
303
|
+
const problems = validateNodeDeclaration(d);
|
|
304
|
+
const warnings = [];
|
|
305
|
+
if (!problems.length) {
|
|
306
|
+
if (UNSPECIFIED(d.ip))
|
|
307
|
+
problems.push("ip: 0.0.0.0 / :: ilan edilemez");
|
|
308
|
+
else if (unreachable(d.ip))
|
|
309
|
+
warnings.push(`ip ${d.ip} yerel / özel ağ adresi — yalnız yerel denemede ya da ortak özel ağda bağlanılabilir`);
|
|
310
|
+
const mail = /^(mailto:)?([^@]+)@/i.exec(contact)?.[2];
|
|
311
|
+
if (mail && !ROLE_MAILBOX.test(mail))
|
|
312
|
+
warnings.push(`iletişim "${clean(contact)}" bir görev posta kutusu gibi görünmüyor: kişi adı yazılmaz — kurumun ortak adresini (ör. noc@, operations@) ya da https sayfasını kullanın`);
|
|
313
|
+
}
|
|
314
|
+
if (problems.length)
|
|
315
|
+
return { problems, warnings };
|
|
316
|
+
return { declaration: d, address: nodeAddressOf(d.node_public_key), problems, warnings };
|
|
317
|
+
}
|
|
318
|
+
/** Bildirim dosyası adı: `<cc>-<ad>.json` (network/permissions/nodes düzeni). */
|
|
319
|
+
export const declarationFileName = (state, name) => {
|
|
320
|
+
if (!NAME_RE.test(name))
|
|
321
|
+
throw new Error("ad: küçük harf, rakam, tire (en çok 32)");
|
|
322
|
+
return `${state.toLowerCase()}-${name}.json`;
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Besu yapılandırması ve izin dosyası için küçük okuyucu: `anahtar=değer` (dize, sayı, mantıksal, dize dizisi; çok satırlı dizi),
|
|
326
|
+
* `#` yorumları. Tablo başlığı (`[x]`) ve iç içe yapı desteklenmez → hata (yanlış okunmaktansa durmak).
|
|
327
|
+
*/
|
|
328
|
+
export function parseToml(text) {
|
|
329
|
+
const out = {};
|
|
330
|
+
const lines = text.replace(/^/, "").split(/\r?\n/);
|
|
331
|
+
const strip = (l) => {
|
|
332
|
+
let q = false;
|
|
333
|
+
for (let i = 0; i < l.length; i++) {
|
|
334
|
+
if (l[i] === '"' && l[i - 1] !== "\\")
|
|
335
|
+
q = !q;
|
|
336
|
+
else if (l[i] === "#" && !q)
|
|
337
|
+
return l.slice(0, i);
|
|
338
|
+
}
|
|
339
|
+
return l;
|
|
340
|
+
};
|
|
341
|
+
const str = (s, n) => {
|
|
342
|
+
const m = /^"((?:[^"\\]|\\.)*)"$/.exec(s.trim());
|
|
343
|
+
if (!m)
|
|
344
|
+
throw new Error(`TOML satır ${n}: dize bekleniyor`);
|
|
345
|
+
return m[1].replace(/\\(.)/g, "$1");
|
|
346
|
+
};
|
|
347
|
+
for (let n = 0; n < lines.length; n++) {
|
|
348
|
+
const l = strip(lines[n]).trim();
|
|
349
|
+
if (!l)
|
|
350
|
+
continue;
|
|
351
|
+
const eq = l.indexOf("=");
|
|
352
|
+
if (eq < 1)
|
|
353
|
+
throw new Error(`TOML satır ${n + 1}: "anahtar=değer" bekleniyor`);
|
|
354
|
+
const key = l.slice(0, eq).trim().replace(/^"|"$/g, "");
|
|
355
|
+
if (!/^[A-Za-z0-9_.-]+$/.test(key))
|
|
356
|
+
throw new Error(`TOML satır ${n + 1}: anahtar geçersiz`);
|
|
357
|
+
let v = l.slice(eq + 1).trim();
|
|
358
|
+
if (v.startsWith("[")) {
|
|
359
|
+
const start = n + 1;
|
|
360
|
+
while (!v.includes("]")) {
|
|
361
|
+
if (++n >= lines.length)
|
|
362
|
+
throw new Error(`TOML satır ${start}: dizi kapanmadı`);
|
|
363
|
+
v += " " + strip(lines[n]).trim();
|
|
364
|
+
}
|
|
365
|
+
const inner = v.slice(1, v.lastIndexOf("]")).trim();
|
|
366
|
+
if (v.slice(v.lastIndexOf("]") + 1).trim())
|
|
367
|
+
throw new Error(`TOML satır ${n + 1}: dizi sonrası fazlalık`);
|
|
368
|
+
out[key] = inner
|
|
369
|
+
? inner
|
|
370
|
+
.split(",")
|
|
371
|
+
.map((x) => x.trim())
|
|
372
|
+
.filter(Boolean)
|
|
373
|
+
.map((x) => str(x, start))
|
|
374
|
+
: [];
|
|
375
|
+
}
|
|
376
|
+
else if (v.startsWith('"'))
|
|
377
|
+
out[key] = str(v, n + 1);
|
|
378
|
+
else if (v === "true" || v === "false")
|
|
379
|
+
out[key] = v === "true";
|
|
380
|
+
else if (/^-?\d+$/.test(v))
|
|
381
|
+
out[key] = Number(v);
|
|
382
|
+
else
|
|
383
|
+
throw new Error(`TOML satır ${n + 1}: desteklenmeyen değer`);
|
|
384
|
+
}
|
|
385
|
+
return out;
|
|
386
|
+
}
|
|
387
|
+
/** Dosyadan TOML (en çok 1 MB). */
|
|
388
|
+
export function readToml(path) {
|
|
389
|
+
if (statSync(path).size > 1024 * 1024)
|
|
390
|
+
throw new Error("TOML dosyası çok büyük (1 MB üstü)");
|
|
391
|
+
return parseToml(readFileSync(path, "utf8"));
|
|
392
|
+
}
|
|
393
|
+
/** Yalnız okuyan JSON-RPC yöntemleri — denetim hiçbir zaman bu kümenin dışında yöntem çağırmaz (oy, izin yükleme, işlem yok). */
|
|
394
|
+
export const READ_ONLY_METHODS = new Set([
|
|
395
|
+
"eth_chainId",
|
|
396
|
+
"eth_blockNumber",
|
|
397
|
+
"eth_syncing",
|
|
398
|
+
"eth_getBlockByNumber",
|
|
399
|
+
"net_version",
|
|
400
|
+
"net_peerCount",
|
|
401
|
+
"admin_nodeInfo",
|
|
402
|
+
"admin_peers",
|
|
403
|
+
"perm_getNodesAllowlist",
|
|
404
|
+
"perm_getAccountsAllowlist",
|
|
405
|
+
"qbft_getValidatorsByBlockNumber",
|
|
406
|
+
"debug_getBadBlocks",
|
|
407
|
+
"txpool_besuStatistics",
|
|
408
|
+
"eth_accounts",
|
|
409
|
+
"web3_clientVersion",
|
|
410
|
+
]);
|
|
411
|
+
/**
|
|
412
|
+
* Varsayılan JSON-RPC taşıyıcısı: POST, en çok 1 MB yanıt, zaman aşımı, yönlendirme İZLENMEZ, adreste kullanıcı bilgisi yok.
|
|
413
|
+
* Alan adı bağlantı anında çözülür ve her adres politikaya göre denetlenir (DNS yeniden bağlama da yakalanır). http yalnız
|
|
414
|
+
* loopback / özel ağ adresinde (izinliyse) ya da `publicHttp` ile.
|
|
415
|
+
*/
|
|
416
|
+
export function defaultRpc(o) {
|
|
417
|
+
const resolveAll = o.resolveAll ?? (async (h) => (await import("node:dns/promises")).lookup(h, { all: true, verbatim: true }));
|
|
418
|
+
const classify = (ip) => (isLoopback(ip) ? "loopback" : isPrivateAddress(ip) ? "private" : "public");
|
|
419
|
+
const verdict = (ip, u, pol) => {
|
|
420
|
+
const c = classify(ip);
|
|
421
|
+
if (c === "loopback" && !pol.loopback)
|
|
422
|
+
return `yerel (loopback) adres izinli değil: ${u.host} → ${ip}`;
|
|
423
|
+
if (c === "private" && !pol.private)
|
|
424
|
+
return `yerel / özel ağ adresi izinli değil: ${u.host} → ${ip} (--allow-private)`;
|
|
425
|
+
if (c === "public" && u.protocol === "http:" && !pol.publicHttp)
|
|
426
|
+
return `dış adreste yalnız https (LP5): ${u.host}`;
|
|
427
|
+
return null;
|
|
428
|
+
};
|
|
429
|
+
return async (url, method, params = []) => {
|
|
430
|
+
if (!READ_ONLY_METHODS.has(method))
|
|
431
|
+
throw new Error(`salt-okur olmayan yöntem çağrılmaz: ${method}`);
|
|
432
|
+
let u;
|
|
433
|
+
try {
|
|
434
|
+
u = new URL(url);
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
return { kind: "network", message: "adres geçersiz" };
|
|
438
|
+
}
|
|
439
|
+
if (u.protocol !== "https:" && u.protocol !== "http:")
|
|
440
|
+
return { kind: "network", message: "yalnız http(s)" };
|
|
441
|
+
if (u.username || u.password)
|
|
442
|
+
return { kind: "network", message: "adreste kullanıcı bilgisi kabul edilmez" };
|
|
443
|
+
const pol = o.policy(u);
|
|
444
|
+
const host = u.hostname.replace(/^\[|\]$/g, "");
|
|
445
|
+
if (isIP(host)) {
|
|
446
|
+
const bad = verdict(host, u, pol);
|
|
447
|
+
if (bad)
|
|
448
|
+
return { kind: "network", message: bad };
|
|
449
|
+
}
|
|
450
|
+
const lookup = (h, opts, cb) => {
|
|
451
|
+
resolveAll(h).then((addrs) => {
|
|
452
|
+
if (!addrs.length)
|
|
453
|
+
return cb(Object.assign(new Error(`çözülemedi: ${h}`), { code: "ENOTFOUND" }), "");
|
|
454
|
+
for (const a of addrs) {
|
|
455
|
+
const bad = verdict(a.address, u, pol);
|
|
456
|
+
if (bad)
|
|
457
|
+
return cb(Object.assign(new Error(bad), { code: "EPOLICY" }), "");
|
|
458
|
+
}
|
|
459
|
+
if (opts?.all)
|
|
460
|
+
return cb(null, addrs);
|
|
461
|
+
cb(null, addrs[0].address, addrs[0].family);
|
|
462
|
+
}, (e) => cb(e, ""));
|
|
463
|
+
};
|
|
464
|
+
const body = JSON.stringify({ jsonrpc: "2.0", id: 1, method, params });
|
|
465
|
+
return new Promise((ok) => {
|
|
466
|
+
const req = (u.protocol === "https:" ? httpsRequest : httpRequest)(u, {
|
|
467
|
+
method: "POST",
|
|
468
|
+
headers: { "content-type": "application/json", "content-length": Buffer.byteLength(body) },
|
|
469
|
+
timeout: o.timeoutMs ?? 10000,
|
|
470
|
+
lookup: lookup,
|
|
471
|
+
...(u.protocol === "https:" && o.tls ? { cert: o.tls.cert, key: o.tls.key } : {}),
|
|
472
|
+
}, (res) => {
|
|
473
|
+
const chunks = [];
|
|
474
|
+
let size = 0;
|
|
475
|
+
res.on("data", (c) => {
|
|
476
|
+
size += c.length;
|
|
477
|
+
if (size > 1024 * 1024)
|
|
478
|
+
return req.destroy(new Error("yanıt çok büyük (1 MB üstü)"));
|
|
479
|
+
chunks.push(c);
|
|
480
|
+
});
|
|
481
|
+
res.on("end", () => {
|
|
482
|
+
const status = res.statusCode ?? 0;
|
|
483
|
+
if (status >= 300 && status < 400)
|
|
484
|
+
return ok({ kind: "error", status, message: "yönlendirme izlenmez (JSON-RPC ucu doğrudan verilmeli)" });
|
|
485
|
+
let j;
|
|
486
|
+
try {
|
|
487
|
+
j = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
488
|
+
}
|
|
489
|
+
catch {
|
|
490
|
+
return ok({ kind: "error", status, message: `JSON-RPC yanıtı değil (HTTP ${status})` });
|
|
491
|
+
}
|
|
492
|
+
if (j && typeof j === "object" && "error" in j && j.error)
|
|
493
|
+
return ok({ kind: "error", status, code: j.error.code, message: clean(j.error.message ?? "hata") });
|
|
494
|
+
if (status !== 200 || !j || !("result" in j))
|
|
495
|
+
return ok({ kind: "error", status, message: `HTTP ${status}` });
|
|
496
|
+
ok({ kind: "result", value: j.result });
|
|
497
|
+
});
|
|
498
|
+
res.on("error", (e) => ok({ kind: "network", message: clean(e.message) }));
|
|
499
|
+
});
|
|
500
|
+
req.on("timeout", () => req.destroy(new Error("zaman aşımı")));
|
|
501
|
+
req.on("error", (e) => ok({
|
|
502
|
+
kind: "network",
|
|
503
|
+
message: clean(e.message),
|
|
504
|
+
tls: u.protocol === "https:" &&
|
|
505
|
+
(/certificate|handshake|alert|ssl|tls/i.test(e.message) || ["EPROTO", "ECONNRESET"].includes(e.code ?? "")),
|
|
506
|
+
}));
|
|
507
|
+
req.end(body);
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
const hexNum = (v) => (typeof v === "string" && /^0x[0-9a-f]+$/i.test(v) ? parseInt(v, 16) : NaN);
|
|
512
|
+
const normEnode = (e) => e.trim().toLowerCase().replace(/\?.*$/, "");
|
|
513
|
+
const setDiff = (a, b) => {
|
|
514
|
+
const sb = new Set(b);
|
|
515
|
+
return a.filter((x) => !sb.has(x));
|
|
516
|
+
};
|
|
517
|
+
const hostOf = (url) => {
|
|
518
|
+
try {
|
|
519
|
+
return new URL(url).hostname.replace(/^\[|\]$/g, "");
|
|
520
|
+
}
|
|
521
|
+
catch {
|
|
522
|
+
return "";
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
/** Dış uçta reddedilmesi gereken (salt-okur) yöntemler — her yasak ad alanından bir tane; durum değiştiren yöntem YOK. */
|
|
526
|
+
export const PROBE_DENIED = [
|
|
527
|
+
"admin_nodeInfo",
|
|
528
|
+
"perm_getNodesAllowlist",
|
|
529
|
+
"qbft_getValidatorsByBlockNumber",
|
|
530
|
+
"debug_getBadBlocks",
|
|
531
|
+
"txpool_besuStatistics",
|
|
532
|
+
"eth_accounts",
|
|
533
|
+
];
|
|
534
|
+
export const PROBE_ALLOWED = ["eth_blockNumber", "net_version"];
|
|
535
|
+
/**
|
|
536
|
+
* Düğüm denetimi (salt okur). Satır kimlikleri N1–N10. Ağdan okunan metin
|
|
537
|
+
* `clean` ile temizlenir ve güvenilmeyen veridir. Operatör tarafı denetimler (bildirim eşleşmesi, blok önerme, oy,
|
|
538
|
+
* hesap izni) bu araçta yoktur — yazma ya da Governance verisi gerektirir.
|
|
539
|
+
*/
|
|
540
|
+
export async function nodeChecks(input, deps) {
|
|
541
|
+
const rows = [];
|
|
542
|
+
const call = (m, p = []) => deps.rpc(input.rpc, m, p);
|
|
543
|
+
const why = (r) => (r.kind === "result" ? "" : r.message);
|
|
544
|
+
const now = input.now ?? new Date();
|
|
545
|
+
// N1 — uç
|
|
546
|
+
const cid = await call("eth_chainId");
|
|
547
|
+
if (cid.kind !== "result") {
|
|
548
|
+
rows.push({
|
|
549
|
+
id: "N1",
|
|
550
|
+
check: "Düğümün yerel RPC ucu",
|
|
551
|
+
result: "fail",
|
|
552
|
+
detail: `eth_chainId yanıtsız: ${why(cid)}`,
|
|
553
|
+
fix: "düğüm çalışıyor mu (log), rpc-http-enabled ve rpc-http-port doğru mu; komutu düğümün kendi makinesinde --rpc http://127.0.0.1:<port> ile çalıştırın",
|
|
554
|
+
});
|
|
555
|
+
rows.push(...configRows(input));
|
|
556
|
+
return rows;
|
|
557
|
+
}
|
|
558
|
+
const chainId = hexNum(cid.value);
|
|
559
|
+
rows.push({ id: "N1", check: "Düğümün yerel RPC ucu", result: "pass", detail: `chainId ${chainId}` });
|
|
560
|
+
// N2 — senkron
|
|
561
|
+
const syncing = await call("eth_syncing");
|
|
562
|
+
const bn = await call("eth_blockNumber");
|
|
563
|
+
const height = bn.kind === "result" ? hexNum(bn.value) : NaN;
|
|
564
|
+
let syncedNow = syncing.kind === "result" && syncing.value === false;
|
|
565
|
+
if (input.chainRpc) {
|
|
566
|
+
const rc = await deps.rpc(input.chainRpc, "eth_chainId");
|
|
567
|
+
const rb = await deps.rpc(input.chainRpc, "eth_blockNumber");
|
|
568
|
+
if (rc.kind !== "result" || rb.kind !== "result") {
|
|
569
|
+
rows.push({
|
|
570
|
+
id: "N2",
|
|
571
|
+
check: "Senkron",
|
|
572
|
+
result: "fail",
|
|
573
|
+
detail: `karşılaştırma ucu yanıtsız: ${why(rc.kind !== "result" ? rc : rb)}`,
|
|
574
|
+
fix: "--chain-rpc adresini ve erişimi (mTLS: --client-cert/--client-key) denetleyin",
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
const ref = hexNum(rb.value);
|
|
579
|
+
const diff = ref - height;
|
|
580
|
+
const sameChain = hexNum(rc.value) === chainId;
|
|
581
|
+
syncedNow &&= sameChain && Math.abs(diff) <= 2;
|
|
582
|
+
rows.push({
|
|
583
|
+
id: "N2",
|
|
584
|
+
check: "Senkron",
|
|
585
|
+
result: !sameChain
|
|
586
|
+
? "fail"
|
|
587
|
+
: syncing.kind === "result" && syncing.value === false && Math.abs(diff) <= 2
|
|
588
|
+
? "pass"
|
|
589
|
+
: "fail",
|
|
590
|
+
detail: !sameChain
|
|
591
|
+
? `chainId farklı (düğüm ${chainId}, karşılaştırma ${hexNum(rc.value)})`
|
|
592
|
+
: `blok ${height} · karşılaştırma ${ref} (fark ${diff}) · eth_syncing ${syncing.kind === "result" ? (syncing.value === false ? "false" : "sürüyor") : "yanıtsız"}`,
|
|
593
|
+
fix: sameChain && Math.abs(diff) > 2
|
|
594
|
+
? "eşleşmeyi bekleyin; eş yoksa izin listesi ve static-nodes.json (N4, N6)"
|
|
595
|
+
: !sameChain
|
|
596
|
+
? "genesis yanlış: işletmecilerden doğru genesis.json'ı alın, veriyi silip yeniden başlatın"
|
|
597
|
+
: undefined,
|
|
598
|
+
});
|
|
599
|
+
// N3 — aynı zincir (genesis bloğu)
|
|
600
|
+
const g1 = await call("eth_getBlockByNumber", ["0x0", false]);
|
|
601
|
+
const g2 = await deps.rpc(input.chainRpc, "eth_getBlockByNumber", ["0x0", false]);
|
|
602
|
+
const h = (r) => r.kind === "result" && r.value && typeof r.value === "object"
|
|
603
|
+
? String(r.value.hash ?? "")
|
|
604
|
+
: "";
|
|
605
|
+
const a = h(g1);
|
|
606
|
+
const b = h(g2);
|
|
607
|
+
rows.push({
|
|
608
|
+
id: "N3",
|
|
609
|
+
check: "Aynı zincir (genesis bloğu)",
|
|
610
|
+
result: a && b ? (a === b ? "pass" : "fail") : "warn",
|
|
611
|
+
detail: a && b
|
|
612
|
+
? a === b
|
|
613
|
+
? `genesis ${shortAddr(a)}`
|
|
614
|
+
: `genesis farklı: ${shortAddr(a)} / ${shortAddr(b)}`
|
|
615
|
+
: "genesis bloğu okunamadı",
|
|
616
|
+
fix: a && b && a !== b ? "yanlış genesis.json: işletmecilerden alıp özetini bant dışı doğrulayın" : undefined,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
else
|
|
621
|
+
rows.push({
|
|
622
|
+
id: "N2",
|
|
623
|
+
check: "Senkron",
|
|
624
|
+
result: syncing.kind !== "result" ? "fail" : syncing.value === false ? "warn" : "fail",
|
|
625
|
+
detail: syncing.kind !== "result"
|
|
626
|
+
? `eth_syncing yanıtsız: ${why(syncing)}`
|
|
627
|
+
: `blok ${height} · eth_syncing ${syncing.value === false ? "false" : "sürüyor"} — karşılaştırma ucu verilmedi`,
|
|
628
|
+
fix: "ağdaki bir uçla karşılaştırma: --chain-rpc <adres>",
|
|
629
|
+
});
|
|
630
|
+
// N4 — eşler
|
|
631
|
+
const pc = await call("net_peerCount");
|
|
632
|
+
const peers = pc.kind === "result" ? hexNum(pc.value) : NaN;
|
|
633
|
+
rows.push({
|
|
634
|
+
id: "N4",
|
|
635
|
+
check: "Eşler",
|
|
636
|
+
result: pc.kind !== "result" ? "fail" : peers >= 1 ? "pass" : "fail",
|
|
637
|
+
detail: pc.kind !== "result" ? `net_peerCount yanıtsız: ${why(pc)}` : `${peers} eş`,
|
|
638
|
+
fix: peers >= 1
|
|
639
|
+
? undefined
|
|
640
|
+
: "eş yok: düğümünüzün bildirimi işletmecilerin izin listesinde mi (render + yükleme), static-nodes.json, güvenlik duvarında P2P portu; statik eş ~1 dk'da bağlanır",
|
|
641
|
+
});
|
|
642
|
+
// N5 — düğüm kimliği (anahtar ↔ node.json / bildirim)
|
|
643
|
+
const ni = await call("admin_nodeInfo");
|
|
644
|
+
const liveKey = ni.kind === "result" && ni.value && typeof ni.value === "object"
|
|
645
|
+
? normalizePublicKey(String(ni.value.id ?? ""))
|
|
646
|
+
: null;
|
|
647
|
+
const liveAddr = liveKey ? nodeAddressOf(liveKey) : input.profile?.address;
|
|
648
|
+
{
|
|
649
|
+
const exp = input.profile?.node_public_key ?? input.declaration?.node_public_key;
|
|
650
|
+
const problems = [];
|
|
651
|
+
if (liveKey && input.profile && liveKey !== input.profile.node_public_key)
|
|
652
|
+
problems.push("düğüm node.json'daki anahtarla çalışmıyor");
|
|
653
|
+
if (liveKey && input.declaration && liveKey !== input.declaration.node_public_key)
|
|
654
|
+
problems.push("düğüm bildirimdeki anahtarla çalışmıyor");
|
|
655
|
+
const listen = ni.kind === "result" && ni.value && typeof ni.value === "object"
|
|
656
|
+
? ni.value.ports?.listener
|
|
657
|
+
: undefined;
|
|
658
|
+
if (input.declaration && typeof listen === "number" && listen !== input.declaration.p2p_port)
|
|
659
|
+
problems.push(`P2P portu ${listen}, bildirimde ${input.declaration.p2p_port}`);
|
|
660
|
+
rows.push({
|
|
661
|
+
id: "N5",
|
|
662
|
+
check: "Düğüm kimliği (anahtar ↔ node.json / bildirim)",
|
|
663
|
+
result: !liveKey ? "warn" : problems.length ? "fail" : exp ? "pass" : "warn",
|
|
664
|
+
detail: !liveKey
|
|
665
|
+
? `admin_nodeInfo okunamadı (${clean(why(ni))}) — ADMIN ad alanı yalnız 127.0.0.1'de açık olmalı`
|
|
666
|
+
: problems.length
|
|
667
|
+
? problems.join("; ")
|
|
668
|
+
: `adres ${shortAddr(liveAddr)}${exp ? " — beklenen anahtar" : " — karşılaştırılacak node.json / bildirim verilmedi"}`,
|
|
669
|
+
fix: problems.length
|
|
670
|
+
? "besu.toml node-private-key-file doğru dosyayı mı gösteriyor; anahtar değiştiyse yeni bildirim (ve validator için Governance adresi) gerekir"
|
|
671
|
+
: undefined,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
// N6 — izin listesi
|
|
675
|
+
{
|
|
676
|
+
const na = await call("perm_getNodesAllowlist");
|
|
677
|
+
const aa = await call("perm_getAccountsAllowlist");
|
|
678
|
+
if (na.kind !== "result" || aa.kind !== "result" || !Array.isArray(na.value) || !Array.isArray(aa.value))
|
|
679
|
+
rows.push({
|
|
680
|
+
id: "N6",
|
|
681
|
+
check: "İzin listesi",
|
|
682
|
+
result: "fail",
|
|
683
|
+
detail: `perm_get* okunamadı (${clean(why(na.kind !== "result" ? na : aa))})`,
|
|
684
|
+
fix: "yerel izinlendirme açık mı (iki permissions-*-config-file-enabled bayrağı) ve PERM ad alanı 127.0.0.1'de açık mı",
|
|
685
|
+
});
|
|
686
|
+
else {
|
|
687
|
+
const nodes = na.value.map((x) => normEnode(String(x)));
|
|
688
|
+
const accts = aa.value.map((x) => String(x).toLowerCase());
|
|
689
|
+
const parts = [`düğüm ${nodes.length}, hesap ${accts.length}`];
|
|
690
|
+
let result = "pass";
|
|
691
|
+
let fix;
|
|
692
|
+
if (input.permissions) {
|
|
693
|
+
const fn = (input.permissions["nodes-allowlist"] ?? []).map(normEnode);
|
|
694
|
+
const fa = (input.permissions["accounts-allowlist"] ?? []).map((x) => x.toLowerCase());
|
|
695
|
+
const d = [
|
|
696
|
+
setDiff(fn, nodes).length,
|
|
697
|
+
setDiff(nodes, fn).length,
|
|
698
|
+
setDiff(fa, accts).length,
|
|
699
|
+
setDiff(accts, fa).length,
|
|
700
|
+
];
|
|
701
|
+
if (d.some(Boolean)) {
|
|
702
|
+
result = "fail";
|
|
703
|
+
parts.push(`çizimle fark: düğüm eksik ${d[0]} / fazla ${d[1]}, hesap eksik ${d[2]} / fazla ${d[3]}`);
|
|
704
|
+
fix =
|
|
705
|
+
"çizimi düğümün dosyasına kopyalayıp perm_reloadPermissionsFromFile (yalnız 127.0.0.1); sonra trust:chain-permissions check";
|
|
706
|
+
}
|
|
707
|
+
else
|
|
708
|
+
parts.push("çizimle (trust:chain-permissions render) aynı");
|
|
709
|
+
}
|
|
710
|
+
if (input.chainRpc) {
|
|
711
|
+
const ra = await deps.rpc(input.chainRpc, "perm_getAccountsAllowlist");
|
|
712
|
+
const rn = await deps.rpc(input.chainRpc, "perm_getNodesAllowlist");
|
|
713
|
+
if (ra.kind === "result" && Array.isArray(ra.value)) {
|
|
714
|
+
const ref = ra.value.map((x) => String(x).toLowerCase());
|
|
715
|
+
const da = setDiff(ref, accts).length + setDiff(accts, ref).length;
|
|
716
|
+
if (da) {
|
|
717
|
+
result = "fail";
|
|
718
|
+
parts.push(`hesap listesi karşılaştırma ucundan farklı (${da} fark; LP3)`);
|
|
719
|
+
fix ??= "iki tarafta da aynı blokta render (--block) → yükle → check; fark işletme olayıdır";
|
|
720
|
+
}
|
|
721
|
+
else
|
|
722
|
+
parts.push("hesap listesi karşılaştırma ucuyla aynı");
|
|
723
|
+
if (rn.kind === "result" && Array.isArray(rn.value)) {
|
|
724
|
+
const refN = rn.value.map((x) => normEnode(String(x)));
|
|
725
|
+
const dn = setDiff(refN, nodes).length + setDiff(nodes, refN).length;
|
|
726
|
+
if (dn) {
|
|
727
|
+
if (result === "pass")
|
|
728
|
+
result = "warn";
|
|
729
|
+
parts.push(`düğüm listesi farklı (${dn}) — işletmecinin kendi RPC düğümleri farkı açıklayabilir`);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
else
|
|
734
|
+
parts.push("karşılaştırma ucunda PERM kapalı (beklenen: dışarıya açılmaz)");
|
|
735
|
+
}
|
|
736
|
+
if (!input.permissions && !(input.chainRpc && result !== "pass")) {
|
|
737
|
+
if (result === "pass")
|
|
738
|
+
result = "warn";
|
|
739
|
+
fix ??=
|
|
740
|
+
"zincirle karşılaştırmak için: trust:chain-permissions render --operator <CC> → --permissions-file <çizim>";
|
|
741
|
+
}
|
|
742
|
+
if (liveKey && input.profile?.role === "validator" && !nodes.some((e) => e.includes(liveKey)))
|
|
743
|
+
parts.push("kendi enode'unuz kendi listenizde yok (bildirim render'a girmemiş olabilir)");
|
|
744
|
+
rows.push({ id: "N6", check: "İzin listesi", result, detail: parts.join(" · "), fix });
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
// N7 — validator kümesi
|
|
748
|
+
{
|
|
749
|
+
const role = input.profile?.role ?? input.declaration?.role;
|
|
750
|
+
if (role !== "validator")
|
|
751
|
+
rows.push({
|
|
752
|
+
id: "N7",
|
|
753
|
+
check: "Validator kümesi",
|
|
754
|
+
result: "skip",
|
|
755
|
+
detail: role === "rpc" ? "RPC düğümü (validator değil)" : "rol bilinmiyor (node.json ya da bildirim verilmedi)",
|
|
756
|
+
});
|
|
757
|
+
else {
|
|
758
|
+
const vs = await call("qbft_getValidatorsByBlockNumber", ["latest"]);
|
|
759
|
+
const list = vs.kind === "result" && Array.isArray(vs.value)
|
|
760
|
+
? vs.value.map((x) => String(x).toLowerCase())
|
|
761
|
+
: null;
|
|
762
|
+
const me = (liveAddr ?? input.profile?.address ?? "").toLowerCase();
|
|
763
|
+
rows.push({
|
|
764
|
+
id: "N7",
|
|
765
|
+
check: "Validator kümesi",
|
|
766
|
+
result: !list ? "warn" : list.includes(me) ? "pass" : "warn",
|
|
767
|
+
detail: !list
|
|
768
|
+
? `qbft_getValidatorsByBlockNumber okunamadı (${clean(why(vs))})`
|
|
769
|
+
: list.includes(me)
|
|
770
|
+
? `${shortAddr(me)} kümede (${list.length} validator)`
|
|
771
|
+
: `${shortAddr(me)} henüz kümede değil (${list.length} validator)`,
|
|
772
|
+
fix: list && !list.includes(me)
|
|
773
|
+
? "beklenen sıra: tam düğüm olarak senkron → mevcut validator'ların ekleme oyu (bu araç oy vermez); blok önermeyi operatör denetler"
|
|
774
|
+
: undefined,
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
// N8 — dışarıya açılan yüzey
|
|
779
|
+
{
|
|
780
|
+
const own = hostOf(input.rpc);
|
|
781
|
+
if (own && !isLoopback(own) && ni.kind === "result")
|
|
782
|
+
rows.push({
|
|
783
|
+
id: "N8",
|
|
784
|
+
check: "RPC dışarıya kapalı",
|
|
785
|
+
result: "fail",
|
|
786
|
+
detail: `yönetim yöntemi (admin_nodeInfo) ${clean(own)} adresinden yanıt verdi — RPC yalnız 127.0.0.1'de dinlemeli`,
|
|
787
|
+
fix: 'besu.toml: rpc-http-host="127.0.0.1"; dış erişim yalnız network/rpc-proxy (mTLS + eth/net/web3)',
|
|
788
|
+
});
|
|
789
|
+
if (input.publicRpc) {
|
|
790
|
+
const answered = [];
|
|
791
|
+
let tlsRefused = 0;
|
|
792
|
+
let net = 0;
|
|
793
|
+
for (const m of PROBE_DENIED) {
|
|
794
|
+
const r = await deps.rpc(input.publicRpc, m, m === "qbft_getValidatorsByBlockNumber" ? ["latest"] : []);
|
|
795
|
+
if (r.kind === "result")
|
|
796
|
+
answered.push(m);
|
|
797
|
+
else if (r.kind === "network")
|
|
798
|
+
r.tls ? tlsRefused++ : net++;
|
|
799
|
+
}
|
|
800
|
+
const allowedOk = [];
|
|
801
|
+
for (const m of PROBE_ALLOWED)
|
|
802
|
+
if ((await deps.rpc(input.publicRpc, m)).kind === "result")
|
|
803
|
+
allowedOk.push(m);
|
|
804
|
+
rows.push({
|
|
805
|
+
id: "N8",
|
|
806
|
+
check: "Dış uçta yalnız eth/net/web3",
|
|
807
|
+
result: answered.length
|
|
808
|
+
? "fail"
|
|
809
|
+
: tlsRefused === PROBE_DENIED.length
|
|
810
|
+
? "warn"
|
|
811
|
+
: net === PROBE_DENIED.length
|
|
812
|
+
? "fail"
|
|
813
|
+
: allowedOk.length === PROBE_ALLOWED.length
|
|
814
|
+
? "pass"
|
|
815
|
+
: "warn",
|
|
816
|
+
detail: answered.length
|
|
817
|
+
? `yasak yöntem yanıt verdi: ${answered.join(", ")}`
|
|
818
|
+
: tlsRefused === PROBE_DENIED.length
|
|
819
|
+
? "TLS el sıkışması istemci sertifikasız reddedildi (mTLS) — yöntem süzgeci sertifikayla denenmeli"
|
|
820
|
+
: net === PROBE_DENIED.length
|
|
821
|
+
? "dış uca ulaşılamadı"
|
|
822
|
+
: `admin/perm/qbft/debug/txpool/eth_accounts reddedildi; izinli: ${allowedOk.join(", ") || "yok"}`,
|
|
823
|
+
fix: answered.length
|
|
824
|
+
? "dış uç yalnız network/rpc-proxy üzerinden (filter.mjs: eth/net/web3); Besu RPC'si dışarı açılmaz"
|
|
825
|
+
: tlsRefused === PROBE_DENIED.length
|
|
826
|
+
? "--client-cert <pem> --client-key <pem> ile yeniden deneyin"
|
|
827
|
+
: allowedOk.length < PROBE_ALLOWED.length
|
|
828
|
+
? "eth_blockNumber / net_version da reddedildi: vekilin yukarı akışı (Besu 127.0.0.1) çalışıyor mu"
|
|
829
|
+
: undefined,
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
else if (!rows.some((r) => r.id === "N8"))
|
|
833
|
+
rows.push({
|
|
834
|
+
id: "N8",
|
|
835
|
+
check: "Dış uçta yalnız eth/net/web3",
|
|
836
|
+
result: "skip",
|
|
837
|
+
detail: "dış uç verilmedi",
|
|
838
|
+
fix: "dışarıdan erişilen vekil varsa: --public-rpc <adres> (gerekiyorsa --client-cert/--client-key)",
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
rows.push(...configRows(input));
|
|
842
|
+
// N10 — saat
|
|
843
|
+
if (!syncedNow)
|
|
844
|
+
rows.push({
|
|
845
|
+
id: "N10",
|
|
846
|
+
check: "Saat",
|
|
847
|
+
result: "skip",
|
|
848
|
+
detail: "düğüm senkron değil / doğrulanamadı — son blok zamanı eski olabilir",
|
|
849
|
+
});
|
|
850
|
+
else {
|
|
851
|
+
const lb = await call("eth_getBlockByNumber", ["latest", false]);
|
|
852
|
+
const ts = lb.kind === "result" && lb.value && typeof lb.value === "object"
|
|
853
|
+
? hexNum(lb.value.timestamp)
|
|
854
|
+
: NaN;
|
|
855
|
+
const skew = Number.isFinite(ts) ? Math.round(now.getTime() / 1000 - ts) : NaN;
|
|
856
|
+
rows.push({
|
|
857
|
+
id: "N10",
|
|
858
|
+
check: "Saat",
|
|
859
|
+
result: !Number.isFinite(skew) ? "warn" : Math.abs(skew) <= 5 ? "pass" : Math.abs(skew) <= 30 ? "warn" : "fail",
|
|
860
|
+
detail: Number.isFinite(skew)
|
|
861
|
+
? `son blok zamanı ile bu makinenin saati arasında ${skew} sn`
|
|
862
|
+
: "son blok okunamadı",
|
|
863
|
+
fix: Number.isFinite(skew) && Math.abs(skew) > 5
|
|
864
|
+
? "NTP: Linux timedatectl / chrony; Windows w32tm /resync — QBFT tur zaman aşımları saat kaymasına duyarlıdır"
|
|
865
|
+
: undefined,
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
return rows;
|
|
869
|
+
}
|
|
870
|
+
/** N9 — besu.toml: arayüzler, ad alanları, izinlendirme bayrakları. */
|
|
871
|
+
function configRows(input) {
|
|
872
|
+
const c = input.config;
|
|
873
|
+
if (!c)
|
|
874
|
+
return [
|
|
875
|
+
{
|
|
876
|
+
id: "N9",
|
|
877
|
+
check: "Yapılandırma: arayüzler ve izinlendirme",
|
|
878
|
+
result: "skip",
|
|
879
|
+
detail: "besu.toml verilmedi",
|
|
880
|
+
fix: "--config <besu.toml> (ya da node init klasörü)",
|
|
881
|
+
},
|
|
882
|
+
];
|
|
883
|
+
const p = [];
|
|
884
|
+
const w = [];
|
|
885
|
+
const loop = (v) => typeof v === "string" && isLoopback(v);
|
|
886
|
+
if (c["rpc-http-enabled"] === true && !loop(c["rpc-http-host"] ?? "127.0.0.1"))
|
|
887
|
+
p.push(`rpc-http-host "${clean(c["rpc-http-host"])}" — yalnız 127.0.0.1 (LP5)`);
|
|
888
|
+
for (const [en, h] of [
|
|
889
|
+
["rpc-ws-enabled", "rpc-ws-host"],
|
|
890
|
+
["graphql-http-enabled", "graphql-http-host"],
|
|
891
|
+
])
|
|
892
|
+
if (c[en] === true && !loop(c[h] ?? "127.0.0.1"))
|
|
893
|
+
p.push(`${h} yalnız 127.0.0.1`);
|
|
894
|
+
const itf = c["p2p-interface"];
|
|
895
|
+
if (itf === undefined)
|
|
896
|
+
p.push("p2p-interface yok — Besu varsayılanı 0.0.0.0 (bütün arayüzler); yalnız iç arayüzün adresi");
|
|
897
|
+
else if (typeof itf !== "string" || UNSPECIFIED(itf))
|
|
898
|
+
p.push(`p2p-interface "${clean(itf)}" — 0.0.0.0 / :: değil, yalnız iç arayüz`);
|
|
899
|
+
if (c["permissions-nodes-config-file-enabled"] !== true)
|
|
900
|
+
p.push("permissions-nodes-config-file-enabled=true olmalı (LP1)");
|
|
901
|
+
if (c["permissions-accounts-config-file-enabled"] !== true)
|
|
902
|
+
p.push("permissions-accounts-config-file-enabled=true olmalı (LP1)");
|
|
903
|
+
const ha = c["host-allowlist"];
|
|
904
|
+
if (Array.isArray(ha) && ha.includes("*"))
|
|
905
|
+
p.push('host-allowlist "*" — yalnız localhost, 127.0.0.1');
|
|
906
|
+
if (c["discovery-enabled"] !== false)
|
|
907
|
+
w.push("discovery-enabled=false önerilir (statik eşler)");
|
|
908
|
+
const api = Array.isArray(c["rpc-http-api"]) ? c["rpc-http-api"].map((x) => x.toUpperCase()) : [];
|
|
909
|
+
if (api.some((x) => ["DEBUG", "TXPOOL", "TRACE", "MINER", "PLUGINS"].includes(x)))
|
|
910
|
+
w.push(`rpc-http-api fazla ad alanı açıyor (${api.join(",")}) — yerelde gerekenler ETH, NET, WEB3, QBFT, PERM, ADMIN`);
|
|
911
|
+
if (input.profile) {
|
|
912
|
+
if (typeof c["p2p-port"] === "number" && c["p2p-port"] !== input.profile.p2p_port)
|
|
913
|
+
w.push(`p2p-port ${c["p2p-port"]}, node.json'da ${input.profile.p2p_port}`);
|
|
914
|
+
if (typeof c["p2p-host"] === "string" && c["p2p-host"] !== input.profile.ip)
|
|
915
|
+
w.push(`p2p-host ${clean(c["p2p-host"])}, bildirilen ip ${input.profile.ip}`);
|
|
916
|
+
}
|
|
917
|
+
return [
|
|
918
|
+
{
|
|
919
|
+
id: "N9",
|
|
920
|
+
check: "Yapılandırma: arayüzler ve izinlendirme",
|
|
921
|
+
result: p.length ? "fail" : w.length ? "warn" : "pass",
|
|
922
|
+
detail: p.length || w.length ? [...p, ...w].join("; ") : "RPC 127.0.0.1, P2P yalnız iç arayüz, iki izin bayrağı açık",
|
|
923
|
+
fix: p.length
|
|
924
|
+
? "tamga-onboard node init şablonuyla karşılaştırın (ARCH-0002 §6); değişiklikten sonra düğümü yeniden başlatın"
|
|
925
|
+
: undefined,
|
|
926
|
+
},
|
|
927
|
+
];
|
|
928
|
+
}
|
|
929
|
+
/** Düğüm adresi: CLI'da düğümün kendi makinesi varsayılır (besu.toml'daki RPC portu, yoksa 8545). */
|
|
930
|
+
export const defaultNodeRpc = (config) => `http://127.0.0.1:${typeof config?.["rpc-http-port"] === "number" ? config["rpc-http-port"] : 8545}`;
|
|
931
|
+
//# sourceMappingURL=node.js.map
|