keys/hd/address.go
func DerivePrivateKeyForPath(privKeyBytes []byte, chainCode []byte, path string) []byte {
	data := privKeyBytes
	parts := strings.Split(path, "/")
	for _, part := range parts {
		prime := part[len(part)-1:] == "'"
		// prime == private derivation. Otherwise public.
		if prime {
			part = part[:len(part)-1]
		}
		i, err := strconv.Atoi(part)
		if err != nil {
			panic(err)
		}
		if i < 0 {
			panic(errors.New("index too large."))
		}
		data, chainCode = DerivePrivateKey(data, chainCode, uint32(i), prime)
		//printKeyInfo(data, nil, chain)
	}
	return data
}
func DerivePrivateKeyForPath(privKeyBytes []byte, chainCode []byte, path string) []byte {
	data := privKeyBytes
	parts := strings.Split(path, "/")
	for _, part := range parts {
		prime := part[len(part)-1:] == "'"
		// prime == private derivation. Otherwise public.
		if prime {
			part = part[:len(part)-1]
		}
		i, err := strconv.Atoi(part)
		if err != nil {
			panic(err)
		}
		if i < 0 {
			panic(errors.New("index too large."))
		}
		data, chainCode = DerivePrivateKey(data, chainCode, uint32(i), prime)
		//printKeyInfo(data, nil, chain)
	}
	return data
}
func DerivePrivateKeyForPath ( privKeyBytes [ ] byte , chainCode [ ] byte , path string ) [ ] byte { data := privKeyBytes parts := strings . Split ( path , " " ) for _ , part := range parts { prime := part [ len ( part ) - 1 : ] == " " // prime == private derivation. Otherwise public. if prime { part = part [ : len ( part ) - 1 ] } i , err := strconv . Atoi ( part ) if err != nil { panic ( err ) } if i < 0 { panic ( errors . New ( " " ) ) } data , chainCode = DerivePrivateKey ( data , chainCode , uint32 ( i ) , prime ) //printKeyInfo(data, nil, chain) } return data }
/*
func printKeyInfo(privKeyBytes []byte, pubKeyBytes []byte, chain []byte) {
	if pubKeyBytes == nil {
		pubKeyBytes = PubKeyBytesFromPrivKeyBytes(privKeyBytes, true)
	}
	addr := AddrFromPubKeyBytes(pubKeyBytes)
	log.Println("\nprikey:\t%v\npubKeyBytes:\t%v\naddr:\t%v\nchain:\t%v",
		HexEncode(privKeyBytes),
		HexEncode(pubKeyBytes),
		addr,
		HexEncode(chain))
}
*/
//-------------------------------------------------------------------
// DerivePrivateKeyForPath derives the private key by following the path from privKeyBytes,
// using the given chainCode.
/ * func printKeyInfo ( privKeyBytes [] byte pubKeyBytes [] byte chain [] byte ) { if pubKeyBytes == nil { pubKeyBytes = PubKeyBytesFromPrivKeyBytes ( privKeyBytes true ) } addr : = AddrFromPubKeyBytes ( pubKeyBytes ) log . Println ( \ nprikey : \ t%v \ npubKeyBytes : \ t%v \ naddr : \ t%v \ nchain : \ t%v HexEncode ( privKeyBytes ) HexEncode ( pubKeyBytes ) addr HexEncode ( chain )) } ------------------------------------------------------------------- DerivePrivateKeyForPath derives the private key by following the path from privKeyBytes using the given chainCode .