1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! Encode and decode [Stellar strkeys] as defined by [SEP-23].
//!
//! Strkeys are the human-readable textual representation of identifiers used
//! across the Stellar network — account IDs, signing keys, contract IDs,
//! liquidity pool IDs, and others. Each strkey begins with a single ASCII
//! letter that identifies its kind (`G`, `S`, `M`, `T`, `X`, `P`, `C`, `L`,
//! `B`) and is encoded as base32 without padding. The binary form is a
//! one-byte version, the type's payload, and a two-byte CRC16-XMODEM
//! checksum, ensuring that mistyped strkeys are detected before they are
//! used.
//!
//! This crate provides:
//!
//! - The [`Strkey`] enum, which can hold and round-trip any strkey kind
//! other than `PrivateKeyEd25519` (`S…`); private-key strkeys are
//! handled directly via [`ed25519::PrivateKey`], with rendering gated
//! behind [`Unredacted`].
//! - Per-kind types in this module ([`PreAuthTx`], [`HashX`], [`Contract`],
//! [`LiquidityPool`], [`ClaimableBalance`]) and in [`ed25519`]
//! ([`ed25519::PublicKey`], [`ed25519::PrivateKey`],
//! [`ed25519::MuxedAccount`], [`ed25519::SignedPayload`]) for callers that
//! know the kind in advance.
//! - [`Display`](core::fmt::Display) and [`FromStr`](core::str::FromStr)
//! implementations for every kind, plus inherent `to_string` /
//! `from_string` / `from_slice` methods. [`ed25519::PrivateKey`] is the
//! exception: it does not implement `Display` or inherent `to_string`
//! directly — wrap it in [`Unredacted`] (`pk.as_unredacted()`) to render
//! the encoded strkey form.
//!
//! # Strkey kinds
//!
//! | Prefix | Kind | Payload bytes |
//! |--------|-----------------------------------------------------------------------|---------------|
//! | `G` | [`Strkey::PublicKeyEd25519`] / [`ed25519::PublicKey`] | 32 |
//! | `S` | [`ed25519::PrivateKey`] only (omitted from [`Strkey`]) | 32 |
//! | `M` | [`Strkey::MuxedAccountEd25519`] / [`ed25519::MuxedAccount`] | 40 |
//! | `T` | [`Strkey::PreAuthTx`] / [`PreAuthTx`] | 32 |
//! | `X` | [`Strkey::HashX`] / [`HashX`] | 32 |
//! | `P` | [`Strkey::SignedPayloadEd25519`] / [`ed25519::SignedPayload`] | 40–100 |
//! | `C` | [`Strkey::Contract`] / [`Contract`] | 32 |
//! | `L` | [`Strkey::LiquidityPool`] / [`LiquidityPool`] | 32 |
//! | `B` | [`Strkey::ClaimableBalance`] / [`ClaimableBalance`] | 33 |
//!
//! # Examples
//!
//! Parse any strkey when the kind isn't known up front:
//!
//! ```
//! use stellar_strkey::Strkey;
//!
//! let s = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF";
//! let strkey: Strkey = s.parse().unwrap();
//! assert!(matches!(strkey, Strkey::PublicKeyEd25519(_)));
//! ```
//!
//! Parse a specific kind and reject anything else:
//!
//! ```
//! use stellar_strkey::Contract;
//!
//! let s = "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4";
//! let contract: Contract = s.parse().unwrap();
//! assert_eq!(contract.0, [0u8; 32]);
//! ```
//!
//! Construct a strkey from raw bytes and render it:
//!
//! ```
//! use stellar_strkey::ed25519::PublicKey;
//!
//! let key = PublicKey([0u8; 32]);
//! assert_eq!(
//! key.to_string().as_str(),
//! "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
//! );
//! ```
//!
//! # `no_std`
//!
//! With default features the crate is `no_std` and does not depend on
//! `alloc`. Encoding uses fixed-capacity buffers from the `heapless` crate,
//! so each kind's `to_string` returns a `heapless::String` sized to the
//! maximum length for that kind.
//!
//! # Cargo features
//!
//! - `serde` — derives [`Serialize`]/[`Deserialize`] that round-trip strkeys
//! as their textual form. [`ed25519::PrivateKey`] is `Deserialize` but
//! not directly `Serialize`; wrap in [`Unredacted`] to serialize.
//! - `serde-decoded` — adds a `Decoded<T>` wrapper that serializes a strkey
//! as a structured JSON object with hex-encoded byte fields, which is
//! useful for tooling that wants to inspect the underlying bytes. Requires
//! `alloc` and implies `serde`.
//! - `cli` — builds the `stellar-strkey` binary for encoding and decoding
//! strkeys from the command line. Requires `std` (disables `no_std` for
//! the crate). Not intended for enabling with the library.
//!
//! [Stellar strkeys]: https://developers.stellar.org/docs/learn/glossary#strkey
//! [SEP-23]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
//! [`Serialize`]: https://docs.rs/serde/latest/serde/trait.Serialize.html
//! [`Deserialize`]: https://docs.rs/serde/latest/serde/trait.Deserialize.html
extern crate alloc;
pub const VERSION: Version = Version ;
pub use *;
pub use *;
pub use Unredacted;
pub use Decoded;