@armory-sh/middleware-hono 0.3.22-alpha.3.21 → 0.3.22-alpha.3.23

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.
Files changed (2) hide show
  1. package/dist/index.js +36 -8
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -119,6 +119,37 @@ function resolveFacilitatorUrl(config, network, token) {
119
119
  }
120
120
  return config.facilitatorUrl;
121
121
  }
122
+ function resolveFacilitatorUrlFromRequirement(config, requirement) {
123
+ const chainId = parseInt(requirement.network.split(":")[1] || "0", 10);
124
+ const assetAddress = requirement.asset.toLowerCase();
125
+ if (config.facilitatorUrlByToken) {
126
+ for (const [chainKey, tokenMap] of Object.entries(config.facilitatorUrlByToken)) {
127
+ const resolvedChain = resolveNetwork(chainKey);
128
+ if (!isValidationError(resolvedChain) && resolvedChain.config.chainId === chainId) {
129
+ for (const [, url] of Object.entries(tokenMap)) {
130
+ const network = resolveNetwork(chainKey);
131
+ if (!isValidationError(network)) {
132
+ for (const tokenKey of Object.keys(tokenMap)) {
133
+ const resolvedToken = resolveToken(tokenKey, network);
134
+ if (!isValidationError(resolvedToken) && resolvedToken.config.contractAddress.toLowerCase() === assetAddress) {
135
+ return url;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ if (config.facilitatorUrlByChain) {
144
+ for (const [chainKey, url] of Object.entries(config.facilitatorUrlByChain)) {
145
+ const resolvedChain = resolveNetwork(chainKey);
146
+ if (!isValidationError(resolvedChain) && resolvedChain.config.chainId === chainId) {
147
+ return url;
148
+ }
149
+ }
150
+ }
151
+ return config.facilitatorUrl;
152
+ }
122
153
  function createPaymentRequirements(config) {
123
154
  ensureTokensRegistered();
124
155
  const {
@@ -148,18 +179,17 @@ function createPaymentRequirements(config) {
148
179
  const atomicAmount = toAtomicUnits(amount);
149
180
  const tokenConfig = resolvedToken.config;
150
181
  const resolvedPayTo = resolvePayTo(config, network, resolvedToken);
151
- const resolvedFacilitatorUrl = resolveFacilitatorUrl(config, network, resolvedToken);
182
+ resolveFacilitatorUrl(config, network, resolvedToken);
152
183
  requirements.push({
153
184
  scheme: "exact",
154
185
  network: network.caip2,
155
- maxAmountRequired: atomicAmount,
186
+ amount: atomicAmount,
156
187
  asset: tokenConfig.contractAddress,
157
188
  payTo: resolvedPayTo,
158
189
  maxTimeoutSeconds,
159
190
  extra: {
160
191
  name: tokenConfig.name,
161
- version: tokenConfig.version,
162
- ...resolvedFacilitatorUrl && { facilitatorUrl: resolvedFacilitatorUrl }
192
+ version: tokenConfig.version
163
193
  }
164
194
  });
165
195
  }
@@ -217,8 +247,7 @@ function paymentMiddleware(config) {
217
247
  c.status(400);
218
248
  return c.json({ error: "Invalid payment payload" });
219
249
  }
220
- const requirementFacilitatorUrl = primaryRequirement.extra?.facilitatorUrl;
221
- const facilitatorUrl = config.facilitatorUrl ?? (typeof requirementFacilitatorUrl === "string" ? requirementFacilitatorUrl : void 0);
250
+ const facilitatorUrl = resolveFacilitatorUrlFromRequirement(config, primaryRequirement);
222
251
  console.log("[payment-middleware] Facilitator URL:", facilitatorUrl);
223
252
  if (!facilitatorUrl) {
224
253
  console.log("[payment-middleware] No facilitator URL configured");
@@ -341,8 +370,7 @@ var routeAwarePaymentMiddleware = (config) => {
341
370
  c.status(400);
342
371
  return c.json({ error: "Invalid payment payload" });
343
372
  }
344
- const requirementFacilitatorUrl = primaryRequirement.extra?.facilitatorUrl;
345
- const facilitatorUrl = matchedRoute.config.facilitatorUrl ?? (typeof requirementFacilitatorUrl === "string" ? requirementFacilitatorUrl : void 0);
373
+ const facilitatorUrl = matchedRoute.config.facilitatorUrl ?? resolveFacilitatorUrlFromRequirement(matchedRoute.config, primaryRequirement);
346
374
  if (!facilitatorUrl) {
347
375
  c.status(500);
348
376
  return c.json({ error: "Payment middleware configuration error", message: "Facilitator URL is required for verification" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/middleware-hono",
3
- "version": "0.3.22-alpha.3.21",
3
+ "version": "0.3.22-alpha.3.23",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "type": "module",
@@ -33,8 +33,8 @@
33
33
  "hono": "^4"
34
34
  },
35
35
  "dependencies": {
36
- "@armory-sh/base": "0.2.22-alpha.3.21",
37
- "@armory-sh/extensions": "0.1.3-alpha.3.21"
36
+ "@armory-sh/base": "0.2.22-alpha.3.23",
37
+ "@armory-sh/extensions": "0.1.3-alpha.3.23"
38
38
  },
39
39
  "devDependencies": {
40
40
  "bun-types": "latest",