@@ -9,6 +9,7 @@ mod dispatches {
99 use frame_support:: traits:: schedule:: DispatchTime ;
1010 use frame_support:: traits:: schedule:: v3:: Anon as ScheduleAnon ;
1111 use frame_system:: pallet_prelude:: BlockNumberFor ;
12+ use sp_core:: ecdsa:: Signature ;
1213 use sp_runtime:: traits:: Saturating ;
1314
1415 use crate :: MAX_CRV3_COMMIT_SIZE_BYTES ;
@@ -1929,6 +1930,50 @@ mod dispatches {
19291930 Ok ( ( ) )
19301931 }
19311932
1933+ /// Attempts to associate a hotkey with an EVM key.
1934+ ///
1935+ /// The signature will be checked to see if the recovered public key matches the `evm_key` provided.
1936+ ///
1937+ /// The EVM key is expected to sign the message according to this formula to produce the signature:
1938+ /// ```text
1939+ /// keccak_256(hotkey ++ keccak_256(block_number))
1940+ /// ```
1941+ ///
1942+ /// # Arguments
1943+ /// * `origin` - The origin of the transaction, which must be signed by the coldkey that owns the `hotkey`.
1944+ /// * `netuid` - The netuid that the `hotkey` belongs to.
1945+ /// * `hotkey` - The hotkey associated with the `origin`.
1946+ /// * `evm_key` - The EVM key to associate with the `hotkey`.
1947+ /// * `block_number` - The block number used in the `signature`.
1948+ /// * `signature` - A signed message by the `evm_key` containing the `hotkey` and the hashed `block_number`.
1949+ ///
1950+ /// # Errors
1951+ /// Returns an error if:
1952+ /// * The transaction is not signed.
1953+ /// * The hotkey is not owned by the origin coldkey.
1954+ /// * The hotkey does not belong to the subnet identified by the netuid.
1955+ /// * The EVM key cannot be recovered from the signature.
1956+ /// * The EVM key recovered from the signature does not match the given EVM key.
1957+ ///
1958+ /// # Events
1959+ /// May emit a `EvmKeyAssociated` event on success
1960+ #[ pallet:: call_index( 93 ) ]
1961+ #[ pallet:: weight( (
1962+ Weight :: from_parts( 3_000_000 , 0 ) . saturating_add( T :: DbWeight :: get( ) . reads_writes( 2 , 1 ) ) ,
1963+ DispatchClass :: Operational ,
1964+ Pays :: Yes
1965+ ) ) ]
1966+ pub fn associate_evm_key (
1967+ origin : T :: RuntimeOrigin ,
1968+ netuid : u16 ,
1969+ hotkey : T :: AccountId ,
1970+ evm_key : H160 ,
1971+ block_number : u64 ,
1972+ signature : Signature ,
1973+ ) -> DispatchResult {
1974+ Self :: do_associate_evm_key ( origin, netuid, hotkey, evm_key, block_number, signature)
1975+ }
1976+
19321977 /// Recycles alpha from a cold/hot key pair, reducing AlphaOut on a subnet
19331978 ///
19341979 /// # Arguments
0 commit comments