@blu1606/create-walrus-app 1.0.0 → 2.0.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.
Files changed (101) hide show
  1. package/dist/generator/file-ops.d.ts +8 -0
  2. package/dist/generator/file-ops.js +20 -0
  3. package/dist/generator/index.js +37 -22
  4. package/dist/generator/layers.d.ts +15 -2
  5. package/dist/generator/layers.js +38 -47
  6. package/dist/generator/types.d.ts +9 -1
  7. package/dist/index.js +1 -2
  8. package/dist/post-install/git.d.ts +8 -0
  9. package/dist/post-install/git.js +2 -0
  10. package/dist/post-install/index.d.ts +0 -1
  11. package/dist/post-install/index.js +2 -15
  12. package/dist/post-install/messages.js +1 -1
  13. package/package.json +3 -3
  14. package/{templates/base → presets/react-mysten-gallery}/.env.example +31 -31
  15. package/presets/react-mysten-gallery/.gitkeep +4 -0
  16. package/{templates/gallery → presets/react-mysten-gallery}/README.md +25 -22
  17. package/presets/react-mysten-gallery/package.json +34 -0
  18. package/presets/react-mysten-gallery/src/App.tsx +23 -0
  19. package/presets/react-mysten-gallery/src/components/features/file-card.tsx +89 -0
  20. package/{templates/gallery/src/components/GalleryGrid.tsx → presets/react-mysten-gallery/src/components/features/gallery-grid.tsx} +5 -5
  21. package/presets/react-mysten-gallery/src/components/features/upload-modal.tsx +69 -0
  22. package/{templates/react/src/components/WalletConnect.tsx → presets/react-mysten-gallery/src/components/features/wallet-connect.tsx} +1 -1
  23. package/presets/react-mysten-gallery/src/components/layout/app-layout.tsx +21 -0
  24. package/{templates/react/src/hooks/useStorage.ts → presets/react-mysten-gallery/src/hooks/use-download.ts} +2 -18
  25. package/presets/react-mysten-gallery/src/hooks/use-upload.ts +49 -0
  26. package/{templates/react/src/hooks/useWallet.ts → presets/react-mysten-gallery/src/hooks/use-wallet.ts} +2 -7
  27. package/presets/react-mysten-gallery/src/index.css +384 -0
  28. package/presets/react-mysten-gallery/src/index.ts +17 -0
  29. package/presets/react-mysten-gallery/src/lib/walrus/adapter.ts +197 -0
  30. package/presets/react-mysten-gallery/src/lib/walrus/client.ts +87 -0
  31. package/presets/react-mysten-gallery/src/lib/walrus/index.ts +4 -0
  32. package/presets/react-mysten-gallery/src/lib/walrus/types.ts +101 -0
  33. package/{templates/react → presets/react-mysten-gallery}/src/main.tsx +0 -1
  34. package/{templates/react → presets/react-mysten-gallery}/src/providers/WalletProvider.tsx +16 -1
  35. package/{templates/base → presets/react-mysten-gallery}/src/utils/env.ts +41 -41
  36. package/{templates/gallery → presets/react-mysten-gallery}/src/utils/index-manager.ts +2 -2
  37. package/presets/react-mysten-gallery/src/utils/mime-type.ts +97 -0
  38. package/presets/react-mysten-gallery/src/utils/preview-generator.ts +134 -0
  39. package/{templates/react → presets/react-mysten-gallery}/tsconfig.json +20 -8
  40. package/presets/react-mysten-simple-upload/.env.example +31 -0
  41. package/presets/react-mysten-simple-upload/.gitkeep +4 -0
  42. package/presets/react-mysten-simple-upload/index.html +13 -0
  43. package/{templates/react → presets/react-mysten-simple-upload}/package.json +13 -11
  44. package/presets/react-mysten-simple-upload/src/App.tsx +27 -0
  45. package/presets/react-mysten-simple-upload/src/components/features/file-preview.tsx +73 -0
  46. package/{templates/simple-upload/src/components/UploadForm.tsx → presets/react-mysten-simple-upload/src/components/features/upload-form.tsx} +15 -5
  47. package/presets/react-mysten-simple-upload/src/components/features/wallet-connect.tsx +21 -0
  48. package/presets/react-mysten-simple-upload/src/components/layout/app-layout.tsx +21 -0
  49. package/presets/react-mysten-simple-upload/src/hooks/use-download.ts +24 -0
  50. package/presets/react-mysten-simple-upload/src/hooks/use-upload.ts +49 -0
  51. package/presets/react-mysten-simple-upload/src/hooks/use-wallet.ts +11 -0
  52. package/presets/react-mysten-simple-upload/src/index.css +252 -0
  53. package/presets/react-mysten-simple-upload/src/index.ts +16 -0
  54. package/presets/react-mysten-simple-upload/src/lib/walrus/adapter.ts +197 -0
  55. package/presets/react-mysten-simple-upload/src/lib/walrus/client.ts +87 -0
  56. package/presets/react-mysten-simple-upload/src/lib/walrus/index.ts +4 -0
  57. package/{templates/base/src/adapters/storage.ts → presets/react-mysten-simple-upload/src/lib/walrus/types.ts} +83 -58
  58. package/presets/react-mysten-simple-upload/src/main.tsx +16 -0
  59. package/presets/react-mysten-simple-upload/src/providers/QueryProvider.tsx +18 -0
  60. package/presets/react-mysten-simple-upload/src/providers/WalletProvider.tsx +52 -0
  61. package/presets/react-mysten-simple-upload/src/utils/env.ts +41 -0
  62. package/presets/react-mysten-simple-upload/src/utils/mime-type.ts +97 -0
  63. package/presets/react-mysten-simple-upload/tsconfig.json +39 -0
  64. package/presets/react-mysten-simple-upload/tsconfig.node.json +10 -0
  65. package/presets/react-mysten-simple-upload/vite.config.ts +19 -0
  66. package/templates/base/README.md +0 -54
  67. package/templates/base/package.json +0 -19
  68. package/templates/base/src/types/index.ts +0 -9
  69. package/templates/base/src/types/walrus.ts +0 -22
  70. package/templates/base/src/utils/format.ts +0 -29
  71. package/templates/base/tsconfig.json +0 -19
  72. package/templates/gallery/package.json +0 -6
  73. package/templates/gallery/src/App.tsx +0 -21
  74. package/templates/gallery/src/components/FileCard.tsx +0 -27
  75. package/templates/gallery/src/components/UploadModal.tsx +0 -45
  76. package/templates/gallery/src/styles.css +0 -58
  77. package/templates/gallery/src/types/gallery.ts +0 -13
  78. package/templates/react/.eslintrc.json +0 -26
  79. package/templates/react/README.md +0 -80
  80. package/templates/react/src/App.tsx +0 -14
  81. package/templates/react/src/components/Layout.tsx +0 -21
  82. package/templates/react/src/dapp-kit.css +0 -1
  83. package/templates/react/src/index.css +0 -50
  84. package/templates/react/src/index.ts +0 -10
  85. package/templates/sdk-mysten/README.md +0 -65
  86. package/templates/sdk-mysten/package.json +0 -14
  87. package/templates/sdk-mysten/src/adapter.ts +0 -80
  88. package/templates/sdk-mysten/src/client.ts +0 -45
  89. package/templates/sdk-mysten/src/config.ts +0 -33
  90. package/templates/sdk-mysten/src/index.ts +0 -11
  91. package/templates/sdk-mysten/src/types.ts +0 -19
  92. package/templates/sdk-mysten/test/adapter.test.ts +0 -20
  93. package/templates/simple-upload/package.json +0 -6
  94. package/templates/simple-upload/src/App.tsx +0 -27
  95. package/templates/simple-upload/src/components/FilePreview.tsx +0 -40
  96. package/templates/simple-upload/src/styles.css +0 -33
  97. /package/{templates/react → presets/react-mysten-gallery}/index.html +0 -0
  98. /package/{templates/react → presets/react-mysten-gallery}/src/providers/QueryProvider.tsx +0 -0
  99. /package/{templates/react → presets/react-mysten-gallery}/tsconfig.node.json +0 -0
  100. /package/{templates/react → presets/react-mysten-gallery}/vite.config.ts +0 -0
  101. /package/{templates/simple-upload → presets/react-mysten-simple-upload}/README.md +0 -0
@@ -0,0 +1,252 @@
1
+ /* Dapp Kit styles */
2
+ @import '@mysten/dapp-kit/dist/index.css';
3
+
4
+ /* Google Fonts Import */
5
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;700&display=swap');
6
+
7
+ /* Global styles */
8
+ :root {
9
+ /* Pallette */
10
+ --walrus-bg-primary: #020617;
11
+ /* Deep Trench */
12
+ --walrus-bg-secondary: #0f172a;
13
+ /* Card/Section bg */
14
+ --walrus-surface: #1e293b;
15
+ /* Input, button bg */
16
+ --walrus-surface-hover: #334155;
17
+ /* Hover states */
18
+ --walrus-accent-cyan: #06b6d4;
19
+ /* Arctic Cyan - Primary Highlight */
20
+ --walrus-accent-blue: #4da2ff;
21
+ /* Sui Blue */
22
+ --walrus-accent-purple: #c084fc;
23
+ /* Secondary Accent */
24
+ --walrus-text-primary: #f8fafc;
25
+ /* Main Text */
26
+ --walrus-text-secondary: #94a3b8;
27
+ /* Muted Text */
28
+ --walrus-border: #334155;
29
+ /* Border Color */
30
+ --walrus-warning: #ef4444;
31
+ --walrus-success: #10b981;
32
+ --walrus-error: #ef4444;
33
+
34
+ /* Base Settings */
35
+ font-family: 'Inter', system-ui, sans-serif;
36
+ line-height: 1.5;
37
+ font-weight: 400;
38
+
39
+ color-scheme: dark;
40
+ color: var(--walrus-text-primary);
41
+ background-color: var(--walrus-bg-primary);
42
+
43
+ font-synthesis: none;
44
+ text-rendering: optimizeLegibility;
45
+ -webkit-font-smoothing: antialiased;
46
+ -moz-osx-font-smoothing: grayscale;
47
+ }
48
+
49
+ body {
50
+ margin: 0;
51
+ display: flex;
52
+ place-items: center;
53
+ min-width: 320px;
54
+ min-height: 100vh;
55
+ background-color: var(--walrus-bg-primary);
56
+ color: var(--walrus-text-primary);
57
+ }
58
+
59
+ #root {
60
+ max-width: 1280px;
61
+ margin: 0 auto;
62
+ padding: 2rem;
63
+ text-align: center;
64
+ width: 100%;
65
+ }
66
+
67
+ /* Typography Overrides */
68
+ h1,
69
+ h2,
70
+ h3,
71
+ h4,
72
+ h5,
73
+ h6 {
74
+ font-family: 'JetBrains Mono', monospace;
75
+ color: var(--walrus-text-primary);
76
+ }
77
+
78
+ h1 {
79
+ font-size: 3.2em;
80
+ line-height: 1.1;
81
+ }
82
+
83
+ h2 {
84
+ font-size: 2.5em;
85
+ }
86
+
87
+ h3 {
88
+ font-size: 1.5em;
89
+ }
90
+
91
+ a {
92
+ font-weight: 500;
93
+ color: var(--walrus-accent-blue);
94
+ text-decoration: inherit;
95
+ }
96
+
97
+ a:hover {
98
+ color: var(--walrus-accent-cyan);
99
+ }
100
+
101
+ /* Button Styling */
102
+ button {
103
+ border-radius: 8px;
104
+ border: 1px solid var(--walrus-border);
105
+ padding: 0.6em 1.2em;
106
+ font-size: 1em;
107
+ font-weight: 600;
108
+ font-family: inherit;
109
+ background-color: var(--walrus-surface);
110
+ color: var(--walrus-text-primary);
111
+ cursor: pointer;
112
+ transition: all 0.25s;
113
+ }
114
+
115
+ button:hover:not(:disabled) {
116
+ border-color: var(--walrus-accent-cyan);
117
+ background-color: var(--walrus-surface-hover);
118
+ box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
119
+ }
120
+
121
+ button:focus,
122
+ button:focus-visible {
123
+ outline: 4px auto var(--walrus-accent-cyan);
124
+ }
125
+
126
+ button:disabled {
127
+ opacity: 0.5;
128
+ cursor: not-allowed;
129
+ background-color: var(--walrus-bg-secondary);
130
+ }
131
+
132
+ /* Form Elements */
133
+ input {
134
+ background-color: var(--walrus-surface);
135
+ border: 1px solid var(--walrus-border);
136
+ color: var(--walrus-text-primary);
137
+ padding: 0.6em;
138
+ border-radius: 8px;
139
+ font-family: inherit;
140
+ font-size: 1em;
141
+ transition: border-color 0.2s;
142
+ }
143
+
144
+ input:focus {
145
+ outline: none;
146
+ border-color: var(--walrus-accent-cyan);
147
+ }
148
+
149
+ /* Utilities / Components */
150
+ .card {
151
+ background-color: var(--walrus-bg-secondary);
152
+ border: 1px solid var(--walrus-border);
153
+ border-radius: 12px;
154
+ padding: 2rem;
155
+ transition: all 0.2s;
156
+ }
157
+
158
+ .card:hover {
159
+ border-color: var(--walrus-accent-cyan);
160
+ box-shadow: 0 0 15px rgba(6, 182, 212, 0.15);
161
+ }
162
+
163
+ .badge {
164
+ display: inline-block;
165
+ padding: 0.2em 0.6em;
166
+ font-size: 0.85em;
167
+ font-weight: 500;
168
+ border-radius: 999px;
169
+ background-color: rgba(192, 132, 252, 0.15);
170
+ color: var(--walrus-accent-purple);
171
+ border: 1px solid rgba(192, 132, 252, 0.3);
172
+ }
173
+
174
+ .text-accent {
175
+ color: var(--walrus-accent-cyan);
176
+ }
177
+
178
+ .text-secondary {
179
+ color: var(--walrus-text-secondary);
180
+ }
181
+
182
+ .text-error {
183
+ color: var(--walrus-error);
184
+ }
185
+
186
+ .text-warning {
187
+ color: var(--walrus-warning);
188
+ }
189
+
190
+ /* App Specific Containers */
191
+ .simple-upload-app {
192
+ max-width: 900px;
193
+ margin: 0 auto;
194
+ display: flex;
195
+ flex-direction: column;
196
+ gap: 2rem;
197
+ }
198
+
199
+ /* Overriding section to look like cards */
200
+ section {
201
+ margin: 0;
202
+ padding: 2rem;
203
+ border: 1px solid var(--walrus-border);
204
+ background-color: var(--walrus-bg-secondary);
205
+ border-radius: 12px;
206
+ transition: border-color 0.2s;
207
+ }
208
+
209
+ section:hover {
210
+ border-color: var(--walrus-surface-hover);
211
+ }
212
+
213
+ section h3 {
214
+ margin-top: 0;
215
+ color: var(--walrus-accent-cyan);
216
+ }
217
+
218
+ .upload-form,
219
+ .file-preview {
220
+ display: flex;
221
+ flex-direction: column;
222
+ gap: 1.5rem;
223
+ align-items: stretch;
224
+ }
225
+
226
+ .file-info {
227
+ background: var(--walrus-bg-primary);
228
+ padding: 1rem;
229
+ border-radius: 8px;
230
+ border: 1px dashed var(--walrus-border);
231
+ text-align: left;
232
+ }
233
+
234
+ .error {
235
+ color: var(--walrus-error);
236
+ background: rgba(239, 68, 68, 0.1);
237
+ padding: 0.5rem;
238
+ border-radius: 4px;
239
+ }
240
+
241
+ .warning {
242
+ color: var(--walrus-warning);
243
+ }
244
+
245
+ /* Code/Pre blocks */
246
+ pre {
247
+ background: var(--walrus-bg-primary) !important;
248
+ color: var(--walrus-text-primary);
249
+ border: 1px solid var(--walrus-border);
250
+ border-radius: 8px;
251
+ font-family: 'JetBrains Mono', monospace;
252
+ }
@@ -0,0 +1,16 @@
1
+ // Re-export Walrus library
2
+ export * from './lib/walrus/index.js';
3
+
4
+ // Re-export features
5
+ export { UploadForm } from './components/features/upload-form.js';
6
+ export { FilePreview } from './components/features/file-preview.js';
7
+ export { WalletConnect } from './components/features/wallet-connect.js';
8
+
9
+ // Re-export hooks
10
+ export { useUpload } from './hooks/use-upload.js';
11
+ export { useDownload, useMetadata } from './hooks/use-download.js';
12
+ export { useWallet } from './hooks/use-wallet.js';
13
+
14
+ // Re-export layout
15
+ export { AppLayout } from './components/layout/app-layout.js';
16
+
@@ -0,0 +1,197 @@
1
+ import type {
2
+ StorageAdapter,
3
+ BlobMetadata,
4
+ UploadOptions,
5
+ DownloadOptions,
6
+ } from './types.js';
7
+ import { getWalrusClient, resetWalrusClient } from './client.js';
8
+ import { WalrusFile, RetryableWalrusClientError } from '@mysten/walrus';
9
+ import { getContentType } from '../../utils/mime-type.js';
10
+
11
+ export class MystenStorageAdapter implements StorageAdapter {
12
+ async upload(
13
+ data: File | Uint8Array,
14
+ options?: UploadOptions
15
+ ): Promise<string> {
16
+ const bytes =
17
+ data instanceof File ? new Uint8Array(await data.arrayBuffer()) : data;
18
+ const fileName = data instanceof File ? data.name : 'upload.bin';
19
+
20
+ try {
21
+ // Check if signer and client are provided
22
+ if (!options?.signer) {
23
+ throw new Error('Wallet signer is required for upload. Please connect your wallet.');
24
+ }
25
+ if (!options?.client) {
26
+ throw new Error('Sui client is required for upload.');
27
+ }
28
+
29
+ const client = options.client;
30
+
31
+ console.log('[Upload] Starting upload flow...');
32
+
33
+ // Detect content type with fallback logic
34
+ const contentType = getContentType(
35
+ data,
36
+ options?.contentType
37
+ );
38
+
39
+ console.log(`[Upload] Detected content-type: ${contentType} for file: ${fileName}`);
40
+
41
+ // Create upload flow with full metadata (identifier + tags)
42
+ const flow = client.walrus.writeFilesFlow({
43
+ files: [
44
+ WalrusFile.from({
45
+ contents: bytes,
46
+ identifier: fileName, // Original filename with extension
47
+ tags: {
48
+ 'content-type': contentType,
49
+ 'original-name': fileName,
50
+ },
51
+ }),
52
+ ],
53
+ });
54
+
55
+ // Step 1: Encode the file
56
+ console.log('[Upload] Step 1: Encoding file...');
57
+ await flow.encode();
58
+ console.log('[Upload] Step 1: Encode complete');
59
+
60
+ // Step 2: Register the blob on-chain (requires wallet signature)
61
+ console.log('[Upload] Step 2: Creating register transaction...');
62
+ const registerTx = flow.register({
63
+ epochs: options?.epochs || 1,
64
+ owner: options.signer.address,
65
+ deletable: true,
66
+ });
67
+
68
+ // Sign and execute the register transaction (dapp-kit will handle wrapping)
69
+ console.log('[Upload] Step 2: Signing register transaction...');
70
+ const registerResult = await options.signer.signAndExecuteTransaction({
71
+ transaction: registerTx,
72
+ });
73
+ console.log('[Upload] Step 2: Register complete, digest:', registerResult.digest);
74
+
75
+ // Step 3: Upload the data to storage nodes
76
+ console.log('[Upload] Step 3: Uploading to storage nodes...');
77
+ await flow.upload({ digest: registerResult.digest });
78
+ console.log('[Upload] Step 3: Upload complete');
79
+
80
+ // Step 4: Certify the blob (requires wallet signature)
81
+ console.log('[Upload] Step 4: Creating certify transaction...');
82
+ const certifyTx = flow.certify();
83
+
84
+ // Sign and execute the certify transaction (dapp-kit will handle wrapping)
85
+ console.log('[Upload] Step 4: Signing certify transaction...');
86
+ await options.signer.signAndExecuteTransaction({
87
+ transaction: certifyTx,
88
+ });
89
+ console.log('[Upload] Step 4: Certify complete');
90
+
91
+ // Step 5: Get the uploaded files
92
+ console.log('[Upload] Step 5: Getting file list...');
93
+ const files = await flow.listFiles();
94
+
95
+ if (!files || files.length === 0) {
96
+ throw new Error('Upload completed but no files were returned');
97
+ }
98
+
99
+ const blobId = files[0].blobId;
100
+ console.log('[Upload] Success! Blob ID:', blobId);
101
+ return blobId;
102
+ } catch (error) {
103
+ console.error('[Upload] Error details:', error);
104
+ throw new Error(
105
+ `Upload failed: ${error instanceof Error ? error.message : 'Unknown error'}`
106
+ );
107
+ }
108
+ }
109
+
110
+ async download(
111
+ blobId: string,
112
+ options?: DownloadOptions
113
+ ): Promise<Uint8Array | string | unknown> {
114
+ const client = getWalrusClient();
115
+
116
+ try {
117
+ // Use getFiles for better API - supports future batch downloads
118
+ const [file] = await client.walrus.getFiles({ ids: [blobId] });
119
+
120
+ // Handle different output formats
121
+ switch (options?.format) {
122
+ case 'text':
123
+ return await file.text();
124
+ case 'json':
125
+ return await file.json();
126
+ default:
127
+ return await file.bytes();
128
+ }
129
+ } catch (error) {
130
+ // Handle retryable errors by resetting client and retrying once
131
+ if (error instanceof RetryableWalrusClientError) {
132
+ console.warn(`[Download] Retryable error detected, resetting client and retrying...`);
133
+ resetWalrusClient();
134
+
135
+ try {
136
+ const retryClient = getWalrusClient();
137
+ const [file] = await retryClient.walrus.getFiles({ ids: [blobId] });
138
+
139
+ switch (options?.format) {
140
+ case 'text':
141
+ return await file.text();
142
+ case 'json':
143
+ return await file.json();
144
+ default:
145
+ return await file.bytes();
146
+ }
147
+ } catch (retryError) {
148
+ throw new Error(
149
+ `Download retry failed for blob ${blobId}: ${retryError instanceof Error ? retryError.message : 'Unknown error'}`
150
+ );
151
+ }
152
+ }
153
+
154
+ throw new Error(
155
+ `Download failed for blob ${blobId}: ${error instanceof Error ? error.message : 'Unknown error'}`
156
+ );
157
+ }
158
+ }
159
+
160
+ async getMetadata(blobId: string): Promise<BlobMetadata> {
161
+ const client = getWalrusClient();
162
+
163
+ try {
164
+ // Get metadata from Walrus
165
+ const metadata = await client.walrus.getBlobMetadata({ blobId });
166
+
167
+ // Get WalrusFile to extract identifier and tags
168
+ const [file] = await client.walrus.getFiles({ ids: [blobId] });
169
+ const identifier = await file.getIdentifier();
170
+ const tags = await file.getTags();
171
+
172
+ return {
173
+ blobId,
174
+ size: Number(metadata.metadata.V1.unencoded_length),
175
+ contentType: tags['content-type'] || 'application/octet-stream',
176
+ fileName: tags['original-name'] || identifier || `blob-${blobId.slice(0, 8)}`,
177
+ tags,
178
+ createdAt: (metadata as unknown as { createdAt?: number }).createdAt || Date.now(),
179
+ };
180
+ } catch (error) {
181
+ throw new Error(
182
+ `Failed to get metadata for blob ${blobId}: ${error instanceof Error ? error.message : 'Unknown error'}`
183
+ );
184
+ }
185
+ }
186
+
187
+ async exists(blobId: string): Promise<boolean> {
188
+ try {
189
+ await this.getMetadata(blobId);
190
+ return true;
191
+ } catch {
192
+ return false;
193
+ }
194
+ }
195
+ }
196
+
197
+ export const storageAdapter = new MystenStorageAdapter();
@@ -0,0 +1,87 @@
1
+ import { walrus, WalrusClient } from '@mysten/walrus';
2
+ import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
3
+ import { loadEnv } from '../../utils/env.js';
4
+
5
+ // Types
6
+ export type WalrusNetwork = 'testnet' | 'mainnet';
7
+
8
+ export interface MystenWalrusConfig {
9
+ network: WalrusNetwork;
10
+ publisherUrl?: string;
11
+ aggregatorUrl?: string;
12
+ suiRpcUrl?: string;
13
+ }
14
+
15
+ type WalrusExtendedClient = SuiClient & { walrus: WalrusClient };
16
+
17
+ // Network Configurations
18
+ const NETWORK_CONFIGS: Record<WalrusNetwork, MystenWalrusConfig> = {
19
+ testnet: {
20
+ network: 'testnet',
21
+ publisherUrl: 'https://publisher.walrus-testnet.walrus.space',
22
+ aggregatorUrl: 'https://aggregator.walrus-testnet.walrus.space',
23
+ suiRpcUrl: 'https://fullnode.testnet.sui.io:443',
24
+ },
25
+ mainnet: {
26
+ network: 'mainnet',
27
+ publisherUrl: 'https://publisher.walrus.space',
28
+ aggregatorUrl: 'https://aggregator.walrus.space',
29
+ suiRpcUrl: 'https://fullnode.mainnet.sui.io:443',
30
+ },
31
+ };
32
+
33
+ function getNetworkConfig(network: WalrusNetwork): MystenWalrusConfig {
34
+ return NETWORK_CONFIGS[network];
35
+ }
36
+
37
+ // Client Management
38
+ let walrusClient: WalrusExtendedClient | null = null;
39
+
40
+ export function getWalrusClient(): WalrusExtendedClient {
41
+ if (walrusClient) {
42
+ return walrusClient;
43
+ }
44
+
45
+ const env = loadEnv();
46
+
47
+ // Validate network value before casting
48
+ const allowedNetworks: WalrusNetwork[] = ['testnet', 'mainnet'];
49
+ if (!allowedNetworks.includes(env.walrusNetwork as WalrusNetwork)) {
50
+ throw new Error(
51
+ `Invalid WALRUS_NETWORK: ${env.walrusNetwork}. Must be one of: ${allowedNetworks.join(', ')}`
52
+ );
53
+ }
54
+ const network = env.walrusNetwork as WalrusNetwork;
55
+ const config = getNetworkConfig(network);
56
+
57
+ // Use SuiClient (required for Walrus SDK and CoinWithBalance intent)
58
+ const suiClient = new SuiClient({
59
+ url:
60
+ env.suiRpc ||
61
+ config.suiRpcUrl ||
62
+ getFullnodeUrl(network === 'testnet' ? 'testnet' : 'mainnet'),
63
+ });
64
+
65
+ // Extend the client with Walrus capabilities and upload relay
66
+ walrusClient = suiClient.$extend(
67
+ walrus({
68
+ network: network, // REQUIRED: Walrus SDK needs to know which network
69
+ // Use CDN for WASM - more reliable than bundler resolution
70
+ wasmUrl: 'https://unpkg.com/@mysten/walrus-wasm@latest/web/walrus_wasm_bg.wasm',
71
+ uploadRelay: {
72
+ host:
73
+ env.walrusPublisher ||
74
+ config.publisherUrl ||
75
+ `https://upload-relay.${network}.walrus.space`,
76
+ sendTip: null, // Skip tip config fetch to avoid CORS issues in development
77
+ },
78
+ ...(env.walrusAggregator && { aggregatorUrl: env.walrusAggregator }),
79
+ })
80
+ );
81
+
82
+ return walrusClient;
83
+ }
84
+
85
+ export function resetWalrusClient(): void {
86
+ walrusClient = null;
87
+ }
@@ -0,0 +1,4 @@
1
+ // Walrus library exports
2
+ export * from './types.js';
3
+ export * from './adapter.js';
4
+ export * from './client.js';
@@ -1,58 +1,83 @@
1
- /**
2
- * Universal storage adapter interface for Walrus
3
- *
4
- * This interface abstracts SDK-specific implementations,
5
- * allowing use case layers to work with any Walrus SDK.
6
- */
7
-
8
- export interface BlobMetadata {
9
- blobId: string;
10
- size: number;
11
- contentType?: string;
12
- createdAt: number;
13
- expiresAt?: number;
14
- }
15
-
16
- export interface UploadOptions {
17
- /** Number of epochs to store (Walrus-specific) */
18
- epochs?: number;
19
- /** MIME type of the content */
20
- contentType?: string;
21
- }
22
-
23
- export interface DownloadOptions {
24
- /** Byte range (for large files) */
25
- range?: { start: number; end: number };
26
- }
27
-
28
- export interface StorageAdapter {
29
- /**
30
- * Upload data to Walrus storage
31
- * @param data - File or raw bytes to upload
32
- * @param options - Upload configuration
33
- * @returns Blob ID (permanent reference)
34
- */
35
- upload(data: File | Uint8Array, options?: UploadOptions): Promise<string>;
36
-
37
- /**
38
- * Download blob data by ID
39
- * @param blobId - Unique blob identifier
40
- * @param options - Download configuration
41
- * @returns Raw blob data
42
- */
43
- download(blobId: string, options?: DownloadOptions): Promise<Uint8Array>;
44
-
45
- /**
46
- * Get blob metadata without downloading content
47
- * @param blobId - Unique blob identifier
48
- * @returns Metadata object
49
- */
50
- getMetadata(blobId: string): Promise<BlobMetadata>;
51
-
52
- /**
53
- * Check if blob exists
54
- * @param blobId - Unique blob identifier
55
- * @returns True if blob is accessible
56
- */
57
- exists(blobId: string): Promise<boolean>;
58
- }
1
+ /**
2
+ * Universal storage adapter interface for Walrus
3
+ *
4
+ * This interface abstracts SDK-specific implementations,
5
+ * allowing use case layers to work with any Walrus SDK.
6
+ */
7
+
8
+ import type { SuiClient } from '@mysten/sui/client';
9
+ import type { Transaction } from '@mysten/sui/transactions';
10
+
11
+ export interface BlobMetadata {
12
+ blobId: string;
13
+ size: number;
14
+ contentType?: string;
15
+ createdAt: number;
16
+ expiresAt?: number;
17
+ /** Original filename with extension */
18
+ fileName?: string;
19
+ /** All tags from WalrusFile */
20
+ tags?: Record<string, string>;
21
+ }
22
+
23
+ export interface SignAndExecuteTransactionArgs {
24
+ transaction: Transaction;
25
+ }
26
+
27
+ export interface SignAndExecuteTransactionResult {
28
+ digest: string;
29
+ effects?: unknown;
30
+ }
31
+
32
+ export interface UploadOptions {
33
+ /** Number of epochs to store (Walrus-specific) */
34
+ epochs?: number;
35
+ /** MIME type of the content */
36
+ contentType?: string;
37
+ /** Sui client with Walrus extension (from useSuiClient hook) */
38
+ client?: SuiClient;
39
+ /** Wallet signer for authenticated uploads with address and transaction signing */
40
+ signer?: {
41
+ address: string;
42
+ signAndExecuteTransaction: (args: SignAndExecuteTransactionArgs) => Promise<SignAndExecuteTransactionResult>;
43
+ };
44
+ }
45
+
46
+ export interface DownloadOptions {
47
+ /** Byte range (for large files) */
48
+ range?: { start: number; end: number };
49
+ /** Output format - auto-detects if not specified */
50
+ format?: 'bytes' | 'text' | 'json';
51
+ }
52
+
53
+ export interface StorageAdapter {
54
+ /**
55
+ * Upload data to Walrus storage
56
+ * @param data - File or raw bytes to upload
57
+ * @param options - Upload configuration
58
+ * @returns Blob ID (permanent reference)
59
+ */
60
+ upload(data: File | Uint8Array, options?: UploadOptions): Promise<string>;
61
+
62
+ /**
63
+ * Download blob data by ID
64
+ * @param blobId - Unique blob identifier
65
+ * @param options - Download configuration
66
+ * @returns Blob data in requested format (Uint8Array, string, or JSON)
67
+ */
68
+ download(blobId: string, options?: DownloadOptions): Promise<Uint8Array | string | unknown>;
69
+
70
+ /**
71
+ * Get blob metadata without downloading content
72
+ * @param blobId - Unique blob identifier
73
+ * @returns Metadata object
74
+ */
75
+ getMetadata(blobId: string): Promise<BlobMetadata>;
76
+
77
+ /**
78
+ * Check if blob exists
79
+ * @param blobId - Unique blob identifier
80
+ * @returns True if blob is accessible
81
+ */
82
+ exists(blobId: string): Promise<boolean>;
83
+ }