@toon-protocol/client-mcp 0.6.0 → 0.7.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.
@@ -11675,6 +11675,80 @@ function isEventExpired(event, nowSeconds = Math.floor(Date.now() / 1e3)) {
11675
11675
  const exp = getEventExpiration(event);
11676
11676
  return exp !== void 0 && exp <= nowSeconds;
11677
11677
  }
11678
+ var genesis_peers_default2 = [];
11679
+ var PUBKEY_REGEX32 = /^[0-9a-f]{64}$/;
11680
+ var ILP_ADDRESS_REGEX2 = /^g\.[a-zA-Z0-9.-]+$/;
11681
+ function isValidPubkey22(pubkey) {
11682
+ return PUBKEY_REGEX32.test(pubkey);
11683
+ }
11684
+ function isValidRelayUrl2(url) {
11685
+ return url.startsWith("wss://") || url.startsWith("ws://");
11686
+ }
11687
+ function isValidIlpAddress2(address) {
11688
+ return ILP_ADDRESS_REGEX2.test(address);
11689
+ }
11690
+ function isValidBtpEndpoint2(url) {
11691
+ return url.startsWith("wss://") || url.startsWith("ws://");
11692
+ }
11693
+ function isValidGenesisPeer2(entry) {
11694
+ if (typeof entry !== "object" || entry === null) return false;
11695
+ const obj = entry;
11696
+ return typeof obj["pubkey"] === "string" && typeof obj["relayUrl"] === "string" && typeof obj["ilpAddress"] === "string" && typeof obj["btpEndpoint"] === "string" && isValidPubkey22(obj["pubkey"]) && isValidRelayUrl2(obj["relayUrl"]) && isValidIlpAddress2(obj["ilpAddress"]) && isValidBtpEndpoint2(obj["btpEndpoint"]);
11697
+ }
11698
+ function deduplicateByPubkey2(peers) {
11699
+ const map = /* @__PURE__ */ new Map();
11700
+ for (const peer of peers) {
11701
+ map.set(peer.pubkey, peer);
11702
+ }
11703
+ return [...map.values()];
11704
+ }
11705
+ function loadGenesisPeers2() {
11706
+ const raw = genesis_peers_default2;
11707
+ const valid = [];
11708
+ for (const entry of raw) {
11709
+ if (isValidGenesisPeer2(entry)) {
11710
+ valid.push(entry);
11711
+ } else {
11712
+ console.warn("Skipping invalid genesis peer entry:", entry);
11713
+ }
11714
+ }
11715
+ return deduplicateByPubkey2(valid);
11716
+ }
11717
+ function loadAdditionalPeers2(json) {
11718
+ let parsed;
11719
+ try {
11720
+ parsed = JSON.parse(json);
11721
+ } catch {
11722
+ console.warn("Failed to parse additional peers JSON:", json);
11723
+ return [];
11724
+ }
11725
+ if (!Array.isArray(parsed)) {
11726
+ console.warn("Additional peers JSON is not an array");
11727
+ return [];
11728
+ }
11729
+ const valid = [];
11730
+ for (const entry of parsed) {
11731
+ if (isValidGenesisPeer2(entry)) {
11732
+ valid.push(entry);
11733
+ } else {
11734
+ console.warn("Skipping invalid additional peer entry:", entry);
11735
+ }
11736
+ }
11737
+ return valid;
11738
+ }
11739
+ function loadAllPeers2(additionalPeersJson) {
11740
+ const genesis = loadGenesisPeers2();
11741
+ if (!additionalPeersJson) {
11742
+ return genesis;
11743
+ }
11744
+ const additional = loadAdditionalPeers2(additionalPeersJson);
11745
+ return deduplicateByPubkey2([...genesis, ...additional]);
11746
+ }
11747
+ var GenesisPeerLoader2 = {
11748
+ loadGenesisPeers: loadGenesisPeers2,
11749
+ loadAdditionalPeers: loadAdditionalPeers2,
11750
+ loadAllPeers: loadAllPeers2
11751
+ };
11678
11752
  var ILP_TO_SEMANTIC2 = Object.freeze({
11679
11753
  T00: "internal_error",
11680
11754
  T04: "insufficient_funds",
@@ -11756,19 +11830,29 @@ function parseCsvEnv(value) {
11756
11830
  const items = value.split(",").map((s) => s.trim()).filter(Boolean);
11757
11831
  return items.length ? items : void 0;
11758
11832
  }
11833
+ function deriveRouteDestinations(anchor) {
11834
+ const segs = anchor.split(".");
11835
+ if (segs.at(-1) === "store" && segs.at(-2) === "relay") {
11836
+ const base = segs.slice(0, -2).join(".");
11837
+ return { publish: `${base}.relay`, store: `${base}.store` };
11838
+ }
11839
+ return { publish: anchor, store: anchor };
11840
+ }
11759
11841
  function resolveConfig(file) {
11760
11842
  const mnemonic = resolveMnemonic(file);
11761
11843
  const proxyUrl = process.env["TOON_CLIENT_PROXY_URL"] ?? file.proxyUrl;
11762
11844
  const faucetUrl = process.env["TOON_CLIENT_FAUCET_URL"] ?? file.faucetUrl;
11763
11845
  const btpUrl = process.env["TOON_CLIENT_BTP_URL"] ?? file.btpUrl;
11764
11846
  const hasUplink = Boolean(btpUrl || proxyUrl);
11765
- const relayUrl = process.env["TOON_CLIENT_RELAY_URL"] ?? file.relayUrl ?? "ws://localhost:7100";
11847
+ const genesisSeed = GenesisPeerLoader2.loadGenesisPeers()[0];
11848
+ const relayUrl = process.env["TOON_CLIENT_RELAY_URL"] ?? file.relayUrl ?? genesisSeed?.relayUrl ?? "ws://localhost:7100";
11766
11849
  const httpPort = Number(
11767
11850
  process.env["TOON_CLIENT_HTTP_PORT"] ?? file.httpPort ?? 8787
11768
11851
  );
11769
- const destination = process.env["TOON_CLIENT_DESTINATION"] ?? file.destination ?? "g.townhouse.town";
11770
- const publishDestination = process.env["TOON_CLIENT_PUBLISH_DESTINATION"] ?? file.publishDestination ?? destination;
11771
- const storeDestination = process.env["TOON_CLIENT_STORE_DESTINATION"] ?? file.storeDestination ?? destination;
11852
+ const destination = process.env["TOON_CLIENT_DESTINATION"] ?? file.destination ?? genesisSeed?.ilpAddress ?? "g.townhouse.town";
11853
+ const routes = deriveRouteDestinations(destination);
11854
+ const publishDestination = process.env["TOON_CLIENT_PUBLISH_DESTINATION"] ?? file.publishDestination ?? routes.publish;
11855
+ const storeDestination = process.env["TOON_CLIENT_STORE_DESTINATION"] ?? file.storeDestination ?? routes.store;
11772
11856
  const feePerEvent = BigInt(file.feePerEvent ?? "1");
11773
11857
  const arweaveGateways = parseCsvEnv(process.env["TOON_CLIENT_ARWEAVE_GATEWAYS"]) ?? file.arweaveGateways ?? [...ARWEAVE_GATEWAYS];
11774
11858
  const network = process.env["TOON_CLIENT_NETWORK"] ?? file.network;
@@ -12142,4 +12226,4 @@ export {
12142
12226
  @scure/bip32/lib/esm/index.js:
12143
12227
  (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12144
12228
  */
12145
- //# sourceMappingURL=chunk-TDXKG3EI.js.map
12229
+ //# sourceMappingURL=chunk-76CTU2A5.js.map