Documentation ¶
Index ¶
- Constants
- Variables
- func DecryptKey(source string, keyJSON []byte, pass string, parseKey funcParseKey) (*PrivateKey, *PublicKey, error)
- func EncryptKey(source string, priKey *PrivateKey, pass string, ...) ([]byte, error)
- func GenKey(source string, genKey funcGenKey, params ...interface{}) (*PrivateKey, *PublicKey, error)
- func MappingKey(source string, privKey *PrivateKey, pubKey *PublicKey, ...) (privKeyM, pubKeyM map[string]interface{}, err error)
- func MappingPrivKey(source string, a *PrivateKey, parseKeyToString funcParseKeyToString) (map[string]interface{}, error)
- func MappingPubKey(source string, a *PublicKey, parsePubKeyToString funcParsePubKeyToString) (map[string]interface{}, error)
- func Marshal(source string, privKey *PrivateKey, pubKey *PublicKey, ...) (privKeyBytes []byte, pubKeyBytes []byte, err error)
- func Unmarshal(source string, privKeyBytes, pubKeyBytes []byte, parseKey funcParseKey, ...) (privKey *PrivateKey, pubKey *PublicKey, err error)
- func Verify(source string, hash []byte, sig *Signature, verify funcVerify, ...) (bool, error)
- type EncryptedKeyJListV3
- type EncryptedKeyJSONV3
- type EncryptedPrivateKey
- type Engine
- type PrivateKey
- type PublicKey
- type Signature
Constants ¶
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" )
const EncryptedVersion = 3
EncryptedVersion is version of EncryptedKeyJSONV3
Variables ¶
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
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