Documentation ¶
Index ¶
Constants ¶
const ( Secp256k1CompressedPublicKeySize = 33 Secp256k1UncompressedPublicKeySize = 65 )
Variables ¶
var ( ErrInvalidSignature = errors.New("signature verification failed") ErrInvalidSignatureLength = errors.New("invalid signature length") )
Functions ¶
Types ¶
type Ed25519PrivateKey ¶
type Ed25519PrivateKey struct {
// contains filtered or unexported fields
}
func Ed25519PrivateKeyFromBytes ¶
func Ed25519PrivateKeyFromBytes(key []byte) (*Ed25519PrivateKey, error)
func Ed25519PrivateKeyFromHex ¶
func Ed25519PrivateKeyFromHex(key string) (*Ed25519PrivateKey, error)
func GenerateEd25519Key ¶
func GenerateEd25519Key() (*Ed25519PrivateKey, error)
GenerateEd25519Key generates a new ed25519 key pair.
func (*Ed25519PrivateKey) Bytes ¶
func (pv *Ed25519PrivateKey) Bytes() []byte
func (*Ed25519PrivateKey) Hex ¶
func (pv *Ed25519PrivateKey) Hex() string
func (*Ed25519PrivateKey) PubKey ¶
func (pv *Ed25519PrivateKey) PubKey() *Ed25519PublicKey
type Ed25519PublicKey ¶
type Ed25519PublicKey struct {
// contains filtered or unexported fields
}
func Ed25519PublicKeyFromBytes ¶
func Ed25519PublicKeyFromBytes(key []byte) (*Ed25519PublicKey, error)
func (*Ed25519PublicKey) Bytes ¶
func (pub *Ed25519PublicKey) Bytes() []byte
type Secp256k1PrivateKey ¶
type Secp256k1PrivateKey struct {
// contains filtered or unexported fields
}
func GenerateSecp256k1Key ¶
func GenerateSecp256k1Key() (*Secp256k1PrivateKey, error)
GenerateSecp256k1Key generates a new secp256k1 private key.
func Secp256k1PrivateKeyFromHex ¶
func Secp256k1PrivateKeyFromHex(key string) (*Secp256k1PrivateKey, error)
func (*Secp256k1PrivateKey) Bytes ¶
func (pv *Secp256k1PrivateKey) Bytes() []byte
func (*Secp256k1PrivateKey) Hex ¶
func (pv *Secp256k1PrivateKey) Hex() string
func (*Secp256k1PrivateKey) PubKey ¶
func (pv *Secp256k1PrivateKey) PubKey() *Secp256k1PublicKey
func (*Secp256k1PrivateKey) Sign ¶
func (pv *Secp256k1PrivateKey) Sign(hash []byte) ([]byte, error)
Sign signs the given hash directly utilizing go-ethereum's Sign function. go-ethereum returns a secp256k1 signature, in [R || S || V] format where V is 0 or 1, 65 bytes long. We want to remove the recovery ID, so we return a 64 byte signature, in [R || S] format.
func (*Secp256k1PrivateKey) SignWithRecoveryID ¶
func (pv *Secp256k1PrivateKey) SignWithRecoveryID(hash []byte) ([]byte, error)
SignWithRecoveryID signs the given hash directly utilizing go-ethereum's Sign function. It includes go-ethereum's recovery ID, which while it is non-standard for Secp256k1, is very common in Bitcoin and Ethereum
type Secp256k1PublicKey ¶
type Secp256k1PublicKey struct {
// contains filtered or unexported fields
}
func Secp256k1PublicKeyFromBytes ¶
func Secp256k1PublicKeyFromBytes(key []byte) (*Secp256k1PublicKey, error)
func (*Secp256k1PublicKey) Bytes ¶
func (pub *Secp256k1PublicKey) Bytes() []byte
func (*Secp256k1PublicKey) Verify ¶
func (pub *Secp256k1PublicKey) Verify(sig []byte, hash []byte) error
Verify verifies the standard secp256k1 signature against the given hash. Caller of this function should make sure the signature is in one of the following two formats: - 65 bytes, [R || S || V] format. This is the standard format. - 64 bytes, [R || S] format.
Since `Verify` suppose to verify the signature produced from `Sign` function, it expects the signature to be 65 bytes long, and in [R || S || V] format where V is 0 or 1. In this implementation, we use `VerifySignature`, which doesn't care about the recovery ID, so it can also support 64 bytes [R || S] format signature like cometbft. e.g. this `Verify` function is able to verify multi-signature-schema like personal_sign, eip712, cometbft, etc., as long as the given signature is in supported format.