Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeWIF(wif string) (*btcec.PrivateKey, error)
- func DoubleSha512(b []byte) []byte
- func EncodeWIF(privKey *btcec.PrivateKey) string
- func ReadVarBytes(r io.Reader, maxAllowed int, fieldName string) ([]byte, error)
- func ReadVarInt(r io.Reader) (uint64, error)
- func ReadVarString(r io.Reader, maxAllowed int) (string, error)
- func Sha512(b []byte) []byte
- func VarIntSerializeSize(val uint64) int
- func WriteVarBytes(w io.Writer, bytes []byte) error
- func WriteVarInt(w io.Writer, val uint64) error
- func WriteVarString(w io.Writer, str string) error
- type Address
Constants ¶
const MaxVarIntSize = 9
Maximum size of a variable length integer.
Variables ¶
var ( // ErrChecksumMismatch describes an error where decoding failed due // to a bad checksum. ErrChecksumMismatch = errors.New("checksum mismatch") // ErrUnknownAddressType describes an error where an address cannot be // decoded as a specific address type due to the string encoding // begining with an invalid identifier byte or unsupported version. ErrUnknownAddressType = errors.New("unknown address type/version") )
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 DecodeWIF ¶
func DecodeWIF(wif string) (*btcec.PrivateKey, error)
DecodeWIF creates a btcec.PrivateKey by decoding the string encoding of the import format. It only supports uncompressed keys.
The WIF string must be a base58-encoded string of the following byte sequence:
- 1 byte to identify the network, must be 0x80
- 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 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 DoubleSha512 ¶
DoubleSha512 returns the sha512^2 of the bytes
func EncodeWIF ¶
func EncodeWIF(privKey *btcec.PrivateKey) string
EncodeWIF creates the Wallet Import Format string encoding of a WIF structure. See DecodeWIF for a detailed breakdown of the format and requirements of a valid WIF string.
func ReadVarBytes ¶
ReadVarBytes reads a variable length byte array. A byte array is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhuastion attacks and forced panics thorugh malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.
func ReadVarInt ¶
ReadVarInt reads a variable length integer from r and returns it as a uint64.
func ReadVarString ¶
ReadVarString reads a variable length string from r and returns it as a Go string. A varString is encoded as a varInt containing the length of the string, and the bytes that represent the string itself. An error is returned if the length is greater than the maximum block payload size, since it would not be possible to put a varString of that size into a block anyways and it also helps protect against memory exhaustion attacks and forced panics through malformed messages.
func VarIntSerializeSize ¶
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func WriteVarBytes ¶
WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.
func WriteVarInt ¶
WriteVarInt serializes val to w using a variable number of bytes depending on its value.
Types ¶
type Address ¶
Address represents a Bitmessage address.
func DecodeAddress ¶
DecodeAddress decodes the Bitmessage address into an Address object.
func (*Address) Encode ¶
Encode the address to a string that begins from BM- based on the hash. Output: [Varint(addressVersion) Varint(stream) ripe checksum] where the Varints are serialized. Then this byte array is base58 encoded to produce our needed address.
func (*Address) PrivateKey ¶
func (addr *Address) PrivateKey() *btcec.PrivateKey
PrivateKey generates the decryption private key used to decrypt v4 pubkeys and v5 broadcasts originating from the address. Such objects are encrypted with the public key corresponding to this private key as the target key. It is the first half of the double SHA-512 hash of version, stream and ripe concatenated together.
func (*Address) PrivateKeySingleHash ¶
func (addr *Address) PrivateKeySingleHash() *btcec.PrivateKey
PrivateKeySingleHash generates the decryption private key used to decrypt v4 broadcasts originating from the address. They are encrypted with the public key corresponding to this private key as the target key. It is the first half of the SHA-512 hash of version, stream and ripe concatenated together.
Directories
¶
Path | Synopsis |
---|---|
Package identity is responsible for creation and management of user identities.
|
Package identity is responsible for creation and management of user identities. |
Package pow implements proof-of-work and its checking mechanism.
|
Package pow implements proof-of-work and its checking mechanism. |