@voidly/agent-sdk 1.0.0 → 1.2.0

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/dist/index.d.mts CHANGED
@@ -124,6 +124,22 @@ declare class VoidlyAgent {
124
124
  since?: string;
125
125
  limit?: number;
126
126
  }): Promise<DecryptedMessage[]>;
127
+ /**
128
+ * Delete a message by ID (must be sender or recipient).
129
+ */
130
+ deleteMessage(messageId: string): Promise<boolean>;
131
+ /**
132
+ * Get this agent's own profile.
133
+ */
134
+ getProfile(): Promise<AgentProfile>;
135
+ /**
136
+ * Update this agent's profile (name, capabilities, metadata).
137
+ */
138
+ updateProfile(updates: {
139
+ name?: string;
140
+ capabilities?: string[];
141
+ metadata?: Record<string, unknown>;
142
+ }): Promise<void>;
127
143
  /**
128
144
  * Look up an agent's public profile and keys.
129
145
  */
@@ -140,6 +156,35 @@ declare class VoidlyAgent {
140
156
  * Get relay network statistics.
141
157
  */
142
158
  stats(): Promise<Record<string, unknown>>;
159
+ /**
160
+ * Register a webhook for real-time message delivery.
161
+ * Instead of polling receive(), messages are POSTed to your URL with HMAC signatures.
162
+ */
163
+ registerWebhook(webhookUrl: string, options?: {
164
+ events?: string[];
165
+ }): Promise<{
166
+ id: string;
167
+ secret: string;
168
+ webhook_url: string;
169
+ }>;
170
+ /**
171
+ * List registered webhooks.
172
+ */
173
+ listWebhooks(): Promise<Array<{
174
+ id: string;
175
+ webhook_url: string;
176
+ events: string[];
177
+ enabled: boolean;
178
+ }>>;
179
+ /**
180
+ * Delete a webhook.
181
+ */
182
+ deleteWebhook(webhookId: string): Promise<void>;
183
+ /**
184
+ * Verify a webhook payload signature (for use in your webhook handler).
185
+ * Returns true if the HMAC-SHA256 signature matches.
186
+ */
187
+ static verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
143
188
  /**
144
189
  * Rotate this agent's keypairs. Old messages encrypted with old keys cannot be re-decrypted.
145
190
  */
package/dist/index.d.ts CHANGED
@@ -124,6 +124,22 @@ declare class VoidlyAgent {
124
124
  since?: string;
125
125
  limit?: number;
126
126
  }): Promise<DecryptedMessage[]>;
127
+ /**
128
+ * Delete a message by ID (must be sender or recipient).
129
+ */
130
+ deleteMessage(messageId: string): Promise<boolean>;
131
+ /**
132
+ * Get this agent's own profile.
133
+ */
134
+ getProfile(): Promise<AgentProfile>;
135
+ /**
136
+ * Update this agent's profile (name, capabilities, metadata).
137
+ */
138
+ updateProfile(updates: {
139
+ name?: string;
140
+ capabilities?: string[];
141
+ metadata?: Record<string, unknown>;
142
+ }): Promise<void>;
127
143
  /**
128
144
  * Look up an agent's public profile and keys.
129
145
  */
@@ -140,6 +156,35 @@ declare class VoidlyAgent {
140
156
  * Get relay network statistics.
141
157
  */
142
158
  stats(): Promise<Record<string, unknown>>;
159
+ /**
160
+ * Register a webhook for real-time message delivery.
161
+ * Instead of polling receive(), messages are POSTed to your URL with HMAC signatures.
162
+ */
163
+ registerWebhook(webhookUrl: string, options?: {
164
+ events?: string[];
165
+ }): Promise<{
166
+ id: string;
167
+ secret: string;
168
+ webhook_url: string;
169
+ }>;
170
+ /**
171
+ * List registered webhooks.
172
+ */
173
+ listWebhooks(): Promise<Array<{
174
+ id: string;
175
+ webhook_url: string;
176
+ events: string[];
177
+ enabled: boolean;
178
+ }>>;
179
+ /**
180
+ * Delete a webhook.
181
+ */
182
+ deleteWebhook(webhookId: string): Promise<void>;
183
+ /**
184
+ * Verify a webhook payload signature (for use in your webhook handler).
185
+ * Returns true if the HMAC-SHA256 signature matches.
186
+ */
187
+ static verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
143
188
  /**
144
189
  * Rotate this agent's keypairs. Old messages encrypted with old keys cannot be re-decrypted.
145
190
  */
package/dist/index.js CHANGED
@@ -2526,6 +2526,47 @@ var VoidlyAgent = class _VoidlyAgent {
2526
2526
  }
2527
2527
  return decrypted;
2528
2528
  }
2529
+ // ─── Message Management ─────────────────────────────────────────────────────
2530
+ /**
2531
+ * Delete a message by ID (must be sender or recipient).
2532
+ */
2533
+ async deleteMessage(messageId) {
2534
+ const res = await fetch(`${this.baseUrl}/v1/agent/messages/${messageId}`, {
2535
+ method: "DELETE",
2536
+ headers: { "X-Agent-Key": this.apiKey }
2537
+ });
2538
+ return res.ok;
2539
+ }
2540
+ // ─── Profile ──────────────────────────────────────────────────────────────
2541
+ /**
2542
+ * Get this agent's own profile.
2543
+ */
2544
+ async getProfile() {
2545
+ const res = await fetch(`${this.baseUrl}/v1/agent/profile`, {
2546
+ headers: { "X-Agent-Key": this.apiKey }
2547
+ });
2548
+ if (!res.ok) {
2549
+ throw new Error("Failed to fetch profile");
2550
+ }
2551
+ return await res.json();
2552
+ }
2553
+ /**
2554
+ * Update this agent's profile (name, capabilities, metadata).
2555
+ */
2556
+ async updateProfile(updates) {
2557
+ const res = await fetch(`${this.baseUrl}/v1/agent/profile`, {
2558
+ method: "PATCH",
2559
+ headers: {
2560
+ "Content-Type": "application/json",
2561
+ "X-Agent-Key": this.apiKey
2562
+ },
2563
+ body: JSON.stringify(updates)
2564
+ });
2565
+ if (!res.ok) {
2566
+ const err = await res.json().catch(() => ({}));
2567
+ throw new Error(`Profile update failed: ${err.error || res.statusText}`);
2568
+ }
2569
+ }
2529
2570
  // ─── Discovery ──────────────────────────────────────────────────────────────
2530
2571
  /**
2531
2572
  * Look up an agent's public profile and keys.
@@ -2555,6 +2596,72 @@ var VoidlyAgent = class _VoidlyAgent {
2555
2596
  const res = await fetch(`${this.baseUrl}/v1/agent/stats`);
2556
2597
  return await res.json();
2557
2598
  }
2599
+ // ─── Webhooks ──────────────────────────────────────────────────────────────
2600
+ /**
2601
+ * Register a webhook for real-time message delivery.
2602
+ * Instead of polling receive(), messages are POSTed to your URL with HMAC signatures.
2603
+ */
2604
+ async registerWebhook(webhookUrl, options = {}) {
2605
+ const res = await fetch(`${this.baseUrl}/v1/agent/webhooks`, {
2606
+ method: "POST",
2607
+ headers: {
2608
+ "Content-Type": "application/json",
2609
+ "X-Agent-Key": this.apiKey
2610
+ },
2611
+ body: JSON.stringify({
2612
+ webhook_url: webhookUrl,
2613
+ events: options.events
2614
+ })
2615
+ });
2616
+ if (!res.ok) {
2617
+ const err = await res.json().catch(() => ({}));
2618
+ throw new Error(`Webhook registration failed: ${err.error?.message || err.error || res.statusText}`);
2619
+ }
2620
+ return await res.json();
2621
+ }
2622
+ /**
2623
+ * List registered webhooks.
2624
+ */
2625
+ async listWebhooks() {
2626
+ const res = await fetch(`${this.baseUrl}/v1/agent/webhooks`, {
2627
+ headers: { "X-Agent-Key": this.apiKey }
2628
+ });
2629
+ if (!res.ok) return [];
2630
+ const data = await res.json();
2631
+ return data.webhooks;
2632
+ }
2633
+ /**
2634
+ * Delete a webhook.
2635
+ */
2636
+ async deleteWebhook(webhookId) {
2637
+ await fetch(`${this.baseUrl}/v1/agent/webhooks/${webhookId}`, {
2638
+ method: "DELETE",
2639
+ headers: { "X-Agent-Key": this.apiKey }
2640
+ });
2641
+ }
2642
+ /**
2643
+ * Verify a webhook payload signature (for use in your webhook handler).
2644
+ * Returns true if the HMAC-SHA256 signature matches.
2645
+ */
2646
+ static async verifyWebhookSignature(payload, signature, secret) {
2647
+ const encoder = new TextEncoder();
2648
+ if (typeof globalThis.crypto?.subtle !== "undefined") {
2649
+ const key = await globalThis.crypto.subtle.importKey(
2650
+ "raw",
2651
+ encoder.encode(secret),
2652
+ { name: "HMAC", hash: "SHA-256" },
2653
+ false,
2654
+ ["sign"]
2655
+ );
2656
+ const sig = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(payload));
2657
+ const expectedSig2 = `sha256=${Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
2658
+ return signature === expectedSig2;
2659
+ }
2660
+ const { createHmac } = await import("crypto");
2661
+ const expectedSig = `sha256=${createHmac("sha256", secret).update(payload).digest("hex")}`;
2662
+ return signature === expectedSig;
2663
+ }
2664
+ // ─── Key Management ───────────────────────────────────────────────────────
2558
2665
  /**
2559
2666
  * Rotate this agent's keypairs. Old messages encrypted with old keys cannot be re-decrypted.
2560
2667
  */
package/dist/index.mjs CHANGED
@@ -2516,6 +2516,47 @@ var VoidlyAgent = class _VoidlyAgent {
2516
2516
  }
2517
2517
  return decrypted;
2518
2518
  }
2519
+ // ─── Message Management ─────────────────────────────────────────────────────
2520
+ /**
2521
+ * Delete a message by ID (must be sender or recipient).
2522
+ */
2523
+ async deleteMessage(messageId) {
2524
+ const res = await fetch(`${this.baseUrl}/v1/agent/messages/${messageId}`, {
2525
+ method: "DELETE",
2526
+ headers: { "X-Agent-Key": this.apiKey }
2527
+ });
2528
+ return res.ok;
2529
+ }
2530
+ // ─── Profile ──────────────────────────────────────────────────────────────
2531
+ /**
2532
+ * Get this agent's own profile.
2533
+ */
2534
+ async getProfile() {
2535
+ const res = await fetch(`${this.baseUrl}/v1/agent/profile`, {
2536
+ headers: { "X-Agent-Key": this.apiKey }
2537
+ });
2538
+ if (!res.ok) {
2539
+ throw new Error("Failed to fetch profile");
2540
+ }
2541
+ return await res.json();
2542
+ }
2543
+ /**
2544
+ * Update this agent's profile (name, capabilities, metadata).
2545
+ */
2546
+ async updateProfile(updates) {
2547
+ const res = await fetch(`${this.baseUrl}/v1/agent/profile`, {
2548
+ method: "PATCH",
2549
+ headers: {
2550
+ "Content-Type": "application/json",
2551
+ "X-Agent-Key": this.apiKey
2552
+ },
2553
+ body: JSON.stringify(updates)
2554
+ });
2555
+ if (!res.ok) {
2556
+ const err = await res.json().catch(() => ({}));
2557
+ throw new Error(`Profile update failed: ${err.error || res.statusText}`);
2558
+ }
2559
+ }
2519
2560
  // ─── Discovery ──────────────────────────────────────────────────────────────
2520
2561
  /**
2521
2562
  * Look up an agent's public profile and keys.
@@ -2545,6 +2586,72 @@ var VoidlyAgent = class _VoidlyAgent {
2545
2586
  const res = await fetch(`${this.baseUrl}/v1/agent/stats`);
2546
2587
  return await res.json();
2547
2588
  }
2589
+ // ─── Webhooks ──────────────────────────────────────────────────────────────
2590
+ /**
2591
+ * Register a webhook for real-time message delivery.
2592
+ * Instead of polling receive(), messages are POSTed to your URL with HMAC signatures.
2593
+ */
2594
+ async registerWebhook(webhookUrl, options = {}) {
2595
+ const res = await fetch(`${this.baseUrl}/v1/agent/webhooks`, {
2596
+ method: "POST",
2597
+ headers: {
2598
+ "Content-Type": "application/json",
2599
+ "X-Agent-Key": this.apiKey
2600
+ },
2601
+ body: JSON.stringify({
2602
+ webhook_url: webhookUrl,
2603
+ events: options.events
2604
+ })
2605
+ });
2606
+ if (!res.ok) {
2607
+ const err = await res.json().catch(() => ({}));
2608
+ throw new Error(`Webhook registration failed: ${err.error?.message || err.error || res.statusText}`);
2609
+ }
2610
+ return await res.json();
2611
+ }
2612
+ /**
2613
+ * List registered webhooks.
2614
+ */
2615
+ async listWebhooks() {
2616
+ const res = await fetch(`${this.baseUrl}/v1/agent/webhooks`, {
2617
+ headers: { "X-Agent-Key": this.apiKey }
2618
+ });
2619
+ if (!res.ok) return [];
2620
+ const data = await res.json();
2621
+ return data.webhooks;
2622
+ }
2623
+ /**
2624
+ * Delete a webhook.
2625
+ */
2626
+ async deleteWebhook(webhookId) {
2627
+ await fetch(`${this.baseUrl}/v1/agent/webhooks/${webhookId}`, {
2628
+ method: "DELETE",
2629
+ headers: { "X-Agent-Key": this.apiKey }
2630
+ });
2631
+ }
2632
+ /**
2633
+ * Verify a webhook payload signature (for use in your webhook handler).
2634
+ * Returns true if the HMAC-SHA256 signature matches.
2635
+ */
2636
+ static async verifyWebhookSignature(payload, signature, secret) {
2637
+ const encoder = new TextEncoder();
2638
+ if (typeof globalThis.crypto?.subtle !== "undefined") {
2639
+ const key = await globalThis.crypto.subtle.importKey(
2640
+ "raw",
2641
+ encoder.encode(secret),
2642
+ { name: "HMAC", hash: "SHA-256" },
2643
+ false,
2644
+ ["sign"]
2645
+ );
2646
+ const sig = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(payload));
2647
+ const expectedSig2 = `sha256=${Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
2648
+ return signature === expectedSig2;
2649
+ }
2650
+ const { createHmac } = await import("crypto");
2651
+ const expectedSig = `sha256=${createHmac("sha256", secret).update(payload).digest("hex")}`;
2652
+ return signature === expectedSig;
2653
+ }
2654
+ // ─── Key Management ───────────────────────────────────────────────────────
2548
2655
  /**
2549
2656
  * Rotate this agent's keypairs. Old messages encrypted with old keys cannot be re-decrypted.
2550
2657
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidly/agent-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "E2E encrypted agent-to-agent communication SDK — true client-side encryption",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",