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.
Files changed (153) hide show
  1. package/dist/{cjs-CSUAVztq.cjs → browser-index.cjs} +5476 -296
  2. package/dist/browser-index.cjs.map +1 -0
  3. package/dist/browser-index.d.cts +1998 -0
  4. package/dist/browser-index.d.cts.map +1 -0
  5. package/dist/browser-index.d.mts +1998 -0
  6. package/dist/browser-index.d.mts.map +1 -0
  7. package/dist/{cjs-sm5h7qxv.mjs → browser-index.mjs} +5169 -69
  8. package/dist/browser-index.mjs.map +1 -0
  9. package/dist/{group-coordination-BlFpBVpn.mjs → group-coordination-BV6PKlKp.mjs} +1 -1
  10. package/dist/{group-coordination-BlFpBVpn.mjs.map → group-coordination-BV6PKlKp.mjs.map} +1 -1
  11. package/dist/{group-coordination-ImuoJEoy.mjs → group-coordination-BytkmY9j.mjs} +1 -1
  12. package/dist/{group-coordination-LGIyipaX.cjs → group-coordination-DL39hJ3R.cjs} +1 -1
  13. package/dist/{group-coordination-LGIyipaX.cjs.map → group-coordination-DL39hJ3R.cjs.map} +1 -1
  14. package/dist/{group-coordination-Cf18OjZt.cjs → group-coordination-DLban6a7.cjs} +1 -1
  15. package/dist/index.cjs +8899 -41
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts.map +1 -1
  18. package/dist/index.mjs +9072 -213
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{prf-handler-D3EqUNWe.cjs → prf-handler-BNd7gmXJ.cjs} +1 -1
  21. package/dist/{prf-handler-D3EqUNWe.cjs.map → prf-handler-BNd7gmXJ.cjs.map} +1 -1
  22. package/dist/prf-handler-CRMgzJG2.cjs +3 -0
  23. package/dist/{prf-handler-Dly_WZGn.mjs → prf-handler-DG99ZkS2.mjs} +1 -1
  24. package/dist/{prf-handler-Db8CsoIP.mjs → prf-handler-Dj2WTO9i.mjs} +1 -1
  25. package/dist/{prf-handler-Db8CsoIP.mjs.map → prf-handler-Dj2WTO9i.mjs.map} +1 -1
  26. package/dist/zkm.service-Bv88tVS5.mjs +3 -0
  27. package/dist/zkm.service-D2BZ_aqA.cjs +3 -0
  28. package/dist/{zkm.service-DfSPbuOl.cjs → zkm.service-DX06sSfB.cjs} +1 -1
  29. package/dist/{zkm.service-DfSPbuOl.cjs.map → zkm.service-DX06sSfB.cjs.map} +1 -1
  30. package/dist/{zkm.service-B24N_0FB.mjs → zkm.service-j0HlN7Oq.mjs} +1 -1
  31. package/dist/{zkm.service-B24N_0FB.mjs.map → zkm.service-j0HlN7Oq.mjs.map} +1 -1
  32. package/package.json +19 -6
  33. package/dist/_esm-C7FRLTj2.cjs +0 -9030
  34. package/dist/_esm-C7FRLTj2.cjs.map +0 -1
  35. package/dist/_esm-D_oMW5T5.mjs +0 -9028
  36. package/dist/_esm-D_oMW5T5.mjs.map +0 -1
  37. package/dist/base64-js-B8y7dH5k.mjs +0 -93
  38. package/dist/base64-js-B8y7dH5k.mjs.map +0 -1
  39. package/dist/base64-js-Tm-kCeud.cjs +0 -98
  40. package/dist/base64-js-Tm-kCeud.cjs.map +0 -1
  41. package/dist/ccip-157tdxqP.cjs +0 -7947
  42. package/dist/ccip-157tdxqP.cjs.map +0 -1
  43. package/dist/ccip-BEMMdVyd.cjs +0 -4
  44. package/dist/ccip-BSmCdJ3K.mjs +0 -3
  45. package/dist/ccip-okqXkslP.mjs +0 -6567
  46. package/dist/ccip-okqXkslP.mjs.map +0 -1
  47. package/dist/chains-CTeD2UcS.mjs +0 -33
  48. package/dist/chains-CTeD2UcS.mjs.map +0 -1
  49. package/dist/chains-Du-lv_5i.cjs +0 -33
  50. package/dist/chains-Du-lv_5i.cjs.map +0 -1
  51. package/dist/chunk-Bnu9O96Y.cjs +0 -60
  52. package/dist/chunk-CVYhg9ik.mjs +0 -45
  53. package/dist/cjs-CSUAVztq.cjs.map +0 -1
  54. package/dist/cjs-sm5h7qxv.mjs.map +0 -1
  55. package/dist/defineChain-7QG67hYU.cjs +0 -30
  56. package/dist/defineChain-7QG67hYU.cjs.map +0 -1
  57. package/dist/defineChain-DBem8ZQY.mjs +0 -24
  58. package/dist/defineChain-DBem8ZQY.mjs.map +0 -1
  59. package/dist/dist-BPmSxkxc.cjs +0 -10676
  60. package/dist/dist-BPmSxkxc.cjs.map +0 -1
  61. package/dist/dist-BSjH4t6s.cjs +0 -12932
  62. package/dist/dist-BSjH4t6s.cjs.map +0 -1
  63. package/dist/dist-C-KjTK4Q.cjs +0 -447
  64. package/dist/dist-C-KjTK4Q.cjs.map +0 -1
  65. package/dist/dist-C2h97xM-.mjs +0 -355
  66. package/dist/dist-C2h97xM-.mjs.map +0 -1
  67. package/dist/dist-CT7grDWb.mjs +0 -12920
  68. package/dist/dist-CT7grDWb.mjs.map +0 -1
  69. package/dist/dist-D7fRmK6G.mjs +0 -10632
  70. package/dist/dist-D7fRmK6G.mjs.map +0 -1
  71. package/dist/dist-DlmcyFmM.mjs +0 -16951
  72. package/dist/dist-DlmcyFmM.mjs.map +0 -1
  73. package/dist/dist-O0uZr5OF.cjs +0 -17122
  74. package/dist/dist-O0uZr5OF.cjs.map +0 -1
  75. package/dist/echo-BB-JgAYZ.cjs +0 -339
  76. package/dist/echo-BB-JgAYZ.cjs.map +0 -1
  77. package/dist/echo-Bwy4_Cvh.mjs +0 -316
  78. package/dist/echo-Bwy4_Cvh.mjs.map +0 -1
  79. package/dist/echo-D6X2IuNW.cjs +0 -9
  80. package/dist/echo-DvfG_heb.mjs +0 -8
  81. package/dist/esm-BcHKCX5i.mjs +0 -569
  82. package/dist/esm-BcHKCX5i.mjs.map +0 -1
  83. package/dist/esm-Bh_YwFIz.cjs +0 -599
  84. package/dist/esm-Bh_YwFIz.cjs.map +0 -1
  85. package/dist/esm-C0XO9TQm.cjs +0 -30449
  86. package/dist/esm-C0XO9TQm.cjs.map +0 -1
  87. package/dist/esm-vMUVj9k4.mjs +0 -30440
  88. package/dist/esm-vMUVj9k4.mjs.map +0 -1
  89. package/dist/keyset-CKMQXvsb.mjs +0 -172
  90. package/dist/keyset-CKMQXvsb.mjs.map +0 -1
  91. package/dist/keyset-Cxdgu110.cjs +0 -237
  92. package/dist/keyset-Cxdgu110.cjs.map +0 -1
  93. package/dist/keyset-DLxpGhdu.cjs +0 -6
  94. package/dist/keyset-IKjlhvqF.mjs +0 -4
  95. package/dist/node-3EUJ4ga9.cjs +0 -9
  96. package/dist/node-C2UpE11T.cjs +0 -444
  97. package/dist/node-C2UpE11T.cjs.map +0 -1
  98. package/dist/node-CHdpTQdN.mjs +0 -8679
  99. package/dist/node-CHdpTQdN.mjs.map +0 -1
  100. package/dist/node-DQt1CVGl.mjs +0 -6
  101. package/dist/node-Dy8ww1LG.cjs +0 -8680
  102. package/dist/node-Dy8ww1LG.cjs.map +0 -1
  103. package/dist/node-IX55IH6z.mjs +0 -397
  104. package/dist/node-IX55IH6z.mjs.map +0 -1
  105. package/dist/nostr-BTOpBN_5.cjs +0 -11
  106. package/dist/nostr-D4E52XRU.mjs +0 -224
  107. package/dist/nostr-D4E52XRU.mjs.map +0 -1
  108. package/dist/nostr-Hv2tsnuI.cjs +0 -272
  109. package/dist/nostr-Hv2tsnuI.cjs.map +0 -1
  110. package/dist/nostr-ZwJe_DlZ.mjs +0 -4
  111. package/dist/pako.esm-DTVnlCJh.cjs +0 -3856
  112. package/dist/pako.esm-DTVnlCJh.cjs.map +0 -1
  113. package/dist/pako.esm-ORhkEHM2.mjs +0 -3838
  114. package/dist/pako.esm-ORhkEHM2.mjs.map +0 -1
  115. package/dist/peer-B9g3OQ5D.cjs +0 -18
  116. package/dist/peer-CptDj7zu.mjs +0 -745
  117. package/dist/peer-CptDj7zu.mjs.map +0 -1
  118. package/dist/peer-CtqL0yiE.mjs +0 -9
  119. package/dist/peer-XrPL0O6z.cjs +0 -822
  120. package/dist/peer-XrPL0O6z.cjs.map +0 -1
  121. package/dist/ping-BXKREIdI.mjs +0 -7
  122. package/dist/ping-BtVhKocl.cjs +0 -379
  123. package/dist/ping-BtVhKocl.cjs.map +0 -1
  124. package/dist/ping-D5fpMhGC.cjs +0 -11
  125. package/dist/ping-DOD50kW_.mjs +0 -332
  126. package/dist/ping-DOD50kW_.mjs.map +0 -1
  127. package/dist/policy-8HcjulLD.cjs +0 -293
  128. package/dist/policy-8HcjulLD.cjs.map +0 -1
  129. package/dist/policy-BA6MEOBY.mjs +0 -5
  130. package/dist/policy-BFNdXvmM.cjs +0 -11
  131. package/dist/policy-D_nFHHjo.mjs +0 -228
  132. package/dist/policy-D_nFHHjo.mjs.map +0 -1
  133. package/dist/prf-handler-BNiyCQMt.cjs +0 -3
  134. package/dist/src-CVfTUJQl.mjs +0 -822
  135. package/dist/src-CVfTUJQl.mjs.map +0 -1
  136. package/dist/src-D5S86Xpf.cjs +0 -827
  137. package/dist/src-D5S86Xpf.cjs.map +0 -1
  138. package/dist/types-B-TLIS13.cjs +0 -212
  139. package/dist/types-B-TLIS13.cjs.map +0 -1
  140. package/dist/types-CTm_FHYD.mjs +0 -111
  141. package/dist/types-CTm_FHYD.mjs.map +0 -1
  142. package/dist/validation-1xwWVXqE.mjs +0 -3
  143. package/dist/validation-DnpurN79.cjs +0 -405
  144. package/dist/validation-DnpurN79.cjs.map +0 -1
  145. package/dist/validation-IsAUvsvy.mjs +0 -334
  146. package/dist/validation-IsAUvsvy.mjs.map +0 -1
  147. package/dist/validation-yCvZCqIs.cjs +0 -6
  148. package/dist/wrapper-C5NpyacC.cjs +0 -3552
  149. package/dist/wrapper-C5NpyacC.cjs.map +0 -1
  150. package/dist/wrapper-CHq_CV4J.mjs +0 -3552
  151. package/dist/wrapper-CHq_CV4J.mjs.map +0 -1
  152. package/dist/zkm.service-BrXyI4BS.mjs +0 -3
  153. package/dist/zkm.service-BvQ01wSH.cjs +0 -3
@@ -1,397 +0,0 @@
1
- import { BifrostNode, PackageEncoder } from "./dist-D7fRmK6G.mjs";
2
- import { c as NodeConfigSchema, l as NodeError } from "./types-CTm_FHYD.mjs";
3
- import { c as registerNodePolicyMetadata, s as prepareNodePolicies } from "./policy-D_nFHHjo.mjs";
4
-
5
- //#region node_modules/@frostr/igloo-core/dist/node.js
6
- /**
7
- * Creates a BifrostNode with proper validation and event handling
8
- */
9
- function createBifrostNode(config, eventConfig = {}) {
10
- try {
11
- const validatedConfig = NodeConfigSchema.parse(config);
12
- const decodedGroup = PackageEncoder.group.decode(validatedConfig.group);
13
- const decodedShare = PackageEncoder.share.decode(validatedConfig.share);
14
- const { peerConfigs, normalizedPolicies } = prepareNodePolicies(validatedConfig.policies);
15
- const nodeOptions = peerConfigs.length ? { policies: peerConfigs } : void 0;
16
- const node = nodeOptions ? new BifrostNode(decodedGroup, decodedShare, validatedConfig.relays, nodeOptions) : new BifrostNode(decodedGroup, decodedShare, validatedConfig.relays);
17
- setupNodeEvents(node, eventConfig);
18
- if (normalizedPolicies.length) registerNodePolicyMetadata(node, normalizedPolicies);
19
- return node;
20
- } catch (error) {
21
- throw new NodeError(`Failed to create BifrostNode: ${error.message}`, {
22
- config,
23
- error
24
- });
25
- }
26
- }
27
- /**
28
- * Sets up comprehensive event handlers for a BifrostNode
29
- */
30
- function setupNodeEvents(node, config = {}) {
31
- const { enableLogging = true, logLevel = "info", customLogger } = config;
32
- const log = (level, message, data) => {
33
- if (!enableLogging) return;
34
- if (customLogger) customLogger(level, message, data);
35
- else console.log(`[${level.toUpperCase()}] ${message}`, data || "");
36
- };
37
- node.on("*", (eventName, data) => {
38
- log("debug", `Event emitted: ${eventName}`, data);
39
- });
40
- node.on("info", (data) => {
41
- log("info", "Bifrost info", data);
42
- });
43
- node.on("debug", (data) => {
44
- log("debug", "Bifrost debug", data);
45
- });
46
- node.on("ready", (node$1) => {
47
- log("info", "Bifrost node is ready", { nodeId: node$1.constructor.name });
48
- });
49
- node.on("closed", (node$1) => {
50
- log("info", "Bifrost node connection closed", { nodeId: node$1.constructor.name });
51
- });
52
- node.on("message", (msg) => {
53
- log("debug", "Received message", msg);
54
- });
55
- node.on("bounced", (reason, msg) => {
56
- log("warn", "Message bounced", {
57
- reason,
58
- message: msg
59
- });
60
- });
61
- node.on("error", (error) => {
62
- log("error", "Node error occurred", error);
63
- });
64
- node.on("/ecdh/sender/req", (msg) => {
65
- log("debug", "ECDH request sent", msg);
66
- });
67
- node.on("/ecdh/sender/res", (...msgs) => {
68
- log("debug", "ECDH responses received", msgs);
69
- });
70
- node.on("/ecdh/sender/rej", (reason, pkg) => {
71
- log("warn", "ECDH request rejected", {
72
- reason,
73
- package: pkg
74
- });
75
- });
76
- node.on("/ecdh/sender/ret", (reason, pkgs) => {
77
- log("info", "ECDH shares aggregated", {
78
- reason,
79
- packages: pkgs
80
- });
81
- });
82
- node.on("/ecdh/sender/err", (reason, msgs) => {
83
- log("error", "ECDH share aggregation failed", {
84
- reason,
85
- messages: msgs
86
- });
87
- });
88
- node.on("/ecdh/handler/req", (msg) => {
89
- log("debug", "ECDH request received", msg);
90
- });
91
- node.on("/ecdh/handler/res", (msg) => {
92
- log("debug", "ECDH response sent", msg);
93
- });
94
- node.on("/ecdh/handler/rej", (reason, msg) => {
95
- log("warn", "ECDH rejection sent", {
96
- reason,
97
- message: msg
98
- });
99
- });
100
- node.on("/sign/sender/req", (msg) => {
101
- log("debug", "Signature request sent", msg);
102
- });
103
- node.on("/sign/sender/res", (...msgs) => {
104
- log("debug", "Signature responses received", msgs);
105
- });
106
- node.on("/sign/sender/rej", (reason, pkg) => {
107
- log("warn", "Signature request rejected", {
108
- reason,
109
- package: pkg
110
- });
111
- });
112
- node.on("/sign/sender/ret", (reason, msgs) => {
113
- log("info", "Signature shares aggregated", {
114
- reason,
115
- signatures: msgs
116
- });
117
- });
118
- node.on("/sign/sender/err", (reason, msgs) => {
119
- log("error", "Signature share aggregation failed", {
120
- reason,
121
- messages: msgs
122
- });
123
- });
124
- node.on("/sign/handler/req", (msg) => {
125
- log("debug", "Signature request received", msg);
126
- });
127
- node.on("/sign/handler/res", (msg) => {
128
- log("debug", "Signature response sent", msg);
129
- });
130
- node.on("/sign/handler/rej", (reason, msg) => {
131
- log("warn", "Signature rejection sent", {
132
- reason,
133
- message: msg
134
- });
135
- });
136
- node.on("/ping/handler/req", (msg) => {
137
- log("debug", "Ping request received", msg);
138
- });
139
- node.on("/ping/handler/res", (msg) => {
140
- log("debug", "Ping response sent", msg);
141
- });
142
- node.on("/ping/handler/rej", (reason, msg) => {
143
- log("warn", "Ping rejection sent", {
144
- reason,
145
- message: msg
146
- });
147
- });
148
- node.on("/ping/handler/ret", (reason, data) => {
149
- log("info", "Ping handler returned", {
150
- reason,
151
- data
152
- });
153
- });
154
- node.on("/ping/sender/req", (msg) => {
155
- log("debug", "Ping request sent", msg);
156
- });
157
- node.on("/ping/sender/res", (msg) => {
158
- log("debug", "Ping response received", msg);
159
- });
160
- node.on("/ping/sender/rej", (reason, msg) => {
161
- log("warn", "Ping request rejected", {
162
- reason,
163
- message: msg
164
- });
165
- });
166
- node.on("/ping/sender/ret", (config$1) => {
167
- log("info", "Ping sender returned peer config", config$1);
168
- });
169
- node.on("/ping/sender/err", (reason, msg) => {
170
- log("error", "Ping sender error", {
171
- reason,
172
- message: msg
173
- });
174
- });
175
- node.on("/echo/handler/req", (msg) => {
176
- log("debug", "Echo request received", msg);
177
- });
178
- node.on("/echo/handler/res", (msg) => {
179
- log("debug", "Echo response sent", msg);
180
- });
181
- node.on("/echo/handler/rej", (reason, msg) => {
182
- log("warn", "Echo rejection sent", {
183
- reason,
184
- message: msg
185
- });
186
- });
187
- node.on("/echo/sender/req", (msg) => {
188
- log("debug", "Echo request sent", msg);
189
- });
190
- node.on("/echo/sender/res", (msg) => {
191
- log("debug", "Echo response received", msg);
192
- });
193
- node.on("/echo/sender/rej", (reason, msg) => {
194
- log("warn", "Echo request rejected", {
195
- reason,
196
- message: msg
197
- });
198
- });
199
- node.on("/echo/sender/ret", (reason) => {
200
- log("info", "Echo sender returned", { reason });
201
- });
202
- node.on("/echo/sender/err", (reason, msg) => {
203
- log("error", "Echo sender error", {
204
- reason,
205
- message: msg
206
- });
207
- });
208
- }
209
- /**
210
- * Safely connects a BifrostNode with error handling
211
- */
212
- async function connectNode(node) {
213
- const client = node?.client;
214
- if (client && typeof client.connect === "function") {
215
- const originalConnect = client.connect;
216
- const hadOwnConnect = Object.prototype.hasOwnProperty.call(client, "connect");
217
- let connectPromise;
218
- client.connect = (...args) => {
219
- const result = originalConnect.apply(client, args);
220
- if (result && typeof result.then === "function") {
221
- connectPromise = Promise.resolve(result).catch((error) => {
222
- throw error;
223
- });
224
- return connectPromise;
225
- }
226
- connectPromise = void 0;
227
- return result;
228
- };
229
- try {
230
- await node.connect();
231
- if (connectPromise) await connectPromise;
232
- return;
233
- } catch (error) {
234
- throw new NodeError(`Failed to connect BifrostNode: ${error?.message ?? error}`, { error });
235
- } finally {
236
- if (hadOwnConnect) client.connect = originalConnect;
237
- else delete client.connect;
238
- }
239
- }
240
- try {
241
- await node.connect();
242
- } catch (error) {
243
- throw new NodeError(`Failed to connect BifrostNode: ${error?.message ?? error}`, { error });
244
- }
245
- }
246
- /**
247
- * Safely closes a BifrostNode with cleanup
248
- */
249
- function closeNode(node) {
250
- const nodeAsAny = node;
251
- const client = nodeAsAny?.client;
252
- const emitCloseError = (error) => {
253
- if (error instanceof Error && error.message === "relay connection closed by us") return;
254
- const normalized = error instanceof NodeError ? error : new NodeError(`Failed to close BifrostNode: ${error instanceof Error ? error.message : String(error)}`, { error });
255
- if (typeof nodeAsAny?.emit === "function") nodeAsAny.emit("error", normalized);
256
- console.warn("[closeNode] Error while closing BifrostNode:", normalized);
257
- };
258
- const attachErrorHandler = (maybePromise) => {
259
- if (maybePromise && typeof maybePromise.catch === "function") maybePromise.catch(emitCloseError);
260
- };
261
- if (client && typeof client.close === "function") {
262
- const originalClose = client.close;
263
- const hadOwnClose = Object.prototype.hasOwnProperty.call(client, "close");
264
- const restoreClientClose = () => {
265
- if (hadOwnClose) client.close = originalClose;
266
- else delete client.close;
267
- };
268
- client.close = (...args) => {
269
- try {
270
- const result = originalClose.apply(client, args);
271
- if (result && typeof result.finally === "function") result.catch(emitCloseError).finally(restoreClientClose);
272
- else restoreClientClose();
273
- return result;
274
- } catch (error) {
275
- restoreClientClose();
276
- throw error;
277
- }
278
- };
279
- try {
280
- attachErrorHandler(node.close());
281
- } catch (error) {
282
- restoreClientClose();
283
- throw new NodeError(`Failed to close BifrostNode: ${error?.message ?? error}`, { error });
284
- }
285
- return;
286
- }
287
- try {
288
- attachErrorHandler(node.close());
289
- } catch (error) {
290
- throw new NodeError(`Failed to close BifrostNode: ${error?.message ?? error}`, { error });
291
- }
292
- }
293
- /**
294
- * Creates a BifrostNode and connects it
295
- */
296
- async function createAndConnectNode(config, eventConfig) {
297
- const node = createBifrostNode(config, eventConfig);
298
- await connectNode(node);
299
- return node;
300
- }
301
- /**
302
- * Enhanced node creation with state information
303
- * Returns both the node and its current state for better control
304
- *
305
- * @param config - Enhanced configuration including timeout and auto-reconnect options
306
- * @param eventConfig - Optional event configuration for logging and custom handlers
307
- * @returns Promise resolving to both the connected node and its state information
308
- *
309
- * @example
310
- * ```typescript
311
- * const { node, state } = await createConnectedNode({
312
- * group: 'bfgroup1...',
313
- * share: 'bfshare1...',
314
- * relays: ['wss://relay.damus.io'],
315
- * connectionTimeout: 5000,
316
- * autoReconnect: true
317
- * });
318
- *
319
- * console.log('Node ready:', state.isReady);
320
- * console.log('Connected relays:', state.connectedRelays);
321
- * ```
322
- */
323
- async function createConnectedNode(config, eventConfig) {
324
- const node = createBifrostNode(config, eventConfig);
325
- const state = {
326
- isReady: false,
327
- isConnected: false,
328
- isConnecting: true,
329
- connectedRelays: []
330
- };
331
- try {
332
- await connectNode(node);
333
- state.isReady = true;
334
- state.isConnected = true;
335
- state.isConnecting = false;
336
- state.connectedRelays = [...config.relays];
337
- return {
338
- node,
339
- state
340
- };
341
- } catch (error) {
342
- state.isConnecting = false;
343
- state.lastError = error instanceof Error ? error.message : "Unknown error";
344
- throw error;
345
- }
346
- }
347
- /**
348
- * Check if a BifrostNode is ready synchronously
349
- * This helper works around the race condition with ready events
350
- *
351
- * @param node - The BifrostNode to check
352
- * @returns true if the node is ready and connected, false otherwise
353
- *
354
- * @example
355
- * ```typescript
356
- * const node = await createAndConnectNode(config);
357
- *
358
- * // Safe synchronous check - no race conditions
359
- * if (isNodeReady(node)) {
360
- * console.log('Node is ready for operations');
361
- * }
362
- * ```
363
- */
364
- function isNodeReady(node) {
365
- try {
366
- return !!node.client && !!node.client.connected;
367
- } catch {
368
- return false;
369
- }
370
- }
371
- /**
372
- * Comprehensive cleanup for BifrostNode
373
- * Removes all event listeners and safely disconnects the node
374
- *
375
- * Note: Since we don't have access to the original listener functions,
376
- * this function uses removeAllListeners to clear all event handlers.
377
- * For more precise cleanup, store listener references when setting them up.
378
- */
379
- function cleanupBifrostNode(node) {
380
- if (!node) return;
381
- try {
382
- const nodeAsAny = node;
383
- if (typeof nodeAsAny.removeAllListeners === "function") nodeAsAny.removeAllListeners();
384
- else console.warn("removeAllListeners not available - manual cleanup may be incomplete");
385
- try {
386
- node.close();
387
- } catch (closeError) {
388
- console.warn("Warning: Error during node.close():", closeError);
389
- }
390
- } catch (error) {
391
- console.warn("Warning: Error during node cleanup:", error);
392
- }
393
- }
394
-
395
- //#endregion
396
- export { createBifrostNode as a, setupNodeEvents as c, createAndConnectNode as i, closeNode as n, createConnectedNode as o, connectNode as r, isNodeReady as s, cleanupBifrostNode as t };
397
- //# sourceMappingURL=node-IX55IH6z.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-IX55IH6z.mjs","names":["node","config"],"sources":["../node_modules/@frostr/igloo-core/dist/node.js"],"sourcesContent":["import { BifrostNode, PackageEncoder } from '@frostr/bifrost';\nimport { NodeError, NodeConfigSchema } from './types.js';\nimport { prepareNodePolicies, registerNodePolicyMetadata } from './policy.js';\n/**\n * Creates a BifrostNode with proper validation and event handling\n */\nexport function createBifrostNode(config, eventConfig = {}) {\n try {\n const validatedConfig = NodeConfigSchema.parse(config);\n const decodedGroup = PackageEncoder.group.decode(validatedConfig.group);\n const decodedShare = PackageEncoder.share.decode(validatedConfig.share);\n const { peerConfigs, normalizedPolicies } = prepareNodePolicies(validatedConfig.policies);\n const nodeOptions = peerConfigs.length ? { policies: peerConfigs } : undefined;\n const node = nodeOptions\n ? new BifrostNode(decodedGroup, decodedShare, validatedConfig.relays, nodeOptions)\n : new BifrostNode(decodedGroup, decodedShare, validatedConfig.relays);\n // Set up event handlers with optional logging\n setupNodeEvents(node, eventConfig);\n if (normalizedPolicies.length) {\n registerNodePolicyMetadata(node, normalizedPolicies);\n }\n return node;\n }\n catch (error) {\n throw new NodeError(`Failed to create BifrostNode: ${error.message}`, { config, error });\n }\n}\n/**\n * Sets up comprehensive event handlers for a BifrostNode\n */\nexport function setupNodeEvents(node, config = {}) {\n const { enableLogging = true, logLevel = 'info', customLogger } = config;\n const log = (level, message, data) => {\n if (!enableLogging)\n return;\n if (customLogger) {\n customLogger(level, message, data);\n }\n else {\n console.log(`[${level.toUpperCase()}] ${message}`, data || '');\n }\n };\n // Wildcard event handler\n node.on('*', (eventName, data) => {\n log('debug', `Event emitted: ${eventName}`, data);\n });\n // Base logging events\n node.on('info', (data) => {\n log('info', 'Bifrost info', data);\n });\n node.on('debug', (data) => {\n log('debug', 'Bifrost debug', data);\n });\n // Base events\n node.on('ready', (node) => {\n log('info', 'Bifrost node is ready', { nodeId: node.constructor.name });\n });\n node.on('closed', (node) => {\n log('info', 'Bifrost node connection closed', { nodeId: node.constructor.name });\n });\n node.on('message', (msg) => {\n log('debug', 'Received message', msg);\n });\n node.on('bounced', (reason, msg) => {\n log('warn', 'Message bounced', { reason, message: msg });\n });\n node.on('error', (error) => {\n log('error', 'Node error occurred', error);\n });\n // ECDH events\n node.on('/ecdh/sender/req', (msg) => {\n log('debug', 'ECDH request sent', msg);\n });\n node.on('/ecdh/sender/res', (...msgs) => {\n log('debug', 'ECDH responses received', msgs);\n });\n node.on('/ecdh/sender/rej', (reason, pkg) => {\n log('warn', 'ECDH request rejected', { reason, package: pkg });\n });\n node.on('/ecdh/sender/ret', (reason, pkgs) => {\n log('info', 'ECDH shares aggregated', { reason, packages: pkgs });\n });\n node.on('/ecdh/sender/err', (reason, msgs) => {\n log('error', 'ECDH share aggregation failed', { reason, messages: msgs });\n });\n node.on('/ecdh/handler/req', (msg) => {\n log('debug', 'ECDH request received', msg);\n });\n node.on('/ecdh/handler/res', (msg) => {\n log('debug', 'ECDH response sent', msg);\n });\n node.on('/ecdh/handler/rej', (reason, msg) => {\n log('warn', 'ECDH rejection sent', { reason, message: msg });\n });\n // Signature events\n node.on('/sign/sender/req', (msg) => {\n log('debug', 'Signature request sent', msg);\n });\n node.on('/sign/sender/res', (...msgs) => {\n log('debug', 'Signature responses received', msgs);\n });\n node.on('/sign/sender/rej', (reason, pkg) => {\n log('warn', 'Signature request rejected', { reason, package: pkg });\n });\n node.on('/sign/sender/ret', (reason, msgs) => {\n log('info', 'Signature shares aggregated', { reason, signatures: msgs });\n });\n node.on('/sign/sender/err', (reason, msgs) => {\n log('error', 'Signature share aggregation failed', { reason, messages: msgs });\n });\n node.on('/sign/handler/req', (msg) => {\n log('debug', 'Signature request received', msg);\n });\n node.on('/sign/handler/res', (msg) => {\n log('debug', 'Signature response sent', msg);\n });\n node.on('/sign/handler/rej', (reason, msg) => {\n log('warn', 'Signature rejection sent', { reason, message: msg });\n });\n // Ping events\n node.on('/ping/handler/req', (msg) => {\n log('debug', 'Ping request received', msg);\n });\n node.on('/ping/handler/res', (msg) => {\n log('debug', 'Ping response sent', msg);\n });\n node.on('/ping/handler/rej', (reason, msg) => {\n log('warn', 'Ping rejection sent', { reason, message: msg });\n });\n node.on('/ping/handler/ret', (reason, data) => {\n log('info', 'Ping handler returned', { reason, data });\n });\n node.on('/ping/sender/req', (msg) => {\n log('debug', 'Ping request sent', msg);\n });\n node.on('/ping/sender/res', (msg) => {\n log('debug', 'Ping response received', msg);\n });\n node.on('/ping/sender/rej', (reason, msg) => {\n log('warn', 'Ping request rejected', { reason, message: msg });\n });\n node.on('/ping/sender/ret', (config) => {\n log('info', 'Ping sender returned peer config', config);\n });\n node.on('/ping/sender/err', (reason, msg) => {\n log('error', 'Ping sender error', { reason, message: msg });\n });\n // Echo events\n node.on('/echo/handler/req', (msg) => {\n log('debug', 'Echo request received', msg);\n });\n node.on('/echo/handler/res', (msg) => {\n log('debug', 'Echo response sent', msg);\n });\n node.on('/echo/handler/rej', (reason, msg) => {\n log('warn', 'Echo rejection sent', { reason, message: msg });\n });\n node.on('/echo/sender/req', (msg) => {\n log('debug', 'Echo request sent', msg);\n });\n node.on('/echo/sender/res', (msg) => {\n log('debug', 'Echo response received', msg);\n });\n node.on('/echo/sender/rej', (reason, msg) => {\n log('warn', 'Echo request rejected', { reason, message: msg });\n });\n node.on('/echo/sender/ret', (reason) => {\n log('info', 'Echo sender returned', { reason });\n });\n node.on('/echo/sender/err', (reason, msg) => {\n log('error', 'Echo sender error', { reason, message: msg });\n });\n}\n/**\n * Safely connects a BifrostNode with error handling\n */\nexport async function connectNode(node) {\n const nodeAsAny = node;\n const client = nodeAsAny?.client;\n if (client && typeof client.connect === 'function') {\n // Work around upstream bug where BifrostNode.connect drops the promise\n // returned by client.connect(), causing unhandled rejections when the\n // handshake fails. Capture that promise so we can await (and surface) it.\n const originalConnect = client.connect;\n const hadOwnConnect = Object.prototype.hasOwnProperty.call(client, 'connect');\n let connectPromise;\n client.connect = (...args) => {\n const result = originalConnect.apply(client, args);\n if (result && typeof result.then === 'function') {\n connectPromise = Promise.resolve(result).catch((error) => {\n throw error;\n });\n return connectPromise;\n }\n connectPromise = undefined;\n return result;\n };\n try {\n await node.connect();\n if (connectPromise) {\n await connectPromise;\n }\n return;\n }\n catch (error) {\n throw new NodeError(`Failed to connect BifrostNode: ${error?.message ?? error}`, { error });\n }\n finally {\n if (hadOwnConnect) {\n client.connect = originalConnect;\n }\n else {\n delete client.connect;\n }\n }\n }\n try {\n await node.connect();\n }\n catch (error) {\n throw new NodeError(`Failed to connect BifrostNode: ${error?.message ?? error}`, { error });\n }\n}\n/**\n * Safely closes a BifrostNode with cleanup\n */\nexport function closeNode(node) {\n const nodeAsAny = node;\n const client = nodeAsAny?.client;\n const emitCloseError = (error) => {\n if (error instanceof Error && error.message === 'relay connection closed by us') {\n // Expected during normal shutdown; swallow to avoid noisy logs.\n return;\n }\n const normalized = error instanceof NodeError\n ? error\n : new NodeError(`Failed to close BifrostNode: ${error instanceof Error ? error.message : String(error)}`, { error });\n if (typeof nodeAsAny?.emit === 'function') {\n nodeAsAny.emit('error', normalized);\n }\n console.warn('[closeNode] Error while closing BifrostNode:', normalized);\n };\n const attachErrorHandler = (maybePromise) => {\n if (maybePromise && typeof maybePromise.catch === 'function') {\n maybePromise.catch(emitCloseError);\n }\n };\n if (client && typeof client.close === 'function') {\n const originalClose = client.close;\n const hadOwnClose = Object.prototype.hasOwnProperty.call(client, 'close');\n const restoreClientClose = () => {\n if (hadOwnClose) {\n client.close = originalClose;\n }\n else {\n delete client.close;\n }\n };\n client.close = (...args) => {\n try {\n const result = originalClose.apply(client, args);\n if (result && typeof result.finally === 'function') {\n result\n .catch(emitCloseError)\n .finally(restoreClientClose);\n }\n else {\n restoreClientClose();\n }\n return result;\n }\n catch (error) {\n restoreClientClose();\n throw error;\n }\n };\n try {\n attachErrorHandler(node.close());\n }\n catch (error) {\n restoreClientClose();\n throw new NodeError(`Failed to close BifrostNode: ${error?.message ?? error}`, { error });\n }\n return;\n }\n try {\n attachErrorHandler(node.close());\n }\n catch (error) {\n throw new NodeError(`Failed to close BifrostNode: ${error?.message ?? error}`, { error });\n }\n}\n/**\n * Creates a BifrostNode and connects it\n */\nexport async function createAndConnectNode(config, eventConfig) {\n const node = createBifrostNode(config, eventConfig);\n await connectNode(node);\n return node;\n}\n/**\n * Enhanced node creation with state information\n * Returns both the node and its current state for better control\n *\n * @param config - Enhanced configuration including timeout and auto-reconnect options\n * @param eventConfig - Optional event configuration for logging and custom handlers\n * @returns Promise resolving to both the connected node and its state information\n *\n * @example\n * ```typescript\n * const { node, state } = await createConnectedNode({\n * group: 'bfgroup1...',\n * share: 'bfshare1...',\n * relays: ['wss://relay.damus.io'],\n * connectionTimeout: 5000,\n * autoReconnect: true\n * });\n *\n * console.log('Node ready:', state.isReady);\n * console.log('Connected relays:', state.connectedRelays);\n * ```\n */\nexport async function createConnectedNode(config, eventConfig) {\n const node = createBifrostNode(config, eventConfig);\n const state = {\n isReady: false,\n isConnected: false,\n isConnecting: true,\n connectedRelays: []\n };\n try {\n await connectNode(node);\n // Node is ready immediately after successful connection\n state.isReady = true;\n state.isConnected = true;\n state.isConnecting = false;\n state.connectedRelays = [...config.relays];\n return { node, state };\n }\n catch (error) {\n state.isConnecting = false;\n state.lastError = error instanceof Error ? error.message : 'Unknown error';\n throw error;\n }\n}\n/**\n * Check if a BifrostNode is ready synchronously\n * This helper works around the race condition with ready events\n *\n * @param node - The BifrostNode to check\n * @returns true if the node is ready and connected, false otherwise\n *\n * @example\n * ```typescript\n * const node = await createAndConnectNode(config);\n *\n * // Safe synchronous check - no race conditions\n * if (isNodeReady(node)) {\n * console.log('Node is ready for operations');\n * }\n * ```\n */\nexport function isNodeReady(node) {\n try {\n // Check if the node has a client and if it's connected\n return !!node.client && !!node.client.connected;\n }\n catch {\n return false;\n }\n}\n/**\n * Comprehensive cleanup for BifrostNode\n * Removes all event listeners and safely disconnects the node\n *\n * Note: Since we don't have access to the original listener functions,\n * this function uses removeAllListeners to clear all event handlers.\n * For more precise cleanup, store listener references when setting them up.\n */\nexport function cleanupBifrostNode(node) {\n if (!node)\n return;\n try {\n // Use removeAllListeners if available (common in EventEmitter implementations)\n const nodeAsAny = node;\n if (typeof nodeAsAny.removeAllListeners === 'function') {\n nodeAsAny.removeAllListeners();\n }\n else {\n // If removeAllListeners is not available, try to clear listeners individually\n // This is a fallback that may not work with all implementations\n console.warn('removeAllListeners not available - manual cleanup may be incomplete');\n }\n // Safely close the connection\n try {\n node.close();\n }\n catch (closeError) {\n console.warn('Warning: Error during node.close():', closeError);\n }\n }\n catch (error) {\n console.warn('Warning: Error during node cleanup:', error);\n }\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;AAMA,SAAgB,kBAAkB,QAAQ,cAAc,EAAE,EAAE;AACxD,KAAI;EACA,MAAM,kBAAkB,iBAAiB,MAAM,OAAO;EACtD,MAAM,eAAe,eAAe,MAAM,OAAO,gBAAgB,MAAM;EACvE,MAAM,eAAe,eAAe,MAAM,OAAO,gBAAgB,MAAM;EACvE,MAAM,EAAE,aAAa,uBAAuB,oBAAoB,gBAAgB,SAAS;EACzF,MAAM,cAAc,YAAY,SAAS,EAAE,UAAU,aAAa,GAAG;EACrE,MAAM,OAAO,cACP,IAAI,YAAY,cAAc,cAAc,gBAAgB,QAAQ,YAAY,GAChF,IAAI,YAAY,cAAc,cAAc,gBAAgB,OAAO;AAEzE,kBAAgB,MAAM,YAAY;AAClC,MAAI,mBAAmB,OACnB,4BAA2B,MAAM,mBAAmB;AAExD,SAAO;UAEJ,OAAO;AACV,QAAM,IAAI,UAAU,iCAAiC,MAAM,WAAW;GAAE;GAAQ;GAAO,CAAC;;;;;;AAMhG,SAAgB,gBAAgB,MAAM,SAAS,EAAE,EAAE;CAC/C,MAAM,EAAE,gBAAgB,MAAM,WAAW,QAAQ,iBAAiB;CAClE,MAAM,OAAO,OAAO,SAAS,SAAS;AAClC,MAAI,CAAC,cACD;AACJ,MAAI,aACA,cAAa,OAAO,SAAS,KAAK;MAGlC,SAAQ,IAAI,IAAI,MAAM,aAAa,CAAC,IAAI,WAAW,QAAQ,GAAG;;AAItE,MAAK,GAAG,MAAM,WAAW,SAAS;AAC9B,MAAI,SAAS,kBAAkB,aAAa,KAAK;GACnD;AAEF,MAAK,GAAG,SAAS,SAAS;AACtB,MAAI,QAAQ,gBAAgB,KAAK;GACnC;AACF,MAAK,GAAG,UAAU,SAAS;AACvB,MAAI,SAAS,iBAAiB,KAAK;GACrC;AAEF,MAAK,GAAG,UAAU,WAAS;AACvB,MAA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E,OAAO;AACV,UAAQ,KAAK,uCAAuC,MAAM"}
@@ -1,11 +0,0 @@
1
- require('./types-B-TLIS13.cjs');
2
- const require_nostr = require('./nostr-Hv2tsnuI.cjs');
3
-
4
- exports.derivePublicKey = require_nostr.derivePublicKey;
5
- exports.generateNostrKeyPair = require_nostr.generateNostrKeyPair;
6
- exports.hexToNpub = require_nostr.hexToNpub;
7
- exports.hexToNsec = require_nostr.hexToNsec;
8
- exports.npubToHex = require_nostr.npubToHex;
9
- exports.nsecToHex = require_nostr.nsecToHex;
10
- exports.validateHexKey = require_nostr.validateHexKey;
11
- exports.validateNostrKey = require_nostr.validateNostrKey;
@@ -1,224 +0,0 @@
1
- import { t as nip19_exports } from "./dist-D7fRmK6G.mjs";
2
- import { d as NostrError } from "./types-CTm_FHYD.mjs";
3
- import { sha256 } from "@noble/hashes/sha2.js";
4
- import { schnorr } from "@noble/curves/secp256k1.js";
5
- import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
6
-
7
- //#region node_modules/nostr-tools/lib/esm/pure.js
8
- var verifiedSymbol = Symbol("verified");
9
- var isRecord = (obj) => obj instanceof Object;
10
- function validateEvent(event) {
11
- if (!isRecord(event)) return false;
12
- if (typeof event.kind !== "number") return false;
13
- if (typeof event.content !== "string") return false;
14
- if (typeof event.created_at !== "number") return false;
15
- if (typeof event.pubkey !== "string") return false;
16
- if (!event.pubkey.match(/^[a-f0-9]{64}$/)) return false;
17
- if (!Array.isArray(event.tags)) return false;
18
- for (let i2 = 0; i2 < event.tags.length; i2++) {
19
- let tag = event.tags[i2];
20
- if (!Array.isArray(tag)) return false;
21
- for (let j = 0; j < tag.length; j++) if (typeof tag[j] !== "string") return false;
22
- }
23
- return true;
24
- }
25
- new TextDecoder("utf-8");
26
- var utf8Encoder = new TextEncoder();
27
- var JS = class {
28
- generateSecretKey() {
29
- return schnorr.utils.randomSecretKey();
30
- }
31
- getPublicKey(secretKey) {
32
- return bytesToHex(schnorr.getPublicKey(secretKey));
33
- }
34
- finalizeEvent(t, secretKey) {
35
- const event = t;
36
- event.pubkey = bytesToHex(schnorr.getPublicKey(secretKey));
37
- event.id = getEventHash(event);
38
- event.sig = bytesToHex(schnorr.sign(hexToBytes(getEventHash(event)), secretKey));
39
- event[verifiedSymbol] = true;
40
- return event;
41
- }
42
- verifyEvent(event) {
43
- if (typeof event[verifiedSymbol] === "boolean") return event[verifiedSymbol];
44
- try {
45
- const hash = getEventHash(event);
46
- if (hash !== event.id) {
47
- event[verifiedSymbol] = false;
48
- return false;
49
- }
50
- const valid = schnorr.verify(hexToBytes(event.sig), hexToBytes(hash), hexToBytes(event.pubkey));
51
- event[verifiedSymbol] = valid;
52
- return valid;
53
- } catch (err) {
54
- event[verifiedSymbol] = false;
55
- return false;
56
- }
57
- }
58
- };
59
- function serializeEvent(evt) {
60
- if (!validateEvent(evt)) throw new Error("can't serialize event with wrong or missing properties");
61
- return JSON.stringify([
62
- 0,
63
- evt.pubkey,
64
- evt.created_at,
65
- evt.kind,
66
- evt.tags,
67
- evt.content
68
- ]);
69
- }
70
- function getEventHash(event) {
71
- return bytesToHex(sha256(utf8Encoder.encode(serializeEvent(event))));
72
- }
73
- var i = new JS();
74
- var generateSecretKey = i.generateSecretKey;
75
- var getPublicKey = i.getPublicKey;
76
- var finalizeEvent = i.finalizeEvent;
77
- var verifyEvent = i.verifyEvent;
78
-
79
- //#endregion
80
- //#region node_modules/@frostr/igloo-core/dist/nostr.js
81
- /**
82
- * Converts a nostr secret key (nsec) to its hex representation
83
- * @param nsec The nostr secret key in nsec format
84
- * @returns The secret key in hex format
85
- */
86
- function nsecToHex(nsec) {
87
- try {
88
- const { type, data } = nip19_exports.decode(nsec);
89
- if (type !== "nsec") throw new NostrError("Invalid nsec format");
90
- return Buffer.from(data).toString("hex");
91
- } catch (error) {
92
- throw new NostrError(`Failed to decode nsec: ${error.message}`, {
93
- nsec,
94
- error
95
- });
96
- }
97
- }
98
- /**
99
- * Converts a hex secret key to nostr secret key (nsec) format
100
- * @param hex The secret key in hex format
101
- * @returns The secret key in nsec format
102
- */
103
- function hexToNsec(hex) {
104
- try {
105
- validateHexKey(hex);
106
- const bytes = new Uint8Array(Buffer.from(hex, "hex"));
107
- return nip19_exports.nsecEncode(bytes);
108
- } catch (error) {
109
- throw new NostrError(`Failed to encode nsec: ${error.message}`, {
110
- hex,
111
- error
112
- });
113
- }
114
- }
115
- /**
116
- * Converts a hex public key to nostr public key (npub) format
117
- * @param hex The public key in hex format
118
- * @returns The public key in npub format
119
- */
120
- function hexToNpub(hex) {
121
- try {
122
- validateHexKey(hex);
123
- return nip19_exports.npubEncode(hex);
124
- } catch (error) {
125
- throw new NostrError(`Failed to encode npub: ${error.message}`, {
126
- hex,
127
- error
128
- });
129
- }
130
- }
131
- /**
132
- * Converts a nostr public key (npub) to its hex representation
133
- * @param npub The nostr public key in npub format
134
- * @returns The public key in hex format
135
- */
136
- function npubToHex(npub) {
137
- try {
138
- const { type, data } = nip19_exports.decode(npub);
139
- if (type !== "npub") throw new NostrError("Invalid npub format");
140
- return data;
141
- } catch (error) {
142
- throw new NostrError(`Failed to decode npub: ${error.message}`, {
143
- npub,
144
- error
145
- });
146
- }
147
- }
148
- /**
149
- * Generates a new nostr key pair (nsec and npub)
150
- * @returns Object containing both nsec and npub, plus hex versions
151
- */
152
- function generateNostrKeyPair() {
153
- try {
154
- const sk = generateSecretKey();
155
- const hexPublicKey = getPublicKey(sk);
156
- const hexPrivateKey = Buffer.from(sk).toString("hex");
157
- return {
158
- nsec: nip19_exports.nsecEncode(sk),
159
- npub: nip19_exports.npubEncode(hexPublicKey),
160
- hexPrivateKey,
161
- hexPublicKey
162
- };
163
- } catch (error) {
164
- throw new NostrError(`Failed to generate nostr key pair: ${error.message}`, { error });
165
- }
166
- }
167
- /**
168
- * Derives the public key from a private key
169
- * @param privateKey The private key in hex or nsec format
170
- * @returns Object containing npub and hex public key
171
- */
172
- function derivePublicKey(privateKey) {
173
- try {
174
- let hexPrivateKey;
175
- if (privateKey.startsWith("nsec")) hexPrivateKey = nsecToHex(privateKey);
176
- else {
177
- validateHexKey(privateKey);
178
- hexPrivateKey = privateKey;
179
- }
180
- const hexPublicKey = getPublicKey(new Uint8Array(Buffer.from(hexPrivateKey, "hex")));
181
- return {
182
- npub: nip19_exports.npubEncode(hexPublicKey),
183
- hexPublicKey
184
- };
185
- } catch (error) {
186
- throw new NostrError(`Failed to derive public key: ${error.message}`, {
187
- privateKey: privateKey.startsWith("nsec") ? "[REDACTED]" : privateKey,
188
- error
189
- });
190
- }
191
- }
192
- /**
193
- * Validates a hex key format (private or public)
194
- * @param hex The hex string to validate
195
- * @param keyType Optional key type for more specific validation
196
- */
197
- function validateHexKey(hex, keyType) {
198
- if (!hex || typeof hex !== "string") throw new NostrError("Hex key must be a non-empty string");
199
- const expectedLength = keyType === "public" ? 64 : keyType === "private" ? 64 : 64;
200
- if (!/^[0-9a-fA-F]+$/.test(hex)) throw new NostrError("Invalid hex format - must contain only hexadecimal characters");
201
- if (hex.length !== expectedLength) throw new NostrError(`Invalid hex key length - expected ${expectedLength} characters, got ${hex.length}`);
202
- }
203
- /**
204
- * Validates a nostr key format (nsec or npub)
205
- * @param key The nostr key to validate
206
- * @param expectedType Optional expected type ('nsec' or 'npub')
207
- */
208
- function validateNostrKey(key, expectedType) {
209
- try {
210
- const { type } = nip19_exports.decode(key);
211
- if (expectedType && type !== expectedType) throw new NostrError(`Expected ${expectedType} but got ${type}`);
212
- if (type !== "nsec" && type !== "npub") throw new NostrError(`Invalid nostr key type: ${type}`);
213
- } catch (error) {
214
- if (error instanceof NostrError) throw error;
215
- throw new NostrError(`Invalid nostr key format: ${error.message}`, {
216
- key: key.substring(0, 10) + "...",
217
- error
218
- });
219
- }
220
- }
221
-
222
- //#endregion
223
- export { npubToHex as a, validateNostrKey as c, hexToNsec as i, generateNostrKeyPair as n, nsecToHex as o, hexToNpub as r, validateHexKey as s, derivePublicKey as t };
224
- //# sourceMappingURL=nostr-D4E52XRU.mjs.map