2014-12-17 12:08:42 +01:00
# bitmessage [![Build Status](https://travis-ci.org/bitchan/bitmessage.svg?branch=master)](https://travis-ci.org/bitchan/bitmessage)
2014-12-11 18:57:42 +01:00
2015-02-28 21:02:04 +01:00
[![NPM ](https://nodei.co/npm/bitmessage.png?downloads=true )](https://www.npmjs.com/package/bitmessage)
2015-01-21 01:19:35 +01:00
2014-12-28 18:08:41 +01:00
JavaScript Bitmessage library for both browserify and node. The goal of this project is to implement Bitmessage protocol v3 for both platforms at the maximum possible level (we still can't create TCP connections or listen for incoming connections in the Browser but the Proof of work and crypto is fully doable).
Public library API is currently in alpha stage, breaking changes are very likely to happen.
2014-12-28 17:59:57 +01:00
2014-12-30 19:30:12 +01:00
API documentation is available [here ](https://bitchan.github.io/bitmessage/docs/ ).
2014-12-30 18:00:28 +01:00
2014-12-28 17:59:57 +01:00
## References
2015-01-03 17:49:20 +01:00
* [Bitmessage wiki ](https://bitmessage.org/wiki/Main_Page )
2023-01-09 04:25:31 +01:00
* [Protocol specification ](https://pybitmessage.rtfd.io/en/v0.6/protocol.html )
2014-12-28 17:59:57 +01:00
* [Whitepaper ](https://bitmessage.org/bitmessage.pdf )
2015-02-06 18:48:49 +01:00
## Feature matrix
2014-12-28 17:59:57 +01:00
2015-01-15 22:00:27 +01:00
- [x] Crypto
2015-01-16 16:35:40 +01:00
- [x] SHA-1
2014-12-28 17:59:57 +01:00
- [x] SHA-256
2015-01-16 16:35:40 +01:00
- [x] SHA-512
2014-12-28 17:59:57 +01:00
- [x] RIPEMD-160
- [x] PRNG
2015-02-11 21:05:38 +01:00
- [x] ECC keys handling
2014-12-28 17:59:57 +01:00
- [x] ECDSA
2015-01-14 00:36:07 +01:00
- [x] ECIES
2015-01-11 14:59:43 +01:00
- [x] Common structures
2015-01-04 21:59:14 +01:00
- [x] message
2015-01-22 01:00:58 +01:00
- [x] object
2014-12-28 17:59:57 +01:00
- [x] var_int
2015-01-02 15:27:03 +01:00
- [x] var_str
- [x] var_int_list
2015-01-06 00:32:10 +01:00
- [x] net_addr
2015-01-15 22:00:27 +01:00
- [x] inv_vect
2015-01-11 14:59:43 +01:00
- [x] encrypted
2015-01-05 00:40:52 +01:00
- [x] service features
- [x] pubkey features
2015-01-16 01:08:56 +01:00
- [x] Message types
2015-01-15 18:13:02 +01:00
- [x] version
2015-01-15 19:11:33 +01:00
- [x] addr
2015-01-15 22:00:27 +01:00
- [x] inv
2015-01-15 22:07:49 +01:00
- [x] getdata
2015-01-16 01:08:56 +01:00
- [x] error
2015-01-29 19:18:07 +01:00
- [x] Object types
2015-01-18 12:37:09 +01:00
- [x] getpubkey
2015-01-22 01:00:58 +01:00
- [x] pubkey
2015-01-28 21:37:20 +01:00
- [x] msg
2015-01-29 19:18:07 +01:00
- [x] broadcast
2024-03-21 16:58:49 +01:00
- [ ] ACK data generation
2015-01-02 22:24:36 +01:00
- [x] WIF
2015-01-09 22:36:42 +01:00
- [x] POW
2015-01-18 13:34:02 +01:00
- [x] High-level classes
- [x] Address
2023-01-09 04:25:31 +01:00
- [ ] UserAgent
2015-02-11 21:05:38 +01:00
- [ ] PyBitmessage configs parsing
2015-01-02 22:56:54 +01:00
- [ ] keys.dat
- [ ] knownnodes.dat
- [ ] messages.dat
2014-12-28 17:59:57 +01:00
2014-12-13 19:59:48 +01:00
## Usage
2015-01-19 13:08:56 +01:00
### Address
2014-12-13 19:59:48 +01:00
```js
2014-12-28 17:59:57 +01:00
var Address = require("bitmessage").Address;
2015-01-19 13:08:56 +01:00
// 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());
2014-12-13 19:59:48 +01:00
```
2015-02-12 11:36:44 +01:00
### Structures
```js
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
```js
var structs = require("bitmessage").structs;
var messages = require("bitmessage").messages;
// Simple encoding and decoding:
var vermsg = messages.version.encode({
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
2015-02-24 19:21:42 +01:00
var addr = messages.addr.decodePayload(decoded.payload);
console.log(addr.addrs[0].host); // 2.2.2.2
2015-02-12 11:36:44 +01:00
// Encode with empty payload:
var verackmsg = structs.message.encode("verack");
console.log(structs.message.decode(verackmsg).command); // verack
```
2015-02-14 11:53:24 +01:00
### Networking
2015-02-12 11:36:44 +01:00
2015-02-25 11:28:58 +01:00
You will need to install [bitmessage-transports ](https://github.com/bitchan/bitmessage-transports ) library.
2015-02-12 11:36:44 +01:00
```js
var messages = require("bitmessage").messages;
2015-02-25 11:28:58 +01:00
var TcpTransport = require("bitmessage-transports").TcpTransport;
2015-02-12 11:36:44 +01:00
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);
});
2015-02-24 18:27:41 +01:00
tcp.on("established", function(version) {
console.log("Connection established to", version.userAgent);
2015-02-12 11:36:44 +01:00
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");
}
});
});
```
2014-12-11 18:57:42 +01:00
## License
bitmessage - JavaScript Bitmessage library
2015-02-07 12:14:53 +01:00
Written in 2014-2015 by Kagami Hiiragi < kagami @ genshiken . org >
2014-12-11 18:57:42 +01:00
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 < http: / / creativecommons . org / publicdomain / zero / 1 . 0 / > .