factom: github.com/Factom-Asset-Tokens/factom Index | Files | Directories

package factom

import "github.com/Factom-Asset-Tokens/factom"

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

Package Files

address.go bytes.go client.go compute.go dblock.go doc.go eblock.go entry.go fblock.go gen.go heights.go identity.go idkey_gen.go int48be.go minute.go networkid.go payload.go pendingentries.go rcd.go transaction.go

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (adr AddressAmount) AddressBytes32() Bytes32

AddressBytes32 converts the Address to Bytes32.

func (AddressAmount) ECAddress Uses

func (adr AddressAmount) ECAddress() ECAddress

ECAddress converts the Address to an ECAddress.

func (AddressAmount) FAAddress Uses

func (adr AddressAmount) FAAddress() FAAddress

FAAddress converts the Address to an FAAddress.

type Bytes Uses

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 Uses

func NewBytes(s string) Bytes

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

func (Bytes) MarshalText Uses

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

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

func (*Bytes) Set Uses

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

Set decodes a hex string into b.

func (Bytes) String Uses

func (b Bytes) String() string

String encodes b as a hex string.

func (Bytes) Type Uses

func (b Bytes) Type() string

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

func (*Bytes) UnmarshalText Uses

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

UnmarshalText decodes a hex string into b.

type Bytes32 Uses

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 Uses

func ABlockChainID() Bytes32

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

func ComputeChainID Uses

func ComputeChainID(nameIDs []Bytes) Bytes32

ComputeChainID returns the chain ID for a set of NameIDs.

func ComputeDBlockBodyMR Uses

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 Uses

func ComputeDBlockHeaderHash(data []byte) Bytes32

ComputeDBlockHeaderHash returns sha256(data[:DBlockHeaderSize]).

func ComputeEBlockBodyMR Uses

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 Uses

func ComputeEBlockHeaderHash(data []byte) Bytes32

ComputeEBlockHeaderHash returns sha256(data[:EBlockHeaderSize]).

func ComputeEntryHash Uses

func ComputeEntryHash(data []byte) Bytes32

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

func ComputeFBlockBodyMR Uses

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 Uses

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

ComputeFBlockKeyMR returns the Key Merkle root of the FBlock.

func ComputeFullHash Uses

func ComputeFullHash(data []byte) Bytes32

ComputeFullHash returns sha256(data).

func ComputeKeyMR Uses

func ComputeKeyMR(headerHash, bodyMR *Bytes32) Bytes32

ComputeKeyMR returns sha256(headerHash|bodyMR).

func ECBlockChainID Uses

func ECBlockChainID() Bytes32

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

func FBlockChainID Uses

func FBlockChainID() Bytes32

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

func GenerateCommit Uses

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 Uses

func NewBytes32(s32 string) Bytes32

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

func (Bytes32) IsZero Uses

func (b Bytes32) IsZero() bool

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

func (Bytes32) MarshalText Uses

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

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

func (*Bytes32) Set Uses

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

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

func (Bytes32) String Uses

func (b Bytes32) String() string

String encodes b as a hex string.

func (Bytes32) Type Uses

func (b Bytes32) Type() string

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

func (*Bytes32) UnmarshalText Uses

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

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

type Client Uses

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 Uses

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 Uses

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

Commit sends an entry or new chain commit to factomd.

func (*Client) FactomdRequest Uses

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 Uses

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

GetPrivateAddresses queries factom-walletd for all private addresses.

func (*Client) Reveal Uses

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

Reveal reveals an entry or new chain entry to factomd.

func (*Client) SavePrivateAddresses Uses

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

SavePrivateAddresses saves many adrs with factom-walletd.

func (*Client) WalletdRequest Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (db DBlock) IsPopulated() bool

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

func (DBlock) MarshalBinary Uses

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 Uses

func (db DBlock) MarshalBinaryLen() int

MarshalBinaryLen returns the length of the binary encoding of db,

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

func (*DBlock) UnmarshalBinary Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (eb EBlock) IsPopulated() bool

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

func (EBlock) MarshalBinary Uses

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 Uses

func (eb EBlock) MarshalBinaryLen() int

MarshalBinaryLen returns the length of the binary encoding of eb,

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

func (EBlock) Prev Uses

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 Uses

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 Uses

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 Uses

type ECAddress [sha256.Size]byte

ECAddress is a Public Entry Credit Address.

func NewECAddress Uses

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

NewECAddress attempts to parse adrStr into a new ECAddress.

func (ECAddress) GetBalance Uses

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

GetBalance queries factomd for the Entry Credit Balance for adr.

func (ECAddress) GetEsAddress Uses

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

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

func (ECAddress) MarshalText Uses

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

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

func (ECAddress) PrefixBytes Uses

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 Uses

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 Uses

func (adr ECAddress) PublicKey() ed25519.PublicKey

PublicKey returns the ed25519.PublicKey for adr.

func (ECAddress) Remove Uses

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

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

func (*ECAddress) Set Uses

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

Set attempts to parse adrStr into adr.

func (ECAddress) String Uses

func (adr ECAddress) String() string

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

func (*ECAddress) UnmarshalText Uses

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

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

type Entry Uses

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"`
    Timestamp time.Time `json:"-"` // Established by EBlock

    // 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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (e Entry) IsPopulated() bool

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

func (Entry) MarshalBinary Uses

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 Uses

func (e Entry) MarshalBinaryLen() int

MarshalBinaryLen returns the total encoded length of e.

func (*Entry) UnmarshalBinary Uses

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 Uses

type EsAddress [sha256.Size]byte

EsAddress is the secret key to a ECAddress.

func GenerateEsAddress Uses

func GenerateEsAddress() (EsAddress, error)

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

func NewEsAddress Uses

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

NewEsAddress attempts to parse adrStr into a new EsAddress.

func (EsAddress) ECAddress Uses

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

ECAddress returns the ECAddress corresponding to adr.

func (EsAddress) GetBalance Uses

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

GetBalance queries factomd for the Entry Credit Balance for adr.

func (EsAddress) MarshalText Uses

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

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

func (EsAddress) PrefixBytes Uses

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 Uses

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 Uses

func (adr EsAddress) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for adr.

func (EsAddress) PublicKey Uses

func (adr EsAddress) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for adr.

func (EsAddress) Remove Uses

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

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

func (EsAddress) Save Uses

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

Save adr with factom-walletd.

func (*EsAddress) Set Uses

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

Set attempts to parse adrStr into adr.

func (EsAddress) String Uses

func (adr EsAddress) String() string

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

func (*EsAddress) UnmarshalText Uses

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

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

type FAAddress Uses

type FAAddress [sha256.Size]byte

FAAddress is a Public Factoid Address.

func NewFAAddress Uses

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

NewFAAddress attempts to parse adrStr into a new FAAddress.

func (FAAddress) GetBalance Uses

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

GetBalance queries factomd for the Factoid Balance for adr.

func (FAAddress) GetFsAddress Uses

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

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

func (FAAddress) MarshalText Uses

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

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

func (FAAddress) PrefixBytes Uses

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 Uses

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 Uses

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

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

func (*FAAddress) Set Uses

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

Set attempts to parse adrStr into adr.

func (FAAddress) String Uses

func (adr FAAddress) String() string

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

func (*FAAddress) UnmarshalText Uses

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

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

type FBlock Uses

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 Uses

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 Uses

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

ComputeFullHash computes the full hash of the FBlock.

func (*FBlock) Get Uses

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 Uses

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 Uses

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 Uses

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 Uses

type FsAddress [sha256.Size]byte

FsAddress is the secret key to a FAAddress.

func GenerateFsAddress Uses

func GenerateFsAddress() (FsAddress, error)

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

func NewFsAddress Uses

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

NewFsAddress attempts to parse adrStr into a new FsAddress.

func (FsAddress) FAAddress Uses

func (adr FsAddress) FAAddress() FAAddress

FAAddress returns the FAAddress corresponding to adr.

func (FsAddress) GetBalance Uses

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

GetBalance queries factomd for the Factoid Balance for adr.

func (FsAddress) MarshalText Uses

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

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

func (FsAddress) PrefixBytes Uses

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 Uses

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 Uses

func (adr FsAddress) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for adr.

func (FsAddress) PublicKey Uses

func (adr FsAddress) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for adr.

func (FsAddress) RCD Uses

func (adr FsAddress) RCD() RCD

RCD computes the RCD for adr.

func (FsAddress) Remove Uses

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

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

func (FsAddress) Save Uses

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

Save adr with factom-walletd.

func (*FsAddress) Set Uses

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

Set attempts to parse adrStr into adr.

func (FsAddress) Sign Uses

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

Sign the msg.

func (FsAddress) String Uses

func (adr FsAddress) String() string

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

func (*FsAddress) UnmarshalText Uses

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

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

type Heights Uses

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 Uses

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 Uses

type ID1Key [sha256.Size]byte

ID1Key is the id1 public key for an identity.

func NewID1Key Uses

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

NewID1Key attempts to parse keyStr into a new ID1Key.

func (ID1Key) MarshalText Uses

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

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

func (ID1Key) Payload Uses

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

Payload returns key as a byte array.

func (ID1Key) PrefixBytes Uses

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 Uses

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 Uses

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

Set attempts to parse keyStr into key.

func (ID1Key) String Uses

func (key ID1Key) String() string

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

func (ID1Key) Type Uses

func (ID1Key) Type() string

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

func (*ID1Key) UnmarshalText Uses

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

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

type ID2Key Uses

type ID2Key [sha256.Size]byte

ID2Key is the id2 public key for an identity.

func NewID2Key Uses

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

NewID2Key attempts to parse keyStr into a new ID2Key.

func (ID2Key) MarshalText Uses

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

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

func (ID2Key) Payload Uses

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

Payload returns key as a byte array.

func (ID2Key) PrefixBytes Uses

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 Uses

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 Uses

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

Set attempts to parse keyStr into key.

func (ID2Key) String Uses

func (key ID2Key) String() string

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

func (ID2Key) Type Uses

func (ID2Key) Type() string

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

func (*ID2Key) UnmarshalText Uses

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

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

type ID3Key Uses

type ID3Key [sha256.Size]byte

ID3Key is the id3 public key for an identity.

func NewID3Key Uses

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

NewID3Key attempts to parse keyStr into a new ID3Key.

func (ID3Key) MarshalText Uses

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

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

func (ID3Key) Payload Uses

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

Payload returns key as a byte array.

func (ID3Key) PrefixBytes Uses

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 Uses

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 Uses

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

Set attempts to parse keyStr into key.

func (ID3Key) String Uses

func (key ID3Key) String() string

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

func (ID3Key) Type Uses

func (ID3Key) Type() string

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

func (*ID3Key) UnmarshalText Uses

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

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

type ID4Key Uses

type ID4Key [sha256.Size]byte

ID4Key is the id4 public key for an identity.

func NewID4Key Uses

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

NewID4Key attempts to parse keyStr into a new ID4Key.

func (ID4Key) MarshalText Uses

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

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

func (ID4Key) Payload Uses

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

Payload returns key as a byte array.

func (ID4Key) PrefixBytes Uses

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 Uses

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 Uses

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

Set attempts to parse keyStr into key.

func (ID4Key) String Uses

func (key ID4Key) String() string

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

func (ID4Key) Type Uses

func (ID4Key) Type() string

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

func (*ID4Key) UnmarshalText Uses

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

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

type Identity Uses

type Identity struct {
    ID1Key *ID1Key
    Height uint32
    Entry
}

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

func (*Identity) Get Uses

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 Uses

func (i Identity) IsPopulated() bool

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

func (*Identity) UnmarshalBinary Uses

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 Uses

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 Uses

func LocalnetID() NetworkID

LocalnetID returns the Localnet NetworkID, 0xFA92E5A4.

func MainnetID Uses

func MainnetID() NetworkID

MainnetID returns the Mainnet NetworkID, 0xFA92E5A2.

func TestnetID Uses

func TestnetID() NetworkID

TestnetID returns the Testnet NetworkID, 0x883e093b.

func (NetworkID) IsCustom Uses

func (n NetworkID) IsCustom() bool

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

func (NetworkID) IsLocalnet Uses

func (n NetworkID) IsLocalnet() bool

IsLocalnet returns true if n is the Localnet NetworkID.

func (NetworkID) IsMainnet Uses

func (n NetworkID) IsMainnet() bool

IsMainnet returns true if n is the Mainnet NetworkID.

func (NetworkID) IsTestnet Uses

func (n NetworkID) IsTestnet() bool

IsTestnet returns true if n is the Testnet NetworkID.

func (*NetworkID) Set Uses

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 Uses

func (n NetworkID) String() string

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

type PendingEntries Uses

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 Uses

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 Uses

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 Uses

type RCD []byte

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

func (RCD) FAAddress Uses

func (rcd RCD) FAAddress() FAAddress

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

func (RCD) Hash Uses

func (rcd RCD) Hash() Bytes32

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

func (RCD) SignatureBlockSize Uses

func (rcd RCD) SignatureBlockSize() int

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

func (RCD) String Uses

func (rcd RCD) String() string

String returns a hex encoded string of the RCD.

func (RCD) Type Uses

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 Uses

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 Uses

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 Uses

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 Uses

type RCDSignature struct {
    RCD       RCD
    Signature Bytes
}

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

func (RCDSignature) IsPopulated Uses

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 Uses

func (rs RCDSignature) Len() int

Len is the total size of the RCD and Signature.

func (RCDSignature) MarshalBinary Uses

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

MarshalBinary concatenates the RCD and the signature.

func (*RCDSignature) UnmarshalBinary Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (r RCDType) String() string

String returns "RCDTypeXX".

type SK1Key Uses

type SK1Key [sha256.Size]byte

SK1Key is the sk1 secret key for an identity.

func GenerateSK1Key Uses

func GenerateSK1Key() (SK1Key, error)

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

func NewSK1Key Uses

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

NewSK1Key attempts to parse keyStr into a new SK1Key.

func (SK1Key) ID1Key Uses

func (key SK1Key) ID1Key() ID1Key

ID1Key computes the ID1Key corresponding to key.

func (SK1Key) MarshalText Uses

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

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

func (SK1Key) Payload Uses

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

Payload returns key as a byte array.

func (SK1Key) PrefixBytes Uses

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 Uses

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 Uses

func (key SK1Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK1Key) PublicKey Uses

func (key SK1Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK1Key) RCD Uses

func (key SK1Key) RCD() RCD

RCD computes the RCD for key.

func (*SK1Key) Set Uses

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

Set attempts to parse keyStr into key.

func (SK1Key) Sign Uses

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

Sign the msg.

func (SK1Key) String Uses

func (key SK1Key) String() string

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

func (SK1Key) Type Uses

func (SK1Key) Type() string

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

func (*SK1Key) UnmarshalText Uses

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

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

type SK2Key Uses

type SK2Key [sha256.Size]byte

SK2Key is the sk2 secret key for an identity.

func GenerateSK2Key Uses

func GenerateSK2Key() (SK2Key, error)

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

func NewSK2Key Uses

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

NewSK2Key attempts to parse keyStr into a new SK2Key.

func (SK2Key) ID2Key Uses

func (key SK2Key) ID2Key() ID2Key

ID2Key computes the ID2Key corresponding to key.

func (SK2Key) MarshalText Uses

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

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

func (SK2Key) Payload Uses

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

Payload returns key as a byte array.

func (SK2Key) PrefixBytes Uses

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 Uses

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 Uses

func (key SK2Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK2Key) PublicKey Uses

func (key SK2Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK2Key) RCD Uses

func (key SK2Key) RCD() RCD

RCD computes the RCD for key.

func (*SK2Key) Set Uses

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

Set attempts to parse keyStr into key.

func (SK2Key) Sign Uses

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

Sign the msg.

func (SK2Key) String Uses

func (key SK2Key) String() string

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

func (SK2Key) Type Uses

func (SK2Key) Type() string

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

func (*SK2Key) UnmarshalText Uses

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

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

type SK3Key Uses

type SK3Key [sha256.Size]byte

SK3Key is the sk3 secret key for an identity.

func GenerateSK3Key Uses

func GenerateSK3Key() (SK3Key, error)

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

func NewSK3Key Uses

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

NewSK3Key attempts to parse keyStr into a new SK3Key.

func (SK3Key) ID3Key Uses

func (key SK3Key) ID3Key() ID3Key

ID3Key computes the ID3Key corresponding to key.

func (SK3Key) MarshalText Uses

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

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

func (SK3Key) Payload Uses

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

Payload returns key as a byte array.

func (SK3Key) PrefixBytes Uses

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 Uses

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 Uses

func (key SK3Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK3Key) PublicKey Uses

func (key SK3Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK3Key) RCD Uses

func (key SK3Key) RCD() RCD

RCD computes the RCD for key.

func (*SK3Key) Set Uses

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

Set attempts to parse keyStr into key.

func (SK3Key) Sign Uses

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

Sign the msg.

func (SK3Key) String Uses

func (key SK3Key) String() string

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

func (SK3Key) Type Uses

func (SK3Key) Type() string

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

func (*SK3Key) UnmarshalText Uses

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

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

type SK4Key Uses

type SK4Key [sha256.Size]byte

SK4Key is the sk4 secret key for an identity.

func GenerateSK4Key Uses

func GenerateSK4Key() (SK4Key, error)

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

func NewSK4Key Uses

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

NewSK4Key attempts to parse keyStr into a new SK4Key.

func (SK4Key) ID4Key Uses

func (key SK4Key) ID4Key() ID4Key

ID4Key computes the ID4Key corresponding to key.

func (SK4Key) MarshalText Uses

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

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

func (SK4Key) Payload Uses

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

Payload returns key as a byte array.

func (SK4Key) PrefixBytes Uses

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 Uses

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 Uses

func (key SK4Key) PrivateKey() ed25519.PrivateKey

PrivateKey returns the ed25519.PrivateKey for key.

func (SK4Key) PublicKey Uses

func (key SK4Key) PublicKey() ed25519.PublicKey

PublicKey computes the ed25519.PublicKey for key.

func (SK4Key) RCD Uses

func (key SK4Key) RCD() RCD

RCD computes the RCD for key.

func (*SK4Key) Set Uses

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

Set attempts to parse keyStr into key.

func (SK4Key) Sign Uses

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

Sign the msg.

func (SK4Key) String Uses

func (key SK4Key) String() string

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

func (SK4Key) Type Uses

func (SK4Key) Type() string

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

func (*SK4Key) UnmarshalText Uses

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

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

type Transaction Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (tx Transaction) MarshalBinaryLen() int

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

func (*Transaction) Sign Uses

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 Uses

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.

Directories

PathSynopsis
fat
fat0Package fat0 provides data types corresponding to valid FAT-0 entries for Transaction and Issuance as well as methods for validating the structure and content of the factom entry.
fat1
fat103
fat107
jsonlen
varintfPackage varintf implements Factom's varInt_F specification.

Package factom imports 21 packages (graph) and is imported by 28 packages. Updated 2020-03-24. Refresh now. Tools for package owners.