ns-auth-sdk 1.14.0 → 1.14.2
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/{cjs-CSUAVztq.cjs → browser-index.cjs} +5476 -296
- package/dist/browser-index.cjs.map +1 -0
- package/dist/browser-index.d.cts +1998 -0
- package/dist/browser-index.d.cts.map +1 -0
- package/dist/browser-index.d.mts +1998 -0
- package/dist/browser-index.d.mts.map +1 -0
- package/dist/{cjs-sm5h7qxv.mjs → browser-index.mjs} +5169 -69
- package/dist/browser-index.mjs.map +1 -0
- package/dist/{group-coordination-BlFpBVpn.mjs → group-coordination-BV6PKlKp.mjs} +1 -1
- package/dist/{group-coordination-BlFpBVpn.mjs.map → group-coordination-BV6PKlKp.mjs.map} +1 -1
- package/dist/{group-coordination-ImuoJEoy.mjs → group-coordination-BytkmY9j.mjs} +1 -1
- package/dist/{group-coordination-LGIyipaX.cjs → group-coordination-DL39hJ3R.cjs} +1 -1
- package/dist/{group-coordination-LGIyipaX.cjs.map → group-coordination-DL39hJ3R.cjs.map} +1 -1
- package/dist/{group-coordination-Cf18OjZt.cjs → group-coordination-DLban6a7.cjs} +1 -1
- package/dist/index.cjs +8899 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.mjs +9072 -213
- package/dist/index.mjs.map +1 -1
- package/dist/{prf-handler-D3EqUNWe.cjs → prf-handler-BNd7gmXJ.cjs} +1 -1
- package/dist/{prf-handler-D3EqUNWe.cjs.map → prf-handler-BNd7gmXJ.cjs.map} +1 -1
- package/dist/prf-handler-CRMgzJG2.cjs +3 -0
- package/dist/{prf-handler-Dly_WZGn.mjs → prf-handler-DG99ZkS2.mjs} +1 -1
- package/dist/{prf-handler-Db8CsoIP.mjs → prf-handler-Dj2WTO9i.mjs} +1 -1
- package/dist/{prf-handler-Db8CsoIP.mjs.map → prf-handler-Dj2WTO9i.mjs.map} +1 -1
- package/dist/zkm.service-Bv88tVS5.mjs +3 -0
- package/dist/zkm.service-D2BZ_aqA.cjs +3 -0
- package/dist/{zkm.service-DfSPbuOl.cjs → zkm.service-DX06sSfB.cjs} +1 -1
- package/dist/{zkm.service-DfSPbuOl.cjs.map → zkm.service-DX06sSfB.cjs.map} +1 -1
- package/dist/{zkm.service-B24N_0FB.mjs → zkm.service-j0HlN7Oq.mjs} +1 -1
- package/dist/{zkm.service-B24N_0FB.mjs.map → zkm.service-j0HlN7Oq.mjs.map} +1 -1
- package/package.json +19 -6
- package/dist/_esm-C7FRLTj2.cjs +0 -9030
- package/dist/_esm-C7FRLTj2.cjs.map +0 -1
- package/dist/_esm-D_oMW5T5.mjs +0 -9028
- package/dist/_esm-D_oMW5T5.mjs.map +0 -1
- package/dist/base64-js-B8y7dH5k.mjs +0 -93
- package/dist/base64-js-B8y7dH5k.mjs.map +0 -1
- package/dist/base64-js-Tm-kCeud.cjs +0 -98
- package/dist/base64-js-Tm-kCeud.cjs.map +0 -1
- package/dist/ccip-157tdxqP.cjs +0 -7947
- package/dist/ccip-157tdxqP.cjs.map +0 -1
- package/dist/ccip-BEMMdVyd.cjs +0 -4
- package/dist/ccip-BSmCdJ3K.mjs +0 -3
- package/dist/ccip-okqXkslP.mjs +0 -6567
- package/dist/ccip-okqXkslP.mjs.map +0 -1
- package/dist/chains-CTeD2UcS.mjs +0 -33
- package/dist/chains-CTeD2UcS.mjs.map +0 -1
- package/dist/chains-Du-lv_5i.cjs +0 -33
- package/dist/chains-Du-lv_5i.cjs.map +0 -1
- package/dist/chunk-Bnu9O96Y.cjs +0 -60
- package/dist/chunk-CVYhg9ik.mjs +0 -45
- package/dist/cjs-CSUAVztq.cjs.map +0 -1
- package/dist/cjs-sm5h7qxv.mjs.map +0 -1
- package/dist/defineChain-7QG67hYU.cjs +0 -30
- package/dist/defineChain-7QG67hYU.cjs.map +0 -1
- package/dist/defineChain-DBem8ZQY.mjs +0 -24
- package/dist/defineChain-DBem8ZQY.mjs.map +0 -1
- package/dist/dist-BPmSxkxc.cjs +0 -10676
- package/dist/dist-BPmSxkxc.cjs.map +0 -1
- package/dist/dist-BSjH4t6s.cjs +0 -12932
- package/dist/dist-BSjH4t6s.cjs.map +0 -1
- package/dist/dist-C-KjTK4Q.cjs +0 -447
- package/dist/dist-C-KjTK4Q.cjs.map +0 -1
- package/dist/dist-C2h97xM-.mjs +0 -355
- package/dist/dist-C2h97xM-.mjs.map +0 -1
- package/dist/dist-CT7grDWb.mjs +0 -12920
- package/dist/dist-CT7grDWb.mjs.map +0 -1
- package/dist/dist-D7fRmK6G.mjs +0 -10632
- package/dist/dist-D7fRmK6G.mjs.map +0 -1
- package/dist/dist-DlmcyFmM.mjs +0 -16951
- package/dist/dist-DlmcyFmM.mjs.map +0 -1
- package/dist/dist-O0uZr5OF.cjs +0 -17122
- package/dist/dist-O0uZr5OF.cjs.map +0 -1
- package/dist/echo-BB-JgAYZ.cjs +0 -339
- package/dist/echo-BB-JgAYZ.cjs.map +0 -1
- package/dist/echo-Bwy4_Cvh.mjs +0 -316
- package/dist/echo-Bwy4_Cvh.mjs.map +0 -1
- package/dist/echo-D6X2IuNW.cjs +0 -9
- package/dist/echo-DvfG_heb.mjs +0 -8
- package/dist/esm-BcHKCX5i.mjs +0 -569
- package/dist/esm-BcHKCX5i.mjs.map +0 -1
- package/dist/esm-Bh_YwFIz.cjs +0 -599
- package/dist/esm-Bh_YwFIz.cjs.map +0 -1
- package/dist/esm-C0XO9TQm.cjs +0 -30449
- package/dist/esm-C0XO9TQm.cjs.map +0 -1
- package/dist/esm-vMUVj9k4.mjs +0 -30440
- package/dist/esm-vMUVj9k4.mjs.map +0 -1
- package/dist/keyset-CKMQXvsb.mjs +0 -172
- package/dist/keyset-CKMQXvsb.mjs.map +0 -1
- package/dist/keyset-Cxdgu110.cjs +0 -237
- package/dist/keyset-Cxdgu110.cjs.map +0 -1
- package/dist/keyset-DLxpGhdu.cjs +0 -6
- package/dist/keyset-IKjlhvqF.mjs +0 -4
- package/dist/node-3EUJ4ga9.cjs +0 -9
- package/dist/node-C2UpE11T.cjs +0 -444
- package/dist/node-C2UpE11T.cjs.map +0 -1
- package/dist/node-CHdpTQdN.mjs +0 -8679
- package/dist/node-CHdpTQdN.mjs.map +0 -1
- package/dist/node-DQt1CVGl.mjs +0 -6
- package/dist/node-Dy8ww1LG.cjs +0 -8680
- package/dist/node-Dy8ww1LG.cjs.map +0 -1
- package/dist/node-IX55IH6z.mjs +0 -397
- package/dist/node-IX55IH6z.mjs.map +0 -1
- package/dist/nostr-BTOpBN_5.cjs +0 -11
- package/dist/nostr-D4E52XRU.mjs +0 -224
- package/dist/nostr-D4E52XRU.mjs.map +0 -1
- package/dist/nostr-Hv2tsnuI.cjs +0 -272
- package/dist/nostr-Hv2tsnuI.cjs.map +0 -1
- package/dist/nostr-ZwJe_DlZ.mjs +0 -4
- package/dist/pako.esm-DTVnlCJh.cjs +0 -3856
- package/dist/pako.esm-DTVnlCJh.cjs.map +0 -1
- package/dist/pako.esm-ORhkEHM2.mjs +0 -3838
- package/dist/pako.esm-ORhkEHM2.mjs.map +0 -1
- package/dist/peer-B9g3OQ5D.cjs +0 -18
- package/dist/peer-CptDj7zu.mjs +0 -745
- package/dist/peer-CptDj7zu.mjs.map +0 -1
- package/dist/peer-CtqL0yiE.mjs +0 -9
- package/dist/peer-XrPL0O6z.cjs +0 -822
- package/dist/peer-XrPL0O6z.cjs.map +0 -1
- package/dist/ping-BXKREIdI.mjs +0 -7
- package/dist/ping-BtVhKocl.cjs +0 -379
- package/dist/ping-BtVhKocl.cjs.map +0 -1
- package/dist/ping-D5fpMhGC.cjs +0 -11
- package/dist/ping-DOD50kW_.mjs +0 -332
- package/dist/ping-DOD50kW_.mjs.map +0 -1
- package/dist/policy-8HcjulLD.cjs +0 -293
- package/dist/policy-8HcjulLD.cjs.map +0 -1
- package/dist/policy-BA6MEOBY.mjs +0 -5
- package/dist/policy-BFNdXvmM.cjs +0 -11
- package/dist/policy-D_nFHHjo.mjs +0 -228
- package/dist/policy-D_nFHHjo.mjs.map +0 -1
- package/dist/prf-handler-BNiyCQMt.cjs +0 -3
- package/dist/src-CVfTUJQl.mjs +0 -822
- package/dist/src-CVfTUJQl.mjs.map +0 -1
- package/dist/src-D5S86Xpf.cjs +0 -827
- package/dist/src-D5S86Xpf.cjs.map +0 -1
- package/dist/types-B-TLIS13.cjs +0 -212
- package/dist/types-B-TLIS13.cjs.map +0 -1
- package/dist/types-CTm_FHYD.mjs +0 -111
- package/dist/types-CTm_FHYD.mjs.map +0 -1
- package/dist/validation-1xwWVXqE.mjs +0 -3
- package/dist/validation-DnpurN79.cjs +0 -405
- package/dist/validation-DnpurN79.cjs.map +0 -1
- package/dist/validation-IsAUvsvy.mjs +0 -334
- package/dist/validation-IsAUvsvy.mjs.map +0 -1
- package/dist/validation-yCvZCqIs.cjs +0 -6
- package/dist/wrapper-C5NpyacC.cjs +0 -3552
- package/dist/wrapper-C5NpyacC.cjs.map +0 -1
- package/dist/wrapper-CHq_CV4J.mjs +0 -3552
- package/dist/wrapper-CHq_CV4J.mjs.map +0 -1
- package/dist/zkm.service-BrXyI4BS.mjs +0 -3
- package/dist/zkm.service-BvQ01wSH.cjs +0 -3
package/dist/peer-XrPL0O6z.cjs
DELETED
|
@@ -1,822 +0,0 @@
|
|
|
1
|
-
const require_types = require('./types-B-TLIS13.cjs');
|
|
2
|
-
const require_keyset = require('./keyset-Cxdgu110.cjs');
|
|
3
|
-
const require_ping = require('./ping-BtVhKocl.cjs');
|
|
4
|
-
|
|
5
|
-
//#region node_modules/@frostr/igloo-core/dist/peer.js
|
|
6
|
-
/**
|
|
7
|
-
* Utility functions for pubkey handling
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Normalize a pubkey by removing 02/03 prefix if present
|
|
11
|
-
*/
|
|
12
|
-
function normalizePubkey(pubkey) {
|
|
13
|
-
if (!pubkey || typeof pubkey !== "string") return pubkey;
|
|
14
|
-
if ((pubkey.startsWith("02") || pubkey.startsWith("03")) && pubkey.length === 66) return pubkey.slice(2);
|
|
15
|
-
return pubkey;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Add 02 prefix to a pubkey if it's missing (convert to compressed format)
|
|
19
|
-
*/
|
|
20
|
-
function addPubkeyPrefix(pubkey, prefix = "02") {
|
|
21
|
-
if (!pubkey || typeof pubkey !== "string") return pubkey;
|
|
22
|
-
if ((pubkey.startsWith("02") || pubkey.startsWith("03")) && pubkey.length === 66) return pubkey;
|
|
23
|
-
if (pubkey.length === 64) return prefix + pubkey;
|
|
24
|
-
return pubkey;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Compare two pubkeys after normalization
|
|
28
|
-
*/
|
|
29
|
-
function comparePubkeys(pubkey1, pubkey2) {
|
|
30
|
-
return normalizePubkey(pubkey1) === normalizePubkey(pubkey2);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Extract self pubkey from credentials with enhanced error handling
|
|
34
|
-
*/
|
|
35
|
-
function extractSelfPubkeyFromCredentials(groupCredential, shareCredential, options = {}) {
|
|
36
|
-
const warnings = [];
|
|
37
|
-
const { normalize = true, suppressWarnings = false } = options;
|
|
38
|
-
try {
|
|
39
|
-
if (!shareCredential || !groupCredential) {
|
|
40
|
-
const warning = "Missing credentials for self pubkey extraction";
|
|
41
|
-
if (!suppressWarnings) warnings.push(warning);
|
|
42
|
-
return {
|
|
43
|
-
pubkey: null,
|
|
44
|
-
warnings
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const decodedShare = require_keyset.decodeShare(shareCredential);
|
|
48
|
-
const decodedGroup = require_keyset.decodeGroup(groupCredential);
|
|
49
|
-
if (!decodedShare?.idx || !decodedGroup?.commits) {
|
|
50
|
-
const warning = "Invalid credential structure for self pubkey extraction";
|
|
51
|
-
if (!suppressWarnings) warnings.push(warning);
|
|
52
|
-
return {
|
|
53
|
-
pubkey: null,
|
|
54
|
-
warnings
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const shareIndex = decodedShare.idx - 1;
|
|
58
|
-
if (shareIndex < 0 || shareIndex >= decodedGroup.commits.length) {
|
|
59
|
-
const warning = "Share index out of range for self pubkey extraction";
|
|
60
|
-
if (!suppressWarnings) warnings.push(warning);
|
|
61
|
-
return {
|
|
62
|
-
pubkey: null,
|
|
63
|
-
warnings
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const selfPubkeyCommit = decodedGroup.commits[shareIndex];
|
|
67
|
-
const selfPubkey = typeof selfPubkeyCommit === "string" ? selfPubkeyCommit : selfPubkeyCommit.pubkey;
|
|
68
|
-
if (!selfPubkey) {
|
|
69
|
-
const warning = "Could not extract self public key from credentials";
|
|
70
|
-
if (!suppressWarnings) warnings.push(warning);
|
|
71
|
-
return {
|
|
72
|
-
pubkey: null,
|
|
73
|
-
warnings
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
pubkey: normalize ? normalizePubkey(selfPubkey) : selfPubkey,
|
|
78
|
-
warnings
|
|
79
|
-
};
|
|
80
|
-
} catch (error) {
|
|
81
|
-
const warning = `Failed to extract self pubkey: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
82
|
-
if (!suppressWarnings) warnings.push(warning);
|
|
83
|
-
return {
|
|
84
|
-
pubkey: null,
|
|
85
|
-
warnings
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Default peer monitoring configuration
|
|
91
|
-
*/
|
|
92
|
-
const DEFAULT_PEER_MONITOR_CONFIG = {
|
|
93
|
-
pingInterval: require_ping.DEFAULT_PING_INTERVAL,
|
|
94
|
-
pingTimeout: require_ping.DEFAULT_PING_TIMEOUT,
|
|
95
|
-
autoMonitor: true,
|
|
96
|
-
enableLogging: false,
|
|
97
|
-
suppressWarnings: false,
|
|
98
|
-
onPeerStatusChange: void 0
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Static peer manager for fallback scenarios when live monitoring fails
|
|
102
|
-
*/
|
|
103
|
-
var StaticPeerManager = class {
|
|
104
|
-
constructor(peerPubkeys, warnings = [], config = {}) {
|
|
105
|
-
this.peers = peerPubkeys.map((pubkey) => ({
|
|
106
|
-
pubkey: normalizePubkey(pubkey),
|
|
107
|
-
status: "unknown",
|
|
108
|
-
lastSeen: void 0,
|
|
109
|
-
allowSend: true,
|
|
110
|
-
allowReceive: true
|
|
111
|
-
}));
|
|
112
|
-
this.warnings = warnings;
|
|
113
|
-
this.config = {
|
|
114
|
-
...DEFAULT_PEER_MONITOR_CONFIG,
|
|
115
|
-
...config
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
getPeerStatus() {
|
|
119
|
-
return {
|
|
120
|
-
peers: this.peers,
|
|
121
|
-
onlinePeers: [],
|
|
122
|
-
offlinePeers: this.peers,
|
|
123
|
-
totalPeers: this.peers.length,
|
|
124
|
-
onlineCount: 0,
|
|
125
|
-
lastChecked: /* @__PURE__ */ new Date()
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
getAllPeers() {
|
|
129
|
-
return [...this.peers];
|
|
130
|
-
}
|
|
131
|
-
getOnlinePeers() {
|
|
132
|
-
return [];
|
|
133
|
-
}
|
|
134
|
-
getOfflinePeers() {
|
|
135
|
-
return [...this.peers];
|
|
136
|
-
}
|
|
137
|
-
getOnlineCount() {
|
|
138
|
-
return 0;
|
|
139
|
-
}
|
|
140
|
-
isPeerOnline(pubkey) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
getPeer(pubkey) {
|
|
144
|
-
return this.peers.find((p) => p.pubkey === pubkey);
|
|
145
|
-
}
|
|
146
|
-
getWarnings() {
|
|
147
|
-
return [...this.warnings];
|
|
148
|
-
}
|
|
149
|
-
async pingPeers() {
|
|
150
|
-
this.log("warn", "Ping not supported in static peer manager mode");
|
|
151
|
-
return this.getPeerStatus();
|
|
152
|
-
}
|
|
153
|
-
startMonitoring() {
|
|
154
|
-
this.log("warn", "Live monitoring not available in static peer manager mode");
|
|
155
|
-
}
|
|
156
|
-
stopMonitoring() {
|
|
157
|
-
this.log("warn", "No monitoring to stop in static peer manager mode");
|
|
158
|
-
}
|
|
159
|
-
updateConfig(config) {
|
|
160
|
-
this.log("warn", "Configuration updates not supported in static peer manager mode");
|
|
161
|
-
}
|
|
162
|
-
cleanup() {
|
|
163
|
-
this.peers = [];
|
|
164
|
-
this.warnings = [];
|
|
165
|
-
}
|
|
166
|
-
log(level, message, data) {
|
|
167
|
-
if (level === "warn" && this.config.suppressWarnings) return;
|
|
168
|
-
if (this.config.customLogger) this.config.customLogger(level, `[StaticPeerManager] ${message}`, data);
|
|
169
|
-
else if (this.config.enableLogging) (level === "error" ? console.error : level === "warn" ? console.warn : level === "debug" ? console.debug : console.log)(`[StaticPeerManager] [${level.toUpperCase()}] ${message}`, data || "");
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Enhanced peer manager class leveraging the new ping functionality
|
|
174
|
-
*/
|
|
175
|
-
var PeerManager = class {
|
|
176
|
-
constructor(node, selfPubkey, config = {}) {
|
|
177
|
-
this.peers = /* @__PURE__ */ new Map();
|
|
178
|
-
this.node = node;
|
|
179
|
-
this.selfPubkey = selfPubkey;
|
|
180
|
-
this.config = {
|
|
181
|
-
...DEFAULT_PEER_MONITOR_CONFIG,
|
|
182
|
-
...config
|
|
183
|
-
};
|
|
184
|
-
this.messageHandler = this.handleMessage.bind(this);
|
|
185
|
-
this.pingResponseHandler = this.handlePingResponse.bind(this);
|
|
186
|
-
this.setupEventListeners();
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Handle incoming messages to mark peers as online
|
|
190
|
-
*/
|
|
191
|
-
handleMessage(msg) {
|
|
192
|
-
if (!msg || typeof msg !== "object") return;
|
|
193
|
-
const peerPubkey = msg.pub || msg.pubkey || msg.from;
|
|
194
|
-
if (peerPubkey) {
|
|
195
|
-
const normalizedPubkey = normalizePubkey(peerPubkey);
|
|
196
|
-
if (this.peers.has(normalizedPubkey)) this.updatePeerStatus(normalizedPubkey, "online");
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Handle ping responses to mark peers as online
|
|
201
|
-
*/
|
|
202
|
-
handlePingResponse(msg) {
|
|
203
|
-
const peerPubkey = msg.pub || msg.pubkey || msg.from;
|
|
204
|
-
if (peerPubkey) {
|
|
205
|
-
const normalizedPubkey = normalizePubkey(peerPubkey);
|
|
206
|
-
if (this.peers.has(normalizedPubkey)) this.updatePeerStatus(normalizedPubkey, "online");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Set up event listeners for backward compatibility
|
|
211
|
-
*/
|
|
212
|
-
setupEventListeners() {
|
|
213
|
-
this.node.on("message", this.messageHandler);
|
|
214
|
-
this.node.on("/ping/sender/res", this.pingResponseHandler);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Initialize peer list from group configuration
|
|
218
|
-
*/
|
|
219
|
-
initializePeers(groupCredential, shareCredential) {
|
|
220
|
-
try {
|
|
221
|
-
const peers = extractPeersFromCredentials(groupCredential, shareCredential);
|
|
222
|
-
this.initializePeersFromList(peers);
|
|
223
|
-
if (this.config.autoMonitor) this.startMonitoring();
|
|
224
|
-
} catch (error) {
|
|
225
|
-
throw new require_types.NodeError(`Failed to initialize peers: ${error.message}`, {
|
|
226
|
-
groupCredential,
|
|
227
|
-
shareCredential,
|
|
228
|
-
error
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Initialize peers from a pre-validated list
|
|
234
|
-
*/
|
|
235
|
-
initializePeersFromList(peerPubkeys) {
|
|
236
|
-
this.peers.clear();
|
|
237
|
-
peerPubkeys.forEach((pubkey) => {
|
|
238
|
-
const normalizedPubkey = normalizePubkey(pubkey);
|
|
239
|
-
this.peers.set(normalizedPubkey, {
|
|
240
|
-
pubkey: normalizedPubkey,
|
|
241
|
-
status: "unknown",
|
|
242
|
-
lastSeen: void 0,
|
|
243
|
-
allowSend: true,
|
|
244
|
-
allowReceive: true
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
this.log("info", `Initialized ${peerPubkeys.length} peers`);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Update the status of a specific peer (public for backward compatibility)
|
|
251
|
-
*/
|
|
252
|
-
updatePeerStatus(pubkey, status) {
|
|
253
|
-
const normalizedPubkey = normalizePubkey(pubkey);
|
|
254
|
-
const peer = this.peers.get(normalizedPubkey);
|
|
255
|
-
if (!peer) return;
|
|
256
|
-
const oldStatus = peer.status;
|
|
257
|
-
peer.status = status;
|
|
258
|
-
peer.lastSeen = status === "online" ? /* @__PURE__ */ new Date() : peer.lastSeen;
|
|
259
|
-
if (oldStatus !== peer.status && this.config.onPeerStatusChange) this.config.onPeerStatusChange(peer);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Update the status of a specific peer from ping result
|
|
263
|
-
*/
|
|
264
|
-
updatePeerFromPingResult(result) {
|
|
265
|
-
const normalizedPubkey = normalizePubkey(result.pubkey);
|
|
266
|
-
const peer = this.peers.get(normalizedPubkey);
|
|
267
|
-
if (!peer) return;
|
|
268
|
-
const oldStatus = peer.status;
|
|
269
|
-
peer.status = result.success ? "online" : "offline";
|
|
270
|
-
peer.lastSeen = result.success ? result.timestamp : peer.lastSeen;
|
|
271
|
-
peer.latency = result.latency;
|
|
272
|
-
peer.policy = result.policy;
|
|
273
|
-
if (oldStatus !== peer.status && this.config.onPeerStatusChange) this.config.onPeerStatusChange(peer);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Ping all peers using the new ping functionality
|
|
277
|
-
*/
|
|
278
|
-
async pingPeers() {
|
|
279
|
-
try {
|
|
280
|
-
const peerPubkeys = Array.from(this.peers.keys());
|
|
281
|
-
if (peerPubkeys.length === 0) {
|
|
282
|
-
this.log("warn", "No peers to ping");
|
|
283
|
-
return this.getPeerStatus();
|
|
284
|
-
}
|
|
285
|
-
this.log("debug", `Pinging ${peerPubkeys.length} peers`);
|
|
286
|
-
(await require_ping.pingPeers(this.node, peerPubkeys, {
|
|
287
|
-
timeout: this.config.pingTimeout,
|
|
288
|
-
eventConfig: { enableLogging: this.config.enableLogging }
|
|
289
|
-
})).forEach((result) => this.updatePeerFromPingResult(result));
|
|
290
|
-
const status = this.getPeerStatus();
|
|
291
|
-
this.log("info", `Ping complete: ${status.onlineCount}/${status.totalPeers} peers online`);
|
|
292
|
-
return status;
|
|
293
|
-
} catch (error) {
|
|
294
|
-
this.handleError(error, "pingPeers");
|
|
295
|
-
for (const peer of this.peers.values()) peer.status = "unknown";
|
|
296
|
-
return this.getPeerStatus();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Get current peer status with enhanced information
|
|
301
|
-
*/
|
|
302
|
-
getPeerStatus() {
|
|
303
|
-
const peers = Array.from(this.peers.values());
|
|
304
|
-
const onlinePeers = peers.filter((p) => p.status === "online");
|
|
305
|
-
const offlinePeers = peers.filter((p) => p.status === "offline");
|
|
306
|
-
const latencies = onlinePeers.map((p) => p.latency).filter((latency) => latency !== void 0);
|
|
307
|
-
const averageLatency = latencies.length > 0 ? latencies.reduce((sum, latency) => sum + latency, 0) / latencies.length : void 0;
|
|
308
|
-
return {
|
|
309
|
-
peers,
|
|
310
|
-
onlinePeers,
|
|
311
|
-
offlinePeers,
|
|
312
|
-
totalPeers: peers.length,
|
|
313
|
-
onlineCount: onlinePeers.length,
|
|
314
|
-
lastChecked: /* @__PURE__ */ new Date(),
|
|
315
|
-
averageLatency
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Start automatic peer monitoring using the ping monitor
|
|
320
|
-
*/
|
|
321
|
-
startMonitoring() {
|
|
322
|
-
if (this.pingMonitor) this.pingMonitor.stop();
|
|
323
|
-
const peerPubkeys = Array.from(this.peers.keys());
|
|
324
|
-
if (peerPubkeys.length === 0) {
|
|
325
|
-
this.log("warn", "No peers to monitor");
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
try {
|
|
329
|
-
this.pingMonitor = require_ping.createPingMonitor(this.node, peerPubkeys, {
|
|
330
|
-
interval: this.config.pingInterval,
|
|
331
|
-
timeout: this.config.pingTimeout,
|
|
332
|
-
onPingResult: (result) => {
|
|
333
|
-
this.updatePeerFromPingResult(result);
|
|
334
|
-
},
|
|
335
|
-
onError: (error, context) => {
|
|
336
|
-
this.handleError(error, `monitor:${context}`);
|
|
337
|
-
},
|
|
338
|
-
eventConfig: { enableLogging: this.config.enableLogging }
|
|
339
|
-
});
|
|
340
|
-
this.pingMonitor.start();
|
|
341
|
-
this.log("info", `Started monitoring ${peerPubkeys.length} peers (interval: ${this.config.pingInterval}ms)`);
|
|
342
|
-
} catch (error) {
|
|
343
|
-
this.handleError(error, "startMonitoring");
|
|
344
|
-
throw new require_types.NodeError(`Failed to start peer monitoring: ${error.message}`, { error });
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Stop automatic peer monitoring
|
|
349
|
-
*/
|
|
350
|
-
stopMonitoring() {
|
|
351
|
-
if (this.pingMonitor) {
|
|
352
|
-
this.pingMonitor.stop();
|
|
353
|
-
this.log("info", "Stopped peer monitoring");
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Update monitoring configuration
|
|
358
|
-
*/
|
|
359
|
-
updateConfig(config) {
|
|
360
|
-
const wasMonitoring = this.pingMonitor?.isRunning;
|
|
361
|
-
this.config = {
|
|
362
|
-
...this.config,
|
|
363
|
-
...config
|
|
364
|
-
};
|
|
365
|
-
if (wasMonitoring && (config.pingInterval || config.pingTimeout)) {
|
|
366
|
-
this.stopMonitoring();
|
|
367
|
-
this.startMonitoring();
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Ping a specific peer
|
|
372
|
-
*/
|
|
373
|
-
async pingPeer(pubkey) {
|
|
374
|
-
if (!this.peers.has(pubkey)) throw new require_types.NodeError(`Peer not found: ${pubkey}`, { pubkey });
|
|
375
|
-
try {
|
|
376
|
-
const result = await require_ping.pingPeer(this.node, pubkey, {
|
|
377
|
-
timeout: this.config.pingTimeout,
|
|
378
|
-
eventConfig: { enableLogging: this.config.enableLogging }
|
|
379
|
-
});
|
|
380
|
-
this.updatePeerFromPingResult(result);
|
|
381
|
-
return result;
|
|
382
|
-
} catch (error) {
|
|
383
|
-
this.handleError(error, "pingPeer");
|
|
384
|
-
throw error;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Get a specific peer by public key
|
|
389
|
-
*/
|
|
390
|
-
getPeer(pubkey) {
|
|
391
|
-
return this.peers.get(pubkey);
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Get all peers
|
|
395
|
-
*/
|
|
396
|
-
getAllPeers() {
|
|
397
|
-
return Array.from(this.peers.values());
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Get online peers only
|
|
401
|
-
*/
|
|
402
|
-
getOnlinePeers() {
|
|
403
|
-
return Array.from(this.peers.values()).filter((p) => p.status === "online");
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Get offline peers only
|
|
407
|
-
*/
|
|
408
|
-
getOfflinePeers() {
|
|
409
|
-
return Array.from(this.peers.values()).filter((p) => p.status === "offline");
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Check if a specific peer is online
|
|
413
|
-
*/
|
|
414
|
-
isPeerOnline(pubkey) {
|
|
415
|
-
return this.peers.get(pubkey)?.status === "online" || false;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Get the count of online peers
|
|
419
|
-
*/
|
|
420
|
-
getOnlineCount() {
|
|
421
|
-
return Array.from(this.peers.values()).filter((p) => p.status === "online").length;
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Cleanup resources
|
|
425
|
-
*/
|
|
426
|
-
cleanup() {
|
|
427
|
-
const nodeAny = this.node;
|
|
428
|
-
if (typeof nodeAny.off === "function") {
|
|
429
|
-
nodeAny.off("message", this.messageHandler);
|
|
430
|
-
nodeAny.off("/ping/sender/res", this.pingResponseHandler);
|
|
431
|
-
} else if (typeof nodeAny.removeListener === "function") {
|
|
432
|
-
nodeAny.removeListener("message", this.messageHandler);
|
|
433
|
-
nodeAny.removeListener("/ping/sender/res", this.pingResponseHandler);
|
|
434
|
-
} else if (typeof nodeAny.removeAllListeners === "function") {
|
|
435
|
-
nodeAny.removeAllListeners("message");
|
|
436
|
-
nodeAny.removeAllListeners("/ping/sender/res");
|
|
437
|
-
}
|
|
438
|
-
this.stopMonitoring();
|
|
439
|
-
if (this.pingMonitor) {
|
|
440
|
-
this.pingMonitor.cleanup();
|
|
441
|
-
this.pingMonitor = void 0;
|
|
442
|
-
}
|
|
443
|
-
this.peers.clear();
|
|
444
|
-
this.log("info", "Peer manager cleaned up");
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Handle errors with optional callback
|
|
448
|
-
*/
|
|
449
|
-
handleError(error, context) {
|
|
450
|
-
if (this.config.onError) this.config.onError(error, context);
|
|
451
|
-
else this.log("error", `Error in ${context}: ${error.message}`);
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Internal logging
|
|
455
|
-
*/
|
|
456
|
-
log(level, message, data) {
|
|
457
|
-
if (level === "warn" && this.config.suppressWarnings) return;
|
|
458
|
-
if (this.config.customLogger) this.config.customLogger(level, `[PeerManager] ${message}`, data);
|
|
459
|
-
else if (this.config.enableLogging) (level === "error" ? console.error : level === "warn" ? console.warn : level === "debug" ? console.debug : console.log)(`[PeerManager] [${level.toUpperCase()}] ${message}`, data || "");
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
/**
|
|
463
|
-
* Extract peers from group credentials using improved error handling
|
|
464
|
-
*/
|
|
465
|
-
function extractPeersFromCredentials(groupCredential, shareCredential) {
|
|
466
|
-
try {
|
|
467
|
-
return extractPeersFromGroup(require_keyset.decodeGroup(groupCredential), extractSelfPubkey(require_keyset.decodeShare(shareCredential)));
|
|
468
|
-
} catch (error) {
|
|
469
|
-
throw new require_types.NodeError(`Failed to extract peers from credentials: ${error.message}`, {
|
|
470
|
-
groupCredential,
|
|
471
|
-
shareCredential,
|
|
472
|
-
error
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Extract self public key from share with multiple strategies
|
|
478
|
-
*/
|
|
479
|
-
function extractSelfPubkey(share) {
|
|
480
|
-
const shareAny = share;
|
|
481
|
-
if (shareAny.pubkey && typeof shareAny.pubkey === "string") return shareAny.pubkey;
|
|
482
|
-
if (shareAny.pub && typeof shareAny.pub === "string") return shareAny.pub;
|
|
483
|
-
if (shareAny.public_key && typeof shareAny.public_key === "string") return shareAny.public_key;
|
|
484
|
-
throw new require_types.NodeError("Could not extract self public key from share credential", { availableFields: Object.keys(shareAny) });
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Extract peers from group package
|
|
488
|
-
*/
|
|
489
|
-
function extractPeersFromGroup(group, selfPubkey) {
|
|
490
|
-
const groupAny = group;
|
|
491
|
-
let allPubkeys = [];
|
|
492
|
-
if (group.commits && Array.isArray(group.commits)) {
|
|
493
|
-
const commitPubkeys = group.commits.map((commit) => commit?.pubkey).filter((pubkey) => pubkey && typeof pubkey === "string" && pubkey.length > 0);
|
|
494
|
-
allPubkeys.push(...commitPubkeys);
|
|
495
|
-
}
|
|
496
|
-
if (allPubkeys.length === 0 && groupAny.participants && Array.isArray(groupAny.participants)) {
|
|
497
|
-
const participantPubkeys = groupAny.participants.filter((pubkey) => pubkey && typeof pubkey === "string" && pubkey.length > 0);
|
|
498
|
-
allPubkeys.push(...participantPubkeys);
|
|
499
|
-
}
|
|
500
|
-
if (allPubkeys.length === 0 && groupAny.members && Array.isArray(groupAny.members)) {
|
|
501
|
-
const memberPubkeys = groupAny.members.map((member) => {
|
|
502
|
-
if (typeof member === "string") return member;
|
|
503
|
-
if (member?.pubkey) return member.pubkey;
|
|
504
|
-
if (member?.pub) return member.pub;
|
|
505
|
-
return null;
|
|
506
|
-
}).filter((pubkey) => pubkey && typeof pubkey === "string" && pubkey.length > 0);
|
|
507
|
-
allPubkeys.push(...memberPubkeys);
|
|
508
|
-
}
|
|
509
|
-
if (allPubkeys.length === 0) throw new require_types.NodeError("No peer public keys found in group", {
|
|
510
|
-
checkedFields: [
|
|
511
|
-
"commits",
|
|
512
|
-
"participants",
|
|
513
|
-
"members"
|
|
514
|
-
],
|
|
515
|
-
groupStructure: Object.keys(groupAny)
|
|
516
|
-
});
|
|
517
|
-
return [...new Set(allPubkeys)].filter((pubkey) => pubkey !== selfPubkey);
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Simple function to ping peers and get online peer pubkeys (legacy compatibility)
|
|
521
|
-
* @deprecated Use PeerManager.pingPeers() or pingPeersInternal() instead
|
|
522
|
-
*/
|
|
523
|
-
async function pingPeers(node, timeout = require_ping.DEFAULT_PING_TIMEOUT) {
|
|
524
|
-
try {
|
|
525
|
-
const result = await node.req?.ping?.();
|
|
526
|
-
if (result && result.ok) {
|
|
527
|
-
if (Array.isArray(result.data)) return result.data;
|
|
528
|
-
else if (result.data && typeof result.data === "object") return Object.keys(result.data);
|
|
529
|
-
}
|
|
530
|
-
return [];
|
|
531
|
-
} catch (error) {
|
|
532
|
-
console.warn("Ping operation failed:", error);
|
|
533
|
-
return [];
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Create a PeerManager instance with a connected BifrostNode
|
|
538
|
-
*/
|
|
539
|
-
async function createPeerManager(node, groupCredential, shareCredential, config = {}) {
|
|
540
|
-
try {
|
|
541
|
-
const validation = await validatePeerCredentials(groupCredential, shareCredential);
|
|
542
|
-
if (!validation.isValid) throw new require_types.NodeError(`Invalid credentials: ${validation.error}`, { validation });
|
|
543
|
-
const peerManager = new PeerManager(node, validation.selfPubkey, config);
|
|
544
|
-
peerManager.initializePeersFromList(validation.peers);
|
|
545
|
-
return peerManager;
|
|
546
|
-
} catch (error) {
|
|
547
|
-
throw new require_types.NodeError(`Failed to create peer manager: ${error.message}`, {
|
|
548
|
-
groupCredential,
|
|
549
|
-
shareCredential,
|
|
550
|
-
error
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Simple peer status check function using ping functionality
|
|
556
|
-
*/
|
|
557
|
-
async function checkPeerStatus(node, groupCredential, shareCredential) {
|
|
558
|
-
try {
|
|
559
|
-
return (await require_ping.pingPeers(node, extractPeersFromCredentials(groupCredential, shareCredential), {
|
|
560
|
-
timeout: require_ping.DEFAULT_PING_TIMEOUT,
|
|
561
|
-
eventConfig: { enableLogging: false }
|
|
562
|
-
})).map((result) => ({
|
|
563
|
-
pubkey: result.pubkey,
|
|
564
|
-
status: result.success ? "online" : "offline"
|
|
565
|
-
}));
|
|
566
|
-
} catch (error) {
|
|
567
|
-
throw new require_types.NodeError(`Failed to check peer status: ${error.message}`, {
|
|
568
|
-
groupCredential,
|
|
569
|
-
shareCredential,
|
|
570
|
-
error
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* Validate peer credentials before creating peer manager
|
|
576
|
-
*/
|
|
577
|
-
async function validatePeerCredentials(groupCredential, shareCredential) {
|
|
578
|
-
const warnings = [];
|
|
579
|
-
try {
|
|
580
|
-
let group;
|
|
581
|
-
try {
|
|
582
|
-
group = require_keyset.decodeGroup(groupCredential);
|
|
583
|
-
} catch (error) {
|
|
584
|
-
return {
|
|
585
|
-
isValid: false,
|
|
586
|
-
error: `Invalid group credential: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
587
|
-
peerCount: 0,
|
|
588
|
-
peers: [],
|
|
589
|
-
warnings
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
let share;
|
|
593
|
-
try {
|
|
594
|
-
share = require_keyset.decodeShare(shareCredential);
|
|
595
|
-
} catch (error) {
|
|
596
|
-
return {
|
|
597
|
-
isValid: false,
|
|
598
|
-
error: `Invalid share credential: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
599
|
-
peerCount: 0,
|
|
600
|
-
peers: [],
|
|
601
|
-
warnings
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
let selfPubkey;
|
|
605
|
-
try {
|
|
606
|
-
selfPubkey = extractSelfPubkey(share);
|
|
607
|
-
} catch (error) {
|
|
608
|
-
return {
|
|
609
|
-
isValid: false,
|
|
610
|
-
error: `Could not extract self public key: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
611
|
-
peerCount: 0,
|
|
612
|
-
peers: [],
|
|
613
|
-
warnings
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
let peers;
|
|
617
|
-
try {
|
|
618
|
-
peers = extractPeersFromGroup(group, selfPubkey);
|
|
619
|
-
} catch (error) {
|
|
620
|
-
return {
|
|
621
|
-
isValid: false,
|
|
622
|
-
error: `Peer extraction failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
623
|
-
peerCount: 0,
|
|
624
|
-
peers: [],
|
|
625
|
-
warnings
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
if (peers.length === 0) warnings.push("No other peers found in group - this might be a single-member group");
|
|
629
|
-
else if (peers.length === 1) warnings.push("Only one other peer found in group");
|
|
630
|
-
return {
|
|
631
|
-
isValid: true,
|
|
632
|
-
peerCount: peers.length,
|
|
633
|
-
peers,
|
|
634
|
-
selfPubkey,
|
|
635
|
-
warnings
|
|
636
|
-
};
|
|
637
|
-
} catch (error) {
|
|
638
|
-
return {
|
|
639
|
-
isValid: false,
|
|
640
|
-
error: `Validation failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
641
|
-
peerCount: 0,
|
|
642
|
-
peers: [],
|
|
643
|
-
warnings
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Enhanced peer manager creation with robust error handling and fallback options
|
|
649
|
-
*/
|
|
650
|
-
async function createPeerManagerRobust(node, groupCredential, shareCredential, config) {
|
|
651
|
-
const enhancedConfig = {
|
|
652
|
-
...DEFAULT_PEER_MONITOR_CONFIG,
|
|
653
|
-
...config
|
|
654
|
-
};
|
|
655
|
-
try {
|
|
656
|
-
const selfPubkeyResult = extractSelfPubkeyFromCredentials(groupCredential, shareCredential, {
|
|
657
|
-
normalize: true,
|
|
658
|
-
suppressWarnings: enhancedConfig.suppressWarnings
|
|
659
|
-
});
|
|
660
|
-
const validation = await validatePeerCredentials(groupCredential, shareCredential);
|
|
661
|
-
if (!validation.isValid) if (enhancedConfig.fallbackMode === "static") try {
|
|
662
|
-
return {
|
|
663
|
-
success: true,
|
|
664
|
-
peerManager: new StaticPeerManager(extractBasicPeers(groupCredential, shareCredential), [...enhancedConfig.suppressWarnings ? [] : [`Live monitoring disabled: ${validation.error}`], ...enhancedConfig.suppressWarnings ? [] : ["Using static peer list as fallback"]], enhancedConfig),
|
|
665
|
-
mode: "static",
|
|
666
|
-
warnings: enhancedConfig.suppressWarnings ? [] : [`Peer monitoring disabled: ${validation.error}`, "Fallback to static peer list enabled"]
|
|
667
|
-
};
|
|
668
|
-
} catch (fallbackError) {
|
|
669
|
-
return {
|
|
670
|
-
success: false,
|
|
671
|
-
error: `Primary and fallback failed: ${validation.error}`,
|
|
672
|
-
mode: "failed"
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
else return {
|
|
676
|
-
success: false,
|
|
677
|
-
error: validation.error,
|
|
678
|
-
mode: "failed"
|
|
679
|
-
};
|
|
680
|
-
try {
|
|
681
|
-
const peerManager = new PeerManager(node, selfPubkeyResult.pubkey || validation.selfPubkey, {
|
|
682
|
-
...enhancedConfig,
|
|
683
|
-
autoMonitor: false
|
|
684
|
-
});
|
|
685
|
-
const normalizedPeers = validation.peers.map((pubkey) => normalizePubkey(pubkey));
|
|
686
|
-
peerManager.initializePeersFromList(normalizedPeers);
|
|
687
|
-
if (enhancedConfig.autoMonitor) try {
|
|
688
|
-
peerManager.startMonitoring();
|
|
689
|
-
} catch (monitorError) {
|
|
690
|
-
if (enhancedConfig.onError) enhancedConfig.onError(monitorError, "startMonitoring");
|
|
691
|
-
if (enhancedConfig.fallbackMode === "static") return {
|
|
692
|
-
success: true,
|
|
693
|
-
peerManager: new StaticPeerManager(normalizedPeers, [...enhancedConfig.suppressWarnings ? [] : [`Live monitoring failed: ${monitorError instanceof Error ? monitorError.message : "Unknown error"}`], ...enhancedConfig.suppressWarnings ? [] : ["Switched to static peer list mode"]], enhancedConfig),
|
|
694
|
-
mode: "static",
|
|
695
|
-
warnings: enhancedConfig.suppressWarnings ? [] : [`Monitoring initialization failed, using static mode`, ...validation.warnings || []]
|
|
696
|
-
};
|
|
697
|
-
else throw monitorError;
|
|
698
|
-
}
|
|
699
|
-
return {
|
|
700
|
-
success: true,
|
|
701
|
-
peerManager,
|
|
702
|
-
mode: "full",
|
|
703
|
-
warnings: enhancedConfig.suppressWarnings ? [] : [...selfPubkeyResult.warnings, ...validation.warnings || []]
|
|
704
|
-
};
|
|
705
|
-
} catch (managerError) {
|
|
706
|
-
if (enhancedConfig.onError) enhancedConfig.onError(managerError, "createPeerManager");
|
|
707
|
-
if (enhancedConfig.fallbackMode === "static") return {
|
|
708
|
-
success: true,
|
|
709
|
-
peerManager: new StaticPeerManager(validation.peers.map((pubkey) => normalizePubkey(pubkey)), [...enhancedConfig.suppressWarnings ? [] : [`PeerManager creation failed: ${managerError instanceof Error ? managerError.message : "Unknown error"}`], ...enhancedConfig.suppressWarnings ? [] : ["Using static peer list as fallback"]], enhancedConfig),
|
|
710
|
-
mode: "static",
|
|
711
|
-
warnings: enhancedConfig.suppressWarnings ? [] : [`Full peer manager creation failed, using static mode`, ...validation.warnings || []]
|
|
712
|
-
};
|
|
713
|
-
else throw managerError;
|
|
714
|
-
}
|
|
715
|
-
} catch (error) {
|
|
716
|
-
if (enhancedConfig.onError) enhancedConfig.onError(error, "createPeerManagerRobust");
|
|
717
|
-
return {
|
|
718
|
-
success: false,
|
|
719
|
-
error: `Peer manager creation failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
720
|
-
mode: "failed"
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* Basic peer extraction for fallback scenarios
|
|
726
|
-
*/
|
|
727
|
-
function extractBasicPeers(groupCredential, shareCredential) {
|
|
728
|
-
try {
|
|
729
|
-
return extractPeersFromCredentials(groupCredential, shareCredential);
|
|
730
|
-
} catch (error) {
|
|
731
|
-
try {
|
|
732
|
-
const group = require_keyset.decodeGroup(groupCredential);
|
|
733
|
-
const groupAny = group;
|
|
734
|
-
if (groupAny.participants && Array.isArray(groupAny.participants)) return groupAny.participants.filter((p) => p && typeof p === "string");
|
|
735
|
-
if (group.commits && Array.isArray(group.commits)) return group.commits.map((c) => c?.pubkey).filter((p) => p && typeof p === "string");
|
|
736
|
-
return [];
|
|
737
|
-
} catch {
|
|
738
|
-
return [];
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
//#endregion
|
|
744
|
-
Object.defineProperty(exports, 'DEFAULT_PEER_MONITOR_CONFIG', {
|
|
745
|
-
enumerable: true,
|
|
746
|
-
get: function () {
|
|
747
|
-
return DEFAULT_PEER_MONITOR_CONFIG;
|
|
748
|
-
}
|
|
749
|
-
});
|
|
750
|
-
Object.defineProperty(exports, 'PeerManager', {
|
|
751
|
-
enumerable: true,
|
|
752
|
-
get: function () {
|
|
753
|
-
return PeerManager;
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
Object.defineProperty(exports, 'StaticPeerManager', {
|
|
757
|
-
enumerable: true,
|
|
758
|
-
get: function () {
|
|
759
|
-
return StaticPeerManager;
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
Object.defineProperty(exports, 'addPubkeyPrefix', {
|
|
763
|
-
enumerable: true,
|
|
764
|
-
get: function () {
|
|
765
|
-
return addPubkeyPrefix;
|
|
766
|
-
}
|
|
767
|
-
});
|
|
768
|
-
Object.defineProperty(exports, 'checkPeerStatus', {
|
|
769
|
-
enumerable: true,
|
|
770
|
-
get: function () {
|
|
771
|
-
return checkPeerStatus;
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
Object.defineProperty(exports, 'comparePubkeys', {
|
|
775
|
-
enumerable: true,
|
|
776
|
-
get: function () {
|
|
777
|
-
return comparePubkeys;
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
Object.defineProperty(exports, 'createPeerManager', {
|
|
781
|
-
enumerable: true,
|
|
782
|
-
get: function () {
|
|
783
|
-
return createPeerManager;
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
Object.defineProperty(exports, 'createPeerManagerRobust', {
|
|
787
|
-
enumerable: true,
|
|
788
|
-
get: function () {
|
|
789
|
-
return createPeerManagerRobust;
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
Object.defineProperty(exports, 'extractPeersFromCredentials', {
|
|
793
|
-
enumerable: true,
|
|
794
|
-
get: function () {
|
|
795
|
-
return extractPeersFromCredentials;
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
Object.defineProperty(exports, 'extractSelfPubkeyFromCredentials', {
|
|
799
|
-
enumerable: true,
|
|
800
|
-
get: function () {
|
|
801
|
-
return extractSelfPubkeyFromCredentials;
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
Object.defineProperty(exports, 'normalizePubkey', {
|
|
805
|
-
enumerable: true,
|
|
806
|
-
get: function () {
|
|
807
|
-
return normalizePubkey;
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
Object.defineProperty(exports, 'pingPeers', {
|
|
811
|
-
enumerable: true,
|
|
812
|
-
get: function () {
|
|
813
|
-
return pingPeers;
|
|
814
|
-
}
|
|
815
|
-
});
|
|
816
|
-
Object.defineProperty(exports, 'validatePeerCredentials', {
|
|
817
|
-
enumerable: true,
|
|
818
|
-
get: function () {
|
|
819
|
-
return validatePeerCredentials;
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
//# sourceMappingURL=peer-XrPL0O6z.cjs.map
|