crypto

package
v0.0.0-...-a039820 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const PrivateKeySize = 32
View Source
const PublicKeySize = 32

Variables

View Source
var TxProofV2DomainSeparatorHash = Keccak256([]byte("TXPROOF_V2")) // HASH_KEY_TXPROOF_V2

Functions

func BytesToScalar

func BytesToScalar(buf []byte) *edwards25519.Scalar

func CompareConsensusPublicKeyBytes

func CompareConsensusPublicKeyBytes(a, b *PublicKeyBytes) int

CompareConsensusPublicKeyBytes Compares public keys in a special consensus specific way

func DeterministicScalar

func DeterministicScalar(entropy []byte) *edwards25519.Scalar

DeterministicScalar consensus way of generating a deterministic scalar from given entropy Slice entropy will have data appended

func GenerateTxProofV1

func GenerateTxProofV1(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature)

func GenerateTxProofV2

func GenerateTxProofV2(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature)

func GetDerivationSharedDataAndViewTagForOutputIndexNoAllocate

func GetDerivationSharedDataAndViewTagForOutputIndexNoAllocate(k PublicKeyBytes, outputIndex uint64, hasher *sha3.HasherState) (edwards25519.Scalar, uint8)

GetDerivationSharedDataAndViewTagForOutputIndexNoAllocate Special version of GetDerivationSharedDataAndViewTagForOutputIndex

func GetDerivationViewTagForOutputIndex

func GetDerivationViewTagForOutputIndex(derivation PublicKey, outputIndex uint64) uint8

func GetEdwards25519Point

func GetEdwards25519Point() *edwards25519.Point

func GetEdwards25519Scalar

func GetEdwards25519Scalar() *edwards25519.Scalar

func GetKeccak256Hasher

func GetKeccak256Hasher() *sha3.HasherState

func HashFastSum

func HashFastSum(hash *sha3.HasherState, b []byte) []byte

HashFastSum sha3.Sum clones the state by allocating memory. prevent that. b must be pre-allocated to the expected size, or larger

func HashToPoint

func HashToPoint(publicKey PublicKey) *edwards25519.Point

func HashToScalar

func HashToScalar(data ...[]byte) *edwards25519.Scalar

func HashToScalarNoAllocate

func HashToScalarNoAllocate(data ...[]byte) edwards25519.Scalar

func HashToScalarNoAllocateSingle

func HashToScalarNoAllocateSingle(data []byte) edwards25519.Scalar

func Keccak256

func Keccak256(data ...[]byte) (result types.Hash)

func Keccak256Single

func Keccak256Single(data []byte) (result types.Hash)

func PooledKeccak256

func PooledKeccak256(data ...[]byte) (result types.Hash)

func PutEdwards25519Point

func PutEdwards25519Point(p *edwards25519.Point)

func PutEdwards25519Scalar

func PutEdwards25519Scalar(s *edwards25519.Scalar)

func PutKeccak256Hasher

func PutKeccak256Hasher(h *sha3.HasherState)

func RandomScalar

func RandomScalar() *edwards25519.Scalar

func VerifyMessageSignature

func VerifyMessageSignature(prefixHash types.Hash, publicKey PublicKey, signature *Signature) bool

func VerifyMessageSignatureSplit

func VerifyMessageSignatureSplit(prefixHash types.Hash, commPublicKey, signPublicKey PublicKey, signature *Signature) bool

VerifyMessageSignatureSplit Allows specifying a different signer key than for the rest. Use VerifyMessageSignature in all other cases

Types

type BinaryTreeHash

type BinaryTreeHash []types.Hash

func (BinaryTreeHash) MainBranch

func (t BinaryTreeHash) MainBranch() (mainBranch []types.Hash)

func (BinaryTreeHash) RootHash

func (t BinaryTreeHash) RootHash() (rootHash types.Hash)

type KeyPair

type KeyPair struct {
	PrivateKey PrivateKey
	PublicKey  PublicKey
}

func NewKeyPairFromPrivate

func NewKeyPairFromPrivate(privateKey PrivateKey) *KeyPair

type PrivateKey

type PrivateKey interface {
	AsSlice() PrivateKeySlice
	AsBytes() PrivateKeyBytes
	AsScalar() *PrivateKeyScalar

	PublicKey() PublicKey

	// GetDerivation derives a secret via a peer PublicKey, ECDH
	GetDerivation(public PublicKey) PublicKey

	// GetDerivationCofactor derives a secret via a peer PublicKey, ECDH, making sure it is in the proper range (*8)
	GetDerivationCofactor(public PublicKey) PublicKey

	String() string
	UnmarshalJSON(b []byte) error
	MarshalJSON() ([]byte, error)
}

func GetDerivationSharedDataAndViewTagForOutputIndex

func GetDerivationSharedDataAndViewTagForOutputIndex(derivation PublicKey, outputIndex uint64) (PrivateKey, uint8)

func GetDerivationSharedDataForOutputIndex

func GetDerivationSharedDataForOutputIndex(derivation PublicKey, outputIndex uint64) PrivateKey

type PrivateKeyBytes

type PrivateKeyBytes [PrivateKeySize]byte
var ZeroPrivateKeyBytes PrivateKeyBytes

func (*PrivateKeyBytes) AsBytes

func (k *PrivateKeyBytes) AsBytes() PrivateKeyBytes

func (*PrivateKeyBytes) AsScalar

func (k *PrivateKeyBytes) AsScalar() *PrivateKeyScalar

func (*PrivateKeyBytes) AsSlice

func (k *PrivateKeyBytes) AsSlice() PrivateKeySlice

func (*PrivateKeyBytes) GetDerivation

func (k *PrivateKeyBytes) GetDerivation(public PublicKey) PublicKey

func (*PrivateKeyBytes) GetDerivationCofactor

func (k *PrivateKeyBytes) GetDerivationCofactor(public PublicKey) PublicKey

func (*PrivateKeyBytes) MarshalJSON

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

func (*PrivateKeyBytes) PublicKey

func (k *PrivateKeyBytes) PublicKey() PublicKey

func (*PrivateKeyBytes) Scan

func (k *PrivateKeyBytes) Scan(src any) error

func (*PrivateKeyBytes) String

func (k *PrivateKeyBytes) String() string

func (*PrivateKeyBytes) UnmarshalJSON

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

func (*PrivateKeyBytes) Value

func (k *PrivateKeyBytes) Value() (driver.Value, error)

type PrivateKeyScalar

type PrivateKeyScalar edwards25519.Scalar

func PrivateKeyFromScalar

func PrivateKeyFromScalar(scalar *edwards25519.Scalar) *PrivateKeyScalar

func (*PrivateKeyScalar) AsBytes

func (p *PrivateKeyScalar) AsBytes() (buf PrivateKeyBytes)

func (*PrivateKeyScalar) AsScalar

func (p *PrivateKeyScalar) AsScalar() *PrivateKeyScalar

func (*PrivateKeyScalar) AsSlice

func (p *PrivateKeyScalar) AsSlice() PrivateKeySlice

func (*PrivateKeyScalar) GetDerivation

func (p *PrivateKeyScalar) GetDerivation(public PublicKey) PublicKey

func (*PrivateKeyScalar) GetDerivationCofactor

func (p *PrivateKeyScalar) GetDerivationCofactor(public PublicKey) PublicKey

func (*PrivateKeyScalar) MarshalJSON

func (p *PrivateKeyScalar) MarshalJSON() ([]byte, error)

func (*PrivateKeyScalar) PublicKey

func (p *PrivateKeyScalar) PublicKey() PublicKey

func (*PrivateKeyScalar) Scalar

func (p *PrivateKeyScalar) Scalar() *edwards25519.Scalar

func (*PrivateKeyScalar) String

func (p *PrivateKeyScalar) String() string

func (*PrivateKeyScalar) UnmarshalJSON

func (p *PrivateKeyScalar) UnmarshalJSON(b []byte) error

type PrivateKeySlice

type PrivateKeySlice []byte

func (*PrivateKeySlice) AsBytes

func (k *PrivateKeySlice) AsBytes() (buf PrivateKeyBytes)

func (*PrivateKeySlice) AsScalar

func (k *PrivateKeySlice) AsScalar() *PrivateKeyScalar

func (*PrivateKeySlice) AsSlice

func (k *PrivateKeySlice) AsSlice() PrivateKeySlice

func (*PrivateKeySlice) GetDerivation

func (k *PrivateKeySlice) GetDerivation(public PublicKey) PublicKey

func (*PrivateKeySlice) GetDerivationCofactor

func (k *PrivateKeySlice) GetDerivationCofactor(public PublicKey) PublicKey

func (*PrivateKeySlice) MarshalJSON

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

func (*PrivateKeySlice) PublicKey

func (k *PrivateKeySlice) PublicKey() PublicKey

func (*PrivateKeySlice) Scan

func (k *PrivateKeySlice) Scan(src any) error

func (*PrivateKeySlice) String

func (k *PrivateKeySlice) String() string

func (*PrivateKeySlice) UnmarshalJSON

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

func (*PrivateKeySlice) Value

func (k *PrivateKeySlice) Value() (driver.Value, error)

type PublicKey

type PublicKey interface {
	AsSlice() PublicKeySlice
	AsBytes() PublicKeyBytes
	AsPoint() *PublicKeyPoint

	String() string
	UnmarshalJSON(b []byte) error
	MarshalJSON() ([]byte, error)
}

func GetKeyImage

func GetKeyImage(pair *KeyPair) PublicKey

type PublicKeyBytes

type PublicKeyBytes [PublicKeySize]byte
var ZeroPublicKeyBytes PublicKeyBytes

func (*PublicKeyBytes) AsBytes

func (k *PublicKeyBytes) AsBytes() PublicKeyBytes

func (*PublicKeyBytes) AsPoint

func (k *PublicKeyBytes) AsPoint() *PublicKeyPoint

func (*PublicKeyBytes) AsSlice

func (k *PublicKeyBytes) AsSlice() PublicKeySlice

func (*PublicKeyBytes) MarshalJSON

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

func (*PublicKeyBytes) Scan

func (k *PublicKeyBytes) Scan(src any) error

func (*PublicKeyBytes) String

func (k *PublicKeyBytes) String() string

func (*PublicKeyBytes) UnmarshalJSON

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

func (*PublicKeyBytes) Value

func (k *PublicKeyBytes) Value() (driver.Value, error)

type PublicKeyPoint

type PublicKeyPoint edwards25519.Point

func PublicKeyFromPoint

func PublicKeyFromPoint(point *edwards25519.Point, _ ...any) *PublicKeyPoint

func (*PublicKeyPoint) Add

func (*PublicKeyPoint) AsBytes

func (k *PublicKeyPoint) AsBytes() (buf PublicKeyBytes)

func (*PublicKeyPoint) AsPoint

func (k *PublicKeyPoint) AsPoint() *PublicKeyPoint

func (*PublicKeyPoint) AsSlice

func (k *PublicKeyPoint) AsSlice() PublicKeySlice

func (*PublicKeyPoint) Cofactor

func (k *PublicKeyPoint) Cofactor() *PublicKeyPoint

func (*PublicKeyPoint) MarshalJSON

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

func (*PublicKeyPoint) Multiply

func (*PublicKeyPoint) Point

func (k *PublicKeyPoint) Point() *edwards25519.Point

func (*PublicKeyPoint) String

func (k *PublicKeyPoint) String() string

func (*PublicKeyPoint) Subtract

func (k *PublicKeyPoint) Subtract(b *PublicKeyPoint) *PublicKeyPoint

func (*PublicKeyPoint) UnmarshalJSON

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

type PublicKeySlice

type PublicKeySlice []byte

func (*PublicKeySlice) AsBytes

func (k *PublicKeySlice) AsBytes() (buf PublicKeyBytes)

func (*PublicKeySlice) AsPoint

func (k *PublicKeySlice) AsPoint() *PublicKeyPoint

func (*PublicKeySlice) AsSlice

func (k *PublicKeySlice) AsSlice() PublicKeySlice

func (*PublicKeySlice) MarshalJSON

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

func (*PublicKeySlice) Scan

func (k *PublicKeySlice) Scan(src any) error

func (*PublicKeySlice) String

func (k *PublicKeySlice) String() string

func (*PublicKeySlice) UnmarshalJSON

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

func (*PublicKeySlice) Value

func (k *PublicKeySlice) Value() (driver.Value, error)

type Signature

type Signature struct {
	// C hash of data in signature, also called e
	C *edwards25519.Scalar
	// R result of the signature, also called s
	R *edwards25519.Scalar
}

Signature Schnorr signature

func CreateMessageSignature

func CreateMessageSignature(prefixHash types.Hash, key PrivateKey) *Signature

func CreateSignature

func CreateSignature(handler SignatureSigningHandler, privateKey PrivateKey) *Signature

CreateSignature produces a Schnorr Signature using H = keccak

func NewSignatureFromBytes

func NewSignatureFromBytes(buf []byte) *Signature

func (*Signature) Bytes

func (s *Signature) Bytes() []byte

func (*Signature) Verify

func (s *Signature) Verify(handler SignatureVerificationHandler, publicKey PublicKey) (ok bool, r *PublicKeyPoint)

Verify checks a Schnorr Signature using H = keccak

type SignatureComm

type SignatureComm struct {
	Hash types.Hash
	Key  PublicKey
	Comm PublicKey
}

SignatureComm Used in normal message signatures

func (*SignatureComm) Bytes

func (s *SignatureComm) Bytes() []byte

type SignatureComm_2

type SignatureComm_2 struct {
	Message types.Hash
	// KeyDerivation D
	KeyDerivation PublicKey
	// RandomPublicKey X
	RandomPublicKey PublicKey
	// RandomDerivation Y
	RandomDerivation PublicKey
	// Separator Domain Separation
	Separator types.Hash
	// TransactionPublicKey R
	TransactionPublicKey PublicKey
	// RecipientViewPublicKey A
	RecipientViewPublicKey  PublicKey
	RecipientSpendPublicKey PublicKey
}

SignatureComm_2 Used in v1/v2 tx proofs

func (*SignatureComm_2) Bytes

func (s *SignatureComm_2) Bytes() []byte

type SignatureComm_2_V1

type SignatureComm_2_V1 struct {
	Message types.Hash
	// KeyDerivation D
	KeyDerivation PublicKey
	// RandomPublicKey X
	RandomPublicKey PublicKey
	// RandomDerivation Y
	RandomDerivation PublicKey
}

SignatureComm_2_V1 Used in v1 tx proofs

func (*SignatureComm_2_V1) Bytes

func (s *SignatureComm_2_V1) Bytes() []byte

type SignatureSigningHandler

type SignatureSigningHandler func(r PrivateKey) []byte

SignatureSigningHandler receives k, inserts it or a pubkey into its data, and produces a []byte buffer for Signing/Verifying

type SignatureVerificationHandler

type SignatureVerificationHandler func(r PublicKey) []byte

SignatureVerificationHandler receives r = pubkey(k), inserts it into its data, and produces a []byte buffer for Signing/Verifying

Jump to

Keyboard shortcuts

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