{"modulePath":"github.com/Evolution404/simcore","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package crypto\n\n## Constants\n\n```go\nconst DigestLength = 32\n```\nDigestLength sets the signature digest exact length\n\n```go\nconst RecoveryIDOffset = 64\n```\nRecoveryIDOffset points to the byte offset within the signature that contains the recovery id.\n\n```go\nconst SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id\n\n```\nSignatureLength indicates the byte length required to carry a signature with recovery id.\n\n## Functions\n\n```go\nfunc CompressPubkey(pubkey *ecdsa.PublicKey) []byte\n```\nCompressPubkey encodes a public key to the 33-byte compressed format.\n\n```go\nfunc CreateAddress(b common.Address, nonce uint64) common.Address\n```\nCreateAddress creates an ethereum address given the bytes and the nonce\n\n```go\nfunc CreateAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address\n```\nCreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.\n\n```go\nfunc DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)\n```\nDecompressPubkey parses a public key in the 33-byte compressed format.\n\n```go\nfunc Ecrecover(hash, sig []byte) ([]byte, error)\n```\nEcrecover returns the uncompressed public key that created the given signature.\n\n```go\nfunc FromECDSA(priv *ecdsa.PrivateKey) []byte\n```\nFromECDSA exports a private key into a binary dump.\n\n```go\nfunc FromECDSAPub(pub *ecdsa.PublicKey) []byte\n```\n\n```go\nfunc GenerateKey() (*ecdsa.PrivateKey, error)\n```\nGenerateKey generates a new private key.\n\n```go\nfunc HashData(kh KeccakState, data []byte) (h common.Hash)\n```\nHashData hashes the provided data using the KeccakState and returns a 32 byte hash\n\n```go\nfunc HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)\n```\nHexToECDSA parses a secp256k1 private key.\n\n```go\nfunc Keccak256(data ...[]byte) []byte\n```\nKeccak256 calculates and returns the Keccak256 hash of the input data.\n\n```go\nfunc Keccak256Hash(data ...[]byte) (h common.Hash)\n```\nKeccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.\n\n```go\nfunc Keccak512(data ...[]byte) []byte\n```\nKeccak512 calculates and returns the Keccak512 hash of the input data.\n\n```go\nfunc LoadECDSA(file string) (*ecdsa.PrivateKey, error)\n```\nLoadECDSA loads a secp256k1 private key from the given file.\n\n```go\nfunc PubkeyToAddress(p ecdsa.PublicKey) common.Address\n```\n\n```go\nfunc S256() elliptic.Curve\n```\nS256 returns an instance of the secp256k1 curve.\n\n```go\nfunc SaveECDSA(file string, key *ecdsa.PrivateKey) error\n```\nSaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.\n\n```go\nfunc SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)\n```\nSigToPub returns the public key that created the given signature.\n\n```go\nfunc Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)\n```\nSign calculates an ECDSA signature.\n\nThis 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.\n\nThe produced signature is in the \\[R || S || V] format where V is 0 or 1.\n\n```go\nfunc ToECDSA(d []byte) (*ecdsa.PrivateKey, error)\n```\nToECDSA creates a private key with the given D value.\n\n```go\nfunc ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey\n```\nToECDSAUnsafe 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).\n\n```go\nfunc UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)\n```\nUnmarshalPubkey converts bytes to a secp256k1 public key.\n\n```go\nfunc ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool\n```\nValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.\n\n```go\nfunc VerifySignature(pubkey, digestHash, signature []byte) bool\n```\nVerifySignature checks that the given public key created signature over digest. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte \\[R || S] format.\n\n## Types\n\n```go\ntype KeccakState interface {\n\thash.Hash\n\tRead([]byte) (int, error)\n}\n```\nKeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.\n\n```go\nfunc NewKeccakState() KeccakState\n```\nNewKeccakState creates a new KeccakState\n\n","path":"github.com/Evolution404/simcore/crypto","name":"crypto","synopsis":"","isRedistributable":true}
