Documentation ¶
Index ¶
- Constants
- Variables
- func Aes256Decrypt(key []byte, ciphertext []byte) ([]byte, error)
- func Aes256Encrypt(key []byte, plaintext []byte) ([]byte, error)
- func ConfigDecodeAesKey(key string) ([]byte, error)
- func ConfigDecodeEncryptKey(b string) (*[32]byte, error)
- func ConfigDecodeKey(b string) ([]byte, error)
- func ConfigEncodeAesKey(key []byte) string
- func ConfigEncodeEncryptKey(key *[32]byte) string
- func ConfigEncodeKey(b []byte) string
- func GenerateCryptKeys(src io.Reader) (PrivCKey, PubCKey, error)
- func GenerateEd25519Key(src io.Reader) (PrivKey, PubKey, error)
- func GenerateKeyPairWithReader(typ int32, src io.Reader) (PrivKey, PubKey, error)
- func HashBlake2x(key []byte) ([256]byte, error)
- func KeyEqual(k1, k2 Key) bool
- func MarshalPrivateKey(k PrivKey) ([]byte, error)
- func MarshalPublicKey(k PubKey) ([]byte, error)
- func New32ByteKey() ([]byte, error)
- func Nonce() ([24]byte, error)
- func ValidateAddress(address string) bool
- type Curve25519PrivateKey
- type Curve25519PublicKey
- type Ed25519PrivateKey
- func (k *Ed25519PrivateKey) Bytes() ([]byte, error)
- func (k *Ed25519PrivateKey) Equals(o Key) bool
- func (k *Ed25519PrivateKey) GetPublic() PubKey
- func (k *Ed25519PrivateKey) Raw() ([]byte, error)
- func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)
- func (k *Ed25519PrivateKey) Type() pb.KeyType
- type Ed25519PublicKey
- type GenSharedKey
- type Key
- type PrivCKey
- type PrivKey
- type PrivKeyUnmarshaller
- type PubCKey
- type PubKey
- type PubKeyUnmarshaller
Constants ¶
const ( // Ed25519 is an enum for the supported Ed25519 key type Ed25519 = iota )
Variables ¶
var ( ErrDecryptionFailed = errors.New("message decryption failed") ErrEncryptFailed = errors.New("message encryption failed") )
var ( // ErrBadKeyType is returned when a key is not supported ErrBadKeyType = errors.New("invalid or unsupported key type") // KeyTypes is a list of supported keys KeyTypes = []int{ Ed25519, } )
var PrivKeyUnmarshallers = map[pb.KeyType]PrivKeyUnmarshaller{ pb.KeyType_Ed25519: UnmarshalEd25519PrivateKey, }
PrivKeyUnmarshallers is a map of unmarshallers by key type
var PubKeyUnmarshallers = map[pb.KeyType]PubKeyUnmarshaller{ pb.KeyType_Ed25519: UnmarshalEd25519PublicKey, }
PubKeyUnmarshallers is a map of unmarshallers by key type
Functions ¶
func Aes256Encrypt ¶
Aes256Encrypt key must be 32 bytes long to have AES-256
func ConfigDecodeAesKey ¶
func ConfigDecodeEncryptKey ¶
func ConfigDecodeKey ¶
ConfigDecodeKey decodes from b64 (for config file), and unmarshals.
func ConfigEncodeAesKey ¶
func ConfigEncodeEncryptKey ¶
func ConfigEncodeKey ¶
ConfigEncodeKey encodes to b64 (for config file), and marshals.
func GenerateEd25519Key ¶
GenerateEd25519Key generate a new ed25519 private and public key pair
func GenerateKeyPairWithReader ¶
GenerateKeyPairWithReader returns a keypair of the given type and bitsize
func HashBlake2x ¶
HashBlake2x : https://blake2.net/blake2x.pdf
func MarshalPrivateKey ¶
MarshalPrivateKey converts a key object into its protobuf serialized form.
func MarshalPublicKey ¶
MarshalPublicKey converts a public key object into a protobuf serialized public key
func New32ByteKey ¶
New32ByteKey creates random 32-byte key for AES-256 GCM encryption
func ValidateAddress ¶
ValidateAddress checks if address corresponds to farmiliar format The address is created as : encodeBase64(pubKey)->sha256->"0x" + substring(64-40,64);
Types ¶
type Curve25519PrivateKey ¶
type Curve25519PrivateKey struct {
Key *[32]byte
}
Ed25519PrivateKey is an ed25519 private key
func (*Curve25519PrivateKey) Decrypt ¶
func (k *Curve25519PrivateKey) Decrypt(senderPublicKey PubCKey, encryptedPayload []byte) ([]byte, error)
func (*Curve25519PrivateKey) Encrypt ¶
func (k *Curve25519PrivateKey) Encrypt(recipientPublicKey PubCKey, payload []byte) ([]byte, error)
Bytes marshals an ed25519 private key to protobuf bytes
func (*Curve25519PrivateKey) Raw ¶
func (k *Curve25519PrivateKey) Raw() *[32]byte
type Curve25519PublicKey ¶
type Curve25519PublicKey struct {
Key *[32]byte
}
Ed25519PublicKey is an ed25519 public key
func (*Curve25519PublicKey) Raw ¶
func (k *Curve25519PublicKey) Raw() *[32]byte
type Ed25519PrivateKey ¶
type Ed25519PrivateKey struct {
// contains filtered or unexported fields
}
Ed25519PrivateKey is an ed25519 private key
func (*Ed25519PrivateKey) Bytes ¶
func (k *Ed25519PrivateKey) Bytes() ([]byte, error)
Bytes marshals an ed25519 private key to protobuf bytes
func (*Ed25519PrivateKey) Equals ¶
func (k *Ed25519PrivateKey) Equals(o Key) bool
Equals compares two ed25519 private keys
func (*Ed25519PrivateKey) GetPublic ¶
func (k *Ed25519PrivateKey) GetPublic() PubKey
GetPublic returns an ed25519 public key from a private key
func (*Ed25519PrivateKey) Raw ¶
func (k *Ed25519PrivateKey) Raw() ([]byte, error)
func (*Ed25519PrivateKey) Sign ¶
func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)
Sign returns a signature from an input message
func (*Ed25519PrivateKey) Type ¶
func (k *Ed25519PrivateKey) Type() pb.KeyType
type Ed25519PublicKey ¶
type Ed25519PublicKey struct {
// contains filtered or unexported fields
}
Ed25519PublicKey is an ed25519 public key
func (*Ed25519PublicKey) Bytes ¶
func (k *Ed25519PublicKey) Bytes() ([]byte, error)
Bytes returns a ed25519 public key as protobuf bytes
func (*Ed25519PublicKey) Equals ¶
func (k *Ed25519PublicKey) Equals(o Key) bool
Equals compares two ed25519 public keys
func (*Ed25519PublicKey) Raw ¶
func (k *Ed25519PublicKey) Raw() ([]byte, error)
func (*Ed25519PublicKey) Type ¶
func (k *Ed25519PublicKey) Type() pb.KeyType
type GenSharedKey ¶
GenSharedKey generates the shared key from a given private key
type Key ¶
type Key interface { // Bytes returns a serialized, storeable representation of this key // DEPRECATED in favor of Marshal / Unmarshal Bytes() ([]byte, error) // Equals checks whether two PubKeys are the same Equals(Key) bool // Raw returns the raw bytes of the key (not wrapped in the // libp2p-crypto protobuf). // // This function is the inverse of {Priv,Pub}KeyUnmarshaler. Raw() ([]byte, error) // Type returns the protobof key type. Type() pb.KeyType }
Key represents a crypto key that can be compared to another key
type PrivKey ¶
type PrivKey interface { Key // Cryptographically sign the given bytes Sign([]byte) ([]byte, error) // Return a public key paired with this private key GetPublic() PubKey }
PrivKey represents a private key that can be used to generate a public key, sign data, and decrypt data that was encrypted with a public key
func UnmarshalPrivateKey ¶
UnmarshalPrivateKey converts a protobuf serialized private key into its representative object
type PrivKeyUnmarshaller ¶
PrivKeyUnmarshaller is a func that creates a PrivKey from a given slice of bytes
type PubKey ¶
type PubKey interface { Key // Verify that 'sig' is the signed hash of 'data' Verify(data []byte, sig []byte) (bool, error) }
PubKey is a public key
func UnmarshalPublicKey ¶
UnmarshalPublicKey converts a protobuf serialized public key into its representative object
type PubKeyUnmarshaller ¶
PubKeyUnmarshaller is a func that creates a PubKey from a given slice of bytes