zcncrypto

package
v1.18.0-RC17 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 13 Imported by: 10

Documentation

Overview

Provides low-level functions and types to work with different cryptographic schemes with a unified interface and provide cryptographic operations.

Index

Constants

View Source
const CryptoVersion = "1.0"

CryptoVersion - version of the crypto library

Variables

This section is empty.

Functions

func IsMnemonicValid

func IsMnemonicValid(mnemonic string) bool

func Sha3Sum256

func Sha3Sum256(data string) string

Types

type BlsSigner added in v1.3.5

type BlsSigner interface {
	SetRandFunc(randReader io.Reader)
	FrSub(out Fr, x Fr, y Fr)

	NewFr() Fr
	NewSecretKey() SecretKey
	NewPublicKey() PublicKey
	NewSignature() Signature
	NewID() ID
}
var BlsSignerInstance BlsSigner

type ED255190chainScheme

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

ED255190chainScheme - a signature scheme based on ED25519

func NewED255190chainScheme

func NewED255190chainScheme() *ED255190chainScheme

NewED255190chainScheme - create a ED255190chainScheme object

func (*ED255190chainScheme) Add

func (ed *ED255190chainScheme) Add(signature, msg string) (string, error)

func (*ED255190chainScheme) GenerateKeys

func (ed *ED255190chainScheme) GenerateKeys() (*Wallet, error)

GenerateKeys - implement interface

func (*ED255190chainScheme) GenerateKeysWithEth

func (ed *ED255190chainScheme) GenerateKeysWithEth(mnemonic, password string) (*Wallet, error)

GenerateKeysWithEth - not implemented

func (*ED255190chainScheme) GetID added in v1.3.1

func (ed *ED255190chainScheme) GetID() string

GetID gets ID in hex string format

func (*ED255190chainScheme) GetMnemonic added in v1.3.1

func (b0 *ED255190chainScheme) GetMnemonic() string

func (*ED255190chainScheme) GetPrivateKey

func (ed *ED255190chainScheme) GetPrivateKey() string

GetPrivateKey - implement interface

func (*ED255190chainScheme) GetPrivateKeyAsByteArray added in v1.3.1

func (ed *ED255190chainScheme) GetPrivateKeyAsByteArray() ([]byte, error)

GetPrivateKeyAsByteArray - converts private key into byte array

func (*ED255190chainScheme) GetPublicKey

func (ed *ED255190chainScheme) GetPublicKey() string

GetPublicKey - implement interface

func (*ED255190chainScheme) RecoverKeys

func (ed *ED255190chainScheme) RecoverKeys(mnemonic string) (*Wallet, error)

func (*ED255190chainScheme) SetID added in v1.3.1

func (ed *ED255190chainScheme) SetID(id string) error

SetID sets ID in HexString format

func (*ED255190chainScheme) SetPrivateKey

func (ed *ED255190chainScheme) SetPrivateKey(privateKey string) error

func (*ED255190chainScheme) SetPublicKey

func (ed *ED255190chainScheme) SetPublicKey(publicKey string) error

func (*ED255190chainScheme) Sign

func (ed *ED255190chainScheme) Sign(hash string) (string, error)

func (*ED255190chainScheme) SplitKeys added in v1.3.1

func (b0 *ED255190chainScheme) SplitKeys(numSplits int) (*Wallet, error)

func (*ED255190chainScheme) Verify

func (ed *ED255190chainScheme) Verify(signature, msg string) (bool, error)

type Fr added in v1.3.5

type Fr interface {
	Serialize() []byte

	SetLittleEndian(buf []byte) error
}

Fr --

type HerumiScheme added in v1.3.5

type HerumiScheme struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
	Mnemonic   string `json:"mnemonic"`

	Ids string `json:"threshold_scheme_id"`
	// contains filtered or unexported fields
}

HerumiScheme - a signature scheme for BLS0Chain Signature

func NewHerumiScheme added in v1.3.5

func NewHerumiScheme() *HerumiScheme

NewHerumiScheme - create a MiraclScheme object

func (*HerumiScheme) Add added in v1.3.5

func (b0 *HerumiScheme) Add(signature, msg string) (string, error)

func (*HerumiScheme) GenerateKeys added in v1.3.5

func (b0 *HerumiScheme) GenerateKeys() (*Wallet, error)

GenerateKeys generate fresh keys

func (*HerumiScheme) GenerateKeysWithEth added in v1.3.5

func (b0 *HerumiScheme) GenerateKeysWithEth(mnemonic, password string) (*Wallet, error)

GenerateKeysWithEth generate fresh keys based on eth wallet

func (*HerumiScheme) GetID added in v1.3.5

func (b0 *HerumiScheme) GetID() string

GetID gets ID in hex string format

func (*HerumiScheme) GetMnemonic added in v1.3.5

func (b0 *HerumiScheme) GetMnemonic() string

func (*HerumiScheme) GetPrivateKey added in v1.3.5

func (b0 *HerumiScheme) GetPrivateKey() string

func (*HerumiScheme) GetPrivateKeyAsByteArray added in v1.3.5

func (b0 *HerumiScheme) GetPrivateKeyAsByteArray() ([]byte, error)

GetPrivateKeyAsByteArray - converts private key into byte array

func (*HerumiScheme) GetPublicKey added in v1.3.5

func (b0 *HerumiScheme) GetPublicKey() string

GetPublicKey - implement interface

func (*HerumiScheme) RecoverKeys added in v1.3.5

func (b0 *HerumiScheme) RecoverKeys(mnemonic string) (*Wallet, error)

RecoverKeys recovery keys from mnemonic

func (*HerumiScheme) SetID added in v1.3.5

func (b0 *HerumiScheme) SetID(id string) error

SetID sets ID in HexString format

func (*HerumiScheme) SetPrivateKey added in v1.3.5

func (b0 *HerumiScheme) SetPrivateKey(privateKey string) error

SetPrivateKey set private key to sign

func (*HerumiScheme) SetPublicKey added in v1.3.5

func (b0 *HerumiScheme) SetPublicKey(publicKey string) error

SetPublicKey - implement interface

func (*HerumiScheme) Sign added in v1.3.5

func (b0 *HerumiScheme) Sign(hash string) (string, error)

Sign sign message

func (*HerumiScheme) SplitKeys added in v1.3.5

func (b0 *HerumiScheme) SplitKeys(numSplits int) (*Wallet, error)

func (*HerumiScheme) Verify added in v1.3.5

func (b0 *HerumiScheme) Verify(signature, msg string) (bool, error)

Verify - implement interface

type ID added in v1.3.5

type ID interface {
	SetHexString(s string) error
	GetHexString() string

	SetDecString(s string) error
}

type KeyPair

type KeyPair struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
}

KeyPair private and publickey

type PublicKey added in v1.3.5

type PublicKey interface {
	SerializeToHexStr() string
	DeserializeHexStr(s string) error

	Serialize() []byte
}

type SecretKey added in v1.3.5

type SecretKey interface {
	SerializeToHexStr() string
	DeserializeHexStr(s string) error

	Serialize() []byte

	GetLittleEndian() []byte
	SetLittleEndian(buf []byte) error

	SetByCSPRNG()

	GetPublicKey() PublicKey

	Sign(m string) Signature
	Add(rhs SecretKey)

	GetMasterSecretKey(k int) (msk []SecretKey, err error)
	Set(msk []SecretKey, id ID) error
}

type Signature added in v1.3.5

type Signature interface {
	SerializeToHexStr() string
	DeserializeHexStr(s string) error

	Add(rhs Signature)

	Verify(pk PublicKey, m string) bool
}

type SignatureScheme

type SignatureScheme interface {
	// Generate fresh keys
	GenerateKeys() (*Wallet, error)
	// Generate fresh keys based on eth wallet
	GenerateKeysWithEth(mnemonic, password string) (*Wallet, error)

	// Generate keys from mnemonic for recovery
	RecoverKeys(mnemonic string) (*Wallet, error)
	GetMnemonic() string

	// Signing  - Set private key to sign
	SetPrivateKey(privateKey string) error
	Sign(hash string) (string, error)

	// Signature verification - Set public key to verify
	SetPublicKey(publicKey string) error
	GetPublicKey() string
	GetPrivateKey() string
	Verify(signature string, msg string) (bool, error)

	// Combine signature for schemes BLS
	Add(signature, msg string) (string, error)

	SplitKeys(numSplits int) (*Wallet, error)

	GetPrivateKeyAsByteArray() ([]byte, error)

	SetID(id string) error
	GetID() string
}

SignatureScheme - an encryption scheme for signing and verifying messages

func GenerateThresholdKeyShares added in v1.3.1

func GenerateThresholdKeyShares(t, n int, originalKey SignatureScheme) ([]SignatureScheme, error)

GenerateThresholdKeyShares given a signature scheme will generate threshold sig keys

func NewSignatureScheme

func NewSignatureScheme(sigScheme string) SignatureScheme

NewSignatureScheme creates an instance for using signature functions

  • sigScheme signature scheme to be used

func UnmarshalSignatureSchemes added in v1.3.5

func UnmarshalSignatureSchemes(sigScheme string, obj interface{}) ([]SignatureScheme, error)

UnmarshalSignatureSchemes unmarshal SignatureScheme from json string

type Wallet

type Wallet struct {
	ClientID      string    `json:"client_id"`
	ClientKey     string    `json:"client_key"`
	PeerPublicKey string    `json:"peer_public_key"` // Peer public key exists only in split wallet
	Keys          []KeyPair `json:"keys"`
	Mnemonic      string    `json:"mnemonics"`
	Version       string    `json:"version"`
	DateCreated   string    `json:"date_created"`
	Nonce         int64     `json:"nonce"`
	IsSplit       bool      `json:"is_split"`
}

Wallet represents client wallet information

func (*Wallet) Marshal

func (w *Wallet) Marshal() (string, error)

Marshal returns json string

func (*Wallet) SaveTo added in v1.17.0

func (w *Wallet) SaveTo(file string) error

func (*Wallet) SetSplitKeys added in v1.17.0

func (w *Wallet) SetSplitKeys(sw *Wallet)

SetSplitKeys sets split keys and wipes out mnemonic and original primary keys

func (*Wallet) Sign added in v1.7.9

func (w *Wallet) Sign(hash, scheme string) (string, error)

Jump to

Keyboard shortcuts

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