@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 +26 -15
- package/dist/abi/core4mica.d.ts +1244 -0
- package/dist/abi/core4mica.js +1606 -0
- package/dist/abi/erc20.d.ts +141 -0
- package/dist/abi/erc20.js +188 -0
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +11 -0
- package/dist/bls.js +3 -3
- package/dist/client.d.ts +7 -9
- package/dist/client.js +16 -26
- package/dist/config.d.ts +3 -4
- package/dist/config.js +12 -7
- package/dist/contract.d.ts +25 -20
- package/dist/contract.js +133 -89
- package/dist/errors.js +4 -0
- package/dist/guarantee.js +19 -20
- package/dist/models.js +63 -0
- package/dist/rpc.js +5 -0
- package/dist/signing.d.ts +6 -23
- package/dist/signing.js +25 -20
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +9 -5
- package/dist/x402/index.js +2 -0
- package/package.json +14 -14
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 `
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
91
|
-
`
|
|
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
|
|
103
|
+
import { Client, ConfigBuilder } from "@4mica/sdk";
|
|
104
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
95
105
|
|
|
96
|
-
const signer =
|
|
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
|