doge

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 15 Imported by: 11

README

Doge

Doge is a library of helpful dogecoin primitives written in Go.

Documentation

Index

Constants

View Source
const (
	SerializedBip32KeyLength = 4 + 1 + 4 + 4 + 32 + 33
	HardenedKey              = 0x80000000
)
View Source
const (
	VersionAuxPoW = 256
	CoinbaseVOut  = 0xffffffff
)
View Source
const (
	ECPrivKeyLen            = 32 // bytes.
	ECPubKeyCompressedLen   = 33 // bytes: [x02/x03][32-X] 2=even 3=odd
	ECPubKeyUncompressedLen = 65 // bytes: [x04][32-X][32-Y]
)
View Source
const (
	OP_0     = 0x00 // push empty array
	OP_FALSE = 0x00 // alias
	// 0x01..0x4b push data of `opcode` length (1-75)
	OP_PUSHDATA1           = 0x4c // 1-byte length, push data
	OP_PUSHDATA2           = 0x4d // 2-byte length, push data
	OP_PUSHDATA4           = 0x4e // 4-byte length, push data
	OP_1NEGATE             = 0x4f // push #-1
	OP_RESERVED            = 0x50
	OP_1                   = 0x51 // push #1
	OP_TRUE                = 0x51 // alias
	OP_2                   = 0x52
	OP_3                   = 0x53
	OP_4                   = 0x54
	OP_5                   = 0x55
	OP_6                   = 0x56
	OP_7                   = 0x57
	OP_8                   = 0x58
	OP_9                   = 0x59
	OP_10                  = 0x5a
	OP_11                  = 0x5b
	OP_12                  = 0x5c
	OP_13                  = 0x5d
	OP_14                  = 0x5e
	OP_15                  = 0x5f
	OP_16                  = 0x60
	OP_NOP                 = 0x61
	OP_VER                 = 0x62
	OP_IF                  = 0x63
	OF_NOTIF               = 0x64
	OP_VERIF               = 0x65
	OP_VERNOTIF            = 0x66
	OP_ELSE                = 0x67
	OP_ENDIF               = 0x68
	OP_VERIFY              = 0x69
	OP_RETURN              = 0x6a
	OP_TOALTSTACK          = 0x6b
	OP_FROMALTSTACK        = 0x6c
	OP_IFDUP               = 0x73
	OP_DEPTH               = 0x74
	OP_DROP                = 0x75
	OP_DUP                 = 0x76
	OP_NIP                 = 0x77
	OP_OVER                = 0x78
	OP_PICK                = 0x79
	OP_ROLL                = 0x7a
	OP_ROT                 = 0x7b
	OP_SWAP                = 0x7c
	OP_TUCK                = 0x7d
	OP_2DROP               = 0x6d
	OP_2DUP                = 0x6e
	OP_3DUP                = 0x6f
	OP_2OVER               = 0x70
	OP_2ROT                = 0x71
	OP_2SWAP               = 0x72
	OP_CAT                 = 0x7e
	OP_SUBSTR              = 0x7
	OP_LEFT                = 0x80
	OP_RIGHT               = 0x81
	OP_SIZE                = 0x82
	OP_INVERT              = 0x83
	OP_AND                 = 0x84
	OP_OR                  = 0x85
	OP_XOR                 = 0x86
	OP_EQUAL               = 0x87
	OP_EQUALVERIFY         = 0x88
	OP_RESERVED1           = 0x89
	OP_RESERVED2           = 0x8a
	OP_1ADD                = 0x8b
	OP_1SUB                = 0x8c
	OP_2MUL                = 0x8d
	OP_2DIV                = 0x8e
	OP_NEGATE              = 0x8f
	OP_ABS                 = 0x90
	OP_NOT                 = 0x91
	OP_0NOTEQUAL           = 0x92
	OP_ADD                 = 0x93
	OP_SUB                 = 0x94
	OP_MUL                 = 0x95
	OP_DIV                 = 0x96
	OP_MOD                 = 0x97
	OP_LSHIFT              = 0x98
	OP_RSHIFT              = 0x99
	OP_BOOLAND             = 0x9a
	OP_BOOLOR              = 0x9b
	OP_NUMEQUAL            = 0x9c
	OP_NUMEQUALVERIFY      = 0x9d
	OP_NUMNOTEQUAL         = 0x9e
	OP_LESSTHAN            = 0x9f
	OP_GREATERTHAN         = 0xa0
	OP_LESSTHANOREQUAL     = 0xa1
	OP_GREATERTHANOREQUAL  = 0xa2
	OP_MIN                 = 0xa3
	OP_MAX                 = 0xa4
	OP_WITHIN              = 0xa5
	OP_RIPEMD160           = 0xa6
	OP_SHA1                = 0xa7
	OP_SHA256              = 0xa8
	OP_HASH160             = 0xa9
	OP_HASH256             = 0xaa
	OP_CODESEPARATOR       = 0xab
	OP_CHECKSIG            = 0xac
	OP_CHECKSIGVERIFY      = 0xad
	OP_CHECKMULTISIG       = 0xae
	OP_CHECKMULTISIGVERIFY = 0xaf
	OP_NOP1                = 0xb0
	OP_CHECKLOCKTIMEVERIFY = 0xb1
	OP_CHECKSEQUENCEVERIFY = 0xb2
	OP_NOP4                = 0xb3
	OP_NOP5                = 0xb4
	OP_NOP6                = 0xb5
	OP_NOP7                = 0xb6
	OP_NOP8                = 0xb7
	OP_NOP9                = 0xb8
	OP_NOP10               = 0xb9
	OP_CHECKSIGADD         = 0xba
)

source: https://en.bitcoin.it/wiki/Script

View Source
const MAX_OP_RETURN_RELAY = 83 // from Core IsStandard in policy.cpp
View Source
const (
	OneDoge = int64(100_000_000) // in Koinu
)

Variables

View Source
var CoinbaseTxID = [32]byte{}
View Source
var ErrAnotherSeed = errors.New("cannot derive a valid master key from this seed (generate another seed)")
View Source
var ErrBadSeed = errors.New("bad seed: must be 16-64 bytes")
View Source
var ErrCannotDerive = errors.New("cannot derive private key from public key")
View Source
var ErrHardened = errors.New("cannot derive a public key from a hardened parent key")
View Source
var ErrInvalidPrivateKey = errors.New("invalid private key")
View Source
var ErrNextIndex = errors.New("cannot derive a valid child key at this key index (try the next index)")
View Source
var ErrTooDeep = errors.New("key derivation path is too long (more than 255)")

Functions

func Base58Decode

func Base58Decode(str string) ([]byte, error)

func Base58DecodeCheck

func Base58DecodeCheck(str string) ([]byte, error)

func Base58Encode

func Base58Encode(bytes []byte) string

func Base58EncodeCheck

func Base58EncodeCheck(bytes []byte) string

CAUTION: appends the Checksum to `bytes` if it has sufficient capacity (4 bytes)

func Base58VerifyChecksum

func Base58VerifyChecksum(bytes []byte, str string) error

func ClassifyScript

func ClassifyScript(script []byte) (ScriptType, ScriptHashOrData)

ClassifyScript infers ScriptType from a script by pattern-matching the bytecode Returns the PubKeyHash/ScriptHash/PubKey/Data extracted from the script

func DecodeECPrivKeyWIF

func DecodeECPrivKeyWIF(str string, chain *ChainParams) (ec_priv_key ECPrivKey, out_chain *ChainParams, err error)

chain is optional, will auto-detect if nil.

func DecodeOP_N added in v0.1.0

func DecodeOP_N(op byte) int

decodeOP_N decodes the pushed literal from OP_1 to OP_16

func DecodePushOP added in v0.1.0

func DecodePushOP(script []byte, ofs int) (newOfs int, length uint32, ok bool)

DecodePushOP decodes the 'length' from OP_0, OP_1 to OP_16, OP_PUSHDATA1,2,4

func ECKeyIsValid

func ECKeyIsValid(pk ECPrivKey) bool

func ECPrivKeyFromBip32WIF

func ECPrivKeyFromBip32WIF(ext_key_wif string, chain *ChainParams) (ec_privkey_wif string, err error)

Given a Bip32 Extended Private Key WIF, extract the WIF-encoded EC Private Key. chain is optional, will auto-detect if nil.

func EncodeBip32WIF

func EncodeBip32WIF(key *Bip32Key) string

EncodeBip32WIF encodes a Bip32Key in WIF format (dgpv,dgub)

func EncodeECPrivKeyUncompressedWIF

func EncodeECPrivKeyUncompressedWIF(key ECPrivKey, chain *ChainParams) string

func EncodeECPrivKeyWIF

func EncodeECPrivKeyWIF(key ECPrivKey, chain *ChainParams) string

func EncodeTx added in v0.1.6

func EncodeTx(tx BlockTx) ([]byte, error)

EncodeTx encodes a transaction to a byte slice. This function does not fail (Go panics if out of memory).

func ExpandScript added in v0.1.0

func ExpandScript(typ ScriptType, data ScriptHashOrData) (script []byte)

ExpandScript re-creates the ScriptPubKey from a ScriptType and ScriptHashOrData

func Hash160

func Hash160(bytes []byte) []byte

func HexDecode

func HexDecode(str string) ([]byte, error)

func HexDecodeReversed added in v0.1.4

func HexDecodeReversed(str string) ([]byte, error)

func HexEncode

func HexEncode(bytes []byte) string

func HexEncodeReversed

func HexEncodeReversed(data []byte) string

func IsOP_N added in v0.1.0

func IsOP_N(op byte) bool

isOP_N recognises OP_1 to OP_16

func IsValidHex

func IsValidHex(hex string) bool

func P2PKHScript added in v0.1.7

func P2PKHScript(pubKeyHash []byte) ([]byte, error)

P2PKHScript creates a P2PKH script from a pubKeyHash. Returns the script or an error if the pubKeyHash length is invalid.

func P2PKHScriptFromAddress added in v0.1.7

func P2PKHScriptFromAddress(address Address) ([]byte, error)

P2PKHScriptFromAddress creates a P2PKH script from a Dogecoin address. Returns the script or an error if the address is invalid.

func P2SHScript added in v0.1.7

func P2SHScript(scriptHash []byte) ([]byte, error)

P2SHScript creates a P2SH script from a redeem script hash. Returns the script or an error if the hash length is invalid.

func P2SHScriptFromRedeemScript added in v0.1.7

func P2SHScriptFromRedeemScript(redeemScript []byte) ([]byte, error)

P2SHScriptFromRedeemScript creates a P2SH script from a redeem script. Returns the script or an error if the redeem script length is invalid.

func RIPEMD160

func RIPEMD160(bytes []byte) []byte

func TxHashHex

func TxHashHex(txBytes []byte) string

TxHashHex hashes a transaction and returns the hash as a hex-string.

func TxHashToHex added in v0.0.15

func TxHashToHex(hash []byte) string

TxHashToHex returns the hex-string of a transaction hash.

func ValidateP2PKH

func ValidateP2PKH(address Address, chain *ChainParams) bool

func ValidateP2SH

func ValidateP2SH(address Address, chain *ChainParams) bool

func VerifyMessage added in v0.0.10

func VerifyMessage(pubKey ECPubKeySchnorr, msg []byte, sig SchnorrSignature) bool

VerifyMessage verifies an arbitrary message with a public key and signature; the signature and public key are also validated, i.e. all parameters can be untrusted data.

Types

type Address

type Address string // Dogecoin address (base-58 Public Key Hash aka PKH)

func Hash160toAddress

func Hash160toAddress(hash []byte, prefix byte) Address

func P2PKHFromECPrivKeyWIF

func P2PKHFromECPrivKeyWIF(ec_priv_key_wif string) (p2pkh Address, err error)

func PubKeyToP2PKH

func PubKeyToP2PKH(key []byte, chain *ChainParams) (Address, error)

PubKeyToP2PKH converst an ECPubKeyCompressed or ECPubKeyUncompressed to a Dogecoin P2PKH Address.

func ScriptToP2SH

func ScriptToP2SH(redeemScript []byte, chain *ChainParams) Address

type Bip32Key

type Bip32Key struct {
	// contains filtered or unexported fields
}

https://en.bitcoin.it/wiki/BIP_0032

func Bip32MasterFromSeed added in v0.0.5

func Bip32MasterFromSeed(seed []byte, chain *ChainParams) (*Bip32Key, error)

Bip32MasterFromSeed derives the Bip32 master key from an entropy seed. Note: bip39.SeedFromMnemonic generates an appropriate seed (also GenerateRandomMnemonic)

func DecodeBip32WIF

func DecodeBip32WIF(extendedKey string, chain *ChainParams) (*Bip32Key, error)

DecodeBip32WIF decodes a WIF-encoded Bip32Key (dgpv,dgub) chain is optional, will auto-detect if nil.

func (*Bip32Key) ChainParams added in v0.0.5

func (key *Bip32Key) ChainParams() *ChainParams

ChainParams returns the chain this key belongs to.

func (*Bip32Key) ChildNumber added in v0.1.8

func (key *Bip32Key) ChildNumber() uint32

ChildNumber returns the child number of this key. ser32(i) for i in xi = xpar/i, with xi the key being serialized. (0x00000000 if master key)

func (*Bip32Key) Clear

func (key *Bip32Key) Clear()

func (*Bip32Key) DeriveChild added in v0.0.5

func (key *Bip32Key) DeriveChild(path []uint32, useSLIP10 bool) (*Bip32Key, error)

DeriveChild derives a child key according to BIP-32. Path is a list of child key indexes. If an index is >= HardenedKey, the derived key will be hardened. For a Private Bip32Key we use PrivateCKD on each path element; for a Public key we use PublicCKD.

func (*Bip32Key) EncodeWIF added in v0.0.8

func (key *Bip32Key) EncodeWIF() string

EncodeWIF encodes this key in Bip32 WIF format (dgpv,dgub)

func (*Bip32Key) GetECPrivKey

func (key *Bip32Key) GetECPrivKey() (ECPrivKey, error)

GetECPrivKey gets a copy of the underlying private key.

func (*Bip32Key) GetECPubKey

func (key *Bip32Key) GetECPubKey() ECPubKeyCompressed

GetECPrivKey gets a copy of the underlying public key.

func (*Bip32Key) IsPrivate added in v0.0.5

func (key *Bip32Key) IsPrivate() bool

IsPrivate is true if the Bip32Key holds a Private key (otherwise it holds the corresponding Public key)

func (*Bip32Key) ParentFingerprint added in v0.0.5

func (key *Bip32Key) ParentFingerprint() uint32

ParentFingerprint is the fingerprint for the parent's public key. This is the fingerprint stored in the Bip32 Serialization Format (EncodeBip32WIF)

func (*Bip32Key) PrivateCKD added in v0.0.5

func (key *Bip32Key) PrivateCKD(path []uint32, useSLIP10 bool) (*Bip32Key, error)

func (*Bip32Key) Public added in v0.0.5

func (key *Bip32Key) Public() *Bip32Key

Public returns the Public Bip32Key corresponding to a Private Bip32Key. If key is already a Public Bip32Key, the same *Bip32Key is returned.

func (*Bip32Key) PublicCKD added in v0.0.5

func (key *Bip32Key) PublicCKD(path []uint32, useSLIP10 bool) (*Bip32Key, error)

func (*Bip32Key) ThisKeyFingerprint added in v0.0.5

func (key *Bip32Key) ThisKeyFingerprint() uint32

ThisKeyFingerprint is the fingerprint for this key's public key. NOTE: this is not the ParentFingerprint() sored in Bip23 WIF format! This is primarily included for tests.

type Block

type Block struct {
	Header BlockHeader
	AuxPoW *MerkleTx // if IsAuxPoW()
	Tx     []BlockTx
}

func DecodeBlock

func DecodeBlock(blockBytes []byte, calcHash bool) (Block, bool)

DecodeBlock decodes a block from a byte slice. If calcHash is true, the block hash is calculated and stored in the Block.BlockID field. Returns false if the serialized block data is malformed.

type BlockHeader

type BlockHeader struct {
	Version    uint32
	PrevBlock  []byte // 32 bytes
	MerkleRoot []byte // 32 bytes
	Timestamp  uint32
	Bits       uint32
	Nonce      uint32
	BlockID    HashID // Block Hash (if decoded with calcHash=True)
}

func (*BlockHeader) IsAuxPoW

func (b *BlockHeader) IsAuxPoW() bool

type BlockTx

type BlockTx struct {
	Version  uint32
	VIn      []BlockTxIn
	VOut     []BlockTxOut
	LockTime uint32
	TxID     HashID // Transaction Hash (if decoded with calcHash=True)
}

func DecodeTx

func DecodeTx(txBytes []byte, calcHash bool) (BlockTx, bool)

DecodeTx decodes a transaction from a byte slice. If calcHash is true, the transaction hash is calculated and stored in the BlockTx.TxID field. Returns false if the serialized transaction data is malformed.

type BlockTxIn

type BlockTxIn struct {
	TxID     []byte // 32 bytes
	VOut     uint32
	Script   []byte // varied length
	Sequence uint32
}

type BlockTxOut

type BlockTxOut struct {
	Value  int64
	Script []byte // varied length
}

type ChainParams

type ChainParams struct {
	ChainName                string
	GenesisBlock             string
	P2PKH_Address_Prefix     byte
	P2SH_Address_Prefix      byte
	PKey_Prefix              byte
	Bip32_PrivKey_Prefix     uint32
	Bip32_PubKey_Prefix      uint32
	Bip32_WIF_PrivKey_Prefix string
	Bip32_WIF_PubKey_Prefix  string
}
var BitcoinMainChain ChainParams = ChainParams{
	ChainName:                "btc_main",
	GenesisBlock:             "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
	P2PKH_Address_Prefix:     0x00,
	P2SH_Address_Prefix:      0x05,
	PKey_Prefix:              0x80,
	Bip32_PrivKey_Prefix:     0x0488ADE4,
	Bip32_PubKey_Prefix:      0x0488B21E,
	Bip32_WIF_PrivKey_Prefix: "xxxx",
	Bip32_WIF_PubKey_Prefix:  "xxxx",
}

Used in tests only.

var BitcoinTestChain ChainParams = ChainParams{
	ChainName:                "btc_test",
	GenesisBlock:             "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
	P2PKH_Address_Prefix:     0x00,
	P2SH_Address_Prefix:      0x05,
	PKey_Prefix:              0x80,
	Bip32_PrivKey_Prefix:     0x0488ADE4,
	Bip32_PubKey_Prefix:      0x0488B21E,
	Bip32_WIF_PrivKey_Prefix: "xxxx",
	Bip32_WIF_PubKey_Prefix:  "xxxx",
}

Used in tests only.

var DogeMainNetChain ChainParams = ChainParams{
	ChainName:                "doge_main",
	GenesisBlock:             "1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691",
	P2PKH_Address_Prefix:     0x1e,
	P2SH_Address_Prefix:      0x16,
	PKey_Prefix:              0x9e,
	Bip32_PrivKey_Prefix:     0x02fac398,
	Bip32_PubKey_Prefix:      0x02facafd,
	Bip32_WIF_PrivKey_Prefix: "dgpv",
	Bip32_WIF_PubKey_Prefix:  "dgub",
}
var DogeRegTestChain ChainParams = ChainParams{
	ChainName:                "doge_regtest",
	GenesisBlock:             "3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5",
	P2PKH_Address_Prefix:     0x6f,
	P2SH_Address_Prefix:      0xc4,
	PKey_Prefix:              0xef,
	Bip32_PrivKey_Prefix:     0x04358394,
	Bip32_PubKey_Prefix:      0x043587cf,
	Bip32_WIF_PrivKey_Prefix: "tprv",
	Bip32_WIF_PubKey_Prefix:  "tpub",
}
var DogeTestNetChain ChainParams = ChainParams{
	ChainName:                "doge_test",
	GenesisBlock:             "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e",
	P2PKH_Address_Prefix:     0x71,
	P2SH_Address_Prefix:      0xc4,
	PKey_Prefix:              0xf1,
	Bip32_PrivKey_Prefix:     0x04358394,
	Bip32_PubKey_Prefix:      0x043587cf,
	Bip32_WIF_PrivKey_Prefix: "tprv",
	Bip32_WIF_PubKey_Prefix:  "tpub",
}

func ChainFromBip32Version

func ChainFromBip32Version(version uint32, allowNonDoge bool) (bool, *ChainParams)

func ChainFromGenesisHash

func ChainFromGenesisHash(hash string) (*ChainParams, error)

func ChainFromTestNetFlag

func ChainFromTestNetFlag(isTestNet bool) *ChainParams

func ChainFromWIFPrefix

func ChainFromWIFPrefix(bytes []byte, allowNonDoge bool) *ChainParams

CAUTION: the result is a best-guess based on the 'version byte' in the decoded WIF data. Do not rely on the returned ChainParams alone for validation: it will fall back on DogeTestNetChain for unknown version bytes (so verify the version byte or bip32-prefix as well)

func ChainFromWIFString

func ChainFromWIFString(wif string) *ChainParams

CAUTION: the result is a best-guess based on the 'version byte' in the WIF string. Do not rely on the returned ChainParams alone for validation: it will fall back on DogeTestNetChain for unknown version bytes (so verify the version byte or bip32-prefix as well)

type Decoder added in v0.1.5

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder is a helper for decoding data from a byte slice. All numbers are assumed to be encoded little-endian.

func Decode added in v0.1.5

func Decode(b []byte) *Decoder

Decode creates a new Decoder from a byte slice.

func (*Decoder) Bool added in v0.1.5

func (d *Decoder) Bool() bool

Bool reads a boolean (byte) value from the buffer.

func (*Decoder) Bytes added in v0.1.5

func (d *Decoder) Bytes(num int) []byte

Bytes reads n bytes from the buffer and advances the position.

func (*Decoder) Complete added in v0.1.5

func (d *Decoder) Complete() bool

Complete returns true if all the data has been read; implies Valid()

func (*Decoder) Error added in v0.1.5

func (d *Decoder) Error(to any) error

Error returns nil if Complete(), or an error describing the wrong encoded size. `to` should be the struct (or interface) being parsed into, for error reporting.

func (*Decoder) Has added in v0.1.5

func (d *Decoder) Has(n int) bool

Has checks if there are at least n bytes remaining in the buffer.

func (*Decoder) Int64 added in v0.1.5

func (d *Decoder) Int64() int64

Int64le reads a signed 64-bit integer from the buffer in little-endian order.

func (*Decoder) PadString added in v0.1.5

func (d *Decoder) PadString(size int) string

PadString reads a fixed-length padded string from the buffer, trimming trailing null bytes.

func (*Decoder) Rest added in v0.1.5

func (d *Decoder) Rest() []byte

Rest reads all remaining bytes in the buffer.

func (*Decoder) Tag4CC added in v0.1.5

func (d *Decoder) Tag4CC() Tag4CC

Tag4CC reads a 4-byte Tag.

func (*Decoder) UInt16 added in v0.1.5

func (d *Decoder) UInt16() uint16

UInt16le reads an unsigned 16-bit integer from the buffer in little-endian order.

func (*Decoder) UInt32 added in v0.1.5

func (d *Decoder) UInt32() uint32

UInt32le reads an unsigned 32-bit integer from the buffer in little-endian order.

func (*Decoder) UInt64 added in v0.1.5

func (d *Decoder) UInt64() uint64

UInt64le reads an unsigned 64-bit integer from the buffer in little-endian order.

func (*Decoder) UInt8 added in v0.1.5

func (d *Decoder) UInt8() uint8

UInt8 reads an unsigned 8-bit integer from the buffer.

func (*Decoder) Valid added in v0.1.5

func (d *Decoder) Valid() bool

Valid returns true if all reads have succeeded without reading past the end of the data.

func (*Decoder) VarString added in v0.1.5

func (d *Decoder) VarString() string

VarString reads a variable-length string from the buffer.

func (*Decoder) VarUInt added in v0.1.5

func (d *Decoder) VarUInt() uint64

VarUInt reads a variable-length unsigned integer from the buffer.

type ECPrivKey

type ECPrivKey = *[32]byte // 32 byte big-endian uint256; 0 < pk < n in secp256k1.

func GenerateECPrivKey

func GenerateECPrivKey() (ECPrivKey, error)

type ECPubKeyCompressed

type ECPubKeyCompressed = *[33]byte // 33 bytes with 0x02 or 0x03 prefix.

func ECPubKeyFromECPrivKey

func ECPubKeyFromECPrivKey(pk ECPrivKey) ECPubKeyCompressed

type ECPubKeySchnorr added in v0.0.10

type ECPubKeySchnorr = *[32]byte // 32 byte X-coordinate-only public key, encoded as a big-endian uint256

type ECPubKeyUncompressed

type ECPubKeyUncompressed = *[65]byte // 65 bytes with 0x04 prefix.

type Encoder added in v0.1.5

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is a helper for encoding data to a byte slice. All numbers are encoded little-endian.

func Encode added in v0.1.5

func Encode(size_hint int) *Encoder

Encode creates a new Encoder for a given size. The underlying buffer will grow as necessary.

func (*Encoder) Bool added in v0.1.5

func (e *Encoder) Bool(b bool)

Encode a boolean as a byte.

func (*Encoder) Bytes added in v0.1.5

func (e *Encoder) Bytes(b []byte)

Encode a slice of bytes. No length is encoded: use VarUInt to prefix with a (non-fixed) length.

func (*Encoder) Int64 added in v0.1.5

func (e *Encoder) Int64(v int64)

Encode a signed 64-bit number in little-endian order.

func (*Encoder) PadString added in v0.1.5

func (e *Encoder) PadString(size uint64, v string) bool

Encodes a string padded to a fixed-size field with zero bytes. If the string is too long to fit, it is truncated. Returns true if the string fits, false if it was truncated.

func (*Encoder) Result added in v0.1.5

func (e *Encoder) Result() []byte

Get the encoded array of bytes

func (*Encoder) Tag4CC added in v0.1.5

func (e *Encoder) Tag4CC(v Tag4CC)

Tag4CC encodes a Four Character Code TAG in big-endian order, to preserve the order of the ASCII characters in the stream.

func (*Encoder) UInt16 added in v0.1.5

func (e *Encoder) UInt16(v uint16)

Encode an unsigned 16-bit number in little-endian order.

func (*Encoder) UInt32 added in v0.1.5

func (e *Encoder) UInt32(v uint32)

Encode an unsigned 32-bit number in little-endian order.

func (*Encoder) UInt64 added in v0.1.5

func (e *Encoder) UInt64(v uint64)

Encode an unsigned 64-bit number in little-endian order.

func (*Encoder) UInt8 added in v0.1.5

func (e *Encoder) UInt8(v uint8)

Encode an unsigned byte as itself.

func (*Encoder) VarString added in v0.1.5

func (e *Encoder) VarString(v string)

Encodes a VarUInt length, followed by the string bytes.

func (*Encoder) VarUInt added in v0.1.5

func (e *Encoder) VarUInt(val uint64)

Encode an unsigned integer of varying length: A single byte up to 0xFC (252) 0xFD + encoded 16-bit number, up to 0xFFFF (65536) 0xFE + encoded 32-bit number, up to 0xFFFFFFFF (4294967295) 0xFF + encoded 64-bit number, up to 0xFFFFFFFFFFFFFFFF (18446744073709551615) This encoding was borrowed from Bitcoin.

type Hash256

type Hash256 = []byte

func DoubleSha256

func DoubleSha256(bytes []byte) Hash256

func Sha256

func Sha256(bytes []byte) Hash256

type HashID added in v0.1.1

type HashID []byte

func (HashID) ToHex added in v0.1.1

func (id HashID) ToHex() string

type KeyType added in v0.0.5

type KeyType = int // keyECPriv,keyECPub,keyBip32Priv,keyBip32Pub,dogeMainNet,dogeTestNet

type MerkleBranch

type MerkleBranch struct {
	Hash     [][]byte // 32 bytes each
	SideMask uint32
}

type MerkleTx

type MerkleTx struct {
	CoinbaseTx       BlockTx
	ParentHash       []byte // 32 bytes
	CoinbaseBranch   MerkleBranch
	BlockchainBranch MerkleBranch
	ParentBlock      BlockHeader
}

type SchnorrSignature added in v0.0.10

type SchnorrSignature = *[64]byte // 64 byte signature, encoding (R.x, s) as big-endian uint256

func SignMessage added in v0.0.10

func SignMessage(privKey ECPrivKey, msg []byte) (SchnorrSignature, error)

SignMessage signs an arbitrary message with a private key. Returns an error if the private key is invalid.

type ScriptHashOrData added in v0.1.0

type ScriptHashOrData = []byte

ScriptHashOrData is the PubKeyHash, ScriptHash, PubKey, MultiSig PubKeys, or OP_RETURN data extracted from the script by ClassifyScript

type ScriptType

type ScriptType byte

ScriptType is inferred from the script by pattern-matching the bytecode

const (
	ScriptTypeNone        ScriptType = 0 // No Script (reserved)
	ScriptTypeP2PK        ScriptType = 1 // TX_PUBKEY (in Core)
	ScriptTypeP2PKH       ScriptType = 2 // TX_PUBKEYHASH
	ScriptTypeP2SH        ScriptType = 3 // TX_SCRIPTHASH
	ScriptTypeMultiSig    ScriptType = 4 // TX_MULTISIG
	ScriptTypeP2PKHW      ScriptType = 5 // TX_WITNESS_V0_KEYHASH
	ScriptTypeP2SHW       ScriptType = 6 // TX_WITNESS_V0_SCRIPTHASH
	ScriptTypeNullData    ScriptType = 7 // TX_NULL_DATA
	ScriptTypeNonStandard ScriptType = 8 // TX_NONSTANDARD
)

ScriptType constants (must fit in a single byte for compact storage)

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is a stream of bytes with read methods. DEPRECATED - use `Decoder` instead.

func NewStream added in v0.0.13

func NewStream(buf []byte) *Stream

NewStream creates a new stream from a byte slice.

func (*Stream) Bytes added in v0.0.13

func (s *Stream) Bytes(num uint64) []byte

Bytes reads num bytes from the stream and returns them.

func (*Stream) Complete added in v0.0.13

func (s *Stream) Complete() bool

Complete returns true if all the data has been read; implies Valid()

func (*Stream) Uint16le added in v0.0.13

func (s *Stream) Uint16le() uint16

Uint16le reads a 16-bit unsigned integer from the stream in little-endian order.

func (*Stream) Uint32le added in v0.0.13

func (s *Stream) Uint32le() uint32

Uint32le reads a 32-bit unsigned integer from the stream in little-endian order.

func (*Stream) Uint64le added in v0.0.13

func (s *Stream) Uint64le() uint64

Uint64le reads a 64-bit unsigned integer from the stream in little-endian order.

func (*Stream) Valid added in v0.0.13

func (s *Stream) Valid() bool

Valid returns true if all reads have succeeded without reading past the end of the data.

func (*Stream) VarUint added in v0.0.13

func (s *Stream) VarUint() uint64

VarUint reads a variable-length unsigned integer from the stream.

type Tag4CC added in v0.1.5

type Tag4CC uint32 // Big-Endian Four Character Code

func NewTag added in v0.1.5

func NewTag(tag string) Tag4CC

func (Tag4CC) Bytes added in v0.1.5

func (t Tag4CC) Bytes() []byte

func (Tag4CC) String added in v0.1.5

func (t Tag4CC) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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