bitcore icon indicating copy to clipboard operation
bitcore copied to clipboard

Modularize bitcore

Open ryanxcharles opened this issue 12 years ago • 19 comments

Bitcore is monolithic and inappropriately large for many applications. Although it is possible to use bitcore in small pieces (by compiling only desired components for the browser, or lazy loading modules in node), it would be more compatible with the npm ecosystem to use distinct modules for each component.

These modules might be:

  • bitcore-buffer (buffer library equal to Buffer in node but with pure js versions for the browser)
  • bitcore-bignum (bignum library with pure js and openssl versions)
  • bitcore-point (elliptic curve crypto with pure js and openssl versions)
  • bitcore-curve (secp256k1 curve params)
  • bitcore-hash (hash functions with pure js and openssl versions)
  • bitcore-key (private/public keys, signing, encryption)
  • bitcore-address (addresses, private key import format, base58)
  • bitcore-tx (Transaction + TransactionBuilder)
  • bitcore-wallet (collections of private keys - maybe include copay multisig wallet logic?)
  • bitcore-sin (SINs)
  • bitcore-peer (network connections - node-only)
  • bitcore-script (and script interpreter)
  • bitcore-bip32
  • bitcore-electrum
  • bitcore-armory

...and then of course "bitcore" would include all of these in one monolithlic library (where you would still have the ability using browserify to compile only the pieces you want).

Besides making it easier to use the individual components of bitcore, this would also make it easier to make updates to individual bitcore components without having to release a whole new bitcore. It was mentioned by @martindale ( https://github.com/bitpay/bitcore/issues/255 ) that express recently did this ( https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x ).

ryanxcharles avatar May 06 '14 14:05 ryanxcharles

Agreed. Maybe this can be version 1.0.0

maraoz avatar May 06 '14 15:05 maraoz

:+1:, exactly what I had in mind. Agree with maraoz that this should be implemented in a more stable version or by slowly extracting the more stable modules.

olalonde avatar May 06 '14 23:05 olalonde

Some more submodule ideas discussed:

  • bitcore-paypro
  • bitcore-hdkeys
  • bitcore-extras
  • bitcore-stealth
  • bitcore-channel
  • bitcore-wire
  • bitcore-blockchain
  • bitcore-node
  • bitcore-rpc

maraoz avatar Dec 17 '14 15:12 maraoz

This one sentence in the express doc is key: "This change was made to allow for these middleware to receive fixes, updates, and releases without impacting express release cycles and vice versa." (via @ryanxcharles)

maraoz avatar Dec 19 '14 16:12 maraoz

My tentative list of submodules, please discuss:

  • bitcore-identity (SINs)
  • bitcore-peer (p2p network connections)
  • bitcore-rpc (rpc interface)
  • bitcore-message (bitcoin message signing and verification)
  • bitcore-uri (bip21)
  • bitcore-hdkeys (bip32)
  • bitcore-paypro (bip70-73)
  • bitcore-egg (bip42)
  • bitcore-hdpurpose (bip43)
  • bitcore-hdpm (bip45)
  • bitcore-bloom (bloom filters, bip37)
  • bitcore-stealth (stealth payments)
  • bitcore-channel (payment channels)
  • bitcore-blockchain (interface to blockchain explorers like insight)
  • bitcore-node (full bitcoin node implementation)

DONE:

  • bitcore-poetry (bip39, https://www.npmjs.com/package/bitcore-poetry)
  • bitcore-ecies (ecies, https://www.npmjs.com/package/bitcore-ecies)
  • bitcore-electrum (electrum seeds, https://www.npmjs.com/package/bitcore-electrum)
  • bitcore-armory (armory-style key derivation, https://www.npmjs.com/package/bitcore-armory)

maraoz avatar Jan 05 '15 20:01 maraoz

LGTM

eordano avatar Jan 05 '15 20:01 eordano

bitcore-hdkeys seems like it should be a part of core

braydonf avatar Jan 05 '15 20:01 braydonf

bitcore-rpc as discussed before, actually doesn't, or wouldn't require('bitcore') though it could if it returned bitcore objects. otherwise it should be bitcoind-rpc.js

braydonf avatar Jan 05 '15 20:01 braydonf

As a note here also: using require('bitcore/lib/paymentprotocol') currently provides the benefits of being a separate module, while also being in the same repository. As described: https://github.com/bitpay/bitcore/blob/master/docs/guide/browser.md

However moving payment protocol to a module would be beneficial since it would decrease the size of the default browser package, especially for use-cases where it is not needed.

braydonf avatar Jan 05 '15 20:01 braydonf

Also I believe bitauth provides what is needed for bitcore-identity already, as discussed on: https://github.com/bitpay/bitcore/issues/825

braydonf avatar Jan 05 '15 20:01 braydonf

If we're having hdkeys in this repo, I feel that bitcore-uri should also stay

eordano avatar Jan 05 '15 20:01 eordano

Hmm. Yes, I didn't realize bitcore-uri was separated also. That seems like it would stay also, though I do think some optimizations could be made so it's not loading all of the url module to decrease the size of the core browser bundle.

braydonf avatar Jan 05 '15 20:01 braydonf

I feel like we could always do require('bitcore/lib/uri') if we only want the URI module. What's the advantage of it being a separate repository and module?

braydonf avatar Jan 05 '15 20:01 braydonf

I agree with @eordano @braydonf on bitcore-uri and bitcore-hdkeys being included on this repo. Both seems kind of core of most bitcoin apps, in any case we should be coherent and include/extract both of them.

I don't see the need for bitcore-hdpm (bip45). I believe bitcore-identity and bitcore-bitauth are different things. @martindale has made some remarks about this.

I'm thinking that maybe the README.md of each submodule should have the documentation of the module. Or should we have a base template for README and link to /docs/XXX with the files to build bitcore.io/guide?

yemel avatar Jan 05 '15 21:01 yemel

@braydonf @eordano I think bitcore-uri and bitcore-hdkeys should go in separate repos. Rationale:

  • Both are BIPs. I like the idea of having only the core in bitcore, and moving BIPs to submodules
  • They are independent files, no other classes use them (try git grep HDPrivateKey and such)
  • We wouldn't add any big complexity in separating it (require('bitcore').URI vs require('bitcore-uri')), and we'll gain the well-known benefits of modularization.

@yemel: on BIP45, I was thinking moving https://github.com/bitpay/copay/blob/master/js/models/HDPath.js to a bitcore submodule. It'd help other developers adopt the BIP.

maraoz avatar Jan 06 '15 13:01 maraoz

Rationale for BIPS as submodules may not work, for example BIP21, BIP72 and BIP73 all belong together as they are dealing with URI, and think it should be organized by features instead.

braydonf avatar Jan 06 '15 18:01 braydonf

The biggest rationale I can see for modularization is that I think that this is more established pattern:

var PaymentProtocol = require('bitcore-paymentprotocol')`

Than doing the following:

var PaymentProtocol = require('bitcore/lib/paymentprotocol');

However I think that the monolithic approach has some advantages as testing all of the code, and interoperability is more efficient. Perhaps we could have a repository that would run tests for all Bitcore modules, we probably should anyways.

braydonf avatar Jan 06 '15 19:01 braydonf

I see... I hadn't thought of automatic testing of all submodules. That may be a big problem...

maraoz avatar Jan 08 '15 20:01 maraoz

As for documentation we should be able to group the modules together and copy the docs and generate the api reference for each. Here is how they can be organized together: https://gist.github.com/braydonf/85ee1339b4b047b84613

braydonf avatar Jan 10 '15 04:01 braydonf