@enclave-e3/sdk 0.1.5 → 0.1.6
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 +65 -72
- package/dist/index.cjs +291 -202
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +186 -69
- package/dist/index.d.ts +186 -69
- package/dist/index.js +298 -217
- package/dist/index.js.map +1 -1
- package/package.json +23 -18
- package/LICENSE.md +0 -165
package/README.md
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
# Enclave TypeScript SDK
|
|
2
2
|
|
|
3
|
-
A powerful, type-safe TypeScript SDK for interacting with Enclave smart
|
|
4
|
-
|
|
5
|
-
methods, and comprehensive error handling.
|
|
3
|
+
A powerful, type-safe TypeScript SDK for interacting with Enclave smart contracts. This SDK provides
|
|
4
|
+
real-time event listening, contract interaction methods, and comprehensive error handling.
|
|
6
5
|
|
|
7
6
|
## Features
|
|
8
7
|
|
|
9
8
|
- **Event-driven architecture**: Listen to smart contract events in real-time
|
|
10
9
|
- **Type-safe**: Built with TypeScript and uses generated types from contracts
|
|
11
|
-
- **Easy contract interactions**: Simple methods for reading from and writing to
|
|
12
|
-
contracts
|
|
10
|
+
- **Easy contract interactions**: Simple methods for reading from and writing to contracts
|
|
13
11
|
- **React integration**: Includes React hooks for easy frontend integration
|
|
14
12
|
- **Error handling**: Comprehensive error handling with custom error types
|
|
15
13
|
- **Gas estimation**: Built-in gas estimation for transactions
|
|
16
|
-
- **Event polling**: Support for both WebSocket and polling-based event
|
|
17
|
-
listening
|
|
14
|
+
- **Event polling**: Support for both WebSocket and polling-based event listening
|
|
18
15
|
|
|
19
16
|
## Installation
|
|
20
17
|
|
|
@@ -25,60 +22,57 @@ pnpm add @enclave-e3/sdk
|
|
|
25
22
|
## Quick Start
|
|
26
23
|
|
|
27
24
|
```typescript
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
EnclaveEventType,
|
|
31
|
-
RegistryEventType,
|
|
32
|
-
} from "@enclave-e3/sdk";
|
|
33
|
-
import { createPublicClient, createWalletClient, http, custom } from "viem";
|
|
25
|
+
import { EnclaveSDK, EnclaveEventType, RegistryEventType } from '@enclave-e3/sdk'
|
|
26
|
+
import { createPublicClient, createWalletClient, http, custom } from 'viem'
|
|
34
27
|
|
|
35
28
|
// Initialize clients
|
|
36
29
|
const publicClient = createPublicClient({
|
|
37
|
-
transport: http(
|
|
38
|
-
})
|
|
30
|
+
transport: http('YOUR_RPC_URL'),
|
|
31
|
+
})
|
|
39
32
|
|
|
40
33
|
const walletClient = createWalletClient({
|
|
41
34
|
transport: custom(window.ethereum),
|
|
42
|
-
})
|
|
35
|
+
})
|
|
43
36
|
|
|
44
37
|
// Create SDK instance
|
|
45
38
|
const sdk = new EnclaveSDK({
|
|
46
39
|
publicClient,
|
|
47
40
|
walletClient,
|
|
48
41
|
contracts: {
|
|
49
|
-
enclave:
|
|
50
|
-
ciphernodeRegistry:
|
|
42
|
+
enclave: '0x...', // Your Enclave contract address
|
|
43
|
+
ciphernodeRegistry: '0x...', // Your CiphernodeRegistry contract address
|
|
51
44
|
},
|
|
52
45
|
chainId: 1, // Optional
|
|
53
|
-
})
|
|
46
|
+
})
|
|
54
47
|
|
|
55
48
|
// Initialize the SDK
|
|
56
|
-
await sdk.initialize()
|
|
49
|
+
await sdk.initialize()
|
|
57
50
|
|
|
58
51
|
// Listen to events with the unified event system
|
|
59
52
|
sdk.onEnclaveEvent(EnclaveEventType.E3_REQUESTED, (event) => {
|
|
60
|
-
console.log(
|
|
61
|
-
})
|
|
53
|
+
console.log('E3 Requested:', event.data)
|
|
54
|
+
})
|
|
62
55
|
|
|
63
56
|
sdk.onEnclaveEvent(RegistryEventType.CIPHERNODE_ADDED, (event) => {
|
|
64
|
-
console.log(
|
|
65
|
-
})
|
|
57
|
+
console.log('Ciphernode Added:', event.data)
|
|
58
|
+
})
|
|
66
59
|
|
|
67
60
|
// Interact with contracts
|
|
68
61
|
const hash = await sdk.requestE3({
|
|
69
|
-
filter: "0x...",
|
|
70
62
|
threshold: [1, 3],
|
|
71
63
|
startWindow: [BigInt(0), BigInt(100)],
|
|
72
64
|
duration: BigInt(3600),
|
|
73
|
-
e3Program:
|
|
74
|
-
e3ProgramParams:
|
|
75
|
-
computeProviderParams:
|
|
76
|
-
|
|
65
|
+
e3Program: '0x...',
|
|
66
|
+
e3ProgramParams: '0x...',
|
|
67
|
+
computeProviderParams: '0x...',
|
|
68
|
+
customParams: '0x...',
|
|
69
|
+
})
|
|
77
70
|
```
|
|
78
71
|
|
|
79
72
|
## Usage within a browser
|
|
80
73
|
|
|
81
|
-
Usage within a typescript project should work out of the box, however in order to use wasm related
|
|
74
|
+
Usage within a typescript project should work out of the box, however in order to use wasm related
|
|
75
|
+
functionality of the SDK within the browser vite you must do the following:
|
|
82
76
|
|
|
83
77
|
- Use `vite`
|
|
84
78
|
- Use the `vite-plugin-top-level-await` plugin
|
|
@@ -110,19 +104,19 @@ The SDK uses a unified event system with TypeScript enums for type safety:
|
|
|
110
104
|
```typescript
|
|
111
105
|
enum EnclaveEventType {
|
|
112
106
|
// E3 Lifecycle
|
|
113
|
-
E3_REQUESTED =
|
|
114
|
-
E3_ACTIVATED =
|
|
115
|
-
INPUT_PUBLISHED =
|
|
116
|
-
CIPHERTEXT_OUTPUT_PUBLISHED =
|
|
117
|
-
PLAINTEXT_OUTPUT_PUBLISHED =
|
|
107
|
+
E3_REQUESTED = 'E3Requested',
|
|
108
|
+
E3_ACTIVATED = 'E3Activated',
|
|
109
|
+
INPUT_PUBLISHED = 'InputPublished',
|
|
110
|
+
CIPHERTEXT_OUTPUT_PUBLISHED = 'CiphertextOutputPublished',
|
|
111
|
+
PLAINTEXT_OUTPUT_PUBLISHED = 'PlaintextOutputPublished',
|
|
118
112
|
|
|
119
113
|
// E3 Program Management
|
|
120
|
-
E3_PROGRAM_ENABLED =
|
|
121
|
-
E3_PROGRAM_DISABLED =
|
|
114
|
+
E3_PROGRAM_ENABLED = 'E3ProgramEnabled',
|
|
115
|
+
E3_PROGRAM_DISABLED = 'E3ProgramDisabled',
|
|
122
116
|
|
|
123
117
|
// Configuration
|
|
124
|
-
CIPHERNODE_REGISTRY_SET =
|
|
125
|
-
MAX_DURATION_SET =
|
|
118
|
+
CIPHERNODE_REGISTRY_SET = 'CiphernodeRegistrySet',
|
|
119
|
+
MAX_DURATION_SET = 'MaxDurationSet',
|
|
126
120
|
// ... more events
|
|
127
121
|
}
|
|
128
122
|
```
|
|
@@ -131,11 +125,12 @@ enum EnclaveEventType {
|
|
|
131
125
|
|
|
132
126
|
```typescript
|
|
133
127
|
enum RegistryEventType {
|
|
134
|
-
CIPHERNODE_ADDED =
|
|
135
|
-
CIPHERNODE_REMOVED =
|
|
136
|
-
COMMITTEE_REQUESTED =
|
|
137
|
-
COMMITTEE_PUBLISHED =
|
|
138
|
-
|
|
128
|
+
CIPHERNODE_ADDED = 'CiphernodeAdded',
|
|
129
|
+
CIPHERNODE_REMOVED = 'CiphernodeRemoved',
|
|
130
|
+
COMMITTEE_REQUESTED = 'CommitteeRequested',
|
|
131
|
+
COMMITTEE_PUBLISHED = 'CommitteePublished',
|
|
132
|
+
COMMITTEE_FINALIZED = 'CommitteeFinalized',
|
|
133
|
+
ENCLAVE_SET = 'EnclaveSet',
|
|
139
134
|
// ... more events
|
|
140
135
|
}
|
|
141
136
|
```
|
|
@@ -146,12 +141,12 @@ Each event follows a consistent structure:
|
|
|
146
141
|
|
|
147
142
|
```typescript
|
|
148
143
|
interface EnclaveEvent<T extends AllEventTypes> {
|
|
149
|
-
type: T
|
|
150
|
-
data: EventData[T]
|
|
151
|
-
log: Log
|
|
152
|
-
timestamp: Date
|
|
153
|
-
blockNumber: bigint
|
|
154
|
-
transactionHash: string
|
|
144
|
+
type: T
|
|
145
|
+
data: EventData[T] // Typed based on event type
|
|
146
|
+
log: Log // Raw viem log
|
|
147
|
+
timestamp: Date
|
|
148
|
+
blockNumber: bigint
|
|
149
|
+
transactionHash: string
|
|
155
150
|
}
|
|
156
151
|
```
|
|
157
152
|
|
|
@@ -160,7 +155,7 @@ interface EnclaveEvent<T extends AllEventTypes> {
|
|
|
160
155
|
The SDK includes a React hook for easy integration:
|
|
161
156
|
|
|
162
157
|
```typescript
|
|
163
|
-
import { useEnclaveSDK } from
|
|
158
|
+
import { useEnclaveSDK } from "@enclave-e3/contracts/sdk";
|
|
164
159
|
|
|
165
160
|
function MyComponent() {
|
|
166
161
|
const {
|
|
@@ -171,20 +166,20 @@ function MyComponent() {
|
|
|
171
166
|
connectWallet,
|
|
172
167
|
requestE3,
|
|
173
168
|
onEnclaveEvent,
|
|
174
|
-
EnclaveEventType
|
|
169
|
+
EnclaveEventType,
|
|
175
170
|
} = useEnclaveSDK({
|
|
176
171
|
contracts: {
|
|
177
|
-
enclave:
|
|
178
|
-
ciphernodeRegistry:
|
|
172
|
+
enclave: "0x...",
|
|
173
|
+
ciphernodeRegistry: "0x...",
|
|
179
174
|
},
|
|
180
|
-
rpcUrl:
|
|
181
|
-
autoConnect: true
|
|
175
|
+
rpcUrl: "YOUR_RPC_URL",
|
|
176
|
+
autoConnect: true,
|
|
182
177
|
});
|
|
183
178
|
|
|
184
179
|
useEffect(() => {
|
|
185
180
|
if (isInitialized) {
|
|
186
181
|
onEnclaveEvent(EnclaveEventType.E3_REQUESTED, (event) => {
|
|
187
|
-
console.log(
|
|
182
|
+
console.log("New E3 request:", event);
|
|
188
183
|
});
|
|
189
184
|
}
|
|
190
185
|
}, [isInitialized]);
|
|
@@ -193,7 +188,7 @@ function MyComponent() {
|
|
|
193
188
|
<div>
|
|
194
189
|
{!isInitialized && (
|
|
195
190
|
<button onClick={connectWallet} disabled={isConnecting}>
|
|
196
|
-
{isConnecting ?
|
|
191
|
+
{isConnecting ? "Connecting..." : "Connect Wallet"}
|
|
197
192
|
</button>
|
|
198
193
|
)}
|
|
199
194
|
{/* Your UI */}
|
|
@@ -211,14 +206,13 @@ function MyComponent() {
|
|
|
211
206
|
```typescript
|
|
212
207
|
// Request a new E3 computation
|
|
213
208
|
await sdk.requestE3({
|
|
214
|
-
filter: `0x${string}`,
|
|
215
209
|
threshold: [number, number],
|
|
216
210
|
startWindow: [bigint, bigint],
|
|
217
211
|
duration: bigint,
|
|
218
212
|
e3Program: `0x${string}`,
|
|
219
213
|
e3ProgramParams: `0x${string}`,
|
|
220
214
|
computeProviderParams: `0x${string}`,
|
|
221
|
-
|
|
215
|
+
customParams?: `0x${string}`,
|
|
222
216
|
gasLimit?: bigint
|
|
223
217
|
});
|
|
224
218
|
|
|
@@ -270,13 +264,13 @@ sdk.cleanup();
|
|
|
270
264
|
|
|
271
265
|
```typescript
|
|
272
266
|
interface SDKConfig {
|
|
273
|
-
publicClient: PublicClient
|
|
274
|
-
walletClient?: WalletClient
|
|
267
|
+
publicClient: PublicClient
|
|
268
|
+
walletClient?: WalletClient
|
|
275
269
|
contracts: {
|
|
276
|
-
enclave: `0x${string}
|
|
277
|
-
ciphernodeRegistry: `0x${string}
|
|
278
|
-
}
|
|
279
|
-
chainId?: number
|
|
270
|
+
enclave: `0x${string}`
|
|
271
|
+
ciphernodeRegistry: `0x${string}`
|
|
272
|
+
}
|
|
273
|
+
chainId?: number
|
|
280
274
|
}
|
|
281
275
|
```
|
|
282
276
|
|
|
@@ -285,15 +279,15 @@ interface SDKConfig {
|
|
|
285
279
|
The SDK includes comprehensive error handling:
|
|
286
280
|
|
|
287
281
|
```typescript
|
|
288
|
-
import { SDKError } from
|
|
282
|
+
import { SDKError } from '@enclave-e3/sdk'
|
|
289
283
|
|
|
290
284
|
try {
|
|
291
|
-
await sdk.requestE3(params)
|
|
285
|
+
await sdk.requestE3(params)
|
|
292
286
|
} catch (error) {
|
|
293
287
|
if (error instanceof SDKError) {
|
|
294
|
-
console.error(`SDK Error (${error.code}): ${error.message}`)
|
|
288
|
+
console.error(`SDK Error (${error.code}): ${error.message}`)
|
|
295
289
|
} else {
|
|
296
|
-
console.error(
|
|
290
|
+
console.error('Unexpected error:', error)
|
|
297
291
|
}
|
|
298
292
|
}
|
|
299
293
|
```
|
|
@@ -315,8 +309,7 @@ pnpm install
|
|
|
315
309
|
pnpm dev
|
|
316
310
|
```
|
|
317
311
|
|
|
318
|
-
The demo showcases all SDK features including real-time event listening and
|
|
319
|
-
contract interactions.
|
|
312
|
+
The demo showcases all SDK features including real-time event listening and contract interactions.
|
|
320
313
|
|
|
321
314
|
### Testing
|
|
322
315
|
|