@armory-sh/middleware-bun 0.3.2 → 0.3.8

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
@@ -5,14 +5,41 @@ import { decodePayment, isExactEvmPayload } from "@armory-sh/base";
5
5
  import {
6
6
  getNetworkConfig,
7
7
  getNetworkByChainId,
8
- encodePaymentPayload
8
+ encodePaymentPayload,
9
+ normalizeNetworkName
9
10
  } from "@armory-sh/base";
10
- var getNetworkName = (network) => {
11
- if (typeof network === "string") return network;
12
- const net = getNetworkByChainId(network);
13
- if (!net) throw new Error(`No network found for chainId: ${network}`);
14
- return net.name.toLowerCase().replace(" mainnet", "").replace(" sepolia", "-sepolia");
11
+ var toSlug = (network) => {
12
+ if (typeof network === "number") {
13
+ const net = getNetworkByChainId(network);
14
+ if (!net) throw new Error(`No network found for chainId: ${network}`);
15
+ return normalizeNetworkName(net.name);
16
+ }
17
+ if (network.startsWith("eip155:")) {
18
+ const chainId = parseInt(network.split(":")[1], 10);
19
+ const net = getNetworkByChainId(chainId);
20
+ if (!net) throw new Error(`No network found for chainId: ${chainId}`);
21
+ return normalizeNetworkName(net.name);
22
+ }
23
+ return normalizeNetworkName(network);
24
+ };
25
+ var toEip155 = (network) => {
26
+ if (typeof network === "number") {
27
+ const net2 = getNetworkByChainId(network);
28
+ if (!net2) throw new Error(`No network found for chainId: ${network}`);
29
+ return net2.caip2Id;
30
+ }
31
+ if (network.startsWith("eip155:")) {
32
+ const net2 = getNetworkConfig(network);
33
+ if (!net2) throw new Error(`No network found for: ${network}`);
34
+ return net2.caip2Id;
35
+ }
36
+ const slug = normalizeNetworkName(network);
37
+ const net = getNetworkConfig(slug);
38
+ if (!net) throw new Error(`No network found for: ${slug}`);
39
+ return net.caip2Id;
15
40
  };
41
+ var getNetworkName = (network) => toSlug(network);
42
+ var getChainId = (network) => toEip155(network);
16
43
  var createV1Requirements = (config, expiry) => {
17
44
  const networkName = getNetworkName(config.network);
18
45
  const network = getNetworkConfig(networkName);
@@ -32,7 +59,7 @@ var createV2Requirements = (config, expiry) => {
32
59
  return {
33
60
  amount: config.amount,
34
61
  to: config.payTo,
35
- chainId: network.caip2Id,
62
+ chainId: getChainId(config.network),
36
63
  assetId: network.caipAssetId,
37
64
  nonce: `${Date.now()}-${crypto.randomUUID()}`,
38
65
  expiry
@@ -157,7 +184,8 @@ import {
157
184
  resolveNetwork,
158
185
  resolveToken,
159
186
  validateAcceptConfig,
160
- isValidationError
187
+ isValidationError,
188
+ normalizeNetworkName as normalizeNetworkName2
161
189
  } from "@armory-sh/base";
162
190
 
163
191
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/middleware-bun",
3
- "version": "0.3.2",
3
+ "version": "0.3.8",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "type": "module",
@@ -24,8 +24,8 @@
24
24
  "directory": "packages/middleware-bun"
25
25
  },
26
26
  "dependencies": {
27
- "@armory-sh/base": "0.2.4",
28
- "@armory-sh/facilitator": "0.2.4"
27
+ "@armory-sh/base": "0.2.12",
28
+ "@armory-sh/facilitator": "0.2.11"
29
29
  },
30
30
  "devDependencies": {
31
31
  "bun-types": "latest",