Artifact [97c4303b76]

Artifact 97c4303b7622bb91b5d1a275fa932fd9a7093ab2aa7c2b4dad18242c021a2242:

Wiki page [Manual] by rkeene on 2018-07-18 05:22:37.
D 2018-07-18T05:22:37.373
L Manual
U rkeene
W 38317
<table class="head">
  <tr>
    <td class="head-ltitle">NANO(N)</td>
    <td class="head-vol"></td>
    <td class="head-rtitle">NANO(N)</td>
  </tr>
</table>
<div class="manual-text">
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
nano - Tcl bindings for Nano
<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="selflink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<b>nano::</b>
<br/>
<b>address::</b>
<br/>
<b>toPublicKey</b> <i>address</i> ?<b>-hex</b>|<b>-binary</b>?
  ?<b>-verify</b>|<b>-no-verify</b>?

<b>fromPublicKey</b> <i>pubKey</i> ?<b>-xrb</b>|<b>-nano</b>?

<b>fromPrivateKey</b> <i>privateKey</i> ?<b>-xrb</b>|<b>-nano</b>?

<br/>
<b>key::</b>
<br/>
<b>newSeed</b> ?<b>-hex</b>|<b>-binary</b>?

<b>newKey</b> ?<b>-hex</b>|<b>-binary</b>?

<b>fromSeed</b> <i>seed</i> ?<i>index</i>? ?<b>-hex</b>|<b>-binary</b>?

<b>publicKeyFromPrivateKey</b> <i>privateKey</i> ?<b>-hex</b>|<b>-binary</b>?

<br/>
<b>block::</b>
<br/>
<b>json::toBlock</b> <i>blockJSON</i>

<b>json::fromDict</b> <i>blockDict</i>

<b>json::fromBlock</b> <i>blockData</i> ?<b>-xrb</b>|<b>-nano</b>? ?
  <b>-type=</b><i>blockType</i> ? ? <b>-signKey=</b><i>privateKey</i> ?

<b>json::sign</b> <i>blockJSON</i> <i>privateKey</i>
  ?<b>-update</b>|<b>-signature</b> ?<b>-hex</b>|<b>binary</b>??

<b>json::verifySignature</b> <i>blockJSON</i>

<b>json::work</b> <i>blockJSON</i> ?<b>-update</b>|<b>-work</b>
  ?<b>-hex</b>|<b>-binary</b>??

<b>json::validateWork</b> <i>blockJSON</i>

<b>json::filter</b> <i>blockJSON</i>

<b>dict::toBlock</b> <i>blockDict</i>

<b>dict::fromJSON</b> <i>blockJSON</i>

<b>dict::fromBlock</b> <i>blockData</i> ?<b>-xrb</b>|<b>-nano</b>? ?
  <b>-type=</b><i>blockType</i> ? ? <b>-signKey=</b><i>privateKey</i> ?

<b>dict::sign</b> <i>blockDict</i> <i>privateKey</i>
  ?<b>-update</b>|<b>-signature</b> ?<b>-hex</b>|<b>binary</b>??

<b>dict::verifySignature</b> <i>blockDict</i>

<b>dict::work</b> <i>blockDict</i> ?<b>-update</b>|<b>-work</b>
  ?<b>-hex</b>|<b>-binary</b>??

<b>dict::validateWork</b> <i>blockDict</i>

<b>hash</b> <i>blockData</i> ?<b>-hex</b>|<b>-binary</b>?

<b>signBlockHash</b> <i>blockHash</i> <i>privateKey</i>
  ?<b>-hex</b>|<b>-binary</b>?

<b>sign</b> <i>blockData</i> <i>privateKey</i> ?<b>-hex</b>|<b>-binary</b>?

<b>verifyBlockHash</b> <i>blockHash</i> <i>signature</i> <i>publicKey</i>

<b>verify</b> <i>blockData</i> <i>signature</i> <i>publicKey</i>

<b>create::send</b> <i>args</i>

<b>create::receive</b> <i>args</i>

<b>create::setRepresentative</b> <i>args</i>

<br/>
<b>work::</b>
<br/>
<b>fromWorkData</b> <i>blockHashOrPublicKey</i> ?<b>-hex</b>|<b>-binary</b>?

<b>fromBlock</b> <i>blockData</i>

<b>validate</b> <i>workData</i> <i>work</i>

<br/>
<b>account::</b>
<br/>
<b>setFrontier</b> <i>account</i> <i>frontierHash</i> <i>balance</i>
  <i>representative</i>

<b>getFrontier</b> <i>account</i>

<b>getFrontier</b> <i>account</i>
  ?<b>frontierHash</b>|<b>balance</b>|<b>representative</b>?

<b>addPending</b> <i>account</i> <i>blockHash</i> <i>amount</i>

<b>getPending</b> <i>account</i> ?<i>blockHash</i>?

<b>clearPending</b> <i>account</i> ?<i>blockHash</i>?

<b>receive</b> <i>account</i> <i>blockHash</i> <i>privateKey</i>

<b>receiveAllPending</b> <i>account</i> <i>privateKey</i>

<b>send</b> <i>fromAccount</i> <i>toAccount</i> <i>amount</i> <i>privateKey</i>

<b>setRepresentative</b> <i>account</i> <i>representative</i> <i>privateKey</i>

<br/>
<br/>

<h1 class="Sh" title="Sh" id="INTRODUCTION"><a class="selflink" href="#INTRODUCTION">INTRODUCTION</a></h1>
<i>Nano</i> is a low-latency payment platform that requires minimal resources,
  relying on a peer-to-peer network to distribute &quot;blocks&quot;, which are
  cryptographically signed transactions. This package provides bindings for
  interacting with the Nano network from <i>Tcl</i>.

Nano uses Ed25519 with Blake2b as the cryptographic hashing primitive for
  digital signatures, rather than the common construction of Ed25519 with the
  SHA2-512 cryptographic hashing function.

Nano implements a &quot;blockchain&quot;, which is a cryptographic linked-list,
  by identifying every &quot;block&quot; by its cryptographic hash and providing
  a pointer from every block to its predecessor in the &quot;chain&quot; as part
  of the hashed data.

This predecessors is referred to here as the &quot;previous&quot; block. In
  Nano, each account has its own blockchain and they reference each other using
  a data structure referred to as &quot;block lattice&quot;, where the
  individual chains contain blocks that reference blocks in other chains to tie
  them together. The field within blocks that reference other blocks on a
  different blockchain is referred to as either the &quot;link&quot; field or
  &quot;source block hash&quot;.

Each Nano block also encapsulates the full state of the account, containing, at
  a minimum, a tuple of (<i>account</i>, <i>balance</i>, <i>representative</i>,
  <i>previous</i>).

Since Nano blocks are signed by independent actors, who may, for their own gain,
  generate multiple valid blocks referring to the same predecessor
  (<i>previous</i>) block, an arbitration mechanism is employed by the Nano
  network to decide which blocks are valid within a given chain. This
  arbitration mechanism operates on the principles of consensus. Each account
  holder has a stake in the network operating nominally, otherwise the balance
  represented by an account is not useful for a transfer of value. In Nano the
  stake an account has in the network is equal to the account's balance. The
  larger the stake an account has the more incentivized the account-holder is to
  ensure the network is operating nominally and not accepting multiple blocks
  that reference the same predecessor.

Nano utilizes a mechanism called <i>voting</i> to determine which blocks are
  valid and which blocks are not valid. Each stakeholder votes their stake upon
  seeing a new subordinate block (<i>i.e.</i>, a block with a unique
  <i>previous</i> value). Since voting is an active and on-going process that
  occurs on the Nano peer-to-peer network, participants must be online to vote
  their stake. As this is often inconvenient or impossible, stakeholders may
  select another stakeholder to vote their share of the network. This delegate
  is referred to as a <i>representative</i>.

Representatives should be chosen carefully by stakeholders since malicious
  representatives may attempt to gather voting power and destabilize the Nano
  network by altering decisions made by consensus previously.

Nano accounts are referred to by address. A Nano address starts with the prefix
  &quot;<b>nano_</b>&quot; or &quot;<b>xrb_</b>&quot;. A Nano address is
  actually the public portion of a private/public keypair, plus the prefix, and
  a checksum to ensure that no digits are mistyped by users when communicating
  them. Nano public keys are 256-bit keys in the Ed25519 algorithm.

A user may have many accounts. To simplify the process of maintaining the
  private/public keypairs for all the accounts, Nano supports the concept of a
  <i>wallet</i>. A <i>wallet</i> is a conceptual entity that is used to refer to
  a <i>seed</i>, which is a random 256-bit number that can be used to derive
  multiple private/public keypairs from.

Balances in Nano are stored in a 128-bit integer value. There are various units
  for representing the balance, the smallest and base unit is called
  &quot;<i>raw</i>&quot;. The most common unit for users to use is called
  &quot;<i>Nano</i>&quot;, one of which is equal to 1e30 raw.

<h2 class="Ss" title="Ss" id="Addresses"><a class="selflink" href="#Addresses">Addresses</a></h2>
Nano addresses are composed of a prefix (either &quot;<b>nano_</b>&quot; or
  &quot;<b>xrb_</b>&quot;) and 300 bits of base32 encoded data. The 300-bits of
  base32 encoded data produce a string that is 6 characters long using the
  base32 alphabet <b>13456789abcdefghijkmnopqrstuwxyz</b>. The format of these
  300 bits are
<pre>
<div class="Pp"></div>
   struct {
       uint4_t padding = 0000b;
       uint256_t publicKey;
       uint40_t  checksum;
   }
<div class="Pp"></div>
</pre>
The checksum is computed as a 5 byte (40 bit) Blake2b hash of the 256-bit public
  key (in binary format), followed by reversing the bytes.

For example the public key
  <b>DC1512154EB72112B8CC230D7B8C7DD467DA78E4763182D6CAFAADB14855A5E8</b> which
  has a 5-byte Blake2b hash of <b>{0x18, 0x74, 0xA3, 0x46, 0x9C}</b> would be
  encoded as
  <b>0000.DC1512154EB72112B8CC230D7B8C7DD467DA78E4763182D6CAFAADB14855A5E8.9C46A37418</b>
  which when encoded in base32 and the prefix added produces the address
  <b>nano_3q1o4acnxfs34cwerarfhg89uo59ubwgaxjjiddeoyofp767dbhamj5c8x1r</b>.

<h2 class="Ss" title="Ss" id="Network"><a class="selflink" href="#Network">Network</a></h2>
The Nano network consists of two different peer-to-peer networks. One for
  real-time block updates over UDP, and another for bulk ledger updates over TCP
  (<i>bootstrapping</i>). The real-time network is a broadcast style network
  where every message sent over it are relayed to all other nodes.

The customary and default port for the real-time/UDP network is 7075/udp, while
  the default port for the bootstrapping/TCP network is 7075/tcp.

The format of the messages on both networks is the same, however not every type
  of message may be used on either network. The <b>keepalive</b> message type is
  invalid on the TCP (bootstrapping) network and the <b>bulk_pull</b> message
  type is invalid on the UDP (real-time) network. The format of message are an 8
  byte header consisting of:
<pre>
<div class="Pp"></div>
   struct {
       uint8_t magicProtocol = 0x52;
       uint8_t magicNetwork  = 0x41/0x42/0x43;
       uint8_t versionMax;
       uint8_t version;
       uint8_t versionMin;
       uint8_t messageType;
       uint16_t extensions;
   };
<div class="Pp"></div>
</pre>
Where the <b>magicProtocol</b> field must be the value <b>0x52</b> (which is
  ASCII 'R') and the <b>magicNetwork</b> field must be one of <b>0x41</b>,
  <b>0x42</b>, or <b>0x43</b> corresponding to one of the three Nano networks. A
  value of <b>0x41</b> (ASCII 'A') represents the Test network; A value of
  <b>0x42</b> (ASCII 'B') represents the Beta network; A value of <b>0x43</b>
  (ASCII 'C') represents the Main network.

The various version fields control the relaying of the message to nodes running
  various versions of the Nano network protocol (distinct from the Nano
  reference implementation version). The <b>versionMax</b> and <b>versionMin</b>
  fields indicate the inclusive range of acceptable versions to relay or
  broadcast this message to. The <b>version</b> field indicates what version of
  the Nano protocol this node is using.

The messageType field indicates what type of message is being relayed, and must
  conform to the following enumeration
<table class="tbl">
  <colgroup>
    <col style="width: 11.00ex;"/>
    <col style="width: 16.00ex;"/>
    <col style="width: 12.00ex;"/>
    <col style="width: 11.00ex;"/>
    <col style="width: 7.00ex;"/>
  </colgroup>
  <tr>
    <td>messageType</td>
    <td>Name</td>
    <td>On Bootstrap</td>
    <td>On Realtime</td>
    <td>Version</td>
  </tr>
  <tr>
    <td>0x00</td>
    <td>Invalid</td>
    <td>Yes</td>
    <td>Yes</td>
    <td>0+</td>
  </tr>
  <tr>
    <td>0x01</td>
    <td>Not_A_Type</td>
    <td>?</td>
    <td>?</td>
    <td>0+</td>
  </tr>
  <tr>
    <td>0x02</td>
    <td>Keepalive</td>
    <td>No</td>
    <td>Yes</td>
    <td>0+</td>
  </tr>
  <tr>
    <td>0x03</td>
    <td>Publish</td>
    <td>No</td>
    <td>Yes</td>
    <td>0+</td>
  </tr>
  <tr>
    <td>0x04</td>
    <td>Confirm_Req</td>
    <td>No</td>
    <td>Yes</td>
    <td>0+</td>
  </tr>
  <tr>
    <td>0x05</td>
    <td>Confirm_Ack</td>
    <td>No</td>
    <td>Yes</td>
    <td>0+</td>
  </tr>
  <tr>
    <td>0x06</td>
    <td>Bulk_Pull</td>
    <td>Yes</td>
    <td>No</td>
    <td>?</td>
  </tr>
  <tr>
    <td>0x07</td>
    <td>Bulk_Push</td>
    <td>Yes</td>
    <td>No</td>
    <td>?</td>
  </tr>
  <tr>
    <td>0x08</td>
    <td>Frontier_Req</td>
    <td>Yes</td>
    <td>No</td>
    <td>?</td>
  </tr>
  <tr>
    <td>0x09</td>
    <td>Bulk_Pull_Blocks</td>
    <td>Yes</td>
    <td>No</td>
    <td>11+</td>
  </tr>
</table>

<b>TODO: Extensions</b>

Following the message header comes the payload for the particular message type.

<dl class="Bl-tag">
  <dt class="It-tag"><b>Invalid</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Not_A_Type</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Keepalive</b></dt>
  <dd class="It-tag">The Keepalive message serves as an introduction and
      beaconing mechanism for the Nano real-time network. The Keepalive message
      requires exactly 8 IPv6 address and port number tuples to be sent as its
      payload. The IPv6 addresses are each 128-bits (16-bytes) long and the port
      numbers are 16-bit integers sent in little endian byte order. The payload
      for the Keepalive message type is 144 bytes in size.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Publish</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Confirm_Req</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Confirm_Ack</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Bulk_Pull</b></dt>
  <dd class="It-tag">The Bulk_Pull message is used to pull the entire chain for
      an account, down to its beginning or to a given block. It takes 2
      arguments, both of them 256-bit. The first argument is the account, so its
      256-bit public key should be encoded as binary in big-endian notation. The
      second argument is the block hash to stop sending at, or 256 bits of 0s to
      indicate that the entire chain should be sent. The payload for Bulk_Pull
      messages is 64 bytes in size.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Bulk_Push</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Frontier_Req</b></dt>
  <dd class="It-tag">TODOC
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>Bulk_Pull_Blocks</b></dt>
  <dd class="It-tag">TODOC
    
    
  </dd>
</dl>
<h1 class="Sh" title="Sh" id="PROCEDURES"><a class="selflink" href="#PROCEDURES">PROCEDURES</a></h1>
<h2 class="Ss" title="Ss" id="Addresses"><a class="selflink" href="#Addresses">Addresses</a></h2>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::address::toPublicKey</b></dt>
  <dd class="It-tag"><i>address</i> ?<b>-hex</b>|<b>-binary</b>?
      ?<b>-verify</b>|<b>-no-verify</b>? <b> -&gt; </b><i>publicKey</i>
    
    Converts a Nano address to a public key. The <b>-hex</b> option indicates
      that the public key should be returned in hexadecimal form. The
      <b>-binary</b> option indicates that the public key should be returned in
      binary form. The <b>-verify</b> option verifies the checksum embedded in
      the Nano address before returning. The <b>-no-verify</b> option inhibits
      verifying the checksum embedded in the Nano address.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::address::fromPublicKey</b></dt>
  <dd class="It-tag"><i>pubKey</i> ?<b>-xrb</b>|<b>-nano</b>? <b> -&gt;
      </b><i>address</i>
    
    Converts a public key to a Nano address. The <b>-xrb</b> option specifies
      that the returned address should be prefixed with the old-style
      &quot;xrb_&quot; prefix, where the <b>-nano</b> option specifies that the
      returned address should be prefixed with the new-style &quot;nano_&quot;
      prefix.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::address::fromPrivateKey</b></dt>
  <dd class="It-tag"><i>privateKey</i> ?<b>-xrb</b>|<b>-nano</b>? <b> -&gt;
      </b><i>address</i>
    
    Converts a private key to a Nano address. It accepts the same arguments as
      <b>fromPublicKey</b>.
    
  </dd>
</dl>
<h2 class="Ss" title="Ss" id="Key_Management"><a class="selflink" href="#Key_Management">Key
  Management</a></h2>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::key::newSeed</b></dt>
  <dd class="It-tag">?<b>-hex</b>|<b>-binary</b>? -&gt; <i>seed</i>
    
    Generates a new seed. A seed is a 256-bit bit-field which, along with a
      32-bit index, is used to derive enumerated keys from a single point of
      entropy. See the <b>fromSeed</b> procedure. The <b>-hex</b> and
      <b>-binary</b> options determine the formatting of the result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::key::newKey</b></dt>
  <dd class="It-tag">?<b>-hex</b>|<b>-binary</b>? -&gt; <i>privateKey</i>
    
    Generates a new private key. A private key can be used to sign transactions,
      which can then be verified with its corresponding public key (see
      <b>publicKeyFromPrivateKey</b>). This procedure is normally not used, but
      rather private keys are derived from a <i>seed</i> and <i>index</i> pair
      using the <b>fromSeed</b> procedure. The <b>-hex</b> and <b>-binary</b>
      options determine the formatting of the result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::key::fromSeed</b></dt>
  <dd class="It-tag"><i>seed</i> ?<i>index</i>? ?<b>-hex</b>|<b>-binary</b>?
      -&gt; <i>privateKey</i>
    
    Derive a private key from the seed specified as <i>seed</i> and the
      <i>index</i> indicated. This procedure is deterministic (i.e., the same
      <i>seed</i> and <i>index</i> will always give you the same private key).
      This procedure is used to derive many keypairs from a single user-managed
      piece of data, so the user does not have to manage multiple private keys.
      If the <i>index</i> is not specified it defaults to <b>0</b>. The
      <b>-hex</b> and <b>-binary</b> options determine the formatting of the
      result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::key::publicKeyFromPrivateKey</b></dt>
  <dd class="It-tag"><i>privateKey</i> ?<b>-hex</b>|<b>-binary</b>? -&gt;
      <i>publicKey</i>
    
    Converts a private key into its corresponding public key. Normally Ed25519
      private keys are a concatenation of the private and public keys, however
      in this package they are each treated separately. The <b>-hex</b> and
      <b>-binary</b> options determine the formatting of the result.
    
  </dd>
</dl>
<h2 class="Ss" title="Ss" id="Low-level_Block"><a class="selflink" href="#Low-level_Block">Low-level
  Block</a></h2>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::</b><i>representation</i><b>::toBlock</b></dt>
  <dd class="It-tag"><i>blockRepresentation</i> -&gt; <i>blockData</i>
    
    Converts from one of the internal representations (either Tcl dictionary or
      JSON) to a Nano block. The <i>representation</i> portion of the command
      name may be one of <b>dict</b> or <b>json</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::json::fromDict</b></dt>
  <dd class="It-tag"><i>blockDict</i> -&gt; <i>blockJSON</i>
    
    Converts from a Tcl dictionary representation to a JSON representation of a
      block.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::json::filter</b></dt>
  <dd class="It-tag"><i>blockJSON</i> -&gt; <i>blockJSON</i>
    
    Filters out JSON object attributes which are not suitable for using with
      other implementations, such as <i>_comment</i>, <i>_workData</i>, and
      <i>_blockHash</i>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::dict::fromJSON</b></dt>
  <dd class="It-tag"><i>blockJSON</i> -&gt; <i>blockDict</i>
    
    Converts from a JSON object representation to a Tcl dictionary
      representation of a block.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::</b><i>representation</i><b>::fromBlock</b></dt>
  <dd class="It-tag"><i>blockData</i> ?<b>-xrb</b>|<b>-nano</b>? ?
      <b>-type=</b><i>blockType</i> ? ? <b>-signKey=</b><i>privateKey</i> ?
      -&gt; <i>blockRepresentation</i>
    
    Parses a Nano block and returns either a Tcl dictionary or a JSON object.
      The <b>-xrb</b> option causes all parsed addresses to be prefixed with the
      old-style &quot;xrb_&quot; address prefix, while the <b>-nano</b> option
      causes them to be prefixed with the new-style &quot;nano_prefix&quot;. The
      <i>representation</i> portion of the command name may be one of
      <b>dict</b> or <b>json</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::</b><i>representation</i><b>::sign</b></dt>
  <dd class="It-tag"><i>blockRepresentation</i> <i>privateKey</i>
      ?<b>-update</b>|<b>-signature</b> ?<b>-hex</b>|<b>binary</b>?? -&gt;
      <i>signature</i>|<i>blockJSON</i>
    
    Sign a block, in either Tcl dictionary or JSON representation, with the
      specified <i>privateKey</i>. If the <b>-update</b> option is used, return
      the object with the updated attribute. If the <b>-signature</b> option is
      used, return just the signature. The <b>-hex</b> and <b>-binary</b>
      options determine the formatting of the result. The <i>representation</i>
      portion of the command name may be one of <b>dict</b> or <b>json</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::</b><i>representation</i><b>::verifySignature</b></dt>
  <dd class="It-tag"><i>blockRepresentation</i> -&gt; <i>boolean</i>
    
    Verify the signature on a block, in either Tcl dictionary or JSON
      representation, matches the public key specified in the <b>account</b>
      attribute of that object. This may not work correctly for old-style blocks
      unless you manually add the <b>account</b> attribute. The
      <i>representation</i> portion of the command name may be one of
      <b>dict</b> or <b>json</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::</b><i>representation</i><b>::work</b></dt>
  <dd class="It-tag"><i>blockRepresentation</i> ?<b>-update</b>|<b>-work</b>
      ?<b>-hex</b>|<b>binary</b>?? -&gt; <i>work</i>|<i>blockRepresentation</i>
    
    Generate proof-of-work (PoW) required to submit a given block to the
      network. Nano uses PoW to increase the cost of submitting blocks to the
      network to cut down on spam. The <i>work</i> that is computed is based on
      the hash of the previous block on this chain, or if there is no previous
      block on this chain (i.e., because it is the first block on an account)
      the public key of the account. If the <b>-update</b> option is used,
      return the object with the updated attribute. If the <b>-work</b> option
      is used, just return the work. The <b>-hex</b> and <b>-binary</b> options
      determine the formatting of the result. The <i>representation</i> portion
      of the command name may be one of <b>dict</b> or <b>json</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::</b><i>representation</i><b>::validateWork</b></dt>
  <dd class="It-tag"><i>blockRepresentation</i> -&gt; <i>boolean</i>
    
    Validate the proof-of-work (PoW) in the object specified as
      <i>blockRepresentation</i> with the attribute <b>work</b> is valid for the
      block passed in. The <i>representation</i> portion of the command name may
      be one of <b>dict</b> or <b>json</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::hash</b></dt>
  <dd class="It-tag"><i>blockData</i> ?<b>-hex</b>|<b>-binary</b>? -&gt;
      <i>blockHash</i>
    
    Compute the cryptographic hash of a block. The cryptographic hashing
      algorithm used for Nano is Blake2b. Blocks are typically identified by
      their hash (i.e., content addressable). The <b>-hex</b> and <b>-binary</b>
      options determine the formatting of the result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::signBlockHash</b></dt>
  <dd class="It-tag"><i>blockHash</i> <i>privateKey</i>
      ?<b>-hex</b>|<b>-binary</b>? -&gt; <i>signature</i>
    
    Compute an Ed25519-with-Blake2b signature of a given block hash specified as
      <i>blockHash</i> with the private key specified as <i>privateKey</i>. In
      Nano, signed blocks are signed by signing the block's hash thus all that
      is needed to sign a block is its hash and the private key that corresponds
      to the account. <b>NOTE: Ensure that the</b> <i>privateKey</i>
      <b>specified matches the account the block belongs to.</b> The <b>-hex</b>
      and <b>-binary</b> options determine the formatting of the result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::sign</b></dt>
  <dd class="It-tag"><i>blockData</i> <i>privateKey</i>
      ?<b>-hex</b>|<b>-binary</b>? -&gt; <i>signature</i>
    
    This is a convenience procedure which computes the hash of a block given as
      <i>blockData</i>, and then calls <b>signBlockHash</b>. The <b>-hex</b> and
      <b>-binary</b> options determine the formatting of the result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::verifyBlockHash</b></dt>
  <dd class="It-tag"><i>blockHash</i> <i>signature</i> <i>publicKey</i> -&gt;
      <i>boolean</i>
    
    Verify that a block hash (<i>blockHash</i>) was signed (<i>signature</i>) by
      an account holding the private key that corresponds to the public key
      specified as <i>publicKey</i>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::verify</b></dt>
  <dd class="It-tag"><i>blockData</i> <i>signature</i> <i>publicKey</i> -&gt;
      <i>boolean</i>
    
    This is a convenience procedure which computes the hash of a block given as
      <i>blockData</i>, and then calls <b>verifyBlockHash</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::create::send</b></dt>
  <dd class="It-tag"><b>from </b><i>address</i> <b>to </b><i>address</i>
      <b>previous </b><i>blockHash</i> <b>representative </b><i>address</i>
      <b>previousBalance </b><i>integer</i> <b>amount </b><i>integer</i> ?
      <b>-json </b><i>boolean</i> ? -&gt; <i>blockJSON</i>|<i>blockDict</i>
    
    This is a low-level interface for creating blocks which correspond to
      sending Nano from one account to another. It constructs a block which
      sends the <b>amount</b> specified from the <b>from</b> address to the
      destination (<b>to</b>). The previous block's hash must be specified as
      the <i>blockHash</i> following <b>previous</b>. Additionally the balance
      of the account at the previous block must be supplied as the integer
      argument to <b>previousBalance</b>. All balance amounts are in units of
      <b>raw</b>. If the optional <b>-json</b> argument is used and specified as
      true the result is a JSON representation, otherwise a Tcl dict
      representation is used.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::create::receive</b></dt>
  <dd class="It-tag"><b>to </b><i>address</i> <b>sourceBlock
      </b><i>blockHash</i> <b>previous </b><i>blockHash</i> <b>representative
      </b><i>address</i> <b>previousBalance </b><i>integer</i> <b>amount
      </b><i>integer</i> ? <b>-json </b><i>boolean</i> ? -&gt;
      <i>blockJSON</i>|<i>blockDict</i>
    
    This is a low-level interface for creating blocks which correspond to
      receiving (pocketing) Nano previously sent from another account to the
      account specified as the <i>address</i> supplied to the <b>to</b>
      argument. It constructs a block which receives the amount of Nano
      specified as the <b>amount</b> argument. The block hash (<i>blockHash</i>)
      of the send block which was used to send the Nano to this account must be
      specified as the argument to the <b>sourceBlock</b> option. The previous
      block's hash must be specified as the <i>blockHash</i> following
      <b>previous</b>. Additionally the balance of the account at the previous
      block must be supplied as the integer argument to <b>previousBalance</b>.
      All balance amounts are in units of <b>raw</b>. If the optional
      <b>-json</b> argument is used and specified as true the result is a JSON
      representation, otherwise a Tcl dict representation is used.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::block::create::setRepresentative</b></dt>
  <dd class="It-tag"><b>account </b><i>address</i> <b>previous
      </b><i>blockHash</i> <b>representative </b><i>address</i> ? <b>-json
      </b><i>boolean</i> ? -&gt; <i>blockJSON</i>|<i>blockDict</i>
    
    This is a low-level interface for creating blocks which correspond to an
      explicit change of representative. Representatives in Nano are used as
      part of the Delegated Proof-of-Stake (dPoS) consensus mechanism which is
      used by the Nano network to determine which block (if any) out of many
      possible subordinate blocks in a chain are valid. So that every account
      holder does not have to be online to vote for valid transactions, an
      account may delegate another account to vote its stake on its behalf. That
      delegate is called a representative. An account may change its
      representative at any time by issuing a block with a new representative,
      such as a send or receive block, or by issuing an explicit change of
      representative block. This procedure creates an explicit change of
      representative block for the <b>account</b> specified. It changes to the
      delegate to the <b>representative</b> specified. Further, the
      <i>blockHash</i> of the previous block must be specified as the argument
      to <b>previous</b>. If the optional <b>-json</b> argument is used and
      specified as true the result is a JSON representation, otherwise a Tcl
      dict representation is used.
    
  </dd>
</dl>
<h2 class="Ss" title="Ss" id="Work_Generation"><a class="selflink" href="#Work_Generation">Work
  Generation</a></h2>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::work::fromWorkData</b></dt>
  <dd class="It-tag"><i>blockHashOrPublicKey</i> ?<b>-hex</b>|<b>-binary</b>?
      -&gt; <i>work</i>
    
    Create proof-of-work (PoW) from a block hash or public key. Which one is
      used depends on whether or not there are any other blocks in this
      account's chain. If this is the first block in this account's chain then
      the public key of the account is used, otherwise the hash of the blocks
      predecessor (<i>previous</i>) is used. The specific value needed should be
      accessible from the <b>_workData</b> member of a JSON object or Tcl
      dictionary. Note that this attribute (and all attributes that begin with
      an underscore) should be discarded when sending the block outside of the
      Tcl process. The <b>-hex</b> and <b>-binary</b> options determine the
      formatting of the result.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::work::fromBlock</b></dt>
  <dd class="It-tag"><i>blockData</i> -&gt; <i>work</i>
    
    This is a convenience procedure which computes work data (either a block
      hash or a public key) for a given block and then calls
      <b>fromWorkData</b>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::work::validate</b></dt>
  <dd class="It-tag"><i>workData</i> <i>work</i> -&gt; <i>boolean</i>
    
    This procedure validates that the supplied <i>work</i> is valid for the
      supplied <i>workData</i>, which is either a block hash or an account
      public key. For more information see the description of
      <b>fromWorkData</b>.
    
    
  </dd>
</dl>
<h2 class="Ss" title="Ss" id="High-level_Account"><a class="selflink" href="#High-level_Account">High-level
  Account</a></h2>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::setFrontier</b></dt>
  <dd class="It-tag"><i>account</i> <i>frontierHash</i> <i>balance</i>
      <i>representative</i>
    
    This procedure is used as part of the High-level Account interface. It sets
      the <i>frontier</i>, which is the block hash (<i>frontierHash</i>) and
      data (<i>balance</i>, <i>representative</i>) associated with that block
      that corresponds to the head of an account's chain.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::getFrontier</b></dt>
  <dd class="It-tag"><i>account</i> -&gt; <i>frontierInfo</i>
    
    This procedure is used as part of the High-level Account interface. It gets
      the Tcl dictionary associated with the frontier most recently set for the
      specified <i>account</i>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::getFrontier</b></dt>
  <dd class="It-tag"><i>account</i>
      ?<b>frontierHash</b>|<b>balance</b>|<b>representative</b>? -&gt;
      <i>frontierHash</i>|<i>balance</i>|<i>representative</i>
    
    This procedure is used as part of the High-level Account interface. It gets
      a specific item from Tcl dictionary associated with the frontier most
      recently set for the specified <i>account</i>.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::addPending</b></dt>
  <dd class="It-tag"><i>account</i> <i>blockHash</i> <i>amount</i>
    
    This procedure is used as part of the High-level Account interface. It is
      used to indicate than a given <i>account</i> has a <b>receive</b> block
      that they could create. The block hash of the corresponding <b>send</b>
      block should be supplied as the <i>blockHash</i> parameter. The amount of
      Nano that was sent in the <b>send</b> block should be specified as the
      <i>amount</i> parameter (in units of raw).
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::getPending</b></dt>
  <dd class="It-tag"><i>account</i> ?<i>blockHash</i>? -&gt; <i>dict</i>
    
    This procedure is used as part of the High-level Account interface. It is
      used to retrieve information stored by <b>addPending</b> for a given
      <i>account</i>. If the <i>blockHash</i> parameter is supplied then a Tcl
      dictionary is returned with a key called <b>amount</b> which contains the
      amount stored previously. If the <i>blockHash</i> parameter is not
      supplied then a Tcl dictionary is returned with keys corresponding to each
      block hash pending for the specified <i>account</i>, and containing a
      subordinate Tcl dictionary with a key called <b>amount</b> as previously
      described.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::account::clearPending</b></dt>
  <dd class="It-tag"><i>account</i> ?<i>blockHash</i>?
    
    This procedure is used as part of the High-level Account interface. It is
      used to clear (that is, remove from the conceptual state of
      &quot;pending&quot;) entries created previously with <b>addPending</b> for
      a given <i>account</i>. If the <i>blockHash</i> parameter is supplied then
      only the entry corresponding to that blockhash is cleared, otherwise all
      entries for the specified <i>account</i> are cleared.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::receive</b></dt>
  <dd class="It-tag"><i>account</i> <i>blockHash</i> <i>privateKey</i> -&gt;
      <i>blockJSON</i>|<i>blockDict</i>
    
    This procedure is used as part of the High-level Account interface. It is
      used to generate a receive block. Its interface is subject to change and
      not considered stable.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::receiveAllPending</b></dt>
  <dd class="It-tag"><i>account</i> <i>privateKey</i> -&gt;
      <i>listOfBlockJSON</i>|<i>listOfBlockDict</i>
    
    This procedure is used as part of the High-level Account interface. It is
      used to generate receive blocks for every pending receive on a given
      <i>account</i>. Its interface is subject to change and not considered
      stable.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>:nano::account::send</b></dt>
  <dd class="It-tag"><i>fromAccount</i> <i>toAccount</i> <i>amount</i>
      <i>privateKey</i> -&gt; <i>blockJSON</i>|<i>blockDict</i>
    
    This procedure is used as part of the High-level Account interface. It is
      used to generate a send block. Its interface is subject to change and not
      considered stable.
    
  </dd>
</dl>
<dl class="Bl-tag">
  <dt class="It-tag"><b>::nano::account::setRepresentative</b></dt>
  <dd class="It-tag"><i>account</i> <i>representative</i> <i>privateKey</i>
      -&gt; <i>blockJSON</i>|<i>blockDict</i>
    
    This procedure is used as part of the High-level Account interface. It is
      used to generate a block that changes the representative for the given
      <i>account</i>. Its interface is subject to change and not considered
      stable.
    
  </dd>
</dl>
<h1 class="Sh" title="Sh" id="EXAMPLES"><a class="selflink" href="#EXAMPLES">EXAMPLES</a></h1>
<h2 class="Ss" title="Ss" id="Example_1:_Generate_a_new_seed_and_derive_10_addresses_from_it"><a class="selflink" href="#Example_1:_Generate_a_new_seed_and_derive_10_addresses_from_it">Example
  1: Generate a new seed and derive 10 addresses from it</a></h2>
<pre>
package require nano 1.1
<div class="Pp"></div>
set seed &#91;::nano::key::newSeed -hex&#93;
puts &quot;Generated seed: $seed&quot;
<div class="Pp"></div>
for {set index 0} {$index &lt; 10} {incr index} {
	set accountPrivateKey &#91;::nano::key::fromSeed $seed $index -hex&#93;
	set accountAddress &#91;::nano::address::fromPrivateKey $accountPrivateKey&#93;
	puts &quot;    - $index: $accountAddress&quot;
}
</pre>

<h1 class="Sh" title="Sh" id="AUTHOR"><a class="selflink" href="#AUTHOR">AUTHOR</a></h1>
Roy Keene &lt;<i>rkeene@nano.org</i>&gt;</div>
<table class="foot">
  <tr>
    <td class="foot-date">18-Jul-2018</td>
    <td class="foot-os">nano 1.1</td>
  </tr>
</table>

Z 0f45647506de7e148a0a82bb62187ce5