{
  "openrpc": "1.2.6",
  "info": {
    "title": "dig RPC — node profile (local dig-node / dig-companion / in-process DIG Browser)",
    "version": "1.0.0",
    "description": "The NODE PROFILE: a distinct, smaller surface than the network profile. Of the byte methods it implements ONLY dig.getContent (local-first, else proxy); everything else proxies upstream or returns -32601. It ADDS node-only methods the security model depends on — chiefly dig.getAnchoredRoot (the CHIP-0035 on-chain head, the trusted root for mandatory root-pinning), dig.stage, and cache.*. Gate on dig.methods rather than assuming one uniform surface. See https://docs.dig.net/docs/protocol/dig-rpc#node-profile.",
    "license": {
      "name": "GPL-2.0",
      "url": "https://github.com/DIG-Network/digstore/blob/main/LICENSE"
    }
  },
  "servers": [
    {
      "name": "local dig-node",
      "url": "http://127.0.0.1:9778",
      "summary": "The local node the DIG Browser runs in-process (FFI) and dig-node serves on 127.0.0.1:9778."
    }
  ],
  "methods": [
    {
      "name": "dig.getContent",
      "summary": "Stream one resource’s ciphertext (local-first, then proxy).",
      "description": "Identical wire contract to the network profile, but served LOCAL-FIRST: from a cached compiled .dig (serve_blind over <cache>/modules/<store>/<root>.module), else an authenticated §21.9 whole-store sync, else the raw JSON-RPC body is proxied upstream to rpc.dig.net. The in-process node ADDITIVELY tags each chunk with `source` (\"local\"|\"remote\").",
      "paramStructure": "by-name",
      "params": [
        {
          "name": "store_id",
          "required": true,
          "schema": {
            "$ref": "#/components/schemas/StoreId"
          }
        },
        {
          "name": "retrieval_key",
          "required": true,
          "schema": {
            "$ref": "#/components/schemas/RetrievalKey"
          }
        },
        {
          "name": "root",
          "required": false,
          "schema": {
            "$ref": "#/components/schemas/Root"
          }
        },
        {
          "name": "offset",
          "required": false,
          "schema": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          }
        },
        {
          "name": "length",
          "required": false,
          "description": "Clamped to the node window (3 MiB).",
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "result": {
        "name": "chunk",
        "schema": {
          "$ref": "#/components/schemas/ChunkObject"
        }
      },
      "errors": [
        {
          "$ref": "#/components/errors/INVALID_PARAMS"
        },
        {
          "$ref": "#/components/errors/INTERNAL_ERROR"
        },
        {
          "$ref": "#/components/errors/RESOURCE_UNAVAILABLE"
        }
      ]
    },
    {
      "name": "dig.getAnchoredRoot",
      "summary": "Resolve the store’s CHIP-0035 on-chain head root (the trusted root).",
      "description": "Walks the CHIP-0035 DataStore singleton lineage on coinset.org (digstore_chain::singleton::sync_datastore) and returns metadata.root_hash — the on-chain-anchored tip. This is the TRUSTED root a client pins a rootless chia:// URN against; verification must never trust the rpc-served \"latest\". Coinset host defaults to api.coinset.org (override DIG_NODE_COINSET). NODE-PROFILE ONLY: absent from the network profile (dig-node lib.rs:721-743).",
      "paramStructure": "by-name",
      "params": [
        {
          "name": "store_id",
          "required": true,
          "schema": {
            "$ref": "#/components/schemas/StoreId"
          }
        }
      ],
      "result": {
        "name": "anchored",
        "schema": {
          "type": "object",
          "properties": {
            "store_id": {
              "$ref": "#/components/schemas/StoreId"
            },
            "root": {
              "$ref": "#/components/schemas/StoreId"
            }
          }
        }
      },
      "errors": [
        {
          "$ref": "#/components/errors/INVALID_PARAMS"
        },
        {
          "$ref": "#/components/errors/INTERNAL_ERROR"
        }
      ]
    },
    {
      "name": "dig.stage",
      "summary": "Compile a local folder into a capsule .dig, in-process.",
      "description": "Compiles a local directory into a capsule (.dig) in-process for preview/publish. NODE-PROFILE ONLY (dig-node lib.rs:768-904).",
      "paramStructure": "by-name",
      "params": [
        {
          "name": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "result": {
        "name": "staged",
        "schema": {
          "type": "object",
          "properties": {
            "store_id": {
              "$ref": "#/components/schemas/StoreId"
            },
            "root": {
              "$ref": "#/components/schemas/StoreId"
            }
          }
        }
      },
      "errors": [
        {
          "$ref": "#/components/errors/INVALID_PARAMS"
        },
        {
          "$ref": "#/components/errors/INTERNAL_ERROR"
        }
      ]
    },
    {
      "name": "cache.getConfig",
      "summary": "Read the local node cache configuration.",
      "description": "Part of the node-only cache.* control surface (getConfig/setCapBytes/clear/listCached/removeCached/fetchAndCache). NODE-PROFILE ONLY (dig-node lib.rs:1143-1231).",
      "paramStructure": "by-name",
      "params": [],
      "result": {
        "name": "config",
        "schema": {
          "type": "object"
        }
      },
      "errors": [
        {
          "$ref": "#/components/errors/INTERNAL_ERROR"
        }
      ]
    }
  ],
  "components": {
    "schemas": {
      "StoreId": {
        "type": "string",
        "pattern": "^[0-9a-f]{64}$",
        "description": "32 bytes as 64 lower-case hex characters.",
        "title": "StoreId"
      },
      "RetrievalKey": {
        "type": "string",
        "pattern": "^[0-9a-f]{64}$",
        "description": "retrieval_key = sha256(urn).",
        "title": "RetrievalKey"
      },
      "Root": {
        "title": "Root",
        "oneOf": [
          {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          {
            "type": "string",
            "const": "latest"
          }
        ],
        "description": "A generation root: 64 hex of one capsule, or the literal \"latest\" for the newest confirmed generation."
      },
      "ChunkObject": {
        "title": "ChunkObject",
        "type": "object",
        "description": "The streaming chunk object returned by every byte-bearing method (dig.getContent, dig.getCapsule, dig.getManifest). Reassemble until `complete`, verify `inclusion_proof` over the whole ciphertext against the CALLER-supplied chain-anchored `root`, split by `chunk_lens`, then AES-256-GCM-SIV-open each chunk. There is NO `decoy` field on the wire: a blind miss is the capsule's own indistinguishable, non-verifying response, discovered client-side by inclusion-proof failure and/or decryption-tag failure.",
        "required": [
          "ciphertext",
          "total_length",
          "offset",
          "length",
          "complete",
          "next_offset",
          "inclusion_proof",
          "root"
        ],
        "properties": {
          "ciphertext": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "This window's bytes, standard base64."
          },
          "total_length": {
            "type": "integer",
            "minimum": 0,
            "description": "The full resource ciphertext length before windowing."
          },
          "offset": {
            "type": "integer",
            "minimum": 0,
            "description": "Byte offset where this window begins in the full object."
          },
          "length": {
            "type": "integer",
            "minimum": 0,
            "description": "This window's byte length (= decoded ciphertext length)."
          },
          "complete": {
            "type": "boolean",
            "description": "true when offset + length >= total_length."
          },
          "next_offset": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The offset to request next, or null when complete."
          },
          "inclusion_proof": {
            "type": [
              "string",
              "null"
            ],
            "contentEncoding": "base64",
            "description": "Base64 merkle inclusion proof for the WHOLE resource, relayed verbatim from the capsule. Sent on every window for getContent/getManifest; empty string / null for getCapsule."
          },
          "chunk_lens": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0
            },
            "description": "Per-chunk CIPHERTEXT byte lengths of the full resource, in order. REQUIRED to split + decrypt a multi-chunk resource. Emitted on the FIRST window only (offset == 0); empty/absent ⇒ a single chunk = the whole ciphertext."
          },
          "root": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "The resolved generation root (hex). Pin subsequent chunks to it."
          },
          "program_hash": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "The served .dig's sha256 (hex) — the on-chain program identity."
          }
        }
      },
      "MetadataManifest": {
        "title": "MetadataManifest",
        "type": "object",
        "description": "The store's plaintext, ungated metadata manifest, embedded in the compiled module (Digstore §8.4).",
        "properties": {
          "schema_version": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "authors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "handle": {
                  "type": "string"
                },
                "contact": {
                  "type": "string"
                }
              }
            }
          },
          "license": {
            "type": "string"
          },
          "homepage": {
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "keywords": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "icon": {
            "type": "string"
          },
          "content_type": {
            "type": "string"
          },
          "links": {
            "type": "object"
          },
          "custom": {
            "type": "object"
          }
        }
      },
      "CapsuleEntry": {
        "title": "CapsuleEntry",
        "type": "object",
        "description": "One confirmed capsule (anchored generation) in a store lineage.",
        "required": [
          "seq",
          "root"
        ],
        "properties": {
          "seq": {
            "type": "integer",
            "minimum": 0,
            "description": "Monotonic generation number."
          },
          "root": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "The generation root passed to the byte methods."
          },
          "program_hash": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "32 bytes as 64 lower-case hex characters."
          },
          "coin_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "The anchoring spend coin id."
          },
          "anchored_at": {
            "type": "integer",
            "description": "Unix timestamp of the anchoring spend."
          }
        }
      }
    },
    "errors": {
      "PARSE_ERROR": {
        "code": -32700,
        "message": "Parse error",
        "data": {
          "type": "object"
        }
      },
      "INVALID_REQUEST": {
        "code": -32600,
        "message": "Invalid request",
        "data": {
          "type": "object"
        }
      },
      "METHOD_NOT_FOUND": {
        "code": -32601,
        "message": "Method not found",
        "data": {
          "type": "object"
        }
      },
      "INVALID_PARAMS": {
        "code": -32602,
        "message": "Invalid params",
        "data": {
          "type": "object"
        }
      },
      "INTERNAL_ERROR": {
        "code": -32603,
        "message": "Internal error",
        "data": {
          "type": "object"
        }
      },
      "RESOURCE_UNAVAILABLE": {
        "code": -32004,
        "message": "Resource not available at the requested root",
        "data": {
          "type": "object"
        }
      }
    }
  },
  "externalDocs": {
    "description": "dig RPC methods (prose)",
    "url": "https://docs.dig.net/docs/protocol/dig-rpc"
  }
}
