async def get_sigs(self, innerpuz: Program, innersol: Program, coin_name) -> List[G2Element]: puzzle_hash = innerpuz.get_tree_hash() pubkey, private = await self.wallet_state_manager.get_keys(puzzle_hash) synthetic_secret_key = calculate_synthetic_secret_key(private, DEFAULT_HIDDEN_PUZZLE_HASH) sigs: List[G2Element] = [] error, conditions, cost = conditions_dict_for_solution(innerpuz, innersol) if conditions is not None: for _, msg in pkm_pairs_for_conditions_dict(conditions, coin_name): signature = AugSchemeMPL.sign(synthetic_secret_key, msg) sigs.append(signature) return sigs
def do_test_spend( puzzle_reveal: Program, solution: Program, payments: Iterable[Tuple[bytes32, int]], key_lookup: KeyTool, farm_time: CoinTimestamp = T1, spend_time: CoinTimestamp = T2, ) -> SpendBundle: """ This method will farm a coin paid to the hash of `puzzle_reveal`, then try to spend it with `solution`, and verify that the created coins correspond to `payments`. The `key_lookup` is used to create a signed version of the `SpendBundle`, although at this time, signatures are not verified. """ coin_db = CoinStore() puzzle_hash = puzzle_reveal.get_tree_hash() # farm it coin = coin_db.farm_coin(puzzle_hash, farm_time) # spend it coin_solution = CoinSolution(coin, puzzle_reveal, solution) spend_bundle = SpendBundle([coin_solution], G2Element()) coin_db.update_coin_store_for_spend_bundle(spend_bundle, spend_time) # ensure all outputs are there for puzzle_hash, amount in payments: for coin in coin_db.coins_for_puzzle_hash(puzzle_hash): if coin.amount == amount: break else: assert 0 # make sure we can actually sign the solution signatures = [] for coin_solution in spend_bundle.coin_solutions: signature = key_lookup.signature_for_solution(coin_solution) signatures.append(signature) return SpendBundle(spend_bundle.coin_solutions, AugSchemeMPL.aggregate(signatures))
def puzzle_for_public_key_and_hidden_puzzle(public_key: G1Element, hidden_puzzle: Program) -> Program: return puzzle_for_public_key_and_hidden_puzzle_hash(public_key, hidden_puzzle.get_tree_hash())
def puzzle_for_inner_puzzle(inner_puzzle: Program) -> Program: return puzzle_for_inner_puzzle_hash(inner_puzzle.get_tree_hash())