Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert blspy to chia_rs, update chia to 2.1.4 #103

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cdv/cmds/chia_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union

import click
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
from chia.consensus.cost_calculator import NPCResult
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.full_node.bundle_tools import simple_solution_generator
Expand All @@ -31,6 +30,7 @@
calculate_synthetic_public_key,
calculate_synthetic_secret_key,
)
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey

from cdv.cmds.util import parse_program

Expand Down Expand Up @@ -161,6 +161,7 @@ def inspect_any_cmd(ctx: click.Context, objects: Tuple[str]):
if type(obj) == str:
print(f"Could not guess the type of {obj}")
elif type(obj) == Coin: # type: ignore[comparison-overlap]
assert isinstance(obj, Coin) # mypy otherwise complains that obj is a str
do_inspect_coin_cmd(ctx, [obj])
elif type(obj) == CoinSpend: # type: ignore[comparison-overlap]
do_inspect_coin_spend_cmd(ctx, [obj])
Expand All @@ -170,11 +171,11 @@ def inspect_any_cmd(ctx: click.Context, objects: Tuple[str]):
do_inspect_coin_record_cmd(ctx, [obj])
elif type(obj) == Program:
do_inspect_program_cmd(ctx, [obj])
elif type(obj) == G1Element:
elif type(obj) == G1Element: # type: ignore[comparison-overlap]
do_inspect_keys_cmd(ctx, public_key=obj)
elif type(obj) == PrivateKey:
elif type(obj) == PrivateKey: # type: ignore[comparison-overlap]
do_inspect_keys_cmd(ctx, secret_key=obj)
elif type(obj) == G2Element:
elif type(obj) == G2Element: # type: ignore[comparison-overlap]
print("That's a BLS aggregated signature") # This is more helpful than just printing it back to them


Expand Down Expand Up @@ -374,7 +375,9 @@ def do_inspect_spend_bundle_cmd(
# If this is from the command line and they've specified at lease one spend to parse
if kwargs and (len(kwargs["spend"]) > 0):
if len(kwargs["aggsig"]) > 0:
sig: G2Element = AugSchemeMPL.aggregate([G2Element(hexstr_to_bytes(sig)) for sig in kwargs["aggsig"]])
sig: G2Element = AugSchemeMPL.aggregate(
[G2Element.from_bytes(hexstr_to_bytes(sig)) for sig in kwargs["aggsig"]]
)
else:
sig = G2Element()
spend_bundle_objs: List[SpendBundle] = [
Expand Down Expand Up @@ -626,6 +629,7 @@ def do_inspect_keys_cmd(ctx: click.Context, print_results: bool = True, **kwargs
if len(kwargs) == 1:
if "secret_key" in kwargs:
sk = kwargs["secret_key"]
assert sk is not None
pk = sk.get_g1()
elif "public_key" in kwargs:
pk = kwargs["public_key"]
Expand Down Expand Up @@ -676,6 +680,7 @@ def one_or_zero(value):
if case == "auth":
list_path = [12381, 8444, 6, 0]
if list_path:
assert sk is not None
sk = _derive_path(sk, list_path)
pk = sk.get_g1()
path = "m/" + "/".join([str(e) for e in path])
Expand Down
2 changes: 1 addition & 1 deletion cdv/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Dict, List, Optional, Tuple, Union

import pytimeparse
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
from chia.clvm.spend_sim import SimClient, SpendSim
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.types.blockchain_format.coin import Coin
Expand All @@ -25,6 +24,7 @@
puzzle_for_pk,
)
from chia.wallet.sign_coin_spends import sign_coin_spends
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey

from cdv.util.keys import private_key_for_index, public_key_for_index

Expand Down
4 changes: 2 additions & 2 deletions cdv/util/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typing import Dict, List

from blspy import AugSchemeMPL, BasicSchemeMPL, G1Element, G2Element, PrivateKey
from chia.util.hash import std_hash
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey


def secret_exponent_for_index(index: int) -> int:
blob = index.to_bytes(32, "big")
hashed_blob = BasicSchemeMPL.key_gen(std_hash(b"foo" + blob))
hashed_blob = AugSchemeMPL.key_gen(std_hash(b"foo" + blob))
r = int.from_bytes(hashed_blob, "big")
return r

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"pytest-asyncio",
"pytimeparse",
"anyio",
"chia-blockchain==2.1.1",
"chia-blockchain==2.1.4",
]

dev_dependencies = [
Expand Down
12 changes: 6 additions & 6 deletions tests/cmds/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,15 @@ def test_programs(self):
assert id in result.output

def test_keys(self):
mnemonic: str = "chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia" # noqa
sk: str = "6e66bc91c04127f1178cb725faf82b55214b5f215b10bd53bf2eb1ee9e76d2cc"
pk: str = "8777e5c4f5b21840eb69d9cc09433655b044a8e80048cd9583bab9a90f4774d2d57c1b19196ae132c9502db5902f3e5d"
mnemonic: str = "spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend" # noqa
geoffwalmsley marked this conversation as resolved.
Show resolved Hide resolved
sk: str = "1ef0ff42df2fdd4472312e033f555c569d18b85ba0d9f1b09ed87b254dc18a8e"
pk: str = "ae6c7589432cb60a00d84fc83971f50a98fd728863d3ceb189300f2f80d6839e9a2e761ef6cdce809caee83a4e73b623"
hd_modifier: str = "m/12381/8444/0/0"
type_modifier: str = "farmer" # Should be same as above HD Path
farmer_sk: str = "1d4a4c2f2059ac889fe066d1116a0fe5dc3d6aa016645306698968c78e8df916"
synthetic_sk: str = "6963ce75cd541a0b49cc6feb15185675beb513bd5808e744d475ec50cf75b2c0"
farmer_sk: str = "6a97995a8b35c69418ad60152a5e1c9a32d159bcb7c343c5ccf83c71e4df2038"
synthetic_sk: str = "4272b71ba1c628948e308148e92c1a9b24a785d52f604610a436d2088f72d578"
ph_modifier: str = "69ae360134b1fae04326e5546f25dc794a19192a1f22a44a46d038e7f0d1ecbb"
modified_synthetic_sk: str = "2dc18bb076849fce06d9c36e59821ff43e8b81068d33fcc5ada3568fb9dcdb7f"
modified_synthetic_sk: str = "405d969856846304eec6b243d810665cb3b7e94b56747b87e8e5597948ba1da6"

runner = CliRunner()

Expand Down