@ardrive/turbo-sdk 1.23.4 → 1.24.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 (57) hide show
  1. package/README.md +126 -159
  2. package/bundles/web.bundle.min.js +71362 -57694
  3. package/lib/cjs/cli/commands/cryptoFund.js +1 -1
  4. package/lib/cjs/cli/constants.js +18 -9
  5. package/lib/cjs/cli/options.js +10 -0
  6. package/lib/cjs/cli/utils.js +20 -10
  7. package/lib/cjs/common/factory.js +3 -1
  8. package/lib/cjs/common/signer.js +1 -0
  9. package/lib/cjs/common/token/ario.js +116 -0
  10. package/lib/cjs/common/token/arweave.js +16 -11
  11. package/lib/cjs/common/token/index.js +5 -0
  12. package/lib/cjs/node/factory.js +3 -1
  13. package/lib/cjs/types.js +1 -0
  14. package/lib/cjs/utils/common.js +34 -0
  15. package/lib/cjs/version.js +1 -1
  16. package/lib/cjs/web/factory.js +3 -1
  17. package/lib/esm/cli/commands/cryptoFund.js +1 -1
  18. package/lib/esm/cli/constants.js +17 -9
  19. package/lib/esm/cli/options.js +10 -0
  20. package/lib/esm/cli/utils.js +19 -9
  21. package/lib/esm/common/factory.js +3 -1
  22. package/lib/esm/common/signer.js +1 -0
  23. package/lib/esm/common/token/ario.js +110 -0
  24. package/lib/esm/common/token/arweave.js +16 -11
  25. package/lib/esm/common/token/index.js +5 -0
  26. package/lib/esm/node/factory.js +3 -1
  27. package/lib/esm/types.js +1 -0
  28. package/lib/esm/utils/common.js +33 -0
  29. package/lib/esm/version.js +1 -1
  30. package/lib/esm/web/factory.js +3 -1
  31. package/lib/types/cli/constants.d.ts +1 -17
  32. package/lib/types/cli/constants.d.ts.map +1 -1
  33. package/lib/types/cli/options.d.ts +10 -0
  34. package/lib/types/cli/options.d.ts.map +1 -1
  35. package/lib/types/cli/types.d.ts +2 -0
  36. package/lib/types/cli/types.d.ts.map +1 -1
  37. package/lib/types/cli/utils.d.ts.map +1 -1
  38. package/lib/types/common/factory.d.ts +1 -1
  39. package/lib/types/common/factory.d.ts.map +1 -1
  40. package/lib/types/common/signer.d.ts +2 -2
  41. package/lib/types/common/signer.d.ts.map +1 -1
  42. package/lib/types/common/token/ario.d.ts +33 -0
  43. package/lib/types/common/token/ario.d.ts.map +1 -0
  44. package/lib/types/common/token/arweave.d.ts.map +1 -1
  45. package/lib/types/common/token/index.d.ts +1 -0
  46. package/lib/types/common/token/index.d.ts.map +1 -1
  47. package/lib/types/node/factory.d.ts +1 -1
  48. package/lib/types/node/factory.d.ts.map +1 -1
  49. package/lib/types/types.d.ts +11 -3
  50. package/lib/types/types.d.ts.map +1 -1
  51. package/lib/types/utils/common.d.ts +14 -0
  52. package/lib/types/utils/common.d.ts.map +1 -1
  53. package/lib/types/version.d.ts +1 -1
  54. package/lib/types/version.d.ts.map +1 -1
  55. package/lib/types/web/factory.d.ts +1 -1
  56. package/lib/types/web/factory.d.ts.map +1 -1
  57. package/package.json +3 -2
package/README.md CHANGED
@@ -13,79 +13,17 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
13
13
  - [Quick Start](#quick-start)
14
14
  - [Usage](#usage)
15
15
  - [Web](#web)
16
- - [Bundlers (Webpack, Rollup, ESbuild, etc.)](#bundlers-webpack-rollup-esbuild-etc)
17
- - [Browser](#browser)
18
16
  - [NodeJS](#nodejs)
19
- - [CommonJS](#commonjs)
20
- - [ESM](#esm)
21
17
  - [Typescript](#typescript)
22
18
  - [Examples](#examples)
23
19
  - [Logging](#logging)
24
20
  - [APIs](#apis)
25
21
  - [TurboFactory](#turbofactory)
26
- - [`unauthenticated()`](#unauthenticated)
27
- - [`authenticated()`](#authenticated)
28
- - [Arweave JWK](#arweave-jwk)
29
- - [ArweaveSigner](#arweavesigner)
30
- - [ArconnectSigner](#arconnectsigner)
31
- - [EthereumSigner](#ethereumsigner)
32
- - [Ethereum Private Key](#ethereum-private-key)
33
- - [POL (MATIC) Private Key](#pol-matic-private-key)
34
- - [HexSolanaSigner](#hexsolanasigner)
35
- - [Solana Secret Key](#solana-secret-key)
36
- - [KYVE Private Key](#kyve-private-key)
37
- - [KYVE Mnemonic](#kyve-mnemonic)
38
22
  - [TurboUnauthenticatedClient](#turbounauthenticatedclient)
39
- - [`getSupportedCurrencies()`](#getsupportedcurrencies)
40
- - [`getSupportedCountries()`](#getsupportedcountries)
41
- - [`getFiatToAR({ currency })`](#getfiattoar-currency-)
42
- - [`getFiatRates()`](#getfiatrates)
43
- - [`getWincForFiat({ amount })`](#getwincforfiat-amount-)
44
- - [`getWincForToken({ tokenAmount })`](#getwincfortoken-tokenamount-)
45
- - [`getTokenPriceForBytes({ byteCount })`](#gettokenpriceforbytes-bytecount-)
46
- - [`getUploadCosts({ bytes })`](#getuploadcosts-bytes-)
47
- - [`uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })`](#uploadsigneddataitem-dataitemstreamfactory-dataitemsizefactory-signal-)
48
- - [`createCheckoutSession({ amount, owner })`](#createcheckoutsession-amount-owner-)
49
- - [Arweave (AR) Fiat Top Up](#arweave-ar-fiat-top-up)
50
- - [Ethereum (ETH) Fiat Top Up](#ethereum-eth-fiat-top-up)
51
- - [Solana (SOL) Fiat Top Up](#solana-sol-fiat-top-up)
52
- - [Polygon (POL / MATIC) Fiat Top Up](#polygon-pol--matic-fiat-top-up)
53
- - [KYVE Fiat Top Up](#kyve-fiat-top-up)
54
- - [`submitFundTransaction({ txId })`](#submitfundtransaction-txid-)
55
23
  - [TurboAuthenticatedClient](#turboauthenticatedclient)
56
- - [`getBalance()`](#getbalance)
57
- - [`signer.getNativeAddress()`](#signergetnativeaddress)
58
- - [`getWincForFiat({ amount, promoCodes })`](#getwincforfiat-amount-promocodes-)
59
- - [`createCheckoutSession({ amount, owner, promoCodes })`](#createcheckoutsession-amount-owner-promocodes-)
60
- - [`uploadFile({ fileStreamFactory, fileSizeFactory, signal, dataItemOpts })`](#uploadfile-filestreamfactory-filesizefactory-signal-dataitemopts-)
61
- - [`uploadFolder({ folderPath, files, dataItemOpts, signal, maxConcurrentUploads, throwOnFailure, manifestOptions })`](#uploadfolder-folderpath-files-dataitemopts-signal-maxconcurrentuploads-throwonfailure-manifestoptions-)
62
- - [NodeJS Upload Folder](#nodejs-upload-folder)
63
- - [Browser Upload Folder](#browser-upload-folder)
64
- - [`topUpWithTokens({ tokenAmount, feeMultiplier })`](#topupwithtokens-tokenamount-feemultiplier-)
65
- - [Arweave (AR) Crypto Top Up](#arweave-ar-crypto-top-up)
66
- - [Ethereum (ETH) Crypto Top Up](#ethereum-eth-crypto-top-up)
67
- - [Polygon (POL / MATIC) Crypto Top Up](#polygon-pol--matic-crypto-top-up)
68
- - [Eth on Base Network Crypto Top Up](#eth-on-base-network-crypto-top-up)
69
- - [Solana (SOL) Crypto Top Up](#solana-sol-crypto-top-up)
70
- - [KYVE Crypto Top Up](#kyve-crypto-top-up)
71
- - [`shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })`](#sharecredits-approvedaddress-approvedwincamount-expiresbyseconds-)
72
- - [`revokeCredits({ approvedAddress })`](#revokecredits-approvedaddress-)
73
- - [`getCreditShareApprovals({ userAddress })`](#getcreditshareapprovals-useraddress-)
74
24
  - [CLI](#cli)
75
- - [Install CLI](#install-cli)
76
- - [CLI Usage](#cli-usage)
77
- - [Options](#options)
78
- - [Commands](#commands)
79
- - [`balance`](#balance)
80
- - [`top-up`](#top-up)
81
- - [`crypto-fund`](#crypto-fund)
82
- - [`upload-folder`](#upload-folder)
83
- - [`upload-file`](#upload-file)
84
- - [`price`](#price)
85
- - [`token-price`](#token-price)
86
- - [`share-credits`](#share-credits)
87
- - [`revoke-credits`](#revoke-credits)
88
- - [`list-shares`](#list-shares)
25
+ - [Installation](#installation-1)
26
+ - [Usage](#usage-1)
89
27
  - [Turbo Credit Sharing](#turbo-credit-sharing)
90
28
  - [Developers](#developers)
91
29
  - [Requirements](#requirements)
@@ -111,55 +49,74 @@ yarn add @ardrive/turbo-sdk
111
49
  ## Quick Start
112
50
 
113
51
  ```typescript
114
- import { TurboFactory, ArweaveSigner } from '@ardrive/turbo-sdk';
115
-
116
- // load your JWK directly to authenticate
117
- const jwk = fs.readFileSync('./my-jwk.json');
118
- const address = arweave.wallets.jwkToAddress(jwk);
119
- const turbo = TurboFactory.authenticated({ privateKey: jwk });
120
-
121
- // or provide your own signer
122
- const signer = new ArweaveSigner(jwk);
123
- const turbo = TurboFactory.authenticated({ signer });
124
-
125
- // get the wallet balance
126
- const { winc: balance } = await turbo.getBalance();
127
-
128
- // prep file for upload
129
- const filePath = path.join(__dirname, './my-image.png');
130
- const fileSize = fs.statSync(filePath).size;
131
-
132
- // get the cost of uploading the file
133
- const [{ winc: fileSizeCost }] = await turbo.getUploadCosts({
134
- bytes: [fileSize],
135
- });
136
-
137
- // check if balance greater than upload cost
138
- if (balance < fileSizeCost) {
139
- const { url } = await turbo.createCheckoutSession({
140
- amount: fileSizeCost,
141
- owner: address,
142
- // add a promo code if you have one
52
+ import { ArweaveSigner, TurboFactory } from '@ardrive/turbo-sdk';
53
+ import Arweave from 'arweave';
54
+ import fs from 'fs';
55
+ import open from 'open';
56
+ import path from 'path';
57
+
58
+ async function uploadWithTurbo() {
59
+ // load your JWK directly to authenticate
60
+ const arweave = Arweave({});
61
+ const jwk = JSON.parse(fs.readFileSync('./my-jwk.json', 'utf-8'));
62
+ const address = await arweave.wallets.jwkToAddress(jwk);
63
+ const turbo = TurboFactory.authenticated({ privateKey: jwk });
64
+
65
+ // or provide your own signer
66
+ // const signer = new ArweaveSigner(jwk);
67
+ // const turbo = TurboFactory.authenticated({ signer });
68
+
69
+ // get the wallet balance
70
+ const { winc: balance } = await turbo.getBalance();
71
+
72
+ // prep file for upload
73
+ const filePath = path.join(__dirname, './my-image.png');
74
+ const fileSize = fs.statSync(filePath).size;
75
+
76
+ // get the cost of uploading the file
77
+ const [{ winc: fileSizeCost }] = await turbo.getUploadCosts({
78
+ bytes: [fileSize],
143
79
  });
144
- // open the URL to top-up, continue when done
145
- open(url);
146
- return;
147
- }
148
80
 
149
- // upload the file
150
- try {
151
- const { id, owner, dataCaches, fastFinalityIndexes } = await turbo.uploadFile(() => {
152
- fileStreamFactory => () => fs.createReadStream(filePath),
153
- fileSizeFactory => () => fileSize,
154
- });
155
- // upload complete!
156
- console.log('Successfully upload data item!', { id, owner, dataCaches, fastFinalityIndexes });
157
- } catch (error) {
158
- // upload failed
159
- console.error('Failed to upload data item!', error);
160
- } finally {
161
- const { winc: newBalance } = await turbo.getBalance();
162
- console.log('New balance:', newBalance);
81
+ // check if balance greater than upload cost, and if in browser
82
+ if (balance < fileSizeCost && window !== undefined) {
83
+ const { url } = await turbo.createCheckoutSession({
84
+ amount: fileSizeCost,
85
+ owner: address,
86
+ // add a promo code if you have one
87
+ });
88
+
89
+ // open the URL to top-up if in browser
90
+ window.open(url, '_blank');
91
+ } else {
92
+ // otherwise, print the URL to the console
93
+ console.log('Please top up your balance via the CLI before uploading', {
94
+ balance,
95
+ fileSizeCost,
96
+ });
97
+ }
98
+
99
+ // upload the file
100
+ try {
101
+ const { id, owner, dataCaches, fastFinalityIndexes } =
102
+ await turbo.uploadFile({
103
+ fileStreamFactory: () => fs.createReadStream(filePath),
104
+ fileSizeFactory: () => fileSize,
105
+ });
106
+ // upload complete!
107
+ console.log('Successfully upload data item!', {
108
+ id,
109
+ owner,
110
+ dataCaches,
111
+ fastFinalityIndexes,
112
+ });
113
+ } catch (error) {
114
+ // upload failed
115
+ console.error('Failed to upload data item!', error);
116
+ } finally {
117
+ const { winc: newBalance } = await turbo.getBalance();
118
+ console.log('New balance:', newBalance);
119
+ }
163
120
  }
164
121
  ```
165
122
 
@@ -169,24 +126,13 @@ The SDK is provided in both CommonJS and ESM formats, and it's compatible with b
169
126
 
170
127
  ### Web
171
128
 
172
- #### Bundlers (Webpack, Rollup, ESbuild, etc.)
173
-
174
- CommonJS:
175
-
176
- ```javascript
177
- import { TurboFactory } from '@ardrive/turbo-sdk';
178
-
179
- const turbo = TurboFactory.unauthenticated();
180
- const rates = await turbo.getFiatRates();
181
- ```
182
-
183
129
  > [!WARNING]
184
130
  > Polyfills are not provided by default for bundled web projects (Vite, ESBuild, Webpack, Rollup, etc.) . Depending on your apps bundler configuration and plugins, you will need to provide polyfills for various imports including `crypto`, `process`, `fs` and `buffer`. Refer to your bundler's documentation for how to provide the necessary polyfills.
185
131
 
186
- ESM:
132
+ #### Bundlers (Webpack, Rollup, ESbuild, etc.)
187
133
 
188
- ```javascript
189
- import { TurboFactory } from '@ardrive/turbo-sdk/<node/web>';
134
+ ```typescript
135
+ import { TurboFactory } from '@ardrive/turbo-sdk/web';
190
136
 
191
137
  const turbo = TurboFactory.unauthenticated();
192
138
  const rates = await turbo.getFiatRates();
@@ -207,11 +153,25 @@ const rates = await turbo.getFiatRates();
207
153
 
208
154
  #### CommonJS
209
155
 
210
- Example available in the [examples/typescript/cjs].
156
+ Full example available in the [examples/typescript/cjs].
157
+
158
+ ```typescript
159
+ import { TurboFactory } from '@ardrive/turbo-sdk';
160
+
161
+ const turbo = TurboFactory.unauthenticated();
162
+ const rates = await turbo.getFiatRates();
163
+ ```
211
164
 
212
165
  #### ESM
213
166
 
214
- Example available in the [examples/typescript/esm].
167
+ Full example available in the [examples/typescript/esm].
168
+
169
+ ```typescript
170
+ import { TurboFactory } from '@ardrive/turbo-sdk/node';
171
+
172
+ const turbo = TurboFactory.unauthenticated();
173
+ const rates = await turbo.getFiatRates();
174
+ ```
215
175
 
216
176
  ### Typescript
217
177
 
@@ -444,21 +404,12 @@ const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
444
404
  });
445
405
 
446
406
  // Open checkout session in a browser
447
- if (process.platform === 'darwin') {
448
- // macOS
449
- exec(`open ${url}`);
450
- } else if (process.platform === 'win32') {
451
- // Windows
452
- exec(`start "" "${url}"`, { shell: true });
453
- } else {
454
- // Linux/Unix
455
- open(url);
456
- }
407
+ window.open(url, '_blank');
457
408
  ```
458
409
 
459
410
  ##### Ethereum (ETH) Fiat Top Up
460
411
 
461
- ```ts
412
+ ```typescript
462
413
  const turbo = TurboFactory.unauthenticated({ token: 'ethereum' });
463
414
 
464
415
  const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
@@ -469,7 +420,7 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
469
420
 
470
421
  ##### Solana (SOL) Fiat Top Up
471
422
 
472
- ```ts
423
+ ```typescript
473
424
  const turbo = TurboFactory.unauthenticated({ token: 'solana' });
474
425
 
475
426
  const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
@@ -480,7 +431,7 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
480
431
 
481
432
  ##### Polygon (POL / MATIC) Fiat Top Up
482
433
 
483
- ```ts
434
+ ```typescript
484
435
  const turbo = TurboFactory.unauthenticated({ token: 'pol' });
485
436
 
486
437
  const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
@@ -491,7 +442,7 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
491
442
 
492
443
  ##### KYVE Fiat Top Up
493
444
 
494
- ```ts
445
+ ```typescript
495
446
  const turbo = TurboFactory.unauthenticated({ token: 'kyve' });
496
447
 
497
448
  const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
@@ -556,17 +507,8 @@ const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
556
507
  promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
557
508
  });
558
509
 
559
- // Open checkout session in a browser
560
- if (process.platform === 'darwin') {
561
- // macOS
562
- exec(`open ${url}`);
563
- } else if (process.platform === 'win32') {
564
- // Windows
565
- exec(`start "" "${url}"`, { shell: true });
566
- } else {
567
- // Linux/Unix
568
- open(url);
569
- }
510
+ // open checkout session in a browser
511
+ window.open(url, '_blank');
570
512
  ```
571
513
 
572
514
  #### `uploadFile({ fileStreamFactory, fileSizeFactory, signal, dataItemOpts })`
@@ -669,9 +611,19 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
669
611
  });
670
612
  ```
671
613
 
614
+ ##### AR.IO Network (ARIO) Crypto Top Up
615
+
616
+ ```typescript
617
+ const turbo = TurboFactory.authenticated({ signer, token: 'ario' });
618
+
619
+ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
620
+ tokenAmount: ARIOToTokenAmount(100), // 100 $ARIO
621
+ });
622
+ ```
623
+
672
624
  ##### Ethereum (ETH) Crypto Top Up
673
625
 
674
- ```ts
626
+ ```typescript
675
627
  const turbo = TurboFactory.authenticated({ signer, token: 'ethereum' });
676
628
 
677
629
  const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
@@ -681,7 +633,7 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
681
633
 
682
634
  ##### Polygon (POL / MATIC) Crypto Top Up
683
635
 
684
- ```ts
636
+ ```typescript
685
637
  const turbo = TurboFactory.authenticated({ signer, token: 'pol' });
686
638
 
687
639
  const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
@@ -691,7 +643,7 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
691
643
 
692
644
  ##### Eth on Base Network Crypto Top Up
693
645
 
694
- ```ts
646
+ ```typescript
695
647
  const turbo = TurboFactory.authenticated({ signer, token: 'base-eth' });
696
648
 
697
649
  const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
@@ -701,7 +653,7 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
701
653
 
702
654
  ##### Solana (SOL) Crypto Top Up
703
655
 
704
- ```ts
656
+ ```typescript
705
657
  const turbo = TurboFactory.authenticated({ signer, token: 'solana' });
706
658
 
707
659
  const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
@@ -711,7 +663,7 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
711
663
 
712
664
  ##### KYVE Crypto Top Up
713
665
 
714
- ```ts
666
+ ```typescript
715
667
  const turbo = TurboFactory.authenticated({ signer, token: 'kyve' });
716
668
 
717
669
  const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
@@ -754,7 +706,9 @@ const { givenApprovals, receivedApprovals } =
754
706
 
755
707
  ## CLI
756
708
 
757
- ### Install CLI
709
+ <!-- markdownlint-disable MD024 -->
710
+
711
+ ### Installation
758
712
 
759
713
  Global installation:
760
714
 
@@ -780,7 +734,9 @@ or
780
734
  yarn add -D @ardrive/turbo-sdk
781
735
  ```
782
736
 
783
- ### CLI Usage
737
+ <!-- markdownlint-disable MD024 -->
738
+
739
+ ### Usage
784
740
 
785
741
  ```shell
786
742
  turbo --help
@@ -806,6 +762,8 @@ Global options:
806
762
  - `-g, --gateway <url>` - Set a custom crypto gateway URL
807
763
  - `--upload-url <url>` - Set a custom upload service URL
808
764
  - `--payment-url <url>` - Set a custom payment service URL
765
+ - `--cu-url <url>` - Set a custom AO compute unit URL
766
+ - `--process-id <id>` - Set a custom target process ID for AO action
809
767
  - `-t, --token <token>` - Token type for the command or connected wallet (default: "arweave")
810
768
 
811
769
  Wallet options:
@@ -876,6 +834,15 @@ turbo crypto-fund --value 0.0001 --token kyve --private-key 'b27...45c'
876
834
  turbo crypto-fund --tx-id 'my-valid-arweave-fund-transaction-id' --token arweave
877
835
  ```
878
836
 
837
+ ```shell
838
+ turbo crypto-fund --value 100 --token ario --wallet-file ../path/to/arweave/wallet/with/ario.json
839
+ ```
840
+
841
+ ```shell
842
+ # Use a custom AO process ID and compute unit:
843
+ turbo crypto-fund --value 100 --token ario --process-id agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA --cu-url https://cu.ao-testnet.xyz
844
+ ```
845
+
879
846
  ##### `upload-folder`
880
847
 
881
848
  Upload a folder of files and create and upload a manifest file for the folder upload to the Turbo Upload Service.