Skip to content

Commit

Permalink
cache synthetic public keys and private keys
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed May 9, 2024
1 parent 16376c4 commit baa9ba8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from __future__ import annotations

import hashlib
from functools import lru_cache
from typing import Union

from chia_rs import G1Element, PrivateKey
Expand Down Expand Up @@ -91,13 +92,15 @@ def calculate_synthetic_offset(public_key: G1Element, hidden_puzzle_hash: bytes3
return offset


@lru_cache(maxsize=1000)
def calculate_synthetic_public_key(public_key: G1Element, hidden_puzzle_hash: bytes32) -> G1Element:
synthetic_offset: PrivateKey = PrivateKey.from_bytes(
calculate_synthetic_offset(public_key, hidden_puzzle_hash).to_bytes(32, "big")
)
return public_key + synthetic_offset.get_g1()


@lru_cache(maxsize=1000)
def calculate_synthetic_secret_key(secret_key: PrivateKey, hidden_puzzle_hash: bytes32) -> PrivateKey:
secret_exponent = int.from_bytes(bytes(secret_key), "big")
public_key = secret_key.get_g1()
Expand Down

0 comments on commit baa9ba8

Please sign in to comment.