argentlabs / argent-x

ArgentX browser extension for StarkNet - made with ❤️ by Argent
https://github.com/argentlabs/argent-x
Other
625 stars 276 forks source link

signMessage is hard to use from code #146

Closed wraitii closed 2 years ago

wraitii commented 2 years ago

The signMessage API of the argent-X signer (I mean the in-browser JS code of the extension) requires passing a TypedData struct, of the following format:

{
     domain: {
       name: "Example DApp",
       chainId: mainnet ? 1 : 3,
       version: "0.0.1",
     },
     types: {
       StarkNetDomain: [
         { name: "name", type: "felt" },
         { name: "chainId", type: "felt" },
         { name: "version", type: "felt" },
       ],
       Message: [{ name: "message", type: "felt" }],
     },
     primaryType: "Message",
     message: {
       "message": "some_short_string"
     }
}

This is un-necessarily complex: the wallet should probably just take a message (possibly a domain name?). Furthermore, the UI fails to report errors if the wrong type of data is passed (it simply hangs). The UI also shows the whole struct when signing the message, but I assume that is somewhat related to this unexpected behaviour in the first place.


Edit: I should note that starknet.js Signer also expects TypedData, so maybe the API should instead be abstracted there somewhat?

janek26 commented 2 years ago

it's definitely something for starknet.js as we just implement their interface But this most likely won't change, as we want to allow apps to use structured signatures, so we don't have such a mess like they have in Ethereum world right now :)

wraitii commented 2 years ago

But this most likely won't change, as we want to allow apps to use structured signatures, so we don't have such a mess like they have in Ethereum world right now :)

Then perhaps the typing should be more obvious? I couldn't find any 'doc' for this except for the usage in ArgentX :)

janek26 commented 2 years ago

Here you go: https://eips.ethereum.org/EIPS/eip-712 Github discussion: https://github.com/argentlabs/argent-x/discussions/14