def run_test_p2_delegated_puzzle_or_hidden_puzzle_with_delegated_puzzle( self, hidden_pub_key_index): payments, conditions = default_payments_and_conditions() hidden_puzzle = p2_conditions.puzzle_for_conditions(conditions) hidden_public_key = public_key_bytes_for_index(hidden_pub_key_index) puzzle = p2_delegated_puzzle_or_hidden_puzzle.puzzle_for_public_key_and_hidden_puzzle( hidden_public_key, hidden_puzzle) puzzle_hash = ProgramHash(puzzle) payable_payments, payable_conditions = default_payments_and_conditions( 5) delegated_puzzle = p2_conditions.puzzle_for_conditions( payable_conditions) delegated_solution = [] synthetic_public_key = p2_delegated_puzzle_or_hidden_puzzle.calculate_synthetic_public_key( hidden_public_key, hidden_puzzle) solution = p2_delegated_puzzle_or_hidden_puzzle.solution_with_delegated_puzzle( synthetic_public_key, delegated_puzzle, delegated_solution) hidden_puzzle_hash = ProgramHash(hidden_puzzle) synthetic_offset = p2_delegated_puzzle_or_hidden_puzzle.calculate_synthetic_offset( hidden_public_key, hidden_puzzle_hash) private_key = bls_private_key_for_index(hidden_pub_key_index) assert private_key.public_key() == hidden_public_key secret_exponent = private_key.secret_exponent() synthetic_secret_exponent = secret_exponent + synthetic_offset DEFAULT_KEYCHAIN.add_secret_exponents([synthetic_secret_exponent]) run_test(puzzle_hash, solution, payable_payments)
def test_p2_conditions(self): payments, conditions = default_payments_and_conditions() puzzle_hash = ProgramHash( p2_conditions.puzzle_for_conditions(conditions)) solution = p2_conditions.solution_for_conditions(conditions) run_test(puzzle_hash, solution, payments)
def make_solution(self, primaries=[], min_time=0, me={}, consumed=[]): ret = [] for primary in primaries: ret.append(make_create_coin_condition( primary['puzzlehash'], primary['amount'])) for coin in consumed: ret.append(make_assert_coin_consumed_condition(coin)) if min_time > 0: ret.append(make_assert_min_time_condition(min_time)) if me: ret.append(make_assert_my_coin_id_condition(me['id'])) return clvm.to_sexp_f([puzzle_for_conditions(ret), []])
def solution_maker(coin, remote): print(coin.name()) if fuzz_coin: coin = fuzz_coin(remote, puzzle_hash) print(coin.name()) id_condition = make_assert_my_coin_id_condition(coin.name()) delegated_puzzle = p2_conditions.puzzle_for_conditions( conditions + [id_condition]) delegated_solution = p2_delegated_conditions.solution_for_conditions( delegated_puzzle, []) solution = p2_m_of_n_delegate_direct.solution_for_delegated_puzzle( M, pks, selectors, delegated_puzzle, delegated_solution) return solution
def test_p2_delegated_puzzle_or_hidden_puzzle_with_hidden_puzzle(self): payments, conditions = default_payments_and_conditions() hidden_puzzle = p2_conditions.puzzle_for_conditions(conditions) hidden_public_key = public_key_bytes_for_index(10) puzzle = p2_delegated_puzzle_or_hidden_puzzle.puzzle_for_public_key_and_hidden_puzzle( hidden_public_key, hidden_puzzle) puzzle_hash = ProgramHash(puzzle) solution = p2_delegated_puzzle_or_hidden_puzzle.solution_with_hidden_puzzle( hidden_public_key, hidden_puzzle, []) run_test(puzzle_hash, solution, payments)
def maximal_solution_for_coin(wallet, index, coin, conditions): """ Create a "maximal" solution for coin. This is an N of N solution which doesn't actually work (unless M == N), but gives insight to the signers as to which N public keys would be necessary. """ delegated_puzzle = puzzle_for_conditions(conditions) delegated_solution = solution_for_conditions(conditions) pub_keys = wallet.pub_keys_for_index(index) n = len(pub_keys) maximal_solution = solution_for_delegated_puzzle(n, pub_keys, [1] * n, delegated_puzzle, delegated_solution) return CoinSolution(coin, maximal_solution), pub_keys
def test_p2_m_of_n_delegated_puzzle(self): payments, conditions = default_payments_and_conditions() pks = [public_key_bytes_for_index(_) for _ in range(1, 6)] M = 3 delegated_puzzle = p2_conditions.puzzle_for_conditions(conditions) delegated_solution = [] puzzle_program = p2_m_of_n_delegate_direct.puzzle_for_m_of_public_key_list( M, pks) selectors = [1, [], [], 1, 1] solution = p2_m_of_n_delegate_direct.solution_for_delegated_puzzle( M, pks, selectors, delegated_puzzle, delegated_solution) puzzle_hash = ProgramHash(puzzle_program) run_test(puzzle_hash, solution, payments)
def finalize_pst(wallet, pst, sigs): """ Return a pair (SpendBundle or None, summary_list). If we have a finalized SpendBundle, it's returned, otherwise None, The summary_list item is a list of items (coin, hkp_list, sigs_to_use, m) which allows the UI to give the end user information about which coins still need signatures. Note that hkp is short for hash_key_pair (ie. aggsig pair) """ m = wallet.m() coin_solutions = [] sig_dict = sigs_to_aggsig_sig_dict(wallet, pst, sigs) all_sigs_to_use = [] summary_list = [] for coin_solution in pst.get("coin_solutions"): coin, solution = coin_solution.coin, coin_solution.solution # run maximal_solution and get conditions conditions_dict = conditions_dict_for_solution(solution) # look for AGG_SIG conditions hkp_list = hash_key_pairs_for_conditions_dict(conditions_dict) # see if we have enough info to build signatures found_list = [] sigs_to_use = [] for aggsig_pair in hkp_list: add_me = 0 if len(sigs_to_use) < m: if aggsig_pair in sig_dict: sigs_to_use.append(sig_dict[aggsig_pair]) add_me = 1 found_list.append(add_me) all_sigs_to_use.extend(sigs_to_use) conditions = pst.get("conditions") delegated_puzzle = puzzle_for_conditions(conditions) delegated_solution = solution_for_conditions(conditions) index = wallet.index_for_puzzle_hash(coin.puzzle_hash, GAP_LIMIT) pub_keys = wallet.pub_keys_for_index(index) actual_solution = solution_for_delegated_puzzle( m, pub_keys, found_list, delegated_puzzle, delegated_solution) coin_solution = CoinSolution(coin, actual_solution) coin_solutions.append(coin_solution) summary = (coin, hkp_list, sigs_to_use, m) summary_list.append(summary) if len(all_sigs_to_use) > 0: aggregated_sig = all_sigs_to_use[0].aggregate(all_sigs_to_use) spend_bundle = SpendBundle(coin_solutions, aggregated_sig) try: if validate_spend_bundle_signature(spend_bundle): return spend_bundle, summary_list except Exception: pass return None, summary_list