@4mica/sdk 1.2.0 → 1.2.2

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/config.d.ts CHANGED
@@ -41,8 +41,25 @@ export declare class ConfigBuilder {
41
41
  private _authEnabled;
42
42
  private _authUrl?;
43
43
  private _authRefreshMarginSecs?;
44
- /** Override the 4Mica core RPC URL. Defaults to `https://api.4mica.xyz/`. */
44
+ /** Set the 4Mica core RPC URL directly. Use {@link network} to select a hosted network by name instead. Defaults to `https://ethereum.sepolia.api.4mica.xyz/`. */
45
45
  rpcUrl(value: string): ConfigBuilder;
46
+ /**
47
+ * Select a hosted 4Mica network by shorthand or CAIP-2 identifier.
48
+ * Resolves to the corresponding core API URL.
49
+ * Mutually exclusive with {@link rpcUrl} — last call wins.
50
+ *
51
+ * Supported values: `"base-sepolia"` / `"eip155:84532"`,
52
+ * `"ethereum-sepolia"` / `"eip155:11155111"`.
53
+ *
54
+ * @throws {@link ConfigError} if the network is not recognised.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * new ConfigBuilder().network("base-sepolia").walletPrivateKey("0x...").build();
59
+ * new ConfigBuilder().network("eip155:84532").walletPrivateKey("0x...").build();
60
+ * ```
61
+ */
62
+ network(value: string): ConfigBuilder;
46
63
  /** Set the wallet private key (hex string). Mutually exclusive with {@link signer}. */
47
64
  walletPrivateKey(value: string): ConfigBuilder;
48
65
  /** Set a pre-built viem `Account` directly. Mutually exclusive with {@link walletPrivateKey}. */
@@ -65,6 +82,7 @@ export declare class ConfigBuilder {
65
82
  * Load configuration from environment variables.
66
83
  *
67
84
  * Recognised variables:
85
+ * - `4MICA_NETWORK` — shorthand or CAIP-2 id (e.g. `base-sepolia`); takes precedence over `4MICA_RPC_URL`
68
86
  * - `4MICA_RPC_URL`
69
87
  * - `4MICA_WALLET_PRIVATE_KEY`
70
88
  * - `4MICA_ETHEREUM_HTTP_RPC_URL`
package/dist/config.js CHANGED
@@ -4,6 +4,7 @@ exports.ConfigBuilder = void 0;
4
4
  const accounts_1 = require("viem/accounts");
5
5
  const errors_1 = require("./errors");
6
6
  const utils_1 = require("./utils");
7
+ const networks_1 = require("./networks");
7
8
  /**
8
9
  * Fluent builder for {@link Config}.
9
10
  *
@@ -17,7 +18,7 @@ const utils_1 = require("./utils");
17
18
  * All fields can also be supplied from environment variables via {@link fromEnv}.
18
19
  */
19
20
  class ConfigBuilder {
20
- _rpcUrl = 'https://api.4mica.xyz/';
21
+ _rpcUrl = 'https://ethereum.sepolia.api.4mica.xyz/';
21
22
  _walletPrivateKey;
22
23
  _signer;
23
24
  _ethereumHttpRpcUrl;
@@ -27,11 +28,35 @@ class ConfigBuilder {
27
28
  _authEnabled = true;
28
29
  _authUrl;
29
30
  _authRefreshMarginSecs;
30
- /** Override the 4Mica core RPC URL. Defaults to `https://api.4mica.xyz/`. */
31
+ /** Set the 4Mica core RPC URL directly. Use {@link network} to select a hosted network by name instead. Defaults to `https://ethereum.sepolia.api.4mica.xyz/`. */
31
32
  rpcUrl(value) {
32
33
  this._rpcUrl = value;
33
34
  return this;
34
35
  }
36
+ /**
37
+ * Select a hosted 4Mica network by shorthand or CAIP-2 identifier.
38
+ * Resolves to the corresponding core API URL.
39
+ * Mutually exclusive with {@link rpcUrl} — last call wins.
40
+ *
41
+ * Supported values: `"base-sepolia"` / `"eip155:84532"`,
42
+ * `"ethereum-sepolia"` / `"eip155:11155111"`.
43
+ *
44
+ * @throws {@link ConfigError} if the network is not recognised.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * new ConfigBuilder().network("base-sepolia").walletPrivateKey("0x...").build();
49
+ * new ConfigBuilder().network("eip155:84532").walletPrivateKey("0x...").build();
50
+ * ```
51
+ */
52
+ network(value) {
53
+ const url = (0, networks_1.resolveNetworkRpcUrl)(value);
54
+ if (!url) {
55
+ throw new errors_1.ConfigError(`unknown network "${value}". Use a known shorthand (e.g. "base-sepolia") or CAIP-2 id, or call rpcUrl() directly.`);
56
+ }
57
+ this._rpcUrl = url;
58
+ return this;
59
+ }
35
60
  /** Set the wallet private key (hex string). Mutually exclusive with {@link signer}. */
36
61
  walletPrivateKey(value) {
37
62
  this._walletPrivateKey = value;
@@ -83,6 +108,7 @@ class ConfigBuilder {
83
108
  * Load configuration from environment variables.
84
109
  *
85
110
  * Recognised variables:
111
+ * - `4MICA_NETWORK` — shorthand or CAIP-2 id (e.g. `base-sepolia`); takes precedence over `4MICA_RPC_URL`
86
112
  * - `4MICA_RPC_URL`
87
113
  * - `4MICA_WALLET_PRIVATE_KEY`
88
114
  * - `4MICA_ETHEREUM_HTTP_RPC_URL`
@@ -94,6 +120,8 @@ class ConfigBuilder {
94
120
  */
95
121
  fromEnv() {
96
122
  const env = process.env;
123
+ if (env['4MICA_NETWORK'])
124
+ this.network(env['4MICA_NETWORK']);
97
125
  if (env['4MICA_RPC_URL'])
98
126
  this._rpcUrl = env['4MICA_RPC_URL'];
99
127
  if (env['4MICA_WALLET_PRIVATE_KEY'])
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './errors';
2
2
  export * from './constants';
3
+ export * from './networks';
3
4
  export * from './config';
4
5
  export * from './utils';
5
6
  export * from './models';
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./errors"), exports);
18
18
  __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./networks"), exports);
19
20
  __exportStar(require("./config"), exports);
20
21
  __exportStar(require("./utils"), exports);
21
22
  __exportStar(require("./models"), exports);
@@ -0,0 +1,40 @@
1
+ /** Metadata for a hosted 4Mica network deployment. */
2
+ export interface NetworkInfo {
3
+ /** CAIP-2 network identifier (e.g. `eip155:84532`). */
4
+ caip2: string;
5
+ /** Hosted 4Mica core API URL for this network. */
6
+ rpcUrl: string;
7
+ }
8
+ /**
9
+ * Hosted 4Mica network deployments, keyed by human-readable shorthand.
10
+ *
11
+ * Pass the shorthand (or the CAIP-2 string) to {@link ConfigBuilder.network}
12
+ * to select a network without writing a URL.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { Client, ConfigBuilder, NETWORKS } from "@4mica/sdk";
17
+ *
18
+ * // By shorthand
19
+ * const cfg = new ConfigBuilder()
20
+ * .network("base-sepolia")
21
+ * .walletPrivateKey("0x...")
22
+ * .build();
23
+ *
24
+ * // Inspect available networks
25
+ * console.log(NETWORKS["base-sepolia"].caip2); // "eip155:84532"
26
+ * ```
27
+ */
28
+ export declare const NETWORKS: Record<string, NetworkInfo>;
29
+ /**
30
+ * Resolve a network shorthand or CAIP-2 identifier to a core API URL.
31
+ * Returns `undefined` if the identifier is not a known hosted network.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * resolveNetworkRpcUrl("base-sepolia"); // "https://base.sepolia.api.4mica.xyz/"
36
+ * resolveNetworkRpcUrl("eip155:84532"); // "https://base.sepolia.api.4mica.xyz/"
37
+ * resolveNetworkRpcUrl("eip155:1"); // undefined
38
+ * ```
39
+ */
40
+ export declare function resolveNetworkRpcUrl(network: string): string | undefined;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NETWORKS = void 0;
4
+ exports.resolveNetworkRpcUrl = resolveNetworkRpcUrl;
5
+ /**
6
+ * Hosted 4Mica network deployments, keyed by human-readable shorthand.
7
+ *
8
+ * Pass the shorthand (or the CAIP-2 string) to {@link ConfigBuilder.network}
9
+ * to select a network without writing a URL.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { Client, ConfigBuilder, NETWORKS } from "@4mica/sdk";
14
+ *
15
+ * // By shorthand
16
+ * const cfg = new ConfigBuilder()
17
+ * .network("base-sepolia")
18
+ * .walletPrivateKey("0x...")
19
+ * .build();
20
+ *
21
+ * // Inspect available networks
22
+ * console.log(NETWORKS["base-sepolia"].caip2); // "eip155:84532"
23
+ * ```
24
+ */
25
+ exports.NETWORKS = {
26
+ 'base-sepolia': {
27
+ caip2: 'eip155:84532',
28
+ rpcUrl: 'https://base.sepolia.api.4mica.xyz/',
29
+ },
30
+ 'ethereum-sepolia': {
31
+ caip2: 'eip155:11155111',
32
+ rpcUrl: 'https://ethereum.sepolia.api.4mica.xyz/',
33
+ },
34
+ };
35
+ const NETWORKS_BY_CAIP2 = Object.fromEntries(Object.values(exports.NETWORKS).map((n) => [n.caip2, n]));
36
+ /**
37
+ * Resolve a network shorthand or CAIP-2 identifier to a core API URL.
38
+ * Returns `undefined` if the identifier is not a known hosted network.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * resolveNetworkRpcUrl("base-sepolia"); // "https://base.sepolia.api.4mica.xyz/"
43
+ * resolveNetworkRpcUrl("eip155:84532"); // "https://base.sepolia.api.4mica.xyz/"
44
+ * resolveNetworkRpcUrl("eip155:1"); // undefined
45
+ * ```
46
+ */
47
+ function resolveNetworkRpcUrl(network) {
48
+ return exports.NETWORKS[network]?.rpcUrl ?? NETWORKS_BY_CAIP2[network]?.rpcUrl;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4mica/sdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "TypeScript SDK for interacting with the 4Mica payment network",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,8 +49,8 @@
49
49
  "fmt": "prettier --check \"{src,tests}/**/*.{ts,js,json}\""
50
50
  },
51
51
  "dependencies": {
52
- "@4mica/x402": "file:../x402-4mica/packages/typescript/x402",
53
- "@noble/curves": "^2.0.1",
52
+ "@4mica/x402": "^1.2.0",
53
+ "@noble/curves": "^2.2.0",
54
54
  "@quillai-network/wachai-validation-sdk": "^0.1.0",
55
55
  "viem": "^2.45.1"
56
56
  },
@@ -70,4 +70,4 @@
70
70
  "typescript-eslint": "^8.54.0",
71
71
  "vitest": "^4.0.17"
72
72
  }
73
- }
73
+ }