Browse Source

Better variable names

master
Luke Childs 6 years ago
parent
commit
caaefa353c
  1. 12
      README.md
  2. 10
      src/index.js
  3. 6
      test/unit.js

12
README.md

@ -23,23 +23,23 @@ const createXpub = require('create-xpub');
const xpub = createXpub({
depth: 3,
childnum: 2147483648,
childNumber: 2147483648,
publicKey: '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97',
chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b'
});
// => 'xpub6CgMcBZk66ayM9ESh7QtBmRKJbsa6rBeBH2k4aQZQJGossryP5r2N2nQS4hBMG1wb8igPoH53bxtzTBaeMqJkbu8bxsih1gGkoAn23Nr8VP'
```
Pass in version bytes for a different network:
Pass in version bytes for a different networkVersion:
```js
const createXpub = require('create-xpub');
const TESTNET = 0x043587CF;
const xpub = createXpub({
network: TESTNET,
networkVersion: TESTNET,
depth: 3,
childnum: 2147483648,
childNumber: 2147483648,
publicKey: '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97',
chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b'
});
@ -64,7 +64,7 @@ An object containing the following properties of the derivation path.
Consult [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) for an in-depth explanation on these properties.
##### network
##### networkVersion
Type: `Number`<br>
Default: `0x0488B21E`
@ -80,7 +80,7 @@ Default: `undefined`
The depth of the derived key.
##### childnum
##### childNumber
Type: `Number`<br>
Default: `undefined`

10
src/index.js

@ -32,10 +32,10 @@ const getPublicKeyFingerprint = publicKey => {
);
};
const createXpub = ({network = XPUB, depth, childnum, chainCode, publicKey}) => {
ow(network, ow.number.label('network'));
const createXpub = ({networkVersion = XPUB, depth, childNumber, chainCode, publicKey}) => {
ow(networkVersion, ow.number.label('networkVersion'));
ow(depth, ow.number.label('depth'));
ow(childnum, ow.number.label('childnum'));
ow(childNumber, ow.number.label('childNumber'));
ow(chainCode, ow.string.label('chainCode'));
ow(publicKey, ow.string.label('publicKey'));
@ -43,10 +43,10 @@ const createXpub = ({network = XPUB, depth, childnum, chainCode, publicKey}) =>
const fingerprint = getPublicKeyFingerprint(publicKey);
const xpub = Buffer.from([
network.toString(16).padStart(8, '0'),
networkVersion.toString(16).padStart(8, '0'),
depth.toString(16).padStart(2, '0'),
fingerprint.toString(16).padStart(8, '0'),
childnum.toString(16).padStart(8, '0'),
childNumber.toString(16).padStart(8, '0'),
chainCode,
publicKey
].join(''), 'hex');

6
test/unit.js

@ -4,7 +4,7 @@ import createXpub from '..';
const TPUB = 0x043587CF;
const xpubTestParams = {
depth: 3,
childnum: 2147483648,
childNumber: 2147483648,
chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b',
publicKey: '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97'
};
@ -20,10 +20,10 @@ test('createXpub is serialised correctly', t => {
t.is(xpub, expectedXpub);
});
test('Different networks can be passed in', t => {
test('Different network version bytes can be passed in', t => {
const tpub = createXpub({
...xpubTestParams,
network: TPUB
networkVersion: TPUB
});
t.is(tpub, expectedTpub);
});

Loading…
Cancel
Save