Bitcoin Forum
June 21, 2024, 07:49:18 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: BlockCypher signing Bitcoin transaction incorrect private key format  (Read 467 times)
eebra82 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 2


View Profile
July 29, 2017, 02:41:28 PM
 #1

I am trying to sign a Bitcoin transaction using the BlockCypher API but I am failing because I don't have my private key in the correct format.

According to their documentation:

Quote
"One of the most common errors in the signing process is a data format mismatch. We always return and expect hex-encoded data, but oftentimes, standard signing libraries require byte arrays. Remember to convert your data, and always send hex-encoded signatures to BlockCypher."

The PHP code should be as follows:

$privateKeys = array("2c2cc015519b79782bd9c5af66f568e808f573714f3c4dc6df7d79c183783cff");
$txSkeleton = $txClient->sign($txSkeleton, $privateKeys);

But my private key is in the format xprv9s21ZrQH143K4NejhhRcspQdS2g7JgnSVwmT2dkXQuszJaQqjYD3wdUdsXyqmfetdUZ2SS25uM7 nAfnUwNDGA75bfqYxKwYZ8zDdaCv6meL, ie not in hex.

I have tried simply converting it to hex, which obviously was a bit overoptimistic of me but the transaction signing fails.

I have Googled and Googled this for weeks and have been unable to figure out how to convert a xprv prefix key into the correct format as required by the BlockCypher API.

I am a paying customer of theirs and have e-mailed them but no reply after two weeks of waiting.

I'm at my wits end and any help would be very much appreciated.
cloverme
Legendary
*
Offline Offline

Activity: 1512
Merit: 1057


SpacePirate.io


View Profile WWW
July 29, 2017, 03:05:42 PM
 #2

You don't need to convert the PK to hex, the hex part they are talking about is the output when you create a transaction. If the transaction signing is failing, there's probably a problem in how you're creating the inputs/outputs of the transactions. You're probably close, try debugging by printing the output of your array ($txSkeleton)... my guess is that there's an issue in it.
eebra82 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 2


View Profile
July 30, 2017, 01:37:16 AM
 #3

cloverme,

Thank you for your advice, I tried again and the actual txSkeleton appears to be fine.

I'm sure the key has to be in hex, if I try to sign the transaction with the xprv key as it is then I get as follows with one error for each character in the key: (x, p, r, v etc.)

Warning: pack(): Type H: illegal hex digit x in .../BlockCypher-php-client-1.5.0/php-client/bitwasp/buffertools/src/Buffertools/Buffer.php on line 57

And then it aborts with:

Fatal error: Uncaught exception 'BlockCypher\Exception\BlockCypherSignatureException' with message '1 private keys do not correspond to any input. Please check private keys provided.' in .../BlockCypher-php-client-1.5.0/php-client/blockcypher/php-client/lib/BlockCypher/Api/TXSkeleton.php:164

If I change the key to any hex, then I only get the last fatal error. Which is pretty expected since the (random) key I am providing then is not matching with the address I am using to fund the transaction.

Do you have any idea how to get from a xprv prefixed key to the 64 digit long hex key that BlockCypher is expecting as input?

Thank you so much in advance.
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!