@toon-protocol/client-mcp 0.5.3 → 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.
@@ -6956,11 +6956,11 @@ function decodeUtf8(bytes) {
6956
6956
  function isBase64(str) {
6957
6957
  return /^[A-Za-z0-9+/]*={0,2}$/.test(str);
6958
6958
  }
6959
- var REQUEST_LINE = "POST /write HTTP/1.1";
6959
+ var DEFAULT_REQUEST_TARGET = "/write";
6960
6960
  var HEADERS = ["Host: relay", "Content-Type: application/json"];
6961
- function buildStoreWriteEnvelope(event) {
6961
+ function buildStoreWriteEnvelope(event, requestTarget = DEFAULT_REQUEST_TARGET) {
6962
6962
  const body = JSON.stringify({ event });
6963
- const head = [REQUEST_LINE, ...HEADERS].join("\r\n");
6963
+ const head = [`POST ${requestTarget} HTTP/1.1`, ...HEADERS].join("\r\n");
6964
6964
  return encodeUtf8(head + "\r\n\r\n" + body);
6965
6965
  }
6966
6966
  var CRLF = "\r\n";
@@ -8755,12 +8755,12 @@ var OnChainChannelClient = class {
8755
8755
  */
8756
8756
  parseChainId(chain2) {
8757
8757
  const parts = chain2.split(":");
8758
- if (parts.length < 3) {
8758
+ if (parts.length < 2) {
8759
8759
  throw new Error(
8760
- `Invalid chain format: "${chain2}". Expected "evm:{network}:{chainId}".`
8760
+ `Invalid chain format: "${chain2}". Expected "evm:{network}:{chainId}" or "evm:{chainId}".`
8761
8761
  );
8762
8762
  }
8763
- const chainIdStr = parts[2];
8763
+ const chainIdStr = parts.length >= 3 ? parts[2] : parts[1];
8764
8764
  if (!chainIdStr) {
8765
8765
  throw new Error(
8766
8766
  `Invalid chain format: "${chain2}". Expected "evm:{network}:{chainId}".`
@@ -9957,7 +9957,9 @@ async function requestBlobStorage(client, secretKey, params) {
9957
9957
  const result = await client.publishEvent(event, {
9958
9958
  destination: params.destination,
9959
9959
  claim: params.claim,
9960
- ilpAmount: params.ilpAmount
9960
+ ilpAmount: params.ilpAmount,
9961
+ // The store/DVM backend serves POST /store (not the relay's /write).
9962
+ proxyPath: "/store"
9961
9963
  });
9962
9964
  if (!result.success) {
9963
9965
  return {
@@ -10457,7 +10459,7 @@ var ToonClient = class {
10457
10459
  if (result.negotiatedChain && result.settlementAddress) {
10458
10460
  const chainType = result.negotiatedChain.split(":")[0] ?? "evm";
10459
10461
  const parts = result.negotiatedChain.split(":");
10460
- const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : 0;
10462
+ const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : parts.length >= 2 ? parseInt(parts[1] ?? "0", 10) : 0;
10461
10463
  const r = result;
10462
10464
  this.peerNegotiations.set(result.registeredPeerId, {
10463
10465
  chain: result.negotiatedChain,
@@ -10475,7 +10477,7 @@ var ToonClient = class {
10475
10477
  if (matchedChain) {
10476
10478
  const peerAddr = peerInfo.settlementAddresses?.[matchedChain];
10477
10479
  const parts = matchedChain.split(":");
10478
- const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : 0;
10480
+ const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : parts.length >= 2 ? parseInt(parts[1] ?? "0", 10) : 0;
10479
10481
  if (peerAddr) {
10480
10482
  this.peerNegotiations.set(result.registeredPeerId, {
10481
10483
  chain: matchedChain,
@@ -10560,7 +10562,7 @@ var ToonClient = class {
10560
10562
  const toonData = this.config.toonEncoder(event);
10561
10563
  const basePricePerByte = 10n;
10562
10564
  const amount = options?.ilpAmount !== void 0 ? String(options.ilpAmount) : String(BigInt(toonData.length) * basePricePerByte);
10563
- const writeData = buildStoreWriteEnvelope(event);
10565
+ const writeData = buildStoreWriteEnvelope(event, options?.proxyPath);
10564
10566
  const destination = options?.destination ?? this.config.destinationAddress;
10565
10567
  const transport = this.getClaimTransport();
10566
10568
  let claimMessage;
@@ -10932,7 +10934,7 @@ var ToonClient = class {
10932
10934
  getChainContext(negotiatedChain) {
10933
10935
  if (!negotiatedChain) return void 0;
10934
10936
  const parts = negotiatedChain.split(":");
10935
- const chainIdPart = parts.length >= 3 ? parts[2] : void 0;
10937
+ const chainIdPart = parts.length >= 3 ? parts[2] : parts.length >= 2 ? parts[1] : void 0;
10936
10938
  const numericChainId = chainIdPart !== void 0 ? parseInt(chainIdPart, 10) : NaN;
10937
10939
  if (isNaN(numericChainId)) return void 0;
10938
10940
  const tokenNetworkAddress = this.config.tokenNetworks?.[negotiatedChain];
@@ -11673,6 +11675,80 @@ function isEventExpired(event, nowSeconds = Math.floor(Date.now() / 1e3)) {
11673
11675
  const exp = getEventExpiration(event);
11674
11676
  return exp !== void 0 && exp <= nowSeconds;
11675
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
+ };
11676
11752
  var ILP_TO_SEMANTIC2 = Object.freeze({
11677
11753
  T00: "internal_error",
11678
11754
  T04: "insufficient_funds",
@@ -11702,6 +11778,18 @@ function buildIlpPrepare(params) {
11702
11778
  };
11703
11779
  }
11704
11780
 
11781
+ // ../arweave/dist/gateways.js
11782
+ var ARWEAVE_GATEWAYS = [
11783
+ "https://ar-io.dev",
11784
+ "https://arweave.net",
11785
+ "https://permagate.io"
11786
+ ];
11787
+ function arweaveUrls(txId, gateways = ARWEAVE_GATEWAYS) {
11788
+ const all = (gateways.length ? gateways : ARWEAVE_GATEWAYS).map((g) => `${g}/${txId}`);
11789
+ const [url, ...fallbacks] = all;
11790
+ return { url: url ?? `${ARWEAVE_GATEWAYS[0]}/${txId}`, fallbacks };
11791
+ }
11792
+
11705
11793
  // src/daemon/config.ts
11706
11794
  var DEFAULT_KEYSTORE_PASSWORD = "toon-client-default";
11707
11795
  function configDir() {
@@ -11737,18 +11825,36 @@ function resolveMnemonic(file) {
11737
11825
  "No mnemonic configured. Set TOON_CLIENT_MNEMONIC, configure a keystorePath (+ TOON_CLIENT_KEYSTORE_PASSWORD), or add `mnemonic` to the config file."
11738
11826
  );
11739
11827
  }
11828
+ function parseCsvEnv(value) {
11829
+ if (!value) return void 0;
11830
+ const items = value.split(",").map((s) => s.trim()).filter(Boolean);
11831
+ return items.length ? items : void 0;
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
+ }
11740
11841
  function resolveConfig(file) {
11741
11842
  const mnemonic = resolveMnemonic(file);
11742
11843
  const proxyUrl = process.env["TOON_CLIENT_PROXY_URL"] ?? file.proxyUrl;
11743
11844
  const faucetUrl = process.env["TOON_CLIENT_FAUCET_URL"] ?? file.faucetUrl;
11744
11845
  const btpUrl = process.env["TOON_CLIENT_BTP_URL"] ?? file.btpUrl;
11745
11846
  const hasUplink = Boolean(btpUrl || proxyUrl);
11746
- 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";
11747
11849
  const httpPort = Number(
11748
11850
  process.env["TOON_CLIENT_HTTP_PORT"] ?? file.httpPort ?? 8787
11749
11851
  );
11750
- const destination = process.env["TOON_CLIENT_DESTINATION"] ?? file.destination ?? "g.townhouse.town";
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;
11751
11856
  const feePerEvent = BigInt(file.feePerEvent ?? "1");
11857
+ const arweaveGateways = parseCsvEnv(process.env["TOON_CLIENT_ARWEAVE_GATEWAYS"]) ?? file.arweaveGateways ?? [...ARWEAVE_GATEWAYS];
11752
11858
  const network = process.env["TOON_CLIENT_NETWORK"] ?? file.network;
11753
11859
  const chain2 = process.env["TOON_CLIENT_CHAIN"] ?? file.chain ?? "evm";
11754
11860
  const apex = file.apexChains?.[chain2] ?? file.apex ?? buildProxyApexNegotiation(file, chain2, destination);
@@ -11794,13 +11900,16 @@ function resolveConfig(file) {
11794
11900
  ...proxyUrl ? { proxyUrl } : {},
11795
11901
  ...faucetUrl ? { faucetUrl } : {},
11796
11902
  destination,
11903
+ publishDestination,
11904
+ storeDestination,
11797
11905
  feePerEvent,
11798
11906
  ...apex ? { apex } : {},
11799
11907
  ...file.apexChildPeers ? { apexChildPeers: file.apexChildPeers } : {},
11800
11908
  chain: chain2,
11801
11909
  apexChannelStorePath,
11802
11910
  toonClientConfig,
11803
- network
11911
+ network,
11912
+ arweaveGateways
11804
11913
  };
11805
11914
  }
11806
11915
  function defaultChainKey(chain2, chainId) {
@@ -11823,7 +11932,7 @@ function buildProxyApexNegotiation(file, chain2, destination) {
11823
11932
  const settlementAddress = settlementAddresses[chainKey];
11824
11933
  if (!settlementAddress) return void 0;
11825
11934
  const parts = chainKey.split(":");
11826
- const chainId = chain2 === "evm" && parts.length >= 3 ? Number(parts[2] ?? 0) : 0;
11935
+ const chainId = chain2 === "evm" && parts.length >= 2 ? Number(parts[2] ?? parts[1] ?? 0) : 0;
11827
11936
  const peerId = destination.split(".").at(-1) ?? destination;
11828
11937
  return {
11829
11938
  destination,
@@ -12080,6 +12189,7 @@ export {
12080
12189
  parseIlpPeerInfo2 as parseIlpPeerInfo,
12081
12190
  isEventExpired,
12082
12191
  buildIlpPrepare,
12192
+ arweaveUrls,
12083
12193
  DEFAULT_KEYSTORE_PASSWORD,
12084
12194
  configDir,
12085
12195
  defaultConfigPath,
@@ -12116,4 +12226,4 @@ export {
12116
12226
  @scure/bip32/lib/esm/index.js:
12117
12227
  (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12118
12228
  */
12119
- //# sourceMappingURL=chunk-3UECPDBJ.js.map
12229
+ //# sourceMappingURL=chunk-76CTU2A5.js.map