OSDN Git Service

Merge pull request #41 from Bytom/dev
[bytom/vapor.git] / crypto / ed25519 / chainkd / util.go
1 package chainkd
2
3 import (
4         "io"
5
6         "github.com/vapor/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 }