@enbox/auth 0.3.1

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 (66) hide show
  1. package/dist/esm/auth-manager.js +496 -0
  2. package/dist/esm/auth-manager.js.map +1 -0
  3. package/dist/esm/events.js +65 -0
  4. package/dist/esm/events.js.map +1 -0
  5. package/dist/esm/flows/dwn-discovery.js +281 -0
  6. package/dist/esm/flows/dwn-discovery.js.map +1 -0
  7. package/dist/esm/flows/dwn-registration.js +122 -0
  8. package/dist/esm/flows/dwn-registration.js.map +1 -0
  9. package/dist/esm/flows/import-identity.js +175 -0
  10. package/dist/esm/flows/import-identity.js.map +1 -0
  11. package/dist/esm/flows/local-connect.js +141 -0
  12. package/dist/esm/flows/local-connect.js.map +1 -0
  13. package/dist/esm/flows/session-restore.js +109 -0
  14. package/dist/esm/flows/session-restore.js.map +1 -0
  15. package/dist/esm/flows/wallet-connect.js +199 -0
  16. package/dist/esm/flows/wallet-connect.js.map +1 -0
  17. package/dist/esm/identity-session.js +33 -0
  18. package/dist/esm/identity-session.js.map +1 -0
  19. package/dist/esm/index.js +50 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/storage/storage.js +152 -0
  22. package/dist/esm/storage/storage.js.map +1 -0
  23. package/dist/esm/types.js +30 -0
  24. package/dist/esm/types.js.map +1 -0
  25. package/dist/esm/vault/vault-manager.js +95 -0
  26. package/dist/esm/vault/vault-manager.js.map +1 -0
  27. package/dist/types/auth-manager.d.ts +176 -0
  28. package/dist/types/auth-manager.d.ts.map +1 -0
  29. package/dist/types/events.d.ts +36 -0
  30. package/dist/types/events.d.ts.map +1 -0
  31. package/dist/types/flows/dwn-discovery.d.ts +157 -0
  32. package/dist/types/flows/dwn-discovery.d.ts.map +1 -0
  33. package/dist/types/flows/dwn-registration.d.ts +39 -0
  34. package/dist/types/flows/dwn-registration.d.ts.map +1 -0
  35. package/dist/types/flows/import-identity.d.ts +35 -0
  36. package/dist/types/flows/import-identity.d.ts.map +1 -0
  37. package/dist/types/flows/local-connect.d.ts +29 -0
  38. package/dist/types/flows/local-connect.d.ts.map +1 -0
  39. package/dist/types/flows/session-restore.d.ts +27 -0
  40. package/dist/types/flows/session-restore.d.ts.map +1 -0
  41. package/dist/types/flows/wallet-connect.d.ts +44 -0
  42. package/dist/types/flows/wallet-connect.d.ts.map +1 -0
  43. package/dist/types/identity-session.d.ts +52 -0
  44. package/dist/types/identity-session.d.ts.map +1 -0
  45. package/dist/types/index.d.ts +45 -0
  46. package/dist/types/index.d.ts.map +1 -0
  47. package/dist/types/storage/storage.d.ts +54 -0
  48. package/dist/types/storage/storage.d.ts.map +1 -0
  49. package/dist/types/types.d.ts +312 -0
  50. package/dist/types/types.d.ts.map +1 -0
  51. package/dist/types/vault/vault-manager.d.ts +57 -0
  52. package/dist/types/vault/vault-manager.d.ts.map +1 -0
  53. package/package.json +71 -0
  54. package/src/auth-manager.ts +569 -0
  55. package/src/events.ts +66 -0
  56. package/src/flows/dwn-discovery.ts +300 -0
  57. package/src/flows/dwn-registration.ts +157 -0
  58. package/src/flows/import-identity.ts +217 -0
  59. package/src/flows/local-connect.ts +171 -0
  60. package/src/flows/session-restore.ts +135 -0
  61. package/src/flows/wallet-connect.ts +225 -0
  62. package/src/identity-session.ts +65 -0
  63. package/src/index.ts +89 -0
  64. package/src/storage/storage.ts +136 -0
  65. package/src/types.ts +388 -0
  66. package/src/vault/vault-manager.ts +89 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * DWN registration flow.
3
+ *
4
+ * Registers the agent DID and connected DID with DWN endpoints.
5
+ * Supports two registration paths:
6
+ * 1. Provider auth (`provider-auth-v0`) — OAuth-style with tokens
7
+ * 2. Proof of Work (default) — PoW challenge-response
8
+ *
9
+ * This matches the registration logic from `Enbox.connect()` but as a
10
+ * standalone, reusable function.
11
+ * @module
12
+ */
13
+ import type { EnboxUserAgent } from '@enbox/agent';
14
+ import type { RegistrationOptions } from '../types.js';
15
+ /** @internal */
16
+ export interface RegistrationContext {
17
+ /** The user agent with RPC access for getServerInfo(). */
18
+ userAgent: EnboxUserAgent;
19
+ /** DWN endpoints to register with. */
20
+ dwnEndpoints: string[];
21
+ /** The agent DID URI. */
22
+ agentDid: string;
23
+ /** The connected DID URI (the identity's DID). */
24
+ connectedDid: string;
25
+ }
26
+ /**
27
+ * Register the agent and connected DIDs with the configured DWN endpoints.
28
+ *
29
+ * For each endpoint:
30
+ * 1. Fetches server info to check registration requirements.
31
+ * 2. If the server requires `provider-auth-v0` and the app provides
32
+ * `onProviderAuthRequired`, runs the OAuth flow (with token refresh).
33
+ * 3. Otherwise falls back to PoW registration.
34
+ * 4. Calls `onSuccess` when all endpoints succeed, `onFailure` on error.
35
+ *
36
+ * @internal
37
+ */
38
+ export declare function registerWithDwnEndpoints(ctx: RegistrationContext, registration: RegistrationOptions): Promise<void>;
39
+ //# sourceMappingURL=dwn-registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dwn-registration.d.ts","sourceRoot":"","sources":["../../../src/flows/dwn-registration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAInD,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,aAAa,CAAC;AAErB,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;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,mBAAmB,EACxB,YAAY,EAAE,mBAAmB,GAChC,OAAO,CAAC,IAAI,CAAC,CAwGf"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Identity import flows.
3
+ *
4
+ * - Import from BIP-39 recovery phrase (re-derive vault + identity).
5
+ * - Import from PortableIdentity JSON.
6
+ * @module
7
+ */
8
+ import type { EnboxUserAgent } from '@enbox/agent';
9
+ import type { AuthEventEmitter } from '../events.js';
10
+ import { AuthSession } from '../identity-session.js';
11
+ import type { ImportFromPhraseOptions, ImportFromPortableOptions, RegistrationOptions, StorageAdapter, SyncOption } from '../types.js';
12
+ /** @internal */
13
+ export interface ImportContext {
14
+ userAgent: EnboxUserAgent;
15
+ emitter: AuthEventEmitter;
16
+ storage: StorageAdapter;
17
+ defaultSync?: SyncOption;
18
+ defaultDwnEndpoints?: string[];
19
+ registration?: RegistrationOptions;
20
+ }
21
+ /**
22
+ * Import (or recover) an identity from a BIP-39 recovery phrase.
23
+ *
24
+ * This re-initializes the vault with the given phrase and password,
25
+ * recovering the agent DID and all derived keys.
26
+ */
27
+ export declare function importFromPhrase(ctx: ImportContext, options: ImportFromPhraseOptions): Promise<AuthSession>;
28
+ /**
29
+ * Import an identity from a PortableIdentity JSON object.
30
+ *
31
+ * The portable identity contains the DID's private keys and metadata,
32
+ * allowing it to be used on this device.
33
+ */
34
+ export declare function importFromPortable(ctx: ImportContext, options: ImportFromPortableOptions): Promise<AuthSession>;
35
+ //# sourceMappingURL=import-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-identity.d.ts","sourceRoot":"","sources":["../../../src/flows/import-identity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EACnB,cAAc,EACd,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,gBAAgB;AAChB,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,WAAW,CAAC,CAuGtB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,WAAW,CAAC,CA6DtB"}
@@ -0,0 +1,29 @@
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 { EnboxUserAgent } from '@enbox/agent';
9
+ import type { AuthEventEmitter } from '../events.js';
10
+ import type { LocalConnectOptions, RegistrationOptions, StorageAdapter, SyncOption } from '../types.js';
11
+ import { AuthSession } from '../identity-session.js';
12
+ /** @internal */
13
+ export interface LocalConnectContext {
14
+ userAgent: EnboxUserAgent;
15
+ emitter: AuthEventEmitter;
16
+ storage: StorageAdapter;
17
+ defaultPassword?: string;
18
+ defaultSync?: SyncOption;
19
+ defaultDwnEndpoints?: string[];
20
+ registration?: RegistrationOptions;
21
+ }
22
+ /**
23
+ * Execute the local connect flow.
24
+ *
25
+ * - On first launch: initializes the vault, creates a new DID, returns recovery phrase.
26
+ * - On subsequent launches: unlocks the vault and reconnects to the existing identity.
27
+ */
28
+ export declare function localConnect(ctx: LocalConnectContext, options?: LocalConnectOptions): Promise<AuthSession>;
29
+ //# sourceMappingURL=local-connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-connect.d.ts","sourceRoot":"","sources":["../../../src/flows/local-connect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGxG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIrD,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,mBAAmB,EACxB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC,CAoItB"}
@@ -0,0 +1,27 @@
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 { EnboxUserAgent } from '@enbox/agent';
9
+ import type { AuthEventEmitter } from '../events.js';
10
+ import type { RestoreSessionOptions, StorageAdapter, SyncOption } from '../types.js';
11
+ import { AuthSession } from '../identity-session.js';
12
+ /** @internal */
13
+ export interface SessionRestoreContext {
14
+ userAgent: EnboxUserAgent;
15
+ emitter: AuthEventEmitter;
16
+ storage: StorageAdapter;
17
+ defaultPassword?: string;
18
+ defaultSync?: SyncOption;
19
+ }
20
+ /**
21
+ * Attempt to restore a previous session.
22
+ *
23
+ * Returns `undefined` if no previous session exists.
24
+ * Returns an `AuthSession` if the session was successfully restored.
25
+ */
26
+ export declare function restoreSession(ctx: SessionRestoreContext, options?: RestoreSessionOptions): Promise<AuthSession | undefined>;
27
+ //# sourceMappingURL=session-restore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-restore.d.ts","sourceRoot":"","sources":["../../../src/flows/session-restore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGrF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,qBAAqB,EAC1B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAmGlC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Wallet connect (OIDC/QR) flow.
3
+ *
4
+ * Connects to an external wallet via the WalletConnect relay protocol,
5
+ * importing a delegated DID with permission grants.
6
+ * This replaces the "Mode B/C" paths in Enbox.connect().
7
+ * @module
8
+ */
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
+ }
22
+ /**
23
+ * Process connected grants by storing them in the local DWN as the owner.
24
+ *
25
+ * This is the agent-level equivalent of `Enbox.processConnectedGrants()`.
26
+ * It stores each grant, signed as owner, and returns the deduplicated
27
+ * list of protocol URIs represented by the grants.
28
+ *
29
+ * @internal
30
+ */
31
+ export declare function processConnectedGrants(params: {
32
+ agent: EnboxUserAgent;
33
+ delegateDid: string;
34
+ grants: DwnDataEncodedRecordsWriteMessage[];
35
+ }): Promise<string[]>;
36
+ /**
37
+ * Execute the wallet connect flow.
38
+ *
39
+ * 1. Passes the permission requests directly to `WalletConnect.initClient()`.
40
+ * 2. Imports the delegate DID and processes grants.
41
+ * 3. Sets up sync and returns an AuthSession.
42
+ */
43
+ export declare function walletConnect(ctx: WalletConnectContext, options: WalletConnectOptions): Promise<AuthSession>;
44
+ //# sourceMappingURL=wallet-connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-connect.d.ts","sourceRoot":"","sources":["../../../src/flows/wallet-connect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,iCAAiC,EAAyD,cAAc,EAAE,MAAM,cAAc,CAAC;AAG7I,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEzG,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED;;;;;;;;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,oBAAoB,EACzB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAsItB"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * AuthSession represents an active, authenticated session with a specific identity.
3
+ * @module
4
+ */
5
+ import type { EnboxAgent } from '@enbox/agent';
6
+ import type { IdentityInfo } from './types.js';
7
+ /**
8
+ * An active, authenticated session bound to a specific identity.
9
+ *
10
+ * The session exposes the authenticated **agent**, **did**, and
11
+ * **delegateDid** — the primitives needed to interact with the DWN
12
+ * network. Consumers that use `@enbox/api` can construct an `Enbox`
13
+ * instance from these properties:
14
+ *
15
+ * ```ts
16
+ * import { Enbox } from '@enbox/api';
17
+ *
18
+ * const session = await auth.connect();
19
+ * const enbox = Enbox.connect({
20
+ * agent: session.agent,
21
+ * connectedDid: session.did,
22
+ * delegateDid: session.delegateDid,
23
+ * });
24
+ * ```
25
+ */
26
+ export declare class AuthSession {
27
+ /** The authenticated Enbox agent managing keys, DIDs, and DWN access. */
28
+ readonly agent: EnboxAgent;
29
+ /** The DID URI of the connected identity. */
30
+ readonly did: string;
31
+ /**
32
+ * The delegate DID URI, present when connected via wallet connect.
33
+ * This is the locally-created DID that holds delegated permissions
34
+ * from the wallet's identity.
35
+ */
36
+ readonly delegateDid?: string;
37
+ /**
38
+ * The BIP-39 recovery phrase, present only on first-time local connect.
39
+ * Should be shown to the user for backup and then discarded from memory.
40
+ */
41
+ readonly recoveryPhrase?: string;
42
+ /** Metadata about the connected identity. */
43
+ readonly identity: IdentityInfo;
44
+ constructor(params: {
45
+ agent: EnboxAgent;
46
+ did: string;
47
+ delegateDid?: string;
48
+ recoveryPhrase?: string;
49
+ identity: IdentityInfo;
50
+ });
51
+ }
52
+ //# sourceMappingURL=identity-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-session.d.ts","sourceRoot":"","sources":["../../src/identity-session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAW;IACtB,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAE3B,6CAA6C;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;gBAEpB,MAAM,EAAE;QAClB,KAAK,EAAE,UAAU,CAAC;QAClB,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,YAAY,CAAC;KACxB;CAOF"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @enbox/auth — Headless authentication and identity management SDK.
3
+ *
4
+ * Provides composable, multi-identity-aware authentication that works
5
+ * in both browser and CLI environments. Depends only on `@enbox/agent`
6
+ * and can be used standalone or consumed by `@enbox/api`.
7
+ *
8
+ * @example Standalone auth
9
+ * ```ts
10
+ * import { AuthManager } from '@enbox/auth';
11
+ *
12
+ * const auth = await AuthManager.create({ sync: '15s' });
13
+ * const session = await auth.restoreSession() ?? await auth.connect();
14
+ *
15
+ * // session.agent — the authenticated Enbox agent
16
+ * // session.did — the connected DID URI
17
+ * ```
18
+ *
19
+ * @example With @enbox/api
20
+ * ```ts
21
+ * import { AuthManager } from '@enbox/auth';
22
+ * import { Enbox } from '@enbox/api';
23
+ *
24
+ * const auth = await AuthManager.create({ sync: '15s' });
25
+ * const session = await auth.connect();
26
+ *
27
+ * const enbox = Enbox.connect({
28
+ * agent: session.agent,
29
+ * connectedDid: session.did,
30
+ * delegateDid: session.delegateDid,
31
+ * });
32
+ * ```
33
+ *
34
+ * @packageDocumentation
35
+ */
36
+ export { AuthManager } from './auth-manager.js';
37
+ export { AuthSession } from './identity-session.js';
38
+ export { VaultManager } from './vault/vault-manager.js';
39
+ export { AuthEventEmitter } from './events.js';
40
+ 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';
43
+ 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';
45
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Storage adapter implementations for session persistence.
3
+ * @module
4
+ */
5
+ import type { StorageAdapter } from '../types.js';
6
+ /**
7
+ * Browser storage adapter backed by `localStorage`.
8
+ *
9
+ * All keys are prefixed to avoid collisions with other localStorage users.
10
+ */
11
+ export declare class BrowserStorage implements StorageAdapter {
12
+ private readonly _prefix;
13
+ constructor(prefix?: string);
14
+ get(key: string): Promise<string | null>;
15
+ set(key: string, value: string): Promise<void>;
16
+ remove(key: string): Promise<void>;
17
+ clear(): Promise<void>;
18
+ }
19
+ /**
20
+ * In-memory storage adapter for testing or environments without persistence.
21
+ */
22
+ export declare class MemoryStorage implements StorageAdapter {
23
+ private readonly _store;
24
+ get(key: string): Promise<string | null>;
25
+ set(key: string, value: string): Promise<void>;
26
+ remove(key: string): Promise<void>;
27
+ clear(): Promise<void>;
28
+ }
29
+ /**
30
+ * LevelDB-backed storage adapter for Node / CLI environments.
31
+ *
32
+ * Uses the `level` package (v8), which selects `classic-level` (LevelDB)
33
+ * in Node and `browser-level` (IndexedDB) in browsers. Level auto-opens
34
+ * on construction and queues operations until ready, so no explicit
35
+ * `open()` call is required.
36
+ */
37
+ export declare class LevelStorage implements StorageAdapter {
38
+ private readonly _db;
39
+ constructor(dataPath?: string);
40
+ get(key: string): Promise<string | null>;
41
+ set(key: string, value: string): Promise<void>;
42
+ remove(key: string): Promise<void>;
43
+ clear(): Promise<void>;
44
+ /** Close the underlying LevelDB database. */
45
+ close(): Promise<void>;
46
+ }
47
+ /**
48
+ * Detect the runtime environment and return an appropriate default storage adapter.
49
+ *
50
+ * - If `localStorage` is available → `BrowserStorage`
51
+ * - Otherwise → `LevelStorage` (persistent on disk via LevelDB)
52
+ */
53
+ export declare function createDefaultStorage(): StorageAdapter;
54
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage/storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;GAIG;AACH,qBAAa,cAAe,YAAW,cAAc;IACnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,SAAW;IAIvB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAY7B;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IAE9C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAa,YAAW,cAAc;IACjD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;gBAEhC,QAAQ,SAA0B;IAIxC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,6CAA6C;IACvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAMrD"}