1104 lines
16 KiB
HTML
1104 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Module: bitmessage/pow</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">Module: bitmessage/pow</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<header>
|
|
|
|
|
|
|
|
|
|
|
|
</header>
|
|
|
|
<article>
|
|
<div class="container-overview">
|
|
|
|
|
|
<div class="description"><p>Implements proof of work.</p></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl class="details">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="tag-source">Source:</dt>
|
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
<a href="pow.js.html">pow.js</a>, <a href="pow.js.html#line1">line 1</a>
|
|
</li></ul></dd>
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="tag-see">See:</dt>
|
|
<dd class="tag-see">
|
|
<ul>
|
|
<li><a href="https://bitmessage.org/wiki/Proof_of_work">https://bitmessage.org/wiki/Proof_of_work</a></li>
|
|
</ul>
|
|
</dd>
|
|
|
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 class="subsection-title">Methods</h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="name" id=".check"><span class="type-signature">(static) </span>check<span class="signature">(opts)</span><span class="type-signature"> → {boolean}</span></h4>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="description">
|
|
<p>Check a POW.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h5>Parameters:</h5>
|
|
|
|
|
|
<table class="params">
|
|
<thead>
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
|
|
|
|
|
|
|
<th class="last">Description</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>opts</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Object</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Proof of work options</p>
|
|
<h6>Properties</h6>
|
|
|
|
|
|
<table class="params">
|
|
<thead>
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
|
|
|
|
|
|
|
<th class="last">Description</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>target</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Proof of work target or pass
|
|
<a href="module-bitmessage_pow.html#.getTarget">getTarget</a> options to <code>opts</code>
|
|
to compute it</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>payload</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Buffer</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Message payload (with nonce)</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>nonce</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
<span class="param-type">Buffer</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>...or already derived nonce</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>initialHash</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Buffer</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>...and initial hash</p></td>
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl class="details">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="tag-source">Source:</dt>
|
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
<a href="pow.js.html">pow.js</a>, <a href="pow.js.html#line55">line 55</a>
|
|
</li></ul></dd>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h5>Returns:</h5>
|
|
|
|
|
|
<div class="param-desc">
|
|
<p>Is the proof of work sufficient.</p>
|
|
</div>
|
|
|
|
|
|
|
|
<dl>
|
|
<dt>
|
|
Type
|
|
</dt>
|
|
<dd>
|
|
|
|
<span class="param-type">boolean</span>
|
|
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="name" id=".doAsync"><span class="type-signature">(static) </span>doAsync<span class="signature">(opts)</span><span class="type-signature"> → {Promise.<number>}</span></h4>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="description">
|
|
<p>Do a POW.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h5>Parameters:</h5>
|
|
|
|
|
|
<table class="params">
|
|
<thead>
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
|
|
|
|
|
|
|
<th class="last">Description</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>opts</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Object</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Proof of work options</p>
|
|
<h6>Properties</h6>
|
|
|
|
|
|
<table class="params">
|
|
<thead>
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
|
<th>Attributes</th>
|
|
|
|
|
|
|
|
|
|
<th class="last">Description</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>data</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Buffer</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Object message payload without nonce to
|
|
get the initial hash from</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>initialHash</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Buffer</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>...or already computed initial
|
|
hash</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>target</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>POW target</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>poolSize</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
<optional><br>
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>POW calculation pool size (by
|
|
default equals to number of cores)</p></td>
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl class="details">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="tag-source">Source:</dt>
|
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
<a href="pow.js.html">pow.js</a>, <a href="pow.js.html#line105">line 105</a>
|
|
</li></ul></dd>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h5>Returns:</h5>
|
|
|
|
|
|
<div class="param-desc">
|
|
<p>A promise that contains computed nonce for
|
|
the given target when fulfilled.</p>
|
|
</div>
|
|
|
|
|
|
|
|
<dl>
|
|
<dt>
|
|
Type
|
|
</dt>
|
|
<dd>
|
|
|
|
<span class="param-type">Promise.<number></span>
|
|
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="name" id=".getTarget"><span class="type-signature">(static) </span>getTarget<span class="signature">(opts)</span><span class="type-signature"> → {number}</span></h4>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="description">
|
|
<p>Calculate target.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h5>Parameters:</h5>
|
|
|
|
|
|
<table class="params">
|
|
<thead>
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
|
|
|
|
|
|
|
<th class="last">Description</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>opts</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Object</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Target options</p>
|
|
<h6>Properties</h6>
|
|
|
|
|
|
<table class="params">
|
|
<thead>
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
|
<th>Attributes</th>
|
|
|
|
|
|
|
|
|
|
<th class="last">Description</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>ttl</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Time to live of the message in seconds</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>payloadLength</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>Length of the message payload
|
|
(with nonce)</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>payload</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">Buffer</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>...or payload itself</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>nonceTrialsPerByte</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
<optional><br>
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>This number is the average
|
|
number of nonce trials a node will have to perform to meet the Proof
|
|
of Work requirement. 1000 is the network minimum so any lower values
|
|
will be automatically raised to 1000.</p></td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td class="name"><code>payloadLengthExtraBytes</code></td>
|
|
|
|
|
|
<td class="type">
|
|
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="attributes">
|
|
|
|
<optional><br>
|
|
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td class="description last"><p>This number is added
|
|
to the data length to make sending small messages more difficult.
|
|
1000 is the network minimum so any lower values will be automatically
|
|
raised to 1000.</p></td>
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl class="details">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="tag-source">Source:</dt>
|
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
<a href="pow.js.html">pow.js</a>, <a href="pow.js.html#line34">line 34</a>
|
|
</li></ul></dd>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h5>Returns:</h5>
|
|
|
|
|
|
<div class="param-desc">
|
|
<p>Target.</p>
|
|
</div>
|
|
|
|
|
|
|
|
<dl>
|
|
<dt>
|
|
Type
|
|
</dt>
|
|
<dd>
|
|
|
|
<span class="param-type">number</span>
|
|
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</article>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-bitmessage.html">bitmessage</a></li><li><a href="module-bitmessage_address.html">bitmessage/address</a></li><li><a href="module-bitmessage_crypto.html">bitmessage/crypto</a></li><li><a href="module-bitmessage_messages.html">bitmessage/messages</a></li><li><a href="module-bitmessage_net_base.html">bitmessage/net/base</a></li><li><a href="module-bitmessage_net_tcp.html">bitmessage/net/tcp</a></li><li><a href="module-bitmessage_net_ws.html">bitmessage/net/ws</a></li><li><a href="module-bitmessage_objects.html">bitmessage/objects</a></li><li><a href="module-bitmessage_pow.html">bitmessage/pow</a></li><li><a href="module-bitmessage_structs.html">bitmessage/structs</a></li><li><a href="module-bitmessage_user-agent.html">bitmessage/user-agent</a></li><li><a href="module-bitmessage_wif.html">bitmessage/wif</a></li></ul><h3>Classes</h3><ul><li><a href="module-bitmessage_address.Address.html">Address</a></li><li><a href="module-bitmessage_net_base.BaseTransport.html">BaseTransport</a></li><li><a href="module-bitmessage_net_tcp.TcpTransport.html">TcpTransport</a></li><li><a href="module-bitmessage_net_ws.WsTransport.html">WsTransport</a></li><li><a href="module-bitmessage_structs.PubkeyBitfield.html">PubkeyBitfield</a></li><li><a href="module-bitmessage_structs.ServicesBitfield.html">ServicesBitfield</a></li></ul><h3>Namespaces</h3><ul><li><a href="module-bitmessage_messages.addr.html">addr</a></li><li><a href="module-bitmessage_messages.error.html">error</a></li><li><a href="module-bitmessage_messages.getdata.html">getdata</a></li><li><a href="module-bitmessage_messages.inv.html">inv</a></li><li><a href="module-bitmessage_messages.version.html">version</a></li><li><a href="module-bitmessage_objects.broadcast.html">broadcast</a></li><li><a href="module-bitmessage_objects.getpubkey.html">getpubkey</a></li><li><a href="module-bitmessage_objects.msg.html">msg</a></li><li><a href="module-bitmessage_objects.pubkey.html">pubkey</a></li><li><a href="module-bitmessage_structs.encrypted.html">encrypted</a></li><li><a href="module-bitmessage_structs.inv_vect.html">inv_vect</a></li><li><a href="module-bitmessage_structs.message.html">message</a></li><li><a href="module-bitmessage_structs.net_addr.html">net_addr</a></li><li><a href="module-bitmessage_structs.object.html">object</a></li><li><a href="module-bitmessage_structs.var_int.html">var_int</a></li><li><a href="module-bitmessage_structs.var_int_list.html">var_int_list</a></li><li><a href="module-bitmessage_structs.var_str.html">var_str</a></li></ul>
|
|
</nav>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a> on Sat Feb 14 2015 14:05:38 GMT+0300 (MSK)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
<script src="scripts/linenumber.js"> </script>
|
|
</body>
|
|
</html> |