From 7f7d698b706c04ebcfbd2066a6499d1d1f934856 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 2 Nov 2024 19:06:41 +0400 Subject: [PATCH 1/8] extract offchain-message crate --- Cargo.lock | 19 ++++++++++- Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 15 ++++++++- sdk/Cargo.toml | 3 +- sdk/offchain-message/Cargo.toml | 32 +++++++++++++++++++ .../src/lib.rs} | 26 +++++++-------- sdk/src/lib.rs | 4 +++ svm/examples/Cargo.lock | 15 ++++++++- 8 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 sdk/offchain-message/Cargo.toml rename sdk/{src/offchain_message.rs => offchain-message/src/lib.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index fa207f9103fc37..960b395df8d9cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7675,6 +7675,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" @@ -8536,7 +8553,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "openssl", "qualifier_attr", "rand 0.7.3", @@ -8568,6 +8584,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 4eb6e6bbe29e92..77f489af6ebfdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -140,6 +140,7 @@ members = [ "sdk/msg", "sdk/native-token", "sdk/nonce", + "sdk/offchain-message", "sdk/package-metadata", "sdk/package-metadata-macro", "sdk/packet", @@ -507,6 +508,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 655ab1471f4066..dae67961c1a4b0 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -6052,6 +6052,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" @@ -7232,7 +7245,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "qualifier_attr", "rand 0.7.3", "rand 0.8.5", @@ -7260,6 +7272,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..5904e740b51867 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 } 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..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 9b81f1ca316b8c..dcb7dc1df91bf2 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -77,6 +77,7 @@ 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; pub mod pubkey; @@ -130,6 +131,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.2.0", note = "Use `solana-poh-config` crate instead")] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index c61a01f945fe01..8638ea7713ee73 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5872,6 +5872,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" @@ -6561,7 +6574,6 @@ dependencies = [ "memmap2", "num-derive", "num-traits", - "num_enum", "rand 0.7.3", "rand 0.8.5", "serde", @@ -6588,6 +6600,7 @@ dependencies = [ "solana-instruction", "solana-keypair", "solana-native-token", + "solana-offchain-message", "solana-packet", "solana-poh-config", "solana-precompile-error", From e0dc1f1115a179a697d04edb89ba53eab10741e0 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 2 Nov 2024 19:36:42 +0400 Subject: [PATCH 2/8] missing feature activation --- programs/sbf/Cargo.lock | 1 + sdk/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index dae67961c1a4b0..cebbf9bd73ebd1 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -6059,6 +6059,7 @@ dependencies = [ "num_enum", "solana-hash", "solana-packet", + "solana-pubkey", "solana-sanitize", "solana-sha256-hasher", "solana-signature", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 5904e740b51867..56c09d745d4364 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -146,7 +146,7 @@ solana-keypair = { workspace = true, optional = true, features = [ "seed-derivable", ] } solana-native-token = { workspace = true } -solana-offchain-message = { workspace = true, optional = 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 } From 03f5c7052b9107890f5e3576b8d09d400a186d07 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 4 Dec 2024 22:46:35 +0400 Subject: [PATCH 3/8] update lock file --- svm/examples/Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 8638ea7713ee73..41b751ad256778 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5879,6 +5879,7 @@ dependencies = [ "num_enum", "solana-hash", "solana-packet", + "solana-pubkey", "solana-sanitize", "solana-sha256-hasher", "solana-signature", From 29021c74704f79d7e60afe5d958305129b95ab50 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 5 Dec 2024 18:03:32 +0400 Subject: [PATCH 4/8] remove accidental change --- sdk/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index dcb7dc1df91bf2..02d30e09050c58 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 poh_config; pub mod precompiles; pub mod program_utils; From cc9b62c926a3ba9ecf90ea603a2a96d7a8025b0a Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 5 Dec 2024 18:03:51 +0400 Subject: [PATCH 5/8] update deprecation --- sdk/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 02d30e09050c58..a5ee8f5e06cb6e 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -131,7 +131,7 @@ 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")] +#[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; From 857353c14da84fe1692203f337e761a9a1263fc8 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 5 Dec 2024 18:49:32 +0400 Subject: [PATCH 6/8] remove another accidental change --- sdk/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index a5ee8f5e06cb6e..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 poh_config; pub mod precompiles; pub mod program_utils; pub mod pubkey; From 03833941b8e1d35759040a9f5e83ad8ad3ed3c7e Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Fri, 6 Dec 2024 16:58:43 +0400 Subject: [PATCH 7/8] add missing metadata Co-authored-by: Jon C --- sdk/offchain-message/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/offchain-message/Cargo.toml b/sdk/offchain-message/Cargo.toml index c58be8f337d61a..ece2bf34b69dad 100644 --- a/sdk/offchain-message/Cargo.toml +++ b/sdk/offchain-message/Cargo.toml @@ -30,3 +30,5 @@ verify = ["dep:solana-pubkey", "solana-signature/verify"] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] From ebcc9a2fab45a74de1207b92c6b6f851534bccc0 Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Fri, 6 Dec 2024 16:58:58 +0400 Subject: [PATCH 8/8] add doc_auto_cfg Co-authored-by: Jon C --- sdk/offchain-message/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/offchain-message/src/lib.rs b/sdk/offchain-message/src/lib.rs index 131e09e9e73b40..75afda50c5686d 100644 --- a/sdk/offchain-message/src/lib.rs +++ b/sdk/offchain-message/src/lib.rs @@ -1,5 +1,5 @@ //! Off-chain message container for storing non-transaction messages. - +#![cfg_attr(docsrs, feature(doc_auto_cfg))] use { num_enum::{IntoPrimitive, TryFromPrimitive}, solana_hash::Hash,