Skip to content

Commit

Permalink
Add mainnet/testnet version byte helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Jan 6, 2019
1 parent 9a69098 commit bd077df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -34,10 +34,9 @@ Pass in version bytes for a different network:

```js
const createXpub = require('create-xpub');
const TESTNET = 0x043587CF;

const tpub = createXpub({
networkVersion: TESTNET,
networkVersion: createXpub.testnet
depth: 3,
childNumber: 2147483648,
chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b',
Expand Down Expand Up @@ -99,6 +98,14 @@ Default: `undefined`

The public key in compressed or uncompressed form.

### createXpub.mainnet

Mainnet (xpub) version bytes: `0x0488B21E`

### createXpub.testnet

Testnet (tpub) version bytes: `0x043587CF`

## License

MIT © Luke Childs
4 changes: 4 additions & 0 deletions src/index.js
Expand Up @@ -3,6 +3,7 @@ const bs58check = require('bs58check');
const {sha256, ripemd160} = require('hash.js');

const XPUB = 0x0488B21E;
const TPUB = 0x043587CF;

const compressPublicKey = publicKey => {
if (publicKey.startsWith('02') || publicKey.startsWith('03')) {
Expand Down Expand Up @@ -55,4 +56,7 @@ const createXpub = ({networkVersion = XPUB, depth, childNumber, chainCode, publi
return bs58check.encode(xpub);
};

createXpub.mainnet = XPUB;
createXpub.testnet = TPUB;

module.exports = createXpub;
3 changes: 1 addition & 2 deletions test/unit.js
@@ -1,7 +1,6 @@
import test from 'ava';
import createXpub from '..';

const TPUB = 0x043587CF;
const xpubTestParams = {
depth: 3,
childNumber: 2147483648,
Expand All @@ -23,7 +22,7 @@ test('createXpub is serialised correctly', t => {
test('Different network version bytes can be passed in', t => {
const tpub = createXpub({
...xpubTestParams,
networkVersion: TPUB
networkVersion: createXpub.testnet
});
t.is(tpub, expectedTpub);
});
Expand Down

0 comments on commit bd077df

Please sign in to comment.