@leofcoin/peernet 0.12.0 → 0.12.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.
@@ -1067,12 +1067,12 @@ class PeerDiscovery {
1067
1067
  async discover(peer) {
1068
1068
  let id = this._getPeerId(peer.id);
1069
1069
  if (id) return id
1070
- const data = new peernet.protos['peernet-peer']({id: this.id});
1070
+ const data = await new peernet.protos['peernet-peer']({id: this.id});
1071
1071
  const node = await peernet.prepareMessage(peer.id, data.encoded);
1072
1072
 
1073
1073
  let response = await peer.request(node.encoded);
1074
- response = protoFor(response);
1075
- response = new peernet.protos['peernet-peer-response'](response.decoded.data);
1074
+ response = await protoFor(response);
1075
+ response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
1076
1076
 
1077
1077
  id = response.decoded.id;
1078
1078
  if (id === this.id) return;
@@ -1103,7 +1103,7 @@ class PeerDiscovery {
1103
1103
  peernet.peerMap.set(from, connections);
1104
1104
  }
1105
1105
  }
1106
- const data = new peernet.protos['peernet-peer-response']({id: this.id});
1106
+ const data = await new peernet.protos['peernet-peer-response']({id: this.id});
1107
1107
  const node = await peernet.prepareMessage(from, data.encoded);
1108
1108
 
1109
1109
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
@@ -1802,7 +1802,7 @@ class MessageHandler {
1802
1802
  data,
1803
1803
  };
1804
1804
  const signature = await this.hashAndSignMessage(message);
1805
- const node = new PeernetMessage({
1805
+ const node = await new PeernetMessage({
1806
1806
  ...message,
1807
1807
  signature,
1808
1808
  });
@@ -1816,8 +1816,8 @@ const dataHandler = async message => {
1816
1816
 
1817
1817
  const {data, id} = message;
1818
1818
 
1819
- message = protoFor(data);
1820
- const proto = protoFor(message.decoded.data);
1819
+ message = await protoFor(data);
1820
+ const proto = await protoFor(message.decoded.data);
1821
1821
  const from = message.decoded.from;
1822
1822
 
1823
1823
  peernet._protoHandler({id, proto}, peernet.client.connections[from], from);
@@ -1883,6 +1883,14 @@ class Peernet {
1883
1883
  return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
1884
1884
  }
1885
1885
 
1886
+ get protos() {
1887
+ return globalThis.peernet.protos
1888
+ }
1889
+
1890
+ get codecs() {
1891
+ return codecFormatInterface.codecs
1892
+ }
1893
+
1886
1894
  addProto(name, proto) {
1887
1895
  if (!this.protos[name]) this.protos[name] = proto;
1888
1896
  }
@@ -1987,16 +1995,11 @@ class Peernet {
1987
1995
  'chat-message': ChatMessage,
1988
1996
  };
1989
1997
 
1990
- this.protos = globalThis.peernet.protos;
1991
- this.codecs = codecFormatInterface.codecs;
1992
-
1993
1998
  this._messageHandler = new MessageHandler(this.network);
1994
1999
 
1995
2000
  const {daemon, environment} = await target();
1996
2001
  this.hasDaemon = daemon;
1997
2002
 
1998
-
1999
-
2000
2003
  for (const store of this.defaultStores) {
2001
2004
  await this.addStore(store, options.storePrefix, options.root);
2002
2005
  }
@@ -2092,7 +2095,7 @@ class Peernet {
2092
2095
  if (store.private) has = false;
2093
2096
  else has = await store.has(hash);
2094
2097
  }
2095
- const data = new DHTMessageResponse({hash, has});
2098
+ const data = await new DHTMessageResponse({hash, has});
2096
2099
  const node = await this.prepareMessage(from, data.encoded);
2097
2100
 
2098
2101
  this.sendMessage(peer, id, node.encoded);
@@ -2108,7 +2111,7 @@ class Peernet {
2108
2111
  data = await store.get(hash);
2109
2112
 
2110
2113
  if (data) {
2111
- data = new DataMessageResponse({hash, data});
2114
+ data = await new DataMessageResponse({hash, data});
2112
2115
 
2113
2116
  const node = await this.prepareMessage(from, data.encoded);
2114
2117
  this.sendMessage(peer, id, node.encoded);
@@ -2135,16 +2138,16 @@ class Peernet {
2135
2138
  */
2136
2139
  async walk(hash) {
2137
2140
  if (!hash) throw new Error('hash expected, received undefined')
2138
- const data = new DHTMessage({hash});
2141
+ const data = await new DHTMessage({hash});
2139
2142
  this.client.id;
2140
2143
  const walk = async peer => {
2141
2144
  const node = await this.prepareMessage(peer.peerId, data.encoded);
2142
2145
  let result = await peer.request(node.encoded);
2143
2146
  result = new Uint8Array(Object.values(result));
2144
- let proto = protoFor(result);
2147
+ let proto = await protoFor(result);
2145
2148
  if (proto.name !== 'peernet-message') throw encapsulatedError()
2146
2149
  const from = proto.decoded.from;
2147
- proto = protoFor(proto.decoded.data);
2150
+ proto = await protoFor(proto.decoded.data);
2148
2151
  if (proto.name !== 'peernet-dht-response') throw dhtError(proto.name)
2149
2152
 
2150
2153
  // TODO: give ip and port (just used for location)
@@ -2243,7 +2246,7 @@ class Peernet {
2243
2246
  if (peer.peerId === id) return peer
2244
2247
  });
2245
2248
 
2246
- let data = new DataMessage({hash, store: store?.name ? store?.name : store});
2249
+ let data = await new DataMessage({hash, store: store?.name ? store?.name : store});
2247
2250
 
2248
2251
  const node = await this.prepareMessage(id, data.encoded);
2249
2252
  if (closest[0]) data = await closest[0].request(node.encoded);
@@ -2254,8 +2257,8 @@ class Peernet {
2254
2257
  if (closest[0]) data = await closest[0].request(node.encoded);
2255
2258
  }
2256
2259
  data = new Uint8Array(Object.values(data));
2257
- let proto = protoFor(data);
2258
- proto = protoFor(proto.decoded.data);
2260
+ let proto = await protoFor(data);
2261
+ proto = await protoFor(proto.decoded.data);
2259
2262
  // TODO: store data automaticly or not
2260
2263
  return proto.decoded.data
2261
2264
 
@@ -2388,7 +2391,7 @@ class Peernet {
2388
2391
  if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic);
2389
2392
  if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
2390
2393
  const id = Math.random().toString(36).slice(-12);
2391
- data = new PsMessage({data, topic});
2394
+ data = await new PsMessage({data, topic});
2392
2395
  for (const peer of this.connections) {
2393
2396
  if (peer.peerId !== this.peerId) {
2394
2397
  const node = await this.prepareMessage(peer.peerId, data.encoded);
@@ -2443,7 +2446,46 @@ __webpack_require__.r(__webpack_exports__);
2443
2446
 
2444
2447
  // EXPORTS
2445
2448
  __webpack_require__.d(__webpack_exports__, {
2446
- "default": function() { return /* binding */ src; }
2449
+ "BasicInterface": function() { return /* reexport */ basic_interface_namespaceObject; },
2450
+ "Codec": function() { return /* reexport */ codec_namespaceObject; },
2451
+ "CodecHash": function() { return /* reexport */ codec_hash_namespaceObject; },
2452
+ "FormatInterface": function() { return /* reexport */ codec_format_interface_namespaceObject; },
2453
+ "codecs": function() { return /* reexport */ codecs_namespaceObject; }
2454
+ });
2455
+
2456
+ // NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/basic-interface.js
2457
+ var basic_interface_namespaceObject = {};
2458
+ __webpack_require__.r(basic_interface_namespaceObject);
2459
+ __webpack_require__.d(basic_interface_namespaceObject, {
2460
+ "default": function() { return BasicInterface; }
2461
+ });
2462
+
2463
+ // NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codecs.js
2464
+ var codecs_namespaceObject = {};
2465
+ __webpack_require__.r(codecs_namespaceObject);
2466
+ __webpack_require__.d(codecs_namespaceObject, {
2467
+ "default": function() { return codecs; }
2468
+ });
2469
+
2470
+ // NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codec.js
2471
+ var codec_namespaceObject = {};
2472
+ __webpack_require__.r(codec_namespaceObject);
2473
+ __webpack_require__.d(codec_namespaceObject, {
2474
+ "default": function() { return PeernetCodec; }
2475
+ });
2476
+
2477
+ // NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codec-hash.js
2478
+ var codec_hash_namespaceObject = {};
2479
+ __webpack_require__.r(codec_hash_namespaceObject);
2480
+ __webpack_require__.d(codec_hash_namespaceObject, {
2481
+ "default": function() { return CodecHash; }
2482
+ });
2483
+
2484
+ // NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codec-format-interface.js
2485
+ var codec_format_interface_namespaceObject = {};
2486
+ __webpack_require__.r(codec_format_interface_namespaceObject);
2487
+ __webpack_require__.d(codec_format_interface_namespaceObject, {
2488
+ "default": function() { return FormatInterface; }
2447
2489
  });
2448
2490
 
2449
2491
  // EXTERNAL MODULE: ./node_modules/@vandeurenglenn/base32/src/base32.js
@@ -3011,8 +3053,6 @@ class FormatInterface extends BasicInterface {
3011
3053
 
3012
3054
 
3013
3055
 
3014
-
3015
- /* harmony default export */ var src = ({ codecs: codecs, Codec: PeernetCodec, CodecHash: CodecHash, FormatInterface: FormatInterface, BasicInterface: BasicInterface });
3016
3056
 
3017
3057
 
3018
3058
  /***/ }),
@@ -939,12 +939,12 @@ class PeerDiscovery {
939
939
  async discover(peer) {
940
940
  let id = this._getPeerId(peer.id);
941
941
  if (id) return id
942
- const data = new peernet.protos['peernet-peer']({id: this.id});
942
+ const data = await new peernet.protos['peernet-peer']({id: this.id});
943
943
  const node = await peernet.prepareMessage(peer.id, data.encoded);
944
944
 
945
945
  let response = await peer.request(node.encoded);
946
- response = protoFor(response);
947
- response = new peernet.protos['peernet-peer-response'](response.decoded.data);
946
+ response = await protoFor(response);
947
+ response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
948
948
 
949
949
  id = response.decoded.id;
950
950
  if (id === this.id) return;
@@ -975,7 +975,7 @@ class PeerDiscovery {
975
975
  peernet.peerMap.set(from, connections);
976
976
  }
977
977
  }
978
- const data = new peernet.protos['peernet-peer-response']({id: this.id});
978
+ const data = await new peernet.protos['peernet-peer-response']({id: this.id});
979
979
  const node = await peernet.prepareMessage(from, data.encoded);
980
980
 
981
981
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
@@ -1674,7 +1674,7 @@ class MessageHandler {
1674
1674
  data,
1675
1675
  };
1676
1676
  const signature = await this.hashAndSignMessage(message);
1677
- const node = new peernetMessage({
1677
+ const node = await new peernetMessage({
1678
1678
  ...message,
1679
1679
  signature,
1680
1680
  });
@@ -1688,8 +1688,8 @@ const dataHandler = async message => {
1688
1688
 
1689
1689
  const {data, id} = message;
1690
1690
 
1691
- message = protoFor(data);
1692
- const proto = protoFor(message.decoded.data);
1691
+ message = await protoFor(data);
1692
+ const proto = await protoFor(message.decoded.data);
1693
1693
  const from = message.decoded.from;
1694
1694
 
1695
1695
  peernet._protoHandler({id, proto}, peernet.client.connections[from], from);
@@ -1755,6 +1755,14 @@ class Peernet {
1755
1755
  return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
1756
1756
  }
1757
1757
 
1758
+ get protos() {
1759
+ return globalThis.peernet.protos
1760
+ }
1761
+
1762
+ get codecs() {
1763
+ return codecFormatInterface.codecs
1764
+ }
1765
+
1758
1766
  addProto(name, proto) {
1759
1767
  if (!this.protos[name]) this.protos[name] = proto;
1760
1768
  }
@@ -1859,16 +1867,11 @@ class Peernet {
1859
1867
  'chat-message': ChatMessage,
1860
1868
  };
1861
1869
 
1862
- this.protos = globalThis.peernet.protos;
1863
- this.codecs = codecFormatInterface.codecs;
1864
-
1865
1870
  this._messageHandler = new MessageHandler(this.network);
1866
1871
 
1867
1872
  const {daemon, environment} = await target();
1868
1873
  this.hasDaemon = daemon;
1869
1874
 
1870
-
1871
-
1872
1875
  for (const store of this.defaultStores) {
1873
1876
  await this.addStore(store, options.storePrefix, options.root);
1874
1877
  }
@@ -1964,7 +1967,7 @@ class Peernet {
1964
1967
  if (store.private) has = false;
1965
1968
  else has = await store.has(hash);
1966
1969
  }
1967
- const data = new dhtResponse({hash, has});
1970
+ const data = await new dhtResponse({hash, has});
1968
1971
  const node = await this.prepareMessage(from, data.encoded);
1969
1972
 
1970
1973
  this.sendMessage(peer, id, node.encoded);
@@ -1980,7 +1983,7 @@ class Peernet {
1980
1983
  data = await store.get(hash);
1981
1984
 
1982
1985
  if (data) {
1983
- data = new DataMessageResponse({hash, data});
1986
+ data = await new DataMessageResponse({hash, data});
1984
1987
 
1985
1988
  const node = await this.prepareMessage(from, data.encoded);
1986
1989
  this.sendMessage(peer, id, node.encoded);
@@ -2007,16 +2010,16 @@ class Peernet {
2007
2010
  */
2008
2011
  async walk(hash) {
2009
2012
  if (!hash) throw new Error('hash expected, received undefined')
2010
- const data = new dht({hash});
2013
+ const data = await new dht({hash});
2011
2014
  this.client.id;
2012
2015
  const walk = async peer => {
2013
2016
  const node = await this.prepareMessage(peer.peerId, data.encoded);
2014
2017
  let result = await peer.request(node.encoded);
2015
2018
  result = new Uint8Array(Object.values(result));
2016
- let proto = protoFor(result);
2019
+ let proto = await protoFor(result);
2017
2020
  if (proto.name !== 'peernet-message') throw encapsulatedError()
2018
2021
  const from = proto.decoded.from;
2019
- proto = protoFor(proto.decoded.data);
2022
+ proto = await protoFor(proto.decoded.data);
2020
2023
  if (proto.name !== 'peernet-dht-response') throw dhtError(proto.name)
2021
2024
 
2022
2025
  // TODO: give ip and port (just used for location)
@@ -2115,7 +2118,7 @@ class Peernet {
2115
2118
  if (peer.peerId === id) return peer
2116
2119
  });
2117
2120
 
2118
- let data = new DataMessage({hash, store: store?.name ? store?.name : store});
2121
+ let data = await new DataMessage({hash, store: store?.name ? store?.name : store});
2119
2122
 
2120
2123
  const node = await this.prepareMessage(id, data.encoded);
2121
2124
  if (closest[0]) data = await closest[0].request(node.encoded);
@@ -2126,8 +2129,8 @@ class Peernet {
2126
2129
  if (closest[0]) data = await closest[0].request(node.encoded);
2127
2130
  }
2128
2131
  data = new Uint8Array(Object.values(data));
2129
- let proto = protoFor(data);
2130
- proto = protoFor(proto.decoded.data);
2132
+ let proto = await protoFor(data);
2133
+ proto = await protoFor(proto.decoded.data);
2131
2134
  // TODO: store data automaticly or not
2132
2135
  return proto.decoded.data
2133
2136
 
@@ -2260,7 +2263,7 @@ class Peernet {
2260
2263
  if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic);
2261
2264
  if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
2262
2265
  const id = Math.random().toString(36).slice(-12);
2263
- data = new PsMessage({data, topic});
2266
+ data = await new PsMessage({data, topic});
2264
2267
  for (const peer of this.connections) {
2265
2268
  if (peer.peerId !== this.peerId) {
2266
2269
  const node = await this.prepareMessage(peer.peerId, data.encoded);
@@ -1024,12 +1024,12 @@ class PeerDiscovery {
1024
1024
  async discover(peer) {
1025
1025
  let id = this._getPeerId(peer.id);
1026
1026
  if (id) return id
1027
- const data = new peernet.protos['peernet-peer']({id: this.id});
1027
+ const data = await new peernet.protos['peernet-peer']({id: this.id});
1028
1028
  const node = await peernet.prepareMessage(peer.id, data.encoded);
1029
1029
 
1030
1030
  let response = await peer.request(node.encoded);
1031
- response = protoFor(response);
1032
- response = new peernet.protos['peernet-peer-response'](response.decoded.data);
1031
+ response = await protoFor(response);
1032
+ response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
1033
1033
 
1034
1034
  id = response.decoded.id;
1035
1035
  if (id === this.id) return;
@@ -1060,7 +1060,7 @@ class PeerDiscovery {
1060
1060
  peernet.peerMap.set(from, connections);
1061
1061
  }
1062
1062
  }
1063
- const data = new peernet.protos['peernet-peer-response']({id: this.id});
1063
+ const data = await new peernet.protos['peernet-peer-response']({id: this.id});
1064
1064
  const node = await peernet.prepareMessage(from, data.encoded);
1065
1065
 
1066
1066
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
@@ -1759,7 +1759,7 @@ class MessageHandler {
1759
1759
  data,
1760
1760
  };
1761
1761
  const signature = await this.hashAndSignMessage(message);
1762
- const node = new PeernetMessage({
1762
+ const node = await new PeernetMessage({
1763
1763
  ...message,
1764
1764
  signature,
1765
1765
  });
@@ -1773,8 +1773,8 @@ const dataHandler = async message => {
1773
1773
 
1774
1774
  const {data, id} = message;
1775
1775
 
1776
- message = protoFor(data);
1777
- const proto = protoFor(message.decoded.data);
1776
+ message = await protoFor(data);
1777
+ const proto = await protoFor(message.decoded.data);
1778
1778
  const from = message.decoded.from;
1779
1779
 
1780
1780
  peernet._protoHandler({id, proto}, peernet.client.connections[from], from);
@@ -1840,6 +1840,14 @@ class Peernet {
1840
1840
  return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
1841
1841
  }
1842
1842
 
1843
+ get protos() {
1844
+ return globalThis.peernet.protos
1845
+ }
1846
+
1847
+ get codecs() {
1848
+ return codecs
1849
+ }
1850
+
1843
1851
  addProto(name, proto) {
1844
1852
  if (!this.protos[name]) this.protos[name] = proto;
1845
1853
  }
@@ -1944,16 +1952,11 @@ class Peernet {
1944
1952
  'chat-message': ChatMessage,
1945
1953
  };
1946
1954
 
1947
- this.protos = globalThis.peernet.protos;
1948
- this.codecs = codecs;
1949
-
1950
1955
  this._messageHandler = new MessageHandler(this.network);
1951
1956
 
1952
1957
  const {daemon, environment} = await target();
1953
1958
  this.hasDaemon = daemon;
1954
1959
 
1955
-
1956
-
1957
1960
  for (const store of this.defaultStores) {
1958
1961
  await this.addStore(store, options.storePrefix, options.root);
1959
1962
  }
@@ -2049,7 +2052,7 @@ class Peernet {
2049
2052
  if (store.private) has = false;
2050
2053
  else has = await store.has(hash);
2051
2054
  }
2052
- const data = new DHTMessageResponse({hash, has});
2055
+ const data = await new DHTMessageResponse({hash, has});
2053
2056
  const node = await this.prepareMessage(from, data.encoded);
2054
2057
 
2055
2058
  this.sendMessage(peer, id, node.encoded);
@@ -2065,7 +2068,7 @@ class Peernet {
2065
2068
  data = await store.get(hash);
2066
2069
 
2067
2070
  if (data) {
2068
- data = new DataMessageResponse({hash, data});
2071
+ data = await new DataMessageResponse({hash, data});
2069
2072
 
2070
2073
  const node = await this.prepareMessage(from, data.encoded);
2071
2074
  this.sendMessage(peer, id, node.encoded);
@@ -2092,16 +2095,16 @@ class Peernet {
2092
2095
  */
2093
2096
  async walk(hash) {
2094
2097
  if (!hash) throw new Error('hash expected, received undefined')
2095
- const data = new DHTMessage({hash});
2098
+ const data = await new DHTMessage({hash});
2096
2099
  this.client.id;
2097
2100
  const walk = async peer => {
2098
2101
  const node = await this.prepareMessage(peer.peerId, data.encoded);
2099
2102
  let result = await peer.request(node.encoded);
2100
2103
  result = new Uint8Array(Object.values(result));
2101
- let proto = protoFor(result);
2104
+ let proto = await protoFor(result);
2102
2105
  if (proto.name !== 'peernet-message') throw encapsulatedError()
2103
2106
  const from = proto.decoded.from;
2104
- proto = protoFor(proto.decoded.data);
2107
+ proto = await protoFor(proto.decoded.data);
2105
2108
  if (proto.name !== 'peernet-dht-response') throw dhtError(proto.name)
2106
2109
 
2107
2110
  // TODO: give ip and port (just used for location)
@@ -2200,7 +2203,7 @@ class Peernet {
2200
2203
  if (peer.peerId === id) return peer
2201
2204
  });
2202
2205
 
2203
- let data = new DataMessage({hash, store: store?.name ? store?.name : store});
2206
+ let data = await new DataMessage({hash, store: store?.name ? store?.name : store});
2204
2207
 
2205
2208
  const node = await this.prepareMessage(id, data.encoded);
2206
2209
  if (closest[0]) data = await closest[0].request(node.encoded);
@@ -2211,8 +2214,8 @@ class Peernet {
2211
2214
  if (closest[0]) data = await closest[0].request(node.encoded);
2212
2215
  }
2213
2216
  data = new Uint8Array(Object.values(data));
2214
- let proto = protoFor(data);
2215
- proto = protoFor(proto.decoded.data);
2217
+ let proto = await protoFor(data);
2218
+ proto = await protoFor(proto.decoded.data);
2216
2219
  // TODO: store data automaticly or not
2217
2220
  return proto.decoded.data
2218
2221
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "",
5
5
  "main": "dist/commonjs/peernet.js",
6
6
  "module": "dist/module/peernet.js",
@@ -23,7 +23,7 @@
23
23
  "license": "MIT",
24
24
  "browserslist": "> 0.5%, last 2 versions, not dead",
25
25
  "dependencies": {
26
- "@leofcoin/codec-format-interface": "^1.1.0",
26
+ "@leofcoin/codec-format-interface": "^1.1.1",
27
27
  "@leofcoin/generate-account": "^1.0.2",
28
28
  "@leofcoin/multi-wallet": "^2.1.2",
29
29
  "@leofcoin/peernet-swarm": "^0.3.1",