@private.me/xbind 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -14
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
- package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
- package/dist-standalone/_deps/shared/cjs/index.js +463 -1
- package/dist-standalone/_deps/shared/cjs/types.js +315 -1
- package/dist-standalone/_deps/shared/errors.js +244 -1
- package/dist-standalone/_deps/shared/index.js +72 -1
- package/dist-standalone/_deps/shared/types.js +86 -1
- 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 +659 -1
- package/dist-standalone/agent-sdk.js +328 -1
- package/dist-standalone/agent.js +1800 -1
- package/dist-standalone/approval.js +193 -1
- package/dist-standalone/async-iterators.js +382 -1
- package/dist-standalone/auth.js +219 -1
- package/dist-standalone/auto-accept.js +229 -1
- package/dist-standalone/backup-config.js +201 -1
- package/dist-standalone/backup.js +326 -1
- package/dist-standalone/batch-operations.js +388 -1
- package/dist-standalone/cancellation.js +477 -1
- package/dist-standalone/checkpoint.js +186 -1
- package/dist-standalone/circuit-breaker.js +468 -1
- package/dist-standalone/cjs/agent-call.js +701 -1
- package/dist-standalone/cjs/agent-sdk.js +332 -1
- package/dist-standalone/cjs/agent.js +1837 -1
- package/dist-standalone/cjs/approval.js +199 -1
- package/dist-standalone/cjs/async-iterators.js +392 -1
- package/dist-standalone/cjs/auth.js +225 -1
- package/dist-standalone/cjs/auto-accept.js +233 -1
- package/dist-standalone/cjs/backup-config.js +207 -1
- package/dist-standalone/cjs/backup.js +330 -1
- package/dist-standalone/cjs/batch-operations.js +397 -1
- package/dist-standalone/cjs/cancellation.js +490 -1
- package/dist-standalone/cjs/checkpoint.js +193 -1
- package/dist-standalone/cjs/circuit-breaker.js +476 -1
- package/dist-standalone/cjs/cli/init.js +492 -1
- package/dist-standalone/cjs/config-validation.js +522 -1
- package/dist-standalone/cjs/connect.js +312 -1
- package/dist-standalone/cjs/connection-pool.js +506 -1
- package/dist-standalone/cjs/correlation-id.js +339 -1
- package/dist-standalone/cjs/crypto-utils.js +176 -1
- package/dist-standalone/cjs/debug-mode.js +534 -1
- package/dist-standalone/cjs/did-document.js +101 -1
- package/dist-standalone/cjs/did-privateme.js +130 -1
- package/dist-standalone/cjs/did-web.js +201 -1
- package/dist-standalone/cjs/discovery.js +462 -1
- package/dist-standalone/cjs/dual-mode.js +251 -1
- package/dist-standalone/cjs/email-templates.js +313 -1
- package/dist-standalone/cjs/email-transport.js +239 -1
- package/dist-standalone/cjs/envelope.js +538 -1
- package/dist-standalone/cjs/errors.js +913 -1
- package/dist-standalone/cjs/event-emitter.js +461 -1
- package/dist-standalone/cjs/gateway-state.js +55 -1
- package/dist-standalone/cjs/gateway-transport.js +120 -1
- package/dist-standalone/cjs/graceful-degradation.js +403 -1
- package/dist-standalone/cjs/guardrails.js +223 -1
- package/dist-standalone/cjs/health-check.js +336 -1
- package/dist-standalone/cjs/http-compat.js +272 -1
- package/dist-standalone/cjs/http-status-map.js +571 -1
- package/dist-standalone/cjs/identity.js +645 -1
- package/dist-standalone/cjs/index.js +406 -1
- package/dist-standalone/cjs/invitation.js +421 -1
- package/dist-standalone/cjs/invite.js +328 -1
- package/dist-standalone/cjs/key-agreement.js +335 -1
- package/dist-standalone/cjs/lazy-init.js +300 -1
- package/dist-standalone/cjs/logger.js +291 -1
- package/dist-standalone/cjs/mdns-discovery.js +202 -1
- package/dist-standalone/cjs/nonce-store.js +80 -1
- package/dist-standalone/cjs/pairing-manager.js +223 -1
- package/dist-standalone/cjs/plugin-system.js +264 -1
- package/dist-standalone/cjs/plugins/logging.js +168 -1
- package/dist-standalone/cjs/plugins/metrics.js +181 -1
- package/dist-standalone/cjs/plugins/validation.js +302 -1
- package/dist-standalone/cjs/policy.js +320 -1
- package/dist-standalone/cjs/progress-callbacks.js +583 -1
- package/dist-standalone/cjs/redis-nonce-store.js +76 -1
- package/dist-standalone/cjs/registry-middleware.js +50 -1
- package/dist-standalone/cjs/retry-strategies.js +544 -1
- package/dist-standalone/cjs/retry-transport.js +102 -1
- package/dist-standalone/cjs/runtime/browser.js +533 -1
- package/dist-standalone/cjs/runtime/edge.js +526 -1
- package/dist-standalone/cjs/runtime/react-native.js +394 -1
- package/dist-standalone/cjs/security-policy.js +245 -1
- package/dist-standalone/cjs/serialization.js +1040 -1
- package/dist-standalone/cjs/split-channel.js +225 -1
- package/dist-standalone/cjs/subscription-proof.js +230 -1
- package/dist-standalone/cjs/succession.js +148 -1
- package/dist-standalone/cjs/timeouts.js +412 -1
- package/dist-standalone/cjs/trace-context.js +424 -1
- package/dist-standalone/cjs/trace-spans.js +495 -1
- package/dist-standalone/cjs/transport.js +63 -1
- package/dist-standalone/cjs/trust-registry.js +991 -1
- package/dist-standalone/cjs/types/error-response.js +56 -1
- package/dist-standalone/cjs/vault-auth.js +178 -1
- package/dist-standalone/cjs/vault-store-loader.js +194 -1
- package/dist-standalone/cjs/verify.js +25 -1
- package/dist-standalone/cjs/version-info.js +543 -1
- package/dist-standalone/cjs/xfetch.js +340 -1
- package/dist-standalone/cli/init.js +455 -1
- package/dist-standalone/cli/setup.js +514 -1
- package/dist-standalone/cli/types.js +27 -1
- package/dist-standalone/cli/xbind.js +148 -1
- package/dist-standalone/config-validation.js +513 -1
- package/dist-standalone/connect.js +274 -1
- package/dist-standalone/connection-pool.js +500 -1
- package/dist-standalone/correlation-id.js +326 -1
- package/dist-standalone/crypto-utils.js +157 -1
- package/dist-standalone/debug-mode.js +510 -1
- package/dist-standalone/did-document.js +96 -1
- package/dist-standalone/did-privateme.js +121 -1
- package/dist-standalone/did-web.js +196 -1
- package/dist-standalone/discovery.js +458 -1
- package/dist-standalone/dual-mode.js +247 -1
- package/dist-standalone/email-templates.js +309 -1
- package/dist-standalone/email-transport.js +232 -1
- package/dist-standalone/envelope.js +525 -1
- package/dist-standalone/errors.js +896 -1
- package/dist-standalone/event-emitter.js +456 -1
- package/dist-standalone/gateway-state.js +51 -1
- package/dist-standalone/gateway-transport.js +116 -1
- package/dist-standalone/graceful-degradation.js +396 -1
- package/dist-standalone/guardrails.js +216 -1
- package/dist-standalone/health-check.js +332 -1
- package/dist-standalone/http-compat.js +267 -1
- package/dist-standalone/http-status-map.js +561 -1
- package/dist-standalone/identity.js +619 -1
- package/dist-standalone/index.js +78 -1
- package/dist-standalone/invitation.js +415 -1
- package/dist-standalone/invite.js +324 -1
- package/dist-standalone/key-agreement.js +325 -1
- package/dist-standalone/lazy-init.js +295 -1
- package/dist-standalone/logger.js +285 -1
- package/dist-standalone/mdns-discovery.js +195 -1
- package/dist-standalone/nonce-store.js +76 -1
- package/dist-standalone/pairing-manager.js +219 -1
- package/dist-standalone/plugin-system.js +257 -1
- package/dist-standalone/plugins/logging.js +163 -1
- package/dist-standalone/plugins/metrics.js +176 -1
- package/dist-standalone/plugins/validation.js +297 -1
- package/dist-standalone/policy.js +315 -1
- package/dist-standalone/progress-callbacks.js +576 -1
- package/dist-standalone/redis-nonce-store.js +72 -1
- package/dist-standalone/registry-middleware.js +47 -1
- package/dist-standalone/retry-strategies.js +534 -1
- package/dist-standalone/retry-transport.js +98 -1
- package/dist-standalone/runtime/browser.js +516 -1
- package/dist-standalone/runtime/edge.js +511 -1
- package/dist-standalone/runtime/react-native.js +383 -1
- package/dist-standalone/security-policy.js +239 -1
- package/dist-standalone/serialization.js +1031 -1
- package/dist-standalone/split-channel.js +219 -1
- package/dist-standalone/subscription-proof.js +224 -1
- package/dist-standalone/succession.js +142 -1
- package/dist-standalone/timeouts.js +398 -1
- package/dist-standalone/trace-context.js +414 -1
- package/dist-standalone/trace-spans.js +488 -1
- package/dist-standalone/transport.js +59 -1
- package/dist-standalone/trust-registry.js +950 -1
- package/dist-standalone/types/error-response.js +52 -1
- package/dist-standalone/vault-auth.js +174 -1
- package/dist-standalone/vault-store-loader.js +187 -1
- package/dist-standalone/verify.js +16 -1
- package/dist-standalone/version-info.js +530 -1
- package/dist-standalone/xfetch.js +335 -1
- package/package.json +4 -13
- package/share1.dat +0 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
- package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
- package/dist-standalone/_deps/shared/cjs/package.json +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
- package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
- package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
- package/dist-standalone/cjs/package.json +0 -3
- package/dist-standalone/package.json +0 -10
|
@@ -1 +1,510 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module debug-mode
|
|
3
|
+
* Debug mode for enhanced developer experience with verbose logging and state inspection
|
|
4
|
+
*
|
|
5
|
+
* Provides comprehensive debugging capabilities including:
|
|
6
|
+
* - Verbose logging of all operations
|
|
7
|
+
* - Internal state dumping and inspection
|
|
8
|
+
* - Network request/response logging
|
|
9
|
+
* - Crypto operation tracing
|
|
10
|
+
* - Performance profiling and timing
|
|
11
|
+
* - Memory usage tracking
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { enableDebugMode, dumpState, createDebugLogger } from '@private.me/xbind/debug-mode';
|
|
16
|
+
*
|
|
17
|
+
* // Enable debug mode globally
|
|
18
|
+
* enableDebugMode({ verbose: true, traceNetwork: true });
|
|
19
|
+
*
|
|
20
|
+
* // Create debug logger for component
|
|
21
|
+
* const debug = createDebugLogger('agent');
|
|
22
|
+
* debug.trace('Operation starting', { did: 'did:key:...' });
|
|
23
|
+
*
|
|
24
|
+
* // Dump internal state
|
|
25
|
+
* const state = dumpState(agent);
|
|
26
|
+
* console.log(state);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { createLogger, LogLevel } from './logger.js';
|
|
30
|
+
/**
|
|
31
|
+
* Global debug mode state
|
|
32
|
+
*/
|
|
33
|
+
class DebugModeState {
|
|
34
|
+
enabled = false;
|
|
35
|
+
options = {};
|
|
36
|
+
measurements = [];
|
|
37
|
+
networkTraces = [];
|
|
38
|
+
cryptoTraces = [];
|
|
39
|
+
stateSnapshots = [];
|
|
40
|
+
activeTimers = new Map();
|
|
41
|
+
}
|
|
42
|
+
const globalDebugState = new DebugModeState();
|
|
43
|
+
/**
|
|
44
|
+
* Enable debug mode with optional configuration
|
|
45
|
+
*
|
|
46
|
+
* @param options - Debug mode options
|
|
47
|
+
*/
|
|
48
|
+
export function enableDebugMode(options = {}) {
|
|
49
|
+
globalDebugState.enabled = true;
|
|
50
|
+
globalDebugState.options = {
|
|
51
|
+
verbose: options.verbose ?? false,
|
|
52
|
+
traceNetwork: options.traceNetwork ?? false,
|
|
53
|
+
traceCrypto: options.traceCrypto ?? false,
|
|
54
|
+
profile: options.profile ?? false,
|
|
55
|
+
trackMemory: options.trackMemory ?? false,
|
|
56
|
+
traceState: options.traceState ?? false,
|
|
57
|
+
output: options.output ?? console.log,
|
|
58
|
+
filters: options.filters,
|
|
59
|
+
};
|
|
60
|
+
const logger = createLogger('debug-mode');
|
|
61
|
+
logger.setLevel(LogLevel.DEBUG);
|
|
62
|
+
logger.info('Debug mode enabled', { options: globalDebugState.options });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Disable debug mode and clear collected data
|
|
66
|
+
*/
|
|
67
|
+
export function disableDebugMode() {
|
|
68
|
+
globalDebugState.enabled = false;
|
|
69
|
+
globalDebugState.measurements = [];
|
|
70
|
+
globalDebugState.networkTraces = [];
|
|
71
|
+
globalDebugState.cryptoTraces = [];
|
|
72
|
+
globalDebugState.stateSnapshots = [];
|
|
73
|
+
globalDebugState.activeTimers.clear();
|
|
74
|
+
const logger = createLogger('debug-mode');
|
|
75
|
+
logger.info('Debug mode disabled');
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if debug mode is enabled
|
|
79
|
+
*/
|
|
80
|
+
export function isDebugEnabled() {
|
|
81
|
+
return globalDebugState.enabled;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get current debug mode options
|
|
85
|
+
*/
|
|
86
|
+
export function getDebugOptions() {
|
|
87
|
+
return { ...globalDebugState.options };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a debug logger for a specific component
|
|
91
|
+
*
|
|
92
|
+
* @param component - Component name
|
|
93
|
+
* @returns Logger instance with debug capabilities
|
|
94
|
+
*/
|
|
95
|
+
export function createDebugLogger(component) {
|
|
96
|
+
const logger = createLogger(component);
|
|
97
|
+
if (globalDebugState.enabled && globalDebugState.options.verbose) {
|
|
98
|
+
logger.setLevel(LogLevel.DEBUG);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
...logger,
|
|
102
|
+
trace(message, context) {
|
|
103
|
+
if (!globalDebugState.enabled || !globalDebugState.options.verbose) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// Apply filters if configured
|
|
107
|
+
if (globalDebugState.options.filters) {
|
|
108
|
+
const { include, exclude } = globalDebugState.options.filters;
|
|
109
|
+
if (include && !include.some((pattern) => pattern.test(message))) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (exclude && exclude.some((pattern) => pattern.test(message))) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
logger.debug(message, context);
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Start performance measurement for an operation
|
|
122
|
+
*
|
|
123
|
+
* @param operation - Operation name
|
|
124
|
+
* @param context - Optional context
|
|
125
|
+
*/
|
|
126
|
+
export function startProfiling(operation, context) {
|
|
127
|
+
if (!globalDebugState.enabled || !globalDebugState.options.profile) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const startTime = performance.now();
|
|
131
|
+
globalDebugState.activeTimers.set(operation, { startTime, context });
|
|
132
|
+
const logger = createDebugLogger('profiler');
|
|
133
|
+
logger.trace(`[PROFILE] Starting: ${operation}`, context);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* End performance measurement and record result
|
|
137
|
+
*
|
|
138
|
+
* @param operation - Operation name
|
|
139
|
+
* @param context - Optional context (overrides context from startProfiling if provided)
|
|
140
|
+
*/
|
|
141
|
+
export function endProfiling(operation, context) {
|
|
142
|
+
if (!globalDebugState.enabled || !globalDebugState.options.profile) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const timerData = globalDebugState.activeTimers.get(operation);
|
|
146
|
+
if (!timerData) {
|
|
147
|
+
const logger = createDebugLogger('profiler');
|
|
148
|
+
logger.warn(`[PROFILE] No start time found for: ${operation}`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const endTime = performance.now();
|
|
152
|
+
const duration = endTime - timerData.startTime;
|
|
153
|
+
// Use context from endProfiling if provided, otherwise use context from startProfiling
|
|
154
|
+
const finalContext = context ?? timerData.context;
|
|
155
|
+
let memoryBefore;
|
|
156
|
+
let memoryAfter;
|
|
157
|
+
let memoryDelta;
|
|
158
|
+
if (globalDebugState.options.trackMemory && typeof process !== 'undefined' && process.memoryUsage) {
|
|
159
|
+
const mem = process.memoryUsage();
|
|
160
|
+
memoryAfter = mem.heapUsed;
|
|
161
|
+
// Estimate (not precise without tracking before)
|
|
162
|
+
memoryBefore = memoryAfter;
|
|
163
|
+
memoryDelta = 0;
|
|
164
|
+
}
|
|
165
|
+
const measurement = {
|
|
166
|
+
operation,
|
|
167
|
+
startTime: timerData.startTime,
|
|
168
|
+
endTime,
|
|
169
|
+
duration,
|
|
170
|
+
memoryBefore,
|
|
171
|
+
memoryAfter,
|
|
172
|
+
memoryDelta,
|
|
173
|
+
context: finalContext,
|
|
174
|
+
};
|
|
175
|
+
globalDebugState.measurements.push(measurement);
|
|
176
|
+
globalDebugState.activeTimers.delete(operation);
|
|
177
|
+
const logger = createDebugLogger('profiler');
|
|
178
|
+
logger.trace(`[PROFILE] Completed: ${operation} (${duration.toFixed(2)}ms)`, {
|
|
179
|
+
duration,
|
|
180
|
+
memoryDelta,
|
|
181
|
+
...context,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get all performance measurements
|
|
186
|
+
*/
|
|
187
|
+
export function getPerformanceMeasurements() {
|
|
188
|
+
return [...globalDebugState.measurements];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Clear performance measurements
|
|
192
|
+
*/
|
|
193
|
+
export function clearPerformanceMeasurements() {
|
|
194
|
+
globalDebugState.measurements = [];
|
|
195
|
+
globalDebugState.activeTimers.clear();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Log network request start
|
|
199
|
+
*
|
|
200
|
+
* @param id - Request ID
|
|
201
|
+
* @param method - HTTP method
|
|
202
|
+
* @param url - URL
|
|
203
|
+
* @param headers - Request headers
|
|
204
|
+
* @param body - Request body
|
|
205
|
+
*/
|
|
206
|
+
export function traceNetworkRequest(id, method, url, headers, body) {
|
|
207
|
+
if (!globalDebugState.enabled || !globalDebugState.options.traceNetwork) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const trace = {
|
|
211
|
+
id,
|
|
212
|
+
method,
|
|
213
|
+
url,
|
|
214
|
+
requestHeaders: redactHeaders(headers),
|
|
215
|
+
requestBody: truncateBody(body),
|
|
216
|
+
startTime: performance.now(),
|
|
217
|
+
};
|
|
218
|
+
globalDebugState.networkTraces.push(trace);
|
|
219
|
+
const logger = createDebugLogger('network');
|
|
220
|
+
logger.trace(`[NETWORK] ${method} ${url}`, {
|
|
221
|
+
requestId: id,
|
|
222
|
+
headers: trace.requestHeaders,
|
|
223
|
+
bodyLength: body?.length ?? 0,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Log network response
|
|
228
|
+
*
|
|
229
|
+
* @param id - Request ID
|
|
230
|
+
* @param status - HTTP status code
|
|
231
|
+
* @param headers - Response headers
|
|
232
|
+
* @param body - Response body
|
|
233
|
+
* @param error - Error (if failed)
|
|
234
|
+
*/
|
|
235
|
+
export function traceNetworkResponse(id, status, headers, body, error) {
|
|
236
|
+
if (!globalDebugState.enabled || !globalDebugState.options.traceNetwork) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const trace = globalDebugState.networkTraces.find((t) => t.id === id);
|
|
240
|
+
if (!trace) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
trace.endTime = performance.now();
|
|
244
|
+
trace.duration = trace.endTime - trace.startTime;
|
|
245
|
+
trace.status = status;
|
|
246
|
+
trace.responseHeaders = headers ? redactHeaders(headers) : undefined;
|
|
247
|
+
trace.responseBody = truncateBody(body);
|
|
248
|
+
trace.error = error;
|
|
249
|
+
const logger = createDebugLogger('network');
|
|
250
|
+
logger.trace(`[NETWORK] Response ${status ?? 'ERROR'} (${trace.duration.toFixed(2)}ms)`, {
|
|
251
|
+
requestId: id,
|
|
252
|
+
status,
|
|
253
|
+
duration: trace.duration,
|
|
254
|
+
error,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get all network traces
|
|
259
|
+
*/
|
|
260
|
+
export function getNetworkTraces() {
|
|
261
|
+
return [...globalDebugState.networkTraces];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Clear network traces
|
|
265
|
+
*/
|
|
266
|
+
export function clearNetworkTraces() {
|
|
267
|
+
globalDebugState.networkTraces = [];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Log crypto operation
|
|
271
|
+
*
|
|
272
|
+
* @param operation - Operation type
|
|
273
|
+
* @param algorithm - Algorithm name
|
|
274
|
+
* @param inputSize - Input size (bytes)
|
|
275
|
+
* @param outputSize - Output size (bytes)
|
|
276
|
+
* @param duration - Duration (ms)
|
|
277
|
+
* @param success - Success flag
|
|
278
|
+
* @param error - Error message (if failed)
|
|
279
|
+
*/
|
|
280
|
+
export function traceCryptoOperation(operation, algorithm, inputSize, outputSize, duration, success, error) {
|
|
281
|
+
if (!globalDebugState.enabled || !globalDebugState.options.traceCrypto) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const trace = {
|
|
285
|
+
operation,
|
|
286
|
+
algorithm,
|
|
287
|
+
inputSize,
|
|
288
|
+
outputSize,
|
|
289
|
+
duration: duration ?? 0,
|
|
290
|
+
success: success ?? true,
|
|
291
|
+
error,
|
|
292
|
+
timestamp: Date.now(),
|
|
293
|
+
};
|
|
294
|
+
globalDebugState.cryptoTraces.push(trace);
|
|
295
|
+
const logger = createDebugLogger('crypto');
|
|
296
|
+
logger.trace(`[CRYPTO] ${operation} (${algorithm})`, {
|
|
297
|
+
inputSize,
|
|
298
|
+
outputSize,
|
|
299
|
+
duration,
|
|
300
|
+
success,
|
|
301
|
+
error,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get all crypto traces
|
|
306
|
+
*/
|
|
307
|
+
export function getCryptoTraces() {
|
|
308
|
+
return [...globalDebugState.cryptoTraces];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Clear crypto traces
|
|
312
|
+
*/
|
|
313
|
+
export function clearCryptoTraces() {
|
|
314
|
+
globalDebugState.cryptoTraces = [];
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Dump internal state of an agent
|
|
318
|
+
*
|
|
319
|
+
* @param agent - Agent instance
|
|
320
|
+
* @returns State snapshot
|
|
321
|
+
*/
|
|
322
|
+
export function dumpState(agent) {
|
|
323
|
+
const snapshot = {
|
|
324
|
+
did: agent.did,
|
|
325
|
+
identityMode: agent.identityMode ?? 'persistent',
|
|
326
|
+
registered: agent.registered ?? false,
|
|
327
|
+
registryUrl: agent.registry?.url,
|
|
328
|
+
nonceStoreType: agent.nonceStore?.constructor?.name ?? 'unknown',
|
|
329
|
+
nonceCount: agent.nonceStore?.size ?? 0,
|
|
330
|
+
transportType: agent.transport?.constructor?.name ?? 'unknown',
|
|
331
|
+
securityPolicy: {
|
|
332
|
+
level: agent.securityPolicy?.level ?? 'unknown',
|
|
333
|
+
replayWindow: agent.securityPolicy?.replayWindow ?? 0,
|
|
334
|
+
timestampTolerance: agent.securityPolicy?.timestampTolerance ?? 0,
|
|
335
|
+
},
|
|
336
|
+
postQuantum: agent.postQuantum ?? false,
|
|
337
|
+
memoryUsage: typeof process !== 'undefined' && process.memoryUsage
|
|
338
|
+
? process.memoryUsage().heapUsed
|
|
339
|
+
: undefined,
|
|
340
|
+
timestamp: Date.now(),
|
|
341
|
+
};
|
|
342
|
+
if (globalDebugState.enabled && globalDebugState.options.traceState) {
|
|
343
|
+
globalDebugState.stateSnapshots.push(snapshot);
|
|
344
|
+
}
|
|
345
|
+
const logger = createDebugLogger('state');
|
|
346
|
+
logger.trace('[STATE] Agent snapshot', snapshot);
|
|
347
|
+
return snapshot;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get all state snapshots
|
|
351
|
+
*/
|
|
352
|
+
export function getStateSnapshots() {
|
|
353
|
+
return [...globalDebugState.stateSnapshots];
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Clear state snapshots
|
|
357
|
+
*/
|
|
358
|
+
export function clearStateSnapshots() {
|
|
359
|
+
globalDebugState.stateSnapshots = [];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Export all debug data as JSON
|
|
363
|
+
*
|
|
364
|
+
* @returns JSON string with all debug data
|
|
365
|
+
*/
|
|
366
|
+
export function exportDebugData() {
|
|
367
|
+
const data = {
|
|
368
|
+
enabled: globalDebugState.enabled,
|
|
369
|
+
options: globalDebugState.options,
|
|
370
|
+
measurements: globalDebugState.measurements,
|
|
371
|
+
networkTraces: globalDebugState.networkTraces,
|
|
372
|
+
cryptoTraces: globalDebugState.cryptoTraces,
|
|
373
|
+
stateSnapshots: globalDebugState.stateSnapshots,
|
|
374
|
+
exportedAt: new Date().toISOString(),
|
|
375
|
+
};
|
|
376
|
+
return JSON.stringify(data, null, 2);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Clear all debug data
|
|
380
|
+
*/
|
|
381
|
+
export function clearAllDebugData() {
|
|
382
|
+
clearPerformanceMeasurements();
|
|
383
|
+
clearNetworkTraces();
|
|
384
|
+
clearCryptoTraces();
|
|
385
|
+
clearStateSnapshots();
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Redact sensitive headers
|
|
389
|
+
*/
|
|
390
|
+
function redactHeaders(headers) {
|
|
391
|
+
const redacted = {};
|
|
392
|
+
const sensitiveHeaders = new Set([
|
|
393
|
+
'authorization',
|
|
394
|
+
'cookie',
|
|
395
|
+
'set-cookie',
|
|
396
|
+
'x-api-key',
|
|
397
|
+
'x-auth-token',
|
|
398
|
+
]);
|
|
399
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
400
|
+
const lowerKey = key.toLowerCase();
|
|
401
|
+
if (sensitiveHeaders.has(lowerKey)) {
|
|
402
|
+
redacted[key] = '[REDACTED]';
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
redacted[key] = value;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return redacted;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Truncate body to reasonable size for logging
|
|
412
|
+
*/
|
|
413
|
+
function truncateBody(body) {
|
|
414
|
+
if (!body)
|
|
415
|
+
return undefined;
|
|
416
|
+
const maxLength = 1000;
|
|
417
|
+
if (body.length <= maxLength) {
|
|
418
|
+
return body;
|
|
419
|
+
}
|
|
420
|
+
return body.substring(0, maxLength) + `... (${body.length - maxLength} more bytes)`;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Generate debug report
|
|
424
|
+
*
|
|
425
|
+
* @returns Human-readable debug report
|
|
426
|
+
*/
|
|
427
|
+
export function generateDebugReport() {
|
|
428
|
+
const lines = [];
|
|
429
|
+
lines.push('='.repeat(80));
|
|
430
|
+
lines.push('xBind Debug Report');
|
|
431
|
+
lines.push('='.repeat(80));
|
|
432
|
+
lines.push('');
|
|
433
|
+
lines.push(`Generated: ${new Date().toISOString()}`);
|
|
434
|
+
lines.push(`Debug Mode: ${globalDebugState.enabled ? 'ENABLED' : 'DISABLED'}`);
|
|
435
|
+
lines.push('');
|
|
436
|
+
if (globalDebugState.measurements.length > 0) {
|
|
437
|
+
lines.push('Performance Measurements:');
|
|
438
|
+
lines.push('-'.repeat(80));
|
|
439
|
+
for (const m of globalDebugState.measurements) {
|
|
440
|
+
lines.push(` ${m.operation}: ${m.duration.toFixed(2)}ms`);
|
|
441
|
+
if (m.memoryDelta !== undefined) {
|
|
442
|
+
lines.push(` Memory: ${formatBytes(m.memoryDelta)}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
lines.push('');
|
|
446
|
+
}
|
|
447
|
+
if (globalDebugState.networkTraces.length > 0) {
|
|
448
|
+
lines.push('Network Traces:');
|
|
449
|
+
lines.push('-'.repeat(80));
|
|
450
|
+
for (const n of globalDebugState.networkTraces) {
|
|
451
|
+
lines.push(` ${n.method} ${n.url}`);
|
|
452
|
+
if (n.status) {
|
|
453
|
+
lines.push(` Status: ${n.status}`);
|
|
454
|
+
}
|
|
455
|
+
if (n.duration) {
|
|
456
|
+
lines.push(` Duration: ${n.duration.toFixed(2)}ms`);
|
|
457
|
+
}
|
|
458
|
+
if (n.error) {
|
|
459
|
+
lines.push(` Error: ${n.error}`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
lines.push('');
|
|
463
|
+
}
|
|
464
|
+
if (globalDebugState.cryptoTraces.length > 0) {
|
|
465
|
+
lines.push('Crypto Operations:');
|
|
466
|
+
lines.push('-'.repeat(80));
|
|
467
|
+
for (const c of globalDebugState.cryptoTraces) {
|
|
468
|
+
lines.push(` ${c.operation} (${c.algorithm})`);
|
|
469
|
+
lines.push(` Input: ${formatBytes(c.inputSize)}`);
|
|
470
|
+
if (c.outputSize) {
|
|
471
|
+
lines.push(` Output: ${formatBytes(c.outputSize)}`);
|
|
472
|
+
}
|
|
473
|
+
lines.push(` Duration: ${c.duration.toFixed(2)}ms`);
|
|
474
|
+
lines.push(` Success: ${c.success}`);
|
|
475
|
+
if (c.error) {
|
|
476
|
+
lines.push(` Error: ${c.error}`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
lines.push('');
|
|
480
|
+
}
|
|
481
|
+
if (globalDebugState.stateSnapshots.length > 0) {
|
|
482
|
+
lines.push('State Snapshots:');
|
|
483
|
+
lines.push('-'.repeat(80));
|
|
484
|
+
const latest = globalDebugState.stateSnapshots[globalDebugState.stateSnapshots.length - 1];
|
|
485
|
+
if (latest) {
|
|
486
|
+
lines.push(` DID: ${latest.did}`);
|
|
487
|
+
lines.push(` Mode: ${latest.identityMode}`);
|
|
488
|
+
lines.push(` Registered: ${latest.registered}`);
|
|
489
|
+
lines.push(` Post-Quantum: ${latest.postQuantum}`);
|
|
490
|
+
lines.push(` Nonce Count: ${latest.nonceCount}`);
|
|
491
|
+
if (latest.memoryUsage) {
|
|
492
|
+
lines.push(` Memory Usage: ${formatBytes(latest.memoryUsage)}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
lines.push('');
|
|
496
|
+
}
|
|
497
|
+
lines.push('='.repeat(80));
|
|
498
|
+
return lines.join('\n');
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Format bytes as human-readable string
|
|
502
|
+
*/
|
|
503
|
+
function formatBytes(bytes) {
|
|
504
|
+
if (bytes === 0)
|
|
505
|
+
return '0 B';
|
|
506
|
+
const units = ['B', 'KB', 'MB', 'GB'];
|
|
507
|
+
const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(1024));
|
|
508
|
+
const value = bytes / Math.pow(1024, i);
|
|
509
|
+
return `${value.toFixed(2)} ${units[i]}`;
|
|
510
|
+
}
|
|
@@ -1 +1,96 @@
|
|
|
1
|
-
import{ok,err}from"./_deps/shared/index.js";
|
|
1
|
+
import { ok, err } from"./_deps/shared/index.js";
|
|
2
|
+
import { toBase64 } from './crypto-utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a DID document for a given DID.
|
|
5
|
+
*
|
|
6
|
+
* Includes service endpoints that advertise PRIVATE.ME/xBind.
|
|
7
|
+
* Both did:key and did:privateme DIDs generate the same service endpoints.
|
|
8
|
+
*
|
|
9
|
+
* @param did - The DID (did:key:z... or did:privateme:z...)
|
|
10
|
+
* @param rawPublicKey - The 32-byte Ed25519 public key
|
|
11
|
+
* @param name - Optional name for the identity
|
|
12
|
+
* @returns DID document with service endpoints
|
|
13
|
+
*/
|
|
14
|
+
export function generateDidDocument(did, rawPublicKey, name) {
|
|
15
|
+
if (!did.startsWith('did:key:') && !did.startsWith('did:privateme:')) {
|
|
16
|
+
return err('INVALID_DID_FORMAT');
|
|
17
|
+
}
|
|
18
|
+
// Convert public key to base64 for inclusion in document
|
|
19
|
+
const publicKeyBase64 = toBase64(rawPublicKey);
|
|
20
|
+
const document = {
|
|
21
|
+
'@context': [
|
|
22
|
+
'https://www.w3.org/ns/did/v1',
|
|
23
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
24
|
+
],
|
|
25
|
+
id: did,
|
|
26
|
+
publicKey: [
|
|
27
|
+
{
|
|
28
|
+
id: `${did}#key-1`,
|
|
29
|
+
type: 'Ed25519VerificationKey2020',
|
|
30
|
+
controller: did,
|
|
31
|
+
publicKeyBase64,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
authentication: [`${did}#key-1`],
|
|
35
|
+
assertionMethod: [`${did}#key-1`],
|
|
36
|
+
keyAgreement: [`${did}#key-1`],
|
|
37
|
+
service: [
|
|
38
|
+
{
|
|
39
|
+
id: `${did}#identity-provider`,
|
|
40
|
+
type: 'IdentityProvider',
|
|
41
|
+
serviceEndpoint: 'https://private.me',
|
|
42
|
+
description: 'PRIVATE.ME xBind Agent - M2M identity authentication',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: `${did}#documentation`,
|
|
46
|
+
type: 'Documentation',
|
|
47
|
+
serviceEndpoint: 'https://private.me/docs/xbind.html',
|
|
48
|
+
description: 'Learn more about PRIVATE.ME/xBind protocol',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
...(name ? { name } : {}),
|
|
52
|
+
};
|
|
53
|
+
return ok(document);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a DID to its document (simulated).
|
|
57
|
+
*
|
|
58
|
+
* In a production system, this would query a DID resolver.
|
|
59
|
+
* For now, this generates a synthetic document based on the DID.
|
|
60
|
+
*
|
|
61
|
+
* @param did - The DID to resolve
|
|
62
|
+
* @param rawPublicKey - The 32-byte Ed25519 public key
|
|
63
|
+
* @returns DID document or error
|
|
64
|
+
*/
|
|
65
|
+
export async function resolveDid(did, rawPublicKey) {
|
|
66
|
+
// In a production system, this would make an HTTP request to a DID resolver
|
|
67
|
+
// For now, generate a synthetic document
|
|
68
|
+
return generateDidDocument(did, rawPublicKey);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Extract service endpoints from a DID document.
|
|
72
|
+
*
|
|
73
|
+
* Filters for PRIVATE.ME service endpoints to provide discovery information.
|
|
74
|
+
*
|
|
75
|
+
* @param document - The DID document
|
|
76
|
+
* @returns Array of service endpoints advertising PRIVATE.ME services
|
|
77
|
+
*/
|
|
78
|
+
export function getServiceEndpoints(document) {
|
|
79
|
+
if (!document.service)
|
|
80
|
+
return [];
|
|
81
|
+
return document.service
|
|
82
|
+
.filter((svc) => {
|
|
83
|
+
const endpoint = typeof svc.serviceEndpoint === 'string' ? svc.serviceEndpoint : '';
|
|
84
|
+
return (endpoint.includes('private.me') ||
|
|
85
|
+
svc.type.includes('PRIVATE.ME') ||
|
|
86
|
+
svc.type === 'IdentityProvider' ||
|
|
87
|
+
svc.type === 'Documentation');
|
|
88
|
+
})
|
|
89
|
+
.map((svc) => ({
|
|
90
|
+
type: svc.type,
|
|
91
|
+
endpoint: typeof svc.serviceEndpoint === 'string'
|
|
92
|
+
? svc.serviceEndpoint
|
|
93
|
+
: JSON.stringify(svc.serviceEndpoint),
|
|
94
|
+
description: svc.description,
|
|
95
|
+
}));
|
|
96
|
+
}
|