crypto

package
v0.0.0-...-2935fa7 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const AddressHexLength = 2 * AddressLength
View Source
const AddressLength = binary.Word160Length

Variables

View Source
var (
	ErrInvalidLengthCrypto        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCrypto          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupCrypto = fmt.Errorf("proto: unexpected end of group")
)
View Source
var ZeroAddress = Address{}

Functions

func EnsureEd25519PrivateKeyCorrect

func EnsureEd25519PrivateKeyCorrect(candidatePrivateKey ed25519.PrivateKey) error

Ensures the last 32 bytes of the ed25519 private key is the public key derived from the first 32 private bytes

func GetEthChainID

func GetEthChainID(ChainID string) *big.Int

func GetEthSignatureRecoveryID

func GetEthSignatureRecoveryID(ChainID string, parity *big.Int) *big.Int

func Keccak256

func Keccak256(data []byte) []byte

func Nonce

func Nonce(caller Address, nonce []byte) []byte

func PublicKeyLength

func PublicKeyLength(curveType CurveType) int

Returns the length in bytes of the public key

func RIPEMD160

func RIPEMD160(data []byte) []byte

func SHA256

func SHA256(data []byte) []byte

func SequenceNonce

func SequenceNonce(address Address, sequence uint64) []byte

Obtain a nearly unique nonce based on a monotonic account sequence number

Types

type Address

type Address binary.Word160

func AddressFromBytes

func AddressFromBytes(bs []byte) (address Address, err error)

Returns an address consisting of the first 20 bytes of bs, return an error if the bs does not have length exactly 20 but will still return either: the bytes in bs padded on the right or the first 20 bytes of bs truncated in any case.

func AddressFromHexString

func AddressFromHexString(str string) (Address, error)

func AddressFromWord256

func AddressFromWord256(addr binary.Word256) Address

func MaybeAddressFromBytes

func MaybeAddressFromBytes(bs []byte) (*Address, error)

Returns a pointer to an Address that is nil iff len(bs) == 0 otherwise does the same as AddressFromBytes

func MustAddressFromBytes

func MustAddressFromBytes(addr []byte) Address

func MustAddressFromHexString

func MustAddressFromHexString(str string) Address

func NewContractAddress

func NewContractAddress(caller Address, nonce []byte) (newAddr Address)

func NewContractAddress2

func NewContractAddress2(caller Address, salt [binary.Word256Bytes]byte, initcode []byte) (newAddr Address)

func (Address) Bytes

func (address Address) Bytes() []byte

Copy address and return a slice onto the copy

func (*Address) Marshal

func (address *Address) Marshal() ([]byte, error)

Gogo proto support

func (Address) MarshalJSON

func (address Address) MarshalJSON() ([]byte, error)

func (Address) MarshalText

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

func (*Address) MarshalTo

func (address *Address) MarshalTo(data []byte) (int, error)

func (*Address) Size

func (address *Address) Size() int

func (Address) String

func (address Address) String() string

func (*Address) Unmarshal

func (address *Address) Unmarshal(data []byte) error

func (*Address) UnmarshalJSON

func (address *Address) UnmarshalJSON(data []byte) error

func (*Address) UnmarshalText

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

func (Address) Word256

func (address Address) Word256() binary.Word256

type Addressable

type Addressable interface {
	// Get the 20 byte EVM address of this account
	GetAddress() Address
	// Public key from which the Address is derived
	GetPublicKey() *PublicKey
}

func NewAddressable

func NewAddressable(publicKey *PublicKey) Addressable

type Addresses

type Addresses []Address

func (Addresses) Len

func (as Addresses) Len() int

func (Addresses) Less

func (as Addresses) Less(i, j int) bool

func (Addresses) Swap

func (as Addresses) Swap(i, j int)

type CompactSecp256k1Signature

type CompactSecp256k1Signature struct {
	Secp256k1Signature
}

*

btcec layout is:
input:  [  v   |  r   |  s   ]
bytes:  [  1   |  32  |  32  ]
Where:
  v = 27 + recovery id (which of 4 possible x coords do we take as public key) (single byte but padded)
  r = encrypted random point
  s = signature proof

Signature layout required by btcec:
sig:    [  r   |  s   |  v  ]
bytes:  [  32  |  32  |  1  ]

func (*CompactSecp256k1Signature) Marshal

func (s *CompactSecp256k1Signature) Marshal() ([]byte, error)

func (*CompactSecp256k1Signature) Unmarshal

func (s *CompactSecp256k1Signature) Unmarshal(bs []byte) error

type CurveType

type CurveType uint32
const (
	CurveTypeUnset CurveType = iota
	CurveTypeEd25519
	CurveTypeSecp256k1
)

func CurveTypeFromString

func CurveTypeFromString(s string) (CurveType, error)

func (CurveType) ABCIType

func (k CurveType) ABCIType() string

func (CurveType) Byte

func (k CurveType) Byte() byte

Get this CurveType's 8 bit identifier as a byte

func (CurveType) String

func (k CurveType) String() string

type EIP155Signature

type EIP155Signature struct {
	Secp256k1Signature
}

func (*EIP155Signature) ToCompactSignature

func (s *EIP155Signature) ToCompactSignature() ([]byte, error)

Get btcec compact signature (our standard)

type ErrInvalidCurve

type ErrInvalidCurve uint32

func (ErrInvalidCurve) Error

func (curveType ErrInvalidCurve) Error() string

type PrivateKey

type PrivateKey struct {
	CurveType CurveType `protobuf:"varint,1,opt,name=CurveType,proto3,casttype=CurveType" json:"CurveType,omitempty"`
	// Note may need initialisation
	PublicKey            []byte   `protobuf:"bytes,2,opt,name=PublicKey,proto3" json:"PublicKey,omitempty"`
	PrivateKey           []byte   `protobuf:"bytes,3,opt,name=PrivateKey,proto3" json:"PrivateKey,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func GeneratePrivateKey

func GeneratePrivateKey(random io.Reader, curveType CurveType) (PrivateKey, error)

func PrivateKeyFromRawBytes

func PrivateKeyFromRawBytes(privateKeyBytes []byte, curveType CurveType) (PrivateKey, error)

func PrivateKeyFromSecret

func PrivateKeyFromSecret(secret string, curveType CurveType) PrivateKey

func (*PrivateKey) Descriptor

func (*PrivateKey) Descriptor() ([]byte, []int)

func (*PrivateKey) GetAddress

func (pk *PrivateKey) GetAddress() Address

func (PrivateKey) GetPublicKey

func (p PrivateKey) GetPublicKey() *PublicKey

func (*PrivateKey) Marshal

func (m *PrivateKey) Marshal() (dAtA []byte, err error)

func (*PrivateKey) MarshalTo

func (m *PrivateKey) MarshalTo(dAtA []byte) (int, error)

func (*PrivateKey) MarshalToSizedBuffer

func (m *PrivateKey) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*PrivateKey) ProtoMessage

func (*PrivateKey) ProtoMessage()

func (PrivateKey) RawBytes

func (p PrivateKey) RawBytes() []byte

func (*PrivateKey) Reset

func (m *PrivateKey) Reset()

func (PrivateKey) Sign

func (p PrivateKey) Sign(msg []byte) (*Signature, error)

func (*PrivateKey) Size

func (m *PrivateKey) Size() (n int)

func (PrivateKey) String

func (p PrivateKey) String() string

func (*PrivateKey) Unmarshal

func (m *PrivateKey) Unmarshal(dAtA []byte) error

func (*PrivateKey) XXX_DiscardUnknown

func (m *PrivateKey) XXX_DiscardUnknown()

func (*PrivateKey) XXX_Marshal

func (m *PrivateKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PrivateKey) XXX_Merge

func (m *PrivateKey) XXX_Merge(src proto.Message)

func (*PrivateKey) XXX_MessageName

func (*PrivateKey) XXX_MessageName() string

func (*PrivateKey) XXX_Size

func (m *PrivateKey) XXX_Size() int

func (*PrivateKey) XXX_Unmarshal

func (m *PrivateKey) XXX_Unmarshal(b []byte) error

type PublicKey

type PublicKey struct {
	CurveType            CurveType                                       `protobuf:"varint,1,opt,name=CurveType,proto3,casttype=CurveType" json:"CurveType,omitempty"`
	PublicKey            github_com_klyed_hivesmartchain_binary.HexBytes `protobuf:"bytes,2,opt,name=PublicKey,proto3,customtype=github.com/klyed/hivesmartchain/binary.HexBytes" json:"PublicKey"`
	XXX_NoUnkeyedLiteral struct{}                                        `json:"-"`
	XXX_unrecognized     []byte                                          `json:"-"`
	XXX_sizecache        int32                                           `json:"-"`
}

func PublicKeyFromBytes

func PublicKeyFromBytes(bs []byte, curveType CurveType) (*PublicKey, error)

Currently this is a stub that reads the raw bytes returned by key_client and returns an ed25519 public key.

func PublicKeyFromTendermintPubKey

func PublicKeyFromTendermintPubKey(pubKey tmCrypto.PubKey) (*PublicKey, error)

func (*PublicKey) AddressHashType

func (p *PublicKey) AddressHashType() string

func (*PublicKey) Descriptor

func (*PublicKey) Descriptor() ([]byte, []int)

func (*PublicKey) GetAddress

func (p *PublicKey) GetAddress() Address

func (*PublicKey) GetCurveType

func (m *PublicKey) GetCurveType() CurveType

func (*PublicKey) IsSet

func (p *PublicKey) IsSet() bool

func (*PublicKey) IsValid

func (p *PublicKey) IsValid() bool

func (*PublicKey) Marshal

func (m *PublicKey) Marshal() (dAtA []byte, err error)

func (*PublicKey) MarshalJSON

func (p *PublicKey) MarshalJSON() ([]byte, error)

func (*PublicKey) MarshalText

func (p *PublicKey) MarshalText() ([]byte, error)

func (*PublicKey) MarshalTo

func (m *PublicKey) MarshalTo(dAtA []byte) (int, error)

func (*PublicKey) MarshalToSizedBuffer

func (m *PublicKey) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*PublicKey) ProtoMessage

func (*PublicKey) ProtoMessage()

func (*PublicKey) Reset

func (m *PublicKey) Reset()

func (*PublicKey) Size

func (m *PublicKey) Size() (n int)

func (*PublicKey) String

func (p *PublicKey) String() string

func (PublicKey) TendermintAddress

func (p PublicKey) TendermintAddress() tmCrypto.Address

func (PublicKey) TendermintPubKey

func (p PublicKey) TendermintPubKey() tmCrypto.PubKey

func (*PublicKey) Unmarshal

func (m *PublicKey) Unmarshal(dAtA []byte) error

func (*PublicKey) UnmarshalJSON

func (p *PublicKey) UnmarshalJSON(text []byte) error

func (*PublicKey) UnmarshalText

func (p *PublicKey) UnmarshalText(text []byte) error

func (*PublicKey) Verify

func (p *PublicKey) Verify(msg []byte, signature *Signature) error

func (*PublicKey) XXX_DiscardUnknown

func (m *PublicKey) XXX_DiscardUnknown()

func (*PublicKey) XXX_Marshal

func (m *PublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PublicKey) XXX_Merge

func (m *PublicKey) XXX_Merge(src proto.Message)

func (*PublicKey) XXX_MessageName

func (*PublicKey) XXX_MessageName() string

func (*PublicKey) XXX_Size

func (m *PublicKey) XXX_Size() int

func (*PublicKey) XXX_Unmarshal

func (m *PublicKey) XXX_Unmarshal(b []byte) error

type PublicKeyJSON

type PublicKeyJSON struct {
	CurveType string
	PublicKey string
}

type Secp256k1Signature

type Secp256k1Signature struct {
	// Magic parity byte (value varies by implementation to carry additional information)
	V big.Int `json:"v"`
	R big.Int `json:"r"`
	S big.Int `json:"s"`
}

func (*Secp256k1Signature) BigRecoveryIndex

func (s *Secp256k1Signature) BigRecoveryIndex() *big.Int

func (*Secp256k1Signature) RecoveryIndex

func (s *Secp256k1Signature) RecoveryIndex() uint

Returns either 0 or 1 for the underlying parity of the public key solution

type Signable

type Signable interface {
	SignBytes(chainID string) ([]byte, error)
}

Signable is an interface for all signable things. It typically removes signatures before serializing.

type Signature

type Signature struct {
	CurveType            CurveType `protobuf:"varint,1,opt,name=CurveType,proto3,casttype=CurveType" json:"CurveType,omitempty"`
	Signature            []byte    `protobuf:"bytes,2,opt,name=Signature,proto3" json:"Signature,omitempty"`
	XXX_NoUnkeyedLiteral struct{}  `json:"-"`
	XXX_unrecognized     []byte    `json:"-"`
	XXX_sizecache        int32     `json:"-"`
}

func SignatureFromBytes

func SignatureFromBytes(bs []byte, curveType CurveType) (*Signature, error)

func (*Signature) Descriptor

func (*Signature) Descriptor() ([]byte, []int)

func (*Signature) GetCurveType

func (m *Signature) GetCurveType() CurveType

func (*Signature) GetEthSignature

func (sig *Signature) GetEthSignature(ChainID string) (*EIP155Signature, error)

func (*Signature) GetSignature

func (m *Signature) GetSignature() []byte

func (*Signature) Marshal

func (m *Signature) Marshal() (dAtA []byte, err error)

func (*Signature) MarshalTo

func (m *Signature) MarshalTo(dAtA []byte) (int, error)

func (*Signature) MarshalToSizedBuffer

func (m *Signature) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Signature) ProtoMessage

func (*Signature) ProtoMessage()

func (*Signature) RawBytes

func (sig *Signature) RawBytes() []byte

func (*Signature) Reset

func (m *Signature) Reset()

func (*Signature) Size

func (m *Signature) Size() (n int)

func (*Signature) String

func (sig *Signature) String() string

func (Signature) TendermintSignature

func (sig Signature) TendermintSignature() []byte

func (*Signature) Unmarshal

func (m *Signature) Unmarshal(dAtA []byte) error

func (*Signature) XXX_DiscardUnknown

func (m *Signature) XXX_DiscardUnknown()

func (*Signature) XXX_Marshal

func (m *Signature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Signature) XXX_Merge

func (m *Signature) XXX_Merge(src proto.Message)

func (*Signature) XXX_MessageName

func (*Signature) XXX_MessageName() string

func (*Signature) XXX_Size

func (m *Signature) XXX_Size() int

func (*Signature) XXX_Unmarshal

func (m *Signature) XXX_Unmarshal(b []byte) error

type Signer

type Signer interface {
	Sign(msg []byte) (*Signature, error)
}

type UserNameInterface

type UserNameInterface interface {
	UserNameJSON()
}

type UserNameJSON

type UserNameJSON struct {
	NativeName string
}

func (UserNameJSON) GetUserName

func (u UserNameJSON) GetUserName() UserNameJSON

func (*UserNameJSON) IsValid

func (u *UserNameJSON) IsValid() bool

func (*UserNameJSON) MarshalJSON

func (u *UserNameJSON) MarshalJSON() ([]byte, error)

func (*UserNameJSON) String

func (u *UserNameJSON) String() string

Jump to

Keyboard shortcuts

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