Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two step owner transfer #17

Open
Neotamandua opened this issue Jan 13, 2025 · 0 comments
Open

Add two step owner transfer #17

Neotamandua opened this issue Jan 13, 2025 · 0 comments

Comments

@Neotamandua
Copy link
Member

Summary

Make it possible to have a two step process for the ownership transfer. Create specs on how to achieve this variability through the same extension.

Possible Solution (optional)

    /// Data used to accept ownership of a contract.
    ///
    /// The payload does not need to specify the new owner, as the signature
    /// will be verified by the contract that has access to the new owner
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Archive, Serialize, Deserialize)]
    #[archive_attr(derive(CheckBytes))]
    pub struct AcceptOwnership {
        nonce: u64,
        signature: Signature,
    }

    impl AcceptOwnership {
        const SIGNATURE_MSG_SIZE: usize = 8;

        /// Create a new `AcceptOwnership` transaction. This transaction is used to
        /// accept ownership of an account when the ownership is implemented as a
        /// two-step process.
        ///
        /// # Arguments
        ///
        /// * `new_owner_sk` - The secret key of the new owner.
        /// * `nonce` - The nonce of the account.
        pub fn new(new_owner_sk: &SecretKey, nonce: u64) -> Self {
            let mut accept_ownership = Self {
                nonce,
                signature: Signature::default(),
            };

            let sig_msg = accept_ownership.signature_message();
            let sig = new_owner_sk.sign(&sig_msg);
            accept_ownership.signature = sig;

            accept_ownership
        }

        /// The message to be signed over.
        pub fn signature_message(&self) -> [u8; Self::SIGNATURE_MSG_SIZE] {
            self.nonce.to_le_bytes()
        }

        /// Get the nonce specified for this transaction.
        pub fn nonce(&self) -> u64 {
            self.nonce
        }

        /// Get the signature specified for this transaction.
        pub fn signature(&self) -> &Signature {
            &self.signature
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant