Back to godoc.org
github.com/Factom-Asset-Tokens/factom

package factom

v0.0.0 (fba5860)
Latest Go to latest
Published: Feb 26, 2020 | License: MIT | Module: github.com/Factom-Asset-Tokens/factom

Overview

Package factom provides data types corresponding to some of the Factom blockchain's data structures, as well as methods on those types for securely querying the data from factomd and factom-walletd's APIs.

In this case, secure means that all of the cryptographic hashes related to a factom data structure are verified during BinaryUnmarshaling.

All of the Factom data structure types in this package have Get, IsPopulated, MarshalBinary, and UnmarshalBinary methods. All Get functions populate the object they are called on, and use a factomd raw data API to pass to UnmarshalBinary, which also performs all applicable cryptographic validation.

Methods that accept a *Client, like those that start with Get, will make calls to the factomd or factom-walletd API queries to populate the data in the variable on which it is called. The returned error can be checked to see if it is a jsonrpc2.Error type, indicating that the networking calls were successful, but that there is some error returned by the RPC method.

IsPopulated methods return whether the data in the variable has been populated by a successful call to Get.

The DBlock, EBlock and Entry types allow for exploring the Factom blockchain.

The Bytes and Bytes32 types implement the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces and are used by other types when JSON marshaling and unmarshaling to and from hex strings is required.

Bytes32 is an array used for ChainIDs, KeyMRs, and other 32 byte hashes.

The Address interfaces and types allow for working with the four Factom address types.

The IDKey interfaces and types allow for working with the id/sk key pairs for server identities.

The Identity type provides a way to retrieve the ID1Key from an established Identity Chain.

Currently this package supports creating new chains and entries using both the factom-walletd "compose" methods, and by locally generating the commit and reveal data, if the private entry credit key is available locally. See Entry.Create and Entry.ComposeCreate.

This package does not yet support Factoid transactions, nor does it support the binary data structures for Admin Blocks, Entry Credit Blocks, or Factoid Blocks.

Index

Constants

const (
	FactomdDefault = "http://localhost:8088/v2"
	WalletdDefault = "http://localhost:8089/v2"
)

Defaults for the factomd and factom-walletd endpoints.

const (
	EntryCommitSize = 1 +
		6 +
		32 +
		1 +
		32 +
		64 // sig
	ChainCommitSize = EntryCommitSize +
		32 +
		32 // commit weld
)
const (
	// RCDType01 is the magic number identifying the RCD type that requires
	// an ed25519 signature from the given public key.
	RCDType01 RCDType = 0x01
	// RCDType01Size is the total size of the RCD.
	RCDType01Size = 1 + ed25519.PublicKeySize
	// RCDType01SigSize is the size of the expected ed25519 signature.
	RCDType01SigSize = ed25519.SignatureSize
)
const (
	// TransactionVersion is the magic number Version byte in all
	// Transactions.
	TransactionVersion byte = 0x02

	// TransactionHeaderSize is the size of a Binary Transaction Header.
	TransactionHeaderSize = 1 +
		6 +
		1 +
		1 +
		1 // EC output count
	TransactionMinTotalSize = TransactionHeaderSize +
		32 + 1 +
		32 + 1 +
		33 + 32 // RCD01 and Signature
)
const DBlockEBlockSize = 32 +
	32 // KeyMR

DBlockEBlockSize is the exact length of an EBlock within a DBlock.

const DBlockHeaderSize = 1 +
	4 +
	32 +
	32 +
	32 +
	4 +
	4 +
	4 // EBlock Count

DBlockHeaderSize is the exact length of a DBlock header.

const DBlockMaxBodySize = math.MaxUint32 * DBlockEBlockSize

DBlockMaxBodySize is the maximum length of the body of a DBlock, which is determined by the largest EBlock count that can be stored in 4 bytes.

const DBlockMaxTotalSize = DBlockHeaderSize + DBlockMaxBodySize

DBlockMaxTotalSize is the maximum length of a DBlock.

const DBlockMinBodySize = DBlockEBlockSize +
	DBlockEBlockSize +
	DBlockEBlockSize // FCT Block

DBlockMinBodySize is the minimum length of the body of a DBlock, which must include at least an Admin Block, EC Block, and FCT Block.

const DBlockMinTotalSize = DBlockHeaderSize + DBlockMinBodySize

DBlockMinTotalSize is the minumum total length of a DBlock.

const EBlockHeaderSize = 32 +
	32 +
	32 +
	32 +
	4 +
	4 +
	4 // [Entry Count (uint32 BE)]

EBlockHeaderSize is the exact length of an EBlock header.

const EBlockMaxBodySize = math.MaxUint32 * EBlockObjectSize

EBlockMaxBodySize is the maximum length of the body of an EBlock, which is determined by the largest ObjectCount that can be stored in 4 bytes.

const EBlockMaxTotalSize = EBlockHeaderSize + EBlockMaxBodySize

EBlockMaxTotalSize is the maximum total length of an EBlock.

const EBlockMinBodySize = EBlockObjectSize * 2

EBlockMinBodySize is the minimum length of the body of an EBlock, which must include at least on Entry hash and one minute marker.

const EBlockMinTotalSize = EBlockHeaderSize + EBlockMinBodySize

EBlockMinTotalSize is the minimum total length of an EBlock.

const EBlockObjectSize = 32

EBlockObjectSize is the length of an EBlock body object, which may be an Entry hash or minute marker.

const EntryHeaderSize = 1 +
	32 +
	2 // total len

EntryHeaderSize is the exact length of an Entry header.

const EntryMaxDataSize = 10240

EntryMaxDataSize is the maximum data length of an Entry.

const EntryMaxTotalSize = EntryMaxDataSize + EntryHeaderSize

EntryMaxTotalSize is the maximum total encoded length of an Entry.

const (
	// FBlockHeaderMinSize is the minimum expected FBlock Header Size.
	FBlockHeaderMinSize = 32 +
		32 +
		32 +
		32 +
		8 +
		4 +
		1 +
		0 +
		4 +
		4 // Body Size
)
const (
	// FBlockMinuteMarker is the byte used to indicate the end of a minute
	// in the FBlock.
	FBlockMinuteMarker = 0x00
)
const NewChainCost = 10

NewChainCost is the fixed added cost of creating a new chain.

Variables

var (
	DBlockDuration = 10 * time.Minute
	MinuteDuration = DBlockDuration / 10
)

DBlockDuration is the duration of a complete DBlock. This affects the duration of a "Minute" and should be adjusted if this package is used against a Factom local network that uses a shorter block time.

This affects the parsing and assigning of Timestamps on Transactions in FBlocks and Entries in EBlocks.

func EntryCost

func EntryCost(size int, newChain bool) (uint8, error)

EntryCost returns the required Entry Credit cost for an entry with encoded length equal to size. An error is returned if size exceeds 10275.

Set newChain to true to add the NewChainCost.

func ValidIdentityChainID

func ValidIdentityChainID(chainID Bytes) bool

ValidIdentityChainID returns true if the chainID matches the pattern for an Identity Chain ID.

The Identity Chain specification can be found here: https://github.com/FactomProject/FactomDocs/blob/master/Identity.md#factom-identity-chain-creation

func ValidIdentityNameIDs

func ValidIdentityNameIDs(nameIDs []Bytes) bool

ValidIdentityNameIDs returns true if the nameIDs match the pattern for a valid Identity Chain. The nameIDs for a chain are the ExtIDs of the first entry in the chain.

The Identity Chain specification can be found here: https://github.com/FactomProject/FactomDocs/blob/master/Identity.md#factom-identity-chain-creation

type AddressAmount

type AddressAmount struct {
	Address Bytes
	Amount  uint64
}

AddressAmount relates a 32 byte Address payload and an Amount.

Bytes are used for the Address for improved unmarshaling efficiency of Transactions.

func (AddressAmount) AddressBytes32

func (adr AddressAmount) AddressBytes32() Bytes32

AddressBytes32 converts the Address to Bytes32.

func (AddressAmount) ECAddress

func (adr AddressAmount) ECAddress() ECAddress

ECAddress converts the Address to an ECAddress.

func (AddressAmount) FAAddress

func (adr AddressAmount) FAAddress() FAAddress

FAAddress converts the Address to an FAAddress.

type Bytes

type Bytes []byte

Bytes implements encoding.TextMarshaler and encoding.TextUnmarshaler to encode and decode hex strings, such as an Entry's ExtIDs or Content.

func NewBytes

func NewBytes(s string) Bytes

NewBytes returns a Bytes populated with the data from s, a hex encoded string.

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string. It never returns an error.

func (*Bytes) Set

func (b *Bytes) Set(hexStr string) error

Set decodes a hex string into b.

func (Bytes) String

func (b Bytes) String() string

String encodes b as a hex string.

func (Bytes) Type

func (b Bytes) Type() string

Type returns "Bytes". Satisfies pflag.Value interface.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(text []byte) error

UnmarshalText decodes a hex string into b.

type Bytes32

type Bytes32 [32]byte

Bytes32 implements encoding.TextMarshaler and encoding.TextUnmarshaler to encode and decode hex strings with exactly 32 bytes of data, such as ChainIDs and KeyMRs.

func ABlockChainID

func ABlockChainID() Bytes32

ABlockChainID returns the ChainID of the Admin Block Chain, 0x00..0a.

func ComputeChainID

func ComputeChainID(nameIDs []Bytes) Bytes32

ComputeChainID returns the chain ID for a set of NameIDs.

func ComputeDBlockBodyMR

func ComputeDBlockBodyMR(elements [][]byte) (Bytes32, error)

ComputeDBlockBodyMR returns the merkle root of the tree created with elements as leaves, where the leaves are hashed.

func ComputeDBlockHeaderHash

func ComputeDBlockHeaderHash(data []byte) Bytes32

ComputeDBlockHeaderHash returns sha256(data[:DBlockHeaderSize]).

func ComputeEBlockBodyMR

func ComputeEBlockBodyMR(elements [][]byte) (Bytes32, error)

ComputeEBlockBodyMR returns the merkle root of the tree created with elements as leaves, where the leaves are not hashed.

func ComputeEBlockHeaderHash

func ComputeEBlockHeaderHash(data []byte) Bytes32

ComputeEBlockHeaderHash returns sha256(data[:EBlockHeaderSize]).

func ComputeEntryHash

func ComputeEntryHash(data []byte) Bytes32

ComputeEntryHash returns the Entry hash of data. Entry's are hashed via: sha256(sha512(data) + data).

func ComputeFBlockBodyMR

func ComputeFBlockBodyMR(elements [][]byte) (Bytes32, error)

ComputeFBlockBodyMR returns the merkle root of the tree created with elements as leaves, where the leaves are hashed.

func ComputeFBlockKeyMR

func ComputeFBlockKeyMR(elements [][]byte) (Bytes32, error)

ComputeFBlockKeyMR returns the Key Merkle root of the FBlock.

func ComputeFullHash

func ComputeFullHash(data []byte) Bytes32

ComputeFullHash returns sha256(data).

func ComputeKeyMR

func ComputeKeyMR(headerHash, bodyMR *Bytes32) Bytes32

ComputeKeyMR returns sha256(headerHash|bodyMR).

func ECBlockChainID

func ECBlockChainID() Bytes32

ECBlockChainID returns the ChainID of the Entry Credit Block Chain, 0x00..0c.

func FBlockChainID

func FBlockChainID() Bytes32

FBlockChainID returns the ChainID of the Factoid Block Chain, 0x00..0f.

func GenerateCommit

func GenerateCommit(es EsAddress, entrydata []byte, hash *Bytes32,
	newChain bool) ([]byte, Bytes32)

GenerateCommit generates a commit message signed by es for the given entrydata and hash.

The entrydata must be the valid raw data encoding of an Entry, which can be obtained using Entry.MarshalBinary.

The hash must be the valid Entry Hash, which is anything that Entry.UnmarshalBinary can parse without error and can be obtained using ComputeEntryHash.

If newChain is true, then the commit will be a new Chain commit. The ChainID will be pulled from the entrydata.

If successful, the commit and Entry Transaction ID will be returned.

txID == sha256(commit[:len(commit)-96])

If either entrydata or hash is not valid, the return values will be invalid and panics may occur. It is up to the caller to ensure that the entrydata and hash are valid.

This allows the caller to manage the memory associated with the entrydata and hash, rather than having to regenerate it repeatedly using Entry.MarshalBinary. For a higher level API see the functions Entry.Compose, Entry.ComposeCreate, and Entry.Create.

The commit message data format is as follows:

     [Version (0x00)] +
	[Timestamp in ms (6 bytes BE)] +
     (if newChain)
	        [ChainID Hash, sha256d(ChainID) (Bytes32)] +
	        [Commit Weld, sha256d(hash|chainID) (Bytes32)] +
	[Entry Hash (Bytes32)] +
	[EC Cost (1 byte)] +
	[EC Public Key (32 Bytes)] +
	[Signature of data up to and including EC Cost (64 Bytes)]

func NewBytes32

func NewBytes32(s32 string) Bytes32

NewBytes32 returns a Bytes32 populated with the data from s32, a hex encoded string.

func (Bytes32) IsZero

func (b Bytes32) IsZero() bool

IsZero returns true if b is equal to its zero value.

func (Bytes32) MarshalText

func (b Bytes32) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string. It never returns an error.

func (*Bytes32) Set

func (b *Bytes32) Set(hexStr string) error

Set decodes a hex string with exactly 32 bytes of data into b.

func (Bytes32) String

func (b Bytes32) String() string

String encodes b as a hex string.

func (Bytes32) Type

func (b Bytes32) Type() string

Type returns "Bytes32". Satisfies pflag.Value interface.

func (*Bytes32) UnmarshalText

func (b *Bytes32) UnmarshalText(text []byte) error

UnmarshalText decodes a hex string with exactly 32 bytes of data into b.

type Client

type Client struct {
	Factomd       jsonrpc2.Client
	FactomdServer string
	Walletd       jsonrpc2.Client
	WalletdServer string
}

Client makes RPC requests to factomd's and factom-walletd's APIs. Client embeds two jsonrpc2.Clients, and thus also two http.Client, one for requests to factomd and one for requests to facgo butom-walletd. Use jsonrpc2.Client's BasicAuth settings to set up BasicAuth and http.Client's transport settings to configure TLS.

func NewClient

func NewClient() *Client

NewClient returns a pointer to a new Client initialized with the default localhost endpoints for factomd and factom-walletd. If factomdDoer or walletdDoer is nil, the default http.Client is used. See jsonrpc2.NewClient for more details.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, commit []byte) error

Commit sends an entry or new chain commit to factomd.

func (*Client) FactomdRequest

func (c *Client) FactomdRequest(
	ctx context.Context, method string, params, result interface{}) error

FactomdRequest makes a request to factomd's v2 API.

func (*Client) GetPrivateAddresses

func (c *Client) GetPrivateAddresses(ctx context.Context) ([]FsAddress, []EsAddress,
	error)

GetPrivateAddresses queries factom-walletd for all private addresses.

func (*Client) Reveal

func (c *Client) Reveal(ctx context.Context, reveal []byte) error

Reveal reveals an entry or new chain entry to factomd.

func (*Client) SavePrivateAddresses

func (c *Client) SavePrivateAddresses(ctx context.Context, adrs ...string) error

SavePrivateAddresses saves many adrs with factom-walletd.

func (*Client) WalletdRequest

func (c *Client) WalletdRequest(
	ctx context.Context, method string, params, result interface{}) error

WalletdRequest makes a request to factom-walletd's v2 API.

type DBlock

type DBlock struct {
	// Computed
	KeyMR    *Bytes32
	FullHash *Bytes32

	// Unmarshaled
	NetworkID    NetworkID
	BodyMR       *Bytes32
	PrevKeyMR    *Bytes32
	PrevFullHash *Bytes32
	Height       uint32
	Timestamp    time.Time

	FBlock FBlock

	// DBlock.Get populates EBlocks with their ChainID, KeyMR, Timestamp,
	// and Height.
	EBlocks []EBlock
	// contains filtered or unexported fields
}

DBlock represents a Factom Directory Block.

func (*DBlock) ClearMarshalBinaryCache

func (db *DBlock) ClearMarshalBinaryCache()

ClearMarshalBinaryCache discards the cached MarshalBinary data.

Subsequent calls to MarshalBinary will re-construct the data from the fields of the DBlock.

func (DBlock) EBlock

func (db DBlock) EBlock(chainID Bytes32) *EBlock

EBlock efficiently finds and returns the *EBlock in db.EBlocks for the given chainID, if it exists. Otherwise, EBlock returns nil.

This assumes that db.EBlocks ordered by ascending ChainID.

func (*DBlock) Get

func (db *DBlock) Get(ctx context.Context, c *Client) (err error)

Get queries factomd for the Directory Block at db.Height. After a successful call, the EBlocks will all have their ChainID and KeyMR, but not their Entries. Call Get on the EBlocks individually to populate their Entries.

func (DBlock) IsPopulated

func (db DBlock) IsPopulated() bool

IsPopulated returns true if db has already been populated by a successful call to Get.

func (DBlock) MarshalBinary

func (db DBlock) MarshalBinary() ([]byte, error)

MarshalBinary returns the raw DBlock data for db. This will return an error if !db.IsPopulated() or if there are more than math.MaxUint32 EBlocks. The data format is as follows.

Header

[Version byte (0x00)] +
[NetworkID (4 bytes)] +
[BodyMR (Bytes32)] +
[PrevKeyMR (Bytes32)] +
[PrevFullHash (Bytes32)] +
[Timestamp (4 bytes)] +
[DB Height (4 bytes)] +
[EBlock Count (4 bytes)]

Body

[Admin Block ChainID (Bytes32{31:0x0a})] +
[Admin Block LookupHash (Bytes32)] +
[EC Block ChainID (Bytes32{31:0x0c})] +
[EC Block HeaderHash (Bytes32)] +
[FCT Block ChainID (Bytes32{31:0x0f})] +
[FCT Block KeyMR (Bytes32)] +
[ChainID 0 (Bytes32)] +
[KeyMR 0 (Bytes32)] +
... +
[ChainID N (Bytes32)] +
[KeyMR N (Bytes32)] +

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#directory-block

func (DBlock) MarshalBinaryLen

func (db DBlock) MarshalBinaryLen() int

MarshalBinaryLen returns the length of the binary encoding of db,

DBlockHeaderSize + (len(db.EBlocks)+1)*DBlockEBlockSize

func (*DBlock) UnmarshalBinary

func (db *DBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals raw DBlock data, verifies the BodyMR, and populates db.FullHash and db.KeyMR, if nil. If db.KeyMR is populated, it is verified. The following format is expected for data.

Header

[Version byte (0x00)] +
[NetworkID (4 bytes)] +
[BodyMR (Bytes32)] +
[PrevKeyMR (Bytes32)] +
[PrevFullHash (Bytes32)] +
[Timestamp (4 bytes)] +
[DB Height (4 bytes)] +
[EBlock Count (4 bytes)]

Body

[Admin Block ChainID (Bytes32{31:0x0a})] +
[Admin Block LookupHash (Bytes32)] +
[EC Block ChainID (Bytes32{31:0x0c})] +
[EC Block HeaderHash (Bytes32)] +
[FCT Block ChainID (Bytes32{31:0x0f})] +
[FCT Block KeyMR (Bytes32)] +
[ChainID 0 (Bytes32)] +
[KeyMR 0 (Bytes32)] +
... +
[ChainID N (Bytes32)] +
[KeyMR N (Bytes32)] +

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#directory-block

type EBlock

type EBlock struct {
	// DBlock.Get populates the ChainID, KeyMR, Height and Timestamp.
	ChainID   *Bytes32
	KeyMR     *Bytes32  // Computed
	Timestamp time.Time // Established by DBlock
	Height    uint32

	FullHash *Bytes32 // Computed

	// Unmarshaled
	PrevKeyMR    *Bytes32
	PrevFullHash *Bytes32
	BodyMR       *Bytes32
	Sequence     uint32
	ObjectCount  uint32

	// EBlock.Get populates the Entries with their Hash and Timestamp.
	Entries []Entry
	// contains filtered or unexported fields
}

EBlock represents a Factom Entry Block.

func (*EBlock) ClearMarshalBinaryCache

func (eb *EBlock) ClearMarshalBinaryCache()

ClearMarshalBinaryCache discards the cached MarshalBinary data.

Subsequent calls to MarshalBinary will re-construct the data from the fields of the EBlock.

func (*EBlock) Get

func (eb *EBlock) Get(ctx context.Context, c *Client) error

Get populates eb with the Entry Block corresponding to eb.KeyMR, if not nil, and otherwise the chain head for eb.ChainID.

If both eb.KeyMR and eb.ChainID are nil, an error will be returned.

After a successful call, all of eb's data will be populated, except the eb.Timestamp, which is established by the DBlock with the same Height. All eb.Entries will be populated with their Hash, ChainID, Timestamp, and Height.

func (*EBlock) GetChainHead

func (eb *EBlock) GetChainHead(ctx context.Context, c *Client) (bool, error)

GetChainHead populates eb.KeyMR with the chain head for eb.ChainID, the latest EBlock KeyMR, if it exists.

The returned boolean indicates whether the chain is in the process list.

If the Chain does not exist, a jsonrpc2/v14.Error will be returned indicating a Missing Chain Head.

If the Chain creation is pending, true will be returned, but the eb.KeyMR will not be populated.

func (*EBlock) GetEntries

func (eb *EBlock) GetEntries(ctx context.Context, c *Client) error

GetEntries calls eb.Get and then calls Get on each Entry in eb.Entries.

Entries are downloaded concurrently.

func (*EBlock) GetFirst

func (eb *EBlock) GetFirst(ctx context.Context, c *Client) error

GetFirst finds the first Entry Block in eb's chain, and populates eb as such.

GetFirst avoids allocating any new EBlocks by reusing eb to traverse up to the first entry block.

func (EBlock) GetPrevAll

func (eb EBlock) GetPrevAll(ctx context.Context, c *Client) ([]EBlock, error)

GetPrevAll returns a slice of all preceding EBlocks, in order from eb to the first EBlock in the chain. So the 0th element of the returned slice is always equal to eb. If eb is the first EBlock in the chain, then it is the only element in the slice. Like Get, if eb does not have a KeyMR, the chain head KeyMR is queried first.

If you are only interested in obtaining the first entry block in eb's chain, and not all of the intermediary ones, then use GetFirst.

func (EBlock) GetPrevBackTo

func (eb EBlock) GetPrevBackTo(
	ctx context.Context, c *Client, keyMR *Bytes32) ([]EBlock, error)

GetPrevBackTo returns a slice of all preceding EBlocks, in order from eb back to, but not including, keyMR. So the 0th element of the returned slice is always equal to eb.

Get is first called on eb. So if eb does not have a KeyMR, the chain head KeyMR is queried first.

If *eb.KeyMR == *keyMR then ([]EBlock{}, nil) is returned.

If *eb.PrevKeyMR == *keyMR, then it is the only element in the slice.

If the beginning of the chain is reached without finding keyMR, then fmt.Errorf("end of chain") is returned.

func (EBlock) GetPrevN

func (eb EBlock) GetPrevN(ctx context.Context, c *Client,
	n uint32) ([]EBlock, error)

GetPrevN returns a slice of n prev EBlocks, in reverse order, including eb. So the 0th element of the returned slice is always equal to eb.

Get is first called on eb. So if eb does not have a KeyMR, the chain head KeyMR is queried first.

If n == 0, then ([]EBlock{}, nil) is returned.

If n == 1, then it is the only element in the slice.

If the beginning of the chain is reached before n EBlocks then fmt.Errorf("end of chain") is returned.

func (EBlock) IsFirst

func (eb EBlock) IsFirst() bool

IsFirst returns true if this is the first EBlock in its chain, indicated by eb.PrevKeyMR.IsZero().

If eb is not populated, eb.IsFirst will always return false.

func (EBlock) IsPopulated

func (eb EBlock) IsPopulated() bool

IsPopulated returns true if eb has already been populated by a successful call to Get.

func (EBlock) MarshalBinary

func (eb EBlock) MarshalBinary() ([]byte, error)

MarshalBinary returns the raw EBlock data for eb. This will return an error if !eb.IsPopulated(). The data format is as follows.

Header

[ChainID (Bytes32)] +
[BodyMR (Bytes32)] +
[PrevKeyMR (Bytes32)] +
[PrevFullHash (Bytes32)] +
[EB Sequence (uint32 BE)] +
[DB Height (uint32 BE)] +
[Object Count (uint32 BE)]

Body

[Object 0 (Bytes32)] // entry hash or minute marker +
... +
[Object N (Bytes32)]

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry-block

If EBlock was populated by a call to MarshalBinary, and ClearMar

func (EBlock) MarshalBinaryLen

func (eb EBlock) MarshalBinaryLen() int

MarshalBinaryLen returns the length of the binary encoding of eb,

EBlockHeaderSize + len(eb.ObjectCount)*len(Bytes32{})

func (EBlock) Prev

func (eb EBlock) Prev() EBlock

Prev returns the EBlock preceding eb, an EBlock with its KeyMR initialized to eb.PrevKeyMR and ChainID initialized to eb.ChainID.

If eb is the first Entry Block in the chain, then eb is returned. If eb is not populated, the returned EBlock will be its zero value.

func (*EBlock) SetTimestamp

func (eb *EBlock) SetTimestamp(ts time.Time)

SetTimestamp sets the EBlock timestamp and updates all Entry Timestamps relative to this new eb.Timestamp so that the Minute Markers will still be valid during BinaryMarshaling.

func (*EBlock) UnmarshalBinary

func (eb *EBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals raw EBlock data, verifies the BodyMR, and populates eb.FullHash and eb.KeyMR, if nil. If eb.KeyMR is populated, it is verified. The following format is expected for data.

Header

[ChainID (Bytes32)] +
[BodyMR (Bytes32)] +
[PrevKeyMR (Bytes32)] +
[PrevFullHash (Bytes32)] +
[EB Sequence (uint32 BE)] +
[DB Height (uint32 BE)] +
[Object Count (uint32 BE)]

Body

[Object 0 (Bytes32)] // entry hash or minute marker +
... +
[Object N (Bytes32)]

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry-block

type ECAddress

type ECAddress [sha256.Size]byte

ECAddress is a Public Entry Credit Address.

func NewECAddress

func NewECAddress(adrStr string) (adr ECAddress, err error)

NewECAddress attempts to parse adrStr into a new ECAddress.

func (ECAddress) GetBalance

func (adr ECAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)

GetBalance queries factomd for the Entry Credit Balance for adr.

func (ECAddress) GetEsAddress

func (adr ECAddress) GetEsAddress(ctx context.Context, c *Client) (EsAddress, error)

GetEsAddress queries factom-walletd for the EsAddress corresponding to adr.

func (ECAddress) MarshalText

func (adr ECAddress) MarshalText() ([]byte, error)

MarshalText encodes adr as a string using adr.String().

func (ECAddress) PrefixBytes

func (ECAddress) PrefixBytes() Bytes

PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x59, 0x2a}.

func (ECAddress) PrefixString

func (ECAddress) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "EC".

func (ECAddress) PublicKey

func (adr ECAddress) PublicKey() ed25519.PublicKey

PublicKey returns the ed25519.PublicKey for adr.

func (ECAddress) Remove

func (adr ECAddress) Remove(ctx context.Context, c *Client) error

Remove adr from factom-walletd. WARNING: THIS IS DESTRUCTIVE.

func (*ECAddress) Set

func (adr *ECAddress) Set(adrStr string) error

Set attempts to parse adrStr into adr.

func (ECAddress) String

func (adr ECAddress) String() string

String encodes adr into its human readable form: base58check with adr.PrefixBytes().

func (*ECAddress) UnmarshalText

func (adr *ECAddress) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable public Entry Credit address into adr.

type Entry

type Entry struct {
	// An Entry in EBlock.Entries after a successful call to EBlock.Get has
	// its ChainID, Hash, and Timestamp.
	ChainID *Bytes32 `json:"chainid,omitempty"`
	Hash    *Bytes32 `json:"entryhash,omitempty"`

	// Established by EBlock
	Timestamp time.Time `json:"-"`
	Height    uint32    `json:"-"`

	// Entry.Get populates the Content and ExtIDs.
	ExtIDs  []Bytes `json:"extids"`
	Content Bytes   `json:"content"`
	// contains filtered or unexported fields
}

Entry represents a Factom Entry.

Entry can be used to Get data when the Hash is known, or submit a new Entry to a given ChainID.

func (*Entry) ClearMarshalBinaryCache

func (e *Entry) ClearMarshalBinaryCache()

ClearMarshalBinaryCache discards the cached MarshalBinary data.

Subsequent calls to MarshalBinary will re-construct the data from the fields of the Entry.

func (*Entry) Compose

func (e *Entry) Compose(es EsAddress) (
	commit []byte, reveal []byte, txID Bytes32, err error)

Compose generates the commit and reveal data required to submit an Entry to factomd with Client.Commit and Client.Reveal. The Transaction ID is also returned.

The e.Hash will be populated if not nil.

If e.ChainID == nil, a new chain will be created, and e.ChainID will be populated.

If the reveal is already available to the caller, use GenerateCommit to create the commit without recreating the reveal, which is simply the raw data of an Entry.

func (*Entry) ComposeCreate

func (e *Entry) ComposeCreate(
	ctx context.Context, c *Client, es EsAddress) (Bytes32, error)

ComposeCreate composes and submits an entry to factomd by calling e.Compose and then c.Commit and c.Reveal.

This does not make any calls to factom-walletd.

The e.Hash will be populated if not nil.

If e.ChainID == nil, a new chain will be created, and e.ChainID will be populated.

If successful, the Transaction ID is returned.

func (Entry) Cost

func (e Entry) Cost() (uint8, error)

Cost returns the EntryCost of e, using e.MarshalBinaryLen().

If e.ChainID == nil, the NewChainCost is added.

func (*Entry) Create

func (e *Entry) Create(ctx context.Context, c *Client, ec ECAddress) (Bytes32, error)

Create queries factom-walletd to compose e as a new Entry, and then queries factomd to commit and reveal the new Entry or new Chain, if e.ChainID == nil.

The given ec must exist in factom-walletd's keystore.

If successful, the commit transaction ID is returned and e.Hash and e.ChainID will be populated.

func (*Entry) Get

func (e *Entry) Get(ctx context.Context, c *Client) error

Get populates e with the Entry data for its e.Hash.

If e.Hash is nil, an error will be returned.

After a successful call e.Content, e.ExtIDs, and e.ChainID will be populated.

func (Entry) IsPopulated

func (e Entry) IsPopulated() bool

IsPopulated returns true if e has already been successfully populated by a call to Get.

func (Entry) MarshalBinary

func (e Entry) MarshalBinary() ([]byte, error)

MarshalBinary returns the raw Entry data for e. This will return an error if !e.IsPopulated(). The data format is as follows.

[Version byte (0x00)] +
[ChainID (Bytes32)] +
[Total ExtID encoded length (uint16 BE)] +
[ExtID 0 length (uint16)] + [ExtID 0 (Bytes)] +
... +
[ExtID X length (uint16)] + [ExtID X (Bytes)] +
[Content (Bytes)]

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry

func (Entry) MarshalBinaryLen

func (e Entry) MarshalBinaryLen() int

MarshalBinaryLen returns the total encoded length of e.

func (*Entry) UnmarshalBinary

func (e *Entry) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals raw entry data into e.

If e.ChainID is not nil, it must equal the ChainID described in the data.

If e.Hash is not nil, it must equal ComputeEntryHash(data).

Like json.Unmarshal, if e.ExtIDs or e.Content are preallocated, they are reset to length zero and then appended to.

The data must encode a valid Entry. Entries are encoded as follows:

[Version byte (0x00)] +
[ChainID (Bytes32)] +
[Total ExtID encoded length (uint16 BE)] +
[ExtID 0 length (uint16)] + [ExtID 0 (Bytes)] +
... +
[ExtID X length (uint16)] + [ExtID X (Bytes)] +
[Content (Bytes)]

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry

type EsAddress

type EsAddress [sha256.Size]byte

EsAddress is the secret key to a ECAddress.

func GenerateEsAddress

func GenerateEsAddress() (EsAddress, error)

GenerateEsAddress generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.

func NewEsAddress

func NewEsAddress(adrStr string) (adr EsAddress, err error)

NewEsAddress attempts to parse adrStr into a new EsAddress.

func (EsAddress) ECAddress

func (adr EsAddress) ECAddress() (ec ECAddress)

ECAddress returns the ECAddress corresponding to adr.

func (EsAddress) GetBalance

func (adr EsAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)

GetBalance queries factomd for the Entry Credit Balance for adr.

func (EsAddress) MarshalText

func (adr EsAddress) MarshalText() ([]byte, error)

MarshalText encodes adr as a string using adr.String().

func (EsAddress) PrefixBytes

func (EsAddress) PrefixBytes() Bytes

PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x5d, 0xb6}.

func (EsAddress) PrefixString

func (EsAddress) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "Es".

func (EsAddress) PrivateKey

func (adr EsAddress) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for adr.

func (EsAddress) PublicKey

func (adr EsAddress) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for adr.

func (EsAddress) Remove

func (adr EsAddress) Remove(ctx context.Context, c *Client) error

Remove adr from factom-walletd. WARNING: THIS IS DESTRUCTIVE.

func (EsAddress) Save

func (adr EsAddress) Save(ctx context.Context, c *Client) error

Save adr with factom-walletd.

func (*EsAddress) Set

func (adr *EsAddress) Set(adrStr string) error

Set attempts to parse adrStr into adr.

func (EsAddress) String

func (adr EsAddress) String() string

String encodes adr into its human readable form: base58check with adr.PrefixBytes().

func (*EsAddress) UnmarshalText

func (adr *EsAddress) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable secret Entry Credit address into adr.

type FAAddress

type FAAddress [sha256.Size]byte

FAAddress is a Public Factoid Address.

func NewFAAddress

func NewFAAddress(adrStr string) (adr FAAddress, err error)

NewFAAddress attempts to parse adrStr into a new FAAddress.

func (FAAddress) GetBalance

func (adr FAAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)

GetBalance queries factomd for the Factoid Balance for adr.

func (FAAddress) GetFsAddress

func (adr FAAddress) GetFsAddress(ctx context.Context, c *Client) (FsAddress, error)

GetFsAddress queries factom-walletd for the FsAddress corresponding to adr.

func (FAAddress) MarshalText

func (adr FAAddress) MarshalText() ([]byte, error)

MarshalText encodes adr as a string using adr.String().

func (FAAddress) PrefixBytes

func (FAAddress) PrefixBytes() Bytes

PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x5f, 0xb1}.

func (FAAddress) PrefixString

func (FAAddress) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "FA".

func (FAAddress) Remove

func (adr FAAddress) Remove(ctx context.Context, c *Client) error

Remove adr from factom-walletd. WARNING: THIS IS DESTRUCTIVE.

func (*FAAddress) Set

func (adr *FAAddress) Set(adrStr string) error

Set attempts to parse adrStr into adr.

func (FAAddress) String

func (adr FAAddress) String() string

String encodes adr into its human readable form: base58check with adr.PrefixBytes().

func (*FAAddress) UnmarshalText

func (adr *FAAddress) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable public Factoid address into adr.

type FBlock

type FBlock struct {
	// Computed Fields
	KeyMR       *Bytes32
	LedgerKeyMR *Bytes32

	// Header Fields
	BodyMR          *Bytes32
	PrevKeyMR       *Bytes32
	PrevLedgerKeyMR *Bytes32

	ECExchangeRate uint64
	Height         uint32

	// Expansion is the expansion space in the FBlock. If we do not parse
	// the expansion, we just store the raw bytes.
	Expansion Bytes

	// Body Fields
	Transactions []Transaction

	// Timestamp is established by the DBlock. It is only populated if the
	// FBlock was unmarshaled from within a DBlock.
	Timestamp time.Time
	// contains filtered or unexported fields
}

FBlock represents a Factoid Block.

func (*FBlock) ClearMarshalBinaryCache

func (fb *FBlock) ClearMarshalBinaryCache()

ClearMarshalBinaryCache discards the cached MarshalBinary data.

Subsequent calls to MarshalBinary will re-construct the data from the fields of the FBlock.

func (FBlock) ComputeFullHash

func (fb FBlock) ComputeFullHash() (Bytes32, error)

ComputeFullHash computes the full hash of the FBlock.

func (*FBlock) Get

func (fb *FBlock) Get(ctx context.Context, c *Client) (err error)

Get queries factomd for the Factoid Block at fb.Header.Height or fb.KeyMR. After a successful call, the Transactions will all be populated.

func (FBlock) IsPopulated

func (fb FBlock) IsPopulated() bool

IsPopulated returns true if fb has already been successfully populated by a call to Get. IsPopulated returns false if fb.Transactions is nil.

func (*FBlock) MarshalBinary

func (fb *FBlock) MarshalBinary() ([]byte, error)

MarshalBinary marshals the FBlock into its binary form. If the FBlock was orignally Unmarshaled, then the cached data is re-used, so this is efficient. See ClearMarshalBinaryCache.

func (*FBlock) UnmarshalBinary

func (fb *FBlock) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals raw directory block data.

Header

[Factoid Block ChainID (Bytes32{31:0x0f})] +
[BodyMR (Bytes32)] +
[PrevKeyMR (Bytes32)] +
[PrevLedgerKeyMR (Bytes32)] +
[Exchange Rate (8 bytes)] +
[DB Height (4 bytes)] +
[Header Expansion size (Bytes)] +
[Header Expansion Area (Bytes)] +
[Transaction Count (4 bytes)] +
[Body Size (4 bytes)] +

Body

[Tx 0 (Bytes)] +
... +
[Tx N (Bytes)] +

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#factoid-block

type FsAddress

type FsAddress [sha256.Size]byte

FsAddress is the secret key to a FAAddress.

func GenerateFsAddress

func GenerateFsAddress() (FsAddress, error)

GenerateFsAddress generates a secure random private Factoid address using crypto/rand.Random as the source of randomness.

func NewFsAddress

func NewFsAddress(adrStr string) (adr FsAddress, err error)

NewFsAddress attempts to parse adrStr into a new FsAddress.

func (FsAddress) FAAddress

func (adr FsAddress) FAAddress() FAAddress

FAAddress returns the FAAddress corresponding to adr.

func (FsAddress) GetBalance

func (adr FsAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)

GetBalance queries factomd for the Factoid Balance for adr.

func (FsAddress) MarshalText

func (adr FsAddress) MarshalText() ([]byte, error)

MarshalText encodes adr as a string using adr.String().

func (FsAddress) PrefixBytes

func (FsAddress) PrefixBytes() Bytes

PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x64, 0x78}.

func (FsAddress) PrefixString

func (FsAddress) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "Fs".

func (FsAddress) PrivateKey

func (adr FsAddress) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for adr.

func (FsAddress) PublicKey

func (adr FsAddress) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for adr.

func (FsAddress) RCD

func (adr FsAddress) RCD() RCD

RCD computes the RCD for adr.

func (FsAddress) Remove

func (adr FsAddress) Remove(ctx context.Context, c *Client) error

Remove adr from factom-walletd. WARNING: THIS IS DESTRUCTIVE.

func (FsAddress) Save

func (adr FsAddress) Save(ctx context.Context, c *Client) error

Save adr with factom-walletd.

func (*FsAddress) Set

func (adr *FsAddress) Set(adrStr string) error

Set attempts to parse adrStr into adr.

func (FsAddress) Sign

func (adr FsAddress) Sign(msg []byte) []byte

Sign the msg.

func (FsAddress) String

func (adr FsAddress) String() string

String encodes adr into its human readable form: base58check with adr.PrefixBytes().

func (*FsAddress) UnmarshalText

func (adr *FsAddress) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable secret Factoid address into adr.

type Heights

type Heights struct {
	// The current directory block height of the local factomd node.
	DirectoryBlock uint32 `json:"directoryblockheight"`

	// The current block being worked on by the leaders in the network.
	// This block is not yet complete, but all transactions submitted will
	// go into this block (depending on network conditions, the transaction
	// may be delayed into the next block)
	Leader uint32 `json:"leaderheight"`

	// The height at which the factomd node has all the entry blocks.
	// Directory blocks are obtained first, entry blocks could be lagging
	// behind the directory block when syncing.
	EntryBlock uint32 `json:"entryblockheight"`

	// The height at which the local factomd node has all the entries. If
	// you added entries at a block height above this, they will not be
	// able to be retrieved by the local factomd until it syncs further.
	Entry uint32 `json:"entryheight"`
}

Heights contains all of the distinct heights for a factomd node and the Factom network.

func (*Heights) Get

func (h *Heights) Get(ctx context.Context, c *Client) error

Get uses c to call the "heights" RPC method and populates h with the result.

type ID1Key

type ID1Key [sha256.Size]byte

ID1Key is the id1 public key for an identity.

func NewID1Key

func NewID1Key(keyStr string) (key ID1Key, err error)

NewID1Key attempts to parse keyStr into a new ID1Key.

func (ID1Key) MarshalText

func (key ID1Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (ID1Key) Payload

func (key ID1Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (ID1Key) PrefixBytes

func (ID1Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbe, 0xba}.

func (ID1Key) PrefixString

func (ID1Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id1".

func (*ID1Key) Set

func (key *ID1Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (ID1Key) String

func (key ID1Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (ID1Key) Type

func (ID1Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*ID1Key) UnmarshalText

func (key *ID1Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable id1 key into key.

type ID2Key

type ID2Key [sha256.Size]byte

ID2Key is the id2 public key for an identity.

func NewID2Key

func NewID2Key(keyStr string) (key ID2Key, err error)

NewID2Key attempts to parse keyStr into a new ID2Key.

func (ID2Key) MarshalText

func (key ID2Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (ID2Key) Payload

func (key ID2Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (ID2Key) PrefixBytes

func (ID2Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbe, 0xd8}.

func (ID2Key) PrefixString

func (ID2Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id2".

func (*ID2Key) Set

func (key *ID2Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (ID2Key) String

func (key ID2Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (ID2Key) Type

func (ID2Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*ID2Key) UnmarshalText

func (key *ID2Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable id2 key into key.

type ID3Key

type ID3Key [sha256.Size]byte

ID3Key is the id3 public key for an identity.

func NewID3Key

func NewID3Key(keyStr string) (key ID3Key, err error)

NewID3Key attempts to parse keyStr into a new ID3Key.

func (ID3Key) MarshalText

func (key ID3Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (ID3Key) Payload

func (key ID3Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (ID3Key) PrefixBytes

func (ID3Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbe, 0xf6}.

func (ID3Key) PrefixString

func (ID3Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id3".

func (*ID3Key) Set

func (key *ID3Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (ID3Key) String

func (key ID3Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (ID3Key) Type

func (ID3Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*ID3Key) UnmarshalText

func (key *ID3Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable id3 key into key.

type ID4Key

type ID4Key [sha256.Size]byte

ID4Key is the id4 public key for an identity.

func NewID4Key

func NewID4Key(keyStr string) (key ID4Key, err error)

NewID4Key attempts to parse keyStr into a new ID4Key.

func (ID4Key) MarshalText

func (key ID4Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (ID4Key) Payload

func (key ID4Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (ID4Key) PrefixBytes

func (ID4Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbf, 0x14}.

func (ID4Key) PrefixString

func (ID4Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id4".

func (*ID4Key) Set

func (key *ID4Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (ID4Key) String

func (key ID4Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (ID4Key) Type

func (ID4Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*ID4Key) UnmarshalText

func (key *ID4Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable id4 key into key.

type Identity

type Identity struct {
	ID1Key *ID1Key
	Height uint32
	Entry
}

Identity represents the Token Issuer's Identity Chain and the public ID1Key.

func (*Identity) Get

func (i *Identity) Get(ctx context.Context, c *Client) error

Get validates i.ChainID as an Identity Chain and parses out the ID1Key.

func (Identity) IsPopulated

func (i Identity) IsPopulated() bool

IsPopulated returns true if the Identity has been populated with an ID1Key.

func (*Identity) UnmarshalBinary

func (i *Identity) UnmarshalBinary(data []byte) error

UnmarshalBinary calls i.Entry.UnmarshalBinary and then performs additional validation checks on the ChainID and NameID formats.

type NetworkID

type NetworkID [4]byte

NetworkID represents the 4 byte magic number that helps identify distinct Factom networks.

NetworkID conforms to the flag.Value interface.

func LocalnetID

func LocalnetID() NetworkID

LocalnetID returns the Localnet NetworkID, 0xFA92E5A4.

func MainnetID

func MainnetID() NetworkID

MainnetID returns the Mainnet NetworkID, 0xFA92E5A2.

func TestnetID

func TestnetID() NetworkID

TestnetID returns the Testnet NetworkID, 0x883e093b.

func (NetworkID) IsCustom

func (n NetworkID) IsCustom() bool

IsCustom returns true if n is not the Mainnet, Testnet, or Localnet NetworkID.

func (NetworkID) IsLocalnet

func (n NetworkID) IsLocalnet() bool

IsLocalnet returns true if n is the Localnet NetworkID.

func (NetworkID) IsMainnet

func (n NetworkID) IsMainnet() bool

IsMainnet returns true if n is the Mainnet NetworkID.

func (NetworkID) IsTestnet

func (n NetworkID) IsTestnet() bool

IsTestnet returns true if n is the Testnet NetworkID.

func (*NetworkID) Set

func (n *NetworkID) Set(netIDStr string) error

Set sets n to the NetworkID corresponding to netIDStr, which can be "main", "mainnet", "test", "testnet", "local", "localnet" or a 4 byte hex encoded string for a custom NetworkID.

func (NetworkID) String

func (n NetworkID) String() string

String returns "mainnet", "testnet", "localnet", or "custom: 0x...".

type PendingEntries

type PendingEntries []Entry

PendingEntries is a list of pending entries which may or may not be revealed. If the entry's ChainID is not nil, then its data has been revealed and can be queried from factomd.

func (PendingEntries) Entries

func (pe PendingEntries) Entries(chainID *Bytes32) []Entry

Entries efficiently finds and returns all entries in pe for the given chainID, if any exist. Otherwise, Entries returns nil.

func (*PendingEntries) Get

func (pe *PendingEntries) Get(ctx context.Context, c *Client) error

Get returns all pending entries sorted by descending ChainID, and then order they were originally returned. Pending Entries that are committed but not revealed have a nil ChainID and are at the end of the pe slice.

type RCD

type RCD []byte

RCD is a Redeem Condition Datastructure. It is just a byte slice with special meaning.

func (RCD) FAAddress

func (rcd RCD) FAAddress() FAAddress

FAAddress returns the sha256d(rcd) which is used as the Factoid Address.

func (RCD) Hash

func (rcd RCD) Hash() Bytes32

Hash returns the sha256d(rcd) which is used as the Factoid Address.

func (RCD) SignatureBlockSize

func (rcd RCD) SignatureBlockSize() int

SignatureBlockSize returns the expected size of the signature block this RCD requires.

func (RCD) String

func (rcd RCD) String() string

String returns a hex encoded string of the RCD.

func (RCD) Type

func (rcd RCD) Type() RCDType

Type returns the first byte of rcd as an RCDType.

This will panic of len(rcd) < 1.

func (*RCD) UnmarshalBinary

func (rcd *RCD) UnmarshalBinary(data []byte) error

UnmarshalBinary parses the first RCD out of data. Use len(rcd) to determine how many bytes of data were read.

func (RCD) Validate

func (rcd RCD) Validate(sig, msg []byte, whitelist ...RCDType) error

Validate verifies the RCD against the given sig and msg. Only RCDTypes in the whitelist are permitted. If no whitelist is provided all supported RCDTypes are allowed.

func (RCD) ValidateType01

func (rcd RCD) ValidateType01(sig, msg []byte) error

ValidateType01 validates the RCD against sig and msg and ensures that the RCD is RCDType01.

type RCDSignature

type RCDSignature struct {
	RCD       RCD
	Signature Bytes
}

RCDSignature relates an RCD and a corresponding Signature of a signed Transaction.

func (RCDSignature) IsPopulated

func (rs RCDSignature) IsPopulated() bool

IsPopulated returns true if s has already been successfully populated by a call to Get. IsPopulated returns false if s.SignatureBlock or s.ReedeemCondition are nil

func (RCDSignature) Len

func (rs RCDSignature) Len() int

Len is the total size of the RCD and Signature.

func (RCDSignature) MarshalBinary

func (rs RCDSignature) MarshalBinary() ([]byte, error)

MarshalBinary concatenates the RCD and the signature.

func (*RCDSignature) UnmarshalBinary

func (rs *RCDSignature) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals the variable length RCD and Signature block into rs.

Use Len to determine how much data was read.

func (RCDSignature) ValidateType01

func (rs RCDSignature) ValidateType01(msg []byte) error

ValidateType01 validates the RCD and Signature against the msg, which is normally the Transaction Binary Ledger.

type RCDSigner

type RCDSigner interface {
	// RCD constructs the RCD.
	RCD() RCD

	// Sign the msg.
	Sign(msg []byte) []byte
}

RCDSigner is the interface implemented by types that can generate Redeem Condition Datastructures and the corresponding signatures to validate them.

type RCDType

type RCDType byte

RCDType is the magic number that represents the RCD type. Currently this only takes up one byte but techincally it is a varintf. Down the road the underlying type may change to allow for longer IDs for RCD Types.

func (RCDType) String

func (r RCDType) String() string

String returns "RCDTypeXX".

type SK1Key

type SK1Key [sha256.Size]byte

SK1Key is the sk1 secret key for an identity.

func GenerateSK1Key

func GenerateSK1Key() (SK1Key, error)

GenerateSK1Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.

func NewSK1Key

func NewSK1Key(keyStr string) (key SK1Key, err error)

NewSK1Key attempts to parse keyStr into a new SK1Key.

func (SK1Key) ID1Key

func (key SK1Key) ID1Key() ID1Key

ID1Key computes the ID1Key corresponding to key.

func (SK1Key) MarshalText

func (key SK1Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (SK1Key) Payload

func (key SK1Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (SK1Key) PrefixBytes

func (SK1Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb6, 0xc9}.

func (SK1Key) PrefixString

func (SK1Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk1".

func (SK1Key) PrivateKey

func (key SK1Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK1Key) PublicKey

func (key SK1Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK1Key) RCD

func (key SK1Key) RCD() RCD

RCD computes the RCD for key.

func (*SK1Key) Set

func (key *SK1Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (SK1Key) Sign

func (key SK1Key) Sign(msg []byte) []byte

Sign the msg.

func (SK1Key) String

func (key SK1Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (SK1Key) Type

func (SK1Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*SK1Key) UnmarshalText

func (key *SK1Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable sk1 key into key.

type SK2Key

type SK2Key [sha256.Size]byte

SK2Key is the sk2 secret key for an identity.

func GenerateSK2Key

func GenerateSK2Key() (SK2Key, error)

GenerateSK2Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.

func NewSK2Key

func NewSK2Key(keyStr string) (key SK2Key, err error)

NewSK2Key attempts to parse keyStr into a new SK2Key.

func (SK2Key) ID2Key

func (key SK2Key) ID2Key() ID2Key

ID2Key computes the ID2Key corresponding to key.

func (SK2Key) MarshalText

func (key SK2Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (SK2Key) Payload

func (key SK2Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (SK2Key) PrefixBytes

func (SK2Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb6, 0xe7}.

func (SK2Key) PrefixString

func (SK2Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk2".

func (SK2Key) PrivateKey

func (key SK2Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK2Key) PublicKey

func (key SK2Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK2Key) RCD

func (key SK2Key) RCD() RCD

RCD computes the RCD for key.

func (*SK2Key) Set

func (key *SK2Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (SK2Key) Sign

func (key SK2Key) Sign(msg []byte) []byte

Sign the msg.

func (SK2Key) String

func (key SK2Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (SK2Key) Type

func (SK2Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*SK2Key) UnmarshalText

func (key *SK2Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable sk2 key into key.

type SK3Key

type SK3Key [sha256.Size]byte

SK3Key is the sk3 secret key for an identity.

func GenerateSK3Key

func GenerateSK3Key() (SK3Key, error)

GenerateSK3Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.

func NewSK3Key

func NewSK3Key(keyStr string) (key SK3Key, err error)

NewSK3Key attempts to parse keyStr into a new SK3Key.

func (SK3Key) ID3Key

func (key SK3Key) ID3Key() ID3Key

ID3Key computes the ID3Key corresponding to key.

func (SK3Key) MarshalText

func (key SK3Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (SK3Key) Payload

func (key SK3Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (SK3Key) PrefixBytes

func (SK3Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb7, 0x05}.

func (SK3Key) PrefixString

func (SK3Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk3".

func (SK3Key) PrivateKey

func (key SK3Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK3Key) PublicKey

func (key SK3Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK3Key) RCD

func (key SK3Key) RCD() RCD

RCD computes the RCD for key.

func (*SK3Key) Set

func (key *SK3Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (SK3Key) Sign

func (key SK3Key) Sign(msg []byte) []byte

Sign the msg.

func (SK3Key) String

func (key SK3Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (SK3Key) Type

func (SK3Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*SK3Key) UnmarshalText

func (key *SK3Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable sk3 key into key.

type SK4Key

type SK4Key [sha256.Size]byte

SK4Key is the sk4 secret key for an identity.

func GenerateSK4Key

func GenerateSK4Key() (SK4Key, error)

GenerateSK4Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.

func NewSK4Key

func NewSK4Key(keyStr string) (key SK4Key, err error)

NewSK4Key attempts to parse keyStr into a new SK4Key.

func (SK4Key) ID4Key

func (key SK4Key) ID4Key() ID4Key

ID4Key computes the ID4Key corresponding to key.

func (SK4Key) MarshalText

func (key SK4Key) MarshalText() ([]byte, error)

MarshalText encodes key as a string using key.String().

func (SK4Key) Payload

func (key SK4Key) Payload() [sha256.Size]byte

Payload returns key as a byte array.

func (SK4Key) PrefixBytes

func (SK4Key) PrefixBytes() []byte

PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb7, 0x23}.

func (SK4Key) PrefixString

func (SK4Key) PrefixString() string

PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk4".

func (SK4Key) PrivateKey

func (key SK4Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK4Key) PublicKey

func (key SK4Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK4Key) RCD

func (key SK4Key) RCD() RCD

RCD computes the RCD for key.

func (*SK4Key) Set

func (key *SK4Key) Set(keyStr string) error

Set attempts to parse keyStr into key.

func (SK4Key) Sign

func (key SK4Key) Sign(msg []byte) []byte

Sign the msg.

func (SK4Key) String

func (key SK4Key) String() string

String encodes key into its human readable form: a base58check string with key.PrefixBytes().

func (SK4Key) Type

func (SK4Key) Type() string

Type returns PrefixString() satisfies the pflag.Value interface.

func (*SK4Key) UnmarshalText

func (key *SK4Key) UnmarshalText(text []byte) error

UnmarshalText decodes a string with a human readable sk4 key into key.

type Transaction

type Transaction struct {
	// ID the sha256 hash of the binary Transaction ledger, which includes
	// the header, timestamp salt, and all inputs and outputs.
	ID *Bytes32

	// Timestamp is established by the FBlock. It is only populated if the
	// Transaction was unmarshaled from within an FBlock
	Timestamp time.Time

	// TimestampSalt is accurate to the millisecond
	TimestampSalt time.Time

	// Totals all denoted in factoshis. Populated by UnmarshalBinary.
	TotalIn, TotalFCTOut, TotalECOut, TotalBurn uint64

	FCTInputs  []AddressAmount
	FCTOutputs []AddressAmount
	ECOutputs  []AddressAmount
	Signatures []RCDSignature
	// contains filtered or unexported fields
}

Transaction is a Factoid Transaction which is stored in the FBlock.

Transactions can be between FAAddresses, or from an FAAddress to an ECAddress.

Transaction amounts are all delimited in Factoshis.

func (*Transaction) ClearMarshalBinaryCache

func (tx *Transaction) ClearMarshalBinaryCache()

ClearMarshalBinaryCache discards the cached MarshalBinary data.

Subsequent calls to MarshalBinary will re-construct the data from the fields of the DBlock.

func (Transaction) IsPopulated

func (tx Transaction) IsPopulated() bool

IsPopulated returns true if tx has already been successfully populated by a call to Get. IsPopulated returns false if tx.FCTInputs is empty, or if tx.Signatures is not equal in length to the tx.FCTInputs, or if tx.TimestampSalt is zero.

func (Transaction) MarshalBinary

func (tx Transaction) MarshalBinary() ([]byte, error)

MarshalBinary marshals the Transaction into its binary form. If the Transaction was orignally Unmarshaled, then the cached data is re-used, so this is efficient. See ClearMarshalBinaryCache.

This assumes that the Transaction has all signatures in place already. See Transaction.Sign for signing transactions.

func (Transaction) MarshalBinaryLedger

func (tx Transaction) MarshalBinaryLedger() ([]byte, error)

MarshalBinaryLedger marshals the header, inputs, outputs, and EC outputs of the Transaction. This is so that the data can be conveniently signed or hashed.

func (Transaction) MarshalBinaryLen

func (tx Transaction) MarshalBinaryLen() int

MarshalBinaryLen efficiently calculates the full Transaction size. The cached binary marshal data is used if populated.

func (*Transaction) Sign

func (tx *Transaction) Sign(signingSet ...RCDSigner) ([]byte, error)

Sign populates the Signatures of the tx with the given signingSet, which must correspond to the tx.FCTInputs. The complete binary marshaled Transaction is returned.

func (*Transaction) UnmarshalBinary

func (tx *Transaction) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals and validates the first Transaction from data, which may include subsequent Transactions. If no error is returned, the Transaction is valid, including all RCDs and signatures.

Use MarshalBinaryLen to efficiently determine the number of bytes read from data.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier