@leofcoin/chain 1.4.57 → 1.4.58

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.
@@ -1,4 +1,4 @@
1
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-3d505e1f.js';
1
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-79442920.js';
2
2
  import './index-640d9f36.js';
3
3
 
4
4
  function commonjsRequire(path) {
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-3d505e1f.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-79442920.js';
2
2
  import './index-640d9f36.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-3d505e1f.js';
1
+ import { F as FormatInterface } from './node-browser-79442920.js';
2
2
  import './index-640d9f36.js';
3
3
 
4
4
  var proto$b = {
@@ -6309,16 +6309,13 @@ const distanceInKmBetweenEarthCoordinates = (lat1, lon1, lat2, lon2) => {
6309
6309
  return earthRadiusKm * c;
6310
6310
  };
6311
6311
  class DhtEarth {
6312
+ providerMap = new Map;
6312
6313
  /**
6313
6314
  *
6314
6315
  */
6315
6316
  constructor() {
6316
6317
  this.providerMap = new Map();
6317
6318
  }
6318
- /**
6319
- * @param {Object} address
6320
- * @return {Object} {latitude: lat, longitude: lon}
6321
- */
6322
6319
  async getCoordinates(address) {
6323
6320
  if (!fetchedCoordinates[address]) {
6324
6321
  const request = `https://whereis.leofcoin.org/?ip=${address}`;
@@ -6338,10 +6335,6 @@ class DhtEarth {
6338
6335
  const { latitude, longitude } = await this.getCoordinates(provider.address);
6339
6336
  return { provider, distance: distanceInKmBetweenEarthCoordinates(peer.latitude, peer.longitude, latitude, longitude) };
6340
6337
  }
6341
- /**
6342
- * @param {Array} providers
6343
- * @return {Object} closestPeer
6344
- */
6345
6338
  async closestPeer(providers) {
6346
6339
  let all = [];
6347
6340
  const address = await getAddress();
@@ -6356,26 +6349,32 @@ class DhtEarth {
6356
6349
  all = all.sort((previous, current) => previous.distance - current.distance);
6357
6350
  return all[0].provider;
6358
6351
  }
6359
- /**
6360
- * @param {String} hash
6361
- * @return {Array} providers
6362
- */
6363
- providersFor(hash) {
6364
- return this.providerMap.get(hash);
6352
+ hasProvider(hash) {
6353
+ return this.providerMap.has(hash);
6365
6354
  }
6366
- /**
6367
- * @param {String} address
6368
- * @param {String} hash
6369
- * @return {Array} providers
6370
- */
6371
- async addProvider(address, hash) {
6372
- let providers = [];
6355
+ providersFor(hash) {
6356
+ let providers;
6373
6357
  if (this.providerMap.has(hash))
6374
6358
  providers = this.providerMap.get(hash);
6375
- providers = new Set([...providers, address]);
6376
- this.providerMap.set(hash, providers);
6377
6359
  return providers;
6378
6360
  }
6361
+ addProvider(address, hash) {
6362
+ let providers = new Set();
6363
+ if (this.providerMap.has(hash)) {
6364
+ providers = this.providerMap.get(hash);
6365
+ }
6366
+ providers.add(address);
6367
+ this.providerMap.set(hash, providers);
6368
+ }
6369
+ removeProvider(address, hash) {
6370
+ let deleted = undefined;
6371
+ if (this.providerMap.has(hash)) {
6372
+ const providers = this.providerMap.get(hash);
6373
+ deleted = providers.delete(address);
6374
+ deleted && this.providerMap.set(hash, providers);
6375
+ }
6376
+ return deleted;
6377
+ }
6379
6378
  }
6380
6379
 
6381
6380
  class MessageHandler {
@@ -20267,7 +20266,7 @@ class Identity {
20267
20266
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20268
20267
  }
20269
20268
  else {
20270
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-904b9f85-2d6175c2.js');
20269
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-4464b87e-d39e42fc.js');
20271
20270
  const { identity, accounts } = await importee.default(password, this.network);
20272
20271
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20273
20272
  await globalThis.walletStore.put('version', String(1));
@@ -20438,7 +20437,7 @@ class Peernet {
20438
20437
  this.root = options.root;
20439
20438
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20440
20439
  // FolderMessageResponse
20441
- } = await import(/* webpackChunkName: "messages" */ './messages-de2c5670-d99ad896.js');
20440
+ } = await import(/* webpackChunkName: "messages" */ './messages-27279443-8ccccaf2.js');
20442
20441
  /**
20443
20442
  * proto Object containing protos
20444
20443
  * @type {Object}
@@ -20517,7 +20516,7 @@ class Peernet {
20517
20516
  if (this.#starting || this.#started)
20518
20517
  return;
20519
20518
  this.#starting = true;
20520
- const importee = await import('./client-d1c29e20-c5d45b87.js');
20519
+ const importee = await import('./client-4d80940e-a63ca03c.js');
20521
20520
  /**
20522
20521
  * @access public
20523
20522
  * @type {PeernetClient}
@@ -20707,8 +20706,8 @@ class Peernet {
20707
20706
  if (!closestPeer || !closestPeer.id)
20708
20707
  return this.requestData(hash, store?.name || store);
20709
20708
  const id = closestPeer.id;
20710
- if (this.#connections[id]) {
20711
- const peer = this.#connections[id];
20709
+ const peer = this.#connections[id];
20710
+ if (peer?.connected) {
20712
20711
  let data = await new globalThis.peernet.protos['peernet-data']({ hash, store: store?.name || store });
20713
20712
  const node = await this.prepareMessage(data);
20714
20713
  if (peer)
@@ -20731,6 +20730,9 @@ class Peernet {
20731
20730
  return BufferToUint8Array(proto.decoded.data);
20732
20731
  // this.put(hash, proto.decoded.data)
20733
20732
  }
20733
+ else {
20734
+ this.dht.removeProvider(id, hash);
20735
+ }
20734
20736
  return;
20735
20737
  }
20736
20738
  get message() {
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-3d505e1f.js';
1
+ export { N as default } from './node-browser-79442920.js';
2
2
  import './index-640d9f36.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.57",
3
+ "version": "1.4.58",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",