Documentation ¶
Index ¶
- func ECPubFromBytes(pkb B) (pub *ECPub, err E)
- func ECPubFromSchnorrBytes(xkb B) (pub *ECPub, err E)
- func FromSecretBytes(skb B) (pkb B, sec *Sec, pub *XPublicKey, ecPub *PublicKey, err error)
- func GenSec() (sec *Sec, err E)
- func Generate() (skb, pkb B, sec *Sec, pub *XPublicKey, ecpub *PublicKey, err E)
- func Msg(b B) (id *Uchar, err E)
- func Negate(uskb B)
- func PubFromBytes(pk B) (pub *Pub, err E)
- func RandomizeContext(ctx *C.secp256k1_context)
- func SecFromBytes(sk B) (sec *Sec, err E)
- func Sig(b B) (sig *Uchar, err E)
- func Sign(msg *Uchar, sk *SecKey) (sig B, err E)
- func SignFromBytes(msg, sk B) (sig B, err E)
- func Verify(msg, sig *Uchar, pk *PubKey) (valid bool)
- func VerifyFromBytes(msg, sig, pk B) (err error)
- func Zero(sk *SecKey)
- type B
- type Cint
- type Context
- type Ctx
- type E
- type ECPub
- type ECPubKey
- type Keygen
- type N
- type Pub
- type PubKey
- type PublicKey
- type S
- type Sec
- type SecKey
- type Signer
- func (s *Signer) ECDH(xkb B) (secret B, err error)
- func (s *Signer) ECPub() (b B)
- func (s *Signer) Generate() (err E)
- func (s *Signer) InitPub(pub B) (err error)
- func (s *Signer) InitSec(skb B) (err error)
- func (s *Signer) Negate()
- func (s *Signer) Pub() (b B)
- func (s *Signer) Sec() (b B)
- func (s *Signer) Sign(msg B) (sig B, err error)
- func (s *Signer) Verify(msg, sig B) (valid bool, err error)
- func (s *Signer) Zero()
- type Uchar
- type XPublicKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ECPubFromBytes ¶
ECPubFromBytes parses a pubkey from 33 bytes to the bitcoin-core/secp256k1 struct.
func ECPubFromSchnorrBytes ¶
ECPubFromSchnorrBytes converts a BIP-340 public key to its even standard 33 byte encoding.
This function is for the purpose of getting a key to do ECDH from an x-only key.
func FromSecretBytes ¶
FromSecretBytes parses and processes what should be a secret key. If it is a correct key within the curve order, but with a public key having an odd Y coordinate, it returns an error with the fixed key.
func Generate ¶
func Generate() (skb, pkb B, sec *Sec, pub *XPublicKey, ecpub *PublicKey, err E)
Generate gathers entropy to generate a full set of bytes and CGO values of it and derived from it to perform signature and ECDH operations.
Note that the pubkey bytes are the 33 byte form with the sign prefix, slice it off for X-only use.
func PubFromBytes ¶
func RandomizeContext ¶
func RandomizeContext(ctx *C.secp256k1_context)
func SecFromBytes ¶
func SignFromBytes ¶
func VerifyFromBytes ¶
Types ¶
type Context ¶
type Context = C.secp256k1_context
func CreateContext ¶
func CreateContext() *Context
func CreateRandomContext ¶
func CreateRandomContext() (c *Context)
type ECPubKey ¶
type ECPubKey = C.secp256k1_pubkey
type Keygen ¶
type Keygen struct {
// contains filtered or unexported fields
}
Keygen is an implementation of a key miner designed to be used for vanity key generation with X-only BIP-340 keys.
func NewKeygen ¶
func NewKeygen() (k *Keygen)
NewKeygen allocates the required buffers for deriving a key. This should only be done once to avoid garbage and make the key mining as fast as possible.
This allocates everything and creates proper CGO variables needed for the generate function so they only need to be allocated once per thread.
func (*Keygen) Generate ¶
Generate takes a pair of buffers for the secret and ec pubkey bytes and gathers new entropy and returns a valid secret key and the compressed pubkey bytes for the partial collision search.
The first byte of pubBytes must be sliced off before deriving the hex/Bech32 forms of the nostr public key.
func (*Keygen) KeyPairBytes ¶
func (*Keygen) Negate ¶
func (k *Keygen) Negate()
Negate should be called when the pubkey's X coordinate is a match but the prefix is a 3. The X coordinate will not change but this ensures that when the X-only key has a 2 prefix added for ECDH and other purposes that it works correctly. This can be done after a match is found as it does not impact anything except the first byte.
type PubKey ¶
type PubKey = C.secp256k1_xonly_pubkey
type PublicKey ¶
type PublicKey struct {
Key *C.secp256k1_pubkey
}
func NewPublicKey ¶
func NewPublicKey() *PublicKey
type SecKey ¶
type SecKey = C.secp256k1_keypair
type Signer ¶
type Signer struct { SecretKey *SecKey PublicKey *PubKey ECPublicKey *ECPubKey // not sure what this is useful for yet. BTCECSec *btcec.SecretKey // contains filtered or unexported fields }
Signer implements the nostr.I interface.
Either the Sec or Pub must be populated, the former is for generating signatures, the latter is for verifying them.
When using this library only for verification, a constructor that converts from bytes to PubKey is needed prior to calling Verify.
type XPublicKey ¶
type XPublicKey struct {
Key *C.secp256k1_xonly_pubkey
}
func NewXPublicKey ¶
func NewXPublicKey() *XPublicKey