@leofcoin/peernet 0.10.5 → 0.10.8
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 +33443 -30179
- package/dist/commonjs/codec-6367213c.js +205 -0
- package/dist/commonjs/codec-format-interface.js +7 -7
- package/dist/commonjs/codec.js +1 -1
- package/dist/commonjs/dht-response.js +2 -2
- package/dist/commonjs/dht.js +2 -2
- package/dist/commonjs/hash.js +17 -17
- package/dist/commonjs/peernet-message.js +2 -2
- package/dist/commonjs/peernet.js +25 -26
- package/dist/commonjs/request.js +2 -2
- package/dist/commonjs/response.js +2 -2
- package/dist/module/peernet.js +6 -7
- package/package.json +5 -3
- package/src/peernet.js +4 -5
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var varint = require('varint');
|
|
4
|
+
var bs32 = require('bs32');
|
|
5
|
+
var bs58 = require('bs58');
|
|
6
|
+
var isHex = require('is-hex');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var varint__default = /*#__PURE__*/_interopDefaultLegacy(varint);
|
|
11
|
+
var bs32__default = /*#__PURE__*/_interopDefaultLegacy(bs32);
|
|
12
|
+
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
13
|
+
var isHex__default = /*#__PURE__*/_interopDefaultLegacy(isHex);
|
|
14
|
+
|
|
15
|
+
var codecs = {
|
|
16
|
+
// just a hash
|
|
17
|
+
'disco-hash': {
|
|
18
|
+
codec: '30',
|
|
19
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
20
|
+
// testnet: 'olivia'
|
|
21
|
+
},
|
|
22
|
+
'peernet-peer-response': {
|
|
23
|
+
codec: '707072',
|
|
24
|
+
hashAlg: 'keccak-256',
|
|
25
|
+
},
|
|
26
|
+
'peernet-peer': {
|
|
27
|
+
codec: '7070',
|
|
28
|
+
hashAlg: 'keccak-256',
|
|
29
|
+
},
|
|
30
|
+
'peernet-dht': {
|
|
31
|
+
codec: '706468',
|
|
32
|
+
hashAlg: 'keccak-256',
|
|
33
|
+
},
|
|
34
|
+
'peernet-dht-response': {
|
|
35
|
+
codec: '706472',
|
|
36
|
+
hashAlg: 'keccak-256',
|
|
37
|
+
},
|
|
38
|
+
// data
|
|
39
|
+
'peernet-data': {
|
|
40
|
+
codec: '706461',
|
|
41
|
+
hashAlg: 'keccak-256',
|
|
42
|
+
},
|
|
43
|
+
'peernet-data-response': {
|
|
44
|
+
codec: '70646172',
|
|
45
|
+
hashAlg: 'keccak-256',
|
|
46
|
+
},
|
|
47
|
+
// message
|
|
48
|
+
'peernet-message': {
|
|
49
|
+
codec: '706d65',
|
|
50
|
+
hashAlg: 'keccak-512',
|
|
51
|
+
},
|
|
52
|
+
// pubsub
|
|
53
|
+
'peernet-ps': {
|
|
54
|
+
codec: '707073',
|
|
55
|
+
hashAlg: 'keccak-256',
|
|
56
|
+
},
|
|
57
|
+
'peernet-response': {
|
|
58
|
+
codec: '7072',
|
|
59
|
+
hashAlg: 'keccak-256',
|
|
60
|
+
},
|
|
61
|
+
'peernet-request': {
|
|
62
|
+
codec: '707271',
|
|
63
|
+
hashAlg: 'keccak-256',
|
|
64
|
+
},
|
|
65
|
+
// normal block
|
|
66
|
+
'leofcoin-block': {
|
|
67
|
+
codec: '6c62',
|
|
68
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
69
|
+
// testnet: 'olivia'
|
|
70
|
+
},
|
|
71
|
+
'leofcoin-tx': {
|
|
72
|
+
codec: '6c74',
|
|
73
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
74
|
+
// testnet: 'olivia'
|
|
75
|
+
},
|
|
76
|
+
// itx
|
|
77
|
+
'leofcoin-itx': {
|
|
78
|
+
codec: '6c69',
|
|
79
|
+
hashAlg: 'keccak-512', // ,
|
|
80
|
+
// testnet: 'olivia'
|
|
81
|
+
},
|
|
82
|
+
// peer reputation
|
|
83
|
+
'leofcoin-pr': {
|
|
84
|
+
codec: '6c70',
|
|
85
|
+
hashAlg: 'keccak-256', // ,
|
|
86
|
+
// testnet: 'olivia'
|
|
87
|
+
},
|
|
88
|
+
// chat message
|
|
89
|
+
'chat-message': {
|
|
90
|
+
codec: '636d',
|
|
91
|
+
hashAlg: 'dbl-keccak-512',
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
class PeernetCodec {
|
|
96
|
+
get codecs() {
|
|
97
|
+
return {...globalThis.peernet.codecs, ...codecs}
|
|
98
|
+
}
|
|
99
|
+
constructor(buffer) {
|
|
100
|
+
if (buffer) {
|
|
101
|
+
if (Buffer.isBuffer(buffer)) {
|
|
102
|
+
const codec = varint__default["default"].decode(buffer);
|
|
103
|
+
const name = this.getCodecName(codec);
|
|
104
|
+
|
|
105
|
+
if (name) {
|
|
106
|
+
this.name = name;
|
|
107
|
+
this.encoded = buffer;
|
|
108
|
+
this.decode(buffer);
|
|
109
|
+
} else {
|
|
110
|
+
this.encode(buffer);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (typeof buffer === 'string') {
|
|
114
|
+
if (this.codecs[buffer]) this.fromName(buffer);
|
|
115
|
+
else if (isHex__default["default"](buffer)) this.fromHex(buffer);
|
|
116
|
+
else if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
|
|
117
|
+
else this.fromBs58(buffer);
|
|
118
|
+
}
|
|
119
|
+
if (!isNaN(buffer)) if (this.codecs[this.getCodecName(buffer)]) this.fromCodec(buffer);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fromEncoded(encoded) {
|
|
124
|
+
const codec = varint__default["default"].decode(encoded);
|
|
125
|
+
const name = this.getCodecName(codec);
|
|
126
|
+
this.name = name;
|
|
127
|
+
this.encoded = encoded;
|
|
128
|
+
this.decode(encoded);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fromHex(hex) {
|
|
132
|
+
this.encoded = Buffer.from(hex, 'hex');
|
|
133
|
+
this.decode();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
fromBs32(input) {
|
|
137
|
+
this.encoded = bs32__default["default"].decode(input);
|
|
138
|
+
this.decode();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fromBs58(input) {
|
|
142
|
+
this.encoded = bs58__default["default"].decode(input);
|
|
143
|
+
this.decode();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getCodec(name) {
|
|
147
|
+
return this.codecs[name].codec
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
getCodecName(codec) {
|
|
151
|
+
return Object.keys(this.codecs).reduce((p, c) => {
|
|
152
|
+
if (parseInt(Buffer.from(`${this.getCodec(c)}`, 'hex').toString('hex'), 16) === codec) return c;
|
|
153
|
+
else return p;
|
|
154
|
+
}, undefined)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
getHashAlg(name) {
|
|
158
|
+
return this.codecs[name].hashAlg
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
fromCodec(codec) {
|
|
162
|
+
this.name = this.getCodecName(codec);
|
|
163
|
+
this.hashAlg = this.getHashAlg(this.name);
|
|
164
|
+
|
|
165
|
+
this.codec = this.getCodec(this.name);
|
|
166
|
+
this.codecBuffer = Buffer.from(varint__default["default"].encode(parseInt(Buffer.from(`${this.codec}`, 'hex').toString('hex'), 16)), 'hex');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fromName(name) {
|
|
170
|
+
const codec = this.getCodec(name);
|
|
171
|
+
this.name = name;
|
|
172
|
+
this.codec = codec;
|
|
173
|
+
this.hashAlg = this.getHashAlg(name);
|
|
174
|
+
this.codecBuffer = Buffer.from(varint__default["default"].encode(parseInt(Buffer.from(`${codec}`, 'hex').toString('hex'), 16)), 'hex');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
toBs32() {
|
|
178
|
+
this.encode();
|
|
179
|
+
return bs32__default["default"].encode(this.encoded)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
toBs58() {
|
|
183
|
+
this.encode();
|
|
184
|
+
return bs58__default["default"].encode(this.encoded)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
toHex() {
|
|
188
|
+
return this.encoded.toString('hex')
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
decode() {
|
|
192
|
+
const codec = varint__default["default"].decode(this.encoded);
|
|
193
|
+
this.fromCodec(codec);
|
|
194
|
+
this.name = this.getCodecName(codec);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
encode() {
|
|
198
|
+
const codec = Buffer.from(varint__default["default"].encode(parseInt(Buffer.from(`${this.codec}`, 'hex').toString('hex'), 16)), 'hex');
|
|
199
|
+
this.encoded = codec;
|
|
200
|
+
return this.encoded
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
exports.PeernetCodec = PeernetCodec;
|
|
205
|
+
exports.codecs = codecs;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var bs32 = require('bs32');
|
|
4
4
|
var bs58 = require('bs58');
|
|
5
5
|
var isHex = require('is-hex');
|
|
6
|
-
var codec = require('./codec-
|
|
6
|
+
var codec = require('./codec-6367213c.js');
|
|
7
7
|
var hash = require('./hash.js');
|
|
8
8
|
require('varint');
|
|
9
9
|
require('keccak');
|
|
@@ -36,8 +36,8 @@ class FormatInterface {
|
|
|
36
36
|
}
|
|
37
37
|
} else {
|
|
38
38
|
if (typeof buffer === 'string') {
|
|
39
|
-
if (isHex__default[
|
|
40
|
-
else if (bs32__default[
|
|
39
|
+
if (isHex__default["default"](buffer)) this.fromHex(buffer);
|
|
40
|
+
else if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
|
|
41
41
|
else this.fromBs58(buffer);
|
|
42
42
|
} else if (typeof buffer === 'object' && !Array.isArray(buffer)) {
|
|
43
43
|
this.create(buffer);
|
|
@@ -105,7 +105,7 @@ class FormatInterface {
|
|
|
105
105
|
* @param {String} encoded
|
|
106
106
|
*/
|
|
107
107
|
fromBs32(encoded) {
|
|
108
|
-
this.encoded = bs32__default[
|
|
108
|
+
this.encoded = bs32__default["default"].decode(encoded);
|
|
109
109
|
this.decode();
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -113,7 +113,7 @@ class FormatInterface {
|
|
|
113
113
|
* @param {String} encoded
|
|
114
114
|
*/
|
|
115
115
|
fromBs58(encoded) {
|
|
116
|
-
this.encoded = bs58__default[
|
|
116
|
+
this.encoded = bs58__default["default"].decode(encoded);
|
|
117
117
|
this.decode();
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -130,7 +130,7 @@ class FormatInterface {
|
|
|
130
130
|
*/
|
|
131
131
|
toBs32() {
|
|
132
132
|
if (!this.encoded) this.encode();
|
|
133
|
-
return bs32__default[
|
|
133
|
+
return bs32__default["default"].encode(this.encoded)
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/**
|
|
@@ -138,7 +138,7 @@ class FormatInterface {
|
|
|
138
138
|
*/
|
|
139
139
|
toBs58() {
|
|
140
140
|
if (!this.encoded) this.encode();
|
|
141
|
-
return bs58__default[
|
|
141
|
+
return bs58__default["default"].encode(this.encoded)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/**
|
package/dist/commonjs/codec.js
CHANGED
|
@@ -5,7 +5,7 @@ require('bs32');
|
|
|
5
5
|
var codecFormatInterface = require('./codec-format-interface.js');
|
|
6
6
|
require('bs58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-6367213c.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -29,7 +29,7 @@ class DHTMessageResponse extends codecFormatInterface {
|
|
|
29
29
|
|
|
30
30
|
constructor(data) {
|
|
31
31
|
const name = 'peernet-dht-response';
|
|
32
|
-
super(data, protons__default[
|
|
32
|
+
super(data, protons__default["default"](proto).PeernetDHTMessageResponse, {name});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
package/dist/commonjs/dht.js
CHANGED
|
@@ -5,7 +5,7 @@ var codecFormatInterface = require('./codec-format-interface.js');
|
|
|
5
5
|
require('bs32');
|
|
6
6
|
require('bs58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-6367213c.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -40,7 +40,7 @@ class DHTMessage extends codecFormatInterface {
|
|
|
40
40
|
|
|
41
41
|
constructor(data) {
|
|
42
42
|
const name = 'peernet-dht';
|
|
43
|
-
super(data, protons__default[
|
|
43
|
+
super(data, protons__default["default"](proto).PeernetDHTMessage, {name});
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
package/dist/commonjs/hash.js
CHANGED
|
@@ -5,7 +5,7 @@ var varint = require('varint');
|
|
|
5
5
|
var bs32 = require('bs32');
|
|
6
6
|
var bs58 = require('bs58');
|
|
7
7
|
var isHex = require('is-hex');
|
|
8
|
-
var codec = require('./codec-
|
|
8
|
+
var codec = require('./codec-6367213c.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
11
|
|
|
@@ -34,8 +34,8 @@ class PeernetHash {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (typeof buffer === 'string') {
|
|
37
|
-
if (isHex__default[
|
|
38
|
-
if (bs32__default[
|
|
37
|
+
if (isHex__default["default"](buffer)) this.fromHex(buffer);
|
|
38
|
+
if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
|
|
39
39
|
else this.fromBs58(buffer);
|
|
40
40
|
} else if (typeof buffer === 'object') this.fromJSON(buffer);
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ class PeernetHash {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
get length() {
|
|
49
|
-
return Buffer.from(varint__default[
|
|
49
|
+
return Buffer.from(varint__default["default"].encode(this.size))
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
get buffer() {
|
|
@@ -66,19 +66,19 @@ class PeernetHash {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
toBs32() {
|
|
69
|
-
return bs32__default[
|
|
69
|
+
return bs32__default["default"].encode(this.hash)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
fromBs32(bs) {
|
|
73
|
-
return this.decode(bs32__default[
|
|
73
|
+
return this.decode(bs32__default["default"].decode(bs))
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
toBs58() {
|
|
77
|
-
return bs58__default[
|
|
77
|
+
return bs58__default["default"].encode(this.hash)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
fromBs58(bs) {
|
|
81
|
-
return this.decode(bs58__default[
|
|
81
|
+
return this.decode(bs58__default["default"].decode(bs))
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
toString(encoding = 'utf8') {
|
|
@@ -93,9 +93,9 @@ class PeernetHash {
|
|
|
93
93
|
let hashAlg = this.discoCodec.hashAlg;
|
|
94
94
|
if (hashAlg.includes('dbl')) {
|
|
95
95
|
hashAlg = hashAlg.replace('dbl-', '');
|
|
96
|
-
buffer = createKeccakHash__default[
|
|
96
|
+
buffer = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
|
|
97
97
|
}
|
|
98
|
-
this.digest = createKeccakHash__default[
|
|
98
|
+
this.digest = createKeccakHash__default["default"](hashAlg.replace('-', '')).update(buffer).digest();
|
|
99
99
|
this.size = this.digest.length;
|
|
100
100
|
|
|
101
101
|
this.codec = this.discoCodec.encode();
|
|
@@ -110,7 +110,7 @@ class PeernetHash {
|
|
|
110
110
|
|
|
111
111
|
validate(buffer) {
|
|
112
112
|
if (Buffer.isBuffer(buffer)) {
|
|
113
|
-
const codec = varint__default[
|
|
113
|
+
const codec = varint__default["default"].decode(buffer);
|
|
114
114
|
if (this.codecs[codec]) {
|
|
115
115
|
this.decode(buffer);
|
|
116
116
|
} else {
|
|
@@ -118,21 +118,21 @@ class PeernetHash {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
if (typeof buffer === 'string') {
|
|
121
|
-
if (isHex__default[
|
|
122
|
-
if (bs32__default[
|
|
121
|
+
if (isHex__default["default"](buffer)) this.fromHex(buffer);
|
|
122
|
+
if (bs32__default["default"].test(buffer)) this.fromBs32(buffer);
|
|
123
123
|
}
|
|
124
124
|
if (typeof buffer === 'object') this.fromJSON(buffer);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
decode(buffer) {
|
|
128
128
|
this.hash = buffer;
|
|
129
|
-
const codec$1 = varint__default[
|
|
129
|
+
const codec$1 = varint__default["default"].decode(buffer);
|
|
130
130
|
|
|
131
131
|
this.discoCodec = new codec.PeernetCodec(codec$1, this.codecs);
|
|
132
132
|
// TODO: validate codec
|
|
133
|
-
buffer = buffer.slice(varint__default[
|
|
134
|
-
this.size = varint__default[
|
|
135
|
-
this.digest = buffer.slice(varint__default[
|
|
133
|
+
buffer = buffer.slice(varint__default["default"].decode.bytes);
|
|
134
|
+
this.size = varint__default["default"].decode(buffer);
|
|
135
|
+
this.digest = buffer.slice(varint__default["default"].decode.bytes);
|
|
136
136
|
if (this.digest.length !== this.size) {
|
|
137
137
|
throw new Error(`hash length inconsistent: 0x${this.hash.toString('hex')}`)
|
|
138
138
|
}
|
|
@@ -5,7 +5,7 @@ var codecFormatInterface = require('./codec-format-interface.js');
|
|
|
5
5
|
require('bs32');
|
|
6
6
|
require('bs58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-6367213c.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -31,7 +31,7 @@ class PeernetMessage extends codecFormatInterface {
|
|
|
31
31
|
|
|
32
32
|
constructor(buffer) {
|
|
33
33
|
const name = 'peernet-message';
|
|
34
|
-
super(buffer, protons__default[
|
|
34
|
+
super(buffer, protons__default["default"](proto).PeernetMessage, {name});
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -15,7 +15,7 @@ var codecFormatInterface = require('./codec-format-interface.js');
|
|
|
15
15
|
var request = require('./request.js');
|
|
16
16
|
var response = require('./response.js');
|
|
17
17
|
var fetch$1 = require('node-fetch');
|
|
18
|
-
var codec = require('./codec-
|
|
18
|
+
var codec = require('./codec-6367213c.js');
|
|
19
19
|
var hash = require('./hash.js');
|
|
20
20
|
var MultiWallet = require('@leofcoin/multi-wallet');
|
|
21
21
|
require('bs32');
|
|
@@ -110,7 +110,7 @@ class PeernetPeer {
|
|
|
110
110
|
*/
|
|
111
111
|
globalThis.connections = new Map();
|
|
112
112
|
globalThis.recentConnections = new Map();
|
|
113
|
-
globalThis.pubsub = globalThis.pubsub || new PubSub__default[
|
|
113
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub__default["default"]({verbose: false});
|
|
114
114
|
|
|
115
115
|
class PeernetClient {
|
|
116
116
|
constructor(options = {}) {
|
|
@@ -119,14 +119,14 @@ class PeernetClient {
|
|
|
119
119
|
if (!options.networkName) options.networkName = 'peernet';
|
|
120
120
|
this.id = options.id;
|
|
121
121
|
|
|
122
|
-
this.topic = Buffer.from(sha256__default[
|
|
122
|
+
this.topic = Buffer.from(sha256__default["default"](`${options.networkName}-${options.networkVersion}`).toString());
|
|
123
123
|
|
|
124
124
|
const trackers = [
|
|
125
125
|
'wss://star.leofcoin.org',
|
|
126
126
|
'wss://tracker.openwebtorrent.com',
|
|
127
127
|
// 'wss://tracker.sloppyta.co:443/announce',
|
|
128
128
|
];
|
|
129
|
-
this.p2p = new P2P__default[
|
|
129
|
+
this.p2p = new P2P__default["default"](trackers, this.topic.slice(0, 20));
|
|
130
130
|
this.p2p.on('peerconnect', (peer) => {
|
|
131
131
|
peer = new PeernetPeer(peer.id, peer);
|
|
132
132
|
connections.set(peer.id, peer);
|
|
@@ -172,7 +172,7 @@ class PeernetClient {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
var version = "0.10.
|
|
175
|
+
var version = "0.10.7";
|
|
176
176
|
|
|
177
177
|
var api$1 = {
|
|
178
178
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -340,7 +340,7 @@ const socketRequestServer = (options, routes = {}) => {
|
|
|
340
340
|
// else if (!options && !routes) return console.error('no routes defined');
|
|
341
341
|
|
|
342
342
|
let {httpServer, httpsServer, port, protocol, credentials, origin, pubsub } = options;
|
|
343
|
-
if (!pubsub) pubsub = new PubSub__default[
|
|
343
|
+
if (!pubsub) pubsub = new PubSub__default["default"]({verbose: false});
|
|
344
344
|
if (!port) port = 6000;
|
|
345
345
|
const connections = [];
|
|
346
346
|
let connection;
|
|
@@ -465,7 +465,7 @@ var http = (config = {}) => {
|
|
|
465
465
|
if (!config.port) config.port = 2000;
|
|
466
466
|
if (!config.host) config.host = '127.0.0.1';
|
|
467
467
|
|
|
468
|
-
const app = new Koa__default[
|
|
468
|
+
const app = new Koa__default["default"]();
|
|
469
469
|
|
|
470
470
|
app.use(async (ctx) => {
|
|
471
471
|
const url = ctx.url.split('/api/')[1];
|
|
@@ -607,7 +607,7 @@ var clientApi = _pubsub => {
|
|
|
607
607
|
|
|
608
608
|
const socketRequestClient = (url, protocols = 'echo-protocol', options = { retry: false, pubsub: false }) => {
|
|
609
609
|
let { pubsub, retry } = options;
|
|
610
|
-
if (!pubsub) pubsub = new PubSub__default[
|
|
610
|
+
if (!pubsub) pubsub = new PubSub__default["default"]({verbose: false});
|
|
611
611
|
|
|
612
612
|
const api = clientApi(pubsub);
|
|
613
613
|
|
|
@@ -846,7 +846,7 @@ class DataMessage extends codecFormatInterface {
|
|
|
846
846
|
* @param {Buffer|String|Object|DataMessage} data - The data needed to create the DataMessage
|
|
847
847
|
*/
|
|
848
848
|
constructor(data) {
|
|
849
|
-
super(data, protons__default[
|
|
849
|
+
super(data, protons__default["default"](proto$5).PeernetDataMessage, {name: 'peernet-data'});
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
852
|
|
|
@@ -864,7 +864,7 @@ class PsMessage extends codecFormatInterface {
|
|
|
864
864
|
|
|
865
865
|
constructor(buffer) {
|
|
866
866
|
const name = 'peernet-ps';
|
|
867
|
-
super(buffer, protons__default[
|
|
867
|
+
super(buffer, protons__default["default"](proto$4).PsMessage, {name});
|
|
868
868
|
}
|
|
869
869
|
}
|
|
870
870
|
|
|
@@ -882,7 +882,7 @@ class PeerMessage extends codecFormatInterface {
|
|
|
882
882
|
|
|
883
883
|
constructor(data) {
|
|
884
884
|
const name = 'peernet-peer';
|
|
885
|
-
super(data, protons__default[
|
|
885
|
+
super(data, protons__default["default"](proto$3).PeernetPeerMessage, {name});
|
|
886
886
|
}
|
|
887
887
|
}
|
|
888
888
|
|
|
@@ -900,7 +900,7 @@ class PeerMessageResponse extends codecFormatInterface {
|
|
|
900
900
|
|
|
901
901
|
constructor(data) {
|
|
902
902
|
const name = 'peernet-peer-response';
|
|
903
|
-
super(data, protons__default[
|
|
903
|
+
super(data, protons__default["default"](proto$2).PeernetPeerMessageResponse, {name});
|
|
904
904
|
}
|
|
905
905
|
}
|
|
906
906
|
|
|
@@ -919,7 +919,7 @@ class DataMessageResponse extends codecFormatInterface {
|
|
|
919
919
|
|
|
920
920
|
constructor(data) {
|
|
921
921
|
const name = 'peernet-data-response';
|
|
922
|
-
super(data, protons__default[
|
|
922
|
+
super(data, protons__default["default"](proto$1).PeernetDataMessageResponse, {name});
|
|
923
923
|
}
|
|
924
924
|
}
|
|
925
925
|
|
|
@@ -938,7 +938,7 @@ class ChatMessage extends codecFormatInterface {
|
|
|
938
938
|
|
|
939
939
|
constructor(buffer) {
|
|
940
940
|
const name = 'chat-message';
|
|
941
|
-
super(buffer, protons__default[
|
|
941
|
+
super(buffer, protons__default["default"](proto).ChatMessage, {name});
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
944
|
|
|
@@ -961,7 +961,7 @@ const protoFor = (data) => {
|
|
|
961
961
|
*/
|
|
962
962
|
const hasDaemon = async () => {
|
|
963
963
|
try {
|
|
964
|
-
let response = await fetch__default[
|
|
964
|
+
let response = await fetch__default["default"]('http://127.0.0.1:1000/api/version');
|
|
965
965
|
response = await response.json();
|
|
966
966
|
return Boolean(response.client === '@peernet/api/http')
|
|
967
967
|
} catch (e) {
|
|
@@ -1097,7 +1097,7 @@ const getAddress = async () => {
|
|
|
1097
1097
|
const {address} = lastFetched;
|
|
1098
1098
|
const now = Math.round(new Date().getTime() / 1000);
|
|
1099
1099
|
if (now - address.timestamp > 1200000) {
|
|
1100
|
-
address.value = await fetch__default[
|
|
1100
|
+
address.value = await fetch__default["default"]('https://icanhazip.com/');
|
|
1101
1101
|
address.value = await address.value.text();
|
|
1102
1102
|
address.timestamp = Math.round(new Date().getTime() / 1000);
|
|
1103
1103
|
lastFetched.address = address;
|
|
@@ -1139,7 +1139,7 @@ class DhtEarth {
|
|
|
1139
1139
|
async getCoordinates(address) {
|
|
1140
1140
|
// const {address} = parseAddress(provider)
|
|
1141
1141
|
const request = `https://whereis.leofcoin.org/?ip=${address}`;
|
|
1142
|
-
let response = await fetch__default[
|
|
1142
|
+
let response = await fetch__default["default"](request);
|
|
1143
1143
|
response = await response.json();
|
|
1144
1144
|
const {lat, lon} = response;
|
|
1145
1145
|
return {latitude: lat, longitude: lon}
|
|
@@ -1202,7 +1202,7 @@ class DhtEarth {
|
|
|
1202
1202
|
* @return {object} { identity, accounts, config }
|
|
1203
1203
|
*/
|
|
1204
1204
|
var generateAccount = async network => {
|
|
1205
|
-
const wallet = new MultiWallet__default[
|
|
1205
|
+
const wallet = new MultiWallet__default["default"](network);
|
|
1206
1206
|
/**
|
|
1207
1207
|
* @type {string}
|
|
1208
1208
|
*/
|
|
@@ -1255,7 +1255,7 @@ class MessageHandler {
|
|
|
1255
1255
|
const hasher = new hash(message, {name: 'peernet-message'});
|
|
1256
1256
|
const identity = await walletStore.get('identity');
|
|
1257
1257
|
|
|
1258
|
-
const wallet = new MultiWallet__default[
|
|
1258
|
+
const wallet = new MultiWallet__default["default"](this.network);
|
|
1259
1259
|
wallet.import(identity.multiWIF);
|
|
1260
1260
|
return wallet.sign(hasher.hash.slice(0, 32))
|
|
1261
1261
|
}
|
|
@@ -1300,7 +1300,7 @@ const nothingFoundError = (hash) => {
|
|
|
1300
1300
|
};
|
|
1301
1301
|
|
|
1302
1302
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
1303
|
-
globalThis.globalSub = globalThis.globalSub || new PubSub__default[
|
|
1303
|
+
globalThis.globalSub = globalThis.globalSub || new PubSub__default["default"]({verbose: true});
|
|
1304
1304
|
|
|
1305
1305
|
/**
|
|
1306
1306
|
* @access public
|
|
@@ -1362,7 +1362,7 @@ class Peernet {
|
|
|
1362
1362
|
if (this.hasDaemon) {
|
|
1363
1363
|
Storage = LeofcoinStorageClient;
|
|
1364
1364
|
} else {
|
|
1365
|
-
Storage = LeofcoinStorage__default[
|
|
1365
|
+
Storage = LeofcoinStorage__default["default"];
|
|
1366
1366
|
}
|
|
1367
1367
|
globalThis[`${name}Store`] = globalThis[`${name}Store`] ||
|
|
1368
1368
|
await new Storage(`${prefix}-${name}`, root);
|
|
@@ -1617,11 +1617,10 @@ class Peernet {
|
|
|
1617
1617
|
} else if (proto.name === 'peernet-data') {
|
|
1618
1618
|
let { hash, store } = proto.decoded;
|
|
1619
1619
|
let data;
|
|
1620
|
-
|
|
1621
1620
|
if (!store) {
|
|
1622
1621
|
store = await this.whichStore([...this.stores], hash);
|
|
1623
1622
|
} else {
|
|
1624
|
-
store = globalThis
|
|
1623
|
+
store = globalThis[`${store}Store`];
|
|
1625
1624
|
}
|
|
1626
1625
|
if (store && !store.private) {
|
|
1627
1626
|
data = await store.get(hash);
|
|
@@ -1769,7 +1768,7 @@ class Peernet {
|
|
|
1769
1768
|
// get closest peer on earth
|
|
1770
1769
|
const closestPeer = await this.dht.closestPeer(providers);
|
|
1771
1770
|
// get peer instance by id
|
|
1772
|
-
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store)
|
|
1771
|
+
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store.name ? store.name : store)
|
|
1773
1772
|
|
|
1774
1773
|
const id = closestPeer.id.toString();
|
|
1775
1774
|
if (this.peers) {
|
|
@@ -1777,7 +1776,7 @@ class Peernet {
|
|
|
1777
1776
|
if (this._getPeerId(peer.id) === id) return peer
|
|
1778
1777
|
});
|
|
1779
1778
|
|
|
1780
|
-
let data = new DataMessage({hash, store});
|
|
1779
|
+
let data = new DataMessage({hash, store: store.name ? store.name : store});
|
|
1781
1780
|
|
|
1782
1781
|
const node = await this.prepareMessage(id, data.encoded);
|
|
1783
1782
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
@@ -1884,7 +1883,7 @@ class Peernet {
|
|
|
1884
1883
|
if (store && await store.has(hash)) data = await store.get(hash);
|
|
1885
1884
|
if (data) return data
|
|
1886
1885
|
|
|
1887
|
-
return this.requestData(hash, store)
|
|
1886
|
+
return this.requestData(hash, store.name ? store.name : store)
|
|
1888
1887
|
}
|
|
1889
1888
|
|
|
1890
1889
|
/**
|
package/dist/commonjs/request.js
CHANGED
|
@@ -5,7 +5,7 @@ var codecFormatInterface = require('./codec-format-interface.js');
|
|
|
5
5
|
require('bs32');
|
|
6
6
|
require('bs58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-6367213c.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -28,7 +28,7 @@ class RequestMessage extends codecFormatInterface {
|
|
|
28
28
|
|
|
29
29
|
constructor(data) {
|
|
30
30
|
const name = 'peernet-request';
|
|
31
|
-
super(data, protons__default[
|
|
31
|
+
super(data, protons__default["default"](proto).PeernetRequestMessage, {name});
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -5,7 +5,7 @@ var codecFormatInterface = require('./codec-format-interface.js');
|
|
|
5
5
|
require('bs32');
|
|
6
6
|
require('bs58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-6367213c.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -28,7 +28,7 @@ class ResponseMessage extends codecFormatInterface {
|
|
|
28
28
|
|
|
29
29
|
constructor(data) {
|
|
30
30
|
const name = 'peernet-response';
|
|
31
|
-
super(data, protons__default[
|
|
31
|
+
super(data, protons__default["default"](proto).PeernetResponseMessage, {name});
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|