conradoqg / naivecoin

A cryptocurrency implementation in less than 1500 lines of code
Apache License 2.0
1.22k stars 319 forks source link

How to Verify Address #31

Open nxycdl opened 6 years ago

nxycdl commented 6 years ago

You have done a great work. Thank you! I have a question ; if a send some coin from a to b , if b address is wrong address how to Verify Address

conradoqg commented 6 years ago

Hey!

If you create that transaction and the B address is wrong, nothing can be done. This is why you need to 100% sure that the B address is right before creating the transaction.

Best

demenvil commented 6 years ago

Hi, The address can be verified only if it was created on the node or the creation of the transaction is requested. When calling try to see if the destination address is in the portfolios no? Or cant to apply for a balance before?

kwccoin commented 6 years ago

To be safe (in real world), I think (i) the wallet can check the address is a valid code somehow or (ii) you can go to the blockchain explorer to find the address first ... it may be the wrong address but at least it cannot be invalid.

As this is programming exercise here, I think my scheme would be:

  1. check the wallet program any chance to check the address you can do this

    http://localhost:3001/operator/e155df3a1bac05f88321b73931b48b54ea4300be9d1225e0b62638f537e5544/balance which returns

    No transactions found for address 'e155df3a1bac05f88321b73931b48b54ea4300be9d1225e0b62638f537e5544'

and for a valid address

http://localhost:3001/operator/e155df3a1bac05f88321b73931b48b54ea4300be9d1225e0b62638f537e5544c/balance which will return this json response

{"balance":47999997300}

and

  1. given there is no fee (:-)) transfer some of your coins to the new address
  2. check the blockchain explorer that there is such a transaction (see above)
  3. if there is on blockchain explorer, program one (as there is, no need)

...

conradoqg commented 6 years ago

@demenvil @kwccoin IMO it's hard to implement that kind of verification if the generation of the address is based on a password. The resulting address could be anything generated anywhere, meaning that for a given password any random address can be created. Without centralizing the address creation (government, central authority or something like that), it's impossible to know if the destination address is valid and if it's from whom you think it is. (I'm not saying that is impossible to determine that, but this imply that a good change to the concept of naivecoin would need to happen).

Coins like Bitcoin, Litecoin and so on use different ways to generate an address, and because of that, they can at least verify if the address is a valid bitcoin/litecoin address. Maybe we could change the way we generate the address by putting an additional NC_ identifier at the beginning of the address so, we can check if it was at least generated from a valid naivecoin client.

The options that @kwccoin showed above are valid approaches to identify the possibility of the target address to be an existing one/real one, however, I think this could be used only as a warning and in the client side (operator).

Do you agree?

Best

neurofluxation commented 6 years ago

@conradoqg - I really like the idea of changing up the address generation. Support for prefixes would be a "nice to have" in the config for sure.

typoworx-de commented 6 years ago

As far as I know mostly every wallet/currency has the API-Methode validateaddress for right this purpose. Right?