Browse Source

Add mainnet/testnet version byte helpers

master
Luke Childs 6 years ago
parent
commit
4b7022c233
  1. 11
      README.md
  2. 4
      src/index.js
  3. 3
      test/unit.js

11
README.md

@ -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',
@ -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
src/index.js

@ -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')) {
@ -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
test/unit.js

@ -1,7 +1,6 @@
import test from 'ava';
import createXpub from '..';
const TPUB = 0x043587CF;
const xpubTestParams = {
depth: 3,
childNumber: 2147483648,
@ -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);
});

Loading…
Cancel
Save