Documentation
¶
Index ¶
- Variables
- func CreateWallets(n int, path string)
- func DoubleSHA256(b []byte) []byte
- func IsOdd(n *big.Int) bool
- func ModInverse(n, mod *big.Int) *big.Int
- func Ripemd160SHA256(b []byte) []byte
- func Root(args []string) error
- func ValidKey(scalar *big.Int) bool
- func VerifyMessage(message *BitcoinMessage, electrum bool) (verified bool, pubkey string, result string, err error)
- type BitcoinMessage
- type CreateWalletCommand
- type JacobianPoint
- func (pt *JacobianPoint) Add(p, q *JacobianPoint) *JacobianPoint
- func (pt *JacobianPoint) Dbl(p *JacobianPoint) *JacobianPoint
- func (pt *JacobianPoint) Eq(q *JacobianPoint) bool
- func (pt *JacobianPoint) Mul(scalar *big.Int, p *JacobianPoint) *JacobianPoint
- func (pt *JacobianPoint) String() string
- func (pt *JacobianPoint) ToAffine() *Point
- type Point
- type PointError
- type PrivateKey
- type PrivateKeyError
- type Runner
- type Secp256k1
- type SignCommand
- type Signature
- type SignatureError
- type VerifyCommand
- type Wallet
Constants ¶
This section is empty.
Variables ¶
var (
OutOfRangeError = &PrivateKeyError{Message: "scalar is out of range"}
)
Functions ¶
func CreateWallets ¶
func DoubleSHA256 ¶
DoubleSHA256 calculates the SHA256 hash of the input byte slice twice.
Parameter:
- b: input byte slice to be hashed.
Returns: The double SHA256 hashed byte slice.
func IsOdd ¶
IsOdd checks if the given big.Int is odd.
It takes a pointer to a big.Int as a parameter. It returns a boolean indicating whether the number is odd or not.
func ModInverse ¶
ModInverse calculates the modular inverse of a number.
It takes two parameters: n and mod, both of type *big.Int. The function returns a pointer to a new *big.Int representing the modular inverse of n modulo mod.
func Ripemd160SHA256 ¶
Ripemd160SHA256 computes the RIPEMD160 hash of the SHA-256 hash of the input byte slice.
Parameter:
- b: input byte slice to be hashed.
Returns: The RIPEMD160 hashed byte slice.
func ValidKey ¶
ValidKey checks if the given big.Int scalar is a valid key.
Parameters:
- scalar: a pointer to a big.Int representing the scalar value.
Returns:
- bool: true if the scalar is valid, false otherwise.
func VerifyMessage ¶
func VerifyMessage(message *BitcoinMessage, electrum bool) (verified bool, pubkey string, result string, err error)
VerifyMessage verifies a signed message using the provided address, message, signature, and electrum flag.
Parameters:
- address: the address used to sign the message.
- message: the message to be verified.
- signature: the signature to verify the message.
- electrum: a flag indicating whether to use the electrum signature format.
Returns:
- bool: true if the message is verified, false otherwise.
- string: the hex-encoded public key.
- string: a message indicating whether the message was verified or not.
- error: an error if any occurred during the verification process.
Types ¶
type BitcoinMessage ¶
func SignMessage ¶
func SignMessage(pk *PrivateKey, addrType, message string, deterministic, electrum bool) (*BitcoinMessage, error)
SignMessage generates a Bitcoin message signature using the provided private key, address type, message, deterministic flag, and electrum flag.
Parameters:
- pk: A pointer to a PrivateKey struct representing the private key. Compressed private key will produce compressed public key and address. Uncompressed private key will only produce one address type - uncompressed legacy address
- addrType: A string representing the address type. It can be either p2pkh (compressed and uncompressed), p2wpkh-p2sh or p2wpkh (only compressed).
- message: A string representing the message.
- deterministic: A boolean indicating whether the signature should be deterministic. If set to true, each unique combination of private key and message will yield only one signature
- electrum: A boolean indicating whether the signature should be in Electrum format.
Returns:
- A pointer to a BitcoinMessage struct representing the signed message.
- An error if there was a problem signing the message.
type CreateWalletCommand ¶
type CreateWalletCommand struct {
// contains filtered or unexported fields
}
func NewCreateWalletCommand ¶
func NewCreateWalletCommand() *CreateWalletCommand
func (*CreateWalletCommand) Init ¶
func (cwc *CreateWalletCommand) Init(args []string) error
func (*CreateWalletCommand) Name ¶
func (cwc *CreateWalletCommand) Name() string
func (*CreateWalletCommand) Run ¶
func (cwc *CreateWalletCommand) Run() error
type JacobianPoint ¶
func NewJacobianPoint ¶
func NewJacobianPoint(x, y, z *big.Int) *JacobianPoint
NewJacobianPoint creates a new JacobianPoint with the given coordinates.
Parameters:
- x: a pointer to a big.Int representing the x-coordinate.
- y: a pointer to a big.Int representing the y-coordinate.
- z: a pointer to a big.Int representing the z-coordinate.
Returns:
- a pointer to a JacobianPoint struct representing the new point.
func (*JacobianPoint) Add ¶
func (pt *JacobianPoint) Add(p, q *JacobianPoint) *JacobianPoint
Add performs elliptic curve point addition in Jacobian coordinates for the secp256k1 curve.
It takes two JacobianPoint points p and q as input parameters and returns a JacobianPoint point.
Parameters:
- p: a pointer to a JacobianPoint representing the first point.
- q: a pointer to a JacobianPoint representing the second point.
Returns:
- a pointer to a JacobianPoint representing the sum of p and q.
Fast Prime Field Elliptic Curve Cryptography with 256 Bit Primes Shay Gueron, Vlad Krasnov https://eprint.iacr.org/2013/816.pdf page 4
func (*JacobianPoint) Dbl ¶
func (pt *JacobianPoint) Dbl(p *JacobianPoint) *JacobianPoint
Dbl performs a point doubling operation in the elliptic curve cryptography with 256 Bit Primes.
Parameter:
- p: a pointer to a JacobianPoint struct representing the point to be doubled.
Returns: A pointer to a JacobianPoint struct representing the result of the point doubling operation.
Fast Prime Field Elliptic Curve Cryptography with 256 Bit Primes Shay Gueron, Vlad Krasnov https://eprint.iacr.org/2013/816.pdf page 4
func (*JacobianPoint) Eq ¶
func (pt *JacobianPoint) Eq(q *JacobianPoint) bool
Eq compares the current JacobianPoint with another JacobianPoint.
Parameters:
- q: the JacobianPoint to compare with.
Returns:
- bool: true if the points are equal, false otherwise.
func (*JacobianPoint) Mul ¶
func (pt *JacobianPoint) Mul(scalar *big.Int, p *JacobianPoint) *JacobianPoint
Mul performs elliptic curve multiplication.
It takes two parameters:
- scalar: a pointer to a big.Int representing the scalar value.
- p: a pointer to a JacobianPoint representing the point to be multiplied.
It returns a pointer to a JacobianPoint representing the result of the multiplication.
https://paulmillr.com/posts/noble-secp256k1-fast-ecc/#fighting-timing-attacks
func (*JacobianPoint) String ¶
func (pt *JacobianPoint) String() string
String returns a string representation of the JacobianPoint struct.
It returns a string in the format "(x=<X>, y=<Y>, z=<Z>)", where <X>, <Y> and <Z> are the string representations of the X, Y and Z coordinates of the JacobianPoint.
func (*JacobianPoint) ToAffine ¶
func (pt *JacobianPoint) ToAffine() *Point
ToAffine converts a point from Jacobian coordinates to affine coordinates.
Parameter:
- p: the point in Jacobian coordinates.
Returns: A pointer to a Point representing the point in affine coordinates.
type Point ¶
func (*Point) String ¶
String returns a string representation of the Point struct.
It returns a string in the format "(x=<X>, y=<Y>)", where <X> and <Y> are the string representations of the X and Y coordinates of the Point.
func (*Point) ToJacobian ¶
func (pt *Point) ToJacobian() *JacobianPoint
ToJacobian converts a point from affine coordinates to Jacobian coordinates.
Parameter:
- p: a pointer to a Point representing the point in affine coordinates.
Returns: A pointer to a JacobianPoint representing the point in Jacobian coordinates.
type PointError ¶
func (*PointError) Error ¶
func (e *PointError) Error() string
func (*PointError) Unwrap ¶
func (e *PointError) Unwrap() error
type PrivateKey ¶
func NewPrivateKey ¶
func NewPrivateKey(raw *big.Int, wif *string) (*PrivateKey, error)
NewPrivateKey generates a new PrivateKey object.
It takes in two parameters:
- raw: a pointer to a big.Int object representing the raw value of the private key.
- wif: a pointer to a string representing the WIF (Wallet Import Format) of the private key.
The function returns a pointer to a PrivateKey object and an error.
- If both raw and wif are provided, it returns an error.
- If neither raw nor wif is provided, it generates a random private key and returns a new PrivateKey object.
- If only wif is provided, it creates a new PrivateKey object with the provided WIF.
- If only raw is provided, it creates a new PrivateKey object with the provided raw value.
The function checks if the generated or provided private key is valid. If the private key is invalid, it returns an error.
The function also encodes the generated or provided private key using the Wif() method. If the encoding fails, it returns an error.
The function returns a pointer to the newly created PrivateKey object.
func (*PrivateKey) SplitBytes ¶
func (k *PrivateKey) SplitBytes() (version []byte, payload []byte, checkSum []byte, err error)
SplitBytes splits the private key bytes into three parts: the version byte, the private key bytes, and the checksum bytes.
It takes no parameters. It returns three byte slices: the version byte, the private key bytes, and the checksum bytes.
func (*PrivateKey) ToInt ¶
func (k *PrivateKey) ToInt() (uncompressed bool, err error)
Int calculates the integer value of the private key.
It returns a boolean indicating if the key is uncompressed and an error if any.
type PrivateKeyError ¶
func (*PrivateKeyError) Error ¶
func (e *PrivateKeyError) Error() string
func (*PrivateKeyError) Unwrap ¶
func (e *PrivateKeyError) Unwrap() error
type SignCommand ¶
type SignCommand struct {
// contains filtered or unexported fields
}
func NewSignCommand ¶
func NewSignCommand() *SignCommand
func (*SignCommand) Init ¶
func (sc *SignCommand) Init(args []string) error
func (*SignCommand) Name ¶
func (sc *SignCommand) Name() string
func (*SignCommand) Run ¶
func (sc *SignCommand) Run() error
type SignatureError ¶
func (*SignatureError) Error ¶
func (e *SignatureError) Error() string
func (*SignatureError) Unwrap ¶
func (e *SignatureError) Unwrap() error
type VerifyCommand ¶
type VerifyCommand struct {
// contains filtered or unexported fields
}
func NewVerifyCommand ¶
func NewVerifyCommand() *VerifyCommand
func (*VerifyCommand) Init ¶
func (vc *VerifyCommand) Init(args []string) error
func (*VerifyCommand) Name ¶
func (vc *VerifyCommand) Name() string
func (*VerifyCommand) Run ¶
func (vc *VerifyCommand) Run() error
type Wallet ¶
type Wallet struct { PrivKey *PrivateKey RawPubKey *Point PubKey string Legacy string Nested string Native string }
func CreateNewWallet ¶
func CreateNewWallet() *Wallet
CreateNewWallet generates a new wallet with private key, public key, and various address types.
Returns:
- A pointer to a Wallet struct representing the new wallet.
func (*Wallet) String ¶
String returns a formatted string representation of the Wallet.
It concatenates the private key (raw), private key (WIF), public key (raw), public key (hex compressed), legacy address, nested segwit address, and native segwit address into a single string.
Returns:
- A string containing the formatted representation of the Wallet.