@private.me/xbind 3.0.0 → 3.0.2

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 (217) hide show
  1. package/README.md +55 -7
  2. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
  3. package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
  4. package/dist-standalone/_deps/shared/cjs/index.js +463 -1
  5. package/dist-standalone/_deps/shared/cjs/types.js +315 -1
  6. package/dist-standalone/_deps/shared/errors.js +244 -1
  7. package/dist-standalone/_deps/shared/index.js +72 -1
  8. package/dist-standalone/_deps/shared/types.js +86 -1
  9. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  10. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  20. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  21. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  28. package/dist-standalone/_deps/xchange/errors.js +1 -1
  29. package/dist-standalone/_deps/xchange/index.js +1 -1
  30. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  31. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  32. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  33. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  34. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  40. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  41. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  42. package/dist-standalone/_deps/xregistry/index.js +1 -1
  43. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  44. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  45. package/dist-standalone/_deps/xregistry/types.js +1 -1
  46. package/dist-standalone/agent-call.js +659 -1
  47. package/dist-standalone/agent-sdk.js +328 -1
  48. package/dist-standalone/agent.js +1800 -1
  49. package/dist-standalone/approval.js +193 -1
  50. package/dist-standalone/async-iterators.js +382 -1
  51. package/dist-standalone/auth.js +219 -1
  52. package/dist-standalone/auto-accept.js +229 -1
  53. package/dist-standalone/backup-config.js +201 -1
  54. package/dist-standalone/backup.js +326 -1
  55. package/dist-standalone/batch-operations.js +388 -1
  56. package/dist-standalone/cancellation.js +477 -1
  57. package/dist-standalone/checkpoint.js +186 -1
  58. package/dist-standalone/circuit-breaker.js +468 -1
  59. package/dist-standalone/cjs/agent-call.js +701 -1
  60. package/dist-standalone/cjs/agent-sdk.js +332 -1
  61. package/dist-standalone/cjs/agent.js +1837 -1
  62. package/dist-standalone/cjs/approval.js +199 -1
  63. package/dist-standalone/cjs/async-iterators.js +392 -1
  64. package/dist-standalone/cjs/auth.js +225 -1
  65. package/dist-standalone/cjs/auto-accept.js +233 -1
  66. package/dist-standalone/cjs/backup-config.js +207 -1
  67. package/dist-standalone/cjs/backup.js +330 -1
  68. package/dist-standalone/cjs/batch-operations.js +397 -1
  69. package/dist-standalone/cjs/cancellation.js +490 -1
  70. package/dist-standalone/cjs/checkpoint.js +193 -1
  71. package/dist-standalone/cjs/circuit-breaker.js +476 -1
  72. package/dist-standalone/cjs/cli/init.js +492 -1
  73. package/dist-standalone/cjs/config-validation.js +522 -1
  74. package/dist-standalone/cjs/connect.js +312 -1
  75. package/dist-standalone/cjs/connection-pool.js +506 -1
  76. package/dist-standalone/cjs/correlation-id.js +339 -1
  77. package/dist-standalone/cjs/crypto-utils.js +176 -1
  78. package/dist-standalone/cjs/debug-mode.js +534 -1
  79. package/dist-standalone/cjs/did-document.js +101 -1
  80. package/dist-standalone/cjs/did-privateme.js +130 -1
  81. package/dist-standalone/cjs/did-web.js +201 -1
  82. package/dist-standalone/cjs/discovery.js +462 -1
  83. package/dist-standalone/cjs/dual-mode.js +251 -1
  84. package/dist-standalone/cjs/email-templates.js +313 -1
  85. package/dist-standalone/cjs/email-transport.js +239 -1
  86. package/dist-standalone/cjs/envelope.js +538 -1
  87. package/dist-standalone/cjs/errors.js +913 -1
  88. package/dist-standalone/cjs/event-emitter.js +461 -1
  89. package/dist-standalone/cjs/gateway-state.js +55 -1
  90. package/dist-standalone/cjs/gateway-transport.js +120 -1
  91. package/dist-standalone/cjs/graceful-degradation.js +403 -1
  92. package/dist-standalone/cjs/guardrails.js +223 -1
  93. package/dist-standalone/cjs/health-check.js +336 -1
  94. package/dist-standalone/cjs/http-compat.js +272 -1
  95. package/dist-standalone/cjs/http-status-map.js +571 -1
  96. package/dist-standalone/cjs/identity.js +645 -1
  97. package/dist-standalone/cjs/index.js +406 -1
  98. package/dist-standalone/cjs/invitation.js +421 -1
  99. package/dist-standalone/cjs/invite.js +328 -1
  100. package/dist-standalone/cjs/key-agreement.js +335 -1
  101. package/dist-standalone/cjs/lazy-init.js +300 -1
  102. package/dist-standalone/cjs/logger.js +291 -1
  103. package/dist-standalone/cjs/mdns-discovery.js +202 -1
  104. package/dist-standalone/cjs/nonce-store.js +80 -1
  105. package/dist-standalone/cjs/pairing-manager.js +223 -1
  106. package/dist-standalone/cjs/plugin-system.js +264 -1
  107. package/dist-standalone/cjs/plugins/logging.js +168 -1
  108. package/dist-standalone/cjs/plugins/metrics.js +181 -1
  109. package/dist-standalone/cjs/plugins/validation.js +302 -1
  110. package/dist-standalone/cjs/policy.js +320 -1
  111. package/dist-standalone/cjs/progress-callbacks.js +583 -1
  112. package/dist-standalone/cjs/redis-nonce-store.js +76 -1
  113. package/dist-standalone/cjs/registry-middleware.js +50 -1
  114. package/dist-standalone/cjs/retry-strategies.js +544 -1
  115. package/dist-standalone/cjs/retry-transport.js +102 -1
  116. package/dist-standalone/cjs/runtime/browser.js +533 -1
  117. package/dist-standalone/cjs/runtime/edge.js +526 -1
  118. package/dist-standalone/cjs/runtime/react-native.js +394 -1
  119. package/dist-standalone/cjs/security-policy.js +245 -1
  120. package/dist-standalone/cjs/serialization.js +1040 -1
  121. package/dist-standalone/cjs/split-channel.js +225 -1
  122. package/dist-standalone/cjs/subscription-proof.js +230 -1
  123. package/dist-standalone/cjs/succession.js +148 -1
  124. package/dist-standalone/cjs/timeouts.js +412 -1
  125. package/dist-standalone/cjs/trace-context.js +424 -1
  126. package/dist-standalone/cjs/trace-spans.js +495 -1
  127. package/dist-standalone/cjs/transport.js +63 -1
  128. package/dist-standalone/cjs/trust-registry.js +991 -1
  129. package/dist-standalone/cjs/types/error-response.js +56 -1
  130. package/dist-standalone/cjs/vault-auth.js +178 -1
  131. package/dist-standalone/cjs/vault-store-loader.js +194 -1
  132. package/dist-standalone/cjs/verify.js +25 -1
  133. package/dist-standalone/cjs/version-info.js +543 -1
  134. package/dist-standalone/cjs/xfetch.js +340 -1
  135. package/dist-standalone/cli/init.js +455 -1
  136. package/dist-standalone/cli/setup.js +514 -1
  137. package/dist-standalone/cli/types.js +27 -1
  138. package/dist-standalone/cli/xbind.js +148 -1
  139. package/dist-standalone/config-validation.js +513 -1
  140. package/dist-standalone/connect.js +274 -1
  141. package/dist-standalone/connection-pool.js +500 -1
  142. package/dist-standalone/correlation-id.js +326 -1
  143. package/dist-standalone/crypto-utils.js +157 -1
  144. package/dist-standalone/debug-mode.js +510 -1
  145. package/dist-standalone/did-document.js +96 -1
  146. package/dist-standalone/did-privateme.js +121 -1
  147. package/dist-standalone/did-web.js +196 -1
  148. package/dist-standalone/discovery.js +458 -1
  149. package/dist-standalone/dual-mode.js +247 -1
  150. package/dist-standalone/email-templates.js +309 -1
  151. package/dist-standalone/email-transport.js +232 -1
  152. package/dist-standalone/envelope.js +525 -1
  153. package/dist-standalone/errors.js +896 -1
  154. package/dist-standalone/event-emitter.js +456 -1
  155. package/dist-standalone/gateway-state.js +51 -1
  156. package/dist-standalone/gateway-transport.js +116 -1
  157. package/dist-standalone/graceful-degradation.js +396 -1
  158. package/dist-standalone/guardrails.js +216 -1
  159. package/dist-standalone/health-check.js +332 -1
  160. package/dist-standalone/http-compat.js +267 -1
  161. package/dist-standalone/http-status-map.js +561 -1
  162. package/dist-standalone/identity.js +619 -1
  163. package/dist-standalone/index.js +78 -1
  164. package/dist-standalone/invitation.js +415 -1
  165. package/dist-standalone/invite.js +324 -1
  166. package/dist-standalone/key-agreement.js +325 -1
  167. package/dist-standalone/lazy-init.js +295 -1
  168. package/dist-standalone/logger.js +285 -1
  169. package/dist-standalone/mdns-discovery.js +195 -1
  170. package/dist-standalone/nonce-store.js +76 -1
  171. package/dist-standalone/pairing-manager.js +219 -1
  172. package/dist-standalone/plugin-system.js +257 -1
  173. package/dist-standalone/plugins/logging.d.ts +84 -0
  174. package/dist-standalone/plugins/logging.js +163 -0
  175. package/dist-standalone/plugins/metrics.d.ts +111 -0
  176. package/dist-standalone/plugins/metrics.js +176 -0
  177. package/dist-standalone/plugins/validation.d.ts +104 -0
  178. package/dist-standalone/plugins/validation.js +297 -0
  179. package/dist-standalone/policy.js +315 -1
  180. package/dist-standalone/progress-callbacks.js +576 -1
  181. package/dist-standalone/redis-nonce-store.js +72 -1
  182. package/dist-standalone/registry-middleware.js +47 -1
  183. package/dist-standalone/retry-strategies.js +534 -1
  184. package/dist-standalone/retry-transport.js +98 -1
  185. package/dist-standalone/runtime/browser.d.ts +311 -0
  186. package/dist-standalone/runtime/browser.js +516 -0
  187. package/dist-standalone/runtime/edge.d.ts +282 -0
  188. package/dist-standalone/runtime/edge.js +511 -0
  189. package/dist-standalone/runtime/react-native.d.ts +157 -0
  190. package/dist-standalone/runtime/react-native.js +383 -0
  191. package/dist-standalone/security-policy.js +239 -1
  192. package/dist-standalone/serialization.js +1031 -1
  193. package/dist-standalone/split-channel.js +219 -1
  194. package/dist-standalone/subscription-proof.js +224 -1
  195. package/dist-standalone/succession.js +142 -1
  196. package/dist-standalone/timeouts.js +398 -1
  197. package/dist-standalone/trace-context.js +414 -1
  198. package/dist-standalone/trace-spans.js +488 -1
  199. package/dist-standalone/transport.js +59 -1
  200. package/dist-standalone/trust-registry.js +950 -1
  201. package/dist-standalone/types/error-response.d.ts +209 -0
  202. package/dist-standalone/types/error-response.js +52 -0
  203. package/dist-standalone/vault-auth.js +174 -1
  204. package/dist-standalone/vault-store-loader.js +187 -1
  205. package/dist-standalone/verify.js +16 -1
  206. package/dist-standalone/version-info.js +530 -1
  207. package/dist-standalone/xfetch.js +335 -1
  208. package/package.json +4 -10
  209. package/share1.dat +0 -0
  210. package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
  211. package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
  212. package/dist-standalone/_deps/shared/cjs/package.json +0 -1
  213. package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
  214. package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
  215. package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
  216. package/dist-standalone/cjs/package.json +0 -3
  217. package/dist-standalone/package.json +0 -10
@@ -1 +1,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:[]};
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
+ }