{"version":3,"sources":["../../src/protocol/lineage.ts"],"sourcesContent":["/**\n * Derivative lineage: which data points a record was derived from, and which\n * records were derived from it.\n *\n * @remarks\n * A data point is addressed by `keccak256(abi.encode(address owner, string\n * scope))` ({@link deriveDataPointId}). A builder writing a derivative names\n * its sources through the `lineage` option of {@link writeData}; the Personal\n * Server stores them under the reserved `$lineage` key and both the Personal\n * Server (`GET /v1/data/:scope/lineage[/:version]`) and the gateway\n * (`GET /v1/data/:dataPointId/lineage[/:version]`) answer the resulting view.\n * Nodes the caller holds no grant for come back as exactly\n * `{ redacted: true }`: no id, scope or version, because the id is\n * `keccak256(owner, scope)` and a grantee who knows the owner could recover\n * the scope from it with a small dictionary. Order and count are preserved,\n * so a redacted node is still identified by its position. A source that no\n * longer resolves comes back with `version: \"0\"`.\n *\n * A derived scope must not share its first dot-segment with any source scope\n * (a grant on `chatgpt.*` must never read a derivative of\n * `chatgpt.conversations`): see {@link assertDerivedScopeNaming}.\n *\n * @category Protocol\n */\n\nimport {\n  encodeAbiParameters,\n  isAddress,\n  keccak256,\n  type Address,\n  type Hex,\n} from \"viem\";\nimport { z } from \"zod\";\nimport { buildWeb3SignedHeader } from \"../auth/web3-signed-builder\";\nimport { LineageReadError, WriteRequestError } from \"../errors\";\nimport {\n  isRecord,\n  readPersonalServerErrorBody,\n} from \"./personal-server-error-body\";\nimport {\n  resolveWriteSigner,\n  type ResolveWriteSignerOptions,\n  type WriteSignerSource,\n} from \"./write-signer\";\n\nconst DATA_POINT_ID_PATTERN = /^0x[0-9a-fA-F]{64}$/;\n\n/** `true` when `value` is a 32-byte hex data point id. */\nexport function isDataPointId(value: unknown): value is Hex {\n  return typeof value === \"string\" && DATA_POINT_ID_PATTERN.test(value);\n}\n\n/**\n * Derive the DataRegistryV2 data point id for an owner and scope:\n * `keccak256(abi.encode(address ownerAddress, string scope))`.\n *\n * @param ownerAddress - The data owner (the Personal Server owner).\n * @param scope - The scope the data point is stored under.\n * @returns The 32-byte id, lowercase hex.\n * @throws Error when `ownerAddress` is not an EVM address.\n */\nexport function deriveDataPointId(ownerAddress: Address, scope: string): Hex {\n  if (!isAddress(ownerAddress, { strict: false })) {\n    throw new Error(\n      `ownerAddress is not an EVM address: ${String(ownerAddress)}`,\n    );\n  }\n  return keccak256(\n    encodeAbiParameters(\n      [\n        { name: \"ownerAddress\", type: \"address\" },\n        { name: \"scope\", type: \"string\" },\n      ],\n      [ownerAddress, scope],\n    ),\n  );\n}\n\nconst DataPointIdSchema = z\n  .string()\n  .regex(DATA_POINT_ID_PATTERN)\n  .transform((value) => value.toLowerCase() as Hex);\n\nconst VERSION_PATTERN = /^[1-9]\\d*$/;\nconst NODE_VERSION_PATTERN = /^(0|[1-9]\\d*)$/;\n\n// Versions are decimal integers, strings on the wire; a numeric value is\n// normalised to the same representation. A node's version may be \"0\": a\n// source that no longer resolves to a registered data point.\nconst VersionSchema = z\n  .union([z.string(), z.number()])\n  .transform(String)\n  .refine((value) => NODE_VERSION_PATTERN.test(value), {\n    message: \"version must be a decimal integer\",\n  });\n// The view's own version is a registered one: always positive.\nconst ViewVersionSchema = VersionSchema.refine(\n  (value) => VERSION_PATTERN.test(value),\n  { message: \"version must be a positive decimal integer\" },\n);\n\n/** First dot-segment of a scope (`chatgpt` for `chatgpt.conversations`). */\nexport function scopeNamespace(scope: string): string {\n  const dot = scope.indexOf(\".\");\n  return dot === -1 ? scope : scope.slice(0, dot);\n}\n\n/**\n * The naming rule: a derived scope and a source scope must not share their\n * first dot-segment, because a `prefix.*` grant would then cover both and\n * leak across the lineage edge. Mirrors the Personal Server's check\n * (`LINEAGE_SCOPE_UNDER_SOURCE_PREFIX`).\n */\nexport function derivedScopeViolatesNaming(\n  derivedScope: string,\n  sourceScope: string,\n): boolean {\n  return scopeNamespace(derivedScope) === scopeNamespace(sourceScope);\n}\n\n/**\n * Throw when `derivedScope` shares its first dot-segment with any source\n * scope (see {@link derivedScopeViolatesNaming}).\n *\n * @throws {WriteRequestError} Naming the offending source scope in `details`.\n */\nexport function assertDerivedScopeNaming(\n  derivedScope: string,\n  sourceScopes: readonly string[],\n): void {\n  for (const sourceScope of sourceScopes) {\n    if (derivedScopeViolatesNaming(derivedScope, sourceScope)) {\n      throw new WriteRequestError(\n        `Derived scope ${derivedScope} must not share its first segment with source scope ${sourceScope}; put derivatives in the app's own namespace`,\n        { scope: derivedScope, sourceScope },\n      );\n    }\n  }\n}\n\nexport const LineageNodeSchema = z.object({\n  dataPointId: DataPointIdSchema,\n  scope: z.string(),\n  /**\n   * The node's current version, decimal string; `\"0\"` for a source that no\n   * longer resolves to a registered data point.\n   */\n  version: VersionSchema,\n  /** The node's tombstone time, or `null` when live. */\n  deletedAt: z.string().nullable(),\n  /**\n   * Never present on a visible node. Declared so a node that carries\n   * `redacted: true` next to an id, scope and version cannot slip through\n   * this branch of {@link LineageEntrySchema} with the key stripped.\n   */\n  redacted: z.never().optional(),\n});\n\n/**\n * A redacted node is exactly `{ redacted: true }`. Any other key on it would\n * leak what the redaction hides, so the schema is strict: a view carrying a\n * redacted node with an id (or anything else) is refused rather than passed\n * through.\n */\nexport const RedactedLineageNodeSchema = z.strictObject({\n  redacted: z.literal(true),\n});\n\nexport const LineageEntrySchema = z.union([\n  RedactedLineageNodeSchema,\n  LineageNodeSchema,\n]);\n\nexport const LineageGraphSchema = z.object({\n  dataPointId: DataPointIdSchema,\n  /** The data point owner; every node in the view belongs to it. */\n  ownerAddress: z.string().optional(),\n  scope: z.string(),\n  /**\n   * The derived record's version whose lineage is shown: the requested one,\n   * else the current one, else (current is a tombstone) the last version\n   * that carried lineage.\n   */\n  version: ViewVersionSchema,\n  deletedAt: z.string().nullable(),\n  sources: z.array(LineageEntrySchema),\n  derivatives: z.array(LineageEntrySchema),\n  /** `true` when `derivatives` was cut at the server's cap (1000). */\n  derivativesTruncated: z.boolean().optional(),\n});\n\n/** A lineage node the caller is allowed to see. */\nexport type LineageNode = z.infer<typeof LineageNodeSchema>;\n\n/** A lineage node the caller holds no grant for: nothing but its position. */\nexport type RedactedLineageNode = z.infer<typeof RedactedLineageNodeSchema>;\n\n/** One entry of a lineage graph. Narrow with {@link isRedactedLineageNode}. */\nexport type LineageEntry = z.infer<typeof LineageEntrySchema>;\n\n/** The lineage view of one data point (the `data` of the response). */\nexport type LineageGraph = z.infer<typeof LineageGraphSchema>;\n\n/** A lineage read: the view plus the gateway's attestation over it. */\nexport interface LineageReadResult extends LineageGraph {\n  /**\n   * The gateway `proof` (`GatewayAttestation` over the served view, so a\n   * redacted view verifies on its own). Passed through as received; absent\n   * when the server sent none.\n   */\n  proof?: Record<string, unknown>;\n}\n\n/** `true` when the entry was redacted (the caller holds no grant for it). */\nexport function isRedactedLineageNode(\n  entry: LineageEntry,\n): entry is RedactedLineageNode {\n  return (\n    \"redacted\" in entry &&\n    entry.redacted === true &&\n    Object.keys(entry).length === 1\n  );\n}\n\n/**\n * The Personal Server lineage path: `/v1/data/:scope/lineage[/:version]`.\n * The version is a path segment (a query string is refused by the server),\n * so the signed `uri` covers the whole request.\n */\nexport function personalServerLineagePath(\n  scope: string,\n  version?: string | number,\n): string {\n  return `/v1/data/${encodeURIComponent(scope)}/lineage${version === undefined ? \"\" : `/${String(version)}`}`;\n}\n\n/**\n * The gateway lineage path: `/v1/data/<id lowercase>/lineage[/:version]`,\n * what the request is signed over and sent to. The grant view is the signed\n * `grantId` claim, never a query parameter.\n */\nexport function gatewayLineagePath(\n  dataPointId: Hex,\n  version?: string | number,\n): string {\n  return `/v1/data/${dataPointId.toLowerCase()}/lineage${version === undefined ? \"\" : `/${String(version)}`}`;\n}\n\ninterface LineageRequestOptions {\n  /**\n   * Read the lineage as of this version (a positive decimal integer);\n   * omitted = the current version, or the last version that carried lineage\n   * when the current one is a tombstone.\n   */\n  version?: string | number;\n  /** `fetch` to use; defaults to `globalThis.fetch`. */\n  fetch?: typeof fetch;\n  /** Extra request headers. */\n  headers?: HeadersInit;\n}\n\n/** Lineage read against the Personal Server holding the record. */\nexport interface PersonalServerLineageParams extends LineageRequestOptions {\n  /** Personal Server origin, e.g. `https://ps.example.com`. */\n  personalServerUrl: string;\n  /** The scope whose lineage to read. */\n  scope: string;\n  /** A grant covering the scope, sent as the signed `grantId` claim. */\n  grantId: string;\n  /** Builder key: a viem `LocalAccount`, `WalletClient`, or `{ signMessage }`. */\n  signer: WriteSignerSource;\n  /** Account for a viem wallet client without a hoisted account. */\n  account?: ResolveWriteSignerOptions[\"account\"];\n  /** Web3Signed audience; defaults to `personalServerUrl`. */\n  audience?: string;\n}\n\n/** Lineage read against the gateway, by data point id. */\nexport interface GatewayLineageParams extends LineageRequestOptions {\n  /** Gateway origin, e.g. `https://dp-rpc.vana.org`. */\n  gatewayUrl: string;\n  /** The data point whose lineage to read (see {@link deriveDataPointId}). */\n  dataPointId: Hex;\n  /**\n   * The key the request is signed with (Web3Signed, audience = the gateway\n   * origin). The signer decides the view: the owner or one of its servers\n   * gets the full view; a registered builder holding a live grant covering\n   * the data point's scope gets that grant's view; anyone else is refused.\n   */\n  signer: WriteSignerSource;\n  /** Account for a viem wallet client without a hoisted account. */\n  account?: ResolveWriteSignerOptions[\"account\"];\n  /**\n   * The grant whose view to read, sent lowercased as the signed `grantId`\n   * claim (never as a query parameter). An owner or server uses it to fetch\n   * the view a builder's grant sees; a builder needs it to see anything.\n   */\n  grantId?: string;\n}\n\nexport type GetLineageParams =\n  | PersonalServerLineageParams\n  | GatewayLineageParams;\n\nfunction normalizeBaseUrl(url: string): string {\n  return url.replace(/\\/+$/, \"\");\n}\n\nfunction resolveFetch(fetchFn: typeof fetch | undefined): typeof fetch {\n  const resolved = fetchFn ?? globalThis.fetch;\n  if (resolved === undefined) {\n    throw new LineageReadError(\"No fetch implementation available\");\n  }\n  return resolved;\n}\n\nfunction normalizeVersion(\n  version: string | number | undefined,\n): string | undefined {\n  if (version === undefined) return undefined;\n  const text = String(version);\n  if (!VERSION_PATTERN.test(text)) {\n    throw new LineageReadError(\n      \"version must be a positive decimal integer\",\n      undefined,\n      \"INVALID_VERSION\",\n      { version },\n    );\n  }\n  return text;\n}\n\nasync function lineageReadFailure(\n  source: string,\n  response: Response,\n): Promise<LineageReadError> {\n  const { errorCode, message, details } =\n    await readPersonalServerErrorBody(response);\n  return new LineageReadError(\n    message ??\n      `${source} lineage read failed: ${response.status} ${response.statusText}`,\n    response.status,\n    errorCode,\n    details,\n  );\n}\n\nasync function parseLineageGraph(\n  source: string,\n  response: Response,\n): Promise<LineageReadResult> {\n  let body: unknown;\n  try {\n    body = await response.json();\n  } catch (err) {\n    throw new LineageReadError(\n      `${source} lineage response is not JSON`,\n      response.status,\n      null,\n      { cause: err instanceof Error ? err.message : String(err) },\n    );\n  }\n  // Both servers answer the gateway envelope `{ data, proof }`; a bare view\n  // is accepted too.\n  const envelope = isRecord(body) && isRecord(body.data) ? body : undefined;\n  const parsed = LineageGraphSchema.safeParse(envelope?.data ?? body);\n  if (!parsed.success) {\n    throw new LineageReadError(\n      `${source} lineage response is not a lineage view`,\n      response.status,\n      null,\n      { issues: parsed.error.issues },\n    );\n  }\n  const proof = isRecord(envelope?.proof) ? envelope.proof : undefined;\n  return proof === undefined ? parsed.data : { ...parsed.data, proof };\n}\n\nasync function sendLineageRead(\n  source: string,\n  fetchFn: typeof fetch,\n  url: string,\n  headers: Headers,\n): Promise<LineageReadResult> {\n  let response: Response;\n  try {\n    response = await fetchFn(url, { method: \"GET\", headers });\n  } catch (err) {\n    throw new LineageReadError(\n      `${source} lineage read failed: ${err instanceof Error ? err.message : String(err)}`,\n      undefined,\n      null,\n      { cause: err instanceof Error ? err.message : String(err) },\n    );\n  }\n  if (!response.ok) {\n    throw await lineageReadFailure(source, response);\n  }\n  return parseLineageGraph(source, response);\n}\n\n/**\n * Read a scope's lineage from the Personal Server that stores it.\n *\n * @remarks\n * Sends `GET /v1/data/:scope/lineage[/:version]` with a Web3Signed\n * `Authorization` header carrying `grantId`, the same authentication a data\n * read uses; the signed `uri` is the full path, version segment included.\n * The server resolves the data point id, fetches the view the grant sees\n * from the gateway and returns the gateway's `data` + `proof`.\n *\n * @returns The lineage view, with redacted entries for nodes the grant does\n *   not cover, plus the gateway attestation.\n * @throws {LineageReadError} On a non-2xx answer (`errorCode`: read errors,\n *   `INVALID_VERSION`, `NOT_FOUND` when the scope or version is not\n *   registered at the gateway, `LINEAGE_FORBIDDEN`, `LINEAGE_GATEWAY_ERROR`,\n *   `LINEAGE_UNAVAILABLE`), an unreadable body, a bad `version`, or a\n *   transport failure.\n */\nexport async function getPersonalServerLineage(\n  params: PersonalServerLineageParams,\n): Promise<LineageReadResult> {\n  const fetchFn = resolveFetch(params.fetch);\n  const baseUrl = normalizeBaseUrl(params.personalServerUrl);\n  const audience = params.audience ?? baseUrl;\n  const signer = resolveWriteSigner(params.signer, { account: params.account });\n  const path = personalServerLineagePath(\n    params.scope,\n    normalizeVersion(params.version),\n  );\n  const headers = new Headers(params.headers);\n  headers.set(\n    \"Authorization\",\n    await buildWeb3SignedHeader({\n      signMessage: signer.signMessage,\n      aud: audience,\n      method: \"GET\",\n      uri: path,\n      grantId: params.grantId,\n    }),\n  );\n  return sendLineageRead(\n    \"Personal Server\",\n    fetchFn,\n    `${baseUrl}${path}`,\n    headers,\n  );\n}\n\n/**\n * Read a data point's lineage from the gateway.\n *\n * @remarks\n * Sends `GET /v1/data/:dataPointId/lineage[/:version]` with a Web3Signed\n * `Authorization` header: `aud` = the gateway origin, `uri` =\n * {@link gatewayLineagePath} (lowercase id, version segment included),\n * empty-body `bodyHash`, and the lowercased `grantId` claim when given. The\n * gateway answers a uniform 404 for an unknown data point and for a signer\n * it will not serve, so the two cannot be told apart from outside.\n *\n * @returns The lineage view, with redacted entries for nodes the caller's\n *   grant does not cover, plus the gateway attestation.\n * @throws {LineageReadError} On a malformed `dataPointId` or `version`, a\n *   non-2xx answer (400 malformed request, 401 `LINEAGE_SIGNATURE_REQUIRED`\n *   / `LINEAGE_SIGNATURE_INVALID`, 404 unknown or not served), an unreadable\n *   body, or a transport failure.\n */\nexport async function getGatewayLineage(\n  params: GatewayLineageParams,\n): Promise<LineageReadResult> {\n  if (!isDataPointId(params.dataPointId)) {\n    throw new LineageReadError(\n      \"dataPointId must be a 32-byte hex string (see deriveDataPointId)\",\n      undefined,\n      \"INVALID_DATA_POINT_ID\",\n      { dataPointId: params.dataPointId },\n    );\n  }\n  const fetchFn = resolveFetch(params.fetch);\n  const baseUrl = normalizeBaseUrl(params.gatewayUrl);\n  const signer = resolveWriteSigner(params.signer, { account: params.account });\n  const uri = gatewayLineagePath(\n    params.dataPointId,\n    normalizeVersion(params.version),\n  );\n  const headers = new Headers(params.headers);\n  headers.set(\n    \"Authorization\",\n    await buildWeb3SignedHeader({\n      signMessage: signer.signMessage,\n      aud: baseUrl,\n      method: \"GET\",\n      uri,\n      grantId: params.grantId?.toLowerCase(),\n    }),\n  );\n  return sendLineageRead(\"Gateway\", fetchFn, `${baseUrl}${uri}`, headers);\n}\n\n/**\n * Read a lineage view from either the Personal Server (by scope) or the\n * gateway (by data point id), chosen by the params shape.\n *\n * @example\n * ```typescript\n * const fromPs = await getLineage({ personalServerUrl, scope, grantId, signer });\n * const fromGateway = await getLineage({ gatewayUrl, dataPointId, grantId, signer });\n * ```\n */\nexport function getLineage(\n  params: GetLineageParams,\n): Promise<LineageReadResult> {\n  return \"personalServerUrl\" in params\n    ? getPersonalServerLineage(params)\n    : getGatewayLineage(params);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,kBAMO;AACP,iBAAkB;AAClB,iCAAsC;AACtC,oBAAoD;AACpD,wCAGO;AACP,0BAIO;AAEP,MAAM,wBAAwB;AAGvB,SAAS,cAAc,OAA8B;AAC1D,SAAO,OAAO,UAAU,YAAY,sBAAsB,KAAK,KAAK;AACtE;AAWO,SAAS,kBAAkB,cAAuB,OAAoB;AAC3E,MAAI,KAAC,uBAAU,cAAc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