@agentvault/secure-channel 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# @agentvault/secure-channel
|
|
2
|
+
|
|
3
|
+
End-to-end encrypted communication channel for AI agents on the [AgentVault](https://agentvault.chat) platform. Connect your agent to its owner with XChaCha20-Poly1305 encryption and Double Ratchet forward secrecy.
|
|
4
|
+
|
|
5
|
+
## What's New in v0.4.0
|
|
6
|
+
|
|
7
|
+
**Webhook Notifications** — Your agent can now receive HTTP webhook callbacks when a new message arrives, even when it's not connected via WebSocket. This is ideal for serverless agents, agents that poll on a schedule, or any agent that isn't always online.
|
|
8
|
+
|
|
9
|
+
### Upgrading from v0.3.x
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @agentvault/secure-channel@latest
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Add `webhookUrl` to your config to enable:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const channel = new SecureChannel({
|
|
19
|
+
inviteToken: "your-token",
|
|
20
|
+
dataDir: "./agentvault-data",
|
|
21
|
+
apiUrl: "https://api.agentvault.chat",
|
|
22
|
+
webhookUrl: "https://your-server.com/webhook/agentvault", // NEW in 0.4.0
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
No other code changes required — fully backward-compatible.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @agentvault/secure-channel
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### Option 1: CLI (Interactive)
|
|
39
|
+
|
|
40
|
+
Run directly with npx using the invite token from your AgentVault dashboard:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx @agentvault/secure-channel --token=YOUR_INVITE_TOKEN
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The CLI will:
|
|
47
|
+
1. Enroll your agent with the server
|
|
48
|
+
2. Display a fingerprint for the owner to verify
|
|
49
|
+
3. Wait for owner approval
|
|
50
|
+
4. Establish an encrypted channel
|
|
51
|
+
5. Enter interactive mode where you can send/receive messages
|
|
52
|
+
|
|
53
|
+
**CLI Flags:**
|
|
54
|
+
|
|
55
|
+
| Flag | Default | Description |
|
|
56
|
+
|------|---------|-------------|
|
|
57
|
+
| `--token` | (required on first run) | Invite token from dashboard |
|
|
58
|
+
| `--name` | `"CLI Agent"` | Agent display name |
|
|
59
|
+
| `--data-dir` | `./agentvault-data` | Directory for persistent state |
|
|
60
|
+
| `--api-url` | `https://api.agentvault.chat` | API endpoint |
|
|
61
|
+
|
|
62
|
+
Environment variables (`AGENTVAULT_INVITE_TOKEN`, `AGENTVAULT_AGENT_NAME`, `AGENTVAULT_DATA_DIR`, `AGENTVAULT_API_URL`) work as alternatives to flags.
|
|
63
|
+
|
|
64
|
+
### Option 2: SDK (Programmatic)
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import { SecureChannel } from "@agentvault/secure-channel";
|
|
68
|
+
|
|
69
|
+
const channel = new SecureChannel({
|
|
70
|
+
inviteToken: "YOUR_INVITE_TOKEN",
|
|
71
|
+
dataDir: "./agentvault-data",
|
|
72
|
+
apiUrl: "https://api.agentvault.chat",
|
|
73
|
+
agentName: "My Agent",
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
channel.on("message", (text, metadata) => {
|
|
77
|
+
console.log(`Received: ${text}`);
|
|
78
|
+
// Echo back
|
|
79
|
+
channel.send(`You said: ${text}`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
channel.on("ready", () => {
|
|
83
|
+
console.log("Secure channel established!");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await channel.start();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Webhook Notifications (v0.4.0+)
|
|
92
|
+
|
|
93
|
+
Enable webhook notifications so your agent gets an HTTP POST when a new message arrives — useful for agents that aren't always connected via WebSocket.
|
|
94
|
+
|
|
95
|
+
### Setup
|
|
96
|
+
|
|
97
|
+
Add `webhookUrl` to your config:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
const channel = new SecureChannel({
|
|
101
|
+
inviteToken: "YOUR_INVITE_TOKEN",
|
|
102
|
+
dataDir: "./agentvault-data",
|
|
103
|
+
apiUrl: "https://api.agentvault.chat",
|
|
104
|
+
webhookUrl: "https://your-server.com/webhook/agentvault",
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The webhook URL is registered automatically during device activation. The channel emits a `webhook_registered` event on success:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
channel.on("webhook_registered", ({ url, secret }) => {
|
|
112
|
+
console.log(`Webhook registered at ${url}`);
|
|
113
|
+
// Save the secret to verify incoming webhooks
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Webhook Payload
|
|
118
|
+
|
|
119
|
+
When the owner sends a message, your webhook endpoint receives:
|
|
120
|
+
|
|
121
|
+
```http
|
|
122
|
+
POST /webhook/agentvault HTTP/1.1
|
|
123
|
+
Content-Type: application/json
|
|
124
|
+
X-AgentVault-Event: new_message
|
|
125
|
+
X-AgentVault-Signature: sha256=<hmac-hex>
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
"event": "new_message",
|
|
129
|
+
"conversation_id": "uuid",
|
|
130
|
+
"sender_device_id": "uuid",
|
|
131
|
+
"message_id": "uuid",
|
|
132
|
+
"timestamp": "2026-02-17T12:00:00Z"
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Verifying Webhook Signatures
|
|
137
|
+
|
|
138
|
+
Each webhook includes an HMAC-SHA256 signature in the `X-AgentVault-Signature` header. Verify it using the secret from the `webhook_registered` event:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import crypto from "crypto";
|
|
142
|
+
|
|
143
|
+
function verifyWebhook(body, signature, secret) {
|
|
144
|
+
const expected = "sha256=" +
|
|
145
|
+
crypto.createHmac("sha256", secret).update(body).digest("hex");
|
|
146
|
+
return crypto.timingSafeEqual(
|
|
147
|
+
Buffer.from(signature),
|
|
148
|
+
Buffer.from(expected),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Configuration Reference
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
interface SecureChannelConfig {
|
|
159
|
+
// Required
|
|
160
|
+
inviteToken: string; // Invite token from the AgentVault dashboard
|
|
161
|
+
dataDir: string; // Directory for persistent state files
|
|
162
|
+
apiUrl: string; // API endpoint (e.g., "https://api.agentvault.chat")
|
|
163
|
+
|
|
164
|
+
// Optional
|
|
165
|
+
agentName?: string; // Display name (default: "CLI Agent")
|
|
166
|
+
platform?: string; // Platform identifier (e.g., "node")
|
|
167
|
+
maxHistorySize?: number; // Max stored messages for cross-device replay (default: 500)
|
|
168
|
+
webhookUrl?: string; // Webhook URL for new message notifications (v0.4.0+)
|
|
169
|
+
|
|
170
|
+
// Callbacks (alternative to event listeners)
|
|
171
|
+
onMessage?: (text: string, metadata: MessageMetadata) => void;
|
|
172
|
+
onStateChange?: (state: ChannelState) => void;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Events
|
|
177
|
+
|
|
178
|
+
| Event | Payload | Description |
|
|
179
|
+
|-------|---------|-------------|
|
|
180
|
+
| `message` | `(text: string, metadata: MessageMetadata)` | Owner sent a message |
|
|
181
|
+
| `ready` | none | WebSocket connected, channel operational |
|
|
182
|
+
| `state` | `(state: ChannelState)` | State transition occurred |
|
|
183
|
+
| `error` | `(error: Error)` | Fatal error |
|
|
184
|
+
| `webhook_registered` | `({ url: string, secret: string })` | Webhook registered (v0.4.0+) |
|
|
185
|
+
|
|
186
|
+
## Channel States
|
|
187
|
+
|
|
188
|
+
`idle` → `enrolling` → `polling` → `activating` → `connecting` → `ready`
|
|
189
|
+
|
|
190
|
+
If disconnected: `ready` → `disconnected` → `connecting` → `ready` (auto-reconnect)
|
|
191
|
+
|
|
192
|
+
## API
|
|
193
|
+
|
|
194
|
+
| Method | Description |
|
|
195
|
+
|--------|-------------|
|
|
196
|
+
| `start()` | Initialize, enroll, and connect |
|
|
197
|
+
| `send(text)` | Encrypt and send message to all owner devices |
|
|
198
|
+
| `stop()` | Gracefully disconnect |
|
|
199
|
+
|
|
200
|
+
| Property | Description |
|
|
201
|
+
|----------|-------------|
|
|
202
|
+
| `state` | Current channel state |
|
|
203
|
+
| `deviceId` | Agent's device ID (after enrollment) |
|
|
204
|
+
| `fingerprint` | Device fingerprint for verification |
|
|
205
|
+
| `conversationId` | Primary conversation ID |
|
|
206
|
+
| `conversationIds` | All active conversation IDs (multi-device) |
|
|
207
|
+
| `sessionCount` | Number of active encrypted sessions |
|
|
208
|
+
|
|
209
|
+
## Multi-Device Support
|
|
210
|
+
|
|
211
|
+
AgentVault supports multiple owner devices (e.g., desktop + mobile). The channel automatically:
|
|
212
|
+
- Maintains independent encrypted sessions per owner device
|
|
213
|
+
- Fans out `send()` to all active sessions
|
|
214
|
+
- Stores message history for cross-device replay (up to `maxHistorySize`)
|
|
215
|
+
- Replays history when a new device connects
|
|
216
|
+
|
|
217
|
+
No additional configuration needed — multi-device is handled transparently.
|
|
218
|
+
|
|
219
|
+
## Security
|
|
220
|
+
|
|
221
|
+
- **XChaCha20-Poly1305** symmetric encryption (192-bit nonces)
|
|
222
|
+
- **X3DH** key agreement (Ed25519 + X25519)
|
|
223
|
+
- **Double Ratchet** for forward secrecy — old keys deleted after use
|
|
224
|
+
- **Zero-knowledge server** — the server never sees plaintext
|
|
225
|
+
- **HMAC-SHA256** webhook signatures for authenticity verification
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT
|