github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/crypto/ed25519/chainkd/util.go (about)

     1  package chainkd
     2  
     3  import (
     4  	"crypto/ed25519"
     5  	"io"
     6  )
     7  
     8  // Utility functions
     9  
    10  func NewXKeys(r io.Reader) (xprv XPrv, xpub XPub, err error) {
    11  	xprv, err = NewXPrv(r)
    12  	if err != nil {
    13  		return
    14  	}
    15  	return xprv, xprv.XPub(), nil
    16  }
    17  
    18  func XPubKeys(xpubs []XPub) []ed25519.PublicKey {
    19  	res := make([]ed25519.PublicKey, 0, len(xpubs))
    20  	for _, xpub := range xpubs {
    21  		res = append(res, xpub.PublicKey())
    22  	}
    23  	return res
    24  }
    25  
    26  func DeriveXPubs(xpubs []XPub, path [][]byte) []XPub {
    27  	res := make([]XPub, 0, len(xpubs))
    28  	for _, xpub := range xpubs {
    29  		d := xpub.Derive(path)
    30  		res = append(res, d)
    31  	}
    32  	return res
    33  }