Skip to content

Commit

Permalink
fix(iota-types): Use bcs for signature conversions (#3830)
Browse files Browse the repository at this point in the history
Co-authored-by: Levente Pap <[email protected]>
  • Loading branch information
DaughterOfMars and lzpap authored Oct 31, 2024
1 parent 37a6009 commit c13a8c0
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions crates/iota-types/src/iota_sdk2_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,34 +1400,14 @@ impl From<CheckpointTransaction> for crate::full_checkpoint_content::CheckpointT

impl From<crate::signature::GenericSignature> for UserSignature {
fn from(value: crate::signature::GenericSignature) -> Self {
match value {
crate::signature::GenericSignature::MultiSig(multi_sig) => Self::Multisig(
MultisigAggregatedSignature::from_serialized_bytes(multi_sig.as_bytes())
.expect("invalid multisig aggregated signature"),
),
crate::signature::GenericSignature::Signature(signature) => Self::Simple(
SimpleSignature::from_serialized_bytes(signature.as_bytes())
.expect("invalid simple signature"),
),
crate::signature::GenericSignature::ZkLoginAuthenticator(zk_login_authenticator) => {
Self::ZkLogin(Box::new(
ZkLoginAuthenticator::from_serialized_bytes(zk_login_authenticator.as_bytes())
.expect("invalid zklogin authenticator"),
))
}
crate::signature::GenericSignature::PasskeyAuthenticator(passkey_authenticator) => {
Self::Passkey(
PasskeyAuthenticator::from_serialized_bytes(passkey_authenticator.as_bytes())
.expect("invalid passkey authenticator"),
)
}
}
bcs::from_bytes(&bcs::to_bytes(&value).expect("invalid signature"))
.expect("invalid signature")
}
}

impl From<UserSignature> for crate::signature::GenericSignature {
fn from(value: UserSignature) -> Self {
Self::from_bytes(&bcs::to_bytes(&value).expect("invalid signature"))
bcs::from_bytes(&bcs::to_bytes(&value).expect("invalid signature"))
.expect("invalid signature")
}
}
Expand Down

0 comments on commit c13a8c0

Please sign in to comment.