diff --git a/Cargo.lock b/Cargo.lock index a76cad71..a101d6c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,7 @@ dependencies = [ "fiat-crypto", "packed_simd_2", "platforms", + "serde", "subtle", "zeroize", ] diff --git a/nucypher-core-wasm/src/lib.rs b/nucypher-core-wasm/src/lib.rs index c0e16b3f..67d155b0 100644 --- a/nucypher-core-wasm/src/lib.rs +++ b/nucypher-core-wasm/src/lib.rs @@ -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); // @@ -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( diff --git a/nucypher-core-wasm/tests/wasm.rs b/nucypher-core-wasm/tests/wasm.rs index aefa2968..2070642d 100644 --- a/nucypher-core-wasm/tests/wasm.rs +++ b/nucypher-core-wasm/tests/wasm.rs @@ -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 diff --git a/nucypher-core/Cargo.toml b/nucypher-core/Cargo.toml index 2dd88cce..8316f652 100644 --- a/nucypher-core/Cargo.toml +++ b/nucypher-core/Cargo.toml @@ -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] diff --git a/nucypher-core/src/dkg.rs b/nucypher-core/src/dkg.rs index 27ab36c3..4fc13792 100644 --- a/nucypher-core/src/dkg.rs +++ b/nucypher-core/src/dkg.rs @@ -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 @@ -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, } } @@ -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 } @@ -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