@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,149 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @module cli/xbind
|
|
5
|
-
* Main xBind CLI router - dispatches to subcommands.
|
|
6
|
-
*
|
|
7
|
-
* Supports 12 commands (v2.0.0 spec):
|
|
8
|
-
* 1. setup - Create deployment identity
|
|
9
|
-
* 2. connect - Connect to a service (TODO)
|
|
10
|
-
* 3. invite - Generate invite link (TODO)
|
|
11
|
-
* 4. list - List connections (TODO)
|
|
12
|
-
* 5. status - Display connection status (TODO)
|
|
13
|
-
* 6. migrate - Scan for API keys (TODO)
|
|
14
|
-
* 7. trial - Activate free trial (TODO)
|
|
15
|
-
* 8. deploy - Deploy algorithms (TODO)
|
|
16
|
-
* 9. server - Start relay server (TODO)
|
|
17
|
-
* 10. revoke - Revoke connection (TODO)
|
|
18
|
-
* 11. backup - Export/import identity (TODO)
|
|
19
|
-
* 12. debug - Diagnostics (TODO)
|
|
20
|
-
*/
|
|
21
|
-
import { parseArgs } from 'node:util';
|
|
22
|
-
import { ExitCode, Colors } from './types.js';
|
|
23
|
-
/**
|
|
24
|
-
* Show help message.
|
|
25
|
-
*/
|
|
26
|
-
function showHelp() {
|
|
27
|
-
console.log(`
|
|
28
|
-
xBind CLI - Identity-Based M2M Authentication
|
|
29
|
-
|
|
30
|
-
Usage:
|
|
31
|
-
xbind <command> [options]
|
|
32
|
-
|
|
33
|
-
Commands:
|
|
34
|
-
setup Create deployment identity (DID + DeploymentID)
|
|
35
|
-
connect Connect to a service (TODO)
|
|
36
|
-
invite Generate viral invite link (TODO)
|
|
37
|
-
list List all active connections (TODO)
|
|
38
|
-
status Display connection status (TODO)
|
|
39
|
-
migrate Scan codebase for API keys (TODO)
|
|
40
|
-
trial Activate 3-month free trial (TODO)
|
|
41
|
-
deploy Deploy proprietary algorithms (TODO)
|
|
42
|
-
server Start agent relay server (TODO)
|
|
43
|
-
revoke Revoke connection (TODO)
|
|
44
|
-
backup Export/import identity (TODO)
|
|
45
|
-
debug Diagnostic information (TODO)
|
|
46
|
-
|
|
47
|
-
Global Options:
|
|
48
|
-
--json Output JSON only (no human-readable text)
|
|
49
|
-
--no-color Disable colored output
|
|
50
|
-
--debug Show detailed error information
|
|
51
|
-
-h, --help Show this help message
|
|
52
|
-
|
|
53
|
-
Examples:
|
|
54
|
-
xbind setup --name my-service
|
|
55
|
-
xbind setup --email user@example.com --force
|
|
56
|
-
xbind connect payments-service
|
|
57
|
-
xbind status
|
|
58
|
-
|
|
59
|
-
Documentation:
|
|
60
|
-
https://private.me/docs/xbind
|
|
61
|
-
`.trim());
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Show version.
|
|
65
|
-
*/
|
|
66
|
-
function showVersion() {
|
|
67
|
-
// Read from package.json
|
|
68
|
-
console.log('xBind CLI v1.3.0');
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Main CLI entry point.
|
|
72
|
-
*/
|
|
73
|
-
async function main() {
|
|
74
|
-
const args = process.argv.slice(2);
|
|
75
|
-
// No arguments - show help
|
|
76
|
-
if (args.length === 0) {
|
|
77
|
-
showHelp();
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
// Parse global flags
|
|
81
|
-
const { values, positionals } = parseArgs({
|
|
82
|
-
args,
|
|
83
|
-
options: {
|
|
84
|
-
help: { type: 'boolean', short: 'h' },
|
|
85
|
-
version: { type: 'boolean', short: 'v' },
|
|
86
|
-
json: { type: 'boolean' },
|
|
87
|
-
'no-color': { type: 'boolean' },
|
|
88
|
-
debug: { type: 'boolean' },
|
|
89
|
-
},
|
|
90
|
-
allowPositionals: true,
|
|
91
|
-
strict: false, // Allow command-specific flags
|
|
92
|
-
});
|
|
93
|
-
// Global flags
|
|
94
|
-
if (values.help) {
|
|
95
|
-
showHelp();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (values.version) {
|
|
99
|
-
showVersion();
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
// Get command
|
|
103
|
-
const command = positionals[0];
|
|
104
|
-
if (!command) {
|
|
105
|
-
showHelp();
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
// Route to command handler
|
|
109
|
-
switch (command) {
|
|
110
|
-
case 'setup': {
|
|
111
|
-
const { main: setupMain } = await import('./setup.js');
|
|
112
|
-
await setupMain(args.slice(1)); // Pass remaining args to setup command
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
case 'connect':
|
|
116
|
-
case 'invite':
|
|
117
|
-
case 'list':
|
|
118
|
-
case 'status':
|
|
119
|
-
case 'migrate':
|
|
120
|
-
case 'trial':
|
|
121
|
-
case 'deploy':
|
|
122
|
-
case 'server':
|
|
123
|
-
case 'revoke':
|
|
124
|
-
case 'backup':
|
|
125
|
-
case 'debug': {
|
|
126
|
-
const useColors = !values['no-color'] && process.stderr.isTTY;
|
|
127
|
-
const yellow = useColors ? Colors.YELLOW : '';
|
|
128
|
-
const reset = useColors ? Colors.RESET : '';
|
|
129
|
-
console.error(`${yellow}⚠️ Command "${command}" not yet implemented${reset}`);
|
|
130
|
-
console.error(`\nAvailable commands:`);
|
|
131
|
-
console.error(` • setup - Create deployment identity (IMPLEMENTED)`);
|
|
132
|
-
console.error(`\nComing soon: connect, invite, list, status, migrate, trial, deploy, server, revoke, backup, debug`);
|
|
133
|
-
process.exit(ExitCode.USER_ERROR);
|
|
134
|
-
}
|
|
135
|
-
default: {
|
|
136
|
-
const useColors = !values['no-color'] && process.stderr.isTTY;
|
|
137
|
-
const red = useColors ? Colors.RED : '';
|
|
138
|
-
const reset = useColors ? Colors.RESET : '';
|
|
139
|
-
console.error(`${red}❌ Error: Unknown command "${command}"${reset}`);
|
|
140
|
-
console.error(`\nRun "xbind --help" to see available commands.`);
|
|
141
|
-
process.exit(ExitCode.USER_ERROR);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
// Run main
|
|
146
|
-
main().catch((error) => {
|
|
147
|
-
console.error('Fatal error:', error instanceof Error ? error.message : String(error));
|
|
148
|
-
process.exit(ExitCode.SYSTEM_ERROR);
|
|
149
|
-
});
|
|
2
|
+
import{parseArgs}from"node:util";import{ExitCode,Colors}from"./types.js";function showHelp(){console.log("\nxBind CLI - Identity-Based M2M Authentication\n\nUsage:\n xbind <command> [options]\n\nCommands:\n setup Create deployment identity (DID + DeploymentID)\n connect Connect to a service (TODO)\n invite Generate viral invite link (TODO)\n list List all active connections (TODO)\n status Display connection status (TODO)\n migrate Scan codebase for API keys (TODO)\n trial Activate 3-month free trial (TODO)\n deploy Deploy proprietary algorithms (TODO)\n server Start agent relay server (TODO)\n revoke Revoke connection (TODO)\n backup Export/import identity (TODO)\n debug Diagnostic information (TODO)\n\nGlobal Options:\n --json Output JSON only (no human-readable text)\n --no-color Disable colored output\n --debug Show detailed error information\n -h, --help Show this help message\n\nExamples:\n xbind setup --name my-service\n xbind setup --email user@example.com --force\n xbind connect payments-service\n xbind status\n\nDocumentation:\n https://private.me/docs/xbind\n ".trim())}function showVersion(){console.log("xBind CLI v1.3.0")}async function main(){const e=process.argv.slice(2);if(0===e.length)return void showHelp();const{values:o,positionals:n}=parseArgs({args:e,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},json:{type:"boolean"},"no-color":{type:"boolean"},debug:{type:"boolean"}},allowPositionals:!0,strict:!1});if(o.help)return void showHelp();if(o.version)return void showVersion();const t=n[0];if(t)switch(t){case"setup":{const{main:o}=await import("./setup.js");await o(e.slice(1));break}case"connect":case"invite":case"list":case"status":case"migrate":case"trial":case"deploy":case"server":case"revoke":case"backup":case"debug":{const e=!o["no-color"]&&process.stderr.isTTY,n=e?Colors.YELLOW:"",s=e?Colors.RESET:"";console.error(`${n}⚠️ Command "${t}" not yet implemented${s}`),console.error("\nAvailable commands:"),console.error(" • setup - Create deployment identity (IMPLEMENTED)"),console.error("\nComing soon: connect, invite, list, status, migrate, trial, deploy, server, revoke, backup, debug"),process.exit(ExitCode.USER_ERROR)}default:{const e=!o["no-color"]&&process.stderr.isTTY,n=e?Colors.RED:"",s=e?Colors.RESET:"";console.error(`${n}❌ Error: Unknown command "${t}"${s}`),console.error('\nRun "xbind --help" to see available commands.'),process.exit(ExitCode.USER_ERROR)}}else showHelp()}main().catch(e=>{console.error("Fatal error:",e instanceof Error?e.message:String(e)),process.exit(ExitCode.SYSTEM_ERROR)});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module config-validation
|
|
3
|
+
* Configuration validation for xBind agent initialization.
|
|
4
|
+
*
|
|
5
|
+
* Provides schema validation, type checking, and clear error messages
|
|
6
|
+
* for AgentOptions and AgentCreateOptions to enhance configuration safety
|
|
7
|
+
* and improve developer experience.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { validateAgentOptions, validateAgentCreateOptions } from '@private.me/xbind';
|
|
12
|
+
*
|
|
13
|
+
* // Validate simplified options
|
|
14
|
+
* const simpleResult = validateAgentOptions({
|
|
15
|
+
* identity: 'persistent',
|
|
16
|
+
* registry: 'https://private.me/registry'
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* if (!simpleResult.ok) {
|
|
20
|
+
* console.error(simpleResult.error); // Clear, actionable error message
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Validate full options
|
|
24
|
+
* const fullResult = validateAgentCreateOptions({
|
|
25
|
+
* name: 'my-agent',
|
|
26
|
+
* registry: myRegistryInstance,
|
|
27
|
+
* transport: myTransportAdapter
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
import type { Result } from '@private.me/shared';
|
|
32
|
+
import type { AgentOptions, AgentCreateOptions } from './agent.js';
|
|
33
|
+
import { XBindError } from './errors.js';
|
|
34
|
+
/**
|
|
35
|
+
* Configuration validation error with detailed context.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ConfigValidationError extends XBindError {
|
|
38
|
+
/** Field that failed validation */
|
|
39
|
+
readonly field: string;
|
|
40
|
+
/** Expected value/type */
|
|
41
|
+
readonly expected: string;
|
|
42
|
+
/** Actual value received */
|
|
43
|
+
readonly actual: unknown;
|
|
44
|
+
/** Suggested fix */
|
|
45
|
+
readonly fix: string;
|
|
46
|
+
constructor(field: string, expected: string, actual: unknown, fix: string);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validation result with detailed error information.
|
|
50
|
+
*/
|
|
51
|
+
export interface ValidationResult {
|
|
52
|
+
/** Whether validation passed */
|
|
53
|
+
valid: boolean;
|
|
54
|
+
/** Validation errors (if any) */
|
|
55
|
+
errors: ConfigValidationError[];
|
|
56
|
+
/** Warnings (non-blocking issues) */
|
|
57
|
+
warnings: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Default values for AgentOptions.
|
|
61
|
+
*/
|
|
62
|
+
export declare const AGENT_OPTIONS_DEFAULTS: {
|
|
63
|
+
readonly identity: "persistent";
|
|
64
|
+
readonly identityTTL: 3600000;
|
|
65
|
+
readonly postQuantumSig: false;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Default values for AgentCreateOptions.
|
|
69
|
+
*/
|
|
70
|
+
export declare const AGENT_CREATE_OPTIONS_DEFAULTS: {
|
|
71
|
+
readonly timestampWindowMs: 30000;
|
|
72
|
+
readonly postQuantumSig: false;
|
|
73
|
+
readonly xchange: false;
|
|
74
|
+
readonly scopes: string[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Validate AgentOptions configuration.
|
|
78
|
+
*
|
|
79
|
+
* Checks all fields for correct types, valid values, and logical consistency.
|
|
80
|
+
* Provides clear, actionable error messages for any validation failures.
|
|
81
|
+
*
|
|
82
|
+
* @param options - AgentOptions to validate
|
|
83
|
+
* @returns Result with validation errors or success
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const result = validateAgentOptions({
|
|
88
|
+
* identity: 'persistent',
|
|
89
|
+
* registry: 'https://private.me/registry',
|
|
90
|
+
* identityTTL: 7200000 // 2 hours
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* if (result.ok) {
|
|
94
|
+
* console.log('Configuration valid!');
|
|
95
|
+
* } else {
|
|
96
|
+
* console.error(result.error);
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function validateAgentOptions(options: unknown): Result<AgentOptions, ConfigValidationError>;
|
|
101
|
+
/**
|
|
102
|
+
* Validate AgentCreateOptions configuration.
|
|
103
|
+
*
|
|
104
|
+
* Checks all fields for correct types, valid values, and logical consistency.
|
|
105
|
+
* Provides clear, actionable error messages for any validation failures.
|
|
106
|
+
*
|
|
107
|
+
* @param options - AgentCreateOptions to validate
|
|
108
|
+
* @returns Result with validation errors or success
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const result = validateAgentCreateOptions({
|
|
113
|
+
* name: 'my-agent',
|
|
114
|
+
* registry: new MemoryTrustRegistry(),
|
|
115
|
+
* transport: new HttpsTransportAdapter(),
|
|
116
|
+
* timestampWindowMs: 60000 // 1 minute
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* if (result.ok) {
|
|
120
|
+
* console.log('Configuration valid!');
|
|
121
|
+
* } else {
|
|
122
|
+
* console.error(result.error);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function validateAgentCreateOptions(options: unknown): Result<AgentCreateOptions, ConfigValidationError>;
|
|
127
|
+
/**
|
|
128
|
+
* Get detailed validation result with all errors and warnings.
|
|
129
|
+
*
|
|
130
|
+
* Unlike the Result-based validators, this function returns all validation
|
|
131
|
+
* issues at once for comprehensive feedback.
|
|
132
|
+
*
|
|
133
|
+
* @param options - AgentOptions to validate
|
|
134
|
+
* @returns ValidationResult with all errors and warnings
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const result = getValidationDetails({
|
|
139
|
+
* identity: 'invalid',
|
|
140
|
+
* identityTTL: -100,
|
|
141
|
+
* postQuantumSig: 'yes' // type error
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* console.log(`Valid: ${result.valid}`);
|
|
145
|
+
* console.log(`Errors: ${result.errors.length}`);
|
|
146
|
+
* console.log(`Warnings: ${result.warnings.length}`);
|
|
147
|
+
*
|
|
148
|
+
* result.errors.forEach(err => {
|
|
149
|
+
* console.error(`- ${err.field}: ${err.message}`);
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function getValidationDetails(options: unknown): ValidationResult;
|
|
154
|
+
/**
|
|
155
|
+
* Validate configuration and throw on error.
|
|
156
|
+
*
|
|
157
|
+
* Convenience function that validates configuration and throws
|
|
158
|
+
* ConfigValidationError if validation fails.
|
|
159
|
+
*
|
|
160
|
+
* @param options - AgentOptions or AgentCreateOptions to validate
|
|
161
|
+
* @throws ConfigValidationError if validation fails
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* try {
|
|
166
|
+
* assertValidConfig({
|
|
167
|
+
* identity: 'persistent',
|
|
168
|
+
* registry: 'https://private.me/registry'
|
|
169
|
+
* });
|
|
170
|
+
* // Configuration is valid, continue
|
|
171
|
+
* } catch (err) {
|
|
172
|
+
* if (err instanceof ConfigValidationError) {
|
|
173
|
+
* console.error(`Invalid ${err.field}: ${err.fix}`);
|
|
174
|
+
* }
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function assertValidConfig(options: unknown): asserts options is AgentOptions;
|
|
179
|
+
/**
|
|
180
|
+
* Validate configuration and throw on error (full options).
|
|
181
|
+
*
|
|
182
|
+
* @param options - AgentCreateOptions to validate
|
|
183
|
+
* @throws ConfigValidationError if validation fails
|
|
184
|
+
*/
|
|
185
|
+
export declare function assertValidCreateConfig(options: unknown): asserts options is AgentCreateOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ok,err}from"./_deps/shared/index.js";import{XBindError}from"./errors.js";export class ConfigValidationError extends XBindError{field;expected;actual;fix;constructor(t,e,r,i){super("CONFIG_INVALID",`Configuration validation failed for '${t}': Expected ${e}, got ${"object"==typeof r&&null!==r?JSON.stringify(r):String(r)}. ${i}`,"https://private.me/docs/xbind/api/configuration"),this.name="ConfigValidationError",this.field=t,this.expected=e,this.actual=r,this.fix=i}}export const AGENT_OPTIONS_DEFAULTS={identity:"persistent",identityTTL:36e5,postQuantumSig:!1};export const AGENT_CREATE_OPTIONS_DEFAULTS={timestampWindowMs:3e4,postQuantumSig:!1,xchange:!1,scopes:[]};export function validateAgentOptions(t){if(!t||"object"!=typeof t)return err(new ConfigValidationError("options","object",t,"Provide a configuration object with at least one option."));const e=t,r=[],i=[];if(void 0!==e.identity&&("string"!=typeof e.identity?r.push(new ConfigValidationError("identity","'persistent' | 'ephemeral'",e.identity,"Use 'persistent' for long-lived DIDs or 'ephemeral' for short-lived DIDs.")):"persistent"!==e.identity&&"ephemeral"!==e.identity&&r.push(new ConfigValidationError("identity","'persistent' | 'ephemeral'",e.identity,"Invalid identity mode. Use 'persistent' or 'ephemeral'."))),void 0!==e.identityTTL&&("number"!=typeof e.identityTTL?r.push(new ConfigValidationError("identityTTL","number (milliseconds)",e.identityTTL,"Provide TTL as a number in milliseconds (e.g., 3600000 for 1 hour).")):e.identityTTL<=0?r.push(new ConfigValidationError("identityTTL","positive number",e.identityTTL,"TTL must be greater than 0. Use at least 60000 (1 minute).")):e.identityTTL<6e4?i.push(`identityTTL is very short (${e.identityTTL}ms). Consider using at least 60000ms (1 minute) to avoid frequent re-registrations.`):e.identityTTL>864e5&&i.push(`identityTTL is very long (${e.identityTTL}ms). Consider using 'persistent' identity mode instead for long-lived agents.`),"persistent"===e.identity&&i.push("identityTTL is ignored for 'persistent' identity mode. Remove this option or switch to 'ephemeral' mode.")),void 0!==e.registry){const t="string"==typeof e.registry,i="object"==typeof e.registry&&null!==e.registry;if(t||i){if(t){const t=e.registry;try{const e=new URL(t);"http:"!==e.protocol&&"https:"!==e.protocol&&r.push(new ConfigValidationError("registry","HTTP(S) URL",t,"Registry URL must use HTTP or HTTPS protocol."))}catch{r.push(new ConfigValidationError("registry","valid URL",t,'Provide a valid URL (e.g., "https://private.me/registry").'))}}else if(i){const t=e.registry,i=["register","resolve"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("registry","TrustRegistry instance","object missing required methods",`TrustRegistry must implement ${i.join(", ")} method(s). Use HttpTrustRegistry or MemoryTrustRegistry.`))}}else r.push(new ConfigValidationError("registry","TrustRegistry instance or URL string",e.registry,'Provide either a registry URL (e.g., "https://private.me/registry") or a TrustRegistry instance.'))}if(void 0!==e.transport){const t=Array.isArray(e.transport);if("object"==typeof e.transport&&null!==e.transport&&!t||t)if(t){const t=e.transport;0===t.length&&r.push(new ConfigValidationError("transport","non-empty array",t,"Provide at least one transport adapter.")),t.forEach((t,e)=>{if("object"!=typeof t||null===t)r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter",t,"Each transport must be a XailTransportAdapter instance."));else{"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}})}else{const t=e.transport;"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError("transport","XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}else r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[]",e.transport,"Provide a single transport adapter or an array of adapters for split-channel security."))}if(void 0!==e.securityPolicy)if("object"!=typeof e.securityPolicy||null===e.securityPolicy)r.push(new ConfigValidationError("securityPolicy","SecurityPolicy instance",e.securityPolicy,"Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy)."));else{const t=e.securityPolicy;"classify"in t&&"function"==typeof t.classify||r.push(new ConfigValidationError("securityPolicy","SecurityPolicy with classify() method","object missing classify() method","SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy."))}if(void 0!==e.postQuantumSig&&"boolean"!=typeof e.postQuantumSig&&r.push(new ConfigValidationError("postQuantumSig","boolean",e.postQuantumSig,"Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.")),void 0!==e.backupConfig)if("object"!=typeof e.backupConfig||null===e.backupConfig)r.push(new ConfigValidationError("backupConfig","BackupConfig object",e.backupConfig,"Provide a BackupConfig object with threshold (k) and totalShares (n) properties."));else{const t=e.backupConfig;"number"!=typeof t.threshold?r.push(new ConfigValidationError("backupConfig.threshold","number",t.threshold,"Threshold (k) must be a number representing shares needed for reconstruction.")):t.threshold<2&&r.push(new ConfigValidationError("backupConfig.threshold","number >= 2",t.threshold,"Threshold must be at least 2 for meaningful splitting.")),"number"!=typeof t.totalShares?r.push(new ConfigValidationError("backupConfig.totalShares","number",t.totalShares,"totalShares (n) must be a number representing total shares to create.")):t.totalShares<2&&r.push(new ConfigValidationError("backupConfig.totalShares","number >= 2",t.totalShares,"totalShares must be at least 2 for splitting.")),"number"==typeof t.threshold&&"number"==typeof t.totalShares&&t.threshold>t.totalShares&&r.push(new ConfigValidationError("backupConfig","threshold <= totalShares",`threshold=${t.threshold}, totalShares=${t.totalShares}`,`Threshold (${t.threshold}) cannot exceed totalShares (${t.totalShares}). Use threshold <= totalShares.`))}return r.length>0?err(r[0]):ok(e)}export function validateAgentCreateOptions(t){if(!t||"object"!=typeof t)return err(new ConfigValidationError("options","object",t,"Provide a configuration object with required fields: name, registry, transport."));const e=t,r=[];if(void 0===e.name?r.push(new ConfigValidationError("name","string (required)",void 0,'Provide a display name for the agent (e.g., "my-agent").')):"string"!=typeof e.name?r.push(new ConfigValidationError("name","string",e.name,"Agent name must be a string.")):0===e.name.trim().length?r.push(new ConfigValidationError("name","non-empty string",e.name,"Agent name cannot be empty or whitespace only.")):e.name.length>255&&r.push(new ConfigValidationError("name","string with length <= 255",e.name,`Agent name is too long (${e.name.length} characters). Use 255 characters or less.`)),void 0===e.registry)r.push(new ConfigValidationError("registry","TrustRegistry (required)",void 0,"Provide a TrustRegistry instance (e.g., new MemoryTrustRegistry() or new HttpTrustRegistry())."));else if("object"!=typeof e.registry||null===e.registry)r.push(new ConfigValidationError("registry","TrustRegistry instance",e.registry,"Registry must be a TrustRegistry instance, not a string or primitive value."));else{const t=e.registry,i=["register","resolve"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("registry","TrustRegistry instance","object missing required methods",`TrustRegistry must implement: ${i.join(", ")}. Use HttpTrustRegistry or MemoryTrustRegistry.`))}if(void 0===e.transport)r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[] (required)",void 0,"Provide a transport adapter (e.g., new HttpsTransportAdapter()) or array of adapters for split-channel."));else{const t=Array.isArray(e.transport);if("object"==typeof e.transport&&null!==e.transport&&!t||t)if(t){const t=e.transport;0===t.length&&r.push(new ConfigValidationError("transport","non-empty array",t,"Provide at least one transport adapter.")),t.forEach((t,e)=>{if("object"!=typeof t||null===t)r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter",t,"Each transport must be a XailTransportAdapter instance."));else{"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}})}else{const t=e.transport;"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError("transport","XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}else r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[]",e.transport,"Provide a single transport adapter or an array of adapters."))}if(void 0!==e.nonceStore)if("object"!=typeof e.nonceStore||null===e.nonceStore)r.push(new ConfigValidationError("nonceStore","NonceStore instance",e.nonceStore,"Provide a NonceStore instance (e.g., new MemoryNonceStore())."));else{const t=e.nonceStore,i=["check","cleanup"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("nonceStore","NonceStore instance","object missing required methods",`NonceStore must implement: ${i.join(", ")}. Use MemoryNonceStore.`))}if(void 0!==e.scopes)if(Array.isArray(e.scopes)){e.scopes.forEach((t,e)=>{"string"!=typeof t?r.push(new ConfigValidationError(`scopes[${e}]`,"string",t,"Each scope must be a string.")):0===t.trim().length&&r.push(new ConfigValidationError(`scopes[${e}]`,"non-empty string",t,"Scope cannot be empty or whitespace only."))})}else r.push(new ConfigValidationError("scopes","string[]",e.scopes,'Provide an array of scope strings (e.g., ["read", "write"]).'));if(void 0!==e.timestampWindowMs&&("number"!=typeof e.timestampWindowMs?r.push(new ConfigValidationError("timestampWindowMs","number (milliseconds)",e.timestampWindowMs,"Provide timestamp window as a number in milliseconds (e.g., 30000 for 30 seconds).")):e.timestampWindowMs<=0?r.push(new ConfigValidationError("timestampWindowMs","positive number",e.timestampWindowMs,"Timestamp window must be greater than 0. Use at least 1000 (1 second).")):e.timestampWindowMs<5e3?r.push(new ConfigValidationError("timestampWindowMs","number >= 5000",e.timestampWindowMs,"Timestamp window is very short. Use at least 5000ms (5 seconds) to account for clock skew.")):e.timestampWindowMs>3e5&&r.push(new ConfigValidationError("timestampWindowMs","number <= 300000",e.timestampWindowMs,"Timestamp window is very long. Consider using 300000ms (5 minutes) or less for security."))),void 0!==e.postQuantumSig&&"boolean"!=typeof e.postQuantumSig&&r.push(new ConfigValidationError("postQuantumSig","boolean",e.postQuantumSig,"Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.")),void 0!==e.xchange&&"boolean"!=typeof e.xchange&&r.push(new ConfigValidationError("xchange","boolean",e.xchange,"Use true to advertise Xchange mode support, or false to disable.")),void 0!==e.securityPolicy)if("object"!=typeof e.securityPolicy||null===e.securityPolicy)r.push(new ConfigValidationError("securityPolicy","SecurityPolicy instance",e.securityPolicy,"Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy)."));else{const t=e.securityPolicy;"classify"in t&&"function"==typeof t.classify||r.push(new ConfigValidationError("securityPolicy","SecurityPolicy with classify() method","object missing classify() method","SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy."))}return r.length>0?err(r[0]):ok(e)}export function getValidationDetails(t){const e=[],r=[],i=validateAgentOptions(t);if(i.ok||e.push(i.error),t&&"object"==typeof t){const e=t;"number"==typeof e.identityTTL&&(e.identityTTL<6e4&&e.identityTTL>0?r.push(`identityTTL is very short (${e.identityTTL}ms). Consider using at least 60000ms (1 minute).`):e.identityTTL>864e5&&r.push(`identityTTL is very long (${e.identityTTL}ms). Consider using 'persistent' identity mode instead.`),"persistent"===e.identity&&r.push("identityTTL is ignored for 'persistent' identity mode."))}return{valid:0===e.length,errors:e,warnings:r}}export function assertValidConfig(t){const e=validateAgentOptions(t);if(!e.ok)throw e.error}export function assertValidCreateConfig(t){const e=validateAgentCreateOptions(t);if(!e.ok)throw e.error}
|
|
@@ -1,274 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @module connect
|
|
3
|
-
* High-level connect() API for zero-config XBind connections.
|
|
4
|
-
*
|
|
5
|
-
* Enables: `const service = await connect('payments-service')`
|
|
6
|
-
*
|
|
7
|
-
* Combines:
|
|
8
|
-
* - Service discovery
|
|
9
|
-
* - Trust verification
|
|
10
|
-
* - Agent creation
|
|
11
|
-
* - Connection establishment
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { connect } from '@private.me/xbind';
|
|
16
|
-
*
|
|
17
|
-
* // Connect by name (uses registry):
|
|
18
|
-
* const payments = await connect('payments-service');
|
|
19
|
-
*
|
|
20
|
-
* // Connect by domain (uses .well-known):
|
|
21
|
-
* const payments = await connect('payments.example.com');
|
|
22
|
-
*
|
|
23
|
-
* // Connect by URL (direct):
|
|
24
|
-
* const payments = await connect('https://api.payments.com/xbind');
|
|
25
|
-
*
|
|
26
|
-
* // Use the connection:
|
|
27
|
-
* await payments.send({
|
|
28
|
-
* to: payments.did,
|
|
29
|
-
* payload: { action: 'createCharge', amount: 100 },
|
|
30
|
-
* scope: 'payments',
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
import { ok, err } from"./_deps/shared/index.js";
|
|
35
|
-
import { fromBase64, toBase64 } from"./_deps/crypto/index.js";
|
|
36
|
-
import { Agent } from './agent.js';
|
|
37
|
-
import { ServiceDiscovery } from './discovery.js';
|
|
38
|
-
import { HttpsTransportAdapter } from './transport.js';
|
|
39
|
-
import { MemoryTrustRegistry } from './trust-registry.js';
|
|
40
|
-
import { importPublicKey } from './identity.js';
|
|
41
|
-
/**
|
|
42
|
-
* Connect error codes.
|
|
43
|
-
*/
|
|
44
|
-
export var ConnectErrorCode;
|
|
45
|
-
(function (ConnectErrorCode) {
|
|
46
|
-
ConnectErrorCode["DISCOVERY_FAILED"] = "CONNECT_DISCOVERY_FAILED";
|
|
47
|
-
ConnectErrorCode["AGENT_CREATION_FAILED"] = "CONNECT_AGENT_CREATION_FAILED";
|
|
48
|
-
ConnectErrorCode["TRUST_VERIFICATION_FAILED"] = "CONNECT_TRUST_VERIFICATION_FAILED";
|
|
49
|
-
ConnectErrorCode["INVALID_SERVICE_INFO"] = "CONNECT_INVALID_SERVICE_INFO";
|
|
50
|
-
})(ConnectErrorCode || (ConnectErrorCode = {}));
|
|
51
|
-
/**
|
|
52
|
-
* Connect to a service with zero configuration.
|
|
53
|
-
*
|
|
54
|
-
* @param nameOrUrl - Service name, domain, or URL
|
|
55
|
-
* @param options - Connection options
|
|
56
|
-
* @returns Connection or error
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* // Minimal:
|
|
61
|
-
* const connection = await connect('payments-service');
|
|
62
|
-
* if (connection.ok) {
|
|
63
|
-
* await connection.value.agent.send({
|
|
64
|
-
* to: connection.value.did,
|
|
65
|
-
* payload: { action: 'test' },
|
|
66
|
-
* scope: 'test',
|
|
67
|
-
* });
|
|
68
|
-
* }
|
|
69
|
-
*
|
|
70
|
-
* // With options:
|
|
71
|
-
* const connection = await connect('payments-service', {
|
|
72
|
-
* name: 'billing-service',
|
|
73
|
-
* xchange: true, // Use faster Xchange mode
|
|
74
|
-
* splitChannel: true, // Use split-channel by default
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export async function connect(nameOrUrl, options = {}) {
|
|
79
|
-
// Step 1: Discover service
|
|
80
|
-
const discovery = options.discovery || new ServiceDiscovery();
|
|
81
|
-
const serviceResult = await discovery.discover(nameOrUrl);
|
|
82
|
-
if (!serviceResult.ok) {
|
|
83
|
-
return err({
|
|
84
|
-
code: ConnectErrorCode.DISCOVERY_FAILED,
|
|
85
|
-
message: `Failed to discover service: ${serviceResult.error.message}`,
|
|
86
|
-
hint: serviceResult.error.hint,
|
|
87
|
-
cause: serviceResult.error,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
const service = serviceResult.value;
|
|
91
|
-
// Step 2: Validate service info
|
|
92
|
-
if (!service.did || !service.endpoint || !service.publicKey) {
|
|
93
|
-
return err({
|
|
94
|
-
code: ConnectErrorCode.INVALID_SERVICE_INFO,
|
|
95
|
-
message: 'Service info missing required fields (did, endpoint, publicKey)',
|
|
96
|
-
hint: 'Service must provide complete metadata',
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
// Step 3: Create trust registry and add service
|
|
100
|
-
const registry = options.registry || new MemoryTrustRegistry();
|
|
101
|
-
try {
|
|
102
|
-
// Import public key (convert from base64 string)
|
|
103
|
-
const publicKeyBytes = fromBase64(service.publicKey);
|
|
104
|
-
const publicKeyResult = await importPublicKey(publicKeyBytes);
|
|
105
|
-
if (!publicKeyResult.ok) {
|
|
106
|
-
return err({
|
|
107
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
108
|
-
message: 'Invalid service public key',
|
|
109
|
-
cause: publicKeyResult.error,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
// Add to trust registry
|
|
113
|
-
await registry.add({
|
|
114
|
-
did: service.did,
|
|
115
|
-
publicKey: publicKeyResult.value,
|
|
116
|
-
x25519PublicKey: service.x25519PublicKey
|
|
117
|
-
? await importPublicKey(fromBase64(service.x25519PublicKey)).then(r => r.ok ? r.value : undefined)
|
|
118
|
-
: undefined,
|
|
119
|
-
mlKemPublicKey: service.mlKemPublicKey
|
|
120
|
-
? fromBase64(service.mlKemPublicKey)
|
|
121
|
-
: undefined,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
return err({
|
|
126
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
127
|
-
message: 'Failed to verify service public key',
|
|
128
|
-
cause: error,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
// Step 4: Create transport
|
|
132
|
-
const transport = options.transport || new HttpsTransportAdapter({
|
|
133
|
-
baseUrl: service.endpoint,
|
|
134
|
-
});
|
|
135
|
-
// Step 5: Create agent
|
|
136
|
-
const agentName = options.name || `client-${Date.now()}`;
|
|
137
|
-
const agentOptions = {
|
|
138
|
-
name: agentName,
|
|
139
|
-
registry,
|
|
140
|
-
transport,
|
|
141
|
-
xchange: options.xchange,
|
|
142
|
-
postQuantumSig: options.postQuantumSig,
|
|
143
|
-
};
|
|
144
|
-
const agentResult = await Agent.create(agentOptions);
|
|
145
|
-
if (!agentResult.ok) {
|
|
146
|
-
return err({
|
|
147
|
-
code: ConnectErrorCode.AGENT_CREATION_FAILED,
|
|
148
|
-
message: 'Failed to create agent',
|
|
149
|
-
cause: agentResult.error,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
// Step 6: Return connection
|
|
153
|
-
return ok({
|
|
154
|
-
agent: agentResult.value,
|
|
155
|
-
service,
|
|
156
|
-
did: service.did,
|
|
157
|
-
endpoint: service.endpoint,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Accept an invite and establish connection.
|
|
162
|
-
*
|
|
163
|
-
* @param inviteUrl - Invite URL
|
|
164
|
-
* @param options - Connection options
|
|
165
|
-
* @returns Connection or error
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```ts
|
|
169
|
-
* const connection = await acceptInvite('https://xbind.to/invite/abc123', {
|
|
170
|
-
* name: 'my-service',
|
|
171
|
-
* });
|
|
172
|
-
*
|
|
173
|
-
* if (connection.ok) {
|
|
174
|
-
* console.log('Connected to:', connection.value.service.name);
|
|
175
|
-
* }
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
export async function acceptInvite(inviteUrl, options = {}) {
|
|
179
|
-
const { InviteService } = await import('./invite.js');
|
|
180
|
-
const inviteService = new InviteService();
|
|
181
|
-
// Get invite details
|
|
182
|
-
const inviteResult = await inviteService.get(inviteUrl);
|
|
183
|
-
if (!inviteResult.ok) {
|
|
184
|
-
return err({
|
|
185
|
-
code: ConnectErrorCode.DISCOVERY_FAILED,
|
|
186
|
-
message: `Failed to get invite: ${inviteResult.error.message}`,
|
|
187
|
-
cause: inviteResult.error,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const invite = inviteResult.value;
|
|
191
|
-
// Convert invite.from to ServiceInfo
|
|
192
|
-
const service = {
|
|
193
|
-
name: invite.from.name,
|
|
194
|
-
did: invite.from.did,
|
|
195
|
-
endpoint: invite.from.endpoint,
|
|
196
|
-
publicKey: invite.from.publicKey,
|
|
197
|
-
x25519PublicKey: invite.from.x25519PublicKey,
|
|
198
|
-
mlKemPublicKey: invite.from.mlKemPublicKey,
|
|
199
|
-
};
|
|
200
|
-
// Connect to service (same as connect())
|
|
201
|
-
// Create trust registry and add service
|
|
202
|
-
const registry = options.registry || new MemoryTrustRegistry();
|
|
203
|
-
try {
|
|
204
|
-
// Import public key (convert from base64 string)
|
|
205
|
-
const publicKeyBytes = fromBase64(service.publicKey);
|
|
206
|
-
const publicKeyResult = await importPublicKey(publicKeyBytes);
|
|
207
|
-
if (!publicKeyResult.ok) {
|
|
208
|
-
return err({
|
|
209
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
210
|
-
message: 'Invalid service public key',
|
|
211
|
-
cause: publicKeyResult.error,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
await registry.add({
|
|
215
|
-
did: service.did,
|
|
216
|
-
publicKey: publicKeyResult.value,
|
|
217
|
-
x25519PublicKey: service.x25519PublicKey
|
|
218
|
-
? await importPublicKey(fromBase64(service.x25519PublicKey)).then(r => r.ok ? r.value : undefined)
|
|
219
|
-
: undefined,
|
|
220
|
-
mlKemPublicKey: service.mlKemPublicKey
|
|
221
|
-
? fromBase64(service.mlKemPublicKey)
|
|
222
|
-
: undefined,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
return err({
|
|
227
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
228
|
-
message: 'Failed to verify service public key',
|
|
229
|
-
cause: error,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
const transport = options.transport || new HttpsTransportAdapter({
|
|
233
|
-
baseUrl: service.endpoint,
|
|
234
|
-
});
|
|
235
|
-
const agentName = options.name || `client-${Date.now()}`;
|
|
236
|
-
const agentOptions = {
|
|
237
|
-
name: agentName,
|
|
238
|
-
registry,
|
|
239
|
-
transport,
|
|
240
|
-
xchange: options.xchange,
|
|
241
|
-
postQuantumSig: options.postQuantumSig,
|
|
242
|
-
};
|
|
243
|
-
const agentResult = await Agent.create(agentOptions);
|
|
244
|
-
if (!agentResult.ok) {
|
|
245
|
-
return err({
|
|
246
|
-
code: ConnectErrorCode.AGENT_CREATION_FAILED,
|
|
247
|
-
message: 'Failed to create agent',
|
|
248
|
-
cause: agentResult.error,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
// Accept the invite
|
|
252
|
-
const acceptResult = await inviteService.accept({
|
|
253
|
-
inviteUrl,
|
|
254
|
-
acceptor: {
|
|
255
|
-
name: agentOptions.name,
|
|
256
|
-
did: agentResult.value.did,
|
|
257
|
-
endpoint: options.endpoint || '', // Agent's endpoint (where it can be reached), empty for client-only agents
|
|
258
|
-
publicKey: toBase64(agentResult.value.identity.rawPublicKey),
|
|
259
|
-
x25519PublicKey: agentResult.value.identity.rawX25519PublicKey
|
|
260
|
-
? toBase64(agentResult.value.identity.rawX25519PublicKey)
|
|
261
|
-
: undefined,
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
if (!acceptResult.ok) {
|
|
265
|
-
// Connection created but invite acceptance failed - still return connection
|
|
266
|
-
// (invite acceptance is for tracking/notification, not required for connectivity)
|
|
267
|
-
}
|
|
268
|
-
return ok({
|
|
269
|
-
agent: agentResult.value,
|
|
270
|
-
service,
|
|
271
|
-
did: service.did,
|
|
272
|
-
endpoint: service.endpoint,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
1
|
+
import{ok,err}from"./_deps/shared/index.js";import{fromBase64,toBase64}from"./crypto-utils.js";import{Agent}from"./agent.js";import{ServiceDiscovery}from"./discovery.js";import{HttpsTransportAdapter}from"./transport.js";import{MemoryTrustRegistry}from"./trust-registry.js";import{importPublicKey}from"./identity.js";export var ConnectErrorCode;!function(e){e.DISCOVERY_FAILED="CONNECT_DISCOVERY_FAILED",e.AGENT_CREATION_FAILED="CONNECT_AGENT_CREATION_FAILED",e.TRUST_VERIFICATION_FAILED="CONNECT_TRUST_VERIFICATION_FAILED",e.INVALID_SERVICE_INFO="CONNECT_INVALID_SERVICE_INFO"}(ConnectErrorCode||(ConnectErrorCode={}));export async function connect(e,r={}){const t=r.discovery||new ServiceDiscovery,i=await t.discover(e);if(!i.ok)return err({code:ConnectErrorCode.DISCOVERY_FAILED,message:`Failed to discover service: ${i.error.message}`,hint:i.error.hint,cause:i.error});const o=i.value;if(!o.did||!o.endpoint||!o.publicKey)return err({code:ConnectErrorCode.INVALID_SERVICE_INFO,message:"Service info missing required fields (did, endpoint, publicKey)",hint:"Service must provide complete metadata"});const n=r.registry||new MemoryTrustRegistry;try{const e=fromBase64(o.publicKey),r=await importPublicKey(e);if(!r.ok)return err({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Invalid service public key",cause:r.error});await n.add({did:o.did,publicKey:r.value,x25519PublicKey:o.x25519PublicKey?await importPublicKey(fromBase64(o.x25519PublicKey)).then(e=>e.ok?e.value:void 0):void 0,mlKemPublicKey:o.mlKemPublicKey?fromBase64(o.mlKemPublicKey):void 0})}catch(e){return err({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Failed to verify service public key",cause:e})}const a=r.transport||new HttpsTransportAdapter({baseUrl:o.endpoint}),c={name:r.name||`client-${Date.now()}`,registry:n,transport:a,xchange:r.xchange,postQuantumSig:r.postQuantumSig},s=await Agent.create(c);return s.ok?ok({agent:s.value,service:o,did:o.did,endpoint:o.endpoint}):err({code:ConnectErrorCode.AGENT_CREATION_FAILED,message:"Failed to create agent",cause:s.error})}export async function acceptInvite(e,r={}){const{InviteService:t}=await import("./invite.js"),i=new t,o=await i.get(e);if(!o.ok)return err({code:ConnectErrorCode.DISCOVERY_FAILED,message:`Failed to get invite: ${o.error.message}`,cause:o.error});const n=o.value,a={name:n.from.name,did:n.from.did,endpoint:n.from.endpoint,publicKey:n.from.publicKey,x25519PublicKey:n.from.x25519PublicKey,mlKemPublicKey:n.from.mlKemPublicKey},c=r.registry||new MemoryTrustRegistry;try{const e=fromBase64(a.publicKey),r=await importPublicKey(e);if(!r.ok)return err({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Invalid service public key",cause:r.error});await c.add({did:a.did,publicKey:r.value,x25519PublicKey:a.x25519PublicKey?await importPublicKey(fromBase64(a.x25519PublicKey)).then(e=>e.ok?e.value:void 0):void 0,mlKemPublicKey:a.mlKemPublicKey?fromBase64(a.mlKemPublicKey):void 0})}catch(e){return err({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Failed to verify service public key",cause:e})}const s=r.transport||new HttpsTransportAdapter({baseUrl:a.endpoint}),d={name:r.name||`client-${Date.now()}`,registry:c,transport:s,xchange:r.xchange,postQuantumSig:r.postQuantumSig},u=await Agent.create(d);if(!u.ok)return err({code:ConnectErrorCode.AGENT_CREATION_FAILED,message:"Failed to create agent",cause:u.error});return(await i.accept({inviteUrl:e,acceptor:{name:d.name,did:u.value.did,endpoint:r.endpoint||"",publicKey:toBase64(u.value.identity.rawPublicKey),x25519PublicKey:u.value.identity.rawX25519PublicKey?toBase64(u.value.identity.rawX25519PublicKey):void 0}})).ok,ok({agent:u.value,service:a,did:a.did,endpoint:a.endpoint})}
|