@invariance/sdk 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Invariance Protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,274 @@
1
+ # @invariance/sdk
2
+
3
+ TypeScript SDK for Invariance Protocol -- the verification layer for autonomous agents on Base L2.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @invariance/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Zero-config (recommended)
14
+
15
+ Create a `.env` file (see `sdk/.env.example`):
16
+
17
+ ```env
18
+ INVARIANCE_CHAIN=base-sepolia
19
+ INVARIANCE_RPC_URL=https://sepolia.base.org
20
+ INVARIANCE_PRIVATE_KEY=0x...
21
+ ```
22
+
23
+ ```typescript
24
+ import { Invariance } from '@invariance/sdk';
25
+
26
+ // Automatically reads from .env — no args needed
27
+ const inv = new Invariance();
28
+ ```
29
+
30
+ ### Explicit config
31
+
32
+ ```typescript
33
+ import { Invariance } from '@invariance/sdk';
34
+
35
+ const inv = new Invariance({
36
+ chain: 'base-sepolia',
37
+ rpcUrl: process.env.RPC_URL,
38
+ signer: wallet, // viem Account, WalletClient, or EIP-1193 provider
39
+ });
40
+
41
+ // Wait for wallet connection
42
+ await inv.ensureWalletInit();
43
+
44
+ // Register an on-chain identity
45
+ const agent = await inv.identity.register({
46
+ type: 'agent',
47
+ owner: '0xYourAddress',
48
+ label: 'TraderBot',
49
+ capabilities: ['swap', 'transfer'],
50
+ });
51
+
52
+ // Create and attach a policy
53
+ const policy = await inv.policy.create({
54
+ name: 'Trading Limits',
55
+ actor: 'agent',
56
+ rules: [
57
+ { type: 'max-spend', config: { limit: '100000' } },
58
+ { type: 'action-whitelist', config: { actions: ['swap', 'transfer'] } },
59
+ ],
60
+ });
61
+ await inv.policy.attach(policy.policyId, agent.identityId);
62
+
63
+ // Execute a verified intent
64
+ const result = await inv.intent.request({
65
+ actor: { type: 'agent', address: agent.address },
66
+ action: 'swap',
67
+ params: { from: 'USDC', to: 'ETH', amount: '100' },
68
+ approval: 'auto',
69
+ });
70
+
71
+ // Verify any transaction
72
+ const verification = await inv.verify(result.proof.txHash);
73
+ ```
74
+
75
+ ## Signer Types
76
+
77
+ The SDK accepts three signer types via `config.signer`:
78
+
79
+ | Type | Example |
80
+ |------|---------|
81
+ | **viem Account** | `privateKeyToAccount('0x...')` |
82
+ | **WalletClient** | `createWalletClient({ ... })` |
83
+ | **EIP-1193 Provider** | `window.ethereum`, injected wallets |
84
+
85
+ ## Modules
86
+
87
+ All modules are lazily initialized and accessed as properties on the `Invariance` client.
88
+
89
+ ### `inv.identity` -- IdentityManager
90
+
91
+ Register agents, humans, and devices as verified on-chain identities.
92
+
93
+ | Method | Description |
94
+ |--------|-------------|
95
+ | `register(opts)` | Register a new identity |
96
+ | `get(identityId)` | Get identity by ID |
97
+ | `resolve(address)` | Resolve address to identity |
98
+ | `update(identityId, opts)` | Update label/capabilities |
99
+ | `pause(identityId)` | Temporarily suspend |
100
+ | `resume(identityId)` | Resume from pause |
101
+ | `deactivate(identityId)` | Permanently deactivate |
102
+ | `list(filters?)` | List identities (requires indexer) |
103
+ | `attest(input)` | Add attestation to identity |
104
+ | `attestations(identityId)` | Get attestations |
105
+
106
+ ### `inv.intent` -- IntentProtocol
107
+
108
+ Request-approve-execute-verify handshake for agent actions.
109
+
110
+ | Method | Description |
111
+ |--------|-------------|
112
+ | `request(opts)` | Submit an intent for execution |
113
+ | `prepare(opts)` | Dry-run with policy checks and gas estimate |
114
+ | `approve(intentId)` | Approve a pending intent |
115
+ | `reject(intentId, reason)` | Reject a pending intent |
116
+ | `status(intentId)` | Get lifecycle state from on-chain data |
117
+ | `history(filters?)` | Query intent history (requires indexer) |
118
+
119
+ ### `inv.policy` -- PolicyEngine
120
+
121
+ Composable, verifiable condition sets enforced on-chain.
122
+
123
+ | Method | Description |
124
+ |--------|-------------|
125
+ | `create(opts)` | Create a policy with rules |
126
+ | `attach(policyId, identityId)` | Bind policy to identity |
127
+ | `detach(policyId, identityId)` | Unbind policy |
128
+ | `evaluate(opts)` | Check if action is allowed |
129
+ | `revoke(policyId)` | Revoke a policy |
130
+ | `status(policyId)` | Get policy status |
131
+ | `list(filters?)` | List policies |
132
+ | `compose(policyIds)` | Compose multiple policies |
133
+ | `onViolation(callback)` | Subscribe to violations |
134
+
135
+ **Rule types:** `max-spend`, `max-per-tx`, `daily-limit`, `require-balance`, `action-whitelist`, `action-blacklist`, `target-whitelist`, `target-blacklist`, `time-window`, `cooldown`, `rate-limit`, `custom`
136
+
137
+ ### `inv.escrow` -- EscrowManager
138
+
139
+ USDC escrow with multi-sig and conditional release.
140
+
141
+ | Method | Description |
142
+ |--------|-------------|
143
+ | `create(opts)` | Create escrow between parties |
144
+ | `fund(escrowId)` | Fund with USDC |
145
+ | `release(escrowId)` | Release funds to beneficiary |
146
+ | `refund(escrowId)` | Refund to depositor |
147
+ | `dispute(escrowId, reason)` | Open a dispute |
148
+ | `resolve(escrowId, opts)` | Resolve a dispute |
149
+ | `approve(escrowId)` | Add multi-sig approval |
150
+ | `approvals(escrowId)` | Get approval status |
151
+ | `status(escrowId)` | Get escrow state |
152
+ | `list(filters?)` | List escrows |
153
+ | `onStateChange(callback)` | Subscribe to state changes |
154
+
155
+ ### `inv.ledger` -- EventLedger
156
+
157
+ Immutable on-chain logging with dual signatures (actor + platform).
158
+
159
+ | Method | Description |
160
+ |--------|-------------|
161
+ | `log(event)` | Log a single entry |
162
+ | `batch(events)` | Log multiple entries in one tx |
163
+ | `query(filters)` | Query entries (requires indexer) |
164
+ | `stream(filters, callback)` | Real-time event stream |
165
+ | `export(filters)` | Export as JSON/CSV |
166
+
167
+ ### `inv.verify` -- Verifier
168
+
169
+ Cryptographic verification and public explorer URLs. Callable directly as `inv.verify(txHash)` and via sub-methods.
170
+
171
+ | Method | Description |
172
+ |--------|-------------|
173
+ | `inv.verify(txHash)` | Verify a transaction (direct call) |
174
+ | `inv.verify.action(opts)` | Verify by actor + action |
175
+ | `inv.verify.identity(address)` | Full identity audit |
176
+ | `inv.verify.escrow(escrowId)` | Escrow audit trail |
177
+ | `inv.verify.proof(proofHash)` | Decode and validate a proof |
178
+ | `inv.verify.bulk(txHashes)` | Batch verify transactions |
179
+ | `inv.verify.url(intentId)` | Generate public explorer URL |
180
+
181
+ ### `inv.reputation` -- ReputationEngine
182
+
183
+ Auto-calculated scores and 1-5 star reviews.
184
+
185
+ | Method | Description |
186
+ |--------|-------------|
187
+ | `get(address)` | Full reputation profile |
188
+ | `review(opts)` | Submit on-chain review |
189
+ | `getReviews(address)` | Get reviews for address |
190
+ | `score(address)` | Calculate overall score |
191
+ | `compare(addresses)` | Rank multiple addresses |
192
+ | `badge(address)` | Get reputation badge |
193
+ | `history(address)` | Score history over time |
194
+
195
+ ### `inv.wallet` -- WalletManager
196
+
197
+ | Method | Description |
198
+ |--------|-------------|
199
+ | `get()` | Get wallet info |
200
+ | `balance()` | Get ETH balance |
201
+ | `getAddress()` | Get connected address |
202
+ | `isConnected()` | Check connection status |
203
+
204
+ ### `inv.gas` -- GasManager
205
+
206
+ | Method | Description |
207
+ |--------|-------------|
208
+ | `estimate(opts)` | Estimate gas for an action |
209
+ | `balance()` | Get ETH balance for gas |
210
+
211
+ ### `inv.x402` -- X402Manager
212
+
213
+ Pay-per-action execution and agent-to-agent payments via x402.
214
+
215
+ | Method | Description |
216
+ |--------|-------------|
217
+ | `payForAction(opts)` | Execute a paid action |
218
+ | `verifyPayment(txHash)` | Verify a payment receipt |
219
+ | `history(filters?)` | Query payment history |
220
+ | `estimateCost(action)` | Estimate cost for an action |
221
+ | `configure(settings)` | Configure payment settings |
222
+
223
+ ### `inv.erc8004` -- ERC8004Manager
224
+
225
+ Standalone ERC-8004 (Trustless Agents) manager for on-chain agent identity, reputation, and validation.
226
+
227
+ ### `inv.erc8004Bridge` -- InvarianceBridge
228
+
229
+ Bridge between ERC-8004 and Invariance modules: link identities, bridge reputation, cross-protocol validation.
230
+
231
+ ## Error Handling
232
+
233
+ ```typescript
234
+ import { InvarianceError, ErrorCode } from '@invariance/sdk';
235
+
236
+ try {
237
+ await inv.intent.request({ ... });
238
+ } catch (err) {
239
+ if (err instanceof InvarianceError) {
240
+ console.log(err.code); // ErrorCode enum value
241
+ console.log(err.message); // Human-readable description
242
+ }
243
+ }
244
+ ```
245
+
246
+ Key error codes: `IDENTITY_NOT_FOUND`, `POLICY_DENIED`, `ESCROW_NOT_FOUND`, `TX_REVERTED`, `VERIFICATION_FAILED`, `WALLET_NOT_CONNECTED`, `NETWORK_ERROR`, `NOT_IMPLEMENTED`
247
+
248
+ ## Events
249
+
250
+ Subscribe to SDK events via the shared event emitter:
251
+
252
+ ```typescript
253
+ inv.on('identity.registered', (data) => { ... });
254
+ inv.on('intent.requested', (data) => { ... });
255
+ inv.on('policy.created', (data) => { ... });
256
+ inv.on('policy.violation', (data) => { ... });
257
+ inv.on('escrow.created', (data) => { ... });
258
+ inv.on('ledger.logged', (data) => { ... });
259
+ inv.on('reputation.reviewed', (data) => { ... });
260
+ ```
261
+
262
+ ## Examples
263
+
264
+ See `examples/` for complete working applications:
265
+
266
+ | Example | Description |
267
+ |---------|-------------|
268
+ | `examples/verified-treasury/` | CLI: policy-gated spending, verified intents, audit trails |
269
+ | `examples/governance-dao/` | Web: democratic AI governance with multi-sig approval |
270
+ | `examples/agent-marketplace/` | Web: hire agents, USDC escrow, reviews, reputation |
271
+
272
+ ## License
273
+
274
+ MIT
@@ -0,0 +1,30 @@
1
+ import {
2
+ InvarianceAtomicVerifierAbi,
3
+ InvarianceCompactLedgerAbi,
4
+ InvarianceEscrowAbi,
5
+ InvarianceHireAbi,
6
+ InvarianceIdentityAbi,
7
+ InvarianceIntentAbi,
8
+ InvarianceLedgerAbi,
9
+ InvariancePolicyAbi,
10
+ InvarianceRegistryAbi,
11
+ InvarianceReviewAbi,
12
+ InvarianceVotingAbi,
13
+ MockUSDCAbi
14
+ } from "./chunk-GHYGRZHM.js";
15
+ import "./chunk-VUNV25KB.js";
16
+ export {
17
+ InvarianceAtomicVerifierAbi,
18
+ InvarianceCompactLedgerAbi,
19
+ InvarianceEscrowAbi,
20
+ InvarianceHireAbi,
21
+ InvarianceIdentityAbi,
22
+ InvarianceIntentAbi,
23
+ InvarianceLedgerAbi,
24
+ InvariancePolicyAbi,
25
+ InvarianceRegistryAbi,
26
+ InvarianceReviewAbi,
27
+ InvarianceVotingAbi,
28
+ MockUSDCAbi
29
+ };
30
+ //# sourceMappingURL=abis-F52VBHAX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}