<!-- Generated from sources/conventions/v1/aeon-secure-document-lifecycle.aeon; do not edit. -->

<a id="aeon-secure-document-lifecycle"></a>
# AEON Secure Document Lifecycle

This section describes the typical lifecycle of a secured AEON document using the security conventions.

The lifecycle includes:

1. Authoring
2. Canonical hashing
3. Signing
4. Optional encryption
5. Transmission
6. Verification
7. Optional decryption

---

<a id="document-authoring"></a>
## 1. Document Authoring

An AEON document is first created without the envelope.

Example:

```aeon
aeon:header = {
  encoding:string = "utf-8"
  mode:string = "strict"
  conventions:conventionSet = [
    "aeon.gp.security.v1"
    "aeon.gp.integrity.v1"
    "aeon.gp.signature.v1"
  ]
}

message:object = {
  from:string = "Alice"
  to:string = "Bob"
  text:string = "Meet at the lighthouse"
}
```

At this stage:

- the document contains only semantic content
- no integrity metadata exists

---

<a id="canonical-hashing"></a>
## 2. Canonical Hashing

The document is processed using `aeon.gp.integrity.v1`.

Steps:

1. parse the document
2. compute the canonical assignment state
3. serialize canonical state lines
4. hash the resulting UTF-8 byte stream

Example result:

```
sha256 → #7A91E4C8...
```

This becomes the **document integrity hash**.

---

<a id="signature-creation"></a>
## 3. Signature Creation

The signer creates a signature over the integrity hash.

Example:

```
sig = Sign(hash, privateKey)
```

Then the envelope is constructed.

Example:

```aeon
"aeon:envelope":securityEnvelope = {

  integrity:integrityBlock = {
    alg:string = "sha-256"
    hash:string = "7a91e4c8..."
  }

  signatures:signatureSet = [
    {
      alg:string = "ed25519"
      kid:string = "alice"
      sig:string = "BASE64_SIGNATURE"
    }
  ]

}
```

The envelope is appended as the **final binding** in the document.

---

<a id="optional-encryption"></a>
## 4. Optional Encryption

If confidentiality is required, the document body may be encrypted.

Typical workflow:

1. encrypt document body
2. produce ciphertext
3. place encryption metadata in the envelope

Example:

```aeon
"aeon:envelope":securityEnvelope = {

  encryption:encryptionBlock = {
    alg:string = "xchacha20-poly1305"
    kid:string = "bob"
    ciphertext:string = "ENCRYPTED_PAYLOAD"
  }

  integrity:integrityBlock = {
    alg:string = "sha-256"
    hash:string = "7a91e4c8..."
  }

  signatures:signatureSet = [
    {
      alg:string = "ed25519"
      kid:string = "alice"
      sig:string = "BASE64_SIGNATURE"
    }
  ]

}
```

This allows recipients to:

- decrypt the body
- verify integrity
- verify signatures

---

<a id="transmission-storage"></a>
## 5. Transmission / Storage

The completed AEON document can now be:

- transmitted
- stored
- archived
- logged
- distributed

Because the document carries its own envelope, it becomes **self-verifying**.

No external signature file is required.

---

<a id="document-verification"></a>
## 6. Document Verification

A receiver verifying the document should perform the following steps.

<a id="step-1-parse-document"></a>
### Step 1 — Parse document

The AEON document is parsed normally.

<a id="step-2-locate-envelope"></a>
### Step 2 — Locate envelope

The processor locates:

```
aeon:envelope
```

<a id="step-3-compute-canonical-integrity-hash"></a>
### Step 3 — Compute canonical integrity hash

The processor recomputes the hash using `aeon.gp.integrity.v1`.

<a id="step-4-compare-hashes"></a>
### Step 4 — Compare hashes

The computed hash must match:

```
aeon:envelope.integrity.hash
```

If the hash differs, the document is considered **tampered**.

<a id="step-5-verify-signatures"></a>
### Step 5 — Verify signatures

Each signature entry is verified using:

- the declared algorithm
- the key referenced by `kid`

If verification fails, the signature is invalid.

---

<a id="optional-decryption"></a>
## 7. Optional Decryption

If the document is encrypted:

1. locate `aeon:envelope.encryption`
2. resolve recipient key
3. decrypt ciphertext
4. reconstruct the AEON body
5. verify integrity and signatures

Decryption failure indicates either:

- incorrect key
- corrupted ciphertext
- tampering

---

<a id="lifecycle-summary"></a>
## 8. Lifecycle Summary

The secure lifecycle can be summarized as:

```
author document
        ↓
canonical hash
        ↓
sign hash
        ↓
(optional) encrypt payload
        ↓
attach envelope
        ↓
transmit / store
        ↓
verify hash
        ↓
verify signatures
        ↓
(optional) decrypt
```

---

<a id="security-properties"></a>
## 9. Security Properties

This lifecycle provides:

<a id="integrity"></a>
### Integrity

Document tampering is detectable.

<a id="authenticity"></a>
### Authenticity

Signatures prove authorship.

<a id="confidentiality"></a>
### Confidentiality

Encryption protects document content.

<a id="self-verification"></a>
### Self-verification

The document carries its own verification data.

---

<a id="design-advantages"></a>
## 10. Design Advantages

This model provides several advantages:

- deterministic hashing
- multi-signature support
- independent algorithm evolution
- envelope-based closure
- compatibility with streaming verification

Because AEON separates structure from security mechanisms, cryptographic algorithms can evolve without modifying the core language.

---

<a id="result"></a>
## Result

The AEON security model enables **verifiable structured documents** while preserving the minimal design philosophy of AEON core.

---

If you want, the next thing worth doing is something surprisingly important:
designing the **canonical test vectors for the integrity algorithm**. That’s what ensures two independent implementations always produce the same hash.
