Documentation ¶
Overview ¶
Package ed25519 provides an Ed25519 implementation backed by crypto/ed25519(https://pkg.golang.ir/crypto/ed25519) std package, but using [ed25519consensus](https://pkg.golang.ir/github.com/hdevalence/ed25519consensus) package for signature verification, which conforms to [ZIP 215](https://zips.z.cash/zip-0215) specification, making it suitable for consensus-critical contexts, see [README from ed25519consensus](https://github.com/hdevalence/ed25519consensus) for the explanation.
Index ¶
- Constants
- Variables
- func New(hash crypto.Hash) (*ed25519Crpt, error)
- func NewBatchVerifier() crpt.BatchVerifier
- func SetEd25519Options(context string, addedRandomness bool, verify *ved25519.VerifyOptions)
- type Address
- type BatchVerifier
- type PrivateKey
- func (priv PrivateKey) Bytes() []byte
- func (priv PrivateKey) Equal(o crpt.PrivateKey) bool
- func (priv PrivateKey) KeyType() crpt.KeyType
- func (priv PrivateKey) Public() crpt.PublicKey
- func (priv PrivateKey) Sign(message, digest []byte, hashFunc crypto.Hash, rand io.Reader) (crpt.Signature, error)
- func (priv PrivateKey) SignDigest(digest []byte, hashFunc crypto.Hash, rand io.Reader) (crpt.Signature, error)
- func (priv PrivateKey) SignMessage(message []byte, rand io.Reader) (crpt.Signature, error)
- func (priv PrivateKey) TypedBytes() crpt.TypedPrivateKey
- type PublicKey
- func (pub PublicKey) Address() Address
- func (pub PublicKey) Bytes() []byte
- func (pub PublicKey) Equal(o crpt.PublicKey) bool
- func (pub PublicKey) KeyType() crpt.KeyType
- func (pub PublicKey) TypedBytes() crpt.TypedPublicKey
- func (pub PublicKey) Verify(message, digest []byte, hashFunc crypto.Hash, sig crpt.Signature) (bool, error)
- func (pub PublicKey) VerifyDigest(digest []byte, hashFunc crypto.Hash, sig crpt.Signature) (ok bool, err error)
- func (pub PublicKey) VerifyMessage(message []byte, sig crpt.Signature) (ok bool, err error)
Constants ¶
const ( KeyType = crpt.Ed25519 // 32 bytes PublicKeySize = ved25519.PublicKeySize // 64 bytes PrivateKeySize = ved25519.PrivateKeySize // 64 bytes (The size of a compressed, Edwards25519 point, and a field element. Both of which are 32 bytes.) SignatureSize = ved25519.SignatureSize // 32 bytes private key seeds. (These are the private key representations used by RFC 8032.) SeedSize = 32 // 64 bytes AddressSize = PublicKeySize )
Variables ¶
var ( KeyTypeByte = byte(KeyType) ErrWrongPublicKeySize = fmt.Errorf("%w, should be 32 bytes", crpt.ErrWrongPublicKeySize) ErrWrongPrivateKeySize = fmt.Errorf("%w, should be 64 bytes", crpt.ErrWrongPrivateKeySize) ErrWrongSignatureSize = fmt.Errorf("%w, should be 64 bytes", crpt.ErrWrongSignatureSize) ErrNotEd25519PublicKey = errors.New("not a Ed25519 public key") ErrNotEd25519PrivateKey = errors.New("not a Ed25519 private key") )
Functions ¶
func NewBatchVerifier ¶ added in v0.5.0
func NewBatchVerifier() crpt.BatchVerifier
func SetEd25519Options ¶ added in v0.5.0
func SetEd25519Options(context string, addedRandomness bool, verify *ved25519.VerifyOptions)
SetEd25519Options sets the Ed25519 options used by this package.
See `github.com/oasisprotocol/curve25519-voi/primitives/ed25519.Options` for parameter details.
Types ¶
type BatchVerifier ¶ added in v0.5.0
type BatchVerifier struct {
*ved25519.BatchVerifier
}
BatchVerifier implements batch verification for ed25519.
func (*BatchVerifier) Add ¶ added in v0.5.0
func (b *BatchVerifier) Add(pub crpt.PublicKey, message []byte, sig crpt.Signature) error
type PrivateKey ¶ added in v0.5.0
type PrivateKey ved25519.PrivateKey
Ed25519 32-byte private key + 32-byte public key suffix = 64 bytes See: https://pkg.golang.ir/crypto/ed25519
func (PrivateKey) Bytes ¶ added in v0.5.0
func (priv PrivateKey) Bytes() []byte
Bytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.
func (PrivateKey) Equal ¶ added in v0.5.0
func (priv PrivateKey) Equal(o crpt.PrivateKey) bool
func (PrivateKey) KeyType ¶ added in v0.5.0
func (priv PrivateKey) KeyType() crpt.KeyType
func (PrivateKey) Public ¶ added in v0.5.0
func (priv PrivateKey) Public() crpt.PublicKey
Panics if the private key is not initialized.
func (PrivateKey) Sign ¶ added in v0.5.0
func (priv PrivateKey) Sign(message, digest []byte, hashFunc crypto.Hash, rand io.Reader, ) (crpt.Signature, error)
Sign produces a signature on the provided message. This assumes the privkey is wellformed in the golang format. The first 32 bytes should be random, corresponding to the normal ed25519 private key. The latter 32 bytes should be the compressed public key. If these conditions aren't met, Sign will return an error or produce an incorrect signature.
func (PrivateKey) SignDigest ¶ added in v0.5.0
func (PrivateKey) SignMessage ¶ added in v0.5.0
func (priv PrivateKey) SignMessage(message []byte, rand io.Reader) (crpt.Signature, error)
func (PrivateKey) TypedBytes ¶ added in v0.5.0
func (priv PrivateKey) TypedBytes() crpt.TypedPrivateKey
TypedBytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.
type PublicKey ¶ added in v0.5.0
Ed25519 32-byte public key
func (PublicKey) Address ¶ added in v0.5.0
Address returns TypedPublicKey instead of deriving address from the public key by hashing and returning the last certain bytes, to avoid adding extra space in transactions for public keys.
Address's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.
func (PublicKey) Bytes ¶ added in v0.5.0
Bytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.
func (PublicKey) TypedBytes ¶ added in v0.5.0
func (pub PublicKey) TypedBytes() crpt.TypedPublicKey
TypedBytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.