@4mica/sdk 0.5.2 → 0.5.4

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,16 +30,17 @@ 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
- > Note: `ethereumHttpRpcUrl` and `contractAddress` are fetched from the core service and validated
41
- > against the connected Ethereum provider automatically. Only override these if you need to use
42
- > different values than the server defaults.
41
+ > Note: `ethereumHttpRpcUrl` and `contractAddress` are fetched from the core service by default.
42
+ > The SDK validates the connected chain ID but does not verify the contract address or code. Only
43
+ > override these if you need to use different values than the server defaults.
43
44
 
44
45
  ### 1) Using ConfigBuilder
45
46
 
@@ -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
  ```
@@ -143,6 +153,7 @@ X-PAYMENT header (and optional `/settle` call) that the facilitator will accept.
143
153
 
144
154
  At minimum you need:
145
155
  - `scheme` and `network` (scheme must include `4mica`, e.g. `4mica-credit`)
156
+ - `payTo` (recipient address), `asset`, and `maxAmountRequired` (v1) or `amount` (v2)
146
157
  - `extra.tabEndpoint` for tab resolution
147
158
 
148
159
  `X402Flow` will refresh the tab by calling `extra.tabEndpoint` before signing.
@@ -246,7 +257,9 @@ async function settle(
246
257
 
247
258
  Notes:
248
259
  - `signPayment` and `signPaymentV2` always use EIP-712 signing and will error if the scheme is not 4mica.
260
+ - `UserClient.signPayment` supports `SigningScheme.EIP712` (default) and `SigningScheme.EIP191`.
249
261
  - `settlePayment` only hits `/settle`; resource servers should still call `/verify` first when enforcing access.
262
+ - `RecipientClient.remunerate` requires the optional `@noble/curves` dependency for BLS decoding.
250
263
 
251
264
  ### API Methods Summary
252
265
 
@@ -292,8 +305,7 @@ Available under `client.rpc` (requires an admin API key):
292
305
  ## Error Handling
293
306
 
294
307
  All SDK errors extend `FourMicaError`. Common error types include `ConfigError`, `RpcError`,
295
- `ClientInitializationError`, `ContractError`, `SigningError`, `VerificationError`, `X402Error`, and
296
- `AuthError`.
308
+ `SigningError`, `VerificationError`, `X402Error`, and `AuthError`.
297
309
 
298
310
  ## License
299
311