Skip to main content

iota_types/
signature.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_sdk_types::{Address, UserSignature, crypto::IntentMessage};
6use serde::Serialize;
7
8use crate::error::IotaResult;
9
10#[derive(Default, Debug, Clone)]
11pub struct VerifyParams {
12    pub accept_passkey_in_multisig: bool,
13    pub additional_multisig_checks: bool,
14}
15
16impl VerifyParams {
17    pub fn new(accept_passkey_in_multisig: bool, additional_multisig_checks: bool) -> Self {
18        Self {
19            accept_passkey_in_multisig,
20            additional_multisig_checks,
21        }
22    }
23}
24
25/// A lightweight trait that all members of [`UserSignature`] implement.
26pub trait AuthenticatorTrait {
27    fn verify_claims<T>(
28        &self,
29        value: &IntentMessage<T>,
30        author: Address,
31        aux_verify_data: &VerifyParams,
32    ) -> IotaResult
33    where
34        T: Serialize;
35}
36
37impl AuthenticatorTrait for UserSignature {
38    fn verify_claims<T>(
39        &self,
40        value: &IntentMessage<T>,
41        author: Address,
42        aux_verify_data: &VerifyParams,
43    ) -> IotaResult
44    where
45        T: Serialize,
46    {
47        match self {
48            UserSignature::Simple(s) => s.verify_claims(value, author, aux_verify_data),
49            UserSignature::Multisig(s) => s.verify_claims(value, author, aux_verify_data),
50            UserSignature::PasskeyAuthenticator(s) => {
51                s.verify_claims(value, author, aux_verify_data)
52            }
53            UserSignature::MoveAuthenticator(s) => s.verify_claims(value, author, aux_verify_data),
54            _ => unimplemented!("a new UserSignature variant was added and needs to be handled"),
55        }
56    }
57}
58
59/// This ports the wrapper trait to the verify_secure defined on
60/// [`crate::crypto::Signature`].
61impl AuthenticatorTrait for crate::crypto::Signature {
62    #[tracing::instrument(level = "trace", skip_all)]
63    fn verify_claims<T>(
64        &self,
65        value: &IntentMessage<T>,
66        author: Address,
67        _aux_verify_data: &VerifyParams,
68    ) -> IotaResult
69    where
70        T: Serialize,
71    {
72        use crate::crypto::IotaSignature;
73        self.verify_secure(value, author)
74    }
75}