@4mica/sdk 0.5.2 → 0.5.3

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/README.md CHANGED
@@ -30,12 +30,13 @@ Node.js 18+ is required.
30
30
  The SDK requires a signing key and can use sensible defaults for the rest:
31
31
 
32
32
  - `walletPrivateKey` (**required** unless `signer` is provided): private key used for signing
33
- - `rpcUrl` (optional): URL of the 4Mica core RPC server. Defaults to `http://127.0.0.1:3000`.
33
+ - `rpcUrl` (optional): URL of the 4Mica core RPC server. Defaults to `https://api.4mica.xyz/`.
34
34
  - `ethereumHttpRpcUrl` (optional): Ethereum JSON-RPC endpoint; fetched from core if omitted
35
35
  - `contractAddress` (optional): Core4Mica contract address; fetched from core if omitted
36
36
  - `adminApiKey` (optional): API key for admin RPCs
37
37
  - `bearerToken` (optional): static bearer token for auth
38
- - `authUrl` and `authRefreshMarginSecs` (optional): SIWE auth config
38
+ - `authUrl` and `authRefreshMarginSecs` (optional): SIWE auth config. Only used when auth is
39
+ enabled via `enableAuth()` or by setting either value (defaults to `rpcUrl` and 60 seconds).
39
40
 
40
41
  > Note: `ethereumHttpRpcUrl` and `contractAddress` are fetched from the core service and validated
41
42
  > against the connected Ethereum provider automatically. Only override these if you need to use
@@ -63,17 +64,24 @@ async function main() {
63
64
 
64
65
  ### 2) Using Environment Variables
65
66
 
66
- Set environment variables:
67
+ Set environment variables (example `.env`):
67
68
 
68
69
  ```bash
69
- export 4MICA_WALLET_PRIVATE_KEY="0x..."
70
- export 4MICA_RPC_URL="https://api.4mica.xyz/"
71
- export 4MICA_ETHEREUM_HTTP_RPC_URL="http://localhost:8545"
72
- export 4MICA_CONTRACT_ADDRESS="0x..."
73
- export 4MICA_ADMIN_API_KEY="ak_..."
74
- export 4MICA_BEARER_TOKEN="Bearer <access_token>"
75
- export 4MICA_AUTH_URL="https://api.4mica.xyz/"
76
- export 4MICA_AUTH_REFRESH_MARGIN_SECS="60"
70
+ 4MICA_WALLET_PRIVATE_KEY="0x..."
71
+ 4MICA_RPC_URL="https://api.4mica.xyz/"
72
+ 4MICA_ETHEREUM_HTTP_RPC_URL="http://localhost:8545"
73
+ 4MICA_CONTRACT_ADDRESS="0x..."
74
+ 4MICA_ADMIN_API_KEY="ak_..."
75
+ 4MICA_BEARER_TOKEN="Bearer <access_token>"
76
+ 4MICA_AUTH_URL="https://api.4mica.xyz/"
77
+ 4MICA_AUTH_REFRESH_MARGIN_SECS="60"
78
+ ```
79
+
80
+ If you want to set them inline for a single command, use `env` since most shells do not allow
81
+ variable names that start with a digit:
82
+
83
+ ```bash
84
+ env 4MICA_WALLET_PRIVATE_KEY="0x..." 4MICA_RPC_URL="https://api.4mica.xyz/" node app.js
77
85
  ```
78
86
 
79
87
  Then in code:
@@ -87,13 +95,15 @@ const client = await Client.new(cfg);
87
95
 
88
96
  ### 3) Using a Custom Signer
89
97
 
90
- If you want to integrate with a custom signer (hardware wallet, remote signer, etc.), provide an
91
- `EvmSigner` implementation. It must expose `address`, `signTypedData`, and `signMessage`.
98
+ If you want to integrate with a custom signer (hardware wallet, remote signer, etc.), provide a
99
+ `viem` `Account` implementation. It must expose `address`, `signTypedData`, and `signMessage` for
100
+ SIWE auth.
92
101
 
93
102
  ```ts
94
- import { Client, ConfigBuilder, createLocalSigner } from "@4mica/sdk";
103
+ import { Client, ConfigBuilder } from "@4mica/sdk";
104
+ import { privateKeyToAccount } from "viem/accounts";
95
105
 
96
- const signer = createLocalSigner(process.env.PAYER_KEY!);
106
+ const signer = privateKeyToAccount(process.env.PAYER_KEY as `0x${string}`);
97
107
  const cfg = new ConfigBuilder().signer(signer).build();
98
108
  const client = await Client.new(cfg);
99
109
  ```
@@ -246,6 +256,7 @@ async function settle(
246
256
 
247
257
  Notes:
248
258
  - `signPayment` and `signPaymentV2` always use EIP-712 signing and will error if the scheme is not 4mica.
259
+ - `UserClient.signPayment` supports `SigningScheme.EIP712` (default) and `SigningScheme.EIP191`.
249
260
  - `settlePayment` only hits `/settle`; resource servers should still call `/verify` first when enforcing access.
250
261
 
251
262
  ### API Methods Summary