bitcoinjs/bitcoinjs-lib — pull request #134 by dcousens (2014-04-16 20:58:18+00:00)
Title: HDWallet now uses Buffers internally

This pull request updates `HDWallet` to use Node Buffers internally.
It is dependent on #133.

In short, bc05828 adds Buffer input parameter support for `ECKey` and `ECPubKey`, necessary to avoid jumping through compatibility hoops in `HDWallet` itself.

814aa9e does most of the heavy lifting, with some small changes to the tests in `test/hdwallet.js`.
Some key points for discussion are the changes in how `hd.parentFingerprint` is stored internally. I opted for the `Number` representation because as per [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#key) the fingerprint is guaranteed to be 32 bits; which fits well within `Number`s integer precision.
This made some of the Buffer code nicer to deal with, but is not absolutely necessary.

Something of interest was that despite the previous documentation, all data used in the serialization format was in MSB byte order (that is, Big Endian) as per the test vectors in `test/hdwallet.js`.
It is not clear if this is intentional, and the [serialization specification](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format) does not mention it at all.
If the test vectors were adapted from this implementation, this should be fixed as soon as possible, because it may derive completely different/wrong private keys.

Lastly, ddea4b176b15 takes some of the implicit `mod` math currently hidden in the `ECKey` constructor and puts it in the open as per the comments and [specification](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#private-parent-key--private-child-key).
This adheres to changes that will be made to the `ECKey` constructors soon, and removes unnecessary calculations and error checking that are not pertinent to what is needed here.