diff --git a/docs/address.js.html b/docs/address.js.html index 12dd2f0..d83d3ef 100644 --- a/docs/address.js.html +++ b/docs/address.js.html @@ -27,10 +27,23 @@
/**
- * Working with Bitmessage addresses.
+ * Working with Bitmessage addresses.  
+ * **NOTE**: `Address` is exported as a module.
+ * @example
+ * var Address = require("bitmessage").Address;
+ * // Or: var Address = require("bitmessage/address");
+ *
+ * // Generate a new random Bitmessage identity.
+ * var addr1 = Address.fromRandom();
+ * console.log("New random Bitmessage address:", addr1.encode());
+ *
+ * // Or create it from passphrase.
+ * var addr2 = Address.fromPassphrase("test");
+ * console.log("Deterministic Bitmessage address:", addr2.encode());
  * @see {@link https://bitmessage.org/wiki/Address}
  * @module bitmessage/address
  */
+// TODO(Kagami): Document getters/setters.
 
 "use strict";
 
@@ -45,7 +58,16 @@ var popkey = require("./_util").popkey;
 
 /**
  * Create a new Bitmessage address object.
- * @param {?Object} opts - Address options
+ * @param {Object=} opts - Address options
+ * @param {number} opts.version - Version number (4 by default)
+ * @param {number} opts.stream - Stream number (1 by default)
+ * @param {Object} opts.behavior - [Pubkey features]{@link
+ * module:bitmessage/structs.PubkeyBitfield} (`DOES_ACK` by default)
+ * @param {Buffer} opts.signPrivateKey - Signing private key
+ * @param {Buffer} opts.signPublicKey - Signing public key
+ * @param {Buffer} opts.encPrivateKey - Encryption private key
+ * @param {Buffer} opts.encPublicKey - Encryption public key
+ * @param {Buffer} opts.ripe - Keys RIPEMD hash
  * @constructor
  * @static
  */
@@ -75,7 +97,7 @@ Address.prototype.clone = function() {
 };
 
 /**
- * Test if given object is an Address instance.  
+ * Test if the given object is an Address instance.  
  * NOTE: Implementation is just simple `instanceof` but it improves
  * readability and consistent with `isArray`, `isBuffer`, etc.
  * @param {Object} obj - Given object
@@ -126,8 +148,8 @@ function getaddrchecksum(data) {
 }
 
 /**
- * Get the ripe hash of the address without prefix zeroes.
- * @return {Buffer} A short ripe hash.
+ * Get the RIPEMD hash of the address keys without prefix nulls.
+ * @return {Buffer} A short RIPEMD hash.
  */
 Address.prototype.getShortRipe = function() {
   var ripe = this.ripe;
@@ -253,10 +275,15 @@ Address.prototype.encode = function() {
 };
 
 /**
- * Create new Bitmessage address from random encryption and signing
+ * Create a new Bitmessage address with random encryption and signing
  * private keys.
- * @param {?Object} opts - Address options
- * @return {Address} Generated address object.
+ * @param {Object=} opts - Address options
+ * @param {number} opts.ripeLength - Required length of the short RIPEMD
+ * hash (19 by default)
+ * @param {number} opts.version - Version number (4 by default)
+ * @param {number} opts.stream - Stream number (1 by default)
+ * @param {Object} opts.behavior - [Pubkey features]{@link module:bitmessage/structs.PubkeyBitfield} (`DOES_ACK` by default)
+ * @return {Address} New address object.
  */
 Address.fromRandom = function(opts) {
   opts = objectAssign({}, opts);
@@ -286,9 +313,15 @@ Address.fromRandom = function(opts) {
 };
 
 /**
- * Create new Bitmessage address from passphrase.
- * @param {?Object} opts - Address options
- * @return {Address} Generated address object.
+ * Create a new Bitmessage address from passphrase.
+ * @param {(string|Object)} opts - Passphrase or address options
+ * @param {string} opts.passphrase - Passphrase to generate address from
+ * @param {number=} opts.ripeLength - Required length of the short
+ * RIPEMD hash (19 by default)
+ * @param {number=} opts.version - Version number (4 by default)
+ * @param {number=} opts.stream - Stream number (1 by default)
+ * @param {Object=} opts.behavior - [Pubkey features]{@link module:bitmessage/structs.PubkeyBitfield} (`DOES_ACK` by default)
+ * @return {Address} New address object.
  */
 Address.fromPassphrase = function(opts) {
   if (typeof opts === "string") {
@@ -423,13 +456,13 @@ module.exports = Address;
 
 
 
 
 
- Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
diff --git a/docs/crypto.js.html b/docs/crypto.js.html index 6ae5f1c..6a2ffa9 100644 --- a/docs/crypto.js.html +++ b/docs/crypto.js.html @@ -38,7 +38,7 @@ var eccrypto = require("eccrypto"); var assert = require("./_util").assert; var platform = require("./platform"); -var promise = platform.promise; +var PPromise = platform.Promise; /** * Calculate SHA-1 hash. @@ -82,7 +82,7 @@ exports.ripemd160 = platform.ripemd160; exports.randomBytes = platform.randomBytes; /** - * Generate new random private key. + * Generate a new random private key. * @return {Buffer} New private key. */ exports.getPrivate = function() { @@ -114,8 +114,8 @@ exports.sign = function(privateKey, msg) { * @param {Buffer} publicKey - A 65-byte public key * @param {Buffer} msg - The message being verified * @param {Buffer} sig - The signature in DER format - * @return {Promise.<undefined>} A promise that resolves on correct - * signature and rejects on bad key or signature. + * @return {Promise.<null>} A promise that resolves on correct signature + * and rejects on bad key or signature. */ exports.verify = function(publicKey, msg, sig) { var hash = sha1(msg); @@ -174,15 +174,14 @@ var encrypted = exports.encrypted = { * Encrypt message for given recepient's public key. * @param {Buffer} publicKeyTo - Recipient's public key (65 bytes) * @param {Buffer} msg - The message being encrypted - * @param {?{?iv: Buffer, ?ephemPrivateKey: Buffer}} opts - You may also - * specify initialization vector (16 bytes) and ephemeral private key - * (32 bytes) to get deterministic results. - * @return {Promise.<Buffer>} - A promise that resolves with the buffer - * in `encrypted` format successful encryption and rejects on failure. + * @param {Object=} opts - You may also specify initialization vector + * and ephemeral private key to get deterministic results + * @param {Buffer} opts.iv - Initialization vector (16 bytes) + * @param {Buffer} opts.ephemPrivateKey - Ephemeral private key (32 + * bytes) + * @return {Promise.<Buffer>} A promise that resolves with the buffer in + * `encrypted` format successful encryption and rejects on failure. */ -// TODO(Kagami): Properly document `opts`. Documenting multiple -// function arguments with options object at the end for now gives -// strange results (probably a bug in jsdoc). exports.encrypt = function(publicKeyTo, msg, opts) { return eccrypto.encrypt(publicKeyTo, msg, opts).then(function(encObj) { return encrypted.encode(encObj); @@ -194,11 +193,11 @@ exports.encrypt = function(publicKeyTo, msg, opts) { * @param {Buffer} privateKey - A 32-byte private key of recepient of * the mesage * @param {Buffer} buf - Encrypted data - * @return {Promise.<Buffer>} - A promise that resolves with the - * plaintext on successful decryption and rejects on failure. + * @return {Promise.<Buffer>} A promise that resolves with the plaintext + * on successful decryption and rejects on failure. */ exports.decrypt = function(privateKey, buf) { - return new promise(function(resolve) { + return new PPromise(function(resolve) { var encObj = encrypted.decode(buf); resolve(eccrypto.decrypt(privateKey, encObj)); }); @@ -213,13 +212,13 @@ exports.decrypt = function(privateKey, buf) {
- Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
diff --git a/docs/index.html b/docs/index.html index 02e6317..b8533db 100644 --- a/docs/index.html +++ b/docs/index.html @@ -52,19 +52,16 @@
  • Protocol specification
  • Whitepaper
  • -

    Feature matrix (both Browser and Node)

      +

      Feature matrix

      • [x] Crypto
        • [x] SHA-1
        • [x] SHA-256
        • [x] SHA-512
        • [x] RIPEMD-160
        • [x] PRNG
        • -
        • [x] ECC keys manipulation
        • +
        • [x] ECC keys handling
        • [x] ECDSA
        • -
        • [x] ECDH
        • [x] ECIES
        • -
        • [x] AES-256-CBC
        • -
        • [x] HMAC-SHA-256
      • [x] Common structures
          @@ -82,7 +79,6 @@
        • [x] Message types
          • [x] version
          • -
          • [x] verack
          • [x] addr
          • [x] inv
          • [x] getdata
          • @@ -103,18 +99,19 @@
          • [x] UserAgent
        • -
        • [ ] Parse PyBitmessage configs
            +
          • [ ] Network transports
              +
            • [x] TCP (Node.js only)
            • +
            • [x] WebSocket
            • +
            • [ ] WebRTC
            • +
            +
          • +
          • [ ] PyBitmessage configs parsing
            • [ ] keys.dat
            • [ ] knownnodes.dat
            • [ ] messages.dat
          -

          Network feature matrix (Node.js only)

            -
          • [ ] Bootstrap
          • -
          • [ ] Connect to the network
          • -
          • [ ] Accept connections
          • -

          Usage

          Address

          var Address = require("bitmessage").Address;
           
           // Generate a new random Bitmessage identity.
          @@ -123,8 +120,73 @@ console.log("New random Bitmessage address:", addr1.encode());
           
           // Or create it from passphrase.
           var addr2 = Address.fromPassphrase("test");
          -console.log("Deterministic Bitmessage address:", addr2.encode());

          License

          bitmessage - JavaScript Bitmessage library

          -

          Written in 2014 by Kagami Hiiragi kagami@genshiken.org

          +console.log("Deterministic Bitmessage address:", addr2.encode());

    Structures

    var structs = require("bitmessage").structs;
    +
    +var encoded = Buffer.concat([
    +  structs.var_int.encode(4),
    +  Buffer("test"),
    +  structs.var_str.encode("test2"),
    +  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]

    Messages

    var structs = require("bitmessage").structs;
    +var messages = require("bitmessage").messages;
    +
    +// Simple encoding and decoding:
    +var vermsg = messages.version.encode({
    +  nonce: Buffer(8),  // Hack detection connection to self
    +  remoteHost: "1.1.1.1",
    +  remotePort: 8444,
    +});
    +console.log(messages.version.decode(vermsg).remoteHost);  // 1.1.1.1
    +
    +// Low-level encoding and decoding:
    +var addrPayload = messages.addr.encodePayload([
    +  {host: "2.2.2.2", port: 28444},
    +]);
    +var addrmsg = structs.message.encode("addr", 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("verack");
    +console.log(structs.message.decode(verackmsg).command);  // verack

    Network

    var messages = require("bitmessage").messages;
    +var TcpTransport = require("bitmessage/net/tcp");
    +
    +var tcp = new TcpTransport({
    +  dnsSeeds: [["bootstrap8444.bitmessage.org", 8444]],
    +});
    +
    +tcp.bootstrap().then(function(nodes) {
    +  var remoteHost = nodes[0][0];
    +  var remotePort = nodes[0][1];
    +  console.log("Connecting to", nodes[0]);
    +  tcp.connect(remotePort, remoteHost);
    +});
    +
    +tcp.on("established", function() {
    +  console.log("Connection established");
    +
    +  tcp.on("message", function(command, payload) {
    +    console.log("Got new", command, "message");
    +    var decoded;
    +    if (command === "addr") {
    +      decoded = messages.addr.decodePayload(payload);
    +      console.log("Got", decoded.addrs.length, "node addresses");
    +    }
    +  });
    +});

    License

    bitmessage - JavaScript Bitmessage library

    +

    Written in 2014-2015 by Kagami Hiiragi kagami@genshiken.org

    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.

    You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see .

    @@ -137,13 +199,13 @@ console.log("Deterministic Bitmessage address:", addr2.encode());
    diff --git a/docs/index.js.html b/docs/index.js.html index 9e98b79..501a518 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -65,13 +65,13 @@ exports.UserAgent = require("./user-agent");
    diff --git a/docs/messages.js.html b/docs/messages.js.html index f9f63fc..8ec914d 100644 --- a/docs/messages.js.html +++ b/docs/messages.js.html @@ -32,14 +32,41 @@ * @see {@link https://bitmessage.org/wiki/Protocol_specification_v3#Message_types} * @see {@link https://bitmessage.org/Bitmessage%20Technical%20Paper.pdf} * @module bitmessage/messages + * @example + * var structs = require("bitmessage").structs; + * var messages = require("bitmessage").messages; + * + * // Simple encoding and decoding: + * var vermsg = messages.version.encode({ + * nonce: Buffer(8), // Hack detection connection to self + * remoteHost: "1.1.1.1", + * remotePort: 8444, + * }); + * console.log(messages.version.decode(vermsg).remoteHost); // 1.1.1.1 + * + * // Low-level encoding and decoding: + * var addrPayload = messages.addr.encodePayload([ + * {host: "2.2.2.2", port: 28444}, + * ]); + * var addrmsg = structs.message.encode("addr", 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("verack"); + * console.log(structs.message.decode(verackmsg).command); // verack */ -// TODO(Kagami): Document object-like params. "use strict"; var objectAssign = Object.assign || require("object-assign"); +var bufferEqual = require("buffer-equal"); var assert = require("./_util").assert; var structs = require("./structs"); +var bmcrypto = require("./crypto"); var UserAgent = require("./user-agent"); var util = require("./_util"); @@ -51,8 +78,7 @@ var ServicesBitfield = structs.ServicesBitfield; * Note that this function doesn't do any validation because it is * already provided by * [message.decode]{@link module:bitmessage/structs.message.decode} - * routine. Normally you call this for each incoming message and then - * call decode function of the appropriate message handler. + * routine. * @param {Buffer} buf - Buffer that starts with encoded message * @return {?string} Message's command if any. */ @@ -71,24 +97,45 @@ exports.getCommand = function(buf) { return command.slice(0, firstNonNull).toString("ascii"); }; +// Random nonce used to detect connections to self. +var randomNonce = bmcrypto.randomBytes(8); + /** * `version` message. * @see {@link https://bitmessage.org/wiki/Protocol_specification#version} * @namespace * @static */ +// TODO(Kagami): User agent and stream numbers size limits per +// <https://github.com/Bitmessage/PyBitmessage/issues/767>. var version = exports.version = { /** - * Random nonce used to detect connections to self. - * @const {Buffer} + * @typedef {Object} DecodeResult + * @property {Object} services - + * [Service]{@link module:bitmessage/structs.ServicesBitfield} + * features to be enabled for this connection + * @property {Date} time - Node time + * @property {string} remoteHost - IPv4/IPv6 address of the node + * receiving this message + * @property {number} remotePort - Port of the node receiving this + * message + * @property {number} port - Incoming port of the node sending this + * message + * @property {Buffer} nonce - Random nonce used to detect connection + * to self + * @property {(Array|string|Buffer)} userAgent - + * [User agent]{@link module:bitmessage/user-agent} of the node + * @property {number[]} streamNumbers - Streams accepted by the node + * @property {number} length - Real data length + * @memberof module:bitmessage/messages.version */ - NONCE: new Buffer("20bde0a3355dad78", "hex"), /** - * Decode `version` message. + * Decode `version` message. * NOTE: `nonce` is copied. * @param {Buffer} buf - Message - * @return {Object} Decoded `version` structure. + * @return {DecodeResult} + * [Decoded `version` structure.]{@link module:bitmessage/messages.version.DecodeResult} */ decode: function(buf) { var decoded = message.decode(buf); @@ -98,9 +145,7 @@ var version = exports.version = { /** * Decode `version` message payload. - * NOTE: `nonce` is copied. - * @param {Buffer} buf - Message payload - * @return {Object} Decoded `version` structure. + * The same as [decode]{@link module:bitmessage/messages.version.decode}. */ decodePayload: function(buf) { // 4 + 8 + 8 + 26 + 26 + 8 + (1+) + (1+) @@ -113,6 +158,7 @@ var version = exports.version = { var addrFrom = structs.net_addr.decode(buf.slice(46, 72), short); var nonce = new Buffer(8); buf.copy(nonce, 0, 72, 80); + assert(!bufferEqual(nonce, randomNonce), "Connection to self"); var decodedUa = UserAgent.decode(buf.slice(80)); var decodedStreamNumbers = structs.var_int_list.decode(decodedUa.rest); return { @@ -136,6 +182,24 @@ var version = exports.version = { /** * Encode `version` message. * @param {Object} opts - Version options + * @param {Object=} opts.services - + * [Service]{@link module:bitmessage/structs.ServicesBitfield} + * features to be enabled for this connection (`NODE_NETWORK` by + * default) + * @param {Date=} opts.time - Node time (current time by default) + * @param {string} opts.remoteHost - IPv4/IPv6 address of the node + * receiving this message + * @param {number} opts.remotePort - Port of the node receiving this + * message + * @param {number=} opts.port - Incoming port of the node (8444 by + * default) + * @param {Buffer=} opts.nonce - Random nonce used to detect connection + * to self (unique per node.js process by default) + * @param {(Array|string|Buffer)=} opts.userAgent - + * [User agent]{@link module:bitmessage/user-agent} of the node + * (bitmessage's by default) + * @param {Array<number>=} opts.streamNumbers - Streams accepted by the + * node (1 by default) * @return {Buffer} Encoded message. */ encode: function(opts) { @@ -145,16 +209,16 @@ var version = exports.version = { /** * Encode `version` message payload. - * @param {Object} opts - Version options - * @return {Buffer} Encoded payload. + * The same as [encode]{@link module:bitmessage/messages.version.encode}. */ encodePayload: function(opts) { // Deal with default options. var services = opts.services || ServicesBitfield().set(ServicesBitfield.NODE_NETWORK); var time = opts.time || new Date(); - var nonce = opts.nonce || version.NONCE; + var nonce = opts.nonce || randomNonce; assert(nonce.length === 8, "Bad nonce"); + var port = opts.port || 8444; var userAgent = opts.userAgent || UserAgent.SELF; var streamNumbers = opts.streamNumbers || [1]; // Start encoding. @@ -169,7 +233,7 @@ var version = exports.version = { var addrFrom = structs.net_addr.encode({ services: services, host: "127.0.0.1", - port: opts.port, + port: port, short: true, }); return Buffer.concat([ @@ -192,10 +256,19 @@ var version = exports.version = { * @static */ var addr = exports.addr = { + /** + * @typedef {Object} DecodeResult + * @property {Object[]} addrs - List of + * [decoded `net_addr` structures]{@link module:bitmessage/structs.net_addr.DecodeResult} + * @property {number} length - Real data length + * @memberof module:bitmessage/messages.addr + */ + /** * Decode `addr` message. * @param {Buffer} buf - Message - * @return {Object} Decoded `addr` structure. + * @return {DecodeResult} + * [Decoded `addr` structure.]{@link module:bitmessage/messages.addr.DecodeResult} */ decode: function(buf) { var decoded = message.decode(buf); @@ -205,8 +278,7 @@ var addr = exports.addr = { /** * Decode `addr` message payload. - * @param {Buffer} buf - Message payload - * @return {Object} Decoded `addr` structure. + * The same as [decode]{@link module:bitmessage/messages.addr.decode}. */ decodePayload: function(buf) { var decoded = structs.var_int.decode(buf); @@ -228,7 +300,8 @@ var addr = exports.addr = { /** * Encode `addr` message. - * @param {Object[]} addrs - Network addresses + * @param {Object[]} addrs - List of + * [net_addr encode options]{@link module:bitmessage/structs.net_addr.encode} * @return {Buffer} Encoded message. */ encode: function(addrs) { @@ -238,13 +311,13 @@ var addr = exports.addr = { /** * Encode `addr` message payload. - * @param {Object[]} addrs - Network addresses - * @return {Buffer} Encoded payload. + * The same as [encode]{@link module:bitmessage/messages.addr.encode}. */ encodePayload: function(addrs) { assert(addrs.length <= 1000, "Too many address entires"); - var addrsBuf = Buffer.concat(addrs.map(structs.net_addr.encode)); - return Buffer.concat([structs.var_int.encode(addrs.length), addrsBuf]); + var addrBufs = addrs.map(structs.net_addr.encode); + var bufs = [structs.var_int.encode(addrs.length)].concat(addrBufs); + return Buffer.concat(bufs); }, }; @@ -256,10 +329,19 @@ var addr = exports.addr = { * @static */ var inv = exports.inv = { + /** + * @typedef {Object} DecodeResult + * @property {Buffer[]} inventory - List of + * [inventory vectors]{@link module:bitmessage/structs.inv_vect} + * @property {number} length - Real data length + * @memberof module:bitmessage/messages.inv + */ + /** * Decode `inv` message. * @param {Buffer} buf - Message - * @return {Object} Decoded `inv` structure. + * @return {DecodeResult} + * [Decoded `inv` structure.]{@link module:bitmessage/messages.inv.DecodeResult} */ decode: function(buf) { var decoded = message.decode(buf); @@ -269,8 +351,7 @@ var inv = exports.inv = { /** * Decode `inv` message payload. - * @param {Buffer} buf - Message payload - * @return {Object} Decoded `inv` structure. + * The same as [decode]{@link module:bitmessage/messages.inv.decode}. */ decodePayload: function(buf) { var decoded = structs.var_int.decode(buf); @@ -292,7 +373,8 @@ var inv = exports.inv = { /** * Encode `inv` message. - * @param {Buffer[]} inventory - Inventory vector list + * @param {Buffer[]} inventory - + * [Inventory vector]{@link module:bitmessage/structs.inv_vect} list * @return {Buffer} Encoded message. */ encode: function(inventory) { @@ -302,13 +384,13 @@ var inv = exports.inv = { /** * Encode `inv` message payload. - * @param {Buffer[]} inventory - Inventory vector list - * @return {Buffer} Encoded payload. + * The same as [encode]{@link module:bitmessage/messages.inv.encode}. */ encodePayload: function(inventory) { assert(inventory.length <= 50000, "Too many inventory entires"); - var invBuf = Buffer.concat(inventory); - return Buffer.concat([structs.var_int.encode(inventory.length), invBuf]); + // TODO(Kagami): Validate vectors length. + var bufs = [structs.var_int.encode(inventory.length)].concat(inventory); + return Buffer.concat(bufs); }, }; @@ -320,10 +402,19 @@ var inv = exports.inv = { * @namespace */ exports.getdata = objectAssign({}, inv, { + /** + * @typedef {Object} DecodeResult + * @property {Buffer[]} inventory - List of + * [inventory vectors]{@link module:bitmessage/structs.inv_vect} + * @property {number} length - Real data length + * @memberof module:bitmessage/messages.getdata + */ + /** * Decode `getdata` message. * @param {Buffer} buf - Message - * @return {Object} Decoded `getdata` structure. + * @return {DecodeResult} + * [Decoded `getdata` structure.]{@link module:bitmessage/messages.getdata.DecodeResult} * @memberof module:bitmessage/messages.getdata */ decode: function(buf) { @@ -331,9 +422,18 @@ exports.getdata = objectAssign({}, inv, { assert(decoded.command === "getdata", "Bad command"); return inv.decodePayload(decoded.payload); }, + + /** + * Decode `getdata` message payload. + * The same as [decode]{@link module:bitmessage/messages.getdata.decode}. + * @function decodePayload + * @memberof module:bitmessage/messages.getdata + */ + /** * Encode `getdata` message. - * @param {Buffer[]} inventory - Inventory vector list + * @param {Buffer[]} inventory - + * [Inventory vector]{@link module:bitmessage/structs.inv_vect} list * @return {Buffer} Encoded message. * @memberof module:bitmessage/messages.getdata */ @@ -341,17 +441,10 @@ exports.getdata = objectAssign({}, inv, { var payload = inv.encodePayload(inventory); return message.encode("getdata", payload); }, - /** - * Decode `getdata` message payload. - * @param {Buffer} buf - Message payload - * @return {Object} Decoded `inv` structure. - * @function decodePayload - * @memberof module:bitmessage/messages.getdata - */ + /** * Encode `getdata` message payload. - * @param {Buffer[]} inventory - Inventory vector list - * @return {Buffer} Encoded payload. + * The same as [encode]{@link module:bitmessage/messages.getdata.encode}. * @function encodePayload * @memberof module:bitmessage/messages.getdata */ @@ -383,10 +476,24 @@ var error = exports.error = { */ FATAL: 2, + /** + * @typedef {Object} DecodeResult + * @property {number} fatal - Type of the error + * @property {number} banTime - The other node informs that it will + * not accept further connections for this number of seconds + * @property {?Buffer} vector - + * [Inventory vector]{@link module:bitmessage/structs.inv_vect} + * related to the error + * @property {string} errorText - A human-readable error description + * @property {number} length - Real data length + * @memberof module:bitmessage/messages.error + */ + /** * Decode `error` message. * @param {Buffer} buf - Message - * @return {Object} Decoded `error` structure. + * @return {DecodeResult} + * [Decoded `error` structure.]{@link module:bitmessage/messages.error.DecodeResult} */ decode: function(buf) { var decoded = message.decode(buf); @@ -396,25 +503,37 @@ var error = exports.error = { /** * Decode `error` message payload. - * @param {Buffer} buf - Message payload - * @return {Object} Decoded `error` structure. + * The same as [decode]{@link module:bitmessage/messages.error.decode}. */ decodePayload: function(buf) { assert(buf.length >= 4, "Buffer is too small"); var decodedFatal = structs.var_int.decode(buf); var decodedBanTime = structs.var_int.decode(decodedFatal.rest); - var decodedVector = structs.var_str.decode(decodedBanTime.rest); - var decodedErrorText = structs.var_str.decode(decodedVector.rest); + + var decodedVectorLength = structs.var_int.decode(decodedBanTime.rest); + // NOTE(Kagami): Inventory vector should be only 32-byte in size but + // currently we don't ensure it. + var vectorLength = decodedVectorLength.value; + var rest = decodedVectorLength.rest; + assert(rest.length >= vectorLength, "Buffer is too small"); + var vector = null; + if (vectorLength) { + vector = new Buffer(vectorLength); + rest.copy(vector); + rest = rest.slice(vectorLength); + } + + var decodedErrorText = structs.var_str.decode(rest); var length = ( decodedFatal.length + decodedBanTime.length + - decodedVector.length + + decodedVectorLength.length + vectorLength + decodedErrorText.length ); return { fatal: decodedFatal.value, banTime: decodedBanTime.value, - vector: decodedVector.str, + vector: vector, errorText: decodedErrorText.str, // Real data length. length: length, @@ -424,6 +543,16 @@ var error = exports.error = { /** * Encode `error` message. * @param {Object} opts - Error options + * @param {number=} opts.fatal - Type of the error + * ([warning]{@link module:bitmessage/messages.error.WARNING} by + * default) + * @param {number=} opts.banTime - Inform the other node, that you + * will not accept further connections for this number of seconds (0 + * by default) + * @param {Buffer=} opts.vector - A 32-byte + * [inventory vector]{@link module:bitmessage/structs.inv_vect} + * related to the error (empty by default) + * @param {string} opts.errorText - A human-readable error description * @return {Buffer} Encoded message. */ encode: function(opts) { @@ -433,19 +562,19 @@ var error = exports.error = { /** * Encode `error` message payload. - * @param {Object} opts - Error options - * @return {Buffer} Encoded payload. + * The same as [encode]{@link module:bitmessage/messages.error.encode}. */ encodePayload: function(opts) { var fatal = opts.fatal || error.WARNING; var banTime = opts.banTime || 0; - var vector = opts.vector || ""; - var errorText = opts.errorText || ""; + // TODO(Kagami): Validate vector length. + var vector = opts.vector || new Buffer(0); return Buffer.concat([ structs.var_int.encode(fatal), structs.var_int.encode(banTime), - structs.var_str.encode(vector), - structs.var_str.encode(errorText), + structs.var_int.encode(vector.length), + vector, + structs.var_str.encode(opts.errorText), ]); }, }; @@ -459,13 +588,13 @@ var error = exports.error = {
    diff --git a/docs/module-bitmessage.html b/docs/module-bitmessage.html index 14f81f1..55584b8 100644 --- a/docs/module-bitmessage.html +++ b/docs/module-bitmessage.html @@ -654,13 +654,13 @@
    diff --git a/docs/module-bitmessage_address.Address.html b/docs/module-bitmessage_address.Address.html index c880a6d..47cb860 100644 --- a/docs/module-bitmessage_address.Address.html +++ b/docs/module-bitmessage_address.Address.html @@ -44,7 +44,7 @@ -

    new Address(optsnullable)

    +

    new Address(optsopt)

    @@ -104,9 +104,9 @@ - + <optional>
    - <nullable>
    + @@ -115,7 +115,217 @@ -

    Address options

    +

    Address options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    version + + +number + + + +

    Version number (4 by default)

    stream + + +number + + + +

    Stream number (1 by default)

    behavior + + +Object + + + +

    Pubkey features (DOES_ACK by default)

    signPrivateKey + + +Buffer + + + +

    Signing private key

    signPublicKey + + +Buffer + + + +

    Signing public key

    encPrivateKey + + +Buffer + + + +

    Encryption private key

    encPublicKey + + +Buffer + + + +

    Encryption public key

    ripe + + +Buffer + + + +

    Keys RIPEMD hash

    + + @@ -156,7 +366,7 @@
    Source:
    @@ -305,7 +515,7 @@
    Source:
    @@ -358,14 +568,14 @@ -

    (static) fromPassphrase(optsnullable) → {Address}

    +

    (static) fromPassphrase(opts) → {Address}

    -

    Create new Bitmessage address from passphrase.

    +

    Create a new Bitmessage address from passphrase.

    @@ -389,6 +599,51 @@ Type + + + + Description + + + + + + + + + opts + + + + + +string +| + +Object + + + + + + + + + +

    Passphrase or address options

    +
    Properties
    + + + + + + + + + + + + @@ -403,7 +658,138 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributes
    optspassphrase + + +string + + + + + + + + + +

    Passphrase to generate address from

    ripeLength + + +number + + + + + + <optional>
    + + + + + +

    Required length of the short +RIPEMD hash (19 by default)

    version + + +number + + + + + + <optional>
    + + + + + +

    Version number (4 by default)

    stream + + +number + + + + + + <optional>
    + + + + + +

    Stream number (1 by default)

    behavior @@ -418,9 +804,9 @@ - + <optional>
    - <nullable>
    + @@ -429,7 +815,14 @@ -

    Address options

    Pubkey features (DOES_ACK by default)

    + + @@ -470,7 +863,7 @@
    Source:
    @@ -497,7 +890,7 @@
    -

    Generated address object.

    +

    New address object.

    @@ -523,14 +916,14 @@ -

    (static) fromRandom(optsnullable) → {Address}

    +

    (static) fromRandom(optsopt) → {Address}

    -

    Create new Bitmessage address from random encryption and signing +

    Create a new Bitmessage address with random encryption and signing private keys.

    @@ -584,9 +977,9 @@ private keys.

    - + <optional>
    - <nullable>
    + @@ -595,7 +988,126 @@ private keys.

    -

    Address options

    +

    Address options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    ripeLength + + +number + + + +

    Required length of the short RIPEMD +hash (19 by default)

    version + + +number + + + +

    Version number (4 by default)

    stream + + +number + + + +

    Stream number (1 by default)

    behavior + + +Object + + + +

    Pubkey features (DOES_ACK by default)

    + + @@ -636,7 +1148,7 @@ private keys.

    Source:
    @@ -663,7 +1175,7 @@ private keys.

    -

    Generated address object.

    +

    New address object.

    @@ -696,7 +1208,7 @@ private keys.

    -

    Test if given object is an Address instance.
    NOTE: Implementation is just simple instanceof but it improves +

    Test if the given object is an Address instance.
    NOTE: Implementation is just simple instanceof but it improves readability and consistent with isArray, isBuffer, etc.

    @@ -790,7 +1302,7 @@ readability and consistent with isArray, isBuffer, etc
    Source:
    @@ -890,7 +1402,7 @@ readability and consistent with isArray, isBuffer, etc
    Source:
    @@ -994,7 +1506,7 @@ readability and consistent with isArray, isBuffer, etc
    Source:
    @@ -1099,7 +1611,7 @@ readability and consistent with isArray, isBuffer, etc
    Source:
    @@ -1205,7 +1717,7 @@ encrypt/decrypt
    Source:
    @@ -1310,7 +1822,7 @@ encrypt/decrypt
    Source:
    @@ -1416,7 +1928,7 @@ encrypt/decrypt
    Source:
    @@ -1476,7 +1988,7 @@ encrypt/decrypt
    -

    Get the ripe hash of the address without prefix zeroes.

    +

    Get the RIPEMD hash of the address keys without prefix nulls.

    @@ -1520,7 +2032,7 @@ encrypt/decrypt
    Source:
    @@ -1547,7 +2059,7 @@ encrypt/decrypt
    -

    A short ripe hash.

    +

    A short RIPEMD hash.

    @@ -1624,7 +2136,7 @@ encrypt/decrypt
    Source:
    @@ -1688,13 +2200,13 @@ encrypt/decrypt
    diff --git a/docs/module-bitmessage_address.html b/docs/module-bitmessage_address.html index ebeeb2a..689fd4c 100644 --- a/docs/module-bitmessage_address.html +++ b/docs/module-bitmessage_address.html @@ -38,7 +38,7 @@
    -

    Working with Bitmessage addresses.

    +

    Working with Bitmessage addresses.
    NOTE: Address is exported as a module.

    @@ -119,6 +119,20 @@ +
    Example
    + +
    var Address = require("bitmessage").Address;
    +// Or: var Address = require("bitmessage/address");
    +
    +// Generate a new random Bitmessage identity.
    +var addr1 = Address.fromRandom();
    +console.log("New random Bitmessage address:", addr1.encode());
    +
    +// Or create it from passphrase.
    +var addr2 = Address.fromPassphrase("test");
    +console.log("Deterministic Bitmessage address:", addr2.encode());
    + + @@ -158,13 +172,13 @@

    diff --git a/docs/module-bitmessage_crypto.html b/docs/module-bitmessage_crypto.html index 96217ae..9450ece 100644 --- a/docs/module-bitmessage_crypto.html +++ b/docs/module-bitmessage_crypto.html @@ -262,7 +262,7 @@ the mesage

    Source:
    @@ -289,10 +289,8 @@ the mesage

    - +

    A promise that resolves with the plaintext +on successful decryption and rejects on failure.

    @@ -318,7 +316,7 @@ plaintext on successful decryption and rejects on failure. -

    (static) encrypt(publicKeyTo, msg, optsnullable) → {Promise.<Buffer>}

    +

    (static) encrypt(publicKeyTo, msg, optsopt) → {Promise.<Buffer>}

    @@ -440,9 +438,9 @@ plaintext on successful decryption and rejects on failure. - + <optional>
    - <nullable>
    + @@ -451,9 +449,81 @@ plaintext on successful decryption and rejects on failure. -

    You may also -specify initialization vector (16 bytes) and ephemeral private key -(32 bytes) to get deterministic results.

    +

    You may also specify initialization vector +and ephemeral private key to get deterministic results

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    iv + + +Buffer + + + +

    Initialization vector (16 bytes)

    ephemPrivateKey + + +Buffer + + + +

    Ephemeral private key (32 +bytes)

    + + @@ -494,7 +564,7 @@ specify initialization vector (16 bytes) and ephemeral private key
    Source:
    @@ -521,10 +591,8 @@ specify initialization vector (16 bytes) and ephemeral private key
    - +

    A promise that resolves with the buffer in +encrypted format successful encryption and rejects on failure.

    @@ -557,7 +625,7 @@ in encrypted format successful encryption and rejects on failure. -

    Generate new random private key.

    +

    Generate a new random private key.

    @@ -1749,7 +1817,7 @@ format when fulfilled.

    -

    (static) verify(publicKey, msg, sig) → {Promise.<undefined>}

    +

    (static) verify(publicKey, msg, sig) → {Promise.<null>}

    @@ -1922,8 +1990,8 @@ format when fulfilled.

    -

    A promise that resolves on correct -signature and rejects on bad key or signature.

    +

    A promise that resolves on correct signature +and rejects on bad key or signature.

    @@ -1934,7 +2002,7 @@ signature and rejects on bad key or signature.

    -Promise.<undefined> +Promise.<null>
    @@ -1960,13 +2028,13 @@ signature and rejects on bad key or signature.


    diff --git a/docs/module-bitmessage_messages.addr.html b/docs/module-bitmessage_messages.addr.html index 9889a8c..c985658 100644 --- a/docs/module-bitmessage_messages.addr.html +++ b/docs/module-bitmessage_messages.addr.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -219,7 +219,7 @@
    Source:
    @@ -246,7 +246,7 @@
    -

    Decoded addr structure.

    +

    Decoded addr structure.

    @@ -257,7 +257,7 @@
    -Object +DecodeResult
    @@ -272,14 +272,15 @@ -

    (static) decodePayload(buf) → {Object}

    +

    (static) decodePayload()

    -

    Decode addr message payload.

    +

    Decode addr message payload. +The same as decode.

    @@ -290,55 +291,6 @@ -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    buf - - -Buffer - - - -

    Message payload

    - - @@ -372,7 +324,7 @@
    Source:
    @@ -395,28 +347,6 @@ -
    Returns:
    - - -
    -

    Decoded addr structure.

    -
    - - - -
    -
    - Type -
    -
    - -Object - - -
    -
    - - @@ -484,7 +414,8 @@ -

    Network addresses

    +

    List of +net_addr encode options

    @@ -525,7 +456,7 @@
    Source:
    @@ -578,14 +509,15 @@ -

    (static) encodePayload(addrs) → {Buffer}

    +

    (static) encodePayload()

    -

    Encode addr message payload.

    +

    Encode addr message payload. +The same as encode.

    @@ -596,10 +528,99 @@ -
    Parameters:
    + + + + +
    + - + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    + + + + + + +
    Properties:
    + + + +
    @@ -637,7 +658,31 @@ - + + + + + + + + + + + + + + + + + @@ -647,8 +692,6 @@ - -
    @@ -678,7 +721,7 @@
    Source:
    @@ -694,41 +737,7 @@ - - - - - - - -
    Returns:
    - - -
    -

    Encoded payload.

    -
    - - - -
    -
    - Type -
    -
    - -Buffer - - -
    -
    - - - - - - - - + @@ -742,13 +751,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_messages.error.html b/docs/module-bitmessage_messages.error.html index 624d833..364918b 100644 --- a/docs/module-bitmessage_messages.error.html +++ b/docs/module-bitmessage_messages.error.html @@ -76,7 +76,7 @@
    Source:
    @@ -168,7 +168,7 @@
    Source:
    @@ -241,7 +241,7 @@ maybe ban you for some time.

    Source:
    @@ -313,7 +313,7 @@ maybe ban you for some time.

    Source:
    @@ -340,7 +340,7 @@ maybe ban you for some time.

    -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -440,7 +440,7 @@ maybe ban you for some time.

    Source:
    @@ -467,7 +467,7 @@ maybe ban you for some time.

    -

    Decoded error structure.

    +

    Decoded error structure.

    @@ -478,7 +478,7 @@ maybe ban you for some time.

    -Object +DecodeResult
    @@ -493,14 +493,15 @@ maybe ban you for some time.

    -

    (static) decodePayload(buf) → {Object}

    +

    (static) decodePayload()

    -

    Decode error message payload.

    +

    Decode error message payload. +The same as decode.

    @@ -511,55 +512,6 @@ maybe ban you for some time.

    -
    Parameters:
    - - -

    Network addresses

    List of +decoded net_addr structures

    length + + +number + + + +

    Real data length

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    buf - - -Buffer - - - -

    Message payload

    - - @@ -593,7 +545,7 @@ maybe ban you for some time.

    Source:
    @@ -616,28 +568,6 @@ maybe ban you for some time.

    -
    Returns:
    - - -
    -

    Decoded error structure.

    -
    - - - -
    -
    - Type -
    -
    - -Object - - -
    -
    - - @@ -705,7 +635,171 @@ maybe ban you for some time.

    -

    Error options

    +

    Error options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    fatal + + +number + + + + + + <optional>
    + + + + + +

    Type of the error +(warning by +default)

    banTime + + +number + + + + + + <optional>
    + + + + + +

    Inform the other node, that you +will not accept further connections for this number of seconds (0 +by default)

    vector + + +Buffer + + + + + + <optional>
    + + + + + +

    A 32-byte +inventory vector +related to the error (empty by default)

    errorText + + +string + + + + + + + + + +

    A human-readable error description

    + + @@ -746,7 +840,7 @@ maybe ban you for some time.

    Source:
    @@ -799,14 +893,15 @@ maybe ban you for some time.

    -

    (static) encodePayload(opts) → {Buffer}

    +

    (static) encodePayload()

    -

    Encode error message payload.

    +

    Encode error message payload. +The same as encode.

    @@ -817,55 +912,6 @@ maybe ban you for some time.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    Error options

    - - @@ -899,7 +945,7 @@ maybe ban you for some time.

    Source:
    @@ -922,34 +968,264 @@ maybe ban you for some time.

    -
    Returns:
    + + -
    -

    Encoded payload.

    -
    + + +

    Type Definitions

    - -
    -
    - Type -
    -
    + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    fatal + + +number + + + + + + + +

    Type of the error

    banTime + + +number + + + + + + + +

    The other node informs that it will +not accept further connections for this number of seconds

    vector + + Buffer - + + + + + + <nullable>
    + +

    Inventory vector +related to the error

    errorText + + +string + + + + + + + +

    A human-readable error description

    length + + +number + + + + + + + +

    Real data length

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + +
    - - - + + @@ -963,13 +1239,13 @@ maybe ban you for some time.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_messages.getdata.html b/docs/module-bitmessage_messages.getdata.html index d907331..c91da55 100644 --- a/docs/module-bitmessage_messages.getdata.html +++ b/docs/module-bitmessage_messages.getdata.html @@ -78,7 +78,7 @@ content of a specific object after filtering known elements.

    Source:
    @@ -121,7 +121,7 @@ content of a specific object after filtering known elements.

    -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -221,7 +221,7 @@ content of a specific object after filtering known elements.

    Source:
    @@ -248,7 +248,7 @@ content of a specific object after filtering known elements.

    -

    Decoded getdata structure.

    +

    Decoded getdata structure.

    @@ -259,7 +259,7 @@ content of a specific object after filtering known elements.

    -Object +DecodeResult
    @@ -274,14 +274,15 @@ content of a specific object after filtering known elements.

    -

    (static) decodePayload(buf) → {Object}

    +

    (static) decodePayload()

    -

    Decode getdata message payload.

    +

    Decode getdata message payload. +The same as decode.

    @@ -292,55 +293,6 @@ content of a specific object after filtering known elements.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    buf - - -Buffer - - - -

    Message payload

    - - @@ -374,7 +326,7 @@ content of a specific object after filtering known elements.

    Source:
    @@ -397,28 +349,6 @@ content of a specific object after filtering known elements.

    -
    Returns:
    - - -
    -

    Decoded inv structure.

    -
    - - - -
    -
    - Type -
    -
    - -Object - - -
    -
    - - @@ -486,7 +416,7 @@ content of a specific object after filtering known elements.

    -

    Inventory vector list

    +

    Inventory vector list

    @@ -527,7 +457,7 @@ content of a specific object after filtering known elements.

    Source:
    @@ -580,14 +510,15 @@ content of a specific object after filtering known elements.

    -

    (static) encodePayload(inventory) → {Buffer}

    +

    (static) encodePayload()

    -

    Encode getdata message payload.

    +

    Encode getdata message payload. +The same as encode.

    @@ -598,10 +529,99 @@ content of a specific object after filtering known elements.

    -
    Parameters:
    + + + + +
    + - + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + +
    @@ -639,7 +659,31 @@ content of a specific object after filtering known elements.

    - + + + + + + + + + + + + + + + + + @@ -649,8 +693,6 @@ content of a specific object after filtering known elements.

    - -
    @@ -680,7 +722,7 @@ content of a specific object after filtering known elements.

    Source:
    @@ -696,41 +738,7 @@ content of a specific object after filtering known elements.

    - - - - - - - -
    Returns:
    - - -
    -

    Encoded payload.

    -
    - - - -
    -
    - Type -
    -
    - -Buffer - - -
    -
    - - - - - - - - + @@ -744,13 +752,13 @@ content of a specific object after filtering known elements.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_messages.html b/docs/module-bitmessage_messages.html index 53ec610..eb59fd3 100644 --- a/docs/module-bitmessage_messages.html +++ b/docs/module-bitmessage_messages.html @@ -123,6 +123,35 @@ +
    Example
    + +
    var structs = require("bitmessage").structs;
    +var messages = require("bitmessage").messages;
    +
    +// Simple encoding and decoding:
    +var vermsg = messages.version.encode({
    +  nonce: Buffer(8),  // Hack detection connection to self
    +  remoteHost: "1.1.1.1",
    +  remotePort: 8444,
    +});
    +console.log(messages.version.decode(vermsg).remoteHost);  // 1.1.1.1
    +
    +// Low-level encoding and decoding:
    +var addrPayload = messages.addr.encodePayload([
    +  {host: "2.2.2.2", port: 28444},
    +]);
    +var addrmsg = structs.message.encode("addr", 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("verack");
    +console.log(structs.message.decode(verackmsg).command);  // verack
    + + @@ -178,8 +207,7 @@ Note that this function doesn't do any validation because it is already provided by message.decode -routine. Normally you call this for each incoming message and then -call decode function of the appropriate message handler.

    +routine.

    @@ -272,7 +300,7 @@ call decode function of the appropriate message handler.

    Source:
    @@ -336,13 +364,13 @@ call decode function of the appropriate message handler.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_messages.inv.html b/docs/module-bitmessage_messages.inv.html index d47255f..ecf9ecb 100644 --- a/docs/module-bitmessage_messages.inv.html +++ b/docs/module-bitmessage_messages.inv.html @@ -77,7 +77,7 @@ more objects.

    Source:
    @@ -120,7 +120,7 @@ more objects.

    -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -220,7 +220,7 @@ more objects.

    Source:
    @@ -247,7 +247,7 @@ more objects.

    -

    Decoded inv structure.

    +

    Decoded inv structure.

    @@ -258,7 +258,7 @@ more objects.

    -Object +DecodeResult
    @@ -273,14 +273,15 @@ more objects.

    -

    (static) decodePayload(buf) → {Object}

    +

    (static) decodePayload()

    -

    Decode inv message payload.

    +

    Decode inv message payload. +The same as decode.

    @@ -291,55 +292,6 @@ more objects.

    -
    Parameters:
    - - -

    Inventory vector list

    List of +inventory vectors

    length + + +number + + + +

    Real data length

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    buf - - -Buffer - - - -

    Message payload

    - - @@ -373,7 +325,7 @@ more objects.

    Source:
    @@ -396,28 +348,6 @@ more objects.

    -
    Returns:
    - - -
    -

    Decoded inv structure.

    -
    - - - -
    -
    - Type -
    -
    - -Object - - -
    -
    - - @@ -485,7 +415,7 @@ more objects.

    -

    Inventory vector list

    +

    Inventory vector list

    @@ -526,7 +456,7 @@ more objects.

    Source:
    @@ -579,14 +509,15 @@ more objects.

    -

    (static) encodePayload(inventory) → {Buffer}

    +

    (static) encodePayload()

    -

    Encode inv message payload.

    +

    Encode inv message payload. +The same as encode.

    @@ -597,10 +528,99 @@ more objects.

    -
    Parameters:
    + + + + +
    + - + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + +
    @@ -638,7 +658,31 @@ more objects.

    - + + + + + + + + + + + + + + + + + @@ -648,8 +692,6 @@ more objects.

    - -
    @@ -679,7 +721,7 @@ more objects.

    Source:
    @@ -695,41 +737,7 @@ more objects.

    - - - - - - - -
    Returns:
    - - -
    -

    Encoded payload.

    -
    - - - -
    -
    - Type -
    -
    - -Buffer - - -
    -
    - - - - - - - - + @@ -743,13 +751,13 @@ more objects.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_messages.version.html b/docs/module-bitmessage_messages.version.html index 087aadd..1dcd8eb 100644 --- a/docs/module-bitmessage_messages.version.html +++ b/docs/module-bitmessage_messages.version.html @@ -76,7 +76,7 @@
    Source:
    @@ -110,82 +110,6 @@ -

    Members

    - - - -

    (static, constant) NONCE :Buffer

    - - - - -
    -

    Random nonce used to detect connections to self.

    -
    - - - -
    Type:
    -
      -
    • - -Buffer - - -
    • -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Source:
    -
    - - - - - - - -
    - - - - - - - -

    Methods

    @@ -195,15 +119,14 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    -

    Decode version message. -NOTE: nonce is copied.

    +

    Decode version message.
    NOTE: nonce is copied.

    @@ -296,7 +219,7 @@ NOTE: nonce is copied.

    Source:
    @@ -323,7 +246,7 @@ NOTE: nonce is copied.

    -

    Decoded version structure.

    +

    Decoded version structure.

    @@ -334,7 +257,7 @@ NOTE: nonce is copied.

    -Object +DecodeResult
    @@ -349,7 +272,7 @@ NOTE: nonce is copied.

    -

    (static) decodePayload(buf) → {Object}

    +

    (static) decodePayload()

    @@ -357,7 +280,7 @@ NOTE: nonce is copied.

    Decode version message payload. -NOTE: nonce is copied.

    +The same as decode.

    @@ -368,55 +291,6 @@ NOTE: nonce is copied.

    -
    Parameters:
    - - -

    Inventory vector list

    List of +inventory vectors

    length + + +number + + + +

    Real data length

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    buf - - -Buffer - - - -

    Message payload

    - - @@ -450,7 +324,7 @@ NOTE: nonce is copied.

    Source:
    @@ -473,28 +347,6 @@ NOTE: nonce is copied.

    -
    Returns:
    - - -
    -

    Decoded version structure.

    -
    - - - -
    -
    - Type -
    -
    - -Object - - -
    -
    - - @@ -562,7 +414,309 @@ NOTE: nonce is copied.

    -

    Version options

    +

    Version options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    services + + +Object + + + + + + <optional>
    + + + + + +

    Service +features to be enabled for this connection (NODE_NETWORK by +default)

    time + + +Date + + + + + + <optional>
    + + + + + +

    Node time (current time by default)

    remoteHost + + +string + + + + + + + + + +

    IPv4/IPv6 address of the node +receiving this message

    remotePort + + +number + + + + + + + + + +

    Port of the node receiving this +message

    port + + +number + + + + + + <optional>
    + + + + + +

    Incoming port of the node (8444 by +default)

    nonce + + +Buffer + + + + + + <optional>
    + + + + + +

    Random nonce used to detect connection +to self (unique per node.js process by default)

    userAgent + + +Array +| + +string +| + +Buffer + + + + + + <optional>
    + + + + + +

    User agent of the node +(bitmessage's by default)

    streamNumbers + + +Array.<number> + + + + + + <optional>
    + + + + + +

    Streams accepted by the +node (1 by default)

    + + @@ -603,7 +757,7 @@ NOTE: nonce is copied.

    Source:
    @@ -656,14 +810,15 @@ NOTE: nonce is copied.

    -

    (static) encodePayload(opts) → {Buffer}

    +

    (static) encodePayload()

    -

    Encode version message payload.

    +

    Encode version message payload. +The same as encode.

    @@ -674,55 +829,6 @@ NOTE: nonce is copied.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    Version options

    - - @@ -756,7 +862,7 @@ NOTE: nonce is copied.

    Source:
    @@ -779,34 +885,331 @@ NOTE: nonce is copied.

    -
    Returns:
    + + -
    -

    Encoded payload.

    -
    + + +

    Type Definitions

    - -
    -
    - Type -
    -
    + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    services + + +Object + + + +

    Service +features to be enabled for this connection

    time + + +Date + + + +

    Node time

    remoteHost + + +string + + + +

    IPv4/IPv6 address of the node +receiving this message

    remotePort + + +number + + + +

    Port of the node receiving this +message

    port + + +number + + + +

    Incoming port of the node sending this +message

    nonce + + Buffer - + +

    Random nonce used to detect connection +to self

    userAgent + + +Array +| + +string +| + +Buffer + + + +

    User agent of the node

    streamNumbers + + +Array.<number> + + + +

    Streams accepted by the node

    length + + +number + + + +

    Real data length

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + +
    - - - + + @@ -820,13 +1223,13 @@ NOTE: nonce is copied.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_net_base.BaseTransport.html b/docs/module-bitmessage_net_base.BaseTransport.html new file mode 100644 index 0000000..c85b776 --- /dev/null +++ b/docs/module-bitmessage_net_base.BaseTransport.html @@ -0,0 +1,881 @@ + + + + + JSDoc: Class: BaseTransport + + + + + + + + + + +
    + +

    Class: BaseTransport

    + + + + + + +
    + +
    + +

    + bitmessage/net/base. + + BaseTransport +

    + + +
    + +
    +
    + + + + + +

    new BaseTransport()

    + + + + + +
    +

    Base transport class. Allows to use single class for both client and +server modes (as separate instances).

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +

    Methods

    + + + + + + +

    (abstract) bootstrap() → {Promise.<Array>}

    + + + + + +
    +

    Do the transport-specific bootstrap process and return promise that +contains discovered nodes when fulfilled (both modes).
    NOTE: Do not use nodes received by this method in addr messages! +This is meaningless.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + +
    Returns:
    + + + + +
    +
    + Type +
    +
    + +Promise.<Array> + + +
    +
    + + + + + + + + + + +

    (abstract) broadcast(msg, payloadopt)

    + + + + + +
    +

    Send message to all +connected clients (server mode only).

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    msg + + +Buffer +| + +string + + + + + + + + + +

    Encoded message or command string

    payload + + +Buffer + + + + + + <optional>
    + + + + + +

    Message payload (used if the first +argument is a string)

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +

    (abstract) close()

    + + + + + +
    +

    Close connection(s) and/or stop listening (both modes).

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +

    (abstract) connect()

    + + + + + +
    +

    Connect to the transport-specific address. Enters client mode. Should +emit open event after successful connect and established event +after verack messages exchange.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +

    (abstract) listen()

    + + + + + +
    +

    Listen for the transport-specific incoming connections. Enters server +mode. Should emit connection event with a transport instance for +each new connection.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +

    (abstract) send(msg, payloadopt)

    + + + + + +
    +

    Send message over the +wire (client mode only).

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    msg + + +Buffer +| + +string + + + + + + + + + +

    Encoded message or command string

    payload + + +Buffer + + + + + + <optional>
    + + + + + +

    Message payload (used if the first +argument is a string)

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + \ No newline at end of file diff --git a/docs/module-bitmessage_net_base.html b/docs/module-bitmessage_net_base.html new file mode 100644 index 0000000..cb03759 --- /dev/null +++ b/docs/module-bitmessage_net_base.html @@ -0,0 +1,173 @@ + + + + + JSDoc: Module: bitmessage/net/base + + + + + + + + + + +
    + +

    Module: bitmessage/net/base

    + + + + + + +
    + +
    + + + + + +
    + +
    +
    + + +

    Networking base module. Defines base transport interface, useful for +implementing new transports. End-users should import some transport +instead in order to connect/accept connections to/from other nodes.
    NOTE: BaseTransport is exported as a module.

    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + +
    Example
    + +
    var BaseTransport = require("bitmessage/net/base");
    + + + + + +
    + + + + + + +

    Classes

    + +
    +
    BaseTransport
    +
    +
    + + + + + + + + + + + + + +
    + +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + \ No newline at end of file diff --git a/docs/module-bitmessage_net_tcp.TcpTransport.html b/docs/module-bitmessage_net_tcp.TcpTransport.html new file mode 100644 index 0000000..5294ac7 --- /dev/null +++ b/docs/module-bitmessage_net_tcp.TcpTransport.html @@ -0,0 +1,573 @@ + + + + + JSDoc: Class: TcpTransport + + + + + + + + + + +
    + +

    Class: TcpTransport

    + + + + + + +
    + +
    + +

    + bitmessage/net/tcp. + + TcpTransport +

    + + +
    + +
    +
    + + + + + +

    new TcpTransport(optsopt)

    + + + + + +
    +

    TCP transport class. Implements +base transport interface.

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    opts + + +Object + + + + + + <optional>
    + + + + + +

    Transport options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    seeds + + +Array + + + +

    Bootstrap nodes (none by default)

    dnsSeeds + + +Array + + + +

    Bootstrap DNS nodes (none by default)

    services + + +Object + + + +

    Service features +provided by this node (NODE_NETWORK by default)

    userAgent + + +Array +| + +string +| + +Buffer + + + +

    User agent of this node +(bitmessage's by default)

    streamNumbers + + +Array.<number> + + + +

    Streams accepted by this node +(1 by default)

    port + + +number + + + +

    Incoming port of this node (8444 by +default)

    + +
    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +

    Methods

    + + + + + + +

    connect()

    + + + + + +
    +

    Connect to a TCP node. Connection arguments are the same as for +net.connect.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +

    listen()

    + + + + + +
    +

    Listen for incoming TCP connections. Listen arguments are the same as +for +server.listen.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + \ No newline at end of file diff --git a/docs/module-bitmessage_net_tcp.html b/docs/module-bitmessage_net_tcp.html new file mode 100644 index 0000000..5457c14 --- /dev/null +++ b/docs/module-bitmessage_net_tcp.html @@ -0,0 +1,197 @@ + + + + + JSDoc: Module: bitmessage/net/tcp + + + + + + + + + + +
    + +

    Module: bitmessage/net/tcp

    + + + + + + +
    + +
    + + + + + +
    + +
    +
    + + +

    TCP transport compatible with PyBitmessage. Available only for Node +platform.
    NOTE: TcpTransport is exported as a module.

    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + +
    Example
    + +
    var messages = require("bitmessage").messages;
    +var TcpTransport = require("bitmessage/net/tcp");
    +
    +var tcp = new TcpTransport({
    +  dnsSeeds: [["bootstrap8444.bitmessage.org", 8444]],
    +});
    +
    +tcp.bootstrap().then(function(nodes) {
    +  var remoteHost = nodes[0][0];
    +  var remotePort = nodes[0][1];
    +  console.log("Connecting to", nodes[0]);
    +  tcp.connect(remotePort, remoteHost);
    +});
    +
    +tcp.on("established", function() {
    +  console.log("Connection established");
    +
    +  tcp.on("message", function(command, payload) {
    +    console.log("Got new", command, "message");
    +    var decoded;
    +    if (command === "addr") {
    +      decoded = messages.addr.decodePayload(payload);
    +      console.log("Got", decoded.addrs.length, "node addresses");
    +    }
    +  });
    +});
    + + + + + +
    + + + + + + +

    Classes

    + +
    +
    TcpTransport
    +
    +
    + + + + + + + + + + + + + +
    + +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + \ No newline at end of file diff --git a/docs/module-bitmessage_net_ws.WsTransport.html b/docs/module-bitmessage_net_ws.WsTransport.html new file mode 100644 index 0000000..8ce8227 --- /dev/null +++ b/docs/module-bitmessage_net_ws.WsTransport.html @@ -0,0 +1,551 @@ + + + + + JSDoc: Class: WsTransport + + + + + + + + + + +
    + +

    Class: WsTransport

    + + + + + + +
    + +
    + +

    + bitmessage/net/ws. + + WsTransport +

    + + +
    + +
    +
    + + + + + +

    new WsTransport(optsopt)

    + + + + + +
    +

    WebSocket transport class. Implements +base transport interface.

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    opts + + +Object + + + + + + <optional>
    + + + + + +

    Transport options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    seeds + + +Array + + + +

    Bootstrap nodes (none by default)

    services + + +Object + + + +

    Service features +provided by this node (NODE_NETWORK by default)

    userAgent + + +Array +| + +string +| + +Buffer + + + +

    User agent of this node +(bitmessage's by default)

    streamNumbers + + +Array.<number> + + + +

    Streams accepted by this node +(1 by default)

    port + + +number + + + +

    Incoming port of this node (8444 by +default)

    + +
    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +

    Methods

    + + + + + + +

    connect()

    + + + + + +
    +

    Connect to a WebSocket node. Connection arguments are the same as for +WebSocket.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +

    listen()

    + + + + + +
    +

    Listen for incoming WebSocket connections. Listen arguments are the +same as for +WebSocketServer. +Available only for Node platform.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + \ No newline at end of file diff --git a/docs/module-bitmessage_net_ws.html b/docs/module-bitmessage_net_ws.html new file mode 100644 index 0000000..821edea --- /dev/null +++ b/docs/module-bitmessage_net_ws.html @@ -0,0 +1,173 @@ + + + + + JSDoc: Module: bitmessage/net/ws + + + + + + + + + + +
    + +

    Module: bitmessage/net/ws

    + + + + + + +
    + +
    + + + + + +
    + +
    +
    + + +

    WebSocket transport. Needed because browsers can't handle TCP sockets +so we use separate WebSocket server to proxy messages into TCP data +packets. Available for both Node.js and Browser platforms.
    NOTE: WsTransport is exported as a module.

    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + +
    Example
    + +
    var WsTransport = require("bitmessage/net/ws");
    + + + + + +
    + + + + + + +

    Classes

    + +
    +
    WsTransport
    +
    +
    + + + + + + + + + + + + + +
    + +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + \ No newline at end of file diff --git a/docs/module-bitmessage_objects.broadcast.html b/docs/module-bitmessage_objects.broadcast.html index dc60ff0..617f45f 100644 --- a/docs/module-bitmessage_objects.broadcast.html +++ b/docs/module-bitmessage_objects.broadcast.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decodeAsync(buf, opts) → {Promise.<Object>}

    +

    (static) decodeAsync(buf, opts) → {Promise.<DecodeResult>}

    @@ -201,121 +201,9 @@ -

    Decoding options

    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Source:
    -
    - - - - - - - -
    - - - - - - - - - - - - - -
    Returns:
    - - -
    -

    A promise that contains decoded -broadcast object structure when fulfilled.

    -
    - - - -
    -
    - Type -
    -
    - -Promise.<Object> - - -
    -
    - - - - - - - - - - -

    (static) decodePayloadAsync(buf, opts) → {Promise.<Object>}

    - - - - - -
    -

    Decode broadcast object message payload.

    -
    - - - - - - - - - -
    Parameters:
    - +

    Any of object.decode options and:

    +
    Properties
    + @@ -339,35 +227,18 @@ - + - - - - - - - - - - - - - - - - + + + + + +
    bufsubscriptions -Buffer +Array.<Address> +| +Address +| - -

    Message payload

    opts - - Object @@ -378,7 +249,18 @@ -

    Decoding options

    Address +objects which represent broadcast subscriptions. It is either +addresses array or single address or Object +addr-by-tag/addr-by-ripe. Time to match the key is O(n), O(1), O(1) +respectfully.

    + + @@ -419,7 +301,7 @@
    Source:
    @@ -446,8 +328,8 @@
    -

    A promise that contains decoded pubkey -object structure when fulfilled.

    +

    A promise that contains +decoded broadcast structure when fulfilled.

    @@ -458,7 +340,7 @@ object structure when fulfilled.

    -Promise.<Object> +Promise.<DecodeResult>
    @@ -472,6 +354,89 @@ object structure when fulfilled.

    + +

    (static) decodePayloadAsync()

    + + + + + +
    +

    Decode broadcast object message payload. +The same as decodeAsync.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +

    (static) encodeAsync(opts) → {Promise.<Buffer>}

    @@ -532,7 +497,235 @@ object structure when fulfilled.

    -

    broadcast object options

    +

    broadcast object options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    ttl + + +number + + + + + + + + + +

    Time to live in seconds

    from + + +Address + + + + + + + + + +

    Originator of the message

    message + + +string +| + +Buffer + + + + + + + + + +

    Message

    subject + + +string +| + +Buffer + + + + + + <optional>
    + + + + + +

    Subject for SIMPLE encoding

    encoding + + +number + + + + + + <optional>
    + + + + + +

    Encoding of the message +(TRIVIAL by default)

    skipPow + + +boolean + + + + + + <optional>
    + + + + + +

    Do not compute POW (false by +default)

    + + @@ -573,7 +766,7 @@ object structure when fulfilled.

    Source:
    @@ -627,14 +820,15 @@ when fulfilled.

    -

    (static) encodePayloadAsync(opts) → {Promise.<Buffer>}

    +

    (static) encodePayloadAsync()

    -

    Encode broadcast object message payload.

    +

    Encode broadcast object message payload. +The same as encodeAsync.

    @@ -645,55 +839,6 @@ when fulfilled.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    broadcast object options

    - - @@ -727,7 +872,7 @@ when fulfilled.

    Source:
    @@ -750,35 +895,678 @@ when fulfilled.

    -
    Returns:
    + + -
    -

    A promise that contains encoded message -payload when fulfilled.

    -
    + + +

    Type Definitions

    - -
    -
    - Type -
    -
    -Promise.<Buffer> + +

    DecodeResult

    -
    + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    nonce + + +Buffer + + + + + + + +

    A 8-byte object nonce

    ttl + + +number + + + + + + + +

    Time to live in seconds

    type + + +number + + + + + + + +

    Object type

    version + + +number + + + + + + + +

    Object version

    stream + + +number + + + + + + + +

    Object stream

    headerLength + + +number + + + + + + + +

    Length of the object header

    tag + + +Buffer + + + + + + + +

    Tag derived from the address object used +to send this broadcast (present only for object version >= 5)

    senderVersion + + +number + + + + + + + +

    Sender's address version

    senderStream + + +number + + + + + + + +

    Sender's stream

    behavior + + +Object + + + + + + + +

    Sender's pubkey features that can be expected from +the node

    signPublicKey + + +Buffer + + + + + + + +

    Sender's signing public key

    encPublicKey + + +Buffer + + + + + + + +

    Sender's encryption public key

    nonceTrialsPerByte + + +number + + + + + + + +

    Difficulty parameter of the +sender (present only if sender's address version >= 3)

    payloadLengthExtraBytes + + +number + + + + + + + +

    Difficulty parameter +of the sender (present only if sender's address version >= 3)

    encoding + + +number + + + + + + + +

    Message encoding

    message + + +string +| + +Buffer + + + + + + + +

    Message string for +TRIVIAL and +SIMPLE encodings or +unparsed buffer data for other encodings

    subject + + +string + + + + + + <optional>
    + + + +

    Subject string for SIMPLE encoding

    signature + + +Buffer + + + + + + + +

    Signature of the message

    length + + +number + + + + + + + +

    Real data length

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + +
    - - - + + @@ -792,13 +1580,13 @@ payload when fulfilled.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_objects.getpubkey.html b/docs/module-bitmessage_objects.getpubkey.html index 23cb631..85d8e48 100644 --- a/docs/module-bitmessage_objects.getpubkey.html +++ b/docs/module-bitmessage_objects.getpubkey.html @@ -78,7 +78,7 @@ for the public key.

    Source:
    @@ -121,7 +121,7 @@ for the public key.

    -

    (static) decodeAsync(buf, optsnullable) → {Promise.<Object>}

    +

    (static) decodeAsync(buf, optsopt) → {Promise.<DecodeResult>}

    @@ -212,9 +212,9 @@ for the public key.

    - + <optional>
    - <nullable>
    + @@ -223,7 +223,7 @@ for the public key.

    -

    Decoding options

    +

    Any of object.decode options

    @@ -264,7 +264,7 @@ for the public key.

    Source:
    @@ -291,8 +291,8 @@ for the public key.

    -

    A promise that contains decoded -getpubkey object structure when fulfilled.

    +

    A promise that contains +decoded getpubkey structure when fulfilled.

    @@ -303,7 +303,7 @@ for the public key.

    -Promise.<Object> +Promise.<DecodeResult>
    @@ -318,14 +318,15 @@ for the public key.

    -

    (static) decodePayloadAsync(buf, optsnullable) → {Promise.<Object>}

    +

    (static) decodePayloadAsync()

    -

    Decode getpubkey object message payload.

    +

    Decode getpubkey object message payload. +The same as decodeAsync.

    @@ -336,98 +337,6 @@ for the public key.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeAttributesDescription
    buf - - -Buffer - - - - - - - - - -

    Message payload

    opts - - -Object - - - - - - - - <nullable>
    - - - -

    Decoding options

    - - @@ -461,7 +370,7 @@ for the public key.

    Source:
    @@ -484,29 +393,6 @@ for the public key.

    -
    Returns:
    - - -
    -

    A promise that contains decoded -getpubkey object structure when fulfilled.

    -
    - - - -
    -
    - Type -
    -
    - -Promise.<Object> - - -
    -
    - - @@ -574,7 +460,131 @@ for the public key.

    -

    getpubkey object options

    +

    getpubkey object options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    ttl + + +number + + + + + + + + + +

    Time to live in seconds

    to + + +Address + + + + + + + + + +

    Receiver of the message

    skipPow + + +boolean + + + + + + <optional>
    + + + + + +

    Do not compute POW (false by +default)

    + + @@ -615,7 +625,7 @@ for the public key.

    Source:
    @@ -669,14 +679,16 @@ when fulfilled.

    -

    (static) encodePayloadAsync(opts) → {Promise.<Buffer>}

    +

    (static) encodePayloadAsync()

    -

    Encode getpubkey object message payload.

    +

    Encode getpubkey object message payload. +The same as +encodeAsync.

    @@ -687,55 +699,6 @@ when fulfilled.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    getpubkey object options

    - - @@ -769,7 +732,7 @@ when fulfilled.

    Source:
    @@ -792,35 +755,322 @@ when fulfilled.

    -
    Returns:
    + + -
    -

    A promise that contains encoded message -payload when fulfilled.

    -
    + + +

    Type Definitions

    - -
    -
    - Type -
    -
    -Promise.<Buffer> + +

    DecodeResult

    -
    + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    nonce + + +Buffer + + + +

    A 8-byte object nonce

    ttl + + +number + + + +

    Time to live in seconds

    type + + +number + + + +

    Object type

    version + + +number + + + +

    Object version

    stream + + +number + + + +

    Object stream

    headerLength + + +number + + + +

    Length of the object header

    ripe + + +Buffer + + + +

    The RIPEMD hash of the requested public +keys for address version <= 3

    tag + + +Buffer + + + +

    ...or tag derived from the address object +for address version >= 4

    length + + +number + + + +

    Real data length

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + +
    - - - + + @@ -834,13 +1084,13 @@ payload when fulfilled.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_objects.html b/docs/module-bitmessage_objects.html index 79017cf..a598d5b 100644 --- a/docs/module-bitmessage_objects.html +++ b/docs/module-bitmessage_objects.html @@ -38,8 +38,8 @@
    -

    Working with objects.
    NOTE: Most operations with objects in this module are asynchronous -and return promises.

    +

    Working with objects.
    NOTE: Most operations with objects are asynchronous and return +promises.

    @@ -161,7 +161,7 @@ and return promises.

    -

    (static) getPayloadType(buf) → (nullable) {number}

    +

    (static) getPayloadType()

    @@ -169,12 +169,7 @@ and return promises.

    Try to get type of the given object message payload. -Note that this function doesn't do any validation because it is -already provided by -object.decodePayload -routine. Normally you call this for each incoming object message -payload and then call decode function of the appropriate object -handler.

    +The same as getType.

    @@ -185,55 +180,6 @@ handler.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    buf - - -Buffer - - - -

    Buffer that starts with object message payload

    - - @@ -267,7 +213,7 @@ handler.

    Source:
    @@ -290,28 +236,6 @@ handler.

    -
    Returns:
    - - -
    -

    Object's type if any.

    -
    - - - -
    -
    - Type -
    -
    - -number - - -
    -
    - - @@ -425,7 +349,7 @@ then call decode function of the appropriate object handler.

    Source:
    @@ -489,13 +413,13 @@ then call decode function of the appropriate object handler.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_objects.msg.html b/docs/module-bitmessage_objects.msg.html index a9ee231..b1ded3b 100644 --- a/docs/module-bitmessage_objects.msg.html +++ b/docs/module-bitmessage_objects.msg.html @@ -76,7 +76,7 @@
    Source:
    @@ -169,7 +169,7 @@ simply be sharing its public key with you.

    Source:
    @@ -241,7 +241,7 @@ simply be sharing its public key with you.

    Source:
    @@ -314,7 +314,7 @@ of data, like URIs or magnet links.

    Source:
    @@ -341,7 +341,7 @@ of data, like URIs or magnet links.

    -

    (static) decodeAsync(buf, opts) → {Promise.<Object>}

    +

    (static) decodeAsync(buf, opts) → {Promise.<DecodeResult>}

    @@ -423,121 +423,9 @@ of data, like URIs or magnet links.

    -

    Decoding options

    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Source:
    -
    - - - - - - - -
    - - - - - - - - - - - - - -
    Returns:
    - - -
    -

    A promise that contains decoded msg -object structure when fulfilled.

    -
    - - - -
    -
    - Type -
    -
    - -Promise.<Object> - - -
    -
    - - - - - - - - - - -

    (static) decodePayloadAsync(buf, opts) → {Promise.<Object>}

    - - - - - -
    -

    Decode msg object message payload.

    -
    - - - - - - - - - -
    Parameters:
    - +

    Any of object.decode options and:

    +
    Properties
    + @@ -561,13 +449,16 @@ object structure when fulfilled.

    - + + + +
    bufidentities -Buffer +Array.<Address> +| + +Address @@ -577,30 +468,15 @@ object structure when fulfilled.

    -

    Message payload

    Address objects used +to decrypt the message

    - - - opts - - - - - -Object - - - - - - - - -

    Decoding options

    @@ -641,7 +517,7 @@ object structure when fulfilled.

    Source:
    @@ -668,8 +544,9 @@ object structure when fulfilled.

    -

    A promise that contains decoded msg -object structure when fulfilled.

    +

    A promise that contains [decoded +msg structure]module:bitmessage/objects.msg.DecodeResult +when fulfilled.

    @@ -680,7 +557,7 @@ object structure when fulfilled.

    -Promise.<Object> +Promise.<DecodeResult>
    @@ -694,6 +571,89 @@ object structure when fulfilled.

    + +

    (static) decodePayloadAsync()

    + + + + + +
    +

    Decode msg object message payload. +The same as decodeAsync.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +

    (static) encodeAsync(opts) → {Promise.<Buffer>}

    @@ -754,7 +714,300 @@ object structure when fulfilled.

    -

    msg object options

    +

    msg object options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    ttl + + +number + + + + + + + + + +

    Time to live in seconds

    from + + +Address + + + + + + + + + +

    Originator of the message

    to + + +Address + + + + + + + + + +

    Receiver of the message

    message + + +string +| + +Buffer + + + + + + + + + +

    Message

    subject + + +string +| + +Buffer + + + + + + <optional>
    + + + + + +

    Subject for SIMPLE encoding

    encoding + + +number + + + + + + <optional>
    + + + + + +

    Encoding of the message +(TRIVIAL by default)

    friend + + +boolean + + + + + + <optional>
    + + + + + +

    Whether the receiver is friend and +should have minimal POW difficulty (false by default)

    skipPow + + +boolean + + + + + + <optional>
    + + + + + +

    Do not compute POW (false by +default)

    + + @@ -795,7 +1048,7 @@ object structure when fulfilled.

    Source:
    @@ -849,14 +1102,15 @@ when fulfilled.

    -

    (static) encodePayloadAsync(opts) → {Promise.<Buffer>}

    +

    (static) encodePayloadAsync()

    -

    Encode msg object message payload.

    +

    Encode msg object message payload. +The same as encodeAsync.

    @@ -867,55 +1121,6 @@ when fulfilled.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    msg object options

    - - @@ -949,7 +1154,7 @@ when fulfilled.

    Source:
    @@ -972,35 +1177,706 @@ when fulfilled.

    -
    Returns:
    + + -
    -

    A promise that contains encoded message -payload when fulfilled.

    -
    + + +

    Type Definitions

    - -
    -
    - Type -
    -
    -Promise.<Buffer> + +

    DecodeResult

    -
    + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    nonce + + +Buffer + + + + + + + +

    A 8-byte object nonce

    ttl + + +number + + + + + + + +

    Time to live in seconds

    type + + +number + + + + + + + +

    Object type

    version + + +number + + + + + + + +

    Object version

    stream + + +number + + + + + + + +

    Object stream

    headerLength + + +number + + + + + + + +

    Length of the object header

    senderVersion + + +number + + + + + + + +

    Sender's address version

    senderStream + + +number + + + + + + + +

    Sender's stream

    behavior + + +Object + + + + + + + +

    Sender's pubkey features that can be expected from +the node

    signPublicKey + + +Buffer + + + + + + + +

    Sender's signing public key

    encPublicKey + + +Buffer + + + + + + + +

    Sender's encryption public key

    nonceTrialsPerByte + + +number + + + + + + + +

    Difficulty parameter of the +sender (present only if sender's address version >= 3)

    payloadLengthExtraBytes + + +number + + + + + + + +

    Difficulty parameter +of the sender (present only if sender's address version >= 3)

    ripe + + +Buffer + + + + + + + +

    The RIPEMD hash of the receiver's keys

    encoding + + +number + + + + + + + +

    Message encoding

    message + + +string +| + +Buffer + + + + + + + +

    Message string for +TRIVIAL and +SIMPLE encodings or +unparsed buffer data for other encodings

    subject + + +string + + + + + + <optional>
    + + + +

    Subject string for SIMPLE encoding

    ack + + +Buffer + + + + + + + +

    Message acknowledgement

    signature + + +Buffer + + + + + + + +

    Signature of the message

    length + + +number + + + + + + + +

    Real data length

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + +
    - - - + + @@ -1014,13 +1890,13 @@ payload when fulfilled.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_objects.pubkey.html b/docs/module-bitmessage_objects.pubkey.html index eee5a62..dfdda0b 100644 --- a/docs/module-bitmessage_objects.pubkey.html +++ b/docs/module-bitmessage_objects.pubkey.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decodeAsync(buf, optsnullable) → {Promise.<Object>}

    +

    (static) decodeAsync(buf, optsopt) → {Promise.<DecodeResult>}

    @@ -210,9 +210,9 @@ - + <optional>
    - <nullable>
    + @@ -221,121 +221,9 @@ -

    Decoding options

    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Source:
    -
    - - - - - - - -
    - - - - - - - - - - - - - -
    Returns:
    - - -
    -

    A promise that contains decoded pubkey -object structure when fulfilled.

    -
    - - - -
    -
    - Type -
    -
    - -Promise.<Object> - - -
    -
    - - - - - - - - - - -

    (static) decodePayloadAsync(buf, optsnullable) → {Promise.<Object>}

    - - - - - -
    -

    Decode pubkey object message payload.

    -
    - - - - - - - - - -
    Parameters:
    - +

    Any of object.decode options and:

    +
    Properties
    + @@ -347,8 +235,6 @@ object structure when fulfilled.

    - - @@ -361,43 +247,18 @@ object structure when fulfilled.

    - + - - - - - - - - - - - - - - - - - - - - - + + + + + +
    TypeAttributes
    bufneeded -Buffer +Array.<Address> +| +Address +| - - - - - - - -

    Message payload

    opts - - Object @@ -405,20 +266,21 @@ object structure when fulfilled.

    - - - - <nullable>
    - - - -

    Decoding options

    Address objects +which represent pubkeys that we are interested in (used only for +pubkeys v4). It is either addresses array or single address or +Object addr-by-tag. Time to match the key is O(n), O(1), O(1) +respectfully.

    + + @@ -459,7 +321,7 @@ object structure when fulfilled.

    Source:
    @@ -486,8 +348,9 @@ object structure when fulfilled.

    -

    A promise that contains decoded pubkey -object structure when fulfilled.

    +

    A promise that contains +decoded pubkey structure +when fulfilled.

    @@ -498,7 +361,7 @@ object structure when fulfilled.

    -Promise.<Object> +Promise.<DecodeResult>
    @@ -512,6 +375,89 @@ object structure when fulfilled.

    + +

    (static) decodePayloadAsync()

    + + + + + +
    +

    Decode pubkey object message payload. +The same as decodeAsync.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +

    (static) encodeAsync(opts) → {Promise.<Buffer>}

    @@ -572,7 +518,162 @@ object structure when fulfilled.

    -

    pubkey object options

    +

    pubkey object options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    ttl + + +number + + + + + + + + + +

    Time to live in seconds

    from + + +Address + + + + + + + + + +

    Originator of the message

    to + + +Address + + + + + + + + + +

    Receiver of the message

    skipPow + + +boolean + + + + + + <optional>
    + + + + + +

    Do not compute POW (false by +default)

    + + @@ -613,7 +714,7 @@ object structure when fulfilled.

    Source:
    @@ -667,14 +768,15 @@ when fulfilled.

    -

    (static) encodePayloadAsync(opts) → {Promise.<Buffer>}

    +

    (static) encodePayloadAsync()

    -

    Encode pubkey object message payload.

    +

    Encode pubkey object message payload. +The same as encodeAsync.

    @@ -685,55 +787,6 @@ when fulfilled.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    pubkey object options

    - - @@ -767,7 +820,7 @@ when fulfilled.

    Source:
    @@ -790,35 +843,440 @@ when fulfilled.

    -
    Returns:
    + + -
    -

    A promise that contains encoded message -payload when fulfilled.

    -
    + + +

    Type Definitions

    - -
    -
    - Type -
    -
    -Promise.<Buffer> + +

    DecodeResult

    -
    + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    nonce + + +Buffer + + + +

    A 8-byte object nonce

    ttl + + +number + + + +

    Time to live in seconds

    type + + +number + + + +

    Object type

    version + + +number + + + +

    Object version

    stream + + +number + + + +

    Object stream

    headerLength + + +number + + + +

    Length of the object header

    tag + + +Buffer + + + +

    Tag derived from the address object +(present only if object version is 4)

    behavior + + +Object + + + +

    Pubkey features that can be expected from +the node

    signPublicKey + + +Buffer + + + +

    Signing public key

    encPublicKey + + +Buffer + + + +

    Encryption public key

    nonceTrialsPerByte + + +number + + + +

    Difficulty parameter of the +node (present only for pubkey version >= 3)

    payloadLengthExtraBytes + + +number + + + +

    Difficulty parameter +of the node (present only for pubkey version >= 3)

    signature + + +Buffer + + + +

    Signature of the message (present +only for pubkey version >= 3)

    length + + +number + + + +

    Real data length

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + +
    - - - + + @@ -832,13 +1290,13 @@ payload when fulfilled.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_pow.html b/docs/module-bitmessage_pow.html index f7423cd..5caeaea 100644 --- a/docs/module-bitmessage_pow.html +++ b/docs/module-bitmessage_pow.html @@ -203,7 +203,130 @@ -

    Proof of work options

    +

    Proof of work options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    target + + +number + + + +

    Proof of work target or pass +getTarget options to opts +to compute it

    payload + + +Buffer + + + +

    Message payload (with nonce)

    nonce + + +number +| + +Buffer + + + +

    ...or already derived nonce

    initialHash + + +Buffer + + + +

    ...and initial hash

    + + @@ -244,7 +367,7 @@
    Source:
    @@ -401,8 +524,6 @@ - <nullable>
    - @@ -435,8 +556,6 @@ get the initial hash from

    - <nullable>
    - @@ -444,7 +563,8 @@ get the initial hash from

    -

    Or already computed initial hash

    +

    ...or already computed initial +hash

    @@ -479,6 +599,40 @@ get the initial hash from

    + + + + poolSize + + + + + +number + + + + + + + + + <optional>
    + + + + + + + + + + +

    POW calculation pool size (by +default equals to number of cores)

    + + + @@ -523,7 +677,7 @@ get the initial hash from

    Source:
    @@ -636,7 +790,201 @@ the given target when fulfilled.

    -

    Target options

    +

    Target options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    ttl + + +number + + + + + + + + + +

    Time to live of the message in seconds

    payloadLength + + +number + + + + + + + + + +

    Length of the message payload +(with nonce)

    payload + + +Buffer + + + + + + + + + +

    ...or payload itself

    nonceTrialsPerByte + + +number + + + + + + <optional>
    + + + + + +

    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.

    payloadLengthExtraBytes + + +number + + + + + + <optional>
    + + + + + +

    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.

    + + @@ -677,7 +1025,7 @@ the given target when fulfilled.

    Source:
    @@ -741,13 +1089,13 @@ the given target when fulfilled.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.PubkeyBitfield.html b/docs/module-bitmessage_structs.PubkeyBitfield.html index 34135ce..f73160e 100644 --- a/docs/module-bitmessage_structs.PubkeyBitfield.html +++ b/docs/module-bitmessage_structs.PubkeyBitfield.html @@ -2,7 +2,7 @@ - JSDoc: Namespace: PubkeyBitfield + JSDoc: Class: PubkeyBitfield @@ -17,7 +17,7 @@
    -

    Namespace: PubkeyBitfield

    +

    Class: PubkeyBitfield

    @@ -41,11 +41,125 @@
    -

    Pubkey bitfield features.

    + + + +

    new PubkeyBitfield(bufopt, optsopt)

    + + + + + +
    +

    Pubkey features bitfield (MSB 0).

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    buf + + +Buffer + + + + + + <optional>
    + + + + + +

    A 4-byte bitfield buffer (will be created if +not provided or will be copied if opts.copy is true)

    opts + + +Object + + + + + + <optional>
    + + + + + +

    Options

    + + + + +
    @@ -76,7 +190,7 @@
    Source:
    @@ -95,7 +209,31 @@
    - + + + + + + + + + + + + + +
    Example
    + +
    var PubkeyBitfield = require("bitmessage").structs.PubkeyBitfield;
    +var behavior = PubkeyBitfield().set([
    +  PubkeyBitfield.INCLUDE_DESTINATION,
    +  PubkeyBitfield.DOES_ACK,
    +]).set(1);
    +console.log(behavior.get(PubkeyBitfield.DOES_ACK));  // true
    +console.log(behavior.get(15));  // false
    + + +
    @@ -120,7 +258,8 @@
    -

    If true, the receiving node does send acknowledgements (rather than +

    Bit index. +If set, the receiving node does send acknowledgements (rather than dropping them).

    @@ -169,7 +308,7 @@ dropping them).

    Source:
    @@ -193,9 +332,10 @@ dropping them).

    -

    Receiving node expects that the RIPE hash encoded in their address -preceedes the encrypted message data of msg messages bound for -them.

    +

    Bit index. +If set, the receiving node expects that the RIPEMD hash encoded in +their address preceedes the encrypted message data of msg messages +bound for them.

    @@ -243,7 +383,79 @@ them.

    Source:
    + + + + + + + +
    + + + + + + + + +

    buffer :Buffer

    + + + + +
    +

    The contents of the bitfield.

    +
    + + + +
    Type:
    +
      +
    • + +Buffer + + +
    • +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    @@ -263,6 +475,315 @@ them.

    +

    Methods

    + + + + + + +

    get(index) → {boolean}

    + + + + + +
    +

    Returns a boolean indicating whether the bit is set.

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    index + + +number + + + +

    Bit index (MSB 0)

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + +
    Returns:
    + + + + +
    +
    + Type +
    +
    + +boolean + + +
    +
    + + + + + + + + + + +

    set(index) → {Object}

    + + + + + +
    +

    Set the given bit(s) to 1.

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    index + + +number +| + +Array.<number> + + + +

    Bit(s) index (MSB 0)

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + +
    Returns:
    + + +
    +

    Returns self so methods can be chained.

    +
    + + + +
    +
    + Type +
    +
    + +Object + + +
    +
    + + + + + + + @@ -277,13 +798,13 @@ them.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.ServicesBitfield.html b/docs/module-bitmessage_structs.ServicesBitfield.html index 827de69..33d4078 100644 --- a/docs/module-bitmessage_structs.ServicesBitfield.html +++ b/docs/module-bitmessage_structs.ServicesBitfield.html @@ -2,7 +2,7 @@ - JSDoc: Namespace: ServicesBitfield + JSDoc: Class: ServicesBitfield @@ -17,7 +17,7 @@
    -

    Namespace: ServicesBitfield

    +

    Class: ServicesBitfield

    @@ -41,11 +41,125 @@
    -

    Services bitfield features.

    + + + +

    new ServicesBitfield(bufopt, optsopt)

    + + + + + +
    +

    Service features bitfield (MSB 0).

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    buf + + +Buffer + + + + + + <optional>
    + + + + + +

    A 8-byte bitfield buffer (will be created if +not provided or will be copied if opts.copy is true)

    opts + + +Object + + + + + + <optional>
    + + + + + +

    Options

    + + + + +
    @@ -76,7 +190,7 @@
    Source:
    @@ -95,7 +209,28 @@
    - + + + + + + + + + + + + + +
    Example
    + +
    var ServicesBitfield = require("bitmessage").structs.ServicesBitfield;
    +var services = ServicesBitfield().set(ServicesBitfield.NODE_NETWORK);
    +console.log(services.get(ServicesBitfield.NODE_NETWORK));  // true
    +console.log(services.get(15));  // false
    + + +
    @@ -120,7 +255,7 @@
    -

    This is a normal network node.

    +

    Bit index indicating normal network node.

    @@ -168,7 +303,79 @@
    Source:
    + + + + + + + +
    + + + + + + + + +

    buffer :Buffer

    + + + + +
    +

    The contents of the bitfield.

    +
    + + + +
    Type:
    +
      +
    • + +Buffer + + +
    • +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    @@ -188,6 +395,315 @@ +

    Methods

    + + + + + + +

    get(index) → {boolean}

    + + + + + +
    +

    Returns a boolean indicating whether the bit is set.

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    index + + +number + + + +

    Bit index (MSB 0)

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + +
    Returns:
    + + + + +
    +
    + Type +
    +
    + +boolean + + +
    +
    + + + + + + + + + + +

    set(index) → {Object}

    + + + + + +
    +

    Set the given bit(s) to 1.

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    index + + +number +| + +Array.<number> + + + +

    Bit(s) index (MSB 0)

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + +
    Returns:
    + + +
    +

    Returns self so methods can be chained.

    +
    + + + +
    +
    + Type +
    +
    + +Object + + +
    +
    + + + + + + + @@ -202,13 +718,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.encrypted.html b/docs/module-bitmessage_structs.encrypted.html index 8986818..90aa5cf 100644 --- a/docs/module-bitmessage_structs.encrypted.html +++ b/docs/module-bitmessage_structs.encrypted.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -219,7 +219,7 @@
    Source:
    @@ -246,7 +246,7 @@
    -

    Decoded encrypted structure.

    +

    Decoded encrypted structure.

    @@ -257,7 +257,7 @@
    -Object +DecodeResult
    @@ -331,7 +331,127 @@ -

    Encode options

    +

    Encoding options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    iv + + +Buffer + + + +

    Initialization vector (16 bytes)

    ephemPrivateKey + + +Buffer + + + +

    Ephemeral private key (32 +bytes)

    ciphertext + + +Buffer + + + +

    The result of encryption (variable +size)

    mac + + +Buffer + + + +

    Message authentication code (32 bytes)

    + + @@ -372,7 +492,7 @@
    Source:
    @@ -399,7 +519,7 @@
    -

    Encoded encrypted payload.

    +

    Encoded encrypted payload.

    @@ -424,6 +544,200 @@ +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    iv + + +Buffer + + + +

    Initialization vector (16 bytes)

    ephemPrivateKey + + +Buffer + + + +

    Ephemeral private key (32 bytes)

    ciphertext + + +Buffer + + + +

    The result of encryption (variable +size)

    mac + + +Buffer + + + +

    Message authentication code (32 bytes)

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + @@ -436,13 +750,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.html b/docs/module-bitmessage_structs.html index af08ebf..730c16c 100644 --- a/docs/module-bitmessage_structs.html +++ b/docs/module-bitmessage_structs.html @@ -119,6 +119,27 @@ +
    Example
    + +
    var structs = require("bitmessage").structs;
    +
    +var encoded = Buffer.concat([
    +  structs.var_int.encode(4),
    +  Buffer("test"),
    +  structs.var_str.encode("test2"),
    +  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]
    + + @@ -129,6 +150,16 @@ +

    Classes

    + +
    +
    PubkeyBitfield
    +
    + +
    ServicesBitfield
    +
    +
    + @@ -151,12 +182,6 @@
    object
    -
    PubkeyBitfield
    -
    - -
    ServicesBitfield
    -
    -
    var_int
    @@ -185,13 +210,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.inv_vect.html b/docs/module-bitmessage_structs.inv_vect.html index 4dc549d..9167edb 100644 --- a/docs/module-bitmessage_structs.inv_vect.html +++ b/docs/module-bitmessage_structs.inv_vect.html @@ -76,7 +76,7 @@
    Source:
    @@ -219,7 +219,7 @@
    Source:
    @@ -246,7 +246,7 @@
    -

    Encoded inv_vect.

    +

    A 32-byte encoded inv_vect.

    @@ -283,13 +283,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.message.html b/docs/module-bitmessage_structs.message.html index 254350d..6ecee73 100644 --- a/docs/module-bitmessage_structs.message.html +++ b/docs/module-bitmessage_structs.message.html @@ -76,7 +76,7 @@
    Source:
    @@ -168,7 +168,7 @@
    Source:
    @@ -195,14 +195,14 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    -

    Decode message structure.
    NOTE: payload is copied, rest references input buffer.

    +

    Decode message.
    NOTE: payload is copied, rest references input buffer.

    @@ -295,7 +295,7 @@
    Source:
    @@ -322,7 +322,7 @@
    -

    Decoded message structure.

    +

    Decoded message structure.

    @@ -333,7 +333,7 @@
    -Object +DecodeResult
    @@ -355,7 +355,7 @@
    -

    Encode message structure.

    +

    Encode message.

    @@ -471,7 +471,7 @@
    Source:
    @@ -520,8 +520,616 @@ + + +

    (static) tryDecode(buf) → (nullable) {TryDecodeResult}

    + + + + + +
    +

    Decode message in "stream" mode.
    NOTE: message payload and rest are copied (so the runtime can GC +processed buffer data).

    +
    + + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    buf + + +Buffer + + + +

    Data buffer

    + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + +
    Returns:
    + + + + + + +
    +
    + Type +
    +
    + +TryDecodeResult + + +
    +
    + + + + + + + + + +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    command + + +string + + + +

    Message command

    payload + + +Buffer + + + +

    Message payload

    length + + +number + + + +

    Full message length

    rest + + +Buffer + + + +

    The rest of the input buffer

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + +

    TryDecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    message + + +Object + + + +

    Decoded message

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    command + + +string + + + +

    Message command

    payload + + +Buffer + + + +

    Message payload

    length + + +number + + + +

    Full message length

    + +
    error + + +Error + + + +

    ...or decoding error

    rest + + +Buffer + + + +

    The rest of the input buffer after +processing message

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + @@ -535,13 +1143,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.net_addr.html b/docs/module-bitmessage_structs.net_addr.html index e251573..18ac9cf 100644 --- a/docs/module-bitmessage_structs.net_addr.html +++ b/docs/module-bitmessage_structs.net_addr.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decode(buf, optsnullable) → {Object}

    +

    (static) decode(buf, optsopt) → {DecodeResult}

    @@ -210,9 +210,9 @@ - + <optional>
    - <nullable>
    + @@ -264,7 +264,7 @@ decode net_addr from
    Source:
    @@ -291,7 +291,7 @@ decode net_addr from
    -

    Decoded net_addr structure.

    +

    Decoded net_addr structure.

    @@ -302,7 +302,7 @@ decode net_addr from
    -Object +DecodeResult
    @@ -376,9 +376,234 @@ decode net_addr from -

    Encode options; use short option to encode -net_addr for -version message

    +

    Encoding options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    short + + +boolean + + + + + + <optional>
    + + + + + +

    Encode net_addr for +version message +(false by default)

    time + + +Date + + + + + + <optional>
    + + + + + +

    Time the node was last active, not +included in short mode (current time by default)

    stream + + +number + + + + + + <optional>
    + + + + + +

    Stream number of the node, not +included in short mode (1 by default)

    services + + +Object + + + + + + <optional>
    + + + + + +

    Services +provided by the node (NODE_NETWORK by default)

    host + + +string + + + + + + + + + +

    IPv4/IPv6 address of the node

    port + + +number + + + + + + + + + +

    Incoming port of the node

    + + @@ -419,7 +644,7 @@ decode net_addr from
    Source:
    @@ -471,6 +696,225 @@ decode net_addr from +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    time + + +Date + + + +

    Time the node was last active, not included +in short mode

    stream + + +number + + + +

    Stream number of the node, not included +in short mode

    services + + +Object + + + +

    Services +provided by the node

    host + + +string + + + +

    IPv4/IPv6 address of the node

    port + + +number + + + +

    Incoming port of the node

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + @@ -483,13 +927,13 @@ decode net_addr from
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.object.html b/docs/module-bitmessage_structs.object.html index 3f12417..5d5969d 100644 --- a/docs/module-bitmessage_structs.object.html +++ b/docs/module-bitmessage_structs.object.html @@ -78,7 +78,7 @@ nodes.

    Source:
    @@ -112,6 +112,298 @@ nodes.

    +

    Members

    + + + +

    (static, constant) BROADCAST :number

    + + + + +
    +

    broadcast object type.

    +
    + + + +
    Type:
    +
      +
    • + +number + + +
    • +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + +

    (static, constant) GETPUBKEY :number

    + + + + +
    +

    getpubkey object type.

    +
    + + + +
    Type:
    +
      +
    • + +number + + +
    • +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + +

    (static, constant) MSG :number

    + + + + +
    +

    msg object type.

    +
    + + + +
    Type:
    +
      +
    • + +number + + +
    • +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + +

    (static, constant) PUBKEY :number

    + + + + +
    +

    pubkey object type.

    +
    + + + +
    Type:
    +
      +
    • + +number + + +
    • +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + +

    Methods

    @@ -121,7 +413,7 @@ nodes.

    -

    (static) decode(buf, optsnullable) → {Object}

    +

    (static) decode(buf, optsopt) → {DecodeResult}

    @@ -212,9 +504,9 @@ nodes.

    - + <optional>
    - <nullable>
    + @@ -223,120 +515,9 @@ nodes.

    -

    Decoding options

    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Source:
    -
    - - - - - - - -
    - - - - - - - - - - - - - -
    Returns:
    - - -
    -

    Decoded object structure.

    -
    - - - -
    -
    - Type -
    -
    - -Object - - -
    -
    - - - - - - - - - - -

    (static) decodePayload(buf, optsnullable) → {Object}

    - - - - - -
    -

    Decode object message payload.
    NOTE: nonce and objectPayload are copied.

    -
    - - - - - - - - - -
    Parameters:
    - +

    Decoding options

    +
    Properties
    + @@ -348,8 +529,6 @@ nodes.

    - - @@ -362,64 +541,53 @@ nodes.

    - + - - - + - + - - - + + + + + +
    TypeAttributes
    bufallowExpired -Buffer +boolean - - - - - -

    Message payload

    Allow expired objects

    optsskipPow -Object +boolean - - - - <nullable>
    - - - -

    Decoding options

    Do not validate object POW

    + + @@ -460,7 +628,7 @@ nodes.

    Source:
    @@ -487,7 +655,7 @@ nodes.

    -

    Decoded object structure.

    +

    Decoded object structure.

    @@ -498,7 +666,7 @@ nodes.

    -Object +DecodeResult
    @@ -512,6 +680,89 @@ nodes.

    + +

    (static) decodePayload()

    + + + + + +
    +

    Decode object message payload. +The same as decode.

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +

    (static) encode(opts) → {Buffer}

    @@ -572,7 +823,223 @@ nodes.

    -

    Object options

    +

    Object options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    nonce + + +Object + + + + + + + + + +

    A 8-byte object nonce

    ttl + + +number + + + + + + + + + +

    Time to live in seconds

    type + + +number + + + + + + + + + +

    Object type

    version + + +number + + + + + + + + + +

    Object version

    stream + + +number + + + + + + <optional>
    + + + + + +

    Object stream (1 by default)

    objectPayload + + +Buffer + + + + + + + + + +

    Object payload

    + + @@ -613,7 +1080,7 @@ nodes.

    Source:
    @@ -666,14 +1133,15 @@ nodes.

    -

    (static) encodePayload(opts) → {Buffer}

    +

    (static) encodePayload()

    -

    Encode object message payload.

    +

    Encode object message payload. +The same as encode.

    @@ -684,55 +1152,6 @@ nodes.

    -
    Parameters:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescription
    opts - - -Object - - - -

    Object options

    - - @@ -766,7 +1185,7 @@ nodes.

    Source:
    @@ -789,28 +1208,6 @@ nodes.

    -
    Returns:
    - - -
    -

    Encoded payload.

    -
    - - - -
    -
    - Type -
    -
    - -Buffer - - -
    -
    - - @@ -879,7 +1276,192 @@ useful if you are going to calculate it later).

    -

    Object options

    +

    Object options

    +
    Properties
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeAttributesDescription
    ttl + + +number + + + + + + + + + +

    Time to live in seconds

    type + + +number + + + + + + + + + +

    Object type

    version + + +number + + + + + + + + + +

    Object version

    stream + + +number + + + + + + <optional>
    + + + + + +

    Object stream (1 by default)

    objectPayload + + +Buffer + + + + + + + + + +

    Object payload

    + + @@ -920,7 +1502,7 @@ useful if you are going to calculate it later).

    Source:
    @@ -972,6 +1554,268 @@ useful if you are going to calculate it later).

    +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    nonce + + +Buffer + + + +

    A 8-byte object nonce

    ttl + + +number + + + +

    Time to live in seconds

    type + + +number + + + +

    Object type

    version + + +number + + + +

    Object version

    stream + + +number + + + +

    Object stream

    headerLength + + +number + + + +

    Length of the object header

    objectPayload + + +Buffer + + + +

    Object payload

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + @@ -984,13 +1828,13 @@ useful if you are going to calculate it later).


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.var_int.html b/docs/module-bitmessage_structs.var_int.html index 7807db4..ed31ff5 100644 --- a/docs/module-bitmessage_structs.var_int.html +++ b/docs/module-bitmessage_structs.var_int.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -219,7 +219,7 @@
    Source:
    @@ -246,7 +246,7 @@
    -

    Decoded var_int structure.

    +

    Decoded var_int structure.

    @@ -257,7 +257,7 @@
    -Object +DecodeResult
    @@ -375,7 +375,7 @@
    Source:
    @@ -427,6 +427,176 @@ +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    value + + +number + + + +

    Stored value

    length + + +number + + + +

    var_int full length

    rest + + +Buffer + + + +

    The rest of the input buffer

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + @@ -439,13 +609,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.var_int_list.html b/docs/module-bitmessage_structs.var_int_list.html index 521b4a1..2adafeb 100644 --- a/docs/module-bitmessage_structs.var_int_list.html +++ b/docs/module-bitmessage_structs.var_int_list.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -220,7 +220,7 @@
    Source:
    @@ -247,7 +247,7 @@
    -

    Decoded var_int_list structure.

    +

    Decoded var_int_list structure.

    @@ -258,7 +258,7 @@
    -Object +DecodeResult
    @@ -373,7 +373,7 @@
    Source:
    @@ -425,6 +425,176 @@ +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    list + + +number + + + +

    Stored numbers

    length + + +number + + + +

    var_int_list full length

    rest + + +Buffer + + + +

    The rest of the input buffer

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + @@ -437,13 +607,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_structs.var_str.html b/docs/module-bitmessage_structs.var_str.html index 134460f..005dff8 100644 --- a/docs/module-bitmessage_structs.var_str.html +++ b/docs/module-bitmessage_structs.var_str.html @@ -76,7 +76,7 @@
    Source:
    @@ -119,7 +119,7 @@ -

    (static) decode(buf) → {Object}

    +

    (static) decode(buf) → {DecodeResult}

    @@ -219,7 +219,7 @@
    Source:
    @@ -246,7 +246,7 @@
    -

    Decoded var_str structure.

    +

    Decoded var_str structure.

    @@ -257,7 +257,7 @@
    -Object +DecodeResult
    @@ -372,7 +372,7 @@
    Source:
    @@ -424,6 +424,176 @@ +

    Type Definitions

    + + + +

    DecodeResult

    + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    str + + +number + + + +

    The string itself

    length + + +number + + + +

    var_str full length

    rest + + +Buffer + + + +

    The rest of the input buffer

    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Source:
    +
    + + + + + + + +
    + + + + + + + + @@ -436,13 +606,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_user-agent.html b/docs/module-bitmessage_user-agent.html index 918c053..cceae6f 100644 --- a/docs/module-bitmessage_user-agent.html +++ b/docs/module-bitmessage_user-agent.html @@ -360,6 +360,9 @@ comes first.

    | string +| + +Buffer @@ -369,8 +372,8 @@ comes first.

    -

    List of software to -encode or just raw user agent string

    +

    List of +software to encode or just raw user agent string/Buffer

    @@ -471,7 +474,7 @@ encode or just raw user agent string

    -

    Encode bitmessage's user agent.

    +

    Encode bitmessage's library user agent.

    @@ -515,7 +518,7 @@ encode or just raw user agent string

    Source:
    @@ -575,8 +578,8 @@ encode or just raw user agent string

    -

    Encode user agent with bitmessage's user agent underneath. Most -underlying software comes first.

    +

    Encode user agent with bitmessage's library user agent underneath. +Most underlying software comes first.

    @@ -679,7 +682,7 @@ software to encode

    Source:
    @@ -898,13 +901,13 @@ format because it's not that important.


    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/module-bitmessage_wif.html b/docs/module-bitmessage_wif.html index 62e2a5c..74f316c 100644 --- a/docs/module-bitmessage_wif.html +++ b/docs/module-bitmessage_wif.html @@ -151,7 +151,8 @@
    -

    Decode WIF encoded private key.

    +

    Decode WIF-encoded private key (corresponded to a uncompressed public +key).

    @@ -244,7 +245,7 @@
    Source:
    @@ -304,7 +305,8 @@
    -

    Convert private key to a WIF.

    +

    Convert private key to a WIF (corresponded to a uncompressed public +key).

    @@ -397,7 +399,7 @@
    Source:
    @@ -424,7 +426,7 @@
    -

    Encoded private key.

    +

    WIF-encoded private key.

    @@ -461,13 +463,13 @@
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:22 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/net_base.js.html b/docs/net_base.js.html new file mode 100644 index 0000000..967cb86 --- /dev/null +++ b/docs/net_base.js.html @@ -0,0 +1,164 @@ + + + + + JSDoc: Source: net/base.js + + + + + + + + + + +
    + +

    Source: net/base.js

    + + + + + + +
    +
    +
    /**
    + * Networking base module. Defines base transport interface, useful for
    + * implementing new transports. End-users should import some transport
    + * instead in order to connect/accept connections to/from other nodes.  
    + * **NOTE**: `BaseTransport` is exported as a module.
    + * @example var BaseTransport = require("bitmessage/net/base");
    + * @module bitmessage/net/base
    + */
    +// TODO(Kagami): Write some sort of tutorial.
    +
    +"use strict";
    +
    +var inherits = require("inherits");
    +var EventEmitter = require("events").EventEmitter;
    +var PPromise = require("../platform").Promise;
    +var structs = require("../structs");
    +
    +/**
    + * Base transport class. Allows to use single class for both client and
    + * server modes (as separate instances).
    + * @constructor
    + * @static
    + */
    +function BaseTransport() {
    +  BaseTransport.super_.call(this);
    +}
    +
    +inherits(BaseTransport, EventEmitter);
    +
    +/**
    + * Do the transport-specific bootstrap process and return promise that
    + * contains discovered nodes when fulfilled (both modes).  
    + * NOTE: Do not use nodes received by this method in `addr` messages!
    + * This is meaningless.
    + * @return {Promise.<Array>}
    + * @abstract
    + */
    +BaseTransport.prototype.bootstrap = function() {
    +  return PPromise.reject(new Error("Not implemented"));
    +};
    +
    +/**
    + * Connect to the transport-specific address. Enters client mode. Should
    + * emit `open` event after successful connect and `established` event
    + * after `verack` messages exchange.
    + * @abstract
    + */
    +BaseTransport.prototype.connect = function() {
    +  throw new Error("Not implemented");
    +};
    +
    +/**
    + * Listen for the transport-specific incoming connections. Enters server
    + * mode. Should emit `connection` event with a transport instance for
    + * each new connection.
    + * @abstract
    + */
    +BaseTransport.prototype.listen = function() {
    +  throw new Error("Not implemented");
    +};
    +
    +/**
    + * Send [message]{@link module:bitmessage/structs.message} over the
    + * wire (client mode only).
    + * @param {(Buffer|string)} msg - Encoded message or command string
    + * @param {Buffer=} payload - Message payload (used if the first
    + * argument is a string)
    + * @abstract
    + */
    +BaseTransport.prototype.send = function() {
    +  throw new Error("Not implemented");
    +};
    +
    +/**
    + * Send [message]{@link module:bitmessage/structs.message} to all
    + * connected clients (server mode only).
    + * @param {(Buffer|string)} msg - Encoded message or command string
    + * @param {Buffer=} payload - Message payload (used if the first
    + * argument is a string)
    + * @abstract
    + */
    +BaseTransport.prototype.broadcast = function() {
    +  throw new Error("Not implemented");
    +};
    +
    +/**
    + * Close connection(s) and/or stop listening (both modes).
    + * @abstract
    + */
    +BaseTransport.prototype.close = function() {
    +  throw new Error("Not implemented");
    +};
    +
    +// Static private helpers.
    +
    +BaseTransport._getmsg = function(args) {
    +  if (typeof args[0] === "string") {
    +    return structs.message.encode(args[0], args[1]);
    +  } else {
    +    return args[0];
    +  }
    +};
    +
    +// Unmap IPv4-mapped IPv6 address.
    +BaseTransport._unmap = function(addr) {
    +  if (addr.slice(0, 7) === "::ffff:") {
    +    return addr.slice(7);
    +  } else {
    +    return addr;
    +  }
    +};
    +
    +module.exports = BaseTransport;
    +
    +
    +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + diff --git a/docs/net_tcp.js.html b/docs/net_tcp.js.html new file mode 100644 index 0000000..32741cd --- /dev/null +++ b/docs/net_tcp.js.html @@ -0,0 +1,377 @@ + + + + + JSDoc: Source: net/tcp.js + + + + + + + + + + +
    + +

    Source: net/tcp.js

    + + + + + + +
    +
    +
    /**
    + * TCP transport compatible with PyBitmessage. Available only for Node
    + * platform.  
    + * **NOTE**: `TcpTransport` is exported as a module.
    + * @module bitmessage/net/tcp
    + * @example
    + * var messages = require("bitmessage").messages;
    + * var TcpTransport = require("bitmessage/net/tcp");
    + *
    + * var tcp = new TcpTransport({
    + *   dnsSeeds: [["bootstrap8444.bitmessage.org", 8444]],
    + * });
    + *
    + * tcp.bootstrap().then(function(nodes) {
    + *   var remoteHost = nodes[0][0];
    + *   var remotePort = nodes[0][1];
    + *   console.log("Connecting to", nodes[0]);
    + *   tcp.connect(remotePort, remoteHost);
    + * });
    + *
    + * tcp.on("established", function() {
    + *   console.log("Connection established");
    + *
    + *   tcp.on("message", function(command, payload) {
    + *     console.log("Got new", command, "message");
    + *     var decoded;
    + *     if (command === "addr") {
    + *       decoded = messages.addr.decodePayload(payload);
    + *       console.log("Got", decoded.addrs.length, "node addresses");
    + *     }
    + *   });
    + * });
    + */
    +
    +"use strict";
    +
    +var objectAssign = Object.assign || require("object-assign");
    +var inherits = require("inherits");
    +var net = require("net");
    +var dns = require("dns");
    +var assert = require("../_util").assert;
    +var PPromise = require("../platform").Promise;
    +var structs = require("../structs");
    +var messages = require("../messages");
    +var BaseTransport = require("./base");
    +
    +var getmsg = BaseTransport._getmsg;
    +var unmap = BaseTransport._unmap;
    +
    +/**
    + * TCP transport class. Implements
    + * [base transport interface]{@link module:bitmessage/net/base.BaseTransport}.
    + * @param {Object=} opts - Transport options
    + * @param {Array} opts.seeds - Bootstrap nodes (none by default)
    + * @param {Array} opts.dnsSeeds - Bootstrap DNS nodes (none by default)
    + * @param {Object} opts.services -
    + * [Service features]{@link module:bitmessage/structs.ServicesBitfield}
    + * provided by this node (`NODE_NETWORK` by default)
    + * @param {(Array|string|Buffer)} opts.userAgent -
    + * [User agent]{@link module:bitmessage/user-agent} of this node
    + * (bitmessage's by default)
    + * @param {number[]} opts.streamNumbers - Streams accepted by this node
    + * (1 by default)
    + * @param {number} opts.port - Incoming port of this node (8444 by
    + * default)
    + * @constructor
    + * @static
    + */
    +function TcpTransport(opts) {
    +  TcpTransport.super_.call(this);
    +  objectAssign(this, opts);
    +  this.seeds = this.seeds || [];
    +  this.dnsSeeds = this.dnsSeeds || [];
    +  this._clients = {};
    +}
    +
    +inherits(TcpTransport, BaseTransport);
    +
    +function getfrom(client) {
    +  return unmap(client.remoteAddress) + ":" + client.remotePort;
    +}
    +
    +TcpTransport.prototype._sendVersion = function() {
    +  return this.send(messages.version.encode({
    +    services: this.services,
    +    userAgent: this.userAgent,
    +    streamNumbers: this.streamNumbers,
    +    port: this.port,
    +    remoteHost: this._client.remoteAddress,
    +    remotePort: this._client.remotePort,
    +  }));
    +};
    +
    +TcpTransport.prototype._setupClient = function(client, accepted) {
    +  var self = this;
    +  self._client = client;
    +  var cache = Buffer(0);
    +  var decoded;
    +  var verackSent = false;
    +  var verackReceived = false;
    +  var established = false;
    +
    +  // Set default transport timeout per spec.
    +  // TODO(Kagami): We may also want to close connection if it wasn't
    +  // established within minute.
    +  client.setTimeout(20000);
    +
    +  client.on("connect", function() {
    +    // NOTE(Kagami): This handler shouldn't be called at all for
    +    // accepted sockets but let's be sure.
    +    if (!accepted) {
    +      self.emit("open");
    +      self._sendVersion();
    +    }
    +  });
    +
    +  client.on("data", function(data) {
    +    // TODO(Kagami): We may want to preallocate 1.6M buffer for each
    +    // client instead (max size of the message) to not constantly
    +    // allocate new buffers. Though this may lead to another issues: too
    +    // many memory per client.
    +    cache = Buffer.concat([cache, data]);
    +    while (true) {
    +      decoded = structs.message.tryDecode(cache);
    +      if (!decoded) {
    +        break;
    +      }
    +      cache = decoded.rest;
    +      if (decoded.message) {
    +        self.emit(
    +          "message",
    +          decoded.message.command,
    +          decoded.message.payload,
    +          decoded.message);
    +      } else if (decoded.error) {
    +        // TODO(Kagami): Wrap it in custom error class?
    +        // TODO(Kagami): Send `error` message and ban node for some time
    +        // if there were too many errors?
    +        self.emit("warning", new Error(
    +          "Message decoding error from " + getfrom(client) + ": " +
    +          decoded.error
    +        ));
    +      }
    +    }
    +  });
    +
    +  // High-level message processing.
    +  self.on("message", function(command) {
    +    if (!established) {
    +      // TODO: Process version data.
    +      // TODO: Disconnect if proto version < 3.
    +      if (command === "version") {
    +        if (verackSent) {
    +          return;
    +        }
    +        self.send("verack");
    +        verackSent = true;
    +        if (accepted) {
    +          self._sendVersion();
    +        } else if (verackReceived) {
    +          self.emit("established");
    +        }
    +      } else if (command === "verack") {
    +        verackReceived = true;
    +        if (verackSent) {
    +          self.emit("established");
    +        }
    +      }
    +    }
    +  });
    +
    +  self.on("established", function() {
    +    established = true;
    +    // Raise timeout up to 10 minutes per spec.
    +    // TODO(Kagami): Send pong messages every 5 minutes as PyBitmessage.
    +    client.setTimeout(600000);
    +  });
    +
    +  client.on("timeout", function() {
    +    client.end();
    +  });
    +
    +  client.on("error", function(err) {
    +    self.emit("error", err);
    +  });
    +
    +  client.on("close", function() {
    +    self.emit("close");
    +    delete self._client;
    +  });
    +};
    +
    +function resolveDnsSeed(seed) {
    +  var host = seed[0];
    +  var port = seed[1];
    +  var nodes = [];
    +  // NOTE(Kagami):
    +  // 1) Node's `getaddrinfo` (`dns.lookup`) returns only one address so
    +  // we can't use it.
    +  // 2) Node's `dig host any` (`dns.resolve`) doesn't return type of the
    +  // record! So we resolve twice for A and AAAA.
    +  // 3) We ignore any errors here, promise's result is always a list.
    +  return new PPromise(function(resolve) {
    +    dns.resolve4(host, function(err, nodes4) {
    +      if (!err) {
    +        nodes4.forEach(function(n) {
    +          nodes.push([n, port]);
    +        });
    +      }
    +      dns.resolve6(host, function(err, nodes6) {
    +        if (!err) {
    +          nodes6.forEach(function(n) {
    +            nodes.push([n, port]);
    +          });
    +        }
    +        resolve(nodes);
    +      });
    +    });
    +  });
    +}
    +
    +TcpTransport.prototype.bootstrap = function() {
    +  var promises = this.dnsSeeds.map(resolveDnsSeed);
    +  var hardcodedNodes = this.seeds;
    +  // FIXME(Kagami): Filter incorrect/private IP range nodes?
    +  // See also: <https://github.com/Bitmessage/PyBitmessage/issues/768>.
    +  return PPromise.all(promises).then(function(dnsNodes) {
    +    // Flatten array of arrays.
    +    dnsNodes = Array.prototype.concat.apply([], dnsNodes);
    +    // Add hardcoded nodes to the end of list because DNS nodes should
    +    // be more up-to-date.
    +    return dnsNodes.concat(hardcodedNodes);
    +  });
    +};
    +
    +/**
    + * Connect to a TCP node. Connection arguments are the same as for
    + * [net.connect](http://nodejs.org/api/net.html#net_net_connect_port_host_connectlistener).
    + */
    +TcpTransport.prototype.connect = function() {
    +  assert(!this._client, "Already connected");
    +  assert(!this._server, "Already listening");
    +  this._setupClient(net.connect.apply(null, arguments));
    +};
    +
    +/**
    + * Listen for incoming TCP connections. Listen arguments are the same as
    + * for
    + * [server.listen](http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback).
    + */
    +TcpTransport.prototype.listen = function() {
    +  assert(!this._client, "Already connected");
    +  assert(!this._server, "Already listening");
    +
    +  var self = this;
    +  var server = self._server = net.createServer();
    +  server.listen.apply(server, arguments);
    +
    +  // TODO(Kagami): We may want to specify some limits for number of
    +  // connected users.
    +  server.on("connection", function(client) {
    +    var addr = client.remoteAddress;
    +    var port = client.remotePort;
    +    if (self._clients[addr]) {
    +      // NOTE(Kagami): Doesn't allow more than one connection per IP.
    +      // This may obstruct people behind NAT but we copy PyBitmessage's
    +      // behavior here.
    +      client.end();
    +      return self.emit("warning", new Error(
    +        unmap(addr) + " was tried to create second connection"
    +      ));
    +    }
    +    self._clients[addr] = client;
    +    client.on("close", function() {
    +      delete self._clients[addr];
    +    });
    +    var transport = new self.constructor(self);
    +    var accepted = true;
    +    transport._setupClient(client, accepted);
    +    self.emit("connection", transport, unmap(addr), port);
    +    // Emit "open" manually because "connect" for this socket won't be
    +    // fired.
    +    transport.emit("open");
    +  });
    +
    +  server.on("error", function(err) {
    +    self.emit("error", err);
    +  });
    +
    +  server.on("close", function() {
    +    self.emit("close");
    +    delete self._server;
    +  });
    +};
    +
    +TcpTransport.prototype.send = function() {
    +  if (this._client) {
    +    this._client.write(getmsg(arguments));
    +  } else {
    +    throw new Error("Not connected");
    +  }
    +};
    +
    +TcpTransport.prototype.broadcast = function() {
    +  var data = getmsg(arguments);
    +  if (this._server) {
    +    Object.keys(this._clients).forEach(function(ip) {
    +      this._clients[ip].write(data);
    +    }, this);
    +  } else {
    +    throw new Error("Not listening");
    +  }
    +};
    +
    +TcpTransport.prototype.close = function() {
    +  if (this._client) {
    +    this._client.end();
    +  } else if (this._server) {
    +    Object.keys(this._clients).forEach(function(ip) {
    +      this._clients[ip].end();
    +    }, this);
    +    this._server.close();
    +  }
    +};
    +
    +module.exports = TcpTransport;
    +
    +
    +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + diff --git a/docs/net_ws.js.html b/docs/net_ws.js.html new file mode 100644 index 0000000..aad07c5 --- /dev/null +++ b/docs/net_ws.js.html @@ -0,0 +1,307 @@ + + + + + JSDoc: Source: net/ws.js + + + + + + + + + + +
    + +

    Source: net/ws.js

    + + + + + + +
    +
    +
    /**
    + * WebSocket transport. Needed because browsers can't handle TCP sockets
    + * so we use separate WebSocket server to proxy messages into TCP data
    + * packets. Available for both Node.js and Browser platforms.  
    + * **NOTE**: `WsTransport` is exported as a module.
    + * @example var WsTransport = require("bitmessage/net/ws");
    + * @module bitmessage/net/ws
    + */
    +
    +"use strict";
    +
    +var objectAssign = Object.assign || require("object-assign");
    +var inherits = require("inherits");
    +var WebSocket = require("ws");  // jshint ignore:line
    +var assert = require("../_util").assert;
    +var PPromise = require("../platform").Promise;
    +var structs = require("../structs");
    +var messages = require("../messages");
    +var BaseTransport = require("./base");
    +
    +var WebSocketServer = WebSocket.Server;
    +var getmsg = BaseTransport._getmsg;
    +var unmap = BaseTransport._unmap;
    +
    +/**
    + * WebSocket transport class. Implements
    + * [base transport interface]{@link module:bitmessage/net/base.BaseTransport}.
    + * @param {Object=} opts - Transport options
    + * @param {Array} opts.seeds - Bootstrap nodes (none by default)
    + * @param {Object} opts.services -
    + * [Service features]{@link module:bitmessage/structs.ServicesBitfield}
    + * provided by this node (`NODE_NETWORK` by default)
    + * @param {(Array|string|Buffer)} opts.userAgent -
    + * [User agent]{@link module:bitmessage/user-agent} of this node
    + * (bitmessage's by default)
    + * @param {number[]} opts.streamNumbers - Streams accepted by this node
    + * (1 by default)
    + * @param {number} opts.port - Incoming port of this node (8444 by
    + * default)
    + * @constructor
    + * @static
    + */
    +function WsTransport(opts) {
    +  WsTransport.super_.call(this);
    +  objectAssign(this, opts);
    +  this.seeds = this.seeds || [];
    +}
    +
    +inherits(WsTransport, BaseTransport);
    +
    +function getfrom(client) {
    +  return unmap(client._socket.remoteAddress) + ":" + client._socket.remotePort;
    +}
    +
    +WsTransport.prototype._sendVersion = function() {
    +  return this.send(messages.version.encode({
    +    services: this.services,
    +    userAgent: this.userAgent,
    +    streamNumbers: this.streamNumbers,
    +    port: this.port,
    +    remoteHost: this._client._socket.remoteAddress,
    +    remotePort: this._client._socket.remotePort,
    +  }));
    +};
    +
    +WsTransport.prototype._handleTimeout = function() {
    +  var client = this._client;
    +  // TODO(Kagami): We may also want to close connection if it wasn't
    +  // established within minute.
    +  client._socket.setTimeout(20000);
    +  client._socket.on("timeout", function() {
    +    client.close();
    +  });
    +  this.on("established", function() {
    +    // Raise timeout up to 10 minutes per spec.
    +    // TODO(Kagami): Send ping frame every 5 minutes as PyBitmessage.
    +    client._socket.setTimeout(600000);
    +  });
    +};
    +
    +WsTransport.prototype._setupClient = function(client, accepted) {
    +  var self = this;
    +  self._client = client;
    +  var verackSent = false;
    +  var verackReceived = false;
    +  var established = false;
    +
    +  client.on("open", function() {
    +    // NOTE(Kagami): This handler shouldn't be called at all for
    +    // accepted sockets but let's be sure.
    +    if (!accepted) {
    +      // NOTE(Kagami): We may set timeout only after connection was
    +      // opened because socket may not yet be available when
    +      // `_setupClient` is called.
    +      self._handleTimeout();
    +      self.emit("open");
    +      self._sendVersion();
    +    }
    +  });
    +
    +  client.on("message", function(data, flags) {
    +    var decoded;
    +    if (!flags.binary) {
    +      // TODO(Kagami): Send `error` message and ban node for some time
    +      // if there were too many errors?
    +      return self.emit("warning", new Error(
    +        "Peer " + getfrom(client) + " sent non-binary data"
    +      ));
    +    }
    +    try {
    +      decoded = structs.message.decode(data);
    +    } catch (err) {
    +      return self.emit("warning", new Error(
    +        "Message decoding error from " + getfrom(client) + ": " + err
    +      ));
    +    }
    +    self.emit("message", decoded.command, decoded.payload, decoded);
    +  });
    +
    +  // High-level message processing.
    +  self.on("message", function(command) {
    +    if (!established) {
    +      // TODO: Process version data.
    +      // TODO: Disconnect if proto version < 3.
    +      if (command === "version") {
    +        if (verackSent) {
    +          return;
    +        }
    +        self.send("verack");
    +        verackSent = true;
    +        if (accepted) {
    +          self._sendVersion();
    +        } else if (verackReceived) {
    +          established = true;
    +          self.emit("established");
    +        }
    +      } else if (command === "verack") {
    +        verackReceived = true;
    +        if (verackSent) {
    +          established = true;
    +          self.emit("established");
    +        }
    +      }
    +    }
    +  });
    +
    +  client.on("error", function(err) {
    +    self.emit("error", err);
    +  });
    +
    +  client.on("close", function() {
    +    self.emit("close");
    +    delete self._client;
    +  });
    +};
    +
    +WsTransport.prototype.bootstrap = function() {
    +  return PPromise.resolve([].concat(this.seeds));
    +};
    +
    +/**
    + * Connect to a WebSocket node. Connection arguments are the same as for
    + * [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
    + */
    +WsTransport.prototype.connect = function(address, protocols, options) {
    +  assert(!this._client, "Already connected");
    +  assert(!this._server, "Already listening");
    +  // `new` doesn't work with `apply`, so passing all possible arguments
    +  // manually.
    +  this._setupClient(new WebSocket(address, protocols, options));
    +};
    +
    +/**
    + * Listen for incoming WebSocket connections. Listen arguments are the
    + * same as for
    + * [WebSocketServer](https://github.com/websockets/ws#server-example).
    + * Available only for Node platform.
    + */
    +WsTransport.prototype.listen = function(options, callback) {
    +  assert(!this._client, "Already connected");
    +  assert(!this._server, "Already listening");
    +
    +  var self = this;
    +  var server = self._server = new WebSocketServer(options, callback);
    +
    +  // TODO(Kagami): We may want to specify some limits for number of
    +  // connected users.
    +  server.on("connection", function(client) {
    +    var addr = client._socket.remoteAddress;
    +    var port = client._remotePort;
    +    var i;
    +
    +    // NOTE(Kagami): O(n) search because `clients` array is already
    +    // provided by `ws` library. We may want to optmize it though and
    +    // also disable `clientTracking` option.
    +    for (i = 0; i < server.clients.length; i++) {
    +      if (server.clients[i] !== client &&
    +          server.clients[i]._socket.remoteAddress === addr) {
    +        // NOTE(Kagami): Doesn't allow more than one connection per IP.
    +        // This may obstruct people behind NAT but we copy
    +        // PyBitmessage's behavior here.
    +        client.close();
    +        return self.emit("warning", new Error(
    +          unmap(addr) + " was tried to create second connection"
    +        ));
    +      }
    +    }
    +
    +    var transport = new self.constructor(self);
    +    var accepted = true;
    +    transport._setupClient(client, accepted);
    +    transport._handleTimeout();
    +    self.emit("connection", transport, unmap(addr), port);
    +    // Emit "open" manually because it won't be fired for already opened
    +    // socket.
    +    transport.emit("open");
    +  });
    +
    +  server.on("error", function(err) {
    +    self.emit("error", err);
    +  });
    +};
    +
    +WsTransport.prototype.send = function() {
    +  if (this._client) {
    +    // TODO(Kagami): `mask: true` doesn't work with Chromium 40. File a
    +    // bug to ws bugtracker.
    +    this._client.send(getmsg(arguments), {binary: true});
    +  } else {
    +    throw new Error("Not connected");
    +  }
    +};
    +
    +WsTransport.prototype.broadcast = function() {
    +  var data = getmsg(arguments);
    +  if (this._server) {
    +    this._server.clients.forEach(function(client) {
    +      client.send(data, {binary: true});
    +    });
    +  } else {
    +    throw new Error("Not listening");
    +  }
    +};
    +
    +WsTransport.prototype.close = function() {
    +  if (this._client) {
    +    this._client.close();
    +  } else if (this._server) {
    +    // `ws` server terminates immediately without any events.
    +    this._server.close();
    +    this.emit("close");
    +    delete this._server;
    +  }
    +};
    +
    +module.exports = WsTransport;
    +
    +
    +
    + + + + +
    + + + +
    + +
    + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK) +
    + + + + + diff --git a/docs/objects.js.html b/docs/objects.js.html index d209058..ef32a87 100644 --- a/docs/objects.js.html +++ b/docs/objects.js.html @@ -28,22 +28,18 @@
    /**
      * Working with objects.  
    - * NOTE: Most operations with objects in this module are asynchronous
    - * and return promises.
    + * NOTE: Most operations with objects are asynchronous and return
    + * promises.
      * @see {@link https://bitmessage.org/wiki/Protocol_specification#Object_types}
      * @module bitmessage/objects
      */
    -// TODO(Kagami): Document object-like params.
    -// FIXME(Kagami): Think through the API, we may want to get decoded
    -// structure even if it contains unsupported version. Also error
    -// handling may need some refactoring.
     
     "use strict";
     
     var objectAssign = Object.assign || require("object-assign");
     var bufferEqual = require("buffer-equal");
     var assert = require("./_util").assert;
    -var promise = require("./platform").promise;
    +var PPromise = require("./platform").Promise;
     var bmcrypto = require("./crypto");
     var Address = require("./address");
     var structs = require("./structs");
    @@ -76,14 +72,7 @@ exports.getType = function(buf) {
     
     /**
      * Try to get type of the given object message payload.
    - * Note that this function doesn't do any validation because it is
    - * already provided by
    - * [object.decodePayload]{@link module:bitmessage/structs.object.decodePayload}
    - * routine. Normally you call this for each incoming object message
    - * payload and then call decode function of the appropriate object
    - * handler.
    - * @param {Buffer} buf - Buffer that starts with object message payload
    - * @return {?number} Object's type if any.
    + * The same as [getType]{@link module:bitmessage/objects.getType}.
      */
     exports.getPayloadType = function(buf) {
       // Object header: 8 + 8 + 4
    @@ -95,7 +84,7 @@ exports.getPayloadType = function(buf) {
     
     // Prepend nonce to a given object without nonce.
     function prependNonce(obj, opts) {
    -  return new promise(function(resolve) {
    +  return new PPromise(function(resolve) {
         assert(obj.length <= 262136, "object message payload is too big");
         opts = objectAssign({}, opts);
         var nonce, target, powp;
    @@ -129,15 +118,33 @@ function prependNonce(obj, opts) {
      * @static
      */
     var getpubkey = exports.getpubkey = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {Buffer} nonce - A 8-byte object nonce
    +   * @property {number} ttl - Time to live in seconds
    +   * @property {number} type - Object type
    +   * @property {number} version - Object version
    +   * @property {number} stream - Object stream
    +   * @property {number} headerLength - Length of the object header
    +   * @property {Buffer} ripe - The RIPEMD hash of the requested public
    +   * keys for address version <= 3
    +   * @property {Buffer} tag - ...or tag derived from the address object
    +   * for address version >= 4
    +   * @property {number} length - Real data length
    +   * @memberof module:bitmessage/objects.getpubkey
    +   */
    +
       /**
        * Decode `getpubkey` object message.
        * @param {Buffer} buf - Message
    -   * @param {?Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded
    -   * `getpubkey` object structure when fulfilled.
    +   * @param {Object=} opts - Any of [object.decode]{@link
    +   * module:bitmessage/structs.object.decode} options
    +   * @return {Promise.<DecodeResult>} A promise that contains
    +   * [decoded `getpubkey` structure]{@link
    +   * module:bitmessage/objects.getpubkey.DecodeResult} when fulfilled.
        */
       decodeAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = message.decode(buf);
           assert(decoded.command === "object", "Bad command");
           resolve(getpubkey.decodePayloadAsync(decoded.payload, opts));
    @@ -146,13 +153,11 @@ var getpubkey = exports.getpubkey = {
     
       /**
        * Decode `getpubkey` object message payload.
    -   * @param {Buffer} buf - Message payload
    -   * @param {?Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded
    -   * `getpubkey` object structure when fulfilled.
    +   * The same as [decodeAsync]{@link
    +   * module:bitmessage/objects.getpubkey.decodeAsync}.
        */
       decodePayloadAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = object.decodePayload(buf, opts);
           assert(decoded.type === object.GETPUBKEY, "Wrong object type");
           assert(decoded.version >= 2, "getpubkey version is too low");
    @@ -174,6 +179,10 @@ var getpubkey = exports.getpubkey = {
       /**
        * Encode `getpubkey` object message.
        * @param {Object} opts - `getpubkey` object options
    +   * @param {number} opts.ttl - Time to live in seconds
    +   * @param {Address} opts.to - Receiver of the message
    +   * @param {boolean=} opts.skipPow - Do not compute POW (false by
    +   * default)
        * @return {Promise.<Buffer>} A promise that contains encoded message
        * when fulfilled.
        */
    @@ -185,12 +194,11 @@ var getpubkey = exports.getpubkey = {
     
       /**
        * Encode `getpubkey` object message payload.
    -   * @param {Object} opts - `getpubkey` object options
    -   * @return {Promise.<Buffer>} A promise that contains encoded message
    -   * payload when fulfilled.
    +   * The same as
    +   * [encodeAsync]{@link module:bitmessage/objects.getpubkey.encodeAsync}.
        */
       encodePayloadAsync: function(opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           opts = objectAssign({}, opts);
           opts.type = object.GETPUBKEY;
           // Bitmessage address of recepeint of `getpubkey` message.
    @@ -270,15 +278,48 @@ function findAddrByTag(addrs, tag) {
      * @static
      */
     var pubkey = exports.pubkey = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {Buffer} nonce - A 8-byte object nonce
    +   * @property {number} ttl - Time to live in seconds
    +   * @property {number} type - Object type
    +   * @property {number} version - Object version
    +   * @property {number} stream - Object stream
    +   * @property {number} headerLength - Length of the object header
    +   * @property {Buffer} tag - Tag derived from the address object
    +   * (present only if object version is 4)
    +   * @property {Object} behavior - [Pubkey features]{@link
    +   * module:bitmessage/structs.PubkeyBitfield} that can be expected from
    +   * the node
    +   * @property {Buffer} signPublicKey - Signing public key
    +   * @property {Buffer} encPublicKey - Encryption public key
    +   * @property {number} nonceTrialsPerByte - Difficulty parameter of the
    +   * node (present only for `pubkey` version >= 3)
    +   * @property {number} payloadLengthExtraBytes - Difficulty parameter
    +   * of the node (present only for `pubkey` version >= 3)
    +   * @property {Buffer} signature - Signature of the message (present
    +   * only for `pubkey` version >= 3)
    +   * @property {number} length - Real data length
    +   * @memberof module:bitmessage/objects.pubkey
    +   */
    +
       /**
        * Decode `pubkey` object message.
        * @param {Buffer} buf - Message
    -   * @param {?Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded `pubkey`
    -   * object structure when fulfilled.
    +   * @param {Object=} opts - Any of [object.decode]{@link
    +   * module:bitmessage/structs.object.decode} options and:
    +   * @param {(Address[]|Address|Object)} opts.needed - Address objects
    +   * which represent pubkeys that we are interested in (used only for
    +   * pubkeys v4). It is either addresses array or single address or
    +   * Object addr-by-tag. Time to match the key is O(n), O(1), O(1)
    +   * respectfully.
    +   * @return {Promise.<DecodeResult>} A promise that contains
    +   * [decoded `pubkey` structure]{@link
    +   * module:bitmessage/objects.pubkey.DecodeResult}
    +   * when fulfilled.
        */
       decodeAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = message.decode(buf);
           assert(decoded.command === "object", "Bad command");
           resolve(pubkey.decodePayloadAsync(decoded.payload, opts));
    @@ -287,13 +328,11 @@ var pubkey = exports.pubkey = {
     
       /**
        * Decode `pubkey` object message payload.
    -   * @param {Buffer} buf - Message payload
    -   * @param {?Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded `pubkey`
    -   * object structure when fulfilled.
    +   * The same as [decodeAsync]{@link
    +   * module:bitmessage/objects.pubkey.decodeAsync}.
        */
       decodePayloadAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           opts = opts || {};
           var decoded = object.decodePayload(buf, opts);
           assert(decoded.type === object.PUBKEY, "Wrong object type");
    @@ -369,6 +408,11 @@ var pubkey = exports.pubkey = {
       /**
        * Encode `pubkey` object message.
        * @param {Object} opts - `pubkey` object options
    +   * @param {number} opts.ttl - Time to live in seconds
    +   * @param {Address} opts.from - Originator of the message
    +   * @param {Address} opts.to - Receiver of the message
    +   * @param {boolean=} opts.skipPow - Do not compute POW (false by
    +   * default)
        * @return {Promise.<Buffer>} A promise that contains encoded message
        * when fulfilled.
        */
    @@ -380,12 +424,11 @@ var pubkey = exports.pubkey = {
     
       /**
        * Encode `pubkey` object message payload.
    -   * @param {Object} opts - `pubkey` object options
    -   * @return {Promise.<Buffer>} A promise that contains encoded message
    -   * payload when fulfilled.
    +   * The same as [encodeAsync]{@link
    +   * module:bitmessage/objects.pubkey.encodeAsync}.
        */
       encodePayloadAsync: function(opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           opts = objectAssign({}, opts);
           opts.type = object.PUBKEY;
           // Originator of `pubkey` message.
    @@ -465,8 +508,9 @@ var pubkey = exports.pubkey = {
     function tryDecryptMsg(identities, buf) {
       function inner(i) {
         if (i > last) {
    -      var err = new Error("Failed to decrypt msg with given identities");
    -      return promise.reject(err);
    +      return PPromise.reject(
    +        new Error("Failed to decrypt msg with given identities")
    +      );
         }
         return bmcrypto
           .decrypt(identities[i].encPrivateKey, buf)
    @@ -567,15 +611,52 @@ var msg = exports.msg = {
        */
       SIMPLE: 2,
     
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {Buffer} nonce - A 8-byte object nonce
    +   * @property {number} ttl - Time to live in seconds
    +   * @property {number} type - Object type
    +   * @property {number} version - Object version
    +   * @property {number} stream - Object stream
    +   * @property {number} headerLength - Length of the object header
    +   * @property {number} senderVersion - Sender's address version
    +   * @property {number} senderStream - Sender's stream
    +   * @property {Object} behavior - Sender's [pubkey features]{@link
    +   * module:bitmessage/structs.PubkeyBitfield} that can be expected from
    +   * the node
    +   * @property {Buffer} signPublicKey - Sender's signing public key
    +   * @property {Buffer} encPublicKey - Sender's encryption public key
    +   * @property {number} nonceTrialsPerByte - Difficulty parameter of the
    +   * sender (present only if sender's address version >= 3)
    +   * @property {number} payloadLengthExtraBytes - Difficulty parameter
    +   * of the sender (present only if sender's address version >= 3)
    +   * @property {Buffer} ripe - The RIPEMD hash of the receiver's keys
    +   * @property {number} encoding - Message encoding
    +   * @property {(string|Buffer)} message - Message string for
    +   * [TRIVIAL]{@link module:bitmessage/objects.msg.TRIVIAL} and
    +   * [SIMPLE]{@link module:bitmessage/objects.msg.SIMPLE} encodings or
    +   * unparsed buffer data for other encodings
    +   * @property {string=} subject - Subject string for [SIMPLE]{@link
    +   * module:bitmessage/objects.msg.SIMPLE} encoding
    +   * @property {Buffer} ack - Message acknowledgement
    +   * @property {Buffer} signature - Signature of the message
    +   * @property {number} length - Real data length
    +   * @memberof module:bitmessage/objects.msg
    +   */
    +
       /**
        * Decode `msg` object message.
        * @param {Buffer} buf - Message
    -   * @param {Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded `msg`
    -   * object structure when fulfilled.
    +   * @param {Object} opts - Any of [object.decode]{@link
    +   * module:bitmessage/structs.object.decode} options and:
    +   * @param {(Address[]|Address)} opts.identities - Address objects used
    +   * to decrypt the message
    +   * @return {Promise.<DecodeResult>} A promise that contains [decoded
    +   * `msg` structure]{@link module:bitmessage/objects.msg.DecodeResult}
    +   * when fulfilled.
        */
       decodeAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = message.decode(buf);
           assert(decoded.command === "object", "Bad command");
           resolve(msg.decodePayloadAsync(decoded.payload, opts));
    @@ -584,13 +665,11 @@ var msg = exports.msg = {
     
       /**
        * Decode `msg` object message payload.
    -   * @param {Buffer} buf - Message payload
    -   * @param {Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded `msg`
    -   * object structure when fulfilled.
    +   * The same as [decodeAsync]{@link
    +   * module:bitmessage/objects.msg.decodeAsync}.
        */
       decodePayloadAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = object.decodePayload(buf, opts);
           assert(decoded.type === object.MSG, "Bad object type");
           assert(decoded.version === 1, "Bad msg version");
    @@ -617,7 +696,7 @@ var msg = exports.msg = {
               var rest = decrypted.slice(decoded.length);
     
               // Pow extra.
    -          if (decoded.senderVersion >= 3) {
    +          if (senderVersion >= 3) {
                 var decodedTrials = var_int.decode(rest);
                 decoded.nonceTrialsPerByte = decodedTrials.value;
                 decoded.length += decodedTrials.length;
    @@ -685,6 +764,18 @@ var msg = exports.msg = {
       /**
        * Encode `msg` object message.
        * @param {Object} opts - `msg` object options
    +   * @param {number} opts.ttl - Time to live in seconds
    +   * @param {Address} opts.from - Originator of the message
    +   * @param {Address} opts.to - Receiver of the message
    +   * @param {(string|Buffer)} opts.message - Message
    +   * @param {(string|Buffer)=} opts.subject - Subject for [SIMPLE]{@link
    +   * module:bitmessage/objects.msg.SIMPLE} encoding
    +   * @param {number=} opts.encoding - Encoding of the message
    +   * ([TRIVIAL]{@link module:bitmessage/objects.msg.TRIVIAL} by default)
    +   * @param {boolean=} opts.friend - Whether the receiver is friend and
    +   * should have minimal POW difficulty (false by default)
    +   * @param {boolean=} opts.skipPow - Do not compute POW (false by
    +   * default)
        * @return {Promise.<Buffer>} A promise that contains encoded message
        * when fulfilled.
        */
    @@ -696,12 +787,11 @@ var msg = exports.msg = {
     
       /**
        * Encode `msg` object message payload.
    -   * @param {Object} opts - `msg` object options
    -   * @return {Promise.<Buffer>} A promise that contains encoded message
    -   * payload when fulfilled.
    +   * The same as [encodeAsync]{@link
    +   * module:bitmessage/objects.msg.encodeAsync}.
        */
       encodePayloadAsync: function(opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           // Deal with options.
           opts = objectAssign({}, opts);
           opts.type = object.MSG;
    @@ -776,8 +866,9 @@ var DEFAULT_ENCODING = msg.TRIVIAL;
     function tryDecryptBroadcastV4(subscriptions, buf) {
       function inner(i) {
         if (i > last) {
    -      var err = new Error("Failed to decrypt broadcast with given identities");
    -      return promise.reject(err);
    +      return PPromise.reject(
    +        new Error("Failed to decrypt broadcast with given identities")
    +      );
         }
         return bmcrypto
           .decrypt(subscriptions[i].getBroadcastPrivateKey(), buf)
    @@ -810,15 +901,55 @@ function tryDecryptBroadcastV4(subscriptions, buf) {
      * @static
      */
     var broadcast = exports.broadcast = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {Buffer} nonce - A 8-byte object nonce
    +   * @property {number} ttl - Time to live in seconds
    +   * @property {number} type - Object type
    +   * @property {number} version - Object version
    +   * @property {number} stream - Object stream
    +   * @property {number} headerLength - Length of the object header
    +   * @property {Buffer} tag - Tag derived from the address object used
    +   * to send this `broadcast` (present only for object version >= 5)
    +   * @property {number} senderVersion - Sender's address version
    +   * @property {number} senderStream - Sender's stream
    +   * @property {Object} behavior - Sender's [pubkey features]{@link
    +   * module:bitmessage/structs.PubkeyBitfield} that can be expected from
    +   * the node
    +   * @property {Buffer} signPublicKey - Sender's signing public key
    +   * @property {Buffer} encPublicKey - Sender's encryption public key
    +   * @property {number} nonceTrialsPerByte - Difficulty parameter of the
    +   * sender (present only if sender's address version >= 3)
    +   * @property {number} payloadLengthExtraBytes - Difficulty parameter
    +   * of the sender (present only if sender's address version >= 3)
    +   * @property {number} encoding - Message encoding
    +   * @property {(string|Buffer)} message - Message string for
    +   * [TRIVIAL]{@link module:bitmessage/objects.msg.TRIVIAL} and
    +   * [SIMPLE]{@link module:bitmessage/objects.msg.SIMPLE} encodings or
    +   * unparsed buffer data for other encodings
    +   * @property {string=} subject - Subject string for [SIMPLE]{@link
    +   * module:bitmessage/objects.msg.SIMPLE} encoding
    +   * @property {Buffer} signature - Signature of the message
    +   * @property {number} length - Real data length
    +   * @memberof module:bitmessage/objects.broadcast
    +   */
    +
       /**
        * Decode `broadcast` object message.
        * @param {Buffer} buf - Message
    -   * @param {Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded
    -   * `broadcast` object structure when fulfilled.
    +   * @param {Object} opts - Any of [object.decode]{@link
    +   * module:bitmessage/structs.object.decode} options and:
    +   * @param {(Address[]|Address|Object)} opts.subscriptions - Address
    +   * objects which represent broadcast subscriptions. It is either
    +   * addresses array or single address or Object
    +   * addr-by-tag/addr-by-ripe. Time to match the key is O(n), O(1), O(1)
    +   * respectfully.
    +   * @return {Promise.<DecodeResult>} A promise that contains
    +   * [decoded `broadcast` structure]{@link
    +   * module:bitmessage/objects.broadcast.DecodeResult} when fulfilled.
        */
       decodeAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = message.decode(buf);
           assert(decoded.command === "object", "Bad command");
           resolve(broadcast.decodePayloadAsync(decoded.payload, opts));
    @@ -827,13 +958,11 @@ var broadcast = exports.broadcast = {
     
       /**
        * Decode `broadcast` object message payload.
    -   * @param {Buffer} buf - Message payload
    -   * @param {Object} opts - Decoding options
    -   * @return {Promise.<Object>} A promise that contains decoded `pubkey`
    -   * object structure when fulfilled.
    +   * The same as [decodeAsync]{@link
    +   * module:bitmessage/objects.broadcast.decodeAsync}.
        */
       decodePayloadAsync: function(buf, opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           var decoded = object.decodePayload(buf, opts);
           assert(decoded.type === object.BROADCAST, "Bad object type");
           var version = decoded.version;
    @@ -957,6 +1086,15 @@ var broadcast = exports.broadcast = {
       /**
        * Encode `broadcast` object message.
        * @param {Object} opts - `broadcast` object options
    +   * @param {number} opts.ttl - Time to live in seconds
    +   * @param {Address} opts.from - Originator of the message
    +   * @param {(string|Buffer)} opts.message - Message
    +   * @param {(string|Buffer)=} opts.subject - Subject for [SIMPLE]{@link
    +   * module:bitmessage/objects.msg.SIMPLE} encoding
    +   * @param {number=} opts.encoding - Encoding of the message
    +   * ([TRIVIAL]{@link module:bitmessage/objects.msg.TRIVIAL} by default)
    +   * @param {boolean=} opts.skipPow - Do not compute POW (false by
    +   * default)
        * @return {Promise.<Buffer>} A promise that contains encoded message
        * when fulfilled.
        */
    @@ -968,12 +1106,11 @@ var broadcast = exports.broadcast = {
     
       /**
        * Encode `broadcast` object message payload.
    -   * @param {Object} opts - `broadcast` object options
    -   * @return {Promise.<Buffer>} A promise that contains encoded message
    -   * payload when fulfilled.
    +   * The same as [encodeAsync]{@link
    +   * module:bitmessage/objects.broadcast.encodeAsync}.
        */
       encodePayloadAsync: function(opts) {
    -    return new promise(function(resolve) {
    +    return new PPromise(function(resolve) {
           // Deal with options.
           opts = objectAssign({}, opts);
           opts.type = object.BROADCAST;
    @@ -1033,13 +1170,13 @@ var broadcast = exports.broadcast = {
     
     
     
     
     
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/pow.js.html b/docs/pow.js.html index 25fb3c7..07698bf 100644 --- a/docs/pow.js.html +++ b/docs/pow.js.html @@ -31,7 +31,6 @@ * @see {@link https://bitmessage.org/wiki/Proof_of_work} * @module bitmessage/pow */ -// TODO(Kagami): Find a way how to document object params properly. "use strict"; @@ -43,6 +42,18 @@ var util = require("./_util"); /** * Calculate target. * @param {Object} opts - Target options + * @param {number} opts.ttl - Time to live of the message in seconds + * @param {number} opts.payloadLength - Length of the message payload + * (with nonce) + * @param {Buffer} opts.payload - ...or payload itself + * @param {number=} opts.nonceTrialsPerByte - 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. + * @param {number=} opts.payloadLengthExtraBytes - 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. * @return {number} Target. * @function * @static @@ -61,6 +72,12 @@ var getTarget = exports.getTarget = function(opts) { /** * Check a POW. * @param {Object} opts - Proof of work options + * @param {number} opts.target - Proof of work target or pass + * [getTarget]{@link module:bitmessage/pow.getTarget} options to `opts` + * to compute it + * @param {Buffer} opts.payload - Message payload (with nonce) + * @param {(number|Buffer)} opts.nonce - ...or already derived nonce + * @param {Buffer} opts.initialHash - ...and initial hash * @return {boolean} Is the proof of work sufficient. */ exports.check = function(opts) { @@ -103,10 +120,13 @@ exports.check = function(opts) { /** * Do a POW. * @param {Object} opts - Proof of work options - * @param {?Buffer} opts.data - Object message payload without nonce to + * @param {Buffer} opts.data - Object message payload without nonce to * get the initial hash from - * @param {?Buffer} opts.initialHash - Or already computed initial hash + * @param {Buffer} opts.initialHash - ...or already computed initial + * hash * @param {number} opts.target - POW target + * @param {number=} opts.poolSize - POW calculation pool size (by + * default equals to number of cores) * @return {Promise.<number>} A promise that contains computed nonce for * the given target when fulfilled. */ @@ -130,13 +150,13 @@ exports.doAsync = function(opts) {
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/structs.js.html b/docs/structs.js.html index 37afdd1..521446d 100644 --- a/docs/structs.js.html +++ b/docs/structs.js.html @@ -28,10 +28,28 @@
    /**
      * Implements common structures.
    - * @see {@link https://bitmessage.org/wiki/Protocol_specification#Common_structures}
    + * @see {@link
    + * https://bitmessage.org/wiki/Protocol_specification#Common_structures}
      * @module bitmessage/structs
    + * @example
    + * var structs = require("bitmessage").structs;
    + *
    + * var encoded = Buffer.concat([
    + *   structs.var_int.encode(4),
    + *   Buffer("test"),
    + *   structs.var_str.encode("test2"),
    + *   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]
      */
    -// TODO(Kagami): Document object-like params.
     
     "use strict";
     
    @@ -56,6 +74,48 @@ function getmsgchecksum(data) {
       return bmcrypto.sha512(data).slice(0, 4);
     }
     
    +// \ :3 /
    +function findMagic(buf) {
    +  var i;
    +  var len = buf.length;
    +  var firstb = false;
    +  var secondb = false;
    +  var thirdb = false;
    +  for (i = 0; i < len; ++i) {
    +    switch (buf[i]) {
    +      case 0xE9:
    +        firstb = true;
    +        break;
    +      case 0xBE:
    +        if (firstb) { secondb = true; }
    +        break;
    +      case 0xB4:
    +        if (firstb && secondb) { thirdb = true; }
    +        break;
    +      case 0xD9:
    +        if (firstb && secondb && thirdb) { return i - 3; }
    +        break;
    +      default:
    +        firstb = false;
    +        secondb = false;
    +        thirdb = false;
    +    }
    +  }
    +  // If we reached the end of the buffer but part of the magic matches
    +  // we'll still return index of the magic's start position.
    +  if (firstb) {
    +    if (secondb) {
    +      --i;
    +    }
    +    if (thirdb) {
    +      --i;
    +    }
    +    return i - 1;  // Compensate for last i's increment
    +  } else {
    +    return -1;
    +  }
    +}
    +
     /**
      * Message structure.
      * @see {@link https://bitmessage.org/wiki/Protocol_specification#Message_structure}
    @@ -70,11 +130,118 @@ var message = exports.message = {
       MAGIC: 0xE9BEB4D9,
     
       /**
    -   * Decode message structure.  
    +   * @typedef {Object} TryDecodeResult
    +   * @property {Object} message - Decoded message
    +   * @property {string} message.command - Message command
    +   * @property {Buffer} message.payload - Message payload
    +   * @property {number} message.length - Full message length
    +   * @property {Error} error - ...or decoding error
    +   * @property {Buffer} rest - The rest of the input buffer after
    +   * processing message
    +   * @memberof module:bitmessage/structs.message
    +   */
    +
    +  /**
    +   * Decode message in "stream" mode.  
    +   * NOTE: message payload and `rest` are copied (so the runtime can GC
    +   * processed buffer data).
    +   * @param {Buffer} buf - Data buffer
    +   * @return {?TryDecodeResult}
    +   * [Decoded result.]{@link module:bitmessage/structs.message.TryDecodeResult}
    +   */
    +  tryDecode: function(buf) {
    +    if (buf.length < 24) {
    +      // Message is not yet fully received, just skip to next process
    +      // cycle.
    +      return;
    +    }
    +    var res = {};
    +
    +    // Magic.
    +    var mindex = findMagic(buf);
    +    if (mindex !== 0) {
    +      if (mindex === -1) {
    +        res.error = new Error("Magic not found, skipping buffer data");
    +        res.rest = new Buffer(0);
    +      } else {
    +        res.error = new Error(
    +          "Magic in the middle of buffer, skipping some data at start"
    +        );
    +        res.rest = new Buffer(buf.length - mindex);
    +        buf.copy(res.rest, 0, mindex);
    +      }
    +      return res;
    +    }
    +
    +    // Payload length.
    +    var payloadLength = buf.readUInt32BE(16, true);
    +    var msgLength = 24 + payloadLength;
    +    // See: <https://github.com/Bitmessage/PyBitmessage/issues/767>.
    +    if (payloadLength > 1600003) {
    +      res.error = new Error("Message is too large, skipping it");
    +      if (buf.length > msgLength) {
    +        res.rest = new Buffer(buf.length - msgLength);
    +        buf.copy(res.rest, 0, msgLength);
    +      } else {
    +        res.rest = new Buffer(0);
    +      }
    +      return res;
    +    }
    +    if (buf.length < msgLength) {
    +      // Message is not yet fully received, just skip to next process
    +      // cycle.
    +      return;
    +    }
    +
    +    // Now we can set `rest` value.
    +    res.rest = new Buffer(buf.length - msgLength);
    +    buf.copy(res.rest, 0, msgLength);
    +
    +    // Command.
    +    var command = buf.slice(4, 16);
    +    var firstNonNull = 0;
    +    var i;
    +    for (i = 11; i >=0; i--) {
    +      if (command[i] > 127) {
    +        res.error = new Error(
    +          "Non-ASCII characters in command, skipping message"
    +        );
    +        return res;
    +      }
    +      if (!firstNonNull && command[i] !== 0) {
    +        firstNonNull = i + 1;
    +      }
    +    }
    +    command = command.slice(0, firstNonNull).toString("ascii");
    +
    +    // Payload.
    +    var payload = new Buffer(payloadLength);
    +    buf.copy(payload, 0, 24, msgLength);
    +    var checksum = buf.slice(20, 24);
    +    if (!bufferEqual(checksum, getmsgchecksum(payload))) {
    +      res.error = new Error("Bad checksum, skipping message");
    +      return res;
    +    }
    +
    +    res.message = {command: command, payload: payload, length: msgLength};
    +    return res;
    +  },
    +
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {string} command - Message command
    +   * @property {Buffer} payload - Message payload
    +   * @property {number} length - Full message length
    +   * @property {Buffer} rest - The rest of the input buffer
    +   * @memberof module:bitmessage/structs.message
    +   */
    +
    +  /**
    +   * Decode message.  
        * NOTE: `payload` is copied, `rest` references input buffer.
        * @param {Buffer} buf - Buffer that starts with encoded message
    -   * @return {{command: string, payload: Buffer, length: number, rest: Buffer}}
    -   * Decoded message structure.
    +   * @return {DecodeResult}
    +   * [Decoded message structure.]{@link module:bitmessage/structs.message.DecodeResult}
        */
       decode: function(buf) {
         assert(buf.length >= 24, "Buffer is too small");
    @@ -93,6 +260,7 @@ var message = exports.message = {
         // than default "utf-8" encoding.
         command = command.slice(0, firstNonNull).toString("ascii");
         var payloadLength = buf.readUInt32BE(16, true);
    +    assert(payloadLength <= 1600003, "Message payload is too big");
         var length = 24 + payloadLength;
         assert(buf.length >= length, "Truncated payload");
         var checksum = buf.slice(20, 24);
    @@ -106,7 +274,7 @@ var message = exports.message = {
       },
     
       /**
    -   * Encode message structure.
    +   * Encode message.
        * @param {string} command - Message command
        * @param {Bufer} payload - Message payload
        * @return {Buffer} Encoded message structure.
    @@ -114,6 +282,8 @@ var message = exports.message = {
       encode: function(command, payload) {
         assert(command.length <= 12, "Command is too long");
         assert(isAscii(command), "Non-ASCII characters in command");
    +    payload = payload || new Buffer(0);
    +    assert(payload.length <= 1600003, "Message payload is too big");
         var buf = new Buffer(24 + payload.length);
         buf.fill(0);
         buf.writeUInt32BE(message.MAGIC, 0, true);
    @@ -134,18 +304,48 @@ var message = exports.message = {
      * @static
      */
     var object = exports.object = {
    -  // Known types.
    +  /**
    +   * [getpubkey]{@link module:bitmessage/objects.getpubkey} object type.
    +   * @constant {number}
    +   */
       GETPUBKEY: 0,
    +  /**
    +   * [pubkey]{@link module:bitmessage/objects.pubkey} object type.
    +   * @constant {number}
    +   */
       PUBKEY: 1,
    +  /**
    +   * [msg]{@link module:bitmessage/objects.msg} object type.
    +   * @constant {number}
    +   */
       MSG: 2,
    +  /**
    +   * [broadcast]{@link module:bitmessage/objects.broadcast} object type.
    +   * @constant {number}
    +   */
       BROADCAST: 3,
     
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {Buffer} nonce - A 8-byte object nonce
    +   * @property {number} ttl - Time to live in seconds
    +   * @property {number} type - Object type
    +   * @property {number} version - Object version
    +   * @property {number} stream - Object stream
    +   * @property {number} headerLength - Length of the object header
    +   * @property {Buffer} objectPayload - Object payload
    +   * @memberof module:bitmessage/structs.object
    +   */
    +
       /**
        * Decode `object` message.  
        * NOTE: `nonce` and `objectPayload` are copied.
        * @param {Buffer} buf - Message
    -   * @param {?Object} opts - Decoding options
    -   * @return {Object} Decoded `object` structure.
    +   * @param {Object=} opts - Decoding options
    +   * @param {boolean} opts.allowExpired - Allow expired objects
    +   * @param {boolean} opts.skipPow - Do not validate object POW
    +   * @return {DecodeResult}
    +   * [Decoded `object` structure.]{@link module:bitmessage/structs.object.DecodeResult}
        */
       decode: function(buf, opts) {
         var decoded = message.decode(buf);
    @@ -154,11 +354,8 @@ var object = exports.object = {
       },
     
       /**
    -   * Decode `object` message payload.  
    -   * NOTE: `nonce` and `objectPayload` are copied.
    -   * @param {Buffer} buf - Message payload
    -   * @param {?Object} opts - Decoding options
    -   * @return {Object} Decoded `object` structure.
    +   * Decode `object` message payload.
    +   * The same as [decode]{@link module:bitmessage/structs.object.decode}.
        */
       decodePayload: function(buf, opts) {
         opts = opts || {};
    @@ -206,6 +403,12 @@ var object = exports.object = {
       /**
        * Encode `object` message.
        * @param {Object} opts - Object options
    +   * @param {Object} opts.nonce - A 8-byte object nonce
    +   * @param {number} opts.ttl - Time to live in seconds
    +   * @param {number} opts.type - Object type
    +   * @param {number} opts.version - Object version
    +   * @param {number=} opts.stream - Object stream (1 by default)
    +   * @param {Buffer} opts.objectPayload - Object payload
        * @return {Buffer} Encoded message.
        */
       encode: function(opts) {
    @@ -215,8 +418,7 @@ var object = exports.object = {
     
       /**
        * Encode `object` message payload.
    -   * @param {Object} opts - Object options
    -   * @return {Buffer} Encoded payload.
    +   * The same as [encode]{@link module:bitmessage/structs.object.encode}.
        */
       encodePayload: function(opts) {
         // NOTE(Kagami): We do not try to calculate nonce here if it is not
    @@ -240,6 +442,11 @@ var object = exports.object = {
        * Encode `object` message payload without leading nonce field (may be
        * useful if you are going to calculate it later).
        * @param {Object} opts - Object options
    +   * @param {number} opts.ttl - Time to live in seconds
    +   * @param {number} opts.type - Object type
    +   * @param {number} opts.version - Object version
    +   * @param {number=} opts.stream - Object stream (1 by default)
    +   * @param {Buffer} opts.objectPayload - Object payload
        * @return {Buffer} Encoded payload.
        */
       encodePayloadWithoutNonce: function(opts) {
    @@ -268,12 +475,20 @@ var object = exports.object = {
      * @static
      */
     var var_int = exports.var_int = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {number} value - Stored value
    +   * @property {number} length - `var_int` full length
    +   * @property {Buffer} rest - The rest of the input buffer
    +   * @memberof module:bitmessage/structs.var_int
    +   */
    +
       /**
        * Decode `var_int`.  
        * NOTE: `rest` references input buffer.
        * @param {Buffer} buf - A buffer that starts with encoded `var_int`
    -   * @return {{value: number, length: number, rest: Buffer}}
    -   * Decoded `var_int` structure.
    +   * @return {DecodeResult}
    +   * [Decoded `var_int` structure.]{@link module:bitmessage/structs.var_int.DecodeResult}
        */
       decode: function(buf) {
         var value, length;
    @@ -361,12 +576,20 @@ var var_int = exports.var_int = {
      * @namespace
      */
     exports.var_str = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {number} str - The string itself
    +   * @property {number} length - `var_str` full length
    +   * @property {Buffer} rest - The rest of the input buffer
    +   * @memberof module:bitmessage/structs.var_str
    +   */
    +
       /**
        * Decode `var_str`.  
        * NOTE: `rest` references input buffer.
        * @param {Buffer} buf - A buffer that starts with encoded `var_str`
    -   * @return {{str: string, length: number, rest: Buffer}}
    -   * Decoded `var_str` structure.
    +   * @return {DecodeResult}
    +   * [Decoded `var_str` structure.]{@link module:bitmessage/structs.var_str.DecodeResult}
        */
       decode: function(buf) {
         var decoded = var_int.decode(buf);
    @@ -397,13 +620,21 @@ exports.var_str = {
      * @namespace
      */
     exports.var_int_list = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {number} list - Stored numbers
    +   * @property {number} length - `var_int_list` full length
    +   * @property {Buffer} rest - The rest of the input buffer
    +   * @memberof module:bitmessage/structs.var_int_list
    +   */
    +
       /**
        * Decode `var_int_list`.  
        * NOTE: `rest` references input buffer.
        * @param {Buffer} buf - A buffer that starts with encoded
        * `var_int_list`
    -   * @return {{list: number[], length: number, rest: Buffer}}
    -   * Decoded `var_int_list` structure.
    +   * @return {DecodeResult}
    +   * [Decoded `var_int_list` structure.]{@link module:bitmessage/structs.var_int_list.DecodeResult}
        */
       decode: function(buf) {
         var decoded = var_int.decode(buf);
    @@ -426,8 +657,9 @@ exports.var_int_list = {
        * @return {Buffer} Encoded `var_int_list`.
        */
       encode: function(list) {
    -    var listBuf = Buffer.concat(list.map(var_int.encode));
    -    return Buffer.concat([var_int.encode(list.length), listBuf]);
    +    var var_ints = list.map(var_int.encode);
    +    var bufs = [var_int.encode(list.length)].concat(var_ints);
    +    return Buffer.concat(bufs);
       },
     };
     
    @@ -454,10 +686,17 @@ function inet_ntop(buf) {
     function inet_pton(str) {
       var buf = new Buffer(16);
       buf.fill(0);
    +  // IPv4-mapped IPv6.
    +  if (str.slice(0, 7) === "::ffff:") {
    +    str = str.slice(7);
    +  }
       // IPv4.
       if (str.indexOf(":") === -1) {
         IPv4_MAPPING.copy(buf);
    -    var octets = str.split(/\./g).map(function(s) {return parseInt(s, 10);});
    +    var octets = str.split(/\./g).map(function(o) {
    +      assert(/^\d+$/.test(o), "Bad octet");
    +      return parseInt(o, 10);
    +    });
         // Support short form from inet_aton(3) man page.
         if (octets.length === 1) {
           buf.writeUInt32BE(octets[0], 12);
    @@ -512,6 +751,8 @@ function inet_pton(str) {
           assert(groups.length === 8, "Bad IPv6 address");
         }
         for (i = 0; i < Math.min(groups.length, 8); i++) {
    +      // Check against parseInt("127.0.0.1", 16) -> 295
    +      assert(/^[0-9a-f]+$/.test(groups[i]), "Bad group");
           buf.writeUInt16BE(parseInt(groups[i], 16), i * 2);
         }
       }
    @@ -524,13 +765,28 @@ function inet_pton(str) {
      * @namespace
      */
     exports.net_addr = {
    +  /**
    +   * @typedef {Object} DecodeResult
    +   * @property {Date} time - Time the node was last active, not included
    +   * in short mode
    +   * @property {number} stream - Stream number of the node, not included
    +   * in short mode
    +   * @property {Object} services -
    +   * [Services]{@link module:bitmessage/structs.ServicesBitfield}
    +   * provided by the node
    +   * @property {string} host - IPv4/IPv6 address of the node
    +   * @property {number} port - Incoming port of the node
    +   * @memberof module:bitmessage/structs.net_addr
    +   */
    +
       /**
        * Decode `net_addr`.
        * @param {Buffer} buf - A buffer that contains encoded `net_addr`
    -   * @param {?Object} opts - Decoding options; use `short` option to
    +   * @param {Object=} opts - Decoding options; use `short` option to
        * decode `net_addr` from
        * [version message]{@link module:bitmessage/messages.version}
    -   * @return {Object} Decoded `net_addr` structure.
    +   * @return {DecodeResult}
    +   * [Decoded `net_addr` structure.]{@link module:bitmessage/structs.net_addr.DecodeResult}
        */
       decode: function(buf, opts) {
         var short = !!(opts || {}).short;
    @@ -558,9 +814,19 @@ exports.net_addr = {
     
       /**
        * Encode `net_addr`.
    -   * @param {Object} opts - Encode options; use `short` option to encode
    -   * `net_addr` for
    +   * @param {Object} opts - Encoding options
    +   * @param {boolean=} opts.short - Encode `net_addr` for
        * [version message]{@link module:bitmessage/messages.version}
    +   * (false by default)
    +   * @param {Date=} opts.time - Time the node was last active, not
    +   * included in short mode (current time by default)
    +   * @param {number=} opts.stream - Stream number of the node, not
    +   * included in short mode (1 by default)
    +   * @param {Object=} opts.services -
    +   * [Services]{@link module:bitmessage/structs.ServicesBitfield}
    +   * provided by the node (`NODE_NETWORK` by default)
    +   * @param {string} opts.host - IPv4/IPv6 address of the node
    +   * @param {number} opts.port - Incoming port of the node
        * @return {Buffer} Encoded `net_addr`.
        */
       encode: function(opts) {
    @@ -595,12 +861,14 @@ exports.net_addr = {
      * @see {@link https://bitmessage.org/wiki/Protocol_specification#Inventory_Vectors}
      * @namespace
      */
    -// Only encode operation is defined because decode is impossible.
     exports.inv_vect = {
    +  // NOTE(Kagami): Only encode operation is defined because decoding of
    +  // the encoded vector is impossible.
    +
       /**
        * Encode inventory vector.
        * @param {Buffer} buf - Payload to calculate the inventory vector for
    -   * @return {Buffer} Encoded `inv_vect`.
    +   * @return {Buffer} A 32-byte encoded `inv_vect`.
        */
       encode: function(buf) {
         return bmcrypto.sha512(bmcrypto.sha512(buf)).slice(0, 32);
    @@ -613,18 +881,34 @@ exports.inv_vect = {
      * @namespace encrypted
      * @static
      */
    +/**
    + * @typedef {Object} DecodeResult
    + * @property {Buffer} iv - Initialization vector (16 bytes)
    + * @property {Buffer} ephemPrivateKey - Ephemeral private key (32 bytes)
    + * @property {Buffer} ciphertext - The result of encryption (variable
    + * size)
    + * @property {Buffer} mac - Message authentication code (32 bytes)
    + * @memberof module:bitmessage/structs.encrypted
    + */
     /**
      * Decode encrypted payload.  
      * NOTE: all structure members are copied.
      * @param {Buffer} buf - A buffer that contains encrypted payload
    - * @return {Object} Decoded encrypted structure.
    + * @return {DecodeResult}
    + * [Decoded `encrypted` structure.]{@link module:bitmessage/structs.encrypted.DecodeResult}
      * @function decode
      * @memberof module:bitmessage/structs.encrypted
      */
     /**
      * Encode `encrypted`.
    - * @param {Object} opts - Encode options
    - * @return {Buffer} Encoded encrypted payload.
    + * @param {Object} opts - Encoding options
    + * @param {Buffer} opts.iv - Initialization vector (16 bytes)
    + * @param {Buffer} opts.ephemPrivateKey - Ephemeral private key (32
    + * bytes)
    + * @param {Buffer} opts.ciphertext - The result of encryption (variable
    + * size)
    + * @param {Buffer} opts.mac - Message authentication code (32 bytes)
    + * @return {Buffer} Encoded `encrypted` payload.
      * @function encode
      * @memberof module:bitmessage/structs.encrypted
      */
    @@ -689,18 +973,49 @@ var Bitfield = function(size) {
     };
     
     /**
    - * Services bitfield features.
    + * Service features bitfield (MSB 0).
      * @see {@link https://bitmessage.org/wiki/Protocol_specification#version}
    - * @namespace
    + * @param {Buffer=} buf - A 8-byte bitfield buffer (will be created if
    + * not provided or will be copied if `opts.copy` is `true`)
    + * @param {Object=} opts - Options
    + * @constructor
      * @static
    + * @example
    + * var ServicesBitfield = require("bitmessage").structs.ServicesBitfield;
    + * var services = ServicesBitfield().set(ServicesBitfield.NODE_NETWORK);
    + * console.log(services.get(ServicesBitfield.NODE_NETWORK));  // true
    + * console.log(services.get(15));  // false
      */
    -// TODO(Kagami): Document methods.
     // NOTE(Kagami): Since pubkey bitfield uses MSB 0, we use it here too.
     // See <https://github.com/Bitmessage/PyBitmessage/issues/769> for
     // details.
     var ServicesBitfield = exports.ServicesBitfield = objectAssign(Bitfield(64), {
       /**
    -   * This is a normal network node.
    +   * Returns a boolean indicating whether the bit is set.
    +   * @param {number} index - Bit index (MSB 0)
    +   * @function get
    +   * @instance
    +   * @return {boolean}
    +   * @memberof module:bitmessage/structs.ServicesBitfield
    +   */
    +  /**
    +   * Set the given bit(s) to `1`.
    +   * @param {(number|number[])} index - Bit(s) index (MSB 0)
    +   * @function set
    +   * @instance
    +   * @return {Object} Returns self so methods can be chained.
    +   * @memberof module:bitmessage/structs.ServicesBitfield
    +   */
    +  /**
    +   * The contents of the bitfield.
    +   * @type {Buffer}
    +   * @var buffer
    +   * @instance
    +   * @memberof module:bitmessage/structs.ServicesBitfield
    +   */
    +
    +  /**
    +   * Bit index indicating normal network node.
        * @memberof module:bitmessage/structs.ServicesBitfield
        * @constant {number}
        */
    @@ -708,22 +1023,58 @@ var ServicesBitfield = exports.ServicesBitfield = objectAssign(Bitfield(64), {
     });
     
     /**
    - * Pubkey bitfield features.
    + * Pubkey features bitfield (MSB 0).
      * @see {@link https://bitmessage.org/wiki/Protocol_specification#Pubkey_bitfield_features}
    - * @namespace
    + * @param {Buffer=} buf - A 4-byte bitfield buffer (will be created if
    + * not provided or will be copied if `opts.copy` is `true`)
    + * @param {Object=} opts - Options
    + * @constructor
    + * @example
    + * var PubkeyBitfield = require("bitmessage").structs.PubkeyBitfield;
    + * var behavior = PubkeyBitfield().set([
    + *   PubkeyBitfield.INCLUDE_DESTINATION,
    + *   PubkeyBitfield.DOES_ACK,
    + * ]).set(1);
    + * console.log(behavior.get(PubkeyBitfield.DOES_ACK));  // true
    + * console.log(behavior.get(15));  // false
      */
    -// TODO(Kagami): Document methods.
     exports.PubkeyBitfield = objectAssign(Bitfield(32), {
       /**
    -   * Receiving node expects that the RIPE hash encoded in their address
    -   * preceedes the encrypted message data of msg messages bound for
    -   * them.
    +   * Returns a boolean indicating whether the bit is set.
    +   * @param {number} index - Bit index (MSB 0)
    +   * @function get
    +   * @instance
    +   * @return {boolean}
    +   * @memberof module:bitmessage/structs.PubkeyBitfield
    +   */
    +  /**
    +   * Set the given bit(s) to `1`.
    +   * @param {(number|number[])} index - Bit(s) index (MSB 0)
    +   * @function set
    +   * @instance
    +   * @return {Object} Returns self so methods can be chained.
    +   * @memberof module:bitmessage/structs.PubkeyBitfield
    +   */
    +  /**
    +   * The contents of the bitfield.
    +   * @type {Buffer}
    +   * @var buffer
    +   * @instance
    +   * @memberof module:bitmessage/structs.PubkeyBitfield
    +   */
    +
    +  /**
    +   * Bit index.
    +   * If set, the receiving node expects that the RIPEMD hash encoded in
    +   * their address preceedes the encrypted message data of msg messages
    +   * bound for them.
        * @memberof module:bitmessage/structs.PubkeyBitfield
        * @constant {number}
        */
       INCLUDE_DESTINATION: 30,
       /**
    -   * If true, the receiving node does send acknowledgements (rather than
    +   * Bit index.
    +   * If set, the receiving node does send acknowledgements (rather than
        * dropping them).
        * @memberof module:bitmessage/structs.PubkeyBitfield
        * @constant {number}
    @@ -740,13 +1091,13 @@ exports.PubkeyBitfield = objectAssign(Bitfield(32), {
     
     
     
     
     
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/styles/jsdoc-default.css b/docs/styles/jsdoc-default.css index 0067cb1..24aa20f 100644 --- a/docs/styles/jsdoc-default.css +++ b/docs/styles/jsdoc-default.css @@ -334,13 +334,15 @@ h6 .params th, .props th { border-right: 1px solid #aaa; } .params thead .last, .props thead .last { border-right: 1px solid #ddd; } -.params td.description > p:first-child +.params td.description > p:first-child, +.props td.description > p:first-child { margin-top: 0; padding-top: 0; } -.params td.description > p:last-child +.params td.description > p:last-child, +.props td.description > p:last-child { margin-bottom: 0; padding-bottom: 0; diff --git a/docs/user-agent.js.html b/docs/user-agent.js.html index 738e026..8643dbe 100644 --- a/docs/user-agent.js.html +++ b/docs/user-agent.js.html @@ -90,8 +90,8 @@ exports.parse = function(str) { /** * Encode user agent into `var_str` Buffer. Most underlying software * comes first. - * @param {(Object[]|string[]|string)} software - List of software to - * encode or just raw user agent string + * @param {(Object[]|string[]|string|Buffer)} software - List of + * software to encode or just raw user agent string/Buffer * @return {Buffer} Encoded user agent. * @function * @static @@ -111,6 +111,8 @@ var encode = exports.encode = function(software) { return str; }).join("/"); ua = "/" + ua + "/"; + } else if (Buffer.isBuffer(software)) { + return software; } else { ua = software; } @@ -118,7 +120,7 @@ var encode = exports.encode = function(software) { }; /** - * Encode bitmessage's user agent. + * Encode bitmessage's library user agent. * @return {Buffer} Encoded user agent. */ exports.encodeSelf = function() { @@ -126,8 +128,8 @@ exports.encodeSelf = function() { }; /** - * Encode user agent with bitmessage's user agent underneath. Most - * underlying software comes first. + * Encode user agent with bitmessage's library user agent underneath. + * Most underlying software comes first. * @param {(Object[]|string[]|Object|string)} software - List of * software to encode * @return {Buffer} Encoded user agent. @@ -146,13 +148,13 @@ exports.encodeSelfWith = function(software) {
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)
    diff --git a/docs/wif.js.html b/docs/wif.js.html index 5fb37f1..29ab941 100644 --- a/docs/wif.js.html +++ b/docs/wif.js.html @@ -45,7 +45,8 @@ function getwifchecksum(data) { } /** - * Decode WIF encoded private key. + * Decode WIF-encoded private key (corresponded to a uncompressed public + * key). * @param {string} wif - Encoded key * @return {Buffer} Private key. */ @@ -59,9 +60,10 @@ exports.decode = function(wif) { }; /** - * Convert private key to a WIF. + * Convert private key to a WIF (corresponded to a uncompressed public + * key). * @param {Buffer} privateKey - A private key to encode - * @return {string} Encoded private key. + * @return {string} WIF-encoded private key. */ exports.encode = function(privateKey) { var data = Buffer.concat([new Buffer([0x80]), privateKey]); @@ -79,13 +81,13 @@ exports.encode = function(privateKey) {
    - Documentation generated by JSDoc 3.3.0-beta1 on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK) + Documentation generated by JSDoc 3.4.0-dev on Thu Feb 12 2015 13:43:38 GMT+0300 (MSK)