SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 05:08:05 AM |
|
First - How can I get the public key of someone else's wallet? Or better yet, can a public key be derived from an address?
Second - How can I generate an address based on that public key? What mathematical calculations, hashes, encryption is being done behind the scenes?
Third - Would an address still "work" even if it was not generated by the wallet owner's client? In other words, if I had the public key of someone's wallet, and generated an address for them without them knowing, could I send them bitcoins to that newly generated address and they would receive them?
Thanks much!
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5292
Merit: 13207
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 05:30:01 AM |
|
First - How can I get the public key of someone else's wallet? Or better yet, can a public key be derived from an address?
It's listed on Bitcoin Block Explorer if it has ever been seen by the network. The full public key cannot be derived from the address alone, as the address is only a hash of the public key. How can I generate an address based on that public key? What mathematical calculations, hashes, encryption is being done behind the scenes? Hash it with SHA-256, then hash that with RIPEMD-160. Then add a version and a checksum and convert it to base58. Input the public key here: http://blockexplorer.com/q/hashpubkeyAnd then input that page's output here: http://blockexplorer.com/q/hashtoaddressHere's my PHP code to do it (pubKeyToAddress): http://pastebin.com/vmRQC7haWould an address still "work" even if it was not generated by the wallet owner's client? In other words, if I had the public key of someone's wallet, and generated an address for them without them knowing, could I send them bitcoins to that newly generated address and they would receive them? Yes. You'll get the same address. A particular public key always becomes the same address.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
BitterTea
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 05:36:00 AM |
|
First - How can I get the public key of someone else's wallet? Or better yet, can a public key be derived from an address? To build an address, a double hash (first SHA-256 then RIPEMD-160) of the public key is appended to the version. Then the first four bytes of the checksum (SHA-256 x 2) of this value are appended. The entire thing is base58 encoded. When you send someone a transaction, you put the hash of their public key in the scriptsig of the output. When they claim the output, they must have the private key whose public key hashes to that value. Second - How can I generate an address based on that public key? What mathematical calculations, hashes, encryption is being done behind the scenes? base58encode(version+ripemd-160(sha-256(public_key))+checksum(version+ripemd-160(sha-256(public_key)))) Where checksum is the first four bytes of sha-256(sha-256(data)). Third - Would an address still "work" even if it was not generated by the wallet owner's client? In other words, if I had the public key of someone's wallet, and generated an address for them without them knowing, could I send them bitcoins to that newly generated address and they would receive them? see this wiki article: https://en.bitcoin.it/wiki/Protocol_specification#AddressesYes, as long as they own the private key from which the public key is derived, and it is a valid bitcoin address.
|
|
|
|
SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 05:41:05 AM |
|
Thanks for the answers theymos and BitterTea! Guess I wasn't asking quite the right questions then... I assumed that each wallet only had one public key! What I am getting at is, how could I generate a list of addresses that I was sure would go to the same wallet? Looks like theymos's PHP code is most of the way there too... ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) Also, bittertea, in your equation, is checksum multiplied by the result of "version+ripemd-160(sha-256(public_key))"?
|
|
|
|
BitterTea
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 05:51:55 AM |
|
Thanks for the answers theymos and BitterTea! Guess I wasn't asking quite the right questions then... I assumed that each wallet only had one public key! What I am getting at is, how could I generate a list of addresses that I was sure would go to the same wallet? Looks like theymos's PHP code is most of the way there too... ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) Also, bittertea, in your equation, is checksum multiplied by the result of "version+ripemd-160(sha-256(public_key))"? A wallet is merely a container of public-private keypairs. You cannot tell whether two addresses belong to the same wallet without scanning a wallet file for the keys represented by the addresses. Check out the wiki page I linked, it should be more clear. A bitcoin address is in fact the hash of a ECDSA public key, computed this way:
Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key)) Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash)) Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)
|
|
|
|
SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 06:02:35 AM |
|
Interesting... thank you much! I will indeed read more in that wiki article.
|
|
|
|
SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 06:13:43 AM |
|
Sorry for all the questions. ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) Can I manually generate a public/private key that corresponds to a given address, then import that information into a wallet.dat to make that particular public/private key combo accepted into that particular wallet? If that is possible, what keeps me from importing the same public/private keys into multiple wallets and causing havoc?
|
|
|
|
anisoptera
Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 308
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 06:17:55 AM |
|
what keeps me from importing the same public/private keys into multiple wallets and causing havoc?
You could accomplish this already by just copying wallet.dat, and the answer is the same there as it is here: whoever spends the coins first wins.
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5292
Merit: 13207
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 06:20:08 AM |
|
Can I manually generate a public/private key that corresponds to a given address
No.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
BitterTea
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 06:22:54 AM |
|
Can I manually generate a public/private key that corresponds to a given address
What themos said. A public key can be derived from a private key, and an address can be derived from a public key, but those operations cannot be reversed. In order to get a private key from a public one you would have to break ECDSA, and in order to get a public key from an address you'd have to break SHA-256 (or scan the block chain).
|
|
|
|
SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 06:46:13 AM |
|
Then why couldn't I generate a private key, generate a public key based on the private key, and generate an address from the public key? Or are you saying that it's not possible to generate a private key, then import it into a wallet file?
|
|
|
|
BitterTea
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 08:11:41 AM |
|
Why don't you tell us what you are attempting to do, and we'll help you find the best way to do it?
|
|
|
|
SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 08:22:27 AM |
|
Sorry for the mystery.
Ultimately, I want to create my own vanity bitcoin addresses (i.e., addresses that contain particular letter/number combos). Gavin has already created a patch for the standard client that can do this, but I'd like to have the code to do it in PHP, and I'd like to know more about how addresses are generated. I'd also like to know if I can generate such vanity addresses for multiple wallets easily.
I suppose this presents a couple of questions. Would a server REQUIRE bitcoind to be running in order to find an address for a wallet? Or is there a way to generate addresses without having the wallet or bitcoind running?
The reason I want to do this in PHP rather than another language is because I am most familiar with PHP. That way, I can optimize the code and more easily manipulate it to what I want to do beyond these vanity address generations.
|
|
|
|
anisoptera
Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 308
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 05:39:31 PM |
|
If you generated a private key the same way bitcoin does and worked out a way to get that into a wallet.dat, then there's no reason you couldn't do what you say. There's nothing special about the private keys bitcoin generates that makes them addresses, they're standard. The tricky part is probably getting it into wallet.dat.
|
|
|
|
|
SgtSpike (OP)
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 01, 2011, 07:55:26 PM |
|
Thanks anisoptera. Guess I'll need to start looking at how data is stored in the wallet.
Thanks for the heads up Maged! Sounds like that sort of a pull could be very useful!
|
|
|
|
|