import (
"encoding/json"
- "fmt"
"reflect"
"sort"
"strings"
// FindByID returns an account's Signer record by its ID.
func (m *Manager) FindByID(id string) (*Account, error) {
- fmt.Println("FindByID start...")
m.cacheMu.Lock()
cachedAccount, ok := m.cache.Get(id)
m.cacheMu.Unlock()
}
for i, xpub := range account.XPubs {
if reflect.TypeOf(xpub).String() == "string" {
- // fmt.Println("account xpubs type:", reflect.TypeOf(xpub).String())
if xpb, err := edchainkd.NewXPub(reflect.ValueOf(xpub).String()); err != nil {
panic(err)
} else {
account.XPubs[i] = *xpb
}
- fmt.Println("account xpubs type:", reflect.TypeOf(account.XPubs[i]).String())
}
}
m.cacheMu.Lock()
m.cache.Add(id, account)
- fmt.Println("FindByID m.cache...", m.cache)
m.cacheMu.Unlock()
return account, nil
}
}
func createP2PKH(account *Account, path [][]byte) (*CtrlProgram, error) {
- fmt.Println("createP2PKH account.XPubs is:", account.XPubs)
derivedXPubs := csp.DeriveXPubs(account.XPubs, path)
- fmt.Println("createP2PKH derivedXPubs is:", derivedXPubs)
pubHash := make([]byte, 0)
- fmt.Println("createP2PKH len(derivedXPubs) is:", len(derivedXPubs))
if len(derivedXPubs) == 0 {
return nil, errors.New("no derived XPub.")
}
derivedPK := dxpub.PublicKey()
pubHash = crypto.Ripemd160(derivedPK)
}
- fmt.Println("createP2PKH ...")
address, err := common.NewAddressWitnessPubKeyHash(pubHash, &consensus.ActiveNetParams)
if err != nil {
import (
"context"
- "encoding/hex"
stdjson "encoding/json"
- "fmt"
- "reflect"
"github.com/vapor/blockchain/signers"
"github.com/vapor/blockchain/txbuilder"
// UtxoToInputs convert an utxo to the txinput
func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.SigningInstruction, error) {
- fmt.Println("UtxoToInputs...")
txInput := types.NewSpendInput(nil, u.SourceID, u.AssetID, u.Amount, u.SourcePos, u.ControlProgram)
sigInst := &txbuilder.SigningInstruction{}
if signer == nil {
if err != nil {
return nil, nil, err
}
- fmt.Println("UtxoToInputs...will sigInst.AddRawWitnessKeys")
sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
derivedXPubs := csp.DeriveXPubs(signer.XPubs, path)
- fmt.Println("UtxoToInputs...finish derivedXPubs := csp.DeriveXPubs(signer.XPubs, path)")
- fmt.Println("UtxoToInputs derivedXPubs:", derivedXPubs)
- fmt.Println("UtxoToInputs derivedXPubs[0] type:", reflect.TypeOf(derivedXPubs[0]))
- //
if len(derivedXPubs) == 0 {
panic("UtxoToInputs derivedXPubs is nil.")
}
switch address.(type) {
case *common.AddressWitnessPubKeyHash:
- fmt.Println("UtxoToInputs *common.AddressWitnessPubKeyHash...")
switch dxpub := derivedXPubs[0].(type) {
case edchainkd.XPub:
- fmt.Println("UtxoToInputs dxpub", hex.EncodeToString(dxpub[:]))
derivedPK := dxpub.PublicKey()
- fmt.Println("UtxoToInputs derivedPK", hex.EncodeToString(derivedPK))
sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(derivedPK)))
- fmt.Println("UtxoToInputs *common.AddressWitnessPubKeyHash done...")
}
case *common.AddressWitnessScriptHash:
- fmt.Println("UtxoToInputs *common.AddressWitnessScriptHash...")
- fmt.Println("UtxoToInputs derivedXPubs", derivedXPubs)
derivedPKs := csp.XPubKeys(derivedXPubs)
script, err := vmutil.P2SPMultiSigProgram(derivedPKs, signer.Quorum)
if err != nil {
return nil, nil, err
}
- fmt.Println("UtxoToInputs derivedPKs:", derivedPKs)
sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness(script))
default:
"fmt"
"io/ioutil"
"os"
- "reflect"
"strings"
"testing"
if err != nil {
t.Fatal(err)
}
- fmt.Println("TestPseudoHSMChainKDKeys xpub:", xpub)
xpub2, _, err := hsm.XCreate("bytom", "nopassword", "en")
if err != nil {
t.Fatal(err)
if err != nil {
t.Fatal(err)
}
- fmt.Println("TestPseudoHSMChainKDKeys xpub.XPub:", xpub.XPub)
- fmt.Println("TestPseudoHSMChainKDKeys xpub.XPub type:", reflect.TypeOf(xpub.XPub))
- fmt.Println("TestPseudoHSMChainKDKeys sig:", sig)
- fmt.Println("TestPseudoHSMChainKDKeys sig type:", reflect.TypeOf(sig))
-
switch xpubkey := xpub.XPub.(type) {
case edchainkd.XPub:
- fmt.Println("TestPseudoHSMChainKDKeys 1 sig:", sig)
if !xpubkey.Verify(msg, sig) {
t.Error("expected verify to succeed")
}
func NewXKeys(r io.Reader) (xprv vcrypto.XPrvKeyer, xpub vcrypto.XPubKeyer, err error) {
// TODO: if ... create sm2 xprv and xpub
- // return .....
- // if ... create ed25519 xprv and xpub
return edchainkd.NewXKeys(r)
}
return res
}
-// func DeriveXPubs(xpubs []vcrypto.XPubKeyer, path [][]byte) []vcrypto.XPubKeyer {
-// res := make([]vcrypto.XPubKeyer, 0, len(xpubs))
-// for _, xpub := range xpubs {
-// switch xpb := xpub.(type) {
-// case edchainkd.XPub:
-// d := xpb.Derive(path)
-// res = append(res, d)
-// fmt.Println("DeriveXPubs d is:", d)
-// }
-// }
-// fmt.Println("DeriveXPubs len(res) is:", len(res))
-// return res
-// }
-
func DeriveXPubs(xpubs []vcrypto.XPubKeyer, path [][]byte) []vcrypto.XPubKeyer {
res := make([]vcrypto.XPubKeyer, 0, len(xpubs))
for _, xpub := range xpubs {
- fmt.Println("DeriveXPubs type xpubs:", reflect.TypeOf(xpubs), "type xpubs[0]:", reflect.TypeOf(xpubs[0]))
- fmt.Println("xpubs[0] is:", xpubs[0])
switch xpb := xpub.(type) {
case edchainkd.XPub:
d := xpb.Derive(path)
res = append(res, d)
- fmt.Println("DeriveXPubs d is:", d)
default:
newxpub, err := edchainkd.NewXPub(reflect.ValueOf(xpub).String())
if err != nil {
} else {
d := newxpub.Derive(path)
res = append(res, d)
- fmt.Println("DeriveXPubs d is:", d)
}
}
}
- fmt.Println("DeriveXPubs len(res) is:", len(res))
return res
}
import (
"encoding/hex"
"errors"
- "fmt"
)
const (
func NewXPub(str string) (*XPub, error) {
xpub := new(XPub)
if len(str) != 2*64 {
- 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 {
- fmt.Println("NewXPub xpub is:", xpub)
- fmt.Println("NewXPub xpubBytes is:", xpubBytes)
copy(xpub[:], xpubBytes[:])
}
return xpub, nil
package types
import (
- "fmt"
-
log "github.com/sirupsen/logrus"
"github.com/vapor/consensus"
// MapTx converts a types TxData object into its entries-based
// representation.
func MapTx(oldTx *TxData) *bc.Tx {
- fmt.Println("MapTx start...")
txID, txHeader, entries := mapTx(oldTx)
tx := &bc.Tx{
TxHeader: txHeader,