wolverine-ai 5.3.2 → 5.3.4
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/package.json +1 -1
- package/src/middleware/x402-fastify.js +11 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wolverine-ai",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"description": "Self-healing Node.js server framework powered by AI. Catches crashes, diagnoses errors, generates fixes, verifies, and restarts — automatically.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -132,20 +132,21 @@ async function x402Plugin(fastify, opts) {
|
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
// Decode payment
|
|
135
|
+
// Decode payment — parse raw payload directly (matching working project pattern)
|
|
136
136
|
let decodedPayment;
|
|
137
137
|
try {
|
|
138
|
-
const { exact } = await import("x402/schemes");
|
|
139
|
-
const libraryDecoded = exact.evm.decodePayment(paymentHeader);
|
|
140
|
-
|
|
141
|
-
// Parse raw payload for metadata
|
|
142
138
|
const raw = JSON.parse(Buffer.from(paymentHeader, "base64").toString("utf-8"));
|
|
143
139
|
|
|
140
|
+
// Validate required fields
|
|
141
|
+
if (!raw.payload?.authorization || !raw.payload?.signature) {
|
|
142
|
+
throw new Error("Missing authorization or signature");
|
|
143
|
+
}
|
|
144
|
+
|
|
144
145
|
decodedPayment = {
|
|
145
146
|
x402Version: raw.x402Version || 1,
|
|
146
147
|
scheme: raw.scheme || "exact",
|
|
147
148
|
network: raw.network || _network,
|
|
148
|
-
payload:
|
|
149
|
+
payload: raw.payload,
|
|
149
150
|
};
|
|
150
151
|
} catch (err) {
|
|
151
152
|
reply.code(402).send({ error: "Invalid payment format: " + err.message, accepts: [paymentRequirements] });
|
|
@@ -158,10 +159,11 @@ async function x402Plugin(fastify, opts) {
|
|
|
158
159
|
|
|
159
160
|
// Verify via facilitator
|
|
160
161
|
try {
|
|
162
|
+
console.log(` 💰 x402 verify: from=${decodedPayment.payload?.authorization?.from} value=${decodedPayment.payload?.authorization?.value} network=${decodedPayment.network}`);
|
|
161
163
|
const verifyResult = await _facilitatorClient.verify(decodedPayment, actualRequirements);
|
|
162
164
|
if (!verifyResult.isValid) {
|
|
163
|
-
console.log(` ⚠️ x402 verify failed: ${verifyResult.invalidReason}`);
|
|
164
|
-
reply.code(402).send({ error: verifyResult.invalidReason || "Payment verification failed", accepts: [paymentRequirements], payer: verifyResult.payer });
|
|
165
|
+
console.log(` ⚠️ x402 verify failed: ${verifyResult.invalidReason} ${verifyResult.invalidMessage || ""}`);
|
|
166
|
+
reply.code(402).send({ error: verifyResult.invalidReason || "Payment verification failed", message: verifyResult.invalidMessage, accepts: [paymentRequirements], payer: verifyResult.payer });
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
167
169
|
} catch (err) {
|
|
@@ -185,10 +187,8 @@ async function x402Plugin(fastify, opts) {
|
|
|
185
187
|
|
|
186
188
|
try {
|
|
187
189
|
const paymentHeader = request.headers["x-payment"] || request.headers["payment-signature"];
|
|
188
|
-
const { exact } = require("x402/schemes");
|
|
189
190
|
const raw = JSON.parse(Buffer.from(paymentHeader, "base64").toString("utf-8"));
|
|
190
|
-
const
|
|
191
|
-
const decodedPayment = { x402Version: raw.x402Version || 1, scheme: raw.scheme || "exact", network: raw.network || _network, payload: libraryDecoded.payload };
|
|
191
|
+
const decodedPayment = { x402Version: raw.x402Version || 1, scheme: raw.scheme || "exact", network: raw.network || _network, payload: raw.payload };
|
|
192
192
|
|
|
193
193
|
const userValue = decodedPayment.payload.authorization.value;
|
|
194
194
|
const { getAddress } = await import("viem");
|