account

package
v0.0.0-...-c17f0e7 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

GenerateKey generates a new random secp256k1 key

func NewKeyFromHexString

func NewKeyFromHexString(key string) (*ecdsa.PrivateKey, error)

NewKeyFromHexString creates a new PrivateKey from the provided hex string-representation. The hex key can be with/without the '0x' prefix. This function should not be used with direct user input as it performs minimal validation. Auto-generated input should be used (i.e. generated keys retrieved direct from Vault) or user-input from Quorum that should have been validated at the Quorum-level. Be careful if using direct user input as valid hex may not result in a valid ethereum private key.

func PrivateKeyToBytes

func PrivateKeyToBytes(key *ecdsa.PrivateKey) ([]byte, error)

PrivateKeyToBytes returns the bytes for the private component of the key, and if necessary, left-0 pads them to 32 bytes.

As outlined in https://github.com/openethereum/openethereum/issues/2263, 256 bit secp256k1 can generate valid keys that are shorter than 32 bytes. To protect against potential issues with variable lengths, key bytes should be left-0 padded.

common/math.PaddedBigBytes accomplishes this using bitwise operations for maximal performance. Given the additional HTTP overhead already introduced when using Vault, and to improve code-readability, standard slice functions have been used here.

func PrivateKeyToHexString

func PrivateKeyToHexString(key *ecdsa.PrivateKey) (string, error)

PrivateKeyToHexString encodes the provided key as a hex string

func Sign

func Sign(toSign []byte, key *ecdsa.PrivateKey) ([]byte, error)

Sign simply signs the data with the provided key using secp256k1. It performs no pre/post-computation of the data - if this is required it should be performed by the caller.

func Zero

func Zero(byt []byte)

Zero zeroes the bytes

func ZeroKey

func ZeroKey(key *ecdsa.PrivateKey)

ZeroKey zeroes the underlying bytes of the key

Types

type Account

type Account struct {
	Address Address
	URL     *url.URL
}

Account is a combination of Quorum address and location URL

type Address

type Address [addressLength]byte

Address is the Quorum account address

func NewAddress

func NewAddress(byt []byte) (Address, error)

NewAddress creates a new Address from the provided bytes. Minimal validation is performed.

func NewAddressFromHexString

func NewAddressFromHexString(addr string) (Address, error)

NewAddressFromHexString creates a new Address from the provided hex string-representation. The hexAddr can be with/without the '0x' prefix.

func PrivateKeyToAddress

func PrivateKeyToAddress(key *ecdsa.PrivateKey) (Address, error)

PrivateKeyToAddress derives the valid 20-byte Quorum address from the provided private key

func (Address) ToBytes

func (a Address) ToBytes() []byte

ToBytes returns the underlying bytes of the Address

func (Address) ToHexString

func (a Address) ToHexString() string

ToHexString encodes the Address as a hex string without the '0x' prefix

Jump to

Keyboard shortcuts

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