trezor / trezor-crypto

:lock: Don't use this repo, use the new monorepo instead:
https://github.com/trezor/trezor-firmware
MIT License
501 stars 201 forks source link

Does someone test the hdnode_sign_digest() or ecdsa_sign_digest() function? #202

Closed FutureOfAI closed 5 years ago

FutureOfAI commented 5 years ago

I want to know how to check the signature results?

I gets digest form double sha256 with unsigned raw transaction: Raw transaction: 0100000001378f5c393a37fddeed1dda87ba68d3454e0fa07ca5851243ed708aeb97d240ab010000001976a9142acf413628545d90a926879112579ca1d19f34c688acffffffff0240420f00000000001976a9140a404ac33a7a75a39230cfb07f370650ce35f7c488ac37236500000000001976a914e62c3bdb842e0e9052bee9c22b3d7a8525bb95b688ac00000000

Digest: 83bfba9121294d30dd9c0a698f1f1ec0f30071cccaf11eee6df0b4cdf926040c

after import privatekey and convert signature to der by ecdsa_sig_to_der() function, I got this: 304502205ecbe4d1a6330a44c8f7ef951d4bf165e6c6b721efada985fb41661bc6e7fd6c022100ade701d4d500304932687867112a946c3a7cbced9d8b1f60751e56173b1c125801

and add this DER message to transaction, I get the signed transaction: 0100000001378f5c393a37fddeed1dda87ba68d3454e0fa07ca5851243ed708aeb97d240ab010000006b48304502205ecbe4d1a6330a44c8f7ef951d4bf165e6c6b721efada985fb41661bc6e7fd6c022100ade701d4d500304932687867112a946c3a7cbced9d8b1f60751e56173b1c1258012102534fd869124dff1cc99c430b97a5b6817b1f8343ce1e1de3ff71d4a3fc6c1592ffffffff0240420f00000000001976a9140a404ac33a7a75a39230cfb07f370650ce35f7c488ac37236500000000001976a914e62c3bdb842e0e9052bee9c22b3d7a8525bb95b688ac00000000

Broadcast this signed transaction to bitcoin test-net in this website: https://coinb.in/#broadcast and it shows Missing inputs error.

what's wrong with this?

f4GGT commented 5 years ago

@FutureOfAI I assume last 4 bytes are locktime, where is the sighash ?

prusnak commented 5 years ago

This is not related to trezor-crypto, but a general question. Please don't use this issue tracker for these.

You need to add sighash (0x00000001) at the end of the hashed data.