diff --git a/CHANGELOG.md b/CHANGELOG.md index 388cc6d0..5163b806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed `E2EThresholdDecryptionRequest` type and bindings. ([#54]) - Modified `EncryptedThresholdDecryptionRequest`/`EncryptedThresholdDecryptionResponse` to use Curve 25519 keys instead of Umbral keys for encryption/decryption. ([#54]) - Modified `ThresholdDecryptionResponse`/`EncryptedThresholdDecryptionResponse` to include `ritual_id` member in struct. ([#54]) +- Ritual ID for `ThresholdDecryption[Request/Response]` / `EncryptedThresholdDecryption[Request/Response]` is now u32 instead of u16. ([#54]) [#53]: https://github.com/nucypher/nucypher-core/pull/53 diff --git a/Cargo.lock b/Cargo.lock index 0b9ccec4..02abd3da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -901,6 +901,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-derive", "wasm-bindgen-test", + "x25519-dalek", ] [[package]] @@ -1597,7 +1598,6 @@ dependencies = [ "proc-macro2", "quote", "syn 1.0.109", - "wasm-bindgen", ] [[package]] diff --git a/nucypher-core-python/src/lib.rs b/nucypher-core-python/src/lib.rs index 94fe6d25..04a6b96d 100644 --- a/nucypher-core-python/src/lib.rs +++ b/nucypher-core-python/src/lib.rs @@ -762,7 +762,7 @@ pub struct ThresholdDecryptionRequest { impl ThresholdDecryptionRequest { #[new] pub fn new( - ritual_id: u16, + ritual_id: u32, variant: u8, ciphertext: &Ciphertext, conditions: Option<&Conditions>, @@ -792,7 +792,7 @@ impl ThresholdDecryptionRequest { } #[getter] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.backend.ritual_id } @@ -863,7 +863,7 @@ pub struct EncryptedThresholdDecryptionRequest { #[pymethods] impl EncryptedThresholdDecryptionRequest { #[getter] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.backend.ritual_id } @@ -905,14 +905,14 @@ pub struct ThresholdDecryptionResponse { #[pymethods] impl ThresholdDecryptionResponse { #[new] - pub fn new(ritual_id: u16, decryption_share: &[u8]) -> Self { + pub fn new(ritual_id: u32, decryption_share: &[u8]) -> Self { ThresholdDecryptionResponse { backend: nucypher_core::ThresholdDecryptionResponse::new(ritual_id, decryption_share), } } #[getter] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.backend.ritual_id } @@ -953,7 +953,7 @@ pub struct EncryptedThresholdDecryptionResponse { #[pymethods] impl EncryptedThresholdDecryptionResponse { #[getter] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.backend.ritual_id } diff --git a/nucypher-core-wasm/src/lib.rs b/nucypher-core-wasm/src/lib.rs index 5dd08e4e..9392a1d0 100644 --- a/nucypher-core-wasm/src/lib.rs +++ b/nucypher-core-wasm/src/lib.rs @@ -657,7 +657,7 @@ pub struct ThresholdDecryptionRequest(nucypher_core::ThresholdDecryptionRequest) impl ThresholdDecryptionRequest { #[wasm_bindgen(constructor)] pub fn new( - ritual_id: u16, + ritual_id: u32, variant: u8, ciphertext: &Ciphertext, conditions: &OptionConditions, @@ -682,7 +682,7 @@ impl ThresholdDecryptionRequest { } #[wasm_bindgen(getter, js_name = ritualId)] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.0.ritual_id } @@ -732,7 +732,7 @@ pub struct EncryptedThresholdDecryptionRequest(nucypher_core::EncryptedThreshold #[wasm_bindgen] impl EncryptedThresholdDecryptionRequest { #[wasm_bindgen(getter, js_name = ritualId)] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.0.ritual_id } @@ -774,7 +774,7 @@ pub struct ThresholdDecryptionResponse(nucypher_core::ThresholdDecryptionRespons impl ThresholdDecryptionResponse { #[wasm_bindgen(constructor)] pub fn new( - ritual_id: u16, + ritual_id: u32, decryption_share: &[u8], ) -> Result { Ok(Self(nucypher_core::ThresholdDecryptionResponse::new( @@ -784,7 +784,7 @@ impl ThresholdDecryptionResponse { } #[wasm_bindgen(getter, js_name = ritualId)] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.0.ritual_id } @@ -824,7 +824,7 @@ pub struct EncryptedThresholdDecryptionResponse( #[wasm_bindgen] impl EncryptedThresholdDecryptionResponse { #[wasm_bindgen(getter, js_name = ritualId)] - pub fn ritual_id(&self) -> u16 { + pub fn ritual_id(&self) -> u32 { self.0.ritual_id } diff --git a/nucypher-core-wasm/tests/wasm.rs b/nucypher-core-wasm/tests/wasm.rs index 615943ca..077d5449 100644 --- a/nucypher-core-wasm/tests/wasm.rs +++ b/nucypher-core-wasm/tests/wasm.rs @@ -688,7 +688,7 @@ fn request_public_key() { #[wasm_bindgen_test] fn threshold_decryption_request() { - let ritual_id: u16 = 5; + let ritual_id: u32 = 5; let service_secret = RequestSecretKey::random(); let service_public_key = service_secret.public_key(); diff --git a/nucypher-core/src/dkg.rs b/nucypher-core/src/dkg.rs index 5dd1c193..013c8c95 100644 --- a/nucypher-core/src/dkg.rs +++ b/nucypher-core/src/dkg.rs @@ -267,9 +267,9 @@ pub mod request_keys { type RequestKeyFactorySeed = GenericArray; /// Error thrown when invalid random seed provided for creating key factory. - pub struct InvalidRequestFactorySeedLengthError; + pub struct InvalidRequestFactorySeedLength; - impl fmt::Display for InvalidRequestFactorySeedLengthError { + impl fmt::Display for InvalidRequestFactorySeedLength { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Invalid seed length") } @@ -304,9 +304,9 @@ pub mod request_keys { /// from a cryptographically secure source of randomness! pub fn from_secure_randomness( seed: &[u8], - ) -> Result { + ) -> Result { if seed.len() != Self::seed_size() { - return Err(InvalidRequestFactorySeedLengthError); + return Err(InvalidRequestFactorySeedLength); } Ok(Self(SecretBox::new(*RequestKeyFactorySeed::from_slice( seed, @@ -343,7 +343,7 @@ pub mod request_keys { #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct ThresholdDecryptionRequest { /// The ID of the ritual. - pub ritual_id: u16, + pub ritual_id: u32, /// The ciphertext to generate a decryption share for. pub ciphertext: Ciphertext, /// A blob of bytes containing decryption conditions for this message. @@ -357,7 +357,7 @@ pub struct ThresholdDecryptionRequest { impl ThresholdDecryptionRequest { /// Creates a new decryption request. pub fn new( - ritual_id: u16, + ritual_id: u32, ciphertext: &Ciphertext, conditions: Option<&Conditions>, context: Option<&Context>, @@ -384,7 +384,7 @@ impl ThresholdDecryptionRequest { impl<'a> ProtocolObjectInner<'a> for ThresholdDecryptionRequest { fn version() -> (u16, u16) { - (1, 0) + (2, 0) } fn brand() -> [u8; 4] { @@ -410,7 +410,7 @@ impl<'a> ProtocolObject<'a> for ThresholdDecryptionRequest {} #[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] pub struct EncryptedThresholdDecryptionRequest { /// ID of the ritual - pub ritual_id: u16, + pub ritual_id: u32, /// Public key of requester pub requester_public_key: RequestPublicKey, @@ -449,7 +449,7 @@ impl EncryptedThresholdDecryptionRequest { impl<'a> ProtocolObjectInner<'a> for EncryptedThresholdDecryptionRequest { fn version() -> (u16, u16) { - (1, 0) + (2, 0) } fn brand() -> [u8; 4] { @@ -475,7 +475,7 @@ impl<'a> ProtocolObject<'a> for EncryptedThresholdDecryptionRequest {} #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] pub struct ThresholdDecryptionResponse { /// The ID of the ritual. - pub ritual_id: u16, + pub ritual_id: u32, /// The decryption share to include in the response. #[serde(with = "serde_bytes::as_base64")] @@ -484,7 +484,7 @@ pub struct ThresholdDecryptionResponse { impl ThresholdDecryptionResponse { /// Creates and a new decryption response. - pub fn new(ritual_id: u16, decryption_share: &[u8]) -> Self { + pub fn new(ritual_id: u32, decryption_share: &[u8]) -> Self { ThresholdDecryptionResponse { ritual_id, decryption_share: decryption_share.to_vec().into(), @@ -502,7 +502,7 @@ impl ThresholdDecryptionResponse { impl<'a> ProtocolObjectInner<'a> for ThresholdDecryptionResponse { fn version() -> (u16, u16) { - (1, 0) + (2, 0) } fn brand() -> [u8; 4] { @@ -528,7 +528,7 @@ impl<'a> ProtocolObject<'a> for ThresholdDecryptionResponse {} #[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] pub struct EncryptedThresholdDecryptionResponse { /// The ID of the ritual. - pub ritual_id: u16, + pub ritual_id: u32, #[serde(with = "serde_bytes::as_base64")] ciphertext: Box<[u8]>, @@ -560,7 +560,7 @@ impl EncryptedThresholdDecryptionResponse { impl<'a> ProtocolObjectInner<'a> for EncryptedThresholdDecryptionResponse { fn version() -> (u16, u16) { - (1, 0) + (2, 0) } fn brand() -> [u8; 4] { @@ -719,6 +719,10 @@ mod tests { // service decrypts request let service_shared_secret = service_secret.derive_shared_secret(&encrypted_request_from_bytes.requester_public_key); + assert_eq!( + service_shared_secret.as_bytes(), + requester_shared_secret.as_bytes() + ); let decrypted_request = encrypted_request_from_bytes .decrypt(&service_shared_secret) .unwrap(); @@ -758,6 +762,10 @@ mod tests { // requester decrypts response let service_public_key = service_secret.public_key(); let requester_shared_secret = requester_secret.derive_shared_secret(&service_public_key); + assert_eq!( + requester_shared_secret.as_bytes(), + service_shared_secret.as_bytes() + ); let decrypted_response = encrypted_response_from_bytes .decrypt(&requester_shared_secret) .unwrap();