input-output-hk / nami

Nami Wallet is a browser based wallet extension to interact with the Cardano blockchain. Support requests: https://iohk.zendesk.com/hc/en-us/requests/new
https://namiwallet.io
Apache License 2.0
372 stars 167 forks source link

How to get the Wallet address #140

Open devtrix opened 2 years ago

devtrix commented 2 years ago

Hi, I have two questions here.

  1. How can I get the wallet address vis javascript in the browser?
  2. How can I have the sign fuctionality like the one OpenSea has during the registration process. I used Metamask with them? Thanks in advance.
rooooooooob commented 2 years ago

For #2 the CIP-30 spec that defines wallet-dApp communication on Cardano is potentially due to have minor changes so keep that in mind. You can use the cardano.signData(address, payload) endpoint. It should return a verification key as well (since addresses on Cardano are key hashes so you can't use just an address to verify a signature but you can go the other way around and go from a key to an address). There's a description of this endpoint in the nami-wallet main readme at the root directory of this repo.

devtrix commented 2 years ago

@rooooooooob You just stated the obvious here buddy. I saw that cardano.signData. What address and what payload? It would be helpful to have an example here since the documentation is not there. Plus, I cant believe Nami people arent even answering this simple question. Cheers!

rooooooooob commented 2 years ago

@devtrix I mentioned it is defined in CIP-30 but the current specification is in slight flux (the PR cardano-foundation/CIPs#148 is already almost what nami does, further away from the in-master copy of CIP-30).

devtrix commented 2 years ago

Any insight on how I can get the wallet address? BTW I am very, very new to the crypto world as it is and still learning my way around. I appreciate all the patience & guidance. Thank you.

rooooooooob commented 2 years ago

@devtrix What are you wanting to do with it? The concept of "the address for a wallet" only makes sense for some wallet types. HD wallets for example will have many addresses associated with a wallet so which one is "the" address? That's why the data sign endpoint takes in an address as a parameter. Would you make an address out of the root pubkey hash? (I am not sure if most wallets would even recognize this or if they wouldn't find it when doing regular HD address discovery) Or pick an arbitrary one of the derived addresses? Or are you just looking for an arbitrary identifier regardless of it it's used as an address?

It's possible we will want to extend the CIP-30 API (it's still in draft status) as well.

devtrix commented 2 years ago

@devtrix What are you wanting to do with it? The concept of "the address for a wallet" only makes sense for some wallet types. HD wallets for example will have many addresses associated with a wallet so which one is "the" address? That's why the data sign endpoint takes in an address as a parameter. Would you make an address out of the root pubkey hash? (I am not sure if most wallets would even recognize this or if they wouldn't find it when doing regular HD address discovery) Or pick an arbitrary one of the derived addresses? Or are you just looking for an arbitrary identifier regardless of it it's used as an address?

It's possible we will want to extend the CIP-30 API (it's still in draft status) as well.

I wanted to use it as a part of my client registration. I didnt want to use their name etc. For web 3.0 wallet integration. I dont care about HW wallets, just Nami and Yoroi.

rooooooooob commented 2 years ago

@devtrix No, not HW (Hardware) wallet, but HD (Hierarchical Deterministic). All Yoroi wallets are HD wallets. I'm not sure about nami. It's a scheme that lets you generate many derived keys from a root passphrase in a secure (and potentially privacy-focused) way.

What if you just pick something like one of the reward addresses? I think for most(all or almost all?) wallets there will only be one and if they return multiple you could just pick the first one lexigraphically and when they go to sign in you just see if you recognize any of them? Or ask them which one they want to use in the case where they have multiple.