@leofcoin/chain 1.7.37 → 1.7.43

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 './node-browser-D_OVxIm6.js';
1
+ import { g as getDefaultExportFromCjs } from './node-browser-lePEPRA6.js';
2
2
  import './index-XTbRdu6H.js';
3
3
 
4
4
  var global;
@@ -63,7 +63,7 @@ var author = "Brian McKelvey <theturtle32@gmail.com> (https://github.com/theturt
63
63
  var contributors = [
64
64
  "Iñaki Baz Castillo <ibc@aliax.net> (http://dev.sipdoc.net)"
65
65
  ];
66
- var version$1 = "1.0.34";
66
+ var version$1 = "1.0.35";
67
67
  var repository = {
68
68
  type: "git",
69
69
  url: "https://github.com/theturtle32/WebSocket-Node.git"
@@ -75,7 +75,7 @@ var engines = {
75
75
  var dependencies = {
76
76
  bufferutil: "^4.0.1",
77
77
  debug: "^2.2.0",
78
- "es5-ext": "^0.10.50",
78
+ "es5-ext": "^0.10.63",
79
79
  "typedarray-to-buffer": "^3.1.5",
80
80
  "utf-8-validate": "^5.0.2",
81
81
  yaeti: "^0.0.6"
@@ -70,31 +70,31 @@ class KeyValue {
70
70
  }
71
71
  }
72
72
 
73
- if (!globalThis.DEBUG) {
74
- let DEBUG = [];
75
- if (globalThis.localStorage) {
76
- DEBUG = globalThis.localStorage.getItem('DEBUG');
77
- globalThis.DEBUG = DEBUG ? DEBUG.split(',') : [DEBUG];
78
- }
79
- }
80
-
81
- const debug$1 = (target, text) => {
82
- if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
83
- if (
84
- globalThis.DEBUG === 'true' ||
85
- globalThis.DEBUG === true ||
86
- globalThis.DEBUG?.indexOf(target) !== -1 ||
87
- globalThis.DEBUG?.indexOf('*') !== -1 ||
88
- globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
89
- )
90
- if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
91
- else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
92
- };
93
-
94
- if (!globalThis.debug) {
95
- globalThis.debug = debug$1;
96
-
97
- globalThis.createDebugger = (target) => (text) => debug$1(target, text);
73
+ if (!globalThis.DEBUG) {
74
+ let DEBUG = [];
75
+ if (globalThis.localStorage) {
76
+ DEBUG = globalThis.localStorage.getItem('DEBUG');
77
+ globalThis.DEBUG = DEBUG ? DEBUG.split(',') : [DEBUG];
78
+ }
79
+ }
80
+
81
+ const debug$1 = (target, text) => {
82
+ if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
83
+ if (
84
+ globalThis.DEBUG === 'true' ||
85
+ globalThis.DEBUG === true ||
86
+ globalThis.DEBUG?.indexOf(target) !== -1 ||
87
+ globalThis.DEBUG?.indexOf('*') !== -1 ||
88
+ globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
89
+ )
90
+ if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
91
+ else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
92
+ };
93
+
94
+ if (!globalThis.debug) {
95
+ globalThis.debug = debug$1;
96
+
97
+ globalThis.createDebugger = (target) => (text) => debug$1(target, text);
98
98
  }
99
99
 
100
100
  const debug = globalThis.createDebugger('leofcoin/storage');
@@ -150,49 +150,86 @@ class BrowerStore {
150
150
  }
151
151
  }
152
152
  async get(key) {
153
- debug(`get ${this.toKeyPath(key)}`);
154
- let handle = await this.db.getFileHandle(this.toKeyPath(key));
155
- let readBuffer;
156
- if (this.inWorker) {
157
- // it's in a worker so that's why typings invalid?
158
- // @ts-ignore
159
- handle = await handle.createSyncAccessHandle();
160
- // @ts-ignore
161
- const fileSize = handle.getSize();
162
- // Read file content to a buffer.
163
- const buffer = new DataView(new ArrayBuffer(fileSize));
164
- // @ts-ignore
165
- readBuffer = handle.read(buffer, { at: 0 });
166
- // @ts-ignore
167
- handle.close();
168
- }
169
- else {
170
- const file = await handle.getFile();
171
- readBuffer = await file.arrayBuffer();
172
- }
173
- return new Uint8Array(readBuffer);
153
+ let promiseResolve;
154
+ let promiseReject;
155
+ let result = new Promise((resolve, reject) => {
156
+ promiseResolve = resolve;
157
+ promiseReject = reject;
158
+ });
159
+ const promise = () => new Promise(async (resolve, reject) => {
160
+ debug(`get ${this.toKeyPath(key)}`);
161
+ setTimeout(async () => {
162
+ try {
163
+ let handle = await this.db.getFileHandle(this.toKeyPath(key));
164
+ let readBuffer;
165
+ if (this.inWorker) {
166
+ // it's in a worker so that's why typings invalid?
167
+ // @ts-ignore
168
+ handle = await handle.createSyncAccessHandle();
169
+ // @ts-ignore
170
+ const fileSize = handle.getSize();
171
+ // Read file content to a buffer.
172
+ const buffer = new DataView(new ArrayBuffer(fileSize));
173
+ // @ts-ignore
174
+ readBuffer = handle.read(buffer, { at: 0 });
175
+ // @ts-ignore
176
+ handle.close();
177
+ }
178
+ else {
179
+ const file = await handle.getFile();
180
+ readBuffer = await file.arrayBuffer();
181
+ }
182
+ this.runQueue();
183
+ promiseResolve(new Uint8Array(readBuffer));
184
+ resolve(new Uint8Array(readBuffer));
185
+ }
186
+ catch (error) {
187
+ promiseReject(error);
188
+ resolve(false);
189
+ }
190
+ }, 1);
191
+ });
192
+ this.queue.push(promise);
193
+ this.runQueue();
194
+ return result;
174
195
  }
175
196
  async put(key, value) {
176
- const promise = () => new Promise(async (resolve) => {
197
+ let promiseResolve;
198
+ let promiseReject;
199
+ let result = new Promise((resolve, reject) => {
200
+ promiseResolve = resolve;
201
+ promiseReject = reject;
202
+ });
203
+ const promise = () => new Promise(async (resolve, reject) => {
177
204
  debug(`put ${this.toKeyPath(key)}`);
178
- let handle = await this.db.getFileHandle(this.toKeyPath(key), { create: true });
179
- let writeable;
180
- if (this.inWorker) {
181
- // it's in a worker so that's why typings invalid?
182
- // @ts-ignore
183
- writeable = await handle.createSyncAccessHandle();
184
- }
185
- else {
186
- writeable = await handle.createWritable();
187
- }
188
- (await writeable).write(this.toKeyValue(value));
189
- (await writeable).close();
190
- this.runQueue();
191
- resolve(true);
205
+ setTimeout(async () => {
206
+ try {
207
+ let handle = await this.db.getFileHandle(this.toKeyPath(key), { create: true });
208
+ let writeable;
209
+ if (this.inWorker) {
210
+ // it's in a worker so that's why typings invalid?
211
+ // @ts-ignore
212
+ writeable = await handle.createSyncAccessHandle();
213
+ }
214
+ else {
215
+ writeable = await handle.createWritable();
216
+ }
217
+ ;
218
+ (await writeable).write(this.toKeyValue(value));
219
+ (await writeable).close();
220
+ this.runQueue();
221
+ resolve(true);
222
+ promiseResolve(true);
223
+ }
224
+ catch (error) {
225
+ promiseReject(error);
226
+ resolve(false);
227
+ }
228
+ }, 5);
192
229
  });
193
230
  this.queue.push(promise);
194
231
  this.runQueue();
195
- return promise;
232
+ return result;
196
233
  }
197
234
  async runQueue() {
198
235
  if (this.queue.length > 0 && !this.busy) {
@@ -208,12 +245,29 @@ class BrowerStore {
208
245
  }
209
246
  async delete(key) {
210
247
  debug(`delete ${this.toKeyPath(key)}`);
211
- return this.db.removeEntry(this.toKeyPath(key));
248
+ return new Promise(async (resolve, reject) => {
249
+ try {
250
+ await this.db.getFileHandle(`${this.toKeyPath(key)}.crswap`);
251
+ setTimeout(() => resolve(this.delete(key)), 5);
252
+ }
253
+ catch (error) {
254
+ try {
255
+ await this.db.removeEntry(this.toKeyPath(key));
256
+ resolve(true);
257
+ }
258
+ catch (error) {
259
+ if (error.name === 'NoModificationAllowedError')
260
+ setTimeout(() => resolve(this.delete(key)), 5);
261
+ else
262
+ reject(error);
263
+ }
264
+ }
265
+ });
212
266
  }
213
267
  async clear() {
214
268
  for await (const key of this.db.keys()) {
215
269
  debug(`clear ${this.toKeyPath(key)}`);
216
- await this.db.removeEntry(key);
270
+ await this.delete(key);
217
271
  }
218
272
  }
219
273
  async values() {
@@ -231,6 +285,8 @@ class BrowerStore {
231
285
  for await (const cursor of this.db.values()) {
232
286
  // huh? Outdated typings?
233
287
  // @ts-ignore
288
+ console.log((await cursor.getFile()).size);
289
+
234
290
  size += (await cursor.getFile()).size;
235
291
  }
236
292
  return size;
@@ -1,4 +1,4 @@
1
- import { L as LittlePubSub } from './node-browser-D_OVxIm6.js';
1
+ import { L as LittlePubSub } from './node-browser-lePEPRA6.js';
2
2
  import './index-XTbRdu6H.js';
3
3
 
4
4
  class Api {
@@ -188,14 +188,17 @@ class SocketRequestClient {
188
188
  #options;
189
189
  #protocol;
190
190
  #url;
191
+ #experimentalWebsocket = false;
191
192
  constructor(url, protocol, options) {
192
- let { retry, timeout, times } = options || {};
193
+ let { retry, timeout, times, experimentalWebsocket } = options || {};
193
194
  if (retry !== undefined)
194
195
  this.#retry = retry;
195
196
  if (timeout !== undefined)
196
197
  this.#timeout = timeout;
197
198
  if (times !== undefined)
198
199
  this.#times = times;
200
+ if (experimentalWebsocket !== undefined)
201
+ this.#experimentalWebsocket;
199
202
  this.#url = url;
200
203
  this.#protocol = protocol;
201
204
  this.#options = options;
@@ -205,36 +208,62 @@ class SocketRequestClient {
205
208
  return new Promise(async (resolve, reject) => {
206
209
  const init = async () => {
207
210
  // @ts-ignore
208
- if (!globalThis.WebSocket)
209
- globalThis.WebSocket = (await import('./browser-WUe24rfW-DADoCQbN.js').then(function (n) { return n.b; })).default.w3cwebsocket;
211
+ if (!globalThis.WebSocket && !this.#experimentalWebsocket)
212
+ globalThis.WebSocket = (await import('./browser-DQJ6xf_F-C6-szetT.js').then(function (n) { return n.b; })).default.w3cwebsocket;
210
213
  const client = new WebSocket(this.#url, this.#protocol);
211
- client.onmessage = this.onmessage;
212
- client.onerror = this.onerror;
213
- client.onopen = () => {
214
- this.#tries = 0;
215
- resolve(new ClientConnection(client, this.api));
216
- };
217
- client.onclose = message => {
218
- this.#tries++;
219
- if (!this.#retry)
220
- return reject(this.#options);
221
- if (this.#tries > this.#times) {
222
- console.log(`${this.#options.protocol} Client Closed`);
223
- console.error(`could not connect to - ${this.#url}/`);
224
- return resolve(new ClientConnection(client, this.api));
225
- }
226
- if (message.code === 1006) {
227
- console.log(`Retrying in ${this.#timeout} ms`);
228
- setTimeout(() => {
229
- return init();
230
- }, this.#timeout);
231
- }
232
- };
214
+ if (this.#experimentalWebsocket) {
215
+ client.addEventListener('error', this.onerror);
216
+ client.addEventListener('message', this.onmessage);
217
+ client.addEventListener('open', () => {
218
+ this.#tries = 0;
219
+ resolve(new ClientConnection(client, this.api));
220
+ });
221
+ client.addEventListener('close', (client.onclose = (message) => {
222
+ this.#tries++;
223
+ if (!this.#retry)
224
+ return reject(this.#options);
225
+ if (this.#tries > this.#times) {
226
+ console.log(`${this.#options.protocol} Client Closed`);
227
+ console.error(`could not connect to - ${this.#url}/`);
228
+ return resolve(new ClientConnection(client, this.api));
229
+ }
230
+ if (message.code === 1006) {
231
+ console.log(`Retrying in ${this.#timeout} ms`);
232
+ setTimeout(() => {
233
+ return init();
234
+ }, this.#timeout);
235
+ }
236
+ }));
237
+ }
238
+ else {
239
+ client.onmessage = this.onmessage;
240
+ client.onerror = this.onerror;
241
+ client.onopen = () => {
242
+ this.#tries = 0;
243
+ resolve(new ClientConnection(client, this.api));
244
+ };
245
+ client.onclose = (message) => {
246
+ this.#tries++;
247
+ if (!this.#retry)
248
+ return reject(this.#options);
249
+ if (this.#tries > this.#times) {
250
+ console.log(`${this.#options.protocol} Client Closed`);
251
+ console.error(`could not connect to - ${this.#url}/`);
252
+ return resolve(new ClientConnection(client, this.api));
253
+ }
254
+ if (message.code === 1006) {
255
+ console.log(`Retrying in ${this.#timeout} ms`);
256
+ setTimeout(() => {
257
+ return init();
258
+ }, this.#timeout);
259
+ }
260
+ };
261
+ }
233
262
  };
234
263
  return init();
235
264
  });
236
265
  }
237
- onerror = error => {
266
+ onerror = (error) => {
238
267
  if (globalThis.pubsub.subscribers['error']) {
239
268
  globalThis.pubsub.publish('error', error);
240
269
  }
@@ -243,6 +272,10 @@ class SocketRequestClient {
243
272
  }
244
273
  };
245
274
  onmessage(message) {
275
+ if (!message.data) {
276
+ console.warn(`message ignored because it contained no data`);
277
+ return;
278
+ }
246
279
  const { value, url, status, id } = JSON.parse(message.data.toString());
247
280
  const publisher = id ? id : url;
248
281
  if (status === 200) {
@@ -280,7 +313,7 @@ const iceServers = [
280
313
  credential: 'openrelayproject'
281
314
  }
282
315
  ];
283
- const SimplePeer = (await import('./index-In1Jzp-v-k_wpCs2M.js').then(function (n) { return n.i; })).default;
316
+ const SimplePeer = (await import('./index-DqPlTtAJ-BCTqnABp.js').then(function (n) { return n.i; })).default;
284
317
  class Peer extends SimplePeer {
285
318
  peerId;
286
319
  channelName;
@@ -347,7 +380,7 @@ class Peer extends SimplePeer {
347
380
  */
348
381
  request(data, id = crypto.randomUUID()) {
349
382
  return new Promise((resolve, reject) => {
350
- const timeout = setTimeout(() => reject(`request for ${id} timed out`), 30000);
383
+ const timeout = setTimeout(() => reject(`request for ${id} timed out`), 30_000);
351
384
  const onrequest = ({ data }) => {
352
385
  clearTimeout(timeout);
353
386
  resolve(data);
@@ -359,7 +392,7 @@ class Peer extends SimplePeer {
359
392
  }
360
393
  }
361
394
 
362
- const debug = globalThis.createDebugger('@peernet/swarm/client');
395
+ const debug = globalThis.createDebugger('@netpeer/swarm/client');
363
396
  class Client {
364
397
  #peerId;
365
398
  #connections = {};
@@ -408,7 +441,7 @@ class Client {
408
441
  async _init() {
409
442
  // reconnectJob()
410
443
  if (!globalThis.RTCPeerConnection)
411
- globalThis.wrtc = (await import('./browser-AyxSBUXj-pguCHlVu.js').then(function (n) { return n.b; })).default;
444
+ globalThis.wrtc = (await import('./browser-pguCHlVu-pguCHlVu.js').then(function (n) { return n.b; })).default;
412
445
  for (const star of this.starsConfig) {
413
446
  try {
414
447
  const client = new SocketRequestClient(star, this.networkVersion);
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-D_OVxIm6.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-lePEPRA6.js';
2
2
  import './index-XTbRdu6H.js';
3
3
 
4
4
  /**