@armory-sh/client-ethers 0.2.20-alpha.3.16 → 0.2.20-alpha.3.18
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 +12 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -123,13 +123,21 @@ function detectX402Version(_response) {
|
|
|
123
123
|
function getPaymentHeaderName(_version) {
|
|
124
124
|
return V2_HEADERS.PAYMENT_SIGNATURE;
|
|
125
125
|
}
|
|
126
|
+
function parseJsonOrBase64(value) {
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(value);
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=");
|
|
132
|
+
return JSON.parse(Buffer.from(normalized, "base64").toString("utf-8"));
|
|
133
|
+
}
|
|
126
134
|
function parsePaymentRequired(response) {
|
|
127
135
|
const v2Header = response.headers.get(V2_HEADERS.PAYMENT_REQUIRED);
|
|
128
136
|
if (!v2Header) {
|
|
129
137
|
throw new PaymentError("No PAYMENT-REQUIRED header found in V2 response");
|
|
130
138
|
}
|
|
131
139
|
try {
|
|
132
|
-
const parsed =
|
|
140
|
+
const parsed = parseJsonOrBase64(v2Header);
|
|
133
141
|
if (!isX402V2PaymentRequired(parsed)) {
|
|
134
142
|
throw new PaymentError("Invalid x402 V2 payment required format");
|
|
135
143
|
}
|
|
@@ -191,8 +199,7 @@ async function createX402V2Payment(signer, requirements, fromAddress, nonce, val
|
|
|
191
199
|
};
|
|
192
200
|
return {
|
|
193
201
|
x402Version: 2,
|
|
194
|
-
|
|
195
|
-
network: requirements.network,
|
|
202
|
+
accepted: requirements,
|
|
196
203
|
payload
|
|
197
204
|
};
|
|
198
205
|
}
|
|
@@ -399,7 +406,7 @@ var armoryPay = async (wallet, url, network, token, options) => {
|
|
|
399
406
|
};
|
|
400
407
|
}
|
|
401
408
|
const data = await response.json();
|
|
402
|
-
const txHash = response.headers.get("
|
|
409
|
+
const txHash = response.headers.get("PAYMENT-RESPONSE");
|
|
403
410
|
return {
|
|
404
411
|
success: true,
|
|
405
412
|
data,
|
|
@@ -509,7 +516,7 @@ var createArmory = (config) => {
|
|
|
509
516
|
};
|
|
510
517
|
}
|
|
511
518
|
const data = await response.json();
|
|
512
|
-
const txHash = response.headers.get("
|
|
519
|
+
const txHash = response.headers.get("PAYMENT-RESPONSE");
|
|
513
520
|
return {
|
|
514
521
|
success: true,
|
|
515
522
|
data,
|