crypto

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// P256 curve
	P256 string = "P-256"
	// P384 curve
	P384 string = "P-384"
	// P521 curve
	P521 string = "P-521"
)
View Source
const (
	ErrUnsupportedKeyAlgorithm = errors.Error("key algorithm not supported")
	ErrInvalidSignature        = errors.Error("invalid signature")
)

Variables

View Source
var (
	EmptyPublicKey  = PublicKey{}
	EmptyPrivateKey = PrivateKey{}
)

Functions

func CalculateSharedKey added in v0.7.0

func CalculateSharedKey(
	priv PrivateKey,
	pub PublicKey,
) ([]byte, error)

CalculateSharedKey calculates a shared secret given a private an public key

func GenerateTLSCertificate added in v0.5.0

func GenerateTLSCertificate(privateKey PrivateKey) (*tls.Certificate, error)

GenerateTLSCertificate for TLS serverset

Types

type KeyAlgorithm added in v0.18.0

type KeyAlgorithm multicodec.Code
const (
	Ed25519Private KeyAlgorithm = KeyAlgorithm(multicodec.Ed25519Priv)
	Ed25519Public  KeyAlgorithm = KeyAlgorithm(multicodec.Ed25519Pub)
)

type PrivateKey

type PrivateKey struct {
	Algorithm KeyAlgorithm
	RawKey    ed25519.PrivateKey // TODO use crypto.PrivateKey
}

func CalculateEphemeralSharedKey added in v0.18.0

func CalculateEphemeralSharedKey(
	pub PublicKey,
) (PrivateKey, []byte, error)

CalculateEphemeralSharedKey creates a new ec25519 key pair, calculates a shared secret given a public key, and returns the created public key and secret

func NewEd25519PrivateKey added in v0.18.0

func NewEd25519PrivateKey() (PrivateKey, error)

func NewEd25519PrivateKeyFromBIP39 added in v0.19.0

func NewEd25519PrivateKeyFromBIP39(mnemonic string) (PrivateKey, error)

TODO check validity and return error

func NewEd25519PrivateKeyFromSeed added in v0.18.0

func NewEd25519PrivateKeyFromSeed(seed []byte) PrivateKey

TODO check validity and return error

func NewSharedKey added in v0.15.4

func NewSharedKey(
	priv PrivateKey,
	pub PublicKey,
) (PrivateKey, []byte, error)

NewSharedKey calculates a shared secret given a private and a public key, and returns it

func (PrivateKey) BIP39 added in v0.19.0

func (k PrivateKey) BIP39() string

func (PrivateKey) IsEmpty added in v0.5.0

func (k PrivateKey) IsEmpty() bool

func (PrivateKey) MarshalJSON added in v0.18.0

func (k PrivateKey) MarshalJSON() ([]byte, error)

func (PrivateKey) MarshalString added in v0.18.0

func (k PrivateKey) MarshalString() (string, error)

func (PrivateKey) PublicKey

func (k PrivateKey) PublicKey() PublicKey

func (PrivateKey) Seed added in v0.19.0

func (k PrivateKey) Seed() []byte

func (PrivateKey) Sign added in v0.5.0

func (k PrivateKey) Sign(message []byte) []byte

func (PrivateKey) String added in v0.5.0

func (k PrivateKey) String() string

func (*PrivateKey) UnmarshalJSON added in v0.18.0

func (k *PrivateKey) UnmarshalJSON(s []byte) error

func (*PrivateKey) UnmarshalString added in v0.18.0

func (k *PrivateKey) UnmarshalString(s string) error

func (*PrivateKey) UnmarshalText added in v0.18.0

func (k *PrivateKey) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler mainly for use by envconfig.

type PublicKey

type PublicKey struct {
	Algorithm KeyAlgorithm
	RawKey    ed25519.PublicKey // TODO use crypto.PublicKey
}

func NewEd25519PublicKeyFromRaw added in v0.18.0

func NewEd25519PublicKeyFromRaw(raw ed25519.PublicKey) PublicKey

TODO check validity and return error

func PublicKeyFromDID added in v0.19.0

func PublicKeyFromDID(d did.DID) (*PublicKey, error)

func (PublicKey) DID added in v0.19.0

func (k PublicKey) DID() did.DID

func (PublicKey) Equals added in v0.5.0

func (k PublicKey) Equals(w PublicKey) bool

func (PublicKey) Hash added in v0.19.0

func (k PublicKey) Hash() tilde.Digest

func (PublicKey) IsEmpty added in v0.5.0

func (k PublicKey) IsEmpty() bool

func (PublicKey) MarshalJSON added in v0.18.0

func (k PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) MarshalString added in v0.18.0

func (k PublicKey) MarshalString() (string, error)

func (PublicKey) String added in v0.5.0

func (k PublicKey) String() string

func (*PublicKey) UnmarshalJSON added in v0.18.0

func (k *PublicKey) UnmarshalJSON(s []byte) error

func (*PublicKey) UnmarshalString added in v0.18.0

func (k *PublicKey) UnmarshalString(s string) error

func (*PublicKey) UnmarshalText added in v0.18.0

func (k *PublicKey) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler mainly for use by envconfig.

func (PublicKey) Verify added in v0.5.0

func (k PublicKey) Verify(message []byte, signature []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL