Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: miguelmorales85 on September 16, 2017, 08:49:28 AM



Title: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on September 16, 2017, 08:49:28 AM
Hello, I want to export my private keys for a SegWit wallet I created in Bitcoin Core 0.14

Currently I'm using Bitcoin Core 0.15
I did the usual procedure:
- walletpassphrase "passphrase" 600
- dumpprivkey "MySegWit-address-starting-in-3"

Then I got this error message:
Address does not refer to a key (code -3)


I check out the error code and is the following:
RPC_TYPE_ERROR                  = -3,  //! Unexpected type was passed as parameter

Is this a bug? Can some one confirm if its possible to export the private keys for a SegWit address in Bitcoin Core?


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on September 16, 2017, 11:28:54 AM
How exactly did you add this address to the wallet?

Hello, I want to export my private keys for a SegWit wallet I created in Bitcoin Core 0.14
There is no such thing as a "SegWit wallet".


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: AStorio on September 16, 2017, 11:39:31 AM
address-starting-in-3 it's multisig address, not SegWit-address


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on September 16, 2017, 11:48:02 AM
address-starting-in-3 it's multisig address, not SegWit-address
Segwit addresses start with an '3' (at least the current implementation of SW addresses). Do not respond to things which you clearly have no knowledge about.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on September 16, 2017, 01:37:06 PM
How exactly did you add this address to the wallet?

Hello, I want to export my private keys for a SegWit wallet I created in Bitcoin Core 0.14
There is no such thing as a "SegWit wallet".

Hello Lauda, I followed the procedure to create a SegWit address using the command line interface from Bitcoin Core 0.14:
- addwitnessaddress "address"

Now that I think about it, I dont remember the address I used to create that one. I am a bit confused right now.

Is this SegWit enabled address binded to another wallet? That is not what I believe address work.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on September 16, 2017, 01:59:36 PM
Hello Lauda, I followed the procedure to create a SegWit address using the command line interface from Bitcoin Core 0.14:
- addwitnessaddress "address"
That's correct, so you must have one of the following (known to the wallet)[1]:
1) Public key.
2) Redeem script.

Now that I think about it, I dont remember the address I used to create that one. I am a bit confused right now.

Is this SegWit enabled address binded to another wallet? That is not what I believe address work.
You need to remember what P2SH is and how it works. The current Segwit addresses are basically encapsulated in P2SH which makes it a tad more complicated (bech32 will be native Segwit and much better/easier).

[1] Unfortunately I don't have any Segwit addresses in Bitcoin Core to test and guide you through your inquiry. I have tested the command with a SW address generated in another wallet. You should look for the redeem script/related private keys.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on September 16, 2017, 02:23:49 PM
Hello Lauda, I followed the procedure to create a SegWit address using the command line interface from Bitcoin Core 0.14:
- addwitnessaddress "address"
That's correct, so you must have one of the following (known to the wallet)[1]:
1) Public key.
2) Redeem script.

Now that I think about it, I dont remember the address I used to create that one. I am a bit confused right now.

Is this SegWit enabled address binded to another wallet? That is not what I believe address work.
You need to remember what P2SH is and how it works. The current Segwit addresses are basically encapsulated in P2SH which makes it a tad more complicated (bech32 will be native Segwit and much better/easier).

[1] Unfortunately I don't have any Segwit addresses in Bitcoin Core to test and guide you through your inquiry. I have tested the command with a SW address generated in another wallet. You should look for the redeem script/related private keys.

Well, the address I used is definitely one of the other I have in my wallet. I dont know if there is such script to redeem.

Do you think I should report the issue to github?

I think there got to be a procedure to export the private key of the segwit enabled addresses.

Thanks for your help



Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on September 16, 2017, 02:25:51 PM
Well, the address I used is definitely one of the other I have in my wallet. I dont know if there is such script to redeem.
Every P2SH address, which that one is, has a redeem script. Read here: https://bitcoin.stackexchange.com/questions/52271/where-are-p2sh-full-redeem-scripts-stored.

Do you think I should report the issue to github?
Not yet.

I think there got to be a procedure to export the private key of the segwit enabled addresses.
I'm going forward with two questions for you:
1) How do you generate/add P2SH addresses to Bitcoin Core?
2) How do you export a P2SH address from Bitcoin Core?

Note: I'm talking about normal multisignature addresses.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on September 16, 2017, 02:46:07 PM

I'm going forward with two questions for you:
1) How do you generate/add P2SH addresses to Bitcoin Core?
2) How do you export a P2SH address from Bitcoin Core?

Note: I'm talking about normal multisignature addresses.

I am learning to use Bitcoin Core cli, I'm kinda noob.

I have not generated a multi-signature address using Bitcoin Core so I've never exported one.

I just wanted to create my first SegWit address and now that I have received some funds in it I wanted to backup my privkey. I have created my wallet backup I just wanted to test the priv key export solution.

I'll take a look at information in the URL.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on September 16, 2017, 03:01:21 PM
I am learning to use Bitcoin Core cli, I'm kinda noob.

I have not generated a multi-signature address using Bitcoin Core so I've never exported one.
Then rethink what you're doing here. You're asking me whether you should open an issue because X is happening, even though you don't know what the right behavior is supposed to be. Don't rush into things.

Quote
So what information is encoded in a P2SH address? A specific unspent Bitcoin can actually have a whole range of different spending conditions attached to it, the most common being a typical P2PKH which just requires the recipient to provide a signature matching the public key hash. The Bitcoin core developers realized that people were looking at the capabilities of Bitcoin's Script language and seeing a whole array of possibilities about what spending conditions you could attach to a Bitcoin output, to create much more elaborate transactions than just P2PKH transactions. The core developers decided that instead of letting senders put in long scripts into their scriptPubKey (where spending conditions usually go), they would let each sender put in a hash of their spending conditions instead. These spending conditions are known as the redeem script, and a P2SH funding transaction simply contains a hash of this redeem script in the scriptPubKey of the funding transaction.The redeem script itself is only revealed, checked against the redeem script hash, and evaluated during the spending transaction.
Source (the whole piece if very useful / I'd recommend reading): http://www.soroushjp.com/2014/12/20/bitcoin-multisig-the-hard-way-understanding-raw-multisignature-bitcoin-transactions/. Segwit in it's current form is encapsulated in P2SH.

Again disclaimer: I have not used any SW stuff with Bitcoin Core yet, thus I'm just basing this on my knowledge of P2SH and SW, which should be correct (or mostly correct).


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: jackg on September 16, 2017, 11:19:35 PM
Hello Lauda, I followed the procedure to create a SegWit address using the command line interface from Bitcoin Core 0.14:
- addwitnessaddress "address"
That's correct, so you must have one of the following (known to the wallet)[1]:
1) Public key.
2) Redeem script.

Now that I think about it, I dont remember the address I used to create that one. I am a bit confused right now.

Is this SegWit enabled address binded to another wallet? That is not what I believe address work.
You need to remember what P2SH is and how it works. The current Segwit addresses are basically encapsulated in P2SH which makes it a tad more complicated (bech32 will be native Segwit and much better/easier).

[1] Unfortunately I don't have any Segwit addresses in Bitcoin Core to test and guide you through your inquiry. I have tested the command with a SW address generated in another wallet. You should look for the redeem script/related private keys.

Well, the address I used is definitely one of the other I have in my wallet. I dont know if there is such script to redeem.

Do you think I should report the issue to github?

I think there got to be a procedure to export the private key of the segwit enabled addresses.

Thanks for your help

A segwit address, afaik will have to have something that can be produced from a normal address.

Open "help" > "debug" > "console".
Then try dumpprivkey address again but with the legacy address. Import that into a segwit accepting service


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: achow101 on September 17, 2017, 01:43:42 AM
addwitnessaddress was primarily a shim to facilitate testing of segwit. It was not really meant to be widely used by users for segwit.

Segwit addresses beginning with a '3' are actually P2SH addresses. This means that the address itself is mapped to a script (after all, it is Pay-to-script-hash), not to a private key. From there the parts of the script itself are mapped to a private key. However dumpprivkey does not go that deep, it only takes things that are mapped directly to a private key, which are P2PKH addresses and public keys. Segwit addresses are not mapped to a private key because they are really just P2SH addresses. So using dumpprivkey with segwit addresses will return an error (as will using any other P2SH address).

To get the private key of the address, you need to take the address that you used addwitnessaddress on originally and call dumpprivkey on that address.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on September 18, 2017, 06:37:47 PM
addwitnessaddress was primarily a shim to facilitate testing of segwit. It was not really meant to be widely used by users for segwit.

Segwit addresses beginning with a '3' are actually P2SH addresses. This means that the address itself is mapped to a script (after all, it is Pay-to-script-hash), not to a private key. From there the parts of the script itself are mapped to a private key. However dumpprivkey does not go that deep, it only takes things that are mapped directly to a private key, which are P2PKH addresses and public keys. Segwit addresses are not mapped to a private key because they are really just P2SH addresses. So using dumpprivkey with segwit addresses will return an error (as will using any other P2SH address).

To get the private key of the address, you need to take the address that you used addwitnessaddress on originally and call dumpprivkey on that address.

Hello, thank you for your reply. Do you know if there is a plan to start using , as a regular user, the SegWit addresses?
I think that if we need to show to the users that SegWit is the right path to take at least the Bitcoin Core should start implementing it.
I will take a look at GreenBit wallet to see how they implemented the SegWit solution.

What I do not understand is why P2SH address does not come from a private key, arent multi-signatures addresses generated from private keys? The more I know about BTC the more I get to think that I know nothing. ???



Quote
So what information is encoded in a P2SH address? A specific unspent Bitcoin can actually have a whole range of different spending conditions attached to it, the most common being a typical P2PKH which just requires the recipient to provide a signature matching the public key hash. The Bitcoin core developers realized that people were looking at the capabilities of Bitcoin's Script language and seeing a whole array of possibilities about what spending conditions you could attach to a Bitcoin output, to create much more elaborate transactions than just P2PKH transactions. The core developers decided that instead of letting senders put in long scripts into their scriptPubKey (where spending conditions usually go), they would let each sender put in a hash of their spending conditions instead. These spending conditions are known as the redeem script, and a P2SH funding transaction simply contains a hash of this redeem script in the scriptPubKey of the funding transaction.The redeem script itself is only revealed, checked against the redeem script hash, and evaluated during the spending transaction.
Source (the whole piece if very useful / I'd recommend reading): http://www.soroushjp.com/2014/12/20/bitcoin-multisig-the-hard-way-understanding-raw-multisignature-bitcoin-transactions/. Segwit in it's current form is encapsulated in P2SH.

Again disclaimer: I have not used any SW stuff with Bitcoin Core yet, thus I'm just basing this on my knowledge of P2SH and SW, which should be correct (or mostly correct).

Thank for the URL Lauda. I will read it, hope it is not so crypto-technical


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Yogafan00000 on October 03, 2017, 12:52:30 PM
I'm in the same situation as OP.

I wanted to try a segwit address to receive some funds from an exchange.

So I generated a new regular address (the old way) then I went to console and did command addwitnessaddress newaddress and got another address with starting with 3

Then, with the intent of confirming I own the keys, I tried dumprivkey on the new segwit address and got the same error as OP.

I would love some knowledge to weigh in on what I'm dealing with, at a practical level.

What exactly is this segwit address I have starting with 3, and why's there no privatekey to it?
What happens if I send funds to it? Is the balance held under the orig address?
What's the difference between this and the first non-segwit address?
Why should I use 1 over the other?


TIA!!


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: achow101 on October 03, 2017, 03:14:07 PM
What exactly is this segwit address I have starting with 3, and why's there no privatekey to it?
Read the thread, I already explained above.

What happens if I send funds to it? Is the balance held under the orig address?
No, it is held under the '3' address.

Addresses and public-private key pairs are different things. A public-private key pair can be associated with many different addresses, not just one '1' address.

What's the difference between this and the first non-segwit address?
It uses segwit.

Why should I use 1 over the other?
Segwit has lower transaction fees.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on October 03, 2017, 03:30:34 PM
Do you know if there is a plan to start using , as a regular user, the SegWit addresses?
Yes, obviously. Bitcoin Core 0.15.1 or 0.16.0 will have GUI support for SegWit.

I think that if we need to show to the users that SegWit is the right path to take at least the Bitcoin Core should start implementing it.
I will take a look at GreenBit wallet to see how they implemented the SegWit solution.
You can use SegWit easily in plenty of other wallets, e.g. Ledger.

What I do not understand is why P2SH address does not come from a private key, arent multi-signatures addresses generated from private keys? The more I know about BTC the more I get to think that I know nothing. ???
I've told you to do your research and achow has explained it. P2SH is mapped to a script, which itself is mapped to private keys. So, if you have a 2 of 3 multisig address you can't "dumpprivkey" on it. You run "dumpprivkey" on the two addresses (or all three) that were used to create the script, ergo the multisig address.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Yogafan00000 on October 03, 2017, 07:18:06 PM

(stuff that achow101 said)


thank you for the answers you provide. I appreciate your time.

What I ended up doing just for today is creating another legacy address on my core wallet and just using that one for my transaction.

I'm sure segwit is great and everything, but I can't afford a headache today if I somehow fuckit up.

I'll try another segwit transaction some other time when I have a more clear understanding of all implications of using segwit addresses from core.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on October 03, 2017, 07:47:19 PM
I think I will not use SegWit address until the process is more user friendly on the Bitcoin Core client.

I wanted to test some transactions and use the new address created to mode some satoshis but I guess I will wait for 0.15.1 ... 0.16... etc

Thank guys for the explanation, there are a lot of great mind in the forum  8)


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: Lauda on October 04, 2017, 06:40:53 AM
I'm sure segwit is great and everything, but I can't afford a headache today if I somehow fuckit up.
I don't see any possible mistake that you could run into while not doing anything not out of the ordinary.

I'll try another segwit transaction some other time when I have a more clear understanding of all implications of using segwit addresses from core.
I think I will not use SegWit address until the process is more user friendly on the Bitcoin Core client.
Use a different wallet in the meantime (if you want to use SegWit), as I've said.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: miguelmorales85 on October 12, 2017, 11:41:45 AM
I have done some exploration in blockchain.info and found this details into my SegWit address:
it has a Hash 160 associated (as do all bitcoin addresses)

When I click on this Hash 160 code I get to another bitcoin address. Could it be this is the original address I used to generated my SegWit address??

I have not found a way to discover my original address from which I generated the SegWit one.


Title: Re: Exporting a SegWit wallet Private Keys on Bitcoin Core 0.15
Post by: jackg on October 25, 2017, 12:34:39 AM
I have done some exploration in blockchain.info and found this details into my SegWit address:
it has a Hash 160 associated (as do all bitcoin addresses)

When I click on this Hash 160 code I get to another bitcoin address. Could it be this is the original address I used to generated my SegWit address??

I have not found a way to discover my original address from which I generated the SegWit one.

If by hash160 you mean the private key, then importing this into any wallet (such as bitcon core or electrum) will generate your legacy address (under normal circumstances).

Generally from my understanding the segwit address is merely a legacy address but with a 3 instead of a 1 (in most regular cases)