trezor / trezor-utxo-lib

UTXO coins functions implemented in pure JavaScript
MIT License
8 stars 11 forks source link

multi: Add decred. #9

Open JoeGruffins opened 4 years ago

JoeGruffins commented 4 years ago

Add decred coin parameters for testnet, simnet, and mainnet.

Add support for decred's unique hashing algorithm. The npm module hash-lib is used for blake256 as it is already used in the decred repositories.

Add a new module bs58check that pulls in functions from bs58check and adds new functions for decred encoding and decodings. Appropriate tests are added to test all success and error paths.

related to #8

I'm not sure changing a couple of function signatures in address.js is going to fly. I'm open to any suggestions, and thank you for your time.

szymonlesisz commented 4 years ago

Hi, i'm terrible sorry for this delayed response. We were releasing other project and i didn't have a time to have a look at it properly.

Adresses works! great job!

now there is a second problematic part, Transaction

in connect we use .fromHex and .toHex to validate signed transactions, parse referenced transactions etc. so this part should be also fixed.

currently Transaction.fromHex(decred-tx-hex, networks.decred) throws error ERR_OUT_OF_RANGE so i guess tx-hex contains some additional unexpected data which needs to be read from buffer, like in zcash or dash case

i swear my response will be quicker this time :)

JoeGruffins commented 4 years ago

Oh! I'm also sorry, I was not watching this. I think I fixed that, but it was a few weeks ago, I'll look over my code one more time, do you want me to add it to this pr or a new one? What I did so far, apparently: https://github.com/JoeGruffins/trezor-utxo-lib/commit/1aba263356527aa70f3d22920d8e12eca0f7c4a8

Pinging for good measure @szymonlesisz

szymonlesisz commented 4 years ago

i think you should put it here, to have a complete Decred support in one place

JoeGruffins commented 4 years ago

I think this adds everything necessary to work with decred transactions. It seems that there are quite a few differences from bitcoin. Some places are so different that I felt new functions were warranted. The most notable being addDecredInput addDecredWitness and signDecred. I'm don't know if this will cause problems down the stack. They are also missing a few checks that are in their bitcoin counterparts. I can add them in if necessary. Would like your @szymonlesisz opinion on these changes before going any farther though.

JoeGruffins commented 4 years ago

I'm testing a bit so there may be some changes and additions incoming. I will however refrain from rebasing for the time being.

JoeGruffins commented 4 years ago

I would prefer to leave simnet params in this library if that's ok, since this library is useful outside of trezor...

JoeGruffins commented 4 years ago

I think I will take some unneeded changes out of this pr and put them in a separate one to make review easier. We don't need all of this to achieve our primary goal of migrating from trezor.js to connect.

JoeGruffins commented 4 years ago

Ok, I don't foresee this pr changing anymore barring a review. Thank you for being patient.