@ardrive/turbo-sdk 1.19.2 → 1.20.0-alpha.2

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 (67) hide show
  1. package/README.md +123 -1
  2. package/bundles/web.bundle.min.js +148 -14
  3. package/lib/cjs/cli/cli.js +18 -0
  4. package/lib/cjs/cli/commands/balance.js +26 -15
  5. package/lib/cjs/cli/commands/cryptoFund.js +3 -1
  6. package/lib/cjs/cli/commands/listShares.js +58 -0
  7. package/lib/cjs/cli/commands/price.js +2 -1
  8. package/lib/cjs/cli/commands/revokeCredits.js +15 -0
  9. package/lib/cjs/cli/commands/shareCredits.js +39 -0
  10. package/lib/cjs/cli/commands/uploadFile.js +2 -1
  11. package/lib/cjs/cli/commands/uploadFolder.js +2 -1
  12. package/lib/cjs/cli/constants.js +2 -1
  13. package/lib/cjs/cli/options.js +43 -4
  14. package/lib/cjs/cli/utils.js +31 -0
  15. package/lib/cjs/common/payment.js +30 -4
  16. package/lib/cjs/common/token/solana.js +2 -2
  17. package/lib/cjs/common/turbo.js +31 -2
  18. package/lib/cjs/common/upload.js +73 -6
  19. package/lib/cjs/version.js +1 -1
  20. package/lib/esm/cli/cli.js +19 -1
  21. package/lib/esm/cli/commands/balance.js +26 -15
  22. package/lib/esm/cli/commands/cryptoFund.js +3 -1
  23. package/lib/esm/cli/commands/listShares.js +55 -0
  24. package/lib/esm/cli/commands/price.js +2 -1
  25. package/lib/esm/cli/commands/revokeCredits.js +12 -0
  26. package/lib/esm/cli/commands/shareCredits.js +36 -0
  27. package/lib/esm/cli/commands/uploadFile.js +3 -2
  28. package/lib/esm/cli/commands/uploadFolder.js +3 -2
  29. package/lib/esm/cli/constants.js +1 -0
  30. package/lib/esm/cli/options.js +42 -3
  31. package/lib/esm/cli/utils.js +30 -0
  32. package/lib/esm/common/payment.js +30 -4
  33. package/lib/esm/common/token/solana.js +2 -2
  34. package/lib/esm/common/turbo.js +31 -2
  35. package/lib/esm/common/upload.js +72 -5
  36. package/lib/esm/version.js +1 -1
  37. package/lib/types/cli/commands/balance.d.ts.map +1 -1
  38. package/lib/types/cli/commands/cryptoFund.d.ts.map +1 -1
  39. package/lib/types/cli/commands/listShares.d.ts +3 -0
  40. package/lib/types/cli/commands/listShares.d.ts.map +1 -0
  41. package/lib/types/cli/commands/price.d.ts.map +1 -1
  42. package/lib/types/cli/commands/revokeCredits.d.ts +18 -0
  43. package/lib/types/cli/commands/revokeCredits.d.ts.map +1 -0
  44. package/lib/types/cli/commands/shareCredits.d.ts +3 -0
  45. package/lib/types/cli/commands/shareCredits.d.ts.map +1 -0
  46. package/lib/types/cli/commands/uploadFile.d.ts.map +1 -1
  47. package/lib/types/cli/commands/uploadFolder.d.ts.map +1 -1
  48. package/lib/types/cli/constants.d.ts +1 -0
  49. package/lib/types/cli/constants.d.ts.map +1 -1
  50. package/lib/types/cli/options.d.ts +121 -2
  51. package/lib/types/cli/options.d.ts.map +1 -1
  52. package/lib/types/cli/types.d.ts +17 -2
  53. package/lib/types/cli/types.d.ts.map +1 -1
  54. package/lib/types/cli/utils.d.ts +2 -1
  55. package/lib/types/cli/utils.d.ts.map +1 -1
  56. package/lib/types/common/payment.d.ts +8 -2
  57. package/lib/types/common/payment.d.ts.map +1 -1
  58. package/lib/types/common/token/solana.d.ts.map +1 -1
  59. package/lib/types/common/turbo.d.ts +27 -2
  60. package/lib/types/common/turbo.d.ts.map +1 -1
  61. package/lib/types/common/upload.d.ts +9 -1
  62. package/lib/types/common/upload.d.ts.map +1 -1
  63. package/lib/types/types.d.ts +54 -3
  64. package/lib/types/types.d.ts.map +1 -1
  65. package/lib/types/utils/axiosClient.d.ts.map +1 -1
  66. package/lib/types/version.d.ts +1 -1
  67. package/package.json +4 -3
package/README.md CHANGED
@@ -65,6 +65,9 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
65
65
  - [Polygon (POL / MATIC) Crypto Top Up](#polygon-pol--matic-crypto-top-up)
66
66
  - [Solana (SOL) Crypto Top Up](#solana-sol-crypto-top-up)
67
67
  - [KYVE Crypto Top Up](#kyve-crypto-top-up)
68
+ - [`shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })`](#sharecredits-approvedaddress-approvedwincamount-expiresbyseconds-)
69
+ - [`revokeCredits({ approvedAddress })`](#revokecredits-approvedaddress-)
70
+ - [`getCreditShareApprovals({ userAddress })`](#getcreditshareapprovals-useraddress-)
68
71
  - [CLI](#cli)
69
72
  - [Install CLI](#install-cli)
70
73
  - [CLI Usage](#cli-usage)
@@ -76,6 +79,10 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
76
79
  - [`upload-folder`](#upload-folder)
77
80
  - [`upload-file`](#upload-file)
78
81
  - [`price`](#price)
82
+ - [`share-credits`](#share-credits)
83
+ - [`revoke-credits`](#revoke-credits)
84
+ - [`list-shares`](#list-shares)
85
+ - [Turbo Credit Sharing](#turbo-credit-sharing)
79
86
  - [Developers](#developers)
80
87
  - [Requirements](#requirements)
81
88
  - [Setup & Build](#setup--build)
@@ -677,6 +684,39 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
677
684
  });
678
685
  ```
679
686
 
687
+ #### `shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })`
688
+
689
+ Shares credits from the connected wallet to the provided native address and approved winc amount. This action will create a signed data item for the approval
690
+
691
+ ```typescript
692
+ const { approvalDataItemId, approvedWincAmount } = await turbo.shareCredits({
693
+ approvedAddress: '2cor...VUa',
694
+ approvedWincAmount: 0.08315565032,
695
+ expiresBySeconds: 3600,
696
+ });
697
+ ```
698
+
699
+ #### `revokeCredits({ approvedAddress })`
700
+
701
+ Revokes all credits shared from the connected wallet to the provided native address.
702
+
703
+ ```typescript
704
+ const revokedApprovals = await turbo.revokeCredits({
705
+ approvedAddress: '2cor...VUa',
706
+ });
707
+ ```
708
+
709
+ #### `getCreditShareApprovals({ userAddress })`
710
+
711
+ Returns all given or received credit share approvals for the connected wallet or the provided native address.
712
+
713
+ ```typescript
714
+ const { givenApprovals, receivedApprovals } =
715
+ await turbo.getCreditShareApprovals({
716
+ userAddress: '2cor...VUa',
717
+ });
718
+ ```
719
+
680
720
  ## CLI
681
721
 
682
722
  ### Install CLI
@@ -723,6 +763,8 @@ npx turbo --help
723
763
 
724
764
  #### Options
725
765
 
766
+ Global options:
767
+
726
768
  - `-V, --version` - output the version number
727
769
  - `-h, --help` - display help for command
728
770
  - `--dev` - Enable development endpoints (default: false)
@@ -731,10 +773,18 @@ npx turbo --help
731
773
  - `--payment-url <url>` - Set a custom payment service URL
732
774
  - `-t, --token <token>` - Token type for the command or connected wallet (default: "arweave")
733
775
 
776
+ Wallet options:
777
+
734
778
  - `-w, --wallet-file <filePath>` - Wallet file to use with the action. Formats accepted: JWK.json, KYVE, ETH, or POL private key as a string, or SOL Secret Key as a Uint8Array
735
779
  - `-m, --mnemonic <phrase>` - Mnemonic to use with the action (KYVE only)
736
780
  - `-p, --private-key <key>` - Private key to use with the action
737
781
 
782
+ Upload options:
783
+
784
+ - `--paid-by <paidBy...>` - A list of native addresses to pay for the upload.
785
+ - `--ignore-approvals` - When no paid by is provided, the CLI will look for and use any received credit share approvals to pay for the upload. This flag will ignore any approvals and only use the connected wallet's balance for upload payment. Default: false
786
+ - `--use-signer-balance-first` - Use the connected wallet's balance before using any credit share approvals for the upload. Default: false
787
+
738
788
  #### Commands
739
789
 
740
790
  ##### `balance`
@@ -820,7 +870,7 @@ Command Options:
820
870
  e.g:
821
871
 
822
872
  ```shell
823
- turbo upload-file --file-path '../path/to/my/file.txt' --token ethereum --wallet-file ../path/to/eth/private/key.txt
873
+ turbo upload-file --file-path '../path/to/my/file.txt' --token ethereum --wallet-file ../path/to/eth/private/key.txt --paid-by '0x...first-payer-address' '0x...second-payer-address' '0x...third-payer-address' 'etc...'
824
874
  ```
825
875
 
826
876
  ##### `price`
@@ -846,6 +896,78 @@ turbo price --value 1024 --type bytes
846
896
  turbo price --value 1.1 --type arweave
847
897
  ```
848
898
 
899
+ ##### `share-credits`
900
+
901
+ Shares credits from the connected wallet to the provided native address and approved winc amount.
902
+
903
+ Command Options:
904
+
905
+ - `-a, --address <nativeAddress>` - Native address to that will receive the Credits
906
+ - `-v, --value <value>` - Value of winc to share to the target address
907
+ - `-e, --expires-by-seconds <seconds>` - Expiry time in seconds for the credit share approval
908
+
909
+ e.g:
910
+
911
+ ```shell
912
+ turbo share-credits --address 2cor...VUa --value 0.083155650320 --wallet-file ../path/to/my/wallet --expires-by-seconds 3600
913
+ ```
914
+
915
+ ##### `revoke-credits`
916
+
917
+ Revoke all credits shared from the connected wallet to the provided native address.
918
+
919
+ Command Options:
920
+
921
+ - `-a, --address <nativeAddress>` - Native address to revoke credit share approvals for
922
+
923
+ e.g:
924
+
925
+ ```shell
926
+ turbo revoke-credits --wallet-file ../path/to/my/wallet
927
+ ```
928
+
929
+ ##### `list-shares`
930
+
931
+ List all given and received credit share approvals from the connected wallet or the provided native address.
932
+
933
+ Command Options:
934
+
935
+ - `-a, --address <nativeAddress>` - Native address to list credit share approvals for
936
+
937
+ e.g:
938
+
939
+ ```shell
940
+ turbo list-shares --address 2cor...VUa --wallet-file ../path/to/my/wallet
941
+ ```
942
+
943
+ ## Turbo Credit Sharing
944
+
945
+ Users can share their purchased Credits with other user's wallets by creating Credit Share Approvals. These approvals are created by uploading a signed data item with tags indicating the recipient's wallet address, the amount of Credits to share, and an optional amount of seconds that the approval will expire in. The recipient can then use the shared Credits to pay for their own uploads to Turbo.
946
+
947
+ Shared Credits cannot be re-shared by the recipient to other recipients. Only the owner of the Credits can share or revoke Credit Share Approvals. Credits that are shared to other wallets may not be used by the original owner of the Credits for sharing or uploading unless the Credit Share Approval is revoked or expired.
948
+
949
+ Approvals can be revoked at any time by similarly uploading a signed data item with tags indicating the recipient's wallet address. This will remove all approvals and prevent the recipient from using the shared Credits. All unused Credits from expired or revoked approvals are returned to the original owner of the Credits.
950
+
951
+ To use the shared Credits, recipient users must provide the wallet address of the user who shared the Credits with them in the `x-paid-by` HTTP header when uploading data. This tells Turbo services to look for and use Credit Share Approvals to pay for the upload before using the signer's balance.
952
+
953
+ For user convenience, during upload the Turbo CLI will use any available Credit Share Approvals found for the connected wallet before using the signing wallet's balance. To instead ignore all Credit shares and only use the signer's balance, use the `--ignore-approvals` flag. To use the signer's balance first before using Credit shares, use the `--use-signer-balance-first` flag. The Turbo SDK layer does not provide this functionality and will always use the signer's balance unless `paidBy` is provided.
954
+
955
+ The Turbo SDK provides the following methods to manage Credit Share Approvals:
956
+
957
+ - `shareCredits`: Creates a Credit Share Approval for the specified wallet address and amount of Credits.
958
+ - `revokeCredits`: Revokes all Credit Share Approvals for the specified wallet address.
959
+ - `listShares`: Lists all Credit Share Approvals for the specified wallet address or connected wallet.
960
+ - `dataItemOpts: { ...opts, paidBy: string[] }`: Upload methods now accept an array of wallet addresses to pay for the upload.
961
+
962
+ The Turbo CLI provides the following commands to manage Credit Share Approvals:
963
+
964
+ - `share-credits`: Creates a Credit Share Approval for the specified wallet address and amount of Credits.
965
+ - `revoke-credits`: Revokes all Credit Share Approvals for the specified wallet address.
966
+ - `list-shares`: Lists all Credit Share Approvals for the specified wallet address or connected wallet.
967
+ - `paidBy: --paid-by <paidBy...>`: Upload commands now accept an array of wallet addresses to pay for the upload.
968
+ - `--ignore-approvals`: Ignore all Credit Share Approvals and only use the signer's balance.
969
+ - `--use-signer-balance-first`: Use the signer's balance first before using Credit Share Approvals.
970
+
849
971
  ## Developers
850
972
 
851
973
  ### Requirements
@@ -310551,7 +310551,7 @@ var import_winston = __toESM(require_winston(), 1);
310551
310551
  init_dirname();
310552
310552
  init_buffer2();
310553
310553
  init_process2();
310554
- var version16 = "1.19.2-alpha.1";
310554
+ var version16 = "1.20.0-alpha.1";
310555
310555
 
310556
310556
  // src/common/logger.ts
310557
310557
  var TurboWinstonLogger = class _TurboWinstonLogger {
@@ -314755,7 +314755,13 @@ var TurboUnauthenticatedPaymentService = class {
314755
314755
  endpoint: `/account/balance/${this.token}?address=${address}`,
314756
314756
  allowedStatuses: [200, 404]
314757
314757
  });
314758
- return balance.winc ? balance : { winc: "0" };
314758
+ return balance.winc ? balance : {
314759
+ winc: "0",
314760
+ controlledWinc: "0",
314761
+ effectiveBalance: "0",
314762
+ givenApprovals: [],
314763
+ receivedApprovals: []
314764
+ };
314759
314765
  }
314760
314766
  getFiatRates() {
314761
314767
  return this.httpService.get({
@@ -314891,6 +314897,21 @@ var TurboUnauthenticatedPaymentService = class {
314891
314897
  }
314892
314898
  throw new Error("Unknown response from payment service: " + response);
314893
314899
  }
314900
+ async getCreditShareApprovals({
314901
+ userAddress
314902
+ }) {
314903
+ const response = await this.httpService.get({
314904
+ endpoint: `/account/approvals/get?userAddress=${userAddress}`,
314905
+ allowedStatuses: [200, 404]
314906
+ });
314907
+ if (response?.givenApprovals === void 0 && response?.receivedApprovals === void 0) {
314908
+ return {
314909
+ givenApprovals: [],
314910
+ receivedApprovals: []
314911
+ };
314912
+ }
314913
+ return response;
314914
+ }
314894
314915
  };
314895
314916
  var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPaymentService {
314896
314917
  constructor({
@@ -314905,9 +314926,15 @@ var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPayment
314905
314926
  this.signer = signer;
314906
314927
  this.tokenTools = tokenTools;
314907
314928
  }
314908
- async getBalance(address) {
314909
- address ??= await this.signer.getNativeAddress();
314910
- return super.getBalance(address);
314929
+ async getBalance(userAddress) {
314930
+ userAddress ??= await this.signer.getNativeAddress();
314931
+ return super.getBalance(userAddress);
314932
+ }
314933
+ async getCreditShareApprovals({
314934
+ userAddress
314935
+ }) {
314936
+ userAddress ??= await this.signer.getNativeAddress();
314937
+ return super.getCreditShareApprovals({ userAddress });
314911
314938
  }
314912
314939
  async getWincForFiat({
314913
314940
  amount,
@@ -349391,7 +349418,9 @@ var SolanaToken = class {
349391
349418
  tokenAmount,
349392
349419
  signer
349393
349420
  }) {
349394
- const publicKey2 = new PublicKey(import_bs583.default.encode(await signer.getPublicKey()));
349421
+ const publicKey2 = new PublicKey(
349422
+ import_bs583.default.encode(Uint8Array.from(await signer.getPublicKey()))
349423
+ );
349395
349424
  const tx = new Transaction2({
349396
349425
  feePayer: publicKey2,
349397
349426
  ...await this.connection.getLatestBlockhash()
@@ -349404,7 +349433,7 @@ var SolanaToken = class {
349404
349433
  })
349405
349434
  );
349406
349435
  const serializedTx = tx.serializeMessage();
349407
- const signature2 = await signer.signData(serializedTx);
349436
+ const signature2 = await signer.signData(Uint8Array.from(serializedTx));
349408
349437
  tx.addSignature(publicKey2, Buffer.from(signature2));
349409
349438
  const id3 = import_bs583.default.encode(signature2);
349410
349439
  await this.submitTx(tx, id3);
@@ -349498,6 +349527,7 @@ init_dirname();
349498
349527
  init_buffer2();
349499
349528
  init_process2();
349500
349529
  init_buffer();
349530
+ init_stream();
349501
349531
 
349502
349532
  // node_modules/plimit-lit/dist/index.js
349503
349533
  init_dirname();
@@ -349622,6 +349652,12 @@ function pLimit(concurrency) {
349622
349652
  }
349623
349653
 
349624
349654
  // src/common/upload.ts
349655
+ var creditSharingTagNames = {
349656
+ shareCredits: "x-approve-payment",
349657
+ sharedWincAmount: "x-amount",
349658
+ approvalExpiresBySeconds: "x-expires-seconds",
349659
+ revokeCredits: "x-delete-payment-approval"
349660
+ };
349625
349661
  var developmentUploadServiceURL = "https://upload.ardrive.dev";
349626
349662
  var defaultUploadServiceURL = "https://upload.ardrive.io";
349627
349663
  var TurboUnauthenticatedUploadService = class {
@@ -349680,16 +349716,22 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
349680
349716
  dataItemOpts
349681
349717
  });
349682
349718
  const signedDataItem = dataItemStreamFactory();
349683
- const fileSize = dataItemSizeFactory();
349684
349719
  this.logger.debug("Uploading signed data item...");
349720
+ const headers = {
349721
+ "content-type": "application/octet-stream",
349722
+ "content-length": `${dataItemSizeFactory()}`
349723
+ };
349724
+ if (dataItemOpts !== void 0 && dataItemOpts.paidBy !== void 0) {
349725
+ const paidBy = Array.isArray(dataItemOpts.paidBy) ? dataItemOpts.paidBy : [dataItemOpts.paidBy];
349726
+ if (dataItemOpts.paidBy.length > 0) {
349727
+ headers["x-paid-by"] = paidBy;
349728
+ }
349729
+ }
349685
349730
  return this.httpService.post({
349686
349731
  endpoint: `/tx/${this.token}`,
349687
349732
  signal,
349688
349733
  data: signedDataItem,
349689
- headers: {
349690
- "content-type": "application/octet-stream",
349691
- "content-length": `${fileSize}`
349692
- }
349734
+ headers
349693
349735
  });
349694
349736
  }
349695
349737
  async generateManifest({
@@ -349814,6 +349856,68 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
349814
349856
  manifestResponse
349815
349857
  };
349816
349858
  }
349859
+ async shareCredits({
349860
+ approvedAddress,
349861
+ approvedWincAmount,
349862
+ expiresBySeconds
349863
+ }) {
349864
+ const dataItemOpts = {
349865
+ tags: [
349866
+ {
349867
+ name: creditSharingTagNames.shareCredits,
349868
+ value: approvedAddress
349869
+ },
349870
+ {
349871
+ name: creditSharingTagNames.sharedWincAmount,
349872
+ value: approvedWincAmount.toString()
349873
+ }
349874
+ ]
349875
+ };
349876
+ if (expiresBySeconds !== void 0) {
349877
+ dataItemOpts.tags.push({
349878
+ name: creditSharingTagNames.approvalExpiresBySeconds,
349879
+ value: expiresBySeconds.toString()
349880
+ });
349881
+ }
349882
+ const nonceData = Buffer.from(
349883
+ approvedAddress + approvedWincAmount + Date.now()
349884
+ );
349885
+ const { createdApproval, ...uploadResponse } = await this.uploadFile({
349886
+ fileStreamFactory: () => Readable.from(nonceData),
349887
+ fileSizeFactory: () => nonceData.byteLength,
349888
+ dataItemOpts
349889
+ });
349890
+ if (!createdApproval) {
349891
+ throw new Error(
349892
+ "Failed to create credit share approval but upload has succeeded\n" + JSON.stringify(uploadResponse)
349893
+ );
349894
+ }
349895
+ return createdApproval;
349896
+ }
349897
+ async revokeCredits({
349898
+ revokedAddress
349899
+ }) {
349900
+ const dataItemOpts = {
349901
+ tags: [
349902
+ {
349903
+ name: creditSharingTagNames.revokeCredits,
349904
+ value: revokedAddress
349905
+ }
349906
+ ]
349907
+ };
349908
+ const nonceData = Buffer.from(revokedAddress + Date.now());
349909
+ const { revokedApprovals, ...uploadResponse } = await this.uploadFile({
349910
+ fileStreamFactory: () => Readable.from(nonceData),
349911
+ fileSizeFactory: () => nonceData.byteLength,
349912
+ dataItemOpts
349913
+ });
349914
+ if (!revokedApprovals) {
349915
+ throw new Error(
349916
+ "Failed to revoke credit share approvals but upload has succeeded\n" + JSON.stringify(uploadResponse)
349917
+ );
349918
+ }
349919
+ return revokedApprovals;
349920
+ }
349817
349921
  };
349818
349922
 
349819
349923
  // src/common/turbo.ts
@@ -349927,6 +350031,12 @@ var TurboUnauthenticatedClient = class {
349927
350031
  wallets.pol = wallets.matic;
349928
350032
  return wallets;
349929
350033
  }
350034
+ /**
350035
+ * Returns a list of all credit share approvals for the user.
350036
+ */
350037
+ getCreditShareApprovals(p8) {
350038
+ return this.paymentService.getCreditShareApprovals(p8);
350039
+ }
349930
350040
  };
349931
350041
  var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
349932
350042
  constructor({
@@ -349940,8 +350050,14 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
349940
350050
  /**
349941
350051
  * Returns the current balance of the user's wallet in 'winc'.
349942
350052
  */
349943
- getBalance(address) {
349944
- return this.paymentService.getBalance(address);
350053
+ getBalance(userAddress) {
350054
+ return this.paymentService.getBalance(userAddress);
350055
+ }
350056
+ /**
350057
+ * Returns a list of all credit share approvals for the user.
350058
+ */
350059
+ getCreditShareApprovals(p8 = {}) {
350060
+ return this.paymentService.getCreditShareApprovals(p8);
349945
350061
  }
349946
350062
  /**
349947
350063
  * Signs and uploads raw data to the Turbo Upload Service.
@@ -349969,6 +350085,23 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
349969
350085
  topUpWithTokens(p8) {
349970
350086
  return this.paymentService.topUpWithTokens(p8);
349971
350087
  }
350088
+ /**
350089
+ * Creates a data item with tags that designate it as a credit share approval.
350090
+ * Signs the data item and sends it to the Turbo Upload Service, which will verify
350091
+ * the signature and forward the admin action towards the Turbo Payment Service.
350092
+ */
350093
+ shareCredits(p8) {
350094
+ return this.uploadService.shareCredits(p8);
350095
+ }
350096
+ /**
350097
+ * Creates a data item with tags that designate it as a revoke action for credit
350098
+ * share approvals for target revokedAddress. Signs the data item and sends it to
350099
+ * the Turbo Upload Service, which will verify the signature and forward the admin
350100
+ * action towards the Turbo Payment Service.
350101
+ */
350102
+ revokeCredits(p8) {
350103
+ return this.uploadService.revokeCredits(p8);
350104
+ }
349972
350105
  };
349973
350106
 
349974
350107
  // src/common/factory.ts
@@ -350504,6 +350637,7 @@ export {
350504
350637
  USD,
350505
350638
  WinstonToTokenAmount,
350506
350639
  ZeroDecimalCurrency,
350640
+ creditSharingTagNames,
350507
350641
  currencyMap,
350508
350642
  defaultPaymentServiceURL,
350509
350643
  defaultTokenMap,
@@ -21,6 +21,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  const commander_1 = require("commander");
22
22
  const version_js_1 = require("../version.js");
23
23
  const index_js_1 = require("./commands/index.js");
24
+ const listShares_js_1 = require("./commands/listShares.js");
25
+ const revokeCredits_js_1 = require("./commands/revokeCredits.js");
26
+ const shareCredits_js_1 = require("./commands/shareCredits.js");
24
27
  const options_js_1 = require("./options.js");
25
28
  const utils_js_1 = require("./utils.js");
26
29
  (0, utils_js_1.applyOptions)(commander_1.program
@@ -48,6 +51,21 @@ const utils_js_1 = require("./utils.js");
48
51
  .description('Get the current Credits estimate for byte, crypto, or fiat value'), [options_js_1.optionMap.value, options_js_1.optionMap.type]).action(async (_commandOptions, command) => {
49
52
  await (0, utils_js_1.runCommand)(command, index_js_1.price);
50
53
  });
54
+ (0, utils_js_1.applyOptions)(commander_1.program
55
+ .command('share-credits')
56
+ .description('Create a Turbo credit share approval'), options_js_1.shareCreditsOptions).action(async (_commandOptions, command) => {
57
+ await (0, utils_js_1.runCommand)(command, shareCredits_js_1.shareCredits);
58
+ });
59
+ (0, utils_js_1.applyOptions)(commander_1.program
60
+ .command('revoke-credits')
61
+ .description('Revokes all Turbo credit share approvals for given address'), options_js_1.revokeCreditsOptions).action(async (_commandOptions, command) => {
62
+ await (0, utils_js_1.runCommand)(command, revokeCredits_js_1.revokeCredits);
63
+ });
64
+ (0, utils_js_1.applyOptions)(commander_1.program
65
+ .command('list-shares')
66
+ .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), options_js_1.listSharesOptions).action(async (_commandOptions, command) => {
67
+ await (0, utils_js_1.runCommand)(command, listShares_js_1.listShares);
68
+ });
51
69
  if (process.argv[1].includes('bin/turbo') || // Running from global .bin
52
70
  process.argv[1].includes('cli/cli') // Running from source
53
71
  ) {
@@ -16,24 +16,35 @@ exports.balance = balance;
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
+ const bignumber_js_1 = require("bignumber.js");
19
20
  const factory_js_1 = require("../../node/factory.js");
21
+ const constants_js_1 = require("../constants.js");
20
22
  const utils_js_1 = require("../utils.js");
21
23
  async function balance(options) {
22
24
  const config = (0, utils_js_1.configFromOptions)(options);
23
25
  const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
24
- if (address !== undefined) {
25
- const turbo = factory_js_1.TurboFactory.unauthenticated(config);
26
- const { winc } = await turbo.getBalance(address);
27
- console.log(`Turbo Balance for Native Address "${address}"\nCredits: ${+winc / 1_000_000_000_000}`);
28
- return;
29
- }
30
- if (privateKey === undefined) {
31
- throw new Error('Must provide an (--address) or use a valid wallet');
32
- }
33
- const turbo = factory_js_1.TurboFactory.authenticated({
34
- ...config,
35
- privateKey,
36
- });
37
- const { winc } = await turbo.getBalance();
38
- console.log(`Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${+winc / 1_000_000_000_000}`);
26
+ const { effectiveBalance, nativeAddress, winc, controlledWinc } = await (async () => {
27
+ if (address !== undefined) {
28
+ return {
29
+ ...(await factory_js_1.TurboFactory.unauthenticated(config).getBalance(address)),
30
+ nativeAddress: address,
31
+ };
32
+ }
33
+ if (privateKey === undefined) {
34
+ throw new Error('Must provide an (--address) or use a valid wallet');
35
+ }
36
+ const turbo = factory_js_1.TurboFactory.authenticated({
37
+ ...config,
38
+ privateKey,
39
+ });
40
+ return {
41
+ ...(await turbo.getBalance()),
42
+ nativeAddress: await turbo.signer.getNativeAddress(),
43
+ };
44
+ })();
45
+ console.log(`Turbo Balance for Native Address "${nativeAddress}"\nEffective Credits: ${+effectiveBalance / constants_js_1.wincPerCredit}${winc === controlledWinc
46
+ ? ''
47
+ : `\nCredits Shared to Other Wallets: ${(0, bignumber_js_1.BigNumber)(controlledWinc)
48
+ .minus(winc)
49
+ .div(constants_js_1.wincPerCredit)}`}`);
39
50
  }
@@ -19,9 +19,11 @@ exports.cryptoFund = cryptoFund;
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ const bignumber_js_1 = require("bignumber.js");
22
23
  const prompts_1 = __importDefault(require("prompts"));
23
24
  const index_js_1 = require("../../common/index.js");
24
25
  const factory_js_1 = require("../../node/factory.js");
26
+ const constants_js_1 = require("../constants.js");
25
27
  const utils_js_1 = require("../utils.js");
26
28
  async function cryptoFund(options) {
27
29
  const value = options.value;
@@ -41,7 +43,7 @@ async function cryptoFund(options) {
41
43
  if (!options.skipConfirmation) {
42
44
  const { winc } = await turbo.getWincForToken({ tokenAmount });
43
45
  const targetWallet = (await turbo.getTurboCryptoWallets())[token];
44
- const credits = (+winc / 1_000_000_000_000).toFixed(12);
46
+ const credits = (0, bignumber_js_1.BigNumber)(winc).dividedBy(constants_js_1.wincPerCredit).toFixed(12);
45
47
  const { confirm } = await (0, prompts_1.default)({
46
48
  type: 'confirm',
47
49
  name: 'confirm',
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listShares = listShares;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const factory_js_1 = require("../../node/factory.js");
20
+ const utils_js_1 = require("../utils.js");
21
+ async function listShares(options) {
22
+ const config = (0, utils_js_1.configFromOptions)(options);
23
+ const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
24
+ const { givenApprovals, receivedApprovals, nativeAddress } = await (async () => {
25
+ if (address !== undefined) {
26
+ const approvals = await factory_js_1.TurboFactory.unauthenticated(config).getCreditShareApprovals({
27
+ userAddress: address,
28
+ });
29
+ return { ...approvals, nativeAddress: address };
30
+ }
31
+ if (privateKey === undefined) {
32
+ throw new Error('Must provide an (--address) or use a valid wallet');
33
+ }
34
+ const turbo = factory_js_1.TurboFactory.authenticated({
35
+ ...config,
36
+ privateKey,
37
+ });
38
+ const approvals = await turbo.getCreditShareApprovals();
39
+ return {
40
+ ...approvals,
41
+ nativeAddress: await turbo.signer.getNativeAddress(),
42
+ };
43
+ })();
44
+ const hasApprovals = givenApprovals?.length === 0 && receivedApprovals?.length === 0;
45
+ const body = {
46
+ message: `${hasApprovals ? 'No ' : ''}` +
47
+ `Credit Share Approvals found for native address '${nativeAddress}'`,
48
+ givenApprovals,
49
+ receivedApprovals,
50
+ };
51
+ if (givenApprovals?.length > 0) {
52
+ body['givenApprovals'] = givenApprovals;
53
+ }
54
+ if (receivedApprovals?.length > 0) {
55
+ body['receivedApprovals'] = receivedApprovals;
56
+ }
57
+ console.log(JSON.stringify(body, null, 2));
58
+ }
@@ -20,6 +20,7 @@ const currency_js_1 = require("../../common/currency.js");
20
20
  const index_js_1 = require("../../common/index.js");
21
21
  const factory_js_1 = require("../../node/factory.js");
22
22
  const types_js_1 = require("../../types.js");
23
+ const constants_js_1 = require("../constants.js");
23
24
  const utils_js_1 = require("../utils.js");
24
25
  async function price(options) {
25
26
  const value = options.value;
@@ -48,5 +49,5 @@ async function price(options) {
48
49
  }
49
50
  throw new Error(`Invalid price type!\nMust be one of: bytes, ${types_js_1.fiatCurrencyTypes.join(', ') + ' ' + types_js_1.tokenTypes.join(', ')}`);
50
51
  })();
51
- console.log(`Current price estimate for ${value} ${type} is ~${(+winc / 1_000_000_000_000).toFixed(12)} Credits`);
52
+ console.log(`Current price estimate for ${value} ${type} is ~${(+winc / constants_js_1.wincPerCredit).toFixed(12)} Credits`);
52
53
  }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.revokeCredits = revokeCredits;
4
+ const utils_js_1 = require("../utils.js");
5
+ async function revokeCredits(options) {
6
+ const { address: revokedAddress } = options;
7
+ if (revokedAddress === undefined) {
8
+ throw new Error('Must provide an approved --address to revoke approvals for');
9
+ }
10
+ const turbo = await (0, utils_js_1.turboFromOptions)(options);
11
+ const revokedApprovals = await turbo.revokeCredits({
12
+ revokedAddress,
13
+ });
14
+ console.log(JSON.stringify({ message: 'Revoked credit share approvals!', revokedApprovals }, null, 2));
15
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shareCredits = shareCredits;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const bignumber_js_1 = require("bignumber.js");
20
+ const utils_js_1 = require("../utils.js");
21
+ async function shareCredits(options) {
22
+ const { address: approvedAddress, value: creditAmount, expiresBySeconds, } = options;
23
+ if (approvedAddress === undefined) {
24
+ throw new Error('Must provide an approved --address to create approval for');
25
+ }
26
+ if (creditAmount === undefined) {
27
+ throw new Error('Must provide a credit --value to create approval for');
28
+ }
29
+ const turbo = await (0, utils_js_1.turboFromOptions)(options);
30
+ const approvedWincAmount = new bignumber_js_1.BigNumber(creditAmount)
31
+ .shiftedBy(12)
32
+ .toFixed(0);
33
+ const result = await turbo.shareCredits({
34
+ approvedAddress,
35
+ approvedWincAmount,
36
+ expiresBySeconds,
37
+ });
38
+ console.log(JSON.stringify({ message: 'Created credit share approval!', ...result }, null, 2));
39
+ }