@flashbacktech/flashbackclient 0.0.13

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Flashback, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @flashbacktech/flashonstellar
2
+
3
+ TypeScript/JavaScript client for:
4
+
5
+ - interacting with the FlashOnStellar storage system on the Stellar blockchain.
6
+ - offering your available storage capacity as a provider on the FlashOnStellar system.
7
+ - connecting your applications as a consumer of storage on the FlashOnStellar system.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @flashbacktech/flashonstellar
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Client Library
18
+
19
+ ```typescript
20
+ import { FlashOnStellarClient, StellarNetwork } from '@flashbacktech/flashonstellar/client';
21
+ ```
22
+
23
+ See the [Stellar README](STELLAR.md) for usage instructions.
24
+
25
+ ### Consumer API reference
26
+
27
+ See the [Consumer README](./src/consumer/README.md) for usage instructions.
28
+
29
+ ### Provider API reference
30
+
31
+ See the [Provider README](./src/provider/README.md) for usage instructions.
32
+
33
+ ## License
34
+
35
+ ISC © [2025] FlashBack Inc.
@@ -0,0 +1,282 @@
1
+ import { StellarNetwork } from './transaction.js';
2
+ /**
3
+ * Configuration interface for the FlashOnStellar client
4
+ * @interface FlashOnStellarClientConfig
5
+ */
6
+ interface FlashOnStellarClientConfig {
7
+ /** Stellar contract address for the FlashOnStellar system */
8
+ contractAddress: string;
9
+ /**
10
+ * Optional callback function to sign non-read Stellar transactions
11
+ * @param xdrToSign - The XDR-encoded transaction to sign
12
+ * @returns Promise resolving to the signed XDR string
13
+ */
14
+ signTransaction?: (xdrToSign: string) => Promise<string>;
15
+ /** Network configuration for Stellar (testnet/public) */
16
+ network: StellarNetwork;
17
+ }
18
+ type ClientContext = FlashOnStellarClientConfig;
19
+ /**
20
+ * Main client class for interacting with the FlashOnStellar system
21
+ * This client provides methods for managing providers, consumers, units, and reservations
22
+ * on the Stellar blockchain.
23
+ */
24
+ declare class FlashOnStellarClient {
25
+ private readonly signTransaction?;
26
+ private readonly contractAddress;
27
+ private readonly network;
28
+ protected getContext(): ClientContext;
29
+ /**
30
+ * Creates a new instance of the FlashOnStellarClient
31
+ * @param config - Configuration options for the client
32
+ */
33
+ constructor(config: FlashOnStellarClientConfig);
34
+ /**
35
+ * Derives a public key from a private key
36
+ * @param privateKey - Stellar private key
37
+ * @returns The corresponding public key
38
+ */
39
+ getPublicKey: (privateKey: string) => string;
40
+ /**
41
+ * Signs a transaction using the provided private key using Stellar SDK
42
+ * The alternative is providing your own signing function (for example, using Wallet Kit).
43
+ * @param xdrToSign - XDR-encoded transaction to sign
44
+ * @param privateKey - Stellar private key to sign with
45
+ * @returns Promise resolving to the signed XDR string
46
+ */
47
+ signTransactionWithKey: (xdrToSign: string, privateKey: string) => Promise<string>;
48
+ /**
49
+ * Retrieves stats for the current user
50
+ * @param wallet_address - Address of the wallet requesting the information
51
+ * @returns Promise resolving to DashboardStats object
52
+ */
53
+ get_stats: (wallet_address: string) => Promise<import("./models.js").ContractStats | null>;
54
+ /**
55
+ * Retrieves provider information
56
+ * @param wallet_address - Address of the wallet requesting the information
57
+ * @param provider_address - Address of the provider to retrieve
58
+ * @param load_units - Optional flag to include provider's units in the response
59
+ * @returns Promise resolving to StorageProvider object
60
+ */
61
+ get_provider: (wallet_address: string, provider_address: string, load_units?: boolean) => Promise<import("./models.js").StorageProvider | null>;
62
+ /**
63
+ * Retrieves all units associated with a provider
64
+ * @param wallet_address - Address of the wallet requesting the information
65
+ * @param provider_address - Address of the provider
66
+ * @returns Promise resolving to an array of StorageUnit objects
67
+ */
68
+ get_provider_units: (wallet_address: string, provider_address: string) => Promise<Map<number, import("./models.js").StorageUnit>>;
69
+ /**
70
+ * Retrieves a paginated list of providers
71
+ * @param wallet_address - Address of the wallet requesting the information
72
+ * @param skip - Number of items to skip for pagination
73
+ * @param take - Number of items to take per page
74
+ * @returns Promise resolving to an array of StorageProvider objects
75
+ */
76
+ get_providers: (wallet_address: string, skip?: number, take?: number) => Promise<Map<string, import("./models.js").StorageProvider>>;
77
+ /**
78
+ * Gets the total count of providers in the system
79
+ * @param wallet_address - Address of the wallet requesting the information
80
+ * @returns Promise resolving to the total number of providers
81
+ */
82
+ get_provider_count: (wallet_address: string) => Promise<number>;
83
+ /**
84
+ * Registers a new provider in the system
85
+ * @param wallet_address - Address of the wallet registering the provider
86
+ * @param provider_address - Address for the new provider
87
+ * @param provider_description - Description of the provider
88
+ * @returns Promise resolving to the registration transaction result
89
+ * @requires Signature - This method requires a transaction signature
90
+ * @throws Will throw if provider address is already registered
91
+ */
92
+ register_provider(wallet_address: string, provider_address: string, provider_description: string): Promise<void>;
93
+ /**
94
+ * Deletes a provider from the system
95
+ * @param wallet_address - Address of the wallet making the request
96
+ * @param provider_address - Address of the provider to delete
97
+ * @returns Promise resolving to the deletion transaction result
98
+ * @requires Signature - This method requires a transaction signature
99
+ */
100
+ delete_provider(wallet_address: string, provider_address: string): Promise<void>;
101
+ /**
102
+ * Updates provider information
103
+ * @param wallet_address - Address of the wallet making the request
104
+ * @param provider_address - Address of the provider to update
105
+ * @param provider_description - New description for the provider
106
+ * @returns Promise resolving to the update transaction result
107
+ * @requires Signature - This method requires a transaction signature
108
+ */
109
+ update_provider(wallet_address: string, provider_address: string, provider_description: string): Promise<void>;
110
+ /**
111
+ * Retrieves consumer information
112
+ * @param wallet_address - Address of the wallet requesting the information
113
+ * @param consumer_address - Address of the consumer to retrieve
114
+ * @param load_reservations - Optional flag to include consumer's reservations
115
+ * @returns Promise resolving to StorageConsumer object
116
+ */
117
+ get_consumer: (wallet_address: string, consumer_address: string, load_reservations?: boolean) => Promise<import("./models.js").StorageConsumer | null>;
118
+ /**
119
+ * Retrieves a paginated list of consumers
120
+ * @param wallet_address - Address of the wallet requesting the information
121
+ * @param skip - Number of items to skip for pagination
122
+ * @param take - Number of items to take per page
123
+ * @returns Promise resolving to an array of StorageConsumer objects
124
+ */
125
+ get_consumers: (wallet_address: string, skip?: number, take?: number) => Promise<Map<string, import("./models.js").StorageConsumer>>;
126
+ /**
127
+ * Gets the total count of consumers in the system
128
+ * @param wallet_address - Address of the wallet requesting the information
129
+ * @returns Promise resolving to the total number of consumers
130
+ */
131
+ get_consumer_count: (wallet_address: string) => Promise<number>;
132
+ /**
133
+ * Retrieves all reservations associated with a consumer
134
+ * @param wallet_address - Address of the wallet requesting the information
135
+ * @param consumer_address - Address of the consumer
136
+ * @returns Promise resolving to an array of StorageReservation objects
137
+ */
138
+ get_consumer_reservations: (wallet_address: string, consumer_address: string) => Promise<Map<number, import("./models.js").StorageReservation>>;
139
+ /**
140
+ * Registers a new consumer in the system
141
+ * @param wallet_address - Address of the wallet registering the consumer
142
+ * @param consumer_address - Address for the new consumer
143
+ * @param consumer_description - Description of the consumer
144
+ * @returns Promise resolving to the registration transaction result
145
+ * @requires Signature - This method requires a transaction signature
146
+ */
147
+ register_consumer(wallet_address: string, consumer_address: string, consumer_description: string): Promise<void>;
148
+ delete_consumer(wallet_address: string, consumer_address: string): Promise<void>;
149
+ update_consumer(wallet_address: string, consumer_address: string, consumer_description: string): Promise<void>;
150
+ /**
151
+ * Registers a new storage unit in the system
152
+ * @param wallet_address - Address of the wallet registering the unit
153
+ * @param provider_address - Address of the provider owning the unit
154
+ * @param capacity - Capacity of the storage unit in gigabytes
155
+ * @param endpoint - Endpoint for the storage unit
156
+ * @returns Promise resolving to the registration transaction result
157
+ * @requires Signature - This method requires a transaction signature
158
+ */
159
+ register_unit(wallet_address: string, provider_address: string, capacity: number, endpoint: string): Promise<[unitId: number, unit: import("./models.js").StorageUnit] | null>;
160
+ /**
161
+ * Retrieves storage unit information
162
+ * @param wallet_address - Address of the wallet requesting the information
163
+ * @param unit_id - Identifier of the storage unit
164
+ * @param load_reservations - Optional flag to include unit's reservations
165
+ * @returns Promise resolving to StorageUnit object
166
+ */
167
+ get_unit: (wallet_address: string, unit_id: number, load_reservations?: boolean) => Promise<import("./models.js").StorageUnit | null>;
168
+ /**
169
+ * Retrieves all reservations for a specific storage unit
170
+ * @param wallet_address - Address of the wallet requesting the information
171
+ * @param unit_id - Identifier of the storage unit
172
+ * @returns Promise resolving to an array of StorageReservation objects
173
+ */
174
+ get_unit_reservations: (wallet_address: string, unit_id: number) => Promise<Map<number, import("./models.js").StorageReservation>>;
175
+ /**
176
+ * Deletes a storage unit from the system
177
+ * @param wallet_address - Address of the wallet making the request
178
+ * @param provider_address - Address of the provider owning the unit
179
+ * @param unit_id - Identifier of the storage unit
180
+ * @returns Promise resolving to the deletion transaction result
181
+ * @requires Signature - This method requires a transaction signature
182
+ * @throws Will throw if unit has active reservations
183
+ */
184
+ delete_unit(wallet_address: string, provider_address: string, unit_id: number): Promise<import("./models.js").DeletionStatus | null>;
185
+ /**
186
+ * Places a storage unit into maintenance mode
187
+ * @param wallet_address - Address of the wallet making the request
188
+ * @param provider_address - Address of the provider owning the unit
189
+ * @param unit_id - Identifier of the storage unit
190
+ * @param maintenance_start - Start date of maintenance period
191
+ * @param maintenance_end - End date of maintenance period
192
+ * @returns Promise resolving to the maintenance transaction result
193
+ * @requires Signature - This method requires a transaction signature
194
+ * @throws Will throw if unit has active reservations that conflict with the maintenance window
195
+ */
196
+ enter_maintenance(wallet_address: string, provider_address: string, unit_id: number, maintenance_start: Date, maintenance_end: Date): Promise<boolean | null>;
197
+ /**
198
+ * Exits maintenance mode for a storage unit
199
+ * @param wallet_address - Address of the wallet making the request
200
+ * @param provider_address - Address of the provider owning the unit
201
+ * @param unit_id - Identifier of the storage unit
202
+ * @returns Promise resolving to the maintenance exit transaction result
203
+ * @requires Signature - This method requires a transaction signature
204
+ * @throws Will throw if unit is not in maintenance mode
205
+ */
206
+ exit_maintenance(wallet_address: string, provider_address: string, unit_id: number): Promise<boolean | null>;
207
+ /**
208
+ * Places a storage unit into decommissioning mode
209
+ * This starts the process of removing the unit from service.
210
+ * @param wallet_address - Address of the wallet making the request
211
+ * @param provider_address - Address of the provider owning the unit
212
+ * @param unit_id - Identifier of the storage unit
213
+ * @returns Promise resolving to the decommissioning transaction result
214
+ * @requires Signature - This method requires a transaction signature
215
+ * @throws Will throw if unit has active reservations
216
+ */
217
+ enter_decommissioning(wallet_address: string, provider_address: string, unit_id: number): Promise<boolean | null>;
218
+ /**
219
+ * Exits decommissioning mode for a storage unit
220
+ * This cancels the decommissioning process and returns the unit to service.
221
+ * @param wallet_address - Address of the wallet making the request
222
+ * @param provider_address - Address of the provider owning the unit
223
+ * @param unit_id - Identifier of the storage unit
224
+ * @returns Promise resolving to the decommissioning exit transaction result
225
+ * @requires Signature - This method requires a transaction signature
226
+ * @throws Will throw if unit is not in decommissioning mode
227
+ */
228
+ exit_decommissioning(wallet_address: string, provider_address: string, unit_id: number): Promise<boolean | null>;
229
+ /**
230
+ * Retrieves information about a specific reservation
231
+ * @param wallet_address - Address of the wallet requesting the information
232
+ * @param reservation_id - Identifier of the reservation
233
+ * @returns Promise resolving to StorageReservation object
234
+ */
235
+ get_reservation: (wallet_address: string, reservation_id: number) => Promise<import("./models.js").StorageReservation | null>;
236
+ /**
237
+ * Creates a new storage reservation
238
+ * @param wallet_address - Address of the wallet making the request
239
+ * @param consumer_address - Address of the consumer requesting storage
240
+ * @param unit_id - Identifier of the storage unit to reserve
241
+ * @param reserved_gb - Amount of storage to reserve in gigabytes
242
+ * @returns Promise resolving to the reservation creation transaction result
243
+ * @requires Signature - This method requires a transaction signature
244
+ * @throws Will throw if unit doesn't have enough available capacity
245
+ * @throws Will throw if unit is in maintenance or decommissioning mode
246
+ */
247
+ reserve_unit(wallet_address: string, consumer_address: string, unit_id: number, reserved_gb: number): Promise<boolean>;
248
+ /**
249
+ * Deletes an existing reservation
250
+ * @param wallet_address - Address of the wallet making the request
251
+ * @param consumer_address - Address of the consumer who owns the reservation
252
+ * @param reservation_id - Identifier of the reservation to delete
253
+ * @returns Promise resolving to the reservation deletion transaction result
254
+ * @requires Signature - This method requires a transaction signature
255
+ * @throws Will throw if reservation has non-zero inuse_bytes
256
+ */
257
+ delete_reservation(wallet_address: string, consumer_address: string, reservation_id: number): Promise<import("./models.js").DeletionStatus>;
258
+ /**
259
+ * Updates the amount of storage currently in use by a consumer
260
+ * @param wallet_address - Address of the wallet making the request
261
+ * @param consumer_address - Address of the consumer
262
+ * @param reservation_id - Identifier of the reservation
263
+ * @param inuse_bytes - Current number of bytes in use
264
+ * @returns Promise resolving to the update transaction result
265
+ * @requires Signature - This method requires a transaction signature
266
+ * @throws Will throw if inuse_bytes exceeds reserved amount
267
+ */
268
+ update_inuse_bytes_consumer(wallet_address: string, consumer_address: string, reservation_id: number, inuse_bytes: number): Promise<boolean>;
269
+ /**
270
+ * Updates the amount of storage currently in use, reported by provider
271
+ * @param wallet_address - Address of the wallet making the request
272
+ * @param provider_address - Address of the provider
273
+ * @param reservation_id - Identifier of the reservation
274
+ * @param inuse_bytes - Current number of bytes in use
275
+ * @returns Promise resolving to the update transaction result
276
+ * @requires Signature - This method requires a transaction signature
277
+ * @throws Will throw if inuse_bytes exceeds reserved amount
278
+ * @throws Will throw if provider's report differs significantly from consumer's report
279
+ */
280
+ update_inuse_bytes_provider(wallet_address: string, provider_address: string, reservation_id: number, inuse_bytes: number): Promise<boolean>;
281
+ }
282
+ export { FlashOnStellarClient, FlashOnStellarClientConfig, ClientContext };