cilantro-sdk 0.0.13 → 0.0.15
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 +540 -316
- package/dist/admin.cjs +40 -1
- package/dist/admin.cjs.map +2 -2
- package/dist/admin.mjs +40 -1
- package/dist/admin.mjs.map +2 -2
- package/dist/api/admin/admin.d.ts +11 -1
- package/dist/api/admin/admin.d.ts.map +1 -1
- package/dist/api/auth/auth.d.ts +9 -1
- package/dist/api/auth/auth.d.ts.map +1 -1
- package/dist/api/health/health.d.ts +7 -0
- package/dist/api/health/health.d.ts.map +1 -1
- package/dist/api/platforms/platforms.d.ts +23 -1
- package/dist/api/platforms/platforms.d.ts.map +1 -1
- package/dist/api/public/public.d.ts +17 -0
- package/dist/api/public/public.d.ts.map +1 -0
- package/dist/api/subscriptions/subscriptions.d.ts +32 -0
- package/dist/api/subscriptions/subscriptions.d.ts.map +1 -0
- package/dist/api/users/users.d.ts +3 -1
- package/dist/api/users/users.d.ts.map +1 -1
- package/dist/api/wallets/wallets.d.ts +7 -1
- package/dist/api/wallets/wallets.d.ts.map +1 -1
- package/dist/auth.cjs +51 -1
- package/dist/auth.cjs.map +2 -2
- package/dist/auth.mjs +51 -1
- package/dist/auth.mjs.map +2 -2
- package/dist/delegated-keys.cjs +173 -0
- package/dist/delegated-keys.cjs.map +7 -0
- package/dist/delegated-keys.d.ts +11 -0
- package/dist/delegated-keys.d.ts.map +1 -0
- package/dist/delegated-keys.mjs +132 -0
- package/dist/delegated-keys.mjs.map +7 -0
- package/dist/helpers.cjs +37 -1
- package/dist/helpers.cjs.map +2 -2
- package/dist/helpers.mjs +37 -1
- package/dist/helpers.mjs.map +2 -2
- package/dist/index.cjs +777 -7
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +761 -6
- package/dist/index.mjs.map +4 -4
- package/dist/models/adminControllerGetPlatformActivityTimelineParams.d.ts +14 -0
- package/dist/models/adminControllerGetPlatformActivityTimelineParams.d.ts.map +1 -0
- package/dist/models/adminControllerGetPlatformGrowthTrendsParams.d.ts +15 -0
- package/dist/models/adminControllerGetPlatformGrowthTrendsParams.d.ts.map +1 -0
- package/dist/models/adminControllerGetPlatformGrowthTrendsPeriod.d.ts +14 -0
- package/dist/models/adminControllerGetPlatformGrowthTrendsPeriod.d.ts.map +1 -0
- package/dist/models/adminControllerGetTopPlatformsMetric.d.ts +14 -0
- package/dist/models/adminControllerGetTopPlatformsMetric.d.ts.map +1 -0
- package/dist/models/adminControllerGetTopPlatformsParams.d.ts +19 -0
- package/dist/models/adminControllerGetTopPlatformsParams.d.ts.map +1 -0
- package/dist/models/cancelSubscriptionDto.d.ts +17 -0
- package/dist/models/cancelSubscriptionDto.d.ts.map +1 -0
- package/dist/models/cancelSubscriptionDtoMetadata.d.ts +14 -0
- package/dist/models/cancelSubscriptionDtoMetadata.d.ts.map +1 -0
- package/dist/models/changePasswordDto.d.ts +17 -0
- package/dist/models/changePasswordDto.d.ts.map +1 -0
- package/dist/models/confirmPaymentDto.d.ts +14 -0
- package/dist/models/confirmPaymentDto.d.ts.map +1 -0
- package/dist/models/createPlatformDto.d.ts +7 -0
- package/dist/models/createPlatformDto.d.ts.map +1 -1
- package/dist/models/createPlatformDtoBillingCycle.d.ts +16 -0
- package/dist/models/createPlatformDtoBillingCycle.d.ts.map +1 -0
- package/dist/models/createSubscriptionDto.d.ts +24 -0
- package/dist/models/createSubscriptionDto.d.ts.map +1 -0
- package/dist/models/createSubscriptionDtoBillingCycle.d.ts +16 -0
- package/dist/models/createSubscriptionDtoBillingCycle.d.ts.map +1 -0
- package/dist/models/createSubscriptionDtoMetadata.d.ts +14 -0
- package/dist/models/createSubscriptionDtoMetadata.d.ts.map +1 -0
- package/dist/models/downgradeSubscriptionDto.d.ts +17 -0
- package/dist/models/downgradeSubscriptionDto.d.ts.map +1 -0
- package/dist/models/downgradeSubscriptionDtoMetadata.d.ts +14 -0
- package/dist/models/downgradeSubscriptionDtoMetadata.d.ts.map +1 -0
- package/dist/models/executeInstructionParamsDto.d.ts +17 -0
- package/dist/models/executeInstructionParamsDto.d.ts.map +1 -0
- package/dist/models/executeInstructionParamsDtoAccountsItem.d.ts +13 -0
- package/dist/models/executeInstructionParamsDtoAccountsItem.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200.d.ts +19 -0
- package/dist/models/healthControllerGetHealth200.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200Checks.d.ts +16 -0
- package/dist/models/healthControllerGetHealth200Checks.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200ChecksDatabase.d.ts +16 -0
- package/dist/models/healthControllerGetHealth200ChecksDatabase.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200ChecksDatabaseStatus.d.ts +13 -0
- package/dist/models/healthControllerGetHealth200ChecksDatabaseStatus.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200ChecksRedis.d.ts +16 -0
- package/dist/models/healthControllerGetHealth200ChecksRedis.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200ChecksRedisStatus.d.ts +13 -0
- package/dist/models/healthControllerGetHealth200ChecksRedisStatus.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200ChecksSolanaRpc.d.ts +16 -0
- package/dist/models/healthControllerGetHealth200ChecksSolanaRpc.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200ChecksSolanaRpcStatus.d.ts +13 -0
- package/dist/models/healthControllerGetHealth200ChecksSolanaRpcStatus.d.ts.map +1 -0
- package/dist/models/healthControllerGetHealth200Status.d.ts +17 -0
- package/dist/models/healthControllerGetHealth200Status.d.ts.map +1 -0
- package/dist/models/index.d.ts +48 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/linkPaymentDto.d.ts +14 -0
- package/dist/models/linkPaymentDto.d.ts.map +1 -0
- package/dist/models/passwordResetConfirmDto.d.ts +17 -0
- package/dist/models/passwordResetConfirmDto.d.ts.map +1 -0
- package/dist/models/passwordResetRequestDto.d.ts +12 -0
- package/dist/models/passwordResetRequestDto.d.ts.map +1 -0
- package/dist/models/prepareTransactionDto.d.ts +24 -0
- package/dist/models/prepareTransactionDto.d.ts.map +1 -0
- package/dist/models/prepareTransactionDtoType.d.ts +17 -0
- package/dist/models/prepareTransactionDtoType.d.ts.map +1 -0
- package/dist/models/renewSubscriptionDto.d.ts +15 -0
- package/dist/models/renewSubscriptionDto.d.ts.map +1 -0
- package/dist/models/renewSubscriptionDtoMetadata.d.ts +14 -0
- package/dist/models/renewSubscriptionDtoMetadata.d.ts.map +1 -0
- package/dist/models/sendSolParamsDto.d.ts +14 -0
- package/dist/models/sendSolParamsDto.d.ts.map +1 -0
- package/dist/models/sendTokenParamsDto.d.ts +16 -0
- package/dist/models/sendTokenParamsDto.d.ts.map +1 -0
- package/dist/models/signMessageDto.d.ts +12 -0
- package/dist/models/signMessageDto.d.ts.map +1 -0
- package/dist/models/submitTransactionDto.d.ts +12 -0
- package/dist/models/submitTransactionDto.d.ts.map +1 -0
- package/dist/models/subscriptionControllerFindAllParams.d.ts +31 -0
- package/dist/models/subscriptionControllerFindAllParams.d.ts.map +1 -0
- package/dist/models/subscriptionControllerFindAllStatus.d.ts +16 -0
- package/dist/models/subscriptionControllerFindAllStatus.d.ts.map +1 -0
- package/dist/models/upgradeSubscriptionDto.d.ts +17 -0
- package/dist/models/upgradeSubscriptionDto.d.ts.map +1 -0
- package/dist/models/upgradeSubscriptionDtoMetadata.d.ts +14 -0
- package/dist/models/upgradeSubscriptionDtoMetadata.d.ts.map +1 -0
- package/dist/models/verifyEmailDto.d.ts +12 -0
- package/dist/models/verifyEmailDto.d.ts.map +1 -0
- package/dist/models/walletControllerPrepareTransaction200.d.ts +13 -0
- package/dist/models/walletControllerPrepareTransaction200.d.ts.map +1 -0
- package/dist/models/walletControllerPrepareTransaction200Data.d.ts +16 -0
- package/dist/models/walletControllerPrepareTransaction200Data.d.ts.map +1 -0
- package/dist/models/walletControllerSignMessage200.d.ts +13 -0
- package/dist/models/walletControllerSignMessage200.d.ts.map +1 -0
- package/dist/models/walletControllerSignMessage200Data.d.ts +16 -0
- package/dist/models/walletControllerSignMessage200Data.d.ts.map +1 -0
- package/dist/models/walletControllerSubmitTransaction200.d.ts +13 -0
- package/dist/models/walletControllerSubmitTransaction200.d.ts.map +1 -0
- package/dist/models/walletControllerSubmitTransaction200Data.d.ts +12 -0
- package/dist/models/walletControllerSubmitTransaction200Data.d.ts.map +1 -0
- package/dist/plans.cjs +198 -0
- package/dist/plans.cjs.map +7 -0
- package/dist/plans.d.ts +12 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.mjs +156 -0
- package/dist/plans.mjs.map +7 -0
- package/dist/platform.cjs +119 -1
- package/dist/platform.cjs.map +2 -2
- package/dist/platform.mjs +119 -1
- package/dist/platform.mjs.map +2 -2
- package/dist/subscriptions.cjs +232 -0
- package/dist/subscriptions.cjs.map +7 -0
- package/dist/subscriptions.d.ts +15 -0
- package/dist/subscriptions.d.ts.map +1 -0
- package/dist/subscriptions.mjs +187 -0
- package/dist/subscriptions.mjs.map +7 -0
- package/dist/transactions.cjs +130 -0
- package/dist/transactions.cjs.map +7 -0
- package/dist/transactions.d.ts +8 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.mjs +92 -0
- package/dist/transactions.mjs.map +7 -0
- package/dist/user.cjs +17 -1
- package/dist/user.cjs.map +2 -2
- package/dist/user.mjs +17 -1
- package/dist/user.mjs.map +2 -2
- package/dist/wallet.cjs +37 -1
- package/dist/wallet.cjs.map +2 -2
- package/dist/wallet.mjs +37 -1
- package/dist/wallet.mjs.map +2 -2
- package/dist/webhooks.cjs +173 -0
- package/dist/webhooks.cjs.map +7 -0
- package/dist/webhooks.d.ts +11 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.mjs +132 -0
- package/dist/webhooks.mjs.map +7 -0
- package/package.json +51 -1
package/README.md
CHANGED
|
@@ -1,316 +1,540 @@
|
|
|
1
|
-
# Cilantro Smart SDK
|
|
2
|
-
|
|
3
|
-
A TypeScript/JavaScript SDK for interacting with the Cilantro Smart API - A Solana wallet management system.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install cilantro-sdk
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
### Option 1: Using API Key (Recommended for Server-Side)
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { configure } from 'cilantro-sdk';
|
|
17
|
-
import { sendSOL } from 'cilantro-sdk/wallet';
|
|
18
|
-
|
|
19
|
-
// Configure SDK with your API key
|
|
20
|
-
configure({
|
|
21
|
-
apiKey: 'your-api-key-here'
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Make authenticated requests
|
|
25
|
-
const result = await sendSOL('wallet-id', {
|
|
26
|
-
recipientAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
|
|
27
|
-
amountLamports: 1000000000
|
|
28
|
-
});
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Option 2: Using Login (For User Authentication)
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
import { loginAndSetAuth } from 'cilantro-sdk/auth';
|
|
35
|
-
import { sendSOL } from 'cilantro-sdk/wallet';
|
|
36
|
-
|
|
37
|
-
// Login and set authentication automatically
|
|
38
|
-
await loginAndSetAuth({
|
|
39
|
-
usernameOrEmail: 'user@example.com',
|
|
40
|
-
password: 'SecurePass123!'
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Make authenticated requests
|
|
44
|
-
const result = await sendSOL('wallet-id', {
|
|
45
|
-
recipientAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
|
|
46
|
-
amountLamports: 1000000000
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Option 3: Manual Authentication Control
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import { setAuth } from 'cilantro-sdk';
|
|
54
|
-
import { login } from 'cilantro-sdk/auth';
|
|
55
|
-
import { sendSOL } from 'cilantro-sdk/wallet';
|
|
56
|
-
|
|
57
|
-
// Login without automatically setting auth
|
|
58
|
-
const authResult = await login({
|
|
59
|
-
usernameOrEmail: 'user@example.com',
|
|
60
|
-
password: 'password123'
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Manually set authentication
|
|
64
|
-
setAuth({ jwt: authResult.data.jwt });
|
|
65
|
-
|
|
66
|
-
// Make authenticated requests
|
|
67
|
-
const result = await sendSOL('wallet-id', {
|
|
68
|
-
recipientAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
|
|
69
|
-
amountLamports: 1000000000
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### CommonJS
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
const { configure } = require('cilantro-sdk');
|
|
77
|
-
const { sendSOL } = require('cilantro-sdk/wallet');
|
|
78
|
-
|
|
79
|
-
// Configure with API key
|
|
80
|
-
configure({ apiKey: 'your-api-key' });
|
|
81
|
-
|
|
82
|
-
// Make authenticated requests
|
|
83
|
-
const result = await sendSOL('wallet-id', { ... });
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Helpers Module - Device Keys & Signer Management
|
|
87
|
-
|
|
88
|
-
The SDK includes a comprehensive helpers module for device key management and signer operations. This simplifies working with email/phone signers and provides automatic device key resolution, validation, and caching.
|
|
89
|
-
|
|
90
|
-
### Quick Example
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
import {
|
|
94
|
-
createEmailSignerHelper,
|
|
95
|
-
getEmailSignerKeypair,
|
|
96
|
-
createLocalStorageAdapter
|
|
97
|
-
} from 'cilantro-sdk/helpers';
|
|
98
|
-
|
|
99
|
-
// Create storage for device keys
|
|
100
|
-
const storage = createLocalStorageAdapter();
|
|
101
|
-
|
|
102
|
-
// Create email signer (device key generated automatically)
|
|
103
|
-
const signer = await createEmailSignerHelper('wallet-id', {
|
|
104
|
-
email: 'user@example.com',
|
|
105
|
-
deviceKeyManager: storage
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Get keypair - SDK automatically:
|
|
109
|
-
// 1. Fetches signer from API
|
|
110
|
-
// 2. Extracts devicePublicKey and deviceId
|
|
111
|
-
// 3. Resolves device key from storage
|
|
112
|
-
// 4. Validates device key matches API
|
|
113
|
-
const keypair = await getEmailSignerKeypair(
|
|
114
|
-
'wallet-id',
|
|
115
|
-
signer.signerId,
|
|
116
|
-
{
|
|
117
|
-
deviceKeyManager: storage
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Key Features
|
|
123
|
-
|
|
124
|
-
- ✅ **Fully Automatic Resolution** - Automatically fetches signer, extracts device info, and resolves device keys
|
|
125
|
-
- ✅ **Automatic Caching** - Keypair derivation is cached to avoid redundant operations
|
|
126
|
-
- ✅ **Device Key Validation** - Prevents mismatches between storage and API
|
|
127
|
-
- ✅ **Multi-Device Support** - Handle multiple devices per signer
|
|
128
|
-
- ✅ **Cross-Platform** - Works in browser and Node.js
|
|
129
|
-
- ✅ **Storage Adapters** - localStorage, filesystem, or memory storage
|
|
130
|
-
- ✅ **Type-Safe** - Full TypeScript support
|
|
131
|
-
- ✅ **Functional** - No classes, pure functions
|
|
132
|
-
|
|
133
|
-
### Available Helpers
|
|
134
|
-
|
|
135
|
-
**Device Key Management:**
|
|
136
|
-
- `getDevicePublicKey()` - Get or create device key with caching
|
|
137
|
-
- `generateDeviceKeyPair()` - Generate new device key pair
|
|
138
|
-
- `rotateDeviceKey()` - Rotate device keys
|
|
139
|
-
- `clearDeviceKeyCache()` - Clear cache
|
|
140
|
-
- `findDeviceKeyByPublicKey()` - Find device key by public key
|
|
141
|
-
- `listAllDeviceKeys()` - List all device keys with metadata
|
|
142
|
-
|
|
143
|
-
**Email Signer Helpers:**
|
|
144
|
-
- `createEmailSignerHelper()` - Create email signer with automatic device key generation
|
|
145
|
-
- `getEmailSignerKeypair()` - Get keypair with automatic device key resolution
|
|
146
|
-
- `signWithEmailSigner()` - Sign messages with email signer
|
|
147
|
-
- `getEmailSignerByEmail()` - Find email signer by email address
|
|
148
|
-
|
|
149
|
-
**Phone Signer Helpers:**
|
|
150
|
-
- `createPhoneSignerHelper()` - Create phone signer with automatic device key generation
|
|
151
|
-
- `getPhoneSignerKeypair()` - Get keypair with automatic device key resolution
|
|
152
|
-
- `signWithPhoneSigner()` - Sign messages with phone signer
|
|
153
|
-
- `getPhoneSignerByPhone()` - Find phone signer by phone number
|
|
154
|
-
|
|
155
|
-
**Device Key Validation & Resolution:**
|
|
156
|
-
- `getSignerDeviceKeys()` - Get all device keys for a signer from API
|
|
157
|
-
- `validateDeviceKey()` - Validate device key matches API
|
|
158
|
-
- `resolveDeviceKey()` - Automatically find matching device key
|
|
159
|
-
- `getBestDeviceIdentity()` - Get most recently used device identity
|
|
160
|
-
|
|
161
|
-
**Device Identity Management:**
|
|
162
|
-
- `addDeviceIdentityToSigner()` - Add new device to existing signer
|
|
163
|
-
- `replaceDeviceIdentity()` - Replace existing device identity
|
|
164
|
-
- `addNewDeviceToSigner()` - Convenience function for adding new device
|
|
165
|
-
- `canAddDeviceToSigner()` - Check if device can be added
|
|
166
|
-
|
|
167
|
-
**Storage Adapters:**
|
|
168
|
-
- `createLocalStorageAdapter()` - Browser localStorage adapter
|
|
169
|
-
- `createFileSystemAdapter()` - Node.js filesystem adapter
|
|
170
|
-
- `createMemoryAdapter()` - In-memory adapter (for testing)
|
|
171
|
-
- `getDefaultStorageAdapter()` - Get platform-appropriate adapter
|
|
172
|
-
|
|
173
|
-
For detailed documentation on device key management, see [DEVICE_KEY_MANAGEMENT.md](./DEVICE_KEY_MANAGEMENT.md).
|
|
174
|
-
|
|
175
|
-
## Configuration
|
|
176
|
-
|
|
177
|
-
### `configure(config)`
|
|
178
|
-
|
|
179
|
-
Initialize the SDK with configuration options.
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
import { configure } from 'cilantro-sdk';
|
|
183
|
-
|
|
184
|
-
configure({
|
|
185
|
-
apiKey: 'your-api-key',
|
|
186
|
-
jwt: 'your-jwt-token', // Optional
|
|
187
|
-
baseURL: 'https://api.cilantro.gg' // Optional: Custom API base URL
|
|
188
|
-
});
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### `setAuth(auth)`
|
|
192
|
-
|
|
193
|
-
Update authentication credentials after initialization.
|
|
194
|
-
|
|
195
|
-
```typescript
|
|
196
|
-
import { setAuth } from 'cilantro-sdk';
|
|
197
|
-
|
|
198
|
-
setAuth({
|
|
199
|
-
jwt: 'your-jwt-token',
|
|
200
|
-
apiKey: 'your-api-key'
|
|
201
|
-
});
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
### `clearAuth()`
|
|
205
|
-
|
|
206
|
-
Clear all authentication credentials.
|
|
207
|
-
|
|
208
|
-
```typescript
|
|
209
|
-
import { clearAuth } from 'cilantro-sdk';
|
|
210
|
-
|
|
211
|
-
clearAuth();
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
### Authentication Types
|
|
215
|
-
|
|
216
|
-
The SDK supports two types of authentication:
|
|
217
|
-
|
|
218
|
-
1. **API Key Authentication**: For server-side applications and platform-level access
|
|
219
|
-
2. **JWT Token Authentication**: For user-specific operations after login
|
|
220
|
-
|
|
221
|
-
You can use either or both simultaneously. The SDK will automatically include the appropriate headers in all requests.
|
|
222
|
-
|
|
223
|
-
## Module Structure
|
|
224
|
-
|
|
225
|
-
The SDK is organized into modules for better code organization:
|
|
226
|
-
|
|
227
|
-
- **Platform** (`cilantro-sdk/platform`) - Platform management and user operations
|
|
228
|
-
- **User** (`cilantro-sdk/user`) - User account operations
|
|
229
|
-
- **Wallet** (`cilantro-sdk/wallet`) - Wallet and blockchain operations
|
|
230
|
-
- **Admin** (`cilantro-sdk/admin`) - Administrative operations
|
|
231
|
-
- **Auth** (`cilantro-sdk/auth`) - Universal authentication
|
|
232
|
-
- **
|
|
233
|
-
- **
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
**
|
|
238
|
-
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
**
|
|
243
|
-
- `create`, `findOne`, `update`
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
-
|
|
252
|
-
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
-
|
|
256
|
-
- `
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
1
|
+
# Cilantro Smart SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript/JavaScript SDK for interacting with the Cilantro Smart API - A Solana wallet management system.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install cilantro-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Option 1: Using API Key (Recommended for Server-Side)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { configure } from 'cilantro-sdk';
|
|
17
|
+
import { sendSOL } from 'cilantro-sdk/wallet';
|
|
18
|
+
|
|
19
|
+
// Configure SDK with your API key
|
|
20
|
+
configure({
|
|
21
|
+
apiKey: 'your-api-key-here'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Make authenticated requests
|
|
25
|
+
const result = await sendSOL('wallet-id', {
|
|
26
|
+
recipientAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
|
|
27
|
+
amountLamports: 1000000000
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Option 2: Using Login (For User Authentication)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { loginAndSetAuth } from 'cilantro-sdk/auth';
|
|
35
|
+
import { sendSOL } from 'cilantro-sdk/wallet';
|
|
36
|
+
|
|
37
|
+
// Login and set authentication automatically
|
|
38
|
+
await loginAndSetAuth({
|
|
39
|
+
usernameOrEmail: 'user@example.com',
|
|
40
|
+
password: 'SecurePass123!'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Make authenticated requests
|
|
44
|
+
const result = await sendSOL('wallet-id', {
|
|
45
|
+
recipientAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
|
|
46
|
+
amountLamports: 1000000000
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Option 3: Manual Authentication Control
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { setAuth } from 'cilantro-sdk';
|
|
54
|
+
import { login } from 'cilantro-sdk/auth';
|
|
55
|
+
import { sendSOL } from 'cilantro-sdk/wallet';
|
|
56
|
+
|
|
57
|
+
// Login without automatically setting auth
|
|
58
|
+
const authResult = await login({
|
|
59
|
+
usernameOrEmail: 'user@example.com',
|
|
60
|
+
password: 'password123'
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Manually set authentication
|
|
64
|
+
setAuth({ jwt: authResult.data.jwt });
|
|
65
|
+
|
|
66
|
+
// Make authenticated requests
|
|
67
|
+
const result = await sendSOL('wallet-id', {
|
|
68
|
+
recipientAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
|
|
69
|
+
amountLamports: 1000000000
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### CommonJS
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const { configure } = require('cilantro-sdk');
|
|
77
|
+
const { sendSOL } = require('cilantro-sdk/wallet');
|
|
78
|
+
|
|
79
|
+
// Configure with API key
|
|
80
|
+
configure({ apiKey: 'your-api-key' });
|
|
81
|
+
|
|
82
|
+
// Make authenticated requests
|
|
83
|
+
const result = await sendSOL('wallet-id', { ... });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Helpers Module - Device Keys & Signer Management
|
|
87
|
+
|
|
88
|
+
The SDK includes a comprehensive helpers module for device key management and signer operations. This simplifies working with email/phone signers and provides automatic device key resolution, validation, and caching.
|
|
89
|
+
|
|
90
|
+
### Quick Example
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import {
|
|
94
|
+
createEmailSignerHelper,
|
|
95
|
+
getEmailSignerKeypair,
|
|
96
|
+
createLocalStorageAdapter
|
|
97
|
+
} from 'cilantro-sdk/helpers';
|
|
98
|
+
|
|
99
|
+
// Create storage for device keys
|
|
100
|
+
const storage = createLocalStorageAdapter();
|
|
101
|
+
|
|
102
|
+
// Create email signer (device key generated automatically)
|
|
103
|
+
const signer = await createEmailSignerHelper('wallet-id', {
|
|
104
|
+
email: 'user@example.com',
|
|
105
|
+
deviceKeyManager: storage
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Get keypair - SDK automatically:
|
|
109
|
+
// 1. Fetches signer from API
|
|
110
|
+
// 2. Extracts devicePublicKey and deviceId
|
|
111
|
+
// 3. Resolves device key from storage
|
|
112
|
+
// 4. Validates device key matches API
|
|
113
|
+
const keypair = await getEmailSignerKeypair(
|
|
114
|
+
'wallet-id',
|
|
115
|
+
signer.signerId,
|
|
116
|
+
{
|
|
117
|
+
deviceKeyManager: storage
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Key Features
|
|
123
|
+
|
|
124
|
+
- ✅ **Fully Automatic Resolution** - Automatically fetches signer, extracts device info, and resolves device keys
|
|
125
|
+
- ✅ **Automatic Caching** - Keypair derivation is cached to avoid redundant operations
|
|
126
|
+
- ✅ **Device Key Validation** - Prevents mismatches between storage and API
|
|
127
|
+
- ✅ **Multi-Device Support** - Handle multiple devices per signer
|
|
128
|
+
- ✅ **Cross-Platform** - Works in browser and Node.js
|
|
129
|
+
- ✅ **Storage Adapters** - localStorage, filesystem, or memory storage
|
|
130
|
+
- ✅ **Type-Safe** - Full TypeScript support
|
|
131
|
+
- ✅ **Functional** - No classes, pure functions
|
|
132
|
+
|
|
133
|
+
### Available Helpers
|
|
134
|
+
|
|
135
|
+
**Device Key Management:**
|
|
136
|
+
- `getDevicePublicKey()` - Get or create device key with caching
|
|
137
|
+
- `generateDeviceKeyPair()` - Generate new device key pair
|
|
138
|
+
- `rotateDeviceKey()` - Rotate device keys
|
|
139
|
+
- `clearDeviceKeyCache()` - Clear cache
|
|
140
|
+
- `findDeviceKeyByPublicKey()` - Find device key by public key
|
|
141
|
+
- `listAllDeviceKeys()` - List all device keys with metadata
|
|
142
|
+
|
|
143
|
+
**Email Signer Helpers:**
|
|
144
|
+
- `createEmailSignerHelper()` - Create email signer with automatic device key generation
|
|
145
|
+
- `getEmailSignerKeypair()` - Get keypair with automatic device key resolution
|
|
146
|
+
- `signWithEmailSigner()` - Sign messages with email signer
|
|
147
|
+
- `getEmailSignerByEmail()` - Find email signer by email address
|
|
148
|
+
|
|
149
|
+
**Phone Signer Helpers:**
|
|
150
|
+
- `createPhoneSignerHelper()` - Create phone signer with automatic device key generation
|
|
151
|
+
- `getPhoneSignerKeypair()` - Get keypair with automatic device key resolution
|
|
152
|
+
- `signWithPhoneSigner()` - Sign messages with phone signer
|
|
153
|
+
- `getPhoneSignerByPhone()` - Find phone signer by phone number
|
|
154
|
+
|
|
155
|
+
**Device Key Validation & Resolution:**
|
|
156
|
+
- `getSignerDeviceKeys()` - Get all device keys for a signer from API
|
|
157
|
+
- `validateDeviceKey()` - Validate device key matches API
|
|
158
|
+
- `resolveDeviceKey()` - Automatically find matching device key
|
|
159
|
+
- `getBestDeviceIdentity()` - Get most recently used device identity
|
|
160
|
+
|
|
161
|
+
**Device Identity Management:**
|
|
162
|
+
- `addDeviceIdentityToSigner()` - Add new device to existing signer
|
|
163
|
+
- `replaceDeviceIdentity()` - Replace existing device identity
|
|
164
|
+
- `addNewDeviceToSigner()` - Convenience function for adding new device
|
|
165
|
+
- `canAddDeviceToSigner()` - Check if device can be added
|
|
166
|
+
|
|
167
|
+
**Storage Adapters:**
|
|
168
|
+
- `createLocalStorageAdapter()` - Browser localStorage adapter
|
|
169
|
+
- `createFileSystemAdapter()` - Node.js filesystem adapter
|
|
170
|
+
- `createMemoryAdapter()` - In-memory adapter (for testing)
|
|
171
|
+
- `getDefaultStorageAdapter()` - Get platform-appropriate adapter
|
|
172
|
+
|
|
173
|
+
For detailed documentation on device key management, see [DEVICE_KEY_MANAGEMENT.md](./DEVICE_KEY_MANAGEMENT.md).
|
|
174
|
+
|
|
175
|
+
## Configuration
|
|
176
|
+
|
|
177
|
+
### `configure(config)`
|
|
178
|
+
|
|
179
|
+
Initialize the SDK with configuration options.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { configure } from 'cilantro-sdk';
|
|
183
|
+
|
|
184
|
+
configure({
|
|
185
|
+
apiKey: 'your-api-key',
|
|
186
|
+
jwt: 'your-jwt-token', // Optional
|
|
187
|
+
baseURL: 'https://api.cilantro.gg' // Optional: Custom API base URL
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### `setAuth(auth)`
|
|
192
|
+
|
|
193
|
+
Update authentication credentials after initialization.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import { setAuth } from 'cilantro-sdk';
|
|
197
|
+
|
|
198
|
+
setAuth({
|
|
199
|
+
jwt: 'your-jwt-token',
|
|
200
|
+
apiKey: 'your-api-key'
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### `clearAuth()`
|
|
205
|
+
|
|
206
|
+
Clear all authentication credentials.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { clearAuth } from 'cilantro-sdk';
|
|
210
|
+
|
|
211
|
+
clearAuth();
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Authentication Types
|
|
215
|
+
|
|
216
|
+
The SDK supports two types of authentication:
|
|
217
|
+
|
|
218
|
+
1. **API Key Authentication**: For server-side applications and platform-level access
|
|
219
|
+
2. **JWT Token Authentication**: For user-specific operations after login
|
|
220
|
+
|
|
221
|
+
You can use either or both simultaneously. The SDK will automatically include the appropriate headers in all requests.
|
|
222
|
+
|
|
223
|
+
## Module Structure
|
|
224
|
+
|
|
225
|
+
The SDK is organized into modules for better code organization:
|
|
226
|
+
|
|
227
|
+
- **Platform** (`cilantro-sdk/platform`) - Platform management and user operations
|
|
228
|
+
- **User** (`cilantro-sdk/user`) - User account operations
|
|
229
|
+
- **Wallet** (`cilantro-sdk/wallet`) - Wallet and blockchain operations
|
|
230
|
+
- **Admin** (`cilantro-sdk/admin`) - Administrative operations
|
|
231
|
+
- **Auth** (`cilantro-sdk/auth`) - Universal authentication
|
|
232
|
+
- **Subscriptions** (`cilantro-sdk/subscriptions`) - Subscription management operations
|
|
233
|
+
- **Plans** (`cilantro-sdk/plans`) - Subscription plan management operations
|
|
234
|
+
- **Transactions** (`cilantro-sdk/transactions`) - Transaction history and status queries
|
|
235
|
+
- **Delegated Keys** (`cilantro-sdk/delegated-keys`) - Temporary key management for session-based signing
|
|
236
|
+
- **Webhooks** (`cilantro-sdk/webhooks`) - Webhook endpoint management for event notifications
|
|
237
|
+
- **Utils** (`cilantro-sdk/utils`) - Utility functions
|
|
238
|
+
- **Helpers** (`cilantro-sdk/helpers`) - Device key management and signer helpers
|
|
239
|
+
|
|
240
|
+
### Quick Reference
|
|
241
|
+
|
|
242
|
+
**Platform Module:**
|
|
243
|
+
- Basic: `create`, `findAll`, `findOne`, `update`, `remove`, `getOwnProfile`, `updateOwnProfile`
|
|
244
|
+
- Users: `getUsers`, `createUser`, `updateUser`, `removeUser`, `toggleUserActive`
|
|
245
|
+
- Wallets: `getWallets` (read-only)
|
|
246
|
+
|
|
247
|
+
**User Module:**
|
|
248
|
+
- `create`, `findOne`, `update`
|
|
249
|
+
|
|
250
|
+
**Wallet Module:**
|
|
251
|
+
- Basic: `create`, `findAll`, `findOne`, `update`, `remove`, `findByAddress`, `getTotalBalance`
|
|
252
|
+
- Status: `activate`, `deactivate`
|
|
253
|
+
- Transactions: `sendSOL`, `sendSPL`, `sendTransaction`, `simulateTransaction`
|
|
254
|
+
- Batch: `batchCreate`, `batchSendSOL`, `batchSendSPL`
|
|
255
|
+
- NFTs & Tokens: `mintNFT`, `mintNFTSimple`, `mintToken`
|
|
256
|
+
- Assets: `getAssets`, `syncAssets`
|
|
257
|
+
- Signers: Email, phone, external, API key, and passkey signer management
|
|
258
|
+
|
|
259
|
+
**Auth Module:**
|
|
260
|
+
- `login` - Login and get JWT token
|
|
261
|
+
- `loginAndSetAuth` - Login and automatically set authentication
|
|
262
|
+
|
|
263
|
+
**Subscriptions Module:**
|
|
264
|
+
- Basic: `create`, `findAll`, `findOne`, `getPlatformSubscription`
|
|
265
|
+
- Management: `upgrade`, `downgrade`, `cancel`, `renew`
|
|
266
|
+
- History: `getHistory` - Get subscription audit trail
|
|
267
|
+
|
|
268
|
+
**Plans Module:**
|
|
269
|
+
- Basic: `findAll`, `findOne`, `update`, `remove`
|
|
270
|
+
- Assignment: `assignToPlatform`, `assignToUser`
|
|
271
|
+
|
|
272
|
+
**Subscriptions Module:**
|
|
273
|
+
- Basic: `create`, `findAll`, `findOne`, `getPlatformSubscription`
|
|
274
|
+
- Management: `upgrade`, `downgrade`, `cancel`, `renew`
|
|
275
|
+
- History: `getHistory` - Get subscription audit trail
|
|
276
|
+
|
|
277
|
+
**Plans Module:**
|
|
278
|
+
- Basic: `findAll`, `findOne`, `update`, `remove`
|
|
279
|
+
- Assignment: `assignToPlatform`, `assignToUser`
|
|
280
|
+
|
|
281
|
+
**Transactions Module:**
|
|
282
|
+
- `getWalletTransactions` - Get paginated transaction history for a wallet
|
|
283
|
+
- `getTransactionStatus` - Get transaction status by Solana signature
|
|
284
|
+
|
|
285
|
+
**Delegated Keys Module:**
|
|
286
|
+
- `create` - Create temporary delegated key for wallet
|
|
287
|
+
- `findAll` - List all delegated keys for a wallet
|
|
288
|
+
- `findOne` - Get delegated key by ID
|
|
289
|
+
- `update` - Update delegated key configuration
|
|
290
|
+
- `remove` - Revoke delegated key
|
|
291
|
+
|
|
292
|
+
**Webhooks Module:**
|
|
293
|
+
- `create` - Register new webhook endpoint
|
|
294
|
+
- `findAll` - List all webhooks for platform
|
|
295
|
+
- `findOne` - Get webhook by ID
|
|
296
|
+
- `update` - Update webhook configuration
|
|
297
|
+
- `remove` - Delete webhook
|
|
298
|
+
|
|
299
|
+
**Helpers Module:**
|
|
300
|
+
- Device key management, signer helpers, validation, and storage adapters (see above)
|
|
301
|
+
|
|
302
|
+
## Examples
|
|
303
|
+
|
|
304
|
+
### Subscriptions Module
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { configure } from 'cilantro-sdk';
|
|
308
|
+
import { subscriptions } from 'cilantro-sdk';
|
|
309
|
+
|
|
310
|
+
// Configure SDK
|
|
311
|
+
configure({ apiKey: 'your-api-key' });
|
|
312
|
+
|
|
313
|
+
// Create a new subscription
|
|
314
|
+
const newSubscription = await subscriptions.create({
|
|
315
|
+
platformId: 'platform-id',
|
|
316
|
+
planId: 'plan-id',
|
|
317
|
+
billingCycle: 'monthly',
|
|
318
|
+
trialDays: 7
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Get all subscriptions with filters
|
|
322
|
+
const allSubscriptions = await subscriptions.findAll({
|
|
323
|
+
status: 'active',
|
|
324
|
+
platformId: 'platform-id'
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Get subscription by ID
|
|
328
|
+
const subscription = await subscriptions.findOne('subscription-id');
|
|
329
|
+
|
|
330
|
+
// Get platform's active subscription
|
|
331
|
+
const platformSubscription = await subscriptions.getPlatformSubscription('platform-id');
|
|
332
|
+
|
|
333
|
+
// Upgrade subscription
|
|
334
|
+
await subscriptions.upgrade('subscription-id', {
|
|
335
|
+
newPlanId: 'premium-plan-id',
|
|
336
|
+
effectiveDate: '2024-01-01T00:00:00Z'
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// Downgrade subscription
|
|
340
|
+
await subscriptions.downgrade('subscription-id', {
|
|
341
|
+
newPlanId: 'basic-plan-id'
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// Cancel subscription
|
|
345
|
+
await subscriptions.cancel('subscription-id', {
|
|
346
|
+
cancelAtPeriodEnd: true
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Renew subscription
|
|
350
|
+
await subscriptions.renew('subscription-id', {
|
|
351
|
+
extendByDays: 30
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Get subscription history
|
|
355
|
+
const history = await subscriptions.getHistory('subscription-id');
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Plans Module
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
import { configure } from 'cilantro-sdk';
|
|
362
|
+
import { plans } from 'cilantro-sdk';
|
|
363
|
+
|
|
364
|
+
// Configure SDK
|
|
365
|
+
configure({ apiKey: 'your-api-key' });
|
|
366
|
+
|
|
367
|
+
// Get all plans
|
|
368
|
+
const allPlans = await plans.findAll();
|
|
369
|
+
|
|
370
|
+
// Get plan by ID
|
|
371
|
+
const plan = await plans.findOne('plan-id');
|
|
372
|
+
|
|
373
|
+
// Update plan
|
|
374
|
+
await plans.update('plan-id', {
|
|
375
|
+
planName: 'Updated Plan Name',
|
|
376
|
+
description: 'New description',
|
|
377
|
+
isActive: true
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// Remove (deactivate) a plan
|
|
381
|
+
await plans.remove('plan-id');
|
|
382
|
+
|
|
383
|
+
// Assign plan to platform
|
|
384
|
+
await plans.assignToPlatform('plan-id', 'platform-id', {
|
|
385
|
+
startDate: '2024-01-01T00:00:00Z',
|
|
386
|
+
billingCycle: 'monthly'
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
// Assign plan to user
|
|
390
|
+
await plans.assignToUser('plan-id', 'user-id', {
|
|
391
|
+
startDate: '2024-01-01T00:00:00Z',
|
|
392
|
+
billingCycle: 'monthly'
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Transactions Module
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
import { configure } from 'cilantro-sdk';
|
|
400
|
+
import { getWalletTransactions, getTransactionStatus } from 'cilantro-sdk/transactions';
|
|
401
|
+
|
|
402
|
+
// Configure SDK
|
|
403
|
+
configure({ apiKey: 'your-api-key' });
|
|
404
|
+
|
|
405
|
+
// Get transaction history for a wallet
|
|
406
|
+
const transactions = await getWalletTransactions('wallet-id', {
|
|
407
|
+
page: 1,
|
|
408
|
+
limit: 20,
|
|
409
|
+
type: 'transfer', // Optional: filter by type (transfer, mint, burn, etc.)
|
|
410
|
+
status: 'confirmed' // Optional: filter by status (pending, confirmed, failed)
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Get transaction status by Solana signature
|
|
414
|
+
const status = await getTransactionStatus('transaction-signature-here');
|
|
415
|
+
console.log('Transaction status:', status);
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Delegated Keys Module
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
import { configure } from 'cilantro-sdk';
|
|
422
|
+
import { create, findAll, update, remove } from 'cilantro-sdk/delegated-keys';
|
|
423
|
+
|
|
424
|
+
// Configure SDK
|
|
425
|
+
configure({ apiKey: 'your-api-key' });
|
|
426
|
+
|
|
427
|
+
// Create a temporary delegated key for session-based signing
|
|
428
|
+
const delegatedKey = await create('wallet-id', {
|
|
429
|
+
publicKey: 'delegated-public-key-here',
|
|
430
|
+
expiresAt: '2024-12-31T23:59:59Z',
|
|
431
|
+
permissions: {
|
|
432
|
+
canTransfer: true,
|
|
433
|
+
maxAmount: 1000000000, // 1 SOL in lamports
|
|
434
|
+
allowedPrograms: ['program-id-1', 'program-id-2']
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// List all delegated keys for a wallet
|
|
439
|
+
const keys = await findAll('wallet-id');
|
|
440
|
+
console.log('Delegated keys:', keys);
|
|
441
|
+
|
|
442
|
+
// Update delegated key permissions
|
|
443
|
+
await update('wallet-id', 'key-id', {
|
|
444
|
+
permissions: {
|
|
445
|
+
canTransfer: false,
|
|
446
|
+
maxAmount: 500000000
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// Revoke a delegated key
|
|
451
|
+
await remove('wallet-id', 'key-id');
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Webhooks Module
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
import { configure } from 'cilantro-sdk';
|
|
458
|
+
import { create, findAll, update, remove } from 'cilantro-sdk/webhooks';
|
|
459
|
+
|
|
460
|
+
// Configure SDK with your API key
|
|
461
|
+
configure({ apiKey: 'your-api-key' });
|
|
462
|
+
|
|
463
|
+
// Register a new webhook endpoint
|
|
464
|
+
const webhook = await create({
|
|
465
|
+
url: 'https://your-domain.com/webhooks/cilantro',
|
|
466
|
+
events: ['wallet.created', 'transaction.confirmed', 'transaction.failed'],
|
|
467
|
+
description: 'Production webhook for transaction events',
|
|
468
|
+
isActive: true
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// List all webhooks for your platform
|
|
472
|
+
const webhooks = await findAll();
|
|
473
|
+
console.log('Registered webhooks:', webhooks);
|
|
474
|
+
|
|
475
|
+
// Update webhook configuration
|
|
476
|
+
await update('webhook-id', {
|
|
477
|
+
events: ['wallet.created', 'transaction.confirmed'],
|
|
478
|
+
isActive: false // Temporarily disable
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// Delete a webhook
|
|
482
|
+
await remove('webhook-id');
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
## Error Handling
|
|
486
|
+
|
|
487
|
+
The SDK provides custom error classes for better error handling:
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
import {
|
|
491
|
+
SDKError,
|
|
492
|
+
DeviceKeyMismatchError,
|
|
493
|
+
DeviceKeyNotFoundError,
|
|
494
|
+
NoDeviceIdentitiesError,
|
|
495
|
+
MultipleDeviceIdentitiesError
|
|
496
|
+
} from 'cilantro-sdk';
|
|
497
|
+
|
|
498
|
+
try {
|
|
499
|
+
const keypair = await getEmailSignerKeypair(walletId, signerId, { deviceKeyManager });
|
|
500
|
+
} catch (error) {
|
|
501
|
+
if (error instanceof DeviceKeyNotFoundError) {
|
|
502
|
+
// Handle device key not found
|
|
503
|
+
console.error('Device key not found:', error.devicePublicKey);
|
|
504
|
+
} else if (error instanceof DeviceKeyMismatchError) {
|
|
505
|
+
// Handle device key mismatch
|
|
506
|
+
console.error('Device key mismatch:', error.expectedDeviceKey, error.actualDeviceKey);
|
|
507
|
+
} else {
|
|
508
|
+
// Handle other errors
|
|
509
|
+
console.error('Error:', error.message);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
## TypeScript Support
|
|
515
|
+
|
|
516
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
import type {
|
|
520
|
+
DeviceKeyPair,
|
|
521
|
+
DeviceKeyStorage,
|
|
522
|
+
SignerInfo,
|
|
523
|
+
Keypair,
|
|
524
|
+
EmailSignerOptions,
|
|
525
|
+
PhoneSignerOptions
|
|
526
|
+
} from 'cilantro-sdk/helpers';
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## Cross-Platform Support
|
|
530
|
+
|
|
531
|
+
The SDK works in both browser and Node.js environments:
|
|
532
|
+
|
|
533
|
+
- **Browser**: Uses Web Crypto API and localStorage
|
|
534
|
+
- **Node.js**: Uses Node.js crypto module and filesystem
|
|
535
|
+
|
|
536
|
+
Storage adapters automatically detect the environment and use the appropriate implementation.
|
|
537
|
+
|
|
538
|
+
## License
|
|
539
|
+
|
|
540
|
+
ISC
|