@snaha/swarm-id 0.0.1
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 +431 -0
- package/dist/chunk/bmt.d.ts +17 -0
- package/dist/chunk/bmt.d.ts.map +1 -0
- package/dist/chunk/cac.d.ts +18 -0
- package/dist/chunk/cac.d.ts.map +1 -0
- package/dist/chunk/constants.d.ts +10 -0
- package/dist/chunk/constants.d.ts.map +1 -0
- package/dist/chunk/encrypted-cac.d.ts +48 -0
- package/dist/chunk/encrypted-cac.d.ts.map +1 -0
- package/dist/chunk/encryption.d.ts +86 -0
- package/dist/chunk/encryption.d.ts.map +1 -0
- package/dist/chunk/index.d.ts +6 -0
- package/dist/chunk/index.d.ts.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/proxy/act/act.d.ts +78 -0
- package/dist/proxy/act/act.d.ts.map +1 -0
- package/dist/proxy/act/crypto.d.ts +44 -0
- package/dist/proxy/act/crypto.d.ts.map +1 -0
- package/dist/proxy/act/grantee-list.d.ts +82 -0
- package/dist/proxy/act/grantee-list.d.ts.map +1 -0
- package/dist/proxy/act/history.d.ts +183 -0
- package/dist/proxy/act/history.d.ts.map +1 -0
- package/dist/proxy/act/index.d.ts +104 -0
- package/dist/proxy/act/index.d.ts.map +1 -0
- package/dist/proxy/chunking-encrypted.d.ts +14 -0
- package/dist/proxy/chunking-encrypted.d.ts.map +1 -0
- package/dist/proxy/chunking.d.ts +15 -0
- package/dist/proxy/chunking.d.ts.map +1 -0
- package/dist/proxy/download-data.d.ts +16 -0
- package/dist/proxy/download-data.d.ts.map +1 -0
- package/dist/proxy/feed-manifest.d.ts +62 -0
- package/dist/proxy/feed-manifest.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/async-finder.d.ts +77 -0
- package/dist/proxy/feeds/epochs/async-finder.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/epoch.d.ts +88 -0
- package/dist/proxy/feeds/epochs/epoch.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/finder.d.ts +67 -0
- package/dist/proxy/feeds/epochs/finder.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/index.d.ts +35 -0
- package/dist/proxy/feeds/epochs/index.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/test-utils.d.ts +93 -0
- package/dist/proxy/feeds/epochs/test-utils.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/types.d.ts +109 -0
- package/dist/proxy/feeds/epochs/types.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/updater.d.ts +68 -0
- package/dist/proxy/feeds/epochs/updater.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/utils.d.ts +22 -0
- package/dist/proxy/feeds/epochs/utils.d.ts.map +1 -0
- package/dist/proxy/feeds/index.d.ts +5 -0
- package/dist/proxy/feeds/index.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/async-finder.d.ts +14 -0
- package/dist/proxy/feeds/sequence/async-finder.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/finder.d.ts +17 -0
- package/dist/proxy/feeds/sequence/finder.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/index.d.ts +23 -0
- package/dist/proxy/feeds/sequence/index.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/types.d.ts +80 -0
- package/dist/proxy/feeds/sequence/types.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/updater.d.ts +26 -0
- package/dist/proxy/feeds/sequence/updater.d.ts.map +1 -0
- package/dist/proxy/index.d.ts +6 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/manifest-builder.d.ts +183 -0
- package/dist/proxy/manifest-builder.d.ts.map +1 -0
- package/dist/proxy/mantaray-encrypted.d.ts +27 -0
- package/dist/proxy/mantaray-encrypted.d.ts.map +1 -0
- package/dist/proxy/mantaray.d.ts +26 -0
- package/dist/proxy/mantaray.d.ts.map +1 -0
- package/dist/proxy/types.d.ts +29 -0
- package/dist/proxy/types.d.ts.map +1 -0
- package/dist/proxy/upload-data.d.ts +17 -0
- package/dist/proxy/upload-data.d.ts.map +1 -0
- package/dist/proxy/upload-encrypted-data.d.ts +103 -0
- package/dist/proxy/upload-encrypted-data.d.ts.map +1 -0
- package/dist/schemas.d.ts +240 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/storage/debounced-uploader.d.ts +62 -0
- package/dist/storage/debounced-uploader.d.ts.map +1 -0
- package/dist/storage/utilization-store.d.ts +108 -0
- package/dist/storage/utilization-store.d.ts.map +1 -0
- package/dist/swarm-id-auth.d.ts +74 -0
- package/dist/swarm-id-auth.d.ts.map +1 -0
- package/dist/swarm-id-auth.js +2 -0
- package/dist/swarm-id-auth.js.map +1 -0
- package/dist/swarm-id-client.d.ts +878 -0
- package/dist/swarm-id-client.d.ts.map +1 -0
- package/dist/swarm-id-client.js +2 -0
- package/dist/swarm-id-client.js.map +1 -0
- package/dist/swarm-id-proxy.d.ts +236 -0
- package/dist/swarm-id-proxy.d.ts.map +1 -0
- package/dist/swarm-id-proxy.js +2 -0
- package/dist/swarm-id-proxy.js.map +1 -0
- package/dist/swarm-id.esm.js +2 -0
- package/dist/swarm-id.esm.js.map +1 -0
- package/dist/swarm-id.umd.js +2 -0
- package/dist/swarm-id.umd.js.map +1 -0
- package/dist/sync/index.d.ts +9 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/key-derivation.d.ts +25 -0
- package/dist/sync/key-derivation.d.ts.map +1 -0
- package/dist/sync/restore-account.d.ts +28 -0
- package/dist/sync/restore-account.d.ts.map +1 -0
- package/dist/sync/serialization.d.ts +16 -0
- package/dist/sync/serialization.d.ts.map +1 -0
- package/dist/sync/store-interfaces.d.ts +53 -0
- package/dist/sync/store-interfaces.d.ts.map +1 -0
- package/dist/sync/sync-account.d.ts +44 -0
- package/dist/sync/sync-account.d.ts.map +1 -0
- package/dist/sync/types.d.ts +13 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/test-fixtures.d.ts +17 -0
- package/dist/test-fixtures.d.ts.map +1 -0
- package/dist/types-BD_VkNn0.js +2 -0
- package/dist/types-BD_VkNn0.js.map +1 -0
- package/dist/types-lJCaT-50.js +2 -0
- package/dist/types-lJCaT-50.js.map +1 -0
- package/dist/types.d.ts +2157 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/account-payload.d.ts +94 -0
- package/dist/utils/account-payload.d.ts.map +1 -0
- package/dist/utils/account-state-snapshot.d.ts +38 -0
- package/dist/utils/account-state-snapshot.d.ts.map +1 -0
- package/dist/utils/backup-encryption.d.ts +127 -0
- package/dist/utils/backup-encryption.d.ts.map +1 -0
- package/dist/utils/batch-utilization.d.ts +432 -0
- package/dist/utils/batch-utilization.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +11 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/hex.d.ts +17 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/key-derivation.d.ts +92 -0
- package/dist/utils/key-derivation.d.ts.map +1 -0
- package/dist/utils/storage-managers.d.ts +65 -0
- package/dist/utils/storage-managers.d.ts.map +1 -0
- package/dist/utils/swarm-id-export.d.ts +24 -0
- package/dist/utils/swarm-id-export.d.ts.map +1 -0
- package/dist/utils/ttl.d.ts +49 -0
- package/dist/utils/ttl.d.ts.map +1 -0
- package/dist/utils/url.d.ts +41 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/versioned-storage.d.ts +131 -0
- package/dist/utils/versioned-storage.d.ts.map +1 -0
- package/package.json +78 -0
- package/src/chunk/bmt.test.ts +217 -0
- package/src/chunk/bmt.ts +57 -0
- package/src/chunk/cac.test.ts +214 -0
- package/src/chunk/cac.ts +65 -0
- package/src/chunk/constants.ts +18 -0
- package/src/chunk/encrypted-cac.test.ts +385 -0
- package/src/chunk/encrypted-cac.ts +131 -0
- package/src/chunk/encryption.test.ts +352 -0
- package/src/chunk/encryption.ts +300 -0
- package/src/chunk/index.ts +47 -0
- package/src/index.ts +430 -0
- package/src/proxy/act/act.test.ts +278 -0
- package/src/proxy/act/act.ts +158 -0
- package/src/proxy/act/bee-compat.test.ts +948 -0
- package/src/proxy/act/crypto.test.ts +436 -0
- package/src/proxy/act/crypto.ts +376 -0
- package/src/proxy/act/grantee-list.test.ts +393 -0
- package/src/proxy/act/grantee-list.ts +239 -0
- package/src/proxy/act/history.test.ts +360 -0
- package/src/proxy/act/history.ts +413 -0
- package/src/proxy/act/index.test.ts +748 -0
- package/src/proxy/act/index.ts +853 -0
- package/src/proxy/chunking-encrypted.ts +95 -0
- package/src/proxy/chunking.ts +65 -0
- package/src/proxy/download-data.ts +448 -0
- package/src/proxy/feed-manifest.ts +174 -0
- package/src/proxy/feeds/epochs/async-finder.ts +372 -0
- package/src/proxy/feeds/epochs/epoch.test.ts +249 -0
- package/src/proxy/feeds/epochs/epoch.ts +181 -0
- package/src/proxy/feeds/epochs/finder.ts +282 -0
- package/src/proxy/feeds/epochs/index.ts +73 -0
- package/src/proxy/feeds/epochs/integration.test.ts +1336 -0
- package/src/proxy/feeds/epochs/test-utils.ts +274 -0
- package/src/proxy/feeds/epochs/types.ts +128 -0
- package/src/proxy/feeds/epochs/updater.ts +192 -0
- package/src/proxy/feeds/epochs/utils.ts +62 -0
- package/src/proxy/feeds/index.ts +5 -0
- package/src/proxy/feeds/sequence/async-finder.ts +31 -0
- package/src/proxy/feeds/sequence/finder.ts +73 -0
- package/src/proxy/feeds/sequence/index.ts +54 -0
- package/src/proxy/feeds/sequence/integration.test.ts +966 -0
- package/src/proxy/feeds/sequence/types.ts +103 -0
- package/src/proxy/feeds/sequence/updater.ts +71 -0
- package/src/proxy/index.ts +5 -0
- package/src/proxy/manifest-builder.test.ts +427 -0
- package/src/proxy/manifest-builder.ts +679 -0
- package/src/proxy/mantaray-encrypted.ts +78 -0
- package/src/proxy/mantaray.ts +104 -0
- package/src/proxy/types.ts +32 -0
- package/src/proxy/upload-data.ts +189 -0
- package/src/proxy/upload-encrypted-data.ts +658 -0
- package/src/schemas.ts +299 -0
- package/src/storage/debounced-uploader.ts +192 -0
- package/src/storage/utilization-store.ts +397 -0
- package/src/swarm-id-client.test.ts +99 -0
- package/src/swarm-id-client.ts +3095 -0
- package/src/swarm-id-proxy.ts +3891 -0
- package/src/sync/index.ts +28 -0
- package/src/sync/restore-account.ts +90 -0
- package/src/sync/serialization.ts +39 -0
- package/src/sync/store-interfaces.ts +62 -0
- package/src/sync/sync-account.test.ts +302 -0
- package/src/sync/sync-account.ts +396 -0
- package/src/sync/types.ts +11 -0
- package/src/test-fixtures.ts +109 -0
- package/src/types.ts +1651 -0
- package/src/utils/account-state-snapshot.test.ts +595 -0
- package/src/utils/account-state-snapshot.ts +94 -0
- package/src/utils/backup-encryption.test.ts +442 -0
- package/src/utils/backup-encryption.ts +352 -0
- package/src/utils/batch-utilization.ts +1309 -0
- package/src/utils/constants.ts +20 -0
- package/src/utils/hex.ts +27 -0
- package/src/utils/key-derivation.ts +197 -0
- package/src/utils/storage-managers.ts +365 -0
- package/src/utils/ttl.ts +129 -0
- package/src/utils/url.test.ts +136 -0
- package/src/utils/url.ts +71 -0
- package/src/utils/versioned-storage.ts +323 -0
|
@@ -0,0 +1,878 @@
|
|
|
1
|
+
import type { ClientOptions, ConnectOptions, AuthStatus, ConnectionInfo, UploadResult, FileData, UploadOptions, ActUploadOptions, DownloadOptions, RequestOptions, Reference, SOCReader, SOCWriter, FeedReaderOptions, FeedWriterOptions, FeedReader, FeedWriter, SequentialFeedReaderOptions, SequentialFeedWriterOptions, SequentialFeedReader, SequentialFeedWriter, PostageBatch } from "./types";
|
|
2
|
+
import { EthAddress, PrivateKey } from "@ethersphere/bee-js";
|
|
3
|
+
/**
|
|
4
|
+
* Main client library for integrating Swarm ID authentication and storage capabilities
|
|
5
|
+
* into web applications.
|
|
6
|
+
*
|
|
7
|
+
* SwarmIdClient enables parent windows to interact with a Swarm ID iframe proxy,
|
|
8
|
+
* providing secure authentication, identity management, and data upload/download
|
|
9
|
+
* functionality to the Swarm decentralized storage network.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const client = new SwarmIdClient({
|
|
14
|
+
* iframeOrigin: 'https://swarm-id.example.com',
|
|
15
|
+
* metadata: {
|
|
16
|
+
* name: 'My App',
|
|
17
|
+
* description: 'A decentralized application'
|
|
18
|
+
* },
|
|
19
|
+
* onAuthChange: (authenticated) => {
|
|
20
|
+
* console.log('Auth status changed:', authenticated)
|
|
21
|
+
* }
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* await client.initialize()
|
|
25
|
+
*
|
|
26
|
+
* const status = await client.checkAuthStatus()
|
|
27
|
+
* if (status.authenticated) {
|
|
28
|
+
* const result = await client.uploadData(new Uint8Array([1, 2, 3]))
|
|
29
|
+
* console.log('Uploaded with reference:', result.reference)
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class SwarmIdClient {
|
|
34
|
+
private iframe;
|
|
35
|
+
private iframeOrigin;
|
|
36
|
+
private iframePath;
|
|
37
|
+
private timeout;
|
|
38
|
+
private initializationTimeout;
|
|
39
|
+
private onAuthChange?;
|
|
40
|
+
private popupMode;
|
|
41
|
+
private metadata;
|
|
42
|
+
private buttonConfig?;
|
|
43
|
+
private containerId?;
|
|
44
|
+
private ready;
|
|
45
|
+
private readyPromise;
|
|
46
|
+
private readyResolve?;
|
|
47
|
+
private readyReject?;
|
|
48
|
+
private pendingRequests;
|
|
49
|
+
private requestIdCounter;
|
|
50
|
+
private messageListener;
|
|
51
|
+
private proxyInitializedPromise;
|
|
52
|
+
private proxyInitializedResolve?;
|
|
53
|
+
private proxyInitializedReject?;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new SwarmIdClient instance.
|
|
56
|
+
*
|
|
57
|
+
* @param options - Configuration options for the client
|
|
58
|
+
* @param options.iframeOrigin - The origin URL where the Swarm ID proxy iframe is hosted
|
|
59
|
+
* @param options.iframePath - The path to the proxy iframe (defaults to "/proxy")
|
|
60
|
+
* @param options.timeout - Request timeout in milliseconds (defaults to 30000)
|
|
61
|
+
* @param options.onAuthChange - Callback function invoked when authentication status changes
|
|
62
|
+
* @param options.popupMode - How to display the authentication popup: "popup" or "window" (defaults to "window")
|
|
63
|
+
* @param options.metadata - Application metadata shown to users during authentication
|
|
64
|
+
* @param options.metadata.name - Application name (1-100 characters)
|
|
65
|
+
* @param options.metadata.description - Optional application description (max 500 characters)
|
|
66
|
+
* @param options.metadata.icon - Optional application icon as a data URL (SVG or PNG, max 4KB)
|
|
67
|
+
* @param options.buttonConfig - Button configuration for the authentication UI (optional)
|
|
68
|
+
* @param options.buttonConfig.connectText - Text for the connect button (optional)
|
|
69
|
+
* @param options.buttonConfig.disconnectText - Text for the disconnect button (optional)
|
|
70
|
+
* @param options.buttonConfig.loadingText - Text shown during loading (optional)
|
|
71
|
+
* @param options.buttonConfig.backgroundColor - Background color for buttons (optional)
|
|
72
|
+
* @param options.buttonConfig.color - Text color for buttons (optional)
|
|
73
|
+
* @param options.buttonConfig.borderRadius - Border radius for buttons and iframe (optional)
|
|
74
|
+
* @param options.containerId - ID of container element to place iframe in (optional)
|
|
75
|
+
* @throws {Error} If the provided app metadata is invalid
|
|
76
|
+
*/
|
|
77
|
+
constructor(options: ClientOptions);
|
|
78
|
+
/**
|
|
79
|
+
* Initializes the client by creating and embedding the proxy iframe.
|
|
80
|
+
*
|
|
81
|
+
* This method must be called before using any other client methods.
|
|
82
|
+
* It creates a hidden iframe, waits for the proxy to initialize,
|
|
83
|
+
* identifies the parent application to the proxy, and waits for
|
|
84
|
+
* the proxy to signal readiness.
|
|
85
|
+
*
|
|
86
|
+
* @returns A promise that resolves when the client is fully initialized
|
|
87
|
+
* @throws {Error} If the client is already initialized
|
|
88
|
+
* @throws {Error} If the iframe fails to load
|
|
89
|
+
* @throws {Error} If the proxy does not respond within the timeout period (30 seconds)
|
|
90
|
+
* @throws {Error} If origin validation fails on the proxy side
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const client = new SwarmIdClient({ ... })
|
|
95
|
+
* try {
|
|
96
|
+
* await client.initialize()
|
|
97
|
+
* console.log('Client ready')
|
|
98
|
+
* } catch (error) {
|
|
99
|
+
* console.error('Failed to initialize:', error)
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
initialize(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Setup message listener for iframe responses
|
|
106
|
+
*/
|
|
107
|
+
private setupMessageListener;
|
|
108
|
+
/**
|
|
109
|
+
* Handle messages from iframe
|
|
110
|
+
*/
|
|
111
|
+
private handleIframeMessage;
|
|
112
|
+
/**
|
|
113
|
+
* Send message to iframe
|
|
114
|
+
*/
|
|
115
|
+
private sendMessage;
|
|
116
|
+
/**
|
|
117
|
+
* Send request and wait for response
|
|
118
|
+
*/
|
|
119
|
+
private sendRequest;
|
|
120
|
+
/**
|
|
121
|
+
* Generate unique request ID
|
|
122
|
+
*/
|
|
123
|
+
private generateRequestId;
|
|
124
|
+
private normalizeSocIdentifier;
|
|
125
|
+
private normalizeSocKey;
|
|
126
|
+
private normalizeFeedTopic;
|
|
127
|
+
private normalizeReference;
|
|
128
|
+
private normalizeFeedTimestamp;
|
|
129
|
+
private normalizeFeedIndex;
|
|
130
|
+
private normalizePayload;
|
|
131
|
+
private socChunkFromResponse;
|
|
132
|
+
/**
|
|
133
|
+
* Ensure client is initialized
|
|
134
|
+
*/
|
|
135
|
+
private ensureReady;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the authentication iframe element.
|
|
138
|
+
*
|
|
139
|
+
* The iframe displays authentication UI based on the current auth status:
|
|
140
|
+
* - If not authenticated: shows a "Connect" button
|
|
141
|
+
* - If authenticated: shows identity info and a "Disconnect" button
|
|
142
|
+
*
|
|
143
|
+
* The iframe is positioned fixed in the bottom-right corner of the viewport.
|
|
144
|
+
*
|
|
145
|
+
* @returns The iframe element displaying the authentication UI
|
|
146
|
+
* @throws {Error} If the client is not initialized
|
|
147
|
+
* @throws {Error} If the iframe is not available
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const iframe = client.getAuthIframe()
|
|
152
|
+
* // The iframe is already displayed; this returns a reference to it
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
getAuthIframe(): HTMLIFrameElement;
|
|
156
|
+
/**
|
|
157
|
+
* Checks the current authentication status with the Swarm ID proxy.
|
|
158
|
+
*
|
|
159
|
+
* @returns A promise resolving to the authentication status object
|
|
160
|
+
* @returns return.authenticated - Whether the user is currently authenticated
|
|
161
|
+
* @returns return.origin - The origin that authenticated (if authenticated)
|
|
162
|
+
* @throws {Error} If the client is not initialized
|
|
163
|
+
* @throws {Error} If the request times out
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const status = await client.checkAuthStatus()
|
|
168
|
+
* if (status.authenticated) {
|
|
169
|
+
* console.log('Authenticated from:', status.origin)
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
checkAuthStatus(): Promise<AuthStatus>;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the current postage batch for the authenticated identity.
|
|
176
|
+
*
|
|
177
|
+
* Returns information about the postage stamp associated with the
|
|
178
|
+
* connected identity, including batch ID, utilization, depth, and TTL.
|
|
179
|
+
*
|
|
180
|
+
* @returns A promise resolving to the PostageBatch or undefined if none is configured
|
|
181
|
+
* @throws {Error} If the client is not initialized
|
|
182
|
+
* @throws {Error} If the request times out
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const batch = await client.getPostageBatch()
|
|
187
|
+
* if (batch) {
|
|
188
|
+
* console.log('Batch ID:', batch.batchID)
|
|
189
|
+
* console.log('Utilization:', batch.utilization)
|
|
190
|
+
* console.log('Depth:', batch.depth)
|
|
191
|
+
* console.log('TTL:', batch.batchTTL)
|
|
192
|
+
* } else {
|
|
193
|
+
* console.log('No postage batch configured')
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
getPostageBatch(): Promise<PostageBatch | undefined>;
|
|
198
|
+
/**
|
|
199
|
+
* Disconnects the current session and clears authentication data.
|
|
200
|
+
*
|
|
201
|
+
* After disconnection, the user will need to re-authenticate to perform
|
|
202
|
+
* uploads or access identity-related features. The {@link onAuthChange}
|
|
203
|
+
* callback will be invoked with `false`.
|
|
204
|
+
*
|
|
205
|
+
* @returns A promise that resolves when disconnection is complete
|
|
206
|
+
* @throws {Error} If the client is not initialized
|
|
207
|
+
* @throws {Error} If the disconnect operation fails
|
|
208
|
+
* @throws {Error} If the request times out
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* await client.disconnect()
|
|
213
|
+
* console.log('User logged out')
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
disconnect(): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Opens the Swarm ID authentication page in a new window.
|
|
219
|
+
*
|
|
220
|
+
* This method creates the same authentication URL as used by the iframe
|
|
221
|
+
* proxy and opens it in a new browser window. The user can authenticate
|
|
222
|
+
* with their Swarm ID, and the resulting authentication will be available
|
|
223
|
+
* to the client when they return.
|
|
224
|
+
*
|
|
225
|
+
* **Browser Compatibility:**
|
|
226
|
+
* - Production (Chrome/Firefox): Works immediately
|
|
227
|
+
* - Localhost (Chrome/Firefox): Works after iframe button grants Storage Access
|
|
228
|
+
* - Safari (any): Download-only mode — auth works, uploads disabled (ITP storage partitioning). Private mode sessions are ephemeral (lost when the private window closes).
|
|
229
|
+
*
|
|
230
|
+
* For localhost development with Chrome/Firefox, click the iframe button first
|
|
231
|
+
* to grant Storage Access. For Safari details, see https://github.com/snaha/swarm-id/issues/167
|
|
232
|
+
*
|
|
233
|
+
* @param options - Configuration options for the connect flow
|
|
234
|
+
* @param options.agent - When true, shows the agent sign-up option on the connect page
|
|
235
|
+
* @throws {Error} If the client is not initialized or the popup fails to open
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* const client = new SwarmIdClient({ ... })
|
|
240
|
+
* await client.initialize()
|
|
241
|
+
*
|
|
242
|
+
* // Open authentication page
|
|
243
|
+
* await client.connect()
|
|
244
|
+
*
|
|
245
|
+
* // Open with agent sign-up option visible
|
|
246
|
+
* await client.connect({ agent: true })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
connect(options?: ConnectOptions): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Retrieves connection information including upload capability and identity details.
|
|
252
|
+
*
|
|
253
|
+
* Use this method to check if the user can upload data and to get
|
|
254
|
+
* information about the currently connected identity.
|
|
255
|
+
*
|
|
256
|
+
* @returns A promise resolving to the connection info object
|
|
257
|
+
* @returns return.canUpload - Whether the user can upload data (has valid postage stamp)
|
|
258
|
+
* @returns return.identity - The connected identity details (if authenticated)
|
|
259
|
+
* @returns return.identity.id - Unique identifier for the identity
|
|
260
|
+
* @returns return.identity.name - Display name of the identity
|
|
261
|
+
* @returns return.identity.address - Ethereum address associated with the identity
|
|
262
|
+
* @throws {Error} If the client is not initialized
|
|
263
|
+
* @throws {Error} If the request times out
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const info = await client.getConnectionInfo()
|
|
268
|
+
* if (info.canUpload) {
|
|
269
|
+
* console.log('Ready to upload as:', info.identity?.name)
|
|
270
|
+
* } else {
|
|
271
|
+
* console.log('No postage stamp available')
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
getConnectionInfo(): Promise<ConnectionInfo>;
|
|
276
|
+
/**
|
|
277
|
+
* Checks whether the Bee node is reachable.
|
|
278
|
+
*
|
|
279
|
+
* This method never throws an exception. If the client is not initialized,
|
|
280
|
+
* the request times out, or any other error occurs, it returns `false`.
|
|
281
|
+
*
|
|
282
|
+
* @returns A promise resolving to `true` if the Bee node is reachable, `false` otherwise
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const connected = await client.isBeeConnected()
|
|
287
|
+
* if (connected) {
|
|
288
|
+
* console.log('Bee node is online')
|
|
289
|
+
* } else {
|
|
290
|
+
* console.log('Bee node is offline')
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
isBeeConnected(): Promise<boolean>;
|
|
295
|
+
/**
|
|
296
|
+
* Gets information about the Bee node configuration.
|
|
297
|
+
*
|
|
298
|
+
* This method retrieves the current Bee node's operating mode and feature flags.
|
|
299
|
+
* Use this to determine if deferred uploads are required (dev mode) or if direct
|
|
300
|
+
* uploads are available (production modes).
|
|
301
|
+
*
|
|
302
|
+
* @returns A promise resolving to the node info object
|
|
303
|
+
* @returns return.beeMode - The Bee node operating mode ("dev", "light", "full", "ultra-light")
|
|
304
|
+
* @returns return.chequebookEnabled - Whether the chequebook is enabled
|
|
305
|
+
* @returns return.swapEnabled - Whether SWAP is enabled
|
|
306
|
+
* @throws {Error} If the client is not initialized
|
|
307
|
+
* @throws {Error} If the Bee node is not reachable
|
|
308
|
+
* @throws {Error} If the request times out
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const nodeInfo = await client.getNodeInfo()
|
|
313
|
+
* if (nodeInfo.beeMode === 'dev') {
|
|
314
|
+
* // Dev mode requires deferred uploads
|
|
315
|
+
* await client.uploadData(data, { deferred: true })
|
|
316
|
+
* } else {
|
|
317
|
+
* // Production modes can use direct uploads
|
|
318
|
+
* await client.uploadData(data, { deferred: false })
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
getNodeInfo(): Promise<{
|
|
323
|
+
beeMode: string;
|
|
324
|
+
chequebookEnabled: boolean;
|
|
325
|
+
swapEnabled: boolean;
|
|
326
|
+
}>;
|
|
327
|
+
/**
|
|
328
|
+
* Uploads raw binary data to the Swarm network.
|
|
329
|
+
*
|
|
330
|
+
* The data is uploaded using the authenticated user's postage stamp.
|
|
331
|
+
* Progress can be tracked via the optional callback.
|
|
332
|
+
*
|
|
333
|
+
* @param data - The binary data to upload as a Uint8Array
|
|
334
|
+
* @param options - Optional upload configuration
|
|
335
|
+
* @param options.pin - Whether to pin the data locally (defaults to false)
|
|
336
|
+
* @param options.encrypt - Whether to encrypt the data (defaults to false)
|
|
337
|
+
* @param options.tag - Tag ID for tracking upload progress
|
|
338
|
+
* @param options.deferred - Whether to use deferred upload (defaults to false)
|
|
339
|
+
* @param options.redundancyLevel - Redundancy level from 0-4 for data availability
|
|
340
|
+
* @param options.onProgress - Optional callback for tracking upload progress
|
|
341
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
342
|
+
* @returns A promise resolving to the upload result
|
|
343
|
+
* @returns return.reference - The Swarm reference (hash) of the uploaded data
|
|
344
|
+
* @returns return.tagUid - The tag UID if a tag was created
|
|
345
|
+
* @throws {Error} If the client is not initialized
|
|
346
|
+
* @throws {Error} If the user is not authenticated or cannot upload
|
|
347
|
+
* @throws {Error} If the request times out
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* const data = new TextEncoder().encode('Hello, Swarm!')
|
|
352
|
+
* const result = await client.uploadData(data, {
|
|
353
|
+
* encrypt: true,
|
|
354
|
+
* onProgress: (progress) => {
|
|
355
|
+
* console.log(`Progress: ${progress.processed}/${progress.total}`)
|
|
356
|
+
* },
|
|
357
|
+
* })
|
|
358
|
+
* console.log('Reference:', result.reference)
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
uploadData(data: Uint8Array, options?: UploadOptions, requestOptions?: RequestOptions): Promise<UploadResult>;
|
|
362
|
+
/**
|
|
363
|
+
* Downloads raw binary data from the Swarm network.
|
|
364
|
+
*
|
|
365
|
+
* @param reference - The Swarm reference (hash) of the data to download.
|
|
366
|
+
* Can be 64 hex chars (32 bytes) or 128 hex chars (64 bytes for encrypted)
|
|
367
|
+
* @param options - Optional download configuration
|
|
368
|
+
* @param options.redundancyStrategy - Strategy for handling redundancy (0-3)
|
|
369
|
+
* @param options.fallback - Whether to use fallback retrieval
|
|
370
|
+
* @param options.timeoutMs - Download timeout in milliseconds
|
|
371
|
+
* @param options.actPublisher - ACT publisher for encrypted content
|
|
372
|
+
* @param options.actHistoryAddress - ACT history address for encrypted content
|
|
373
|
+
* @param options.actTimestamp - ACT timestamp for encrypted content
|
|
374
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
375
|
+
* @returns A promise resolving to the downloaded data as a Uint8Array
|
|
376
|
+
* @throws {Error} If the client is not initialized
|
|
377
|
+
* @throws {Error} If the reference is not found
|
|
378
|
+
* @throws {Error} If the request times out
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* const data = await client.downloadData('a1b2c3...') // 64 char hex reference
|
|
383
|
+
* const text = new TextDecoder().decode(data)
|
|
384
|
+
* console.log('Downloaded:', text)
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
downloadData(reference: Reference, options?: DownloadOptions, requestOptions?: RequestOptions): Promise<Uint8Array>;
|
|
388
|
+
/**
|
|
389
|
+
* Uploads a file to the Swarm network.
|
|
390
|
+
*
|
|
391
|
+
* Accepts either a File object (from file input) or raw Uint8Array data.
|
|
392
|
+
* When using a File object, the filename is automatically extracted unless
|
|
393
|
+
* explicitly overridden.
|
|
394
|
+
*
|
|
395
|
+
* @param file - The file to upload (File object or Uint8Array)
|
|
396
|
+
* @param name - Optional filename (extracted from File object if not provided)
|
|
397
|
+
* @param options - Optional upload configuration
|
|
398
|
+
* @param options.pin - Whether to pin the file locally (defaults to false)
|
|
399
|
+
* @param options.encrypt - Whether to encrypt the file (defaults to false)
|
|
400
|
+
* @param options.tag - Tag ID for tracking upload progress
|
|
401
|
+
* @param options.deferred - Whether to use deferred upload (defaults to false)
|
|
402
|
+
* @param options.redundancyLevel - Redundancy level from 0-4 for data availability
|
|
403
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
404
|
+
* @returns A promise resolving to the upload result
|
|
405
|
+
* @returns return.reference - The Swarm reference (hash) of the uploaded file
|
|
406
|
+
* @returns return.tagUid - The tag UID if a tag was created
|
|
407
|
+
* @throws {Error} If the client is not initialized
|
|
408
|
+
* @throws {Error} If the user is not authenticated or cannot upload
|
|
409
|
+
* @throws {Error} If the request times out
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```typescript
|
|
413
|
+
* // From file input
|
|
414
|
+
* const fileInput = document.querySelector('input[type="file"]')
|
|
415
|
+
* const file = fileInput.files[0]
|
|
416
|
+
* const result = await client.uploadFile(file)
|
|
417
|
+
*
|
|
418
|
+
* // From Uint8Array with custom name
|
|
419
|
+
* const data = new Uint8Array([...])
|
|
420
|
+
* const result = await client.uploadFile(data, 'document.pdf')
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
uploadFile(file: File | Uint8Array, name?: string, options?: UploadOptions, requestOptions?: RequestOptions): Promise<UploadResult>;
|
|
424
|
+
/**
|
|
425
|
+
* Downloads a file from the Swarm network.
|
|
426
|
+
*
|
|
427
|
+
* Returns both the file data and its original filename (if available).
|
|
428
|
+
* For manifest references, an optional path can be specified to retrieve
|
|
429
|
+
* a specific file from the manifest.
|
|
430
|
+
*
|
|
431
|
+
* @param reference - The Swarm reference (hash) of the file to download
|
|
432
|
+
* @param path - Optional path within a manifest to retrieve a specific file
|
|
433
|
+
* @param options - Optional download configuration
|
|
434
|
+
* @param options.redundancyStrategy - Strategy for handling redundancy (0-3)
|
|
435
|
+
* @param options.fallback - Whether to use fallback retrieval
|
|
436
|
+
* @param options.timeoutMs - Download timeout in milliseconds
|
|
437
|
+
* @param options.actPublisher - ACT publisher for encrypted content
|
|
438
|
+
* @param options.actHistoryAddress - ACT history address for encrypted content
|
|
439
|
+
* @param options.actTimestamp - ACT timestamp for encrypted content
|
|
440
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
441
|
+
* @returns A promise resolving to the file data object
|
|
442
|
+
* @returns return.name - The filename
|
|
443
|
+
* @returns return.data - The file contents as a Uint8Array
|
|
444
|
+
* @throws {Error} If the client is not initialized
|
|
445
|
+
* @throws {Error} If the reference is not found
|
|
446
|
+
* @throws {Error} If the request times out
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* const file = await client.downloadFile('a1b2c3...')
|
|
451
|
+
* console.log('Filename:', file.name)
|
|
452
|
+
*
|
|
453
|
+
* // Create download link
|
|
454
|
+
* const blob = new Blob([file.data])
|
|
455
|
+
* const url = URL.createObjectURL(blob)
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
downloadFile(reference: Reference, path?: string, options?: DownloadOptions, requestOptions?: RequestOptions): Promise<FileData>;
|
|
459
|
+
/**
|
|
460
|
+
* Uploads a single chunk to the Swarm network.
|
|
461
|
+
*
|
|
462
|
+
* Chunks are the fundamental unit of storage in Swarm (4KB each).
|
|
463
|
+
* This method is useful for low-level operations or when implementing
|
|
464
|
+
* custom chunking strategies.
|
|
465
|
+
*
|
|
466
|
+
* @param data - The chunk data to upload (should be exactly 4KB for optimal storage)
|
|
467
|
+
* @param options - Optional upload configuration
|
|
468
|
+
* @param options.pin - Whether to pin the chunk locally (defaults to false)
|
|
469
|
+
* @param options.encrypt - Whether to encrypt the chunk (defaults to false)
|
|
470
|
+
* @param options.tag - Tag ID for tracking upload progress
|
|
471
|
+
* @param options.deferred - Whether to use deferred upload (defaults to false)
|
|
472
|
+
* @param options.redundancyLevel - Redundancy level from 0-4 for data availability
|
|
473
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
474
|
+
* @returns A promise resolving to the upload result
|
|
475
|
+
* @returns return.reference - The Swarm reference (hash) of the uploaded chunk
|
|
476
|
+
* @throws {Error} If the client is not initialized
|
|
477
|
+
* @throws {Error} If the user is not authenticated or cannot upload
|
|
478
|
+
* @throws {Error} If the request times out
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* const chunk = new Uint8Array(4096) // 4KB chunk
|
|
483
|
+
* chunk.fill(0x42) // Fill with data
|
|
484
|
+
* const result = await client.uploadChunk(chunk)
|
|
485
|
+
* console.log('Chunk reference:', result.reference)
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
uploadChunk(data: Uint8Array, options?: UploadOptions, requestOptions?: RequestOptions): Promise<UploadResult>;
|
|
489
|
+
/**
|
|
490
|
+
* Downloads a single chunk from the Swarm network.
|
|
491
|
+
*
|
|
492
|
+
* Retrieves a chunk by its reference hash. This method is useful for
|
|
493
|
+
* low-level operations or when implementing custom retrieval strategies.
|
|
494
|
+
*
|
|
495
|
+
* @param reference - The Swarm reference (hash) of the chunk to download
|
|
496
|
+
* @param options - Optional download configuration
|
|
497
|
+
* @param options.redundancyStrategy - Strategy for handling redundancy (0-3)
|
|
498
|
+
* @param options.fallback - Whether to use fallback retrieval
|
|
499
|
+
* @param options.timeoutMs - Download timeout in milliseconds
|
|
500
|
+
* @param options.actPublisher - ACT publisher for encrypted content
|
|
501
|
+
* @param options.actHistoryAddress - ACT history address for encrypted content
|
|
502
|
+
* @param options.actTimestamp - ACT timestamp for encrypted content
|
|
503
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
504
|
+
* @returns A promise resolving to the chunk data as a Uint8Array
|
|
505
|
+
* @throws {Error} If the client is not initialized
|
|
506
|
+
* @throws {Error} If the reference is not found
|
|
507
|
+
* @throws {Error} If the request times out
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const chunk = await client.downloadChunk('a1b2c3...')
|
|
512
|
+
* console.log('Chunk size:', chunk.length)
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
downloadChunk(reference: Reference, options?: DownloadOptions, requestOptions?: RequestOptions): Promise<Uint8Array>;
|
|
516
|
+
/**
|
|
517
|
+
* Returns an object for reading single owner chunks (SOC).
|
|
518
|
+
*
|
|
519
|
+
* @param ownerAddress - Ethereum address of the SOC owner
|
|
520
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
521
|
+
* @returns SOCReader with `download` (encrypted) and `rawDownload` (unencrypted)
|
|
522
|
+
* @throws {Error} If the client is not initialized
|
|
523
|
+
* @throws {Error} If the request times out
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* const reader = client.makeSOCReader(owner)
|
|
528
|
+
* const soc = await reader.download(identifier, encryptionKey)
|
|
529
|
+
* console.log('Payload:', new TextDecoder().decode(soc.payload))
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
makeSOCReader(ownerAddress: EthAddress | Uint8Array | string, requestOptions?: RequestOptions): SOCReader;
|
|
533
|
+
/**
|
|
534
|
+
* Returns an object for reading and writing single owner chunks (SOC).
|
|
535
|
+
*
|
|
536
|
+
* Uploads are encrypted by default. Use `rawUpload` for unencrypted SOCs.
|
|
537
|
+
*
|
|
538
|
+
* @param signer - Optional SOC signer private key. If omitted, the proxy uses the app signer.
|
|
539
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
540
|
+
* @returns SOCWriter with `upload`, `rawUpload`, `download`, and `rawDownload`
|
|
541
|
+
* @throws {Error} If the client is not initialized
|
|
542
|
+
* @throws {Error} If the request times out
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```typescript
|
|
546
|
+
* const writer = client.makeSOCWriter()
|
|
547
|
+
* const upload = await writer.upload(identifier, payload)
|
|
548
|
+
* const soc = await writer.download(identifier, upload.encryptionKey)
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
makeSOCWriter(signer?: PrivateKey | Uint8Array | string, requestOptions?: RequestOptions): SOCWriter;
|
|
552
|
+
/**
|
|
553
|
+
* Returns an object for reading epoch-based feeds.
|
|
554
|
+
*
|
|
555
|
+
* @param options - Feed reader options
|
|
556
|
+
* @param options.topic - Feed topic (32 bytes)
|
|
557
|
+
* @param options.owner - Optional feed owner address
|
|
558
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
559
|
+
* @returns FeedReader with `getOwner`, `downloadReference`, and `downloadPayload`
|
|
560
|
+
* @throws {Error} If the client is not initialized
|
|
561
|
+
* @throws {Error} If the request times out
|
|
562
|
+
*/
|
|
563
|
+
makeEpochFeedReader(options: FeedReaderOptions, requestOptions?: RequestOptions): FeedReader;
|
|
564
|
+
/**
|
|
565
|
+
* Returns an object for reading and writing epoch-based feeds.
|
|
566
|
+
*
|
|
567
|
+
* @param options - Feed writer options
|
|
568
|
+
* @param options.topic - Feed topic (32 bytes)
|
|
569
|
+
* @param options.signer - Optional feed signer private key. If omitted, the proxy uses the app signer.
|
|
570
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
571
|
+
* @returns FeedWriter with `getOwner`, `downloadReference`, `downloadPayload`, `uploadPayload`, and `uploadReference`
|
|
572
|
+
* @throws {Error} If the client is not initialized
|
|
573
|
+
* @throws {Error} If the request times out
|
|
574
|
+
*/
|
|
575
|
+
makeEpochFeedWriter(options: FeedWriterOptions, requestOptions?: RequestOptions): FeedWriter;
|
|
576
|
+
/**
|
|
577
|
+
* Returns a sequential feed reader (chunk API only).
|
|
578
|
+
*
|
|
579
|
+
* @param options - Sequential feed reader options
|
|
580
|
+
* @param options.topic - Feed topic (32 bytes)
|
|
581
|
+
* @param options.owner - Optional feed owner address
|
|
582
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
583
|
+
* @returns SequentialFeedReader with payload/reference download helpers
|
|
584
|
+
*/
|
|
585
|
+
makeSequentialFeedReader(options: SequentialFeedReaderOptions, requestOptions?: RequestOptions): SequentialFeedReader;
|
|
586
|
+
/**
|
|
587
|
+
* Returns a sequential feed writer (chunk API only).
|
|
588
|
+
*
|
|
589
|
+
* @param options - Sequential feed writer options
|
|
590
|
+
* @param options.topic - Feed topic (32 bytes)
|
|
591
|
+
* @param options.signer - Optional signer private key. If omitted, proxy uses app signer.
|
|
592
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
593
|
+
* @returns SequentialFeedWriter with payload/reference upload helpers
|
|
594
|
+
*/
|
|
595
|
+
makeSequentialFeedWriter(options: SequentialFeedWriterOptions, requestOptions?: RequestOptions): SequentialFeedWriter;
|
|
596
|
+
/**
|
|
597
|
+
* Creates a feed manifest for accessing feed content via URL.
|
|
598
|
+
*
|
|
599
|
+
* A feed manifest enables accessing the latest feed content via a URL path
|
|
600
|
+
* (e.g., `/bzz/{manifest-reference}/`). The manifest stores metadata about
|
|
601
|
+
* the feed including owner, topic, and type.
|
|
602
|
+
*
|
|
603
|
+
* @param topic - Feed topic (32-byte hex string)
|
|
604
|
+
* @param options - Optional configuration
|
|
605
|
+
* @param options.owner - Feed owner address; if omitted, uses app signer
|
|
606
|
+
* @param options.uploadOptions - Upload configuration (pin, deferred, etc.)
|
|
607
|
+
* @param requestOptions - Request configuration (timeout, headers)
|
|
608
|
+
* @returns Promise resolving to the manifest reference
|
|
609
|
+
* @throws {Error} If the client is not initialized
|
|
610
|
+
* @throws {Error} If no owner is provided and no app signer is available
|
|
611
|
+
* @throws {Error} If the request times out
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* // Create manifest for a feed (uses app signer as owner)
|
|
616
|
+
* const manifestRef = await client.createFeedManifest(topic)
|
|
617
|
+
* console.log('Feed accessible at /bzz/' + manifestRef)
|
|
618
|
+
*
|
|
619
|
+
* // Create manifest with explicit owner
|
|
620
|
+
* const manifestRef = await client.createFeedManifest(topic, {
|
|
621
|
+
* owner: '0x1234...',
|
|
622
|
+
* uploadOptions: { pin: true }
|
|
623
|
+
* })
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
createFeedManifest(topic: string, options?: {
|
|
627
|
+
owner?: string;
|
|
628
|
+
/** Feed type: "Sequence" for sequential feeds, "Epoch" for epoch feeds. Default: "Sequence" */
|
|
629
|
+
feedType?: "Sequence" | "Epoch";
|
|
630
|
+
uploadOptions?: UploadOptions;
|
|
631
|
+
}, requestOptions?: RequestOptions): Promise<string>;
|
|
632
|
+
/**
|
|
633
|
+
* Mines a private key whose SOC address is proximate to a target overlay.
|
|
634
|
+
*
|
|
635
|
+
* This is a synchronous, pure computation that does not require authentication.
|
|
636
|
+
* The mined signer can be used with {@link gsocSend} to send GSOC messages
|
|
637
|
+
* that route to the target overlay node.
|
|
638
|
+
*
|
|
639
|
+
* @param targetOverlay - The target overlay address to mine proximity for
|
|
640
|
+
* @param identifier - The GSOC identifier
|
|
641
|
+
* @param proximity - Optional proximity depth (defaults to 12 in bee-js)
|
|
642
|
+
* @returns A promise resolving to the mined signer as a hex string (private key)
|
|
643
|
+
* @throws {Error} If the client is not initialized
|
|
644
|
+
* @throws {Error} If no valid signer can be mined
|
|
645
|
+
* @throws {Error} If the request times out
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```typescript
|
|
649
|
+
* const signer = await client.gsocMine(targetOverlay, identifier)
|
|
650
|
+
* // Use signer with gsocSend
|
|
651
|
+
* await client.gsocSend(signer, identifier, data)
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
gsocMine(targetOverlay: string, identifier: string, proximity?: number): Promise<string>;
|
|
655
|
+
/**
|
|
656
|
+
* Sends a GSOC (Global Single Owner Chunk) message using a mined signer.
|
|
657
|
+
*
|
|
658
|
+
* The signer should be obtained from {@link gsocMine}. The message is sent
|
|
659
|
+
* using the proxy's stored postage batch ID.
|
|
660
|
+
*
|
|
661
|
+
* @param signer - The mined signer as a hex string (from gsocMine)
|
|
662
|
+
* @param identifier - The GSOC identifier
|
|
663
|
+
* @param data - The message data to send
|
|
664
|
+
* @param options - Optional upload configuration
|
|
665
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
666
|
+
* @returns A promise resolving to the upload result with reference and optional tagUid
|
|
667
|
+
* @throws {Error} If the client is not initialized
|
|
668
|
+
* @throws {Error} If the user is not authenticated
|
|
669
|
+
* @throws {Error} If no postage batch ID is available
|
|
670
|
+
* @throws {Error} If the request times out
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```typescript
|
|
674
|
+
* const signer = await client.gsocMine(targetOverlay, identifier)
|
|
675
|
+
* const result = await client.gsocSend(signer, identifier, new TextEncoder().encode('Hello!'))
|
|
676
|
+
* console.log('GSOC reference:', result.reference)
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
gsocSend(signer: string, identifier: string, data: Uint8Array, options?: UploadOptions, requestOptions?: RequestOptions): Promise<UploadResult>;
|
|
680
|
+
/**
|
|
681
|
+
* Uploads data with ACT (Access Control Tries) protection.
|
|
682
|
+
*
|
|
683
|
+
* This method encrypts the data and creates an ACT that controls who can decrypt it.
|
|
684
|
+
* Only the specified grantees (and the publisher) can decrypt and access the data.
|
|
685
|
+
*
|
|
686
|
+
* @param data - The binary data to upload as a Uint8Array
|
|
687
|
+
* @param grantees - Array of grantee public keys as compressed hex strings (33 bytes = 66 hex chars)
|
|
688
|
+
* @param options - Optional upload configuration
|
|
689
|
+
* @param options.pin - Whether to pin the data locally (defaults to false)
|
|
690
|
+
* @param options.tag - Tag ID for tracking upload progress
|
|
691
|
+
* @param options.deferred - Whether to use deferred upload (defaults to false)
|
|
692
|
+
* @param options.redundancyLevel - Redundancy level from 0-4 for data availability
|
|
693
|
+
* @param options.onProgress - Optional callback for tracking upload progress
|
|
694
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
695
|
+
* @returns A promise resolving to the ACT upload result
|
|
696
|
+
* @returns return.encryptedReference - The encrypted reference that must be stored with the ACT
|
|
697
|
+
* @returns return.actReference - The Swarm reference (hash) of the ACT manifest
|
|
698
|
+
* @returns return.historyReference - The Swarm reference of the history manifest (use for future operations)
|
|
699
|
+
* @returns return.granteeListReference - The Swarm reference of the encrypted grantee list
|
|
700
|
+
* @returns return.publisherPubKey - The publisher's compressed public key (share with grantees)
|
|
701
|
+
* @returns return.tagUid - The tag UID if a tag was created
|
|
702
|
+
* @throws {Error} If the client is not initialized
|
|
703
|
+
* @throws {Error} If the user is not authenticated or cannot upload
|
|
704
|
+
* @throws {Error} If the request times out
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```typescript
|
|
708
|
+
* const data = new TextEncoder().encode('Secret message')
|
|
709
|
+
* const grantees = ['03a1b2c3...'] // Compressed public keys of allowed readers
|
|
710
|
+
* const result = await client.actUploadData(data, grantees, {
|
|
711
|
+
* onProgress: (progress) => {
|
|
712
|
+
* console.log(`Progress: ${progress.processed}/${progress.total}`)
|
|
713
|
+
* },
|
|
714
|
+
* })
|
|
715
|
+
* console.log('History Reference:', result.historyReference)
|
|
716
|
+
* console.log('Encrypted Reference:', result.encryptedReference)
|
|
717
|
+
* console.log('Publisher Public Key:', result.publisherPubKey)
|
|
718
|
+
* ```
|
|
719
|
+
*/
|
|
720
|
+
actUploadData(data: Uint8Array, grantees: string[], options?: ActUploadOptions, requestOptions?: RequestOptions): Promise<{
|
|
721
|
+
encryptedReference: string;
|
|
722
|
+
historyReference: string;
|
|
723
|
+
granteeListReference: string;
|
|
724
|
+
publisherPubKey: string;
|
|
725
|
+
actReference: string;
|
|
726
|
+
tagUid?: number;
|
|
727
|
+
}>;
|
|
728
|
+
/**
|
|
729
|
+
* Downloads ACT-protected data from the Swarm network.
|
|
730
|
+
*
|
|
731
|
+
* This method decrypts the ACT to recover the content reference,
|
|
732
|
+
* then downloads and returns the decrypted data. Only authorized
|
|
733
|
+
* grantees (including the publisher) can successfully decrypt.
|
|
734
|
+
*
|
|
735
|
+
* @param encryptedReference - The encrypted reference from actUploadData
|
|
736
|
+
* @param historyReference - The history reference from actUploadData
|
|
737
|
+
* @param publisherPubKey - The publisher's compressed public key from actUploadData
|
|
738
|
+
* @param timestamp - Optional timestamp to look up a specific ACT version
|
|
739
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
740
|
+
* @returns A promise resolving to the decrypted data as a Uint8Array
|
|
741
|
+
* @throws {Error} If the client is not initialized
|
|
742
|
+
* @throws {Error} If the user is not authorized to decrypt the ACT
|
|
743
|
+
* @throws {Error} If the references are not found
|
|
744
|
+
* @throws {Error} If the request times out
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```typescript
|
|
748
|
+
* // Using the references from actUploadData
|
|
749
|
+
* const data = await client.actDownloadData(
|
|
750
|
+
* encryptedReference,
|
|
751
|
+
* historyReference,
|
|
752
|
+
* publisherPubKey
|
|
753
|
+
* )
|
|
754
|
+
* const text = new TextDecoder().decode(data)
|
|
755
|
+
* console.log('Decrypted:', text)
|
|
756
|
+
* ```
|
|
757
|
+
*/
|
|
758
|
+
actDownloadData(encryptedReference: string, historyReference: string, publisherPubKey: string, timestamp?: number, requestOptions?: RequestOptions): Promise<Uint8Array>;
|
|
759
|
+
/**
|
|
760
|
+
* Adds new grantees to an existing ACT.
|
|
761
|
+
*
|
|
762
|
+
* This method adds new public keys to the ACT's access list.
|
|
763
|
+
* Only the publisher (original uploader) can add grantees.
|
|
764
|
+
* Returns new references since Swarm content is immutable.
|
|
765
|
+
*
|
|
766
|
+
* @param historyReference - The current history reference
|
|
767
|
+
* @param grantees - Array of new grantee public keys as compressed hex strings
|
|
768
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
769
|
+
* @returns A promise resolving to the new references
|
|
770
|
+
* @returns return.historyReference - The new history reference after adding grantees
|
|
771
|
+
* @returns return.granteeListReference - The new grantee list reference
|
|
772
|
+
* @returns return.actReference - The new ACT reference
|
|
773
|
+
* @throws {Error} If the client is not initialized
|
|
774
|
+
* @throws {Error} If the user is not the publisher
|
|
775
|
+
* @throws {Error} If the request times out
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```typescript
|
|
779
|
+
* const newGrantees = ['03d4e5f6...'] // New public keys to grant access
|
|
780
|
+
* const result = await client.actAddGrantees(historyReference, newGrantees)
|
|
781
|
+
* console.log('New History Reference:', result.historyReference)
|
|
782
|
+
* // The encrypted reference remains the same
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
actAddGrantees(historyReference: string, grantees: string[], requestOptions?: RequestOptions): Promise<{
|
|
786
|
+
historyReference: string;
|
|
787
|
+
granteeListReference: string;
|
|
788
|
+
actReference: string;
|
|
789
|
+
}>;
|
|
790
|
+
/**
|
|
791
|
+
* Revokes grantees from an existing ACT.
|
|
792
|
+
*
|
|
793
|
+
* This method removes public keys from the ACT's access list and performs
|
|
794
|
+
* key rotation to ensure revoked grantees cannot decrypt new versions.
|
|
795
|
+
* Returns new references including a new encrypted reference.
|
|
796
|
+
*
|
|
797
|
+
* IMPORTANT: The original encrypted reference can still be decrypted by
|
|
798
|
+
* revoked grantees if they have cached it. Key rotation only protects
|
|
799
|
+
* access through the new references.
|
|
800
|
+
*
|
|
801
|
+
* @param historyReference - The current history reference
|
|
802
|
+
* @param encryptedReference - The current encrypted reference (needed for key rotation)
|
|
803
|
+
* @param revokeGrantees - Array of grantee public keys to revoke as compressed hex strings
|
|
804
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
805
|
+
* @returns A promise resolving to the new references after revocation
|
|
806
|
+
* @returns return.encryptedReference - The new encrypted reference (key rotated)
|
|
807
|
+
* @returns return.historyReference - The new history reference after revocation
|
|
808
|
+
* @returns return.granteeListReference - The new grantee list reference
|
|
809
|
+
* @returns return.actReference - The new ACT reference after revocation
|
|
810
|
+
* @throws {Error} If the client is not initialized
|
|
811
|
+
* @throws {Error} If the user is not the publisher
|
|
812
|
+
* @throws {Error} If the request times out
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```typescript
|
|
816
|
+
* const revokeKeys = ['03a1b2c3...'] // Public keys to revoke
|
|
817
|
+
* const result = await client.actRevokeGrantees(historyReference, encryptedReference, revokeKeys)
|
|
818
|
+
* console.log('New History Reference:', result.historyReference)
|
|
819
|
+
* console.log('New Encrypted Reference:', result.encryptedReference)
|
|
820
|
+
* // All references are new due to key rotation
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
823
|
+
actRevokeGrantees(historyReference: string, encryptedReference: string, revokeGrantees: string[], requestOptions?: RequestOptions): Promise<{
|
|
824
|
+
encryptedReference: string;
|
|
825
|
+
historyReference: string;
|
|
826
|
+
granteeListReference: string;
|
|
827
|
+
actReference: string;
|
|
828
|
+
}>;
|
|
829
|
+
/**
|
|
830
|
+
* Retrieves the list of grantees from an ACT.
|
|
831
|
+
*
|
|
832
|
+
* Only the publisher (original uploader) can view the grantee list,
|
|
833
|
+
* as it is encrypted with the publisher's key.
|
|
834
|
+
*
|
|
835
|
+
* @param historyReference - The history reference
|
|
836
|
+
* @param requestOptions - Optional request configuration (timeout, headers, endlesslyRetry)
|
|
837
|
+
* @returns A promise resolving to an array of grantee public keys as compressed hex strings
|
|
838
|
+
* @throws {Error} If the client is not initialized
|
|
839
|
+
* @throws {Error} If the user is not the publisher
|
|
840
|
+
* @throws {Error} If the request times out
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```typescript
|
|
844
|
+
* const grantees = await client.actGetGrantees(historyReference)
|
|
845
|
+
* console.log('Current grantees:', grantees.length)
|
|
846
|
+
* grantees.forEach(pubKey => console.log(' -', pubKey))
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
actGetGrantees(historyReference: string, requestOptions?: RequestOptions): Promise<string[]>;
|
|
850
|
+
/**
|
|
851
|
+
* Destroys the client and releases all resources.
|
|
852
|
+
*
|
|
853
|
+
* This method should be called when the client is no longer needed.
|
|
854
|
+
* It performs the following cleanup:
|
|
855
|
+
* - Cancels all pending requests with an error
|
|
856
|
+
* - Removes the message event listener
|
|
857
|
+
* - Removes the iframe from the DOM
|
|
858
|
+
* - Resets the client to an uninitialized state
|
|
859
|
+
*
|
|
860
|
+
* After calling destroy(), the client instance cannot be reused.
|
|
861
|
+
* Create a new instance if you need to reconnect.
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* ```typescript
|
|
865
|
+
* // Clean up when component unmounts
|
|
866
|
+
* useEffect(() => {
|
|
867
|
+
* const client = new SwarmIdClient({ ... })
|
|
868
|
+
* client.initialize()
|
|
869
|
+
*
|
|
870
|
+
* return () => {
|
|
871
|
+
* client.destroy()
|
|
872
|
+
* }
|
|
873
|
+
* }, [])
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
destroy(): void;
|
|
877
|
+
}
|
|
878
|
+
//# sourceMappingURL=swarm-id-client.d.ts.map
|