bitmessage-js/docs/module-bitmessage_crypto.html

2043 lines
23 KiB
HTML
Raw Normal View History

2015-01-03 17:04:14 +01:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Module: bitmessage/crypto</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/crypto</h1>
<section>
<header>
</header>
<article>
<div class="container-overview">
<div class="description"><p>Isomorphic Bitmessage crypto module. Reexports platform-dependent
2015-01-31 12:54:23 +01:00
implementations and also some common routines.</p></div>
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
2015-01-31 12:54:23 +01:00
<h4 class="name" id=".decrypt"><span class="type-signature">(static) </span>decrypt<span class="signature">(privateKey, buf)</span><span class="type-signature"> &rarr; {Promise.&lt;Buffer>}</span></h4>
<div class="description">
<p>Decrypt message using given private key.</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>privateKey</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>A 32-byte private key of recepient of
the mesage</p></td>
</tr>
<tr>
<td class="name"><code>buf</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>Encrypted data</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-02-12 11:44:15 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line171">line 171</a>
2015-01-31 12:54:23 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-02-12 11:44:15 +01:00
<p>A promise that resolves with the plaintext
on successful decryption and rejects on failure.</p>
2015-01-31 12:54:23 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;Buffer></span>
</dd>
</dl>
2015-02-12 11:44:15 +01:00
<h4 class="name" id=".encrypt"><span class="type-signature">(static) </span>encrypt<span class="signature">(publicKeyTo, msg, opts<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Buffer>}</span></h4>
2015-01-31 12:54:23 +01:00
<div class="description">
<p>Encrypt message for given recepient's public key.</p>
</div>
<h5>Parameters:</h5>
<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>publicKeyTo</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>Recipient's public key (65 bytes)</p></td>
</tr>
<tr>
<td class="name"><code>msg</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>The message being encrypted</p></td>
</tr>
<tr>
<td class="name"><code>opts</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
2015-02-12 11:44:15 +01:00
&lt;optional><br>
2015-01-31 12:54:23 +01:00
2015-02-12 11:44:15 +01:00
2015-01-31 12:54:23 +01:00
</td>
2015-02-12 11:44:15 +01:00
<td class="description last"><p>You may also specify initialization vector
and ephemeral private key to get deterministic results</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>iv</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>Initialization vector (16 bytes)</p></td>
</tr>
<tr>
<td class="name"><code>ephemPrivateKey</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>Ephemeral private key (32
bytes)</p></td>
</tr>
</tbody>
</table>
</td>
2015-01-31 12:54:23 +01:00
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-02-12 11:44:15 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line157">line 157</a>
2015-01-31 12:54:23 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-02-12 11:44:15 +01:00
<p>A promise that resolves with the buffer in
<code>encrypted</code> format successful encryption and rejects on failure.</p>
2015-01-31 12:54:23 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;Buffer></span>
</dd>
</dl>
2015-01-03 17:04:14 +01:00
<h4 class="name" id=".getPrivate"><span class="type-signature">(static) </span>getPrivate<span class="signature">()</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
<div class="description">
2015-02-12 11:44:15 +01:00
<p>Generate a new random private key.</p>
2015-01-31 12:54:23 +01:00
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line60">line 60</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New private key.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
<h4 class="name" id=".getPublic"><span class="type-signature">(static) </span>getPublic<span class="signature">(privateKey)</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
<div class="description">
<p>Generate public key for the given private key.</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>privateKey</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>A 32-byte private key</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line70">line 70</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>A 65-byte (uncompressed) public key.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
<h4 class="name" id=".randomBytes"><span class="type-signature">(static) </span>randomBytes<span class="signature">(size)</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
<div class="description">
<p>Generate cryptographically strong pseudo-random data.</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>size</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>Number of bytes</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line54">line 54</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Buffer with random data.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
<h4 class="name" id=".ripemd160"><span class="type-signature">(static) </span>ripemd160<span class="signature">(buf)</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
<div class="description">
<p>Calculate RIPEMD-160 hash.</p>
2015-01-03 17:04:14 +01:00
</div>
2015-01-31 12:54:23 +01:00
<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>buf</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>Input data</p></td>
</tr>
</tbody>
</table>
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-01-31 12:54:23 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line46">line 46</a>
2015-01-03 17:04:14 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-01-31 12:54:23 +01:00
<p>Resulting hash.</p>
2015-01-03 17:04:14 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
2015-01-31 12:54:23 +01:00
<h4 class="name" id=".sha1"><span class="type-signature">(static) </span>sha1<span class="signature">(buf)</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
2015-01-03 17:04:14 +01:00
<div class="description">
2015-01-31 12:54:23 +01:00
<p>Calculate SHA-1 hash.</p>
2015-01-03 17:04:14 +01:00
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
2015-01-31 12:54:23 +01:00
<td class="name"><code>buf</code></td>
2015-01-03 17:04:14 +01:00
<td class="type">
<span class="param-type">Buffer</span>
</td>
2015-01-31 12:54:23 +01:00
<td class="description last"><p>Input data</p></td>
2015-01-03 17:04:14 +01:00
</tr>
</tbody>
</table>
2015-01-31 12:54:23 +01:00
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-01-31 12:54:23 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line22">line 22</a>
2015-01-03 17:04:14 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-01-31 12:54:23 +01:00
<p>Resulting hash.</p>
2015-01-03 17:04:14 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
2015-01-31 12:54:23 +01:00
<h4 class="name" id=".sha256"><span class="type-signature">(static) </span>sha256<span class="signature">(buf)</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
2015-01-03 17:04:14 +01:00
<div class="description">
2015-01-31 12:54:23 +01:00
<p>Calculate SHA-256 hash.</p>
2015-01-03 17:04:14 +01:00
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
2015-01-31 12:54:23 +01:00
<td class="name"><code>buf</code></td>
2015-01-03 17:04:14 +01:00
<td class="type">
2015-01-31 12:54:23 +01:00
<span class="param-type">Buffer</span>
2015-01-03 17:04:14 +01:00
</td>
2015-01-31 12:54:23 +01:00
<td class="description last"><p>Input data</p></td>
2015-01-03 17:04:14 +01:00
</tr>
</tbody>
</table>
2015-01-31 12:54:23 +01:00
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-01-31 12:54:23 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line30">line 30</a>
2015-01-03 17:04:14 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-01-31 12:54:23 +01:00
<p>Resulting hash.</p>
2015-01-03 17:04:14 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
2015-01-31 12:54:23 +01:00
<h4 class="name" id=".sha512"><span class="type-signature">(static) </span>sha512<span class="signature">(buf)</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
2015-01-03 17:04:14 +01:00
<div class="description">
2015-01-31 12:54:23 +01:00
<p>Calculate SHA-512 hash.</p>
2015-01-03 17:04:14 +01:00
</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>buf</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>Input data</p></td>
</tr>
</tbody>
</table>
2015-01-31 12:54:23 +01:00
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-01-31 12:54:23 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line38">line 38</a>
2015-01-03 17:04:14 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Resulting hash.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Buffer</span>
</dd>
</dl>
2015-01-31 12:54:23 +01:00
<h4 class="name" id=".sign"><span class="type-signature">(static) </span>sign<span class="signature">(privateKey, msg)</span><span class="type-signature"> &rarr; {Promise.&lt;Buffer>}</span></h4>
2015-01-03 17:04:14 +01:00
<div class="description">
2015-01-31 12:54:23 +01:00
<p>Sign message using ecdsa-with-sha1 scheme.</p>
2015-01-03 17:04:14 +01:00
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
2015-01-31 12:54:23 +01:00
<td class="name"><code>privateKey</code></td>
2015-01-03 17:04:14 +01:00
<td class="type">
<span class="param-type">Buffer</span>
</td>
2015-01-31 12:54:23 +01:00
<td class="description last"><p>A 32-byte private key</p></td>
</tr>
<tr>
<td class="name"><code>msg</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>The message being signed</p></td>
2015-01-03 17:04:14 +01:00
</tr>
</tbody>
</table>
2015-01-31 12:54:23 +01:00
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-01-31 12:54:23 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line79">line 79</a>
2015-01-03 17:04:14 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-01-31 12:54:23 +01:00
<p>A promise that contains signature in DER
format when fulfilled.</p>
2015-01-03 17:04:14 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
2015-01-31 12:54:23 +01:00
<span class="param-type">Promise.&lt;Buffer></span>
2015-01-03 17:04:14 +01:00
</dd>
</dl>
2015-02-12 11:44:15 +01:00
<h4 class="name" id=".verify"><span class="type-signature">(static) </span>verify<span class="signature">(publicKey, msg, sig)</span><span class="type-signature"> &rarr; {Promise.&lt;null>}</span></h4>
2015-01-03 17:04:14 +01:00
<div class="description">
2015-01-31 12:54:23 +01:00
<p>Verify signature using ecdsa-with-sha1 scheme.</p>
2015-01-03 17:04:14 +01:00
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
2015-01-31 12:54:23 +01:00
<td class="name"><code>publicKey</code></td>
2015-01-03 17:04:14 +01:00
<td class="type">
<span class="param-type">Buffer</span>
</td>
2015-01-31 12:54:23 +01:00
<td class="description last"><p>A 65-byte public key</p></td>
</tr>
<tr>
<td class="name"><code>msg</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>The message being verified</p></td>
</tr>
<tr>
<td class="name"><code>sig</code></td>
<td class="type">
<span class="param-type">Buffer</span>
</td>
<td class="description last"><p>The signature in DER format</p></td>
2015-01-03 17:04:14 +01:00
</tr>
</tbody>
</table>
2015-01-31 12:54:23 +01:00
2015-01-03 17:04:14 +01:00
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2015-01-31 12:54:23 +01:00
<a href="crypto.js.html">crypto.js</a>, <a href="crypto.js.html#line92">line 92</a>
2015-01-03 17:04:14 +01:00
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
2015-02-12 11:44:15 +01:00
<p>A promise that resolves on correct signature
and rejects on bad key or signature.</p>
2015-01-03 17:04:14 +01:00
</div>
<dl>
<dt>
Type
</dt>
<dd>
2015-02-12 11:44:15 +01:00
<span class="param-type">Promise.&lt;null></span>
2015-01-03 17:04:14 +01:00
</dd>
</dl>
</article>
</section>
</div>
<nav>
2015-02-28 20:57:18 +01:00
<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_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_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>
2015-01-03 17:04:14 +01:00
</nav>
<br class="clear">
<footer>
2015-02-28 20:57:18 +01:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a> on Sat Feb 28 2015 22:57:02 GMT+0300 (MSK)
2015-01-03 17:04:14 +01:00
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>