@swarm-tips/client 0.4.2 → 0.4.3
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/SBOM.spdx.json +5 -5
- package/dist/agent.d.ts +16 -0
- package/dist/agent.js +70 -53
- package/dist/cli/swarm.d.ts +5 -0
- package/dist/cli/swarm.js +37 -19
- package/dist/contracts/generated/coordination_game.d.ts +179 -1
- package/dist/contracts/generated/shillbot.d.ts +119 -12
- package/dist/contracts/idl/coordination_game.json +180 -2
- package/dist/contracts/idl/shillbot.json +119 -12
- package/dist/generated/openapi.d.ts +17 -2
- package/dist/generated/openapi.js +1 -1
- package/dist/inbox/client.d.ts +2 -4
- package/dist/inbox/client.js +11 -6
- package/dist/inbox/index.d.ts +1 -1
- package/dist/inbox/index.js +1 -1
- package/dist/inbox/types.d.ts +9 -0
- package/dist/inbox/types.js +10 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/shillbot/api.d.ts +7 -0
- package/dist/shillbot/api.js +41 -130
- package/dist/shillbot/index.d.ts +1 -0
- package/dist/shillbot/index.js +3 -0
- package/dist/shillbot/verify-tx.d.ts +62 -0
- package/dist/shillbot/verify-tx.js +643 -0
- package/dist/signer/evm.d.ts +1 -1
- package/dist/signer/evm.js +72 -2
- package/dist/signer/index.d.ts +1 -1
- package/dist/signer/types.d.ts +4 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vow/index.d.ts +1 -1
- package/dist/vow/index.js +1 -1
- package/dist/vow/verify.d.ts +36 -0
- package/dist/vow/verify.js +458 -1
- package/package.json +1 -1
package/dist/inbox/client.js
CHANGED
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
* bs58(ed25519 detached over the nonce UTF-8 bytes) — use `solanaNonceSigner`
|
|
25
25
|
* from this package; EVM = the `personal_sign` hex string as-is.
|
|
26
26
|
*/
|
|
27
|
+
import { VALID_TOPICS, isValidTopicId } from "./types.js";
|
|
28
|
+
export { VALID_TOPICS, isValidTopicId };
|
|
27
29
|
/** Non-2xx responses and client-side boundary rejections. `status` is the
|
|
28
30
|
* HTTP status, or 0 for errors raised before any request was made. */
|
|
29
31
|
export class InboxApiError extends Error {
|
|
@@ -233,8 +235,9 @@ export class InboxClient {
|
|
|
233
235
|
* needed. `minTrust` drops posts whose author trust is below it
|
|
234
236
|
* server-side. Hidden (auto-moderated) posts are always dropped. */
|
|
235
237
|
async readTopic(topicId, opts = {}) {
|
|
236
|
-
if (!topicId)
|
|
237
|
-
throw new InboxApiError(0,
|
|
238
|
+
if (!isValidTopicId(topicId)) {
|
|
239
|
+
throw new InboxApiError(0, `topicId must be one of ${VALID_TOPICS.join(", ")}`);
|
|
240
|
+
}
|
|
238
241
|
const params = new URLSearchParams({ topic_id: topicId });
|
|
239
242
|
if (opts.cursor)
|
|
240
243
|
params.set("cursor", opts.cursor);
|
|
@@ -261,8 +264,9 @@ export class InboxClient {
|
|
|
261
264
|
* inbox send). Rejects empty / oversize bodies client-side; quota
|
|
262
265
|
* rejections surface as InboxApiError with the server's message. */
|
|
263
266
|
async publishPost(topicId, body, opts = {}) {
|
|
264
|
-
if (!topicId)
|
|
265
|
-
throw new InboxApiError(0,
|
|
267
|
+
if (!isValidTopicId(topicId)) {
|
|
268
|
+
throw new InboxApiError(0, `topicId must be one of ${VALID_TOPICS.join(", ")}`);
|
|
269
|
+
}
|
|
266
270
|
const bytes = new TextEncoder().encode(body).length;
|
|
267
271
|
if (bytes === 0 || bytes > MAX_BODY_BYTES) {
|
|
268
272
|
throw new InboxApiError(0, `body must be 1..${MAX_BODY_BYTES} bytes (got ${bytes})`);
|
|
@@ -282,8 +286,9 @@ export class InboxClient {
|
|
|
282
286
|
/** Report a post for moderation. Session-gated. Idempotent per reporter —
|
|
283
287
|
* a repeat report returns `already_reported: true`. */
|
|
284
288
|
async reportPost(topicId, postId, reason) {
|
|
285
|
-
if (!topicId)
|
|
286
|
-
throw new InboxApiError(0,
|
|
289
|
+
if (!isValidTopicId(topicId)) {
|
|
290
|
+
throw new InboxApiError(0, `topicId must be one of ${VALID_TOPICS.join(", ")}`);
|
|
291
|
+
}
|
|
287
292
|
if (!postId)
|
|
288
293
|
throw new InboxApiError(0, "postId is required");
|
|
289
294
|
const payload = {
|
package/dist/inbox/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { InboxClient, InboxApiError, type InboxClientOpts, type InboxMessage, type MessageReference, type MessageEnvelope, type InboxListOptions, type InboxListPage, type OpenMessageResult, type OpenedMessage, type AckMessageResult, type InboxSession, type MessagePage, type NonceSigner, type SendReceipt, type MuteReceipt, type TopicId, type TopicPost, type TopicPage, type PublishReceipt, type ReportReceipt, } from "./client.js";
|
|
1
|
+
export { InboxClient, InboxApiError, type InboxClientOpts, type InboxMessage, type MessageReference, type MessageEnvelope, type InboxListOptions, type InboxListPage, type OpenMessageResult, type OpenedMessage, type AckMessageResult, type InboxSession, type MessagePage, type NonceSigner, type SendReceipt, type MuteReceipt, VALID_TOPICS, isValidTopicId, type TopicId, type TopicPost, type TopicPage, type PublishReceipt, type ReportReceipt, } from "./client.js";
|
|
2
2
|
export { solanaNonceSigner } from "./solana.js";
|
package/dist/inbox/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Shared browser client for the agent-inbox REST twins
|
|
2
2
|
// (mcp.swarm.tips /internal/inbox/*).
|
|
3
|
-
export { InboxClient, InboxApiError, } from "./client.js";
|
|
3
|
+
export { InboxClient, InboxApiError, VALID_TOPICS, isValidTopicId, } from "./client.js";
|
|
4
4
|
export { solanaNonceSigner } from "./solana.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical public topic boards supported by the Swarm MCP inbox/topics service:
|
|
3
|
+
* - `open-challenge`: Coordination Game matchmaking
|
|
4
|
+
* - `subcontract`: Shillbot task handoff
|
|
5
|
+
* - `town-square`: Open general coordination board
|
|
6
|
+
*/
|
|
7
|
+
export declare const VALID_TOPICS: readonly ["open-challenge", "subcontract", "town-square"];
|
|
8
|
+
export type TopicId = (typeof VALID_TOPICS)[number];
|
|
9
|
+
export declare function isValidTopicId(value: unknown): value is TopicId;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical public topic boards supported by the Swarm MCP inbox/topics service:
|
|
3
|
+
* - `open-challenge`: Coordination Game matchmaking
|
|
4
|
+
* - `subcontract`: Shillbot task handoff
|
|
5
|
+
* - `town-square`: Open general coordination board
|
|
6
|
+
*/
|
|
7
|
+
export const VALID_TOPICS = ["open-challenge", "subcontract", "town-square"];
|
|
8
|
+
export function isValidTopicId(value) {
|
|
9
|
+
return typeof value === "string" && VALID_TOPICS.includes(value);
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export { CLIENT_VERSION } from "./version.js";
|
|
|
3
3
|
export declare const CLIENT_MANIFEST_SCHEMA: "swarm.client-manifest/v1";
|
|
4
4
|
export { SwarmClientError } from "./errors.js";
|
|
5
5
|
export type { SwarmClientErrorCode, SwarmClientErrorOptions } from "./errors.js";
|
|
6
|
-
export { SwarmAgent, createSwarmAgent, type ExecuteTaskOptions, type ExecutedTaskResult, type NextTaskAction, type SwarmAgentOptions, type SwarmNetwork, type TaskLifecycleStep, } from "./agent.js";
|
|
6
|
+
export { DEFAULT_MAX_NETWORK_FEE_WEI, SwarmAgent, createSwarmAgent, extractCreateEscrowLamports, type ExecuteTaskOptions, type ExecutedTaskResult, type NextTaskAction, type SwarmAgentOptions, type SwarmNetwork, type TaskLifecycleStep, } from "./agent.js";
|
|
7
7
|
export { WalletTokenManager, type TokenProvider, type WalletTokenManagerOptions, } from "./auth/token-manager.js";
|
|
8
|
-
export { fromEvmPrivateKey, fromEvmWalletClient, fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, redactSigner, type EvmCallRequest, type EvmPrivateKeyOptions, type EvmSwarmSigner, type EvmWalletClientLike, type SolanaSwarmSigner, type SolanaWalletAdapterLike, type SwarmSigner, } from "./signer/index.js";
|
|
9
|
-
export { SHILLBOT_ESCROW_DEPLOYMENTS, SHILLBOT_EVM_SELECTORS, buildOnChainActionProofRef, estimateSolanaNetworkFeeLamports, formatOnChainActionAttributionMessage, validatePreparedEvmCall, validatePreparedTransaction, type BuildOnChainActionProofRefParams, type BuildVerifyOptions, type PreparedEvmCallExpectation, type PreparedTransactionExpectation, type PreparedTransactionResponse, type ValidatedEvmCall, type VerificationDataResponse, } from "./shillbot/api.js";
|
|
8
|
+
export { fromEvmPrivateKey, fromEvmWalletClient, fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, redactSigner, type EvmCallRequest, type EvmPrivateKeyOptions, type EvmSwarmSigner, type EvmTransactionSigner, type EvmWalletClientLike, type SolanaSwarmSigner, type SolanaWalletAdapterLike, type SwarmSigner, } from "./signer/index.js";
|
|
9
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_ESCROW_DEPLOYMENTS, SHILLBOT_EVM_SELECTORS, SHILLBOT_INSTRUCTION_SPECS, buildOnChainActionProofRef, estimateSolanaNetworkFeeLamports, formatOnChainActionAttributionMessage, normalizeEvmChainId, validateComputeBudgetInstruction, validateComputeBudgetInstructions, validatePreparedEvmCall, validatePreparedTransaction, verifyBuiltTransaction, type AuthoritySlotRule, type BuildOnChainActionProofRefParams, type BuildVerifyOptions, type PreparedEvmCallExpectation, type PreparedTransactionExpectation, type PreparedTransactionResponse, type ShillbotInstructionName, type ShillbotInstructionSpec, type ValidatedEvmCall, type VerificationDataResponse, type VerifyBuiltTransactionExpectation, } from "./shillbot/api.js";
|
|
10
|
+
export { VALID_TOPICS, isValidTopicId, type TopicId, } from "./inbox/types.js";
|
|
11
|
+
export { DEFAULT_MAX_VOW_BYTES, fetchVowAttestationJson, validateVowUrl, verifyVow, type FetchVowOptions, type VerifyVowOptions, } from "./vow/verify.js";
|
|
10
12
|
export { OPENAPI_SERVERS, OPENAPI_VERSION, type OpenApiOperationId, type OpenApiOperations, type OpenApiPaths, type OpenApiSchemas, type OpenApiServerUrl, } from "./generated/openapi.js";
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
export { CLIENT_VERSION } from "./version.js";
|
|
3
3
|
export const CLIENT_MANIFEST_SCHEMA = "swarm.client-manifest/v1";
|
|
4
4
|
export { SwarmClientError } from "./errors.js";
|
|
5
|
-
export { SwarmAgent, createSwarmAgent, } from "./agent.js";
|
|
5
|
+
export { DEFAULT_MAX_NETWORK_FEE_WEI, SwarmAgent, createSwarmAgent, extractCreateEscrowLamports, } from "./agent.js";
|
|
6
6
|
export { WalletTokenManager, } from "./auth/token-manager.js";
|
|
7
7
|
export { fromEvmPrivateKey, fromEvmWalletClient, fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, redactSigner, } from "./signer/index.js";
|
|
8
|
-
export { SHILLBOT_ESCROW_DEPLOYMENTS, SHILLBOT_EVM_SELECTORS, buildOnChainActionProofRef, estimateSolanaNetworkFeeLamports, formatOnChainActionAttributionMessage, validatePreparedEvmCall, validatePreparedTransaction, } from "./shillbot/api.js";
|
|
8
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_ESCROW_DEPLOYMENTS, SHILLBOT_EVM_SELECTORS, SHILLBOT_INSTRUCTION_SPECS, buildOnChainActionProofRef, estimateSolanaNetworkFeeLamports, formatOnChainActionAttributionMessage, normalizeEvmChainId, validateComputeBudgetInstruction, validateComputeBudgetInstructions, validatePreparedEvmCall, validatePreparedTransaction, verifyBuiltTransaction, } from "./shillbot/api.js";
|
|
9
|
+
export { VALID_TOPICS, isValidTopicId, } from "./inbox/types.js";
|
|
10
|
+
export { DEFAULT_MAX_VOW_BYTES, fetchVowAttestationJson, validateVowUrl, verifyVow, } from "./vow/verify.js";
|
|
9
11
|
export { OPENAPI_SERVERS, OPENAPI_VERSION, } from "./generated/openapi.js";
|
package/dist/shillbot/api.d.ts
CHANGED
|
@@ -70,13 +70,19 @@ export declare class ShillbotApiClient {
|
|
|
70
70
|
buildFinalize(id: string): Promise<PreparedTransactionResponse>;
|
|
71
71
|
confirmTask<TResponse = unknown>(id: string, body: ConfirmTransactionRequest): Promise<TResponse>;
|
|
72
72
|
}
|
|
73
|
+
import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation } from "./verify-tx.js";
|
|
74
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, };
|
|
73
75
|
export interface PreparedTransactionExpectation {
|
|
74
76
|
action: Action;
|
|
75
77
|
network: "mainnet" | "devnet";
|
|
76
78
|
wallet: string;
|
|
77
79
|
taskPda?: string;
|
|
78
80
|
feePayer?: string;
|
|
81
|
+
payoutTo?: string;
|
|
82
|
+
oracleAuthority?: string;
|
|
79
83
|
escrowLamports?: bigint;
|
|
84
|
+
contentId?: string;
|
|
85
|
+
maxComputeUnitPriceMicroLamports?: bigint;
|
|
80
86
|
allowedProgramIds?: string[];
|
|
81
87
|
}
|
|
82
88
|
/** Canonical deployed ShillbotEscrow EVM contracts keyed by CAIP-2 chain ID. */
|
|
@@ -94,6 +100,7 @@ export interface ValidatedEvmCall {
|
|
|
94
100
|
value: bigint;
|
|
95
101
|
chain: string;
|
|
96
102
|
}
|
|
103
|
+
export declare function normalizeEvmChainId(chain: string | number): string;
|
|
97
104
|
/**
|
|
98
105
|
* C10 fail-closed local validator for server-prepared EVM `ShillbotEscrow` calls.
|
|
99
106
|
* Verifies canonical contract address for `chain`, 4-byte function selector for
|
package/dist/shillbot/api.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Buffer } from "buffer";
|
|
|
2
2
|
import { ComputeBudgetProgram, Secp256k1Program, } from "@solana/web3.js";
|
|
3
3
|
import { HttpClient } from "../http.js";
|
|
4
4
|
import { SwarmClientError } from "../errors.js";
|
|
5
|
-
import {
|
|
5
|
+
import { signAndBroadcast, } from "./index.js";
|
|
6
6
|
function decodeJwtWallet(token) {
|
|
7
7
|
if (!token)
|
|
8
8
|
return undefined;
|
|
@@ -156,6 +156,8 @@ export class ShillbotApiClient {
|
|
|
156
156
|
return this.post(`/tasks/${encodeURIComponent(id)}/confirm`, body);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
|
|
160
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, };
|
|
159
161
|
const SWITCHBOARD_PROGRAM_IDS = {
|
|
160
162
|
mainnet: "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv",
|
|
161
163
|
devnet: "Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2",
|
|
@@ -173,15 +175,27 @@ export const SHILLBOT_EVM_SELECTORS = {
|
|
|
173
175
|
verify: "0x3bae608b", // verifyTaskAttested(uint64,uint64,bytes)
|
|
174
176
|
finalize: "0xcb26e65b", // finalizeTask(uint64)
|
|
175
177
|
};
|
|
176
|
-
function normalizeEvmChainId(chain) {
|
|
178
|
+
export function normalizeEvmChainId(chain) {
|
|
179
|
+
if (typeof chain === "number") {
|
|
180
|
+
if (!Number.isSafeInteger(chain) || chain <= 0) {
|
|
181
|
+
throw new SwarmClientError({
|
|
182
|
+
code: "INVALID_ARGUMENT",
|
|
183
|
+
operation: "shillbot.normalizeEvmChainId",
|
|
184
|
+
message: `Invalid EVM chain ID: ${String(chain)}`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return `eip155:${chain}`;
|
|
188
|
+
}
|
|
177
189
|
const trimmed = chain.trim().toLowerCase();
|
|
178
|
-
if (trimmed
|
|
190
|
+
if (/^\d+$/.test(trimmed))
|
|
191
|
+
return `eip155:${trimmed}`;
|
|
192
|
+
if (trimmed === "base-sepolia")
|
|
179
193
|
return "eip155:84532";
|
|
180
|
-
if (trimmed === "base"
|
|
194
|
+
if (trimmed === "base")
|
|
181
195
|
return "eip155:8453";
|
|
182
|
-
if (trimmed === "ethereum"
|
|
196
|
+
if (trimmed === "ethereum")
|
|
183
197
|
return "eip155:1";
|
|
184
|
-
if (trimmed === "ethereum-sepolia" || trimmed === "sepolia"
|
|
198
|
+
if (trimmed === "ethereum-sepolia" || trimmed === "sepolia") {
|
|
185
199
|
return "eip155:11155111";
|
|
186
200
|
}
|
|
187
201
|
return trimmed;
|
|
@@ -219,7 +233,7 @@ export function validatePreparedEvmCall(evmCall, expected) {
|
|
|
219
233
|
const callChain = typeof raw.chain === "string"
|
|
220
234
|
? normalizeEvmChainId(raw.chain)
|
|
221
235
|
: typeof raw.chain_id === "number"
|
|
222
|
-
?
|
|
236
|
+
? normalizeEvmChainId(raw.chain_id)
|
|
223
237
|
: undefined;
|
|
224
238
|
const expectedChain = expected.chain ? normalizeEvmChainId(expected.chain) : undefined;
|
|
225
239
|
if (callChain && expectedChain && callChain !== expectedChain) {
|
|
@@ -313,6 +327,7 @@ export function estimateSolanaNetworkFeeLamports(inspected, wallet) {
|
|
|
313
327
|
const computeBudgetId = ComputeBudgetProgram.programId.toBase58();
|
|
314
328
|
let computeUnitLimit;
|
|
315
329
|
let microLamportsPerCu = 0n;
|
|
330
|
+
let additionalFeeLamports = 0n;
|
|
316
331
|
let nonComputeBudgetIxCount = 0;
|
|
317
332
|
for (const ix of inspected.instructions) {
|
|
318
333
|
if (ix.program_id !== computeBudgetId) {
|
|
@@ -323,150 +338,46 @@ export function estimateSolanaNetworkFeeLamports(inspected, wallet) {
|
|
|
323
338
|
if (data.length === 0)
|
|
324
339
|
continue;
|
|
325
340
|
const tag = data[0];
|
|
341
|
+
if (tag === 0 && data.length >= 9) {
|
|
342
|
+
// Legacy RequestUnitsDeprecated: u32 units + u32 additionalFeeLamports (never early-return!)
|
|
343
|
+
computeUnitLimit = BigInt(data.readUInt32LE(1));
|
|
344
|
+
additionalFeeLamports += BigInt(data.readUInt32LE(5));
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (tag === 1) {
|
|
348
|
+
// RequestHeapFrame(u32 bytes): does not alter fee, continue checking subsequent instructions!
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
326
351
|
if (tag === 2 && data.length >= 5) {
|
|
327
352
|
computeUnitLimit = BigInt(data.readUInt32LE(1));
|
|
353
|
+
continue;
|
|
328
354
|
}
|
|
329
|
-
|
|
355
|
+
if (tag === 3 && data.length >= 9) {
|
|
330
356
|
const view = new DataView(data.buffer, data.byteOffset + 1, 8);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return BigInt(inspected.signers.length) * 5000n + additionalFee;
|
|
357
|
+
const price = view.getBigUint64(0, true);
|
|
358
|
+
if (price > microLamportsPerCu) {
|
|
359
|
+
microLamportsPerCu = price;
|
|
360
|
+
}
|
|
361
|
+
continue;
|
|
337
362
|
}
|
|
338
363
|
}
|
|
339
364
|
const effectiveUnits = computeUnitLimit ?? BigInt(Math.max(1, nonComputeBudgetIxCount)) * 200000n;
|
|
340
365
|
const priorityFeeLamports = (effectiveUnits * microLamportsPerCu + 999999n) / 1000000n;
|
|
341
366
|
const baseSignatureFeeLamports = BigInt(Math.max(1, inspected.signers.length)) * 5000n;
|
|
342
|
-
return baseSignatureFeeLamports + priorityFeeLamports;
|
|
367
|
+
return baseSignatureFeeLamports + priorityFeeLamports + additionalFeeLamports;
|
|
343
368
|
}
|
|
344
369
|
export function permittedPreparedProgramIds(action, network) {
|
|
345
370
|
return action === "verify"
|
|
346
371
|
? [SWITCHBOARD_PROGRAM_IDS[network], Secp256k1Program.programId.toBase58()]
|
|
347
372
|
: [];
|
|
348
373
|
}
|
|
349
|
-
function lifecycleName(action) {
|
|
350
|
-
if (action === "create")
|
|
351
|
-
return "create_task";
|
|
352
|
-
if (action === "submit")
|
|
353
|
-
return "submit_work";
|
|
354
|
-
return `${action}_task`;
|
|
355
|
-
}
|
|
356
|
-
function matchesDiscriminator(dataBase64, action) {
|
|
357
|
-
const data = Buffer.from(dataBase64, "base64");
|
|
358
|
-
return data.subarray(0, 8).equals(shillbotInstructionDiscriminator(lifecycleName(action)));
|
|
359
|
-
}
|
|
360
374
|
/**
|
|
361
375
|
* Fail-closed local validation for a server-prepared Shillbot transaction.
|
|
362
376
|
* The network is an explicit part of the expectation; callers must construct
|
|
363
377
|
* their Connection for that same network before signing.
|
|
364
378
|
*/
|
|
365
379
|
export function validatePreparedTransaction(encoded, expected) {
|
|
366
|
-
|
|
367
|
-
throw new SwarmClientError({
|
|
368
|
-
code: "INVALID_ARGUMENT",
|
|
369
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
370
|
-
message: "Unsupported network",
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
const inspected = inspectTransaction(encoded);
|
|
374
|
-
if (!inspected.signers.includes(expected.wallet)) {
|
|
375
|
-
throw new SwarmClientError({
|
|
376
|
-
code: "TRANSACTION_MISMATCH",
|
|
377
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
378
|
-
message: "Wallet is not a required signer",
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
if (expected.feePayer && inspected.fee_payer !== expected.feePayer) {
|
|
382
|
-
throw new SwarmClientError({
|
|
383
|
-
code: "TRANSACTION_MISMATCH",
|
|
384
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
385
|
-
message: "Fee payer differs from expectation",
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
const shillbotId = SHILLBOT_PROGRAM_ID.toBase58();
|
|
389
|
-
const shillbotIxs = inspected.instructions.filter((instruction) => instruction.program_id === shillbotId);
|
|
390
|
-
const lifecycle = shillbotIxs.filter((instruction) => matchesDiscriminator(instruction.data_base64, expected.action));
|
|
391
|
-
const companions = shillbotIxs.filter((instruction) => instruction !== lifecycle[0]);
|
|
392
|
-
const claimDisc = shillbotInstructionDiscriminator("claim_task");
|
|
393
|
-
const payoutDisc = shillbotInstructionDiscriminator("set_payout_to");
|
|
394
|
-
const hasDisc = (ix, disc) => Buffer.from(ix.data_base64, "base64").subarray(0, 8).equals(disc);
|
|
395
|
-
const ixPos = (ix) => inspected.instructions.indexOf(ix);
|
|
396
|
-
const validClaimCompanion = (ix) => hasDisc(ix, claimDisc) &&
|
|
397
|
-
ix.accounts.length >= 4 &&
|
|
398
|
-
(!expected.taskPda || ix.accounts[0] === expected.taskPda) &&
|
|
399
|
-
ix.accounts[0] === lifecycle[0]?.accounts[0] &&
|
|
400
|
-
ix.accounts[3] === expected.wallet;
|
|
401
|
-
const validPayoutCompanion = (ix) => hasDisc(ix, payoutDisc) &&
|
|
402
|
-
ix.accounts.length === 2 &&
|
|
403
|
-
(!expected.taskPda || ix.accounts[0] === expected.taskPda) &&
|
|
404
|
-
ix.accounts[0] === lifecycle[0]?.accounts[0] &&
|
|
405
|
-
ix.accounts[1] === expected.wallet;
|
|
406
|
-
const validCompanions = companions.length === 0 ||
|
|
407
|
-
(expected.action === "claim" &&
|
|
408
|
-
companions.length === 1 &&
|
|
409
|
-
validPayoutCompanion(companions[0]) &&
|
|
410
|
-
ixPos(companions[0]) > ixPos(lifecycle[0])) ||
|
|
411
|
-
(expected.action === "submit" &&
|
|
412
|
-
companions.length === 1 &&
|
|
413
|
-
validClaimCompanion(companions[0]) &&
|
|
414
|
-
ixPos(lifecycle[0]) === ixPos(companions[0]) + 1) ||
|
|
415
|
-
(expected.action === "submit" &&
|
|
416
|
-
companions.length === 2 &&
|
|
417
|
-
validClaimCompanion(companions[0]) &&
|
|
418
|
-
validPayoutCompanion(companions[1]) &&
|
|
419
|
-
ixPos(companions[1]) === ixPos(companions[0]) + 1 &&
|
|
420
|
-
ixPos(lifecycle[0]) === ixPos(companions[1]) + 1);
|
|
421
|
-
if (lifecycle.length !== 1 || !validCompanions) {
|
|
422
|
-
throw new SwarmClientError({
|
|
423
|
-
code: "TRANSACTION_MISMATCH",
|
|
424
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
425
|
-
message: "Expected exactly one matching Shillbot lifecycle instruction",
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
const taskAccountIndex = expected.action === "create" ? 1 : 0;
|
|
429
|
-
if (expected.taskPda && lifecycle[0].accounts[taskAccountIndex] !== expected.taskPda) {
|
|
430
|
-
throw new SwarmClientError({
|
|
431
|
-
code: "TRANSACTION_MISMATCH",
|
|
432
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
433
|
-
message: "Task PDA differs from expectation",
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
const alwaysAllowed = new Set([
|
|
437
|
-
shillbotId,
|
|
438
|
-
ComputeBudgetProgram.programId.toBase58(),
|
|
439
|
-
...permittedPreparedProgramIds(expected.action, expected.network),
|
|
440
|
-
...(expected.allowedProgramIds ?? []),
|
|
441
|
-
]);
|
|
442
|
-
const unrelated = inspected.instructions.find((instruction) => !alwaysAllowed.has(instruction.program_id));
|
|
443
|
-
if (unrelated) {
|
|
444
|
-
throw new SwarmClientError({
|
|
445
|
-
code: "TRANSACTION_MISMATCH",
|
|
446
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
447
|
-
message: `Unexpected program ${unrelated.program_id}`,
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
if (expected.action === "create" && expected.escrowLamports !== undefined) {
|
|
451
|
-
const data = Buffer.from(lifecycle[0].data_base64, "base64");
|
|
452
|
-
if (data.length < 24) {
|
|
453
|
-
throw new SwarmClientError({
|
|
454
|
-
code: "TRANSACTION_MISMATCH",
|
|
455
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
456
|
-
message: "Create instruction is truncated",
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
const view = new DataView(data.buffer, data.byteOffset + 16, 8);
|
|
460
|
-
const amount = view.getBigUint64(0, true);
|
|
461
|
-
if (amount !== expected.escrowLamports) {
|
|
462
|
-
throw new SwarmClientError({
|
|
463
|
-
code: "TRANSACTION_MISMATCH",
|
|
464
|
-
operation: "shillbot.validatePreparedTransaction",
|
|
465
|
-
message: `Escrow amount ${amount} differs from expected ${expected.escrowLamports}`,
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return inspected;
|
|
380
|
+
return verifyBuiltTransaction(encoded, expected, "shillbot.validatePreparedTransaction");
|
|
470
381
|
}
|
|
471
382
|
/**
|
|
472
383
|
* Format the canonical EIP-191 message signed by an agent's EVM referral wallet
|
package/dist/shillbot/index.d.ts
CHANGED
|
@@ -113,3 +113,4 @@ export declare const buildFinalize: (request: Omit<FinalizeBuild, "action">) =>
|
|
|
113
113
|
export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
|
|
114
114
|
export type { SwitchboardVerifyRequest } from "./switchboard.js";
|
|
115
115
|
export * from "./payout-oracle.js";
|
|
116
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, } from "./verify-tx.js";
|
package/dist/shillbot/index.js
CHANGED
|
@@ -281,6 +281,7 @@ export function verifyIntent(encoded, intent) {
|
|
|
281
281
|
throw new Error(`unexpected companion program ${ix.program_id}`);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
+
validateComputeBudgetInstructions(inspected.instructions);
|
|
284
285
|
const expectedDiscriminator = shillbotInstructionDiscriminator(intent.action === "submit" ? "submit_work" : `${intent.action}_task`);
|
|
285
286
|
const lifecycle = inspected.instructions.filter((ix) => ix.program_id === shillbotProgramId &&
|
|
286
287
|
Buffer.from(ix.data_base64, "base64")
|
|
@@ -372,3 +373,5 @@ export const buildVerify = (request) => buildTransaction({ ...request, action: "
|
|
|
372
373
|
export const buildFinalize = (request) => buildTransaction({ ...request, action: "finalize" });
|
|
373
374
|
export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
|
|
374
375
|
export * from "./payout-oracle.js";
|
|
376
|
+
import { validateComputeBudgetInstructions } from "./verify-tx.js";
|
|
377
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Action, type Network, type TransactionInspection } from "./index.js";
|
|
2
|
+
/** Default maximum allowed Solana priority fee price per compute unit (`100_000` micro-lamports/CU). */
|
|
3
|
+
export declare const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 100000n;
|
|
4
|
+
/** Solana runtime ceiling for `ComputeBudget::SetComputeUnitLimit` (`1_400_000` CUs). */
|
|
5
|
+
export declare const MAX_COMPUTE_UNIT_LIMIT = 1400000;
|
|
6
|
+
export type ShillbotInstructionName = "initialize" | "create_task" | "claim_task" | "claim_task_session" | "set_payout_to" | "submit_work" | "submit_work_session" | "approve_task" | "verify_task" | "verify_task_attested" | "challenge_task" | "finalize_task" | "expire_task" | "resolve_challenge" | "resolve_challenge_default" | "update_params" | "transfer_authority" | "update_treasury" | "update_oracle_authority" | "emergency_return" | "create_session" | "revoke_session" | "register_identity" | "revoke_identity" | "close_agent_state" | "migrate_agent_state" | "migrate_task";
|
|
7
|
+
export type AuthoritySlotRule = number | "fee_payer" | "verify_task" | "verify_task_attested";
|
|
8
|
+
export interface ShillbotInstructionSpec {
|
|
9
|
+
readonly name: ShillbotInstructionName;
|
|
10
|
+
readonly minAccounts: number;
|
|
11
|
+
readonly exactAccounts?: number;
|
|
12
|
+
readonly taskSlot: number | null;
|
|
13
|
+
readonly authoritySlot: AuthoritySlotRule;
|
|
14
|
+
/** True when third-party gas sponsorship (`fee_payer !== wallet`) is permitted by protocol design. */
|
|
15
|
+
readonly allowsSponsoredFeePayer: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Exact Anchor account-index and authority-slot specification for every Shillbot instruction,
|
|
19
|
+
* derived directly from `programs/shillbot/src/instructions/*.rs` and `shillbot.json` IDL.
|
|
20
|
+
*/
|
|
21
|
+
export declare const SHILLBOT_INSTRUCTION_SPECS: Readonly<Record<ShillbotInstructionName, ShillbotInstructionSpec>>;
|
|
22
|
+
export interface VerifyBuiltTransactionExpectation {
|
|
23
|
+
action?: Action;
|
|
24
|
+
instructionName?: ShillbotInstructionName;
|
|
25
|
+
network: Network;
|
|
26
|
+
wallet: string;
|
|
27
|
+
taskPda?: string;
|
|
28
|
+
feePayer?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Explicit authorized payout destination pubkey (base58).
|
|
31
|
+
* Required whenever a `set_payout_to` instruction is present; otherwise any
|
|
32
|
+
* `set_payout_to` instruction is rejected fail-closed.
|
|
33
|
+
*/
|
|
34
|
+
payoutTo?: string;
|
|
35
|
+
oracleAuthority?: string;
|
|
36
|
+
escrowLamports?: bigint;
|
|
37
|
+
contentId?: string;
|
|
38
|
+
maxComputeUnitPriceMicroLamports?: bigint;
|
|
39
|
+
allowedProgramIds?: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate a single `ComputeBudget111111111111111111111111111111` instruction's tag,
|
|
43
|
+
* byte length, and value bounds. Never early-returns from a multi-instruction loop.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateComputeBudgetInstruction(data: Uint8Array, maxComputeUnitPriceMicroLamports?: bigint, operation?: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Validate every `ComputeBudget` instruction in an inspected transaction without
|
|
48
|
+
* short-circuiting on `RequestHeapFrame` (tag 1) or any preceding instruction.
|
|
49
|
+
*/
|
|
50
|
+
export declare function validateComputeBudgetInstructions(instructions: TransactionInspection["instructions"], maxComputeUnitPriceMicroLamports?: bigint, operation?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Strict fail-closed local validator for built or server-prepared Shillbot Solana transactions.
|
|
53
|
+
*
|
|
54
|
+
* Enforces:
|
|
55
|
+
* - Allowed program IDs (Shillbot + ComputeBudget, plus Switchboard + Secp256k1 only on `verify`).
|
|
56
|
+
* - Full loop validation of all `ComputeBudget` instructions (no early return on `RequestHeapFrame`),
|
|
57
|
+
* capping `SetComputeUnitPrice <= MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS` (`100_000` micro-lamports/CU).
|
|
58
|
+
* - Exact Anchor account-index positions for `task` PDA and authority signer slots per discriminator.
|
|
59
|
+
* - Explicit `set_payout_to` opt-in guard: rejects any `set_payout_to` instruction unless
|
|
60
|
+
* `expected.payoutTo` is explicitly provided AND matches `ix.data[8..40]` and `accounts == [task, wallet]`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function verifyBuiltTransaction(encoded: string, expected: VerifyBuiltTransactionExpectation, operation?: string): TransactionInspection;
|