@t2000/cli 4.2.2 → 4.3.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.
package/dist/index.js CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  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);
3
+ import {
4
+ SIGNATURE_FLAG_TO_SCHEME,
5
+ SIGNATURE_SCHEME_TO_FLAG,
6
+ SIGNATURE_SCHEME_TO_SIZE
7
+ } from "./chunk-634W6JCI.js";
3
8
  import {
4
9
  AggregatorClient,
5
10
  Env,
@@ -27,11 +32,6 @@ import {
27
32
  init_bcs,
28
33
  suiBcs
29
34
  } from "./chunk-24QPX3VK.js";
30
- import {
31
- SIGNATURE_FLAG_TO_SCHEME,
32
- SIGNATURE_SCHEME_TO_FLAG,
33
- SIGNATURE_SCHEME_TO_SIZE
34
- } from "./chunk-634W6JCI.js";
35
35
  import {
36
36
  HashMD,
37
37
  SHA512_IV,
@@ -35686,11 +35686,88 @@ var KeypairSigner = class {
35686
35686
  return this.keypair;
35687
35687
  }
35688
35688
  };
35689
+ async function executeTx(client, signer, buildTx, options = {}) {
35690
+ const tx = await buildTx();
35691
+ tx.setSender(signer.getAddress());
35692
+ const txBytes = await tx.build({ client: options.buildClient ?? client });
35693
+ const { signature } = await signer.signTransaction(txBytes);
35694
+ const result = await client.executeTransactionBlock({
35695
+ transactionBlock: txBytes,
35696
+ signature,
35697
+ options: { showEffects: true }
35698
+ });
35699
+ await client.waitForTransaction({ digest: result.digest });
35700
+ const gasUsed = result.effects?.gasUsed;
35701
+ let gasCostSui = 0;
35702
+ if (gasUsed) {
35703
+ const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
35704
+ gasCostSui = Number(total) / 1e9;
35705
+ }
35706
+ return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
35707
+ }
35689
35708
  function parseChallengeAmount(challenge) {
35690
35709
  const raw = challenge?.request?.amount;
35691
35710
  const n = typeof raw === "string" ? Number(raw) : typeof raw === "number" ? raw : Number.NaN;
35692
35711
  return Number.isFinite(n) ? n : void 0;
35693
35712
  }
35713
+ async function payWithMpp(args) {
35714
+ const { signer, client, options } = args;
35715
+ const { Mppx } = await import("./client-BG6M6WUI.js");
35716
+ const { sui, USDC } = await import("./client-UCPLLOGQ.js");
35717
+ const { SuiGrpcClient: SuiGrpcClient2 } = await import("./grpc-RHG6ARHV.js");
35718
+ const signerAddress = signer.getAddress();
35719
+ let paymentDigest;
35720
+ let gasCostSui = 0;
35721
+ let chargedAmount;
35722
+ const network = client.network === "testnet" ? "testnet" : "mainnet";
35723
+ const grpcBaseUrl = network === "testnet" ? "https://fullnode.testnet.sui.io" : "https://fullnode.mainnet.sui.io";
35724
+ const grpcClient = new SuiGrpcClient2({ baseUrl: grpcBaseUrl, network });
35725
+ const mppx = Mppx.create({
35726
+ polyfill: false,
35727
+ onChallenge: async (challenge) => {
35728
+ const parsed = parseChallengeAmount(challenge);
35729
+ if (parsed !== void 0) chargedAmount = parsed;
35730
+ return void 0;
35731
+ },
35732
+ methods: [sui({
35733
+ client,
35734
+ currency: USDC,
35735
+ signer: {
35736
+ toSuiAddress: () => signerAddress,
35737
+ signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
35738
+ },
35739
+ execute: async (tx) => {
35740
+ const result = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
35741
+ paymentDigest = result.digest;
35742
+ gasCostSui = result.gasCostSui;
35743
+ return { digest: result.digest };
35744
+ }
35745
+ })]
35746
+ });
35747
+ const method = (options.method ?? "GET").toUpperCase();
35748
+ const canHaveBody = method !== "GET" && method !== "HEAD";
35749
+ const response = await mppx.fetch(options.url, {
35750
+ method,
35751
+ headers: options.headers,
35752
+ body: canHaveBody ? options.body : void 0
35753
+ });
35754
+ const contentType = response.headers.get("content-type") ?? "";
35755
+ let body;
35756
+ try {
35757
+ body = contentType.includes("application/json") ? await response.json() : await response.text();
35758
+ } catch {
35759
+ body = null;
35760
+ }
35761
+ const paid = !!paymentDigest;
35762
+ return {
35763
+ status: response.status,
35764
+ body,
35765
+ paid,
35766
+ cost: paid ? chargedAmount ?? options.maxPrice ?? void 0 : void 0,
35767
+ gasCostSui: paid ? gasCostSui : void 0,
35768
+ receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
35769
+ };
35770
+ }
35694
35771
  var ZkLoginSigner = class {
35695
35772
  constructor(ephemeralKeypair, zkProof, userAddress, maxEpoch) {
35696
35773
  this.ephemeralKeypair = ephemeralKeypair;
@@ -35712,8 +35789,17 @@ var ZkLoginSigner = class {
35712
35789
  })
35713
35790
  };
35714
35791
  }
35715
- async signPersonalMessage(_messageBytes) {
35716
- throw new Error("ZkLoginSigner.signPersonalMessage is not yet implemented. Use KeypairSigner for sdk.pay() until grief-protection signing is wired for zkLogin.");
35792
+ async signPersonalMessage(messageBytes) {
35793
+ const { getZkLoginSignature } = await import("./esm-SWUQQCXL.js");
35794
+ const { signature: ephSig, bytes } = await this.ephemeralKeypair.signPersonalMessage(messageBytes);
35795
+ return {
35796
+ signature: getZkLoginSignature({
35797
+ inputs: this.zkProof,
35798
+ maxEpoch: this.maxEpoch,
35799
+ userSignature: ephSig
35800
+ }),
35801
+ bytes
35802
+ };
35717
35803
  }
35718
35804
  isExpired(currentEpoch) {
35719
35805
  return currentEpoch >= this.maxEpoch;
@@ -40588,25 +40674,6 @@ var ContactManager = class {
40588
40674
  }
40589
40675
  };
40590
40676
  var DEFAULT_CONFIG_DIR = join$1(homedir(), ".t2000");
40591
- async function executeTx(client, signer, buildTx, options = {}) {
40592
- const tx = await buildTx();
40593
- tx.setSender(signer.getAddress());
40594
- const txBytes = await tx.build({ client: options.buildClient ?? client });
40595
- const { signature } = await signer.signTransaction(txBytes);
40596
- const result = await client.executeTransactionBlock({
40597
- transactionBlock: txBytes,
40598
- signature,
40599
- options: { showEffects: true }
40600
- });
40601
- await client.waitForTransaction({ digest: result.digest });
40602
- const gasUsed = result.effects?.gasUsed;
40603
- let gasCostSui = 0;
40604
- if (gasUsed) {
40605
- const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
40606
- gasCostSui = Number(total) / 1e9;
40607
- }
40608
- return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
40609
- }
40610
40677
  var T2000 = class _T2000 extends import_index2.default {
40611
40678
  _signer;
40612
40679
  _keypair;
@@ -40686,66 +40753,11 @@ var T2000 = class _T2000 extends import_index2.default {
40686
40753
  async pay(options) {
40687
40754
  this.enforcer.assertNotLocked();
40688
40755
  this.enforcer.check({ operation: "pay", amount: options.maxPrice ?? 1 });
40689
- const { Mppx } = await import("./client-BG6M6WUI.js");
40690
- const { sui, USDC } = await import("./client-3JAUHH6P.js");
40691
- const { SuiGrpcClient: SuiGrpcClient2 } = await import("./grpc-RHG6ARHV.js");
40692
- const client = this.client;
40693
- const signer = this._signer;
40694
- const signerAddress = signer.getAddress();
40695
- let paymentDigest;
40696
- let gasCostSui = 0;
40697
- let chargedAmount;
40698
- const network = client.network === "testnet" ? "testnet" : "mainnet";
40699
- const grpcBaseUrl = network === "testnet" ? "https://fullnode.testnet.sui.io" : "https://fullnode.mainnet.sui.io";
40700
- const grpcClient = new SuiGrpcClient2({ baseUrl: grpcBaseUrl, network });
40701
- const mppx = Mppx.create({
40702
- polyfill: false,
40703
- onChallenge: async (challenge) => {
40704
- const parsed = parseChallengeAmount(challenge);
40705
- if (parsed !== void 0) chargedAmount = parsed;
40706
- return void 0;
40707
- },
40708
- methods: [sui({
40709
- client,
40710
- currency: USDC,
40711
- signer: {
40712
- toSuiAddress: () => signerAddress,
40713
- signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
40714
- },
40715
- execute: async (tx) => {
40716
- const result = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
40717
- paymentDigest = result.digest;
40718
- gasCostSui = result.gasCostSui;
40719
- return { digest: result.digest };
40720
- }
40721
- })]
40722
- });
40723
- const method = (options.method ?? "GET").toUpperCase();
40724
- const canHaveBody = method !== "GET" && method !== "HEAD";
40725
- const response = await mppx.fetch(options.url, {
40726
- method,
40727
- headers: options.headers,
40728
- body: canHaveBody ? options.body : void 0
40729
- });
40730
- const contentType = response.headers.get("content-type") ?? "";
40731
- let body;
40732
- try {
40733
- body = contentType.includes("application/json") ? await response.json() : await response.text();
40734
- } catch {
40735
- body = null;
40736
- }
40737
- const paid = !!paymentDigest;
40738
- if (paid) {
40739
- this.enforcer.recordUsage(chargedAmount ?? options.maxPrice ?? 1);
40756
+ const result = await payWithMpp({ signer: this._signer, client: this.client, options });
40757
+ if (result.paid) {
40758
+ this.enforcer.recordUsage(result.cost ?? options.maxPrice ?? 1);
40740
40759
  }
40741
- return {
40742
- status: response.status,
40743
- body,
40744
- paid,
40745
- cost: paid ? chargedAmount ?? options.maxPrice ?? void 0 : void 0,
40746
- gasCostSui: paid ? gasCostSui : void 0,
40747
- receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
40748
- };
40760
+ return result;
40749
40761
  }
40750
40762
  // [S.323 / 2026-05-25] VOLO vSUI staking surfaces removed (full cut).
40751
40763
  // Engine cut Volo in S.277; SDK + CLI + MCP followed in S.323 because the
@@ -45335,7 +45347,7 @@ function registerMcpStart(parent) {
45335
45347
  parent.command("start", { isDefault: true }).description("Start MCP server (stdio transport \u2014 for AI client integration)").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").action(async (opts) => {
45336
45348
  let mod2;
45337
45349
  try {
45338
- mod2 = await import("./dist-FS73FEVZ.js");
45350
+ mod2 = await import("./dist-ELFUROC5.js");
45339
45351
  } catch {
45340
45352
  console.error("MCP server not installed. Run:\n npm install -g @t2000/mcp");
45341
45353
  process.exit(1);