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.
Files changed (178) hide show
  1. package/README.md +540 -316
  2. package/dist/admin.cjs +40 -1
  3. package/dist/admin.cjs.map +2 -2
  4. package/dist/admin.mjs +40 -1
  5. package/dist/admin.mjs.map +2 -2
  6. package/dist/api/admin/admin.d.ts +11 -1
  7. package/dist/api/admin/admin.d.ts.map +1 -1
  8. package/dist/api/auth/auth.d.ts +9 -1
  9. package/dist/api/auth/auth.d.ts.map +1 -1
  10. package/dist/api/health/health.d.ts +7 -0
  11. package/dist/api/health/health.d.ts.map +1 -1
  12. package/dist/api/platforms/platforms.d.ts +23 -1
  13. package/dist/api/platforms/platforms.d.ts.map +1 -1
  14. package/dist/api/public/public.d.ts +17 -0
  15. package/dist/api/public/public.d.ts.map +1 -0
  16. package/dist/api/subscriptions/subscriptions.d.ts +32 -0
  17. package/dist/api/subscriptions/subscriptions.d.ts.map +1 -0
  18. package/dist/api/users/users.d.ts +3 -1
  19. package/dist/api/users/users.d.ts.map +1 -1
  20. package/dist/api/wallets/wallets.d.ts +7 -1
  21. package/dist/api/wallets/wallets.d.ts.map +1 -1
  22. package/dist/auth.cjs +51 -1
  23. package/dist/auth.cjs.map +2 -2
  24. package/dist/auth.mjs +51 -1
  25. package/dist/auth.mjs.map +2 -2
  26. package/dist/delegated-keys.cjs +173 -0
  27. package/dist/delegated-keys.cjs.map +7 -0
  28. package/dist/delegated-keys.d.ts +11 -0
  29. package/dist/delegated-keys.d.ts.map +1 -0
  30. package/dist/delegated-keys.mjs +132 -0
  31. package/dist/delegated-keys.mjs.map +7 -0
  32. package/dist/helpers.cjs +37 -1
  33. package/dist/helpers.cjs.map +2 -2
  34. package/dist/helpers.mjs +37 -1
  35. package/dist/helpers.mjs.map +2 -2
  36. package/dist/index.cjs +777 -7
  37. package/dist/index.cjs.map +4 -4
  38. package/dist/index.d.ts +5 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.mjs +761 -6
  41. package/dist/index.mjs.map +4 -4
  42. package/dist/models/adminControllerGetPlatformActivityTimelineParams.d.ts +14 -0
  43. package/dist/models/adminControllerGetPlatformActivityTimelineParams.d.ts.map +1 -0
  44. package/dist/models/adminControllerGetPlatformGrowthTrendsParams.d.ts +15 -0
  45. package/dist/models/adminControllerGetPlatformGrowthTrendsParams.d.ts.map +1 -0
  46. package/dist/models/adminControllerGetPlatformGrowthTrendsPeriod.d.ts +14 -0
  47. package/dist/models/adminControllerGetPlatformGrowthTrendsPeriod.d.ts.map +1 -0
  48. package/dist/models/adminControllerGetTopPlatformsMetric.d.ts +14 -0
  49. package/dist/models/adminControllerGetTopPlatformsMetric.d.ts.map +1 -0
  50. package/dist/models/adminControllerGetTopPlatformsParams.d.ts +19 -0
  51. package/dist/models/adminControllerGetTopPlatformsParams.d.ts.map +1 -0
  52. package/dist/models/cancelSubscriptionDto.d.ts +17 -0
  53. package/dist/models/cancelSubscriptionDto.d.ts.map +1 -0
  54. package/dist/models/cancelSubscriptionDtoMetadata.d.ts +14 -0
  55. package/dist/models/cancelSubscriptionDtoMetadata.d.ts.map +1 -0
  56. package/dist/models/changePasswordDto.d.ts +17 -0
  57. package/dist/models/changePasswordDto.d.ts.map +1 -0
  58. package/dist/models/confirmPaymentDto.d.ts +14 -0
  59. package/dist/models/confirmPaymentDto.d.ts.map +1 -0
  60. package/dist/models/createPlatformDto.d.ts +7 -0
  61. package/dist/models/createPlatformDto.d.ts.map +1 -1
  62. package/dist/models/createPlatformDtoBillingCycle.d.ts +16 -0
  63. package/dist/models/createPlatformDtoBillingCycle.d.ts.map +1 -0
  64. package/dist/models/createSubscriptionDto.d.ts +24 -0
  65. package/dist/models/createSubscriptionDto.d.ts.map +1 -0
  66. package/dist/models/createSubscriptionDtoBillingCycle.d.ts +16 -0
  67. package/dist/models/createSubscriptionDtoBillingCycle.d.ts.map +1 -0
  68. package/dist/models/createSubscriptionDtoMetadata.d.ts +14 -0
  69. package/dist/models/createSubscriptionDtoMetadata.d.ts.map +1 -0
  70. package/dist/models/downgradeSubscriptionDto.d.ts +17 -0
  71. package/dist/models/downgradeSubscriptionDto.d.ts.map +1 -0
  72. package/dist/models/downgradeSubscriptionDtoMetadata.d.ts +14 -0
  73. package/dist/models/downgradeSubscriptionDtoMetadata.d.ts.map +1 -0
  74. package/dist/models/executeInstructionParamsDto.d.ts +17 -0
  75. package/dist/models/executeInstructionParamsDto.d.ts.map +1 -0
  76. package/dist/models/executeInstructionParamsDtoAccountsItem.d.ts +13 -0
  77. package/dist/models/executeInstructionParamsDtoAccountsItem.d.ts.map +1 -0
  78. package/dist/models/healthControllerGetHealth200.d.ts +19 -0
  79. package/dist/models/healthControllerGetHealth200.d.ts.map +1 -0
  80. package/dist/models/healthControllerGetHealth200Checks.d.ts +16 -0
  81. package/dist/models/healthControllerGetHealth200Checks.d.ts.map +1 -0
  82. package/dist/models/healthControllerGetHealth200ChecksDatabase.d.ts +16 -0
  83. package/dist/models/healthControllerGetHealth200ChecksDatabase.d.ts.map +1 -0
  84. package/dist/models/healthControllerGetHealth200ChecksDatabaseStatus.d.ts +13 -0
  85. package/dist/models/healthControllerGetHealth200ChecksDatabaseStatus.d.ts.map +1 -0
  86. package/dist/models/healthControllerGetHealth200ChecksRedis.d.ts +16 -0
  87. package/dist/models/healthControllerGetHealth200ChecksRedis.d.ts.map +1 -0
  88. package/dist/models/healthControllerGetHealth200ChecksRedisStatus.d.ts +13 -0
  89. package/dist/models/healthControllerGetHealth200ChecksRedisStatus.d.ts.map +1 -0
  90. package/dist/models/healthControllerGetHealth200ChecksSolanaRpc.d.ts +16 -0
  91. package/dist/models/healthControllerGetHealth200ChecksSolanaRpc.d.ts.map +1 -0
  92. package/dist/models/healthControllerGetHealth200ChecksSolanaRpcStatus.d.ts +13 -0
  93. package/dist/models/healthControllerGetHealth200ChecksSolanaRpcStatus.d.ts.map +1 -0
  94. package/dist/models/healthControllerGetHealth200Status.d.ts +17 -0
  95. package/dist/models/healthControllerGetHealth200Status.d.ts.map +1 -0
  96. package/dist/models/index.d.ts +48 -0
  97. package/dist/models/index.d.ts.map +1 -1
  98. package/dist/models/linkPaymentDto.d.ts +14 -0
  99. package/dist/models/linkPaymentDto.d.ts.map +1 -0
  100. package/dist/models/passwordResetConfirmDto.d.ts +17 -0
  101. package/dist/models/passwordResetConfirmDto.d.ts.map +1 -0
  102. package/dist/models/passwordResetRequestDto.d.ts +12 -0
  103. package/dist/models/passwordResetRequestDto.d.ts.map +1 -0
  104. package/dist/models/prepareTransactionDto.d.ts +24 -0
  105. package/dist/models/prepareTransactionDto.d.ts.map +1 -0
  106. package/dist/models/prepareTransactionDtoType.d.ts +17 -0
  107. package/dist/models/prepareTransactionDtoType.d.ts.map +1 -0
  108. package/dist/models/renewSubscriptionDto.d.ts +15 -0
  109. package/dist/models/renewSubscriptionDto.d.ts.map +1 -0
  110. package/dist/models/renewSubscriptionDtoMetadata.d.ts +14 -0
  111. package/dist/models/renewSubscriptionDtoMetadata.d.ts.map +1 -0
  112. package/dist/models/sendSolParamsDto.d.ts +14 -0
  113. package/dist/models/sendSolParamsDto.d.ts.map +1 -0
  114. package/dist/models/sendTokenParamsDto.d.ts +16 -0
  115. package/dist/models/sendTokenParamsDto.d.ts.map +1 -0
  116. package/dist/models/signMessageDto.d.ts +12 -0
  117. package/dist/models/signMessageDto.d.ts.map +1 -0
  118. package/dist/models/submitTransactionDto.d.ts +12 -0
  119. package/dist/models/submitTransactionDto.d.ts.map +1 -0
  120. package/dist/models/subscriptionControllerFindAllParams.d.ts +31 -0
  121. package/dist/models/subscriptionControllerFindAllParams.d.ts.map +1 -0
  122. package/dist/models/subscriptionControllerFindAllStatus.d.ts +16 -0
  123. package/dist/models/subscriptionControllerFindAllStatus.d.ts.map +1 -0
  124. package/dist/models/upgradeSubscriptionDto.d.ts +17 -0
  125. package/dist/models/upgradeSubscriptionDto.d.ts.map +1 -0
  126. package/dist/models/upgradeSubscriptionDtoMetadata.d.ts +14 -0
  127. package/dist/models/upgradeSubscriptionDtoMetadata.d.ts.map +1 -0
  128. package/dist/models/verifyEmailDto.d.ts +12 -0
  129. package/dist/models/verifyEmailDto.d.ts.map +1 -0
  130. package/dist/models/walletControllerPrepareTransaction200.d.ts +13 -0
  131. package/dist/models/walletControllerPrepareTransaction200.d.ts.map +1 -0
  132. package/dist/models/walletControllerPrepareTransaction200Data.d.ts +16 -0
  133. package/dist/models/walletControllerPrepareTransaction200Data.d.ts.map +1 -0
  134. package/dist/models/walletControllerSignMessage200.d.ts +13 -0
  135. package/dist/models/walletControllerSignMessage200.d.ts.map +1 -0
  136. package/dist/models/walletControllerSignMessage200Data.d.ts +16 -0
  137. package/dist/models/walletControllerSignMessage200Data.d.ts.map +1 -0
  138. package/dist/models/walletControllerSubmitTransaction200.d.ts +13 -0
  139. package/dist/models/walletControllerSubmitTransaction200.d.ts.map +1 -0
  140. package/dist/models/walletControllerSubmitTransaction200Data.d.ts +12 -0
  141. package/dist/models/walletControllerSubmitTransaction200Data.d.ts.map +1 -0
  142. package/dist/plans.cjs +198 -0
  143. package/dist/plans.cjs.map +7 -0
  144. package/dist/plans.d.ts +12 -0
  145. package/dist/plans.d.ts.map +1 -0
  146. package/dist/plans.mjs +156 -0
  147. package/dist/plans.mjs.map +7 -0
  148. package/dist/platform.cjs +119 -1
  149. package/dist/platform.cjs.map +2 -2
  150. package/dist/platform.mjs +119 -1
  151. package/dist/platform.mjs.map +2 -2
  152. package/dist/subscriptions.cjs +232 -0
  153. package/dist/subscriptions.cjs.map +7 -0
  154. package/dist/subscriptions.d.ts +15 -0
  155. package/dist/subscriptions.d.ts.map +1 -0
  156. package/dist/subscriptions.mjs +187 -0
  157. package/dist/subscriptions.mjs.map +7 -0
  158. package/dist/transactions.cjs +130 -0
  159. package/dist/transactions.cjs.map +7 -0
  160. package/dist/transactions.d.ts +8 -0
  161. package/dist/transactions.d.ts.map +1 -0
  162. package/dist/transactions.mjs +92 -0
  163. package/dist/transactions.mjs.map +7 -0
  164. package/dist/user.cjs +17 -1
  165. package/dist/user.cjs.map +2 -2
  166. package/dist/user.mjs +17 -1
  167. package/dist/user.mjs.map +2 -2
  168. package/dist/wallet.cjs +37 -1
  169. package/dist/wallet.cjs.map +2 -2
  170. package/dist/wallet.mjs +37 -1
  171. package/dist/wallet.mjs.map +2 -2
  172. package/dist/webhooks.cjs +173 -0
  173. package/dist/webhooks.cjs.map +7 -0
  174. package/dist/webhooks.d.ts +11 -0
  175. package/dist/webhooks.d.ts.map +1 -0
  176. package/dist/webhooks.mjs +132 -0
  177. package/dist/webhooks.mjs.map +7 -0
  178. 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
- - **Utils** (`cilantro-sdk/utils`) - Utility functions
233
- - **Helpers** (`cilantro-sdk/helpers`) - Device key management and signer helpers
234
-
235
- ### Quick Reference
236
-
237
- **Platform Module:**
238
- - Basic: `create`, `findAll`, `findOne`, `update`, `remove`, `getOwnProfile`, `updateOwnProfile`
239
- - Users: `getUsers`, `createUser`, `updateUser`, `removeUser`, `toggleUserActive`
240
- - Wallets: `getWallets` (read-only)
241
-
242
- **User Module:**
243
- - `create`, `findOne`, `update`
244
-
245
- **Wallet Module:**
246
- - Basic: `create`, `findAll`, `findOne`, `update`, `remove`, `findByAddress`, `getTotalBalance`
247
- - Status: `activate`, `deactivate`
248
- - Transactions: `sendSOL`, `sendSPL`, `sendTransaction`, `simulateTransaction`
249
- - Batch: `batchCreate`, `batchSendSOL`, `batchSendSPL`
250
- - NFTs & Tokens: `mintNFT`, `mintNFTSimple`, `mintToken`
251
- - Assets: `getAssets`, `syncAssets`
252
- - Signers: Email, phone, external, API key, and passkey signer management
253
-
254
- **Auth Module:**
255
- - `login` - Login and get JWT token
256
- - `loginAndSetAuth` - Login and automatically set authentication
257
-
258
- **Helpers Module:**
259
- - Device key management, signer helpers, validation, and storage adapters (see above)
260
-
261
- ## Error Handling
262
-
263
- The SDK provides custom error classes for better error handling:
264
-
265
- ```typescript
266
- import {
267
- SDKError,
268
- DeviceKeyMismatchError,
269
- DeviceKeyNotFoundError,
270
- NoDeviceIdentitiesError,
271
- MultipleDeviceIdentitiesError
272
- } from 'cilantro-sdk';
273
-
274
- try {
275
- const keypair = await getEmailSignerKeypair(walletId, signerId, { deviceKeyManager });
276
- } catch (error) {
277
- if (error instanceof DeviceKeyNotFoundError) {
278
- // Handle device key not found
279
- console.error('Device key not found:', error.devicePublicKey);
280
- } else if (error instanceof DeviceKeyMismatchError) {
281
- // Handle device key mismatch
282
- console.error('Device key mismatch:', error.expectedDeviceKey, error.actualDeviceKey);
283
- } else {
284
- // Handle other errors
285
- console.error('Error:', error.message);
286
- }
287
- }
288
- ```
289
-
290
- ## TypeScript Support
291
-
292
- The SDK is written in TypeScript and provides full type definitions:
293
-
294
- ```typescript
295
- import type {
296
- DeviceKeyPair,
297
- DeviceKeyStorage,
298
- SignerInfo,
299
- Keypair,
300
- EmailSignerOptions,
301
- PhoneSignerOptions
302
- } from 'cilantro-sdk/helpers';
303
- ```
304
-
305
- ## Cross-Platform Support
306
-
307
- The SDK works in both browser and Node.js environments:
308
-
309
- - **Browser**: Uses Web Crypto API and localStorage
310
- - **Node.js**: Uses Node.js crypto module and filesystem
311
-
312
- Storage adapters automatically detect the environment and use the appropriate implementation.
313
-
314
- ## License
315
-
316
- ISC
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