@interop/wallet-core 0.23.1 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +33 -18
  2. package/dist/clients/revocation.d.ts +3 -6
  3. package/dist/clients/revocation.d.ts.map +1 -1
  4. package/dist/clients/revocation.js +5 -9
  5. package/dist/clients/revocation.js.map +1 -1
  6. package/dist/clients/rosterPolicy.d.ts +11 -17
  7. package/dist/clients/rosterPolicy.d.ts.map +1 -1
  8. package/dist/clients/rosterPolicy.js +22 -27
  9. package/dist/clients/rosterPolicy.js.map +1 -1
  10. package/dist/enrollment/enrollment.d.ts +2 -2
  11. package/dist/enrollment/enrollment.d.ts.map +1 -1
  12. package/dist/enrollment/enrollment.js +15 -10
  13. package/dist/enrollment/enrollment.js.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/keys/index.d.ts +11 -8
  17. package/dist/keys/index.d.ts.map +1 -1
  18. package/dist/keys/index.js +11 -8
  19. package/dist/keys/index.js.map +1 -1
  20. package/dist/keys/rosterLogStore.d.ts +34 -0
  21. package/dist/keys/rosterLogStore.d.ts.map +1 -0
  22. package/dist/keys/rosterLogStore.js +110 -0
  23. package/dist/keys/rosterLogStore.js.map +1 -0
  24. package/dist/keys/rosterStore.d.ts +18 -4
  25. package/dist/keys/rosterStore.d.ts.map +1 -1
  26. package/dist/keys/rosterStore.js +35 -16
  27. package/dist/keys/rosterStore.js.map +1 -1
  28. package/dist/keys/userKeyCascade.d.ts +1 -1
  29. package/dist/keys/userKeyCascade.js +1 -1
  30. package/dist/keys/userKeyRoster.d.ts +50 -97
  31. package/dist/keys/userKeyRoster.d.ts.map +1 -1
  32. package/dist/keys/userKeyRoster.js +44 -145
  33. package/dist/keys/userKeyRoster.js.map +1 -1
  34. package/dist/request/appKey.d.ts +254 -0
  35. package/dist/request/appKey.d.ts.map +1 -0
  36. package/dist/request/appKey.js +498 -0
  37. package/dist/request/appKey.js.map +1 -0
  38. package/dist/request/classify.d.ts +54 -3
  39. package/dist/request/classify.d.ts.map +1 -1
  40. package/dist/request/classify.js +106 -0
  41. package/dist/request/classify.js.map +1 -1
  42. package/dist/request/index.d.ts +4 -0
  43. package/dist/request/index.d.ts.map +1 -1
  44. package/dist/request/index.js +4 -0
  45. package/dist/request/index.js.map +1 -1
  46. package/dist/request/processRequest.d.ts.map +1 -1
  47. package/dist/request/processRequest.js +15 -6
  48. package/dist/request/processRequest.js.map +1 -1
  49. package/dist/request/types.d.ts +45 -2
  50. package/dist/request/types.d.ts.map +1 -1
  51. package/dist/resourceLog/append.d.ts +103 -0
  52. package/dist/resourceLog/append.d.ts.map +1 -0
  53. package/dist/resourceLog/append.js +190 -0
  54. package/dist/resourceLog/append.js.map +1 -0
  55. package/dist/resourceLog/controller.d.ts +57 -0
  56. package/dist/resourceLog/controller.d.ts.map +1 -0
  57. package/dist/resourceLog/controller.js +81 -0
  58. package/dist/resourceLog/controller.js.map +1 -0
  59. package/dist/resourceLog/entry.d.ts +68 -0
  60. package/dist/resourceLog/entry.d.ts.map +1 -0
  61. package/dist/resourceLog/entry.js +167 -0
  62. package/dist/resourceLog/entry.js.map +1 -0
  63. package/dist/resourceLog/errors.d.ts +75 -0
  64. package/dist/resourceLog/errors.d.ts.map +1 -0
  65. package/dist/resourceLog/errors.js +76 -0
  66. package/dist/resourceLog/errors.js.map +1 -0
  67. package/dist/resourceLog/index.d.ts +23 -0
  68. package/dist/resourceLog/index.d.ts.map +1 -0
  69. package/dist/resourceLog/index.js +23 -0
  70. package/dist/resourceLog/index.js.map +1 -0
  71. package/dist/resourceLog/pin.d.ts +44 -0
  72. package/dist/resourceLog/pin.d.ts.map +1 -0
  73. package/dist/resourceLog/pin.js +32 -0
  74. package/dist/resourceLog/pin.js.map +1 -0
  75. package/dist/resourceLog/verify.d.ts +89 -0
  76. package/dist/resourceLog/verify.d.ts.map +1 -0
  77. package/dist/resourceLog/verify.js +434 -0
  78. package/dist/resourceLog/verify.js.map +1 -0
  79. package/dist/space/collections.d.ts +14 -11
  80. package/dist/space/collections.d.ts.map +1 -1
  81. package/dist/space/collections.js +14 -11
  82. package/dist/space/collections.js.map +1 -1
  83. package/dist/space/index.d.ts +2 -2
  84. package/dist/space/index.d.ts.map +1 -1
  85. package/dist/space/index.js +2 -2
  86. package/dist/space/index.js.map +1 -1
  87. package/dist/webvh/didWeb.d.ts +4 -6
  88. package/dist/webvh/didWeb.d.ts.map +1 -1
  89. package/dist/webvh/didWeb.js.map +1 -1
  90. package/dist/webvh/didWebvh.d.ts +1 -2
  91. package/dist/webvh/didWebvh.d.ts.map +1 -1
  92. package/dist/webvh/didWebvh.js +1 -6
  93. package/dist/webvh/didWebvh.js.map +1 -1
  94. package/package.json +10 -4
@@ -0,0 +1,498 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * The App Connect app-key credential: a self-issued VC that carries a 32-byte
6
+ * seed an app keeps in the user's wallet so it can open its encrypted data on
7
+ * this and other devices. Unlike an ordinary credential, the issuer and
8
+ * subject are NOT the wallet user's DID -- they are a did:key derived from the
9
+ * seed itself (self-issued by the app key), so the credential validates
10
+ * standalone and the same seed reconstitutes the same identity on every
11
+ * client. The credential is bound to the attested requesting origin
12
+ * (`credentialSubject.origin`) and to the application's canonical URL
13
+ * (`credentialSubject.appUrl`), and matched wallet-side against both, so a
14
+ * phishing origin can neither recover an existing app key nor be handed one
15
+ * minted for another origin, and applications sharing an origin are kept
16
+ * apart by their `appUrl`s.
17
+ *
18
+ * Ported from Freewallet's `src/lib/appKey.ts`, migrated from the
19
+ * `credentialType` / `vocabBase` model to the App Connect spec's `appUrl`
20
+ * model: the type array is a fixed two-entry list, the inline `@context` is
21
+ * one static object identical for every application, and which application a
22
+ * credential belongs to is a claim (`credentialSubject.appUrl`), not a type.
23
+ * See the App Connect spec's App Key Credential section for the normative
24
+ * shape, matching, and minting rules this module implements.
25
+ */
26
+ import * as vc from '@interop/vc';
27
+ import { base64urlnopad } from '@scure/base';
28
+ import { CapabilityAgent } from '@interop/webkms-client';
29
+ import { Ed25519Signature2020 } from '@interop/ed25519-signature';
30
+ import { issuerId, subjectId, typeArray } from '@interop/data-integrity-core/guards';
31
+ import { documentLoader } from './composeVp.js';
32
+ /**
33
+ * The semantic `handle` mixed into seed derivation. It identifies the agent
34
+ * but does not affect the derived key (only the seed bytes and the key name
35
+ * enter the HMAC), so it is cosmetic; kept for legibility.
36
+ */
37
+ const APP_KEY_HANDLE = 'freewallet-app-key';
38
+ /**
39
+ * The key name mixed into seed derivation. Unlike the handle this is
40
+ * load-bearing: it is the HMAC message in `CapabilityAgent` derivation, so the
41
+ * exact string is a pinned input of the App Connect key-derivation rule --
42
+ * every existing app-key credential's identity depends on it.
43
+ */
44
+ export const APP_KEY_KEY_NAME = 'app-key';
45
+ const VC_1_CONTEXT_URL = 'https://www.w3.org/2018/credentials/v1';
46
+ /**
47
+ * The marker type every app-key credential carries, mapped to one stable IRI
48
+ * for every application. It makes "presents as an app key" a term check rather
49
+ * than a shape heuristic, which is what the store-time refusal
50
+ * ({@link assertStorableAppKey}) and the match path key off.
51
+ *
52
+ * It is a self-declaration, not evidence: the `type` array of a planted
53
+ * credential is attacker-controlled like the rest of it. The seed-to-subject
54
+ * binding ({@link appKeySeedBindsSubject}) authenticates only a credential's
55
+ * internal consistency, never its provenance (a fully attacker-generated
56
+ * credential binds perfectly). That is exactly why external ingest refuses on
57
+ * the marker alone, binding or not ({@link assertStorableAppKey}): app keys
58
+ * are wallet-minted, never imported.
59
+ */
60
+ export const APP_KEY_CREDENTIAL_TYPE = 'AppKeyCredential';
61
+ /**
62
+ * The fixed `type` array of every app-key credential: exactly two entries, in
63
+ * this order, identical for every application. Which application a credential
64
+ * belongs to is the `credentialSubject.appUrl` claim, not a type.
65
+ */
66
+ export const APP_KEY_TYPE_ARRAY = Object.freeze([
67
+ 'VerifiableCredential',
68
+ APP_KEY_CREDENTIAL_TYPE
69
+ ]);
70
+ /**
71
+ * The static inline `@context` object every app-key credential carries as the
72
+ * second entry of its `@context` array (after the VC 1.1 context URL). The
73
+ * shape is normative and byte-identical for every application and every
74
+ * credential: carrying the terms inline keeps the credential verifiable with
75
+ * no remote vocabulary fetch on either side.
76
+ */
77
+ export const APP_KEY_CONTEXT = Object.freeze({
78
+ '@protected': true,
79
+ AppKeyCredential: 'https://w3id.org/byoe#AppKeyCredential',
80
+ appUrl: 'https://w3id.org/byoe#appUrl',
81
+ seed: 'https://w3id.org/byoe#seed',
82
+ origin: 'https://w3id.org/byoe#origin',
83
+ name: 'https://schema.org/name',
84
+ description: 'https://schema.org/description'
85
+ });
86
+ /**
87
+ * The number of random bytes in an app-key seed.
88
+ */
89
+ const SEED_BYTE_LENGTH = 32;
90
+ /**
91
+ * Whether a credential presents as an app key -- that is, carries the
92
+ * {@link APP_KEY_CREDENTIAL_TYPE} marker in its `type` array. Says nothing
93
+ * about whether it IS one; that is the seed-to-subject binding's job.
94
+ *
95
+ * @param credential {IVerifiableCredential}
96
+ * @returns {boolean}
97
+ */
98
+ export function presentsAsAppKey(credential) {
99
+ return typeArray(credential.type).includes(APP_KEY_CREDENTIAL_TYPE);
100
+ }
101
+ /**
102
+ * The refusal a store path raises for a credential that presents as an app key
103
+ * but arrived from outside the wallet's own mint path. A distinct class so the
104
+ * UI can show its own translated wording rather than this message.
105
+ */
106
+ export class AppKeyRefusedError extends Error {
107
+ constructor() {
108
+ super('This credential claims to be an app key. App keys are created by the ' +
109
+ 'wallet itself and cannot be added from outside, so it was not stored.');
110
+ this.name = 'AppKeyRefusedError';
111
+ }
112
+ }
113
+ /**
114
+ * Refuses any credential that presents as an app key, unconditionally --
115
+ * whether or not it binds to its own seed. Called on every path that puts a
116
+ * credential in the store from outside the wallet (a CHAPI store offer, a
117
+ * URL / QR / manual-paste import), so an externally arriving app key never
118
+ * reaches the store, the credential list, or the user's Space.
119
+ *
120
+ * The seed-to-subject binding ({@link appKeySeedBindsSubject}) authenticates
121
+ * only the credential's internal consistency, not its provenance: a fully
122
+ * attacker-generated credential binds perfectly (a fresh seed, the victim
123
+ * app's `origin` and `appUrl`, self-issued), and storing it would make its
124
+ * DID the controller the wallet delegates the user's storage to. So there is
125
+ * no "binds, so it stores" carve-out here: app-key credentials are
126
+ * wallet-minted, never imported, and only the wallet's own mint path may
127
+ * store one.
128
+ *
129
+ * A credential with no marker is left alone, so an ordinary credential that
130
+ * merely happens to carry a `seed` or `origin` claim is never caught.
131
+ *
132
+ * @param credential {IVerifiableCredential}
133
+ * @returns {void} throws the refusal reason
134
+ */
135
+ export function assertStorableAppKey(credential) {
136
+ if (presentsAsAppKey(credential)) {
137
+ throw new AppKeyRefusedError();
138
+ }
139
+ }
140
+ /**
141
+ * Whether an app-key credential's subject DID is the one its own seed derives
142
+ * -- the binding that makes the credential an app key rather than merely a
143
+ * self-issued claim to be one. Self-issuance is a weak signal (anyone can
144
+ * self-issue); this is the strong one, and it is fully local: the credential
145
+ * carries the seed, so re-derive with the same call `mintAppKeyCredential`
146
+ * uses and compare. Fails closed on an absent, non-base64url, or otherwise
147
+ * unusable seed rather than throwing out of the match path.
148
+ *
149
+ * @param credential {IVerifiableCredential}
150
+ * @returns {Promise<boolean>}
151
+ */
152
+ export async function appKeySeedBindsSubject(credential) {
153
+ const subjectDid = subjectId(credential);
154
+ const seed = appKeySeedBytes(credential);
155
+ if (!subjectDid || !seed || seed.length !== SEED_BYTE_LENGTH) {
156
+ return false;
157
+ }
158
+ try {
159
+ const agent = await CapabilityAgent.fromSeed({
160
+ seed,
161
+ handle: APP_KEY_HANDLE,
162
+ keyName: APP_KEY_KEY_NAME
163
+ });
164
+ return agent.id === subjectDid;
165
+ }
166
+ catch {
167
+ return false;
168
+ }
169
+ }
170
+ /**
171
+ * Raised by {@link assertMintedAppKey} when a credential offered to the mint
172
+ * path's store door does not carry the mint invariants. Reaching it means a
173
+ * caller tried to route a foreign credential through the wallet's own mint
174
+ * door -- a programming error, not a user-facing refusal, so it is not
175
+ * translated like {@link AppKeyRefusedError}.
176
+ */
177
+ export class AppKeyMintInvariantError extends Error {
178
+ constructor() {
179
+ super('Only a wallet-minted app-key credential (marker type present, subject ' +
180
+ 'DID derived from its own seed) can be stored through the mint path.');
181
+ this.name = 'AppKeyMintInvariantError';
182
+ }
183
+ }
184
+ /**
185
+ * Asserts the mint invariants on a credential the wallet claims to have just
186
+ * minted: it presents as an app key (the marker type) and its subject DID
187
+ * re-derives from the seed it carries. The mirror image of
188
+ * {@link assertStorableAppKey} -- external ingest refuses every marker
189
+ * credential, the mint door stores only credentials that carry the full mint
190
+ * shape -- kept beside it so the two halves of the app-key store policy live
191
+ * in one module.
192
+ *
193
+ * @param credential {IVerifiableCredential}
194
+ * @returns {Promise<void>} throws {@link AppKeyMintInvariantError}
195
+ */
196
+ export async function assertMintedAppKey(credential) {
197
+ if (!presentsAsAppKey(credential) ||
198
+ !(await appKeySeedBindsSubject(credential))) {
199
+ throw new AppKeyMintInvariantError();
200
+ }
201
+ }
202
+ /**
203
+ * Whether a credential is self-issued: it names an issuer, and that issuer is
204
+ * its own subject. The shape every app-key credential has and every planted
205
+ * one must not be allowed to fake alone.
206
+ */
207
+ function isSelfIssued(credential) {
208
+ const issuer = issuerId(credential.issuer);
209
+ return !!issuer && issuer === subjectId(credential);
210
+ }
211
+ /**
212
+ * The instant a credential's `issuanceDate` denotes, or NaN when it is
213
+ * absent, not a string, or does not parse. Ranking is over instants, not raw
214
+ * strings: the ranking decides which DID the wallet delegates to, so a
215
+ * comparison manipulable by the *spelling* of a date (a numeric offset,
216
+ * differing fractional-second precision) would reopen the planted-credential
217
+ * path in a narrower form.
218
+ */
219
+ function issuanceInstant(credential) {
220
+ const raw = credential.issuanceDate;
221
+ if (typeof raw !== 'string') {
222
+ return NaN;
223
+ }
224
+ return Date.parse(raw);
225
+ }
226
+ /**
227
+ * Sort comparator ordering credentials latest-first by the instant their
228
+ * `issuanceDate` denotes; a credential whose date is absent or unparseable
229
+ * sorts last.
230
+ */
231
+ function byIssuanceInstantDesc(first, second) {
232
+ const firstInstant = issuanceInstant(first);
233
+ const secondInstant = issuanceInstant(second);
234
+ if (Number.isNaN(firstInstant)) {
235
+ return Number.isNaN(secondInstant) ? 0 : 1;
236
+ }
237
+ if (Number.isNaN(secondInstant)) {
238
+ return -1;
239
+ }
240
+ return secondInstant - firstInstant;
241
+ }
242
+ /**
243
+ * The app-key candidates for an app + origin, latest-first: everything the
244
+ * cheap, synchronous predicates accept, so only plausible candidates pay for
245
+ * a key derivation. A candidate must carry the marker (required, not merely
246
+ * tolerated: a credential can then only reach the delegation path by carrying
247
+ * it, which is exactly what the store-time refusal screens), name the
248
+ * request's `appUrl` in `credentialSubject.appUrl` (both sides in serialized
249
+ * form -- the wallet mints the claim serialized, so the comparison is an
250
+ * exact string match), be self-issued, and be bound to the attested
251
+ * requesting origin. Sorting here (rather than after the binding check) lets
252
+ * {@link findAppKeyCredential} stop at the newest credential that binds.
253
+ *
254
+ * @param options {object}
255
+ * @param options.credentials {IVerifiableCredential[]}
256
+ * @param options.appUrl {string} - The request's `app.appUrl` in serialized
257
+ * form.
258
+ * @param options.origin {string} - The attested requesting origin.
259
+ * @returns {IVerifiableCredential[]}
260
+ */
261
+ export function appKeyCandidates({ credentials, appUrl, origin }) {
262
+ return credentials
263
+ .filter(credential => presentsAsAppKey(credential) &&
264
+ appKeyAppUrl(credential) === appUrl &&
265
+ isSelfIssued(credential) &&
266
+ appKeyOrigin(credential) === origin)
267
+ .sort(byIssuanceInstantDesc);
268
+ }
269
+ /**
270
+ * The current (latest) app-key credential for an app + origin, or undefined
271
+ * when the user has none -- which signals first run for that (origin,
272
+ * `appUrl`) pair.
273
+ *
274
+ * @param options {object}
275
+ * @param options.credentials {IVerifiableCredential[]}
276
+ * @param options.appUrl {string} - The request's `app.appUrl` in serialized
277
+ * form.
278
+ * @param options.origin {string} - The attested requesting origin.
279
+ * @returns {Promise<IVerifiableCredential | undefined>}
280
+ */
281
+ export async function findAppKeyCredential({ credentials, appUrl, origin }) {
282
+ // Newest-first, returning at the first credential that binds: a non-binding
283
+ // one ranked above it is discarded on the way, and the credentials below it
284
+ // never pay for a key derivation.
285
+ for (const candidate of appKeyCandidates({ credentials, appUrl, origin })) {
286
+ if (await appKeySeedBindsSubject(candidate)) {
287
+ return candidate;
288
+ }
289
+ }
290
+ return undefined;
291
+ }
292
+ /**
293
+ * Assembles and signs an app-key credential for a seed the caller supplies:
294
+ * the fixed two-entry type array, the static inline context, issuer and
295
+ * subject both the seed-derived DID, and the `seed` / `appUrl` / `origin`
296
+ * claims. `vc.issue` auto-fills `issuanceDate` in the canonical UTC form the
297
+ * ranking expects. Shared by the fresh mint and the legacy re-issue.
298
+ */
299
+ async function issueAppKeyCredential({ seedBytes, appName, appUrl, origin, description }) {
300
+ const agent = await CapabilityAgent.fromSeed({
301
+ seed: seedBytes,
302
+ handle: APP_KEY_HANDLE,
303
+ keyName: APP_KEY_KEY_NAME
304
+ });
305
+ const controllerDid = agent.id;
306
+ const credential = {
307
+ '@context': [VC_1_CONTEXT_URL, { ...APP_KEY_CONTEXT }],
308
+ id: `urn:uuid:${crypto.randomUUID()}`,
309
+ type: [...APP_KEY_TYPE_ARRAY],
310
+ name: `${appName} app key`,
311
+ description,
312
+ issuer: controllerDid,
313
+ credentialSubject: {
314
+ id: controllerDid,
315
+ seed: base64urlnopad.encode(seedBytes),
316
+ appUrl,
317
+ origin
318
+ }
319
+ };
320
+ const suite = new Ed25519Signature2020({ signer: agent.getSigner() });
321
+ const signed = (await vc.issue({
322
+ credential,
323
+ suite,
324
+ documentLoader
325
+ }));
326
+ return { credential: signed, subjectDid: controllerDid };
327
+ }
328
+ /**
329
+ * Mints a fresh app-key credential for an app + origin: generates a 32-byte
330
+ * seed, derives the seed's did:key, and self-issues the credential (issuer ==
331
+ * subject == the seed-derived DID) with the `credentialSubject.appUrl` claim
332
+ * set from the validated request value. Does NOT store the result -- the
333
+ * caller stores it before delegating, so a failed delegation is found as
334
+ * "returning" on the next attempt rather than minting a second identity.
335
+ *
336
+ * @param options {object}
337
+ * @param options.app {IAppConnectApp} - The validated app identity; its
338
+ * `appUrl` must already be in serialized form (`appConnectRequestOf`
339
+ * guarantees this).
340
+ * @param options.origin {string} - The attested requesting origin, never a
341
+ * value taken from the request body.
342
+ * @returns {Promise<{ credential: IVerifiableCredential; subjectDid: string }>}
343
+ */
344
+ export async function mintAppKeyCredential({ app, origin }) {
345
+ const seedBytes = crypto.getRandomValues(new Uint8Array(SEED_BYTE_LENGTH));
346
+ return issueAppKeyCredential({
347
+ seedBytes,
348
+ appName: app.name,
349
+ appUrl: app.appUrl,
350
+ origin,
351
+ description: `The ${app.name} app keeps this key in your wallet so it can open ` +
352
+ 'your encrypted data on this and other devices.'
353
+ });
354
+ }
355
+ /**
356
+ * The latest legacy app-key credential for an origin, or undefined. A legacy
357
+ * credential predates the `appUrl` model: it carries the marker and a
358
+ * per-app third type entry, but no `credentialSubject.appUrl` claim. Its
359
+ * identity was scoped to (origin, `credentialType`), and the request no
360
+ * longer carries a `credentialType` to select on, so the mapping is
361
+ * recoverable only when it is unambiguous: when the binding legacy candidates
362
+ * for the origin all name one subject DID. Two distinct legacy identities on
363
+ * one origin yield undefined rather than a guess -- re-issuing the wrong one
364
+ * would hand one application another's identity, which is worse than the
365
+ * caller treating the connect as a first run.
366
+ *
367
+ * @param options {object}
368
+ * @param options.credentials {IVerifiableCredential[]}
369
+ * @param options.origin {string} - The attested requesting origin.
370
+ * @returns {Promise<IVerifiableCredential | undefined>}
371
+ */
372
+ export async function findLegacyAppKeyCredential({ credentials, origin }) {
373
+ const candidates = credentials
374
+ .filter(credential => presentsAsAppKey(credential) &&
375
+ appKeyAppUrl(credential) === undefined &&
376
+ isSelfIssued(credential) &&
377
+ appKeyOrigin(credential) === origin)
378
+ .sort(byIssuanceInstantDesc);
379
+ const bound = [];
380
+ for (const candidate of candidates) {
381
+ if (await appKeySeedBindsSubject(candidate)) {
382
+ bound.push(candidate);
383
+ }
384
+ }
385
+ if (bound.length === 0) {
386
+ return undefined;
387
+ }
388
+ const subjects = new Set(bound.map(credential => subjectId(credential)));
389
+ if (subjects.size > 1) {
390
+ return undefined;
391
+ }
392
+ return bound[0];
393
+ }
394
+ /**
395
+ * Re-issues a legacy app-key credential in place under the `appUrl` model:
396
+ * the same seed (so the same derived DID -- the app's identity and its
397
+ * encrypted-data access are preserved), the fixed two-entry type array, the
398
+ * static inline context, and the `credentialSubject.appUrl` claim set from
399
+ * the validated request value. A fresh mint would roll the seed and orphan
400
+ * the identity, and must never be the migration path. The fresh
401
+ * `issuanceDate` ranks the re-issued credential ahead of the legacy one, so
402
+ * subsequent connects match it directly.
403
+ *
404
+ * Does NOT store the result; the caller stores it through the mint door
405
+ * (it satisfies {@link assertMintedAppKey}) and may retire the legacy record.
406
+ *
407
+ * @param options {object}
408
+ * @param options.credential {IVerifiableCredential} - The legacy credential;
409
+ * it must bind per {@link appKeySeedBindsSubject} and be bound to `origin`,
410
+ * else this throws {@link AppKeyMintInvariantError}.
411
+ * @param options.app {IAppConnectApp} - The validated app identity; its
412
+ * `appUrl` must already be in serialized form.
413
+ * @param options.origin {string} - The attested requesting origin.
414
+ * @returns {Promise<{ credential: IVerifiableCredential; subjectDid: string }>}
415
+ */
416
+ export async function reissueAppKeyCredential({ credential, app, origin }) {
417
+ if (!(await appKeySeedBindsSubject(credential)) ||
418
+ appKeyOrigin(credential) !== origin) {
419
+ throw new AppKeyMintInvariantError();
420
+ }
421
+ const seedBytes = appKeySeedBytes(credential);
422
+ if (!seedBytes) {
423
+ throw new AppKeyMintInvariantError();
424
+ }
425
+ const legacyDescription = credential
426
+ .description;
427
+ return issueAppKeyCredential({
428
+ seedBytes,
429
+ appName: app.name,
430
+ appUrl: app.appUrl,
431
+ origin,
432
+ description: typeof legacyDescription === 'string'
433
+ ? legacyDescription
434
+ : `The ${app.name} app keeps this key in your wallet so it can ` +
435
+ 'open your encrypted data on this and other devices.'
436
+ });
437
+ }
438
+ /**
439
+ * The subject DID (`credentialSubject.id`) of an app-key credential, or
440
+ * undefined. For a valid app-key credential this equals the issuer.
441
+ *
442
+ * @param credential {IVerifiableCredential}
443
+ * @returns {string | undefined}
444
+ */
445
+ export function appKeySubjectDid(credential) {
446
+ return subjectId(credential);
447
+ }
448
+ /**
449
+ * The 32-byte seed an app-key credential carries
450
+ * (`credentialSubject.seed`, base64url-no-pad), or undefined when it is absent
451
+ * or malformed. This is the app's client secret, the root of its identity and
452
+ * of the keys it encrypts its own data with. The wallet reads it only to
453
+ * re-derive the credential's subject DID ({@link appKeySeedBindsSubject}) and
454
+ * to re-issue a legacy credential under the same identity; nothing downstream
455
+ * of the match takes the seed, so it never reaches the grant path.
456
+ *
457
+ * @param credential {IVerifiableCredential}
458
+ * @returns {Uint8Array | undefined}
459
+ */
460
+ function appKeySeedBytes(credential) {
461
+ const subject = credential.credentialSubject;
462
+ if (!subject || typeof subject.seed !== 'string') {
463
+ return undefined;
464
+ }
465
+ try {
466
+ return base64urlnopad.decode(subject.seed);
467
+ }
468
+ catch {
469
+ return undefined;
470
+ }
471
+ }
472
+ /**
473
+ * The origin (`credentialSubject.origin`) an app-key credential is bound to,
474
+ * when present.
475
+ *
476
+ * @param credential {IVerifiableCredential}
477
+ * @returns {string | undefined}
478
+ */
479
+ export function appKeyOrigin(credential) {
480
+ const subject = credential.credentialSubject;
481
+ return subject && typeof subject.origin === 'string'
482
+ ? subject.origin
483
+ : undefined;
484
+ }
485
+ /**
486
+ * The application URL (`credentialSubject.appUrl`) an app-key credential is
487
+ * scoped to, when present. Absent on a legacy (pre-`appUrl`) credential.
488
+ *
489
+ * @param credential {IVerifiableCredential}
490
+ * @returns {string | undefined}
491
+ */
492
+ export function appKeyAppUrl(credential) {
493
+ const subject = credential.credentialSubject;
494
+ return subject && typeof subject.appUrl === 'string'
495
+ ? subject.appUrl
496
+ : undefined;
497
+ }
498
+ //# sourceMappingURL=appKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,+CAA+C;gBAC9D,qDAAqD;KAC5D,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAiC;IAEjC,OAAO,SAAS,CAAC,UAAU,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,eAAe,CACtB,UAAiC;IAEjC,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAmD,CAAA;IAC9E,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAiC;IAEjC,MAAM,OAAO,GAAG,UAAU,CAAC,iBACO,CAAA;IAClC,OAAO,OAAO,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;QAClD,CAAC,CAAC,OAAO,CAAC,MAAM;QAChB,CAAC,CAAC,SAAS,CAAA;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAiC;IAEjC,MAAM,OAAO,GAAG,UAAU,CAAC,iBACO,CAAA;IAClC,OAAO,OAAO,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;QAClD,CAAC,CAAC,OAAO,CAAC,MAAM;QAChB,CAAC,CAAC,SAAS,CAAA;AACf,CAAC"}
@@ -9,10 +9,11 @@
9
9
  *
10
10
  * Ported from Freewallet's `src/lib/walletRequest/classify.ts` (the superset of
11
11
  * DCW's `app/lib/exchanges.ts` / `walletRequestApi.ts` dispatch helpers). The
12
- * App Connect query kind is a Freewallet-only extension and stays app-side; the
13
- * shared classifier covers the three VPR-spec query types.
12
+ * shared classifier covers the three VPR-spec query types plus the App Connect
13
+ * `AppConnectQuery` extension (`appConnectRequestOf`), whose `app` block is
14
+ * validated here against the attested requesting origin.
14
15
  */
15
- import type { CHAPIStoreEvent, ICapabilityQueryDetail, ICredentialQuery, IQueryByExample, IVPOffer, IVPRequest, IVPRDetails, IVPRQuery, IVerifiableCredential, IVerifiablePresentation, WalletRequestProfile } from './types.js';
16
+ import type { CHAPIStoreEvent, IAppConnectRequest, ICapabilityQueryDetail, ICredentialQuery, IQueryByExample, IVPOffer, IVPRequest, IVPRDetails, IVPRQuery, IVerifiableCredential, IVerifiablePresentation, WalletRequestProfile } from './types.js';
16
17
  import type { CHAPIGetEvent } from './types.js';
17
18
  /**
18
19
  * The VC data model version a presentation carrying the given credentials must
@@ -90,6 +91,56 @@ export declare function credentialQueriesOf(query: IQueryByExample): ICredential
90
91
  * @returns {ICapabilityQueryDetail[]}
91
92
  */
92
93
  export declare function zcapQueriesOf(queries: IVPRQuery[]): ICapabilityQueryDetail[];
94
+ /**
95
+ * Validates an App Connect `app.appUrl` against the attested requesting origin
96
+ * and returns its serialized form. The value must parse as an absolute URL,
97
+ * must not carry a fragment, and its origin must equal the attested origin;
98
+ * any violation throws (the query is malformed). All storage and comparison
99
+ * downstream uses the returned serialization, so spellings differing only in
100
+ * a default port, percent-encoding case, or dot-segments do not name distinct
101
+ * applications.
102
+ *
103
+ * The fragment check reads the serialized URL rather than `url.hash`: a bare
104
+ * trailing `#` sets an empty (non-null) fragment that `hash` reports as `''`,
105
+ * and a percent-encoded `%23` never appears as `#` in the serialization.
106
+ *
107
+ * @param options {object}
108
+ * @param options.appUrl {string} - The request's `app.appUrl`.
109
+ * @param options.origin {string} - The attested requesting origin.
110
+ * @returns {string} The parsed URL's serialization.
111
+ */
112
+ export declare function serializedAppUrl({ appUrl, origin }: {
113
+ appUrl: string;
114
+ origin: string;
115
+ }): string;
116
+ /**
117
+ * Extracts the App Connect request from a query set, when one is present. An
118
+ * `AppConnectQuery` is one mental model per popup: the request must not also
119
+ * carry `QueryByExample` or standalone zcap queries, at most one
120
+ * `AppConnectQuery` is allowed, and its `app` block must carry the display
121
+ * `name` and the `appUrl` the wallet needs to match or mint the app-key
122
+ * credential -- with the `appUrl` validated against the attested requesting
123
+ * origin and rewritten to its serialized form ({@link serializedAppUrl}).
124
+ * Violations throw; classification-time callers surface the throw as a
125
+ * malformed-request state. The capability queries are normalized to an array
126
+ * (absent means "no grants requested" -- a connect that only recovers the app
127
+ * key is legal), and each entry is rebuilt from an allowlist of the declared
128
+ * fields (`referenceId`, `allowedAction`, `invocationTarget`): the type-level
129
+ * Omit does not bind an actual request body, so any other wire-level field --
130
+ * a smuggled `reason`, an attacker-chosen `controller`, a future
131
+ * display-bearing addition -- is made unrepresentable here, before the entries
132
+ * reach the profile the consent screen and the delegation path read.
133
+ *
134
+ * @param options {object}
135
+ * @param options.queries {IVPRQuery[]}
136
+ * @param options.origin {string} - The attested requesting origin the
137
+ * `appUrl` is validated against.
138
+ * @returns {IAppConnectRequest | null}
139
+ */
140
+ export declare function appConnectRequestOf({ queries, origin }: {
141
+ queries: IVPRQuery[];
142
+ origin: string;
143
+ }): IAppConnectRequest | null;
93
144
  /**
94
145
  * Classifies a VPR body onto the independent axes the consent screen and
95
146
  * response assembly work from: whether DID Authentication is requested, and
@@ -1 +1 @@
1
- {"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../src/request/classify.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAEhB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,EACX,SAAS,EACT,qBAAqB,EACrB,uBAAuB,EAEvB,oBAAoB,EACrB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAO/C;;;;;;;;;GASG;AACH,w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