Files
chia-blockchain/tests/keys.py
T
b964d86a5f Electron react (#226)
* clean react
* add material ui
* add word list
* mnemonic v0
* jeepney backup
* keychain usage
* wallet api
* mnemonic ui
* mnemonics redux state
* handle exceptions correctly
* dashboard
* wallets
* get puzzle hash
* tx history
* sidebar
* start stop wallet node
* use existing mnemonics
* status info
* create cc wallet
* theme should be outside of switch
* create offer
* dbus alternative for linux
* key migration
* don't autocomplete, don't reset simulator db
* reset mnemonics
* Refactor keychain, and key migration
* Implement UI for changing keys
* Removing keys and mnemonic button
* Start making farmer and harvester RPCs
* start rpx for simulator
* Harvester and farmer websocket, and basic UI
* Plot display and deletion
* launch daemon on start
* State changes from full node, harvester, farmer, and full node ui improvements
* split balances in react
* pending change balance
* plotter
* dev config
* maintain connection / retry
* Remove electron-ui, and style fixes
* Better farmer and full node control
* Remove electron ui references
* Uncomment out starting the dameon
* Remove timelord tab, and change full node style
* Clean up new wallet login
* Refactor RPCs
* Now that the GH runner uses python 3.7.7 - use for windows installer
* add balance split to coloured coin wallet
* spendable balance fix
* Import private key from UI fix
* mac build/installer

Co-authored-by: Mariano Sorgente <sorgente711@gmail.com>
Co-authored-by: Lipa Long <lipa@chia.net>
Co-authored-by: Gene Hoffman <hoffmang@hoffmang.com>
2020-06-01 08:56:59 -07:00

62 lines
1.8 KiB
Python

import blspy
from src.types.coin_solution import CoinSolution
from src.types.spend_bundle import SpendBundle
from src.wallet.BLSPrivateKey import BLSPrivateKey
from src.wallet.puzzles import p2_delegated_puzzle
from src.wallet.puzzles.puzzle_utils import make_create_coin_condition
from tests.util.key_tool import KeyTool
HIERARCHICAL_PRIVATE_KEY = blspy.ExtendedPrivateKey.from_seed(b"foo")
def bls_private_key_for_index(index):
return BLSPrivateKey.from_bytes(
bytes(HIERARCHICAL_PRIVATE_KEY.private_child(index).get_private_key())
)
def public_key_bytes_for_index(index):
return bytes(HIERARCHICAL_PRIVATE_KEY.private_child(index).get_public_key())
def puzzle_program_for_index(index):
return p2_delegated_puzzle.puzzle_for_pk(public_key_bytes_for_index(index))
def puzzle_hash_for_index(index):
return puzzle_program_for_index(index).get_hash()
def conditions_for_payment(puzzle_hash_amount_pairs):
conditions = [
make_create_coin_condition(ph, amount)
for ph, amount in puzzle_hash_amount_pairs
]
return conditions
def make_default_keyUtil():
keychain = KeyTool()
private_keys = [bls_private_key_for_index(_) for _ in range(10)]
secret_exponents = [int.from_bytes(bytes(_), "big") for _ in private_keys]
keychain.add_secret_exponents(secret_exponents)
return keychain
DEFAULT_KEYTOOL = make_default_keyUtil()
def spend_coin(coin, conditions, index, keychain=DEFAULT_KEYTOOL):
solution = p2_delegated_puzzle.solution_for_conditions(
puzzle_program_for_index(index), conditions
)
return build_spend_bundle(coin, solution, keychain)
def build_spend_bundle(coin, solution, keychain=DEFAULT_KEYTOOL):
coin_solution = CoinSolution(coin, solution)
signature = keychain.signature_for_solution(solution, bytes(coin))
return SpendBundle([coin_solution], signature)