bitmessage-js/docs/index.html

214 lines
9.5 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: Home</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">Home</h1>
<h3> </h3>
<section>
2015-01-31 12:54:23 +01:00
<article><h1>bitmessage <a href="https://travis-ci.org/bitchan/bitmessage"><img src="https://travis-ci.org/bitchan/bitmessage.svg?branch=master" alt="Build Status"></a></h1><p><a href="https://www.npmjs.com/package/bitmessage"><img src="https://nodei.co/npm/bitmessage.png" alt="NPM"></a></p>
<p>JavaScript Bitmessage library for both browserify and node. The goal of this project is to implement Bitmessage protocol v3 for both platforms at the maximum possible level (we still can't create TCP connections or listen for incoming connections in the Browser but the Proof of work and crypto is fully doable).</p>
2015-01-03 17:04:14 +01:00
<p>Public library API is currently in alpha stage, breaking changes are very likely to happen.</p>
<p>API documentation is available <a href="https://bitchan.github.io/bitmessage/docs/">here</a>.</p>
<h2>References</h2><ul>
2015-01-31 12:54:23 +01:00
<li><a href="https://bitmessage.org/wiki/Main_Page">Bitmessage wiki</a></li>
2015-01-03 17:04:14 +01:00
<li><a href="https://bitmessage.org/wiki/Protocol_specification">Protocol specification</a></li>
<li><a href="https://bitmessage.org/bitmessage.pdf">Whitepaper</a></li>
</ul>
2015-02-12 11:44:15 +01:00
<h2>Feature matrix</h2><ul>
2015-01-31 12:54:23 +01:00
<li>[x] Crypto<ul>
<li>[x] SHA-1</li>
2015-01-03 17:04:14 +01:00
<li>[x] SHA-256</li>
2015-01-31 12:54:23 +01:00
<li>[x] SHA-512</li>
2015-01-03 17:04:14 +01:00
<li>[x] RIPEMD-160</li>
<li>[x] PRNG</li>
2015-02-12 11:44:15 +01:00
<li>[x] ECC keys handling</li>
2015-01-03 17:04:14 +01:00
<li>[x] ECDSA</li>
2015-01-31 12:54:23 +01:00
<li>[x] ECIES</li>
2015-01-03 17:04:14 +01:00
</ul>
</li>
2015-01-31 12:54:23 +01:00
<li>[x] Common structures<ul>
<li>[x] message</li>
<li>[x] object</li>
2015-01-03 17:04:14 +01:00
<li>[x] var_int</li>
<li>[x] var_str</li>
<li>[x] var_int_list</li>
2015-01-31 12:54:23 +01:00
<li>[x] net_addr</li>
<li>[x] inv_vect</li>
<li>[x] encrypted</li>
<li>[x] service features</li>
<li>[x] pubkey features</li>
2015-01-03 17:04:14 +01:00
</ul>
</li>
2015-01-31 12:54:23 +01:00
<li>[x] Message types<ul>
<li>[x] version</li>
<li>[x] addr</li>
<li>[x] inv</li>
<li>[x] getdata</li>
<li>[x] error</li>
2015-01-03 17:04:14 +01:00
</ul>
</li>
2015-01-31 12:54:23 +01:00
<li>[x] Object types<ul>
<li>[x] getpubkey</li>
<li>[x] pubkey</li>
<li>[x] msg</li>
<li>[x] broadcast</li>
2015-01-03 17:04:14 +01:00
</ul>
</li>
<li>[x] WIF</li>
2015-01-31 12:54:23 +01:00
<li>[x] POW</li>
<li>[x] High-level classes<ul>
<li>[x] Address</li>
<li>[x] UserAgent</li>
2015-01-03 17:04:14 +01:00
</ul>
</li>
2015-02-12 11:44:15 +01:00
<li>[ ] Network transports<ul>
<li>[x] TCP (Node.js only)</li>
<li>[x] WebSocket</li>
<li>[ ] WebRTC</li>
</ul>
</li>
<li>[ ] PyBitmessage configs parsing<ul>
2015-01-03 17:04:14 +01:00
<li>[ ] keys.dat</li>
<li>[ ] knownnodes.dat</li>
<li>[ ] messages.dat</li>
</ul>
</li>
</ul>
2015-01-31 12:54:23 +01:00
<h2>Usage</h2><h3>Address</h3><pre class="prettyprint source lang-js"><code>var Address = require(&quot;bitmessage&quot;).Address;
// Generate a new random Bitmessage identity.
var addr1 = Address.fromRandom();
console.log(&quot;New random Bitmessage address:&quot;, addr1.encode());
// Or create it from passphrase.
var addr2 = Address.fromPassphrase(&quot;test&quot;);
2015-02-12 11:44:15 +01:00
console.log(&quot;Deterministic Bitmessage address:&quot;, addr2.encode());</code></pre><h3>Structures</h3><pre class="prettyprint source lang-js"><code>var structs = require(&quot;bitmessage&quot;).structs;
var encoded = Buffer.concat([
structs.var_int.encode(4),
Buffer(&quot;test&quot;),
structs.var_str.encode(&quot;test2&quot;),
structs.var_int_list.encode([1, 2, 3]),
]);
var decoded1 = structs.var_str.decode(encoded);
console.log(decoded1.str); // test
var decoded2 = structs.var_str.decode(decoded1.rest);
console.log(decoded2.str); // test2
var decoded3 = structs.var_int.decode(decoded2.rest);
console.log(decoded3.value); // 3
var decoded4 = structs.var_int_list.decode(decoded2.rest);
console.log(decoded4.list); // [1, 2, 3]</code></pre><h3>Messages</h3><pre class="prettyprint source lang-js"><code>var structs = require(&quot;bitmessage&quot;).structs;
var messages = require(&quot;bitmessage&quot;).messages;
// Simple encoding and decoding:
var vermsg = messages.version.encode({
nonce: Buffer(8), // Hack detection connection to self
remoteHost: &quot;1.1.1.1&quot;,
remotePort: 8444,
});
console.log(messages.version.decode(vermsg).remoteHost); // 1.1.1.1
// Low-level encoding and decoding:
var addrPayload = messages.addr.encodePayload([
{host: &quot;2.2.2.2&quot;, port: 28444},
]);
var addrmsg = structs.message.encode(&quot;addr&quot;, addrPayload);
var decoded = structs.message.decode(addrmsg);
console.log(decoded.command); // addr
var payload = decoded.payload;
var decodedPayload = messages.addr.decodePayload(payload);
console.log(decodedPayload.addrs[0].host); // 2.2.2.2
// Encode with empty payload:
var verackmsg = structs.message.encode(&quot;verack&quot;);
2015-02-14 11:54:39 +01:00
console.log(structs.message.decode(verackmsg).command); // verack</code></pre><h3>Networking</h3><pre class="prettyprint source lang-js"><code>var messages = require(&quot;bitmessage&quot;).messages;
var TcpTransport = require(&quot;bitmessage/lib/net/tcp&quot;);
2015-02-12 11:44:15 +01:00
var tcp = new TcpTransport({
dnsSeeds: [[&quot;bootstrap8444.bitmessage.org&quot;, 8444]],
});
tcp.bootstrap().then(function(nodes) {
var remoteHost = nodes[0][0];
var remotePort = nodes[0][1];
console.log(&quot;Connecting to&quot;, nodes[0]);
tcp.connect(remotePort, remoteHost);
});
tcp.on(&quot;established&quot;, function() {
console.log(&quot;Connection established&quot;);
tcp.on(&quot;message&quot;, function(command, payload) {
console.log(&quot;Got new&quot;, command, &quot;message&quot;);
var decoded;
if (command === &quot;addr&quot;) {
decoded = messages.addr.decodePayload(payload);
console.log(&quot;Got&quot;, decoded.addrs.length, &quot;node addresses&quot;);
}
});
});</code></pre><h2>License</h2><p>bitmessage - JavaScript Bitmessage library</p>
2015-02-14 12:00:58 +01:00
<p>Written in 2014-2015 by Kagami Hiiragi <a href="&#x6d;&#x61;&#105;&#108;&#116;&#x6f;&#x3a;&#x6b;&#97;&#x67;&#97;&#x6d;&#x69;&#x40;&#x67;&#x65;&#x6e;&#x73;&#x68;&#x69;&#x6b;&#101;&#x6e;&#x2e;&#111;&#x72;&#x67;">&#x6b;&#97;&#x67;&#97;&#x6d;&#x69;&#x40;&#x67;&#x65;&#x6e;&#x73;&#x68;&#x69;&#x6b;&#101;&#x6e;&#x2e;&#111;&#x72;&#x67;</a></p>
2015-01-03 17:04:14 +01:00
<p>To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.</p>
<p>You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.</p></article>
</section>
</div>
<nav>
2015-02-14 12:00:58 +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_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>
2015-01-03 17:04:14 +01:00
</nav>
<br class="clear">
<footer>
2015-02-14 12:00:58 +01:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a> on Sat Feb 14 2015 14:00:49 GMT+0300 (MSK)
2015-01-03 17:04:14 +01:00
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>