Documentation ¶
Index ¶
- Constants
- Variables
- func AddressFromPublicKey(pubKey *btcec.PublicKey, mainnet bool) string
- func AddressFromPublicKeyHash(pubKeyHash []byte, mainnet bool) string
- func AddressToPubKeyHash(address string) (publicKeyHash string, err error)
- func AddressToScript(address string) (script []byte, err error)
- func BuildBlockHeader(version uint32, previousBlockHash string, merkleRoot []byte, time []byte, ...) []byte
- func BuildCoinbase(c1 []byte, c2 []byte, extraNonce1 string, extraNonce2 string) []byte
- func BuildMerkleRootFromCoinbase(coinbaseHash []byte, merkleBranches []string) []byte
- func DecodeBIP276(text string) (prefix string, version int, network int, data []byte, err error)
- func DecodeParts(b []byte) ([][]byte, error)
- func DecodeString(s string) ([]byte, error)
- func DecodeStringParts(s string) ([][]byte, error)
- func DecodeVarInt(b []byte) (result uint64, size int)
- func DecodeVarIntFromReader(r *bufio.Reader) (uint64, error)
- func DifficultyFromBits(bits string) (float64, error)
- func DifficultyToHashrate(coin string, diff uint64, targetSeconds float64) float64
- func EncodeBIP276(prefix string, network int, version int, data []byte) string
- func EncodeParts(parts [][]byte) ([]byte, error)
- func EncodeToString(src []byte) string
- func Equals(b1 []byte, b2 []byte) bool
- func ExpandTargetFrom(bits string) (string, error)
- func ExpandTargetFromAsInt(bits string) (*big.Int, error)
- func GetBlockSubsidyForHeight(height uint64) uint64
- func GetCoinbaseParts(height uint32, coinbaseValue uint64, defaultWitnessCommitment string, ...) (coinbase1 []byte, coinbase2 []byte, err error)
- func GetLittleEndianBytes(v uint32, l uint32) []byte
- func GetMerkleBranches(template []string) []string
- func Hash160(data []byte) []byte
- func HumanHash(val float64) string
- func MaxEncodedLen(b []byte) int
- func MerkleRootFromBranches(txHash string, txIndex int, branches []string) (string, error)
- func PrivateKeyToWIF(key []byte) string
- func PublicKeyHashFromPublicKey(pubKey *btcec.PublicKey) string
- func PublicKeyHashFromPublicKeyStr(pubKeyStr string) (string, error)
- func PublicKeyToP2PKHScript(pubkey []byte) []byte
- func ReverseBytes(a []byte) []byte
- func ReverseHexString(hex string) string
- func Sha256d(b []byte) []byte
- func SortByteArrays(src [][]byte) [][]byte
- func ValidateWalletAddress(coin string, address string) (bool, error)
- func VarInt(i uint64) []byte
- type Address
- type Choice
- type PublicKey
Constants ¶
const ( Op0 = 0x00 // 0 OpZERO = 0x00 // 0 OpFALSE = 0x00 // 0 - AKA Op0 OpDATA1 = 0x01 // 1 OpDATA2 = 0x02 // 2 OpDATA3 = 0x03 // 3 OpDATA4 = 0x04 // 4 OpDATA5 = 0x05 // 5 OpDATA6 = 0x06 // 6 OpDATA7 = 0x07 // 7 OpDATA8 = 0x08 // 8 OpDATA9 = 0x09 // 9 OpDATA10 = 0x0a // 10 OpDATA11 = 0x0b // 11 OpDATA12 = 0x0c // 12 OpDATA13 = 0x0d // 13 OpDATA14 = 0x0e // 14 OpDATA15 = 0x0f // 15 OpDATA16 = 0x10 // 16 OpDATA17 = 0x11 // 17 OpDATA18 = 0x12 // 18 OpDATA19 = 0x13 // 19 OpDATA20 = 0x14 // 20 OpDATA21 = 0x15 // 21 OpDATA22 = 0x16 // 22 OpDATA23 = 0x17 // 23 OpDATA24 = 0x18 // 24 OpDATA25 = 0x19 // 25 OpDATA26 = 0x1a // 26 OpDATA27 = 0x1b // 27 OpDATA28 = 0x1c // 28 OpDATA29 = 0x1d // 29 OpDATA30 = 0x1e // 30 OpDATA31 = 0x1f // 31 OpDATA32 = 0x20 // 32 OpDATA33 = 0x21 // 33 OpDATA34 = 0x22 // 34 OpDATA35 = 0x23 // 35 OpDATA36 = 0x24 // 36 OpDATA37 = 0x25 // 37 OpDATA38 = 0x26 // 38 OpDATA39 = 0x27 // 39 OpDATA40 = 0x28 // 40 OpDATA41 = 0x29 // 41 OpDATA42 = 0x2a // 42 OpDATA43 = 0x2b // 43 OpDATA44 = 0x2c // 44 OpDATA45 = 0x2d // 45 OpDATA46 = 0x2e // 46 OpDATA47 = 0x2f // 47 OpDATA48 = 0x30 // 48 OpDATA49 = 0x31 // 49 OpDATA50 = 0x32 // 50 OpDATA51 = 0x33 // 51 OpDATA52 = 0x34 // 52 OpDATA53 = 0x35 // 53 OpDATA54 = 0x36 // 54 OpDATA55 = 0x37 // 55 OpDATA56 = 0x38 // 56 OpDATA57 = 0x39 // 57 OpDATA58 = 0x3a // 58 OpDATA59 = 0x3b // 59 OpDATA60 = 0x3c // 60 OpDATA61 = 0x3d // 61 OpDATA62 = 0x3e // 62 OpDATA63 = 0x3f // 63 OpDATA64 = 0x40 // 64 OpDATA65 = 0x41 // 65 OpDATA66 = 0x42 // 66 OpDATA67 = 0x43 // 67 OpDATA68 = 0x44 // 68 OpDATA69 = 0x45 // 69 OpDATA70 = 0x46 // 70 OpDATA71 = 0x47 // 71 OpDATA72 = 0x48 // 72 OpDATA73 = 0x49 // 73 OpDATA74 = 0x4a // 74 OpDATA75 = 0x4b // 75 OpPUSHDATA1 = 0x4c // 76 OpPUSHDATA2 = 0x4d // 77 OpPUSHDATA4 = 0x4e // 78 Op1NEGATE = 0x4f // 79 OpRESERVED = 0x50 // 80 OpBASE = 0x50 // 80 Op1 = 0x51 // 81 - AKA OpTRUE OpONE = 0x51 // 81 OpTRUE = 0x51 // 81 Op2 = 0x52 // 82 Op3 = 0x53 // 83 Op4 = 0x54 // 84 Op5 = 0x55 // 85 Op6 = 0x56 // 86 Op7 = 0x57 // 87 Op8 = 0x58 // 88 Op9 = 0x59 // 89 Op10 = 0x5a // 90 Op11 = 0x5b // 91 Op12 = 0x5c // 92 Op13 = 0x5d // 93 Op14 = 0x5e // 94 Op15 = 0x5f // 95 Op16 = 0x60 // 96 OpSIXTEEN = 0x60 // 96 OpNOP = 0x61 // 97 OpVER = 0x62 // 98 OpIF = 0x63 // 99 OpNOTIF = 0x64 // 100 OpVERIF = 0x65 // 101 OpVERNOTIF = 0x66 // 102 OpELSE = 0x67 // 103 OpENDIF = 0x68 // 104 OpVERIFY = 0x69 // 105 OpRETURN = 0x6a // 106 OpTOALTSTACK = 0x6b // 107 OpFROMALTSTACK = 0x6c // 108 Op2DROP = 0x6d // 109 Op2DUP = 0x6e // 110 Op3DUP = 0x6f // 111 Op2OVER = 0x70 // 112 Op2ROT = 0x71 // 113 Op2SWAP = 0x72 // 114 OpIFDUP = 0x73 // 115 OpDEPTH = 0x74 // 116 OpDROP = 0x75 // 117 OpDUP = 0x76 // 118 - Duplicate the top item in the stack OpNIP = 0x77 // 119 OpOVER = 0x78 // 120 OpPICK = 0x79 // 121 OpROLL = 0x7a // 122 OpROT = 0x7b // 123 OpSWAP = 0x7c // 124 OpTUCK = 0x7d // 125 OpCAT = 0x7e // 126 OpSPLIT = 0x7f // 127 OpNUM2BIN = 0x80 // 128 OpBIN2NUM = 0x81 // 129 OpSIZE = 0x82 // 130 OpINVERT = 0x83 // 131 OpAND = 0x84 // 132 OpOR = 0x85 // 133 OpXOR = 0x86 // 134 OpEQUAL = 0x87 // 135 - Returns 1 if the inputs are exactly equal, 0 otherwise OpEQUALVERIFY = 0x88 // 136 - Same as OP_EQUAL, but run OP_VERIFY after to halt if not TRUE OpRESERVED1 = 0x89 // 137 OpRESERVED2 = 0x8a // 138 Op1ADD = 0x8b // 139 Op1SUB = 0x8c // 140 Op2MUL = 0x8d // 141 Op2DIV = 0x8e // 142 OpNEGATE = 0x8f // 143 OpABS = 0x90 // 144 OpNOT = 0x91 // 145 Op0NOTEQUAL = 0x92 // 146 OpADD = 0x93 // 147 OpSUB = 0x94 // 148 OpMUL = 0x95 // 149 OpDIV = 0x96 // 150 OpMOD = 0x97 // 151 OpLSHIFT = 0x98 // 152 OpRSHIFT = 0x99 // 153 OpBOOLAND = 0x9a // 154 OpBOOLOR = 0x9b // 155 OpNUMEQUAL = 0x9c // 156 OpNUMEQUALVERIFY = 0x9d // 157 OpNUMNOTEQUAL = 0x9e // 158 OpLESSTHAN = 0x9f // 159 OpGREATERTHAN = 0xa0 // 160 OpLESSTHANOREQUAL = 0xa1 // 161 OpGREATERTHANOREQUAL = 0xa2 // 162 OpMIN = 0xa3 // 163 OpMAX = 0xa4 // 164 OpWITHIN = 0xa5 // 165 OpRIPEMD160 = 0xa6 // 166 OpSHA1 = 0xa7 // 167 OpSHA256 = 0xa8 // 168 OpHASH160 = 0xa9 // 169 - Return RIPEMD160(SHA256(x)) hash of top item OpHASH256 = 0xaa // 170 OpCODESEPARATOR = 0xab // 171 OpCHECKSIG = 0xac // 172 - Pop a public key and signature and validate the signature for the transaction's hashed data, return TRUE if matching OpCHECKSIGVERIFY = 0xad // 173 OpCHECKMULTISIG = 0xae // 174 OpCHECKMULTISIGVERIFY = 0xaf // 175 OpNOP1 = 0xb0 // 176 OpNOP2 = 0xb1 // 177 OpCHECKLOCKTIMEVERIFY = 0xb1 // 177 - AKA OpNOP2 OpNOP3 = 0xb2 // 178 OpCHECKSEQUENCEVERIFY = 0xb2 // 178 - AKA OpNOP3 OpNOP4 = 0xb3 // 179 OpNOP5 = 0xb4 // 180 OpNOP6 = 0xb5 // 181 OpNOP7 = 0xb6 // 182 OpNOP8 = 0xb7 // 183 OpNOP9 = 0xb8 // 184 OpNOP10 = 0xb9 // 185 OpUNKNOWN186 = 0xba // 186 OpUNKNOWN187 = 0xbb // 187 OpUNKNOWN188 = 0xbc // 188 OpUNKNOWN189 = 0xbd // 189 OpUNKNOWN190 = 0xbe // 190 OpUNKNOWN191 = 0xbf // 191 OpUNKNOWN192 = 0xc0 // 192 OpUNKNOWN193 = 0xc1 // 193 OpUNKNOWN194 = 0xc2 // 194 OpUNKNOWN195 = 0xc3 // 195 OpUNKNOWN196 = 0xc4 // 196 OpUNKNOWN197 = 0xc5 // 197 OpUNKNOWN198 = 0xc6 // 198 OpUNKNOWN199 = 0xc7 // 199 OpUNKNOWN200 = 0xc8 // 200 OpUNKNOWN201 = 0xc9 // 201 OpUNKNOWN202 = 0xca // 202 OpUNKNOWN203 = 0xcb // 203 OpUNKNOWN204 = 0xcc // 204 OpUNKNOWN205 = 0xcd // 205 OpUNKNOWN206 = 0xce // 206 OpUNKNOWN207 = 0xcf // 207 OpUNKNOWN208 = 0xd0 // 208 OpUNKNOWN209 = 0xd1 // 209 OpUNKNOWN210 = 0xd2 // 210 OpUNKNOWN211 = 0xd3 // 211 OpUNKNOWN212 = 0xd4 // 212 OpUNKNOWN213 = 0xd5 // 213 OpUNKNOWN214 = 0xd6 // 214 OpUNKNOWN215 = 0xd7 // 215 OpUNKNOWN216 = 0xd8 // 216 OpUNKNOWN217 = 0xd9 // 217 OpUNKNOWN218 = 0xda // 218 OpUNKNOWN219 = 0xdb // 219 OpUNKNOWN220 = 0xdc // 220 OpUNKNOWN221 = 0xdd // 221 OpUNKNOWN222 = 0xde // 222 OpUNKNOWN223 = 0xdf // 223 OpUNKNOWN224 = 0xe0 // 224 OpUNKNOWN225 = 0xe1 // 225 OpUNKNOWN226 = 0xe2 // 226 OpUNKNOWN227 = 0xe3 // 227 OpUNKNOWN228 = 0xe4 // 228 OpUNKNOWN229 = 0xe5 // 229 OpUNKNOWN230 = 0xe6 // 230 OpUNKNOWN231 = 0xe7 // 231 OpUNKNOWN232 = 0xe8 // 232 OpUNKNOWN233 = 0xe9 // 233 OpUNKNOWN234 = 0xea // 234 OpUNKNOWN235 = 0xeb // 235 OpUNKNOWN236 = 0xec // 236 OpUNKNOWN237 = 0xed // 237 OpUNKNOWN238 = 0xee // 238 OpUNKNOWN239 = 0xef // 239 OpUNKNOWN240 = 0xf0 // 240 OpUNKNOWN241 = 0xf1 // 241 OpUNKNOWN242 = 0xf2 // 242 OpUNKNOWN243 = 0xf3 // 243 OpUNKNOWN244 = 0xf4 // 244 OpUNKNOWN245 = 0xf5 // 245 OpUNKNOWN246 = 0xf6 // 246 OpUNKNOWN247 = 0xf7 // 247 OpUNKNOWN248 = 0xf8 // 248 OpUNKNOWN249 = 0xf9 // 249 OpSMALLINTEGER = 0xfa // 250 - bitcoin core internal OpPUBKEYS = 0xfb // 251 - bitcoin core internal OpUNKNOWN252 = 0xfc // 252 OpPUBKEYHASH = 0xfd // 253 - bitcoin core internal OpPUBKEY = 0xfe // 254 - bitcoin core internal OpINVALIDOPCODE = 0xff // 255 - bitcoin core internal )
Bitcoin Script constants
const CHARSET string = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
CHARSET is the cashaddr character set for encoding.
const Radix = len(base58table)
Radix of the base58 encoding system.
Variables ¶
var ( Public []byte // Public mainnet Private []byte // Private mainnet TestPublic []byte TestPrivate []byte )
Networks
var BitsPerDigit = math.Log2(float64(Radix))
BitsPerDigit - Bits of entropy per base 58 digit.
Functions ¶
func AddressFromPublicKey ¶
AddressFromPublicKey takes a btcec public key and returns a P2PKH address string. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func AddressFromPublicKeyHash ¶
AddressFromPublicKeyHash takes a byte array hash of a public key and returns a P2PKH address string. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func AddressToPubKeyHash ¶
AddressToPubKeyHash decodes a Bitcoin address (P2PKH) into the hash of the public key encoded as a string of hex values.
func AddressToScript ¶
AddressToScript comment
func BuildBlockHeader ¶
func BuildBlockHeader(version uint32, previousBlockHash string, merkleRoot []byte, time []byte, bits []byte, nonce []byte) []byte
BuildBlockHeader builds the block header byte array from the specific fields in the header.
func BuildCoinbase ¶
BuildCoinbase recombines the different parts of the coinbase transaction. See https://arxiv.org/pdf/1703.06545.pdf section 2.2 for more info.
func BuildMerkleRootFromCoinbase ¶
BuildMerkleRootFromCoinbase builds the merkle root of the block from the coinbase transaction hash (txid) and the merkle branches needed to work up the merkle tree and returns the merkle root byte array.
func DecodeBIP276 ¶
DecodeBIP276 is used to decode BIP276 formatted data into specific (non-standard) scripts. See https://github.com/moneybutton/bips/blob/master/bip-0276.mediawiki
func DecodeParts ¶
DecodeParts returns an array of strings...
func DecodeString ¶
DecodeString returns the bytes represented by the base58 string s
func DecodeStringParts ¶
DecodeStringParts calls DecodeParts.
func DecodeVarInt ¶
DecodeVarInt takes a byte array in VarInt format and returns the decoded unsiged integer value and it's size in bytes. See http://learnmeabitcoin.com/glossary/varint
func DecodeVarIntFromReader ¶ added in v1.0.45
Read the stream and return the varint value only consuming the correct number of bytes....
func DifficultyFromBits ¶
DifficultyFromBits returns the mining difficulty from the nBits field in the block header.
func DifficultyToHashrate ¶
DifficultyToHashrate takes a specific coin ticker, it's difficulty, and target and compuptes the estimated hashrate on that specific coin (or chain).
func EncodeBIP276 ¶
EncodeBIP276 is used to encode specific (non-standard) scripts in BIP276 format. See https://github.com/moneybutton/bips/blob/master/bip-0276.mediawiki
func EncodeParts ¶
EncodeParts takes a slice of slices and returns a single slice with the appropriate OP_PUSH commands embedded.
func EncodeToString ¶
EncodeToString returns a string from a byte slice.
func ExpandTargetFromAsInt ¶
ExpandTargetFromAsInt comment
func GetBlockSubsidyForHeight ¶ added in v1.0.42
GetBlockSubsidyForHeight func
func GetCoinbaseParts ¶
func GetCoinbaseParts(height uint32, coinbaseValue uint64, defaultWitnessCommitment string, coinbaseText string, walletAddress string, minerIDBytes []byte) (coinbase1 []byte, coinbase2 []byte, err error)
GetCoinbaseParts returns the two split coinbase parts from coinbase metadata. See https://arxiv.org/pdf/1703.06545.pdf section 2.2 for more info.
func GetLittleEndianBytes ¶
GetLittleEndianBytes returns a byte array in little endian from an unsigned integer of 32 bytes.
func GetMerkleBranches ¶
GetMerkleBranches comment TODO:
func MaxEncodedLen ¶
MaxEncodedLen - returns the maximum possible length of a base58 encoding. This number may be larger than the encoded slice.
func MerkleRootFromBranches ¶
MerkleRootFromBranches comment TODO:
func PrivateKeyToWIF ¶
PrivateKeyToWIF takes a 256 bit private key and outputs it in Wallet Interchange Format
func PublicKeyHashFromPublicKey ¶
PublicKeyHashFromPublicKey hashes a btcec public key (in compressed format starting with 03 or 02) and returns the hash encoded as a string of hex values.
func PublicKeyHashFromPublicKeyStr ¶
PublicKeyHashFromPublicKeyStr hashes a public key string (in compressed format starting with 03 or 02) and returns the hash encoded as a string of hex values.
func PublicKeyToP2PKHScript ¶
PublicKeyToP2PKHScript turns a public key string (in compressed format) into a P2PKH script. Example: from 023717efaec6761e457f55c8417815505b695209d0bbfed8c3265be425b373c2d6 to 76a9144d5d1920331b71735a97a606d9734aed83cb3dfa88ac
func ReverseBytes ¶
ReverseBytes reverses the bytes (little endian/big endian). This is used when computing merkle trees in Bitcoin, for example.
func ReverseHexString ¶
ReverseHexString reverses the hex string (little endian/big endian). This is used when computing merkle trees in Bitcoin, for example.
func ValidateWalletAddress ¶
ValidateWalletAddress will check that the address is valid for the specified coin.
func VarInt ¶
VarInt takes an unsiged integer and returns a byte array in VarInt format. See http://learnmeabitcoin.com/glossary/varint
Types ¶
type Address ¶
An Address contains the address string as well as the public key hash string.
func NewAddressFromPublicKey ¶
NewAddressFromPublicKey takes a public key string and returns an Address struct pointer. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func NewAddressFromPublicKeyHash ¶
NewAddressFromPublicKeyHash takes a public key hash in bytes and returns an Address struct pointer. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func NewAddressFromString ¶
NewAddressFromString takes a string address (P2PKH) and returns a pointer to an Address which contains the address string as well as the public key hash string.
type Choice ¶
type Choice struct { Weight int Item interface{} }
Choice is used by WeightedChoice
func WeightedChoice ¶
WeightedChoice used weighted random selection to return one of the supplied choices. Weights of 0 are never selected. All other weight values are relative. E.g. if you have two choices both weighted 3, they will be returned equally often; and each will be returned 3 times as often as a choice weighted 1.
type PublicKey ¶
type PublicKey struct { Version []byte `json:"-"` Network string `json:"network"` Depth uint16 `json:"depth"` FingerPrint []byte `json:"-"` // : -1440106556, FingerPrintStr string `json:"fingerPrint"` // : -1440106556, ParentFingerPrint []byte `json:"-"` //: 0, ParentFingerPrintStr string `json:"parentFingerPrint"` //: 0, ChildIndex []byte `json:"childIndex"` //: 0, ChainCode []byte `json:"-"` // '41fc504936a63056da1a0f9dd44cad3651b64a17b53e523e18a8d228a489c16a', ChainCodeStr string `json:"chainCode"` PrivateKey []byte `json:"-"` // '0362e448fdb4c7c307a80cc3c8ede19cd2599a5ea5c05b188fc56a25c59bfcf125', PrivateKeyStr string `json:"privateKey"` // '0362e448fdb4c7c307a80cc3c8ede19cd2599a5ea5c05b188fc56a25c59bfcf125', PublicKey []byte `json:"-"` // '0362e448fdb4c7c307a80cc3c8ede19cd2599a5ea5c05b188fc56a25c59bfcf125', PublicKeyStr string `json:"publicKey"` // '0362e448fdb4c7c307a80cc3c8ede19cd2599a5ea5c05b188fc56a25c59bfcf125', Checksum []byte `json:"-"` //: 43286247, XPrvKey string `json:"xprvkey"` // 'xprv661My XPubKey string `json:"xpubkey"` // 'xpub661My }
A PublicKey contains metadata associated with an ECDSA public key.
func NewPrivateKey ¶
NewPrivateKey comment TODO: public key or private key?
func NewPublicKey ¶
NewPublicKey takes an xpub string and returns a PublicKey pointer. See BIP32 https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
func (*PublicKey) Child ¶
Child dervies a child public key for a specific index. See BIP32 https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
func (*PublicKey) GetXPub ¶
GetXPub returns an xpub string from a PublicKey. See BIP32 https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
Source Files ¶
- Address.go
- BIP276.go
- Base58.go
- BuildBlockHeader.go
- BuildMerkleRootFromCoinbase.go
- DifficultyToHashrate.go
- Equals.go
- ExpandTargetFrom.go
- GetCoinbaseParts.go
- GetMerkleBranches.go
- Hash160.go
- HumanHash.go
- Opcodes.go
- PrivateKeyToWIF.go
- PublicKey.go
- PublicKeyToP2PKHScript.go
- ReverseBytes.go
- ReverseHexString.go
- Sha256d.go
- ValidateWalletAddress.go
- WeightedChoice.go
- sortBytesSlice.go
- utils.go