primitives

package
v0.0.0-...-303b437 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 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}

Functions

func AddCommas

func AddCommas(v int64) (ret string)

func AreBinaryMarshallablesEqual

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

func AreBytesEqual

func AreBytesEqual(b1, b2 []byte) bool

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)

func DecodeBinary

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

func DecodeJSON

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

func DecodeJSONString

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

func DecodeVarInt

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

func DecodeVarIntGo

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

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

func DoubleSha

func DoubleSha(data []byte) []byte

shad Double Sha256 Hash; sha256(sha256(data))

func EfficiencyToString

func EfficiencyToString(eff uint16) string

func EncodeBinary

func EncodeBinary(bytes []byte) string

func EncodeJSON

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

func EncodeJSONString

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

func EncodeJSONToBuffer

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

func EncodeVarInt

func EncodeVarInt(out *Buffer, v uint64) error

func EncodeVarIntGo

func EncodeVarIntGo(out *Buffer, v uint64) error

Encode 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)

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{})

func LogJSONs

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

func LogNilHashBug

func LogNilHashBug(msg string)

func Loghash

func Loghash(h interfaces.IHash)

func Loghashfixed

func Loghashfixed(h [32]byte)

***************************************************************

	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

func NewShaHashFromStruct

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

func NewZeroHash

func NewZeroHash() interfaces.IHash

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

func RandomSignatureSet

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

func RandomVarInt

func RandomVarInt() uint64

func Sha

func Sha(p []byte) interfaces.IHash

Create a Sha256 Hash from a byte array

func Shad

func Shad(data []byte) interfaces.IHash

Shad 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 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

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

Verify 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
}

func NewBuffer

func NewBuffer(buf []byte) *Buffer

func (*Buffer) DeepCopyBytes

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

func (*Buffer) PeekByte

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

func (*Buffer) Pop

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

func (*Buffer) PopBinaryMarshallable

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

func (*Buffer) PopBinaryMarshallableMsgArray

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

func (*Buffer) PopBool

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

func (*Buffer) PopByte

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

func (*Buffer) PopBytes

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

func (*Buffer) PopIHash

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

func (*Buffer) PopInt

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

func (*Buffer) PopInt64

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

func (*Buffer) PopLen

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

func (*Buffer) PopMsg

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

func (*Buffer) PopString

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

func (*Buffer) PopTimestamp

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

func (*Buffer) PopUInt16

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

func (*Buffer) PopUInt32

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

func (*Buffer) PopUInt64

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

func (*Buffer) PopUInt8

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

func (*Buffer) PopVarInt

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

func (*Buffer) Push

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

func (*Buffer) PushBinaryMarshallable

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

func (*Buffer) PushBinaryMarshallableMsgArray

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

func (*Buffer) PushBool

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

func (*Buffer) PushByte

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

func (*Buffer) PushBytes

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

func (*Buffer) PushIHash

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

func (*Buffer) PushInt

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

func (*Buffer) PushInt64

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

func (*Buffer) PushMsg

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

func (*Buffer) PushString

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

func (*Buffer) PushTimestamp

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

func (*Buffer) PushUInt16

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

func (*Buffer) PushUInt32

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

func (*Buffer) PushUInt64

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

func (*Buffer) PushUInt8

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

func (*Buffer) PushVarInt

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

type ByteSlice

type ByteSlice struct {
	Bytes []byte
}

func RandomByteSlice

func RandomByteSlice() *ByteSlice

func StringToByteSlice

func StringToByteSlice(s string) *ByteSlice

func (*ByteSlice) IsSameAs

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

func (*ByteSlice) JSONByte

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

func (*ByteSlice) JSONString

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

func (*ByteSlice) MarshalBinary

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

func (*ByteSlice) MarshalText

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

func (*ByteSlice) New

func (*ByteSlice) String

func (bs *ByteSlice) String() string

func (*ByteSlice) UnmarshalBinary

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

func (*ByteSlice) UnmarshalBinaryData

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

type ByteSlice20

type ByteSlice20 [20]byte

func (*ByteSlice20) GetFixed

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

func (*ByteSlice20) IsSameAs

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

func (*ByteSlice20) JSONByte

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

func (*ByteSlice20) JSONString

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

func (*ByteSlice20) MarshalBinary

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

func (*ByteSlice20) MarshalText

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

func (*ByteSlice20) String

func (bs *ByteSlice20) String() string

func (*ByteSlice20) UnmarshalBinary

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

func (*ByteSlice20) UnmarshalBinaryData

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

type ByteSlice32

type ByteSlice32 [32]byte

func Byte32ToByteSlice32

func Byte32ToByteSlice32(b [32]byte) *ByteSlice32

func StringToByteSlice32

func StringToByteSlice32(s string) *ByteSlice32

func (*ByteSlice32) Fixed

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

func (*ByteSlice32) IsSameAs

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

func (*ByteSlice32) JSONByte

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

func (*ByteSlice32) JSONString

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

func (*ByteSlice32) MarshalBinary

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

func (*ByteSlice32) MarshalText

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

func (*ByteSlice32) String

func (bs *ByteSlice32) String() string

func (*ByteSlice32) UnmarshalBinary

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

func (*ByteSlice32) UnmarshalBinaryData

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

type ByteSlice6

type ByteSlice6 [6]byte

func (*ByteSlice6) IsSameAs

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

func (*ByteSlice6) JSONByte

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

func (*ByteSlice6) JSONString

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

func (*ByteSlice6) MarshalBinary

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

func (*ByteSlice6) MarshalText

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

func (*ByteSlice6) String

func (bs *ByteSlice6) String() string

func (*ByteSlice6) UnmarshalBinary

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

func (*ByteSlice6) UnmarshalBinaryData

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

type ByteSlice64

type ByteSlice64 [64]byte

func (*ByteSlice64) IsSameAs

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

func (*ByteSlice64) JSONByte

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

func (*ByteSlice64) JSONString

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

func (*ByteSlice64) MarshalBinary

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

func (*ByteSlice64) MarshalText

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

func (*ByteSlice64) String

func (bs *ByteSlice64) String() string

func (*ByteSlice64) UnmarshalBinary

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

func (*ByteSlice64) UnmarshalBinaryData

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

type ByteSliceSig

type ByteSliceSig [ed25519.SignatureSize]byte

func (*ByteSliceSig) GetFixed

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

func (*ByteSliceSig) IsSameAs

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

func (*ByteSliceSig) JSONByte

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

func (*ByteSliceSig) JSONString

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

func (*ByteSliceSig) MarshalBinary

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

func (*ByteSliceSig) MarshalText

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

func (*ByteSliceSig) String

func (bs *ByteSliceSig) String() string

func (*ByteSliceSig) UnmarshalBinary

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

func (*ByteSliceSig) UnmarshalBinaryData

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

func (*ByteSliceSig) UnmarshalText

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

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

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)

Create a Sha512[:256] Hash from a byte array

func (*Hash) ByteString

func (h *Hash) ByteString() string

func (*Hash) Bytes

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

func (*Hash) Copy

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

func (*Hash) Fixed

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

func (*Hash) GetBytes

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

Make 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

func (*Hash) IsHashNil

func (h *Hash) IsHashNil() bool

func (*Hash) IsMinuteMarker

func (h *Hash) IsMinuteMarker() bool

Is the hash a minute marker (the last byte indicates the minute number)

func (*Hash) IsSameAs

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

Compare two Hashes

func (*Hash) IsZero

func (h *Hash) IsZero() bool

func (*Hash) JSONByte

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

func (*Hash) JSONString

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

func (*Hash) MarshalBinary

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

func (*Hash) MarshalText

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

func (*Hash) New

func (*Hash) PFixed

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

func (*Hash) SetBytes

func (hash *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

Convert a hash into a string with hex encoding

func (*Hash) ToMinute

func (h *Hash) ToMinute() byte

func (*Hash) UnmarshalBinary

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

func (*Hash) UnmarshalBinaryData

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

func (*Hash) UnmarshalText

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

type JSON2Request

type JSON2Request struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id"`
	Params  interface{} `json:"params,omitempty"`
	Method  string      `json:"method,omitempty"`
}

func NewJSON2Request

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

func NewJSON2RequestBlank

func NewJSON2RequestBlank() *JSON2Request

func ParseJSON2Request

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

func (*JSON2Request) JSONByte

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

func (*JSON2Request) JSONString

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

func (*JSON2Request) String

func (e *JSON2Request) String() string

type JSON2Response

type JSON2Response struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id"`
	Error   *JSONError  `json:"error,omitempty"`
	Result  interface{} `json:"result,omitempty"`
}

func NewJSON2Response

func NewJSON2Response() *JSON2Response

func (*JSON2Response) AddError

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

func (*JSON2Response) JSONByte

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

func (*JSON2Response) JSONString

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

func (*JSON2Response) String

func (e *JSON2Response) String() string

type JSONError

type JSONError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

func NewJSONError

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

func (*JSONError) Error

func (j *JSONError) Error() string

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)

Create a new private key from a hex string

func NewPrivateKeyFromHexBytes

func NewPrivateKeyFromHexBytes(privKeybytes []byte) *PrivateKey

func RandomPrivateKey

func RandomPrivateKey() *PrivateKey

func (*PrivateKey) AllocateNew

func (pk *PrivateKey) AllocateNew()

func (*PrivateKey) CustomMarshalText2

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

func (*PrivateKey) GenerateKey

func (pk *PrivateKey) GenerateKey() error

Generate creates new PrivateKey / PublciKey pair or returns error

func (*PrivateKey) Init

func (e *PrivateKey) Init()

func (*PrivateKey) MarshalSign

Sign signs msg with PrivateKey and return Signature

func (*PrivateKey) PrivateKeyString

func (pk *PrivateKey) PrivateKeyString() string

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

func (*PrivateKey) Public

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

func (*PrivateKey) PublicKeyString

func (pk *PrivateKey) PublicKeyString() string

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)

func (*PublicKey) Copy

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

func (PublicKey) Fixed

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

func (*PublicKey) IsSameAs

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

func (*PublicKey) MarshalBinary

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

func (*PublicKey) MarshalText

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

func (*PublicKey) String

func (pk *PublicKey) String() string

func (*PublicKey) UnmarshalBinary

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

func (*PublicKey) UnmarshalBinaryData

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

func (*PublicKey) UnmarshalText

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

func (*PublicKey) Verify

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

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) 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