Documentation ¶
Index ¶
- Constants
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func CreateAddress(b types.Address, nonce uint64) types.Address
- func CreateAddress2(b types.Address, salt [32]byte, inithash []byte) types.Address
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func DecryptSymmetric(key []byte, cyphertext []byte) ([]byte, error)
- func EcRecover(ctx context.Context, data types.HexBytes, sig types.HexBytes) (types.Address, error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func EncryptSymmetric(key, plaintext []byte) ([]byte, error)
- func ExtractSignature(data, signature []byte) (*ecdsa.PublicKey, error)
- func ExtractSignatures(signaturePairs [][2]string) ([]string, error)
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
- func Keccak256(data ...[]byte) []byte
- func Keccak256Hash(data ...[]byte) (h types.Hash)
- func Keccak512(data ...[]byte) []byte
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func PubkeyToAddress(p ecdsa.PublicKey) types.Address
- func S256() elliptic.Curve
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)
- func Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
- func SignBytes(data []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
- func SignBytesAsHex(data []byte, identity *ecdsa.PrivateKey) (string, error)
- func SignStringAsHex(data string, identity *ecdsa.PrivateKey) (string, error)
- func TextAndHash(data []byte) ([]byte, string)
- func TextHash(data []byte) []byte
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func VerifySignatures(signaturePairs [][3]string) error
- type DHPair
- type EthereumCrypto
- func (c EthereumCrypto) DH(dhPair dr.DHPair, dhPub dr.Key) (dr.Key, error)
- func (c EthereumCrypto) Decrypt(mk dr.Key, authCiphertext, ad []byte) ([]byte, error)
- func (c EthereumCrypto) Encrypt(mk dr.Key, plaintext, ad []byte) ([]byte, error)
- func (c EthereumCrypto) GenerateDH() (dr.DHPair, error)
- func (c EthereumCrypto) KdfCK(ck dr.Key) (dr.Key, dr.Key)
- func (c EthereumCrypto) KdfRK(rk, dhOut dr.Key) (dr.Key, dr.Key, dr.Key)
Constants ¶
const DigestLength = 32
DigestLength sets the signature digest exact length
const RecoveryIDOffset = 64
RecoveryIDOffset points to the byte offset within the signature that contains the recovery id.
const SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id
SignatureLength indicates the byte length required to carry a signature with recovery id.
Variables ¶
This section is empty.
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func CreateAddress ¶
CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress2 ¶
CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func EncryptSymmetric ¶
func ExtractSignature ¶
ExtractSignature returns a public key for a given data and signature.
func ExtractSignatures ¶
ExtractSignatures extract from tuples of signatures content a public key DEPRECATED: use ExtractSignature
func FromECDSA ¶
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func SaveECDSA ¶
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
func Sign ¶
func Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
Sign calculates an ECDSA signature.
This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given digest cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.
The produced signature is in the [R || S || V] format where V is 0 or 1.
func SignBytes ¶
func SignBytes(data []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
SignBytes signs the hash of arbitrary data.
func SignBytesAsHex ¶
func SignBytesAsHex(data []byte, identity *ecdsa.PrivateKey) (string, error)
SignBytesAsHex signs the Keccak256 hash of arbitrary data and returns its hex representation.
func SignStringAsHex ¶
func SignStringAsHex(data string, identity *ecdsa.PrivateKey) (string, error)
SignStringAsHex signs the Keccak256 hash of arbitrary string and returns its hex representation.
func TextAndHash ¶
TextAndHash is a helper function that calculates a hash for the given message that can be safely used to calculate a signature from.
The hash is calulcated as
keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
This gives context to the signed message and prevents signing of transactions.
func TextHash ¶
TextHash is a helper function that calculates a hash for the given message that can be safely used to calculate a signature from.
The hash is calulcated as
keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
This gives context to the signed message and prevents signing of transactions.
func ToECDSA ¶
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe ¶
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
func UnmarshalPubkey ¶
UnmarshalPubkey converts bytes to a secp256k1 public key.
func VerifySignatures ¶
VerifySignatures verifies tuples of signatures content/hash/public key
Types ¶
type DHPair ¶
func (DHPair) PrivateKey ¶
type EthereumCrypto ¶
type EthereumCrypto struct{}
EthereumCrypto is an implementation of Crypto with cryptographic primitives recommended by the Double Ratchet Algorithm specification. However, some details are different, see function comments for details.
func (EthereumCrypto) Encrypt ¶
Encrypt uses a slightly different approach than in the algorithm specification: it uses AES-256-CTR instead of AES-256-CBC for security, ciphertext length and implementation complexity considerations.
func (EthereumCrypto) GenerateDH ¶
func (c EthereumCrypto) GenerateDH() (dr.DHPair, error)
See the Crypto interface.