Documentation ¶
Index ¶
- Constants
- type ECDSAPrivateKey
- func (key *ECDSAPrivateKey) Add(tweak [32]byte) error
- func (key *ECDSAPrivateKey) ECDSAPublicKey() (*ECDSAPublicKey, error)
- func (key *ECDSAPrivateKey) ECDSASign(hash *Hash) (*ECDSASignature, error)
- func (key *ECDSAPrivateKey) Negate() error
- func (key *ECDSAPrivateKey) Serialize() *SerializedPrivateKey
- func (key ECDSAPrivateKey) String() string
- func (key *ECDSAPrivateKey) ToSchnorr() (*SchnorrKeyPair, error)
- type ECDSAPublicKey
- func (key *ECDSAPublicKey) Add(tweak [32]byte) error
- func (key *ECDSAPublicKey) ECDSAVerify(hash *Hash, signature *ECDSASignature) bool
- func (key *ECDSAPublicKey) IsEqual(target *ECDSAPublicKey) bool
- func (key *ECDSAPublicKey) Negate() error
- func (key *ECDSAPublicKey) Serialize() (*SerializedECDSAPublicKey, error)
- func (key ECDSAPublicKey) String() string
- func (key *ECDSAPublicKey) ToSchnorr() (*SchnorrPublicKey, error)
- type ECDSASignature
- type Hash
- type SchnorrKeyPair
- func (key *SchnorrKeyPair) Add(tweak [32]byte) error
- func (key *SchnorrKeyPair) SchnorrPublicKey() (*SchnorrPublicKey, error)
- func (key *SchnorrKeyPair) SchnorrSign(hash *Hash) (*SchnorrSignature, error)
- func (key *SchnorrKeyPair) SerializePrivateKey() *SerializedPrivateKey
- func (key SchnorrKeyPair) String() string
- type SchnorrPublicKey
- func (key *SchnorrPublicKey) Add(tweak [32]byte) error
- func (key *SchnorrPublicKey) IsEqual(target *SchnorrPublicKey) bool
- func (key *SchnorrPublicKey) SchnorrVerify(hash *Hash, signature *SchnorrSignature) bool
- func (key *SchnorrPublicKey) Serialize() (*SerializedSchnorrPublicKey, error)
- func (key SchnorrPublicKey) String() string
- type SchnorrSignature
- type SerializedECDSAPublicKey
- type SerializedECDSASignature
- type SerializedPrivateKey
- type SerializedSchnorrPublicKey
- type SerializedSchnorrSignature
Constants ¶
const ( // HashSize of array used to store hashes. See Hash. HashSize = 32 // SerializedPrivateKeySize defines the length in bytes of SerializedPrivateKey SerializedPrivateKeySize = 32 )
const SerializedECDSAPublicKeySize = 33
SerializedECDSAPublicKeySize defines the length in bytes of a SerializedECDSAPublicKey
const (
// SerializedECDSASignatureSize defines the length in bytes of SerializedECDSASignature
SerializedECDSASignatureSize = 64
)
const SerializedSchnorrPublicKeySize = 32
SerializedSchnorrPublicKeySize defines the length in bytes of a SerializedSchnorrPublicKey
const (
// SerializedSchnorrSignatureSize defines the length in bytes of SerializedSchnorrSignature
SerializedSchnorrSignatureSize = 64
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ECDSAPrivateKey ¶
type ECDSAPrivateKey struct {
// contains filtered or unexported fields
}
ECDSAPrivateKey is a type representing a Secp256k1 ECDSA private key.
func DeserializeECDSAPrivateKey ¶
func DeserializeECDSAPrivateKey(data *SerializedPrivateKey) (key *ECDSAPrivateKey, err error)
DeserializeECDSAPrivateKey returns a ECDSAPrivateKey type from a 32 byte private key. will verify it's a valid private key(Group Order > key > 0)
func DeserializeECDSAPrivateKeyFromSlice ¶
func DeserializeECDSAPrivateKeyFromSlice(data []byte) (key *ECDSAPrivateKey, err error)
DeserializeECDSAPrivateKeyFromSlice returns a ECDSAPrivateKey type from a serialized private key slice. will verify that it's 32 byte and it's a valid private key(Group Order > key > 0)
func GenerateECDSAPrivateKey ¶
func GenerateECDSAPrivateKey() (key *ECDSAPrivateKey, err error)
GenerateECDSAPrivateKey generates a random valid private key from `crypto/rand`
func (*ECDSAPrivateKey) Add ¶
func (key *ECDSAPrivateKey) Add(tweak [32]byte) error
Add a tweak to the private key by doing `key + tweak % Group Order`. this adds it in place. This is meant for creating BIP-32(HD) wallets
func (*ECDSAPrivateKey) ECDSAPublicKey ¶
func (key *ECDSAPrivateKey) ECDSAPublicKey() (*ECDSAPublicKey, error)
ECDSAPublicKey generates a PublicKey for the corresponding private key.
func (*ECDSAPrivateKey) ECDSASign ¶
func (key *ECDSAPrivateKey) ECDSASign(hash *Hash) (*ECDSASignature, error)
ECDSASign creates an ECDSA signature using the private key and the input hashed message. Notice: the [32] byte array *MUST* be a hash of a message.
func (*ECDSAPrivateKey) Negate ¶
func (key *ECDSAPrivateKey) Negate() error
Negate a private key in place.
func (*ECDSAPrivateKey) Serialize ¶
func (key *ECDSAPrivateKey) Serialize() *SerializedPrivateKey
Serialize a private key
func (ECDSAPrivateKey) String ¶
func (key ECDSAPrivateKey) String() string
String returns the ECDSAPrivateKey as the hexadecimal string
func (*ECDSAPrivateKey) ToSchnorr ¶
func (key *ECDSAPrivateKey) ToSchnorr() (*SchnorrKeyPair, error)
ToSchnorr converts an ECDSA private key to a schnorr keypair Note: You shouldn't sign using the same key in both ECDSA and Schnorr signatures. this function is for convenience when using BIP-32
type ECDSAPublicKey ¶
type ECDSAPublicKey struct {
// contains filtered or unexported fields
}
ECDSAPublicKey is a PublicKey type used to sign and verify ECDSA signatures. The struct itself is an opaque data type that should only be created via the supplied methods.
func DeserializeECDSAPubKey ¶
func DeserializeECDSAPubKey(serializedPubKey []byte) (*ECDSAPublicKey, error)
DeserializeECDSAPubKey deserializes a serialized ECDSA public key, verifying it's valid. it supports only compressed(33 bytes) public keys. it does not support uncompressed(65 bytes) or hybrid(65 bytes) keys.
func (*ECDSAPublicKey) Add ¶
func (key *ECDSAPublicKey) Add(tweak [32]byte) error
Add a tweak to the public key by doing `key + tweak*Generator`. this adds it in place. This is meant for creating BIP-32(HD) wallets
func (*ECDSAPublicKey) ECDSAVerify ¶
func (key *ECDSAPublicKey) ECDSAVerify(hash *Hash, signature *ECDSASignature) bool
ECDSAVerify verifies a ECDSA signature using the public key and the input hashed message. Notice: the [32] byte array *MUST* be a hash of a message you hashed yourself.
func (*ECDSAPublicKey) IsEqual ¶
func (key *ECDSAPublicKey) IsEqual(target *ECDSAPublicKey) bool
IsEqual returns true if target is the same as key.
func (*ECDSAPublicKey) Negate ¶
func (key *ECDSAPublicKey) Negate() error
Negate a public key in place. Equivalent to negating the private key and then generating the public key.
func (*ECDSAPublicKey) Serialize ¶
func (key *ECDSAPublicKey) Serialize() (*SerializedECDSAPublicKey, error)
Serialize serializes a ECDSA public key
func (ECDSAPublicKey) String ¶
func (key ECDSAPublicKey) String() string
String returns the ECDSAPublicKey as the hexadecimal string
func (*ECDSAPublicKey) ToSchnorr ¶
func (key *ECDSAPublicKey) ToSchnorr() (*SchnorrPublicKey, error)
ToSchnorr converts an ECDSA public key to a schnorr public key Note: You shouldn't sign with the same key in ECDSA and Schnorr signatures. this function is for convenience when using BIP-32
type ECDSASignature ¶
type ECDSASignature struct {
// contains filtered or unexported fields
}
ECDSASignature is a type representing a ECDSA Signature. The struct itself is an opaque data type that should only be created via the supplied methods.
func DeserializeECDSASignature ¶
func DeserializeECDSASignature(serializedSignature *SerializedECDSASignature) (*ECDSASignature, error)
DeserializeECDSASignature deserializes a 64 byte serialized ECDSA signature into a ECDSASignature type.
func DeserializeECDSASignatureFromSlice ¶
func DeserializeECDSASignatureFromSlice(data []byte) (signature *ECDSASignature, err error)
DeserializeECDSASignatureFromSlice returns a ECDSASignature type from a serialized signature slice. will verify that it's SerializedECDSASignatureSize bytes long
func (*ECDSASignature) IsEqual ¶
func (signature *ECDSASignature) IsEqual(target *ECDSASignature) bool
IsEqual returns true if target is the same as signature.
func (*ECDSASignature) Serialize ¶
func (signature *ECDSASignature) Serialize() *SerializedECDSASignature
Serialize returns a 64 byte serialized signature
func (ECDSASignature) String ¶
func (signature ECDSASignature) String() string
String returns the ECDSASignature as the hexadecimal string
type Hash ¶
Hash is a type encapsulating the result of hashing some unknown sized data. it typically represents Sha256 / Double Sha256.
type SchnorrKeyPair ¶
type SchnorrKeyPair struct {
// contains filtered or unexported fields
}
SchnorrKeyPair is a type representing a pair of Secp256k1 private and public keys. This can be used to create Schnorr signatures
func DeserializeSchnorrPrivateKey ¶
func DeserializeSchnorrPrivateKey(data *SerializedPrivateKey) (*SchnorrKeyPair, error)
DeserializeSchnorrPrivateKey returns a SchnorrKeyPair type from a 32 byte private key. will verify it's a valid private key(Group Order > key > 0)
func DeserializeSchnorrPrivateKeyFromSlice ¶
func DeserializeSchnorrPrivateKeyFromSlice(data []byte) (key *SchnorrKeyPair, err error)
DeserializeSchnorrPrivateKeyFromSlice returns a SchnorrKeyPair type from a serialized private key slice. will verify that it's 32 byte and it's a valid private key(Group Order > key > 0)
func GenerateSchnorrKeyPair ¶
func GenerateSchnorrKeyPair() (key *SchnorrKeyPair, err error)
GenerateSchnorrKeyPair generates a random valid private key from `crypto/rand`
func (*SchnorrKeyPair) Add ¶
func (key *SchnorrKeyPair) Add(tweak [32]byte) error
Add a tweak to the public key by doing `key + tweak % Group Order` and adjust the pub/priv keys according to parity. this adds it in place. This is meant for creating BIP-32(HD) wallets
func (*SchnorrKeyPair) SchnorrPublicKey ¶
func (key *SchnorrKeyPair) SchnorrPublicKey() (*SchnorrPublicKey, error)
SchnorrPublicKey generates a PublicKey for the corresponding private key.
func (*SchnorrKeyPair) SchnorrSign ¶
func (key *SchnorrKeyPair) SchnorrSign(hash *Hash) (*SchnorrSignature, error)
SchnorrSign creates a schnorr signature using the private key and the input hashed message. Notice: the [32] byte array *MUST* be a hash of a message.
func (*SchnorrKeyPair) SerializePrivateKey ¶
func (key *SchnorrKeyPair) SerializePrivateKey() *SerializedPrivateKey
SerializePrivateKey returns the private key in the keypair.
func (SchnorrKeyPair) String ¶
func (key SchnorrKeyPair) String() string
String returns the SchnorrKeyPair as the hexadecimal string
type SchnorrPublicKey ¶
type SchnorrPublicKey struct {
// contains filtered or unexported fields
}
SchnorrPublicKey is a PublicKey type used to sign and verify Schnorr signatures. The struct itself is an opaque data type that should only be created via the supplied methods.
func DeserializeSchnorrPubKey ¶
func DeserializeSchnorrPubKey(serializedPubKey []byte) (*SchnorrPublicKey, error)
DeserializeSchnorrPubKey deserializes a serialized schnorr public key, verifying it's valid.
func (*SchnorrPublicKey) Add ¶
func (key *SchnorrPublicKey) Add(tweak [32]byte) error
Add a tweak to the public key by doing `key + tweak*Generator`. this adds it in place. This is meant for creating BIP-32(HD) wallets
func (*SchnorrPublicKey) IsEqual ¶
func (key *SchnorrPublicKey) IsEqual(target *SchnorrPublicKey) bool
IsEqual returns true if target is the same as key.
func (*SchnorrPublicKey) SchnorrVerify ¶
func (key *SchnorrPublicKey) SchnorrVerify(hash *Hash, signature *SchnorrSignature) bool
SchnorrVerify verifies a schnorr signature using the public key and the input hashed message. Notice: the [32] byte array *MUST* be a hash of a message you hashed yourself.
func (*SchnorrPublicKey) Serialize ¶
func (key *SchnorrPublicKey) Serialize() (*SerializedSchnorrPublicKey, error)
Serialize serializes a schnorr public key
func (SchnorrPublicKey) String ¶
func (key SchnorrPublicKey) String() string
String returns the SchnorrPublicKey as the hexadecimal string
type SchnorrSignature ¶
type SchnorrSignature struct {
// contains filtered or unexported fields
}
SchnorrSignature is a type representing a Schnorr Signature. The struct itself is an opaque data type that should only be created via the supplied methods.
func DeserializeSchnorrSignature ¶
func DeserializeSchnorrSignature(serializedSignature *SerializedSchnorrSignature) *SchnorrSignature
DeserializeSchnorrSignature deserializes a 64 byte serialized schnorr signature into a SchnorrSignature type.
func DeserializeSchnorrSignatureFromSlice ¶
func DeserializeSchnorrSignatureFromSlice(data []byte) (signature *SchnorrSignature, err error)
DeserializeSchnorrSignatureFromSlice returns a SchnorrSignature type from a serialized signature slice. will verify that it's SerializedSchnorrSignatureSize bytes long
func (*SchnorrSignature) IsEqual ¶
func (signature *SchnorrSignature) IsEqual(target *SchnorrSignature) bool
IsEqual returns true if target is the same as signature.
func (*SchnorrSignature) Serialize ¶
func (signature *SchnorrSignature) Serialize() *SerializedSchnorrSignature
Serialize returns a 64 byte serialized signature
func (SchnorrSignature) String ¶
func (signature SchnorrSignature) String() string
String returns the SchnorrSignature as the hexadecimal string
type SerializedECDSAPublicKey ¶
type SerializedECDSAPublicKey [SerializedECDSAPublicKeySize]byte
SerializedECDSAPublicKey is a is a byte array representing the storage representation of a compressed ECDSAPublicKey
func (SerializedECDSAPublicKey) String ¶
func (serialized SerializedECDSAPublicKey) String() string
String returns the SerializedECDSAPublicKey as a hexadecimal string
type SerializedECDSASignature ¶
type SerializedECDSASignature [SerializedECDSASignatureSize]byte
SerializedECDSASignature is a is a byte array representing the storage representation of a ECDSASignature
func (SerializedECDSASignature) String ¶
func (serialized SerializedECDSASignature) String() string
String returns the SerializedECDSASignature as the hexadecimal string
type SerializedPrivateKey ¶
type SerializedPrivateKey [SerializedPrivateKeySize]byte
SerializedPrivateKey is a byte array representing the storage representation of a SchnorrKeyPair
func (SerializedPrivateKey) String ¶
func (key SerializedPrivateKey) String() string
String returns the SchnorrKeyPair as the hexadecimal string
type SerializedSchnorrPublicKey ¶
type SerializedSchnorrPublicKey [SerializedSchnorrPublicKeySize]byte
SerializedSchnorrPublicKey is a is a byte array representing the storage representation of a SchnorrPublicKey
func (SerializedSchnorrPublicKey) String ¶
func (serialized SerializedSchnorrPublicKey) String() string
String returns the SerializedSchnorrPublicKey as a hexadecimal string
type SerializedSchnorrSignature ¶
type SerializedSchnorrSignature [SerializedSchnorrSignatureSize]byte
SerializedSchnorrSignature is a is a byte array representing the storage representation of a SchnorrSignature
func (SerializedSchnorrSignature) String ¶
func (serialized SerializedSchnorrSignature) String() string
String returns the SerializedSchnorrSignature as the hexadecimal string