@private.me/xbind 1.3.5 → 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 -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,421 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module invitation
|
|
4
|
-
* Growth hack: Turn recipient-not-found failures into invitation opportunities.
|
|
5
|
-
*
|
|
6
|
-
* When agent.send() fails because recipient is not registered, this module
|
|
7
|
-
* provides an invitation mechanism to turn failures into viral growth.
|
|
8
|
-
*
|
|
9
|
-
* Flow:
|
|
10
|
-
* 1. Sender calls agent.send({ to: 'unregistered@example.com', ... })
|
|
11
|
-
* 2. send() fails with RECIPIENT_NOT_FOUND
|
|
12
|
-
* 3. Error includes invitationToken and inviteUrl
|
|
13
|
-
* 4. Sender shares URL with recipient
|
|
14
|
-
* 5. Recipient clicks link, signs up, joins Xail
|
|
15
|
-
* 6. Connection auto-establishes
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.InvitationStore = exports.InvitationClient = exports.InvitationErrorCode = void 0;
|
|
19
|
-
exports.generateInvitationToken = generateInvitationToken;
|
|
20
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
21
|
-
/**
|
|
22
|
-
* Error codes for invitation operations.
|
|
23
|
-
*/
|
|
24
|
-
var InvitationErrorCode;
|
|
25
|
-
(function (InvitationErrorCode) {
|
|
26
|
-
/** Invitation token is invalid format */
|
|
27
|
-
InvitationErrorCode["INVALID_TOKEN"] = "INVITATION_INVALID_TOKEN";
|
|
28
|
-
/** Invitation token has expired */
|
|
29
|
-
InvitationErrorCode["EXPIRED_TOKEN"] = "INVITATION_EXPIRED_TOKEN";
|
|
30
|
-
/** Invitation token already redeemed */
|
|
31
|
-
InvitationErrorCode["ALREADY_REDEEMED"] = "INVITATION_ALREADY_REDEEMED";
|
|
32
|
-
/** Rate limit exceeded (10 invitations/day per DID) */
|
|
33
|
-
InvitationErrorCode["RATE_LIMIT_EXCEEDED"] = "INVITATION_RATE_LIMIT_EXCEEDED";
|
|
34
|
-
/** Server communication failed */
|
|
35
|
-
InvitationErrorCode["SERVER_ERROR"] = "INVITATION_SERVER_ERROR";
|
|
36
|
-
})(InvitationErrorCode || (exports.InvitationErrorCode = InvitationErrorCode = {}));
|
|
37
|
-
/**
|
|
38
|
-
* Client-side invitation manager.
|
|
39
|
-
* Creates invitations after send() failures and manages their lifecycle.
|
|
40
|
-
*/
|
|
41
|
-
class InvitationClient {
|
|
42
|
-
invitationApiUrl;
|
|
43
|
-
/**
|
|
44
|
-
* Create invitation client.
|
|
45
|
-
*
|
|
46
|
-
* @param options - Configuration
|
|
47
|
-
* @param options.invitationApiUrl - Invitation API URL (default: https://api.private.me)
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* const inviteClient = new InvitationClient();
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
constructor(options = {}) {
|
|
55
|
-
this.invitationApiUrl = options.invitationApiUrl || 'https://api.private.me';
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Create an invitation for a recipient who is not yet registered.
|
|
59
|
-
*
|
|
60
|
-
* Called automatically when agent.send() returns RECIPIENT_NOT_FOUND.
|
|
61
|
-
* Generates a time-limited invitation token that can be shared via email/SMS.
|
|
62
|
-
*
|
|
63
|
-
* @param senderDid - DID of the agent sending the invitation
|
|
64
|
-
* @param recipientContact - Email address or identifier of recipient
|
|
65
|
-
* @param expiryDays - Days until invitation expires (default: 7)
|
|
66
|
-
* @returns Invitation token with shareable URL or error
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```ts
|
|
70
|
-
* const inviteResult = await inviteClient.create(
|
|
71
|
-
* 'did:key:z6Mk...',
|
|
72
|
-
* 'alice@example.com',
|
|
73
|
-
* 7 // 7-day expiry
|
|
74
|
-
* );
|
|
75
|
-
*
|
|
76
|
-
* if (inviteResult.ok) {
|
|
77
|
-
* // Share inviteResult.value.inviteUrl with recipient
|
|
78
|
-
* console.log('Share this link:', inviteResult.value.inviteUrl);
|
|
79
|
-
* } else {
|
|
80
|
-
* // Handle error
|
|
81
|
-
* console.error('Failed:', inviteResult.error.message);
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
async create(senderDid, recipientContact, expiryDays = 7) {
|
|
86
|
-
try {
|
|
87
|
-
const response = await fetch(`${this.invitationApiUrl}/invitations/create`, {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
},
|
|
92
|
-
body: JSON.stringify({
|
|
93
|
-
senderDid,
|
|
94
|
-
recipientContact,
|
|
95
|
-
expiryDays,
|
|
96
|
-
}),
|
|
97
|
-
});
|
|
98
|
-
if (response.status === 429) {
|
|
99
|
-
return (0, shared_1.err)({
|
|
100
|
-
code: InvitationErrorCode.RATE_LIMIT_EXCEEDED,
|
|
101
|
-
message: 'Too many invitations created. Limit: 10 per day',
|
|
102
|
-
hint: 'Wait before creating more invitations',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (!response.ok) {
|
|
106
|
-
return (0, shared_1.err)({
|
|
107
|
-
code: InvitationErrorCode.SERVER_ERROR,
|
|
108
|
-
message: `Server error: ${response.status}`,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const data = await response.json();
|
|
112
|
-
return (0, shared_1.ok)({
|
|
113
|
-
token: data.token,
|
|
114
|
-
expiresAt: new Date(data.expiresAt),
|
|
115
|
-
senderDid: data.senderDid,
|
|
116
|
-
recipientContact: data.recipientContact,
|
|
117
|
-
inviteUrl: data.inviteUrl,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
return (0, shared_1.err)({
|
|
122
|
-
code: InvitationErrorCode.SERVER_ERROR,
|
|
123
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Redeem an invitation token and create a new DID for the recipient.
|
|
129
|
-
*
|
|
130
|
-
* Called by recipient after clicking invitation link.
|
|
131
|
-
* Returns a new DID that can be used immediately for messaging.
|
|
132
|
-
*
|
|
133
|
-
* @param token - Invitation token from URL query parameter
|
|
134
|
-
* @returns New DID for recipient or error
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```ts
|
|
138
|
-
* // From URL: https://private.me/invite?token=abc123
|
|
139
|
-
* const urlParams = new URLSearchParams(window.location.search);
|
|
140
|
-
* const token = urlParams.get('token');
|
|
141
|
-
*
|
|
142
|
-
* const redeemResult = await inviteClient.redeem(token);
|
|
143
|
-
* if (redeemResult.ok) {
|
|
144
|
-
* // Auto-create agent with new DID
|
|
145
|
-
* const agent = await Agent.create(redeemResult.value);
|
|
146
|
-
* } else {
|
|
147
|
-
* // Handle: expired, already used, invalid
|
|
148
|
-
* console.error(redeemResult.error.message);
|
|
149
|
-
* }
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
async redeem(token) {
|
|
153
|
-
try {
|
|
154
|
-
if (!token || typeof token !== 'string') {
|
|
155
|
-
return (0, shared_1.err)({
|
|
156
|
-
code: InvitationErrorCode.INVALID_TOKEN,
|
|
157
|
-
message: 'Invitation token is required',
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
const response = await fetch(`${this.invitationApiUrl}/invitations/redeem`, {
|
|
161
|
-
method: 'POST',
|
|
162
|
-
headers: {
|
|
163
|
-
'Content-Type': 'application/json',
|
|
164
|
-
},
|
|
165
|
-
body: JSON.stringify({ token }),
|
|
166
|
-
});
|
|
167
|
-
if (response.status === 400) {
|
|
168
|
-
return (0, shared_1.err)({
|
|
169
|
-
code: InvitationErrorCode.INVALID_TOKEN,
|
|
170
|
-
message: 'Invitation token is invalid',
|
|
171
|
-
hint: 'Check the token in your URL',
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if (response.status === 410) {
|
|
175
|
-
const data = await response.json();
|
|
176
|
-
if (data.reason === 'expired') {
|
|
177
|
-
return (0, shared_1.err)({
|
|
178
|
-
code: InvitationErrorCode.EXPIRED_TOKEN,
|
|
179
|
-
message: 'Invitation has expired',
|
|
180
|
-
hint: 'Ask the sender for a new invitation',
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
return (0, shared_1.err)({
|
|
184
|
-
code: InvitationErrorCode.ALREADY_REDEEMED,
|
|
185
|
-
message: 'Invitation has already been used',
|
|
186
|
-
hint: 'Each invitation can only be used once',
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (!response.ok) {
|
|
190
|
-
return (0, shared_1.err)({
|
|
191
|
-
code: InvitationErrorCode.SERVER_ERROR,
|
|
192
|
-
message: `Server error: ${response.status}`,
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
const data = await response.json();
|
|
196
|
-
return (0, shared_1.ok)(data.did);
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
return (0, shared_1.err)({
|
|
200
|
-
code: InvitationErrorCode.SERVER_ERROR,
|
|
201
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get invitation details without redeeming.
|
|
207
|
-
*
|
|
208
|
-
* Used to preview sender name before accepting invitation.
|
|
209
|
-
*
|
|
210
|
-
* @param token - Invitation token
|
|
211
|
-
* @returns Invitation details or error
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* ```ts
|
|
215
|
-
* const detailsResult = await inviteClient.get(token);
|
|
216
|
-
* if (detailsResult.ok) {
|
|
217
|
-
* console.log(`${detailsResult.value.senderDid} invited you`);
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
async get(token) {
|
|
222
|
-
try {
|
|
223
|
-
const response = await fetch(`${this.invitationApiUrl}/invitations/${encodeURIComponent(token)}`, {
|
|
224
|
-
headers: {
|
|
225
|
-
'Accept': 'application/json',
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
if (response.status === 404) {
|
|
229
|
-
return (0, shared_1.err)({
|
|
230
|
-
code: InvitationErrorCode.INVALID_TOKEN,
|
|
231
|
-
message: 'Invitation not found',
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
if (!response.ok) {
|
|
235
|
-
return (0, shared_1.err)({
|
|
236
|
-
code: InvitationErrorCode.SERVER_ERROR,
|
|
237
|
-
message: `Server error: ${response.status}`,
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
const data = await response.json();
|
|
241
|
-
return (0, shared_1.ok)({
|
|
242
|
-
senderDid: data.senderDid,
|
|
243
|
-
recipientContact: data.recipientContact,
|
|
244
|
-
expiresAt: new Date(data.expiresAt),
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
return (0, shared_1.err)({
|
|
249
|
-
code: InvitationErrorCode.SERVER_ERROR,
|
|
250
|
-
message: error instanceof Error ? error.message : 'Network error',
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
exports.InvitationClient = InvitationClient;
|
|
256
|
-
/**
|
|
257
|
-
* Server-side invitation store (in-memory with JSONL persistence).
|
|
258
|
-
* Used by /invitations/* API endpoints.
|
|
259
|
-
*/
|
|
260
|
-
class InvitationStore {
|
|
261
|
-
invitations = new Map();
|
|
262
|
-
redeemedTokens = new Set();
|
|
263
|
-
/** Track invitation creation per DID for rate limiting (10/day) */
|
|
264
|
-
creationCounts = new Map();
|
|
265
|
-
/**
|
|
266
|
-
* Create an invitation and return token + expiry.
|
|
267
|
-
* Enforces rate limit: 10 invitations per DID per 24 hours.
|
|
268
|
-
*
|
|
269
|
-
* @param senderDid - DID creating the invitation
|
|
270
|
-
* @param recipientContact - Email or identifier
|
|
271
|
-
* @param expiryDays - Days until expiry
|
|
272
|
-
* @returns Token + metadata or error
|
|
273
|
-
*/
|
|
274
|
-
create(senderDid, recipientContact, expiryDays = 7) {
|
|
275
|
-
// Check rate limit
|
|
276
|
-
const now = Date.now();
|
|
277
|
-
const limit = this.creationCounts.get(senderDid);
|
|
278
|
-
if (limit && limit.count >= 10 && now < limit.resetTime) {
|
|
279
|
-
return (0, shared_1.err)({
|
|
280
|
-
code: InvitationErrorCode.RATE_LIMIT_EXCEEDED,
|
|
281
|
-
message: 'Rate limit exceeded. Maximum 10 invitations per day.',
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
// Reset counter if window expired
|
|
285
|
-
if (limit && now >= limit.resetTime) {
|
|
286
|
-
this.creationCounts.delete(senderDid);
|
|
287
|
-
}
|
|
288
|
-
// Generate token
|
|
289
|
-
const token = generateInvitationToken();
|
|
290
|
-
const expiresAt = now + (expiryDays * 24 * 60 * 60 * 1000);
|
|
291
|
-
const invitation = {
|
|
292
|
-
token,
|
|
293
|
-
senderDid,
|
|
294
|
-
recipientContact,
|
|
295
|
-
createdAt: now,
|
|
296
|
-
expiresAt,
|
|
297
|
-
redeemed: false,
|
|
298
|
-
};
|
|
299
|
-
this.invitations.set(token, invitation);
|
|
300
|
-
// Update rate limit counter
|
|
301
|
-
if (!limit) {
|
|
302
|
-
this.creationCounts.set(senderDid, {
|
|
303
|
-
count: 1,
|
|
304
|
-
resetTime: now + (24 * 60 * 60 * 1000), // 24-hour window
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
limit.count += 1;
|
|
309
|
-
}
|
|
310
|
-
return (0, shared_1.ok)(invitation);
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Get invitation by token without marking as redeemed.
|
|
314
|
-
*
|
|
315
|
-
* @param token - Token to lookup
|
|
316
|
-
* @returns Invitation or error
|
|
317
|
-
*/
|
|
318
|
-
get(token) {
|
|
319
|
-
const invitation = this.invitations.get(token);
|
|
320
|
-
if (!invitation) {
|
|
321
|
-
return (0, shared_1.err)({
|
|
322
|
-
code: InvitationErrorCode.INVALID_TOKEN,
|
|
323
|
-
message: 'Invitation not found',
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
const now = Date.now();
|
|
327
|
-
if (now > invitation.expiresAt) {
|
|
328
|
-
// Clean up expired invitation
|
|
329
|
-
this.invitations.delete(token);
|
|
330
|
-
return (0, shared_1.err)({
|
|
331
|
-
code: InvitationErrorCode.EXPIRED_TOKEN,
|
|
332
|
-
message: 'Invitation has expired',
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
if (invitation.redeemed) {
|
|
336
|
-
return (0, shared_1.err)({
|
|
337
|
-
code: InvitationErrorCode.ALREADY_REDEEMED,
|
|
338
|
-
message: 'Invitation has already been redeemed',
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
return (0, shared_1.ok)(invitation);
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Redeem an invitation (one-time use).
|
|
345
|
-
* Mark as redeemed and generate new DID.
|
|
346
|
-
*
|
|
347
|
-
* @param token - Token to redeem
|
|
348
|
-
* @returns New DID or error
|
|
349
|
-
*/
|
|
350
|
-
redeem(token) {
|
|
351
|
-
const getResult = this.get(token);
|
|
352
|
-
if (!getResult.ok) {
|
|
353
|
-
return getResult;
|
|
354
|
-
}
|
|
355
|
-
const invitation = getResult.value;
|
|
356
|
-
invitation.redeemed = true;
|
|
357
|
-
this.redeemedTokens.add(token);
|
|
358
|
-
// Generate DID for recipient
|
|
359
|
-
const did = generateRecipientDid(invitation.senderDid, invitation.recipientContact);
|
|
360
|
-
return (0, shared_1.ok)(did);
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Clean up expired invitations (run daily).
|
|
364
|
-
* @returns Number of invitations deleted
|
|
365
|
-
*/
|
|
366
|
-
cleanup() {
|
|
367
|
-
const now = Date.now();
|
|
368
|
-
let count = 0;
|
|
369
|
-
for (const [token, invitation] of this.invitations.entries()) {
|
|
370
|
-
if (now > invitation.expiresAt || invitation.redeemed) {
|
|
371
|
-
this.invitations.delete(token);
|
|
372
|
-
count += 1;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
return count;
|
|
376
|
-
}
|
|
377
|
-
/** Get active invitation count */
|
|
378
|
-
get count() {
|
|
379
|
-
return this.invitations.size;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
exports.InvitationStore = InvitationStore;
|
|
383
|
-
/**
|
|
384
|
-
* Generate a cryptographically secure invitation token.
|
|
385
|
-
* Format: 48-character hex string (192 bits).
|
|
386
|
-
* @returns Random token
|
|
387
|
-
*/
|
|
388
|
-
function generateInvitationToken() {
|
|
389
|
-
const bytes = new Uint8Array(24);
|
|
390
|
-
crypto.getRandomValues(bytes);
|
|
391
|
-
return Array.from(bytes)
|
|
392
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
393
|
-
.join('');
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Generate a deterministic DID for invited recipient.
|
|
397
|
-
* Ensures consistent identity across sessions.
|
|
398
|
-
*
|
|
399
|
-
* @param senderDid - DID of sender
|
|
400
|
-
* @param recipientContact - Email or identifier
|
|
401
|
-
* @returns Generated DID for recipient
|
|
402
|
-
*/
|
|
403
|
-
function generateRecipientDid(senderDid, recipientContact) {
|
|
404
|
-
// Create a simple derived identifier
|
|
405
|
-
// In production: derive from email + hash(senderDid) for uniqueness
|
|
406
|
-
const hash = hashString(`${senderDid}:${recipientContact}`);
|
|
407
|
-
return `did:key:z6Mk${hash}`;
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Simple hash function for DID generation.
|
|
411
|
-
* @param input - String to hash
|
|
412
|
-
* @returns Hex string
|
|
413
|
-
*/
|
|
414
|
-
function hashString(input) {
|
|
415
|
-
let hash = 0;
|
|
416
|
-
for (let i = 0; i < input.length; i += 1) {
|
|
417
|
-
hash = ((hash << 5) - hash) + input.charCodeAt(i);
|
|
418
|
-
hash = hash & hash; // Convert to 32bit integer
|
|
419
|
-
}
|
|
420
|
-
return Math.abs(hash).toString(16).padStart(8, '0');
|
|
421
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InvitationStore=exports.InvitationClient=exports.InvitationErrorCode=void 0,exports.generateInvitationToken=generateInvitationToken;const shared_1=require("../_deps/shared/index.js");var InvitationErrorCode;!function(e){e.INVALID_TOKEN="INVITATION_INVALID_TOKEN",e.EXPIRED_TOKEN="INVITATION_EXPIRED_TOKEN",e.ALREADY_REDEEMED="INVITATION_ALREADY_REDEEMED",e.RATE_LIMIT_EXCEEDED="INVITATION_RATE_LIMIT_EXCEEDED",e.SERVER_ERROR="INVITATION_SERVER_ERROR"}(InvitationErrorCode||(exports.InvitationErrorCode=InvitationErrorCode={}));class InvitationClient{invitationApiUrl;constructor(e={}){this.invitationApiUrl=e.invitationApiUrl||"https://api.private.me"}async create(e,t,r=7){try{const n=await fetch(`${this.invitationApiUrl}/invitations/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({senderDid:e,recipientContact:t,expiryDays:r})});if(429===n.status)return(0,shared_1.err)({code:InvitationErrorCode.RATE_LIMIT_EXCEEDED,message:"Too many invitations created. Limit: 10 per day",hint:"Wait before creating more invitations"});if(!n.ok)return(0,shared_1.err)({code:InvitationErrorCode.SERVER_ERROR,message:`Server error: ${n.status}`});const i=await n.json();return(0,shared_1.ok)({token:i.token,expiresAt:new Date(i.expiresAt),senderDid:i.senderDid,recipientContact:i.recipientContact,inviteUrl:i.inviteUrl})}catch(e){return(0,shared_1.err)({code:InvitationErrorCode.SERVER_ERROR,message:e instanceof Error?e.message:"Network error"})}}async redeem(e){try{if(!e||"string"!=typeof e)return(0,shared_1.err)({code:InvitationErrorCode.INVALID_TOKEN,message:"Invitation token is required"});const t=await fetch(`${this.invitationApiUrl}/invitations/redeem`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e})});if(400===t.status)return(0,shared_1.err)({code:InvitationErrorCode.INVALID_TOKEN,message:"Invitation token is invalid",hint:"Check the token in your URL"});if(410===t.status){return"expired"===(await t.json()).reason?(0,shared_1.err)({code:InvitationErrorCode.EXPIRED_TOKEN,message:"Invitation has expired",hint:"Ask the sender for a new invitation"}):(0,shared_1.err)({code:InvitationErrorCode.ALREADY_REDEEMED,message:"Invitation has already been used",hint:"Each invitation can only be used once"})}if(!t.ok)return(0,shared_1.err)({code:InvitationErrorCode.SERVER_ERROR,message:`Server error: ${t.status}`});const r=await t.json();return(0,shared_1.ok)(r.did)}catch(e){return(0,shared_1.err)({code:InvitationErrorCode.SERVER_ERROR,message:e instanceof Error?e.message:"Network error"})}}async get(e){try{const t=await fetch(`${this.invitationApiUrl}/invitations/${encodeURIComponent(e)}`,{headers:{Accept:"application/json"}});if(404===t.status)return(0,shared_1.err)({code:InvitationErrorCode.INVALID_TOKEN,message:"Invitation not found"});if(!t.ok)return(0,shared_1.err)({code:InvitationErrorCode.SERVER_ERROR,message:`Server error: ${t.status}`});const r=await t.json();return(0,shared_1.ok)({senderDid:r.senderDid,recipientContact:r.recipientContact,expiresAt:new Date(r.expiresAt)})}catch(e){return(0,shared_1.err)({code:InvitationErrorCode.SERVER_ERROR,message:e instanceof Error?e.message:"Network error"})}}}exports.InvitationClient=InvitationClient;class InvitationStore{invitations=new Map;redeemedTokens=new Set;creationCounts=new Map;create(e,t,r=7){const n=Date.now(),i=this.creationCounts.get(e);if(i&&i.count>=10&&n<i.resetTime)return(0,shared_1.err)({code:InvitationErrorCode.RATE_LIMIT_EXCEEDED,message:"Rate limit exceeded. Maximum 10 invitations per day."});i&&n>=i.resetTime&&this.creationCounts.delete(e);const o=generateInvitationToken(),a={token:o,senderDid:e,recipientContact:t,createdAt:n,expiresAt:n+24*r*60*60*1e3,redeemed:!1};return this.invitations.set(o,a),i?i.count+=1:this.creationCounts.set(e,{count:1,resetTime:n+864e5}),(0,shared_1.ok)(a)}get(e){const t=this.invitations.get(e);if(!t)return(0,shared_1.err)({code:InvitationErrorCode.INVALID_TOKEN,message:"Invitation not found"});return Date.now()>t.expiresAt?(this.invitations.delete(e),(0,shared_1.err)({code:InvitationErrorCode.EXPIRED_TOKEN,message:"Invitation has expired"})):t.redeemed?(0,shared_1.err)({code:InvitationErrorCode.ALREADY_REDEEMED,message:"Invitation has already been redeemed"}):(0,shared_1.ok)(t)}redeem(e){const t=this.get(e);if(!t.ok)return t;const r=t.value;r.redeemed=!0,this.redeemedTokens.add(e);const n=generateRecipientDid(r.senderDid,r.recipientContact);return(0,shared_1.ok)(n)}cleanup(){const e=Date.now();let t=0;for(const[r,n]of this.invitations.entries())(e>n.expiresAt||n.redeemed)&&(this.invitations.delete(r),t+=1);return t}get count(){return this.invitations.size}}function generateInvitationToken(){const e=new Uint8Array(24);return crypto.getRandomValues(e),Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function generateRecipientDid(e,t){return`did:key:z6Mk${hashString(`${e}:${t}`)}`}function hashString(e){let t=0;for(let r=0;r<e.length;r+=1)t=(t<<5)-t+e.charCodeAt(r),t&=t;return Math.abs(t).toString(16).padStart(8,"0")}exports.InvitationStore=InvitationStore;
|