mirror of
https://github.com/crabwise-ai/crabwalk.git
synced 2026-08-14 00:57:52 +00:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user