github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/crypto/ed25519/chainkd/util.go (about)

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