@enbox/dwn-sdk-js 0.3.8 → 0.4.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 (79) hide show
  1. package/dist/browser.mjs +11 -11
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +175 -512
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/dwn-error.js +1 -3
  6. package/dist/esm/src/core/dwn-error.js.map +1 -1
  7. package/dist/esm/src/core/messages-grant-authorization.js +1 -17
  8. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  9. package/dist/esm/src/core/protocol-authorization-validation.js +1 -1
  10. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
  11. package/dist/esm/src/core/replication-apply.js +200 -0
  12. package/dist/esm/src/core/replication-apply.js.map +1 -0
  13. package/dist/esm/src/dwn.js +212 -0
  14. package/dist/esm/src/dwn.js.map +1 -1
  15. package/dist/esm/src/handlers/messages-sync.js +66 -369
  16. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  17. package/dist/esm/src/handlers/records-write.js +18 -12
  18. package/dist/esm/src/handlers/records-write.js.map +1 -1
  19. package/dist/esm/src/index.js +1 -1
  20. package/dist/esm/src/index.js.map +1 -1
  21. package/dist/esm/src/interfaces/messages-sync.js +0 -11
  22. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  23. package/dist/esm/tests/core/replication-apply.spec.js +220 -0
  24. package/dist/esm/tests/core/replication-apply.spec.js.map +1 -0
  25. package/dist/esm/tests/dwn.spec.js +139 -2
  26. package/dist/esm/tests/dwn.spec.js.map +1 -1
  27. package/dist/esm/tests/features/records-record-limit.spec.js +14 -0
  28. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
  29. package/dist/esm/tests/handlers/messages-sync.spec.js +1 -684
  30. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  31. package/dist/esm/tests/handlers/records-write.spec.js +43 -2
  32. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  33. package/dist/esm/tests/test-suite.js +0 -2
  34. package/dist/esm/tests/test-suite.js.map +1 -1
  35. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  36. package/dist/types/src/core/dwn-error.d.ts +1 -3
  37. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  38. package/dist/types/src/core/messages-grant-authorization.d.ts +0 -1
  39. package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
  40. package/dist/types/src/core/replication-apply.d.ts +93 -0
  41. package/dist/types/src/core/replication-apply.d.ts.map +1 -0
  42. package/dist/types/src/dwn.d.ts +22 -1
  43. package/dist/types/src/dwn.d.ts.map +1 -1
  44. package/dist/types/src/handlers/messages-sync.d.ts +10 -54
  45. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  46. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  47. package/dist/types/src/index.d.ts +3 -3
  48. package/dist/types/src/index.d.ts.map +1 -1
  49. package/dist/types/src/interfaces/messages-sync.d.ts +0 -3
  50. package/dist/types/src/interfaces/messages-sync.d.ts.map +1 -1
  51. package/dist/types/src/types/messages-types.d.ts +0 -18
  52. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  53. package/dist/types/tests/core/replication-apply.spec.d.ts +2 -0
  54. package/dist/types/tests/core/replication-apply.spec.d.ts.map +1 -0
  55. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  56. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -1
  57. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  58. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  59. package/dist/types/tests/test-suite.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/core/dwn-error.ts +1 -3
  62. package/src/core/messages-grant-authorization.ts +1 -31
  63. package/src/core/protocol-authorization-validation.ts +2 -2
  64. package/src/core/replication-apply.ts +272 -0
  65. package/src/dwn.ts +296 -2
  66. package/src/handlers/messages-sync.ts +92 -585
  67. package/src/handlers/records-write.ts +18 -13
  68. package/src/index.ts +3 -4
  69. package/src/interfaces/messages-sync.ts +8 -25
  70. package/src/types/messages-types.ts +0 -20
  71. package/dist/esm/src/sync/records-projection.js +0 -228
  72. package/dist/esm/src/sync/records-projection.js.map +0 -1
  73. package/dist/esm/tests/sync/records-projection.spec.js +0 -245
  74. package/dist/esm/tests/sync/records-projection.spec.js.map +0 -1
  75. package/dist/types/src/sync/records-projection.d.ts +0 -98
  76. package/dist/types/src/sync/records-projection.d.ts.map +0 -1
  77. package/dist/types/tests/sync/records-projection.spec.d.ts +0 -2
  78. package/dist/types/tests/sync/records-projection.spec.d.ts.map +0 -1
  79. package/src/sync/records-projection.ts +0 -328
@@ -1 +1 @@
1
- {"version":3,"file":"dwn.js","sourceRoot":"","sources":["../../../src/dwn.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EA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UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,MAAM,2BAA2B,CAAC;YACzE,OAAO;gBACL,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE;aAC9B,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,wBAAwB,CACnC,UAAe;QAEf,8BAA8B;QAC9B,MAAM,YAAY,GAAG,UAAU,EAAE,UAAU,EAAE,SAAS,CAAC;QACvD,MAAM,SAAS,GAAG,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC;QAEjD,IAAI,YAAY,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1D,OAAO;gBACL,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,yDAAyD,YAAY,aAAa,SAAS,EAAE,EAAE;aAC7H,CAAC;QACJ,CAAC;QAED,6BAA6B;QAC7B,IAAI,CAAC;YACH,oDAAoD;YACpD,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;CACF;AAAA,CAAC;AAQD,CAAC"}
@@ -7,21 +7,15 @@ import { messageReplyFromError } from '../core/message-reply.js';
7
7
  import { MessagesGrantAuthorization } from '../core/messages-grant-authorization.js';
8
8
  import { MessagesSync } from '../interfaces/messages-sync.js';
9
9
  import { Records } from '../utils/records.js';
10
- import { RecordsProjection } from '../sync/records-projection.js';
11
- import { RecordsWrite } from '../interfaces/records-write.js';
12
- import { SortDirection } from '../types/query-types.js';
13
10
  import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
14
- import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
15
11
  /**
16
- * Maximum inline data size for diff responses aligned with the
17
- * {@link DwnConstant.maxDataSizeAllowedToBeEncoded} threshold (30 KB).
18
- * RecordsWrite data payloads smaller than this are base64url-encoded and
19
- * included directly in the diff reply. Larger payloads must be fetched
20
- * separately via MessagesRead.
12
+ * Maximum inline data size for diff responses, aligned with the
13
+ * {@link DwnConstant.maxDataSizeAllowedToBeEncoded} threshold.
21
14
  */
22
15
  const DEFAULT_MAX_INLINE_DATA_SIZE = DwnConstant.maxDataSizeAllowedToBeEncoded;
23
16
  export class MessagesSyncHandler {
24
17
  deps;
18
+ _defaultHashHexCache;
25
19
  constructor(deps) {
26
20
  this.deps = deps;
27
21
  }
@@ -40,190 +34,120 @@ export class MessagesSyncHandler {
40
34
  catch (e) {
41
35
  return messageReplyFromError(e, 401);
42
36
  }
43
- const { action } = message.descriptor;
44
- const projectionScopes = MessagesSyncHandler.getProjectionScopes(message);
45
37
  try {
46
- switch (action) {
47
- case 'root': {
48
- return await this.handleRoot(tenant, message, projectionScopes);
49
- }
50
- case 'subtree': {
51
- return await this.handleSubtree(tenant, message, projectionScopes);
52
- }
53
- case 'leaves': {
54
- return await this.handleLeaves(tenant, message, projectionScopes);
55
- }
56
- case 'diff': {
38
+ switch (message.descriptor.action) {
39
+ case 'root':
40
+ return await this.handleRoot(tenant, message);
41
+ case 'subtree':
42
+ return await this.handleSubtree(tenant, message);
43
+ case 'leaves':
44
+ return await this.handleLeaves(tenant, message);
45
+ case 'diff':
57
46
  return await this.handleDiff(tenant, message);
58
- }
59
- default: {
47
+ default:
60
48
  return {
61
- status: { code: 400, detail: `Unknown action: ${action}` },
49
+ status: { code: 400, detail: `Unknown action: ${message.descriptor.action}` },
62
50
  };
63
- }
64
51
  }
65
52
  }
66
53
  catch (e) {
67
54
  return messageReplyFromError(e, 500);
68
55
  }
69
56
  }
70
- async handleRoot(tenant, message, projectionScopes) {
71
- const root = await this.getRootHex(tenant, message.descriptor.protocol, projectionScopes);
57
+ async handleRoot(tenant, message) {
58
+ const root = hashToHex(await this.getIndexedRootHash(tenant, message.descriptor.protocol));
72
59
  return {
73
60
  status: { code: 200, detail: 'OK' },
74
- root: root,
61
+ root,
75
62
  };
76
63
  }
77
- async getRootHex(tenant, protocol, projectionScopes) {
78
- if (projectionScopes === undefined) {
79
- const rootHash = await this.getIndexedRootHash(tenant, protocol);
80
- return hashToHex(rootHash);
81
- }
82
- return this.withProjectionSnapshot(tenant, projectionScopes, snapshot => snapshot.getRootHex());
83
- }
84
- async getIndexedRootHash(tenant, protocol) {
85
- if (protocol === undefined) {
86
- return this.deps.stateIndex.getRoot(tenant);
87
- }
88
- return this.deps.stateIndex.getProtocolRoot(tenant, protocol);
89
- }
90
- async handleSubtree(tenant, message, projectionScopes) {
64
+ async handleSubtree(tenant, message) {
91
65
  const bitPath = MessagesSyncHandler.parseBitPrefix(message.descriptor.prefix);
92
- const hash = await this.getSubtreeHash(tenant, message.descriptor.protocol, projectionScopes, bitPath);
66
+ const hash = await MessagesSyncHandler.getIndexedSubtreeHash(this.deps.stateIndex, tenant, message.descriptor.protocol, bitPath);
93
67
  return {
94
68
  status: { code: 200, detail: 'OK' },
95
69
  hash: hashToHex(hash),
96
70
  };
97
71
  }
98
- async handleLeaves(tenant, message, projectionScopes) {
72
+ async handleLeaves(tenant, message) {
99
73
  const bitPath = MessagesSyncHandler.parseBitPrefix(message.descriptor.prefix);
100
- const leaves = await this.getLeaves(tenant, message.descriptor.protocol, projectionScopes, bitPath);
74
+ const leaves = await MessagesSyncHandler.getIndexedLeaves(this.deps.stateIndex, tenant, message.descriptor.protocol, bitPath);
101
75
  return {
102
76
  status: { code: 200, detail: 'OK' },
103
77
  entries: leaves,
104
78
  };
105
79
  }
106
- async getSubtreeHash(tenant, protocol, projectionScopes, bitPath) {
107
- if (projectionScopes === undefined) {
108
- return this.getIndexedSubtreeHash(tenant, protocol, bitPath);
109
- }
110
- return this.withProjectionSnapshot(tenant, projectionScopes, snapshot => snapshot.getSubtreeHash(bitPath));
111
- }
112
- async getLeaves(tenant, protocol, projectionScopes, bitPath) {
113
- if (projectionScopes === undefined) {
114
- return this.getIndexedLeaves(tenant, protocol, bitPath);
115
- }
116
- return this.withProjectionSnapshot(tenant, projectionScopes, snapshot => snapshot.getLeaves(bitPath));
117
- }
118
- async getIndexedSubtreeHash(tenant, protocol, bitPath) {
119
- return MessagesSyncHandler.getIndexedSubtreeHashFromStateIndex(this.deps.stateIndex, tenant, protocol, bitPath);
120
- }
121
- async getIndexedLeaves(tenant, protocol, bitPath) {
122
- return MessagesSyncHandler.getIndexedLeavesFromStateIndex(this.deps.stateIndex, tenant, protocol, bitPath);
123
- }
124
80
  /**
125
- * Handle the 'diff' action: the client sends its subtree hashes at a given
126
- * depth, and the server compares them against its own tree to compute the
127
- * set difference in a single round-trip.
128
- *
129
- * Response includes:
130
- * - `onlyRemote`: messages the server has that the client doesn't, with
131
- * inline data for small payloads.
132
- * - `onlyLocal`: bit prefixes where the client has entries the server
133
- * doesn't (client can enumerate its own leaves for these prefixes).
81
+ * Computes a single-round diff between the client's sparse Merkle tree view
82
+ * and this DWN's full/protocol StateIndex tree.
134
83
  */
135
84
  async handleDiff(tenant, message) {
136
85
  const { protocol, hashes: clientHashes, depth } = message.descriptor;
137
- const projectionScopes = MessagesSyncHandler.getProjectionScopes(message);
138
86
  if (!clientHashes || depth === undefined) {
139
87
  return {
140
88
  status: { code: 400, detail: 'diff action requires hashes and depth' },
141
89
  };
142
90
  }
143
- const stateIndex = this.deps.stateIndex;
144
- const projectionSnapshot = await this.createProjectionSnapshot(tenant, projectionScopes);
145
91
  const onlyRemoteCids = [];
146
92
  const onlyLocalPrefixes = [];
147
- try {
148
- // Get the default (empty subtree) hash at the given depth so we can
149
- // filter out client entries that represent empty subtrees.
150
- const defaultHashHex = await this.getDefaultHashHex(depth);
151
- // Build the set of all prefixes at the given depth that either side has.
152
- // Filter out client prefixes whose hash equals the default (empty subtree)
153
- // hash — these represent empty subtrees and should be treated the same as
154
- // omitted prefixes.
155
- const allPrefixes = new Set();
156
- for (const [pfx, hash] of Object.entries(clientHashes)) {
157
- if (hash !== defaultHashHex) {
158
- allPrefixes.add(pfx);
159
- }
160
- }
161
- // Enumerate server-side non-empty prefixes by walking the server's
162
- // tree to the given depth and collecting leaf prefixes.
163
- const serverHashes = await this.collectSubtreeHashes(tenant, protocol, projectionSnapshot, depth);
164
- for (const prefix of Object.keys(serverHashes)) {
93
+ const defaultHashHex = await this.getDefaultHashHex(depth);
94
+ const allPrefixes = new Set();
95
+ for (const [prefix, hash] of Object.entries(clientHashes)) {
96
+ if (hash !== defaultHashHex) {
165
97
  allPrefixes.add(prefix);
166
98
  }
167
- // Compare each prefix's hash between client and server.
168
- for (const pfx of allPrefixes) {
169
- const clientHash = clientHashes[pfx]; // undefined if client has empty subtree
170
- const serverHash = serverHashes[pfx]; // undefined if server has empty subtree
171
- if (clientHash === serverHash) {
172
- // Identical subtree — skip.
173
- continue;
174
- }
175
- if (serverHash === undefined) {
176
- // Client has entries the server doesn't.
177
- onlyLocalPrefixes.push(pfx);
178
- continue;
179
- }
180
- const bitPath = MessagesSyncHandler.parseBitPrefix(pfx);
181
- const serverLeaves = await MessagesSyncHandler.getServerLeaves(stateIndex, tenant, protocol, projectionSnapshot, bitPath);
182
- onlyRemoteCids.push(...serverLeaves);
183
- if (clientHash !== undefined) {
184
- // Both sides have entries but they differ. The client will enumerate
185
- // its own leaves for this prefix and de-duplicate server leaves.
186
- onlyLocalPrefixes.push(pfx);
187
- }
188
- }
189
99
  }
190
- finally {
191
- await projectionSnapshot?.close();
100
+ const serverHashes = await this.collectSubtreeHashes(tenant, protocol, depth);
101
+ for (const prefix of Object.keys(serverHashes)) {
102
+ allPrefixes.add(prefix);
103
+ }
104
+ for (const prefix of allPrefixes) {
105
+ const clientHash = clientHashes[prefix];
106
+ const serverHash = serverHashes[prefix];
107
+ if (clientHash === serverHash) {
108
+ continue;
109
+ }
110
+ if (serverHash === undefined) {
111
+ onlyLocalPrefixes.push(prefix);
112
+ continue;
113
+ }
114
+ const bitPath = MessagesSyncHandler.parseBitPrefix(prefix);
115
+ const serverLeaves = await MessagesSyncHandler.getIndexedLeaves(this.deps.stateIndex, tenant, protocol, bitPath);
116
+ onlyRemoteCids.push(...serverLeaves);
117
+ if (clientHash !== undefined) {
118
+ onlyLocalPrefixes.push(prefix);
119
+ }
192
120
  }
193
- // Build response entries with inline message data where possible.
194
- const onlyRemote = await this.buildDiffEntries(tenant, onlyRemoteCids);
195
- const dependencies = projectionScopes === undefined
196
- ? []
197
- : await this.buildProjectedDependencyEntries(tenant, onlyRemote);
198
121
  return {
199
122
  status: { code: 200, detail: 'OK' },
200
- onlyRemote,
123
+ onlyRemote: await this.buildDiffEntries(tenant, onlyRemoteCids),
201
124
  onlyLocal: onlyLocalPrefixes,
202
- ...(dependencies.length > 0 ? { dependencies } : {}),
203
125
  };
204
126
  }
127
+ async getIndexedRootHash(tenant, protocol) {
128
+ if (protocol === undefined) {
129
+ return this.deps.stateIndex.getRoot(tenant);
130
+ }
131
+ return this.deps.stateIndex.getProtocolRoot(tenant, protocol);
132
+ }
205
133
  /**
206
- * Walk the server's SMT to the given depth and collect all non-empty
207
- * subtree hashes as a `{ prefix: hexHash }` map.
134
+ * Walks this DWN's StateIndex tree to the requested depth and returns only
135
+ * non-empty subtree hashes keyed by bit prefix.
208
136
  */
209
- async collectSubtreeHashes(tenant, protocol, projectionSnapshot, depth) {
210
- const stateIndex = this.deps.stateIndex;
137
+ async collectSubtreeHashes(tenant, protocol, depth) {
211
138
  const result = {};
212
139
  const walk = async (prefix, currentDepth) => {
213
140
  const bitPath = MessagesSyncHandler.parseBitPrefix(prefix);
214
- const hash = await MessagesSyncHandler.getServerSubtreeHash(stateIndex, tenant, protocol, projectionSnapshot, bitPath);
141
+ const hash = await MessagesSyncHandler.getIndexedSubtreeHash(this.deps.stateIndex, tenant, protocol, bitPath);
215
142
  const hexHash = hashToHex(hash);
216
143
  const defaultHashHex = await this.getDefaultHashHex(currentDepth);
217
144
  if (hexHash === defaultHashHex) {
218
- // Empty subtree — don't include in the result.
219
145
  return;
220
146
  }
221
147
  if (currentDepth >= depth) {
222
- // Reached target depth with a non-empty subtree.
223
148
  result[prefix] = hexHash;
224
149
  return;
225
150
  }
226
- // Recurse into children.
227
151
  await Promise.all([
228
152
  walk(prefix + '0', currentDepth + 1),
229
153
  walk(prefix + '1', currentDepth + 1),
@@ -232,44 +156,18 @@ export class MessagesSyncHandler {
232
156
  await walk('', 0);
233
157
  return result;
234
158
  }
235
- async createProjectionSnapshot(tenant, projectionScopes) {
236
- if (projectionScopes === undefined) {
237
- return undefined;
238
- }
239
- return RecordsProjection.createSnapshot({
240
- tenant,
241
- messageStore: this.deps.messageStore,
242
- scopes: projectionScopes,
243
- });
244
- }
245
- static async getServerLeaves(stateIndex, tenant, protocol, projectionSnapshot, bitPath) {
246
- if (projectionSnapshot === undefined) {
247
- return MessagesSyncHandler.getIndexedLeavesFromStateIndex(stateIndex, tenant, protocol, bitPath);
248
- }
249
- return projectionSnapshot.getLeaves(bitPath);
250
- }
251
- static async getServerSubtreeHash(stateIndex, tenant, protocol, projectionSnapshot, bitPath) {
252
- if (projectionSnapshot === undefined) {
253
- return MessagesSyncHandler.getIndexedSubtreeHashFromStateIndex(stateIndex, tenant, protocol, bitPath);
254
- }
255
- return projectionSnapshot.getSubtreeHash(bitPath);
256
- }
257
- static async getIndexedLeavesFromStateIndex(stateIndex, tenant, protocol, bitPath) {
159
+ static async getIndexedLeaves(stateIndex, tenant, protocol, bitPath) {
258
160
  if (protocol === undefined) {
259
161
  return stateIndex.getLeaves(tenant, bitPath);
260
162
  }
261
163
  return stateIndex.getProtocolLeaves(tenant, protocol, bitPath);
262
164
  }
263
- static async getIndexedSubtreeHashFromStateIndex(stateIndex, tenant, protocol, bitPath) {
165
+ static async getIndexedSubtreeHash(stateIndex, tenant, protocol, bitPath) {
264
166
  if (protocol === undefined) {
265
167
  return stateIndex.getSubtreeHash(tenant, bitPath);
266
168
  }
267
169
  return stateIndex.getProtocolSubtreeHash(tenant, protocol, bitPath);
268
170
  }
269
- /**
270
- * Get the hex-encoded default hash for a given depth. Lazily cached.
271
- */
272
- _defaultHashHexCache;
273
171
  async getDefaultHashHex(depth) {
274
172
  if (this._defaultHashHexCache === undefined) {
275
173
  const { initDefaultHashes } = await import('../smt/smt-utils.js');
@@ -282,220 +180,46 @@ export class MessagesSyncHandler {
282
180
  return this._defaultHashHexCache.get(depth) ?? '';
283
181
  }
284
182
  /**
285
- * Build diff response entries for the given messageCids.
286
- * Reads each message from the MessageStore and, for small RecordsWrite
287
- * payloads, inlines the data as base64url.
183
+ * Builds diff entries and inlines data when it is small enough for the
184
+ * MessagesSync response. Large record data remains fetch-by-CID.
288
185
  */
289
186
  async buildDiffEntries(tenant, messageCids) {
290
187
  const entries = [];
291
188
  for (const messageCid of messageCids) {
292
189
  const { message, encodedData: inlineData, data } = await this.readMessageByCid(tenant, messageCid);
293
190
  if (!message) {
294
- // Message was deleted between diff computation and read — skip.
295
191
  continue;
296
192
  }
297
193
  const entry = { messageCid, message };
298
- // Use inline data from the MessageStore if available (small payloads).
299
194
  if (inlineData) {
300
195
  entry.encodedData = inlineData;
301
196
  }
302
197
  else if (data) {
303
- // Data is in the DataStore — inline it if small enough.
304
198
  const bytes = await MessagesSyncHandler.streamToBytes(data);
305
199
  if (bytes.byteLength <= DEFAULT_MAX_INLINE_DATA_SIZE) {
306
200
  entry.encodedData = Encoder.bytesToBase64Url(bytes);
307
201
  }
308
- // Large payloads are NOT inlined — client fetches via MessagesRead.
309
202
  }
310
203
  entries.push(entry);
311
204
  }
312
205
  return entries;
313
206
  }
314
- async buildProjectedDependencyEntries(tenant, primaryEntries) {
315
- const dependenciesByCid = new Map();
316
- const configsByProtocol = new Map();
317
- for (const primaryEntry of primaryEntries) {
318
- const protocolMetadata = MessagesSyncHandler.recordsWriteProtocolMetadata(primaryEntry.message);
319
- if (protocolMetadata !== undefined) {
320
- await this.addProtocolConfigClosureDependencies(tenant, protocolMetadata.protocol, protocolMetadata.messageTimestamp, primaryEntry.messageCid, configsByProtocol, dependenciesByCid);
321
- continue;
322
- }
323
- const initialWrite = await this.readRecordsDeleteInitialWrite(tenant, primaryEntry.message);
324
- if (initialWrite === undefined) {
325
- continue;
326
- }
327
- await MessagesSyncHandler.addRecordsInitialWriteDependency(primaryEntry.messageCid, initialWrite, dependenciesByCid);
328
- const initialWriteMetadata = MessagesSyncHandler.recordsWriteProtocolMetadata(initialWrite);
329
- if (initialWriteMetadata === undefined) {
330
- continue;
331
- }
332
- await this.addProtocolConfigClosureDependencies(tenant, initialWriteMetadata.protocol, initialWriteMetadata.messageTimestamp, primaryEntry.messageCid, configsByProtocol, dependenciesByCid);
333
- }
334
- return [...dependenciesByCid.values()];
335
- }
336
- async readRecordsDeleteInitialWrite(tenant, message) {
337
- const recordId = MessagesSyncHandler.recordsDeleteRecordId(message);
338
- if (recordId === undefined) {
339
- return undefined;
340
- }
341
- const { messages } = await this.deps.messageStore.query(tenant, [{
342
- interface: DwnInterfaceName.Records,
343
- method: DwnMethodName.Write,
344
- recordId,
345
- }]);
346
- const initialWrite = await RecordsWrite.getInitialWrite(messages);
347
- return initialWrite === undefined ? undefined : MessagesSyncHandler.toWireMessage(initialWrite);
348
- }
349
- static async addRecordsInitialWriteDependency(rootMessageCid, dependency, dependenciesByCid) {
350
- const dependencyCid = await Message.getCid(dependency);
351
- if (dependenciesByCid.has(dependencyCid)) {
352
- return;
353
- }
354
- dependenciesByCid.set(dependencyCid, {
355
- dependencyClass: 'recordsInitialWrite',
356
- messageCid: dependencyCid,
357
- message: dependency,
358
- rootMessageCid,
359
- });
360
- }
361
- async addProtocolConfigClosureDependencies(tenant, rootProtocol, rootMessageTimestamp, rootMessageCid, configsByProtocol, dependenciesByCid) {
362
- // Dependency hints are not part of the projected root; they are advisory
363
- // bootstrap data for the receiver. Bound each closure to the primary
364
- // RecordsWrite timestamp because protocol authorization uses the definition
365
- // active when that record was created, not whatever config is newest today.
366
- const visitedProtocols = new Set();
367
- const pendingProtocols = [rootProtocol];
368
- for (let protocol = MessagesSyncHandler.takeNextUnvisitedProtocol(pendingProtocols, visitedProtocols); protocol !== undefined; protocol = MessagesSyncHandler.takeNextUnvisitedProtocol(pendingProtocols, visitedProtocols)) {
369
- const configs = await this.getCachedGoverningProtocolsConfigure(tenant, protocol, rootMessageTimestamp, configsByProtocol);
370
- await MessagesSyncHandler.addProtocolConfigDependencies({
371
- configs,
372
- rootMessageCid,
373
- visitedProtocols,
374
- pendingProtocols,
375
- dependenciesByCid,
376
- });
377
- }
378
- }
379
- async getCachedGoverningProtocolsConfigure(tenant, protocol, messageTimestamp, configsByProtocol) {
380
- const configCacheKey = JSON.stringify([protocol, messageTimestamp]);
381
- const cachedConfigs = configsByProtocol.get(configCacheKey);
382
- if (cachedConfigs !== undefined) {
383
- return cachedConfigs;
384
- }
385
- const configs = await this.readGoverningProtocolsConfigure(tenant, protocol, messageTimestamp);
386
- configsByProtocol.set(configCacheKey, configs);
387
- return configs;
388
- }
389
- static async addProtocolConfigDependencies({ configs, rootMessageCid, visitedProtocols, pendingProtocols, dependenciesByCid, }) {
390
- for (const dependency of configs) {
391
- await MessagesSyncHandler.addProtocolConfigDependency(rootMessageCid, dependency, dependenciesByCid);
392
- MessagesSyncHandler.queueUnvisitedProtocols(MessagesSyncHandler.protocolsConfigureUses(dependency), visitedProtocols, pendingProtocols);
393
- }
394
- }
395
- static async addProtocolConfigDependency(rootMessageCid, dependency, dependenciesByCid) {
396
- const dependencyCid = await Message.getCid(dependency);
397
- if (dependenciesByCid.has(dependencyCid)) {
398
- return;
399
- }
400
- dependenciesByCid.set(dependencyCid, {
401
- dependencyClass: 'protocolsConfigure',
402
- messageCid: dependencyCid,
403
- message: dependency,
404
- rootMessageCid,
405
- });
406
- }
407
- static takeNextUnvisitedProtocol(pendingProtocols, visitedProtocols) {
408
- while (pendingProtocols.length > 0) {
409
- const protocol = pendingProtocols.shift();
410
- if (visitedProtocols.has(protocol)) {
411
- continue;
412
- }
413
- visitedProtocols.add(protocol);
414
- return protocol;
415
- }
416
- return undefined;
417
- }
418
- static queueUnvisitedProtocols(protocols, visitedProtocols, pendingProtocols) {
419
- for (const protocol of protocols) {
420
- if (!visitedProtocols.has(protocol)) {
421
- pendingProtocols.push(protocol);
422
- }
423
- }
424
- }
425
- static protocolsConfigureUses(message) {
426
- if (message.descriptor.interface !== DwnInterfaceName.Protocols ||
427
- message.descriptor.method !== DwnMethodName.Configure) {
428
- return [];
429
- }
430
- const uses = message.descriptor.definition?.uses;
431
- return uses === undefined
432
- ? []
433
- : Object.values(uses).filter((protocol) => typeof protocol === 'string');
434
- }
435
- async readGoverningProtocolsConfigure(tenant, protocol, messageTimestamp) {
436
- const { messages } = await this.deps.messageStore.query(tenant, [{
437
- interface: DwnInterfaceName.Protocols,
438
- method: DwnMethodName.Configure,
439
- protocol,
440
- messageTimestamp: { lte: messageTimestamp },
441
- }], { messageTimestamp: SortDirection.Descending });
442
- const governingMessage = await Message.getNewestMessage(messages);
443
- return governingMessage === undefined ? [] : [governingMessage];
444
- }
445
- static recordsWriteProtocolMetadata(message) {
446
- if (message?.descriptor.interface !== DwnInterfaceName.Records ||
447
- message.descriptor.method !== DwnMethodName.Write) {
448
- return undefined;
449
- }
450
- const protocol = message.descriptor.protocol;
451
- return typeof protocol === 'string'
452
- ? { protocol, messageTimestamp: message.descriptor.messageTimestamp }
453
- : undefined;
454
- }
455
- static recordsDeleteRecordId(message) {
456
- if (message?.descriptor.interface !== DwnInterfaceName.Records ||
457
- message.descriptor.method !== DwnMethodName.Delete) {
458
- return undefined;
459
- }
460
- const recordId = message.descriptor.recordId;
461
- return typeof recordId === 'string' ? recordId : undefined;
462
- }
463
- static toWireMessage(message) {
464
- const { encodedData: _encodedData, initialWrite: _initialWrite, ...wireMessage } = message;
465
- return wireMessage;
466
- }
467
- /**
468
- * Read a message and its data from the MessageStore + DataStore by CID.
469
- */
470
207
  async readMessageByCid(tenant, messageCid) {
471
208
  const storedMessage = await this.deps.messageStore.get(tenant, messageCid);
472
209
  if (!storedMessage) {
473
210
  return {};
474
211
  }
475
- // Extract and strip `encodedData` from the stored message.
476
- // `encodedData` is an internal storage optimization for small payloads
477
- // that are stored inline in the MessageStore rather than in the DataStore.
478
- // It must not be included in the wire-format message (the recipient's
479
- // DWN would reject it as an unexpected top-level property).
480
212
  let inlineEncodedData;
481
213
  if (MessagesSyncHandler.hasEncodedData(storedMessage)) {
482
214
  inlineEncodedData = storedMessage.encodedData;
483
215
  delete storedMessage.encodedData;
484
216
  }
485
217
  let data;
486
- // Check if this is a RecordsWrite with data that is small enough to inline.
487
218
  if (inlineEncodedData === undefined && Records.isRecordsWrite(storedMessage)) {
488
219
  const { dataCid, dataSize } = storedMessage.descriptor;
489
- if (dataSize <= DEFAULT_MAX_INLINE_DATA_SIZE) {
490
- // Some stores may have small payload bytes in DataStore instead of encodedData.
491
- if (this.deps.dataStore) {
492
- // DataStore uses recordId, not messageCid. For RecordsWrite,
493
- // recordId is a top-level message property.
494
- const dataResult = await this.deps.dataStore.get(tenant, storedMessage.recordId, dataCid);
495
- if (dataResult?.dataStream) {
496
- data = dataResult.dataStream;
497
- }
498
- }
220
+ if (dataSize <= DEFAULT_MAX_INLINE_DATA_SIZE && this.deps.dataStore) {
221
+ const dataResult = await this.deps.dataStore.get(tenant, storedMessage.recordId, dataCid);
222
+ data = dataResult?.dataStream;
499
223
  }
500
224
  }
501
225
  return { message: storedMessage, encodedData: inlineEncodedData, data };
@@ -503,29 +227,6 @@ export class MessagesSyncHandler {
503
227
  static hasEncodedData(message) {
504
228
  return 'encodedData' in message && typeof message.encodedData === 'string';
505
229
  }
506
- static getProjectionScopes(message) {
507
- const { projectionScopes } = message.descriptor;
508
- if (projectionScopes === undefined) {
509
- return undefined;
510
- }
511
- return projectionScopes;
512
- }
513
- async withProjectionSnapshot(tenant, scopes, fn) {
514
- const snapshot = await RecordsProjection.createSnapshot({
515
- tenant: tenant,
516
- messageStore: this.deps.messageStore,
517
- scopes: scopes,
518
- });
519
- try {
520
- return await fn(snapshot);
521
- }
522
- finally {
523
- await snapshot.close();
524
- }
525
- }
526
- /**
527
- * Read a ReadableStream to completion and return the bytes.
528
- */
529
230
  static async streamToBytes(stream) {
530
231
  const reader = stream.getReader();
531
232
  const chunks = [];
@@ -546,9 +247,6 @@ export class MessagesSyncHandler {
546
247
  }
547
248
  return result;
548
249
  }
549
- /**
550
- * Parse a bit prefix string (e.g. "0110101") into a boolean array.
551
- */
552
250
  static parseBitPrefix(prefix) {
553
251
  if (!/^[01]*$/.test(prefix)) {
554
252
  throw new DwnError(DwnErrorCode.MessagesSyncInvalidPrefix, `Invalid prefix: must contain only '0' and '1' characters, got: ${prefix}`);
@@ -572,10 +270,9 @@ export class MessagesSyncHandler {
572
270
  permissionGrants,
573
271
  messageStore
574
272
  });
273
+ return;
575
274
  }
576
- else {
577
- throw new DwnError(DwnErrorCode.MessagesSyncAuthorizationFailed, 'message failed authorization');
578
- }
275
+ throw new DwnError(DwnErrorCode.MessagesSyncAuthorizationFailed, 'message failed authorization');
579
276
  }
580
277
  }
581
278
  //# sourceMappingURL=messages-sync.js.map