@private.me/xbind 3.0.2 → 3.0.3

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 (221) hide show
  1. package/README.md +2366 -204
  2. package/README.md.backup +2121 -0
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -729
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -463
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -315
  7. package/dist-standalone/_deps/shared/errors.js +1 -244
  8. package/dist-standalone/_deps/shared/index.js +1 -72
  9. package/dist-standalone/_deps/shared/types.js +1 -86
  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.d.ts +2 -2
  48. package/dist-standalone/agent-call.js +1 -659
  49. package/dist-standalone/agent-sdk.js +1 -328
  50. package/dist-standalone/agent.d.ts +2 -0
  51. package/dist-standalone/agent.js +1 -1800
  52. package/dist-standalone/approval.js +1 -193
  53. package/dist-standalone/async-iterators.d.ts +3 -3
  54. package/dist-standalone/async-iterators.js +1 -382
  55. package/dist-standalone/auth.js +1 -219
  56. package/dist-standalone/auto-accept.js +1 -229
  57. package/dist-standalone/backup-config.js +1 -201
  58. package/dist-standalone/backup.js +1 -326
  59. package/dist-standalone/batch-operations.js +1 -388
  60. package/dist-standalone/cancellation.js +1 -477
  61. package/dist-standalone/checkpoint.js +1 -186
  62. package/dist-standalone/circuit-breaker.js +1 -468
  63. package/dist-standalone/cjs/agent-call.js +1 -701
  64. package/dist-standalone/cjs/agent-sdk.js +1 -332
  65. package/dist-standalone/cjs/agent.js +1 -1837
  66. package/dist-standalone/cjs/approval.js +1 -199
  67. package/dist-standalone/cjs/async-iterators.js +1 -392
  68. package/dist-standalone/cjs/auth.js +1 -225
  69. package/dist-standalone/cjs/auto-accept.js +1 -233
  70. package/dist-standalone/cjs/backup-config.js +1 -207
  71. package/dist-standalone/cjs/backup.js +1 -330
  72. package/dist-standalone/cjs/batch-operations.js +1 -397
  73. package/dist-standalone/cjs/cancellation.js +1 -490
  74. package/dist-standalone/cjs/checkpoint.js +1 -193
  75. package/dist-standalone/cjs/circuit-breaker.js +1 -476
  76. package/dist-standalone/cjs/cli/init.js +1 -492
  77. package/dist-standalone/cjs/config-validation.js +1 -522
  78. package/dist-standalone/cjs/connect.js +1 -312
  79. package/dist-standalone/cjs/connection-pool.js +1 -506
  80. package/dist-standalone/cjs/correlation-id.js +1 -339
  81. package/dist-standalone/cjs/crypto-utils.js +1 -176
  82. package/dist-standalone/cjs/debug-mode.js +1 -534
  83. package/dist-standalone/cjs/did-document.js +1 -101
  84. package/dist-standalone/cjs/did-privateme.js +1 -130
  85. package/dist-standalone/cjs/did-web.js +1 -201
  86. package/dist-standalone/cjs/discovery.js +1 -462
  87. package/dist-standalone/cjs/dual-mode.js +1 -251
  88. package/dist-standalone/cjs/email-templates.js +1 -313
  89. package/dist-standalone/cjs/email-transport.js +1 -239
  90. package/dist-standalone/cjs/envelope.js +1 -538
  91. package/dist-standalone/cjs/errors.js +1 -913
  92. package/dist-standalone/cjs/event-emitter.js +1 -461
  93. package/dist-standalone/cjs/gateway-state.js +1 -55
  94. package/dist-standalone/cjs/gateway-transport.js +1 -120
  95. package/dist-standalone/cjs/graceful-degradation.js +1 -403
  96. package/dist-standalone/cjs/guardrails.js +1 -223
  97. package/dist-standalone/cjs/health-check.js +1 -336
  98. package/dist-standalone/cjs/http-compat.js +1 -272
  99. package/dist-standalone/cjs/http-status-map.js +1 -571
  100. package/dist-standalone/cjs/identity.js +1 -645
  101. package/dist-standalone/cjs/index.js +1 -406
  102. package/dist-standalone/cjs/invitation.js +1 -421
  103. package/dist-standalone/cjs/invite.js +1 -328
  104. package/dist-standalone/cjs/key-agreement.js +1 -335
  105. package/dist-standalone/cjs/lazy-init.js +1 -300
  106. package/dist-standalone/cjs/logger.js +1 -291
  107. package/dist-standalone/cjs/loopback-transport.js +1 -0
  108. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  109. package/dist-standalone/cjs/nonce-store.js +1 -80
  110. package/dist-standalone/cjs/pairing-manager.js +1 -223
  111. package/dist-standalone/cjs/plugin-system.js +1 -264
  112. package/dist-standalone/cjs/plugins/logging.js +1 -168
  113. package/dist-standalone/cjs/plugins/metrics.js +1 -181
  114. package/dist-standalone/cjs/plugins/validation.js +1 -302
  115. package/dist-standalone/cjs/policy.js +1 -320
  116. package/dist-standalone/cjs/progress-callbacks.js +1 -583
  117. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  118. package/dist-standalone/cjs/registry-middleware.js +1 -50
  119. package/dist-standalone/cjs/retry-strategies.js +1 -544
  120. package/dist-standalone/cjs/retry-transport.js +1 -102
  121. package/dist-standalone/cjs/runtime/browser.js +1 -533
  122. package/dist-standalone/cjs/runtime/edge.js +1 -526
  123. package/dist-standalone/cjs/runtime/react-native.js +1 -394
  124. package/dist-standalone/cjs/security-policy.js +1 -245
  125. package/dist-standalone/cjs/serialization.js +1 -1040
  126. package/dist-standalone/cjs/split-channel.js +1 -225
  127. package/dist-standalone/cjs/subscription-proof.js +1 -230
  128. package/dist-standalone/cjs/succession.js +1 -148
  129. package/dist-standalone/cjs/timeouts.js +1 -412
  130. package/dist-standalone/cjs/trace-context.js +1 -424
  131. package/dist-standalone/cjs/trace-spans.js +1 -495
  132. package/dist-standalone/cjs/transport.js +1 -63
  133. package/dist-standalone/cjs/trust-registry.js +1 -991
  134. package/dist-standalone/cjs/types/error-response.js +1 -56
  135. package/dist-standalone/cjs/vault-auth.js +1 -178
  136. package/dist-standalone/cjs/vault-store-loader.js +1 -194
  137. package/dist-standalone/cjs/verify.js +1 -25
  138. package/dist-standalone/cjs/version-info.js +1 -543
  139. package/dist-standalone/cjs/xfetch.js +1 -340
  140. package/dist-standalone/cli/init.js +1 -455
  141. package/dist-standalone/cli/setup.js +1 -514
  142. package/dist-standalone/cli/types.js +1 -27
  143. package/dist-standalone/cli/xbind.js +1 -148
  144. package/dist-standalone/config-validation.js +1 -513
  145. package/dist-standalone/connect.js +1 -274
  146. package/dist-standalone/connection-pool.js +1 -500
  147. package/dist-standalone/correlation-id.js +1 -326
  148. package/dist-standalone/crypto-utils.d.ts +2 -7
  149. package/dist-standalone/crypto-utils.js +1 -157
  150. package/dist-standalone/debug-mode.js +1 -510
  151. package/dist-standalone/did-document.js +1 -96
  152. package/dist-standalone/did-privateme.js +1 -121
  153. package/dist-standalone/did-web.js +1 -196
  154. package/dist-standalone/discovery.js +1 -458
  155. package/dist-standalone/dual-mode.js +1 -247
  156. package/dist-standalone/email-templates.js +1 -309
  157. package/dist-standalone/email-transport.d.ts +2 -2
  158. package/dist-standalone/email-transport.js +1 -232
  159. package/dist-standalone/envelope.js +1 -525
  160. package/dist-standalone/errors.d.ts +13 -3
  161. package/dist-standalone/errors.js +1 -896
  162. package/dist-standalone/event-emitter.js +1 -456
  163. package/dist-standalone/gateway-state.d.ts +1 -1
  164. package/dist-standalone/gateway-state.js +1 -51
  165. package/dist-standalone/gateway-transport.js +1 -116
  166. package/dist-standalone/graceful-degradation.js +1 -396
  167. package/dist-standalone/guardrails.js +1 -216
  168. package/dist-standalone/health-check.d.ts +5 -1
  169. package/dist-standalone/health-check.js +1 -332
  170. package/dist-standalone/http-compat.d.ts +1 -1
  171. package/dist-standalone/http-compat.js +1 -267
  172. package/dist-standalone/http-status-map.js +1 -561
  173. package/dist-standalone/identity.js +1 -619
  174. package/dist-standalone/index.d.ts +15 -4
  175. package/dist-standalone/index.js +1 -78
  176. package/dist-standalone/invitation.js +1 -415
  177. package/dist-standalone/invite.js +1 -324
  178. package/dist-standalone/key-agreement.js +1 -325
  179. package/dist-standalone/lazy-init.d.ts +11 -6
  180. package/dist-standalone/lazy-init.js +1 -295
  181. package/dist-standalone/logger.js +1 -285
  182. package/dist-standalone/loopback-transport.d.ts +87 -0
  183. package/dist-standalone/loopback-transport.js +1 -0
  184. package/dist-standalone/mdns-discovery.js +1 -195
  185. package/dist-standalone/nonce-store.js +1 -76
  186. package/dist-standalone/pairing-manager.js +1 -219
  187. package/dist-standalone/plugin-system.js +1 -257
  188. package/dist-standalone/plugins/logging.js +1 -163
  189. package/dist-standalone/plugins/metrics.d.ts +4 -4
  190. package/dist-standalone/plugins/metrics.js +1 -176
  191. package/dist-standalone/plugins/validation.js +1 -297
  192. package/dist-standalone/policy.js +1 -315
  193. package/dist-standalone/progress-callbacks.js +1 -576
  194. package/dist-standalone/redis-nonce-store.js +1 -72
  195. package/dist-standalone/registry-middleware.js +1 -47
  196. package/dist-standalone/retry-strategies.js +1 -534
  197. package/dist-standalone/retry-transport.js +1 -98
  198. package/dist-standalone/runtime/browser.js +1 -516
  199. package/dist-standalone/runtime/edge.js +1 -511
  200. package/dist-standalone/runtime/react-native.d.ts +1 -1
  201. package/dist-standalone/runtime/react-native.js +1 -383
  202. package/dist-standalone/security-policy.js +1 -239
  203. package/dist-standalone/serialization.js +1 -1031
  204. package/dist-standalone/split-channel.js +1 -219
  205. package/dist-standalone/subscription-proof.js +1 -224
  206. package/dist-standalone/succession.js +1 -142
  207. package/dist-standalone/timeouts.js +1 -398
  208. package/dist-standalone/trace-context.js +1 -414
  209. package/dist-standalone/trace-spans.js +1 -488
  210. package/dist-standalone/transport.js +1 -59
  211. package/dist-standalone/trust-registry.d.ts +3 -3
  212. package/dist-standalone/trust-registry.js +1 -950
  213. package/dist-standalone/types/error-response.js +1 -52
  214. package/dist-standalone/vault-auth.js +1 -174
  215. package/dist-standalone/vault-store-loader.d.ts +9 -0
  216. package/dist-standalone/vault-store-loader.js +1 -187
  217. package/dist-standalone/verify.js +1 -16
  218. package/dist-standalone/version-info.js +1 -530
  219. package/dist-standalone/xfetch.js +1 -335
  220. package/package.json +1 -1
  221. package/share1.dat +0 -0
@@ -1,583 +1 @@
1
- "use strict";
2
- /**
3
- * @module progress-callbacks
4
- * Enhanced progress tracking for xBind operations
5
- *
6
- * Provides domain-specific progress callbacks for long-running operations:
7
- * - Upload/download progress with bandwidth estimation
8
- * - Share distribution progress (XorIDA multi-channel delivery)
9
- * - Encryption/decryption progress
10
- * - Multi-stage operation tracking
11
- *
12
- * @example
13
- * ```typescript
14
- * const tracker = new OperationProgressTracker(onProgress);
15
- * tracker.startStage('encryption', 40); // 40% of total operation
16
- * // ... encryption work
17
- * tracker.updateStageProgress(50); // 50% of encryption stage
18
- * tracker.completeStage();
19
- * ```
20
- */
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.EncryptionProgressTracker = exports.ShareDistributionTracker = exports.TransferProgressTracker = exports.OperationProgressTracker = void 0;
23
- const ux_helpers_1 = require("../_deps/ux-helpers/index.js");
24
- /**
25
- * Multi-stage operation progress tracker.
26
- *
27
- * Manages progress across multiple stages with weighted contributions
28
- * to overall progress. Useful for complex operations like:
29
- * - Message send: resolve DID (10%) → encrypt (30%) → split shares (20%) → distribute (40%)
30
- * - File transfer: prepare (5%) → encrypt (25%) → upload (70%)
31
- *
32
- * @example
33
- * ```typescript
34
- * const tracker = new OperationProgressTracker(onProgress);
35
- *
36
- * tracker.startStage('preparation', 10);
37
- * // ... prep work
38
- * tracker.completeStage();
39
- *
40
- * tracker.startStage('encryption', 40);
41
- * tracker.updateStageProgress(50); // Halfway through encryption
42
- * tracker.completeStage();
43
- *
44
- * tracker.startStage('distribution', 50);
45
- * // ... distribution work
46
- * tracker.complete();
47
- * ```
48
- */
49
- class OperationProgressTracker {
50
- callback;
51
- throttleMs;
52
- lastUpdateTime = 0;
53
- currentStage = '';
54
- currentStageWeight = 0;
55
- currentStageProgress = 0;
56
- completedWeight = 0;
57
- metadata = {};
58
- /**
59
- * Create a new operation progress tracker.
60
- *
61
- * @param onProgress Progress callback (standard or enhanced)
62
- * @param options Tracking options
63
- */
64
- constructor(onProgress, options) {
65
- this.callback = onProgress;
66
- this.throttleMs = options?.throttleMs ?? 100; // Default 100ms throttle
67
- }
68
- /**
69
- * Start a new stage.
70
- *
71
- * @param name Stage identifier
72
- * @param weight Weight of this stage (percentage of total, 0-100)
73
- * @param description Human-readable description
74
- */
75
- startStage(name, weight, description) {
76
- this.currentStage = name;
77
- this.currentStageWeight = Math.max(0, Math.min(100, weight));
78
- this.currentStageProgress = 0;
79
- this.reportProgress(description ?? `Starting ${name}...`);
80
- }
81
- /**
82
- * Update progress within the current stage.
83
- *
84
- * @param stagePercent Progress percentage within current stage (0-100)
85
- * @param status Optional status message
86
- * @param metadata Optional progress metadata
87
- */
88
- updateStageProgress(stagePercent, status, metadata) {
89
- this.currentStageProgress = Math.max(0, Math.min(100, stagePercent));
90
- if (metadata) {
91
- this.metadata = { ...this.metadata, ...metadata };
92
- }
93
- const message = status ?? `${this.currentStage} (${Math.round(stagePercent)}%)`;
94
- this.reportProgress(message);
95
- }
96
- /**
97
- * Complete the current stage and advance overall progress.
98
- */
99
- completeStage() {
100
- this.currentStageProgress = 100;
101
- this.completedWeight += this.currentStageWeight;
102
- this.reportProgress(`${this.currentStage} complete`);
103
- // Reset for next stage
104
- this.currentStage = '';
105
- this.currentStageWeight = 0;
106
- this.currentStageProgress = 0;
107
- }
108
- /**
109
- * Mark the entire operation as complete.
110
- */
111
- complete() {
112
- this.completedWeight = 100;
113
- this.currentStageProgress = 100;
114
- this.reportProgress('Complete');
115
- }
116
- /**
117
- * Get current overall progress percentage.
118
- *
119
- * @returns Progress percentage (0-100)
120
- */
121
- getProgress() {
122
- const stageContribution = (this.currentStageWeight * this.currentStageProgress) / 100;
123
- return Math.min(100, this.completedWeight + stageContribution);
124
- }
125
- /**
126
- * Update metadata without changing progress.
127
- *
128
- * @param metadata Metadata to merge
129
- */
130
- updateMetadata(metadata) {
131
- this.metadata = { ...this.metadata, ...metadata };
132
- }
133
- /**
134
- * Report progress to callback (with throttling).
135
- *
136
- * @param status Status message
137
- */
138
- reportProgress(status) {
139
- if (!this.callback)
140
- return;
141
- const now = Date.now();
142
- if (now - this.lastUpdateTime < this.throttleMs) {
143
- // Throttle updates unless complete
144
- const progress = this.getProgress();
145
- if (progress < 100)
146
- return;
147
- }
148
- this.lastUpdateTime = now;
149
- const progress = this.getProgress();
150
- // Check if callback expects enhanced events
151
- if (this.isEnhancedCallback(this.callback)) {
152
- const event = {
153
- stage: this.currentStage,
154
- progress,
155
- stageProgress: this.currentStageProgress,
156
- status,
157
- metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
158
- };
159
- this.callback(event);
160
- }
161
- else {
162
- // Standard callback
163
- this.callback(status, progress);
164
- }
165
- }
166
- /**
167
- * Check if callback expects enhanced events.
168
- *
169
- * @param callback Callback to check
170
- * @returns True if enhanced callback
171
- */
172
- isEnhancedCallback(callback) {
173
- // Enhanced callbacks accept 1 parameter (event object)
174
- // Standard callbacks accept 2 parameters (status, percent)
175
- return callback.length === 1;
176
- }
177
- }
178
- exports.OperationProgressTracker = OperationProgressTracker;
179
- /**
180
- * Transfer progress tracker with bandwidth estimation.
181
- *
182
- * Tracks upload/download progress with automatic bandwidth calculation
183
- * and estimated time remaining.
184
- *
185
- * @example
186
- * ```typescript
187
- * const tracker = new TransferProgressTracker(totalBytes, onProgress);
188
- *
189
- * for (const chunk of chunks) {
190
- * await uploadChunk(chunk);
191
- * tracker.addTransferred(chunk.length);
192
- * }
193
- *
194
- * tracker.complete();
195
- * ```
196
- */
197
- class TransferProgressTracker {
198
- totalBytes;
199
- callback;
200
- reporter;
201
- throttleMs;
202
- bytesTransferred = 0;
203
- startTime = Date.now();
204
- lastUpdateTime = 0;
205
- samples = [];
206
- maxSamples = 10;
207
- /**
208
- * Create a new transfer progress tracker.
209
- *
210
- * @param totalBytes Total bytes to transfer
211
- * @param onProgress Progress callback
212
- * @param throttleMs Minimum interval between updates (default: 100ms)
213
- */
214
- constructor(totalBytes, onProgress, throttleMs = 100) {
215
- this.totalBytes = totalBytes;
216
- this.callback = onProgress;
217
- this.throttleMs = throttleMs;
218
- // Create standard progress reporter for fallback
219
- this.reporter = new ux_helpers_1.ProgressReporter(typeof onProgress === 'function' && onProgress.length === 2
220
- ? onProgress
221
- : undefined);
222
- }
223
- /**
224
- * Add transferred bytes and update progress.
225
- *
226
- * @param bytes Number of bytes transferred
227
- */
228
- addTransferred(bytes) {
229
- this.bytesTransferred += bytes;
230
- const now = Date.now();
231
- // Add sample for bandwidth estimation
232
- this.samples.push({ time: now, bytes: this.bytesTransferred });
233
- if (this.samples.length > this.maxSamples) {
234
- this.samples.shift();
235
- }
236
- // Throttle updates
237
- if (now - this.lastUpdateTime < this.throttleMs) {
238
- return;
239
- }
240
- this.lastUpdateTime = now;
241
- this.reportProgress();
242
- }
243
- /**
244
- * Mark transfer as complete.
245
- */
246
- complete() {
247
- this.bytesTransferred = this.totalBytes;
248
- this.reportProgress();
249
- }
250
- /**
251
- * Get current progress percentage.
252
- *
253
- * @returns Progress percentage (0-100)
254
- */
255
- getProgress() {
256
- if (this.totalBytes === 0)
257
- return 100;
258
- return Math.min(100, (this.bytesTransferred / this.totalBytes) * 100);
259
- }
260
- /**
261
- * Calculate current transfer rate.
262
- *
263
- * @returns Bytes per second
264
- */
265
- calculateBytesPerSecond() {
266
- if (this.samples.length < 2) {
267
- const elapsed = (Date.now() - this.startTime) / 1000;
268
- return elapsed > 0 ? this.bytesTransferred / elapsed : 0;
269
- }
270
- const oldest = this.samples[0];
271
- const newest = this.samples[this.samples.length - 1];
272
- if (!oldest || !newest)
273
- return 0;
274
- const timeDiff = (newest.time - oldest.time) / 1000; // seconds
275
- const bytesDiff = newest.bytes - oldest.bytes;
276
- return timeDiff > 0 ? bytesDiff / timeDiff : 0;
277
- }
278
- /**
279
- * Estimate time remaining.
280
- *
281
- * @returns Estimated milliseconds remaining
282
- */
283
- estimateTimeRemaining() {
284
- const bytesPerSecond = this.calculateBytesPerSecond();
285
- if (bytesPerSecond === 0)
286
- return 0;
287
- const bytesRemaining = this.totalBytes - this.bytesTransferred;
288
- return (bytesRemaining / bytesPerSecond) * 1000; // milliseconds
289
- }
290
- /**
291
- * Report progress to callback.
292
- */
293
- reportProgress() {
294
- if (!this.callback)
295
- return;
296
- const progress = this.getProgress();
297
- const bytesPerSecond = this.calculateBytesPerSecond();
298
- const estimatedTimeRemaining = this.estimateTimeRemaining();
299
- const status = this.formatStatus(progress, bytesPerSecond, estimatedTimeRemaining);
300
- if (this.isEnhancedCallback(this.callback)) {
301
- const event = {
302
- stage: 'transfer',
303
- progress,
304
- stageProgress: progress,
305
- status,
306
- metadata: {
307
- bytesTransferred: this.bytesTransferred,
308
- totalBytes: this.totalBytes,
309
- bytesPerSecond,
310
- estimatedTimeRemaining,
311
- },
312
- };
313
- this.callback(event);
314
- }
315
- else {
316
- this.reporter.report(status, progress);
317
- }
318
- }
319
- /**
320
- * Format status message with transfer details.
321
- *
322
- * @param progress Progress percentage
323
- * @param bytesPerSecond Transfer rate
324
- * @param estimatedTimeRemaining Time remaining in ms
325
- * @returns Formatted status string
326
- */
327
- formatStatus(progress, bytesPerSecond, estimatedTimeRemaining) {
328
- const transferred = this.formatBytes(this.bytesTransferred);
329
- const total = this.formatBytes(this.totalBytes);
330
- const rate = this.formatBytes(bytesPerSecond);
331
- const remaining = this.formatTime(estimatedTimeRemaining);
332
- return `Transferring ${transferred} / ${total} (${Math.round(progress)}%) - ${rate}/s - ${remaining} remaining`;
333
- }
334
- /**
335
- * Format bytes for display.
336
- *
337
- * @param bytes Number of bytes
338
- * @returns Formatted string (e.g., "1.5 MB")
339
- */
340
- formatBytes(bytes) {
341
- const units = ['B', 'KB', 'MB', 'GB', 'TB'];
342
- let value = bytes;
343
- let unitIndex = 0;
344
- while (value >= 1024 && unitIndex < units.length - 1) {
345
- value /= 1024;
346
- unitIndex++;
347
- }
348
- return `${value.toFixed(1)} ${units[unitIndex]}`;
349
- }
350
- /**
351
- * Format time for display.
352
- *
353
- * @param ms Milliseconds
354
- * @returns Formatted string (e.g., "2m 30s")
355
- */
356
- formatTime(ms) {
357
- const seconds = Math.floor(ms / 1000);
358
- if (seconds < 60)
359
- return `${seconds}s`;
360
- const minutes = Math.floor(seconds / 60);
361
- const remainingSeconds = seconds % 60;
362
- if (minutes < 60)
363
- return `${minutes}m ${remainingSeconds}s`;
364
- const hours = Math.floor(minutes / 60);
365
- const remainingMinutes = minutes % 60;
366
- return `${hours}h ${remainingMinutes}m`;
367
- }
368
- /**
369
- * Check if callback expects enhanced events.
370
- *
371
- * @param callback Callback to check
372
- * @returns True if enhanced callback
373
- */
374
- isEnhancedCallback(callback) {
375
- return callback.length === 1;
376
- }
377
- }
378
- exports.TransferProgressTracker = TransferProgressTracker;
379
- /**
380
- * Share distribution progress tracker for XorIDA operations.
381
- *
382
- * Tracks progress of distributing shares across multiple channels.
383
- *
384
- * @example
385
- * ```typescript
386
- * const tracker = new ShareDistributionTracker(3, onProgress);
387
- *
388
- * await distributeShare(0);
389
- * tracker.markShareDistributed(0);
390
- *
391
- * await distributeShare(1);
392
- * tracker.markShareDistributed(1);
393
- *
394
- * await distributeShare(2);
395
- * tracker.markShareDistributed(2);
396
- *
397
- * tracker.complete();
398
- * ```
399
- */
400
- class ShareDistributionTracker {
401
- totalShares;
402
- callback;
403
- reporter;
404
- distributedShares = new Set();
405
- /**
406
- * Create a new share distribution tracker.
407
- *
408
- * @param totalShares Total number of shares to distribute
409
- * @param onProgress Progress callback
410
- */
411
- constructor(totalShares, onProgress) {
412
- this.totalShares = totalShares;
413
- this.callback = onProgress;
414
- this.reporter = new ux_helpers_1.ProgressReporter(typeof onProgress === 'function' && onProgress.length === 2
415
- ? onProgress
416
- : undefined);
417
- }
418
- /**
419
- * Mark a share as successfully distributed.
420
- *
421
- * @param shareIndex Zero-based share index
422
- */
423
- markShareDistributed(shareIndex) {
424
- this.distributedShares.add(shareIndex);
425
- this.reportProgress();
426
- }
427
- /**
428
- * Mark all shares as distributed and complete.
429
- */
430
- complete() {
431
- for (let i = 0; i < this.totalShares; i++) {
432
- this.distributedShares.add(i);
433
- }
434
- this.reportProgress();
435
- }
436
- /**
437
- * Get current progress percentage.
438
- *
439
- * @returns Progress percentage (0-100)
440
- */
441
- getProgress() {
442
- if (this.totalShares === 0)
443
- return 100;
444
- return (this.distributedShares.size / this.totalShares) * 100;
445
- }
446
- /**
447
- * Report progress to callback.
448
- */
449
- reportProgress() {
450
- if (!this.callback)
451
- return;
452
- const progress = this.getProgress();
453
- const status = `Distributed ${this.distributedShares.size} / ${this.totalShares} shares`;
454
- if (this.isEnhancedCallback(this.callback)) {
455
- const event = {
456
- stage: 'distribution',
457
- progress,
458
- stageProgress: progress,
459
- status,
460
- metadata: {
461
- sharesDistributed: this.distributedShares.size,
462
- totalShares: this.totalShares,
463
- },
464
- };
465
- this.callback(event);
466
- }
467
- else {
468
- this.reporter.report(status, progress);
469
- }
470
- }
471
- /**
472
- * Check if callback expects enhanced events.
473
- *
474
- * @param callback Callback to check
475
- * @returns True if enhanced callback
476
- */
477
- isEnhancedCallback(callback) {
478
- return callback.length === 1;
479
- }
480
- }
481
- exports.ShareDistributionTracker = ShareDistributionTracker;
482
- /**
483
- * Encryption progress tracker.
484
- *
485
- * Tracks progress of encryption/decryption operations on large data.
486
- *
487
- * @example
488
- * ```typescript
489
- * const tracker = new EncryptionProgressTracker('encrypt', totalChunks, onProgress);
490
- *
491
- * for (const chunk of chunks) {
492
- * await encryptChunk(chunk);
493
- * tracker.incrementProcessed();
494
- * }
495
- *
496
- * tracker.complete();
497
- * ```
498
- */
499
- class EncryptionProgressTracker {
500
- operation;
501
- totalItems;
502
- callback;
503
- reporter;
504
- itemsProcessed = 0;
505
- /**
506
- * Create a new encryption progress tracker.
507
- *
508
- * @param operation Cryptographic operation type
509
- * @param totalItems Total number of items to process
510
- * @param onProgress Progress callback
511
- */
512
- constructor(operation, totalItems, onProgress) {
513
- this.operation = operation;
514
- this.totalItems = totalItems;
515
- this.callback = onProgress;
516
- this.reporter = new ux_helpers_1.ProgressReporter(typeof onProgress === 'function' && onProgress.length === 2
517
- ? onProgress
518
- : undefined);
519
- }
520
- /**
521
- * Increment the number of processed items.
522
- *
523
- * @param count Number of items to add (default: 1)
524
- */
525
- incrementProcessed(count = 1) {
526
- this.itemsProcessed += count;
527
- this.reportProgress();
528
- }
529
- /**
530
- * Mark operation as complete.
531
- */
532
- complete() {
533
- this.itemsProcessed = this.totalItems;
534
- this.reportProgress();
535
- }
536
- /**
537
- * Get current progress percentage.
538
- *
539
- * @returns Progress percentage (0-100)
540
- */
541
- getProgress() {
542
- if (this.totalItems === 0)
543
- return 100;
544
- return Math.min(100, (this.itemsProcessed / this.totalItems) * 100);
545
- }
546
- /**
547
- * Report progress to callback.
548
- */
549
- reportProgress() {
550
- if (!this.callback)
551
- return;
552
- const progress = this.getProgress();
553
- const operationName = this.operation.charAt(0).toUpperCase() + this.operation.slice(1);
554
- const status = `${operationName}ing: ${this.itemsProcessed} / ${this.totalItems} items`;
555
- if (this.isEnhancedCallback(this.callback)) {
556
- const event = {
557
- stage: this.operation,
558
- progress,
559
- stageProgress: progress,
560
- status,
561
- metadata: {
562
- cryptoOperation: this.operation,
563
- itemsProcessed: this.itemsProcessed,
564
- totalItems: this.totalItems,
565
- },
566
- };
567
- this.callback(event);
568
- }
569
- else {
570
- this.reporter.report(status, progress);
571
- }
572
- }
573
- /**
574
- * Check if callback expects enhanced events.
575
- *
576
- * @param callback Callback to check
577
- * @returns True if enhanced callback
578
- */
579
- isEnhancedCallback(callback) {
580
- return callback.length === 1;
581
- }
582
- }
583
- exports.EncryptionProgressTracker = EncryptionProgressTracker;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EncryptionProgressTracker=exports.ShareDistributionTracker=exports.TransferProgressTracker=exports.OperationProgressTracker=void 0;const ux_helpers_1=require("../_deps/ux-helpers/index.js");class OperationProgressTracker{callback;throttleMs;lastUpdateTime=0;currentStage="";currentStageWeight=0;currentStageProgress=0;completedWeight=0;metadata={};constructor(t,e){this.callback=t,this.throttleMs=e?.throttleMs??100}startStage(t,e,s){this.currentStage=t,this.currentStageWeight=Math.max(0,Math.min(100,e)),this.currentStageProgress=0,this.reportProgress(s??`Starting ${t}...`)}updateStageProgress(t,e,s){this.currentStageProgress=Math.max(0,Math.min(100,t)),s&&(this.metadata={...this.metadata,...s});const r=e??`${this.currentStage} (${Math.round(t)}%)`;this.reportProgress(r)}completeStage(){this.currentStageProgress=100,this.completedWeight+=this.currentStageWeight,this.reportProgress(`${this.currentStage} complete`),this.currentStage="",this.currentStageWeight=0,this.currentStageProgress=0}complete(){this.completedWeight=100,this.currentStageProgress=100,this.reportProgress("Complete")}getProgress(){const t=this.currentStageWeight*this.currentStageProgress/100;return Math.min(100,this.completedWeight+t)}updateMetadata(t){this.metadata={...this.metadata,...t}}reportProgress(t){if(!this.callback)return;const e=Date.now();if(e-this.lastUpdateTime<this.throttleMs){if(this.getProgress()<100)return}this.lastUpdateTime=e;const s=this.getProgress();if(this.isEnhancedCallback(this.callback)){const e={stage:this.currentStage,progress:s,stageProgress:this.currentStageProgress,status:t,metadata:Object.keys(this.metadata).length>0?this.metadata:void 0};this.callback(e)}else this.callback(t,s)}isEnhancedCallback(t){return 1===t.length}}exports.OperationProgressTracker=OperationProgressTracker;class TransferProgressTracker{totalBytes;callback;reporter;throttleMs;bytesTransferred=0;startTime=Date.now();lastUpdateTime=0;samples=[];maxSamples=10;constructor(t,e,s=100){this.totalBytes=t,this.callback=e,this.throttleMs=s,this.reporter=new ux_helpers_1.ProgressReporter("function"==typeof e&&2===e.length?e:void 0)}addTransferred(t){this.bytesTransferred+=t;const e=Date.now();this.samples.push({time:e,bytes:this.bytesTransferred}),this.samples.length>this.maxSamples&&this.samples.shift(),e-this.lastUpdateTime<this.throttleMs||(this.lastUpdateTime=e,this.reportProgress())}complete(){this.bytesTransferred=this.totalBytes,this.reportProgress()}getProgress(){return 0===this.totalBytes?100:Math.min(100,this.bytesTransferred/this.totalBytes*100)}calculateBytesPerSecond(){if(this.samples.length<2){const t=(Date.now()-this.startTime)/1e3;return t>0?this.bytesTransferred/t:0}const t=this.samples[0],e=this.samples[this.samples.length-1];if(!t||!e)return 0;const s=(e.time-t.time)/1e3,r=e.bytes-t.bytes;return s>0?r/s:0}estimateTimeRemaining(){const t=this.calculateBytesPerSecond();if(0===t)return 0;return(this.totalBytes-this.bytesTransferred)/t*1e3}reportProgress(){if(!this.callback)return;const t=this.getProgress(),e=this.calculateBytesPerSecond(),s=this.estimateTimeRemaining(),r=this.formatStatus(t,e,s);if(this.isEnhancedCallback(this.callback)){const a={stage:"transfer",progress:t,stageProgress:t,status:r,metadata:{bytesTransferred:this.bytesTransferred,totalBytes:this.totalBytes,bytesPerSecond:e,estimatedTimeRemaining:s}};this.callback(a)}else this.reporter.report(r,t)}formatStatus(t,e,s){const r=this.formatBytes(this.bytesTransferred),a=this.formatBytes(this.totalBytes),i=this.formatBytes(e),o=this.formatTime(s);return`Transferring ${r} / ${a} (${Math.round(t)}%) - ${i}/s - ${o} remaining`}formatBytes(t){const e=["B","KB","MB","GB","TB"];let s=t,r=0;for(;s>=1024&&r<e.length-1;)s/=1024,r++;return`${s.toFixed(1)} ${e[r]}`}formatTime(t){const e=Math.floor(t/1e3);if(e<60)return`${e}s`;const s=Math.floor(e/60);if(s<60)return`${s}m ${e%60}s`;return`${Math.floor(s/60)}h ${s%60}m`}isEnhancedCallback(t){return 1===t.length}}exports.TransferProgressTracker=TransferProgressTracker;class ShareDistributionTracker{totalShares;callback;reporter;distributedShares=new Set;constructor(t,e){this.totalShares=t,this.callback=e,this.reporter=new ux_helpers_1.ProgressReporter("function"==typeof e&&2===e.length?e:void 0)}markShareDistributed(t){this.distributedShares.add(t),this.reportProgress()}complete(){for(let t=0;t<this.totalShares;t++)this.distributedShares.add(t);this.reportProgress()}getProgress(){return 0===this.totalShares?100:this.distributedShares.size/this.totalShares*100}reportProgress(){if(!this.callback)return;const t=this.getProgress(),e=`Distributed ${this.distributedShares.size} / ${this.totalShares} shares`;if(this.isEnhancedCallback(this.callback)){const s={stage:"distribution",progress:t,stageProgress:t,status:e,metadata:{sharesDistributed:this.distributedShares.size,totalShares:this.totalShares}};this.callback(s)}else this.reporter.report(e,t)}isEnhancedCallback(t){return 1===t.length}}exports.ShareDistributionTracker=ShareDistributionTracker;class EncryptionProgressTracker{operation;totalItems;callback;reporter;itemsProcessed=0;constructor(t,e,s){this.operation=t,this.totalItems=e,this.callback=s,this.reporter=new ux_helpers_1.ProgressReporter("function"==typeof s&&2===s.length?s:void 0)}incrementProcessed(t=1){this.itemsProcessed+=t,this.reportProgress()}complete(){this.itemsProcessed=this.totalItems,this.reportProgress()}getProgress(){return 0===this.totalItems?100:Math.min(100,this.itemsProcessed/this.totalItems*100)}reportProgress(){if(!this.callback)return;const t=this.getProgress(),e=`${this.operation.charAt(0).toUpperCase()+this.operation.slice(1)}ing: ${this.itemsProcessed} / ${this.totalItems} items`;if(this.isEnhancedCallback(this.callback)){const s={stage:this.operation,progress:t,stageProgress:t,status:e,metadata:{cryptoOperation:this.operation,itemsProcessed:this.itemsProcessed,totalItems:this.totalItems}};this.callback(s)}else this.reporter.report(e,t)}isEnhancedCallback(t){return 1===t.length}}exports.EncryptionProgressTracker=EncryptionProgressTracker;
@@ -1,76 +1 @@
1
- "use strict";
2
- /* -- RedisNonceStore -- Cross-Node Replay Prevention -- */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.RedisNonceStore = void 0;
5
- /** Default TTL for nonce entries: 600 seconds (10 minutes). */
6
- const DEFAULT_TTL_SECONDS = 600;
7
- /** Default key prefix for Redis nonce keys. */
8
- const DEFAULT_KEY_PREFIX = 'nonce:';
9
- /**
10
- * Redis-backed nonce store for multi-node deployments.
11
- *
12
- * Uses Redis SET NX with TTL for atomic, distributed nonce deduplication.
13
- * Nonce expiry is handled by Redis TTL -- no manual cleanup needed.
14
- * Zero npm dependencies: users provide their own RedisClient implementation.
15
- *
16
- * @example
17
- * ```typescript
18
- * import { RedisNonceStore } from '@private.me/xbind';
19
- * import Redis from 'ioredis';
20
- *
21
- * const redis = new Redis();
22
- * const store = new RedisNonceStore({
23
- * client: {
24
- * setNX: (key, value, ttl) =>
25
- * redis.set(key, value, 'EX', ttl, 'NX'),
26
- * del: (key) => redis.del(key),
27
- * quit: () => redis.quit(),
28
- * },
29
- * });
30
- * ```
31
- */
32
- class RedisNonceStore {
33
- client;
34
- ttlSeconds;
35
- keyPrefix;
36
- constructor(opts) {
37
- this.client = opts.client;
38
- this.ttlSeconds = opts.ttlSeconds ?? DEFAULT_TTL_SECONDS;
39
- this.keyPrefix = opts.keyPrefix ?? DEFAULT_KEY_PREFIX;
40
- }
41
- /**
42
- * Check if a nonce is fresh and record it atomically via Redis SET NX.
43
- *
44
- * Uses Redis SET with NX (set-if-not-exists) and EX (TTL in seconds)
45
- * for atomic, distributed deduplication. If the key already exists in
46
- * any Redis-connected node, the nonce is rejected as a duplicate.
47
- *
48
- * @param nonce - The nonce string to check.
49
- * @param senderDid - The DID of the sender.
50
- * @returns true if the nonce is new (accepted), false if duplicate (rejected).
51
- */
52
- async check(nonce, senderDid) {
53
- const key = `${this.keyPrefix}${senderDid}:${nonce}`;
54
- const result = await this.client.setNX(key, '1', this.ttlSeconds);
55
- return result === 'OK';
56
- }
57
- /**
58
- * No-op for Redis store -- TTL-based expiry is handled automatically.
59
- *
60
- * This method exists to satisfy the NonceStore interface. Redis keys
61
- * expire based on the TTL set during setNX, so no manual cleanup is needed.
62
- */
63
- cleanup() {
64
- // No-op: Redis TTL handles expiry automatically
65
- }
66
- /**
67
- * Disconnect from Redis gracefully.
68
- *
69
- * Calls the underlying RedisClient quit() method to close the connection.
70
- * After calling dispose(), the store should not be used.
71
- */
72
- dispose() {
73
- void this.client.quit();
74
- }
75
- }
76
- exports.RedisNonceStore = RedisNonceStore;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RedisNonceStore=void 0;const DEFAULT_TTL_SECONDS=600,DEFAULT_KEY_PREFIX="nonce:";class RedisNonceStore{client;ttlSeconds;keyPrefix;constructor(e){this.client=e.client,this.ttlSeconds=e.ttlSeconds??600,this.keyPrefix=e.keyPrefix??"nonce:"}async check(e,t){const s=`${this.keyPrefix}${t}:${e}`;return"OK"===await this.client.setNX(s,"1",this.ttlSeconds)}cleanup(){}dispose(){this.client.quit()}}exports.RedisNonceStore=RedisNonceStore;