{"version":3,"sources":["../../src/protocol/data-point-status.ts"],"sourcesContent":["/**\n * On-chain status mutation primitives for DataRegistryV2 data points.\n *\n * The v2 contract drops the file concept in favor of versioned data points\n * keyed on (owner, scope). Each data point has a lifecycle Status that the\n * owner can change directly — there's no EIP-712 signature flow and no\n * gateway endpoint that mediates this, because the contract enforces\n * `msg.sender == owner` for `setStatus`. The owner therefore has to sign\n * and broadcast the tx from their own wallet.\n *\n * These helpers are signer/transport-agnostic — they return the raw\n * `{to, data}` request object so callers can feed it to any wallet stack\n * (viem `sendTransaction`/`writeContract`, ethers, wallet-rpc, MPC,\n * Safe transactions, etc.). Mirrors the shape used by `escrow-deposit.ts`.\n *\n * @category Protocol\n */\nimport { encodeFunctionData } from \"viem\";\nimport type { DataPortabilityGatewayConfig } from \"./eip712\";\n\n// Lifecycle states from IDataRegistryV2.Status. Wire encoding is uint8.\n// - None: no data point exists for this (owner, scope).\n// - Active: has data, served on /v1/escrow/pay's recordDataAccess path.\n// - Inactive: owner-paused — refuses new versions until re-activated.\n//   `addData` (or addDataWithSignature) auto-revives Inactive → Active.\n// - Unavailable: terminal soft-delete — `addData` and recordDataAccess both\n//   revert. The owner can still resurrect by calling setStatus(Active), but\n//   that signals intent to bring the data point back online; a downstream\n//   client treating Unavailable as a delete tombstone should re-fetch after\n//   any DataPointStatusChanged event.\nexport enum DataPointStatus {\n  None = 0,\n  Active = 1,\n  Inactive = 2,\n  Unavailable = 3,\n}\n\n// Minimal ABI fragment for the owner-only `setStatus(scope, newStatus)`\n// entry point. Kept inline so callers don't have to load the full contract\n// ABI just to change a status.\nexport const DATA_REGISTRY_STATUS_ABI = [\n  {\n    type: \"function\",\n    name: \"setStatus\",\n    stateMutability: \"nonpayable\",\n    inputs: [\n      { name: \"scope\", type: \"string\" },\n      { name: \"newStatus\", type: \"uint8\" },\n    ],\n    outputs: [],\n  },\n] as const;\n\nexport function dataRegistryContractAddress(\n  config: DataPortabilityGatewayConfig,\n): `0x${string}` {\n  return config.contracts.dataRegistry as `0x${string}`;\n}\n\nexport interface SetDataPointStatusInput {\n  scope: string;\n  status: DataPointStatus;\n}\n\n// Shape compatible with viem's `sendTransaction` / `writeContract` request\n// objects. No `value` — `setStatus` is non-payable.\nexport interface DataPointStatusTransactionRequest {\n  to: `0x${string}`;\n  data: `0x${string}`;\n}\n\nexport function encodeSetDataPointStatusData(\n  input: SetDataPointStatusInput,\n): `0x${string}` {\n  return encodeFunctionData({\n    abi: DATA_REGISTRY_STATUS_ABI,\n    functionName: \"setStatus\",\n    args: [input.scope, input.status],\n  });\n}\n\n// Build the full tx request for a status change. Feed straight to\n// `walletClient.sendTransaction({...req, account, chain})`. The caller's\n// `account` MUST equal the data point's owner — the contract reverts\n// otherwise.\nexport function buildSetDataPointStatusRequest(\n  config: DataPortabilityGatewayConfig,\n  input: SetDataPointStatusInput,\n): DataPointStatusTransactionRequest {\n  return {\n    to: dataRegistryContractAddress(config),\n    data: encodeSetDataPointStatusData(input),\n  };\n}\n\n// Convenience for the \"remove this data point\" intent — the v2 equivalent\n// of the old DELETE /v1/files/:id flow. Sets the status to Unavailable so\n// downstream readers (recordDataAccess, future addData) revert. Callers\n// that want the data point pausable rather than tombstoned should use\n// `buildSetDataPointStatusRequest` with `DataPointStatus.Inactive`.\nexport function buildMarkDataPointUnavailableRequest(\n  config: DataPortabilityGatewayConfig,\n  input: { scope: string },\n): DataPointStatusTransactionRequest {\n  return buildSetDataPointStatusRequest(config, {\n    scope: input.scope,\n    status: DataPointStatus.Unavailable,\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,kBAAmC;AAa5B,IAAK,kBAAL,kBAAKA,qBAAL;AACL,EAAAA,kCAAA,UAAO,KAAP;AACA,EAAAA,kCAAA,YAAS,KAAT;AACA,EAAAA,kCAAA,cAAW,KAAX;AACA,EAAAA,kCAAA,iBAAc,KAAd;AAJU,SAAAA;AAAA,GAAA;AAUL,MAAM,2BAA2B;AAAA,EACtC;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,iBAAiB;AAAA,IACjB,QAAQ;AAAA,MACN,EAAE,MAAM,SAAS,MAAM,SAAS;AAAA,MAChC,EAAE,MAAM,aAAa,MAAM,QAAQ;AAAA,IACrC;AAAA,IACA,SAAS,CAAC;AAAA,EACZ;AACF;AAEO,SAAS,4BACd,QACe;AACf,SAAO,OAAO,UAAU;AAC1B;AAcO,SAAS,6BACd,OACe;AACf,aAAO,gCAAmB;AAAA,IACxB,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM;AAAA,EAClC,CAAC;AACH;AAMO,SAAS,+BACd,QACA,OACmC;AACnC,SAAO;AAAA,IACL,IAAI,4BAA4B,MAAM;AAAA,IACtC,MAAM,6BAA6B,KAAK;AAAA,EAC1C;AACF;AAOO,SAAS,qCACd,QACA,OACmC;AACnC,SAAO,+BAA+B,QAAQ;AAAA,IAC5C,OAAO,MAAM;AAAA,IACb,QAAQ;AAAA,EACV,CAAC;AACH;","names":["DataPointStatus"]}