sui_sdk_types/
lib.rs

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#![cfg_attr(doc_cfg, feature(doc_cfg))]

#[cfg(feature = "hash")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "hash")))]
pub mod hash;

mod address;
mod checkpoint;
mod crypto;
mod digest;
mod effects;
mod events;
mod execution_status;
pub mod framework;
mod gas;
mod object;
mod object_id;
mod transaction;
mod type_tag;
mod u256;

pub use address::Address;
pub use address::AddressParseError;
pub use checkpoint::CheckpointCommitment;
pub use checkpoint::CheckpointContents;
pub use checkpoint::CheckpointData;
pub use checkpoint::CheckpointSequenceNumber;
pub use checkpoint::CheckpointSummary;
pub use checkpoint::CheckpointTimestamp;
pub use checkpoint::CheckpointTransaction;
pub use checkpoint::CheckpointTransactionInfo;
pub use checkpoint::EndOfEpochData;
pub use checkpoint::EpochId;
pub use checkpoint::ProtocolVersion;
pub use checkpoint::SignedCheckpointSummary;
pub use checkpoint::StakeUnit;
pub use crypto::Bls12381PublicKey;
pub use crypto::Bls12381Signature;
pub use crypto::Bn254FieldElement;
pub use crypto::CircomG1;
pub use crypto::CircomG2;
pub use crypto::Claim;
pub use crypto::Ed25519PublicKey;
pub use crypto::Ed25519Signature;
pub use crypto::Intent;
pub use crypto::IntentAppId;
pub use crypto::IntentScope;
pub use crypto::IntentVersion;
pub use crypto::Jwk;
pub use crypto::JwkId;
pub use crypto::MultisigAggregatedSignature;
pub use crypto::MultisigCommittee;
pub use crypto::MultisigMember;
pub use crypto::MultisigMemberPublicKey;
pub use crypto::MultisigMemberSignature;
pub use crypto::PasskeyAuthenticator;
pub use crypto::PasskeyPublicKey;
pub use crypto::Secp256k1PublicKey;
pub use crypto::Secp256k1Signature;
pub use crypto::Secp256r1PublicKey;
pub use crypto::Secp256r1Signature;
pub use crypto::SignatureScheme;
pub use crypto::SimpleSignature;
pub use crypto::UserSignature;
pub use crypto::ValidatorAggregatedSignature;
pub use crypto::ValidatorCommittee;
pub use crypto::ValidatorCommitteeMember;
pub use crypto::ValidatorSignature;
pub use crypto::ZkLoginAuthenticator;
pub use crypto::ZkLoginInputs;
pub use crypto::ZkLoginProof;
pub use crypto::ZkLoginPublicIdentifier;
pub use digest::CheckpointContentsDigest;
pub use digest::CheckpointDigest;
pub use digest::ConsensusCommitDigest;
pub use digest::Digest;
pub use digest::DigestParseError;
pub use digest::EffectsAuxiliaryDataDigest;
pub use digest::ObjectDigest;
pub use digest::SigningDigest;
pub use digest::TransactionDigest;
pub use digest::TransactionEffectsDigest;
pub use digest::TransactionEventsDigest;
pub use effects::ChangedObject;
pub use effects::IdOperation;
pub use effects::ModifiedAtVersion;
pub use effects::ObjectIn;
pub use effects::ObjectOut;
pub use effects::ObjectReferenceWithOwner;
pub use effects::TransactionEffects;
pub use effects::TransactionEffectsV1;
pub use effects::TransactionEffectsV2;
pub use effects::UnchangedSharedKind;
pub use effects::UnchangedSharedObject;
pub use events::BalanceChange;
pub use events::Event;
pub use events::TransactionEvents;
pub use execution_status::CommandArgumentError;
pub use execution_status::ExecutionError;
pub use execution_status::ExecutionStatus;
pub use execution_status::MoveLocation;
pub use execution_status::PackageUpgradeError;
pub use execution_status::TypeArgumentError;
pub use gas::GasCostSummary;
pub use object::GenesisObject;
pub use object::MovePackage;
pub use object::MoveStruct;
pub use object::Object;
pub use object::ObjectData;
pub use object::ObjectReference;
pub use object::ObjectType;
pub use object::Owner;
pub use object::TypeOrigin;
pub use object::UpgradeInfo;
pub use object::Version;
pub use object_id::ObjectId;
pub use transaction::ActiveJwk;
pub use transaction::Argument;
pub use transaction::AuthenticatorStateExpire;
pub use transaction::AuthenticatorStateUpdate;
pub use transaction::CancelledTransaction;
pub use transaction::ChangeEpoch;
pub use transaction::Command;
pub use transaction::ConsensusCommitPrologue;
pub use transaction::ConsensusCommitPrologueV2;
pub use transaction::ConsensusCommitPrologueV3;
pub use transaction::ConsensusDeterminedVersionAssignments;
pub use transaction::EndOfEpochTransactionKind;
pub use transaction::GasPayment;
pub use transaction::GenesisTransaction;
pub use transaction::Input;
pub use transaction::MakeMoveVector;
pub use transaction::MergeCoins;
pub use transaction::MoveCall;
pub use transaction::ProgrammableTransaction;
pub use transaction::Publish;
pub use transaction::RandomnessStateUpdate;
pub use transaction::SignedTransaction;
pub use transaction::SplitCoins;
pub use transaction::SystemPackage;
pub use transaction::Transaction;
pub use transaction::TransactionExpiration;
pub use transaction::TransactionKind;
pub use transaction::TransferObjects;
pub use transaction::Upgrade;
pub use transaction::VersionAssignment;
pub use type_tag::Identifier;
pub use type_tag::StructTag;
pub use type_tag::TypeParseError;
pub use type_tag::TypeTag;

#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
pub(crate) use transaction::SignedTransactionWithIntentMessage;

#[cfg(test)]
mod serialization_proptests;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PersonalMessage<'a>(pub std::borrow::Cow<'a, [u8]>);

#[cfg(feature = "serde")]
mod _serde {
    use base64ct::Base64;
    use base64ct::Encoding;
    use serde::Deserialize;
    use serde::Deserializer;
    use serde::Serialize;
    use serde::Serializer;
    use serde_with::Bytes;
    use serde_with::DeserializeAs;
    use serde_with::SerializeAs;
    use std::borrow::Cow;

    pub(crate) type ReadableDisplay =
        ::serde_with::As<::serde_with::IfIsHumanReadable<::serde_with::DisplayFromStr>>;

    pub(crate) type OptionReadableDisplay =
        ::serde_with::As<Option<::serde_with::IfIsHumanReadable<::serde_with::DisplayFromStr>>>;

    pub(crate) type ReadableBase64Encoded =
        ::serde_with::As<::serde_with::IfIsHumanReadable<Base64Encoded, ::serde_with::Bytes>>;

    pub(crate) struct Base64Encoded;

    impl<T: AsRef<[u8]>> SerializeAs<T> for Base64Encoded {
        fn serialize_as<S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            let bytes = source.as_ref();
            let b64 = Base64::encode_string(bytes);
            b64.serialize(serializer)
        }
    }

    impl<'de, T: TryFrom<Vec<u8>>> DeserializeAs<'de, T> for Base64Encoded {
        fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error>
        where
            D: Deserializer<'de>,
        {
            let b64: Cow<'de, str> = Deserialize::deserialize(deserializer)?;
            let bytes = Base64::decode_vec(&b64).map_err(serde::de::Error::custom)?;
            let length = bytes.len();
            T::try_from(bytes).map_err(|_| {
                serde::de::Error::custom(format_args!(
                    "Can't convert a Byte Vector of length {length} to the output type."
                ))
            })
        }
    }

    /// Serializes a bitmap according to the roaring bitmap on-disk standard.
    /// <https://github.com/RoaringBitmap/RoaringFormatSpec>
    pub(crate) struct BinaryRoaringBitmap;

    impl SerializeAs<roaring::RoaringBitmap> for BinaryRoaringBitmap {
        fn serialize_as<S>(
            source: &roaring::RoaringBitmap,
            serializer: S,
        ) -> Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            let mut bytes = vec![];

            source
                .serialize_into(&mut bytes)
                .map_err(serde::ser::Error::custom)?;
            Bytes::serialize_as(&bytes, serializer)
        }
    }

    impl<'de> DeserializeAs<'de, roaring::RoaringBitmap> for BinaryRoaringBitmap {
        fn deserialize_as<D>(deserializer: D) -> Result<roaring::RoaringBitmap, D::Error>
        where
            D: Deserializer<'de>,
        {
            let bytes: Cow<'de, [u8]> = Bytes::deserialize_as(deserializer)?;
            roaring::RoaringBitmap::deserialize_from(&bytes[..]).map_err(serde::de::Error::custom)
        }
    }

    pub(crate) struct Base64RoaringBitmap;

    impl SerializeAs<roaring::RoaringBitmap> for Base64RoaringBitmap {
        fn serialize_as<S>(
            source: &roaring::RoaringBitmap,
            serializer: S,
        ) -> Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            let mut bytes = vec![];

            source
                .serialize_into(&mut bytes)
                .map_err(serde::ser::Error::custom)?;
            let b64 = Base64::encode_string(&bytes);
            b64.serialize(serializer)
        }
    }

    impl<'de> DeserializeAs<'de, roaring::RoaringBitmap> for Base64RoaringBitmap {
        fn deserialize_as<D>(deserializer: D) -> Result<roaring::RoaringBitmap, D::Error>
        where
            D: Deserializer<'de>,
        {
            let b64: Cow<'de, str> = Deserialize::deserialize(deserializer)?;
            let bytes = Base64::decode_vec(&b64).map_err(serde::de::Error::custom)?;
            roaring::RoaringBitmap::deserialize_from(&bytes[..]).map_err(serde::de::Error::custom)
        }
    }

    pub(crate) use super::SignedTransactionWithIntentMessage;
}