Refactor ClawdbotClient challenge-response handling. Improved WebSocket state checks before sending responses and updated HMAC-SHA256 signing to include both nonce and timestamp. Enhanced logging for challenge response messages to aid in debugging.

This commit is contained in:
luccast
2026-01-25 19:31:52 -05:00
parent e793a46072
commit 265f8bcb1f
+13 -4
View File
@@ -103,21 +103,30 @@ export class ClawdbotClient {
return
}
// Sign the nonce with HMAC-SHA256
if (this.ws?.readyState !== WebSocket.OPEN) {
console.error('[clawdbot] WebSocket not open for challenge response')
return
}
// Sign nonce+timestamp with HMAC-SHA256
const message = `${challenge.nonce}:${challenge.ts}`
const signature = createHmac('sha256', this.token)
.update(challenge.nonce)
.update(message)
.digest('hex')
// Try format: type + connect params + challenge response
const response = {
type: 'connect',
...createConnectParams(this.token),
challenge: {
nonce: challenge.nonce,
ts: challenge.ts,
signature,
},
}
console.log('[clawdbot] Sending challenge response')
this.ws?.send(JSON.stringify(response))
console.log('[clawdbot] Sending challenge response:', JSON.stringify(response).slice(0, 300))
this.ws.send(JSON.stringify(response))
}
private handleMessage(