@enbox/auth 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/auth-manager.js +200 -4
- package/dist/esm/auth-manager.js.map +1 -1
- package/dist/esm/flows/dwn-discovery.js +96 -81
- package/dist/esm/flows/dwn-discovery.js.map +1 -1
- package/dist/esm/flows/dwn-registration.js +49 -3
- package/dist/esm/flows/dwn-registration.js.map +1 -1
- package/dist/esm/flows/import-identity.js +2 -0
- package/dist/esm/flows/import-identity.js.map +1 -1
- package/dist/esm/flows/local-connect.js +25 -8
- package/dist/esm/flows/local-connect.js.map +1 -1
- package/dist/esm/flows/session-restore.js +13 -2
- package/dist/esm/flows/session-restore.js.map +1 -1
- package/dist/esm/flows/wallet-connect.js +5 -4
- package/dist/esm/flows/wallet-connect.js.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/password-provider.js +319 -0
- package/dist/esm/password-provider.js.map +1 -0
- package/dist/esm/types.js +9 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/auth-manager.d.ts +67 -2
- package/dist/types/auth-manager.d.ts.map +1 -1
- package/dist/types/flows/dwn-discovery.d.ts +40 -53
- package/dist/types/flows/dwn-discovery.d.ts.map +1 -1
- package/dist/types/flows/dwn-registration.d.ts +20 -1
- package/dist/types/flows/dwn-registration.d.ts.map +1 -1
- package/dist/types/flows/import-identity.d.ts.map +1 -1
- package/dist/types/flows/local-connect.d.ts +2 -0
- package/dist/types/flows/local-connect.d.ts.map +1 -1
- package/dist/types/flows/session-restore.d.ts +2 -0
- package/dist/types/flows/session-restore.d.ts.map +1 -1
- package/dist/types/flows/wallet-connect.d.ts +2 -2
- package/dist/types/flows/wallet-connect.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/password-provider.d.ts +194 -0
- package/dist/types/password-provider.d.ts.map +1 -0
- package/dist/types/types.d.ts +86 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +8 -9
- package/src/auth-manager.ts +236 -8
- package/src/flows/dwn-discovery.ts +99 -79
- package/src/flows/dwn-registration.ts +60 -5
- package/src/flows/import-identity.ts +2 -0
- package/src/flows/local-connect.ts +24 -3
- package/src/flows/session-restore.ts +15 -2
- package/src/flows/wallet-connect.ts +5 -4
- package/src/index.ts +10 -1
- package/src/password-provider.ts +383 -0
- package/src/types.ts +93 -1
|
@@ -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>;
|
|
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>;
|
|
39
58
|
//# sourceMappingURL=dwn-registration.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAMnD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACf,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;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"}
|
|
@@ -1 +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,
|
|
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,CAwGtB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,WAAW,CAAC,CA8DtB"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { EnboxUserAgent } from '@enbox/agent';
|
|
9
9
|
import type { AuthEventEmitter } from '../events.js';
|
|
10
|
+
import type { PasswordProvider } from '../password-provider.js';
|
|
10
11
|
import type { LocalConnectOptions, RegistrationOptions, StorageAdapter, SyncOption } from '../types.js';
|
|
11
12
|
import { AuthSession } from '../identity-session.js';
|
|
12
13
|
/** @internal */
|
|
@@ -15,6 +16,7 @@ export interface LocalConnectContext {
|
|
|
15
16
|
emitter: AuthEventEmitter;
|
|
16
17
|
storage: StorageAdapter;
|
|
17
18
|
defaultPassword?: string;
|
|
19
|
+
passwordProvider?: PasswordProvider;
|
|
18
20
|
defaultSync?: SyncOption;
|
|
19
21
|
defaultDwnEndpoints?: string[];
|
|
20
22
|
registration?: RegistrationOptions;
|
|
@@ -1 +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,
|
|
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,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,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,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,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,CAuJtB"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { EnboxUserAgent } from '@enbox/agent';
|
|
9
9
|
import type { AuthEventEmitter } from '../events.js';
|
|
10
|
+
import type { PasswordProvider } from '../password-provider.js';
|
|
10
11
|
import type { RestoreSessionOptions, StorageAdapter, SyncOption } from '../types.js';
|
|
11
12
|
import { AuthSession } from '../identity-session.js';
|
|
12
13
|
/** @internal */
|
|
@@ -15,6 +16,7 @@ export interface SessionRestoreContext {
|
|
|
15
16
|
emitter: AuthEventEmitter;
|
|
16
17
|
storage: StorageAdapter;
|
|
17
18
|
defaultPassword?: string;
|
|
19
|
+
passwordProvider?: PasswordProvider;
|
|
18
20
|
defaultSync?: SyncOption;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
@@ -1 +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,
|
|
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,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,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,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,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,CAqHlC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Wallet connect (
|
|
2
|
+
* Wallet connect (Enbox Connect relay) flow.
|
|
3
3
|
*
|
|
4
|
-
* Connects to an external wallet via the
|
|
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
|
|
@@ -1 +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,
|
|
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,CAuItB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -37,9 +37,12 @@ export { AuthManager } from './auth-manager.js';
|
|
|
37
37
|
export { AuthSession } from './identity-session.js';
|
|
38
38
|
export { VaultManager } from './vault/vault-manager.js';
|
|
39
39
|
export { AuthEventEmitter } from './events.js';
|
|
40
|
+
export { PasswordProvider } from './password-provider.js';
|
|
41
|
+
export type { PasswordContext } from './password-provider.js';
|
|
40
42
|
export { EnboxUserAgent, HdIdentityVault } from '@enbox/agent';
|
|
41
43
|
export { processConnectedGrants } from './flows/wallet-connect.js';
|
|
42
|
-
export {
|
|
44
|
+
export { loadTokensFromStorage, saveTokensToStorage } from './flows/dwn-registration.js';
|
|
45
|
+
export { applyLocalDwnDiscovery, checkUrlForDwnDiscoveryPayload, clearLocalDwnEndpoint, discoverLocalDwn, persistLocalDwnEndpoint, requestLocalDwnDiscovery, restoreLocalDwnEndpoint, } from './flows/dwn-discovery.js';
|
|
43
46
|
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';
|
|
47
|
+
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
48
|
//# 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,WA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AAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -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,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,MAA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YG;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"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -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
|
|
@@ -277,6 +333,19 @@ export interface RestoreSessionOptions {
|
|
|
277
333
|
*/
|
|
278
334
|
onPasswordRequired?: () => Promise<string>;
|
|
279
335
|
}
|
|
336
|
+
/** Options for {@link AuthManager.connectHeadless}. */
|
|
337
|
+
export interface HeadlessConnectOptions {
|
|
338
|
+
/** Vault password (overrides manager default). */
|
|
339
|
+
password?: string;
|
|
340
|
+
}
|
|
341
|
+
/** Options for {@link AuthManager.shutdown}. */
|
|
342
|
+
export interface ShutdownOptions {
|
|
343
|
+
/**
|
|
344
|
+
* Milliseconds to wait for pending sync operations before shutting down.
|
|
345
|
+
* Default: `2000`.
|
|
346
|
+
*/
|
|
347
|
+
timeout?: number;
|
|
348
|
+
}
|
|
280
349
|
/** Options for {@link AuthManager.disconnect}. */
|
|
281
350
|
export interface DisconnectOptions {
|
|
282
351
|
/**
|
|
@@ -304,6 +373,14 @@ export interface StorageAdapter {
|
|
|
304
373
|
remove(key: string): Promise<void>;
|
|
305
374
|
/** Clear all stored data. */
|
|
306
375
|
clear(): Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* Close the underlying storage resources (e.g. LevelDB handles).
|
|
378
|
+
*
|
|
379
|
+
* Optional — not all adapters need cleanup. Called by
|
|
380
|
+
* {@link AuthManager.shutdown} to release resources so the process
|
|
381
|
+
* can exit cleanly.
|
|
382
|
+
*/
|
|
383
|
+
close?(): Promise<void>;
|
|
307
384
|
}
|
|
308
385
|
/** The insecure default password used when none is provided. */
|
|
309
386
|
export declare const INSECURE_DEFAULT_PASSWORD = "insecure-static-phrase";
|
|
@@ -321,12 +398,20 @@ export declare const STORAGE_KEYS: {
|
|
|
321
398
|
/** The connected DID (for wallet-connected sessions). */
|
|
322
399
|
readonly CONNECTED_DID: "enbox:auth:connectedDid";
|
|
323
400
|
/**
|
|
324
|
-
* The base URL of the local DWN server discovered via the `dwn://
|
|
401
|
+
* The base URL of the local DWN server discovered via the `dwn://connect`
|
|
325
402
|
* browser redirect flow. Persisted so subsequent page loads can skip the
|
|
326
403
|
* redirect and inject the endpoint directly.
|
|
327
404
|
*
|
|
328
405
|
* @see https://github.com/enboxorg/enbox/issues/589
|
|
329
406
|
*/
|
|
330
407
|
readonly LOCAL_DWN_ENDPOINT: "enbox:auth:localDwnEndpoint";
|
|
408
|
+
/**
|
|
409
|
+
* JSON-serialised `Record<string, RegistrationTokenData>` for DWN endpoint
|
|
410
|
+
* registration tokens. Automatically loaded before registration and saved
|
|
411
|
+
* after new/refreshed tokens are obtained when `persistTokens` is enabled.
|
|
412
|
+
*
|
|
413
|
+
* @see https://github.com/enboxorg/enbox/issues/690
|
|
414
|
+
*/
|
|
415
|
+
readonly REGISTRATION_TOKENS: "enbox:auth:registrationTokens";
|
|
331
416
|
};
|
|
332
417
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","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;GAGG;AACH,eAAO,MAAM,YAAY;IACvB,oDAAoD;;IAGpD,+CAA+C;;IAG/C,4DAA4D;;IAG5D,yDAAyD;;IAGzD;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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": "
|
|
11
|
-
"build:esm": "
|
|
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,15 @@
|
|
|
56
56
|
"bun": ">=1.0.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@enbox/agent": "0.
|
|
59
|
+
"@enbox/agent": "0.4.0",
|
|
60
60
|
"@enbox/common": "0.0.7",
|
|
61
61
|
"@enbox/dids": "0.0.9",
|
|
62
62
|
"@enbox/dwn-clients": "0.1.0",
|
|
63
|
-
"level": "8.0.
|
|
63
|
+
"level": "8.0.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@types/node": "
|
|
67
|
-
"bun-types": "
|
|
68
|
-
"
|
|
69
|
-
"typescript": "5.5.4"
|
|
66
|
+
"@types/node": "22.19.15",
|
|
67
|
+
"bun-types": "1.3.10",
|
|
68
|
+
"typescript": "5.9.3"
|
|
70
69
|
}
|
|
71
70
|
}
|