taproot

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const SecretKeyLength = 32

SecretKeyLength is the number of bytes in a SecretKey.

View Source
const SignatureLen = 64

SignatureLen is the number of bytes in a Signature.

Variables

This section is empty.

Functions

func GenKey

func GenKey(rand io.Reader) (SecretKey, PublicKey, error)

GenKey generates a new key-pair, from a source of randomness.

Errors returned by this function will only come from the reader. If you know that the reader will never return errors, you can rest assured that this function won't either.

func TaggedHash

func TaggedHash(tag string, datas ...[]byte) []byte

TaggedHash addes some domain separation to SHA-256.

This is the hash_tag function mentioned in BIP-340.

See: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification

Types

type PublicKey

type PublicKey []byte

PublicKey represents a public key for BIP-340 signatures.

This key allows verifying signatures produced with the corresponding secret key.

This is simply an array of 32 bytes.

func (PublicKey) Verify

func (pk PublicKey) Verify(sig Signature, m []byte) bool

Verify checks the integrity of a signature, using a public key.

Note that m is the hash of a message, and not the message itself.

type SecretKey

type SecretKey []byte

SecretKey represents a secret key for BIP-340 signatures.

This is simply an array of 32 bytes.

func (SecretKey) Public

func (s SecretKey) Public() (PublicKey, error)

Public calculates the public key corresponding to a given secret key.

This will return an error if the secret key is invalid.

See: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-generation

func (SecretKey) Sign

func (sk SecretKey) Sign(rand io.Reader, m []byte) (Signature, error)

Sign uses a secret key to create a new signature.

Note that m should be the hash of a message, and not the actual message.

This accepts a source of randomness, but nil can be passed to use entirely deterministic signatures. Adding randomness hardens the implementation against fault attacks, but isn't strictly necessary for security.

Without randomness, an atomic counter is used to also hedge against attacks.

Errors will be returned if the source of randomness produces an error, or if the secret key is invalid.

type Signature

type Signature []byte

Signature represents a signature according to BIP-340.

This should exactly SignatureLen = 64 bytes long.

This can only be produced using a secret key, but anyone with a public key can verify the integrity of the signature.

Jump to

Keyboard shortcuts

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