@ardrive/turbo-sdk 1.0.0-alpha.21 → 1.0.0-alpha.23

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 (37) hide show
  1. package/README.md +161 -23
  2. package/bundles/web.bundle.min.js +142 -34
  3. package/lib/cjs/common/currency.js +42 -0
  4. package/lib/cjs/common/index.js +1 -0
  5. package/lib/cjs/common/payment.js +38 -6
  6. package/lib/cjs/common/turbo.js +22 -11
  7. package/lib/cjs/common/upload.js +9 -3
  8. package/lib/cjs/node/signer.js +33 -2
  9. package/lib/cjs/utils/readableStream.js +6 -4
  10. package/lib/cjs/web/signer.js +9 -4
  11. package/lib/esm/common/currency.js +27 -0
  12. package/lib/esm/common/index.js +1 -0
  13. package/lib/esm/common/payment.js +38 -6
  14. package/lib/esm/common/turbo.js +22 -11
  15. package/lib/esm/common/upload.js +9 -3
  16. package/lib/esm/node/signer.js +33 -2
  17. package/lib/esm/utils/readableStream.js +6 -4
  18. package/lib/esm/web/signer.js +9 -4
  19. package/lib/types/common/currency.d.ts +43 -0
  20. package/lib/types/common/currency.d.ts.map +1 -0
  21. package/lib/types/common/index.d.ts +1 -0
  22. package/lib/types/common/index.d.ts.map +1 -1
  23. package/lib/types/common/payment.d.ts +13 -5
  24. package/lib/types/common/payment.d.ts.map +1 -1
  25. package/lib/types/common/turbo.d.ts +8 -7
  26. package/lib/types/common/turbo.d.ts.map +1 -1
  27. package/lib/types/common/upload.d.ts +2 -2
  28. package/lib/types/common/upload.d.ts.map +1 -1
  29. package/lib/types/node/signer.d.ts +8 -3
  30. package/lib/types/node/signer.d.ts.map +1 -1
  31. package/lib/types/types.d.ts +42 -8
  32. package/lib/types/types.d.ts.map +1 -1
  33. package/lib/types/utils/readableStream.d.ts +2 -1
  34. package/lib/types/utils/readableStream.d.ts.map +1 -1
  35. package/lib/types/web/signer.d.ts +7 -3
  36. package/lib/types/web/signer.d.ts.map +1 -1
  37. package/package.json +1 -1
package/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # @ardriveapp/turbo-sdk 🚀
2
2
 
3
- Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionalities for interacting with the Turbo Upload and Payment Services. It is available in both NodeJS and Web environments.
3
+ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interacting with the Turbo Upload and Payment Services and is available for both NodeJS and Web environments.
4
4
 
5
5
  ## Table of Contents
6
6
 
7
7
  - [Installation](#installation)
8
- - [Usage](#usage):
9
-
8
+ - [Usage](#usage)
10
9
  - [NodeJS Environments](#nodejs)
11
10
  - [CommonJS](#commonjs)
12
11
  - [ESM](#esm)
@@ -15,7 +14,6 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionalities for inter
15
14
  - [Browser](#browser)
16
15
  - [Typescript](#typescript)
17
16
  - [Examples](./examples)
18
-
19
17
  - [Contributions](#contributions)
20
18
 
21
19
  ## Installation
@@ -32,14 +30,14 @@ yarn add @ardrive/turbo-sdk
32
30
 
33
31
  ## Usage
34
32
 
35
- The SDK is available in both CommonJS and ESM formats and is compatible with bundlers such as Webpack, Rollup, and ESbuild.
33
+ The SDK is provided in both CommonJS and ESM formats, and it's compatible with bundlers such as Webpack, Rollup, and ESbuild. Utilize the appropriate named exports provided by this SDK's [package.json] based on your project's configuration. Refer to the [examples] directory to see how to use the SDK in various environments.
36
34
 
37
35
  ### Web
38
36
 
39
37
  #### Bundlers (Webpack, Rollup, ESbuild, etc.)
40
38
 
41
39
  ```javascript
42
- import { TurboFactory } from '@ardrive/turbo-sdk/web';
40
+ import { TurboFactory } from '@ardrive/turbo-sdk';
43
41
 
44
42
  const turbo = TurboFactory.unauthenticated({});
45
43
  const rates = await turbo.getFiatRates();
@@ -59,14 +57,58 @@ const rates = await turbo.getFiatRates();
59
57
 
60
58
  #### CommonJS
61
59
 
60
+ Project's `package.json`:
61
+
62
+ ```json
63
+ {
64
+ "type": "commonjs" // or absent
65
+ }
66
+ ```
67
+
68
+ tsconfig's `tsconfig.json`:
69
+
70
+ ```json
71
+ {
72
+ "compilerOptions": {
73
+ "module": "CommonJS",
74
+ "moduleResolution": "Node",
75
+ "skipLibCheck": true
76
+ }
77
+ }
78
+ ```
79
+
80
+ Usage:
81
+
62
82
  ```javascript
63
- const { TurboFactory } = require('@ardrive/turbo-sdk/node');
83
+ const { TurboFactory } = require('@ardrive/turbo-sdk');
64
84
 
65
85
  const turbo = TurboFactory.unauthenticated({});
66
86
  const rates = await turbo.getFiatRates();
67
87
  ```
68
88
 
69
- ### ESM
89
+ #### ESM
90
+
91
+ Project's `package.json`:
92
+
93
+ ```json
94
+ {
95
+ "type": "module"
96
+ }
97
+ ```
98
+
99
+ tsconfig's `tsconfig.json`:
100
+
101
+ ```json
102
+ {
103
+ "compilerOptions": {
104
+ "module": "NodeNext",
105
+ "moduleResolution": "NodeNext",
106
+ "skipLibCheck": true
107
+ }
108
+ }
109
+ ```
110
+
111
+ Usage:
70
112
 
71
113
  ```javascript
72
114
  import { TurboFactory } from '@ardrive/turbo-sdk/node';
@@ -77,7 +119,7 @@ const rates = await turbo.getFiatRates();
77
119
 
78
120
  ### Typescript
79
121
 
80
- The SDK provides TypeScript typings. When you import the SDK in a TypeScript project:
122
+ The SDK provides TypeScript types. When you import the SDK in a TypeScript project:
81
123
 
82
124
  ```typescript
83
125
  import Ardrive from '@ardrive/turbo-sdk/web';
@@ -85,30 +127,126 @@ import Ardrive from '@ardrive/turbo-sdk/web';
85
127
  // or '@ardrive/turbo-sdk/node' for Node.js projects
86
128
  ```
87
129
 
88
- The provided typings (`./lib/types/index.d.ts`) will be automatically recognized, offering type checking and autocompletion benefits.
130
+ Types are exported from `./lib/types/index.d.ts` and should be automatically recognized, offering benefits such as type-checking and autocompletion.
89
131
 
90
- ## APIs (WIP)
132
+ ## APIs
91
133
 
92
134
  ### TurboFactory
93
135
 
94
- - `public()`
95
- - `private()`
136
+ - `unauthenticated()` - Creates an instance of a client that accesses Turbo's unauthenticated services.
137
+
138
+ ```typescript
139
+ const turbo = TurboFactory.unauthenticated({});
140
+ ```
141
+
142
+ - `authenticated()` - Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services.
143
+
144
+ ```typescript
145
+ const jwk = await arweave.crypto.generateJWK();
146
+ const turbo = TurboFactory.authenticated({ privateKey: jwk });
147
+ ```
96
148
 
97
149
  ### TurboUnauthenticatedClient
98
150
 
99
- - `getFiatRates()`
100
- - `getFiatToAR()`
101
- - `getSupportedCountries()`
102
- - `getSupportedCurrencies()`
103
- - `getWincForFiat()`
104
- - `getUploadCosts()`
105
- - `uploadSignedDataItem()`
151
+ - `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).
152
+
153
+ ```typescript
154
+ const currencies = await turbo.getSupportedCurrencies();
155
+ ```
156
+
157
+ - `getSupportedCountries()` - Returns the list of countries supported by the Turbo Payment Service's top up workflow.
158
+
159
+ ```typescript
160
+ const countries = await turbo.getSupportedCountries();
161
+ ```
162
+
163
+ - `getFiatToAR()` - Returns the current raw fiat to AR conversion rate for a specific currency as reported by third-party pricing oracles.
164
+
165
+ ```typescript
166
+ const fiatToAR = await turbo.getFiatToAR({ currency: 'USD' });
167
+ ```
168
+
169
+ - `getFiatRates()` - Returns the current fiat rates for 1 GiB of data for supported currencies, including all top-up adjustments and fees.
170
+
171
+ ```typescript
172
+ const rates = await turbo.getFiatRates();
173
+ ```
174
+
175
+ - `getWincForFiat({ amount, promoCodes })` - Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes.
176
+
177
+ ```typescript
178
+ const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
179
+ await turbo.getWincForFiat({
180
+ amount: USD(100),
181
+ promoCodes: ['MY_PROMO_CODE'],
182
+ });
183
+ ```
184
+
185
+ - `getUploadCosts({ bytes })` - Returns the estimated cost in Winston Credits for the provided file sizes, including all upload adjustments and fees.
186
+
187
+ ```typescript
188
+ const costs = await turbo.getUploadCosts({ bytes: [1000, 2000] });
189
+ ```
190
+
191
+ - `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.
192
+
193
+ ```typescript
194
+ const filePath = path.join(__dirname, './my-signed-data-item');
195
+ const dataItemSize = fs.statSync(filePath).size;
196
+ const uploadResponse = await turbo.uploadSignedDataItem({
197
+ dataItemStreamFactory: () => fs.createReadStream(filePath),
198
+ dataItemSizeFactory: () => dataItemSize,
199
+ signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
200
+ });
201
+ ```
202
+
203
+ - `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.
204
+
205
+ ```typescript
206
+ const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
207
+ await turbo.createCheckoutSession({
208
+ amount: USD(10.0), // $10.00 USD
209
+ owner: publicArweaveAddress,
210
+ promoCodes: ['MY_PROMO_CODE'],
211
+ });
212
+
213
+ // Open checkout session in a browser
214
+ if (process.platform === 'darwin') {
215
+ // macOS
216
+ exec(`open ${url}`);
217
+ } else if (process.platform === 'win32') {
218
+ // Windows
219
+ exec(`start "" "${url}"`, { shell: true });
220
+ } else {
221
+ // Linux/Unix
222
+ open(url);
223
+ }
224
+ ```
106
225
 
107
226
  ### TurboAuthenticatedClient
108
227
 
109
- - `getBalance()`
110
- - `uploadFile()`
228
+ - `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
229
+
230
+ ```typescript
231
+ const balance = await turbo.getBalance();
232
+ ```
233
+
234
+ - `uploadFile({ fileStreamFactory, fileSizeFactory, signal })` - 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.
235
+
236
+ ```typescript
237
+ const filePath = path.join(__dirname, './my-unsigned-file.txt');
238
+ const fileSize = fs.stateSync(filePath).size;
239
+ const uploadResult = await turboAuthClient.uploadFile({
240
+ fileStreamFactory: () => fs.createReadStream(filePath),
241
+ fileSizeFactory: () => fileSize,
242
+ });
243
+ ```
111
244
 
112
245
  ## Contributions
113
246
 
114
- If you encounter any issues or have feature requests, please file an issue on our GitHub repository. Contributions, pull requests, and feedback are welcome and encouraged.
247
+ If you encounter any issues or have feature requests, please file an issue on our GitHub repository. Contributions, pull requests, and feedback are both welcome and encouraged.
248
+
249
+ [package.json]: ./package.json
250
+ [examples]: ./examples
251
+ [TurboUnauthenticatedClient]: #turboUnauthenticatedClient
252
+ [TurboAuthenticatedClient]: #turboAuthenticatedClient
@@ -47404,24 +47404,24 @@ var TurboUnauthenticatedPaymentService = class {
47404
47404
  retryConfig
47405
47405
  });
47406
47406
  }
47407
- async getFiatRates() {
47407
+ getFiatRates() {
47408
47408
  return this.httpService.get({
47409
47409
  endpoint: "/rates"
47410
47410
  });
47411
47411
  }
47412
- async getFiatToAR({
47412
+ getFiatToAR({
47413
47413
  currency
47414
47414
  }) {
47415
47415
  return this.httpService.get({
47416
47416
  endpoint: `/rates/${currency}`
47417
47417
  });
47418
47418
  }
47419
- async getSupportedCountries() {
47419
+ getSupportedCountries() {
47420
47420
  return this.httpService.get({
47421
47421
  endpoint: "/countries"
47422
47422
  });
47423
47423
  }
47424
- async getSupportedCurrencies() {
47424
+ getSupportedCurrencies() {
47425
47425
  return this.httpService.get({
47426
47426
  endpoint: "/currencies"
47427
47427
  });
@@ -47437,10 +47437,37 @@ var TurboUnauthenticatedPaymentService = class {
47437
47437
  const wincCostsForBytes = await Promise.all(fetchPricePromises);
47438
47438
  return wincCostsForBytes;
47439
47439
  }
47440
- async getWincForFiat({ amount, currency }) {
47440
+ getWincForFiat({
47441
+ amount
47442
+ }) {
47443
+ const { amount: paymentAmount, type: currencyType } = amount;
47441
47444
  return this.httpService.get({
47442
- endpoint: `/price/${currency}/${amount}`
47445
+ endpoint: `/price/${currencyType}/${paymentAmount}`
47446
+ });
47447
+ }
47448
+ appendPromoCodesToQuery(promoCodes) {
47449
+ const promoCodesQuery = promoCodes.join(",");
47450
+ return promoCodesQuery ? `?promoCode=${promoCodesQuery}` : "";
47451
+ }
47452
+ async getCheckout({ amount, owner, promoCodes = [] }, headers) {
47453
+ const { amount: paymentAmount, type: currencyType } = amount;
47454
+ const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}${this.appendPromoCodesToQuery(
47455
+ promoCodes
47456
+ )}`;
47457
+ const { adjustments, paymentSession, topUpQuote } = await this.httpService.get({
47458
+ endpoint,
47459
+ headers
47443
47460
  });
47461
+ return {
47462
+ winc: topUpQuote.winstonCreditAmount,
47463
+ adjustments,
47464
+ url: paymentSession.url,
47465
+ paymentAmount: topUpQuote.paymentAmount,
47466
+ quotedPaymentAmount: topUpQuote.quotedPaymentAmount
47467
+ };
47468
+ }
47469
+ createCheckoutSession(params) {
47470
+ return this.getCheckout(params);
47444
47471
  }
47445
47472
  };
47446
47473
  var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPaymentService {
@@ -47461,6 +47488,21 @@ var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPayment
47461
47488
  });
47462
47489
  return balance.winc ? balance : { winc: "0" };
47463
47490
  }
47491
+ async getWincForFiat({
47492
+ amount,
47493
+ promoCodes = []
47494
+ }) {
47495
+ return this.httpService.get({
47496
+ endpoint: `/price/${amount.type}/${amount.amount}${this.appendPromoCodesToQuery(promoCodes)}`,
47497
+ headers: await this.signer.generateSignedRequestHeaders()
47498
+ });
47499
+ }
47500
+ async createCheckoutSession(params) {
47501
+ return this.getCheckout(
47502
+ params,
47503
+ await this.signer.generateSignedRequestHeaders()
47504
+ );
47505
+ }
47464
47506
  };
47465
47507
 
47466
47508
  // src/common/turbo.ts
@@ -47480,14 +47522,17 @@ var TurboUnauthenticatedUploadService = class {
47480
47522
  }
47481
47523
  async uploadSignedDataItem({
47482
47524
  dataItemStreamFactory,
47525
+ dataItemSizeFactory,
47483
47526
  signal
47484
47527
  }) {
47528
+ const fileSize = dataItemSizeFactory();
47485
47529
  return this.httpService.post({
47486
47530
  endpoint: `/tx`,
47487
47531
  signal,
47488
47532
  data: dataItemStreamFactory(),
47489
47533
  headers: {
47490
- "content-type": "application/octet-stream"
47534
+ "content-type": "application/octet-stream",
47535
+ "content-length": `${fileSize}`
47491
47536
  }
47492
47537
  });
47493
47538
  }
@@ -47503,17 +47548,22 @@ var TurboAuthenticatedUploadService = class extends TurboUnauthenticatedUploadSe
47503
47548
  }
47504
47549
  async uploadFile({
47505
47550
  fileStreamFactory,
47551
+ fileSizeFactory,
47506
47552
  signal
47507
47553
  }) {
47508
- const signedDataItem = await this.signer.signDataItem({
47509
- fileStreamFactory
47554
+ const { dataItemStreamFactory, dataItemSizeFactory } = await this.signer.signDataItem({
47555
+ fileStreamFactory,
47556
+ fileSizeFactory
47510
47557
  });
47558
+ const signedDataItem = dataItemStreamFactory();
47559
+ const fileSize = dataItemSizeFactory();
47511
47560
  return this.httpService.post({
47512
47561
  endpoint: `/tx`,
47513
47562
  signal,
47514
47563
  data: signedDataItem,
47515
47564
  headers: {
47516
- "content-type": "application/octet-stream"
47565
+ "content-type": "application/octet-stream",
47566
+ "content-length": `${fileSize}`
47517
47567
  }
47518
47568
  });
47519
47569
  }
@@ -47531,7 +47581,7 @@ var TurboUnauthenticatedClient = class {
47531
47581
  /**
47532
47582
  * Returns the supported fiat currency conversion rate for 1AR based on current market prices.
47533
47583
  */
47534
- async getFiatToAR({
47584
+ getFiatToAR({
47535
47585
  currency
47536
47586
  }) {
47537
47587
  return this.paymentService.getFiatToAR({ currency });
@@ -47542,25 +47592,25 @@ var TurboUnauthenticatedClient = class {
47542
47592
  * Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
47543
47593
  * cost in 'winc' for a given number of bytes, use getUploadCosts.
47544
47594
  */
47545
- async getFiatRates() {
47595
+ getFiatRates() {
47546
47596
  return this.paymentService.getFiatRates();
47547
47597
  }
47548
47598
  /**
47549
47599
  * Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
47550
47600
  */
47551
- async getSupportedCountries() {
47601
+ getSupportedCountries() {
47552
47602
  return this.paymentService.getSupportedCountries();
47553
47603
  }
47554
47604
  /**
47555
47605
  * Returns a list of all supported fiat currencies.
47556
47606
  */
47557
- async getSupportedCurrencies() {
47607
+ getSupportedCurrencies() {
47558
47608
  return this.paymentService.getSupportedCurrencies();
47559
47609
  }
47560
47610
  /**
47561
47611
  * Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
47562
47612
  */
47563
- async getUploadCosts({
47613
+ getUploadCosts({
47564
47614
  bytes
47565
47615
  }) {
47566
47616
  return this.paymentService.getUploadCosts({ bytes });
@@ -47568,24 +47618,29 @@ var TurboUnauthenticatedClient = class {
47568
47618
  /**
47569
47619
  * Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
47570
47620
  */
47571
- async getWincForFiat({
47572
- amount,
47573
- currency
47574
- }) {
47575
- return this.paymentService.getWincForFiat({ amount, currency });
47621
+ getWincForFiat(params) {
47622
+ return this.paymentService.getWincForFiat(params);
47576
47623
  }
47577
47624
  /**
47578
47625
  * Uploads a signed data item to the Turbo Upload Service.
47579
47626
  */
47580
- async uploadSignedDataItem({
47627
+ uploadSignedDataItem({
47581
47628
  dataItemStreamFactory,
47629
+ dataItemSizeFactory,
47582
47630
  signal
47583
47631
  }) {
47584
47632
  return this.uploadService.uploadSignedDataItem({
47585
47633
  dataItemStreamFactory,
47634
+ dataItemSizeFactory,
47586
47635
  signal
47587
47636
  });
47588
47637
  }
47638
+ /**
47639
+ * Creates a Turbo Checkout Session for a given amount and currency.
47640
+ */
47641
+ createCheckoutSession(params) {
47642
+ return this.paymentService.createCheckoutSession(params);
47643
+ }
47589
47644
  };
47590
47645
  var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
47591
47646
  constructor({
@@ -47597,17 +47652,22 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
47597
47652
  /**
47598
47653
  * Returns the current balance of the user's wallet in 'winc'.
47599
47654
  */
47600
- async getBalance() {
47655
+ getBalance() {
47601
47656
  return this.paymentService.getBalance();
47602
47657
  }
47603
47658
  /**
47604
47659
  * Signs and uploads raw data to the Turbo Upload Service.
47605
47660
  */
47606
- async uploadFile({
47661
+ uploadFile({
47607
47662
  fileStreamFactory,
47663
+ fileSizeFactory,
47608
47664
  signal
47609
47665
  }) {
47610
- return this.uploadService.uploadFile({ fileStreamFactory, signal });
47666
+ return this.uploadService.uploadFile({
47667
+ fileStreamFactory,
47668
+ fileSizeFactory,
47669
+ signal
47670
+ });
47611
47671
  }
47612
47672
  };
47613
47673
 
@@ -47633,6 +47693,34 @@ var TurboBaseFactory = class {
47633
47693
  // src/common/index.ts
47634
47694
  init_shim();
47635
47695
 
47696
+ // src/common/currency.ts
47697
+ init_shim();
47698
+ var ZeroDecimalCurrency = class {
47699
+ constructor(amount, type) {
47700
+ this.amount = amount;
47701
+ this.type = type;
47702
+ }
47703
+ };
47704
+ var TwoDecimalCurrency = class {
47705
+ constructor(a, type) {
47706
+ this.a = a;
47707
+ this.type = type;
47708
+ }
47709
+ get amount() {
47710
+ return this.a * 100;
47711
+ }
47712
+ };
47713
+ var USD = (usd) => new TwoDecimalCurrency(usd, "usd");
47714
+ var EUR = (eur) => new TwoDecimalCurrency(eur, "eur");
47715
+ var GBP = (gbp) => new TwoDecimalCurrency(gbp, "gbp");
47716
+ var CAD = (cad) => new TwoDecimalCurrency(cad, "cad");
47717
+ var AUD = (aud) => new TwoDecimalCurrency(aud, "aud");
47718
+ var INR = (inr) => new TwoDecimalCurrency(inr, "inr");
47719
+ var SGD = (sgd) => new TwoDecimalCurrency(sgd, "sgd");
47720
+ var HKD = (hkd) => new TwoDecimalCurrency(hkd, "hkd");
47721
+ var BRL = (brl) => new TwoDecimalCurrency(brl, "brl");
47722
+ var JPY = (jpy) => new ZeroDecimalCurrency(jpy, "jpy");
47723
+
47636
47724
  // src/web/signer.ts
47637
47725
  init_shim();
47638
47726
 
@@ -55555,19 +55643,22 @@ function toB64Url(buffer) {
55555
55643
  // src/utils/readableStream.ts
55556
55644
  init_shim();
55557
55645
  async function readableStreamToBuffer({
55558
- stream
55646
+ stream,
55647
+ size
55559
55648
  }) {
55560
55649
  const reader = stream.getReader();
55561
- const chunks = [];
55650
+ const buffer = import_buffer.Buffer.alloc(size);
55651
+ let offset = 0;
55562
55652
  let done = false;
55563
55653
  while (!done) {
55564
55654
  const { done: streamDone, value } = await reader.read();
55565
55655
  done = streamDone;
55566
55656
  if (!done) {
55567
- chunks.push(value);
55657
+ buffer.set(value, offset);
55658
+ offset += value.byteLength;
55568
55659
  }
55569
55660
  }
55570
- return import_buffer.Buffer.concat(chunks);
55661
+ return buffer;
55571
55662
  }
55572
55663
 
55573
55664
  // src/web/signer.ts
@@ -55578,15 +55669,20 @@ var TurboWebArweaveSigner = class {
55578
55669
  this.signer = new ArweaveSigner(this.privateKey);
55579
55670
  }
55580
55671
  async signDataItem({
55581
- fileStreamFactory
55672
+ fileStreamFactory,
55673
+ fileSizeFactory
55582
55674
  }) {
55583
55675
  const buffer = await readableStreamToBuffer({
55584
- stream: fileStreamFactory()
55585
- // TODO: add payload size to get performance improvements
55676
+ stream: fileStreamFactory(),
55677
+ size: fileSizeFactory()
55586
55678
  });
55587
- const signedDataItem = createData(buffer, this.signer);
55679
+ const signedDataItem = createData(buffer, this.signer, {});
55588
55680
  await signedDataItem.sign(this.signer);
55589
- return signedDataItem.getRaw();
55681
+ return {
55682
+ // while this returns a Buffer - it needs to match our return type for uploading
55683
+ dataItemStreamFactory: () => signedDataItem.getRaw(),
55684
+ dataItemSizeFactory: () => signedDataItem.getRaw().length
55685
+ };
55590
55686
  }
55591
55687
  // NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto
55592
55688
  async generateSignedRequestHeaders() {
@@ -55628,6 +55724,15 @@ var TurboFactory = class extends TurboBaseFactory {
55628
55724
  // src/types.ts
55629
55725
  init_shim();
55630
55726
  export {
55727
+ AUD,
55728
+ BRL,
55729
+ CAD,
55730
+ EUR,
55731
+ GBP,
55732
+ HKD,
55733
+ INR,
55734
+ JPY,
55735
+ SGD,
55631
55736
  TurboAuthenticatedClient,
55632
55737
  TurboAuthenticatedPaymentService,
55633
55738
  TurboAuthenticatedUploadService,
@@ -55635,7 +55740,10 @@ export {
55635
55740
  TurboUnauthenticatedClient,
55636
55741
  TurboUnauthenticatedPaymentService,
55637
55742
  TurboUnauthenticatedUploadService,
55638
- TurboWebArweaveSigner
55743
+ TurboWebArweaveSigner,
55744
+ TwoDecimalCurrency,
55745
+ USD,
55746
+ ZeroDecimalCurrency
55639
55747
  };
55640
55748
  /*! Bundled license information:
55641
55749
 
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JPY = exports.BRL = exports.HKD = exports.SGD = exports.INR = exports.AUD = exports.CAD = exports.GBP = exports.EUR = exports.USD = exports.TwoDecimalCurrency = exports.ZeroDecimalCurrency = void 0;
4
+ class ZeroDecimalCurrency {
5
+ constructor(amount, type) {
6
+ this.amount = amount;
7
+ this.type = type;
8
+ }
9
+ }
10
+ exports.ZeroDecimalCurrency = ZeroDecimalCurrency;
11
+ class TwoDecimalCurrency {
12
+ constructor(a, type) {
13
+ this.a = a;
14
+ this.type = type;
15
+ }
16
+ get amount() {
17
+ return this.a * 100;
18
+ }
19
+ }
20
+ exports.TwoDecimalCurrency = TwoDecimalCurrency;
21
+ // Two decimal currencies that are supported by the Turbo API
22
+ const USD = (usd) => new TwoDecimalCurrency(usd, 'usd');
23
+ exports.USD = USD;
24
+ const EUR = (eur) => new TwoDecimalCurrency(eur, 'eur');
25
+ exports.EUR = EUR;
26
+ const GBP = (gbp) => new TwoDecimalCurrency(gbp, 'gbp');
27
+ exports.GBP = GBP;
28
+ const CAD = (cad) => new TwoDecimalCurrency(cad, 'cad');
29
+ exports.CAD = CAD;
30
+ const AUD = (aud) => new TwoDecimalCurrency(aud, 'aud');
31
+ exports.AUD = AUD;
32
+ const INR = (inr) => new TwoDecimalCurrency(inr, 'inr');
33
+ exports.INR = INR;
34
+ const SGD = (sgd) => new TwoDecimalCurrency(sgd, 'sgd');
35
+ exports.SGD = SGD;
36
+ const HKD = (hkd) => new TwoDecimalCurrency(hkd, 'hkd');
37
+ exports.HKD = HKD;
38
+ const BRL = (brl) => new TwoDecimalCurrency(brl, 'brl');
39
+ exports.BRL = BRL;
40
+ // Zero decimal currencies that are supported by the Turbo API
41
+ const JPY = (jpy) => new ZeroDecimalCurrency(jpy, 'jpy');
42
+ exports.JPY = JPY;
@@ -33,3 +33,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  __exportStar(require("./upload.js"), exports);
34
34
  __exportStar(require("./payment.js"), exports);
35
35
  __exportStar(require("./turbo.js"), exports);
36
+ __exportStar(require("./currency.js"), exports);