Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMalformedPrivateKey = errors.New("malformed private key")
ErrMalformedPrivateKey describes an error where a WIF-encoded private key cannot be decoded due to being improperly formatted. This may occur if the byte length is incorrect or an unexpected magic number was encountered.
Functions ¶
func Curve ¶
func Curve() *secp256k1.KoblitzCurve
Curve returns a pointer to a copy of the elliptical curve.
Types ¶
type WIF ¶
type WIF struct { // PrivKey is the private key being imported or exported. PrivKey secp256k1.PrivateKey // contains filtered or unexported fields }
WIF contains the individual components described by the Wallet Import Format (WIF). A WIF string is typically used to represent a private key and its associated address in a way that may be easily copied and imported into or exported from wallet software. WIF strings may be decoded into this structure by calling DecodeWIF or created with a user-provided private key by calling NewWIF.
func DecodeWIF ¶
DecodeWIF creates a new WIF structure by decoding the string encoding of the import format.
The WIF string must be a base58-encoded string of the following byte sequence:
- 2 bytes to identify the network, must be 0x80 for mainnet or 0xef for either testnet or the regression test network
- 1 extra byte
- 32 bytes of a binary-encoded, big-endian, zero-padded private key
- 4 bytes of checksum, must equal the first four bytes of the double SHA256 of every byte before the checksum in this sequence
If the base58-decoded byte sequence does not match this, DecodeWIF will return a non-nil error. ErrMalformedPrivateKey is returned when the WIF is of an impossible length. ErrChecksumMismatch is returned if the expected WIF checksum does not match the calculated checksum.
func NewWIF ¶
func NewWIF(privKey secp256k1.PrivateKey, params *chaincfg.Params) *WIF
NewWIF creates a new WIF structure to export an address and its private key as a string encoded in the Wallet Import Format. The compress argument specifies whether the address intended to be imported or exported was created by serializing the public key compressed rather than uncompressed.
func (*WIF) SerializePubKey ¶
SerializePubKey serializes the associated public key of the imported or exported private key in compressed format. The serialization format chosen depends on the value of w.ecType.