It's my pleasure if this repo can help anyone who is planning to step into ethereum dApp development.
the keys you need to notify when you generate a offchain signature:
- check signing message and hashed message
- use
ethers.utils._TypedDataEncoderto encode signing typed message(equal toabi.encodePacked()). - use
ethers.utils.keccak256()to hash encoded message.(equal tokeccak256(abi.encodePacked())). - use
ethers.utils.AbiCoderto encode simple message(equal toabi.encode()).
- sign typed data directly
- utilize the
signer._signTypedData()to sign typedData directly. - utilize the
signer.signMessage()to sign simple message.
- choose three type of signature(based on ECDSA.sol) to verify onchain
- type1: bytesLik signature
- type2: r, s, v signature => need to split the signature:
ethers.utils.splitSignature(signature) - type3: r, vs signature => need to split the signature:
ethers.utils.splitSignature(signature), and then concat the v,s bytes.