@ghostlytools/cli 1.9.0 → 1.10.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.
Files changed (107) hide show
  1. package/README.md +28 -20
  2. package/SKILL.md +5 -1
  3. package/dist/assets/{api-DFCgr6RH.js → api-BF_KwecF.js} +84 -38
  4. package/dist/assets/api-BF_KwecF.js.map +1 -0
  5. package/dist/assets/{api-raWw9j_m.js → api-DdrA86Ur.js} +2 -2
  6. package/dist/assets/{apiKit-CCavJJcl.js → apiKit-Du1u2l4x.js} +8 -8
  7. package/dist/assets/apiKit-Du1u2l4x.js.map +1 -0
  8. package/dist/assets/{apps-B7o2BPj6.js → apps-Bti9fDoW.js} +1 -1
  9. package/dist/assets/{apps-DmxEG147.js → apps-DwPfp54I.js} +5 -3
  10. package/dist/assets/apps-DwPfp54I.js.map +1 -0
  11. package/dist/assets/{arkade-DtYR9H0c.js → arkade-DOWpA2Kr.js} +2 -2
  12. package/dist/assets/{arkade-DtYR9H0c.js.map → arkade-DOWpA2Kr.js.map} +1 -1
  13. package/dist/assets/{backup-BserdrNk.js → backup-CeRckyl2.js} +1 -1
  14. package/dist/assets/{backup-YIB2XIES.js → backup-DZ_Q1eSu.js} +6 -6
  15. package/dist/assets/{backup-YIB2XIES.js.map → backup-DZ_Q1eSu.js.map} +1 -1
  16. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  17. package/dist/assets/{blobFiles-DOQDRdDI.js → blobFiles-BnjN_Vrz.js} +3 -3
  18. package/dist/assets/{blobFiles-DOQDRdDI.js.map → blobFiles-BnjN_Vrz.js.map} +1 -1
  19. package/dist/assets/buttons-BxIThdg9.js +332 -0
  20. package/dist/assets/buttons-BxIThdg9.js.map +1 -0
  21. package/dist/assets/buttons-D9QBHS9Y.js +2 -0
  22. package/dist/assets/client-D5E1RQYB.js +473 -0
  23. package/dist/assets/client-D5E1RQYB.js.map +1 -0
  24. package/dist/assets/{endpoint-BdaeBw2L.js → endpoint-DWHkXWVM.js} +101 -16
  25. package/dist/assets/endpoint-DWHkXWVM.js.map +1 -0
  26. package/dist/assets/{envelope-Dt75vrmY.js → envelope-CugS9qwQ.js} +2 -2
  27. package/dist/assets/{envelope-Dt75vrmY.js.map → envelope-CugS9qwQ.js.map} +1 -1
  28. package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -1
  29. package/dist/assets/{fileBytes-BPDKufla.js → fileBytes-DMzrIdCu.js} +1 -1
  30. package/dist/assets/{fileBytes-DNgrRL0R.js → fileBytes-DjBYYyXT.js} +3 -3
  31. package/dist/assets/{fileBytes-DNgrRL0R.js.map → fileBytes-DjBYYyXT.js.map} +1 -1
  32. package/dist/assets/{fileBytes-Q3ehcEr8.js → fileBytes-Douk1yOp.js} +2 -2
  33. package/dist/assets/{fileBytes-Q3ehcEr8.js.map → fileBytes-Douk1yOp.js.map} +1 -1
  34. package/dist/assets/fileBytesIdb-CD5Uv490.js +2 -0
  35. package/dist/assets/{fileBytesIdb-Dm1EyEbT.js → fileBytesIdb-CkClu9YI.js} +3 -3
  36. package/dist/assets/{fileBytesIdb-Dm1EyEbT.js.map → fileBytesIdb-CkClu9YI.js.map} +1 -1
  37. package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js → fileBytesOpfs-WryQuOgK.js} +3 -3
  38. package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js.map → fileBytesOpfs-WryQuOgK.js.map} +1 -1
  39. package/dist/assets/{fixedHosts-B598JzbC.js → fixedHosts-B4E4VrYE.js} +4 -4
  40. package/dist/assets/{fixedHosts-B598JzbC.js.map → fixedHosts-B4E4VrYE.js.map} +1 -1
  41. package/dist/assets/{groupFiles-FXel6zIc.js → groupFiles-NonOYBKN.js} +378 -59
  42. package/dist/assets/groupFiles-NonOYBKN.js.map +1 -0
  43. package/dist/assets/{host-DIBeK_c_.js → host-DvcVt5YI.js} +79 -23
  44. package/dist/assets/{host-DIBeK_c_.js.map → host-DvcVt5YI.js.map} +1 -1
  45. package/dist/assets/{hyperdhtRelay-D185dETu.js → hyperdhtRelay-Ce42sR8x.js} +2 -2
  46. package/dist/assets/{hyperdhtRelay-D185dETu.js.map → hyperdhtRelay-Ce42sR8x.js.map} +1 -1
  47. package/dist/assets/{idb-BkOJES5_.js → idb-BHsAqENE.js} +37 -6
  48. package/dist/assets/idb-BHsAqENE.js.map +1 -0
  49. package/dist/assets/{irohWeb-BSv_BWyG.js → irohWeb-C9ChbD-c.js} +57 -3
  50. package/dist/assets/{irohWeb-BSv_BWyG.js.map → irohWeb-C9ChbD-c.js.map} +1 -1
  51. package/dist/assets/{main-BbhfMTt8.js → main-4qE381KM.js} +194 -276
  52. package/dist/assets/main-4qE381KM.js.map +1 -0
  53. package/dist/assets/{mainline-9Vc3c3SA.js → mainline-DOwZDHVy.js} +2 -2
  54. package/dist/assets/{mainline-9Vc3c3SA.js.map → mainline-DOwZDHVy.js.map} +1 -1
  55. package/dist/assets/{networkReason-BncJ9KSM.js → networkReason-MInk1Y63.js} +3 -3
  56. package/dist/assets/{networkReason-BncJ9KSM.js.map → networkReason-MInk1Y63.js.map} +1 -1
  57. package/dist/assets/{nwc-QX3Yt1Sb.js → nwc-CHLWFV1R.js} +3 -3
  58. package/dist/assets/{nwc-QX3Yt1Sb.js.map → nwc-CHLWFV1R.js.map} +1 -1
  59. package/dist/assets/{nwcProvider-CzX3xH47.js → nwcProvider-BlkPOJen.js} +2 -2
  60. package/dist/assets/{nwcProvider-CzX3xH47.js.map → nwcProvider-BlkPOJen.js.map} +1 -1
  61. package/dist/assets/{ownDid-D8z5gwGI.js → ownDid-yXtY_1B5.js} +3 -3
  62. package/dist/assets/ownDid-yXtY_1B5.js.map +1 -0
  63. package/dist/assets/{profiles-MFtCmJwK.js → profiles-vbXHs0Mq.js} +40 -3
  64. package/dist/assets/profiles-vbXHs0Mq.js.map +1 -0
  65. package/dist/assets/{registry-PTtBMaYZ.js → registry-BN9r2pR4.js} +1 -1
  66. package/dist/assets/{registry-B2Dtnibo.js → registry-chCD0KWS.js} +5 -5
  67. package/dist/assets/registry-chCD0KWS.js.map +1 -0
  68. package/dist/assets/{resolve-ZxVzwFNA.js → resolve-Dtzogt2W.js} +2 -2
  69. package/dist/assets/{resolve-ZxVzwFNA.js.map → resolve-Dtzogt2W.js.map} +1 -1
  70. package/dist/assets/{restoredRows-BCRCjhdF.js → restoredRows-CRYwIx3g.js} +2 -2
  71. package/dist/assets/{restoredRows-BCRCjhdF.js.map → restoredRows-CRYwIx3g.js.map} +1 -1
  72. package/dist/assets/{buttons-CuRfKnPI.js → secretGuard-CSVNxXVW.js} +80 -330
  73. package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
  74. package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
  75. package/dist/assets/{server-Dw1o8z1o.js → server-BZnsm5X5.js} +1749 -335
  76. package/dist/assets/server-BZnsm5X5.js.map +1 -0
  77. package/dist/assets/{src-BD8RBVEp.js → src-DZagapGt.js} +1043 -197
  78. package/dist/assets/src-DZagapGt.js.map +1 -0
  79. package/dist/assets/{sshForges-DWrESWkK.js → sshForges-BkTgy5rx.js} +16 -9
  80. package/dist/assets/{sshForges-DWrESWkK.js.map → sshForges-BkTgy5rx.js.map} +1 -1
  81. package/dist/assets/{translate-D1uP0q32.js → translate-B9SMd6uf.js} +8 -7
  82. package/dist/assets/translate-B9SMd6uf.js.map +1 -0
  83. package/dist/assets/{usdt-DhVN8geQ.js → usdt-BU4ezonh.js} +3 -3
  84. package/dist/assets/{usdt-DhVN8geQ.js.map → usdt-BU4ezonh.js.map} +1 -1
  85. package/dist/assets/{words-DdXPkB3n.js → words-jYy7lTcb.js} +4 -2
  86. package/dist/assets/words-jYy7lTcb.js.map +1 -0
  87. package/dist/ghostly.mjs +1 -1
  88. package/package.json +1 -1
  89. package/dist/assets/api-DFCgr6RH.js.map +0 -1
  90. package/dist/assets/apiKit-CCavJJcl.js.map +0 -1
  91. package/dist/assets/apps-DmxEG147.js.map +0 -1
  92. package/dist/assets/buttons-CuRfKnPI.js.map +0 -1
  93. package/dist/assets/buttons-De3LPdSG.js +0 -2
  94. package/dist/assets/daemonProof-DtrL5lE5.js +0 -236
  95. package/dist/assets/daemonProof-DtrL5lE5.js.map +0 -1
  96. package/dist/assets/endpoint-BdaeBw2L.js.map +0 -1
  97. package/dist/assets/fileBytesIdb-DZcESfTt.js +0 -2
  98. package/dist/assets/groupFiles-FXel6zIc.js.map +0 -1
  99. package/dist/assets/idb-BkOJES5_.js.map +0 -1
  100. package/dist/assets/main-BbhfMTt8.js.map +0 -1
  101. package/dist/assets/ownDid-D8z5gwGI.js.map +0 -1
  102. package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
  103. package/dist/assets/registry-B2Dtnibo.js.map +0 -1
  104. package/dist/assets/server-Dw1o8z1o.js.map +0 -1
  105. package/dist/assets/src-BD8RBVEp.js.map +0 -1
  106. package/dist/assets/translate-D1uP0q32.js.map +0 -1
  107. package/dist/assets/words-DdXPkB3n.js.map +0 -1
@@ -1,7 +1,4 @@
1
- import { Lu as randomBytes, Ru as toBase64Url, co as STATUS_CARD_LIMITS, fo as buttonLabelClash, hi as BUTTONS_CAPABILITY, ho as checkStatusCard, to as BUTTON_STYLES } from "./src-BD8RBVEp.js";
2
1
  import { t as CliError } from "./errors-R4S2SAEM.js";
3
- import { _ as oneOf, b as str, g as num, h as node, i as chatOrGroup, n as bool, p as messageOf } from "./apiKit-CCavJJcl.js";
4
- import { t as goesOn$1 } from "./waitNotice-B8D8WhbE.js";
5
2
  import { sha256 } from "@noble/hashes/sha2.js";
6
3
  import { createBase58check } from "@scure/base";
7
4
  import { wordlist } from "@scure/bip39/wordlists/english.js";
@@ -749,9 +746,19 @@ var HEX_SECRET = /\b(?:0x)?(?:[0-9a-fA-F]{128}|[0-9a-fA-F]{64})\b/g;
749
746
  * Monero's keys count too: "Private spend key" and "Spend key (private)" (Cake Wallet, MyMonero). A bare "spend key" or
750
747
  * "view key" does not, as a wallet's public keys are written that way too.
751
748
  */
752
- var SECRET_CONTEXT = /priv(?:ate)?[\s_-]*(?:(?:spend|view)[\s_-]*)?key|(?:spend|view)[\s_-]*key[\s_-]*\(\s*private|secret|seed|mnemonic|nsec|xprv|\bwif\b|recovery|passphrase/i;
749
+ var SECRET_CONTEXT = /priv(?:ate)?[\s_-]*(?:(?:spend|view)[\s_-]*)?key|(?:spend|view)[\s_-]*key[\s_-]*\(\s*private|secret|seed|mnemonic|nsec|xprv|\bwif\b|recovery|passphrase|password/i;
750
+ /** A bitcoind login: its cookie file (`__cookie__:<hex>`), `rpcpassword=`, or the bitcoind source's own words. */
751
+ var NODE_CONTEXT = /__cookie__|rpc[\s_-]*pass(?:word)?|\bcookie\b/i;
753
752
  /** How far from a 64-hex string a word like "seed" still counts as saying what it is. */
754
753
  var CONTEXT_REACH = 48;
754
+ /** A macaroon (version 2) with a location, as LND writes it: `02 01 <length> lnd …`, in hex or base64. */
755
+ var MACAROON_HEX = /\b0201[0-9a-fA-F]{96,}\b/g;
756
+ var MACAROON_BASE64 = /(?<![\w+/-])AgE[\w+/-]{60,}={0,2}/g;
757
+ /** A Core Lightning rune: base64url of a 32-byte authcode and the restrictions. */
758
+ var RUNE = /(?<![\w-])[\w-]{43,}={0,2}(?![\w=-])/g;
759
+ /** The restrictions of a rune that `createrune` made: its unique id first (`=0`, `=3&method=…`). */
760
+ var RUNE_RESTRICTIONS = /^=\d+(?:[&|][ -~]*)?$/;
761
+ var RUNE_WORD = /\brunes?\b/i;
755
762
  var CASHU_TOKEN = /\bcashu([AB])([A-Za-z0-9_\-+/]{20,}={0,2})/g;
756
763
  /**
757
764
  * Characters that take no room on screen: format characters (zero-width space, soft hyphen, word joiner, the joiners,
@@ -776,6 +783,7 @@ function findSecret(text) {
776
783
  })) return { kind: "mnemonic" };
777
784
  if (readings.some((reading) => NSEC.test(reading))) return { kind: "nsec" };
778
785
  if (readings.some((reading) => EXTENDED_PRIVATE.test(reading) || hasWif(reading))) return { kind: "bitcoin-key" };
786
+ if (readings.some(hasNodeLogin)) return { kind: "node-login" };
779
787
  if (readings.some(hasHexSecret)) return { kind: "hex-key" };
780
788
  const tokens = readings.map(findCashu);
781
789
  return tokens.find((found) => found?.kind === "cashu" && found.amount !== null) ?? tokens.find((found) => found) ?? null;
@@ -866,15 +874,64 @@ function hasWif(text) {
866
874
  } catch {}
867
875
  return false;
868
876
  }
877
+ /** Whether `context` is said within reach of `match`, before or after it. */
878
+ function beside(text, match, context) {
879
+ const before = text.slice(Math.max(0, match.index - CONTEXT_REACH), match.index);
880
+ const after = text.slice(match.index + match[0].length, match.index + match[0].length + CONTEXT_REACH);
881
+ return context.test(before) || context.test(after);
882
+ }
869
883
  /** 64 or 128 hex digits with "private key", "secret", "seed" or the like close by. A bare hash is not asked about. */
870
884
  function hasHexSecret(text) {
871
- for (const match of text.matchAll(HEX_SECRET)) {
872
- const before = text.slice(Math.max(0, match.index - CONTEXT_REACH), match.index);
873
- const after = text.slice(match.index + match[0].length, match.index + match[0].length + CONTEXT_REACH);
874
- if (SECRET_CONTEXT.test(before) || SECRET_CONTEXT.test(after)) return true;
875
- }
885
+ return hexBeside(text, SECRET_CONTEXT);
886
+ }
887
+ function hexBeside(text, context) {
888
+ for (const match of text.matchAll(HEX_SECRET)) if (beside(text, match, context)) return true;
889
+ return false;
890
+ }
891
+ /** A login to a node: a macaroon, a rune, or 64 hex digits that bitcoind's cookie or `rpcpassword` names. */
892
+ function hasNodeLogin(text) {
893
+ if (hexBeside(text, NODE_CONTEXT)) return true;
894
+ for (const [hex] of text.matchAll(MACAROON_HEX)) if (hex.length % 2 === 0 && isMacaroon(Uint8Array.from(hex.match(/../g), (b) => parseInt(b, 16)))) return true;
895
+ for (const [text64] of text.matchAll(MACAROON_BASE64)) if (isMacaroon(tryBase64(text64))) return true;
896
+ for (const match of text.matchAll(RUNE)) if (isRune(text, match)) return true;
876
897
  return false;
877
898
  }
899
+ var printable = (bytes) => bytes.every((b) => b >= 32 && b <= 126);
900
+ /** Bytes as a string of one character each, however many there are. */
901
+ var binary = (bytes) => Array.from(bytes, (b) => String.fromCharCode(b)).join("");
902
+ function tryBase64(text) {
903
+ try {
904
+ return fromBase64(text);
905
+ } catch {
906
+ return null;
907
+ }
908
+ }
909
+ /** Whether `text` is exactly how `bytes` are written in padded base64url: nothing left over in its last letter. */
910
+ function canonicalBase64url(text, bytes) {
911
+ return btoa(binary(bytes)).replace(/\+/g, "-").replace(/\//g, "_") === text;
912
+ }
913
+ /** Version 2 with a location (LND's "lnd"), the identifier next, and the 32-byte signature last. */
914
+ function isMacaroon(bytes) {
915
+ if (!bytes || bytes[0] !== 2 || bytes[1] !== 1) return false;
916
+ const length = bytes[2];
917
+ return length > 0 && length < 128 && printable(bytes.subarray(3, 3 + length)) && bytes[3 + length] === 2 && bytes.length >= 3 + length + 36 && bytes[bytes.length - 34] === 6 && bytes[bytes.length - 33] === 32;
918
+ }
919
+ /**
920
+ * A rune decodes to a hash, which is never text, and then its restrictions, which always are: the unique id first
921
+ * when `createrune` made it, padded as it prints it. One with no restriction (or an older one with no id, or with its
922
+ * padding taken off) counts only beside the word "rune".
923
+ * Hex is read as a hash or a key above, never as a rune.
924
+ */
925
+ function isRune(text, match) {
926
+ if (/^[0-9a-fA-F]+=*$/.test(match[0])) return false;
927
+ const bytes = tryBase64(match[0]);
928
+ if (!bytes || bytes.length < 32 || printable(bytes.subarray(0, 32))) return false;
929
+ const tail = bytes.subarray(32);
930
+ if (!printable(tail)) return false;
931
+ const restrictions = binary(tail);
932
+ if (canonicalBase64url(match[0], bytes) && RUNE_RESTRICTIONS.test(restrictions)) return true;
933
+ return (!restrictions || /^\w*[!=/^$~<>{}#]/.test(restrictions)) && beside(text, match, RUNE_WORD);
934
+ }
878
935
  /** Every Cashu token in the text, with their amounts added up when all of them decode and share one unit. */
879
936
  function findCashu(text) {
880
937
  const tokens = [...text.matchAll(CASHU_TOKEN)].map(([, version, body]) => decodeCashu(version, body));
@@ -1002,330 +1059,23 @@ addSeedLists([
1002
1059
  [MONERO_CHINESE_SIMPLIFIED, 1]
1003
1060
  ]);
1004
1061
  //#endregion
1005
- //#region src/waits.ts
1006
- var DELIVERY_RANK = {
1007
- sending: 0,
1008
- waiting: 1,
1009
- queued: 1,
1010
- held: 2,
1011
- sent: 2,
1012
- delivered: 3
1013
- };
1014
- /**
1015
- * What a timed-out wait says of what happens next: a daemon goes on, a one-shot's profile closes now. A one-shot's
1016
- * `edit` and `group edit` said "while this profile is online" too, as it was about to leave. Ctrl-C says the same.
1017
- */
1018
- var goesOn = (ctx) => goesOn$1(ctx.mode);
1019
- /** Waits until the contact confirmed the latest edit of one of my messages (it is no longer pending). */
1020
- async function waitForEdit(ctx, chat, messageId, ms) {
1021
- const until = Date.now() + ms;
1022
- for (;;) {
1023
- const message = await node(ctx).getMessage(chat, messageId);
1024
- if (!message) throw new CliError("not_found", `No message ${messageId} in this chat`);
1025
- if (!message.edit?.pending) return message;
1026
- if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact has not confirmed the edit yet (it needs a live chat and a contact's app that shows edits). It ${goesOn(ctx)}`, {
1027
- messageId,
1028
- edits: message.edit.seq
1029
- });
1030
- await new Promise((resolve) => setTimeout(resolve, 250));
1031
- }
1032
- }
1033
- /** Waits until the contact confirmed my removal of a message, which is already gone here. */
1034
- async function waitForRemoval(ctx, chat, messageId, ms) {
1035
- const until = Date.now() + ms;
1036
- while (node(ctx).removalPending({
1037
- linkId: chat,
1038
- messageId
1039
- })) {
1040
- if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the message is gone here and the contact has not confirmed yet. Its removal ${goesOn(ctx)}`, { messageId });
1041
- await new Promise((resolve) => setTimeout(resolve, 250));
1042
- }
1062
+ //#region src/secretGuard.ts
1063
+ /** What a refusal says the text looks like. */
1064
+ function secretWords(secret) {
1065
+ if (secret.kind === "cashu") return "a Cashu token (money anyone who reads it can take)";
1066
+ return secret.kind === "node-login" ? "a secret (a login to a node: a macaroon, a rune, an RPC password or cookie)" : "a secret (a seed or a private key)";
1043
1067
  }
1044
1068
  /**
1045
- * Waits until an edge took my group message, or its edit number `edit` (WISP 902: a group has no receipts, so this is
1046
- * as far as the author sees): a member's edge in a private group, an edge to one of my hubs in a community.
1069
+ * The guard `send` has (docs/CLI.md § Safety), for any other text a command sends off the device (a group's name, the
1070
+ * name contacts see, a file's name, a revocation's reason): one that looks like a seed, a private key, a login to a node
1071
+ * or a Cashu token goes only with `--force`. `what` names the text ("group's name"), `verb` what `--force` does ("rename it").
1047
1072
  */
1048
- async function waitForGroupFrame(ctx, groupId, messageId, edit, ms) {
1049
- const until = Date.now() + ms;
1050
- for (;;) {
1051
- const taken = node(ctx).groupTaken({
1052
- groupId,
1053
- messageId,
1054
- ...edit ? { edit } : {}
1055
- });
1056
- if (taken > 0) return taken;
1057
- if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: no member's edge took it yet (it stays in the group and goes when one opens). It ${goesOn(ctx)}`, {
1058
- messageId,
1059
- ...edit ? { edits: edit } : {}
1060
- });
1061
- await new Promise((resolve) => setTimeout(resolve, 250));
1062
- }
1073
+ function guardText(text, force, what, verb) {
1074
+ if (force || typeof text !== "string" || !text) return;
1075
+ const secret = findSecret(text);
1076
+ if (secret) throw new CliError("confirm", `The ${what} looks like ${secretWords(secret)}; ${verb} with --force if you mean to`, { kind: secret.kind });
1063
1077
  }
1064
- /**
1065
- * A one-shot whose text went over the live link waits this long for its receipt before it leaves (`waitForMessage`).
1066
- * Left at `sent`, the engine stopping took the text for unconfirmed, the next start sent it again on the DHT, and that
1067
- * copy took the chat's one DHT text awaiting a receipt: a script's next one-shot send waited 30 s behind it, every 5-8
1068
- * messages, and the last text showed "Connection closed before receipt" though the contact had it (agents#1640).
1069
- */
1070
- var ONE_SHOT_RECEIPT_MS = 2e3;
1071
- /**
1072
- * Waits until the contact confirmed my reaction or pin in a 1:1 chat (WISP 401): until `pending` no longer finds it in
1073
- * what the contact has not confirmed (`chatUnconfirmed`). It goes on the live session, a reaction also on the DHT
1074
- * envelopes; one not confirmed in time is kept and said again.
1075
- */
1076
- async function waitForConfirmed(ctx, chat, what, pending, ms) {
1077
- const until = Date.now() + ms;
1078
- while (pending(node(ctx).chatUnconfirmed({ linkId: chat }))) {
1079
- if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact has not confirmed the ${what} yet. It is kept here and ${goesOn(ctx)}`, { chat });
1080
- await new Promise((resolve) => setTimeout(resolve, 250));
1081
- }
1082
- }
1083
- /**
1084
- * Waits until a message of mine reached `target` (`sent`: on its way to the contact; `delivered`: acknowledged). A
1085
- * one-shot's text sent over the live link waits a moment more for its receipt (`ONE_SHOT_RECEIPT_MS`).
1086
- */
1087
- async function waitForMessage(ctx, chat, messageId, target, ms) {
1088
- const reached = await waitForDelivery(ctx, chat, messageId, target, ms);
1089
- if (ctx.mode !== "one-shot" || target !== "sent" || reached.delivery !== "sent" || reached.via !== "datalink") return reached;
1090
- return waitForDelivery(ctx, chat, messageId, "delivered", ONE_SHOT_RECEIPT_MS).catch(async () => await node(ctx).getMessage(chat, messageId) ?? reached);
1091
- }
1092
- async function waitForDelivery(ctx, chat, messageId, target, ms) {
1093
- const want = DELIVERY_RANK[target];
1094
- const look = (message) => {
1095
- if (!message) return void 0;
1096
- const delivery = message.delivery ?? "sent";
1097
- if (delivery === "failed") throw new CliError("engine", message.deliveryError ?? "The message could not be sent", {
1098
- messageId,
1099
- delivery
1100
- });
1101
- return (DELIVERY_RANK[delivery] ?? 0) >= want ? message : void 0;
1102
- };
1103
- return new Promise((resolve, reject) => {
1104
- let settled = false;
1105
- const finish = (error, message) => {
1106
- if (settled) return;
1107
- settled = true;
1108
- clearTimeout(timer);
1109
- off();
1110
- if (error) reject(error);
1111
- else resolve(message);
1112
- };
1113
- const check = (last = false) => void node(ctx).getMessage(chat, messageId).then((message) => {
1114
- try {
1115
- const done = look(message);
1116
- if (done) finish(null, done);
1117
- else if (last) finish(new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the message is ${message?.delivery ?? "not sent yet"} and ${goesOn(ctx)}`, {
1118
- messageId,
1119
- delivery: message?.delivery ?? null
1120
- }));
1121
- } catch (error) {
1122
- finish(error);
1123
- }
1124
- }, finish);
1125
- const timer = setTimeout(() => check(true), ms);
1126
- const off = ctx.hub.onEvent((event) => {
1127
- if (event.chat === chat && (event.messageId === messageId || event.message?.id === messageId)) check();
1128
- });
1129
- check();
1130
- });
1131
- }
1132
- //#endregion
1133
- //#region src/buttons.ts
1134
- /**
1135
- * `--button id:Label` (again for each, 1 to 6), `--style id=primary|neutral|danger`, `--once` and `--id`, as the
1136
- * method's parameters: `buttons` and `buttonsId`. Nothing when no `--button` is given. The label may hold colons: the
1137
- * id ends at the first one. An id given twice, two labels that read the same (ignoring case and spaces at the ends), a
1138
- * label that is another button's id, or a style not listed are a usage error here, before the profile opens; other
1139
- * bounds (ids, labels, how many) are the card's, checked when it is sent.
1140
- */
1141
- function buttonsOf(options) {
1142
- const given = Array.isArray(options.button) ? options.button : [];
1143
- if (!given.length) {
1144
- for (const flag of [
1145
- "style",
1146
- "once",
1147
- "id"
1148
- ]) if (options[flag] !== void 0) throw new CliError("usage", `--${flag} goes with --button id:Label`);
1149
- return;
1150
- }
1151
- const buttons = given.map((value) => {
1152
- const colon = value.indexOf(":");
1153
- if (colon < 1 || colon === value.length - 1) throw new CliError("usage", `--button takes id:Label, like yes:Yes, not ${JSON.stringify(value)}`);
1154
- return {
1155
- id: value.slice(0, colon),
1156
- label: value.slice(colon + 1).trim()
1157
- };
1158
- });
1159
- const twice = buttons.findIndex((button, at) => buttons.findIndex((other) => other.id === button.id) !== at);
1160
- if (twice !== -1) throw new CliError("usage", `--button ${JSON.stringify(given[twice])} repeats the id ${JSON.stringify(buttons[twice].id)}: each button takes its own`);
1161
- const clash = buttonLabelClash(buttons);
1162
- if (clash) {
1163
- const [at, other] = [JSON.stringify(given[clash.at]), JSON.stringify(given[clash.with])];
1164
- throw new CliError("usage", clash.kind === "label" ? `--button ${at} repeats the label of --button ${other} (ignoring case and spaces): a typed answer could not tell them apart` : `--button ${at} has a label that is the id of --button ${other}: a typed answer could not tell them apart`);
1165
- }
1166
- for (const value of Array.isArray(options.style) ? options.style : []) {
1167
- const eq = value.indexOf("=");
1168
- const button = eq > 0 ? buttons.find((b) => b.id === value.slice(0, eq)) : void 0;
1169
- if (!button) throw new CliError("usage", `--style takes id=primary|neutral|danger for one of the buttons, not ${JSON.stringify(value)}`);
1170
- const style = value.slice(eq + 1);
1171
- if (!BUTTON_STYLES.includes(style)) throw new CliError("usage", `--style ${JSON.stringify(value)}: a button's style is ${BUTTON_STYLES.join(", ")}`);
1172
- button.style = style;
1173
- }
1174
- if (options.once === true) for (const button of buttons) button.once = true;
1175
- return {
1176
- buttons,
1177
- ...options.id !== void 0 && { buttonsId: String(options.id) }
1178
- };
1179
- }
1180
- /** A buttons card checked by the sender's rule, or a `bad_request` that says what is wrong. */
1181
- function checked(card) {
1182
- const result = checkStatusCard(card);
1183
- if ("error" in result) throw new CliError("bad_request", `Buttons: ${result.error}`, { card });
1184
- return result.card;
1185
- }
1186
- /**
1187
- * The card a send's `buttons` (and `buttonsId`) make, or undefined when it names none. `buttons` is a list of
1188
- * `{id, label, style?, once?}`; the id of the question is made up (`ask-…`) unless given.
1189
- */
1190
- function buttonsCard(params) {
1191
- const buttons = params.buttons;
1192
- if (buttons === void 0 || buttons === null) {
1193
- if (params.buttonsId !== void 0) throw new CliError("bad_request", "buttonsId goes with buttons");
1194
- return;
1195
- }
1196
- if (!Array.isArray(buttons)) throw new CliError("bad_request", "buttons must be a list of {id, label, style?, once?}");
1197
- return checked({
1198
- kind: "buttons",
1199
- id: str(params, "buttonsId") ?? `ask-${toBase64Url(randomBytes(6))}`,
1200
- buttons
1201
- });
1202
- }
1203
- /** Whether a 1:1 contact's app shows and presses buttons: null until its app said what it offers. */
1204
- function pressable(link) {
1205
- const peer = link.sessionOffers?.peer;
1206
- return peer ? peer.includes(BUTTONS_CAPABILITY) : null;
1207
- }
1208
- /** The message of mine with buttons that `button update` names, by its id here (or the id both sides know). */
1209
- function buttonsMessage(message, ref, group) {
1210
- if (!message) throw new CliError("not_found", `No message ${JSON.stringify(ref)} of yours in this ${group ? "group" : "chat"}: the messageId send gave`);
1211
- if (message.card?.kind !== "buttons") throw new CliError("bad_request", "That message has no buttons: send one with send --button id:Label");
1212
- return message;
1213
- }
1214
- /**
1215
- * `button update`: the answer shown on a question's buttons (`chosen`), the buttons closed (`close`), or a new text
1216
- * (`text`), by editing the message with the same buttons. What is not given stays as it was.
1217
- */
1218
- async function updateButtons(ctx, params) {
1219
- const target = chatOrGroup(ctx, str(params, "chat", true));
1220
- const ref = str(params, "message", true);
1221
- const chosen = str(params, "chosen");
1222
- const close = bool(params, "close");
1223
- const newText = str(params, "text");
1224
- if (chosen === void 0 && !close && newText === void 0) throw new CliError("bad_request", "Nothing to update: give chosen, close or text");
1225
- if (newText !== void 0 && !bool(params, "force")) {
1226
- const secret = findSecret(newText);
1227
- if (secret) throw new CliError("confirm", `The text looks like ${secret.kind === "cashu" ? "a Cashu token (money anyone who reads it can take)" : "a secret (a seed or a private key)"}; update with --force if you mean to`, { kind: secret.kind });
1228
- }
1229
- const message = buttonsMessage(await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me"), ref, target.group);
1230
- if ((message.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) throw new CliError("refused", `This message took ${STATUS_CARD_LIMITS.edits} updates, the most one takes: ask again with a new send`, {
1231
- messageId: message.id,
1232
- edits: message.edit.seq
1233
- });
1234
- const before = message.card;
1235
- if (chosen !== void 0 && !before.buttons.some((b) => b.id === chosen)) throw new CliError("bad_request", `That message has no button ${JSON.stringify(chosen)}; its buttons: ${before.buttons.map((b) => b.id).join(", ")}`, { card: before });
1236
- const card = checked({
1237
- ...before,
1238
- ...chosen !== void 0 && { chosen },
1239
- ...(close || before.closed) && { closed: true }
1240
- });
1241
- const text = newText ?? message.text;
1242
- const wait = oneOf(params, "wait", target.group ? ["none", "sent"] : ["none", "confirmed"], "none");
1243
- const ms = num(params, "timeout", 30, {
1244
- min: 1,
1245
- max: 3600
1246
- }) * 1e3;
1247
- const result = await node(ctx).editMessage({
1248
- linkId: target.linkId,
1249
- messageId: message.id,
1250
- text,
1251
- card
1252
- });
1253
- if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error);
1254
- let edited = await node(ctx).getMessage(target.linkId, message.id);
1255
- if (wait === "confirmed" && edited?.edit?.pending) edited = await waitForEdit(ctx, target.linkId, message.id, ms);
1256
- const edges = wait === "sent" && edited?.edit ? await waitForGroupFrame(ctx, target.id, message.id, edited.edit.seq, ms) : void 0;
1257
- return {
1258
- [target.group ? "group" : "chat"]: target.id,
1259
- buttons: card.id,
1260
- messageId: message.id,
1261
- card,
1262
- edits: edited?.edit?.seq ?? 0,
1263
- ...target.group ? { ...edges !== void 0 && { edges } } : { confirmed: !!edited && !edited.edit?.pending }
1264
- };
1265
- }
1266
- /**
1267
- * `button press`: the other side of a question, as the app's tap: a press on a button of someone else's message, by
1268
- * its id here (or the id both sides know). The engine sends a reply whose text is the button's label, and refuses what
1269
- * an app would: a button the message does not have, closed buttons, a second answer past `once`, a second press
1270
- * within a second. A one-shot in a chat waits until the press went out, as `send` does.
1271
- */
1272
- async function pressButton(ctx, params) {
1273
- const target = chatOrGroup(ctx, str(params, "chat", true));
1274
- const ref = str(params, "message", true);
1275
- const buttonId = str(params, "button", true);
1276
- const where = target.group ? "group" : "chat";
1277
- const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender !== "me");
1278
- if (!message) throw new CliError("not_found", `No message ${JSON.stringify(ref)} from someone else in this ${where}: the id its event or history gave`);
1279
- if (message.card?.kind !== "buttons") throw new CliError("bad_request", "That message has no buttons");
1280
- const button = message.card.buttons.find((b) => b.id === buttonId);
1281
- if (!button) throw new CliError("not_found", `That message has no button ${JSON.stringify(buttonId)}; its buttons: ${message.card.buttons.map((b) => b.id).join(", ")}`);
1282
- const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", [
1283
- "none",
1284
- "sent",
1285
- "delivered"
1286
- ], ctx.mode === "one-shot" ? "sent" : "none");
1287
- const ms = num(params, "timeout", 30, {
1288
- min: 1,
1289
- max: 3600
1290
- }) * 1e3;
1291
- const result = await node(ctx).pressButton({
1292
- linkId: target.linkId,
1293
- messageId: message.id,
1294
- buttonId
1295
- });
1296
- if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error, result.paced ? { paced: true } : void 0);
1297
- const replyId = result.messageId ?? null;
1298
- const answer = {
1299
- [where]: target.id,
1300
- messageId: message.id,
1301
- button: button.id,
1302
- label: button.label,
1303
- replyId
1304
- };
1305
- if (!replyId) return answer;
1306
- if (target.group) {
1307
- const edges = wait === "sent" ? await waitForGroupFrame(ctx, target.id, replyId, void 0, ms) : node(ctx).groupTaken({
1308
- groupId: target.id,
1309
- messageId: replyId
1310
- });
1311
- return {
1312
- ...answer,
1313
- edges
1314
- };
1315
- }
1316
- const reply = wait === "none" ? await node(ctx).getMessage(target.linkId, replyId) : await waitForMessage(ctx, target.linkId, replyId, wait, ms);
1317
- return {
1318
- ...answer,
1319
- delivery: reply?.delivery ?? null
1320
- };
1321
- }
1322
- var BUTTON_METHODS = {
1323
- /** WISP 406 · Message Buttons: a press on a button of someone else's message, as the app's tap. */
1324
- "button.press": pressButton,
1325
- /** WISP 406 · Message Buttons: the answer chosen on a question of mine, its buttons closed, or its text changed. */
1326
- "button.update": updateButtons
1327
- };
1328
1078
  //#endregion
1329
- export { waitForConfirmed as a, waitForMessage as c, pressable as i, waitForRemoval as l, buttonsCard as n, waitForEdit as o, buttonsOf as r, waitForGroupFrame as s, BUTTON_METHODS as t, findSecret as u };
1079
+ export { secretWords as n, findSecret as r, guardText as t };
1330
1080
 
1331
- //# sourceMappingURL=buttons-CuRfKnPI.js.map
1081
+ //# sourceMappingURL=secretGuard-CSVNxXVW.js.map