Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/hex"
- "fmt"
- "github.com/bytom/crypto/sm2/chainkd"
- )
- func main() {
- strXpub := "02e097442c49eccae999f7687e088c918838df8d804980a220dba6bd7a51258e76347a32ad977251122e50456dcfe155d80cbfa83186a64f7756f044a126e664ac"
- byteXpub := decodeHexString(strXpub)
- xpub := new(chainkd.XPub)
- copy(xpub[:], byteXpub[:])
- bytePath := [][]byte{decodeHexString("00010203"), decodeHexString("03ededed"), decodeHexString("123456")}
- ChildXpub := xpub.Derive(bytePath)
- byteChildXpub := make([]byte, 65)
- copy(byteChildXpub[:], ChildXpub[:])
- strChildXpub := hex.EncodeToString(byteChildXpub)
- fmt.Println("xpub: ", hex.EncodeToString(byteXpub))
- fmt.Println("path: ")
- for _, p := range bytePath {
- fmt.Println(hex.EncodeToString(p))
- }
- fmt.Println("child xpub: ", strChildXpub)
- }
- func decodeHexString(hexStr string) (b []byte) {
- b, err := hex.DecodeString(hexStr)
- if err != nil {
- panic(err)
- }
- return
- }
Add Comment
Please, Sign In to add comment