{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "heldWrite": {
      "properties": {
        "collection": {
          "format": "nsid",
          "type": "string"
        },
        "record": {
          "description": "The record, with the \"$subject\" (and optionally \"$now\" and \"$name\") slots as string values.",
          "type": "unknown"
        },
        "rkey": {
          "description": "The record key, which may carry \"$subject\". Absent: an accessRule takes its deterministic key, any other record a TID.",
          "type": "string"
        },
        "space": {
          "description": "The space the record is for, as permissioned.putRecord's `space`. Required: a public record is not held.",
          "type": "string"
        }
      },
      "required": [
        "collection",
        "space",
        "record"
      ],
      "type": "object"
    },
    "main": {
      "description": "Hold a write until someone proves a phone number: when an account proves `phone`, the platform fills every string value exactly \"$subject\" in `write.record` (and \"$subject\" in `write.rkey`) with that account's DID, every value exactly \"$now\" in the record with the time and every value exactly \"$name\" with that account's name (its public pub.techne.draft.actor.profile displayName, trimmed, at most 64 graphemes, else its handle; a write waits until one is known), and writes the record as `actAs` in `write.space` with what it holds for that account. Only the number's keyed hash is kept; the template may not contain the number. Every hold is answered alike, whether or not the number already has an account: one that has is released the next time it is proved (each phone sign-in proves it), never at once, so nothing here says whether a number has an account or whose it is. The caller must be able to write as `actAs` (its own DID, a collective or circle whose own member space (`space.collective.member/self`) it manages), now and again when the number is proved; a hold whose caller no longer may, or with a block either way between the new account and the caller or `actAs`, is dropped unwritten, as is one whose record the space does not admit. The record must be one permissioned.putRecord would take with the caller's DID in the slot, and must carry the slot. The nightly sweep deletes a hold 180 days after it was made. Holding again with the same number, `actAs`, `collection`, `space`, `rkey` and record `space` answers the existing hold unchanged (the first template wins; withdraw it with releasePhoneHold and hold again to change it). The template is shown to everyone who may write as `actAs` and read `space` (listPhoneHolds). Identity knows nothing about what the record means. Any signed-in DID; one call spends one of the caller's writes.",
      "errors": [
        {
          "description": "HTTP 400: a number that is not E.164, a record without the \"$subject\" slot or carrying the number, a record or key permissioned.putRecord would refuse, or a body that is not JSON; 415: not application/json; 422: not the input's shape; 413: a record over 64 KiB.",
          "name": "InvalidRequest"
        },
        {
          "description": "HTTP 403: the caller may not write as `actAs`.",
          "name": "Forbidden"
        },
        {
          "description": "Too many writes from this DID (HTTP 429).",
          "name": "RateLimitExceeded"
        }
      ],
      "input": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "actAs": {
              "description": "The account the record is written as.",
              "format": "did",
              "type": "string"
            },
            "app": {
              "description": "A label the caller gives itself, unverified, echoed in listPhoneHolds.",
              "maxLength": 64,
              "minLength": 1,
              "type": "string"
            },
            "phone": {
              "description": "The number, E.164 (+15551234567).",
              "type": "string"
            },
            "write": {
              "ref": "#heldWrite",
              "type": "ref"
            }
          },
          "required": [
            "phone",
            "actAs",
            "write"
          ],
          "type": "object"
        }
      },
      "output": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "id": {
              "description": "The hold.",
              "type": "string"
            }
          },
          "required": [
            "id"
          ],
          "type": "object"
        }
      },
      "type": "procedure"
    }
  },
  "id": "pub.techne.draft.identity.holdForPhone",
  "lexicon": 1
}
