Files
plm-lottery/plm_engine/electrum/scripthash.py
T
davideandClaude Sonnet 5.5 3ee60a23da B1: plm_engine takes the modules without a database (ADR-59)
HD derivation (pure part), PSBT builder, Electrum client/merkle/quorum/scripthash, network
profile, addresses and header checks move to plm_engine; the old stack imports them from
there. A test forbids framework imports in the package.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 15:31:47 +01:00

16 lines
627 B
Python

import hashlib
from embit.script import Script
def address_to_scripthash(address: str) -> str:
"""Electrum protocol scripthash: sha256(scriptPubKey), byte-reversed, hex.
Uses `.data` (the raw scriptPubKey bytes), not `.serialize()` — the latter
prefixes a compact-size length byte meant for embedding the script as pushdata
elsewhere (e.g. a P2SH redeemScript), which is not part of the actual on-chain
output script and produces a wrong (unmatchable) scripthash if used here.
"""
script_pubkey = Script.from_address(address).data
return hashlib.sha256(script_pubkey).digest()[::-1].hex()