ed25519

package
v0.0.0-...-0354332 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 52

Documentation

Overview

Package ed25519 implements an Ed25519 Verify function for use in consensus-critical contexts. The Verify function is compatible with the particular validation rules around edge cases described in IOTA protocol RFC-0028.

Index

Constants

View Source
const (
	PublicKeySize  = ed25519.PublicKeySize
	SignatureSize  = ed25519.SignatureSize
	PrivateKeySize = ed25519.PrivateKeySize
	SeedSize       = ed25519.SeedSize
)

Variables

View Source
var (
	ErrNotEnoughBytes = ierrors.New("not enough bytes")
)

Functions

func GenerateKey

func GenerateKey() (publicKey PublicKey, privateKey PrivateKey, err error)

GenerateKey creates a public/private key pair.

func Verify

func Verify(publicKey ed25519.PublicKey, message, sig []byte) bool

Verify reports whether sig is a valid signature of message by publicKey. It uses precisely-specified validation criteria (ZIP 215) suitable for use in consensus-critical contexts.

Types

type KeyPair

type KeyPair struct {
	PrivateKey PrivateKey
	PublicKey  PublicKey
}

func GenerateKeyPair

func GenerateKeyPair() (keyPair KeyPair)

type PrivateKey

type PrivateKey [PrivateKeySize]byte

PrivateKey is the type of Ed25519 private keys.

func GeneratePrivateKey

func GeneratePrivateKey() (privateKey PrivateKey, err error)

GenerateKey creates a private key.

func PrivateKeyFromBytes

func PrivateKeyFromBytes(bytes []byte) (result PrivateKey, consumedBytes int, err error)

PrivateKeyFromBytes creates a PrivateKey from the given bytes.

func PrivateKeyFromSeed

func PrivateKeyFromSeed(seed []byte) (result PrivateKey)

PrivateKeyFromSeed calculates a private key from a seed.

func (PrivateKey) Bytes

func (privateKey PrivateKey) Bytes() ([]byte, error)

Bytes returns the privateKey in bytes.

func (PrivateKey) Public

func (privateKey PrivateKey) Public() (result PublicKey)

Public returns the PublicKey corresponding to privateKey.

func (PrivateKey) Seed

func (privateKey PrivateKey) Seed() *Seed

Seed returns the private key seed corresponding to privateKey. It is provided for interoperability with RFC 8032. RFC 8032's private keys correspond to seeds in this package.

func (PrivateKey) Sign

func (privateKey PrivateKey) Sign(data []byte) (result Signature)

Sign signs the message with privateKey and returns a signature.

func (PrivateKey) String

func (privateKey PrivateKey) String() string

String returns a human-readable version of the PrivateKey (base58 encoded).

type PublicKey

type PublicKey [PublicKeySize]byte

PublicKey is the type of Ed25519 public keys.

func NativeToPublicKeys

func NativeToPublicKeys(nativePubKeys []ed25519.PublicKey) (result []PublicKey)

NativeToPublicKeys converts crypto/ed25519 native public keys into a []PublicKey.

func PublicKeyFromBytes

func PublicKeyFromBytes(bytes []byte) (result PublicKey, consumedBytes int, err error)

PublicKeyFromBytes creates a PublicKey from the given bytes.

func PublicKeyFromString

func PublicKeyFromString(s string) (publicKey PublicKey, err error)

PublicKeyFromString parses the given string with base58 encoding and returns a PublicKey.

func RecoverKey

func RecoverKey(key, data, sig []byte) (result PublicKey, err error)

RecoverKey makes sure that key and signature have the correct length and verifies whether sig is a valid signature of data by pub.

func (PublicKey) Bytes

func (publicKey PublicKey) Bytes() ([]byte, error)

Bytes returns the publicKey in bytes.

func (PublicKey) MarshalJSON

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

MarshalJSON serializes public key to JSON as base58 encoded string.

func (PublicKey) String

func (publicKey PublicKey) String() string

String returns a human-readable version of the PublicKey (base58 encoded).

func (PublicKey) ToEd25519

func (publicKey PublicKey) ToEd25519() ed25519.PublicKey

ToEd25519 returns the public key as native crypto/ed25519.PublicKey.

func (*PublicKey) UnmarshalJSON

func (publicKey *PublicKey) UnmarshalJSON(b []byte) error

UnmarshalJSON parses public key from JSON in base58 encoding.

func (PublicKey) VerifySignature

func (publicKey PublicKey) VerifySignature(data []byte, signature Signature) bool

VerifySignature reports whether signature is a valid signature of message by publicKey.

type Seed

type Seed struct {
	// contains filtered or unexported fields
}

Seed is a generator for a deterministic sequence of KeyPairs.

func NewSeed

func NewSeed(optionalSeedBytes ...[]byte) *Seed

NewSeed represents the factory method for a Seed object. It either generates a new random seed or restores an existing one from a sequence of bytes.

func (*Seed) Bytes

func (seed *Seed) Bytes() []byte

Bytes marshals the Seed object into a sequence of Bytes that can be used to later restore the Seed by handing it into the factory method.

func (*Seed) KeyPair

func (seed *Seed) KeyPair(n uint64) (keyPair *KeyPair)

KeyPair retrieves the n'th KeyPair from the Seed.

func (*Seed) String

func (seed *Seed) String() string

String returns a human-readable version of the Seed (base58 encoded).

type Signature

type Signature [SignatureSize]byte
var EmptySignature Signature

func SignatureFromBytes

func SignatureFromBytes(bytes []byte) (result Signature, consumedBytes int, err error)

SignatureFromBytes creates a Signature from the given bytes.

func (Signature) Bytes

func (signature Signature) Bytes() ([]byte, error)

Bytes returns the signature in bytes.

func (Signature) String

func (signature Signature) String() string

String returns a human-readable version of the Signature (base58 encoded).

Jump to

Keyboard shortcuts

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