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

waas: Add support for signTypedData intent #630

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

patrislav
Copy link
Member

No description provided.

@patrislav patrislav requested a review from a team as a code owner December 16, 2024 14:49
Copy link
Member

@pkieltyka pkieltyka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Can you also update "waas-ethers" the signTypedData method..? I added to waas-ethers last week the new "signedTypedData" but my implementation is actually a bit wrong, and we should be having it call the new waas package signTypedData as you've newly added in this PR

@patrislav
Copy link
Member Author

Can you also update "waas-ethers" the signTypedData method..? I added to waas-ethers last week the new "signedTypedData" but my implementation is actually a bit wrong, and we should be having it call the new waas package signTypedData as you've newly added in this PR

I did, but it's going to be invalid due to missing primaryType, not sure how can I include it as the function signature (defined by the AbstractSigner interface) doesn't provide it as argument... Or is there another way that I'm missing?

@pkieltyka
Copy link
Member

pkieltyka commented Dec 16, 2024

I did a bit of testing with ethers ..

async function main() {
  const typedDataJson = `{
    "types": {
      "ExampleMessage": [
        { "name": "message", "type": "string" },
        { "name": "value", "type": "uint256" },
        { "name": "from", "type": "address" },
        { "name": "to", "type": "address" }
      ]
    },
    "domain": {
      "name": "EIP712Example",
      "version": "1",
      "chainId": 5,
      "verifyingContract": "0xc0ffee254729296a45a3885639AC7E10F9d54979",
      "salt": "0x70736575646f2d72616e646f6d2076616c756500000000000000000000000000"
    },
    "message": {
      "message": "Test message",
      "value": 10000,
      "from": "0xc0ffee254729296a45a3885639AC7E10F9d54979",
      "to": "0xc0ffee254729296a45a3885639AC7E10F9d54979"
    }
  }`

  const typedData = JSON.parse(typedDataJson)

  const wallet = ethers.Wallet.fromPhrase(mnemonic)
  console.log('wallet address:', wallet.address)

  const domainHashStruct = ethers.TypedDataEncoder.hashDomain(typedData.domain)
  console.log('domainHashStruct:', domainHashStruct)

  const signature = await wallet.signTypedData(typedData.domain, typedData.types, typedData.message)
  console.log('signature:', signature)

  // verify signature
  const recoveredAddress = ethers.verifyTypedData(typedData.domain, typedData.types, typedData.message, signature)
  console.log('recovered address:', recoveredAddress)
}

main()

this works fine.

as you can see "primaryType" is not defined. It works because ethers will set the "primaryType" automatically as there is just a single type of "ExampleMessage".

If you add another type under "types" (ie. Person), and do not specify "primaryType" then ethers will respond with the error of 'ambiguous primary types or unused types: "ExampleMessage", "Person"'

I'll update ethkit so we do the same thing to auto-detect

@pkieltyka
Copy link
Member

this will do it: 0xsequence/ethkit#151

@pkieltyka pkieltyka force-pushed the waas-sign-typed-intent branch from 53590ec to 6286cb6 Compare December 19, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants