Documentation
¶
Index ¶
- Constants
- Variables
- func CompressPubkey(pub *ecdsa.PublicKey) abytes.HexBytes
- func DecompressPubkey(bz []byte) (*ecdsa.PublicKey, xerrors.XError)
- func DefaultHash(datas ...[]byte) []byte
- func DefaultHasher() hash.Hash
- func DefaultHasherName() string
- func ImportPrvKey(d []byte) (*ecdsa.PrivateKey, error)
- func ImportPrvKeyHex(d string) (*ecdsa.PrivateKey, error)
- func NewPrvKey() (*ecdsa.PrivateKey, error)
- func PKCS5Padding(b []byte, blocksize int) ([]byte, error)
- func PKCS5UnPadding(b []byte, blocksize int) ([]byte, error)
- func PKCS7Padding(b []byte, blocksize int) ([]byte, error)
- func PKCS7UnPadding(b []byte, blocksize int) ([]byte, error)
- func Pub2Addr(pub *ecdsa.PublicKey) types.Address
- func PubBytes2Addr(pubBytes []byte) (types.Address, xerrors.XError)
- func Sig2Addr(msg, sig []byte) (types.Address, abytes.HexBytes, xerrors.XError)
- func Sign(msg []byte, prv *ecdsa.PrivateKey) ([]byte, error)
- func VerifySig(pubkey, msg, sig []byte) bool
- type SFilePV
- func GenSFilePV(keyFilePath, stateFilePath string) *SFilePV
- func LoadOrGenSFilePV(keyFilePath, stateFilePath string, s []byte) *SFilePV
- func LoadSFilePV(keyFilePath, stateFilePath string, s []byte) *SFilePV
- func LoadSFilePVEmptyState(keyFilePath, stateFilePath string, s []byte) *SFilePV
- func NewSFilePV(privKey crypto.PrivKey, keyFilePath, stateFilePath string) *SFilePV
- func (pv *SFilePV) GetAddress() types.Address
- func (pv *SFilePV) GetPubKey() (crypto.PubKey, error)
- func (pv *SFilePV) ResetWith(s []byte)
- func (pv *SFilePV) SaveWith(s []byte)
- func (pv *SFilePV) SignProposal(chainID string, proposal *tmproto.Proposal) error
- func (pv *SFilePV) SignVote(chainID string, vote *tmproto.Vote) error
- func (pv *SFilePV) String() string
- type SFilePVKey
- type SFilePVLastSignState
- type WalletKey
- func (wk *WalletKey) IsLock() bool
- func (wk *WalletKey) Lock()
- func (wk *WalletKey) LockWith(pass []byte)
- func (wk *WalletKey) PrvKey() []byte
- func (wk *WalletKey) PrvKeyClone() []byte
- func (wk *WalletKey) PubKey() []byte
- func (wk *WalletKey) Save(wr io.Writer) (int, error)
- func (wk *WalletKey) Sign(msg []byte) ([]byte, error)
- func (wk *WalletKey) String() string
- func (wk *WalletKey) Unlock(s []byte) error
- func (wk *WalletKey) VerifySig(msg, sig []byte) bool
Constants ¶
const ( //Aes128CBC = "aes-128-cbc" Aes256CBC = "aes-256-cbc" Secp256K1 = tmsecp256k1.KeyType SymmAlgo = Aes256CBC DKLEN = 32 AsymmAlgo = Secp256K1 )
const DefaultValKeyDir = "walkeys/vals"
const DefaultWalletKeyDir = "walkeys"
const DefaultWalletKeyDirPerm = 0700
Variables ¶
var ( // ErrInvalidBlockSize indicates hash blocksize <= 0. ErrInvalidBlockSize = xerrors.NewOrdinary("invalid blocksize") // ErrInvalidPKCS5Data indicates bad input to PKCS7 pad or unpad. ErrInvalidPKCS5Data = xerrors.NewOrdinary("invalid PKCS5 data (empty or not padded)") // ErrInvalidPKCS5Padding indicates PKCS5 unpad fails to bad input. ErrInvalidPKCS5Padding = xerrors.NewOrdinary("invalid PKCS5 padding on input") // ErrInvalidPKCS7Data indicates bad input to PKCS7 pad or unpad. ErrInvalidPKCS7Data = xerrors.NewOrdinary("invalid PKCS7 data (empty or not padded)") // ErrInvalidPKCS7Padding indicates PKCS7 unpad fails to bad input. ErrInvalidPKCS7Padding = xerrors.NewOrdinary("invalid PKCS7 padding on input") )
Functions ¶
func DefaultHash ¶
func DefaultHasher ¶
func DefaultHasherName ¶
func DefaultHasherName() string
func ImportPrvKey ¶
func ImportPrvKey(d []byte) (*ecdsa.PrivateKey, error)
func ImportPrvKeyHex ¶
func ImportPrvKeyHex(d string) (*ecdsa.PrivateKey, error)
func NewPrvKey ¶
func NewPrvKey() (*ecdsa.PrivateKey, error)
func PKCS7Padding ¶
pkcs7Padding right-pads the given byte slice with 1 to n bytes, where n is the block size. The size of the result is x times n, where x is at least 1.
func PKCS7UnPadding ¶
pkcs7UnPadding validates and unpads data from the given bytes slice. The returned value will be 1 to n bytes smaller depending on the amount of padding, where n is the block size.
func PubBytes2Addr ¶
pubBytes is 33 bytes compressed format
Types ¶
type SFilePV ¶
type SFilePV struct { Key SFilePVKey LastSignState SFilePVLastSignState }
SFilePV implements PrivValidator using data persisted to disk to prevent double signing. NOTE: the directories containing pv.Key.filePath and pv.LastSignState.filePath must already exist. It includes the LastSignature and LastSignBytes so we don't lose the signature if the process crashes after signing but before the resulting consensus message is processed.
func GenSFilePV ¶
GenSFilePV generates a new validator with randomly generated private key and sets the filePaths, but does not call Save().
func LoadOrGenSFilePV ¶
LoadOrGenSFilePV loads a SFilePV from the given filePaths or else generates a new one and saves it to the filePaths.
func LoadSFilePV ¶
LoadSFilePV loads a SFilePV from the filePaths. The SFilePV handles double signing prevention by persisting data to the stateFilePath. If either file path does not exist, the program will exit.
func LoadSFilePVEmptyState ¶
LoadSFilePVEmptyState loads a SFilePV from the given keyFilePath, with an empty LastSignState. If the keyFilePath does not exist, the program will exit.
func NewSFilePV ¶
NewSFilePV generates a new validator from the given key and paths.
func (*SFilePV) GetAddress ¶
GetAddress returns the address of the validator. Implements PrivValidator.
func (*SFilePV) GetPubKey ¶
GetPubKey returns the public key of the validator. Implements PrivValidator.
func (*SFilePV) SignProposal ¶
SignProposal signs a canonical representation of the proposal, along with the chainID. Implements PrivValidator.
type SFilePVKey ¶
type SFilePVKey struct { Address types.Address `json:"address"` PubKey crypto.PubKey `json:"pub_key"` PrivKey crypto.PrivKey `json:"priv_key"` // contains filtered or unexported fields }
SFilePVKey stores the immutable part of PrivValidator.
func (SFilePVKey) SaveWith ¶
func (pvKey SFilePVKey) SaveWith(s []byte)
Save persists the SFilePVKey to its filePath.
type SFilePVLastSignState ¶
type SFilePVLastSignState struct { Height int64 `json:"height"` Round int32 `json:"round"` Step int8 `json:"step"` Signature []byte `json:"signature,omitempty"` SignBytes abytes.HexBytes `json:"signbytes,omitempty"` // contains filtered or unexported fields }
SFilePVLastSignState stores the mutable part of PrivValidator.
func (*SFilePVLastSignState) CheckHRS ¶
CheckHRS checks the given height, round, step (HRS) against that of the SFilePVLastSignState. It returns an error if the arguments constitute a regression, or if they match but the SignBytes are empty. The returned boolean indicates whether the last Signature should be reused - it returns true if the HRS matches the arguments and the SignBytes are not empty (indicating we have already signed for this HRS, and can reuse the existing signature). It panics if the HRS matches the arguments, there's a SignBytes, but no Signature.
func (*SFilePVLastSignState) Save ¶
func (lss *SFilePVLastSignState) Save()
Save persists the FilePvLastSignState to its filePath.
type WalletKey ¶
type WalletKey struct { Version int `json:"version"` Address types.Address `json:"address"` Algo string `json:"algo"` CipherTextParams *cipherTextParams `json:"cp"` DKParams *dkParams `json:"dkp"` // contains filtered or unexported fields }