Documentation
¶
Overview ¶
Package factom provides data types corresponding to some of the Factom blockchain's data structures, as well as methods on those types for querying the data from factomd and factom-walletd's APIs.
All of the Factom data structure types in this package have the Get and IsPopulated methods.
Methods that accept a *Client, like those that start with Get, may 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 are used by other types when JSON marshaling and unmarshaling to and from hex encoded data is required. Bytes32 is used for Chain IDs and KeyMRs.
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.
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 DBlocks or EBlocks. Additionally, working with Identity Chains is not yet supported beyond querying the ID1Key.
Index ¶
- Constants
- func EntryCost(size int) (int8, error)
- func ValidIdentityChainID(chainID Bytes) bool
- func ValidIdentityNameIDs(nameIDs []Bytes) bool
- type Address
- type Bytes
- type Bytes32
- type Client
- func (c *Client) Commit(commit []byte) error
- func (c *Client) FactomdRequest(method string, params, result interface{}) error
- func (c *Client) GetAddress(pubAdr Address, privAdr PrivateAddress) error
- func (c *Client) GetAddresses() ([]Address, error)
- func (c *Client) GetECAddresses() ([]ECAddress, error)
- func (c *Client) GetEsAddresses() ([]EsAddress, error)
- func (c *Client) GetFAAddresses() ([]FAAddress, error)
- func (c *Client) GetFsAddresses() ([]FsAddress, error)
- func (c *Client) GetPrivateAddresses() ([]PrivateAddress, error)
- func (c *Client) RemoveAddress(adr Address) error
- func (c *Client) Reveal(reveal []byte) error
- func (c *Client) SavePrivateAddresses(adrs ...PrivateAddress) error
- func (c *Client) WalletdRequest(method string, params, result interface{}) error
- type DBlock
- type EBlock
- type EBlockHeader
- type ECAddress
- func (adr ECAddress) GetBalance(c *Client) (uint64, error)
- func (adr ECAddress) GetEsAddress(c *Client) (EsAddress, error)
- func (adr ECAddress) GetPrivateAddress(c *Client) (PrivateAddress, error)
- func (adr ECAddress) MarshalJSON() ([]byte, error)
- func (adr ECAddress) Payload() [sha256.Size]byte
- func (ECAddress) PrefixBytes() []byte
- func (ECAddress) PrefixString() string
- func (adr ECAddress) PublicAddress() Address
- func (adr ECAddress) PublicKey() ed25519.PublicKey
- func (adr ECAddress) Remove(c *Client) error
- func (adr *ECAddress) Set(adrStr string) error
- func (adr ECAddress) String() string
- func (adr *ECAddress) UnmarshalJSON(data []byte) error
- type Entry
- func (e *Entry) Compose(es EsAddress) (commit []byte, reveal []byte, txID *Bytes32, err error)
- func (e *Entry) ComposeCreate(c *Client, es EsAddress) (*Bytes32, error)
- func (e Entry) ComputeHash() (Bytes32, error)
- func (e *Entry) Create(c *Client, ec ECAddress) (*Bytes32, error)
- func (e *Entry) Get(c *Client) error
- func (e Entry) IsPopulated() bool
- func (e *Entry) MarshalBinary() ([]byte, error)
- func (e *Entry) UnmarshalBinary(data []byte) error
- type EsAddress
- func (adr EsAddress) ECAddress() (ec ECAddress)
- func (adr EsAddress) GetBalance(c *Client) (uint64, error)
- func (adr EsAddress) GetPrivateAddress(_ *Client) (PrivateAddress, error)
- func (adr EsAddress) MarshalJSON() ([]byte, error)
- func (adr EsAddress) Payload() [sha256.Size]byte
- func (EsAddress) PrefixBytes() []byte
- func (EsAddress) PrefixString() string
- func (adr EsAddress) PrivateKey() ed25519.PrivateKey
- func (adr EsAddress) PublicAddress() Address
- func (adr EsAddress) PublicKey() ed25519.PublicKey
- func (adr EsAddress) Remove(c *Client) error
- func (adr EsAddress) Save(c *Client) error
- func (adr *EsAddress) Set(adrStr string) error
- func (adr EsAddress) String() string
- func (adr *EsAddress) UnmarshalJSON(data []byte) error
- type FAAddress
- func (adr FAAddress) GetBalance(c *Client) (uint64, error)
- func (adr FAAddress) GetFsAddress(c *Client) (FsAddress, error)
- func (adr FAAddress) GetPrivateAddress(c *Client) (PrivateAddress, error)
- func (adr FAAddress) MarshalJSON() ([]byte, error)
- func (adr FAAddress) Payload() [sha256.Size]byte
- func (FAAddress) PrefixBytes() []byte
- func (FAAddress) PrefixString() string
- func (adr FAAddress) PublicAddress() Address
- func (adr FAAddress) RCDHash() [sha256.Size]byte
- func (adr FAAddress) Remove(c *Client) error
- func (adr *FAAddress) Scan(v interface{}) error
- func (adr *FAAddress) Set(adrStr string) error
- func (adr FAAddress) String() string
- func (adr *FAAddress) UnmarshalJSON(data []byte) error
- func (adr FAAddress) Value() (driver.Value, error)
- type FsAddress
- func (adr FsAddress) FAAddress() FAAddress
- func (adr FsAddress) GetBalance(c *Client) (uint64, error)
- func (adr FsAddress) GetPrivateAddress(_ *Client) (PrivateAddress, error)
- func (adr FsAddress) MarshalJSON() ([]byte, error)
- func (adr FsAddress) Payload() [sha256.Size]byte
- func (FsAddress) PrefixBytes() []byte
- func (FsAddress) PrefixString() string
- func (adr FsAddress) PrivateKey() ed25519.PrivateKey
- func (adr FsAddress) PublicAddress() Address
- func (adr FsAddress) PublicKey() ed25519.PublicKey
- func (adr FsAddress) RCD() []byte
- func (adr FsAddress) RCDHash() [sha256.Size]byte
- func (adr FsAddress) Remove(c *Client) error
- func (adr FsAddress) Save(c *Client) error
- func (adr *FsAddress) Set(adrStr string) error
- func (adr FsAddress) String() string
- func (adr *FsAddress) UnmarshalJSON(data []byte) error
- type Heights
- type ID1Key
- func (key ID1Key) IDKey() IDKey
- func (key ID1Key) MarshalJSON() ([]byte, error)
- func (key ID1Key) Payload() [sha256.Size]byte
- func (ID1Key) PrefixBytes() []byte
- func (ID1Key) PrefixString() string
- func (key ID1Key) RCDHash() [sha256.Size]byte
- func (key *ID1Key) Scan(v interface{}) error
- func (key *ID1Key) Set(keyStr string) error
- func (key ID1Key) String() string
- func (key *ID1Key) UnmarshalJSON(data []byte) error
- func (key ID1Key) Value() (driver.Value, error)
- type ID2Key
- func (key ID2Key) IDKey() IDKey
- func (key ID2Key) MarshalJSON() ([]byte, error)
- func (key ID2Key) Payload() [sha256.Size]byte
- func (ID2Key) PrefixBytes() []byte
- func (ID2Key) PrefixString() string
- func (key ID2Key) RCDHash() [sha256.Size]byte
- func (key *ID2Key) Scan(v interface{}) error
- func (key *ID2Key) Set(keyStr string) error
- func (key ID2Key) String() string
- func (key *ID2Key) UnmarshalJSON(data []byte) error
- func (key ID2Key) Value() (driver.Value, error)
- type ID3Key
- func (key ID3Key) IDKey() IDKey
- func (key ID3Key) MarshalJSON() ([]byte, error)
- func (key ID3Key) Payload() [sha256.Size]byte
- func (ID3Key) PrefixBytes() []byte
- func (ID3Key) PrefixString() string
- func (key ID3Key) RCDHash() [sha256.Size]byte
- func (key *ID3Key) Scan(v interface{}) error
- func (key *ID3Key) Set(keyStr string) error
- func (key ID3Key) String() string
- func (key *ID3Key) UnmarshalJSON(data []byte) error
- func (key ID3Key) Value() (driver.Value, error)
- type ID4Key
- func (key ID4Key) IDKey() IDKey
- func (key ID4Key) MarshalJSON() ([]byte, error)
- func (key ID4Key) Payload() [sha256.Size]byte
- func (ID4Key) PrefixBytes() []byte
- func (ID4Key) PrefixString() string
- func (key ID4Key) RCDHash() [sha256.Size]byte
- func (key *ID4Key) Scan(v interface{}) error
- func (key *ID4Key) Set(keyStr string) error
- func (key ID4Key) String() string
- func (key *ID4Key) UnmarshalJSON(data []byte) error
- func (key ID4Key) Value() (driver.Value, error)
- type IDKey
- type Identity
- type PrivateAddress
- type RCDPrivateKey
- type SK1Key
- func (key SK1Key) ID1Key() ID1Key
- func (key SK1Key) IDKey() IDKey
- func (key SK1Key) MarshalJSON() ([]byte, error)
- func (key SK1Key) Payload() [sha256.Size]byte
- func (SK1Key) PrefixBytes() []byte
- func (SK1Key) PrefixString() string
- func (key SK1Key) PrivateKey() ed25519.PrivateKey
- func (key SK1Key) PublicKey() ed25519.PublicKey
- func (key SK1Key) RCD() []byte
- func (key SK1Key) RCDHash() [sha256.Size]byte
- func (key SK1Key) SKKey() SKKey
- func (key *SK1Key) Set(keyStr string) error
- func (key SK1Key) String() string
- func (key *SK1Key) UnmarshalJSON(data []byte) error
- type SK2Key
- func (key SK2Key) ID2Key() ID2Key
- func (key SK2Key) IDKey() IDKey
- func (key SK2Key) MarshalJSON() ([]byte, error)
- func (key SK2Key) Payload() [sha256.Size]byte
- func (SK2Key) PrefixBytes() []byte
- func (SK2Key) PrefixString() string
- func (key SK2Key) PrivateKey() ed25519.PrivateKey
- func (key SK2Key) PublicKey() ed25519.PublicKey
- func (key SK2Key) RCD() []byte
- func (key SK2Key) RCDHash() [sha256.Size]byte
- func (key SK2Key) SKKey() SKKey
- func (key *SK2Key) Set(keyStr string) error
- func (key SK2Key) String() string
- func (key *SK2Key) UnmarshalJSON(data []byte) error
- type SK3Key
- func (key SK3Key) ID3Key() ID3Key
- func (key SK3Key) IDKey() IDKey
- func (key SK3Key) MarshalJSON() ([]byte, error)
- func (key SK3Key) Payload() [sha256.Size]byte
- func (SK3Key) PrefixBytes() []byte
- func (SK3Key) PrefixString() string
- func (key SK3Key) PrivateKey() ed25519.PrivateKey
- func (key SK3Key) PublicKey() ed25519.PublicKey
- func (key SK3Key) RCD() []byte
- func (key SK3Key) RCDHash() [sha256.Size]byte
- func (key SK3Key) SKKey() SKKey
- func (key *SK3Key) Set(keyStr string) error
- func (key SK3Key) String() string
- func (key *SK3Key) UnmarshalJSON(data []byte) error
- type SK4Key
- func (key SK4Key) ID4Key() ID4Key
- func (key SK4Key) IDKey() IDKey
- func (key SK4Key) MarshalJSON() ([]byte, error)
- func (key SK4Key) Payload() [sha256.Size]byte
- func (SK4Key) PrefixBytes() []byte
- func (SK4Key) PrefixString() string
- func (key SK4Key) PrivateKey() ed25519.PrivateKey
- func (key SK4Key) PublicKey() ed25519.PublicKey
- func (key SK4Key) RCD() []byte
- func (key SK4Key) RCDHash() [sha256.Size]byte
- func (key SK4Key) SKKey() SKKey
- func (key *SK4Key) Set(keyStr string) error
- func (key SK4Key) String() string
- func (key *SK4Key) UnmarshalJSON(data []byte) error
- type SKKey
- type Time
Constants ¶
const ( // RCDType is the magic number identifying the currenctly accepted RCD. RCDType byte = 0x01 // RCDSize is the size of the RCD. RCDSize = ed25519.PublicKeySize + 1 // SignatureSize is the size of the ed25519 signatures. SignatureSize = ed25519.SignatureSize )
const ( FactomdDefault = "http://localhost:8088" WalletdDefault = "http://localhost:8089" )
Defaults for the factomd and factom-walletd endpoints.
const NewChainCost = 10
NewChainCost is the fixed added cost of creating a new chain.
Variables ¶
This section is empty.
Functions ¶
func EntryCost ¶
EntryCost returns the required Entry Credit cost for an entry with encoded length equal to size. An error is returned if size exceeds 10275.
func ValidIdentityChainID ¶
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 ¶
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
Types ¶
type Address ¶
type Address interface {
// PrefixBytes returns the prefix bytes for the Address.
PrefixBytes() []byte
// PrefixString returns the encoded prefix string for the Address.
PrefixString() string
// String encodes the address to a base58check string with the
// appropriate prefix.
String() string
// Payload returns the address as a byte array.
Payload() [sha256.Size]byte
// PublicAddress returns the corresponding public address in an Address
// interface. Public addresses return themselves. Private addresses
// compute the public address.
PublicAddress() Address
// GetPrivateAddress returns the corresponding private address in a
// PrivateAddress interface. Public addresses query factom-walletd for
// the private address. Private addresses return themselves.
GetPrivateAddress(*Client) (PrivateAddress, error)
// GetBalance returns the current balance for the address.
GetBalance(*Client) (uint64, error)
// Remove queries factom-walletd to remove the public and private
// addresses from its database.
// WARNING: DESTRUCTIVE ACTION! LOSS OF KEYS AND FUNDS MAY RESULT!
Remove(*Client) error
}
Address is the interface implemented by the four address types: FAAddress, FsAddress, ECAddress, and EsAddress.
func NewAddress ¶
NewAddress parses adrStr and returns the correct address type as an Address interface. This is useful when the address type isn't known prior to parsing adrStr. If the address type is known ahead of time, it is generally better to just use the appropriate concrete type.
func NewPublicAddress ¶
NewPublicAddress parses adrStr and returns the correct address type as an Address interface. If adrStr is not a public address then an "invalid prefix" error is returned. This is useful when the address type isn't known prior to parsing adrStr, but must be a public address. If the address type is known ahead of time, it is generally better to just use the appropriate concrete type.
type Bytes ¶
type Bytes []byte
Bytes implements json.Marshaler and json.Unmarshaler to encode and decode strings with hex encoded data, such as an Entry's External IDs or content.
func (Bytes) MarshalJSON ¶
MarshalJSON encodes b as a hex JSON string.
func (*Bytes) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with hex encoded data.
type Bytes32 ¶
type Bytes32 [32]byte
Bytes32 implements json.Marshaler and json.Unmarshaler to encode and decode strings with exactly 32 bytes of hex encoded data, such as Chain IDs and KeyMRs.
func EntryHash ¶
EntryHash returns the Entry hash of data. Entry's are hashed via: sha256(sha512(data) + data).
func NewBytes32 ¶
NewBytes32 allocates a new Bytes32 object with the first 32 bytes of data contained in s32.
func (Bytes32) MarshalJSON ¶
MarshalJSON encodes b as a hex JSON string.
func (*Bytes32) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with exactly 32 bytes of hex encoded data.
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 factom-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 Client initialized with the default localhost endpoints for factomd and factom-walletd, and 15 second timeouts for each of the http.Clients.
func (*Client) FactomdRequest ¶
FactomdRequest makes a request to factomd's v2 API.
func (*Client) GetAddress ¶
func (c *Client) GetAddress(pubAdr Address, privAdr PrivateAddress) error
GetAddress queries factom-walletd for the privAdr corresponding to pubAdr. If the returned error is nil, then privAdr is now populated. Note that privAdr must be a pointer to a concrete type implementing PrivateAddress.
func (*Client) GetAddresses ¶
GetAddresses queries factom-walletd for all public addresses.
func (*Client) GetECAddresses ¶
GetECAddresses queries factom-walletd for all public Entry Credit addresses.
func (*Client) GetEsAddresses ¶
GetEsAddresses queries factom-walletd for all secret Entry Credit addresses.
func (*Client) GetFAAddresses ¶
GetFAAddresses queries factom-walletd for all public Factoid addresses.
func (*Client) GetFsAddresses ¶
GetFsAddresses queries factom-walletd for all secret Factoid addresses.
func (*Client) GetPrivateAddresses ¶
func (c *Client) GetPrivateAddresses() ([]PrivateAddress, error)
GetPrivateAddresses queries factom-walletd for all private addresses.
func (*Client) RemoveAddress ¶
RemoveAddress removes adr from factom-walletd. WARNING: THIS IS DESTRUCTIVE.
func (*Client) SavePrivateAddresses ¶
func (c *Client) SavePrivateAddresses(adrs ...PrivateAddress) error
SavePrivateAddresses saves many adrs with factom-walletd.
func (*Client) WalletdRequest ¶
WalletdRequest makes a request to factom-walletd's v2 API.
type DBlock ¶
type DBlock struct {
Height uint64 `json:"height"`
// DBlock.Get populates EBlocks with their ChainID and KeyMR.
EBlocks []EBlock `json:"dbentries,omitempty"`
}
DBlock represents a Factom Directory Block.
func (*DBlock) Get ¶
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 ¶
IsPopulated returns true if db has already been successfully populated by a call to Get. IsPopulated returns false if db.EBlocks is nil.
type EBlock ¶
type EBlock struct {
// DBlock.Get populates the ChainID, KeyMR, and Height.
ChainID *Bytes32 `json:"chainid,omitempty"`
KeyMR *Bytes32 `json:"keymr,omitempty"`
// EBlock.Get populates the EBlockHeader.PrevKeyMR and the Entries with
// their Hash and Timestamp.
EBlockHeader `json:"header,omitempty"`
Entries []Entry `json:"entrylist,omitempty"`
}
EBlock represents a Factom Entry Block.
func (*EBlock) Get ¶
Get queries factomd for the Entry Block corresponding to eb.KeyMR, if not nil, and otherwise the Entry Block chain head for eb.ChainID. Either eb.KeyMR or eb.ChainID must be not nil or else Get will fail to populate the EBlock. After a successful call, EBlockHeader and Entries will be populated. Each Entry will be populated with its Hash, Timestamp, ChainID, and Height, but not its Content or ExtIDs. Call Get on the individual Entries to populate their Content and ExtIDs.
func (EBlock) GetAllPrev ¶
GetAllPrev returns a slice of all preceding EBlocks in eb's chain, in order from earliest to latest, up to and including eb. So the last element of the returned slice is always equal to eb. If eb is the first entry block in its chain, then it is the only element in the slice.
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 to reduce network calls and memory usage.
func (*EBlock) GetChainHead ¶
GetChainHead queries factomd for the latest eb.KeyMR for chain eb.ChainID.
func (*EBlock) GetFirst ¶
GetFirst finds the first Entry Block in eb's chain, and populates eb as such.
GetFirst differs from GetAllPrev in that it does not allocate any additional EBlocks. GetFirst avoids allocating any new EBlocks by reusing eb to traverse up to the first entry block.
func (EBlock) IsFirst ¶
IsFirst returns true if this is the first EBlock in its chain, indicated by the PrevKeyMR being all zeroes. IsFirst returns false if eb is not populated or if the PrevKeyMR is not all zeroes.
func (EBlock) IsPopulated ¶
IsPopulated returns true if eb has already been successfully populated by a call to Get. Returns false if eb.PrevKeyMR is nil.
type EBlockHeader ¶
type EBlockHeader struct {
PrevKeyMR *Bytes32 `json:"prevkeymr,omitempty"`
Height uint64 `json:"dbheight"`
}
EBlockHeader is required for unmashaling the nested structure of the Entry Block response from the factomd JSON RPC API.
type ECAddress ¶
ECAddress is a Public Entry Credit Address.
func NewECAddress ¶
NewECAddress attempts to parse adrStr into a new ECAddress.
func (ECAddress) GetBalance ¶
GetBalance queries factomd for the Entry Credit Balance for adr.
func (ECAddress) GetEsAddress ¶
GetEsAddress queries factom-walletd for the EsAddress corresponding to adr.
func (ECAddress) GetPrivateAddress ¶
func (adr ECAddress) GetPrivateAddress(c *Client) (PrivateAddress, error)
GetPrivateAddress queries factom-walletd for the secret address corresponding to adr and returns it as a PrivateAddress.
func (ECAddress) MarshalJSON ¶
MarshalJSON encodes adr as a JSON string using adr.String().
func (ECAddress) PrefixBytes ¶
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{0x59, 0x2a}.
func (ECAddress) PrefixString ¶
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) PublicAddress ¶
PublicAddress returns adr as an Address.
func (ECAddress) String ¶
String encodes adr into its human readable form: a base58check string with adr.PrefixBytes().
func (*ECAddress) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable public Entry Credit address into adr.
type Entry ¶
type Entry struct {
// EBlock.Get populates the Hash, Timestamp, ChainID, and Height.
Hash *Bytes32 `json:"entryhash,omitempty"`
Timestamp Time `json:"timestamp,omitempty"`
ChainID *Bytes32 `json:"chainid,omitempty"`
Height uint64 `json:"-"`
// Entry.Get populates the Content and ExtIDs.
ExtIDs []Bytes `json:"extids"`
Content Bytes `json:"content"`
}
Entry represents a Factom Entry.
func (*Entry) Compose ¶
Compose generates the commit and reveal data required to submit an entry to factomd. If e.ChainID is nil, then the ChainID is computed from the e.ExtIDs and a new chain commit is created.
func (*Entry) ComposeCreate ¶
ComposeCreate Composes e locally and then Commit and Reveals it using factomd. This does not make any calls to factom-walletd. The Transaction ID is returned.
func (Entry) ComputeHash ¶
ComputeHash returns the Entry's hash as computed by hashing the binary representation of the Entry.
func (*Entry) Create ¶
Create queries factom-walletd to compose and factomd to commit and reveal a new Entry or new Chain, if e.ChainID is nil. ec must exist in factom-walletd's keystore.
func (*Entry) Get ¶
Get queries factomd for the entry corresponding to e.Hash, which must be not nil. After a successful call e.Content, e.ExtIDs, and e.Timestamp will be populated.
func (Entry) IsPopulated ¶
IsPopulated returns true if e has already been successfully populated by a call to Get. IsPopulated returns false if e.ExtIDs, e.Content, or e.Hash are nil, or if e.Timestamp is zero.
func (*Entry) MarshalBinary ¶
MarshalBinary marshals the entry to its binary representation. See UnmarshalBinary for encoding details. MarshalBinary populates e.ChainID if nil, and always overwrites e.Hash with the computed EntryHash. This is also the reveal data.
func (*Entry) UnmarshalBinary ¶
UnmarshalBinary unmarshals raw entry data. It does not populate the Entry.Hash. Entries are encoded as follows and use big endian uint16:
[Version byte (0x00)] + [ChainID (Bytes32)] + [Total ExtID encoded length (uint16)] + [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 ¶
EsAddress is the secret key to a ECAddress.
func GenerateEsAddress ¶
GenerateEsAddress generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func NewEsAddress ¶
NewEsAddress attempts to parse adrStr into a new EsAddress.
func (EsAddress) GetBalance ¶
GetBalance queries factomd for the Entry Credit Balance for adr.
func (EsAddress) GetPrivateAddress ¶
func (adr EsAddress) GetPrivateAddress(_ *Client) (PrivateAddress, error)
GetPrivateAddress returns adr as a PrivateAddress.
func (EsAddress) MarshalJSON ¶
MarshalJSON encodes adr as a JSON string using adr.String().
func (EsAddress) PrefixBytes ¶
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{0x5d, 0xb6}.
func (EsAddress) PrefixString ¶
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) PublicAddress ¶
PublicAddress returns the ECAddress corresponding to adr as an Address.
func (EsAddress) String ¶
String encodes adr into its human readable form: a base58check string with adr.PrefixBytes().
func (*EsAddress) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable secret Entry Credit address into adr.
type FAAddress ¶
FAAddress is a Public Factoid Address.
func NewFAAddress ¶
NewFAAddress attempts to parse adrStr into a new FAAddress.
func (FAAddress) GetBalance ¶
GetBalance queries factomd for the Factoid Balance for adr.
func (FAAddress) GetFsAddress ¶
GetFsAddress queries factom-walletd for the FsAddress corresponding to adr.
func (FAAddress) GetPrivateAddress ¶
func (adr FAAddress) GetPrivateAddress(c *Client) (PrivateAddress, error)
GetPrivateAddress queries factom-walletd for the secret address corresponding to adr and returns it as a PrivateAddress.
func (FAAddress) MarshalJSON ¶
MarshalJSON encodes adr as a JSON string using adr.String().
func (FAAddress) PrefixBytes ¶
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{0x5f, 0xb1}.
func (FAAddress) PrefixString ¶
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) PublicAddress ¶
PublicAddress returns adr as an Address.
func (*FAAddress) Scan ¶
Scan implements sql.Scanner for adr using Bytes32.Scan. The FAAddress type is not encoded and is assumed.
func (FAAddress) String ¶
String encodes adr into its human readable form: a base58check string with adr.PrefixBytes().
func (*FAAddress) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable public Factoid address into adr.
type FsAddress ¶
FsAddress is the secret key to a FAAddress.
func GenerateFsAddress ¶
GenerateFsAddress generates a secure random private Factoid address using crypto/rand.Random as the source of randomness.
func NewFsAddress ¶
NewFsAddress attempts to parse adrStr into a new FsAddress.
func (FsAddress) GetBalance ¶
GetBalance queries factomd for the Factoid Balance for adr.
func (FsAddress) GetPrivateAddress ¶
func (adr FsAddress) GetPrivateAddress(_ *Client) (PrivateAddress, error)
GetPrivateAddress returns adr as a PrivateAddress.
func (FsAddress) MarshalJSON ¶
MarshalJSON encodes adr as a JSON string using adr.String().
func (FsAddress) PrefixBytes ¶
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{0x64, 0x78}.
func (FsAddress) PrefixString ¶
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) PublicAddress ¶
PublicAddress returns the FAAddress corresponding to adr as an Address.
func (FsAddress) String ¶
String encodes adr into its human readable form: a base58check string with adr.PrefixBytes().
func (*FsAddress) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON 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 uint64 `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 uint64 `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 uint64 `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 uint64 `json:"entryheight"`
}
Heights contains all of the distinct heights for a factomd node and the Factom network.
type ID1Key ¶
ID1Key is the id1 public key for an identity.
func (ID1Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (ID1Key) PrefixBytes ¶
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 ¶
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) Scan ¶
Scan implements sql.Scanner for key using Bytes32.Scan. The ID1Key type is not encoded and is assumed.
func (ID1Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID1Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable id1 key into key.
type ID2Key ¶
ID2Key is the id2 public key for an identity.
func (ID2Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (ID2Key) PrefixBytes ¶
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 ¶
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) Scan ¶
Scan implements sql.Scanner for key using Bytes32.Scan. The ID2Key type is not encoded and is assumed.
func (ID2Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID2Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable id2 key into key.
type ID3Key ¶
ID3Key is the id3 public key for an identity.
func (ID3Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (ID3Key) PrefixBytes ¶
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 ¶
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) Scan ¶
Scan implements sql.Scanner for key using Bytes32.Scan. The ID3Key type is not encoded and is assumed.
func (ID3Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID3Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable id3 key into key.
type ID4Key ¶
ID4Key is the id4 public key for an identity.
func (ID4Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (ID4Key) PrefixBytes ¶
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 ¶
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) Scan ¶
Scan implements sql.Scanner for key using Bytes32.Scan. The ID4Key type is not encoded and is assumed.
func (ID4Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID4Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable id4 key into key.
type IDKey ¶
type IDKey interface {
// PrefixBytes returns the prefix bytes for the key.
PrefixBytes() []byte
// PrefixString returns the encoded prefix string for the key.
PrefixString() string
// String encodes the key to a base58check string with the appropriate
// prefix.
String() string
// Payload returns the key as a byte array.
Payload() [sha256.Size]byte
// RCDHash returns the RCDHash as a byte array. For IDxKeys, this is
// identical to Payload. For SKxKeys the RCDHash is computed.
RCDHash() [sha256.Size]byte
// IDKey returns the corresponding IDxKey in an IDKey interface.
// IDxKeys return themselves. Private SKxKeys compute the
// corresponding IDxKey.
IDKey() IDKey
}
IDKey is the interface implemented by the four ID and SK Key types.
type Identity ¶
Identity represents the Token Issuer's Identity Chain and the public ID1Key.
func NewIdentity ¶
NewIdentity initializes an Identity with the given chainID.
func (Identity) IsPopulated ¶
IsPopulated returns true if the Identity has been populated with an ID1Key.
type PrivateAddress ¶
type PrivateAddress interface {
Address
// PrivateKey returns the ed25519.PrivateKey which can be used for
// signing data.
PrivateKey() ed25519.PrivateKey
// PublicKey returns the ed25519.PublicKey which can be used for
// verifying signatures.
PublicKey() ed25519.PublicKey
}
PrivateAddress is the interface implemented by the two private address types: FsAddress, and EsAddress.
func NewPrivateAddress ¶
func NewPrivateAddress(adrStr string) (PrivateAddress, error)
NewPrivateAddress parses adrStr and returns the correct address type as a PrivateAddress interface. If adrStr is not a private address then an "invalid prefix" error is returned. This is useful when the address type isn't known prior to parsing adrStr, but must be a private address. If the address type is known ahead of time, it is generally better to just use the appropriate concrete type.
type RCDPrivateKey ¶
type RCDPrivateKey interface {
// RCD returns the RCD corresponding to the private key.
RCD() []byte
// PrivateKey returns the ed25519.PrivateKey which can be used for
// signing data.
PrivateKey() ed25519.PrivateKey
// PublicKey returns the ed25519.PublicKey which can be used for
// verifying signatures.
PublicKey() ed25519.PublicKey
}
RCDPrivateKey is the interface implemented by the four SK Key types and the Fs Address type.
type SK1Key ¶
SK1Key is the sk1 secret key for an identity.
func GenerateSK1Key ¶
GenerateSK1Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK1Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (SK1Key) PrefixBytes ¶
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 ¶
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) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK1Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable sk1 key into key.
type SK2Key ¶
SK2Key is the sk2 secret key for an identity.
func GenerateSK2Key ¶
GenerateSK2Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK2Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (SK2Key) PrefixBytes ¶
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 ¶
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) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK2Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable sk2 key into key.
type SK3Key ¶
SK3Key is the sk3 secret key for an identity.
func GenerateSK3Key ¶
GenerateSK3Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK3Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (SK3Key) PrefixBytes ¶
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 ¶
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) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK3Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable sk3 key into key.
type SK4Key ¶
SK4Key is the sk4 secret key for an identity.
func GenerateSK4Key ¶
GenerateSK4Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK4Key) MarshalJSON ¶
MarshalJSON encodes key as a JSON string using key.String().
func (SK4Key) PrefixBytes ¶
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 ¶
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) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK4Key) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON string with a human readable sk4 key into key.
type SKKey ¶
type SKKey interface {
IDKey
// SKKey returns the SKKey interface. IDxKeys return themselves.
// Private SKxKeys compute the corresponding IDxKey.
SKKey() SKKey
// RCD returns the RCD corresponding to the private key.
RCD() []byte
// PrivateKey returns the ed25519.PrivateKey which can be used for
// signing data.
PrivateKey() ed25519.PrivateKey
// PublicKey returns the ed25519.PublicKey which can be used for
// verifying signatures.
PublicKey() ed25519.PublicKey
}
SKKey is the interface implemented by the four SK Key types.
type Time ¶
Time embeds time.Time and implements the json.Unmarshaler interface for correctly parsing the timestamps returned by the factomd JSON RPC API.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON unmarshals a string containing a Unix seconds since epoch timestamp.