Documentation ¶
Index ¶
- func CheckWIF(wif string) (valid bool, err error)
- func NAF(k []byte) ([]byte, []byte)
- func SignCompact(curve *KoblitzCurve, key *PrivateKey, hash []byte, isCompressedKey bool) ([]byte, error)
- type KoblitzCurve
- func (curve *KoblitzCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)
- func (curve *KoblitzCurve) DecompressPoint(x *big.Int, ybit bool) (*big.Int, error)
- func (curve *KoblitzCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int)
- func (curve *KoblitzCurve) IsOnCurve(x, y *big.Int) bool
- func (curve *KoblitzCurve) Params() *elliptic.CurveParams
- func (curve *KoblitzCurve) QPlus1Div4() *big.Int
- func (curve *KoblitzCurve) ScalarBaseMult(k []byte) (*big.Int, *big.Int)
- func (curve *KoblitzCurve) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)
- type PrivateKey
- func (priv *PrivateKey) FromBytes(b []byte) (err error)
- func (priv *PrivateKey) FromWIF(wif string) (err error)
- func (p *PrivateKey) PubKey() *PublicKey
- func (p *PrivateKey) Sign(hash []byte) (*Signature, error)
- func (priv *PrivateKey) ToBytes() (b []byte)
- func (p *PrivateKey) ToECDSA() *ecdsa.PrivateKey
- func (priv *PrivateKey) ToWIF() (wif string)
- func (priv *PrivateKey) ToWIFC() (wifc string)
- type PublicKey
- func (pub *PublicKey) FromBytes(koblitzcurve *KoblitzCurve, b []byte) (err error)
- func (pub *PublicKey) ToAddress() (address string)
- func (pub *PublicKey) ToAddressUncompressed() (address string)
- func (pub *PublicKey) ToBytes() (b []byte)
- func (pub *PublicKey) ToBytesUncompressed() (b []byte)
- func (p *PublicKey) ToECDSA() *ecdsa.PublicKey
- type Signature
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckWIF ¶
CheckWIF checks that string wif is a valid Wallet Import Format or Wallet Import Format Compressed string. If it is not, err is populated with the reason.
func NAF ¶
NAF takes a positive integer k and returns the Non-Adjacent Form (NAF) as two byte slices. The first is where 1s will be. The second is where -1s will be. NAF is convenient in that on average, only 1/3rd of its values are non-zero. This is algorithm 3.30 from [GECC].
Essentially, this makes it possible to minimize the number of operations since the resulting ints returned will be at least 50% 0s.
func SignCompact ¶
func SignCompact(curve *KoblitzCurve, key *PrivateKey, hash []byte, isCompressedKey bool) ([]byte, error)
SignCompact produces a compact signature of the data in hash with the given private key on the given koblitz curve. The isCompressed parameter should be used to detail if the given signature should reference a compressed public key or not. If successful the bytes of the compact signature will be returned in the format: <(byte of 27+public key solution)+4 if compressed >< padded bytes for signature R><padded bytes for signature S> where the R and S parameters are padde up to the bitlengh of the curve.
Types ¶
type KoblitzCurve ¶
type KoblitzCurve struct { *elliptic.CurveParams H int // cofactor of the curve. // contains filtered or unexported fields }
KoblitzCurve supports a koblitz curve implementation that fits the ECC Curve interface from crypto/elliptic.
func (*KoblitzCurve) Add ¶
Add returns the sum of (x1,y1) and (x2,y2). Part of the elliptic.Curve interface.
func (*KoblitzCurve) DecompressPoint ¶
DecompressPoint decompresses coordinate x and ylsb (y's least significant bit)
and returns the value of y source: https://github.com/btcsuite/btcd/blob/807d344fe97072efdf38ac3df053e07f26187a4f/btcec/pubkey.go#L27
func (*KoblitzCurve) IsOnCurve ¶
func (curve *KoblitzCurve) IsOnCurve(x, y *big.Int) bool
IsOnCurve returns boolean if the point (x,y) is on the curve. Part of the elliptic.Curve interface. This function differs from the crypto/elliptic algorithm since a = 0 not -3.
func (*KoblitzCurve) Params ¶
func (curve *KoblitzCurve) Params() *elliptic.CurveParams
Params returns the parameters for the curve.
func (*KoblitzCurve) QPlus1Div4 ¶
func (curve *KoblitzCurve) QPlus1Div4() *big.Int
QPlus1Div4 returns the Q+1/4 constant for the curve for use in calculating square roots via exponention.
func (*KoblitzCurve) ScalarBaseMult ¶
ScalarBaseMult returns k*G where G is the base point of the group and k is a big endian integer. Part of the elliptic.Curve interface.
func (*KoblitzCurve) ScalarMult ¶
ScalarMult returns k*(Bx, By) where k is a big endian integer. Part of the elliptic.Curve interface.
type PrivateKey ¶
type PrivateKey ecdsa.PrivateKey
func NewPrivateKey ¶
func NewPrivateKey(koblitzcurve elliptic.Curve) (*PrivateKey, error)
GenerateKey generate PublicKey/PrivateKey from KoblitzCurve
func (*PrivateKey) FromBytes ¶
func (priv *PrivateKey) FromBytes(b []byte) (err error)
FromBytes converts a 32-byte byte slice to a Bitcoin private key and derives the corresponding public key.
func (*PrivateKey) FromWIF ¶
func (priv *PrivateKey) FromWIF(wif string) (err error)
FromWIF converts a Wallet Import Format string to a Bitcoin private key and derives the corresponding public key.
func (*PrivateKey) PubKey ¶
func (p *PrivateKey) PubKey() *PublicKey
PubKey returns the PublicKey corresponding to this private key.
func (*PrivateKey) Sign ¶
func (p *PrivateKey) Sign(hash []byte) (*Signature, error)
Sign generates an ECDSA signature for the provided hash (which should be the result of hashing a larger message) using the private key. Produced signature is deterministic (same message and same key yield the same signature) and canonical in accordance with RFC6979 and BIP0062.
func (*PrivateKey) ToBytes ¶
func (priv *PrivateKey) ToBytes() (b []byte)
ToBytes converts a Bitcoin private key to a 32-byte byte slice.
func (*PrivateKey) ToECDSA ¶
func (p *PrivateKey) ToECDSA() *ecdsa.PrivateKey
ToECDSA returns the private key as a *ecdsa.PrivateKey.
func (*PrivateKey) ToWIF ¶
func (priv *PrivateKey) ToWIF() (wif string)
ToWIF converts a Bitcoin private key to a Wallet Import Format string.
func (*PrivateKey) ToWIFC ¶
func (priv *PrivateKey) ToWIFC() (wifc string)
ToWIFC converts a private key to a Wallet Import Format string with the public key compressed flag.
type PublicKey ¶
func RecoverCompact ¶
func RecoverCompact(curve *KoblitzCurve, signature, hash []byte) (*PublicKey, bool, error)
RecoverCompact verifies the compact signature "signature" of "hash" for the Koblitz curve in "curve". If the signature matches then the recovered public key will be returned as well as a boolen if the original key was compressed or not, else an error will be returned.
func (*PublicKey) FromBytes ¶
func (pub *PublicKey) FromBytes(koblitzcurve *KoblitzCurve, b []byte) (err error)
TODO: Where is it used and what is it used for? FromBytes converts a byte slice (either with or without point compression) to a public key.
func (*PublicKey) ToAddressUncompressed ¶
ToAddressUncompressed converts a public key to an uncompressed address string.
func (*PublicKey) ToBytes ¶
ToBytes converts a public key to a 33-byte byte slice with point compression.
func (*PublicKey) ToBytesUncompressed ¶
ToBytesUncompressed converts a public key to a 65-byte byte slice without point compression.
type Signature ¶
Signature is a type representing an ecdsa signature.
func ParseDERSignature ¶
ParseDERSignature parses a signature in DER format for the curve type `curve` into a Signature type. If parsing according to the less strict BER format is needed, use ParseSignature.
func ParseSignature ¶
ParseSignature parses a signature in BER format for the curve type `curve' into a Signature type, perfoming some basic sanity checks. If parsing according to the more strict DER format is needed, use ParseDERSignature.
func (*Signature) IsEqual ¶
IsEqual compares this Signature instance to the one passed, returning true if both Signatures are equivalent. A signature is equivalent to another, if they both have the same scalar value for R and S.
func (*Signature) Serialize ¶
Serialize returns the ECDSA signature in the more strict DER format. Note that the serialized bytes returned do not include the appended hash type used in Bitcoin signature scripts.
encoding/asn1 is broken so we hand roll this output:
0x30 <length> 0x02 <length r> r 0x02 <length s> s