@private.me/xbind 1.3.5 → 2.3.4

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 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.enableDebugMode=enableDebugMode,exports.disableDebugMode=disableDebugMode,exports.isDebugEnabled=isDebugEnabled,exports.getDebugOptions=getDebugOptions,exports.createDebugLogger=createDebugLogger,exports.startProfiling=startProfiling,exports.endProfiling=endProfiling,exports.getPerformanceMeasurements=getPerformanceMeasurements,exports.clearPerformanceMeasurements=clearPerformanceMeasurements,exports.traceNetworkRequest=traceNetworkRequest,exports.traceNetworkResponse=traceNetworkResponse,exports.getNetworkTraces=getNetworkTraces,exports.clearNetworkTraces=clearNetworkTraces,exports.traceCryptoOperation=traceCryptoOperation,exports.getCryptoTraces=getCryptoTraces,exports.clearCryptoTraces=clearCryptoTraces,exports.dumpState=dumpState,exports.getStateSnapshots=getStateSnapshots,exports.clearStateSnapshots=clearStateSnapshots,exports.exportDebugData=exportDebugData,exports.clearAllDebugData=clearAllDebugData,exports.generateDebugReport=generateDebugReport;const logger_js_1=require("./logger.js");class DebugModeState{enabled=!1;options={};measurements=[];networkTraces=[];cryptoTraces=[];stateSnapshots=[];activeTimers=new Map}const globalDebugState=new DebugModeState;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=(0,logger_js_1.createLogger)("debug-mode");t.setLevel(logger_js_1.LogLevel.DEBUG),t.info("Debug mode enabled",{options:globalDebugState.options})}function disableDebugMode(){globalDebugState.enabled=!1,globalDebugState.measurements=[],globalDebugState.networkTraces=[],globalDebugState.cryptoTraces=[],globalDebugState.stateSnapshots=[],globalDebugState.activeTimers.clear();(0,logger_js_1.createLogger)("debug-mode").info("Debug mode disabled")}function isDebugEnabled(){return globalDebugState.enabled}function getDebugOptions(){return{...globalDebugState.options}}function createDebugLogger(e){const t=(0,logger_js_1.createLogger)(e);return globalDebugState.enabled&&globalDebugState.options.verbose&&t.setLevel(logger_js_1.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)}}}}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)}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})}function getPerformanceMeasurements(){return[...globalDebugState.measurements]}function clearPerformanceMeasurements(){globalDebugState.measurements=[],globalDebugState.activeTimers.clear()}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})}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})}function getNetworkTraces(){return[...globalDebugState.networkTraces]}function clearNetworkTraces(){globalDebugState.networkTraces=[]}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})}function getCryptoTraces(){return[...globalDebugState.cryptoTraces]}function clearCryptoTraces(){globalDebugState.cryptoTraces=[]}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}function getStateSnapshots(){return[...globalDebugState.stateSnapshots]}function clearStateSnapshots(){globalDebugState.stateSnapshots=[]}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)}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)`}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,101 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateDidDocument = generateDidDocument;
4
- exports.resolveDid = resolveDid;
5
- exports.getServiceEndpoints = getServiceEndpoints;
6
- const shared_1 = require("../_deps/shared/index.js");
7
- const crypto_1 = require("../_deps/crypto/index.js");
8
- /**
9
- * Generate a DID document for a given DID.
10
- *
11
- * Includes service endpoints that advertise PRIVATE.ME/xBind.
12
- * Both did:key and did:privateme DIDs generate the same service endpoints.
13
- *
14
- * @param did - The DID (did:key:z... or did:privateme:z...)
15
- * @param rawPublicKey - The 32-byte Ed25519 public key
16
- * @param name - Optional name for the identity
17
- * @returns DID document with service endpoints
18
- */
19
- function generateDidDocument(did, rawPublicKey, name) {
20
- if (!did.startsWith('did:key:') && !did.startsWith('did:privateme:')) {
21
- return (0, shared_1.err)('INVALID_DID_FORMAT');
22
- }
23
- // Convert public key to base64 for inclusion in document
24
- const publicKeyBase64 = (0, crypto_1.toBase64)(rawPublicKey);
25
- const document = {
26
- '@context': [
27
- 'https://www.w3.org/ns/did/v1',
28
- 'https://w3id.org/security/suites/ed25519-2020/v1',
29
- ],
30
- id: did,
31
- publicKey: [
32
- {
33
- id: `${did}#key-1`,
34
- type: 'Ed25519VerificationKey2020',
35
- controller: did,
36
- publicKeyBase64,
37
- },
38
- ],
39
- authentication: [`${did}#key-1`],
40
- assertionMethod: [`${did}#key-1`],
41
- keyAgreement: [`${did}#key-1`],
42
- service: [
43
- {
44
- id: `${did}#identity-provider`,
45
- type: 'IdentityProvider',
46
- serviceEndpoint: 'https://private.me',
47
- description: 'PRIVATE.ME xBind Agent - M2M identity authentication',
48
- },
49
- {
50
- id: `${did}#documentation`,
51
- type: 'Documentation',
52
- serviceEndpoint: 'https://private.me/docs/xbind.html',
53
- description: 'Learn more about PRIVATE.ME/xBind protocol',
54
- },
55
- ],
56
- ...(name ? { name } : {}),
57
- };
58
- return (0, shared_1.ok)(document);
59
- }
60
- /**
61
- * Resolve a DID to its document (simulated).
62
- *
63
- * In a production system, this would query a DID resolver.
64
- * For now, this generates a synthetic document based on the DID.
65
- *
66
- * @param did - The DID to resolve
67
- * @param rawPublicKey - The 32-byte Ed25519 public key
68
- * @returns DID document or error
69
- */
70
- async function resolveDid(did, rawPublicKey) {
71
- // In a production system, this would make an HTTP request to a DID resolver
72
- // For now, generate a synthetic document
73
- return generateDidDocument(did, rawPublicKey);
74
- }
75
- /**
76
- * Extract service endpoints from a DID document.
77
- *
78
- * Filters for PRIVATE.ME service endpoints to provide discovery information.
79
- *
80
- * @param document - The DID document
81
- * @returns Array of service endpoints advertising PRIVATE.ME services
82
- */
83
- function getServiceEndpoints(document) {
84
- if (!document.service)
85
- return [];
86
- return document.service
87
- .filter((svc) => {
88
- const endpoint = typeof svc.serviceEndpoint === 'string' ? svc.serviceEndpoint : '';
89
- return (endpoint.includes('private.me') ||
90
- svc.type.includes('PRIVATE.ME') ||
91
- svc.type === 'IdentityProvider' ||
92
- svc.type === 'Documentation');
93
- })
94
- .map((svc) => ({
95
- type: svc.type,
96
- endpoint: typeof svc.serviceEndpoint === 'string'
97
- ? svc.serviceEndpoint
98
- : JSON.stringify(svc.serviceEndpoint),
99
- description: svc.description,
100
- }));
101
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.generateDidDocument=generateDidDocument,exports.resolveDid=resolveDid,exports.getServiceEndpoints=getServiceEndpoints;const shared_1=require("../_deps/shared/index.js"),crypto_utils_js_1=require("./crypto-utils.js");function generateDidDocument(e,t,i){if(!e.startsWith("did:key:")&&!e.startsWith("did:privateme:"))return(0,shared_1.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:(0,crypto_utils_js_1.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(0,shared_1.ok)(n)}async function resolveDid(e,t){return generateDidDocument(e,t)}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,130 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicKeyToPrivateMeDid = publicKeyToPrivateMeDid;
4
- exports.privateMeDidToPublicKeyBytes = privateMeDidToPublicKeyBytes;
5
- exports.isPrivateMeDid = isPrivateMeDid;
6
- exports.isDidKeyFormat = isDidKeyFormat;
7
- exports.convertDidFormat = convertDidFormat;
8
- exports.normalizeDid = normalizeDid;
9
- exports.parseDid = parseDid;
10
- const shared_1 = require("../_deps/shared/index.js");
11
- const identity_js_1 = require("./identity.js");
12
- /**
13
- * Mechanism 4: Convert Ed25519 public key to did:privateme DID.
14
- *
15
- * Format: did:privateme:z + base58btc(0xed01 || publicKey)
16
- *
17
- * This is a new DID method identifier for PRIVATE.ME ACIs.
18
- * It uses the same base58btc encoding as did:key for compatibility,
19
- * but signals that the identity is backed by PRIVATE.ME infrastructure.
20
- *
21
- * Backward compatible: agents accept both did:key and did:privateme formats.
22
- *
23
- * @param rawPublicKey - 32-byte Ed25519 public key
24
- * @returns DID in format did:privateme:z...
25
- */
26
- function publicKeyToPrivateMeDid(rawPublicKey) {
27
- // Use same encoding as did:key, but with privateme method
28
- const didKeyFormat = (0, identity_js_1.publicKeyToDid)(rawPublicKey);
29
- // Replace did:key: with did:privateme:
30
- return didKeyFormat.replace(/^did:key:/, 'did:privateme:');
31
- }
32
- /**
33
- * Extract raw 32-byte public key from a did:privateme DID.
34
- *
35
- * Format: did:privateme:z + base58btc(0xed01 || publicKey)
36
- *
37
- * @param did - DID in format did:privateme:z...
38
- * @returns 32-byte public key or error
39
- */
40
- function privateMeDidToPublicKeyBytes(did) {
41
- if (!did.startsWith('did:privateme:z')) {
42
- return (0, shared_1.err)('INVALID_DID_FORMAT');
43
- }
44
- // Convert to did:key format temporarily for parsing
45
- const didKeyFormat = did.replace(/^did:privateme:/, 'did:key:');
46
- // Use the existing parser
47
- const result = (0, identity_js_1.didToPublicKeyBytes)(didKeyFormat);
48
- if (!result.ok) {
49
- return (0, shared_1.err)(result.error);
50
- }
51
- return (0, shared_1.ok)(result.value);
52
- }
53
- /**
54
- * Determine if a DID is in the new did:privateme format.
55
- *
56
- * @param did - The DID to check
57
- * @returns true if DID is did:privateme format, false otherwise
58
- */
59
- function isPrivateMeDid(did) {
60
- return did.startsWith('did:privateme:');
61
- }
62
- /**
63
- * Determine if a DID is in the did:key format.
64
- *
65
- * @param did - The DID to check
66
- * @returns true if DID is did:key format, false otherwise
67
- */
68
- function isDidKeyFormat(did) {
69
- return did.startsWith('did:key:');
70
- }
71
- /**
72
- * Convert between DID formats (did:key ↔ did:privateme).
73
- *
74
- * Allows backward compatibility between old did:key and new did:privateme formats.
75
- * The public key remains the same; only the method identifier changes.
76
- *
77
- * @param did - Source DID in either format
78
- * @returns Converted DID in the other format, or error
79
- */
80
- function convertDidFormat(did) {
81
- if (isDidKeyFormat(did)) {
82
- // Convert did:key to did:privateme
83
- return (0, shared_1.ok)(did.replace(/^did:key:/, 'did:privateme:'));
84
- }
85
- if (isPrivateMeDid(did)) {
86
- // Convert did:privateme to did:key
87
- return (0, shared_1.ok)(did.replace(/^did:privateme:/, 'did:key:'));
88
- }
89
- return (0, shared_1.err)('UNSUPPORTED_DID_FORMAT');
90
- }
91
- /**
92
- * Normalize a DID to the canonical format (did:privateme).
93
- *
94
- * All DIDs are converted to did:privateme format for consistency.
95
- * Existing did:key DIDs are automatically upgraded.
96
- *
97
- * @param did - Source DID in any supported format
98
- * @returns Normalized DID in did:privateme format
99
- */
100
- function normalizeDid(did) {
101
- if (isPrivateMeDid(did)) {
102
- // Already in target format
103
- return (0, shared_1.ok)(did);
104
- }
105
- if (isDidKeyFormat(did)) {
106
- // Convert to did:privateme
107
- return (0, shared_1.ok)(did.replace(/^did:key:/, 'did:privateme:'));
108
- }
109
- return (0, shared_1.err)('UNSUPPORTED_DID_FORMAT');
110
- }
111
- /**
112
- * Parse a DID into method, identifier, and fragment.
113
- *
114
- * @param did - Full DID string
115
- * @returns Parsed DID components or error
116
- */
117
- function parseDid(did) {
118
- const fragmentMatch = did.indexOf('#');
119
- const base = fragmentMatch >= 0 ? did.substring(0, fragmentMatch) : did;
120
- const fragment = fragmentMatch >= 0 ? did.substring(fragmentMatch + 1) : undefined;
121
- const parts = base.split(':');
122
- if (parts.length < 3 || parts[0] !== 'did') {
123
- return (0, shared_1.err)('INVALID_DID_FORMAT');
124
- }
125
- return (0, shared_1.ok)({
126
- method: parts[1],
127
- identifier: parts.slice(2).join(':'),
128
- fragment,
129
- });
130
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.publicKeyToPrivateMeDid=publicKeyToPrivateMeDid,exports.privateMeDidToPublicKeyBytes=privateMeDidToPublicKeyBytes,exports.isPrivateMeDid=isPrivateMeDid,exports.isDidKeyFormat=isDidKeyFormat,exports.convertDidFormat=convertDidFormat,exports.normalizeDid=normalizeDid,exports.parseDid=parseDid;const shared_1=require("../_deps/shared/index.js"),identity_js_1=require("./identity.js");function publicKeyToPrivateMeDid(e){return(0,identity_js_1.publicKeyToDid)(e).replace(/^did:key:/,"did:privateme:")}function privateMeDidToPublicKeyBytes(e){if(!e.startsWith("did:privateme:z"))return(0,shared_1.err)("INVALID_DID_FORMAT");const i=e.replace(/^did:privateme:/,"did:key:"),r=(0,identity_js_1.didToPublicKeyBytes)(i);return r.ok?(0,shared_1.ok)(r.value):(0,shared_1.err)(r.error)}function isPrivateMeDid(e){return e.startsWith("did:privateme:")}function isDidKeyFormat(e){return e.startsWith("did:key:")}function convertDidFormat(e){return isDidKeyFormat(e)?(0,shared_1.ok)(e.replace(/^did:key:/,"did:privateme:")):isPrivateMeDid(e)?(0,shared_1.ok)(e.replace(/^did:privateme:/,"did:key:")):(0,shared_1.err)("UNSUPPORTED_DID_FORMAT")}function normalizeDid(e){return isPrivateMeDid(e)?(0,shared_1.ok)(e):isDidKeyFormat(e)?(0,shared_1.ok)(e.replace(/^did:key:/,"did:privateme:")):(0,shared_1.err)("UNSUPPORTED_DID_FORMAT")}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]?(0,shared_1.err)("INVALID_DID_FORMAT"):(0,shared_1.ok)({method:d[1],identifier:d.slice(2).join(":"),fragment:t})}
@@ -1,201 +1 @@
1
- "use strict";
2
- /**
3
- * did:web resolver — resolves DIDs hosted on developer domains.
4
- *
5
- * Implements the W3C did:web method:
6
- * did:web:example.com -> https://example.com/.well-known/did.json
7
- * did:web:example.com:path:to -> https://example.com/path/to/did.json
8
- *
9
- * Enables direct agent-to-agent communication without a centralized registry.
10
- * Implements TrustRegistry interface for drop-in use with Agent class.
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.DidWebResolver = void 0;
14
- exports.didWebToUrl = didWebToUrl;
15
- const shared_1 = require("../_deps/shared/index.js");
16
- const crypto_1 = require("../_deps/crypto/index.js");
17
- /**
18
- * Resolve did:web DIDs by fetching DID documents from the hosting domain.
19
- *
20
- * Implements TrustRegistry interface so it can be used as a drop-in
21
- * replacement for MemoryTrustRegistry or HttpTrustRegistry.
22
- */
23
- class DidWebResolver {
24
- fetchFn;
25
- cacheTtlMs;
26
- cache = new Map();
27
- constructor(opts) {
28
- this.fetchFn = opts?.fetch ?? globalThis.fetch.bind(globalThis);
29
- this.cacheTtlMs = opts?.cacheTtlMs ?? 300_000;
30
- }
31
- /** Registration not supported for did:web (developers host their own). */
32
- async register(_did, _publicKey, _name, _scopes, _x25519PublicKey) {
33
- return (0, shared_1.err)('ALREADY_REGISTERED');
34
- }
35
- /**
36
- * Resolve a did:web DID to its raw public key bytes.
37
- * @param did - A did:web DID string.
38
- * @returns Public key bytes or error.
39
- */
40
- async resolve(did) {
41
- const entry = await this.fetchEntry(did);
42
- if (!entry.ok)
43
- return entry;
44
- if (entry.value.revoked)
45
- return (0, shared_1.err)('REVOKED');
46
- return (0, shared_1.ok)(entry.value.publicKey);
47
- }
48
- /**
49
- * Check if a did:web DID has a specific scope.
50
- * @param did - The DID to check.
51
- * @param scope - The scope to verify.
52
- * @returns True if scope is granted.
53
- */
54
- async hasScope(did, scope) {
55
- const entry = await this.fetchEntry(did);
56
- if (!entry.ok)
57
- return false;
58
- return entry.value.scopes.has(scope);
59
- }
60
- /**
61
- * Check if a did:web DID has a specific receive scope.
62
- * @param did - The DID to check.
63
- * @param scope - The scope to verify.
64
- * @returns True if receive scope is granted.
65
- */
66
- async hasReceiveScope(did, scope) {
67
- const entry = await this.fetchEntry(did);
68
- if (!entry.ok)
69
- return false;
70
- // Undefined = accept all scopes (backward compatibility)
71
- if (!entry.value.receiveScopes)
72
- return true;
73
- return entry.value.receiveScopes.has(scope);
74
- }
75
- /** Revocation not supported for did:web (developer controls their domain). */
76
- async revoke(_did) {
77
- return (0, shared_1.err)('NOT_FOUND');
78
- }
79
- /**
80
- * Get the full registry entry for a did:web DID.
81
- * @param did - The DID to look up.
82
- * @returns Full entry or error.
83
- */
84
- async getEntry(did) {
85
- return this.fetchEntry(did);
86
- }
87
- /** Number of cached entries (for testing). */
88
- get cacheSize() {
89
- return this.cache.size;
90
- }
91
- /** Fetch and parse a DID document, with caching. */
92
- async fetchEntry(did) {
93
- // Check cache
94
- const cached = this.cache.get(did);
95
- if (cached && Date.now() - cached.fetchedAt < this.cacheTtlMs) {
96
- return (0, shared_1.ok)(cached.entry);
97
- }
98
- const url = didWebToUrl(did);
99
- if (!url)
100
- return (0, shared_1.err)('NOT_FOUND');
101
- try {
102
- const res = await this.fetchFn(url);
103
- if (!res.ok)
104
- return (0, shared_1.err)('NOT_FOUND');
105
- const doc = (await res.json());
106
- const entry = parseDidDocument(did, doc);
107
- if (!entry)
108
- return (0, shared_1.err)('NOT_FOUND');
109
- this.cache.set(did, { entry, fetchedAt: Date.now() });
110
- return (0, shared_1.ok)(entry);
111
- }
112
- catch {
113
- return (0, shared_1.err)('NETWORK_ERROR');
114
- }
115
- }
116
- }
117
- exports.DidWebResolver = DidWebResolver;
118
- /**
119
- * Convert a did:web DID to its HTTPS URL.
120
- * did:web:example.com -> https://example.com/.well-known/did.json
121
- * did:web:example.com:path:to -> https://example.com/path/to/did.json
122
- * @param did - The did:web DID string.
123
- * @returns HTTPS URL or null if invalid.
124
- */
125
- function didWebToUrl(did) {
126
- if (!did.startsWith('did:web:'))
127
- return null;
128
- const parts = did.slice('did:web:'.length).split(':');
129
- if (parts.length === 0 || !parts[0])
130
- return null;
131
- const domain = decodeURIComponent(parts[0]);
132
- if (parts.length === 1) {
133
- return `https://${domain}/.well-known/did.json`;
134
- }
135
- const path = parts.slice(1).map(decodeURIComponent).join('/');
136
- return `https://${domain}/${path}/did.json`;
137
- }
138
- /** Parse a DID document into a RegistryEntry. */
139
- function parseDidDocument(did, doc) {
140
- if (!doc.verificationMethod || doc.verificationMethod.length === 0) {
141
- return null;
142
- }
143
- const vm = doc.verificationMethod[0];
144
- if (!vm)
145
- return null;
146
- let publicKey = null;
147
- if (vm.publicKeyMultibase) {
148
- publicKey = decodeMultibase(vm.publicKeyMultibase);
149
- }
150
- else if (vm.publicKeyBase64) {
151
- publicKey = (0, crypto_1.fromBase64)(vm.publicKeyBase64);
152
- }
153
- if (!publicKey)
154
- return null;
155
- return {
156
- did,
157
- publicKey,
158
- name: doc.xailName ?? did,
159
- scopes: new Set(doc.xailScopes ?? []),
160
- revoked: doc.deactivated === true,
161
- rotation_sequence: 1, // DID documents don't track rotation, default to 1
162
- };
163
- }
164
- /** Decode z-prefixed base58btc multibase to bytes. */
165
- function decodeMultibase(mb) {
166
- if (!mb.startsWith('z'))
167
- return null;
168
- return base58Decode(mb.slice(1));
169
- }
170
- /** Base58 decode (Bitcoin alphabet). */
171
- function base58Decode(s) {
172
- const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
173
- const BASE = BigInt(58);
174
- let num = BigInt(0);
175
- for (const char of s) {
176
- const idx = ALPHABET.indexOf(char);
177
- if (idx < 0)
178
- return new Uint8Array(0);
179
- num = num * BASE + BigInt(idx);
180
- }
181
- const hex = num.toString(16);
182
- const padded = hex.length % 2 ? '0' + hex : hex;
183
- const bytes = new Uint8Array(padded.length / 2);
184
- for (let i = 0; i < bytes.length; i++) {
185
- bytes[i] = parseInt(padded.slice(i * 2, i * 2 + 2), 16);
186
- }
187
- // Handle leading zeros (base58 "1" = 0x00)
188
- let leadingZeros = 0;
189
- for (const c of s) {
190
- if (c === '1')
191
- leadingZeros++;
192
- else
193
- break;
194
- }
195
- if (leadingZeros > 0) {
196
- const result = new Uint8Array(leadingZeros + bytes.length);
197
- result.set(bytes, leadingZeros);
198
- return result;
199
- }
200
- return bytes;
201
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DidWebResolver=void 0,exports.didWebToUrl=didWebToUrl;const shared_1=require("../_deps/shared/index.js"),crypto_utils_js_1=require("./crypto-utils.js");class DidWebResolver{fetchFn;cacheTtlMs;cache=new Map;constructor(e){this.fetchFn=e?.fetch??globalThis.fetch.bind(globalThis),this.cacheTtlMs=e?.cacheTtlMs??3e5}async register(e,t,r,n,s){return(0,shared_1.err)("ALREADY_REGISTERED")}async resolve(e){const t=await this.fetchEntry(e);return t.ok?t.value.revoked?(0,shared_1.err)("REVOKED"):(0,shared_1.ok)(t.value.publicKey):t}async hasScope(e,t){const r=await this.fetchEntry(e);return!!r.ok&&r.value.scopes.has(t)}async hasReceiveScope(e,t){const r=await this.fetchEntry(e);return!!r.ok&&(!r.value.receiveScopes||r.value.receiveScopes.has(t))}async revoke(e){return(0,shared_1.err)("NOT_FOUND")}async getEntry(e){return this.fetchEntry(e)}get cacheSize(){return this.cache.size}async fetchEntry(e){const t=this.cache.get(e);if(t&&Date.now()-t.fetchedAt<this.cacheTtlMs)return(0,shared_1.ok)(t.entry);const r=didWebToUrl(e);if(!r)return(0,shared_1.err)("NOT_FOUND");try{const t=await this.fetchFn(r);if(!t.ok)return(0,shared_1.err)("NOT_FOUND");const n=parseDidDocument(e,await t.json());return n?(this.cache.set(e,{entry:n,fetchedAt:Date.now()}),(0,shared_1.ok)(n)):(0,shared_1.err)("NOT_FOUND")}catch{return(0,shared_1.err)("NETWORK_ERROR")}}}function didWebToUrl(e){if(!e.startsWith("did:web:"))return null;const t=e.slice(8).split(":");if(0===t.length||!t[0])return null;const r=decodeURIComponent(t[0]);if(1===t.length)return`https://${r}/.well-known/did.json`;return`https://${r}/${t.slice(1).map(decodeURIComponent).join("/")}/did.json`}function parseDidDocument(e,t){if(!t.verificationMethod||0===t.verificationMethod.length)return null;const r=t.verificationMethod[0];if(!r)return null;let n=null;return r.publicKeyMultibase?n=decodeMultibase(r.publicKeyMultibase):r.publicKeyBase64&&(n=(0,crypto_utils_js_1.fromBase64)(r.publicKeyBase64)),n?{did:e,publicKey:n,name:t.xailName??e,scopes:new Set(t.xailScopes??[]),revoked:!0===t.deactivated,rotation_sequence:1}:null}function decodeMultibase(e){return e.startsWith("z")?base58Decode(e.slice(1)):null}function base58Decode(e){const t=BigInt(58);let r=BigInt(0);for(const n of e){const e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".indexOf(n);if(e<0)return new Uint8Array(0);r=r*t+BigInt(e)}const n=r.toString(16),s=n.length%2?"0"+n:n,i=new Uint8Array(s.length/2);for(let e=0;e<i.length;e++)i[e]=parseInt(s.slice(2*e,2*e+2),16);let c=0;for(const t of e){if("1"!==t)break;c++}if(c>0){const e=new Uint8Array(c+i.length);return e.set(i,c),e}return i}exports.DidWebResolver=DidWebResolver;