@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,328 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module invite
|
|
4
|
-
* Viral invite system for XBind connections.
|
|
5
|
-
*
|
|
6
|
-
* Enables one-click invites:
|
|
7
|
-
* - Generate: `xbind invite payments-service`
|
|
8
|
-
* - Accept: Click link or `xbind accept https://xbind.to/invite/abc123`
|
|
9
|
-
*
|
|
10
|
-
* The viral loop:
|
|
11
|
-
* 1. Service A invites Service B
|
|
12
|
-
* 2. Service B clicks link (< 60 sec setup)
|
|
13
|
-
* 3. Connection established
|
|
14
|
-
* 4. Service B invites Service C
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.InviteService = exports.InviteErrorCode = void 0;
|
|
18
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
19
|
-
/**
|
|
20
|
-
* Invite error codes.
|
|
21
|
-
*/
|
|
22
|
-
var InviteErrorCode;
|
|
23
|
-
(function (InviteErrorCode) {
|
|
24
|
-
InviteErrorCode["INVALID_INVITE"] = "INVITE_INVALID";
|
|
25
|
-
InviteErrorCode["EXPIRED_INVITE"] = "INVITE_EXPIRED";
|
|
26
|
-
InviteErrorCode["INVITE_NOT_FOUND"] = "INVITE_NOT_FOUND";
|
|
27
|
-
InviteErrorCode["NETWORK_ERROR"] = "INVITE_NETWORK_ERROR";
|
|
28
|
-
InviteErrorCode["ALREADY_CONNECTED"] = "INVITE_ALREADY_CONNECTED";
|
|
29
|
-
})(InviteErrorCode || (exports.InviteErrorCode = InviteErrorCode = {}));
|
|
30
|
-
/**
|
|
31
|
-
* Invite service for creating and accepting invites.
|
|
32
|
-
*/
|
|
33
|
-
class InviteService {
|
|
34
|
-
inviteApiUrl;
|
|
35
|
-
/**
|
|
36
|
-
* Create invite service.
|
|
37
|
-
*
|
|
38
|
-
* @param options - Configuration
|
|
39
|
-
* @param options.inviteApiUrl - Invite API URL (default: https://xbind.to)
|
|
40
|
-
*/
|
|
41
|
-
constructor(options = {}) {
|
|
42
|
-
this.inviteApiUrl = options.inviteApiUrl || 'https://xbind.to';
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create an invite.
|
|
46
|
-
*
|
|
47
|
-
* @param options - Invite options
|
|
48
|
-
* @param options.from - Sender service info
|
|
49
|
-
* @param options.target - Target service (optional)
|
|
50
|
-
* @param options.template - Suggested template (e.g., "payment-processing")
|
|
51
|
-
* @param options.permissions - Custom permissions
|
|
52
|
-
* @param options.expiresIn - Expiration in seconds (default: 7 days)
|
|
53
|
-
* @returns Invite or error
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* const inviteService = new InviteService();
|
|
58
|
-
* const invite = await inviteService.create({
|
|
59
|
-
* from: {
|
|
60
|
-
* name: 'billing-service',
|
|
61
|
-
* did: 'did:key:z6Mk...',
|
|
62
|
-
* endpoint: 'https://billing.example.com',
|
|
63
|
-
* publicKey: '...',
|
|
64
|
-
* },
|
|
65
|
-
* target: {
|
|
66
|
-
* name: 'payments-service',
|
|
67
|
-
* },
|
|
68
|
-
* template: 'payment-processing',
|
|
69
|
-
* });
|
|
70
|
-
*
|
|
71
|
-
* // Share invite.value.url or invite.value.qr
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
async create(options) {
|
|
75
|
-
const expiresIn = options.expiresIn || 7 * 24 * 60 * 60; // 7 days
|
|
76
|
-
const expires = new Date(Date.now() + expiresIn * 1000).toISOString();
|
|
77
|
-
try {
|
|
78
|
-
const response = await fetch(`${this.inviteApiUrl}/invites/create`, {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/json',
|
|
82
|
-
},
|
|
83
|
-
body: JSON.stringify({
|
|
84
|
-
from: {
|
|
85
|
-
name: options.from.name,
|
|
86
|
-
did: options.from.did,
|
|
87
|
-
endpoint: options.from.endpoint,
|
|
88
|
-
publicKey: options.from.publicKey,
|
|
89
|
-
x25519PublicKey: options.from.x25519PublicKey,
|
|
90
|
-
mlKemPublicKey: options.from.mlKemPublicKey,
|
|
91
|
-
},
|
|
92
|
-
to: options.target,
|
|
93
|
-
template: options.template,
|
|
94
|
-
permissions: options.permissions,
|
|
95
|
-
expires,
|
|
96
|
-
}),
|
|
97
|
-
});
|
|
98
|
-
if (!response.ok) {
|
|
99
|
-
return (0, shared_1.err)({
|
|
100
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
101
|
-
message: `Failed to create invite: ${response.status}`,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
const data = await response.json();
|
|
105
|
-
return (0, shared_1.ok)(data);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
return (0, shared_1.err)({
|
|
109
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
110
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Accept an invite.
|
|
116
|
-
*
|
|
117
|
-
* @param options - Accept options
|
|
118
|
-
* @param options.inviteUrl - Invite URL (e.g., https://xbind.to/invite/abc123)
|
|
119
|
-
* @param options.acceptor - Acceptor service info
|
|
120
|
-
* @returns Connection info or error
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* const inviteService = new InviteService();
|
|
125
|
-
* const result = await inviteService.accept({
|
|
126
|
-
* inviteUrl: 'https://xbind.to/invite/abc123',
|
|
127
|
-
* acceptor: {
|
|
128
|
-
* name: 'payments-service',
|
|
129
|
-
* did: 'did:key:z6Mk...',
|
|
130
|
-
* endpoint: 'https://payments.example.com',
|
|
131
|
-
* publicKey: '...',
|
|
132
|
-
* }
|
|
133
|
-
* });
|
|
134
|
-
*
|
|
135
|
-
* if (result.ok) {
|
|
136
|
-
* console.log('Connected!');
|
|
137
|
-
* }
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
async accept(options) {
|
|
141
|
-
try {
|
|
142
|
-
// Extract invite ID from URL
|
|
143
|
-
const inviteId = this.extractInviteId(options.inviteUrl);
|
|
144
|
-
if (!inviteId) {
|
|
145
|
-
return (0, shared_1.err)({
|
|
146
|
-
code: InviteErrorCode.INVALID_INVITE,
|
|
147
|
-
message: 'Invalid invite URL',
|
|
148
|
-
hint: 'URL should be like: https://xbind.to/invite/abc123',
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
// Accept invite
|
|
152
|
-
const response = await fetch(`${this.inviteApiUrl}/invites/${inviteId}/accept`, {
|
|
153
|
-
method: 'POST',
|
|
154
|
-
headers: {
|
|
155
|
-
'Content-Type': 'application/json',
|
|
156
|
-
},
|
|
157
|
-
body: JSON.stringify({
|
|
158
|
-
acceptor: {
|
|
159
|
-
name: options.acceptor.name,
|
|
160
|
-
did: options.acceptor.did,
|
|
161
|
-
endpoint: options.acceptor.endpoint,
|
|
162
|
-
publicKey: options.acceptor.publicKey,
|
|
163
|
-
x25519PublicKey: options.acceptor.x25519PublicKey,
|
|
164
|
-
mlKemPublicKey: options.acceptor.mlKemPublicKey,
|
|
165
|
-
},
|
|
166
|
-
}),
|
|
167
|
-
});
|
|
168
|
-
if (response.status === 404) {
|
|
169
|
-
return (0, shared_1.err)({
|
|
170
|
-
code: InviteErrorCode.INVITE_NOT_FOUND,
|
|
171
|
-
message: 'Invite not found or expired',
|
|
172
|
-
hint: 'The invite may have been revoked or expired',
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
if (response.status === 410) {
|
|
176
|
-
const errorData = await response.json().catch(() => ({}));
|
|
177
|
-
return (0, shared_1.err)({
|
|
178
|
-
code: InviteErrorCode.EXPIRED_INVITE,
|
|
179
|
-
message: errorData.message || 'Invite has expired',
|
|
180
|
-
hint: errorData.hint || 'Ask the sender to create a new invite',
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (response.status === 409) {
|
|
184
|
-
return (0, shared_1.err)({
|
|
185
|
-
code: InviteErrorCode.ALREADY_CONNECTED,
|
|
186
|
-
message: 'Services are already connected',
|
|
187
|
-
hint: 'You are already connected to this service',
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
if (!response.ok) {
|
|
191
|
-
return (0, shared_1.err)({
|
|
192
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
193
|
-
message: `Failed to accept invite: ${response.status}`,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const data = await response.json();
|
|
197
|
-
return (0, shared_1.ok)(data);
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
return (0, shared_1.err)({
|
|
201
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
202
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
203
|
-
hint: 'Check your network connection and try again',
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Get invite details without accepting.
|
|
209
|
-
*
|
|
210
|
-
* @param inviteUrl - Invite URL
|
|
211
|
-
* @returns Invite details or error
|
|
212
|
-
*/
|
|
213
|
-
async get(inviteUrl) {
|
|
214
|
-
try {
|
|
215
|
-
const inviteId = this.extractInviteId(inviteUrl);
|
|
216
|
-
if (!inviteId) {
|
|
217
|
-
return (0, shared_1.err)({
|
|
218
|
-
code: InviteErrorCode.INVALID_INVITE,
|
|
219
|
-
message: 'Invalid invite URL',
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
const response = await fetch(`${this.inviteApiUrl}/invites/${inviteId}`, {
|
|
223
|
-
headers: {
|
|
224
|
-
'Accept': 'application/json',
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
if (response.status === 404) {
|
|
228
|
-
return (0, shared_1.err)({
|
|
229
|
-
code: InviteErrorCode.INVITE_NOT_FOUND,
|
|
230
|
-
message: 'Invite not found',
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (!response.ok) {
|
|
234
|
-
return (0, shared_1.err)({
|
|
235
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
236
|
-
message: `Failed to get invite: ${response.status}`,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
const data = await response.json();
|
|
240
|
-
return (0, shared_1.ok)(data);
|
|
241
|
-
}
|
|
242
|
-
catch (error) {
|
|
243
|
-
return (0, shared_1.err)({
|
|
244
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
245
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Revoke an invite.
|
|
251
|
-
*
|
|
252
|
-
* @param inviteId - Invite ID to revoke
|
|
253
|
-
* @returns Success or error
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```ts
|
|
257
|
-
* const inviteService = new InviteService();
|
|
258
|
-
* const result = await inviteService.revoke('inv_abc123');
|
|
259
|
-
*
|
|
260
|
-
* if (result.ok) {
|
|
261
|
-
* console.log('Invite revoked');
|
|
262
|
-
* }
|
|
263
|
-
* ```
|
|
264
|
-
*/
|
|
265
|
-
async revoke(inviteId) {
|
|
266
|
-
try {
|
|
267
|
-
const response = await fetch(`${this.inviteApiUrl}/invites/${inviteId}/revoke`, {
|
|
268
|
-
method: 'POST',
|
|
269
|
-
headers: {
|
|
270
|
-
'Content-Type': 'application/json',
|
|
271
|
-
},
|
|
272
|
-
});
|
|
273
|
-
if (response.status === 404) {
|
|
274
|
-
return (0, shared_1.err)({
|
|
275
|
-
code: InviteErrorCode.INVITE_NOT_FOUND,
|
|
276
|
-
message: 'Invite not found',
|
|
277
|
-
hint: 'The invite may have already been revoked or expired',
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
if (!response.ok) {
|
|
281
|
-
return (0, shared_1.err)({
|
|
282
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
283
|
-
message: `Failed to revoke invite: ${response.status}`,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
const data = await response.json();
|
|
287
|
-
return (0, shared_1.ok)(data);
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
return (0, shared_1.err)({
|
|
291
|
-
code: InviteErrorCode.NETWORK_ERROR,
|
|
292
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Extract invite ID from URL.
|
|
298
|
-
*
|
|
299
|
-
* @param url - Invite URL
|
|
300
|
-
* @returns Invite ID or null
|
|
301
|
-
*
|
|
302
|
-
* @example
|
|
303
|
-
* ```ts
|
|
304
|
-
* extractInviteId('https://xbind.to/invite/abc123') // 'abc123'
|
|
305
|
-
* extractInviteId('https://xbind.to/billing/invite/xyz') // 'xyz'
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
extractInviteId(url) {
|
|
309
|
-
try {
|
|
310
|
-
const parsed = new URL(url);
|
|
311
|
-
const segments = parsed.pathname.split('/').filter(s => s.length > 0);
|
|
312
|
-
// Look for 'invite' segment followed by ID
|
|
313
|
-
const inviteIndex = segments.indexOf('invite');
|
|
314
|
-
if (inviteIndex !== -1 && segments[inviteIndex + 1]) {
|
|
315
|
-
return segments[inviteIndex + 1] ?? null;
|
|
316
|
-
}
|
|
317
|
-
// Fallback: last segment
|
|
318
|
-
if (segments.length > 0) {
|
|
319
|
-
return segments[segments.length - 1] ?? null;
|
|
320
|
-
}
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
catch {
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
exports.InviteService = InviteService;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InviteService=exports.InviteErrorCode=void 0;const shared_1=require("../_deps/shared/index.js");var InviteErrorCode;!function(e){e.INVALID_INVITE="INVITE_INVALID",e.EXPIRED_INVITE="INVITE_EXPIRED",e.INVITE_NOT_FOUND="INVITE_NOT_FOUND",e.NETWORK_ERROR="INVITE_NETWORK_ERROR",e.ALREADY_CONNECTED="INVITE_ALREADY_CONNECTED"}(InviteErrorCode||(exports.InviteErrorCode=InviteErrorCode={}));class InviteService{inviteApiUrl;constructor(e={}){this.inviteApiUrl=e.inviteApiUrl||"https://xbind.to"}async create(e){const r=e.expiresIn||604800,t=new Date(Date.now()+1e3*r).toISOString();try{const r=await fetch(`${this.inviteApiUrl}/invites/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:{name:e.from.name,did:e.from.did,endpoint:e.from.endpoint,publicKey:e.from.publicKey,x25519PublicKey:e.from.x25519PublicKey,mlKemPublicKey:e.from.mlKemPublicKey},to:e.target,template:e.template,permissions:e.permissions,expires:t})});if(!r.ok)return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:`Failed to create invite: ${r.status}`});const i=await r.json();return(0,shared_1.ok)(i)}catch(e){return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:e instanceof Error?e.message:"Network error"})}}async accept(e){try{const r=this.extractInviteId(e.inviteUrl);if(!r)return(0,shared_1.err)({code:InviteErrorCode.INVALID_INVITE,message:"Invalid invite URL",hint:"URL should be like: https://xbind.to/invite/abc123"});const t=await fetch(`${this.inviteApiUrl}/invites/${r}/accept`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({acceptor:{name:e.acceptor.name,did:e.acceptor.did,endpoint:e.acceptor.endpoint,publicKey:e.acceptor.publicKey,x25519PublicKey:e.acceptor.x25519PublicKey,mlKemPublicKey:e.acceptor.mlKemPublicKey}})});if(404===t.status)return(0,shared_1.err)({code:InviteErrorCode.INVITE_NOT_FOUND,message:"Invite not found or expired",hint:"The invite may have been revoked or expired"});if(410===t.status){const e=await t.json().catch(()=>({}));return(0,shared_1.err)({code:InviteErrorCode.EXPIRED_INVITE,message:e.message||"Invite has expired",hint:e.hint||"Ask the sender to create a new invite"})}if(409===t.status)return(0,shared_1.err)({code:InviteErrorCode.ALREADY_CONNECTED,message:"Services are already connected",hint:"You are already connected to this service"});if(!t.ok)return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:`Failed to accept invite: ${t.status}`});const i=await t.json();return(0,shared_1.ok)(i)}catch(e){return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:e instanceof Error?e.message:"Network error",hint:"Check your network connection and try again"})}}async get(e){try{const r=this.extractInviteId(e);if(!r)return(0,shared_1.err)({code:InviteErrorCode.INVALID_INVITE,message:"Invalid invite URL"});const t=await fetch(`${this.inviteApiUrl}/invites/${r}`,{headers:{Accept:"application/json"}});if(404===t.status)return(0,shared_1.err)({code:InviteErrorCode.INVITE_NOT_FOUND,message:"Invite not found"});if(!t.ok)return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:`Failed to get invite: ${t.status}`});const i=await t.json();return(0,shared_1.ok)(i)}catch(e){return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:e instanceof Error?e.message:"Network error"})}}async revoke(e){try{const r=await fetch(`${this.inviteApiUrl}/invites/${e}/revoke`,{method:"POST",headers:{"Content-Type":"application/json"}});if(404===r.status)return(0,shared_1.err)({code:InviteErrorCode.INVITE_NOT_FOUND,message:"Invite not found",hint:"The invite may have already been revoked or expired"});if(!r.ok)return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:`Failed to revoke invite: ${r.status}`});const t=await r.json();return(0,shared_1.ok)(t)}catch(e){return(0,shared_1.err)({code:InviteErrorCode.NETWORK_ERROR,message:e instanceof Error?e.message:"Network error"})}}extractInviteId(e){try{const r=new URL(e).pathname.split("/").filter(e=>e.length>0),t=r.indexOf("invite");return-1!==t&&r[t+1]?r[t+1]??null:r.length>0?r[r.length-1]??null:null}catch{return null}}}exports.InviteService=InviteService;
|
|
@@ -1,246 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateEphemeralKeyPair = generateEphemeralKeyPair;
|
|
4
|
-
exports.importX25519PublicKey = importX25519PublicKey;
|
|
5
|
-
exports.deriveSharedKeyECDH = deriveSharedKeyECDH;
|
|
6
|
-
exports.senderKeyAgreement = senderKeyAgreement;
|
|
7
|
-
exports.receiverKeyAgreement = receiverKeyAgreement;
|
|
8
|
-
exports.combineSharedSecrets = combineSharedSecrets;
|
|
9
|
-
exports.senderHybridKeyAgreement = senderHybridKeyAgreement;
|
|
10
|
-
exports.receiverHybridKeyAgreement = receiverHybridKeyAgreement;
|
|
11
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
12
|
-
const mlkem_1 = require("mlkem");
|
|
13
|
-
/* -- Constants -- */
|
|
14
|
-
const X25519_RAW_KEY_BYTES = 32;
|
|
15
|
-
const AES_KEY_BITS = 256;
|
|
16
|
-
/* -- Helpers -- */
|
|
17
|
-
/** Copy Uint8Array to fresh ArrayBuffer. */
|
|
18
|
-
function toArrayBuffer(data) {
|
|
19
|
-
const buf = new ArrayBuffer(data.byteLength);
|
|
20
|
-
new Uint8Array(buf).set(data);
|
|
21
|
-
return buf;
|
|
22
|
-
}
|
|
23
|
-
/* -- Key Generation -- */
|
|
24
|
-
/**
|
|
25
|
-
* Generate an ephemeral X25519 key pair for ECDH key agreement.
|
|
26
|
-
*
|
|
27
|
-
* Uses Web Crypto API to generate a fresh X25519 key pair.
|
|
28
|
-
* The key pair is ephemeral -- it should be used for a single
|
|
29
|
-
* key agreement and then discarded.
|
|
30
|
-
*
|
|
31
|
-
* @returns Result containing the ephemeral key pair or error.
|
|
32
|
-
*/
|
|
33
|
-
async function generateEphemeralKeyPair() {
|
|
34
|
-
try {
|
|
35
|
-
// SAFETY: X25519 generateKey always returns CryptoKeyPair
|
|
36
|
-
const keyPair = await crypto.subtle.generateKey({ name: 'X25519' }, true, ['deriveBits']);
|
|
37
|
-
const rawPub = new Uint8Array(await crypto.subtle.exportKey('raw', keyPair.publicKey));
|
|
38
|
-
return (0, shared_1.ok)({
|
|
39
|
-
privateKey: keyPair.privateKey,
|
|
40
|
-
publicKey: keyPair.publicKey,
|
|
41
|
-
rawPublicKey: rawPub,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return (0, shared_1.err)('KEYGEN_FAILED');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/* -- Key Import -- */
|
|
49
|
-
/**
|
|
50
|
-
* Import a raw 32-byte X25519 public key into a CryptoKey.
|
|
51
|
-
*
|
|
52
|
-
* Used by the receiver to import the sender's ephemeral public
|
|
53
|
-
* key from the envelope for ECDH derivation.
|
|
54
|
-
*
|
|
55
|
-
* @param rawPublicKey - Raw 32-byte X25519 public key.
|
|
56
|
-
* @returns Result containing the imported CryptoKey or error.
|
|
57
|
-
*/
|
|
58
|
-
async function importX25519PublicKey(rawPublicKey) {
|
|
59
|
-
if (rawPublicKey.length !== X25519_RAW_KEY_BYTES) {
|
|
60
|
-
return (0, shared_1.err)('INVALID_KEY_LENGTH:EXPECTED_32');
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
const key = await crypto.subtle.importKey('raw', toArrayBuffer(rawPublicKey), { name: 'X25519' }, true, []);
|
|
64
|
-
return (0, shared_1.ok)(key);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return (0, shared_1.err)('IMPORT_FAILED');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/* -- ECDH Key Derivation -- */
|
|
71
|
-
/**
|
|
72
|
-
* Derive a shared AES-256-GCM key via X25519 ECDH.
|
|
73
|
-
*
|
|
74
|
-
* Performs ECDH key agreement between a local private key and a
|
|
75
|
-
* remote public key, producing 256 bits of shared secret that
|
|
76
|
-
* are imported as an AES-256-GCM key.
|
|
77
|
-
*
|
|
78
|
-
* @param localPrivateKey - Local X25519 private key.
|
|
79
|
-
* @param remotePublicKey - Remote X25519 public key (CryptoKey).
|
|
80
|
-
* @returns Result containing the derived AES-256-GCM key or error.
|
|
81
|
-
*/
|
|
82
|
-
async function deriveSharedKeyECDH(localPrivateKey, remotePublicKey) {
|
|
83
|
-
try {
|
|
84
|
-
const sharedBits = await crypto.subtle.deriveBits({ name: 'X25519', public: remotePublicKey }, localPrivateKey, AES_KEY_BITS);
|
|
85
|
-
const aesKey = await crypto.subtle.importKey('raw', sharedBits, { name: 'AES-GCM', length: AES_KEY_BITS }, false, ['encrypt', 'decrypt']);
|
|
86
|
-
return (0, shared_1.ok)(aesKey);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return (0, shared_1.err)('DERIVE_FAILED');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/* -- High-Level API -- */
|
|
93
|
-
/**
|
|
94
|
-
* Perform sender-side ECDH key agreement.
|
|
95
|
-
*
|
|
96
|
-
* Generates an ephemeral X25519 key pair, derives a shared key
|
|
97
|
-
* with the recipient's static X25519 public key, and returns
|
|
98
|
-
* both the shared key and the ephemeral public key to include
|
|
99
|
-
* in the envelope.
|
|
100
|
-
*
|
|
101
|
-
* @param recipientX25519PubKey - Recipient's static X25519 public key.
|
|
102
|
-
* @returns Result containing the key agreement result or error.
|
|
103
|
-
*/
|
|
104
|
-
async function senderKeyAgreement(recipientX25519PubKey) {
|
|
105
|
-
const ephemeral = await generateEphemeralKeyPair();
|
|
106
|
-
if (!ephemeral.ok)
|
|
107
|
-
return ephemeral;
|
|
108
|
-
const shared = await deriveSharedKeyECDH(ephemeral.value.privateKey, recipientX25519PubKey);
|
|
109
|
-
if (!shared.ok)
|
|
110
|
-
return shared;
|
|
111
|
-
return (0, shared_1.ok)({
|
|
112
|
-
sharedKey: shared.value,
|
|
113
|
-
ephemeralPublicKey: ephemeral.value.rawPublicKey,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Perform receiver-side ECDH key agreement.
|
|
118
|
-
*
|
|
119
|
-
* Imports the sender's ephemeral public key from the envelope
|
|
120
|
-
* and derives the shared key using the receiver's static X25519
|
|
121
|
-
* private key.
|
|
122
|
-
*
|
|
123
|
-
* @param receiverPrivateKey - Receiver's static X25519 private key.
|
|
124
|
-
* @param senderEphemeralPubRaw - Sender's ephemeral public key (raw bytes).
|
|
125
|
-
* @returns Result containing the derived AES-256-GCM key or error.
|
|
126
|
-
*/
|
|
127
|
-
async function receiverKeyAgreement(receiverPrivateKey, senderEphemeralPubRaw) {
|
|
128
|
-
const imported = await importX25519PublicKey(senderEphemeralPubRaw);
|
|
129
|
-
if (!imported.ok)
|
|
130
|
-
return imported;
|
|
131
|
-
return deriveSharedKeyECDH(receiverPrivateKey, imported.value);
|
|
132
|
-
}
|
|
133
|
-
/* -- Hybrid Key Agreement (X25519 + ML-KEM-768) -- */
|
|
134
|
-
const HYBRID_HKDF_INFO = 'xail-hybrid-kem-v2';
|
|
135
|
-
/**
|
|
136
|
-
* Combine X25519 and ML-KEM shared secrets via HKDF-SHA256.
|
|
137
|
-
*
|
|
138
|
-
* Concatenates 32B X25519 + 32B ML-KEM shared secrets, runs HKDF
|
|
139
|
-
* with zero salt and 'xail-hybrid-kem-v2' info, outputs 256-bit AES key.
|
|
140
|
-
* Secure as long as either X25519 OR ML-KEM remains unbroken.
|
|
141
|
-
*
|
|
142
|
-
* @param x25519Shared - 32-byte raw X25519 ECDH shared bits.
|
|
143
|
-
* @param mlKemShared - 32-byte ML-KEM-768 shared secret.
|
|
144
|
-
* @returns AES-256-GCM CryptoKey derived from both secrets.
|
|
145
|
-
*/
|
|
146
|
-
async function combineSharedSecrets(x25519Shared, mlKemShared) {
|
|
147
|
-
try {
|
|
148
|
-
const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
|
|
149
|
-
combined.set(x25519Shared);
|
|
150
|
-
combined.set(mlKemShared, x25519Shared.length);
|
|
151
|
-
const baseKey = await crypto.subtle.importKey('raw', toArrayBuffer(combined), 'HKDF', false, ['deriveBits']);
|
|
152
|
-
const derived = await crypto.subtle.deriveBits({
|
|
153
|
-
name: 'HKDF',
|
|
154
|
-
hash: 'SHA-256',
|
|
155
|
-
salt: new Uint8Array(32),
|
|
156
|
-
info: new TextEncoder().encode(HYBRID_HKDF_INFO),
|
|
157
|
-
}, baseKey, AES_KEY_BITS);
|
|
158
|
-
const aesKey = await crypto.subtle.importKey('raw', derived, { name: 'AES-GCM', length: AES_KEY_BITS }, false, ['encrypt', 'decrypt']);
|
|
159
|
-
return (0, shared_1.ok)(aesKey);
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
return (0, shared_1.err)('HKDF_FAILED');
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Perform sender-side hybrid key agreement (X25519 + ML-KEM-768).
|
|
167
|
-
*
|
|
168
|
-
* 1. Generate ephemeral X25519, ECDH → x25519SharedBits
|
|
169
|
-
* 2. ML-KEM-768 encapsulate → kemCiphertext + mlKemShared
|
|
170
|
-
* 3. HKDF(x25519Shared || mlKemShared) → AES-256-GCM key
|
|
171
|
-
*
|
|
172
|
-
* @param recipientX25519Pub - Recipient's static X25519 public key.
|
|
173
|
-
* @param recipientMlKemPub - Recipient's ML-KEM-768 public key (1184B).
|
|
174
|
-
* @returns Hybrid key agreement result with shared key, ephemeral pub, and KEM ciphertext.
|
|
175
|
-
*/
|
|
176
|
-
async function senderHybridKeyAgreement(recipientX25519Pub, recipientMlKemPub) {
|
|
177
|
-
// Step 1: Ephemeral X25519 ECDH
|
|
178
|
-
const ephemeral = await generateEphemeralKeyPair();
|
|
179
|
-
if (!ephemeral.ok)
|
|
180
|
-
return ephemeral;
|
|
181
|
-
let x25519Shared;
|
|
182
|
-
try {
|
|
183
|
-
x25519Shared = new Uint8Array(await crypto.subtle.deriveBits({ name: 'X25519', public: recipientX25519Pub }, ephemeral.value.privateKey, AES_KEY_BITS));
|
|
184
|
-
}
|
|
185
|
-
catch {
|
|
186
|
-
return (0, shared_1.err)('DERIVE_FAILED');
|
|
187
|
-
}
|
|
188
|
-
// Step 2: ML-KEM-768 encapsulate
|
|
189
|
-
let kemCipherText;
|
|
190
|
-
let kemSharedSecret;
|
|
191
|
-
try {
|
|
192
|
-
const mlkem = new mlkem_1.MlKem768();
|
|
193
|
-
const [cipherText, sharedSecret] = await mlkem.encap(recipientMlKemPub);
|
|
194
|
-
kemCipherText = cipherText;
|
|
195
|
-
kemSharedSecret = sharedSecret;
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
return (0, shared_1.err)('KEM_ENCAPSULATE_FAILED');
|
|
199
|
-
}
|
|
200
|
-
// Step 3: Combine via HKDF
|
|
201
|
-
const combined = await combineSharedSecrets(x25519Shared, kemSharedSecret);
|
|
202
|
-
if (!combined.ok)
|
|
203
|
-
return combined;
|
|
204
|
-
return (0, shared_1.ok)({
|
|
205
|
-
sharedKey: combined.value,
|
|
206
|
-
ephemeralPublicKey: ephemeral.value.rawPublicKey,
|
|
207
|
-
kemCiphertext: kemCipherText,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Perform receiver-side hybrid key agreement (X25519 + ML-KEM-768).
|
|
212
|
-
*
|
|
213
|
-
* 1. Import ephemeral X25519, ECDH → x25519SharedBits
|
|
214
|
-
* 2. ML-KEM-768 decapsulate → mlKemShared
|
|
215
|
-
* 3. HKDF(x25519Shared || mlKemShared) → same AES-256-GCM key
|
|
216
|
-
*
|
|
217
|
-
* @param x25519PrivateKey - Receiver's static X25519 private key.
|
|
218
|
-
* @param ephPubRaw - Sender's ephemeral X25519 public key (32B).
|
|
219
|
-
* @param kemCiphertext - ML-KEM-768 ciphertext from sender (1088B).
|
|
220
|
-
* @param mlKemSecretKey - Receiver's ML-KEM-768 secret key (2400B).
|
|
221
|
-
* @returns AES-256-GCM shared key or error.
|
|
222
|
-
*/
|
|
223
|
-
async function receiverHybridKeyAgreement(x25519PrivateKey, ephPubRaw, kemCiphertext, mlKemSecretKey) {
|
|
224
|
-
// Step 1: X25519 ECDH
|
|
225
|
-
const imported = await importX25519PublicKey(ephPubRaw);
|
|
226
|
-
if (!imported.ok)
|
|
227
|
-
return imported;
|
|
228
|
-
let x25519Shared;
|
|
229
|
-
try {
|
|
230
|
-
x25519Shared = new Uint8Array(await crypto.subtle.deriveBits({ name: 'X25519', public: imported.value }, x25519PrivateKey, AES_KEY_BITS));
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
return (0, shared_1.err)('DERIVE_FAILED');
|
|
234
|
-
}
|
|
235
|
-
// Step 2: ML-KEM-768 decapsulate
|
|
236
|
-
let mlKemShared;
|
|
237
|
-
try {
|
|
238
|
-
const mlkem = new mlkem_1.MlKem768();
|
|
239
|
-
mlKemShared = await mlkem.decap(kemCiphertext, mlKemSecretKey);
|
|
240
|
-
}
|
|
241
|
-
catch {
|
|
242
|
-
return (0, shared_1.err)('KEM_DECAPSULATE_FAILED');
|
|
243
|
-
}
|
|
244
|
-
// Step 3: Combine via HKDF
|
|
245
|
-
return combineSharedSecrets(x25519Shared, mlKemShared);
|
|
246
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.generateEphemeralKeyPair=generateEphemeralKeyPair,exports.importX25519PublicKey=importX25519PublicKey,exports.deriveSharedKeyECDH=deriveSharedKeyECDH,exports.senderKeyAgreement=senderKeyAgreement,exports.receiverKeyAgreement=receiverKeyAgreement,exports.combineSharedSecrets=combineSharedSecrets,exports.senderHybridKeyAgreement=senderHybridKeyAgreement,exports.receiverHybridKeyAgreement=receiverHybridKeyAgreement;const shared_1=require("../_deps/shared/index.js"),mlkem_1=require("mlkem"),X25519_RAW_KEY_BYTES=32,AES_KEY_BITS=256;function toArrayBuffer(e){const r=new ArrayBuffer(e.byteLength);return new Uint8Array(r).set(e),r}async function generateEphemeralKeyPair(){try{const e=await crypto.subtle.generateKey({name:"X25519"},!0,["deriveBits"]),r=new Uint8Array(await crypto.subtle.exportKey("raw",e.publicKey));return(0,shared_1.ok)({privateKey:e.privateKey,publicKey:e.publicKey,rawPublicKey:r})}catch{return(0,shared_1.err)("KEYGEN_FAILED")}}async function importX25519PublicKey(e){if(e.length!==X25519_RAW_KEY_BYTES)return(0,shared_1.err)("INVALID_KEY_LENGTH:EXPECTED_32");try{const r=await crypto.subtle.importKey("raw",toArrayBuffer(e),{name:"X25519"},!0,[]);return(0,shared_1.ok)(r)}catch{return(0,shared_1.err)("IMPORT_FAILED")}}async function deriveSharedKeyECDH(e,r){try{const t=await crypto.subtle.deriveBits({name:"X25519",public:r},e,AES_KEY_BITS),a=await crypto.subtle.importKey("raw",t,{name:"AES-GCM",length:AES_KEY_BITS},!1,["encrypt","decrypt"]);return(0,shared_1.ok)(a)}catch{return(0,shared_1.err)("DERIVE_FAILED")}}async function senderKeyAgreement(e){const r=await generateEphemeralKeyPair();if(!r.ok)return r;const t=await deriveSharedKeyECDH(r.value.privateKey,e);return t.ok?(0,shared_1.ok)({sharedKey:t.value,ephemeralPublicKey:r.value.rawPublicKey}):t}async function receiverKeyAgreement(e,r){const t=await importX25519PublicKey(r);return t.ok?deriveSharedKeyECDH(e,t.value):t}const HYBRID_HKDF_INFO="xail-hybrid-kem-v2";async function combineSharedSecrets(e,r,t,a,n,i){try{const c=e.length+r.length+t.length+a.length+n.length+i.length,y=new Uint8Array(c);let s=0;y.set(e,s),s+=e.length,y.set(r,s),s+=r.length,y.set(t,s),s+=t.length,y.set(a,s),s+=a.length,y.set(n,s),s+=n.length,y.set(i,s);const o=(new TextEncoder).encode("XWingKEM"),u=await crypto.subtle.importKey("raw",toArrayBuffer(y),"HKDF",!1,["deriveBits"]),l=await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:o,info:(new TextEncoder).encode(HYBRID_HKDF_INFO)},u,AES_KEY_BITS),K=await crypto.subtle.importKey("raw",l,{name:"AES-GCM",length:AES_KEY_BITS},!1,["encrypt","decrypt"]);return(0,shared_1.ok)(K)}catch{return(0,shared_1.err)("HKDF_FAILED")}}async function senderHybridKeyAgreement(e,r){const t=await generateEphemeralKeyPair();if(!t.ok)return t;let a,n,i,c;try{a=new Uint8Array(await crypto.subtle.deriveBits({name:"X25519",public:e},t.value.privateKey,AES_KEY_BITS))}catch{return(0,shared_1.err)("DERIVE_FAILED")}try{const e=await(0,mlkem_1.createMlKem768)(),[t,a]=e.encap(r);n=t,i=a}catch{return(0,shared_1.err)("KEM_ENCAPSULATE_FAILED")}try{const r=await crypto.subtle.exportKey("raw",e);c=new Uint8Array(r)}catch{return(0,shared_1.err)("EXPORT_KEY_FAILED")}const y=await combineSharedSecrets(i,n,a,t.value.rawPublicKey,c,r);return y.ok?(0,shared_1.ok)({sharedKey:y.value,ephemeralPublicKey:t.value.rawPublicKey,kemCiphertext:n}):y}async function receiverHybridKeyAgreement(e,r,t,a,n,i){const c=await importX25519PublicKey(t);if(!c.ok)return c;let y,s;try{y=new Uint8Array(await crypto.subtle.deriveBits({name:"X25519",public:c.value},e,AES_KEY_BITS))}catch{return(0,shared_1.err)("DERIVE_FAILED")}try{s=(await(0,mlkem_1.createMlKem768)()).decap(a,n)}catch{return(0,shared_1.err)("KEM_DECAPSULATE_FAILED")}return combineSharedSecrets(s,a,y,t,r,i)}
|