You might want to familiarise yourself with some Mochimo codebase lingo...
Transaction Buffer
The entire TX object used for communication between nodes
Transaction Data
The data contained within the Transaction Buffer (usually a Network Transaction)
Capability Bits
The bits of a byte after the version byte of a transaction buffer, indicating a
Node's capabilities on the network
Operation Codes
Number codes used during socket connection to request certain operations with
the Mochimo Network
Transaction Address
The full quantum resistant address used by the Mochimo Cryptocurrency Network
Source/Destination/Change Addresses
Due to the security concern of using "One Time Signatures" (see WOTS+), a
standard transaction consists of 3 addressable parts:
- The source address; the address where funds are transferred from,
- The destination address; the address where funds are transferred to (the amount of funds that are transferred to this address is determined by the value of an associated "sendtotal" property), and
- The change address; the address where the remaining funds that weren't sent to the destination address are received (the amount of funds that are transferred to this address is determined by the value of an associated "changetotal" property)
With that out of the way, let's begin...
- Mochimo
Initialize integration with the Mochimo Cryptocurrency Network.
- LEntry ⇐
Uint8Array LEntry class objects are only accessible via the Block class.
The Ledger Entry class is a Uint8Array of static size containing a full WOTS+ address and a 64-bit balance.- TXEntry ⇐
Uint8Array The Transaction class is a Uint8Array of static size containing all elements required for inclusion in a valid Mochimo Block or TX Object. TXEntry is typically used for reading transactions from a Mochimo Block.
- BlockTrailer ⇐
Uint8Array The BlockTrailer class is a Uint8Array of static size containing the trailer elements appended to a valid Mochimo Block. BlockTrailers can be joined together in series to create a historically verifiable chain known as a Tfile.
- Block ⇐
Uint8Array The Block class is a Uint8Array consisting of 3 main parts; a block header, block contents, and a block trailer. The contents of a block can be either transactions (for a normal block), ledger entries (for a neogenesis block), or empty (for a pseudo block).
- Tfile ⇐
Uint8Array The Tfile class is a Uint8Array desgined to contain all or part of the historically verifiable chain known as a Tfile in the Mochimo ecosystem.
- Node
The Node class is primarily used to communicate with network peers connected to the Mochimo Cryptocurrency Network.
- Tx ⇐
Uint8Array The Tx class is a Uint8Array of static size representing the Transaction Buffer used to communicate with network peers.
- Wots
The Wots class provides utility functions to generate, sign and verify WOTS+ addresses used by the Mochimo Network Blockchain, as well as a few pointer constants for positions of intra-address components.
Initialize integration with the Mochimo Cryptocurrency Network.
Example
const Mochimo = require('mochimo');Mochimo~constants : Object
Mochimo constants, used throughout the ecosystem of Mochimo protocols.
Kind: inner constant of Mochimo
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| INVALID_SOCKET | Number |
-1 |
Expired/Unused Socket |
| VETIMEOUT | Number |
-1 |
Return status for a timeout |
| VEOK | Number |
0 |
Return status for no issues |
| VERROR | Number |
1 |
Return status for a failure |
| VEBAD | Number |
2 |
Return status for a failure and possible malice |
| C_PUSH | Number |
1 |
Capability bit indicating the ability to push Candidate Blocks, used primarily by the Mochimo Windows Headless Miner (b00000001) |
| C_WALLET | Number |
2 |
Capability bit indicating the operation of a wallet (b00000010) |
| C_SANCTUARY | Number |
4 |
Capability bit indicating an activation of the Sanctuary Protocol (b00000100) |
| C_MFEE | Number |
8 |
Capability bit indicating the desired Fee change outcome of the Sanctuary Protocol (b00001000) |
| C_LOGGING | Number |
16 |
Capability bit indicating the availability of Logging (b00010000) |
| OP_NULL | Number |
0 |
Operation code Null; Not used but usually indicating a lack of socket initialization during a transaction of data |
| OP_HELLO | Number |
1 |
Operation code Hello; Used as a request code to initiate the first step of a Mochimo 3-way handshake |
| OP_HELLO_ACK | Number |
2 |
Operation code Hello Acknowledgement; Used as a return code to indicate the second step of a Mochimo 3-way handshake |
| OP_TX | Number |
3 |
Operation code Transaction; Used as request code to send a signed transaction to a Node for distribution across the Mochimo Network |
| OP_FOUND | Number |
4 |
Operation code Block Found; Used as a network alert code indicating the existence of a new block update available for download. To obtain the block update, a new socket connection and opcode must be used |
| OP_GETBLOCK | Number |
5 |
Operation code Get Block; Used as a request code to get/download a block from a Node. This operation can take some time if requesting a neogensis block, due to network speed and ledger file size |
| OP_GETIPL | Number |
6 |
Operation code Get IP List; Used as a request code when requesting a Node's peer list |
| OP_SEND_BL | Number |
7 |
Operation code Send Block; Used as a return code for validation when sending a block, usually after an OP_GETBLOCK is received |
| OP_SEND_IP | Number |
8 |
Operation code Send IP List; Used as a validation code when sending a peer list, usually after an OP_GETIPL is received |
| OP_BUSY | Number |
9 |
Operation code Busy; Used as a return code to indicate that a Node is currently busy and unable to process a request |
| OP_NACK | Number |
10 |
Operation code No Acknowledgement operation code? The workings of this code is currently unknown, as it is unused throughout the codebase. I'm sure if I was to ask of it's original purpose I would get a clear and concise response. For now, this obnoxiously unhelpful description will serve as one of my adequate systems of unusual humor |
| OP_GET_TFILE | Number |
11 |
Operation code Get Trailer File; Used as a request code to get/download a Node's entire Tfile. This operation can take some time, due to network speed and Tfile size |
| OP_BALANCE | Number |
12 |
Operation code Address Balance; Used as a request code when requesting the balance of a Mochimo Address |
| OP_SEND_BAL | Number |
13 |
Operation code Send Address Balance; Used as a return code for validation when sending the balance of a Mochimo Address |
| OP_RESOLVE | Number |
14 |
Operation code Resolve Tag; Used as a request/return code when requesting the Mochimo Address registered to a Mochimo Tag |
| OP_GET_CBLOCK | Number |
15 |
Operation code Get Candidate Block; Used as a request code to get/download a candidate block from a Node. Candidate blocks include all recent transactions for a Windows Headless Miner to find a solution |
| OP_MBLOCK | Number |
16 |
Operation code Mined Block; Used as a network alert code indicating that a Windows Headless Miner has found a solution to a candidate block it received and requires assistance distributing the block update. Unlike OP_FOUND, the socket connection stays open to continue sending the block update along with OP_SEND_BL |
| OP_HASH | Number |
17 |
Operation code Block Hash; Used as a request/return code when requesting the block hash of a specified block number |
| OP_TF | Number |
18 |
Operation code Partial Trailer File; Used as a request code to get/download a section of a Trailer File. Requests can be up to 1000 trailers in size, and the operation is validated with an OP_SEND_BL return code |
| OP_IDENTIFY | Number |
19 |
Operation code Identify; Used as a request/return code to identify which nodes have activated the Sanctuary protocol and obtain their Santuary specifications |
Example
const Mochimo = require('mochimo');
console.log(`The value of VEOK is available at ${Mochimo.constants.VEOK}`);
console.log(`... and is also available at ${Mochimo.VEOK}`);Mochimo~getBalance(peer, address, isTag) ⇒ Promise
Download a ledger entry from a network peer.
Kind: inner method of Mochimo
Fulfil: ?(external:Lentry) When the address or tag is found, promise
resolves a new Mochimo.Lentry() object containing the ledger entry data.
When the address or tag is NOT found, promise resolves null.
Reject: Error Error indicating the failure
| Param | Type | Description |
|---|---|---|
| peer | String |
IPv4 address of network peer |
| address | String | Uint8Array |
A Mochimo WOTS+ address or tagged address to search the ledger for. |
| isTag | Boolean |
Indicates that the address is a tag. |
Example
const Mochimo = require('mochimo');
const taggedAddress = '696c6c616d616e7564690000';
// request ledger entry balance and print results
Mochimo.getBalance('127.0.0.1', taggedAddress, true).then(lentry => {
if (lentry === null) console.error('address not found in ledger');
else {
console.log('Full address:', lentry.address);
console.log('Address tag:', lentry.tag);
console.log('Balance:', lentry.balance);
}
}).catch(console.error);Mochimo~getBlock(peer, [bnum]) ⇒ Promise
Download a Mochimo Block file from a network peer.
Kind: inner method of Mochimo
Fulfil: Block A new Mochimo.Block() object containing the
downloaded block data
Reject: Error Error indicating the failure
| Param | Type | Description |
|---|---|---|
| peer | String |
IPv4 address of network peer |
| [bnum] | BigInt | Number |
Blockchain number to download Omit parameter to get peer's current block |
Example
const fsp = require('fs').promises;
const Mochimo = require('mochimo');
// download and write block data to file, else write error to stderr
Mochimo.getBlock('127.0.0.1', 123456).then(block => {
return fsp.writeFile('000000000001e240.bc', block);
}).catch(console.error);Mochimo~getHash(peer, [bnum]) ⇒ Promise
Download a Mochimo Block Hash from a network peer.
Kind: inner method of Mochimo
Fulfil: String The block hash represented as a string
Reject: Error Error indicating the failure
| Param | Type | Description |
|---|---|---|
| peer | String |
IPv4 address of network peer |
| [bnum] | BigInt | Number |
Blockchain number of desired hash Omit parameter to get peer's current block |
Example
const Mochimo = require('mochimo');
// download and write block data to file, else write error to stderr
Mochimo.getBlock('127.0.0.1', 0).then(hash => {
console.log('Genesis block hash: ' + hash);
}).catch(console.error);Mochimo~getNetworkPeers(startPeers) ⇒ Promise
Get a list of available (non-busy) Mochimo Network peers.
Kind: inner method of Mochimo
Fulfil: Array.<String> An array of current network peers
Reject: Error Error indicating a failure
| Param | Type | Description |
|---|---|---|
| startPeers | Array.<String> | String |
Either a single, or an array of, IPv4 addresses to network peers |
Example
const Mochimo = require('mochimo');
// get list of peers and write to stdout, else write error to stderr
Mochimo.getNetworkPeers('127.0.0.1').then((list) => {
console.log('Found %d Network Peers:\n%O', value.length, value));
}).catch(console.error);Mochimo~getPeerlist(peer) ⇒ Promise
Download a peerlist from a network peer.
Kind: inner method of Mochimo
Fulfil: Array.<String> Array of peers as IPv4 strings
Reject: Error Error indicating a failure
| Param | Type | Description |
|---|---|---|
| peer | String |
IPv4 address of network peer |
Example
const Mochimo = require('mochimo');
// request peerlist from network peer
Mochimo.getPeerlist('127.0.0.1').then(peerlist => {
console.log('Peerlist: %O', peerlist);
}).catch(console.error);Mochimo~getTfile(peer, [bnum], [count]) ⇒ Promise
Download partial or full Trailer file from a network peer.
Kind: inner method of Mochimo
Fulfil: Tfile A new Mochimo.Tfile() object containing the
downloaded trailer data
Reject: Error Error indicating a failure
| Param | Type | Description |
|---|---|---|
| peer | String |
IPv4 address of network peer |
| [bnum] | Number |
The first trailer to download (max 32bit number) Omit parameter to download full trailer file (tfile.dat) |
| [count] | Number |
The number of trailers to download (max 1000) Omit parameter to download one (1) trailer |
Example
const fsp = require('fs').promises;
const Mochimo = require('mochimo');
// download and write partial tfile to file, else write error to stderr
Mochimo.getTfile('127.0.0.1', 0, 24).then(tfile => {
return fsp.writeFile('partialt_file.dat', tfile);
}).catch(console.error);LEntry ⇐ Uint8Array
LEntry class objects are only accessible via the Block
class.
The Ledger Entry class is a Uint8Array of static size containing
a full WOTS+ address and a 64-bit balance.
Kind: global class
Extends: Uint8Array
Create a new Ledger Entry for the handling of an address-balance pair.
| Param | Type | Default | Description |
|---|---|---|---|
| [input] | Buffer | ArrayBuffer |
An existing ledger entry or wots address (as a Buffer only). When input is a Buffer, a new underyling Uint8Array is created and set with the contents of input.When input is an ArrayBuffer, a new "view" of the ArrayBuffer is created. |
|
| [byteOffset] | Number |
0 |
The byte offset of the ledger entry view, when input is an ArrayBuffer.Does nothing when input is not an ArrayBuffer. |
lentry.address : String
The full 2208 byte Mochimo address, in hexadecimal format
Kind: instance property of LEntry
Default: "0000... <4416 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 4416 hexadecimal character String or 2208 byte Array.
lentry.balance : BigInt
The associated balance, in nanoMochimo
Kind: instance property of LEntry
Default: 0n
Throws:
TypeErrorwhen set value cannot be converted to the original type
lentry.tag : String
The tag attached to the ledger address, in hexadecimal format
Kind: instance property of LEntry
Default: "0000... <24 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 24 hexadecimal character String or 12 byte Array.
lentry.toJSON() ⇒ Object
Kind: instance method of LEntry
Returns: Object - LEntry class object, in JSON format
Properties
| Name | Type | Description |
|---|---|---|
| address | Number |
refer to LEntry class properties |
| balance | Number |
|
| tag | Number |
LEntry.length : Number
Breakdown:
- WOTS+ address, 2208 bytes
- Balance (64bit), 8 bytes
Kind: static property of LEntry
Constant_value: 2216
LEntry.ADDRESSp : Number
FOR ADVANCED USE ONLY!
Array pointer to address
Kind: static property of LEntry
Constant_value: 0
LEntry.TAGp : Number
FOR ADVANCED USE ONLY!
Array pointer to tag
Kind: static property of LEntry
Constant_value: 2196
LEntry.BALANCEp : Number
FOR ADVANCED USE ONLY!
Array pointer to balance
Kind: static property of LEntry
Constant_value: 2208
TXEntry ⇐ Uint8Array
The Transaction class is a Uint8Array of static size containing all elements required for inclusion in a valid Mochimo Block or TX Object. TXEntry is typically used for reading transactions from a Mochimo Block.
Kind: global class
Extends: Uint8Array
- TXEntry ⇐
Uint8Array- new TXEntry([input], [byteOffset])
- instance
- static
Create a new Transaction Entry.
| Param | Type | Default | Description |
|---|---|---|---|
| [input] | Buffer | ArrayBuffer |
An existing transaction entry. When input is a Buffer, a new underyling Uint8Array is created and set with the contents of input.When input is an ArrayBuffer, a new "view" of the ArrayBuffer is created. |
|
| [byteOffset] | Number |
0 |
The byte offset of the transaction entry view, when input is an ArrayBuffer. Does nothing when input is not an ArrayBuffer. |
txentry.srcaddr : String
The source address, in hexadecimal format
Kind: instance property of TXEntry
txentry.srctag : String
The tag attached to the source address, in hexadecimal format
Kind: instance property of TXEntry
txentry.dstaddr : String
The destination address, in hexadecimal format
Kind: instance property of TXEntry
txentry.dsttag : String
The tag attached to the destination address, in hexadecimal format
Kind: instance property of TXEntry
txentry.chgaddr : String
The change address, in hexadecimal format
Kind: instance property of TXEntry
txentry.chgtag : String
The tag attached to the change address, in hexadecimal format
Kind: instance property of TXEntry
txentry.sendtotal : BigInt
The transaction send amount, in nanoMochimo
Kind: instance property of TXEntry
txentry.changetotal : BigInt
The transaction change amount, in nanoMochimo
Kind: instance property of TXEntry
txentry.txfee : BigInt
The transaction fee, in nanoMochimo
Kind: instance property of TXEntry
txentry.txsig : String
The transaction signature, in hexadecimal format
Kind: instance property of TXEntry
txentry.txid : String
The transaction id, in hexadecimal format
Kind: instance property of TXEntry
txentry.toJSON(minify) ⇒ Object
Kind: instance method of TXEntry
Returns: Object - TXEntry class object, in JSON format
| Param | Type | Description |
|---|---|---|
| minify | Boolean |
Limits properties to 64 characters long |
Properties
| Name | Type | Description |
|---|---|---|
| srcaddr | Number |
refer to TXEntry class properties |
| srctag | Number |
|
| dstaddr | Number |
|
| dsttag | Number |
|
| chgaddr | Number |
|
| chgtag | Number |
|
| sendtotal | Number |
|
| changetotal | Number |
|
| txfee | Number |
|
| txsig | Number |
|
| txid | Number |
TXEntry.SRCADDRp : Number
FOR ADVANCED USE ONLY!
Array pointer to srcaddr
Kind: static property of TXEntry
Constant_value: 0
TXEntry.DSTADDRp : Number
FOR ADVANCED USE ONLY!
Array pointer to dstaddr
Kind: static property of TXEntry
Constant_value: 2208
TXEntry.CHGADDRp : Number
FOR ADVANCED USE ONLY!
Array pointer to chgaddr
Kind: static property of TXEntry
Constant_value: 4416
TXEntry.SENDTOTALp : Number
FOR ADVANCED USE ONLY!
Array pointer to sendtotal
Kind: static property of TXEntry
Constant_value: 6624
TXEntry.CHANGETOTALp : Number
FOR ADVANCED USE ONLY!
Array pointer to changetotal
Kind: static property of TXEntry
Constant_value: 6632
TXEntry.TXFEEp : Number
FOR ADVANCED USE ONLY!
Array pointer to txfee
Kind: static property of TXEntry
Constant_value: 6640
TXEntry.TXSIGp : Number
FOR ADVANCED USE ONLY!
Array pointer to txsig
Kind: static property of TXEntry
Constant_value: 6648
TXEntry.TXIDp : Number
FOR ADVANCED USE ONLY!
Array pointer to txid
Kind: static property of TXEntry
Constant_value: 8792
TXEntry.length : Number
Breakdown:
- 3x WOTS+ (inc. tag), 6624 bytes
- 3x Amounts (64bit), 24 bytes
- 1x Signature (WOTS+), 2144 bytes
- 1x ID Hash (sha256), 32 bytes
Kind: static property of TXEntry
Constant_value: 8824
BlockTrailer ⇐ Uint8Array
The BlockTrailer class is a Uint8Array of static size containing the trailer elements appended to a valid Mochimo Block. BlockTrailers can be joined together in series to create a historically verifiable chain known as a Tfile.
Kind: global class
Extends: Uint8Array
- BlockTrailer ⇐
Uint8Array- new BlockTrailer([input], [byteOffset])
- instance
- static
Create a new Block Trailer.
| Param | Type | Default | Description |
|---|---|---|---|
| [input] | Buffer | ArrayBuffer |
An existing block trailer. When input is a Buffer, a new underyling Uint8Array is created and set with the contents of input.When input is an ArrayBuffer, a new "view" of the ArrayBuffer is created. |
|
| [byteOffset] | Number |
0 |
The byte offset of the transaction entry view, when input is an ArrayBuffer. Does nothing when input is not an ArrayBuffer. |
blocktrailer.phash : String
The previous block hash, in hexadecimal format
Kind: instance property of BlockTrailer
blocktrailer.bnum : BigInt
The block number
Kind: instance property of BlockTrailer
blocktrailer.mfee : BigInt
The mining fee (a.k.a. transaction fee), in nanoMochimo
Kind: instance property of BlockTrailer
blocktrailer.tcount : Number
The number of transactions
Kind: instance property of BlockTrailer
blocktrailer.time0 : Number
The previous block's solve time (UTC seconds)
Kind: instance property of BlockTrailer
blocktrailer.difficulty : Number
The mining difficulty
Kind: instance property of BlockTrailer
blocktrailer.mroot : String
The merkle root, in hexadecimal format
Kind: instance property of BlockTrailer
blocktrailer.nonce : String
The nonce, in hexadecimal format
Kind: instance property of BlockTrailer
blocktrailer.stime : String
The current block's solve time (UTC seconds)
Kind: instance property of BlockTrailer
blocktrailer.bhash : String
The current block hash, in hexadecimal format
Kind: instance property of BlockTrailer
blocktrailer.toJSON() ⇒ Object
Kind: instance method of BlockTrailer
Returns: Object - BlockTrailer class object, in JSON format
Properties
| Name | Type | Description |
|---|---|---|
| phash | Number |
refer to BlockTrailer class properties |
| bnum | Number |
|
| mfee | Number |
|
| tcount | Number |
|
| time0 | Number |
|
| difficulty | Number |
|
| mroot | Number |
|
| nonce | Number |
|
| stime | Number |
|
| bhash | Number |
BlockTrailer.PHASHp : Number
FOR ADVANCED USE ONLY!
Array pointer to phash
Kind: static property of BlockTrailer
Constant_value: 0
BlockTrailer.BNUMp : Number
FOR ADVANCED USE ONLY!
Array pointer to bnum
Kind: static property of BlockTrailer
Constant_value: 32
BlockTrailer.MFEEp : Number
FOR ADVANCED USE ONLY!
Array pointer to mfee
Kind: static property of BlockTrailer
Constant_value: 40
BlockTrailer.TCOUNTp : Number
FOR ADVANCED USE ONLY!
Array pointer to tcount
Kind: static property of BlockTrailer
Constant_value: 48
BlockTrailer.TIME0p : Number
FOR ADVANCED USE ONLY!
Array pointer to time0
Kind: static property of BlockTrailer
Constant_value: 52
BlockTrailer.DIFFp : Number
FOR ADVANCED USE ONLY!
Array pointer to diff
Kind: static property of BlockTrailer
Constant_value: 56
BlockTrailer.MROOTp : Number
FOR ADVANCED USE ONLY!
Array pointer to mroot
Kind: static property of BlockTrailer
Constant_value: 60
BlockTrailer.NONCEp : Number
FOR ADVANCED USE ONLY!
Array pointer to nonce
Kind: static property of BlockTrailer
Constant_value: 92
BlockTrailer.STIMEp : Number
FOR ADVANCED USE ONLY!
Array pointer to stime
Kind: static property of BlockTrailer
Constant_value: 124
BlockTrailer.BHASHp : Number
FOR ADVANCED USE ONLY!
Array pointer to bhash
Kind: static property of BlockTrailer
Constant_value: 128
BlockTrailer.length : Number
Breakdown:
- 4x Hash (sha256), 128 bytes
- 2x Number (64-bit), 16 bytes
- 4x Number (32-bit), 16 bytes
Kind: static property of BlockTrailer
Constant_value: 160
Block ⇐ Uint8Array
The Block class is a Uint8Array consisting of 3 main parts; a block header, block contents, and a block trailer. The contents of a block can be either transactions (for a normal block), ledger entries (for a neogenesis block), or empty (for a pseudo block).
Kind: global class
Extends: Uint8Array
- Block ⇐
Uint8Array- instance
- .type :
Number - .haiku :
String - .amount :
BigInt - .hdrlen :
Number - .maddr :
String - .mreward :
BigInt - .transactions :
Array.<TXEntry> - .ledger :
Array.<LEntry> - .trailer :
BlockTrailer - .phash :
String - .bnum :
BigInt - .mfee :
BigInt - .tcount :
Number - .time0 :
Number - .difficulty :
Number - .mroot :
String - .nonce :
String - .stime :
Number - .bhash :
String - .toJSON(minify) ⇒
Object - .verifyBlockHash([hash]) ⇒
Boolean
- .type :
- static
- instance
block.type : Number
The block type
Kind: instance property of Block
See
block.haiku : String
The Haiku representation of the blocks nonce.
Kind: instance property of Block
See: Block.nonce
block.amount : BigInt
Amount of Mochimo sent in transactions for a NORMAL block type, or amount of Mochimo stored in ledger entries for a NEOGENESIS block type.
Kind: instance property of Block
block.hdrlen : Number
The block header length
Kind: instance property of Block
Null: when size of block buffer is < 4 bytes
block.maddr : String
The address that receives the mining reward, in hexadecimal format
Kind: instance property of Block
Null: when block type !== Block.NORMAL
See: NORMAL
block.mreward : BigInt
The mining reward, in nanoMochimo
Kind: instance property of Block
Null: when block type !== Block.NORMAL
See: NORMAL
block.transactions : Array.<TXEntry>
An array of transaction entries contained within the block
Kind: instance property of Block
Default: []
block.ledger : Array.<LEntry>
An array of ledger entries contained within the block
Kind: instance property of Block
Default: []
block.trailer : BlockTrailer
A BlockTrailer object associated with the block
Kind: instance property of Block
block.phash : String
Kind: instance property of Block
See: BlockTrailer.phash
block.bnum : BigInt
Kind: instance property of Block
See: BlockTrailer.bnum
block.mfee : BigInt
Kind: instance property of Block
See: BlockTrailer.mfee
block.tcount : Number
Kind: instance property of Block
See: BlockTrailer.tcount
block.time0 : Number
Kind: instance property of Block
See: BlockTrailer.time0
block.difficulty : Number
Kind: instance property of Block
See: BlockTrailer.difficulty
block.mroot : String
Kind: instance property of Block
See: BlockTrailer.mroot
block.nonce : String
Kind: instance property of Block
See: BlockTrailer.nonce
block.stime : Number
Kind: instance property of Block
See: BlockTrailer.stime
block.bhash : String
Kind: instance property of Block
See: BlockTrailer.bhash
block.toJSON(minify) ⇒ Object
Kind: instance method of Block
Returns: Object - Block class object, in JSON format
| Param | Type | Description |
|---|---|---|
| minify | Boolean |
Limits string properties to 64 characters and removes transactions/ledger array. |
Properties
| Name | Type | Description |
|---|---|---|
| type | Number |
The block type as a string |
| size | Number |
The size of the Block in bytes |
| bnum | Number |
refer to Block class properties |
| time0 | Number |
|
| stime | Number |
|
| difficulty | Number |
|
| bhash | Number |
|
| phash | Number |
|
| mroot | Number |
Only available on NORMAL block types |
| nonce | Number |
Only available on NORMAL block types |
| maddr | Number |
Only available on NORMAL block types |
| mreward | Number |
Only available on NORMAL block types |
| mfee | Number |
Only available on NORMAL block types |
| amount | Number |
Only available on NORMAL, GENESIS and NEOGENESIS block types |
| tcount | Number |
Only available on NORMAL block types |
| transactions | Number |
Only available on NORMAL block types |
| lcount | Number |
Only available on GENESIS and NEOGENESIS block types |
| ledger | Number |
*Only available on GENESIS and NEOGENESIS block types |
block.verifyBlockHash([hash]) ⇒ Boolean
Verify the block hash contained within a Block object.
Kind: instance method of Block
Returns: Boolean - Verified status of block hash
| Param | Type | Description |
|---|---|---|
| [hash] | String |
Optional hash to verify against |
Block.INVALID : String
Represents an invalid block type
Kind: static property of Block
Constant_value: "invalid"
Block.NORMAL : String
Represents a normal block type
Kind: static property of Block
Constant_value: "normal"
Block.GENESIS : String
Represents a genesis block type
Kind: static property of Block
Constant_value: "genesis"
Block.NEOGENESIS : String
Represents a neogenesis block type
Kind: static property of Block
Constant_value: "neogenesis"
Block.PSEUDO : String
Represents a pseudo block type
Kind: static property of Block
Constant_value: "pseudo"
Tfile ⇐ Uint8Array
The Tfile class is a Uint8Array desgined to contain all or part of the historically verifiable chain known as a Tfile in the Mochimo ecosystem.
Kind: global class
Extends: Uint8Array
FOR ADVANCED USE ONLY!
Although the Tfile class can be instantiated
directly, it is not recommended.
Instead, consider using
Mochimo.getTfile() to obtain a Tfile
directly from the Mochimo network.
| Param | Type | Description |
|---|---|---|
| bytes | ArrayBuffer | TypedArray |
Tfile data |
| [offset] | Number |
The starting byte of the exposed data |
| [length] | Number |
The length of the exposed data The length will be modified if not a multiple of BlockTrailer.length (160) |
tfile.trailer(index) ⇒ BlockTrailer
Kind: instance method of Tfile
Returns: BlockTrailer - A BlockTrailer object representing trailer
data at the specified index.
| Param | Type | Description |
|---|---|---|
| index | Number |
Index of desired block trailer |
The Node class is primarily used to communicate with network peers connected to the Mochimo Cryptocurrency Network.
Kind: global class
Properties
| Name | Type | Description |
|---|---|---|
| timestamp | Number |
UTC Timestamp (in ms), updated on Node creation, after Socket connection and on Socket data event |
| ip | String |
The IPv4 address used in the peer connection |
| port | Number |
The port number used in the peer connection |
| ping | Number |
The ping (in ms) associated with the peer connection's response to an OP_HELLO request |
| baud | Number |
The baudrate (in bits per sec) associated with the peer connection |
| status | Number |
The status of the peer |
| id1 | Number |
3-way handshake verification ID #1 |
| id2 | Number |
3-way handshake verification ID #2 |
| opcode | Number |
Operation code transmitted in tx |
| tx | Tx |
The last transaction packet received from a peer |
| socket | Socket |
A Socket object that handles communication with the peer |
| data | Uint8Array |
The transaction buffer data |
- Node
- new Node([options])
- instance
- static
FOR ADVANCED USE ONLY!
Although the Node class can be instantiated
directly, it is not recommended.
Instead, consider using the static
function callserver to obtain a Node object.
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | String |
{} |
...see Node.callserver([options]) |
node.toJSON() ⇒ Object
Kind: instance method of Node
Returns: Object - Node class object, in JSON format
Properties
| Name | Type | Description |
|---|---|---|
| timestamp | Number |
|
| ip | String |
refer to Node class properties |
| port | Number |
|
| status | Number |
|
| ping | Number |
present if status is VEOK or VEBAD |
| baud | Number |
present if status is VEOK or VEBAD |
| pversion | Number |
refer to Tx class properties |
| cbits | Number |
|
| network | Number |
|
| cblock | BigInt |
|
| cblockhash | String |
|
| pblockhash | String |
|
| weight | String |
|
| peers | Array.<String> |
present if status is VEOK and tx.opcode wass OP_SEND_IPArray of peers requested with OP_GETIPL |
Node.callserver(options) ⇒ Promise
Connect to a network peer and verify the Mochimo handshake protocol.
Kind: static method of Node
Fulfil: Node A Node object with the result of the connection
attempt to a network peer
Reject: Error Error indicating a failure to create a Node object
or socket connection
| Param | Type | Description |
|---|---|---|
| options | Object |
callserver() options... |
| options.ip | String |
IPv4 address for peer connection |
| options.port | Number |
Port number for peer connection |
| options.opcode | Number |
Operation code to be used upon succesful connection handshake. Executes sendop() on Node |
| options.tx | Object |
Object containing Tx parameters to modify before executing sendop() with options.opcode.Does nothing if options.opcode is not present |
Example
const Mochimo = require('mochimo');
Mochimo.Node.callserver('127.0.0.1').then((node) => {
console.log(`Handshake successful, connected to ${node.ip}`);
}).catch(console.error);Node.sendop(node, opcode) ⇒ Promise
Send an operation code to a connected network peer.
Kind: static method of Node
Fulfil: Node Reference to the Node object that was passed to the
function, updated with the result of the request.
Reject: Error Error indicating and invalid operation code or a
failure during the requested operation
| Param | Type | Description |
|---|---|---|
| node | Node |
Node object with an active socket connection |
| opcode | Number |
Valid operation code |
Example
const Mochimo = require('mochimo');
Mochimo.Node.callserver('127.0.0.1').then((node) => {
console.log(`Handshake successful, connected to ${node.ip}`);
return Mochimo.sendop(node, Mochimo.constants.OP_GETIPL);
}).then((node) => {
console.log(`OP_GETIPL operation result: ${node}`);
}).catch(console.error);Tx ⇐ Uint8Array
The Tx class is a Uint8Array of static size representing the Transaction Buffer used to communicate with network peers.
Kind: global class
Extends: Uint8Array
- Tx ⇐
Uint8Array- new Tx()
- instance
- .blocknum :
BigInt - .cbits :
Number - .cblock :
BigInt - .cblockhash :
String - .changetotal :
BigInt - .chgaddr :
String - .crc16 :
Number - .dstaddr :
String - .id1 :
Number - .id2 :
Number - .len :
Number - .network :
Number - .opcode :
Number - .pblockhash :
String - .pversion :
Number - .sendtotal :
BigInt - .srcaddr :
String - .trailer :
Number - .txfee :
BigInt - .txsig :
String - .weight :
String - .crc16compute() ⇒
Number - .crc16test() ⇒
Boolean - .getTxData() ⇒
Uint8Array - .toJSON() ⇒
Object
- .blocknum :
- static
FOR ADVANCED USE ONLY!
Although the Tx class can be instantiated
directly, it is not recommended.
Instead, consider using the static
functions in the Node class.
tx.blocknum : BigInt
Get/Set the I/O Block number of a Transaction Buffer.
Kind: instance property of Tx
Default: 0n
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.cbits : Number
Get/Set the Capability Bits of a Transaction Buffer.
Kind: instance property of Tx
Default: 0
Throws:
TypeErrorwhen set value cannot be converted to the original type
See: Mochimo.constants
tx.cblock : BigInt
Get/Set the Current Block number of a Transaction Buffer.
Kind: instance property of Tx
Default: 0n
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.cblockhash : String
Get/Set the Current Block Hash of a Transaction Buffer.
Kind: instance property of Tx
Default: "0000... <64 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 64 hexadecimal character String or 32 byte Array.
tx.changetotal : BigInt
Get/Set the Transaction Change Amount of a Transaction Buffer. Value represents nanoMochimo.
Kind: instance property of Tx
Default: 0n
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.chgaddr : String
Get/Set the Transaction Change Address of a Transaction Buffer.
Kind: instance property of Tx
Default: "0000... <4408 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 4416 hexadecimal character String or 2208 byte Array.
tx.crc16 : Number
Get/Set the CRC16 Hash of a Transaction Buffer
*Setting this property is NOT RECOMMENDED
Kind: instance property of Tx
Default: 0
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.dstaddr : String
Get/Set the Transaction Destination Address of a Transaction Buffer.
Kind: instance property of Tx
Default: "0000... <4408 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 4416 hexadecimal character String or 2208 byte Array.
tx.id1 : Number
Get/Set the first ID of a Transaction Buffer.
*Setting this property is NOT RECOMMENDED
Kind: instance property of Tx
Default: 0
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.id2 : Number
Get/Set the second ID of a Transaction Buffer.
*Setting this property is NOT RECOMMENDED
Kind: instance property of Tx
Default: -1
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.len : Number
Get/Set the Transaction Length of a Transaction Buffer.
Kind: instance property of Tx
Default: 0
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.network : Number
Get/Set* the Network Version of a Transaction Buffer.
*Setting this property is NOT RECOMMENDED
Kind: instance property of Tx
Default: 0xABCD
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.opcode : Number
Get/Set the Operation Code of a Transaction Buffer.
Kind: instance property of Tx
Default: OP_NULL
Throws:
TypeErrorwhen set value cannot be converted to the original type
See: Mochimo.constants
tx.pblockhash : String
Get/Set the Previous Block Hash of a Transaction Buffer.
Kind: instance property of Tx
Default: "0000... <64 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 64 hexadecimal character String or 32 byte Array.
tx.pversion : Number
Get/Set the Protocol Version of a Transaction Buffer.
Kind: instance property of Tx
Default: 4
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.sendtotal : BigInt
Get/Set the Transaction Send Amount of a Transaction Buffer. Value represents nanoMochimo.
Kind: instance property of Tx
Default: 0n
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.srcaddr : String
Get/Set the Transaction Source Address of a Transaction Buffer.
Kind: instance property of Tx
Default: "0000... <4408 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 4416 hexadecimal character String or 2208 byte Array.
tx.trailer : Number
Get/Set the Trailer of a Transaction Buffer.
*Setting this property is NOT RECOMMENDED
Kind: instance property of Tx
Default: 0
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.txfee : BigInt
Get/Set the Transaction Fee Amount of a Transaction Buffer. Value represents nanoMochimo.
Kind: instance property of Tx
Default: 0n
Throws:
TypeErrorwhen set value cannot be converted to the original type
tx.txsig : String
Get/Set the Transaction Signature of a Transaction Buffer.
Kind: instance property of Tx
Default: 0n
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 4288 hexadecimal character String or 2144 byte Array.
tx.weight : String
Get/Set the Blockchain Weight of a Transaction Buffer.
Kind: instance property of Tx
Default: "0... <up to 64 characters>"
Throws:
TypeErrorwhen set an invalid data type*
*Valid data types are hexadecimal String, Array or TypedArray.TypeErrorwhen set a value of invalid length*
*Must be 1-64 hexadecimal character String or 1-32 byte Array.
tx.crc16compute() ⇒ Number
Perform a CRC16 hash on 8916 bytes of the underlying transaction buffer.
This function was ported directly from the Mochimo Codebase
crc16.c file
Kind: instance method of Tx
Returns: Number - The CRC16 hash value (16 bit unsigned)
tx.crc16test() ⇒ Boolean
Validate the CRC16 hash value of the Tx this function is called.
Kind: instance method of Tx
Returns: Boolean - Result of validation
tx.getTxData() ⇒ Uint8Array
Obtain the Transaction Data of a Transaction Buffer (Tx) in a new typed array (with a new underlying buffer).
Kind: instance method of Tx
tx.toJSON() ⇒ Object
Kind: instance method of Tx
Returns: Object - Tx class object, in JSON format
Properties
| Name | Type | Description |
|---|---|---|
| pversion | Number |
refer to Tx class properties |
| cbits | Number |
|
| network | Number |
|
| id1 | Number |
|
| id2 | Number |
|
| opcode | Number |
|
| cblock | BigInt |
|
| blocknum | BigInt |
|
| cblockhash | String |
|
| pblockhash | String |
|
| weight | String |
|
| len | Number |
|
| data | Uint8Array |
present only if opcode != OP_TX |
| srcaddr | Uint8Array |
present only if opcode is OP_TX |
| dstaddr | Uint8Array |
present only if opcode is OP_TX |
| chgaddr | Uint8Array |
present only if opcode is OP_TX |
| sendtotal | BigInt |
present only if opcode is OP_TX |
| changetotal | BigInt |
present only if opcode is OP_TX |
| txfee | BigInt |
present only if opcode is OP_TX |
| txsig | Uint8Array |
present only if opcode is OP_TX |
| crc16 | Number |
|
| trailer | Number |
Tx.length : Number
Breakdown:
- 2x Bytes (8bit), 2 bytes
- 6x Words (16bit), 12 bytes
- 2x Blocknumbers (64bit), 16bytes
- 3x WOTS+ (inc. tag), 6624 bytes
- 3x Amounts (64bit), 24 bytes
- 1x Signature (WOTS+), 2144 bytes
- 3x Hashes (sha256), 96 bytes
Kind: static property of Tx
Constant_value: 8920
The Wots class provides utility functions to generate, sign and verify WOTS+ addresses used by the Mochimo Network Blockchain, as well as a few pointer constants for positions of intra-address components.
Kind: global class
Wots.ADDRp : Number
Pointer to the ADDR portion of a WOTS+ address
Kind: static property of Wots
Constant_value: 2176
Wots.PUBSEEDp : Number
Pointer to the Public Seed portion of a WOTS+ address
Kind: static property of Wots
Constant_value: 2144
Wots.SIGLEN : Number
The byte length of a WOTS+ Signature
Kind: static property of Wots
Constant_value: 2144
Wots.generate([seed]) ⇒ Object
Generate a WOTS+ address and secret pair, with or without a seed.
Kind: static method of Wots
Returns: Object - Object.address: The generated WOTS+ address,
Object.secret: The secret key associated with the address
| Param | Type | Description |
|---|---|---|
| [seed] | Uint8Array |
Array of binary data (preferably random) If no seed is supplied, a 32-byte CSPRNG seed will be provided. |
Example
example file
const { Wots } = require('mochimo');
const { randomBytes } = require('crypto');
const wots = Wots.generate(randomBytes(32));
console.log('WOTS+ address:', Buffer.from(wots.address).toString('hex'));
console.log('WOTS+ secret:', wots.secret);Wots.pkFromSig(signature, message, pubSeed, addr) ⇒ Uint8Array
Generate* a WOTS+ public address key from a WOTS+ signature.
&astMust have access to signed message, and Public Seed and ADDR
portions of the full WOTS+ address.
Kind: static method of Wots
Returns: Uint8Array - Public key portion of WOTS+ address
Throws:
TypeErrorwhen signature is not 2144 bytes longTypeErrorwhen pubSeed is not 32 bytes longTypeErrorwhen addr is not 32 bytes long
| Param | Type | Description |
|---|---|---|
| signature | Uint8Array |
The WOTS+ signature |
| message | Uint8Array |
The message used to sign |
| pubSeed | Uint8Array |
Public Seed portion of WOTS+ address *32 bytes starting at byte 2144 of WOTS+ address |
| addr | Uint8Array |
ADDR portion of WOTS+ address *32 bytes starting at byte 2176 of WOTS+ address |
Example
const { Wots, constants } = require('mochimo');
const { randomBytes } = require('crypto');
const pkSecret = Wots.generate();
const message = randomBytes(constants.TRANLEN);
const signature = Wots.sign(message, pkSecret.secret);
const pubSeed = pkSecret.address.subarray(Wots.PUBSEEDp, 32);
const addr = pkSecret.address.subarray(Wots.ADDRp, 32);
const pkFromSig = Wots.pkFromSig(signature, message, pubSeed, addr);
console.log(pkFromSig.some((curr, i) => curr !== pkSecret.address[i]
? 'result is different' : 'result is identical');Wots.sign(message, secret) ⇒ Uint8Array
Generate a WOTS+ Signature from a message and secret.
Kind: static method of Wots
Returns: Uint8Array - A WOTS+ Signature
| Param | Type | Description |
|---|---|---|
| message | Uint8Array |
The message to be signed |
| secret | Uint8Array |
A secret* *Must have been generated by Wots.generate() |
Example
const { Wots, TRANLEN } = require('mochimo');
const { randomBytes } = require('crypto');
const pkSecret = Wots.generate();
const message = randomBytes(TRANLEN);
const signature = Wots.sign(message, pkSecret.secret);
console.log('WOTS+ Signature: ' + Buffer.from(signature).toString('hex'));Wots.verify(signature, message, address) ⇒ Boolean
Verify a WOTS+ signature against a known message and WOTS+ address.
Kind: static method of Wots
Returns: Boolean - Verification result
Throws:
TypeErrorwhen signature is not 2144 bytes longTypeErrorwhen address is not 2208 bytes long
| Param | Type | Description |
|---|---|---|
| signature | Uint8Array |
The WOTS+ signature |
| message | Uint8Array |
The message used to sign |
| address | Uint8Array |
The WOTS+ address to verify against the signature |
Example
const { Wots, TXSIGLEN, TRANLEN, TXADDRLEN } = require('mochimo');
const signature = Buffer.alloc(TXSIGLEN); // 2144 byte array
const message = Buffer.alloc(TRANLEN); // 8792 byte array
const address = Buffer.alloc(TXADDRLEN); // 2208 byte array
console.log('WOTS+ signature verification',
Wots.verify(signature, message, address) ? 'valid' : 'not valid');// END OF DOCUMENTATION...