cairn-p2p 0.3.2 → 0.4.1
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/dist/browser.cjs +26 -1
- package/dist/browser.d.cts +3 -1
- package/dist/browser.d.ts +3 -1
- package/dist/browser.js +26 -1
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/index.cjs +3463 -25
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +29 -2
- package/dist/{libp2p-node-4XKNTJT4.js → libp2p-node-AJLSFZN2.js} +2 -0
- package/dist/src-CNFSUBMM.js +2966 -0
- package/package.json +2 -2
- package/src/node.ts +35 -1
package/dist/browser.cjs
CHANGED
|
@@ -1629,6 +1629,8 @@ var Node = class _Node {
|
|
|
1629
1629
|
_libp2pNode = null;
|
|
1630
1630
|
/** Listen addresses reported by the libp2p node. */
|
|
1631
1631
|
_listenAddresses = [];
|
|
1632
|
+
/** Connection hints from pairing, keyed by peer ID hex string. */
|
|
1633
|
+
_peerHints = /* @__PURE__ */ new Map();
|
|
1632
1634
|
constructor(config) {
|
|
1633
1635
|
this._config = config;
|
|
1634
1636
|
}
|
|
@@ -1803,6 +1805,9 @@ var Node = class _Node {
|
|
|
1803
1805
|
const payload = consumeQrPayload(data);
|
|
1804
1806
|
this._runPairingExchange(payload.pakeCredential);
|
|
1805
1807
|
const remotePeerId = bytesToHex3(payload.peerId);
|
|
1808
|
+
if (payload.hints && payload.hints.length > 0) {
|
|
1809
|
+
this._peerHints.set(remotePeerId, payload.hints);
|
|
1810
|
+
}
|
|
1806
1811
|
this._completePairing(remotePeerId);
|
|
1807
1812
|
return remotePeerId;
|
|
1808
1813
|
}
|
|
@@ -1838,8 +1843,28 @@ var Node = class _Node {
|
|
|
1838
1843
|
return remotePeerId;
|
|
1839
1844
|
}
|
|
1840
1845
|
// --- Connection methods ---
|
|
1841
|
-
/** Connect to a paired peer.
|
|
1846
|
+
/** Connect to a paired peer. Dials via libp2p if transport is started, falls back to in-memory handshake. */
|
|
1842
1847
|
async connect(peerId, _options) {
|
|
1848
|
+
if (this._libp2pNode && this._peerHints.has(peerId)) {
|
|
1849
|
+
const hints = this._peerHints.get(peerId);
|
|
1850
|
+
const { multiaddr } = await import("@multiformats/multiaddr");
|
|
1851
|
+
const wsHints = hints.filter((h) => h.hintType === "multiaddr" && h.value.includes("/ws"));
|
|
1852
|
+
const tcpHints = hints.filter((h) => h.hintType === "multiaddr" && h.value.includes("/tcp/") && !h.value.includes("/ws"));
|
|
1853
|
+
const allHints = [...wsHints, ...tcpHints];
|
|
1854
|
+
let connected = false;
|
|
1855
|
+
for (const hint of allHints) {
|
|
1856
|
+
try {
|
|
1857
|
+
const ma = multiaddr(hint.value);
|
|
1858
|
+
await this._libp2pNode.dial(ma);
|
|
1859
|
+
connected = true;
|
|
1860
|
+
break;
|
|
1861
|
+
} catch {
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (!connected && allHints.length > 0) {
|
|
1865
|
+
throw new CairnError("TRANSPORT", `failed to connect to peer ${peerId} via any address`);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1843
1868
|
const handshakeResult = await this._performNoiseHandshake();
|
|
1844
1869
|
const bobDh = X25519Keypair.generate();
|
|
1845
1870
|
const ratchet = DoubleRatchet.initSender(handshakeResult.sessionKey, bobDh.publicKeyBytes());
|
package/dist/browser.d.cts
CHANGED
|
@@ -464,6 +464,8 @@ declare class Node {
|
|
|
464
464
|
private _libp2pNode;
|
|
465
465
|
/** Listen addresses reported by the libp2p node. */
|
|
466
466
|
private _listenAddresses;
|
|
467
|
+
/** Connection hints from pairing, keyed by peer ID hex string. */
|
|
468
|
+
private readonly _peerHints;
|
|
467
469
|
private constructor();
|
|
468
470
|
/** Create a new cairn peer node with zero-config defaults (Tier 0). */
|
|
469
471
|
static create(config?: Partial<CairnConfig>): Promise<Node>;
|
|
@@ -522,7 +524,7 @@ declare class Node {
|
|
|
522
524
|
pairEnterPin(pin: string): Promise<string>;
|
|
523
525
|
pairGenerateLink(): Promise<LinkPairingData>;
|
|
524
526
|
pairFromLink(uri: string): Promise<string>;
|
|
525
|
-
/** Connect to a paired peer.
|
|
527
|
+
/** Connect to a paired peer. Dials via libp2p if transport is started, falls back to in-memory handshake. */
|
|
526
528
|
connect(peerId: string, _options?: {
|
|
527
529
|
signal?: AbortSignal;
|
|
528
530
|
}): Promise<NodeSession>;
|
package/dist/browser.d.ts
CHANGED
|
@@ -464,6 +464,8 @@ declare class Node {
|
|
|
464
464
|
private _libp2pNode;
|
|
465
465
|
/** Listen addresses reported by the libp2p node. */
|
|
466
466
|
private _listenAddresses;
|
|
467
|
+
/** Connection hints from pairing, keyed by peer ID hex string. */
|
|
468
|
+
private readonly _peerHints;
|
|
467
469
|
private constructor();
|
|
468
470
|
/** Create a new cairn peer node with zero-config defaults (Tier 0). */
|
|
469
471
|
static create(config?: Partial<CairnConfig>): Promise<Node>;
|
|
@@ -522,7 +524,7 @@ declare class Node {
|
|
|
522
524
|
pairEnterPin(pin: string): Promise<string>;
|
|
523
525
|
pairGenerateLink(): Promise<LinkPairingData>;
|
|
524
526
|
pairFromLink(uri: string): Promise<string>;
|
|
525
|
-
/** Connect to a paired peer.
|
|
527
|
+
/** Connect to a paired peer. Dials via libp2p if transport is started, falls back to in-memory handshake. */
|
|
526
528
|
connect(peerId: string, _options?: {
|
|
527
529
|
signal?: AbortSignal;
|
|
528
530
|
}): Promise<NodeSession>;
|
package/dist/browser.js
CHANGED
|
@@ -1581,6 +1581,8 @@ var Node = class _Node {
|
|
|
1581
1581
|
_libp2pNode = null;
|
|
1582
1582
|
/** Listen addresses reported by the libp2p node. */
|
|
1583
1583
|
_listenAddresses = [];
|
|
1584
|
+
/** Connection hints from pairing, keyed by peer ID hex string. */
|
|
1585
|
+
_peerHints = /* @__PURE__ */ new Map();
|
|
1584
1586
|
constructor(config) {
|
|
1585
1587
|
this._config = config;
|
|
1586
1588
|
}
|
|
@@ -1755,6 +1757,9 @@ var Node = class _Node {
|
|
|
1755
1757
|
const payload = consumeQrPayload(data);
|
|
1756
1758
|
this._runPairingExchange(payload.pakeCredential);
|
|
1757
1759
|
const remotePeerId = bytesToHex3(payload.peerId);
|
|
1760
|
+
if (payload.hints && payload.hints.length > 0) {
|
|
1761
|
+
this._peerHints.set(remotePeerId, payload.hints);
|
|
1762
|
+
}
|
|
1758
1763
|
this._completePairing(remotePeerId);
|
|
1759
1764
|
return remotePeerId;
|
|
1760
1765
|
}
|
|
@@ -1790,8 +1795,28 @@ var Node = class _Node {
|
|
|
1790
1795
|
return remotePeerId;
|
|
1791
1796
|
}
|
|
1792
1797
|
// --- Connection methods ---
|
|
1793
|
-
/** Connect to a paired peer.
|
|
1798
|
+
/** Connect to a paired peer. Dials via libp2p if transport is started, falls back to in-memory handshake. */
|
|
1794
1799
|
async connect(peerId, _options) {
|
|
1800
|
+
if (this._libp2pNode && this._peerHints.has(peerId)) {
|
|
1801
|
+
const hints = this._peerHints.get(peerId);
|
|
1802
|
+
const { multiaddr } = await import("@multiformats/multiaddr");
|
|
1803
|
+
const wsHints = hints.filter((h) => h.hintType === "multiaddr" && h.value.includes("/ws"));
|
|
1804
|
+
const tcpHints = hints.filter((h) => h.hintType === "multiaddr" && h.value.includes("/tcp/") && !h.value.includes("/ws"));
|
|
1805
|
+
const allHints = [...wsHints, ...tcpHints];
|
|
1806
|
+
let connected = false;
|
|
1807
|
+
for (const hint of allHints) {
|
|
1808
|
+
try {
|
|
1809
|
+
const ma = multiaddr(hint.value);
|
|
1810
|
+
await this._libp2pNode.dial(ma);
|
|
1811
|
+
connected = true;
|
|
1812
|
+
break;
|
|
1813
|
+
} catch {
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
if (!connected && allHints.length > 0) {
|
|
1817
|
+
throw new CairnError("TRANSPORT", `failed to connect to peer ${peerId} via any address`);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1795
1820
|
const handshakeResult = await this._performNoiseHandshake();
|
|
1796
1821
|
const bobDh = X25519Keypair.generate();
|
|
1797
1822
|
const ratchet = DoubleRatchet.initSender(handshakeResult.sessionKey, bobDh.publicKeyBytes());
|