import { createRequire as __createRequire } from 'module'; import { fileURLToPath as __fileURLToPath } from 'url'; import { dirname as __pathDirname } from 'path'; const require = __createRequire(import.meta.url); const __filename = __fileURLToPath(import.meta.url); const __dirname = __pathDirname(__filename);
import {
  Credential_exports,
  Method_exports,
  zod_exports
} from "./chunk-2HBLU5GV.js";
import "./chunk-OCLKPYUU.js";
import {
  Transaction
} from "./chunk-N5MEZ42L.js";
import "./chunk-6ADWLA5A.js";
import "./chunk-BLV67HXL.js";
import "./chunk-NGS6K3I3.js";
import "./chunk-77SWBATH.js";
import "./chunk-7LGHVVIJ.js";
import "./chunk-YPWSCLE3.js";

// ../../node_modules/.pnpm/@suimpp+mpp@0.7.0_@modelcontextprotocol+sdk@1.28.0_zod@3.25.76__express@5.2.1_hono@4.12_f01adfc448f369aa1dacd5a54f4d2679/node_modules/@suimpp/mpp/dist/client.js
var suiCharge = Method_exports.from({
  intent: "charge",
  name: "sui",
  schema: {
    credential: {
      payload: zod_exports.object({
        digest: zod_exports.string(),
        signature: zod_exports.string()
      })
    },
    request: zod_exports.object({
      amount: zod_exports.string(),
      currency: zod_exports.string(),
      recipient: zod_exports.string()
    })
  }
});
var textEncoder = new TextEncoder();
function createSuiPaymentProofMessage({
  challenge,
  digest
}) {
  return JSON.stringify({
    domain: "suimpp.sui.payment-proof",
    version: 1,
    method: challenge.method,
    intent: challenge.intent,
    challengeId: challenge.id,
    amount: challenge.request.amount,
    currency: challenge.request.currency,
    recipient: challenge.request.recipient,
    digest
  });
}
function createSuiPaymentProofBytes(message) {
  return textEncoder.encode(createSuiPaymentProofMessage(message));
}
function parseAmountToRaw(amount, decimals) {
  const [whole = "0", frac = ""] = amount.split(".");
  const paddedFrac = frac.padEnd(decimals, "0").slice(0, decimals);
  return BigInt(whole + paddedFrac);
}
var SUI_USDC_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
var SUI_USDC_TESTNET_TYPE = "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC";
var SUI_DOLLAR_TYPE = "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
var USDC = {
  type: SUI_USDC_TYPE,
  decimals: 6
};
var USDC_TESTNET = {
  type: SUI_USDC_TESTNET_TYPE,
  decimals: 6
};
var SUI_DOLLAR = {
  type: SUI_DOLLAR_TYPE,
  decimals: 6
};
function sui(options) {
  if (!options.currency) {
    throw new Error("[suimpp] Currency is required");
  }
  return Method_exports.toClient(suiCharge, {
    async createCredential({ challenge }) {
      const { amount, currency, recipient } = challenge.request;
      if (currency !== options.currency.type) {
        throw new Error(`Unsupported currency: ${currency}`);
      }
      const amountRaw = parseAmountToRaw(amount, options.currency.decimals);
      const tx = new Transaction();
      tx.setSender(options.signer.toSuiAddress());
      tx.moveCall({
        target: "0x2::balance::send_funds",
        arguments: [
          tx.balance({ type: options.currency.type, balance: amountRaw }),
          tx.pure.address(recipient)
        ],
        typeArguments: [options.currency.type]
      });
      let result;
      try {
        if (options.execute) {
          result = await options.execute(tx);
        } else {
          const execResult = await options.client.core.signAndExecuteTransaction({
            transaction: await tx.build({ client: options.client }),
            signer: options.signer,
            include: { effects: true }
          });
          if (execResult.FailedTransaction) {
            throw new Error(
              execResult.FailedTransaction.status.error?.message ?? "Transaction failed"
            );
          }
          if (!execResult.Transaction) {
            throw new Error("Transaction failed");
          }
          result = execResult.Transaction;
        }
      } catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        throw new Error(`Payment transaction failed: ${msg}`);
      }
      const proof = await options.signer.signPersonalMessage(
        createSuiPaymentProofBytes({
          challenge,
          digest: result.digest
        })
      );
      return Credential_exports.serialize({
        challenge,
        payload: {
          digest: result.digest,
          signature: proof.signature
        }
      });
    }
  });
}
export {
  SUI_DOLLAR,
  SUI_DOLLAR_TYPE,
  SUI_USDC_TESTNET_TYPE,
  SUI_USDC_TYPE,
  USDC,
  USDC_TESTNET,
  sui,
  suiCharge
};
//# sourceMappingURL=client-Q7WIWXQW.js.map