crypto

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 22 Imported by: 40

Documentation

Index

Constants

View Source
const (
	DigestSize    = 32
	KeySize       = 32
	PublicKeySize = KeySize
	SecretKeySize = KeySize
	SignatureSize = 64
)
View Source
const (
	ProofSize = 32 + 32 + 32
)

Variables

View Source
var (
	ZeroDigest = Digest{
		0x03, 0x17, 0x0a, 0x2e, 0x75, 0x97, 0xb7, 0xb7, 0xe3, 0xd8, 0x4c, 0x05, 0x39, 0x1d, 0x13, 0x9a,
		0x62, 0xb1, 0x57, 0xe7, 0x87, 0x86, 0xd8, 0xc0, 0x82, 0xf2, 0x9d, 0xcf, 0x4c, 0x11, 0x13, 0x14,
	}
)

Functions

func ComputeVRF added in v0.5.0

func ComputeVRF(sk SecretKey, msg []byte) []byte

ComputeVRF generates the VRF value for the byte slice msg using given private key sk.

func Decrypt added in v0.3.0

func Decrypt(key, encrypted []byte) ([]byte, error)

func ECDSARecoverPublicKey added in v0.7.0

func ECDSARecoverPublicKey(digest, signature []byte) (*btcec.PublicKey, error)

func Encrypt added in v0.3.0

func Encrypt(key, message []byte) ([]byte, error)

func GenerateKeyPair

func GenerateKeyPair(seed []byte) (SecretKey, PublicKey, error)

func MustBytesFromBase58 added in v0.5.0

func MustBytesFromBase58(s string) []byte

func NewFastHash added in v0.6.0

func NewFastHash() (hash.Hash, error)

func ReadInputs added in v0.8.0

func ReadInputs(inputs []byte) ([]*big.Int, error)

func SharedKey added in v0.3.0

func SharedKey(sk SecretKey, pk PublicKey, prefix []byte) ([]byte, error)

func SignVRF added in v0.5.0

func SignVRF(sk SecretKey, msg []byte) ([]byte, error)

func Verify

func Verify(publicKey PublicKey, signature Signature, data []byte) bool

func VerifyVRF added in v0.5.0

func VerifyVRF(pk PublicKey, msg, signature []byte) (bool, []byte, error)

Types

type Bls12381 added in v0.8.0

type Bls12381 struct{}

func (Bls12381) Groth16Verify added in v0.8.0

func (Bls12381) Groth16Verify(vk []byte, proof []byte, inputs []byte) (bool, error)

type Bn256 added in v0.8.0

type Bn256 struct{}

func (Bn256) Groth16Verify added in v0.8.0

func (Bn256) Groth16Verify(vk []byte, proof []byte, inputs []byte) (bool, error)

type Digest

type Digest [DigestSize]byte

func FastHash

func FastHash(data []byte) (Digest, error)

func Keccak256

func Keccak256(data []byte) (Digest, error)

func MustDigestFromBase58 added in v0.3.0

func MustDigestFromBase58(s string) Digest

func MustFastHash added in v0.3.0

func MustFastHash(data []byte) Digest

func NewDigestFromBase58

func NewDigestFromBase58(s string) (Digest, error)

func NewDigestFromBytes added in v0.2.0

func NewDigestFromBytes(b []byte) (Digest, error)

func SecureHash

func SecureHash(data []byte) (Digest, error)

func (Digest) Bytes added in v0.2.0

func (d Digest) Bytes() []byte

func (Digest) MarshalBinary

func (d Digest) MarshalBinary() ([]byte, error)

func (Digest) MarshalJSON

func (d Digest) MarshalJSON() ([]byte, error)

func (Digest) ShortString added in v0.3.0

func (d Digest) ShortString() string

func (Digest) String

func (d Digest) String() string

func (*Digest) UnmarshalBinary

func (d *Digest) UnmarshalBinary(data []byte) error

func (*Digest) UnmarshalJSON

func (d *Digest) UnmarshalJSON(value []byte) error

type Dummy added in v0.8.0

type Dummy struct{}

func (Dummy) Groth16Verify added in v0.8.0

func (Dummy) Groth16Verify(vk, proof, inputs []byte) (bool, error)

type MerkleTree added in v0.5.0

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

func NewMerkleTree added in v0.5.0

func NewMerkleTree() (*MerkleTree, error)

func (*MerkleTree) Push added in v0.5.0

func (t *MerkleTree) Push(data []byte)

func (*MerkleTree) RebuildRoot added in v0.5.0

func (t *MerkleTree) RebuildRoot(leaf Digest, proofs []Digest, index uint64) Digest

func (*MerkleTree) Root added in v0.5.0

func (t *MerkleTree) Root() Digest

type PublicKey

type PublicKey [PublicKeySize]byte

func GeneratePublicKey

func GeneratePublicKey(sk SecretKey) PublicKey

func MustPublicKeyFromBase58 added in v0.3.0

func MustPublicKeyFromBase58(s string) PublicKey

func NewPublicKeyFromBase58

func NewPublicKeyFromBase58(s string) (PublicKey, error)

func NewPublicKeyFromBytes added in v0.2.0

func NewPublicKeyFromBytes(b []byte) (PublicKey, error)

func (*PublicKey) Bytes added in v0.2.0

func (k *PublicKey) Bytes() []byte

func (PublicKey) MarshalBinary

func (k PublicKey) MarshalBinary() ([]byte, error)

func (PublicKey) MarshalJSON

func (k PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) String added in v0.2.0

func (k PublicKey) String() string

func (*PublicKey) UnmarshalBinary

func (k *PublicKey) UnmarshalBinary(data []byte) error

func (*PublicKey) UnmarshalJSON

func (k *PublicKey) UnmarshalJSON(value []byte) error

func (PublicKey) WriteTo added in v0.5.0

func (k PublicKey) WriteTo(buf []byte) error

type SecretKey

type SecretKey [SecretKeySize]byte

func GenerateSecretKey

func GenerateSecretKey(seed []byte) SecretKey

func MustSecretKeyFromBase58 added in v0.5.0

func MustSecretKeyFromBase58(s string) SecretKey

func NewSecretKeyFromBase58

func NewSecretKeyFromBase58(s string) (SecretKey, error)

func NewSecretKeyFromBytes added in v0.3.0

func NewSecretKeyFromBytes(b []byte) (SecretKey, error)

func (SecretKey) Bytes added in v0.3.0

func (k SecretKey) Bytes() []byte

func (SecretKey) MarshalBinary

func (k SecretKey) MarshalBinary() ([]byte, error)

func (SecretKey) MarshalJSON

func (k SecretKey) MarshalJSON() ([]byte, error)

func (SecretKey) String added in v0.1.2

func (k SecretKey) String() string

func (*SecretKey) UnmarshalBinary

func (k *SecretKey) UnmarshalBinary(data []byte) error

func (*SecretKey) UnmarshalJSON

func (k *SecretKey) UnmarshalJSON(value []byte) error

type Signature

type Signature [SignatureSize]byte

func MustSignatureFromBase58 added in v0.3.0

func MustSignatureFromBase58(s string) Signature

func NewSignatureFromBase58

func NewSignatureFromBase58(s string) (Signature, error)

func NewSignatureFromBytes added in v0.2.0

func NewSignatureFromBytes(b []byte) (Signature, error)

func Sign

func Sign(secretKey SecretKey, data []byte) (Signature, error)

func (Signature) Bytes added in v0.2.0

func (s Signature) Bytes() []byte

func (Signature) MarshalBinary

func (s Signature) MarshalBinary() ([]byte, error)

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

func (Signature) ShortString added in v0.3.0

func (s Signature) ShortString() string

func (Signature) String added in v0.1.2

func (s Signature) String() string

func (*Signature) UnmarshalBinary

func (s *Signature) UnmarshalBinary(data []byte) error

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(value []byte) error

Jump to

Keyboard shortcuts

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