-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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
}
}Metadata
Metadata
Assignees
Labels
No labels