Bitcoin Forum
May 05, 2024, 11:19:08 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: A little technical information request...  (Read 1648 times)
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 05:08:05 AM
 #1

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!
"If you don't want people to know you're a scumbag then don't be a scumbag." -- margaritahuyan
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714907948
Hero Member
*
Offline Offline

Posts: 1714907948

View Profile Personal Message (Offline)

Ignore
1714907948
Reply with quote  #2

1714907948
Report to moderator
1714907948
Hero Member
*
Offline Offline

Posts: 1714907948

View Profile Personal Message (Offline)

Ignore
1714907948
Reply with quote  #2

1714907948
Report to moderator
1714907948
Hero Member
*
Offline Offline

Posts: 1714907948

View Profile Personal Message (Offline)

Ignore
1714907948
Reply with quote  #2

1714907948
Report to moderator
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5194
Merit: 12972


View Profile
June 01, 2011, 05:30:01 AM
 #2

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.

Quote
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/hashpubkey
And then input that page's output here:
http://blockexplorer.com/q/hashtoaddress

Here's my PHP code to do it (pubKeyToAddress):
http://pastebin.com/vmRQC7ha

Quote
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?

Yes. You'll get the same address. A particular public key always becomes the same address.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
BitterTea
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250



View Profile
June 01, 2011, 05:36:00 AM
 #3

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.

Quote
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)).

Quote
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#Addresses

Yes, 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 Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 05:41:05 AM
 #4

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

Also, bittertea, in your equation, is checksum multiplied by the result of "version+ripemd-160(sha-256(public_key))"?
BitterTea
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250



View Profile
June 01, 2011, 05:51:55 AM
 #5

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

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.

Quote
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 Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 06:02:35 AM
 #6

Interesting... thank you much!  I will indeed read more in that wiki article.
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 06:13:43 AM
 #7

Sorry for all the questions.  Smiley

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
**
Offline Offline

Activity: 308
Merit: 10



View Profile
June 01, 2011, 06:17:55 AM
 #8

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 Offline

Activity: 5194
Merit: 12972


View Profile
June 01, 2011, 06:20:08 AM
 #9

Can I manually generate a public/private key that corresponds to a given address

No.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
BitterTea
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250



View Profile
June 01, 2011, 06:22:54 AM
 #10

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 Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 06:46:13 AM
 #11

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
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250



View Profile
June 01, 2011, 08:11:41 AM
 #12

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 Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 08:22:27 AM
 #13

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
**
Offline Offline

Activity: 308
Merit: 10



View Profile
June 01, 2011, 05:39:31 PM
 #14

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.

Maged
Legendary
*
Offline Offline

Activity: 1204
Merit: 1015


View Profile
June 01, 2011, 07:31:38 PM
 #15

The tricky part is probably getting it into wallet.dat.
As far as that goes, this patch is in the works:
http://forum.bitcoin.org/index.php?topic=8091.0

SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
June 01, 2011, 07:55:26 PM
 #16

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!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!