crypto

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0, MIT Imports: 17 Imported by: 8

Documentation

Index

Constants

View Source
const (
	SigTypeSecp256k1 = crypto.SigTypeSecp256k1
	SigTypeBLS       = crypto.SigTypeBLS
)
View Source
const BigIntMaxSerializedLen = 128 // is this big enough? or too big?
View Source
const FilBase = uint64(2_000_000_000)
View Source
const FilecoinPrecision = uint64(1_000_000_000_000_000_000)
View Source
const PrivateKeyBytes = 32

PrivateKeyBytes is the size of a serialized private key.

Variables

View Source
var EmptyInt = BigInt{}
View Source
var TotalFilecoinInt = FromFil(FilBase)

Functions

func BigCmp

func BigCmp(a, b BigInt) int

func DeciStr

func DeciStr(bi BigInt) string

func EcRecover

func EcRecover(msg, signature []byte) ([]byte, error)

EcRecover recovers the public key from a message, signature pair.

func PublicKeyForSecpSecretKey

func PublicKeyForSecpSecretKey(sk []byte) []byte

PublicKeyForSecpSecretKey returns the public key for this private key.

func SignBLS

func SignBLS(sk, msg []byte) ([]byte, error)

SignBLS signs the given message with BLS.

func SignSecp

func SignSecp(sk, msg []byte) ([]byte, error)

SignSecp signs the given message using secp256k1 based cryptography, which must be 32 bytes long.

func SizeStr

func SizeStr(bi BigInt) string

func ValidateBlsSignature

func ValidateBlsSignature(data []byte, addr address.Address, signature []byte) error

func ValidateSecpSignature

func ValidateSecpSignature(data []byte, addr address.Address, signature []byte) error

func ValidateSignature

func ValidateSignature(data []byte, addr address.Address, sig Signature) error

ValidateSignature cryptographically verifies that 'sig' is the signed hash of 'data' with the public key belonging to `addr`.

func VerifyBLS

func VerifyBLS(pubKey, msg, signature []byte) bool

VerifyBLS checks the given signature is valid using BLS cryptography.

func VerifyBLSAggregate

func VerifyBLSAggregate(pubKeys, msgs [][]byte, signature []byte) bool

VerifyBLSAggregate checks the given signature is a valid aggregate signature over all messages and public keys

func VerifySecp

func VerifySecp(pk, msg, signature []byte) bool

VerifySecp checks the given signature is a secp256k1 signature and returns true if it is valid.

Types

type BigInt

type BigInt = big2.Int

func BigAdd

func BigAdd(a, b BigInt) BigInt

func BigDiv

func BigDiv(a, b BigInt) BigInt

func BigFromBytes

func BigFromBytes(b []byte) BigInt

func BigFromString

func BigFromString(s string) (BigInt, error)

func BigMod

func BigMod(a, b BigInt) BigInt

func BigMul

func BigMul(a, b BigInt) BigInt

func BigSub

func BigSub(a, b BigInt) BigInt

func FromFil

func FromFil(i uint64) BigInt

func NewInt

func NewInt(i uint64) BigInt

type KeyInfo

type KeyInfo struct {
	// Private key.
	PrivateKey []byte `json:"privateKey"`
	// Cryptographic system used to generate private key.
	SigType SigType `json:"type"`
}

KeyInfo is a key and its type used for signing.

func NewBLSKeyFromSeed

func NewBLSKeyFromSeed(seed io.Reader) (KeyInfo, error)

func NewSecpKeyFromSeed

func NewSecpKeyFromSeed(seed io.Reader) (KeyInfo, error)

NewSecpKeyFromSeed generates a new key from the given reader.

func (*KeyInfo) Address

func (ki *KeyInfo) Address() (address.Address, error)

Address returns the address for this keyinfo

func (*KeyInfo) Equals

func (ki *KeyInfo) Equals(other *KeyInfo) bool

Equals returns true if the KeyInfo is equal to other.

func (*KeyInfo) Key

func (ki *KeyInfo) Key() []byte

Key returns the private key of KeyInfo

func (*KeyInfo) MarshalCBOR

func (t *KeyInfo) MarshalCBOR(w io.Writer) error

func (*KeyInfo) MarshalJSON

func (ki *KeyInfo) MarshalJSON() ([]byte, error)

func (*KeyInfo) PublicKey

func (ki *KeyInfo) PublicKey() []byte

Returns the public key part as uncompressed bytes.

func (*KeyInfo) Type

func (ki *KeyInfo) Type() SigType

Type returns the type of curve used to generate the private key

func (*KeyInfo) UnmarshalCBOR

func (t *KeyInfo) UnmarshalCBOR(r io.Reader) error

func (*KeyInfo) UnmarshalJSON

func (ki *KeyInfo) UnmarshalJSON(data []byte) error

type SigType

type SigType = crypto.SigType

type Signature

type Signature = crypto.Signature

func Sign

func Sign(data []byte, secretKey []byte, sigtype SigType) (*Signature, error)

Directories

Path Synopsis
bls

Jump to

Keyboard shortcuts

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