joule-sdk 0.1.0 → 0.1.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/client.js +11 -3
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -43,10 +43,18 @@ class JouleClient {
|
|
|
43
43
|
throw new Error(`Compute server error (${initialResponse.status}): ${errorBody?.error?.message || "Unknown error"}`);
|
|
44
44
|
}
|
|
45
45
|
// Step 2: Extract payment requirements from 402 response
|
|
46
|
-
|
|
47
|
-
const
|
|
46
|
+
// Prefer X-Payment header (base64 JSON), fall back to body.paymentRequirements
|
|
47
|
+
const xPaymentHeader = initialResponse.headers.get("X-Payment");
|
|
48
|
+
let requirements;
|
|
49
|
+
if (xPaymentHeader) {
|
|
50
|
+
requirements = JSON.parse(Buffer.from(xPaymentHeader, "base64").toString("utf-8"));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const errorBody = await initialResponse.json();
|
|
54
|
+
requirements = errorBody.paymentRequirements;
|
|
55
|
+
}
|
|
48
56
|
if (!requirements) {
|
|
49
|
-
throw new Error("402 response missing
|
|
57
|
+
throw new Error("402 response missing payment requirements — is this an x402-enabled endpoint?");
|
|
50
58
|
}
|
|
51
59
|
// Step 3: Build and sign Soroban transfer
|
|
52
60
|
const paymentPayload = await (0, wallet_1.buildSignedPayment)(this.keypair, requirements, this.network, this.rpcUrl);
|
package/package.json
CHANGED