diff --git a/Cargo.lock b/Cargo.lock index 614e0928baff46..8b3a119838d3e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7695,6 +7695,23 @@ dependencies = [ "solana-hash", ] +[[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" @@ -8590,7 +8607,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "openssl", "qualifier_attr", "rand 0.7.3", @@ -8622,6 +8638,7 @@ dependencies = [ "solana-keypair", "solana-logger", "solana-native-token", + "solana-offchain-message", "solana-packet", "solana-poh-config", "solana-precompile-error", diff --git a/Cargo.toml b/Cargo.toml index 71e2d5e25ea5b5..21684e6126f9d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -141,6 +141,7 @@ members = [ "sdk/msg", "sdk/native-token", "sdk/nonce", + "sdk/offchain-message", "sdk/package-metadata", "sdk/package-metadata-macro", "sdk/packet", @@ -509,6 +510,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 0c65ffee745c0d..29d9aa591f4948 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -6069,6 +6069,20 @@ dependencies = [ "solana-sha256-hasher", ] +[[package]] +name = "solana-offchain-message" +version = "2.2.0" +dependencies = [ + "num_enum", + "solana-hash", + "solana-packet", + "solana-pubkey", + "solana-sanitize", + "solana-sha256-hasher", + "solana-signature", + "solana-signer", +] + [[package]] name = "solana-packet" version = "2.2.0" @@ -7280,7 +7294,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "qualifier_attr", "rand 0.7.3", "rand 0.8.5", @@ -7308,6 +7321,7 @@ dependencies = [ "solana-instruction", "solana-keypair", "solana-native-token", + "solana-offchain-message", "solana-packet", "solana-poh-config", "solana-precompile-error", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 4dabd2cb4d83eb..56c09d745d4364 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -40,6 +40,7 @@ full = [ "dep:solana-ed25519-program", "dep:solana-compute-budget-interface", "dep:solana-keypair", + "dep:solana-offchain-message", "dep:solana-precompile-error", "dep:solana-precompiles", "dep:solana-presigner", @@ -104,7 +105,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 } @@ -146,6 +146,7 @@ solana-keypair = { workspace = true, optional = true, features = [ "seed-derivable", ] } solana-native-token = { workspace = true } +solana-offchain-message = { workspace = true, optional = true, features = ["verify"] } solana-packet = { workspace = true, features = ["bincode", "serde"] } solana-poh-config = { workspace = true, features = ["serde"] } solana-precompile-error = { workspace = true, optional = true } diff --git a/sdk/offchain-message/Cargo.toml b/sdk/offchain-message/Cargo.toml new file mode 100644 index 00000000000000..ece2bf34b69dad --- /dev/null +++ b/sdk/offchain-message/Cargo.toml @@ -0,0 +1,34 @@ +[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"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] diff --git a/sdk/src/offchain_message.rs b/sdk/offchain-message/src/lib.rs similarity index 95% rename from sdk/src/offchain_message.rs rename to sdk/offchain-message/src/lib.rs index 8214fff91951d9..75afda50c5686d 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")] - +#![cfg_attr(docsrs, feature(doc_auto_cfg))] 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 9b81f1ca316b8c..ac7f74fd95a9e2 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -76,7 +76,6 @@ pub mod log; pub mod native_loader; pub mod net; pub mod nonce_account; -pub mod offchain_message; pub mod precompiles; pub mod program_utils; pub mod pubkey; @@ -130,6 +129,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.2.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.2.0", note = "Use `solana-poh-config` crate instead")] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index e8260c3a279114..b3c445209bb16c 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5889,6 +5889,20 @@ dependencies = [ "solana-sha256-hasher", ] +[[package]] +name = "solana-offchain-message" +version = "2.2.0" +dependencies = [ + "num_enum", + "solana-hash", + "solana-packet", + "solana-pubkey", + "solana-sanitize", + "solana-sha256-hasher", + "solana-signature", + "solana-signer", +] + [[package]] name = "solana-packet" version = "2.2.0" @@ -6602,7 +6616,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "rand 0.7.3", "rand 0.8.5", "serde", @@ -6629,6 +6642,7 @@ dependencies = [ "solana-instruction", "solana-keypair", "solana-native-token", + "solana-offchain-message", "solana-packet", "solana-poh-config", "solana-precompile-error",