@enbox/auth 0.4.0 → 0.6.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.
Files changed (86) hide show
  1. package/dist/esm/auth-manager.js +244 -121
  2. package/dist/esm/auth-manager.js.map +1 -1
  3. package/dist/esm/connect/import.js +131 -0
  4. package/dist/esm/connect/import.js.map +1 -0
  5. package/dist/esm/connect/lifecycle.js +235 -0
  6. package/dist/esm/connect/lifecycle.js.map +1 -0
  7. package/dist/esm/connect/local.js +91 -0
  8. package/dist/esm/connect/local.js.map +1 -0
  9. package/dist/esm/{flows/session-restore.js → connect/restore.js} +39 -50
  10. package/dist/esm/connect/restore.js.map +1 -0
  11. package/dist/esm/{flows/wallet-connect.js → connect/wallet.js} +33 -39
  12. package/dist/esm/connect/wallet.js.map +1 -0
  13. package/dist/esm/{flows/dwn-discovery.js → discovery.js} +98 -83
  14. package/dist/esm/discovery.js.map +1 -0
  15. package/dist/esm/index.js +7 -3
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/password-provider.js +319 -0
  18. package/dist/esm/password-provider.js.map +1 -0
  19. package/dist/esm/{flows/dwn-registration.js → registration.js} +50 -4
  20. package/dist/esm/registration.js.map +1 -0
  21. package/dist/esm/types.js +11 -1
  22. package/dist/esm/types.js.map +1 -1
  23. package/dist/esm/wallet-connect-client.js +188 -0
  24. package/dist/esm/wallet-connect-client.js.map +1 -0
  25. package/dist/types/auth-manager.d.ts +86 -7
  26. package/dist/types/auth-manager.d.ts.map +1 -1
  27. package/dist/types/connect/import.d.ts +25 -0
  28. package/dist/types/connect/import.d.ts.map +1 -0
  29. package/dist/types/connect/lifecycle.d.ts +152 -0
  30. package/dist/types/connect/lifecycle.d.ts.map +1 -0
  31. package/dist/types/connect/local.d.ts +18 -0
  32. package/dist/types/connect/local.d.ts.map +1 -0
  33. package/dist/types/connect/restore.d.ts +18 -0
  34. package/dist/types/connect/restore.d.ts.map +1 -0
  35. package/dist/types/{flows/wallet-connect.d.ts → connect/wallet.d.ts} +7 -16
  36. package/dist/types/connect/wallet.d.ts.map +1 -0
  37. package/dist/types/{flows/dwn-discovery.d.ts → discovery.d.ts} +43 -56
  38. package/dist/types/discovery.d.ts.map +1 -0
  39. package/dist/types/index.d.ts +8 -4
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/types/password-provider.d.ts +194 -0
  42. package/dist/types/password-provider.d.ts.map +1 -0
  43. package/dist/types/{flows/dwn-registration.d.ts → registration.d.ts} +21 -2
  44. package/dist/types/registration.d.ts.map +1 -0
  45. package/dist/types/types.d.ts +92 -4
  46. package/dist/types/types.d.ts.map +1 -1
  47. package/dist/types/wallet-connect-client.d.ts +89 -0
  48. package/dist/types/wallet-connect-client.d.ts.map +1 -0
  49. package/package.json +15 -12
  50. package/src/auth-manager.ts +279 -145
  51. package/src/connect/import.ts +148 -0
  52. package/src/connect/lifecycle.ts +321 -0
  53. package/src/connect/local.ts +101 -0
  54. package/src/connect/restore.ts +117 -0
  55. package/src/{flows/wallet-connect.ts → connect/wallet.ts} +42 -58
  56. package/src/{flows/dwn-discovery.ts → discovery.ts} +103 -82
  57. package/src/index.ts +14 -4
  58. package/src/password-provider.ts +383 -0
  59. package/src/{flows/dwn-registration.ts → registration.ts} +61 -6
  60. package/src/types.ts +100 -4
  61. package/src/wallet-connect-client.ts +278 -0
  62. package/dist/esm/flows/dwn-discovery.js.map +0 -1
  63. package/dist/esm/flows/dwn-registration.js.map +0 -1
  64. package/dist/esm/flows/import-identity.js +0 -175
  65. package/dist/esm/flows/import-identity.js.map +0 -1
  66. package/dist/esm/flows/local-connect.js +0 -141
  67. package/dist/esm/flows/local-connect.js.map +0 -1
  68. package/dist/esm/flows/session-restore.js.map +0 -1
  69. package/dist/esm/flows/wallet-connect.js.map +0 -1
  70. package/dist/esm/vault/vault-manager.js +0 -95
  71. package/dist/esm/vault/vault-manager.js.map +0 -1
  72. package/dist/types/flows/dwn-discovery.d.ts.map +0 -1
  73. package/dist/types/flows/dwn-registration.d.ts.map +0 -1
  74. package/dist/types/flows/import-identity.d.ts +0 -35
  75. package/dist/types/flows/import-identity.d.ts.map +0 -1
  76. package/dist/types/flows/local-connect.d.ts +0 -29
  77. package/dist/types/flows/local-connect.d.ts.map +0 -1
  78. package/dist/types/flows/session-restore.d.ts +0 -27
  79. package/dist/types/flows/session-restore.d.ts.map +0 -1
  80. package/dist/types/flows/wallet-connect.d.ts.map +0 -1
  81. package/dist/types/vault/vault-manager.d.ts +0 -57
  82. package/dist/types/vault/vault-manager.d.ts.map +0 -1
  83. package/src/flows/import-identity.ts +0 -217
  84. package/src/flows/local-connect.ts +0 -171
  85. package/src/flows/session-restore.ts +0 -142
  86. package/src/vault/vault-manager.ts +0 -89
@@ -5,11 +5,10 @@
5
5
  * multi-identity-aware auth system that works in both browser and CLI environments.
6
6
  * @module
7
7
  */
8
+ import type { HdIdentityVault, PortableIdentity } from '@enbox/agent';
9
+ import type { AuthEvent, AuthEventHandler, AuthManagerOptions, AuthState, DisconnectOptions, HeadlessConnectOptions, IdentityInfo, ImportFromPhraseOptions, ImportFromPortableOptions, LocalConnectOptions, RestoreSessionOptions, ShutdownOptions, WalletConnectOptions } from './types.js';
8
10
  import { EnboxUserAgent } from '@enbox/agent';
9
- import type { PortableIdentity } from '@enbox/agent';
10
11
  import { AuthSession } from './identity-session.js';
11
- import { VaultManager } from './vault/vault-manager.js';
12
- import type { AuthEvent, AuthEventHandler, AuthManagerOptions, AuthState, DisconnectOptions, IdentityInfo, ImportFromPhraseOptions, ImportFromPortableOptions, LocalConnectOptions, RestoreSessionOptions, WalletConnectOptions } from './types.js';
13
12
  /**
14
13
  * The primary entry point for authentication and identity management.
15
14
  *
@@ -47,14 +46,22 @@ export declare class AuthManager {
47
46
  private _userAgent;
48
47
  private _emitter;
49
48
  private _storage;
50
- private _vault;
51
49
  private _session;
52
50
  private _state;
53
51
  private _isConnecting;
52
+ private _isShutDown;
54
53
  private _defaultPassword?;
54
+ private _passwordProvider?;
55
55
  private _defaultSync?;
56
56
  private _defaultDwnEndpoints?;
57
57
  private _registration?;
58
+ /**
59
+ * The local DWN server endpoint discovered during `create()`, if any.
60
+ * `undefined` means no local server was found. This is set before any
61
+ * event listeners are attached, so consumers should check this property
62
+ * after `create()` returns rather than relying solely on events.
63
+ */
64
+ private _localDwnEndpoint?;
58
65
  private constructor();
59
66
  /**
60
67
  * Create a new AuthManager instance.
@@ -79,7 +86,7 @@ export declare class AuthManager {
79
86
  */
80
87
  connect(options?: LocalConnectOptions): Promise<AuthSession>;
81
88
  /**
82
- * Connect to an external wallet via the OIDC/QR relay protocol.
89
+ * Connect to an external wallet via the Enbox Connect relay protocol.
83
90
  *
84
91
  * This runs the full WalletConnect flow: generates a URI for QR display,
85
92
  * validates the PIN, imports the delegated DID, and processes grants.
@@ -110,6 +117,30 @@ export declare class AuthManager {
110
117
  * This replaces the manual `previouslyConnected` localStorage pattern.
111
118
  */
112
119
  restoreSession(options?: RestoreSessionOptions): Promise<AuthSession | undefined>;
120
+ /**
121
+ * Lightweight vault unlock for one-shot utilities and subprocesses.
122
+ *
123
+ * Unlocks the vault and retrieves the active (or first available)
124
+ * identity **without** starting sync, DWN registration, or persisting
125
+ * session markers. This is the recommended replacement for calling
126
+ * `agent.start({ password })` directly.
127
+ *
128
+ * Typical use cases:
129
+ * - Git credential helpers that need to sign a token and exit
130
+ * - CLI utilities that perform a single operation
131
+ * - Any subprocess that shares a data directory with a long-running daemon
132
+ *
133
+ * @param options - Optional password override.
134
+ * @returns An active AuthSession (with sync disabled).
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const session = await auth.connectHeadless({ password });
139
+ * const did = session.did; // ready to use
140
+ * await auth.shutdown(); // clean exit
141
+ * ```
142
+ */
143
+ connectHeadless(options?: HeadlessConnectOptions): Promise<AuthSession>;
113
144
  /** The current active session, or `undefined` if not connected. */
114
145
  get session(): AuthSession | undefined;
115
146
  /**
@@ -137,6 +168,30 @@ export declare class AuthManager {
137
168
  * @param options.timeout - Milliseconds to wait for sync to complete.
138
169
  */
139
170
  disconnect(options?: DisconnectOptions): Promise<void>;
171
+ /**
172
+ * Gracefully shut down the auth manager, releasing all resources.
173
+ *
174
+ * This goes beyond {@link disconnect} or {@link lock}: it stops sync,
175
+ * clears the active session, locks the vault, and **closes** the
176
+ * underlying storage handles (e.g. LevelDB) so the process can exit
177
+ * without dangling timers or open file descriptors.
178
+ *
179
+ * After calling `shutdown()`, the `AuthManager` instance should not be
180
+ * reused — create a new one via {@link AuthManager.create} if needed.
181
+ *
182
+ * Idempotent: calling `shutdown()` more than once is safe.
183
+ *
184
+ * @param options - Optional shutdown configuration.
185
+ * @param options.timeout - Milliseconds to wait for sync to stop. Default: `2000`.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const session = await auth.connectHeadless({ password });
190
+ * // ... perform work ...
191
+ * await auth.shutdown(); // clean exit, no process.exit() needed
192
+ * ```
193
+ */
194
+ shutdown(options?: ShutdownOptions): Promise<void>;
140
195
  /**
141
196
  * List all stored identities.
142
197
  *
@@ -166,8 +221,8 @@ export declare class AuthManager {
166
221
  * to another device.
167
222
  */
168
223
  exportIdentity(didUri: string): Promise<PortableIdentity>;
169
- /** Access the vault manager for lock/unlock/backup operations. */
170
- get vault(): VaultManager;
224
+ /** Access the underlying identity vault for lock/unlock/backup operations. */
225
+ get vault(): HdIdentityVault;
171
226
  /**
172
227
  * Subscribe to an auth lifecycle event.
173
228
  *
@@ -186,6 +241,30 @@ export declare class AuthManager {
186
241
  get isConnecting(): boolean;
187
242
  /** The underlying EnboxUserAgent (for advanced usage). */
188
243
  get agent(): EnboxUserAgent;
244
+ /**
245
+ * The local DWN server endpoint discovered during `create()`, if any.
246
+ *
247
+ * When set, the agent is operating in remote mode (no in-process DWN).
248
+ * This property is available immediately after `create()` returns,
249
+ * before any event listeners are attached.
250
+ */
251
+ get localDwnEndpoint(): string | undefined;
252
+ /**
253
+ * Build a `FlowContext` from the manager's current state.
254
+ *
255
+ * Replaces the 5 manual inline context constructions that were
256
+ * previously duplicated across `connect()`, `walletConnect()`,
257
+ * `importFromPhrase()`, `importFromPortable()`, and `restoreSession()`.
258
+ */
259
+ private _flowContext;
260
+ /**
261
+ * Template for connection flows that follow the guard → try/finally → setState pattern.
262
+ *
263
+ * Consolidates the duplicated concurrency guard, `_isConnecting` flag management,
264
+ * session assignment, and state transition across `connect()`, `walletConnect()`,
265
+ * `importFromPhrase()`, and `importFromPortable()`.
266
+ */
267
+ private _withConnect;
189
268
  private _setState;
190
269
  private _guardConcurrency;
191
270
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auth-manager.d.ts","sourceRoot":"","sources":["../../src/auth-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAkB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EAEnB,qBAAqB,EAGrB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,aAAa,CAAS;IAG9B,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,YAAY,CAAC,CAAa;IAClC,OAAO,CA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+ * @module
7
+ */
8
+ import type { AuthSession } from '../identity-session.js';
9
+ import type { FlowContext } from './lifecycle.js';
10
+ import type { ImportFromPhraseOptions, ImportFromPortableOptions } from '../types.js';
11
+ /**
12
+ * Import (or recover) an identity from a BIP-39 recovery phrase.
13
+ *
14
+ * This re-initializes the vault with the given phrase and password,
15
+ * recovering the agent DID and all derived keys.
16
+ */
17
+ export declare function importFromPhrase(ctx: FlowContext, options: ImportFromPhraseOptions): Promise<AuthSession>;
18
+ /**
19
+ * Import an identity from a PortableIdentity JSON object.
20
+ *
21
+ * The portable identity contains the DID's private keys and metadata,
22
+ * allowing it to be used on this device.
23
+ */
24
+ export declare function importFromPortable(ctx: FlowContext, options: ImportFromPortableOptions): Promise<AuthSession>;
25
+ //# sourceMappingURL=import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../../src/connect/import.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAMtF;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,WAAW,CAAC,CAiEtB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,WAAW,CAAC,CA8CtB"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Shared helpers for connect flows.
3
+ *
4
+ * Consolidates duplicated logic across `local-connect`, `session-restore`,
5
+ * `wallet-connect`, and `import-identity` flows:
6
+ *
7
+ * - Password resolution chain
8
+ * - Vault init/start lifecycle
9
+ * - Sync mode/interval calculation and startup
10
+ * - `connectedDid` / `delegateDid` derivation from identity metadata
11
+ * - Session finalization (storage persistence + AuthSession construction + events)
12
+ *
13
+ * @module
14
+ * @internal
15
+ */
16
+ import type { BearerIdentity, EnboxUserAgent } from '@enbox/agent';
17
+ import type { AuthEventEmitter } from '../events.js';
18
+ import type { PasswordProvider } from '../password-provider.js';
19
+ import type { RegistrationOptions, StorageAdapter, SyncOption } from '../types.js';
20
+ import { AuthSession } from '../identity-session.js';
21
+ /**
22
+ * Unified context passed from `AuthManager` to every connect flow.
23
+ *
24
+ * Replaces the per-flow `LocalConnectContext`, `SessionRestoreContext`,
25
+ * `WalletConnectContext`, and `ImportContext` interfaces. All fields are
26
+ * optional beyond the core triple (`userAgent`, `emitter`, `storage`) so
27
+ * flows only consume what they need.
28
+ *
29
+ * @internal
30
+ */
31
+ export interface FlowContext {
32
+ userAgent: EnboxUserAgent;
33
+ emitter: AuthEventEmitter;
34
+ storage: StorageAdapter;
35
+ defaultPassword?: string;
36
+ passwordProvider?: PasswordProvider;
37
+ defaultSync?: SyncOption;
38
+ defaultDwnEndpoints?: string[];
39
+ registration?: RegistrationOptions;
40
+ }
41
+ /**
42
+ * Resolve a password through the standard chain:
43
+ * explicit option → manager default → provider → insecure fallback.
44
+ *
45
+ * Emits a console warning when the insecure default is used.
46
+ *
47
+ * @param ctx - The flow context (provides `defaultPassword` and `passwordProvider`).
48
+ * @param explicit - An explicit password from the caller (highest priority).
49
+ * @param isFirstLaunch - Whether the vault has never been initialized.
50
+ * @returns The resolved password string.
51
+ *
52
+ * @internal
53
+ */
54
+ export declare function resolvePassword(ctx: Pick<FlowContext, 'defaultPassword' | 'passwordProvider'>, explicit: string | undefined, isFirstLaunch: boolean): Promise<string>;
55
+ /**
56
+ * Initialize (on first launch) and start the agent, then emit `vault-unlocked`.
57
+ *
58
+ * This consolidates the 5 copies of:
59
+ * ```ts
60
+ * if (isFirstLaunch) { await userAgent.initialize({ password, ... }); }
61
+ * await userAgent.start({ password });
62
+ * emitter.emit('vault-unlocked', {});
63
+ * ```
64
+ *
65
+ * @returns The recovery phrase if the vault was just initialized, otherwise `undefined`.
66
+ *
67
+ * @internal
68
+ */
69
+ export declare function ensureVaultReady(params: {
70
+ userAgent: EnboxUserAgent;
71
+ emitter: AuthEventEmitter;
72
+ password: string;
73
+ isFirstLaunch: boolean;
74
+ recoveryPhrase?: string;
75
+ dwnEndpoints?: string[];
76
+ }): Promise<string | undefined>;
77
+ /**
78
+ * Start DWN synchronisation if `sync` is not `'off'`.
79
+ *
80
+ * Consolidates 6 copies of:
81
+ * ```ts
82
+ * const syncMode = sync === undefined ? 'live' : 'poll';
83
+ * const syncInterval = sync ?? (syncMode === 'live' ? '5m' : '2m');
84
+ * userAgent.sync.startSync({ mode: syncMode, interval: syncInterval })
85
+ * .catch((err) => console.error('[@enbox/auth] Sync failed:', err));
86
+ * ```
87
+ *
88
+ * @internal
89
+ */
90
+ export declare function startSyncIfEnabled(userAgent: EnboxUserAgent, sync: SyncOption | undefined): void;
91
+ /**
92
+ * Create a new `did:dht` identity with Ed25519 signing and X25519
93
+ * encryption keys, and a DWN service endpoint.
94
+ *
95
+ * This consolidates the identical identity creation block that was
96
+ * duplicated in `localConnect` and `importFromPhrase`.
97
+ *
98
+ * @internal
99
+ */
100
+ export declare function createDefaultIdentity(userAgent: EnboxUserAgent, dwnEndpoints?: string[], name?: string): Promise<BearerIdentity>;
101
+ /**
102
+ * Derive `connectedDid` and `delegateDid` from identity metadata.
103
+ *
104
+ * For a **local** identity: `connectedDid` is the identity's own DID URI
105
+ * and `delegateDid` is `undefined`.
106
+ *
107
+ * For a **wallet-connected** identity: `connectedDid` is the external wallet
108
+ * DID, and `delegateDid` is the local identity's DID URI.
109
+ *
110
+ * @param identity - The bearer identity to extract DIDs from.
111
+ * @param storedDelegateDid - Optional fallback delegate DID from storage,
112
+ * used by session-restore when the identity metadata doesn't include a
113
+ * `connectedDid` but a delegate DID was persisted in a prior session.
114
+ *
115
+ * @internal
116
+ */
117
+ export declare function resolveIdentityDids(identity: BearerIdentity, storedDelegateDid?: string): {
118
+ connectedDid: string;
119
+ delegateDid: string | undefined;
120
+ };
121
+ /**
122
+ * Persist session markers, build an `AuthSession`, and emit lifecycle events.
123
+ *
124
+ * Consolidates 5 copies of:
125
+ * ```ts
126
+ * await storage.set(STORAGE_KEYS.PREVIOUSLY_CONNECTED, 'true');
127
+ * await storage.set(STORAGE_KEYS.ACTIVE_IDENTITY, connectedDid);
128
+ * const session = new AuthSession({ ... });
129
+ * emitter.emit('identity-added', { identity: identityInfo });
130
+ * emitter.emit('session-start', { session: { ... } });
131
+ * ```
132
+ *
133
+ * @param params.emitIdentityAdded - Whether to emit `identity-added`. Defaults to `true`.
134
+ * Set to `false` for session-restore (identity was already added in the original flow).
135
+ * @param params.extraStorageKeys - Additional key-value pairs to persist (e.g. delegate/connected DIDs
136
+ * for wallet-connect flows).
137
+ *
138
+ * @internal
139
+ */
140
+ export declare function finalizeSession(params: {
141
+ userAgent: EnboxUserAgent;
142
+ emitter: AuthEventEmitter;
143
+ storage: StorageAdapter;
144
+ connectedDid: string;
145
+ delegateDid?: string;
146
+ recoveryPhrase?: string;
147
+ identityName: string;
148
+ identityConnectedDid?: string;
149
+ emitIdentityAdded?: boolean;
150
+ extraStorageKeys?: Record<string, string>;
151
+ }): Promise<AuthSession>;
152
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../src/connect/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,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zB;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,cAAc,EACxB,iBAAiB,CAAC,EAAE,MAAM,GACzB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAMA;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC5C,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,GAAG,OAAO,CAAC,WAAW,CAAC,CA+CvB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Local DID connect flow.
3
+ *
4
+ * Creates or reconnects a local identity with vault-protected keys.
5
+ * This replaces the "Mode D/E" paths in Enbox.connect().
6
+ * @module
7
+ */
8
+ import type { AuthSession } from '../identity-session.js';
9
+ import type { FlowContext } from './lifecycle.js';
10
+ import type { LocalConnectOptions } from '../types.js';
11
+ /**
12
+ * Execute the local connect flow.
13
+ *
14
+ * - On first launch: initializes the vault, creates a new DID, returns recovery phrase.
15
+ * - On subsequent launches: unlocks the vault and reconnects to the existing identity.
16
+ */
17
+ export declare function localConnect(ctx: FlowContext, options?: LocalConnectOptions): Promise<AuthSession>;
18
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/connect/local.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAOvD;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,WAAW,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC,CA0EtB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Session restore flow.
3
+ *
4
+ * Restores a previously established session from persisted storage,
5
+ * replacing the "previouslyConnected" pattern in apps.
6
+ * @module
7
+ */
8
+ import type { AuthSession } from '../identity-session.js';
9
+ import type { FlowContext } from './lifecycle.js';
10
+ import type { RestoreSessionOptions } from '../types.js';
11
+ /**
12
+ * Attempt to restore a previous session.
13
+ *
14
+ * Returns `undefined` if no previous session exists.
15
+ * Returns an `AuthSession` if the session was successfully restored.
16
+ */
17
+ export declare function restoreSession(ctx: FlowContext, options?: RestoreSessionOptions): Promise<AuthSession | undefined>;
18
+ //# sourceMappingURL=restore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restore.d.ts","sourceRoot":"","sources":["../../../src/connect/restore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAMzD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,WAAW,EAChB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA2FlC"}
@@ -1,24 +1,15 @@
1
1
  /**
2
- * Wallet connect (OIDC/QR) flow.
2
+ * Wallet connect (Enbox Connect relay) flow.
3
3
  *
4
- * Connects to an external wallet via the WalletConnect relay protocol,
4
+ * Connects to an external wallet via the Enbox Connect relay protocol,
5
5
  * importing a delegated DID with permission grants.
6
6
  * This replaces the "Mode B/C" paths in Enbox.connect().
7
7
  * @module
8
8
  */
9
9
  import type { DwnDataEncodedRecordsWriteMessage, EnboxUserAgent } from '@enbox/agent';
10
- import type { AuthEventEmitter } from '../events.js';
11
- import { AuthSession } from '../identity-session.js';
12
- import type { RegistrationOptions, StorageAdapter, SyncOption, WalletConnectOptions } from '../types.js';
13
- /** @internal */
14
- export interface WalletConnectContext {
15
- userAgent: EnboxUserAgent;
16
- emitter: AuthEventEmitter;
17
- storage: StorageAdapter;
18
- defaultSync?: SyncOption;
19
- defaultDwnEndpoints?: string[];
20
- registration?: RegistrationOptions;
21
- }
10
+ import type { AuthSession } from '../identity-session.js';
11
+ import type { FlowContext } from './lifecycle.js';
12
+ import type { WalletConnectOptions } from '../types.js';
22
13
  /**
23
14
  * Process connected grants by storing them in the local DWN as the owner.
24
15
  *
@@ -40,5 +31,5 @@ export declare function processConnectedGrants(params: {
40
31
  * 2. Imports the delegate DID and processes grants.
41
32
  * 3. Sets up sync and returns an AuthSession.
42
33
  */
43
- export declare function walletConnect(ctx: WalletConnectContext, options: WalletConnectOptions): Promise<AuthSession>;
44
- //# sourceMappingURL=wallet-connect.d.ts.map
34
+ export declare function walletConnect(ctx: FlowContext, options: WalletConnectOptions): Promise<AuthSession>;
35
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/connect/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAyD,cAAc,EAAE,MAAM,cAAc,CAAC;AAE7I,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AASxD;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE;IACnD,KAAK,EAAE,cAAc,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,iCAAiC,EAAE,CAAC;CAC7C,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAmCpB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CA8HtB"}
@@ -7,36 +7,31 @@
7
7
  *
8
8
  * ## Discovery channels (browser, highest to lowest priority)
9
9
  *
10
- * 1. **URL fragment payload** — A `dwn://register` redirect just landed
10
+ * 1. **URL fragment payload** — A `dwn://connect` redirect just landed
11
11
  * on the page with the endpoint in `#`. Highest priority because it's
12
12
  * fresh and explicit.
13
13
  * 2. **Persisted endpoint** (localStorage) — A previously discovered
14
14
  * endpoint restored and re-validated via `GET /info`.
15
- * 3. **Agent-level discovery** (transparent, runs on every `sendRequest`)
16
- * — `~/.enbox/dwn.json` discovery file (Node/Bun only; skipped in
17
- * browsers) and sequential port probing on `127.0.0.1:{3000,55500–55509}`.
18
- * This channel works even if the browser-specific functions here
19
- * return `false`.
20
15
  *
21
16
  * ## Discovery channels (CLI / native, all transparent)
22
17
  *
23
- * In Node/Bun environments, all discovery happens automatically inside
18
+ * In Node/Bun environments, the agent's `LocalDwnDiscovery` reads the
19
+ * `~/.enbox/dwn.json` discovery file automatically inside
24
20
  * `AgentDwnApi.getLocalDwnEndpoint()`. The browser-specific functions
25
21
  * in this module (`checkUrlForDwnDiscoveryPayload`, `requestLocalDwnDiscovery`)
26
- * are not needed the agent reads `~/.enbox/dwn.json` and probes ports
27
- * on its own.
22
+ * are not needed in those environments.
28
23
  *
29
- * @see https://github.com/enboxorg/enbox/issues/589
24
+ * @see https://github.com/enboxorg/enbox/issues/677
30
25
  * @module
31
26
  */
32
27
  import type { EnboxUserAgent } from '@enbox/agent';
33
- import type { AuthEventEmitter } from '../events.js';
34
- import type { StorageAdapter } from '../types.js';
28
+ import type { AuthEventEmitter } from './events.js';
29
+ import type { StorageAdapter } from './types.js';
35
30
  /**
36
31
  * Check the current page URL for a `DwnDiscoveryPayload` in the fragment.
37
32
  *
38
33
  * This is called once at the start of a connection flow to detect whether
39
- * the user was just redirected back from a `dwn://register` handler. If a
34
+ * the user was just redirected back from a `dwn://connect` handler. If a
40
35
  * valid payload is found, the endpoint is persisted and the fragment is
41
36
  * cleared to prevent double-reads.
42
37
  *
@@ -44,6 +39,28 @@ import type { StorageAdapter } from '../types.js';
44
39
  * was found in the URL.
45
40
  */
46
41
  export declare function checkUrlForDwnDiscoveryPayload(): string | undefined;
42
+ /**
43
+ * Run local DWN discovery **before the agent exists**.
44
+ *
45
+ * This is the standalone counterpart of {@link applyLocalDwnDiscovery} and
46
+ * is designed to be called in `AuthManager.create()`, before
47
+ * `EnboxUserAgent.create()`, so the agent creation can decide whether to
48
+ * spin up an in-process DWN or operate in remote mode.
49
+ *
50
+ * Discovery channels (highest → lowest priority):
51
+ * 1. **URL fragment payload** — A `dwn://connect` redirect just landed.
52
+ * 2. **Persisted endpoint** (localStorage) — A previously discovered
53
+ * endpoint, re-validated via `GET /info`.
54
+ *
55
+ * When a valid endpoint is found it is persisted to storage. When a
56
+ * previously-persisted endpoint is stale, it is removed.
57
+ *
58
+ * @param storage - The auth storage adapter (for reading/writing the
59
+ * cached endpoint).
60
+ * @returns The validated endpoint URL, or `undefined` if no local DWN
61
+ * server is available.
62
+ */
63
+ export declare function discoverLocalDwn(storage: StorageAdapter): Promise<string | undefined>;
47
64
  /**
48
65
  * Persist a discovered local DWN endpoint in auth storage.
49
66
  *
@@ -76,25 +93,18 @@ export declare function restoreLocalDwnEndpoint(agent: EnboxUserAgent, storage:
76
93
  * Run the full local DWN discovery sequence for a browser connection flow.
77
94
  *
78
95
  * This function handles the **receiving** side of local DWN discovery in
79
- * the browser. It does NOT trigger the `dwn://register` redirect — use
96
+ * the browser. It does NOT trigger the `dwn://connect` redirect — use
80
97
  * {@link requestLocalDwnDiscovery} for that.
81
98
  *
82
99
  * The discovery channels, from highest to lowest priority:
83
100
  *
84
- * 1. **URL fragment payload** — A `dwn://register` redirect just landed on
101
+ * 1. **URL fragment payload** — A `dwn://connect` redirect just landed on
85
102
  * this page with the DWN endpoint in `#`. This is the highest-priority
86
103
  * signal because it's fresh and explicit.
87
104
  *
88
105
  * 2. **Persisted endpoint** (localStorage) — A previously discovered
89
106
  * endpoint is restored and re-validated via `GET /info`.
90
107
  *
91
- * 3. **Agent-level discovery** (transparent) — Even if this function
92
- * returns `false`, the agent's `LocalDwnDiscovery` will independently
93
- * try the discovery file (`~/.enbox/dwn.json`) and port probing on
94
- * every `sendRequest()` call. Those channels are not available in
95
- * browsers (no filesystem access, CORS may block probes), but they
96
- * work transparently in Node/Bun CLI environments.
97
- *
98
108
  * When an `emitter` is provided, this function emits:
99
109
  * - `'local-dwn-available'` with the endpoint when discovery succeeds.
100
110
  * - `'local-dwn-unavailable'` when no local DWN could be reached.
@@ -106,52 +116,29 @@ export declare function restoreLocalDwnEndpoint(agent: EnboxUserAgent, storage:
106
116
  */
107
117
  export declare function applyLocalDwnDiscovery(agent: EnboxUserAgent, storage: StorageAdapter, emitter?: AuthEventEmitter): Promise<boolean>;
108
118
  /**
109
- * Initiate the `dwn://register` flow by opening the register URL.
119
+ * Initiate the `dwn://connect` flow by opening the connect URL.
110
120
  *
111
- * This asks the operating system to route `dwn://register?callback=<url>`
121
+ * This asks the operating system to route `dwn://connect?callback=<url>`
112
122
  * to the registered handler (electrobun-dwn), which will redirect the
113
123
  * user's browser back to `callbackUrl` with the local DWN endpoint
114
124
  * encoded in the URL fragment.
115
125
  *
116
- * **Important:** There is no reliable cross-browser API to detect whether
117
- * a `dwn://` handler is installed. If no handler is registered, this call
118
- * will silently fail or show an OS-level error dialog. Use
119
- * {@link probeLocalDwn} first to check if a local DWN is already
120
- * reachable via port probing — if it is, you can skip the register flow
121
- * entirely and call {@link applyLocalDwnDiscovery} instead.
126
+ * **Note:** There is no reliable cross-browser API to detect whether a
127
+ * `dwn://` handler is installed. If no handler is registered, this call
128
+ * will silently fail or show an OS-level error dialog.
122
129
  *
123
130
  * @param callbackUrl - The URL to redirect back to. Defaults to the
124
131
  * current page URL (without its fragment) if running in a browser.
125
- * @returns `true` if the register URL was opened, `false` if no
132
+ * @returns `true` if the connect URL was opened, `false` if no
126
133
  * callback URL could be determined (e.g. no `globalThis.location`).
127
134
  *
128
135
  * @example
129
136
  * ```ts
130
- * // Check if local DWN is already available via direct probe.
131
- * const alreadyAvailable = await probeLocalDwn();
132
- * if (!alreadyAvailable) {
133
- * // No local DWN found trigger the dwn://register flow.
134
- * requestLocalDwnDiscovery();
135
- * // The page will reload with the endpoint in the URL fragment.
136
- * }
137
+ * // Trigger the dwn://connect flow to discover a local DWN.
138
+ * requestLocalDwnDiscovery();
139
+ * // The page will reload with the endpoint in the URL fragment.
140
+ * // On the next connect/restore, applyLocalDwnDiscovery() reads it.
137
141
  * ```
138
142
  */
139
143
  export declare function requestLocalDwnDiscovery(callbackUrl?: string): boolean;
140
- /**
141
- * Probe whether a local DWN server is reachable via direct HTTP fetch.
142
- *
143
- * Attempts `GET http://127.0.0.1:{port}/info` on the well-known port
144
- * candidates and returns the endpoint URL of the first server that
145
- * responds with a valid `@enbox/dwn-server` identity.
146
- *
147
- * This is useful in browsers to check if a local DWN is available
148
- * *before* triggering the `dwn://register` redirect flow — if the
149
- * server is already reachable (CORS permitting), the redirect is
150
- * unnecessary.
151
- *
152
- * @returns The local DWN endpoint URL, or `undefined` if no server
153
- * was found. Returns `undefined` (rather than throwing) on CORS
154
- * errors or network failures.
155
- */
156
- export declare function probeLocalDwn(): Promise<string | undefined>;
157
- //# sourceMappingURL=dwn-discovery.d.ts.map
144
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAKnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,IAAI,MAAM,GAAG,SAAS,CAkBnE;AA4BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwB7B;AAID;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,OAAO,CAAC,CAclB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,OAAO,CAAC,CA2BlB;AAID;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAuBtE"}
@@ -35,11 +35,15 @@
35
35
  */
36
36
  export { AuthManager } from './auth-manager.js';
37
37
  export { AuthSession } from './identity-session.js';
38
- export { VaultManager } from './vault/vault-manager.js';
39
38
  export { AuthEventEmitter } from './events.js';
39
+ export { PasswordProvider } from './password-provider.js';
40
+ export type { PasswordContext } from './password-provider.js';
40
41
  export { EnboxUserAgent, HdIdentityVault } from '@enbox/agent';
41
- export { processConnectedGrants } from './flows/wallet-connect.js';
42
- export { applyLocalDwnDiscovery, checkUrlForDwnDiscoveryPayload, clearLocalDwnEndpoint, persistLocalDwnEndpoint, probeLocalDwn, requestLocalDwnDiscovery, restoreLocalDwnEndpoint, } from './flows/dwn-discovery.js';
42
+ export { processConnectedGrants } from './connect/wallet.js';
43
+ export { WalletConnect } from './wallet-connect-client.js';
44
+ export type { Permission, ProtocolPermissionOptions, WalletConnectClientOptions } from './wallet-connect-client.js';
45
+ export { loadTokensFromStorage, saveTokensToStorage } from './registration.js';
46
+ export { applyLocalDwnDiscovery, checkUrlForDwnDiscoveryPayload, clearLocalDwnEndpoint, discoverLocalDwn, persistLocalDwnEndpoint, requestLocalDwnDiscovery, restoreLocalDwnEndpoint, } from './discovery.js';
43
47
  export { BrowserStorage, LevelStorage, MemoryStorage, createDefaultStorage } from './storage/storage.js';
44
- export type { AuthEvent, AuthEventHandler, AuthEventMap, AuthManagerOptions, AuthSessionInfo, AuthState, ConnectPermissionRequest, DisconnectOptions, IdentityInfo, IdentityVaultBackup, ImportFromPhraseOptions, ImportFromPortableOptions, LocalConnectOptions, LocalDwnStrategy, PortableIdentity, ProviderAuthParams, ProviderAuthResult, RegistrationOptions, RegistrationTokenData, RestoreSessionOptions, StorageAdapter, SyncOption, WalletConnectOptions, } from './types.js';
48
+ export type { AuthEvent, AuthEventHandler, AuthEventMap, AuthManagerOptions, AuthSessionInfo, AuthState, ConnectPermissionRequest, DisconnectOptions, HeadlessConnectOptions, IdentityInfo, IdentityVaultBackup, ImportFromPhraseOptions, ImportFromPortableOptions, LocalConnectOptions, LocalDwnStrategy, PortableIdentity, ProviderAuthParams, ProviderAuthResult, RegistrationOptions, RegistrationTokenData, RestoreSessionOptions, ShutdownOptions, StorageAdapter, SyncOption, WalletConnectOptions, } from './types.js';
45
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,OAAO,EACL,sBAAsB,EACtB,8BAA8B,EAC9B,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGzG,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,O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