@t2000/cli 9.5.0 → 9.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.
@@ -9890,6 +9890,7 @@ var KeypairSigner = class {
9890
9890
  constructor(keypair) {
9891
9891
  this.keypair = keypair;
9892
9892
  }
9893
+ kind = "keypair";
9893
9894
  getAddress() {
9894
9895
  return this.keypair.getPublicKey().toSuiAddress();
9895
9896
  }
@@ -9988,6 +9989,13 @@ async function payWithMpp(args) {
9988
9989
  }
9989
9990
  const headerChallenge = await parseMppSuiChallenge(probe);
9990
9991
  if (headerChallenge) {
9992
+ if (signer.kind === "zklogin") {
9993
+ throw new T2000Error(
9994
+ "DIALECT_UNSUPPORTED",
9995
+ "This seller only offers the MPP header dialect, which zkLogin (Passport) wallets cannot safely pay: the seller cannot verify zkLogin signatures, so the payment would settle on-chain without the service delivering. No payment was made. Use an x402-capable service, or pay from a keypair wallet (t2 CLI / MCP).",
9996
+ { dialect: "mpp-header", signerKind: "zklogin" }
9997
+ );
9998
+ }
9991
9999
  const result = await payViaMppHeader({ signer, client, options });
9992
10000
  await reportDirectPayment(result, options.url);
9993
10001
  return result;
@@ -10223,6 +10231,7 @@ var ZkLoginSigner = class {
10223
10231
  this.userAddress = userAddress;
10224
10232
  this.maxEpoch = maxEpoch;
10225
10233
  }
10234
+ kind = "zklogin";
10226
10235
  getAddress() {
10227
10236
  return this.userAddress;
10228
10237
  }
@@ -11929,6 +11938,205 @@ var T2000 = class _T2000 extends import_index.default {
11929
11938
  }
11930
11939
  };
11931
11940
  init_errors();
11941
+ init_errors();
11942
+ init_token_registry();
11943
+ init_preflight();
11944
+ init_coinSelection();
11945
+ var A2A_ESCROW_PACKAGE_ID = process.env.A2A_ESCROW_PACKAGE_ID ?? "0x9e67c380fb7079d793d6d15ff916b24d82779d7119bfa4631863102ed485c0a0";
11946
+ var CLOCK_ID2 = "0x6";
11947
+ var MODULE = "escrow";
11948
+ var MAX_JOB_USDC = 50;
11949
+ var JOB_STATES = [
11950
+ "funded",
11951
+ "delivered",
11952
+ "released",
11953
+ "refunded",
11954
+ "rejected"
11955
+ ];
11956
+ function hexToBytes22(hex) {
11957
+ const clean3 = hex.startsWith("0x") ? hex.slice(2) : hex;
11958
+ if (clean3.length === 0 || clean3.length % 2 !== 0 || /[^0-9a-fA-F]/.test(clean3)) {
11959
+ throw new T2000Error(
11960
+ "INVALID_AMOUNT",
11961
+ `Expected a hex hash (0x\u2026), got "${hex.slice(0, 32)}"`
11962
+ );
11963
+ }
11964
+ const out = [];
11965
+ for (let i = 0; i < clean3.length; i += 2) {
11966
+ out.push(Number.parseInt(clean3.slice(i, i + 2), 16));
11967
+ }
11968
+ return out;
11969
+ }
11970
+ function bytesToHex22(bytes) {
11971
+ let s = "0x";
11972
+ for (const b of bytes) s += b.toString(16).padStart(2, "0");
11973
+ return s;
11974
+ }
11975
+ function preflightCreateJob(terms) {
11976
+ const addressCheck = checkSuiAddress(terms.seller);
11977
+ if (!addressCheck.valid) return addressCheck;
11978
+ if (!Number.isFinite(terms.amountUsdc) || terms.amountUsdc <= 0) {
11979
+ return preflightFail("INVALID_AMOUNT", `Amount must be positive. Got ${terms.amountUsdc}.`);
11980
+ }
11981
+ if (terms.amountUsdc > MAX_JOB_USDC) {
11982
+ return preflightFail(
11983
+ "INVALID_AMOUNT",
11984
+ `v1 caps escrow jobs at ${MAX_JOB_USDC} USDC (no-arbitration split only stays fair at small sizes). Got ${terms.amountUsdc}.`
11985
+ );
11986
+ }
11987
+ if (terms.deliverByMs <= Date.now()) {
11988
+ return preflightFail("INVALID_AMOUNT", "deliverByMs must be in the future.");
11989
+ }
11990
+ if (terms.reviewWindowMs < 0) {
11991
+ return preflightFail("INVALID_AMOUNT", "reviewWindowMs must be \u2265 0.");
11992
+ }
11993
+ if (!Number.isInteger(terms.rejectSplitBps) || terms.rejectSplitBps < 0 || terms.rejectSplitBps > 1e4) {
11994
+ return preflightFail("INVALID_AMOUNT", "rejectSplitBps must be an integer 0\u201310000.");
11995
+ }
11996
+ try {
11997
+ hexToBytes22(terms.specHash);
11998
+ } catch (e) {
11999
+ return preflightFail("INVALID_AMOUNT", e.message);
12000
+ }
12001
+ return PREFLIGHT_OK;
12002
+ }
12003
+ async function buildCreateJobTx({
12004
+ client,
12005
+ buyer,
12006
+ terms
12007
+ }) {
12008
+ const pf = preflightCreateJob(terms);
12009
+ if (!pf.valid) throw new T2000Error(pf.code, pf.error);
12010
+ const seller = validateAddress(terms.seller);
12011
+ if (seller === validateAddress(buyer)) {
12012
+ throw new T2000Error("INVALID_ADDRESS", "Buyer and seller must be different wallets.");
12013
+ }
12014
+ const rawAmount = BigInt(Math.floor(terms.amountUsdc * 10 ** USDC_DECIMALS));
12015
+ const tx = new Transaction();
12016
+ const { coin } = await selectAndSplitCoin(tx, client, buyer, USDC_TYPE, rawAmount, {
12017
+ allowSwapAll: false
12018
+ });
12019
+ tx.moveCall({
12020
+ target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE}::create`,
12021
+ typeArguments: [USDC_TYPE],
12022
+ arguments: [
12023
+ tx.pure.address(seller),
12024
+ coin,
12025
+ tx.pure.vector("u8", hexToBytes22(terms.specHash)),
12026
+ tx.pure.u64(terms.deliverByMs),
12027
+ tx.pure.u64(terms.reviewWindowMs),
12028
+ tx.pure.u64(terms.rejectSplitBps),
12029
+ tx.object(CLOCK_ID2)
12030
+ ]
12031
+ });
12032
+ return tx;
12033
+ }
12034
+ function jobCall(jobId, fn) {
12035
+ const tx = new Transaction();
12036
+ tx.moveCall({
12037
+ target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE}::${fn}`,
12038
+ typeArguments: [USDC_TYPE],
12039
+ arguments: [tx.object(jobId), tx.object(CLOCK_ID2)]
12040
+ });
12041
+ return tx;
12042
+ }
12043
+ function buildDeliverJobTx(jobId, deliveryHash) {
12044
+ const tx = new Transaction();
12045
+ tx.moveCall({
12046
+ target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE}::deliver`,
12047
+ typeArguments: [USDC_TYPE],
12048
+ arguments: [
12049
+ tx.object(jobId),
12050
+ tx.pure.vector("u8", hexToBytes22(deliveryHash)),
12051
+ tx.object(CLOCK_ID2)
12052
+ ]
12053
+ });
12054
+ return tx;
12055
+ }
12056
+ function buildReleaseJobTx(jobId) {
12057
+ return jobCall(jobId, "release");
12058
+ }
12059
+ function buildRejectJobTx(jobId) {
12060
+ return jobCall(jobId, "reject");
12061
+ }
12062
+ function buildRefundJobTx(jobId) {
12063
+ return jobCall(jobId, "refund");
12064
+ }
12065
+ async function getJob(client, jobId) {
12066
+ const resp = await client.core.getObject({ objectId: jobId, include: { json: true } }).catch((e) => {
12067
+ throw new T2000Error(
12068
+ "RPC_ERROR",
12069
+ `Job ${jobId} not found: ${e instanceof Error ? e.message : String(e)}`
12070
+ );
12071
+ });
12072
+ const objType = resp.object?.type ?? "";
12073
+ const json = resp.object?.json;
12074
+ if (!json || !objType.includes(`::${MODULE}::Job<`)) {
12075
+ throw new T2000Error("RPC_ERROR", `Object ${jobId} is not an a2a_escrow Job.`);
12076
+ }
12077
+ const stateNum = Number(json.state ?? -1);
12078
+ const state = JOB_STATES[stateNum];
12079
+ if (!state) {
12080
+ throw new T2000Error("RPC_ERROR", `Job ${jobId} has unknown state ${stateNum}.`);
12081
+ }
12082
+ const deliveredAtMs = Number(json.delivered_at_ms ?? 0);
12083
+ const deliveryBytes = json.delivery_hash ?? [];
12084
+ const hasDelivery = deliveredAtMs > 0;
12085
+ return {
12086
+ id: jobId,
12087
+ buyer: String(json.buyer),
12088
+ seller: String(json.seller),
12089
+ amountUsdc: Number(json.amount) / 10 ** USDC_DECIMALS,
12090
+ escrowUsdc: Number(json.escrow) / 10 ** USDC_DECIMALS,
12091
+ specHash: bytesToHex22(json.spec_hash ?? []),
12092
+ deliverByMs: Number(json.deliver_by_ms),
12093
+ reviewWindowMs: Number(json.review_window_ms),
12094
+ rejectSplitBps: Number(json.reject_split_bps),
12095
+ state,
12096
+ deliveryHash: hasDelivery ? bytesToHex22(deliveryBytes) : null,
12097
+ deliveredAtMs: hasDelivery ? deliveredAtMs : null,
12098
+ createdAtMs: Number(json.created_at_ms)
12099
+ };
12100
+ }
12101
+ function jobActionsFor(job, caller, nowMs = Date.now()) {
12102
+ const me = validateAddress(caller);
12103
+ const isBuyer = me === job.buyer;
12104
+ const isSeller = me === job.seller;
12105
+ const actions = [];
12106
+ if (job.state === "funded") {
12107
+ if (isSeller && nowMs <= job.deliverByMs) actions.push("deliver");
12108
+ if (isBuyer) actions.push("release");
12109
+ if (nowMs > job.deliverByMs) actions.push("refund");
12110
+ } else if (job.state === "delivered") {
12111
+ const windowClosesMs = (job.deliveredAtMs ?? 0) + job.reviewWindowMs;
12112
+ if (isBuyer && nowMs <= windowClosesMs) actions.push("release", "reject");
12113
+ if (nowMs > windowClosesMs) actions.push("release");
12114
+ }
12115
+ return actions;
12116
+ }
12117
+ async function verifyJobForSeller({
12118
+ client,
12119
+ jobId,
12120
+ seller,
12121
+ minAmountUsdc,
12122
+ minRunwayMs = 6e4
12123
+ }) {
12124
+ const job = await getJob(client, jobId);
12125
+ const problems = [];
12126
+ if (job.state !== "funded") {
12127
+ problems.push(`state is "${job.state}", expected "funded"`);
12128
+ }
12129
+ if (job.seller !== validateAddress(seller)) {
12130
+ problems.push(`job pays ${job.seller}, not this seller`);
12131
+ }
12132
+ if (job.escrowUsdc < minAmountUsdc) {
12133
+ problems.push(`escrow holds ${job.escrowUsdc} USDC, price is ${minAmountUsdc}`);
12134
+ }
12135
+ if (job.deliverByMs - Date.now() < minRunwayMs) {
12136
+ problems.push("deadline too close to accept");
12137
+ }
12138
+ return { ok: problems.length === 0, job, problems };
12139
+ }
11932
12140
  init_coinSelection();
11933
12141
  init_cetus_swap();
11934
12142
  init_coinSelection();
@@ -12478,6 +12686,18 @@ export {
12478
12686
  assertLimitConfig,
12479
12687
  LimitEnforcer,
12480
12688
  T2000,
12689
+ A2A_ESCROW_PACKAGE_ID,
12690
+ MAX_JOB_USDC,
12691
+ JOB_STATES,
12692
+ preflightCreateJob,
12693
+ buildCreateJobTx,
12694
+ buildDeliverJobTx,
12695
+ buildReleaseJobTx,
12696
+ buildRejectJobTx,
12697
+ buildRefundJobTx,
12698
+ getJob,
12699
+ jobActionsFor,
12700
+ verifyJobForSeller,
12481
12701
  SPONSORED_PYTH_DEPENDENT_PROVIDERS,
12482
12702
  getSponsoredSwapProviders,
12483
12703
  WRITE_APPENDER_REGISTRY,
@@ -12517,4 +12737,4 @@ export {
12517
12737
  @scure/bip39/index.js:
12518
12738
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12519
12739
  */
12520
- //# sourceMappingURL=chunk-HP5E2AUH.js.map
12740
+ //# sourceMappingURL=chunk-HCEFAB2I.js.map