@leofcoin/chain 1.9.22 → 1.9.25
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.
- package/exports/browser/{browser-FVp_QbaL-C-GWIuv6.js → browser-DEjI2nFg-CL-zDjzl.js} +1 -1
- package/exports/browser/{browser-8BFql6K9-BMXXABIY.js → browser-tK3uOLQV-CtcRBohi.js} +1 -1
- package/exports/browser/chain.js +100 -8
- package/exports/browser/{client-lPe0SUWx-DwxXCP5p.js → client-Ba1cHcxF-B4lH2-fQ.js} +18 -13
- package/exports/browser/{index-D6qd-AUn-cJS9xh8w.js → index-DIhxISkU-Bdapw5qM.js} +1 -1
- package/exports/browser/{messages-BfDvXW-x-BaHit_or.js → messages-BX59GgBQ-DVjVrJBf.js} +1 -1
- package/exports/browser/{node-browser-Dc4HZiX0.js → node-browser-Cdgaf6tz.js} +1978 -1906
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +83 -4
- package/package.json +15 -15
package/exports/browser/chain.js
CHANGED
|
@@ -2473,6 +2473,11 @@ function requireRange () {
|
|
|
2473
2473
|
|
|
2474
2474
|
const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
|
|
2475
2475
|
|
|
2476
|
+
const invalidXRangeOrder = (M, m, p) => (
|
|
2477
|
+
(isX(M) && !isX(m)) ||
|
|
2478
|
+
(isX(m) && p && !isX(p))
|
|
2479
|
+
);
|
|
2480
|
+
|
|
2476
2481
|
// ~, ~> --> * (any, kinda silly)
|
|
2477
2482
|
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
|
2478
2483
|
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
|
@@ -2490,6 +2495,10 @@ function requireRange () {
|
|
|
2490
2495
|
|
|
2491
2496
|
const replaceTilde = (comp, options) => {
|
|
2492
2497
|
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
2498
|
+
// if we're including prereleases in the match, then the lower bound is
|
|
2499
|
+
// -0, the lowest possible prerelease value, just like x-ranges and carets.
|
|
2500
|
+
// this keeps `~1.2` equivalent to the `1.2.x` x-range it's documented as.
|
|
2501
|
+
const z = options.includePrerelease ? '-0' : '';
|
|
2493
2502
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
2494
2503
|
debug('tilde', comp, _, M, m, p, pr);
|
|
2495
2504
|
let ret;
|
|
@@ -2497,10 +2506,10 @@ function requireRange () {
|
|
|
2497
2506
|
if (isX(M)) {
|
|
2498
2507
|
ret = '';
|
|
2499
2508
|
} else if (isX(m)) {
|
|
2500
|
-
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
2509
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
2501
2510
|
} else if (isX(p)) {
|
|
2502
2511
|
// ~1.2 == >=1.2.0 <1.3.0-0
|
|
2503
|
-
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
2512
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
2504
2513
|
} else if (pr) {
|
|
2505
2514
|
debug('replaceTilde pr', pr);
|
|
2506
2515
|
ret = `>=${M}.${m}.${p}-${pr
|
|
@@ -2569,10 +2578,10 @@ function requireRange () {
|
|
|
2569
2578
|
if (M === '0') {
|
|
2570
2579
|
if (m === '0') {
|
|
2571
2580
|
ret = `>=${M}.${m}.${p
|
|
2572
|
-
}
|
|
2581
|
+
} <${M}.${m}.${+p + 1}-0`;
|
|
2573
2582
|
} else {
|
|
2574
2583
|
ret = `>=${M}.${m}.${p
|
|
2575
|
-
}
|
|
2584
|
+
} <${M}.${+m + 1}.0-0`;
|
|
2576
2585
|
}
|
|
2577
2586
|
} else {
|
|
2578
2587
|
ret = `>=${M}.${m}.${p
|
|
@@ -2598,6 +2607,10 @@ function requireRange () {
|
|
|
2598
2607
|
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
2599
2608
|
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
2600
2609
|
debug('xRange', comp, ret, gtlt, M, m, p, pr);
|
|
2610
|
+
if (invalidXRangeOrder(M, m, p)) {
|
|
2611
|
+
return comp
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2601
2614
|
const xM = isX(M);
|
|
2602
2615
|
const xm = xM || isX(m);
|
|
2603
2616
|
const xp = xm || isX(p);
|
|
@@ -4947,6 +4960,42 @@ class State extends Contract {
|
|
|
4947
4960
|
get resolving() {
|
|
4948
4961
|
return this.#resolving;
|
|
4949
4962
|
}
|
|
4963
|
+
async #resolveLastBlockMessage(result) {
|
|
4964
|
+
if (result instanceof Uint8Array) {
|
|
4965
|
+
try {
|
|
4966
|
+
let payload = result;
|
|
4967
|
+
for (let i = 0; i < 3; i += 1) {
|
|
4968
|
+
try {
|
|
4969
|
+
const wrapped = await new globalThis.peernet.protos["peernet-response"](payload);
|
|
4970
|
+
if (wrapped?.decoded?.response === void 0) break;
|
|
4971
|
+
payload = wrapped.decoded.response;
|
|
4972
|
+
} catch {
|
|
4973
|
+
break;
|
|
4974
|
+
}
|
|
4975
|
+
}
|
|
4976
|
+
if (payload !== result) return this.#resolveLastBlockMessage(payload);
|
|
4977
|
+
return new LastBlockMessage(result);
|
|
4978
|
+
} catch {
|
|
4979
|
+
const candidate = new TextDecoder().decode(result);
|
|
4980
|
+
if (candidate) {
|
|
4981
|
+
const blockData = await globalThis.peernet.get(candidate, "block");
|
|
4982
|
+
if (blockData) return new BlockMessage(blockData);
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
if (typeof result === "string") {
|
|
4987
|
+
const blockData = await globalThis.peernet.get(result, "block");
|
|
4988
|
+
if (blockData) return new BlockMessage(blockData);
|
|
4989
|
+
}
|
|
4990
|
+
if (result && typeof result === "object") {
|
|
4991
|
+
const response = result.decoded?.response ?? result.response;
|
|
4992
|
+
if (response !== void 0) return this.#resolveLastBlockMessage(response);
|
|
4993
|
+
if ("hash" in result && "index" in result) {
|
|
4994
|
+
return new LastBlockMessage(result);
|
|
4995
|
+
}
|
|
4996
|
+
}
|
|
4997
|
+
throw new Error(`invalid lastBlock payload: ${typeof result}`);
|
|
4998
|
+
}
|
|
4950
4999
|
get contracts() {
|
|
4951
5000
|
return this.#machine.contracts;
|
|
4952
5001
|
}
|
|
@@ -5386,7 +5435,7 @@ class State extends Contract {
|
|
|
5386
5435
|
}
|
|
5387
5436
|
}
|
|
5388
5437
|
}
|
|
5389
|
-
return { result
|
|
5438
|
+
return { result, peer };
|
|
5390
5439
|
} catch (error) {
|
|
5391
5440
|
const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
|
|
5392
5441
|
debug$1(`lastBlock request failed: ${peerId}:`, error?.message ?? error);
|
|
@@ -5407,6 +5456,12 @@ class State extends Contract {
|
|
|
5407
5456
|
throw new ResolveError("latestBlock: no responses from compatible peers");
|
|
5408
5457
|
}
|
|
5409
5458
|
console.log({ promises });
|
|
5459
|
+
promises = await Promise.all(
|
|
5460
|
+
promises.map(async (item) => ({
|
|
5461
|
+
value: (await this.#resolveLastBlockMessage(item.value)).decoded,
|
|
5462
|
+
peer: item.peer
|
|
5463
|
+
}))
|
|
5464
|
+
);
|
|
5410
5465
|
let latest = { index: 0, hash: "0x0", previousHash: "0x0" };
|
|
5411
5466
|
promises = promises.sort((a, b) => b.index - a.index);
|
|
5412
5467
|
if (promises.length > 0) latest = promises[0].value;
|
|
@@ -6453,6 +6508,42 @@ class Chain extends VersionControl {
|
|
|
6453
6508
|
throw error;
|
|
6454
6509
|
}
|
|
6455
6510
|
}
|
|
6511
|
+
async #resolveLastBlockMessage(result) {
|
|
6512
|
+
if (result instanceof Uint8Array) {
|
|
6513
|
+
try {
|
|
6514
|
+
let payload = result;
|
|
6515
|
+
for (let i = 0; i < 3; i += 1) {
|
|
6516
|
+
try {
|
|
6517
|
+
const wrapped = await new globalThis.peernet.protos["peernet-response"](payload);
|
|
6518
|
+
if (wrapped?.decoded?.response === void 0) break;
|
|
6519
|
+
payload = wrapped.decoded.response;
|
|
6520
|
+
} catch {
|
|
6521
|
+
break;
|
|
6522
|
+
}
|
|
6523
|
+
}
|
|
6524
|
+
if (payload !== result) return this.#resolveLastBlockMessage(payload);
|
|
6525
|
+
return new LastBlockMessage(result);
|
|
6526
|
+
} catch {
|
|
6527
|
+
const candidate = new TextDecoder().decode(result);
|
|
6528
|
+
if (candidate) {
|
|
6529
|
+
const blockData = await globalThis.peernet.get(candidate, "block");
|
|
6530
|
+
if (blockData) return new BlockMessage(blockData);
|
|
6531
|
+
}
|
|
6532
|
+
}
|
|
6533
|
+
}
|
|
6534
|
+
if (typeof result === "string") {
|
|
6535
|
+
const blockData = await globalThis.peernet.get(result, "block");
|
|
6536
|
+
if (blockData) return new BlockMessage(blockData);
|
|
6537
|
+
}
|
|
6538
|
+
if (result && typeof result === "object") {
|
|
6539
|
+
const response = result.decoded?.response ?? result.response;
|
|
6540
|
+
if (response !== void 0) return this.#resolveLastBlockMessage(response);
|
|
6541
|
+
if ("hash" in result && "index" in result) {
|
|
6542
|
+
return new LastBlockMessage(result);
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
throw new Error(`invalid lastBlock payload: ${typeof result}`);
|
|
6546
|
+
}
|
|
6456
6547
|
async #decodeKnownBlocksResponse(response) {
|
|
6457
6548
|
if (!response) return null;
|
|
6458
6549
|
if (Array.isArray(response)) {
|
|
@@ -6578,11 +6669,12 @@ class Chain extends VersionControl {
|
|
|
6578
6669
|
console.log(await this.lastBlock);
|
|
6579
6670
|
const lastBlockRaw = await this.#makeRequest(peer, "lastBlock");
|
|
6580
6671
|
console.log("raw last block response:", lastBlockRaw);
|
|
6581
|
-
if (lastBlockRaw === void 0 || lastBlockRaw === null
|
|
6672
|
+
if (lastBlockRaw === void 0 || lastBlockRaw === null) {
|
|
6582
6673
|
throw new Error(`invalid lastBlock payload: ${typeof lastBlockRaw}`);
|
|
6583
6674
|
}
|
|
6584
|
-
|
|
6585
|
-
|
|
6675
|
+
const lastBlockMessage = await this.#resolveLastBlockMessage(lastBlockRaw);
|
|
6676
|
+
console.log(lastBlockMessage);
|
|
6677
|
+
lastBlock = lastBlockMessage.decoded;
|
|
6586
6678
|
} catch (error) {
|
|
6587
6679
|
const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
|
|
6588
6680
|
debug(`lastBlock request failed: ${peerName}:`, error?.message ?? error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as inflate_1, c as createDebugger, d as deflate_1, L as LittlePubSub } from './node-browser-
|
|
1
|
+
import { i as inflate_1, c as createDebugger, d as deflate_1, L as LittlePubSub } from './node-browser-Cdgaf6tz.js';
|
|
2
2
|
import 'crypto';
|
|
3
3
|
import './constants-COpvMqFX.js';
|
|
4
4
|
|
|
@@ -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-
|
|
234
|
+
globalThis.WebSocket = (await import('./browser-tK3uOLQV-CtcRBohi.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-
|
|
1305
|
+
const koushWrtcModule = await import('./browser-DEjI2nFg-CL-zDjzl.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');
|
|
@@ -1853,14 +1853,15 @@ class Client {
|
|
|
1853
1853
|
return peer;
|
|
1854
1854
|
};
|
|
1855
1855
|
#peerJoined = async ({ peerId, version, transport }, star) => {
|
|
1856
|
-
// check if peer rejoined before the previous connection closed
|
|
1857
|
-
if (this.#connections[peerId]) {
|
|
1858
|
-
this.#connections[peerId].destroy();
|
|
1859
|
-
delete this.#connections[peerId];
|
|
1860
|
-
}
|
|
1861
1856
|
if (this.peerId === peerId)
|
|
1862
1857
|
return;
|
|
1863
|
-
|
|
1858
|
+
// Stars can announce the same peer more than once while its transport is
|
|
1859
|
+
// still negotiating. Keep that connection/attempt alive; destroying it
|
|
1860
|
+
// here makes simultaneous joins continually reset each other.
|
|
1861
|
+
// Both sides receive the discovery event. Elect exactly one offerer so
|
|
1862
|
+
// simultaneous joins do not create competing channels/SDP negotiations.
|
|
1863
|
+
const initiator = String(this.peerId) < String(peerId);
|
|
1864
|
+
this.#startPeerTransportAttempt(peerId, star, version, initiator, transport);
|
|
1864
1865
|
debug(`peer ${peerId} joined`);
|
|
1865
1866
|
};
|
|
1866
1867
|
#inComingSignal = async ({ from, signal, channelName, version }, star) => {
|
|
@@ -1926,12 +1927,16 @@ class Client {
|
|
|
1926
1927
|
});
|
|
1927
1928
|
};
|
|
1928
1929
|
#peerClose = (peer) => {
|
|
1930
|
+
// A failed transport can finish closing after fallback has already placed a
|
|
1931
|
+
// replacement in the connection map. Never let that stale close delete or
|
|
1932
|
+
// advance the replacement's active attempt.
|
|
1933
|
+
if (this.#connections[peer.peerId] !== peer) {
|
|
1934
|
+
debug(`ignored stale close for ${peer.peerId}`);
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1929
1937
|
const wasConnected = peer.connected;
|
|
1930
1938
|
this.#peerTransportKinds.delete(peer.peerId);
|
|
1931
|
-
|
|
1932
|
-
peer.destroy();
|
|
1933
|
-
delete this.#connections[peer.peerId];
|
|
1934
|
-
}
|
|
1939
|
+
delete this.#connections[peer.peerId];
|
|
1935
1940
|
if (!wasConnected && this.#peerTransportAttempts.has(peer.peerId)) {
|
|
1936
1941
|
this.#advanceTransportAttempt(peer.peerId);
|
|
1937
1942
|
}
|