bitcoin-message-signing
Generic Bitcoin message signing: BIP137 (legacy P2PKH-only) and BIP322 (modern, supports any output type). Used for proof-of-ownership, withdraw verification, federated authentication, exchange KYC-free attestation. USE WHEN: implementing "sign this message with your Bitcoin address", verifying ownership of an address, building auth via signing.
What this skill does
# Bitcoin Message Signing
Two specifications:
- **BIP137** (Hourglass) — legacy. Works only for P2PKH (uncompressed
or compressed). Output: 65-byte recoverable ECDSA + Base64.
- **BIP322** (modern) — works for any output type (P2PKH, P2WPKH,
P2WSH, P2TR, even script-only). Output: a virtual PSBT-like
signature.
## BIP137 (legacy)
```
prefix = "Bitcoin Signed Message:\n"
preamble = varint(len(prefix)) || prefix || varint(len(msg)) || msg
hash = SHA256d(preamble)
signature = recoverable_ecdsa_sign(privkey, hash) # 65 bytes
encoded = base64(signature)
```
Verify: recover pubkey from signature, derive P2PKH address, compare.
**Limitations**:
- Only P2PKH. Cannot prove ownership of a SegWit / Taproot address.
- Wallets don't always agree on the prefix (some include trailing
newline, others don't).
- Recoverable ECDSA implies pubkey isn't directly transmitted.
## BIP322 (modern)
Generalizes signing by constructing a **virtual transaction**:
```
to_spend = transaction with:
version=0, locktime=0,
vin = [{ prevout: 0xffffffff..., scriptSig: OP_0 PUSH msg_hash, sequence: 0 }],
vout = [{ value: 0, scriptPubKey: <message-target scriptPubKey> }]
to_sign = transaction with:
version=0, locktime=0,
vin = [{ prevout: txid_of_to_spend, vout: 0, sequence: 0 }],
vout = [{ value: 0, scriptPubKey: OP_RETURN }]
```
Then sign `to_sign` as a normal transaction spending `to_spend`'s
output. The signature can be:
- A full BIP322 signature with witness data, OR
- A "simple" form where only the witness/scriptSig is encoded.
### Address types supported
- P2PKH, P2SH-anything, P2WPKH, P2WSH, P2TR.
- Multi-key: produce multiple sigs across signers and combine into one
BIP322 witness.
- Even script-only addresses (no key) can produce a "proof of
knowledge" of preimage.
## Encoded forms
- **BIP322 simple** — Base64 of a witness stack only. Suitable for
P2WPKH/P2WSH/P2TR.
- **BIP322 full** — Base64 of `to_sign` PSBT-like blob. Required for
P2SH or anything with non-witness data.
## Verification flow
```python
def verify_bip322(address, message, signature_b64):
spk = address_to_scriptPubKey(address)
msg_hash = bip322_hash(message)
to_spend = build_to_spend(spk, msg_hash)
to_sign = build_to_sign(to_spend)
apply_signature(to_sign, signature_b64)
return script_executes_successfully(to_sign, vin[0])
```
## Common use cases
- **Exchange withdraw verification** — "prove you own the destination
before we send".
- **Federated/KYC-free login** — sign a server-issued nonce with the
Bitcoin address you want to associate with the account.
- **Off-chain attestation** — sign a public commitment.
- **DLC oracle attestation** — adapter signatures + BIP322.
## Library support
- `bitcoinjs-lib` (since 6.x) — BIP322 sign/verify.
- `python-bitcoinlib` — BIP137 native, BIP322 via plugin.
- `rust-bitcoin` — BIP322 in `signed-message` crate.
- `bitcoinj` — BIP137; BIP322 incomplete.
## Common bugs
- Mixing BIP137 prefix conventions across wallets — verify with the
same library/wallet that signed where possible.
- Trying to BIP137-sign a SegWit address by deriving an arbitrary
P2PKH from the same key → semantically wrong; use BIP322 instead.
- For Taproot: the witness stack must use `SIGHASH_DEFAULT` to be
byte-identical to a real Taproot spend; some libraries default to
`SIGHASH_ALL` (0x01) which encodes a different sighash.
## See also
- [psbt/SKILL.md](../psbt/SKILL.md)
- [../../wallets/hd/SKILL.md](../../wallets/hd/SKILL.md)
- [../../cryptography/schnorr/SKILL.md](../../cryptography/schnorr/SKILL.md)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.