@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
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Determine if an object is a Buffer
3
+ *
4
+ * @author Feross Aboukhadijeh <https://feross.org>
5
+ * @license MIT
6
+ */
7
+
8
+ /*!
9
+ * The buffer module from node.js, for the browser.
10
+ *
11
+ * @author Feross Aboukhadijeh <https://feross.org>
12
+ * @license MIT
13
+ */
14
+
15
+ /*!
16
+ * assert.js - assertions for javascript
17
+ * Copyright (c) 2018, Christopher Jeffrey (MIT License).
18
+ * https://github.com/chjj/bsert
19
+ */
20
+
21
+ /*!
22
+ * base32.js - base32 for bcrypto
23
+ * Copyright (c) 2014-2019, Christopher Jeffrey (MIT License).
24
+ * https://github.com/bcoin-org/bcrypto
25
+ *
26
+ * Parts of this software are based on bitcoin/bitcoin:
27
+ * Copyright (c) 2009-2019, The Bitcoin Core Developers (MIT License).
28
+ * Copyright (c) 2009-2019, The Bitcoin Developers (MIT License).
29
+ * https://github.com/bitcoin/bitcoin
30
+ *
31
+ * Resources:
32
+ * https://tools.ietf.org/html/rfc4648
33
+ * https://github.com/bitcoin/bitcoin/blob/11d486d/src/utilstrencodings.cpp#L230
34
+ */
35
+
36
+ /*! For license information please see browser.js.LICENSE.txt */
37
+
38
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
39
+
40
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -229,47 +229,47 @@ const socketRequestClient = (url, protocols = 'echo-protocol', options = { retry
229
229
  });
230
230
  };
231
231
 
232
- class HttpClientApi$1 {
233
- constructor(config = {}) {
234
- if (!config.apiPath) config.apiPath = 'api';
235
-
236
- const address = `ws://${config.host}:${config.port}`;
237
-
238
- this.apiUrl = (url) => `${address}/${url}`;
239
- return (async () => {
240
- this.client = await socketRequestClient(address, config.protocol, {pubsub: config.pubsub, retry: 3000});
241
- return this
242
- })()
243
- }
244
-
245
- async get(url, obj) {
246
- const headers = {};
247
- let body = null;
248
- let method = 'GET';
249
- if (obj) {
250
- method = 'POST';
251
- headers['Content-Type'] = 'application/json';
252
- body = JSON.stringify(obj);
253
- }
254
- let response = await this.client.request(url, {headers, body, method});
255
- const type = response.headers.get('content-type').split(';')[0];
256
- if (type==='application/json') response = await response.json();
257
- return response
258
- }
259
-
260
- async put(url, obj) {
261
- const headers = {};
262
- let body = {};
263
- if (obj) {
264
- headers['Content-Type'] = 'application/json';
265
- body = JSON.stringify(obj);
266
- }
267
-
268
- let response = await fetch(this.apiUrl(url), {method: 'PUT', headers, body});
269
- const type = response.headers.get('content-type').split(';')[0];
270
- if (type==='application/json') response = await response.json();
271
- return response
272
- }
232
+ class HttpClientApi$1 {
233
+ constructor(config = {}) {
234
+ if (!config.apiPath) config.apiPath = 'api';
235
+
236
+ const address = `ws://${config.host}:${config.port}`;
237
+
238
+ this.apiUrl = (url) => `${address}/${url}`;
239
+ return (async () => {
240
+ this.client = await socketRequestClient(address, config.protocol, {pubsub: config.pubsub, retry: 3000});
241
+ return this
242
+ })()
243
+ }
244
+
245
+ async get(url, obj) {
246
+ const headers = {};
247
+ let body = null;
248
+ let method = 'GET';
249
+ if (obj) {
250
+ method = 'POST';
251
+ headers['Content-Type'] = 'application/json';
252
+ body = JSON.stringify(obj);
253
+ }
254
+ let response = await this.client.request(url, {headers, body, method});
255
+ const type = response.headers.get('content-type').split(';')[0];
256
+ if (type==='application/json') response = await response.json();
257
+ return response
258
+ }
259
+
260
+ async put(url, obj) {
261
+ const headers = {};
262
+ let body = {};
263
+ if (obj) {
264
+ headers['Content-Type'] = 'application/json';
265
+ body = JSON.stringify(obj);
266
+ }
267
+
268
+ let response = await fetch(this.apiUrl(url), {method: 'PUT', headers, body});
269
+ const type = response.headers.get('content-type').split(';')[0];
270
+ if (type==='application/json') response = await response.json();
271
+ return response
272
+ }
273
273
  }
274
274
 
275
275
  class HttpClientApi extends HttpClientApi$1 {
@@ -3,7 +3,7 @@
3
3
  var varint = require('varint');
4
4
  var bs32 = require('@vandeurenglenn/base32');
5
5
  var bs58 = require('@vandeurenglenn/base58');
6
- var isHex = require('is-hex');
6
+ var isHex = require('@vandeurenglenn/is-hex');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
@@ -92,123 +92,123 @@ var codecs = {
92
92
  },
93
93
  };
94
94
 
95
- class PeernetCodec {
96
- get codecs() {
97
- return {...globalThis.peernet.codecs, ...codecs}
98
- }
99
- constructor(buffer) {
100
- if (buffer) {
101
- if (buffer instanceof Uint8Array) {
102
- const codec = varint__default["default"].decode(buffer);
103
- const name = this.getCodecName(codec);
104
- if (name) {
105
- this.name = name;
106
- this.encoded = buffer;
107
- this.decode(buffer);
108
- } else {
109
- this.encode(buffer);
110
- }
111
- } else if (buffer instanceof ArrayBuffer) {
112
- const encoded = new Uint8Array(buffer.byteLength);
113
-
114
- for (let i = 0; i < buffer.byteLength; i++) {
115
- encoded[i] = buffer[i];
116
- }
117
- this.encoded = encoded;
118
- // this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength)
119
- this.decode(buffer);
120
- return
121
- }
122
- if (typeof buffer === 'string') {
123
- if (this.codecs[buffer]) this.fromName(buffer);
124
- else if (isHex__default["default"](buffer)) this.fromHex(buffer);
125
- else if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
126
- else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
127
- else throw new Error(`unsupported string ${buffer}`)
128
- }
129
- if (!isNaN(buffer)) if (this.codecs[this.getCodecName(buffer)]) this.fromCodec(buffer);
130
- }
131
- }
132
-
133
- fromEncoded(encoded) {
134
- const codec = varint__default["default"].decode(encoded);
135
- const name = this.getCodecName(codec);
136
- this.name = name;
137
- this.encoded = encoded;
138
- this.decode(encoded);
139
- }
140
-
141
- fromHex(hex) {
142
- this.encoded = Buffer.from(hex, 'hex');
143
- this.decode();
144
- }
145
-
146
- fromBs32(input) {
147
- this.encoded = bs32__default["default"].decode(input);
148
- this.decode();
149
- }
150
-
151
- fromBs58(input) {
152
- this.encoded = bs58__default["default"].decode(input);
153
- this.decode();
154
- }
155
-
156
- getCodec(name) {
157
- return this.codecs[name].codec
158
- }
159
-
160
- getCodecName(codec) {
161
- return Object.keys(this.codecs).reduce((p, c) => {
162
- const item = this.codecs[c];
163
- if (item.codec === codec) return c;
164
- else return p;
165
- }, undefined)
166
- }
167
-
168
- getHashAlg(name) {
169
- return this.codecs[name].hashAlg
170
- }
171
-
172
- fromCodec(codec) {
173
- this.name = this.getCodecName(codec);
174
- this.hashAlg = this.getHashAlg(this.name);
175
-
176
- this.codec = this.getCodec(this.name);
177
- this.codecBuffer = varint__default["default"].encode(codec);
178
- }
179
-
180
- fromName(name) {
181
- const codec = this.getCodec(name);
182
- this.name = name;
183
- this.codec = codec;
184
- this.hashAlg = this.getHashAlg(name);
185
- this.codecBuffer = varint__default["default"].encode(codec);
186
- }
187
-
188
- toBs32() {
189
- this.encode();
190
- return bs32__default["default"].encode(this.encoded)
191
- }
192
-
193
- toBs58() {
194
- this.encode();
195
- return bs58__default["default"].encode(this.encoded)
196
- }
197
-
198
- toHex() {
199
- return this.encoded.toString('hex')
200
- }
201
-
202
- decode() {
203
- const codec = varint__default["default"].decode(this.encoded);
204
- this.fromCodec(codec);
205
- }
206
-
207
- encode() {
208
- const codec = varint__default["default"].encode(this.decoded);
209
- this.encoded = codec;
210
- return this.encoded
211
- }
95
+ class PeernetCodec {
96
+ get codecs() {
97
+ return {...globalThis.peernet.codecs, ...codecs}
98
+ }
99
+ constructor(buffer) {
100
+ if (buffer) {
101
+ if (buffer instanceof Uint8Array) {
102
+ const codec = varint__default["default"].decode(buffer);
103
+ const name = this.getCodecName(codec);
104
+ if (name) {
105
+ this.name = name;
106
+ this.encoded = buffer;
107
+ this.decode(buffer);
108
+ } else {
109
+ this.encode(buffer);
110
+ }
111
+ } else if (buffer instanceof ArrayBuffer) {
112
+ const encoded = new Uint8Array(buffer.byteLength);
113
+
114
+ for (let i = 0; i < buffer.byteLength; i++) {
115
+ encoded[i] = buffer[i];
116
+ }
117
+ this.encoded = encoded;
118
+ // this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength)
119
+ this.decode(buffer);
120
+ return
121
+ }
122
+ if (typeof buffer === 'string') {
123
+ if (this.codecs[buffer]) this.fromName(buffer);
124
+ else if (isHex__default["default"](buffer)) this.fromHex(buffer);
125
+ else if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
126
+ else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
127
+ else throw new Error(`unsupported string ${buffer}`)
128
+ }
129
+ if (!isNaN(buffer)) if (this.codecs[this.getCodecName(buffer)]) this.fromCodec(buffer);
130
+ }
131
+ }
132
+
133
+ fromEncoded(encoded) {
134
+ const codec = varint__default["default"].decode(encoded);
135
+ const name = this.getCodecName(codec);
136
+ this.name = name;
137
+ this.encoded = encoded;
138
+ this.decode(encoded);
139
+ }
140
+
141
+ fromHex(hex) {
142
+ this.encoded = Buffer.from(hex, 'hex');
143
+ this.decode();
144
+ }
145
+
146
+ fromBs32(input) {
147
+ this.encoded = bs32__default["default"].decode(input);
148
+ this.decode();
149
+ }
150
+
151
+ fromBs58(input) {
152
+ this.encoded = bs58__default["default"].decode(input);
153
+ this.decode();
154
+ }
155
+
156
+ getCodec(name) {
157
+ return this.codecs[name].codec
158
+ }
159
+
160
+ getCodecName(codec) {
161
+ return Object.keys(this.codecs).reduce((p, c) => {
162
+ const item = this.codecs[c];
163
+ if (item.codec === codec) return c;
164
+ else return p;
165
+ }, undefined)
166
+ }
167
+
168
+ getHashAlg(name) {
169
+ return this.codecs[name].hashAlg
170
+ }
171
+
172
+ fromCodec(codec) {
173
+ this.name = this.getCodecName(codec);
174
+ this.hashAlg = this.getHashAlg(this.name);
175
+
176
+ this.codec = this.getCodec(this.name);
177
+ this.codecBuffer = varint__default["default"].encode(codec);
178
+ }
179
+
180
+ fromName(name) {
181
+ const codec = this.getCodec(name);
182
+ this.name = name;
183
+ this.codec = codec;
184
+ this.hashAlg = this.getHashAlg(name);
185
+ this.codecBuffer = varint__default["default"].encode(codec);
186
+ }
187
+
188
+ toBs32() {
189
+ this.encode();
190
+ return bs32__default["default"].encode(this.encoded)
191
+ }
192
+
193
+ toBs58() {
194
+ this.encode();
195
+ return bs58__default["default"].encode(this.encoded)
196
+ }
197
+
198
+ toHex() {
199
+ return this.encoded.toString('hex')
200
+ }
201
+
202
+ decode() {
203
+ const codec = varint__default["default"].decode(this.encoded);
204
+ this.fromCodec(codec);
205
+ }
206
+
207
+ encode() {
208
+ const codec = varint__default["default"].encode(this.decoded);
209
+ this.encoded = codec;
210
+ return this.encoded
211
+ }
212
212
  }
213
213
 
214
214
  exports.PeernetCodec = PeernetCodec;