@leofcoin/chain 1.5.45 → 1.5.46

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 { F as FormatInterface } from './node-browser-2c421007.js';
1
+ import { F as FormatInterface } from './node-browser-c75c189a.js';
2
2
  import './index-c3bd3090.js';
3
3
 
4
4
  var proto$b = {
@@ -794,7 +794,7 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
794
794
  default: _nodeResolve_empty
795
795
  });
796
796
 
797
- var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
797
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
798
798
 
799
799
  (function (module) {
800
800
  (function (module, exports) {
@@ -851,7 +851,7 @@ var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
851
851
  if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
852
852
  Buffer = window.Buffer;
853
853
  } else {
854
- Buffer = require$$0$1.Buffer;
854
+ Buffer = require$$3.Buffer;
855
855
  }
856
856
  } catch (e) {
857
857
  }
@@ -13561,7 +13561,7 @@ var bn = {exports: {}};
13561
13561
  if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
13562
13562
  Buffer = window.Buffer;
13563
13563
  } else {
13564
- Buffer = require$$0$1.Buffer;
13564
+ Buffer = require$$3.Buffer;
13565
13565
  }
13566
13566
  } catch (e) {
13567
13567
  }
@@ -17205,7 +17205,7 @@ if (typeof self === 'object') {
17205
17205
  } else {
17206
17206
  // Node.js or Web worker with no crypto support
17207
17207
  try {
17208
- var crypto$1 = require$$0$1;
17208
+ var crypto$1 = require$$3;
17209
17209
  if (typeof crypto$1.randomBytes !== 'function')
17210
17210
  throw new Error('Not supported');
17211
17211
 
@@ -27182,7 +27182,7 @@ class Identity {
27182
27182
  this.selectedAccount = new TextDecoder().decode(selected);
27183
27183
  }
27184
27184
  else {
27185
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-687f692b-bcdff490.js');
27185
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-81687e93-18fab48d.js');
27186
27186
  const { identity, accounts } = await importee.default(password, this.network);
27187
27187
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
27188
27188
  await globalThis.walletStore.put('version', String(1));
@@ -27373,7 +27373,7 @@ class Peernet {
27373
27373
  this.root = options.root;
27374
27374
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
27375
27375
  // FolderMessageResponse
27376
- } = await import(/* webpackChunkName: "messages" */ './messages-1c117282-a35a5fbc.js');
27376
+ } = await import(/* webpackChunkName: "messages" */ './messages-cccb78db-116bfaa7.js');
27377
27377
  /**
27378
27378
  * proto Object containing protos
27379
27379
  * @type {Object}
@@ -27467,247 +27467,7 @@ class Peernet {
27467
27467
  if (this.#starting || this.#started)
27468
27468
  return;
27469
27469
  this.#starting = true;
27470
- const importee = class Client {
27471
- #peerId;
27472
- #connections = {};
27473
- #stars = {};
27474
- #connectEvent = 'peer:connected';
27475
- id;
27476
- networkVersion;
27477
- starsConfig;
27478
- socketClient;
27479
- messageSize = 262144;
27480
- version;
27481
- #messagesToHandle = {};
27482
- get peerId() {
27483
- return this.#peerId;
27484
- }
27485
- get connections() {
27486
- return { ...this.#connections };
27487
- }
27488
- get peers() {
27489
- return Object.entries(this.#connections);
27490
- }
27491
- getPeer(peerId) {
27492
- return this.#connections[peerId];
27493
- }
27494
- /**
27495
- *
27496
- * @param options {object}
27497
- * @param options.peerId {string}
27498
- * @param options.networkVersion {string}
27499
- * @param options.version {string}
27500
- * @param options.stars {string[]}
27501
- * @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
27502
- */
27503
- constructor(options) {
27504
- const { peerId, networkVersion, version, connectEvent, stars } = {
27505
- ...defaultOptions,
27506
- ...options
27507
- };
27508
- this.#peerId = peerId;
27509
- this.networkVersion = networkVersion;
27510
- this.version = version;
27511
- this.#connectEvent = connectEvent;
27512
- this.starsConfig = stars;
27513
- this._init();
27514
- }
27515
- async _init() {
27516
- // reconnectJob()
27517
- if (!globalThis.RTCPeerConnection)
27518
- globalThis.wrtc = (await import('./browser-2c73e2ef-2c73e2ef.js').then(function (n) { return n.b; })).default;
27519
- for (const star of this.starsConfig) {
27520
- try {
27521
- const client = new SocketRequestClient(star, this.networkVersion);
27522
- this.#stars[star] = await client.init();
27523
- this.setupStarListeners(this.#stars[star]);
27524
- this.#stars[star].send({
27525
- url: 'join',
27526
- params: { version: this.version, peerId: this.peerId }
27527
- });
27528
- }
27529
- catch (e) {
27530
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 &&
27531
- !this.socketClient)
27532
- throw new Error(`No star available to connect`);
27533
- }
27534
- }
27535
- if (globalThis.navigator) {
27536
- globalThis.addEventListener('beforeunload', async () => this.close());
27537
- }
27538
- else {
27539
- process.on('SIGINT', async () => {
27540
- process.stdin.resume();
27541
- await this.close();
27542
- process.exit();
27543
- });
27544
- }
27545
- }
27546
- setupStarListeners(star) {
27547
- star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
27548
- star.pubsub.subscribe('peer:left', (id) => this.#peerLeft(id, star));
27549
- star.pubsub.subscribe('star:joined', this.#starJoined);
27550
- star.pubsub.subscribe('star:left', this.#starLeft);
27551
- star.pubsub.subscribe('signal', (message) => this.#inComingSignal(message, star));
27552
- }
27553
- #starJoined = (id) => {
27554
- if (this.#stars[id]) {
27555
- this.#stars[id].close(0);
27556
- delete this.#stars[id];
27557
- }
27558
- console.log(`star ${id} joined`);
27559
- };
27560
- #starLeft = async (id) => {
27561
- if (this.#stars[id]) {
27562
- this.#stars[id].close(0);
27563
- delete this.#stars[id];
27564
- }
27565
- if (Object.keys(this.#stars).length === 0) {
27566
- for (const star of this.starsConfig) {
27567
- try {
27568
- const socketClient = await new SocketRequestClient(star, this.networkVersion).init();
27569
- if (!socketClient?.client?.OPEN)
27570
- return;
27571
- this.#stars[star] = socketClient;
27572
- this.#stars[star].send({
27573
- url: 'join',
27574
- params: { peerId: this.peerId, version: this.version }
27575
- });
27576
- this.setupStarListeners(socketClient);
27577
- }
27578
- catch (e) {
27579
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1)
27580
- throw new Error(`No star available to connect`);
27581
- }
27582
- }
27583
- }
27584
- globalThis.debug(`star ${id} left`);
27585
- };
27586
- #peerLeft = (peer, star) => {
27587
- const id = peer.peerId || peer;
27588
- if (this.#connections[id]) {
27589
- this.#connections[id].destroy();
27590
- delete this.#connections[id];
27591
- }
27592
- globalThis.debug(`peer ${id} left`);
27593
- };
27594
- #createRTCPeerConnection = (peerId, star, version, initiator = false) => {
27595
- const peer = new Peer({
27596
- initiator: initiator,
27597
- from: this.peerId,
27598
- to: peerId,
27599
- version
27600
- });
27601
- peer.on('signal', (signal) => this.#peerSignal(peer, signal, star, this.version));
27602
- peer.on('connect', () => this.#peerConnect(peer));
27603
- peer.on('close', () => this.#peerClose(peer));
27604
- peer.on('data', (data) => this.#peerData(peer, data));
27605
- peer.on('error', (error) => this.#peerError(peer, error));
27606
- this.#connections[peerId] = peer;
27607
- };
27608
- #peerJoined = async ({ peerId, version }, star) => {
27609
- // check if peer rejoined before the previous connection closed
27610
- if (this.#connections[peerId]) {
27611
- this.#connections[peerId].destroy();
27612
- delete this.#connections[peerId];
27613
- }
27614
- // RTCPeerConnection
27615
- this.#createRTCPeerConnection(peerId, star, version, true);
27616
- globalThis.debug(`peer ${peerId} joined`);
27617
- };
27618
- #inComingSignal = async ({ from, signal, channelName, version }, star) => {
27619
- if (version !== this.version) {
27620
- console.warn(`${from} joined using the wrong version.\nexpected: ${this.version} but got:${version}`);
27621
- return;
27622
- }
27623
- let peer = this.#connections[from];
27624
- if (!peer) {
27625
- this.#createRTCPeerConnection(from, star, version);
27626
- peer = this.#connections[from];
27627
- }
27628
- if (String(peer.channelName) !== String(channelName))
27629
- console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}`);
27630
- peer.signal(signal);
27631
- };
27632
- #peerSignal = (peer, signal, star, version) => {
27633
- let client = this.#stars[star];
27634
- if (!client)
27635
- client = this.#stars[Object.keys(this.#stars)[0]];
27636
- client.send({
27637
- url: 'signal',
27638
- params: {
27639
- from: this.peerId,
27640
- to: peer.peerId,
27641
- channelName: peer.channelName,
27642
- version,
27643
- signal
27644
- }
27645
- });
27646
- };
27647
- #peerClose = (peer) => {
27648
- if (this.#connections[peer.peerId]) {
27649
- peer.destroy();
27650
- delete this.#connections[peer.peerId];
27651
- }
27652
- globalThis.debug(`closed ${peer.peerId}'s connection`);
27653
- };
27654
- #peerConnect = (peer) => {
27655
- globalThis.debug(`${peer.peerId} connected`);
27656
- globalThis.pubsub.publishVerbose(this.#connectEvent, peer.peerId);
27657
- };
27658
- #noticeMessage = (message, id, from, peer) => {
27659
- if (globalThis.pubsub.subscribers[id]) {
27660
- globalThis.pubsub.publish(id, {
27661
- data: new Uint8Array(Object.values(message)),
27662
- id,
27663
- from,
27664
- peer
27665
- });
27666
- }
27667
- else {
27668
- globalThis.pubsub.publish('peer:data', {
27669
- data: new Uint8Array(Object.values(message)),
27670
- id,
27671
- from,
27672
- peer
27673
- });
27674
- }
27675
- };
27676
- #peerData = (peer, data) => {
27677
- const { id, size, chunk } = JSON.parse(new TextDecoder().decode(data));
27678
- peer.bw.down += size;
27679
- if (size <= MAX_MESSAGE_SIZE) {
27680
- this.#noticeMessage(chunk, id, peer.peerId, peer);
27681
- }
27682
- else {
27683
- if (!this.#messagesToHandle[id])
27684
- this.#messagesToHandle[id] = [];
27685
- this.#messagesToHandle[id] = [
27686
- ...this.#messagesToHandle[id],
27687
- ...Object.values(chunk)
27688
- ];
27689
- if (this.#messagesToHandle[id].length === Number(size)) {
27690
- this.#noticeMessage(this.#messagesToHandle[id], id, peer.peerId, peer);
27691
- delete this.#messagesToHandle[id];
27692
- }
27693
- }
27694
- };
27695
- #peerError = (peer, error) => {
27696
- console.warn(`Connection error: ${error.message}`);
27697
- peer.destroy();
27698
- };
27699
- async close() {
27700
- for (const star in this.#stars) {
27701
- if (this.#stars[star].connectionState() === 'open')
27702
- await this.#stars[star].send({ url: 'leave', params: this.peerId });
27703
- }
27704
- const promises = [
27705
- Object.values(this.#connections).map((connection) => connection.destroy()),
27706
- Object.values(this.#stars).map((connection) => connection.close(0))
27707
- ];
27708
- return Promise.allSettled(promises);
27709
- }
27710
- };
27470
+ const importee = await import('./client-f193279c-98f2aeaa.js');
27711
27471
  /**
27712
27472
  * @access public
27713
27473
  * @type {PeernetClient}
@@ -28240,4 +28000,4 @@ class Node {
28240
28000
  }
28241
28001
  }
28242
28002
 
28243
- export { FormatInterface as F, MultiWallet as M, Node as N, base58$1 as b, encrypt as e };
28003
+ export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Node as N, base58$1 as b, commonjsGlobal as c, encrypt as e, getDefaultExportFromCjs as g, inherits_browserExports as i, require$$3 as r };
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-2c421007.js';
1
+ export { N as default } from './node-browser-c75c189a.js';
2
2
  import './index-c3bd3090.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.45",
3
+ "version": "1.5.46",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": {