@3mate/walrus-sponsor-sdk 0.1.0 → 0.3.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/LICENSE +1 -1
- package/README.md +159 -63
- package/dist/cli.js +814 -0
- package/dist/index.d.mts +144 -158
- package/dist/index.d.ts +144 -158
- package/dist/index.js +201 -199
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +191 -201
- package/dist/index.mjs.map +1 -0
- package/package.json +21 -7
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# @3mate/walrus-sponsor-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@3mate/walrus-sponsor-sdk)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Official SDK & CLI for [Walrus Sponsor Service](https://walrus-sponsor.krill.tube) — sponsored blob storage on the [Walrus](https://walrus.space) network.
|
|
4
7
|
|
|
5
8
|
Zero runtime dependencies. Works in Node.js 18+ and modern browsers.
|
|
6
9
|
|
|
@@ -8,117 +11,210 @@ Zero runtime dependencies. Works in Node.js 18+ and modern browsers.
|
|
|
8
11
|
|
|
9
12
|
```bash
|
|
10
13
|
npm install @3mate/walrus-sponsor-sdk
|
|
14
|
+
|
|
15
|
+
# For CLI usage (global)
|
|
16
|
+
npm install -g @3mate/walrus-sponsor-sdk
|
|
11
17
|
```
|
|
12
18
|
|
|
13
19
|
## Quick Start
|
|
14
20
|
|
|
21
|
+
### SDK (programmatic)
|
|
22
|
+
|
|
15
23
|
```typescript
|
|
16
24
|
import { WalrusSponsor } from "@3mate/walrus-sponsor-sdk";
|
|
17
25
|
|
|
18
|
-
const
|
|
26
|
+
const client = new WalrusSponsor({
|
|
19
27
|
apiKey: "sbk_live_...",
|
|
20
|
-
baseUrl
|
|
28
|
+
// baseUrl defaults to https://walrus-sponsor.krill.tube
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Upload a file (Node.js)
|
|
32
|
+
const result = await client.upload("./photo.jpg", {
|
|
33
|
+
creatorAddress: "0x123...",
|
|
34
|
+
epochs: 5,
|
|
21
35
|
});
|
|
22
36
|
|
|
23
|
-
|
|
37
|
+
console.log("Blob ID:", result.blob_id);
|
|
38
|
+
console.log("View:", client.getBlobUrl(result.blob_id));
|
|
39
|
+
|
|
40
|
+
// Upload a file (Browser)
|
|
24
41
|
const file = document.querySelector<HTMLInputElement>("#file")!.files![0];
|
|
25
|
-
const
|
|
42
|
+
const browserResult = await client.upload(file, {
|
|
26
43
|
creatorAddress: "0x123...",
|
|
27
44
|
epochs: 3,
|
|
28
45
|
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### CLI
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Configure (API key stored in OS keychain — never plaintext on disk)
|
|
52
|
+
krilly config set-key sbk_live_abc123...
|
|
53
|
+
|
|
54
|
+
# Upload
|
|
55
|
+
krilly upload ./photo.jpg --creator 0x123... --epochs 5
|
|
29
56
|
|
|
30
|
-
|
|
57
|
+
# List blobs
|
|
58
|
+
krilly blobs --status active --pretty
|
|
59
|
+
|
|
60
|
+
# Get blob details
|
|
61
|
+
krilly blob 0xabc...
|
|
62
|
+
|
|
63
|
+
# Estimate cost
|
|
64
|
+
krilly cost --size 1048576 --epochs 3 --pretty
|
|
31
65
|
```
|
|
32
66
|
|
|
33
|
-
## API
|
|
67
|
+
## API Reference
|
|
34
68
|
|
|
35
69
|
### Constructor
|
|
36
70
|
|
|
37
71
|
```typescript
|
|
38
72
|
new WalrusSponsor({
|
|
39
|
-
apiKey: string;
|
|
40
|
-
baseUrl
|
|
41
|
-
aggregatorUrl?: string;
|
|
73
|
+
apiKey: string; // Required — sbk_live_...
|
|
74
|
+
baseUrl?: string; // Default: https://walrus-sponsor.krill.tube
|
|
75
|
+
aggregatorUrl?: string; // Default: https://aggregator.walrus-mainnet.walrus.space
|
|
42
76
|
});
|
|
43
77
|
```
|
|
44
78
|
|
|
45
79
|
### Methods
|
|
46
80
|
|
|
47
|
-
| Method | Description |
|
|
48
|
-
|
|
49
|
-
| `health()` | Check if
|
|
50
|
-
| `epoch()` | Get current Walrus epoch info |
|
|
51
|
-
| `
|
|
52
|
-
| `upload(file, opts)` | Upload
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
| Method | Description | Returns |
|
|
82
|
+
|--------|-------------|---------|
|
|
83
|
+
| `health()` | Check if service is live | `{ status, timestamp }` |
|
|
84
|
+
| `epoch()` | Get current Walrus epoch info | `{ currentEpoch, startTime, endTime }` |
|
|
85
|
+
| `storageCost(size, epochs)` | Estimate WAL storage cost | `{ total_cost, storage_cost, write_cost }` |
|
|
86
|
+
| `upload(file, opts)` | Upload file (sponsor pays WAL) | `{ blob_id, tx_digest, ... }` |
|
|
87
|
+
| `blobs(opts?)` | List blobs (filter by status/creator) | `{ blobs[], total }` |
|
|
88
|
+
| `blob(id)` | Get single blob detail | `BlobDetail` |
|
|
89
|
+
| `delete(blobId, systemObjId)` | Delete blob, reclaim storage | `{ tx_digest, storage_returned }` |
|
|
90
|
+
| `extend(opts)` | Extend blob storage duration | `{ new_end_epoch, tx_digest }` |
|
|
91
|
+
| `fund(blobId, coinId)` | Add WAL funds to a blob | `{ tx_digest }` |
|
|
92
|
+
| `register(opts)` | Advanced: client-side upload step 1 | `{ blob_object_id, tx_digest }` |
|
|
93
|
+
| `certify(opts)` | Advanced: client-side upload step 2 | `{ sponsored_blob_id, tx_digest }` |
|
|
94
|
+
| `getBlobUrl(blobId)` | Get aggregator download URL | `string` |
|
|
95
|
+
|
|
96
|
+
### Upload Options
|
|
58
97
|
|
|
59
98
|
```typescript
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
99
|
+
client.upload(file, {
|
|
100
|
+
creatorAddress: "0x...", // Required — who owns the blob
|
|
101
|
+
epochs: 5, // Storage duration (default: 1)
|
|
102
|
+
deletable: true, // Allow deletion before expiry (default: true)
|
|
103
|
+
filename: "photo.jpg", // Optional filename override
|
|
104
|
+
contentType: "image/jpeg", // Optional MIME type
|
|
105
|
+
});
|
|
68
106
|
```
|
|
69
107
|
|
|
70
|
-
|
|
108
|
+
The `file` parameter accepts:
|
|
109
|
+
- **Node.js**: `string` (file path), `Buffer`, `Uint8Array`, `ReadableStream`
|
|
110
|
+
- **Browser**: `File`, `Blob`
|
|
71
111
|
|
|
72
|
-
|
|
73
|
-
|--------|------|---------|-------------|
|
|
74
|
-
| `creatorAddress` | `string` | — | Required. Sui address to own the blob |
|
|
75
|
-
| `epochs` | `number` | `1` | Storage duration in epochs |
|
|
76
|
-
| `deletable` | `boolean` | `true` | Whether the blob can be deleted |
|
|
112
|
+
## CLI Commands
|
|
77
113
|
|
|
78
|
-
###
|
|
114
|
+
### Config
|
|
79
115
|
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
offset: 0,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const blob = await walrus.getBlob("0x1234...");
|
|
116
|
+
```bash
|
|
117
|
+
krilly config set-key <api_key> # Save API key (OS keychain)
|
|
118
|
+
krilly config set-url <url> # Set backend URL
|
|
119
|
+
krilly config set-aggregator <url> # Set aggregator URL
|
|
120
|
+
krilly config show # Show current config
|
|
89
121
|
```
|
|
90
122
|
|
|
91
|
-
|
|
123
|
+
> 🔒 API keys are stored in your OS keychain (macOS Keychain / Linux libsecret).
|
|
124
|
+
> Falls back to AES-256-GCM encrypted file if keychain is unavailable.
|
|
92
125
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
126
|
+
### Operations
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
krilly health
|
|
130
|
+
krilly epoch
|
|
131
|
+
krilly cost --size <bytes> --epochs <n>
|
|
132
|
+
|
|
133
|
+
krilly upload <file> --creator <address> [--epochs <n>] [--deletable]
|
|
134
|
+
krilly blobs [--status <s>] [--creator <addr>] [--limit <n>] [--offset <n>]
|
|
135
|
+
krilly blob <id>
|
|
136
|
+
krilly delete <id> --system-object <id>
|
|
137
|
+
krilly extend <id> --epochs <n> --system-object <id> --payment-coin <id>
|
|
138
|
+
krilly fund <id> --coin <id>
|
|
139
|
+
|
|
140
|
+
krilly url <blob_id>
|
|
98
141
|
```
|
|
99
142
|
|
|
100
|
-
|
|
143
|
+
Add `--pretty` to any command for formatted JSON output.
|
|
144
|
+
|
|
145
|
+
## Error Handling
|
|
101
146
|
|
|
102
147
|
```typescript
|
|
103
|
-
import { WalrusSponsorError } from "@3mate/walrus-sponsor-sdk";
|
|
148
|
+
import { WalrusSponsor, WalrusSponsorError } from "@3mate/walrus-sponsor-sdk";
|
|
149
|
+
|
|
150
|
+
const client = new WalrusSponsor({ apiKey: "sbk_live_..." });
|
|
104
151
|
|
|
105
152
|
try {
|
|
106
|
-
await
|
|
153
|
+
await client.upload("./file.txt", { creatorAddress: "0x..." });
|
|
107
154
|
} catch (err) {
|
|
108
155
|
if (err instanceof WalrusSponsorError) {
|
|
109
|
-
console.error(err.message);
|
|
110
|
-
|
|
111
|
-
console.error(err.details); // Raw API error body
|
|
156
|
+
console.error(`API Error [${err.status}]: ${err.message}`);
|
|
157
|
+
// err.code — e.g. "INSUFFICIENT_BALANCE", "RATE_LIMIT_EXCEEDED"
|
|
112
158
|
}
|
|
113
159
|
}
|
|
114
160
|
```
|
|
115
161
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
162
|
+
## Security
|
|
163
|
+
|
|
164
|
+
- API keys are **never stored in plaintext** on disk
|
|
165
|
+
- macOS: stored in Keychain (`security` CLI)
|
|
166
|
+
- Linux: stored in GNOME Keyring / KDE Wallet (`secret-tool`)
|
|
167
|
+
- Fallback: AES-256-GCM encrypted file at `~/.krilly/.vault`
|
|
168
|
+
- Non-secret config (`baseUrl`) stored in `~/.krilly/config.json`
|
|
121
169
|
|
|
122
170
|
## License
|
|
123
171
|
|
|
124
|
-
MIT
|
|
172
|
+
MIT — [3mate Labs](https://github.com/3MateLabs)
|
|
173
|
+
|
|
174
|
+
## AI Agent Integration
|
|
175
|
+
|
|
176
|
+
Krilly is designed to be agent-friendly. Give your AI agent decentralized storage in one line:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { WalrusSponsor } from "krilly";
|
|
180
|
+
|
|
181
|
+
const walrus = new WalrusSponsor({
|
|
182
|
+
apiKey: process.env.WALRUS_API_KEY, // set in agent environment
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Upload agent-generated content
|
|
186
|
+
const result = await walrus.upload(
|
|
187
|
+
{ data: Buffer.from(output), filename: "report.json", contentType: "application/json" },
|
|
188
|
+
{ creatorAddress: "0x...", epochs: 5 }
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// Permanent, decentralized URL — no auth needed to read
|
|
192
|
+
const url = walrus.getBlobUrl(result.blob_id);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### For Agent Frameworks
|
|
196
|
+
|
|
197
|
+
Each SDK method maps 1:1 to a tool/function call:
|
|
198
|
+
|
|
199
|
+
| Tool | Method | Description |
|
|
200
|
+
|------|--------|-------------|
|
|
201
|
+
| `walrus_upload` | `upload(file, opts)` | Store file on Walrus |
|
|
202
|
+
| `walrus_list` | `blobs(opts?)` | List stored blobs |
|
|
203
|
+
| `walrus_get` | `blob(id)` | Get blob metadata |
|
|
204
|
+
| `walrus_cost` | `estimateCost(size, epochs)` | Estimate cost |
|
|
205
|
+
| `walrus_delete` | `delete(id, sysObj)` | Delete blob |
|
|
206
|
+
| `walrus_extend` | `extend(opts)` | Extend storage |
|
|
207
|
+
| `walrus_url` | `getBlobUrl(id)` | Get download URL |
|
|
208
|
+
|
|
209
|
+
Works with LangChain, CrewAI, AutoGPT, OpenClaw, or any framework that supports npm packages.
|
|
210
|
+
|
|
211
|
+
### CLI for Shell-Based Agents
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
export WALRUS_API_KEY=sbk_live_...
|
|
215
|
+
krilly config set-key $WALRUS_API_KEY
|
|
216
|
+
krilly upload ./data.json --creator 0x... --epochs 5
|
|
217
|
+
krilly blobs --pretty
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
See full docs: https://walrus-sponsor.krill.tube/docs/ai-agents
|