@opendatalabs/personal-server-ts-core 1.6.0 → 1.7.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 (49) hide show
  1. package/dist/api/index.d.ts +8 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +175 -21
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/contracts/data.d.ts +14 -0
  6. package/dist/contracts/data.d.ts.map +1 -1
  7. package/dist/contracts/data.js +55 -14
  8. package/dist/contracts/data.js.map +1 -1
  9. package/dist/errors/catalog.d.ts +34 -0
  10. package/dist/errors/catalog.d.ts.map +1 -1
  11. package/dist/errors/catalog.js +41 -0
  12. package/dist/errors/catalog.js.map +1 -1
  13. package/dist/lineage/attestation.d.ts +42 -0
  14. package/dist/lineage/attestation.d.ts.map +1 -0
  15. package/dist/lineage/attestation.js +25 -0
  16. package/dist/lineage/attestation.js.map +1 -0
  17. package/dist/lineage/gateway.d.ts +105 -0
  18. package/dist/lineage/gateway.d.ts.map +1 -0
  19. package/dist/lineage/gateway.js +242 -0
  20. package/dist/lineage/gateway.js.map +1 -0
  21. package/dist/lineage/index.d.ts +5 -0
  22. package/dist/lineage/index.d.ts.map +1 -0
  23. package/dist/lineage/index.js +5 -0
  24. package/dist/lineage/index.js.map +1 -0
  25. package/dist/lineage/lineage.d.ts +141 -0
  26. package/dist/lineage/lineage.d.ts.map +1 -0
  27. package/dist/lineage/lineage.js +255 -0
  28. package/dist/lineage/lineage.js.map +1 -0
  29. package/dist/signing/request-signer.d.ts +2 -0
  30. package/dist/signing/request-signer.d.ts.map +1 -1
  31. package/dist/signing/request-signer.js +1 -0
  32. package/dist/signing/request-signer.js.map +1 -1
  33. package/dist/signing/signer.d.ts +8 -0
  34. package/dist/signing/signer.d.ts.map +1 -1
  35. package/dist/signing/signer.js +9 -0
  36. package/dist/signing/signer.js.map +1 -1
  37. package/dist/sync/data-point-id.d.ts +7 -0
  38. package/dist/sync/data-point-id.d.ts.map +1 -0
  39. package/dist/sync/data-point-id.js +16 -0
  40. package/dist/sync/data-point-id.js.map +1 -0
  41. package/dist/sync/workers/upload.d.ts +10 -6
  42. package/dist/sync/workers/upload.d.ts.map +1 -1
  43. package/dist/sync/workers/upload.js +39 -17
  44. package/dist/sync/workers/upload.js.map +1 -1
  45. package/dist/write/attribution.d.ts +6 -4
  46. package/dist/write/attribution.d.ts.map +1 -1
  47. package/dist/write/attribution.js +51 -3
  48. package/dist/write/attribution.js.map +1 -1
  49. package/package.json +5 -1
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Derivative data: lineage on the write path.
3
+ *
4
+ * A derivative is an ordinary write whose body names the data points it was
5
+ * computed from. The caller's `lineage` field (top level of a JSON body, or
6
+ * inside the `X-Vana-Metadata` object of a binary write) is a list of data
7
+ * point ids, `keccak256(abi.encode(owner, scope))`. The Personal Server
8
+ * validates it against the owner's own data points and mirrors it into the
9
+ * envelope `data` under the reserved `$lineage` key, the same in-`data`
10
+ * marker idiom as `$writtenBy` and `$binary`, so lineage rides the unchanged
11
+ * encrypt / upload / register path and `metadataHash` commits to it.
12
+ *
13
+ * The caller's `lineage` field is left in the record untouched: for session
14
+ * writes it is inside the bytes the builder signed, so the lineage claim is
15
+ * builder-signed and `$lineage` is the server-validated mirror of it.
16
+ *
17
+ * See docs/derivative-data-api.md for the wire contract.
18
+ */
19
+ import type { DataStoragePort } from "../ports/index.js";
20
+ /** Reserved key inside the envelope `data` record for validated lineage. */
21
+ export declare const LINEAGE_KEY: "$lineage";
22
+ /** The caller-facing field name (JSON body top level / binary metadata). */
23
+ export declare const LINEAGE_FIELD: "lineage";
24
+ /** Upper bound on sources per record; keeps validation and hashing bounded. */
25
+ export declare const MAX_LINEAGE_SOURCES = 256;
26
+ /** Page size of the local index scan the source resolver runs. */
27
+ export declare const LOCAL_SCOPE_SCAN_PAGE = 1000;
28
+ export interface StoredLineage {
29
+ /** Validated, lowercased source data point ids in the order given. */
30
+ sources: `0x${string}`[];
31
+ /** ISO timestamp the Personal Server validated and stamped the lineage. */
32
+ writtenAt: string;
33
+ }
34
+ /** A source as the resolver saw it (local index or gateway). */
35
+ export interface ResolvedLineageSource {
36
+ dataPointId: `0x${string}`;
37
+ scope: string;
38
+ /** Null while the source is only known locally (not registered yet). */
39
+ version: string | null;
40
+ deletedAt: string | null;
41
+ }
42
+ /** The subset of a gateway data-point record the resolver needs. */
43
+ export interface LineageDataPointRecord {
44
+ dataPointId: string;
45
+ ownerAddress: string;
46
+ scope: string;
47
+ version: string;
48
+ deletedAt: string | null;
49
+ }
50
+ /**
51
+ * Gateway lookup for a source that is not in the local index. Must include
52
+ * deleted (tombstoned) data points: a deleted source is still a valid
53
+ * lineage target, it is only reported as deleted when the lineage is walked.
54
+ */
55
+ export interface LineageSourceLookup {
56
+ getDataPoint(dataPointId: string): Promise<LineageDataPointRecord | null>;
57
+ }
58
+ export declare function hasReservedLineageKey(data: Record<string, unknown>): boolean;
59
+ /** Stamp validated lineage into an envelope `data` record. */
60
+ export declare function stampLineage(data: Record<string, unknown>, lineage: StoredLineage): Record<string, unknown>;
61
+ /**
62
+ * The stored `$lineage` of a record, or null for a root record. Tolerates
63
+ * hand-crafted envelopes: anything that is not the exact stamped shape is
64
+ * treated as no lineage rather than thrown on.
65
+ */
66
+ export declare class StoredLineageMalformedError extends Error {
67
+ constructor(detail: string);
68
+ }
69
+ /**
70
+ * Absent `$lineage` (or a data object that is not a record) is `null`: no
71
+ * statement. A PRESENT but malformed `$lineage` throws: a corrupted or
72
+ * hand-crafted derivative must fail closed, never fall through the root
73
+ * path and get registered as if it made no lineage statement.
74
+ */
75
+ export declare function readStoredLineage(data: Record<string, unknown> | undefined): StoredLineage | null;
76
+ /**
77
+ * The caller's `lineage` field from a JSON body or a binary write's parsed
78
+ * metadata. `undefined` when the container is not an object or carries no
79
+ * such field, so a bare-string metadata header or a lineage-less body is a
80
+ * root record.
81
+ */
82
+ export declare function extractLineageField(container: unknown): unknown;
83
+ /**
84
+ * Parse the caller's `lineage` value: an array of distinct 0x-prefixed
85
+ * 32-byte hex strings, at most MAX_LINEAGE_SOURCES long. Ids are lowercased
86
+ * so equal ids compare equal wherever they are stored. Throws
87
+ * LineageInvalidError (400).
88
+ */
89
+ export declare function parseLineageSources(value: unknown): `0x${string}`[];
90
+ /** First dot-segment of a scope (`chatgpt` for `chatgpt.conversations`). */
91
+ export declare function scopeNamespace(scope: string): string;
92
+ /**
93
+ * The naming rule. Grant patterns are exact, `prefix.*` or `*`; `prefix.*`
94
+ * covers every scope that starts with `prefix.`. A derived scope and a
95
+ * source scope are both covered by the same non-universal pattern exactly
96
+ * when they share their first segment, and that is the one way the current
97
+ * grammar can leak across a lineage edge (a grant on `chatgpt.*` would read
98
+ * both `chatgpt.conversations` and a derivative named `chatgpt.summary`).
99
+ * `*` reads everything by definition and is not a lineage leak.
100
+ */
101
+ export declare function derivedScopeViolatesNaming(derivedScope: string, sourceScope: string): boolean;
102
+ export declare function assertDerivedScopeNaming(derivedScope: string, sourceScopes: readonly string[]): void;
103
+ export interface ResolveLineageSourcesInput {
104
+ /** The derived record's scope. */
105
+ scope: string;
106
+ sources: readonly `0x${string}`[];
107
+ serverOwner: `0x${string}`;
108
+ storage: Pick<DataStoragePort, "listScopes">;
109
+ /** Absent = sources must be in the local index. */
110
+ gateway?: LineageSourceLookup;
111
+ }
112
+ /**
113
+ * Resolve every source id to a data point of this owner. The local index is
114
+ * consulted first (`keccak256(owner, scope)` over the server's own scopes,
115
+ * so an unsynced local scope is a valid source), then the gateway with
116
+ * deleted points included. An id that resolves to nothing, or to another
117
+ * owner's data point, fails the whole write with 422
118
+ * LINEAGE_SOURCE_UNKNOWN listing every offending id; a gateway that cannot
119
+ * be reached fails with 502 so the builder retries instead of being told
120
+ * its source does not exist.
121
+ */
122
+ export declare function resolveLineageSources(input: ResolveLineageSourcesInput): Promise<ResolvedLineageSource[]>;
123
+ export interface PrepareLineageInput {
124
+ scope: string;
125
+ /** The raw caller value (`body.lineage` / `metadata.lineage`). */
126
+ field: unknown;
127
+ serverOwner: `0x${string}` | undefined;
128
+ storage: Pick<DataStoragePort, "listScopes">;
129
+ gateway?: LineageSourceLookup;
130
+ now: () => Date;
131
+ }
132
+ /**
133
+ * Validate a write's lineage end to end (shape, sources, naming rule) and
134
+ * produce the `$lineage` record to stamp. An empty list is an EXPLICIT root
135
+ * statement: it is stamped (`sources: []`) and registered as an attested
136
+ * root, distinct from an absent field, which makes no lineage statement.
137
+ * Throws ProtocolErrors; callers on the write path let them propagate
138
+ * before anything is stored.
139
+ */
140
+ export declare function prepareLineage(input: PrepareLineageInput): Promise<StoredLineage>;
141
+ //# sourceMappingURL=lineage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lineage.d.ts","sourceRoot":"","sources":["../../src/lineage/lineage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,4EAA4E;AAC5E,eAAO,MAAM,WAAW,EAAG,UAAmB,CAAC;AAE/C,4EAA4E;AAC5E,eAAO,MAAM,aAAa,EAAG,SAAkB,CAAC;AAEhD,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,kEAAkE;AAClE,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAI1C,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,OAAO,EAAE,KAAK,MAAM,EAAE,EAAE,CAAC;IACzB,2EAA2E;IAC3E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,oEAAoE;AACpE,MAAM,WAAW,sBAA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AC9B,IAAI,CASN;AAED,MAAM,WAAW,0BAA0B;IACzC,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,SAAS,KAAK,MAAM,EAAE,EAAE,CAAC;IAClC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;IAC7C,mDAAmD;IACnD,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CA2DlC;AAkCD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS,CAAC;IACvC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,aAAa,CAAC,CAmBxB"}
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Derivative data: lineage on the write path.
3
+ *
4
+ * A derivative is an ordinary write whose body names the data points it was
5
+ * computed from. The caller's `lineage` field (top level of a JSON body, or
6
+ * inside the `X-Vana-Metadata` object of a binary write) is a list of data
7
+ * point ids, `keccak256(abi.encode(owner, scope))`. The Personal Server
8
+ * validates it against the owner's own data points and mirrors it into the
9
+ * envelope `data` under the reserved `$lineage` key, the same in-`data`
10
+ * marker idiom as `$writtenBy` and `$binary`, so lineage rides the unchanged
11
+ * encrypt / upload / register path and `metadataHash` commits to it.
12
+ *
13
+ * The caller's `lineage` field is left in the record untouched: for session
14
+ * writes it is inside the bytes the builder signed, so the lineage claim is
15
+ * builder-signed and `$lineage` is the server-validated mirror of it.
16
+ *
17
+ * See docs/derivative-data-api.md for the wire contract.
18
+ */
19
+ import { LineageInvalidError, LineageScopeUnderSourcePrefixError, LineageSourceLookupFailedError, LineageSourceUnknownError, ServerNotConfiguredError, } from "../errors/catalog.js";
20
+ import { computeDataPointId } from "../sync/data-point-id.js";
21
+ /** Reserved key inside the envelope `data` record for validated lineage. */
22
+ export const LINEAGE_KEY = "$lineage";
23
+ /** The caller-facing field name (JSON body top level / binary metadata). */
24
+ export const LINEAGE_FIELD = "lineage";
25
+ /** Upper bound on sources per record; keeps validation and hashing bounded. */
26
+ export const MAX_LINEAGE_SOURCES = 256;
27
+ /** Page size of the local index scan the source resolver runs. */
28
+ export const LOCAL_SCOPE_SCAN_PAGE = 1000;
29
+ const BYTES32_HEX = /^0x[0-9a-fA-F]{64}$/;
30
+ function isRecord(value) {
31
+ return value !== null && typeof value === "object" && !Array.isArray(value);
32
+ }
33
+ export function hasReservedLineageKey(data) {
34
+ return Object.prototype.hasOwnProperty.call(data, LINEAGE_KEY);
35
+ }
36
+ /** Stamp validated lineage into an envelope `data` record. */
37
+ export function stampLineage(data, lineage) {
38
+ return { ...data, [LINEAGE_KEY]: lineage };
39
+ }
40
+ /**
41
+ * The stored `$lineage` of a record, or null for a root record. Tolerates
42
+ * hand-crafted envelopes: anything that is not the exact stamped shape is
43
+ * treated as no lineage rather than thrown on.
44
+ */
45
+ export class StoredLineageMalformedError extends Error {
46
+ constructor(detail) {
47
+ super(`Stored $lineage is malformed: ${detail}`);
48
+ this.name = "StoredLineageMalformedError";
49
+ }
50
+ }
51
+ /**
52
+ * Absent `$lineage` (or a data object that is not a record) is `null`: no
53
+ * statement. A PRESENT but malformed `$lineage` throws: a corrupted or
54
+ * hand-crafted derivative must fail closed, never fall through the root
55
+ * path and get registered as if it made no lineage statement.
56
+ */
57
+ export function readStoredLineage(data) {
58
+ if (!isRecord(data) || !(LINEAGE_KEY in data))
59
+ return null;
60
+ const value = data[LINEAGE_KEY];
61
+ if (!isRecord(value)) {
62
+ throw new StoredLineageMalformedError("not an object");
63
+ }
64
+ const sources = value.sources;
65
+ if (!Array.isArray(sources) ||
66
+ !sources.every((id) => typeof id === "string" && BYTES32_HEX.test(id))) {
67
+ throw new StoredLineageMalformedError("sources is not a list of bytes32 ids");
68
+ }
69
+ if (typeof value.writtenAt !== "string") {
70
+ throw new StoredLineageMalformedError("writtenAt is not a string");
71
+ }
72
+ return {
73
+ sources: sources.map((id) => id.toLowerCase()),
74
+ writtenAt: value.writtenAt,
75
+ };
76
+ }
77
+ /**
78
+ * The caller's `lineage` field from a JSON body or a binary write's parsed
79
+ * metadata. `undefined` when the container is not an object or carries no
80
+ * such field, so a bare-string metadata header or a lineage-less body is a
81
+ * root record.
82
+ */
83
+ export function extractLineageField(container) {
84
+ if (!isRecord(container))
85
+ return undefined;
86
+ return container[LINEAGE_FIELD];
87
+ }
88
+ /**
89
+ * Parse the caller's `lineage` value: an array of distinct 0x-prefixed
90
+ * 32-byte hex strings, at most MAX_LINEAGE_SOURCES long. Ids are lowercased
91
+ * so equal ids compare equal wherever they are stored. Throws
92
+ * LineageInvalidError (400).
93
+ */
94
+ export function parseLineageSources(value) {
95
+ if (!Array.isArray(value)) {
96
+ throw new LineageInvalidError(`${LINEAGE_FIELD} must be an array of data point ids (0x-prefixed 32-byte hex)`);
97
+ }
98
+ if (value.length > MAX_LINEAGE_SOURCES) {
99
+ throw new LineageInvalidError(`${LINEAGE_FIELD} lists ${value.length} sources; the maximum is ${MAX_LINEAGE_SOURCES}`, { max: MAX_LINEAGE_SOURCES, count: value.length });
100
+ }
101
+ const seen = new Set();
102
+ const sources = [];
103
+ for (const entry of value) {
104
+ if (typeof entry !== "string" || !BYTES32_HEX.test(entry)) {
105
+ throw new LineageInvalidError(`${LINEAGE_FIELD} entries must be 0x-prefixed 32-byte hex data point ids`, { entry: typeof entry === "string" ? entry : typeof entry });
106
+ }
107
+ const id = entry.toLowerCase();
108
+ if (seen.has(id)) {
109
+ throw new LineageInvalidError(`${LINEAGE_FIELD} lists the same source twice`, { duplicate: id });
110
+ }
111
+ seen.add(id);
112
+ sources.push(id);
113
+ }
114
+ return sources;
115
+ }
116
+ /** First dot-segment of a scope (`chatgpt` for `chatgpt.conversations`). */
117
+ export function scopeNamespace(scope) {
118
+ const dot = scope.indexOf(".");
119
+ return dot === -1 ? scope : scope.slice(0, dot);
120
+ }
121
+ /**
122
+ * The naming rule. Grant patterns are exact, `prefix.*` or `*`; `prefix.*`
123
+ * covers every scope that starts with `prefix.`. A derived scope and a
124
+ * source scope are both covered by the same non-universal pattern exactly
125
+ * when they share their first segment, and that is the one way the current
126
+ * grammar can leak across a lineage edge (a grant on `chatgpt.*` would read
127
+ * both `chatgpt.conversations` and a derivative named `chatgpt.summary`).
128
+ * `*` reads everything by definition and is not a lineage leak.
129
+ */
130
+ export function derivedScopeViolatesNaming(derivedScope, sourceScope) {
131
+ return scopeNamespace(derivedScope) === scopeNamespace(sourceScope);
132
+ }
133
+ export function assertDerivedScopeNaming(derivedScope, sourceScopes) {
134
+ for (const sourceScope of sourceScopes) {
135
+ if (derivedScopeViolatesNaming(derivedScope, sourceScope)) {
136
+ throw new LineageScopeUnderSourcePrefixError({
137
+ scope: derivedScope,
138
+ sourceScope,
139
+ });
140
+ }
141
+ }
142
+ }
143
+ /**
144
+ * Resolve every source id to a data point of this owner. The local index is
145
+ * consulted first (`keccak256(owner, scope)` over the server's own scopes,
146
+ * so an unsynced local scope is a valid source), then the gateway with
147
+ * deleted points included. An id that resolves to nothing, or to another
148
+ * owner's data point, fails the whole write with 422
149
+ * LINEAGE_SOURCE_UNKNOWN listing every offending id; a gateway that cannot
150
+ * be reached fails with 502 so the builder retries instead of being told
151
+ * its source does not exist.
152
+ */
153
+ export async function resolveLineageSources(input) {
154
+ const ownId = computeDataPointId(input.serverOwner, input.scope);
155
+ const self = input.sources.find((id) => id === ownId);
156
+ if (self) {
157
+ throw new LineageInvalidError("A record cannot list its own data point as a lineage source", { dataPointId: self });
158
+ }
159
+ const local = localScopesById(input.storage, input.serverOwner, new Set(input.sources));
160
+ const resolved = [];
161
+ const unknown = [];
162
+ for (const dataPointId of input.sources) {
163
+ const localScope = local.get(dataPointId);
164
+ if (localScope !== undefined) {
165
+ resolved.push({
166
+ dataPointId,
167
+ scope: localScope,
168
+ version: null,
169
+ deletedAt: null,
170
+ });
171
+ continue;
172
+ }
173
+ if (!input.gateway) {
174
+ unknown.push(dataPointId);
175
+ continue;
176
+ }
177
+ let record;
178
+ try {
179
+ record = await input.gateway.getDataPoint(dataPointId);
180
+ }
181
+ catch (err) {
182
+ throw new LineageSourceLookupFailedError({
183
+ dataPointId,
184
+ error: err instanceof Error ? err.message : String(err),
185
+ });
186
+ }
187
+ if (!record ||
188
+ record.ownerAddress.toLowerCase() !== input.serverOwner.toLowerCase()) {
189
+ unknown.push(dataPointId);
190
+ continue;
191
+ }
192
+ resolved.push({
193
+ dataPointId,
194
+ scope: record.scope,
195
+ version: record.version,
196
+ deletedAt: record.deletedAt,
197
+ });
198
+ }
199
+ if (unknown.length > 0) {
200
+ throw new LineageSourceUnknownError({ unknown });
201
+ }
202
+ return resolved;
203
+ }
204
+ /**
205
+ * `dataPointId -> scope` for the server's own scopes that appear in
206
+ * `wanted`. Pages through the whole local index (an unsynced scope is a
207
+ * valid source wherever it sorts), stopping early once every wanted id has
208
+ * been found.
209
+ */
210
+ function localScopesById(storage, serverOwner, wanted) {
211
+ const byId = new Map();
212
+ for (let offset = 0;; offset += LOCAL_SCOPE_SCAN_PAGE) {
213
+ const { scopes, total } = storage.listScopes({
214
+ limit: LOCAL_SCOPE_SCAN_PAGE,
215
+ offset,
216
+ });
217
+ for (const summary of scopes) {
218
+ const id = computeDataPointId(serverOwner, summary.scope);
219
+ if (wanted.has(id))
220
+ byId.set(id, summary.scope);
221
+ }
222
+ if (byId.size === wanted.size ||
223
+ scopes.length === 0 ||
224
+ offset + scopes.length >= total) {
225
+ break;
226
+ }
227
+ }
228
+ return byId;
229
+ }
230
+ /**
231
+ * Validate a write's lineage end to end (shape, sources, naming rule) and
232
+ * produce the `$lineage` record to stamp. An empty list is an EXPLICIT root
233
+ * statement: it is stamped (`sources: []`) and registered as an attested
234
+ * root, distinct from an absent field, which makes no lineage statement.
235
+ * Throws ProtocolErrors; callers on the write path let them propagate
236
+ * before anything is stored.
237
+ */
238
+ export async function prepareLineage(input) {
239
+ const sources = parseLineageSources(input.field);
240
+ if (!input.serverOwner) {
241
+ throw new ServerNotConfiguredError({
242
+ reason: "serverOwner is required to validate lineage sources",
243
+ });
244
+ }
245
+ const resolved = await resolveLineageSources({
246
+ scope: input.scope,
247
+ sources,
248
+ serverOwner: input.serverOwner,
249
+ storage: input.storage,
250
+ gateway: input.gateway,
251
+ });
252
+ assertDerivedScopeNaming(input.scope, resolved.map((source) => source.scope));
253
+ return { sources, writtenAt: input.now().toISOString() };
254
+ }
255
+ //# sourceMappingURL=lineage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lineage.js","sourceRoot":"","sources":["../../src/lineage/lineage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,mBAAmB,EACnB,kCAAkC,EAClC,8BAA8B,EAC9B,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,UAAmB,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,SAAkB,CAAC;AAEhD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC,kEAAkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAoC1C,SAAS,QAAQ,CAAC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,CAAC;gBAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;QACD,IACE,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;YACzB,MAAM,CAAC,MAAM,KAAK,CAAC;YACnB,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,KAAK,EAC/B,CAAC;YACD,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAYD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAA0B;IAE1B,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACvB,MAAM,IAAI,wBAAwB,CAAC;YACjC,MAAM,EAAE,qDAAqD;SAC9D,CAAC,CAAC;IACL,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC;QAC3C,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO;QACP,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,CAAC;IACH,wBAAwB,CACtB,KAAK,CAAC,KAAK,EACX,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CACvC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AAC3D,CAAC"}
@@ -8,6 +8,8 @@ export interface RequestSigner {
8
8
  method: string;
9
9
  uri: string;
10
10
  body?: Uint8Array;
11
+ /** Signed `grantId` claim (the grant view a lineage read asks for). */
12
+ grantId?: string;
11
13
  }): Promise<string>;
12
14
  }
13
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"request-signer.d.ts","sourceRoot":"","sources":["../../src/signing/request-signer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,MAAM,EAAE;QAClB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAYzE"}
1
+ {"version":3,"file":"request-signer.d.ts","sourceRoot":"","sources":["../../src/signing/request-signer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,MAAM,EAAE;QAClB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,uEAAuE;QACvE,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAazE"}
@@ -15,6 +15,7 @@ export function createRequestSigner(account) {
15
15
  method: params.method,
16
16
  uri: params.uri,
17
17
  body: params.body,
18
+ grantId: params.grantId,
18
19
  });
19
20
  },
20
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"request-signer.js","sourceRoot":"","sources":["../../src/signing/request-signer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAYvE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,OAAO;QACL,KAAK,CAAC,WAAW,CAAC,MAAM;YACtB,OAAO,qBAAqB,CAAC;gBAC3B,WAAW,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;gBAC9D,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"request-signer.js","sourceRoot":"","sources":["../../src/signing/request-signer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAcvE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,OAAO;QACL,KAAK,CAAC,WAAW,CAAC,MAAM;YACtB,OAAO,qBAAqB,CAAC;gBAC3B,WAAW,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;gBAC9D,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -5,6 +5,7 @@
5
5
  import type { ServerAccount } from "../keys/server-account.js";
6
6
  import type { GatewayConfig } from "../schemas/server-config.js";
7
7
  import { type GrantRegistrationMessage, type GrantRevocationMessage, type AddDataMessage, type RecordDataAccessMessage } from "@opendatalabs/vana-sdk/browser";
8
+ import { type LineageAttestationMessage } from "../lineage/attestation.js";
8
9
  export interface ServerSigner {
9
10
  /** Address that signs (the server account). */
10
11
  readonly address: `0x${string}`;
@@ -27,6 +28,13 @@ export interface ServerSigner {
27
28
  * recordId is a per-event bytes32 the contract pins to prevent replay.
28
29
  */
29
30
  signRecordDataAccess(msg: RecordDataAccessMessage): Promise<`0x${string}`>;
31
+ /**
32
+ * LineageAttestation (derivative data): binds a derivative's source list
33
+ * to the exact (owner, scope, version, dataHash) it is registered with,
34
+ * under the DataRegistry domain. The gateway requires it on POST /v1/data
35
+ * with `lineage`; see lineage/attestation.ts for why.
36
+ */
37
+ signLineageAttestation(msg: LineageAttestationMessage): Promise<`0x${string}`>;
30
38
  }
31
39
  export declare function createServerSigner(account: ServerAccount, gatewayConfig: GatewayConfig): ServerSigner;
32
40
  //# sourceMappingURL=signer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signing/signer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAQL,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC7B,MAAM,gCAAgC,CAAC;AAExC,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;IAChC,qBAAqB,CAAC,GAAG,EAAE,wBAAwB,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IAC7E,mBAAmB,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IACzE;;;;;OAKG;IACH,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IACzD;;;;;;;;OAQG;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,aAAa,GAC3B,YAAY,CA6Dd"}
@@ -3,6 +3,7 @@
3
3
  * Uses the ServerAccount's derived key for all signatures.
4
4
  */
5
5
  import { grantRegistrationDomain, grantRevocationDomain, dataRegistryDomain, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, } from "@opendatalabs/vana-sdk/browser";
6
+ import { LINEAGE_ATTESTATION_TYPES, } from "../lineage/attestation.js";
6
7
  export function createServerSigner(account, gatewayConfig) {
7
8
  return {
8
9
  address: account.address,
@@ -34,6 +35,14 @@ export function createServerSigner(account, gatewayConfig) {
34
35
  message: msg,
35
36
  });
36
37
  },
38
+ async signLineageAttestation(msg) {
39
+ return account.signTypedData({
40
+ domain: dataRegistryDomain(gatewayConfig),
41
+ types: LINEAGE_ATTESTATION_TYPES,
42
+ primaryType: "LineageAttestation",
43
+ message: { ...msg, sources: [...msg.sources] },
44
+ });
45
+ },
37
46
  async signRecordDataAccess(msg) {
38
47
  return account.signTypedData({
39
48
  domain: dataRegistryDomain(gatewayConfig),
@@ -1 +1 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signing/signer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,cAAc,EACd,wBAAwB,GAKzB,MAAM,gCAAgC,CAAC;AA0BxC,MAAM,UAAU,kBAAkB,CAChC,OAAsB,EACtB,aAA4B;IAE5B,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QAExB,KAAK,CAAC,qBAAqB,CACzB,GAA6B;YAE7B,OAAO,OAAO,CAAC,aAAa,CAAC;gBAC3B,MAAM,EAAE,uBAAuB,CAAC,aAAa,CAAC;gBAC9C,KAAK,EAAE,wBAAwB;gBAC/B,WAAW,EAAE,mBAAmB;gBAChC,iDAAiD;gBACjD,iEAAiE;gBACjE,8DAA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,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Deterministic DPv2 data-point id: `keccak256(abi.encode(owner, scope))`,
3
+ * the same primary key DataRegistryV2 and the gateway use. Every version of
4
+ * a scope shares this id; the registry row carries the current version.
5
+ */
6
+ export declare function computeDataPointId(ownerAddress: string, scope: string): `0x${string}`;
7
+ //# sourceMappingURL=data-point-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-point-id.d.ts","sourceRoot":"","sources":["../../src/sync/data-point-id.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,GACZ,KAAK,MAAM,EAAE,CAaf"}
@@ -0,0 +1,16 @@
1
+ import { encodeAbiParameters, keccak256 } from "viem";
2
+ /**
3
+ * Deterministic DPv2 data-point id: `keccak256(abi.encode(owner, scope))`,
4
+ * the same primary key DataRegistryV2 and the gateway use. Every version of
5
+ * a scope shares this id; the registry row carries the current version.
6
+ */
7
+ export function computeDataPointId(ownerAddress, scope) {
8
+ // ABI-encoding an address is checksum-insensitive (same bytes either way),
9
+ // but viem rejects mixed-case strings that fail checksum validation;
10
+ // normalize so config-sourced owner strings can't trip it.
11
+ return keccak256(encodeAbiParameters([
12
+ { name: "ownerAddress", type: "address" },
13
+ { name: "scope", type: "string" },
14
+ ], [ownerAddress.toLowerCase(), scope]));
15
+ }
16
+ //# sourceMappingURL=data-point-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-point-id.js","sourceRoot":"","sources":["../../src/sync/data-point-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,YAAoB,EACpB,KAAa;IAEb,2EAA2E;IAC3E,qEAAqE;IACrE,2DAA2D;IAC3D,OAAO,SAAS,CACd,mBAAmB,CACjB;QACE,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE;QACzC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;KAClC,EACD,CAAC,YAAY,CAAC,WAAW,EAAmB,EAAE,KAAK,CAAC,CACrD,CACF,CAAC;AACJ,CAAC"}
@@ -4,6 +4,8 @@ import type { ServerSigner } from "../../signing/signer.js";
4
4
  import type { Logger } from "../../logger/index.js";
5
5
  import type { IndexEntry } from "../../storage/index/types.js";
6
6
  import type { DataStoragePort } from "../../ports/index.js";
7
+ import type { LineageGatewayPort } from "../../lineage/gateway.js";
8
+ export { computeDataPointId } from "../data-point-id.js";
7
9
  export interface UploadWorkerDeps {
8
10
  storage: DataStoragePort;
9
11
  storageAdapter: StorageAdapter;
@@ -12,6 +14,14 @@ export interface UploadWorkerDeps {
12
14
  masterKey: Uint8Array;
13
15
  serverOwner: string;
14
16
  logger: Logger;
17
+ /**
18
+ * Registers derivative records (envelopes stamped with `$lineage`) with
19
+ * their lineage. The SDK client's registerDataPoint sends only the AddData
20
+ * fields, so a derivative needs this direct client; without it a derivative
21
+ * upload fails (and retries next cycle) rather than silently registering as
22
+ * a root record whose lineage exists only inside the ciphertext.
23
+ */
24
+ lineageGateway?: Pick<LineageGatewayPort, "registerDataPoint">;
15
25
  }
16
26
  export interface UploadResult {
17
27
  path: string;
@@ -55,10 +65,4 @@ export declare function uploadOne(deps: UploadWorkerDeps, entry: IndexEntry): Pr
55
65
  */
56
66
  export declare function uploadAll(deps: UploadWorkerDeps, options?: UploadAllOptions): Promise<UploadResult[]>;
57
67
  export declare function parseGatewayNextVersion(message: string): number | null;
58
- /**
59
- * Deterministic DPv2 data-point id — `keccak256(abi.encode(owner, scope))`,
60
- * the same primary key DataRegistryV2 and the gateway use. Lets the upload
61
- * worker look up the registry's live row for a scope without a list call.
62
- */
63
- export declare function computeDataPointId(ownerAddress: string, scope: string): `0x${string}`;
64
68
  //# sourceMappingURL=upload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/sync/workers/upload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,eAAe,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,UAAU,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACrD;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,IAAI,EAAE,MAAM;CAIzB;AAcD;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,YAAY,CAAC,CAuNvB;AAED;;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