Skip to content

Commit

Permalink
Merge pull request #579 from Chia-Network/bls-python-bindings
Browse files Browse the repository at this point in the history
[CHIA-780] member functions for deriving hardened and unhardened keys
  • Loading branch information
arvidn authored Jun 17, 2024
2 parents a8e40e8 + a30bb43 commit b71d337
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
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: ...
def derive_hardened(self, int) -> PrivateKey: ...
def derive_unhardened(self, int) -> PrivateKey: ...
def __init__(
self
) -> None: ...
Expand Down

0 comments on commit b71d337

Please sign in to comment.