Skip to content

Instantly share code, notes, and snippets.

@shesek
Last active July 2, 2017 16:53
Show Gist options
  • Save shesek/5847524 to your computer and use it in GitHub Desktop.
Save shesek/5847524 to your computer and use it in GitHub Desktop.
Package bitcoinjs-lib as a nodejs module (VERY hacky, but good enough for now)
#!/bin/bash
# Package bitcoinjs-lib as a nodejs module
# Install bitcoinjs first (`npm install bitcoinjs-lib`),
# than run this in your app's directory.
TARGET=lib/bitcoinjs-lib.js
# Wrap all of bitcoinjs-lib and its dependencies in an IIFE
# and export the Bitcoin, Crypto and BigInteger objects.
# (module is shadowed because bitcoinjs-lib partially
# attempts to identify and use it, which results in
# broken code)
echo 'module.exports = (function(window,module){' > $TARGET
( cd node_modules/bitcoinjs-lib/src/ && \
for file in jsbn/{jsbn,jsbn2,prng4,rng,ec,sec}.js \
crypto-js/{crypto,sha256,ripemd160}.js \
events/eventemitter.js \
{bitcoin,util,base58,address,ecdsa,eckey,opcode,script,transaction,message}.js \
; do
cat $file
echo ';'
done \
) >> $TARGET
echo 'BigInteger.sec={getSECCurveByName: getSECCurveByName};' >> $TARGET
echo 'return { Bitcoin: Bitcoin, Crypto: Crypto, BigInteger: BigInteger } ; })(' >> $TARGET
echo 'typeof window!=="undefined"?window:global)' >> $TARGET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment