@private.me/xbind 1.3.0 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -275
- package/dist-standalone/_deps/shared/cjs/index.js +1 -138
- package/dist-standalone/_deps/shared/cjs/types.js +1 -90
- package/dist-standalone/_deps/shared/errors.js +1 -262
- package/dist-standalone/_deps/shared/index.js +1 -77
- package/dist-standalone/_deps/shared/types.js +1 -91
- 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 -541
- 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 -516
- 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 +66 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -209
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -103
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -119
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -71
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -86
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -57
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -68
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -152
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -199
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -61
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -24
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -221
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -109
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -66
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -45
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -53
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -63
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -148
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -195
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -56
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -15
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -215
- 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,312 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module connect
|
|
4
|
-
* High-level connect() API for zero-config XBind connections.
|
|
5
|
-
*
|
|
6
|
-
* Enables: `const service = await connect('payments-service')`
|
|
7
|
-
*
|
|
8
|
-
* Combines:
|
|
9
|
-
* - Service discovery
|
|
10
|
-
* - Trust verification
|
|
11
|
-
* - Agent creation
|
|
12
|
-
* - Connection establishment
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { connect } from '@private.me/xbind';
|
|
17
|
-
*
|
|
18
|
-
* // Connect by name (uses registry):
|
|
19
|
-
* const payments = await connect('payments-service');
|
|
20
|
-
*
|
|
21
|
-
* // Connect by domain (uses .well-known):
|
|
22
|
-
* const payments = await connect('payments.example.com');
|
|
23
|
-
*
|
|
24
|
-
* // Connect by URL (direct):
|
|
25
|
-
* const payments = await connect('https://api.payments.com/xbind');
|
|
26
|
-
*
|
|
27
|
-
* // Use the connection:
|
|
28
|
-
* await payments.send({
|
|
29
|
-
* to: payments.did,
|
|
30
|
-
* payload: { action: 'createCharge', amount: 100 },
|
|
31
|
-
* scope: 'payments',
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
36
|
-
if (k2 === undefined) k2 = k;
|
|
37
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
38
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
39
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
40
|
-
}
|
|
41
|
-
Object.defineProperty(o, k2, desc);
|
|
42
|
-
}) : (function(o, m, k, k2) {
|
|
43
|
-
if (k2 === undefined) k2 = k;
|
|
44
|
-
o[k2] = m[k];
|
|
45
|
-
}));
|
|
46
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
47
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
48
|
-
}) : function(o, v) {
|
|
49
|
-
o["default"] = v;
|
|
50
|
-
});
|
|
51
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
52
|
-
var ownKeys = function(o) {
|
|
53
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
54
|
-
var ar = [];
|
|
55
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
56
|
-
return ar;
|
|
57
|
-
};
|
|
58
|
-
return ownKeys(o);
|
|
59
|
-
};
|
|
60
|
-
return function (mod) {
|
|
61
|
-
if (mod && mod.__esModule) return mod;
|
|
62
|
-
var result = {};
|
|
63
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
64
|
-
__setModuleDefault(result, mod);
|
|
65
|
-
return result;
|
|
66
|
-
};
|
|
67
|
-
})();
|
|
68
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
-
exports.ConnectErrorCode = void 0;
|
|
70
|
-
exports.connect = connect;
|
|
71
|
-
exports.acceptInvite = acceptInvite;
|
|
72
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
73
|
-
const crypto_1 = require("../_deps/crypto/index.js");
|
|
74
|
-
const agent_js_1 = require("./agent.js");
|
|
75
|
-
const discovery_js_1 = require("./discovery.js");
|
|
76
|
-
const transport_js_1 = require("./transport.js");
|
|
77
|
-
const trust_registry_js_1 = require("./trust-registry.js");
|
|
78
|
-
const identity_js_1 = require("./identity.js");
|
|
79
|
-
/**
|
|
80
|
-
* Connect error codes.
|
|
81
|
-
*/
|
|
82
|
-
var ConnectErrorCode;
|
|
83
|
-
(function (ConnectErrorCode) {
|
|
84
|
-
ConnectErrorCode["DISCOVERY_FAILED"] = "CONNECT_DISCOVERY_FAILED";
|
|
85
|
-
ConnectErrorCode["AGENT_CREATION_FAILED"] = "CONNECT_AGENT_CREATION_FAILED";
|
|
86
|
-
ConnectErrorCode["TRUST_VERIFICATION_FAILED"] = "CONNECT_TRUST_VERIFICATION_FAILED";
|
|
87
|
-
ConnectErrorCode["INVALID_SERVICE_INFO"] = "CONNECT_INVALID_SERVICE_INFO";
|
|
88
|
-
})(ConnectErrorCode || (exports.ConnectErrorCode = ConnectErrorCode = {}));
|
|
89
|
-
/**
|
|
90
|
-
* Connect to a service with zero configuration.
|
|
91
|
-
*
|
|
92
|
-
* @param nameOrUrl - Service name, domain, or URL
|
|
93
|
-
* @param options - Connection options
|
|
94
|
-
* @returns Connection or error
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* // Minimal:
|
|
99
|
-
* const connection = await connect('payments-service');
|
|
100
|
-
* if (connection.ok) {
|
|
101
|
-
* await connection.value.agent.send({
|
|
102
|
-
* to: connection.value.did,
|
|
103
|
-
* payload: { action: 'test' },
|
|
104
|
-
* scope: 'test',
|
|
105
|
-
* });
|
|
106
|
-
* }
|
|
107
|
-
*
|
|
108
|
-
* // With options:
|
|
109
|
-
* const connection = await connect('payments-service', {
|
|
110
|
-
* name: 'billing-service',
|
|
111
|
-
* xchange: true, // Use faster Xchange mode
|
|
112
|
-
* splitChannel: true, // Use split-channel by default
|
|
113
|
-
* });
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
async function connect(nameOrUrl, options = {}) {
|
|
117
|
-
// Step 1: Discover service
|
|
118
|
-
const discovery = options.discovery || new discovery_js_1.ServiceDiscovery();
|
|
119
|
-
const serviceResult = await discovery.discover(nameOrUrl);
|
|
120
|
-
if (!serviceResult.ok) {
|
|
121
|
-
return (0, shared_1.err)({
|
|
122
|
-
code: ConnectErrorCode.DISCOVERY_FAILED,
|
|
123
|
-
message: `Failed to discover service: ${serviceResult.error.message}`,
|
|
124
|
-
hint: serviceResult.error.hint,
|
|
125
|
-
cause: serviceResult.error,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
const service = serviceResult.value;
|
|
129
|
-
// Step 2: Validate service info
|
|
130
|
-
if (!service.did || !service.endpoint || !service.publicKey) {
|
|
131
|
-
return (0, shared_1.err)({
|
|
132
|
-
code: ConnectErrorCode.INVALID_SERVICE_INFO,
|
|
133
|
-
message: 'Service info missing required fields (did, endpoint, publicKey)',
|
|
134
|
-
hint: 'Service must provide complete metadata',
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// Step 3: Create trust registry and add service
|
|
138
|
-
const registry = options.registry || new trust_registry_js_1.MemoryTrustRegistry();
|
|
139
|
-
try {
|
|
140
|
-
// Import public key (convert from base64 string)
|
|
141
|
-
const publicKeyBytes = (0, crypto_1.fromBase64)(service.publicKey);
|
|
142
|
-
const publicKeyResult = await (0, identity_js_1.importPublicKey)(publicKeyBytes);
|
|
143
|
-
if (!publicKeyResult.ok) {
|
|
144
|
-
return (0, shared_1.err)({
|
|
145
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
146
|
-
message: 'Invalid service public key',
|
|
147
|
-
cause: publicKeyResult.error,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
// Add to trust registry
|
|
151
|
-
await registry.add({
|
|
152
|
-
did: service.did,
|
|
153
|
-
publicKey: publicKeyResult.value,
|
|
154
|
-
x25519PublicKey: service.x25519PublicKey
|
|
155
|
-
? await (0, identity_js_1.importPublicKey)((0, crypto_1.fromBase64)(service.x25519PublicKey)).then(r => r.ok ? r.value : undefined)
|
|
156
|
-
: undefined,
|
|
157
|
-
mlKemPublicKey: service.mlKemPublicKey
|
|
158
|
-
? (0, crypto_1.fromBase64)(service.mlKemPublicKey)
|
|
159
|
-
: undefined,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
return (0, shared_1.err)({
|
|
164
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
165
|
-
message: 'Failed to verify service public key',
|
|
166
|
-
cause: error,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
// Step 4: Create transport
|
|
170
|
-
const transport = options.transport || new transport_js_1.HttpsTransportAdapter({
|
|
171
|
-
baseUrl: service.endpoint,
|
|
172
|
-
});
|
|
173
|
-
// Step 5: Create agent
|
|
174
|
-
const agentName = options.name || `client-${Date.now()}`;
|
|
175
|
-
const agentOptions = {
|
|
176
|
-
name: agentName,
|
|
177
|
-
registry,
|
|
178
|
-
transport,
|
|
179
|
-
xchange: options.xchange,
|
|
180
|
-
postQuantumSig: options.postQuantumSig,
|
|
181
|
-
};
|
|
182
|
-
const agentResult = await agent_js_1.Agent.create(agentOptions);
|
|
183
|
-
if (!agentResult.ok) {
|
|
184
|
-
return (0, shared_1.err)({
|
|
185
|
-
code: ConnectErrorCode.AGENT_CREATION_FAILED,
|
|
186
|
-
message: 'Failed to create agent',
|
|
187
|
-
cause: agentResult.error,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
// Step 6: Return connection
|
|
191
|
-
return (0, shared_1.ok)({
|
|
192
|
-
agent: agentResult.value,
|
|
193
|
-
service,
|
|
194
|
-
did: service.did,
|
|
195
|
-
endpoint: service.endpoint,
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Accept an invite and establish connection.
|
|
200
|
-
*
|
|
201
|
-
* @param inviteUrl - Invite URL
|
|
202
|
-
* @param options - Connection options
|
|
203
|
-
* @returns Connection or error
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```ts
|
|
207
|
-
* const connection = await acceptInvite('https://xbind.to/invite/abc123', {
|
|
208
|
-
* name: 'my-service',
|
|
209
|
-
* });
|
|
210
|
-
*
|
|
211
|
-
* if (connection.ok) {
|
|
212
|
-
* console.log('Connected to:', connection.value.service.name);
|
|
213
|
-
* }
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
async function acceptInvite(inviteUrl, options = {}) {
|
|
217
|
-
const { InviteService } = await Promise.resolve().then(() => __importStar(require('./invite.js')));
|
|
218
|
-
const inviteService = new InviteService();
|
|
219
|
-
// Get invite details
|
|
220
|
-
const inviteResult = await inviteService.get(inviteUrl);
|
|
221
|
-
if (!inviteResult.ok) {
|
|
222
|
-
return (0, shared_1.err)({
|
|
223
|
-
code: ConnectErrorCode.DISCOVERY_FAILED,
|
|
224
|
-
message: `Failed to get invite: ${inviteResult.error.message}`,
|
|
225
|
-
cause: inviteResult.error,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
const invite = inviteResult.value;
|
|
229
|
-
// Convert invite.from to ServiceInfo
|
|
230
|
-
const service = {
|
|
231
|
-
name: invite.from.name,
|
|
232
|
-
did: invite.from.did,
|
|
233
|
-
endpoint: invite.from.endpoint,
|
|
234
|
-
publicKey: invite.from.publicKey,
|
|
235
|
-
x25519PublicKey: invite.from.x25519PublicKey,
|
|
236
|
-
mlKemPublicKey: invite.from.mlKemPublicKey,
|
|
237
|
-
};
|
|
238
|
-
// Connect to service (same as connect())
|
|
239
|
-
// Create trust registry and add service
|
|
240
|
-
const registry = options.registry || new trust_registry_js_1.MemoryTrustRegistry();
|
|
241
|
-
try {
|
|
242
|
-
// Import public key (convert from base64 string)
|
|
243
|
-
const publicKeyBytes = (0, crypto_1.fromBase64)(service.publicKey);
|
|
244
|
-
const publicKeyResult = await (0, identity_js_1.importPublicKey)(publicKeyBytes);
|
|
245
|
-
if (!publicKeyResult.ok) {
|
|
246
|
-
return (0, shared_1.err)({
|
|
247
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
248
|
-
message: 'Invalid service public key',
|
|
249
|
-
cause: publicKeyResult.error,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
await registry.add({
|
|
253
|
-
did: service.did,
|
|
254
|
-
publicKey: publicKeyResult.value,
|
|
255
|
-
x25519PublicKey: service.x25519PublicKey
|
|
256
|
-
? await (0, identity_js_1.importPublicKey)((0, crypto_1.fromBase64)(service.x25519PublicKey)).then(r => r.ok ? r.value : undefined)
|
|
257
|
-
: undefined,
|
|
258
|
-
mlKemPublicKey: service.mlKemPublicKey
|
|
259
|
-
? (0, crypto_1.fromBase64)(service.mlKemPublicKey)
|
|
260
|
-
: undefined,
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
return (0, shared_1.err)({
|
|
265
|
-
code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
|
|
266
|
-
message: 'Failed to verify service public key',
|
|
267
|
-
cause: error,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
const transport = options.transport || new transport_js_1.HttpsTransportAdapter({
|
|
271
|
-
baseUrl: service.endpoint,
|
|
272
|
-
});
|
|
273
|
-
const agentName = options.name || `client-${Date.now()}`;
|
|
274
|
-
const agentOptions = {
|
|
275
|
-
name: agentName,
|
|
276
|
-
registry,
|
|
277
|
-
transport,
|
|
278
|
-
xchange: options.xchange,
|
|
279
|
-
postQuantumSig: options.postQuantumSig,
|
|
280
|
-
};
|
|
281
|
-
const agentResult = await agent_js_1.Agent.create(agentOptions);
|
|
282
|
-
if (!agentResult.ok) {
|
|
283
|
-
return (0, shared_1.err)({
|
|
284
|
-
code: ConnectErrorCode.AGENT_CREATION_FAILED,
|
|
285
|
-
message: 'Failed to create agent',
|
|
286
|
-
cause: agentResult.error,
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
// Accept the invite
|
|
290
|
-
const acceptResult = await inviteService.accept({
|
|
291
|
-
inviteUrl,
|
|
292
|
-
acceptor: {
|
|
293
|
-
name: agentOptions.name,
|
|
294
|
-
did: agentResult.value.did,
|
|
295
|
-
endpoint: options.endpoint || '', // Agent's endpoint (where it can be reached), empty for client-only agents
|
|
296
|
-
publicKey: (0, crypto_1.toBase64)(agentResult.value.identity.rawPublicKey),
|
|
297
|
-
x25519PublicKey: agentResult.value.identity.rawX25519PublicKey
|
|
298
|
-
? (0, crypto_1.toBase64)(agentResult.value.identity.rawX25519PublicKey)
|
|
299
|
-
: undefined,
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
if (!acceptResult.ok) {
|
|
303
|
-
// Connection created but invite acceptance failed - still return connection
|
|
304
|
-
// (invite acceptance is for tracking/notification, not required for connectivity)
|
|
305
|
-
}
|
|
306
|
-
return (0, shared_1.ok)({
|
|
307
|
-
agent: agentResult.value,
|
|
308
|
-
service,
|
|
309
|
-
did: service.did,
|
|
310
|
-
endpoint: service.endpoint,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,i,o)}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),__importStar=this&&this.__importStar||function(){var e=function(r){return e=Object.getOwnPropertyNames||function(e){var r=[];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[r.length]=t);return r},e(r)};return function(r){if(r&&r.__esModule)return r;var t={};if(null!=r)for(var i=e(r),o=0;o<i.length;o++)"default"!==i[o]&&__createBinding(t,r,i[o]);return __setModuleDefault(t,r),t}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConnectErrorCode=void 0,exports.connect=connect,exports.acceptInvite=acceptInvite;const shared_1=require("../_deps/shared/index.js"),crypto_utils_js_1=require("./crypto-utils.js"),agent_js_1=require("./agent.js"),discovery_js_1=require("./discovery.js"),transport_js_1=require("./transport.js"),trust_registry_js_1=require("./trust-registry.js"),identity_js_1=require("./identity.js");var ConnectErrorCode;async function connect(e,r={}){const t=r.discovery||new discovery_js_1.ServiceDiscovery,i=await t.discover(e);if(!i.ok)return(0,shared_1.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(0,shared_1.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 trust_registry_js_1.MemoryTrustRegistry;try{const e=(0,crypto_utils_js_1.fromBase64)(o.publicKey),r=await(0,identity_js_1.importPublicKey)(e);if(!r.ok)return(0,shared_1.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(0,identity_js_1.importPublicKey)((0,crypto_utils_js_1.fromBase64)(o.x25519PublicKey)).then(e=>e.ok?e.value:void 0):void 0,mlKemPublicKey:o.mlKemPublicKey?(0,crypto_utils_js_1.fromBase64)(o.mlKemPublicKey):void 0})}catch(e){return(0,shared_1.err)({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Failed to verify service public key",cause:e})}const s=r.transport||new transport_js_1.HttpsTransportAdapter({baseUrl:o.endpoint}),a={name:r.name||`client-${Date.now()}`,registry:n,transport:s,xchange:r.xchange,postQuantumSig:r.postQuantumSig},c=await agent_js_1.Agent.create(a);return c.ok?(0,shared_1.ok)({agent:c.value,service:o,did:o.did,endpoint:o.endpoint}):(0,shared_1.err)({code:ConnectErrorCode.AGENT_CREATION_FAILED,message:"Failed to create agent",cause:c.error})}async function acceptInvite(e,r={}){const{InviteService:t}=await Promise.resolve().then(()=>__importStar(require("./invite.js"))),i=new t,o=await i.get(e);if(!o.ok)return(0,shared_1.err)({code:ConnectErrorCode.DISCOVERY_FAILED,message:`Failed to get invite: ${o.error.message}`,cause:o.error});const n=o.value,s={name:n.from.name,did:n.from.did,endpoint:n.from.endpoint,publicKey:n.from.publicKey,x25519PublicKey:n.from.x25519PublicKey,mlKemPublicKey:n.from.mlKemPublicKey},a=r.registry||new trust_registry_js_1.MemoryTrustRegistry;try{const e=(0,crypto_utils_js_1.fromBase64)(s.publicKey),r=await(0,identity_js_1.importPublicKey)(e);if(!r.ok)return(0,shared_1.err)({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Invalid service public key",cause:r.error});await a.add({did:s.did,publicKey:r.value,x25519PublicKey:s.x25519PublicKey?await(0,identity_js_1.importPublicKey)((0,crypto_utils_js_1.fromBase64)(s.x25519PublicKey)).then(e=>e.ok?e.value:void 0):void 0,mlKemPublicKey:s.mlKemPublicKey?(0,crypto_utils_js_1.fromBase64)(s.mlKemPublicKey):void 0})}catch(e){return(0,shared_1.err)({code:ConnectErrorCode.TRUST_VERIFICATION_FAILED,message:"Failed to verify service public key",cause:e})}const c=r.transport||new transport_js_1.HttpsTransportAdapter({baseUrl:s.endpoint}),u={name:r.name||`client-${Date.now()}`,registry:a,transport:c,xchange:r.xchange,postQuantumSig:r.postQuantumSig},d=await agent_js_1.Agent.create(u);if(!d.ok)return(0,shared_1.err)({code:ConnectErrorCode.AGENT_CREATION_FAILED,message:"Failed to create agent",cause:d.error});return(await i.accept({inviteUrl:e,acceptor:{name:u.name,did:d.value.did,endpoint:r.endpoint||"",publicKey:(0,crypto_utils_js_1.toBase64)(d.value.identity.rawPublicKey),x25519PublicKey:d.value.identity.rawX25519PublicKey?(0,crypto_utils_js_1.toBase64)(d.value.identity.rawX25519PublicKey):void 0}})).ok,(0,shared_1.ok)({agent:d.value,service:s,did:s.did,endpoint:s.endpoint})}!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||(exports.ConnectErrorCode=ConnectErrorCode={}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConnectionPool=void 0,exports.getGlobalPool=getGlobalPool,exports.resetGlobalPool=resetGlobalPool;class ConnectionPool{options;connections=new Map;metrics;cleanupInterval=null;constructor(t={}){this.options={maxConnections:t.maxConnections??10,minConnections:t.minConnections??2,keepAliveTimeout:t.keepAliveTimeout??3e4,idleTimeout:t.idleTimeout??6e4,requestTimeout:t.requestTimeout??3e4,enableMetrics:t.enableMetrics??!0,retryOnFailure:t.retryOnFailure??!0,maxRetries:t.maxRetries??3},this.metrics={totalRequests:0,reuseCount:0,failedRequests:0,requestDurations:[],byOrigin:new Map},this.startCleanup()}async fetch(t,e){const s=Date.now(),n=this.getOrigin(t);try{const o=await this.acquireConnection(n);this.options.enableMetrics&&(this.metrics.totalRequests++,o.requestCount>0&&this.metrics.reuseCount++);const i={...e,signal:e?.signal??o.controller.signal,keepalive:!0},r=await fetch(t,i);if(o.requestCount++,o.lastUsedAt=Date.now(),o.state="idle",this.options.enableMetrics){const t=Date.now()-s;this.recordMetrics(n,t)}return r}catch(s){if(this.options.enableMetrics&&this.metrics.failedRequests++,this.options.retryOnFailure&&!0!==e?.signal?.aborted)return this.retryRequest(t,e,1);throw s}}async retryRequest(t,e,s){if(s>this.options.maxRetries)throw new Error(`Request failed after ${this.options.maxRetries} retries: ${t}`);const n=100*Math.pow(2,s-1);await new Promise(t=>setTimeout(t,n));const o=this.getOrigin(t);try{const s=await this.acquireConnection(o),n={...e,signal:e?.signal??s.controller.signal,keepalive:!0},i=await fetch(t,n);return s.requestCount++,s.lastUsedAt=Date.now(),s.state="idle",i}catch(n){if(s>=this.options.maxRetries)throw new Error(`Request failed after ${this.options.maxRetries} retries: ${t}`);return this.retryRequest(t,e,s+1)}}async acquireConnection(t){let e=this.connections.get(t);e||(e=[],this.connections.set(t,e));const s=e.find(t=>"idle"===t.state);if(s)return s.state="active",s;if(e.length<this.options.maxConnections){const s=this.createConnection(t);return e.push(s),s}return this.waitForConnection(t)}async waitForConnection(t){const e=Date.now(),s=this.options.requestTimeout;for(;Date.now()-e<s;){const e=this.connections.get(t);if(!e)throw new Error(`Connection pool for ${t} disappeared`);const s=e.find(t=>"idle"===t.state);if(s)return s.state="active",s;await new Promise(t=>setTimeout(t,10))}throw new Error(`Timeout waiting for connection to ${t} after ${s}ms`)}createConnection(t){const e=new Uint8Array(8);crypto.getRandomValues(e);return{id:`conn_${Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}`,origin:t,createdAt:Date.now(),lastUsedAt:Date.now(),requestCount:0,state:"active",controller:new AbortController}}getOrigin(t){try{const e=new URL(t);return`${e.protocol}//${e.host}`}catch(e){throw new Error(`Invalid URL: ${t}`)}}recordMetrics(t,e){this.metrics.requestDurations.push(e),this.metrics.requestDurations.length>1e3&&this.metrics.requestDurations.shift();let s=this.metrics.byOrigin.get(t);s||(s={requests:0,durations:[]},this.metrics.byOrigin.set(t,s)),s.requests++,s.durations.push(e),s.durations.length>100&&s.durations.shift()}getMetrics(){let t=0,e=0,s=0;const n=new Map;for(const[o,i]of this.connections.entries()){t+=i.length,e+=i.filter(t=>"active"===t.state).length,s+=i.filter(t=>"idle"===t.state).length;const r=this.metrics.byOrigin.get(o);if(r){const t=r.durations.length>0?r.durations.reduce((t,e)=>t+e,0)/r.durations.length:0;n.set(o,{connections:i.length,requests:r.requests,avgDuration:Math.round(t)})}}const o=this.metrics.requestDurations.length>0?Math.round(this.metrics.requestDurations.reduce((t,e)=>t+e,0)/this.metrics.requestDurations.length):0,i=this.metrics.totalRequests>0?this.metrics.reuseCount/this.metrics.totalRequests:0;return{totalConnections:t,activeConnections:e,idleConnections:s,totalRequests:this.metrics.totalRequests,reuseCount:this.metrics.reuseCount,failedRequests:this.metrics.failedRequests,avgRequestDuration:o,hitRate:i,byOrigin:n}}resetMetrics(){this.metrics={totalRequests:0,reuseCount:0,failedRequests:0,requestDurations:[],byOrigin:new Map}}startCleanup(){this.cleanupInterval=setInterval(()=>{this.cleanup()},1e4)}cleanup(){const t=Date.now();for(const[e,s]of this.connections.entries()){const n=s.filter(e=>t-e.lastUsedAt>this.options.idleTimeout&&"idle"===e.state?(e.controller.abort(),e.state="closed",!1):"closed"!==e.state);for(;n.length<this.options.minConnections&&n.length<this.options.maxConnections;){const t=this.createConnection(e);t.state="idle",n.push(t)}n.length>0?this.connections.set(e,n):this.connections.delete(e)}}cleanupNow(){this.cleanup()}async close(){this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null);for(const[t,e]of this.connections.entries())for(const t of e)t.controller.abort(),t.state="closed";this.connections.clear()}getConnectionCount(t){const e=this.connections.get(t);return e?e.length:0}getOrigins(){return Array.from(this.connections.keys())}isHealthy(){const t=this.getMetrics();return!((t.totalRequests>0?t.failedRequests/t.totalRequests:0)>.1)&&!(t.avgRequestDuration>5e3)}}exports.ConnectionPool=ConnectionPool;let globalPool=null;function getGlobalPool(t){return globalPool||(globalPool=new ConnectionPool(t)),globalPool}async function resetGlobalPool(){globalPool&&(await globalPool.close(),globalPool=null)}
|
|
@@ -1,339 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module correlation-id
|
|
4
|
-
* Client-side correlation ID utilities for request tracking
|
|
5
|
-
*
|
|
6
|
-
* Correlation IDs enable distributed tracing across xBind agent operations,
|
|
7
|
-
* making it easier to debug issues, track requests across microservices,
|
|
8
|
-
* and correlate logs between client and server.
|
|
9
|
-
*
|
|
10
|
-
* Format: `req_{timestamp}_{random}`
|
|
11
|
-
* Example: `req_1716234567890_a3f5c9d2`
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { generateCorrelationId, attachCorrelationId } from '@private.me/xbind';
|
|
16
|
-
*
|
|
17
|
-
* // Generate a new correlation ID
|
|
18
|
-
* const id = generateCorrelationId();
|
|
19
|
-
*
|
|
20
|
-
* // Attach to request headers
|
|
21
|
-
* const headers = attachCorrelationId(new Headers(), id);
|
|
22
|
-
*
|
|
23
|
-
* // Validate format
|
|
24
|
-
* if (validateCorrelationId(id)) {
|
|
25
|
-
* console.log('Valid correlation ID');
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.CORRELATION_ID_ALIASES = exports.CORRELATION_ID_HEADER = void 0;
|
|
31
|
-
exports.generateCorrelationId = generateCorrelationId;
|
|
32
|
-
exports.validateCorrelationId = validateCorrelationId;
|
|
33
|
-
exports.parseCorrelationId = parseCorrelationId;
|
|
34
|
-
exports.attachCorrelationId = attachCorrelationId;
|
|
35
|
-
exports.extractCorrelationId = extractCorrelationId;
|
|
36
|
-
exports.getOrCreateCorrelationId = getOrCreateCorrelationId;
|
|
37
|
-
exports.createCorrelationIdFromTimestamp = createCorrelationIdFromTimestamp;
|
|
38
|
-
exports.getCorrelationIdAge = getCorrelationIdAge;
|
|
39
|
-
exports.isCorrelationIdExpired = isCorrelationIdExpired;
|
|
40
|
-
exports.correlationIdMiddleware = correlationIdMiddleware;
|
|
41
|
-
/**
|
|
42
|
-
* Standard header name for correlation ID
|
|
43
|
-
*/
|
|
44
|
-
exports.CORRELATION_ID_HEADER = 'X-Correlation-ID';
|
|
45
|
-
/**
|
|
46
|
-
* Alternative header names for compatibility
|
|
47
|
-
*/
|
|
48
|
-
exports.CORRELATION_ID_ALIASES = [
|
|
49
|
-
'X-Request-ID',
|
|
50
|
-
'X-Trace-ID',
|
|
51
|
-
'X-Transaction-ID',
|
|
52
|
-
];
|
|
53
|
-
/**
|
|
54
|
-
* Regular expression for validating correlation ID format
|
|
55
|
-
*/
|
|
56
|
-
const CORRELATION_ID_PATTERN = /^req_\d{13}_[a-f0-9]{8}$/;
|
|
57
|
-
/**
|
|
58
|
-
* Generate a new correlation ID
|
|
59
|
-
*
|
|
60
|
-
* Format: `req_{timestamp}_{random}`
|
|
61
|
-
* - `req`: Static prefix for identification
|
|
62
|
-
* - `timestamp`: Unix timestamp in milliseconds (13 digits)
|
|
63
|
-
* - `random`: 8-character hex string for uniqueness
|
|
64
|
-
*
|
|
65
|
-
* @returns New correlation ID string
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const id = generateCorrelationId();
|
|
70
|
-
* // => "req_1716234567890_a3f5c9d2"
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
function generateCorrelationId() {
|
|
74
|
-
const timestamp = Date.now();
|
|
75
|
-
const random = generateRandomHex(8);
|
|
76
|
-
return `req_${timestamp}_${random}`;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Validate correlation ID format
|
|
80
|
-
*
|
|
81
|
-
* Checks if the provided string matches the expected correlation ID format.
|
|
82
|
-
*
|
|
83
|
-
* @param id - String to validate
|
|
84
|
-
* @returns True if valid, false otherwise
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* validateCorrelationId('req_1716234567890_a3f5c9d2'); // => true
|
|
89
|
-
* validateCorrelationId('invalid'); // => false
|
|
90
|
-
* validateCorrelationId('req_123_abc'); // => false (wrong lengths)
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
function validateCorrelationId(id) {
|
|
94
|
-
if (typeof id !== 'string')
|
|
95
|
-
return false;
|
|
96
|
-
return CORRELATION_ID_PATTERN.test(id);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Parse correlation ID into components
|
|
100
|
-
*
|
|
101
|
-
* Extracts the timestamp and random components from a correlation ID.
|
|
102
|
-
*
|
|
103
|
-
* @param id - Correlation ID to parse
|
|
104
|
-
* @returns Parsed components or null if invalid
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const spec = parseCorrelationId('req_1716234567890_a3f5c9d2');
|
|
109
|
-
* // => { prefix: 'req', timestamp: 1716234567890, random: 'a3f5c9d2' }
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
function parseCorrelationId(id) {
|
|
113
|
-
if (!validateCorrelationId(id))
|
|
114
|
-
return null;
|
|
115
|
-
const parts = id.split('_');
|
|
116
|
-
return {
|
|
117
|
-
prefix: parts[0] ?? 'req',
|
|
118
|
-
timestamp: parseInt(parts[1] ?? '0', 10),
|
|
119
|
-
random: parts[2] ?? '',
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Attach correlation ID to request headers
|
|
124
|
-
*
|
|
125
|
-
* Adds the correlation ID to the X-Correlation-ID header.
|
|
126
|
-
* If no ID is provided, generates a new one.
|
|
127
|
-
* Compatible with both Headers API and plain objects.
|
|
128
|
-
*
|
|
129
|
-
* @param headers - Headers object or plain object
|
|
130
|
-
* @param id - Correlation ID (generates new if not provided)
|
|
131
|
-
* @returns Updated headers object
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* // With Headers API
|
|
136
|
-
* const headers = new Headers();
|
|
137
|
-
* attachCorrelationId(headers);
|
|
138
|
-
*
|
|
139
|
-
* // With plain object
|
|
140
|
-
* const headers = { 'Content-Type': 'application/json' };
|
|
141
|
-
* attachCorrelationId(headers, 'req_1716234567890_a3f5c9d2');
|
|
142
|
-
*
|
|
143
|
-
* // With existing correlation ID
|
|
144
|
-
* const id = generateCorrelationId();
|
|
145
|
-
* attachCorrelationId(headers, id);
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
function attachCorrelationId(headers, id) {
|
|
149
|
-
const correlationId = id ?? generateCorrelationId();
|
|
150
|
-
if (!validateCorrelationId(correlationId)) {
|
|
151
|
-
throw new Error(`Invalid correlation ID format: ${correlationId}. Expected format: req_{timestamp}_{random}`);
|
|
152
|
-
}
|
|
153
|
-
if (headers instanceof Headers) {
|
|
154
|
-
headers.set(exports.CORRELATION_ID_HEADER, correlationId);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
headers[exports.CORRELATION_ID_HEADER] = correlationId;
|
|
158
|
-
}
|
|
159
|
-
return headers;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Extract correlation ID from request headers
|
|
163
|
-
*
|
|
164
|
-
* Checks the standard header and common aliases.
|
|
165
|
-
*
|
|
166
|
-
* @param headers - Headers object or plain object
|
|
167
|
-
* @returns Correlation ID if found, undefined otherwise
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* const headers = new Headers({
|
|
172
|
-
* 'X-Correlation-ID': 'req_1716234567890_a3f5c9d2'
|
|
173
|
-
* });
|
|
174
|
-
* const id = extractCorrelationId(headers);
|
|
175
|
-
* // => 'req_1716234567890_a3f5c9d2'
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
function extractCorrelationId(headers) {
|
|
179
|
-
// Check primary header
|
|
180
|
-
const primary = headers instanceof Headers
|
|
181
|
-
? headers.get(exports.CORRELATION_ID_HEADER)
|
|
182
|
-
: headers[exports.CORRELATION_ID_HEADER];
|
|
183
|
-
if (primary && validateCorrelationId(primary)) {
|
|
184
|
-
return primary;
|
|
185
|
-
}
|
|
186
|
-
// Check aliases
|
|
187
|
-
for (const alias of exports.CORRELATION_ID_ALIASES) {
|
|
188
|
-
const value = headers instanceof Headers ? headers.get(alias) : headers[alias];
|
|
189
|
-
if (value && validateCorrelationId(value)) {
|
|
190
|
-
return value;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return undefined;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Get or create correlation ID from headers
|
|
197
|
-
*
|
|
198
|
-
* Returns existing correlation ID from headers, or generates a new one if not found.
|
|
199
|
-
* Does NOT modify the input headers.
|
|
200
|
-
*
|
|
201
|
-
* @param headers - Headers to check
|
|
202
|
-
* @returns Existing or new correlation ID
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* const headers = new Headers();
|
|
207
|
-
* const id = getOrCreateCorrelationId(headers);
|
|
208
|
-
* // => Generates new ID if not found in headers
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
function getOrCreateCorrelationId(headers) {
|
|
212
|
-
if (!headers)
|
|
213
|
-
return generateCorrelationId();
|
|
214
|
-
const existing = extractCorrelationId(headers);
|
|
215
|
-
return existing ?? generateCorrelationId();
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Create a correlation ID from a timestamp
|
|
219
|
-
*
|
|
220
|
-
* Useful for testing or when you need deterministic IDs.
|
|
221
|
-
*
|
|
222
|
-
* @param timestamp - Unix timestamp in milliseconds
|
|
223
|
-
* @param random - Optional random component (generates if not provided)
|
|
224
|
-
* @returns Correlation ID
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```typescript
|
|
228
|
-
* const id = createCorrelationIdFromTimestamp(1716234567890);
|
|
229
|
-
* // => 'req_1716234567890_a3f5c9d2'
|
|
230
|
-
*
|
|
231
|
-
* const deterministicId = createCorrelationIdFromTimestamp(1716234567890, 'aaaaaaaa');
|
|
232
|
-
* // => 'req_1716234567890_aaaaaaaa'
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
function createCorrelationIdFromTimestamp(timestamp, random) {
|
|
236
|
-
const randomComponent = random ?? generateRandomHex(8);
|
|
237
|
-
if (!/^[a-f0-9]{8}$/.test(randomComponent)) {
|
|
238
|
-
throw new Error(`Invalid random component: ${randomComponent}. Expected 8 hex characters`);
|
|
239
|
-
}
|
|
240
|
-
return `req_${timestamp}_${randomComponent}`;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Calculate age of correlation ID in milliseconds
|
|
244
|
-
*
|
|
245
|
-
* @param id - Correlation ID
|
|
246
|
-
* @returns Age in milliseconds, or null if invalid
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```typescript
|
|
250
|
-
* const id = generateCorrelationId();
|
|
251
|
-
* setTimeout(() => {
|
|
252
|
-
* const age = getCorrelationIdAge(id);
|
|
253
|
-
* console.log(`Request age: ${age}ms`);
|
|
254
|
-
* }, 1000);
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
function getCorrelationIdAge(id) {
|
|
258
|
-
const spec = parseCorrelationId(id);
|
|
259
|
-
if (!spec)
|
|
260
|
-
return null;
|
|
261
|
-
const now = Date.now();
|
|
262
|
-
return now - spec.timestamp;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Check if correlation ID is expired
|
|
266
|
-
*
|
|
267
|
-
* @param id - Correlation ID
|
|
268
|
-
* @param maxAgeMs - Maximum age in milliseconds (default: 5 minutes)
|
|
269
|
-
* @returns True if expired, false otherwise
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```typescript
|
|
273
|
-
* const id = generateCorrelationId();
|
|
274
|
-
* if (isCorrelationIdExpired(id, 60000)) {
|
|
275
|
-
* console.log('Request older than 1 minute');
|
|
276
|
-
* }
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
function isCorrelationIdExpired(id, maxAgeMs = 5 * 60 * 1000) {
|
|
280
|
-
const age = getCorrelationIdAge(id);
|
|
281
|
-
return age !== null && age > maxAgeMs;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Generate random hex string
|
|
285
|
-
*
|
|
286
|
-
* Uses Web Crypto API in browser, Node.js crypto in Node.
|
|
287
|
-
* Falls back to Math.random() if neither available (NOT cryptographically secure).
|
|
288
|
-
*
|
|
289
|
-
* @param length - Number of hex characters to generate
|
|
290
|
-
* @returns Random hex string
|
|
291
|
-
*
|
|
292
|
-
* @internal
|
|
293
|
-
*/
|
|
294
|
-
function generateRandomHex(length) {
|
|
295
|
-
const bytes = Math.ceil(length / 2);
|
|
296
|
-
// Try Web Crypto API (browser)
|
|
297
|
-
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
298
|
-
const buffer = new Uint8Array(bytes);
|
|
299
|
-
crypto.getRandomValues(buffer);
|
|
300
|
-
return Array.from(buffer)
|
|
301
|
-
.map((b) => b.toString(16).padStart(2, '0'))
|
|
302
|
-
.join('')
|
|
303
|
-
.substring(0, length);
|
|
304
|
-
}
|
|
305
|
-
// Try Node.js crypto
|
|
306
|
-
try {
|
|
307
|
-
const nodeCrypto = require('node:crypto');
|
|
308
|
-
return nodeCrypto.randomBytes(bytes).toString('hex').substring(0, length);
|
|
309
|
-
}
|
|
310
|
-
catch {
|
|
311
|
-
// SECURITY: Never fall back to Math.random() in production (OWASP violation)
|
|
312
|
-
// Correlation IDs must be cryptographically random to prevent enumeration attacks
|
|
313
|
-
throw new Error('Cryptographic random generation unavailable. ' +
|
|
314
|
-
'Install crypto polyfill or use environment with crypto support.');
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Middleware helper for Express/Koa-style frameworks
|
|
319
|
-
*
|
|
320
|
-
* Automatically attaches correlation ID to incoming requests.
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```typescript
|
|
324
|
-
* import express from 'express';
|
|
325
|
-
* import { correlationIdMiddleware } from '@private.me/xbind';
|
|
326
|
-
*
|
|
327
|
-
* const app = express();
|
|
328
|
-
* app.use(correlationIdMiddleware());
|
|
329
|
-
* ```
|
|
330
|
-
*/
|
|
331
|
-
function correlationIdMiddleware() {
|
|
332
|
-
return (req, res, next) => {
|
|
333
|
-
const id = getOrCreateCorrelationId(req.headers);
|
|
334
|
-
req.correlationId = id;
|
|
335
|
-
res.setHeader(exports.CORRELATION_ID_HEADER, id);
|
|
336
|
-
if (typeof next === 'function')
|
|
337
|
-
next();
|
|
338
|
-
};
|
|
339
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CORRELATION_ID_ALIASES=exports.CORRELATION_ID_HEADER=void 0,exports.generateCorrelationId=generateCorrelationId,exports.validateCorrelationId=validateCorrelationId,exports.parseCorrelationId=parseCorrelationId,exports.attachCorrelationId=attachCorrelationId,exports.extractCorrelationId=extractCorrelationId,exports.getOrCreateCorrelationId=getOrCreateCorrelationId,exports.createCorrelationIdFromTimestamp=createCorrelationIdFromTimestamp,exports.getCorrelationIdAge=getCorrelationIdAge,exports.isCorrelationIdExpired=isCorrelationIdExpired,exports.correlationIdMiddleware=correlationIdMiddleware,exports.CORRELATION_ID_HEADER="X-Correlation-ID",exports.CORRELATION_ID_ALIASES=["X-Request-ID","X-Trace-ID","X-Transaction-ID"];const CORRELATION_ID_PATTERN=/^req_\d{13}_[a-f0-9]{8}$/;function generateCorrelationId(){return`req_${Date.now()}_${generateRandomHex(8)}`}function validateCorrelationId(r){return"string"==typeof r&&CORRELATION_ID_PATTERN.test(r)}function parseCorrelationId(r){if(!validateCorrelationId(r))return null;const e=r.split("_");return{prefix:e[0]??"req",timestamp:parseInt(e[1]??"0",10),random:e[2]??""}}function attachCorrelationId(r,e){const t=e??generateCorrelationId();if(!validateCorrelationId(t))throw new Error(`Invalid correlation ID format: ${t}. Expected format: req_{timestamp}_{random}`);return r instanceof Headers?r.set(exports.CORRELATION_ID_HEADER,t):r[exports.CORRELATION_ID_HEADER]=t,r}function extractCorrelationId(r){const e=r instanceof Headers?r.get(exports.CORRELATION_ID_HEADER):r[exports.CORRELATION_ID_HEADER];if(e&&validateCorrelationId(e))return e;for(const e of exports.CORRELATION_ID_ALIASES){const t=r instanceof Headers?r.get(e):r[e];if(t&&validateCorrelationId(t))return t}}function getOrCreateCorrelationId(r){if(!r)return generateCorrelationId();return extractCorrelationId(r)??generateCorrelationId()}function createCorrelationIdFromTimestamp(r,e){const t=e??generateRandomHex(8);if(!/^[a-f0-9]{8}$/.test(t))throw new Error(`Invalid random component: ${t}. Expected 8 hex characters`);return`req_${r}_${t}`}function getCorrelationIdAge(r){const e=parseCorrelationId(r);if(!e)return null;return Date.now()-e.timestamp}function isCorrelationIdExpired(r,e=3e5){const t=getCorrelationIdAge(r);return null!==t&&t>e}function generateRandomHex(r){const e=Math.ceil(r/2);if("undefined"!=typeof crypto&&crypto.getRandomValues){const t=new Uint8Array(e);return crypto.getRandomValues(t),Array.from(t).map(r=>r.toString(16).padStart(2,"0")).join("").substring(0,r)}try{return require("node:crypto").randomBytes(e).toString("hex").substring(0,r)}catch{throw new Error("Cryptographic random generation unavailable. Install crypto polyfill or use environment with crypto support.")}}function correlationIdMiddleware(){return(r,e,t)=>{const o=getOrCreateCorrelationId(r.headers);r.correlationId=o,e.setHeader(exports.CORRELATION_ID_HEADER,o),"function"==typeof t&&t()}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function toBase64(r){if("undefined"!=typeof Buffer)return Buffer.from(r).toString("base64");const e=String.fromCharCode(...r);return btoa(e)}function fromBase64(r){if("undefined"!=typeof Buffer)return new Uint8Array(Buffer.from(r,"base64"));const e=atob(r),t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function toBase64Url(r){return toBase64(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function fromBase64Url(r){let e=r.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return fromBase64(e)}function generateUUID(){if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();const r=new Uint8Array(16);crypto.getRandomValues(r),r[6]=15&r[6]|64,r[8]=63&r[8]|128;const e=Array.from(r).map(r=>r.toString(16).padStart(2,"0")).join("");return`${e.substring(0,8)}-${e.substring(8,12)}-${e.substring(12,16)}-${e.substring(16,20)}-${e.substring(20)}`}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isCryptoLoaded=exports.getCrypto=exports.loadCryptoPackage=void 0,exports.toBase64=toBase64,exports.fromBase64=fromBase64,exports.toBase64Url=toBase64Url,exports.fromBase64Url=fromBase64Url,exports.generateUUID=generateUUID,exports.formatShareHeader=formatShareHeader,exports.parseShareHeader=parseShareHeader,exports.hasShareHeader=hasShareHeader,exports.splitXorIDA=splitXorIDA,exports.reconstructXorIDA=reconstructXorIDA,exports.nextOddPrime=nextOddPrime,exports.pkcs7Pad=pkcs7Pad,exports.pkcs7Unpad=pkcs7Unpad,exports.generateHMAC=generateHMAC,exports.verifyHMAC=verifyHMAC;const START_MARKER="Encrypted://",END_MARKER="=> Generated by Xecret (TM)",BRAND_PREFIX="Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> ";function formatShareHeader(r){return`${BRAND_PREFIX}${START_MARKER} ${r} ${END_MARKER}`}function parseShareHeader(r){const e=r.indexOf(START_MARKER);if(e<0)return r.trim();const t=e+START_MARKER.length,o=r.indexOf(END_MARKER,t);return o<0?r.trim():r.substring(t,o).trim()}function hasShareHeader(r){return r.includes(START_MARKER)&&r.includes(END_MARKER)}const vault_store_loader_js_1=require("./vault-store-loader.js");function splitXorIDA(r,e,t){const o=(0,vault_store_loader_js_1.getCrypto)();if(!o)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return o.splitXorIDA(r,e,t)}function reconstructXorIDA(r,e,t,o){const a=(0,vault_store_loader_js_1.getCrypto)();if(!a)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return a.reconstructXorIDA(r,e,t,o)}function nextOddPrime(r){const e=(0,vault_store_loader_js_1.getCrypto)();if(!e)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return e.nextOddPrime(r)}function pkcs7Pad(r,e){const t=(0,vault_store_loader_js_1.getCrypto)();if(!t)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return t.pkcs7Pad(r,e)}function pkcs7Unpad(r,e){const t=(0,vault_store_loader_js_1.getCrypto)();if(!t)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return t.pkcs7Unpad(r,e)}async function generateHMAC(r){const e=(0,vault_store_loader_js_1.getCrypto)();if(!e)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return e.generateHMAC(r)}async function verifyHMAC(r,e,t){const o=(0,vault_store_loader_js_1.getCrypto)();if(!o)throw new Error("Crypto package not loaded. Call loadCryptoPackage() first.");return o.verifyHMAC(r,e,t)}Object.defineProperty(exports,"getCrypto",{enumerable:!0,get:function(){return vault_store_loader_js_1.getCrypto}}),Object.defineProperty(exports,"loadCryptoPackage",{enumerable:!0,get:function(){return vault_store_loader_js_1.loadCryptoPackage}}),Object.defineProperty(exports,"isCryptoLoaded",{enumerable:!0,get:function(){return vault_store_loader_js_1.isCryptoLoaded}});
|