keys

package
v0.7.11 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EcdsaRLen   = 32
	EcdsaSLen   = 32
	EcdsaMsgLen = 32
)

The Ecdsa signature is the couple (R, S), both R and S are 32 bytes

View Source
const EcdsaSignatureLen = 64

EcdsaSignatureLen is 64 bytes

View Source
const PrivKeyBytesLen = 32

PrivKeyBytesLen are 32-bytes for all supported curvetypes

Variables

View Source
var (
	ErrPrivKeyUndecodable   = errors.New("could not decode privkey")
	ErrPrivKeyLengthInvalid = errors.New("invalid privkey length")
	ErrPrivKeyZero          = errors.New("privkey cannot be 0")
	ErrPubKeyNotOnCurve     = errors.New("pubkey is not on the curve")

	ErrKeyGenSecp256k1Failed = errors.New(
		"keygen: error generating key pair for secp256k1 curve type",
	)
	ErrKeyGenEdwards25519Failed = errors.New(
		"keygen: error generating key pair for edwards25519 curve type",
	)
	ErrKeyGenSecp256r1Failed = errors.New(
		"keygen: error generating key pair for secp256r1 curve type",
	)
	ErrKeyGenPallasFailed = errors.New(
		"keygen: error generating key pair for pallas curve type",
	)
	ErrCurveTypeNotSupported = errors.New("not a supported CurveType")

	ErrSignUnsupportedPayloadSignatureType = errors.New(
		"sign: unexpected payload.SignatureType while signing",
	)
	ErrSignUnsupportedSignatureType = errors.New(
		"sign: unexpected Signature type while signing",
	)
	ErrSignFailed = errors.New("sign: unable to sign")

	ErrVerifyUnsupportedPayloadSignatureType = errors.New(
		"verify: unexpected payload.SignatureType while verifying",
	)
	ErrVerifyUnsupportedSignatureType = errors.New(
		"verify: unexpected Signature type while verifying",
	)
	ErrVerifyFailed = errors.New("verify: verify returned false")
)

Named error types for Keys errors

View Source
var ErrPallasTransactionValidationErr = errors.New("transaction with pallas validation failed")

Functions

func Err

func Err(err error) bool

Err takes an error as an argument and returns whether or not the error is one thrown by the keys package

func ParseSigningPayload

func ParseSigningPayload(rawPayload *types.SigningPayload) (*mina.Transaction, error)

Types

type KeyPair

type KeyPair struct {
	PublicKey  *types.PublicKey `json:"public_key"`
	PrivateKey []byte           `json:"private_key"`
}

KeyPair contains a PrivateKey and its associated PublicKey

func GenerateKeypair

func GenerateKeypair(curve types.CurveType) (*KeyPair, error)

GenerateKeypair returns a Keypair of a specified CurveType

func ImportPrivateKey

func ImportPrivateKey(privKeyHex string, curve types.CurveType) (*KeyPair, error)

ImportPrivateKey returns a Keypair from a hex-encoded privkey string

func (*KeyPair) IsValid

func (k *KeyPair) IsValid() error

IsValid checks the validity of a KeyPair.

func (*KeyPair) MarshalJSON

func (k *KeyPair) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default JSON marshaler and encodes bytes as hex instead of base64.

func (*KeyPair) Signer

func (k *KeyPair) Signer() (Signer, error)

Signer returns the constructs a Signer for the KeyPair.

func (*KeyPair) UnmarshalJSON

func (k *KeyPair) UnmarshalJSON(b []byte) error

UnmarshalJSON overrides the default JSON unmarshaler and decodes bytes from hex instead of base64.

type PayloadFields

type PayloadFields struct {
	To         string  `json:"to"`
	From       string  `json:"from"`
	Fee        string  `json:"fee"`
	Amount     *string `json:"amount,omitempty"`
	Nonce      string  `json:"nonce"`
	ValidUntil *string `json:"valid_until,omitempty"`
	Memo       *string `json:"memo,omitempty"`
}

type Signer

type Signer interface {
	PublicKey() *types.PublicKey
	Sign(payload *types.SigningPayload, sigType types.SignatureType) (*types.Signature, error)
	Verify(signature *types.Signature) error
}

Signer is an interface for different curve signers

type SignerEdwards25519

type SignerEdwards25519 struct {
	KeyPair *KeyPair
}

SignerEdwards25519 is initialized from a keypair

func (*SignerEdwards25519) PublicKey

func (s *SignerEdwards25519) PublicKey() *types.PublicKey

PublicKey returns the PublicKey of the signer

func (*SignerEdwards25519) Sign

func (s *SignerEdwards25519) Sign(
	payload *types.SigningPayload,
	sigType types.SignatureType,
) (*types.Signature, error)

Sign arbitrary payloads using a KeyPair

func (*SignerEdwards25519) Verify

func (s *SignerEdwards25519) Verify(signature *types.Signature) error

Verify verifies a Signature, by checking the validity of a Signature, the SigningPayload, and the PublicKey of the Signature.

type SignerPallas

type SignerPallas struct {
	KeyPair *KeyPair
}

func (*SignerPallas) PublicKey

func (s *SignerPallas) PublicKey() *types.PublicKey

func (*SignerPallas) Sign

func (s *SignerPallas) Sign(
	payload *types.SigningPayload,
	sigType types.SignatureType,
) (*types.Signature, error)

Sign transaction payloads using a KeyPair

func (*SignerPallas) Verify

func (s *SignerPallas) Verify(signature *types.Signature) error

Verify verifies a Signature, by checking the validity of a Signature, the SigningPayload, and the PublicKey of the Signature.

type SignerSecp256k1

type SignerSecp256k1 struct {
	KeyPair *KeyPair
}

SignerSecp256k1 is initialized from a keypair

func (*SignerSecp256k1) PublicKey

func (s *SignerSecp256k1) PublicKey() *types.PublicKey

PublicKey returns the PublicKey of the signer

func (*SignerSecp256k1) Sign

func (s *SignerSecp256k1) Sign(
	payload *types.SigningPayload,
	sigType types.SignatureType,
) (*types.Signature, error)

Sign arbitrary payloads using a KeyPair

func (*SignerSecp256k1) Verify

func (s *SignerSecp256k1) Verify(signature *types.Signature) error

Verify verifies a Signature, by checking the validity of a Signature, the SigningPayload, and the PublicKey of the Signature.

type SignerSecp256r1

type SignerSecp256r1 struct {
	KeyPair *KeyPair
}

SignerSecp256r1 is initialized from a keypair

func (*SignerSecp256r1) PublicKey

func (s *SignerSecp256r1) PublicKey() *types.PublicKey

PublicKey returns the PublicKey of the signer

func (*SignerSecp256r1) Sign

func (s *SignerSecp256r1) Sign(
	payload *types.SigningPayload,
	sigType types.SignatureType,
) (*types.Signature, error)

Sign arbitrary payloads using a KeyPair with specific sigType. Currently, we only support sigType types.Ecdsa for secp256r1 and the signature format is R || S.

func (*SignerSecp256r1) Verify

func (s *SignerSecp256r1) Verify(signature *types.Signature) error

Verify verifies a Signature, by checking the validity of a Signature, the SigningPayload, and the PublicKey of the Signature.

type SigningPayload

type SigningPayload struct {
	Payment *PayloadFields `json:"payment"`
}

Jump to

Keyboard shortcuts

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