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 "./chunk-OCLKPYUU.js";
import {
  Transaction,
  coinWithBalance
} from "./chunk-UY3WLP52.js";
import "./chunk-3XUF7GM3.js";
import {
  Credential_exports,
  Method_exports,
  zod_exports
} from "./chunk-2HBLU5GV.js";
import "./chunk-NGS6K3I3.js";
import "./chunk-77SWBATH.js";
import "./chunk-7LGHVVIJ.js";
import "./chunk-YPWSCLE3.js";

// ../../node_modules/.pnpm/@suimpp+mpp@0.3.1_@modelcontextprotocol+sdk@1.28.0_zod@3.25.76__express@5.2.1_hono@4.12_0b94899a6b1cb79b7850473c6a4b48f9/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()
      })
    },
    request: zod_exports.object({
      amount: zod_exports.string(),
      currency: zod_exports.string(),
      recipient: zod_exports.string()
    })
  }
});
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";
function sui(options) {
  const address = options.signer.toSuiAddress();
  const decimals = options.decimals ?? 6;
  return Method_exports.toClient(suiCharge, {
    async createCredential({ challenge }) {
      const { amount, currency, recipient } = challenge.request;
      const amountRaw = parseAmountToRaw(amount, decimals);
      const tx = new Transaction();
      tx.setSender(address);
      const payment = coinWithBalance({ balance: amountRaw, type: currency });
      tx.transferObjects([payment], recipient);
      let result;
      try {
        if (options.execute) {
          result = await options.execute(tx);
        } else {
          const built = await tx.build({ client: options.client });
          const { signature } = await options.signer.signTransaction(built);
          const execResult = await options.client.core.executeTransaction({
            transaction: built,
            signatures: [signature],
            include: { effects: true }
          });
          if (execResult.FailedTransaction) {
            throw new Error(execResult.FailedTransaction.status.error?.message ?? "Transaction failed");
          }
          result = execResult.Transaction;
        }
      } catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        throw new Error(`Payment transaction failed: ${msg}`);
      }
      return Credential_exports.serialize({
        challenge,
        payload: { digest: result.digest }
      });
    }
  });
}
export {
  SUI_USDC_TYPE,
  sui,
  suiCharge
};
//# sourceMappingURL=client-QOEU3RTY.js.map