From 6fb0d983e89c07e9ab1dc4bb144ef7306eda87f9 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 26 Jun 2024 14:05:06 -0700 Subject: [PATCH 1/3] Expose from_seed in SecretKey to python as well --- crates/chia-bls/src/secret_key.rs | 6 ++++++ wheel/python/chia_rs/chia_rs.pyi | 2 ++ 2 files changed, 8 insertions(+) diff --git a/crates/chia-bls/src/secret_key.rs b/crates/chia-bls/src/secret_key.rs index 661719814..31ab6f284 100644 --- a/crates/chia-bls/src/secret_key.rs +++ b/crates/chia-bls/src/secret_key.rs @@ -270,6 +270,12 @@ impl SecretKey { pub fn py_derive_unhardened(&self, idx: u32) -> Self { self.derive_unhardened(idx) } + + #[pyo3(name = "from_seed")] + #[must_use] + pub fn py_from_seed(&self, seed: &[u8]) -> Self { + self.from_seed(seed) + } } #[cfg(feature = "py-bindings")] diff --git a/wheel/python/chia_rs/chia_rs.pyi b/wheel/python/chia_rs/chia_rs.pyi index 02001a0f4..03c0d2deb 100644 --- a/wheel/python/chia_rs/chia_rs.pyi +++ b/wheel/python/chia_rs/chia_rs.pyi @@ -236,6 +236,8 @@ class PrivateKey: def to_json_dict(self) -> Any: ... @staticmethod def from_json_dict(json_dict: Any) -> PrivateKey: ... + @staticmethod + def from_seed(bytes) -> PrivateKey: ... class Spend: coin_id: bytes From 15e46198a43933b1570227931fcf9da22262052f Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 26 Jun 2024 14:26:59 -0700 Subject: [PATCH 2/3] Alright do it better --- crates/chia-bls/src/secret_key.rs | 6 +++--- wheel/generate_type_stubs.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/chia-bls/src/secret_key.rs b/crates/chia-bls/src/secret_key.rs index 31ab6f284..6e4384a51 100644 --- a/crates/chia-bls/src/secret_key.rs +++ b/crates/chia-bls/src/secret_key.rs @@ -272,9 +272,9 @@ impl SecretKey { } #[pyo3(name = "from_seed")] - #[must_use] - pub fn py_from_seed(&self, seed: &[u8]) -> Self { - self.from_seed(seed) + #[staticmethod] + pub fn py_from_seed(seed: &[u8]) -> Self { + Self::from_seed(seed) } } diff --git a/wheel/generate_type_stubs.py b/wheel/generate_type_stubs.py index ab57e0625..32213e25e 100644 --- a/wheel/generate_type_stubs.py +++ b/wheel/generate_type_stubs.py @@ -430,6 +430,8 @@ def __init__( "def public_key(self) -> G1Element: ...", "def derive_hardened(self, int) -> PrivateKey: ...", "def derive_unhardened(self, int) -> PrivateKey: ...", + "@staticmethod", + "def from_seed(bytes) -> PrivateKey: ...", ], ) From 7cf31381ddc8ac2498e190d20c5b9421030cc0b7 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 26 Jun 2024 14:28:23 -0700 Subject: [PATCH 3/3] Run the script --- wheel/python/chia_rs/chia_rs.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wheel/python/chia_rs/chia_rs.pyi b/wheel/python/chia_rs/chia_rs.pyi index 03c0d2deb..076f93153 100644 --- a/wheel/python/chia_rs/chia_rs.pyi +++ b/wheel/python/chia_rs/chia_rs.pyi @@ -215,6 +215,8 @@ class PrivateKey: def public_key(self) -> G1Element: ... def derive_hardened(self, int) -> PrivateKey: ... def derive_unhardened(self, int) -> PrivateKey: ... + @staticmethod + def from_seed(bytes) -> PrivateKey: ... def __init__( self ) -> None: ... @@ -236,8 +238,6 @@ class PrivateKey: def to_json_dict(self) -> Any: ... @staticmethod def from_json_dict(json_dict: Any) -> PrivateKey: ... - @staticmethod - def from_seed(bytes) -> PrivateKey: ... class Spend: coin_id: bytes