utils

package
v0.0.0-...-3680526 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChecksumMismatch = errors.New("checksum mismatch")

ErrChecksumMismatch describes an error where decoding failed due to a bad checksum.

View Source
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 AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func Decode

func Decode(val []byte, obj interface{}) error

func Encode

func Encode(s interface{}) ([]byte, error)

func FileCopy

func FileCopy(src, dst string) (int64, error)

func FileExists

func FileExists(filePath string) (bool, error)

FileExists reports whether the named file or directory exists.

func GetNetParams

func GetNetParams(name string) *params.Params

GetNetParams by network name

func GetUserDataDir

func GetUserDataDir() string

GetUserDataDir get user data dir

func MakeDirAll

func MakeDirAll(path string) error

MakeDirAll make dir

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens web brower

Types

type WIF

type WIF struct {
	// PrivKey is the private key being imported or exported.
	PrivKey *secp256k1.PrivateKey

	// CompressPubKey specifies whether the address controlled by the
	// imported or exported private key was created by hashing a
	// compressed (33-byte) serialized public key, rather than an
	// uncompressed (65-byte) one.
	CompressPubKey bool
	// 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

func DecodeWIF(wif string, net *params.Params) (*WIF, error)

func DecodeWIFV09

func DecodeWIFV09(wif string, net *params.Params) (*WIF, error)

DecodeWIFV09 creates a new qitmeer-wallet V0.9 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:

  • 1 byte to identify the network, must be 0x80 for mainnet or 0xef for either testnet3 or the regression test network
  • 32 bytes of a binary-encoded, big-endian, zero-padded private key
  • Optional 1 byte (equal to 0x01) if the address being imported or exported was created by taking the RIPEMD160 after SHA256 hash of a serialized compressed (33-byte) public 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 or the expected compressed pubkey magic number does not equal the expected value of 0x01. ErrChecksumMismatch is returned if the expected WIF checksum does not match the calculated checksum.

func NewWIF

func NewWIF(privKey *secp256k1.PrivateKey, net *params.Params, compress bool) (*WIF, error)

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) IsForNet

func (w *WIF) IsForNet(net *params.Params) bool

IsForNet returns whether or not the decoded WIF structure is associated with the passed bitcoin network.

func (*WIF) SerializePubKey

func (w *WIF) SerializePubKey() []byte

SerializePubKey serializes the associated public key of the imported or exported private key in either a compressed or uncompressed format. The serialization format chosen depends on the value of w.CompressPubKey.

func (*WIF) String

func (w *WIF) String() string

func (*WIF) StringV09

func (w *WIF) StringV09() string

StringV09 creates the Wallet Import Format string encoding of a qitmeer-wallet V0.9 WIF structure. See DecodeWIF for a detailed breakdown of the format and requirements of a valid WIF string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL