@private.me/xbind 3.0.2 → 3.0.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.
Files changed (221) hide show
  1. package/README.md +2366 -204
  2. package/README.md.backup +2121 -0
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -729
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -463
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -315
  7. package/dist-standalone/_deps/shared/errors.js +1 -244
  8. package/dist-standalone/_deps/shared/index.js +1 -72
  9. package/dist-standalone/_deps/shared/types.js +1 -86
  10. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  20. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  21. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  28. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  29. package/dist-standalone/_deps/xchange/errors.js +1 -1
  30. package/dist-standalone/_deps/xchange/index.js +1 -1
  31. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  32. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  33. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  34. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  40. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  41. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  42. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  43. package/dist-standalone/_deps/xregistry/index.js +1 -1
  44. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  45. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  46. package/dist-standalone/_deps/xregistry/types.js +1 -1
  47. package/dist-standalone/agent-call.d.ts +2 -2
  48. package/dist-standalone/agent-call.js +1 -659
  49. package/dist-standalone/agent-sdk.js +1 -328
  50. package/dist-standalone/agent.d.ts +2 -0
  51. package/dist-standalone/agent.js +1 -1800
  52. package/dist-standalone/approval.js +1 -193
  53. package/dist-standalone/async-iterators.d.ts +3 -3
  54. package/dist-standalone/async-iterators.js +1 -382
  55. package/dist-standalone/auth.js +1 -219
  56. package/dist-standalone/auto-accept.js +1 -229
  57. package/dist-standalone/backup-config.js +1 -201
  58. package/dist-standalone/backup.js +1 -326
  59. package/dist-standalone/batch-operations.js +1 -388
  60. package/dist-standalone/cancellation.js +1 -477
  61. package/dist-standalone/checkpoint.js +1 -186
  62. package/dist-standalone/circuit-breaker.js +1 -468
  63. package/dist-standalone/cjs/agent-call.js +1 -701
  64. package/dist-standalone/cjs/agent-sdk.js +1 -332
  65. package/dist-standalone/cjs/agent.js +1 -1837
  66. package/dist-standalone/cjs/approval.js +1 -199
  67. package/dist-standalone/cjs/async-iterators.js +1 -392
  68. package/dist-standalone/cjs/auth.js +1 -225
  69. package/dist-standalone/cjs/auto-accept.js +1 -233
  70. package/dist-standalone/cjs/backup-config.js +1 -207
  71. package/dist-standalone/cjs/backup.js +1 -330
  72. package/dist-standalone/cjs/batch-operations.js +1 -397
  73. package/dist-standalone/cjs/cancellation.js +1 -490
  74. package/dist-standalone/cjs/checkpoint.js +1 -193
  75. package/dist-standalone/cjs/circuit-breaker.js +1 -476
  76. package/dist-standalone/cjs/cli/init.js +1 -492
  77. package/dist-standalone/cjs/config-validation.js +1 -522
  78. package/dist-standalone/cjs/connect.js +1 -312
  79. package/dist-standalone/cjs/connection-pool.js +1 -506
  80. package/dist-standalone/cjs/correlation-id.js +1 -339
  81. package/dist-standalone/cjs/crypto-utils.js +1 -176
  82. package/dist-standalone/cjs/debug-mode.js +1 -534
  83. package/dist-standalone/cjs/did-document.js +1 -101
  84. package/dist-standalone/cjs/did-privateme.js +1 -130
  85. package/dist-standalone/cjs/did-web.js +1 -201
  86. package/dist-standalone/cjs/discovery.js +1 -462
  87. package/dist-standalone/cjs/dual-mode.js +1 -251
  88. package/dist-standalone/cjs/email-templates.js +1 -313
  89. package/dist-standalone/cjs/email-transport.js +1 -239
  90. package/dist-standalone/cjs/envelope.js +1 -538
  91. package/dist-standalone/cjs/errors.js +1 -913
  92. package/dist-standalone/cjs/event-emitter.js +1 -461
  93. package/dist-standalone/cjs/gateway-state.js +1 -55
  94. package/dist-standalone/cjs/gateway-transport.js +1 -120
  95. package/dist-standalone/cjs/graceful-degradation.js +1 -403
  96. package/dist-standalone/cjs/guardrails.js +1 -223
  97. package/dist-standalone/cjs/health-check.js +1 -336
  98. package/dist-standalone/cjs/http-compat.js +1 -272
  99. package/dist-standalone/cjs/http-status-map.js +1 -571
  100. package/dist-standalone/cjs/identity.js +1 -645
  101. package/dist-standalone/cjs/index.js +1 -406
  102. package/dist-standalone/cjs/invitation.js +1 -421
  103. package/dist-standalone/cjs/invite.js +1 -328
  104. package/dist-standalone/cjs/key-agreement.js +1 -335
  105. package/dist-standalone/cjs/lazy-init.js +1 -300
  106. package/dist-standalone/cjs/logger.js +1 -291
  107. package/dist-standalone/cjs/loopback-transport.js +1 -0
  108. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  109. package/dist-standalone/cjs/nonce-store.js +1 -80
  110. package/dist-standalone/cjs/pairing-manager.js +1 -223
  111. package/dist-standalone/cjs/plugin-system.js +1 -264
  112. package/dist-standalone/cjs/plugins/logging.js +1 -168
  113. package/dist-standalone/cjs/plugins/metrics.js +1 -181
  114. package/dist-standalone/cjs/plugins/validation.js +1 -302
  115. package/dist-standalone/cjs/policy.js +1 -320
  116. package/dist-standalone/cjs/progress-callbacks.js +1 -583
  117. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  118. package/dist-standalone/cjs/registry-middleware.js +1 -50
  119. package/dist-standalone/cjs/retry-strategies.js +1 -544
  120. package/dist-standalone/cjs/retry-transport.js +1 -102
  121. package/dist-standalone/cjs/runtime/browser.js +1 -533
  122. package/dist-standalone/cjs/runtime/edge.js +1 -526
  123. package/dist-standalone/cjs/runtime/react-native.js +1 -394
  124. package/dist-standalone/cjs/security-policy.js +1 -245
  125. package/dist-standalone/cjs/serialization.js +1 -1040
  126. package/dist-standalone/cjs/split-channel.js +1 -225
  127. package/dist-standalone/cjs/subscription-proof.js +1 -230
  128. package/dist-standalone/cjs/succession.js +1 -148
  129. package/dist-standalone/cjs/timeouts.js +1 -412
  130. package/dist-standalone/cjs/trace-context.js +1 -424
  131. package/dist-standalone/cjs/trace-spans.js +1 -495
  132. package/dist-standalone/cjs/transport.js +1 -63
  133. package/dist-standalone/cjs/trust-registry.js +1 -991
  134. package/dist-standalone/cjs/types/error-response.js +1 -56
  135. package/dist-standalone/cjs/vault-auth.js +1 -178
  136. package/dist-standalone/cjs/vault-store-loader.js +1 -194
  137. package/dist-standalone/cjs/verify.js +1 -25
  138. package/dist-standalone/cjs/version-info.js +1 -543
  139. package/dist-standalone/cjs/xfetch.js +1 -340
  140. package/dist-standalone/cli/init.js +1 -455
  141. package/dist-standalone/cli/setup.js +1 -514
  142. package/dist-standalone/cli/types.js +1 -27
  143. package/dist-standalone/cli/xbind.js +1 -148
  144. package/dist-standalone/config-validation.js +1 -513
  145. package/dist-standalone/connect.js +1 -274
  146. package/dist-standalone/connection-pool.js +1 -500
  147. package/dist-standalone/correlation-id.js +1 -326
  148. package/dist-standalone/crypto-utils.d.ts +2 -7
  149. package/dist-standalone/crypto-utils.js +1 -157
  150. package/dist-standalone/debug-mode.js +1 -510
  151. package/dist-standalone/did-document.js +1 -96
  152. package/dist-standalone/did-privateme.js +1 -121
  153. package/dist-standalone/did-web.js +1 -196
  154. package/dist-standalone/discovery.js +1 -458
  155. package/dist-standalone/dual-mode.js +1 -247
  156. package/dist-standalone/email-templates.js +1 -309
  157. package/dist-standalone/email-transport.d.ts +2 -2
  158. package/dist-standalone/email-transport.js +1 -232
  159. package/dist-standalone/envelope.js +1 -525
  160. package/dist-standalone/errors.d.ts +13 -3
  161. package/dist-standalone/errors.js +1 -896
  162. package/dist-standalone/event-emitter.js +1 -456
  163. package/dist-standalone/gateway-state.d.ts +1 -1
  164. package/dist-standalone/gateway-state.js +1 -51
  165. package/dist-standalone/gateway-transport.js +1 -116
  166. package/dist-standalone/graceful-degradation.js +1 -396
  167. package/dist-standalone/guardrails.js +1 -216
  168. package/dist-standalone/health-check.d.ts +5 -1
  169. package/dist-standalone/health-check.js +1 -332
  170. package/dist-standalone/http-compat.d.ts +1 -1
  171. package/dist-standalone/http-compat.js +1 -267
  172. package/dist-standalone/http-status-map.js +1 -561
  173. package/dist-standalone/identity.js +1 -619
  174. package/dist-standalone/index.d.ts +15 -4
  175. package/dist-standalone/index.js +1 -78
  176. package/dist-standalone/invitation.js +1 -415
  177. package/dist-standalone/invite.js +1 -324
  178. package/dist-standalone/key-agreement.js +1 -325
  179. package/dist-standalone/lazy-init.d.ts +11 -6
  180. package/dist-standalone/lazy-init.js +1 -295
  181. package/dist-standalone/logger.js +1 -285
  182. package/dist-standalone/loopback-transport.d.ts +87 -0
  183. package/dist-standalone/loopback-transport.js +1 -0
  184. package/dist-standalone/mdns-discovery.js +1 -195
  185. package/dist-standalone/nonce-store.js +1 -76
  186. package/dist-standalone/pairing-manager.js +1 -219
  187. package/dist-standalone/plugin-system.js +1 -257
  188. package/dist-standalone/plugins/logging.js +1 -163
  189. package/dist-standalone/plugins/metrics.d.ts +4 -4
  190. package/dist-standalone/plugins/metrics.js +1 -176
  191. package/dist-standalone/plugins/validation.js +1 -297
  192. package/dist-standalone/policy.js +1 -315
  193. package/dist-standalone/progress-callbacks.js +1 -576
  194. package/dist-standalone/redis-nonce-store.js +1 -72
  195. package/dist-standalone/registry-middleware.js +1 -47
  196. package/dist-standalone/retry-strategies.js +1 -534
  197. package/dist-standalone/retry-transport.js +1 -98
  198. package/dist-standalone/runtime/browser.js +1 -516
  199. package/dist-standalone/runtime/edge.js +1 -511
  200. package/dist-standalone/runtime/react-native.d.ts +1 -1
  201. package/dist-standalone/runtime/react-native.js +1 -383
  202. package/dist-standalone/security-policy.js +1 -239
  203. package/dist-standalone/serialization.js +1 -1031
  204. package/dist-standalone/split-channel.js +1 -219
  205. package/dist-standalone/subscription-proof.js +1 -224
  206. package/dist-standalone/succession.js +1 -142
  207. package/dist-standalone/timeouts.js +1 -398
  208. package/dist-standalone/trace-context.js +1 -414
  209. package/dist-standalone/trace-spans.js +1 -488
  210. package/dist-standalone/transport.js +1 -59
  211. package/dist-standalone/trust-registry.d.ts +3 -3
  212. package/dist-standalone/trust-registry.js +1 -950
  213. package/dist-standalone/types/error-response.js +1 -52
  214. package/dist-standalone/vault-auth.js +1 -174
  215. package/dist-standalone/vault-store-loader.d.ts +9 -0
  216. package/dist-standalone/vault-store-loader.js +1 -187
  217. package/dist-standalone/verify.js +1 -16
  218. package/dist-standalone/version-info.js +1 -530
  219. package/dist-standalone/xfetch.js +1 -335
  220. package/package.json +1 -1
  221. package/share1.dat +0 -0
@@ -1,522 +1 @@
1
- "use strict";
2
- /**
3
- * @module config-validation
4
- * Configuration validation for xBind agent initialization.
5
- *
6
- * Provides schema validation, type checking, and clear error messages
7
- * for AgentOptions and AgentCreateOptions to enhance configuration safety
8
- * and improve developer experience.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { validateAgentOptions, validateAgentCreateOptions } from '@private.me/xbind';
13
- *
14
- * // Validate simplified options
15
- * const simpleResult = validateAgentOptions({
16
- * identity: 'persistent',
17
- * registry: 'https://private.me/registry'
18
- * });
19
- *
20
- * if (!simpleResult.ok) {
21
- * console.error(simpleResult.error); // Clear, actionable error message
22
- * }
23
- *
24
- * // Validate full options
25
- * const fullResult = validateAgentCreateOptions({
26
- * name: 'my-agent',
27
- * registry: myRegistryInstance,
28
- * transport: myTransportAdapter
29
- * });
30
- * ```
31
- */
32
- Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.AGENT_CREATE_OPTIONS_DEFAULTS = exports.AGENT_OPTIONS_DEFAULTS = exports.ConfigValidationError = void 0;
34
- exports.validateAgentOptions = validateAgentOptions;
35
- exports.validateAgentCreateOptions = validateAgentCreateOptions;
36
- exports.getValidationDetails = getValidationDetails;
37
- exports.assertValidConfig = assertValidConfig;
38
- exports.assertValidCreateConfig = assertValidCreateConfig;
39
- const shared_1 = require("../_deps/shared/index.js");
40
- const errors_js_1 = require("./errors.js");
41
- /**
42
- * Configuration validation error with detailed context.
43
- */
44
- class ConfigValidationError extends errors_js_1.XBindError {
45
- /** Field that failed validation */
46
- field;
47
- /** Expected value/type */
48
- expected;
49
- /** Actual value received */
50
- actual;
51
- /** Suggested fix */
52
- fix;
53
- constructor(field, expected, actual, fix) {
54
- const message = `Configuration validation failed for '${field}': Expected ${expected}, got ${typeof actual === 'object' && actual !== null ? JSON.stringify(actual) : String(actual)}. ${fix}`;
55
- super('CONFIG_INVALID', message, 'https://private.me/docs/xbind/api/configuration');
56
- this.name = 'ConfigValidationError';
57
- this.field = field;
58
- this.expected = expected;
59
- this.actual = actual;
60
- this.fix = fix;
61
- }
62
- }
63
- exports.ConfigValidationError = ConfigValidationError;
64
- /**
65
- * Default values for AgentOptions.
66
- */
67
- exports.AGENT_OPTIONS_DEFAULTS = {
68
- identity: 'persistent',
69
- identityTTL: 3600000, // 1 hour
70
- postQuantumSig: false,
71
- };
72
- /**
73
- * Default values for AgentCreateOptions.
74
- */
75
- exports.AGENT_CREATE_OPTIONS_DEFAULTS = {
76
- timestampWindowMs: 30000, // 30 seconds
77
- postQuantumSig: false,
78
- xchange: false,
79
- scopes: [],
80
- };
81
- /**
82
- * Validate AgentOptions configuration.
83
- *
84
- * Checks all fields for correct types, valid values, and logical consistency.
85
- * Provides clear, actionable error messages for any validation failures.
86
- *
87
- * @param options - AgentOptions to validate
88
- * @returns Result with validation errors or success
89
- *
90
- * @example
91
- * ```typescript
92
- * const result = validateAgentOptions({
93
- * identity: 'persistent',
94
- * registry: 'https://private.me/registry',
95
- * identityTTL: 7200000 // 2 hours
96
- * });
97
- *
98
- * if (result.ok) {
99
- * console.log('Configuration valid!');
100
- * } else {
101
- * console.error(result.error);
102
- * }
103
- * ```
104
- */
105
- function validateAgentOptions(options) {
106
- if (!options || typeof options !== 'object') {
107
- return (0, shared_1.err)(new ConfigValidationError('options', 'object', options, 'Provide a configuration object with at least one option.'));
108
- }
109
- const opts = options;
110
- const errors = [];
111
- const warnings = [];
112
- // Validate identity mode
113
- if (opts.identity !== undefined) {
114
- if (typeof opts.identity !== 'string') {
115
- errors.push(new ConfigValidationError('identity', "'persistent' | 'ephemeral'", opts.identity, "Use 'persistent' for long-lived DIDs or 'ephemeral' for short-lived DIDs."));
116
- }
117
- else if (opts.identity !== 'persistent' && opts.identity !== 'ephemeral') {
118
- errors.push(new ConfigValidationError('identity', "'persistent' | 'ephemeral'", opts.identity, `Invalid identity mode. Use 'persistent' or 'ephemeral'.`));
119
- }
120
- }
121
- // Validate identityTTL
122
- if (opts.identityTTL !== undefined) {
123
- if (typeof opts.identityTTL !== 'number') {
124
- errors.push(new ConfigValidationError('identityTTL', 'number (milliseconds)', opts.identityTTL, 'Provide TTL as a number in milliseconds (e.g., 3600000 for 1 hour).'));
125
- }
126
- else if (opts.identityTTL <= 0) {
127
- errors.push(new ConfigValidationError('identityTTL', 'positive number', opts.identityTTL, 'TTL must be greater than 0. Use at least 60000 (1 minute).'));
128
- }
129
- else if (opts.identityTTL < 60000) {
130
- warnings.push(`identityTTL is very short (${opts.identityTTL}ms). Consider using at least 60000ms (1 minute) to avoid frequent re-registrations.`);
131
- }
132
- else if (opts.identityTTL > 86400000) {
133
- warnings.push(`identityTTL is very long (${opts.identityTTL}ms). Consider using 'persistent' identity mode instead for long-lived agents.`);
134
- }
135
- // Warn if TTL specified but identity is not ephemeral
136
- if (opts.identity === 'persistent') {
137
- warnings.push("identityTTL is ignored for 'persistent' identity mode. Remove this option or switch to 'ephemeral' mode.");
138
- }
139
- }
140
- // Validate registry
141
- if (opts.registry !== undefined) {
142
- const isString = typeof opts.registry === 'string';
143
- const isObject = typeof opts.registry === 'object' && opts.registry !== null;
144
- if (!isString && !isObject) {
145
- errors.push(new ConfigValidationError('registry', 'TrustRegistry instance or URL string', opts.registry, 'Provide either a registry URL (e.g., "https://private.me/registry") or a TrustRegistry instance.'));
146
- }
147
- else if (isString) {
148
- const url = opts.registry;
149
- try {
150
- const parsed = new URL(url);
151
- if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
152
- errors.push(new ConfigValidationError('registry', 'HTTP(S) URL', url, 'Registry URL must use HTTP or HTTPS protocol.'));
153
- }
154
- }
155
- catch {
156
- errors.push(new ConfigValidationError('registry', 'valid URL', url, 'Provide a valid URL (e.g., "https://private.me/registry").'));
157
- }
158
- }
159
- else if (isObject) {
160
- // Validate TrustRegistry interface
161
- const registry = opts.registry;
162
- const requiredMethods = ['register', 'resolve'];
163
- const missingMethods = requiredMethods.filter((method) => !(method in registry) || typeof registry[method] !== 'function');
164
- if (missingMethods.length > 0) {
165
- errors.push(new ConfigValidationError('registry', 'TrustRegistry instance', 'object missing required methods', `TrustRegistry must implement ${missingMethods.join(', ')} method(s). Use HttpTrustRegistry or MemoryTrustRegistry.`));
166
- }
167
- }
168
- }
169
- // Validate transport
170
- if (opts.transport !== undefined) {
171
- const isArray = Array.isArray(opts.transport);
172
- const isSingleTransport = typeof opts.transport === 'object' && opts.transport !== null && !isArray;
173
- if (!isSingleTransport && !isArray) {
174
- errors.push(new ConfigValidationError('transport', 'XailTransportAdapter or XailTransportAdapter[]', opts.transport, 'Provide a single transport adapter or an array of adapters for split-channel security.'));
175
- }
176
- else if (isArray) {
177
- const transports = opts.transport;
178
- if (transports.length === 0) {
179
- errors.push(new ConfigValidationError('transport', 'non-empty array', transports, 'Provide at least one transport adapter.'));
180
- }
181
- // Validate each transport in array
182
- transports.forEach((transport, index) => {
183
- if (typeof transport !== 'object' || transport === null) {
184
- errors.push(new ConfigValidationError(`transport[${index}]`, 'XailTransportAdapter', transport, 'Each transport must be a XailTransportAdapter instance.'));
185
- }
186
- else {
187
- const t = transport;
188
- if (!('send' in t) || typeof t.send !== 'function') {
189
- errors.push(new ConfigValidationError(`transport[${index}]`, 'XailTransportAdapter with send() method', 'object missing send() method', 'Transport must implement send() method. Use HttpsTransportAdapter or custom adapter.'));
190
- }
191
- }
192
- });
193
- }
194
- else {
195
- // Validate single transport
196
- const transport = opts.transport;
197
- if (!('send' in transport) || typeof transport.send !== 'function') {
198
- errors.push(new ConfigValidationError('transport', 'XailTransportAdapter with send() method', 'object missing send() method', 'Transport must implement send() method. Use HttpsTransportAdapter or custom adapter.'));
199
- }
200
- }
201
- }
202
- // Validate securityPolicy
203
- if (opts.securityPolicy !== undefined) {
204
- if (typeof opts.securityPolicy !== 'object' || opts.securityPolicy === null) {
205
- errors.push(new ConfigValidationError('securityPolicy', 'SecurityPolicy instance', opts.securityPolicy, 'Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy).'));
206
- }
207
- else {
208
- const policy = opts.securityPolicy;
209
- if (!('classify' in policy) || typeof policy.classify !== 'function') {
210
- errors.push(new ConfigValidationError('securityPolicy', 'SecurityPolicy with classify() method', 'object missing classify() method', 'SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy.'));
211
- }
212
- }
213
- }
214
- // Validate postQuantumSig
215
- if (opts.postQuantumSig !== undefined) {
216
- if (typeof opts.postQuantumSig !== 'boolean') {
217
- errors.push(new ConfigValidationError('postQuantumSig', 'boolean', opts.postQuantumSig, 'Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.'));
218
- }
219
- }
220
- // Validate backupConfig
221
- if (opts.backupConfig !== undefined) {
222
- if (typeof opts.backupConfig !== 'object' || opts.backupConfig === null) {
223
- errors.push(new ConfigValidationError('backupConfig', 'BackupConfig object', opts.backupConfig, 'Provide a BackupConfig object with threshold (k) and totalShares (n) properties.'));
224
- }
225
- else {
226
- const config = opts.backupConfig;
227
- if (typeof config.threshold !== 'number') {
228
- errors.push(new ConfigValidationError('backupConfig.threshold', 'number', config.threshold, 'Threshold (k) must be a number representing shares needed for reconstruction.'));
229
- }
230
- else if (config.threshold < 2) {
231
- errors.push(new ConfigValidationError('backupConfig.threshold', 'number >= 2', config.threshold, 'Threshold must be at least 2 for meaningful splitting.'));
232
- }
233
- if (typeof config.totalShares !== 'number') {
234
- errors.push(new ConfigValidationError('backupConfig.totalShares', 'number', config.totalShares, 'totalShares (n) must be a number representing total shares to create.'));
235
- }
236
- else if (config.totalShares < 2) {
237
- errors.push(new ConfigValidationError('backupConfig.totalShares', 'number >= 2', config.totalShares, 'totalShares must be at least 2 for splitting.'));
238
- }
239
- // Validate threshold <= totalShares
240
- if (typeof config.threshold === 'number' &&
241
- typeof config.totalShares === 'number' &&
242
- config.threshold > config.totalShares) {
243
- errors.push(new ConfigValidationError('backupConfig', 'threshold <= totalShares', `threshold=${config.threshold}, totalShares=${config.totalShares}`, `Threshold (${config.threshold}) cannot exceed totalShares (${config.totalShares}). Use threshold <= totalShares.`));
244
- }
245
- }
246
- }
247
- // Return first error or success
248
- if (errors.length > 0) {
249
- return (0, shared_1.err)(errors[0]);
250
- }
251
- return (0, shared_1.ok)(opts);
252
- }
253
- /**
254
- * Validate AgentCreateOptions configuration.
255
- *
256
- * Checks all fields for correct types, valid values, and logical consistency.
257
- * Provides clear, actionable error messages for any validation failures.
258
- *
259
- * @param options - AgentCreateOptions to validate
260
- * @returns Result with validation errors or success
261
- *
262
- * @example
263
- * ```typescript
264
- * const result = validateAgentCreateOptions({
265
- * name: 'my-agent',
266
- * registry: new MemoryTrustRegistry(),
267
- * transport: new HttpsTransportAdapter(),
268
- * timestampWindowMs: 60000 // 1 minute
269
- * });
270
- *
271
- * if (result.ok) {
272
- * console.log('Configuration valid!');
273
- * } else {
274
- * console.error(result.error);
275
- * }
276
- * ```
277
- */
278
- function validateAgentCreateOptions(options) {
279
- if (!options || typeof options !== 'object') {
280
- return (0, shared_1.err)(new ConfigValidationError('options', 'object', options, 'Provide a configuration object with required fields: name, registry, transport.'));
281
- }
282
- const opts = options;
283
- const errors = [];
284
- // Validate required fields
285
- if (opts.name === undefined) {
286
- errors.push(new ConfigValidationError('name', 'string (required)', undefined, 'Provide a display name for the agent (e.g., "my-agent").'));
287
- }
288
- else if (typeof opts.name !== 'string') {
289
- errors.push(new ConfigValidationError('name', 'string', opts.name, 'Agent name must be a string.'));
290
- }
291
- else if (opts.name.trim().length === 0) {
292
- errors.push(new ConfigValidationError('name', 'non-empty string', opts.name, 'Agent name cannot be empty or whitespace only.'));
293
- }
294
- else if (opts.name.length > 255) {
295
- errors.push(new ConfigValidationError('name', 'string with length <= 255', opts.name, `Agent name is too long (${opts.name.length} characters). Use 255 characters or less.`));
296
- }
297
- // Validate required registry
298
- if (opts.registry === undefined) {
299
- errors.push(new ConfigValidationError('registry', 'TrustRegistry (required)', undefined, 'Provide a TrustRegistry instance (e.g., new MemoryTrustRegistry() or new HttpTrustRegistry()).'));
300
- }
301
- else if (typeof opts.registry !== 'object' || opts.registry === null) {
302
- errors.push(new ConfigValidationError('registry', 'TrustRegistry instance', opts.registry, 'Registry must be a TrustRegistry instance, not a string or primitive value.'));
303
- }
304
- else {
305
- // Validate TrustRegistry interface
306
- const registry = opts.registry;
307
- const requiredMethods = ['register', 'resolve'];
308
- const missingMethods = requiredMethods.filter((method) => !(method in registry) || typeof registry[method] !== 'function');
309
- if (missingMethods.length > 0) {
310
- errors.push(new ConfigValidationError('registry', 'TrustRegistry instance', 'object missing required methods', `TrustRegistry must implement: ${missingMethods.join(', ')}. Use HttpTrustRegistry or MemoryTrustRegistry.`));
311
- }
312
- }
313
- // Validate required transport
314
- if (opts.transport === undefined) {
315
- errors.push(new ConfigValidationError('transport', 'XailTransportAdapter or XailTransportAdapter[] (required)', undefined, 'Provide a transport adapter (e.g., new HttpsTransportAdapter()) or array of adapters for split-channel.'));
316
- }
317
- else {
318
- const isArray = Array.isArray(opts.transport);
319
- const isSingleTransport = typeof opts.transport === 'object' && opts.transport !== null && !isArray;
320
- if (!isSingleTransport && !isArray) {
321
- errors.push(new ConfigValidationError('transport', 'XailTransportAdapter or XailTransportAdapter[]', opts.transport, 'Provide a single transport adapter or an array of adapters.'));
322
- }
323
- else if (isArray) {
324
- const transports = opts.transport;
325
- if (transports.length === 0) {
326
- errors.push(new ConfigValidationError('transport', 'non-empty array', transports, 'Provide at least one transport adapter.'));
327
- }
328
- // Validate each transport in array
329
- transports.forEach((transport, index) => {
330
- if (typeof transport !== 'object' || transport === null) {
331
- errors.push(new ConfigValidationError(`transport[${index}]`, 'XailTransportAdapter', transport, 'Each transport must be a XailTransportAdapter instance.'));
332
- }
333
- else {
334
- const t = transport;
335
- if (!('send' in t) || typeof t.send !== 'function') {
336
- errors.push(new ConfigValidationError(`transport[${index}]`, 'XailTransportAdapter with send() method', 'object missing send() method', 'Transport must implement send() method. Use HttpsTransportAdapter or custom adapter.'));
337
- }
338
- }
339
- });
340
- }
341
- else {
342
- // Validate single transport
343
- const transport = opts.transport;
344
- if (!('send' in transport) || typeof transport.send !== 'function') {
345
- errors.push(new ConfigValidationError('transport', 'XailTransportAdapter with send() method', 'object missing send() method', 'Transport must implement send() method. Use HttpsTransportAdapter or custom adapter.'));
346
- }
347
- }
348
- }
349
- // Validate optional nonceStore
350
- if (opts.nonceStore !== undefined) {
351
- if (typeof opts.nonceStore !== 'object' || opts.nonceStore === null) {
352
- errors.push(new ConfigValidationError('nonceStore', 'NonceStore instance', opts.nonceStore, 'Provide a NonceStore instance (e.g., new MemoryNonceStore()).'));
353
- }
354
- else {
355
- const store = opts.nonceStore;
356
- const requiredMethods = ['check', 'cleanup'];
357
- const missingMethods = requiredMethods.filter((method) => !(method in store) || typeof store[method] !== 'function');
358
- if (missingMethods.length > 0) {
359
- errors.push(new ConfigValidationError('nonceStore', 'NonceStore instance', 'object missing required methods', `NonceStore must implement: ${missingMethods.join(', ')}. Use MemoryNonceStore.`));
360
- }
361
- }
362
- }
363
- // Validate scopes
364
- if (opts.scopes !== undefined) {
365
- if (!Array.isArray(opts.scopes)) {
366
- errors.push(new ConfigValidationError('scopes', 'string[]', opts.scopes, 'Provide an array of scope strings (e.g., ["read", "write"]).'));
367
- }
368
- else {
369
- const scopes = opts.scopes;
370
- scopes.forEach((scope, index) => {
371
- if (typeof scope !== 'string') {
372
- errors.push(new ConfigValidationError(`scopes[${index}]`, 'string', scope, 'Each scope must be a string.'));
373
- }
374
- else if (scope.trim().length === 0) {
375
- errors.push(new ConfigValidationError(`scopes[${index}]`, 'non-empty string', scope, 'Scope cannot be empty or whitespace only.'));
376
- }
377
- });
378
- }
379
- }
380
- // Validate timestampWindowMs
381
- if (opts.timestampWindowMs !== undefined) {
382
- if (typeof opts.timestampWindowMs !== 'number') {
383
- errors.push(new ConfigValidationError('timestampWindowMs', 'number (milliseconds)', opts.timestampWindowMs, 'Provide timestamp window as a number in milliseconds (e.g., 30000 for 30 seconds).'));
384
- }
385
- else if (opts.timestampWindowMs <= 0) {
386
- errors.push(new ConfigValidationError('timestampWindowMs', 'positive number', opts.timestampWindowMs, 'Timestamp window must be greater than 0. Use at least 1000 (1 second).'));
387
- }
388
- else if (opts.timestampWindowMs < 5000) {
389
- errors.push(new ConfigValidationError('timestampWindowMs', 'number >= 5000', opts.timestampWindowMs, 'Timestamp window is very short. Use at least 5000ms (5 seconds) to account for clock skew.'));
390
- }
391
- else if (opts.timestampWindowMs > 300000) {
392
- errors.push(new ConfigValidationError('timestampWindowMs', 'number <= 300000', opts.timestampWindowMs, 'Timestamp window is very long. Consider using 300000ms (5 minutes) or less for security.'));
393
- }
394
- }
395
- // Validate postQuantumSig
396
- if (opts.postQuantumSig !== undefined) {
397
- if (typeof opts.postQuantumSig !== 'boolean') {
398
- errors.push(new ConfigValidationError('postQuantumSig', 'boolean', opts.postQuantumSig, 'Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.'));
399
- }
400
- }
401
- // Validate xchange
402
- if (opts.xchange !== undefined) {
403
- if (typeof opts.xchange !== 'boolean') {
404
- errors.push(new ConfigValidationError('xchange', 'boolean', opts.xchange, 'Use true to advertise Xchange mode support, or false to disable.'));
405
- }
406
- }
407
- // Validate securityPolicy
408
- if (opts.securityPolicy !== undefined) {
409
- if (typeof opts.securityPolicy !== 'object' || opts.securityPolicy === null) {
410
- errors.push(new ConfigValidationError('securityPolicy', 'SecurityPolicy instance', opts.securityPolicy, 'Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy).'));
411
- }
412
- else {
413
- const policy = opts.securityPolicy;
414
- if (!('classify' in policy) || typeof policy.classify !== 'function') {
415
- errors.push(new ConfigValidationError('securityPolicy', 'SecurityPolicy with classify() method', 'object missing classify() method', 'SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy.'));
416
- }
417
- }
418
- }
419
- // Return first error or success
420
- if (errors.length > 0) {
421
- return (0, shared_1.err)(errors[0]);
422
- }
423
- return (0, shared_1.ok)(opts);
424
- }
425
- /**
426
- * Get detailed validation result with all errors and warnings.
427
- *
428
- * Unlike the Result-based validators, this function returns all validation
429
- * issues at once for comprehensive feedback.
430
- *
431
- * @param options - AgentOptions to validate
432
- * @returns ValidationResult with all errors and warnings
433
- *
434
- * @example
435
- * ```typescript
436
- * const result = getValidationDetails({
437
- * identity: 'invalid',
438
- * identityTTL: -100,
439
- * postQuantumSig: 'yes' // type error
440
- * });
441
- *
442
- * console.log(`Valid: ${result.valid}`);
443
- * console.log(`Errors: ${result.errors.length}`);
444
- * console.log(`Warnings: ${result.warnings.length}`);
445
- *
446
- * result.errors.forEach(err => {
447
- * console.error(`- ${err.field}: ${err.message}`);
448
- * });
449
- * ```
450
- */
451
- function getValidationDetails(options) {
452
- const errors = [];
453
- const warnings = [];
454
- // Run validation and collect all errors
455
- const result = validateAgentOptions(options);
456
- if (!result.ok) {
457
- errors.push(result.error);
458
- }
459
- // Check for warning conditions (even if validation passed)
460
- if (options && typeof options === 'object') {
461
- const opts = options;
462
- // Check for warning conditions
463
- if (typeof opts.identityTTL === 'number') {
464
- if (opts.identityTTL < 60000 && opts.identityTTL > 0) {
465
- warnings.push(`identityTTL is very short (${opts.identityTTL}ms). Consider using at least 60000ms (1 minute).`);
466
- }
467
- else if (opts.identityTTL > 86400000) {
468
- warnings.push(`identityTTL is very long (${opts.identityTTL}ms). Consider using 'persistent' identity mode instead.`);
469
- }
470
- if (opts.identity === 'persistent') {
471
- warnings.push("identityTTL is ignored for 'persistent' identity mode.");
472
- }
473
- }
474
- }
475
- return {
476
- valid: errors.length === 0,
477
- errors,
478
- warnings,
479
- };
480
- }
481
- /**
482
- * Validate configuration and throw on error.
483
- *
484
- * Convenience function that validates configuration and throws
485
- * ConfigValidationError if validation fails.
486
- *
487
- * @param options - AgentOptions or AgentCreateOptions to validate
488
- * @throws ConfigValidationError if validation fails
489
- *
490
- * @example
491
- * ```typescript
492
- * try {
493
- * assertValidConfig({
494
- * identity: 'persistent',
495
- * registry: 'https://private.me/registry'
496
- * });
497
- * // Configuration is valid, continue
498
- * } catch (err) {
499
- * if (err instanceof ConfigValidationError) {
500
- * console.error(`Invalid ${err.field}: ${err.fix}`);
501
- * }
502
- * }
503
- * ```
504
- */
505
- function assertValidConfig(options) {
506
- const result = validateAgentOptions(options);
507
- if (!result.ok) {
508
- throw result.error;
509
- }
510
- }
511
- /**
512
- * Validate configuration and throw on error (full options).
513
- *
514
- * @param options - AgentCreateOptions to validate
515
- * @throws ConfigValidationError if validation fails
516
- */
517
- function assertValidCreateConfig(options) {
518
- const result = validateAgentCreateOptions(options);
519
- if (!result.ok) {
520
- throw result.error;
521
- }
522
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AGENT_CREATE_OPTIONS_DEFAULTS=exports.AGENT_OPTIONS_DEFAULTS=exports.ConfigValidationError=void 0,exports.validateAgentOptions=validateAgentOptions,exports.validateAgentCreateOptions=validateAgentCreateOptions,exports.getValidationDetails=getValidationDetails,exports.assertValidConfig=assertValidConfig,exports.assertValidCreateConfig=assertValidCreateConfig;const shared_1=require("../_deps/shared/index.js"),errors_js_1=require("./errors.js");class ConfigValidationError extends errors_js_1.XBindError{field;expected;actual;fix;constructor(t,e,r,i){super("CONFIG_INVALID",`Configuration validation failed for '${t}': Expected ${e}, got ${"object"==typeof r&&null!==r?JSON.stringify(r):String(r)}. ${i}`,"https://private.me/docs/xbind/api/configuration"),this.name="ConfigValidationError",this.field=t,this.expected=e,this.actual=r,this.fix=i}}function validateAgentOptions(t){if(!t||"object"!=typeof t)return(0,shared_1.err)(new ConfigValidationError("options","object",t,"Provide a configuration object with at least one option."));const e=t,r=[],i=[];if(void 0!==e.identity&&("string"!=typeof e.identity?r.push(new ConfigValidationError("identity","'persistent' | 'ephemeral'",e.identity,"Use 'persistent' for long-lived DIDs or 'ephemeral' for short-lived DIDs.")):"persistent"!==e.identity&&"ephemeral"!==e.identity&&r.push(new ConfigValidationError("identity","'persistent' | 'ephemeral'",e.identity,"Invalid identity mode. Use 'persistent' or 'ephemeral'."))),void 0!==e.identityTTL&&("number"!=typeof e.identityTTL?r.push(new ConfigValidationError("identityTTL","number (milliseconds)",e.identityTTL,"Provide TTL as a number in milliseconds (e.g., 3600000 for 1 hour).")):e.identityTTL<=0?r.push(new ConfigValidationError("identityTTL","positive number",e.identityTTL,"TTL must be greater than 0. Use at least 60000 (1 minute).")):e.identityTTL<6e4?i.push(`identityTTL is very short (${e.identityTTL}ms). Consider using at least 60000ms (1 minute) to avoid frequent re-registrations.`):e.identityTTL>864e5&&i.push(`identityTTL is very long (${e.identityTTL}ms). Consider using 'persistent' identity mode instead for long-lived agents.`),"persistent"===e.identity&&i.push("identityTTL is ignored for 'persistent' identity mode. Remove this option or switch to 'ephemeral' mode.")),void 0!==e.registry){const t="string"==typeof e.registry,i="object"==typeof e.registry&&null!==e.registry;if(t||i){if(t){const t=e.registry;try{const e=new URL(t);"http:"!==e.protocol&&"https:"!==e.protocol&&r.push(new ConfigValidationError("registry","HTTP(S) URL",t,"Registry URL must use HTTP or HTTPS protocol."))}catch{r.push(new ConfigValidationError("registry","valid URL",t,'Provide a valid URL (e.g., "https://private.me/registry").'))}}else if(i){const t=e.registry,i=["register","resolve"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("registry","TrustRegistry instance","object missing required methods",`TrustRegistry must implement ${i.join(", ")} method(s). Use HttpTrustRegistry or MemoryTrustRegistry.`))}}else r.push(new ConfigValidationError("registry","TrustRegistry instance or URL string",e.registry,'Provide either a registry URL (e.g., "https://private.me/registry") or a TrustRegistry instance.'))}if(void 0!==e.transport){const t=Array.isArray(e.transport);if("object"==typeof e.transport&&null!==e.transport&&!t||t)if(t){const t=e.transport;0===t.length&&r.push(new ConfigValidationError("transport","non-empty array",t,"Provide at least one transport adapter.")),t.forEach((t,e)=>{if("object"!=typeof t||null===t)r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter",t,"Each transport must be a XailTransportAdapter instance."));else{"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}})}else{const t=e.transport;"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError("transport","XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}else r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[]",e.transport,"Provide a single transport adapter or an array of adapters for split-channel security."))}if(void 0!==e.securityPolicy)if("object"!=typeof e.securityPolicy||null===e.securityPolicy)r.push(new ConfigValidationError("securityPolicy","SecurityPolicy instance",e.securityPolicy,"Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy)."));else{const t=e.securityPolicy;"classify"in t&&"function"==typeof t.classify||r.push(new ConfigValidationError("securityPolicy","SecurityPolicy with classify() method","object missing classify() method","SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy."))}if(void 0!==e.postQuantumSig&&"boolean"!=typeof e.postQuantumSig&&r.push(new ConfigValidationError("postQuantumSig","boolean",e.postQuantumSig,"Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.")),void 0!==e.backupConfig)if("object"!=typeof e.backupConfig||null===e.backupConfig)r.push(new ConfigValidationError("backupConfig","BackupConfig object",e.backupConfig,"Provide a BackupConfig object with threshold (k) and totalShares (n) properties."));else{const t=e.backupConfig;"number"!=typeof t.threshold?r.push(new ConfigValidationError("backupConfig.threshold","number",t.threshold,"Threshold (k) must be a number representing shares needed for reconstruction.")):t.threshold<2&&r.push(new ConfigValidationError("backupConfig.threshold","number >= 2",t.threshold,"Threshold must be at least 2 for meaningful splitting.")),"number"!=typeof t.totalShares?r.push(new ConfigValidationError("backupConfig.totalShares","number",t.totalShares,"totalShares (n) must be a number representing total shares to create.")):t.totalShares<2&&r.push(new ConfigValidationError("backupConfig.totalShares","number >= 2",t.totalShares,"totalShares must be at least 2 for splitting.")),"number"==typeof t.threshold&&"number"==typeof t.totalShares&&t.threshold>t.totalShares&&r.push(new ConfigValidationError("backupConfig","threshold <= totalShares",`threshold=${t.threshold}, totalShares=${t.totalShares}`,`Threshold (${t.threshold}) cannot exceed totalShares (${t.totalShares}). Use threshold <= totalShares.`))}return r.length>0?(0,shared_1.err)(r[0]):(0,shared_1.ok)(e)}function validateAgentCreateOptions(t){if(!t||"object"!=typeof t)return(0,shared_1.err)(new ConfigValidationError("options","object",t,"Provide a configuration object with required fields: name, registry, transport."));const e=t,r=[];if(void 0===e.name?r.push(new ConfigValidationError("name","string (required)",void 0,'Provide a display name for the agent (e.g., "my-agent").')):"string"!=typeof e.name?r.push(new ConfigValidationError("name","string",e.name,"Agent name must be a string.")):0===e.name.trim().length?r.push(new ConfigValidationError("name","non-empty string",e.name,"Agent name cannot be empty or whitespace only.")):e.name.length>255&&r.push(new ConfigValidationError("name","string with length <= 255",e.name,`Agent name is too long (${e.name.length} characters). Use 255 characters or less.`)),void 0===e.registry)r.push(new ConfigValidationError("registry","TrustRegistry (required)",void 0,"Provide a TrustRegistry instance (e.g., new MemoryTrustRegistry() or new HttpTrustRegistry())."));else if("object"!=typeof e.registry||null===e.registry)r.push(new ConfigValidationError("registry","TrustRegistry instance",e.registry,"Registry must be a TrustRegistry instance, not a string or primitive value."));else{const t=e.registry,i=["register","resolve"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("registry","TrustRegistry instance","object missing required methods",`TrustRegistry must implement: ${i.join(", ")}. Use HttpTrustRegistry or MemoryTrustRegistry.`))}if(void 0===e.transport)r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[] (required)",void 0,"Provide a transport adapter (e.g., new HttpsTransportAdapter()) or array of adapters for split-channel."));else{const t=Array.isArray(e.transport);if("object"==typeof e.transport&&null!==e.transport&&!t||t)if(t){const t=e.transport;0===t.length&&r.push(new ConfigValidationError("transport","non-empty array",t,"Provide at least one transport adapter.")),t.forEach((t,e)=>{if("object"!=typeof t||null===t)r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter",t,"Each transport must be a XailTransportAdapter instance."));else{"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}})}else{const t=e.transport;"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError("transport","XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}else r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[]",e.transport,"Provide a single transport adapter or an array of adapters."))}if(void 0!==e.nonceStore)if("object"!=typeof e.nonceStore||null===e.nonceStore)r.push(new ConfigValidationError("nonceStore","NonceStore instance",e.nonceStore,"Provide a NonceStore instance (e.g., new MemoryNonceStore())."));else{const t=e.nonceStore,i=["check","cleanup"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("nonceStore","NonceStore instance","object missing required methods",`NonceStore must implement: ${i.join(", ")}. Use MemoryNonceStore.`))}if(void 0!==e.scopes)if(Array.isArray(e.scopes)){e.scopes.forEach((t,e)=>{"string"!=typeof t?r.push(new ConfigValidationError(`scopes[${e}]`,"string",t,"Each scope must be a string.")):0===t.trim().length&&r.push(new ConfigValidationError(`scopes[${e}]`,"non-empty string",t,"Scope cannot be empty or whitespace only."))})}else r.push(new ConfigValidationError("scopes","string[]",e.scopes,'Provide an array of scope strings (e.g., ["read", "write"]).'));if(void 0!==e.timestampWindowMs&&("number"!=typeof e.timestampWindowMs?r.push(new ConfigValidationError("timestampWindowMs","number (milliseconds)",e.timestampWindowMs,"Provide timestamp window as a number in milliseconds (e.g., 30000 for 30 seconds).")):e.timestampWindowMs<=0?r.push(new ConfigValidationError("timestampWindowMs","positive number",e.timestampWindowMs,"Timestamp window must be greater than 0. Use at least 1000 (1 second).")):e.timestampWindowMs<5e3?r.push(new ConfigValidationError("timestampWindowMs","number >= 5000",e.timestampWindowMs,"Timestamp window is very short. Use at least 5000ms (5 seconds) to account for clock skew.")):e.timestampWindowMs>3e5&&r.push(new ConfigValidationError("timestampWindowMs","number <= 300000",e.timestampWindowMs,"Timestamp window is very long. Consider using 300000ms (5 minutes) or less for security."))),void 0!==e.postQuantumSig&&"boolean"!=typeof e.postQuantumSig&&r.push(new ConfigValidationError("postQuantumSig","boolean",e.postQuantumSig,"Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.")),void 0!==e.xchange&&"boolean"!=typeof e.xchange&&r.push(new ConfigValidationError("xchange","boolean",e.xchange,"Use true to advertise Xchange mode support, or false to disable.")),void 0!==e.securityPolicy)if("object"!=typeof e.securityPolicy||null===e.securityPolicy)r.push(new ConfigValidationError("securityPolicy","SecurityPolicy instance",e.securityPolicy,"Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy)."));else{const t=e.securityPolicy;"classify"in t&&"function"==typeof t.classify||r.push(new ConfigValidationError("securityPolicy","SecurityPolicy with classify() method","object missing classify() method","SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy."))}return r.length>0?(0,shared_1.err)(r[0]):(0,shared_1.ok)(e)}function getValidationDetails(t){const e=[],r=[],i=validateAgentOptions(t);if(i.ok||e.push(i.error),t&&"object"==typeof t){const e=t;"number"==typeof e.identityTTL&&(e.identityTTL<6e4&&e.identityTTL>0?r.push(`identityTTL is very short (${e.identityTTL}ms). Consider using at least 60000ms (1 minute).`):e.identityTTL>864e5&&r.push(`identityTTL is very long (${e.identityTTL}ms). Consider using 'persistent' identity mode instead.`),"persistent"===e.identity&&r.push("identityTTL is ignored for 'persistent' identity mode."))}return{valid:0===e.length,errors:e,warnings:r}}function assertValidConfig(t){const e=validateAgentOptions(t);if(!e.ok)throw e.error}function assertValidCreateConfig(t){const e=validateAgentCreateOptions(t);if(!e.ok)throw e.error}exports.ConfigValidationError=ConfigValidationError,exports.AGENT_OPTIONS_DEFAULTS={identity:"persistent",identityTTL:36e5,postQuantumSig:!1},exports.AGENT_CREATE_OPTIONS_DEFAULTS={timestampWindowMs:3e4,postQuantumSig:!1,xchange:!1,scopes:[]};