@leofcoin/peernet 1.1.73 → 1.1.75

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 { g as getDefaultExportFromCjs } from './peernet-0298b289.js';
1
+ import { g as getDefaultExportFromCjs } from './peernet-50qCgIc4.js';
2
2
 
3
3
  var global;
4
4
  var hasRequiredGlobal;
@@ -1,4 +1,4 @@
1
- import { K as KeyPath, a as KeyValue } from './value-4e80eeeb.js';
1
+ import { K as KeyPath, a as KeyValue } from './value-wzPYMxsX.js';
2
2
 
3
3
  const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
4
4
 
@@ -24,9 +24,7 @@ function getCursorAdvanceMethods() {
24
24
  IDBCursor.prototype.continuePrimaryKey,
25
25
  ]));
26
26
  }
27
- const cursorRequestMap = new WeakMap();
28
27
  const transactionDoneMap = new WeakMap();
29
- const transactionStoreNamesMap = new WeakMap();
30
28
  const transformCache = new WeakMap();
31
29
  const reverseTransformCache = new WeakMap();
32
30
  function promisifyRequest(request) {
@@ -46,16 +44,6 @@ function promisifyRequest(request) {
46
44
  request.addEventListener('success', success);
47
45
  request.addEventListener('error', error);
48
46
  });
49
- promise
50
- .then((value) => {
51
- // Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval
52
- // (see wrapFunction).
53
- if (value instanceof IDBCursor) {
54
- cursorRequestMap.set(value, request);
55
- }
56
- // Catching to avoid "Uncaught Promise exceptions"
57
- })
58
- .catch(() => { });
59
47
  // This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
60
48
  // is because we create many promises from a single IDBRequest.
61
49
  reverseTransformCache.set(promise, request);
@@ -92,10 +80,6 @@ let idbProxyTraps = {
92
80
  // Special handling for transaction.done.
93
81
  if (prop === 'done')
94
82
  return transactionDoneMap.get(target);
95
- // Polyfill for objectStoreNames because of Edge.
96
- if (prop === 'objectStoreNames') {
97
- return target.objectStoreNames || transactionStoreNamesMap.get(target);
98
- }
99
83
  // Make tx.store return the only store in the transaction, or undefined if there are many.
100
84
  if (prop === 'store') {
101
85
  return receiver.objectStoreNames[1]
@@ -124,15 +108,6 @@ function replaceTraps(callback) {
124
108
  function wrapFunction(func) {
125
109
  // Due to expected object equality (which is enforced by the caching in `wrap`), we
126
110
  // only create one new func per func.
127
- // Edge doesn't support objectStoreNames (booo), so we polyfill it here.
128
- if (func === IDBDatabase.prototype.transaction &&
129
- !('objectStoreNames' in IDBTransaction.prototype)) {
130
- return function (storeNames, ...args) {
131
- const tx = func.call(unwrap(this), storeNames, ...args);
132
- transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
133
- return wrap(tx);
134
- };
135
- }
136
111
  // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
137
112
  // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
138
113
  // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
@@ -143,7 +118,7 @@ function wrapFunction(func) {
143
118
  // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
144
119
  // the original object.
145
120
  func.apply(unwrap(this), args);
146
- return wrap(cursorRequestMap.get(this));
121
+ return wrap(this.request);
147
122
  };
148
123
  }
149
124
  return function (...args) {
@@ -1,5 +1,5 @@
1
- import { L as LittlePubSub } from './peernet-0298b289.js';
2
- import './value-4e80eeeb.js';
1
+ import { L as LittlePubSub } from './peernet-50qCgIc4.js';
2
+ import './value-wzPYMxsX.js';
3
3
 
4
4
  class Api {
5
5
  _pubsub;
@@ -206,7 +206,7 @@ class SocketRequestClient {
206
206
  const init = async () => {
207
207
  // @ts-ignore
208
208
  if (!globalThis.WebSocket)
209
- globalThis.WebSocket = (await import('./browser-dc41c03f.js').then(function (n) { return n.b; })).default.w3cwebsocket;
209
+ globalThis.WebSocket = (await import('./browser-Tj0_3j2t.js').then(function (n) { return n.b; })).default.w3cwebsocket;
210
210
  const client = new WebSocket(this.#url, this.#protocol);
211
211
  client.onmessage = this.onmessage;
212
212
  client.onerror = this.onerror;
@@ -280,12 +280,15 @@ const iceServers = [
280
280
  credential: 'openrelayproject'
281
281
  }
282
282
  ];
283
- const SimplePeer = (await import('./index-fd97ecae.js').then(function (n) { return n.i; })).default;
283
+ const SimplePeer = (await import('./index-Bvry90bx.js').then(function (n) { return n.i; })).default;
284
284
  class Peer extends SimplePeer {
285
285
  peerId;
286
286
  channelName;
287
287
  version;
288
288
  bw = { up: 0, down: 0 };
289
+ get connected() {
290
+ return super.connected;
291
+ }
289
292
  constructor(options) {
290
293
  const { from, to, initiator, trickle, config, version } = options;
291
294
  const channelName = initiator ? `${from}:${to}` : `${to}:${from}`;
@@ -356,6 +359,7 @@ class Peer extends SimplePeer {
356
359
  }
357
360
  }
358
361
 
362
+ const debug = globalThis.createDebugger('@peernet/swarm/client');
359
363
  class Client {
360
364
  #peerId;
361
365
  #connections = {};
@@ -404,7 +408,7 @@ class Client {
404
408
  async _init() {
405
409
  // reconnectJob()
406
410
  if (!globalThis.RTCPeerConnection)
407
- globalThis.wrtc = (await import('./browser-2c73e2ef.js').then(function (n) { return n.b; })).default;
411
+ globalThis.wrtc = (await import('./browser-AyxSBUXj.js').then(function (n) { return n.b; })).default;
408
412
  for (const star of this.starsConfig) {
409
413
  try {
410
414
  const client = new SocketRequestClient(star, this.networkVersion);
@@ -421,16 +425,16 @@ class Client {
421
425
  throw new Error(`No star available to connect`);
422
426
  }
423
427
  }
424
- if (globalThis.navigator) {
425
- globalThis.addEventListener('beforeunload', async () => this.close());
426
- }
427
- else {
428
+ if (globalThis.process?.versions?.node) {
428
429
  process.on('SIGINT', async () => {
429
430
  process.stdin.resume();
430
431
  await this.close();
431
432
  process.exit();
432
433
  });
433
434
  }
435
+ else {
436
+ globalThis.addEventListener('beforeunload', async () => this.close());
437
+ }
434
438
  }
435
439
  setupStarListeners(star) {
436
440
  star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
@@ -470,7 +474,7 @@ class Client {
470
474
  }
471
475
  }
472
476
  }
473
- globalThis.debug(`star ${id} left`);
477
+ debug(`star ${id} left`);
474
478
  };
475
479
  #peerLeft = (peer, star) => {
476
480
  const id = peer.peerId || peer;
@@ -478,7 +482,7 @@ class Client {
478
482
  this.#connections[id].destroy();
479
483
  delete this.#connections[id];
480
484
  }
481
- globalThis.debug(`peer ${id} left`);
485
+ debug(`peer ${id} left`);
482
486
  };
483
487
  #createRTCPeerConnection = (peerId, star, version, initiator = false) => {
484
488
  const peer = new Peer({
@@ -502,7 +506,7 @@ class Client {
502
506
  }
503
507
  // RTCPeerConnection
504
508
  this.#createRTCPeerConnection(peerId, star, version, true);
505
- globalThis.debug(`peer ${peerId} joined`);
509
+ debug(`peer ${peerId} joined`);
506
510
  };
507
511
  #inComingSignal = async ({ from, signal, channelName, version }, star) => {
508
512
  if (version !== this.version) {
@@ -538,10 +542,10 @@ class Client {
538
542
  peer.destroy();
539
543
  delete this.#connections[peer.peerId];
540
544
  }
541
- globalThis.debug(`closed ${peer.peerId}'s connection`);
545
+ debug(`closed ${peer.peerId}'s connection`);
542
546
  };
543
547
  #peerConnect = (peer) => {
544
- globalThis.debug(`${peer.peerId} connected`);
548
+ debug(`${peer.peerId} connected`);
545
549
  globalThis.pubsub.publishVerbose(this.#connectEvent, peer.peerId);
546
550
  };
547
551
  #noticeMessage = (message, id, from, peer) => {
@@ -0,0 +1,19 @@
1
+ import type { base58String } from '@vandeurenglenn/base58';
2
+ export default class Identity {
3
+ #private;
4
+ network: any;
5
+ id: string;
6
+ selectedAccount: string;
7
+ constructor(network: string);
8
+ get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
9
+ getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
10
+ load(password?: string): Promise<void>;
11
+ selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
12
+ sign(hash: Uint8Array): any;
13
+ lock(password: string): void;
14
+ unlock(password: string): void;
15
+ export(password: string): Promise<any>;
16
+ import(password: any, encrypted: base58String): Promise<void>;
17
+ exportQR(password: string): Promise<string>;
18
+ importQR(image: File | Blob, password: string): Promise<void>;
19
+ }