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

# @spellguard/amp

> Admissible Messaging Policy — logging and archiving

# @spellguard/amp

Admissible Messaging Policy for audit logging and message archiving.

## Client Functions

| Function                                  | Description                       |
| ----------------------------------------- | --------------------------------- |
| `encryptForVerifier(payload, key)`        | Encrypt payload for Verifier      |
| `decryptFromVerifier(encrypted, key)`     | Decrypt payload from Verifier     |
| `verifyArchiveIntegrity(commit, archive)` | Verify archive matches commitment |

## Server Functions

| Function                              | Description                          |
| ------------------------------------- | ------------------------------------ |
| `initLoggingBackends()`               | Initialize configured backends       |
| `generateCommitment(message)`         | Generate commitment for a message    |
| `logCommitment(commitment)`           | Log commitment to backend            |
| `archiveMessage(message, commitment)` | Archive encrypted message            |
| `logAndArchive(msg, commit)`          | Log and archive in one operation     |
| `getOrCreateChannel(a, b)`            | Get or create channel between agents |

## Usage Example

```typescript theme={null}
import {
  initLoggingBackends,
  generateCommitment,
  logAndArchive,
  encryptForVerifier
} from '@spellguard/amp';

// Server-side: Initialize backends
await initLoggingBackends();

// Client-side: Encrypt message
const encrypted = encryptForVerifier(
  JSON.stringify({ action: 'transfer', amount: 100 }),
  verifier.sessionX25519PublicKey
);

// Server-side: Log with commitment
const message = {
  id: crypto.randomUUID(),
  sender: 'agent-a',
  recipient: 'agent-b',
  encryptedPayload: encrypted,
  timestamp: Date.now()
};

const commitment = generateCommitment(message);
const result = await logAndArchive(message, commitment);

console.log('Commitment ID:', result.commitmentId);
console.log('Archive ID:', result.archiveId);
```

## Backend Configuration

```bash theme={null}
# Environment variables
COMMITMENT_BACKEND=rekor   # 'memory' | 'rekor'
ARCHIVE_BACKEND=s3         # 'memory' | 's3'

# S3 configuration (when using s3 backend)
AWS_REGION=us-east-1
S3_BUCKET=my-spellguard-archives
```
