Bitcoin Forum
May 13, 2024, 03:57:34 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Signing non-standard transaction  (Read 1074 times)
jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1097


View Profile
July 11, 2013, 03:14:03 PM
 #1

I am trying to create a transaction to implement my proposed color coin protocol. Test-net transaction id is a0eecca313623fb39ddf92ed36782ec58003fec049d8395166b459bfbbfa3e7a . The output script is

Code:
bc0167de574bfa6c2e04af2b80bf2717399ec614 OP_NOP3 OP_DROP OP_DUP OP_HASH160 ef8a580d4a2f946cf9bb4c18cee113061ffe1912 OP_EQUALVERIFY OP_CHECKSIG

Where

Code:
bc0167de574bfa6c2e04af2b80bf2717399ec614 = RIPEMD160(SHA256(76a914a42f15b5fd15552aa14973bfc59039fbc095580488ac))

and 76a914a42f15b5fd15552aa14973bfc59039fbc095580488ac is the script of the previous output

The new script is, of course, non-standard but it should act exactly like a normal pay-to-pubkey-hash transaction.

Then, I use this command to create a raw transaction to spend to colored coin:

Code:
bitcoind --testnet createrawtransaction '[{"txid":"a0eecca313623fb39ddf92ed36782ec58003fec049d8395166b459bfbbfa3e7a","vout":0}]' '{"n1mkYwsdnQap2fcHrzoiZQgxceKFkVrrER":1.78}'

and bitcoind returns:

Code:
01000000017a3efabbbf59b4665139d849c0fe0380c52e7836ed92df9db33f6213a3cceea00000000000ffffffff0180109c0a000000001976a914de2ef3cd43d270c9aba0c165fc9dc0a8ed0148cc88ac00000000

I try to use signrawtransaction to sign it, and unsurprisingly, bitcoind fails to sign. Is there any easy way to sign the transaction? (The public key is 03D8D93A4F4BF9628742D2C580E83508941474A924A24F5A4339AE0AD200F2B3FD)

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
Even if you use Bitcoin through Tor, the way transactions are handled by the network makes anonymity difficult to achieve. Do not expect your transactions to be anonymous unless you really know what you're doing.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715572654
Hero Member
*
Offline Offline

Posts: 1715572654

View Profile Personal Message (Offline)

Ignore
1715572654
Reply with quote  #2

1715572654
Report to moderator
1715572654
Hero Member
*
Offline Offline

Posts: 1715572654

View Profile Personal Message (Offline)

Ignore
1715572654
Reply with quote  #2

1715572654
Report to moderator
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1233


May Bitcoin be touched by his Noodly Appendage


View Profile
July 11, 2013, 03:42:24 PM
 #2

I suggest you to sign it by hand:
Format it correctly (corresponding to the sighash), copy the bytes in your clipboard (using a hex editor), sign it with bitcoin-qt, un-base64 the signature, drop the first byte and divide the remaining 64bytes long string into two 32bytes long ones (r and s) (See edit 1)
Format r and s correctly (DER format), then create the scriptpubkey (see the sighash article on the wiki)

PS1: you can use a tool to sign the transaction more easily, search for jasvet in the dev&tech forum

PS2: I can do it for you if you're not interested in the process but rather in the result

Edit 1: I forgot about the "Bitcoin signing message" prefix... You actually need a tool to sign your bytes

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
Mike Hearn
Legendary
*
expert
Offline Offline

Activity: 1526
Merit: 1129


View Profile
July 11, 2013, 03:49:08 PM
 #3

Your best bet for this type of work is to use bitcoinj or perhaps Jeff's new txtool program.
blueadept
Full Member
***
Offline Offline

Activity: 225
Merit: 101


View Profile
July 11, 2013, 04:02:25 PM
Last edit: July 11, 2013, 04:17:19 PM by blueadept
 #4

Your best bet for this type of work is to use bitcoinj or perhaps Jeff's new txtool program.

+1 for BitcoinJ, use the ScriptBuilder class to write your custom ScriptSig and the Transaction class (calculateSignature method) to sign with the appropriate key.  I haven't looked too closely at Jeff's tool, but I'm not sure it'd work.

Code:
Transaction tx = new Transaction();
tx.addInput(prevtxout);
tx.addOutput(...);
tx.getInput(0).setScriptSig(
    new ScriptBuilder()
        .data(tx.calculateSignature(0, // input number
            key, // ECKey instantiated with the private key you provided
            tx.getInput(0).getConnectedOutput().getScriptPubKey(), // ScriptPubKey from the output - you can also just use prevtxout.getScriptPubKey()
            SigHash.ALL, // the SIGHASH_ALL sighash flags
            false // SIGHASH_ANYONECANPAY is false
        ).encodeToBitcoin()) // Encode the signature to Bitcoin format and return as byte array, which is what data() expects
        .data(key.getPubKey()) // Add key to top of stack since this is an address/pubkeyhash transaction and not just a pubkey transaction
        .build()  // Build the ScriptSig
);

Fairly simple, though there's setup to do to get all of that stuff into the right variables to start with

Like my posts?  Connect with me on LinkedIn and endorse my "Bitcoin" skill.
Decentralized, instant off-chain payments.
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!