@enbox/agent 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/browser.mjs +11 -11
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/anonymous-dwn-api.js +184 -0
  4. package/dist/esm/anonymous-dwn-api.js.map +1 -0
  5. package/dist/esm/dwn-api.js +86 -777
  6. package/dist/esm/dwn-api.js.map +1 -1
  7. package/dist/esm/dwn-encryption.js +342 -0
  8. package/dist/esm/dwn-encryption.js.map +1 -0
  9. package/dist/esm/dwn-key-delivery.js +256 -0
  10. package/dist/esm/dwn-key-delivery.js.map +1 -0
  11. package/dist/esm/dwn-record-upgrade.js +119 -0
  12. package/dist/esm/dwn-record-upgrade.js.map +1 -0
  13. package/dist/esm/dwn-type-guards.js +23 -0
  14. package/dist/esm/dwn-type-guards.js.map +1 -0
  15. package/dist/esm/index.js +6 -0
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/protocol-utils.js +158 -0
  18. package/dist/esm/protocol-utils.js.map +1 -0
  19. package/dist/esm/store-data-protocols.js +1 -1
  20. package/dist/esm/store-data-protocols.js.map +1 -1
  21. package/dist/esm/sync-engine-level.js +22 -353
  22. package/dist/esm/sync-engine-level.js.map +1 -1
  23. package/dist/esm/sync-messages.js +234 -0
  24. package/dist/esm/sync-messages.js.map +1 -0
  25. package/dist/esm/sync-topological-sort.js +143 -0
  26. package/dist/esm/sync-topological-sort.js.map +1 -0
  27. package/dist/esm/test-harness.js +20 -0
  28. package/dist/esm/test-harness.js.map +1 -1
  29. package/dist/types/anonymous-dwn-api.d.ts +140 -0
  30. package/dist/types/anonymous-dwn-api.d.ts.map +1 -0
  31. package/dist/types/dwn-api.d.ts +36 -179
  32. package/dist/types/dwn-api.d.ts.map +1 -1
  33. package/dist/types/dwn-encryption.d.ts +144 -0
  34. package/dist/types/dwn-encryption.d.ts.map +1 -0
  35. package/dist/types/dwn-key-delivery.d.ts +112 -0
  36. package/dist/types/dwn-key-delivery.d.ts.map +1 -0
  37. package/dist/types/dwn-record-upgrade.d.ts +33 -0
  38. package/dist/types/dwn-record-upgrade.d.ts.map +1 -0
  39. package/dist/types/dwn-type-guards.d.ts +9 -0
  40. package/dist/types/dwn-type-guards.d.ts.map +1 -0
  41. package/dist/types/index.d.ts +6 -0
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/protocol-utils.d.ts +70 -0
  44. package/dist/types/protocol-utils.d.ts.map +1 -0
  45. package/dist/types/sync-engine-level.d.ts +5 -42
  46. package/dist/types/sync-engine-level.d.ts.map +1 -1
  47. package/dist/types/sync-messages.d.ts +76 -0
  48. package/dist/types/sync-messages.d.ts.map +1 -0
  49. package/dist/types/sync-topological-sort.d.ts +15 -0
  50. package/dist/types/sync-topological-sort.d.ts.map +1 -0
  51. package/dist/types/test-harness.d.ts +10 -0
  52. package/dist/types/test-harness.d.ts.map +1 -1
  53. package/package.json +5 -5
  54. package/src/anonymous-dwn-api.ts +263 -0
  55. package/src/dwn-api.ts +160 -1015
  56. package/src/dwn-encryption.ts +481 -0
  57. package/src/dwn-key-delivery.ts +370 -0
  58. package/src/dwn-record-upgrade.ts +166 -0
  59. package/src/dwn-type-guards.ts +43 -0
  60. package/src/index.ts +6 -0
  61. package/src/protocol-utils.ts +185 -0
  62. package/src/store-data-protocols.ts +1 -1
  63. package/src/sync-engine-level.ts +24 -413
  64. package/src/sync-messages.ts +277 -0
  65. package/src/sync-topological-sort.ts +167 -0
  66. package/src/test-harness.ts +19 -0
@@ -0,0 +1,256 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { ContentEncryptionAlgorithm, DataStream, KeyDerivationScheme, Message, Protocols, Records, } from '@enbox/dwn-sdk-js';
11
+ import { getDwnServiceEndpointUrls } from './utils.js';
12
+ import { KeyDeliveryProtocolDefinition } from './store-data-protocols.js';
13
+ import { buildEncryptionInput, encryptAndComputeCid, getEncryptionKeyDeriver, getKeyDecrypter, ivLength } from './dwn-encryption.js';
14
+ import { DwnInterface, dwnMessageConstructors } from './types/dwn.js';
15
+ /**
16
+ * Ensures the key delivery protocol is installed on the given tenant's DWN,
17
+ * with `$encryption` keys injected. Uses the same lazy initialization pattern
18
+ * as `DwnDataStore.initialize()`.
19
+ *
20
+ * @param agent - The platform agent
21
+ * @param tenantDid - The DID of the DWN owner
22
+ * @param processRequest - The agent's processRequest method (bound)
23
+ * @param getProtocolDefinition - Function to get a protocol definition
24
+ * @param installedCache - Cache for installation status
25
+ */
26
+ export function ensureKeyDeliveryProtocol(agent, tenantDid, processRequest, getProtocolDefinition, installedCache, protocolDefinitionCache) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ if (installedCache.get(tenantDid)) {
29
+ return;
30
+ }
31
+ const protocolUri = KeyDeliveryProtocolDefinition.protocol;
32
+ const existing = yield getProtocolDefinition(tenantDid, protocolUri);
33
+ if (!existing) {
34
+ // Derive and inject $encryption keys for each type path
35
+ const keyDeriver = yield getEncryptionKeyDeriver(agent, tenantDid);
36
+ const definitionWithKeys = yield Protocols.deriveAndInjectPublicEncryptionKeys(KeyDeliveryProtocolDefinition, keyDeriver);
37
+ const { reply: { status } } = yield processRequest({
38
+ author: tenantDid,
39
+ target: tenantDid,
40
+ messageType: DwnInterface.ProtocolsConfigure,
41
+ messageParams: { definition: definitionWithKeys },
42
+ });
43
+ if (status.code !== 202) {
44
+ throw new Error(`AgentDwnApi: Failed to install key delivery protocol: ${status.code} - ${status.detail}`);
45
+ }
46
+ // Invalidate protocol definition cache so subsequent reads pick up the new definition
47
+ protocolDefinitionCache.delete(`${tenantDid}~${protocolUri}`);
48
+ }
49
+ installedCache.set(tenantDid, true);
50
+ });
51
+ }
52
+ /**
53
+ * Writes a `contextKey` record to the owner's DWN, delivering an encrypted
54
+ * context key to a participant.
55
+ *
56
+ * The payload is encrypted to the **recipient's** ProtocolPath-derived public
57
+ * key on the key-delivery protocol, so only the recipient can decrypt it.
58
+ *
59
+ * @param agent - The platform agent
60
+ * @param params - The write parameters
61
+ * @param processRequest - The agent's processRequest method (bound)
62
+ * @param ensureProtocol - Function to ensure key delivery protocol is installed
63
+ * @param eagerSend - Function to eagerly send the record to the remote DWN
64
+ * @returns The recordId of the written contextKey record
65
+ */
66
+ export function writeContextKeyRecord(agent, params, processRequest, ensureProtocol, eagerSend) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const { tenantDid, recipientDid, contextKeyData, sourceProtocol, sourceContextId, recipientKeyDeliveryPublicKey } = params;
69
+ // Ensure the key delivery protocol is installed on the owner's DWN
70
+ yield ensureProtocol(tenantDid);
71
+ const protocolUri = KeyDeliveryProtocolDefinition.protocol;
72
+ // Serialize the payload to JSON bytes
73
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(contextKeyData));
74
+ // Common contextKey record parameters
75
+ const contextKeyParams = {
76
+ protocol: protocolUri,
77
+ protocolPath: 'contextKey',
78
+ dataFormat: 'application/json',
79
+ recipient: recipientDid,
80
+ tags: { protocol: sourceProtocol, contextId: sourceContextId },
81
+ };
82
+ let message;
83
+ let status;
84
+ if (recipientKeyDeliveryPublicKey) {
85
+ // --- Encrypt to the recipient's ProtocolPath key (cross-DWN delivery) ---
86
+ // Manually build encryption input targeting the recipient's key so the
87
+ // record is decryptable only by the recipient.
88
+ const algorithm = ContentEncryptionAlgorithm.A256GCM;
89
+ const dataEncryptionKey = crypto.getRandomValues(new Uint8Array(32));
90
+ const dataEncryptionIV = crypto.getRandomValues(new Uint8Array(ivLength(algorithm)));
91
+ const { encryptedBytes, dataCid, dataSize, authenticationTag } = yield encryptAndComputeCid(plaintextBytes, dataEncryptionKey, dataEncryptionIV, algorithm);
92
+ const encryptionInput = Object.assign(Object.assign({}, buildEncryptionInput(dataEncryptionKey, dataEncryptionIV, recipientKeyDeliveryPublicKey.rootKeyId, recipientKeyDeliveryPublicKey.publicKeyJwk, KeyDerivationScheme.ProtocolPath)), { authenticationTag });
93
+ ({ message, reply: { status } } = yield processRequest({
94
+ author: tenantDid,
95
+ target: tenantDid,
96
+ messageType: DwnInterface.RecordsWrite,
97
+ messageParams: Object.assign(Object.assign({}, contextKeyParams), { dataCid, dataSize, encryptionInput }),
98
+ dataStream: new Blob([encryptedBytes]),
99
+ }));
100
+ }
101
+ else {
102
+ // --- Fallback: encrypt to the owner's key (local self-delivery) ---
103
+ // When no recipient key is provided, use the generic processRequest
104
+ // encryption path which encrypts to the DWN owner's ProtocolPath key.
105
+ ({ message, reply: { status } } = yield processRequest({
106
+ author: tenantDid,
107
+ target: tenantDid,
108
+ messageType: DwnInterface.RecordsWrite,
109
+ messageParams: contextKeyParams,
110
+ dataStream: new Blob([plaintextBytes], { type: 'application/json' }),
111
+ encryption: true,
112
+ }));
113
+ }
114
+ if (!(message && status.code === 202)) {
115
+ throw new Error(`AgentDwnApi: Failed to write contextKey record for ${recipientDid}: ${status.code} - ${status.detail}`);
116
+ }
117
+ // Eagerly send the contextKey record to the tenant's remote DWN so that
118
+ // participants can fetch it immediately without waiting for sync.
119
+ // This is fire-and-forget — sync will guarantee eventual consistency.
120
+ eagerSend(tenantDid, message).catch((err) => {
121
+ console.warn(`AgentDwnApi: Eager send of contextKey record '${message.recordId}' ` +
122
+ `to remote DWN failed: ${err.message}. Sync will deliver it later.`);
123
+ });
124
+ return message.recordId;
125
+ });
126
+ }
127
+ /**
128
+ * Eagerly sends a contextKey record to the tenant's remote DWN.
129
+ * This is best-effort — sync guarantees eventual consistency regardless.
130
+ *
131
+ * @param agent - The platform agent
132
+ * @param tenantDid - The DWN owner's DID
133
+ * @param contextKeyMessage - The context key message to send
134
+ * @param getDwnMessage - Function to read a full message from local DWN
135
+ * @param sendDwnRpcRequest - Function to send a DWN RPC request
136
+ */
137
+ export function eagerSendContextKeyRecord(agent, tenantDid, contextKeyMessage, getDwnMessage, sendDwnRpcRequest) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ let dwnEndpointUrls;
140
+ try {
141
+ dwnEndpointUrls = yield getDwnServiceEndpointUrls(tenantDid, agent.did);
142
+ }
143
+ catch (_a) {
144
+ // DID resolution or endpoint lookup failed — not fatal, sync will handle it.
145
+ return;
146
+ }
147
+ if (dwnEndpointUrls.length === 0) {
148
+ return;
149
+ }
150
+ // Read the full message (including data blob) from the local DWN
151
+ const { data } = yield getDwnMessage({
152
+ author: tenantDid,
153
+ messageType: DwnInterface.RecordsWrite,
154
+ messageCid: yield Message.getCid(contextKeyMessage),
155
+ });
156
+ yield sendDwnRpcRequest({
157
+ targetDid: tenantDid,
158
+ dwnEndpointUrls,
159
+ message: contextKeyMessage,
160
+ data,
161
+ });
162
+ });
163
+ }
164
+ /**
165
+ * Fetches and decrypts a `contextKey` record from a DWN, returning the
166
+ * `DerivedPrivateJwk` payload.
167
+ *
168
+ * Supports both local reads (tenant queries own DWN) and remote reads
169
+ * (participant queries the context owner's DWN).
170
+ *
171
+ * @param agent - The platform agent
172
+ * @param params - The fetch parameters
173
+ * @param processRequest - The agent's processRequest method (bound)
174
+ * @param getSigner - Function to get a signer for a DID
175
+ * @param sendDwnRpcRequest - Function to send a DWN RPC request
176
+ * @returns The decrypted `DerivedPrivateJwk`, or `undefined` if no matching record found
177
+ */
178
+ export function fetchContextKeyRecord(agent, params, processRequest, getSigner, sendDwnRpcRequest) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ var _a, _b, _c, _d, _e;
181
+ const { ownerDid, requesterDid, sourceProtocol, sourceContextId } = params;
182
+ const protocolUri = KeyDeliveryProtocolDefinition.protocol;
183
+ const isLocal = ownerDid === requesterDid;
184
+ // Shared query filter for both local and remote paths
185
+ const contextKeyFilter = {
186
+ protocol: protocolUri,
187
+ protocolPath: 'contextKey',
188
+ recipient: requesterDid,
189
+ tags: { protocol: sourceProtocol, contextId: sourceContextId },
190
+ };
191
+ /** Parse decrypted bytes into a DerivedPrivateJwk. */
192
+ const parsePayload = (bytes) => JSON.parse(new TextDecoder().decode(bytes));
193
+ if (isLocal) {
194
+ // Local query: owner queries their own DWN
195
+ const { reply } = yield processRequest({
196
+ author: requesterDid,
197
+ target: ownerDid,
198
+ messageType: DwnInterface.RecordsQuery,
199
+ messageParams: { filter: contextKeyFilter },
200
+ });
201
+ if (reply.status.code !== 200 || !((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length)) {
202
+ return undefined;
203
+ }
204
+ // Read the full record to get the data (auto-decrypted by processRequest)
205
+ const recordId = reply.entries[0].recordId;
206
+ const { reply: readReply } = yield processRequest({
207
+ author: requesterDid,
208
+ target: ownerDid,
209
+ messageType: DwnInterface.RecordsRead,
210
+ messageParams: { filter: { recordId } },
211
+ encryption: true,
212
+ });
213
+ const readResult = readReply;
214
+ if (!((_b = readResult.entry) === null || _b === void 0 ? void 0 : _b.data)) {
215
+ return undefined;
216
+ }
217
+ return parsePayload(yield DataStream.toBytes(readResult.entry.data));
218
+ }
219
+ else {
220
+ // Remote query: participant queries the context owner's DWN
221
+ const signer = yield getSigner(requesterDid);
222
+ const dwnEndpointUrls = yield getDwnServiceEndpointUrls(ownerDid, agent.did);
223
+ const recordsQuery = yield dwnMessageConstructors[DwnInterface.RecordsQuery].create({
224
+ signer,
225
+ filter: contextKeyFilter,
226
+ });
227
+ const queryReply = yield sendDwnRpcRequest({
228
+ targetDid: ownerDid,
229
+ dwnEndpointUrls,
230
+ message: recordsQuery.message,
231
+ });
232
+ if (queryReply.status.code !== 200 || !((_c = queryReply.entries) === null || _c === void 0 ? void 0 : _c.length)) {
233
+ return undefined;
234
+ }
235
+ // Read the full record remotely
236
+ const recordId = queryReply.entries[0].recordId;
237
+ const recordsRead = yield dwnMessageConstructors[DwnInterface.RecordsRead].create({
238
+ signer,
239
+ filter: { recordId },
240
+ });
241
+ const readReply = yield sendDwnRpcRequest({
242
+ targetDid: ownerDid,
243
+ dwnEndpointUrls,
244
+ message: recordsRead.message,
245
+ });
246
+ if (!((_d = readReply.entry) === null || _d === void 0 ? void 0 : _d.data) || !((_e = readReply.entry) === null || _e === void 0 ? void 0 : _e.recordsWrite)) {
247
+ return undefined;
248
+ }
249
+ // Decrypt the contextKey payload using the requester's key-delivery protocol path key
250
+ const keyDecrypter = yield getKeyDecrypter(agent, requesterDid);
251
+ const decryptedStream = yield Records.decrypt(readReply.entry.recordsWrite, keyDecrypter, readReply.entry.data);
252
+ return parsePayload(yield DataStream.toBytes(decryptedStream));
253
+ }
254
+ });
255
+ }
256
+ //# sourceMappingURL=dwn-key-delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dwn-key-delivery.js","sourceRoot":"","sources":["../../src/dwn-key-delivery.ts"],"names":[],"mappings":";;;;;;;;;AAeA,OAAO,EACL,0BAA0B,EAC1B,UAAU,EACV,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,OAAO,GACR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACrI,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AA6BtE;;;;;;;;;;GAUG;AACH,MAAM,UAAgB,yBAAyB,CAC7C,KAAwB,EACxB,SAAiB,EACjB,cAAgC,EAChC,qBAA+E,EAC/E,cAA4H,EAC5H,uBAAsD;;QAEtD,IAAI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AM,YAAY,GAAG,MAAM,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAChE,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,OAAO,CAC3C,SAAS,CAAC,KAAK,CAAC,YAAY,EAC5B,YAAY,EACZ,SAAS,CAAC,KAAK,CAAC,IAAkC,CACnD,CAAC;YAEF,OAAO,YAAY,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CAAA"}
@@ -0,0 +1,119 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Encoder, KeyDerivationScheme, Message, Records, } from '@enbox/dwn-sdk-js';
11
+ import { deriveContextEncryptionInput, getKeyDecrypter } from './dwn-encryption.js';
12
+ import { DwnInterface, dwnMessageConstructors } from './types/dwn.js';
13
+ /**
14
+ * Reactively upgrades an externally-authored root record that has only
15
+ * ProtocolPath encryption by appending a ProtocolContext recipient entry.
16
+ *
17
+ * After the upgrade, both the owner (ProtocolPath) and context key holders —
18
+ * including the external author (ProtocolContext) — can decrypt the record.
19
+ *
20
+ * Steps:
21
+ * 1. Decrypt the DEK using the owner's ProtocolPath-derived private key
22
+ * 2. Derive the context public key from the owner's #enc key
23
+ * 3. ECIES-encrypt the same DEK to the context public key
24
+ * 4. Append the ProtocolContext recipient entry (using PR 0b append mode)
25
+ * 5. Re-sign the record as owner
26
+ *
27
+ * @param agent - The platform agent
28
+ * @param tenantDid - The DWN owner's DID
29
+ * @param recordsWrite - The RecordsWrite message to upgrade
30
+ * @param dwn - The DWN instance
31
+ * @param getSigner - Function to get a DWN signer
32
+ * @param contextKeyCache - Cache for context key info
33
+ */
34
+ export function upgradeExternalRootRecord(agent, tenantDid, recordsWrite, dwn, getSigner, contextKeyCache) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const { encryption } = recordsWrite;
37
+ if (!encryption) {
38
+ return;
39
+ }
40
+ // Verify: has ProtocolPath but NOT ProtocolContext
41
+ const hasProtocolPath = encryption.recipients.some((r) => r.header.derivationScheme === KeyDerivationScheme.ProtocolPath);
42
+ const hasProtocolContext = encryption.recipients.some((r) => r.header.derivationScheme === KeyDerivationScheme.ProtocolContext);
43
+ if (!hasProtocolPath || hasProtocolContext) {
44
+ return;
45
+ }
46
+ // 1. Decrypt the DEK using the owner's ProtocolPath key
47
+ const keyDecrypter = yield getKeyDecrypter(agent, tenantDid);
48
+ // Find the ProtocolPath recipient entry
49
+ const pathRecipient = encryption.recipients.find((r) => r.header.derivationScheme === KeyDerivationScheme.ProtocolPath);
50
+ const fullDerivationPath = Records.constructKeyDerivationPathUsingProtocolPathScheme(recordsWrite.descriptor);
51
+ const dataEncryptionKey = yield keyDecrypter.decrypt(fullDerivationPath, {
52
+ encryptedKey: Encoder.base64UrlToBytes(pathRecipient.encrypted_key),
53
+ ephemeralPublicKey: pathRecipient.header.epk,
54
+ });
55
+ // 2. Derive the context public key — contextId = recordId for root records
56
+ const contextId = recordsWrite.recordId;
57
+ const encryptionIV = Encoder.base64UrlToBytes(encryption.iv);
58
+ // 3 & 4. Append the ProtocolContext recipient entry using append mode.
59
+ // Append mode preserves the author's identity and authorization so that
60
+ // signAsOwner() can be called in step 5.
61
+ const { encryptionInput: contextEncryptionInput, keyId, keyUri, contextDerivationPath } = yield deriveContextEncryptionInput(agent, tenantDid, contextId, dataEncryptionKey, encryptionIV);
62
+ // Set the authentication tag from the existing JWE encryption property
63
+ const fullContextInput = Object.assign(Object.assign({}, contextEncryptionInput), { authenticationTag: Encoder.base64UrlToBytes(encryption.tag) });
64
+ // Parse the message to get a RecordsWrite instance we can mutate
65
+ const recordsWriteInstance = yield dwnMessageConstructors[DwnInterface.RecordsWrite].parse(recordsWrite);
66
+ yield recordsWriteInstance.encryptSymmetricEncryptionKey(fullContextInput, { append: true });
67
+ // 5. Re-sign as owner — the author's signature is preserved but its
68
+ // encryptionCid is now stale; the owner's signature vouches for the
69
+ // updated encryption property.
70
+ const signer = yield getSigner(tenantDid);
71
+ yield recordsWriteInstance.signAsOwner(signer);
72
+ // Store the upgraded message directly via the message store, bypassing
73
+ // the handler's conflict resolution which doesn't support same-timestamp
74
+ // owner-augmented replacements. The data is unchanged — only the encryption
75
+ // metadata and authorization are updated.
76
+ //
77
+ // We must also update the state index and event stream to keep sync and
78
+ // real-time subscribers consistent — without this, the upgraded record
79
+ // would never propagate to remote DWNs or notify subscribers.
80
+ const { messageStore, stateIndex, eventStream } = dwn.storage;
81
+ // Validate the upgrade only changed encryption and authorization fields.
82
+ // The descriptor, recordId, contextId, and data must remain identical.
83
+ // Note: parse() may produce a new descriptor object, so we compare by value.
84
+ const upgradedMessage = recordsWriteInstance.message;
85
+ if (JSON.stringify(upgradedMessage.descriptor) !== JSON.stringify(recordsWrite.descriptor)) {
86
+ throw new Error('AgentDwnApi: upgradeExternalRootRecord() must not modify the descriptor.');
87
+ }
88
+ if (upgradedMessage.recordId !== recordsWrite.recordId) {
89
+ throw new Error('AgentDwnApi: upgradeExternalRootRecord() must not modify the recordId.');
90
+ }
91
+ // Fetch the stored original (which carries encodedData for small payloads)
92
+ const originalCid = yield Message.getCid(recordsWrite);
93
+ const storedOriginal = yield messageStore.get(tenantDid, originalCid);
94
+ // Build indexes for the upgraded message (mark as latest base state)
95
+ const isLatestBaseState = true;
96
+ const upgradedIndexes = yield recordsWriteInstance.constructIndexes(isLatestBaseState);
97
+ // Carry over the encoded data from the stored original (the handler
98
+ // base64url-encodes small payloads into encodedData during processMessage)
99
+ if (storedOriginal === null || storedOriginal === void 0 ? void 0 : storedOriginal.encodedData) {
100
+ upgradedMessage.encodedData = storedOriginal.encodedData;
101
+ }
102
+ // Use put-before-delete ordering: if a crash occurs after the put but
103
+ // before the delete, we end up with a duplicate (recoverable via the
104
+ // isLatestBaseState index) rather than data loss (unrecoverable).
105
+ const upgradedCid = yield Message.getCid(upgradedMessage);
106
+ yield messageStore.put(tenantDid, upgradedMessage, upgradedIndexes);
107
+ yield stateIndex.insert(tenantDid, upgradedCid, upgradedIndexes);
108
+ // Now remove the original message and its state index entry.
109
+ yield messageStore.delete(tenantDid, originalCid);
110
+ yield stateIndex.delete(tenantDid, [originalCid]);
111
+ // Notify real-time subscribers (mirrors handler behavior)
112
+ if (eventStream !== undefined) {
113
+ eventStream.emit(tenantDid, { message: upgradedMessage }, upgradedIndexes);
114
+ }
115
+ // Cache context key info for subsequent writes in this context
116
+ contextKeyCache.set(contextId, { keyId, keyUri, contextDerivationPath });
117
+ });
118
+ }
119
+ //# sourceMappingURL=dwn-record-upgrade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dwn-record-upgrade.js","sourceRoot":"","sources":["../../src/dwn-record-upgrade.ts"],"names":[],"mappings":";;;;;;;;;AAYA,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO,GACR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAgB,yBAAyB,CAC7C,KAAwB,EACxB,SAAiB,EACjB,YAAiC,EACjC,GAAQ,EACR,SAAiD,EACjD,eAA6H;;QAE7H,MAAM,EAAE,UAAU,EAAE,GAAG,YAAY,CAAC;QACpC,IAAI,CAAC,UAAU,EAAE,CAAC;YAAC,OAAO;QAAC,CAAC;QAE5B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+1,23 @@
1
+ import { DwnInterfaceName } from '@enbox/dwn-sdk-js';
2
+ import { DwnInterface } from './types/dwn.js';
3
+ export function isDwnRequest(dwnRequest, messageType) {
4
+ return dwnRequest.messageType === messageType;
5
+ }
6
+ export function isDwnMessage(messageType, message) {
7
+ const incomingMessageInterfaceName = message.descriptor.interface + message.descriptor.method;
8
+ return incomingMessageInterfaceName === messageType;
9
+ }
10
+ export function isRecordsType(messageType) {
11
+ return messageType === DwnInterface.RecordsDelete ||
12
+ messageType === DwnInterface.RecordsQuery ||
13
+ messageType === DwnInterface.RecordsRead ||
14
+ messageType === DwnInterface.RecordsSubscribe ||
15
+ messageType === DwnInterface.RecordsWrite;
16
+ }
17
+ export function isRecordPermissionScope(scope) {
18
+ return scope.interface === DwnInterfaceName.Records;
19
+ }
20
+ export function isMessagesPermissionScope(scope) {
21
+ return scope.interface === DwnInterfaceName.Messages;
22
+ }
23
+ //# sourceMappingURL=dwn-type-guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dwn-type-guards.js","sourceRoot":"","sources":["../../src/dwn-type-guards.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,YAAY,CAC1B,UAA2C,EAAE,WAAc;IAE3D,OAAO,UAAU,CAAC,WAAW,KAAK,WAAW,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,WAAc,EAAE,OAAuB;IAEvC,MAAM,4BAA4B,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC;IAC9F,OAAO,4BAA4B,KAAK,WAAW,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAAyB;IACrD,OAAO,WAAW,KAAK,YAAY,CAAC,aAAa;QAC/C,WAAW,KAAK,YAAY,CAAC,YAAY;QACzC,WAAW,KAAK,YAAY,CAAC,WAAW;QACxC,WAAW,KAAK,YAAY,CAAC,gBAAgB;QAC7C,WAAW,KAAK,YAAY,CAAC,YAAY,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAyB;IAC/D,OAAO,KAAK,CAAC,SAAS,KAAK,gBAAgB,CAAC,OAAO,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAyB;IACjE,OAAO,KAAK,CAAC,SAAS,KAAK,gBAAgB,CAAC,QAAQ,CAAC;AACvD,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  export * from './types/dwn.js';
2
2
  export * from './agent-did-resolver-cache.js';
3
+ export * from './anonymous-dwn-api.js';
3
4
  export * from './bearer-identity.js';
4
5
  export * from './crypto-api.js';
5
6
  export * from './did-api.js';
6
7
  export * from './dwn-api.js';
8
+ export * from './dwn-encryption.js';
9
+ export * from './dwn-key-delivery.js';
10
+ export * from './dwn-record-upgrade.js';
11
+ export * from './dwn-type-guards.js';
12
+ export * from './protocol-utils.js';
7
13
  export * from './hd-identity-vault.js';
8
14
  export * from './identity-api.js';
9
15
  export * from './local-key-manager.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAQ/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAQ/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Navigates a protocol definition's structure to find the rule set at a given protocol path.
3
+ * @param protocolDefinition - The protocol definition to search
4
+ * @param protocolPath - The dot-separated protocol path (e.g. 'thread/message')
5
+ * @returns The rule set at the given path, or undefined if the path doesn't exist
6
+ */
7
+ export function getRuleSetAtPath(protocolDefinition, protocolPath) {
8
+ const segments = protocolPath.split('/');
9
+ let ruleSet = protocolDefinition.structure;
10
+ for (const segment of segments) {
11
+ ruleSet = ruleSet[segment];
12
+ if (!ruleSet) {
13
+ return undefined;
14
+ }
15
+ }
16
+ return ruleSet;
17
+ }
18
+ /**
19
+ * Extracts the root context ID from a contextId or parentContextId.
20
+ * e.g. 'abc/def/ghi' -> 'abc', 'abc' -> 'abc'
21
+ * @param contextId - The context ID to extract the root from
22
+ * @returns The root context ID
23
+ */
24
+ export function getRootContextId(contextId) {
25
+ return contextId.split('/')[0] || contextId;
26
+ }
27
+ /**
28
+ * Checks if a protocol path represents a multi-party context.
29
+ * Returns true if the root path's subtree contains $role descendants
30
+ * or relational who/of $actions rules that grant read access.
31
+ *
32
+ * @param protocolDefinition - The full protocol definition
33
+ * @param rootProtocolPath - The root protocol path to check
34
+ * @returns true if the protocol path represents a multi-party context
35
+ */
36
+ export function isMultiPartyContext(protocolDefinition, rootProtocolPath) {
37
+ const ruleSet = getRuleSetAtPath(protocolDefinition, rootProtocolPath);
38
+ if (!ruleSet) {
39
+ return false;
40
+ }
41
+ // (a) Check for $role descendants in the subtree
42
+ function hasRoleRecursive(rs) {
43
+ for (const key in rs) {
44
+ if (!key.startsWith('$')) {
45
+ const child = rs[key];
46
+ if (child.$role === true) {
47
+ return true;
48
+ }
49
+ if (hasRoleRecursive(child)) {
50
+ return true;
51
+ }
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ if (hasRoleRecursive(ruleSet)) {
57
+ return true;
58
+ }
59
+ // (b) Check for relational who/of read rules anywhere in the protocol
60
+ // that reference a path within this subtree. A rule like
61
+ // { who: 'recipient', of: 'email', can: ['read'] } on any record
62
+ // type means the email recipient needs a context key.
63
+ return hasRelationalReadAccess(undefined, rootProtocolPath, protocolDefinition);
64
+ }
65
+ /**
66
+ * Checks whether any relational who/of rule in the protocol grants
67
+ * read access for a given actor type and ancestor path.
68
+ *
69
+ * Walks the *entire* protocol structure looking for any $actions rule that:
70
+ * - Has `who` equal to `actorType` ('recipient' or 'author'), or any actor
71
+ * type if `actorType` is `undefined`
72
+ * - Has `of` equal to `ofPath`
73
+ * - Has `can` including 'read'
74
+ *
75
+ * @param actorType - 'author' | 'recipient', or undefined for any
76
+ * @param ofPath - The protocol path to check (e.g. 'thread', 'email')
77
+ * @param protocolDefinition - The full protocol definition
78
+ * @returns true if a matching relational read rule exists
79
+ */
80
+ export function hasRelationalReadAccess(actorType, ofPath, protocolDefinition) {
81
+ const structure = protocolDefinition.structure;
82
+ function walkRuleSet(rs) {
83
+ var _a;
84
+ // Check $actions on this node
85
+ if (rs.$actions) {
86
+ for (const rule of rs.$actions) {
87
+ if (rule.who &&
88
+ rule.who !== 'anyone' &&
89
+ (actorType === undefined || rule.who === actorType) &&
90
+ rule.of === ofPath &&
91
+ ((_a = rule.can) === null || _a === void 0 ? void 0 : _a.includes('read'))) {
92
+ return true;
93
+ }
94
+ }
95
+ }
96
+ // Recurse into child record types
97
+ for (const key in rs) {
98
+ if (!key.startsWith('$')) {
99
+ if (walkRuleSet(rs[key])) {
100
+ return true;
101
+ }
102
+ }
103
+ }
104
+ return false;
105
+ }
106
+ return walkRuleSet(structure);
107
+ }
108
+ /**
109
+ * Analyses a record write to determine which DIDs need context key delivery.
110
+ *
111
+ * Returns a set of participant DIDs that should receive `contextKey` records.
112
+ * The DWN owner (tenantDid) is always excluded — they have ProtocolPath access.
113
+ *
114
+ * Cases handled:
115
+ * 1. `$role` record with a recipient -> recipient is a participant
116
+ * 2. Record has a recipient and a relational read rule grants access
117
+ * via `{ who: 'recipient', of: '<path>', can: ['read'] }`
118
+ * 3. Record is authored by an external party -> if `{ who: 'author', of:
119
+ * '<path>', can: ['read'] }` rules grant read access, the author needs
120
+ * a context key.
121
+ *
122
+ * @param params.protocolDefinition - The installed protocol definition
123
+ * @param params.protocolPath - The written record's protocol path
124
+ * @param params.recipient - Recipient DID from the record, if any
125
+ * @param params.tenantDid - The DWN owner's DID (excluded from results)
126
+ * @param params.authorDid - Author DID if externally authored, undefined otherwise
127
+ * @returns Set of DIDs that need context key delivery
128
+ */
129
+ export function detectNewParticipants({ protocolDefinition, protocolPath, recipient, tenantDid, authorDid }) {
130
+ const participants = new Set();
131
+ // Navigate to the rule set at the given protocol path
132
+ const ruleSet = getRuleSetAtPath(protocolDefinition, protocolPath);
133
+ if (!ruleSet) {
134
+ return participants;
135
+ }
136
+ // Case 1: $role record -> recipient is a participant
137
+ if (ruleSet.$role === true && recipient) {
138
+ participants.add(recipient);
139
+ }
140
+ // Case 2: Record has a recipient -> check if relational read rules exist
141
+ if (recipient && recipient !== tenantDid) {
142
+ if (hasRelationalReadAccess('recipient', protocolPath, protocolDefinition)) {
143
+ participants.add(recipient);
144
+ }
145
+ }
146
+ // Case 3: External author -> check if author-based relational read rules exist.
147
+ // If `{ who: 'author', of: '<path>', can: ['read'] }` is defined anywhere
148
+ // in the protocol, the external author needs a context key to decrypt.
149
+ if (authorDid && authorDid !== tenantDid) {
150
+ if (hasRelationalReadAccess('author', protocolPath, protocolDefinition)) {
151
+ participants.add(authorDid);
152
+ }
153
+ }
154
+ // Remove the DWN owner — they always have ProtocolPath access
155
+ participants.delete(tenantDid);
156
+ return participants;
157
+ }
158
+ //# sourceMappingURL=protocol-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-utils.js","sourceRoot":"","sources":["../../src/protocol-utils.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,kBAAsC,EACtC,YAAoB;IAEpB,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,OAAO,GACT,kBAAkB,CAAC,SAAuC,CAAC;IAC7D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAgC,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;YAAC,OAAO,SAAS,CAAC;QAAC,CAAC;IACrC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBA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AC9B,CAAC;IAED,yEAAyE;IACzE,IAAI,SAAS,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QACzC,IAAI,uBAAuB,CAAC,WAAW,EAAE,YAAY,EAAE,kBAAkB,CAAC,EAAE,CAAC;YAC3E,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,gFAAgF;IAChF,0EAA0E;IAC1E,uEAAuE;IACvE,IAAI,SAAS,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QACzC,IAAI,uBAAuB,CAAC,QAAQ,EAAE,YAAY,EAAE,kBAAkB,CAAC,EAAE,CAAC;YACxE,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,8DAA8D;IAC9D,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAE/B,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -21,7 +21,7 @@ export const IdentityProtocolDefinition = {
21
21
  }
22
22
  };
23
23
  export const KeyDeliveryProtocolDefinition = {
24
- protocol: 'https://enbox.org/protocols/key-delivery',
24
+ protocol: 'https://identity.foundation/protocols/key-delivery',
25
25
  published: false,
26
26
  types: {
27
27
  contextKey: {
@@ -1 +1 @@
1
- {"version":3,"file":"store-data-protocols.js","sourceRoot":"","sources":["../../src/store-data-protocols.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAAuB;IAC5D,QAAQ,EAAI,0DAA0D;IACtE,SAAS,EAAG,KAAK;IACjB,KAAK,EAAO;QACV,WAAW,EAAE;YACX,MAAM,EAAQ,uDAAuD;YACrE,WAAW,EAAG;gBACZ,kBAAkB;aACnB;SACF;QACD,gBAAgB,EAAE;YAChB,MAAM,EAAQ,4DAA4D;YAC1E,WAAW,EAAG;gBACZ,kBAAkB;aACnB;SACF;KACF;IACD,SAAS,EAAE;QACT,WAAW,EAAQ,EAAE;QACrB,gBAAgB,EAAG,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAuB;IAC/D,QAAQ,EAAI,0CAA0C;IACtD,SAAS,EAAG,KAAK;IACjB,KAAK,EAAO;QACV,UAAU,EAAE;YACV,WAAW,EAAE,CAAC,kBAAkB,CAAC;SAClC;KACF;IACD,SAAS,EAAE;QACT,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE;aACtD;YACD,KAAK,EAAE;gBACL,aAAa,EAAS,CAAC,UAAU,EAAE,WAAW,CAAC;gBAC/C,mBAAmB,EAAG,KAAK;gBAC3B,QAAQ,EAAc,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACxC,SAAS,EAAa,EAAE,IAAI,EAAE,QAAQ,EAAE;aACzC;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAuB;IACvD,QAAQ,EAAI,qDAAqD;IACjE,SAAS,EAAG,KAAK;IACjB,KAAK,EAAO;QACV,UAAU,EAAE;YACV,MAAM,EAAe,sDAAsD;YAC3E,WAAW,EAAU,CAAC,kBAAkB,CAAC;YACzC,kBAAkB,EAAG,IAAI;SAC1B;KACF;IACD,SAAS,EAAE;QACT,UAAU,EAAE,EAAE;KACf;CACF,CAAC"}
1
+ {"version":3,"file":"store-data-protocols.js","sourceRoot":"","sources":["../../src/store-data-protocols.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAAuB;IAC5D,QAAQ,EAAI,0DAA0D;IACtE,SAAS,EAAG,KAAK;IACjB,KAAK,EAAO;QACV,WAAW,EAAE;YACX,MAAM,EAAQ,uDAAuD;YACrE,WAAW,EAAG;gBACZ,kBAAkB;aACnB;SACF;QACD,gBAAgB,EAAE;YAChB,MAAM,EAAQ,4DAA4D;YAC1E,WAAW,EAAG;gBACZ,kBAAkB;aACnB;SACF;KACF;IACD,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