Documentation ¶
Index ¶
- Constants
- func RecoverFromAdaptorAndSignature(adaptor *EncryptedSignature, encryptionKey *PublicKey, sig *Signature) (*secp256k1.ModNScalar, error)
- type EncryptedSignature
- func (s *EncryptedSignature) Decode(b []byte) error
- func (a *EncryptedSignature) Decrypt(sk *secp256k1.ModNScalar) (*Signature, error)
- func (s *EncryptedSignature) Encode() ([]byte, error)
- func (s *EncryptedSignature) MarshalJSON() ([]byte, error)
- func (s *EncryptedSignature) UnmarshalJSON(in []byte) error
- type Keypair
- type NonceFunc
- type Point
- func (p *Point) Add(a, b *Point)
- func (p *Point) BaseExp(k *secp256k1.ModNScalar)
- func (p *Point) Copy() *Point
- func (p *Point) Equal(other *Point) bool
- func (p *Point) Negate()
- func (p *Point) PutBytes(dst []byte)
- func (p *Point) Scale(point *Point, k *secp256k1.ModNScalar)
- func (p *Point) SetBytes(bc []byte) error
- func (p *Point) Sub(a, b *Point)
- func (p *Point) ToBytes() []byte
- func (p *Point) XY() (*secp256k1.FieldVal, *secp256k1.FieldVal, error)
- type PrivateKey
- type PublicKey
- func (k *PublicKey) Decode(b []byte) error
- func (k *PublicKey) Encode() ([]byte, error)
- func (k *PublicKey) EncodeDecompressed() ([]byte, error)
- func (k *PublicKey) MarshalJSON() ([]byte, error)
- func (k *PublicKey) UnmarshalJSON(in []byte) error
- func (k *PublicKey) Verify(msg []byte, sig *Signature) (bool, error)
- func (k *PublicKey) VerifyAdaptor(msg []byte, encryptionKey *PublicKey, adaptor *EncryptedSignature) (bool, error)
- type Signature
Constants ¶
const EncodedAdaptorSize = 33 + 33 + (32 * 3)
const MessageLength = 32
Variables ¶
This section is empty.
Functions ¶
func RecoverFromAdaptorAndSignature ¶
func RecoverFromAdaptorAndSignature(adaptor *EncryptedSignature, encryptionKey *PublicKey, sig *Signature) (*secp256k1.ModNScalar, error)
RecoverFromAdaptorAndSignature recovers the decryption key given an encrypted signature and the signature that was decrypted from it.
Types ¶
type EncryptedSignature ¶
type EncryptedSignature struct {
R, R_a *Point
// contains filtered or unexported fields
}
EncryptedSignature is an "encrypted" ECDSA signature aka adaptor signature (R || R_a || s || dleqProof).
func (*EncryptedSignature) Decode ¶
func (s *EncryptedSignature) Decode(b []byte) error
Decode parses bytes buffer `b` into EncryptedSignature.
func (*EncryptedSignature) Decrypt ¶
func (a *EncryptedSignature) Decrypt(sk *secp256k1.ModNScalar) (*Signature, error)
Decrypt function is used to decrypt an encrypted signature yielding the plain ECDSA signature.
* Before calling this method you should be certain that the EncryptedSignature is what you think it is by calling PublicKey.VerifyAdaptor on it first.
* Once you give the decrypted Signature to anyone who has seen EncryptedSignature, they will be able to learn decryption key aka secret by calling RecoverFromAdaptorAndSignature.
func (*EncryptedSignature) Encode ¶
func (s *EncryptedSignature) Encode() ([]byte, error)
Encode encodes EncryptedSignature into EncodedAdaptorSize bytes buffer as follows (R || R_a || s || proof.z | proof.s).
func (*EncryptedSignature) MarshalJSON ¶
func (s *EncryptedSignature) MarshalJSON() ([]byte, error)
MarshalJSON serializes EncryptedSignature into JSON format based on the Encode method.
func (*EncryptedSignature) UnmarshalJSON ¶
func (s *EncryptedSignature) UnmarshalJSON(in []byte) error
UnmarshalJSON deserializes EncryptedSignature from JSON formatted bytes based on the Decode method.
type Keypair ¶
type Keypair struct {
// contains filtered or unexported fields
}
Keypair defines pair of ECDSA PrivateKey and PublicKey.
func GenerateKeypair ¶
func GenerateKeypair() *Keypair
GenerateKeypair generates a random PrivateKey scalar and derives point on secp256k1 curve as a corresponding PublicKey. If private scalar generates no point on a curve, this step would be repeated until it is.
func KeypairFromHex ¶
KeypairFromHex decodes hex formatted (without "0x") string `s` into a Keypair.
func (*Keypair) AdaptorSign ¶
func (kp *Keypair) AdaptorSign(msg []byte, encKey *PublicKey, nonceFnOpt ...NonceFunc) (*EncryptedSignature, error)
AdaptorSign create an encrypted signature aka "adaptor signature" aka "pre-signature".
The `msg` param is a 32 bytes hash. Use `nonceFnOpt` to specify custom NonceFunc. Default is WithRFC6979.
func (*Keypair) Private ¶
func (kp *Keypair) Private() *PrivateKey
Private returns PrivateKey component.
type NonceFunc ¶
type NonceFunc = func() (*secp256k1.ModNScalar, error)
NonceFunc defines nonce generation algorithm.
func WithRFC6979 ¶
func WithRFC6979(sk *PrivateKey, msg []byte, encKey *PublicKey) NonceFunc
WithRFC6979 can be used to specify deterministic nonce generation based on the RFC-6979 spec.
This is the default way of generation nonce in this library.
func WithRandom ¶
func WithRandom() NonceFunc
WithRandom can be used to specify random nonce generation.
type Point ¶
type Point struct {
*secp256k1.JacobianPoint
}
Point is the library's internal elliptic curve point representation and is a wrapper around `secp256k1.JacobianPoint` https://github.com/decred/dcrd/tree/master/dcrec/secp256k1.
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey wraps secp256k1 scalar field being a secret component of the ECDSA scheme.
func (*PrivateKey) Decode ¶
func (k *PrivateKey) Decode(b []byte) error
Decode parses bytes buffer `b` into PrivateKey.
If buffer overflows 32 bytes error will be returned.
func (*PrivateKey) Encode ¶
func (k *PrivateKey) Encode() ([]byte, error)
Encode encodes PrivateKey into a 32 bytes buffer.
func (*PrivateKey) Inner ¶
func (k *PrivateKey) Inner() *secp256k1.ModNScalar
Inner returns secp256k1.ModNScalar behind PrivateKey.
func (*PrivateKey) MarshalJSON ¶
func (k *PrivateKey) MarshalJSON() ([]byte, error)
MarshalJSON serializes PrivateKey into JSON format based on the Encode method.
func (*PrivateKey) Public ¶
func (k *PrivateKey) Public() *PublicKey
Public derives PublicKey (X) by generating point with secret scalar (x): X = G^x.
func (*PrivateKey) UnmarshalJSON ¶
func (k *PrivateKey) UnmarshalJSON(in []byte) error
UnmarshalJSON deserializes JSON formatted bytes into PrivateKey.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey wraps point on the secp256k1 curve being a public component of the ECDSA scheme.
func (*PublicKey) Decode ¶
Decode decodes bytes buffer `b` into a PublicKey automatically recognizing compression type.
func (*PublicKey) Encode ¶
Encode encodes PublicKey into a 33 bytes buffer in a compressed form.
To comply with go-ethereum requirements first byte specifies this "type" (ie. compressed, uncompressed, or hybrid) https://github.com/quan8/go-ethereum/blob/a1c09b93871dd3770adffb177086abda1b2ff3af/vendor/github.com/btcsuite/btcd/btcec/pubkey.go#L69
func (*PublicKey) EncodeDecompressed ¶
EncodeDecompressed encodes PublicKey into a 64 bytes buffer in an uncompressed form (x||y).
func (*PublicKey) MarshalJSON ¶
MarshalJSON serializes PublicKey into JSON format based on the Encode method.
func (*PublicKey) UnmarshalJSON ¶
UnmarshalJSON deserializes JSON formatted bytes into PublicKey.
func (*PublicKey) Verify ¶
Verify verifies that given Signature was signed from a `msg` by the receiver PublicKey.
func (*PublicKey) VerifyAdaptor ¶
func (k *PublicKey) VerifyAdaptor(msg []byte, encryptionKey *PublicKey, adaptor *EncryptedSignature) (bool, error)
VerifyAdaptor verifies an encrypted signature is valid i.e. if it is decrypted it will yield a signature on `msg` under receiver PublicKey.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature is a standard ECDSA signature (v||r||s).
func (*Signature) Decode ¶
Decode parses 64/65 bytes buffer `b` into a receiver Signature.
In case `b` is 65 bytes the last 65-th byte would be decoded as `recovery_id` aka `v`.
func (*Signature) EncodeRecoverable ¶
EncodeRecoverable encodes Signature into a 65 bytes buffer where last byte is a `receiver_id` aka `v`.
func (*Signature) MarshalJSON ¶
MarshalJSON serializes Signature into JSON format based on the Encode method.
func (*Signature) UnmarshalJSON ¶
UnmarshalJSON deserializes JSON formatted bytes into Signature.