routstrd 0.2.22 → 0.3.0

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/index.js CHANGED
@@ -27,6 +27,7 @@ var __export = (target, all) => {
27
27
  });
28
28
  };
29
29
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
30
+ var __require = import.meta.require;
30
31
 
31
32
  // node_modules/commander/lib/error.js
32
33
  var require_error = __commonJS((exports) => {
@@ -748,11 +749,11 @@ var require_suggestSimilar = __commonJS((exports) => {
748
749
 
749
750
  // node_modules/commander/lib/command.js
750
751
  var require_command = __commonJS((exports) => {
751
- var EventEmitter = import.meta.require("events").EventEmitter;
752
- var childProcess = import.meta.require("child_process");
753
- var path = import.meta.require("path");
754
- var fs = import.meta.require("fs");
755
- var process2 = import.meta.require("process");
752
+ var EventEmitter = __require("events").EventEmitter;
753
+ var childProcess = __require("child_process");
754
+ var path = __require("path");
755
+ var fs = __require("fs");
756
+ var process2 = __require("process");
756
757
  var { Argument, humanReadableArgName } = require_argument();
757
758
  var { CommanderError } = require_error();
758
759
  var { Help, stripColor } = require_help();
@@ -1000,8 +1001,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1000
1001
  this._exitCallback = (err) => {
1001
1002
  if (err.code !== "commander.executeSubCommandAsync") {
1002
1003
  throw err;
1003
- } else {
1004
- }
1004
+ } else {}
1005
1005
  };
1006
1006
  }
1007
1007
  return this;
@@ -2235,8 +2235,7 @@ async function readLockOwner(lockDir) {
2235
2235
  token: typeof parsed.token === "string" ? parsed.token : undefined
2236
2236
  };
2237
2237
  }
2238
- } catch {
2239
- }
2238
+ } catch {}
2240
2239
  return null;
2241
2240
  }
2242
2241
  async function isLockStale(lockDir, staleAfterMs) {
@@ -2298,8 +2297,7 @@ async function withCrossProcessLock(lockDir, fn, options = {}) {
2298
2297
  await release();
2299
2298
  }
2300
2299
  }
2301
- var init_process_lock = () => {
2302
- };
2300
+ var init_process_lock = () => {};
2303
2301
 
2304
2302
  // src/start-daemon.ts
2305
2303
  async function isDaemonHealthy(port) {
@@ -5220,8 +5218,7 @@ function unsafeWrapper(fn) {
5220
5218
  return function(...args) {
5221
5219
  try {
5222
5220
  return fn.apply(null, args);
5223
- } catch (e) {
5224
- }
5221
+ } catch (e) {}
5225
5222
  };
5226
5223
  }
5227
5224
  function bech32Polymod(pre) {
@@ -7171,28 +7168,49 @@ function calcPaddedLen(len) {
7171
7168
  throw new Error("expected positive integer");
7172
7169
  if (len <= 32)
7173
7170
  return 32;
7174
- const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
7171
+ const nextPower = 2 ** (Math.floor(Math.log2(len - 1)) + 1);
7175
7172
  const chunk = nextPower <= 256 ? 32 : nextPower / 8;
7176
7173
  return chunk * (Math.floor((len - 1) / chunk) + 1);
7177
7174
  }
7178
7175
  function writeU16BE(num2) {
7179
- if (!Number.isSafeInteger(num2) || num2 < minPlaintextSize || num2 > maxPlaintextSize)
7176
+ if (!Number.isSafeInteger(num2) || num2 < minPlaintextSize || num2 > 65535)
7180
7177
  throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
7181
7178
  const arr = new Uint8Array(2);
7182
7179
  new DataView(arr.buffer).setUint16(0, num2, false);
7183
7180
  return arr;
7184
7181
  }
7182
+ function writeU32BE(num2) {
7183
+ if (!Number.isSafeInteger(num2) || num2 < extendedPrefixThreshold || num2 > maxPlaintextSize)
7184
+ throw new Error("invalid plaintext size: must be between 65536 and 4294967295 bytes");
7185
+ const arr = new Uint8Array(4);
7186
+ new DataView(arr.buffer).setUint32(0, num2, false);
7187
+ return arr;
7188
+ }
7185
7189
  function pad(plaintext) {
7186
7190
  const unpadded = utf8Encoder.encode(plaintext);
7187
7191
  const unpaddedLen = unpadded.length;
7188
- const prefix = writeU16BE(unpaddedLen);
7192
+ if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
7193
+ throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
7194
+ const prefix = unpaddedLen >= extendedPrefixThreshold ? concatBytes(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
7189
7195
  const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
7190
7196
  return concatBytes(prefix, unpadded, suffix);
7191
7197
  }
7192
7198
  function unpad(padded) {
7193
- const unpaddedLen = new DataView(padded.buffer).getUint16(0);
7194
- const unpadded = padded.subarray(2, 2 + unpaddedLen);
7195
- if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen))
7199
+ const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
7200
+ const firstTwo = dv.getUint16(0);
7201
+ let unpaddedLen;
7202
+ let prefixLen;
7203
+ if (firstTwo === 0) {
7204
+ unpaddedLen = dv.getUint32(2);
7205
+ if (unpaddedLen < extendedPrefixThreshold)
7206
+ throw new Error("invalid padding");
7207
+ prefixLen = 6;
7208
+ } else {
7209
+ unpaddedLen = firstTwo;
7210
+ prefixLen = 2;
7211
+ }
7212
+ const unpadded = padded.subarray(prefixLen, prefixLen + unpaddedLen);
7213
+ if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== prefixLen + calcPaddedLen(unpaddedLen))
7196
7214
  throw new Error("invalid padding");
7197
7215
  return utf8Decoder.decode(unpadded);
7198
7216
  }
@@ -7206,7 +7224,7 @@ function decodePayload(payload) {
7206
7224
  if (typeof payload !== "string")
7207
7225
  throw new Error("payload must be a valid string");
7208
7226
  const plen = payload.length;
7209
- if (plen < 132 || plen > 87472)
7227
+ if (plen < 132)
7210
7228
  throw new Error("invalid payload length: " + plen);
7211
7229
  if (payload[0] === "#")
7212
7230
  throw new Error("unknown encryption version");
@@ -7217,7 +7235,7 @@ function decodePayload(payload) {
7217
7235
  throw new Error("invalid base64: " + error.message);
7218
7236
  }
7219
7237
  const dlen = data.length;
7220
- if (dlen < 99 || dlen > 65603)
7238
+ if (dlen < 99)
7221
7239
  throw new Error("invalid data length: " + dlen);
7222
7240
  const vers = data[0];
7223
7241
  if (vers !== 2)
@@ -7403,6 +7421,135 @@ function parse2(uri) {
7403
7421
  decoded: decode(match[1])
7404
7422
  };
7405
7423
  }
7424
+ function parseKind(kind) {
7425
+ if (!kind)
7426
+ return;
7427
+ return /^\d+$/.test(kind) ? parseInt(kind, 10) : kind;
7428
+ }
7429
+ function parseAddressPointer(value, relayUrl) {
7430
+ const idx = value.indexOf(":");
7431
+ const idx2 = value.indexOf(":", idx + 1);
7432
+ if (idx === -1 || idx2 === -1)
7433
+ return;
7434
+ const kind = parseInt(value.slice(0, idx), 10);
7435
+ if (Number.isNaN(kind))
7436
+ return;
7437
+ return {
7438
+ kind,
7439
+ pubkey: value.slice(idx + 1, idx2),
7440
+ identifier: value.slice(idx2 + 1),
7441
+ relays: relayUrl ? [relayUrl] : []
7442
+ };
7443
+ }
7444
+ function parsePointer(tag) {
7445
+ switch (tag[0]) {
7446
+ case "E":
7447
+ case "e":
7448
+ if (!tag[1])
7449
+ return;
7450
+ return {
7451
+ id: tag[1],
7452
+ relays: tag[2] ? [tag[2]] : [],
7453
+ author: tag[3]
7454
+ };
7455
+ case "A":
7456
+ case "a":
7457
+ if (!tag[1])
7458
+ return;
7459
+ return parseAddressPointer(tag[1], tag[2]);
7460
+ case "I":
7461
+ case "i":
7462
+ if (!tag[1])
7463
+ return;
7464
+ return {
7465
+ value: tag[1],
7466
+ hint: tag[2]
7467
+ };
7468
+ }
7469
+ }
7470
+ function parseQuote(tag) {
7471
+ if (!tag[1])
7472
+ return;
7473
+ if (tag[1].includes(":")) {
7474
+ return parseAddressPointer(tag[1], tag[2]);
7475
+ }
7476
+ return {
7477
+ id: tag[1],
7478
+ relays: tag[2] ? [tag[2]] : [],
7479
+ author: tag[3]
7480
+ };
7481
+ }
7482
+ function choosePointer(candidates) {
7483
+ return candidates.findLast((candidate) => candidate.tagName === "A" || candidate.tagName === "a")?.pointer || candidates.findLast((candidate) => candidate.tagName === "I" || candidate.tagName === "i")?.pointer || candidates.findLast((candidate) => candidate.tagName === "E" || candidate.tagName === "e")?.pointer;
7484
+ }
7485
+ function inheritRelayHints(pointer, profiles) {
7486
+ if (!pointer || !("id" in pointer) || !pointer.author)
7487
+ return;
7488
+ const author = profiles.find((profile) => profile.pubkey === pointer.author);
7489
+ if (!author || !author.relays)
7490
+ return;
7491
+ if (!pointer.relays) {
7492
+ pointer.relays = [];
7493
+ }
7494
+ author.relays.forEach((url) => {
7495
+ if (pointer.relays.indexOf(url) === -1)
7496
+ pointer.relays.push(url);
7497
+ });
7498
+ author.relays = pointer.relays;
7499
+ }
7500
+ function parse3(event) {
7501
+ const result = {
7502
+ root: undefined,
7503
+ rootKind: undefined,
7504
+ reply: undefined,
7505
+ replyKind: undefined,
7506
+ mentions: [],
7507
+ quotes: [],
7508
+ profiles: []
7509
+ };
7510
+ const rootCandidates = [];
7511
+ const replyCandidates = [];
7512
+ for (const tag of event.tags) {
7513
+ if ((tag[0] === "E" || tag[0] === "A" || tag[0] === "I") && tag[1]) {
7514
+ const pointer = parsePointer(tag);
7515
+ if (pointer)
7516
+ rootCandidates.push({ tagName: tag[0], pointer });
7517
+ continue;
7518
+ }
7519
+ if ((tag[0] === "e" || tag[0] === "a" || tag[0] === "i") && tag[1]) {
7520
+ const pointer = parsePointer(tag);
7521
+ if (pointer)
7522
+ replyCandidates.push({ tagName: tag[0], pointer });
7523
+ continue;
7524
+ }
7525
+ if (tag[0] === "K") {
7526
+ result.rootKind = parseKind(tag[1]);
7527
+ continue;
7528
+ }
7529
+ if (tag[0] === "k") {
7530
+ result.replyKind = parseKind(tag[1]);
7531
+ continue;
7532
+ }
7533
+ if (tag[0] === "q") {
7534
+ const pointer = parseQuote(tag);
7535
+ if (pointer)
7536
+ result.quotes.push(pointer);
7537
+ continue;
7538
+ }
7539
+ if ((tag[0] === "P" || tag[0] === "p") && tag[1]) {
7540
+ result.profiles.push({
7541
+ pubkey: tag[1],
7542
+ relays: tag[2] ? [tag[2]] : []
7543
+ });
7544
+ }
7545
+ }
7546
+ result.root = choosePointer(rootCandidates);
7547
+ result.reply = choosePointer(replyCandidates);
7548
+ inheritRelayHints(result.root, result.profiles);
7549
+ inheritRelayHints(result.reply, result.profiles);
7550
+ result.quotes.forEach((pointer) => inheritRelayHints(pointer, result.profiles));
7551
+ return result;
7552
+ }
7406
7553
  function finishReactionEvent(t, reacted, privateKey) {
7407
7554
  const inheritedTags = reacted.tags.filter((tag) => tag.length >= 2 && (tag[0] === "e" || tag[0] === "p"));
7408
7555
  return finalizeEvent({
@@ -7437,7 +7584,7 @@ function getReactedEventPointer(event) {
7437
7584
  author: lastPTag[1]
7438
7585
  };
7439
7586
  }
7440
- function* parse3(content) {
7587
+ function* parse4(content) {
7441
7588
  let emojis = [];
7442
7589
  if (typeof content !== "string") {
7443
7590
  for (let i2 = 0;i2 < content.tags.length; i2++) {
@@ -7591,8 +7738,7 @@ function* matchAll(content) {
7591
7738
  start: match.index,
7592
7739
  end: match.index + shortcode.length
7593
7740
  };
7594
- } catch (_e) {
7595
- }
7741
+ } catch (_e) {}
7596
7742
  }
7597
7743
  }
7598
7744
  function replaceAll(content, replacer) {
@@ -7617,12 +7763,12 @@ async function validateGithub(pubkey, username, proof) {
7617
7763
  function parseConnectionString(connectionString) {
7618
7764
  const { host, pathname, searchParams } = new URL(connectionString);
7619
7765
  const pubkey = pathname || host;
7620
- const relay = searchParams.get("relay");
7766
+ const relays = searchParams.getAll("relay");
7621
7767
  const secret = searchParams.get("secret");
7622
- if (!pubkey || !relay || !secret) {
7768
+ if (!pubkey || relays.length === 0 || !secret) {
7623
7769
  throw new Error("invalid connection string");
7624
7770
  }
7625
- return { pubkey, relay, secret };
7771
+ return { pubkey, relay: relays[0], relays, secret };
7626
7772
  }
7627
7773
  async function makeNwcRequestEvent(pubkey, secretKey, invoice) {
7628
7774
  const content = {
@@ -7672,8 +7818,7 @@ async function getZapEndpoint(metadata) {
7672
7818
  if (body.allowsNostr && body.nostrPubkey) {
7673
7819
  return body.callback;
7674
7820
  }
7675
- } catch (err) {
7676
- }
7821
+ } catch (err) {}
7677
7822
  return null;
7678
7823
  }
7679
7824
  function makeZapRequest(params) {
@@ -8034,8 +8179,7 @@ var __defProp2, __export2 = (target, all) => {
8034
8179
  this.reconnectTimeoutHandle = setTimeout(async () => {
8035
8180
  try {
8036
8181
  await this.connect();
8037
- } catch (err) {
8038
- }
8182
+ } catch (err) {}
8039
8183
  }, backoff);
8040
8184
  }
8041
8185
  handleHardClose(reason) {
@@ -8339,7 +8483,11 @@ var __defProp2, __export2 = (target, all) => {
8339
8483
  case "AUTH": {
8340
8484
  this.challenge = data[1];
8341
8485
  if (this.onauth) {
8342
- this.auth(this.onauth);
8486
+ this.auth(this.onauth).catch((err) => {
8487
+ if (!(err instanceof SendingOnClosedConnection)) {
8488
+ throw err;
8489
+ }
8490
+ });
8343
8491
  }
8344
8492
  return;
8345
8493
  }
@@ -8407,8 +8555,7 @@ var __defProp2, __export2 = (target, all) => {
8407
8555
  try {
8408
8556
  this.relay.send('["CLOSE",' + JSON.stringify(this.id) + "]");
8409
8557
  } catch (err) {
8410
- if (err instanceof SendingOnClosedConnection) {
8411
- } else {
8558
+ if (err instanceof SendingOnClosedConnection) {} else {
8412
8559
  throw err;
8413
8560
  }
8414
8561
  }
@@ -8420,7 +8567,7 @@ var __defProp2, __export2 = (target, all) => {
8420
8567
  this.relay.idleSince = Date.now();
8421
8568
  this.onclose?.(reason);
8422
8569
  }
8423
- }, _WebSocket, _WebSocket2, nip19_exports, NostrTypeGuard, Bech32MaxSize = 5000, BECH32_REGEX, nip04_exports, nip05_exports, NIP05_REGEX, isNip05 = (value) => NIP05_REGEX.test(value || ""), _fetch, nip10_exports, nip11_exports, _fetch2, nip13_exports, nip17_exports, nip59_exports, nip44_exports, minPlaintextSize = 1, maxPlaintextSize = 65535, v2, TWO_DAYS, now = () => Math.round(Date.now() / 1000), randomNow = () => Math.round(now() - Math.random() * TWO_DAYS), nip44ConversationKey = (privateKey, publicKey) => getConversationKey(privateKey, publicKey), nip44Encrypt = (data, privateKey, publicKey) => encrypt22(JSON.stringify(data), nip44ConversationKey(privateKey, publicKey)), nip44Decrypt = (data, privateKey) => JSON.parse(decrypt22(data.content, nip44ConversationKey(privateKey, data.pubkey))), unwrapEvent2, unwrapManyEvents2, nip18_exports, nip21_exports, NOSTR_URI_REGEX, nip25_exports, nip27_exports, noCharacter, noURLCharacter, MAX_HASHTAG_LENGTH = 42, nip28_exports, channelCreateEvent = (t, privateKey) => {
8570
+ }, _WebSocket, _WebSocket2, nip19_exports, NostrTypeGuard, Bech32MaxSize = 5000, BECH32_REGEX, nip04_exports, nip05_exports, NIP05_REGEX, isNip05 = (value) => NIP05_REGEX.test(value || ""), _fetch, nip10_exports, nip11_exports, _fetch2, nip13_exports, nip17_exports, nip59_exports, nip44_exports, minPlaintextSize = 1, maxPlaintextSize = 4294967295, extendedPrefixThreshold = 65536, v2, TWO_DAYS, now = () => Math.round(Date.now() / 1000), randomNow = () => Math.round(now() - Math.random() * TWO_DAYS), nip44ConversationKey = (privateKey, publicKey) => getConversationKey(privateKey, publicKey), nip44Encrypt = (data, privateKey, publicKey) => encrypt22(JSON.stringify(data), nip44ConversationKey(privateKey, publicKey)), nip44Decrypt = (data, privateKey) => JSON.parse(decrypt22(data.content, nip44ConversationKey(privateKey, data.pubkey))), unwrapEvent2, unwrapManyEvents2, nip18_exports, nip21_exports, NOSTR_URI_REGEX, nip22_exports, nip25_exports, nip27_exports, noCharacter, noURLCharacter, MAX_HASHTAG_LENGTH = 42, nip28_exports, channelCreateEvent = (t, privateKey) => {
8424
8571
  let content;
8425
8572
  if (typeof t.content === "object") {
8426
8573
  content = JSON.stringify(t.content);
@@ -9087,12 +9234,10 @@ var init_esm = __esm(() => {
9087
9234
  };
9088
9235
  try {
9089
9236
  _WebSocket = WebSocket;
9090
- } catch {
9091
- }
9237
+ } catch {}
9092
9238
  try {
9093
9239
  _WebSocket2 = WebSocket;
9094
- } catch {
9095
- }
9240
+ } catch {}
9096
9241
  nip19_exports = {};
9097
9242
  __export2(nip19_exports, {
9098
9243
  BECH32_REGEX: () => BECH32_REGEX,
@@ -9135,8 +9280,7 @@ var init_esm = __esm(() => {
9135
9280
  NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/;
9136
9281
  try {
9137
9282
  _fetch = fetch;
9138
- } catch (_) {
9139
- }
9283
+ } catch (_) {}
9140
9284
  nip10_exports = {};
9141
9285
  __export2(nip10_exports, {
9142
9286
  parse: () => parse
@@ -9148,8 +9292,7 @@ var init_esm = __esm(() => {
9148
9292
  });
9149
9293
  try {
9150
9294
  _fetch2 = fetch;
9151
- } catch {
9152
- }
9295
+ } catch {}
9153
9296
  nip13_exports = {};
9154
9297
  __export2(nip13_exports, {
9155
9298
  getPow: () => getPow,
@@ -9182,7 +9325,9 @@ var init_esm = __esm(() => {
9182
9325
  v2 = {
9183
9326
  utils: {
9184
9327
  getConversationKey,
9185
- calcPaddedLen
9328
+ calcPaddedLen,
9329
+ pad,
9330
+ unpad
9186
9331
  },
9187
9332
  encrypt: encrypt22,
9188
9333
  decrypt: decrypt22
@@ -9203,6 +9348,10 @@ var init_esm = __esm(() => {
9203
9348
  test: () => test
9204
9349
  });
9205
9350
  NOSTR_URI_REGEX = new RegExp(`nostr:(${BECH32_REGEX.source})`);
9351
+ nip22_exports = {};
9352
+ __export2(nip22_exports, {
9353
+ parse: () => parse3
9354
+ });
9206
9355
  nip25_exports = {};
9207
9356
  __export2(nip25_exports, {
9208
9357
  finishReactionEvent: () => finishReactionEvent,
@@ -9210,7 +9359,7 @@ var init_esm = __esm(() => {
9210
9359
  });
9211
9360
  nip27_exports = {};
9212
9361
  __export2(nip27_exports, {
9213
- parse: () => parse3
9362
+ parse: () => parse4
9214
9363
  });
9215
9364
  noCharacter = /\W/m;
9216
9365
  noURLCharacter = /[^\w\/] |[^\w\/]$|$|,| /m;
@@ -9237,8 +9386,7 @@ var init_esm = __esm(() => {
9237
9386
  });
9238
9387
  try {
9239
9388
  _fetch3 = fetch;
9240
- } catch {
9241
- }
9389
+ } catch {}
9242
9390
  nip47_exports = {};
9243
9391
  __export2(nip47_exports, {
9244
9392
  makeNwcRequestEvent: () => makeNwcRequestEvent,
@@ -9259,8 +9407,7 @@ var init_esm = __esm(() => {
9259
9407
  });
9260
9408
  try {
9261
9409
  _fetch4 = fetch;
9262
- } catch {
9263
- }
9410
+ } catch {}
9264
9411
  nip77_exports = {};
9265
9412
  __export2(nip77_exports, {
9266
9413
  Negentropy: () => Negentropy,
@@ -11269,8 +11416,8 @@ var require_qrcode = __commonJS((exports) => {
11269
11416
 
11270
11417
  // node_modules/pngjs/lib/chunkstream.js
11271
11418
  var require_chunkstream = __commonJS((exports, module) => {
11272
- var util = import.meta.require("util");
11273
- var Stream = import.meta.require("stream");
11419
+ var util = __require("util");
11420
+ var Stream = __require("stream");
11274
11421
  var ChunkStream = module.exports = function() {
11275
11422
  Stream.call(this);
11276
11423
  this._buffers = [];
@@ -11626,7 +11773,7 @@ var require_filter_parse = __commonJS((exports, module) => {
11626
11773
 
11627
11774
  // node_modules/pngjs/lib/filter-parse-async.js
11628
11775
  var require_filter_parse_async = __commonJS((exports, module) => {
11629
- var util = import.meta.require("util");
11776
+ var util = __require("util");
11630
11777
  var ChunkStream = require_chunkstream();
11631
11778
  var Filter = require_filter_parse();
11632
11779
  var FilterAsync = module.exports = function(bitmapInfo) {
@@ -11740,8 +11887,7 @@ var require_parser = __commonJS((exports, module) => {
11740
11887
  this.inflateData = dependencies.inflateData;
11741
11888
  this.finished = dependencies.finished;
11742
11889
  this.simpleTransparency = dependencies.simpleTransparency;
11743
- this.headersFinished = dependencies.headersFinished || function() {
11744
- };
11890
+ this.headersFinished = dependencies.headersFinished || function() {};
11745
11891
  };
11746
11892
  Parser.prototype.start = function() {
11747
11893
  this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
@@ -11933,8 +12079,7 @@ var require_parser = __commonJS((exports, module) => {
11933
12079
  var require_bitmapper = __commonJS((exports) => {
11934
12080
  var interlaceUtils = require_interlace();
11935
12081
  var pixelBppMapper = [
11936
- function() {
11937
- },
12082
+ function() {},
11938
12083
  function(pxData, data, pxPos, rawPos) {
11939
12084
  if (rawPos === data.length) {
11940
12085
  throw new Error("Ran out of data");
@@ -11975,8 +12120,7 @@ var require_bitmapper = __commonJS((exports) => {
11975
12120
  }
11976
12121
  ];
11977
12122
  var pixelBppCustomMapper = [
11978
- function() {
11979
- },
12123
+ function() {},
11980
12124
  function(pxData, pixelData, pxPos, maxBit) {
11981
12125
  let pixel = pixelData[0];
11982
12126
  pxData[pxPos] = pixel;
@@ -12220,8 +12364,8 @@ var require_format_normaliser = __commonJS((exports, module) => {
12220
12364
 
12221
12365
  // node_modules/pngjs/lib/parser-async.js
12222
12366
  var require_parser_async = __commonJS((exports, module) => {
12223
- var util = import.meta.require("util");
12224
- var zlib = import.meta.require("zlib");
12367
+ var util = __require("util");
12368
+ var zlib = __require("zlib");
12225
12369
  var ChunkStream = require_chunkstream();
12226
12370
  var FilterAsync = require_filter_parse_async();
12227
12371
  var Parser = require_parser();
@@ -12255,8 +12399,7 @@ var require_parser_async = __commonJS((exports, module) => {
12255
12399
  }
12256
12400
  if (this._filter) {
12257
12401
  this._filter.destroy();
12258
- this._filter.on("error", function() {
12259
- });
12402
+ this._filter.on("error", function() {});
12260
12403
  }
12261
12404
  this.errord = true;
12262
12405
  };
@@ -12615,7 +12758,7 @@ var require_packer = __commonJS((exports, module) => {
12615
12758
  var CrcStream = require_crc();
12616
12759
  var bitPacker = require_bitpacker();
12617
12760
  var filter = require_filter_pack();
12618
- var zlib = import.meta.require("zlib");
12761
+ var zlib = __require("zlib");
12619
12762
  var Packer = module.exports = function(options) {
12620
12763
  this._options = options;
12621
12764
  options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
@@ -12699,8 +12842,8 @@ var require_packer = __commonJS((exports, module) => {
12699
12842
 
12700
12843
  // node_modules/pngjs/lib/packer-async.js
12701
12844
  var require_packer_async = __commonJS((exports, module) => {
12702
- var util = import.meta.require("util");
12703
- var Stream = import.meta.require("stream");
12845
+ var util = __require("util");
12846
+ var Stream = __require("stream");
12704
12847
  var constants = require_constants();
12705
12848
  var Packer = require_packer();
12706
12849
  var PackerAsync = module.exports = function(opt) {
@@ -12732,10 +12875,10 @@ var require_packer_async = __commonJS((exports, module) => {
12732
12875
 
12733
12876
  // node_modules/pngjs/lib/sync-inflate.js
12734
12877
  var require_sync_inflate = __commonJS((exports, module) => {
12735
- var assert = import.meta.require("assert").ok;
12736
- var zlib = import.meta.require("zlib");
12737
- var util = import.meta.require("util");
12738
- var kMaxLength = import.meta.require("buffer").kMaxLength;
12878
+ var assert = __require("assert").ok;
12879
+ var zlib = __require("zlib");
12880
+ var util = __require("util");
12881
+ var kMaxLength = __require("buffer").kMaxLength;
12739
12882
  function Inflate(opts) {
12740
12883
  if (!(this instanceof Inflate)) {
12741
12884
  return new Inflate(opts);
@@ -12895,8 +13038,7 @@ var require_filter_parse_sync = __commonJS((exports) => {
12895
13038
  write: function(bufferPart) {
12896
13039
  outBuffers.push(bufferPart);
12897
13040
  },
12898
- complete: function() {
12899
- }
13041
+ complete: function() {}
12900
13042
  });
12901
13043
  filter.start();
12902
13044
  reader.process();
@@ -12907,7 +13049,7 @@ var require_filter_parse_sync = __commonJS((exports) => {
12907
13049
  // node_modules/pngjs/lib/parser-sync.js
12908
13050
  var require_parser_sync = __commonJS((exports, module) => {
12909
13051
  var hasSyncZlib = true;
12910
- var zlib = import.meta.require("zlib");
13052
+ var zlib = __require("zlib");
12911
13053
  var inflateSync = require_sync_inflate();
12912
13054
  if (!zlib.deflateSync) {
12913
13055
  hasSyncZlib = false;
@@ -12993,7 +13135,7 @@ var require_parser_sync = __commonJS((exports, module) => {
12993
13135
  // node_modules/pngjs/lib/packer-sync.js
12994
13136
  var require_packer_sync = __commonJS((exports, module) => {
12995
13137
  var hasSyncZlib = true;
12996
- var zlib = import.meta.require("zlib");
13138
+ var zlib = __require("zlib");
12997
13139
  if (!zlib.deflateSync) {
12998
13140
  hasSyncZlib = false;
12999
13141
  }
@@ -13025,10 +13167,10 @@ var require_packer_sync = __commonJS((exports, module) => {
13025
13167
 
13026
13168
  // node_modules/pngjs/lib/png-sync.js
13027
13169
  var require_png_sync = __commonJS((exports) => {
13028
- var parse4 = require_parser_sync();
13170
+ var parse5 = require_parser_sync();
13029
13171
  var pack = require_packer_sync();
13030
13172
  exports.read = function(buffer, options) {
13031
- return parse4(buffer, options || {});
13173
+ return parse5(buffer, options || {});
13032
13174
  };
13033
13175
  exports.write = function(png, options) {
13034
13176
  return pack(png, options);
@@ -13037,8 +13179,8 @@ var require_png_sync = __commonJS((exports) => {
13037
13179
 
13038
13180
  // node_modules/pngjs/lib/png.js
13039
13181
  var require_png = __commonJS((exports) => {
13040
- var util = import.meta.require("util");
13041
- var Stream = import.meta.require("stream");
13182
+ var util = __require("util");
13183
+ var Stream = __require("stream");
13042
13184
  var Parser = require_parser_async();
13043
13185
  var Packer = require_packer_async();
13044
13186
  var PNGSync = require_png_sync();
@@ -13242,7 +13384,7 @@ var require_utils2 = __commonJS((exports) => {
13242
13384
 
13243
13385
  // node_modules/qrcode/lib/renderer/png.js
13244
13386
  var require_png2 = __commonJS((exports) => {
13245
- var fs = import.meta.require("fs");
13387
+ var fs = __require("fs");
13246
13388
  var PNG = require_png().PNG;
13247
13389
  var Utils = require_utils2();
13248
13390
  exports.render = function render(qrData, options) {
@@ -13366,7 +13508,7 @@ var require_utf8 = __commonJS((exports) => {
13366
13508
  cb = options;
13367
13509
  options = undefined;
13368
13510
  }
13369
- const fs = import.meta.require("fs");
13511
+ const fs = __require("fs");
13370
13512
  const utf8 = exports.render(qrData, options);
13371
13513
  fs.writeFile(path, utf8, cb);
13372
13514
  };
@@ -13540,7 +13682,7 @@ var require_svg = __commonJS((exports) => {
13540
13682
  cb = options;
13541
13683
  options = undefined;
13542
13684
  }
13543
- const fs = import.meta.require("fs");
13685
+ const fs = __require("fs");
13544
13686
  const svgTag = exports.render(qrData, options);
13545
13687
  const xmlStr = '<?xml version="1.0" encoding="utf-8"?>' + '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + svgTag;
13546
13688
  fs.writeFile(path, xmlStr, cb);
@@ -14157,8 +14299,7 @@ function renderBox(lines, width, title) {
14157
14299
  function startBarSection(sectionKey, maxLabelLen) {
14158
14300
  _sectionMaxLabelLen.set(sectionKey, maxLabelLen);
14159
14301
  }
14160
- function endBarSection(_sectionKey) {
14161
- }
14302
+ function endBarSection(_sectionKey) {}
14162
14303
  function renderBarChart(label, value, maxValue, width, color, percentageValue, sectionKey) {
14163
14304
  const safeMaxValue = Math.max(maxValue, 1);
14164
14305
  const pct = percentageValue !== undefined ? percentageValue.toFixed(1) : (value / safeMaxValue * 100).toFixed(1);
@@ -15629,7 +15770,7 @@ async function isCocodInstalled(cocodPath) {
15629
15770
  // package.json
15630
15771
  var package_default = {
15631
15772
  name: "routstrd",
15632
- version: "0.2.22",
15773
+ version: "0.3.0",
15633
15774
  module: "src/index.ts",
15634
15775
  type: "module",
15635
15776
  private: false,
@@ -15656,6 +15797,7 @@ var package_default = {
15656
15797
  "@routstr/sdk": "^0.3.8",
15657
15798
  "applesauce-core": "^5.1.0",
15658
15799
  "applesauce-relay": "^5.1.0",
15800
+ "applesauce-wallet-connect": "^6.0.0",
15659
15801
  commander: "^14.0.2",
15660
15802
  "nostr-tools": "^2.12.0",
15661
15803
  qrcode: "^1.5.4",
@@ -15781,7 +15923,7 @@ Initialization complete!`);
15781
15923
  To ensure routstrd persists across system restarts, run: 'routstrd service install'`);
15782
15924
  }
15783
15925
  program.name("routstrd").description("Routstr daemon - Manage routstr processes").version(package_default.version, "--version", "output the version number");
15784
- program.command("refund").description("Refund pending tokens and API keys to a specified mint").option("-m, --mint-url <mintUrl>", "Mint URL to refund to (defaults to first mint in wallet)").option("-y, --yes", "Skip confirmation prompt", false).action(async (options) => {
15926
+ program.command("refund").description("Refund pending tokens and API keys to a specified mint").option("-m, --mint-url <mintUrl>", "Mint URL to refund to (defaults to first mint in wallet)").option("-y, --yes", "Skip confirmation prompt", false).option("--xcashu", "Refund xcashu tokens only (uses refundXcashuTokens)", false).action(async (options) => {
15785
15927
  await ensureDaemonRunning();
15786
15928
  let mintUrl = options.mintUrl;
15787
15929
  if (!mintUrl) {
@@ -15799,6 +15941,27 @@ program.command("refund").description("Refund pending tokens and API keys to a s
15799
15941
  console.log(`Using mint URL: ${mintUrl}`);
15800
15942
  }
15801
15943
  try {
15944
+ if (options.xcashu) {
15945
+ const result2 = await callDaemon("/refund/xcashu", {
15946
+ method: "POST",
15947
+ body: { mintUrl }
15948
+ });
15949
+ if (result2.error) {
15950
+ console.log(result2.error);
15951
+ process.exit(1);
15952
+ }
15953
+ const output2 = result2.output;
15954
+ if (output2) {
15955
+ console.log(output2.message);
15956
+ console.log(`
15957
+ Results:`);
15958
+ for (const r of output2.results) {
15959
+ const status = r.success ? "success" : `failed: ${r.error || "unknown"}`;
15960
+ console.log(` - ${r.baseUrl}: ${status}`);
15961
+ }
15962
+ }
15963
+ return;
15964
+ }
15802
15965
  const result = await callDaemon("/refund", {
15803
15966
  method: "POST",
15804
15967
  body: { mintUrl }
@@ -16407,6 +16570,65 @@ walletMintsCmd.command("info <url>").description("Get wallet mint info").action(
16407
16570
  body: { url }
16408
16571
  });
16409
16572
  });
16573
+ var nwcCmd = program.command("nwc").description("Manage NWC (Nostr Wallet Connect) integration");
16574
+ nwcCmd.command("connect").description("Connect to a Lightning wallet via NWC").argument("[connection-string]", "NWC connection string (nostr+walletconnect://...)").action(async (connectionString) => {
16575
+ if (!connectionString) {
16576
+ const rl = __require("readline").createInterface({
16577
+ input: process.stdin,
16578
+ output: process.stdout
16579
+ });
16580
+ connectionString = await new Promise((resolve) => {
16581
+ rl.question("Paste your NWC connection string: ", (answer) => {
16582
+ rl.close();
16583
+ resolve(answer.trim());
16584
+ });
16585
+ });
16586
+ }
16587
+ if (!/^nostr\+walletconnect:\/\/[0-9a-fA-F]{64}\?relay=/.test(connectionString)) {
16588
+ console.error("Invalid NWC connection string: expected nostr+walletconnect://<64-char-hex>?relay=...");
16589
+ process.exit(1);
16590
+ }
16591
+ await handleDaemonCommand("/nwc/connect", {
16592
+ method: "POST",
16593
+ body: { connectionString }
16594
+ });
16595
+ });
16596
+ nwcCmd.command("disconnect").description("Disconnect from NWC wallet").action(async () => {
16597
+ await handleDaemonCommand("/nwc/disconnect", {
16598
+ method: "POST"
16599
+ });
16600
+ });
16601
+ nwcCmd.command("status").description("Show NWC connection status and wallet info").action(async () => {
16602
+ await handleDaemonCommand("/nwc/status");
16603
+ });
16604
+ nwcCmd.command("fund <amount>").description("Manually fund the Cashu wallet from the connected NWC wallet").action(async (amount) => {
16605
+ const parsedAmount = parsePositiveIntOrExit(amount, "amount");
16606
+ await handleDaemonCommand("/nwc/fund", {
16607
+ method: "POST",
16608
+ body: { amount: parsedAmount }
16609
+ });
16610
+ });
16611
+ var autoRefillCmd = nwcCmd.command("auto-refill").description("Manage automatic wallet refill from NWC");
16612
+ autoRefillCmd.command("on").description("Enable auto-refill").option("--threshold <sats>", "Refill when Cashu balance drops below this many sats", "500").option("--amount <sats>", "Refill this many sats at a time", "1000").option("--cooldown <seconds>", "Minimum time between refills in seconds", "300").action(async (options) => {
16613
+ const threshold = parsePositiveIntOrExit(options.threshold, "threshold");
16614
+ const amount = parsePositiveIntOrExit(options.amount, "amount");
16615
+ const cooldownSec = parsePositiveIntOrExit(options.cooldown, "cooldown");
16616
+ await handleDaemonCommand("/nwc/auto-refill", {
16617
+ method: "POST",
16618
+ body: {
16619
+ enabled: true,
16620
+ threshold,
16621
+ amount,
16622
+ cooldownMs: cooldownSec * 1000
16623
+ }
16624
+ });
16625
+ });
16626
+ autoRefillCmd.command("off").description("Disable auto-refill").action(async () => {
16627
+ await handleDaemonCommand("/nwc/auto-refill", {
16628
+ method: "POST",
16629
+ body: { enabled: false }
16630
+ });
16631
+ });
16410
16632
  program.command("stop").description("Stop the background daemon").action(async () => {
16411
16633
  await handleDaemonCommand("/stop", { method: "POST" });
16412
16634
  });
@@ -16428,7 +16650,7 @@ serviceCmd.command("install").description("Install and start routstrd using PM2
16428
16650
  try {
16429
16651
  daemonPath = Bun.resolveSync("./daemon/index.js", import.meta.url);
16430
16652
  } catch (e) {
16431
- const path = import.meta.require("path");
16653
+ const path = __require("path");
16432
16654
  daemonPath = path.join(path.dirname(import.meta.url).replace("file://", ""), "daemon", "index.js");
16433
16655
  }
16434
16656
  if (!existsSync9(daemonPath)) {
@@ -16465,8 +16687,7 @@ serviceCmd.command("uninstall").description("Stop and remove routstrd from PM2")
16465
16687
  serviceCmd.command("logs").description("View PM2 logs for routstrd").action(() => {
16466
16688
  try {
16467
16689
  execSync("pm2 logs routstrd", { stdio: "inherit" });
16468
- } catch (e) {
16469
- }
16690
+ } catch (e) {}
16470
16691
  });
16471
16692
  program.command("restart").description("Restart the background daemon").option("--port <port>", "Port to listen on").option("-p, --provider <provider>", "Default provider to use").action(async (options) => {
16472
16693
  await requireLocalDaemon();
@@ -16507,7 +16728,7 @@ program.command("mode").description("Set the client mode (lazyrefund/apikeys or
16507
16728
  Current mode: ${currentMode}`);
16508
16729
  const modes = ["apikeys", "xcashu"];
16509
16730
  const selectedIndex = await new Promise((resolve) => {
16510
- const rl = import.meta.require("readline").createInterface({
16731
+ const rl = __require("readline").createInterface({
16511
16732
  input: process.stdin,
16512
16733
  output: process.stdout
16513
16734
  });