sui_types/
sui_sdk_types_conversions.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Module for conversions between sui-core types and sui-sdk types
5//!
6//! For now this module makes heavy use of the `bcs_convert_impl` macro to implement the `From` trait
7//! for converting between core and external sdk types, relying on the fact that the BCS format of
8//! these types are strictly identical. As time goes on we'll slowly hand implement these impls
9//! directly to avoid going through the BCS machinery.
10
11use fastcrypto::traits::ToFromBytes;
12use sui_sdk_types::{
13    self, ActiveJwk, Address, Argument, AuthenticatorStateExpire, Bitmap, Bls12381PublicKey,
14    Bls12381Signature, CanceledTransaction, CanceledTransactionV2, ChangeEpoch,
15    CheckpointCommitment, CheckpointContents, CheckpointData, CheckpointSummary, Command,
16    CommandArgumentError, ConsensusDeterminedVersionAssignments, Digest, Ed25519PublicKey,
17    Ed25519Signature, EndOfEpochTransactionKind, ExecutionError, ExecutionStatus,
18    ExecutionTimeObservationKey, ExecutionTimeObservations, IdOperation, Identifier, Input, Jwk,
19    JwkId, MakeMoveVector, MergeCoins, MoveCall, MoveLocation, MovePackage,
20    MultisigMemberPublicKey, MultisigMemberSignature, Object, ObjectIn, ObjectOut, ObjectReference,
21    Owner, PackageUpgradeError, PasskeyAuthenticator, PasskeyPublicKey, Publish,
22    Secp256k1PublicKey, Secp256k1Signature, Secp256r1PublicKey, Secp256r1Signature,
23    SignatureScheme, SignedCheckpointSummary, SignedTransaction, SimpleSignature, SplitCoins,
24    StructTag, SystemPackage, Transaction, TransactionEffects, TransactionEffectsV1,
25    TransactionEffectsV2, TransactionEvents, TransactionExpiration, TransactionKind,
26    TransferObjects, TypeArgumentError, TypeParseError, TypeTag, UnchangedConsensusKind, Upgrade,
27    UserSignature, ValidatorAggregatedSignature, ValidatorCommittee, ValidatorCommitteeMember,
28    ValidatorExecutionTimeObservation, VersionAssignment, VersionAssignmentV2,
29    ZkLoginAuthenticator, ZkLoginPublicIdentifier,
30};
31use tap::Pipe;
32
33use crate::crypto::SuiSignature as _;
34
35#[derive(Debug)]
36pub struct SdkTypeConversionError(String);
37
38impl std::fmt::Display for SdkTypeConversionError {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        f.write_str(&self.0)
41    }
42}
43
44impl std::error::Error for SdkTypeConversionError {}
45
46impl From<TypeParseError> for SdkTypeConversionError {
47    fn from(value: TypeParseError) -> Self {
48        Self(value.to_string())
49    }
50}
51
52impl From<anyhow::Error> for SdkTypeConversionError {
53    fn from(value: anyhow::Error) -> Self {
54        Self(value.to_string())
55    }
56}
57
58impl From<bcs::Error> for SdkTypeConversionError {
59    fn from(value: bcs::Error) -> Self {
60        Self(value.to_string())
61    }
62}
63
64impl From<std::array::TryFromSliceError> for SdkTypeConversionError {
65    fn from(value: std::array::TryFromSliceError) -> Self {
66        Self(value.to_string())
67    }
68}
69
70macro_rules! bcs_convert_impl {
71    ($core:ty, $external:ty) => {
72        impl TryFrom<$core> for $external {
73            type Error = bcs::Error;
74
75            fn try_from(value: $core) -> Result<Self, Self::Error> {
76                let bytes = bcs::to_bytes(&value)?;
77                bcs::from_bytes(&bytes)
78            }
79        }
80
81        impl TryFrom<$external> for $core {
82            type Error = bcs::Error;
83
84            fn try_from(value: $external) -> Result<Self, Self::Error> {
85                let bytes = bcs::to_bytes(&value)?;
86                bcs::from_bytes(&bytes)
87            }
88        }
89    };
90}
91
92bcs_convert_impl!(crate::object::Object, Object);
93bcs_convert_impl!(crate::transaction::TransactionData, Transaction);
94bcs_convert_impl!(crate::effects::TransactionEffectsV1, TransactionEffectsV1);
95bcs_convert_impl!(crate::effects::TransactionEffectsV2, TransactionEffectsV2);
96bcs_convert_impl!(
97    crate::messages_checkpoint::CheckpointSummary,
98    CheckpointSummary
99);
100bcs_convert_impl!(
101    crate::messages_checkpoint::CertifiedCheckpointSummary,
102    SignedCheckpointSummary
103);
104bcs_convert_impl!(
105    crate::messages_checkpoint::CheckpointContents,
106    CheckpointContents
107);
108bcs_convert_impl!(
109    crate::full_checkpoint_content::CheckpointData,
110    CheckpointData
111);
112bcs_convert_impl!(crate::signature::GenericSignature, UserSignature);
113bcs_convert_impl!(
114    crate::crypto::ZkLoginPublicIdentifier,
115    ZkLoginPublicIdentifier
116);
117bcs_convert_impl!(
118    crate::crypto::ZkLoginAuthenticatorAsBytes,
119    ZkLoginAuthenticator
120);
121bcs_convert_impl!(
122    crate::zk_login_authenticator::ZkLoginAuthenticator,
123    ZkLoginAuthenticator
124);
125bcs_convert_impl!(
126    crate::crypto::PasskeyAuthenticatorAsBytes,
127    PasskeyAuthenticator
128);
129bcs_convert_impl!(
130    crate::passkey_authenticator::PasskeyAuthenticator,
131    PasskeyAuthenticator
132);
133bcs_convert_impl!(crate::effects::TransactionEvents, TransactionEvents);
134bcs_convert_impl!(crate::transaction::TransactionKind, TransactionKind);
135bcs_convert_impl!(crate::move_package::MovePackage, MovePackage);
136
137impl<const T: bool> From<crate::crypto::AuthorityQuorumSignInfo<T>>
138    for ValidatorAggregatedSignature
139{
140    fn from(value: crate::crypto::AuthorityQuorumSignInfo<T>) -> Self {
141        let crate::crypto::AuthorityQuorumSignInfo {
142            epoch,
143            signature,
144            signers_map,
145        } = value;
146
147        Self {
148            epoch,
149            signature: Bls12381Signature::from_bytes(signature.as_ref()).unwrap(),
150            bitmap: Bitmap::from_iter(signers_map),
151        }
152    }
153}
154
155impl<const T: bool> From<ValidatorAggregatedSignature>
156    for crate::crypto::AuthorityQuorumSignInfo<T>
157{
158    fn from(value: ValidatorAggregatedSignature) -> Self {
159        let ValidatorAggregatedSignature {
160            epoch,
161            signature,
162            bitmap,
163        } = value;
164
165        Self {
166            epoch,
167            signature: crate::crypto::AggregateAuthoritySignature::from_bytes(signature.as_bytes())
168                .unwrap(),
169            signers_map: roaring::RoaringBitmap::from_iter(bitmap.iter()),
170        }
171    }
172}
173
174impl From<crate::object::Owner> for Owner {
175    fn from(value: crate::object::Owner) -> Self {
176        match value {
177            crate::object::Owner::AddressOwner(address) => Self::Address(address.into()),
178            crate::object::Owner::ObjectOwner(object_id) => Self::Object(object_id.into()),
179            crate::object::Owner::Shared {
180                initial_shared_version,
181            } => Self::Shared(initial_shared_version.value()),
182            crate::object::Owner::Immutable => Self::Immutable,
183            crate::object::Owner::ConsensusAddressOwner {
184                start_version,
185                owner,
186            } => Self::ConsensusAddress {
187                start_version: start_version.value(),
188                owner: owner.into(),
189            },
190        }
191    }
192}
193
194impl From<Owner> for crate::object::Owner {
195    fn from(value: Owner) -> Self {
196        match value {
197            Owner::Address(address) => crate::object::Owner::AddressOwner(address.into()),
198            Owner::Object(object_id) => crate::object::Owner::ObjectOwner(object_id.into()),
199            Owner::Shared(initial_shared_version) => crate::object::Owner::Shared {
200                initial_shared_version: initial_shared_version.into(),
201            },
202            Owner::Immutable => crate::object::Owner::Immutable,
203            Owner::ConsensusAddress {
204                start_version,
205                owner,
206            } => crate::object::Owner::ConsensusAddressOwner {
207                start_version: start_version.into(),
208                owner: owner.into(),
209            },
210            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
211        }
212    }
213}
214
215impl From<crate::base_types::SuiAddress> for Address {
216    fn from(value: crate::base_types::SuiAddress) -> Self {
217        Self::new(value.to_inner())
218    }
219}
220
221impl From<Address> for crate::base_types::SuiAddress {
222    fn from(value: Address) -> Self {
223        crate::base_types::ObjectID::new(value.into_inner()).into()
224    }
225}
226
227impl From<crate::base_types::ObjectID> for Address {
228    fn from(value: crate::base_types::ObjectID) -> Self {
229        Self::new(value.into_bytes())
230    }
231}
232
233impl From<Address> for crate::base_types::ObjectID {
234    fn from(value: Address) -> Self {
235        Self::new(value.into_inner())
236    }
237}
238
239impl TryFrom<crate::transaction::SenderSignedData> for SignedTransaction {
240    type Error = SdkTypeConversionError;
241
242    fn try_from(value: crate::transaction::SenderSignedData) -> Result<Self, Self::Error> {
243        let crate::transaction::SenderSignedTransaction {
244            intent_message,
245            tx_signatures,
246        } = value.into_inner();
247
248        Self {
249            transaction: intent_message.value.try_into()?,
250            signatures: tx_signatures
251                .into_iter()
252                .map(TryInto::try_into)
253                .collect::<Result<_, _>>()?,
254        }
255        .pipe(Ok)
256    }
257}
258
259impl TryFrom<SignedTransaction> for crate::transaction::SenderSignedData {
260    type Error = SdkTypeConversionError;
261
262    fn try_from(value: SignedTransaction) -> Result<Self, Self::Error> {
263        let SignedTransaction {
264            transaction,
265            signatures,
266        } = value;
267
268        Self::new(
269            transaction.try_into()?,
270            signatures
271                .into_iter()
272                .map(TryInto::try_into)
273                .collect::<Result<_, _>>()?,
274        )
275        .pipe(Ok)
276    }
277}
278
279impl TryFrom<crate::transaction::Transaction> for SignedTransaction {
280    type Error = SdkTypeConversionError;
281
282    fn try_from(value: crate::transaction::Transaction) -> Result<Self, Self::Error> {
283        value.into_data().try_into()
284    }
285}
286
287impl TryFrom<SignedTransaction> for crate::transaction::Transaction {
288    type Error = SdkTypeConversionError;
289
290    fn try_from(value: SignedTransaction) -> Result<Self, Self::Error> {
291        Ok(Self::new(value.try_into()?))
292    }
293}
294
295pub fn type_tag_core_to_sdk(
296    value: move_core_types::language_storage::TypeTag,
297) -> Result<TypeTag, SdkTypeConversionError> {
298    match value {
299        move_core_types::language_storage::TypeTag::Bool => TypeTag::Bool,
300        move_core_types::language_storage::TypeTag::U8 => TypeTag::U8,
301        move_core_types::language_storage::TypeTag::U64 => TypeTag::U64,
302        move_core_types::language_storage::TypeTag::U128 => TypeTag::U128,
303        move_core_types::language_storage::TypeTag::Address => TypeTag::Address,
304        move_core_types::language_storage::TypeTag::Signer => TypeTag::Signer,
305        move_core_types::language_storage::TypeTag::Vector(type_tag) => {
306            TypeTag::Vector(Box::new(type_tag_core_to_sdk(*type_tag)?))
307        }
308        move_core_types::language_storage::TypeTag::Struct(struct_tag) => {
309            TypeTag::Struct(Box::new(struct_tag_core_to_sdk(*struct_tag)?))
310        }
311        move_core_types::language_storage::TypeTag::U16 => TypeTag::U16,
312        move_core_types::language_storage::TypeTag::U32 => TypeTag::U32,
313        move_core_types::language_storage::TypeTag::U256 => TypeTag::U256,
314    }
315    .pipe(Ok)
316}
317
318pub fn struct_tag_core_to_sdk(
319    value: move_core_types::language_storage::StructTag,
320) -> Result<StructTag, SdkTypeConversionError> {
321    let move_core_types::language_storage::StructTag {
322        address,
323        module,
324        name,
325        type_params,
326    } = value;
327
328    let address = Address::new(address.into_bytes());
329    let module = Identifier::new(module.as_str())?;
330    let name = Identifier::new(name.as_str())?;
331    let type_params = type_params
332        .into_iter()
333        .map(type_tag_core_to_sdk)
334        .collect::<Result<_, _>>()?;
335    StructTag::new(address, module, name, type_params).pipe(Ok)
336}
337
338pub fn type_tag_sdk_to_core(
339    value: TypeTag,
340) -> Result<move_core_types::language_storage::TypeTag, SdkTypeConversionError> {
341    match value {
342        TypeTag::Bool => move_core_types::language_storage::TypeTag::Bool,
343        TypeTag::U8 => move_core_types::language_storage::TypeTag::U8,
344        TypeTag::U64 => move_core_types::language_storage::TypeTag::U64,
345        TypeTag::U128 => move_core_types::language_storage::TypeTag::U128,
346        TypeTag::Address => move_core_types::language_storage::TypeTag::Address,
347        TypeTag::Signer => move_core_types::language_storage::TypeTag::Signer,
348        TypeTag::Vector(type_tag) => move_core_types::language_storage::TypeTag::Vector(Box::new(
349            type_tag_sdk_to_core(*type_tag)?,
350        )),
351        TypeTag::Struct(struct_tag) => move_core_types::language_storage::TypeTag::Struct(
352            Box::new(struct_tag_sdk_to_core(*struct_tag)?),
353        ),
354        TypeTag::U16 => move_core_types::language_storage::TypeTag::U16,
355        TypeTag::U32 => move_core_types::language_storage::TypeTag::U32,
356        TypeTag::U256 => move_core_types::language_storage::TypeTag::U256,
357    }
358    .pipe(Ok)
359}
360
361pub fn struct_tag_sdk_to_core(
362    value: StructTag,
363) -> Result<move_core_types::language_storage::StructTag, SdkTypeConversionError> {
364    let address = value.address();
365    let module = value.module();
366    let name = value.name();
367    let type_params = value.type_params();
368
369    let address = move_core_types::account_address::AccountAddress::new(address.into_inner());
370    let module = move_core_types::identifier::Identifier::new(module.as_str())?;
371    let name = move_core_types::identifier::Identifier::new(name.as_str())?;
372    let type_params = type_params
373        .iter()
374        .cloned()
375        .map(type_tag_sdk_to_core)
376        .collect::<Result<_, _>>()?;
377    move_core_types::language_storage::StructTag {
378        address,
379        module,
380        name,
381        type_params,
382    }
383    .pipe(Ok)
384}
385
386impl TryFrom<crate::type_input::TypeInput> for TypeTag {
387    type Error = SdkTypeConversionError;
388
389    fn try_from(value: crate::type_input::TypeInput) -> Result<Self, Self::Error> {
390        match value {
391            crate::type_input::TypeInput::Bool => Self::Bool,
392            crate::type_input::TypeInput::U8 => Self::U8,
393            crate::type_input::TypeInput::U64 => Self::U64,
394            crate::type_input::TypeInput::U128 => Self::U128,
395            crate::type_input::TypeInput::Address => Self::Address,
396            crate::type_input::TypeInput::Signer => Self::Signer,
397            crate::type_input::TypeInput::Vector(type_input) => {
398                Self::Vector(Box::new((*type_input).try_into()?))
399            }
400            crate::type_input::TypeInput::Struct(struct_input) => {
401                Self::Struct(Box::new((*struct_input).try_into()?))
402            }
403            crate::type_input::TypeInput::U16 => Self::U16,
404            crate::type_input::TypeInput::U32 => Self::U32,
405            crate::type_input::TypeInput::U256 => Self::U256,
406        }
407        .pipe(Ok)
408    }
409}
410
411impl TryFrom<crate::type_input::StructInput> for StructTag {
412    type Error = SdkTypeConversionError;
413
414    fn try_from(value: crate::type_input::StructInput) -> Result<Self, Self::Error> {
415        Self::new(
416            Address::new(value.address.into_bytes()),
417            Identifier::new(value.module)?,
418            Identifier::new(value.name)?,
419            value
420                .type_params
421                .into_iter()
422                .map(TryInto::try_into)
423                .collect::<Result<_, _>>()?,
424        )
425        .pipe(Ok)
426    }
427}
428
429impl From<TypeTag> for crate::type_input::TypeInput {
430    fn from(value: TypeTag) -> Self {
431        match value {
432            TypeTag::U8 => Self::U8,
433            TypeTag::U16 => Self::U16,
434            TypeTag::U32 => Self::U32,
435            TypeTag::U64 => Self::U64,
436            TypeTag::U128 => Self::U128,
437            TypeTag::U256 => Self::U256,
438            TypeTag::Bool => Self::Bool,
439            TypeTag::Address => Self::Address,
440            TypeTag::Signer => Self::Signer,
441            TypeTag::Vector(type_tag) => Self::Vector(Box::new((*type_tag).into())),
442            TypeTag::Struct(struct_tag) => Self::Struct(Box::new((*struct_tag).into())),
443        }
444    }
445}
446
447impl From<StructTag> for crate::type_input::StructInput {
448    fn from(value: StructTag) -> Self {
449        Self {
450            address: move_core_types::account_address::AccountAddress::new(
451                value.address().into_inner(),
452            ),
453            module: value.module().as_str().into(),
454            name: value.name().as_str().into(),
455            type_params: value
456                .type_params()
457                .iter()
458                .cloned()
459                .map(crate::type_input::TypeInput::from)
460                .collect(),
461        }
462    }
463}
464
465impl From<crate::digests::ObjectDigest> for Digest {
466    fn from(value: crate::digests::ObjectDigest) -> Self {
467        Self::new(value.into_inner())
468    }
469}
470
471impl From<Digest> for crate::digests::ObjectDigest {
472    fn from(value: Digest) -> Self {
473        Self::new(value.into_inner())
474    }
475}
476
477impl From<crate::digests::TransactionDigest> for Digest {
478    fn from(value: crate::digests::TransactionDigest) -> Self {
479        Self::new(value.into_inner())
480    }
481}
482
483impl From<Digest> for crate::digests::TransactionDigest {
484    fn from(value: Digest) -> Self {
485        Self::new(value.into_inner())
486    }
487}
488
489impl From<crate::messages_checkpoint::CheckpointDigest> for Digest {
490    fn from(value: crate::messages_checkpoint::CheckpointDigest) -> Self {
491        Self::new(value.into_inner())
492    }
493}
494
495impl From<Digest> for crate::messages_checkpoint::CheckpointDigest {
496    fn from(value: Digest) -> Self {
497        Self::new(value.into_inner())
498    }
499}
500
501impl From<crate::digests::Digest> for Digest {
502    fn from(value: crate::digests::Digest) -> Self {
503        Self::new(value.into_inner())
504    }
505}
506
507impl From<Digest> for crate::digests::Digest {
508    fn from(value: Digest) -> Self {
509        Self::new(value.into_inner())
510    }
511}
512
513impl From<crate::digests::CheckpointArtifactsDigest> for Digest {
514    fn from(value: crate::digests::CheckpointArtifactsDigest) -> Self {
515        Self::new(value.into_inner())
516    }
517}
518
519impl From<Digest> for crate::digests::CheckpointArtifactsDigest {
520    fn from(value: Digest) -> Self {
521        Self::new(value.into_inner())
522    }
523}
524
525impl From<crate::committee::Committee> for ValidatorCommittee {
526    fn from(value: crate::committee::Committee) -> Self {
527        Self {
528            epoch: value.epoch(),
529            members: value
530                .voting_rights
531                .into_iter()
532                .map(|(name, stake)| ValidatorCommitteeMember {
533                    public_key: name.into(),
534                    stake,
535                })
536                .collect(),
537        }
538    }
539}
540
541impl From<ValidatorCommittee> for crate::committee::Committee {
542    fn from(value: ValidatorCommittee) -> Self {
543        let ValidatorCommittee { epoch, members } = value;
544
545        Self::new(
546            epoch,
547            members
548                .into_iter()
549                .map(|member| (member.public_key.into(), member.stake))
550                .collect(),
551        )
552    }
553}
554
555impl From<crate::crypto::AuthorityPublicKeyBytes> for Bls12381PublicKey {
556    fn from(value: crate::crypto::AuthorityPublicKeyBytes) -> Self {
557        Self::new(value.0)
558    }
559}
560
561impl From<Bls12381PublicKey> for crate::crypto::AuthorityPublicKeyBytes {
562    fn from(value: Bls12381PublicKey) -> Self {
563        Self::new(value.into_inner())
564    }
565}
566
567impl From<UnchangedConsensusKind> for crate::effects::UnchangedConsensusKind {
568    fn from(value: UnchangedConsensusKind) -> Self {
569        match value {
570            UnchangedConsensusKind::ReadOnlyRoot { version, digest } => {
571                Self::ReadOnlyRoot((version.into(), digest.into()))
572            }
573            UnchangedConsensusKind::MutateDeleted { version } => {
574                Self::MutateConsensusStreamEnded(version.into())
575            }
576            UnchangedConsensusKind::ReadDeleted { version } => {
577                Self::ReadConsensusStreamEnded(version.into())
578            }
579            UnchangedConsensusKind::Canceled { version } => Self::Cancelled(version.into()),
580            UnchangedConsensusKind::PerEpochConfig => Self::PerEpochConfig,
581            UnchangedConsensusKind::PerEpochConfigWithSequenceNumber { .. } => todo!(),
582            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
583        }
584    }
585}
586
587impl From<crate::effects::UnchangedConsensusKind> for UnchangedConsensusKind {
588    fn from(value: crate::effects::UnchangedConsensusKind) -> Self {
589        match value {
590            crate::effects::UnchangedConsensusKind::ReadOnlyRoot((version, digest)) => {
591                Self::ReadOnlyRoot {
592                    version: version.into(),
593                    digest: digest.into(),
594                }
595            }
596            crate::effects::UnchangedConsensusKind::MutateConsensusStreamEnded(version) => {
597                Self::MutateDeleted {
598                    version: version.into(),
599                }
600            }
601            crate::effects::UnchangedConsensusKind::ReadConsensusStreamEnded(version) => {
602                Self::ReadDeleted {
603                    version: version.into(),
604                }
605            }
606            crate::effects::UnchangedConsensusKind::Cancelled(version) => Self::Canceled {
607                version: version.into(),
608            },
609            crate::effects::UnchangedConsensusKind::PerEpochConfig => Self::PerEpochConfig,
610        }
611    }
612}
613
614impl From<crate::effects::ObjectIn> for ObjectIn {
615    fn from(value: crate::effects::ObjectIn) -> Self {
616        match value {
617            crate::effects::ObjectIn::NotExist => Self::NotExist,
618            crate::effects::ObjectIn::Exist(((version, digest), owner)) => Self::Exist {
619                version: version.value(),
620                digest: digest.into(),
621                owner: owner.into(),
622            },
623        }
624    }
625}
626
627impl From<crate::effects::ObjectOut> for ObjectOut {
628    fn from(value: crate::effects::ObjectOut) -> Self {
629        match value {
630            crate::effects::ObjectOut::NotExist => Self::NotExist,
631            crate::effects::ObjectOut::ObjectWrite((digest, owner)) => Self::ObjectWrite {
632                digest: digest.into(),
633                owner: owner.into(),
634            },
635            crate::effects::ObjectOut::PackageWrite((version, digest)) => Self::PackageWrite {
636                version: version.value(),
637                digest: digest.into(),
638            },
639
640            // TODO implement accumulator in sdk. This feature is not live yet on any network
641            crate::effects::ObjectOut::AccumulatorWriteV1(_) => todo!(),
642        }
643    }
644}
645
646impl From<crate::effects::IDOperation> for IdOperation {
647    fn from(value: crate::effects::IDOperation) -> Self {
648        match value {
649            crate::effects::IDOperation::None => Self::None,
650            crate::effects::IDOperation::Created => Self::Created,
651            crate::effects::IDOperation::Deleted => Self::Deleted,
652        }
653    }
654}
655
656impl From<crate::transaction::TransactionExpiration> for TransactionExpiration {
657    fn from(value: crate::transaction::TransactionExpiration) -> Self {
658        match value {
659            crate::transaction::TransactionExpiration::None => Self::None,
660            crate::transaction::TransactionExpiration::Epoch(epoch) => Self::Epoch(epoch),
661            crate::transaction::TransactionExpiration::ValidDuring { .. } => {
662                // TODO: Implement proper SDK conversion for ValidDuring
663                // For now, treat as None to maintain compatibility
664                Self::None
665            }
666        }
667    }
668}
669
670impl From<TransactionExpiration> for crate::transaction::TransactionExpiration {
671    fn from(value: TransactionExpiration) -> Self {
672        match value {
673            TransactionExpiration::None => Self::None,
674            TransactionExpiration::Epoch(epoch) => Self::Epoch(epoch),
675            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
676        }
677    }
678}
679
680impl From<crate::execution_status::TypeArgumentError> for TypeArgumentError {
681    fn from(value: crate::execution_status::TypeArgumentError) -> Self {
682        match value {
683            crate::execution_status::TypeArgumentError::TypeNotFound => Self::TypeNotFound,
684            crate::execution_status::TypeArgumentError::ConstraintNotSatisfied => {
685                Self::ConstraintNotSatisfied
686            }
687        }
688    }
689}
690
691impl From<TypeArgumentError> for crate::execution_status::TypeArgumentError {
692    fn from(value: TypeArgumentError) -> Self {
693        match value {
694            TypeArgumentError::TypeNotFound => Self::TypeNotFound,
695            TypeArgumentError::ConstraintNotSatisfied => Self::ConstraintNotSatisfied,
696            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
697        }
698    }
699}
700
701impl From<crate::execution_status::PackageUpgradeError> for PackageUpgradeError {
702    fn from(value: crate::execution_status::PackageUpgradeError) -> Self {
703        match value {
704            crate::execution_status::PackageUpgradeError::UnableToFetchPackage { package_id } => {
705                Self::UnableToFetchPackage {
706                    package_id: package_id.into(),
707                }
708            }
709            crate::execution_status::PackageUpgradeError::NotAPackage { object_id } => {
710                Self::NotAPackage {
711                    object_id: object_id.into(),
712                }
713            }
714            crate::execution_status::PackageUpgradeError::IncompatibleUpgrade => {
715                Self::IncompatibleUpgrade
716            }
717            crate::execution_status::PackageUpgradeError::DigestDoesNotMatch { digest } => {
718                Self::DigestDoesNotMatch {
719                    digest: Digest::from_bytes(digest).unwrap(),
720                }
721            }
722            crate::execution_status::PackageUpgradeError::UnknownUpgradePolicy { policy } => {
723                Self::UnknownUpgradePolicy { policy }
724            }
725            crate::execution_status::PackageUpgradeError::PackageIDDoesNotMatch {
726                package_id,
727                ticket_id,
728            } => Self::PackageIdDoesNotMatch {
729                package_id: package_id.into(),
730                ticket_id: ticket_id.into(),
731            },
732        }
733    }
734}
735
736impl From<PackageUpgradeError> for crate::execution_status::PackageUpgradeError {
737    fn from(value: PackageUpgradeError) -> Self {
738        match value {
739            PackageUpgradeError::UnableToFetchPackage { package_id } => {
740                Self::UnableToFetchPackage {
741                    package_id: package_id.into(),
742                }
743            }
744            PackageUpgradeError::NotAPackage { object_id } => Self::NotAPackage {
745                object_id: object_id.into(),
746            },
747            PackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
748            PackageUpgradeError::DigestDoesNotMatch { digest } => Self::DigestDoesNotMatch {
749                digest: digest.into_inner().to_vec(),
750            },
751            PackageUpgradeError::UnknownUpgradePolicy { policy } => {
752                Self::UnknownUpgradePolicy { policy }
753            }
754            PackageUpgradeError::PackageIdDoesNotMatch {
755                package_id,
756                ticket_id,
757            } => Self::PackageIDDoesNotMatch {
758                package_id: package_id.into(),
759                ticket_id: ticket_id.into(),
760            },
761            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
762        }
763    }
764}
765
766impl From<crate::execution_status::CommandArgumentError> for CommandArgumentError {
767    fn from(value: crate::execution_status::CommandArgumentError) -> Self {
768        match value {
769            crate::execution_status::CommandArgumentError::TypeMismatch => Self::TypeMismatch,
770            crate::execution_status::CommandArgumentError::InvalidBCSBytes => Self::InvalidBcsBytes,
771            crate::execution_status::CommandArgumentError::InvalidUsageOfPureArg => Self::InvalidUsageOfPureArgument,
772            crate::execution_status::CommandArgumentError::InvalidArgumentToPrivateEntryFunction => Self::InvalidArgumentToPrivateEntryFunction,
773            crate::execution_status::CommandArgumentError::IndexOutOfBounds { idx } => Self::IndexOutOfBounds { index: idx },
774            crate::execution_status::CommandArgumentError::SecondaryIndexOutOfBounds { result_idx, secondary_idx } => Self::SecondaryIndexOutOfBounds { result: result_idx, subresult: secondary_idx },
775            crate::execution_status::CommandArgumentError::InvalidResultArity { result_idx } => Self::InvalidResultArity { result: result_idx },
776            crate::execution_status::CommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
777            crate::execution_status::CommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
778            crate::execution_status::CommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
779            crate::execution_status::CommandArgumentError::InvalidObjectByMutRef => Self::InvalidObjectByMutRef,
780            crate::execution_status::CommandArgumentError::SharedObjectOperationNotAllowed => Self::ConsensusObjectOperationNotAllowed,
781            crate::execution_status::CommandArgumentError::InvalidArgumentArity => Self::InvalidArgumentArity,
782            crate::execution_status::CommandArgumentError::InvalidTransferObject  => Self::InvalidTransferObject,
783            crate::execution_status::CommandArgumentError::InvalidMakeMoveVecNonObjectArgument =>
784                Self::InvalidMakeMoveVecNonObjectArgument,
785            crate::execution_status::CommandArgumentError::ArgumentWithoutValue  =>
786                Self::ArgumentWithoutValue,
787            crate::execution_status::CommandArgumentError::CannotMoveBorrowedValue =>
788                Self::CannotMoveBorrowedValue,
789            crate::execution_status::CommandArgumentError::CannotWriteToExtendedReference =>
790                Self::CannotWriteToExtendedReference,
791            crate::execution_status::CommandArgumentError::InvalidReferenceArgument =>
792                Self::InvalidReferenceArgument,
793        }
794    }
795}
796
797impl From<CommandArgumentError> for crate::execution_status::CommandArgumentError {
798    fn from(value: CommandArgumentError) -> Self {
799        match value {
800            CommandArgumentError::TypeMismatch => Self::TypeMismatch,
801            CommandArgumentError::InvalidBcsBytes => Self::InvalidBCSBytes,
802            CommandArgumentError::InvalidUsageOfPureArgument => Self::InvalidUsageOfPureArg,
803            CommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
804                Self::InvalidArgumentToPrivateEntryFunction
805            }
806            CommandArgumentError::IndexOutOfBounds { index } => {
807                Self::IndexOutOfBounds { idx: index }
808            }
809            CommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
810                Self::SecondaryIndexOutOfBounds {
811                    result_idx: result,
812                    secondary_idx: subresult,
813                }
814            }
815            CommandArgumentError::InvalidResultArity { result } => {
816                Self::InvalidResultArity { result_idx: result }
817            }
818            CommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
819            CommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
820            CommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
821            CommandArgumentError::InvalidObjectByMutRef => Self::InvalidObjectByMutRef,
822            CommandArgumentError::ConsensusObjectOperationNotAllowed => {
823                Self::SharedObjectOperationNotAllowed
824            }
825            CommandArgumentError::InvalidArgumentArity => Self::InvalidArgumentArity,
826            CommandArgumentError::InvalidTransferObject => Self::InvalidTransferObject,
827            CommandArgumentError::InvalidMakeMoveVecNonObjectArgument => {
828                Self::InvalidMakeMoveVecNonObjectArgument
829            }
830            CommandArgumentError::ArgumentWithoutValue => Self::ArgumentWithoutValue,
831            CommandArgumentError::CannotMoveBorrowedValue => Self::CannotMoveBorrowedValue,
832            CommandArgumentError::CannotWriteToExtendedReference => {
833                Self::CannotWriteToExtendedReference
834            }
835            CommandArgumentError::InvalidReferenceArgument => Self::InvalidReferenceArgument,
836            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
837        }
838    }
839}
840
841impl From<crate::execution_status::ExecutionFailureStatus> for ExecutionError {
842    fn from(value: crate::execution_status::ExecutionFailureStatus) -> Self {
843        match value {
844            crate::execution_status::ExecutionFailureStatus::InsufficientGas => Self::InsufficientGas,
845            crate::execution_status::ExecutionFailureStatus::InvalidGasObject => Self::InvalidGasObject,
846            crate::execution_status::ExecutionFailureStatus::InvariantViolation => Self::InvariantViolation,
847            crate::execution_status::ExecutionFailureStatus::FeatureNotYetSupported => Self::FeatureNotYetSupported,
848            crate::execution_status::ExecutionFailureStatus::MoveObjectTooBig { object_size, max_object_size } => Self::ObjectTooBig { object_size, max_object_size },
849            crate::execution_status::ExecutionFailureStatus::MovePackageTooBig { object_size, max_object_size } => Self::PackageTooBig { object_size, max_object_size },
850            crate::execution_status::ExecutionFailureStatus::CircularObjectOwnership { object } => Self::CircularObjectOwnership { object: object.into() },
851            crate::execution_status::ExecutionFailureStatus::InsufficientCoinBalance => Self::InsufficientCoinBalance,
852            crate::execution_status::ExecutionFailureStatus::CoinBalanceOverflow => Self::CoinBalanceOverflow,
853            crate::execution_status::ExecutionFailureStatus::PublishErrorNonZeroAddress => Self::PublishErrorNonZeroAddress,
854            crate::execution_status::ExecutionFailureStatus::SuiMoveVerificationError => Self::SuiMoveVerificationError,
855            crate::execution_status::ExecutionFailureStatus::MovePrimitiveRuntimeError(move_location_opt) => Self::MovePrimitiveRuntimeError { location: move_location_opt.0.map(Into::into) },
856            crate::execution_status::ExecutionFailureStatus::MoveAbort(move_location, code) => Self::MoveAbort { location: move_location.into(), code },
857            crate::execution_status::ExecutionFailureStatus::VMVerificationOrDeserializationError => Self::VmVerificationOrDeserializationError,
858            crate::execution_status::ExecutionFailureStatus::VMInvariantViolation => Self::VmInvariantViolation,
859            crate::execution_status::ExecutionFailureStatus::FunctionNotFound => Self::FunctionNotFound,
860            crate::execution_status::ExecutionFailureStatus::ArityMismatch => Self::ArityMismatch,
861            crate::execution_status::ExecutionFailureStatus::TypeArityMismatch => Self::TypeArityMismatch,
862            crate::execution_status::ExecutionFailureStatus::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
863            crate::execution_status::ExecutionFailureStatus::CommandArgumentError { arg_idx, kind } => Self::CommandArgumentError { argument: arg_idx, kind: kind.into() },
864            crate::execution_status::ExecutionFailureStatus::TypeArgumentError { argument_idx, kind } => Self::TypeArgumentError { type_argument: argument_idx, kind: kind.into() },
865            crate::execution_status::ExecutionFailureStatus::UnusedValueWithoutDrop { result_idx, secondary_idx } => Self::UnusedValueWithoutDrop { result: result_idx, subresult: secondary_idx },
866            crate::execution_status::ExecutionFailureStatus::InvalidPublicFunctionReturnType { idx } => Self::InvalidPublicFunctionReturnType { index: idx },
867            crate::execution_status::ExecutionFailureStatus::InvalidTransferObject => Self::InvalidTransferObject,
868            crate::execution_status::ExecutionFailureStatus::EffectsTooLarge { current_size, max_size } => Self::EffectsTooLarge { current_size, max_size },
869            crate::execution_status::ExecutionFailureStatus::PublishUpgradeMissingDependency => Self::PublishUpgradeMissingDependency,
870            crate::execution_status::ExecutionFailureStatus::PublishUpgradeDependencyDowngrade => Self::PublishUpgradeDependencyDowngrade,
871            crate::execution_status::ExecutionFailureStatus::PackageUpgradeError { upgrade_error } => Self::PackageUpgradeError { kind: upgrade_error.into() },
872            crate::execution_status::ExecutionFailureStatus::WrittenObjectsTooLarge { current_size, max_size } => Self::WrittenObjectsTooLarge { object_size: current_size, max_object_size:max_size },
873            crate::execution_status::ExecutionFailureStatus::CertificateDenied => Self::CertificateDenied,
874            crate::execution_status::ExecutionFailureStatus::SuiMoveVerificationTimedout => Self::SuiMoveVerificationTimedout,
875            crate::execution_status::ExecutionFailureStatus::SharedObjectOperationNotAllowed => Self::ConsensusObjectOperationNotAllowed,
876            crate::execution_status::ExecutionFailureStatus::InputObjectDeleted => Self::InputObjectDeleted,
877            crate::execution_status::ExecutionFailureStatus::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => Self::ExecutionCanceledDueToConsensusObjectCongestion { congested_objects: congested_objects.0.into_iter().map(Into::into).collect() },
878            crate::execution_status::ExecutionFailureStatus::AddressDeniedForCoin { address, coin_type } => Self::AddressDeniedForCoin { address: address.into(), coin_type },
879            crate::execution_status::ExecutionFailureStatus::CoinTypeGlobalPause { coin_type } => Self::CoinTypeGlobalPause { coin_type },
880            crate::execution_status::ExecutionFailureStatus::ExecutionCancelledDueToRandomnessUnavailable => Self::ExecutionCanceledDueToRandomnessUnavailable,
881            crate::execution_status::ExecutionFailureStatus::MoveVectorElemTooBig { value_size, max_scaled_size } => Self::MoveVectorElemTooBig { value_size, max_scaled_size },
882            crate::execution_status::ExecutionFailureStatus::MoveRawValueTooBig { value_size, max_scaled_size } => Self::MoveRawValueTooBig { value_size, max_scaled_size },
883            crate::execution_status::ExecutionFailureStatus::InvalidLinkage => Self::InvalidLinkage,
884            crate::execution_status::ExecutionFailureStatus::InsufficientBalanceForWithdraw => {
885                todo!("Add InsufficientBalanceForWithdraw to sdk")
886            }
887            crate::execution_status::ExecutionFailureStatus::NonExclusiveWriteInputObjectModified { .. } => {
888                todo!("Add NonExclusiveWriteInputObjectModified to sdk")
889            }
890        }
891    }
892}
893
894impl From<ExecutionError> for crate::execution_status::ExecutionFailureStatus {
895    fn from(value: ExecutionError) -> Self {
896        match value {
897            ExecutionError::InsufficientGas => Self::InsufficientGas,
898            ExecutionError::InvalidGasObject => Self::InvalidGasObject,
899            ExecutionError::InvariantViolation => Self::InvariantViolation,
900            ExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
901            ExecutionError::ObjectTooBig {
902                object_size,
903                max_object_size,
904            } => Self::MoveObjectTooBig {
905                object_size,
906                max_object_size,
907            },
908            ExecutionError::PackageTooBig {
909                object_size,
910                max_object_size,
911            } => Self::MovePackageTooBig {
912                object_size,
913                max_object_size,
914            },
915            ExecutionError::CircularObjectOwnership { object } => Self::CircularObjectOwnership {
916                object: object.into(),
917            },
918            ExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
919            ExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
920            ExecutionError::PublishErrorNonZeroAddress => Self::PublishErrorNonZeroAddress,
921            ExecutionError::SuiMoveVerificationError => Self::SuiMoveVerificationError,
922            ExecutionError::MovePrimitiveRuntimeError { location } => {
923                Self::MovePrimitiveRuntimeError(crate::execution_status::MoveLocationOpt(
924                    location.map(Into::into),
925                ))
926            }
927            ExecutionError::MoveAbort { location, code } => Self::MoveAbort(location.into(), code),
928            ExecutionError::VmVerificationOrDeserializationError => {
929                Self::VMVerificationOrDeserializationError
930            }
931            ExecutionError::VmInvariantViolation => Self::VMInvariantViolation,
932            ExecutionError::FunctionNotFound => Self::FunctionNotFound,
933            ExecutionError::ArityMismatch => Self::ArityMismatch,
934            ExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
935            ExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
936            ExecutionError::CommandArgumentError { argument, kind } => Self::CommandArgumentError {
937                arg_idx: argument,
938                kind: kind.into(),
939            },
940            ExecutionError::TypeArgumentError {
941                type_argument,
942                kind,
943            } => Self::TypeArgumentError {
944                argument_idx: type_argument,
945                kind: kind.into(),
946            },
947            ExecutionError::UnusedValueWithoutDrop { result, subresult } => {
948                Self::UnusedValueWithoutDrop {
949                    result_idx: result,
950                    secondary_idx: subresult,
951                }
952            }
953            ExecutionError::InvalidPublicFunctionReturnType { index } => {
954                Self::InvalidPublicFunctionReturnType { idx: index }
955            }
956            ExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
957            ExecutionError::EffectsTooLarge {
958                current_size,
959                max_size,
960            } => Self::EffectsTooLarge {
961                current_size,
962                max_size,
963            },
964            ExecutionError::PublishUpgradeMissingDependency => {
965                Self::PublishUpgradeMissingDependency
966            }
967            ExecutionError::PublishUpgradeDependencyDowngrade => {
968                Self::PublishUpgradeDependencyDowngrade
969            }
970            ExecutionError::PackageUpgradeError { kind } => Self::PackageUpgradeError {
971                upgrade_error: kind.into(),
972            },
973            ExecutionError::WrittenObjectsTooLarge {
974                object_size,
975                max_object_size,
976            } => Self::WrittenObjectsTooLarge {
977                current_size: object_size,
978                max_size: max_object_size,
979            },
980            ExecutionError::CertificateDenied => Self::CertificateDenied,
981            ExecutionError::SuiMoveVerificationTimedout => Self::SuiMoveVerificationTimedout,
982            ExecutionError::ConsensusObjectOperationNotAllowed => {
983                Self::SharedObjectOperationNotAllowed
984            }
985            ExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
986            ExecutionError::ExecutionCanceledDueToConsensusObjectCongestion {
987                congested_objects,
988            } => Self::ExecutionCancelledDueToSharedObjectCongestion {
989                congested_objects: crate::execution_status::CongestedObjects(
990                    congested_objects.into_iter().map(Into::into).collect(),
991                ),
992            },
993            ExecutionError::AddressDeniedForCoin { address, coin_type } => {
994                Self::AddressDeniedForCoin {
995                    address: address.into(),
996                    coin_type,
997                }
998            }
999            ExecutionError::CoinTypeGlobalPause { coin_type } => {
1000                Self::CoinTypeGlobalPause { coin_type }
1001            }
1002            ExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1003                Self::ExecutionCancelledDueToRandomnessUnavailable
1004            }
1005            ExecutionError::MoveVectorElemTooBig {
1006                value_size,
1007                max_scaled_size,
1008            } => Self::MoveVectorElemTooBig {
1009                value_size,
1010                max_scaled_size,
1011            },
1012            ExecutionError::MoveRawValueTooBig {
1013                value_size,
1014                max_scaled_size,
1015            } => Self::MoveRawValueTooBig {
1016                value_size,
1017                max_scaled_size,
1018            },
1019            ExecutionError::InvalidLinkage => Self::InvalidLinkage,
1020            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
1021        }
1022    }
1023}
1024
1025impl From<crate::execution_status::MoveLocation> for MoveLocation {
1026    fn from(value: crate::execution_status::MoveLocation) -> Self {
1027        Self {
1028            package: Address::new(value.module.address().into_bytes()),
1029            module: Identifier::new(value.module.name().as_str()).unwrap(),
1030            function: value.function,
1031            instruction: value.instruction,
1032            function_name: value
1033                .function_name
1034                .map(|name| Identifier::new(name).unwrap()),
1035        }
1036    }
1037}
1038
1039impl From<MoveLocation> for crate::execution_status::MoveLocation {
1040    fn from(value: MoveLocation) -> Self {
1041        Self {
1042            module: move_core_types::language_storage::ModuleId::new(
1043                move_core_types::account_address::AccountAddress::new(value.package.into_inner()),
1044                move_core_types::identifier::Identifier::new(value.module.as_str()).unwrap(),
1045            ),
1046            function: value.function,
1047            instruction: value.instruction,
1048            function_name: value.function_name.map(|ident| ident.as_str().into()),
1049        }
1050    }
1051}
1052
1053impl From<crate::execution_status::ExecutionStatus> for ExecutionStatus {
1054    fn from(value: crate::execution_status::ExecutionStatus) -> Self {
1055        match value {
1056            crate::execution_status::ExecutionStatus::Success => Self::Success,
1057            crate::execution_status::ExecutionStatus::Failure { error, command } => Self::Failure {
1058                error: error.into(),
1059                command: command.map(|c| c as u64),
1060            },
1061        }
1062    }
1063}
1064
1065impl From<crate::messages_checkpoint::CheckpointCommitment> for CheckpointCommitment {
1066    fn from(value: crate::messages_checkpoint::CheckpointCommitment) -> Self {
1067        match value {
1068            crate::messages_checkpoint::CheckpointCommitment::ECMHLiveObjectSetDigest(digest) => {
1069                Self::EcmhLiveObjectSet {
1070                    digest: digest.digest.into(),
1071                }
1072            }
1073            crate::messages_checkpoint::CheckpointCommitment::CheckpointArtifactsDigest(digest) => {
1074                Self::CheckpointArtifacts {
1075                    digest: digest.into(),
1076                }
1077            }
1078        }
1079    }
1080}
1081
1082impl TryFrom<crate::crypto::PublicKey> for MultisigMemberPublicKey {
1083    type Error = SdkTypeConversionError;
1084
1085    fn try_from(value: crate::crypto::PublicKey) -> Result<Self, Self::Error> {
1086        match value {
1087            crate::crypto::PublicKey::Ed25519(bytes_representation) => {
1088                Self::Ed25519(Ed25519PublicKey::new(bytes_representation.0))
1089            }
1090            crate::crypto::PublicKey::Secp256k1(bytes_representation) => {
1091                Self::Secp256k1(Secp256k1PublicKey::new(bytes_representation.0))
1092            }
1093            crate::crypto::PublicKey::Secp256r1(bytes_representation) => {
1094                Self::Secp256r1(Secp256r1PublicKey::new(bytes_representation.0))
1095            }
1096            crate::crypto::PublicKey::ZkLogin(z) => Self::ZkLogin(z.try_into()?),
1097            crate::crypto::PublicKey::Passkey(p) => {
1098                Self::Passkey(PasskeyPublicKey::new(Secp256r1PublicKey::new(p.0)))
1099            }
1100        }
1101        .pipe(Ok)
1102    }
1103}
1104
1105impl TryFrom<crate::crypto::CompressedSignature> for MultisigMemberSignature {
1106    type Error = SdkTypeConversionError;
1107
1108    fn try_from(value: crate::crypto::CompressedSignature) -> Result<Self, Self::Error> {
1109        match value {
1110            crate::crypto::CompressedSignature::Ed25519(bytes_representation) => {
1111                Self::Ed25519(Ed25519Signature::new(bytes_representation.0))
1112            }
1113            crate::crypto::CompressedSignature::Secp256k1(bytes_representation) => {
1114                Self::Secp256k1(Secp256k1Signature::new(bytes_representation.0))
1115            }
1116            crate::crypto::CompressedSignature::Secp256r1(bytes_representation) => {
1117                Self::Secp256r1(Secp256r1Signature::new(bytes_representation.0))
1118            }
1119            crate::crypto::CompressedSignature::ZkLogin(z) => {
1120                Self::ZkLogin(Box::new(z.try_into()?))
1121            }
1122            crate::crypto::CompressedSignature::Passkey(p) => Self::Passkey(p.try_into()?),
1123        }
1124        .pipe(Ok)
1125    }
1126}
1127
1128impl TryFrom<crate::crypto::Signature> for SimpleSignature {
1129    type Error = SdkTypeConversionError;
1130
1131    fn try_from(value: crate::crypto::Signature) -> Result<Self, Self::Error> {
1132        match value {
1133            crate::crypto::Signature::Ed25519SuiSignature(ed25519_sui_signature) => Self::Ed25519 {
1134                signature: Ed25519Signature::from_bytes(ed25519_sui_signature.signature_bytes())?,
1135                public_key: Ed25519PublicKey::from_bytes(ed25519_sui_signature.public_key_bytes())?,
1136            },
1137            crate::crypto::Signature::Secp256k1SuiSignature(secp256k1_sui_signature) => {
1138                Self::Secp256k1 {
1139                    signature: Secp256k1Signature::from_bytes(
1140                        secp256k1_sui_signature.signature_bytes(),
1141                    )?,
1142                    public_key: Secp256k1PublicKey::from_bytes(
1143                        secp256k1_sui_signature.public_key_bytes(),
1144                    )?,
1145                }
1146            }
1147
1148            crate::crypto::Signature::Secp256r1SuiSignature(secp256r1_sui_signature) => {
1149                Self::Secp256r1 {
1150                    signature: Secp256r1Signature::from_bytes(
1151                        secp256r1_sui_signature.signature_bytes(),
1152                    )?,
1153                    public_key: Secp256r1PublicKey::from_bytes(
1154                        secp256r1_sui_signature.public_key_bytes(),
1155                    )?,
1156                }
1157            }
1158        }
1159        .pipe(Ok)
1160    }
1161}
1162
1163impl From<crate::crypto::SignatureScheme> for SignatureScheme {
1164    fn from(value: crate::crypto::SignatureScheme) -> Self {
1165        match value {
1166            crate::crypto::SignatureScheme::ED25519 => Self::Ed25519,
1167            crate::crypto::SignatureScheme::Secp256k1 => Self::Secp256k1,
1168            crate::crypto::SignatureScheme::Secp256r1 => Self::Secp256r1,
1169            crate::crypto::SignatureScheme::BLS12381 => Self::Bls12381,
1170            crate::crypto::SignatureScheme::MultiSig => Self::Multisig,
1171            crate::crypto::SignatureScheme::ZkLoginAuthenticator => Self::ZkLogin,
1172            crate::crypto::SignatureScheme::PasskeyAuthenticator => Self::Passkey,
1173        }
1174    }
1175}
1176
1177impl From<crate::transaction::CallArg> for Input {
1178    fn from(value: crate::transaction::CallArg) -> Self {
1179        match value {
1180            crate::transaction::CallArg::Pure(vec) => Self::Pure { value: vec },
1181            crate::transaction::CallArg::Object(object_arg) => match object_arg {
1182                crate::transaction::ObjectArg::ImmOrOwnedObject((id, version, digest)) => {
1183                    Self::ImmutableOrOwned(ObjectReference::new(
1184                        id.into(),
1185                        version.value(),
1186                        digest.into(),
1187                    ))
1188                }
1189                crate::transaction::ObjectArg::SharedObject {
1190                    id,
1191                    initial_shared_version,
1192                    mutability,
1193                } => Self::Shared {
1194                    object_id: id.into(),
1195                    initial_shared_version: initial_shared_version.value(),
1196                    mutable: match mutability {
1197                        crate::transaction::SharedObjectMutability::Mutable => true,
1198                        crate::transaction::SharedObjectMutability::Immutable => false,
1199                        // TODO(address-balances): expose non-exclusive writes to sdk
1200                        crate::transaction::SharedObjectMutability::NonExclusiveWrite => false,
1201                    },
1202                },
1203                crate::transaction::ObjectArg::Receiving((id, version, digest)) => Self::Receiving(
1204                    ObjectReference::new(id.into(), version.value(), digest.into()),
1205                ),
1206            },
1207            crate::transaction::CallArg::FundsWithdrawal(_) => {
1208                // TODO(address-balances): Add support for balance withdraws.
1209                todo!("Convert balance withdraw reservation to sdk Input")
1210            }
1211        }
1212    }
1213}
1214
1215impl From<Input> for crate::transaction::CallArg {
1216    fn from(value: Input) -> Self {
1217        use crate::transaction::ObjectArg;
1218
1219        match value {
1220            Input::Pure { value } => Self::Pure(value),
1221            Input::ImmutableOrOwned(object_reference) => {
1222                let (id, version, digest) = object_reference.into_parts();
1223                Self::Object(ObjectArg::ImmOrOwnedObject((
1224                    id.into(),
1225                    version.into(),
1226                    digest.into(),
1227                )))
1228            }
1229            Input::Shared {
1230                object_id,
1231                initial_shared_version,
1232                mutable,
1233            } => Self::Object(ObjectArg::SharedObject {
1234                id: object_id.into(),
1235                initial_shared_version: initial_shared_version.into(),
1236                mutability: if mutable {
1237                    crate::transaction::SharedObjectMutability::Mutable
1238                } else {
1239                    crate::transaction::SharedObjectMutability::Immutable
1240                },
1241            }),
1242            Input::Receiving(object_reference) => {
1243                let (id, version, digest) = object_reference.into_parts();
1244                Self::Object(ObjectArg::Receiving((
1245                    id.into(),
1246                    version.into(),
1247                    digest.into(),
1248                )))
1249            }
1250            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
1251        }
1252    }
1253}
1254
1255impl From<crate::transaction::Argument> for Argument {
1256    fn from(value: crate::transaction::Argument) -> Self {
1257        match value {
1258            crate::transaction::Argument::GasCoin => Self::Gas,
1259            crate::transaction::Argument::Input(idx) => Self::Input(idx),
1260            crate::transaction::Argument::Result(idx) => Self::Result(idx),
1261            crate::transaction::Argument::NestedResult(idx, sub_idx) => {
1262                Self::NestedResult(idx, sub_idx)
1263            }
1264        }
1265    }
1266}
1267
1268impl From<Argument> for crate::transaction::Argument {
1269    fn from(value: Argument) -> Self {
1270        match value {
1271            Argument::Gas => Self::GasCoin,
1272            Argument::Input(idx) => Self::Input(idx),
1273            Argument::Result(idx) => Self::Result(idx),
1274            Argument::NestedResult(idx, sub_idx) => Self::NestedResult(idx, sub_idx),
1275        }
1276    }
1277}
1278
1279impl TryFrom<TransactionEffects> for crate::effects::TransactionEffects {
1280    type Error = SdkTypeConversionError;
1281
1282    fn try_from(value: TransactionEffects) -> Result<Self, Self::Error> {
1283        match value {
1284            TransactionEffects::V1(v1) => Self::V1((*v1).try_into()?),
1285            TransactionEffects::V2(v2) => Self::V2((*v2).try_into()?),
1286        }
1287        .pipe(Ok)
1288    }
1289}
1290
1291impl TryFrom<crate::effects::TransactionEffects> for TransactionEffects {
1292    type Error = SdkTypeConversionError;
1293
1294    fn try_from(value: crate::effects::TransactionEffects) -> Result<Self, Self::Error> {
1295        match value {
1296            crate::effects::TransactionEffects::V1(v1) => Self::V1(Box::new(v1.try_into()?)),
1297            crate::effects::TransactionEffects::V2(v2) => Self::V2(Box::new(v2.try_into()?)),
1298        }
1299        .pipe(Ok)
1300    }
1301}
1302
1303impl TryFrom<crate::transaction::Command> for Command {
1304    type Error = SdkTypeConversionError;
1305
1306    fn try_from(value: crate::transaction::Command) -> Result<Self, Self::Error> {
1307        match value {
1308            crate::transaction::Command::MoveCall(programmable_move_call) => {
1309                Self::MoveCall((*programmable_move_call).try_into()?)
1310            }
1311            crate::transaction::Command::TransferObjects(vec, argument) => {
1312                Self::TransferObjects(TransferObjects {
1313                    objects: vec.into_iter().map(Into::into).collect(),
1314                    address: argument.into(),
1315                })
1316            }
1317            crate::transaction::Command::SplitCoins(argument, vec) => {
1318                Self::SplitCoins(SplitCoins {
1319                    coin: argument.into(),
1320                    amounts: vec.into_iter().map(Into::into).collect(),
1321                })
1322            }
1323            crate::transaction::Command::MergeCoins(argument, vec) => {
1324                Self::MergeCoins(MergeCoins {
1325                    coin: argument.into(),
1326                    coins_to_merge: vec.into_iter().map(Into::into).collect(),
1327                })
1328            }
1329            crate::transaction::Command::Publish(vec, vec1) => Self::Publish(Publish {
1330                modules: vec,
1331                dependencies: vec1.into_iter().map(Into::into).collect(),
1332            }),
1333            crate::transaction::Command::MakeMoveVec(type_input, elements) => {
1334                Self::MakeMoveVector(MakeMoveVector {
1335                    type_: type_input.map(TryInto::try_into).transpose()?,
1336                    elements: elements.into_iter().map(Into::into).collect(),
1337                })
1338            }
1339            crate::transaction::Command::Upgrade(modules, deps, object_id, ticket) => {
1340                Self::Upgrade(Upgrade {
1341                    modules,
1342                    dependencies: deps.into_iter().map(Into::into).collect(),
1343                    package: object_id.into(),
1344                    ticket: ticket.into(),
1345                })
1346            }
1347        }
1348        .pipe(Ok)
1349    }
1350}
1351
1352impl TryFrom<crate::transaction::ProgrammableMoveCall> for MoveCall {
1353    type Error = SdkTypeConversionError;
1354
1355    fn try_from(value: crate::transaction::ProgrammableMoveCall) -> Result<Self, Self::Error> {
1356        Self {
1357            package: value.package.into(),
1358            module: Identifier::new(value.module)?,
1359            function: Identifier::new(value.function)?,
1360            type_arguments: value
1361                .type_arguments
1362                .into_iter()
1363                .map(TryInto::try_into)
1364                .collect::<Result<_, _>>()?,
1365            arguments: value.arguments.into_iter().map(Into::into).collect(),
1366        }
1367        .pipe(Ok)
1368    }
1369}
1370
1371impl From<MoveCall> for crate::transaction::ProgrammableMoveCall {
1372    fn from(value: MoveCall) -> Self {
1373        Self {
1374            package: value.package.into(),
1375            module: value.module.as_str().into(),
1376            function: value.function.as_str().into(),
1377            type_arguments: value.type_arguments.into_iter().map(Into::into).collect(),
1378            arguments: value.arguments.into_iter().map(Into::into).collect(),
1379        }
1380    }
1381}
1382
1383impl From<Command> for crate::transaction::Command {
1384    fn from(value: Command) -> Self {
1385        match value {
1386            Command::MoveCall(move_call) => Self::MoveCall(Box::new(move_call.into())),
1387            Command::TransferObjects(TransferObjects { objects, address }) => {
1388                Self::TransferObjects(
1389                    objects.into_iter().map(Into::into).collect(),
1390                    address.into(),
1391                )
1392            }
1393            Command::SplitCoins(SplitCoins { coin, amounts }) => {
1394                Self::SplitCoins(coin.into(), amounts.into_iter().map(Into::into).collect())
1395            }
1396            Command::MergeCoins(MergeCoins {
1397                coin,
1398                coins_to_merge,
1399            }) => Self::MergeCoins(
1400                coin.into(),
1401                coins_to_merge.into_iter().map(Into::into).collect(),
1402            ),
1403            Command::Publish(Publish {
1404                modules,
1405                dependencies,
1406            }) => Self::Publish(modules, dependencies.into_iter().map(Into::into).collect()),
1407            Command::MakeMoveVector(MakeMoveVector { type_, elements }) => Self::MakeMoveVec(
1408                type_.map(Into::into),
1409                elements.into_iter().map(Into::into).collect(),
1410            ),
1411            Command::Upgrade(Upgrade {
1412                modules,
1413                dependencies,
1414                package,
1415                ticket,
1416            }) => Self::Upgrade(
1417                modules,
1418                dependencies.into_iter().map(Into::into).collect(),
1419                package.into(),
1420                ticket.into(),
1421            ),
1422            _ => unreachable!("sdk shouldn't have a variant that the mono repo doesn't"),
1423        }
1424    }
1425}
1426
1427impl From<crate::transaction::StoredExecutionTimeObservations> for ExecutionTimeObservations {
1428    fn from(value: crate::transaction::StoredExecutionTimeObservations) -> Self {
1429        match value {
1430            crate::transaction::StoredExecutionTimeObservations::V1(vec) => Self::V1(
1431                vec.into_iter()
1432                    .map(|(key, value)| {
1433                        (
1434                            key.into(),
1435                            value
1436                                .into_iter()
1437                                .map(|(name, duration)| ValidatorExecutionTimeObservation {
1438                                    validator: name.into(),
1439                                    duration,
1440                                })
1441                                .collect(),
1442                        )
1443                    })
1444                    .collect(),
1445            ),
1446        }
1447    }
1448}
1449
1450impl From<crate::execution::ExecutionTimeObservationKey> for ExecutionTimeObservationKey {
1451    fn from(value: crate::execution::ExecutionTimeObservationKey) -> Self {
1452        match value {
1453            crate::execution::ExecutionTimeObservationKey::MoveEntryPoint {
1454                package,
1455                module,
1456                function,
1457                type_arguments,
1458            } => Self::MoveEntryPoint {
1459                package: package.into(),
1460                module,
1461                function,
1462                type_arguments: type_arguments
1463                    .into_iter()
1464                    .map(TryInto::try_into)
1465                    .collect::<Result<_, _>>()
1466                    .unwrap(),
1467            },
1468            crate::execution::ExecutionTimeObservationKey::TransferObjects => Self::TransferObjects,
1469            crate::execution::ExecutionTimeObservationKey::SplitCoins => Self::SplitCoins,
1470            crate::execution::ExecutionTimeObservationKey::MergeCoins => Self::MergeCoins,
1471            crate::execution::ExecutionTimeObservationKey::Publish => Self::Publish,
1472            crate::execution::ExecutionTimeObservationKey::MakeMoveVec => Self::MakeMoveVec,
1473            crate::execution::ExecutionTimeObservationKey::Upgrade => Self::Upgrade,
1474        }
1475    }
1476}
1477
1478impl From<crate::transaction::EndOfEpochTransactionKind> for EndOfEpochTransactionKind {
1479    fn from(value: crate::transaction::EndOfEpochTransactionKind) -> Self {
1480        match value {
1481            crate::transaction::EndOfEpochTransactionKind::ChangeEpoch(change_epoch) => {
1482                Self::ChangeEpoch(change_epoch.into())
1483            }
1484            crate::transaction::EndOfEpochTransactionKind::AuthenticatorStateCreate => {
1485                Self::AuthenticatorStateCreate
1486            }
1487            crate::transaction::EndOfEpochTransactionKind::AuthenticatorStateExpire(
1488                authenticator_state_expire,
1489            ) => Self::AuthenticatorStateExpire(authenticator_state_expire.into()),
1490            crate::transaction::EndOfEpochTransactionKind::RandomnessStateCreate => {
1491                Self::RandomnessStateCreate
1492            }
1493            crate::transaction::EndOfEpochTransactionKind::DenyListStateCreate => {
1494                Self::DenyListStateCreate
1495            }
1496            crate::transaction::EndOfEpochTransactionKind::BridgeStateCreate(chain_identifier) => {
1497                Self::BridgeStateCreate {
1498                    chain_id: Digest::new(chain_identifier.as_bytes().to_owned()),
1499                }
1500            }
1501            crate::transaction::EndOfEpochTransactionKind::BridgeCommitteeInit(sequence_number) => {
1502                Self::BridgeCommitteeInit {
1503                    bridge_object_version: sequence_number.value(),
1504                }
1505            }
1506            crate::transaction::EndOfEpochTransactionKind::StoreExecutionTimeObservations(
1507                stored_execution_time_observations,
1508            ) => Self::StoreExecutionTimeObservations(stored_execution_time_observations.into()),
1509            crate::transaction::EndOfEpochTransactionKind::AccumulatorRootCreate => {
1510                todo!("AccumulatorRootCreate needs to be added to sdk")
1511            }
1512            crate::transaction::EndOfEpochTransactionKind::CoinRegistryCreate => {
1513                Self::CoinRegistryCreate
1514            }
1515            crate::transaction::EndOfEpochTransactionKind::DisplayRegistryCreate => {
1516                Self::DisplayRegistryCreate
1517            }
1518        }
1519    }
1520}
1521
1522impl From<crate::transaction::ChangeEpoch> for ChangeEpoch {
1523    fn from(
1524        crate::transaction::ChangeEpoch {
1525            epoch,
1526            protocol_version,
1527            storage_charge,
1528            computation_charge,
1529            storage_rebate,
1530            non_refundable_storage_fee,
1531            epoch_start_timestamp_ms,
1532            system_packages,
1533        }: crate::transaction::ChangeEpoch,
1534    ) -> Self {
1535        Self {
1536            epoch,
1537            protocol_version: protocol_version.as_u64(),
1538            storage_charge,
1539            computation_charge,
1540            storage_rebate,
1541            non_refundable_storage_fee,
1542            epoch_start_timestamp_ms,
1543            system_packages: system_packages
1544                .into_iter()
1545                .map(|(version, modules, dependencies)| SystemPackage {
1546                    version: version.value(),
1547                    modules,
1548                    dependencies: dependencies.into_iter().map(Into::into).collect(),
1549                })
1550                .collect(),
1551        }
1552    }
1553}
1554
1555impl From<crate::transaction::AuthenticatorStateExpire> for AuthenticatorStateExpire {
1556    fn from(value: crate::transaction::AuthenticatorStateExpire) -> Self {
1557        Self {
1558            min_epoch: value.min_epoch,
1559            authenticator_object_initial_shared_version: value
1560                .authenticator_obj_initial_shared_version
1561                .value(),
1562        }
1563    }
1564}
1565
1566impl From<crate::messages_consensus::ConsensusDeterminedVersionAssignments>
1567    for ConsensusDeterminedVersionAssignments
1568{
1569    fn from(value: crate::messages_consensus::ConsensusDeterminedVersionAssignments) -> Self {
1570        use crate::messages_consensus::ConsensusDeterminedVersionAssignments::*;
1571        match value {
1572            CancelledTransactions(vec) => Self::CanceledTransactions {
1573                canceled_transactions: vec
1574                    .into_iter()
1575                    .map(|(digest, assignments)| CanceledTransaction {
1576                        digest: digest.into(),
1577                        version_assignments: assignments
1578                            .into_iter()
1579                            .map(|(id, version)| VersionAssignment {
1580                                object_id: id.into(),
1581                                version: version.value(),
1582                            })
1583                            .collect(),
1584                    })
1585                    .collect(),
1586            },
1587            CancelledTransactionsV2(canceled_transactions) => Self::CanceledTransactionsV2 {
1588                canceled_transactions: canceled_transactions
1589                    .into_iter()
1590                    .map(|(digest, assignments)| CanceledTransactionV2 {
1591                        digest: digest.into(),
1592                        version_assignments: assignments
1593                            .into_iter()
1594                            .map(|((id, start_version), version)| VersionAssignmentV2 {
1595                                object_id: id.into(),
1596                                start_version: start_version.value(),
1597                                version: version.value(),
1598                            })
1599                            .collect(),
1600                    })
1601                    .collect(),
1602            },
1603        }
1604    }
1605}
1606
1607impl From<crate::authenticator_state::ActiveJwk> for ActiveJwk {
1608    fn from(value: crate::authenticator_state::ActiveJwk) -> Self {
1609        let crate::authenticator_state::ActiveJwk { jwk_id, jwk, epoch } = value;
1610        Self {
1611            jwk_id: JwkId {
1612                iss: jwk_id.iss,
1613                kid: jwk_id.kid,
1614            },
1615            jwk: Jwk {
1616                kty: jwk.kty,
1617                e: jwk.e,
1618                n: jwk.n,
1619                alg: jwk.alg,
1620            },
1621            epoch,
1622        }
1623    }
1624}
1625
1626// TODO remaining set of enums to add impls for to ensure new additions are caught during review
1627//
1628// impl From<crate::transaction::TransactionKind> for TransactionKind {
1629//     fn from(value: crate::transaction::TransactionKind) -> Self {
1630//         todo!()
1631//     }
1632// }
1633// src/object.rs:pub enum ObjectData {