@leofcoin/chain 1.9.17 → 1.9.19

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,6 +1,6 @@
1
- import { g as getDefaultExportFromCjs } from './node-browser-y2adT6_R.js';
1
+ import { g as getDefaultExportFromCjs } from './node-browser-CYsu-WiL.js';
2
2
  import 'crypto';
3
- import './constants-V2VjIc2r.js';
3
+ import './constants-BCaq9RBn.js';
4
4
 
5
5
  function _mergeNamespaces$1(n, m) {
6
6
  m.forEach(function (e) {
@@ -1,6 +1,6 @@
1
- import { g as getDefaultExportFromCjs } from './node-browser-y2adT6_R.js';
1
+ import { g as getDefaultExportFromCjs } from './node-browser-CYsu-WiL.js';
2
2
  import 'crypto';
3
- import './constants-V2VjIc2r.js';
3
+ import './constants-BCaq9RBn.js';
4
4
 
5
5
  function _mergeNamespaces$1(n, m) {
6
6
  m.forEach(function (e) {
@@ -1,4 +1,4 @@
1
- import { t as toBase58, T as TransactionMessage, C as ContractMessage, f as RawTransactionMessage, b as BlockMessage, L as LastBlockMessage, P as PROTOCOL_VERSION, R as REACHED_ONE_ZERO_ZERO, d as PrevoteMessage, c as PrecommitMessage, e as ProposalMessage, B as BWMessage, S as StateMessage, a as BWRequestMessage } from './constants-V2VjIc2r.js';
1
+ import { t as toBase58, T as TransactionMessage, C as ContractMessage, R as RawTransactionMessage, B as BlockMessage, L as LastBlockMessage, P as PROTOCOL_VERSION, a as REACHED_ONE_ZERO_ZERO, b as PrevoteMessage, c as PrecommitMessage, d as ProposalMessage, e as BWMessage, S as StateMessage, f as BWRequestMessage } from './constants-BCaq9RBn.js';
2
2
 
3
3
  const getTargets = () => Array.from([]);
4
4
  const isEnabled = (target) => {
@@ -1234,6 +1234,22 @@ function requireSemver$1 () {
1234
1234
 
1235
1235
  const parseOptions = requireParseOptions();
1236
1236
  const { compareIdentifiers } = requireIdentifiers();
1237
+
1238
+ const isPrereleaseIdentifier = (prerelease, identifier) => {
1239
+ const identifiers = identifier.split('.');
1240
+ if (identifiers.length > prerelease.length) {
1241
+ return false
1242
+ }
1243
+
1244
+ for (let i = 0; i < identifiers.length; i++) {
1245
+ if (compareIdentifiers(prerelease[i], identifiers[i]) !== 0) {
1246
+ return false
1247
+ }
1248
+ }
1249
+
1250
+ return true
1251
+ };
1252
+
1237
1253
  class SemVer {
1238
1254
  constructor (version, options) {
1239
1255
  options = parseOptions(options);
@@ -1537,8 +1553,9 @@ function requireSemver$1 () {
1537
1553
  if (identifierBase === false) {
1538
1554
  prerelease = [identifier];
1539
1555
  }
1540
- if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
1541
- if (isNaN(this.prerelease[1])) {
1556
+ if (isPrereleaseIdentifier(this.prerelease, identifier)) {
1557
+ const prereleaseBase = this.prerelease[identifier.split('.').length];
1558
+ if (isNaN(prereleaseBase)) {
1542
1559
  this.prerelease = prerelease;
1543
1560
  }
1544
1561
  } else {
@@ -5798,7 +5815,7 @@ class ConnectionMonitor {
5798
5815
  try {
5799
5816
  const networkName = globalThis.peernet?.network;
5800
5817
  if (networkName && typeof networkName === "string") {
5801
- const { default: networks } = await import('./constants-V2VjIc2r.js').then(function (n) { return n.n; });
5818
+ const { default: networks } = await import('./constants-BCaq9RBn.js').then(function (n) { return n.n; });
5802
5819
  const [mainKey, subKey] = networkName.split(":");
5803
5820
  const networkConfig = networks?.[mainKey]?.[subKey];
5804
5821
  if (networkConfig?.stars && Array.isArray(networkConfig.stars)) {
@@ -6364,31 +6381,31 @@ class Chain extends VersionControl {
6364
6381
  const node = await this.#prepareRequest(request);
6365
6382
  try {
6366
6383
  let response = await peer.request(node.encoded);
6367
- response = await new globalThis.peernet.protos["peernet-response"](response);
6384
+ if (response === void 0 || response === null) return response;
6368
6385
  const normalizeResponse = async (payload) => {
6369
- if (payload && typeof payload === "object" && "response" in payload) {
6370
- return normalizeResponse(payload.response);
6386
+ if (payload === void 0 || payload === null) return payload;
6387
+ if (payload && typeof payload === "object") {
6388
+ if ("decoded" in payload && payload?.decoded && "response" in payload.decoded) {
6389
+ return normalizeResponse(payload.decoded.response);
6390
+ }
6391
+ if ("response" in payload) {
6392
+ return normalizeResponse(payload.response);
6393
+ }
6371
6394
  }
6372
6395
  if (payload instanceof Uint8Array || typeof Buffer !== "undefined" && Buffer.isBuffer(payload)) {
6373
- let bytes = payload;
6374
- for (let i = 0; i < 3; i++) {
6375
- try {
6376
- const nested = await new globalThis.peernet.protos["peernet-response"](bytes);
6377
- payload = nested?.decoded?.response;
6378
- if (!(payload instanceof Uint8Array)) break;
6379
- bytes = payload;
6380
- } catch {
6381
- break;
6396
+ const bytes = payload instanceof Uint8Array ? payload : new Uint8Array(payload);
6397
+ try {
6398
+ const wrapped = await new globalThis.peernet.protos["peernet-response"](bytes);
6399
+ if (wrapped?.decoded?.response !== void 0) {
6400
+ return normalizeResponse(wrapped.decoded.response);
6382
6401
  }
6402
+ } catch {
6383
6403
  }
6384
- if (payload instanceof Uint8Array) {
6385
- try {
6386
- return JSON.parse(new TextDecoder().decode(payload));
6387
- } catch {
6388
- return payload;
6389
- }
6404
+ try {
6405
+ return JSON.parse(new TextDecoder().decode(bytes));
6406
+ } catch {
6407
+ return bytes;
6390
6408
  }
6391
- return payload;
6392
6409
  }
6393
6410
  if (typeof payload === "string") {
6394
6411
  try {
@@ -6399,7 +6416,7 @@ class Chain extends VersionControl {
6399
6416
  }
6400
6417
  return payload;
6401
6418
  };
6402
- return await normalizeResponse(response.decoded.response);
6419
+ return await normalizeResponse(response);
6403
6420
  } catch (error) {
6404
6421
  const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
6405
6422
  debug(`peernet request failed: ${request} -> ${peerId}:`, error?.message ?? error);
@@ -6518,6 +6535,9 @@ class Chain extends VersionControl {
6518
6535
  console.log("requesting last block from peer...");
6519
6536
  console.log(await this.lastBlock);
6520
6537
  const lastBlockRaw = await this.#makeRequest(peer, "lastBlock");
6538
+ if (lastBlockRaw === void 0 || lastBlockRaw === null || typeof lastBlockRaw !== "object" && !(lastBlockRaw instanceof Uint8Array)) {
6539
+ throw new Error(`invalid lastBlock payload: ${typeof lastBlockRaw}`);
6540
+ }
6521
6541
  console.log(new LastBlockMessage(lastBlockRaw));
6522
6542
  lastBlock = new LastBlockMessage(lastBlockRaw).decoded;
6523
6543
  } catch (error) {
@@ -1,6 +1,6 @@
1
- import { i as inflate_1, c as createDebugger, d as deflate_1, L as LittlePubSub } from './node-browser-y2adT6_R.js';
1
+ import { i as inflate_1, c as createDebugger, d as deflate_1, L as LittlePubSub } from './node-browser-CYsu-WiL.js';
2
2
  import 'crypto';
3
- import './constants-V2VjIc2r.js';
3
+ import './constants-BCaq9RBn.js';
4
4
 
5
5
  class Api {
6
6
  _pubsub;
@@ -231,7 +231,7 @@ class SocketRequestClient {
231
231
  const init = async () => {
232
232
  // @ts-ignore
233
233
  if (!globalThis.WebSocket && !this.#experimentalWebsocket)
234
- globalThis.WebSocket = (await import('./browser-8BFql6K9-BMRX6B2u.js').then(function (n) { return n.b; })).default.w3cwebsocket;
234
+ globalThis.WebSocket = (await import('./browser-8BFql6K9-Cfm2axSE.js').then(function (n) { return n.b; })).default.w3cwebsocket;
235
235
  const client = new WebSocket(this.#url, this.#protocol);
236
236
  if (this.#experimentalWebsocket) {
237
237
  client.addEventListener('error', this.onerror);
@@ -1302,7 +1302,7 @@ class Client {
1302
1302
  }
1303
1303
  }
1304
1304
  async #loadNodeWebrtcImplementation() {
1305
- const koushWrtcModule = await import('./browser-FVp_QbaL-zB8FF4EN.js').then(function (n) { return n.b; });
1305
+ const koushWrtcModule = await import('./browser-FVp_QbaL-DShoEW2_.js').then(function (n) { return n.b; });
1306
1306
  const koushWrtc = koushWrtcModule.default;
1307
1307
  if (!isWrtcImplementation(koushWrtc)) {
1308
1308
  throw new Error('@koush/wrtc does not match required wrtc contract');
@@ -9040,4 +9040,4 @@ const DEFAULT_NODE_OPTIONS = {
9040
9040
  stars: networks.leofcoin.peach.stars
9041
9041
  };
9042
9042
 
9043
- export { BWMessage as B, ContractMessage as C, DEFAULT_NODE_OPTIONS as D, LastBlockMessage as L, PROTOCOL_VERSION as P, REACHED_ONE_ZERO_ZERO as R, StateMessage as S, TransactionMessage as T, ValidatorMessage as V, BWRequestMessage as a, BlockMessage as b, PrecommitMessage as c, PrevoteMessage as d, ProposalMessage as e, RawTransactionMessage as f, networks$1 as n, toBase58 as t };
9043
+ export { BlockMessage as B, ContractMessage as C, DEFAULT_NODE_OPTIONS as D, LastBlockMessage as L, PROTOCOL_VERSION as P, RawTransactionMessage as R, StateMessage as S, TransactionMessage as T, ValidatorMessage as V, REACHED_ONE_ZERO_ZERO as a, PrevoteMessage as b, PrecommitMessage as c, ProposalMessage as d, BWMessage as e, BWRequestMessage as f, networks$1 as n, toBase58 as t };
@@ -1,6 +1,6 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-y2adT6_R.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-CYsu-WiL.js';
2
2
  import 'crypto';
3
- import './constants-V2VjIc2r.js';
3
+ import './constants-BCaq9RBn.js';
4
4
 
5
5
  /**
6
6
  * @params {String} network
@@ -1,6 +1,6 @@
1
- import { F as FormatInterface } from './node-browser-y2adT6_R.js';
1
+ import { F as FormatInterface } from './node-browser-CYsu-WiL.js';
2
2
  import 'crypto';
3
- import './constants-V2VjIc2r.js';
3
+ import './constants-BCaq9RBn.js';
4
4
 
5
5
  var proto$b = {
6
6
  data: new Uint8Array(),
@@ -1,5 +1,5 @@
1
1
  import { createHash as createHash$1 } from 'crypto';
2
- import { T as TransactionMessage, C as ContractMessage, b as BlockMessage, B as BWMessage, a as BWRequestMessage, V as ValidatorMessage, S as StateMessage, L as LastBlockMessage, D as DEFAULT_NODE_OPTIONS } from './constants-V2VjIc2r.js';
2
+ import { T as TransactionMessage, C as ContractMessage, B as BlockMessage, e as BWMessage, f as BWRequestMessage, V as ValidatorMessage, S as StateMessage, L as LastBlockMessage, D as DEFAULT_NODE_OPTIONS } from './constants-BCaq9RBn.js';
3
3
 
4
4
  var nodeConfig = async (config = {
5
5
  network: "leofcoin:peach",
@@ -8337,7 +8337,7 @@ class Identity {
8337
8337
  this.selectedAccount = new TextDecoder().decode(selected);
8338
8338
  }
8339
8339
  else {
8340
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-D6qd-AUn-CCzkkXys.js');
8340
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-D6qd-AUn-q2EQ9wfH.js');
8341
8341
  const { identity, accounts } = await importee.default(password, this.network);
8342
8342
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
8343
8343
  await globalThis.walletStore.put('version', String(1));
@@ -16998,7 +16998,7 @@ class Peernet {
16998
16998
  await getAddress();
16999
16999
  this.storePrefix = options.storePrefix;
17000
17000
  this.root = options.root;
17001
- const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-BfDvXW-x-C-CI69S2.js');
17001
+ const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-BfDvXW-x-CNuQ6tVL.js');
17002
17002
  /**
17003
17003
  * proto Object containing protos
17004
17004
  * @type {Object}
@@ -17045,7 +17045,7 @@ class Peernet {
17045
17045
  if (this.#starting || this.#started)
17046
17046
  return;
17047
17047
  this.#starting = true;
17048
- const importee = await import('./client-lPe0SUWx-DR-mCTBz.js');
17048
+ const importee = await import('./client-lPe0SUWx-Cm8Ph6Z5.js');
17049
17049
  /**
17050
17050
  * @access public
17051
17051
  * @type {PeernetClient}
@@ -1,3 +1,3 @@
1
- export { N as default } from './node-browser-y2adT6_R.js';
1
+ export { N as default } from './node-browser-CYsu-WiL.js';
2
2
  import 'crypto';
3
- import './constants-V2VjIc2r.js';
3
+ import './constants-BCaq9RBn.js';
package/exports/chain.js CHANGED
@@ -2587,31 +2587,31 @@ class Chain extends VersionControl {
2587
2587
  const node = await this.#prepareRequest(request);
2588
2588
  try {
2589
2589
  let response = await peer.request(node.encoded);
2590
- response = await new globalThis.peernet.protos["peernet-response"](response);
2590
+ if (response === void 0 || response === null) return response;
2591
2591
  const normalizeResponse = async (payload) => {
2592
- if (payload && typeof payload === "object" && "response" in payload) {
2593
- return normalizeResponse(payload.response);
2592
+ if (payload === void 0 || payload === null) return payload;
2593
+ if (payload && typeof payload === "object") {
2594
+ if ("decoded" in payload && payload?.decoded && "response" in payload.decoded) {
2595
+ return normalizeResponse(payload.decoded.response);
2596
+ }
2597
+ if ("response" in payload) {
2598
+ return normalizeResponse(payload.response);
2599
+ }
2594
2600
  }
2595
2601
  if (payload instanceof Uint8Array || typeof Buffer !== "undefined" && Buffer.isBuffer(payload)) {
2596
- let bytes = payload;
2597
- for (let i = 0; i < 3; i++) {
2598
- try {
2599
- const nested = await new globalThis.peernet.protos["peernet-response"](bytes);
2600
- payload = nested?.decoded?.response;
2601
- if (!(payload instanceof Uint8Array)) break;
2602
- bytes = payload;
2603
- } catch {
2604
- break;
2602
+ const bytes = payload instanceof Uint8Array ? payload : new Uint8Array(payload);
2603
+ try {
2604
+ const wrapped = await new globalThis.peernet.protos["peernet-response"](bytes);
2605
+ if (wrapped?.decoded?.response !== void 0) {
2606
+ return normalizeResponse(wrapped.decoded.response);
2605
2607
  }
2608
+ } catch {
2606
2609
  }
2607
- if (payload instanceof Uint8Array) {
2608
- try {
2609
- return JSON.parse(new TextDecoder().decode(payload));
2610
- } catch {
2611
- return payload;
2612
- }
2610
+ try {
2611
+ return JSON.parse(new TextDecoder().decode(bytes));
2612
+ } catch {
2613
+ return bytes;
2613
2614
  }
2614
- return payload;
2615
2615
  }
2616
2616
  if (typeof payload === "string") {
2617
2617
  try {
@@ -2622,7 +2622,7 @@ class Chain extends VersionControl {
2622
2622
  }
2623
2623
  return payload;
2624
2624
  };
2625
- return await normalizeResponse(response.decoded.response);
2625
+ return await normalizeResponse(response);
2626
2626
  } catch (error) {
2627
2627
  const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
2628
2628
  debug(`peernet request failed: ${request} -> ${peerId}:`, error?.message ?? error);
@@ -2741,6 +2741,9 @@ class Chain extends VersionControl {
2741
2741
  console.log("requesting last block from peer...");
2742
2742
  console.log(await this.lastBlock);
2743
2743
  const lastBlockRaw = await this.#makeRequest(peer, "lastBlock");
2744
+ if (lastBlockRaw === void 0 || lastBlockRaw === null || typeof lastBlockRaw !== "object" && !(lastBlockRaw instanceof Uint8Array)) {
2745
+ throw new Error(`invalid lastBlock payload: ${typeof lastBlockRaw}`);
2746
+ }
2744
2747
  console.log(new LastBlockMessage(lastBlockRaw));
2745
2748
  lastBlock = new LastBlockMessage(lastBlockRaw).decoded;
2746
2749
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.9.17",
3
+ "version": "1.9.19",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -55,7 +55,7 @@
55
55
  "@rollup/plugin-typescript": "^12.3.0",
56
56
  "@types/semver": "^7.7.1",
57
57
  "@vandeurenglenn/debug": "^1.4.0",
58
- "rollup": "^4.60.4",
58
+ "rollup": "^4.61.1",
59
59
  "rollup-plugin-esbuild": "^6.2.1",
60
60
  "rollup-plugin-modify": "^3.0.0",
61
61
  "tape": "^5.9.0",
@@ -77,6 +77,6 @@
77
77
  "@leofcoin/workers": "^1.5.30",
78
78
  "@vandeurenglenn/base58": "^1.1.9",
79
79
  "@vandeurenglenn/easy-worker": "^1.0.3",
80
- "semver": "^7.8.1"
80
+ "semver": "^7.8.2"
81
81
  }
82
82
  }