> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ana.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# Stage a rule document

> Sends a sealed rule document to the engine. The engine opens it, checks it, and
returns the attestation (`engineSig`) that the on-chain commit needs. The Anafi API
passes the envelope through without reading it.

A staged document does nothing until the owner commits it on chain with
`AnafiDslRegistry.commitDsl(commitment, attestationValidUntil, engineSig, adapter)`.
See [DSL registry](/contracts/dsl-registry).

- Who may call: anyone. The route needs no sign-in, because only the owner can
  commit.
- Before: build the stage frame, seal it under the `info` tag
  `anafi/dsl-seal/<network>/` plus the 20 address bytes of `aa`, and keep the
  response key. See [Sealed requests](/api-reference/sealed-requests).
- Check the reply before the owner signs: `commitment` must equal your own
  `keccak256(salt ‖ yaml)`, and `adapter` must equal the adapter that you sealed.
- Guarantee: `engineSig` is valid for `commitDsl` until `attestationValidUntil`,
  about 30 minutes after the stage, and only while the on-chain document is still
  the parent that you named.

Each call stages again. The engine limits how many staged documents it keeps, and
answers `429` with `staged_dsl_cap_reached` when the limit is reached.




## OpenAPI

````yaml /api/openapi.yaml post /api/wallets/{aa}/dsl/commit/stage
openapi: 3.1.0
info:
  title: Anafi API
  version: 0.3.0
  summary: The public HTTP API of one Anafi network.
  description: >
    The Anafi API is the HTTP surface of one Anafi network. Each network has its
    own host.

    The public TypeScript SDK `@anafi-cc/anafi-sdk` calls these routes for you,
    and it also

    builds and checks the signed and sealed payloads. You can call the routes
    directly.


    - No API key is necessary today.

    - Request and response bodies are JSON, except where an operation says
    otherwise.

    - A route that carries a confidential payload takes an HPKE-sealed envelope.
    Read
      [Sealed requests](/api-reference/sealed-requests) before you call it without the SDK.
    - Read [Introduction](/api-reference/introduction) for formats and
      [Errors](/api-reference/errors) for the error bodies.

    Browser origin: the API hosts answer CORS only for `https://app.ana.fi`
    today. A browser

    page on another origin cannot call the API directly. A server, a script, or
    your own

    same-origin proxy can call it.
servers:
  - url: https://api.polygon.ana.fi
    description: Polygon PoS (chain id 137)
  - url: https://api.xlayer.ana.fi
    description: X Layer (chain id 196)
  - url: https://api.polygon-amoy.ana.fi
    description: Polygon Amoy testnet (chain id 80002)
security: []
tags:
  - name: Accounts
    description: >-
      Find the accounts of an owner address, and deploy the 1-of-1 Safe of an
      owner.
  - name: Safe relay
    description: Submit an owner-signed Safe transaction. Anafi pays the gas.
  - name: Rules
    description: >-
      Stage a sealed rule document. The engine returns the attestation for the
      on-chain commit.
  - name: Confidential channel
    description: >-
      Read back the rule document and the account state of an account through a
      sealed channel.
  - name: Notification email
    description: Verify the email address that rule notifications go to.
  - name: Activity
    description: Read the payments that the engine made for an account.
  - name: Fees
    description: Read the fee terms of the network and the sponsorship of an account.
  - name: Payments
    description: Ask for the email receipt of a payment made on the pay page.
  - name: Rule language
    description: >-
      Read the rule language reference, and write a rule document from a
      description.
  - name: Bank payouts
    description: >
      Connect a Safe to Monerium for bank payouts in euro, and read the state of
      the

      connection and of the orders. These routes are served only on
      `polygon-amoy`

      (Monerium sandbox). The `polygon` and `xlayer` hosts answer `404`.
  - name: Status
    description: Check that the Anafi API answers.
paths:
  /api/wallets/{aa}/dsl/commit/stage:
    post:
      tags:
        - Rules
      summary: Stage a rule document
      description: >
        Sends a sealed rule document to the engine. The engine opens it, checks
        it, and

        returns the attestation (`engineSig`) that the on-chain commit needs.
        The Anafi API

        passes the envelope through without reading it.


        A staged document does nothing until the owner commits it on chain with

        `AnafiDslRegistry.commitDsl(commitment, attestationValidUntil,
        engineSig, adapter)`.

        See [DSL registry](/contracts/dsl-registry).


        - Who may call: anyone. The route needs no sign-in, because only the
        owner can
          commit.
        - Before: build the stage frame, seal it under the `info` tag
          `anafi/dsl-seal/<network>/` plus the 20 address bytes of `aa`, and keep the
          response key. See [Sealed requests](/api-reference/sealed-requests).
        - Check the reply before the owner signs: `commitment` must equal your
        own
          `keccak256(salt ‖ yaml)`, and `adapter` must equal the adapter that you sealed.
        - Guarantee: `engineSig` is valid for `commitDsl` until
        `attestationValidUntil`,
          about 30 minutes after the stage, and only while the on-chain document is still
          the parent that you named.

        Each call stages again. The engine limits how many staged documents it
        keeps, and

        answers `429` with `staged_dsl_cap_reached` when the limit is reached.
      operationId: stageDslCommit
      parameters:
        - $ref: '#/components/parameters/AccountPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SealedRelayRequest'
            example:
              sealed:
                kem_pk:
                  - 131
                  - 22
                  - 7
                  - 240
                  - 18
                  - 77
                  - 5
                  - 199
                  - 61
                  - 3
                  - 88
                  - 140
                  - 211
                  - 9
                  - 47
                  - 100
                  - 12
                  - 250
                  - 33
                  - 64
                  - 17
                  - 92
                  - 180
                  - 6
                  - 71
                  - 39
                  - 145
                  - 201
                  - 8
                  - 55
                  - 160
                  - 26
                ct:
                  - 17
                  - 204
                  - 93
                  - 6
                  - 145
                  - 220
                  - 61
                  - 2
                  - 118
                  - 33
                  - 9
                  - 250
                  - 4
                  - 77
                  - 18
                  - 160
                  - 5
                  - 66
                  - 201
                  - 140
      responses:
        '200':
          description: The engine staged and attested the document.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StageDslCommitResponse'
              example:
                commitment: >-
                  0x3c6e0b8a024d5c2f1b7e9a4d6c8f0e2a4b6c8d0e2f4a6b8c0d2e4f6a8b0c2d4e
                engineSig: >-
                  0xed9f6f25068608efd412958da4dfc19328ca3511251fa6d5f9c42baf230e32f87c2a91d04e5b3f6a8d1c0e9b7f2a4c6e8d0b1f3a5c7e9d2b4f6a8c0e1d3f5a7b1c
                dslVersion: 1
                attestationValidUntil: 1796308602
                adapter: '0x5f3c0e1b2a4d6e8f0a1b2c3d4e5f60718293a4b5'
                sealedWarnings:
                  nonce:
                    - 12
                    - 201
                    - 4
                    - 77
                    - 150
                    - 3
                    - 88
                    - 9
                    - 61
                    - 240
                    - 18
                    - 33
                  ct:
                    - 201
                    - 14
                    - 90
                    - 3
                    - 66
                    - 129
                    - 4
                    - 250
                    - 17
                    - 8
                    - 61
                    - 92
                    - 140
                    - 7
                    - 33
                    - 2
                    - 99
                    - 180
                    - 21
                    - 6
        '400':
          $ref: '#/components/responses/InvalidPathOrJson'
        '409':
          description: >
            Stale parent. The on-chain document is no longer the parent that the
            frame

            named, because another commit landed. Open `sealed_error`. Its
            `reason` is

            `stale_parent` and `current_document` names the on-chain document.
            Rebuild the

            document on that parent and stage again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DslStageRefusal'
        '413':
          $ref: '#/components/responses/BodyTooLarge'
        '415':
          $ref: '#/components/responses/MissingJsonContentType'
        '422':
          description: >
            The engine refused the document, or the body is not valid.

            - JSON `{"error":"invalid_dsl","sealed_error":...}`: the document is
            not valid,
              or it names a notification email that the account has not verified (`reason`
              `notification_email_not_verified`). Open `sealed_error` with the response
              key and show `message` to the author.
            - Plain text from the engine: the envelope did not open under the
            `info` tag of
              this network and this `aa`, or the frame is malformed, or the named adapter is
              not live on this chain.
            - Plain text from the Anafi API: a JSON field is missing or has the
            wrong type.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DslStageRefusal'
            text/plain:
              schema:
                $ref: '#/components/schemas/PlainTextError'
              example: could not open or validate the sealed DSL
        '429':
          description: >-
            The engine keeps the maximum count of staged documents. Commit or
            wait, then stage again.
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/PlainTextError'
              example: staged_dsl_cap_reached
        '500':
          description: The engine could not store, sign or seal the reply. Try again later.
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/PlainTextError'
        '502':
          description: >
            The engine could not be reached, could not read the chain, or sent a
            reply that

            the Anafi API could not read. Try again later.
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/PlainTextError'
              example: engine unreachable
components:
  parameters:
    AccountPath:
      name: aa
      in: path
      required: true
      description: >-
        The account address (a Safe or a plain address), as `0x` and 40 hex
        digits in any letter case.
      schema:
        $ref: '#/components/schemas/Address'
      example: '0xf9836de53d455019ed985896fce8af80be66b7f9'
  schemas:
    SealedRelayRequest:
      type: object
      description: >-
        The body of every route that carries a sealed request. The Anafi API
        passes `sealed` to the engine unchanged and takes the account from the
        path.
      required:
        - sealed
      properties:
        sealed:
          $ref: '#/components/schemas/SealedEnvelope'
    StageDslCommitResponse:
      type: object
      description: >-
        The attestation of the engine for one staged document. Pass the values
        to `AnafiDslRegistry.commitDsl` without change.
      required:
        - commitment
        - engineSig
        - dslVersion
        - attestationValidUntil
        - adapter
        - sealedWarnings
      properties:
        commitment:
          $ref: '#/components/schemas/Bytes32Hex'
          description: >-
            The commitment `keccak256(salt ‖ yaml)`. Compare it with your own
            value before the owner signs. A difference means that the document
            was changed on the way.
        engineSig:
          $ref: '#/components/schemas/HexBytes'
          description: >-
            The signature of the engine over the commit digest. Pass it to
            `commitDsl` as `engineSig`.
        dslVersion:
          type: integer
          minimum: 1
          description: >-
            The version that this document gets when it is committed. It is the
            current on-chain version of the account plus 1. It is not a version
            of the language or of a contract.
        attestationValidUntil:
          $ref: '#/components/schemas/UnixSeconds'
          description: >-
            The time at which `engineSig` expires, about 30 minutes after the
            stage. Pass this exact value to `commitDsl` as `validUntil`. Another
            value fails the signature check.
        adapter:
          $ref: '#/components/schemas/Address'
          description: >-
            The adapter that the engine bound into the signature. It must equal
            the adapter in your frame. Pass it to `commitDsl`.
        sealedWarnings:
          $ref: '#/components/schemas/SealedResponse'
          description: >-
            Advisory findings about the document, sealed to the caller. The
            opened JSON is `{"messages": ["..."]}`. The list is empty for a
            clean document. The findings do not stop the commit.
    DslStageRefusal:
      type: object
      description: >
        A refusal of a staged document. The reason is sealed to the caller. Open

        `sealed_error` with the response key of the stage request. The opened
        JSON has

        `message` (text for the author), and can have `reason` (`stale_parent`
        or

        `notification_email_not_verified`) and `current_document` (`version` and
        `hash`,

        only with `stale_parent`).
      required:
        - error
        - sealed_error
      properties:
        error:
          type: string
          const: invalid_dsl
          description: >-
            Always `invalid_dsl`. The status code tells a refusal (`422`) from a
            stale parent (`409`).
        sealed_error:
          $ref: '#/components/schemas/SealedResponse'
    PlainTextError:
      type: string
      description: >-
        A short English sentence. Show it or log it. Do not parse it; branch on
        the status code.
    Address:
      type: string
      pattern: ^0x[0-9a-fA-F]{40}$
      description: >-
        A 20-byte address as `0x` and 40 hex digits. Requests accept any letter
        case. Responses use lowercase.
      examples:
        - '0xf9836de53d455019ed985896fce8af80be66b7f9'
    SealedEnvelope:
      type: object
      description: >
        An HPKE-sealed request. Each field is a JSON array of byte values
        (integers from 0 to

        255), not a hex string. The key names are snake_case. See

        [Sealed requests](/api-reference/sealed-requests).
      required:
        - kem_pk
        - ct
      additionalProperties: false
      properties:
        kem_pk:
          type: array
          description: >-
            The encapsulated key of the sender, an ephemeral X25519 public key
            of 32 bytes.
          minItems: 32
          maxItems: 32
          items:
            type: integer
            minimum: 0
            maximum: 255
        ct:
          type: array
          description: >-
            The ciphertext, which is the sealed payload and the 16-byte AEAD
            tag.
          minItems: 16
          items:
            type: integer
            minimum: 0
            maximum: 255
    Bytes32Hex:
      type: string
      pattern: ^0x[0-9a-f]{64}$
      description: 32 bytes as `0x` and 64 lowercase hex digits.
    HexBytes:
      type: string
      pattern: ^0x([0-9a-fA-F]{2})*$
      description: Bytes as `0x` and an even count of hex digits.
    UnixSeconds:
      type: integer
      description: Seconds since 1970-01-01T00:00:00Z.
      examples:
        - 1796305002
    SealedResponse:
      type: object
      description: >
        A reply sealed with ChaCha20-Poly1305 under the response key that the
        caller

        exported from the HPKE context of the request. Each field is a JSON
        array of byte

        values. See [Sealed requests](/api-reference/sealed-requests).
      required:
        - nonce
        - ct
      properties:
        nonce:
          type: array
          description: The 12-byte AEAD nonce.
          minItems: 12
          maxItems: 12
          items:
            type: integer
            minimum: 0
            maximum: 255
        ct:
          type: array
          description: The ciphertext with its 16-byte AEAD tag.
          minItems: 16
          items:
            type: integer
            minimum: 0
            maximum: 255
  responses:
    InvalidPathOrJson:
      description: The `aa` path segment is not an address, or the body is not valid JSON.
      content:
        text/plain:
          schema:
            $ref: '#/components/schemas/PlainTextError'
          example: >-
            Failed to parse the request body as JSON: EOF while parsing an
            object at line 1 column 1
    BodyTooLarge:
      description: >-
        The body is larger than the limit of the route. The limit is 2 MB for
        `POST /api/dsl/generate` and the bank payout routes, and 512 KiB for all
        other routes.
      content:
        text/plain:
          schema:
            $ref: '#/components/schemas/PlainTextError'
    MissingJsonContentType:
      description: 'The request has no `Content-Type: application/json` header.'
      content:
        text/plain:
          schema:
            $ref: '#/components/schemas/PlainTextError'
          example: 'Expected request with `Content-Type: application/json`'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.