@leofcoin/peernet 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser/peernet.js
CHANGED
|
@@ -261,7 +261,7 @@ class LeofcoinStorage$1 {
|
|
|
261
261
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
var version = "0.
|
|
264
|
+
var version = "0.9.0";
|
|
265
265
|
|
|
266
266
|
var api$1 = {
|
|
267
267
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -1002,8 +1002,8 @@ var codecs = {
|
|
|
1002
1002
|
// chat message
|
|
1003
1003
|
'chat-message': {
|
|
1004
1004
|
codec: '636d',
|
|
1005
|
-
hashAlg: 'dbl-keccak-512'
|
|
1006
|
-
}
|
|
1005
|
+
hashAlg: 'dbl-keccak-512',
|
|
1006
|
+
},
|
|
1007
1007
|
};
|
|
1008
1008
|
|
|
1009
1009
|
class PeernetCodec {
|
|
@@ -1576,6 +1576,17 @@ class DataMessageResponse extends FormatInterface {
|
|
|
1576
1576
|
}
|
|
1577
1577
|
}
|
|
1578
1578
|
|
|
1579
|
+
class ChatMessage extends FormatInterface {
|
|
1580
|
+
get keys() {
|
|
1581
|
+
return ['author', 'value', 'timestamp', 'files']
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
constructor(buffer) {
|
|
1585
|
+
const name = 'chat-message';
|
|
1586
|
+
super(buffer, protons__default['default'](proto$9).ChatMessage, {name});
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1579
1590
|
const debug = (log) => {
|
|
1580
1591
|
if (globalThis.DEBUG || globalThis.debug) console.log(`%c ${log}`, 'color: #0080ff;');
|
|
1581
1592
|
};
|
|
@@ -1977,7 +1988,7 @@ class Peernet {
|
|
|
1977
1988
|
}
|
|
1978
1989
|
|
|
1979
1990
|
get defaultStores() {
|
|
1980
|
-
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data']
|
|
1991
|
+
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
1981
1992
|
}
|
|
1982
1993
|
|
|
1983
1994
|
addProto(name, proto) {
|
|
@@ -1990,7 +2001,7 @@ class Peernet {
|
|
|
1990
2001
|
|
|
1991
2002
|
async addStore(name, prefix, root, isPrivate = true) {
|
|
1992
2003
|
if (name === 'block' || name === 'transaction' || name === 'chain' ||
|
|
1993
|
-
name === 'data') isPrivate = false;
|
|
2004
|
+
name === 'data' || name === 'message') isPrivate = false;
|
|
1994
2005
|
|
|
1995
2006
|
let Storage;
|
|
1996
2007
|
if (this.hasDaemon) {
|
|
@@ -2066,6 +2077,7 @@ class Peernet {
|
|
|
2066
2077
|
'peernet-data': DataMessage,
|
|
2067
2078
|
'peernet-data-response': DataMessageResponse,
|
|
2068
2079
|
'peernet-ps': PsMessage,
|
|
2080
|
+
'chat-message': ChatMessage
|
|
2069
2081
|
};
|
|
2070
2082
|
this.protos = globalThis.peernet.protos;
|
|
2071
2083
|
|
|
@@ -2418,6 +2430,36 @@ class Peernet {
|
|
|
2418
2430
|
return null
|
|
2419
2431
|
}
|
|
2420
2432
|
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
get message() {
|
|
2436
|
+
return {
|
|
2437
|
+
/**
|
|
2438
|
+
* Get content for given message hash
|
|
2439
|
+
*
|
|
2440
|
+
* @param {String} hash
|
|
2441
|
+
*/
|
|
2442
|
+
get: async (hash) => {
|
|
2443
|
+
debug(`get message ${hash}`);
|
|
2444
|
+
const message = await messageStore.has(hash);
|
|
2445
|
+
if (message) return await messageStore.get(hash)
|
|
2446
|
+
return this.requestData(hash, 'message')
|
|
2447
|
+
},
|
|
2448
|
+
/**
|
|
2449
|
+
* put message content
|
|
2450
|
+
*
|
|
2451
|
+
* @param {String} hash
|
|
2452
|
+
* @param {Buffer} message
|
|
2453
|
+
*/
|
|
2454
|
+
put: async (hash, message) => await messageStore.put(hash, message),
|
|
2455
|
+
/**
|
|
2456
|
+
* @param {String} hash
|
|
2457
|
+
* @return {Boolean}
|
|
2458
|
+
*/
|
|
2459
|
+
has: async (hash) => await messageStore.has(hash),
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2421
2463
|
get data() {
|
|
2422
2464
|
return {
|
|
2423
2465
|
/**
|
|
@@ -2508,16 +2550,16 @@ class Peernet {
|
|
|
2508
2550
|
*/
|
|
2509
2551
|
async publish(topic, data) {
|
|
2510
2552
|
// globalSub.publish(topic, data)
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
2553
|
if (!Buffer.isBuffer(topic)) topic = Buffer.from(topic);
|
|
2514
2554
|
if (!Buffer.isBuffer(data)) data = Buffer.from(data);
|
|
2515
2555
|
const id = Math.random().toString(36).slice(-12);
|
|
2516
2556
|
data = new PsMessage({data, topic});
|
|
2517
2557
|
for (const peer of this.peers) {
|
|
2518
|
-
if (peer.connection._connected
|
|
2519
|
-
|
|
2520
|
-
|
|
2558
|
+
if (peer.connection._connected) {
|
|
2559
|
+
if (peer.id.toString() !== this.peerId.toString()) {
|
|
2560
|
+
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2561
|
+
peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
|
|
2562
|
+
}
|
|
2521
2563
|
} else {
|
|
2522
2564
|
this.removePeer(peer);
|
|
2523
2565
|
}
|
package/dist/commonjs/codec.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var protons = require('protons');
|
|
4
|
+
var codecFormatInterface = require('./codec-format-interface.js');
|
|
5
|
+
|
|
6
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var protons__default = /*#__PURE__*/_interopDefaultLegacy(protons);
|
|
9
|
+
|
|
10
|
+
var proto = `
|
|
11
|
+
// PeernetMessage
|
|
12
|
+
message PeernetMessage {
|
|
13
|
+
required bytes data = 1;
|
|
14
|
+
required bytes signature = 2;
|
|
15
|
+
optional bytes from = 3;
|
|
16
|
+
optional bytes to = 4;
|
|
17
|
+
optional string id = 5;
|
|
18
|
+
}`;
|
|
19
|
+
|
|
20
|
+
class PeernetMessage extends codecFormatInterface {
|
|
21
|
+
get keys() {
|
|
22
|
+
return ['data', 'signature', 'from', 'to', 'id']
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
constructor(buffer) {
|
|
26
|
+
const name = 'peernet-message';
|
|
27
|
+
super(buffer, protons__default['default'](proto).PeernetMessage, {name});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.PeernetMessage = PeernetMessage;
|
|
32
|
+
exports.proto = proto;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var
|
|
3
|
+
require('protons');
|
|
4
|
+
var peernetMessage = require('./peernet-message-b6925673.js');
|
|
5
|
+
require('./codec-format-interface.js');
|
|
5
6
|
require('bs32');
|
|
6
7
|
require('bs58');
|
|
7
8
|
require('is-hex');
|
|
@@ -10,29 +11,6 @@ require('varint');
|
|
|
10
11
|
require('./hash.js');
|
|
11
12
|
require('keccak');
|
|
12
13
|
|
|
13
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
14
|
|
|
15
|
-
var protons__default = /*#__PURE__*/_interopDefaultLegacy(protons);
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
// PeernetMessage
|
|
19
|
-
message PeernetMessage {
|
|
20
|
-
required bytes data = 1;
|
|
21
|
-
required bytes signature = 2;
|
|
22
|
-
optional bytes from = 3;
|
|
23
|
-
optional bytes to = 4;
|
|
24
|
-
optional string id = 5;
|
|
25
|
-
}`;
|
|
26
|
-
|
|
27
|
-
class PeernetMessage extends codecFormatInterface {
|
|
28
|
-
get keys() {
|
|
29
|
-
return ['data', 'signature', 'from', 'to', 'id']
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
constructor(buffer) {
|
|
33
|
-
const name = 'peernet-message';
|
|
34
|
-
super(buffer, protons__default['default'](proto).PeernetMessage, {name});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = PeernetMessage;
|
|
16
|
+
module.exports = peernetMessage.PeernetMessage;
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -6,7 +6,7 @@ var P2P = require('p2pt');
|
|
|
6
6
|
var websocket = require('websocket');
|
|
7
7
|
var http$1 = require('http');
|
|
8
8
|
var Koa = require('koa');
|
|
9
|
-
var peernetMessage = require('./peernet-message.js');
|
|
9
|
+
var peernetMessage = require('./peernet-message-b6925673.js');
|
|
10
10
|
var dht = require('./dht.js');
|
|
11
11
|
var dhtResponse = require('./dht-response.js');
|
|
12
12
|
var protons = require('protons');
|
|
@@ -264,7 +264,7 @@ class LeofcoinStorage$1 {
|
|
|
264
264
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
var version = "0.
|
|
267
|
+
var version = "0.9.0";
|
|
268
268
|
|
|
269
269
|
var api$1 = {
|
|
270
270
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -1011,6 +1011,17 @@ class DataMessageResponse extends codecFormatInterface {
|
|
|
1011
1011
|
}
|
|
1012
1012
|
}
|
|
1013
1013
|
|
|
1014
|
+
class ChatMessage extends codecFormatInterface {
|
|
1015
|
+
get keys() {
|
|
1016
|
+
return ['author', 'value', 'timestamp', 'files']
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
constructor(buffer) {
|
|
1020
|
+
const name = 'chat-message';
|
|
1021
|
+
super(buffer, protons__default['default'](peernetMessage.proto).ChatMessage, {name});
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1014
1025
|
const debug = (log) => {
|
|
1015
1026
|
if (globalThis.DEBUG || globalThis.debug) console.log(`%c ${log}`, 'color: #0080ff;');
|
|
1016
1027
|
};
|
|
@@ -1350,7 +1361,7 @@ class MessageHandler {
|
|
|
1350
1361
|
data,
|
|
1351
1362
|
};
|
|
1352
1363
|
const signature = await this.hashAndSignMessage(message);
|
|
1353
|
-
const node = new peernetMessage({
|
|
1364
|
+
const node = new peernetMessage.PeernetMessage({
|
|
1354
1365
|
...message,
|
|
1355
1366
|
signature,
|
|
1356
1367
|
});
|
|
@@ -1412,7 +1423,7 @@ class Peernet {
|
|
|
1412
1423
|
}
|
|
1413
1424
|
|
|
1414
1425
|
get defaultStores() {
|
|
1415
|
-
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data']
|
|
1426
|
+
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
1416
1427
|
}
|
|
1417
1428
|
|
|
1418
1429
|
addProto(name, proto) {
|
|
@@ -1425,7 +1436,7 @@ class Peernet {
|
|
|
1425
1436
|
|
|
1426
1437
|
async addStore(name, prefix, root, isPrivate = true) {
|
|
1427
1438
|
if (name === 'block' || name === 'transaction' || name === 'chain' ||
|
|
1428
|
-
name === 'data') isPrivate = false;
|
|
1439
|
+
name === 'data' || name === 'message') isPrivate = false;
|
|
1429
1440
|
|
|
1430
1441
|
let Storage;
|
|
1431
1442
|
if (this.hasDaemon) {
|
|
@@ -1495,12 +1506,13 @@ class Peernet {
|
|
|
1495
1506
|
'peernet-response': response,
|
|
1496
1507
|
'peernet-peer': PeerMessage,
|
|
1497
1508
|
'peernet-peer-response': PeerMessageResponse,
|
|
1498
|
-
'peernet-message': peernetMessage,
|
|
1509
|
+
'peernet-message': peernetMessage.PeernetMessage,
|
|
1499
1510
|
'peernet-dht': dht,
|
|
1500
1511
|
'peernet-dht-response': dhtResponse,
|
|
1501
1512
|
'peernet-data': DataMessage,
|
|
1502
1513
|
'peernet-data-response': DataMessageResponse,
|
|
1503
1514
|
'peernet-ps': PsMessage,
|
|
1515
|
+
'chat-message': ChatMessage
|
|
1504
1516
|
};
|
|
1505
1517
|
this.protos = globalThis.peernet.protos;
|
|
1506
1518
|
|
|
@@ -1549,7 +1561,7 @@ class Peernet {
|
|
|
1549
1561
|
this._peerHandler.discover(peer);
|
|
1550
1562
|
peer.on('peernet.data', async (message) => {
|
|
1551
1563
|
const id = message.id;
|
|
1552
|
-
message = new peernetMessage(Buffer.from(message.data.data));
|
|
1564
|
+
message = new peernetMessage.PeernetMessage(Buffer.from(message.data.data));
|
|
1553
1565
|
const proto = protoFor(message.decoded.data);
|
|
1554
1566
|
await this._protoHandler({id, proto}, peer);
|
|
1555
1567
|
const fulldId = this._getPeerId(peer.id);
|
|
@@ -1853,6 +1865,36 @@ class Peernet {
|
|
|
1853
1865
|
return null
|
|
1854
1866
|
}
|
|
1855
1867
|
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
get message() {
|
|
1871
|
+
return {
|
|
1872
|
+
/**
|
|
1873
|
+
* Get content for given message hash
|
|
1874
|
+
*
|
|
1875
|
+
* @param {String} hash
|
|
1876
|
+
*/
|
|
1877
|
+
get: async (hash) => {
|
|
1878
|
+
debug(`get message ${hash}`);
|
|
1879
|
+
const message = await messageStore.has(hash);
|
|
1880
|
+
if (message) return await messageStore.get(hash)
|
|
1881
|
+
return this.requestData(hash, 'message')
|
|
1882
|
+
},
|
|
1883
|
+
/**
|
|
1884
|
+
* put message content
|
|
1885
|
+
*
|
|
1886
|
+
* @param {String} hash
|
|
1887
|
+
* @param {Buffer} message
|
|
1888
|
+
*/
|
|
1889
|
+
put: async (hash, message) => await messageStore.put(hash, message),
|
|
1890
|
+
/**
|
|
1891
|
+
* @param {String} hash
|
|
1892
|
+
* @return {Boolean}
|
|
1893
|
+
*/
|
|
1894
|
+
has: async (hash) => await messageStore.has(hash),
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1856
1898
|
get data() {
|
|
1857
1899
|
return {
|
|
1858
1900
|
/**
|
|
@@ -1943,16 +1985,16 @@ class Peernet {
|
|
|
1943
1985
|
*/
|
|
1944
1986
|
async publish(topic, data) {
|
|
1945
1987
|
// globalSub.publish(topic, data)
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
1988
|
if (!Buffer.isBuffer(topic)) topic = Buffer.from(topic);
|
|
1949
1989
|
if (!Buffer.isBuffer(data)) data = Buffer.from(data);
|
|
1950
1990
|
const id = Math.random().toString(36).slice(-12);
|
|
1951
1991
|
data = new PsMessage({data, topic});
|
|
1952
1992
|
for (const peer of this.peers) {
|
|
1953
|
-
if (peer.connection._connected
|
|
1954
|
-
|
|
1955
|
-
|
|
1993
|
+
if (peer.connection._connected) {
|
|
1994
|
+
if (peer.id.toString() !== this.peerId.toString()) {
|
|
1995
|
+
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
1996
|
+
peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
|
|
1997
|
+
}
|
|
1956
1998
|
} else {
|
|
1957
1999
|
this.removePeer(peer);
|
|
1958
2000
|
}
|
package/dist/module/peernet.js
CHANGED
|
@@ -244,7 +244,7 @@ class LeofcoinStorage$1 {
|
|
|
244
244
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
var version = "0.
|
|
247
|
+
var version = "0.9.0";
|
|
248
248
|
|
|
249
249
|
var api$1 = {
|
|
250
250
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -1559,6 +1559,17 @@ class DataMessageResponse extends FormatInterface {
|
|
|
1559
1559
|
}
|
|
1560
1560
|
}
|
|
1561
1561
|
|
|
1562
|
+
class ChatMessage extends FormatInterface {
|
|
1563
|
+
get keys() {
|
|
1564
|
+
return ['author', 'value', 'timestamp', 'files']
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
constructor(buffer) {
|
|
1568
|
+
const name = 'chat-message';
|
|
1569
|
+
super(buffer, protons(proto$9).ChatMessage, {name});
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1562
1573
|
const debug = (log) => {
|
|
1563
1574
|
if (globalThis.DEBUG || globalThis.debug) console.log(`%c ${log}`, 'color: #0080ff;');
|
|
1564
1575
|
};
|
|
@@ -1960,7 +1971,7 @@ class Peernet {
|
|
|
1960
1971
|
}
|
|
1961
1972
|
|
|
1962
1973
|
get defaultStores() {
|
|
1963
|
-
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data']
|
|
1974
|
+
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
1964
1975
|
}
|
|
1965
1976
|
|
|
1966
1977
|
addProto(name, proto) {
|
|
@@ -1973,7 +1984,7 @@ class Peernet {
|
|
|
1973
1984
|
|
|
1974
1985
|
async addStore(name, prefix, root, isPrivate = true) {
|
|
1975
1986
|
if (name === 'block' || name === 'transaction' || name === 'chain' ||
|
|
1976
|
-
name === 'data') isPrivate = false;
|
|
1987
|
+
name === 'data' || name === 'message') isPrivate = false;
|
|
1977
1988
|
|
|
1978
1989
|
let Storage;
|
|
1979
1990
|
if (this.hasDaemon) {
|
|
@@ -2049,6 +2060,7 @@ class Peernet {
|
|
|
2049
2060
|
'peernet-data': DataMessage,
|
|
2050
2061
|
'peernet-data-response': DataMessageResponse,
|
|
2051
2062
|
'peernet-ps': PsMessage,
|
|
2063
|
+
'chat-message': ChatMessage,
|
|
2052
2064
|
};
|
|
2053
2065
|
this.protos = globalThis.peernet.protos;
|
|
2054
2066
|
|
|
@@ -2401,6 +2413,35 @@ class Peernet {
|
|
|
2401
2413
|
return null
|
|
2402
2414
|
}
|
|
2403
2415
|
|
|
2416
|
+
|
|
2417
|
+
get message() {
|
|
2418
|
+
return {
|
|
2419
|
+
/**
|
|
2420
|
+
* Get content for given message hash
|
|
2421
|
+
*
|
|
2422
|
+
* @param {String} hash
|
|
2423
|
+
*/
|
|
2424
|
+
get: async (hash) => {
|
|
2425
|
+
debug(`get message ${hash}`);
|
|
2426
|
+
const message = await messageStore.has(hash);
|
|
2427
|
+
if (message) return await messageStore.get(hash)
|
|
2428
|
+
return this.requestData(hash, 'message')
|
|
2429
|
+
},
|
|
2430
|
+
/**
|
|
2431
|
+
* put message content
|
|
2432
|
+
*
|
|
2433
|
+
* @param {String} hash
|
|
2434
|
+
* @param {Buffer} message
|
|
2435
|
+
*/
|
|
2436
|
+
put: async (hash, message) => await messageStore.put(hash, message),
|
|
2437
|
+
/**
|
|
2438
|
+
* @param {String} hash
|
|
2439
|
+
* @return {Boolean}
|
|
2440
|
+
*/
|
|
2441
|
+
has: async (hash) => await messageStore.has(hash),
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2404
2445
|
get data() {
|
|
2405
2446
|
return {
|
|
2406
2447
|
/**
|
|
@@ -2491,16 +2532,16 @@ class Peernet {
|
|
|
2491
2532
|
*/
|
|
2492
2533
|
async publish(topic, data) {
|
|
2493
2534
|
// globalSub.publish(topic, data)
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
2535
|
if (!Buffer.isBuffer(topic)) topic = Buffer.from(topic);
|
|
2497
2536
|
if (!Buffer.isBuffer(data)) data = Buffer.from(data);
|
|
2498
2537
|
const id = Math.random().toString(36).slice(-12);
|
|
2499
2538
|
data = new PsMessage({data, topic});
|
|
2500
2539
|
for (const peer of this.peers) {
|
|
2501
|
-
if (peer.connection._connected
|
|
2502
|
-
|
|
2503
|
-
|
|
2540
|
+
if (peer.connection._connected) {
|
|
2541
|
+
if (peer.id.toString() !== this.peerId.toString()) {
|
|
2542
|
+
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2543
|
+
peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
|
|
2544
|
+
}
|
|
2504
2545
|
} else {
|
|
2505
2546
|
this.removePeer(peer);
|
|
2506
2547
|
}
|