Documentation ¶
Overview ¶
Package crypto is combined crypto module for both general(AES, ...) and ethereum(Ecrevoer, sign, ...)
Index ¶
- Constants
- Variables
- func DecryptAes(text, keyStr string, nonce []byte) string
- func DeriveSha(txs []common.Hash) (common.Hash, *trie.Trie)
- func EcRecover(dataStr, sigStr string) (addr ethcommon.Address, err error)
- func EcRecoverToPubkey(hash, sig string) ([]byte, error)
- func EncryptAes(text, keyStr, nonceStr string) (string, []byte)
- func GetTransactionOpts() *bind.TransactOpts
- func PubkeyToAddress(p []byte) ethcommon.Address
- func Sign(msg string, privKey *ecdsa.PrivateKey) ([]byte, error)
- func VerifyProof(txs []common.Hash, tr *trie.Trie) (bool, error)
- type Crypto
- type Transactions
Constants ¶
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
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 ¶
var ( PathChan = make(chan string) PassphraseChan = make(chan string) )
For singleton
Functions ¶
func DecryptAes ¶
DecryptAes decrypts text using AES with given key and nonce
func EcRecover ¶
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 ¶
EcRecoverToPubkey returns public key through EcRecover
func EncryptAes ¶
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 ¶
PubkeyToAddress converts public key to ethereum address
Types ¶
type Crypto ¶
type Crypto struct {
// contains filtered or unexported fields
}
Crypto manager It should be initialized first at main
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 ¶
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 ¶
GetAddress returns an address of Crypto manager
func (*Crypto) InitChainID ¶
InitChainID initializes chain ID
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.