{"version":3,"file":"text.cjs","names":["MODE_SPELLINGS: Record<BlockEventMode, readonly string[]>"],"sources":["../../src/utils/text.ts"],"sourcesContent":["/**\n * Decodes blockchain event attributes from various formats to strings\n * Handles both string and Uint8Array inputs from Tendermint events\n * @param x - The attribute value to decode (string or Uint8Array)\n * @returns Decoded string value\n */\nexport const decodeAttr = (x: Uint8Array | string) => {\n  if (typeof x === \"string\") {\n    return x;\n  }\n  else if (x instanceof Uint8Array) {\n    return Buffer.from(x).toString();\n  }\n  else {\n    return \"\";\n  }\n};\n\n/** Minimal shape of an ABCI event, compatible with both CometBFT 0.37 and 0.38 response types */\nexport type ModeTaggedEvent = {\n  attributes: readonly {\n    key: Uint8Array | string\n    value: Uint8Array | string\n  }[]\n};\n\n/** Values Cosmos SDK 0.50+ stamps on `finalize_block_events` to mark their origin (baseapp.go) */\nexport type BlockEventMode = \"BeginBlock\" | \"EndBlock\";\n\nconst MODE_SPELLINGS: Record<BlockEventMode, readonly string[]> = {\n  BeginBlock: [\"BeginBlock\", \"begin_block\"],\n  EndBlock: [\"EndBlock\", \"end_block\"],\n};\n\n/**\n * Checks whether a finalize_block event carries the given `mode` attribute.\n * The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings\n * are accepted as well so forks that lowercase the value keep working.\n * @param event - Event with an attributes array\n * @param mode - Which phase of the block the event must belong to\n * @returns true when the event has a matching `mode` attribute\n */\nexport const hasBlockEventMode = (event: ModeTaggedEvent, mode: BlockEventMode): boolean => {\n  const accepted = MODE_SPELLINGS[mode];\n  return event.attributes.some(a => decodeAttr(a.key) === \"mode\" && accepted.includes(decodeAttr(a.value)));\n};\n\n/**\n * Returns a URL that is safe to log: the password part of any credentials is masked.\n * Strings that do not parse as a URL are returned unchanged.\n */\nexport const redactUrl = (url: string): string => {\n  try {\n    const parsed = new URL(url);\n    if (parsed.password) {\n      parsed.password = \"***\";\n    }\n    return parsed.toString();\n  }\n  catch (_e) {\n    return url;\n  }\n};\n"],"mappings":";;;;;;;;AAMA,MAAa,cAAc,MAA2B;AACpD,KAAI,OAAO,MAAM,SACf,QAAO;UAEA,aAAa,WACpB,QAAO,OAAO,KAAK,EAAE,CAAC,UAAU;KAGhC,QAAO;;AAeX,MAAMA,iBAA4D;CAChE,YAAY,CAAC,cAAc,cAAc;CACzC,UAAU,CAAC,YAAY,YAAY;CACpC;;;;;;;;;AAUD,MAAa,qBAAqB,OAAwB,SAAkC;CAC1F,MAAM,WAAW,eAAe;AAChC,QAAO,MAAM,WAAW,MAAK,MAAK,WAAW,EAAE,IAAI,KAAK,UAAU,SAAS,SAAS,WAAW,EAAE,MAAM,CAAC,CAAC;;;;;;AAO3G,MAAa,aAAa,QAAwB;AAChD,KAAI;EACF,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,MAAI,OAAO,SACT,QAAO,WAAW;AAEpB,SAAO,OAAO,UAAU;UAEnB,IAAI;AACT,SAAO"}