web3swift-team / web3swift

Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Apache License 2.0
812 stars 431 forks source link

Authenticate with a wallet (e.g. Metamask) #491

Open armanarutiunov opened 2 years ago

armanarutiunov commented 2 years ago

From what I understand this library allows you to create or import a wallet via mnemonics or the private key. But is it possible to somehow authenticate with a wallet similar to the way you do it on web? So that the app can read your wallet but the moment you want to fire a transaction you have to approve it in the actual wallet app separately?

Importing a wallet via private key makes sense if it's a wallet app. But what I'm trying to build is a frontend for a smart contract. And potential users of such app would not trust their private keys or mnemonics with it.

pharms-eth commented 2 years ago

MetaMask suggests using wallet for such a connection: https://docs.walletconnect.com/mobile-linking https://docs.metamask.io/guide/mobile-best-practices.html#using-walletconnect

skywinder commented 2 years ago

Hi. Looks like you want walletconnect functionality.

There is no such feature yet. I'd be more than happy to merge a PR adding this feature, it seems like it would be useful for sure 👍

skywinder commented 2 years ago

Probably we will add WC as a module to web3swift in the future. Let me discuss it with the team.

maurovz commented 2 years ago

Hi. Looks like you want walletconnect functionality.

There is no such feature yet. I'd be more than happy to merge a PR adding this feature, it seems like it would be useful for sure 👍

That'd be a great feature. I recently did something similar using WC as you suggest. I'm going to get familiar with the code to see if I can help out :)

Benoye commented 2 years ago

I would like this feature as well, let me know if I can help !

armanarutiunov commented 2 years ago

Sounds amazing, thank you! Let me also know if there is any help needed. Can't wait!

Benoye commented 2 years ago

Hi guys, I looked at how something could be done quickly. I managed to get it to work, here is my process:

1 - connect to a wallet using the WallectConnectSwift library 2 - prepare an EthereumTransaction using this library 3 - convert the EthereumTransaction object to a Client.Transaction object of the WalletConnect library 4 - Open the Wallet Connect url to make the appropriate wallet app open and approve the transaction

This way, it is not necessary to have the private key to launch transactions. As you can see, in this process this library is used only as a helper to prepare the transactions..

armanarutiunov commented 2 years ago

Nice one @Benoye! I think you probably want to use the V2 library though: https://github.com/WalletConnect/WalletConnectSwiftV2 The one you shared a link for works only with the V1 of their protocol as I understand.

Benoye commented 2 years ago

Good point @armanarutiunov ! Thanks ! I did not know there was a v2 ! I am going to take a look in the following days..

ceobitch commented 2 years ago

Probably we will add WC as a module to web3swift in the future. Let me discuss it with the team.

Every needs this, trust me I been telling wallet connect the whole time. @skywinder

Benoye commented 2 years ago

Nice one @Benoye! I think you probably want to use the V2 library though: https://github.com/WalletConnect/WalletConnectSwiftV2 The one you shared a link for works only with the V1 of their protocol as I understand.

I talked on Discord with some WalletConnect people: some wallets are not supported yet in the v2 protocol, I am going to stuck to the v1 as I want to put something in production quickly..