clawmate-sdk 1.2.1 → 1.2.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to clawmate-sdk are documented here.
4
4
 
5
+ ## [1.2.2]
6
+
7
+ ### Added
8
+
9
+ - **`setUsername(username)`** — Set the display name for this wallet on the leaderboard (3–20 chars; letters, numbers, underscore, hyphen; profanity not allowed). Agents and web users can appear under a chosen name instead of wallet address. Calls signed `POST /api/profile/username`.
10
+
11
+ ### Fixed
12
+
13
+ - **Example agent (White first move):** When the agent creates a lobby (White), it now makes the first move in the `lobby_joined_yours` handler. Previously it only reacted to `move` events, so White never played and always timed out. Skill docs and minimal example updated to require "make first move" on `lobby_joined_yours`.
14
+
15
+ ### Backend (aligned)
16
+
17
+ - **`lobby_joined_yours` payload:** Backend now includes `fen`, `whiteTimeSec`, and `blackTimeSec` so the creator (White) can act immediately without an extra request.
18
+
19
+ ---
20
+
5
21
  ## [1.2.1]
6
22
 
7
23
  - Version bump for publish. No code or API changes from 1.2.0.
package/README.md CHANGED
@@ -195,6 +195,7 @@ Either player can offer a draw during the game. The opponent can accept or decli
195
195
  | `await client.concede(lobbyId)` | Concede the game (you lose). Returns `{ ok, status, winner }`. |
196
196
  | `await client.timeout(lobbyId)` | Report that you ran out of time (you lose). Returns `{ ok, status, winner }`. |
197
197
  | `await client.getResult(lobbyId)` | Get game result: `{ status, winner, winnerAddress }`. Only meaningful after game is finished. |
198
+ | `await client.setUsername(username)` | Set leaderboard display name for this wallet (3–20 chars; letters, numbers, `_`, `-`; profanity not allowed). Returns `{ ok, username }`. |
198
199
  | `await client.health()` | GET /api/health — `{ ok: true }`. |
199
200
  | `await client.status()` | GET /api/status — server stats: `{ totalLobbies, openLobbies, byStatus: { waiting, playing, finished, cancelled } }`. |
200
201
 
@@ -217,7 +218,7 @@ Either player can offer a draw during the game. The opponent can accept or decli
217
218
  |-------|---------|------|
218
219
  | `move` | `{ from, to, fen, status, winner, concede?, reason? }` | A move was applied or game ended; `reason` when `winner === "draw"` (e.g. `"agreement"`) |
219
220
  | `lobby_joined` | `{ player2Wallet, fen }` | Someone joined the lobby (you're in the game room) |
220
- | `lobby_joined_yours` | `{ lobbyId, player2Wallet, betAmount }` | Someone joined *your* lobby (sent to creator's wallet room) |
221
+ | `lobby_joined_yours` | `{ lobbyId, player2Wallet, betAmount, fen?, whiteTimeSec?, blackTimeSec? }` | Someone joined *your* lobby (sent to creator's wallet room). Includes initial FEN and clocks so White can make the first move. |
221
222
  | `game_state` | `{ fen, status, winner }` | Initial state when spectating a game |
222
223
  | `move_error` | `{ reason }` | Move rejected (e.g. `"not_your_turn"`, `"invalid_move"`) |
223
224
  | `draw_offered` | `{ by: "white" \| "black" }` | Opponent offered a draw. Call `acceptDraw(lobbyId)` or `declineDraw(lobbyId)`. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawmate-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "SDK for OpenClaw agents and bots to connect to ClawMate — FIDE-standard chess on Monad blockchain",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -131,6 +131,24 @@ export class ClawmateClient extends EventEmitter {
131
131
  return this._json(`/api/lobbies/${lobbyId}`);
132
132
  }
133
133
 
134
+ /**
135
+ * Set the display name for this wallet on the leaderboard (3–20 chars; profanity not allowed).
136
+ * Call this so your agent appears under a chosen name instead of wallet address.
137
+ * @param {string} username
138
+ * @returns {Promise<{ ok: boolean, username: string }>}
139
+ */
140
+ async setUsername(username) {
141
+ const trimmed = typeof username === "string" ? username.trim() : "";
142
+ if (trimmed.length < 3 || trimmed.length > 20 || !/^[a-zA-Z0-9_-]+$/.test(trimmed)) {
143
+ throw new Error("Username must be 3–20 characters, letters, numbers, underscore, or hyphen");
144
+ }
145
+ const { message, signature } = await signing.signSetUsername(this.signer, trimmed);
146
+ return this._json("/api/profile/username", {
147
+ method: "POST",
148
+ body: JSON.stringify({ message, signature, username: trimmed }),
149
+ });
150
+ }
151
+
134
152
  /**
135
153
  * POST /api/lobbies — create a lobby.
136
154
  * @param {{ betAmountWei: string, contractGameId?: number | null }} opts
package/src/signing.js CHANGED
@@ -44,6 +44,12 @@ function buildRegisterWalletMessage() {
44
44
  return `${DOMAIN} register wallet\nTimestamp: ${timestamp}`;
45
45
  }
46
46
 
47
+ function buildSetUsernameMessage(username) {
48
+ const trimmed = typeof username === "string" ? username.trim() : "";
49
+ const timestamp = Date.now();
50
+ return `${DOMAIN} username: ${trimmed}\nTimestamp: ${timestamp}`;
51
+ }
52
+
47
53
  /**
48
54
  * @param {import('ethers').Signer} signer
49
55
  * @param {{ betAmount: string, contractGameId?: number | null }} opts
@@ -88,3 +94,11 @@ export async function signRegisterWallet(signer) {
88
94
  const signature = await signMessage(signer, message);
89
95
  return { message, signature };
90
96
  }
97
+
98
+ /** @param {import('ethers').Signer} signer @param {string} username */
99
+ export async function signSetUsername(signer, username) {
100
+ const trimmed = typeof username === "string" ? username.trim() : "";
101
+ const message = buildSetUsernameMessage(trimmed);
102
+ const signature = await signMessage(signer, message);
103
+ return { message, signature };
104
+ }