Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Diagnose and troubleshoot bitcoin-auth token generation and verification issues. This skill should be used when users encounter authentication failures, signature verification errors, or integration problems with the bitcoin-auth library.
.claude/skills/microck-bitcoin-auth-diagnostics/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-08 | ✗→✓ | ▲ Improved | 71% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 135% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 39% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 100% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 29% | 0% |
This skill enables comprehensive diagnosis of bitcoin-auth authentication issues across client and server implementations. Use this skill when encountering token generation failures, signature verification errors, or integration problems with the bitcoin-auth library.
Use this skill when:
All bitcoin-auth tokens follow this pipe-delimited format:
pubkey|scheme|timestamp|requestPath|signatureComponents:
pubkey: Hex-encoded public key (66 characters)scheme: Either bsm (legacy) or brc77 (recommended)timestamp: ISO8601 format (e.g., 2025-01-15T14:30:00.000Z)requestPath: Full path including query parameters (e.g., /api/endpoint?param=value)signature: Base64-encoded signatureExample valid token:
02a1b2c3d4e5f6...|brc77|2025-01-15T14:30:00.123Z|/api/status|dGVzdHNpZ25hdHVyZQ==First, validate the token structure before checking cryptographic validity:
typescriptimport { parseAuthToken } from 'bitcoin-auth'; const token = "..."; // The failing token const parsed = parseAuthToken(token); if (!parsed) { console.error("FAILED: Token structure is invalid"); // Check: Does token have exactly 5 pipe-delimited parts? const parts = token.split('|'); console.log(`Token has ${parts.length} parts (expected 5)`); console.log("Parts:", parts); // Common issues: // - Missing parts (incomplete token) // - Extra pipes in requestPath or other fields // - Invalid scheme (not 'bsm' or 'brc77') } else { console.log("✅ Token structure is valid"); console.log("Parsed token:", parsed); }
Validate each component individually:
typescriptconst { pubkey, scheme, timestamp, requestPath, signature } = parsed; // Validate public key console.log("Public key length:", pubkey.length); // Should be 66 chars console.log("Public key starts with 02/03:", pubkey.startsWith('02') || pubkey.startsWith('03')); // Validate scheme console.log("Scheme:", scheme); // Must be 'bsm' or 'brc77' // Validate timestamp const tokenTime = new Date(timestamp); console.log("Token timestamp:", tokenTime.toISOString()); console.log("Current time:", new Date().toISOString()); console.log("Age (minutes):", (Date.now() - tokenTime.getTime()) / 60000); // Default timePad is 5 minutes - token older than 5 minutes will fail // Validate request path console.log("Request path:", requestPath); // Must match EXACTLY including query parameters and their order // Validate signature console.log("Signature (base64):", signature); console.log("Signature length:", signature.length);
If structure is valid, diagnose verification failures:
typescriptimport { verifyAuthToken } from 'bitcoin-auth'; import type { AuthPayload } from 'bitcoin-auth'; const authPayload: AuthPayload = { requestPath: "/api/endpoint?param=value", // Must match token exactly timestamp: new Date().toISOString(), // Server's current time body: requestBody // Optional, must match if token was signed with body }; const isValid = verifyAuthToken( token, authPayload, 5, // timePad in minutes (default 5) 'utf8' // bodyEncoding: 'utf8', 'hex', or 'base64' ); if (!isValid) { console.error("FAILED: Signature verification failed"); // Diagnose specific failures: // 1. Request path mismatch if (parsed.requestPath !== authPayload.requestPath) { console.error("❌ Request path mismatch:"); console.error(" Token path:", parsed.requestPath); console.error(" Verify path:", authPayload.requestPath); // Common issue: Query parameter order differs } // 2. Timestamp issues const tokenTimestamp = new Date(parsed.timestamp); const targetTime = new Date(authPayload.timestamp); targetTime.setMinutes(targetTime.getMinutes() + 5); // Add timePad if (tokenTimestamp > targetTime) { console.error("❌ Token timestamp too far in future"); console.error(" Token time:", tokenTimestamp.toISOString()); console.error(" Target time:", targetTime.toISOString()); } // 3. Body hash mismatch if (authPayload.body) { console.log("Verifying with body present"); console.log(" Body encoding:", 'utf8'); // Check encoding matches console.log(" Body length:", authPayload.body.length); // Try different encodings if utf8 fails } // 4. Scheme-specific issues if (parsed.scheme === 'bsm') { console.log("Using legacy BSM signature scheme"); // BSM uses different signature format than BRC77 } else { console.log("Using BRC77 signature scheme (recommended)"); } }
Check for common integration mistakes:
Server-side (verification):
typescript// ❌ WRONG: Using token's timestamp (defeats the purpose) const authPayload = { requestPath, timestamp: parsedToken.timestamp, // DON'T DO THIS body }; // ✅ CORRECT: Use server's current time const serverTime = new Date().toISOString(); const authPayload = { requestPath, timestamp: serverTime, body };
Client-side (generation):
typescript// ✅ Token generation import { getAuthToken } from 'bitcoin-auth'; const token = getAuthToken({ privateKeyWif, requestPath: '/api/endpoint?param=value', // Include full path with query body: JSON.stringify(requestBody), // If POST/PUT with body scheme: 'brc77', // Default, recommended bodyEncoding: 'utf8' // Default }); // Include in request headers fetch(url + requestPath, { method: 'POST', headers: { 'X-Auth-Token': token, 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody) });
Cause: Token doesn't have exactly 5 pipe-delimited parts
Solutions:
Cause: Signature doesn't match the payload
Solutions:
Cause: Token timestamp too far from server time
Solutions:
Cause: Token requestPath doesn't match verification path
Solutions:
Cause: Body used for signing doesn't match verification body
Solutions:
When working with Sigma Auth (auth.sigmaidentity.com), common patterns:
Token verification endpoint:
typescript// POST /api/auth/token-for-endpoint // Body: { authToken: "...", requestBody: "..." } // Server parses and verifies: const parsed = parseAuthToken(authToken); const authPayload = { requestPath: "/api/auth/token-for-endpoint", timestamp: new Date().toISOString(), body: requestBody }; const isValid = verifyAuthToken(authToken, authPayload);
Wallet connect flow:
typescript// Uses BSM scheme for compatibility const token = getAuthToken({ privateKeyWif, requestPath: "/wallet/connect", scheme: 'bsm' });
For detailed API documentation and implementation examples, see:
references/bitcoin-auth-api.md - Complete API referencereferences/common-issues.md - Detailed troubleshooting guide@bsv/sdk peer dependencybun add bitcoin-authNever log private keys or WIF strings - Only log public keys, tokens, and diagnostic information.
When diagnosing authentication issues:
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-08 | fail→pass | 11,832 | 4,791 | -60% | 1 | 1 | 0% | 1,950 | 3,336 | +71% | 0 | 0 | — |
case-09 | fail→pass | 9,281 | 6,921 | -25% | 1 | 1 | 0% | 1,550 | 3,640 | +135% | 0 | 0 | — |
case-01 | fail→pass | 23,080 | 17,248 | -25% | 1 | 1 | 0% | 4,305 | 5,975 | +39% | 0 | 0 | — |
case-02 | fail→fail | 22,905 | 19,016 | -17% | 1 | 1 | 0% | 3,766 | 6,054 | +61% | 0 | 0 | — |
case-03 | fail→fail | 24,897 | 18,478 | -26% | 1 | 1 | 0% | 4,270 | 5,957 | +40% | 0 | 0 | — |
case-04 | pass→pass | 14,786 | 9,616 | -35% | 1 | 1 | 0% | 2,540 | 4,426 | +74% | 0 | 0 | — |
case-05 | pass→pass | 13,069 | 6,980 | -47% | 1 | 1 | 0% | 2,416 | 3,670 | +52% | 0 | 0 | — |
case-06 | fail→pass | 14,053 | 10,240 | -27% | 1 | 1 | 0% | 2,188 | 4,380 | +100% | 0 | 0 | — |
case-07 | pass→pass | 12,161 | 11,135 | -8% | 1 | 1 | 0% | 1,918 | 4,496 | +134% | 0 | 0 | — |
case-10 | fail→pass | 34,017 | 3,957 | -88% | 1 | 1 | 0% | 2,477 | 3,200 | +29% | 0 | 0 | — |
case-11 | fail→pass | 8,050 | 4,025 | -50% | 1 | 1 | 0% | 1,203 | 3,143 | +161% | 0 | 0 | — |
case-12 | fail→pass | 11,533 | 1,439 | -88% | 1 | 1 | 0% | 1,878 | 2,692 | +43% | 0 | 0 | — |
case-13 | fail→pass | 14,384 | 14,018 | -3% | 1 | 1 | 0% | 2,500 | 4,916 | +97% | 0 | 0 | — |
case-14 | pass→pass | 12,033 | 7,021 | -42% | 1 | 1 | 0% | 2,091 | 3,773 | +80% | 0 | 0 | — |
case-15 | pass→pass | 14,084 | 9,611 | -32% | 1 | 1 | 0% | 2,160 | 4,025 | +86% | 0 | 0 | — |
case-16 | pass→pass | 14,515 | 9,679 | -33% | 1 | 1 | 0% | 2,395 | 4,017 | +68% | 0 | 0 | — |
case-17 | fail→pass | 8,937 | 2,953 | -67% | 1 | 1 | 0% | 1,445 | 2,953 | +104% | 0 | 0 | — |
case-18 | fail→pass | 6,262 | 3,115 | -50% | 1 | 1 | 0% | 1,120 | 2,946 | +163% | 0 | 0 | — |
case-19 | pass→pass | 14,172 | 6,778 | -52% | 1 | 1 | 0% | 2,403 | 3,711 | +54% | 0 | 0 | — |
case-20 | pass→pass | 11,334 | 10,760 | -5% | 1 | 1 | 0% | 2,138 | 4,584 | +114% | 0 | 0 | — |
case-21 | pass→pass | 15,161 | 8,761 | -42% | 1 | 1 | 0% | 2,646 | 3,998 | +51% | 0 | 0 | — |
case-22 | pass→pass | 15,379 | 13,066 | -15% | 1 | 1 | 0% | 3,003 | 5,007 | +67% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +45 percentage points is the difference between those two pass rates over the 21 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.