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

Use hash to compute the raw payload in IMP mock #910

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pallets/identity-management-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ pub mod pallet {
) -> DispatchResult {
let code =
Self::challenge_codes(who, identity).ok_or(Error::<T>::ChallengeCodeNotExist)?;
let msg = Self::get_expected_web3_message(who, identity, &code)?;
let msg = Self::get_expected_payload(who, identity, &code)?;

ensure!(
msg.as_slice() == validation_data.message.as_slice(),
Expand Down Expand Up @@ -599,7 +599,7 @@ pub mod pallet {
) -> DispatchResult {
let code =
Self::challenge_codes(who, identity).ok_or(Error::<T>::ChallengeCodeNotExist)?;
let msg = Self::get_expected_web3_message(who, identity, &code)?;
let msg = Self::get_expected_payload(who, identity, &code)?;
let digest = Self::compute_evm_msg_digest(&msg);
if let IdentityMultiSignature::Ethereum(sig) = &validation_data.signature {
let recovered_evm_address = Self::recover_evm_address(&digest, sig.as_ref())
Expand All @@ -621,18 +621,17 @@ pub mod pallet {
Ok(())
}

// web3 message format: <challeng-code> + <litentry-AccountId32> + <Identity>, where
// <> means SCALE-encoded
// Notice: actually we use the same format for web2 message too
pub fn get_expected_web3_message(
// Payload format: blake2_256(<challeng-code> + <litentry-AccountId32> + <Identity>), where
// <> means SCALE-encoded. It applies to both web2 and web3 message
pub fn get_expected_payload(
who: &T::AccountId,
identity: &Identity,
code: &ChallengeCode,
) -> Result<Vec<u8>, DispatchError> {
let mut msg = code.encode();
msg.append(&mut who.encode());
msg.append(&mut identity.encode());
Ok(msg)
Ok(blake2_256(&msg).to_vec())
}

// we use an EIP-191 message has computing
Expand Down
4 changes: 2 additions & 2 deletions pallets/identity-management-mock/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn create_mock_polkadot_validation_data(
code: ChallengeCode,
) -> ValidationData {
let identity = create_mock_polkadot_identity(p.public().0);
let msg = IdentityManagementMock::get_expected_web3_message(&who, &identity, &code)
let msg = IdentityManagementMock::get_expected_payload(&who, &identity, &code)
.expect("cannot calculate web3 message");
let sig = p.sign(&msg);

Expand All @@ -194,7 +194,7 @@ pub fn create_mock_eth_validation_data(
code: ChallengeCode,
) -> ValidationData {
let identity = create_mock_eth_identity(p.address().0);
let msg = IdentityManagementMock::get_expected_web3_message(&who, &identity, &code)
let msg = IdentityManagementMock::get_expected_payload(&who, &identity, &code)
.expect("cannot calculate web3 message");
let digest = IdentityManagementMock::compute_evm_msg_digest(&msg);
let sig = sign(p.secret(), &Message::from(digest)).unwrap();
Expand Down