crypto

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package crypto implements cryptographic operations for ATLYS

Package crypto implements cryptographic signing operations for ATLYS

Index

Constants

View Source
const (
	Ed25519SignatureSize   = 64
	Secp256k1SignatureSize = 65
)

SignatureSize defines the size of signatures in bytes

Variables

This section is empty.

Functions

func AggregateSignatures

func AggregateSignatures(signatures [][]byte, keyType KeyType) ([]byte, error)

AggregateSignatures combines multiple signatures into one

func DeriveKey

func DeriveKey(masterKey []byte, index uint32, keyType KeyType) ([]byte, error)

DeriveKey derives a new key from a master key and index

func SignHash

func SignHash(privateKey []byte, hash []byte, keyType KeyType) ([]byte, error)

SignHash signs a pre-computed hash

func VerifyAggregateSignature

func VerifyAggregateSignature(pubKeys [][]byte, messages [][]byte, signature []byte, keyType KeyType) bool

VerifyAggregateSignature verifies an aggregated signature

func VerifyHashSignature

func VerifyHashSignature(pubKey, hash, signature []byte, keyType KeyType) bool

VerifyHashSignature verifies a signature on a pre-computed hash

Types

type BatchVerifier

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

BatchVerifier handles batch signature verification

func NewBatchVerifier

func NewBatchVerifier(keyType KeyType) *BatchVerifier

NewBatchVerifier creates a new batch signature verifier

func (*BatchVerifier) AddSignature

func (bv *BatchVerifier) AddSignature(pubKey, message, signature []byte) error

AddSignature adds a signature to the batch

func (*BatchVerifier) Verify

func (bv *BatchVerifier) Verify() bool

Verify performs batch signature verification

type DeterministicReader

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

DeterministicReader provides deterministic randomness from a seed

func NewDeterministicReader

func NewDeterministicReader(seed []byte) *DeterministicReader

func (*DeterministicReader) Read

func (r *DeterministicReader) Read(p []byte) (n int, err error)

type Ed25519Signer

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

Ed25519Signer implements Signer for Ed25519

func NewEd25519Signer

func NewEd25519Signer(privateKey []byte) (*Ed25519Signer, error)

NewEd25519Signer creates a new Ed25519 signer

func (*Ed25519Signer) GetAddress

func (s *Ed25519Signer) GetAddress() types.Address

func (*Ed25519Signer) GetPublicKey

func (s *Ed25519Signer) GetPublicKey() []byte

func (*Ed25519Signer) Sign

func (s *Ed25519Signer) Sign(message []byte) ([]byte, error)

Sign signs a message using Ed25519

func (*Ed25519Signer) Verify

func (s *Ed25519Signer) Verify(pubKey, message, signature []byte) bool

Verify verifies an Ed25519 signature

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
	KeyType    KeyType
	Address    types.Address
}

KeyPair represents a cryptographic key pair

func (*KeyPair) Sign

func (kp *KeyPair) Sign(message []byte) ([]byte, error)

Sign signs a message with a private key

func (*KeyPair) Verify

func (kp *KeyPair) Verify(message, signature []byte) bool

Verify verifies a signature with a public key

type KeyStore

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

KeyStore manages cryptographic keys

func NewKeyStore

func NewKeyStore() *KeyStore

NewKeyStore creates a new instance of KeyStore

func (*KeyStore) DeleteKey

func (ks *KeyStore) DeleteKey(address types.Address) error

DeleteKey removes a key pair from the keystore

func (*KeyStore) ExportPrivateKey

func (ks *KeyStore) ExportPrivateKey(address types.Address) (string, error)

ExportPrivateKey exports a private key for a given address

func (*KeyStore) GenerateFromSeed

func (ks *KeyStore) GenerateFromSeed(seed string, keyType KeyType) (*KeyPair, error)

GenerateFromSeed generates a deterministic key pair from a seed phrase

func (*KeyStore) GenerateKeyPair

func (ks *KeyStore) GenerateKeyPair(keyType KeyType) (*KeyPair, error)

GenerateKeyPair creates a new key pair

func (*KeyStore) GetKeyPair

func (ks *KeyStore) GetKeyPair(address types.Address) (*KeyPair, error)

GetKeyPair retrieves a key pair by address

func (*KeyStore) ImportPrivateKey

func (ks *KeyStore) ImportPrivateKey(privateKeyHex string, keyType KeyType) (*KeyPair, error)

ImportPrivateKey imports an existing private key

func (*KeyStore) ListAddresses

func (ks *KeyStore) ListAddresses() []types.Address

ListAddresses returns all addresses in the keystore

type KeyType

type KeyType uint8

KeyType identifies the type of cryptographic key

const (
	KeyTypeEd25519 KeyType = iota
	KeyTypeSecp256k1
)

type MultiSigner

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

MultiSigner handles multi-signature operations

func NewMultiSigner

func NewMultiSigner(threshold uint, publicKeys [][]byte, keyType KeyType) (*MultiSigner, error)

NewMultiSigner creates a new multi-signature handler

func (*MultiSigner) VerifyMultiSig

func (ms *MultiSigner) VerifyMultiSig(message []byte, signatures [][]byte, signerIndexes []uint) bool

VerifyMultiSig verifies a multi-signature

type Signer

type Signer interface {
	Sign(message []byte) ([]byte, error)
	Verify(pubKey, message, signature []byte) bool
	GetPublicKey() []byte
	GetAddress() types.Address
}

Signer interface defines the signing operations

Jump to

Keyboard shortcuts

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