0.4.2 • Published 10 years ago
bip32-path v0.4.2
BIP32 Path
Bitcoin BIP32 ("HD Wallet") path helpers.
There are multiple path representations being used by different implementations. These includes:
m/44'/0'/0'/0/0where the apostrophe means hardened keym/44h/0h/0h/0/0where the letterhmeans hardened key- and a binary representation predominantly used by Trezor & compatible wallets and some software tools, such as bitcoinjs-lib
Some useful links:
- BIP32 specification
- BIP44 specification
- BIP39, an online tool to convert/derive keys
- BIP32JP, an online tool to convert/derive keys
API
BIPPath.fromString(path, reqRoot)- creates an instance from a path written as text. SetreqRootto true if them/prefix is mandatory.BIPPath.fromPathArray(path)- creates an instance from a binary path arraynew BIPPath(path)- alias forBIPPath.fromPathArray(path)<bippath>.toString(noRoot, oldStyle)- returns a text encoded path. Set tonoRootto true to omit them/prefix. SetoldStyletrue to usehinstead of'for marking hardened nodes.<bippath>.toPathArray()- returns a binary path arrayBIPPath.validateString(path, reqRoot)- returns true if the input is a valid path stringBIPPath.validatePathArray(path)- returns true if the input is a valid binary path array
Binary path arrays contain each node as a separate number, where hardened nodes are marked by setting the 32th bit: m/44'/1/1/0 corresponds to [ 0x8000002c, 1, 1, 0 ]
Examples
var bippath = require('bip32-path')
bippath.fromPathArray([0x8000002c, 1, 1, 0]).toString() // m/44'/1/1/0
bippath.fromString("m/44'/0'/0'").toString(false, true) // m/44h/0h/0h
bippath.fromString("m/44h/0h/0'").toString(true) // 44'/0'/0'
bippath.fromString("m/44'/0'/0'").toPathArray() // [ 0x8000002c, 0x80000000, 0x80000000 ]0.4.2
10 years ago