@zerox1/sdk 0.2.18 → 0.2.20
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.ts +240 -0
- package/dist/index.js +401 -1
- package/package.json +5 -5
- package/packages/darwin-arm64/bin/zerox1-node +0 -0
- package/packages/darwin-arm64/package.json +1 -1
- package/packages/darwin-x64/bin/zerox1-node +0 -0
- package/packages/darwin-x64/package.json +1 -1
- package/packages/linux-x64/bin/zerox1-node +0 -0
- package/packages/linux-x64/package.json +1 -1
- package/packages/win32-x64/bin/zerox1-node.exe +0 -0
- package/packages/win32-x64/package.json +1 -1
- package/src/index.ts +572 -0
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,172 @@ export interface SendFeedbackParams {
|
|
|
64
64
|
outcome: 'negative' | 'neutral' | 'positive';
|
|
65
65
|
role: 'participant' | 'notary';
|
|
66
66
|
}
|
|
67
|
+
/** Decoded content of an incoming PROPOSE envelope payload. */
|
|
68
|
+
export interface ProposePayload {
|
|
69
|
+
/** Amount in USDC microunits (e.g. 1_000_000n = 1 USDC). 0n = unspecified. */
|
|
70
|
+
amount: bigint;
|
|
71
|
+
/** Maximum counter rounds the proposer allows. Default: 2. */
|
|
72
|
+
maxRounds: number;
|
|
73
|
+
/** Human-readable proposal message. */
|
|
74
|
+
message: string;
|
|
75
|
+
}
|
|
76
|
+
/** Decoded content of an incoming COUNTER envelope payload. */
|
|
77
|
+
export interface CounterPayload {
|
|
78
|
+
/** Counter-offered amount in USDC microunits. */
|
|
79
|
+
amount: bigint;
|
|
80
|
+
/** Which counter round this is (1-indexed). */
|
|
81
|
+
round: number;
|
|
82
|
+
/** Maximum rounds as originally set in the PROPOSE. */
|
|
83
|
+
maxRounds: number;
|
|
84
|
+
/** Human-readable counter message. */
|
|
85
|
+
message: string;
|
|
86
|
+
}
|
|
87
|
+
export interface SendProposeParams {
|
|
88
|
+
/** Hex-encoded 32-byte agent ID of the target agent. */
|
|
89
|
+
recipient: string;
|
|
90
|
+
/**
|
|
91
|
+
* 16-byte hex conversation ID. Auto-generated if omitted.
|
|
92
|
+
* The returned object includes the final conversation_id used.
|
|
93
|
+
*/
|
|
94
|
+
conversationId?: string;
|
|
95
|
+
/** Bid amount in USDC microunits. Default: 0n (unspecified). */
|
|
96
|
+
amount?: bigint;
|
|
97
|
+
/**
|
|
98
|
+
* Max counter rounds allowed. Default: 2.
|
|
99
|
+
* Set to 3 if your average reputation score is >= 70.
|
|
100
|
+
*/
|
|
101
|
+
maxRounds?: number;
|
|
102
|
+
/** Proposal text (task description, terms, etc.). */
|
|
103
|
+
message: string;
|
|
104
|
+
}
|
|
105
|
+
export interface SendCounterParams {
|
|
106
|
+
/** Hex-encoded 32-byte agent ID of the counterparty. */
|
|
107
|
+
recipient: string;
|
|
108
|
+
/** Conversation ID from the original PROPOSE. */
|
|
109
|
+
conversationId: string;
|
|
110
|
+
/** Counter-offered amount in USDC microunits. */
|
|
111
|
+
amount: bigint;
|
|
112
|
+
/** Counter round number (1-indexed). Must be <= maxRounds. */
|
|
113
|
+
round: number;
|
|
114
|
+
/** maxRounds from the original PROPOSE. */
|
|
115
|
+
maxRounds: number;
|
|
116
|
+
/** Explanation of your counter-offer. */
|
|
117
|
+
message?: string;
|
|
118
|
+
}
|
|
119
|
+
/** Decoded content of an incoming ACCEPT envelope payload. */
|
|
120
|
+
export interface AcceptPayload {
|
|
121
|
+
/**
|
|
122
|
+
* The amount being accepted in USDC microunits.
|
|
123
|
+
* Matches the most-recent COUNTER amount, or the original PROPOSE amount
|
|
124
|
+
* if no COUNTER was issued. Use this value for `lockPayment`.
|
|
125
|
+
*/
|
|
126
|
+
amount: bigint;
|
|
127
|
+
/** Optional acceptance message. */
|
|
128
|
+
message: string;
|
|
129
|
+
}
|
|
130
|
+
export interface SendAcceptParams {
|
|
131
|
+
/** Hex-encoded 32-byte agent ID of the agent whose offer you are accepting. */
|
|
132
|
+
recipient: string;
|
|
133
|
+
/** Conversation ID from the original PROPOSE. */
|
|
134
|
+
conversationId: string;
|
|
135
|
+
/**
|
|
136
|
+
* The agreed amount in USDC microunits — must match the most-recent COUNTER
|
|
137
|
+
* (or original PROPOSE if no COUNTER was sent). Both parties use this
|
|
138
|
+
* to call `lockPayment` with the correct amount.
|
|
139
|
+
*/
|
|
140
|
+
amount: bigint;
|
|
141
|
+
/** Optional acceptance message. */
|
|
142
|
+
message?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface LockPaymentParams {
|
|
145
|
+
/** Hex-encoded 32-byte agent_id of the provider who will receive payment. */
|
|
146
|
+
provider: string;
|
|
147
|
+
/** Hex-encoded 16-byte conversation ID from the negotiation. */
|
|
148
|
+
conversationId: string;
|
|
149
|
+
/** Amount to lock in USDC microunits (must match the ACCEPT amount). */
|
|
150
|
+
amount: bigint;
|
|
151
|
+
/** Notary fee in USDC microunits. Default: amount / 10n. */
|
|
152
|
+
notaryFee?: bigint;
|
|
153
|
+
/** Solana slot timeout before provider can claim without approval. Default: 1000. */
|
|
154
|
+
timeoutSlots?: number;
|
|
155
|
+
/** Hex-encoded 32-byte agent_id of a designated notary (optional). */
|
|
156
|
+
notary?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface ApprovePaymentParams {
|
|
159
|
+
/** Hex-encoded 32-byte agent_id of the requester (payer). */
|
|
160
|
+
requester: string;
|
|
161
|
+
/** Hex-encoded 32-byte agent_id of the provider (payee). */
|
|
162
|
+
provider: string;
|
|
163
|
+
/** Hex-encoded 16-byte conversation ID from the negotiation. */
|
|
164
|
+
conversationId: string;
|
|
165
|
+
/** Hex-encoded 32-byte agent_id of the notary. Defaults to this agent (self-approval). */
|
|
166
|
+
notary?: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Default token mint addresses allowed in agent-to-agent swaps.
|
|
170
|
+
* Prevents agents from being tricked into swapping into fraudulent tokens.
|
|
171
|
+
*
|
|
172
|
+
* Both devnet and mainnet mints are included; the node validates against
|
|
173
|
+
* whichever network it is connected to.
|
|
174
|
+
*
|
|
175
|
+
* Override per-agent with `Zerox1Agent.setSwapWhitelist()`.
|
|
176
|
+
*/
|
|
177
|
+
export declare const DEFAULT_SWAP_WHITELIST: ReadonlySet<string>;
|
|
178
|
+
export interface SwapParams {
|
|
179
|
+
/** Solana base58 mint address of the token to sell. */
|
|
180
|
+
inputMint: string;
|
|
181
|
+
/** Solana base58 mint address of the token to buy. */
|
|
182
|
+
outputMint: string;
|
|
183
|
+
/** Amount in input-token native units (e.g. lamports for SOL). */
|
|
184
|
+
amount: bigint;
|
|
185
|
+
/** Max slippage in basis points. Default: 50 (0.5%). */
|
|
186
|
+
slippageBps?: number;
|
|
187
|
+
/** Custom whitelist to use instead of DEFAULT_SWAP_WHITELIST. Pass an empty set to disable. */
|
|
188
|
+
whitelist?: ReadonlySet<string>;
|
|
189
|
+
}
|
|
190
|
+
export interface SwapResult {
|
|
191
|
+
/** Input amount actually consumed (native units). */
|
|
192
|
+
inAmount: bigint;
|
|
193
|
+
/** Output amount received (native units). */
|
|
194
|
+
outAmount: bigint;
|
|
195
|
+
/** Transaction signature. */
|
|
196
|
+
signature: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Encode a PROPOSE payload into the structured wire format:
|
|
200
|
+
* `[16-byte LE i128 amount][JSON {"max_rounds": N, "message": "..."}]`
|
|
201
|
+
*/
|
|
202
|
+
export declare function encodeProposePayload(message: string, amount?: bigint, maxRounds?: number): Buffer;
|
|
203
|
+
/**
|
|
204
|
+
* Encode a COUNTER payload into the structured wire format:
|
|
205
|
+
* `[16-byte LE i128 amount][JSON {"round": N, "max_rounds": M, "message": "..."}]`
|
|
206
|
+
*/
|
|
207
|
+
export declare function encodeCounterPayload(amount: bigint, round: number, maxRounds: number, message?: string): Buffer;
|
|
208
|
+
/**
|
|
209
|
+
* Decode a PROPOSE envelope payload.
|
|
210
|
+
* Returns `null` if the payload is not in the structured format
|
|
211
|
+
* (e.g. a raw-string PROPOSE from an older agent).
|
|
212
|
+
*/
|
|
213
|
+
export declare function decodeProposePayload(payloadB64: string): ProposePayload | null;
|
|
214
|
+
/**
|
|
215
|
+
* Encode an ACCEPT payload.
|
|
216
|
+
* `[16-byte LE i128 amount][JSON {"message": "..."}]`
|
|
217
|
+
*
|
|
218
|
+
* Both parties must use the same `amount` — it is the agreed price that
|
|
219
|
+
* will be passed to `lockPayment` on-chain.
|
|
220
|
+
*/
|
|
221
|
+
export declare function encodeAcceptPayload(amount: bigint, message?: string): Buffer;
|
|
222
|
+
/**
|
|
223
|
+
* Decode an ACCEPT envelope payload.
|
|
224
|
+
* Returns `null` if the payload is not in the structured format
|
|
225
|
+
* (older agents may send a plain-text ACCEPT).
|
|
226
|
+
*/
|
|
227
|
+
export declare function decodeAcceptPayload(payloadB64: string): AcceptPayload | null;
|
|
228
|
+
/**
|
|
229
|
+
* Decode a COUNTER envelope payload.
|
|
230
|
+
* Returns `null` if the payload is not in the structured format.
|
|
231
|
+
*/
|
|
232
|
+
export declare function decodeCounterPayload(payloadB64: string): CounterPayload | null;
|
|
67
233
|
export interface HostingNode {
|
|
68
234
|
node_id: string;
|
|
69
235
|
name: string;
|
|
@@ -107,6 +273,7 @@ export declare class Zerox1Agent {
|
|
|
107
273
|
private port;
|
|
108
274
|
private nodeUrl;
|
|
109
275
|
private _reconnectDelay;
|
|
276
|
+
private _swapWhitelist;
|
|
110
277
|
private constructor();
|
|
111
278
|
/**
|
|
112
279
|
* Create an Zerox1Agent instance.
|
|
@@ -197,11 +364,76 @@ export declare class Zerox1Agent {
|
|
|
197
364
|
* Protocol rule 9 requires CBOR — this method handles the encoding.
|
|
198
365
|
*/
|
|
199
366
|
sendFeedback(params: SendFeedbackParams): Promise<SentConfirmation>;
|
|
367
|
+
/**
|
|
368
|
+
* Send a PROPOSE envelope.
|
|
369
|
+
*
|
|
370
|
+
* Calls POST /negotiate/propose — the node handles binary payload encoding.
|
|
371
|
+
* Returns the conversation ID used (auto-generated if not supplied)
|
|
372
|
+
* along with the send confirmation.
|
|
373
|
+
*/
|
|
374
|
+
sendPropose(params: SendProposeParams): Promise<{
|
|
375
|
+
conversationId: string;
|
|
376
|
+
confirmation: SentConfirmation;
|
|
377
|
+
}>;
|
|
378
|
+
/**
|
|
379
|
+
* Send a COUNTER envelope.
|
|
380
|
+
*
|
|
381
|
+
* Calls POST /negotiate/counter — the node handles binary payload encoding.
|
|
382
|
+
* Protocol rules: `round` must be 1-indexed and <= `maxRounds`.
|
|
383
|
+
*/
|
|
384
|
+
sendCounter(params: SendCounterParams): Promise<SentConfirmation>;
|
|
385
|
+
/**
|
|
386
|
+
* Send an ACCEPT envelope with the agreed amount.
|
|
387
|
+
*
|
|
388
|
+
* Calls POST /negotiate/accept — the node handles binary payload encoding.
|
|
389
|
+
* The `amount` must match the most-recent COUNTER (or original PROPOSE if
|
|
390
|
+
* there was no counter). Both parties use this value to call `lockPayment`.
|
|
391
|
+
*/
|
|
392
|
+
sendAccept(params: SendAcceptParams): Promise<SentConfirmation>;
|
|
393
|
+
/**
|
|
394
|
+
* Lock USDC in the escrow program on-chain.
|
|
395
|
+
*
|
|
396
|
+
* Call this after `sendAccept()` to fund the escrow account before the
|
|
397
|
+
* provider begins work. The node signs the Solana transaction using its
|
|
398
|
+
* own keypair (this agent is the requester / payer).
|
|
399
|
+
*
|
|
400
|
+
* The automatic lock triggered by `sendAccept()` (via the node loop) uses
|
|
401
|
+
* default parameters. Use this method for explicit control — e.g. a custom
|
|
402
|
+
* notary or timeout.
|
|
403
|
+
*
|
|
404
|
+
* @param params.amount — must match the amount in the ACCEPT payload exactly.
|
|
405
|
+
*/
|
|
406
|
+
lockPayment(params: LockPaymentParams): Promise<void>;
|
|
407
|
+
/**
|
|
408
|
+
* Approve and release a locked escrow payment to the provider.
|
|
409
|
+
*
|
|
410
|
+
* Call this after verifying the provider's DELIVER output is satisfactory.
|
|
411
|
+
* The node signs as the approver (notary or requester).
|
|
412
|
+
*
|
|
413
|
+
* @param params.notary — defaults to this agent (self-approval when no separate notary).
|
|
414
|
+
*/
|
|
415
|
+
approvePayment(params: ApprovePaymentParams): Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Override the token whitelist for this agent instance.
|
|
418
|
+
* Pass an empty Set to disable whitelist enforcement (not recommended).
|
|
419
|
+
*/
|
|
420
|
+
setSwapWhitelist(whitelist: ReadonlySet<string>): void;
|
|
421
|
+
/**
|
|
422
|
+
* Execute a Jupiter token swap via the node's `/trade/swap` endpoint.
|
|
423
|
+
*
|
|
424
|
+
* Both `inputMint` and `outputMint` must be in the active whitelist
|
|
425
|
+
* (DEFAULT_SWAP_WHITELIST unless overridden via `setSwapWhitelist()`).
|
|
426
|
+
* This prevents agents from being deceived into swapping fraudulent tokens.
|
|
427
|
+
*
|
|
428
|
+
* @throws If either mint is not whitelisted, or the node rejects the swap.
|
|
429
|
+
*/
|
|
430
|
+
swap(params: SwapParams): Promise<SwapResult>;
|
|
200
431
|
/** Generate a random 16-byte conversation ID as hex. */
|
|
201
432
|
newConversationId(): string;
|
|
202
433
|
/**
|
|
203
434
|
* Encode a bid value (i128 LE) into the first 16 bytes of a payload,
|
|
204
435
|
* followed by optional extra bytes (your terms).
|
|
436
|
+
* @deprecated Use `encodeProposePayload()` or `encodeCounterPayload()` instead.
|
|
205
437
|
*/
|
|
206
438
|
encodeBidValue(value: bigint, rest?: Buffer): Buffer;
|
|
207
439
|
private _connectInbox;
|
|
@@ -264,6 +496,14 @@ export declare class HostedAgent {
|
|
|
264
496
|
* Mirrors `Zerox1Agent.sendFeedback()`.
|
|
265
497
|
*/
|
|
266
498
|
sendFeedback(params: SendFeedbackParams): Promise<void>;
|
|
499
|
+
/** Send a PROPOSE envelope via POST /hosted/negotiate/propose. */
|
|
500
|
+
sendPropose(params: SendProposeParams): Promise<{
|
|
501
|
+
conversationId: string;
|
|
502
|
+
}>;
|
|
503
|
+
/** Send a COUNTER envelope via POST /hosted/negotiate/counter. */
|
|
504
|
+
sendCounter(params: SendCounterParams): Promise<void>;
|
|
505
|
+
/** Send an ACCEPT envelope via POST /hosted/negotiate/accept. */
|
|
506
|
+
sendAccept(params: SendAcceptParams): Promise<void>;
|
|
267
507
|
/** Generate a random 16-byte conversation ID as hex. */
|
|
268
508
|
newConversationId(): string;
|
|
269
509
|
private _connect;
|