crypto

package
v0.0.0-...-132da2d Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LengthHeaderSize   = 4
	MaxDataSize        = 1024
	ChallengeSize      = 32
	Poly1305TagSize    = 16
	FrameSize          = MaxDataSize + LengthHeaderSize
	EncryptedFrameSize = Poly1305TagSize + FrameSize
	AEADKeySize        = chacha20poly1305.KeySize
	AEADNonceSize      = chacha20poly1305.NonceSize
	TwoAEADKeySize     = 2 * AEADKeySize
	HKDFSize           = TwoAEADKeySize + ChallengeSize // 2 keys and challenge
)
View Source
const (
	BLS12381PrivKeySize   = 32
	BLS12381PubKeySize    = 48
	BLS12381SignatureSize = 96
)
View Source
const (
	Ed25519PrivKeySize   = ed25519.PrivateKeySize
	Ed25519PubKeySize    = ed25519.PublicKeySize
	Ed25519SignatureSize = ed25519.SignatureSize
)
View Source
const (
	SECP256K1PrivKeySize   = 32
	SECP256K1PubKeySize    = 33
	SECP256K1SignatureSize = 64
)
View Source
const (
	// the number of bytes in an address
	AddressSize = 20
)
View Source
const (
	ETHSECP256K1PubKeySize = 64 // represents the uncompressed SECP256K1 public key size
)
View Source
const (
	HashSize = sha256.Size
)
View Source
const (
	KeyStoreName = "keystore.json"
)

Variables

View Source
var (
	DisableCache      = false
	SignatureCache, _ = bigcache.New(context.Background(), bigcache.Config{
		Shards:             1024,
		LifeWindow:         5 * time.Minute,
		CleanWindow:        20 * time.Second,
		MaxEntriesInWindow: 1_00_000,
		MaxEntrySize:       1000,
		HardMaxCacheSize:   250,
		Verbose:            false,
	})
)
View Source
var DiscriminantCache = map[string]*big.Int{}
View Source
var File_crypto_proto protoreflect.FileDescriptor
View Source
var (
	MaxHash = bytes.Repeat([]byte{0xFF}, HashSize)
)
View Source
var Residues = []int{}/* 5760 elements not displayed */

Public to allow others to import

View Source
var SieveInfo = []Pair{}/* 6536 elements not displayed */

Public to allow others to import

Functions

func BytesToBLS12381Point

func BytesToBLS12381Point(bz []byte) (kyber.Point, error)

BytesToBLS12381Point() creates a new G1 point on BLS12-381 curve which is the public key of the pair

func CheckCache

func CheckCache(pk PublicKeyI, msg, sig []byte) (found bool, addToCache func())

CheckCache() is a convenience function that checks the signature cache for a combination and returns a callback for the caller to easily add the signature to the cache

func Ed25519PrivateKeyToCurve25519

func Ed25519PrivateKeyToCurve25519(pk ed25519.PrivateKey) []byte

Ed25519PrivateKeyToCurve25519 hashes the Ed25519 private key seed and extracts the first 32 bytes to form a Curve25519 scalar, which is compatible with Curve25519 operations This conversion allows the use of a single cryptographic key pair Ed25519 for both signing and key exchange

func Ed25519PublicKeyToCurve25519

func Ed25519PublicKeyToCurve25519(pk ed25519.PublicKey) ([]byte, error)

Ed25519PublicKeyToCurve25519 interprets the Ed25519 public key as a point on the Edwards25519 curve and converts it to a Curve25519 public key in Montgomery form, suitable for X25519 encryption This conversion allows the use of a single cryptographic key pair Ed25519 for both signing and key exchange

func GenerateVDF

func GenerateVDF(seed []byte, iterations int, stop <-chan struct{}) (out []byte, proofBytes []byte)

GenerateVDF() executes a verifiable delay function given a seed and a number of iterations

func HKDFSecretsAndChallenge

func HKDFSecretsAndChallenge(dhSecret []byte, ePub, ePeerPub []byte) (send cipher.AEAD, receive cipher.AEAD, challenge *[32]byte, err error)

HKDFSecretsAndChallenge generates shared encryption keys and a unique challenge using HKDF (HMAC-based Key Derivation Function) from a Diffie-Hellman shared secret

Parameters: - dhSecret: the shared secret derived from a Diffie-Hellman key exchange - ePub: the ephemeral local public key, this should just be a temporary public key only used for authentication - ePeerPub: the ephemeral peer's public key, this should just be a temporary public key only used for authentication

Returns: - send: an AEAD (Authenticated Encryption with Associated Data) cipher for outgoing messages - receive: an AEAD (Authenticated Encryption with Associated Data) cipher for incoming messages - challenge: a unique 32-byte challenge used for authentication purposes - err: error if key derivation or cipher creation fails

Process: 1. Uses the shared DH secret as input to HKDF to derive multiple cryptographic keys 2. Compares local and peer public keys to determine which key is for sending vs. receiving 3. Populates `challenge`, `sendSecret`, and `receiveSecret` from the HKDF buffer 4. Initializes AEAD ciphers (ChaCha20-Poly1305) for sending and receiving messages

func Hash

func Hash(msg []byte) []byte

Hash() executes the global hashing algorithm on input bytes

func HashString

func HashString(msg []byte) string

HashString() returns the hex byte version of a hash

func Hasher

func Hasher() hash.Hash

Hasher() returns the global hashing algorithm used

func MaxBitmapSize

func MaxBitmapSize(numValidators uint64) int

func MerkleTree

func MerkleTree(items [][]byte) (root []byte, store [][]byte, err error)

MerkleTree creates a merkle tree from a slice of bytes. A linear slice was chosen since it uses about half as much memory as a tree example: items = {a, b, c, d} -> store = {H(a), H(b), H(c), H(d), H(H(a),H(b)), H(H(c),H(d)), H(H(H(a),H(b)),H(H(c),H(d))) }

func NewDiscriminant

func NewDiscriminant(seed []byte) *big.Int

NewDiscriminant generates a 2048-bit discriminant using a seed The discriminant % 8 == 7 and is a negated random prime p between 13 - 2^4096

func PrivateKeyToFile

func PrivateKeyToFile(key PrivateKeyI, filepath string) error

PrivateKeyToFile() writes a private key to a file located at filepath

func PubIsBlacklisted

func PubIsBlacklisted(pubKey []byte) bool

PubIsBlacklisted() prevents public keys that exploit vulnerabilities in 25519 -> x25519 conversion Reject small-order points early to prevent vulnerabilities from weak points that could be exploited in cryptographic operations, as recommended in the research (https://eprint.iacr.org/2017/806.pdf)

func SharedSecret

func SharedSecret(peerPublicKey, private []byte) ([]byte, error)

SharedSecret function takes ed25519 public and private keys, converts them to Curve25519-compatible keys, and performs a Diffie-Hellman-style key exchange with X25519 - meaning both peers compute exact pseudorandom bytes from their peersPublicKey and their local private key without transmitting the secret over the wire

func ShortHash

func ShortHash(msg []byte) []byte

ShortHash() executes the global hashing algorithm on input bytes and truncates the output to 20 bytes

func ShortHashString

func ShortHashString(msg []byte) string

ShortHashString() returns the hex byte version of a short hash

func VerifyVDF

func VerifyVDF(seed, out, proof []byte, iterations int) bool

VerifyVDF() verifies VDF bytes given a seed and iterations

Types

type Address

type Address []byte

Address represents a short version of a public key that pairs to a users secret private key Addresses are the most used identity in the blockchain state due to their hash collision resistant property

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes() casts the address value back to a byte slice

func (Address) Equals

func (a Address) Equals(e AddressI) bool

Equals() compares two address objects and returns true if they're equal

func (Address) Marshal

func (a Address) Marshal() ([]byte, error)

Marshal() implements the proto.Marshaller interface

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON() is the address implementation of json.Marshaller interface

func (Address) String

func (a Address) String() string

String() returns the hex string representation of an address

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON() is the address implementation of json.Marshaller interface

type AddressI

type AddressI interface {
	// Marshal() models the protobuf.Marshaller interface
	Marshal() ([]byte, error)
	// Bytes() casts the public key to bytes
	Bytes() []byte
	// String() returns the hex string representation
	String() string
	Equals(AddressI) bool
}

AddressI is an interface model for the short version of the Public Key

func NewAddress

func NewAddress(b []byte) AddressI

NewAddress() creates a new address object from bytes by assigning bytes to the underlying address object

func NewAddressFromBytes

func NewAddressFromBytes(bz []byte) AddressI

NewAddressFromBytes() casts bytes as an AddressI interface

func NewAddressFromString

func NewAddressFromString(hexString string) (AddressI, error)

NewAddressFromString() returns the hex string implementation of an AddressI interface

type BLS12381MultiPublicKey

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

BLS12381MultiPublicKey is an aggregated public key created by combining multiple BLS public keys from different signers This combined key is used to verify an aggregated signature, confirming that a quorum (or all) of the original signers have participated without needing to verify each signer individually

func (*BLS12381MultiPublicKey) AddSigner

func (b *BLS12381MultiPublicKey) AddSigner(signature []byte, index int) error

AddSigner() adds a signature to the list to later be aggregated, the index represents the signer's index on the fixed order of the public key list

func (*BLS12381MultiPublicKey) AggregateSignatures

func (b *BLS12381MultiPublicKey) AggregateSignatures() ([]byte, error)

AggregateSignatures() aggregates multiple signatures into a single 96 byte signature

func (*BLS12381MultiPublicKey) Bitmap

func (b *BLS12381MultiPublicKey) Bitmap() []byte

Bitmap() returns a bitfield where each bit represents the signing status of a specific signer in the public key list. A set bit (1) indicates the signer at that index signed, while a cleared bit (0) indicates they did not

func (*BLS12381MultiPublicKey) Copy

Copy() creates a safe copy of the MultiPublicKey given a list of public keys

func (*BLS12381MultiPublicKey) PublicKeys

func (b *BLS12381MultiPublicKey) PublicKeys() (keys []PublicKeyI)

PublicKeys() returns the ordered list of public keys from the bitmap

func (*BLS12381MultiPublicKey) Reset

func (b *BLS12381MultiPublicKey) Reset()

Reset() clears the mask and signature fields of the MultiPublicKey for reuse

func (*BLS12381MultiPublicKey) SetBitmap

func (b *BLS12381MultiPublicKey) SetBitmap(bm []byte) error

SetBitmap() is used to set the mask of a BLS Multi key

func (*BLS12381MultiPublicKey) SignerEnabledAt

func (b *BLS12381MultiPublicKey) SignerEnabledAt(i int) (bool, error)

func (*BLS12381MultiPublicKey) VerifyBytes

func (b *BLS12381MultiPublicKey) VerifyBytes(msg, sig []byte) bool

VerifyBytes() verifies a digital signature given the original message payload and the signature out

type BLS12381PrivateKey

type BLS12381PrivateKey struct {
	kyber.Scalar
	// contains filtered or unexported fields
}

BLS12381PrivateKey is a private key wrapper implementation that satisfies the PrivateKeyI interface Boneh-Lynn-Shacham (BLS) signature scheme enables compact, aggregable digital signatures for secure, verifiable messages between multiple parties

func (*BLS12381PrivateKey) Bytes

func (b *BLS12381PrivateKey) Bytes() []byte

Bytes() gives the protobuf bytes representation of the private key

func (*BLS12381PrivateKey) Equals

func (b *BLS12381PrivateKey) Equals(i PrivateKeyI) bool

Equals() compares two private key objects and returns if they are equal

func (*BLS12381PrivateKey) MarshalJSON

func (b *BLS12381PrivateKey) MarshalJSON() ([]byte, error)

MarshalJSON() is the json.Marshaller implementation for the BLS12381PrivateKey object

func (*BLS12381PrivateKey) PublicKey

func (b *BLS12381PrivateKey) PublicKey() PublicKeyI

PublicKey() returns the individual public key that pairs with this BLS private key for basic signature verification

func (*BLS12381PrivateKey) Sign

func (b *BLS12381PrivateKey) Sign(msg []byte) []byte

Sign() digitally signs a message and returns the signature output

func (*BLS12381PrivateKey) String

func (b *BLS12381PrivateKey) String() string

String() returns the hex string representation of the private key

func (*BLS12381PrivateKey) UnmarshalJSON

func (b *BLS12381PrivateKey) UnmarshalJSON(bz []byte) (err error)

UnmarshalJSON() is the json.Unmarshaler implementation for the BLS12381PrivateKey object

type BLS12381PublicKey

type BLS12381PublicKey struct {
	kyber.Point
	// contains filtered or unexported fields
}

BLS12381PublicKey is a public key wrapper implementation that satisfies the PublicKeyI interface Boneh-Lynn-Shacham (BLS) signature scheme enables compact, aggregable digital signatures for secure, verifiable messages between multiple parties

func NewBLS12381PublicKey

func NewBLS12381PublicKey(publicKey kyber.Point) *BLS12381PublicKey

NewBLSPublicKey creates a new BLSPublicKey reference from a kyber point

func (*BLS12381PublicKey) Address

func (b *BLS12381PublicKey) Address() AddressI

Address() returns the short version of the public key

func (*BLS12381PublicKey) Bytes

func (b *BLS12381PublicKey) Bytes() []byte

Bytes() returns the protobuf bytes representation of the public key

func (*BLS12381PublicKey) Equals

func (b *BLS12381PublicKey) Equals(i PublicKeyI) bool

Equals() compares two public key objects and returns true if they are equal

func (*BLS12381PublicKey) MarshalJSON

func (b *BLS12381PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON() implements the json.Marshaller interface for the BLS12381PublicKey

func (*BLS12381PublicKey) String

func (b *BLS12381PublicKey) String() string

String() returns the hex string representation of the public key

func (*BLS12381PublicKey) UnmarshalJSON

func (b *BLS12381PublicKey) UnmarshalJSON(bz []byte) (err error)

UnmarshalJSON() implements the json.Unmarshaler interface for the BLS12381PublicKey

func (*BLS12381PublicKey) VerifyBytes

func (b *BLS12381PublicKey) VerifyBytes(msg []byte, sig []byte) (valid bool)

VerifyBytes() verifies an individual BLS signature given a message and the signature out

type BatchTuple

type BatchTuple struct {
	PublicKey PublicKeyI // the public key associated with the batch tuple
	Message   []byte     // the unique message payload
	Signature []byte     // the digital signature that corresponds to the message and public key
	// contains filtered or unexported fields
}

BatchTuple is a convenient structure to validate the batch

func (*BatchTuple) Key

func (bt *BatchTuple) Key() string

Key() returns a unique string key for the cache

type BatchVerifier

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

BatchVerifier is an efficient, multi-threaded, batch verifier for many common keys

func NewBatchVerifier

func NewBatchVerifier(noOp ...bool) (b *BatchVerifier)

NewBatchVerifier() constructs a batch verifier

func (*BatchVerifier) Add

func (b *BatchVerifier) Add(pk PublicKeyI, publicKey, message, signature []byte) (err error)

Add() adds a tuple to the batch verifier

func (*BatchVerifier) Verify

func (b *BatchVerifier) Verify() (badIndices []int)

Verify() returns the indices of bad signatures (if any)

type BigIntPool

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

func NewBigIntPool

func NewBigIntPool() *BigIntPool

NewBigIntPool() constructs a big int pool

func (*BigIntPool) New

func (bp *BigIntPool) New() (b *big.Int)

New() pops a bigInt from the list

func (*BigIntPool) Recycle

func (bp *BigIntPool) Recycle(ints ...*big.Int)

Recycle releases a big.int to the pool

type ClassGroup

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

ClassGroup is a set of equivalence classes of certain algebraic objects, like ideals or binary quadratic forms The important equations are -> (ax^2 + bxy +cy^2) and (b^2 - 4ac = Discriminant) ClassGroup provides operations for class groups of quadratic imaginary fields, which form the basis for constructing Verifiable Delay Functions These groups enable efficient sequential computations with fast verification, leveraging their cryptographic hardness properties Unlike RSA-based VDFs, class groups don’t require a trusted setup

func CloneClassGroup

func CloneClassGroup(cg *ClassGroup) *ClassGroup

CloneClassGroup() creates a shallow copy of the class group

func NewClassGroup

func NewClassGroup(a, b, c *big.Int) *ClassGroup

NewClassGroup() is a constructor for the class group object

func (*ClassGroup) BigPow

func (group *ClassGroup) BigPow(z *big.Int) *ClassGroup

BigPow() executes an exponential function (group^n) on a class group and returns the resulting class group

func (*ClassGroup) Decode

func (group *ClassGroup) Decode(bz []byte, discriminant *big.Int) (err error)

Encode() converts the bytes into ClassGroup

func (*ClassGroup) Discard

func (group *ClassGroup) Discard()

Discard() recycles the big ints used for the class group

func (*ClassGroup) Discriminant

func (group *ClassGroup) Discriminant() *big.Int

The discriminant is a constant and may be calculated from a,b,c D = b^2-4ac

func (*ClassGroup) Encode

func (group *ClassGroup) Encode() (bz []byte)

Encode() converts the ClassGroup into bytes

func (*ClassGroup) Equal

func (group *ClassGroup) Equal(other *ClassGroup) bool

Equal() compares two ClassGroups using their underlying values and returns true if they are equivalent

func (*ClassGroup) Identity

func (group *ClassGroup) Identity() *ClassGroup

Identity() returns the element that, when combined with any other element in the group, leaves the other element unchanged

func (*ClassGroup) Multiply

func (group *ClassGroup) Multiply(other *ClassGroup) *ClassGroup

Multiply performs multiplication of two elements from the class group and returns the resulting class group element NOTE: this function re-uses big.int instances for memory efficiency so the variable names won't match the commented equations

func (*ClassGroup) Normalized

func (group *ClassGroup) Normalized() *ClassGroup

Normalized() ensures that the coefficient b is always in the range -a < b <= a making subsequent computations, such as reductions or multiplications more straightforward by starting from a consistent state

func (*ClassGroup) Pow

func (group *ClassGroup) Pow(n int64) *ClassGroup

Pow() executes an exponential function (group^n) on a class group and returns the resulting class group

func (*ClassGroup) Reduced

func (group *ClassGroup) Reduced() *ClassGroup

Reduced() transforms a given class group element into a more compact and canonical representation of the group element reduction ensures that (a <= c) && (b >= 0 when a == c) This creates smaller coefficients to optimize arithmetic operations

func (*ClassGroup) Square

func (group *ClassGroup) Square() *ClassGroup

Square() executes a pow(2) operation on the class group

type DeleteOpts

type DeleteOpts struct {
	Address  []byte
	Nickname string
}

type ED25519PrivateKey

type ED25519PrivateKey struct{ ed25519.PrivateKey }

ED25519PrivateKey is the private key of a cryptographic key pair used in elliptic curve signing and verification, based on the Curve25519 elliptic curve It is used to create 'unique' digital signatures of messages

func (*ED25519PrivateKey) Bytes

func (p *ED25519PrivateKey) Bytes() []byte

Bytes() casts the private key to bytes

func (*ED25519PrivateKey) Equals

func (p *ED25519PrivateKey) Equals(key PrivateKeyI) bool

Equals() compares two private key objects and returns true if they are equal

func (*ED25519PrivateKey) MarshalJSON

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

MarshalJSON() implements the json.Marshaller interface for ED25519PrivateKey

func (*ED25519PrivateKey) PublicKey

func (p *ED25519PrivateKey) PublicKey() PublicKeyI

PublicKey() returns the public key that pairs with this private key object

func (*ED25519PrivateKey) Sign

func (p *ED25519PrivateKey) Sign(msg []byte) []byte

Sign() returns the digital signature out of an Ed25519 private key sign function given a message

func (*ED25519PrivateKey) String

func (p *ED25519PrivateKey) String() string

String() returns the hex string representation of the private key

func (*ED25519PrivateKey) UnmarshalJSON

func (p *ED25519PrivateKey) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON() implements the json.Marshaller interface for ED25519PrivateKey

type ED25519PublicKey

type ED25519PublicKey struct{ ed25519.PublicKey }

ED25519PublicKey is the public key of a cryptographic key pair used in elliptic curve signing and verification, based on the Curve25519 elliptic curve It is used to verify ownership of the private key as well as validate digital signatures created by the private key

func NewPublicKeyED25519

func NewPublicKeyED25519(publicKey ed25519.PublicKey) *ED25519PublicKey

NewPublicKeyED25519() returns a ED25519PublicKey reference that satisfies the PublicKeyI interface

func (*ED25519PublicKey) Address

func (p *ED25519PublicKey) Address() AddressI

Address() returns the short version of the public key

func (*ED25519PublicKey) Bytes

func (p *ED25519PublicKey) Bytes() []byte

Bytes() casts the public key to bytes

func (*ED25519PublicKey) Equals

func (p *ED25519PublicKey) Equals(i PublicKeyI) bool

Equals() compares two public key objects and returns if the two are equal

func (*ED25519PublicKey) MarshalJSON

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

MarshalJSON() implements the json.Marshaller interface for ED25519PublicKey

func (*ED25519PublicKey) String

func (p *ED25519PublicKey) String() string

String() returns the hex string representation of the public key

func (*ED25519PublicKey) UnmarshalJSON

func (p *ED25519PublicKey) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON() implements the json.Unmarshaler interface for ED25519PublicKey

func (*ED25519PublicKey) VerifyBytes

func (p *ED25519PublicKey) VerifyBytes(msg []byte, sig []byte) (valid bool)

VerifyBytes() validates a digital signature was signed by the paired private key given the message signed

type ETHSECP256K1PrivateKey

type ETHSECP256K1PrivateKey struct {
	SECP256K1PrivateKey
}

func BytesToEthSECP256K1Private

func BytesToEthSECP256K1Private(b []byte) (*ETHSECP256K1PrivateKey, error)

BytesToEthSECP256K1Private() converts bytes to SECP256K1 private key using go-ethereum

func (*ETHSECP256K1PrivateKey) PublicKey

func (s *ETHSECP256K1PrivateKey) PublicKey() PublicKeyI

EthPublicKey() returns the ethereum public pair to this private key

type ETHSECP256K1PublicKey

type ETHSECP256K1PublicKey struct {
	*ecdsa.PublicKey
}

ETHSECP256K1PublicKey is the ethereum variant of the public key of a cryptographic key pair used in elliptic curve signing and verification, based on the SECP256K1 elliptic curve, it is used to verify ownership of the private key as well as validate digital signatures created by the private key

func BytesToEthSECP256K1Public

func BytesToEthSECP256K1Public(b []byte) (*ETHSECP256K1PublicKey, error)

BytesToEthSECP256K1Public() returns ETHSECP256K1PublicKey from bytes

func (*ETHSECP256K1PublicKey) Address

func (s *ETHSECP256K1PublicKey) Address() AddressI

Address() returns the short version of the public key

func (*ETHSECP256K1PublicKey) Bytes

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

Bytes() returns the byte representation of the Public Key

func (*ETHSECP256K1PublicKey) BytesWithPrefix

func (s *ETHSECP256K1PublicKey) BytesWithPrefix() []byte

Bytes() returns the byte representation of the Public Key

func (*ETHSECP256K1PublicKey) Equals

func (s *ETHSECP256K1PublicKey) Equals(i PublicKeyI) bool

Equals() compares two ETHSECP256K1PublicKey objects and returns true if they're equal

func (*ETHSECP256K1PublicKey) MarshalJSON

func (s *ETHSECP256K1PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON() is the json.Marshaller implementation for ETHSECP256K1PublicKey

func (*ETHSECP256K1PublicKey) String

func (s *ETHSECP256K1PublicKey) String() string

String() returns the hex string representation of the public key

func (*ETHSECP256K1PublicKey) UnmarshalJSON

func (s *ETHSECP256K1PublicKey) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON() is the json.Unmarshaler implementation for ETHSECP256K1PublicKey

func (*ETHSECP256K1PublicKey) VerifyBytes

func (s *ETHSECP256K1PublicKey) VerifyBytes(msg []byte, sig []byte) (valid bool)

VerifyBytes() returns true if the digital signature is valid for this public key and the given message

type EncryptedPrivateKey

type EncryptedPrivateKey struct {
	PublicKey   string `json:"publicKey"`
	Salt        string `json:"salt"`
	Encrypted   string `json:"encrypted"`
	KeyAddress  string `json:"keyAddress"`            // TODO: better naming
	KeyNickname string `json:"keyNickname,omitempty"` // TODO: better naming
}

EncryptedPrivateKey represents an encrypted form of a private key, including the public key, salt used in key derivation, and the encrypted private key itself

func EncryptPrivateKey

func EncryptPrivateKey(publicKey, privateKey, password []byte, address string) (*EncryptedPrivateKey, error)

EncryptPrivateKey creates an encrypted private key by generating a random salt and deriving an encryption key with the KDF, and finally encrypting key using AES-GCM

type GetKeyGroupOpts

type GetKeyGroupOpts struct {
	Address  []byte
	Nickname string
}

type ImportOpts

type ImportOpts struct {
	Address  []byte
	Nickname string
}

type ImportRawOpts

type ImportRawOpts struct {
	Nickname string
}

type KeyGroup

type KeyGroup struct {
	Address    AddressI    // short version of the public key
	PublicKey  PublicKeyI  // the public code that can cryptographically verify signatures from the private key
	PrivateKey PrivateKeyI // the secret code that is capable of producing digital signatures
}

KeyGroup is a structure that holds the Address and PublicKey that corresponds to PrivateKey

func NewKeyGroup

func NewKeyGroup(pk PrivateKeyI) *KeyGroup

NewKeyGroup() generates a public key and address that pairs with the private key

func (*KeyGroup) UnmarshalJSON

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

UnmarshalJSON() implements the json.unmarshaler interface for Keygroup

type Keystore

type Keystore struct {
	AddressMap  map[string]*EncryptedPrivateKey `json:"addressMap"`            // address -> EncriptedPrivateKey
	NicknameMap map[string]string               `json:"nicknameMap,omitempty"` // nickname -> Address
}

Keystore() represents a lightweight database of private keys that are encrypted

func NewKeystoreFromFile

func NewKeystoreFromFile(dataDirPath string) (*Keystore, error)

NewKeystoreFromFile() creates a new keystore object from a file

func NewKeystoreInMemory

func NewKeystoreInMemory() *Keystore

NewKeystoreInMemory() creates a new in memory keystore

func (*Keystore) DeleteKey

func (ks *Keystore) DeleteKey(opts DeleteOpts)

DeleteKey() removes a private key from the store given an address and/or nickname

func (*Keystore) GetKey

func (ks *Keystore) GetKey(address []byte, password string) (PrivateKeyI, error)

GetKey() returns the PrivateKeyI interface for an address and decrypts it using the password

func (*Keystore) GetKeyGroup

func (ks *Keystore) GetKeyGroup(password string, opts GetKeyGroupOpts) (*KeyGroup, error)

GetKeyGroup() returns the full keygroup for an address or nickname and decrypts the private key using the password

func (*Keystore) Import

func (ks *Keystore) Import(encrypted *EncryptedPrivateKey, opts ImportOpts) error

Import() imports an encrypted private key to the store

func (*Keystore) ImportRaw

func (ks *Keystore) ImportRaw(privateKeyBytes []byte, password string, opts ImportRawOpts) (address string, err error)

ImportRaw() imports a non-encrypted private key to the store, but encrypts it given a password

func (*Keystore) SaveToFile

func (ks *Keystore) SaveToFile(dataDirPath string) error

SaveToFile() persists the keystore to a filepath

type MultiPublicKeyI

type MultiPublicKeyI interface {
	AggregateSignatures() ([]byte, error)
	// VerifyBytes() verifies a digital aggregate signature from multiple signers
	VerifyBytes(msg, aggregatedSignature []byte) bool
	// AddSigner() is used to track signers by setting a bit at the index position (from the pre-created public key list)
	AddSigner(signature []byte, index int) error
	// SignerEnabledAt() returns true if a signer is enabled at a certain bit
	SignerEnabledAt(i int) (bool, error)
	// PublicKeys() returns the list of public keys
	PublicKeys() (keys []PublicKeyI)
	// SetBitmap() loads the values of a bitmap into the MultiPublicKey
	SetBitmap(bm []byte) error
	// Bitmap() returns a clone of the bitmap of the MPK
	// The bitmap is used to track who signed or not
	Bitmap() []byte
	// Copy() returns a safe clone of the MPK
	Copy() MultiPublicKeyI
	// Reset() resets the PublicKey list and the Bitmap values
	Reset()
}

MultiPublicKeyI is an interface model for a multi-signature public key, representing multiple signers in a single structure It allows aggregation of individual signatures, validation of aggregated signatures, and management of signers through a bitmap that tracks which participants have signed

func NewMultiBLSFromPoints

func NewMultiBLSFromPoints(publicKeys []kyber.Point, bitmap []byte) (MultiPublicKeyI, error)

NewMultiBLSFromPoints() creates a multi public key from a list of G1 points on a BLS12381 curve

type Pair

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

type PrivateKeyI

type PrivateKeyI interface {
	Bytes() []byte
	Sign(msg []byte) []byte
	PublicKey() PublicKeyI
	// String() returns the hex string representation
	String() string
	Equals(PrivateKeyI) bool
	// models the json.Marshaller encoding interface
	json.Marshaler
	// models the json.Unmarshaler decoding interface
	json.Unmarshaler
}

PrivateKeyI is an interface model for a secret cryptographic code that is used to produce digital signatures

func BytesToBLS12381PrivateKey

func BytesToBLS12381PrivateKey(bz []byte) (PrivateKeyI, error)

BytesToBLS12381PrivateKey() creates a new PrivateKeyI interface from a BLS Private Key bytes

func BytesToED25519Private

func BytesToED25519Private(bz []byte) PrivateKeyI

BytesToED25519Private() creates a new PrivateKeyI interface from ED25519 bytes

func DecryptPrivateKey

func DecryptPrivateKey(epk *EncryptedPrivateKey, password []byte) (pk PrivateKeyI, err error)

DecryptPrivateKey takes an EncryptedPrivateKey and decrypts it to a PrivateKeyI interface using the password

func NewBLS12381PrivateKey

func NewBLS12381PrivateKey() (PrivateKeyI, error)

NewBLS12381PrivateKey() generates a new BLS private key

func NewBLS12381PrivateKeyFromFile

func NewBLS12381PrivateKeyFromFile(filepath string) (PrivateKeyI, error)

NewBLS12381PrivateKeyFromFile() creates a new PrivateKeyI interface from a BLS12381 json file

func NewETHSECP256K1PrivateKey

func NewETHSECP256K1PrivateKey() (PrivateKeyI, error)

NewETHSECP256K1PrivateKey() generates a new ETHSECP256K1 private key

func NewEd25519PrivateKey

func NewEd25519PrivateKey() (PrivateKeyI, error)

NewEd25519PrivateKey() generates a new ED25519 private key

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(bz []byte) (PrivateKeyI, error)

NewPrivateKeyFromBytes() creates a new PrivateKeyI interface from bytes

func NewPrivateKeyFromString

func NewPrivateKeyFromString(s string) (PrivateKeyI, error)

NewPrivateKeyFromString() creates a new PrivateKeyI interface from a hex string

func NewSECP256K1PrivateKey

func NewSECP256K1PrivateKey() (PrivateKeyI, error)

NewSECP256K1PrivateKey() generates a new SECP256K1 private key

func StringToBLS12381PrivateKey

func StringToBLS12381PrivateKey(hexString string) (PrivateKeyI, error)

StringToBLS12381PrivateKey() creates a new PrivateKeyI interface from a BLS Private Key hex string

func StringToED25519Private

func StringToED25519Private(hexString string) (PrivateKeyI, error)

StringToED25519Private() creates a new PrivateKeyI interface from an ED25519 hex string

func StringToSECP256K1Private

func StringToSECP256K1Private(hexString string) (PrivateKeyI, error)

StringToSECP256K1Private() creates a new PrivateKeyI interface from an SECP256K1 hex string

type ProtoAddress

type ProtoAddress struct {

	// address: the shorter version of a public key
	Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
	// contains filtered or unexported fields
}

***************************************************************************************************** This file is auto-generated from source files in `/lib/.proto/*` using Protocol Buffers (protobuf)

Protobuf is a language-neutral, platform-neutral serialization format. It allows users to define objects in a way that’s both efficient to store and fast to transmit over the network. These definitions are compiled into code that *enables different systems and programming languages to communicate in a byte-perfect manner*

To update these structures, make changes to the source .proto files, then recompile to regenerate this file. These auto-generated files are easily recognized by checking for a `.pb.go` ending ***************************************************************************************************** _ _ _ ProtoAddress is a wrapper around address bytes enabling protobuf encoding and decoding

func (*ProtoAddress) Descriptor deprecated

func (*ProtoAddress) Descriptor() ([]byte, []int)

Deprecated: Use ProtoAddress.ProtoReflect.Descriptor instead.

func (*ProtoAddress) GetAddress

func (x *ProtoAddress) GetAddress() []byte

func (*ProtoAddress) ProtoMessage

func (*ProtoAddress) ProtoMessage()

func (*ProtoAddress) ProtoReflect

func (x *ProtoAddress) ProtoReflect() protoreflect.Message

func (*ProtoAddress) Reset

func (x *ProtoAddress) Reset()

func (*ProtoAddress) String

func (x *ProtoAddress) String() string

type ProtoAddresses

type ProtoAddresses struct {

	// addresses: a list of shorter versions of a public key
	Addresses [][]byte `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"`
	// contains filtered or unexported fields
}

A repeated list of addresses in proto format

func (*ProtoAddresses) Descriptor deprecated

func (*ProtoAddresses) Descriptor() ([]byte, []int)

Deprecated: Use ProtoAddresses.ProtoReflect.Descriptor instead.

func (*ProtoAddresses) GetAddresses

func (x *ProtoAddresses) GetAddresses() [][]byte

func (*ProtoAddresses) ProtoMessage

func (*ProtoAddresses) ProtoMessage()

func (*ProtoAddresses) ProtoReflect

func (x *ProtoAddresses) ProtoReflect() protoreflect.Message

func (*ProtoAddresses) Reset

func (x *ProtoAddresses) Reset()

func (*ProtoAddresses) String

func (x *ProtoAddresses) String() string

type ProtoClassGroup

type ProtoClassGroup struct {
	A []byte `protobuf:"bytes,1,opt,name=a,proto3" json:"a,omitempty"` // a value in ax^2 + bxy + cy^2
	B []byte `protobuf:"bytes,2,opt,name=b,proto3" json:"b,omitempty"` // b value in ax^2 + bxy + cy^2
	// contains filtered or unexported fields
}

ProtoClassGroup represents a mathematical class group with coefficients a and b

func (*ProtoClassGroup) Descriptor deprecated

func (*ProtoClassGroup) Descriptor() ([]byte, []int)

Deprecated: Use ProtoClassGroup.ProtoReflect.Descriptor instead.

func (*ProtoClassGroup) GetA

func (x *ProtoClassGroup) GetA() []byte

func (*ProtoClassGroup) GetB

func (x *ProtoClassGroup) GetB() []byte

func (*ProtoClassGroup) ProtoMessage

func (*ProtoClassGroup) ProtoMessage()

func (*ProtoClassGroup) ProtoReflect

func (x *ProtoClassGroup) ProtoReflect() protoreflect.Message

func (*ProtoClassGroup) Reset

func (x *ProtoClassGroup) Reset()

func (*ProtoClassGroup) String

func (x *ProtoClassGroup) String() string

type ProtoPrivKey

type ProtoPrivKey struct {

	// priv_key: is a secret cryptographic key used in asymmetric encryption to sign data and prove ownership
	// of a public key
	Privkey []byte `protobuf:"bytes,1,opt,name=privkey,proto3" json:"privkey,omitempty"`
	// contains filtered or unexported fields
}

ProtoPrivKey is a wrapper around private key bytes enabling protobuf encoding and decoding

func (*ProtoPrivKey) Descriptor deprecated

func (*ProtoPrivKey) Descriptor() ([]byte, []int)

Deprecated: Use ProtoPrivKey.ProtoReflect.Descriptor instead.

func (*ProtoPrivKey) GetPrivkey

func (x *ProtoPrivKey) GetPrivkey() []byte

func (*ProtoPrivKey) ProtoMessage

func (*ProtoPrivKey) ProtoMessage()

func (*ProtoPrivKey) ProtoReflect

func (x *ProtoPrivKey) ProtoReflect() protoreflect.Message

func (*ProtoPrivKey) Reset

func (x *ProtoPrivKey) Reset()

func (*ProtoPrivKey) String

func (x *ProtoPrivKey) String() string

type ProtoPubKey

type ProtoPubKey struct {

	// pub_key: the public cryptographic code that allows signature verification from a private key
	Pubkey []byte `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"`
	// contains filtered or unexported fields
}

ProtoPubKey is a wrapper around public key bytes enabling protobuf encoding and decoding

func (*ProtoPubKey) Descriptor deprecated

func (*ProtoPubKey) Descriptor() ([]byte, []int)

Deprecated: Use ProtoPubKey.ProtoReflect.Descriptor instead.

func (*ProtoPubKey) GetPubkey

func (x *ProtoPubKey) GetPubkey() []byte

func (*ProtoPubKey) ProtoMessage

func (*ProtoPubKey) ProtoMessage()

func (*ProtoPubKey) ProtoReflect

func (x *ProtoPubKey) ProtoReflect() protoreflect.Message

func (*ProtoPubKey) Reset

func (x *ProtoPubKey) Reset()

func (*ProtoPubKey) String

func (x *ProtoPubKey) String() string

type PublicKeyI

type PublicKeyI interface {
	// Address() creates a unique shorter fixed length version of the public key
	Address() AddressI
	// Bytes() casts the public key to bytes
	Bytes() []byte
	// VerifyBytes() verifies a digital signature from its corresponding private key
	VerifyBytes(msg []byte, sig []byte) bool
	// String() returns the hex string representation
	String() string
	// Equals() compares two PublicKeys and returns true if they're equal
	Equals(PublicKeyI) bool
	// models the json.Marshaller encoding interface
	json.Marshaler
	// models the json.Unmarshaler decoding interface
	json.Unmarshaler
}

PublicKeyI is an interface model for a cryptographic code shared openly, used to verify digital signatures of its paired private key

func BytesToBLS12381Public

func BytesToBLS12381Public(bz []byte) (PublicKeyI, error)

BytesToBLS12381Public() creates a new PublicKeyI interface from BLS public key bytes

func BytesToED25519Public

func BytesToED25519Public(bz []byte) PublicKeyI

BytesToED25519Public() creates a new PublicKeyI interface from a ED25519PublicKey hex string

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(bz []byte) (PublicKeyI, error)

NewPublicKeyFromBytes() creates a new PublicKeyI interface from a byte slice

func NewPublicKeyFromString

func NewPublicKeyFromString(s string) (PublicKeyI, error)

NewPublicKeyFromString() creates a new PublicKeyI interface from a hex string

func RecoverPublicKey

func RecoverPublicKey(signer types.Signer, tx types.Transaction) (PublicKeyI, error)

RecoverPublicKey() recovers a public key from ethereum the transaction and validates the signature

func StringToBLS12381Public

func StringToBLS12381Public(hexString string) (PublicKeyI, error)

StringToBLSPublic() creates a new PublicKeyI interface from BLS hex string

func StringToED25519Public

func StringToED25519Public(hexString string) (PublicKeyI, error)

StringToED25519Public() creates a new PublicKeyI interface from ED25519PublicKey bytes

type SECP256K1PrivateKey

type SECP256K1PrivateKey struct {
	*ecdsa.PrivateKey
}

SECP256K1PrivateKey is the private key of a cryptographic key pair used in elliptic curve signing and verification, based on the SECP256K1 elliptic curve It is used to create 'unique' digital signatures of messages

func BytesToSECP256K1Private

func BytesToSECP256K1Private(b []byte) (*SECP256K1PrivateKey, error)

BytesToSECP256K1Private() converts bytes to SECP256K1 private key using go-ethereum

func (*SECP256K1PrivateKey) Bytes

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

Bytes() returns the byte representation of the private key

func (*SECP256K1PrivateKey) Equals

func (s *SECP256K1PrivateKey) Equals(i PrivateKeyI) bool

Equals() compares to private keys and returns true if they are equal

func (*SECP256K1PrivateKey) MarshalJSON

func (s *SECP256K1PrivateKey) MarshalJSON() ([]byte, error)

MarshalJSON() is the json.Marshaller implementation for SECP256K1PrivateKey

func (*SECP256K1PrivateKey) PublicKey

func (s *SECP256K1PrivateKey) PublicKey() PublicKeyI

PublicKey() returns the public pair to this private key

func (*SECP256K1PrivateKey) Sign

func (s *SECP256K1PrivateKey) Sign(msg []byte) []byte

Sign() returns digital signature bytes from the message

func (*SECP256K1PrivateKey) String

func (s *SECP256K1PrivateKey) String() string

String() returns the hex string representation of the private key

func (*SECP256K1PrivateKey) UnmarshalJSON

func (s *SECP256K1PrivateKey) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON() is the json.Unmarshaler implementation for SECP256K1PrivateKey

type SECP256K1PublicKey

type SECP256K1PublicKey struct {
	*ecdsa.PublicKey
	// contains filtered or unexported fields
}

SECP256K1PublicKey is the public key of a cryptographic key pair used in elliptic curve signing and verification, based on the SECP256K1 elliptic curve It is used to verify ownership of the private key as well as validate digital signatures created by the private key

func BytesToSECP256K1Public

func BytesToSECP256K1Public(b []byte) (*SECP256K1PublicKey, error)

BytesToSECP256K1Public() returns SECP256K1PublicKey from bytes

func (*SECP256K1PublicKey) Address

func (s *SECP256K1PublicKey) Address() AddressI

Address() returns the short version of the public key Address format varies between chains: - Cosmos, Harmony, Binance, Avalanche RIPEMD-160(SHA-256(pubkey)) <Tendermint> - BTC, BCH, BSV, (and other forks) <1 byte version> + RIPEMD-160(SHA-256(pubkey)) + <4 byte Checksum> `RIPEMD-160(SHA-256(pubkey))` seems to be the most common theme in addressing for SECP256K1 public keys

func (*SECP256K1PublicKey) Bytes

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

Bytes() returns the byte representation of the Public Key

func (*SECP256K1PublicKey) Equals

func (s *SECP256K1PublicKey) Equals(i PublicKeyI) bool

Equals() compares two SECP256K1PublicKey objects and returns true if they're equal

func (*SECP256K1PublicKey) MarshalJSON

func (s *SECP256K1PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON() is the json.Marshaller implementation for SECP256K1PublicKey

func (*SECP256K1PublicKey) String

func (s *SECP256K1PublicKey) String() string

String() returns the hex string representation of the public key

func (*SECP256K1PublicKey) UnmarshalJSON

func (s *SECP256K1PublicKey) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON() is the json.Unmarshaler implementation for SECP256K1PublicKey

func (*SECP256K1PublicKey) VerifyBytes

func (s *SECP256K1PublicKey) VerifyBytes(msg []byte, sig []byte) (valid bool)

VerifyBytes() returns true if the digital signature is valid for this public key and the given message

type VDF

type VDF struct {

	// proof: a proof of function completion given a specific seed
	Proof []byte `protobuf:"bytes,1,opt,name=proof,proto3" json:"proof,omitempty"`
	// output: the final output of the calculated 'squarings'
	Output []byte `protobuf:"bytes,2,opt,name=output,proto3" json:"output,omitempty"`
	// iterations: number of serial executions (proxy for time)
	Iterations uint64 `protobuf:"varint,3,opt,name=iterations,proto3" json:"iterations,omitempty"`
	// contains filtered or unexported fields
}

A Verifiable Delay Function is a cryptographic function that takes a set amount of time to compute, even on powerful hardware, and produces a result that any node may quickly verify. In Canopy it's used as a proxy for time to deter historical forking attacks like a 'long-range-attack'.

func (*VDF) Copy

func (x *VDF) Copy() (vdfCopy *VDF)

Copy() creates a deep copy of the VDF object

func (*VDF) Descriptor deprecated

func (*VDF) Descriptor() ([]byte, []int)

Deprecated: Use VDF.ProtoReflect.Descriptor instead.

func (*VDF) GetIterations

func (x *VDF) GetIterations() uint64

func (*VDF) GetOutput

func (x *VDF) GetOutput() []byte

func (*VDF) GetProof

func (x *VDF) GetProof() []byte

func (*VDF) MarshalJSON

func (x *VDF) MarshalJSON() ([]byte, error)

MarshalJSON() implements the json.Marshaller interface for VDF

func (*VDF) ProtoMessage

func (*VDF) ProtoMessage()

func (*VDF) ProtoReflect

func (x *VDF) ProtoReflect() protoreflect.Message

func (*VDF) Reset

func (x *VDF) Reset()

func (*VDF) String

func (x *VDF) String() string

func (*VDF) UnmarshalJSON

func (x *VDF) UnmarshalJSON(b []byte) (err error)

MarshalJSON() implements the json.Marshaller interface for VDF

Jump to

Keyboard shortcuts

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