You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Luke Childs fc1a2e5238 1.0.2 6 years ago
src Add Type checking 6 years ago
test Make tests more readable 6 years ago
.gitignore Initial commit 6 years ago
.travis.yml Initial commit 6 years ago
LICENSE Initial commit 6 years ago
README.md Add ledgerjs tip 6 years ago
package.json 1.0.2 6 years ago

README.md

create-xpub

Create a BIP32 extended public key

Build Status Coverage Status npm

Creates a Base58 encoded extended public key (xpub) for use in a BIP32 hierarchical deterministic wallet.

Install

npm install create-xpub

Usage

You should familiarise yourself with BIP32 to understand what these arguments represent.

const createXpub = require('create-xpub');

const xpub = createXpub({
  depth: 3,
  childnum: 2147483648,
  publicKey: '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97',
  chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b'
});
// => 'xpub6CgMcBZk66ayM9ESh7QtBmRKJbsa6rBeBH2k4aQZQJGossryP5r2N2nQS4hBMG1wb8igPoH53bxtzTBaeMqJkbu8bxsih1gGkoAn23Nr8VP'

Pass in version bytes for a different network:

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

const xpub = createXpub({
  network: TESTNET,
  depth: 3,
  childnum: 2147483648,
  publicKey: '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97',
  chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b'
});
// => tpubDD3z8RPRoNYRcwRJ9JPyPgkgdiyE6Eghiud3R8ThkD2hdAXgTJh7WUTEg6mxskyBP3Fb1NnwahnwgdgC3DgYe3MRfZd2NYLWLkmBn7UWZXk'

Tip

If you're working with ledgerjs you can pass the output of getwalletpublickey() almost directly in.

API

createXpub(options)

Returns a Base58 encoded extended public key.

options

Type: Object

An object containing the following properties of the derivation path.

Consult BIP32 for an in-depth explanation on these properties.

network

Type: Number
Default: 0x0488B21E

Network version bytes.

Default is 0x0488B21E for mainnet.

depth

Type: Number
Default: undefined

The depth of the derived key.

childnum

Type: Number
Default: undefined

The child number

chainCode

Type: String
Default: undefined

The chain code

publicKey

Type: String
Default: undefined

The public key in compressed or uncompressed form.

License

MIT © Luke Childs