nostr-tools 2.9.1 → 2.9.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/lib/cjs/index.js CHANGED
@@ -2176,7 +2176,9 @@ __export(nip59_exports, {
2176
2176
  createSeal: () => createSeal,
2177
2177
  createWrap: () => createWrap,
2178
2178
  unwrapEvent: () => unwrapEvent,
2179
- wrapEvent: () => wrapEvent
2179
+ unwrapManyEvents: () => unwrapManyEvents,
2180
+ wrapEvent: () => wrapEvent,
2181
+ wrapManyEvents: () => wrapManyEvents
2180
2182
  });
2181
2183
  var TWO_DAYS = 2 * 24 * 60 * 60;
2182
2184
  var now = () => Math.round(Date.now() / 1e3);
@@ -2223,10 +2225,29 @@ function wrapEvent(event, senderPrivateKey, recipientPublicKey) {
2223
2225
  const seal = createSeal(rumor, senderPrivateKey, recipientPublicKey);
2224
2226
  return createWrap(seal, recipientPublicKey);
2225
2227
  }
2228
+ function wrapManyEvents(event, senderPrivateKey, recipientsPublicKeys) {
2229
+ if (!recipientsPublicKeys || recipientsPublicKeys.length === 0) {
2230
+ throw new Error("At least one recipient is required.");
2231
+ }
2232
+ const senderPublicKey = getPublicKey(senderPrivateKey);
2233
+ const wrappeds = [wrapEvent(event, senderPrivateKey, senderPublicKey)];
2234
+ recipientsPublicKeys.forEach((recipientPublicKey) => {
2235
+ wrappeds.push(wrapEvent(event, senderPrivateKey, recipientPublicKey));
2236
+ });
2237
+ return wrappeds;
2238
+ }
2226
2239
  function unwrapEvent(wrap, recipientPrivateKey) {
2227
2240
  const unwrappedSeal = nip44Decrypt(wrap, recipientPrivateKey);
2228
2241
  return nip44Decrypt(unwrappedSeal, recipientPrivateKey);
2229
2242
  }
2243
+ function unwrapManyEvents(wrappedEvents, recipientPrivateKey) {
2244
+ let unwrappedEvents = [];
2245
+ wrappedEvents.forEach((e) => {
2246
+ unwrappedEvents.push(unwrapEvent(e, recipientPrivateKey));
2247
+ });
2248
+ unwrappedEvents.sort((a, b) => a.created_at - b.created_at);
2249
+ return unwrappedEvents;
2250
+ }
2230
2251
 
2231
2252
  // nip98.ts
2232
2253
  var nip98_exports = {};