Skip to content

Commit

Permalink
Merge pull request #616 from Chia-Network/sk-sign-augment
Browse files Browse the repository at this point in the history
CHIA-922: CHIA-938: Add signing and verification methods
  • Loading branch information
Rigidity authored Jul 22, 2024
2 parents fc61c21 + fb69e77 commit e1a7b55
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions crates/chia-bls/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ impl PublicKey {
Self::generator()
}

pub fn verify(&self, signature: &crate::Signature, msg: &[u8]) -> bool {
crate::verify(signature, self, msg)
}

pub fn pair(&self, other: &crate::Signature) -> crate::GTElement {
other.pair(self)
}
Expand Down
11 changes: 9 additions & 2 deletions crates/chia-bls/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,15 @@ impl SecretKey {
#[classattr]
pub const PRIVATE_KEY_SIZE: usize = 32;

pub fn sign_g2(&self, msg: &[u8]) -> crate::Signature {
crate::sign(self, msg)
pub fn sign(&self, msg: &[u8], final_pk: Option<PublicKey>) -> crate::Signature {
match final_pk {
Some(prefix) => {
let mut aug_msg = prefix.to_bytes().to_vec();
aug_msg.extend_from_slice(msg);
crate::sign_raw(self, aug_msg)
}
None => crate::sign(self, msg),
}
}

pub fn get_g1(&self) -> PublicKey {
Expand Down
3 changes: 2 additions & 1 deletion wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def __init__(
"SIZE: ClassVar[int] = ...",
"def __new__(cls) -> G1Element: ...",
"def get_fingerprint(self) -> int: ...",
"def verify(self, signature: G2Element, msg: bytes) -> bool: ...",
"def pair(self, other: G2Element) -> GTElement: ...",
"@staticmethod",
"def generator() -> G1Element: ...",
Expand Down Expand Up @@ -420,7 +421,7 @@ def __init__(
[],
[
"PRIVATE_KEY_SIZE: ClassVar[int] = ...",
"def sign_g2(self, msg: bytes, dst: bytes) -> G2Element: ...",
"def sign(self, msg: bytes, final_pk: Optional[G1Element] = None) -> G2Element: ...",
"def get_g1(self) -> G1Element: ...",
"def __str__(self) -> str: ...",
"def public_key(self) -> G1Element: ...",
Expand Down
3 changes: 2 additions & 1 deletion wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class G1Element:
SIZE: ClassVar[int] = ...
def __new__(cls) -> G1Element: ...
def get_fingerprint(self) -> int: ...
def verify(self, signature: G2Element, msg: bytes) -> bool: ...
def pair(self, other: G2Element) -> GTElement: ...
@staticmethod
def generator() -> G1Element: ...
Expand Down Expand Up @@ -206,7 +207,7 @@ class GTElement:

class PrivateKey:
PRIVATE_KEY_SIZE: ClassVar[int] = ...
def sign_g2(self, msg: bytes, dst: bytes) -> G2Element: ...
def sign(self, msg: bytes, final_pk: Optional[G1Element] = None) -> G2Element: ...
def get_g1(self) -> G1Element: ...
def __str__(self) -> str: ...
def public_key(self) -> G1Element: ...
Expand Down

0 comments on commit e1a7b55

Please sign in to comment.