Skip to content

Commit a5f08e3

Browse files
author
yeastplume
committed
fix from_pubkey function
1 parent fac1c8a commit a5f08e3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/pedersen.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,15 @@ impl Commitment {
9696
}
9797

9898
/// Creates from a pubkey
99-
pub fn from_pubkey(secp: &Secp256k1, pk: &key::PublicKey) -> Result<Self, Error> {
100-
unsafe {
101-
let mut commit = Self::blank();
102-
if ffi::secp256k1_pubkey_to_pedersen_commitment(secp.ctx, commit.as_mut_ptr(), &pk.0) == 1 {
103-
Ok(commit)
104-
} else {
105-
Err(InvalidCommit)
106-
}
99+
pub fn from_pubkey(secp: &Secp256k1, pk: &key::PublicKey) -> Result<Commitment, Error> {
100+
let mut commit_i = [0; constants::PEDERSEN_COMMITMENT_SIZE_INTERNAL];
101+
let res = unsafe {
102+
ffi::secp256k1_pubkey_to_pedersen_commitment(secp.ctx, commit_i.as_mut_ptr(), &pk.0 as *const _)
103+
};
104+
if res == 1 {
105+
Ok(secp.commit_ser(commit_i)?)
106+
} else {
107+
Err(InvalidCommit)
107108
}
108109
}
109110

0 commit comments

Comments
 (0)