예제 #1
0
def segwit_multisign(tx, i, script, pk, amount, hashcode=SIGHASH_ALL, separator_index=None):
    wscript = segwit_strip_script_separator(script, index=separator_index)
    signing_tx = segwit_signature_form(tx, i, wscript, amount, hashcode=hashcode)
    rawsig = ecdsa_raw_sign(hashlib.sha256(hashlib.sha256(
        binascii.unhexlify(signing_tx)).digest()).hexdigest(), pk)
    sig = der_encode_sig(*rawsig)+encode(hashcode, 16, 2)
    return sig
예제 #2
0
def segwit_sign(tx,
                i,
                priv,
                amount,
                hashcode=SIGHASH_ALL,
                script=None,
                separator_index=None):
    i = int(i)
    txobj = tx if isinstance(tx, dict) else deserialize(tx)
    if not isinstance(tx, dict) and ((not is_python2 and isinstance(re, bytes))
                                     or not re.match('^[0-9a-fA-F]*$', tx)):
        return binascii.unhexlify(sign(binascii.hexlify(tx), i, priv))
    if len(priv) <= 33:
        priv = binascii.hexlify(priv)
    pub = privkey_to_pubkey(priv)
    address = pubkey_to_address(pub)
    wscript = mk_pubkey_script(address) if not script else script
    stripped_script = segwit_strip_script_separator(wscript, separator_index)
    signing_tx = segwit_signature_form(tx,
                                       i,
                                       stripped_script,
                                       amount,
                                       hashcode=hashcode)
    rawsig = ecdsa_raw_sign(
        hashlib.sha256(
            hashlib.sha256(
                binascii.unhexlify(signing_tx)).digest()).hexdigest(), priv)
    sig = der_encode_sig(*rawsig) + encode(hashcode, 16, 2)
    txobj['ins'][i]['txinwitness'] = [sig, pub if not script else script]
    return serialize(txobj)
예제 #3
0
def make_tx_signatures(txs_to_sign, privkey, pubkey):
    signatures = []
    public = []
    for tx_to_sign in txs_to_sign:
        sig = der_encode_sig(
            *ecdsa_raw_sign(tx_to_sign.rstrip(' \t\r\n\0'), privkey))
        signatures.append(sig)
        public.append(pubkey)
    return signatures, public
예제 #4
0
def bech32_multisign(tx, i, priv, amount, script, hashcode=SIGHASH_ALL):
    from bitcoin import segwit_signature_form, ecdsa_raw_sign, der_encode_sig
    i = int(i)
    if len(priv) <= 33:
        priv = binascii.hexlify(priv)
    signing_tx = segwit_signature_form(tx,
                                       i,
                                       script,
                                       amount,
                                       hashcode=hashcode)
    rawsig = ecdsa_raw_sign(
        hashlib.sha256(
            hashlib.sha256(
                binascii.unhexlify(signing_tx)).digest()).hexdigest(), priv)
    sig = der_encode_sig(*rawsig) + encode(hashcode, 16, 2)
    return sig
예제 #5
0
def segwit_sign(tx, i, priv, amount, hashcode=SIGHASH_ALL, script=None, separator_index=None):
    i = int(i)
    txobj = tx if isinstance(tx, dict) else deserialize(tx)
    if not isinstance(tx, dict) and ((not is_python2 and isinstance(re, bytes)) or not re.match('^[0-9a-fA-F]*$', tx)):
        return binascii.unhexlify(sign(binascii.hexlify(tx), i, priv))
    if len(priv) <= 33:
        priv = binascii.hexlify(priv)
    pub = privkey_to_pubkey(priv)
    address = pubkey_to_address(pub)
    wscript = mk_pubkey_script(address) if not script else script
    stripped_script = segwit_strip_script_separator(wscript, separator_index)
    signing_tx = segwit_signature_form(tx, i, stripped_script, amount, hashcode=hashcode)
    rawsig = ecdsa_raw_sign(hashlib.sha256(hashlib.sha256(binascii.unhexlify(signing_tx)).digest()).hexdigest(), priv)
    sig = der_encode_sig(*rawsig)+encode(hashcode, 16, 2)
    txobj['ins'][i]['txinwitness'] = [sig, pub if not script else script]
    return serialize(txobj)
예제 #6
0
def segwit_multisign(tx,
                     i,
                     script,
                     pk,
                     amount,
                     hashcode=SIGHASH_ALL,
                     separator_index=None):
    wscript = segwit_strip_script_separator(script, index=separator_index)
    signing_tx = segwit_signature_form(tx,
                                       i,
                                       wscript,
                                       amount,
                                       hashcode=hashcode)
    rawsig = ecdsa_raw_sign(
        hashlib.sha256(
            hashlib.sha256(
                binascii.unhexlify(signing_tx)).digest()).hexdigest(), pk)
    sig = der_encode_sig(*rawsig) + encode(hashcode, 16, 2)
    return sig
예제 #7
0
def bech32_sign(tx, i, priv, amount, script=None, hashcode=SIGHASH_ALL):
    from bitcoin import deserialize, segwit_signature_form, ecdsa_raw_sign, der_encode_sig, serialize, compress
    i = int(i)
    txobj = tx if isinstance(tx, dict) else deserialize(tx)
    if len(priv) <= 33:
        priv = binascii.hexlify(priv)
    pub = compress(privkey_to_pubkey(priv))
    script = script or ('76a914' + hash160(binascii.unhexlify(pub)) + '88ac')
    signing_tx = segwit_signature_form(tx,
                                       i,
                                       script,
                                       amount,
                                       hashcode=hashcode)
    rawsig = ecdsa_raw_sign(
        hashlib.sha256(
            hashlib.sha256(
                binascii.unhexlify(signing_tx)).digest()).hexdigest(), priv)
    sig = der_encode_sig(*rawsig) + encode(hashcode, 16, 2)
    txobj['ins'][i]['txinwitness'] = [sig, pub]
    return serialize(txobj)
예제 #8
0
def sign_donation_tx(tx, i, priv):
	k = sign_k
	hashcode = btc.SIGHASH_ALL
	i = int(i)
	if len(priv) <= 33:
		priv = btc.safe_hexlify(priv)
	pub = btc.privkey_to_pubkey(priv)
	address = btc.pubkey_to_address(pub)
	signing_tx = btc.signature_form(tx, i, btc.mk_pubkey_script(address), hashcode)

	msghash = btc.bin_txhash(signing_tx, hashcode)
	z = btc.hash_to_int(msghash)
	#k = deterministic_generate_k(msghash, priv)
	r, y = btc.fast_multiply(btc.G, k)
	s = btc.inv(k, btc.N) * (z + r*btc.decode_privkey(priv)) % btc.N
	rawsig = 27+(y % 2), r, s

	sig =  btc.der_encode_sig(*rawsig)+btc.encode(hashcode, 16, 2)
	#sig = ecdsa_tx_sign(signing_tx, priv, hashcode)
	txobj = btc.deserialize(tx)
	txobj["ins"][i]["script"] = btc.serialize_script([sig, pub])
	return btc.serialize(txobj)
예제 #9
0
def sign_donation_tx(tx, i, priv):
    k = sign_k
    hashcode = btc.SIGHASH_ALL
    i = int(i)
    if len(priv) <= 33:
        priv = btc.safe_hexlify(priv)
    pub = btc.privkey_to_pubkey(priv)
    address = btc.pubkey_to_address(pub)
    signing_tx = btc.signature_form(tx, i, btc.mk_pubkey_script(address),
                                    hashcode)

    msghash = btc.bin_txhash(signing_tx, hashcode)
    z = btc.hash_to_int(msghash)
    #k = deterministic_generate_k(msghash, priv)
    r, y = btc.fast_multiply(btc.G, k)
    s = btc.inv(k, btc.N) * (z + r * btc.decode_privkey(priv)) % btc.N
    rawsig = 27 + (y % 2), r, s

    sig = btc.der_encode_sig(*rawsig) + btc.encode(hashcode, 16, 2)
    #sig = ecdsa_tx_sign(signing_tx, priv, hashcode)
    txobj = btc.deserialize(tx)
    txobj["ins"][i]["script"] = btc.serialize_script([sig, pub])
    return btc.serialize(txobj)