Skip to content

Commit

Permalink
Add <Bytes> tag for polkadotjs signature in crowdloan (#514)
Browse files Browse the repository at this point in the history
The public polkadotjs api signRaw is wrapping the message in this tag.
  • Loading branch information
hussein-aitlahcen authored Jan 19, 2022
1 parent d8c6701 commit f20f18b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 5 additions & 1 deletion frame/crowdloan-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,12 @@ pub mod pallet {
relay_account: RelayChainAccountId,
proof: &MultiSignature,
) -> bool {
let mut msg = prefix.to_vec();
let wrapped_prefix: &[u8] = b"<Bytes>";
let wrapped_postfix: &[u8] = b"</Bytes>";
let mut msg = wrapped_prefix.to_vec();
msg.append(&mut prefix.to_vec());
msg.append(&mut reward_account.using_encoded(|x| hex::encode(x).as_bytes().to_vec()));
msg.append(&mut wrapped_postfix.to_vec());
proof.verify(&msg[..], &relay_account.into())
}

Expand Down
9 changes: 4 additions & 5 deletions frame/crowdloan-rewards/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ impl ClaimKey {
}
}

pub fn relay_proof(
relay_account: &RelayKey,
reward_account: AccountId,
) -> Proof<RelayChainAccountId> {
let mut msg = PROOF_PREFIX.to_vec();
fn relay_proof(relay_account: &RelayKey, reward_account: AccountId) -> Proof<RelayChainAccountId> {
let mut msg = b"<Bytes>".to_vec();
msg.append(&mut PROOF_PREFIX.to_vec());
msg.append(&mut reward_account.using_encoded(|x| hex::encode(x).as_bytes().to_vec()));
msg.append(&mut b"</Bytes>".to_vec());
Proof::RelayChain(relay_account.public().into(), relay_account.sign(&msg).into())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const toHexString = bytes =>

// The prefix is defined as pallet config
const proofMessage = (account: IKeyringPair) =>
"picasso-" + toHexString(account.publicKey);
"<Bytes>picasso-" + toHexString(account.publicKey) + "</Bytes>";

const ethAccount = (seed: number) =>
web3.eth.accounts.privateKeyToAccount("0x" + seed.toString(16).padStart(64, '0'))
Expand Down

0 comments on commit f20f18b

Please sign in to comment.