@openclaw/nostr 2026.7.2-beta.7 → 2026.7.33

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 (159) hide show
  1. package/dist/{channel-O6-jXoT5.js → .setup/channel-B4SX7Iq6.mjs} +554 -877
  2. package/dist/{config-schema-CelPzg1N.js → .setup/config-schema-DIiXiBKr.mjs} +1 -1
  3. package/dist/.setup/inbound-direct-dm-runtime-EdLLVtkh.mjs +2 -0
  4. package/dist/{setup-adapter-BjKmSwdW.js → .setup/setup-adapter-DEU3o8MF.mjs} +1 -31
  5. package/dist/.setup/setup-plugin-api-DzlCumkz.mjs +2 -0
  6. package/dist/.setup/setup-plugin-api-csfJrRxD.mjs +111 -0
  7. package/dist/{setup-surface-BJCFpe02.js → .setup/setup-surface-DWa6-9ku.mjs} +70 -41
  8. package/dist/api.js +72 -61
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/dist/doctor-contract-api.js +3 -2
  11. package/dist/setup-api.js +1 -1
  12. package/dist/setup-entry.js +2 -1
  13. package/dist/setup-plugin-api.js +1 -112
  14. package/node_modules/nostr-tools/lib/cjs/abstract-pool.js +28 -59
  15. package/node_modules/nostr-tools/lib/cjs/abstract-pool.js.map +3 -3
  16. package/node_modules/nostr-tools/lib/cjs/abstract-relay.js +7 -44
  17. package/node_modules/nostr-tools/lib/cjs/abstract-relay.js.map +2 -2
  18. package/node_modules/nostr-tools/lib/cjs/core.js +1 -17
  19. package/node_modules/nostr-tools/lib/cjs/core.js.map +3 -3
  20. package/node_modules/nostr-tools/lib/cjs/filter.js.map +1 -1
  21. package/node_modules/nostr-tools/lib/cjs/index.js +130 -172
  22. package/node_modules/nostr-tools/lib/cjs/index.js.map +4 -4
  23. package/node_modules/nostr-tools/lib/cjs/kinds.js +1 -17
  24. package/node_modules/nostr-tools/lib/cjs/kinds.js.map +3 -3
  25. package/node_modules/nostr-tools/lib/cjs/nip04.js.map +1 -1
  26. package/node_modules/nostr-tools/lib/cjs/nip10.js +5 -20
  27. package/node_modules/nostr-tools/lib/cjs/nip10.js.map +3 -3
  28. package/node_modules/nostr-tools/lib/cjs/nip13.js.map +1 -1
  29. package/node_modules/nostr-tools/lib/cjs/nip17.js +23 -30
  30. package/node_modules/nostr-tools/lib/cjs/nip17.js.map +4 -4
  31. package/node_modules/nostr-tools/lib/cjs/nip18.js +14 -21
  32. package/node_modules/nostr-tools/lib/cjs/nip18.js.map +4 -4
  33. package/node_modules/nostr-tools/lib/cjs/nip19.js.map +1 -1
  34. package/node_modules/nostr-tools/lib/cjs/nip21.js.map +1 -1
  35. package/node_modules/nostr-tools/lib/cjs/nip22.js +7 -22
  36. package/node_modules/nostr-tools/lib/cjs/nip22.js.map +3 -3
  37. package/node_modules/nostr-tools/lib/cjs/nip25.js +14 -21
  38. package/node_modules/nostr-tools/lib/cjs/nip25.js.map +4 -4
  39. package/node_modules/nostr-tools/lib/cjs/nip27.js.map +1 -1
  40. package/node_modules/nostr-tools/lib/cjs/nip28.js +14 -21
  41. package/node_modules/nostr-tools/lib/cjs/nip28.js.map +4 -4
  42. package/node_modules/nostr-tools/lib/cjs/nip29.js.map +1 -1
  43. package/node_modules/nostr-tools/lib/cjs/nip30.js.map +2 -2
  44. package/node_modules/nostr-tools/lib/cjs/nip42.js.map +2 -2
  45. package/node_modules/nostr-tools/lib/cjs/nip44.js.map +1 -1
  46. package/node_modules/nostr-tools/lib/cjs/nip45.js +9 -22
  47. package/node_modules/nostr-tools/lib/cjs/nip45.js.map +4 -4
  48. package/node_modules/nostr-tools/lib/cjs/nip46.js +70 -111
  49. package/node_modules/nostr-tools/lib/cjs/nip46.js.map +4 -4
  50. package/node_modules/nostr-tools/lib/cjs/nip47.js +18 -25
  51. package/node_modules/nostr-tools/lib/cjs/nip47.js.map +4 -4
  52. package/node_modules/nostr-tools/lib/cjs/nip57.js +16 -23
  53. package/node_modules/nostr-tools/lib/cjs/nip57.js.map +4 -4
  54. package/node_modules/nostr-tools/lib/cjs/nip58.js.map +2 -2
  55. package/node_modules/nostr-tools/lib/cjs/nip59.js +7 -16
  56. package/node_modules/nostr-tools/lib/cjs/nip59.js.map +3 -3
  57. package/node_modules/nostr-tools/lib/cjs/nip75.js.map +1 -1
  58. package/node_modules/nostr-tools/lib/cjs/nip94.js.map +1 -1
  59. package/node_modules/nostr-tools/lib/cjs/nip98.js +16 -23
  60. package/node_modules/nostr-tools/lib/cjs/nip98.js.map +4 -4
  61. package/node_modules/nostr-tools/lib/cjs/nip99.js.map +2 -2
  62. package/node_modules/nostr-tools/lib/cjs/nipb0.js +17 -38
  63. package/node_modules/nostr-tools/lib/cjs/nipb0.js.map +4 -4
  64. package/node_modules/nostr-tools/lib/cjs/nipb7.js +7 -13
  65. package/node_modules/nostr-tools/lib/cjs/nipb7.js.map +2 -2
  66. package/node_modules/nostr-tools/lib/cjs/pool.js +61 -102
  67. package/node_modules/nostr-tools/lib/cjs/pool.js.map +4 -4
  68. package/node_modules/nostr-tools/lib/cjs/pure.js +14 -21
  69. package/node_modules/nostr-tools/lib/cjs/pure.js.map +4 -4
  70. package/node_modules/nostr-tools/lib/cjs/references.js.map +1 -1
  71. package/node_modules/nostr-tools/lib/cjs/relay.js +42 -86
  72. package/node_modules/nostr-tools/lib/cjs/relay.js.map +4 -4
  73. package/node_modules/nostr-tools/lib/cjs/signer.js +14 -21
  74. package/node_modules/nostr-tools/lib/cjs/signer.js.map +4 -4
  75. package/node_modules/nostr-tools/lib/cjs/utils.js +0 -10
  76. package/node_modules/nostr-tools/lib/cjs/utils.js.map +2 -2
  77. package/node_modules/nostr-tools/lib/cjs/wasm.js +2 -16
  78. package/node_modules/nostr-tools/lib/cjs/wasm.js.map +4 -4
  79. package/node_modules/nostr-tools/lib/esm/abstract-pool.js +28 -59
  80. package/node_modules/nostr-tools/lib/esm/abstract-pool.js.map +3 -3
  81. package/node_modules/nostr-tools/lib/esm/abstract-relay.js +7 -44
  82. package/node_modules/nostr-tools/lib/esm/abstract-relay.js.map +2 -2
  83. package/node_modules/nostr-tools/lib/esm/core.js +1 -15
  84. package/node_modules/nostr-tools/lib/esm/core.js.map +3 -3
  85. package/node_modules/nostr-tools/lib/esm/filter.js.map +1 -1
  86. package/node_modules/nostr-tools/lib/esm/index.js +80 -122
  87. package/node_modules/nostr-tools/lib/esm/index.js.map +4 -4
  88. package/node_modules/nostr-tools/lib/esm/kinds.js +1 -17
  89. package/node_modules/nostr-tools/lib/esm/kinds.js.map +3 -3
  90. package/node_modules/nostr-tools/lib/esm/nip04.js.map +1 -1
  91. package/node_modules/nostr-tools/lib/esm/nip10.js +5 -18
  92. package/node_modules/nostr-tools/lib/esm/nip10.js.map +3 -3
  93. package/node_modules/nostr-tools/lib/esm/nip13.js.map +1 -1
  94. package/node_modules/nostr-tools/lib/esm/nip17.js +8 -15
  95. package/node_modules/nostr-tools/lib/esm/nip17.js.map +4 -4
  96. package/node_modules/nostr-tools/lib/esm/nip18.js +8 -15
  97. package/node_modules/nostr-tools/lib/esm/nip18.js.map +4 -4
  98. package/node_modules/nostr-tools/lib/esm/nip19.js.map +1 -1
  99. package/node_modules/nostr-tools/lib/esm/nip21.js.map +1 -1
  100. package/node_modules/nostr-tools/lib/esm/nip22.js +7 -20
  101. package/node_modules/nostr-tools/lib/esm/nip22.js.map +3 -3
  102. package/node_modules/nostr-tools/lib/esm/nip25.js +8 -15
  103. package/node_modules/nostr-tools/lib/esm/nip25.js.map +4 -4
  104. package/node_modules/nostr-tools/lib/esm/nip27.js.map +1 -1
  105. package/node_modules/nostr-tools/lib/esm/nip28.js +8 -15
  106. package/node_modules/nostr-tools/lib/esm/nip28.js.map +4 -4
  107. package/node_modules/nostr-tools/lib/esm/nip29.js.map +1 -1
  108. package/node_modules/nostr-tools/lib/esm/nip30.js.map +2 -2
  109. package/node_modules/nostr-tools/lib/esm/nip42.js.map +2 -2
  110. package/node_modules/nostr-tools/lib/esm/nip44.js.map +1 -1
  111. package/node_modules/nostr-tools/lib/esm/nip45.js +10 -23
  112. package/node_modules/nostr-tools/lib/esm/nip45.js.map +4 -4
  113. package/node_modules/nostr-tools/lib/esm/nip46.js +54 -95
  114. package/node_modules/nostr-tools/lib/esm/nip46.js.map +4 -4
  115. package/node_modules/nostr-tools/lib/esm/nip47.js +8 -15
  116. package/node_modules/nostr-tools/lib/esm/nip47.js.map +4 -4
  117. package/node_modules/nostr-tools/lib/esm/nip57.js +10 -17
  118. package/node_modules/nostr-tools/lib/esm/nip57.js.map +4 -4
  119. package/node_modules/nostr-tools/lib/esm/nip58.js.map +2 -2
  120. package/node_modules/nostr-tools/lib/esm/nip59.js +1 -10
  121. package/node_modules/nostr-tools/lib/esm/nip59.js.map +3 -3
  122. package/node_modules/nostr-tools/lib/esm/nip75.js.map +1 -1
  123. package/node_modules/nostr-tools/lib/esm/nip94.js.map +1 -1
  124. package/node_modules/nostr-tools/lib/esm/nip98.js +8 -15
  125. package/node_modules/nostr-tools/lib/esm/nip98.js.map +4 -4
  126. package/node_modules/nostr-tools/lib/esm/nip99.js.map +2 -2
  127. package/node_modules/nostr-tools/lib/esm/nipb0.js +18 -39
  128. package/node_modules/nostr-tools/lib/esm/nipb0.js.map +4 -4
  129. package/node_modules/nostr-tools/lib/esm/nipb7.js +7 -13
  130. package/node_modules/nostr-tools/lib/esm/nipb7.js.map +2 -2
  131. package/node_modules/nostr-tools/lib/esm/pool.js +54 -95
  132. package/node_modules/nostr-tools/lib/esm/pool.js.map +4 -4
  133. package/node_modules/nostr-tools/lib/esm/pure.js +8 -15
  134. package/node_modules/nostr-tools/lib/esm/pure.js.map +4 -4
  135. package/node_modules/nostr-tools/lib/esm/references.js.map +1 -1
  136. package/node_modules/nostr-tools/lib/esm/relay.js +36 -80
  137. package/node_modules/nostr-tools/lib/esm/relay.js.map +4 -4
  138. package/node_modules/nostr-tools/lib/esm/signer.js +8 -15
  139. package/node_modules/nostr-tools/lib/esm/signer.js.map +4 -4
  140. package/node_modules/nostr-tools/lib/esm/utils.js +0 -10
  141. package/node_modules/nostr-tools/lib/esm/utils.js.map +2 -2
  142. package/node_modules/nostr-tools/lib/esm/wasm.js +3 -17
  143. package/node_modules/nostr-tools/lib/esm/wasm.js.map +4 -4
  144. package/node_modules/nostr-tools/lib/nostr.bundle.js +77 -121
  145. package/node_modules/nostr-tools/lib/nostr.bundle.js.map +4 -4
  146. package/node_modules/nostr-tools/lib/types/abstract-pool.d.ts +4 -7
  147. package/node_modules/nostr-tools/lib/types/abstract-relay.d.ts +2 -7
  148. package/node_modules/nostr-tools/lib/types/helpers.d.ts +2 -0
  149. package/node_modules/nostr-tools/lib/types/kinds.d.ts +0 -2
  150. package/node_modules/nostr-tools/lib/types/nipb0.d.ts +1 -0
  151. package/node_modules/nostr-tools/lib/types/nipb7.d.ts +1 -0
  152. package/node_modules/nostr-tools/lib/types/relay.d.ts +2 -2
  153. package/node_modules/nostr-tools/lib/types/utils.d.ts +0 -4
  154. package/node_modules/nostr-tools/package.json +1 -1
  155. package/openclaw.plugin.json +5 -0
  156. package/package.json +15 -41
  157. package/dist/inbound-direct-dm-runtime-DHn9NoYN.js +0 -2
  158. package/node_modules/nostr-tools/lib/types/nipb0.test.d.ts +0 -1
  159. /package/dist/{state-account-id-CvBZ9s6P.js → .setup/state-account-id-CvBZ9s6P.mjs} +0 -0
@@ -34,42 +34,7 @@ module.exports = __toCommonJS(nip46_exports);
34
34
 
35
35
  // pure.ts
36
36
  var import_secp256k1 = require("@noble/curves/secp256k1.js");
37
- var import_utils3 = require("@noble/hashes/utils.js");
38
-
39
- // utils.ts
40
- var import_utils = require("@noble/hashes/utils.js");
41
- var utf8Decoder = new TextDecoder("utf-8");
42
- var utf8Encoder = new TextEncoder();
43
- function normalizeURL(url) {
44
- try {
45
- if (url.indexOf("://") === -1)
46
- url = "wss://" + url;
47
- let p = new URL(url);
48
- if (p.protocol === "http:")
49
- p.protocol = "ws:";
50
- else if (p.protocol === "https:")
51
- p.protocol = "wss:";
52
- p.pathname = p.pathname.replace(/\/+/g, "/");
53
- if (p.pathname.endsWith("/"))
54
- p.pathname = p.pathname.slice(0, -1);
55
- if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
56
- p.port = "";
57
- p.searchParams.sort();
58
- p.hash = "";
59
- return p.toString();
60
- } catch (e) {
61
- throw new Error(`Invalid URL: ${url}`);
62
- }
63
- }
64
- function isHex32(input) {
65
- for (let i2 = 0; i2 < 64; i2++) {
66
- let cc = input.charCodeAt(i2);
67
- if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
68
- return false;
69
- }
70
- }
71
- return true;
72
- }
37
+ var import_utils2 = require("@noble/hashes/utils.js");
73
38
 
74
39
  // core.ts
75
40
  var verifiedSymbol = Symbol("verified");
@@ -85,7 +50,7 @@ function validateEvent(event) {
85
50
  return false;
86
51
  if (typeof event.pubkey !== "string")
87
52
  return false;
88
- if (!isHex32(event.pubkey))
53
+ if (!event.pubkey.match(/^[a-f0-9]{64}$/))
89
54
  return false;
90
55
  if (!Array.isArray(event.tags))
91
56
  return false;
@@ -103,18 +68,46 @@ function validateEvent(event) {
103
68
 
104
69
  // pure.ts
105
70
  var import_sha2 = require("@noble/hashes/sha2.js");
71
+
72
+ // utils.ts
73
+ var import_utils = require("@noble/hashes/utils.js");
74
+ var utf8Decoder = new TextDecoder("utf-8");
75
+ var utf8Encoder = new TextEncoder();
76
+ function normalizeURL(url) {
77
+ try {
78
+ if (url.indexOf("://") === -1)
79
+ url = "wss://" + url;
80
+ let p = new URL(url);
81
+ if (p.protocol === "http:")
82
+ p.protocol = "ws:";
83
+ else if (p.protocol === "https:")
84
+ p.protocol = "wss:";
85
+ p.pathname = p.pathname.replace(/\/+/g, "/");
86
+ if (p.pathname.endsWith("/"))
87
+ p.pathname = p.pathname.slice(0, -1);
88
+ if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
89
+ p.port = "";
90
+ p.searchParams.sort();
91
+ p.hash = "";
92
+ return p.toString();
93
+ } catch (e) {
94
+ throw new Error(`Invalid URL: ${url}`);
95
+ }
96
+ }
97
+
98
+ // pure.ts
106
99
  var JS = class {
107
100
  generateSecretKey() {
108
101
  return import_secp256k1.schnorr.utils.randomSecretKey();
109
102
  }
110
103
  getPublicKey(secretKey) {
111
- return (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
104
+ return (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
112
105
  }
113
106
  finalizeEvent(t, secretKey) {
114
107
  const event = t;
115
- event.pubkey = (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
108
+ event.pubkey = (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
116
109
  event.id = getEventHash(event);
117
- event.sig = (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.sign((0, import_utils3.hexToBytes)(getEventHash(event)), secretKey));
110
+ event.sig = (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.sign((0, import_utils2.hexToBytes)(getEventHash(event)), secretKey));
118
111
  event[verifiedSymbol] = true;
119
112
  return event;
120
113
  }
@@ -127,7 +120,7 @@ var JS = class {
127
120
  event[verifiedSymbol] = false;
128
121
  return false;
129
122
  }
130
- const valid = import_secp256k1.schnorr.verify((0, import_utils3.hexToBytes)(event.sig), (0, import_utils3.hexToBytes)(hash), (0, import_utils3.hexToBytes)(event.pubkey));
123
+ const valid = import_secp256k1.schnorr.verify((0, import_utils2.hexToBytes)(event.sig), (0, import_utils2.hexToBytes)(hash), (0, import_utils2.hexToBytes)(event.pubkey));
131
124
  event[verifiedSymbol] = valid;
132
125
  return valid;
133
126
  } catch (err) {
@@ -143,7 +136,7 @@ function serializeEvent(evt) {
143
136
  }
144
137
  function getEventHash(event) {
145
138
  let eventHash = (0, import_sha2.sha256)(utf8Encoder.encode(serializeEvent(event)));
146
- return (0, import_utils3.bytesToHex)(eventHash);
139
+ return (0, import_utils2.bytesToHex)(eventHash);
147
140
  }
148
141
  var i = new JS();
149
142
  var generateSecretKey = i.generateSecretKey;
@@ -153,18 +146,18 @@ var verifyEvent = i.verifyEvent;
153
146
 
154
147
  // nip44.ts
155
148
  var import_chacha = require("@noble/ciphers/chacha.js");
156
- var import_utils5 = require("@noble/ciphers/utils.js");
149
+ var import_utils4 = require("@noble/ciphers/utils.js");
157
150
  var import_secp256k12 = require("@noble/curves/secp256k1.js");
158
151
  var import_hkdf = require("@noble/hashes/hkdf.js");
159
152
  var import_hmac = require("@noble/hashes/hmac.js");
160
153
  var import_sha22 = require("@noble/hashes/sha2.js");
161
- var import_utils6 = require("@noble/hashes/utils.js");
154
+ var import_utils5 = require("@noble/hashes/utils.js");
162
155
  var import_base = require("@scure/base");
163
156
  var minPlaintextSize = 1;
164
157
  var maxPlaintextSize = 4294967295;
165
158
  var extendedPrefixThreshold = 65536;
166
159
  function getConversationKey(privkeyA, pubkeyB) {
167
- const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0, import_utils6.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
160
+ const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0, import_utils5.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
168
161
  return (0, import_hkdf.extract)(import_sha22.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
169
162
  }
170
163
  function getMessageKeys(conversationKey, nonce) {
@@ -203,9 +196,9 @@ function pad(plaintext) {
203
196
  const unpaddedLen = unpadded.length;
204
197
  if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
205
198
  throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
206
- const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils6.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
199
+ const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils5.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
207
200
  const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
208
- return (0, import_utils6.concatBytes)(prefix, unpadded, suffix);
201
+ return (0, import_utils5.concatBytes)(prefix, unpadded, suffix);
209
202
  }
210
203
  function unpad(padded) {
211
204
  const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
@@ -229,7 +222,7 @@ function unpad(padded) {
229
222
  function hmacAad(key, message, aad) {
230
223
  if (aad.length !== 32)
231
224
  throw new Error("AAD associated data must be 32 bytes");
232
- const combined = (0, import_utils6.concatBytes)(aad, message);
225
+ const combined = (0, import_utils5.concatBytes)(aad, message);
233
226
  return (0, import_hmac.hmac)(import_sha22.sha256, key, combined);
234
227
  }
235
228
  function decodePayload(payload) {
@@ -258,18 +251,18 @@ function decodePayload(payload) {
258
251
  mac: data.subarray(-32)
259
252
  };
260
253
  }
261
- function encrypt(plaintext, conversationKey, nonce = (0, import_utils6.randomBytes)(32)) {
254
+ function encrypt(plaintext, conversationKey, nonce = (0, import_utils5.randomBytes)(32)) {
262
255
  const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
263
256
  const padded = pad(plaintext);
264
257
  const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
265
258
  const mac = hmacAad(hmac_key, ciphertext, nonce);
266
- return import_base.base64.encode((0, import_utils6.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
259
+ return import_base.base64.encode((0, import_utils5.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
267
260
  }
268
261
  function decrypt(payload, conversationKey) {
269
262
  const { nonce, ciphertext, mac } = decodePayload(payload);
270
263
  const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
271
264
  const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
272
- if (!(0, import_utils5.equalBytes)(calculatedMac, mac))
265
+ if (!(0, import_utils4.equalBytes)(calculatedMac, mac))
273
266
  throw new Error("invalid MAC");
274
267
  const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
275
268
  return unpad(padded);
@@ -379,14 +372,12 @@ var AbstractRelay = class {
379
372
  openSubs = /* @__PURE__ */ new Map();
380
373
  enablePing;
381
374
  enableReconnect;
382
- idleTimeout = 0;
383
375
  idleSince = Date.now();
384
376
  ongoingOperations = 0;
385
377
  reconnectTimeoutHandle;
386
378
  pingIntervalHandle;
387
379
  reconnectAttempts = 0;
388
380
  skipReconnection = false;
389
- idleTimeoutHandle;
390
381
  connectionPromise;
391
382
  openCountRequests = /* @__PURE__ */ new Map();
392
383
  openEventPublishes = /* @__PURE__ */ new Map();
@@ -402,8 +393,6 @@ var AbstractRelay = class {
402
393
  this._WebSocket = opts.websocketImplementation || WebSocket;
403
394
  this.enablePing = opts.enablePing;
404
395
  this.enableReconnect = opts.enableReconnect || false;
405
- if (opts.idleTimeout)
406
- this.idleTimeout = opts.idleTimeout;
407
396
  }
408
397
  static async connect(url, opts) {
409
398
  const relay = new AbstractRelay(url, opts);
@@ -427,22 +416,6 @@ var AbstractRelay = class {
427
416
  get connected() {
428
417
  return this._connected;
429
418
  }
430
- clearIdleTimeout() {
431
- if (this.idleTimeoutHandle) {
432
- clearTimeout(this.idleTimeoutHandle);
433
- this.idleTimeoutHandle = void 0;
434
- }
435
- }
436
- scheduleIdleClose() {
437
- this.clearIdleTimeout();
438
- if (this.idleTimeout > 0) {
439
- this.idleTimeoutHandle = setTimeout(() => {
440
- if (this.ongoingOperations === 0 && this.idleSince) {
441
- this.close();
442
- }
443
- }, this.idleTimeout);
444
- }
445
- }
446
419
  async reconnect() {
447
420
  const backoff = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
448
421
  this.reconnectAttempts++;
@@ -454,11 +427,6 @@ var AbstractRelay = class {
454
427
  }, backoff);
455
428
  }
456
429
  handleHardClose(reason) {
457
- if (this.ws) {
458
- this.ws.onopen = null;
459
- this.ws.onerror = null;
460
- this.ws.onclose = null;
461
- }
462
430
  if (this.pingIntervalHandle) {
463
431
  clearInterval(this.pingIntervalHandle);
464
432
  this.pingIntervalHandle = void 0;
@@ -466,7 +434,6 @@ var AbstractRelay = class {
466
434
  this._connected = false;
467
435
  this.connectionPromise = void 0;
468
436
  this.idleSince = void 0;
469
- this.clearIdleTimeout();
470
437
  if (this.enableReconnect && !this.skipReconnection) {
471
438
  this.reconnect();
472
439
  } else {
@@ -489,6 +456,7 @@ var AbstractRelay = class {
489
456
  if (this.reconnectAttempts === 0) {
490
457
  this.skipReconnection = true;
491
458
  }
459
+ this.onclose?.();
492
460
  this.handleHardClose("relay connection timed out");
493
461
  }, opts.timeout);
494
462
  }
@@ -534,6 +502,7 @@ var AbstractRelay = class {
534
502
  if (this.reconnectAttempts === 0) {
535
503
  this.skipReconnection = true;
536
504
  }
505
+ this.onclose?.();
537
506
  this.handleHardClose("relay connection failed");
538
507
  };
539
508
  this.ws.onclose = (ev) => {
@@ -622,7 +591,6 @@ var AbstractRelay = class {
622
591
  }
623
592
  async publish(event) {
624
593
  this.idleSince = void 0;
625
- this.clearIdleTimeout();
626
594
  this.ongoingOperations++;
627
595
  const ret = new Promise((resolve, reject) => {
628
596
  const timeout = setTimeout(() => {
@@ -644,10 +612,8 @@ var AbstractRelay = class {
644
612
  }
645
613
  }
646
614
  this.ongoingOperations--;
647
- if (this.ongoingOperations === 0) {
615
+ if (this.ongoingOperations === 0)
648
616
  this.idleSince = Date.now();
649
- this.scheduleIdleClose();
650
- }
651
617
  return ret;
652
618
  }
653
619
  async count(filters, params) {
@@ -673,7 +639,6 @@ var AbstractRelay = class {
673
639
  subscribe(filters, params) {
674
640
  if (params.label !== "<forced-ping>") {
675
641
  this.idleSince = void 0;
676
- this.clearIdleTimeout();
677
642
  this.ongoingOperations++;
678
643
  }
679
644
  const sub = this.prepareSubscription(filters, params);
@@ -702,17 +667,10 @@ var AbstractRelay = class {
702
667
  }
703
668
  this.closeAllSubscriptions("relay connection closed by us");
704
669
  this._connected = false;
705
- this.connectionPromise = void 0;
706
670
  this.idleSince = void 0;
707
- this.clearIdleTimeout();
708
671
  this.onclose?.();
709
- if (this.ws) {
710
- this.ws.onopen = null;
711
- this.ws.onerror = null;
712
- this.ws.onclose = null;
713
- if (this.ws.readyState !== this._WebSocket.CLOSING && this.ws.readyState !== this._WebSocket.CLOSED) {
714
- this.ws.close();
715
- }
672
+ if (this.ws?.readyState === this._WebSocket.OPEN) {
673
+ this.ws?.close();
716
674
  }
717
675
  }
718
676
  _onmessage(ev) {
@@ -739,7 +697,7 @@ var AbstractRelay = class {
739
697
  case "EVENT": {
740
698
  const so = this.openSubs.get(data[1]);
741
699
  const event = data[2];
742
- if (matchFilters(so.filters, event) && this.verifyEvent(event, this.url)) {
700
+ if (this.verifyEvent(event) && matchFilters(so.filters, event)) {
743
701
  so.onevent(event);
744
702
  } else {
745
703
  so.oninvalidevent?.(event);
@@ -887,17 +845,21 @@ var Subscription = class {
887
845
  }
888
846
  this.relay.openSubs.delete(this.id);
889
847
  this.relay.ongoingOperations--;
890
- if (this.relay.ongoingOperations === 0) {
848
+ if (this.relay.ongoingOperations === 0)
891
849
  this.relay.idleSince = Date.now();
892
- this.relay.scheduleIdleClose();
893
- }
894
850
  this.onclose?.(reason);
895
851
  }
896
852
  };
897
853
 
854
+ // helpers.ts
855
+ var alwaysTrue = (t) => {
856
+ t[verifiedSymbol] = true;
857
+ return true;
858
+ };
859
+
898
860
  // nip45.ts
899
861
  var import_sha23 = require("@noble/hashes/sha2.js");
900
- var import_utils9 = require("@noble/hashes/utils.js");
862
+ var import_utils8 = require("@noble/hashes/utils.js");
901
863
  var M = 256;
902
864
  var HLL_HEX_LENGTH = M * 2;
903
865
  var utf8Encoder2 = new TextEncoder();
@@ -921,7 +883,7 @@ function newHll() {
921
883
  return new Uint8Array(M);
922
884
  }
923
885
  function hllDecode(hex) {
924
- if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-f]+$/.test(hex))
886
+ if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
925
887
  return void 0;
926
888
  const registers = new Uint8Array(M);
927
889
  for (let i2 = 0; i2 < M; i2++) {
@@ -960,8 +922,8 @@ var AbstractSimplePool = class {
960
922
  verifyEvent;
961
923
  enablePing;
962
924
  enableReconnect;
963
- idleTimeout = 2e4;
964
925
  automaticallyAuth;
926
+ trustedRelayURLs = /* @__PURE__ */ new Set();
965
927
  onRelayConnectionFailure;
966
928
  onRelayConnectionSuccess;
967
929
  allowConnectingToRelay;
@@ -972,8 +934,6 @@ var AbstractSimplePool = class {
972
934
  this._WebSocket = opts.websocketImplementation;
973
935
  this.enablePing = opts.enablePing;
974
936
  this.enableReconnect = opts.enableReconnect || false;
975
- if (opts.idleTimeout)
976
- this.idleTimeout = opts.idleTimeout;
977
937
  this.automaticallyAuth = opts.automaticallyAuth;
978
938
  this.onRelayConnectionFailure = opts.onRelayConnectionFailure;
979
939
  this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess;
@@ -985,11 +945,10 @@ var AbstractSimplePool = class {
985
945
  let relay = this.relays.get(url);
986
946
  if (!relay) {
987
947
  relay = new AbstractRelay(url, {
988
- verifyEvent: this.verifyEvent,
948
+ verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
989
949
  websocketImplementation: this._WebSocket,
990
950
  enablePing: this.enablePing,
991
- enableReconnect: this.enableReconnect,
992
- idleTimeout: this.idleTimeout
951
+ enableReconnect: this.enableReconnect
993
952
  });
994
953
  relay.onclose = () => {
995
954
  this.relays.delete(url);
@@ -1069,11 +1028,11 @@ var AbstractSimplePool = class {
1069
1028
  }
1070
1029
  };
1071
1030
  const closesReceived = [];
1072
- let handleClose = (i2, url, reason) => {
1031
+ let handleClose = (i2, reason) => {
1073
1032
  if (closesReceived[i2])
1074
1033
  return;
1075
1034
  handleEose(i2);
1076
- closesReceived[i2] = { url, reason };
1035
+ closesReceived[i2] = reason;
1077
1036
  if (closesReceived.filter((a) => a).length === groupedRequests.length) {
1078
1037
  params.onclose?.(closesReceived);
1079
1038
  handleClose = () => {
@@ -1091,7 +1050,7 @@ var AbstractSimplePool = class {
1091
1050
  const allOpened = Promise.all(
1092
1051
  groupedRequests.map(async ({ url, filters }, i2) => {
1093
1052
  if (this.allowConnectingToRelay?.(url, ["read", filters]) === false) {
1094
- handleClose(i2, url, "connection skipped by allowConnectingToRelay");
1053
+ handleClose(i2, "connection skipped by allowConnectingToRelay");
1095
1054
  return;
1096
1055
  }
1097
1056
  let relay;
@@ -1102,7 +1061,7 @@ var AbstractSimplePool = class {
1102
1061
  });
1103
1062
  } catch (err) {
1104
1063
  this.onRelayConnectionFailure?.(url);
1105
- handleClose(i2, url, err?.message || String(err));
1064
+ handleClose(i2, err?.message || String(err));
1106
1065
  return;
1107
1066
  }
1108
1067
  this.onRelayConnectionSuccess?.(url);
@@ -1116,17 +1075,17 @@ var AbstractSimplePool = class {
1116
1075
  ...params,
1117
1076
  oneose: () => handleEose(i2),
1118
1077
  onclose: (reason2) => {
1119
- handleClose(i2, url, reason2);
1078
+ handleClose(i2, reason2);
1120
1079
  },
1121
1080
  alreadyHaveEvent: localAlreadyHaveEventHandler,
1122
1081
  eoseTimeout: params.maxWait,
1123
1082
  abort: params.abort
1124
1083
  });
1125
1084
  }).catch((err) => {
1126
- handleClose(i2, url, `auth was required and attempted, but failed with: ${err}`);
1085
+ handleClose(i2, `auth was required and attempted, but failed with: ${err}`);
1127
1086
  });
1128
1087
  } else {
1129
- handleClose(i2, url, reason);
1088
+ handleClose(i2, reason);
1130
1089
  }
1131
1090
  },
1132
1091
  alreadyHaveEvent: localAlreadyHaveEventHandler,
@@ -1154,7 +1113,7 @@ var AbstractSimplePool = class {
1154
1113
  if (subcloser)
1155
1114
  subcloser.close(reason);
1156
1115
  else
1157
- params.onclose?.(relays.map((url) => ({ url, reason })));
1116
+ params.onclose?.(relays.map((_) => reason));
1158
1117
  }
1159
1118
  });
1160
1119
  return subcloser;