@opendatalabs/vana-sdk 0.1.0-alpha.3d5028d → 0.1.0-alpha.4584bee

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 (57) hide show
  1. package/README.md +55 -4
  2. package/package.json +44 -23
  3. package/dist/browser-cRpdLQ3-.d.ts +0 -237
  4. package/dist/browser.d.ts +0 -1
  5. package/dist/browser.js +0 -294
  6. package/dist/browser.js.map +0 -1
  7. package/dist/chains.browser.cjs +0 -96
  8. package/dist/chains.browser.cjs.map +0 -1
  9. package/dist/chains.browser.d.cts +0 -53
  10. package/dist/chains.browser.d.ts +0 -53
  11. package/dist/chains.browser.js +0 -65
  12. package/dist/chains.browser.js.map +0 -1
  13. package/dist/chains.cjs +0 -96
  14. package/dist/chains.cjs.map +0 -1
  15. package/dist/chains.d.cts +0 -2
  16. package/dist/chains.d.ts +0 -2
  17. package/dist/chains.js +0 -65
  18. package/dist/chains.js.map +0 -1
  19. package/dist/chains.node.cjs +0 -96
  20. package/dist/chains.node.cjs.map +0 -1
  21. package/dist/chains.node.d.cts +0 -2
  22. package/dist/chains.node.d.ts +0 -2
  23. package/dist/chains.node.js +0 -65
  24. package/dist/chains.node.js.map +0 -1
  25. package/dist/index.browser.d.ts +0 -36790
  26. package/dist/index.browser.js +0 -45560
  27. package/dist/index.browser.js.map +0 -1
  28. package/dist/index.d.cts +0 -2
  29. package/dist/index.node.cjs +0 -46092
  30. package/dist/index.node.cjs.map +0 -1
  31. package/dist/index.node.d.cts +0 -36927
  32. package/dist/index.node.d.ts +0 -36927
  33. package/dist/index.node.js +0 -45952
  34. package/dist/index.node.js.map +0 -1
  35. package/dist/node-CkdgwBiv.d.cts +0 -237
  36. package/dist/node-CkdgwBiv.d.ts +0 -237
  37. package/dist/node.cjs +0 -350
  38. package/dist/node.cjs.map +0 -1
  39. package/dist/node.d.cts +0 -1
  40. package/dist/node.d.ts +0 -1
  41. package/dist/node.js +0 -313
  42. package/dist/node.js.map +0 -1
  43. package/dist/platform.browser.d.ts +0 -60
  44. package/dist/platform.browser.js +0 -365
  45. package/dist/platform.browser.js.map +0 -1
  46. package/dist/platform.cjs +0 -734
  47. package/dist/platform.cjs.map +0 -1
  48. package/dist/platform.d.cts +0 -2
  49. package/dist/platform.d.ts +0 -2
  50. package/dist/platform.js +0 -697
  51. package/dist/platform.js.map +0 -1
  52. package/dist/platform.node.cjs +0 -734
  53. package/dist/platform.node.cjs.map +0 -1
  54. package/dist/platform.node.d.cts +0 -101
  55. package/dist/platform.node.d.ts +0 -101
  56. package/dist/platform.node.js +0 -697
  57. package/dist/platform.node.js.map +0 -1
package/README.md CHANGED
@@ -28,12 +28,19 @@ npm install viem@^2.31.7
28
28
 
29
29
  ## Quick Start
30
30
 
31
- The Vana SDK supports both browser and Node.js environments with explicit entry points:
31
+ The Vana SDK provides optimized builds for different environments:
32
32
 
33
- ### Browser Applications (React, Vue, etc.)
33
+ | Build | Use Case | Crypto Implementation | Configuration |
34
+ | -------------- | --------------------------------- | ---------------------------------- | ----------------- |
35
+ | **`/browser`** | Browser apps (React, Vue) | Pure JavaScript (@noble/secp256k1) | **Zero config** ✓ |
36
+ | **`/node`** | Server-side (Node.js, API routes) | Native bindings (secp256k1) | Zero config ✓ |
37
+
38
+ ### Browser Applications
39
+
40
+ The browser build uses pure JavaScript cryptography and requires **no special configuration**:
34
41
 
35
42
  ```typescript
36
- // For browser-based applications (React, Vue, etc.)
43
+ // Browser build - works out of the box with any bundler
37
44
  import { Vana, mokshaTestnet } from "@opendatalabs/vana-sdk/browser";
38
45
  import { createWalletClient, http } from "viem";
39
46
  import { privateKeyToAccount } from "viem/accounts";
@@ -53,7 +60,9 @@ const vana = Vana({
53
60
  });
54
61
  ```
55
62
 
56
- ### Server-side Applications (Next.js API routes, Express)
63
+ ### Server-side Applications (Node.js)
64
+
65
+ The Node.js build uses native secp256k1 bindings for optimal performance:
57
66
 
58
67
  ```typescript
59
68
  // For server-side applications (Next.js API routes, Express)
@@ -360,6 +369,48 @@ vana.data.validateDataAgainstSchema(data: unknown, schema: DataSchema): void
360
369
  - **Issues**: [GitHub Issues](https://github.com/vana-com/vana-sdk/issues)
361
370
  - **Discord**: [Join our community](https://discord.gg/vanabuilders)
362
371
 
372
+ ## Generated Code
373
+
374
+ The SDK includes automatically generated code from various sources to provide type-safe interfaces. All generated files are located in `src/generated/` and should **never be edited manually**.
375
+
376
+ ### Code Generation Scripts
377
+
378
+ | Script | Purpose | Generated Files |
379
+ | ---------------------------- | -------------------------------------- | --------------------------- |
380
+ | `npm run fetch-abis` | Smart contract ABIs from blockchain | `src/generated/abi/*.ts` |
381
+ | `npm run fetch-server-types` | Personal server API types from OpenAPI | `src/generated/server/*.ts` |
382
+ | `npm run codegen:subgraph` | GraphQL types from subgraph schema | `src/generated/subgraph.ts` |
383
+
384
+ ### Network-Specific Generation
385
+
386
+ Some generation scripts support different networks:
387
+
388
+ ```bash
389
+ # Generate subgraph types for different networks
390
+ npm run codegen:subgraph:moksha # Moksha testnet (default)
391
+ npm run codegen:subgraph:mainnet # Vana mainnet
392
+
393
+ # Generate ABIs for different networks
394
+ npm run fetch-abis moksha # Moksha testnet (default)
395
+ npm run fetch-abis mainnet # Vana mainnet
396
+ ```
397
+
398
+ ### Development Workflow
399
+
400
+ When working with the SDK:
401
+
402
+ 1. **Never edit generated files** - They are overwritten on regeneration
403
+ 2. **Regenerate after schema changes** - Run generation scripts when external schemas change
404
+ 3. **Generated files are committed** - They're included in version control for consistency
405
+ 4. **ESLint ignores generated code** - Style rules don't apply to generated files
406
+
407
+ ```bash
408
+ # Regenerate all code after schema updates
409
+ npm run fetch-abis
410
+ npm run fetch-server-types
411
+ npm run codegen:subgraph
412
+ ```
413
+
363
414
  ## Development
364
415
 
365
416
  ```bash
package/package.json CHANGED
@@ -1,14 +1,24 @@
1
1
  {
2
2
  "name": "@opendatalabs/vana-sdk",
3
- "version": "0.1.0-alpha.3d5028d",
3
+ "version": "0.1.0-alpha.4584bee",
4
4
  "description": "A TypeScript library for interacting with Vana Network smart contracts.",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "type": "module",
9
+ "sideEffects": false,
9
10
  "main": "dist/index.node.js",
10
11
  "types": "dist/index.node.d.ts",
11
12
  "exports": {
13
+ ".": {
14
+ "browser": {
15
+ "types": "./dist/index.browser.d.ts",
16
+ "import": "./dist/index.browser.js"
17
+ },
18
+ "types": "./dist/index.node.d.ts",
19
+ "import": "./dist/index.node.js",
20
+ "require": "./dist/index.node.cjs"
21
+ },
12
22
  "./browser": {
13
23
  "types": "./dist/index.browser.d.ts",
14
24
  "import": "./dist/index.browser.js"
@@ -19,15 +29,15 @@
19
29
  "require": "./dist/index.node.cjs"
20
30
  },
21
31
  "./chains": {
32
+ "browser": {
33
+ "types": "./dist/chains.browser.d.ts",
34
+ "import": "./dist/chains.browser.js"
35
+ },
22
36
  "node": {
23
37
  "types": "./dist/chains.node.d.ts",
24
38
  "import": "./dist/chains.node.js",
25
39
  "require": "./dist/chains.node.cjs"
26
40
  },
27
- "browser": {
28
- "import": "./dist/chains.browser.js",
29
- "types": "./dist/chains.browser.d.ts"
30
- },
31
41
  "default": {
32
42
  "types": "./dist/chains.node.d.ts",
33
43
  "import": "./dist/chains.node.js",
@@ -35,15 +45,15 @@
35
45
  }
36
46
  },
37
47
  "./platform": {
48
+ "browser": {
49
+ "types": "./dist/platform.browser.d.ts",
50
+ "import": "./dist/platform.browser.js"
51
+ },
38
52
  "node": {
39
53
  "types": "./dist/platform.node.d.ts",
40
54
  "import": "./dist/platform.node.js",
41
55
  "require": "./dist/platform.node.cjs"
42
56
  },
43
- "browser": {
44
- "import": "./dist/platform.browser.js",
45
- "types": "./dist/platform.browser.d.ts"
46
- },
47
57
  "default": {
48
58
  "types": "./dist/platform.node.d.ts",
49
59
  "import": "./dist/platform.node.js",
@@ -51,6 +61,10 @@
51
61
  }
52
62
  }
53
63
  },
64
+ "browser": {
65
+ "secp256k1": false,
66
+ "crypto": false
67
+ },
54
68
  "files": [
55
69
  "dist",
56
70
  "README.md",
@@ -60,11 +74,10 @@
60
74
  "clean": "rimraf dist",
61
75
  "build:types": "tsup src/index.ts --dts-only --out-dir dist --no-clean",
62
76
  "build:node": "tsup src/index.node.ts --platform node --format esm,cjs --target node18 --out-dir dist --no-clean",
63
- "build:browser": "tsup src/index.browser.ts --platform browser --format esm --target es2020 --out-dir dist --dts --no-clean",
77
+ "build:browser": "tsup --config tsup-browser.config.ts",
64
78
  "build:chains": "tsup src/chains.ts src/chains.node.ts src/chains.browser.ts --platform node --format esm,cjs --target node18 --out-dir dist --dts --no-clean",
65
79
  "build:platform": "tsup src/platform.ts src/platform.node.ts src/node.ts --platform node --format esm,cjs --target node18 --out-dir dist --dts --no-clean && tsup src/platform.browser.ts src/browser.ts --platform browser --format esm --target es2020 --out-dir dist --dts --no-clean",
66
- "build": "npm run clean && npm run build:types && npm run build:node && npm run build:browser && npm run build:chains && npm run build:platform",
67
- "prepare": "npm run build",
80
+ "build": "npm run clean && npx npm-run-all --parallel build:types build:node build:browser build:chains build:platform",
68
81
  "dev": "npm run build -- --watch",
69
82
  "lint": "eslint .",
70
83
  "lint:fix": "eslint . --fix",
@@ -74,7 +87,10 @@
74
87
  "test:coverage": "vitest run --coverage",
75
88
  "test:coverage:verbose": "vitest run --coverage --reporter=verbose --coverage.reporter=text",
76
89
  "fetch-abis": "tsx scripts/fetch-abis.ts",
77
- "fetch-server-types": "tsx scripts/fetch-server-types.ts"
90
+ "fetch-server-types": "tsx scripts/fetch-server-types.ts",
91
+ "codegen:subgraph": "graphql-codegen --config codegen.ts",
92
+ "codegen:subgraph:moksha": "VANA_CODEGEN_NETWORK=moksha graphql-codegen --config codegen.ts",
93
+ "codegen:subgraph:mainnet": "VANA_CODEGEN_NETWORK=mainnet graphql-codegen --config codegen.ts"
78
94
  },
79
95
  "keywords": [
80
96
  "vana",
@@ -85,40 +101,45 @@
85
101
  "author": "",
86
102
  "license": "ISC",
87
103
  "dependencies": {
104
+ "@noble/hashes": "^1.8.0",
105
+ "@noble/secp256k1": "^2.3.0",
88
106
  "abitype": "^1.0.8",
89
107
  "ajv": "^8.17.1",
90
108
  "ajv-formats": "^3.0.1",
91
109
  "eccrypto-js": "^5.4.0",
110
+ "graphql": "^16.11.0",
92
111
  "openpgp": "^6.1.1",
93
112
  "viem": "^2.31.7"
94
113
  },
95
- "peerDependencies": {
96
- "eccrypto": "^1.1.6"
97
- },
98
- "peerDependenciesMeta": {
99
- "eccrypto": {
100
- "optional": true
101
- }
102
- },
103
114
  "devDependencies": {
104
- "@types/eccrypto": "^1.1.6",
115
+ "@graphql-codegen/cli": "^5.0.7",
116
+ "@graphql-codegen/typed-document-node": "^5.1.2",
117
+ "@graphql-codegen/typescript": "^4.1.6",
118
+ "@graphql-codegen/typescript-operations": "^4.6.1",
105
119
  "@types/node": "^24.0.10",
106
- "eccrypto": "^1.1.6",
120
+ "@types/secp256k1": "^4.0.6",
107
121
  "@typescript-eslint/eslint-plugin": "^8.32.1",
108
122
  "@typescript-eslint/parser": "^8.32.1",
109
123
  "@vitest/coverage-v8": "^3.2.4",
124
+ "bundle-require": "^5.1.0",
125
+ "consola": "^3.4.0",
110
126
  "eslint": "^9.26.0",
111
127
  "eslint-config-prettier": "^10.1.5",
112
128
  "eslint-plugin-prettier": "^5.4.0",
129
+ "fix-dts-default-cjs-exports": "^1.0.1",
113
130
  "globals": "^16.3.0",
114
131
  "openapi-typescript": "^7.8.0",
115
132
  "prettier": "^3.5.3",
116
133
  "rimraf": "^6.0.1",
134
+ "tree-kill": "^1.2.2",
117
135
  "tsup": "^8.5.0",
118
136
  "tsx": "^4.19.4",
119
137
  "typescript": "^5.8.3",
120
138
  "vitest": "^3.2.4"
121
139
  },
140
+ "optionalDependencies": {
141
+ "secp256k1": "^5.0.1"
142
+ },
122
143
  "engines": {
123
144
  "node": ">=20.0.0"
124
145
  },
@@ -1,237 +0,0 @@
1
- /**
2
- * Platform Adapter interface for environment-specific implementations
3
- *
4
- * This interface abstracts all environment-specific dependencies to ensure
5
- * the SDK works seamlessly across Node.js and browser/SSR environments.
6
- *
7
- * **Implementation Context:**
8
- * - Node.js: Uses native crypto modules and full OpenPGP support
9
- * - Browser: Uses Web Crypto API and browser-compatible libraries
10
- * - SSR: Automatically selects appropriate implementation based on runtime
11
- *
12
- * **Usage Notes:**
13
- * Platform adapters are automatically selected by the SDK. Direct usage is only
14
- * needed for custom implementations or testing.
15
- */
16
- /**
17
- * Platform type identifier
18
- */
19
- type PlatformType = "node" | "browser";
20
- /**
21
- * Encryption operations that require different implementations per platform
22
- */
23
- interface VanaCryptoAdapter {
24
- /**
25
- * Encrypt data with a public key using asymmetric cryptography
26
- *
27
- * **Usage Context:**
28
- * - Used internally for file encryption before storage
29
- * - Public key format: Armored PGP public key string
30
- * - Returns base64-encoded encrypted data
31
- *
32
- * @param data The data to encrypt
33
- * @param publicKey The public key for encryption
34
- * @returns Promise resolving to encrypted data
35
- */
36
- encryptWithPublicKey(data: string, publicKey: string): Promise<string>;
37
- /**
38
- * Decrypt data with a private key using asymmetric cryptography
39
- *
40
- * @param encryptedData The encrypted data
41
- * @param privateKey The private key for decryption
42
- * @returns Promise resolving to decrypted data
43
- */
44
- decryptWithPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
45
- /**
46
- * Generate a new key pair for asymmetric cryptography
47
- *
48
- * @returns Promise resolving to public and private key pair
49
- */
50
- generateKeyPair(): Promise<{
51
- publicKey: string;
52
- privateKey: string;
53
- }>;
54
- /**
55
- * Encrypt data with a wallet's public key using ECDH cryptography
56
- * Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
57
- *
58
- * **Usage Context:**
59
- * - Used for sharing encryption keys with permission recipients
60
- * - Public key format: Compressed or uncompressed secp256k1 hex string
61
- * - Compatible with Ethereum wallet public keys
62
- *
63
- * @param data The data to encrypt (string)
64
- * @param publicKey The wallet's public key (secp256k1)
65
- * @returns Promise resolving to encrypted data as hex string
66
- */
67
- encryptWithWalletPublicKey(data: string, publicKey: string): Promise<string>;
68
- /**
69
- * Decrypt data with a wallet's private key using ECDH cryptography
70
- * Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
71
- *
72
- * @param encryptedData The encrypted data as hex string
73
- * @param privateKey The wallet's private key (secp256k1)
74
- * @returns Promise resolving to decrypted data as string
75
- */
76
- decryptWithWalletPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
77
- /**
78
- * Encrypt data with a password using PGP password-based encryption
79
- * Uses platform-appropriate OpenPGP implementation with consistent format
80
- *
81
- * @param data The data to encrypt as Uint8Array
82
- * @param password The password for encryption (typically wallet signature)
83
- * @returns Promise resolving to encrypted data as Uint8Array
84
- */
85
- encryptWithPassword(data: Uint8Array, password: string): Promise<Uint8Array>;
86
- /**
87
- * Decrypt data with a password using PGP password-based decryption
88
- * Uses platform-appropriate OpenPGP implementation with consistent format
89
- *
90
- * @param encryptedData The encrypted data as Uint8Array
91
- * @param password The password for decryption (typically wallet signature)
92
- * @returns Promise resolving to decrypted data as Uint8Array
93
- */
94
- decryptWithPassword(encryptedData: Uint8Array, password: string): Promise<Uint8Array>;
95
- }
96
- /**
97
- * PGP operations that require different configurations per platform
98
- */
99
- interface VanaPGPAdapter {
100
- /**
101
- * Encrypt data using PGP with proper platform configuration
102
- *
103
- * @param data The data to encrypt
104
- * @param publicKey The PGP public key
105
- * @returns Promise resolving to encrypted data
106
- */
107
- encrypt(data: string, publicKey: string): Promise<string>;
108
- /**
109
- * Decrypt data using PGP with proper platform configuration
110
- *
111
- * @param encryptedData The encrypted data
112
- * @param privateKey The PGP private key
113
- * @returns Promise resolving to decrypted data
114
- */
115
- decrypt(encryptedData: string, privateKey: string): Promise<string>;
116
- /**
117
- * Generate a new PGP key pair with platform-appropriate configuration
118
- *
119
- * @param options - Key generation options
120
- * @param options.name - The name for the PGP key
121
- * @param options.email - The email for the PGP key
122
- * @param options.passphrase - Optional passphrase to protect the private key
123
- * @returns Promise resolving to public and private key pair
124
- */
125
- generateKeyPair(options?: {
126
- name?: string;
127
- email?: string;
128
- passphrase?: string;
129
- }): Promise<{
130
- publicKey: string;
131
- privateKey: string;
132
- }>;
133
- }
134
- /**
135
- * HTTP operations that need consistent API across platforms
136
- */
137
- interface VanaHttpAdapter {
138
- /**
139
- * Perform HTTP request with platform-appropriate fetch implementation
140
- *
141
- * @param url The URL to request
142
- * @param options Request options
143
- * @returns Promise resolving to response
144
- */
145
- fetch(url: string, options?: RequestInit): Promise<Response>;
146
- }
147
- /**
148
- * Simple cache operations that work across platforms
149
- */
150
- interface VanaCacheAdapter {
151
- /**
152
- * Get a value from the cache
153
- *
154
- * @param key The cache key
155
- * @returns The cached value or null if not found/expired
156
- */
157
- get(key: string): string | null;
158
- /**
159
- * Set a value in the cache
160
- *
161
- * @param key The cache key
162
- * @param value The value to cache
163
- */
164
- set(key: string, value: string): void;
165
- /**
166
- * Delete a value from the cache
167
- *
168
- * @param key The cache key
169
- */
170
- delete(key: string): void;
171
- /**
172
- * Clear all values from the cache
173
- */
174
- clear(): void;
175
- }
176
- /**
177
- * Main platform adapter interface that combines all platform-specific functionality
178
- *
179
- * **Implementation Guidelines:**
180
- * 1. All methods must maintain consistent behavior across platforms
181
- * 2. Error types and messages should be unified
182
- * 3. Data formats (encoding, serialization) must be identical
183
- * 4. Performance characteristics can vary but API must be consistent
184
- *
185
- * **Custom Implementation Example:**
186
- * ```typescript
187
- * class CustomPlatformAdapter implements VanaPlatformAdapter {
188
- * crypto = new CustomCryptoAdapter();
189
- * pgp = new CustomPGPAdapter();
190
- * http = new CustomHttpAdapter();
191
- * platform = 'browser' as const;
192
- * }
193
- * ```
194
- */
195
- interface VanaPlatformAdapter {
196
- /**
197
- * Crypto operations adapter
198
- */
199
- crypto: VanaCryptoAdapter;
200
- /**
201
- * PGP operations adapter
202
- */
203
- pgp: VanaPGPAdapter;
204
- /**
205
- * HTTP operations adapter
206
- */
207
- http: VanaHttpAdapter;
208
- /**
209
- * Cache operations adapter
210
- */
211
- cache: VanaCacheAdapter;
212
- /**
213
- * Platform identifier for debugging/telemetry
214
- */
215
- readonly platform: PlatformType;
216
- }
217
-
218
- /**
219
- * Browser implementation of the Vana Platform Adapter
220
- *
221
- * This implementation uses browser-compatible libraries and configurations
222
- * to provide crypto, PGP, and HTTP functionality without Node.js dependencies.
223
- */
224
-
225
- /**
226
- * Complete browser platform adapter implementation
227
- */
228
- declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
229
- crypto: VanaCryptoAdapter;
230
- pgp: VanaPGPAdapter;
231
- http: VanaHttpAdapter;
232
- cache: VanaCacheAdapter;
233
- platform: "browser";
234
- constructor();
235
- }
236
-
237
- export { BrowserPlatformAdapter as B, type PlatformType as P, type VanaPlatformAdapter as V };
package/dist/browser.d.ts DELETED
@@ -1 +0,0 @@
1
- export { B as BrowserPlatformAdapter } from './browser-cRpdLQ3-.js';