keys

package
v0.18.15 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SHA224 = "SHA224"
	SHA256 = "SHA256"
	SHA384 = "SHA384"
	SHA512 = "SHA512"

	TAGLEN  = 6
	SIG_LEN = 64
)
View Source
const (
	UNKNOWN Algorithm = iota
	ED25519
	SECP256K1
	BTCECSECP

	ETHSECP

	ED25519_PUB_SIZE  int = ed25519.PubKeyEd25519Size
	ED25519_PRIV_SIZE int = 64

	SECP256K1_PUB_SIZE  int = secp256k1.PubKeySecp256k1Size
	SECP256K1_PRIV_SIZE int = 32
)
View Source
const (
	EmptyStr = ""
	VERSION  = 1
)

Variables

View Source
var (
	ErrWrongPublicKeyAdapter  = errors.New("error in asserting to PublicKey Addapter")
	ErrWrongPrivateKeyAdapter = errors.New("error in asserting to PrivateKey Addapter")
	ErrMissMsg                = errors.New("miss message to sign")
	ErrMissSigners            = errors.New("signers not specified")
	ErrInvalidThreshold       = errors.New("invalid threshold")
	ErrNotExpectedSigner      = errors.New("not expected signer")
	ErrInvalidSignedMsg       = errors.New("invalid signed message")
)

Functions

func ETHSECP256K1TOECDSA added in v0.13.0

func ETHSECP256K1TOECDSA(data []byte) *ecdsa.PrivateKey

func GetFileName added in v0.14.0

func GetFileName(path string, address Address) (string, error)

func NewKeyPairFromTendermint

func NewKeyPairFromTendermint() (PublicKey, PrivateKey, error)

func PreHashRequired added in v0.14.0

func PreHashRequired(sig []byte) (bool, hash.Hash)

Types

type AccountKey added in v0.14.0

type AccountKey struct {
	Version    int    `json:"version"`
	CipherText string `json:"cipher_text"`
	Address    string `json:"address"`
}

type Address

type Address []byte

Address to be used as to reference a key-pair.

func (Address) Bytes

func (a Address) Bytes() []byte

func (Address) Equal

func (a Address) Equal(b Address) bool

func (Address) Err added in v0.10.8

func (a Address) Err() error

func (Address) Humanize

func (a Address) Humanize() string

func (Address) MarshalText added in v0.10.8

func (a Address) MarshalText() ([]byte, error)

MarshalText returns the text form for an Address. It returns a byteslice containing the hex encoding of the address including the 0lt prefix

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalText added in v0.10.8

func (a *Address) UnmarshalText(text []byte) error

UnmarshalText decodes the given text in a byteslice of characters, and works regardless of whether the 0lt prefix is present or not.

type Algorithm

type Algorithm int

func GetAlgorithmFromTmKeyName added in v0.10.4

func GetAlgorithmFromTmKeyName(name string) Algorithm

func (Algorithm) MarshalText added in v0.10.8

func (a Algorithm) MarshalText() ([]byte, error)

func (Algorithm) String added in v0.14.0

func (a Algorithm) String() string

func (*Algorithm) UnmarshalText added in v0.10.8

func (a *Algorithm) UnmarshalText(name []byte) error

type BTCMultiSig added in v0.13.0

type BTCMultiSig struct {
	Msg []byte `json:"msg"`

	M int `json:"m"`

	Signers []Address `json:"signers"`

	Signatures []BTCSignature `json:"signatures"`
}

func NewBTCMultiSig added in v0.13.0

func NewBTCMultiSig(msg []byte, m int, signers []Address) (*BTCMultiSig, error)

func (*BTCMultiSig) AddSignature added in v0.13.0

func (m *BTCMultiSig) AddSignature(s *BTCSignature) error

func (BTCMultiSig) Address added in v0.13.0

func (m BTCMultiSig) Address() Address

func (BTCMultiSig) Bytes added in v0.13.0

func (m BTCMultiSig) Bytes() []byte

func (*BTCMultiSig) FromBytes added in v0.13.0

func (m *BTCMultiSig) FromBytes(b []byte) error

func (*BTCMultiSig) GetSignatures added in v0.13.0

func (m *BTCMultiSig) GetSignatures() []BTCSignature

func (*BTCMultiSig) GetSignaturesInOrder added in v0.13.0

func (m *BTCMultiSig) GetSignaturesInOrder() [][]byte

func (*BTCMultiSig) GetSignerIndex added in v0.13.0

func (m *BTCMultiSig) GetSignerIndex(addr Address) (int, error)

func (BTCMultiSig) HasAddressSigned added in v0.13.0

func (m BTCMultiSig) HasAddressSigned(addr Address) bool

func (BTCMultiSig) IsCancel added in v0.13.0

func (m BTCMultiSig) IsCancel() bool

func (BTCMultiSig) IsValid added in v0.13.0

func (m BTCMultiSig) IsValid() bool

func (*BTCMultiSig) Marshal added in v0.13.0

func (m *BTCMultiSig) Marshal() ([]byte, error)

func (*BTCMultiSig) Unmarshal added in v0.13.0

func (m *BTCMultiSig) Unmarshal(b []byte) error

type BTCSignature added in v0.13.0

type BTCSignature struct {
	Index   int     `json:"index"`
	Address Address `json:"address"` // this should be a compressed public key
	Sign    []byte  `json:"sign"`
}

type Code added in v0.17.0

type Code []byte

Code is account Code type alias

func (Code) String added in v0.17.0

func (c Code) String() string

type KeyStore added in v0.14.0

type KeyStore struct {
}

func NewKeyStore added in v0.14.0

func NewKeyStore() *KeyStore

func (*KeyStore) DeleteKey added in v0.14.0

func (ks *KeyStore) DeleteKey(path string, address Address, passphrase string) error

func (*KeyStore) GetAddress added in v0.14.0

func (ks *KeyStore) GetAddress(path string, filename string) (Address, error)

func (*KeyStore) GetKeyData added in v0.14.0

func (ks *KeyStore) GetKeyData(path string, address Address, passphrase string) ([]byte, error)

func (*KeyStore) KeyExists added in v0.14.0

func (ks *KeyStore) KeyExists(path string, address Address) bool

func (*KeyStore) SaveKeyData added in v0.14.0

func (ks *KeyStore) SaveKeyData(path string, address Address, data []byte, passphrase string) error

func (*KeyStore) VerifyPassphrase added in v0.14.0

func (ks *KeyStore) VerifyPassphrase(path string, address Address, passphrase string) (bool, error)

type MultiSig added in v0.11.0

type MultiSig struct {

	// message that need to be sign by this multisig
	Msg []byte

	//used for threshold signature where M represent the minimal signatures for the multisig to be valid
	// M is between (0, len(Signer)]
	// when M = len(Signer): need all signers to sign
	M int

	//the expected signers that need to sign for the message, the signers will be sorted in the slice.
	Signers []Address

	//the collection of signatures for signers, the index of signatures should match the index of signers. this should
	// be empty when created and before add Signature
	Signatures []Signature
}

func (*MultiSig) AddSignature added in v0.11.0

func (m *MultiSig) AddSignature(s Signature) error

func (MultiSig) Address added in v0.11.0

func (m MultiSig) Address() Address

func (MultiSig) Bytes added in v0.11.0

func (m MultiSig) Bytes() []byte

func (*MultiSig) FromBytes added in v0.11.0

func (m *MultiSig) FromBytes(b []byte) error

func (*MultiSig) GetSignatures added in v0.13.0

func (m *MultiSig) GetSignatures() []Signature

func (*MultiSig) GetSignerIndex added in v0.13.0

func (m *MultiSig) GetSignerIndex(ad Address) (int, error)

func (MultiSig) HasAddressSigned added in v0.13.0

func (m MultiSig) HasAddressSigned(addr Address) bool

func (*MultiSig) Init added in v0.11.0

func (m *MultiSig) Init(msg []byte, threshold int, signers []Address) error

func (MultiSig) IsValid added in v0.11.0

func (m MultiSig) IsValid() bool

type MultiSigner added in v0.11.0

type MultiSigner interface {
	//Initialize the MultiSig
	// "msg" that need to be sign by this multisig
	// "threshold" used for threshold signature representing the minimal signatures for the multisig to be valid
	// "signers" are the expected signers that need to sign for the message, the signers will be sorted in the slice.
	Init(msg []byte, threshold int, signers []Address) error

	// Add a signature to the MultiSig. Return error if the signature not satisfy:
	//  - Valid s.PubKey in signature
	//  - PubKey's address doesn't match signer address of s.Index
	//  - Signed info is not the signature for message in the MultiSig
	AddSignature(s Signature) error

	// check MultiSig contains enough signature with threshold
	IsValid() bool

	// Return the bytes for the MultiSig,
	// the Bytes should include all info
	Bytes() []byte

	// Set MultiSig from []byte
	FromBytes(b []byte) error

	GetSignerIndex(Address) (int, error)

	GetSignatures() []Signature
}

type PrivateKey

type PrivateKey struct {
	Keytype Algorithm `json:"keyType"`
	Data    []byte    `json:"data"`
}

func GetPrivateKeyFromBytes

func GetPrivateKeyFromBytes(k []byte, algorithm Algorithm) (PrivateKey, error)

func NodeKeyFromTendermint

func NodeKeyFromTendermint(key *p2p.NodeKey) (PrivateKey, error)

NodeKeyFromTendermint returns a PrivateKey from a tendermint NodeKey. The input key must be a ED25519 key.

func PVKeyFromTendermint added in v0.10.4

func PVKeyFromTendermint(key *privval.FilePVKey) (PrivateKey, error)

NodeKeyFromTendermint returns a PrivateKey from a tendermint NodeKey. The input key must be a ED25519 key.

func (PrivateKey) GetHandler

func (privKey PrivateKey) GetHandler() (PrivateKeyHandler, error)

get the private key handler

func (*PrivateKey) GobDecode

func (privKey *PrivateKey) GobDecode(buf []byte) error

func (*PrivateKey) GobEncode

func (privKey *PrivateKey) GobEncode() ([]byte, error)

type PrivateKeyBTCEC added in v0.13.0

type PrivateKeyBTCEC btcec.PrivateKey

func (PrivateKeyBTCEC) Bytes added in v0.13.0

func (k PrivateKeyBTCEC) Bytes() []byte

func (PrivateKeyBTCEC) Equals added in v0.13.0

func (k PrivateKeyBTCEC) Equals(privkey PrivateKey) bool

func (PrivateKeyBTCEC) PubKey added in v0.13.0

func (k PrivateKeyBTCEC) PubKey() PublicKey

func (PrivateKeyBTCEC) Sign added in v0.13.0

func (k PrivateKeyBTCEC) Sign(msg []byte) ([]byte, error)

type PrivateKeyED25519

type PrivateKeyED25519 ed25519.PrivKeyEd25519

func (PrivateKeyED25519) Bytes

func (k PrivateKeyED25519) Bytes() []byte

func (PrivateKeyED25519) Equals

func (k PrivateKeyED25519) Equals(privkey PrivateKey) bool

func (PrivateKeyED25519) PubKey

func (k PrivateKeyED25519) PubKey() PublicKey

func (PrivateKeyED25519) Sign

func (k PrivateKeyED25519) Sign(msg []byte) ([]byte, error)

type PrivateKeyETHSECP added in v0.13.0

type PrivateKeyETHSECP ecdsa.PrivateKey

func (PrivateKeyETHSECP) Bytes added in v0.13.0

func (p PrivateKeyETHSECP) Bytes() []byte

func (PrivateKeyETHSECP) Equals added in v0.13.0

func (p PrivateKeyETHSECP) Equals(privKey PrivateKey) bool

func (PrivateKeyETHSECP) PubKey added in v0.13.0

func (p PrivateKeyETHSECP) PubKey() PublicKey

func (PrivateKeyETHSECP) Sign added in v0.13.0

func (p PrivateKeyETHSECP) Sign(b []byte) ([]byte, error)

type PrivateKeyHandler

type PrivateKeyHandler interface {
	Bytes() []byte
	Sign([]byte) ([]byte, error)
	PubKey() PublicKey
	Equals(PrivateKey) bool
}

type PrivateKeySECP256K1

type PrivateKeySECP256K1 secp256k1.PrivKeySecp256k1

func (PrivateKeySECP256K1) Bytes

func (k PrivateKeySECP256K1) Bytes() []byte

func (PrivateKeySECP256K1) Equals

func (k PrivateKeySECP256K1) Equals(privkey PrivateKey) bool

func (PrivateKeySECP256K1) PubKey

func (k PrivateKeySECP256K1) PubKey() PublicKey

func (PrivateKeySECP256K1) Sign

func (k PrivateKeySECP256K1) Sign(msg []byte) ([]byte, error)

type PublicKey

type PublicKey struct {
	KeyType Algorithm `json:"keyType"`
	Data    []byte    `json:"data"`
}

key Types

func GetPublicKeyFromBytes

func GetPublicKeyFromBytes(k []byte, algorithm Algorithm) (PublicKey, error)

func PubKeyFromTendermint added in v0.12.0

func PubKeyFromTendermint(key []byte) (PublicKey, error)

func (PublicKey) Equal

func (pubKey PublicKey) Equal(pkey PublicKey) bool

func (PublicKey) GetABCIPubKey

func (pubKey PublicKey) GetABCIPubKey() types.PubKey

func (PublicKey) GetHandler

func (pubKey PublicKey) GetHandler() (PublicKeyHandler, error)

Get the public key handler

func (*PublicKey) GobDecode

func (pubKey *PublicKey) GobDecode(buf []byte) error

func (*PublicKey) GobEncode

func (pubKey *PublicKey) GobEncode() ([]byte, error)

type PublicKeyBTCEC added in v0.13.0

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

func (PublicKeyBTCEC) Address added in v0.13.0

func (k PublicKeyBTCEC) Address() Address

Address hashes the key with a RIPEMD-160 hash

func (PublicKeyBTCEC) Bytes added in v0.13.0

func (k PublicKeyBTCEC) Bytes() []byte

func (PublicKeyBTCEC) Equals added in v0.13.0

func (k PublicKeyBTCEC) Equals(PubkeyBTCEC PublicKey) bool

func (PublicKeyBTCEC) String added in v0.13.0

func (k PublicKeyBTCEC) String() string

func (PublicKeyBTCEC) VerifyBytes added in v0.13.0

func (k PublicKeyBTCEC) VerifyBytes(msg []byte, sig []byte) bool

type PublicKeyED25519

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

func (PublicKeyED25519) Address

func (k PublicKeyED25519) Address() Address

Address hashes the key with a RIPEMD-160 hash

func (PublicKeyED25519) Bytes

func (k PublicKeyED25519) Bytes() []byte

func (PublicKeyED25519) Equals

func (k PublicKeyED25519) Equals(pubkey PublicKey) bool

func (PublicKeyED25519) String

func (k PublicKeyED25519) String() string

func (PublicKeyED25519) VerifyBytes

func (k PublicKeyED25519) VerifyBytes(msg []byte, sig []byte) bool

func (PublicKeyED25519) VerifyPreHashMsg added in v0.14.0

func (k PublicKeyED25519) VerifyPreHashMsg(msg []byte, sig []byte, hash hash.Hash) bool

type PublicKeyETHSECP added in v0.13.0

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

func (PublicKeyETHSECP) Address added in v0.13.0

func (k PublicKeyETHSECP) Address() Address

func (PublicKeyETHSECP) Bytes added in v0.13.0

func (k PublicKeyETHSECP) Bytes() []byte

func (PublicKeyETHSECP) Equals added in v0.13.0

func (k PublicKeyETHSECP) Equals(pubKey PublicKey) bool

func (PublicKeyETHSECP) VerifyBytes added in v0.13.0

func (k PublicKeyETHSECP) VerifyBytes(msg []byte, sig []byte) bool

type PublicKeyHandler

type PublicKeyHandler interface {
	Address() Address
	Bytes() []byte
	VerifyBytes(msg []byte, sig []byte) bool
	Equals(PublicKey) bool
}

Interfaces

type PublicKeySECP256K1

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

func (PublicKeySECP256K1) Address

func (k PublicKeySECP256K1) Address() Address

Address hashes the key with a RIPEMD-160 hash

func (PublicKeySECP256K1) Bytes

func (k PublicKeySECP256K1) Bytes() []byte

func (PublicKeySECP256K1) Equals

func (k PublicKeySECP256K1) Equals(PubkeySECP256K1 PublicKey) bool

func (PublicKeySECP256K1) String

func (k PublicKeySECP256K1) String() string

func (PublicKeySECP256K1) VerifyBytes

func (k PublicKeySECP256K1) VerifyBytes(msg []byte, sig []byte) bool

type Signature added in v0.11.0

type Signature struct {
	Index  int       `json:"index"` //index in the MultiSig
	PubKey PublicKey `json:"pubkey"`
	Signed []byte    `json:"signed"`
}

Jump to

Keyboard shortcuts

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