@private.me/xbind 1.2.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 (295) hide show
  1. package/AGENTS.md +778 -0
  2. package/LICENSE.md +27 -0
  3. package/README.md +400 -0
  4. package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
  5. package/dist-standalone/_deps/crypto/base64.js +97 -0
  6. package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
  7. package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
  8. package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
  9. package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
  10. package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
  11. package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
  12. package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
  13. package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
  14. package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
  15. package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
  16. package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
  17. package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
  18. package/dist-standalone/_deps/crypto/errors.js +109 -0
  19. package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
  20. package/dist-standalone/_deps/crypto/hmac.js +66 -0
  21. package/dist-standalone/_deps/crypto/index.d.ts +20 -0
  22. package/dist-standalone/_deps/crypto/index.js +45 -0
  23. package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
  24. package/dist-standalone/_deps/crypto/padding.js +53 -0
  25. package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
  26. package/dist-standalone/_deps/crypto/share-header.js +63 -0
  27. package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
  28. package/dist-standalone/_deps/crypto/shares.js +148 -0
  29. package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
  30. package/dist-standalone/_deps/crypto/tlv.js +195 -0
  31. package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
  32. package/dist-standalone/_deps/crypto/uuid.js +56 -0
  33. package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
  34. package/dist-standalone/_deps/crypto/verify.js +15 -0
  35. package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
  36. package/dist-standalone/_deps/crypto/xorida.js +215 -0
  37. package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
  38. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
  39. package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
  40. package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
  41. package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
  42. package/dist-standalone/_deps/shared/cjs/index.js +492 -0
  43. package/dist-standalone/_deps/shared/cjs/package.json +1 -0
  44. package/dist-standalone/_deps/shared/cjs/types.js +403 -0
  45. package/dist-standalone/_deps/shared/errors.d.ts +48 -0
  46. package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
  47. package/dist-standalone/_deps/shared/errors.js +192 -0
  48. package/dist-standalone/_deps/shared/errors.js.map +1 -0
  49. package/dist-standalone/_deps/shared/index.d.ts +4 -0
  50. package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
  51. package/dist-standalone/_deps/shared/index.js +78 -0
  52. package/dist-standalone/_deps/shared/index.js.map +1 -0
  53. package/dist-standalone/_deps/shared/types.d.ts +1097 -0
  54. package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
  55. package/dist-standalone/_deps/shared/types.js +89 -0
  56. package/dist-standalone/_deps/shared/types.js.map +1 -0
  57. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
  58. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
  59. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
  60. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
  61. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
  62. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
  63. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
  64. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
  65. package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
  66. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
  67. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
  68. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
  69. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
  70. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
  71. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
  72. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
  73. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
  74. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
  75. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
  76. package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
  77. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
  78. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
  79. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
  80. package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
  81. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
  82. package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
  83. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
  84. package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
  85. package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
  86. package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
  87. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
  88. package/dist-standalone/_deps/ux-helpers/index.js +16 -0
  89. package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
  90. package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
  91. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
  92. package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
  93. package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
  94. package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
  95. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
  96. package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
  97. package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
  98. package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
  99. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
  100. package/dist-standalone/_deps/ux-helpers/search.js +116 -0
  101. package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
  102. package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
  103. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
  104. package/dist-standalone/_deps/ux-helpers/types.js +7 -0
  105. package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
  106. package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
  107. package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
  108. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
  109. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
  110. package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
  111. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
  112. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
  113. package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
  114. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
  115. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
  116. package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
  117. package/dist-standalone/_deps/xchange/errors.js +1 -0
  118. package/dist-standalone/_deps/xchange/index.d.ts +15 -0
  119. package/dist-standalone/_deps/xchange/index.js +1 -0
  120. package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
  121. package/dist-standalone/_deps/xchange/invite-client.js +1 -0
  122. package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
  123. package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
  124. package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
  125. package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
  126. package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
  127. package/dist-standalone/_deps/xchange/xchange.js +1 -0
  128. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
  129. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
  130. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
  131. package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
  132. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
  133. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
  134. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
  135. package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
  136. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
  137. package/dist-standalone/_deps/xregistry/discovery.js +1 -0
  138. package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
  139. package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
  140. package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
  141. package/dist-standalone/_deps/xregistry/errors.js +1 -0
  142. package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
  143. package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
  144. package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
  145. package/dist-standalone/_deps/xregistry/index.js +1 -0
  146. package/dist-standalone/_deps/xregistry/index.js.map +1 -0
  147. package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
  148. package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
  149. package/dist-standalone/_deps/xregistry/registry.js +1 -0
  150. package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
  151. package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
  152. package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
  153. package/dist-standalone/_deps/xregistry/schema.js +1 -0
  154. package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
  155. package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
  156. package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
  157. package/dist-standalone/_deps/xregistry/types.js +1 -0
  158. package/dist-standalone/_deps/xregistry/types.js.map +1 -0
  159. package/dist-standalone/agent-call.d.ts +286 -0
  160. package/dist-standalone/agent-call.js +642 -0
  161. package/dist-standalone/agent-sdk.d.ts +207 -0
  162. package/dist-standalone/agent-sdk.js +328 -0
  163. package/dist-standalone/agent.d.ts +670 -0
  164. package/dist-standalone/agent.js +1529 -0
  165. package/dist-standalone/approval.d.ts +145 -0
  166. package/dist-standalone/approval.js +193 -0
  167. package/dist-standalone/auth.d.ts +75 -0
  168. package/dist-standalone/auth.js +219 -0
  169. package/dist-standalone/auto-accept.d.ts +102 -0
  170. package/dist-standalone/auto-accept.js +229 -0
  171. package/dist-standalone/backup-config.d.ts +150 -0
  172. package/dist-standalone/backup-config.js +201 -0
  173. package/dist-standalone/checkpoint.d.ts +125 -0
  174. package/dist-standalone/checkpoint.js +186 -0
  175. package/dist-standalone/cjs/agent-call.js +651 -0
  176. package/dist-standalone/cjs/agent-sdk.js +332 -0
  177. package/dist-standalone/cjs/agent.js +1566 -0
  178. package/dist-standalone/cjs/approval.js +199 -0
  179. package/dist-standalone/cjs/auth.js +225 -0
  180. package/dist-standalone/cjs/auto-accept.js +233 -0
  181. package/dist-standalone/cjs/backup-config.js +207 -0
  182. package/dist-standalone/cjs/checkpoint.js +193 -0
  183. package/dist-standalone/cjs/cli/init.js +487 -0
  184. package/dist-standalone/cjs/connect.js +312 -0
  185. package/dist-standalone/cjs/did-document.js +101 -0
  186. package/dist-standalone/cjs/did-privateme.js +130 -0
  187. package/dist-standalone/cjs/did-web.js +201 -0
  188. package/dist-standalone/cjs/discovery.js +462 -0
  189. package/dist-standalone/cjs/dual-mode.js +251 -0
  190. package/dist-standalone/cjs/email-templates.js +313 -0
  191. package/dist-standalone/cjs/email-transport.js +239 -0
  192. package/dist-standalone/cjs/envelope.js +510 -0
  193. package/dist-standalone/cjs/errors.js +562 -0
  194. package/dist-standalone/cjs/gateway-state.js +55 -0
  195. package/dist-standalone/cjs/gateway-transport.js +120 -0
  196. package/dist-standalone/cjs/guardrails.js +223 -0
  197. package/dist-standalone/cjs/http-compat.js +272 -0
  198. package/dist-standalone/cjs/identity.js +541 -0
  199. package/dist-standalone/cjs/index.js +224 -0
  200. package/dist-standalone/cjs/invitation.js +421 -0
  201. package/dist-standalone/cjs/invite.js +328 -0
  202. package/dist-standalone/cjs/key-agreement.js +246 -0
  203. package/dist-standalone/cjs/lazy-init.js +300 -0
  204. package/dist-standalone/cjs/mdns-discovery.js +202 -0
  205. package/dist-standalone/cjs/nonce-store.js +66 -0
  206. package/dist-standalone/cjs/package.json +3 -0
  207. package/dist-standalone/cjs/pairing-manager.js +223 -0
  208. package/dist-standalone/cjs/policy.js +320 -0
  209. package/dist-standalone/cjs/redis-nonce-store.js +76 -0
  210. package/dist-standalone/cjs/registry-middleware.js +50 -0
  211. package/dist-standalone/cjs/retry-transport.js +102 -0
  212. package/dist-standalone/cjs/security-policy.js +204 -0
  213. package/dist-standalone/cjs/split-channel.js +177 -0
  214. package/dist-standalone/cjs/subscription-proof.js +230 -0
  215. package/dist-standalone/cjs/succession.js +148 -0
  216. package/dist-standalone/cjs/transport.js +63 -0
  217. package/dist-standalone/cjs/trust-registry.js +742 -0
  218. package/dist-standalone/cjs/verify.js +25 -0
  219. package/dist-standalone/cjs/xfetch.js +252 -0
  220. package/dist-standalone/cli/init.d.ts +63 -0
  221. package/dist-standalone/cli/init.js +450 -0
  222. package/dist-standalone/connect.d.ts +143 -0
  223. package/dist-standalone/connect.js +274 -0
  224. package/dist-standalone/did-document.d.ts +65 -0
  225. package/dist-standalone/did-document.js +96 -0
  226. package/dist-standalone/did-privateme.d.ts +70 -0
  227. package/dist-standalone/did-privateme.js +121 -0
  228. package/dist-standalone/did-web.d.ts +73 -0
  229. package/dist-standalone/did-web.js +196 -0
  230. package/dist-standalone/discovery.d.ts +176 -0
  231. package/dist-standalone/discovery.js +458 -0
  232. package/dist-standalone/dual-mode.d.ts +145 -0
  233. package/dist-standalone/dual-mode.js +247 -0
  234. package/dist-standalone/email-templates.d.ts +41 -0
  235. package/dist-standalone/email-templates.js +309 -0
  236. package/dist-standalone/email-transport.d.ts +139 -0
  237. package/dist-standalone/email-transport.js +232 -0
  238. package/dist-standalone/envelope.d.ts +288 -0
  239. package/dist-standalone/envelope.js +497 -0
  240. package/dist-standalone/errors.d.ts +74 -0
  241. package/dist-standalone/errors.js +548 -0
  242. package/dist-standalone/gateway-state.d.ts +32 -0
  243. package/dist-standalone/gateway-state.js +51 -0
  244. package/dist-standalone/gateway-transport.d.ts +59 -0
  245. package/dist-standalone/gateway-transport.js +116 -0
  246. package/dist-standalone/guardrails.d.ts +136 -0
  247. package/dist-standalone/guardrails.js +216 -0
  248. package/dist-standalone/http-compat.d.ts +150 -0
  249. package/dist-standalone/http-compat.js +267 -0
  250. package/dist-standalone/identity.d.ts +176 -0
  251. package/dist-standalone/identity.js +516 -0
  252. package/dist-standalone/index.d.ts +83 -0
  253. package/dist-standalone/index.js +51 -0
  254. package/dist-standalone/invitation.d.ts +211 -0
  255. package/dist-standalone/invitation.js +415 -0
  256. package/dist-standalone/invite.d.ts +192 -0
  257. package/dist-standalone/invite.js +324 -0
  258. package/dist-standalone/key-agreement.d.ts +122 -0
  259. package/dist-standalone/key-agreement.js +236 -0
  260. package/dist-standalone/lazy-init.d.ts +167 -0
  261. package/dist-standalone/lazy-init.js +295 -0
  262. package/dist-standalone/mdns-discovery.d.ts +117 -0
  263. package/dist-standalone/mdns-discovery.js +195 -0
  264. package/dist-standalone/nonce-store.d.ts +39 -0
  265. package/dist-standalone/nonce-store.js +62 -0
  266. package/dist-standalone/package.json +11 -0
  267. package/dist-standalone/pairing-manager.d.ts +147 -0
  268. package/dist-standalone/pairing-manager.js +219 -0
  269. package/dist-standalone/policy.d.ts +150 -0
  270. package/dist-standalone/policy.js +315 -0
  271. package/dist-standalone/redis-nonce-store.d.ts +93 -0
  272. package/dist-standalone/redis-nonce-store.js +72 -0
  273. package/dist-standalone/registry-middleware.d.ts +38 -0
  274. package/dist-standalone/registry-middleware.js +47 -0
  275. package/dist-standalone/retry-transport.d.ts +76 -0
  276. package/dist-standalone/retry-transport.js +98 -0
  277. package/dist-standalone/security-policy.d.ts +146 -0
  278. package/dist-standalone/security-policy.js +198 -0
  279. package/dist-standalone/split-channel.d.ts +69 -0
  280. package/dist-standalone/split-channel.js +171 -0
  281. package/dist-standalone/subscription-proof.d.ts +103 -0
  282. package/dist-standalone/subscription-proof.js +224 -0
  283. package/dist-standalone/succession.d.ts +57 -0
  284. package/dist-standalone/succession.js +142 -0
  285. package/dist-standalone/transport.d.ts +50 -0
  286. package/dist-standalone/transport.js +59 -0
  287. package/dist-standalone/trust-registry.d.ts +286 -0
  288. package/dist-standalone/trust-registry.js +702 -0
  289. package/dist-standalone/verify.d.ts +16 -0
  290. package/dist-standalone/verify.js +16 -0
  291. package/dist-standalone/xfetch.d.ts +129 -0
  292. package/dist-standalone/xfetch.js +247 -0
  293. package/llms.txt +800 -0
  294. package/package.json +79 -0
  295. package/share1.dat +0 -0
@@ -0,0 +1,93 @@
1
+ import type { NonceStore } from './nonce-store.js';
2
+ /**
3
+ * Minimal Redis client interface.
4
+ *
5
+ * Users implement this with their Redis library of choice (ioredis, node-redis, etc.).
6
+ * This keeps @private.me/xbind free of concrete Redis dependencies.
7
+ */
8
+ export interface RedisClient {
9
+ /**
10
+ * SET key value EX seconds NX -- atomic set-if-not-exists with TTL.
11
+ * @param key - The key to set.
12
+ * @param value - The value to store.
13
+ * @param ttlSeconds - Time-to-live in seconds.
14
+ * @returns 'OK' if the key was set (new), null if the key already exists (duplicate).
15
+ */
16
+ setNX(key: string, value: string, ttlSeconds: number): Promise<string | null>;
17
+ /**
18
+ * DEL key -- delete a key from Redis.
19
+ * @param key - The key to delete.
20
+ * @returns The number of keys removed.
21
+ */
22
+ del(key: string): Promise<number>;
23
+ /**
24
+ * QUIT -- disconnect from Redis gracefully.
25
+ */
26
+ quit(): Promise<void>;
27
+ }
28
+ /**
29
+ * Configuration options for RedisNonceStore.
30
+ */
31
+ export interface RedisNonceStoreOptions {
32
+ /** The Redis client instance to use for nonce storage. */
33
+ readonly client: RedisClient;
34
+ /** TTL in seconds for nonce entries. Default: 600 (10 minutes). */
35
+ readonly ttlSeconds?: number;
36
+ /** Key prefix for all nonce entries in Redis. Default: 'nonce:'. */
37
+ readonly keyPrefix?: string;
38
+ }
39
+ /**
40
+ * Redis-backed nonce store for multi-node deployments.
41
+ *
42
+ * Uses Redis SET NX with TTL for atomic, distributed nonce deduplication.
43
+ * Nonce expiry is handled by Redis TTL -- no manual cleanup needed.
44
+ * Zero npm dependencies: users provide their own RedisClient implementation.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * import { RedisNonceStore } from '@private.me/xbind';
49
+ * import Redis from 'ioredis';
50
+ *
51
+ * const redis = new Redis();
52
+ * const store = new RedisNonceStore({
53
+ * client: {
54
+ * setNX: (key, value, ttl) =>
55
+ * redis.set(key, value, 'EX', ttl, 'NX'),
56
+ * del: (key) => redis.del(key),
57
+ * quit: () => redis.quit(),
58
+ * },
59
+ * });
60
+ * ```
61
+ */
62
+ export declare class RedisNonceStore implements NonceStore {
63
+ private readonly client;
64
+ private readonly ttlSeconds;
65
+ private readonly keyPrefix;
66
+ constructor(opts: RedisNonceStoreOptions);
67
+ /**
68
+ * Check if a nonce is fresh and record it atomically via Redis SET NX.
69
+ *
70
+ * Uses Redis SET with NX (set-if-not-exists) and EX (TTL in seconds)
71
+ * for atomic, distributed deduplication. If the key already exists in
72
+ * any Redis-connected node, the nonce is rejected as a duplicate.
73
+ *
74
+ * @param nonce - The nonce string to check.
75
+ * @param senderDid - The DID of the sender.
76
+ * @returns true if the nonce is new (accepted), false if duplicate (rejected).
77
+ */
78
+ check(nonce: string, senderDid: string): Promise<boolean>;
79
+ /**
80
+ * No-op for Redis store -- TTL-based expiry is handled automatically.
81
+ *
82
+ * This method exists to satisfy the NonceStore interface. Redis keys
83
+ * expire based on the TTL set during setNX, so no manual cleanup is needed.
84
+ */
85
+ cleanup(): void;
86
+ /**
87
+ * Disconnect from Redis gracefully.
88
+ *
89
+ * Calls the underlying RedisClient quit() method to close the connection.
90
+ * After calling dispose(), the store should not be used.
91
+ */
92
+ dispose(): void;
93
+ }
@@ -0,0 +1,72 @@
1
+ /* -- RedisNonceStore -- Cross-Node Replay Prevention -- */
2
+ /** Default TTL for nonce entries: 600 seconds (10 minutes). */
3
+ const DEFAULT_TTL_SECONDS = 600;
4
+ /** Default key prefix for Redis nonce keys. */
5
+ const DEFAULT_KEY_PREFIX = 'nonce:';
6
+ /**
7
+ * Redis-backed nonce store for multi-node deployments.
8
+ *
9
+ * Uses Redis SET NX with TTL for atomic, distributed nonce deduplication.
10
+ * Nonce expiry is handled by Redis TTL -- no manual cleanup needed.
11
+ * Zero npm dependencies: users provide their own RedisClient implementation.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { RedisNonceStore } from '@private.me/xbind';
16
+ * import Redis from 'ioredis';
17
+ *
18
+ * const redis = new Redis();
19
+ * const store = new RedisNonceStore({
20
+ * client: {
21
+ * setNX: (key, value, ttl) =>
22
+ * redis.set(key, value, 'EX', ttl, 'NX'),
23
+ * del: (key) => redis.del(key),
24
+ * quit: () => redis.quit(),
25
+ * },
26
+ * });
27
+ * ```
28
+ */
29
+ export class RedisNonceStore {
30
+ client;
31
+ ttlSeconds;
32
+ keyPrefix;
33
+ constructor(opts) {
34
+ this.client = opts.client;
35
+ this.ttlSeconds = opts.ttlSeconds ?? DEFAULT_TTL_SECONDS;
36
+ this.keyPrefix = opts.keyPrefix ?? DEFAULT_KEY_PREFIX;
37
+ }
38
+ /**
39
+ * Check if a nonce is fresh and record it atomically via Redis SET NX.
40
+ *
41
+ * Uses Redis SET with NX (set-if-not-exists) and EX (TTL in seconds)
42
+ * for atomic, distributed deduplication. If the key already exists in
43
+ * any Redis-connected node, the nonce is rejected as a duplicate.
44
+ *
45
+ * @param nonce - The nonce string to check.
46
+ * @param senderDid - The DID of the sender.
47
+ * @returns true if the nonce is new (accepted), false if duplicate (rejected).
48
+ */
49
+ async check(nonce, senderDid) {
50
+ const key = `${this.keyPrefix}${senderDid}:${nonce}`;
51
+ const result = await this.client.setNX(key, '1', this.ttlSeconds);
52
+ return result === 'OK';
53
+ }
54
+ /**
55
+ * No-op for Redis store -- TTL-based expiry is handled automatically.
56
+ *
57
+ * This method exists to satisfy the NonceStore interface. Redis keys
58
+ * expire based on the TTL set during setNX, so no manual cleanup is needed.
59
+ */
60
+ cleanup() {
61
+ // No-op: Redis TTL handles expiry automatically
62
+ }
63
+ /**
64
+ * Disconnect from Redis gracefully.
65
+ *
66
+ * Calls the underlying RedisClient quit() method to close the connection.
67
+ * After calling dispose(), the store should not be used.
68
+ */
69
+ dispose() {
70
+ void this.client.quit();
71
+ }
72
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Express middleware for protecting trust registry endpoints with bearer auth.
3
+ *
4
+ * GET/HEAD requests pass through (public reads). POST/PUT/DELETE require
5
+ * a valid Bearer token matching the configured admin token.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import express from 'express';
10
+ * import { createRegistryAuthMiddleware } from '@private.me/xbind';
11
+ *
12
+ * const app = express();
13
+ * app.use('/registry', createRegistryAuthMiddleware(process.env.REGISTRY_ADMIN_TOKEN!));
14
+ * ```
15
+ */
16
+ /** Express-compatible request with method and headers. */
17
+ interface MiddlewareRequest {
18
+ readonly method: string;
19
+ readonly headers: Record<string, string | string[] | undefined>;
20
+ }
21
+ /** Express-compatible response with status and json. */
22
+ interface MiddlewareResponse {
23
+ status: (code: number) => {
24
+ json: (data: unknown) => void;
25
+ };
26
+ }
27
+ /**
28
+ * Create an Express-compatible middleware that protects write operations
29
+ * on registry endpoints with bearer token authentication.
30
+ *
31
+ * GET and HEAD requests pass through without authentication.
32
+ * POST, PUT, and DELETE require `Authorization: Bearer <token>`.
33
+ *
34
+ * @param token - The admin token to validate against.
35
+ * @returns Express middleware function.
36
+ */
37
+ export declare function createRegistryAuthMiddleware(token: string): (req: MiddlewareRequest, res: MiddlewareResponse, next: (err?: unknown) => void) => void;
38
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Express middleware for protecting trust registry endpoints with bearer auth.
3
+ *
4
+ * GET/HEAD requests pass through (public reads). POST/PUT/DELETE require
5
+ * a valid Bearer token matching the configured admin token.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import express from 'express';
10
+ * import { createRegistryAuthMiddleware } from '@private.me/xbind';
11
+ *
12
+ * const app = express();
13
+ * app.use('/registry', createRegistryAuthMiddleware(process.env.REGISTRY_ADMIN_TOKEN!));
14
+ * ```
15
+ */
16
+ /**
17
+ * Create an Express-compatible middleware that protects write operations
18
+ * on registry endpoints with bearer token authentication.
19
+ *
20
+ * GET and HEAD requests pass through without authentication.
21
+ * POST, PUT, and DELETE require `Authorization: Bearer <token>`.
22
+ *
23
+ * @param token - The admin token to validate against.
24
+ * @returns Express middleware function.
25
+ */
26
+ export function createRegistryAuthMiddleware(token) {
27
+ return (req, res, next) => {
28
+ const method = req.method.toUpperCase();
29
+ if (method === 'GET' || method === 'HEAD') {
30
+ next();
31
+ return;
32
+ }
33
+ const authHeader = typeof req.headers['authorization'] === 'string'
34
+ ? req.headers['authorization']
35
+ : undefined;
36
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
37
+ res.status(401).json({ error: 'UNAUTHORIZED' });
38
+ return;
39
+ }
40
+ const provided = authHeader.slice('Bearer '.length);
41
+ if (provided !== token) {
42
+ res.status(401).json({ error: 'UNAUTHORIZED' });
43
+ return;
44
+ }
45
+ next();
46
+ };
47
+ }
@@ -0,0 +1,76 @@
1
+ import type { Result } from '@private.me/shared';
2
+ import type { XailTransportAdapter, TransportError, EnvelopeHandler } from './transport.js';
3
+ import type { AnyTransportEnvelope } from './envelope.js';
4
+ /**
5
+ * Configuration options for exponential backoff retry logic.
6
+ */
7
+ export interface RetryOptions {
8
+ /** Maximum number of retry attempts. Default: 3. */
9
+ maxRetries?: number;
10
+ /** Base delay in milliseconds for exponential backoff. Default: 1000. */
11
+ baseDelayMs?: number;
12
+ /** Maximum jitter in milliseconds for randomization. Default: 200. */
13
+ maxJitterMs?: number;
14
+ }
15
+ /**
16
+ * Decorator that adds exponential backoff retry logic to any transport adapter.
17
+ *
18
+ * Retry delays follow exponential backoff with jitter:
19
+ * - Formula: 2^attempt * baseDelay + jitter
20
+ * - Jitter: Math.random() * maxJitter * 2 - maxJitter
21
+ * - Default delays: 1s, 2s, 4s (with ±200ms jitter)
22
+ *
23
+ * Use case: Push notification delivery failures requiring automatic retry.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const transport = new RetryTransportAdapter(baseTransport, {
28
+ * maxRetries: 3,
29
+ * baseDelayMs: 1000,
30
+ * maxJitterMs: 200
31
+ * });
32
+ * ```
33
+ */
34
+ export declare class RetryTransportAdapter implements XailTransportAdapter {
35
+ private readonly inner;
36
+ private readonly maxRetries;
37
+ private readonly baseDelayMs;
38
+ private readonly maxJitterMs;
39
+ /**
40
+ * Create a new RetryTransportAdapter wrapping an existing transport.
41
+ *
42
+ * @param inner - The transport adapter to wrap with retry logic
43
+ * @param options - Retry configuration options
44
+ */
45
+ constructor(inner: XailTransportAdapter, options?: RetryOptions);
46
+ /**
47
+ * Send an envelope with exponential backoff retry logic.
48
+ *
49
+ * Retries on all error types (SEND_FAILED, NETWORK_ERROR, RECIPIENT_UNREACHABLE, TIMEOUT).
50
+ * Throws error after all retries are exhausted.
51
+ *
52
+ * @param envelope - The envelope to send
53
+ * @param recipientDid - The recipient's DID
54
+ * @returns Result with void on success, or TransportError on failure
55
+ * @throws Error if all retry attempts are exhausted
56
+ */
57
+ send(envelope: AnyTransportEnvelope, recipientDid: string): Promise<Result<void, TransportError>>;
58
+ /**
59
+ * Register a handler for incoming envelopes.
60
+ * Delegates directly to the inner transport.
61
+ *
62
+ * @param handler - The envelope handler function
63
+ */
64
+ onReceive(handler: EnvelopeHandler): void;
65
+ /**
66
+ * Shut down the transport.
67
+ * Delegates directly to the inner transport.
68
+ */
69
+ dispose(): void;
70
+ /**
71
+ * Sleep for a specified duration.
72
+ *
73
+ * @param ms - Duration in milliseconds
74
+ */
75
+ private sleep;
76
+ }
@@ -0,0 +1,98 @@
1
+ /* ── Implementation ── */
2
+ /**
3
+ * Decorator that adds exponential backoff retry logic to any transport adapter.
4
+ *
5
+ * Retry delays follow exponential backoff with jitter:
6
+ * - Formula: 2^attempt * baseDelay + jitter
7
+ * - Jitter: Math.random() * maxJitter * 2 - maxJitter
8
+ * - Default delays: 1s, 2s, 4s (with ±200ms jitter)
9
+ *
10
+ * Use case: Push notification delivery failures requiring automatic retry.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const transport = new RetryTransportAdapter(baseTransport, {
15
+ * maxRetries: 3,
16
+ * baseDelayMs: 1000,
17
+ * maxJitterMs: 200
18
+ * });
19
+ * ```
20
+ */
21
+ export class RetryTransportAdapter {
22
+ inner;
23
+ maxRetries;
24
+ baseDelayMs;
25
+ maxJitterMs;
26
+ /**
27
+ * Create a new RetryTransportAdapter wrapping an existing transport.
28
+ *
29
+ * @param inner - The transport adapter to wrap with retry logic
30
+ * @param options - Retry configuration options
31
+ */
32
+ constructor(inner, options = {}) {
33
+ this.inner = inner;
34
+ this.maxRetries = options.maxRetries ?? 3;
35
+ this.baseDelayMs = options.baseDelayMs ?? 1000;
36
+ this.maxJitterMs = options.maxJitterMs ?? 200;
37
+ }
38
+ /**
39
+ * Send an envelope with exponential backoff retry logic.
40
+ *
41
+ * Retries on all error types (SEND_FAILED, NETWORK_ERROR, RECIPIENT_UNREACHABLE, TIMEOUT).
42
+ * Throws error after all retries are exhausted.
43
+ *
44
+ * @param envelope - The envelope to send
45
+ * @param recipientDid - The recipient's DID
46
+ * @returns Result with void on success, or TransportError on failure
47
+ * @throws Error if all retry attempts are exhausted
48
+ */
49
+ async send(envelope, recipientDid) {
50
+ let lastError;
51
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
52
+ const result = await this.inner.send(envelope, recipientDid);
53
+ // Success - return immediately
54
+ if (result.ok) {
55
+ return result;
56
+ }
57
+ // Store error for final throw
58
+ lastError = result.error;
59
+ // Don't delay after final attempt
60
+ if (attempt < this.maxRetries) {
61
+ // Exponential backoff: 2^attempt * baseDelay + jitter
62
+ const delay = Math.pow(2, attempt) * this.baseDelayMs;
63
+ // SAFETY: Using crypto.getRandomValues for OWASP-compliant secure random jitter
64
+ const jitterArray = new Uint32Array(1);
65
+ crypto.getRandomValues(jitterArray);
66
+ const jitter = (jitterArray[0] / 0xffffffff) * this.maxJitterMs * 2 -
67
+ this.maxJitterMs;
68
+ await this.sleep(delay + jitter);
69
+ }
70
+ }
71
+ // All retries exhausted - throw error with clear message
72
+ throw new Error(`Failed after ${this.maxRetries} retries: ${lastError ?? 'unknown error'}`);
73
+ }
74
+ /**
75
+ * Register a handler for incoming envelopes.
76
+ * Delegates directly to the inner transport.
77
+ *
78
+ * @param handler - The envelope handler function
79
+ */
80
+ onReceive(handler) {
81
+ this.inner.onReceive(handler);
82
+ }
83
+ /**
84
+ * Shut down the transport.
85
+ * Delegates directly to the inner transport.
86
+ */
87
+ dispose() {
88
+ this.inner.dispose();
89
+ }
90
+ /**
91
+ * Sleep for a specified duration.
92
+ *
93
+ * @param ms - Duration in milliseconds
94
+ */
95
+ sleep(ms) {
96
+ return new Promise((resolve) => setTimeout(resolve, ms));
97
+ }
98
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Security policy interface for automatic risk-based Xorida activation.
3
+ *
4
+ * Determines when to apply information-theoretic security (XorIDA split-channel)
5
+ * vs standard encrypted transport based on action semantics and parameters.
6
+ *
7
+ * Design principle: Security should be invisible to users. The policy classifies
8
+ * risk automatically so developers don't need to understand threshold cryptography.
9
+ */
10
+ /** Security mode selected by policy. */
11
+ export type SecurityMode = {
12
+ readonly type: 'standard';
13
+ } | {
14
+ readonly type: 'split';
15
+ readonly shares: number;
16
+ readonly threshold: number;
17
+ } | {
18
+ readonly type: 'xchange';
19
+ };
20
+ /** Explicit security level override (user-facing). */
21
+ export type SecurityLevel = 'auto' | 'standard' | 'high' | 'critical';
22
+ /** Context for security classification. */
23
+ export interface SecurityContext {
24
+ /** Action being performed (e.g., 'transfer', 'execute', 'send'). */
25
+ readonly action: string;
26
+ /** Action parameters (amount, recipient, scope, etc.). */
27
+ readonly params: Record<string, unknown>;
28
+ /** Sender DID. */
29
+ readonly sender: string;
30
+ /** Recipient DID. */
31
+ readonly recipient: string;
32
+ /** Permission scope. */
33
+ readonly scope: string;
34
+ /** Explicit security level override (if provided by user). */
35
+ readonly securityOverride?: SecurityLevel;
36
+ }
37
+ /** Reason why a particular security mode was selected. */
38
+ export interface SecurityDecision {
39
+ /** Selected security mode. */
40
+ readonly mode: SecurityMode;
41
+ /** Human-readable reason for this decision. */
42
+ readonly reason: string;
43
+ /** Whether this was an auto-decision or explicit override. */
44
+ readonly wasOverridden: boolean;
45
+ }
46
+ /**
47
+ * Security policy interface.
48
+ *
49
+ * Implementations classify actions into security modes based on risk.
50
+ * Used by Agent.send() to automatically apply Xorida when needed.
51
+ */
52
+ export interface SecurityPolicy {
53
+ /**
54
+ * Classify an action into a security mode.
55
+ *
56
+ * @param context - Action context (action, params, sender, recipient, scope)
57
+ * @returns Security decision with mode and reason
58
+ */
59
+ classify(context: SecurityContext): SecurityDecision;
60
+ }
61
+ /**
62
+ * Default security policy for basic XBind.
63
+ *
64
+ * Rules:
65
+ * - Transfers over $100,000: High security (3 shares, 2-of-3 threshold)
66
+ * - Cross-entity communication: High security (3 shares, 2-of-3 threshold)
67
+ * - Explicit 'high' override: High security (3 shares, 2-of-3 threshold)
68
+ * - Explicit 'critical' override: Critical security (5 shares, 3-of-5 threshold)
69
+ * - Everything else: Standard encrypted transport (V3 hybrid PQ)
70
+ *
71
+ * Enterprise and Government variants extend this with custom rules.
72
+ */
73
+ export declare class DefaultSecurityPolicy implements SecurityPolicy {
74
+ private readonly options;
75
+ /**
76
+ * Create a default security policy.
77
+ *
78
+ * @param options - Optional configuration
79
+ * @param options.highValueThreshold - Amount threshold for high security (default: 100000)
80
+ * @param options.enableXchange - Allow Xchange mode for performance (default: false)
81
+ */
82
+ constructor(options?: {
83
+ readonly highValueThreshold?: number;
84
+ readonly enableXchange?: boolean;
85
+ });
86
+ classify(context: SecurityContext): SecurityDecision;
87
+ }
88
+ /**
89
+ * Security mode description with multiple format representations.
90
+ */
91
+ export interface SecurityModeDescription {
92
+ /** Security mode type. */
93
+ readonly type: 'standard' | 'split' | 'xchange';
94
+ /** Security level classification. */
95
+ readonly level: 'standard' | 'high' | 'critical' | 'performance';
96
+ /** Share configuration (only for split mode). */
97
+ readonly shares?: {
98
+ readonly total: number;
99
+ readonly threshold: number;
100
+ };
101
+ /** Multiple format representations. */
102
+ readonly formats: {
103
+ readonly multiline: string;
104
+ readonly singleline: string;
105
+ readonly json: string;
106
+ readonly markdown: string;
107
+ };
108
+ }
109
+ /**
110
+ * Get a human-readable security mode description.
111
+ *
112
+ * Used for logging and user feedback.
113
+ *
114
+ * @param mode - Security mode
115
+ * @returns User-friendly description
116
+ *
117
+ * @deprecated Use describeSecurityModeStructured() for new code. This function remains for backward compatibility.
118
+ */
119
+ export declare function describeSecurityMode(mode: SecurityMode): string;
120
+ /**
121
+ * Get a structured security mode description with multiple formats.
122
+ *
123
+ * Returns an object with the security classification and formatted descriptions
124
+ * optimized for different use cases (display, logging, APIs, docs).
125
+ *
126
+ * @param mode - Security mode
127
+ * @returns Security mode description with formats
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const mode: SecurityMode = { type: 'split', shares: 3, threshold: 2 };
132
+ * const description = describeSecurityModeStructured(mode);
133
+ *
134
+ * console.log(description.formats.singleline);
135
+ * // "high | split | 2-of-3"
136
+ *
137
+ * console.log(description.formats.multiline);
138
+ * // "Security Level: High
139
+ * // Mode: Split-channel (XorIDA)
140
+ * // Shares: 3 total, 2 required"
141
+ *
142
+ * console.log(description.shares);
143
+ * // { total: 3, threshold: 2 }
144
+ * ```
145
+ */
146
+ export declare function describeSecurityModeStructured(mode: SecurityMode): SecurityModeDescription;