OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Fri, 24 May 2019 03:11:29 +0000 (11:11 +0800)
committerChengcheng Zhang <943420582@qq.com>
Fri, 24 May 2019 03:11:29 +0000 (11:11 +0800)
account/accounts_test.go
crypto/csp/util.go
crypto/ed25519/chainkd/serialize.go

index 2cc1dc5..1f773d4 100644 (file)
@@ -76,6 +76,8 @@ func TestCreateAccount(t *testing.T) {
        fmt.Println("found is:", found, "found xpub:", found.XPubs)
        if !testutil.DeepEqual(account, found) {
                t.Errorf("expected account %v to be recorded as %v", account, found)
+               //////////
+               t.Errorf("expected type of account %v to be recorded as %v", reflect.TypeOf(account.XPubs[0]), reflect.TypeOf(found.XPubs[0]))
        }
 }
 
index 287f860..eae5e6b 100644 (file)
@@ -49,12 +49,17 @@ func XPubKeys(xpubs []vcrypto.XPubKeyer) []crypto.PublicKey {
 func DeriveXPubs(xpubs []vcrypto.XPubKeyer, path [][]byte) []vcrypto.XPubKeyer {
        res := make([]vcrypto.XPubKeyer, 0, len(xpubs))
        for _, xpub := range xpubs {
-               fmt.Println("DeriveXPubs =====", reflect.TypeOf(xpubs[0]))
-               if xpb, ok := xpub.(edchainkd.XPub); ok {
-                       d := xpb.Derive(path)
+               fmt.Println("DeriveXPubs type xpubs:", reflect.TypeOf(xpubs), "type xpubs[0]:", reflect.TypeOf(xpubs[0]))
+               fmt.Println("xpubs[0] is:", xpubs[0])
+               newxpub, err := edchainkd.NewXPub(reflect.ValueOf(xpub).String())
+               if err != nil {
+                       fmt.Println("csp DeriveXPubs err:", err)
+               } else {
+                       d := newxpub.Derive(path)
                        res = append(res, d)
                        fmt.Println("DeriveXPubs d is:", d)
                }
+
                // switch xpb := xpub.(type) {
                // case edchainkd.XPub:
                //      d := xpb.Derive(path)
index a6fe639..133b94b 100644 (file)
@@ -3,6 +3,7 @@ package chainkd
 import (
        "encoding/hex"
        "errors"
+       "fmt"
 )
 
 const (
@@ -59,7 +60,17 @@ func (xprv XPrv) String() string {
        return hex.EncodeToString(xprv.Bytes())
 }
 
-// func (xpub *XPub) UnmarshalJSON(b []byte) error {
+func NewXPub(str string) (xpub *XPub, err error) {
+       if len(str) != 2*extendedPublicKeySize {
+               fmt.Println("str length is:", len(str))
+               fmt.Println("str is:", str)
+               return nil, errors.New("string length is invalid.")
+       }
+       if xpubBytes, err := hex.DecodeString(str); err != nil {
+               return nil, err
+       } else {
+               copy(xpub[:], xpubBytes[:])
+       }
 
-//     return nil
-// }
+       return xpub, nil
+}