@swarm-tips/client 0.4.4 → 0.4.6
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 +26 -0
- package/dist/agent.js +91 -7
- package/dist/cli/swarm.js +29 -4
- package/dist/coordination-game/api.d.ts +49 -0
- package/dist/coordination-game/api.js +9 -0
- package/dist/coordination-game/evm/abi.d.ts +273 -5
- package/dist/coordination-game/evm/abi.js +347 -5
- package/dist/coordination-game/evm/cross-chain.d.ts +64 -1
- package/dist/coordination-game/evm/cross-chain.js +129 -6
- package/dist/coordination-game/evm/index.d.ts +2 -0
- package/dist/coordination-game/evm/index.js +1 -0
- package/dist/coordination-game/index.d.ts +1 -0
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/index.js +1 -1
- package/dist/evm/sign.d.ts +6 -0
- package/dist/evm/sign.js +17 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/shillbot/api.d.ts +11 -2
- package/dist/shillbot/api.js +22 -4
- package/dist/shillbot/index.d.ts +41 -3
- package/dist/shillbot/index.js +114 -7
- package/dist/shillbot/verify-tx.d.ts +9 -1
- package/dist/shillbot/verify-tx.js +128 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { type Hex } from "viem";
|
|
2
|
-
import type { CoordinationGameApiClient, XMatchPayload } from "../api.js";
|
|
2
|
+
import type { CoordinationGameApiClient, XMatchPayload, XOutcomeCertPayload } from "../api.js";
|
|
3
3
|
export declare function unpadAddress(word: string): Hex;
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a 65-byte `0x` secp256k1 `[r||s||v]` signature so `v` is in the
|
|
6
|
+
* EVM `ecrecover` / OpenZeppelin `ECDSA.recover` domain (`27 | 28`). The
|
|
7
|
+
* off-chain relay stores signatures with `v = 0 | 1`; passing `v < 27` directly
|
|
8
|
+
* to `CrossChainGame` reverts with `ECDSAInvalidSignature`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeEvmSigV(sig: string): Hex;
|
|
4
11
|
export interface CrossChainMatchResult {
|
|
5
12
|
match: XMatchPayload;
|
|
6
13
|
handle: string | undefined;
|
|
@@ -24,7 +31,63 @@ export interface EvmFundPin {
|
|
|
24
31
|
contract: Hex;
|
|
25
32
|
stakeWei: bigint;
|
|
26
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Reconstruct the `CertLib.MatchLiveCert` tuple expected by `CrossChainGame`
|
|
36
|
+
* (`lockTranche`, `settle`, `openClaim`, `supersedeClaim`,
|
|
37
|
+
* `submitEquivocationProof`) from a matched `XMatchPayload`. `chainTag` is
|
|
38
|
+
* recomputed as `keccak256(utf8(leg.chain))`, matching `game-api`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function certTupleFromMatchPayload(match: XMatchPayload): {
|
|
41
|
+
readonly matchId: Hex;
|
|
42
|
+
readonly tournamentId: bigint;
|
|
43
|
+
readonly matchupCommitment: Hex;
|
|
44
|
+
readonly legA: {
|
|
45
|
+
readonly chainTag: `0x${string}`;
|
|
46
|
+
readonly contractId: Hex;
|
|
47
|
+
readonly player: Hex;
|
|
48
|
+
readonly sessionKey: `0x${string}`;
|
|
49
|
+
readonly stake: bigint;
|
|
50
|
+
readonly tranche: bigint;
|
|
51
|
+
};
|
|
52
|
+
readonly legB: {
|
|
53
|
+
readonly chainTag: `0x${string}`;
|
|
54
|
+
readonly contractId: Hex;
|
|
55
|
+
readonly player: Hex;
|
|
56
|
+
readonly sessionKey: `0x${string}`;
|
|
57
|
+
readonly stake: bigint;
|
|
58
|
+
readonly tranche: bigint;
|
|
59
|
+
};
|
|
60
|
+
readonly quoteTimestamp: bigint;
|
|
61
|
+
readonly quoteMaxAgeSecs: number;
|
|
62
|
+
readonly matchDeadline: bigint;
|
|
63
|
+
readonly claimWindowSecs: number;
|
|
64
|
+
readonly aIsP1: number;
|
|
65
|
+
};
|
|
27
66
|
export declare function buildEvmFundCall(match: XMatchPayload, pin: EvmFundPin): EvmFundCall;
|
|
67
|
+
/**
|
|
68
|
+
* Build the unsigned permissionless `CrossChainGame.lockTranche(cert, operatorSig)`
|
|
69
|
+
* call (`value === 0n`) from the matched `XMatchPayload`, verifying `leg_b`
|
|
70
|
+
* against `pin` and normalizing `operator_signature` `v` to `27 | 28`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildEvmLockTrancheCall(match: XMatchPayload, pin: EvmFundPin): EvmFundCall;
|
|
73
|
+
export interface XSettleBundle {
|
|
74
|
+
outcome: Pick<XOutcomeCertPayload, "match_id" | "match_live_digest" | "outcome_kind" | "step_count" | "p1_guess" | "p2_guess" | "first_committer" | "matchup_type" | "transcript_hash">;
|
|
75
|
+
live_sigs: readonly [string, string, string];
|
|
76
|
+
oc_sigs: readonly [string, string, string];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build the unsigned permissionless `CrossChainGame.settle(cert, oc, liveSigs, ocSigs)`
|
|
80
|
+
* call (`value === 0n`), verifying `leg_b` against `pin`, checking `match_id`
|
|
81
|
+
* and `match_live_digest` consistency, and normalizing all 6 signatures to
|
|
82
|
+
* EVM `v = 27 | 28`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildEvmSettleCall(match: XMatchPayload, bundle: XSettleBundle, pin: EvmFundPin): EvmFundCall;
|
|
85
|
+
/**
|
|
86
|
+
* Read `CrossChainGame.matches(matchId).status` (`0 = None, 1 = Funded,
|
|
87
|
+
* 2 = Locked, 3 = Claiming, 4 = Settled, 5 = ClaimSettled, 6 = RefundedNoCert,
|
|
88
|
+
* 7 = RefundedTimeout`).
|
|
89
|
+
*/
|
|
90
|
+
export declare function readEvmXMatchStatus(rpcUrl: string, contract: Hex, matchId: Hex): Promise<number>;
|
|
28
91
|
export interface FundTargetReader {
|
|
29
92
|
stakeWei(contract: Hex): Promise<bigint>;
|
|
30
93
|
matchStatus(contract: Hex, matchId: Hex): Promise<number>;
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import { createPublicClient, encodeFunctionData, http } from "viem";
|
|
1
|
+
import { createPublicClient, encodeFunctionData, http, keccak256, toBytes, } from "viem";
|
|
2
2
|
import { CROSS_CHAIN_GAME_ABI } from "./abi.js";
|
|
3
3
|
export function unpadAddress(word) {
|
|
4
4
|
const hex = word.startsWith("0x") ? word.slice(2) : word;
|
|
5
5
|
return `0x${hex.slice(-40)}`;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a 65-byte `0x` secp256k1 `[r||s||v]` signature so `v` is in the
|
|
9
|
+
* EVM `ecrecover` / OpenZeppelin `ECDSA.recover` domain (`27 | 28`). The
|
|
10
|
+
* off-chain relay stores signatures with `v = 0 | 1`; passing `v < 27` directly
|
|
11
|
+
* to `CrossChainGame` reverts with `ECDSAInvalidSignature`.
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeEvmSigV(sig) {
|
|
14
|
+
if (!/^0x[0-9a-fA-F]{130}$/.test(sig)) {
|
|
15
|
+
throw new Error(`expected 65-byte 0x signature (130 hex chars), got length ${sig.length}`);
|
|
16
|
+
}
|
|
17
|
+
const body = sig.slice(2).toLowerCase();
|
|
18
|
+
const rs = body.slice(0, 128);
|
|
19
|
+
let v = parseInt(body.slice(128, 130), 16);
|
|
20
|
+
if (v < 27)
|
|
21
|
+
v += 27;
|
|
22
|
+
return `0x${rs}${v.toString(16).padStart(2, "0")}`;
|
|
23
|
+
}
|
|
7
24
|
export async function findCrossChainMatch(api, input, options = {}) {
|
|
8
25
|
const joined = await api.joinCrossChainQueue({
|
|
9
26
|
wallet: input.wallet,
|
|
@@ -23,15 +40,49 @@ export async function findCrossChainMatch(api, input, options = {}) {
|
|
|
23
40
|
}
|
|
24
41
|
throw new Error("no opponent found before timeout");
|
|
25
42
|
}
|
|
26
|
-
|
|
43
|
+
function verifyPin(match, pin) {
|
|
27
44
|
const to = unpadAddress(match.leg_b.contract);
|
|
28
45
|
if (to.toLowerCase() !== pin.contract.toLowerCase()) {
|
|
29
46
|
throw new Error(`relay leg_b.contract ${to} != pinned CrossChainGame ${pin.contract}`);
|
|
30
47
|
}
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
throw new Error(`relay leg_b.stake ${
|
|
48
|
+
const stakeWei = BigInt(match.leg_b.stake_base_units);
|
|
49
|
+
if (stakeWei !== pin.stakeWei) {
|
|
50
|
+
throw new Error(`relay leg_b.stake ${stakeWei} != pinned stake ${pin.stakeWei}`);
|
|
34
51
|
}
|
|
52
|
+
return { to, stakeWei };
|
|
53
|
+
}
|
|
54
|
+
function legTupleFromPayload(leg) {
|
|
55
|
+
return {
|
|
56
|
+
chainTag: keccak256(toBytes(leg.chain)),
|
|
57
|
+
contractId: leg.contract,
|
|
58
|
+
player: leg.player,
|
|
59
|
+
sessionKey: unpadAddress(leg.session_key),
|
|
60
|
+
stake: BigInt(leg.stake_base_units),
|
|
61
|
+
tranche: BigInt(leg.tranche_base_units),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reconstruct the `CertLib.MatchLiveCert` tuple expected by `CrossChainGame`
|
|
66
|
+
* (`lockTranche`, `settle`, `openClaim`, `supersedeClaim`,
|
|
67
|
+
* `submitEquivocationProof`) from a matched `XMatchPayload`. `chainTag` is
|
|
68
|
+
* recomputed as `keccak256(utf8(leg.chain))`, matching `game-api`.
|
|
69
|
+
*/
|
|
70
|
+
export function certTupleFromMatchPayload(match) {
|
|
71
|
+
return {
|
|
72
|
+
matchId: match.match_id,
|
|
73
|
+
tournamentId: BigInt(match.tournament_id),
|
|
74
|
+
matchupCommitment: match.matchup_commitment,
|
|
75
|
+
legA: legTupleFromPayload(match.leg_a),
|
|
76
|
+
legB: legTupleFromPayload(match.leg_b),
|
|
77
|
+
quoteTimestamp: BigInt(match.quote_timestamp),
|
|
78
|
+
quoteMaxAgeSecs: Number(match.quote_max_age_secs),
|
|
79
|
+
matchDeadline: BigInt(match.match_deadline),
|
|
80
|
+
claimWindowSecs: Number(match.claim_window_secs),
|
|
81
|
+
aIsP1: Number(match.a_is_p1),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function buildEvmFundCall(match, pin) {
|
|
85
|
+
const { to, stakeWei } = verifyPin(match, pin);
|
|
35
86
|
const data = encodeFunctionData({
|
|
36
87
|
abi: CROSS_CHAIN_GAME_ABI,
|
|
37
88
|
functionName: "createMatch",
|
|
@@ -45,7 +96,79 @@ export function buildEvmFundCall(match, pin) {
|
|
|
45
96
|
match.create_match_operator_sig,
|
|
46
97
|
],
|
|
47
98
|
});
|
|
48
|
-
return { to, data, value };
|
|
99
|
+
return { to, data, value: stakeWei };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build the unsigned permissionless `CrossChainGame.lockTranche(cert, operatorSig)`
|
|
103
|
+
* call (`value === 0n`) from the matched `XMatchPayload`, verifying `leg_b`
|
|
104
|
+
* against `pin` and normalizing `operator_signature` `v` to `27 | 28`.
|
|
105
|
+
*/
|
|
106
|
+
export function buildEvmLockTrancheCall(match, pin) {
|
|
107
|
+
const { to } = verifyPin(match, pin);
|
|
108
|
+
const data = encodeFunctionData({
|
|
109
|
+
abi: CROSS_CHAIN_GAME_ABI,
|
|
110
|
+
functionName: "lockTranche",
|
|
111
|
+
args: [certTupleFromMatchPayload(match), normalizeEvmSigV(match.operator_signature)],
|
|
112
|
+
});
|
|
113
|
+
return { to, data, value: 0n };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Build the unsigned permissionless `CrossChainGame.settle(cert, oc, liveSigs, ocSigs)`
|
|
117
|
+
* call (`value === 0n`), verifying `leg_b` against `pin`, checking `match_id`
|
|
118
|
+
* and `match_live_digest` consistency, and normalizing all 6 signatures to
|
|
119
|
+
* EVM `v = 27 | 28`.
|
|
120
|
+
*/
|
|
121
|
+
export function buildEvmSettleCall(match, bundle, pin) {
|
|
122
|
+
const { to } = verifyPin(match, pin);
|
|
123
|
+
if (bundle.outcome.match_id.toLowerCase() !== match.match_id.toLowerCase()) {
|
|
124
|
+
throw new Error(`outcome.match_id ${bundle.outcome.match_id} != match.match_id ${match.match_id}`);
|
|
125
|
+
}
|
|
126
|
+
if (match.match_live_digest &&
|
|
127
|
+
bundle.outcome.match_live_digest.toLowerCase() !== match.match_live_digest.toLowerCase()) {
|
|
128
|
+
throw new Error(`outcome.match_live_digest ${bundle.outcome.match_live_digest} != match.match_live_digest ${match.match_live_digest}`);
|
|
129
|
+
}
|
|
130
|
+
const oc = {
|
|
131
|
+
matchId: bundle.outcome.match_id,
|
|
132
|
+
matchLiveDigest: bundle.outcome.match_live_digest,
|
|
133
|
+
outcomeKind: Number(bundle.outcome.outcome_kind),
|
|
134
|
+
stepCount: Number(bundle.outcome.step_count),
|
|
135
|
+
p1Guess: Number(bundle.outcome.p1_guess),
|
|
136
|
+
p2Guess: Number(bundle.outcome.p2_guess),
|
|
137
|
+
firstCommitter: Number(bundle.outcome.first_committer),
|
|
138
|
+
matchupType: Number(bundle.outcome.matchup_type),
|
|
139
|
+
transcriptHash: bundle.outcome.transcript_hash,
|
|
140
|
+
};
|
|
141
|
+
const liveSigs = [
|
|
142
|
+
normalizeEvmSigV(bundle.live_sigs[0]),
|
|
143
|
+
normalizeEvmSigV(bundle.live_sigs[1]),
|
|
144
|
+
normalizeEvmSigV(bundle.live_sigs[2]),
|
|
145
|
+
];
|
|
146
|
+
const ocSigs = [
|
|
147
|
+
normalizeEvmSigV(bundle.oc_sigs[0]),
|
|
148
|
+
normalizeEvmSigV(bundle.oc_sigs[1]),
|
|
149
|
+
normalizeEvmSigV(bundle.oc_sigs[2]),
|
|
150
|
+
];
|
|
151
|
+
const data = encodeFunctionData({
|
|
152
|
+
abi: CROSS_CHAIN_GAME_ABI,
|
|
153
|
+
functionName: "settle",
|
|
154
|
+
args: [certTupleFromMatchPayload(match), oc, liveSigs, ocSigs],
|
|
155
|
+
});
|
|
156
|
+
return { to, data, value: 0n };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Read `CrossChainGame.matches(matchId).status` (`0 = None, 1 = Funded,
|
|
160
|
+
* 2 = Locked, 3 = Claiming, 4 = Settled, 5 = ClaimSettled, 6 = RefundedNoCert,
|
|
161
|
+
* 7 = RefundedTimeout`).
|
|
162
|
+
*/
|
|
163
|
+
export async function readEvmXMatchStatus(rpcUrl, contract, matchId) {
|
|
164
|
+
const client = createPublicClient({ transport: http(rpcUrl) });
|
|
165
|
+
const result = (await client.readContract({
|
|
166
|
+
address: contract,
|
|
167
|
+
abi: CROSS_CHAIN_GAME_ABI,
|
|
168
|
+
functionName: "matches",
|
|
169
|
+
args: [matchId],
|
|
170
|
+
}));
|
|
171
|
+
return Number(result[0]);
|
|
49
172
|
}
|
|
50
173
|
export async function verifyEvmFundTarget(match, pin, readers) {
|
|
51
174
|
if (readers.length < 2)
|
|
@@ -5,3 +5,5 @@ export * from "./session-funding.js";
|
|
|
5
5
|
export * from "./transactions.js";
|
|
6
6
|
export * from "./cross-chain.js";
|
|
7
7
|
export * from "../chains.js";
|
|
8
|
+
export { signDigest, signDigestForRelay } from "../../evm/sign.js";
|
|
9
|
+
export type { XLegPayload, XMatchPayload, XOutcomeCertPayload, XSettleSigsResponse, XSolSettleTxResponse, } from "../api.js";
|
package/dist/evm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { signDigestForRelay } from "./sign.js";
|
|
1
|
+
export { signDigest, signDigestForRelay } from "./sign.js";
|
|
2
2
|
export { sendUnsignedCall, sendContractCall, type UnsignedEvmCall, type CallSender, } from "./tx.js";
|
|
3
3
|
export { buildWagmiConfig, getEvmTestWalletKey, getEvmRpcOverride, type ChainWithRpcs, type WagmiConfigOpts, } from "./wallet.js";
|
package/dist/evm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Product-agnostic EVM frontend primitives shared across
|
|
2
2
|
// Swarm Tips frontends (coordination-game today; a future shillbot EVM flow
|
|
3
3
|
// just adds this package as a dependency + brings its own ABI/flow).
|
|
4
|
-
export { signDigestForRelay } from "./sign.js";
|
|
4
|
+
export { signDigest, signDigestForRelay } from "./sign.js";
|
|
5
5
|
export { sendUnsignedCall, sendContractCall, } from "./tx.js";
|
|
6
6
|
export { buildWagmiConfig, getEvmTestWalletKey, getEvmRpcOverride, } from "./wallet.js";
|
package/dist/evm/sign.d.ts
CHANGED
|
@@ -10,3 +10,9 @@ import type { Hex } from "viem";
|
|
|
10
10
|
* (the inverse axis; see chain-core `sign_digest_eth` / `evm_operator_sig_v_convention`).
|
|
11
11
|
*/
|
|
12
12
|
export declare function signDigestForRelay(privateKey: Hex, digestHex: Hex): Promise<Hex>;
|
|
13
|
+
/**
|
|
14
|
+
* Sign a `0x` 32-byte digest with an EVM private key, returning a `0x` 65-byte
|
|
15
|
+
* `[r||s||v]` secp256k1 signature with `v = 27 | 28` (the EVM `ecrecover` /
|
|
16
|
+
* OpenZeppelin `ECDSA.recover` convention verified by on-chain EVM contracts).
|
|
17
|
+
*/
|
|
18
|
+
export declare function signDigest(privateKey: Hex, digestHex: Hex): Promise<Hex>;
|
package/dist/evm/sign.js
CHANGED
|
@@ -21,3 +21,20 @@ export async function signDigestForRelay(privateKey, digestHex) {
|
|
|
21
21
|
v -= 27; // 27|28 -> 0|1 for the relay's k256 recover_address
|
|
22
22
|
return `0x${rs}${v.toString(16).padStart(2, "0")}`;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Sign a `0x` 32-byte digest with an EVM private key, returning a `0x` 65-byte
|
|
26
|
+
* `[r||s||v]` secp256k1 signature with `v = 27 | 28` (the EVM `ecrecover` /
|
|
27
|
+
* OpenZeppelin `ECDSA.recover` convention verified by on-chain EVM contracts).
|
|
28
|
+
*/
|
|
29
|
+
export async function signDigest(privateKey, digestHex) {
|
|
30
|
+
const serialized = await sign({ hash: digestHex, privateKey, to: "hex" });
|
|
31
|
+
const body = serialized.slice(2); // 130 hex chars: r(64) || s(64) || v(2)
|
|
32
|
+
if (body.length !== 130) {
|
|
33
|
+
throw new Error(`unexpected signature length: ${serialized}`);
|
|
34
|
+
}
|
|
35
|
+
const rs = body.slice(0, 128);
|
|
36
|
+
let v = parseInt(body.slice(128, 130), 16);
|
|
37
|
+
if (v < 27)
|
|
38
|
+
v += 27;
|
|
39
|
+
return `0x${rs}${v.toString(16).padStart(2, "0")}`;
|
|
40
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export type { SwarmClientErrorCode, SwarmClientErrorOptions } from "./errors.js"
|
|
|
6
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
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";
|
|
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 ExpireTaskState, type PreparedEvmCallExpectation, type PreparedTransactionExpectation, type PreparedTransactionResponse, type ShillbotInstructionName, type ShillbotInstructionSpec, type ValidatedEvmCall, type VerificationDataResponse, type VerifyBuiltTransactionExpectation, } from "./shillbot/api.js";
|
|
10
|
+
export { ADVANCE_ACCOUNT_SPACE, EXTENSION_CREDIT_PROGRAM_ID, advanceAccountDiscriminator, advancePda, decodeExtensionCreditAdvance, type DecodedAdvanceAccount, } from "./shillbot/index.js";
|
|
10
11
|
export { VALID_TOPICS, isValidTopicId, type TopicId, } from "./inbox/types.js";
|
|
11
12
|
export { DEFAULT_MAX_VOW_BYTES, fetchVowAttestationJson, validateVowUrl, verifyVow, type FetchVowOptions, type VerifyVowOptions, } from "./vow/verify.js";
|
|
12
13
|
export { OPENAPI_SERVERS, OPENAPI_VERSION, type OpenApiOperationId, type OpenApiOperations, type OpenApiPaths, type OpenApiSchemas, type OpenApiServerUrl, } from "./generated/openapi.js";
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { DEFAULT_MAX_NETWORK_FEE_WEI, SwarmAgent, createSwarmAgent, extractCreat
|
|
|
6
6
|
export { WalletTokenManager, } from "./auth/token-manager.js";
|
|
7
7
|
export { fromEvmPrivateKey, fromEvmWalletClient, fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, redactSigner, } from "./signer/index.js";
|
|
8
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 { ADVANCE_ACCOUNT_SPACE, EXTENSION_CREDIT_PROGRAM_ID, advanceAccountDiscriminator, advancePda, decodeExtensionCreditAdvance, } from "./shillbot/index.js";
|
|
9
10
|
export { VALID_TOPICS, isValidTopicId, } from "./inbox/types.js";
|
|
10
11
|
export { DEFAULT_MAX_VOW_BYTES, fetchVowAttestationJson, validateVowUrl, verifyVow, } from "./vow/verify.js";
|
|
11
12
|
export { OPENAPI_SERVERS, OPENAPI_VERSION, } from "./generated/openapi.js";
|
package/dist/shillbot/api.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface PreparedTransactionResponse {
|
|
|
9
9
|
task_pda?: string;
|
|
10
10
|
transaction_intent?: TransactionIntent;
|
|
11
11
|
evm_call?: unknown;
|
|
12
|
+
payout_to?: string;
|
|
13
|
+
advance_backer?: string;
|
|
12
14
|
}
|
|
13
15
|
export interface VerificationDataResponse {
|
|
14
16
|
task_id?: string;
|
|
@@ -17,6 +19,11 @@ export interface VerificationDataResponse {
|
|
|
17
19
|
verification_hash: string;
|
|
18
20
|
global_state?: string;
|
|
19
21
|
switchboard_feed: string;
|
|
22
|
+
required_payout_to?: string;
|
|
23
|
+
advance_backer?: string;
|
|
24
|
+
verification_kind?: number;
|
|
25
|
+
co_signed_transaction?: string;
|
|
26
|
+
evm_verify_call?: unknown;
|
|
20
27
|
}
|
|
21
28
|
export interface BuildVerifyOptions {
|
|
22
29
|
payer?: string;
|
|
@@ -68,10 +75,11 @@ export declare class ShillbotApiClient {
|
|
|
68
75
|
getVerificationData(id: string, network?: "mainnet" | "devnet"): Promise<VerificationDataResponse>;
|
|
69
76
|
buildVerify(id: string, opts?: BuildVerifyOptions): Promise<PreparedTransactionResponse>;
|
|
70
77
|
buildFinalize(id: string): Promise<PreparedTransactionResponse>;
|
|
78
|
+
buildExpire(id: string): Promise<PreparedTransactionResponse>;
|
|
71
79
|
confirmTask<TResponse = unknown>(id: string, body: ConfirmTransactionRequest): Promise<TResponse>;
|
|
72
80
|
}
|
|
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, };
|
|
81
|
+
import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ExpireTaskState, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation } from "./verify-tx.js";
|
|
82
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ExpireTaskState, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, };
|
|
75
83
|
export interface PreparedTransactionExpectation {
|
|
76
84
|
action: Action;
|
|
77
85
|
network: "mainnet" | "devnet";
|
|
@@ -79,6 +87,7 @@ export interface PreparedTransactionExpectation {
|
|
|
79
87
|
taskPda?: string;
|
|
80
88
|
feePayer?: string;
|
|
81
89
|
payoutTo?: string;
|
|
90
|
+
expireTaskState?: ExpireTaskState;
|
|
82
91
|
oracleAuthority?: string;
|
|
83
92
|
escrowLamports?: bigint;
|
|
84
93
|
contentId?: string;
|
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 { signAndBroadcast, } from "./index.js";
|
|
5
|
+
import { EXTENSION_CREDIT_PROGRAM_ID, signAndBroadcast, } from "./index.js";
|
|
6
6
|
function decodeJwtWallet(token) {
|
|
7
7
|
if (!token)
|
|
8
8
|
return undefined;
|
|
@@ -139,6 +139,16 @@ export class ShillbotApiClient {
|
|
|
139
139
|
throw err;
|
|
140
140
|
}
|
|
141
141
|
const vdata = await this.getVerificationData(id, resolvedNetwork);
|
|
142
|
+
if (vdata.evm_verify_call || vdata.co_signed_transaction) {
|
|
143
|
+
return {
|
|
144
|
+
task_id: vdata.task_id ?? id,
|
|
145
|
+
transaction: vdata.co_signed_transaction ?? "",
|
|
146
|
+
task_pda: vdata.task_pda,
|
|
147
|
+
...(vdata.evm_verify_call !== undefined ? { evm_call: vdata.evm_verify_call } : {}),
|
|
148
|
+
...(vdata.required_payout_to ? { payout_to: vdata.required_payout_to } : {}),
|
|
149
|
+
...(vdata.advance_backer ? { advance_backer: vdata.advance_backer } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
142
152
|
const fallback = await postMcpBuildVerify({
|
|
143
153
|
task_id: id,
|
|
144
154
|
...(payer ? { payer } : {}),
|
|
@@ -161,6 +171,9 @@ export class ShillbotApiClient {
|
|
|
161
171
|
buildFinalize(id) {
|
|
162
172
|
return this.post(`/tasks/${encodeURIComponent(id)}/build-finalize`);
|
|
163
173
|
}
|
|
174
|
+
buildExpire(id) {
|
|
175
|
+
return this.post(`/tasks/${encodeURIComponent(id)}/build-expire`);
|
|
176
|
+
}
|
|
164
177
|
confirmTask(id, body) {
|
|
165
178
|
return this.post(`/tasks/${encodeURIComponent(id)}/confirm`, body);
|
|
166
179
|
}
|
|
@@ -183,6 +196,7 @@ export const SHILLBOT_EVM_SELECTORS = {
|
|
|
183
196
|
approve: "0x97312249", // approveTask(uint64)
|
|
184
197
|
verify: "0x3bae608b", // verifyTaskAttested(uint64,uint64,bytes)
|
|
185
198
|
finalize: "0xcb26e65b", // finalizeTask(uint64)
|
|
199
|
+
expire: "0x5e9f3d19", // expireTask(uint64)
|
|
186
200
|
};
|
|
187
201
|
export function normalizeEvmChainId(chain) {
|
|
188
202
|
if (typeof chain === "number") {
|
|
@@ -376,9 +390,13 @@ export function estimateSolanaNetworkFeeLamports(inspected, wallet) {
|
|
|
376
390
|
return baseSignatureFeeLamports + priorityFeeLamports + additionalFeeLamports;
|
|
377
391
|
}
|
|
378
392
|
export function permittedPreparedProgramIds(action, network) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
393
|
+
if (action === "verify") {
|
|
394
|
+
return [SWITCHBOARD_PROGRAM_IDS[network], Secp256k1Program.programId.toBase58()];
|
|
395
|
+
}
|
|
396
|
+
if (action === "finalize") {
|
|
397
|
+
return [EXTENSION_CREDIT_PROGRAM_ID.toBase58()];
|
|
398
|
+
}
|
|
399
|
+
return [];
|
|
382
400
|
}
|
|
383
401
|
/**
|
|
384
402
|
* Fail-closed local validation for a server-prepared Shillbot transaction.
|
package/dist/shillbot/index.d.ts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Buffer } from "buffer";
|
|
2
|
+
import { Connection, PublicKey, Transaction, TransactionInstruction, VersionedTransaction, type BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
|
|
2
3
|
export { COORDINATION_GAME_IDL, COORDINATION_GAME_PROGRAM_ID, SHILLBOT_IDL, SHILLBOT_PROGRAM_ID, agentStatePda, buildShillbotInstruction, clientStatePda, globalStatePda, shillbotInstructionDiscriminator, taskPda, } from "../contracts/index.js";
|
|
3
4
|
export type { BuildShillbotInstructionRequest, CoordinationGame, Shillbot, } from "../contracts/index.js";
|
|
4
5
|
export declare const SCHEMA_VERSION: "swarm.shillbot.transaction-intent/v1";
|
|
5
|
-
export
|
|
6
|
+
export declare const EXTENSION_CREDIT_PROGRAM_ID: PublicKey;
|
|
7
|
+
export declare function advancePda(backer: PublicKey | string, agent: PublicKey | string): PublicKey;
|
|
8
|
+
export declare function routeAndRecoupDiscriminator(): Buffer;
|
|
9
|
+
/** Exact Anchor account byte length of `extension-credit` `Advance` (`8 + 32 + 32 + 8 + 8 + 8 + 1 + 16 = 113`). */
|
|
10
|
+
export declare const ADVANCE_ACCOUNT_SPACE = 113;
|
|
11
|
+
export declare function advanceAccountDiscriminator(): Buffer;
|
|
12
|
+
export interface DecodedAdvanceAccount {
|
|
13
|
+
backer: PublicKey;
|
|
14
|
+
recipient: PublicKey;
|
|
15
|
+
advanceLamports: bigint;
|
|
16
|
+
recoupedLamports: bigint;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Decode an on-chain `extension-credit` `Advance` account (`programs/extension-credit/src/state/advance.rs`).
|
|
20
|
+
* Returns `null` if the length (`113` bytes) or 8-byte Anchor discriminator (`account:Advance`) does not match.
|
|
21
|
+
*/
|
|
22
|
+
export declare function decodeExtensionCreditAdvance(data: Uint8Array): DecodedAdvanceAccount | null;
|
|
23
|
+
export declare function buildRouteAndRecoupInstruction(accounts: {
|
|
24
|
+
advance: PublicKey | string;
|
|
25
|
+
backer: PublicKey | string;
|
|
26
|
+
recipient: PublicKey | string;
|
|
27
|
+
}): TransactionInstruction;
|
|
28
|
+
export type Action = "create" | "claim" | "submit" | "approve" | "verify" | "finalize" | "expire";
|
|
6
29
|
export type Risk = "earn" | "spend" | "escrow_control";
|
|
7
30
|
export type Network = "mainnet" | "devnet";
|
|
8
31
|
export type TransactionVersion = "legacy" | "v0";
|
|
@@ -85,8 +108,22 @@ export interface FinalizeBuild extends CommonBuild {
|
|
|
85
108
|
agent: string;
|
|
86
109
|
client: string;
|
|
87
110
|
treasury: string;
|
|
111
|
+
/** Optional true agent pubkey whose `AgentState` PDA is appended as remaining account `[5]`. */
|
|
112
|
+
agentStateOwner?: string;
|
|
113
|
+
/** Optional `extension-credit` backer pubkey to bundle atomic `route_and_recoup` after `finalize_task`. */
|
|
114
|
+
recoupBacker?: string;
|
|
115
|
+
/** Optional `extension-credit` recipient pubkey (defaults to `agentStateOwner ?? wallet`) for `route_and_recoup`. */
|
|
116
|
+
recoupRecipient?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface ExpireBuild extends CommonBuild {
|
|
119
|
+
action: "expire";
|
|
120
|
+
taskPda: string;
|
|
121
|
+
/** Campaign client receiving the escrow refund (defaults to `wallet`). */
|
|
122
|
+
client?: string;
|
|
123
|
+
/** Optional claimed agent pubkey whose `AgentState` PDA is appended as remaining account `[3]`. */
|
|
124
|
+
claimedAgent?: string;
|
|
88
125
|
}
|
|
89
|
-
export type BuildRequest = CreateBuild | ClaimBuild | ApproveBuild | SubmitBuild | VerifyBuild | FinalizeBuild;
|
|
126
|
+
export type BuildRequest = CreateBuild | ClaimBuild | ApproveBuild | SubmitBuild | VerifyBuild | FinalizeBuild | ExpireBuild;
|
|
90
127
|
export declare function buildInstruction(request: BuildRequest): TransactionInstruction;
|
|
91
128
|
export declare function intentDigest(intent: Omit<TransactionIntent, "digest">): string;
|
|
92
129
|
export declare function buildTransaction(request: BuildRequest): BuiltTransaction;
|
|
@@ -110,6 +147,7 @@ export declare const buildSubmit: (request: Omit<SubmitBuild, "action">) => Buil
|
|
|
110
147
|
export declare const buildApprove: (request: Omit<ApproveBuild, "action">) => BuiltTransaction;
|
|
111
148
|
export declare const buildVerify: (request: Omit<VerifyBuild, "action">) => BuiltTransaction;
|
|
112
149
|
export declare const buildFinalize: (request: Omit<FinalizeBuild, "action">) => BuiltTransaction;
|
|
150
|
+
export declare const buildExpire: (request: Omit<ExpireBuild, "action">) => BuiltTransaction;
|
|
113
151
|
export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
|
|
114
152
|
export type { SwitchboardVerifyRequest } from "./switchboard.js";
|
|
115
153
|
export * from "./payout-oracle.js";
|