blue-js-sdk 2.0.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.
Files changed (215) hide show
  1. package/CHANGELOG.md +446 -0
  2. package/LICENSE +21 -0
  3. package/README.md +75 -0
  4. package/ai-path/ADMIN-ELEVATION.md +116 -0
  5. package/ai-path/AI-MANIFESTO.md +185 -0
  6. package/ai-path/BREAKING.md +74 -0
  7. package/ai-path/CHECKLIST.md +619 -0
  8. package/ai-path/CONNECTION-STEPS.md +724 -0
  9. package/ai-path/DECISION-TREE.md +378 -0
  10. package/ai-path/DEPENDENCIES.md +459 -0
  11. package/ai-path/E2E-FLOW.md +1555 -0
  12. package/ai-path/FAILURES.md +403 -0
  13. package/ai-path/GUIDE.md +1217 -0
  14. package/ai-path/README.md +558 -0
  15. package/ai-path/SPLIT-TUNNEL.md +266 -0
  16. package/ai-path/cli.js +535 -0
  17. package/ai-path/connect.js +884 -0
  18. package/ai-path/discover.js +178 -0
  19. package/ai-path/environment.js +266 -0
  20. package/ai-path/errors.js +86 -0
  21. package/ai-path/examples/autonomous-agent.mjs +220 -0
  22. package/ai-path/examples/multi-region.mjs +174 -0
  23. package/ai-path/examples/one-shot.mjs +31 -0
  24. package/ai-path/index.js +60 -0
  25. package/ai-path/pricing.js +136 -0
  26. package/ai-path/recommend.js +413 -0
  27. package/ai-path/run-admin.vbs +25 -0
  28. package/ai-path/setup.js +291 -0
  29. package/ai-path/wallet.js +137 -0
  30. package/app-helpers.js +363 -0
  31. package/app-settings.js +95 -0
  32. package/app-types.js +267 -0
  33. package/audit.js +847 -0
  34. package/batch.js +293 -0
  35. package/bin/setup.js +376 -0
  36. package/chain/authz.js +109 -0
  37. package/chain/broadcast.js +472 -0
  38. package/chain/client.js +160 -0
  39. package/chain/fee-grants.js +305 -0
  40. package/chain/index.js +891 -0
  41. package/chain/lcd.js +313 -0
  42. package/chain/queries.js +547 -0
  43. package/chain/rpc.js +408 -0
  44. package/chain/wallet.js +141 -0
  45. package/cli/config.js +143 -0
  46. package/cli/index.js +463 -0
  47. package/cli/output.js +182 -0
  48. package/cli.js +491 -0
  49. package/client/index.js +251 -0
  50. package/client.js +271 -0
  51. package/config/index.js +255 -0
  52. package/connection/connect.js +849 -0
  53. package/connection/disconnect.js +180 -0
  54. package/connection/discovery.js +321 -0
  55. package/connection/index.js +76 -0
  56. package/connection/proxy.js +148 -0
  57. package/connection/resilience.js +428 -0
  58. package/connection/security.js +232 -0
  59. package/connection/state.js +369 -0
  60. package/connection/tunnel.js +691 -0
  61. package/consumer.js +132 -0
  62. package/cosmjs-setup.js +1884 -0
  63. package/defaults.js +366 -0
  64. package/disk-cache.js +107 -0
  65. package/dist/client.d.ts +108 -0
  66. package/dist/client.d.ts.map +1 -0
  67. package/dist/client.js +400 -0
  68. package/dist/client.js.map +1 -0
  69. package/dist/index.d.ts +8 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +8 -0
  72. package/dist/index.js.map +1 -0
  73. package/errors/index.js +112 -0
  74. package/errors.js +218 -0
  75. package/examples/README.md +64 -0
  76. package/examples/connect-direct.mjs +106 -0
  77. package/examples/connect-plan.mjs +125 -0
  78. package/examples/error-handling.mjs +109 -0
  79. package/examples/query-nodes.mjs +94 -0
  80. package/examples/wallet-basics.mjs +61 -0
  81. package/generated/amino/amino.ts +9 -0
  82. package/generated/cosmos/base/v1beta1/coin.ts +365 -0
  83. package/generated/cosmos_proto/cosmos.ts +323 -0
  84. package/generated/gogoproto/gogo.ts +9 -0
  85. package/generated/google/protobuf/descriptor.ts +7601 -0
  86. package/generated/google/protobuf/duration.ts +208 -0
  87. package/generated/google/protobuf/timestamp.ts +238 -0
  88. package/generated/sentinel/lease/v1/events.ts +924 -0
  89. package/generated/sentinel/lease/v1/lease.ts +292 -0
  90. package/generated/sentinel/lease/v1/msg.ts +949 -0
  91. package/generated/sentinel/lease/v1/params.ts +164 -0
  92. package/generated/sentinel/node/v3/events.ts +881 -0
  93. package/generated/sentinel/node/v3/msg.ts +1002 -0
  94. package/generated/sentinel/node/v3/node.ts +263 -0
  95. package/generated/sentinel/node/v3/params.ts +183 -0
  96. package/generated/sentinel/plan/v3/events.ts +675 -0
  97. package/generated/sentinel/plan/v3/msg.ts +1191 -0
  98. package/generated/sentinel/plan/v3/plan.ts +283 -0
  99. package/generated/sentinel/provider/v2/events.ts +171 -0
  100. package/generated/sentinel/provider/v2/msg.ts +480 -0
  101. package/generated/sentinel/provider/v2/params.ts +131 -0
  102. package/generated/sentinel/provider/v2/provider.ts +246 -0
  103. package/generated/sentinel/session/v3/events.ts +480 -0
  104. package/generated/sentinel/session/v3/msg.ts +616 -0
  105. package/generated/sentinel/session/v3/params.ts +260 -0
  106. package/generated/sentinel/session/v3/proof.ts +180 -0
  107. package/generated/sentinel/session/v3/session.ts +384 -0
  108. package/generated/sentinel/subscription/v3/events.ts +1181 -0
  109. package/generated/sentinel/subscription/v3/msg.ts +1305 -0
  110. package/generated/sentinel/subscription/v3/params.ts +167 -0
  111. package/generated/sentinel/subscription/v3/subscription.ts +315 -0
  112. package/generated/sentinel/types/v1/bandwidth.ts +124 -0
  113. package/generated/sentinel/types/v1/price.ts +149 -0
  114. package/generated/sentinel/types/v1/renewal.ts +87 -0
  115. package/generated/sentinel/types/v1/status.ts +54 -0
  116. package/generated/typeRegistry.ts +27 -0
  117. package/index.js +486 -0
  118. package/node-connect.js +3015 -0
  119. package/operator.js +134 -0
  120. package/package.json +113 -0
  121. package/plan-operations.js +199 -0
  122. package/preflight.js +352 -0
  123. package/pricing/index.js +262 -0
  124. package/proto/amino/amino.proto +84 -0
  125. package/proto/cosmos/base/v1beta1/coin.proto +61 -0
  126. package/proto/cosmos_proto/cosmos.proto +112 -0
  127. package/proto/gogoproto/gogo.proto +145 -0
  128. package/proto/google/api/annotations.proto +31 -0
  129. package/proto/google/api/http.proto +370 -0
  130. package/proto/google/protobuf/any.proto +106 -0
  131. package/proto/google/protobuf/duration.proto +115 -0
  132. package/proto/google/protobuf/timestamp.proto +145 -0
  133. package/proto/sentinel/lease/v1/events.proto +52 -0
  134. package/proto/sentinel/lease/v1/genesis.proto +15 -0
  135. package/proto/sentinel/lease/v1/lease.proto +25 -0
  136. package/proto/sentinel/lease/v1/msg.proto +62 -0
  137. package/proto/sentinel/lease/v1/params.proto +17 -0
  138. package/proto/sentinel/node/v3/events.proto +50 -0
  139. package/proto/sentinel/node/v3/genesis.proto +15 -0
  140. package/proto/sentinel/node/v3/msg.proto +63 -0
  141. package/proto/sentinel/node/v3/node.proto +27 -0
  142. package/proto/sentinel/node/v3/params.proto +21 -0
  143. package/proto/sentinel/node/v3/querier.proto +63 -0
  144. package/proto/sentinel/plan/v3/events.proto +41 -0
  145. package/proto/sentinel/plan/v3/genesis.proto +21 -0
  146. package/proto/sentinel/plan/v3/msg.proto +83 -0
  147. package/proto/sentinel/plan/v3/plan.proto +32 -0
  148. package/proto/sentinel/plan/v3/querier.proto +53 -0
  149. package/proto/sentinel/provider/v2/events.proto +16 -0
  150. package/proto/sentinel/provider/v2/genesis.proto +15 -0
  151. package/proto/sentinel/provider/v2/msg.proto +35 -0
  152. package/proto/sentinel/provider/v2/params.proto +17 -0
  153. package/proto/sentinel/provider/v2/provider.proto +24 -0
  154. package/proto/sentinel/provider/v3/genesis.proto +15 -0
  155. package/proto/sentinel/provider/v3/params.proto +13 -0
  156. package/proto/sentinel/session/v3/events.proto +30 -0
  157. package/proto/sentinel/session/v3/genesis.proto +15 -0
  158. package/proto/sentinel/session/v3/msg.proto +50 -0
  159. package/proto/sentinel/session/v3/params.proto +25 -0
  160. package/proto/sentinel/session/v3/proof.proto +25 -0
  161. package/proto/sentinel/session/v3/querier.proto +100 -0
  162. package/proto/sentinel/session/v3/session.proto +50 -0
  163. package/proto/sentinel/subscription/v2/allocation.proto +21 -0
  164. package/proto/sentinel/subscription/v2/payout.proto +22 -0
  165. package/proto/sentinel/subscription/v3/events.proto +65 -0
  166. package/proto/sentinel/subscription/v3/genesis.proto +17 -0
  167. package/proto/sentinel/subscription/v3/msg.proto +83 -0
  168. package/proto/sentinel/subscription/v3/params.proto +21 -0
  169. package/proto/sentinel/subscription/v3/subscription.proto +33 -0
  170. package/proto/sentinel/types/v1/bandwidth.proto +19 -0
  171. package/proto/sentinel/types/v1/price.proto +21 -0
  172. package/proto/sentinel/types/v1/renewal.proto +21 -0
  173. package/proto/sentinel/types/v1/status.proto +16 -0
  174. package/protocol/encoding.js +341 -0
  175. package/protocol/events.js +361 -0
  176. package/protocol/handshake.js +297 -0
  177. package/protocol/index.js +15 -0
  178. package/protocol/messages.js +346 -0
  179. package/protocol/plans.js +199 -0
  180. package/protocol/v2ray.js +268 -0
  181. package/protocol/v3.js +723 -0
  182. package/protocol/wireguard.js +125 -0
  183. package/security/index.js +132 -0
  184. package/session-manager.js +329 -0
  185. package/session-tracker.js +80 -0
  186. package/setup.js +376 -0
  187. package/speedtest/index.js +528 -0
  188. package/speedtest.js +567 -0
  189. package/src/client.ts +502 -0
  190. package/src/index.ts +20 -0
  191. package/state/index.js +347 -0
  192. package/state.js +516 -0
  193. package/test-all-chain-ops.js +493 -0
  194. package/test-all-logic.js +199 -0
  195. package/test-all-msg-types.js +292 -0
  196. package/test-every-connection.js +208 -0
  197. package/test-feegrant-connect.js +98 -0
  198. package/test-logic.js +148 -0
  199. package/test-mainnet.js +176 -0
  200. package/test-plan-lifecycle.js +335 -0
  201. package/tls-trust.js +132 -0
  202. package/tsconfig.build.json +20 -0
  203. package/tsconfig.json +34 -0
  204. package/types/chain.d.ts +746 -0
  205. package/types/connection.d.ts +425 -0
  206. package/types/errors.d.ts +174 -0
  207. package/types/index.d.ts +1380 -0
  208. package/types/nodes.d.ts +187 -0
  209. package/types/pricing.d.ts +156 -0
  210. package/types/protocol.d.ts +332 -0
  211. package/types/session.d.ts +236 -0
  212. package/types/settings.d.ts +192 -0
  213. package/v3protocol.js +1053 -0
  214. package/wallet/index.js +153 -0
  215. package/wireguard.js +307 -0
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Sentinel SDK — Node Types
3
+ *
4
+ * Types for querying, filtering, scoring, and displaying Sentinel dVPN nodes.
5
+ * Covers: online node queries, node enrichment, geographic indexing,
6
+ * node filtering, and display-ready objects for UI rendering.
7
+ */
8
+
9
+ import type { PriceEntry, ChainNode } from './chain.js';
10
+
11
+ // ─── Node Query Options ────────────────────────────────────────────────────
12
+
13
+ /** Options for queryOnlineNodes() / listNodes(). */
14
+ export interface ListNodesOptions {
15
+ /** LCD URL (default: cascading fallback across 4 endpoints) */
16
+ lcdUrl?: string;
17
+ /**
18
+ * Maximum nodes to probe for status (default: 100).
19
+ * Set higher to discover more of the network (900+ active nodes total).
20
+ */
21
+ maxNodes?: number;
22
+ /** Filter by service type (null = all) */
23
+ serviceType?: 'wireguard' | 'v2ray' | null;
24
+ /** Concurrency for node probing (default: 30) */
25
+ concurrency?: number;
26
+ /** Progress callback: called after each batch of nodes is probed */
27
+ onNodeProbed?: (progress: NodeProbeProgress) => void;
28
+ /** Skip quality-score sorting (default: false) */
29
+ skipSort?: boolean;
30
+ /** Bypass 5-minute node cache and force fresh scan (default: false) */
31
+ noCache?: boolean;
32
+ /** Skip cache entirely and wait for fresh results (default: false) */
33
+ waitForFresh?: boolean;
34
+ }
35
+
36
+ /** Progress callback data for node probing. */
37
+ export interface NodeProbeProgress {
38
+ /** Total nodes to probe */
39
+ total: number;
40
+ /** Nodes probed so far */
41
+ probed: number;
42
+ /** Nodes found online so far */
43
+ online: number;
44
+ }
45
+
46
+ /** Options for enrichNodes(). */
47
+ export interface EnrichNodesOptions {
48
+ /** Concurrency for status probes (default: 30) */
49
+ concurrency?: number;
50
+ /** Per-node probe timeout in ms (default: 8000) */
51
+ timeout?: number;
52
+ /** Progress callback */
53
+ onProgress?: (progress: { total: number; done: number; enriched: number }) => void;
54
+ }
55
+
56
+ // ─── Scored Node ───────────────────────────────────────────────────────────
57
+
58
+ /**
59
+ * Node with quality scoring applied. Returned by queryOnlineNodes() and enrichNodes().
60
+ * Sorted by qualityScore (highest first).
61
+ */
62
+ export interface ScoredNode {
63
+ /** sentnode1... address */
64
+ address: string;
65
+ /** Node's HTTPS remote URL */
66
+ remoteUrl: string;
67
+ /** Service type: 'wireguard' or 'v2ray' */
68
+ serviceType: string;
69
+ /** Node display name */
70
+ moniker: string;
71
+ /** Country name (as reported by node) */
72
+ country: string;
73
+ /** City name */
74
+ city: string;
75
+ /** Current peer count */
76
+ peers: number;
77
+ /**
78
+ * Clock drift in seconds (null if unknown).
79
+ * Nodes with |drift| > 120s are penalized (VMess breaks).
80
+ */
81
+ clockDriftSec: number | null;
82
+ /**
83
+ * Quality score 0-100. Higher is better.
84
+ * Factors: WG preferred over V2Ray, low peers, low drift, udvpn pricing.
85
+ */
86
+ qualityScore: number;
87
+ /** Per-GB pricing entries from LCD */
88
+ gigabytePrices: PriceEntry[];
89
+ /** Per-hour pricing entries from LCD */
90
+ hourlyPrices: PriceEntry[];
91
+ }
92
+
93
+ // ─── Node Filter ───────────────────────────────────────────────────────────
94
+
95
+ /** Criteria for filterNodes(). All fields are optional (AND logic). */
96
+ export interface NodeFilter {
97
+ /** Filter by country name or ISO code */
98
+ country?: string;
99
+ /** Filter by service type */
100
+ serviceType?: 'wireguard' | 'v2ray';
101
+ /** Maximum price in P2P per GB */
102
+ maxPriceDvpn?: number;
103
+ /** Minimum quality score (0-100) */
104
+ minScore?: number;
105
+ }
106
+
107
+ // ─── Node Score ────────────────────────────────────────────────────────────
108
+
109
+ /** Standardized price extraction result from getNodePrices(). */
110
+ export interface NodePrices {
111
+ /** Per-GB pricing */
112
+ gigabyte: {
113
+ /** Price in whole P2P tokens */
114
+ dvpn: number;
115
+ /** Price in micro-denom (udvpn) */
116
+ udvpn: number;
117
+ /** Raw chain price object (null if node has no GB pricing) */
118
+ raw: PriceEntry | null;
119
+ };
120
+ /** Per-hour pricing */
121
+ hourly: {
122
+ /** Price in whole P2P tokens */
123
+ dvpn: number;
124
+ /** Price in micro-denom (udvpn) */
125
+ udvpn: number;
126
+ /** Raw chain price object (null if node has no hourly pricing) */
127
+ raw: PriceEntry | null;
128
+ };
129
+ /** Token denomination (always 'udvpn') */
130
+ denom: string;
131
+ /** sentnode1... address */
132
+ nodeAddress: string;
133
+ }
134
+
135
+ // ─── Geographic Index ──────────────────────────────────────────────────────
136
+
137
+ /** Geographic index from buildNodeIndex(). Enables instant country/city lookups. */
138
+ export interface NodeIndex {
139
+ /** Nodes grouped by country name */
140
+ countries: Record<string, ScoredNode[]>;
141
+ /** Nodes grouped by city name */
142
+ cities: Record<string, ScoredNode[]>;
143
+ /** Summary statistics */
144
+ stats: {
145
+ totalNodes: number;
146
+ totalCountries: number;
147
+ totalCities: number;
148
+ byCountry: Array<{ country: string; count: number }>;
149
+ };
150
+ }
151
+
152
+ // ─── Network Overview ──────────────────────────────────────────────────────
153
+
154
+ /** Network overview from getNetworkOverview(). Perfect for dashboards. */
155
+ export interface NetworkOverview {
156
+ /** Total active nodes on the network */
157
+ totalNodes: number;
158
+ /** Node count by country */
159
+ byCountry: Array<{ country: string; count: number }>;
160
+ /** Node count by service type */
161
+ byType: {
162
+ wireguard: number;
163
+ v2ray: number;
164
+ unknown: number;
165
+ };
166
+ /** Average prices across all nodes */
167
+ averagePrice: {
168
+ /** Average per-GB price in P2P tokens */
169
+ gigabyteDvpn: number;
170
+ /** Average per-hour price in P2P tokens */
171
+ hourlyDvpn: number;
172
+ };
173
+ /** Raw node data */
174
+ nodes: unknown[];
175
+ }
176
+
177
+ // ─── Broken Nodes ──────────────────────────────────────────────────────────
178
+
179
+ /** Known broken node entry from BROKEN_NODES blacklist. */
180
+ export interface BrokenNode {
181
+ /** sentnode1... address */
182
+ address: string;
183
+ /** Reason the node is broken */
184
+ reason: string;
185
+ /** Date when the node was verified broken */
186
+ verified: string;
187
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Sentinel SDK — Pricing & Display Types
3
+ *
4
+ * Types for pricing display, cost estimation, country mapping,
5
+ * and UI builder helpers. These are NOT protocol functions --
6
+ * they're UX helpers that every consumer app needs.
7
+ */
8
+
9
+ import type { PriceEntry } from './chain.js';
10
+
11
+ // ─── Price Display ─────────────────────────────────────────────────────────
12
+
13
+ /** Formatted node pricing for UI display. From formatNodePricing(). */
14
+ export interface NodePricingDisplay {
15
+ /** Per-GB price string (e.g. '0.04 P2P/GB') or null if no GB pricing */
16
+ perGb: string | null;
17
+ /** Per-hour price string (e.g. '0.02 P2P/hr') or null if no hourly pricing */
18
+ perHour: string | null;
19
+ /** Which pricing model is cheaper (null if only one model available) */
20
+ cheapest: 'gb' | 'hour' | null;
21
+ /** Raw per-GB price in micro-denom (null if unavailable) */
22
+ gbRaw: number | null;
23
+ /** Raw per-hour price in micro-denom (null if unavailable) */
24
+ hrRaw: number | null;
25
+ }
26
+
27
+ /** Session cost estimate from estimateSessionPrice(). */
28
+ export interface SessionPriceEstimate {
29
+ /** Formatted cost string (e.g. '0.20 P2P') or 'N/A' if pricing unavailable */
30
+ cost: string;
31
+ /** Cost in micro-denom (0 if unavailable) */
32
+ costUdvpn: number;
33
+ /** Pricing model used */
34
+ model: 'gb' | 'hour';
35
+ /** Amount (GB or hours) */
36
+ amount: number;
37
+ /** Unit label ('GB' or 'hours') */
38
+ unit: string;
39
+ }
40
+
41
+ // ─── Country Info ──────────────────────────────────────────────────────────
42
+
43
+ /**
44
+ * Country name to ISO 3166-1 alpha-2 code map.
45
+ * Includes 80+ countries with standard names, chain variants
46
+ * (e.g. 'The Netherlands', 'Turkiye'), and short codes.
47
+ */
48
+ export type CountryMap = Readonly<Record<string, string>>;
49
+
50
+ // ─── Node Display ──────────────────────────────────────────────────────────
51
+
52
+ /** Display-ready node object from buildNodeDisplay(). Ready for UI rendering. */
53
+ export interface NodeDisplay {
54
+ /** sentnode1... address */
55
+ address: string;
56
+ /** Node display name (null if not probed) */
57
+ moniker: string | null;
58
+ /** Country name (null if not probed) */
59
+ country: string | null;
60
+ /** ISO 3166-1 alpha-2 country code (null if unknown) */
61
+ countryCode: string | null;
62
+ /** City name (null if not probed) */
63
+ city: string | null;
64
+ /** Flag image URL from flagcdn.com (null if no country code) */
65
+ flagUrl: string | null;
66
+ /** Emoji flag for web display (empty string if no country code) */
67
+ flagEmoji: string;
68
+ /** Service type string (null if not probed) */
69
+ serviceType: string | null;
70
+ /** Short protocol label for UI: 'WG' | 'V2' | null */
71
+ protocol: 'WG' | 'V2' | null;
72
+ /** Formatted pricing from formatNodePricing() */
73
+ pricing: NodePricingDisplay;
74
+ /** Current peer count */
75
+ peers: number;
76
+ /** Maximum peer count */
77
+ maxPeers: number;
78
+ /** Node software version */
79
+ version: string | null;
80
+ /** Whether the node responded to status probe */
81
+ online: boolean;
82
+ }
83
+
84
+ /** Country group for sidebar display. From groupNodesByCountry(). */
85
+ export interface CountryGroup {
86
+ /** Country name */
87
+ country: string;
88
+ /** ISO country code */
89
+ countryCode: string;
90
+ /** Flag image URL */
91
+ flagUrl: string;
92
+ /** Emoji flag */
93
+ flagEmoji: string;
94
+ /** All nodes in this country */
95
+ nodes: NodeDisplay[];
96
+ /** Number of online nodes */
97
+ onlineCount: number;
98
+ /** Total nodes (online + offline) */
99
+ totalCount: number;
100
+ }
101
+
102
+ // ─── Pricing Reference ─────────────────────────────────────────────────────
103
+
104
+ /**
105
+ * Static pricing reference for cost estimation UI.
106
+ * These are APPROXIMATE values from chain data -- actual prices vary per node.
107
+ * Always use estimateCost() or getNodePrices() for live data.
108
+ */
109
+ export interface PricingReference {
110
+ /** When these values were last verified */
111
+ verified: string;
112
+ /** Disclaimer about accuracy */
113
+ note: string;
114
+ session: {
115
+ /** Typical session cost in P2P (0.04-0.15 per GB) */
116
+ typicalCostDvpn: number;
117
+ /** Minimum recommended wallet balance in P2P */
118
+ minBalanceDvpn: number;
119
+ /** Minimum recommended wallet balance in micro-denom */
120
+ minBalanceUdvpn: number;
121
+ };
122
+ gasPerMsg: {
123
+ /** Gas for MsgStartSession (~200k) */
124
+ startSession: number;
125
+ /** Gas for subscription + session (~250k) */
126
+ startSubscription: number;
127
+ /** Gas for MsgCreatePlan (~300k) */
128
+ createPlan: number;
129
+ /** Gas for MsgStartLease (~250k) */
130
+ startLease: number;
131
+ /** Gas for batch of 5 MsgStartSession (~800k) */
132
+ batchOf5: number;
133
+ };
134
+ averageNodePrices: {
135
+ /** Average per-GB price in micro-denom */
136
+ gigabyteQuoteValue: string;
137
+ /** Average per-hour price in micro-denom */
138
+ hourlyQuoteValue: string;
139
+ /** Typical base_value (sdk.Dec string) */
140
+ baseValue: string;
141
+ };
142
+ }
143
+
144
+ // ─── Session Duration Presets ──────────────────────────────────────────────
145
+
146
+ /**
147
+ * Common hour options for hourly session selection UI.
148
+ * Values: [1, 2, 4, 8, 12, 24]
149
+ */
150
+ export type HourOptions = number[];
151
+
152
+ /**
153
+ * Common GB options for per-GB session selection UI.
154
+ * Values: [1, 2, 5, 10, 25, 50]
155
+ */
156
+ export type GbOptions = number[];
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Sentinel SDK — Protocol Types
3
+ *
4
+ * Types for the v3 node protocol: node status, handshakes,
5
+ * WireGuard tunnels, V2Ray configs, and transport rates.
6
+ *
7
+ * v3 differences from v2:
8
+ * - Node status: GET / (not GET /status)
9
+ * - Handshake: POST / (not POST /accounts/{addr}/sessions/{id})
10
+ * - field: service_type (not type), remote_addrs (array, not remote_url string)
11
+ * - Sessions wrapped in base_session
12
+ */
13
+
14
+ /// <reference types="node" />
15
+
16
+ // ─── Node Status ───────────────────────────────────────────────────────────
17
+
18
+ /** Normalized node status from nodeStatusV3(). Combines v3 API response fields. */
19
+ export interface NodeStatus {
20
+ /** sentnode1... address (may be empty if node doesn't report it) */
21
+ address: string;
22
+ /** Service type: 'wireguard' or 'v2ray' */
23
+ type: 'wireguard' | 'v2ray';
24
+ /** Node display name */
25
+ moniker: string;
26
+ /** Current peer count (active connections) */
27
+ peers: number;
28
+ /** Bandwidth capabilities */
29
+ bandwidth: {
30
+ /** Download speed in bytes/s */
31
+ download: number;
32
+ /** Upload speed in bytes/s */
33
+ upload: number;
34
+ };
35
+ /** Geographic location */
36
+ location: {
37
+ /** City name */
38
+ city: string;
39
+ /** Country name (as reported by node -- may be variant like "Turkiye") */
40
+ country: string;
41
+ /** ISO 3166-1 alpha-2 country code (as reported by node) */
42
+ country_code: string;
43
+ /** Latitude */
44
+ latitude: number;
45
+ /** Longitude */
46
+ longitude: number;
47
+ };
48
+ /** Quality of service limits */
49
+ qos: {
50
+ /** Maximum allowed peers (null if not configured) */
51
+ max_peers: number | null;
52
+ };
53
+ /**
54
+ * Clock drift in seconds between our machine and the node.
55
+ * Positive = node clock is ahead. null = couldn't determine.
56
+ * VMess AEAD fails if |drift| > 120s.
57
+ */
58
+ clockDriftSec: number | null;
59
+ /** Per-GB pricing (empty array -- not in v3 status, fetched from LCD) */
60
+ gigabyte_prices: unknown[];
61
+ /** Raw response object from node API */
62
+ _raw: unknown;
63
+ }
64
+
65
+ // ─── WireGuard ─────────────────────────────────────────────────────────────
66
+
67
+ /** WireGuard Curve25519 key pair from generateWgKeyPair(). */
68
+ export interface WgKeyPair {
69
+ /** Private key (32 bytes, bit-clamped per WG spec) */
70
+ privateKey: Buffer;
71
+ /** Public key (32 bytes, X25519 base point multiplication) */
72
+ publicKey: Buffer;
73
+ }
74
+
75
+ /** WireGuard configuration parameters for writeWgConfig(). */
76
+ export interface WgConfigOptions {
77
+ /**
78
+ * DNS servers as comma-separated string.
79
+ * Default: Handshake DNS with Google/Cloudflare fallbacks.
80
+ */
81
+ dns?: string;
82
+ /**
83
+ * MTU value. Sentinel nodes use 1280.
84
+ * Higher values may cause packet fragmentation issues.
85
+ */
86
+ mtu?: number;
87
+ /**
88
+ * Keepalive interval in seconds (default: 15).
89
+ * Prevents NAT timeout on residential connections.
90
+ */
91
+ keepalive?: number;
92
+ }
93
+
94
+ // ─── Handshake Results ─────────────────────────────────────────────────────
95
+
96
+ /**
97
+ * Result from WireGuard handshake (initHandshakeV3).
98
+ * Contains everything needed to configure the WG interface.
99
+ */
100
+ export interface HandshakeResult {
101
+ /** IP addresses assigned to our WireGuard interface (e.g. ['10.8.0.2/32']) */
102
+ assignedAddrs: string[];
103
+ /** Server's WireGuard public key (base64-encoded) */
104
+ serverPubKey: string;
105
+ /** Server's WireGuard endpoint (e.g. '185.47.255.36:52618') */
106
+ serverEndpoint: string;
107
+ /** Raw JSON config string from node response */
108
+ config: string;
109
+ /** Full handshake response object */
110
+ result: unknown;
111
+ }
112
+
113
+ /**
114
+ * Result from V2Ray handshake (initHandshakeV3V2Ray).
115
+ * Contains metadata for building the V2Ray client config.
116
+ */
117
+ export interface V2RayHandshakeResult {
118
+ /**
119
+ * JSON string of V2Ray metadata.
120
+ * Pass this to buildV2RayClientConfig() as the metadataJson parameter.
121
+ * Contains: transport type, port, service name, security settings.
122
+ */
123
+ config: string;
124
+ /** Full handshake response object */
125
+ result: unknown;
126
+ }
127
+
128
+ // ─── V2Ray Config ──────────────────────────────────────────────────────────
129
+
130
+ /** Options for buildV2RayClientConfig(). */
131
+ export interface V2RayConfigOptions {
132
+ /** DNS servers (comma-separated or preset name) */
133
+ dns?: string;
134
+ /** DNS preset name ('handshake', 'google', 'cloudflare') */
135
+ dnsPreset?: string;
136
+ }
137
+
138
+ /**
139
+ * V2Ray client configuration object (JSON structure).
140
+ * Generated by buildV2RayClientConfig(). Write this to a JSON file
141
+ * and pass to v2ray.exe as the config argument.
142
+ */
143
+ export interface V2RayConfig {
144
+ /** Log configuration */
145
+ log: { loglevel: string };
146
+ /** Inbound proxy configuration (SOCKS5) */
147
+ inbounds: Array<{
148
+ tag: string;
149
+ protocol: string;
150
+ listen: string;
151
+ port: number;
152
+ settings: { auth: string; udp: boolean };
153
+ }>;
154
+ /** Outbound configurations (one per transport/metadata entry) */
155
+ outbounds: Array<{
156
+ tag: string;
157
+ protocol: string;
158
+ settings: {
159
+ vnext?: Array<{
160
+ address: string;
161
+ port: number;
162
+ users: Array<{
163
+ id?: string;
164
+ uuid?: string;
165
+ encryption?: string;
166
+ alterId?: number;
167
+ security?: string;
168
+ }>;
169
+ }>;
170
+ };
171
+ streamSettings?: {
172
+ network: string;
173
+ security: string;
174
+ tlsSettings?: Record<string, unknown>;
175
+ grpcSettings?: Record<string, unknown>;
176
+ wsSettings?: Record<string, unknown>;
177
+ httpSettings?: Record<string, unknown>;
178
+ tcpSettings?: Record<string, unknown>;
179
+ kcpSettings?: Record<string, unknown>;
180
+ quicSettings?: Record<string, unknown>;
181
+ };
182
+ }>;
183
+ /** Routing rules (balancer, direct, DNS) */
184
+ routing?: {
185
+ domainStrategy: string;
186
+ rules: Array<Record<string, unknown>>;
187
+ balancers?: Array<Record<string, unknown>>;
188
+ };
189
+ /** DNS configuration */
190
+ dns?: { servers: string[] };
191
+ /** Observatory for active probing */
192
+ observatory?: Record<string, unknown>;
193
+ }
194
+
195
+ // ─── Transport Rates ───────────────────────────────────────────────────────
196
+
197
+ /** Static transport success rate (from 780-node scan). */
198
+ export interface TransportSuccessRate {
199
+ /** Success rate 0.0-1.0 */
200
+ rate: number;
201
+ /** Number of nodes tested */
202
+ sample: number;
203
+ /** Human-readable note about this transport */
204
+ note: string;
205
+ }
206
+
207
+ /** Dynamic transport rate (runtime tracking, persisted to disk). */
208
+ export interface DynamicTransportRate {
209
+ /** Success rate 0.0-1.0 */
210
+ rate: number;
211
+ /** Total samples (success + fail) */
212
+ sample: number;
213
+ }
214
+
215
+ // ─── Speed Testing ─────────────────────────────────────────────────────────
216
+
217
+ /** Speed test result from speedtestDirect() or speedtestViaSocks5(). */
218
+ export interface SpeedResult {
219
+ /** Download speed in Mbps */
220
+ mbps: number;
221
+ /** Number of chunks downloaded */
222
+ chunks: number;
223
+ /** Adaptive strategy used (e.g. 'full', 'probe-only') */
224
+ adaptive: string;
225
+ /** Total bytes downloaded */
226
+ totalBytes?: number;
227
+ /** Test duration in seconds */
228
+ seconds?: number;
229
+ /** Fallback host used (if primary failed) */
230
+ fallbackHost?: string;
231
+ }
232
+
233
+ /** Speed test comparison from compareSpeedTests(). */
234
+ export interface SpeedComparison {
235
+ /** True if after test is faster */
236
+ improved: boolean;
237
+ /** True if after test is slower */
238
+ degraded: boolean;
239
+ /** Raw delta values */
240
+ delta: {
241
+ downloadMbps: number;
242
+ uploadMbps: number;
243
+ latencyMs: number;
244
+ };
245
+ /** Percentage change */
246
+ percentChange: {
247
+ download: number;
248
+ upload: number;
249
+ };
250
+ }
251
+
252
+ /** Speed test configuration constants. */
253
+ export interface SpeedtestDefaults {
254
+ /** Bytes per chunk for download test */
255
+ readonly chunkBytes: number;
256
+ /** Number of chunks to download */
257
+ readonly chunkCount: number;
258
+ /** Bytes for initial probe */
259
+ readonly probeBytes: number;
260
+ /** Mbps threshold for full test vs probe-only */
261
+ readonly probeThresholdMbps: number;
262
+ /** Primary speed test host */
263
+ readonly primaryHost: string;
264
+ /** DNS cache TTL in ms */
265
+ readonly dnsCacheTtl: number;
266
+ /** Fallback speed test hosts */
267
+ readonly fallbackHosts: ReadonlyArray<{
268
+ host: string;
269
+ path: string;
270
+ size: number;
271
+ }>;
272
+ }
273
+
274
+ // ─── WireGuard Tunnel Management ───────────────────────────────────────────
275
+
276
+ /** Result from watchdogCheck() -- quick tunnel health check. */
277
+ export interface WatchdogResult {
278
+ /** Whether a tunnel is currently active */
279
+ active: boolean;
280
+ /** Tunnel name (e.g. 'sentinel0') */
281
+ name?: string;
282
+ /** Tunnel uptime in ms */
283
+ uptimeMs?: number;
284
+ }
285
+
286
+ /** Result from checkOrphanedTunnels(). */
287
+ export interface OrphanedTunnelCheck {
288
+ /** Whether orphaned tunnels were found */
289
+ found: boolean;
290
+ /** Names of orphaned tunnels */
291
+ tunnels: string[];
292
+ /** Whether cleanup was performed */
293
+ cleaned: boolean;
294
+ }
295
+
296
+ /** Result from cleanOrphanedTunnels(). */
297
+ export interface CleanOrphanedResult {
298
+ /** Number of tunnels cleaned */
299
+ cleaned: number;
300
+ /** Error messages for tunnels that couldn't be cleaned */
301
+ errors: string[];
302
+ }
303
+
304
+ /** Result from checkOrphanedV2Ray(). */
305
+ export interface OrphanedV2RayCheck {
306
+ /** Whether orphaned V2Ray processes were found */
307
+ found: boolean;
308
+ /** PIDs of orphaned processes */
309
+ pids: number[];
310
+ }
311
+
312
+ /** Result from checkVpnConflicts(). */
313
+ export interface VpnConflictCheck {
314
+ /** Detected VPN software that may conflict */
315
+ conflicts: Array<{
316
+ /** VPN software name */
317
+ name: string;
318
+ /** Whether it's currently running */
319
+ running: boolean;
320
+ }>;
321
+ }
322
+
323
+ /** Result from checkPortConflicts(). */
324
+ export interface PortConflictCheck {
325
+ /** Ports that are in use */
326
+ conflicts: Array<{
327
+ /** Port number */
328
+ port: number;
329
+ /** Whether the port is currently in use */
330
+ inUse: boolean;
331
+ }>;
332
+ }