@swarm-tips/client 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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
+ }
@@ -1,4 +1,4 @@
1
- export declare const OPENAPI_VERSION: "0.4.2";
1
+ export declare const OPENAPI_VERSION: "0.4.4";
2
2
  export declare const OPENAPI_SERVERS: readonly ["https://mcp.swarm.tips", "https://api.shillbot.org", "https://api.coordination.game"];
3
3
  export type OpenApiServerUrl = (typeof OPENAPI_SERVERS)[number];
4
4
  export interface OpenApiSchemas {
@@ -1,6 +1,6 @@
1
1
  // AUTO-GENERATED by scripts/sync-generated.mjs from services/mcp-server/openapi.merged.json.
2
2
  // Do not edit by hand — run `pnpm --filter @swarm-tips/client sync:generated`.
3
- export const OPENAPI_VERSION = "0.4.2";
3
+ export const OPENAPI_VERSION = "0.4.4";
4
4
  export const OPENAPI_SERVERS = [
5
5
  "https://mcp.swarm.tips",
6
6
  "https://api.shillbot.org",
package/dist/http.js CHANGED
@@ -29,7 +29,7 @@ export class HttpClient {
29
29
  }
30
30
  async request(path, init = {}) {
31
31
  const operation = `${init.method ?? "GET"} ${path}`;
32
- const token = init.token ?? (await this.getToken?.());
32
+ const token = init.token !== undefined ? init.token : await this.getToken?.();
33
33
  const { token: _token, _retried, ...fetchInit } = init;
34
34
  const headers = {
35
35
  ...fetchInit.headers,
@@ -43,7 +43,7 @@ export declare class ShillbotApiClient {
43
43
  post<T>(path: string, body?: unknown): Promise<T>;
44
44
  patch<T>(path: string, body?: unknown): Promise<T>;
45
45
  listTasks<TTask = unknown>(limit?: number): Promise<TaskListResponse<TTask>>;
46
- getTask<TTask = unknown>(id: string): Promise<TTask>;
46
+ getTask<TTask = unknown>(id: string, network?: "mainnet" | "devnet"): Promise<TTask>;
47
47
  listAgentTasks<TTask = unknown>(): Promise<TTask[] | TaskListResponse<TTask>>;
48
48
  listPendingApproval<TTask = unknown>(): Promise<TTask[] | TaskListResponse<TTask>>;
49
49
  listCampaigns<TCampaign = unknown>(): Promise<TCampaign[] | CampaignListResponse<TCampaign>>;
@@ -38,10 +38,19 @@ export class ShillbotApiClient {
38
38
  return this.http.patch(path, body);
39
39
  }
40
40
  listTasks(limit = 50) {
41
- return this.get(`/tasks?limit=${encodeURIComponent(String(limit))}`);
41
+ return this.http.get(`/tasks?limit=${encodeURIComponent(String(limit))}`, null);
42
42
  }
43
- getTask(id) {
44
- return this.get(`/tasks/${encodeURIComponent(id)}`);
43
+ async getTask(id, network) {
44
+ const trimmed = id.trim();
45
+ if (!trimmed) {
46
+ throw new SwarmClientError({
47
+ code: "INVALID_ARGUMENT",
48
+ operation: "shillbot.getTask",
49
+ message: "Task id is required",
50
+ });
51
+ }
52
+ const suffix = network ? `?network=${encodeURIComponent(network)}` : "";
53
+ return this.http.get(`/tasks/${encodeURIComponent(trimmed)}${suffix}`, null);
45
54
  }
46
55
  listAgentTasks() {
47
56
  return this.get("/agent/tasks");
@@ -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).
@@ -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
- 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
- });
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(keypair.secretKey);
46
- const address = keypair.publicKey.toBase58();
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/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const CLIENT_VERSION = "0.4.3";
1
+ export declare const CLIENT_VERSION = "0.4.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLIENT_VERSION = "0.4.3";
1
+ export const CLIENT_VERSION = "0.4.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarm-tips/client",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Typed browser and Node.js clients for Swarm Tips, Shillbot, and Coordination Game",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",