@private.me/xbind 1.3.5 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module trace-spans
|
|
3
|
+
* Distributed tracing spans with parent-child relationships
|
|
4
|
+
*
|
|
5
|
+
* Provides span tracking for distributed tracing with automatic timing,
|
|
6
|
+
* attribute collection, and integration with W3C Trace Context.
|
|
7
|
+
*
|
|
8
|
+
* Performance target: <1ms overhead per operation
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { TraceSpan, SpanRecorder } from '@private.me/xbind';
|
|
13
|
+
*
|
|
14
|
+
* // Create a span recorder
|
|
15
|
+
* const recorder = new SpanRecorder();
|
|
16
|
+
*
|
|
17
|
+
* // Start a span
|
|
18
|
+
* const span = recorder.startSpan('operation-name', { attr: 'value' });
|
|
19
|
+
*
|
|
20
|
+
* // Do work...
|
|
21
|
+
*
|
|
22
|
+
* // End the span
|
|
23
|
+
* span.end();
|
|
24
|
+
*
|
|
25
|
+
* // Get completed spans
|
|
26
|
+
* const spans = recorder.getCompletedSpans();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { TraceContext } from './trace-context.js';
|
|
30
|
+
/**
|
|
31
|
+
* Span status codes (aligned with OpenTelemetry)
|
|
32
|
+
*/
|
|
33
|
+
export declare enum SpanStatusCode {
|
|
34
|
+
/** Operation completed successfully */
|
|
35
|
+
OK = 0,
|
|
36
|
+
/** Operation encountered an error */
|
|
37
|
+
ERROR = 1,
|
|
38
|
+
/** Status is unset (default) */
|
|
39
|
+
UNSET = 2
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Span status
|
|
43
|
+
*/
|
|
44
|
+
export interface SpanStatus {
|
|
45
|
+
code: SpanStatusCode;
|
|
46
|
+
message?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Span attributes (key-value pairs)
|
|
50
|
+
*/
|
|
51
|
+
export interface SpanAttributes {
|
|
52
|
+
[key: string]: string | number | boolean | undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Span event (timestamped log entry within a span)
|
|
56
|
+
*/
|
|
57
|
+
export interface SpanEvent {
|
|
58
|
+
/** Event name */
|
|
59
|
+
name: string;
|
|
60
|
+
/** Event timestamp (milliseconds since epoch) */
|
|
61
|
+
timestamp: number;
|
|
62
|
+
/** Event attributes */
|
|
63
|
+
attributes?: SpanAttributes;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Span kind (aligned with OpenTelemetry)
|
|
67
|
+
*/
|
|
68
|
+
export declare enum SpanKind {
|
|
69
|
+
/** Internal span (default) */
|
|
70
|
+
INTERNAL = 0,
|
|
71
|
+
/** Server span (handling incoming request) */
|
|
72
|
+
SERVER = 1,
|
|
73
|
+
/** Client span (outgoing request) */
|
|
74
|
+
CLIENT = 2,
|
|
75
|
+
/** Producer span (message queue producer) */
|
|
76
|
+
PRODUCER = 3,
|
|
77
|
+
/** Consumer span (message queue consumer) */
|
|
78
|
+
CONSUMER = 4
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Completed span data
|
|
82
|
+
*/
|
|
83
|
+
export interface SpanData {
|
|
84
|
+
/** Span ID (16 hex characters) */
|
|
85
|
+
spanId: string;
|
|
86
|
+
/** Trace ID (32 hex characters) */
|
|
87
|
+
traceId: string;
|
|
88
|
+
/** Parent span ID (16 hex characters, if any) */
|
|
89
|
+
parentSpanId?: string;
|
|
90
|
+
/** Span name */
|
|
91
|
+
name: string;
|
|
92
|
+
/** Span kind */
|
|
93
|
+
kind: SpanKind;
|
|
94
|
+
/** Start timestamp (milliseconds since epoch) */
|
|
95
|
+
startTime: number;
|
|
96
|
+
/** End timestamp (milliseconds since epoch) */
|
|
97
|
+
endTime: number;
|
|
98
|
+
/** Duration in milliseconds */
|
|
99
|
+
duration: number;
|
|
100
|
+
/** Span status */
|
|
101
|
+
status: SpanStatus;
|
|
102
|
+
/** Span attributes */
|
|
103
|
+
attributes: SpanAttributes;
|
|
104
|
+
/** Span events */
|
|
105
|
+
events: SpanEvent[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Trace span for distributed tracing
|
|
109
|
+
*
|
|
110
|
+
* Represents a single unit of work in a distributed trace with automatic timing.
|
|
111
|
+
*/
|
|
112
|
+
export declare class TraceSpan {
|
|
113
|
+
/** Span ID (unique within trace) */
|
|
114
|
+
readonly spanId: string;
|
|
115
|
+
/** Trace context */
|
|
116
|
+
readonly traceContext: TraceContext;
|
|
117
|
+
/** Span name */
|
|
118
|
+
readonly name: string;
|
|
119
|
+
/** Span kind */
|
|
120
|
+
readonly kind: SpanKind;
|
|
121
|
+
/** Parent span ID */
|
|
122
|
+
readonly parentSpanId?: string;
|
|
123
|
+
/** Start timestamp (milliseconds since epoch) */
|
|
124
|
+
readonly startTime: number;
|
|
125
|
+
/** End timestamp (milliseconds since epoch, undefined if not ended) */
|
|
126
|
+
private endTime?;
|
|
127
|
+
/** Span status */
|
|
128
|
+
private status;
|
|
129
|
+
/** Span attributes */
|
|
130
|
+
private attributes;
|
|
131
|
+
/** Span events */
|
|
132
|
+
private events;
|
|
133
|
+
/** Whether span has ended */
|
|
134
|
+
private ended;
|
|
135
|
+
/**
|
|
136
|
+
* Create a trace span
|
|
137
|
+
*
|
|
138
|
+
* @param name - Span name
|
|
139
|
+
* @param traceContext - Trace context
|
|
140
|
+
* @param options - Span options
|
|
141
|
+
*/
|
|
142
|
+
constructor(name: string, traceContext: TraceContext, options?: {
|
|
143
|
+
kind?: SpanKind;
|
|
144
|
+
parentSpanId?: string;
|
|
145
|
+
attributes?: SpanAttributes;
|
|
146
|
+
});
|
|
147
|
+
/**
|
|
148
|
+
* Set span attribute
|
|
149
|
+
*
|
|
150
|
+
* @param key - Attribute key
|
|
151
|
+
* @param value - Attribute value
|
|
152
|
+
* @returns This span (for chaining)
|
|
153
|
+
*/
|
|
154
|
+
setAttribute(key: string, value: string | number | boolean): this;
|
|
155
|
+
/**
|
|
156
|
+
* Set multiple span attributes
|
|
157
|
+
*
|
|
158
|
+
* @param attributes - Attributes to set
|
|
159
|
+
* @returns This span (for chaining)
|
|
160
|
+
*/
|
|
161
|
+
setAttributes(attributes: SpanAttributes): this;
|
|
162
|
+
/**
|
|
163
|
+
* Add an event to the span
|
|
164
|
+
*
|
|
165
|
+
* Events are timestamped log entries within a span.
|
|
166
|
+
*
|
|
167
|
+
* @param name - Event name
|
|
168
|
+
* @param attributes - Optional event attributes
|
|
169
|
+
* @returns This span (for chaining)
|
|
170
|
+
*/
|
|
171
|
+
addEvent(name: string, attributes?: SpanAttributes): this;
|
|
172
|
+
/**
|
|
173
|
+
* Set span status
|
|
174
|
+
*
|
|
175
|
+
* @param code - Status code
|
|
176
|
+
* @param message - Optional status message
|
|
177
|
+
* @returns This span (for chaining)
|
|
178
|
+
*/
|
|
179
|
+
setStatus(code: SpanStatusCode, message?: string): this;
|
|
180
|
+
/**
|
|
181
|
+
* Record an exception in the span
|
|
182
|
+
*
|
|
183
|
+
* Automatically sets status to ERROR and adds exception event.
|
|
184
|
+
*
|
|
185
|
+
* @param error - Error to record
|
|
186
|
+
* @returns This span (for chaining)
|
|
187
|
+
*/
|
|
188
|
+
recordException(error: Error | unknown): this;
|
|
189
|
+
/**
|
|
190
|
+
* End the span
|
|
191
|
+
*
|
|
192
|
+
* Records the end timestamp and marks the span as complete.
|
|
193
|
+
* If status is UNSET, automatically sets to OK.
|
|
194
|
+
*
|
|
195
|
+
* @param endTime - Optional end timestamp (defaults to now)
|
|
196
|
+
*/
|
|
197
|
+
end(endTime?: number): void;
|
|
198
|
+
/**
|
|
199
|
+
* Check if span has ended
|
|
200
|
+
*
|
|
201
|
+
* @returns True if ended
|
|
202
|
+
*/
|
|
203
|
+
isEnded(): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Get span duration in milliseconds
|
|
206
|
+
*
|
|
207
|
+
* @returns Duration or null if not ended
|
|
208
|
+
*/
|
|
209
|
+
getDuration(): number | null;
|
|
210
|
+
/**
|
|
211
|
+
* Export span data
|
|
212
|
+
*
|
|
213
|
+
* @returns Span data (throws if span not ended)
|
|
214
|
+
*/
|
|
215
|
+
toData(): SpanData;
|
|
216
|
+
/**
|
|
217
|
+
* Create a child span
|
|
218
|
+
*
|
|
219
|
+
* The child span will have the same trace ID but a new span ID.
|
|
220
|
+
*
|
|
221
|
+
* @param name - Child span name
|
|
222
|
+
* @param options - Span options
|
|
223
|
+
* @returns New child span
|
|
224
|
+
*/
|
|
225
|
+
createChild(name: string, options?: {
|
|
226
|
+
kind?: SpanKind;
|
|
227
|
+
attributes?: SpanAttributes;
|
|
228
|
+
}): TraceSpan;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Span recorder for collecting completed spans
|
|
232
|
+
*
|
|
233
|
+
* Manages span lifecycle and provides access to completed span data.
|
|
234
|
+
*/
|
|
235
|
+
export declare class SpanRecorder {
|
|
236
|
+
/** Active spans (not yet ended) */
|
|
237
|
+
private activeSpans;
|
|
238
|
+
/** Completed spans */
|
|
239
|
+
private completedSpans;
|
|
240
|
+
/** Maximum number of completed spans to keep (prevent memory leak) */
|
|
241
|
+
private maxSpans;
|
|
242
|
+
/** Trace context for root spans */
|
|
243
|
+
private rootContext?;
|
|
244
|
+
/**
|
|
245
|
+
* Create a span recorder
|
|
246
|
+
*
|
|
247
|
+
* @param options - Recorder options
|
|
248
|
+
*/
|
|
249
|
+
constructor(options?: {
|
|
250
|
+
maxSpans?: number;
|
|
251
|
+
traceContext?: TraceContext;
|
|
252
|
+
});
|
|
253
|
+
/**
|
|
254
|
+
* Start a new span
|
|
255
|
+
*
|
|
256
|
+
* @param name - Span name
|
|
257
|
+
* @param options - Span options
|
|
258
|
+
* @returns New span
|
|
259
|
+
*/
|
|
260
|
+
startSpan(name: string, options?: {
|
|
261
|
+
kind?: SpanKind;
|
|
262
|
+
attributes?: SpanAttributes;
|
|
263
|
+
traceContext?: TraceContext;
|
|
264
|
+
parentSpan?: TraceSpan;
|
|
265
|
+
}): TraceSpan;
|
|
266
|
+
/**
|
|
267
|
+
* End a span and record its data
|
|
268
|
+
*
|
|
269
|
+
* @param span - Span to end
|
|
270
|
+
*/
|
|
271
|
+
private endSpan;
|
|
272
|
+
/**
|
|
273
|
+
* Get all completed spans
|
|
274
|
+
*
|
|
275
|
+
* @returns Array of completed span data
|
|
276
|
+
*/
|
|
277
|
+
getCompletedSpans(): readonly SpanData[];
|
|
278
|
+
/**
|
|
279
|
+
* Get active spans
|
|
280
|
+
*
|
|
281
|
+
* @returns Array of active spans
|
|
282
|
+
*/
|
|
283
|
+
getActiveSpans(): readonly TraceSpan[];
|
|
284
|
+
/**
|
|
285
|
+
* Clear all completed spans
|
|
286
|
+
*/
|
|
287
|
+
clearCompletedSpans(): void;
|
|
288
|
+
/**
|
|
289
|
+
* Get span count
|
|
290
|
+
*
|
|
291
|
+
* @returns Object with active and completed span counts
|
|
292
|
+
*/
|
|
293
|
+
getSpanCount(): {
|
|
294
|
+
active: number;
|
|
295
|
+
completed: number;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Find completed spans by trace ID
|
|
299
|
+
*
|
|
300
|
+
* @param traceId - Trace ID to search for
|
|
301
|
+
* @returns Array of matching spans
|
|
302
|
+
*/
|
|
303
|
+
findSpansByTraceId(traceId: string): SpanData[];
|
|
304
|
+
/**
|
|
305
|
+
* Build trace tree from completed spans
|
|
306
|
+
*
|
|
307
|
+
* Groups spans by trace ID and builds parent-child relationships.
|
|
308
|
+
*
|
|
309
|
+
* @param traceId - Trace ID to build tree for
|
|
310
|
+
* @returns Tree structure
|
|
311
|
+
*/
|
|
312
|
+
buildTraceTree(traceId: string): SpanTree | null;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Span tree node (for visualization)
|
|
316
|
+
*/
|
|
317
|
+
export interface SpanTree {
|
|
318
|
+
span: SpanData;
|
|
319
|
+
children: SpanTree[];
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Helper function to measure async operation with automatic span tracking
|
|
323
|
+
*
|
|
324
|
+
* @param recorder - Span recorder
|
|
325
|
+
* @param name - Span name
|
|
326
|
+
* @param fn - Async function to measure
|
|
327
|
+
* @param options - Span options
|
|
328
|
+
* @returns Result of async function
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* const result = await measureAsync(recorder, 'database-query', async () => {
|
|
333
|
+
* return await db.query('SELECT * FROM users');
|
|
334
|
+
* });
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
export declare function measureAsync<T>(recorder: SpanRecorder, name: string, fn: () => Promise<T>, options?: {
|
|
338
|
+
kind?: SpanKind;
|
|
339
|
+
attributes?: SpanAttributes;
|
|
340
|
+
}): Promise<T>;
|
|
341
|
+
/**
|
|
342
|
+
* Helper function to measure sync operation with automatic span tracking
|
|
343
|
+
*
|
|
344
|
+
* @param recorder - Span recorder
|
|
345
|
+
* @param name - Span name
|
|
346
|
+
* @param fn - Sync function to measure
|
|
347
|
+
* @param options - Span options
|
|
348
|
+
* @returns Result of sync function
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* const result = measureSync(recorder, 'encryption', () => {
|
|
353
|
+
* return encrypt(data, key);
|
|
354
|
+
* });
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
export declare function measureSync<T>(recorder: SpanRecorder, name: string, fn: () => T, options?: {
|
|
358
|
+
kind?: SpanKind;
|
|
359
|
+
attributes?: SpanAttributes;
|
|
360
|
+
}): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{TraceContext,generateSpanId}from"./trace-context.js";export var SpanStatusCode;!function(t){t[t.OK=0]="OK",t[t.ERROR=1]="ERROR",t[t.UNSET=2]="UNSET"}(SpanStatusCode||(SpanStatusCode={}));export var SpanKind;!function(t){t[t.INTERNAL=0]="INTERNAL",t[t.SERVER=1]="SERVER",t[t.CLIENT=2]="CLIENT",t[t.PRODUCER=3]="PRODUCER",t[t.CONSUMER=4]="CONSUMER"}(SpanKind||(SpanKind={}));export class TraceSpan{spanId;traceContext;name;kind;parentSpanId;startTime;endTime;status;attributes;events;ended;constructor(t,e,n={}){this.spanId=generateSpanId(),this.traceContext=e,this.name=t,this.kind=n.kind??SpanKind.INTERNAL,this.parentSpanId=n.parentSpanId,this.startTime=Date.now(),this.status={code:SpanStatusCode.UNSET},this.attributes=n.attributes??{},this.events=[],this.ended=!1}setAttribute(t,e){if(this.ended)throw new Error("Cannot set attribute on ended span");return this.attributes[t]=e,this}setAttributes(t){if(this.ended)throw new Error("Cannot set attributes on ended span");return Object.assign(this.attributes,t),this}addEvent(t,e){if(this.ended)throw new Error("Cannot add event to ended span");return this.events.push({name:t,timestamp:Date.now(),attributes:e}),this}setStatus(t,e){if(this.ended)throw new Error("Cannot set status on ended span");return this.status={code:t,message:e},this}recordException(t){if(this.ended)throw new Error("Cannot record exception on ended span");this.setStatus(SpanStatusCode.ERROR);const e={};return t instanceof Error?(e["exception.type"]=t.name,e["exception.message"]=t.message,t.stack&&(e["exception.stacktrace"]=t.stack)):e["exception.message"]=String(t),this.addEvent("exception",e),this}end(t){this.ended||(this.endTime=t??Date.now(),this.ended=!0,this.status.code===SpanStatusCode.UNSET&&(this.status={code:SpanStatusCode.OK}))}isEnded(){return this.ended}getDuration(){return this.ended&&this.endTime?this.endTime-this.startTime:null}toData(){if(!this.ended||!this.endTime)throw new Error("Cannot export data from active span. Call end() first.");return{spanId:this.spanId,traceId:this.traceContext.traceId,parentSpanId:this.parentSpanId,name:this.name,kind:this.kind,startTime:this.startTime,endTime:this.endTime,duration:this.endTime-this.startTime,status:{...this.status},attributes:{...this.attributes},events:this.events.map(t=>({name:t.name,timestamp:t.timestamp,attributes:t.attributes?{...t.attributes}:void 0}))}}createChild(t,e={}){return new TraceSpan(t,this.traceContext,{...e,parentSpanId:this.spanId})}}export class SpanRecorder{activeSpans;completedSpans;maxSpans;rootContext;constructor(t={}){this.activeSpans=new Map,this.completedSpans=[],this.maxSpans=t.maxSpans??1e3,this.rootContext=t.traceContext}startSpan(t,e={}){const n=e.traceContext??e.parentSpan?.traceContext??this.rootContext??TraceContext.create(),a=new TraceSpan(t,n,{kind:e.kind,attributes:e.attributes,parentSpanId:e.parentSpan?.spanId});this.activeSpans.set(a.spanId,a);const s=setTimeout(()=>{a.isEnded()||(a.setStatus(SpanStatusCode.ERROR,"Span not ended (auto-ended by recorder)"),this.endSpan(a))},6e4),r=a.end.bind(a);return a.end=t=>{clearTimeout(s),r(t),this.endSpan(a)},a}endSpan(t){t.isEnded()||t.end(),this.activeSpans.delete(t.spanId);const e=t.toData();this.completedSpans.push(e),this.completedSpans.length>this.maxSpans&&this.completedSpans.shift()}getCompletedSpans(){return[...this.completedSpans]}getActiveSpans(){return Array.from(this.activeSpans.values())}clearCompletedSpans(){this.completedSpans=[]}getSpanCount(){return{active:this.activeSpans.size,completed:this.completedSpans.length}}findSpansByTraceId(t){return this.completedSpans.filter(e=>e.traceId===t)}buildTraceTree(t){const e=this.findSpansByTraceId(t);if(0===e.length)return null;const n=e.find(t=>!t.parentSpanId);return n?buildSpanTreeNode(n,e):null}}function buildSpanTreeNode(t,e){const n=e.filter(e=>e.parentSpanId===t.spanId).map(t=>buildSpanTreeNode(t,e));return{span:t,children:n}}export async function measureAsync(t,e,n,a){const s=t.startSpan(e,a);try{const t=await n();return s.setStatus(SpanStatusCode.OK),t}catch(t){throw s.recordException(t),t}finally{s.end()}}export function measureSync(t,e,n,a){const s=t.startSpan(e,a);try{const t=n();return s.setStatus(SpanStatusCode.OK),t}catch(t){throw s.recordException(t),t}finally{s.end()}}
|
|
@@ -1,59 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* HTTPS transport adapter — sends envelopes as JSON POST requests.
|
|
4
|
-
*
|
|
5
|
-
* Recipient URL resolved as: baseUrl/deliver/{recipientDid}
|
|
6
|
-
* This is the SDK's default transport for server-to-server delivery.
|
|
7
|
-
*/
|
|
8
|
-
export class HttpsTransportAdapter {
|
|
9
|
-
baseUrl;
|
|
10
|
-
timeoutMs;
|
|
11
|
-
fetchFn;
|
|
12
|
-
handlers = [];
|
|
13
|
-
constructor(opts) {
|
|
14
|
-
this.baseUrl = opts.baseUrl.replace(/\/$/, '');
|
|
15
|
-
this.timeoutMs = opts.timeoutMs ?? 10_000;
|
|
16
|
-
this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
17
|
-
}
|
|
18
|
-
async send(envelope, recipientDid) {
|
|
19
|
-
const url = `${this.baseUrl}/deliver/${encodeURIComponent(recipientDid)}`;
|
|
20
|
-
try {
|
|
21
|
-
const controller = new AbortController();
|
|
22
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
23
|
-
const response = await this.fetchFn(url, {
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: { 'Content-Type': 'application/json' },
|
|
26
|
-
body: JSON.stringify(envelope),
|
|
27
|
-
signal: controller.signal,
|
|
28
|
-
});
|
|
29
|
-
clearTimeout(timer);
|
|
30
|
-
if (!response.ok) {
|
|
31
|
-
return err(response.status === 404
|
|
32
|
-
? 'RECIPIENT_UNREACHABLE'
|
|
33
|
-
: 'SEND_FAILED');
|
|
34
|
-
}
|
|
35
|
-
return ok(undefined);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
if (e instanceof DOMException && e.name === 'AbortError') {
|
|
39
|
-
return err('TIMEOUT');
|
|
40
|
-
}
|
|
41
|
-
return err('NETWORK_ERROR');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
onReceive(handler) {
|
|
45
|
-
this.handlers.push(handler);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Dispatch a received envelope to all handlers.
|
|
49
|
-
* Called by the server when an incoming POST is received.
|
|
50
|
-
*/
|
|
51
|
-
dispatch(envelope) {
|
|
52
|
-
for (const handler of this.handlers) {
|
|
53
|
-
handler(envelope);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
dispose() {
|
|
57
|
-
this.handlers = [];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
import{ok,err}from"./_deps/shared/index.js";export class HttpsTransportAdapter{baseUrl;timeoutMs;fetchFn;handlers=[];constructor(t){this.baseUrl=t.baseUrl.replace(/\/$/,""),this.timeoutMs=t.timeoutMs??1e4,this.fetchFn=t.fetch??globalThis.fetch.bind(globalThis)}async send(t,e){const s=`${this.baseUrl}/deliver/${encodeURIComponent(e)}`;try{const e=new AbortController,r=setTimeout(()=>e.abort(),this.timeoutMs),o=await this.fetchFn(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e.signal});return clearTimeout(r),o.ok?ok(void 0):err(404===o.status?"RECIPIENT_UNREACHABLE":"SEND_FAILED")}catch(t){return t instanceof DOMException&&"AbortError"===t.name?err("TIMEOUT"):err("NETWORK_ERROR")}}onReceive(t){this.handlers.push(t)}dispatch(t){for(const e of this.handlers)e(t)}dispose(){this.handlers=[]}}
|
|
@@ -1,7 +1,81 @@
|
|
|
1
1
|
import type { Result } from '@private.me/shared';
|
|
2
2
|
import type { DIDStateCheckpoint } from './checkpoint.js';
|
|
3
|
+
/**
|
|
4
|
+
* Rate limiter for DID registration endpoints.
|
|
5
|
+
*
|
|
6
|
+
* Implements sliding window algorithm with:
|
|
7
|
+
* - Per-IP limit: 10 registrations/hour
|
|
8
|
+
* - Global limit: 1000 registrations/hour
|
|
9
|
+
*
|
|
10
|
+
* Prevents DID registration spam attacks (SCALE-1).
|
|
11
|
+
*/
|
|
12
|
+
export declare class RegistrationRateLimiter {
|
|
13
|
+
private readonly perIPTimestamps;
|
|
14
|
+
private readonly globalTimestamps;
|
|
15
|
+
private readonly perIPLimit;
|
|
16
|
+
private readonly globalLimit;
|
|
17
|
+
private readonly windowMs;
|
|
18
|
+
private cleanupInterval;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new registration rate limiter.
|
|
21
|
+
*
|
|
22
|
+
* @param perIPLimit - Maximum registrations per IP in time window (default: 10)
|
|
23
|
+
* @param globalLimit - Maximum global registrations in time window (default: 1000)
|
|
24
|
+
* @param windowMs - Time window in milliseconds (default: 3600000 = 1 hour)
|
|
25
|
+
*/
|
|
26
|
+
constructor(perIPLimit?: number, globalLimit?: number, windowMs?: number);
|
|
27
|
+
/**
|
|
28
|
+
* Check if registration is allowed for the given IP.
|
|
29
|
+
*
|
|
30
|
+
* @param ip - Client IP address
|
|
31
|
+
* @returns True if allowed, false if rate limited
|
|
32
|
+
*/
|
|
33
|
+
checkLimit(ip: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Record a registration attempt.
|
|
36
|
+
*
|
|
37
|
+
* Call this AFTER successful registration to avoid counting failures.
|
|
38
|
+
*
|
|
39
|
+
* @param ip - Client IP address
|
|
40
|
+
*/
|
|
41
|
+
recordRegistration(ip: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get remaining registrations for an IP.
|
|
44
|
+
*
|
|
45
|
+
* @param ip - Client IP address
|
|
46
|
+
* @returns Remaining registrations allowed
|
|
47
|
+
*/
|
|
48
|
+
getRemainingForIP(ip: string): number;
|
|
49
|
+
/**
|
|
50
|
+
* Get remaining global registrations.
|
|
51
|
+
*
|
|
52
|
+
* @returns Remaining global registrations allowed
|
|
53
|
+
*/
|
|
54
|
+
getRemainingGlobal(): number;
|
|
55
|
+
/**
|
|
56
|
+
* Get reset time for an IP's rate limit.
|
|
57
|
+
*
|
|
58
|
+
* @param ip - Client IP address
|
|
59
|
+
* @returns Unix timestamp (ms) when limit resets, or null if not rate limited
|
|
60
|
+
*/
|
|
61
|
+
getResetTimeForIP(ip: string): number | null;
|
|
62
|
+
/**
|
|
63
|
+
* Cleanup old timestamps to prevent memory leaks.
|
|
64
|
+
*
|
|
65
|
+
* Removes entries with no requests in the last window period.
|
|
66
|
+
*/
|
|
67
|
+
cleanup(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Stop cleanup interval (for testing or shutdown).
|
|
70
|
+
*/
|
|
71
|
+
destroy(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Reset all rate limits (for testing).
|
|
74
|
+
*/
|
|
75
|
+
reset(): void;
|
|
76
|
+
}
|
|
3
77
|
/** Trust registry error codes. */
|
|
4
|
-
export type RegistryError = 'NOT_FOUND' | 'ALREADY_REGISTERED' | 'REVOKED' | 'NETWORK_ERROR';
|
|
78
|
+
export type RegistryError = 'NOT_FOUND' | 'ALREADY_REGISTERED' | 'REVOKED' | 'EXPIRED' | 'NETWORK_ERROR' | 'RATE_LIMIT_EXCEEDED';
|
|
5
79
|
/** Metadata stored for a registered DID. */
|
|
6
80
|
export interface RegistryEntry {
|
|
7
81
|
readonly did: string;
|
|
@@ -21,6 +95,14 @@ export interface RegistryEntry {
|
|
|
21
95
|
readonly xchange?: boolean;
|
|
22
96
|
/** Current rotation sequence for this DID (prevents rollback attacks). */
|
|
23
97
|
readonly rotation_sequence: number;
|
|
98
|
+
/** SDK version (semver format, e.g., "1.2.3"). Optional for backward compatibility. */
|
|
99
|
+
readonly sdkVersion?: string;
|
|
100
|
+
/** Minimum supported envelope version. Optional for backward compatibility. */
|
|
101
|
+
readonly minEnvelopeVersion?: number;
|
|
102
|
+
/** Maximum supported envelope version. Optional for backward compatibility. */
|
|
103
|
+
readonly maxEnvelopeVersion?: number;
|
|
104
|
+
/** Unix timestamp (milliseconds) when this entry expires. Undefined = never expires. */
|
|
105
|
+
readonly expiresAt?: number;
|
|
24
106
|
}
|
|
25
107
|
/** Trust event types for real-time registry updates. */
|
|
26
108
|
export interface TrustEvent {
|
|
@@ -40,7 +122,7 @@ export interface TrustEvent {
|
|
|
40
122
|
*/
|
|
41
123
|
export interface TrustRegistry {
|
|
42
124
|
/** Register a DID with its public key, name, and scopes. */
|
|
43
|
-
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[]): Promise<Result<void, RegistryError>>;
|
|
125
|
+
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[], sdkVersion?: string, minEnvelopeVersion?: number, maxEnvelopeVersion?: number, ttlMs?: number, clientIP?: string): Promise<Result<void, RegistryError>>;
|
|
44
126
|
/** Resolve a DID to its raw public key bytes. */
|
|
45
127
|
resolve(did: string): Promise<Result<Uint8Array, RegistryError>>;
|
|
46
128
|
/** Check if a DID has a specific scope permission. */
|
|
@@ -76,19 +158,33 @@ export interface TrustRegistry {
|
|
|
76
158
|
* @param scopes - New scopes (replaces existing)
|
|
77
159
|
*/
|
|
78
160
|
updateScopes?(did: string, scopes: string[]): Promise<Result<void, RegistryError>>;
|
|
161
|
+
/**
|
|
162
|
+
* Remove all expired entries from the registry.
|
|
163
|
+
* Optional method - not all implementations support cleanup.
|
|
164
|
+
*
|
|
165
|
+
* @returns Number of entries removed.
|
|
166
|
+
*/
|
|
167
|
+
cleanup?(): Promise<number>;
|
|
79
168
|
}
|
|
80
169
|
/**
|
|
81
170
|
* In-memory trust registry for development and testing.
|
|
82
171
|
*/
|
|
83
172
|
export declare class MemoryTrustRegistry implements TrustRegistry {
|
|
84
173
|
private readonly entries;
|
|
85
|
-
|
|
174
|
+
private readonly rateLimiter?;
|
|
175
|
+
constructor(opts?: {
|
|
176
|
+
enableRateLimiting?: boolean;
|
|
177
|
+
rateLimiter?: RegistrationRateLimiter;
|
|
178
|
+
});
|
|
179
|
+
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[], sdkVersion?: string, minEnvelopeVersion?: number, maxEnvelopeVersion?: number, ttlMs?: number, clientIP?: string): Promise<Result<void, RegistryError>>;
|
|
86
180
|
resolve(did: string): Promise<Result<Uint8Array, RegistryError>>;
|
|
87
181
|
hasScope(did: string, scope: string): Promise<boolean>;
|
|
88
182
|
hasReceiveScope(did: string, scope: string): Promise<boolean>;
|
|
89
183
|
revoke(did: string): Promise<Result<void, RegistryError>>;
|
|
90
184
|
getEntry(did: string): Promise<Result<RegistryEntry, RegistryError>>;
|
|
91
185
|
updateScopes(did: string, scopes: string[]): Promise<Result<void, RegistryError>>;
|
|
186
|
+
/** Remove all expired entries from the registry. */
|
|
187
|
+
cleanup(): Promise<number>;
|
|
92
188
|
/** Number of entries (for testing). */
|
|
93
189
|
get size(): number;
|
|
94
190
|
}
|
|
@@ -126,7 +222,7 @@ export declare class HttpTrustRegistry implements TrustRegistry {
|
|
|
126
222
|
constructor(opts: HttpTrustRegistryOptions);
|
|
127
223
|
/** Clear all cached entries. Call after registration or revocation. */
|
|
128
224
|
clearCache(): void;
|
|
129
|
-
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[]): Promise<Result<void, RegistryError>>;
|
|
225
|
+
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[], sdkVersion?: string, minEnvelopeVersion?: number, maxEnvelopeVersion?: number, ttlMs?: number, clientIP?: string): Promise<Result<void, RegistryError>>;
|
|
130
226
|
resolve(did: string): Promise<Result<Uint8Array, RegistryError>>;
|
|
131
227
|
hasScope(did: string, scope: string): Promise<boolean>;
|
|
132
228
|
hasReceiveScope(did: string, scope: string): Promise<boolean>;
|
|
@@ -226,13 +322,15 @@ export declare class FileTrustRegistry implements TrustRegistry {
|
|
|
226
322
|
private init;
|
|
227
323
|
/** Append record to JSONL file. */
|
|
228
324
|
private append;
|
|
229
|
-
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[]): Promise<Result<void, RegistryError>>;
|
|
325
|
+
register(did: string, publicKey: Uint8Array, name: string, scopes?: string[], x25519PublicKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaPublicKey?: Uint8Array, xchange?: boolean, receiveScopes?: string[], sdkVersion?: string, minEnvelopeVersion?: number, maxEnvelopeVersion?: number, ttlMs?: number, clientIP?: string): Promise<Result<void, RegistryError>>;
|
|
230
326
|
resolve(did: string): Promise<Result<Uint8Array, RegistryError>>;
|
|
231
327
|
hasScope(did: string, scope: string): Promise<boolean>;
|
|
232
328
|
hasReceiveScope(did: string, scope: string): Promise<boolean>;
|
|
233
329
|
revoke(did: string): Promise<Result<void, RegistryError>>;
|
|
234
330
|
getEntry(did: string): Promise<Result<RegistryEntry, RegistryError>>;
|
|
235
331
|
updateScopes(did: string, scopes: string[]): Promise<Result<void, RegistryError>>;
|
|
332
|
+
/** Remove all expired entries from the registry. */
|
|
333
|
+
cleanup(): Promise<number>;
|
|
236
334
|
/**
|
|
237
335
|
* Rotate a DID to a new public key with rollback protection.
|
|
238
336
|
*
|
|
@@ -282,5 +380,8 @@ export declare function createEnterpriseTrustRegistry(opts: {
|
|
|
282
380
|
mlKemPublicKey?: Uint8Array;
|
|
283
381
|
mlDsaPublicKey?: Uint8Array;
|
|
284
382
|
xchange?: boolean;
|
|
383
|
+
sdkVersion?: string;
|
|
384
|
+
minEnvelopeVersion?: number;
|
|
385
|
+
maxEnvelopeVersion?: number;
|
|
285
386
|
}>;
|
|
286
387
|
}): Promise<TrustRegistry>;
|