Skip to content

About

Secure communication protocol for agents with end-to-end encryption and authentication

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

eicp — encrypted-interagent-communication-protocol

Secure, replay-proof, end-to-end encrypted messaging between AI agents over signed JSON envelopes. Zero runtime dependencies; Node ≥ 18 or Bun.

The problem

Multi-agent systems constantly exchange instructions, payments, and state — usually over plaintext HTTP or ad-hoc JSON with no authentication. That means:

  • Anyone on the path can read or rewrite messages. A prompt injection, a MITM, or a compromised relay can silently alter what an agent "decided".
  • There is no proof of who sent what. Spoofing an agent id is trivial without signed identity.
  • Replays look like new work. Capture a message, re-deliver it later, and the receiving agent performs the same action twice.

What this gives you

eicp is a small protocol + library + CLI that fixes exactly those three failures:

  • End-to-end encryption — every message is sealed to the recipient's X25519 public key with a fresh ephemeral key pair; the shared secret is expanded with HKDF-SHA256 into an AES-256-GCM key. The server that relays envelopes never sees plaintext.
  • Authentication — every envelope's header (routing + ciphertext digest) is signed with the sender's Ed25519 key. Receivers verify against a pinned trust store; key rotation is explicit (force), so an attacker who can inject registrations cannot silently rotate a victim's keys.
  • Replay protection — receivers reject messages outside a freshness skew window and reject any previously seen nonce. Nonces persist across restarts so a restart doesn't reopen the window.
  • An operational shape that fits agents — a single "post office" server holds the private keys for its local agents (keys never leave the process) and exposes a small bearer-token HTTP API. Remote agents integrate over HTTP without holding key material.

How it works

sender                                    receiver
  │ sealTo(recipient.ecdh, plaintext)        │
  │   ephemeral X25519 key pair              │
  │   shared = ECDH(eph_priv, rec_pub)       │
  │   key    = HKDF-SHA256(shared, salt=nonce)
  │   ct,tag = AES-256-GCM(key, iv=nonce[0:12], plaintext)
  │                                          │
  │ envelope = {v:1, alg, from, to, ts,      │
  │             nonce, epk, topic?, ct, tag} │
  │ sig      = Ed25519_sign(canonical_header_json)
  └────────────── envelope over HTTP ────────┤
                                             │ 1. structural validation (v, alg, lengths, base64url)
                                             │ 2. sender pinned in trust store?   → UNTRUSTED
                                             │ 3. Ed25519 signature over canonical header → TAMPER
                                             │ 4. ts inside skew window?          → STALE
                                             │ 5. nonce unseen?                   → REPLAY
                                             │ 6. AES-256-GCM open with recipient key → TAMPER
                                             ▼
                                        Delivery { from, to, topic?, ts, plaintext, bytes }

Design decisions worth knowing:

  • The signature covers a canonical JSON serialization of the header with fixed key order, so signature bytes are identical across runtimes and there is no ambiguity about what was signed.
  • The 16-byte nonce is triple-duty: GCM IV (first 12 bytes), HKDF salt, and the replay registry key. One random draw, three guarantees.
  • Errors are typed (VALIDATION, UNTRUSTED, TAMPER, STALE, REPLAY, KEYCONFLICT, …) and map to HTTP status codes, so protocol failures are diagnosable from a log line.
  • State persists atomically (write-to-tmp + rename) as a versioned JSON file: identities, trust pins, and seen nonces. Malformed files fail as CORRUPTION rather than silently resetting security state.

Getting started

git clone https://github.com/Retsumdk/encrypted-interagent-communication-protocol.git
cd encrypted-interagent-communication-protocol
bun install          # or: npm install (prepare script builds dist/)
bun test             # 26 tests

Or install directly from GitHub:

npm install github:Retsumdk/encrypted-interagent-communication-protocol
# with Bun, trust the lifecycle script so the package builds:
# bun add github:Retsumdk/encrypted-interagent-communication-protocol && bun pm trust encrypted-interagent-communication-protocol

Using the CLI

Two agents on one office:

# terminal 1 — start the post office
eicp server --port 8787 --state state.json --secret choose-a-long-secret

# terminal 2 — provision both agents, exchange, observe
eicp keygen --id alice
eicp keygen --id bob
eicp trust --id alice
eicp trust --id bob
eicp send --from alice --to bob --text "meet at the dead drop at 0900" --topic ops
# → { "from": "alice", "to": "bob", "ts": 1760000000000,
#     "plaintext": "meet at the dead drop at 0900", "bytes": 29, "topic": "ops" }

eicp stats
# → { "sent": 1, "delivered": 1, "rejected": 0, "identities": 2, "trust": 2, ... }

The bearer token is the server's --secret value.

Delivering an envelope that arrived over some other channel (file, queue, another office):

# envelopes.json is a JSON array of envelope objects
eicp inbox --id bob --file envelopes.json

Pinning an agent whose keys live on a different office — export its public identity (the /keygen response body) to a JSON file, then:

eicp trust --file external-agent.json

Using the library

import { KeyStore, TrustStore, ReplayGuard, Post, publicOf } from "encrypted-interagent-communication-protocol";

const keys = new KeyStore();
const trust = new TrustStore();
const replay = new ReplayGuard(5 * 60_000, 30_000); // window, skew
const office = new Post({ keys, trust, replay });

const alice = keys.create("alice");
const bob = keys.create("bob");
trust.pin({ ...publicOf(alice) });
trust.pin({ id: "bob", sign: bob.sign, ecdh: bob.ecdh });

const envelope = office.send("alice", "bob", "hello bob", { topic: "demo" });
const delivery = office.receive(envelope);
// delivery.plaintext === "hello bob"

The low-level pieces are exported too: sealTo/openFrom (raw AES-GCM sealing), sealEnvelope/verifyEnvelope (signing), createIdentity/publicOf (keys), and startServer if you want to embed the office in your own process.

Security properties and limits

  • Forward secrecy per message: a fresh ephemeral X25519 key pair is used for every envelope; compromising a long-term key does not decrypt past traffic captured in transit.
  • Metadata is not hidden: from, to, topic, and ts are visible to the office operator (they must be, for routing) but are authenticated, so they cannot be forged.
  • Trust is pinned, not discovered: there is deliberately no automatic TOFU. TrustStore.pin is your trust root.
  • The office is trusted with plaintext for its local agents — it holds their private keys. Run it on a machine you control; the HTTP API exists so other machines don't need keys.
  • Message size limit: 1 MiB plaintext (MAX_PLAINTEXT_BYTES).

API

Endpoint Auth Body Returns
GET /health no — { ok, uptimeMs }
GET /stats no — counters, identity/trust/nonce counts
POST /keygen bearer { id } public identity (private keys stay on the server)
POST /trust bearer { id, sign, ecdh } pinned trust entry with fingerprint
POST /send bearer { from, to, plaintext, topic? } sealed, signed envelope
POST /receive bearer { envelope } Delivery
POST /identities bearer {} public identities of all local agents
POST /trust-list bearer {} all pinned public identities

Rejections return the mapped status with { error: <CODE>, message }.

Development

bun install
bun test              # bun test runner
bun run build         # tsc → dist/
node dist/cli.js --help

License

MIT License


Built by Retsumdk

About

Secure communication protocol for agents with end-to-end encryption and authentication

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages