@ardrive/turbo-sdk 1.5.0 → 1.7.0-alpha.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.
Files changed (38) hide show
  1. package/README.md +242 -179
  2. package/bundles/web.bundle.min.js +48 -13
  3. package/lib/cjs/common/payment.js +4 -1
  4. package/lib/cjs/common/signer.js +20 -0
  5. package/lib/cjs/common/upload.js +6 -5
  6. package/lib/cjs/node/factory.js +10 -2
  7. package/lib/cjs/node/signer.js +6 -6
  8. package/lib/cjs/types.js +3 -1
  9. package/lib/cjs/version.js +1 -1
  10. package/lib/cjs/web/factory.js +8 -0
  11. package/lib/cjs/web/signer.js +3 -1
  12. package/lib/esm/common/payment.js +4 -1
  13. package/lib/esm/common/signer.js +20 -0
  14. package/lib/esm/common/upload.js +6 -5
  15. package/lib/esm/node/factory.js +12 -4
  16. package/lib/esm/node/signer.js +4 -6
  17. package/lib/esm/types.js +2 -0
  18. package/lib/esm/version.js +1 -1
  19. package/lib/esm/web/factory.js +9 -1
  20. package/lib/esm/web/signer.js +2 -2
  21. package/lib/types/common/payment.d.ts +2 -2
  22. package/lib/types/common/payment.d.ts.map +1 -1
  23. package/lib/types/common/signer.d.ts +4 -0
  24. package/lib/types/common/signer.d.ts.map +1 -1
  25. package/lib/types/common/upload.d.ts +4 -3
  26. package/lib/types/common/upload.d.ts.map +1 -1
  27. package/lib/types/node/factory.d.ts +1 -1
  28. package/lib/types/node/factory.d.ts.map +1 -1
  29. package/lib/types/node/signer.d.ts +3 -3
  30. package/lib/types/node/signer.d.ts.map +1 -1
  31. package/lib/types/types.d.ts +6 -4
  32. package/lib/types/types.d.ts.map +1 -1
  33. package/lib/types/version.d.ts +1 -1
  34. package/lib/types/version.d.ts.map +1 -1
  35. package/lib/types/web/factory.d.ts.map +1 -1
  36. package/lib/types/web/signer.d.ts +2 -2
  37. package/lib/types/web/signer.d.ts.map +1 -1
  38. package/package.json +2 -1
package/README.md CHANGED
@@ -9,28 +9,31 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
9
9
  - [Installation](#installation)
10
10
  - [Quick Start](#quick-start)
11
11
  - [Usage](#usage)
12
- - [NodeJS Environments](#nodejs)
13
- - [CommonJS](#commonjs)
14
- - [ESM](#esm)
15
- - [Web Environments](#web)
16
- - [Bundlers (Webpack, Rollup, ESbuild, etc.)](#bundlers-webpack-rollup-esbuild-etc)
17
- - [Browser](#browser)
12
+ - [Web](#web)
13
+ - [NodeJS](#nodejs)
18
14
  - [Typescript](#typescript)
15
+ - [Examples](#examples)
19
16
  - [APIs](#apis)
20
17
  - [TurboFactory](#turbofactory)
18
+ - [`unauthenticated()`](#unauthenticated)
19
+ - [`authenticated()`](#authenticated)
21
20
  - [TurboUnauthenticatedClient](#turbounauthenticatedclient)
21
+ - [`getSupportedCurrencies()`](#getsupportedcurrencies)
22
+ - [`getSupportedCountries()`](#getsupportedcountries)
23
+ - [`getFiatToAR({ currency })`](#getfiattoar-currency-)
24
+ - [`getFiatRates()`](#getfiatrates)
25
+ - [`getWincForFiat({ amount })`](#getwincforfiat-amount-)
26
+ - [`getUploadCosts({ bytes })`](#getuploadcosts-bytes-)
27
+ - [`uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })`](#uploadsigneddataitem-dataitemstreamfactory-dataitemsizefactory-signal-)
28
+ - [`createCheckoutSession({ amount, owner })`](#createcheckoutsession-amount-owner-)
29
+ - [`submitFundTransaction({ txId })`](#submitfundtransaction-txid-)
22
30
  - [TurboAuthenticatedClient](#turboauthenticatedclient)
23
- - [Examples](./examples)
24
- - [CJS](./examples/cjs/index.js)
25
- - [ESM](./examples/esm/index.mjs)
26
- - [Web](./examples/web/index.html)
31
+ - [`getBalance()`](#getbalance)
32
+ - [`getWincForFiat({ amount, promoCodes })`](#getwincforfiat-amount-promocodes-)
33
+ - [`createCheckoutSession({ amount, owner, promoCodes })`](#createcheckoutsession-amount-owner-promocodes-)
34
+ - [`uploadFile({ fileStreamFactory, fileSizeFactory, signal, dataItemOpts })`](#uploadfile-filestreamfactory-filesizefactory-signal-dataitemopts-)
35
+ - [`topUpWithTokens({ tokenAmount, feeMultiplier })`](#topupwithtokens-tokenamount-feemultiplier-)
27
36
  - [Developers](#developers)
28
- - [Requirements](#requirements)
29
- - [Setup & Build](#setup--build)
30
- - [Testing](#testing)
31
- - [Linting and Formatting](#linting--formatting)
32
- - [Architecture](#architecture)
33
- - [Contributing](./CONTRIBUTING.md)
34
37
 
35
38
  ## Installation
36
39
 
@@ -156,198 +159,258 @@ import { TurboFactory } from '@ardrive/turbo-sdk/<node/web>';
156
159
 
157
160
  Types are exported from `./lib/types/[node/web]/index.d.ts` and should be automatically recognized, offering benefits such as type-checking and autocompletion.
158
161
 
162
+ ### Examples
163
+
164
+ Examples are available in the [examples] directory. To run examples:
165
+
166
+ - `yarn example:web` - opens up the example web page
167
+ - `yarn example:cjs` - runs example CJS node script
168
+ - `yarn example:esm` - runs example ESM node script
169
+
159
170
  ## APIs
160
171
 
161
172
  ### TurboFactory
162
173
 
163
- - `unauthenticated()` - Creates an instance of a client that accesses Turbo's unauthenticated services.
174
+ #### `unauthenticated()`
164
175
 
165
- ```typescript
166
- const turbo = TurboFactory.unauthenticated();
167
- ```
176
+ Creates an instance of a client that accesses Turbo's unauthenticated services.
168
177
 
169
- - `authenticated()` - Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services. Requires either a signer, or private key to be provided.
178
+ ```typescript
179
+ const turbo = TurboFactory.unauthenticated();
180
+ ```
170
181
 
171
- ```typescript
172
- const jwk = await arweave.crypto.generateJWK();
173
- const turbo = TurboFactory.authenticated({ privateKey: jwk });
174
- ```
182
+ #### `authenticated()`
183
+
184
+ Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services. Requires either a signer, or private key to be provided.
185
+
186
+ ```typescript
187
+ const jwk = await arweave.crypto.generateJWK();
188
+ const turbo = TurboFactory.authenticated({ privateKey: jwk });
189
+ ```
175
190
 
176
- or
191
+ or
177
192
 
178
- ```typescript
179
- const signer = new ArweaveSigner(jwk);
180
- const turbo = TurboFactory.authenticated({ signer });
181
- ```
193
+ ```typescript
194
+ const signer = new ArweaveSigner(jwk);
195
+ const turbo = TurboFactory.authenticated({ signer });
196
+ ```
182
197
 
183
198
  ### TurboUnauthenticatedClient
184
199
 
185
- - `getSupportedCurrencies()` - Returns the list of currencies supported by the Turbo Payment Service for topping up a user balance of AR Credits (measured in Winston Credits, or winc).
200
+ #### `getSupportedCurrencies()`
186
201
 
187
- ```typescript
188
- const currencies = await turbo.getSupportedCurrencies();
189
- ```
202
+ Returns the list of currencies supported by the Turbo Payment Service for topping up a user balance of AR Credits (measured in Winston Credits, or winc).
190
203
 
191
- - `getSupportedCountries()` - Returns the list of countries supported by the Turbo Payment Service's top up workflow.
204
+ ```typescript
205
+ const currencies = await turbo.getSupportedCurrencies();
206
+ ```
207
+
208
+ #### `getSupportedCountries()`
192
209
 
193
- ```typescript
194
- const countries = await turbo.getSupportedCountries();
195
- ```
210
+ Returns the list of countries supported by the Turbo Payment Service's top up workflow.
196
211
 
197
- - `getFiatToAR({ currency })` - Returns the current raw fiat to AR conversion rate for a specific currency as reported by third-party pricing oracles.
212
+ ```typescript
213
+ const countries = await turbo.getSupportedCountries();
214
+ ```
198
215
 
199
- ```typescript
200
- const fiatToAR = await turbo.getFiatToAR({ currency: 'USD' });
201
- ```
216
+ #### `getFiatToAR({ currency })`
202
217
 
203
- - `getFiatRates()` - Returns the current fiat rates for 1 GiB of data for supported currencies, including all top-up adjustments and fees.
218
+ Returns the current raw fiat to AR conversion rate for a specific currency as reported by third-party pricing oracles.
204
219
 
205
- ```typescript
206
- const rates = await turbo.getFiatRates();
207
- ```
208
-
209
- - `getWincForFiat({ amount })` - Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount. To leverage promo codes, see [TurboAuthenticatedClient].
210
-
211
- ```typescript
212
- const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
213
- await turbo.getWincForFiat({
214
- amount: USD(100),
215
- // promo codes require an authenticated client
216
- });
217
- ```
218
-
219
- - `getUploadCosts({ bytes })` - Returns the estimated cost in Winston Credits for the provided file sizes, including all upload adjustments and fees.
220
-
221
- ```typescript
222
- const [uploadCostForFile] = await turbo.getUploadCosts({ bytes: [1024] });
223
- const { winc, adjustments } = uploadCostForFile;
224
- ```
225
-
226
- - `uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })` - Uploads a signed data item. The provided `dataItemStreamFactory` should produce a NEW signed data item stream each time is it invoked. The `dataItemSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request.
227
-
228
- ```typescript
229
- const filePath = path.join(__dirname, './my-signed-data-item');
230
- const dataItemSize = fs.statSync(filePath).size;
231
- const uploadResponse = await turbo.uploadSignedDataItem({
232
- dataItemStreamFactory: () => fs.createReadStream(filePath),
233
- dataItemSizeFactory: () => dataItemSize,
234
- signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
220
+ ```typescript
221
+ const fiatToAR = await turbo.getFiatToAR({ currency: 'USD' });
222
+ ```
223
+
224
+ #### `getFiatRates()`
225
+
226
+ Returns the current fiat rates for 1 GiB of data for supported currencies, including all top-up adjustments and fees.
227
+
228
+ ```typescript
229
+ const rates = await turbo.getFiatRates();
230
+ ```
231
+
232
+ #### `getWincForFiat({ amount })`
233
+
234
+ Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount. To leverage promo codes, see [TurboAuthenticatedClient].
235
+
236
+ ```typescript
237
+ const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
238
+ await turbo.getWincForFiat({
239
+ amount: USD(100),
240
+ // promo codes require an authenticated client
235
241
  });
236
- ```
237
-
238
- - `createCheckoutSession({ amount, owner })` - Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner. The returned URL can be opened in the browser, all payments are processed by Stripe. To leverage promo codes, see [TurboAuthenticatedClient].
239
-
240
- ```typescript
241
- const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
242
- await turbo.createCheckoutSession({
243
- amount: USD(10.0), // $10.00 USD
244
- owner: publicArweaveAddress,
245
- // promo codes require an authenticated client
246
- });
247
-
248
- // Open checkout session in a browser
249
- if (process.platform === 'darwin') {
250
- // macOS
251
- exec(`open ${url}`);
252
- } else if (process.platform === 'win32') {
253
- // Windows
254
- exec(`start "" "${url}"`, { shell: true });
255
- } else {
256
- // Linux/Unix
257
- open(url);
258
- }
259
- ```
260
-
261
- - `submitFundTransaction({ txId })` - Submits the transaction ID of a funding transaction to Turbo Payment Service for top up processing. The `txId` is the transaction ID of the transaction to be submitted.
262
-
263
- - Note: Use this API if you've already executed your token transfer to the Turbo wallet. Otherwise, consider using `topUpWithTokens` to execute a new token transfer to the Turbo wallet and submit its resulting transaction ID for top up processing all in one go
264
-
265
- ```typescript
266
- const turbo = TurboFactory.unauthenticated(); // defaults to arweave token type
267
- const { status, id, ...fundResult } = await turbo.submitFundTransaction({
268
- txId: 'my-valid-arweave-fund-transaction-id',
242
+ ```
243
+
244
+ #### `getUploadCosts({ bytes })`
245
+
246
+ Returns the estimated cost in Winston Credits for the provided file sizes, including all upload adjustments and fees.
247
+
248
+ ```typescript
249
+ const [uploadCostForFile] = await turbo.getUploadCosts({ bytes: [1024] });
250
+ const { winc, adjustments } = uploadCostForFile;
251
+ ```
252
+
253
+ #### `uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })`
254
+
255
+ Uploads a signed data item. The provided `dataItemStreamFactory` should produce a NEW signed data item stream each time is it invoked. The `dataItemSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request.
256
+
257
+ ```typescript
258
+ const filePath = path.join(__dirname, './my-signed-data-item');
259
+ const dataItemSize = fs.statSync(filePath).size;
260
+ const uploadResponse = await turbo.uploadSignedDataItem({
261
+ dataItemStreamFactory: () => fs.createReadStream(filePath),
262
+ dataItemSizeFactory: () => dataItemSize,
263
+ signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
264
+ });
265
+ ```
266
+
267
+ #### `createCheckoutSession({ amount, owner })`
268
+
269
+ Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner. The returned URL can be opened in the browser, all payments are processed by Stripe. To leverage promo codes, see [TurboAuthenticatedClient].
270
+
271
+ ```typescript
272
+ const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
273
+ await turbo.createCheckoutSession({
274
+ amount: USD(10.0), // $10.00 USD
275
+ owner: publicArweaveAddress,
276
+ // promo codes require an authenticated client
269
277
  });
270
- ```
278
+
279
+ // Open checkout session in a browser
280
+ if (process.platform === 'darwin') {
281
+ // macOS
282
+ exec(`open ${url}`);
283
+ } else if (process.platform === 'win32') {
284
+ // Windows
285
+ exec(`start "" "${url}"`, { shell: true });
286
+ } else {
287
+ // Linux/Unix
288
+ open(url);
289
+ }
290
+ ```
291
+
292
+ ##### Top up to ETH or SOL wallets
293
+
294
+ ```ts
295
+ const turbo = TurboFactory.unauthenticated({ token: 'ethereum' });
296
+
297
+ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
298
+ amount: USD(10.0), // $10.00 USD
299
+ owner: publicEthereumAddress,
300
+ });
301
+ ```
302
+
303
+ ```ts
304
+ const turbo = TurboFactory.unauthenticated({ token: 'solana' });
305
+
306
+ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
307
+ amount: USD(10.0), // $10.00 USD
308
+ owner: publicSolanaAddress,
309
+ });
310
+ ```
311
+
312
+ #### `submitFundTransaction({ txId })`
313
+
314
+ Submits the transaction ID of a funding transaction to Turbo Payment Service for top up processing. The `txId` is the transaction ID of the transaction to be submitted.
315
+
316
+ - Note: Use this API if you've already executed your token transfer to the Turbo wallet. Otherwise, consider using `topUpWithTokens` to execute a new token transfer to the Turbo wallet and submit its resulting transaction ID for top up processing all in one go
317
+
318
+ ```typescript
319
+ const turbo = TurboFactory.unauthenticated(); // defaults to arweave token type
320
+ const { status, id, ...fundResult } = await turbo.submitFundTransaction({
321
+ txId: 'my-valid-arweave-fund-transaction-id',
322
+ });
323
+ ```
271
324
 
272
325
  ### TurboAuthenticatedClient
273
326
 
274
- - `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
275
-
276
- ```typescript
277
- const { winc: balance } = await turbo.getBalance();
278
- ```
279
-
280
- - `getWincForFiat({ amount, promoCodes })` - Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes.
281
-
282
- ```typescript
283
- const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
284
- await turbo.getWincForFiat({
285
- amount: USD(100),
286
- promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
287
- });
288
- ```
289
-
290
- - `createCheckoutSession({ amount, owner, promoCodes })` - Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner, and optional promo codes. The returned URL can be opened in the browser, all payments are processed by Stripe. Promo codes require an authenticated client.
291
-
292
- ```typescript
293
- const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
294
- await turbo.createCheckoutSession({
295
- amount: USD(10.0), // $10.00 USD
296
- owner: publicArweaveAddress,
297
- promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
298
- });
299
-
300
- // Open checkout session in a browser
301
- if (process.platform === 'darwin') {
302
- // macOS
303
- exec(`open ${url}`);
304
- } else if (process.platform === 'win32') {
305
- // Windows
306
- exec(`start "" "${url}"`, { shell: true });
307
- } else {
308
- // Linux/Unix
309
- open(url);
310
- }
311
- ```
312
-
313
- - `uploadFile({ fileStreamFactory, fileSizeFactory, signal, dataItemOpts })` - Signs and uploads a raw file. The provided `fileStreamFactory` should produce a NEW file data stream each time is it invoked. The `fileSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. `dataItemOpts` is an optional object that can be used to configure tags, target, and anchor for the data item upload.
314
-
315
- ```typescript
316
- const filePath = path.join(__dirname, './my-unsigned-file.txt');
317
- const fileSize = fs.stateSync(filePath).size;
318
- const uploadResult = await turbo.uploadFile({
319
- fileStreamFactory: () => fs.createReadStream(filePath),
320
- fileSizeFactory: () => fileSize,
321
- dataItemOpts: {
322
- // optional
323
- tags: [
324
- {
325
- name: 'Content-Type',
326
- value: 'text/plain',
327
- },
328
- {
329
- name: 'My-Custom-Tag',
330
- value: 'my-custom-value',
331
- },
332
- ],
333
- // no timeout or AbortSignal provided
334
- },
335
- });
336
- ```
327
+ #### `getBalance()`
328
+
329
+ Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
330
+
331
+ ```typescript
332
+ const { winc: balance } = await turbo.getBalance();
333
+ ```
334
+
335
+ #### `getWincForFiat({ amount, promoCodes })`
336
+
337
+ Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes.
337
338
 
338
- - `topUpWithTokens({ tokenAmount, feeMultiplier })` - Tops up the connected wallet with Credits by submitting a payment transaction for the token amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
339
+ ```typescript
340
+ const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
341
+ await turbo.getWincForFiat({
342
+ amount: USD(100),
343
+ promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
344
+ });
345
+ ```
339
346
 
340
- - The `tokenAmount` is the amount of tokens in the token type's smallest unit value (e.g: Winston for arweave token type) to fund the wallet with.
341
- - The `feeMultiplier` (optional) is the multiplier to apply to the reward for the transaction to modify its chances of being mined. Credits will be added to the wallet balance after the transaction is confirmed on the given blockchain. Defaults to 1.0, meaning no multiplier.
347
+ #### `createCheckoutSession({ amount, owner, promoCodes })`
342
348
 
343
- ```typescript
344
- const turbo = TurboFactory.authenticated({ signer, token: 'arweave' });
349
+ Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner, and optional promo codes. The returned URL can be opened in the browser, all payments are processed by Stripe. Promo codes require an authenticated client.
345
350
 
346
- const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
347
- tokenAmount: WinstonToTokenAmount(100_000_000), // 0.0001 AR
348
- feeMultiplier: 1.1, // 10% increase in reward for improved mining chances
351
+ ```typescript
352
+ const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
353
+ await turbo.createCheckoutSession({
354
+ amount: USD(10.0), // $10.00 USD
355
+ owner: publicArweaveAddress,
356
+ promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
349
357
  });
350
- ```
358
+
359
+ // Open checkout session in a browser
360
+ if (process.platform === 'darwin') {
361
+ // macOS
362
+ exec(`open ${url}`);
363
+ } else if (process.platform === 'win32') {
364
+ // Windows
365
+ exec(`start "" "${url}"`, { shell: true });
366
+ } else {
367
+ // Linux/Unix
368
+ open(url);
369
+ }
370
+ ```
371
+
372
+ #### `uploadFile({ fileStreamFactory, fileSizeFactory, signal, dataItemOpts })`
373
+
374
+ Signs and uploads a raw file. The provided `fileStreamFactory` should produce a NEW file data stream each time is it invoked. The `fileSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. `dataItemOpts` is an optional object that can be used to configure tags, target, and anchor for the data item upload.
375
+
376
+ ```typescript
377
+ const filePath = path.join(__dirname, './my-unsigned-file.txt');
378
+ const fileSize = fs.stateSync(filePath).size;
379
+ const uploadResult = await turbo.uploadFile({
380
+ fileStreamFactory: () => fs.createReadStream(filePath),
381
+ fileSizeFactory: () => fileSize,
382
+ dataItemOpts: {
383
+ // optional
384
+ tags: [
385
+ {
386
+ name: 'Content-Type',
387
+ value: 'text/plain',
388
+ },
389
+ {
390
+ name: 'My-Custom-Tag',
391
+ value: 'my-custom-value',
392
+ },
393
+ ],
394
+ // no timeout or AbortSignal provided
395
+ },
396
+ });
397
+ ```
398
+
399
+ #### `topUpWithTokens({ tokenAmount, feeMultiplier })`
400
+
401
+ Tops up the connected wallet with Credits by submitting a payment transaction for the token amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
402
+
403
+ - The `tokenAmount` is the amount of tokens in the token type's smallest unit value (e.g: Winston for arweave token type) to fund the wallet with.
404
+ - The `feeMultiplier` (optional) is the multiplier to apply to the reward for the transaction to modify its chances of being mined. Credits will be added to the wallet balance after the transaction is confirmed on the given blockchain. Defaults to 1.0, meaning no multiplier.
405
+
406
+ ```typescript
407
+ const turbo = TurboFactory.authenticated({ signer, token: 'arweave' });
408
+
409
+ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
410
+ tokenAmount: WinstonToTokenAmount(100_000_000), // 0.0001 AR
411
+ feeMultiplier: 1.1, // 10% increase in reward for improved mining chances
412
+ });
413
+ ```
351
414
 
352
415
  ## Developers
353
416
 
@@ -95846,9 +95846,9 @@ var require_scrypt = __commonJS({
95846
95846
  }
95847
95847
  });
95848
95848
 
95849
- // node_modules/base-x/node_modules/safe-buffer/index.js
95849
+ // node_modules/arbundles/node_modules/safe-buffer/index.js
95850
95850
  var require_safe_buffer = __commonJS({
95851
- "node_modules/base-x/node_modules/safe-buffer/index.js"(exports13, module2) {
95851
+ "node_modules/arbundles/node_modules/safe-buffer/index.js"(exports13, module2) {
95852
95852
  "use strict";
95853
95853
  init_dirname();
95854
95854
  init_buffer2();
@@ -95908,9 +95908,9 @@ var require_safe_buffer = __commonJS({
95908
95908
  }
95909
95909
  });
95910
95910
 
95911
- // node_modules/base-x/src/index.js
95911
+ // node_modules/arbundles/node_modules/base-x/src/index.js
95912
95912
  var require_src = __commonJS({
95913
- "node_modules/base-x/src/index.js"(exports13, module2) {
95913
+ "node_modules/arbundles/node_modules/base-x/src/index.js"(exports13, module2) {
95914
95914
  "use strict";
95915
95915
  init_dirname();
95916
95916
  init_buffer2();
@@ -96042,9 +96042,9 @@ var require_src = __commonJS({
96042
96042
  }
96043
96043
  });
96044
96044
 
96045
- // node_modules/bs58/index.js
96045
+ // node_modules/arbundles/node_modules/bs58/index.js
96046
96046
  var require_bs58 = __commonJS({
96047
- "node_modules/bs58/index.js"(exports13, module2) {
96047
+ "node_modules/arbundles/node_modules/bs58/index.js"(exports13, module2) {
96048
96048
  "use strict";
96049
96049
  init_dirname();
96050
96050
  init_buffer2();
@@ -130843,7 +130843,7 @@ var import_winston = __toESM(require_winston(), 1);
130843
130843
  init_dirname();
130844
130844
  init_buffer2();
130845
130845
  init_process2();
130846
- var version21 = "1.5.0-alpha.4";
130846
+ var version21 = "1.6.0";
130847
130847
 
130848
130848
  // src/common/logger.ts
130849
130849
  var TurboWinstonLogger = class {
@@ -139243,7 +139243,7 @@ var TurboUnauthenticatedPaymentService = class {
139243
139243
  uiMode = "hosted"
139244
139244
  }, headers) {
139245
139245
  const { amount: paymentAmount, type: currencyType } = amount;
139246
- const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}?uiMode=${uiMode}${promoCodes.length > 0 ? `&${this.appendPromoCodesToQuery(promoCodes)}` : ""}`;
139246
+ const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}?uiMode=${uiMode}${promoCodes.length > 0 ? `&${this.appendPromoCodesToQuery(promoCodes)}` : ""}&token=${this.token}`;
139247
139247
  const { adjustments, paymentSession, topUpQuote } = await this.httpService.get({
139248
139248
  endpoint,
139249
139249
  headers
@@ -139355,6 +139355,9 @@ var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPayment
139355
139355
  feeMultiplier = 1,
139356
139356
  tokenAmount: tokenAmountV
139357
139357
  }) {
139358
+ if (!this.tokenMap[this.token]) {
139359
+ throw new Error(`Token type not supported for crypto fund ${this.token}`);
139360
+ }
139358
139361
  const tokenAmount = new BigNumber2(tokenAmountV);
139359
139362
  const target = await this.getTargetWalletForFund();
139360
139363
  this.logger.debug("Funding account...", {
@@ -139402,8 +139405,10 @@ var TurboUnauthenticatedUploadService = class {
139402
139405
  constructor({
139403
139406
  url = defaultUploadServiceURL,
139404
139407
  retryConfig,
139405
- logger: logger19 = new TurboWinstonLogger()
139408
+ logger: logger19 = new TurboWinstonLogger(),
139409
+ token = "arweave"
139406
139410
  }) {
139411
+ this.token = token;
139407
139412
  this.logger = logger19;
139408
139413
  this.httpService = new TurboHTTPService({
139409
139414
  url: `${url}/v1`,
@@ -139419,7 +139424,7 @@ var TurboUnauthenticatedUploadService = class {
139419
139424
  const fileSize = dataItemSizeFactory();
139420
139425
  this.logger.debug("Uploading signed data item...");
139421
139426
  return this.httpService.post({
139422
- endpoint: `/tx`,
139427
+ endpoint: `/tx/${this.token}`,
139423
139428
  signal,
139424
139429
  data: dataItemStreamFactory(),
139425
139430
  headers: {
@@ -139434,9 +139439,10 @@ var TurboAuthenticatedUploadService = class extends TurboUnauthenticatedUploadSe
139434
139439
  url = defaultUploadServiceURL,
139435
139440
  retryConfig,
139436
139441
  signer,
139437
- logger: logger19
139442
+ logger: logger19,
139443
+ token
139438
139444
  }) {
139439
- super({ url, retryConfig, logger: logger19 });
139445
+ super({ url, retryConfig, logger: logger19, token });
139440
139446
  this.signer = signer;
139441
139447
  }
139442
139448
  async uploadFile({
@@ -139454,7 +139460,7 @@ var TurboAuthenticatedUploadService = class extends TurboUnauthenticatedUploadSe
139454
139460
  const fileSize = dataItemSizeFactory();
139455
139461
  this.logger.debug("Uploading signed data item...");
139456
139462
  return this.httpService.post({
139457
- endpoint: `/tx`,
139463
+ endpoint: `/tx/${this.token}`,
139458
139464
  signal,
139459
139465
  data: signedDataItem,
139460
139466
  headers: {
@@ -139678,6 +139684,24 @@ var TurboDataItemAbstractSigner = class {
139678
139684
  this.logger = logger19;
139679
139685
  this.signer = signer;
139680
139686
  }
139687
+ get sigConfig() {
139688
+ if (this.signer instanceof EthereumSigner) {
139689
+ return {
139690
+ signatureLength: 65,
139691
+ ownerLength: 65
139692
+ };
139693
+ }
139694
+ if (this.signer instanceof HexSolanaSigner2) {
139695
+ return {
139696
+ signatureLength: 64,
139697
+ ownerLength: 32
139698
+ };
139699
+ }
139700
+ return {
139701
+ ownerLength: 512,
139702
+ signatureLength: 512
139703
+ };
139704
+ }
139681
139705
  async generateSignedRequestHeaders() {
139682
139706
  const nonce = randomBytes(16).toString("hex");
139683
139707
  const buffer2 = Buffer2.from(nonce);
@@ -139777,6 +139801,13 @@ var TurboFactory = class extends TurboBaseFactory {
139777
139801
  let signer;
139778
139802
  if (providedSigner) {
139779
139803
  signer = providedSigner;
139804
+ if (!token) {
139805
+ if (signer instanceof EthereumSigner) {
139806
+ token = "ethereum";
139807
+ } else if (signer instanceof HexSolanaSigner2) {
139808
+ token = "solana";
139809
+ }
139810
+ }
139780
139811
  } else if (privateKey) {
139781
139812
  signer = new ArweaveSigner(privateKey);
139782
139813
  } else {
@@ -139809,6 +139840,7 @@ var TurboFactory = class extends TurboBaseFactory {
139809
139840
  init_dirname();
139810
139841
  init_buffer2();
139811
139842
  init_process2();
139843
+ var allowedFiatTokens = ["arweave", "solana", "ethereum"];
139812
139844
  var tokenTypes = [
139813
139845
  "arweave"
139814
139846
  /*'solana', 'ethereum'*/
@@ -139822,8 +139854,10 @@ export {
139822
139854
  BRL,
139823
139855
  CAD,
139824
139856
  EUR,
139857
+ EthereumSigner,
139825
139858
  GBP,
139826
139859
  HKD,
139860
+ HexSolanaSigner2 as HexSolanaSigner,
139827
139861
  INR,
139828
139862
  JPY,
139829
139863
  SGD,
@@ -139839,6 +139873,7 @@ export {
139839
139873
  USD,
139840
139874
  WinstonToTokenAmount,
139841
139875
  ZeroDecimalCurrency,
139876
+ allowedFiatTokens,
139842
139877
  defaultPaymentServiceURL,
139843
139878
  defaultTurboConfiguration,
139844
139879
  defaultUploadServiceURL,
@@ -74,7 +74,7 @@ class TurboUnauthenticatedPaymentService {
74
74
  const { amount: paymentAmount, type: currencyType } = amount;
75
75
  const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}?uiMode=${uiMode}${promoCodes.length > 0
76
76
  ? `&${this.appendPromoCodesToQuery(promoCodes)}`
77
- : ''}`;
77
+ : ''}&token=${this.token}`;
78
78
  const { adjustments, paymentSession, topUpQuote } = await this.httpService.get({
79
79
  endpoint,
80
80
  headers,
@@ -173,6 +173,9 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
173
173
  return walletAddress;
174
174
  }
175
175
  async topUpWithTokens({ feeMultiplier = 1, tokenAmount: tokenAmountV, }) {
176
+ if (!this.tokenMap[this.token]) {
177
+ throw new Error(`Token type not supported for crypto fund ${this.token}`);
178
+ }
176
179
  const tokenAmount = new bignumber_js_1.BigNumber(tokenAmountV);
177
180
  const target = await this.getTargetWalletForFund();
178
181
  this.logger.debug('Funding account...', {