Exemplo n.º 1
0
    def set_sender_values(self, AP_puzzlehash, a_pubkey_used):
        if isinstance(AP_puzzlehash, str):
            self.AP_puzzlehash = puzzlehash_from_string(AP_puzzlehash)
        else:
            self.AP_puzzlehash = AP_puzzlehash

        if isinstance(a_pubkey_used, str):
            a_pubkey = BLSPublicKey.from_bytes(bytes.fromhex(a_pubkey_used))
            self.a_pubkey = a_pubkey
        else:
            self.a_pubkey = a_pubkey_used
Exemplo n.º 2
0
async def spend_rl_coin(wallet, ledger_api):
    if wallet.rl_available_balance() == 0:
        print("Available rate limited coin balance is 0!")
        return
    receiver_pubkey = input("Enter receiver's pubkey: 0x")
    receiver_pubkey = bytes(BLSPublicKey.from_bytes(bytes.fromhex(receiver_pubkey)))
    amount = -1
    while amount > wallet.current_rl_balance or amount < 0:
        amount = input("Enter amount to give recipient: ")
        if amount == "q":
            return
        if not amount.isdigit():
            amount = -1
        amount = int(amount)

    puzzlehash = wallet.get_puzzlehash_for_pk(receiver_pubkey)
    spend_bundle = wallet.rl_generate_signed_transaction(amount, puzzlehash)
    _ = await ledger_api.push_tx(tx=spend_bundle)
Exemplo n.º 3
0
def farm_block(previous_header, previous_signature, block_number,
               proof_of_space, spend_bundle, coinbase_puzzle_hash, reward):

    fees_puzzle_hash = puzzle_hash_for_index(3)

    coinbase_coin, coinbase_signature = create_coinbase_coin_and_signature(
        block_number, coinbase_puzzle_hash, reward,
        proof_of_space.pool_public_key)

    timestamp = int(1e10) + 300 * block_number
    header, body = farm_new_block(previous_header, previous_signature,
                                  block_number, proof_of_space, spend_bundle,
                                  coinbase_coin, coinbase_signature,
                                  fees_puzzle_hash, timestamp)

    header_signature = sign_header(header, proof_of_space.plot_public_key)

    bad_bls_public_key = BLSPublicKey.from_bytes(public_key_bytes_for_index(9))

    bad_eor_public_key = EORPrivateKey(std_hash(bytes([5]))).public_key()

    hkp = header_signature.aggsig_pair(proof_of_space.plot_public_key,
                                       HeaderHash(header))
    _ = header_signature.validate([hkp])
    assert _

    hkp = header_signature.aggsig_pair(bad_eor_public_key, HeaderHash(header))
    assert not header_signature.validate([hkp])

    hkp = body.coinbase_signature.aggsig_pair(proof_of_space.pool_public_key,
                                              body.coinbase_coin.name())
    assert body.coinbase_signature.validate([hkp])

    hkp = body.coinbase_signature.aggsig_pair(bad_bls_public_key,
                                              body.coinbase_coin.name())
    assert not body.coinbase_signature.validate([hkp])
    return header, header_signature, body
Exemplo n.º 4
0
async def create_rl_coin(wallet, ledger_api):
    utxo_list = list(wallet.my_utxos)
    if len(utxo_list) == 0:
        print("No UTXOs available.")
        return
    print("Select UTXO for origin: ")
    num = 0
    for utxo in utxo_list:
        print(f"{num}) coin_name:{utxo.name()} amount:{utxo.amount}")
        num += 1
    selected = get_int("Select UTXO for origin: ")
    origin = utxo_list[selected]
    print("Rate limit is defined as amount of Chia per time interval.(Blocks)\n")
    rate = get_int("Specify the Chia amount limit: ")
    interval = get_int("Specify the interval length (blocks): ")
    print("Specify the pubkey of receiver")
    pubkey = input(prompt)
    my_pubkey = hexbytes(wallet.get_next_public_key().serialize())
    send_amount = get_int("Enter amount to give recipient: ")
    print(f"\n\nInitialization string: {origin.parent_coin_info}:{origin.puzzle_hash}:"
          f"{origin.amount}:{origin.name()}:{rate}:{interval}:{my_pubkey}")
    print("\nPaste Initialization string to the receiver")
    print("Press Enter to continue:")
    input(prompt)
    pubkey = bytes(BLSPublicKey.from_bytes(bytes.fromhex(pubkey)))
    rl_puzzle = wallet.rl_puzzle_for_pk(pubkey, rate, interval, origin.name(), my_pubkey)
    rl_puzzlehash = ProgramHash(rl_puzzle)
    wallet.clawback_puzzlehash = rl_puzzlehash
    wallet.clawback_origin = origin.name()
    wallet.clawback_limit = rate
    wallet.clawback_interval = interval
    wallet.clawback_pk = my_pubkey
    wallet.rl_receiver_pk = pubkey

    spend_bundle = wallet.generate_signed_transaction_with_origin(send_amount, rl_puzzlehash, origin.name())
    _ = await ledger_api.push_tx(tx=spend_bundle)
Exemplo n.º 5
0
import blspy

from chiasim.atoms import uint64
from chiasim.hashable import BLSPublicKey, BLSSignature, Coin, ProgramHash

HIERARCHICAL_PRIVATE_KEY = blspy.ExtendedPrivateKey.from_seed(b"foo")
POOL_PRIVATE_KEYS = [
    HIERARCHICAL_PRIVATE_KEY.private_child(_).get_private_key()
    for _ in range(100)
]
POOL_PUBLIC_KEYS = [
    BLSPublicKey.from_bytes(_.get_public_key().serialize())
    for _ in POOL_PRIVATE_KEYS
]
POOL_LOOKUP = dict(zip(POOL_PUBLIC_KEYS, POOL_PRIVATE_KEYS))


def get_pool_public_key(index=0) -> BLSPublicKey:
    # TODO: make this configurable
    return POOL_PUBLIC_KEYS[index]


def signature_for_coinbase(coin: Coin, pool_private_key: blspy.PrivateKey):
    message_hash = coin.name()
    return BLSSignature(
        pool_private_key.sign_prepend_prehashed(message_hash).serialize())


def sign_coinbase_coin(coin: Coin, public_key: BLSPublicKey):
    private_key = POOL_LOOKUP.get(public_key)
    if private_key is None:
Exemplo n.º 6
0
 def public_key(self) -> BLSPublicKey:
     return BLSPublicKey(self.pk.get_public_key().serialize())
Exemplo n.º 7
0
 def public_key(self):
     return BLSPublicKey.from_bytes(
         self._bls_public_hd_key.get_public_key().serialize()
     )