@private.me/xbind 1.3.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
- package/dist-standalone/_deps/shared/cjs/index.js +1 -496
- package/dist-standalone/_deps/shared/cjs/types.js +1 -317
- package/dist-standalone/_deps/shared/errors.js +1 -255
- package/dist-standalone/_deps/shared/index.js +1 -74
- package/dist-standalone/_deps/shared/types.js +1 -90
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +1 -642
- package/dist-standalone/agent-sdk.js +1 -328
- package/dist-standalone/agent.d.ts +95 -5
- package/dist-standalone/agent.js +1 -1545
- package/dist-standalone/approval.js +1 -193
- package/dist-standalone/async-iterators.d.ts +275 -0
- package/dist-standalone/async-iterators.js +1 -0
- package/dist-standalone/auth.js +1 -219
- package/dist-standalone/auto-accept.js +1 -229
- package/dist-standalone/backup-config.js +1 -201
- package/dist-standalone/backup.d.ts +114 -0
- package/dist-standalone/backup.js +1 -0
- package/dist-standalone/batch-operations.d.ts +297 -0
- package/dist-standalone/batch-operations.js +1 -0
- package/dist-standalone/cancellation.d.ts +301 -0
- package/dist-standalone/cancellation.js +1 -0
- package/dist-standalone/checkpoint.js +1 -186
- package/dist-standalone/circuit-breaker.d.ts +351 -0
- package/dist-standalone/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/agent-call.js +1 -651
- package/dist-standalone/cjs/agent-sdk.js +1 -332
- package/dist-standalone/cjs/agent.js +1 -1582
- package/dist-standalone/cjs/approval.js +1 -199
- package/dist-standalone/cjs/async-iterators.js +1 -0
- package/dist-standalone/cjs/auth.js +1 -225
- package/dist-standalone/cjs/auto-accept.js +1 -233
- package/dist-standalone/cjs/backup-config.js +1 -207
- package/dist-standalone/cjs/backup.js +1 -0
- package/dist-standalone/cjs/batch-operations.js +1 -0
- package/dist-standalone/cjs/cancellation.js +1 -0
- package/dist-standalone/cjs/checkpoint.js +1 -193
- package/dist-standalone/cjs/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/cli/init.js +1 -486
- package/dist-standalone/cjs/config-validation.js +1 -0
- package/dist-standalone/cjs/connect.js +1 -312
- package/dist-standalone/cjs/connection-pool.js +1 -0
- package/dist-standalone/cjs/correlation-id.js +1 -339
- package/dist-standalone/cjs/crypto-utils.js +1 -0
- package/dist-standalone/cjs/debug-mode.js +1 -0
- package/dist-standalone/cjs/did-document.js +1 -101
- package/dist-standalone/cjs/did-privateme.js +1 -130
- package/dist-standalone/cjs/did-web.js +1 -201
- package/dist-standalone/cjs/discovery.js +1 -462
- package/dist-standalone/cjs/dual-mode.js +1 -251
- package/dist-standalone/cjs/email-templates.js +1 -313
- package/dist-standalone/cjs/email-transport.js +1 -239
- package/dist-standalone/cjs/envelope.js +1 -510
- package/dist-standalone/cjs/errors.js +1 -826
- package/dist-standalone/cjs/event-emitter.js +1 -0
- package/dist-standalone/cjs/gateway-state.js +1 -55
- package/dist-standalone/cjs/gateway-transport.js +1 -120
- package/dist-standalone/cjs/graceful-degradation.js +1 -0
- package/dist-standalone/cjs/guardrails.js +1 -223
- package/dist-standalone/cjs/health-check.js +1 -0
- package/dist-standalone/cjs/http-compat.js +1 -272
- package/dist-standalone/cjs/http-status-map.js +1 -571
- package/dist-standalone/cjs/identity.js +1 -540
- package/dist-standalone/cjs/index.js +1 -237
- package/dist-standalone/cjs/invitation.js +1 -421
- package/dist-standalone/cjs/invite.js +1 -328
- package/dist-standalone/cjs/key-agreement.js +1 -246
- package/dist-standalone/cjs/lazy-init.js +1 -300
- package/dist-standalone/cjs/logger.js +1 -0
- package/dist-standalone/cjs/mdns-discovery.js +1 -202
- package/dist-standalone/cjs/nonce-store.js +1 -66
- package/dist-standalone/cjs/pairing-manager.js +1 -223
- package/dist-standalone/cjs/plugin-system.js +1 -0
- package/dist-standalone/cjs/plugins/logging.js +1 -0
- package/dist-standalone/cjs/plugins/metrics.js +1 -0
- package/dist-standalone/cjs/plugins/validation.js +1 -0
- package/dist-standalone/cjs/policy.js +1 -320
- package/dist-standalone/cjs/progress-callbacks.js +1 -0
- package/dist-standalone/cjs/redis-nonce-store.js +1 -76
- package/dist-standalone/cjs/registry-middleware.js +1 -50
- package/dist-standalone/cjs/retry-strategies.js +1 -0
- package/dist-standalone/cjs/retry-transport.js +1 -102
- package/dist-standalone/cjs/runtime/browser.js +1 -0
- package/dist-standalone/cjs/runtime/edge.js +1 -0
- package/dist-standalone/cjs/runtime/react-native.js +1 -0
- package/dist-standalone/cjs/security-policy.js +1 -245
- package/dist-standalone/cjs/serialization.js +1 -0
- package/dist-standalone/cjs/split-channel.js +1 -177
- package/dist-standalone/cjs/subscription-proof.js +1 -230
- package/dist-standalone/cjs/succession.js +1 -148
- package/dist-standalone/cjs/timeouts.js +1 -0
- package/dist-standalone/cjs/trace-context.js +1 -0
- package/dist-standalone/cjs/trace-spans.js +1 -0
- package/dist-standalone/cjs/transport.js +1 -63
- package/dist-standalone/cjs/trust-registry.js +1 -742
- package/dist-standalone/cjs/types/error-response.js +1 -56
- package/dist-standalone/cjs/vault-auth.js +1 -0
- package/dist-standalone/cjs/vault-store-loader.js +1 -0
- package/dist-standalone/cjs/verify.js +1 -25
- package/dist-standalone/cjs/version-info.js +1 -0
- package/dist-standalone/cjs/xfetch.js +1 -252
- package/dist-standalone/cli/init.js +1 -449
- package/dist-standalone/cli/setup.js +1 -514
- package/dist-standalone/cli/types.js +1 -27
- package/dist-standalone/cli/xbind.js +1 -148
- package/dist-standalone/config-validation.d.ts +185 -0
- package/dist-standalone/config-validation.js +1 -0
- package/dist-standalone/connect.js +1 -274
- package/dist-standalone/connection-pool.d.ts +251 -0
- package/dist-standalone/connection-pool.js +1 -0
- package/dist-standalone/correlation-id.js +1 -326
- package/dist-standalone/crypto-utils.d.ts +60 -0
- package/dist-standalone/crypto-utils.js +1 -0
- package/dist-standalone/debug-mode.d.ts +286 -0
- package/dist-standalone/debug-mode.js +1 -0
- package/dist-standalone/did-document.js +1 -96
- package/dist-standalone/did-privateme.js +1 -121
- package/dist-standalone/did-web.js +1 -196
- package/dist-standalone/discovery.js +1 -458
- package/dist-standalone/dual-mode.js +1 -247
- package/dist-standalone/email-templates.js +1 -309
- package/dist-standalone/email-transport.js +1 -232
- package/dist-standalone/envelope.d.ts +29 -1
- package/dist-standalone/envelope.js +1 -497
- package/dist-standalone/errors.d.ts +10 -0
- package/dist-standalone/errors.js +1 -811
- package/dist-standalone/event-emitter.d.ts +395 -0
- package/dist-standalone/event-emitter.js +1 -0
- package/dist-standalone/gateway-state.js +1 -51
- package/dist-standalone/gateway-transport.js +1 -116
- package/dist-standalone/graceful-degradation.d.ts +246 -0
- package/dist-standalone/graceful-degradation.js +1 -0
- package/dist-standalone/guardrails.js +1 -216
- package/dist-standalone/health-check.d.ts +150 -0
- package/dist-standalone/health-check.js +1 -0
- package/dist-standalone/http-compat.js +1 -267
- package/dist-standalone/http-status-map.js +1 -561
- package/dist-standalone/identity.d.ts +64 -1
- package/dist-standalone/identity.js +1 -515
- package/dist-standalone/index.d.ts +45 -3
- package/dist-standalone/index.js +1 -52
- package/dist-standalone/invitation.js +1 -415
- package/dist-standalone/invite.js +1 -324
- package/dist-standalone/key-agreement.d.ts +61 -13
- package/dist-standalone/key-agreement.js +1 -236
- package/dist-standalone/lazy-init.js +1 -295
- package/dist-standalone/logger.d.ts +77 -0
- package/dist-standalone/logger.js +1 -0
- package/dist-standalone/mdns-discovery.js +1 -195
- package/dist-standalone/nonce-store.d.ts +16 -3
- package/dist-standalone/nonce-store.js +1 -62
- package/dist-standalone/package.json +0 -1
- package/dist-standalone/pairing-manager.js +1 -219
- package/dist-standalone/plugin-system.d.ts +145 -0
- package/dist-standalone/plugin-system.js +1 -0
- package/dist-standalone/policy.js +1 -315
- package/dist-standalone/progress-callbacks.d.ts +394 -0
- package/dist-standalone/progress-callbacks.js +1 -0
- package/dist-standalone/redis-nonce-store.js +1 -72
- package/dist-standalone/registry-middleware.js +1 -47
- package/dist-standalone/retry-strategies.d.ts +382 -0
- package/dist-standalone/retry-strategies.js +1 -0
- package/dist-standalone/retry-transport.js +1 -98
- package/dist-standalone/security-policy.js +1 -239
- package/dist-standalone/serialization.d.ts +244 -0
- package/dist-standalone/serialization.js +1 -0
- package/dist-standalone/split-channel.d.ts +49 -1
- package/dist-standalone/split-channel.js +1 -171
- package/dist-standalone/subscription-proof.js +1 -224
- package/dist-standalone/succession.js +1 -142
- package/dist-standalone/timeouts.d.ts +275 -0
- package/dist-standalone/timeouts.js +1 -0
- package/dist-standalone/trace-context.d.ts +252 -0
- package/dist-standalone/trace-context.js +1 -0
- package/dist-standalone/trace-spans.d.ts +360 -0
- package/dist-standalone/trace-spans.js +1 -0
- package/dist-standalone/transport.js +1 -59
- package/dist-standalone/trust-registry.d.ts +106 -5
- package/dist-standalone/trust-registry.js +1 -702
- package/dist-standalone/vault-auth.d.ts +91 -0
- package/dist-standalone/vault-auth.js +1 -0
- package/dist-standalone/vault-store-loader.d.ts +110 -0
- package/dist-standalone/vault-store-loader.js +1 -0
- package/dist-standalone/verify.js +1 -16
- package/dist-standalone/version-info.d.ts +259 -0
- package/dist-standalone/version-info.js +1 -0
- package/dist-standalone/xfetch.js +1 -247
- package/llms.txt +1 -0
- package/package.json +65 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -222
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
- package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -199
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -134
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -145
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -159
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -92
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -295
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -364
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -136
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -71
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -366
- package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/errors.js.map +0 -1
- package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/index.js.map +0 -1
- package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
- package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/index.js.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
- package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/types.js.map +0 -1
|
@@ -1,300 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module lazy-init
|
|
4
|
-
* Lazy agent initialization for zero-click onboarding.
|
|
5
|
-
*
|
|
6
|
-
* Defers invite acceptance and identity generation until first
|
|
7
|
-
* send/receive call. Enables: `Agent.lazy({ name: 'my-service' })`
|
|
8
|
-
* with no async/await at construction time.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* // Environment: XBIND_INVITE_CODE=XBD-abc123
|
|
13
|
-
*
|
|
14
|
-
* // Old way (explicit):
|
|
15
|
-
* const agent = await Agent.create({ name: 'my-service', registry, transport });
|
|
16
|
-
*
|
|
17
|
-
* // New way (lazy):
|
|
18
|
-
* const agent = Agent.lazy({ name: 'my-service' });
|
|
19
|
-
* // No await, no async — agent is constructed synchronously.
|
|
20
|
-
* // Invite auto-accepts on first send/receive:
|
|
21
|
-
* await agent.send({ to: partnerDid, payload: data, scope: 'test' });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.LazyAgent = exports.LazyAgentErrorCode = void 0;
|
|
26
|
-
exports.createLazyAgent = createLazyAgent;
|
|
27
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
28
|
-
const agent_js_1 = require("./agent.js");
|
|
29
|
-
const auto_accept_js_1 = require("./auto-accept.js");
|
|
30
|
-
const trust_registry_js_1 = require("./trust-registry.js");
|
|
31
|
-
const transport_js_1 = require("./transport.js");
|
|
32
|
-
const crypto_1 = require("../_deps/crypto/index.js");
|
|
33
|
-
/**
|
|
34
|
-
* Lazy agent error codes.
|
|
35
|
-
*/
|
|
36
|
-
var LazyAgentErrorCode;
|
|
37
|
-
(function (LazyAgentErrorCode) {
|
|
38
|
-
LazyAgentErrorCode["INIT_FAILED"] = "LAZY_AGENT_INIT_FAILED";
|
|
39
|
-
LazyAgentErrorCode["AUTO_ACCEPT_FAILED"] = "LAZY_AGENT_AUTO_ACCEPT_FAILED";
|
|
40
|
-
LazyAgentErrorCode["AGENT_CREATION_FAILED"] = "LAZY_AGENT_AGENT_CREATION_FAILED";
|
|
41
|
-
})(LazyAgentErrorCode || (exports.LazyAgentErrorCode = LazyAgentErrorCode = {}));
|
|
42
|
-
/**
|
|
43
|
-
* Lazy agent wrapper.
|
|
44
|
-
*
|
|
45
|
-
* Proxies all Agent methods and initializes on first call.
|
|
46
|
-
* Caches the initialized agent for subsequent calls.
|
|
47
|
-
*/
|
|
48
|
-
class LazyAgent {
|
|
49
|
-
config;
|
|
50
|
-
agent = null;
|
|
51
|
-
initPromise = null;
|
|
52
|
-
lastError = null;
|
|
53
|
-
constructor(config) {
|
|
54
|
-
this.config = config;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get the agent's DID.
|
|
58
|
-
*
|
|
59
|
-
* Triggers initialization if not already initialized.
|
|
60
|
-
* Throws if initialization fails.
|
|
61
|
-
*/
|
|
62
|
-
get did() {
|
|
63
|
-
if (!this.agent) {
|
|
64
|
-
throw new Error('Agent not initialized. Call send/receive first or await ensureInitialized().');
|
|
65
|
-
}
|
|
66
|
-
return this.agent.did;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Check if agent is ready (initialized).
|
|
70
|
-
*/
|
|
71
|
-
isReady() {
|
|
72
|
-
return this.agent !== null;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Get last initialization error (if any).
|
|
76
|
-
*/
|
|
77
|
-
getLastError() {
|
|
78
|
-
return this.lastError;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Ensure agent is initialized.
|
|
82
|
-
*
|
|
83
|
-
* Can be called explicitly to trigger init before first send/receive.
|
|
84
|
-
* Safe to call multiple times — subsequent calls return cached agent.
|
|
85
|
-
*
|
|
86
|
-
* @returns Agent instance or error
|
|
87
|
-
*/
|
|
88
|
-
async ensureInitialized() {
|
|
89
|
-
// If already initialized, return cached agent
|
|
90
|
-
if (this.agent) {
|
|
91
|
-
return (0, shared_1.ok)(this.agent);
|
|
92
|
-
}
|
|
93
|
-
// If initialization is in progress, wait for it
|
|
94
|
-
if (this.initPromise) {
|
|
95
|
-
return this.initPromise;
|
|
96
|
-
}
|
|
97
|
-
// Start initialization
|
|
98
|
-
this.initPromise = this.initialize();
|
|
99
|
-
const result = await this.initPromise;
|
|
100
|
-
// Clear promise after completion (success or failure)
|
|
101
|
-
this.initPromise = null;
|
|
102
|
-
if (result.ok) {
|
|
103
|
-
this.agent = result.value;
|
|
104
|
-
this.lastError = null;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
this.lastError = {
|
|
108
|
-
code: LazyAgentErrorCode.INIT_FAILED,
|
|
109
|
-
message: `Agent initialization failed: ${result.error}`,
|
|
110
|
-
cause: result.error,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Internal initialization logic.
|
|
117
|
-
*
|
|
118
|
-
* 1. Auto-accept invite (if XBIND_INVITE_CODE set)
|
|
119
|
-
* 2. Create agent identity
|
|
120
|
-
* 3. Configure registry and transport
|
|
121
|
-
* 4. Return initialized agent
|
|
122
|
-
*/
|
|
123
|
-
async initialize() {
|
|
124
|
-
// Step 1: Attempt auto-accept if invite code is available
|
|
125
|
-
const inviteCode = this.config.inviteCode ?? this.getEnv('XBIND_INVITE_CODE');
|
|
126
|
-
let registry = this.config.registry;
|
|
127
|
-
let transport = this.config.transport;
|
|
128
|
-
const endpoint = this.config.endpoint ?? this.getEnv('XBIND_ENDPOINT') ?? '';
|
|
129
|
-
if (inviteCode) {
|
|
130
|
-
// Create temporary agent to get DID and public key for invite acceptance
|
|
131
|
-
const tempAgentResult = await agent_js_1.Agent.create({
|
|
132
|
-
name: this.config.name,
|
|
133
|
-
registry: new trust_registry_js_1.MemoryTrustRegistry(),
|
|
134
|
-
transport: new transport_js_1.HttpsTransportAdapter({ baseUrl: 'http://localhost' }), // Placeholder
|
|
135
|
-
postQuantumSig: this.config.postQuantumSig,
|
|
136
|
-
xchange: this.config.xchange,
|
|
137
|
-
});
|
|
138
|
-
if (!tempAgentResult.ok) {
|
|
139
|
-
return (0, shared_1.err)(tempAgentResult.error);
|
|
140
|
-
}
|
|
141
|
-
const tempAgent = tempAgentResult.value;
|
|
142
|
-
// Export public key for invite acceptance
|
|
143
|
-
const seedsResult = await tempAgent.exportSeeds();
|
|
144
|
-
if (!seedsResult.ok) {
|
|
145
|
-
return (0, shared_1.err)('IDENTITY_FAILED');
|
|
146
|
-
}
|
|
147
|
-
const publicKey = (0, crypto_1.toBase64)(tempAgent.identity.rawPublicKey);
|
|
148
|
-
const x25519PublicKey = tempAgent.identity.rawX25519PublicKey
|
|
149
|
-
? (0, crypto_1.toBase64)(tempAgent.identity.rawX25519PublicKey)
|
|
150
|
-
: undefined;
|
|
151
|
-
// Auto-accept invite
|
|
152
|
-
const acceptResult = await (0, auto_accept_js_1.autoAcceptInvite)({
|
|
153
|
-
inviteCode,
|
|
154
|
-
enabled: true,
|
|
155
|
-
registry: this.config.autoAccept?.registry,
|
|
156
|
-
inviteApiUrl: this.config.autoAccept?.inviteApiUrl,
|
|
157
|
-
}, {
|
|
158
|
-
name: this.config.name,
|
|
159
|
-
did: tempAgent.did,
|
|
160
|
-
endpoint,
|
|
161
|
-
publicKey,
|
|
162
|
-
x25519PublicKey,
|
|
163
|
-
});
|
|
164
|
-
if (!acceptResult.ok) {
|
|
165
|
-
this.lastError = {
|
|
166
|
-
code: LazyAgentErrorCode.AUTO_ACCEPT_FAILED,
|
|
167
|
-
message: acceptResult.error.message,
|
|
168
|
-
hint: acceptResult.error.hint,
|
|
169
|
-
cause: acceptResult.error,
|
|
170
|
-
};
|
|
171
|
-
// Non-fatal: continue with temp agent even if auto-accept fails
|
|
172
|
-
// (registry may already be configured)
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
// Use auto-configured registry if not provided
|
|
176
|
-
if (!registry && acceptResult.value.registryAutoconfigured) {
|
|
177
|
-
// Registry was already configured by autoAcceptInvite
|
|
178
|
-
registry = this.config.autoAccept?.registry ?? new trust_registry_js_1.MemoryTrustRegistry();
|
|
179
|
-
}
|
|
180
|
-
// Use inviter's endpoint as default transport if not provided
|
|
181
|
-
if (!transport) {
|
|
182
|
-
transport = new transport_js_1.HttpsTransportAdapter({
|
|
183
|
-
baseUrl: acceptResult.value.from.endpoint,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// Return temp agent as initialized agent
|
|
188
|
-
this.agent = tempAgent;
|
|
189
|
-
return (0, shared_1.ok)(tempAgent);
|
|
190
|
-
}
|
|
191
|
-
// Step 2: No invite code — create agent normally
|
|
192
|
-
const defaultRegistry = registry ?? new trust_registry_js_1.MemoryTrustRegistry();
|
|
193
|
-
const defaultTransport = transport ?? new transport_js_1.HttpsTransportAdapter({
|
|
194
|
-
baseUrl: endpoint || 'http://localhost',
|
|
195
|
-
});
|
|
196
|
-
const agentResult = await agent_js_1.Agent.create({
|
|
197
|
-
name: this.config.name,
|
|
198
|
-
registry: defaultRegistry,
|
|
199
|
-
transport: defaultTransport,
|
|
200
|
-
postQuantumSig: this.config.postQuantumSig,
|
|
201
|
-
xchange: this.config.xchange,
|
|
202
|
-
});
|
|
203
|
-
if (!agentResult.ok) {
|
|
204
|
-
this.lastError = {
|
|
205
|
-
code: LazyAgentErrorCode.AGENT_CREATION_FAILED,
|
|
206
|
-
message: `Agent creation failed: ${agentResult.error}`,
|
|
207
|
-
cause: agentResult.error,
|
|
208
|
-
};
|
|
209
|
-
return agentResult;
|
|
210
|
-
}
|
|
211
|
-
this.agent = agentResult.value;
|
|
212
|
-
return (0, shared_1.ok)(this.agent);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Send a message (proxied to underlying agent).
|
|
216
|
-
*
|
|
217
|
-
* Automatically initializes agent on first call.
|
|
218
|
-
*/
|
|
219
|
-
async send(opts) {
|
|
220
|
-
const agentResult = await this.ensureInitialized();
|
|
221
|
-
if (!agentResult.ok) {
|
|
222
|
-
return agentResult;
|
|
223
|
-
}
|
|
224
|
-
return agentResult.value.send(opts);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Receive a message (proxied to underlying agent).
|
|
228
|
-
*
|
|
229
|
-
* Automatically initializes agent on first call.
|
|
230
|
-
*/
|
|
231
|
-
async receive(envelope, opts) {
|
|
232
|
-
const agentResult = await this.ensureInitialized();
|
|
233
|
-
if (!agentResult.ok) {
|
|
234
|
-
return (0, shared_1.err)(agentResult.error);
|
|
235
|
-
}
|
|
236
|
-
return agentResult.value.receive(envelope, opts);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Receive a split-channel share (proxied to underlying agent).
|
|
240
|
-
*
|
|
241
|
-
* Automatically initializes agent on first call.
|
|
242
|
-
*/
|
|
243
|
-
async receiveSplitShare(envelope) {
|
|
244
|
-
const agentResult = await this.ensureInitialized();
|
|
245
|
-
if (!agentResult.ok) {
|
|
246
|
-
return (0, shared_1.err)(agentResult.error);
|
|
247
|
-
}
|
|
248
|
-
return agentResult.value.receiveSplitShare(envelope);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Get environment variable value.
|
|
252
|
-
*
|
|
253
|
-
* @param key - Environment variable name
|
|
254
|
-
* @returns Environment variable value or empty string
|
|
255
|
-
*/
|
|
256
|
-
getEnv(key) {
|
|
257
|
-
// SAFETY: Check for Node.js environment before accessing process
|
|
258
|
-
if (typeof process !== 'undefined' && typeof process.env !== 'undefined') {
|
|
259
|
-
return process.env[key] ?? '';
|
|
260
|
-
}
|
|
261
|
-
return '';
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Export the underlying agent (for advanced use cases).
|
|
265
|
-
*
|
|
266
|
-
* Throws if agent is not initialized.
|
|
267
|
-
*/
|
|
268
|
-
getAgent() {
|
|
269
|
-
if (!this.agent) {
|
|
270
|
-
throw new Error('Agent not initialized. Call send/receive first or await ensureInitialized().');
|
|
271
|
-
}
|
|
272
|
-
return this.agent;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
exports.LazyAgent = LazyAgent;
|
|
276
|
-
/**
|
|
277
|
-
* Create a lazy agent that initializes on first use.
|
|
278
|
-
*
|
|
279
|
-
* Extension method for Agent class. Adds `Agent.lazy()` factory.
|
|
280
|
-
*
|
|
281
|
-
* @param config - Lazy agent configuration
|
|
282
|
-
* @returns Lazy agent wrapper
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```ts
|
|
286
|
-
* // Environment: XBIND_INVITE_CODE=XBD-abc123
|
|
287
|
-
*
|
|
288
|
-
* const agent = createLazyAgent({ name: 'my-service' });
|
|
289
|
-
*
|
|
290
|
-
* // No initialization yet — happens on first send:
|
|
291
|
-
* await agent.send({
|
|
292
|
-
* to: 'did:key:z6Mk...',
|
|
293
|
-
* payload: { action: 'test' },
|
|
294
|
-
* scope: 'test',
|
|
295
|
-
* });
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
function createLazyAgent(config) {
|
|
299
|
-
return new LazyAgent(config);
|
|
300
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LazyAgent=exports.LazyAgentErrorCode=void 0,exports.createLazyAgent=createLazyAgent;const shared_1=require("../_deps/shared/index.js"),agent_js_1=require("./agent.js"),auto_accept_js_1=require("./auto-accept.js"),trust_registry_js_1=require("./trust-registry.js"),transport_js_1=require("./transport.js"),crypto_utils_js_1=require("./crypto-utils.js");var LazyAgentErrorCode;!function(e){e.INIT_FAILED="LAZY_AGENT_INIT_FAILED",e.AUTO_ACCEPT_FAILED="LAZY_AGENT_AUTO_ACCEPT_FAILED",e.AGENT_CREATION_FAILED="LAZY_AGENT_AGENT_CREATION_FAILED"}(LazyAgentErrorCode||(exports.LazyAgentErrorCode=LazyAgentErrorCode={}));class LazyAgent{config;agent=null;initPromise=null;lastError=null;constructor(e){this.config=e}get did(){if(!this.agent)throw new Error("Agent not initialized. Call send/receive first or await ensureInitialized().");return this.agent.did}isReady(){return null!==this.agent}getLastError(){return this.lastError}async ensureInitialized(){if(this.agent)return(0,shared_1.ok)(this.agent);if(this.initPromise)return this.initPromise;this.initPromise=this.initialize();const e=await this.initPromise;return this.initPromise=null,e.ok?(this.agent=e.value,this.lastError=null):this.lastError={code:LazyAgentErrorCode.INIT_FAILED,message:`Agent initialization failed: ${e.error}`,cause:e.error},e}async initialize(){const e=this.config.inviteCode??this.getEnv("XBIND_INVITE_CODE");let t=this.config.registry,r=this.config.transport;const i=this.config.endpoint??this.getEnv("XBIND_ENDPOINT")??"";if(e){const s=await agent_js_1.Agent.create({name:this.config.name,registry:new trust_registry_js_1.MemoryTrustRegistry,transport:new transport_js_1.HttpsTransportAdapter({baseUrl:"http://localhost"}),postQuantumSig:this.config.postQuantumSig,xchange:this.config.xchange});if(!s.ok)return(0,shared_1.err)(s.error);const n=s.value;if(!(await n.exportSeeds()).ok)return(0,shared_1.err)("IDENTITY_FAILED");const a=(0,crypto_utils_js_1.toBase64)(n.identity.rawPublicKey),o=n.identity.rawX25519PublicKey?(0,crypto_utils_js_1.toBase64)(n.identity.rawX25519PublicKey):void 0,c=await(0,auto_accept_js_1.autoAcceptInvite)({inviteCode:e,enabled:!0,registry:this.config.autoAccept?.registry,inviteApiUrl:this.config.autoAccept?.inviteApiUrl},{name:this.config.name,did:n.did,endpoint:i,publicKey:a,x25519PublicKey:o});return c.ok?(!t&&c.value.registryAutoconfigured&&(t=this.config.autoAccept?.registry??new trust_registry_js_1.MemoryTrustRegistry),r||(r=new transport_js_1.HttpsTransportAdapter({baseUrl:c.value.from.endpoint}))):this.lastError={code:LazyAgentErrorCode.AUTO_ACCEPT_FAILED,message:c.error.message,hint:c.error.hint,cause:c.error},this.agent=n,(0,shared_1.ok)(n)}const s=t??new trust_registry_js_1.MemoryTrustRegistry,n=r??new transport_js_1.HttpsTransportAdapter({baseUrl:i||"http://localhost"}),a=await agent_js_1.Agent.create({name:this.config.name,registry:s,transport:n,postQuantumSig:this.config.postQuantumSig,xchange:this.config.xchange});return a.ok?(this.agent=a.value,(0,shared_1.ok)(this.agent)):(this.lastError={code:LazyAgentErrorCode.AGENT_CREATION_FAILED,message:`Agent creation failed: ${a.error}`,cause:a.error},a)}async send(e){const t=await this.ensureInitialized();return t.ok?t.value.send(e):t}async receive(e,t){const r=await this.ensureInitialized();return r.ok?r.value.receive(e,t):(0,shared_1.err)(r.error)}async receiveSplitShare(e){const t=await this.ensureInitialized();return t.ok?t.value.receiveSplitShare(e):(0,shared_1.err)(t.error)}getEnv(e){return"undefined"!=typeof process&&void 0!==process.env?process.env[e]??"":""}getAgent(){if(!this.agent)throw new Error("Agent not initialized. Call send/receive first or await ensureInitialized().");return this.agent}}function createLazyAgent(e){return new LazyAgent(e)}exports.LazyAgent=LazyAgent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var LogLevel;Object.defineProperty(exports,"__esModule",{value:!0}),exports.logger=exports.LogLevel=void 0,exports.createLogger=createLogger,exports.getGlobalLogger=getGlobalLogger,exports.setGlobalLogger=setGlobalLogger,function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.SILENT=4]="SILENT"}(LogLevel||(exports.LogLevel=LogLevel={}));const SENSITIVE_PATTERNS={did:/^did:[a-zA-Z0-9]+:/,nonce:/^[a-f0-9]{32,}$|^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/,key:/^[a-zA-Z0-9+/]{40,}={0,2}$|^[a-f0-9]{64,}$/,token:/^eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,email:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,phone:/^\+?[1-9]\d{9,14}$/,apiKey:/^(sk_|pk_|ak_)[a-zA-Z0-9_-]{20,}$/},SENSITIVE_FIELD_NAMES=new Set(["password","secret","apiKey","api_key","privateKey","private_key","accessToken","access_token","refreshToken","refresh_token","masterKey","master_key","encryptionKey","encryption_key","authToken","auth_token","sessionToken","session_token","jwtToken","jwt_token","did","nonce","key","token","seed","entropy"]);function isSensitive(e,t){if("string"!=typeof t)return!1;const o=e.toLowerCase();if(SENSITIVE_FIELD_NAMES.has(o))return!0;for(const[e,n]of Object.entries(SENSITIVE_PATTERNS))if(o.includes(e)&&n.test(t))return!0;return!1}function redactValue(e){if(e.length<=4)return"*".repeat(Math.max(1,e.length));const t=Math.min(4,Math.ceil(e.length/4));return e.substring(0,t)+"*".repeat(Math.max(3,e.length-t-2))+e.substring(e.length-2)}function parseContextForLogging(e){const t=[],o={};for(const[n,r]of Object.entries(e))if(null!=r)if("object"==typeof r)if(r instanceof Error)o[n]={name:r.name,message:r.message};else if(r instanceof Map||r instanceof Set)o[n]=`[${r.constructor.name}]`;else if(Array.isArray(r))o[n]=r.map(e=>"string"==typeof e&&isSensitive(n,e)?(t.push(n),redactValue(e)):e);else{const e=parseContextForLogging(r);o[n]=e.context,e.redacted.length>0&&t.push(...e.redacted.map(e=>`${n}.${e}`))}else"string"==typeof r?isSensitive(n,r)?(t.push(n),o[n]=redactValue(r)):o[n]=r:o[n]="boolean"==typeof r||"number"==typeof r?r:`[${typeof r}]`;else o[n]=r;return{redacted:t,context:o}}function formatLogEntry(e,t,o,n,r){const s={timestamp:n,level:e,message:t};return o&&Object.keys(o).length>0&&(s.context=o),r.length>0&&(s.redacted=r),JSON.stringify(s)}function createLogger(e="default"){let t=LogLevel.INFO;const o=process.env.XAIL_LOG_LEVEL?.toUpperCase();o&&o in LogLevel&&(t=LogLevel[o]);return{debug(t,o){if(!this.isEnabled(LogLevel.DEBUG))return;const n=(new Date).toISOString(),r=o?parseContextForLogging(o):{redacted:[],context:{}},s=formatLogEntry("DEBUG",t,r.context,n,r.redacted);console.debug(`[${e}] ${s}`)},info(t,o){if(!this.isEnabled(LogLevel.INFO))return;const n=(new Date).toISOString(),r=o?parseContextForLogging(o):{redacted:[],context:{}},s=formatLogEntry("INFO",t,r.context,n,r.redacted);console.log(`[${e}] ${s}`)},warn(t,o){if(!this.isEnabled(LogLevel.WARN))return;const n=(new Date).toISOString(),r=o?parseContextForLogging(o):{redacted:[],context:{}},s=formatLogEntry("WARN",t,r.context,n,r.redacted);console.warn(`[${e}] ${s}`)},error(t,o,n){if(!this.isEnabled(LogLevel.ERROR))return;const r=(new Date).toISOString(),s=o?{...o}:{};n instanceof Error?s.error={name:n.name,message:n.message,stack:n.stack}:void 0!==n&&(s.error=n);const a=Object.keys(s).length>0?parseContextForLogging(s):{redacted:[],context:{}},g=formatLogEntry("ERROR",t,a.context,r,a.redacted);console.error(`[${e}] ${g}`)},setLevel(e){t=e},getLevel:()=>t,isEnabled:e=>e>=t}}let globalLogger=null;function getGlobalLogger(){return globalLogger||(globalLogger=createLogger("xbind")),globalLogger}function setGlobalLogger(e){globalLogger=e}exports.logger=getGlobalLogger();
|
|
@@ -1,202 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module mdns-discovery
|
|
4
|
-
* mDNS service discovery for local network device pairing.
|
|
5
|
-
*
|
|
6
|
-
* Service Type: _privateme._tcp.local (RFC 6763 compliant)
|
|
7
|
-
* Port: 58472 (dynamic range 58000-58999)
|
|
8
|
-
* TXT Record: did=z6Mk..., endpoint=http://192.168.1.5:58472, name=Desktop
|
|
9
|
-
*
|
|
10
|
-
* Security properties:
|
|
11
|
-
* - Physical proximity required (same LAN)
|
|
12
|
-
* - User confirmation on both devices
|
|
13
|
-
* - Nonce-based challenge-response
|
|
14
|
-
* - 60-second timeout
|
|
15
|
-
* - Gold Standard compliant (GS-CONNECT requirement #26)
|
|
16
|
-
*/
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.MdnsDiscoveryManager = exports.DiscoveryErrorCode = void 0;
|
|
22
|
-
const bonjour_service_1 = __importDefault(require("bonjour-service"));
|
|
23
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
24
|
-
/**
|
|
25
|
-
* Discovery error types.
|
|
26
|
-
*/
|
|
27
|
-
var DiscoveryErrorCode;
|
|
28
|
-
(function (DiscoveryErrorCode) {
|
|
29
|
-
DiscoveryErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
30
|
-
DiscoveryErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
31
|
-
DiscoveryErrorCode["NO_SERVICES"] = "NO_SERVICES";
|
|
32
|
-
DiscoveryErrorCode["INVALID_SERVICE"] = "INVALID_SERVICE";
|
|
33
|
-
})(DiscoveryErrorCode || (exports.DiscoveryErrorCode = DiscoveryErrorCode = {}));
|
|
34
|
-
/**
|
|
35
|
-
* mDNS discovery manager.
|
|
36
|
-
*
|
|
37
|
-
* Advertises service on local network and scans for other devices.
|
|
38
|
-
* Uses bonjour-service library (RFC 6763/6762 compliant).
|
|
39
|
-
*/
|
|
40
|
-
class MdnsDiscoveryManager {
|
|
41
|
-
bonjour;
|
|
42
|
-
service = null;
|
|
43
|
-
serviceType = 'privateme';
|
|
44
|
-
protocol = 'tcp';
|
|
45
|
-
port = 58472;
|
|
46
|
-
constructor() {
|
|
47
|
-
this.bonjour = new bonjour_service_1.default();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Advertise service on local network.
|
|
51
|
-
*
|
|
52
|
-
* Broadcasts mDNS announcement with device DID and HTTP endpoint.
|
|
53
|
-
* Other devices on the same LAN can discover this service via scan().
|
|
54
|
-
*
|
|
55
|
-
* @param name - Device name (e.g., "Desktop", "MacBook Pro")
|
|
56
|
-
* @param did - Device DID
|
|
57
|
-
* @param port - Local HTTP server port (default: 58472)
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const manager = new MdnsDiscoveryManager();
|
|
62
|
-
* manager.advertise('Desktop', 'did:key:z6Mk...', 58472);
|
|
63
|
-
* // Service now visible to other devices on LAN
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
advertise(name, did, port = this.port) {
|
|
67
|
-
// Stop existing advertisement
|
|
68
|
-
if (this.service) {
|
|
69
|
-
this.service.stop?.();
|
|
70
|
-
}
|
|
71
|
-
// Publish service
|
|
72
|
-
this.service = this.bonjour.publish({
|
|
73
|
-
name,
|
|
74
|
-
type: this.serviceType,
|
|
75
|
-
protocol: this.protocol,
|
|
76
|
-
port,
|
|
77
|
-
txt: {
|
|
78
|
-
did,
|
|
79
|
-
endpoint: `http://localhost:${port}`, // Will be replaced with actual IP by Bonjour
|
|
80
|
-
name,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Scan local network for services.
|
|
86
|
-
*
|
|
87
|
-
* Discovers all Private.Me devices on the same LAN.
|
|
88
|
-
* Filters out own DID from results (can't pair with self).
|
|
89
|
-
*
|
|
90
|
-
* @param ownDid - Own device DID (to filter out)
|
|
91
|
-
* @param timeoutMs - Scan timeout in milliseconds (default: 5000ms)
|
|
92
|
-
* @returns Array of discovered services
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* const manager = new MdnsDiscoveryManager();
|
|
97
|
-
* const result = await manager.scan('did:key:z6Mk...myDid', 5000);
|
|
98
|
-
* if (result.ok) {
|
|
99
|
-
* console.log(`Found ${result.value.length} devices`);
|
|
100
|
-
* for (const service of result.value) {
|
|
101
|
-
* console.log(`${service.name} - ${service.did}`);
|
|
102
|
-
* }
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
async scan(ownDid, timeoutMs = 5000) {
|
|
107
|
-
return new Promise((resolve) => {
|
|
108
|
-
const discovered = new Map();
|
|
109
|
-
let resolved = false;
|
|
110
|
-
// Browse for services
|
|
111
|
-
const browser = this.bonjour.find({
|
|
112
|
-
type: this.serviceType,
|
|
113
|
-
protocol: this.protocol,
|
|
114
|
-
});
|
|
115
|
-
// Handle service discovery
|
|
116
|
-
browser.on('up', (service) => {
|
|
117
|
-
try {
|
|
118
|
-
// Parse TXT record
|
|
119
|
-
const txt = service.txt;
|
|
120
|
-
if (!txt || !txt.did || !txt.name) {
|
|
121
|
-
return; // Invalid service - missing required fields
|
|
122
|
-
}
|
|
123
|
-
// Filter out own DID
|
|
124
|
-
if (txt.did === ownDid) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
// Extract endpoint
|
|
128
|
-
const endpoint = txt.endpoint || `http://${service.host || 'localhost'}:${service.port}`;
|
|
129
|
-
// Extract addresses (filter IPv4 only)
|
|
130
|
-
const addresses = (service.addresses || []).filter((addr) => {
|
|
131
|
-
// Simple IPv4 check (contains dots, not colons)
|
|
132
|
-
return addr.includes('.') && !addr.includes(':');
|
|
133
|
-
});
|
|
134
|
-
const info = {
|
|
135
|
-
name: txt.name,
|
|
136
|
-
did: txt.did,
|
|
137
|
-
endpoint,
|
|
138
|
-
addresses,
|
|
139
|
-
port: service.port || this.port,
|
|
140
|
-
};
|
|
141
|
-
discovered.set(txt.did, info);
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
// Ignore invalid service
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
// Timeout after specified duration
|
|
148
|
-
const timeoutId = setTimeout(() => {
|
|
149
|
-
if (resolved)
|
|
150
|
-
return;
|
|
151
|
-
resolved = true;
|
|
152
|
-
browser.stop();
|
|
153
|
-
if (discovered.size === 0) {
|
|
154
|
-
resolve((0, shared_1.err)({
|
|
155
|
-
code: DiscoveryErrorCode.NO_SERVICES,
|
|
156
|
-
message: 'No devices found on local network',
|
|
157
|
-
hint: 'Ensure both devices are on the same Wi-Fi network',
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
resolve((0, shared_1.ok)(Array.from(discovered.values())));
|
|
162
|
-
}
|
|
163
|
-
}, timeoutMs);
|
|
164
|
-
// Allow cleanup if promise resolves early
|
|
165
|
-
browser.on('error', (error) => {
|
|
166
|
-
if (resolved)
|
|
167
|
-
return;
|
|
168
|
-
resolved = true;
|
|
169
|
-
clearTimeout(timeoutId);
|
|
170
|
-
browser.stop();
|
|
171
|
-
resolve((0, shared_1.err)({
|
|
172
|
-
code: DiscoveryErrorCode.NETWORK_ERROR,
|
|
173
|
-
message: error.message,
|
|
174
|
-
hint: 'Check firewall settings and network connectivity',
|
|
175
|
-
}));
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Stop advertising service.
|
|
181
|
-
*
|
|
182
|
-
* Removes mDNS announcement from local network.
|
|
183
|
-
* Other devices will no longer see this service.
|
|
184
|
-
*/
|
|
185
|
-
stopAdvertising() {
|
|
186
|
-
if (this.service) {
|
|
187
|
-
this.service.stop?.();
|
|
188
|
-
this.service = null;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Release resources.
|
|
193
|
-
*
|
|
194
|
-
* Stops advertising and cleans up Bonjour instance.
|
|
195
|
-
* Call this when shutting down the application.
|
|
196
|
-
*/
|
|
197
|
-
destroy() {
|
|
198
|
-
this.stopAdvertising();
|
|
199
|
-
this.bonjour.destroy();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.MdnsDiscoveryManager = MdnsDiscoveryManager;
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MdnsDiscoveryManager=exports.DiscoveryErrorCode=void 0;const bonjour_service_1=__importDefault(require("bonjour-service")),shared_1=require("../_deps/shared/index.js");var DiscoveryErrorCode;!function(e){e.NETWORK_ERROR="NETWORK_ERROR",e.TIMEOUT="TIMEOUT",e.NO_SERVICES="NO_SERVICES",e.INVALID_SERVICE="INVALID_SERVICE"}(DiscoveryErrorCode||(exports.DiscoveryErrorCode=DiscoveryErrorCode={}));class MdnsDiscoveryManager{bonjour;service=null;serviceType="privateme";protocol="tcp";port=58472;constructor(){this.bonjour=new bonjour_service_1.default}advertise(e,r,o=this.port){this.service&&this.service.stop?.(),this.service=this.bonjour.publish({name:e,type:this.serviceType,protocol:this.protocol,port:o,txt:{did:r,endpoint:`http://localhost:${o}`,name:e}})}async scan(e,r=5e3){return new Promise(o=>{const s=new Map;let t=!1;const i=this.bonjour.find({type:this.serviceType,protocol:this.protocol});i.on("up",r=>{try{const o=r.txt;if(!o||!o.did||!o.name)return;if(o.did===e)return;const t=o.endpoint||`http://${r.host||"localhost"}:${r.port}`,i=(r.addresses||[]).filter(e=>e.includes(".")&&!e.includes(":")),n={name:o.name,did:o.did,endpoint:t,addresses:i,port:r.port||this.port};s.set(o.did,n)}catch(e){}});const n=setTimeout(()=>{t||(t=!0,i.stop(),0===s.size?o((0,shared_1.err)({code:DiscoveryErrorCode.NO_SERVICES,message:"No devices found on local network",hint:"Ensure both devices are on the same Wi-Fi network"})):o((0,shared_1.ok)(Array.from(s.values()))))},r);i.on("error",e=>{t||(t=!0,clearTimeout(n),i.stop(),o((0,shared_1.err)({code:DiscoveryErrorCode.NETWORK_ERROR,message:e.message,hint:"Check firewall settings and network connectivity"})))})})}stopAdvertising(){this.service&&(this.service.stop?.(),this.service=null)}destroy(){this.stopAdvertising(),this.bonjour.destroy()}}exports.MdnsDiscoveryManager=MdnsDiscoveryManager;
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* ── NonceStore — Replay Prevention ── */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.MemoryNonceStore = void 0;
|
|
5
|
-
/** Default TTL for nonce entries: 10 minutes. */
|
|
6
|
-
const DEFAULT_TTL_MS = 10 * 60 * 1000;
|
|
7
|
-
/** Default cleanup interval: 60 seconds. */
|
|
8
|
-
const DEFAULT_CLEANUP_INTERVAL_MS = 60 * 1000;
|
|
9
|
-
/**
|
|
10
|
-
* In-memory nonce store for development and single-process deployments.
|
|
11
|
-
*
|
|
12
|
-
* Stores nonces in a Map keyed by "senderDid:nonce" with expiry timestamps.
|
|
13
|
-
* Periodic cleanup removes expired entries to prevent unbounded growth.
|
|
14
|
-
*/
|
|
15
|
-
class MemoryNonceStore {
|
|
16
|
-
seen = new Map();
|
|
17
|
-
ttlMs;
|
|
18
|
-
cleanupIntervalMs;
|
|
19
|
-
timer = null;
|
|
20
|
-
constructor(opts) {
|
|
21
|
-
this.ttlMs = opts?.ttlMs ?? DEFAULT_TTL_MS;
|
|
22
|
-
this.cleanupIntervalMs = opts?.cleanupIntervalMs ?? DEFAULT_CLEANUP_INTERVAL_MS;
|
|
23
|
-
// Timer starts lazily on first check() to avoid blocking process exit in tests
|
|
24
|
-
}
|
|
25
|
-
/** Start cleanup timer on first use. */
|
|
26
|
-
ensureTimer() {
|
|
27
|
-
if (this.timer !== null)
|
|
28
|
-
return;
|
|
29
|
-
const t = setInterval(() => this.cleanup(), this.cleanupIntervalMs);
|
|
30
|
-
// Unref so the timer doesn't block Node.js process exit
|
|
31
|
-
if (typeof t === 'object' && 'unref' in t) {
|
|
32
|
-
t.unref(); // SAFETY: runtime check guards access
|
|
33
|
-
}
|
|
34
|
-
this.timer = t;
|
|
35
|
-
}
|
|
36
|
-
async check(nonce, senderDid) {
|
|
37
|
-
this.ensureTimer();
|
|
38
|
-
const key = `${senderDid}:${nonce}`;
|
|
39
|
-
const existing = this.seen.get(key);
|
|
40
|
-
const now = Date.now();
|
|
41
|
-
if (existing !== undefined && existing > now) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
this.seen.set(key, now + this.ttlMs);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
cleanup() {
|
|
48
|
-
const now = Date.now();
|
|
49
|
-
for (const [key, expiry] of this.seen) {
|
|
50
|
-
if (expiry <= now)
|
|
51
|
-
this.seen.delete(key);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
dispose() {
|
|
55
|
-
if (this.timer !== null) {
|
|
56
|
-
clearInterval(this.timer);
|
|
57
|
-
this.timer = null;
|
|
58
|
-
}
|
|
59
|
-
this.seen.clear();
|
|
60
|
-
}
|
|
61
|
-
/** Number of active (non-expired) entries. Useful for testing. */
|
|
62
|
-
get size() {
|
|
63
|
-
return this.seen.size;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.MemoryNonceStore = MemoryNonceStore;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MemoryNonceStore=void 0;const DEFAULT_TTL_MS=6e5,DEFAULT_CLEANUP_INTERVAL_MS=6e4;class MemoryNonceStore{seen=new Map;ttlMs;cleanupIntervalMs;timer=null;constructor(e){this.ttlMs=e?.ttlMs??6e5,this.cleanupIntervalMs=e?.cleanupIntervalMs??6e4}ensureTimer(){if(null!==this.timer)return;const e=setInterval(()=>this.cleanup(),this.cleanupIntervalMs);"object"==typeof e&&"unref"in e&&e.unref(),this.timer=e}buildKey(e,t,s){if(null==s)return`${t}:${e}`;return`${t}:${e}:${"string"==typeof s.shareGroupId?s.shareGroupId:""}:${"number"==typeof s.shareIndex?String(s.shareIndex):""}`}async check(e,t,s){this.ensureTimer();const r=this.buildKey(e,t,s),n=this.seen.get(r),i=Date.now();return!(void 0!==n&&n>i)&&(this.seen.set(r,i+this.ttlMs),!0)}cleanup(){const e=Date.now(),t=Array.from(this.seen.keys());for(const s of t){const t=this.seen.get(s);void 0!==t&&t<=e&&this.seen.delete(s)}}dispose(){null!==this.timer&&(clearInterval(this.timer),this.timer=null),this.seen.clear()}get size(){return this.seen.size}}exports.MemoryNonceStore=MemoryNonceStore;
|