@swarm-tips/client 0.2.12 → 0.3.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.
Files changed (44) hide show
  1. package/README.md +59 -18
  2. package/SBOM.spdx.json +5 -5
  3. package/dist/agent.d.ts +176 -0
  4. package/dist/agent.js +561 -0
  5. package/dist/auth/token-manager.d.ts +33 -0
  6. package/dist/auth/token-manager.js +175 -0
  7. package/dist/cli/keyfile.d.ts +24 -0
  8. package/dist/cli/keyfile.js +97 -0
  9. package/dist/cli/swarm.d.ts +14 -0
  10. package/dist/cli/swarm.js +516 -0
  11. package/dist/contracts/generated/shillbot.d.ts +9 -3
  12. package/dist/contracts/idl/shillbot.json +9 -3
  13. package/dist/coordination-game/api.d.ts +4 -4
  14. package/dist/coordination-game/api.js +8 -8
  15. package/dist/errors.d.ts +1 -1
  16. package/dist/generated/openapi.d.ts +1963 -0
  17. package/dist/generated/openapi.js +8 -0
  18. package/dist/http.d.ts +6 -3
  19. package/dist/http.js +18 -4
  20. package/dist/inbox/client.d.ts +16 -1
  21. package/dist/inbox/client.js +48 -2
  22. package/dist/inbox/index.d.ts +1 -1
  23. package/dist/index.d.ts +7 -2
  24. package/dist/index.js +7 -2
  25. package/dist/shillbot/api.d.ts +49 -2
  26. package/dist/shillbot/api.js +377 -33
  27. package/dist/signer/evm.d.ts +25 -0
  28. package/dist/signer/evm.js +249 -0
  29. package/dist/signer/index.d.ts +3 -0
  30. package/dist/signer/index.js +3 -0
  31. package/dist/signer/solana.d.ts +24 -0
  32. package/dist/signer/solana.js +183 -0
  33. package/dist/signer/types.d.ts +30 -0
  34. package/dist/signer/types.js +31 -0
  35. package/dist/swarm/index.d.ts +1 -0
  36. package/dist/swarm/index.js +9 -2
  37. package/dist/version.d.ts +1 -0
  38. package/dist/version.js +1 -0
  39. package/dist/vow/decoders/shillbot.d.ts +1 -0
  40. package/dist/vow/decoders/shillbot.js +2 -0
  41. package/dist/vow/types.d.ts +1 -0
  42. package/dist/vow/verify.d.ts +3 -2
  43. package/dist/vow/verify.js +8 -3
  44. package/package.json +5 -3
@@ -0,0 +1,249 @@
1
+ import { Buffer } from "buffer";
2
+ import { Secp256k1Program } from "@solana/web3.js";
3
+ import { SwarmClientError } from "../errors.js";
4
+ import { redactSigner } from "./types.js";
5
+ // Compact pure-TS Keccak-256 for EIP-55 address checksumming with zero optional peer dependency at load time.
6
+ const KECCAK_ROUNDS = 24;
7
+ const RC_LOW = [
8
+ 0x00000001, 0x00008082, 0x0000808a, 0x80008000, 0x0000808b, 0x80000001,
9
+ 0x80008081, 0x00008009, 0x0000008a, 0x00000088, 0x80008009, 0x8000000a,
10
+ 0x8000808b, 0x0000008b, 0x00008089, 0x00008003, 0x00008002, 0x00000080,
11
+ 0x0000800a, 0x8000000a, 0x80008081, 0x00008080, 0x80000001, 0x80008008,
12
+ ];
13
+ const RC_HIGH = [
14
+ 0x00000000, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000,
15
+ 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16
+ 0x00000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000,
17
+ 0x00000000, 0x80000000, 0x80000000, 0x80000000, 0x00000000, 0x80000000,
18
+ ];
19
+ const ROTC = [
20
+ 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
21
+ 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
22
+ ];
23
+ const PILN = [
24
+ 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
25
+ 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
26
+ ];
27
+ function keccakF1600(s) {
28
+ const bc = new Uint32Array(10);
29
+ for (let round = 0; round < KECCAK_ROUNDS; round++) {
30
+ for (let i = 0; i < 10; i += 2) {
31
+ bc[i] = s[i] ^ s[i + 10] ^ s[i + 20] ^ s[i + 30] ^ s[i + 40];
32
+ bc[i + 1] = s[i + 1] ^ s[i + 11] ^ s[i + 21] ^ s[i + 31] ^ s[i + 41];
33
+ }
34
+ for (let i = 0; i < 10; i += 2) {
35
+ const prev = (i + 8) % 10;
36
+ const next = (i + 2) % 10;
37
+ const dLow = bc[prev] ^ ((bc[next] << 1) | (bc[next + 1] >>> 31));
38
+ const dHigh = bc[prev + 1] ^ ((bc[next + 1] << 1) | (bc[next] >>> 31));
39
+ for (let j = 0; j < 50; j += 10) {
40
+ s[j + i] ^= dLow;
41
+ s[j + i + 1] ^= dHigh;
42
+ }
43
+ }
44
+ let tLow = s[2];
45
+ let tHigh = s[3];
46
+ for (let i = 0; i < 24; i++) {
47
+ const j = PILN[i] * 2;
48
+ const r = ROTC[i];
49
+ const nLow = s[j];
50
+ const nHigh = s[j + 1];
51
+ if (r < 32) {
52
+ s[j] = (tLow << r) | (tHigh >>> (32 - r));
53
+ s[j + 1] = (tHigh << r) | (tLow >>> (32 - r));
54
+ }
55
+ else {
56
+ const sShift = r - 32;
57
+ s[j] = (tHigh << sShift) | (tLow >>> (32 - sShift));
58
+ s[j + 1] = (tLow << sShift) | (tHigh >>> (32 - sShift));
59
+ }
60
+ tLow = nLow;
61
+ tHigh = nHigh;
62
+ }
63
+ for (let j = 0; j < 50; j += 10) {
64
+ for (let i = 0; i < 10; i++)
65
+ bc[i] = s[j + i];
66
+ for (let i = 0; i < 10; i += 2) {
67
+ s[j + i] ^= ~bc[(i + 2) % 10] & bc[(i + 4) % 10];
68
+ s[j + i + 1] ^= ~bc[(i + 3) % 10] & bc[(i + 5) % 10];
69
+ }
70
+ }
71
+ s[0] ^= RC_LOW[round];
72
+ s[1] ^= RC_HIGH[round];
73
+ }
74
+ }
75
+ function keccak256Bytes(input) {
76
+ const rate = 136;
77
+ const state = new Uint32Array(50);
78
+ const block = new Uint8Array(rate);
79
+ let offset = 0;
80
+ while (offset + rate <= input.length) {
81
+ for (let i = 0; i < rate; i += 4) {
82
+ state[i >> 2] ^=
83
+ input[offset + i] |
84
+ (input[offset + i + 1] << 8) |
85
+ (input[offset + i + 2] << 16) |
86
+ (input[offset + i + 3] << 24);
87
+ }
88
+ keccakF1600(state);
89
+ offset += rate;
90
+ }
91
+ const rem = input.length - offset;
92
+ block.fill(0);
93
+ block.set(input.subarray(offset), 0);
94
+ block[rem] ^= 0x01;
95
+ block[rate - 1] ^= 0x80;
96
+ for (let i = 0; i < rate; i += 4) {
97
+ state[i >> 2] ^=
98
+ block[i] | (block[i + 1] << 8) | (block[i + 2] << 16) | (block[i + 3] << 24);
99
+ }
100
+ keccakF1600(state);
101
+ const out = new Uint8Array(32);
102
+ for (let i = 0; i < 8; i++) {
103
+ const w = state[i];
104
+ out[i * 4] = w & 0xff;
105
+ out[i * 4 + 1] = (w >>> 8) & 0xff;
106
+ out[i * 4 + 2] = (w >>> 16) & 0xff;
107
+ out[i * 4 + 3] = (w >>> 24) & 0xff;
108
+ }
109
+ return out;
110
+ }
111
+ function toEip55Address(lowerHexNoPrefix) {
112
+ const clean = lowerHexNoPrefix.toLowerCase();
113
+ const hash = keccak256Bytes(new TextEncoder().encode(clean));
114
+ let out = "0x";
115
+ for (let i = 0; i < 40; i++) {
116
+ const nibble = (hash[i >> 1] >> (i % 2 === 0 ? 4 : 0)) & 0x0f;
117
+ out += nibble >= 8 ? clean[i].toUpperCase() : clean[i];
118
+ }
119
+ return out;
120
+ }
121
+ /**
122
+ * Create a browser-clean `EvmSwarmSigner` from a `0x`-prefixed 32-byte hex private key.
123
+ * Derives the EIP-55 address and EIP-191 `personal_sign` signatures without requiring
124
+ * optional peer `viem` at module load, and uses `viem` dynamically if `sendTransaction` is called.
125
+ */
126
+ export function fromEvmPrivateKey(privateKeyHex, opts = {}) {
127
+ if (typeof privateKeyHex !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(privateKeyHex)) {
128
+ throw new SwarmClientError({
129
+ code: "INVALID_ARGUMENT",
130
+ operation: "signer.fromEvmPrivateKey",
131
+ message: "Expected a 0x-prefixed 32-byte hex EVM private key",
132
+ });
133
+ }
134
+ const secretBytes = Buffer.from(privateKeyHex.slice(2), "hex");
135
+ const normalizedKey = `0x${privateKeyHex.slice(2).toLowerCase()}`;
136
+ let rawAddressHex;
137
+ try {
138
+ const probe = Secp256k1Program.createInstructionWithPrivateKey({
139
+ privateKey: secretBytes,
140
+ message: new Uint8Array(0),
141
+ });
142
+ const addrOffset = probe.data.readUInt16LE(4);
143
+ rawAddressHex = Buffer.from(probe.data.subarray(addrOffset, addrOffset + 20)).toString("hex");
144
+ }
145
+ catch {
146
+ throw new SwarmClientError({
147
+ code: "INVALID_ARGUMENT",
148
+ operation: "signer.fromEvmPrivateKey",
149
+ message: "Invalid secp256k1 private key",
150
+ });
151
+ }
152
+ const address = toEip55Address(rawAddressHex);
153
+ return redactSigner({
154
+ chain: "evm",
155
+ address,
156
+ ...(opts.chainId !== undefined ? { chainId: opts.chainId } : {}),
157
+ async signMessage(message) {
158
+ const msgBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
159
+ const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${msgBytes.length}`);
160
+ const payload = new Uint8Array(prefix.length + msgBytes.length);
161
+ payload.set(prefix, 0);
162
+ payload.set(msgBytes, prefix.length);
163
+ const ix = Secp256k1Program.createInstructionWithPrivateKey({
164
+ privateKey: secretBytes,
165
+ message: payload,
166
+ });
167
+ const sigOffset = ix.data.readUInt16LE(1);
168
+ const rsHex = Buffer.from(ix.data.subarray(sigOffset, sigOffset + 64)).toString("hex");
169
+ const vHex = (ix.data[sigOffset + 64] + 27).toString(16).padStart(2, "0");
170
+ return `0x${rsHex}${vHex}`;
171
+ },
172
+ async sendTransaction(call) {
173
+ if (!opts.rpcUrl) {
174
+ throw new SwarmClientError({
175
+ code: "INVALID_ARGUMENT",
176
+ operation: "signer.sendTransaction",
177
+ message: "rpcUrl is required in fromEvmPrivateKey options to broadcast EVM transactions",
178
+ });
179
+ }
180
+ const [{ createWalletClient, http }, { privateKeyToAccount }] = await Promise.all([
181
+ import("viem"),
182
+ import("viem/accounts"),
183
+ ]);
184
+ const account = privateKeyToAccount(normalizedKey);
185
+ const chainId = call.chainId ?? opts.chainId ?? 84532;
186
+ const client = createWalletClient({
187
+ account,
188
+ transport: http(opts.rpcUrl),
189
+ });
190
+ return client.sendTransaction({
191
+ account,
192
+ chain: {
193
+ id: chainId,
194
+ name: `eip155:${chainId}`,
195
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
196
+ rpcUrls: { default: { http: [opts.rpcUrl] } },
197
+ },
198
+ to: call.to,
199
+ data: call.data,
200
+ value: call.value ?? 0n,
201
+ });
202
+ },
203
+ });
204
+ }
205
+ /**
206
+ * Adapt a `viem` / `wagmi` `WalletClient` into a browser-clean `EvmSwarmSigner`.
207
+ */
208
+ export function fromEvmWalletClient(walletClient) {
209
+ const rawAccount = walletClient?.account;
210
+ const rawAddress = typeof rawAccount === "string"
211
+ ? rawAccount
212
+ : rawAccount && typeof rawAccount === "object"
213
+ ? rawAccount.address
214
+ : undefined;
215
+ if (!rawAddress || !/^0x[0-9a-fA-F]{40}$/.test(rawAddress)) {
216
+ throw new SwarmClientError({
217
+ code: "INVALID_ARGUMENT",
218
+ operation: "signer.fromEvmWalletClient",
219
+ message: "WalletClient has no connected account address",
220
+ });
221
+ }
222
+ const address = toEip55Address(rawAddress.slice(2));
223
+ const chainId = walletClient.chain?.id;
224
+ const signer = {
225
+ chain: "evm",
226
+ address,
227
+ ...(chainId !== undefined ? { chainId } : {}),
228
+ async signMessage(message) {
229
+ return walletClient.signMessage({
230
+ account: rawAccount ?? address,
231
+ message: typeof message === "string" ? message : { raw: message },
232
+ });
233
+ },
234
+ ...(walletClient.sendTransaction
235
+ ? {
236
+ async sendTransaction(call) {
237
+ return walletClient.sendTransaction({
238
+ account: rawAccount ?? address,
239
+ to: call.to,
240
+ data: call.data,
241
+ value: call.value ?? 0n,
242
+ ...(call.chainId ? { chainId: call.chainId } : {}),
243
+ });
244
+ },
245
+ }
246
+ : {}),
247
+ };
248
+ return redactSigner(signer);
249
+ }
@@ -0,0 +1,3 @@
1
+ export { redactSigner, type EvmCallRequest, type EvmSwarmSigner, type SolanaSwarmSigner, type SwarmSigner, } from "./types.js";
2
+ export { fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, type SolanaWalletAdapterLike, } from "./solana.js";
3
+ export { fromEvmPrivateKey, fromEvmWalletClient, type EvmPrivateKeyOptions, type EvmWalletClientLike, } from "./evm.js";
@@ -0,0 +1,3 @@
1
+ export { redactSigner, } from "./types.js";
2
+ export { fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, } from "./solana.js";
3
+ export { fromEvmPrivateKey, fromEvmWalletClient, } from "./evm.js";
@@ -0,0 +1,24 @@
1
+ import { Keypair, VersionedTransaction, type PublicKey, type Transaction } from "@solana/web3.js";
2
+ import { type SolanaSwarmSigner } from "./types.js";
3
+ export interface SolanaWalletAdapterLike {
4
+ publicKey: PublicKey | {
5
+ toBase58(): string;
6
+ } | null | undefined;
7
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
8
+ signTransaction?: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
9
+ }
10
+ /**
11
+ * Create a browser-clean `SolanaSwarmSigner` from a `@solana/web3.js` `Keypair`.
12
+ * Secret key bytes stay trapped inside a private closure and are redacted from logs/JSON.
13
+ */
14
+ export declare function fromSolanaKeypair(keypair: Keypair): SolanaSwarmSigner;
15
+ /**
16
+ * Create a `SolanaSwarmSigner` from a 64-byte `Uint8Array`, base58-encoded secret key,
17
+ * or JSON `[u8, ...]` array string (matching `solana-keygen` format).
18
+ */
19
+ export declare function fromSolanaSecretKey(secret: Uint8Array | string): SolanaSwarmSigner;
20
+ /**
21
+ * Adapt a browser Solana Wallet Adapter (`@solana/wallet-adapter-base` compatible)
22
+ * into a `SolanaSwarmSigner`.
23
+ */
24
+ export declare function fromSolanaWalletAdapter(adapter: SolanaWalletAdapterLike): SolanaSwarmSigner;
@@ -0,0 +1,183 @@
1
+ import bs58 from "bs58";
2
+ import { Ed25519Program, Keypair, VersionedTransaction, } from "@solana/web3.js";
3
+ import { SwarmClientError } from "../errors.js";
4
+ import { redactSigner } from "./types.js";
5
+ const ED25519_PKCS8_PREFIX = new Uint8Array([
6
+ 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
7
+ 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20,
8
+ ]);
9
+ async function signEd25519Detached(secretKey64, message) {
10
+ if (globalThis.crypto?.subtle) {
11
+ try {
12
+ const pkcs8 = new Uint8Array(48);
13
+ pkcs8.set(ED25519_PKCS8_PREFIX, 0);
14
+ pkcs8.set(secretKey64.subarray(0, 32), 16);
15
+ const key = await globalThis.crypto.subtle.importKey("pkcs8", pkcs8, { name: "Ed25519" }, false, ["sign"]);
16
+ pkcs8.fill(0);
17
+ const payload = new Uint8Array(message.byteLength);
18
+ payload.set(message);
19
+ const sig = await globalThis.crypto.subtle.sign("Ed25519", key, payload);
20
+ return new Uint8Array(sig);
21
+ }
22
+ catch {
23
+ // Fall back to @solana/web3.js Ed25519Program below on runtimes without WebCrypto Ed25519.
24
+ }
25
+ }
26
+ const ix = Ed25519Program.createInstructionWithPrivateKey({
27
+ privateKey: secretKey64,
28
+ message,
29
+ });
30
+ const sigOffset = ix.data[2] | (ix.data[3] << 8);
31
+ return new Uint8Array(ix.data.subarray(sigOffset, sigOffset + 64));
32
+ }
33
+ /**
34
+ * Create a browser-clean `SolanaSwarmSigner` from a `@solana/web3.js` `Keypair`.
35
+ * Secret key bytes stay trapped inside a private closure and are redacted from logs/JSON.
36
+ */
37
+ export function fromSolanaKeypair(keypair) {
38
+ if (!keypair?.secretKey || keypair.secretKey.length !== 64) {
39
+ throw new SwarmClientError({
40
+ code: "INVALID_ARGUMENT",
41
+ operation: "signer.fromSolanaKeypair",
42
+ message: "Expected a valid 64-byte Solana Keypair",
43
+ });
44
+ }
45
+ const secretBytes = new Uint8Array(keypair.secretKey);
46
+ const address = keypair.publicKey.toBase58();
47
+ return redactSigner({
48
+ chain: "solana",
49
+ address,
50
+ async signMessage(message) {
51
+ return signEd25519Detached(secretBytes, message);
52
+ },
53
+ async signTransaction(tx) {
54
+ const kp = Keypair.fromSecretKey(secretBytes);
55
+ if (tx instanceof VersionedTransaction) {
56
+ tx.sign([kp]);
57
+ }
58
+ else {
59
+ tx.partialSign(kp);
60
+ }
61
+ return tx;
62
+ },
63
+ });
64
+ }
65
+ /**
66
+ * Create a `SolanaSwarmSigner` from a 64-byte `Uint8Array`, base58-encoded secret key,
67
+ * or JSON `[u8, ...]` array string (matching `solana-keygen` format).
68
+ */
69
+ export function fromSolanaSecretKey(secret) {
70
+ let bytes;
71
+ if (secret instanceof Uint8Array) {
72
+ bytes = new Uint8Array(secret);
73
+ }
74
+ else if (typeof secret === "string") {
75
+ const trimmed = secret.trim();
76
+ if (!trimmed) {
77
+ throw new SwarmClientError({
78
+ code: "INVALID_ARGUMENT",
79
+ operation: "signer.fromSolanaSecretKey",
80
+ message: "Solana secret key string must not be empty",
81
+ });
82
+ }
83
+ if (trimmed.startsWith("[")) {
84
+ let parsed;
85
+ try {
86
+ parsed = JSON.parse(trimmed);
87
+ }
88
+ catch {
89
+ throw new SwarmClientError({
90
+ code: "INVALID_ARGUMENT",
91
+ operation: "signer.fromSolanaSecretKey",
92
+ message: "Invalid JSON array for Solana secret key",
93
+ });
94
+ }
95
+ if (!Array.isArray(parsed) ||
96
+ parsed.length !== 64 ||
97
+ parsed.some((n) => typeof n !== "number" || !Number.isInteger(n) || n < 0 || n > 255)) {
98
+ throw new SwarmClientError({
99
+ code: "INVALID_ARGUMENT",
100
+ operation: "signer.fromSolanaSecretKey",
101
+ message: "Solana JSON secret key must be an array of 64 byte integers (0..255)",
102
+ });
103
+ }
104
+ bytes = Uint8Array.from(parsed);
105
+ }
106
+ else {
107
+ try {
108
+ bytes = bs58.decode(trimmed);
109
+ }
110
+ catch {
111
+ throw new SwarmClientError({
112
+ code: "INVALID_ARGUMENT",
113
+ operation: "signer.fromSolanaSecretKey",
114
+ message: "Invalid base58 Solana secret key",
115
+ });
116
+ }
117
+ }
118
+ }
119
+ else {
120
+ throw new SwarmClientError({
121
+ code: "INVALID_ARGUMENT",
122
+ operation: "signer.fromSolanaSecretKey",
123
+ message: "Expected a 64-byte Uint8Array, base58 string, or JSON byte array string",
124
+ });
125
+ }
126
+ if (bytes.length !== 64) {
127
+ throw new SwarmClientError({
128
+ code: "INVALID_ARGUMENT",
129
+ operation: "signer.fromSolanaSecretKey",
130
+ message: `Expected 64-byte Solana secret key, received ${bytes.length} bytes`,
131
+ });
132
+ }
133
+ let kp;
134
+ try {
135
+ kp = Keypair.fromSecretKey(bytes);
136
+ }
137
+ catch {
138
+ throw new SwarmClientError({
139
+ code: "INVALID_ARGUMENT",
140
+ operation: "signer.fromSolanaSecretKey",
141
+ message: "Invalid Solana Ed25519 secret key bytes",
142
+ });
143
+ }
144
+ return fromSolanaKeypair(kp);
145
+ }
146
+ /**
147
+ * Adapt a browser Solana Wallet Adapter (`@solana/wallet-adapter-base` compatible)
148
+ * into a `SolanaSwarmSigner`.
149
+ */
150
+ export function fromSolanaWalletAdapter(adapter) {
151
+ if (!adapter?.publicKey) {
152
+ throw new SwarmClientError({
153
+ code: "INVALID_ARGUMENT",
154
+ operation: "signer.fromSolanaWalletAdapter",
155
+ message: "Wallet adapter has no connected publicKey",
156
+ });
157
+ }
158
+ const address = adapter.publicKey.toBase58();
159
+ return redactSigner({
160
+ chain: "solana",
161
+ address,
162
+ async signMessage(message) {
163
+ if (!adapter.signMessage) {
164
+ throw new SwarmClientError({
165
+ code: "INVALID_ARGUMENT",
166
+ operation: "signer.signMessage",
167
+ message: "Connected Solana wallet adapter does not support signMessage",
168
+ });
169
+ }
170
+ return adapter.signMessage(message);
171
+ },
172
+ async signTransaction(tx) {
173
+ if (!adapter.signTransaction) {
174
+ throw new SwarmClientError({
175
+ code: "INVALID_ARGUMENT",
176
+ operation: "signer.signTransaction",
177
+ message: "Connected Solana wallet adapter does not support signTransaction",
178
+ });
179
+ }
180
+ return adapter.signTransaction(tx);
181
+ },
182
+ });
183
+ }
@@ -0,0 +1,30 @@
1
+ import type { Transaction, VersionedTransaction } from "@solana/web3.js";
2
+ export interface SolanaSwarmSigner {
3
+ readonly chain: "solana";
4
+ readonly address: string;
5
+ signMessage(message: Uint8Array): Promise<Uint8Array>;
6
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
7
+ }
8
+ export interface EvmCallRequest {
9
+ to: `0x${string}`;
10
+ data: `0x${string}`;
11
+ value?: bigint;
12
+ chainId?: number;
13
+ }
14
+ export interface EvmSwarmSigner {
15
+ readonly chain: "evm";
16
+ readonly address: `0x${string}`;
17
+ readonly chainId?: number;
18
+ signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
19
+ sendTransaction?(call: EvmCallRequest): Promise<`0x${string}`>;
20
+ }
21
+ export type SwarmSigner = SolanaSwarmSigner | EvmSwarmSigner;
22
+ /**
23
+ * C6 Redaction: attach safe serialization and inspection hooks while freezing
24
+ * the public signer surface so secret key material can never leak into JSON,
25
+ * string formatting, or `util.inspect` logs.
26
+ */
27
+ export declare function redactSigner<T extends {
28
+ readonly chain: string;
29
+ readonly address: string;
30
+ }>(signer: T): T;
@@ -0,0 +1,31 @@
1
+ const NODE_INSPECT_CUSTOM = Symbol.for("nodejs.util.inspect.custom");
2
+ /**
3
+ * C6 Redaction: attach safe serialization and inspection hooks while freezing
4
+ * the public signer surface so secret key material can never leak into JSON,
5
+ * string formatting, or `util.inspect` logs.
6
+ */
7
+ export function redactSigner(signer) {
8
+ const { chain, address } = signer;
9
+ const label = `SwarmSigner(${chain}:${address})`;
10
+ Object.defineProperties(signer, {
11
+ toJSON: {
12
+ value: () => ({ chain, address }),
13
+ enumerable: false,
14
+ configurable: false,
15
+ writable: false,
16
+ },
17
+ toString: {
18
+ value: () => label,
19
+ enumerable: false,
20
+ configurable: false,
21
+ writable: false,
22
+ },
23
+ [NODE_INSPECT_CUSTOM]: {
24
+ value: () => label,
25
+ enumerable: false,
26
+ configurable: false,
27
+ writable: false,
28
+ },
29
+ });
30
+ return Object.freeze(signer);
31
+ }
@@ -78,6 +78,7 @@ export declare class SwarmClient {
78
78
  results: SearchHit[];
79
79
  corpus_size: number;
80
80
  }>;
81
+ earningCandidates<T = unknown>(limit?: number): Promise<T>;
81
82
  reputation(wallet: string, network?: string): Promise<AgentReputation>;
82
83
  leaderboard(limit?: number): Promise<EigenTrustRecord[]>;
83
84
  toolCount(): Promise<number | null>;
@@ -1,4 +1,5 @@
1
1
  import { HttpClient } from "../http.js";
2
+ import { CLIENT_VERSION } from "../version.js";
2
3
  function parseRpc(body) {
3
4
  const trimmed = body.trimStart();
4
5
  if (trimmed.startsWith("{")) {
@@ -26,7 +27,9 @@ export class SwarmClient {
26
27
  baseUrl;
27
28
  constructor(options) {
28
29
  this.baseUrl = options.baseUrl.replace(/\/$/, "");
29
- this.fetchImpl = (options.fetch ?? globalThis.fetch).bind(globalThis);
30
+ this.fetchImpl = options.fetch
31
+ ? (input, init) => options.fetch(input, init)
32
+ : globalThis.fetch.bind(globalThis);
30
33
  this.http = new HttpClient(options);
31
34
  }
32
35
  async listings() { return this.http.get("/internal/listings"); }
@@ -37,6 +40,10 @@ export class SwarmClient {
37
40
  params.set("limit", String(limit));
38
41
  return this.http.get(`/internal/mcp/search?${params.toString()}`);
39
42
  }
43
+ async earningCandidates(limit) {
44
+ const qs = limit !== undefined ? `?limit=${encodeURIComponent(String(limit))}` : "";
45
+ return this.http.get(`/internal/mcp/earning-candidates${qs}`);
46
+ }
40
47
  reputation(wallet, network = "mainnet") {
41
48
  if (!wallet)
42
49
  return Promise.reject(new TypeError("wallet is required"));
@@ -49,7 +56,7 @@ export class SwarmClient {
49
56
  async toolCount() {
50
57
  const headers = { "Content-Type": "application/json", Accept: "application/json, text/event-stream" };
51
58
  try {
52
- const init = await this.fetchImpl(`${this.baseUrl}/mcp`, { method: "POST", headers, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "swarm-client", version: "0.2.4" } } }) });
59
+ const init = await this.fetchImpl(`${this.baseUrl}/mcp`, { method: "POST", headers, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "swarm-client", version: CLIENT_VERSION } } }) });
53
60
  if (!init.ok)
54
61
  return null;
55
62
  const session = init.headers.get("mcp-session-id");
@@ -0,0 +1 @@
1
+ export declare const CLIENT_VERSION = "0.3.0";
@@ -0,0 +1 @@
1
+ export const CLIENT_VERSION = "0.3.0";
@@ -56,5 +56,6 @@ export declare const resolveShillbotState: StateResolver;
56
56
  * account, so post-finalize the attestation is permanently unverifiable. */
57
57
  export declare const shillbotValidStates: (accountKind: string) => readonly string[];
58
58
  export declare const SHILLBOT_VOW_PROGRAM_ID = "2tR37nqMpwdV4DVUHjzUmL1rH2DtkA8zrRA4EAhT7KMi";
59
+ export declare const SHILLBOT_SCORE_MAX = 1000000n;
59
60
  /** Convenience bundle for callers that just want the canonical Shillbot triple. */
60
61
  export declare const shillbotProtocol: ProtocolHandler;
@@ -114,12 +114,14 @@ export const shillbotValidStates = (accountKind) => {
114
114
  return ["verified"];
115
115
  };
116
116
  export const SHILLBOT_VOW_PROGRAM_ID = "2tR37nqMpwdV4DVUHjzUmL1rH2DtkA8zrRA4EAhT7KMi";
117
+ export const SHILLBOT_SCORE_MAX = 1000000n;
117
118
  /** Convenience bundle for callers that just want the canonical Shillbot triple. */
118
119
  export const shillbotProtocol = {
119
120
  decode: decodeShillbotTask,
120
121
  resolveState: resolveShillbotState,
121
122
  validStates: shillbotValidStates,
122
123
  programId: SHILLBOT_VOW_PROGRAM_ID,
124
+ scoreMax: SHILLBOT_SCORE_MAX,
123
125
  };
124
126
  function bytesToHex(b) {
125
127
  let s = "";
@@ -106,4 +106,5 @@ export interface ProtocolHandler {
106
106
  resolveState: StateResolver;
107
107
  validStates: ValidStates;
108
108
  programId?: string;
109
+ scoreMax?: bigint | number | string;
109
110
  }
@@ -1,5 +1,6 @@
1
1
  import { Connection } from "@solana/web3.js";
2
2
  import type { AasV1Attestation, FailureReason, ProtocolHandler, Verdict } from "./types.js";
3
+ export declare const DEFAULT_SCORE_MAX = 1000000n;
3
4
  /**
4
5
  * Step-by-step verifier per `docs/specs/vow-v1.md` §4.
5
6
  *
@@ -10,7 +11,7 @@ import type { AasV1Attestation, FailureReason, ProtocolHandler, Verdict } from "
10
11
  *
11
12
  * Splitting lets unit tests cover the pure parts without an RPC.
12
13
  */
13
- export declare function verifyV1(attestation: unknown, protocol: ProtocolHandler, rpc: Connection): Promise<Verdict>;
14
+ export declare function verifyV1(attestation: unknown, protocol: ProtocolHandler, rpc: Connection, expectedScoreMax?: bigint | number | string): Promise<Verdict>;
14
15
  /**
15
16
  * Pure step 1 + step 6 of the protocol. Returns null on success or
16
17
  * the first failure reason.
@@ -20,4 +21,4 @@ export declare function verifyV1Schema(attestation: unknown): FailureReason | nu
20
21
  * Steps 2-5 + 7 — touches RPC. Returns null on success or the first
21
22
  * failure reason.
22
23
  */
23
- export declare function verifyV1OnChain(a: AasV1Attestation, protocol: ProtocolHandler, rpc: Connection): Promise<FailureReason | null>;
24
+ export declare function verifyV1OnChain(a: AasV1Attestation, protocol: ProtocolHandler, rpc: Connection, expectedScoreMax?: bigint | number | string): Promise<FailureReason | null>;
@@ -1,6 +1,7 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { anchorDiscriminator, bytesEqual } from "./discriminator.js";
3
3
  import { asV1, checkSchema } from "./schema.js";
4
+ export const DEFAULT_SCORE_MAX = 1000000n;
4
5
  /**
5
6
  * Step-by-step verifier per `docs/specs/vow-v1.md` §4.
6
7
  *
@@ -11,7 +12,7 @@ import { asV1, checkSchema } from "./schema.js";
11
12
  *
12
13
  * Splitting lets unit tests cover the pure parts without an RPC.
13
14
  */
14
- export async function verifyV1(attestation, protocol, rpc) {
15
+ export async function verifyV1(attestation, protocol, rpc, expectedScoreMax) {
15
16
  const checkedAt = nowRfc3339();
16
17
  const rpcEndpoint = rpc.rpcEndpoint;
17
18
  const schemaFail = verifyV1Schema(attestation);
@@ -25,7 +26,7 @@ export async function verifyV1(attestation, protocol, rpc) {
25
26
  };
26
27
  }
27
28
  const a = asV1(attestation);
28
- const onChainFail = await verifyV1OnChain(a, protocol, rpc);
29
+ const onChainFail = await verifyV1OnChain(a, protocol, rpc, expectedScoreMax);
29
30
  if (onChainFail) {
30
31
  return {
31
32
  valid: false,
@@ -61,7 +62,11 @@ export function verifyV1Schema(attestation) {
61
62
  * Steps 2-5 + 7 — touches RPC. Returns null on success or the first
62
63
  * failure reason.
63
64
  */
64
- export async function verifyV1OnChain(a, protocol, rpc) {
65
+ export async function verifyV1OnChain(a, protocol, rpc, expectedScoreMax) {
66
+ const expectedMax = BigInt(expectedScoreMax ?? protocol.scoreMax ?? DEFAULT_SCORE_MAX);
67
+ if (BigInt(a.score_max) !== expectedMax) {
68
+ return "field_mismatch:score_max";
69
+ }
65
70
  // Step 2 — fetch the on-chain account.
66
71
  const accountInfo = await rpc.getAccountInfo(new PublicKey(a.account));
67
72
  if (accountInfo === null) {