bitcoinjs-lib almost built transaction but...
Turtus opened this issue · 18 comments
Issue Template
Context
Im trying to connect the same libraries we used for bitcoin-like networks to send verge transaction, and all seems to be good but....
Prerequisites
yep
User Story:
Ive created tx with bitcoinjs-lib
Transaction {
version: 1,
locktime: 0,
ins:
[ { hash:
<Buffer ae 3a 5e 3d 49 34 1d 20 bf 27 36 b7 fa 3a 4f c3 de 4c 91 e3 4c 69 44 e4 c5 68 39 db 8b a8 cd ab>,
index: 0,
script:
<Buffer 48 30 45 02 21 00 8a f4 19 68 2d df a0 d9 7a 6c 95 51 71 a4 9d d6 94 64 1c 09 f5 37 eb c2 1a 4c b0 50 99 35 3c 0d 02 20 18 55 5a c5 3a 96 7d 8b 60 5d ... >,
sequence: 4294967294,
witness: [] } ],
outs:
[ { script:
<Buffer 76 a9 14 2c c1 ab c8 0e 29 c9 5c 11 8a 59 7b a9 78 72 20 58 60 14 b1 88 ac>,
value: 950000 },
{ script:
<Buffer 76 a9 14 a3 d4 33 34 ff 9e a4 c2 57 a1 79 6b 63 e4 fa 83 30 74 7d 2e 88 ac>,
value: 93821000 } ] }
and added 8 bytes of transaction time after version bytes
01000000cee20dd501ae3a5e3d49341d20bf2736b7fa3a4fc3de4c91e34c6944e4c56839db8ba8cdab000000006b4830450221008af419682ddfa0d97a6c955171a49dd694641c09f537ebc21a4cb05099353c0d022018555ac53a967d8b605dff92f71065a109243d752c671a0d06a92c8d9b613173012103798895304e772774789de317c34bdaa881b626a536ab46f7502d043d4b630d97feffffff02f07e0e00000000001976a9142cc1abc80e29c95c118a597ba9787220586014b188ac48989705000000001976a914a3d43334ff9ea4c257a1796b63e4fa8330747d2e88ac00000000
Expected Behavior
raw transaction is valid and node put in into the mempool
Current Behavior
"mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 16)"
Yeah I think each time should have a length of 4 bytes
also the signing for the inputs must be done with times included
sign(getTxWithTime())
ouch, yep - 4 bytes )))
ive done like this - is there any way not to change bitcoinjs-lib? (will try tomorrow but maybe you have already played with it)
const bitcoin = require('bitcoinjs-lib')
const txb = new bitcoin.TransactionBuilder(verge_network)
....
txb.sign(i, keyPair)
looks like somewhere here https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/transaction_builder.js#L1055
playing with time position here /bitcoinjs-lib/src/transaction.js:283
buffer to sign for bitcoin
0100000001ae3a5e3d49341d20bf2736b7fa3a4fc3de4c91e34c6944e4c56839db8ba8cdab000000001976a914a3d43334ff9ea4c257a1796b63e4fa8330747d2e88acfeffffff02f07e0e00000000001976a9142cc1abc80e29c95c118a597ba9787220586014b188ac48989705000000001976a914a3d43334ff9ea4c257a1796b63e4fa8330747d2e88ac0000000001000000
buffer im adding time (tried all positions, here pushed to -8 => -4 bytes) but still the same error(
0100000001ae3a5e3d49341d20bf2736b7fa3a4fc3de4c91e34c6944e4c56839db8ba8cdab000000001976a914a3d43334ff9ea4c257a1796b63e4fa8330747d2e88acfeffffff02f07e0e00000000001976a9142cc1abc80e29c95c118a597ba9787220586014b188ac48989705000000001976a914a3d43334ff9ea4c257a1796b63e4fa8330747d2e88ac00000000 ca1dd15d 01000000
Do you have a runnable example? Like a real code snippet so that I can quickly test all.
heh, one moment)
here is position yep?)
https://github.com/vergecurrency/VERGE/blob/0d669aab902c12c97cd8beabe8151b3e26f3f3b8/src/script/interpreter.cpp#L1301
Well that’s for witness only, there must be tx->nTime, input->nTime references encoded
i`ll try to make separate repo with the hack over bitcoinjs-lib to support verge - and show you with code to run, thank you for support
Turtus/bitcoinjs-lib@4834c73 here you go - just need to change private / address / output to use - or direct message me in telegram etc - i will give you my test credits
I guess you won't be able to use this library, without modifying it first. @Turtus
I just had a quick look into everything and I could see it possibly working but only by modifying the lib itself.
thats already clear - Turtus/bitcoinjs-lib@fb934f5 - if you will help me with signing i think we will get correct verge-working code of this - and it will be gorgeous) thanks a lot in advance
https://github.com/Turtus/bitcoinjs-lib/pull/1 works for me.
ahaaaa! thank you - ive tried first just modify result of bitcoinjs lib - but your version is much much bettter!!! thank you very much- will add verge to trustee wallet for some small users it will be nice (not a lot of tor etc - just usual multicurrency wallet with exchanges)
Ah cool, thanks! Have great day :)
@marpme need your help again )
we are happily using verge in trustee for almost two years but sometimes got strange error
mandatory-script-verify-flag-failed (signature must be zero for failed check(multi)sig operation) (code 16)
for example on this transaction (system time is syncronized)
01000000a7a2e9600641c260da4c84baf48b119c415f64bd3d55c1ff52fc68e6b71ed7640716b6631b000000006b4830450221008f0887d9bd68dcae941d645d55e816ea9e49fb505fbf2463caf4bb9abd36331402203dcf546fd252d58aae976faac90e8c332583601e239f996f50b8bdc6593579f901210309c7bbb4b6e02ab2e53afbb095970c79f1d067f11ceb5535158a5c1b06347c6f80e3ffff576a5ae4e0248ad62ba591dfecb9a35c3e583e7411998b1467f8525cdac58ba5010000006b483045022100f23917ca5801b7a82f47c1f63ee82ee9ffe92e273bcc776b91da2974f37bf1570220340d2f9585396bc6e602d192cd5612e580fb02d9e4c2df55e007a7fc9b7c555401210309c7bbb4b6e02ab2e53afbb095970c79f1d067f11ceb5535158a5c1b06347c6f80e3ffff291eadab82ced544b058aab50305707e1b8a847d4c5cf0849a4e0a238042e37e010000006b483045022100a023f278b0f1ca4f38b4745f87e0b4ce3ad6593049806020513ffed8bea6515e022013ed0a44ccaa52a2b32467c9cb66dac5e1caadaaf793bebc426046f7e528bfad01210309c7bbb4b6e02ab2e53afbb095970c79f1d067f11ceb5535158a5c1b06347c6f80e3ffffe0b23f25e1e4298699a57b7b4f6ff3e0892b83432c16dd54f1f312505ce8f4a3030000006b48304502210098c106cf2cb554c42e0bc661a12081bd0930f77b75a42d9d58bc6009bcc21fc802203dea1abbb1f5922f5b769a6c875b4ae3c93eff749e85736cf40601b59bb57d4501210309c7bbb4b6e02ab2e53afbb095970c79f1d067f11ceb5535158a5c1b06347c6f80e3ffff711b9ae36c6a0593b7f886a02354b91d35c0085f0d6bc9a88d941b1ba1461d54000000006a473044022061a418981e2d9c18548be282b5e37a236623eee6ef70d5b274601f93049b3e4702204c0128b06bf5789c78afc5be43a54bfd77281ca6f22aac6f0824cd98e2c5184601210309c7bbb4b6e02ab2e53afbb095970c79f1d067f11ceb5535158a5c1b06347c6f80e3ffff0cf783a752a94d68f2a6393916a7608a61a3c68fbb0a09470528594fd330aafb010000006b483045022100d98fa035798878eb0221370220f846d43f8ecb72cd8354b975e56ce9a7a70e99022029961b1cce53c4889c14defc0581aecd992801e800adb639c3d77a0ee2e6d54301210309c7bbb4b6e02ab2e53afbb095970c79f1d067f11ceb5535158a5c1b06347c6f80e3ffff0176bb68db040000001976a914b1913b8c3c0a09313137c50952091b9fb888a4a788ac00000000
no solution?