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