Skip to content

Commit

Permalink
Fix serialization of requester public key to use actual object instea…
Browse files Browse the repository at this point in the history
…d of Box.
  • Loading branch information
derekpierre committed May 29, 2023
1 parent 39e6471 commit ac50a6e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions nucypher-core-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl EncryptedTreasureMap {
pub struct SharedSecret(x25519_dalek::SharedSecret);

#[wasm_bindgen]
#[derive(derive_more::From, derive_more::AsRef)]
#[derive(PartialEq, Eq, Debug, derive_more::From, derive_more::AsRef)]
pub struct RequesterPublicKey(x25519_dalek::PublicKey);

//
Expand Down Expand Up @@ -642,8 +642,8 @@ impl EncryptedThresholdDecryptionRequest {
}

#[wasm_bindgen(getter, js_name = requesterPublicKey)]
pub fn requester_public_key(&self) -> Box<[u8]> {
self.0.requester_public_key.clone()
pub fn requester_public_key(&self) -> RequesterPublicKey {
RequesterPublicKey::from(self.0.requester_public_key)
}

pub fn decrypt(
Expand Down
3 changes: 1 addition & 2 deletions nucypher-core-wasm/tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,9 @@ fn threshold_decryption_request() {

assert_eq!(encrypted_request_from_bytes, encrypted_request);
assert_eq!(encrypted_request_from_bytes.ritual_id(), ritual_id);
// TODO clean up storage/use of requester public key
assert_eq!(
encrypted_request_from_bytes.requester_public_key(),
requester_public_key.to_bytes().to_vec().into_boxed_slice()
requester_key
);

// service decrypts request
Expand Down
2 changes: 1 addition & 1 deletion nucypher-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sha3 = "0.10"
rmp-serde = "1"
serde_with = "1.14"
hex = "0.4"
x25519-dalek = "2.0.0-rc.2"
x25519-dalek = { version="2.0.0-rc.2", features = ["serde"] }
chacha20poly1305 = "0.10.1"

[dev-dependencies]
Expand Down
9 changes: 3 additions & 6 deletions nucypher-core/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ pub struct EncryptedThresholdDecryptionRequest {
/// ID of the ritual
pub ritual_id: u16,

#[serde(with = "serde_bytes::as_base64")]
/// Public key of requester
/// TODO this should not be Box
pub requester_public_key: Box<[u8]>,
pub requester_public_key: PublicKey,

#[serde(with = "serde_bytes::as_base64")]
/// Encrypted request
Expand All @@ -201,7 +199,7 @@ impl EncryptedThresholdDecryptionRequest {
.expect("encryption failed - out of memory?");
Self {
ritual_id: request.ritual_id,
requester_public_key: requester_public_key.to_bytes().to_vec().into_boxed_slice(),
requester_public_key: *requester_public_key,
ciphertext,
}
}
Expand Down Expand Up @@ -297,7 +295,6 @@ pub struct EncryptedThresholdDecryptionResponse {

impl EncryptedThresholdDecryptionResponse {
fn new(response: &ThresholdDecryptionResponse, shared_secret: &SharedSecret) -> Self {
// TODO: using Umbral for encryption to avoid introducing more crypto primitives.
let ciphertext = encrypt_with_shared_secret(shared_secret, &response.to_bytes())
.expect("encryption failed - out of memory?");
Self { ciphertext }
Expand Down Expand Up @@ -413,7 +410,7 @@ mod tests {
assert_eq!(encrypted_request_from_bytes.ritual_id, ritual_id);
assert_eq!(
encrypted_request_from_bytes.requester_public_key,
requester_public_key.as_bytes().to_vec().into_boxed_slice()
requester_public_key
);

// service decrypts request
Expand Down

0 comments on commit ac50a6e

Please sign in to comment.