@interop/was-react 0.8.2 → 0.9.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/README.md +55 -44
- package/dist/auth/chapi.d.ts.map +1 -1
- package/dist/auth/chapi.js +16 -5
- package/dist/auth/chapi.js.map +1 -1
- package/dist/auth/loginFlow.d.ts.map +1 -1
- package/dist/auth/loginFlow.js +55 -49
- package/dist/auth/loginFlow.js.map +1 -1
- package/dist/auth/verifyResponse.d.ts.map +1 -1
- package/dist/auth/verifyResponse.js +27 -10
- package/dist/auth/verifyResponse.js.map +1 -1
- package/dist/auth/walletRequestTypes.d.ts +9 -90
- package/dist/auth/walletRequestTypes.d.ts.map +1 -1
- package/dist/config.d.ts +9 -9
- package/dist/config.js +0 -0
- package/dist/dev/provisionDevGrants.d.ts.map +1 -1
- package/dist/dev/provisionDevGrants.js +18 -19
- package/dist/dev/provisionDevGrants.js.map +1 -1
- package/dist/grants.d.ts +19 -9
- package/dist/grants.d.ts.map +1 -1
- package/dist/grants.js +17 -2
- package/dist/grants.js.map +1 -1
- package/dist/identity/agents.d.ts +1 -1
- package/dist/identity/agents.d.ts.map +1 -1
- package/dist/identity/agents.js +10 -25
- package/dist/identity/agents.js.map +1 -1
- package/dist/identity/appSession.d.ts +27 -0
- package/dist/identity/appSession.d.ts.map +1 -1
- package/dist/identity/appSession.js +51 -13
- package/dist/identity/appSession.js.map +1 -1
- package/dist/identity/seedCredential.d.ts +7 -0
- package/dist/identity/seedCredential.d.ts.map +1 -1
- package/dist/identity/seedCredential.js +11 -14
- package/dist/identity/seedCredential.js.map +1 -1
- package/dist/identity/seedStore.d.ts +19 -0
- package/dist/identity/seedStore.d.ts.map +1 -1
- package/dist/identity/seedStore.js +40 -13
- package/dist/identity/seedStore.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/jsonLd.d.ts +19 -0
- package/dist/jsonLd.d.ts.map +1 -0
- package/dist/jsonLd.js +24 -0
- package/dist/jsonLd.js.map +1 -0
- package/dist/mui/AdoptDialog.d.ts.map +1 -1
- package/dist/mui/AdoptDialog.js +7 -3
- package/dist/mui/AdoptDialog.js.map +1 -1
- package/dist/mui/ClearDataDialog.d.ts.map +1 -1
- package/dist/mui/ClearDataDialog.js +12 -11
- package/dist/mui/ClearDataDialog.js.map +1 -1
- package/dist/mui/ConfirmDialog.d.ts +35 -0
- package/dist/mui/ConfirmDialog.d.ts.map +1 -0
- package/dist/mui/ConfirmDialog.js +18 -0
- package/dist/mui/ConfirmDialog.js.map +1 -0
- package/dist/mui/LogoutDialog.d.ts.map +1 -1
- package/dist/mui/LogoutDialog.js +7 -3
- package/dist/mui/LogoutDialog.js.map +1 -1
- package/dist/react/documentApp.d.ts +29 -0
- package/dist/react/documentApp.d.ts.map +1 -1
- package/dist/react/documentApp.js +9 -38
- package/dist/react/documentApp.js.map +1 -1
- package/dist/react/hooks.d.ts +13 -7
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/hooks.js +17 -11
- package/dist/react/hooks.js.map +1 -1
- package/dist/session/authStore.d.ts +9 -9
- package/dist/session/authStore.d.ts.map +1 -1
- package/dist/session/authStore.js +203 -112
- package/dist/session/authStore.js.map +1 -1
- package/dist/storage/adopt.d.ts +5 -1
- package/dist/storage/adopt.d.ts.map +1 -1
- package/dist/storage/adopt.js +8 -24
- package/dist/storage/adopt.js.map +1 -1
- package/dist/storage/entityStore.d.ts.map +1 -1
- package/dist/storage/entityStore.js +27 -20
- package/dist/storage/entityStore.js.map +1 -1
- package/dist/storage/localStore.d.ts +12 -6
- package/dist/storage/localStore.d.ts.map +1 -1
- package/dist/storage/localStore.js +146 -77
- package/dist/storage/localStore.js.map +1 -1
- package/dist/storage/rehydrate.d.ts.map +1 -1
- package/dist/storage/rehydrate.js +20 -4
- package/dist/storage/rehydrate.js.map +1 -1
- package/dist/storage/sharedCollectionReader.d.ts +1 -1
- package/dist/storage/sharedCollectionReader.d.ts.map +1 -1
- package/dist/storage/sharedCollectionReader.js +79 -64
- package/dist/storage/sharedCollectionReader.js.map +1 -1
- package/dist/storage/storageManager.d.ts +3 -1
- package/dist/storage/storageManager.d.ts.map +1 -1
- package/dist/storage/storageManager.js +20 -6
- package/dist/storage/storageManager.js.map +1 -1
- package/dist/storage/syncController.d.ts +1 -16
- package/dist/storage/syncController.d.ts.map +1 -1
- package/dist/storage/syncController.js +48 -37
- package/dist/storage/syncController.js.map +1 -1
- package/dist/storage/syncStatusStore.d.ts +8 -6
- package/dist/storage/syncStatusStore.d.ts.map +1 -1
- package/dist/storage/syncStatusStore.js +6 -6
- package/dist/storage/syncStatusStore.js.map +1 -1
- package/dist/storage/wasRemoteStore.d.ts +34 -2
- package/dist/storage/wasRemoteStore.d.ts.map +1 -1
- package/dist/storage/wasRemoteStore.js +45 -7
- package/dist/storage/wasRemoteStore.js.map +1 -1
- package/dist/storage/wasSync.d.ts.map +1 -1
- package/dist/storage/wasSync.js +47 -38
- package/dist/storage/wasSync.js.map +1 -1
- package/dist/sync/changesQuery.d.ts.map +1 -1
- package/dist/sync/changesQuery.js +2 -9
- package/dist/sync/changesQuery.js.map +1 -1
- package/dist/sync/docCipher.d.ts +23 -10
- package/dist/sync/docCipher.d.ts.map +1 -1
- package/dist/sync/docCipher.js +17 -11
- package/dist/sync/docCipher.js.map +1 -1
- package/dist/sync/feedMasterPort.d.ts +6 -0
- package/dist/sync/feedMasterPort.d.ts.map +1 -1
- package/dist/sync/feedMasterPort.js +82 -37
- package/dist/sync/feedMasterPort.js.map +1 -1
- package/dist/sync/index.d.ts +6 -5
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +6 -3
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/lww.d.ts +27 -18
- package/dist/sync/lww.d.ts.map +1 -1
- package/dist/sync/lww.js +35 -8
- package/dist/sync/lww.js.map +1 -1
- package/dist/sync/lwwConflictHandler.d.ts +15 -14
- package/dist/sync/lwwConflictHandler.d.ts.map +1 -1
- package/dist/sync/lwwConflictHandler.js +37 -26
- package/dist/sync/lwwConflictHandler.js.map +1 -1
- package/dist/sync/pushWrites.d.ts +9 -9
- package/dist/sync/pushWrites.d.ts.map +1 -1
- package/dist/sync/pushWrites.js +102 -68
- package/dist/sync/pushWrites.js.map +1 -1
- package/dist/sync/syncedDocSchema.d.ts.map +1 -1
- package/dist/sync/syncedDocSchema.js +3 -0
- package/dist/sync/syncedDocSchema.js.map +1 -1
- package/dist/sync/types.d.ts +115 -15
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/types.js +36 -18
- package/dist/sync/types.js.map +1 -1
- package/dist/sync/wasSyncPort.d.ts +0 -11
- package/dist/sync/wasSyncPort.d.ts.map +1 -1
- package/dist/sync/wasSyncPort.js +20 -36
- package/dist/sync/wasSyncPort.js.map +1 -1
- package/package.json +6 -6
- package/dist/identity/initAppSession.d.ts +0 -27
- package/dist/identity/initAppSession.d.ts.map +0 -1
- package/dist/identity/initAppSession.js +0 -30
- package/dist/identity/initAppSession.js.map +0 -1
|
@@ -2,45 +2,19 @@
|
|
|
2
2
|
* Copyright (c) 2026 Interop Alliance. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The relying-party side of the VC API request vocabulary: the Verifiable
|
|
6
|
+
* Presentation Request this library composes for a wallet, and the queries it
|
|
7
|
+
* carries.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* agnostic so the same
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* The request travels today via a CHAPI popup, but the shapes are transport
|
|
10
|
+
* agnostic, so the same compose logic can later back other entry points (a QR
|
|
11
|
+
* scan, an exchange-URL POST) without dragging React or CHAPI along. Only the
|
|
12
|
+
* types this library actually emits or consumes live here; the wallet-side
|
|
13
|
+
* message/response/classification shapes belong to the wallet.
|
|
13
14
|
*
|
|
14
15
|
* @see https://w3c-ccg.github.io/vp-request-spec/
|
|
15
16
|
*/
|
|
16
17
|
import type { IVerifiableCredential, IVerifiablePresentation, IZcap } from '@interop/data-integrity-core';
|
|
17
|
-
/**
|
|
18
|
-
* The union of VC API message types the wallet can classify. Zcap and exchange
|
|
19
|
-
* invitation / issue request messages are deferred to later work.
|
|
20
|
-
*/
|
|
21
|
-
export type WalletAPIMessage = IVPRequest | IVPOffer;
|
|
22
|
-
/**
|
|
23
|
-
* "I'm offering the following credentials" -- a Verifiable Presentation offered
|
|
24
|
-
* to the wallet for storage.
|
|
25
|
-
*
|
|
26
|
-
* @see https://vcplayground.org/docs/n/chapi/wallets/native/#vc-api
|
|
27
|
-
*/
|
|
28
|
-
export type IVPOffer = {
|
|
29
|
-
credentialRequestOrigin?: string;
|
|
30
|
-
verifiablePresentation: IVerifiablePresentation;
|
|
31
|
-
redirectUrl?: string;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* "The following things are requested" -- a Verifiable Presentation Request
|
|
35
|
-
* asking the wallet to share credentials and/or prove DID Authentication.
|
|
36
|
-
*
|
|
37
|
-
* @see https://w3c-ccg.github.io/vp-request-spec/
|
|
38
|
-
*/
|
|
39
|
-
export type IVPRequest = {
|
|
40
|
-
credentialRequestOrigin?: string;
|
|
41
|
-
verifiablePresentationRequest: IVPRDetails;
|
|
42
|
-
redirectUrl?: string;
|
|
43
|
-
};
|
|
44
18
|
/**
|
|
45
19
|
* The body of a Verifiable Presentation Request: one or more queries, plus the
|
|
46
20
|
* `challenge` / `domain` used when a DID Authentication proof is requested.
|
|
@@ -50,27 +24,7 @@ export type IVPRDetails = {
|
|
|
50
24
|
challenge?: string;
|
|
51
25
|
domain?: string;
|
|
52
26
|
};
|
|
53
|
-
export type IVPRQuery =
|
|
54
|
-
/**
|
|
55
|
-
* A request for one or more VCs matching an example credential shape.
|
|
56
|
-
*
|
|
57
|
-
* @see https://w3c-ccg.github.io/vp-request-spec/#query-by-example
|
|
58
|
-
*/
|
|
59
|
-
export type IQueryByExample = {
|
|
60
|
-
type: 'QueryByExample';
|
|
61
|
-
acceptedCryptosuites?: Array<{
|
|
62
|
-
cryptosuite: string;
|
|
63
|
-
}>;
|
|
64
|
-
credentialQuery: {
|
|
65
|
-
reason?: string;
|
|
66
|
-
example: {
|
|
67
|
-
'@context'?: string | object | Array<string | object>;
|
|
68
|
-
type?: string | string[];
|
|
69
|
-
issuer?: string | object | Array<string | object>;
|
|
70
|
-
[x: string]: unknown;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
27
|
+
export type IVPRQuery = IDIDAuthenticationQuery | IAppConnectQuery;
|
|
74
28
|
/**
|
|
75
29
|
* A request for a proof of DID Authentication (a signed VerifiablePresentation
|
|
76
30
|
* over the request's `challenge` / `domain`).
|
|
@@ -86,20 +40,6 @@ export type IDIDAuthenticationQuery = {
|
|
|
86
40
|
cryptosuite: string;
|
|
87
41
|
}>;
|
|
88
42
|
};
|
|
89
|
-
/**
|
|
90
|
-
* A request for one or more delegated capabilities (zcaps) on the user's WAS
|
|
91
|
-
* storage. `AuthorizationCapabilityQuery` is the canonical type string (VCALM
|
|
92
|
-
* §3.4.4); `ZcapQuery` is a legacy alias sent by DCW / the
|
|
93
|
-
* `wallet-to-webapp-demo`. `capabilityQuery` may be a single detail object or
|
|
94
|
-
* an array of them.
|
|
95
|
-
*
|
|
96
|
-
* @see https://w3c.github.io/vcalm/ -- AuthorizationCapabilityQuery
|
|
97
|
-
*/
|
|
98
|
-
export type IZcapQuery = {
|
|
99
|
-
type: 'AuthorizationCapabilityQuery' | 'ZcapQuery';
|
|
100
|
-
capabilityQuery: ICapabilityQueryDetail | ICapabilityQueryDetail[];
|
|
101
|
-
challenge?: string;
|
|
102
|
-
};
|
|
103
43
|
/**
|
|
104
44
|
* A single requested capability: which actions (`allowedAction`) the RP
|
|
105
45
|
* (`controller`) wants on which storage target (`invocationTarget`), with an
|
|
@@ -145,26 +85,5 @@ export type IAppConnectQuery = {
|
|
|
145
85
|
};
|
|
146
86
|
capabilityQuery: IAppConnectCapabilityQuery | IAppConnectCapabilityQuery[];
|
|
147
87
|
};
|
|
148
|
-
/**
|
|
149
|
-
* The wallet's response to a request, delivered by whichever transport received
|
|
150
|
-
* it (CHAPI `respondWith`, a future exchange-URL POST, etc). Delegated zcaps
|
|
151
|
-
* ride *inside* the response VP (as a `zcap` array, embedded before signing),
|
|
152
|
-
* so this shape stays credential-presentation only.
|
|
153
|
-
*/
|
|
154
|
-
export type WalletResponse = {
|
|
155
|
-
verifiablePresentation?: IVerifiablePresentation;
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
* A VP Request classified on two independent axes: whether DID Authentication
|
|
159
|
-
* is requested, and separately what content is asked for (credentials and/or
|
|
160
|
-
* capability delegations). Any combination is valid, including zcap-only. The
|
|
161
|
-
* consent screen renders one section per non-empty axis; the two axes replace
|
|
162
|
-
* the former `'vc' | 'didauth' | 'vc+didauth'` cross-product enum.
|
|
163
|
-
*/
|
|
164
|
-
export type WalletRequestProfile = {
|
|
165
|
-
didAuth: boolean;
|
|
166
|
-
vcQueries: IQueryByExample[];
|
|
167
|
-
zcapRequests: ICapabilityQueryDetail[];
|
|
168
|
-
};
|
|
169
88
|
export type { IVerifiableCredential, IVerifiablePresentation, IZcap };
|
|
170
89
|
//# sourceMappingURL=walletRequestTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletRequestTypes.d.ts","sourceRoot":"","sources":["../../src/auth/walletRequestTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"walletRequestTypes.d.ts","sourceRoot":"","sources":["../../src/auth/walletRequestTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,EACN,MAAM,8BAA8B,CAAA;AAErC;;;GAGG;AACH,MAA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EAAE,CAAA"}
|
package/dist/config.d.ts
CHANGED
|
@@ -46,9 +46,9 @@ export interface WasCollectionConfig {
|
|
|
46
46
|
* declares a world-readable collection (the wallet provisions it with a
|
|
47
47
|
* public-read policy); public implies PLAINTEXT -- payloads are stored as-is,
|
|
48
48
|
* with no per-collection cipher, and the LWW bookkeeping fields (`updatedAt`,
|
|
49
|
-
* `
|
|
50
|
-
* random per-
|
|
51
|
-
* user's public documents). Changing a collection's visibility after first
|
|
49
|
+
* `clientId`) are world-readable alongside the content (`clientId` is a
|
|
50
|
+
* random per-install attribution label, but still a linkability handle across
|
|
51
|
+
* a user's public documents). Changing a collection's visibility after first
|
|
52
52
|
* use is a data-migration event, not a config tweak: existing rows keep
|
|
53
53
|
* their stored form and stop being readable by the other mode.
|
|
54
54
|
*/
|
|
@@ -66,7 +66,7 @@ export interface WasCollectionConfig {
|
|
|
66
66
|
/**
|
|
67
67
|
* One SHARED collection: a wallet-owned, already-encrypted collection the app
|
|
68
68
|
* asks the wallet for read-and-decrypt access to (the
|
|
69
|
-
* `
|
|
69
|
+
* `https://w3id.org/byoe#shared-collection` grant). It is the mirror image of
|
|
70
70
|
* {@link WasCollectionConfig}: read-only, NOT replicated into RxDB, NOT written
|
|
71
71
|
* to, and with no local replica. Reads go straight to the server through a
|
|
72
72
|
* `SharedCollectionReader`.
|
|
@@ -138,7 +138,7 @@ export interface WasAppConfig {
|
|
|
138
138
|
collections: WasCollectionConfig[];
|
|
139
139
|
/**
|
|
140
140
|
* Wallet-owned collections this app asks to be given READ-AND-DECRYPT access
|
|
141
|
-
* to (the `
|
|
141
|
+
* to (the `https://w3id.org/byoe#shared-collection` grant). Read-only by construction: they
|
|
142
142
|
* are never replicated into RxDB, never written to, and have no local
|
|
143
143
|
* replica -- reads go straight to the server through a
|
|
144
144
|
* `SharedCollectionReader`. A collection may be app-owned (`collections`) or
|
|
@@ -172,9 +172,9 @@ export interface WasAppConfig {
|
|
|
172
172
|
*/
|
|
173
173
|
dbName?: string;
|
|
174
174
|
/**
|
|
175
|
-
* Prefix for this app's `localStorage` keys (e.g. the
|
|
176
|
-
* {@link DEFAULT_STORAGE_KEY_PREFIX}. Migrating apps should set
|
|
177
|
-
* prefix so an existing per-install
|
|
175
|
+
* Prefix for this app's `localStorage` keys (e.g. the LWW `clientId`).
|
|
176
|
+
* Defaults to {@link DEFAULT_STORAGE_KEY_PREFIX}. Migrating apps should set
|
|
177
|
+
* their prior prefix so an existing per-install client id is preserved.
|
|
178
178
|
*/
|
|
179
179
|
storageKeyPrefix?: string;
|
|
180
180
|
/**
|
|
@@ -228,7 +228,7 @@ export declare const DEFAULT_DB_NAME = "was-react";
|
|
|
228
228
|
*/
|
|
229
229
|
export declare const DEFAULT_ONBOARDING = "login-gated";
|
|
230
230
|
/**
|
|
231
|
-
* Default `localStorage` key prefix (e.g. `was-react:
|
|
231
|
+
* Default `localStorage` key prefix (e.g. `was-react:clientId`).
|
|
232
232
|
*/
|
|
233
233
|
export declare const DEFAULT_STORAGE_KEY_PREFIX = "was-react:";
|
|
234
234
|
/**
|
package/dist/config.js
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provisionDevGrants.d.ts","sourceRoot":"","sources":["../../src/dev/provisionDevGrants.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAQlE;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,UAIrC,CAAA;AAEF;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE;QACN,UAAU,EAAE,OAAO,CAAA;QACnB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,CAAA;CACF;
|
|
1
|
+
{"version":3,"file":"provisionDevGrants.d.ts","sourceRoot":"","sources":["../../src/dev/provisionDevGrants.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAQlE;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,UAIrC,CAAA;AAEF;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE;QACN,UAAU,EAAE,OAAO,CAAA;QACnB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,CAAA;CACF;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,SAAS,EACT,IAAI,EACJ,WAAW,EACX,SAAuB,EACvB,OAAO,EACP,eAA0C,EAC1C,cAAc,EAGd,OAAqC,EACrC,KAAa,EACb,GAAc,EACf,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,UAAU,CAAA;IAChB,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,UAAU,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAChC,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAsGpC"}
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
23
23
|
import { dirname } from 'node:path';
|
|
24
24
|
import { WasClient } from '@interop/was-client';
|
|
25
|
-
import { ZcapClient } from '@interop/ezcap';
|
|
26
|
-
import { Ed25519Signature2020 } from '@interop/ed25519-signature';
|
|
27
25
|
import { CapabilityAgent } from '@interop/webkms-client';
|
|
26
|
+
import { agentsFromKeyAgent } from '@interop/wallet-core/identity';
|
|
28
27
|
import { deriveIdentity } from '../identity/agents.js';
|
|
28
|
+
import { collectionPath } from '../grants.js';
|
|
29
29
|
import { RW_ACTIONS } from '../auth/loginRequest.js';
|
|
30
30
|
import { errorStatus } from '../sync/index.js';
|
|
31
31
|
/**
|
|
@@ -52,12 +52,7 @@ async function provisionerClient({ serverUrl, seed }) {
|
|
|
52
52
|
handle: 'dev-provisioner',
|
|
53
53
|
keyName: 'provisioner-key'
|
|
54
54
|
});
|
|
55
|
-
const
|
|
56
|
-
const zcapClient = new ZcapClient({
|
|
57
|
-
SuiteClass: Ed25519Signature2020,
|
|
58
|
-
invocationSigner: signer,
|
|
59
|
-
delegationSigner: signer
|
|
60
|
-
});
|
|
55
|
+
const { zcapClient } = agentsFromKeyAgent({ keyAgent: agent });
|
|
61
56
|
return { was: new WasClient({ serverUrl, zcapClient }), did: agent.id };
|
|
62
57
|
}
|
|
63
58
|
/**
|
|
@@ -90,11 +85,10 @@ export async function provisionDevGrants({ serverUrl, seed, collections, spaceNa
|
|
|
90
85
|
// The server accepts HEAD even though storage-core's ActionInput union omits
|
|
91
86
|
// it, hence the assertion.
|
|
92
87
|
actions = RW_ACTIONS, probe = false, log = () => { } }) {
|
|
93
|
-
const { controllerDid: appDid, zcapClient: appZcapClient }
|
|
94
|
-
|
|
95
|
-
serverUrl,
|
|
96
|
-
|
|
97
|
-
});
|
|
88
|
+
const [{ controllerDid: appDid, zcapClient: appZcapClient }, { was: provisioner, did: provisionerDid }] = await Promise.all([
|
|
89
|
+
deriveIdentity({ seed, identityHandle }),
|
|
90
|
+
provisionerClient({ serverUrl, seed: provisionerSeed })
|
|
91
|
+
]);
|
|
98
92
|
log(`Provisioning against ${serverUrl}`);
|
|
99
93
|
log(` provisioner DID: ${provisionerDid}`);
|
|
100
94
|
log(` app (RP) DID: ${appDid}`);
|
|
@@ -117,9 +111,11 @@ actions = RW_ACTIONS, probe = false, log = () => { } }) {
|
|
|
117
111
|
controller: provisionerDid,
|
|
118
112
|
invocationTarget: spaceUrl
|
|
119
113
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
// `Promise.all` preserves input order, so `grants[i]` still corresponds to
|
|
115
|
+
// `collections[i]` (the probe below relies on that for `[0]`).
|
|
116
|
+
const grants = await Promise.all(collections.map(async (id) => {
|
|
117
|
+
// Plaintext collection (no encryption descriptor) -- mirrors wallet
|
|
118
|
+
// provisioning.
|
|
123
119
|
await space.createCollection({ id, name: id });
|
|
124
120
|
const zcap = await provisioner.grant({
|
|
125
121
|
to: appDid,
|
|
@@ -127,9 +123,9 @@ actions = RW_ACTIONS, probe = false, log = () => { } }) {
|
|
|
127
123
|
target: `${spaceUrl}/${id}`,
|
|
128
124
|
capability: spaceRoot
|
|
129
125
|
});
|
|
130
|
-
grants.push(zcap);
|
|
131
126
|
log(` collection "${id}": created + delegated RW to app`);
|
|
132
|
-
|
|
127
|
+
return zcap;
|
|
128
|
+
}));
|
|
133
129
|
if (outFile !== undefined) {
|
|
134
130
|
await mkdir(dirname(outFile), { recursive: true });
|
|
135
131
|
await writeFile(outFile, JSON.stringify({ grants }, null, 2));
|
|
@@ -155,7 +151,10 @@ actions = RW_ACTIONS, probe = false, log = () => { } }) {
|
|
|
155
151
|
try {
|
|
156
152
|
const response = await appWas.request({
|
|
157
153
|
capability: probeCapability,
|
|
158
|
-
path:
|
|
154
|
+
path: collectionPath({
|
|
155
|
+
spaceId: space.id,
|
|
156
|
+
collectionId: probeCollectionId
|
|
157
|
+
}),
|
|
159
158
|
method: 'PUT',
|
|
160
159
|
json: { id: probeCollectionId, encryption: { scheme: 'edv' } }
|
|
161
160
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provisionDevGrants.js","sourceRoot":"","sources":["../../src/dev/provisionDevGrants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAA;AAEjE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"provisionDevGrants.js","sourceRoot":"","sources":["../../src/dev/provisionDevGrants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAA;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,WAAW,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AAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;YACpC,UAAU,EAAE,eAAe;YAC3B,IAAI,EAAE,cAAc,CAAC;gBACnB,OAAO,EAAE,KAAK,CAAC,EAAE;gBACjB,YAAY,EAAE,iBAAiB;aAChC,CAAC;YACF,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;SAC/D,CAAC,CAAA;QACF,GAAG,CAAC,oCAAoC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;QAC1D,MAAM,CAAC,KAAK,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAA;IAC9D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAC/B,MAAM,IAAI,GAAI,GAA0B,CAAC,IAAI,CAAA;QAC7C,GAAG,CAAC,8BAA8B,MAAM,IAAI,KAAK,EAAE,CAAC,CAAA;QACpD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,GAAG,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/C,CAAC;QACD,MAAM,CAAC,KAAK,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IAC1D,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/grants.d.ts
CHANGED
|
@@ -13,16 +13,23 @@ export interface ParsedGrants {
|
|
|
13
13
|
byCollectionId: Record<string, IZcap>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Builds the server path of a collection, the inverse of the grammar
|
|
17
|
+
* `parseInvocationTarget` reads. Callers append a trailing slash or query
|
|
18
|
+
* string for resource-listing and query endpoints.
|
|
19
|
+
*
|
|
20
|
+
* @param options {object}
|
|
21
|
+
* @param options.spaceId {string}
|
|
22
|
+
* @param options.collectionId {string}
|
|
23
|
+
* @returns {string}
|
|
18
24
|
*/
|
|
19
|
-
|
|
20
|
-
serverUrl: string;
|
|
25
|
+
export declare function collectionPath({ spaceId, collectionId }: {
|
|
21
26
|
spaceId: string;
|
|
22
27
|
collectionId: string;
|
|
23
|
-
}
|
|
28
|
+
}): string;
|
|
24
29
|
/**
|
|
25
|
-
* Parses a single `invocationTarget` URL into its WAS components
|
|
30
|
+
* Parses a single `invocationTarget` URL into its WAS components: the server
|
|
31
|
+
* origin, the space id, and the collection (every routed grant is
|
|
32
|
+
* collection-scoped, so `collectionId` is always present). `serverUrl` is
|
|
26
33
|
* the bare origin (`protocol//host`) with no trailing slash, matching the shape
|
|
27
34
|
* the reference server validates `SERVER_URL` into; the path grammar itself is
|
|
28
35
|
* owned by `@interop/was-client`'s `parseSpaceTarget`. A collection- or
|
|
@@ -32,9 +39,13 @@ interface ParsedTarget {
|
|
|
32
39
|
* capabilities.
|
|
33
40
|
*
|
|
34
41
|
* @param target {string} an absolute WAS URL
|
|
35
|
-
* @returns {
|
|
42
|
+
* @returns {{ serverUrl: string, spaceId: string, collectionId: string }}
|
|
36
43
|
*/
|
|
37
|
-
export declare function parseInvocationTarget(target: string):
|
|
44
|
+
export declare function parseInvocationTarget(target: string): {
|
|
45
|
+
serverUrl: string;
|
|
46
|
+
spaceId: string;
|
|
47
|
+
collectionId: string;
|
|
48
|
+
};
|
|
38
49
|
/**
|
|
39
50
|
* Parses a delegated grant set into the sync topology. Asserts a single server
|
|
40
51
|
* origin and a single space across every grant, and routes each collection-scoped
|
|
@@ -45,5 +56,4 @@ export declare function parseInvocationTarget(target: string): ParsedTarget;
|
|
|
45
56
|
* @returns {ParsedGrants}
|
|
46
57
|
*/
|
|
47
58
|
export declare function parseGrants(zcaps: IZcap[]): ParsedGrants;
|
|
48
|
-
export {};
|
|
49
59
|
//# sourceMappingURL=grants.d.ts.map
|
package/dist/grants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../src/grants.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AAEzD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;CACtC;AAED
|
|
1
|
+
{"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../src/grants.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AAEzD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;CACtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,YAAY,EACb,EAAE;IACD,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;CACrB,GAAG,MAAM,CAET;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG;IACrD,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;CACrB,CA0BA;AAiBD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,YAAY,CAgCxD"}
|
package/dist/grants.js
CHANGED
|
@@ -17,7 +17,22 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { parseSpaceTarget } from '@interop/was-client';
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Builds the server path of a collection, the inverse of the grammar
|
|
21
|
+
* `parseInvocationTarget` reads. Callers append a trailing slash or query
|
|
22
|
+
* string for resource-listing and query endpoints.
|
|
23
|
+
*
|
|
24
|
+
* @param options {object}
|
|
25
|
+
* @param options.spaceId {string}
|
|
26
|
+
* @param options.collectionId {string}
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function collectionPath({ spaceId, collectionId }) {
|
|
30
|
+
return `/space/${spaceId}/${collectionId}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses a single `invocationTarget` URL into its WAS components: the server
|
|
34
|
+
* origin, the space id, and the collection (every routed grant is
|
|
35
|
+
* collection-scoped, so `collectionId` is always present). `serverUrl` is
|
|
21
36
|
* the bare origin (`protocol//host`) with no trailing slash, matching the shape
|
|
22
37
|
* the reference server validates `SERVER_URL` into; the path grammar itself is
|
|
23
38
|
* owned by `@interop/was-client`'s `parseSpaceTarget`. A collection- or
|
|
@@ -27,7 +42,7 @@ import { parseSpaceTarget } from '@interop/was-client';
|
|
|
27
42
|
* capabilities.
|
|
28
43
|
*
|
|
29
44
|
* @param target {string} an absolute WAS URL
|
|
30
|
-
* @returns {
|
|
45
|
+
* @returns {{ serverUrl: string, spaceId: string, collectionId: string }}
|
|
31
46
|
*/
|
|
32
47
|
export function parseInvocationTarget(target) {
|
|
33
48
|
let url;
|
package/dist/grants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grants.js","sourceRoot":"","sources":["../src/grants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"grants.js","sourceRoot":"","sources":["../src/grants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;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} from '@interop/ezcap';
|
|
48
|
+
import type { ZcapClient } from '@interop/ezcap';
|
|
49
49
|
import type { IKeyAgreementKey, IKeyResolver } from '@interop/data-integrity-core';
|
|
50
50
|
/**
|
|
51
51
|
* Default cosmetic label for the master identity agent. Local naming only (does
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/identity/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/identity/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,8BAA8B,CAAA;AAErC;;;GAGG;AACH,eAAO,MAAM,uBAAuB,cAAc,CAAA;AAMlD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,eAAe,CAAA;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB;;OAEG;IACH,eAAe,EAAE,gBAAgB,CAAA;IACjC;;OAEG;IACH,WAAW,EAAE,YAAY,CAAA;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,EACnC,IAAI,EACJ,cAAwC,EACzC,EAAE;IACD,IAAI,EAAE,UAAU,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,OAAO,CAAC,cAAc,CAAC,CAe1B"}
|
package/dist/identity/agents.js
CHANGED
|
@@ -45,10 +45,7 @@
|
|
|
45
45
|
* Crypto that Node 24 provides.
|
|
46
46
|
*/
|
|
47
47
|
import { CapabilityAgent } from '@interop/webkms-client';
|
|
48
|
-
import {
|
|
49
|
-
import { ZcapClient } from '@interop/ezcap';
|
|
50
|
-
import { X25519KeyAgreementKey2020 } from '@interop/x25519-key-agreement-key';
|
|
51
|
-
import { singleKeyResolver } from '@interop/wallet-core/identity';
|
|
48
|
+
import { agentsFromKeyAgent } from '@interop/wallet-core/identity';
|
|
52
49
|
/**
|
|
53
50
|
* Default cosmetic label for the master identity agent. Local naming only (does
|
|
54
51
|
* not affect key material or the derived did:key); safe to override.
|
|
@@ -68,31 +65,19 @@ const IDENTITY_KEY_NAME = 'app-key';
|
|
|
68
65
|
* @returns {Promise<IdentityAgents>}
|
|
69
66
|
*/
|
|
70
67
|
export async function deriveIdentity({ seed, identityHandle = DEFAULT_IDENTITY_HANDLE }) {
|
|
68
|
+
if (seed.length !== 32) {
|
|
69
|
+
throw new Error(`Master seed must be 32 bytes (got ${seed.length}).`);
|
|
70
|
+
}
|
|
71
71
|
const keyAgent = await CapabilityAgent.fromSeed({
|
|
72
72
|
seed,
|
|
73
73
|
handle: identityHandle,
|
|
74
74
|
keyName: IDENTITY_KEY_NAME
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
// The identity KAK: the Ed25519-to-X25519 (Montgomery) conversion of the
|
|
83
|
-
// controller key pair -- the same conversion a wallet applies to the
|
|
84
|
-
// controller did:key when it writes this app into a shared collection's
|
|
85
|
-
// epoch roster.
|
|
86
|
-
const keyAgreementKey = X25519KeyAgreementKey2020.fromEd25519VerificationKey2020({
|
|
87
|
-
keyPair: keyAgent.getVerificationKeyPair()
|
|
88
|
-
});
|
|
89
|
-
const keyResolver = singleKeyResolver({ keyAgreementKey });
|
|
90
|
-
return {
|
|
91
|
-
controllerDid: keyAgent.id,
|
|
92
|
-
keyAgent,
|
|
93
|
-
zcapClient,
|
|
94
|
-
keyAgreementKey,
|
|
95
|
-
keyResolver
|
|
96
|
-
};
|
|
76
|
+
// The assembly (signer, ZcapClient, the Ed25519-to-X25519 Montgomery
|
|
77
|
+
// conversion of the controller key pair, key resolver) is shared with the
|
|
78
|
+
// wallet side via `agentsFromKeyAgent`, so the conversion that both sides of
|
|
79
|
+
// a share must agree on has exactly one implementation. Only the pinned
|
|
80
|
+
// derivation inputs above (seed bytes + keyName) stay local.
|
|
81
|
+
return { ...agentsFromKeyAgent({ keyAgent }), keyAgent };
|
|
97
82
|
}
|
|
98
83
|
//# sourceMappingURL=agents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/identity/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/identity/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAMlE;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAA;AAElD,6EAA6E;AAC7E,mEAAmE;AACnE,MAAM,iBAAiB,GAAG,SAAS,CAAA;AA8BnC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,IAAI,EACJ,cAAc,GAAG,uBAAuB,EAIzC;IACC,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;IACvE,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC;QAC9C,IAAI;QACJ,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,iBAAiB;KAC3B,CAAC,CAAA;IACF,qEAAqE;IACrE,0EAA0E;IAC1E,6EAA6E;IAC7E,wEAAwE;IACxE,6DAA6D;IAC7D,OAAO,EAAE,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAA;AAC1D,CAAC"}
|
|
@@ -32,6 +32,13 @@ export interface AppSessionRecord {
|
|
|
32
32
|
export interface RestoredAppSession extends AppSessionRecord {
|
|
33
33
|
seed: Uint8Array;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A nominal far-future expiry (ms) standing in for "no expiry": used both for a
|
|
37
|
+
* login that returned no grants (so there is no earliest-expiry to report) and
|
|
38
|
+
* for grants minted without one (dev/test). Well past any near-expiry warning,
|
|
39
|
+
* so the expiry watch never fires against it.
|
|
40
|
+
*/
|
|
41
|
+
export declare const NO_EXPIRY_MS: number;
|
|
35
42
|
/**
|
|
36
43
|
* Whether an ISO `expires` timestamp is in the past (or malformed).
|
|
37
44
|
*/
|
|
@@ -60,6 +67,26 @@ export declare function persistAppSession({ session, store }: {
|
|
|
60
67
|
session: RestoredAppSession;
|
|
61
68
|
store: SeedStore;
|
|
62
69
|
}): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Reads the persisted seed and session record WITHOUT clearing anything and
|
|
72
|
+
* WITHOUT applying the expiry rule -- the reconnect path's read, where the
|
|
73
|
+
* record being past its expiry is the normal case and the seed must survive it
|
|
74
|
+
* (only the grants need renewing). Either half comes back `null` when it is
|
|
75
|
+
* missing or malformed.
|
|
76
|
+
*
|
|
77
|
+
* Use {@link restoreAppSession} for a hot restore instead: it enforces the
|
|
78
|
+
* expiry and wipes a stale record.
|
|
79
|
+
*
|
|
80
|
+
* @param options {object}
|
|
81
|
+
* @param options.store {SeedStore}
|
|
82
|
+
* @returns {Promise<{ seed: Uint8Array | null, record: AppSessionRecord | null }>}
|
|
83
|
+
*/
|
|
84
|
+
export declare function peekAppSession({ store }: {
|
|
85
|
+
store: SeedStore;
|
|
86
|
+
}): Promise<{
|
|
87
|
+
seed: Uint8Array | null;
|
|
88
|
+
record: AppSessionRecord | null;
|
|
89
|
+
}>;
|
|
63
90
|
/**
|
|
64
91
|
* Restores the persisted session, or returns `null` (clearing any stale state)
|
|
65
92
|
* when it is missing, malformed, or expired.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appSession.d.ts","sourceRoot":"","sources":["../../src/identity/appSession.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,IAAI,EAAE,UAAU,CAAA;CACjB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAG1E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,GAAG,GAAE,IAAiB,GACrB,OAAO,CAMT;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,GAAG,IAAI,CAgB7D;AAED;;;;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;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,OAAO,EACP,KAAK,EACN,EAAE;IACD,OAAO,EAAE,kBAAkB,CAAA;IAC3B,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CAIhB;AAuBD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG,OAAO,CAAC;IAC7E,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAChC,CAAC,CASD;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,KAAK,EACN,EAAE;IACD,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAUrC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,EACpC,KAAK,EACN,EAAE;IACD,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhB"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A nominal far-future expiry (ms) standing in for "no expiry": used both for a
|
|
3
|
+
* login that returned no grants (so there is no earliest-expiry to report) and
|
|
4
|
+
* for grants minted without one (dev/test). Well past any near-expiry warning,
|
|
5
|
+
* so the expiry watch never fires against it.
|
|
6
|
+
*/
|
|
7
|
+
export const NO_EXPIRY_MS = 100 * 365 * 24 * 60 * 60 * 1000;
|
|
1
8
|
/**
|
|
2
9
|
* Whether an ISO `expires` timestamp is in the past (or malformed).
|
|
3
10
|
*/
|
|
@@ -53,27 +60,58 @@ export async function persistAppSession({ session, store }) {
|
|
|
53
60
|
await store.saveRecord(record);
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
63
|
+
* Whether a value loaded out of a {@link SeedStore} is a structurally complete
|
|
64
|
+
* session record. Says nothing about freshness -- an expired record is still a
|
|
65
|
+
* well-formed one (which is exactly what the reconnect path reads).
|
|
66
|
+
*
|
|
67
|
+
* @param stored {unknown}
|
|
68
|
+
* @returns {boolean}
|
|
69
|
+
*/
|
|
70
|
+
function isAppSessionRecord(stored) {
|
|
71
|
+
const record = stored;
|
|
72
|
+
return (!!record &&
|
|
73
|
+
typeof record.controllerDid === 'string' &&
|
|
74
|
+
typeof record.serverUrl === 'string' &&
|
|
75
|
+
typeof record.spaceId === 'string' &&
|
|
76
|
+
Array.isArray(record.grants) &&
|
|
77
|
+
record.grants.length > 0 &&
|
|
78
|
+
typeof record.expires === 'string');
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Reads the persisted seed and session record WITHOUT clearing anything and
|
|
82
|
+
* WITHOUT applying the expiry rule -- the reconnect path's read, where the
|
|
83
|
+
* record being past its expiry is the normal case and the seed must survive it
|
|
84
|
+
* (only the grants need renewing). Either half comes back `null` when it is
|
|
85
|
+
* missing or malformed.
|
|
86
|
+
*
|
|
87
|
+
* Use {@link restoreAppSession} for a hot restore instead: it enforces the
|
|
88
|
+
* expiry and wipes a stale record.
|
|
58
89
|
*
|
|
59
90
|
* @param options {object}
|
|
60
91
|
* @param options.store {SeedStore}
|
|
61
|
-
* @returns {Promise<
|
|
92
|
+
* @returns {Promise<{ seed: Uint8Array | null, record: AppSessionRecord | null }>}
|
|
62
93
|
*/
|
|
63
|
-
export async function
|
|
94
|
+
export async function peekAppSession({ store }) {
|
|
64
95
|
const [seed, stored] = await Promise.all([
|
|
65
96
|
store.loadSeed(),
|
|
66
97
|
store.loadRecord()
|
|
67
98
|
]);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
99
|
+
return {
|
|
100
|
+
seed: seed ?? null,
|
|
101
|
+
record: isAppSessionRecord(stored) ? stored : null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Restores the persisted session, or returns `null` (clearing any stale state)
|
|
106
|
+
* when it is missing, malformed, or expired.
|
|
107
|
+
*
|
|
108
|
+
* @param options {object}
|
|
109
|
+
* @param options.store {SeedStore}
|
|
110
|
+
* @returns {Promise<RestoredAppSession | null>}
|
|
111
|
+
*/
|
|
112
|
+
export async function restoreAppSession({ store }) {
|
|
113
|
+
const { seed, record } = await peekAppSession({ store });
|
|
114
|
+
if (!seed || !record) {
|
|
77
115
|
return null;
|
|
78
116
|
}
|
|
79
117
|
if (isExpired(record.expires)) {
|