{
  "openapi": "3.1.0",
  "info": {
    "title": "Amanah Service API",
    "version": "1.0.0",
    "summary": "Record bank-confirmed donations on the Amanah Ledger and retrieve their status and proof.",
    "description": "Amanah Service is the backend API that donation platforms integrate with. A platform submits each donation that its bank has\nconfirmed; Amanah Service validates it, queues it, and records a tamper-evident commitment on the Solana blockchain.\nDonors and anyone else can then look the record up in Amanah Explorer.\n\nThis reference documents the public, platform-facing `/v1` routes only. Operator and registry routes (`/admin`, `/internal`)\nare not part of the public API and are not documented here.\n\n## Getting access\n\nKeys are issued by the Amanah Ledger team, not self-served. Use \"Register interest\" on the landing page\n(https://amanah-ledger.com/#interest) or write to contact@amanah-ledger.com. You receive a key id and a secret; the secret is\nshown once and cannot be retrieved again. Your platform must also be registered and active on-chain, and every recipient\nwallet you donate to must be a verified recipient in Amanah Registry (otherwise `422`).\n\n## Authentication: signed requests\n\nEvery request carries four headers and is authenticated with HMAC-SHA256 over the exact request. There is no bearer token.\n\n| Header | Value |\n|---|---|\n| `X-Key-Id` | Your key id, for example `k_AbC...` (at most 128 characters). |\n| `X-Timestamp` | Current Unix time in whole seconds (1 to 12 digits). |\n| `X-Nonce` | A fresh unique string per request, 16 to 64 characters of `A-Z a-z 0-9 _ -`. |\n| `X-Signature` | Lowercase hex (64 characters) of the HMAC-SHA256 described below. |\n\nThe signed string (the \"canonical string\") is five fields joined with `|`:\n\n```\nMETHOD|PATH_AND_QUERY|TIMESTAMP|NONCE|SHA256_HEX_OF_BODY\n```\n\n- `METHOD` is upper case (`GET`, `POST`).\n- `PATH_AND_QUERY` is the request target exactly as it goes on the wire: the path plus the query string if any, not decoded and not\n  normalised (for example `/v1/donations/0b6c.../proof`).\n- `TIMESTAMP` and `NONCE` are the same strings you send in the headers.\n- `SHA256_HEX_OF_BODY` is the lowercase hex SHA-256 of the exact body bytes you send. For a request with no body it is the hash of\n  the empty string, `e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`.\n\nThe signature is `hex( HMAC_SHA256( key = secret as a UTF-8 string, message = canonical string ) )`. The secret is used as the\nliteral string you were given (do not base64-decode it).\n\nSign the bytes you send: do not re-serialise the JSON after signing.\n\n```js\n// Node.js\nimport { createHash, createHmac, randomBytes } from \"node:crypto\";\nconst body = JSON.stringify(payload);                       // send exactly these bytes\nconst ts = String(Math.floor(Date.now() / 1000));\nconst nonce = randomBytes(16).toString(\"hex\");\nconst canonical = [\"POST\", \"/v1/donations\", ts, nonce, createHash(\"sha256\").update(body).digest(\"hex\")].join(\"|\");\nconst signature = createHmac(\"sha256\", secret).update(canonical, \"utf8\").digest(\"hex\");\n// headers: X-Key-Id, X-Timestamp: ts, X-Nonce: nonce, X-Signature: signature, Content-Type: application/json\n```\n\nServer-side checks, in order: header format, key and signature, key not disabled or expired, timestamp within 300 seconds of\nserver time, per-platform front-door rate limit, nonce not seen before, platform active, source IP allowlist (only if one is\nconfigured for your platform).\n\n- A request rejected with `IP_NOT_ALLOWED` has already consumed its nonce.\n- An unknown key, a revoked key and a wrong signature are indistinguishable: all return `401 AUTH_BAD_SIGNATURE`.\n  The disabled/expired state of a key is revealed (`403`) only to a caller whose signature is valid.\n- A nonce can be used once. It is remembered until 600 seconds after its timestamp. Reusing it returns `401 AUTH_REPLAY`.\n  Use a new nonce for every attempt, including retries.\n- Clock drift beyond 300 seconds returns `401 AUTH_STALE`. Keep your server clock in sync (NTP).\n\n## Idempotency\n\nThere is no `Idempotency-Key` header. Idempotency is keyed on the bank transaction: the pair (`bankCode`, normalised\n`bankReference`). Submitting the same bank transaction again from the same platform returns `202` with the original\n`donationId`, **provided every bound field matches**: `platformReference`, `recipientWallet`, `amountMinor`, `currency`,\n`paidAt` (to the second), `category` (omitted equals 0) and `metadataHash` (absent equals absent). If any differ, the answer is\n`409 REFERENCE_CONFLICT`. If a different platform has already recorded the same bank transaction, the answer is `409 DUPLICATE`.\nAn idempotent repeat consumes no create-rate-limit token and no daily-cap slot.\n\n`bankReference` is normalised before use (ASCII whitespace trimmed at both ends, ASCII letters upper-cased), so case and\nsurrounding spaces do not make a different transaction. JSON key order and whitespace do not matter either, but remember each\nattempt needs a fresh nonce and a new signature.\n\n## Rate limits\n\nTwo limits apply per platform, both continuous-refill token buckets (the capacity equals the per-minute limit).\n\n- **Front door**: every authenticated `/v1` request (create, status, proof) takes one token. The default is 6000 per minute per\n  platform (operator-configured; may be off). Requests that fail authentication never use your budget. A replayed request\n  still takes a token before it is rejected.\n- **Create limit**: a per-platform value set by the Amanah Ledger team. Only requests that reach the insert stage take a token.\n\nA platform whose create limit is unset (null) has no create limit. Over a limit returns `429 RATE_LIMITED`. No `Retry-After`\nheader is sent; back off and retry with a new nonce. A platform may also have a **daily cap** on new donations per\nplatform-local day: `429 DAILY_CAP_EXCEEDED`.\n\nA third limit sits in front of the API, at the edge (nginx), and is per client IP address, not per platform: about 50\nrequests per second with a burst of 100. Excess requests get a plain `429` from nginx (see \"Errors\" below), before they reach\nthe API. Concurrent connections per IP are also capped (40).\n\n## Errors\n\nErrors produced by the API are JSON of the form `{ \"error\": { \"code\": \"...\", \"message\": \"...\" } }`. The `code` is stable and\nmeant for programs; the `message` is for humans and may change. Validation errors name the offending fields and never echo\nvalues.\n\n**Errors produced at the edge are not necessarily JSON.** The reverse proxy in front of the API answers some requests itself,\nwith its own (HTML or empty) body and no `error.code`: `429` when one client IP exceeds the edge rate limit, `400` for a path\ncontaining `..`, `%2e`, `%2f`, `%5c` or `%00` (the signature covers the exact path, so such paths are refused outright),\n`413` for bodies over 64 KiB (the API itself limits to 16 KiB), `404` for any path outside `/v1/`, and `503` when one client IP exceeds the\nconnection cap (40), `502`/`504` when the backend is down or slow, and Cloudflare's own `52x` pages when the origin is unreachable. Clients must therefore branch on the HTTP status first and parse a JSON error body only when the\nresponse is `application/json`.\n\n## Lifecycle of a donation\n\n`RECEIVED` is only ever the status in the `202` response to a create call. After that a donation is `QUEUED` (accepted,\nwaiting for the on-chain worker), then `SUBMITTED` (a transaction has been sent), then `CONFIRMED`, then `FINALIZED` (final\non Solana). **Do not assume statuses only move forward**: while the worker retries (a transaction expired, a temporary RPC\nfailure, an operational hold) a `SUBMITTED` donation can go back to `QUEUED` and be sent again, and an operator can re-queue a\n`DEAD` one. Treat `CONFIRMED` and `FINALIZED` as the success states and poll until you see one; `FINALIZED` is final.\n`DEAD` means the worker gave up after retries or a terminal on-chain error; contact the Amanah Ledger team.\n\n## Request limits\n\nJSON bodies only (`Content-Type: application/json`), at most 16 KiB (16384 bytes).\n",
    "contact": {
      "name": "Amanah Ledger",
      "email": "contact@amanah-ledger.com",
      "url": "https://amanah-ledger.com"
    }
  },
  "servers": [
    {
      "url": "https://api.amanah-ledger.com",
      "description": "Production. Only `/v1/*` is routed here; every other path returns 404."
    }
  ],
  "tags": [
    {
      "name": "Donations",
      "description": "Submit a bank-confirmed donation, follow it to the chain, and fetch the proof of the record."
    }
  ],
  "paths": {
    "/v1/donations": {
      "post": {
        "operationId": "createDonation",
        "tags": [
          "Donations"
        ],
        "summary": "Record a donation",
        "description": "Submits one bank-confirmed donation. On success the donation is accepted and queued (`202`); it is written on-chain\nasynchronously, so poll `GET /v1/donations/{id}` for progress.\n\nProcessing order: authentication, body validation (including that `bankCode` is a known bank), same-platform lookup\n(idempotent repeat or `REFERENCE_CONFLICT`), cross-platform lookup (`DUPLICATE`), recipient check, platform on-chain\ncheck, create rate limit, daily cap, insert. An idempotent repeat is answered before the recipient check, the rate limit\nand the cap.\n\nThe recipient (`recipientWallet`) must be a verified recipient in Amanah Registry and registered on-chain, and must not be\nin the process of being suspended; otherwise `422 RECIPIENT_NOT_VERIFIED`.\n",
        "security": [
          {
            "AmanahHmac": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/KeyId"
          },
          {
            "$ref": "#/components/parameters/Timestamp"
          },
          {
            "$ref": "#/components/parameters/Nonce"
          },
          {
            "$ref": "#/components/parameters/Signature"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDonationRequest"
              },
              "example": {
                "platformReference": "INV-2026-000123",
                "bankCode": "MBBEMYKL",
                "bankReference": "ib-20261122-7788",
                "amountMinor": "50000",
                "currency": "MYR",
                "recipientWallet": "7tBntpS9MYMo4koekTWqHXyewJFUkPzyL5finB2GMtjU",
                "paidAt": "2026-11-22T11:58:30+08:00",
                "category": 0
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted and queued. Also the answer to an idempotent repeat, with the original `donationId`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonationAccepted"
                },
                "example": {
                  "donationId": "0b6c2f3e-8d4a-4b8e-9c1e-5a7f1d2e3c4b",
                  "status": "RECEIVED"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "description": "`REFERENCE_CONFLICT`: the same bank transaction was already recorded by your platform with different details (amount,\nrecipient, currency, paidAt, category, metadataHash or platformReference), or your `platformReference` was already used\nfor a different bank transaction. `DUPLICATE`: another platform already recorded this bank transaction (no identifiers\nare returned).\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "referenceConflict": {
                    "value": {
                      "error": {
                        "code": "REFERENCE_CONFLICT",
                        "message": "platformReference or bank transaction already used with different details"
                      }
                    }
                  },
                  "duplicate": {
                    "value": {
                      "error": {
                        "code": "DUPLICATE",
                        "message": "This bank transaction has already been recorded"
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMediaType"
          },
          "422": {
            "description": "`RECIPIENT_NOT_VERIFIED`: the recipient wallet is unknown, not verified, not registered on-chain, or is being suspended.\n`PLATFORM_NOT_ONCHAIN`: your platform is not active on-chain.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "recipientNotVerified": {
                    "value": {
                      "error": {
                        "code": "RECIPIENT_NOT_VERIFIED",
                        "message": "Recipient is not verified"
                      }
                    }
                  },
                  "platformNotOnchain": {
                    "value": {
                      "error": {
                        "code": "PLATFORM_NOT_ONCHAIN",
                        "message": "Platform is not active on-chain"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "`RATE_LIMITED` (front-door or create limit) or `DAILY_CAP_EXCEEDED` (your platform's daily cap of new donations for the\nplatform-local day). No `Retry-After` header is sent.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "rateLimited": {
                    "value": {
                      "error": {
                        "code": "RATE_LIMITED",
                        "message": "Rate limit exceeded"
                      }
                    }
                  },
                  "dailyCap": {
                    "value": {
                      "error": {
                        "code": "DAILY_CAP_EXCEEDED",
                        "message": "Daily donation cap reached"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/donations/{id}": {
      "get": {
        "operationId": "getDonation",
        "tags": [
          "Donations"
        ],
        "summary": "Get a donation's status",
        "description": "Returns the current status of one of your platform's donations. A donation that belongs to another platform, does not\nexist, or whose id is not a UUID returns the same `404`.\n\n`signature` appears once a transaction signature is known. It is the signature of the latest attempt and can change if the\ndonation is re-queued and sent again; only a `CONFIRMED` or `FINALIZED` donation has a signature you should rely on. `recordAddress` (the Solana account holding the record) is\nreturned only when `status` is `CONFIRMED` or `FINALIZED`.\n",
        "security": [
          {
            "AmanahHmac": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/KeyId"
          },
          {
            "$ref": "#/components/parameters/Timestamp"
          },
          {
            "$ref": "#/components/parameters/Nonce"
          },
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/DonationId"
          }
        ],
        "responses": {
          "200": {
            "description": "The donation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonationStatus"
                },
                "example": {
                  "donationId": "0b6c2f3e-8d4a-4b8e-9c1e-5a7f1d2e3c4b",
                  "status": "FINALIZED",
                  "signature": "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW",
                  "recordAddress": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/donations/{id}/proof": {
      "get": {
        "operationId": "getDonationProof",
        "tags": [
          "Donations"
        ],
        "summary": "Get the proof of a donation",
        "description": "Returns the values needed to independently recompute the on-chain commitment for one of your donations: the record\naddress, the bank code, the bank reference and the random salt. These are the sensitive inputs that are deliberately\nnot stored on-chain in the clear, so treat the response as confidential.\n\nEvery successful call is written to the platform audit log (action `proof.read`) before the proof is released. If that\nwrite fails, the proof is not returned.\n\nAll byte strings are lowercase hex. `bankCode` is the 11-byte bank code, zero padded on the right. `bankReference` is the\nUTF-8 bytes of the **normalised** reference (trimmed, upper-cased), not the text as you submitted it. `salt` is 16 bytes.\nThe proof can be requested at any status, including before the record is on-chain.\n",
        "security": [
          {
            "AmanahHmac": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/KeyId"
          },
          {
            "$ref": "#/components/parameters/Timestamp"
          },
          {
            "$ref": "#/components/parameters/Nonce"
          },
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/DonationId"
          }
        ],
        "responses": {
          "200": {
            "description": "The proof.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonationProof"
                },
                "example": {
                  "recordAddress": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
                  "bankCode": "4d4242454d594b4c000000",
                  "bankReference": "49422d32303236313132322d37373838",
                  "salt": "00112233445566778899aabbccddeeff"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "AmanahHmac": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Signature",
        "description": "Signed requests. OpenAPI has no native HMAC scheme, so this is modelled as the `X-Signature` header; a request is only\nvalid when `X-Key-Id`, `X-Timestamp` and `X-Nonce` are sent as well and the signature is computed as described under\n\"Authentication: signed requests\" in the introduction.\n"
      }
    },
    "parameters": {
      "KeyId": {
        "name": "X-Key-Id",
        "in": "header",
        "required": true,
        "description": "Your API key id.",
        "schema": {
          "type": "string",
          "maxLength": 128,
          "examples": [
            "k_AbCdEfGhIjKlMnOp"
          ]
        }
      },
      "Timestamp": {
        "name": "X-Timestamp",
        "in": "header",
        "required": true,
        "description": "Current Unix time in whole seconds. Must be within 300 seconds of server time.",
        "schema": {
          "type": "string",
          "pattern": "^[0-9]{1,12}$",
          "examples": [
            "1795348710"
          ]
        }
      },
      "Nonce": {
        "name": "X-Nonce",
        "in": "header",
        "required": true,
        "description": "A unique value per request (a replay returns `AUTH_REPLAY`). Remembered until 600 seconds after the timestamp.",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,64}$",
          "examples": [
            "3f9a1c5e7b2d4f60a8c1e3b5d7f90214"
          ]
        }
      },
      "Signature": {
        "name": "X-Signature",
        "in": "header",
        "required": true,
        "description": "Lowercase hex HMAC-SHA256 of `METHOD|PATH_AND_QUERY|TIMESTAMP|NONCE|SHA256_HEX_OF_BODY`, keyed with your secret.",
        "schema": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "DonationId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "The `donationId` returned when the donation was created.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "schemas": {
      "CreateDonationRequest": {
        "type": "object",
        "additionalProperties": false,
        "description": "Unknown fields are rejected with `VALIDATION_FAILED`.",
        "required": [
          "platformReference",
          "bankCode",
          "bankReference",
          "amountMinor",
          "currency",
          "recipientWallet",
          "paidAt"
        ],
        "properties": {
          "platformReference": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own reference (at most 128 characters, counted as UTF-16 code units by the server) for this donation. Unique per platform: reusing it for a different bank transaction is `REFERENCE_CONFLICT`."
          },
          "bankCode": {
            "type": "string",
            "pattern": "^[A-Z0-9]{1,11}$",
            "description": "Code of the bank that confirmed the payment. Must be one of the banks Amanah Ledger supports, otherwise `VALIDATION_FAILED` (field `bankCode`). Ask the Amanah Ledger team for the list."
          },
          "bankReference": {
            "type": "string",
            "maxLength": 128,
            "description": "The bank's reference for the transaction. Must not be empty after normalisation (trim ASCII whitespace, upper-case ASCII\nletters). Stored and proven in normalised form. Together with `bankCode` it identifies the bank transaction for\nidempotency and duplicate detection.\n"
          },
          "amountMinor": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "description": "Amount in minor units (for example sen) as a **decimal string**, 1 to 18446744073709551615 (2^64-1). A JSON number is rejected."
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$",
            "description": "Three upper-case letters."
          },
          "recipientWallet": {
            "type": "string",
            "description": "Solana address (base58, 32 bytes, canonical form) of a verified recipient.",
            "examples": [
              "7tBntpS9MYMo4koekTWqHXyewJFUkPzyL5finB2GMtjU"
            ]
          },
          "paidAt": {
            "type": "string",
            "description": "When the donor paid, RFC 3339 with an explicit offset (`Z` or `+hh:mm`) and whole seconds, for example\n`2026-11-22T11:58:30+08:00`. Fractional seconds are rejected. Must be after the Unix epoch and at most 240 seconds\nin the future.\n",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(Z|[+-]\\d{2}:\\d{2})$"
          },
          "category": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535,
            "default": 0,
            "description": "Optional category code, 0 to 65535. Omitted means 0."
          },
          "metadataHash": {
            "type": "string",
            "pattern": "^[0-9a-fA-F]{64}$",
            "description": "Optional 32-byte hash (64 hex characters) of your own metadata for this donation. Stored as bytes; the metadata itself is not sent."
          }
        }
      },
      "DonationAccepted": {
        "type": "object",
        "required": [
          "donationId",
          "status"
        ],
        "properties": {
          "donationId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "const": "RECEIVED"
          }
        }
      },
      "DonationStatus": {
        "type": "object",
        "required": [
          "donationId",
          "status"
        ],
        "properties": {
          "donationId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "signature": {
            "type": "string",
            "description": "Solana transaction signature (base58) of the latest attempt, present once known. May change after a re-queue."
          },
          "recordAddress": {
            "type": "string",
            "description": "Solana account holding the record (base58). Present only when `status` is `CONFIRMED` or `FINALIZED`."
          }
        }
      },
      "Status": {
        "type": "string",
        "enum": [
          "RECEIVED",
          "QUEUED",
          "SUBMITTED",
          "CONFIRMED",
          "FINALIZED",
          "DEAD"
        ],
        "description": "`QUEUED` accepted and waiting; `SUBMITTED` sent to Solana; `CONFIRMED` confirmed; `FINALIZED` final;\n`DEAD` the on-chain worker gave up (contact Amanah Ledger). `RECEIVED` is the status in the create response and is a\nvalid value of the underlying column, but a stored donation is normally already `QUEUED` when you can first read it.\n"
      },
      "DonationProof": {
        "type": "object",
        "required": [
          "recordAddress",
          "bankCode",
          "bankReference",
          "salt"
        ],
        "properties": {
          "recordAddress": {
            "type": "string",
            "description": "Solana account of the record (base58)."
          },
          "bankCode": {
            "type": "string",
            "pattern": "^[0-9a-f]{22}$",
            "description": "Hex of the 11-byte bank code, zero padded on the right."
          },
          "bankReference": {
            "type": "string",
            "pattern": "^([0-9a-f]{2})+$",
            "description": "Hex of the UTF-8 bytes of the **normalised** bank reference."
          },
          "salt": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$",
            "description": "Hex of the 16-byte random salt of this donation."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "$ref": "#/components/schemas/ErrorCode"
              },
              "message": {
                "type": "string",
                "description": "Human-readable text. Not stable; do not parse it."
              }
            }
          }
        }
      },
      "ErrorCode": {
        "type": "string",
        "enum": [
          "AUTH_BAD_SIGNATURE",
          "AUTH_STALE",
          "AUTH_REPLAY",
          "KEY_DISABLED",
          "KEY_EXPIRED",
          "PLATFORM_INACTIVE",
          "IP_NOT_ALLOWED",
          "VALIDATION_FAILED",
          "RECIPIENT_NOT_VERIFIED",
          "PLATFORM_NOT_ONCHAIN",
          "RATE_LIMITED",
          "DAILY_CAP_EXCEEDED",
          "DUPLICATE",
          "REFERENCE_CONFLICT",
          "NOT_FOUND",
          "BAD_REQUEST",
          "PAYLOAD_TOO_LARGE",
          "UNSUPPORTED_MEDIA_TYPE",
          "INTERNAL"
        ]
      }
    },
    "responses": {
      "ValidationFailed": {
        "description": "`VALIDATION_FAILED`: the body is not valid JSON, has an unknown field, or a field is invalid. The message lists the field\nnames (for example `Invalid request: amountMinor, paidAt`), never the values.\n",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "VALIDATION_FAILED",
                "message": "Invalid request: amountMinor"
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "`AUTH_BAD_SIGNATURE`: missing or malformed auth headers, unknown or revoked key, or wrong signature (all identical).\n`AUTH_STALE`: timestamp more than 300 seconds from server time. `AUTH_REPLAY`: nonce already used.\n",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "badSignature": {
                "value": {
                  "error": {
                    "code": "AUTH_BAD_SIGNATURE",
                    "message": "Authentication failed"
                  }
                }
              },
              "stale": {
                "value": {
                  "error": {
                    "code": "AUTH_STALE",
                    "message": "Timestamp outside the allowed window"
                  }
                }
              },
              "replay": {
                "value": {
                  "error": {
                    "code": "AUTH_REPLAY",
                    "message": "Nonce already used"
                  }
                }
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "Returned only for a valid signature. `KEY_DISABLED`: the key is disabled. `KEY_EXPIRED`: the key has expired.\n`PLATFORM_INACTIVE`: the platform is deactivated. `IP_NOT_ALLOWED`: your platform has an IP allowlist and the source\naddress is not on it.\n",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "KEY_DISABLED",
                "message": "API key is disabled"
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "No such donation for your platform (a donation of another platform, a missing id and a malformed id are indistinguishable). Unknown `/v1` paths also return `NOT_FOUND`.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "NOT_FOUND",
                "message": "Not found"
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "`RATE_LIMITED`: the platform's front-door limit is exhausted. No `Retry-After` header is sent.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "RATE_LIMITED",
                "message": "Rate limit exceeded"
              }
            }
          }
        }
      },
      "PayloadTooLarge": {
        "description": "The body is larger than 16 KiB. Answered before authentication. (Above 64 KiB the edge answers first, with a non-JSON `413`.)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "PAYLOAD_TOO_LARGE",
                "message": "Request body too large"
              }
            }
          }
        }
      },
      "UnsupportedMediaType": {
        "description": "The content type is not `application/json`. Answered before authentication.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "UNSUPPORTED_MEDIA_TYPE",
                "message": "Content-Type must be application/json"
              }
            }
          }
        }
      },
      "Internal": {
        "description": "Unexpected server error. The body is generic; retry later with a new nonce and contact the Amanah Ledger team if it persists.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "INTERNAL",
                "message": "Internal server error"
              }
            }
          }
        }
      }
    }
  }
}
