I followed the answer of "how to verify a signature in a pallet", and try to verify some data signed by a private key on chain logic.
#[pallet::weight(10_000)]
pub fn my_verify(origin: OriginFor<T>, data: Vec<u8>, sig: T::Signature, from: T::PublicKey) -> DispatchResult{
log::info!("--------public key is {:?}", from.clone().into_account());
log::info!("--------signature is {:?}", sig.clone());
log::info!("--------data is {:?}", data.clone());
let ok = sig.verify(&data[..], &from.into_account());
// `ok` is a bool. Use in an `if` or `ensure!`.
ensure!(ok, <Error<T>>::SignatureVerifyError);
Ok(())
}
but I got false from sig.verify(). My config is exactly the same as the question's answer.
#[pallet::config]
pub trait Config: frame_system::Config {
/// A Signature can be verified with a specific `PublicKey`.
/// The additional traits are boilerplate.
type Signature: Verify<Signer = Self::PublicKey> + Encode + Decode + Member + TypeInfo;
/// A PublicKey can be converted into an `AccountId`. This is required by the
/// `Signature` type.
/// The additional traits are boilerplate.
type PublicKey: IdentifyAccount<AccountId = Self::PublicKey> + Encode + Decode + Member + TypeInfo;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
#[pallet::constant]
type MaxMinersOwned: Get<u32>;
#[pallet::constant]
type EpochCycle: Get<u32>;
}
and runtime config is like this:
impl pallet_xenon::Config for Runtime {
type Signature = sp_core::sr25519::Signature;
type PublicKey = sp_core::sr25519::Public;
type Event = Event;
type MaxMinersOwned = MaxMinersOwned;
type EpochCycle = EpochCycle;
}
So what mistake did I make? Help!!! Please!!!