primitives

package
v6.5.0-p2p2-beta0+inco... Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 4 more Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorBadMethod             = 0
	ErrorNotAcceptable         = 1
	ErrorMissingVersionSpec    = 2
	ErrorMalformedVersionSpec  = 3
	ErrorBadVersionSpec        = 4
	ErrorEmptyRequest          = 5
	ErrorBadElementSpec        = 6
	ErrorBadIdentifier         = 7
	ErrorBlockNotFound         = 8
	ErrorEntryNotFound         = 9
	ErrorInternal              = 10
	ErrorJSONMarshal           = 11
	ErrorXMLMarshal            = 12
	ErrorUnsupportedMarshal    = 13
	ErrorJSONUnmarshal         = 14
	ErrorXMLUnmarshal          = 15
	ErrorUnsupportedUnmarshal  = 16
	ErrorBadPOSTData           = 17
	ErrorTemplateError         = 18
	ErrorHTTPNewRequestFailure = 19
	ErrorHTTPDoRequestFailure  = 20
	ErrorHTMLMarshal           = 21
)

Variables

View Source
var EntryCreditPrefix = []byte{0x59, 0x2a}
View Source
var EntryCreditPrivatePrefix = []byte{0x5d, 0xb6}
View Source
var FactoidPrefix = []byte{0x5f, 0xb1}
View Source
var FactoidPrivatePrefix = []byte{0x64, 0x78}

ZeroHash is a zero hash

Functions

func AddCommas

func AddCommas(v int64) (ret string)

func AreBinaryMarshallablesEqual

func AreBinaryMarshallablesEqual(b1, b2 interfaces.BinaryMarshallable) (bool, error)

AreBinaryMarshallablesEqual returns true if the input interfaces are both nil, or both exist and can be marshalled into byte identical arrays

func AreBytesEqual

func AreBytesEqual(b1, b2 []byte) bool

AreBytesEqual returns true iff the lengths and byte values of the input []byte arrays are equal

func BuildMerkleTreeStore

func BuildMerkleTreeStore(hashes []interfaces.IHash) (merkles []interfaces.IHash)

The root of the Merkle Tree is returned in merkles[len(merkles)-1]

func CalculateCoinbasePayout

func CalculateCoinbasePayout(efficiency uint16) uint64

func ComputeMerkleRoot

func ComputeMerkleRoot(hashes []interfaces.IHash) interfaces.IHash

Give a list of hashes, return the root of the Merkle Tree

func ConvertAddressToUser

func ConvertAddressToUser(prefix []byte, addr interfaces.IAddress) []byte

Convert Factoid and Entry Credit addresses to their more user friendly and human readable formats.

Creates the binary form. Just needs the conversion to base58 for display.

func ConvertDecimalToFloat

func ConvertDecimalToFloat(v uint64) float64

Converts factoshis to floating point factoids

func ConvertDecimalToPaddedString

func ConvertDecimalToPaddedString(v uint64) string

Take fixed point data and produce a nice decimal point sort of output that users can handle.

func ConvertDecimalToString

func ConvertDecimalToString(v uint64) string

Converts factoshis to floating point string

func ConvertECAddressToUserStr

func ConvertECAddressToUserStr(addr interfaces.IAddress) string

Convert Entry Credits

func ConvertECPrivateToUserStr

func ConvertECPrivateToUserStr(addr interfaces.IAddress) string

Convert Entry Credit Private key

func ConvertFctAddressToUserStr

func ConvertFctAddressToUserStr(addr interfaces.IAddress) string

Convert Factoid Addresses

func ConvertFctPrivateToUserStr

func ConvertFctPrivateToUserStr(addr interfaces.IAddress) string

Convert Factoid Private Key

func ConvertFixedPoint

func ConvertFixedPoint(amt string) (string, error)

Convert Decimal point input to FixedPoint (no decimal point) output suitable for Factom to chew on.

func ConvertUserStrToAddress

func ConvertUserStrToAddress(userFAddr string) []byte

Convert a User facing Factoid or Entry Credit address or their Private Key representations to the regular form. Note validation must be done separately!

func CreateHash

func CreateHash(entities ...interfaces.BinaryMarshallable) (h interfaces.IHash, err error)

CreateHash returns a hash created from all input entities

func DecodeBinary

func DecodeBinary(bytes string) ([]byte, error)

DecodeBinary returns a byte array of the decoded input hexadecimal (0-F) string

func DecodeJSON

func DecodeJSON(data []byte, v interface{}) error

DecodeJSON unmarshals input []byte into input interface

func DecodeJSONString

func DecodeJSONString(data string, v interface{}) error

DecodeJSONString unmarshals input string into input interface

func DecodeVarInt

func DecodeVarInt(data []byte) (uint64, []byte)

DecodeVarInt decodes a variable integer from the given data buffer. We use the algorithm used by Go, only BigEndian.

func DecodeVarIntGo

func DecodeVarIntGo(data []byte) (uint64, []byte)

DecodeVarIntGo decodes a variable integer from the given data buffer. We use the algorithm used by Go, only BigEndian.

func DoubleSha

func DoubleSha(data []byte) []byte

DoubleSha returns a new hash created by double hashing the input: shad Double Sha256 Hash; sha256(sha256(data))

func EfficiencyToString

func EfficiencyToString(eff uint16) string

func EncodeBinary

func EncodeBinary(bytes []byte) string

EncodeBinary returns the hexadecimal (0-F) encoding of input byte array

func EncodeJSON

func EncodeJSON(data interface{}) ([]byte, error)

EncodeJSON marshals data into Json format

func EncodeJSONString

func EncodeJSONString(data interface{}) (string, error)

EncodeJSONString marshals data into Json format

func EncodeJSONToBuffer

func EncodeJSONToBuffer(data interface{}, b *bytes.Buffer) error

EncodeJSONToBuffer marshals input data into Json format and writes it to the input buffer

func EncodeVarInt

func EncodeVarInt(out *Buffer, v uint64) error

EncodeVarInt encodes an integer as a variable int into the given data buffer.

func EncodeVarIntGo

func EncodeVarIntGo(out *Buffer, v uint64) error

EncodeVarIntGo encodes an integer as a variable int into the given data buffer.

func GenerateKeyFromPrivateKey

func GenerateKeyFromPrivateKey(privateKey []byte) (public []byte, private []byte, err error)

func GetTime

func GetTime() uint64

func GetTimeMilli

func GetTimeMilli() uint64

func HashMerkleBranches

func HashMerkleBranches(left interfaces.IHash, right interfaces.IHash) interfaces.IHash

HashMerkleBranches takes two hashes, treated as the left and right tree nodes, and returns the hash of their concatenation. This is a helper function used to aid in the generation of a merkle tree.

func HexToHash

func HexToHash(hexStr string) (h interfaces.IHash, err error)

HexToHash converts the input hexidecimal (0-F) string into the internal []byte array

func HumanReadableECPrivateKeyToPrivateKey

func HumanReadableECPrivateKeyToPrivateKey(human string) ([]byte, error)

func HumanReadableECPrivateKeyToPrivateKeyString

func HumanReadableECPrivateKeyToPrivateKeyString(human string) (string, error)

func HumanReadableFactoidPrivateKeyToPrivateKey

func HumanReadableFactoidPrivateKeyToPrivateKey(human string) ([]byte, error)

func HumanReadableFactoidPrivateKeyToPrivateKeyString

func HumanReadableFactoidPrivateKeyToPrivateKeyString(human string) (string, error)

func Log

func Log(format string, args ...interface{})

Log prints the formated string with args (using fmt.Printf) with a prepended file and line number of the calling function: "<file>:<linenumber> - <fmt.Printf_output>\n"

func LogJSONs

func LogJSONs(format string, args ...interface{})

LogJSONs converts input args to Json format and then prints the formated string with new Json args (using fmt.Printf) with a prepended file and line number of the calling function: "<file>:<linenumber> - <fmt.Printf_output>\n"

func LogNilHashBug

func LogNilHashBug(msg string)

func Loghash

func Loghash(h interfaces.IHash)

Loghash logs the input interface

func Loghashfixed

func Loghashfixed(h [32]byte)

Loghashfixed logs the input hash ***************************************************************

	DEBUG logging to keep full hash. Turned on from command line
 ***************************************************************

func MnemonicStringToPrivateKey

func MnemonicStringToPrivateKey(mnemonic string) ([]byte, error)

func MnemonicStringToPrivateKeyString

func MnemonicStringToPrivateKeyString(mnemonic string) (string, error)

func NewHash

func NewHash(b []byte) interfaces.IHash

NewHash creates a new object for the input hash

func NewShaHashFromStruct

func NewShaHashFromStruct(DataStruct interface{}) (interfaces.IHash, error)

NewShaHashFromStruct marshals the input struct into a json byte array, then double hashes the json array

func NewZeroHash

func NewZeroHash() interfaces.IHash

NewZeroHash creates a new zero hash object

func NextPowerOfTwo

func NextPowerOfTwo(n int) int

NextPowerOfTwo returns the next highest power of two from a given number if it is not already a power of two. This is a helper function used during the calculation of a merkle tree.

func PrivateKeyStringToHumanReadableECPrivateKey

func PrivateKeyStringToHumanReadableECPrivateKey(priv string) (string, error)

func PrivateKeyStringToHumanReadableFactoidPrivateKey

func PrivateKeyStringToHumanReadableFactoidPrivateKey(priv string) (string, error)

func PrivateKeyStringToHumanReadablePrivateKey

func PrivateKeyStringToHumanReadablePrivateKey(priv string, b1, b2 byte) (string, error)

func PrivateKeyStringToPublicKey

func PrivateKeyStringToPublicKey(private string) ([]byte, error)

func PrivateKeyStringToPublicKeyString

func PrivateKeyStringToPublicKeyString(private string) (string, error)

func PrivateKeyToPublicKey

func PrivateKeyToPublicKey(private []byte) ([]byte, error)

func RandomHash

func RandomHash() interfaces.IHash

RandomHash returns a new random hash

func RandomSignatureSet

func RandomSignatureSet() ([]byte, interfaces.Signer, interfaces.IFullSignature)

func RandomVarInt

func RandomVarInt() uint64

RandomVarInt returns a random variable integer

func Sha

func Sha(p []byte) interfaces.IHash

Sha creates a Sha256 Hash from a byte array

func Shad

func Shad(data []byte) interfaces.IHash

Shad returns a new hash created by double hashing the input: Double Sha256 Hash; sha256(sha256(data))

func Sign

func Sign(priv, data []byte) []byte

func SignSignable

func SignSignable(priv []byte, data interfaces.ISignable) ([]byte, error)

func UnmarshalBinaryDataOfLength

func UnmarshalBinaryDataOfLength(dest []byte, source []byte, length int) (newData []byte, err error)

UnmarshalBinaryDataOfLength unmarshals an arbitrary input []byte array up to specified length, returning residual

func ValidateECPrivateUserStr

func ValidateECPrivateUserStr(userFAddr string) bool

Validate Entry Credit Private Key

func ValidateECUserStr

func ValidateECUserStr(userFAddr string) bool

Validate Entry Credits

func ValidateFPrivateUserStr

func ValidateFPrivateUserStr(userFAddr string) bool

Validate Factoid Private Key

func ValidateFUserStr

func ValidateFUserStr(userFAddr string) bool

Validate Factoids

func VarIntLength

func VarIntLength(v uint64) uint64

VarIntLength returns the length of the variable integer when encoded as a var int

func Verify

func Verify(publicKey *[ed25519.PublicKeySize]byte, message []byte, sig *[ed25519.SignatureSize]byte) bool

Verify returns true iff sig is a valid signature of message by publicKey.

func VerifySignature

func VerifySignature(data, publicKey, signature []byte) error

func VerifySlice

func VerifySlice(p []byte, message []byte, s []byte) bool

VerifySlice returns true iff sig is a valid signature of message by publicKey.

func WriteNumber16

func WriteNumber16(out *Buffer, num uint16)

func WriteNumber32

func WriteNumber32(out *Buffer, num uint32)

func WriteNumber64

func WriteNumber64(out *Buffer, num uint64)

func WriteNumber8

func WriteNumber8(out *Buffer, num uint8)

Types

type Buffer

type Buffer struct {
	bytes.Buffer
}

Buffer contains a bytes.Buffer

func NewBuffer

func NewBuffer(buf []byte) *Buffer

NewBuffer copies the input []byte array int a new Buffer object and returns the Buffer

func (*Buffer) DeepCopyBytes

func (b *Buffer) DeepCopyBytes() []byte

DeepCopyBytes returns the remainder of the unread buffer. Despite its name, it DOES NOT COPY!

func (*Buffer) PeekByte

func (b *Buffer) PeekByte() (byte, error)

PeekByte returns the next unread byte in the buffer without advancing the read state

func (*Buffer) Pop

func (b *Buffer) Pop(h []byte) error

Pop reads a number of bytes equal to the length of the input []byte array

func (*Buffer) PopBinaryMarshallable

func (b *Buffer) PopBinaryMarshallable(dst interfaces.BinaryMarshallable) error

PopBinaryMarshallable reads a binary marshallable interface object from the Buffer

func (*Buffer) PopBinaryMarshallableMsgArray

func (b *Buffer) PopBinaryMarshallableMsgArray() ([]interfaces.IMsg, error)

PopBinaryMarshallableMsgArray reads a message array from the Buffer

func (*Buffer) PopBool

func (b *Buffer) PopBool() (bool, error)

PopBool reads a bool from the Buffer

func (*Buffer) PopByte

func (b *Buffer) PopByte() (byte, error)

PopByte reads a byte from the buffer

func (*Buffer) PopBytes

func (b *Buffer) PopBytes() ([]byte, error)

PopBytes reads a byte array from the Buffer

func (*Buffer) PopIHash

func (b *Buffer) PopIHash() (interfaces.IHash, error)

PopIHash reads an hash from the Buffer

func (*Buffer) PopInt

func (b *Buffer) PopInt() (int, error)

PopInt reads an int from the Buffer

func (*Buffer) PopInt64

func (b *Buffer) PopInt64() (int64, error)

PopInt64 reads an int64 from the Buffer

func (*Buffer) PopLen

func (b *Buffer) PopLen(l int) ([]byte, error)

PopLen reads a number of bytes equal to the input length from the Buffer

func (*Buffer) PopMsg

func (b *Buffer) PopMsg() (msg interfaces.IMsg, err error)

PopMsg reads a message from the Buffer

func (*Buffer) PopString

func (b *Buffer) PopString() (string, error)

PopString reads a string from the Buffer

func (*Buffer) PopTimestamp

func (b *Buffer) PopTimestamp() (interfaces.Timestamp, error)

PopTimestamp reads a time stamp from the Buffer

func (*Buffer) PopUInt16

func (b *Buffer) PopUInt16() (uint16, error)

PopUInt16 reads a uint16 from the Buffer

func (*Buffer) PopUInt32

func (b *Buffer) PopUInt32() (uint32, error)

PopUInt32 reads a uint32 from the Buffer

func (*Buffer) PopUInt64

func (b *Buffer) PopUInt64() (uint64, error)

PopUInt64 reads a uint64 from the Buffer

func (*Buffer) PopUInt8

func (b *Buffer) PopUInt8() (uint8, error)

PopUInt8 reads a uint8 from the Buffer

func (*Buffer) PopVarInt

func (b *Buffer) PopVarInt() (uint64, error)

PopVarInt reads an integer from the Buffer

func (*Buffer) Push

func (b *Buffer) Push(h []byte) error

Push appends the input []byte array to the Buffer. Return error will always be nil, because Write gaurantees a nil error return.

func (*Buffer) PushBinaryMarshallable

func (b *Buffer) PushBinaryMarshallable(bm interfaces.BinaryMarshallable) error

PushBinaryMarshallable marshals the input and writes it to the Buffer

func (*Buffer) PushBinaryMarshallableMsgArray

func (b *Buffer) PushBinaryMarshallableMsgArray(bm []interfaces.IMsg) error

PushBinaryMarshallableMsgArray marshals the input message array and writes it into the Buffer

func (*Buffer) PushBool

func (b *Buffer) PushBool(boo bool) error

PushBool writes the input bool to the Buffer

func (*Buffer) PushByte

func (b *Buffer) PushByte(h byte) error

PushByte writes the input byte to the Buffer. Returned error is always nil.

func (*Buffer) PushBytes

func (b *Buffer) PushBytes(h []byte) error

PushBytes marshals and writes the []byte array to the Buffer

func (*Buffer) PushIHash

func (b *Buffer) PushIHash(h interfaces.IHash) error

PushIHash marshals and writes the input hash to the Buffer

func (*Buffer) PushInt

func (b *Buffer) PushInt(i int) error

PushInt writes an int to the Buffer.

func (*Buffer) PushInt64

func (b *Buffer) PushInt64(i int64) error

PushInt64 writes the input int64 to the Buffer

func (*Buffer) PushMsg

func (b *Buffer) PushMsg(msg interfaces.IMsg) error

PushMsg marshals and writes the input message to the Buffer

func (*Buffer) PushString

func (b *Buffer) PushString(s string) error

PushString marshals and writes the string to the Buffer

func (*Buffer) PushTimestamp

func (b *Buffer) PushTimestamp(ts interfaces.Timestamp) error

PushTimestamp writes a timestamp into the Buffer

func (*Buffer) PushUInt16

func (b *Buffer) PushUInt16(i uint16) error

PushUInt16 writes the input uint16 to the Buffer

func (*Buffer) PushUInt32

func (b *Buffer) PushUInt32(i uint32) error

PushUInt32 writes the input uint32 to the Buffer

func (*Buffer) PushUInt64

func (b *Buffer) PushUInt64(i uint64) error

PushUInt64 writes the input uint64 to the Buffer

func (*Buffer) PushUInt8

func (b *Buffer) PushUInt8(h uint8) error

PushUInt8 writes the input int8 to the Buffer

func (*Buffer) PushVarInt

func (b *Buffer) PushVarInt(vi uint64) error

PushVarInt writes the smallest possible data to the Buffer to represent the input integer

type ByteSlice

type ByteSlice struct {
	Bytes []byte
}

ByteSlice contains a []byte

func RandomByteSlice

func RandomByteSlice() *ByteSlice

RandomByteSlice returns a random non empty ByteSlice of length 1 <= len <= 63

func StringToByteSlice

func StringToByteSlice(s string) *ByteSlice

StringToByteSlice converts the input string to a ByteSlice

func (*ByteSlice) IsSameAs

func (bs *ByteSlice) IsSameAs(b *ByteSlice) bool

IsSameAs returns true iff the input ByteSlice is binary identical to this ByteSlice

func (*ByteSlice) JSONByte

func (bs *ByteSlice) JSONByte() ([]byte, error)

JSONByte marshals the ByteSlice into json format

func (*ByteSlice) JSONString

func (bs *ByteSlice) JSONString() (string, error)

JSONString marshals the ByteSlice into json format byte string

func (*ByteSlice) MarshalBinary

func (bs *ByteSlice) MarshalBinary() (rval []byte, err error)

MarshalBinary returns the byte array of the ByteSlice

func (*ByteSlice) MarshalText

func (bs *ByteSlice) MarshalText() (rval []byte, err error)

MarshalText marshals the receiver into text

func (*ByteSlice) New

New returns a new ByteSlice

func (*ByteSlice) String

func (bs *ByteSlice) String() string

String returns a hexidecimal (0-F) string of the ByteSlice

func (*ByteSlice) UnmarshalBinary

func (bs *ByteSlice) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the input byte array into the ByteSlice

func (*ByteSlice) UnmarshalBinaryData

func (bs *ByteSlice) UnmarshalBinaryData(data []byte) (newData []byte, err error)

UnmarshalBinaryData copies the input byte array to the ByteSlice

type ByteSlice20

type ByteSlice20 [20]byte

ByteSlice20 is a fixed [20]byte

func (*ByteSlice20) GetFixed

func (bs *ByteSlice20) GetFixed() ([20]byte, error)

GetFixed returns a new copy of the internal byte array

func (*ByteSlice20) IsSameAs

func (bs *ByteSlice20) IsSameAs(b *ByteSlice20) bool

IsSameAs returns true iff input ByteSlice20 is binary identical to this ByteSlice20

func (*ByteSlice20) JSONByte

func (bs *ByteSlice20) JSONByte() ([]byte, error)

JSONByte returns the encoded JSON format data

func (*ByteSlice20) JSONString

func (bs *ByteSlice20) JSONString() (string, error)

JSONString returns the encoded JSON format byte string

func (*ByteSlice20) MarshalBinary

func (bs *ByteSlice20) MarshalBinary() (rval []byte, err error)

MarshalBinary returns the byte array of the ByteSlice20

func (*ByteSlice20) MarshalText

func (bs *ByteSlice20) MarshalText() (rval []byte, err error)

MarshalText marshals the internal ByteSlice20

func (*ByteSlice20) String

func (bs *ByteSlice20) String() string

String returns a hexidecimal (0-F) string of the internal data

func (*ByteSlice20) UnmarshalBinary

func (bs *ByteSlice20) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the input data into the ByteSlice20

func (*ByteSlice20) UnmarshalBinaryData

func (bs *ByteSlice20) UnmarshalBinaryData(data []byte) (newData []byte, err error)

UnmarshalBinaryData unmarshals the input data into the ByteSlice20

type ByteSlice32

type ByteSlice32 [32]byte

ByteSlice32 is a fixed [32]byte array

func Byte32ToByteSlice32

func Byte32ToByteSlice32(b [32]byte) *ByteSlice32

Byte32ToByteSlice32 returns a new ByteSlice32 containing the input data

func StringToByteSlice32

func StringToByteSlice32(s string) *ByteSlice32

StringToByteSlice32 converts the input hexidecimal string (0-F) to a new ByteSlice32

func (*ByteSlice32) Fixed

func (bs *ByteSlice32) Fixed() [32]byte

Fixed returns the internal fixed byte array data

func (*ByteSlice32) IsSameAs

func (bs *ByteSlice32) IsSameAs(b *ByteSlice32) bool

IsSameAs returns true iff input ByteSlice32 is binary identical to this ByteSlice

func (*ByteSlice32) JSONByte

func (bs *ByteSlice32) JSONByte() ([]byte, error)

JSONByte returns the encoded json data of this ByteSlice32

func (*ByteSlice32) JSONString

func (bs *ByteSlice32) JSONString() (string, error)

JSONString returns the encoded json byte string of this ByteSlice32

func (*ByteSlice32) MarshalBinary

func (bs *ByteSlice32) MarshalBinary() (rval []byte, err error)

MarshalBinary marshals this ByteSlice32 into []byte array

func (*ByteSlice32) MarshalText

func (bs *ByteSlice32) MarshalText() (rval []byte, err error)

MarshalText marshals this ByteSlice32 into the returned array

func (*ByteSlice32) String

func (bs *ByteSlice32) String() string

String returns the hexidecimal string (0-F) of this ByteSlice32

func (*ByteSlice32) UnmarshalBinary

func (bs *ByteSlice32) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the input data into this ByteSlice32

func (*ByteSlice32) UnmarshalBinaryData

func (bs *ByteSlice32) UnmarshalBinaryData(data []byte) (newData []byte, err error)

UnmarshalBinaryData unmarshals the input data into this ByteSlice32

type ByteSlice6

type ByteSlice6 [6]byte

ByteSlice6 is a fixed [6]byte array

func (*ByteSlice6) IsSameAs

func (bs *ByteSlice6) IsSameAs(b *ByteSlice6) bool

IsSameAs returns true iff the input ByteSlice6 is binary identical to this ByteSlice6

func (*ByteSlice6) JSONByte

func (bs *ByteSlice6) JSONByte() ([]byte, error)

JSONByte returns the json encoded data of the ByteSlice6

func (*ByteSlice6) JSONString

func (bs *ByteSlice6) JSONString() (string, error)

JSONString returns the json encoded byte string of the ByteSlice6

func (*ByteSlice6) MarshalBinary

func (bs *ByteSlice6) MarshalBinary() (rval []byte, err error)

MarshalBinary marshals this ByteSlice6 into a []byte array

func (*ByteSlice6) MarshalText

func (bs *ByteSlice6) MarshalText() (rval []byte, err error)

MarshalText marshals the ByteSlice6 into text

func (*ByteSlice6) String

func (bs *ByteSlice6) String() string

String returns the hexidecimal (0-F) string of the ByteSlice6S

func (*ByteSlice6) UnmarshalBinary

func (bs *ByteSlice6) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the input data into the ByteSlice6

func (*ByteSlice6) UnmarshalBinaryData

func (bs *ByteSlice6) UnmarshalBinaryData(data []byte) (newData []byte, err error)

UnmarshalBinaryData unmarshals the input data into the ByteSlice6

type ByteSlice64

type ByteSlice64 [64]byte

ByteSlice64 is a fixed [64]byte array

func (*ByteSlice64) IsSameAs

func (bs *ByteSlice64) IsSameAs(b *ByteSlice64) bool

IsSameAs returns true iff the input ByteSlice64 is binary identical to this ByteSlice64

func (*ByteSlice64) JSONByte

func (bs *ByteSlice64) JSONByte() ([]byte, error)

JSONByte returns the json encoded data

func (*ByteSlice64) JSONString

func (bs *ByteSlice64) JSONString() (string, error)

JSONString returns the json encoded byte string

func (*ByteSlice64) MarshalBinary

func (bs *ByteSlice64) MarshalBinary() (rval []byte, err error)

MarshalBinary marshals this ByteSlice64

func (*ByteSlice64) MarshalText

func (bs *ByteSlice64) MarshalText() (rval []byte, err error)

MarshalText marshals this ByteSlice64 into text

func (*ByteSlice64) String

func (bs *ByteSlice64) String() string

String returns the json encoded hexidecimal (0-F) string

func (*ByteSlice64) UnmarshalBinary

func (bs *ByteSlice64) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the input data into this ByteSlice64

func (*ByteSlice64) UnmarshalBinaryData

func (bs *ByteSlice64) UnmarshalBinaryData(data []byte) (newData []byte, err error)

UnmarshalBinaryData unmarshals the input data into this ByteSlice64

type ByteSliceSig

type ByteSliceSig [ed25519.SignatureSize]byte

ByteSliceSig is a fixed byte array of the ed25519 signature length

func (*ByteSliceSig) GetFixed

func (bs *ByteSliceSig) GetFixed() ([ed25519.SignatureSize]byte, error)

GetFixed returns a new copy of the internal byte array

func (*ByteSliceSig) IsSameAs

func (bs *ByteSliceSig) IsSameAs(b *ByteSliceSig) bool

IsSameAs returns true iff the input ByteSliceSig is binary identical to this ByteSliceSig

func (*ByteSliceSig) JSONByte

func (bs *ByteSliceSig) JSONByte() ([]byte, error)

JSONByte returns the json encoded data of the ByteSliceSig

func (*ByteSliceSig) JSONString

func (bs *ByteSliceSig) JSONString() (string, error)

JSONString returns the json encoded byte string of the ByteSliceSig

func (*ByteSliceSig) MarshalBinary

func (bs *ByteSliceSig) MarshalBinary() (rval []byte, err error)

MarshalBinary marshals this ByteSliceSig into []byte array

func (*ByteSliceSig) MarshalText

func (bs *ByteSliceSig) MarshalText() (rval []byte, err error)

MarshalText marshals the ByteSliceSig into text

func (*ByteSliceSig) String

func (bs *ByteSliceSig) String() string

String returns a hexidecimal (0-F) string of the ByteSliceSig

func (*ByteSliceSig) UnmarshalBinary

func (bs *ByteSliceSig) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the input data into the ByteSliceSig

func (*ByteSliceSig) UnmarshalBinaryData

func (bs *ByteSliceSig) UnmarshalBinaryData(data []byte) (newData []byte, err error)

UnmarshalBinaryData unmarshals the input data into the ByteSliceSig

func (*ByteSliceSig) UnmarshalText

func (bs *ByteSliceSig) UnmarshalText(text []byte) error

UnmarshalText unmarshals the input text to the ByteSliceSig

type Error

type Error struct {
	APICode     uint
	HTTPCode    int
	Name        string
	Description string
	SupportURL  string
	Message     string
}

func CreateError

func CreateError(code uint, message string) *Error

func (*Error) Error

func (r *Error) Error() string

type Hash

Hash is a convenient fixed []byte type created at the hash length

func NewShaHash

func NewShaHash(newHash []byte) (*Hash, error)

NewShaHash returns a new ShaHash from a byte slice. An error is returned if the number of bytes passed in is not constants.HASH_LENGTH.

func NewShaHashFromStr

func NewShaHashFromStr(hash string) (*Hash, error)

NewShaHashFromStr creates a ShaHash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the ShaHash.

func Sha512Half

func Sha512Half(p []byte) (h *Hash)

Sha512Half creates a Sha512[:256] Hash from a byte array

func (*Hash) ByteString

func (h *Hash) ByteString() string

ByteString returns the hash as a byte string

func (*Hash) Bytes

func (h *Hash) Bytes() (rval []byte)

Bytes returns a copy of the internal []byte array

func (*Hash) Copy

func (h *Hash) Copy() (rval interfaces.IHash)

Copy returns a copy of this Hash

func (*Hash) Fixed

func (h *Hash) Fixed() [constants.HASH_LENGTH]byte

Fixed returns the fixed []byte array

func (*Hash) GetBytes

func (h *Hash) GetBytes() []byte

GetBytes makes a copy of the hash in this hash. Changes to the return value WILL NOT be reflected in the source hash. You have to do a SetBytes to change the source value.

func (Hash) GetHash

func (Hash) GetHash() interfaces.IHash

GetHash is unused, merely here to implement the IHash interface

func (*Hash) IsHashNil

func (h *Hash) IsHashNil() bool

IsHashNil returns true if receiver is nil, or the hash is zero

func (*Hash) IsMinuteMarker

func (h *Hash) IsMinuteMarker() bool

IsMinuteMarker checks if the Hash is the hash of a minute marker (the last byte indicates the minute number) A minute marker is determined by having all but the last value as zero

func (*Hash) IsSameAs

func (a *Hash) IsSameAs(b interfaces.IHash) bool

IsSameAs compares two Hashes and returns true iff they hashs are binary identical

func (*Hash) IsZero

func (h *Hash) IsZero() bool

IsZero returns true iff Hash is zero

func (*Hash) JSONByte

func (h *Hash) JSONByte() ([]byte, error)

JSONByte returns the json encoded []byte array of the Hash

func (*Hash) JSONString

func (h *Hash) JSONString() (string, error)

JSONString returns the json encoded byte string of the Hash

func (*Hash) MarshalBinary

func (h *Hash) MarshalBinary() (rval []byte, err error)

MarshalBinary returns a copy of the []byte array

func (*Hash) MarshalText

func (h *Hash) MarshalText() (rval []byte, err error)

MarshalText marshals the Hash as text

func (*Hash) New

New creates a new Hash (required for BinarymarshallableAndCopyable interface)

func (*Hash) PFixed

func (h *Hash) PFixed() *[constants.HASH_LENGTH]byte

PFixed returns a pointer to the fixed []byte array

func (*Hash) SetBytes

func (h *Hash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not constants.HASH_LENGTH.

func (*Hash) String

func (h *Hash) String() string

String converts a hash into a hexidecimal (0-F) string

func (*Hash) ToMinute

func (h *Hash) ToMinute() byte

ToMinute returns the last byte of the Hash

func (*Hash) UnmarshalBinary

func (h *Hash) UnmarshalBinary(p []byte) (err error)

UnmarshalBinary unmarshals the input array into the Hash

func (*Hash) UnmarshalBinaryData

func (h *Hash) UnmarshalBinaryData(p []byte) (newData []byte, err error)

UnmarshalBinaryData unmarshals the input array into the Hash

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(b []byte) error

UnmarshalText unmarshals the input array

type JSON2Request

type JSON2Request struct {
	JSONRPC string      `json:"jsonrpc"` // version string which MUST be "2.0" (version 1.0 didn't have this field)
	ID      interface{} `json:"id"`      // Unique client defined ID associated with this request. It may be a number,
	// string, or nil. It is used by the remote to formulate a response object
	// containing the same ID back to the client. If nil, remote treats request object
	// as a notification, and that the client does not expect a response object back
	Params interface{} `json:"params,omitempty"` // input parameters for the subroutine called on the remote - may be omitted
	Method string      `json:"method,omitempty"` // name of the subroutine to be called on the remote
}

JSON2Request is an JSON RPC request object used in factomd according to the specification for JSON RPC 2.0 See specification: https://www.jsonrpc.org/specification Remote Proceedure Call (RPC) is a protocol for executing subroutines on a remote

func NewJSON2Request

func NewJSON2Request(method string, id, params interface{}) *JSON2Request

NewJSON2Request creates a new JSON2Request with the input parameters

func NewJSON2RequestBlank

func NewJSON2RequestBlank() *JSON2Request

NewJSON2RequestBlank creates a new blank JSON2Request object with only the JSONRPC field filled (because it has 1 acceptable value)

func ParseJSON2Request

func ParseJSON2Request(request string) (*JSON2Request, error)

ParseJSON2Request unmarshals a string into a JSON2Request object

func (*JSON2Request) JSONByte

func (j *JSON2Request) JSONByte() ([]byte, error)

JSONByte encodes object to a json []byte

func (*JSON2Request) JSONString

func (j *JSON2Request) JSONString() (string, error)

JSONString encodes object to a json string with error return

func (*JSON2Request) String

func (j *JSON2Request) String() string

String encodes object to a json string with no error return

type JSON2Response

type JSON2Response struct {
	JSONRPC string      `json:"jsonrpc"` // version string which MUST be "2.0" (version 1.0 didn't have this field)
	ID      interface{} `json:"id"`      // Unique client defined ID associated with incoming request. It may be a number,
	// string, or nil. It is used by the remote to formulate a this response object
	// containing the same ID back to the client. If nil, remote treats request object
	// as a notification, and that the client does not expect a response object back
	Error  *JSONError  `json:"error,omitempty"`  // Must be present if called subroutine had an error (mutually exclusive with Result)
	Result interface{} `json:"result,omitempty"` // Must be present if called subroutine succeeded (mutually exclusive with Error)
}

JSON2Response is an JSON RPC response object used in factomd according to the specification for JSON RPC 2.0 See specification: https://www.jsonrpc.org/specification Remote Proceedure Call (RPC) is a protocol for executing subroutines on a remote

func NewJSON2Response

func NewJSON2Response() *JSON2Response

NewJSON2Response returns a new JSON2Response initialized with defaults

func (*JSON2Response) AddError

func (j *JSON2Response) AddError(code int, message string, data interface{})

AddError sets the member Error with a new JSONError formed from the inputs

func (*JSON2Response) JSONByte

func (j *JSON2Response) JSONByte() ([]byte, error)

JSONByte encodes object to a json []byte

func (*JSON2Response) JSONString

func (j *JSON2Response) JSONString() (string, error)

JSONString encodes object to a json string

func (*JSON2Response) String

func (j *JSON2Response) String() string

String encodes object to a json string

type JSONError

type JSONError struct {
	Code    int         `json:"code"`           // The error code associated with the error type
	Message string      `json:"message"`        // The error message as a concise single sentence
	Data    interface{} `json:"data,omitempty"` // Optional data object containing additional information about the error
}

JSONError is an JSON RPC error object used in factomd according to the specification for JSON RPC 2.0 See specification: https://www.jsonrpc.org/specification Remote Proceedure Call (RPC) is a protocol for executing subroutines on a remote

func NewJSONError

func NewJSONError(code int, message string, data interface{}) *JSONError

NewJSONError returns a new JSONError struct filled with the inputs

func (*JSONError) Error

func (j *JSONError) Error() string

Error returns the member 'Message' of JSONError struct. If member 'Data' is also a string type, the return string is concatenated with a colon ":" and the string contents of 'Data'

type MerkleNode

type MerkleNode struct {
	Left  *Hash `json:"left,omitempty"`
	Right *Hash `json:"right,omitempty"`
	Top   *Hash `json:"top,omitempty"`
}

func BuildMerkleBranch

func BuildMerkleBranch(hashes []interfaces.IHash, entryIndex int, fullDetail bool) []*MerkleNode

func BuildMerkleBranchForHash

func BuildMerkleBranchForHash(hashes []interfaces.IHash, target interfaces.IHash, fullDetail bool) []*MerkleNode

type PrivateKey

type PrivateKey struct {
	Key *[ed25519.PrivateKeySize]byte
	Pub *PublicKey
}

PrivateKey contains Public/Private key pair

func NewPrivateKeyFromHex

func NewPrivateKeyFromHex(s string) (*PrivateKey, error)

NewPrivateKeyFromHex creates a new private key from a hex string

func NewPrivateKeyFromHexBytes

func NewPrivateKeyFromHexBytes(privKeybytes []byte) *PrivateKey

NewPrivateKeyFromHexBytes creates a new private key from hex []byte

func RandomPrivateKey

func RandomPrivateKey() *PrivateKey

RandomPrivateKey returns a new random private key

func (*PrivateKey) CustomMarshalText2

func (pk *PrivateKey) CustomMarshalText2(string) ([]byte, error)

CustomMarshalText2 is a badly named function which encodes the private key to a string and concatenates with the public key to return single string with both private and public keys - suggest renaming: MarshalPrivateAndPublicKeys

func (*PrivateKey) GenerateKey

func (pk *PrivateKey) GenerateKey() error

GenerateKey creates new PrivateKey / PublicKey pair or returns error

func (*PrivateKey) Init

func (pk *PrivateKey) Init()

Init initializes the internal Key/Pub pair to new []byte if previously nil

func (*PrivateKey) MarshalSign

MarshalSign marshals and signs msg with PrivateKey and return Signature

func (*PrivateKey) PrivateKeyString

func (pk *PrivateKey) PrivateKeyString() string

PrivateKeyString returns hex-encoded string of first 32 bytes of key (private key portion)

func (*PrivateKey) Public

func (pk *PrivateKey) Public() []byte

Public returns the public key of PrivateKey struct

func (*PrivateKey) PublicKeyString

func (pk *PrivateKey) PublicKeyString() string

PublicKeyString returns string of the public key

func (*PrivateKey) Sign

func (pk *PrivateKey) Sign(msg []byte) (sig interfaces.IFullSignature)

Sign signs msg with PrivateKey and return Signature

type PublicKey

type PublicKey [ed25519.PublicKeySize]byte

PublicKey contains only Public part of Public/Private key pair

func PubKeyFromString

func PubKeyFromString(instr string) (pk PublicKey)

PubKeyFromString decodes an input string into a public key

func (*PublicKey) Copy

func (k *PublicKey) Copy() (*PublicKey, error)

Copy creates a new copy of the public key

func (PublicKey) Fixed

func (k PublicKey) Fixed() [ed25519.PublicKeySize]byte

Fixed returns itself

func (*PublicKey) IsSameAs

func (k *PublicKey) IsSameAs(b *PublicKey) bool

IsSameAs returns true iff input 'b' is the same as 'k'

func (*PublicKey) MarshalBinary

func (k *PublicKey) MarshalBinary() (rval []byte, err error)

MarshalBinary marshals and returns a new []byte containing the PublicKey k

func (*PublicKey) MarshalText

func (k *PublicKey) MarshalText() (rval []byte, err error)

MarshalText marshals the public key into a []byte

func (*PublicKey) String

func (k *PublicKey) String() string

String encodes the public key into a string

func (*PublicKey) UnmarshalBinary

func (k *PublicKey) UnmarshalBinary(p []byte) (err error)

UnmarshalBinary unmarshals the input p into the public key k

func (*PublicKey) UnmarshalBinaryData

func (k *PublicKey) UnmarshalBinaryData(p []byte) ([]byte, error)

UnmarshalBinaryData unmarshals the first section of input p of the size of a public key, and returns the residual data p

func (*PublicKey) UnmarshalText

func (k *PublicKey) UnmarshalText(b []byte) error

UnmarshalText decodes the input []byte public key into 'k'

func (*PublicKey) Verify

func (k *PublicKey) Verify(msg []byte, sig *[ed25519.SignatureSize]byte) bool

Verify returns true iff sig is a valid signature of message by publicKey k

type Signature

type Signature struct {
	Pub *PublicKey    `json:"pub"`
	Sig *ByteSliceSig `json:"sig"`
}

type DetachedSignature [ed25519.SignatureSize]byte type DetachedPublicKey [ed25519.PublicKeySize]byte

Signature has signed data and its corresponding PublicKey

func (*Signature) Bytes

func (sig *Signature) Bytes() []byte

func (*Signature) CustomMarshalText

func (sig *Signature) CustomMarshalText() ([]byte, error)

func (*Signature) GetKey

func (sig *Signature) GetKey() []byte

func (*Signature) GetPubBytes

func (sig *Signature) GetPubBytes() []byte

func (*Signature) GetSigBytes

func (sig *Signature) GetSigBytes() []byte

func (*Signature) GetSignature

func (sig *Signature) GetSignature() *[ed25519.SignatureSize]byte

func (*Signature) Init

func (e *Signature) Init()

func (*Signature) IsSameAs

func (a *Signature) IsSameAs(b interfaces.IFullSignature) bool

func (*Signature) MarshalBinary

func (s *Signature) MarshalBinary() (rval []byte, err error)

func (*Signature) SetPub

func (sig *Signature) SetPub(publicKey []byte)

func (*Signature) SetSignature

func (sig *Signature) SetSignature(signature []byte) error

func (*Signature) UnmarshalBinary

func (s *Signature) UnmarshalBinary(data []byte) error

func (*Signature) UnmarshalBinaryData

func (sig *Signature) UnmarshalBinaryData(data []byte) ([]byte, error)

func (*Signature) Verify

func (sig *Signature) Verify(msg []byte) bool

Verify returns true iff sig is a valid signature of msg by PublicKey.

type Timestamp

type Timestamp uint64 //in miliseconds

A structure for handling timestamps for messages

func NewTimestampFromMilliseconds

func NewTimestampFromMilliseconds(s uint64) *Timestamp

func NewTimestampFromMinutes

func NewTimestampFromMinutes(s uint32) *Timestamp

func NewTimestampFromSeconds

func NewTimestampFromSeconds(s uint32) *Timestamp

func NewTimestampNow

func NewTimestampNow() *Timestamp

func (Timestamp) Clone

func (t Timestamp) Clone() interfaces.Timestamp

Clone() Functions that return timestamps in structures should clone said timestamps so users don't change the timestamp in the structures.

func (*Timestamp) GetTime

func (t *Timestamp) GetTime() time.Time

func (*Timestamp) GetTimeMilli

func (t *Timestamp) GetTimeMilli() int64

func (*Timestamp) GetTimeMilliUInt64

func (t *Timestamp) GetTimeMilliUInt64() uint64

func (*Timestamp) GetTimeMinutesUInt32

func (t *Timestamp) GetTimeMinutesUInt32() uint32

func (*Timestamp) GetTimeSeconds

func (t *Timestamp) GetTimeSeconds() int64

func (*Timestamp) GetTimeSecondsUInt32

func (t *Timestamp) GetTimeSecondsUInt32() uint32

func (*Timestamp) IsSameAs

func (a *Timestamp) IsSameAs(b interfaces.Timestamp) bool

func (*Timestamp) MarshalBinary

func (t *Timestamp) MarshalBinary() (rval []byte, err error)

func (*Timestamp) SetTime

func (t *Timestamp) SetTime(miliseconds uint64)

func (*Timestamp) SetTimeMilli

func (t *Timestamp) SetTimeMilli(miliseconds int64)

func (*Timestamp) SetTimeNow

func (t *Timestamp) SetTimeNow()

func (*Timestamp) SetTimeSeconds

func (t *Timestamp) SetTimeSeconds(seconds int64)

func (*Timestamp) SetTimestamp

func (t *Timestamp) SetTimestamp(b interfaces.Timestamp)

func (*Timestamp) String

func (t *Timestamp) String() string

func (*Timestamp) UTCString

func (t *Timestamp) UTCString() string

func (*Timestamp) UnmarshalBinary

func (t *Timestamp) UnmarshalBinary(data []byte) error

func (*Timestamp) UnmarshalBinaryData

func (t *Timestamp) UnmarshalBinaryData(data []byte) (newData []byte, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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