crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

pdu

GoDoc GoReport Travis License Chat Mentioned in Awesome Go

Package pdu provides ...

Overview

This package ...

Documentation

Index

Constants

View Source
const (
	// MultipleSignatures is type of signature by more than one key pairs
	MultipleSignatures = "MS"
	// Signature2PublicKey is type of signature by one key pair
	Signature2PublicKey = "S2PK"

	// BTC is symbol of Bitcoin
	BTC = "BTC"
	// ETH is symbol of Ethereum
	ETH = "ETH"
	// PDU is symbol of PDU
	PDU = "PDU"
)
View Source
const EncryptedVersion = 3

EncryptedVersion is version of EncryptedKeyJSONV3

Variables

View Source
var (
	// ErrParamsMissing is returned when params is not enough
	ErrParamsMissing = errors.New("params missing")

	// ErrSourceNotMatch is returned if the source name of signature and key not match
	ErrSourceNotMatch = errors.New("signature source not match")

	// ErrSigTypeNotSupport is returned if the signature is not MS or S2PK
	ErrSigTypeNotSupport = errors.New("signature type not support")

	// ErrGenerateKeyFail is returned when generate key fail
	ErrGenerateKeyFail = errors.New("generate key fail")

	// ErrKeyTypeNotSupport is returned if key type not support
	ErrKeyTypeNotSupport = errors.New("key type not support")

	// ErrSigPubKeyNotMatch is returned if the signature and key not match for MS
	ErrSigPubKeyNotMatch = errors.New("count of signature and public key not match")

	// ErrInvalidPubkey is returned if the public key is invalid
	ErrInvalidPubkey = errors.New("invalid public key")
)

Functions

func DecryptKey added in v0.1.0

func DecryptKey(source string, keyJSON []byte, pass string, parseKey funcParseKey) (*PrivateKey, *PublicKey, error)

DecryptKey decrypt private key from file

func EncryptKey added in v0.1.0

func EncryptKey(source string, priKey *PrivateKey, pass string, privKeyToKeyBytes funcPrivKeyToKeyBytes) ([]byte, error)

EncryptKey encryptKey into file

func GenKey added in v0.1.0

func GenKey(source string, genKey funcGenKey, params ...interface{}) (*PrivateKey, *PublicKey, error)

GenKey generate the private and public key pair

func MappingKey added in v0.1.0

func MappingKey(source string, privKey *PrivateKey, pubKey *PublicKey, parseKeyToString funcParseKeyToString, parsePubKeyToString funcParsePubKeyToString) (privKeyM, pubKeyM map[string]interface{}, err error)

MappingKey build private & public key content into map for display or marshal

func MappingPrivKey added in v0.1.0

func MappingPrivKey(source string, a *PrivateKey, parseKeyToString funcParseKeyToString) (map[string]interface{}, error)

MappingPrivKey display the content of private key

func MappingPubKey added in v0.1.0

func MappingPubKey(source string, a *PublicKey, parsePubKeyToString funcParsePubKeyToString) (map[string]interface{}, error)

MappingPubKey display the content of public key

func Marshal added in v0.1.0

func Marshal(source string, privKey *PrivateKey, pubKey *PublicKey, parseKeyToString funcParseKeyToString, parsePubKeyToString funcParsePubKeyToString) (privKeyBytes []byte, pubKeyBytes []byte, err error)

Marshal marshal private & public key to json

func Unmarshal added in v0.1.0

func Unmarshal(source string, privKeyBytes, pubKeyBytes []byte, parseKey funcParseKey, parsePubKey funcParsePubKey) (privKey *PrivateKey, pubKey *PublicKey, err error)

Unmarshal unmarshal private & public key from json

func Verify added in v0.1.0

func Verify(source string, hash []byte, sig *Signature, verify funcVerify, parseMulSig funcParseMulSig) (bool, error)

Verify is used to verify the signature

Types

type EncryptedKeyJListV3 added in v0.1.0

type EncryptedKeyJListV3 []*EncryptedKeyJSONV3

EncryptedKeyJListV3 is for ms

type EncryptedKeyJSONV3 added in v0.1.0

type EncryptedKeyJSONV3 struct {
	Address string              `json:"address"`
	Crypto  keystore.CryptoJSON `json:"crypto"`
	ID      string              `json:"id"`
	Version int                 `json:"version"`
}

EncryptedKeyJSONV3 is from geth

func EncryptSignleKey added in v0.1.0

func EncryptSignleKey(keyBytes, address []byte, pass string) (*EncryptedKeyJSONV3, error)

EncryptSignleKey encrypt single private key

type EncryptedPrivateKey added in v0.1.0

type EncryptedPrivateKey struct {
	Source  string              `json:"source"`
	SigType string              `json:"sigType"`
	EPK     EncryptedKeyJListV3 `json:"priKey"`
}

EncryptedPrivateKey is encrypted private key in json

type Engine

type Engine interface {
	Name() string
	GenKey(params ...interface{}) (*PrivateKey, *PublicKey, error)
	Sign([]byte, *PrivateKey) (*Signature, error)
	Verify([]byte, *Signature) (bool, error)
	Unmarshal([]byte, []byte) (*PrivateKey, *PublicKey, error)
	Marshal(*PrivateKey, *PublicKey) ([]byte, []byte, error)
	EncryptKey(*PrivateKey, string) ([]byte, error)
	DecryptKey([]byte, string) (*PrivateKey, *PublicKey, error)
	MappingKey(*PrivateKey, *PublicKey) (map[string]interface{}, map[string]interface{}, error)
}

Engine is an crypto algorithm engine

type PrivateKey

type PrivateKey struct {
	Source  string      `json:"source"`
	SigType string      `json:"sigType"`
	PriKey  interface{} `json:"priKey"`
}

PrivateKey contains the source name, type and private key content

type PublicKey

type PublicKey struct {
	Source  string      `json:"source"`
	SigType string      `json:"sigType"`
	PubKey  interface{} `json:"pubKey"`
}

PublicKey contains the source name, type and public key content

type Signature

type Signature struct {
	PublicKey
	Signature []byte `json:"signature"`
}

Signature contain the signature and public key

func Sign added in v0.1.0

func Sign(source string, hash []byte, priKey *PrivateKey, sign funcSign) (*Signature, error)

Sign is used to create signature of content by private key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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