Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeBytesFromString(str string) (bytes []byte, err error)
- func DecodeKeyFromString[T Key](str string, construct func([]byte) (T, error), def T) (T, error)
- func DecryptX25519(privKey, pubKey *[32]byte, encrypted []byte) ([]byte, error)
- func Ed25519PrivateKeyToCurve25519(pk ed25519.PrivateKey) []byte
- func Ed25519PublicKeyToCurve25519(pk ed25519.PublicKey) []byte
- func EncodeBytesToString(bytes []byte) string
- func EncodeKeyToString[T Key](key T) (str string, err error)
- func EncryptX25519(pubKey *[32]byte, msg []byte) []byte
- func GenerateEd25519Key(src io.Reader) (PrivKey, PubKey, error)
- func GenerateRandomEd25519KeyPair() (PrivKey, PubKey, error)
- func IdFromSigningPubKey(pubKey PubKey) (peer.ID, error)
- func KeyEquals(k1, k2 Key) bool
- type AESKey
- type DerivationResult
- type Ed25519PrivKey
- func (k *Ed25519PrivKey) Decrypt(msg []byte) ([]byte, error)
- func (k *Ed25519PrivKey) Equals(o Key) bool
- func (k *Ed25519PrivKey) GetPublic() PubKey
- func (k *Ed25519PrivKey) LibP2P() (crypto.PrivKey, error)
- func (k *Ed25519PrivKey) Marshall() ([]byte, error)
- func (k *Ed25519PrivKey) Raw() ([]byte, error)
- func (k *Ed25519PrivKey) Sign(msg []byte) ([]byte, error)
- type Ed25519PubKey
- func (k *Ed25519PubKey) Account() string
- func (k *Ed25519PubKey) Encrypt(msg []byte) (data []byte, err error)
- func (k *Ed25519PubKey) Equals(o Key) bool
- func (k *Ed25519PubKey) LibP2P() (crypto.PubKey, error)
- func (k *Ed25519PubKey) Marshall() ([]byte, error)
- func (k *Ed25519PubKey) Network() string
- func (k *Ed25519PubKey) PeerId() string
- func (k *Ed25519PubKey) Raw() ([]byte, error)
- func (k *Ed25519PubKey) Storage() []byte
- func (k *Ed25519PubKey) Verify(data []byte, sig []byte) (bool, error)
- type Key
- type KeyStorage
- type Mnemonic
- type MnemonicGenerator
- type PrivKey
- type PubKey
- func DecodeAccountAddress(address string) (PubKey, error)
- func DecodePeerId(peerId string) (PubKey, error)
- func NewEd25519PubKey(pubKey ed25519.PublicKey) PubKey
- func NewSigningEd25519PubKeyFromBytes(bytes []byte) (PubKey, error)
- func UnmarshalEd25519PublicKey(data []byte) (PubKey, error)
- func UnmarshalEd25519PublicKeyProto(bytes []byte) (PubKey, error)
- type SymKey
Constants ¶
const ( // NonceBytes is the length of GCM nonce. NonceBytes = 12 // KeyBytes is the length of GCM key. KeyBytes = 32 )
const ( AnysyncSpacePath = "m/SLIP-0021/anysync/space" AnysyncTreePath = "m/SLIP-0021/anysync/tree/%s" )
Variables ¶
var ( ErrInvalidWordCount = errors.New("error invalid word count for mnemonic") ErrInvalidMnemonic = errors.New("error invalid mnemonic") )
var ErrIncorrectKeyType = errors.New("incorrect key type")
var ErrX25519DecryptionFailed = errors.New("failed decryption with x25519 key")
Functions ¶
func DecodeBytesFromString ¶
func DecodeKeyFromString ¶
func DecryptX25519 ¶
DecryptX25519 takes a x25519 private and public key and decrypts the message
func Ed25519PrivateKeyToCurve25519 ¶
func Ed25519PrivateKeyToCurve25519(pk ed25519.PrivateKey) []byte
Ed25519PrivateKeyToCurve25519 converts an Ed25519 private key to a Curve25519 private key This code is originally taken from here https://github.com/jorrizza/ed2curve25519/blob/master/ed2curve25519.go
func Ed25519PublicKeyToCurve25519 ¶
Ed25519PublicKeyToCurve25519 converts an Ed25519 public key to a Curve25519 public key
func EncodeBytesToString ¶
func EncodeKeyToString ¶
func EncryptX25519 ¶
EncryptX25519 takes a x25519 public key and encrypts the message
func GenerateEd25519Key ¶
GenerateEd25519Key generates a new ed25519 private and public key pair.
Types ¶
type AESKey ¶
type AESKey struct {
// contains filtered or unexported fields
}
func UnmarshallAESKey ¶
UnmarshallAESKey returns a key by decoding bytes.
func UnmarshallAESKeyString ¶
UnmarshallAESKeyString returns a key by decoding a base32-encoded string.
type DerivationResult ¶
type Ed25519PrivKey ¶
type Ed25519PrivKey struct {
// contains filtered or unexported fields
}
Ed25519PrivKey is an ed25519 private key.
func (*Ed25519PrivKey) Decrypt ¶
func (k *Ed25519PrivKey) Decrypt(msg []byte) ([]byte, error)
Decrypt decrypts the message
func (*Ed25519PrivKey) Equals ¶
func (k *Ed25519PrivKey) Equals(o Key) bool
Equals compares two ed25519 private keys.
func (*Ed25519PrivKey) GetPublic ¶
func (k *Ed25519PrivKey) GetPublic() PubKey
GetPublic returns an ed25519 public key from a private key.
func (*Ed25519PrivKey) LibP2P ¶
func (k *Ed25519PrivKey) LibP2P() (crypto.PrivKey, error)
LibP2P converts the key to libp2p format
func (*Ed25519PrivKey) Marshall ¶
func (k *Ed25519PrivKey) Marshall() ([]byte, error)
Marshall marshalls the key into proto
type Ed25519PubKey ¶
type Ed25519PubKey struct {
// contains filtered or unexported fields
}
Ed25519PubKey is an ed25519 public key.
func (*Ed25519PubKey) Account ¶
func (k *Ed25519PubKey) Account() string
Account returns string representation of key in anytype account format
func (*Ed25519PubKey) Encrypt ¶
func (k *Ed25519PubKey) Encrypt(msg []byte) (data []byte, err error)
Encrypt message
func (*Ed25519PubKey) Equals ¶
func (k *Ed25519PubKey) Equals(o Key) bool
Equals compares two ed25519 public keys.
func (*Ed25519PubKey) LibP2P ¶
func (k *Ed25519PubKey) LibP2P() (crypto.PubKey, error)
LibP2P converts the key to libp2p format
func (*Ed25519PubKey) Marshall ¶
func (k *Ed25519PubKey) Marshall() ([]byte, error)
Marshall marshalls the key into proto
func (*Ed25519PubKey) Network ¶
func (k *Ed25519PubKey) Network() string
func (*Ed25519PubKey) PeerId ¶
func (k *Ed25519PubKey) PeerId() string
PeerId returns string representation of key for peer id
func (*Ed25519PubKey) Storage ¶
func (k *Ed25519PubKey) Storage() []byte
Storage returns underlying byte storage
type Key ¶
type Key interface { // Equals returns if the keys are equal Equals(Key) bool // Raw returns raw key Raw() ([]byte, error) }
Key is an abstract interface for all types of keys
type KeyStorage ¶
func NewKeyStorage ¶
func NewKeyStorage() KeyStorage
type Mnemonic ¶
type Mnemonic string
func (Mnemonic) DeriveKeys ¶
func (m Mnemonic) DeriveKeys(index uint32) (res DerivationResult, err error)
type MnemonicGenerator ¶
type MnemonicGenerator struct {
// contains filtered or unexported fields
}
func NewMnemonicGenerator ¶
func NewMnemonicGenerator() MnemonicGenerator
func (MnemonicGenerator) WithEntropy ¶
func (g MnemonicGenerator) WithEntropy(b []byte) (Mnemonic, error)
func (MnemonicGenerator) WithRandomEntropy ¶
func (g MnemonicGenerator) WithRandomEntropy(size int) (Mnemonic, error)
func (MnemonicGenerator) WithWordCount ¶
func (g MnemonicGenerator) WithWordCount(wc int) (Mnemonic, error)
type PrivKey ¶
type PrivKey interface { Key // Decrypt decrypts the message and returns the result Decrypt(message []byte) ([]byte, error) // Sign signs the raw bytes and returns the signature Sign([]byte) ([]byte, error) // GetPublic returns the associated public key GetPublic() PubKey // Marshall wraps key in proto encoding and marshalls it Marshall() ([]byte, error) // LibP2P returns libp2p model LibP2P() (crypto.PrivKey, error) }
PrivKey is an interface for keys that should be used for signing and decryption
func NewEd25519PrivKey ¶
func NewEd25519PrivKey(privKey ed25519.PrivateKey) PrivKey
func UnmarshalEd25519PrivateKey ¶
UnmarshalEd25519PrivateKey returns a private key from input bytes.
type PubKey ¶
type PubKey interface { Key // Encrypt encrypts the message and returns the result Encrypt(message []byte) ([]byte, error) // Verify verifies the signed message and the signature Verify(data []byte, sig []byte) (bool, error) // Marshall wraps key in proto encoding and marshalls it Marshall() ([]byte, error) // Storage returns underlying key storage Storage() []byte // Account returns string representation for anytype account Account() string // Network returns string representation for anytype network Network() string // PeerId returns string representation for peer id PeerId() string // LibP2P returns libp2p model LibP2P() (crypto.PubKey, error) }
PubKey is the public key used to verify the signatures and decrypt messages
func DecodeAccountAddress ¶
func DecodePeerId ¶
func NewEd25519PubKey ¶
func UnmarshalEd25519PublicKey ¶
UnmarshalEd25519PublicKey returns a public key from input bytes.