Documentation ¶
Index ¶
- Variables
- func Base58Decode(inp []byte) ([]byte, error)
- func Base58Encode(input []byte) []byte
- func Bech32mencode(data []byte, hrp string, ver int) string
- func Convbits85(p []byte) []int
- func Encrypt(k PrKey, passphrase string) string
- func GetAddressETH(pubKey []byte) (string, error)
- func GetAddressP2PKH(pubKey []byte) (string, error)
- func GetAddressP2PKHUncomp(pubKey []byte) (string, error)
- func GetAddressP2SH(pubKey []byte) (string, error)
- func GetAddressP2TR(pubKey []byte) (string, error)
- func GetAddressP2WPKH(pubKey []byte) (string, error)
- func HashPubKey(pubKey []byte) []byte
- func Keccak256Hash(data []byte) (h []byte)
- func PointFromX(xb []byte, even bool) (x, y *big.Int)
- func PointFromXc(xb []byte, even bool) (*big.Int, *big.Int, error)
- func PubKey(k *big.Int, uncomp bool) []byte
- func PubKeyCompUncomp(k []byte, comp bool) ([]byte, error)
- func RandFieldElement(rand io.Reader) (k *big.Int, err error)
- func RandFieldElementEx(rand io.Reader, ex []byte) (k *big.Int, err error)
- type AddressType
- type PrKey
- func (k *PrKey) Address() (a string)
- func (k *PrKey) AddressT(at AddressType) (a string)
- func (k *PrKey) BIP38(p string) string
- func (k *PrKey) Bytes() []byte
- func (k *PrKey) GetAddressType() AddressType
- func (k *PrKey) Hex() string
- func (k *PrKey) IsUncomp() bool
- func (k *PrKey) PubK() []byte
- func (k *PrKey) Set(key big.Int) (*PrKey, error)
- func (k *PrKey) SetAddressType(t AddressType) (*PrKey, error)
- func (k *PrKey) SetBIP38(w, p string) (*PrKey, error)
- func (k *PrKey) SetBytes(b []byte) (*PrKey, error)
- func (k *PrKey) SetHex(khex string) (*PrKey, error)
- func (k *PrKey) SetUncomp(u bool) *PrKey
- func (k *PrKey) SetWIF(w string) (*PrKey, error)
- func (k *PrKey) WIF() string
- type Secp256k1C
- func (curve *Secp256k1C) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)
- func (curve *Secp256k1C) Double(x1, y1 *big.Int) (*big.Int, *big.Int)
- func (curve *Secp256k1C) IsOnCurve(x, y *big.Int) bool
- func (curve *Secp256k1C) Params() *Secp256k1C
- func (curve *Secp256k1C) ScalarBaseMult(k []byte) (*big.Int, *big.Int)
- func (curve *Secp256k1C) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)
Constants ¶
This section is empty.
Variables ¶
var ( PKeyOutOfR = errors.New("private key out of range") CoordOutOfR = errors.New("coordinate(s) out of range") NoSuchPoin = errors.New("no such point exists") InvHexStr = errors.New("invalid hex string") InvWIF = errors.New("invalid WIF") InvPubKeyF = errors.New("invalid public key format") InvWIFCSum = errors.New("invalid WIF checksum") InvAddrType = errors.New("invalid address type") BIP38InvCSum = errors.New("BIP38 checksum invalid") BIP38PassErr = errors.New("BIP38 wrong password") )
var B58Alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
Functions ¶
func Base58Decode ¶
Base58Decode decodes Base58-encoded data
func Base58Encode ¶
Base58Encode encodes a byte array to Base58
func Bech32mencode ¶
Bech32mencode encodes a segwit (Bech32 BIP 0173 / Bech32m BIP 0350) address.
func Convbits85 ¶
Convbits85 converts a byte slice (8 bits) to int slice (5 bits).
func Encrypt ¶
Encrypt returns the encrypted private key (BIP038) for the private key k. (no EC multiply).
func GetAddressETH ¶
GetAddressETH returns the Ethereum address (mixed-case checksum).
func GetAddressP2PKH ¶
GetAddressP2PKH returns the Pay-to-pubkey-hash Bitcoin address (compressed pubkey).
func GetAddressP2PKHUncomp ¶
GetAddressP2PKHUncomp returns the Pay-to-pubkey-hash Bitcoin address (uncompressed pubkey).
func GetAddressP2SH ¶
GetAddressP2SH returns the Pay-to-script-hash Bitcoin address.
func GetAddressP2TR ¶
GetAddressP2TR returns the Pay-to-taproot Bitcoin address with pubKey as internal key.
func GetAddressP2WPKH ¶
GetAddressP2WPKH returns the Pay-to-witness-pubkey-hash Bitcoin address.
func HashPubKey ¶
HashPubKey returns the Hash160 hash of the pubkey.
func Keccak256Hash ¶
Keccak256Hash returns the legacy Keccak256 hash of data
func PointFromX ¶
PointFromX returns the x and y coordinates of the point for which x coordinate and even/odd of y coordinate are given. WARNING!!! This function does not check is the coordinate valid and if the point exists. Use PointFromXc if yoy want to check.
func PointFromXc ¶
PointFromXc returns the x and y coordinates of the point for which x coordinate and even/odd of y coordinate are given. If the point does not exist, an error will be returned
func PubKey ¶
PubKey returns the public key of the private key k in compressed format if comp == true or in uncompressed format if comp == false.
func PubKeyCompUncomp ¶
PubKeyCompUncomp returns public key in compressed format if comp == true or in uncompressed format if comp == false. k - public key in compressed or uncompressed format. Returns nil and InvPubKeyF error if the public key format is invalid. WARNING!!! This function checks only the key format. If the point is not on the curve (or at infinity), the behavior is undefined. Use the IsOnCurve function to check this.
func RandFieldElement ¶
RandFieldElement returns a random element of the field underlying the given curve using the procedure given in [NSA] A.2.1.
Implementation copied from Go's crypto/ecdsa package since the function wasn't public.
func RandFieldElementEx ¶
RandFieldElementEx returns a random element of the field. It obtains input from two of sources (rand io.Reader and ex []byte) and mixes them. See https://datatracker.ietf.org/doc/html/rfc4086#section-5.1
Returned RandFieldElement(rand) if len(ex) == 0
Types ¶
type AddressType ¶
type AddressType uint
const ( P2PKH AddressType = iota // Pay-to-pubkey-hash P2PKHUncomp // Pay-to-pubkey-hash (uncompressed pubkey) P2SH // Pay-to-script-hash P2WPKH // Pay-to-witness-pubkey-hash P2TR // Pay-to-taproot ETH // Ethereum address (mixed-case checksum) MaxType )
Possible types of the addresses
type PrKey ¶
type PrKey struct {
// contains filtered or unexported fields
}
func (*PrKey) AddressT ¶
func (k *PrKey) AddressT(at AddressType) (a string)
AddressT returns an address of the given type
func (*PrKey) GetAddressType ¶
func (k *PrKey) GetAddressType() AddressType
func (*PrKey) Set ¶
Set set k.k. to the value of key and returns k, nil. nil, PKeyOutOfR will be returned if k < 1 or k greater than the order of the base point - 1.
func (*PrKey) SetAddressType ¶
func (k *PrKey) SetAddressType(t AddressType) (*PrKey, error)
SetAddressType sets k.a to t and returns k, error. If error != nil, (nil, error) returned.
func (*PrKey) SetBIP38 ¶
SetBIP38 tries to decrypt the BIP38 encrypted private key w with a password p, sets k.k to its value and returns k, error. If error != nil, (nil, error) returned.
func (*PrKey) SetBytes ¶
SetBytes interprets b as the bytes of a big-endian unsigned integer, sets k.k to that value, and returns k, error. If error != nil, (nil, error) returned.
func (*PrKey) SetHex ¶
SetHex set k.k to the value of khex, interpreted as base 16 and returns k, error. khex must be 64 hex digits long and may be prefixed with "0X" or "0x". If error != nil, (nil, error) returned.
type Secp256k1C ¶
type Secp256k1C struct { P *big.Int // the order of the underlying field N *big.Int // the order of the base point B *big.Int // the constant of the Secp256k1C equation Gx, Gy *big.Int // (x,y) of the base point BitSize int // the size of the underlying field }
func Secp256k1 ¶
func Secp256k1() *Secp256k1C
func (*Secp256k1C) IsOnCurve ¶
func (curve *Secp256k1C) IsOnCurve(x, y *big.Int) bool
IsOnCurve returns true if the given (x,y) lies on the BitCurve.
func (*Secp256k1C) Params ¶
func (curve *Secp256k1C) Params() *Secp256k1C