base58check

package
v0.697.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package base58check decodes a Base58Check string — the encoding Bitcoin (and many forks / chains) use for WIF private keys, legacy addresses, and BIP-32 extended keys — into its version, payload, and checksum validity, and identifies the artifact type. A leaked WIF private key, address, or xprv/xpub is common crypto-forensics / IR / pentest loot; decoding one offline (and confirming its checksum) is the natural companion to bip39_decode. Pure offline transform; no network or device.

Wrap-vs-native judgement

Native. Base58Check is a public encoding: a base-58 integer conversion, a 4-byte double-SHA-256 checksum, and a version-byte prefix — math/big + crypto/sha256, nothing to wrap.

What this covers / defers

  • 1-byte-version artifacts: P2PKH (0x00 mainnet / 0x6F testnet), P2SH (0x05 / 0xC4), and WIF private keys (0x80 / 0xEF) — the WIF case surfaces the 32-byte private key and the compressed flag.
  • 4-byte-version BIP-32 extended keys (xprv/xpub, tprv/tpub) — identified and field-parsed (depth, parent fingerprint, child number, chain code, key) from the fixed 78-byte body.
  • Bech32 (segwit bc1…/tb1…) is a DIFFERENT encoding, not Base58Check, and is out of scope here (a separate decoder).
  • An unknown version byte is surfaced raw ("unknown") rather than guessed.

Verifiable / no confidently-wrong output

Anchored to the canonical Bitcoin vectors — the WIF 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ → private key 0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D, and the genesis address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa → hash160 62E907B15CBF27D5425399EBF6F0FB50EBB88F18. A string whose 4-byte double-SHA-256 checksum does not validate is reported as such (likely a typo or truncation) rather than asserted genuine; a non-Base58 character or a too-short decode is rejected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtendedKey

type ExtendedKey struct {
	Depth             int    `json:"depth"`
	ParentFingerprint string `json:"parent_fingerprint"` // 4-byte hex
	ChildNumber       uint32 `json:"child_number"`
	ChainCodeHex      string `json:"chain_code_hex"` // 32-byte hex
	KeyHex            string `json:"key_hex"`        // 33-byte hex (0x00||priv for xprv, compressed pub for xpub)
}

ExtendedKey holds the parsed fields of a BIP-32 extended key (when the decoded artifact is one).

type Result

type Result struct {
	Input         string `json:"input"`
	Type          string `json:"type"`              // identified artifact, or "unknown"
	Network       string `json:"network,omitempty"` // mainnet / testnet
	VersionHex    string `json:"version_hex"`       // 1- or 4-byte version, hex
	PayloadHex    string `json:"payload_hex"`
	ChecksumValid bool   `json:"checksum_valid"`
	// WIF-specific.
	PrivateKeyHex string `json:"private_key_hex,omitempty"`
	Compressed    *bool  `json:"compressed,omitempty"`
	// BIP-32 extended-key fields (when Type is an extended key).
	Extended *ExtendedKey `json:"extended,omitempty"`
	Note     string       `json:"note,omitempty"`
}

Result is the decoded view of a Base58Check string.

func Decode

func Decode(s string) (*Result, error)

Decode decodes a Base58Check string, validates its double-SHA-256 checksum, and identifies the artifact. A bad Base58 character or a too-short decode is an error; a non-validating checksum is reported (not an error).

Jump to

Keyboard shortcuts

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