Documentation ¶
Index ¶
- Constants
- Variables
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func MaxSharedKeyLength(p ECCPublicKey) int
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func S256() elliptic.Curve
- func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
- func SignDecode(sign []byte) (r, s *big.Int, err error)
- func SignEncode(r, s *big.Int) []byte
- func ValidateSecpSigValues(v byte, r, s *big.Int) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- func VrfEval(priv ECCPrivateKey, m []byte) (index [32]byte, proof []byte)
- func VrfProofToHash(pub ECCPublicKey, m, proof []byte) (index [32]byte, err error)
- func VrfVerify(pub ECCPublicKey, seed, proof []byte, index [32]byte) bool
- type Cipher
- type ECCPrivateKey
- type ECCPublicKey
- type Hash
- type Secp256k1PrivateKey
- func (p *Secp256k1PrivateKey) ByteSize() int
- func (p *Secp256k1PrivateKey) FromBytes(priv []byte) (ECCPrivateKey, error)
- func (p *Secp256k1PrivateKey) FromECDSA(key *ecdsa.PrivateKey) ECCPrivateKey
- func (p *Secp256k1PrivateKey) GenerateShared(k ECCPublicKey, skLen, macLen int) (sk []byte, err error)
- func (p *Secp256k1PrivateKey) GetPublicKey() ECCPublicKey
- func (p *Secp256k1PrivateKey) Public() crypto.PublicKey
- func (p *Secp256k1PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)
- func (p *Secp256k1PrivateKey) ToBytes() []byte
- func (p *Secp256k1PrivateKey) ToECDSA() *ecdsa.PrivateKey
- func (p *Secp256k1PrivateKey) VrfEval(m []byte) (index [32]byte, proof []byte)
- type Secp256k1PublicKey
- func (p *Secp256k1PublicKey) ByteSize() int
- func (p *Secp256k1PublicKey) FromBytes(pub []byte) (ECCPublicKey, error)
- func (p *Secp256k1PublicKey) FromBytesNodeID(id []byte) ECCPublicKey
- func (p *Secp256k1PublicKey) FromECDSA(key *ecdsa.PublicKey) ECCPublicKey
- func (p *Secp256k1PublicKey) Hash256s(in ...[]byte) []byte
- func (p *Secp256k1PublicKey) PubkeyToAddress() []byte
- func (p *Secp256k1PublicKey) ToAddress() []byte
- func (p *Secp256k1PublicKey) ToBytes() []byte
- func (p *Secp256k1PublicKey) ToECDSA() *ecdsa.PublicKey
- func (p *Secp256k1PublicKey) ToNodeIDBytes() []byte
- func (p *Secp256k1PublicKey) VrfProofToHash(m, proof []byte) (index [32]byte, err error)
- func (p *Secp256k1PublicKey) VrfVerify(m, proof []byte, index [32]byte) bool
- type Secp256k1Signer
- func (s Secp256k1Signer) BytesToPriv(d []byte) (ECCPrivateKey, error)
- func (s Secp256k1Signer) BytesToPub(pub []byte) (ECCPublicKey, error)
- func (s Secp256k1Signer) GenerateKey() (priv ECCPrivateKey, err error)
- func (s Secp256k1Signer) Hasher() hash.Hash
- func (s Secp256k1Signer) LengthOfHash() int
- func (s Secp256k1Signer) LengthOfPrivateKey() int
- func (s Secp256k1Signer) LengthOfPublicKey() int
- func (s Secp256k1Signer) LengthOfSignature() int
- func (s Secp256k1Signer) Name() string
- func (s Secp256k1Signer) PrivToBytes(priv ECCPrivateKey) []byte
- func (s Secp256k1Signer) PubFromNodeId(nid []byte) []byte
- func (s Secp256k1Signer) PubToBytes(pub ECCPublicKey) []byte
- func (s Secp256k1Signer) PubToNodeIdBytes(pub []byte) ([]byte, error)
- func (s Secp256k1Signer) RecoverPub(hash, sig []byte) ([]byte, error)
- func (s Secp256k1Signer) Sign(priv []byte, hash []byte) (sig []byte, err error)
- func (s Secp256k1Signer) String() string
- func (s Secp256k1Signer) Verify(pub []byte, hash []byte, sig []byte) bool
Constants ¶
const ( HashLength = 32 SECP256K1SHA3 = "secp256k1_sha3" )
Variables ¶
var ( ErrInvalidCurve = errors.New("invalid elliptic curve") )
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func MaxSharedKeyLength ¶
func MaxSharedKeyLength(p ECCPublicKey) int
func Sign ¶
func Sign(hash []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 hash 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 SignEncode ¶
func VerifySignature ¶
VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.
func VrfProofToHash ¶
func VrfProofToHash(pub ECCPublicKey, m, proof []byte) (index [32]byte, err error)
Types ¶
type Cipher ¶
type Cipher interface { Name() string GenerateKey() (priv ECCPrivateKey, err error) Sign(priv []byte, hash []byte) (sig []byte, err error) Verify(pub []byte, hash []byte, sig []byte) bool RecoverPub(hash, sig []byte) ([]byte, error) PrivToBytes(priv ECCPrivateKey) []byte PubToBytes(pub ECCPublicKey) []byte BytesToPriv(d []byte) (ECCPrivateKey, error) BytesToPub(pub []byte) (ECCPublicKey, error) PubFromNodeId(id []byte) []byte PubToNodeIdBytes(pub []byte) ([]byte, error) Hasher() hash.Hash LengthOfPublicKey() int // number of bytes of public key LengthOfPrivateKey() int // number of bytes of private key LengthOfSignature() int // number of bytes of signature LengthOfHash() int // number of bytes of input Hash }
type ECCPrivateKey ¶
type ECCPrivateKey interface { elliptic.Curve crypto.Signer GetPublicKey() ECCPublicKey ToECDSA() *ecdsa.PrivateKey FromECDSA(key *ecdsa.PrivateKey) ECCPrivateKey ToBytes() []byte FromBytes(priv []byte) (ECCPrivateKey, error) VrfEval(m []byte) (index [32]byte, proof []byte) }
type ECCPublicKey ¶
type ECCPublicKey interface { elliptic.Curve ToECDSA() *ecdsa.PublicKey FromECDSA(key *ecdsa.PublicKey) ECCPublicKey ToBytes() []byte FromBytes(pub []byte) (ECCPublicKey, error) ToNodeIDBytes() []byte FromBytesNodeID(id []byte) ECCPublicKey ToAddress() []byte VrfProofToHash(m, proof []byte) (index [32]byte, err error) VrfVerify(m, proof []byte, index [32]byte) bool }
type Hash ¶
type Hash [HashLength]byte
type Secp256k1PrivateKey ¶
type Secp256k1PrivateKey ecdsa.PrivateKey
func (*Secp256k1PrivateKey) ByteSize ¶
func (p *Secp256k1PrivateKey) ByteSize() int
func (*Secp256k1PrivateKey) FromBytes ¶
func (p *Secp256k1PrivateKey) FromBytes(priv []byte) (ECCPrivateKey, error)
func (*Secp256k1PrivateKey) FromECDSA ¶
func (p *Secp256k1PrivateKey) FromECDSA(key *ecdsa.PrivateKey) ECCPrivateKey
func (*Secp256k1PrivateKey) GenerateShared ¶
func (p *Secp256k1PrivateKey) GenerateShared(k ECCPublicKey, skLen, macLen int) (sk []byte, err error)
func (*Secp256k1PrivateKey) GetPublicKey ¶
func (p *Secp256k1PrivateKey) GetPublicKey() ECCPublicKey
func (*Secp256k1PrivateKey) Public ¶
func (p *Secp256k1PrivateKey) Public() crypto.PublicKey
func (*Secp256k1PrivateKey) Sign ¶
func (p *Secp256k1PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)
func (*Secp256k1PrivateKey) ToBytes ¶
func (p *Secp256k1PrivateKey) ToBytes() []byte
func (*Secp256k1PrivateKey) ToECDSA ¶
func (p *Secp256k1PrivateKey) ToECDSA() *ecdsa.PrivateKey
type Secp256k1PublicKey ¶
func (*Secp256k1PublicKey) ByteSize ¶
func (p *Secp256k1PublicKey) ByteSize() int
func (*Secp256k1PublicKey) FromBytes ¶
func (p *Secp256k1PublicKey) FromBytes(pub []byte) (ECCPublicKey, error)
func (*Secp256k1PublicKey) FromBytesNodeID ¶
func (p *Secp256k1PublicKey) FromBytesNodeID(id []byte) ECCPublicKey
func (*Secp256k1PublicKey) FromECDSA ¶
func (p *Secp256k1PublicKey) FromECDSA(key *ecdsa.PublicKey) ECCPublicKey
func (*Secp256k1PublicKey) Hash256s ¶
func (p *Secp256k1PublicKey) Hash256s(in ...[]byte) []byte
func (*Secp256k1PublicKey) PubkeyToAddress ¶
func (p *Secp256k1PublicKey) PubkeyToAddress() []byte
func (*Secp256k1PublicKey) ToAddress ¶
func (p *Secp256k1PublicKey) ToAddress() []byte
func (*Secp256k1PublicKey) ToBytes ¶
func (p *Secp256k1PublicKey) ToBytes() []byte
func (*Secp256k1PublicKey) ToECDSA ¶
func (p *Secp256k1PublicKey) ToECDSA() *ecdsa.PublicKey
func (*Secp256k1PublicKey) ToNodeIDBytes ¶
func (p *Secp256k1PublicKey) ToNodeIDBytes() []byte
func (*Secp256k1PublicKey) VrfProofToHash ¶
func (p *Secp256k1PublicKey) VrfProofToHash(m, proof []byte) (index [32]byte, err error)
type Secp256k1Signer ¶
type Secp256k1Signer struct{}
func (Secp256k1Signer) BytesToPriv ¶
func (s Secp256k1Signer) BytesToPriv(d []byte) (ECCPrivateKey, error)
func (Secp256k1Signer) BytesToPub ¶
func (s Secp256k1Signer) BytesToPub(pub []byte) (ECCPublicKey, error)
func (Secp256k1Signer) GenerateKey ¶
func (s Secp256k1Signer) GenerateKey() (priv ECCPrivateKey, err error)
func (Secp256k1Signer) Hasher ¶
func (s Secp256k1Signer) Hasher() hash.Hash
func (Secp256k1Signer) LengthOfHash ¶
func (s Secp256k1Signer) LengthOfHash() int
func (Secp256k1Signer) LengthOfPrivateKey ¶
func (s Secp256k1Signer) LengthOfPrivateKey() int
func (Secp256k1Signer) LengthOfPublicKey ¶
func (s Secp256k1Signer) LengthOfPublicKey() int
func (Secp256k1Signer) LengthOfSignature ¶
func (s Secp256k1Signer) LengthOfSignature() int
func (Secp256k1Signer) Name ¶
func (s Secp256k1Signer) Name() string
func (Secp256k1Signer) PrivToBytes ¶
func (s Secp256k1Signer) PrivToBytes(priv ECCPrivateKey) []byte
func (Secp256k1Signer) PubFromNodeId ¶
func (s Secp256k1Signer) PubFromNodeId(nid []byte) []byte
func (Secp256k1Signer) PubToBytes ¶
func (s Secp256k1Signer) PubToBytes(pub ECCPublicKey) []byte
func (Secp256k1Signer) PubToNodeIdBytes ¶
func (s Secp256k1Signer) PubToNodeIdBytes(pub []byte) ([]byte, error)
func (Secp256k1Signer) RecoverPub ¶ added in v1.0.204
func (s Secp256k1Signer) RecoverPub(hash, sig []byte) ([]byte, error)
func (Secp256k1Signer) Sign ¶
func (s Secp256k1Signer) Sign(priv []byte, hash []byte) (sig []byte, err error)
func (Secp256k1Signer) String ¶
func (s Secp256k1Signer) String() string