@leofcoin/peernet 0.11.0 → 0.11.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.
Files changed (38) hide show
  1. package/coverage/lcov-report/base.css +224 -0
  2. package/coverage/lcov-report/block-navigation.js +87 -0
  3. package/coverage/lcov-report/codec-format-interface.js.html +637 -0
  4. package/coverage/lcov-report/dht-response.js.html +193 -0
  5. package/coverage/lcov-report/favicon.png +0 -0
  6. package/coverage/lcov-report/index.html +131 -0
  7. package/coverage/lcov-report/prettify.css +1 -0
  8. package/coverage/lcov-report/prettify.js +2 -0
  9. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  10. package/coverage/lcov-report/sorter.js +196 -0
  11. package/coverage/lcov.info +199 -0
  12. package/dist/browser/peernet.js +1288 -1385
  13. package/dist/commonjs/{client-bd0caeb7.js → client-1a1f75e6.js} +41 -41
  14. package/dist/commonjs/{codec-4a768e5e.js → codec-8c8c652f.js} +118 -118
  15. package/dist/commonjs/codec-format-interface.js +167 -167
  16. package/dist/commonjs/codec.js +2 -2
  17. package/dist/commonjs/dht-response.js +11 -11
  18. package/dist/commonjs/dht.js +2 -2
  19. package/dist/commonjs/hash.js +149 -149
  20. package/dist/commonjs/{http-2b0735ef.js → http-7bbac90a.js} +1 -1
  21. package/dist/commonjs/peernet-message.js +2 -2
  22. package/dist/commonjs/peernet.js +843 -934
  23. package/dist/commonjs/request.js +2 -2
  24. package/dist/commonjs/response.js +2 -2
  25. package/dist/module/peernet.js +1357 -1448
  26. package/package.json +2 -18
  27. package/src/client.js +75 -75
  28. package/src/codec/codec-format-interface.js +172 -172
  29. package/src/codec/codec.js +124 -124
  30. package/src/dht/dht.js +121 -121
  31. package/src/discovery/peer-discovery.js +75 -75
  32. package/src/hash/hash.js +155 -155
  33. package/src/http/client/http-client.js +44 -44
  34. package/src/messages/dht-response.js +14 -14
  35. package/src/peer.js +67 -67
  36. package/src/peernet.js +612 -612
  37. package/src/proto/chat-message.proto.js +7 -7
  38. package/src/utils/utils.js +78 -78
@@ -3,8 +3,8 @@
3
3
  require('varint');
4
4
  require('@vandeurenglenn/base32');
5
5
  require('@vandeurenglenn/base58');
6
- require('is-hex');
7
- var codec = require('./codec-4a768e5e.js');
6
+ require('@vandeurenglenn/is-hex');
7
+ var codec = require('./codec-8c8c652f.js');
8
8
 
9
9
 
10
10
 
@@ -4,8 +4,8 @@ var protons = require('protons');
4
4
  var codecFormatInterface = require('./codec-format-interface.js');
5
5
  require('@vandeurenglenn/base32');
6
6
  require('@vandeurenglenn/base58');
7
- require('is-hex');
8
- require('./codec-4a768e5e.js');
7
+ require('@vandeurenglenn/is-hex');
8
+ require('./codec-8c8c652f.js');
9
9
  require('varint');
10
10
  require('./hash.js');
11
11
  require('keccak');
@@ -22,15 +22,15 @@ message PeernetDHTMessageResponse {
22
22
  }
23
23
  `;
24
24
 
25
- class DHTMessageResponse extends codecFormatInterface {
26
- get keys() {
27
- return ['hash', 'has']
28
- }
29
-
30
- constructor(data) {
31
- const name = 'peernet-dht-response';
32
- super(data, protons__default["default"](proto).PeernetDHTMessageResponse, {name});
33
- }
25
+ class DHTMessageResponse extends codecFormatInterface {
26
+ get keys() {
27
+ return ['hash', 'has']
28
+ }
29
+
30
+ constructor(data) {
31
+ const name = 'peernet-dht-response';
32
+ super(data, protons__default["default"](proto).PeernetDHTMessageResponse, {name});
33
+ }
34
34
  }
35
35
 
36
36
  module.exports = DHTMessageResponse;
@@ -4,8 +4,8 @@ var protons = require('protons');
4
4
  var codecFormatInterface = require('./codec-format-interface.js');
5
5
  require('@vandeurenglenn/base32');
6
6
  require('@vandeurenglenn/base58');
7
- require('is-hex');
8
- require('./codec-4a768e5e.js');
7
+ require('@vandeurenglenn/is-hex');
8
+ require('./codec-8c8c652f.js');
9
9
  require('varint');
10
10
  require('./hash.js');
11
11
  require('keccak');
@@ -4,8 +4,8 @@ var createKeccakHash = require('keccak');
4
4
  var varint = require('varint');
5
5
  var bs32 = require('@vandeurenglenn/base32');
6
6
  var bs58 = require('@vandeurenglenn/base58');
7
- var isHex = require('is-hex');
8
- var codec = require('./codec-4a768e5e.js');
7
+ var isHex = require('@vandeurenglenn/is-hex');
8
+ var codec = require('./codec-8c8c652f.js');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
@@ -15,153 +15,153 @@ var bs32__default = /*#__PURE__*/_interopDefaultLegacy(bs32);
15
15
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
16
16
  var isHex__default = /*#__PURE__*/_interopDefaultLegacy(isHex);
17
17
 
18
- class PeernetHash {
19
- constructor(buffer, options = {}) {
20
- if (options.name) this.name = options.name;
21
- else this.name = 'disco-hash';
22
- if (options.codecs) this.codecs = options.codecs;
23
- if (buffer) {
24
- if (Buffer.isBuffer(buffer)) {
25
- this.discoCodec = new codec.PeernetCodec(buffer, this.codecs);
26
- const name = this.discoCodec.name;
27
-
28
- if (name) {
29
- this.name = name;
30
- this.decode(buffer);
31
- } else {
32
- this.encode(buffer);
33
- }
34
- }
35
-
36
- if (typeof buffer === 'string') {
37
- if (isHex__default["default"](buffer)) this.fromHex(buffer);
38
- if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
39
- else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
40
- else throw new Error(`unsupported string ${buffer}`)
41
- } else if (typeof buffer === 'object') this.fromJSON(buffer);
42
- }
43
- }
44
-
45
- get prefix() {
46
- const length = this.length;
47
- const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
48
- for (let i = 0; i < this.discoCodec.codecBuffer.length; i++) {
49
- uint8Array[i] = this.discoCodec.codecBuffer[i];
50
- }
51
-
52
- for (let i = uint8Array.length - 1; i < length.length; i++) {
53
- uint8Array[i] = length[i];
54
- }
55
- return uint8Array
56
- }
57
-
58
- get length() {
59
- return varint__default["default"].encode(this.size)
60
- }
61
-
62
- get buffer() {
63
- return this.hash
64
- }
65
-
66
- toHex() {
67
- return this.hash.toString('hex')
68
- }
69
-
70
- fromHex(hex) {
71
- return this.decode(Buffer.from(hex, 'hex'))
72
- }
73
-
74
- fromJSON(json) {
75
- return this.encode(Buffer.from(JSON.stringify(json)))
76
- }
77
-
78
- toBs32() {
79
- return bs32__default["default"].encode(this.hash)
80
- }
81
-
82
- fromBs32(bs) {
83
- return this.decode(bs32__default["default"].decode(bs))
84
- }
85
-
86
- toBs58() {
87
- return bs58__default["default"].encode(this.hash)
88
- }
89
-
90
- fromBs58(bs) {
91
- return this.decode(bs58__default["default"].decode(bs))
92
- }
93
-
94
- toString(encoding = 'utf8') {
95
- return this.hash.toString(encoding)
96
- }
97
-
98
- encode(buffer, name) {
99
- if (!this.name && name) this.name = name;
100
- if (!buffer) buffer = this.buffer;
101
- this.discoCodec = new codec.PeernetCodec(this.name, this.codecs);
102
- this.discoCodec.fromName(this.name);
103
- let hashAlg = this.discoCodec.hashAlg;
104
- if (hashAlg.includes('dbl')) {
105
- hashAlg = hashAlg.replace('dbl-', '');
106
- buffer = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
107
- }
108
- this.digest = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
109
- this.size = this.digest.length;
110
-
111
- this.codec = this.discoCodec.encode();
112
- this.codec = this.discoCodec.codecBuffer;
113
- this.hash = Buffer.concat([
114
- this.prefix,
115
- this.digest,
116
- ]);
117
-
118
- return this.hash
119
- }
120
-
121
- validate(buffer) {
122
- if (Buffer.isBuffer(buffer)) {
123
- const codec = varint__default["default"].decode(buffer);
124
- if (this.codecs[codec]) {
125
- this.decode(buffer);
126
- } else {
127
- this.encode(buffer);
128
- }
129
- }
130
- if (typeof buffer === 'string') {
131
- if (isHex__default["default"](buffer)) this.fromHex(buffer);
132
- if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
133
- }
134
- if (typeof buffer === 'object') this.fromJSON(buffer);
135
- }
136
-
137
- decode(buffer) {
138
- this.hash = buffer;
139
- const codec$1 = varint__default["default"].decode(buffer);
140
-
141
- this.discoCodec = new codec.PeernetCodec(codec$1, this.codecs);
142
- // TODO: validate codec
143
- buffer = buffer.slice(varint__default["default"].decode.bytes);
144
- this.size = varint__default["default"].decode(buffer);
145
- this.digest = buffer.slice(varint__default["default"].decode.bytes);
146
- if (this.digest.length !== this.size) {
147
- throw new Error(`hash length inconsistent: 0x${this.hash.toString('hex')}`)
148
- }
149
-
150
- // const discoCodec = new Codec(codec, this.codecs)
151
-
152
- this.name = this.discoCodec.name;
153
-
154
-
155
- this.size = this.digest.length;
156
-
157
- return {
158
- codec: this.codec,
159
- name: this.name,
160
- size: this.size,
161
- length: this.length,
162
- digest: this.digest,
163
- }
164
- }
18
+ class PeernetHash {
19
+ constructor(buffer, options = {}) {
20
+ if (options.name) this.name = options.name;
21
+ else this.name = 'disco-hash';
22
+ if (options.codecs) this.codecs = options.codecs;
23
+ if (buffer) {
24
+ if (Buffer.isBuffer(buffer)) {
25
+ this.discoCodec = new codec.PeernetCodec(buffer, this.codecs);
26
+ const name = this.discoCodec.name;
27
+
28
+ if (name) {
29
+ this.name = name;
30
+ this.decode(buffer);
31
+ } else {
32
+ this.encode(buffer);
33
+ }
34
+ }
35
+
36
+ if (typeof buffer === 'string') {
37
+ if (isHex__default["default"](buffer)) this.fromHex(buffer);
38
+ if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
39
+ else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
40
+ else throw new Error(`unsupported string ${buffer}`)
41
+ } else if (typeof buffer === 'object') this.fromJSON(buffer);
42
+ }
43
+ }
44
+
45
+ get prefix() {
46
+ const length = this.length;
47
+ const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
48
+ for (let i = 0; i < this.discoCodec.codecBuffer.length; i++) {
49
+ uint8Array[i] = this.discoCodec.codecBuffer[i];
50
+ }
51
+
52
+ for (let i = uint8Array.length - 1; i < length.length; i++) {
53
+ uint8Array[i] = length[i];
54
+ }
55
+ return uint8Array
56
+ }
57
+
58
+ get length() {
59
+ return varint__default["default"].encode(this.size)
60
+ }
61
+
62
+ get buffer() {
63
+ return this.hash
64
+ }
65
+
66
+ toHex() {
67
+ return this.hash.toString('hex')
68
+ }
69
+
70
+ fromHex(hex) {
71
+ return this.decode(Buffer.from(hex, 'hex'))
72
+ }
73
+
74
+ fromJSON(json) {
75
+ return this.encode(Buffer.from(JSON.stringify(json)))
76
+ }
77
+
78
+ toBs32() {
79
+ return bs32__default["default"].encode(this.hash)
80
+ }
81
+
82
+ fromBs32(bs) {
83
+ return this.decode(bs32__default["default"].decode(bs))
84
+ }
85
+
86
+ toBs58() {
87
+ return bs58__default["default"].encode(this.hash)
88
+ }
89
+
90
+ fromBs58(bs) {
91
+ return this.decode(bs58__default["default"].decode(bs))
92
+ }
93
+
94
+ toString(encoding = 'utf8') {
95
+ return this.hash.toString(encoding)
96
+ }
97
+
98
+ encode(buffer, name) {
99
+ if (!this.name && name) this.name = name;
100
+ if (!buffer) buffer = this.buffer;
101
+ this.discoCodec = new codec.PeernetCodec(this.name, this.codecs);
102
+ this.discoCodec.fromName(this.name);
103
+ let hashAlg = this.discoCodec.hashAlg;
104
+ if (hashAlg.includes('dbl')) {
105
+ hashAlg = hashAlg.replace('dbl-', '');
106
+ buffer = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
107
+ }
108
+ this.digest = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
109
+ this.size = this.digest.length;
110
+
111
+ this.codec = this.discoCodec.encode();
112
+ this.codec = this.discoCodec.codecBuffer;
113
+ this.hash = Buffer.concat([
114
+ this.prefix,
115
+ this.digest,
116
+ ]);
117
+
118
+ return this.hash
119
+ }
120
+
121
+ validate(buffer) {
122
+ if (Buffer.isBuffer(buffer)) {
123
+ const codec = varint__default["default"].decode(buffer);
124
+ if (this.codecs[codec]) {
125
+ this.decode(buffer);
126
+ } else {
127
+ this.encode(buffer);
128
+ }
129
+ }
130
+ if (typeof buffer === 'string') {
131
+ if (isHex__default["default"](buffer)) this.fromHex(buffer);
132
+ if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
133
+ }
134
+ if (typeof buffer === 'object') this.fromJSON(buffer);
135
+ }
136
+
137
+ decode(buffer) {
138
+ this.hash = buffer;
139
+ const codec$1 = varint__default["default"].decode(buffer);
140
+
141
+ this.discoCodec = new codec.PeernetCodec(codec$1, this.codecs);
142
+ // TODO: validate codec
143
+ buffer = buffer.slice(varint__default["default"].decode.bytes);
144
+ this.size = varint__default["default"].decode(buffer);
145
+ this.digest = buffer.slice(varint__default["default"].decode.bytes);
146
+ if (this.digest.length !== this.size) {
147
+ throw new Error(`hash length inconsistent: 0x${this.hash.toString('hex')}`)
148
+ }
149
+
150
+ // const discoCodec = new Codec(codec, this.codecs)
151
+
152
+ this.name = this.discoCodec.name;
153
+
154
+
155
+ this.size = this.digest.length;
156
+
157
+ return {
158
+ codec: this.codec,
159
+ name: this.name,
160
+ size: this.size,
161
+ length: this.length,
162
+ digest: this.digest,
163
+ }
164
+ }
165
165
  }
166
166
 
167
167
  module.exports = PeernetHash;
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
10
10
  var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
11
11
  var Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
12
12
 
13
- var version = "0.10.8";
13
+ var version = "0.11.0";
14
14
 
15
15
  var api$1 = {
16
16
  version: ({send}) => send({client: '@peernet/api/http', version}),
@@ -4,8 +4,8 @@ var protons = require('protons');
4
4
  var codecFormatInterface = require('./codec-format-interface.js');
5
5
  require('@vandeurenglenn/base32');
6
6
  require('@vandeurenglenn/base58');
7
- require('is-hex');
8
- require('./codec-4a768e5e.js');
7
+ require('@vandeurenglenn/is-hex');
8
+ require('./codec-8c8c652f.js');
9
9
  require('varint');
10
10
  require('./hash.js');
11
11
  require('keccak');