@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 3mate Labs
3
+ Copyright (c) 2025 3mate Labs
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # @3mate/walrus-sponsor-sdk
2
2
 
3
- Official SDK for [3mate Walrus Sponsor](https://github.com/3MateLabs/walrus-sponsor-sdk) — sponsored blob storage on the [Walrus](https://walrus.space) network.
3
+ [![npm version](https://img.shields.io/npm/v/@3mate/walrus-sponsor-sdk)](https://www.npmjs.com/package/@3mate/walrus-sponsor-sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](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 walrus = new WalrusSponsor({
26
+ const client = new WalrusSponsor({
19
27
  apiKey: "sbk_live_...",
20
- baseUrl: "https://your-backend.com",
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
- // Upload a file (browser)
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 result = await walrus.upload(file, {
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
- console.log("View:", walrus.getBlobUrl(result.blobId));
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; // Required — your API key (sbk_live_...)
40
- baseUrl: string; // Required — your backend URL
41
- aggregatorUrl?: string; // Optional — defaults to mainnet aggregator
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 backend is live |
50
- | `epoch()` | Get current Walrus epoch info |
51
- | `estimateCost(size, epochs?)` | Estimate WAL storage cost |
52
- | `upload(file, opts)` | Upload a file via sponsored publisher |
53
- | `listBlobs(opts?)` | List blobs with optional filters |
54
- | `getBlob(id)` | Get single blob details |
55
- | `getBlobUrl(blobId)` | Build aggregator URL (no network call) |
56
-
57
- ### Upload
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
- // Browser — File or Blob
61
- await walrus.upload(file, { creatorAddress: "0x..." });
62
-
63
- // Node.js Buffer
64
- await walrus.upload(
65
- { data: buffer, filename: "photo.png", contentType: "image/png" },
66
- { creatorAddress: "0x...", epochs: 3 }
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
- Options:
108
+ The `file` parameter accepts:
109
+ - **Node.js**: `string` (file path), `Buffer`, `Uint8Array`, `ReadableStream`
110
+ - **Browser**: `File`, `Blob`
71
111
 
72
- | Option | Type | Default | Description |
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
- ### List & Get Blobs
114
+ ### Config
79
115
 
80
- ```typescript
81
- const { blobs, total } = await walrus.listBlobs({
82
- status: "active",
83
- creatorAddress: "0x...",
84
- limit: 10,
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
- ### Estimate Cost
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
- ```typescript
94
- const cost = await walrus.estimateCost(1024 * 1024, 3); // 1 MB, 3 epochs
95
- console.log(cost.totalCost); // WAL amount as string
96
- console.log(cost.storageCost); // storage component
97
- console.log(cost.writeCost); // write component
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
- ### Error Handling
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 walrus.upload(file, opts);
153
+ await client.upload("./file.txt", { creatorAddress: "0x..." });
107
154
  } catch (err) {
108
155
  if (err instanceof WalrusSponsorError) {
109
- console.error(err.message); // Human-readable message
110
- console.error(err.statusCode); // 401, 402, 502, etc.
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
- | Status | Meaning |
117
- |--------|---------|
118
- | 401 | Invalid or missing API key |
119
- | 402 | Insufficient workspace balance |
120
- | 502 | Storage service unavailable |
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