---
name: bawdesk-sync
description: Automatically track and sync all past and present works done with your Binance .ai & BAW agentic wallet to BawDesk with strict Zero-Knowledge AES-256-GCM End-to-End Encryption (E2EE) so even the server/owner cannot read private works.
homepage: https://bawdesk.xyz/
---

# BawDesk Auto-Sync Skill (`bawdesk-sync`) — Zero-Knowledge E2EE

You are connected to **BawDesk** — the privacy-first Mission Control Desk for Binance `.ai` & BAW agentic wallets on BNB Smart Chain (`chainId 56`).

**Privacy Rule (Strict Zero-Knowledge E2EE):**
- **Every private work MUST be encrypted locally with AES-256-GCM** using the user's `vaultKey` *before* sending to BawDesk.
- **NEVER send `vaultKey` to BawDesk servers** and **NEVER print `syncToken` or `vaultKey` in chat**.
- BawDesk servers reject plaintext private works (`400 E2EE_REQUIRED`). Only opaque ciphertext (`v1.<ivBase64>.<ctBase64>`) is stored in the database — neither BawDesk nor its owner can read private works.

---

## Base Endpoints & On-Chain Constants

- **BawDesk API Base:** `https://bawdesk.xyz` *(fallback: `https://bawdesk.agentperp.workers.dev`)*
- **On-Chain Registry (BSC Mainnet `chainId 56`):** `0xf0385f3Cd1fAe51Fa754bFEddB3Bba5ea3b56200` (`exact_match` on Sourcify)
- **Binance `.ai` Registry:** `0x60B9262456dE011F7d15a54CdD8c48bAaa8B022F`
- **$AGC Token:** `0x63dea5aCdbE1F27c968907D08610A5f0A0284bA6`

---

## Step 1: Installation & Local E2EE Credentials

When the user pastes a **Link Agent Prompt** from BawDesk:

1. **Install this skill** into your persistent skills directory:
   - OpenClaw: `~/.openclaw/skills/bawdesk-sync/SKILL.md`
   - Claude Code / Codex / Cursor: `~/.claude/skills/bawdesk-sync/SKILL.md` or `.agents/skills/bawdesk-sync/SKILL.md`

2. **Identify the user's `.ai` / BAW wallet** and (if `baw` is available) sign the 0-gas EIP-712 `BawDeskLink` typed data (`domain: BawDesk v1 chainId 56 verifyingContract 0xf0385f3Cd1fAe51Fa754bFEddB3Bba5ea3b56200`).

3. **Claim the pairing** (DO NOT include `vaultKey` in this HTTP call!):
   ```bash
   curl -s -X POST https://bawdesk.xyz/api/pair/claim \
     -H "Content-Type: application/json" \
     -d '{
       "pairId": "<pairId>",
       "address": "<0xWalletAddress>",
       "handle": "<name.ai>",
       "signature": "<optional 0x EIP-712 signature>",
       "agentPlatform": "<e.g. OpenClaw / Claude / Codex>"
     }'
   ```

4. **Save credentials locally** to `~/.bawdesk/config.json` (`chmod 600` if on Unix):
   ```json
   {
     "apiBase": "https://bawdesk.xyz",
     "wallet": "0x...",
     "handle": "name.ai",
     "syncToken": "ah_sync_...",
     "vaultKey": "bdvk_<64_hex_chars_from_user_prompt>"
   }
   ```

---

## Step 2: Local AES-256-GCM Encryption Helper (Zero Dependencies)

Before sending any private work to `/api/works/bulk` or `/api/works/upsert`, encrypt its JSON payload locally using `vaultKey` (`v1.<ivBase64>.<ctPlusAuthTagBase64>`) and blind its `externalKey` with SHA-256 so even project names never leak!

### Node.js Reference (built-in `crypto`, zero npm packages):
```js
const crypto = require("crypto");

function keyBytes(vaultKey) {
  const hex = vaultKey.replace(/^bdvk_/i, "").trim();
  return Buffer.from(hex, "hex"); // 32 bytes (256-bit)
}

function blindExternalKey(vaultKey, rawKey) {
  return "ek_" + crypto.createHash("sha256").update(`${vaultKey}:${rawKey}`).digest("hex").slice(0, 24);
}

function encryptE2EE(vaultKey, obj) {
  const iv = crypto.randomBytes(12);
  const cipher = crypto.createCipheriv("aes-256-gcm", keyBytes(vaultKey), iv);
  const ct = Buffer.concat([cipher.update(JSON.stringify(obj), "utf8"), cipher.final()]);
  const tag = cipher.getAuthTag(); // 16-byte GCM auth tag appended (WebCrypto compatible!)
  return `v1.${iv.toString("base64")}.${Buffer.concat([ct, tag]).toString("base64")}`;
}

function buildEncryptedWork(vaultKey, rawKey, status, details) {
  return {
    externalKey: blindExternalKey(vaultKey, rawKey),
    status, // "present" | "past" | "paused" | "failed"
    encrypted: true,
    isPublic: false,
    ciphertext: encryptE2EE(vaultKey, details),
    eventCiphertext: details.statusNote ? encryptE2EE(vaultKey, { note: details.statusNote }) : "",
    startedAt: details.startedAt,
    completedAt: details.completedAt,
  };
}
```

### Plaintext Payload Shape (Encrypted Inside `ciphertext`):
```json
{
  "rawExternalKey": "agentperp-agcbnb-long-42",
  "category": "trading",
  "title": "AGCBNB 5x Long Position (#42)",
  "summary": "Opened 5x leveraged long on AgentPerp DEX V3 with TP/SL configured.",
  "protocol": "AgentPerp DEX V3",
  "chain": "BSC",
  "invested": "50,000 AGC",
  "currentValue": "58,400 AGC",
  "pnl": "+8,400 AGC",
  "pnlPct": 16.8,
  "statusNote": "Active — TP set at +25%, SL at -10%.",
  "txHashes": ["0x..."],
  "links": [{"label": "AgentPerp DEX", "url": "https://agentperpdex.xyz/"}],
  "tags": ["perps", "long", "AGC"]
}
```
Valid `category` values: `"trading"`, `"token_sale"`, `"lp_yield"`, `"airdrop_quest"`, `"deploy_build"`, `"swap_transfer"`, `"automation"`, `"other"`.

---

## Step 3: Initial Full Audit & Backfill (Run Immediately After Linking!)

1. Audit ALL **Past Works** (closed trades, swaps, deployments, claimed rewards, finished campaigns) and **Present Works** (open trading positions, active token sales/presales, active LPs, pending unlocks, running automations) done with the user's `.ai` wallet.
2. Encrypt every work item locally using `buildEncryptedWork(vaultKey, rawKey, status, details)`.
3. Push all encrypted items in one batch to `POST https://bawdesk.xyz/api/works/bulk` (`Authorization: Bearer <syncToken>`, body `{ "works": [ ... ] }`).
4. Reply to the user with ONLY:
   - Their **6-character Confirmation Code (`BD-XXXXXX`)**
   - A brief summary count of encrypted Present & Past works synced.

---

## Step 4: Ongoing Auto-Reporting Rule (Always Active!)

Whenever you start, update, or finish ANY work with the user's `.ai` wallet going forward:
- Load `syncToken` and `vaultKey` from `~/.bawdesk/config.json`.
- Encrypt the updated work object with the same `rawKey` (so `blindExternalKey` stays identical and updates cleanly in place without duplicates!).
- Send to `POST https://bawdesk.xyz/api/works/upsert` (`Authorization: Bearer <syncToken>`).

---

## Step 5 (Optional): On-Chain Pro Upgrade & Work Proof Anchoring

Core E2EE tracking (up to 100 works) is **100% free & zero-gas**. Optional **BawDesk Pro** (`10,000 AGC`) & **On-Chain Work Proof Anchoring** (`1,000 AGC`) on `0xf0385f3Cd1fAe51Fa754bFEddB3Bba5ea3b56200` atomically burn **70% `$AGC` to `0x…dEaD`** and send **30% to treasury**. Zero user-fund custody.
