@private.me/xbind 1.3.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/LICENSES.md +212 -0
  2. package/README.md +388 -6
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -496
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -317
  7. package/dist-standalone/_deps/shared/errors.js +1 -255
  8. package/dist-standalone/_deps/shared/index.js +1 -74
  9. package/dist-standalone/_deps/shared/types.js +1 -90
  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.js +1 -642
  48. package/dist-standalone/agent-sdk.js +1 -328
  49. package/dist-standalone/agent.d.ts +95 -5
  50. package/dist-standalone/agent.js +1 -1545
  51. package/dist-standalone/approval.js +1 -193
  52. package/dist-standalone/async-iterators.d.ts +275 -0
  53. package/dist-standalone/async-iterators.js +1 -0
  54. package/dist-standalone/auth.js +1 -219
  55. package/dist-standalone/auto-accept.js +1 -229
  56. package/dist-standalone/backup-config.js +1 -201
  57. package/dist-standalone/backup.d.ts +114 -0
  58. package/dist-standalone/backup.js +1 -0
  59. package/dist-standalone/batch-operations.d.ts +297 -0
  60. package/dist-standalone/batch-operations.js +1 -0
  61. package/dist-standalone/cancellation.d.ts +301 -0
  62. package/dist-standalone/cancellation.js +1 -0
  63. package/dist-standalone/checkpoint.js +1 -186
  64. package/dist-standalone/circuit-breaker.d.ts +351 -0
  65. package/dist-standalone/circuit-breaker.js +1 -0
  66. package/dist-standalone/cjs/agent-call.js +1 -651
  67. package/dist-standalone/cjs/agent-sdk.js +1 -332
  68. package/dist-standalone/cjs/agent.js +1 -1582
  69. package/dist-standalone/cjs/approval.js +1 -199
  70. package/dist-standalone/cjs/async-iterators.js +1 -0
  71. package/dist-standalone/cjs/auth.js +1 -225
  72. package/dist-standalone/cjs/auto-accept.js +1 -233
  73. package/dist-standalone/cjs/backup-config.js +1 -207
  74. package/dist-standalone/cjs/backup.js +1 -0
  75. package/dist-standalone/cjs/batch-operations.js +1 -0
  76. package/dist-standalone/cjs/cancellation.js +1 -0
  77. package/dist-standalone/cjs/checkpoint.js +1 -193
  78. package/dist-standalone/cjs/circuit-breaker.js +1 -0
  79. package/dist-standalone/cjs/cli/init.js +1 -486
  80. package/dist-standalone/cjs/config-validation.js +1 -0
  81. package/dist-standalone/cjs/connect.js +1 -312
  82. package/dist-standalone/cjs/connection-pool.js +1 -0
  83. package/dist-standalone/cjs/correlation-id.js +1 -339
  84. package/dist-standalone/cjs/crypto-utils.js +1 -0
  85. package/dist-standalone/cjs/debug-mode.js +1 -0
  86. package/dist-standalone/cjs/did-document.js +1 -101
  87. package/dist-standalone/cjs/did-privateme.js +1 -130
  88. package/dist-standalone/cjs/did-web.js +1 -201
  89. package/dist-standalone/cjs/discovery.js +1 -462
  90. package/dist-standalone/cjs/dual-mode.js +1 -251
  91. package/dist-standalone/cjs/email-templates.js +1 -313
  92. package/dist-standalone/cjs/email-transport.js +1 -239
  93. package/dist-standalone/cjs/envelope.js +1 -510
  94. package/dist-standalone/cjs/errors.js +1 -826
  95. package/dist-standalone/cjs/event-emitter.js +1 -0
  96. package/dist-standalone/cjs/gateway-state.js +1 -55
  97. package/dist-standalone/cjs/gateway-transport.js +1 -120
  98. package/dist-standalone/cjs/graceful-degradation.js +1 -0
  99. package/dist-standalone/cjs/guardrails.js +1 -223
  100. package/dist-standalone/cjs/health-check.js +1 -0
  101. package/dist-standalone/cjs/http-compat.js +1 -272
  102. package/dist-standalone/cjs/http-status-map.js +1 -571
  103. package/dist-standalone/cjs/identity.js +1 -540
  104. package/dist-standalone/cjs/index.js +1 -237
  105. package/dist-standalone/cjs/invitation.js +1 -421
  106. package/dist-standalone/cjs/invite.js +1 -328
  107. package/dist-standalone/cjs/key-agreement.js +1 -246
  108. package/dist-standalone/cjs/lazy-init.js +1 -300
  109. package/dist-standalone/cjs/logger.js +1 -0
  110. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  111. package/dist-standalone/cjs/nonce-store.js +1 -66
  112. package/dist-standalone/cjs/pairing-manager.js +1 -223
  113. package/dist-standalone/cjs/plugin-system.js +1 -0
  114. package/dist-standalone/cjs/plugins/logging.js +1 -0
  115. package/dist-standalone/cjs/plugins/metrics.js +1 -0
  116. package/dist-standalone/cjs/plugins/validation.js +1 -0
  117. package/dist-standalone/cjs/policy.js +1 -320
  118. package/dist-standalone/cjs/progress-callbacks.js +1 -0
  119. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  120. package/dist-standalone/cjs/registry-middleware.js +1 -50
  121. package/dist-standalone/cjs/retry-strategies.js +1 -0
  122. package/dist-standalone/cjs/retry-transport.js +1 -102
  123. package/dist-standalone/cjs/runtime/browser.js +1 -0
  124. package/dist-standalone/cjs/runtime/edge.js +1 -0
  125. package/dist-standalone/cjs/runtime/react-native.js +1 -0
  126. package/dist-standalone/cjs/security-policy.js +1 -245
  127. package/dist-standalone/cjs/serialization.js +1 -0
  128. package/dist-standalone/cjs/split-channel.js +1 -177
  129. package/dist-standalone/cjs/subscription-proof.js +1 -230
  130. package/dist-standalone/cjs/succession.js +1 -148
  131. package/dist-standalone/cjs/timeouts.js +1 -0
  132. package/dist-standalone/cjs/trace-context.js +1 -0
  133. package/dist-standalone/cjs/trace-spans.js +1 -0
  134. package/dist-standalone/cjs/transport.js +1 -63
  135. package/dist-standalone/cjs/trust-registry.js +1 -742
  136. package/dist-standalone/cjs/types/error-response.js +1 -56
  137. package/dist-standalone/cjs/vault-auth.js +1 -0
  138. package/dist-standalone/cjs/vault-store-loader.js +1 -0
  139. package/dist-standalone/cjs/verify.js +1 -25
  140. package/dist-standalone/cjs/version-info.js +1 -0
  141. package/dist-standalone/cjs/xfetch.js +1 -252
  142. package/dist-standalone/cli/init.js +1 -449
  143. package/dist-standalone/cli/setup.js +1 -514
  144. package/dist-standalone/cli/types.js +1 -27
  145. package/dist-standalone/cli/xbind.js +1 -148
  146. package/dist-standalone/config-validation.d.ts +185 -0
  147. package/dist-standalone/config-validation.js +1 -0
  148. package/dist-standalone/connect.js +1 -274
  149. package/dist-standalone/connection-pool.d.ts +251 -0
  150. package/dist-standalone/connection-pool.js +1 -0
  151. package/dist-standalone/correlation-id.js +1 -326
  152. package/dist-standalone/crypto-utils.d.ts +60 -0
  153. package/dist-standalone/crypto-utils.js +1 -0
  154. package/dist-standalone/debug-mode.d.ts +286 -0
  155. package/dist-standalone/debug-mode.js +1 -0
  156. package/dist-standalone/did-document.js +1 -96
  157. package/dist-standalone/did-privateme.js +1 -121
  158. package/dist-standalone/did-web.js +1 -196
  159. package/dist-standalone/discovery.js +1 -458
  160. package/dist-standalone/dual-mode.js +1 -247
  161. package/dist-standalone/email-templates.js +1 -309
  162. package/dist-standalone/email-transport.js +1 -232
  163. package/dist-standalone/envelope.d.ts +29 -1
  164. package/dist-standalone/envelope.js +1 -497
  165. package/dist-standalone/errors.d.ts +10 -0
  166. package/dist-standalone/errors.js +1 -811
  167. package/dist-standalone/event-emitter.d.ts +395 -0
  168. package/dist-standalone/event-emitter.js +1 -0
  169. package/dist-standalone/gateway-state.js +1 -51
  170. package/dist-standalone/gateway-transport.js +1 -116
  171. package/dist-standalone/graceful-degradation.d.ts +246 -0
  172. package/dist-standalone/graceful-degradation.js +1 -0
  173. package/dist-standalone/guardrails.js +1 -216
  174. package/dist-standalone/health-check.d.ts +150 -0
  175. package/dist-standalone/health-check.js +1 -0
  176. package/dist-standalone/http-compat.js +1 -267
  177. package/dist-standalone/http-status-map.js +1 -561
  178. package/dist-standalone/identity.d.ts +64 -1
  179. package/dist-standalone/identity.js +1 -515
  180. package/dist-standalone/index.d.ts +45 -3
  181. package/dist-standalone/index.js +1 -52
  182. package/dist-standalone/invitation.js +1 -415
  183. package/dist-standalone/invite.js +1 -324
  184. package/dist-standalone/key-agreement.d.ts +61 -13
  185. package/dist-standalone/key-agreement.js +1 -236
  186. package/dist-standalone/lazy-init.js +1 -295
  187. package/dist-standalone/logger.d.ts +77 -0
  188. package/dist-standalone/logger.js +1 -0
  189. package/dist-standalone/mdns-discovery.js +1 -195
  190. package/dist-standalone/nonce-store.d.ts +16 -3
  191. package/dist-standalone/nonce-store.js +1 -62
  192. package/dist-standalone/package.json +0 -1
  193. package/dist-standalone/pairing-manager.js +1 -219
  194. package/dist-standalone/plugin-system.d.ts +145 -0
  195. package/dist-standalone/plugin-system.js +1 -0
  196. package/dist-standalone/policy.js +1 -315
  197. package/dist-standalone/progress-callbacks.d.ts +394 -0
  198. package/dist-standalone/progress-callbacks.js +1 -0
  199. package/dist-standalone/redis-nonce-store.js +1 -72
  200. package/dist-standalone/registry-middleware.js +1 -47
  201. package/dist-standalone/retry-strategies.d.ts +382 -0
  202. package/dist-standalone/retry-strategies.js +1 -0
  203. package/dist-standalone/retry-transport.js +1 -98
  204. package/dist-standalone/security-policy.js +1 -239
  205. package/dist-standalone/serialization.d.ts +244 -0
  206. package/dist-standalone/serialization.js +1 -0
  207. package/dist-standalone/split-channel.d.ts +49 -1
  208. package/dist-standalone/split-channel.js +1 -171
  209. package/dist-standalone/subscription-proof.js +1 -224
  210. package/dist-standalone/succession.js +1 -142
  211. package/dist-standalone/timeouts.d.ts +275 -0
  212. package/dist-standalone/timeouts.js +1 -0
  213. package/dist-standalone/trace-context.d.ts +252 -0
  214. package/dist-standalone/trace-context.js +1 -0
  215. package/dist-standalone/trace-spans.d.ts +360 -0
  216. package/dist-standalone/trace-spans.js +1 -0
  217. package/dist-standalone/transport.js +1 -59
  218. package/dist-standalone/trust-registry.d.ts +106 -5
  219. package/dist-standalone/trust-registry.js +1 -702
  220. package/dist-standalone/vault-auth.d.ts +91 -0
  221. package/dist-standalone/vault-auth.js +1 -0
  222. package/dist-standalone/vault-store-loader.d.ts +110 -0
  223. package/dist-standalone/vault-store-loader.js +1 -0
  224. package/dist-standalone/verify.js +1 -16
  225. package/dist-standalone/version-info.d.ts +259 -0
  226. package/dist-standalone/version-info.js +1 -0
  227. package/dist-standalone/xfetch.js +1 -247
  228. package/llms.txt +1 -0
  229. package/package.json +65 -5
  230. package/share1.dat +0 -0
  231. package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
  232. package/dist-standalone/_deps/crypto/base64.js +0 -222
  233. package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
  234. package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
  235. package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
  236. package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
  237. package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
  238. package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
  239. package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
  240. package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
  241. package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
  242. package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
  243. package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
  244. package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
  245. package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
  246. package/dist-standalone/_deps/crypto/errors.js +0 -199
  247. package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
  248. package/dist-standalone/_deps/crypto/hmac.js +0 -134
  249. package/dist-standalone/_deps/crypto/index.d.ts +0 -20
  250. package/dist-standalone/_deps/crypto/index.js +0 -145
  251. package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
  252. package/dist-standalone/_deps/crypto/padding.js +0 -159
  253. package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
  254. package/dist-standalone/_deps/crypto/share-header.js +0 -92
  255. package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
  256. package/dist-standalone/_deps/crypto/shares.js +0 -295
  257. package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
  258. package/dist-standalone/_deps/crypto/tlv.js +0 -364
  259. package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
  260. package/dist-standalone/_deps/crypto/uuid.js +0 -136
  261. package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
  262. package/dist-standalone/_deps/crypto/verify.js +0 -71
  263. package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
  264. package/dist-standalone/_deps/crypto/xorida.js +0 -366
  265. package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
  266. package/dist-standalone/_deps/shared/errors.js.map +0 -1
  267. package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
  268. package/dist-standalone/_deps/shared/index.js.map +0 -1
  269. package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
  270. package/dist-standalone/_deps/shared/types.js.map +0 -1
  271. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
  272. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
  273. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
  274. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
  275. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
  276. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
  277. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
  278. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
  279. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
  280. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
  281. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
  282. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
  283. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
  284. package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
  285. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
  286. package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
  287. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
  288. package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
  289. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
  290. package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
  291. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
  292. package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
  293. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
  294. package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
  295. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
  296. package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
  297. package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
  298. package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
  299. package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
  300. package/dist-standalone/_deps/xregistry/index.js.map +0 -1
  301. package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
  302. package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
  303. package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
  304. package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
  305. package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
  306. package/dist-standalone/_deps/xregistry/types.js.map +0 -1
@@ -0,0 +1,286 @@
1
+ /**
2
+ * @module debug-mode
3
+ * Debug mode for enhanced developer experience with verbose logging and state inspection
4
+ *
5
+ * Provides comprehensive debugging capabilities including:
6
+ * - Verbose logging of all operations
7
+ * - Internal state dumping and inspection
8
+ * - Network request/response logging
9
+ * - Crypto operation tracing
10
+ * - Performance profiling and timing
11
+ * - Memory usage tracking
12
+ *
13
+ * Usage:
14
+ * ```typescript
15
+ * import { enableDebugMode, dumpState, createDebugLogger } from '@private.me/xbind/debug-mode';
16
+ *
17
+ * // Enable debug mode globally
18
+ * enableDebugMode({ verbose: true, traceNetwork: true });
19
+ *
20
+ * // Create debug logger for component
21
+ * const debug = createDebugLogger('agent');
22
+ * debug.trace('Operation starting', { did: 'did:key:...' });
23
+ *
24
+ * // Dump internal state
25
+ * const state = dumpState(agent);
26
+ * console.log(state);
27
+ * ```
28
+ */
29
+ import type { Logger, LogContext } from './logger.js';
30
+ import type { Agent } from './agent.js';
31
+ /**
32
+ * Debug mode configuration options
33
+ */
34
+ export interface DebugModeOptions {
35
+ /** Enable verbose logging (default: false) */
36
+ verbose?: boolean;
37
+ /** Trace network requests/responses (default: false) */
38
+ traceNetwork?: boolean;
39
+ /** Trace crypto operations (default: false) */
40
+ traceCrypto?: boolean;
41
+ /** Enable performance profiling (default: false) */
42
+ profile?: boolean;
43
+ /** Track memory usage (default: false) */
44
+ trackMemory?: boolean;
45
+ /** Log internal state changes (default: false) */
46
+ traceState?: boolean;
47
+ /** Custom output function (default: console.log) */
48
+ output?: (message: string) => void;
49
+ /** Filter patterns for selective logging */
50
+ filters?: {
51
+ /** Include only operations matching these patterns */
52
+ include?: RegExp[];
53
+ /** Exclude operations matching these patterns */
54
+ exclude?: RegExp[];
55
+ };
56
+ }
57
+ /**
58
+ * Performance measurement result
59
+ */
60
+ export interface PerformanceMeasurement {
61
+ /** Operation name */
62
+ operation: string;
63
+ /** Start timestamp (ms) */
64
+ startTime: number;
65
+ /** End timestamp (ms) */
66
+ endTime: number;
67
+ /** Duration (ms) */
68
+ duration: number;
69
+ /** Memory usage before operation (bytes) */
70
+ memoryBefore?: number;
71
+ /** Memory usage after operation (bytes) */
72
+ memoryAfter?: number;
73
+ /** Memory delta (bytes) */
74
+ memoryDelta?: number;
75
+ /** Additional context */
76
+ context?: Record<string, unknown>;
77
+ }
78
+ /**
79
+ * Network trace entry
80
+ */
81
+ export interface NetworkTrace {
82
+ /** Request ID */
83
+ id: string;
84
+ /** HTTP method */
85
+ method: string;
86
+ /** URL */
87
+ url: string;
88
+ /** Request headers (redacted) */
89
+ requestHeaders: Record<string, string>;
90
+ /** Request body (truncated) */
91
+ requestBody?: string;
92
+ /** Response status code */
93
+ status?: number;
94
+ /** Response headers (redacted) */
95
+ responseHeaders?: Record<string, string>;
96
+ /** Response body (truncated) */
97
+ responseBody?: string;
98
+ /** Start timestamp */
99
+ startTime: number;
100
+ /** End timestamp */
101
+ endTime?: number;
102
+ /** Duration (ms) */
103
+ duration?: number;
104
+ /** Error (if failed) */
105
+ error?: string;
106
+ }
107
+ /**
108
+ * Crypto operation trace entry
109
+ */
110
+ export interface CryptoTrace {
111
+ /** Operation type (encrypt, decrypt, sign, verify, etc.) */
112
+ operation: string;
113
+ /** Algorithm */
114
+ algorithm: string;
115
+ /** Input size (bytes) */
116
+ inputSize: number;
117
+ /** Output size (bytes) */
118
+ outputSize?: number;
119
+ /** Duration (ms) */
120
+ duration: number;
121
+ /** Success flag */
122
+ success: boolean;
123
+ /** Error message (if failed) */
124
+ error?: string;
125
+ /** Timestamp */
126
+ timestamp: number;
127
+ }
128
+ /**
129
+ * Agent state snapshot
130
+ */
131
+ export interface AgentStateSnapshot {
132
+ /** Agent DID */
133
+ did: string;
134
+ /** Identity mode */
135
+ identityMode: 'persistent' | 'ephemeral';
136
+ /** Registration status */
137
+ registered: boolean;
138
+ /** Trust registry URL */
139
+ registryUrl?: string;
140
+ /** Nonce store type */
141
+ nonceStoreType: string;
142
+ /** Nonce count */
143
+ nonceCount: number;
144
+ /** Transport adapter type */
145
+ transportType: string;
146
+ /** Security policy summary */
147
+ securityPolicy: {
148
+ level: string;
149
+ replayWindow: number;
150
+ timestampTolerance: number;
151
+ };
152
+ /** Post-quantum enabled */
153
+ postQuantum: boolean;
154
+ /** Memory usage (bytes) */
155
+ memoryUsage?: number;
156
+ /** Snapshot timestamp */
157
+ timestamp: number;
158
+ }
159
+ /**
160
+ * Enable debug mode with optional configuration
161
+ *
162
+ * @param options - Debug mode options
163
+ */
164
+ export declare function enableDebugMode(options?: DebugModeOptions): void;
165
+ /**
166
+ * Disable debug mode and clear collected data
167
+ */
168
+ export declare function disableDebugMode(): void;
169
+ /**
170
+ * Check if debug mode is enabled
171
+ */
172
+ export declare function isDebugEnabled(): boolean;
173
+ /**
174
+ * Get current debug mode options
175
+ */
176
+ export declare function getDebugOptions(): DebugModeOptions;
177
+ /**
178
+ * Create a debug logger for a specific component
179
+ *
180
+ * @param component - Component name
181
+ * @returns Logger instance with debug capabilities
182
+ */
183
+ export declare function createDebugLogger(component: string): Logger & {
184
+ trace: (message: string, context?: LogContext) => void;
185
+ };
186
+ /**
187
+ * Start performance measurement for an operation
188
+ *
189
+ * @param operation - Operation name
190
+ * @param context - Optional context
191
+ */
192
+ export declare function startProfiling(operation: string, context?: Record<string, unknown>): void;
193
+ /**
194
+ * End performance measurement and record result
195
+ *
196
+ * @param operation - Operation name
197
+ * @param context - Optional context (overrides context from startProfiling if provided)
198
+ */
199
+ export declare function endProfiling(operation: string, context?: Record<string, unknown>): void;
200
+ /**
201
+ * Get all performance measurements
202
+ */
203
+ export declare function getPerformanceMeasurements(): PerformanceMeasurement[];
204
+ /**
205
+ * Clear performance measurements
206
+ */
207
+ export declare function clearPerformanceMeasurements(): void;
208
+ /**
209
+ * Log network request start
210
+ *
211
+ * @param id - Request ID
212
+ * @param method - HTTP method
213
+ * @param url - URL
214
+ * @param headers - Request headers
215
+ * @param body - Request body
216
+ */
217
+ export declare function traceNetworkRequest(id: string, method: string, url: string, headers: Record<string, string>, body?: string): void;
218
+ /**
219
+ * Log network response
220
+ *
221
+ * @param id - Request ID
222
+ * @param status - HTTP status code
223
+ * @param headers - Response headers
224
+ * @param body - Response body
225
+ * @param error - Error (if failed)
226
+ */
227
+ export declare function traceNetworkResponse(id: string, status?: number, headers?: Record<string, string>, body?: string, error?: string): void;
228
+ /**
229
+ * Get all network traces
230
+ */
231
+ export declare function getNetworkTraces(): NetworkTrace[];
232
+ /**
233
+ * Clear network traces
234
+ */
235
+ export declare function clearNetworkTraces(): void;
236
+ /**
237
+ * Log crypto operation
238
+ *
239
+ * @param operation - Operation type
240
+ * @param algorithm - Algorithm name
241
+ * @param inputSize - Input size (bytes)
242
+ * @param outputSize - Output size (bytes)
243
+ * @param duration - Duration (ms)
244
+ * @param success - Success flag
245
+ * @param error - Error message (if failed)
246
+ */
247
+ export declare function traceCryptoOperation(operation: string, algorithm: string, inputSize: number, outputSize?: number, duration?: number, success?: boolean, error?: string): void;
248
+ /**
249
+ * Get all crypto traces
250
+ */
251
+ export declare function getCryptoTraces(): CryptoTrace[];
252
+ /**
253
+ * Clear crypto traces
254
+ */
255
+ export declare function clearCryptoTraces(): void;
256
+ /**
257
+ * Dump internal state of an agent
258
+ *
259
+ * @param agent - Agent instance
260
+ * @returns State snapshot
261
+ */
262
+ export declare function dumpState(agent: Agent): AgentStateSnapshot;
263
+ /**
264
+ * Get all state snapshots
265
+ */
266
+ export declare function getStateSnapshots(): AgentStateSnapshot[];
267
+ /**
268
+ * Clear state snapshots
269
+ */
270
+ export declare function clearStateSnapshots(): void;
271
+ /**
272
+ * Export all debug data as JSON
273
+ *
274
+ * @returns JSON string with all debug data
275
+ */
276
+ export declare function exportDebugData(): string;
277
+ /**
278
+ * Clear all debug data
279
+ */
280
+ export declare function clearAllDebugData(): void;
281
+ /**
282
+ * Generate debug report
283
+ *
284
+ * @returns Human-readable debug report
285
+ */
286
+ export declare function generateDebugReport(): string;
@@ -0,0 +1 @@
1
+ import{createLogger,LogLevel}from"./logger.js";class DebugModeState{enabled=!1;options={};measurements=[];networkTraces=[];cryptoTraces=[];stateSnapshots=[];activeTimers=new Map}const globalDebugState=new DebugModeState;export function enableDebugMode(e={}){globalDebugState.enabled=!0,globalDebugState.options={verbose:e.verbose??!1,traceNetwork:e.traceNetwork??!1,traceCrypto:e.traceCrypto??!1,profile:e.profile??!1,trackMemory:e.trackMemory??!1,traceState:e.traceState??!1,output:e.output??console.log,filters:e.filters};const t=createLogger("debug-mode");t.setLevel(LogLevel.DEBUG),t.info("Debug mode enabled",{options:globalDebugState.options})}export function disableDebugMode(){globalDebugState.enabled=!1,globalDebugState.measurements=[],globalDebugState.networkTraces=[],globalDebugState.cryptoTraces=[],globalDebugState.stateSnapshots=[],globalDebugState.activeTimers.clear();createLogger("debug-mode").info("Debug mode disabled")}export function isDebugEnabled(){return globalDebugState.enabled}export function getDebugOptions(){return{...globalDebugState.options}}export function createDebugLogger(e){const t=createLogger(e);return globalDebugState.enabled&&globalDebugState.options.verbose&&t.setLevel(LogLevel.DEBUG),{...t,trace(e,o){if(globalDebugState.enabled&&globalDebugState.options.verbose){if(globalDebugState.options.filters){const{include:t,exclude:o}=globalDebugState.options.filters;if(t&&!t.some(t=>t.test(e)))return;if(o&&o.some(t=>t.test(e)))return}t.debug(e,o)}}}}export function startProfiling(e,t){if(!globalDebugState.enabled||!globalDebugState.options.profile)return;const o=performance.now();globalDebugState.activeTimers.set(e,{startTime:o,context:t});createDebugLogger("profiler").trace(`[PROFILE] Starting: ${e}`,t)}export function endProfiling(e,t){if(!globalDebugState.enabled||!globalDebugState.options.profile)return;const o=globalDebugState.activeTimers.get(e);if(!o){return void createDebugLogger("profiler").warn(`[PROFILE] No start time found for: ${e}`)}const r=performance.now(),a=r-o.startTime,s=t??o.context;let n,u,g;if(globalDebugState.options.trackMemory&&"undefined"!=typeof process&&process.memoryUsage){u=process.memoryUsage().heapUsed,n=u,g=0}const l={operation:e,startTime:o.startTime,endTime:r,duration:a,memoryBefore:n,memoryAfter:u,memoryDelta:g,context:s};globalDebugState.measurements.push(l),globalDebugState.activeTimers.delete(e);createDebugLogger("profiler").trace(`[PROFILE] Completed: ${e} (${a.toFixed(2)}ms)`,{duration:a,memoryDelta:g,...t})}export function getPerformanceMeasurements(){return[...globalDebugState.measurements]}export function clearPerformanceMeasurements(){globalDebugState.measurements=[],globalDebugState.activeTimers.clear()}export function traceNetworkRequest(e,t,o,r,a){if(!globalDebugState.enabled||!globalDebugState.options.traceNetwork)return;const s={id:e,method:t,url:o,requestHeaders:redactHeaders(r),requestBody:truncateBody(a),startTime:performance.now()};globalDebugState.networkTraces.push(s);createDebugLogger("network").trace(`[NETWORK] ${t} ${o}`,{requestId:e,headers:s.requestHeaders,bodyLength:a?.length??0})}export function traceNetworkResponse(e,t,o,r,a){if(!globalDebugState.enabled||!globalDebugState.options.traceNetwork)return;const s=globalDebugState.networkTraces.find(t=>t.id===e);if(!s)return;s.endTime=performance.now(),s.duration=s.endTime-s.startTime,s.status=t,s.responseHeaders=o?redactHeaders(o):void 0,s.responseBody=truncateBody(r),s.error=a;createDebugLogger("network").trace(`[NETWORK] Response ${t??"ERROR"} (${s.duration.toFixed(2)}ms)`,{requestId:e,status:t,duration:s.duration,error:a})}export function getNetworkTraces(){return[...globalDebugState.networkTraces]}export function clearNetworkTraces(){globalDebugState.networkTraces=[]}export function traceCryptoOperation(e,t,o,r,a,s,n){if(!globalDebugState.enabled||!globalDebugState.options.traceCrypto)return;const u={operation:e,algorithm:t,inputSize:o,outputSize:r,duration:a??0,success:s??!0,error:n,timestamp:Date.now()};globalDebugState.cryptoTraces.push(u);createDebugLogger("crypto").trace(`[CRYPTO] ${e} (${t})`,{inputSize:o,outputSize:r,duration:a,success:s,error:n})}export function getCryptoTraces(){return[...globalDebugState.cryptoTraces]}export function clearCryptoTraces(){globalDebugState.cryptoTraces=[]}export function dumpState(e){const t={did:e.did,identityMode:e.identityMode??"persistent",registered:e.registered??!1,registryUrl:e.registry?.url,nonceStoreType:e.nonceStore?.constructor?.name??"unknown",nonceCount:e.nonceStore?.size??0,transportType:e.transport?.constructor?.name??"unknown",securityPolicy:{level:e.securityPolicy?.level??"unknown",replayWindow:e.securityPolicy?.replayWindow??0,timestampTolerance:e.securityPolicy?.timestampTolerance??0},postQuantum:e.postQuantum??!1,memoryUsage:"undefined"!=typeof process&&process.memoryUsage?process.memoryUsage().heapUsed:void 0,timestamp:Date.now()};globalDebugState.enabled&&globalDebugState.options.traceState&&globalDebugState.stateSnapshots.push(t);return createDebugLogger("state").trace("[STATE] Agent snapshot",t),t}export function getStateSnapshots(){return[...globalDebugState.stateSnapshots]}export function clearStateSnapshots(){globalDebugState.stateSnapshots=[]}export function exportDebugData(){const e={enabled:globalDebugState.enabled,options:globalDebugState.options,measurements:globalDebugState.measurements,networkTraces:globalDebugState.networkTraces,cryptoTraces:globalDebugState.cryptoTraces,stateSnapshots:globalDebugState.stateSnapshots,exportedAt:(new Date).toISOString()};return JSON.stringify(e,null,2)}export function clearAllDebugData(){clearPerformanceMeasurements(),clearNetworkTraces(),clearCryptoTraces(),clearStateSnapshots()}function redactHeaders(e){const t={},o=new Set(["authorization","cookie","set-cookie","x-api-key","x-auth-token"]);for(const[r,a]of Object.entries(e)){const e=r.toLowerCase();o.has(e)?t[r]="[REDACTED]":t[r]=a}return t}function truncateBody(e){if(!e)return;const t=1e3;return e.length<=t?e:e.substring(0,t)+`... (${e.length-t} more bytes)`}export function generateDebugReport(){const e=[];if(e.push("=".repeat(80)),e.push("xBind Debug Report"),e.push("=".repeat(80)),e.push(""),e.push(`Generated: ${(new Date).toISOString()}`),e.push("Debug Mode: "+(globalDebugState.enabled?"ENABLED":"DISABLED")),e.push(""),globalDebugState.measurements.length>0){e.push("Performance Measurements:"),e.push("-".repeat(80));for(const t of globalDebugState.measurements)e.push(` ${t.operation}: ${t.duration.toFixed(2)}ms`),void 0!==t.memoryDelta&&e.push(` Memory: ${formatBytes(t.memoryDelta)}`);e.push("")}if(globalDebugState.networkTraces.length>0){e.push("Network Traces:"),e.push("-".repeat(80));for(const t of globalDebugState.networkTraces)e.push(` ${t.method} ${t.url}`),t.status&&e.push(` Status: ${t.status}`),t.duration&&e.push(` Duration: ${t.duration.toFixed(2)}ms`),t.error&&e.push(` Error: ${t.error}`);e.push("")}if(globalDebugState.cryptoTraces.length>0){e.push("Crypto Operations:"),e.push("-".repeat(80));for(const t of globalDebugState.cryptoTraces)e.push(` ${t.operation} (${t.algorithm})`),e.push(` Input: ${formatBytes(t.inputSize)}`),t.outputSize&&e.push(` Output: ${formatBytes(t.outputSize)}`),e.push(` Duration: ${t.duration.toFixed(2)}ms`),e.push(` Success: ${t.success}`),t.error&&e.push(` Error: ${t.error}`);e.push("")}if(globalDebugState.stateSnapshots.length>0){e.push("State Snapshots:"),e.push("-".repeat(80));const t=globalDebugState.stateSnapshots[globalDebugState.stateSnapshots.length-1];t&&(e.push(` DID: ${t.did}`),e.push(` Mode: ${t.identityMode}`),e.push(` Registered: ${t.registered}`),e.push(` Post-Quantum: ${t.postQuantum}`),e.push(` Nonce Count: ${t.nonceCount}`),t.memoryUsage&&e.push(` Memory Usage: ${formatBytes(t.memoryUsage)}`)),e.push("")}return e.push("=".repeat(80)),e.join("\n")}function formatBytes(e){if(0===e)return"0 B";const t=Math.floor(Math.log(Math.abs(e))/Math.log(1024));return`${(e/Math.pow(1024,t)).toFixed(2)} ${["B","KB","MB","GB"][t]}`}
@@ -1,96 +1 @@
1
- import { ok, err } from"./_deps/shared/index.js";
2
- import { toBase64 } from"./_deps/crypto/index.js";
3
- /**
4
- * Generate a DID document for a given DID.
5
- *
6
- * Includes service endpoints that advertise PRIVATE.ME/xBind.
7
- * Both did:key and did:privateme DIDs generate the same service endpoints.
8
- *
9
- * @param did - The DID (did:key:z... or did:privateme:z...)
10
- * @param rawPublicKey - The 32-byte Ed25519 public key
11
- * @param name - Optional name for the identity
12
- * @returns DID document with service endpoints
13
- */
14
- export function generateDidDocument(did, rawPublicKey, name) {
15
- if (!did.startsWith('did:key:') && !did.startsWith('did:privateme:')) {
16
- return err('INVALID_DID_FORMAT');
17
- }
18
- // Convert public key to base64 for inclusion in document
19
- const publicKeyBase64 = toBase64(rawPublicKey);
20
- const document = {
21
- '@context': [
22
- 'https://www.w3.org/ns/did/v1',
23
- 'https://w3id.org/security/suites/ed25519-2020/v1',
24
- ],
25
- id: did,
26
- publicKey: [
27
- {
28
- id: `${did}#key-1`,
29
- type: 'Ed25519VerificationKey2020',
30
- controller: did,
31
- publicKeyBase64,
32
- },
33
- ],
34
- authentication: [`${did}#key-1`],
35
- assertionMethod: [`${did}#key-1`],
36
- keyAgreement: [`${did}#key-1`],
37
- service: [
38
- {
39
- id: `${did}#identity-provider`,
40
- type: 'IdentityProvider',
41
- serviceEndpoint: 'https://private.me',
42
- description: 'PRIVATE.ME xBind Agent - M2M identity authentication',
43
- },
44
- {
45
- id: `${did}#documentation`,
46
- type: 'Documentation',
47
- serviceEndpoint: 'https://private.me/docs/xbind.html',
48
- description: 'Learn more about PRIVATE.ME/xBind protocol',
49
- },
50
- ],
51
- ...(name ? { name } : {}),
52
- };
53
- return ok(document);
54
- }
55
- /**
56
- * Resolve a DID to its document (simulated).
57
- *
58
- * In a production system, this would query a DID resolver.
59
- * For now, this generates a synthetic document based on the DID.
60
- *
61
- * @param did - The DID to resolve
62
- * @param rawPublicKey - The 32-byte Ed25519 public key
63
- * @returns DID document or error
64
- */
65
- export async function resolveDid(did, rawPublicKey) {
66
- // In a production system, this would make an HTTP request to a DID resolver
67
- // For now, generate a synthetic document
68
- return generateDidDocument(did, rawPublicKey);
69
- }
70
- /**
71
- * Extract service endpoints from a DID document.
72
- *
73
- * Filters for PRIVATE.ME service endpoints to provide discovery information.
74
- *
75
- * @param document - The DID document
76
- * @returns Array of service endpoints advertising PRIVATE.ME services
77
- */
78
- export function getServiceEndpoints(document) {
79
- if (!document.service)
80
- return [];
81
- return document.service
82
- .filter((svc) => {
83
- const endpoint = typeof svc.serviceEndpoint === 'string' ? svc.serviceEndpoint : '';
84
- return (endpoint.includes('private.me') ||
85
- svc.type.includes('PRIVATE.ME') ||
86
- svc.type === 'IdentityProvider' ||
87
- svc.type === 'Documentation');
88
- })
89
- .map((svc) => ({
90
- type: svc.type,
91
- endpoint: typeof svc.serviceEndpoint === 'string'
92
- ? svc.serviceEndpoint
93
- : JSON.stringify(svc.serviceEndpoint),
94
- description: svc.description,
95
- }));
96
- }
1
+ import{ok,err}from"./_deps/shared/index.js";import{toBase64}from"./crypto-utils.js";export function generateDidDocument(e,t,i){if(!e.startsWith("did:key:")&&!e.startsWith("did:privateme:"))return err("INVALID_DID_FORMAT");const n={"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/suites/ed25519-2020/v1"],id:e,publicKey:[{id:`${e}#key-1`,type:"Ed25519VerificationKey2020",controller:e,publicKeyBase64:toBase64(t)}],authentication:[`${e}#key-1`],assertionMethod:[`${e}#key-1`],keyAgreement:[`${e}#key-1`],service:[{id:`${e}#identity-provider`,type:"IdentityProvider",serviceEndpoint:"https://private.me",description:"PRIVATE.ME xBind Agent - M2M identity authentication"},{id:`${e}#documentation`,type:"Documentation",serviceEndpoint:"https://private.me/docs/xbind.html",description:"Learn more about PRIVATE.ME/xBind protocol"}],...i?{name:i}:{}};return ok(n)}export async function resolveDid(e,t){return generateDidDocument(e,t)}export function getServiceEndpoints(e){return e.service?e.service.filter(e=>("string"==typeof e.serviceEndpoint?e.serviceEndpoint:"").includes("private.me")||e.type.includes("PRIVATE.ME")||"IdentityProvider"===e.type||"Documentation"===e.type).map(e=>({type:e.type,endpoint:"string"==typeof e.serviceEndpoint?e.serviceEndpoint:JSON.stringify(e.serviceEndpoint),description:e.description})):[]}
@@ -1,121 +1 @@
1
- import { ok, err } from"./_deps/shared/index.js";
2
- import { publicKeyToDid, didToPublicKeyBytes } from './identity.js';
3
- /**
4
- * Mechanism 4: Convert Ed25519 public key to did:privateme DID.
5
- *
6
- * Format: did:privateme:z + base58btc(0xed01 || publicKey)
7
- *
8
- * This is a new DID method identifier for PRIVATE.ME ACIs.
9
- * It uses the same base58btc encoding as did:key for compatibility,
10
- * but signals that the identity is backed by PRIVATE.ME infrastructure.
11
- *
12
- * Backward compatible: agents accept both did:key and did:privateme formats.
13
- *
14
- * @param rawPublicKey - 32-byte Ed25519 public key
15
- * @returns DID in format did:privateme:z...
16
- */
17
- export function publicKeyToPrivateMeDid(rawPublicKey) {
18
- // Use same encoding as did:key, but with privateme method
19
- const didKeyFormat = publicKeyToDid(rawPublicKey);
20
- // Replace did:key: with did:privateme:
21
- return didKeyFormat.replace(/^did:key:/, 'did:privateme:');
22
- }
23
- /**
24
- * Extract raw 32-byte public key from a did:privateme DID.
25
- *
26
- * Format: did:privateme:z + base58btc(0xed01 || publicKey)
27
- *
28
- * @param did - DID in format did:privateme:z...
29
- * @returns 32-byte public key or error
30
- */
31
- export function privateMeDidToPublicKeyBytes(did) {
32
- if (!did.startsWith('did:privateme:z')) {
33
- return err('INVALID_DID_FORMAT');
34
- }
35
- // Convert to did:key format temporarily for parsing
36
- const didKeyFormat = did.replace(/^did:privateme:/, 'did:key:');
37
- // Use the existing parser
38
- const result = didToPublicKeyBytes(didKeyFormat);
39
- if (!result.ok) {
40
- return err(result.error);
41
- }
42
- return ok(result.value);
43
- }
44
- /**
45
- * Determine if a DID is in the new did:privateme format.
46
- *
47
- * @param did - The DID to check
48
- * @returns true if DID is did:privateme format, false otherwise
49
- */
50
- export function isPrivateMeDid(did) {
51
- return did.startsWith('did:privateme:');
52
- }
53
- /**
54
- * Determine if a DID is in the did:key format.
55
- *
56
- * @param did - The DID to check
57
- * @returns true if DID is did:key format, false otherwise
58
- */
59
- export function isDidKeyFormat(did) {
60
- return did.startsWith('did:key:');
61
- }
62
- /**
63
- * Convert between DID formats (did:key ↔ did:privateme).
64
- *
65
- * Allows backward compatibility between old did:key and new did:privateme formats.
66
- * The public key remains the same; only the method identifier changes.
67
- *
68
- * @param did - Source DID in either format
69
- * @returns Converted DID in the other format, or error
70
- */
71
- export function convertDidFormat(did) {
72
- if (isDidKeyFormat(did)) {
73
- // Convert did:key to did:privateme
74
- return ok(did.replace(/^did:key:/, 'did:privateme:'));
75
- }
76
- if (isPrivateMeDid(did)) {
77
- // Convert did:privateme to did:key
78
- return ok(did.replace(/^did:privateme:/, 'did:key:'));
79
- }
80
- return err('UNSUPPORTED_DID_FORMAT');
81
- }
82
- /**
83
- * Normalize a DID to the canonical format (did:privateme).
84
- *
85
- * All DIDs are converted to did:privateme format for consistency.
86
- * Existing did:key DIDs are automatically upgraded.
87
- *
88
- * @param did - Source DID in any supported format
89
- * @returns Normalized DID in did:privateme format
90
- */
91
- export function normalizeDid(did) {
92
- if (isPrivateMeDid(did)) {
93
- // Already in target format
94
- return ok(did);
95
- }
96
- if (isDidKeyFormat(did)) {
97
- // Convert to did:privateme
98
- return ok(did.replace(/^did:key:/, 'did:privateme:'));
99
- }
100
- return err('UNSUPPORTED_DID_FORMAT');
101
- }
102
- /**
103
- * Parse a DID into method, identifier, and fragment.
104
- *
105
- * @param did - Full DID string
106
- * @returns Parsed DID components or error
107
- */
108
- export function parseDid(did) {
109
- const fragmentMatch = did.indexOf('#');
110
- const base = fragmentMatch >= 0 ? did.substring(0, fragmentMatch) : did;
111
- const fragment = fragmentMatch >= 0 ? did.substring(fragmentMatch + 1) : undefined;
112
- const parts = base.split(':');
113
- if (parts.length < 3 || parts[0] !== 'did') {
114
- return err('INVALID_DID_FORMAT');
115
- }
116
- return ok({
117
- method: parts[1],
118
- identifier: parts.slice(2).join(':'),
119
- fragment,
120
- });
121
- }
1
+ import{ok,err}from"./_deps/shared/index.js";import{publicKeyToDid,didToPublicKeyBytes}from"./identity.js";export function publicKeyToPrivateMeDid(e){return publicKeyToDid(e).replace(/^did:key:/,"did:privateme:")}export function privateMeDidToPublicKeyBytes(e){if(!e.startsWith("did:privateme:z"))return err("INVALID_DID_FORMAT");const i=e.replace(/^did:privateme:/,"did:key:"),r=didToPublicKeyBytes(i);return r.ok?ok(r.value):err(r.error)}export function isPrivateMeDid(e){return e.startsWith("did:privateme:")}export function isDidKeyFormat(e){return e.startsWith("did:key:")}export function convertDidFormat(e){return isDidKeyFormat(e)?ok(e.replace(/^did:key:/,"did:privateme:")):isPrivateMeDid(e)?ok(e.replace(/^did:privateme:/,"did:key:")):err("UNSUPPORTED_DID_FORMAT")}export function normalizeDid(e){return isPrivateMeDid(e)?ok(e):isDidKeyFormat(e)?ok(e.replace(/^did:key:/,"did:privateme:")):err("UNSUPPORTED_DID_FORMAT")}export function parseDid(e){const i=e.indexOf("#"),r=i>=0?e.substring(0,i):e,t=i>=0?e.substring(i+1):void 0,d=r.split(":");return d.length<3||"did"!==d[0]?err("INVALID_DID_FORMAT"):ok({method:d[1],identifier:d.slice(2).join(":"),fragment:t})}