def generate_single_podle_sig(priv, i): """Make a podle entry for key priv at index i, using a dummy utxo value. This calls the underlying 'raw' code based on the class PoDLE, not the library 'generate_podle' which intelligently searches and updates commitments. """ dummy_utxo = bitcoin.sha256(priv) + ":3" podle = PoDLE(dummy_utxo, binascii.hexlify(priv).decode('ascii')) r = podle.generate_podle(i) return (r['P'], r['P2'], r['sig'], r['e'], r['commit'])
def generate_single_podle_sig(u, priv, i): """Make a podle entry for key priv at index i, using a dummy utxo value. This calls the underlying 'raw' code based on the class PoDLE, not the library 'generate_podle' which intelligently searches and updates commitments. """ #Convert priv to hex hexpriv = btc.from_wif_privkey(priv, vbyte=get_p2pk_vbyte()) podle = PoDLE(u, hexpriv) r = podle.generate_podle(i) return (r['P'], r['P2'], r['sig'], r['e'], r['commit'])
def generate_single_podle_sig(u, priv, i): """Make a podle entry for key priv at index i, using a dummy utxo value. This calls the underlying 'raw' code based on the class PoDLE, not the library 'generate_podle' which intelligently searches and updates commitments. """ # Convert priv from wif; note that wallet type # isn't relevant since we only work with pubkeys in PoDLE: rawpriv, _ = BTCEngine.wif_to_privkey(priv) podle = PoDLE(u, rawpriv) r = podle.generate_podle(i) return (r['P'], r['P2'], r['sig'], r['e'], r['commit'])
def generate_single_podle_sig(u, priv, i): """Make a podle entry for key priv at index i, using a dummy utxo value. This calls the underlying 'raw' code based on the class PoDLE, not the library 'generate_podle' which intelligently searches and updates commitments. """ #Convert priv from wif; require P2SH-P2WPKH keys rawpriv, keytype = BTCEngine.wif_to_privkey(priv) assert keytype == BTC_P2SH_P2WPKH podle = PoDLE(u, rawpriv) r = podle.generate_podle(i) return (r['P'], r['P2'], r['sig'], r['e'], r['commit'])
def test_podle_constructor(setup_podle): """Tests rules about construction of PoDLE object are conformed to. """ priv = b"\xaa"*32 #pub and priv together not allowed with pytest.raises(PoDLEError) as e_info: p = PoDLE(priv=priv, P="dummypub") #no pub or priv is allowed, i forget if this is useful for something p = PoDLE() #create from priv p = PoDLE(priv=priv+b"\x01", u=(struct.pack(b"B", 7)*32, 4)) pdict = p.generate_podle(2) assert all([k in pdict for k in ['used', 'utxo', 'P', 'P2', 'commit', 'sig', 'e']]) #using the valid data, serialize/deserialize test deser = p.deserialize_revelation(p.serialize_revelation()) assert all([deser[x] == pdict[x] for x in ['utxo', 'P', 'P2', 'sig', 'e']]) #deserialization must fail for wrong number of items with pytest.raises(PoDLEError) as e_info: p.deserialize_revelation(':'.join([str(x) for x in range(4)]), separator=':') #reveal() must work without pre-generated commitment p.commitment = None pdict2 = p.reveal() assert pdict2 == pdict #corrupt P2, cannot commit: p.P2 = "blah" with pytest.raises(PoDLEError) as e_info: p.get_commitment() #generation fails without a utxo p = PoDLE(priv=priv) with pytest.raises(PoDLEError) as e_info: p.generate_podle(0) #Test construction from pubkey pub = bitcoin.privkey_to_pubkey(priv+b"\x01") p = PoDLE(P=pub) with pytest.raises(PoDLEError) as e_info: p.get_commitment() with pytest.raises(PoDLEError) as e_info: p.verify("dummycommitment", range(3))