{"id":19303822,"url":"https://github.com/web3w/hd-address","last_synced_at":"2025-04-22T11:32:11.302Z","repository":{"id":50225489,"uuid":"281634858","full_name":"web3w/hd-address","owner":"web3w","description":"An extensible HD Wallet Address management utility","archived":false,"fork":false,"pushed_at":"2023-10-17T17:06:18.000Z","size":84,"stargazers_count":24,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T17:43:21.824Z","etag":null,"topics":["blockchain","btc","chain","coin","ethereum","hd-address","hd-wallet","mnemonic","trx","wallet"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/web3w.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-22T09:32:52.000Z","updated_at":"2024-11-02T18:19:33.000Z","dependencies_parsed_at":"2024-06-19T04:01:47.586Z","dependency_job_id":null,"html_url":"https://github.com/web3w/hd-address","commit_stats":null,"previous_names":["gisvr/hd-address"],"tags_count":6,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fhd-address","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fhd-address/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fhd-address/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fhd-address/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/web3w","download_url":"https://codeload.github.com/web3w/hd-address/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250232215,"owners_count":21396595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","btc","chain","coin","ethereum","hd-address","hd-wallet","mnemonic","trx","wallet"],"created_at":"2024-11-09T23:27:40.824Z","updated_at":"2025-04-22T11:32:09.404Z","avatar_url":"https://github.com/web3w.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hd-address\n[![NPM version](https://img.shields.io/npm/v/hd-address?style=flat-square)](https://www.npmjs.com/package/hd-address)\n\n\u003e An extensible HD Wallet Address management utility\n\u003e\n [中文说明](https://github.com/gisvr/hd-address/blob/master/README_CN.md)\n \n Please contact us if you have any special needs txdev6@gmail.com \n\n### Install\n```\n$ npm i hd-address\n$ yarn add hd-address\n```\n### Reference \n* [HD Wallet (bip32)](https://github.com/bitcoin/bips/blob/master/bip-0032/derivation.png)\n* [Mnemonic wordlists reference (bip39)](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) \n* [HD Wallet coin type list (bip44)]( https://github.com/satoshilabs/slips/blob/master/slip-0044.md)  \n\u003e m / purpose' / coin_type' / account' / change / address_index\n```js\n                                                        / address 0\n                coinType 0(btc) -- account 0 -- change 0  \n              /                                         \\ address 1\nroot -- BIP44 \n              \\\n                coinType 60(eth) -- account 0 -- change 1 -- address 0\n                          \n```\n## API\n#### 1.HD Wallet private key API \n```javascript\nconst hdAddress = require(\"hd-address\")  \n// Generate mnemocie seed base58\nconst mnemocie = hdAddress.mnemocie.getRandomMnemocie()\nconst seed = hdAddress.seed.getRandomSeed()\nconst base58 = hdAddress.base58.getRandomBase58()\n\n// Create Hd wallet\nconst hdWallet =new hdAddress.mnemocie(mnemocie)\nconst hdWallet =new hdAddress.seed(seed)\nconst hdWallet =new hdAddress.base58(base58)\n\n// Generate keypair\nhdWallet.getHdPath(coinTypeCode, index, account = 0, change = 0) \nhdWallet.getKeyPair(coinTypeCode, index, account, change) \nhdWallet.getCoinKeyPair(coin, index, account, change) \n\n// ChainCode\nhdWallet.getChainCodeByPath(path)\nhdWallet.getPublicKeyByChainCode(parentPub, chainCode, path)\nhdWallet.getPrivateKeyByChainCode(parentPri, chainCode, path)\n\n```\n\n#### 2.Get coin address  API\n```javascript\nconst hdAddress = require(\"hd-address\")  \n// Create a wallet with Coin Info\nlet hd = hdAddress.HD(mnemonic,hdAddress.keyType.mnemonic,pwd)\nlet hd = hdAddress.HD(seed,hdAddress.keyType.seed) \nlet hd = hdAddress.HD(base58,hdAddress.keyType.base58) \n\n// Get coin info\nhd.BTC.getCoinKeyPair(index, account, change)\nhd.ETH.getCoinAddressKeyPair(index, account, change)\nhd.TRX.getAddress(index, account, change)\nhd.LTC.getAddressByPath(hdPath) \nhd.BCH.getAddressByPrivateKey(privateKey)\nhd.BTC_TEST.getAddressByPublicKey(publicKey)\n``` \n\n## Example\n### Initialization\n1.[Mnemonic Initialization](https://github.com/gisvr/hd-address-example/blob/master/init/mnemonic.pwd.js) \n```javascript\n    const mnemonic = hdAddress.mnemocie.getRandomMnemonic()    \n    let hd = hdAddress.HD(mnemonic,hdAddress.keyType.mnemonic)  \n```\n\n2.[Seed Initialization](https://github.com/gisvr/hd-address-example/blob/master/init/seed.js) \n```javascript\n    const {seed} =hdAddress.mnemocie.getRandomSeed() \n    let hd = hdAddress.HD(seed,hdAddress.keyType.seed)  \n```\n\n3.[Base58 Initialization](https://github.com/gisvr/hd-address-example/blob/master/init/seed.js) \n\n```javascript\n    const {base58} =hdAddress.mnemocie.getRandomBase58() \n    let hd = hdAddress.HD(base58,hdAddress.keyType.base58) //v3.1\n```\n\n### Get coin address info\n\n1.[Get BTC ETH TRX address example](https://github.com/gisvr/hd-address-example/blob/master/init/mnemonic.js) \n```javascript\n    let hdIndex=6677\n    let btcAddr =  hd.BTC.getAddress(hdIndex)\n    console.log(\"BTC\",btcAddr.address)\n    let ethAddr =  hd.ETH.getAddress(hdIndex)\n    console.log(\"ETH\",ethAddr.address)\n    let trxAddr =  hd.TRX.getAddress(hdIndex)\n    console.log(\"TRX\",trxAddr.address)\n```\n\n2.Get address by path\n```javascript\n    let hdpath = \"m/0'/1/1\" // account/change/index\n    let {address, pub, pri, path} = hd.BTC.getAddressByPath(hdpath)\n    console.log(address, pub, pri, path) \n```\n\n3.[Get keypair](https://github.com/gisvr/hd-address-example/blob/master/address/address.keypair.js)\n```js\n  let {address, path, pri, pub} =  hd.BTC.getCoinAddressKeyPair(hdIndex)\n  console.log(address, path)\n```\n4.Get address using private key or public key\n```js\n  let priAddr =  hd.BTC.getAddressByPrivateKey(pri)\n  console.assert(priAddr.address == address)\n\n  let pubAddr =  hd.BTC.getAddressByPublicKey(pub)\n  console.assert(pubAddr.address == address)\n```\n\n### Generate safe secret key\n\n1.[Get Random Mnemonic](https://github.com/gisvr/hd-address-example/blob/master/mnemonic_safe/mnemonic.js) \n```javascript\n    let wordList = hdAddress.mnemonic.wordLists.CN\n    let strength = hdAddress.mnemonic.strength.high \n    let cnMnemo = hdAddress.mnemonic.getRandomMnemonic(strength, wordList)\n    let isMnemo = hdAddress.mnemonic.validateMnemonic(cnMnemo) \n    console.log(isMnemo)\n```\n\n2.Get Random base58\n```javascript\n    let strength = hdAddress.base58.strength.high \n    let base58 = hdAddress.mnemonic.getRandombase58(strength)\n```\n \n### **EOS extension:** [example](https://github.com/gisvr/hd-address-example/blob/master/extension/eos.address.js)\nYou can extend hd-address by implementing AddressClass\n```javascript\n\nconst AddressClass =  require(\"hd-address\").AddressClass //v3.0\n\nmodule.exports = class EosAddress extends AddressClass {\n    constructor(hd) {\n        let coin = \"EOS\"\n        super(hd, coin);\n    }\n\n    getAddress(index) {\n        console.log(this.coin, \"implement  getAddress method\")\n    }\n\n    getAddressByPrivateKey(privateKey) {\n        console.log(this.coin, \"implement  getAddressByPrivateKey method\")\n    }\n\n    getAddressByPublicKey(privateKey) {\n        console.log(this.coin, \"implement  getAddressByPublicKey method\")\n    }\n}\n```\n### **Get address using chain code:** [example](https://github.com/gisvr/hd-address-example/blob/master/chaincode/chaincode.js)\nChain Code can do hierarchical authorization management\n```js\n    let hdPath = \"m/44'/0'/1'\"\n    let {pub, chainCode} = hd.wallet.getChainCodeByPath(hdPath)\n    console.log(hdPath, \"chainCode\", chainCode.toString(\"hex\"),\"\\n\")\n\n    // pubKey + chainCode +childPath =\u003e  address\n    let childPath = \"m/1/\" + hdIndex\n    let child = hd.wallet.getPublicKeyByChainCode(pub, chainCode, childPath)\n    let childAaddr = hd.BTC.getAddressByPublicKey(child.pub)\n    console.log(childPath, child.pub.toString(\"hex\"),\"BTC Address\",childAaddr.address)\n\n    //path =\u003e  address\n    let testPath = \"m/44'/0'/1'/1/\" + hdIndex\n    let test = hd.wallet.getChainCodeByPath(testPath)\n    let testAaddr = hd.BTC.getAddressByPublicKey(test.pub)\n    console.log(testPath, test.pub.toString(\"hex\"),\"BTC Address\",testAaddr.address)\n```\n\n# Testing\n\n```js\n  mocha \n```\n\n# License\n\n[Apache-2.0 License](./LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb3w%2Fhd-address","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweb3w%2Fhd-address","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb3w%2Fhd-address/lists"}