crypto

package
v0.0.0-...-5a544cf Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package crypto is combined crypto module for both general(AES, ...) and ethereum(Ecrevoer, sign, ...)

Index

Constants

View Source
const (
	// DbSecretKeyPropName is DB column name about secret key
	DbSecretKeyPropName = "secret_key"
	// DbNoncePropName is DB column name about nonce
	DbNoncePropName = "nonce"
	// DbKeyJSONPropName is DB column name about key json
	DbKeyJSONPropName = "key_json"
)

For DB columns

View Source
const (
	// Passphrase means passphrase used to decrypt keystore
	Passphrase = "KEY_PASSPHRASE"
	// Path means a location of keyjson in file system
	Path = "KEY_PATH"
	// IsAwsLambda decides if served as AWS lambda or not
	IsAwsLambda = "AWS_LAMBDA"
)

For environment arguments

Variables

View Source
var (
	PathChan       = make(chan string)
	PassphraseChan = make(chan string)
)

For singleton

Functions

func DecryptAes

func DecryptAes(text, keyStr string, nonce []byte) string

DecryptAes decrypts text using AES with given key and nonce

func DeriveSha

func DeriveSha(txs []common.Hash) (common.Hash, *trie.Trie)

DeriveSha calculates root hash based on transactions

func EcRecover

func EcRecover(dataStr, sigStr string) (addr ethcommon.Address, err error)

EcRecover returns the address for the Account that was used to create the signature. Note, this function is compatible with eth_sign and personal_sign. As such it recovers the address of: hash = keccak256("\x19Ethereum Signed Message:\n"${message length}${message}) addr = ecrecover(hash, signature)

Note, the signature must conform to the secp256k1 curve R, S and V values, where the V value must be be 27 or 28 for legacy reasons.

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover

func EcRecoverToPubkey

func EcRecoverToPubkey(hash, sig string) ([]byte, error)

EcRecoverToPubkey returns public key through EcRecover

func EncryptAes

func EncryptAes(text, keyStr, nonceStr string) (string, []byte)

EncryptAes encrypts text using AES with given key and nonce

func GetTransactionOpts

func GetTransactionOpts() *bind.TransactOpts

GetTransactionOpts returns TransactOpts to create contract session

func PubkeyToAddress

func PubkeyToAddress(p []byte) ethcommon.Address

PubkeyToAddress converts public key to ethereum address

func Sign

func Sign(msg string, privKey *ecdsa.PrivateKey) ([]byte, error)

Sign returns signed message using given private key

func VerifyProof

func VerifyProof(txs []common.Hash, tr *trie.Trie) (bool, error)

VerifyProof checks if root hash for transactions is valid

Types

type Crypto

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

Crypto manager It should be initialized first at main

func GetDummy

func GetDummy() *Crypto

GetDummy returns dummy Crypto instance for test

func GetInstance

func GetInstance() *Crypto

GetInstance returns pointer of Crypto instance Because DB operations are needed for Crypto initiation, Crypto is designed as singleton to reduce the number of DB operation units used

func (*Crypto) ApplyNonce

func (c *Crypto) ApplyNonce(f interface{}) bool

ApplyNonce applies nonce to a given function "f" Function description should be func(uint64) (error) If given function returns nil error, increase nonce Meaning of this function's return is either nonce was increased or not

func (*Crypto) GetAddress

func (c *Crypto) GetAddress() string

GetAddress returns an address of Crypto manager

func (*Crypto) InitChainID

func (c *Crypto) InitChainID(chainID *big.Int)

InitChainID initializes chain ID

func (*Crypto) InitNonce

func (c *Crypto) InitNonce(nonce uint64)

InitNonce initailizes TX nonce one time

func (*Crypto) Sign

func (c *Crypto) Sign(msg string) string

Sign returns signed message using own private key

func (*Crypto) SignTx

func (c *Crypto) SignTx(tx *types.Transaction) (*types.Transaction, error)

SignTx returns signed transaction using own private key

type Transactions

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

Transactions is a leaf hash list

func (Transactions) GetRlp

func (s Transactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (Transactions) Len

func (s Transactions) Len() int

Len returns the length of s.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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