Skip to content

Commit

Permalink
mod:chain example
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wang committed Jul 31, 2020
1 parent d756f4f commit cf21ce1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,19 @@ module.exports = class EosAddress extends AddressClass {
```
### **Chain Code:** [example](./example/chaincode.js)
```js
let hdPath = "m/44'/0'/1'"
let {pub, chainCode} = hd.wallet.getPathChainCode(hdPath)
console.log(hdPath, "chainCode", chainCode.toString("hex"))

let childPath = "m/1/" + hdIndex
let child = hd.wallet.getPublicKeyByChainCode(pub, chainCode, childPath)
console.log(childPath, child.pub.toString("hex"))

let testPath = "m/44'/0'/1'/1/" + hdIndex
let test = hd.wallet.getPathChainCode(testPath)
console.log(testPath, test.pub.toString("hex"))
let hdPath = "m/44'/0'/1'"
let {pub, chainCode} = hd.wallet.getPathChainCode(hdPath)
console.log(hdPath, "chainCode", chainCode.toString("hex"),"\n")

let childPath = "m/1/" + hdIndex
let child = hd.wallet.getPublicKeyByChainCode(pub, chainCode, childPath)
let childAaddr = hd.BTC.getAddressByPublicKey(child.pub)
console.log(childPath, child.pub.toString("hex"),"BTC Address",childAaddr.address)

let testPath = "m/44'/0'/1'/1/" + hdIndex
let test = hd.wallet.getPathChainCode(testPath)
let testAaddr = hd.BTC.getAddressByPublicKey(child.pub)
console.log(testPath, test.pub.toString("hex"),"BTC Address",testAaddr.address)
```
# Testing

Expand Down
8 changes: 5 additions & 3 deletions example/chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ let hd = hdAddress.HD(myselfMnemonic)
let getPublicKeyByChainCode = () => {
let hdPath = "m/44'/0'/1'"
let {pub, chainCode} = hd.wallet.getPathChainCode(hdPath)
console.log(hdPath, "chainCode", chainCode.toString("hex"))
console.log(hdPath, "chainCode", chainCode.toString("hex"),"\n")

let childPath = "m/1/" + hdIndex
let child = hd.wallet.getPublicKeyByChainCode(pub, chainCode, childPath)
console.log(childPath, child.pub.toString("hex"))
let childAaddr = hd.BTC.getAddressByPublicKey(child.pub)
console.log(childPath, child.pub.toString("hex"),"BTC Address",childAaddr.address)

let testPath = "m/44'/0'/1'/1/" + hdIndex
let test = hd.wallet.getPathChainCode(testPath)
console.log(testPath, test.pub.toString("hex"))
let testAaddr = hd.BTC.getAddressByPublicKey(child.pub)
console.log(testPath, test.pub.toString("hex"),"BTC Address",testAaddr.address)
}

let getPrivateKeyByChainCode = () => {
Expand Down
2 changes: 2 additions & 0 deletions test/lib/utils/hd.chaincode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ it("HD getPublicKeyByChainCode", async () => {
let hd = new HDWallet()
let hdPath = "m/44'/0'/1'"
let {pub,chainCode} = hd.getPathChainCode(hdPath)
let pubAddr = hd.BTC.getAddressByPublicKey(pub)
console.log(hdPath,"chainCode",chainCode.toString("hex"))
console.log(hdPath,"chainCode",chainCode.toString("hex"))

let childPath= "m/1/"+hdIndex
Expand Down

0 comments on commit cf21ce1

Please sign in to comment.