diff --git a/Cargo.lock b/Cargo.lock index cc437e886f238b..89f931968b4e20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7481,6 +7481,23 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-offchain-message" +version = "2.2.0" +dependencies = [ + "num_enum", + "solana-hash", + "solana-keypair", + "solana-offchain-message", + "solana-packet", + "solana-pubkey", + "solana-sanitize", + "solana-sha256-hasher", + "solana-signature", + "solana-signer", + "static_assertions", +] + [[package]] name = "solana-package-metadata" version = "2.2.0" @@ -8265,7 +8282,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "qualifier_attr", "rand 0.7.3", "rand 0.8.5", @@ -8291,6 +8307,7 @@ dependencies = [ "solana-keypair", "solana-logger", "solana-native-token", + "solana-offchain-message", "solana-packet", "solana-precompile-error", "solana-presigner", diff --git a/Cargo.toml b/Cargo.toml index 4481a65765ce93..4fdd83e40f2dc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,6 +127,7 @@ members = [ "sdk/msg", "sdk/native-token", "sdk/nonce", + "sdk/offchain-message", "sdk/package-metadata", "sdk/package-metadata-macro", "sdk/packet", @@ -470,6 +471,7 @@ solana-net-utils = { path = "net-utils", version = "=2.2.0" } solana-nohash-hasher = "0.2.1" solana-nonce = { path = "sdk/nonce", version = "=2.2.0" } solana-notifier = { path = "notifier", version = "=2.2.0" } +solana-offchain-message = { path = "sdk/offchain-message", version = "=2.2.0" } solana-package-metadata = { path = "sdk/package-metadata", version = "=2.2.0" } solana-package-metadata-macro = { path = "sdk/package-metadata-macro", version = "=2.2.0" } solana-packet = { path = "sdk/packet", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 498441efb8766f..32e97232d78f25 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5898,6 +5898,19 @@ dependencies = [ "solana-sha256-hasher", ] +[[package]] +name = "solana-offchain-message" +version = "2.2.0" +dependencies = [ + "num_enum", + "solana-hash", + "solana-packet", + "solana-sanitize", + "solana-sha256-hasher", + "solana-signature", + "solana-signer", +] + [[package]] name = "solana-packet" version = "2.2.0" @@ -7004,7 +7017,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "qualifier_attr", "rand 0.7.3", "rand 0.8.5", @@ -7027,6 +7039,7 @@ dependencies = [ "solana-instruction", "solana-keypair", "solana-native-token", + "solana-offchain-message", "solana-packet", "solana-precompile-error", "solana-presigner", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 4dd91e2277a944..a02e3a0c3478de 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -35,6 +35,7 @@ full = [ "digest", "solana-pubkey/rand", "dep:solana-keypair", + "dep:solana-offchain-message", "dep:solana-precompile-error", "dep:solana-presigner", "dep:solana-seed-derivable", @@ -81,7 +82,6 @@ log = { workspace = true } memmap2 = { workspace = true, optional = true } num-derive = { workspace = true } num-traits = { workspace = true } -num_enum = { workspace = true } qualifier_attr = { workspace = true, optional = true } rand = { workspace = true, optional = true } rand0-7 = { workspace = true, optional = true } @@ -110,6 +110,7 @@ solana-inflation = { workspace = true, features = ["serde"] } solana-instruction = { workspace = true } solana-keypair = { workspace = true, optional = true, features = ["seed-derivable"] } solana-native-token = { workspace = true } +solana-offchain-message = { workspace = true, optional = true } solana-packet = { workspace = true, features = ["bincode", "serde"] } solana-precompile-error = { workspace = true, optional = true } solana-presigner = { workspace = true, optional = true } diff --git a/sdk/offchain-message/Cargo.toml b/sdk/offchain-message/Cargo.toml new file mode 100644 index 00000000000000..c58be8f337d61a --- /dev/null +++ b/sdk/offchain-message/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "solana-offchain-message" +description = "Solana offchain message signing" +documentation = "https://docs.rs/solana-offchain-message" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +num_enum = { workspace = true } +solana-hash = { workspace = true } +solana-packet = { workspace = true } +solana-pubkey = { workspace = true, optional = true } +solana-sanitize = { workspace = true } +solana-sha256-hasher = { workspace = true } +solana-signature = { workspace = true } +solana-signer = { workspace = true } + +[dev-dependencies] +solana-keypair = { workspace = true } +solana-offchain-message = { path = ".", features = ["dev-context-only-utils"] } +static_assertions = { workspace = true } + +[features] +dev-context-only-utils = ["verify"] +verify = ["dep:solana-pubkey", "solana-signature/verify"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/src/offchain_message.rs b/sdk/offchain-message/src/lib.rs similarity index 96% rename from sdk/src/offchain_message.rs rename to sdk/offchain-message/src/lib.rs index 8214fff91951d9..131e09e9e73b40 100644 --- a/sdk/src/offchain_message.rs +++ b/sdk/offchain-message/src/lib.rs @@ -1,15 +1,11 @@ //! Off-chain message container for storing non-transaction messages. -#![cfg(feature = "full")] - use { - crate::{ - hash::Hash, - pubkey::Pubkey, - signature::{Signature, Signer}, - }, num_enum::{IntoPrimitive, TryFromPrimitive}, + solana_hash::Hash, solana_sanitize::SanitizeError, + solana_signature::Signature, + solana_signer::Signer, }; #[cfg(test)] @@ -46,11 +42,10 @@ pub enum MessageFormat { pub mod v0 { use { super::{is_printable_ascii, is_utf8, MessageFormat, OffchainMessage as Base}, - crate::{ - hash::{Hash, Hasher}, - packet::PACKET_DATA_SIZE, - }, + solana_hash::Hash, + solana_packet::PACKET_DATA_SIZE, solana_sanitize::SanitizeError, + solana_sha256_hasher::Hasher, }; /// OffchainMessage Version 0. @@ -239,15 +234,20 @@ impl OffchainMessage { Ok(signer.sign_message(&self.serialize()?)) } + #[cfg(feature = "verify")] /// Verify that the message signature is valid for the given public key - pub fn verify(&self, signer: &Pubkey, signature: &Signature) -> Result { + pub fn verify( + &self, + signer: &solana_pubkey::Pubkey, + signature: &Signature, + ) -> Result { Ok(signature.verify(signer.as_ref(), &self.serialize()?)) } } #[cfg(test)] mod tests { - use {super::*, crate::signature::Keypair, std::str::FromStr}; + use {super::*, solana_keypair::Keypair, std::str::FromStr}; #[test] fn test_offchain_message_ascii() { diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 7a67f719523cbd..6a7276d980c15a 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -80,7 +80,6 @@ pub mod log; pub mod native_loader; pub mod net; pub mod nonce_account; -pub mod offchain_message; pub mod poh_config; pub mod precompiles; pub mod program_utils; @@ -128,6 +127,9 @@ pub use solana_feature_set as feature_set; pub use solana_fee_structure as fee; #[deprecated(since = "2.1.0", note = "Use `solana-inflation` crate instead")] pub use solana_inflation as inflation; +#[cfg(feature = "full")] +#[deprecated(since = "2.1.0", note = "Use `solana-offchain-message` crate instead")] +pub use solana_offchain_message as offchain_message; #[deprecated(since = "2.1.0", note = "Use `solana-packet` crate instead")] pub use solana_packet as packet; #[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")]