diff --git a/Cargo.lock b/Cargo.lock index 641b9e9a..392e1a85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,12 @@ version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes-lit" version = "0.0.5" @@ -189,6 +195,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "crate-git-revision" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54851b5b3f24621804b1cded2820975623c205e3055d2d44031cdb1237339ac8" +dependencies = [ + "serde", + "serde_derive", + "serde_json", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -367,6 +384,15 @@ dependencies = [ "wasi", ] +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -379,6 +405,17 @@ version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" +[[package]] +name = "heapless" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ba4bd83f9415b58b4ed8dc5714c76e626a105be4646c02630ad730ad3b5aa4" +dependencies = [ + "hash32", + "stable_deref_trait", + "zeroize", +] + [[package]] name = "heck" version = "0.4.0" @@ -713,14 +750,22 @@ dependencies = [ "digest", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "stellar-strkey" -version = "0.0.13" +version = "0.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee1832fb50c651ad10f734aaf5d31ca5acdfb197a6ecda64d93fcdb8885af913" +checksum = "0f34ff61c0ca6f1c2b4169e8d1633417bd9225f58b6175e4e317204565d16277" dependencies = [ - "crate-git-revision", + "crate-git-revision 0.0.9", "data-encoding", + "heapless", + "zeroize", ] [[package]] @@ -732,7 +777,7 @@ dependencies = [ "bytes-lit", "cfg_eval", "clap", - "crate-git-revision", + "crate-git-revision 0.0.6", "escape-bytes", "ethnum", "hex", @@ -980,3 +1025,23 @@ dependencies = [ "quote", "syn 2.0.101", ] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] diff --git a/Cargo.toml b/Cargo.toml index e497f31a..78a9c588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Stellar Development Foundation "] license = "Apache-2.0" version = "27.0.0" edition = "2021" -rust-version = "1.84.0" +rust-version = "1.87.0" [[bin]] name = "stellar-xdr" @@ -20,7 +20,7 @@ crate-git-revision = "0.0.6" [dependencies] cfg_eval = { version = "0.1.2", optional = true } -stellar-strkey = { version = "0.0.13", optional = true } +stellar-strkey = { version = "0.0.18", optional = true } base64 = { version = "0.22.1", optional = true } serde = { version = "1.0.139", features = ["derive"], optional = true } serde_with = { version = "3.12.0", features = ["schemars_0_8"], optional = true } diff --git a/src/lib.rs b/src/lib.rs index 21635663..ecf86428 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,8 @@ #![allow(clippy::tabs_in_doc_comments)] #![allow(clippy::doc_markdown)] #![allow(clippy::doc_lazy_continuation)] +#![allow(clippy::unnecessary_semicolon)] +#![allow(clippy::non_std_lazy_statics)] #![allow(unused_attributes)] //! Library and CLI containing types and functionality for working with Stellar diff --git a/src/str.rs b/src/str.rs index 26cff8bd..3d8dbd0b 100644 --- a/src/str.rs +++ b/src/str.rs @@ -160,8 +160,7 @@ impl core::str::FromStr for MuxedAccount { ed25519: Uint256(ed25519), id, })), - stellar_strkey::Strkey::PrivateKeyEd25519(_) - | stellar_strkey::Strkey::PreAuthTx(_) + stellar_strkey::Strkey::PreAuthTx(_) | stellar_strkey::Strkey::HashX(_) | stellar_strkey::Strkey::SignedPayloadEd25519(_) | stellar_strkey::Strkey::Contract(_) @@ -204,10 +203,8 @@ impl core::fmt::Display for SignerKeyEd25519SignedPayload { ed25519: Uint256(ed25519), payload, } = self; - let k = stellar_strkey::ed25519::SignedPayload { - ed25519: *ed25519, - payload: payload.into(), - }; + let k = stellar_strkey::ed25519::SignedPayload::new(*ed25519, payload.as_ref()) + .map_err(|_| core::fmt::Error)?; let s = k.to_string(); f.write_str(&s)?; Ok(()) @@ -217,11 +214,10 @@ impl core::fmt::Display for SignerKeyEd25519SignedPayload { impl core::str::FromStr for SignerKeyEd25519SignedPayload { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let stellar_strkey::ed25519::SignedPayload { ed25519, payload } = - stellar_strkey::ed25519::SignedPayload::from_str(s)?; + let sp = stellar_strkey::ed25519::SignedPayload::from_str(s)?; Ok(SignerKeyEd25519SignedPayload { - ed25519: Uint256(ed25519), - payload: payload.try_into()?, + ed25519: Uint256(*sp.ed25519()), + payload: sp.payload().try_into()?, }) } } @@ -240,16 +236,13 @@ impl core::str::FromStr for SignerKey { stellar_strkey::Strkey::HashX(stellar_strkey::HashX(h)) => { Ok(SignerKey::HashX(Uint256(h))) } - stellar_strkey::Strkey::SignedPayloadEd25519( - stellar_strkey::ed25519::SignedPayload { ed25519, payload }, - ) => Ok(SignerKey::Ed25519SignedPayload( - SignerKeyEd25519SignedPayload { - ed25519: Uint256(ed25519), - payload: payload.try_into()?, - }, - )), - stellar_strkey::Strkey::PrivateKeyEd25519(_) - | stellar_strkey::Strkey::Contract(_) + stellar_strkey::Strkey::SignedPayloadEd25519(sp) => Ok( + SignerKey::Ed25519SignedPayload(SignerKeyEd25519SignedPayload { + ed25519: Uint256(*sp.ed25519()), + payload: sp.payload().try_into()?, + }), + ), + stellar_strkey::Strkey::Contract(_) | stellar_strkey::Strkey::MuxedAccountEd25519(_) | stellar_strkey::Strkey::LiquidityPool(_) | stellar_strkey::Strkey::ClaimableBalance(_) => Err(Error::Invalid), @@ -332,8 +325,7 @@ impl core::str::FromStr for ScAddress { )) => Ok(ScAddress::ClaimableBalance( ClaimableBalanceId::ClaimableBalanceIdTypeV0(Hash(claimable_balance)), )), - stellar_strkey::Strkey::PrivateKeyEd25519(_) - | stellar_strkey::Strkey::PreAuthTx(_) + stellar_strkey::Strkey::PreAuthTx(_) | stellar_strkey::Strkey::HashX(_) | stellar_strkey::Strkey::SignedPayloadEd25519(_) => Err(Error::Invalid), }