@supanovaapp/sdk 0.1.0

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 ADDED
@@ -0,0 +1,468 @@
1
+ # Supa SDK
2
+
3
+ Supa SDK allows dApps to connect to Canton Network with Privy.io authentication and Ed25519 signing via Stellar wallets.
4
+
5
+ ## Quick overview
6
+
7
+ For a quick overview of the code, check out the demo application in the `/demo` folder.
8
+
9
+ ## Key Features
10
+
11
+ - **Privy.io Authentication** - Email, wallet, and social login methods
12
+ - **Canton Network Integration** - Full Canton ledger access with Ed25519 signing
13
+ - **Built-in Confirmation Modals** - User-friendly signing confirmations
14
+ - **Theme Support** - Light/dark mode with customizable appearance
15
+ - **Automatic Polling** - Transaction completion tracking
16
+ - **TypeScript Support** - Full type safety and IntelliSense
17
+ - **React Hooks** - Simple and intuitive API
18
+
19
+ ## Installation
20
+
21
+ ### From npm (when published)
22
+
23
+ ```bash
24
+ npm install @supa/sdk
25
+ # or
26
+ yarn add @supa/sdk
27
+ # or
28
+ pnpm add @supa/sdk
29
+ ```
30
+
31
+ ### From local repository
32
+
33
+ If the package is not yet published to npm, you can install it locally:
34
+
35
+ #### 1. Clone the repository
36
+
37
+ ```bash
38
+ git clone <repository-url>
39
+ cd supa-sdk
40
+ ```
41
+
42
+ #### 2. Install dependencies and build
43
+
44
+ ```bash
45
+ npm install
46
+ npm run build
47
+ ```
48
+
49
+ #### 3. Link to your project
50
+
51
+ **Option A: Using npm link (recommended)**
52
+
53
+ In the SDK directory:
54
+ ```bash
55
+ npm link
56
+ ```
57
+
58
+ In your project directory:
59
+ ```bash
60
+ npm link @supa/sdk
61
+ ```
62
+
63
+ **Option B: Using local path**
64
+
65
+ In your project's `package.json`, add:
66
+ ```json
67
+ {
68
+ "dependencies": {
69
+ "@supa/sdk": "file:../path/to/supa-sdk"
70
+ }
71
+ }
72
+ ```
73
+
74
+ Then run:
75
+ ```bash
76
+ npm install
77
+ ```
78
+
79
+ **Option C: Using tarball**
80
+
81
+ In the SDK directory:
82
+ ```bash
83
+ npm pack
84
+ ```
85
+
86
+ This creates a `.tgz` file. In your project:
87
+ ```bash
88
+ npm install ../path/to/supa-sdk/supa-sdk-0.1.0.tgz
89
+ ```
90
+
91
+ ## Quick Start
92
+
93
+ ```tsx
94
+ import { SupaProvider, useAuth, useCanton } from '@supa/sdk';
95
+
96
+ function App() {
97
+ return (
98
+ <SupaProvider config={{ privyAppId: 'your-app-id' }}>
99
+ <MyApp />
100
+ </SupaProvider>
101
+ );
102
+ }
103
+
104
+ function MyApp() {
105
+ const { login, authenticated } = useAuth();
106
+ const { registerCanton, isRegistered, sendTransaction } = useCanton();
107
+
108
+ if (!authenticated) {
109
+ return <button onClick={login}>Login</button>;
110
+ }
111
+
112
+ if (!isRegistered) {
113
+ return <button onClick={registerCanton}>Register Canton</button>;
114
+ }
115
+
116
+ return (
117
+ <button onClick={() => sendTransaction(command, contracts)}>
118
+ Send Transaction
119
+ </button>
120
+ );
121
+ }
122
+ ```
123
+
124
+ ## Usage guide
125
+
126
+ ### 1. Initialize the SDK
127
+
128
+ Wrap your application with `SupaProvider`:
129
+
130
+ ```tsx
131
+ import { SupaProvider } from '@supa/sdk';
132
+
133
+ function App() {
134
+ return (
135
+ <SupaProvider
136
+ config={{
137
+ privyAppId: 'your-privy-app-id',
138
+ apiBaseUrl: 'https://stage_api.supa.fyi', // optional
139
+ nodeIdentifier: 'nodeId',
140
+ appearance: {
141
+ theme: 'light', // 'light' or 'dark'
142
+ accentColor: '#6366f1',
143
+ },
144
+ loginMethods: ['email', 'wallet', 'google'],
145
+ }}
146
+ >
147
+ <YourApp />
148
+ </SupaProvider>
149
+ );
150
+ }
151
+ ```
152
+
153
+ **Configuration options:**
154
+ - `privyAppId` - Your Privy App ID (required)
155
+ - `apiBaseUrl` - Backend API URL (default: `https://stage_api.supa.fyi`)
156
+ - `nodeIdentifier` - Canton node identifier (default: `devnet-0`)
157
+ - `appearance` - Theme and styling options
158
+ - `loginMethods` - Array of enabled authentication methods
159
+
160
+ ---
161
+
162
+ ### 2. Connect to the wallet
163
+
164
+ Use the `useAuth` hook to manage authentication:
165
+
166
+ ```tsx
167
+ import { useAuth } from '@supa/sdk';
168
+
169
+ function LoginButton() {
170
+ const { login, logout, authenticated, user } = useAuth();
171
+
172
+ if (!authenticated) {
173
+ return <button onClick={login}>Login with Privy</button>;
174
+ }
175
+
176
+ return (
177
+ <div>
178
+ <p>Welcome, {user?.email?.address}!</p>
179
+ <button onClick={logout}>Logout</button>
180
+ </div>
181
+ );
182
+ }
183
+ ```
184
+
185
+ After successful authentication, `authenticated` becomes `true` and `user` object contains user data.
186
+
187
+ ---
188
+
189
+ ### 3. Canton Network Operations
190
+
191
+ #### Register Canton Wallet
192
+
193
+ ```tsx
194
+ import { useCanton } from '@supa/sdk';
195
+
196
+ function CantonWallet() {
197
+ const { registerCanton, isRegistered, cantonUser, loading } = useCanton();
198
+
199
+ const handleRegister = async () => {
200
+ try {
201
+ await registerCanton();
202
+ console.log('Canton wallet registered!');
203
+ } catch (error) {
204
+ console.error('Registration failed:', error);
205
+ }
206
+ };
207
+
208
+ if (!isRegistered) {
209
+ return <button onClick={handleRegister} disabled={loading}>
210
+ Register Canton Wallet
211
+ </button>;
212
+ }
213
+
214
+ return (
215
+ <div>
216
+ <p>Party ID: {cantonUser?.partyId}</p>
217
+ <p>Email: {cantonUser?.email}</p>
218
+ </div>
219
+ );
220
+ }
221
+ ```
222
+
223
+ #### Get Active Contracts
224
+
225
+ ```tsx
226
+ const { getActiveContracts } = useCanton();
227
+
228
+ // Get all contracts
229
+ const allContracts = await getActiveContracts();
230
+
231
+ // Filter by template IDs
232
+ const filteredContracts = await getActiveContracts([
233
+ 'template-id-1',
234
+ 'template-id-2'
235
+ ]);
236
+ ```
237
+
238
+ #### Submit a Transaction
239
+
240
+ ```tsx
241
+ const { sendTransaction } = useCanton();
242
+
243
+ const command = {
244
+ // Your Canton command
245
+ };
246
+
247
+ try {
248
+ const result = await sendTransaction(command, disclosedContracts, {
249
+ timeout: 30000, // completion timeout (ms)
250
+ pollInterval: 1000, // polling interval (ms)
251
+ });
252
+ console.log('Transaction successful:', result);
253
+ } catch (error) {
254
+ console.error('Transaction failed:', error);
255
+ }
256
+ ```
257
+
258
+ The SDK automatically:
259
+ 1. Prepares the transaction
260
+ 2. Shows confirmation modal
261
+ 3. Signs with user approval
262
+ 4. Submits and polls for completion
263
+
264
+ #### Sign a Message
265
+
266
+ ```tsx
267
+ const { signMessage } = useCanton();
268
+
269
+ try {
270
+ const signature = await signMessage('Hello, Canton!');
271
+ console.log('Signature:', signature);
272
+ } catch (error) {
273
+ console.error('Signing failed:', error);
274
+ }
275
+ ```
276
+
277
+ ---
278
+
279
+ ### 4. Devnet Operations
280
+
281
+ Request test tokens from the devnet faucet:
282
+
283
+ ```tsx
284
+ const { tapDevnet } = useCanton();
285
+
286
+ try {
287
+ const result = await tapDevnet('1000', {
288
+ timeout: 30000,
289
+ pollInterval: 1000,
290
+ });
291
+ console.log('Tokens received:', result);
292
+ } catch (error) {
293
+ console.error('Faucet request failed:', error);
294
+ }
295
+ ```
296
+
297
+ ---
298
+
299
+ ### 5. Advanced Features
300
+
301
+ #### Custom Modal Options
302
+
303
+ ```tsx
304
+ import { useSignMessage } from '@supa/sdk';
305
+
306
+ const { signMessage } = useSignMessage();
307
+
308
+ await signMessage('Hello', {
309
+ title: 'Sign Message',
310
+ description: 'Please review and sign.',
311
+ confirmText: 'Sign',
312
+ rejectText: 'Cancel',
313
+ onSuccess: (sig) => console.log('Signed:', sig),
314
+ onRejection: () => console.log('Rejected'),
315
+ });
316
+ ```
317
+
318
+ #### Custom Transaction Modals
319
+
320
+ ```tsx
321
+ import { useSendTransaction } from '@supa/sdk';
322
+
323
+ const { sendTransaction } = useSendTransaction();
324
+
325
+ await sendTransaction(command, contracts, {
326
+ modalTitle: 'Confirm Payment',
327
+ modalDescription: 'Send 100 tokens to Alice',
328
+ modalConfirmText: 'Pay Now',
329
+ submitOptions: { timeout: 30000 },
330
+ });
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Available Hooks
336
+
337
+ | Hook | Purpose | Key Methods |
338
+ |------|---------|-------------|
339
+ | `useAuth` | Authentication | `login`, `logout`, `authenticated`, `user` |
340
+ | `useCanton` | Canton Network | `registerCanton`, `signMessage`, `sendTransaction`, `getActiveContracts`, `tapDevnet` |
341
+ | `useSignMessage` | Enhanced message signing | `signMessage` with custom modals |
342
+ | `useSendTransaction` | Enhanced transactions | `sendTransaction` with custom modals |
343
+ | `useConfirmModal` | Generic modals | `confirm`, `signMessageConfirm`, `signTransactionConfirm` |
344
+
345
+ ## TypeScript Support
346
+
347
+ Full TypeScript support with generated types:
348
+
349
+ ```tsx
350
+ import type {
351
+ // Hook Return Types
352
+ UseAuthReturn,
353
+ UseCantonReturn,
354
+ UseSignMessageReturn,
355
+ UseSendTransactionReturn,
356
+ UseConfirmModalReturn,
357
+
358
+ // Canton Types
359
+ CantonMeResponseDto,
360
+ CantonActiveContractsResponseDto,
361
+ CantonQueryCompletionResponseDto,
362
+
363
+ // Option Types
364
+ SignMessageOptions,
365
+ SendTransactionOptions,
366
+ ConfirmModalOptions,
367
+ } from '@supa/sdk';
368
+ ```
369
+
370
+ ## How to run demo
371
+
372
+ ### Prerequisites
373
+
374
+ The demo uses the local version of the SDK (`file:..` dependency), so you need to build the SDK first.
375
+
376
+ ```bash
377
+ # 1. Install SDK dependencies
378
+ npm install
379
+
380
+ # 2. Create .env file in demo folder with your Privy credentials
381
+ # demo/.env:
382
+ # VITE_PRIVY_APP_ID=your_privy_app_id
383
+ # VITE_PRIVY_CLIENT_ID=your_privy_client_id
384
+ # VITE_API_BASE_URL=https://stage_api.supa.fyi
385
+ # VITE_CANTON_NODE_ID=nodeId
386
+
387
+ # 3. Build SDK, pack and run demo (one command)
388
+ npm run build && npm pack && cd demo && rm -rf node_modules/@supa node_modules/.vite package-lock.json && npm i && npm run dev
389
+ ```
390
+
391
+ This command builds the SDK, creates a tarball, cleans old dependencies/cache, reinstalls and starts the dev server.
392
+
393
+ Visit http://localhost:6969 to see the demo.
394
+
395
+ > **Note**: If you make changes to the SDK source code, run the full command again to rebuild and restart.
396
+
397
+ The demo application includes:
398
+ - Complete authentication flow
399
+ - Canton wallet registration
400
+ - Message signing with modals
401
+ - Transaction sending with modals
402
+ - Contract querying
403
+ - Devnet faucet integration
404
+ - Theme switching
405
+ - Error handling
406
+
407
+ ## Development Guide
408
+
409
+ This section is for active SDK development and contribution.
410
+
411
+ ### Setup for Development
412
+
413
+ ```bash
414
+ # 1. Clone the repository
415
+ git clone <repository-url>
416
+ cd supa-sdk
417
+
418
+ # 2. Install dependencies
419
+ npm install
420
+
421
+ # 3. Build the SDK
422
+ npm run build
423
+ ```
424
+
425
+ ### Development Workflow
426
+
427
+ The demo application in `/demo` folder is already configured to use the local SDK version via `"@supa/sdk": "file:.."` dependency.
428
+
429
+ #### Recommended Workflow
430
+
431
+ ```bash
432
+ # Build SDK, pack and run demo (from root directory)
433
+ npm run build && npm pack && cd demo && rm -rf node_modules/@supa node_modules/.vite package-lock.json && npm i && npm run dev
434
+ ```
435
+
436
+ After making changes to SDK source, run the same command again. This ensures:
437
+ - Clean build of SDK
438
+ - Fresh tarball package
439
+ - Cleared cache and dependencies
440
+ - Proper dev server restart
441
+
442
+ ### Build Output
443
+
444
+ The `npm run build` command creates distribution files in `dist/`:
445
+ - `dist/index.js` - CommonJS bundle
446
+ - `dist/index.esm.js` - ES modules bundle
447
+ - `dist/index.d.ts` - TypeScript definitions
448
+
449
+ ## Publish to NPM
450
+
451
+ ```bash
452
+ npm run build
453
+ npm publish
454
+ ```
455
+
456
+ ## Support
457
+
458
+ - **Demo**: Full working example in `/demo` folder
459
+ - **Issues**: Report bugs on GitHub
460
+ - **Examples**: Check out the demo application for complete implementation examples
461
+
462
+ ---
463
+
464
+ **Version:** 0.1.0
465
+ **License:** MIT
466
+ **React:** 18+ / 19
467
+ **TypeScript:** 5+
468
+ **Privy SDK:** 3.3.0+