def scripthash_hex(script): return hash_to_hex_str(sha256(bytes(script)))
def get_bytes(self, n): while len(self.pool) < n: self.pool.extend(self.sha) self.sha = sha256(self.sha) result, self.pool = self.pool[:n], self.pool[n:] return result
def scripthash_bytes(script: Script) -> bytes: return sha256(bytes(script))
def __init__(self, seed): self.sha = sha256(seed) self.pool = bytearray()
def scripthash_hex(item): if isinstance(item, Address): item = item.to_script_bytes() return hash_to_hex_str(sha256(bytes(item)))
def _get_unique_identity_id(self, system_id: IdentitySystem, system_data: str) -> bytes: if system_id == IdentitySystem.OnChain: return bytes.fromhex(system_data) return sha256(system_data.encode('utf-8'))
def scripthash_bytes(script: Union[bytes, Script]) -> bytes: # NOTE(typing) Ignore passing a bytes object into the `bytes` builtin, as it is valid. return sha256(bytes(script)) # type: ignore
import pytest import scryptlib.utils import scryptlib.contract from scryptlib.types import Int, PubKey, Sig, SigHashPreimage, Ripemd160 import bitcoinx from bitcoinx import PrivateKey, TxOutput, SigHash, pack_byte, Script, sha256, PublicKey, int_to_be_bytes, hash160, TxInputContext, Tx, TxInput import ecdsa from hashlib import sha256 as sha256_hashlib secret = b'This is a secret message!' h_secret = sha256(secret) k = h_secret secret_wrong = b'This is the wrong secret message!' h_secret_wrong = sha256(secret_wrong) k_wrong = h_secret G = PublicKey.from_hex( '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798') Q = G.multiply(k) r, _ = Q.to_point() r = int_to_be_bytes(r) if r[0] & 0x80: r0 = pack_byte(0) + r else: r0 = r r_hash = hash160(r0)