Ejemplo n.º 1
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,
	}
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
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
}