@leofcoin/peernet 0.11.0 → 0.11.3

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 (46) 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/326.peernet.js +1 -0
  13. package/dist/browser/peernet.js +2 -108930
  14. package/dist/browser/peernet.js.LICENSE.txt +40 -0
  15. package/dist/commonjs/{client-bd0caeb7.js → client-1a1f75e6.js} +41 -41
  16. package/dist/commonjs/{codec-4a768e5e.js → codec-8c8c652f.js} +118 -118
  17. package/dist/commonjs/codec-format-interface.js +167 -167
  18. package/dist/commonjs/codec.js +2 -2
  19. package/dist/commonjs/dht-response.js +11 -11
  20. package/dist/commonjs/dht.js +2 -2
  21. package/dist/commonjs/hash.js +149 -149
  22. package/dist/commonjs/{http-2b0735ef.js → http-e088ccdb.js} +1 -1
  23. package/dist/commonjs/peernet-message.js +4 -4
  24. package/dist/commonjs/peernet.js +850 -943
  25. package/dist/commonjs/request.js +2 -2
  26. package/dist/commonjs/response.js +3 -3
  27. package/dist/module/peernet.js +1373 -1466
  28. package/index.html +2 -2
  29. package/package.json +6 -21
  30. package/src/client.js +75 -75
  31. package/src/codec/codec-format-interface.js +172 -172
  32. package/src/codec/codec.js +124 -124
  33. package/src/dht/dht.js +121 -121
  34. package/src/discovery/peer-discovery.js +75 -75
  35. package/src/handlers/message.js +2 -4
  36. package/src/hash/hash.js +155 -155
  37. package/src/http/client/http-client.js +44 -44
  38. package/src/messages/dht-response.js +14 -14
  39. package/src/peer.js +67 -67
  40. package/src/peernet.js +613 -612
  41. package/src/proto/chat-message.proto.js +7 -7
  42. package/src/proto/peernet.proto.js +2 -2
  43. package/src/proto/response.proto.js +1 -1
  44. package/src/utils/utils.js +78 -78
  45. package/test.js +1 -1
  46. package/webpack.config.js +10 -4
@@ -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.2";
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');
@@ -19,8 +19,8 @@ var proto = `
19
19
  message PeernetMessage {
20
20
  required bytes data = 1;
21
21
  required bytes signature = 2;
22
- optional bytes from = 3;
23
- optional bytes to = 4;
22
+ optional string from = 3;
23
+ optional string to = 4;
24
24
  optional string id = 5;
25
25
  }`;
26
26