@zeroxyz/cli 1.19.0 → 1.20.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 +110 -88
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78449,7 +78449,7 @@ init_esm_shims();
|
|
|
78449
78449
|
// ../sdk/dist/index.js
|
|
78450
78450
|
init_esm_shims();
|
|
78451
78451
|
|
|
78452
|
-
// ../sdk/dist/chunk-
|
|
78452
|
+
// ../sdk/dist/chunk-FWHVWIO2.js
|
|
78453
78453
|
init_esm_shims();
|
|
78454
78454
|
|
|
78455
78455
|
// ../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/index.js
|
|
@@ -117572,69 +117572,6 @@ function createSIWxClientHook(signer) {
|
|
|
117572
117572
|
};
|
|
117573
117573
|
}
|
|
117574
117574
|
|
|
117575
|
-
// ../../node_modules/.pnpm/@x402+fetch@2.9.0_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@x402/fetch/dist/esm/index.mjs
|
|
117576
|
-
init_esm_shims();
|
|
117577
|
-
function wrapFetchWithPayment(fetch2, client) {
|
|
117578
|
-
const httpClient = client instanceof x402HTTPClient ? client : new x402HTTPClient(client);
|
|
117579
|
-
return async (input, init) => {
|
|
117580
|
-
const request3 = new Request(input, init);
|
|
117581
|
-
const clonedRequest = request3.clone();
|
|
117582
|
-
const response = await fetch2(request3);
|
|
117583
|
-
if (response.status !== 402) {
|
|
117584
|
-
return response;
|
|
117585
|
-
}
|
|
117586
|
-
let paymentRequired;
|
|
117587
|
-
try {
|
|
117588
|
-
const getHeader = (name) => response.headers.get(name);
|
|
117589
|
-
let body;
|
|
117590
|
-
try {
|
|
117591
|
-
const responseText = await response.text();
|
|
117592
|
-
if (responseText) {
|
|
117593
|
-
body = JSON.parse(responseText);
|
|
117594
|
-
}
|
|
117595
|
-
} catch {
|
|
117596
|
-
}
|
|
117597
|
-
paymentRequired = httpClient.getPaymentRequiredResponse(getHeader, body);
|
|
117598
|
-
} catch (error48) {
|
|
117599
|
-
throw new Error(
|
|
117600
|
-
`Failed to parse payment requirements: ${error48 instanceof Error ? error48.message : "Unknown error"}`
|
|
117601
|
-
);
|
|
117602
|
-
}
|
|
117603
|
-
const hookHeaders = await httpClient.handlePaymentRequired(paymentRequired);
|
|
117604
|
-
if (hookHeaders) {
|
|
117605
|
-
const hookRequest = clonedRequest.clone();
|
|
117606
|
-
for (const [key, value] of Object.entries(hookHeaders)) {
|
|
117607
|
-
hookRequest.headers.set(key, value);
|
|
117608
|
-
}
|
|
117609
|
-
const hookResponse = await fetch2(hookRequest);
|
|
117610
|
-
if (hookResponse.status !== 402) {
|
|
117611
|
-
return hookResponse;
|
|
117612
|
-
}
|
|
117613
|
-
}
|
|
117614
|
-
let paymentPayload;
|
|
117615
|
-
try {
|
|
117616
|
-
paymentPayload = await client.createPaymentPayload(paymentRequired);
|
|
117617
|
-
} catch (error48) {
|
|
117618
|
-
throw new Error(
|
|
117619
|
-
`Failed to create payment payload: ${error48 instanceof Error ? error48.message : "Unknown error"}`
|
|
117620
|
-
);
|
|
117621
|
-
}
|
|
117622
|
-
const paymentHeaders = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
117623
|
-
if (clonedRequest.headers.has("PAYMENT-SIGNATURE") || clonedRequest.headers.has("X-PAYMENT")) {
|
|
117624
|
-
throw new Error("Payment already attempted");
|
|
117625
|
-
}
|
|
117626
|
-
for (const [key, value] of Object.entries(paymentHeaders)) {
|
|
117627
|
-
clonedRequest.headers.set(key, value);
|
|
117628
|
-
}
|
|
117629
|
-
clonedRequest.headers.set(
|
|
117630
|
-
"Access-Control-Expose-Headers",
|
|
117631
|
-
"PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
|
|
117632
|
-
);
|
|
117633
|
-
const secondResponse = await fetch2(clonedRequest);
|
|
117634
|
-
return secondResponse;
|
|
117635
|
-
};
|
|
117636
|
-
}
|
|
117637
|
-
|
|
117638
117575
|
// ../../node_modules/.pnpm/mppx@0.6.9_@modelcontextprotocol+sdk@1.29.0_@cfworker+json-schema@4.1.1_zod@4.3.6__expr_0954cd65f6aa59a781b5373f235842da/node_modules/mppx/dist/index.js
|
|
117639
117576
|
init_esm_shims();
|
|
117640
117577
|
|
|
@@ -143831,7 +143768,7 @@ config(en_default2());
|
|
|
143831
143768
|
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/index.js
|
|
143832
143769
|
var zod_default = external_exports3;
|
|
143833
143770
|
|
|
143834
|
-
// ../sdk/dist/chunk-
|
|
143771
|
+
// ../sdk/dist/chunk-FWHVWIO2.js
|
|
143835
143772
|
var createManagedAccount = (client, address2, opts = {}) => {
|
|
143836
143773
|
const signOptions = {
|
|
143837
143774
|
// expectedAddress pins verification to this adapter's frozen address.
|
|
@@ -144497,6 +144434,9 @@ var Payments = class {
|
|
|
144497
144434
|
input.walletAddress
|
|
144498
144435
|
);
|
|
144499
144436
|
let capturedAmount = null;
|
|
144437
|
+
let pendingAmountUnits = 0n;
|
|
144438
|
+
let identityChallengeHandled = false;
|
|
144439
|
+
let paidChallengeHandled = false;
|
|
144500
144440
|
let capturedNetwork;
|
|
144501
144441
|
let preflightError = null;
|
|
144502
144442
|
const x402 = registerExactEvmScheme(new x402Client(), { signer: account });
|
|
@@ -144525,11 +144465,25 @@ var Payments = class {
|
|
|
144525
144465
|
};
|
|
144526
144466
|
}
|
|
144527
144467
|
const rawAmountUnits = BigInt(rawAmount);
|
|
144528
|
-
|
|
144468
|
+
pendingAmountUnits = rawAmountUnits;
|
|
144469
|
+
const challengeAmount = formatUnits(rawAmountUnits, 6);
|
|
144470
|
+
if (rawAmountUnits === 0n) {
|
|
144471
|
+
if (identityChallengeHandled || paidChallengeHandled) {
|
|
144472
|
+
return {
|
|
144473
|
+
abort: true,
|
|
144474
|
+
reason: "Only one zero-value identity challenge is allowed, and it must precede payment."
|
|
144475
|
+
};
|
|
144476
|
+
}
|
|
144477
|
+
} else if (paidChallengeHandled) {
|
|
144478
|
+
return {
|
|
144479
|
+
abort: true,
|
|
144480
|
+
reason: "A positive-value x402 payment was already attempted for this fetch; refusing a second charge."
|
|
144481
|
+
};
|
|
144482
|
+
}
|
|
144529
144483
|
if (maxPayUnits !== null && rawAmountUnits > maxPayUnits) {
|
|
144530
144484
|
return {
|
|
144531
144485
|
abort: true,
|
|
144532
|
-
reason: `Payment of ${
|
|
144486
|
+
reason: `Payment of ${challengeAmount} USDC exceeds maxPay ${input.maxPay}`
|
|
144533
144487
|
};
|
|
144534
144488
|
}
|
|
144535
144489
|
const detected = networkToChain(capturedNetwork);
|
|
@@ -144549,9 +144503,10 @@ var Payments = class {
|
|
|
144549
144503
|
}
|
|
144550
144504
|
if (balance !== null && balance < rawAmountUnits) {
|
|
144551
144505
|
const have = formatUnits(balance, 6);
|
|
144506
|
+
const requiredAmount = formatUnits(rawAmountUnits, 6);
|
|
144552
144507
|
preflightError = new ZeroInsufficientFundsError(
|
|
144553
|
-
`wallet has ${have} USDC on Base, needs ${
|
|
144554
|
-
{ have, need:
|
|
144508
|
+
`wallet has ${have} USDC on Base, needs ${requiredAmount}.`,
|
|
144509
|
+
{ have, need: requiredAmount }
|
|
144555
144510
|
);
|
|
144556
144511
|
return { abort: true, reason: preflightError.message };
|
|
144557
144512
|
}
|
|
@@ -144562,18 +144517,64 @@ var Payments = class {
|
|
|
144562
144517
|
const httpClient = new x402HTTPClient(x402).onPaymentRequired(
|
|
144563
144518
|
createSIWxClientHook(account)
|
|
144564
144519
|
);
|
|
144565
|
-
const
|
|
144566
|
-
withSynthesizedX402Header(configuredFetch),
|
|
144567
|
-
httpClient
|
|
144568
|
-
);
|
|
144520
|
+
const paymentFetch = withSynthesizedX402Header(configuredFetch);
|
|
144569
144521
|
let response;
|
|
144570
144522
|
try {
|
|
144571
|
-
|
|
144523
|
+
const request22 = new Request(input.url, {
|
|
144572
144524
|
method: input.method ?? "GET",
|
|
144573
144525
|
headers: input.headers,
|
|
144574
144526
|
body: input.body,
|
|
144575
144527
|
signal: input.signal
|
|
144576
144528
|
});
|
|
144529
|
+
response = await paymentFetch(request22.clone());
|
|
144530
|
+
for (let paymentStage = 0; paymentStage < 2; paymentStage++) {
|
|
144531
|
+
if (response.status !== 402) break;
|
|
144532
|
+
const parseChallenge = async (challengeResponse) => {
|
|
144533
|
+
let body;
|
|
144534
|
+
try {
|
|
144535
|
+
const text = await challengeResponse.clone().text();
|
|
144536
|
+
if (text) body = JSON.parse(text);
|
|
144537
|
+
} catch {
|
|
144538
|
+
}
|
|
144539
|
+
return httpClient.getPaymentRequiredResponse(
|
|
144540
|
+
(name) => challengeResponse.headers.get(name),
|
|
144541
|
+
body
|
|
144542
|
+
);
|
|
144543
|
+
};
|
|
144544
|
+
let paymentRequired = await parseChallenge(response);
|
|
144545
|
+
const hookHeaders = await httpClient.handlePaymentRequired(paymentRequired);
|
|
144546
|
+
if (hookHeaders) {
|
|
144547
|
+
const hookRequest = request22.clone();
|
|
144548
|
+
for (const [key, value] of Object.entries(hookHeaders)) {
|
|
144549
|
+
hookRequest.headers.set(key, value);
|
|
144550
|
+
}
|
|
144551
|
+
response = await paymentFetch(hookRequest);
|
|
144552
|
+
if (response.status === 402) {
|
|
144553
|
+
paymentRequired = await parseChallenge(response);
|
|
144554
|
+
} else {
|
|
144555
|
+
break;
|
|
144556
|
+
}
|
|
144557
|
+
}
|
|
144558
|
+
pendingAmountUnits = 0n;
|
|
144559
|
+
const paymentPayload = await x402.createPaymentPayload(paymentRequired);
|
|
144560
|
+
if (pendingAmountUnits === 0n) {
|
|
144561
|
+
identityChallengeHandled = true;
|
|
144562
|
+
capturedAmount = "0";
|
|
144563
|
+
} else {
|
|
144564
|
+
paidChallengeHandled = true;
|
|
144565
|
+
capturedAmount = formatUnits(pendingAmountUnits, 6);
|
|
144566
|
+
}
|
|
144567
|
+
const paymentHeaders = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
144568
|
+
const paidRequest = request22.clone();
|
|
144569
|
+
for (const [key, value] of Object.entries(paymentHeaders)) {
|
|
144570
|
+
paidRequest.headers.set(key, value);
|
|
144571
|
+
}
|
|
144572
|
+
paidRequest.headers.set(
|
|
144573
|
+
"Access-Control-Expose-Headers",
|
|
144574
|
+
"PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
|
|
144575
|
+
);
|
|
144576
|
+
response = await paymentFetch(paidRequest);
|
|
144577
|
+
}
|
|
144577
144578
|
} catch (err) {
|
|
144578
144579
|
if (preflightError) throw preflightError;
|
|
144579
144580
|
if (err instanceof ZeroError) throw err;
|
|
@@ -145141,8 +145142,17 @@ var cancelBody2 = (response) => {
|
|
|
145141
145142
|
} catch {
|
|
145142
145143
|
}
|
|
145143
145144
|
};
|
|
145144
|
-
var detectPaymentRequirement = async (response) => {
|
|
145145
|
+
var detectPaymentRequirement = async (response, preferredProtocol) => {
|
|
145145
145146
|
if (response.status !== 402) return null;
|
|
145147
|
+
const wwwAuth = response.headers.get("www-authenticate");
|
|
145148
|
+
const advertisesMpp = wwwAuth ? splitWwwAuthenticateChallenges(wwwAuth).some((challenge2) => {
|
|
145149
|
+
const scheme = challenge2.trim().split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
145150
|
+
return MPP_SCHEME_TOKENS.has(scheme);
|
|
145151
|
+
}) : false;
|
|
145152
|
+
if (preferredProtocol === "mpp") {
|
|
145153
|
+
cancelBody2(response);
|
|
145154
|
+
return advertisesMpp ? { protocol: "mpp", raw: { "www-authenticate": wwwAuth } } : { protocol: "unknown", raw: { requestedProtocol: "mpp" } };
|
|
145155
|
+
}
|
|
145146
145156
|
const x402Header = response.headers.get("payment-required") ?? response.headers.get("x-payment-required");
|
|
145147
145157
|
if (x402Header) {
|
|
145148
145158
|
cancelBody2(response);
|
|
@@ -145172,15 +145182,13 @@ var detectPaymentRequirement = async (response) => {
|
|
|
145172
145182
|
} catch {
|
|
145173
145183
|
}
|
|
145174
145184
|
}
|
|
145175
|
-
|
|
145176
|
-
|
|
145177
|
-
|
|
145178
|
-
|
|
145179
|
-
|
|
145180
|
-
|
|
145181
|
-
|
|
145182
|
-
return { protocol: "mpp", raw: { "www-authenticate": wwwAuth } };
|
|
145183
|
-
}
|
|
145185
|
+
if (preferredProtocol === "x402") {
|
|
145186
|
+
cancelBody2(response);
|
|
145187
|
+
return { protocol: "unknown", raw: { requestedProtocol: "x402" } };
|
|
145188
|
+
}
|
|
145189
|
+
if (advertisesMpp) {
|
|
145190
|
+
cancelBody2(response);
|
|
145191
|
+
return { protocol: "mpp", raw: { "www-authenticate": wwwAuth } };
|
|
145184
145192
|
}
|
|
145185
145193
|
cancelBody2(response);
|
|
145186
145194
|
return { protocol: "unknown", raw: {} };
|
|
@@ -145506,7 +145514,10 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
145506
145514
|
return result2;
|
|
145507
145515
|
}
|
|
145508
145516
|
if (response.status === 402) {
|
|
145509
|
-
const requirement = await detectPaymentRequirement(
|
|
145517
|
+
const requirement = await detectPaymentRequirement(
|
|
145518
|
+
response,
|
|
145519
|
+
opts.paymentProtocol
|
|
145520
|
+
);
|
|
145510
145521
|
if (requirement?.protocol === "x402" || requirement?.protocol === "mpp") {
|
|
145511
145522
|
const payCall = requirement.protocol === "x402" ? client.payments.pay : client.payments.payMpp;
|
|
145512
145523
|
try {
|
|
@@ -145578,7 +145589,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
145578
145589
|
} else if (requirement?.protocol === "unknown") {
|
|
145579
145590
|
const result2 = errorFetchResult(
|
|
145580
145591
|
startedAt,
|
|
145581
|
-
"Capability returned 402 with an unrecognized payment protocol. Neither x402 nor MPP markers were detected in the response headers or body.",
|
|
145592
|
+
opts.paymentProtocol ? `Capability did not advertise the requested ${opts.paymentProtocol} payment protocol.` : "Capability returned 402 with an unrecognized payment protocol. Neither x402 nor MPP markers were detected in the response headers or body.",
|
|
145582
145593
|
"unrecognized_402_protocol",
|
|
145583
145594
|
capabilityIdRequested,
|
|
145584
145595
|
"payment_failed",
|
|
@@ -145760,7 +145771,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
145760
145771
|
return result;
|
|
145761
145772
|
};
|
|
145762
145773
|
var package_default = {
|
|
145763
|
-
version: "0.
|
|
145774
|
+
version: "0.14.0"
|
|
145764
145775
|
};
|
|
145765
145776
|
var SDK_VERSION2 = package_default.version;
|
|
145766
145777
|
var agentAuthMetadataSchema = external_exports3.object({
|
|
@@ -147902,7 +147913,7 @@ var placeholderFor = (fieldName, propSchema) => String(sampleValueFor(fieldName,
|
|
|
147902
147913
|
|
|
147903
147914
|
// package.json
|
|
147904
147915
|
var package_default2 = {
|
|
147905
|
-
version: "1.
|
|
147916
|
+
version: "1.20.0"};
|
|
147906
147917
|
|
|
147907
147918
|
// src/app.ts
|
|
147908
147919
|
init_esm_shims();
|
|
@@ -149528,6 +149539,9 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
149528
149539
|
"--data-stdin",
|
|
149529
149540
|
"Read the request body from stdin (equivalent to `-d @-`)."
|
|
149530
149541
|
).option("-H, --header <header...>", "Headers in Key:Value format").option("--max-pay <amount>", "Maximum per-call spend limit (USDC)").option(
|
|
149542
|
+
"--protocol <protocol>",
|
|
149543
|
+
"Force payment protocol when multiple are offered (x402 or mpp)"
|
|
149544
|
+
).option(
|
|
149531
149545
|
"--wallet-address <address>",
|
|
149532
149546
|
"Pay/sign from this profile wallet instead of the primary (managed signing; must be a delegated wallet on your profile)"
|
|
149533
149547
|
).option(
|
|
@@ -149548,6 +149562,11 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
149548
149562
|
).action(
|
|
149549
149563
|
async (url4, options) => {
|
|
149550
149564
|
try {
|
|
149565
|
+
if (options.protocol && !["x402", "mpp"].includes(options.protocol)) {
|
|
149566
|
+
throw new Error(
|
|
149567
|
+
`Invalid protocol "${options.protocol}". Must be x402 or mpp.`
|
|
149568
|
+
);
|
|
149569
|
+
}
|
|
149551
149570
|
const { analyticsService, client, walletAddress, lowBalanceWarning } = appContext.services;
|
|
149552
149571
|
const fromToken = options.capability ? isShortToken(options.capability) : false;
|
|
149553
149572
|
const effectiveCapRef = options.capability;
|
|
@@ -149668,6 +149687,9 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
149668
149687
|
headers,
|
|
149669
149688
|
...resolvedBody !== void 0 && { body: resolvedBody },
|
|
149670
149689
|
...options.maxPay && { maxPay: options.maxPay },
|
|
149690
|
+
...options.protocol && {
|
|
149691
|
+
paymentProtocol: options.protocol
|
|
149692
|
+
},
|
|
149671
149693
|
...options.walletAddress && {
|
|
149672
149694
|
walletAddress: options.walletAddress
|
|
149673
149695
|
},
|