Пример #1
0
func cliConvertPrivValidatorToErisKey(cmd *cobra.Command, args []string) {
	cmd.ParseFlags(args)
	if len(args) == 0 {
		exit(fmt.Errorf("Please enter the path to the priv_validator.json"))
	}

	pvf := args[0]
	b, err := ioutil.ReadFile(pvf)
	ifExit(err)

	pv := new(PrivValidator)
	wire.ReadJSON(pv, b, &err)
	ifExit(err)

	keyStore := crypto.NewKeyStorePlain(DefaultKeyStore)

	key := &crypto.Key{
		Id:         uuid.NewRandom(),
		Type:       crypto.KeyType{crypto.CurveTypeEd25519, crypto.AddrTypeRipemd160},
		Address:    pv.Address,
		PrivateKey: pv.PrivKey[:],
	}

	fmt.Printf("%X\n", key.Address)
	ifExit(keyStore.StoreKey(key, ""))
}
Пример #2
0
func newKeySecp256k1(addrType AddrType) *Key {
	pub, priv := secp256k1.GenerateKeyPair()
	return &Key{
		Id:         uuid.NewRandom(),
		Type:       KeyType{CurveTypeSecp256k1, addrType},
		Address:    AddressFromPub(addrType, pub),
		PrivateKey: priv,
	}
}
Пример #3
0
func keyFromPrivEd25519(addrType AddrType, priv []byte) (*Key, error) {
	privKeyBytes := new([64]byte)
	copy(privKeyBytes[:32], priv)
	pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
	pubKey := account.PubKeyEd25519(*pubKeyBytes)
	return &Key{
		Id:         uuid.NewRandom(),
		Type:       KeyType{CurveTypeEd25519, addrType},
		Address:    pubKey.Address(),
		PrivateKey: privKeyBytes[:],
	}, nil
}
Пример #4
0
func keyFromPrivSecp256k1(addrType AddrType, priv []byte) (*Key, error) {
	pub, err := secp256k1.GeneratePubKey(priv)
	if err != nil {
		return nil, err
	}
	return &Key{
		Id:         uuid.NewRandom(),
		Type:       KeyType{CurveTypeSecp256k1, addrType},
		Address:    AddressFromPub(addrType, pub),
		PrivateKey: priv,
	}, nil
}
Пример #5
0
func coreConvertPrivValidatorToErisKey(b []byte) (key *kstore.Key, err error) {

	pv := new(PrivValidator)
	wire.ReadJSON(pv, b, &err)
	if err != nil {
		return nil, err
	}

	keyStore := kstore.NewKeyStorePlain(DefaultKeyStore)

	key = &kstore.Key{
		Id:         uuid.NewRandom(),
		Type:       kstore.KeyType{kstore.CurveTypeEd25519, kstore.AddrTypeRipemd160},
		Address:    pv.Address,
		PrivateKey: pv.PrivKey[:],
	}

	err = keyStore.StoreKey(key, "")
	return key, err
}