Package bmutil provides Bitmessage-specific convenience functions and types. A comprehensive suite of tests is provided to ensure proper functionality. Package bmutil is licensed under the liberal ISC license.
This package was developed for bmd, an alternative full-node implementation of Bitmessage which is under active development by Monetas. Although it was primarily written for bmd, this package has intentionally been designed so it can be used as a standalone package for any projects needing the functionality provided.
It is based off btcutil, which is developed by Conformal.
go doc style documentation for the project can be viewed online without
installing this package by using the GoDoc site here:
You can also view the documentation locally once the package is installed with
godoc tool by running
godoc -http=":6060" and pointing your browser to
$ go get github.com/DanielKrawisz/bmutil
Package btcutil is licensed under the copyfree ISC License.
- func DecodeWIF(wif string) (*btcec.PrivateKey, error)
- func DoubleSha512(addr Address) 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(addr Address) byte
- func Tag(addr Address) *hash.Sha
- func V4BroadcastDecryptionKey(addr Address) *btcec.PrivateKey
- func V5BroadcastDecryptionKey(addr Address) *btcec.PrivateKey
- 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
const ( // DefaultAddressVersion is the address version that we use when we // create new addresses. DefaultAddressVersion = 4 // DefaultStream is the only stream currently in use on the Bitmessage // network, which is 1. DefaultStream = 1 )
const MaxVarIntSize = 9
MaxVarIntSize is the maximum size of a variable length integer.
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") // ErrDepricatedAddressVersion is returned if we try to create a // new address with a version less than 4. ErrDepricatedAddressVersion = errors.New("Address versions below 4 are depricated.") // ErrInvalidStream is returned if someone tries to create an address // with stream other than 1. ErrInvalidStream = errors.New("Only stream 1 is currently in use.") )
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.
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 calculates the double sha512 sum of the address, the first half of which is used as private encryption key for the public key object and the second half is used as a tag.
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.
Sha512 calculates the sha512 sum of the address, the first half of which is used as private encryption key for v2 and v3 broadcasts.
Tag calculates tag corresponding to the Bitmessage address. According to protocol specifications, it is the second half of the double SHA-512 hash of version, stream and ripe concatenated together.
V4BroadcastDecryptionKey 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.
V5BroadcastDecryptionKey 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 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.
Address represents a Bitmessage address.
func DecodeAddress ¶
DecodeAddress decodes the Bitmessage address into an Address object.
func NewAddress ¶
NewAddress creates a new address. Currently supported parameters must be provided for the object to be created. That means version 4 only and stream 1.
Package serialize is a generated protocol buffer package.
|Package serialize is a generated protocol buffer package.|
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.|