@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
@@ -0,0 +1,194 @@
1
+ /**
2
+ * PasswordProvider — composable password acquisition strategies.
3
+ *
4
+ * Replaces ad-hoc password prompting scattered across CLI consumers
5
+ * (env vars, raw-mode TTY, `/dev/tty` + `stty`, `@clack/prompts`, etc.)
6
+ * with a single, composable abstraction.
7
+ *
8
+ * @example Chained provider (env first, fall back to TTY)
9
+ * ```ts
10
+ * import { PasswordProvider } from '@enbox/auth';
11
+ *
12
+ * const provider = PasswordProvider.chain([
13
+ * PasswordProvider.fromEnv('ENBOX_PASSWORD'),
14
+ * PasswordProvider.fromTty({ prompt: 'Vault password: ' }),
15
+ * ]);
16
+ *
17
+ * const auth = await AuthManager.create({ passwordProvider: provider });
18
+ * ```
19
+ *
20
+ * @module
21
+ */
22
+ /** Context passed to a password provider explaining why a password is needed. */
23
+ export interface PasswordContext {
24
+ /**
25
+ * Why the password is being requested.
26
+ *
27
+ * - `'create'` — first launch, creating a new vault (prompt may ask
28
+ * for confirmation).
29
+ * - `'unlock'` — unlocking an existing vault.
30
+ */
31
+ reason: 'create' | 'unlock';
32
+ }
33
+ /**
34
+ * A strategy for obtaining a vault password.
35
+ *
36
+ * Implementations may be interactive (TTY prompts) or non-interactive
37
+ * (environment variables, cached values). Use {@link PasswordProvider.chain}
38
+ * to compose multiple strategies with automatic fallback.
39
+ */
40
+ export interface PasswordProvider {
41
+ /**
42
+ * Obtain a password.
43
+ *
44
+ * @param context - Why the password is needed.
45
+ * @returns The password string.
46
+ * @throws If the provider cannot obtain a password (e.g. env var
47
+ * not set, no TTY available). The error is caught by `chain()`
48
+ * which falls through to the next provider.
49
+ */
50
+ getPassword(context: PasswordContext): Promise<string>;
51
+ }
52
+ /** @internal Minimal interface for an stdin-like readable stream. */
53
+ export interface TtyReadable {
54
+ isTTY?: boolean;
55
+ setRawMode(mode: boolean): void;
56
+ setEncoding(encoding: string): void;
57
+ resume(): void;
58
+ pause(): void;
59
+ on(event: 'data', listener: (chunk: string) => void): void;
60
+ removeListener(event: 'data', listener: (chunk: string) => void): void;
61
+ }
62
+ /** @internal Minimal interface for an stdout-like writable stream. */
63
+ export interface TtyWritable {
64
+ write(data: string): boolean;
65
+ }
66
+ /**
67
+ * Read a password from a raw-mode TTY stream.
68
+ *
69
+ * Reads character-by-character with no echo. Handles Enter (resolve),
70
+ * Ctrl-C (reject), backspace, and printable characters.
71
+ *
72
+ * @internal Exported for testing only.
73
+ */
74
+ export declare function readPasswordRawMode(stdin: TtyReadable, stdout: TtyWritable, prompt: string): Promise<string>;
75
+ /** @internal Injectable I/O for testing `readPasswordDevTty`. */
76
+ export interface DevTtyIo {
77
+ openSync(path: string, flags: string): number;
78
+ readSync(fd: number, buf: Uint8Array, offset: number, length: number, position: null): number;
79
+ writeSync(fd: number, data: string): number;
80
+ closeSync(fd: number): void;
81
+ execSync(cmd: string, opts: {
82
+ stdio: string;
83
+ }): void;
84
+ }
85
+ /**
86
+ * Read a password from `/dev/tty` using synchronous I/O.
87
+ *
88
+ * Opens `/dev/tty` directly, uses `stty -echo` to suppress input,
89
+ * reads until newline, then restores echo and closes file descriptors.
90
+ *
91
+ * @param prompt - The prompt string to display.
92
+ * @param io - Injectable I/O functions (defaults to `node:fs` + `node:child_process`).
93
+ * @internal Exported for testing only.
94
+ */
95
+ export declare function readPasswordDevTty(prompt: string, io?: DevTtyIo): Promise<string>;
96
+ export declare namespace PasswordProvider {
97
+ /**
98
+ * Read the password from an environment variable.
99
+ *
100
+ * Throws if the variable is not set or is empty, allowing `chain()`
101
+ * to fall through to the next provider.
102
+ *
103
+ * @param envVar - Name of the environment variable. Default: `'ENBOX_PASSWORD'`.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const provider = PasswordProvider.fromEnv('MY_APP_PASSWORD');
108
+ * ```
109
+ */
110
+ function fromEnv(envVar?: string): PasswordProvider;
111
+ /**
112
+ * Wrap an async callback as a password provider.
113
+ *
114
+ * This is the escape hatch for custom UI (e.g. `@clack/prompts`,
115
+ * Electron dialog, browser modal).
116
+ *
117
+ * @param callback - Called with the password context; must return a password string.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const provider = PasswordProvider.fromCallback(async ({ reason }) => {
122
+ * if (reason === 'create') {
123
+ * return await showCreatePasswordDialog();
124
+ * }
125
+ * return await showUnlockDialog();
126
+ * });
127
+ * ```
128
+ */
129
+ function fromCallback(callback: (context: PasswordContext) => Promise<string>): PasswordProvider;
130
+ /**
131
+ * Prompt for a password via `process.stdin` in raw mode.
132
+ *
133
+ * Input is read character-by-character with no echo. Handles
134
+ * backspace and Ctrl-C (rejects with an error). Only works when
135
+ * `process.stdin.isTTY` is `true`; throws otherwise so `chain()`
136
+ * can fall through to the next provider.
137
+ *
138
+ * Suitable for main CLI processes that own stdin/stdout.
139
+ *
140
+ * @param options - Optional configuration.
141
+ * @param options.prompt - Text to display before reading. Default: `'Vault password: '`.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const provider = PasswordProvider.fromTty({ prompt: 'Password: ' });
146
+ * ```
147
+ */
148
+ function fromTty(options?: {
149
+ prompt?: string;
150
+ }): PasswordProvider;
151
+ /**
152
+ * Prompt for a password via `/dev/tty` (Unix only).
153
+ *
154
+ * Opens `/dev/tty` directly, bypassing `process.stdin`. This is
155
+ * essential for subprocesses where stdin is owned by the parent
156
+ * (e.g. Git credential helpers, SSH, GPG). Uses `stty -echo` to
157
+ * suppress input echo.
158
+ *
159
+ * Throws if `/dev/tty` cannot be opened (e.g. non-Unix platform,
160
+ * no controlling terminal), allowing `chain()` to fall through.
161
+ *
162
+ * @param options - Optional configuration.
163
+ * @param options.prompt - Text to display before reading. Default: `'Vault password: '`.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * // For git credential helpers:
168
+ * const provider = PasswordProvider.fromDevTty();
169
+ * ```
170
+ */
171
+ function fromDevTty(options?: {
172
+ prompt?: string;
173
+ }): PasswordProvider;
174
+ /**
175
+ * Compose multiple providers with automatic fallback.
176
+ *
177
+ * Tries each provider in order. If a provider throws, the next one
178
+ * is tried. If all providers fail, the last error is rethrown.
179
+ *
180
+ * @param providers - Ordered list of providers to try.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * // Try env var first, then interactive TTY, then /dev/tty for subprocesses.
185
+ * const provider = PasswordProvider.chain([
186
+ * PasswordProvider.fromEnv('ENBOX_PASSWORD'),
187
+ * PasswordProvider.fromTty(),
188
+ * PasswordProvider.fromDevTty(),
189
+ * ]);
190
+ * ```
191
+ */
192
+ function chain(providers: PasswordProvider[]): PasswordProvider;
193
+ }
194
+ //# sourceMappingURL=password-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-provider.d.ts","sourceRoot":"","sources":["../../src/password-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,iFAAiF;AACjF,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;OAQG;IACH,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD;AAID,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EA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M,EAAE,MAAM,EACd,EAAE,CAAC,EAAE,QAAQ,GACZ,OAAO,CAAC,MAAM,CAAC,CAkEjB;AAKD,yBAAiB,gBAAgB,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,SAAgB,OAAO,CAAC,MAAM,SAAmB,GAAG,gBAAgB,CAYnE;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAgB,YAAY,CAC1B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,GACtD,gBAAgB,CAElB;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAgB,OAAO,CAAC,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,gBAAgB,CAkB3E;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAgB,UAAU,CAAC,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,gBAAgB,CAQ9E;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAgB,KAAK,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAoBrE;CACF"}
@@ -11,7 +11,7 @@
11
11
  * @module
12
12
  */
13
13
  import type { EnboxUserAgent } from '@enbox/agent';
14
- import type { RegistrationOptions } from '../types.js';
14
+ import type { RegistrationOptions, RegistrationTokenData, StorageAdapter } from './types.js';
15
15
  /** @internal */
16
16
  export interface RegistrationContext {
17
17
  /** The user agent with RPC access for getServerInfo(). */
@@ -22,6 +22,11 @@ export interface RegistrationContext {
22
22
  agentDid: string;
23
23
  /** The connected DID URI (the identity's DID). */
24
24
  connectedDid: string;
25
+ /**
26
+ * Storage adapter for automatic token persistence.
27
+ * Only used when `registration.persistTokens` is `true`.
28
+ */
29
+ storage?: StorageAdapter;
25
30
  }
26
31
  /**
27
32
  * Register the agent and connected DIDs with the configured DWN endpoints.
@@ -36,4 +41,18 @@ export interface RegistrationContext {
36
41
  * @internal
37
42
  */
38
43
  export declare function registerWithDwnEndpoints(ctx: RegistrationContext, registration: RegistrationOptions): Promise<void>;
39
- //# sourceMappingURL=dwn-registration.d.ts.map
44
+ /**
45
+ * Load registration tokens from a `StorageAdapter`.
46
+ *
47
+ * Returns an empty record if no tokens are stored or the stored value
48
+ * is corrupt (best-effort — never throws).
49
+ *
50
+ * @internal
51
+ */
52
+ export declare function loadTokensFromStorage(storage: StorageAdapter): Promise<Record<string, RegistrationTokenData>>;
53
+ /**
54
+ * Save registration tokens to a `StorageAdapter`.
55
+ * @internal
56
+ */
57
+ export declare function saveTokensToStorage(storage: StorageAdapter, tokens: Record<string, RegistrationTokenData>): Promise<void>;
58
+ //# sourceMappingURL=registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/registration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAMnD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,SAAS,EAAE,cAAc,CAAC;IAE1B,sCAAsC;IACtC,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IAEjB,kDAAkD;IAClD,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,mBAAmB,EACxB,YAAY,EAAE,mBAAmB,GAChC,OAAO,CAAC,IAAI,CAAC,CAqHf;AAID;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAQhD;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -3,6 +3,7 @@
3
3
  * Public types for the authentication and identity management SDK.
4
4
  */
5
5
  import type { ConnectPermissionRequest, EnboxUserAgent, HdIdentityVault, LocalDwnStrategy, PortableIdentity } from '@enbox/agent';
6
+ import type { PasswordProvider } from './password-provider.js';
6
7
  export type { ConnectPermissionRequest, HdIdentityVault, IdentityVaultBackup, LocalDwnStrategy, PortableIdentity } from '@enbox/agent';
7
8
  export type { EnboxUserAgent } from '@enbox/agent';
8
9
  /**
@@ -132,13 +133,44 @@ export interface RegistrationOptions {
132
133
  * Pre-existing registration tokens from a previous session, keyed by
133
134
  * DWN endpoint URL. If a valid (non-expired) token exists for an
134
135
  * endpoint, it is used directly without re-running the auth flow.
136
+ *
137
+ * When {@link persistTokens} is `true`, this field is ignored —
138
+ * tokens are loaded automatically from the `StorageAdapter`.
135
139
  */
136
140
  registrationTokens?: Record<string, RegistrationTokenData>;
137
141
  /**
138
142
  * Called when new or refreshed registration tokens are obtained.
139
143
  * The app should persist these for future sessions.
144
+ *
145
+ * When {@link persistTokens} is `true`, tokens are saved automatically
146
+ * to the `StorageAdapter`. This callback is still invoked (if provided)
147
+ * **after** the automatic save, so consumers can observe token changes
148
+ * without handling persistence themselves.
140
149
  */
141
150
  onRegistrationTokens?: (tokens: Record<string, RegistrationTokenData>) => void;
151
+ /**
152
+ * Automatically persist and restore registration tokens using the
153
+ * auth manager's `StorageAdapter`.
154
+ *
155
+ * When `true`, tokens are loaded from storage before registration and
156
+ * saved back after new or refreshed tokens are obtained. This removes
157
+ * the need for consumers to implement their own token I/O via
158
+ * {@link registrationTokens} and {@link onRegistrationTokens}.
159
+ *
160
+ * Defaults to `false` for backward compatibility.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const auth = await AuthManager.create({
165
+ * registration: {
166
+ * onSuccess: () => {},
167
+ * onFailure: (err) => console.error(err),
168
+ * persistTokens: true,
169
+ * },
170
+ * });
171
+ * ```
172
+ */
173
+ persistTokens?: boolean;
142
174
  }
143
175
  /** Options for {@link AuthManager.create}. */
144
176
  export interface AuthManagerOptions {
@@ -182,8 +214,32 @@ export interface AuthManagerOptions {
182
214
  /**
183
215
  * Default password for vault operations.
184
216
  * If not provided, an insecure default is used (with a console warning).
217
+ *
218
+ * For more flexible password acquisition (env vars, TTY prompts,
219
+ * chained fallbacks), use {@link passwordProvider} instead.
185
220
  */
186
221
  password?: string;
222
+ /**
223
+ * A composable password provider for obtaining the vault password.
224
+ *
225
+ * When set, this provider is consulted by `connect()`,
226
+ * `restoreSession()`, and `connectHeadless()` whenever a password
227
+ * is needed and none was given explicitly. It takes precedence over
228
+ * the static {@link password} option.
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * import { AuthManager, PasswordProvider } from '@enbox/auth';
233
+ *
234
+ * const auth = await AuthManager.create({
235
+ * passwordProvider: PasswordProvider.chain([
236
+ * PasswordProvider.fromEnv('ENBOX_PASSWORD'),
237
+ * PasswordProvider.fromTty(),
238
+ * ]),
239
+ * });
240
+ * ```
241
+ */
242
+ passwordProvider?: PasswordProvider;
187
243
  /**
188
244
  * Sync interval for DWN synchronization.
189
245
  * - `'off'` — disable sync
@@ -222,9 +278,10 @@ export interface WalletConnectOptions {
222
278
  /**
223
279
  * Protocol permission requests for the wallet connect flow.
224
280
  *
225
- * Each entry is a `ConnectPermissionRequest` from `@enbox/agent` containing
226
- * a `protocolDefinition` and `permissionScopes`. Use
227
- * `WalletConnect.createPermissionRequestForProtocol()` to build these.
281
+ * Each entry is a `ConnectPermissionRequest` containing a
282
+ * `protocolDefinition` and `permissionScopes`. Use
283
+ * `WalletConnect.createPermissionRequestForProtocol()` from `@enbox/auth`
284
+ * to build these.
228
285
  */
229
286
  permissionRequests: ConnectPermissionRequest[];
230
287
  /** Called when the wallet URI is ready (render as QR code). */
@@ -277,6 +334,19 @@ export interface RestoreSessionOptions {
277
334
  */
278
335
  onPasswordRequired?: () => Promise<string>;
279
336
  }
337
+ /** Options for {@link AuthManager.connectHeadless}. */
338
+ export interface HeadlessConnectOptions {
339
+ /** Vault password (overrides manager default). */
340
+ password?: string;
341
+ }
342
+ /** Options for {@link AuthManager.shutdown}. */
343
+ export interface ShutdownOptions {
344
+ /**
345
+ * Milliseconds to wait for pending sync operations before shutting down.
346
+ * Default: `2000`.
347
+ */
348
+ timeout?: number;
349
+ }
280
350
  /** Options for {@link AuthManager.disconnect}. */
281
351
  export interface DisconnectOptions {
282
352
  /**
@@ -304,9 +374,19 @@ export interface StorageAdapter {
304
374
  remove(key: string): Promise<void>;
305
375
  /** Clear all stored data. */
306
376
  clear(): Promise<void>;
377
+ /**
378
+ * Close the underlying storage resources (e.g. LevelDB handles).
379
+ *
380
+ * Optional — not all adapters need cleanup. Called by
381
+ * {@link AuthManager.shutdown} to release resources so the process
382
+ * can exit cleanly.
383
+ */
384
+ close?(): Promise<void>;
307
385
  }
308
386
  /** The insecure default password used when none is provided. */
309
387
  export declare const INSECURE_DEFAULT_PASSWORD = "insecure-static-phrase";
388
+ /** Default DWN endpoints for new identities when none are configured. */
389
+ export declare const DEFAULT_DWN_ENDPOINTS: string[];
310
390
  /**
311
391
  * Storage keys used by the auth manager for session persistence.
312
392
  * @internal
@@ -321,12 +401,20 @@ export declare const STORAGE_KEYS: {
321
401
  /** The connected DID (for wallet-connected sessions). */
322
402
  readonly CONNECTED_DID: "enbox:auth:connectedDid";
323
403
  /**
324
- * The base URL of the local DWN server discovered via the `dwn://register`
404
+ * The base URL of the local DWN server discovered via the `dwn://connect`
325
405
  * browser redirect flow. Persisted so subsequent page loads can skip the
326
406
  * redirect and inject the endpoint directly.
327
407
  *
328
408
  * @see https://github.com/enboxorg/enbox/issues/589
329
409
  */
330
410
  readonly LOCAL_DWN_ENDPOINT: "enbox:auth:localDwnEndpoint";
411
+ /**
412
+ * JSON-serialised `Record<string, RegistrationTokenData>` for DWN endpoint
413
+ * registration tokens. Automatically loaded before registration and saved
414
+ * after new/refreshed tokens are obtained when `persistTokens` is enabled.
415
+ *
416
+ * @see https://github.com/enboxorg/enbox/issues/690
417
+ */
418
+ readonly REGISTRATION_TOKENS: "enbox:auth:registrationTokens";
331
419
  };
332
420
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGlI,YAAY,EAAE,wBAAwB,EAAE,eAAe,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGvI,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAInD;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,GAAG,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AAI/D;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GACjB,eAAe,GACf,QAAQ,GACR,UAAU,GACV,WAAW,CAAC;AAIhB,mDAAmD;AACnD,MAAM,MAAM,SAAS,GACjB,cAAc,GACd,eAAe,GACf,aAAa,GACb,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,gBAAgB,GAChB,qBAAqB,GACrB,uBAAuB,CAAC;AAE5B,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE;QAAE,QAAQ,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,SAAS,CAAA;KAAE,CAAC;IAC5D,eAAe,EAAE;QAAE,OAAO,EAAE,eAAe,CAAA;KAAE,CAAC;IAC9C,aAAa,EAAE;QAAE,GAAG,EAA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kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,kDAAkD;AAClD,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEzC,4BAA4B;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C,oBAAoB;IACpB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC,6BAA6B;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAID,gEAAgE;AAChE,eAAO,MAAM,yBAAyB,2BAA2B,CAAC;AAElE,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,UAAgC,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,YAAY;IACvB,oDAAoD;;IAGpD,+CAA+C;;IAG/C,4DAA4D;;IAG5D,yDAAyD;;IAGzD;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * WalletConnect client — initiates the relay-mediated connect flow.
3
+ *
4
+ * Moved from `@enbox/agent/src/connect.ts` because `initClient` has zero
5
+ * coupling to agent internals (no vault, no key store, no DWN processing,
6
+ * no sync). Its only consumer is `auth/src/connect/wallet.ts`.
7
+ *
8
+ * The server-side counterpart (`EnboxConnectProtocol`) correctly stays in
9
+ * `@enbox/agent` because it uses `agent.processDwnRequest()`,
10
+ * `agent.sendDwnRequest()`, and `AgentPermissionsApi`.
11
+ *
12
+ * @module
13
+ */
14
+ import type { ConnectPermissionRequest, DwnProtocolDefinition } from '@enbox/agent';
15
+ import type { EnboxConnectResponse } from '@enbox/agent';
16
+ /**
17
+ * Options for initiating a wallet connect flow (remote, relay-mediated).
18
+ *
19
+ * This is the agent-level options type used by `initClient()`. The auth-level
20
+ * `WalletConnectOptions` (in `types.ts`) wraps this with additional fields
21
+ * like `sync`.
22
+ */
23
+ export type WalletConnectClientOptions = {
24
+ /** The user-friendly name of the app, displayed in the wallet consent UI. */
25
+ displayName: string;
26
+ /** The URL of the connect server which relays messages between the app and wallet. */
27
+ connectServerUrl: string;
28
+ /**
29
+ * The URI of the wallet app. Query params (`request_uri`, `encryption_key`)
30
+ * are appended and passed to `onWalletUriReady`.
31
+ * @example `enbox://connect` or `http://localhost:3000/`
32
+ */
33
+ walletUri: string;
34
+ /**
35
+ * The protocols of permissions requested, along with the definition and
36
+ * permission scopes for each protocol. The key is the protocol URL and
37
+ * the value is an object with the protocol definition and the permission scopes.
38
+ */
39
+ permissionRequests: ConnectPermissionRequest[];
40
+ /**
41
+ * Called with the wallet URI including query params (`request_uri`, `encryption_key`).
42
+ * The app should render this as a QR code or use it as a deep link.
43
+ *
44
+ * @param uri - The wallet URI with connect payload.
45
+ */
46
+ onWalletUriReady: (uri: string) => void;
47
+ /**
48
+ * Called to collect the PIN from the user. The PIN is used as AAD
49
+ * when decrypting the connect response from the relay.
50
+ *
51
+ * @returns A promise that resolves to the PIN as a string.
52
+ */
53
+ validatePin: () => Promise<string>;
54
+ };
55
+ /**
56
+ * Shorthand for the types of permissions that can be requested.
57
+ */
58
+ export type Permission = 'write' | 'read' | 'delete' | 'query' | 'subscribe' | 'configure';
59
+ /**
60
+ * The options for creating a permission request for a given protocol.
61
+ */
62
+ export type ProtocolPermissionOptions = {
63
+ /** The protocol definition for the protocol being requested */
64
+ definition: DwnProtocolDefinition;
65
+ /** The permissions being requested for the protocol */
66
+ permissions: Permission[];
67
+ };
68
+ /**
69
+ * Initiates the wallet connect process. Used when a client wants to obtain
70
+ * a did from a provider.
71
+ */
72
+ declare function initClient({ displayName, connectServerUrl, walletUri, permissionRequests, onWalletUriReady, validatePin, }: WalletConnectClientOptions): Promise<{
73
+ delegateGrants: EnboxConnectResponse['delegateGrants'];
74
+ delegatePortableDid: EnboxConnectResponse['delegatePortableDid'];
75
+ connectedDid: string;
76
+ } | undefined>;
77
+ /**
78
+ * Creates a set of Dwn Permission Scopes to request for a given protocol.
79
+ *
80
+ * If no permissions are provided, the default is to request all relevant record permissions (write, read, delete, query, subscribe).
81
+ * 'configure' is not included by default, as this gives the application a lot of control over the protocol.
82
+ */
83
+ declare function createPermissionRequestForProtocol({ definition, permissions }: ProtocolPermissionOptions): ConnectPermissionRequest;
84
+ export declare const WalletConnect: {
85
+ initClient: typeof initClient;
86
+ createPermissionRequestForProtocol: typeof createPermissionRequestForProtocol;
87
+ };
88
+ export {};
89
+ //# sourceMappingURL=wallet-connect-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-connect-client.d.ts","sourceRoot":"","sources":["../../src/wallet-connect-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAsB,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxG,OAAO,KAAK,EAAyB,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAQhF;;;;;;GAMG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAC;IAEpB,sFAAsF;IACtF,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;IAE/C;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC;;;;;OAKG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3F;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,+DAA+D;IAC/D,UAAU,EAAE,qBAAqB,CAAC;IAElC,uDAAuD;IACvD,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,iBAAe,UAAU,CAAC,EACxB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,GACZ,EAAE,0BAA0B,GAAG,OAAO,CAAC;IACtC,cAAc,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IACvD,mBAAmB,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;IACjE,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC,CAkGb;AAED;;;;;GAKG;AACH,iBAAS,kCAAkC,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,yBAAyB,GAAG,wBAAwB,CAsE5H;AAED,eAAO,MAAM,aAAa;;;CAAqD,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@enbox/auth",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Headless authentication and identity management SDK for Enbox",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/index.js",
7
7
  "module": "./dist/esm/index.js",
8
8
  "types": "./dist/types/index.d.ts",
9
9
  "scripts": {
10
- "clean": "rimraf dist",
11
- "build:esm": "rimraf dist/esm dist/types && bun tsc -p tsconfig.json",
10
+ "clean": "rm -rf dist",
11
+ "build:esm": "rm -rf dist/esm dist/types && bun tsc -p tsconfig.json",
12
12
  "build": "bun run clean && bun run build:esm",
13
13
  "lint": "eslint . --max-warnings 0",
14
14
  "lint:fix": "eslint . --fix",
@@ -56,16 +56,19 @@
56
56
  "bun": ">=1.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@enbox/agent": "0.3.1",
60
- "@enbox/common": "0.0.7",
61
- "@enbox/dids": "0.0.9",
62
- "@enbox/dwn-clients": "0.1.0",
63
- "level": "8.0.0"
59
+ "@enbox/agent": "0.5.0",
60
+ "@enbox/common": "0.1.0",
61
+ "@enbox/crypto": "0.1.0",
62
+ "@enbox/dids": "0.1.0",
63
+ "@enbox/dwn-clients": "0.2.0",
64
+ "@enbox/dwn-sdk-js": "0.2.0",
65
+ "level": "8.0.1"
64
66
  },
65
67
  "devDependencies": {
66
- "@types/node": "20.14.8",
67
- "bun-types": "latest",
68
- "rimraf": "4.4.0",
69
- "typescript": "5.5.4"
68
+ "@types/node": "22.19.15",
69
+ "@types/sinon": "17.0.3",
70
+ "bun-types": "1.3.10",
71
+ "sinon": "18.0.0",
72
+ "typescript": "5.9.3"
70
73
  }
71
74
  }