@private.me/xbind 1.3.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
- package/dist-standalone/_deps/shared/cjs/index.js +1 -496
- package/dist-standalone/_deps/shared/cjs/types.js +1 -317
- package/dist-standalone/_deps/shared/errors.js +1 -255
- package/dist-standalone/_deps/shared/index.js +1 -74
- package/dist-standalone/_deps/shared/types.js +1 -90
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +1 -642
- package/dist-standalone/agent-sdk.js +1 -328
- package/dist-standalone/agent.d.ts +95 -5
- package/dist-standalone/agent.js +1 -1545
- package/dist-standalone/approval.js +1 -193
- package/dist-standalone/async-iterators.d.ts +275 -0
- package/dist-standalone/async-iterators.js +1 -0
- package/dist-standalone/auth.js +1 -219
- package/dist-standalone/auto-accept.js +1 -229
- package/dist-standalone/backup-config.js +1 -201
- package/dist-standalone/backup.d.ts +114 -0
- package/dist-standalone/backup.js +1 -0
- package/dist-standalone/batch-operations.d.ts +297 -0
- package/dist-standalone/batch-operations.js +1 -0
- package/dist-standalone/cancellation.d.ts +301 -0
- package/dist-standalone/cancellation.js +1 -0
- package/dist-standalone/checkpoint.js +1 -186
- package/dist-standalone/circuit-breaker.d.ts +351 -0
- package/dist-standalone/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/agent-call.js +1 -651
- package/dist-standalone/cjs/agent-sdk.js +1 -332
- package/dist-standalone/cjs/agent.js +1 -1582
- package/dist-standalone/cjs/approval.js +1 -199
- package/dist-standalone/cjs/async-iterators.js +1 -0
- package/dist-standalone/cjs/auth.js +1 -225
- package/dist-standalone/cjs/auto-accept.js +1 -233
- package/dist-standalone/cjs/backup-config.js +1 -207
- package/dist-standalone/cjs/backup.js +1 -0
- package/dist-standalone/cjs/batch-operations.js +1 -0
- package/dist-standalone/cjs/cancellation.js +1 -0
- package/dist-standalone/cjs/checkpoint.js +1 -193
- package/dist-standalone/cjs/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/cli/init.js +1 -486
- package/dist-standalone/cjs/config-validation.js +1 -0
- package/dist-standalone/cjs/connect.js +1 -312
- package/dist-standalone/cjs/connection-pool.js +1 -0
- package/dist-standalone/cjs/correlation-id.js +1 -339
- package/dist-standalone/cjs/crypto-utils.js +1 -0
- package/dist-standalone/cjs/debug-mode.js +1 -0
- package/dist-standalone/cjs/did-document.js +1 -101
- package/dist-standalone/cjs/did-privateme.js +1 -130
- package/dist-standalone/cjs/did-web.js +1 -201
- package/dist-standalone/cjs/discovery.js +1 -462
- package/dist-standalone/cjs/dual-mode.js +1 -251
- package/dist-standalone/cjs/email-templates.js +1 -313
- package/dist-standalone/cjs/email-transport.js +1 -239
- package/dist-standalone/cjs/envelope.js +1 -510
- package/dist-standalone/cjs/errors.js +1 -826
- package/dist-standalone/cjs/event-emitter.js +1 -0
- package/dist-standalone/cjs/gateway-state.js +1 -55
- package/dist-standalone/cjs/gateway-transport.js +1 -120
- package/dist-standalone/cjs/graceful-degradation.js +1 -0
- package/dist-standalone/cjs/guardrails.js +1 -223
- package/dist-standalone/cjs/health-check.js +1 -0
- package/dist-standalone/cjs/http-compat.js +1 -272
- package/dist-standalone/cjs/http-status-map.js +1 -571
- package/dist-standalone/cjs/identity.js +1 -540
- package/dist-standalone/cjs/index.js +1 -237
- package/dist-standalone/cjs/invitation.js +1 -421
- package/dist-standalone/cjs/invite.js +1 -328
- package/dist-standalone/cjs/key-agreement.js +1 -246
- package/dist-standalone/cjs/lazy-init.js +1 -300
- package/dist-standalone/cjs/logger.js +1 -0
- package/dist-standalone/cjs/mdns-discovery.js +1 -202
- package/dist-standalone/cjs/nonce-store.js +1 -66
- package/dist-standalone/cjs/pairing-manager.js +1 -223
- package/dist-standalone/cjs/plugin-system.js +1 -0
- package/dist-standalone/cjs/plugins/logging.js +1 -0
- package/dist-standalone/cjs/plugins/metrics.js +1 -0
- package/dist-standalone/cjs/plugins/validation.js +1 -0
- package/dist-standalone/cjs/policy.js +1 -320
- package/dist-standalone/cjs/progress-callbacks.js +1 -0
- package/dist-standalone/cjs/redis-nonce-store.js +1 -76
- package/dist-standalone/cjs/registry-middleware.js +1 -50
- package/dist-standalone/cjs/retry-strategies.js +1 -0
- package/dist-standalone/cjs/retry-transport.js +1 -102
- package/dist-standalone/cjs/runtime/browser.js +1 -0
- package/dist-standalone/cjs/runtime/edge.js +1 -0
- package/dist-standalone/cjs/runtime/react-native.js +1 -0
- package/dist-standalone/cjs/security-policy.js +1 -245
- package/dist-standalone/cjs/serialization.js +1 -0
- package/dist-standalone/cjs/split-channel.js +1 -177
- package/dist-standalone/cjs/subscription-proof.js +1 -230
- package/dist-standalone/cjs/succession.js +1 -148
- package/dist-standalone/cjs/timeouts.js +1 -0
- package/dist-standalone/cjs/trace-context.js +1 -0
- package/dist-standalone/cjs/trace-spans.js +1 -0
- package/dist-standalone/cjs/transport.js +1 -63
- package/dist-standalone/cjs/trust-registry.js +1 -742
- package/dist-standalone/cjs/types/error-response.js +1 -56
- package/dist-standalone/cjs/vault-auth.js +1 -0
- package/dist-standalone/cjs/vault-store-loader.js +1 -0
- package/dist-standalone/cjs/verify.js +1 -25
- package/dist-standalone/cjs/version-info.js +1 -0
- package/dist-standalone/cjs/xfetch.js +1 -252
- package/dist-standalone/cli/init.js +1 -449
- package/dist-standalone/cli/setup.js +1 -514
- package/dist-standalone/cli/types.js +1 -27
- package/dist-standalone/cli/xbind.js +1 -148
- package/dist-standalone/config-validation.d.ts +185 -0
- package/dist-standalone/config-validation.js +1 -0
- package/dist-standalone/connect.js +1 -274
- package/dist-standalone/connection-pool.d.ts +251 -0
- package/dist-standalone/connection-pool.js +1 -0
- package/dist-standalone/correlation-id.js +1 -326
- package/dist-standalone/crypto-utils.d.ts +60 -0
- package/dist-standalone/crypto-utils.js +1 -0
- package/dist-standalone/debug-mode.d.ts +286 -0
- package/dist-standalone/debug-mode.js +1 -0
- package/dist-standalone/did-document.js +1 -96
- package/dist-standalone/did-privateme.js +1 -121
- package/dist-standalone/did-web.js +1 -196
- package/dist-standalone/discovery.js +1 -458
- package/dist-standalone/dual-mode.js +1 -247
- package/dist-standalone/email-templates.js +1 -309
- package/dist-standalone/email-transport.js +1 -232
- package/dist-standalone/envelope.d.ts +29 -1
- package/dist-standalone/envelope.js +1 -497
- package/dist-standalone/errors.d.ts +10 -0
- package/dist-standalone/errors.js +1 -811
- package/dist-standalone/event-emitter.d.ts +395 -0
- package/dist-standalone/event-emitter.js +1 -0
- package/dist-standalone/gateway-state.js +1 -51
- package/dist-standalone/gateway-transport.js +1 -116
- package/dist-standalone/graceful-degradation.d.ts +246 -0
- package/dist-standalone/graceful-degradation.js +1 -0
- package/dist-standalone/guardrails.js +1 -216
- package/dist-standalone/health-check.d.ts +150 -0
- package/dist-standalone/health-check.js +1 -0
- package/dist-standalone/http-compat.js +1 -267
- package/dist-standalone/http-status-map.js +1 -561
- package/dist-standalone/identity.d.ts +64 -1
- package/dist-standalone/identity.js +1 -515
- package/dist-standalone/index.d.ts +45 -3
- package/dist-standalone/index.js +1 -52
- package/dist-standalone/invitation.js +1 -415
- package/dist-standalone/invite.js +1 -324
- package/dist-standalone/key-agreement.d.ts +61 -13
- package/dist-standalone/key-agreement.js +1 -236
- package/dist-standalone/lazy-init.js +1 -295
- package/dist-standalone/logger.d.ts +77 -0
- package/dist-standalone/logger.js +1 -0
- package/dist-standalone/mdns-discovery.js +1 -195
- package/dist-standalone/nonce-store.d.ts +16 -3
- package/dist-standalone/nonce-store.js +1 -62
- package/dist-standalone/package.json +0 -1
- package/dist-standalone/pairing-manager.js +1 -219
- package/dist-standalone/plugin-system.d.ts +145 -0
- package/dist-standalone/plugin-system.js +1 -0
- package/dist-standalone/policy.js +1 -315
- package/dist-standalone/progress-callbacks.d.ts +394 -0
- package/dist-standalone/progress-callbacks.js +1 -0
- package/dist-standalone/redis-nonce-store.js +1 -72
- package/dist-standalone/registry-middleware.js +1 -47
- package/dist-standalone/retry-strategies.d.ts +382 -0
- package/dist-standalone/retry-strategies.js +1 -0
- package/dist-standalone/retry-transport.js +1 -98
- package/dist-standalone/security-policy.js +1 -239
- package/dist-standalone/serialization.d.ts +244 -0
- package/dist-standalone/serialization.js +1 -0
- package/dist-standalone/split-channel.d.ts +49 -1
- package/dist-standalone/split-channel.js +1 -171
- package/dist-standalone/subscription-proof.js +1 -224
- package/dist-standalone/succession.js +1 -142
- package/dist-standalone/timeouts.d.ts +275 -0
- package/dist-standalone/timeouts.js +1 -0
- package/dist-standalone/trace-context.d.ts +252 -0
- package/dist-standalone/trace-context.js +1 -0
- package/dist-standalone/trace-spans.d.ts +360 -0
- package/dist-standalone/trace-spans.js +1 -0
- package/dist-standalone/transport.js +1 -59
- package/dist-standalone/trust-registry.d.ts +106 -5
- package/dist-standalone/trust-registry.js +1 -702
- package/dist-standalone/vault-auth.d.ts +91 -0
- package/dist-standalone/vault-auth.js +1 -0
- package/dist-standalone/vault-store-loader.d.ts +110 -0
- package/dist-standalone/vault-store-loader.js +1 -0
- package/dist-standalone/verify.js +1 -16
- package/dist-standalone/version-info.d.ts +259 -0
- package/dist-standalone/version-info.js +1 -0
- package/dist-standalone/xfetch.js +1 -247
- package/llms.txt +1 -0
- package/package.json +65 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -222
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
- package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -199
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -134
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -145
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -159
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -92
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -295
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -364
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -136
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -71
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -366
- package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/errors.js.map +0 -1
- package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/index.js.map +0 -1
- package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
- package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/index.js.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
- package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/types.js.map +0 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module progress-callbacks
|
|
3
|
+
* Enhanced progress tracking for xBind operations
|
|
4
|
+
*
|
|
5
|
+
* Provides domain-specific progress callbacks for long-running operations:
|
|
6
|
+
* - Upload/download progress with bandwidth estimation
|
|
7
|
+
* - Share distribution progress (XorIDA multi-channel delivery)
|
|
8
|
+
* - Encryption/decryption progress
|
|
9
|
+
* - Multi-stage operation tracking
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const tracker = new OperationProgressTracker(onProgress);
|
|
14
|
+
* tracker.startStage('encryption', 40); // 40% of total operation
|
|
15
|
+
* // ... encryption work
|
|
16
|
+
* tracker.updateStageProgress(50); // 50% of encryption stage
|
|
17
|
+
* tracker.completeStage();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { ProgressCallback } from '@private.me/ux-helpers';
|
|
21
|
+
/**
|
|
22
|
+
* Enhanced progress event with operation-specific metadata.
|
|
23
|
+
*/
|
|
24
|
+
export interface EnhancedProgressEvent {
|
|
25
|
+
/** Current stage/operation name */
|
|
26
|
+
readonly stage: string;
|
|
27
|
+
/** Overall progress percentage (0-100) */
|
|
28
|
+
readonly progress: number;
|
|
29
|
+
/** Stage-specific progress percentage (0-100) */
|
|
30
|
+
readonly stageProgress: number;
|
|
31
|
+
/** Human-readable status message */
|
|
32
|
+
readonly status: string;
|
|
33
|
+
/** Operation-specific metadata */
|
|
34
|
+
readonly metadata?: ProgressMetadata;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Progress metadata for different operation types.
|
|
38
|
+
*/
|
|
39
|
+
export interface ProgressMetadata {
|
|
40
|
+
/** Bytes transferred (for upload/download) */
|
|
41
|
+
readonly bytesTransferred?: number;
|
|
42
|
+
/** Total bytes (for upload/download) */
|
|
43
|
+
readonly totalBytes?: number;
|
|
44
|
+
/** Transfer rate in bytes/second */
|
|
45
|
+
readonly bytesPerSecond?: number;
|
|
46
|
+
/** Estimated time remaining in milliseconds */
|
|
47
|
+
readonly estimatedTimeRemaining?: number;
|
|
48
|
+
/** Number of shares distributed (for XorIDA operations) */
|
|
49
|
+
readonly sharesDistributed?: number;
|
|
50
|
+
/** Total shares to distribute */
|
|
51
|
+
readonly totalShares?: number;
|
|
52
|
+
/** Current encryption/decryption operation */
|
|
53
|
+
readonly cryptoOperation?: 'encrypt' | 'decrypt' | 'sign' | 'verify';
|
|
54
|
+
/** Number of items processed */
|
|
55
|
+
readonly itemsProcessed?: number;
|
|
56
|
+
/** Total items to process */
|
|
57
|
+
readonly totalItems?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Enhanced progress callback with metadata.
|
|
61
|
+
*/
|
|
62
|
+
export type EnhancedProgressCallback = (event: EnhancedProgressEvent) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Stage definition for multi-stage operations.
|
|
65
|
+
*/
|
|
66
|
+
export interface OperationStage {
|
|
67
|
+
/** Stage identifier */
|
|
68
|
+
readonly name: string;
|
|
69
|
+
/** Weight of this stage (percentage of total operation, 0-100) */
|
|
70
|
+
readonly weight: number;
|
|
71
|
+
/** Human-readable description */
|
|
72
|
+
readonly description: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Options for operation progress tracking.
|
|
76
|
+
*/
|
|
77
|
+
export interface OperationProgressOptions {
|
|
78
|
+
/** Progress callback */
|
|
79
|
+
readonly onProgress?: ProgressCallback | EnhancedProgressCallback;
|
|
80
|
+
/** Enable bandwidth estimation for transfers */
|
|
81
|
+
readonly estimateBandwidth?: boolean;
|
|
82
|
+
/** Minimum interval between progress updates (ms) */
|
|
83
|
+
readonly throttleMs?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Multi-stage operation progress tracker.
|
|
87
|
+
*
|
|
88
|
+
* Manages progress across multiple stages with weighted contributions
|
|
89
|
+
* to overall progress. Useful for complex operations like:
|
|
90
|
+
* - Message send: resolve DID (10%) → encrypt (30%) → split shares (20%) → distribute (40%)
|
|
91
|
+
* - File transfer: prepare (5%) → encrypt (25%) → upload (70%)
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const tracker = new OperationProgressTracker(onProgress);
|
|
96
|
+
*
|
|
97
|
+
* tracker.startStage('preparation', 10);
|
|
98
|
+
* // ... prep work
|
|
99
|
+
* tracker.completeStage();
|
|
100
|
+
*
|
|
101
|
+
* tracker.startStage('encryption', 40);
|
|
102
|
+
* tracker.updateStageProgress(50); // Halfway through encryption
|
|
103
|
+
* tracker.completeStage();
|
|
104
|
+
*
|
|
105
|
+
* tracker.startStage('distribution', 50);
|
|
106
|
+
* // ... distribution work
|
|
107
|
+
* tracker.complete();
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare class OperationProgressTracker {
|
|
111
|
+
private readonly callback?;
|
|
112
|
+
private readonly throttleMs;
|
|
113
|
+
private lastUpdateTime;
|
|
114
|
+
private currentStage;
|
|
115
|
+
private currentStageWeight;
|
|
116
|
+
private currentStageProgress;
|
|
117
|
+
private completedWeight;
|
|
118
|
+
private metadata;
|
|
119
|
+
/**
|
|
120
|
+
* Create a new operation progress tracker.
|
|
121
|
+
*
|
|
122
|
+
* @param onProgress Progress callback (standard or enhanced)
|
|
123
|
+
* @param options Tracking options
|
|
124
|
+
*/
|
|
125
|
+
constructor(onProgress?: ProgressCallback | EnhancedProgressCallback, options?: Omit<OperationProgressOptions, 'onProgress'>);
|
|
126
|
+
/**
|
|
127
|
+
* Start a new stage.
|
|
128
|
+
*
|
|
129
|
+
* @param name Stage identifier
|
|
130
|
+
* @param weight Weight of this stage (percentage of total, 0-100)
|
|
131
|
+
* @param description Human-readable description
|
|
132
|
+
*/
|
|
133
|
+
startStage(name: string, weight: number, description?: string): void;
|
|
134
|
+
/**
|
|
135
|
+
* Update progress within the current stage.
|
|
136
|
+
*
|
|
137
|
+
* @param stagePercent Progress percentage within current stage (0-100)
|
|
138
|
+
* @param status Optional status message
|
|
139
|
+
* @param metadata Optional progress metadata
|
|
140
|
+
*/
|
|
141
|
+
updateStageProgress(stagePercent: number, status?: string, metadata?: Partial<ProgressMetadata>): void;
|
|
142
|
+
/**
|
|
143
|
+
* Complete the current stage and advance overall progress.
|
|
144
|
+
*/
|
|
145
|
+
completeStage(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Mark the entire operation as complete.
|
|
148
|
+
*/
|
|
149
|
+
complete(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Get current overall progress percentage.
|
|
152
|
+
*
|
|
153
|
+
* @returns Progress percentage (0-100)
|
|
154
|
+
*/
|
|
155
|
+
getProgress(): number;
|
|
156
|
+
/**
|
|
157
|
+
* Update metadata without changing progress.
|
|
158
|
+
*
|
|
159
|
+
* @param metadata Metadata to merge
|
|
160
|
+
*/
|
|
161
|
+
updateMetadata(metadata: Partial<ProgressMetadata>): void;
|
|
162
|
+
/**
|
|
163
|
+
* Report progress to callback (with throttling).
|
|
164
|
+
*
|
|
165
|
+
* @param status Status message
|
|
166
|
+
*/
|
|
167
|
+
private reportProgress;
|
|
168
|
+
/**
|
|
169
|
+
* Check if callback expects enhanced events.
|
|
170
|
+
*
|
|
171
|
+
* @param callback Callback to check
|
|
172
|
+
* @returns True if enhanced callback
|
|
173
|
+
*/
|
|
174
|
+
private isEnhancedCallback;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Transfer progress tracker with bandwidth estimation.
|
|
178
|
+
*
|
|
179
|
+
* Tracks upload/download progress with automatic bandwidth calculation
|
|
180
|
+
* and estimated time remaining.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const tracker = new TransferProgressTracker(totalBytes, onProgress);
|
|
185
|
+
*
|
|
186
|
+
* for (const chunk of chunks) {
|
|
187
|
+
* await uploadChunk(chunk);
|
|
188
|
+
* tracker.addTransferred(chunk.length);
|
|
189
|
+
* }
|
|
190
|
+
*
|
|
191
|
+
* tracker.complete();
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare class TransferProgressTracker {
|
|
195
|
+
private readonly totalBytes;
|
|
196
|
+
private readonly callback?;
|
|
197
|
+
private readonly reporter;
|
|
198
|
+
private readonly throttleMs;
|
|
199
|
+
private bytesTransferred;
|
|
200
|
+
private startTime;
|
|
201
|
+
private lastUpdateTime;
|
|
202
|
+
private samples;
|
|
203
|
+
private readonly maxSamples;
|
|
204
|
+
/**
|
|
205
|
+
* Create a new transfer progress tracker.
|
|
206
|
+
*
|
|
207
|
+
* @param totalBytes Total bytes to transfer
|
|
208
|
+
* @param onProgress Progress callback
|
|
209
|
+
* @param throttleMs Minimum interval between updates (default: 100ms)
|
|
210
|
+
*/
|
|
211
|
+
constructor(totalBytes: number, onProgress?: ProgressCallback | EnhancedProgressCallback, throttleMs?: number);
|
|
212
|
+
/**
|
|
213
|
+
* Add transferred bytes and update progress.
|
|
214
|
+
*
|
|
215
|
+
* @param bytes Number of bytes transferred
|
|
216
|
+
*/
|
|
217
|
+
addTransferred(bytes: number): void;
|
|
218
|
+
/**
|
|
219
|
+
* Mark transfer as complete.
|
|
220
|
+
*/
|
|
221
|
+
complete(): void;
|
|
222
|
+
/**
|
|
223
|
+
* Get current progress percentage.
|
|
224
|
+
*
|
|
225
|
+
* @returns Progress percentage (0-100)
|
|
226
|
+
*/
|
|
227
|
+
getProgress(): number;
|
|
228
|
+
/**
|
|
229
|
+
* Calculate current transfer rate.
|
|
230
|
+
*
|
|
231
|
+
* @returns Bytes per second
|
|
232
|
+
*/
|
|
233
|
+
private calculateBytesPerSecond;
|
|
234
|
+
/**
|
|
235
|
+
* Estimate time remaining.
|
|
236
|
+
*
|
|
237
|
+
* @returns Estimated milliseconds remaining
|
|
238
|
+
*/
|
|
239
|
+
private estimateTimeRemaining;
|
|
240
|
+
/**
|
|
241
|
+
* Report progress to callback.
|
|
242
|
+
*/
|
|
243
|
+
private reportProgress;
|
|
244
|
+
/**
|
|
245
|
+
* Format status message with transfer details.
|
|
246
|
+
*
|
|
247
|
+
* @param progress Progress percentage
|
|
248
|
+
* @param bytesPerSecond Transfer rate
|
|
249
|
+
* @param estimatedTimeRemaining Time remaining in ms
|
|
250
|
+
* @returns Formatted status string
|
|
251
|
+
*/
|
|
252
|
+
private formatStatus;
|
|
253
|
+
/**
|
|
254
|
+
* Format bytes for display.
|
|
255
|
+
*
|
|
256
|
+
* @param bytes Number of bytes
|
|
257
|
+
* @returns Formatted string (e.g., "1.5 MB")
|
|
258
|
+
*/
|
|
259
|
+
private formatBytes;
|
|
260
|
+
/**
|
|
261
|
+
* Format time for display.
|
|
262
|
+
*
|
|
263
|
+
* @param ms Milliseconds
|
|
264
|
+
* @returns Formatted string (e.g., "2m 30s")
|
|
265
|
+
*/
|
|
266
|
+
private formatTime;
|
|
267
|
+
/**
|
|
268
|
+
* Check if callback expects enhanced events.
|
|
269
|
+
*
|
|
270
|
+
* @param callback Callback to check
|
|
271
|
+
* @returns True if enhanced callback
|
|
272
|
+
*/
|
|
273
|
+
private isEnhancedCallback;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Share distribution progress tracker for XorIDA operations.
|
|
277
|
+
*
|
|
278
|
+
* Tracks progress of distributing shares across multiple channels.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const tracker = new ShareDistributionTracker(3, onProgress);
|
|
283
|
+
*
|
|
284
|
+
* await distributeShare(0);
|
|
285
|
+
* tracker.markShareDistributed(0);
|
|
286
|
+
*
|
|
287
|
+
* await distributeShare(1);
|
|
288
|
+
* tracker.markShareDistributed(1);
|
|
289
|
+
*
|
|
290
|
+
* await distributeShare(2);
|
|
291
|
+
* tracker.markShareDistributed(2);
|
|
292
|
+
*
|
|
293
|
+
* tracker.complete();
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export declare class ShareDistributionTracker {
|
|
297
|
+
private readonly totalShares;
|
|
298
|
+
private readonly callback?;
|
|
299
|
+
private readonly reporter;
|
|
300
|
+
private distributedShares;
|
|
301
|
+
/**
|
|
302
|
+
* Create a new share distribution tracker.
|
|
303
|
+
*
|
|
304
|
+
* @param totalShares Total number of shares to distribute
|
|
305
|
+
* @param onProgress Progress callback
|
|
306
|
+
*/
|
|
307
|
+
constructor(totalShares: number, onProgress?: ProgressCallback | EnhancedProgressCallback);
|
|
308
|
+
/**
|
|
309
|
+
* Mark a share as successfully distributed.
|
|
310
|
+
*
|
|
311
|
+
* @param shareIndex Zero-based share index
|
|
312
|
+
*/
|
|
313
|
+
markShareDistributed(shareIndex: number): void;
|
|
314
|
+
/**
|
|
315
|
+
* Mark all shares as distributed and complete.
|
|
316
|
+
*/
|
|
317
|
+
complete(): void;
|
|
318
|
+
/**
|
|
319
|
+
* Get current progress percentage.
|
|
320
|
+
*
|
|
321
|
+
* @returns Progress percentage (0-100)
|
|
322
|
+
*/
|
|
323
|
+
getProgress(): number;
|
|
324
|
+
/**
|
|
325
|
+
* Report progress to callback.
|
|
326
|
+
*/
|
|
327
|
+
private reportProgress;
|
|
328
|
+
/**
|
|
329
|
+
* Check if callback expects enhanced events.
|
|
330
|
+
*
|
|
331
|
+
* @param callback Callback to check
|
|
332
|
+
* @returns True if enhanced callback
|
|
333
|
+
*/
|
|
334
|
+
private isEnhancedCallback;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Encryption progress tracker.
|
|
338
|
+
*
|
|
339
|
+
* Tracks progress of encryption/decryption operations on large data.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const tracker = new EncryptionProgressTracker('encrypt', totalChunks, onProgress);
|
|
344
|
+
*
|
|
345
|
+
* for (const chunk of chunks) {
|
|
346
|
+
* await encryptChunk(chunk);
|
|
347
|
+
* tracker.incrementProcessed();
|
|
348
|
+
* }
|
|
349
|
+
*
|
|
350
|
+
* tracker.complete();
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
export declare class EncryptionProgressTracker {
|
|
354
|
+
private readonly operation;
|
|
355
|
+
private readonly totalItems;
|
|
356
|
+
private readonly callback?;
|
|
357
|
+
private readonly reporter;
|
|
358
|
+
private itemsProcessed;
|
|
359
|
+
/**
|
|
360
|
+
* Create a new encryption progress tracker.
|
|
361
|
+
*
|
|
362
|
+
* @param operation Cryptographic operation type
|
|
363
|
+
* @param totalItems Total number of items to process
|
|
364
|
+
* @param onProgress Progress callback
|
|
365
|
+
*/
|
|
366
|
+
constructor(operation: 'encrypt' | 'decrypt' | 'sign' | 'verify', totalItems: number, onProgress?: ProgressCallback | EnhancedProgressCallback);
|
|
367
|
+
/**
|
|
368
|
+
* Increment the number of processed items.
|
|
369
|
+
*
|
|
370
|
+
* @param count Number of items to add (default: 1)
|
|
371
|
+
*/
|
|
372
|
+
incrementProcessed(count?: number): void;
|
|
373
|
+
/**
|
|
374
|
+
* Mark operation as complete.
|
|
375
|
+
*/
|
|
376
|
+
complete(): void;
|
|
377
|
+
/**
|
|
378
|
+
* Get current progress percentage.
|
|
379
|
+
*
|
|
380
|
+
* @returns Progress percentage (0-100)
|
|
381
|
+
*/
|
|
382
|
+
getProgress(): number;
|
|
383
|
+
/**
|
|
384
|
+
* Report progress to callback.
|
|
385
|
+
*/
|
|
386
|
+
private reportProgress;
|
|
387
|
+
/**
|
|
388
|
+
* Check if callback expects enhanced events.
|
|
389
|
+
*
|
|
390
|
+
* @param callback Callback to check
|
|
391
|
+
* @returns True if enhanced callback
|
|
392
|
+
*/
|
|
393
|
+
private isEnhancedCallback;
|
|
394
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ProgressReporter}from"./_deps/ux-helpers/index.js";export 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}}export 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 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}}export class ShareDistributionTracker{totalShares;callback;reporter;distributedShares=new Set;constructor(t,e){this.totalShares=t,this.callback=e,this.reporter=new 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}}export class EncryptionProgressTracker{operation;totalItems;callback;reporter;itemsProcessed=0;constructor(t,e,s){this.operation=t,this.totalItems=e,this.callback=s,this.reporter=new 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}}
|
|
@@ -1,72 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
const DEFAULT_TTL_SECONDS=600,DEFAULT_KEY_PREFIX="nonce:";export class RedisNonceStore{client;ttlSeconds;keyPrefix;constructor(t){this.client=t.client,this.ttlSeconds=t.ttlSeconds??600,this.keyPrefix=t.keyPrefix??"nonce:"}async check(t,e){const c=`${this.keyPrefix}${e}:${t}`;return"OK"===await this.client.setNX(c,"1",this.ttlSeconds)}cleanup(){}dispose(){this.client.quit()}}
|
|
@@ -1,47 +1 @@
|
|
|
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
|
-
}
|
|
1
|
+
export function createRegistryAuthMiddleware(r){return(t,e,o)=>{const s=t.method.toUpperCase();if("GET"===s||"HEAD"===s)return void o();const i="string"==typeof t.headers.authorization?t.headers.authorization:void 0;if(!i||!i.startsWith("Bearer "))return void e.status(401).json({error:"UNAUTHORIZED"});i.slice(7)===r?o():e.status(401).json({error:"UNAUTHORIZED"})}}
|