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

feat: add support for starknet account to offchain actions #383

Merged
merged 36 commits into from
Jul 29, 2024

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Jun 2, 2024

Summary

Closes: #372 and https://github.com/snapshot-labs/pitches/issues/83

This PR add starknet wallet support for setAlias on offchain networks.

Once alias is created, a starknet account will be able to follow/unfollow a space and edit its user profile

With this PR, features on starknet accounts will be on par with EVM accounts

Changes

  • feat: create an alias from a starknet wallet
  • fix: enable back follow/unfollow and updateUser button for starknet users
  • fix: load followed spaces for starknet users
  • fix: update follow/unfollow/updateUsers type ons sx/offchain to accept starknet address
  • fix: update starknet-sig returned envelop to always return address as a padded address
  • fix: do not load starknet user's vote from offchain hub
  • refactor: remove SignatureData from sx/offchain/types, and use the global one from sx/types

How to test

Waiting merging of snapshot-labs/snapshot-sequencer#400

  • Log in with a starknet wallet
  • Follow a space
  • It should ask to sign a transaction to create an alias
  • After signing, it should follow the space, and the space should appear on the sidebar
  • Refresh the page
  • The followed space should appear in the sidebar
  • You can follow/unfollow more spaces (offchain/evm/starknet spaces)
  • Go to your user profile
  • The EDIT button should be visible
  • Edit and save your profile
  • It should save and show your updated profile

@wa0x6e wa0x6e marked this pull request as ready for review June 2, 2024 19:15
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jun 5, 2024

It's ready on sx side, waiting for update on backend (sequencer) side to accept starknet addresses

@Sekhmet
Copy link
Member

Sekhmet commented Jun 5, 2024

I am trying to make this work via EthSig in Starknet, but it always fail with just undefined when trying to Follow a space with a starknet account.

If you are signed in using ArgentX (or Braavos, or any other Starknet wallet) you will get Starknet provider, starknet's EthereumSig client is supposed to work with Ethereum provider (so you can vote with Ethereum wallet on Starknet spaces), for doing actions with Starknet provider we need to use StarknetSig client (which I see has been updated now).

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jun 5, 2024

I am trying to make this work via EthSig in Starknet, but it always fail with just undefined when trying to Follow a space with a starknet account.

If you are signed in using ArgentX (or Braavos, or any other Starknet wallet) you will get Starknet provider, starknet's EthereumSig client is supposed to work with Ethereum provider (so you can vote with Ethereum wallet on Starknet spaces), for doing actions with Starknet provider we need to use StarknetSig client (which I see has been updated now).

Yes, I just finally made it work with StarknetSig. A small thing I noticed is that there are no network switcher when the wallet is on the wrong network, and the signing will fail with "Invalid chain ID"

apps/ui/src/composables/useActions.ts Outdated Show resolved Hide resolved
apps/ui/src/composables/useActions.ts Outdated Show resolved Hide resolved
@aurelianoB
Copy link
Contributor

A small thing I noticed is that there are no network switcher when the wallet is on the wrong network, and the signing will fail with "Invalid chain ID"

Shouldn't the alias and any hub-related action done with it be agnostic of the chain currently used in the wallet? That's at least how it works for evm wallets right now

@Sekhmet
Copy link
Member

Sekhmet commented Jul 2, 2024

Is this PR supposed to work or it's missing sequencer support?

@wa0x6e wa0x6e marked this pull request as draft July 2, 2024 09:37
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jul 2, 2024

refactoring in progress, to include features in the current cycle

@wa0x6e wa0x6e changed the title feat: add setAlias to starknet eth sign feat: add support for starknet account to offchain actions Jul 2, 2024
@wa0x6e wa0x6e self-assigned this Jul 3, 2024
@wa0x6e wa0x6e marked this pull request as ready for review July 4, 2024 13:02
@Sekhmet
Copy link
Member

Sekhmet commented Jul 15, 2024

@wa0x6e this PR is waiting to get retested as sequencer PR has been merged, is that correct?

Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

I can't get it to work.

Trying to follow sn or sn-sep spaces when singing alias request (on Braavos) I get this error:
image

Tried both with Starknet and Starknet Sepolia network in Braavos.

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jul 24, 2024

I can't get it to work.

Trying to follow sn or sn-sep spaces when singing alias request (on Braavos) I get this error: image

Tried both with Starknet and Starknet Sepolia network in Braavos.

Just to know, can you try with argent X ?

@Sekhmet
Copy link
Member

Sekhmet commented Jul 24, 2024

It worked with Argent X (Starknet mainnet account following starknet mainnet space).

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jul 24, 2024

Yes, just confirmed the issue with braavos and argentx. Braavos is returning a signature array with 3 items, whereas argent x is returning only 2

Working on a fix on snapshot.js side

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jul 25, 2024

Fixed deployed on sequencer.

You can now sign with argent x or braavos wallet.

Still, braavos can sign the message on any chain, whereas argent x will return an error when signing on a different chainId than the one set in the message domain

@wa0x6e wa0x6e requested a review from Sekhmet July 25, 2024 12:34
@Sekhmet
Copy link
Member

Sekhmet commented Jul 26, 2024

I still encounter this issue with Braavos wallet.

Braavos (failing):

curl 'https://seq.snapshot.org/' \
  -H 'accept: application/json' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8,pl;q=0.7' \
  -H 'content-type: application/json' \
  -H 'origin: http://localhost:8080' \
  -H 'priority: u=1, i' \
  -H 'referer: http://localhost:8080/' \
  -H 'sec-ch-ua: "Chromium";v="124", "Brave";v="124", "Not-A.Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-gpc: 1' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
  --data-raw '{"address":"0x0679a64fb03683f0aea697da37e2b62549f5d527aadd7fa06f7cb4a0dd8f7f58","sig":["0x303ce05e24ab6836e10be55f2322ec476a8277a9fba3ad9121f3c4f44c22b9b","0x1946094ed071a324589562bacc67d4db45824d30c5db367fe6cdf57c43b2e93"],"data":{"domain":{"name":"sx-starknet","version":"0.1.0","chainId":"0x534e5f4d41494e","verifyingContract":""},"types":{"StarkNetDomain":[{"name":"name","type":"felt252"},{"name":"version","type":"felt252"},{"name":"chainId","type":"felt252"},{"name":"verifyingContract","type":"ContractAddress"}],"SetAlias":[{"name":"from","type":"ContractAddress"},{"name":"alias","type":"string"},{"name":"timestamp","type":"felt"}]},"message":{"from":"0x0679a64fb03683f0aea697da37e2b62549f5d527aadd7fa06f7cb4a0dd8f7f58","timestamp":1722013734,"alias":"0x20Fe6C2F907407CacaF5f4Da0aDA30BB4B975eb8"},"primaryType":"SetAlias"}}'

ArgentX (working):

curl 'https://seq.snapshot.org/' \
  -H 'accept: application/json' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8,pl;q=0.7' \
  -H 'content-type: application/json' \
  -H 'origin: http://localhost:8080' \
  -H 'priority: u=1, i' \
  -H 'referer: http://localhost:8080/' \
  -H 'sec-ch-ua: "Chromium";v="124", "Brave";v="124", "Not-A.Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-gpc: 1' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
  --data-raw '{"address":"0x06abd599ab530c5b3bc603111bdd20d77890db330402dc870fc9866f50ed6d2a","sig":["0x7612c93866317c50256dc3803a42ea222d05f7e091cf926f05627707959be39","0x5b2cdee002fb8244a8ca13bd2929a9afd5f53eaf3bd0eb51bfe0ee307ce6157"],"data":{"domain":{"name":"sx-starknet","version":"0.1.0","chainId":"0x534e5f4d41494e","verifyingContract":""},"types":{"StarkNetDomain":[{"name":"name","type":"felt252"},{"name":"version","type":"felt252"},{"name":"chainId","type":"felt252"},{"name":"verifyingContract","type":"ContractAddress"}],"SetAlias":[{"name":"from","type":"ContractAddress"},{"name":"alias","type":"string"},{"name":"timestamp","type":"felt"}]},"message":{"from":"0x06abd599ab530c5b3bc603111bdd20d77890db330402dc870fc9866f50ed6d2a","timestamp":1722013819,"alias":"0x0fdC188BdAb37b82928D1e87dAfb6c8654d777a4"},"primaryType":"SetAlias"}}'

Looks like both use 2 value signature, so it's some other problem.

@ChaituVR
Copy link
Member

Looks like Bravoos account is not deployed https://starkscan.co/contract/0x0679a64fb03683f0aea697da37e2b62549f5d527aadd7fa06f7cb4a0dd8f7f58

Signatures with non deployed accounts are not working. so we thought of disabling write actions with such accounts #537

@Sekhmet
Copy link
Member

Sekhmet commented Jul 26, 2024

@ChaituVR good point, got lost when trying different accounts across wallets. I can reproduce it with accounts that are deployed as well:

Braavos, account deployed on sepolia:
https://sepolia.starkscan.co/contract/0x07c39c8912b61368aeb3111ad480fc661162798a7fe10be6fb880e2c18ccbc6f

curl 'https://seq.snapshot.org/' \
  -H 'accept: application/json' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8,pl;q=0.7' \
  -H 'content-type: application/json' \
  -H 'origin: http://localhost:8080' \
  -H 'priority: u=1, i' \
  -H 'referer: http://localhost:8080/' \
  -H 'sec-ch-ua: "Chromium";v="124", "Brave";v="124", "Not-A.Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-gpc: 1' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
  --data-raw '{"address":"0x07c39c8912b61368aeb3111ad480fc661162798a7fe10be6fb880e2c18ccbc6f","sig":["0x1","0x6e34a42393e79d0b30b93badbe3781e909469e71e7756b811ec29513831094c","0x574c0bdac26626315725a01056a208074323d6eb3382b49751872e236fa9a56"],"data":{"domain":{"name":"sx-starknet","version":"0.1.0","chainId":"0x534e5f5345504f4c4941","verifyingContract":""},"types":{"StarkNetDomain":[{"name":"name","type":"felt252"},{"name":"version","type":"felt252"},{"name":"chainId","type":"felt252"},{"name":"verifyingContract","type":"ContractAddress"}],"SetAlias":[{"name":"from","type":"ContractAddress"},{"name":"alias","type":"string"},{"name":"timestamp","type":"felt"}]},"message":{"from":"0x07c39c8912b61368aeb3111ad480fc661162798a7fe10be6fb880e2c18ccbc6f","timestamp":1722014767,"alias":"0x9C5eCC4F164AbA7fA284efafee4fFfb2101Ae0BC"},"primaryType":"SetAlias"}}'

I don't have mainnet Braavos account at the moment.

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jul 27, 2024

@ChaituVR good point, got lost when trying different accounts across wallets. I can reproduce it with accounts that are deployed as well:

Braavos, account deployed on sepolia: https://sepolia.starkscan.co/contract/0x07c39c8912b61368aeb3111ad480fc661162798a7fe10be6fb880e2c18ccbc6f

curl 'https://seq.snapshot.org/' \
  -H 'accept: application/json' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8,pl;q=0.7' \
  -H 'content-type: application/json' \
  -H 'origin: http://localhost:8080' \
  -H 'priority: u=1, i' \
  -H 'referer: http://localhost:8080/' \
  -H 'sec-ch-ua: "Chromium";v="124", "Brave";v="124", "Not-A.Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-gpc: 1' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
  --data-raw '{"address":"0x07c39c8912b61368aeb3111ad480fc661162798a7fe10be6fb880e2c18ccbc6f","sig":["0x1","0x6e34a42393e79d0b30b93badbe3781e909469e71e7756b811ec29513831094c","0x574c0bdac26626315725a01056a208074323d6eb3382b49751872e236fa9a56"],"data":{"domain":{"name":"sx-starknet","version":"0.1.0","chainId":"0x534e5f5345504f4c4941","verifyingContract":""},"types":{"StarkNetDomain":[{"name":"name","type":"felt252"},{"name":"version","type":"felt252"},{"name":"chainId","type":"felt252"},{"name":"verifyingContract","type":"ContractAddress"}],"SetAlias":[{"name":"from","type":"ContractAddress"},{"name":"alias","type":"string"},{"name":"timestamp","type":"felt"}]},"message":{"from":"0x07c39c8912b61368aeb3111ad480fc661162798a7fe10be6fb880e2c18ccbc6f","timestamp":1722014767,"alias":"0x9C5eCC4F164AbA7fA284efafee4fFfb2101Ae0BC"},"primaryType":"SetAlias"}}'

I don't have mainnet Braavos account at the moment.

This payload pass when sent to testnet.seq.snapshot.org.

Your account is only deployed on Sepolia, so only testnet.sequencer will be able to verify, and vice versa, sequencer mainnet will only be able to verify contract on mainnet

Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

tACK

@Sekhmet Sekhmet merged commit e088ca6 into master Jul 29, 2024
1 of 3 checks passed
@Sekhmet Sekhmet deleted the feat-support-starknet-alias branch July 29, 2024 10:33
Sekhmet added a commit that referenced this pull request Jul 29, 2024
Regression from: #383
(but broken change commited by me).
Sekhmet added a commit that referenced this pull request Jul 29, 2024
Regression from: #383
(but broken change commited by me).
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.

feat: create session keys (alias) from starknet address
4 participants