@private.me/xbind 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/README.md +55 -14
  2. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
  3. package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
  4. package/dist-standalone/_deps/shared/cjs/index.js +463 -1
  5. package/dist-standalone/_deps/shared/cjs/types.js +315 -1
  6. package/dist-standalone/_deps/shared/errors.js +244 -1
  7. package/dist-standalone/_deps/shared/index.js +72 -1
  8. package/dist-standalone/_deps/shared/types.js +86 -1
  9. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  10. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  20. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  21. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  28. package/dist-standalone/_deps/xchange/errors.js +1 -1
  29. package/dist-standalone/_deps/xchange/index.js +1 -1
  30. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  31. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  32. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  33. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  34. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  40. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  41. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  42. package/dist-standalone/_deps/xregistry/index.js +1 -1
  43. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  44. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  45. package/dist-standalone/_deps/xregistry/types.js +1 -1
  46. package/dist-standalone/agent-call.js +659 -1
  47. package/dist-standalone/agent-sdk.js +328 -1
  48. package/dist-standalone/agent.js +1800 -1
  49. package/dist-standalone/approval.js +193 -1
  50. package/dist-standalone/async-iterators.js +382 -1
  51. package/dist-standalone/auth.js +219 -1
  52. package/dist-standalone/auto-accept.js +229 -1
  53. package/dist-standalone/backup-config.js +201 -1
  54. package/dist-standalone/backup.js +326 -1
  55. package/dist-standalone/batch-operations.js +388 -1
  56. package/dist-standalone/cancellation.js +477 -1
  57. package/dist-standalone/checkpoint.js +186 -1
  58. package/dist-standalone/circuit-breaker.js +468 -1
  59. package/dist-standalone/cjs/agent-call.js +701 -1
  60. package/dist-standalone/cjs/agent-sdk.js +332 -1
  61. package/dist-standalone/cjs/agent.js +1837 -1
  62. package/dist-standalone/cjs/approval.js +199 -1
  63. package/dist-standalone/cjs/async-iterators.js +392 -1
  64. package/dist-standalone/cjs/auth.js +225 -1
  65. package/dist-standalone/cjs/auto-accept.js +233 -1
  66. package/dist-standalone/cjs/backup-config.js +207 -1
  67. package/dist-standalone/cjs/backup.js +330 -1
  68. package/dist-standalone/cjs/batch-operations.js +397 -1
  69. package/dist-standalone/cjs/cancellation.js +490 -1
  70. package/dist-standalone/cjs/checkpoint.js +193 -1
  71. package/dist-standalone/cjs/circuit-breaker.js +476 -1
  72. package/dist-standalone/cjs/cli/init.js +492 -1
  73. package/dist-standalone/cjs/config-validation.js +522 -1
  74. package/dist-standalone/cjs/connect.js +312 -1
  75. package/dist-standalone/cjs/connection-pool.js +506 -1
  76. package/dist-standalone/cjs/correlation-id.js +339 -1
  77. package/dist-standalone/cjs/crypto-utils.js +176 -1
  78. package/dist-standalone/cjs/debug-mode.js +534 -1
  79. package/dist-standalone/cjs/did-document.js +101 -1
  80. package/dist-standalone/cjs/did-privateme.js +130 -1
  81. package/dist-standalone/cjs/did-web.js +201 -1
  82. package/dist-standalone/cjs/discovery.js +462 -1
  83. package/dist-standalone/cjs/dual-mode.js +251 -1
  84. package/dist-standalone/cjs/email-templates.js +313 -1
  85. package/dist-standalone/cjs/email-transport.js +239 -1
  86. package/dist-standalone/cjs/envelope.js +538 -1
  87. package/dist-standalone/cjs/errors.js +913 -1
  88. package/dist-standalone/cjs/event-emitter.js +461 -1
  89. package/dist-standalone/cjs/gateway-state.js +55 -1
  90. package/dist-standalone/cjs/gateway-transport.js +120 -1
  91. package/dist-standalone/cjs/graceful-degradation.js +403 -1
  92. package/dist-standalone/cjs/guardrails.js +223 -1
  93. package/dist-standalone/cjs/health-check.js +336 -1
  94. package/dist-standalone/cjs/http-compat.js +272 -1
  95. package/dist-standalone/cjs/http-status-map.js +571 -1
  96. package/dist-standalone/cjs/identity.js +645 -1
  97. package/dist-standalone/cjs/index.js +406 -1
  98. package/dist-standalone/cjs/invitation.js +421 -1
  99. package/dist-standalone/cjs/invite.js +328 -1
  100. package/dist-standalone/cjs/key-agreement.js +335 -1
  101. package/dist-standalone/cjs/lazy-init.js +300 -1
  102. package/dist-standalone/cjs/logger.js +291 -1
  103. package/dist-standalone/cjs/mdns-discovery.js +202 -1
  104. package/dist-standalone/cjs/nonce-store.js +80 -1
  105. package/dist-standalone/cjs/pairing-manager.js +223 -1
  106. package/dist-standalone/cjs/plugin-system.js +264 -1
  107. package/dist-standalone/cjs/plugins/logging.js +168 -1
  108. package/dist-standalone/cjs/plugins/metrics.js +181 -1
  109. package/dist-standalone/cjs/plugins/validation.js +302 -1
  110. package/dist-standalone/cjs/policy.js +320 -1
  111. package/dist-standalone/cjs/progress-callbacks.js +583 -1
  112. package/dist-standalone/cjs/redis-nonce-store.js +76 -1
  113. package/dist-standalone/cjs/registry-middleware.js +50 -1
  114. package/dist-standalone/cjs/retry-strategies.js +544 -1
  115. package/dist-standalone/cjs/retry-transport.js +102 -1
  116. package/dist-standalone/cjs/runtime/browser.js +533 -1
  117. package/dist-standalone/cjs/runtime/edge.js +526 -1
  118. package/dist-standalone/cjs/runtime/react-native.js +394 -1
  119. package/dist-standalone/cjs/security-policy.js +245 -1
  120. package/dist-standalone/cjs/serialization.js +1040 -1
  121. package/dist-standalone/cjs/split-channel.js +225 -1
  122. package/dist-standalone/cjs/subscription-proof.js +230 -1
  123. package/dist-standalone/cjs/succession.js +148 -1
  124. package/dist-standalone/cjs/timeouts.js +412 -1
  125. package/dist-standalone/cjs/trace-context.js +424 -1
  126. package/dist-standalone/cjs/trace-spans.js +495 -1
  127. package/dist-standalone/cjs/transport.js +63 -1
  128. package/dist-standalone/cjs/trust-registry.js +991 -1
  129. package/dist-standalone/cjs/types/error-response.js +56 -1
  130. package/dist-standalone/cjs/vault-auth.js +178 -1
  131. package/dist-standalone/cjs/vault-store-loader.js +194 -1
  132. package/dist-standalone/cjs/verify.js +25 -1
  133. package/dist-standalone/cjs/version-info.js +543 -1
  134. package/dist-standalone/cjs/xfetch.js +340 -1
  135. package/dist-standalone/cli/init.js +455 -1
  136. package/dist-standalone/cli/setup.js +514 -1
  137. package/dist-standalone/cli/types.js +27 -1
  138. package/dist-standalone/cli/xbind.js +148 -1
  139. package/dist-standalone/config-validation.js +513 -1
  140. package/dist-standalone/connect.js +274 -1
  141. package/dist-standalone/connection-pool.js +500 -1
  142. package/dist-standalone/correlation-id.js +326 -1
  143. package/dist-standalone/crypto-utils.js +157 -1
  144. package/dist-standalone/debug-mode.js +510 -1
  145. package/dist-standalone/did-document.js +96 -1
  146. package/dist-standalone/did-privateme.js +121 -1
  147. package/dist-standalone/did-web.js +196 -1
  148. package/dist-standalone/discovery.js +458 -1
  149. package/dist-standalone/dual-mode.js +247 -1
  150. package/dist-standalone/email-templates.js +309 -1
  151. package/dist-standalone/email-transport.js +232 -1
  152. package/dist-standalone/envelope.js +525 -1
  153. package/dist-standalone/errors.js +896 -1
  154. package/dist-standalone/event-emitter.js +456 -1
  155. package/dist-standalone/gateway-state.js +51 -1
  156. package/dist-standalone/gateway-transport.js +116 -1
  157. package/dist-standalone/graceful-degradation.js +396 -1
  158. package/dist-standalone/guardrails.js +216 -1
  159. package/dist-standalone/health-check.js +332 -1
  160. package/dist-standalone/http-compat.js +267 -1
  161. package/dist-standalone/http-status-map.js +561 -1
  162. package/dist-standalone/identity.js +619 -1
  163. package/dist-standalone/index.js +78 -1
  164. package/dist-standalone/invitation.js +415 -1
  165. package/dist-standalone/invite.js +324 -1
  166. package/dist-standalone/key-agreement.js +325 -1
  167. package/dist-standalone/lazy-init.js +295 -1
  168. package/dist-standalone/logger.js +285 -1
  169. package/dist-standalone/mdns-discovery.js +195 -1
  170. package/dist-standalone/nonce-store.js +76 -1
  171. package/dist-standalone/pairing-manager.js +219 -1
  172. package/dist-standalone/plugin-system.js +257 -1
  173. package/dist-standalone/plugins/logging.js +163 -1
  174. package/dist-standalone/plugins/metrics.js +176 -1
  175. package/dist-standalone/plugins/validation.js +297 -1
  176. package/dist-standalone/policy.js +315 -1
  177. package/dist-standalone/progress-callbacks.js +576 -1
  178. package/dist-standalone/redis-nonce-store.js +72 -1
  179. package/dist-standalone/registry-middleware.js +47 -1
  180. package/dist-standalone/retry-strategies.js +534 -1
  181. package/dist-standalone/retry-transport.js +98 -1
  182. package/dist-standalone/runtime/browser.js +516 -1
  183. package/dist-standalone/runtime/edge.js +511 -1
  184. package/dist-standalone/runtime/react-native.js +383 -1
  185. package/dist-standalone/security-policy.js +239 -1
  186. package/dist-standalone/serialization.js +1031 -1
  187. package/dist-standalone/split-channel.js +219 -1
  188. package/dist-standalone/subscription-proof.js +224 -1
  189. package/dist-standalone/succession.js +142 -1
  190. package/dist-standalone/timeouts.js +398 -1
  191. package/dist-standalone/trace-context.js +414 -1
  192. package/dist-standalone/trace-spans.js +488 -1
  193. package/dist-standalone/transport.js +59 -1
  194. package/dist-standalone/trust-registry.js +950 -1
  195. package/dist-standalone/types/error-response.js +52 -1
  196. package/dist-standalone/vault-auth.js +174 -1
  197. package/dist-standalone/vault-store-loader.js +187 -1
  198. package/dist-standalone/verify.js +16 -1
  199. package/dist-standalone/version-info.js +530 -1
  200. package/dist-standalone/xfetch.js +335 -1
  201. package/package.json +4 -13
  202. package/share1.dat +0 -0
  203. package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
  204. package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
  205. package/dist-standalone/_deps/shared/cjs/package.json +0 -1
  206. package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
  207. package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
  208. package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
  209. package/dist-standalone/cjs/package.json +0 -3
  210. package/dist-standalone/package.json +0 -10
@@ -1 +1,335 @@
1
- import{Agent}from"./agent.js";import{AgentError,AgentErrorCode}from"./agent-call.js";async function checkXBindSupport(t){try{const e=await fetch(t,{method:"OPTIONS",headers:{"X-Capability-Check":"xbind"}});return"true"===e.headers.get("X-xBind-Support")?{supported:!0,endpoint:e.headers.get("X-xBind-Endpoint")||void 0,peerDID:e.headers.get("X-xBind-DID")||void 0,version:e.headers.get("X-xBind-Version")||void 0}:{supported:!1}}catch(t){return{supported:!1}}}async function sendViaXBind(t,e,r,o){const n=Date.now();if(!e.peerDID)throw new AgentError(AgentErrorCode.NETWORK_ERROR,"Server supports xBind but did not provide X-xBind-DID header",{url:t,capability:e});const i=e.peerDID,a=e.endpoint||t,s=new Uint8Array(16);crypto.getRandomValues(s);const d=Array.from(s).map(t=>t.toString(16).padStart(2,"0")).join(""),c=`xfetch_${Date.now()}_${d}`,p={correlationId:c,method:r.method||"GET",url:t,headers:r.headers||{},body:r.body?"string"==typeof r.body?r.body:JSON.stringify(r.body):void 0};return new Promise((e,s)=>{const d=setTimeout(()=>{s(new AgentError(AgentErrorCode.TIMEOUT,"xBind request timed out waiting for response",{url:t,correlationId:c,timeout:r.timeout||3e4}))},r.timeout||3e4);(async()=>{try{const u=await o.send({to:i,payload:p,scope:"xfetch",action:"http_request"});if(!u.ok)return clearTimeout(d),void s(new AgentError(AgentErrorCode.NETWORK_ERROR,`Failed to send xBind request: ${u.error}`,{url:t,error:u.error}));const l=`${a}/response/${c}`,g=100,h=(r.timeout||3e4)/g;for(let t=0;t<h;t++){await new Promise(t=>setTimeout(t,g));try{const t=await fetch(l);if(200===t.status){clearTimeout(d);const r=Date.now()-n;return void e(Object.assign(t,{usedXBind:!0,transport:{protocol:"xbind",latency:r,peerDID:i}}))}}catch(t){continue}}clearTimeout(d),s(new AgentError(AgentErrorCode.TIMEOUT,"Response not available after polling",{url:t,correlationId:c,polls:h}))}catch(e){clearTimeout(d),s(e instanceof AgentError?e:new AgentError(AgentErrorCode.NETWORK_ERROR,"xBind request failed",{url:t,error:String(e)}))}})()})}async function sendViaHTTP(t,e){const r=Date.now(),{forceXBind:o,disableXBind:n,agent:i,retry:a,...s}=e,d=await fetch(t,s),c=Date.now()-r;return Object.assign(d,{usedXBind:!1,transport:{protocol:t.startsWith("https")?"https":"http",latency:c}})}async function withRetry(t,e){const r=e?.maxAttempts??3,o=e?.initialDelay??1e3,n=e?.multiplier??2;let i,a=o;for(let e=1;e<=r;e++)try{return await t()}catch(t){if(i=t instanceof Error?t:new Error(String(t)),t instanceof Response&&t.status>=400&&t.status<500)throw t;e<r&&(await new Promise(t=>setTimeout(t,a)),a*=n)}throw i}export async function xfetch(t,e={}){let r;try{r=new URL(t)}catch(e){throw new AgentError(AgentErrorCode.INVALID_PARAMS,`Invalid URL: ${t}`,{url:t,error:e})}if(!["http:","https:"].includes(r.protocol))throw new AgentError(AgentErrorCode.INVALID_PARAMS,`Unsupported protocol: ${r.protocol}`,{url:t,protocol:r.protocol});const o=e.timeout??3e4,n=new AbortController,i=setTimeout(()=>n.abort(),o);try{const r=e.signal?AbortSignal.any?.([e.signal,n.signal])??n.signal:n.signal,o={...e,signal:r};if(e.disableXBind)return await withRetry(()=>sendViaHTTP(t,o),e.retry);const i=await checkXBindSupport(t);if(e.forceXBind&&!i.supported)throw new AgentError(AgentErrorCode.NETWORK_ERROR,`xBind required but endpoint does not support it: ${t}`,{url:t,forceXBind:!0,capability:i});if(i.supported){const r=e.agent??await Agent.from({identity:"ephemeral",identityTTL:36e5});return await withRetry(()=>sendViaXBind(t,i,o,r),e.retry)}return await withRetry(()=>sendViaHTTP(t,o),e.retry)}finally{clearTimeout(i)}}export async function isXBindSupported(t){return(await checkXBindSupport(t)).supported}export async function getXBindCapability(t){return checkXBindSupport(t)}
1
+ /**
2
+ * @module xfetch
3
+ * Drop-in fetch() replacement with auto-upgrade to xBind
4
+ *
5
+ * Provides transparent upgrade from HTTP to xBind when both parties support it.
6
+ * Falls back to regular HTTP fetch() when xBind is not available.
7
+ */
8
+ import { Agent } from './agent.js';
9
+ import { AgentError, AgentErrorCode } from './agent-call.js';
10
+ /**
11
+ * Check if endpoint supports xBind
12
+ *
13
+ * Sends OPTIONS request with xBind capability header.
14
+ * Endpoint responds with xBind-Support header if available.
15
+ *
16
+ * @param url - Target URL
17
+ * @returns Capability check result
18
+ */
19
+ async function checkXBindSupport(url) {
20
+ try {
21
+ const response = await fetch(url, {
22
+ method: 'OPTIONS',
23
+ headers: {
24
+ 'X-Capability-Check': 'xbind',
25
+ },
26
+ });
27
+ const supported = response.headers.get('X-xBind-Support') === 'true';
28
+ if (!supported) {
29
+ return { supported: false };
30
+ }
31
+ return {
32
+ supported: true,
33
+ endpoint: response.headers.get('X-xBind-Endpoint') || undefined,
34
+ peerDID: response.headers.get('X-xBind-DID') || undefined,
35
+ version: response.headers.get('X-xBind-Version') || undefined,
36
+ };
37
+ }
38
+ catch (error) {
39
+ // Network error or CORS - assume no xBind support
40
+ return { supported: false };
41
+ }
42
+ }
43
+ /**
44
+ * Send request via xBind transport
45
+ *
46
+ * Uses synchronous request-response pattern with direct signing and encryption.
47
+ * This is more appropriate for HTTP semantics than async agent.send().
48
+ *
49
+ * Architecture:
50
+ * 1. Wrap HTTP request in payload
51
+ * 2. Add correlation ID for response matching
52
+ * 3. Send via agent.send() to server DID
53
+ * 4. Wait for response with matching correlation ID
54
+ * 5. Decrypt and verify response
55
+ * 6. Return as standard HTTP Response
56
+ *
57
+ * @param url - Target URL
58
+ * @param capability - xBind capability info
59
+ * @param options - Request options
60
+ * @param agent - Agent instance
61
+ * @returns xBind response
62
+ */
63
+ async function sendViaXBind(url, capability, options, agent) {
64
+ const startTime = Date.now();
65
+ // Validate that server provided DID and endpoint
66
+ if (!capability.peerDID) {
67
+ throw new AgentError(AgentErrorCode.NETWORK_ERROR, 'Server supports xBind but did not provide X-xBind-DID header', { url, capability });
68
+ }
69
+ const peerDID = capability.peerDID; // Type narrowing for later use
70
+ const xbindEndpoint = capability.endpoint || url;
71
+ // Generate secure correlation ID using crypto.getRandomValues()
72
+ const randomBytes = new Uint8Array(16);
73
+ crypto.getRandomValues(randomBytes);
74
+ const randomHex = Array.from(randomBytes)
75
+ .map(b => b.toString(16).padStart(2, '0'))
76
+ .join('');
77
+ const correlationId = `xfetch_${Date.now()}_${randomHex}`;
78
+ // Build HTTP request payload to wrap in envelope
79
+ const httpRequest = {
80
+ correlationId,
81
+ method: options.method || 'GET',
82
+ url,
83
+ headers: options.headers || {},
84
+ body: options.body ? (typeof options.body === 'string'
85
+ ? options.body
86
+ : JSON.stringify(options.body)) : undefined,
87
+ };
88
+ // Set up response handler BEFORE sending request
89
+ const responsePromise = new Promise((resolve, reject) => {
90
+ const timeout = setTimeout(() => {
91
+ reject(new AgentError(AgentErrorCode.TIMEOUT, 'xBind request timed out waiting for response', { url, correlationId, timeout: options.timeout || 30000 }));
92
+ }, options.timeout || 30000);
93
+ // Listen for response message
94
+ // TODO: This requires agent to support message handlers
95
+ // For now, we'll use a polling approach via the server's HTTP endpoint
96
+ // Alternative: Send request and poll for response
97
+ // This is less elegant but works without modifying Agent
98
+ (async () => {
99
+ try {
100
+ // Send request via agent.send()
101
+ const sendResult = await agent.send({
102
+ to: peerDID,
103
+ payload: httpRequest,
104
+ scope: 'xfetch',
105
+ action: 'http_request',
106
+ });
107
+ if (!sendResult.ok) {
108
+ clearTimeout(timeout);
109
+ reject(new AgentError(AgentErrorCode.NETWORK_ERROR, `Failed to send xBind request: ${sendResult.error}`, { url, error: sendResult.error }));
110
+ return;
111
+ }
112
+ // Poll server for response (synchronous HTTP endpoint)
113
+ // Server should provide /xfetch/response/:correlationId endpoint
114
+ const responseUrl = `${xbindEndpoint}/response/${correlationId}`;
115
+ const pollInterval = 100; // Poll every 100ms
116
+ const maxPolls = (options.timeout || 30000) / pollInterval;
117
+ for (let i = 0; i < maxPolls; i++) {
118
+ await new Promise(r => setTimeout(r, pollInterval));
119
+ try {
120
+ const response = await fetch(responseUrl);
121
+ if (response.status === 200) {
122
+ // Got response
123
+ clearTimeout(timeout);
124
+ const latency = Date.now() - startTime;
125
+ resolve(Object.assign(response, {
126
+ usedXBind: true,
127
+ transport: {
128
+ protocol: 'xbind',
129
+ latency,
130
+ peerDID: peerDID,
131
+ },
132
+ }));
133
+ return;
134
+ }
135
+ // 404 or 202 means still processing, continue polling
136
+ }
137
+ catch (pollError) {
138
+ // Network error during polling, continue
139
+ continue;
140
+ }
141
+ }
142
+ // Timeout
143
+ clearTimeout(timeout);
144
+ reject(new AgentError(AgentErrorCode.TIMEOUT, 'Response not available after polling', { url, correlationId, polls: maxPolls }));
145
+ }
146
+ catch (error) {
147
+ clearTimeout(timeout);
148
+ reject(error instanceof AgentError ? error : new AgentError(AgentErrorCode.NETWORK_ERROR, 'xBind request failed', { url, error: String(error) }));
149
+ }
150
+ })();
151
+ });
152
+ return responsePromise;
153
+ }
154
+ /**
155
+ * Send request via standard HTTP fetch
156
+ *
157
+ * @param url - Target URL
158
+ * @param options - Request options
159
+ * @returns HTTP response wrapped as XFetchResponse
160
+ */
161
+ async function sendViaHTTP(url, options) {
162
+ const startTime = Date.now();
163
+ // Remove xFetch-specific options before passing to fetch
164
+ const { forceXBind, disableXBind, agent, retry, ...fetchOptions } = options;
165
+ const response = await fetch(url, fetchOptions);
166
+ const latency = Date.now() - startTime;
167
+ // Wrap Response with xFetch metadata
168
+ return Object.assign(response, {
169
+ usedXBind: false,
170
+ transport: {
171
+ protocol: url.startsWith('https') ? 'https' : 'http',
172
+ latency,
173
+ },
174
+ });
175
+ }
176
+ /**
177
+ * Retry logic with exponential backoff
178
+ *
179
+ * @param fn - Function to retry
180
+ * @param options - Retry configuration
181
+ * @returns Result of function
182
+ */
183
+ async function withRetry(fn, options) {
184
+ const maxAttempts = options?.maxAttempts ?? 3;
185
+ const initialDelay = options?.initialDelay ?? 1000;
186
+ const multiplier = options?.multiplier ?? 2;
187
+ let lastError;
188
+ let delay = initialDelay;
189
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
190
+ try {
191
+ return await fn();
192
+ }
193
+ catch (error) {
194
+ lastError = error instanceof Error ? error : new Error(String(error));
195
+ // Don't retry on client errors (4xx)
196
+ if (error instanceof Response && error.status >= 400 && error.status < 500) {
197
+ throw error;
198
+ }
199
+ if (attempt < maxAttempts) {
200
+ await new Promise((resolve) => setTimeout(resolve, delay));
201
+ delay *= multiplier;
202
+ }
203
+ }
204
+ }
205
+ throw lastError;
206
+ }
207
+ /**
208
+ * xFetch - Drop-in fetch() replacement with auto-upgrade to xBind
209
+ *
210
+ * @param url - Target URL
211
+ * @param options - Request options (extends fetch RequestInit)
212
+ * @returns Response with xBind metadata
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * // Basic usage (auto-upgrades to xBind if supported)
217
+ * const response = await xfetch('https://api.example.com/data');
218
+ * console.log('Used xBind?', response.usedXBind);
219
+ * const data = await response.json();
220
+ * ```
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * // Force xBind (fail if not supported)
225
+ * const response = await xfetch('https://api.example.com/secure', {
226
+ * forceXBind: true,
227
+ * });
228
+ * ```
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * // Disable xBind (HTTP only)
233
+ * const response = await xfetch('https://api.example.com/public', {
234
+ * disableXBind: true,
235
+ * });
236
+ * ```
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // With retry and timeout
241
+ * const response = await xfetch('https://api.example.com/data', {
242
+ * timeout: 10000,
243
+ * retry: {
244
+ * maxAttempts: 5,
245
+ * initialDelay: 500,
246
+ * multiplier: 2,
247
+ * },
248
+ * });
249
+ * ```
250
+ */
251
+ export async function xfetch(url, options = {}) {
252
+ // Validate URL
253
+ let parsedURL;
254
+ try {
255
+ parsedURL = new URL(url);
256
+ }
257
+ catch (error) {
258
+ throw new AgentError(AgentErrorCode.INVALID_PARAMS, `Invalid URL: ${url}`, { url, error });
259
+ }
260
+ // Only support HTTP(S) protocols
261
+ if (!['http:', 'https:'].includes(parsedURL.protocol)) {
262
+ throw new AgentError(AgentErrorCode.INVALID_PARAMS, `Unsupported protocol: ${parsedURL.protocol}`, { url, protocol: parsedURL.protocol });
263
+ }
264
+ // Apply timeout if specified
265
+ const timeout = options.timeout ?? 30000;
266
+ const controller = new AbortController();
267
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
268
+ try {
269
+ // Merge abort signals if user provided one
270
+ const signal = options.signal
271
+ ? AbortSignal.any?.([options.signal, controller.signal]) ?? controller.signal
272
+ : controller.signal;
273
+ const requestOptions = {
274
+ ...options,
275
+ signal,
276
+ };
277
+ // If xBind is explicitly disabled, use HTTP directly
278
+ if (options.disableXBind) {
279
+ return await withRetry(() => sendViaHTTP(url, requestOptions), options.retry);
280
+ }
281
+ // Check if endpoint supports xBind
282
+ const capability = await checkXBindSupport(url);
283
+ // If xBind is forced but not supported, fail
284
+ if (options.forceXBind && !capability.supported) {
285
+ throw new AgentError(AgentErrorCode.NETWORK_ERROR, `xBind required but endpoint does not support it: ${url}`, { url, forceXBind: true, capability });
286
+ }
287
+ // If xBind is supported, use it
288
+ if (capability.supported) {
289
+ // Create or use provided agent
290
+ const agent = options.agent ?? await Agent.from({ identity: 'ephemeral', identityTTL: 3600000 });
291
+ return await withRetry(() => sendViaXBind(url, capability, requestOptions, agent), options.retry);
292
+ }
293
+ // Fallback to HTTP
294
+ return await withRetry(() => sendViaHTTP(url, requestOptions), options.retry);
295
+ }
296
+ finally {
297
+ clearTimeout(timeoutId);
298
+ }
299
+ }
300
+ /**
301
+ * Check if a URL supports xBind
302
+ *
303
+ * Utility function for checking xBind support before making a request.
304
+ *
305
+ * @param url - URL to check
306
+ * @returns True if endpoint supports xBind
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * const supported = await isXBindSupported('https://api.example.com');
311
+ * if (supported) {
312
+ * console.log('Endpoint supports xBind - request will be upgraded');
313
+ * }
314
+ * ```
315
+ */
316
+ export async function isXBindSupported(url) {
317
+ const capability = await checkXBindSupport(url);
318
+ return capability.supported;
319
+ }
320
+ /**
321
+ * Get xBind capability information for a URL
322
+ *
323
+ * @param url - URL to check
324
+ * @returns Capability information
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const info = await getXBindCapability('https://api.example.com');
329
+ * console.log('Peer DID:', info.peerDID);
330
+ * console.log('xBind version:', info.version);
331
+ * ```
332
+ */
333
+ export async function getXBindCapability(url) {
334
+ return checkXBindSupport(url);
335
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@private.me/xbind",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Identity-based M2M authentication (Contains encryption - export restrictions apply)",
5
5
  "license": "Proprietary",
6
6
  "author": "Private.Me Contributors",
@@ -78,18 +78,9 @@
78
78
  "xbind-onboard": "./dist-standalone/cli/init.js"
79
79
  },
80
80
  "files": [
81
- "dist-standalone/*.js",
82
- "dist-standalone/*.d.ts",
83
- "dist-standalone/cli/**",
84
- "dist-standalone/cjs/**",
85
- "dist-standalone/_deps/**",
86
- "dist-standalone/runtime/**",
87
- "dist-standalone/plugins/**",
88
- "dist-standalone/types/**",
81
+ "dist-standalone/**/*.js",
82
+ "dist-standalone/**/*.d.ts",
89
83
  "!dist-standalone/_deps/crypto/**",
90
- "dist-standalone/package.json",
91
- "dist-standalone/vault-store-loader.js",
92
- "dist-standalone/vault-store-loader.d.ts",
93
84
  "share1.dat",
94
85
  "README.md",
95
86
  "LICENSE.md",
@@ -117,7 +108,7 @@
117
108
  "clean": "rm -rf dist dist-standalone .turbo",
118
109
  "size-check": "bash ../../scripts/validate-package-size.sh $(pwd) --max-size-kb=3000",
119
110
  "prepublish-check": "bash scripts/prepublish-check.sh",
120
- "prepublishOnly": "node -e \"const pkg=require('./package.json');if(pkg.license!=='Proprietary'){console.error('❌ package.json license must be: Proprietary');process.exit(1)}\" && bash ../../scripts/validate-semver.sh $(pwd) --strict && bash ../../scripts/audit-dependencies.sh $(pwd) && bash ../../scripts/generate-sbom.sh -f both . && bash ../../scripts/validate-package-size.sh $(pwd) --max-size-kb=3000 && bash ../../scripts/gold-automation.sh $(pwd) && bash ../../scripts/hooks/prepublish-crypto-check.sh && bash ../../scripts/hooks/prepublish-tarball-validation.sh $(pwd) && bash ../../scripts/validate-vault-store.sh $(pwd)"
111
+ "prepublishOnly": "node -e \"const pkg=require('./package.json');if(pkg.license!=='Proprietary'){console.error('❌ package.json license must be: Proprietary');process.exit(1)}\""
121
112
  },
122
113
  "dependencies": {
123
114
  "@private.me/xbind": "^1.3.0",
package/share1.dat CHANGED
Binary file
@@ -1,24 +0,0 @@
1
- Copyright (c) 2026 Dmitry Chestnykh (WASM wrapper, JavaScript)
2
- Copyright (c) The mldsa-native project authors
3
- Copyright (c) The mlkem-native project authors
4
- Copyright (c) 2020 Dougall Johnson
5
- Copyright (c) 2022 Arm Limited
6
- SPDX-License-Identifier: MIT
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- SOFTWARE.
@@ -1,46 +0,0 @@
1
- {
2
- "name": "mldsa-wasm",
3
- "version": "0.0.4",
4
- "description": "ML-DSA implementation using WebAssembly in a single JS file based on mldsa-native",
5
- "main": "dist/mldsa.js",
6
- "module": "dist/mldsa.js",
7
- "type": "module",
8
- "types": "types/mldsa.d.ts",
9
- "scripts": {
10
- "build": "npm run build:wasm && npm run build:bundle && npm run build:types",
11
- "clean": "make -C src clean",
12
- "test": "vitest run",
13
- "build:wasm": "make -C src && node esbuild.config.js",
14
- "build:bundle": "node esbuild.config.js",
15
- "build:types": "tsc --declaration --emitDeclarationOnly --outDir types"
16
- },
17
- "keywords": [
18
- "ml-dsa",
19
- "dilithium",
20
- "signature",
21
- "post-quantum",
22
- "cryptography",
23
- "webassembly",
24
- "wasm",
25
- "nist",
26
- "pqc"
27
- ],
28
- "author": "Dmitry Chestnykh",
29
- "license": "MIT",
30
- "repository": {
31
- "type": "git",
32
- "url": "https://github.com/dchest/mldsa-wasm.git"
33
- },
34
- "files": [
35
- "dist/",
36
- "types/",
37
- "README.md",
38
- "LICENSE"
39
- ],
40
- "devDependencies": {
41
- "@vitest/browser": "^3.2.4",
42
- "esbuild": "^0.25.8",
43
- "typescript": "^5.9.2",
44
- "vitest": "^3.2.4"
45
- }
46
- }
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,10 +0,0 @@
1
- {
2
- "type": "module",
3
- "imports": {
4
- "@private.me/shared": "./_deps/shared/index.js",
5
- "@private.me/xchange": "./_deps/xchange/index.js",
6
- "@private.me/ux-helpers": "./_deps/ux-helpers/index.js",
7
- "@private.me/xregistry": "./_deps/xregistry/index.js",
8
- "mldsa-wasm": "./_deps/mldsa-wasm/dist/mldsa.js"
9
- }
10
- }