@voidly/agent-sdk 2.2.0 → 3.1.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
@@ -28,6 +28,12 @@ interface AgentProfile {
28
28
  encryption_public_key: string;
29
29
  /** ML-KEM-768 public key (base64, 1184 bytes) — present if agent supports PQ */
30
30
  mlkem_public_key?: string;
31
+ /** X3DH signed prekey bundle — enables async key agreement with offline agents */
32
+ signed_prekey?: {
33
+ public_key: string;
34
+ signature: string;
35
+ id: number;
36
+ };
31
37
  capabilities: string[];
32
38
  message_count: number;
33
39
  }
@@ -71,6 +77,14 @@ interface VoidlyAgentConfig {
71
77
  timeout?: number;
72
78
  /** Enable post-quantum hybrid encryption — ML-KEM-768 + X25519 (default: true) */
73
79
  postQuantum?: boolean;
80
+ /** Enable deniable messaging — HMAC authentication instead of Ed25519 signatures (default: false) */
81
+ deniable?: boolean;
82
+ /** Enable Double Ratchet with DH ratchet for post-compromise recovery (default: true) */
83
+ doubleRatchet?: boolean;
84
+ /** Random delay range in ms before sending (metadata timing protection, default: 0 = disabled) */
85
+ jitterMs?: number;
86
+ /** Use long-poll for listen() instead of short-interval polling (default: true) */
87
+ longPoll?: boolean;
74
88
  }
75
89
  interface ListenOptions {
76
90
  /** Milliseconds between polls (default: 2000, min: 500) */
@@ -151,8 +165,14 @@ declare class VoidlyAgent {
151
165
  private requireSignatures;
152
166
  private timeout;
153
167
  private postQuantum;
168
+ private deniable;
169
+ private doubleRatchet;
170
+ private jitterMs;
171
+ private longPoll;
154
172
  private mlkemPublicKey;
155
173
  private mlkemSecretKey;
174
+ private _signedPrekey;
175
+ private _signedPrekeyId;
156
176
  private _pinnedDids;
157
177
  private _listeners;
158
178
  private _conversations;
@@ -161,6 +181,10 @@ declare class VoidlyAgent {
161
181
  private _identityCache;
162
182
  private _seenMessageIds;
163
183
  private _decryptFailCount;
184
+ private _rpcHandlers;
185
+ private _rpcPending;
186
+ private _coverTrafficTimer;
187
+ private _rpcListener;
164
188
  private constructor();
165
189
  /**
166
190
  * Register a new agent on the Voidly relay.
@@ -184,9 +208,17 @@ declare class VoidlyAgent {
184
208
  sendStep: number;
185
209
  recvChainKey: string;
186
210
  recvStep: number;
211
+ rootKey?: string;
212
+ dhSendSecretKey?: string;
213
+ dhSendPublicKey?: string;
214
+ dhRecvPubKey?: string;
215
+ prevSendStep?: number;
187
216
  }>;
188
217
  mlkemPublicKey?: string;
189
218
  mlkemSecretKey?: string;
219
+ signedPrekeySecret?: string;
220
+ signedPrekeyPublic?: string;
221
+ signedPrekeyId?: number;
190
222
  }, config?: VoidlyAgentConfig): VoidlyAgent;
191
223
  /**
192
224
  * Export credentials for persistence.
@@ -204,9 +236,17 @@ declare class VoidlyAgent {
204
236
  sendStep: number;
205
237
  recvChainKey: string;
206
238
  recvStep: number;
239
+ rootKey?: string;
240
+ dhSendSecretKey?: string;
241
+ dhSendPublicKey?: string;
242
+ dhRecvPubKey?: string;
243
+ prevSendStep?: number;
207
244
  }>;
208
245
  mlkemPublicKey?: string;
209
246
  mlkemSecretKey?: string;
247
+ signedPrekeySecret?: string;
248
+ signedPrekeyPublic?: string;
249
+ signedPrekeyId?: number;
210
250
  };
211
251
  /**
212
252
  * Get the number of messages that failed to decrypt.
@@ -836,6 +876,82 @@ declare class VoidlyAgent {
836
876
  status: string;
837
877
  warning?: string;
838
878
  }>;
879
+ /**
880
+ * Upload prekey bundle for X3DH async key agreement.
881
+ * Other agents can fetch your prekeys and establish encrypted sessions
882
+ * even while you're offline.
883
+ *
884
+ * @param count Number of one-time prekeys to upload (default: 20)
885
+ */
886
+ uploadPrekeys(count?: number): Promise<{
887
+ uploaded: number;
888
+ signed_prekey_updated: boolean;
889
+ }>;
890
+ /**
891
+ * Fetch another agent's prekey bundle for X3DH key agreement.
892
+ * Use this to establish an encrypted session with an offline agent.
893
+ */
894
+ fetchPrekeys(did: string): Promise<{
895
+ identity_key: string;
896
+ signing_key: string;
897
+ signed_prekey: {
898
+ public_key: string;
899
+ signature: string;
900
+ id: number;
901
+ } | null;
902
+ one_time_prekey: {
903
+ id: number;
904
+ public_key: string;
905
+ } | null;
906
+ mlkem_public_key: string | null;
907
+ } | null>;
908
+ /**
909
+ * Create a channel with client-side encryption.
910
+ * The channel symmetric key is generated locally and encrypted per-member.
911
+ * The relay NEVER sees the plaintext channel key — true E2E for groups.
912
+ */
913
+ createEncryptedChannel(options: {
914
+ name: string;
915
+ description?: string;
916
+ topic?: string;
917
+ private?: boolean;
918
+ }): Promise<{
919
+ id: string;
920
+ name: string;
921
+ channelKey: Uint8Array;
922
+ }>;
923
+ /**
924
+ * Post a client-side encrypted message to a channel.
925
+ * Uses the channel's shared symmetric key — relay never sees plaintext.
926
+ *
927
+ * @param channelId Channel ID
928
+ * @param message Plaintext message
929
+ * @param channelKey 32-byte symmetric channel key (from createEncryptedChannel or received via invite)
930
+ */
931
+ postEncrypted(channelId: string, message: string, channelKey: Uint8Array): Promise<{
932
+ id: string;
933
+ }>;
934
+ /**
935
+ * Read and decrypt channel messages using client-side channel key.
936
+ * Ignores server-side encryption entirely — true E2E.
937
+ *
938
+ * @param channelId Channel ID
939
+ * @param channelKey 32-byte symmetric channel key
940
+ */
941
+ readEncrypted(channelId: string, channelKey: Uint8Array, options?: {
942
+ since?: string;
943
+ before?: string;
944
+ limit?: number;
945
+ }): Promise<{
946
+ messages: Array<{
947
+ id: string;
948
+ from: string;
949
+ content: string;
950
+ timestamp: string;
951
+ signatureValid: boolean;
952
+ }>;
953
+ count: number;
954
+ }>;
839
955
  /**
840
956
  * Listen for incoming messages with an event-driven callback.
841
957
  * Uses adaptive polling — speeds up when messages are flowing, slows down when idle.
@@ -884,6 +1000,100 @@ declare class VoidlyAgent {
884
1000
  * Stop all active listeners. Useful for clean shutdown.
885
1001
  */
886
1002
  stopAll(): void;
1003
+ /**
1004
+ * Invoke a function on a remote agent. Synchronous RPC over encrypted messaging.
1005
+ * The remote agent must have registered a handler via `onInvoke()`.
1006
+ *
1007
+ * @example
1008
+ * ```ts
1009
+ * // Call a translator agent
1010
+ * const result = await agent.invoke('did:voidly:translator', 'translate', {
1011
+ * text: 'Hello, world!',
1012
+ * to: 'ja',
1013
+ * });
1014
+ * console.log(result.translation); // こんにちは
1015
+ *
1016
+ * // With timeout
1017
+ * const data = await agent.invoke(peerDid, 'analyze', { url: '...' }, 15000);
1018
+ * ```
1019
+ */
1020
+ invoke(targetDid: string, method: string, params?: any, timeoutMs?: number): Promise<any>;
1021
+ /**
1022
+ * Register a handler for incoming RPC invocations.
1023
+ * When another agent calls `invoke(yourDid, method, params)`, your handler runs.
1024
+ *
1025
+ * @example
1026
+ * ```ts
1027
+ * // Register a translation capability
1028
+ * agent.onInvoke('translate', async (params, callerDid) => {
1029
+ * const result = await myTranslateFunction(params.text, params.to);
1030
+ * return { translation: result };
1031
+ * });
1032
+ *
1033
+ * // Register a search capability
1034
+ * agent.onInvoke('search', async (params) => {
1035
+ * return { results: await searchDatabase(params.query) };
1036
+ * });
1037
+ * ```
1038
+ */
1039
+ onInvoke(method: string, handler: (params: any, callerDid: string) => Promise<any>): void;
1040
+ /**
1041
+ * Remove an RPC handler.
1042
+ */
1043
+ offInvoke(method: string): void;
1044
+ /** @internal Start listening for RPC requests and responses */
1045
+ private _ensureRpcListener;
1046
+ /**
1047
+ * Send a message directly to a peer's webhook endpoint, bypassing the relay entirely.
1048
+ * The relay never sees the message — true peer-to-peer encrypted delivery.
1049
+ *
1050
+ * Falls back to relay-based send if direct delivery fails.
1051
+ *
1052
+ * @example
1053
+ * ```ts
1054
+ * // Try direct first, fall back to relay
1055
+ * const result = await agent.sendDirect('did:voidly:peer', 'Hello P2P!');
1056
+ * console.log(result.direct); // true if delivered directly, false if via relay
1057
+ * ```
1058
+ */
1059
+ sendDirect(recipientDid: string, message: string, options?: {
1060
+ contentType?: string;
1061
+ messageType?: string;
1062
+ threadId?: string;
1063
+ ttl?: number;
1064
+ }): Promise<SendResult & {
1065
+ direct: boolean;
1066
+ }>;
1067
+ /**
1068
+ * Enable cover traffic — sends encrypted noise at random intervals.
1069
+ * Makes real messages indistinguishable from cover traffic for any observer
1070
+ * monitoring message timing and frequency.
1071
+ *
1072
+ * Cover messages are encrypted and padded identically to real messages.
1073
+ * The relay cannot distinguish them from real traffic.
1074
+ *
1075
+ * @example
1076
+ * ```ts
1077
+ * // Send noise every ~30s (randomized ±50%)
1078
+ * agent.enableCoverTraffic({ intervalMs: 30000 });
1079
+ *
1080
+ * // Stop cover traffic
1081
+ * agent.disableCoverTraffic();
1082
+ * ```
1083
+ */
1084
+ enableCoverTraffic(options?: {
1085
+ intervalMs?: number;
1086
+ }): void;
1087
+ /**
1088
+ * Disable cover traffic.
1089
+ */
1090
+ disableCoverTraffic(): void;
1091
+ /**
1092
+ * Fetch from primary relay with fallback to alternate relays.
1093
+ * Unlike _timedFetch which only hits one URL, this tries all known relays.
1094
+ * @internal
1095
+ */
1096
+ private _resilientFetch;
887
1097
  /**
888
1098
  * Start or resume a conversation with another agent.
889
1099
  * Automatically manages thread IDs, message history, and reply chains.
package/dist/index.d.ts CHANGED
@@ -28,6 +28,12 @@ interface AgentProfile {
28
28
  encryption_public_key: string;
29
29
  /** ML-KEM-768 public key (base64, 1184 bytes) — present if agent supports PQ */
30
30
  mlkem_public_key?: string;
31
+ /** X3DH signed prekey bundle — enables async key agreement with offline agents */
32
+ signed_prekey?: {
33
+ public_key: string;
34
+ signature: string;
35
+ id: number;
36
+ };
31
37
  capabilities: string[];
32
38
  message_count: number;
33
39
  }
@@ -71,6 +77,14 @@ interface VoidlyAgentConfig {
71
77
  timeout?: number;
72
78
  /** Enable post-quantum hybrid encryption — ML-KEM-768 + X25519 (default: true) */
73
79
  postQuantum?: boolean;
80
+ /** Enable deniable messaging — HMAC authentication instead of Ed25519 signatures (default: false) */
81
+ deniable?: boolean;
82
+ /** Enable Double Ratchet with DH ratchet for post-compromise recovery (default: true) */
83
+ doubleRatchet?: boolean;
84
+ /** Random delay range in ms before sending (metadata timing protection, default: 0 = disabled) */
85
+ jitterMs?: number;
86
+ /** Use long-poll for listen() instead of short-interval polling (default: true) */
87
+ longPoll?: boolean;
74
88
  }
75
89
  interface ListenOptions {
76
90
  /** Milliseconds between polls (default: 2000, min: 500) */
@@ -151,8 +165,14 @@ declare class VoidlyAgent {
151
165
  private requireSignatures;
152
166
  private timeout;
153
167
  private postQuantum;
168
+ private deniable;
169
+ private doubleRatchet;
170
+ private jitterMs;
171
+ private longPoll;
154
172
  private mlkemPublicKey;
155
173
  private mlkemSecretKey;
174
+ private _signedPrekey;
175
+ private _signedPrekeyId;
156
176
  private _pinnedDids;
157
177
  private _listeners;
158
178
  private _conversations;
@@ -161,6 +181,10 @@ declare class VoidlyAgent {
161
181
  private _identityCache;
162
182
  private _seenMessageIds;
163
183
  private _decryptFailCount;
184
+ private _rpcHandlers;
185
+ private _rpcPending;
186
+ private _coverTrafficTimer;
187
+ private _rpcListener;
164
188
  private constructor();
165
189
  /**
166
190
  * Register a new agent on the Voidly relay.
@@ -184,9 +208,17 @@ declare class VoidlyAgent {
184
208
  sendStep: number;
185
209
  recvChainKey: string;
186
210
  recvStep: number;
211
+ rootKey?: string;
212
+ dhSendSecretKey?: string;
213
+ dhSendPublicKey?: string;
214
+ dhRecvPubKey?: string;
215
+ prevSendStep?: number;
187
216
  }>;
188
217
  mlkemPublicKey?: string;
189
218
  mlkemSecretKey?: string;
219
+ signedPrekeySecret?: string;
220
+ signedPrekeyPublic?: string;
221
+ signedPrekeyId?: number;
190
222
  }, config?: VoidlyAgentConfig): VoidlyAgent;
191
223
  /**
192
224
  * Export credentials for persistence.
@@ -204,9 +236,17 @@ declare class VoidlyAgent {
204
236
  sendStep: number;
205
237
  recvChainKey: string;
206
238
  recvStep: number;
239
+ rootKey?: string;
240
+ dhSendSecretKey?: string;
241
+ dhSendPublicKey?: string;
242
+ dhRecvPubKey?: string;
243
+ prevSendStep?: number;
207
244
  }>;
208
245
  mlkemPublicKey?: string;
209
246
  mlkemSecretKey?: string;
247
+ signedPrekeySecret?: string;
248
+ signedPrekeyPublic?: string;
249
+ signedPrekeyId?: number;
210
250
  };
211
251
  /**
212
252
  * Get the number of messages that failed to decrypt.
@@ -836,6 +876,82 @@ declare class VoidlyAgent {
836
876
  status: string;
837
877
  warning?: string;
838
878
  }>;
879
+ /**
880
+ * Upload prekey bundle for X3DH async key agreement.
881
+ * Other agents can fetch your prekeys and establish encrypted sessions
882
+ * even while you're offline.
883
+ *
884
+ * @param count Number of one-time prekeys to upload (default: 20)
885
+ */
886
+ uploadPrekeys(count?: number): Promise<{
887
+ uploaded: number;
888
+ signed_prekey_updated: boolean;
889
+ }>;
890
+ /**
891
+ * Fetch another agent's prekey bundle for X3DH key agreement.
892
+ * Use this to establish an encrypted session with an offline agent.
893
+ */
894
+ fetchPrekeys(did: string): Promise<{
895
+ identity_key: string;
896
+ signing_key: string;
897
+ signed_prekey: {
898
+ public_key: string;
899
+ signature: string;
900
+ id: number;
901
+ } | null;
902
+ one_time_prekey: {
903
+ id: number;
904
+ public_key: string;
905
+ } | null;
906
+ mlkem_public_key: string | null;
907
+ } | null>;
908
+ /**
909
+ * Create a channel with client-side encryption.
910
+ * The channel symmetric key is generated locally and encrypted per-member.
911
+ * The relay NEVER sees the plaintext channel key — true E2E for groups.
912
+ */
913
+ createEncryptedChannel(options: {
914
+ name: string;
915
+ description?: string;
916
+ topic?: string;
917
+ private?: boolean;
918
+ }): Promise<{
919
+ id: string;
920
+ name: string;
921
+ channelKey: Uint8Array;
922
+ }>;
923
+ /**
924
+ * Post a client-side encrypted message to a channel.
925
+ * Uses the channel's shared symmetric key — relay never sees plaintext.
926
+ *
927
+ * @param channelId Channel ID
928
+ * @param message Plaintext message
929
+ * @param channelKey 32-byte symmetric channel key (from createEncryptedChannel or received via invite)
930
+ */
931
+ postEncrypted(channelId: string, message: string, channelKey: Uint8Array): Promise<{
932
+ id: string;
933
+ }>;
934
+ /**
935
+ * Read and decrypt channel messages using client-side channel key.
936
+ * Ignores server-side encryption entirely — true E2E.
937
+ *
938
+ * @param channelId Channel ID
939
+ * @param channelKey 32-byte symmetric channel key
940
+ */
941
+ readEncrypted(channelId: string, channelKey: Uint8Array, options?: {
942
+ since?: string;
943
+ before?: string;
944
+ limit?: number;
945
+ }): Promise<{
946
+ messages: Array<{
947
+ id: string;
948
+ from: string;
949
+ content: string;
950
+ timestamp: string;
951
+ signatureValid: boolean;
952
+ }>;
953
+ count: number;
954
+ }>;
839
955
  /**
840
956
  * Listen for incoming messages with an event-driven callback.
841
957
  * Uses adaptive polling — speeds up when messages are flowing, slows down when idle.
@@ -884,6 +1000,100 @@ declare class VoidlyAgent {
884
1000
  * Stop all active listeners. Useful for clean shutdown.
885
1001
  */
886
1002
  stopAll(): void;
1003
+ /**
1004
+ * Invoke a function on a remote agent. Synchronous RPC over encrypted messaging.
1005
+ * The remote agent must have registered a handler via `onInvoke()`.
1006
+ *
1007
+ * @example
1008
+ * ```ts
1009
+ * // Call a translator agent
1010
+ * const result = await agent.invoke('did:voidly:translator', 'translate', {
1011
+ * text: 'Hello, world!',
1012
+ * to: 'ja',
1013
+ * });
1014
+ * console.log(result.translation); // こんにちは
1015
+ *
1016
+ * // With timeout
1017
+ * const data = await agent.invoke(peerDid, 'analyze', { url: '...' }, 15000);
1018
+ * ```
1019
+ */
1020
+ invoke(targetDid: string, method: string, params?: any, timeoutMs?: number): Promise<any>;
1021
+ /**
1022
+ * Register a handler for incoming RPC invocations.
1023
+ * When another agent calls `invoke(yourDid, method, params)`, your handler runs.
1024
+ *
1025
+ * @example
1026
+ * ```ts
1027
+ * // Register a translation capability
1028
+ * agent.onInvoke('translate', async (params, callerDid) => {
1029
+ * const result = await myTranslateFunction(params.text, params.to);
1030
+ * return { translation: result };
1031
+ * });
1032
+ *
1033
+ * // Register a search capability
1034
+ * agent.onInvoke('search', async (params) => {
1035
+ * return { results: await searchDatabase(params.query) };
1036
+ * });
1037
+ * ```
1038
+ */
1039
+ onInvoke(method: string, handler: (params: any, callerDid: string) => Promise<any>): void;
1040
+ /**
1041
+ * Remove an RPC handler.
1042
+ */
1043
+ offInvoke(method: string): void;
1044
+ /** @internal Start listening for RPC requests and responses */
1045
+ private _ensureRpcListener;
1046
+ /**
1047
+ * Send a message directly to a peer's webhook endpoint, bypassing the relay entirely.
1048
+ * The relay never sees the message — true peer-to-peer encrypted delivery.
1049
+ *
1050
+ * Falls back to relay-based send if direct delivery fails.
1051
+ *
1052
+ * @example
1053
+ * ```ts
1054
+ * // Try direct first, fall back to relay
1055
+ * const result = await agent.sendDirect('did:voidly:peer', 'Hello P2P!');
1056
+ * console.log(result.direct); // true if delivered directly, false if via relay
1057
+ * ```
1058
+ */
1059
+ sendDirect(recipientDid: string, message: string, options?: {
1060
+ contentType?: string;
1061
+ messageType?: string;
1062
+ threadId?: string;
1063
+ ttl?: number;
1064
+ }): Promise<SendResult & {
1065
+ direct: boolean;
1066
+ }>;
1067
+ /**
1068
+ * Enable cover traffic — sends encrypted noise at random intervals.
1069
+ * Makes real messages indistinguishable from cover traffic for any observer
1070
+ * monitoring message timing and frequency.
1071
+ *
1072
+ * Cover messages are encrypted and padded identically to real messages.
1073
+ * The relay cannot distinguish them from real traffic.
1074
+ *
1075
+ * @example
1076
+ * ```ts
1077
+ * // Send noise every ~30s (randomized ±50%)
1078
+ * agent.enableCoverTraffic({ intervalMs: 30000 });
1079
+ *
1080
+ * // Stop cover traffic
1081
+ * agent.disableCoverTraffic();
1082
+ * ```
1083
+ */
1084
+ enableCoverTraffic(options?: {
1085
+ intervalMs?: number;
1086
+ }): void;
1087
+ /**
1088
+ * Disable cover traffic.
1089
+ */
1090
+ disableCoverTraffic(): void;
1091
+ /**
1092
+ * Fetch from primary relay with fallback to alternate relays.
1093
+ * Unlike _timedFetch which only hits one URL, this tries all known relays.
1094
+ * @internal
1095
+ */
1096
+ private _resilientFetch;
887
1097
  /**
888
1098
  * Start or resume a conversation with another agent.
889
1099
  * Automatically manages thread IDs, message history, and reply chains.