@swarm-tips/client 0.4.2 → 0.4.4
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/README.md +3 -2
- package/SBOM.spdx.json +5 -5
- package/dist/agent.d.ts +17 -1
- package/dist/agent.js +71 -54
- package/dist/cli/swarm.d.ts +5 -0
- package/dist/cli/swarm.js +48 -21
- 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/http.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 +8 -1
- package/dist/shillbot/api.js +53 -133
- 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/solana.d.ts +3 -2
- package/dist/signer/solana.js +36 -9
- 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/signer/evm.js
CHANGED
|
@@ -118,6 +118,42 @@ function toEip55Address(lowerHexNoPrefix) {
|
|
|
118
118
|
}
|
|
119
119
|
return out;
|
|
120
120
|
}
|
|
121
|
+
function normalizeSignerEvmChain(chain) {
|
|
122
|
+
if (typeof chain === "number") {
|
|
123
|
+
if (!Number.isSafeInteger(chain) || chain <= 0) {
|
|
124
|
+
throw new SwarmClientError({
|
|
125
|
+
code: "INVALID_ARGUMENT",
|
|
126
|
+
operation: "signer.evm",
|
|
127
|
+
message: `Invalid EVM chainId: ${String(chain)}`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return `eip155:${chain}`;
|
|
131
|
+
}
|
|
132
|
+
const trimmed = chain.trim().toLowerCase();
|
|
133
|
+
if (/^\d+$/.test(trimmed))
|
|
134
|
+
return `eip155:${trimmed}`;
|
|
135
|
+
if (trimmed === "base-sepolia")
|
|
136
|
+
return "eip155:84532";
|
|
137
|
+
if (trimmed === "base")
|
|
138
|
+
return "eip155:8453";
|
|
139
|
+
if (trimmed === "ethereum")
|
|
140
|
+
return "eip155:1";
|
|
141
|
+
if (trimmed === "ethereum-sepolia" || trimmed === "sepolia")
|
|
142
|
+
return "eip155:11155111";
|
|
143
|
+
return trimmed;
|
|
144
|
+
}
|
|
145
|
+
function parseCaip2NumericChainId(caip2) {
|
|
146
|
+
const match = /^eip155:(\d+)$/.exec(caip2);
|
|
147
|
+
const parsed = match ? Number(match[1]) : Number.NaN;
|
|
148
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
149
|
+
throw new SwarmClientError({
|
|
150
|
+
code: "INVALID_ARGUMENT",
|
|
151
|
+
operation: "signer.sendTransaction",
|
|
152
|
+
message: `Unsupported EVM CAIP-2 chain identifier: ${caip2}`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return parsed;
|
|
156
|
+
}
|
|
121
157
|
/**
|
|
122
158
|
* Create a browser-clean `EvmSwarmSigner` from a `0x`-prefixed 32-byte hex private key.
|
|
123
159
|
* Derives the EIP-55 address and EIP-191 `personal_sign` signatures without requiring
|
|
@@ -131,6 +167,9 @@ export function fromEvmPrivateKey(privateKeyHex, opts = {}) {
|
|
|
131
167
|
message: "Expected a 0x-prefixed 32-byte hex EVM private key",
|
|
132
168
|
});
|
|
133
169
|
}
|
|
170
|
+
if (opts.chainId !== undefined) {
|
|
171
|
+
normalizeSignerEvmChain(opts.chainId);
|
|
172
|
+
}
|
|
134
173
|
const secretBytes = Buffer.from(privateKeyHex.slice(2), "hex");
|
|
135
174
|
const normalizedKey = `0x${privateKeyHex.slice(2).toLowerCase()}`;
|
|
136
175
|
let rawAddressHex;
|
|
@@ -177,12 +216,26 @@ export function fromEvmPrivateKey(privateKeyHex, opts = {}) {
|
|
|
177
216
|
message: "rpcUrl is required in fromEvmPrivateKey options to broadcast EVM transactions",
|
|
178
217
|
});
|
|
179
218
|
}
|
|
219
|
+
const signerChain = opts.chainId !== undefined ? normalizeSignerEvmChain(opts.chainId) : undefined;
|
|
220
|
+
const requestedChain = call.chain !== undefined
|
|
221
|
+
? normalizeSignerEvmChain(call.chain)
|
|
222
|
+
: call.chainId !== undefined
|
|
223
|
+
? normalizeSignerEvmChain(call.chainId)
|
|
224
|
+
: undefined;
|
|
225
|
+
if (signerChain && requestedChain && signerChain !== requestedChain) {
|
|
226
|
+
throw new SwarmClientError({
|
|
227
|
+
code: "TRANSACTION_MISMATCH",
|
|
228
|
+
operation: "signer.sendTransaction",
|
|
229
|
+
message: `EVM signer chain ${signerChain} differs from call chain ${requestedChain}`,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const resolvedCaip2 = requestedChain ?? signerChain ?? "eip155:84532";
|
|
233
|
+
const chainId = parseCaip2NumericChainId(resolvedCaip2);
|
|
180
234
|
const [{ createWalletClient, http }, { privateKeyToAccount }] = await Promise.all([
|
|
181
235
|
import("viem"),
|
|
182
236
|
import("viem/accounts"),
|
|
183
237
|
]);
|
|
184
238
|
const account = privateKeyToAccount(normalizedKey);
|
|
185
|
-
const chainId = call.chainId ?? opts.chainId ?? 84532;
|
|
186
239
|
const client = createWalletClient({
|
|
187
240
|
account,
|
|
188
241
|
transport: http(opts.rpcUrl),
|
|
@@ -198,6 +251,7 @@ export function fromEvmPrivateKey(privateKeyHex, opts = {}) {
|
|
|
198
251
|
to: call.to,
|
|
199
252
|
data: call.data,
|
|
200
253
|
value: call.value ?? 0n,
|
|
254
|
+
...(call.maxFeePerGas !== undefined ? { maxFeePerGas: call.maxFeePerGas } : {}),
|
|
201
255
|
});
|
|
202
256
|
},
|
|
203
257
|
});
|
|
@@ -234,12 +288,28 @@ export function fromEvmWalletClient(walletClient) {
|
|
|
234
288
|
...(walletClient.sendTransaction
|
|
235
289
|
? {
|
|
236
290
|
async sendTransaction(call) {
|
|
291
|
+
const signerChain = chainId !== undefined ? normalizeSignerEvmChain(chainId) : undefined;
|
|
292
|
+
const requestedChain = call.chain !== undefined
|
|
293
|
+
? normalizeSignerEvmChain(call.chain)
|
|
294
|
+
: call.chainId !== undefined
|
|
295
|
+
? normalizeSignerEvmChain(call.chainId)
|
|
296
|
+
: undefined;
|
|
297
|
+
if (signerChain && requestedChain && signerChain !== requestedChain) {
|
|
298
|
+
throw new SwarmClientError({
|
|
299
|
+
code: "TRANSACTION_MISMATCH",
|
|
300
|
+
operation: "signer.sendTransaction",
|
|
301
|
+
message: `WalletClient chain ${signerChain} differs from call chain ${requestedChain}`,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
const resolvedNumeric = call.chainId ??
|
|
305
|
+
(requestedChain ? parseCaip2NumericChainId(requestedChain) : chainId);
|
|
237
306
|
return walletClient.sendTransaction({
|
|
238
307
|
account: rawAccount ?? address,
|
|
239
308
|
to: call.to,
|
|
240
309
|
data: call.data,
|
|
241
310
|
value: call.value ?? 0n,
|
|
242
|
-
...(
|
|
311
|
+
...(resolvedNumeric !== undefined ? { chainId: resolvedNumeric } : {}),
|
|
312
|
+
...(call.maxFeePerGas !== undefined ? { maxFeePerGas: call.maxFeePerGas } : {}),
|
|
243
313
|
});
|
|
244
314
|
},
|
|
245
315
|
}
|
package/dist/signer/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { redactSigner, type EvmCallRequest, type EvmSwarmSigner, type SolanaSwarmSigner, type SwarmSigner, } from "./types.js";
|
|
1
|
+
export { redactSigner, type EvmCallRequest, type EvmSwarmSigner, type EvmTransactionSigner, type SolanaSwarmSigner, type SwarmSigner, } from "./types.js";
|
|
2
2
|
export { fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, type SolanaWalletAdapterLike, } from "./solana.js";
|
|
3
3
|
export { fromEvmPrivateKey, fromEvmWalletClient, type EvmPrivateKeyOptions, type EvmWalletClientLike, } from "./evm.js";
|
package/dist/signer/solana.d.ts
CHANGED
|
@@ -8,10 +8,11 @@ export interface SolanaWalletAdapterLike {
|
|
|
8
8
|
signTransaction?: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Create a browser-clean `SolanaSwarmSigner` from a `@solana/web3.js` `Keypair
|
|
11
|
+
* Create a browser-clean `SolanaSwarmSigner` from a `@solana/web3.js` `Keypair`
|
|
12
|
+
* or a raw 64-byte `Uint8Array` secret key (e.g. `Uint8Array.from(JSON.parse(...))`).
|
|
12
13
|
* Secret key bytes stay trapped inside a private closure and are redacted from logs/JSON.
|
|
13
14
|
*/
|
|
14
|
-
export declare function fromSolanaKeypair(keypair: Keypair): SolanaSwarmSigner;
|
|
15
|
+
export declare function fromSolanaKeypair(keypair: Keypair | Uint8Array): SolanaSwarmSigner;
|
|
15
16
|
/**
|
|
16
17
|
* Create a `SolanaSwarmSigner` from a 64-byte `Uint8Array`, base58-encoded secret key,
|
|
17
18
|
* or JSON `[u8, ...]` array string (matching `solana-keygen` format).
|
package/dist/signer/solana.js
CHANGED
|
@@ -31,19 +31,46 @@ async function signEd25519Detached(secretKey64, message) {
|
|
|
31
31
|
return new Uint8Array(ix.data.subarray(sigOffset, sigOffset + 64));
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* Create a browser-clean `SolanaSwarmSigner` from a `@solana/web3.js` `Keypair
|
|
34
|
+
* Create a browser-clean `SolanaSwarmSigner` from a `@solana/web3.js` `Keypair`
|
|
35
|
+
* or a raw 64-byte `Uint8Array` secret key (e.g. `Uint8Array.from(JSON.parse(...))`).
|
|
35
36
|
* Secret key bytes stay trapped inside a private closure and are redacted from logs/JSON.
|
|
36
37
|
*/
|
|
37
38
|
export function fromSolanaKeypair(keypair) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
let resolved;
|
|
40
|
+
if (keypair instanceof Uint8Array) {
|
|
41
|
+
if (keypair.length !== 64) {
|
|
42
|
+
throw new SwarmClientError({
|
|
43
|
+
code: "INVALID_ARGUMENT",
|
|
44
|
+
operation: "signer.fromSolanaKeypair",
|
|
45
|
+
message: `Expected 64-byte Solana secret key, received ${keypair.length} bytes`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
resolved = Keypair.fromSecretKey(new Uint8Array(keypair));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new SwarmClientError({
|
|
53
|
+
code: "INVALID_ARGUMENT",
|
|
54
|
+
operation: "signer.fromSolanaKeypair",
|
|
55
|
+
message: "Invalid Solana Ed25519 secret key bytes",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
if (!keypair?.secretKey ||
|
|
61
|
+
keypair.secretKey.length !== 64 ||
|
|
62
|
+
!keypair.publicKey ||
|
|
63
|
+
typeof keypair.publicKey.toBase58 !== "function") {
|
|
64
|
+
throw new SwarmClientError({
|
|
65
|
+
code: "INVALID_ARGUMENT",
|
|
66
|
+
operation: "signer.fromSolanaKeypair",
|
|
67
|
+
message: "Expected a valid 64-byte Solana Keypair or Uint8Array",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
resolved = keypair;
|
|
44
71
|
}
|
|
45
|
-
const secretBytes = new Uint8Array(
|
|
46
|
-
const address =
|
|
72
|
+
const secretBytes = new Uint8Array(resolved.secretKey);
|
|
73
|
+
const address = resolved.publicKey.toBase58();
|
|
47
74
|
return redactSigner({
|
|
48
75
|
chain: "solana",
|
|
49
76
|
address,
|
package/dist/signer/types.d.ts
CHANGED
|
@@ -9,15 +9,18 @@ export interface EvmCallRequest {
|
|
|
9
9
|
to: `0x${string}`;
|
|
10
10
|
data: `0x${string}`;
|
|
11
11
|
value?: bigint;
|
|
12
|
+
chain?: string;
|
|
12
13
|
chainId?: number;
|
|
14
|
+
maxFeePerGas?: bigint;
|
|
13
15
|
}
|
|
14
16
|
export interface EvmSwarmSigner {
|
|
15
17
|
readonly chain: "evm";
|
|
16
18
|
readonly address: `0x${string}`;
|
|
17
|
-
readonly chainId?: number;
|
|
19
|
+
readonly chainId?: string | number;
|
|
18
20
|
signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
|
|
19
21
|
sendTransaction?(call: EvmCallRequest): Promise<`0x${string}`>;
|
|
20
22
|
}
|
|
23
|
+
export type EvmTransactionSigner = EvmSwarmSigner;
|
|
21
24
|
export type SwarmSigner = SolanaSwarmSigner | EvmSwarmSigner;
|
|
22
25
|
/**
|
|
23
26
|
* C6 Redaction: attach safe serialization and inspection hooks while freezing
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLIENT_VERSION = "0.4.
|
|
1
|
+
export declare const CLIENT_VERSION = "0.4.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.4.
|
|
1
|
+
export const CLIENT_VERSION = "0.4.4";
|
package/dist/vow/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { VowV1Attestation, AasV1Attestation, AccountDecoder, DecodedAccount, FailureReason, ProtocolHandler, StateResolver, Verdict, } from "./types.js";
|
|
2
2
|
export { anchorDiscriminator, bytesEqual } from "./discriminator.js";
|
|
3
3
|
export { checkSchema, asV1 } from "./schema.js";
|
|
4
|
-
export { verifyV1, verifyV1Schema,
|
|
4
|
+
export { DEFAULT_MAX_VOW_BYTES, DEFAULT_SCORE_MAX, fetchVowAttestationJson, validateVowUrl, verifyV1, verifyV1OnChain, verifyV1Schema, verifyVow, type FetchVowOptions, type VerifyVowOptions, } from "./verify.js";
|
|
5
5
|
export { decodeShillbotTask, resolveShillbotState, shillbotProtocol, } from "./decoders/shillbot.js";
|
|
6
6
|
export type { ExtensionRecord } from "./decoders/extension.js";
|
|
7
7
|
export { decodeExtension, resolveExtensionType, EXTENSION_ACCOUNT_KIND, EXTENSION_MIN_BODY_LEN, EXTENSION_ACTIVE_STATE, } from "./decoders/extension.js";
|
package/dist/vow/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { anchorDiscriminator, bytesEqual } from "./discriminator.js";
|
|
2
2
|
export { checkSchema, asV1 } from "./schema.js";
|
|
3
|
-
export { verifyV1, verifyV1Schema,
|
|
3
|
+
export { DEFAULT_MAX_VOW_BYTES, DEFAULT_SCORE_MAX, fetchVowAttestationJson, validateVowUrl, verifyV1, verifyV1OnChain, verifyV1Schema, verifyVow, } from "./verify.js";
|
|
4
4
|
export { decodeShillbotTask, resolveShillbotState, shillbotProtocol, } from "./decoders/shillbot.js";
|
|
5
5
|
export { decodeExtension, resolveExtensionType, EXTENSION_ACCOUNT_KIND, EXTENSION_MIN_BODY_LEN, EXTENSION_ACTIVE_STATE, } from "./decoders/extension.js";
|
package/dist/vow/verify.d.ts
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
import { Connection } from "@solana/web3.js";
|
|
2
|
+
import type { FetchLike } from "../http.js";
|
|
2
3
|
import type { AasV1Attestation, FailureReason, ProtocolHandler, Verdict } from "./types.js";
|
|
3
4
|
export declare const DEFAULT_SCORE_MAX = 1000000n;
|
|
5
|
+
/** Default maximum VOW attestation HTTP response size (`2 MiB`). */
|
|
6
|
+
export declare const DEFAULT_MAX_VOW_BYTES: number;
|
|
7
|
+
export interface FetchVowOptions {
|
|
8
|
+
fetch?: FetchLike;
|
|
9
|
+
/** Maximum response body size in bytes; default `2 * 1024 * 1024` (2 MiB). */
|
|
10
|
+
maxBytes?: number;
|
|
11
|
+
/** Explicitly opt in to `http://127.0.0.1`, `http://localhost`, or `http://[::1]` for local testing. */
|
|
12
|
+
allowLocalhostHttp?: boolean;
|
|
13
|
+
operation?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface VerifyVowOptions extends FetchVowOptions {
|
|
16
|
+
rpcUrl?: string;
|
|
17
|
+
connection?: Connection;
|
|
18
|
+
network?: "mainnet" | "devnet";
|
|
19
|
+
protocol?: ProtocolHandler;
|
|
20
|
+
expectedScoreMax?: bigint | number | string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validate a VOW attestation URL against SSRF, scheme downgrade, trailing-dot FQDN
|
|
24
|
+
* bypasses, internal/metadata suffixes, and private/loopback/link-local IP literals.
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateVowUrl(rawUrl: string, opts?: {
|
|
27
|
+
allowLocalhostHttp?: boolean;
|
|
28
|
+
operation?: string;
|
|
29
|
+
}): URL;
|
|
30
|
+
/**
|
|
31
|
+
* Safely fetch and JSON-decode a VOW v1 attestation document with `redirect: "error"`
|
|
32
|
+
* and a strict streaming byte cap (`DEFAULT_MAX_VOW_BYTES` = 2 MiB).
|
|
33
|
+
*/
|
|
34
|
+
export declare function fetchVowAttestationJson(rawUrl: string, opts?: FetchVowOptions): Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* High-level VOW v1 verifier accepting an HTTPS URL, JSON string, or parsed object.
|
|
37
|
+
* Enforces SSRF host/IP validation, `redirect: "error"`, and a 2 MiB streaming body cap.
|
|
38
|
+
*/
|
|
39
|
+
export declare function verifyVow(urlOrJson: string | Record<string, unknown>, opts?: VerifyVowOptions): Promise<Verdict>;
|
|
4
40
|
/**
|
|
5
41
|
* Step-by-step verifier per `docs/specs/vow-v1.md` §4.
|
|
6
42
|
*
|