Bitcoin Forum
May 08, 2024, 11:14:02 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1] 2 »
1  Local / Discussioni avanzate e sviluppo / Re: Raccolta fonti di codice sorgenti legati al Bitcoin e crittovalute on: December 28, 2020, 10:33:04 AM
un ottimo debug per Bitcoin Script: https://github.com/kallewoof/btcdeb
2  Bitcoin / Bitcoin Technical Support / Re: Generate P2WSH - redeemScript does not correspond to witnessScript on: April 14, 2020, 06:52:55 AM
Yes I saw the PR!
I thought that another example should be interest to understand the bug  Wink

3  Bitcoin / Bitcoin Technical Support / Re: Generate P2WSH - redeemScript does not correspond to witnessScript on: April 13, 2020, 09:24:36 PM
I create another script P2SH-P2WSH wrap P2PK and I get the same error.

Code:
$ cat compressed_public_key_1.txt 
03ccf24edaa6fe2fd9f5a9d2103be709f388e31814b2ae1a68de9fd7283ed202b8
$ cat redeem_script_1.txt
0020c9d55d035e6f48bd09d06a72a221374e6b8ab2e5ca79c3f81aed7560bcbf35b7                                                                                                                   
$ cat scriptPubKey_1.txt
A9146fbae965219dd0d5e0ec6355221bcdce2670ba1487                                                                                                                                         
$ cat witness_script_1.txt
2103ccf24edaa6fe2fd9f5a9d2103be709f388e31814b2ae1a68de9fd7283ed202b8AC

Create transaction and sign it

Code:
$ TX_DATA=$(bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT'}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]')

$ bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEMSCRIPT'","witnessScript":"'$WITNESSCRIPT'","amount":"'$TOTAL_UTXO_AMOUNT'"}]'  | jq -r '.hex'

error code: -8
error message:
redeemScript does not correspond to witnessScript


I don't try with custom script yet
4  Bitcoin / Bitcoin Technical Support / Re: Generate P2WSH - redeemScript does not correspond to witnessScript on: April 01, 2020, 03:39:55 PM
It looks like you've run into a bug in Bitcoin Core

Specifically, for historical reasons, Bitcoin Core will sometimes automatically convert P2PKH scripts into P2WPKH outputs when doing segwit stuff. So what happened is that when it checks whether the redeemScript matches the witnessScript, it mistakenly computes the P2WPKH script for your P2PKH witnessScript instead of the P2WSH script that you are expecting. This causes a mismatch and the error.

You could try omitting the redeemScript field from your call to signrawtransactionwithkey but it may fail to sign then.

I've opened a PR to fix this.

Thanks for reply.
I tried to omit the redeem script
Code:
$ bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","witnessScript":"'$WITNESSCRIPT'","amount":"'$TOTAL_UTXO_AMOUNT'"}]'
error code: -8
error message:
redeemScript/witnessScript does not match scriptPubKey

But I get the same error
5  Bitcoin / Bitcoin Technical Support / Generate P2WSH - redeemScript does not correspond to witnessScript on: March 31, 2020, 02:39:51 PM
I want to generate P2WSH to study it. I read the spec https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wsh-address but I have an error during spend it. (redeemScript does not correspond to witnessScript)

I create a bash script to generate private and public key, and I will report only the part to create redeem script etc.

Public key
Code:
02aa31bcc43d302bd217761e3268b3fde67078a8ddcb157517f9c69633f5f9e214

Witness script
Code:
SCRIPT="76a9"$PBLENGTH$PBH"88AC"
printf $SCRIPT > witness_script.txt
> result: 76a9143a067efd9e4c79d0b8c94d81108fa21920ef896788AC

Create Script Hash, use sha256 once
Code:
ADDR_SHA=`printf $SCRIPT | xxd -r -p | openssl sha256| sed 's/^.* //'`
printf $ADDR_SHA > scripthash.txt
> result: bd73935d1af51d3e4490f158cc2585fdd8ac81cae898855faa8e26606a7e9934

Create redeem script  (i.e. 0x0020{32-byte scripthash})
Code:
REDEEMSCRIPT="0020"$ADDR_SHA
printf $REDEEMSCRIPT > redeem_script.txt
> result: 0020bd73935d1af51d3e4490f158cc2585fdd8ac81cae898855faa8e26606a7e9934

Create SCRIPTPUBKEY (OP_HASH160 hash160(redeemScript) OP_EQUAL) where hash160 is Sha256 and ripemd160
Code:
  ADDR_160=$(printf $(printf $REDEEMSCRIPT | xxd -r -p | openssl sha256| sed 's/^.* //') | xxd -r -p | openssl ripemd160 | sed 's/^.* //')
  SCRIPTPUBKEY="A914"$ADDR_160"87"
  printf $SCRIPTPUBKEY > scriptPubKey.txt
> result: A914bb18c1d4c6d65ca60f4dee268475c429f9896b6587

Create Address (regtest, prefix is C4)
Code:
  ADDR=`printf $VERSION_PREFIX_ADDRESS$ADDR_160 | xxd -p -r | base58 -c`
  printf $ADDR > address_p2sh-p2wsh.txt
> result: 2NAJW1K8Us8ymnzZvRJY4JPqKQ6VqRcMqd7

Then I create a transaction from this address to anther address. I have 50 bitcoin available.
Code:

REDEEMSCRIPT=`cat redeem_script.txt`
SCRIPTPUBKEY=`cat scriptPubKey.txt`
WITNESSCRIPT=`cat witness_script.txt`

TX_DATA=$(bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT'}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]')

TX_SIGNED=$(bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEMSCRIPT'","witnessScript":"'$WITNESSCRIPT'","amount":"'$TOTAL_UTXO_AMOUNT'"}]'  | jq -r '.hex')

At that moment I have this error
redeemScript does not correspond to witnessScript

TX_DATA:
Code:
{
  "txid": "b0a12356d1caa8bb6cfb1dd572c520742fc96d176762a10b8f669118744417c7",
  "hash": "b0a12356d1caa8bb6cfb1dd572c520742fc96d176762a10b8f669118744417c7",
  "version": 2,
  "size": 85,
  "vsize": 85,
  "weight": 340,
  "locktime": 0,
  "vin": [
    {
      "txid": "4de43b38df24ff350ac9821637ea8996fa33d20aa99677b86918f577697a3e15",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 49.99100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 af886b3952c6b69e25721d6ffbf3d96c39ca4352 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914af886b3952c6b69e25721d6ffbf3d96c39ca435288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mwX5yAv3Q42VsebJwuk3Qzn2mikWBugF4g"
        ]
      }
    }
  ]
}

UTXO
Code:
$ bitcoin-cli getrawtransaction 4de43b38df24ff350ac9821637ea8996fa33d20aa99677b86918f577697a3e15 2
{
  "txid": "4de43b38df24ff350ac9821637ea8996fa33d20aa99677b86918f577697a3e15",
  "hash": "df9abe47f73aacbe0fd021868123c0a7e9ab923db9d8a4972f12bdb36d8e89d6",
  "version": 2,
  "size": 169,
  "vsize": 142,
  "weight": 568,
  "locktime": 0,
  "vin": [
    {
      "coinbase": "510101",
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 50.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 bb18c1d4c6d65ca60f4dee268475c429f9896b65 OP_EQUAL",
        "hex": "a914bb18c1d4c6d65ca60f4dee268475c429f9896b6587",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2NAJW1K8Us8ymnzZvRJY4JPqKQ6VqRcMqd7"
        ]
      }
    },
    {
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
        "hex": "6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
        "type": "nulldata"
      }
    }
  ],
  "hex": "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0200f2052a0100000017a914bb18c1d4c6d65ca60f4dee268475c429f9896b65870000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000",
  "blockhash": "4fa868b42b4f935ff48ae10893f5dad5cb1a0fb5c1f1dd38b7cbe476aa3c0270",
  "confirmations": 107,
  "time": 1585666082,
  "blocktime": 1585666082
}

6  Local / Crittografia e decentralizzazione / Re: Che cos'è PGP? on: March 13, 2020, 02:32:32 PM
Interessante Articolo
https://medium.com/@satoshiwantsyou/verifica-signature-bitcoin-core-pgp-628bee490767
7  Bitcoin / Bitcoin Technical Support / Re: Get private_key.pem from WIF format on: March 08, 2020, 11:32:58 AM
Amazing dex1, it works!
Can you explain
Code:
PRE_STRING=302e0201010420
secp256k1_ID=a00706052b8104000a
I searched more details but I don't find good resources
8  Bitcoin / Bitcoin Technical Support / Get private_key.pem from WIF format on: March 06, 2020, 04:09:55 PM
I want to retrieve my private_key.pem format in order to sign my transaction

For example, I create P2SH address
Code:
$ ADDR_DEST_1=`bitcoin-cli getnewaddress`            
$ echo $ADDR_DEST_1
2MzdMAQKoPr2x7Bzm6tpGpDPnvWmsL9AjQA

I can Get Private key WIF
Code:
$ bitcoin-cli dumpprivkey $ADDR_DEST_1
cP73T5gHo6Wnyco11T2fsxocZqsQE6hwPG9UG1vcupMZh4iLyH19

Now I can do base58 decode
Code:
$ printf cP73T5gHo6Wnyco11T2fsxocZqsQE6hwPG9UG1vcupMZh4iLyH19 | base58 -d | xxd -p -c 76     
ef2d7238106df87d7b70f9d7cc4ff833ff9fad86aa5e50f8cf42689c238d70f72301c597c498

ef  is version prefix for testnet/regtest
01 compression flag
c597c498 should be the checksum.

Then My key is: 2d7238106df87d7b70f9d7cc4ff833ff9fad86aa5e50f8cf42689c238d70f723

Now I need to get private key pem.
Then I tried with

Code:
echo 2d7238106df87d7b70f9d7cc4ff833ff9fad86aa5e50f8cf42689c238d70f723 > btc_priv.key

$ openssl ec -noout -text -inform DER -in foo_priv.key
read EC key
unable to load Key

$ openssl x509 -in btc_priv.key -inform DER -outform PEM
unable to load certificate
4486393452:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1220:
4486393452:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:386:Type=X509

$ cat btc_priv.key | xxd -r -p  > test.bin  
$ openssl ec -in test.bin -inform DER -pubin -text -noout                
read EC key
unable to load Key
4456304236:error:0D06B08E:asn1 encoding routines:ASN1_D2I_READ_BIO:not enough data:a_d2i_fp.c:247:

I searched in https://github.com/bitcoin/bitcoin/blob/452bb90c718da18a79bfad50ff9b7d1c8f1b4aa3/src/secp256k1/contrib/lax_der_privatekey_parsing.c and https://github.com/bitcoin/bitcoin/blob/99813a9745fe10a58bedd7a4cb721faf14f907a4/src/rest.cpp But I don't understand Sad
9  Bitcoin / Bitcoin Technical Support / Re: Sign Transaction Bitcoin with Openssl on: March 03, 2020, 09:50:31 PM
Ok I'm back! Smiley

The problem is
Code:
openssl dgst -sha256 -hex -sign chiave_priv_3.pem a.txt
In that way I do another SHA256! I did SHA256 3 times!  Shocked

To resolve this issue, I can do something like
Code:
$ openssl pkeyutl -inkey chiave_priv_3.pem -sign -in a.txt -pkeyopt digest:sha256 | xxd -p -c 256
or I can do single SHA256 and apply another SHA256 with openssl
Code:
$ printf 0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b000000001976a914d2bb7890f3f6356d89673367b44e9a7d0265009188acffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac0000000001000000 | xxd -r -p | sha256sum -b | xxd -r -p > a.txt
$ openssl dgst -sha256 -hex -sign chiave_priv_3.pem a.txt

I prefer the first solution!

About "mandatory-script-verify-flag-failed (Non-canonical signature: S value is unnecessarily high) (code 16)" it's more complicated than that.
I converted the S (DER signature) to base10. (it's another signature, not the same of thread, sorry but I have my notes)
For example:
Code:
$ s=`echo "ibase=16; $(printf 00f00e64e164ce4fee984165ba8205a8544ece37458006687cdaa53d4e6e1859bc  | tr '[:lower:]' '[:upper:]')" | bc |  tr -d '\n' | tr -d '\' | awk '{print $1}'`
$ echo $s
108580515770129610852831425129233053758690240817412348750872366071983533218236

Then convert N to base 10, and get N/2
Code:
$ N=`echo "ibase=16;FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141" | bc  |  tr -d '\n' | tr -d '\' | awk '{print $1}'`
$ echo $N
108580515770129610852831425129233053758690240817412348750872366071983533218236

$ N2=`echo "$N/2" | bc |  tr -d '\n' | tr -d '\' | awk '{print $1}'`
$ echo $N2
57896044618658097711785492504343953926418782139537452191302581570759080747168

You can find very cool stuffs if u search 108580515770129610852831425129233053758690240817412348750872366071983533218236 or 57896044618658097711785492504343953926418782139537452191302581570759080747168 in google

Now I Check if s is greater than N/2, if it is I need to subtract it. (N-S)
Code:
$ s=`echo "$N - $s" | bc |  tr -d '\n' | tr -d '\' | awk '{print $1}'`  
$ echo $s
7211573467186584570739559879454854094147323461662555631732797069534628276101

Convert the result to base16
Code:
$ s=`echo "obase=16;$s" | bc`
$ echo $s
E2412F237BCDCA1AD1AD7DA1075D8C0AD258A07066D695F99DEA0AAEC7034A4

Sometimes you can get odd bytes, in that case I have 63 hex.
Code:
$ printf FF19B1E9B31B01167BE9A457DFA57AA6BE0A5A12F4237BEE52D213E621DE785 | wc -c
  63
It's very similar when you get seed phrase, if you don't have a block of 11 bits, you need to add some "padding", then I add 0 at the beginning.

Code:
s=0FF19B1E9B31B01167BE9A457DFA57AA6BE0A5A12F4237BEE52D213E621DE785

Now I can make a "new" DER signature, replace the old s with the new one, calculate the length of it and the length of signature!
And it works! Smiley
I hope to help someone!
Thanks to Andrew Chow and BrewMaster for your time guys
(English is not my mother tongue; please excuse any errors on my part)


10  Bitcoin / Bitcoin Technical Support / Re: Sign Transaction Bitcoin with Openssl on: February 25, 2020, 03:25:14 PM
Thanks for your reply, I saw that links about that issue "mandatory-script-verify-flag-failed (Non-canonical signature: S value is unnecessarily high) (code 16)".

https://github.com/bitcoin-core/secp256k1/blob/544435fc90a5672d862e2a51f44c10251893b97d/src/ecdsa_impl.h#L310-L315

Do you know If I can check S before signature or If I can do that function 
Code:
if (S > N/2) then S = N - S
in bash without use external library?

thanks
11  Bitcoin / Bitcoin Technical Support / Re: Sign Transaction Bitcoin with Openssl on: February 17, 2020, 11:56:05 AM
Thanks again.
I created a script to replicate my goal.
I change public key uncompressed with compressed.

Sometimes I get that error:
mandatory-script-verify-flag-failed (Non-canonical signature: S value is unnecessarily high) (code 16)
It's the issue that you explain in the last post.

and sometimes I get that error:
mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 16)
12  Bitcoin / Bitcoin Technical Support / Re: Sign Transaction Bitcoin with Openssl on: February 17, 2020, 10:51:54 AM
Thanks for reply.

I followed the steps but I have some issues.

Paste the new parts here, public keys and private keys are the same.
My enviroment is regtest.

this is my UTXO
Code:
  {
   {
    "txid": "3bd88800252c4d049ced8813b1d6fff76b99d84e56289dfd60eca8898814a8e2",
    "vout": 0,
    "address": "mzjCn3ojXBGWcRjWYfJdNdrM9yr5UbpXgq",
    "label": "",
    "scriptPubKey": "76a914d2bb7890f3f6356d89673367b44e9a7d0265009188ac",
    "amount": 49.99900000,
    "confirmations": 6,
    "spendable": true,
    "solvable": true,
    "desc": "pkh([d2bb7890]03d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748)#67xu85z0",
    "safe": true
  },


there are my parameters for my transaction:
Code:
TXID=3bd88800252c4d049ced8813b1d6fff76b99d84e56289dfd60eca8898814a8e2
VOUT=0
AMOUNT=49.998
ADDR_MITT=msPjuNgbmbRSkNGJPvquKJRRmrbzS96s62

Now create my transaction data
Code:
$ bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT'}]' '[{"'$ADDR_MITT'":'$AMOUNT'}]'
0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b0000000000ffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac00000000

Now I put the scriptPubKey and SigHash.
Code:
0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b000000001976a914d2bb7890f3f6356d89673367b44e9a7d0265009188acffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac0000000001000000

(I tried even with ScriptPub of previous transaction. The UTXO of 3bd88800252c4d049ced8813b1d6fff76b99d84e56289dfd60eca8898814a8e2.)

Double SHA256
Code:
printf 0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b000000001976a914d2bb7890f3f6356d89673367b44e9a7d0265009188acffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac0000000001000000 | xxd -r -p | sha256sum -b | xxd -r -p | sha256sum -b > a.txt

Code:
result:
f1f941f66a7bd080f14506ff91a05bd3d525dae236a4d86bac5dfa6e3bce4563

Signature
Code:
openssl dgst -sha256 -hex -sign chiave_priv_3.pem a.txt
EC-SHA256(a.txt)= 30450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f

add 01 at the end.
Code:
30450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f01

48 is the signature Length.

Public key not compressed is
Code:
04d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748321ac6d22737633f56538a28158d2558ca09407d9f6cc221c54b873e4cb9b999

41 is the public key length.

Signature+public key is 278 char => 8B

The whole transaction is
Code:
0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b000000008B4830450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f014104d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748321ac6d22737633f56538a28158d2558ca09407d9f6cc221c54b873e4cb9b999ffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac00000000

Code:
$ bitcoin-cli sendrawtransaction 0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b000000008B4830450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f014104d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748321ac6d22737633f56538a28158d2558ca09407d9f6cc221c54b873e4cb9b999ffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac00000000
error code: -26
error message:
mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation) (code 16)

Code:
$ bitcoin-cli decoderawtransaction 0200000001e2a8148889a8ec60fd9d28564ed8996bf7ffd6b11388ed9c044d2c250088d83b000000008B4830450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f014104d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748321ac6d22737633f56538a28158d2558ca09407d9f6cc221c54b873e4cb9b999ffffffff01c0e4022a010000001976a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac00000000
{
  "txid": "0101c9603426d1476d813617bc9af7c83eb62d1efec973c096ba55ad74c3501b",
  "hash": "0101c9603426d1476d813617bc9af7c83eb62d1efec973c096ba55ad74c3501b",
  "version": 2,
  "size": 224,
  "vsize": 224,
  "weight": 896,
  "locktime": 0,
  "vin": [
    {
      "txid": "3bd88800252c4d049ced8813b1d6fff76b99d84e56289dfd60eca8898814a8e2",
      "vout": 0,
      "scriptSig": {
        "asm": "30450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f[ALL] 04d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748321ac6d22737633f56538a28158d2558ca09407d9f6cc221c54b873e4cb9b999",
        "hex": "4830450220120a27e6e275545d4b1c79d4fad40a5d6dc9d44f512a00d5b2b71b68e5e4d376022100bf6284c39500565c089efec95db1d82869882a08b30513a3de0287ff223b834f014104d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748321ac6d22737633f56538a28158d2558ca09407d9f6cc221c54b873e4cb9b999"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 49.99800000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 824441111b374bec1952a5b3fa9dd4e3ed679b38 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914824441111b374bec1952a5b3fa9dd4e3ed679b3888ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "msPjuNgbmbRSkNGJPvquKJRRmrbzS96s62"
        ]
      }
    }
  ]
}


13  Bitcoin / Bitcoin Technical Support / Sign Transaction Bitcoin with Openssl on: February 16, 2020, 11:11:46 AM
I created Legacy address in testnet enviroment.
Code:
    $ openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out chiave_priv.pem
    -----BEGIN EC PARAMETERS-----
    BgUrgQQACg==
    -----END EC PARAMETERS-----
    -----BEGIN EC PRIVATE KEY-----
    MHQCAQEEIIec9IrjQkpFhCAqMMNHQuU/6X7+DDH7p/TPr2on9j+XoAcGBSuBBAAK
    oUQDQgAEJNcNWmojf5IU23BoNL6mG1VLcV08UAqXp/YrE6AbMkaVj05xJJCPg2FN
    wu/j5c/5zp6GoBla+XuYagwHl0VwAQ==
    -----END EC PRIVATE KEY-----

    $ openssl ec -in chiave_priv.pem -outform DER|tail -c +8|head -c 32 |xxd -p -c 32 > btc_priv.key
    879cf48ae3424a4584202a30c34742e53fe97efe0c31fba7f4cfaf6a27f63f97

It's my private key WIF
Code:
    cS8KGbfbAxW6DLWvDQAfR4ZPXC2yJVXa7Qj4gYrFZNNGcWtbyPJ6

it is my compressed public key
Code:
    0324d70d5a6a237f9214db706834bea61b554b715d3c500a97a7f62b13a01b3246

it's my transaction data that I want to sign with my private key
Code:
    0200000001bc010c04e1c44a991760fa1cb7af1076bf755077d1cba60d3d4ca3f0de670d210000000000ffffffff01c0aff629010000001976a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac00000000

I know that I have to do double sha256
Code:
    $ printf 0200000001bc010c04e1c44a991760fa1cb7af1076bf755077d1cba60d3d4ca3f0de670d210000000000ffffffff01c0aff629010000001976a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac00000000 | xxd -r -p | sha256sum -b | xxd -r -p | sha256sum -b > a.txt

Now Sign it (maybe here the error?)
Code:
    $ openssl dgst -sha256 -hex -sign chiave_priv.pem a.txt  
    EC-SHA256(a.txt)= 30440220113f4da0dab33c850b13c3f8e8239acdb9d474808d9c65e91a9304c4573ac3fc0220514df1aaf115535de6e3a7da19011b416b84bd2ec8737958d2d97c6eed6985f7

Create ScriptSig

 - 6A ScriptSig length => 212 char hex
 - 47 Signature Length+SIGHHASH => 142 char hex
 - < signature > 01
 - 01 => SIGHASH_ALL
 - 21 Public key length => 66 char hex
 - < public key >

Below you can find the whole transaction data
Code:
0200000001bc010c04e1c44a991760fa1cb7af1076bf755077d1cba60d3d4ca3f0de670d21000000006A4730440220113f4da0dab33c850b13c3f8e8239acdb9d474808d9c65e91a9304c4573ac3fc0220514df1aaf115535de6e3a7da19011b416b84bd2ec8737958d2d97c6eed6985f701210324d70d5a6a237f9214db706834bea61b554b715d3c500a97a7f62b13a01b3246ffffffff01c0aff629010000001976a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac00000000

When I try to sentransaction, I get a error
Code:
    $ bitcoin-cli sendrawtransaction 0200000001bc010c04e1c44a991760fa1cb7af1076bf755077d1cba60d3d4ca3f0de670d21000000006A4730440220113f4da0dab33c850b13c3f8e8239acdb9d474808d9c65e91a9304c4573ac3fc0220514df1aaf115535de6e3a7da19011b416b84bd2ec8737958d2d97c6eed6985f701210324d70d5a6a237f9214db706834bea61b554b715d3c500a97a7f62b13a01b3246ffffffff01c0aff629010000001976a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac00000000
        error code: -26
        error message:
        mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 16)

Decoderawtransaction:
Code:
bitcoin-cli decoderawtransaction 0200000001bc010c04e1c44a991760fa1cb7af1076bf755077d1cba60d3d4ca3f0de670d21000000006A4730440220113f4da0dab33c850b13c3f8e8239acdb9d474808d9c65e91a9304c4573ac3fc0220514df1aaf115535de6e3a7da19011b416b84bd2ec8737958d2d97c6eed6985f701210324d70d5a6a237f9214db706834bea61b554b715d3c500a97a7f62b13a01b3246ffffffff01c0aff629010000001976a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac00000000
    {
      "txid": "3f360942dca166a75397cbc3f481771bea8f1c2b0c79313b034fb067882b3b36",
      "hash": "3f360942dca166a75397cbc3f481771bea8f1c2b0c79313b034fb067882b3b36",
      "version": 2,
      "size": 191,
      "vsize": 191,
      "weight": 764,
      "locktime": 0,
      "vin": [
        {
          "txid": "210d67def0a34c3d0da6cbd1775075bf7610afb71cfa6017994ac4e1040c01bc",
          "vout": 0,
          "scriptSig": {
            "asm": "30440220113f4da0dab33c850b13c3f8e8239acdb9d474808d9c65e91a9304c4573ac3fc0220514df1aaf115535de6e3a7da19011b416b84bd2ec8737958d2d97c6eed6985f7[ALL] 0324d70d5a6a237f9214db706834bea61b554b715d3c500a97a7f62b13a01b3246",
            "hex": "4730440220113f4da0dab33c850b13c3f8e8239acdb9d474808d9c65e91a9304c4573ac3fc0220514df1aaf115535de6e3a7da19011b416b84bd2ec8737958d2d97c6eed6985f701210324d70d5a6a237f9214db706834bea61b554b715d3c500a97a7f62b13a01b3246"
          },
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 49.99000000,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 f6b61a355d427c892e51bdb261d4f56c4e93b16f OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac",
            "reqSigs": 1,
            "type": "pubkeyhash",
            "addresses": [
              "n41SfwRvQD7tXJsbZsEcDWKFQ7DLYi3P7i"
            ]
          }
        }
      ]
    }
14  Alternate cryptocurrencies / Tokens (Altcoins) / Re: [ANN]🌎Bitminer Factory : BLOCKCHAIN MADE SUSTAINABLE🌎 on: August 17, 2018, 11:56:35 AM
Bitminer Factory company offers to install the Dashboard app for your smartphone to mine with It

no, it's not true. Bitminer Factory Offers Mining Contract Where you can earn with mining
15  Local / Alt-Currencies (Italiano) / Airdrop condivisione REF on: February 21, 2018, 10:38:05 AM
Ciao a tutti,
esiste un canale per condividere il proprio ref ?
Io ho fatto un canale per farlo https://t.me/joinchat/CiQOCg6_FokssBcNlb_flg
non so se ne esiste già uno.
Amici di airdrop avevano vietato il ref
Grazie
Ciao
16  Alternate cryptocurrencies / Bounties (Altcoins) / Re: 💰💰[ANN][PreSale]G-global - official bounty 💰💰up to $1 000 000 to share💰💰 on: February 19, 2018, 11:50:46 AM
#Proof of authentication
Joined: Twitter Telegram
twitter Username: barno7

Retweet:
1) https://twitter.com/GGlobal_Project/status/963431316355207168
2) https://twitter.com/GGlobal_Project/status/964081203174404097
3) https://twitter.com/GGlobal_Project/status/964148753245655041
4) https://twitter.com/GGlobal_Project/status/964423405805031430

Bitcointalk Username: barno
Bitcointalk Profile Link: https://bitcointalk.org/index.php?action=profile;u=1584891
telegram username: barno7_Red_Army_member
17  Alternate cryptocurrencies / Bounties (Altcoins) / Re: ⭐️[Airdrop] SIGLO - Future of Mobile Connectivity.JOIN TELEGRAM,EARN REWARD⭐️ on: February 10, 2018, 09:14:13 PM
Bitcointalk Username:  barno
Bitcointalk Profile:       https://bitcointalk.org/index.php?action=profile;u=1584891
18  Alternate cryptocurrencies / Bounties (Altcoins) / Re: [Airdrop] LegacyLotto on: February 08, 2018, 03:06:56 PM
1) Twitter account link : https://twitter.com/barno7
2) Telegram account: barno7_Red_Army_member
3) Link to your post with : https://bitcointalk.org/index.php?topic=2851932.msg29866022#msg29866022
4) ETH wallet: 0x34D09cdd03727F744C2b7BF4066f1e752A8233e0


19  Alternate cryptocurrencies / Tokens (Altcoins) / Re: [ANN][ICO] LegacyLotto | World’s first ticket mining blockchain lottery. on: February 08, 2018, 02:52:42 PM
Very very nice project! the whitepaper (https://static1.squarespace.com/static/5a39e108aeb6254304496341/t/5a69dc9f41920243676c6409/1516887201401/WHITE+PAPER.pdf) is very nice and clear, even the video is so nice!
20  Alternate cryptocurrencies / Bounties (Altcoins) / Re: [Airdrop][BOUNTY] Kepler 🚀 4 KEP token worth 5-1000 $ [Limited to 5000 users]🔥 on: February 05, 2018, 10:20:05 PM
#joined airdrop  #Keplertek.org
Telegram username: @barno7_Red_Army_member
Bitcointalk username: barno
Bitcointalk profile link: https://bitcointalk.org/index.php?action=profile;u=1584891
eth address: 0x34D09cdd03727F744C2b7BF4066f1e752A8233e0
Pages: [1] 2 »
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!