crypto

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package crypto exposes high-level cryptographic functionality.

Index

Constants

This section is empty.

Variables

View Source
var BLSKeyGroup = BLSPairing.G1()

BLSKeyGroup is the G1 group.

BLSPairing is the BLS12-381 suite.

Functions

func BLSPointFromHex

func BLSPointFromHex(hexStr string) (kyber.Point, error)

BLSPointFromHex unwraps a hex serialization to a G1 or G2 point on the BLS12-381 curve.

func BLSPointToHex

func BLSPointToHex(p kyber.Point) string

BLSPointToHex returns the hex serialization of a BLS public key (G1) or signature (G2).

func DerivePubkey

func DerivePubkey(secret kyber.Scalar) *bls12381.KyberG1

DerivePubkey returns a BLS public key given a private key.

func NewKeyPair

func NewKeyPair() (secret kyber.Scalar, pubkey *bls12381.KyberG1)

NewKeyPair creates a new random key pair.

func NewTBLSPoly

func NewTBLSPoly(t int) (pri *share.PriPoly, pub *share.PubPoly)

NewTBLSPoly creates a new secret sharing polynomial for a BLS12-381 threshold signature scheme. Note that this function is not particularly secure as it constructs the root key in memory.

func ReadPlaintextPassword

func ReadPlaintextPassword(filePath string) (string, error)

ReadPlaintextPassword reads a password as the first line from a file.

func WritePlaintextPassword

func WritePlaintextPassword(filePath string, overwrite bool, password string) error

WritePlaintextPassword saves a password to a file without leading or trailing whitespace.

If overwrite is set and a file already exists at the given path, the file contents will be erased.

Types

type BLSPubkeyHex

type BLSPubkeyHex struct {
	kyber.Point
}

BLSPubkeyHex wraps a BLS public key with simplified hex serialization.

func (BLSPubkeyHex) MarshalText

func (p BLSPubkeyHex) MarshalText() ([]byte, error)

MarshalText returns the hex serialization of the compressed form BLS12-381 G1 point.

func (*BLSPubkeyHex) UnmarshalText

func (p *BLSPubkeyHex) UnmarshalText(b []byte) error

UnmarshalText decodes the given hex serialization of the compressed form BLS12-381 G1 point.

type Keystore

type Keystore struct {
	Crypto      map[string]interface{} `json:"crypto"`      // checksum, cipher, kdf
	Description string                 `json:"description"` // free-form text string explaining keystore purpose
	UUID        string                 `json:"uuid"`        // random UUID
	Pubkey      string                 `json:"pubkey"`      // BLS12-381 hex public key
	Path        string                 `json:"path"`        // EIP-2334 derivation path if hierarchical deriv, otherwise empty
	Version     uint                   `json:"version"`     // must be 4
}

Keystore describes the EIP-2335 BLS12-381 keystore file format.

https://eips.ethereum.org/EIPS/eip-2335

func BLSKeyPairToKeystore

func BLSKeyPairToKeystore(scalar kyber.Scalar, pubkey kyber.Point, password string) (*Keystore, error)

BLSKeyPairToKeystore creates a new EIP-2335 keystore given a BLS12-381 key pair. The provided keys should be standalone and not part of hierarchical deterministic derivation.

func LoadKeystore

func LoadKeystore(filePath string) (*Keystore, error)

LoadKeystore reads and unmarshals the keystore from the given path.

func NewBLSKeystore

func NewBLSKeystore(password string) (*Keystore, kyber.Scalar, kyber.Point, error)

NewBLSKeystore creates a new keystore with a random BLS12-381 private key.

func TBLSShareToKeystore

func TBLSShareToKeystore(scheme *TBLSScheme, priPoly *share.PriShare, password string) (*Keystore, error)

TBLSShareToKeystore constructs a new keystore from a threshold BLS private key share.

Prints the public key as a side effect.

func (*Keystore) BLSKeyPair

func (k *Keystore) BLSKeyPair(password string) (kyber.Scalar, kyber.Point, error)

BLSKeyPair returns the BLS12-381 keypair stored in a keystore.

func (*Keystore) Save

func (k *Keystore) Save(filePath string) error

Save marshals and writes the keystore to the given path.

type TBLSScheme

type TBLSScheme struct {
	*share.PubPoly
}

TBLSScheme wraps drand/share.PubPoly, the public commitments of a BLS secret sharing scheme required to recover BLS threshold signatures from signature shares.

func (TBLSScheme) Encode

func (t TBLSScheme) Encode() (TBLSSchemeEncoded, error)

Encode serializes cryptographic data.

func (TBLSScheme) MarshalJSON

func (t TBLSScheme) MarshalJSON() ([]byte, error)

MarshalJSON serializes a TBLS scheme to JSON.

func (TBLSScheme) Pubkey

func (t TBLSScheme) Pubkey() kyber.Point

Pubkey returns the BLS public key.

func (*TBLSScheme) UnmarshalJSON

func (t *TBLSScheme) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes a TBLS scheme from JSON.

type TBLSSchemeEncoded

type TBLSSchemeEncoded []BLSPubkeyHex

TBLSSchemeEncoded is the serialized form of TBLSScheme suitable for JSON encoding.

func (TBLSSchemeEncoded) Decode

func (t TBLSSchemeEncoded) Decode() *TBLSScheme

Decode reconstructs the threshold BLS commitment data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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