@t2000/sdk 4.2.2 → 4.3.1
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/browser.cjs +101 -2
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +100 -3
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +98 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -81
- package/dist/index.js.map +1 -1
- package/dist/{types-CElCPOFA.d.ts → types-CFV4VcJJ.d.cts} +102 -86
- package/dist/{types-BjvEpkwT.d.cts → types-DqRLGfOC.d.ts} +102 -86
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1402,6 +1402,27 @@ var KeypairSigner = class {
|
|
|
1402
1402
|
}
|
|
1403
1403
|
};
|
|
1404
1404
|
|
|
1405
|
+
// src/wallet/executeTx.ts
|
|
1406
|
+
async function executeTx(client, signer, buildTx, options = {}) {
|
|
1407
|
+
const tx = await buildTx();
|
|
1408
|
+
tx.setSender(signer.getAddress());
|
|
1409
|
+
const txBytes = await tx.build({ client: options.buildClient ?? client });
|
|
1410
|
+
const { signature } = await signer.signTransaction(txBytes);
|
|
1411
|
+
const result = await client.executeTransactionBlock({
|
|
1412
|
+
transactionBlock: txBytes,
|
|
1413
|
+
signature,
|
|
1414
|
+
options: { showEffects: true }
|
|
1415
|
+
});
|
|
1416
|
+
await client.waitForTransaction({ digest: result.digest });
|
|
1417
|
+
const gasUsed = result.effects?.gasUsed;
|
|
1418
|
+
let gasCostSui = 0;
|
|
1419
|
+
if (gasUsed) {
|
|
1420
|
+
const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
1421
|
+
gasCostSui = Number(total) / 1e9;
|
|
1422
|
+
}
|
|
1423
|
+
return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1405
1426
|
// src/mpp-cost.ts
|
|
1406
1427
|
function parseChallengeAmount(challenge) {
|
|
1407
1428
|
const raw = challenge?.request?.amount;
|
|
@@ -1409,6 +1430,66 @@ function parseChallengeAmount(challenge) {
|
|
|
1409
1430
|
return Number.isFinite(n) ? n : void 0;
|
|
1410
1431
|
}
|
|
1411
1432
|
|
|
1433
|
+
// src/wallet/pay.ts
|
|
1434
|
+
async function payWithMpp(args) {
|
|
1435
|
+
const { signer, client, options } = args;
|
|
1436
|
+
const { Mppx } = await import('mppx/client');
|
|
1437
|
+
const { sui, USDC } = await import('@suimpp/mpp/client');
|
|
1438
|
+
const { SuiGrpcClient: SuiGrpcClient2 } = await import('@mysten/sui/grpc');
|
|
1439
|
+
const signerAddress = signer.getAddress();
|
|
1440
|
+
let paymentDigest;
|
|
1441
|
+
let gasCostSui = 0;
|
|
1442
|
+
let chargedAmount;
|
|
1443
|
+
const network = client.network === "testnet" ? "testnet" : "mainnet";
|
|
1444
|
+
const grpcBaseUrl = network === "testnet" ? "https://fullnode.testnet.sui.io" : "https://fullnode.mainnet.sui.io";
|
|
1445
|
+
const grpcClient = new SuiGrpcClient2({ baseUrl: grpcBaseUrl, network });
|
|
1446
|
+
const mppx = Mppx.create({
|
|
1447
|
+
polyfill: false,
|
|
1448
|
+
onChallenge: async (challenge) => {
|
|
1449
|
+
const parsed = parseChallengeAmount(challenge);
|
|
1450
|
+
if (parsed !== void 0) chargedAmount = parsed;
|
|
1451
|
+
return void 0;
|
|
1452
|
+
},
|
|
1453
|
+
methods: [sui({
|
|
1454
|
+
client,
|
|
1455
|
+
currency: USDC,
|
|
1456
|
+
signer: {
|
|
1457
|
+
toSuiAddress: () => signerAddress,
|
|
1458
|
+
signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
|
|
1459
|
+
},
|
|
1460
|
+
execute: async (tx) => {
|
|
1461
|
+
const result = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
1462
|
+
paymentDigest = result.digest;
|
|
1463
|
+
gasCostSui = result.gasCostSui;
|
|
1464
|
+
return { digest: result.digest };
|
|
1465
|
+
}
|
|
1466
|
+
})]
|
|
1467
|
+
});
|
|
1468
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
1469
|
+
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
1470
|
+
const response = await mppx.fetch(options.url, {
|
|
1471
|
+
method,
|
|
1472
|
+
headers: options.headers,
|
|
1473
|
+
body: canHaveBody ? options.body : void 0
|
|
1474
|
+
});
|
|
1475
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1476
|
+
let body;
|
|
1477
|
+
try {
|
|
1478
|
+
body = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
1479
|
+
} catch {
|
|
1480
|
+
body = null;
|
|
1481
|
+
}
|
|
1482
|
+
const paid = !!paymentDigest;
|
|
1483
|
+
return {
|
|
1484
|
+
status: response.status,
|
|
1485
|
+
body,
|
|
1486
|
+
paid,
|
|
1487
|
+
cost: paid ? chargedAmount ?? options.maxPrice ?? void 0 : void 0,
|
|
1488
|
+
gasCostSui: paid ? gasCostSui : void 0,
|
|
1489
|
+
receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1412
1493
|
// src/wallet/zkLoginSigner.ts
|
|
1413
1494
|
var ZkLoginSigner = class {
|
|
1414
1495
|
constructor(ephemeralKeypair, zkProof, userAddress, maxEpoch) {
|
|
@@ -1431,8 +1512,17 @@ var ZkLoginSigner = class {
|
|
|
1431
1512
|
})
|
|
1432
1513
|
};
|
|
1433
1514
|
}
|
|
1434
|
-
async signPersonalMessage(
|
|
1435
|
-
|
|
1515
|
+
async signPersonalMessage(messageBytes) {
|
|
1516
|
+
const { getZkLoginSignature } = await import('@mysten/zklogin');
|
|
1517
|
+
const { signature: ephSig, bytes } = await this.ephemeralKeypair.signPersonalMessage(messageBytes);
|
|
1518
|
+
return {
|
|
1519
|
+
signature: getZkLoginSignature({
|
|
1520
|
+
inputs: this.zkProof,
|
|
1521
|
+
maxEpoch: this.maxEpoch,
|
|
1522
|
+
userSignature: ephSig
|
|
1523
|
+
}),
|
|
1524
|
+
bytes
|
|
1525
|
+
};
|
|
1436
1526
|
}
|
|
1437
1527
|
isExpired(currentEpoch) {
|
|
1438
1528
|
return currentEpoch >= this.maxEpoch;
|
|
@@ -6521,25 +6611,6 @@ var ContactManager = class {
|
|
|
6521
6611
|
}
|
|
6522
6612
|
};
|
|
6523
6613
|
var DEFAULT_CONFIG_DIR = path.join(os.homedir(), ".t2000");
|
|
6524
|
-
async function executeTx(client, signer, buildTx, options = {}) {
|
|
6525
|
-
const tx = await buildTx();
|
|
6526
|
-
tx.setSender(signer.getAddress());
|
|
6527
|
-
const txBytes = await tx.build({ client: options.buildClient ?? client });
|
|
6528
|
-
const { signature } = await signer.signTransaction(txBytes);
|
|
6529
|
-
const result = await client.executeTransactionBlock({
|
|
6530
|
-
transactionBlock: txBytes,
|
|
6531
|
-
signature,
|
|
6532
|
-
options: { showEffects: true }
|
|
6533
|
-
});
|
|
6534
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
6535
|
-
const gasUsed = result.effects?.gasUsed;
|
|
6536
|
-
let gasCostSui = 0;
|
|
6537
|
-
if (gasUsed) {
|
|
6538
|
-
const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
6539
|
-
gasCostSui = Number(total) / 1e9;
|
|
6540
|
-
}
|
|
6541
|
-
return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
|
|
6542
|
-
}
|
|
6543
6614
|
var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
6544
6615
|
_signer;
|
|
6545
6616
|
_keypair;
|
|
@@ -6619,66 +6690,11 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6619
6690
|
async pay(options) {
|
|
6620
6691
|
this.enforcer.assertNotLocked();
|
|
6621
6692
|
this.enforcer.check({ operation: "pay", amount: options.maxPrice ?? 1 });
|
|
6622
|
-
const
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
const client = this.client;
|
|
6626
|
-
const signer = this._signer;
|
|
6627
|
-
const signerAddress = signer.getAddress();
|
|
6628
|
-
let paymentDigest;
|
|
6629
|
-
let gasCostSui = 0;
|
|
6630
|
-
let chargedAmount;
|
|
6631
|
-
const network = client.network === "testnet" ? "testnet" : "mainnet";
|
|
6632
|
-
const grpcBaseUrl = network === "testnet" ? "https://fullnode.testnet.sui.io" : "https://fullnode.mainnet.sui.io";
|
|
6633
|
-
const grpcClient = new SuiGrpcClient2({ baseUrl: grpcBaseUrl, network });
|
|
6634
|
-
const mppx = Mppx.create({
|
|
6635
|
-
polyfill: false,
|
|
6636
|
-
onChallenge: async (challenge) => {
|
|
6637
|
-
const parsed = parseChallengeAmount(challenge);
|
|
6638
|
-
if (parsed !== void 0) chargedAmount = parsed;
|
|
6639
|
-
return void 0;
|
|
6640
|
-
},
|
|
6641
|
-
methods: [sui({
|
|
6642
|
-
client,
|
|
6643
|
-
currency: USDC,
|
|
6644
|
-
signer: {
|
|
6645
|
-
toSuiAddress: () => signerAddress,
|
|
6646
|
-
signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
|
|
6647
|
-
},
|
|
6648
|
-
execute: async (tx) => {
|
|
6649
|
-
const result = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
6650
|
-
paymentDigest = result.digest;
|
|
6651
|
-
gasCostSui = result.gasCostSui;
|
|
6652
|
-
return { digest: result.digest };
|
|
6653
|
-
}
|
|
6654
|
-
})]
|
|
6655
|
-
});
|
|
6656
|
-
const method = (options.method ?? "GET").toUpperCase();
|
|
6657
|
-
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
6658
|
-
const response = await mppx.fetch(options.url, {
|
|
6659
|
-
method,
|
|
6660
|
-
headers: options.headers,
|
|
6661
|
-
body: canHaveBody ? options.body : void 0
|
|
6662
|
-
});
|
|
6663
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
6664
|
-
let body;
|
|
6665
|
-
try {
|
|
6666
|
-
body = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
6667
|
-
} catch {
|
|
6668
|
-
body = null;
|
|
6693
|
+
const result = await payWithMpp({ signer: this._signer, client: this.client, options });
|
|
6694
|
+
if (result.paid) {
|
|
6695
|
+
this.enforcer.recordUsage(result.cost ?? options.maxPrice ?? 1);
|
|
6669
6696
|
}
|
|
6670
|
-
|
|
6671
|
-
if (paid) {
|
|
6672
|
-
this.enforcer.recordUsage(chargedAmount ?? options.maxPrice ?? 1);
|
|
6673
|
-
}
|
|
6674
|
-
return {
|
|
6675
|
-
status: response.status,
|
|
6676
|
-
body,
|
|
6677
|
-
paid,
|
|
6678
|
-
cost: paid ? chargedAmount ?? options.maxPrice ?? void 0 : void 0,
|
|
6679
|
-
gasCostSui: paid ? gasCostSui : void 0,
|
|
6680
|
-
receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
|
|
6681
|
-
};
|
|
6697
|
+
return result;
|
|
6682
6698
|
}
|
|
6683
6699
|
// [S.323 / 2026-05-25] VOLO vSUI staking surfaces removed (full cut).
|
|
6684
6700
|
// Engine cut Volo in S.277; SDK + CLI + MCP followed in S.323 because the
|
|
@@ -8650,6 +8666,7 @@ exports.createSuiClient = createSuiClient;
|
|
|
8650
8666
|
exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
|
|
8651
8667
|
exports.deserializeCetusRoute = deserializeCetusRoute;
|
|
8652
8668
|
exports.displayHandle = displayHandle;
|
|
8669
|
+
exports.executeTx = executeTx;
|
|
8653
8670
|
exports.exportPrivateKey = exportPrivateKey;
|
|
8654
8671
|
exports.extractAllUserLegs = extractAllUserLegs;
|
|
8655
8672
|
exports.extractTransferDetails = extractTransferDetails;
|
|
@@ -8693,6 +8710,7 @@ exports.normalizeAddressInput = normalizeAddressInput;
|
|
|
8693
8710
|
exports.normalizeAsset = normalizeAsset;
|
|
8694
8711
|
exports.normalizeCoinType = normalizeCoinType;
|
|
8695
8712
|
exports.parseSuiRpcTx = parseSuiRpcTx;
|
|
8713
|
+
exports.payWithMpp = payWithMpp;
|
|
8696
8714
|
exports.queryHistory = queryHistory;
|
|
8697
8715
|
exports.queryTransaction = queryTransaction;
|
|
8698
8716
|
exports.rawToStable = rawToStable;
|