1.4.0
Listen for new Factom Events:
Extends EventEmitter
(FactomCli)
FactomCli instance to be used by the FactomEventEmitter instance to fetch blockchain data.
const { FactomCli, FactomEventEmitter } = require('factom');
const cli = new FactomCli();
// Poll the blockchain every 10s
const emitter = new FactomEventEmitter(cli, { interval: 10000 });
emitter.on('newDirectoryBlock', (directoryBlock) => ...);
emitter.on('newFactoidBlock', (factoidBlock) => ...);
emitter.on('newAdminBlock', (adminBlock) => ...);
emitter.on('newEntryCreditBlock', (entryCreditBlock) => ...);
emitter.on('newChain', (entryBlock) => ...);
// Listen to any transaction involving a given Factoid address
emitter.on('FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC', (transaction) => ...);
// Listen to any new entries in a given chain
emitter.on('4060c0192a421ca121ffff935889ef55a64574a6ef0e69b2b4f8a0ab919b2ca4', (entryBlock) => ...);
// Listen to any pending transactions involving a given Factoid address
emitter.on(FactomEventEmitter.getSubscriptionToken({
eventType: 'newPendingTransaction', topic: 'FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC'
}), (pendingTransaction) => ...);
Main class to read and write data from Factom blockchain.
(Object?)
Options of connection to factomd and factom-walletd.
Name | Description |
---|---|
opts.factomd ConnectionOptions?
|
Options of connection to factomd. |
opts.walletd ConnectionOptions?
|
Options of connection to factom-walletd. |
const cli = new FactomCli({
factomd: {
host: 'api.factomd.net',
port: 443,
protocol: 'https'
},
walletd: {
host: 'localhost',
user: 'paul',
password: 'pass'
}
});
Add an Entry/Chain or a collection of either of those to the Factom blockchain. Performs both commits and reveals.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Name | Description |
---|---|
options.commitTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.revealTimeout number
(default 60 )
|
Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. |
options.concurrency number
(default 200 )
|
Only if the obj argument is an iterable. Limits the number of concurrent Promises adding entries/chains. |
options.skipFundValidation boolean
(default false )
|
Skip the validation that the EC address holds enough Entry Credits to pay the commits. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
(Promise<{txId: string, repeatedCommit: boolean, chainId: string, entryHash: string}> | Promise<Array<{txId: string, repeatedCommit: boolean, chainId: string, entryHash: string}>>)
:
Transaction ID (commit), if it is a repeated commit (
https://docs.factom.com/api#repeated-commit
), chain id and entry hash.
It is an array of such object if the input was an iterable of Entry or Chain.
Add a Chain to the Factom blockchain. Performs both commit and reveal.
(Chain)
Chain to add.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Name | Description |
---|---|
options.commitTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.revealTimeout number
(default 60 )
|
Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. |
options.skipFundValidation boolean
(default false )
|
Skip the validation that the EC address holds enough Entry Credits to pay the commit. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<{txId: string, repeatedCommit: boolean, chainId: string, entryHash: string}>
:
Transaction ID (commit), if it is a repeated commit (
https://docs.factom.com/api#repeated-commit
), chain id and entry hash.
Add a collection of Chains to the Factom blockchain. Performs both commits and reveals.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Name | Description |
---|---|
options.commitTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.revealTimeout number
(default 60 )
|
Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. |
options.concurrency number
(default 200 )
|
Only if the obj argument is an iterable. Limits the number of concurrent Promises adding entries/chains. |
options.skipFundValidation boolean
(default false )
|
Skip the validation that the EC address holds enough Entry Credits to pay the commits. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<Array<{txId: string, repeatedCommit: boolean, chainId: string, entryHash: string}>>
:
Transaction ID (commit), if it is a repeated commit (
https://docs.factom.com/api#repeated-commit
), chain id and entry hash.
Add a collection of Entries to the Factom blockchain. Performs both commits and reveals.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Name | Description |
---|---|
options.commitTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.revealTimeout number
(default 60 )
|
Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. |
options.concurrency number
(default 200 )
|
Only if the obj argument is an iterable. Limits the number of concurrent Promises adding entries/chains. |
options.skipFundValidation boolean
(default false )
|
Skip the validation that the EC address holds enough Entry Credits to pay the commits. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<Array<{txId: string, repeatedCommit: boolean, chainId: string, entryHash: string}>>
:
Transaction ID (commit), if it is a repeated commit (
https://docs.factom.com/api#repeated-commit
), chain id and entry hash.
Add an Entry to the Factom blockchain. Performs both commit and reveal.
(Entry)
Entry to add.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Name | Description |
---|---|
options.commitTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.revealTimeout number
(default 60 )
|
Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. |
options.skipFundValidation boolean
(default false )
|
Skip the validation that the EC address holds enough Entry Credits to pay the commit. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<{txId: string, repeatedCommit: boolean, chainId: string, entryHash: string}>
:
Transaction ID (commit), if it is a repeated commit (
https://docs.factom.com/api#repeated-commit
), chain id and entry hash.
Commit an Entry or a Chain.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Commit options.
Name | Description |
---|---|
options.ackTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<{txId: string, repeatedCommit: boolean}>
:
Transaction ID and if this is a repeated commit (
https://docs.factom.com/api#repeated-commit
). If repeatedCommit is true, txId is undefined.
Commit a Chain.
(Chain)
Chain to commit.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Commit options.
Name | Description |
---|---|
options.ackTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<{txId: string, repeatedCommit: boolean}>
:
Transaction ID and if this is a repeated commit (
https://docs.factom.com/api#repeated-commit
). If repeatedCommit is true, txId is undefined.
Commit an Entry.
(Entry)
Entry to commit.
(string)
Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
(Object?
= {}
)
Commit options.
Name | Description |
---|---|
options.ackTimeout number
(default 60 )
|
Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. |
options.sign function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>)?
|
Signing function. Takes as input the data to sign with the EC public key paying for the commmit and should return its signature as a Buffer or a hex encoded string (or a Promise of those). The returned signature must have been made by the private key corresponding to the ecAddress argument. |
Promise<{txId: string, repeatedCommit: boolean}>
:
Transaction ID and if this is a repeated commit (
https://docs.factom.com/api#repeated-commit
). If repeatedCommit is true, txId is undefined.
Create a transaction to convert Factoids to Entry Credit.
(string)
Private or public Factoid address origin of the funds. If a public address is provided (FA) the corresponding private address must be stored in factom-walletd.
(string)
Public Entry Credit address to receive the ECs.
(number)
Amount of Entry Credit (EC) to purchase.
(number?)
Value to override fees of the transaction (if not specified the library computes the lowest acceptable fee).
Promise<Transaction>
:
Create a single input single output (SISO) Factoid transaction.
(string)
Private or public Factoid address origin of the funds. If a public address is provided (FA) the corresponding private address must be stored in factom-walletd.
(string)
Public Factoid address receiving the funds.
(number)
Amount to transfer in factoshis (10^-8 Factoids).
(number?)
Value to override fees of the transaction (if not specified the library computes the lowest acceptable fee).
Promise<Transaction>
:
Make a direct call to factomd API. See https://docs.factom.com/api#factomd-api.
(string)
Factomd API method name.
(Object?)
The object that the factomd API is expecting.
(Object?)
Request configuration.
Name | Description |
---|---|
requestConfig.timeout number?
|
Timeout in milliseconds for the request. Override the timeout set at the instance level. |
requestConfig.retry Object?
|
Retry strategy. For the detail of the options see https://github.com/tim-kos/node-retry#retrytimeoutsoptions . Override the retry strategy set at the instance level. |
Promise<Object>
:
Factomd API response.
Get an admin block by keyMR or height.
Promise<AdminBlock>
:
Get the head of a given chain.
(string)
Chain ID.
Promise<{keyMR: string, chainInProcessList: boolean}>
:
result - keymr of the head of the chain.
chainInProcessList indicates if there is an Entry Block for that chain currently in the process list.
If this is the case that would indicate that the head of that chain will change at the next block.
Get a directory block by keyMR or height.
Promise<DirectoryBlock>
:
Return latest directory block saved.
Promise<DirectoryBlock>
:
Get entry by hash (returned Entry does not contain an EntryBlockContext and a timestamp). See FactomCli#getEntryWithBlockContext.
(string)
Hash of the entry to query.
Promise<Entry>
:
Entry that does not contain an
EntryBlockContext
and a timestamp).
Get an entry block.
(string)
KeyMR of the entry block.
Promise<EntryBlock>
:
Get an entry credit block by keyMR or height.
Promise<EntryCreditBlock>
:
Get entry by hash with its EntryBlockContext and timestamp. Note that this method is more expensive than FactomCli#getEntry as it also has to retrieve the Entry Block data.
(string)
Hash of the entry to query.
Promise<Entry>
:
Entry with its blockContext and timestamp populated.
Get a Factoid block by keyMR or height.
Promise<FactoidBlock>
:
Return blockchain heights. For the explanation of the different heights see https://docs.factom.com/api#heights.
Promise<{directoryBlockHeight: number, leaderHeight: number, entryBlockHeight: number, entryHeight: number}>
:
Get Factoid transaction by id.
(string)
Transaction id.
Transaction
:
Reveal an Entry or Chain.
(number
= 60
)
Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack.
Promise<{chainId: string, entryHash: string}>
:
Rewind a chain entry by entry (newest to oldest) while a predicate is true.
(string)
Chain to rewind.
(function (Entry))
Predicate of the while loop. Iteration stop if either the predicate is false or the end of the chain has been reached.
(function (Entry))
Function to apply at each iteration.
cli.rewindChainWhile('dab6c095c22ec6db1b0961fdb82d504a95f0a31467bb7df73cc793532b0e9ae3', (entry) => true, function(entry) {
// Do stuff with the entry
})
Send a Factoid transaction. This method will throw if the transaction fees are too low given the current EC rate. Note that by default this method also rejects a transaction over paying the minimum required fees by a factor 10 as it is most likely a user input error. This can be overriden with the force option.
(Transaction)
(Object?)
Name | Description |
---|---|
options.timeout number
(default 60 )
|
Time to wait in seconds for transaction acknowledgment before timing out. If negative value, doesn't wait for ack. |
options.force boolean
(default false )
|
Set to true to bypass the checks of the transaction fee overpay and the minimum EC output amount. |
Promise<string>
:
Transaction ID.
Wait until an acknowlegment is received from the network for a commit.
Promise<string>
:
Status of the commit. See
https://docs.factom.com/api#ack
.
Wait until an acknowlegment is received from the network for a Factoid transaction.
Promise<string>
:
Status of the transaction. See
https://docs.factom.com/api#ack
.
Wait until an acknowlegment is received from the network for a reveal.
(string)
Hash of the revealed entry.
(string)
Chain ID of the revealed entry.
(number
= 60
)
Wait time in seconds.
Promise<string>
:
Status of the reveal. See
https://docs.factom.com/api#ack
.
Make a direct call to factom-walletd API. See https://docs.factom.com/api#factom-walletd-api.
(string)
Walletd API method name.
(Object?)
The object that the walletd API is expecting.
(Object?)
Request configuration.
Name | Description |
---|---|
requestConfig.timeout number?
|
Timeout in milliseconds for the request. Override the timeout set at the instance level. |
requestConfig.retry Object?
|
Retry strategy. For the detail of the options see https://github.com/tim-kos/node-retry#retrytimeoutsoptions . Override the retry strategy set at the instance level. |
Promise<Object>
:
Walletd API response.
Extract the key contained in an address. Cannot be used with public FCT address as those contain a RCD hash and not a key (See addressToRcdHash).
(string)
Any address, except public FCT address.
Buffer
:
Key contained in the address.
Extract the RCD hash from a public FCT address.
(string)
Public FCT address.
Buffer
:
RCD hash.
Class representing an Admin block.
(string)
: Back reference hash.
(string)
: Lookup hash.
(number)
: Directory block height.
(string)
: Back reference hash of previous Admin block.
(number)
: Header expansion size.
(string)
: Header expansion area.
(number)
: Size of the body.
(Object)
: Admin entries. Each entry has its own type (can be identified either by its adminId (number) or its adminCode (string)).
Class to build an Entry
Set block context. This method is used internally by the library to populate a block context, regular users should not have to use this.
(EntryBlockContext)
EntryBuilder
:
EntryBuilder instance.
Set chain ID.
EntryBuilder
:
EntryBuilder instance.
Set content.
(string
= hex
)
Encoding of the content if it is a string.
EntryBuilder
:
EntryBuilder instance.
Add an external ID.
(string
= hex
)
Encoding of the external id if it is a string.
EntryBuilder
:
EntryBuilder instance.
Set the timestamp for the entry commit. If not set the library will use Date.now() as the commit timestamp.
(number)
Timestamp in milliseconds.
EntryBuilder
:
EntryBuilder instance.
Class to build a Transaction.
(Transaction?)
Optional transaction to use to initialize the attributes of the builder.
Build the Transaction.
Transaction
:
Built transaction.
Add an input to the transaction.
(string)
Factoid address.
User should provide a private address (Fs) to allow the signature of the transaction.
If a public address is provided the user will need to provide the RCD and signature using
TransactionBuilder#rcdSignature
.
(number)
Amount in factoshis (10^-8 Factoids).
TransactionBuilder
:
TransactionBuilder instance.
Add an output to the transaction. Both FCT and EC outputs are supported. Please note that in case of an EC output, the amount is still in factoshis, it is not the number of Entry Credits.
(string)
Factoid or Entry Credit public address.
(number)
Amount in factoshis (10^-8 Factoids).
TransactionBuilder
:
TransactionBuilder instance.
Add a RCD and signature to the transaction. This is used only in the case of unsigned transactions (usefull for hardware wallets). RCDs/signatures need to be added in the same order as their corresponding inputs.
TransactionBuilder
:
TransactionBuilder instance.
Set the transaction timestamp. If not set the library will use Date.now() as the transaction timestamp.
(number)
Timestamp in milliseconds.
TransactionBuilder
:
TransactionBuilder instance.
Class representing a Factoid transaction.
(TransactionBuilder)
(TransactionBlockContext?)
(string)
: Transaction ID.
(number)
: Timestamp in milliseconds.
(Array<TransactionAddress>)
: Inputs.
(Array<TransactionAddress>)
: Factoid outputs.
(Array<TransactionAddress>)
: Entry Credit outputs.
(number)
: Total amount of factoshis as input of this transaction.
(number)
: Total amount of factoshis as factoid outputs of this transaction.
(number)
: Total amount of factoshis as entry credit outputs of this transaction.
(number)
: Fees paid in this transaction.
(TransactionBlockContext)
: Block context.
const transaction = Transaction.builder()
.input('Fs2w6VL6cwBqt6SpUyPLvdo9TK834gCr52Y225z8C5aHPAFav36X', 14000000)
.input('Fs2E6iXCLAKDiPqVtfxtuQCKsTe7o6DJFDnht1wST53s4ibtdu9f', 1010000 + fees)
.output('FA3syRxpYEvFFvoN4ZfNRJVQdumLpTK4CMmMUFmKGeqyTNgsg5uH', 5000000)
.output('FA24PAtyZWWVAPm95ZCVpwyY6RYHeCMTiZt2v4VQAY8aBXMUZteF', 10000000)
// Note that the line below is to buy Entry Credits (see the address type) and the amount is in Factoshis like other outputs:
// it is *not* the number of Entry Credits you are purchasing.
.output('EC2UFobcsWom2NvyNDN67Q8eTdpCQvwYe327ZeGTLXbYaZ56e3QR', 10000)
.build()
Transaction builder static factory.
(Transaction?)
Optional transaction to use to initialize the attributes of the builder.
TransactionBuilder
:
A new TransactionBuilder.
Compute the required fees (minimum difference between inputs and outputs amounts) for the transaction (for a given EC rate).
(Object?)
Extra options necessary to compute fees of an unsigned transaction.
number
:
Number of factoshis (10^-8 Factoids) required as fees for this transaction.
Class representing an Entry.
(EntryBuilder)
(Buffer)
: Chain ID.
(Buffer)
: Content.
(number)
: Timestamp in milliseconds for the commit.
(EntryBlockContext)
: Block context. This property is
not
populated when using the method getEntry.
const myEntry = Entry.builder()
.chainId('9107a308f91fd7962fecb321fdadeb37e2ca7d456f1d99d24280136c0afd55f2')
.extId('6d79206578742069642031') // If no encoding parameter is passed as 2nd argument, 'hex' is used as default
.extId('Some external ID', 'utf8')
.content('My new content', 'utf8')
.build();
Entry builder static factory.
(Entry?)
Optional entry to use to initialize the attributes of the builder.
EntryBuilder
:
A new EntryBuilder.
Factomd API client.
Extends BaseCli
(ConnectionOptions?)
Factomd connection options.
Make a call to factomd API. See https://docs.factom.com/api#factomd-api.
(string)
Factomd API method name.
(Object?)
The object that the factomd API is expecting.
(Object?)
Request configuration.
Name | Description |
---|---|
requestConfig.timeout number?
|
Timeout in milliseconds for the request. Override the timeout set at the instance level. |
requestConfig.retry Object?
|
Retry strategy. For the detail of the options see https://github.com/tim-kos/node-retry#retrytimeoutsoptions . Override the retry strategy set at the instance level. |
Promise<Object>
:
Factomd API response.
Walletd API client.
Extends BaseCli
(ConnectionOptions?)
Walletd connection options.
Make a call to factom-walletd API. See https://docs.factom.com/api#factom-walletd-api.
(string)
Walletd API method name.
(Object?)
The object that the walletd API is expecting.
(Object?)
Request configuration.
Name | Description |
---|---|
requestConfig.timeout number?
|
Timeout in milliseconds for the request. Override the timeout set at the instance level. |
requestConfig.retry Object?
|
Retry strategy. For the detail of the options see https://github.com/tim-kos/node-retry#retrytimeoutsoptions . Override the retry strategy set at the instance level. |
Promise<Object>
:
Walletd API response.
Class representing a Chain.
Compose the commit and reveal of a Chain, that can then be used as inputs of the factomd APIs commit-chain
and reveal-chain
.
(Chain)
Chain to compose the commit and reveal of.
(string)
Private Entry Credit address that pays for and sign the commit.
{commit: Buffer, reveal: Buffer}
:
Chain commit and reveal.
Compose the commit of a Chain, that can then be used as input of the factomd API commit-chain
.
Note that if the chain first entry doesn't have a timestamp set the library will use Date.now() as the default for the commit timestamp.
(Chain)
Chain to compose the commit of.
(string)
Private Entry Credit address that pays for and sign the commit.
Buffer
:
Chain commit.
Compose the commit of a Chain using an external signing function.
The commit can then be sent through factomd API commit-chain
.
(Chain)
Chain to compose the commit of.
(string)
Public Entry Credit address that pays for the commit.
(function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>))
Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecPublicAddress argument.
Buffer
:
Chain commit.
Compose the commit and reveal of a Chain using an external signing function for the commit.
The result can then be used as inputs of the factomd APIs commit-chain
and reveal-chain
.
(Chain)
Chain to compose the commit and reveal of.
(string)
Public Entry Credit address that pays for the commit.
(function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>))
Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecPublicAddress argument.
{commit: Buffer, reveal: Buffer}
:
Chain commit and reveal.
Compose the reveal of a Chain, that can then be used as input of the factomd API reveal-chain
.
(Chain)
Chain to compose the reveal of.
Buffer
:
Chain reveal.
Compose the commit and reveal of an Entry, that can then be used as inputs of the factomd APIs commit-entry
and reveal-entry
.
(Entry)
Entry to compose the commit and reveal of.
(string)
Private Entry Credit address that pays for and sign the commit.
{commit: Buffer, reveal: Buffer}
:
Entry commit and reveal.
Compose the commit of an Entry, that can then be used as input of the factomd API commit-entry
.
Note that if the Entry doesn't have a timestamp set the library will use Date.now() as the default for the commit timestamp.
(Entry)
Entry to compose the commit of.
(string)
Private Entry Credit address that pays for and sign the commit.
Buffer
:
Entry commit.
Compose the commit of an Entry delegating the signature.
The commit can then be sent through factomd API commit-entry
.
(Entry)
Entry to compose the commit of.
(string)
Public Entry Credit address that pays for the commit.
(function (Buffer, string): (Buffer | string | Promise<(Buffer | string)>))
Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecPublicAddress argument.
Buffer
:
Entry commit.
Compose the commit and reveal of an Entry using an external signing function.
The result can then be used as inputs of the factomd APIs commit-entry
and reveal-entry
.
(Entry)
Entry to compose the commit and reveal of.
(string)
Public Entry Credit address that pays for the commit.
(function (Buffer, sign): (Buffer | string | Promise<(Buffer | string)>))
Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecPublicAddress argument.
{commit: Buffer, reveal: Buffer}
:
Entry commit and reveal.
Compose the reveal of an Entry, that can then be used as input of the factomd API reveal-entry
.
(Entry)
Entry to compose the reveal of.
Buffer
:
Entry reveal.
Compute the ID of a Chain provided its first entry.
(Entry)
The first entry of the chain.
Buffer
:
Chain ID.
Compute the transaction ID of the Chain commit. The transaction ID is dependent on the timestamp set in the chain first entry. Note that if the timestamp is not set the library uses Date.now() as the default, changing the result of this function if called at different times.
(Chain)
Buffer
:
The transaction id of the Chain commit.
Compute the transaction ID of the Entry commit. The transaction ID is dependent on the timestamp set in the entry. Note that if the timestamp is not set the library uses Date.now() as the default, changing the result of this function if called at different times.
(Entry)
Buffer
:
The transaction id of the Entry commit.
Describe the options of connection to factomd or factom-walletd.
Type: Object
(string?)
: IP or hostname. Default to localhost.
(number?)
: Port. Default to 8088 for factomd and 8089 for walletd.
(string?)
: Path to V2 API. Default to /v2.
(string?)
: Path to debug API. Default to /debug.
(string?)
: User for basic authentication.
(string?)
: Password for basic authentication.
(string?)
: http or https. Default to http.
(number?)
: Specifies the number of milliseconds before any API request times out.
If a request takes longer than
timeout
, the request will be aborted. Default is
0
(no timeout).
(boolean?)
: Set to false to allow connection to a node with a self-signed certificate. Default to true.
(Object?)
: Retry strategy. For the detail of the options see
https://github.com/tim-kos/node-retry#retrytimeoutsoptions
. Default to {retries: 3, factor: 2, minTimeout: 500, maxTimeout: 2000}
const cli = new FactomdCli({
host: '52.202.51.228',
port: 8088,
path: '/',
debugPath: '/debug',
user: 'paul',
password: 'pwd',
protocol: 'https',
rejectUnauthorized: false,
timeout: 5000,
retry: {
retries: 3,
factor: 2,
minTimeout: 500,
maxTimeout: 2000
}
});
Class representing a Directory block.
(string)
: Key Merkel Root.
(number)
: Height.
(string)
: Key Merkel Root of the previous Directory block.
(number)
: UNIX timestamp (seconds).
(string)
: Full hash of the block. Only available when the block is queried by height.
(string)
: Full hash of the previous Directory block. Only available when the block is queried by height.
(string)
: Key Merkle Root of the block body. Only available when the block is queried by height.
(string)
: Reference to the admin block.
(string)
: Reference to the entry credit block.
(string)
: Reference to the factoid block.
Class representing an Entry block.
(string)
: Key Mertle Root.
(string)
: Key Mertle Root of the previous Entry block.
(number)
: Directory block height.
(number)
: UNIX timestamp (seconds).
(string)
: Chain ID.
(number)
: Sequence number of this block relative to that sub chain.
Block context of an Entry.
Type: Object
(number)
: Epoch timestamp (in seconds) of the entry.
(number)
: Directory Block height.
(number)
: Epoch timestamp (in seconds) of the Entry Block.
(number)
: Entry Block sequence number.
(string)
: Entry Block KeyMR.
Class representing an Entry Credit block.
(string)
: Hash of the header.
(string)
: Full hash.
(string)
: Header expansion area.
(string)
: Hash of the body.
(string)
: Hash of the previous Entry Credit block header.
(string)
: Full hash of the previous Entry Credit block.
(number)
: Directory block height.
(number)
: Size of the body.
(number)
: Object count.
Get all the commits for a given minute.
(number)
Minute (between 1 and 10 included)
Array<{version: number, millis: number, entryHash: string, credits: number, ecPublicKey: string, signature: string}>
:
Commits.
Class representing a Factoid block.
(string)
: Key Mertle Root.
(string)
: Merkle Root of the body.
(string)
: Key Merkle Root of the previous Factoid block.
(string)
: Ledger Key Merkle Root.
(string)
: Ledger Key Merkle Root of the previous Factoid block.
(number)
: Entry credit rate.
(number)
: Directory block height.
(Array<Transaction>)
: Array of Factoid transactions part of this block.
Get coinbase transaction of the block.
Transaction
:
Coinbase transaction of the block.
Generate a new random EC address pair (private and public).
{public: string, private: string}
:
Public and private EC addresses.
Generate a new random FCT address pair (private and public).
{public: string, private: string}
:
Public and private FCT addresses.
Get public address corresponding to an address.
(string)
Any address.
string
:
Public address.
Validate that an address is valid (well formed).
(string)
Address to validate
boolean
:
True if the address is valid.
Determine if a given string is a valid FCT chain.
(string)
Chain to validate.
boolean
:
True if the chain is a valid FCT chain.
Validate if an address is a valid EC address (public or private).
(string)
Address to validate.
boolean
:
True if the address is a valid EC address.
Validate if an address is a valid FCT address (public or private).
(string)
Address to validate.
boolean
:
True if the address is a valid FCT address.
Validate if an address is a valid private EC or FCT address.
(string)
Address to validate.
boolean
:
True if the address is a valid private EC or FCT address.
Validate if an address is a valid private EC address.
(string)
Address to validate.
boolean
:
True if the address is a valid private EC address.
Validate if an address is a valid private FCT address.
(string)
Address to validate.
boolean
:
True if the address is a valid private FCT address.
Validate if an address is a valid public EC or FCT address.
(string)
Address to validate.
boolean
:
True if the address is a valid public EC or FCT address.
Validate if an address is a valid public EC address.
(string)
Address to validate.
boolean
:
True if the address is a valid public EC address.
Validate if an address is a valid public FCT address.
(string)
Address to validate.
boolean
:
True if the address is a valid public FCT address.
Build a human readable public EC address from a 32-byte key.
string
:
Public EC address.
Build a human readable public FCT address from a key.
string
:
Public FCT address.
Build a human readable public FCT address from a RCD hash.
string
:
Public FCT address.
Build a human readable private EC address from a 32-byte seed.
string
:
Private EC address.
Build a human readable private FCT address from a 32-byte seed.
string
:
Private FCT address.
Class to hold address and amount of an input/output of a Transaction.
Block context of a Transaction.
Type: Object