Documentation ¶
Index ¶
- Constants
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func CreateAddress(b entity.Address, nonce uint64) entity.Address
- func CreateAddress2(b entity.Address, salt [32]byte, inithash []byte) entity.Address
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func Ecrecover(hash, sig []byte) ([]byte, 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 entity.Hash)
- func Keccak512(data ...[]byte) []byte
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func PubkeyToAddress(p ecdsa.PublicKey) entity.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 SignECDSA(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, digestHash, signature []byte) bool
- type KeccakState
Constants ¶
const DigestLength = 32
DigestLength设置签名摘要的精确长度
const RecoveryIDOffset = 64
RecoveryIDOffset points to the byte offset within the signature that contains the recovery id.
const SignatureLength = 64 + 1 // 64字节ECDSA签名+1字节恢复id
SignatureLength表示携带具有恢复id的签名所需的字节长度。
Variables ¶
This section is empty.
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func CreateAddress ¶
CreateAddress在给定字节和nonce的情况下创建以太坊地址
func CreateAddress2 ¶
CreateAddress2在给定地址字节、初始合同代码哈希和salt的情况下创建以太坊地址。
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func FromECDSAPub ¶
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA解析secp256k1私钥。
func Keccak256Hash ¶
Keccak256哈希计算并返回输入数据的Keccak256哈希,将其转换为内部哈希数据结构。
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA从给定文件加载secp256k1私钥。
func SaveECDSA ¶
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA将secp256k1私钥保存到具有限制权限的给定文件。密钥数据以十六进制编码保存。
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 SignECDSA ¶
func SignECDSA(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
Sign计算ECDSA签名。 此函数容易受到选定的明文攻击,这些攻击可能会泄漏有关用于签名的私钥的信息。 呼叫者必须意识到对手无法选择给定摘要。常见的解决方案是在计算签名之前对任何输入进行散列。 生成的签名采用[R | | S | V]格式,其中V为0或1。
func ToECDSAUnsafe ¶
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToecdsanSafe盲目地将二进制blob转换为私钥。除非您确信输入有效,并且希望避免由于错误的原点编码(0个前缀被截断)而导致的错误,否则几乎不应该使用它。
func UnmarshalPubkey ¶
UnmarshalPubkey converts bytes to a secp256k1 public key.
func ValidateSignatureValues ¶
ValidateSignatureValues验证签名值对于给定的链规则是否有效。假设v值为0或1。
func VerifySignature ¶
VerifySignature 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.
Types ¶
type KeccakState ¶
KeccakState包裹sha3。状态除了通常的散列方法外,它还支持读取以从散列状态获取可变数量的数据。Read比Sum快,因为它不复制内部状态,但也修改内部状态。