QIE is EVM-compatible (Cosmos SDK + eth_* JSON-RPC, testnet chain 1983 / mainnet 1990), so this reuses the existing generic EVM x402 payment path (same shape as the Flare integration) rather than bespoke chain code: - lib/x402/qie_networks.ts, qie_rpc.ts, qie_finality.ts, qie_client.ts, qie_gateway.ts, qie_payment_attempt_store.ts - api/qie_x402_routes.ts wired into api/server.ts - scripts/qie_x402_check.ts (readiness/preflight, mirrors x402:algorand:check) - docs/qie_x402.md + a QIE Hackathon section in docs/SUBMISSIONS.md Fails closed without CRED402_QIE_PAY_TO / asset / facilitator configured, same discipline as the Algorand integration. Honest gaps flagged rather than faked: QUSDC's exact testnet contract address is unconfirmed (falls back to pricing in native QIE), and a real signed transaction needs a funded faucet key + live facilitator neither of which exist yet — both documented as TODO with exact unblock steps in docs/SUBMISSIONS.md. Track: AI + Autonomous Agents. Deadline: 2026-11-30, with a QIE Mainnet (chain 1990) contract deployment required at submission, not just testnet — confirmed via the hackathon's own dashboard + press coverage. 9/9 new tests pass (node:test via tsx --test), typecheck clean.
55 lines
2.4 KiB
TypeScript
55 lines
2.4 KiB
TypeScript
import { readAndInspectQieChallenge, type QiePaymentPolicy } from "../lib/x402/qie_client.js";
|
|
import { qieNetworkNameFor } from "../lib/x402/qie_networks.js";
|
|
|
|
/**
|
|
* Read-only QIE x402 preflight check (`npm run x402:qie:check`). Mirrors
|
|
* `scripts/algorand_x402_check.ts`: fetches the unpaid challenge, decodes
|
|
* `PAYMENT-REQUIRED`, and enforces the exact `exact`-scheme requirements
|
|
* before any client would sign or submit a transaction. Never pays.
|
|
*/
|
|
|
|
function loadCliConfig(): { endpoint: string; policy: QiePaymentPolicy } {
|
|
const endpoint = process.argv[process.argv.length - 1];
|
|
if (!endpoint || endpoint.startsWith("--") || !endpoint.includes("://")) {
|
|
throw new Error("Usage: npm run x402:qie:check -- https://host/v1/x402/qie/credit-score/AGENT_ID");
|
|
}
|
|
const networkName = qieNetworkNameFor((process.env.CRED402_QIE_CLIENT_NETWORK ?? "testnet").trim());
|
|
if (!networkName) throw new Error("CRED402_QIE_CLIENT_NETWORK must be testnet or mainnet");
|
|
|
|
const expectedPayTo = process.env.CRED402_QIE_EXPECTED_PAY_TO?.trim();
|
|
if (!expectedPayTo) throw new Error("CRED402_QIE_EXPECTED_PAY_TO is required");
|
|
|
|
const expectedAssetAddress = process.env.CRED402_QIE_EXPECTED_ASSET_ADDRESS?.trim();
|
|
if (!expectedAssetAddress) throw new Error("CRED402_QIE_EXPECTED_ASSET_ADDRESS is required");
|
|
|
|
const maxAmountBaseUnits = process.env.CRED402_QIE_MAX_PRICE_BASE_UNITS?.trim() ?? "10000";
|
|
const expectedAmountBaseUnits = process.env.CRED402_QIE_EXPECTED_PRICE_BASE_UNITS?.trim();
|
|
|
|
return {
|
|
endpoint,
|
|
policy: { networkName, expectedPayTo, expectedAssetAddress, expectedAmountBaseUnits, maxAmountBaseUnits, requestUrl: endpoint },
|
|
};
|
|
}
|
|
|
|
async function main() {
|
|
const { endpoint, policy } = loadCliConfig();
|
|
const response = await fetch(endpoint, {
|
|
method: "GET",
|
|
headers: { accept: "application/json" },
|
|
redirect: "error",
|
|
});
|
|
const result = await readAndInspectQieChallenge(response, policy);
|
|
|
|
console.log("QIE x402 preflight passed (no payment sent)");
|
|
console.log(`Resource: ${result.resourceUrl}`);
|
|
console.log(`Network: QIE ${result.networkName} (${result.selected.network})`);
|
|
console.log(`Asset: ${result.selected.asset}`);
|
|
console.log(`Amount: ${result.amountBaseUnits} base units`);
|
|
console.log(`Receiver: ${result.selected.payTo}`);
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(`Preflight failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
process.exitCode = 1;
|
|
});
|