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

[CHIA-780] member functions for deriving hardened and unhardened keys #579

Merged
merged 1 commit into from
Jun 17, 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
13 changes: 9 additions & 4 deletions crates/chia-bls/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,30 @@ mod pybindings {
const SIZE: usize = 48;

#[new]
pub fn init() -> Self {
fn init() -> Self {
Self::default()
}

#[staticmethod]
#[pyo3(name = "generator")]
pub fn py_generator() -> Self {
fn py_generator() -> Self {
Self::generator()
}

pub fn pair(&self, other: &Signature) -> GTElement {
fn pair(&self, other: &Signature) -> GTElement {
other.pair(self)
}

#[pyo3(name = "get_fingerprint")]
pub fn py_get_fingerprint(&self) -> u32 {
fn py_get_fingerprint(&self) -> u32 {
self.get_fingerprint()
}

#[pyo3(name = "derive_unhardened")]
fn py_derive_unhardened(&self, idx: u32) -> Self {
self.derive_unhardened(idx)
}

fn __str__(&self) -> String {
hex::encode(self.to_bytes())
}
Expand Down
19 changes: 17 additions & 2 deletions crates/chia-bls/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,32 @@ mod pybindings {
#[classattr]
const PRIVATE_KEY_SIZE: usize = 32;

pub fn sign_g2(&self, msg: &[u8]) -> Signature {
fn sign_g2(&self, msg: &[u8]) -> Signature {
crate::sign(self, msg)
}

pub fn get_g1(&self) -> PublicKey {
fn get_g1(&self) -> PublicKey {
self.public_key()
}

#[pyo3(name = "public_key")]
fn py_public_key(&self) -> PublicKey {
self.public_key()
}

fn __str__(&self) -> String {
hex::encode(self.to_bytes())
}

#[pyo3(name = "derive_hardened")]
fn py_derive_hardened(&self, idx: u32) -> Self {
self.derive_hardened(idx)
}

#[pyo3(name = "derive_unhardened")]
fn py_derive_unhardened(&self, idx: u32) -> Self {
self.derive_unhardened(idx)
}
}

impl ToJsonDict for SecretKey {
Expand Down
4 changes: 4 additions & 0 deletions wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def __init__(
"def __str__(self) -> str: ...",
"def __add__(self, other: G1Element) -> G1Element: ...",
"def __iadd__(self, other: G1Element) -> G1Element: ...",
"def derive_unhardened(self, int) -> G1Element: ...",
],
)
print_class(
Expand Down Expand Up @@ -426,6 +427,9 @@ def __init__(
"def sign_g2(self, msg: bytes, dst: bytes) -> G2Element: ...",
"def get_g1(self) -> G1Element: ...",
"def __str__(self) -> str: ...",
"def public_key(self) -> G1Element: ...",
"def derive_hardened(self, int) -> PrivateKey: ...",
"def derive_unhardened(self, int) -> PrivateKey: ...",
],
)

Expand Down
4 changes: 4 additions & 0 deletions wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class G1Element:
def __str__(self) -> str: ...
def __add__(self, other: G1Element) -> G1Element: ...
def __iadd__(self, other: G1Element) -> G1Element: ...
def derive_unhardened(self, int) -> G1Element: ...
def __init__(
self
) -> None: ...
Expand Down Expand Up @@ -211,6 +212,9 @@ class PrivateKey:
def sign_g2(self, msg: bytes, dst: bytes) -> G2Element: ...
def get_g1(self) -> G1Element: ...
def __str__(self) -> str: ...
def public_key(self) -> G1Element: ...
Rigidity marked this conversation as resolved.
Show resolved Hide resolved
def derive_hardened(self, int) -> PrivateKey: ...
def derive_unhardened(self, int) -> PrivateKey: ...
def __init__(
self
) -> None: ...
Expand Down
Loading