Guest User

Untitled

a guest
Feb 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/hex"
  5. "fmt"
  6.  
  7. "github.com/bytom/crypto/sm2/chainkd"
  8. )
  9.  
  10. func main() {
  11. strXpub := "02e097442c49eccae999f7687e088c918838df8d804980a220dba6bd7a51258e76347a32ad977251122e50456dcfe155d80cbfa83186a64f7756f044a126e664ac"
  12. byteXpub := decodeHexString(strXpub)
  13. xpub := new(chainkd.XPub)
  14. copy(xpub[:], byteXpub[:])
  15.  
  16. bytePath := [][]byte{decodeHexString("00010203"), decodeHexString("03ededed"), decodeHexString("123456")}
  17.  
  18. ChildXpub := xpub.Derive(bytePath)
  19. byteChildXpub := make([]byte, 65)
  20. copy(byteChildXpub[:], ChildXpub[:])
  21. strChildXpub := hex.EncodeToString(byteChildXpub)
  22.  
  23. fmt.Println("xpub: ", hex.EncodeToString(byteXpub))
  24. fmt.Println("path: ")
  25. for _, p := range bytePath {
  26. fmt.Println(hex.EncodeToString(p))
  27. }
  28. fmt.Println("child xpub: ", strChildXpub)
  29. }
  30.  
  31. func decodeHexString(hexStr string) (b []byte) {
  32. b, err := hex.DecodeString(hexStr)
  33. if err != nil {
  34. panic(err)
  35. }
  36. return
  37. }
Add Comment
Please, Sign In to add comment