bitcoin

package
v0.0.0-...-f261603 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package bitcoin implements the bitcoin specific primitives.

Index

Constants

View Source
const (
	// SchnorrPublicKeySize is the size of a BIP-0340 Schnorr public key
	// in bytes.
	SchnorrPublicKeySize = 32
	// SchnorrSignatureSize is the size of a BIP-0340 Schnorr signature
	// in bytes.
	SchnorrSignatureSize = 64
)

Variables

This section is empty.

Functions

func IsValidSignatureEncodingBIP0066

func IsValidSignatureEncodingBIP0066(data []byte) bool

IsValidSignatureEncodingBIP0066 returns true iff `data` is encoded per BIP-0066, including the trailing `sighash` byte.

See: https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki

func PreHashSchnorrMessage

func PreHashSchnorrMessage(name string, msg []byte) ([]byte, error)

PreHashSchnorrMessage pre-hashes the message `msg`, with the domain-separator `name`, as suggested in BIP-0340. It returns the byte-encoded pre-hashed message.

Note: The spec is silent regarding 0-length `name` values. This implementation rejects them with an error, given that the main motivation for pre-hashing in the first place is domain-separation.

func VerifyASN1

func VerifyASN1(k *secec.PublicKey, digest, sig []byte) bool

VerifyASN1 verifies the BIP-0066 encoded signature `sig` of `digest`, using the PublicKey `k`, using the verification procedure as specified in SEC 1, Version 2.0, Section 4.1.4, with the additional restriction that `s` MUST be less than or equal to `n / 2`. Its return value records whether the signature is valid.

Note: The signature MUST have the trailing `sighash` byte.

Types

type SchnorrPrivateKey

type SchnorrPrivateKey struct {
	// contains filtered or unexported fields
}

SchnorrPrivateKey is a private key for sigining BIP-0340 Schnorr signatures.

func GenerateSchnorrKey

func GenerateSchnorrKey() (*SchnorrPrivateKey, error)

GenerateSchnorrKey generates a new SchnorrPrivateKey, using crypto/rand.Reader as the entropy source.

func NewSchnorrPrivateKey

func NewSchnorrPrivateKey(key []byte) (*SchnorrPrivateKey, error)

NewSchnorrPrivateKey checks that `key` is valid, and returns a SchnorrPrivateKey.

func NewSchnorrPrivateKeyFromECDSA

func NewSchnorrPrivateKeyFromECDSA(sk *secec.PrivateKey) *SchnorrPrivateKey

NewSchnorrPrivateKeyFromECDSA returns the SchnorrPrivateKey corresponding to the ECDSA PrivateKey `sk`.

func (*SchnorrPrivateKey) Bytes

func (k *SchnorrPrivateKey) Bytes() []byte

Bytes returns a copy of the encoding of the private key.

func (*SchnorrPrivateKey) Equal

Equal returns whether `x` represents the same private key as `k`. This check is performed in constant time as long as the key types match.

func (*SchnorrPrivateKey) Public

func (k *SchnorrPrivateKey) Public() crypto.PublicKey

func (*SchnorrPrivateKey) PublicKey

func (k *SchnorrPrivateKey) PublicKey() *SchnorrPublicKey

PublicKey returns the Schnorr public key corresponding to `k`.

func (*SchnorrPrivateKey) Scalar

func (k *SchnorrPrivateKey) Scalar() *secp256k1.Scalar

Scalar returns a copy of the scalar underlying `k`.

func (*SchnorrPrivateKey) Sign

func (k *SchnorrPrivateKey) Sign(rand io.Reader, msg []byte, _ crypto.SignerOpts) ([]byte, error)

Sign signs `msg` using the SchnorrPrivateKey `k`, using the signing procedure as specified in BIP-0340. It returns the byte-encoded signature.

Note: If `rand` is nil, crypto/rand.Reader will be used.

type SchnorrPublicKey

type SchnorrPublicKey struct {
	// contains filtered or unexported fields
}

SchnorrPublicKey is a public key for verifying BIP-0340 Schnorr signatures.

func NewSchnorrPublicKey

func NewSchnorrPublicKey(key []byte) (*SchnorrPublicKey, error)

NewSchnorrPublicKey checks that `key` is valid, and returns a SchnorrPublicKey.

func NewSchnorrPublicKeyFromECDSA

func NewSchnorrPublicKeyFromECDSA(pk *secec.PublicKey) *SchnorrPublicKey

NewSchnorrPublicKeyFromECDSA returns the SchnorrPublicKey corresponding to the ECDSA PrivateKey `sk`.

func NewSchnorrPublicKeyFromPoint

func NewSchnorrPublicKeyFromPoint(point *secp256k1.Point) (*SchnorrPublicKey, error)

NewSchnorrPublicKeyFromPoint checks that `point` is valid, and returns a SchnorrPublicKey.

Note: This routine accepts any point on the curve, and will fixup the Y-coordinate if required.

func (*SchnorrPublicKey) Bytes

func (k *SchnorrPublicKey) Bytes() []byte

Bytes returns a copy of the byte encoding of the public key.

func (*SchnorrPublicKey) Equal

func (k *SchnorrPublicKey) Equal(x crypto.PublicKey) bool

Equal returns whether `x` represents the same public key as `k`. This check is performed in constant time as long as the key types match.

func (*SchnorrPublicKey) Point

func (k *SchnorrPublicKey) Point() *secp256k1.Point

Point returns a copy of the point underlying `k`.

func (*SchnorrPublicKey) Verify

func (k *SchnorrPublicKey) Verify(msg, sig []byte) bool

Verify verifies the Schnorr signature `sig` of `msg`, using the SchnorrPublicKey `k`, using the verification procedure as specified in BIP-0340. Its return value records whether the signature is valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL