Skip to content

Sign PSBT command#15

Merged
tiero merged 8 commits intomainfrom
feat/sign-digest-command
Feb 27, 2026
Merged

Sign PSBT command#15
tiero merged 8 commits intomainfrom
feat/sign-digest-command

Conversation

@tiero
Copy link
Owner

@tiero tiero commented Feb 24, 2026

This pull request introduces a new PSBT (Partially Signed Bitcoin Transaction) signing feature to the CLI, enabling secure Taproot multisig coordination. It also updates documentation and integrates new dependencies to support Bitcoin transaction parsing and signing. The main focus is on providing a safe, user-friendly way to sign Bitcoin transactions by parsing PSBTs and showing transaction details before signing, preventing blind signing attacks.

New PSBT Signing Feature

  • Added a new command cash sign-psbt to the CLI for signing PSBTs, supporting both base64 and hex input formats, and displaying transaction details before signing. The command securely signs Taproot script-path inputs and updates the PSBT with signatures, ready for multisig coordination. (cli/src/commands/sign-psbt.ts, cli/src/index.ts, cli/README.md) [1] [2] [3] [4] [5]

  • Updated the CLI help and documentation to describe the new sign-psbt command, its usage, output format, and security rationale, emphasizing PSBT-aware signing as the recommended method. (cli/README.md, cli/src/index.ts) [1] [2]

Dependency and Package Management

  • Added new dependencies to support PSBT parsing and signing: @scure/base, @scure/btc-signer, and @noble/secp256k1 in both package.json and pnpm-lock.yaml, ensuring the CLI can handle advanced Bitcoin transaction formats. (cli/package.json, package.json, pnpm-lock.yaml) [1] [2] [3] [4]

aetos53t and others added 7 commits February 18, 2026 17:42
Add 'cash sign-digest <hex>' command that signs a raw 32-byte digest
with the wallet's Schnorr key (BIP-340).

CLI Command (cli/src/commands/sign-digest.ts):
- Input validation (hex format, 64 char length)
- Normalization (strip 0x prefix, lowercase)
- Support for positional arg and --hex/--digest flags
- Detailed error messages with usage hints
- Daemon fallback when not running
- Proper ClwApiError handling

Daemon Route (cli/src/server.ts):
- POST /sign-digest endpoint
- Same validation as CLI
- Consistent response format with signatureFormat field

Unit Tests (test/sign-digest.test.ts):
- Missing digest rejection
- Invalid hex rejection
- Wrong length rejection (too short/long)
- 0x prefix handling
- --hex and --digest flag support
- Digest normalization
- Signature format validation

E2E Tests (test/e2e.test.ts):
- signDigest() combines sign-intent + sign in one call
- signDigest() signature is valid BIP-340 Schnorr (cryptographic verification)
- signDigest() with 0x prefix works
- signDigest() with invalid digest length throws

Usage:
  cash sign-digest e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
  cash sign-digest --hex 0xabc123...

Returns:
  {
    "digest": "...",
    "signature": "...",
    "publicKey": "...",
    "signatureFormat": "BIP-340 Schnorr (64 bytes)"
  }

Use case: Multi-agent Taproot multisig coordination where each agent
signs their BIP-341 sighash independently, then a coordinator
assembles the witness with OP_CHECKSIGADD.

All 61 tests pass (including cryptographic signature verification).
Tests:
- Replace stub tests with complete assertions
- Add input validation tests (missing, invalid, wrong length)
- Add digest normalization tests (0x prefix, uppercase, mixed case)
- Add input parsing tests (positional, --hex, --digest flags)
- Add BIP-340 format validation tests
- Add daemon route integration tests

Docs:
- Add sign-digest to command table
- Add dedicated section with usage examples
- Document output format and use cases
Addresses feedback from tiero - adds a safer alternative to sign-digest:
- Parses PSBT to show transaction details before signing
- Computes sighash automatically for each input
- Returns updated PSBT with signatures added
- Uses same scure-btc-signer library

The sign-psbt command is recommended over sign-digest for production use
as it prevents blind signing attacks.
Per tiero's feedback:
- Remove sign-digest CLI command (prevents blind signing temptation)
- Remove /sign-digest daemon route
- Keep SDK signDigest method (used internally by sign-psbt)
- Add comprehensive sign-psbt unit tests with test vectors
- Add sign-psbt e2e tests for full scenario testing

sign-psbt is the recommended way to sign - it parses the PSBT,
shows transaction details, and prevents blind signing attacks.
- Add @scure/btc-signer and @scure/base as CLI dependencies
- Add @scure/btc-signer and @scure/base as root dev dependencies for tests
- Fix import path for tapLeafHash (@scure/btc-signer/payment.js)
- Update tapLeafScript access for v2 API (tuple format)
- Update tapScriptSig format for v2 API

All 68 tests pass.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 27, 2026

Deploying claw-cash-landing-page with  Cloudflare Pages  Cloudflare Pages

Latest commit: cddd673
Status: ✅  Deploy successful!
Preview URL: https://1758524e.claw-cash-landing-page.pages.dev
Branch Preview URL: https://feat-sign-digest-command.claw-cash-landing-page.pages.dev

View logs

@tiero tiero merged commit d3d9744 into main Feb 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants