@ardrive/turbo-sdk 1.20.0-alpha.1 → 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.
- package/README.md +66 -38
- package/bundles/web.bundle.min.js +38 -33
- package/lib/cjs/cli/cli.js +12 -12
- package/lib/cjs/cli/commands/{listApprovals.js → listShares.js} +6 -6
- package/lib/cjs/cli/commands/{revokeApprovals.js → revokeCredits.js} +4 -4
- package/lib/cjs/cli/commands/{createApproval.js → shareCredits.js} +4 -4
- package/lib/cjs/cli/options.js +6 -6
- package/lib/cjs/common/payment.js +3 -3
- package/lib/cjs/common/turbo.js +13 -13
- package/lib/cjs/common/upload.js +21 -13
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +13 -13
- package/lib/esm/cli/commands/{listApprovals.js → listShares.js} +5 -5
- package/lib/esm/cli/commands/{revokeApprovals.js → revokeCredits.js} +3 -3
- package/lib/esm/cli/commands/{createApproval.js → shareCredits.js} +3 -3
- package/lib/esm/cli/options.js +5 -5
- package/lib/esm/common/payment.js +3 -3
- package/lib/esm/common/turbo.js +13 -13
- package/lib/esm/common/upload.js +20 -12
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/listShares.d.ts +3 -0
- package/lib/types/cli/commands/listShares.d.ts.map +1 -0
- package/lib/types/cli/commands/{revokeApprovals.d.ts → revokeCredits.d.ts} +3 -3
- package/lib/types/cli/commands/revokeCredits.d.ts.map +1 -0
- package/lib/types/cli/commands/shareCredits.d.ts +3 -0
- package/lib/types/cli/commands/shareCredits.d.ts.map +1 -0
- package/lib/types/cli/options.d.ts +11 -11
- package/lib/types/cli/options.d.ts.map +1 -1
- package/lib/types/cli/types.d.ts +3 -3
- package/lib/types/cli/types.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts +5 -5
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +12 -12
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +9 -7
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/types.d.ts +16 -16
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/axiosClient.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/lib/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/types/cli/commands/createApproval.d.ts +0 -3
- package/lib/types/cli/commands/createApproval.d.ts.map +0 -1
- package/lib/types/cli/commands/listApprovals.d.ts +0 -3
- package/lib/types/cli/commands/listApprovals.d.ts.map +0 -1
- package/lib/types/cli/commands/revokeApprovals.d.ts.map +0 -1
package/README.md
CHANGED
@@ -65,9 +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
|
-
- [`
|
69
|
-
- [`
|
70
|
-
- [`
|
68
|
+
- [`shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })`](#sharecredits-approvedaddress-approvedwincamount-expiresbyseconds-)
|
69
|
+
- [`revokeCredits({ approvedAddress })`](#revokecredits-approvedaddress-)
|
70
|
+
- [`getCreditShareApprovals({ userAddress })`](#getcreditshareapprovals-useraddress-)
|
71
71
|
- [CLI](#cli)
|
72
72
|
- [Install CLI](#install-cli)
|
73
73
|
- [CLI Usage](#cli-usage)
|
@@ -79,9 +79,10 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
79
79
|
- [`upload-folder`](#upload-folder)
|
80
80
|
- [`upload-file`](#upload-file)
|
81
81
|
- [`price`](#price)
|
82
|
-
- [`
|
83
|
-
- [`revoke-
|
84
|
-
- [`list-
|
82
|
+
- [`share-credits`](#share-credits)
|
83
|
+
- [`revoke-credits`](#revoke-credits)
|
84
|
+
- [`list-shares`](#list-shares)
|
85
|
+
- [Turbo Credit Sharing](#turbo-credit-sharing)
|
85
86
|
- [Developers](#developers)
|
86
87
|
- [Requirements](#requirements)
|
87
88
|
- [Setup & Build](#setup--build)
|
@@ -683,36 +684,35 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
|
683
684
|
});
|
684
685
|
```
|
685
686
|
|
686
|
-
#### `
|
687
|
+
#### `shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })`
|
687
688
|
|
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
|
689
690
|
|
690
691
|
```typescript
|
691
|
-
const { approvalDataItemId, approvedWincAmount } =
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
});
|
692
|
+
const { approvalDataItemId, approvedWincAmount } = await turbo.shareCredits({
|
693
|
+
approvedAddress: '2cor...VUa',
|
694
|
+
approvedWincAmount: 0.08315565032,
|
695
|
+
expiresBySeconds: 3600,
|
696
|
+
});
|
697
697
|
```
|
698
698
|
|
699
|
-
#### `
|
699
|
+
#### `revokeCredits({ approvedAddress })`
|
700
700
|
|
701
|
-
Revokes all
|
701
|
+
Revokes all credits shared from the connected wallet to the provided native address.
|
702
702
|
|
703
703
|
```typescript
|
704
|
-
const revokedApprovals = await turbo.
|
704
|
+
const revokedApprovals = await turbo.revokeCredits({
|
705
705
|
approvedAddress: '2cor...VUa',
|
706
706
|
});
|
707
707
|
```
|
708
708
|
|
709
|
-
#### `
|
709
|
+
#### `getCreditShareApprovals({ userAddress })`
|
710
710
|
|
711
|
-
Returns all
|
711
|
+
Returns all given or received credit share approvals for the connected wallet or the provided native address.
|
712
712
|
|
713
713
|
```typescript
|
714
714
|
const { givenApprovals, receivedApprovals } =
|
715
|
-
await turbo.
|
715
|
+
await turbo.getCreditShareApprovals({
|
716
716
|
userAddress: '2cor...VUa',
|
717
717
|
});
|
718
718
|
```
|
@@ -781,9 +781,9 @@ Wallet options:
|
|
781
781
|
|
782
782
|
Upload options:
|
783
783
|
|
784
|
-
- `--paid-by <paidBy...>` -
|
785
|
-
- `--ignore-approvals` -
|
786
|
-
- `--use-signer-balance-first` - Use the connected wallet's balance before using any
|
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
787
|
|
788
788
|
#### Commands
|
789
789
|
|
@@ -870,7 +870,7 @@ Command Options:
|
|
870
870
|
e.g:
|
871
871
|
|
872
872
|
```shell
|
873
|
-
turbo upload-file --file-path '../path/to/my/file.txt' --token ethereum --wallet-file ../path/to/eth/private/key.txt --paid-by '0x...address' '0x...
|
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...'
|
874
874
|
```
|
875
875
|
|
876
876
|
##### `price`
|
@@ -896,50 +896,78 @@ turbo price --value 1024 --type bytes
|
|
896
896
|
turbo price --value 1.1 --type arweave
|
897
897
|
```
|
898
898
|
|
899
|
-
##### `
|
899
|
+
##### `share-credits`
|
900
900
|
|
901
|
-
|
901
|
+
Shares credits from the connected wallet to the provided native address and approved winc amount.
|
902
902
|
|
903
903
|
Command Options:
|
904
904
|
|
905
|
-
- `-a, --address <nativeAddress>` - Native address to that will receive the
|
906
|
-
- `-v, --value <value>` - Value of winc to
|
907
|
-
- `-e, --expires-by-seconds <seconds>` - Expiry time in seconds for the
|
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
908
|
|
909
909
|
e.g:
|
910
910
|
|
911
911
|
```shell
|
912
|
-
turbo
|
912
|
+
turbo share-credits --address 2cor...VUa --value 0.083155650320 --wallet-file ../path/to/my/wallet --expires-by-seconds 3600
|
913
913
|
```
|
914
914
|
|
915
|
-
##### `revoke-
|
915
|
+
##### `revoke-credits`
|
916
916
|
|
917
|
-
Revoke all
|
917
|
+
Revoke all credits shared from the connected wallet to the provided native address.
|
918
918
|
|
919
919
|
Command Options:
|
920
920
|
|
921
|
-
- `-a, --address <nativeAddress>` - Native address to revoke
|
921
|
+
- `-a, --address <nativeAddress>` - Native address to revoke credit share approvals for
|
922
922
|
|
923
923
|
e.g:
|
924
924
|
|
925
925
|
```shell
|
926
|
-
turbo revoke-
|
926
|
+
turbo revoke-credits --wallet-file ../path/to/my/wallet
|
927
927
|
```
|
928
928
|
|
929
|
-
##### `list-
|
929
|
+
##### `list-shares`
|
930
930
|
|
931
|
-
List all given and received
|
931
|
+
List all given and received credit share approvals from the connected wallet or the provided native address.
|
932
932
|
|
933
933
|
Command Options:
|
934
934
|
|
935
|
-
- `-a, --address <nativeAddress>` - Native address to list
|
935
|
+
- `-a, --address <nativeAddress>` - Native address to list credit share approvals for
|
936
936
|
|
937
937
|
e.g:
|
938
938
|
|
939
939
|
```shell
|
940
|
-
turbo list-
|
940
|
+
turbo list-shares --address 2cor...VUa --wallet-file ../path/to/my/wallet
|
941
941
|
```
|
942
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
|
+
|
943
971
|
## Developers
|
944
972
|
|
945
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.
|
310554
|
+
var version16 = "1.20.0-alpha.1";
|
310555
310555
|
|
310556
310556
|
// src/common/logger.ts
|
310557
310557
|
var TurboWinstonLogger = class _TurboWinstonLogger {
|
@@ -314897,7 +314897,7 @@ var TurboUnauthenticatedPaymentService = class {
|
|
314897
314897
|
}
|
314898
314898
|
throw new Error("Unknown response from payment service: " + response);
|
314899
314899
|
}
|
314900
|
-
async
|
314900
|
+
async getCreditShareApprovals({
|
314901
314901
|
userAddress
|
314902
314902
|
}) {
|
314903
314903
|
const response = await this.httpService.get({
|
@@ -314930,11 +314930,11 @@ var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPayment
|
|
314930
314930
|
userAddress ??= await this.signer.getNativeAddress();
|
314931
314931
|
return super.getBalance(userAddress);
|
314932
314932
|
}
|
314933
|
-
async
|
314933
|
+
async getCreditShareApprovals({
|
314934
314934
|
userAddress
|
314935
314935
|
}) {
|
314936
314936
|
userAddress ??= await this.signer.getNativeAddress();
|
314937
|
-
return super.
|
314937
|
+
return super.getCreditShareApprovals({ userAddress });
|
314938
314938
|
}
|
314939
314939
|
async getWincForFiat({
|
314940
314940
|
amount,
|
@@ -349652,10 +349652,12 @@ function pLimit(concurrency) {
|
|
349652
349652
|
}
|
349653
349653
|
|
349654
349654
|
// src/common/upload.ts
|
349655
|
-
var
|
349656
|
-
|
349657
|
-
|
349658
|
-
|
349655
|
+
var creditSharingTagNames = {
|
349656
|
+
shareCredits: "x-approve-payment",
|
349657
|
+
sharedWincAmount: "x-amount",
|
349658
|
+
approvalExpiresBySeconds: "x-expires-seconds",
|
349659
|
+
revokeCredits: "x-delete-payment-approval"
|
349660
|
+
};
|
349659
349661
|
var developmentUploadServiceURL = "https://upload.ardrive.dev";
|
349660
349662
|
var defaultUploadServiceURL = "https://upload.ardrive.io";
|
349661
349663
|
var TurboUnauthenticatedUploadService = class {
|
@@ -349854,20 +349856,26 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
|
|
349854
349856
|
manifestResponse
|
349855
349857
|
};
|
349856
349858
|
}
|
349857
|
-
async
|
349859
|
+
async shareCredits({
|
349858
349860
|
approvedAddress,
|
349859
349861
|
approvedWincAmount,
|
349860
349862
|
expiresBySeconds
|
349861
349863
|
}) {
|
349862
349864
|
const dataItemOpts = {
|
349863
349865
|
tags: [
|
349864
|
-
{
|
349865
|
-
|
349866
|
+
{
|
349867
|
+
name: creditSharingTagNames.shareCredits,
|
349868
|
+
value: approvedAddress
|
349869
|
+
},
|
349870
|
+
{
|
349871
|
+
name: creditSharingTagNames.sharedWincAmount,
|
349872
|
+
value: approvedWincAmount.toString()
|
349873
|
+
}
|
349866
349874
|
]
|
349867
349875
|
};
|
349868
349876
|
if (expiresBySeconds !== void 0) {
|
349869
349877
|
dataItemOpts.tags.push({
|
349870
|
-
name:
|
349878
|
+
name: creditSharingTagNames.approvalExpiresBySeconds,
|
349871
349879
|
value: expiresBySeconds.toString()
|
349872
349880
|
});
|
349873
349881
|
}
|
@@ -349881,18 +349889,18 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
|
|
349881
349889
|
});
|
349882
349890
|
if (!createdApproval) {
|
349883
349891
|
throw new Error(
|
349884
|
-
"Failed to create
|
349892
|
+
"Failed to create credit share approval but upload has succeeded\n" + JSON.stringify(uploadResponse)
|
349885
349893
|
);
|
349886
349894
|
}
|
349887
349895
|
return createdApproval;
|
349888
349896
|
}
|
349889
|
-
async
|
349897
|
+
async revokeCredits({
|
349890
349898
|
revokedAddress
|
349891
349899
|
}) {
|
349892
349900
|
const dataItemOpts = {
|
349893
349901
|
tags: [
|
349894
349902
|
{
|
349895
|
-
name:
|
349903
|
+
name: creditSharingTagNames.revokeCredits,
|
349896
349904
|
value: revokedAddress
|
349897
349905
|
}
|
349898
349906
|
]
|
@@ -349905,7 +349913,7 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
|
|
349905
349913
|
});
|
349906
349914
|
if (!revokedApprovals) {
|
349907
349915
|
throw new Error(
|
349908
|
-
"Failed to revoke
|
349916
|
+
"Failed to revoke credit share approvals but upload has succeeded\n" + JSON.stringify(uploadResponse)
|
349909
349917
|
);
|
349910
349918
|
}
|
349911
349919
|
return revokedApprovals;
|
@@ -350024,10 +350032,10 @@ var TurboUnauthenticatedClient = class {
|
|
350024
350032
|
return wallets;
|
350025
350033
|
}
|
350026
350034
|
/**
|
350027
|
-
* Returns a list of all
|
350035
|
+
* Returns a list of all credit share approvals for the user.
|
350028
350036
|
*/
|
350029
|
-
|
350030
|
-
return this.paymentService.
|
350037
|
+
getCreditShareApprovals(p8) {
|
350038
|
+
return this.paymentService.getCreditShareApprovals(p8);
|
350031
350039
|
}
|
350032
350040
|
};
|
350033
350041
|
var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
@@ -350046,10 +350054,10 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
|
350046
350054
|
return this.paymentService.getBalance(userAddress);
|
350047
350055
|
}
|
350048
350056
|
/**
|
350049
|
-
* Returns a list of all
|
350057
|
+
* Returns a list of all credit share approvals for the user.
|
350050
350058
|
*/
|
350051
|
-
|
350052
|
-
return this.paymentService.
|
350059
|
+
getCreditShareApprovals(p8 = {}) {
|
350060
|
+
return this.paymentService.getCreditShareApprovals(p8);
|
350053
350061
|
}
|
350054
350062
|
/**
|
350055
350063
|
* Signs and uploads raw data to the Turbo Upload Service.
|
@@ -350078,21 +350086,21 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
|
350078
350086
|
return this.paymentService.topUpWithTokens(p8);
|
350079
350087
|
}
|
350080
350088
|
/**
|
350081
|
-
* Creates a data item with tags that designate it as a
|
350089
|
+
* Creates a data item with tags that designate it as a credit share approval.
|
350082
350090
|
* Signs the data item and sends it to the Turbo Upload Service, which will verify
|
350083
350091
|
* the signature and forward the admin action towards the Turbo Payment Service.
|
350084
350092
|
*/
|
350085
|
-
|
350086
|
-
return this.uploadService.
|
350093
|
+
shareCredits(p8) {
|
350094
|
+
return this.uploadService.shareCredits(p8);
|
350087
350095
|
}
|
350088
350096
|
/**
|
350089
|
-
* Creates a data item with tags that designate it as a revoke action for
|
350090
|
-
*
|
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
|
350091
350099
|
* the Turbo Upload Service, which will verify the signature and forward the admin
|
350092
350100
|
* action towards the Turbo Payment Service.
|
350093
350101
|
*/
|
350094
|
-
|
350095
|
-
return this.uploadService.
|
350102
|
+
revokeCredits(p8) {
|
350103
|
+
return this.uploadService.revokeCredits(p8);
|
350096
350104
|
}
|
350097
350105
|
};
|
350098
350106
|
|
@@ -350629,9 +350637,7 @@ export {
|
|
350629
350637
|
USD,
|
350630
350638
|
WinstonToTokenAmount,
|
350631
350639
|
ZeroDecimalCurrency,
|
350632
|
-
|
350633
|
-
approvalExpiresBySecondsTagName,
|
350634
|
-
createDelegatedPaymentApprovalTagName,
|
350640
|
+
creditSharingTagNames,
|
350635
350641
|
currencyMap,
|
350636
350642
|
defaultPaymentServiceURL,
|
350637
350643
|
defaultTokenMap,
|
@@ -350652,7 +350658,6 @@ export {
|
|
350652
350658
|
isWebUploadFolderParams,
|
350653
350659
|
lamportToTokenAmount,
|
350654
350660
|
privateKeyFromKyveMnemonic,
|
350655
|
-
revokeDelegatePaymentApprovalTagName,
|
350656
350661
|
signerFromKyveMnemonic,
|
350657
350662
|
signerFromKyvePrivateKey2 as signerFromKyvePrivateKey,
|
350658
350663
|
tokenToBaseMap,
|
package/lib/cjs/cli/cli.js
CHANGED
@@ -20,10 +20,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
// eslint-disable-next-line header/header -- This is a CLI file
|
21
21
|
const commander_1 = require("commander");
|
22
22
|
const version_js_1 = require("../version.js");
|
23
|
-
const createApproval_js_1 = require("./commands/createApproval.js");
|
24
23
|
const index_js_1 = require("./commands/index.js");
|
25
|
-
const
|
26
|
-
const
|
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");
|
27
27
|
const options_js_1 = require("./options.js");
|
28
28
|
const utils_js_1 = require("./utils.js");
|
29
29
|
(0, utils_js_1.applyOptions)(commander_1.program
|
@@ -52,19 +52,19 @@ const utils_js_1 = require("./utils.js");
|
|
52
52
|
await (0, utils_js_1.runCommand)(command, index_js_1.price);
|
53
53
|
});
|
54
54
|
(0, utils_js_1.applyOptions)(commander_1.program
|
55
|
-
.command('
|
56
|
-
.description('Create a Turbo
|
57
|
-
await (0, utils_js_1.runCommand)(command,
|
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
58
|
});
|
59
59
|
(0, utils_js_1.applyOptions)(commander_1.program
|
60
|
-
.command('revoke-
|
61
|
-
.description('Revokes all Turbo
|
62
|
-
await (0, utils_js_1.runCommand)(command,
|
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
63
|
});
|
64
64
|
(0, utils_js_1.applyOptions)(commander_1.program
|
65
|
-
.command('list-
|
66
|
-
.description('Lists all Turbo
|
67
|
-
await (0, utils_js_1.runCommand)(command,
|
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
68
|
});
|
69
69
|
if (process.argv[1].includes('bin/turbo') || // Running from global .bin
|
70
70
|
process.argv[1].includes('cli/cli') // Running from source
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.listShares = listShares;
|
4
4
|
/**
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
6
6
|
*
|
@@ -18,12 +18,12 @@ exports.listApprovals = listApprovals;
|
|
18
18
|
*/
|
19
19
|
const factory_js_1 = require("../../node/factory.js");
|
20
20
|
const utils_js_1 = require("../utils.js");
|
21
|
-
async function
|
21
|
+
async function listShares(options) {
|
22
22
|
const config = (0, utils_js_1.configFromOptions)(options);
|
23
23
|
const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
|
24
24
|
const { givenApprovals, receivedApprovals, nativeAddress } = await (async () => {
|
25
25
|
if (address !== undefined) {
|
26
|
-
const approvals = await factory_js_1.TurboFactory.unauthenticated(config).
|
26
|
+
const approvals = await factory_js_1.TurboFactory.unauthenticated(config).getCreditShareApprovals({
|
27
27
|
userAddress: address,
|
28
28
|
});
|
29
29
|
return { ...approvals, nativeAddress: address };
|
@@ -35,7 +35,7 @@ async function listApprovals(options) {
|
|
35
35
|
...config,
|
36
36
|
privateKey,
|
37
37
|
});
|
38
|
-
const approvals = await turbo.
|
38
|
+
const approvals = await turbo.getCreditShareApprovals();
|
39
39
|
return {
|
40
40
|
...approvals,
|
41
41
|
nativeAddress: await turbo.signer.getNativeAddress(),
|
@@ -43,8 +43,8 @@ async function listApprovals(options) {
|
|
43
43
|
})();
|
44
44
|
const hasApprovals = givenApprovals?.length === 0 && receivedApprovals?.length === 0;
|
45
45
|
const body = {
|
46
|
-
message: `${hasApprovals ? 'No
|
47
|
-
` for native address '${nativeAddress}'`,
|
46
|
+
message: `${hasApprovals ? 'No ' : ''}` +
|
47
|
+
`Credit Share Approvals found for native address '${nativeAddress}'`,
|
48
48
|
givenApprovals,
|
49
49
|
receivedApprovals,
|
50
50
|
};
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.revokeCredits = revokeCredits;
|
4
4
|
const utils_js_1 = require("../utils.js");
|
5
|
-
async function
|
5
|
+
async function revokeCredits(options) {
|
6
6
|
const { address: revokedAddress } = options;
|
7
7
|
if (revokedAddress === undefined) {
|
8
8
|
throw new Error('Must provide an approved --address to revoke approvals for');
|
9
9
|
}
|
10
10
|
const turbo = await (0, utils_js_1.turboFromOptions)(options);
|
11
|
-
const revokedApprovals = await turbo.
|
11
|
+
const revokedApprovals = await turbo.revokeCredits({
|
12
12
|
revokedAddress,
|
13
13
|
});
|
14
|
-
console.log(JSON.stringify({ message: 'Revoked approvals', revokedApprovals }, null, 2));
|
14
|
+
console.log(JSON.stringify({ message: 'Revoked credit share approvals!', revokedApprovals }, null, 2));
|
15
15
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.shareCredits = shareCredits;
|
4
4
|
/**
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
6
6
|
*
|
@@ -18,7 +18,7 @@ exports.createApproval = createApproval;
|
|
18
18
|
*/
|
19
19
|
const bignumber_js_1 = require("bignumber.js");
|
20
20
|
const utils_js_1 = require("../utils.js");
|
21
|
-
async function
|
21
|
+
async function shareCredits(options) {
|
22
22
|
const { address: approvedAddress, value: creditAmount, expiresBySeconds, } = options;
|
23
23
|
if (approvedAddress === undefined) {
|
24
24
|
throw new Error('Must provide an approved --address to create approval for');
|
@@ -30,10 +30,10 @@ async function createApproval(options) {
|
|
30
30
|
const approvedWincAmount = new bignumber_js_1.BigNumber(creditAmount)
|
31
31
|
.shiftedBy(12)
|
32
32
|
.toFixed(0);
|
33
|
-
const result = await turbo.
|
33
|
+
const result = await turbo.shareCredits({
|
34
34
|
approvedAddress,
|
35
35
|
approvedWincAmount,
|
36
36
|
expiresBySeconds,
|
37
37
|
});
|
38
|
-
console.log(JSON.stringify({ message: 'Created approval
|
38
|
+
console.log(JSON.stringify({ message: 'Created credit share approval!', ...result }, null, 2));
|
39
39
|
}
|
package/lib/cjs/cli/options.js
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
* limitations under the License.
|
16
16
|
*/
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.
|
18
|
+
exports.listSharesOptions = exports.revokeCreditsOptions = exports.shareCreditsOptions = exports.uploadFileOptions = exports.uploadFolderOptions = exports.uploadOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
|
19
19
|
exports.optionMap = {
|
20
20
|
token: {
|
21
21
|
alias: '-t, --token <type>',
|
@@ -134,12 +134,12 @@ exports.optionMap = {
|
|
134
134
|
},
|
135
135
|
ignoreApprovals: {
|
136
136
|
alias: '--ignore-approvals',
|
137
|
-
description: "Ignore all
|
137
|
+
description: "Ignore all credit share approvals, only use signing wallet's balance",
|
138
138
|
default: false,
|
139
139
|
},
|
140
140
|
useSignerBalanceFirst: {
|
141
141
|
alias: '--use-signer-balance-first',
|
142
|
-
description: 'Use the signer balance first before using
|
142
|
+
description: 'Use the signer balance first before using credit share approvals',
|
143
143
|
default: false,
|
144
144
|
},
|
145
145
|
};
|
@@ -174,11 +174,11 @@ exports.uploadFolderOptions = [
|
|
174
174
|
exports.optionMap.maxConcurrency,
|
175
175
|
];
|
176
176
|
exports.uploadFileOptions = [...exports.uploadOptions, exports.optionMap.filePath];
|
177
|
-
exports.
|
177
|
+
exports.shareCreditsOptions = [
|
178
178
|
...exports.walletOptions,
|
179
179
|
exports.optionMap.value,
|
180
180
|
exports.optionMap.address,
|
181
181
|
exports.optionMap.expiresBySeconds,
|
182
182
|
];
|
183
|
-
exports.
|
184
|
-
exports.
|
183
|
+
exports.revokeCreditsOptions = [...exports.walletOptions, exports.optionMap.address];
|
184
|
+
exports.listSharesOptions = exports.revokeCreditsOptions;
|
@@ -164,7 +164,7 @@ class TurboUnauthenticatedPaymentService {
|
|
164
164
|
}
|
165
165
|
throw new Error('Unknown response from payment service: ' + response);
|
166
166
|
}
|
167
|
-
async
|
167
|
+
async getCreditShareApprovals({ userAddress, }) {
|
168
168
|
const response = await this.httpService.get({
|
169
169
|
endpoint: `/account/approvals/get?userAddress=${userAddress}`,
|
170
170
|
allowedStatuses: [200, 404],
|
@@ -191,9 +191,9 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
|
|
191
191
|
userAddress ??= await this.signer.getNativeAddress();
|
192
192
|
return super.getBalance(userAddress);
|
193
193
|
}
|
194
|
-
async
|
194
|
+
async getCreditShareApprovals({ userAddress, }) {
|
195
195
|
userAddress ??= await this.signer.getNativeAddress();
|
196
|
-
return super.
|
196
|
+
return super.getCreditShareApprovals({ userAddress });
|
197
197
|
}
|
198
198
|
async getWincForFiat({ amount, promoCodes = [], }) {
|
199
199
|
return super.getWincForFiat({
|
package/lib/cjs/common/turbo.js
CHANGED
@@ -109,10 +109,10 @@ class TurboUnauthenticatedClient {
|
|
109
109
|
return wallets;
|
110
110
|
}
|
111
111
|
/**
|
112
|
-
* Returns a list of all
|
112
|
+
* Returns a list of all credit share approvals for the user.
|
113
113
|
*/
|
114
|
-
|
115
|
-
return this.paymentService.
|
114
|
+
getCreditShareApprovals(p) {
|
115
|
+
return this.paymentService.getCreditShareApprovals(p);
|
116
116
|
}
|
117
117
|
}
|
118
118
|
exports.TurboUnauthenticatedClient = TurboUnauthenticatedClient;
|
@@ -128,10 +128,10 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
|
|
128
128
|
return this.paymentService.getBalance(userAddress);
|
129
129
|
}
|
130
130
|
/**
|
131
|
-
* Returns a list of all
|
131
|
+
* Returns a list of all credit share approvals for the user.
|
132
132
|
*/
|
133
|
-
|
134
|
-
return this.paymentService.
|
133
|
+
getCreditShareApprovals(p = {}) {
|
134
|
+
return this.paymentService.getCreditShareApprovals(p);
|
135
135
|
}
|
136
136
|
/**
|
137
137
|
* Signs and uploads raw data to the Turbo Upload Service.
|
@@ -155,21 +155,21 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
|
|
155
155
|
return this.paymentService.topUpWithTokens(p);
|
156
156
|
}
|
157
157
|
/**
|
158
|
-
* Creates a data item with tags that designate it as a
|
158
|
+
* Creates a data item with tags that designate it as a credit share approval.
|
159
159
|
* Signs the data item and sends it to the Turbo Upload Service, which will verify
|
160
160
|
* the signature and forward the admin action towards the Turbo Payment Service.
|
161
161
|
*/
|
162
|
-
|
163
|
-
return this.uploadService.
|
162
|
+
shareCredits(p) {
|
163
|
+
return this.uploadService.shareCredits(p);
|
164
164
|
}
|
165
165
|
/**
|
166
|
-
* Creates a data item with tags that designate it as a revoke action for
|
167
|
-
*
|
166
|
+
* Creates a data item with tags that designate it as a revoke action for credit
|
167
|
+
* share approvals for target revokedAddress. Signs the data item and sends it to
|
168
168
|
* the Turbo Upload Service, which will verify the signature and forward the admin
|
169
169
|
* action towards the Turbo Payment Service.
|
170
170
|
*/
|
171
|
-
|
172
|
-
return this.uploadService.
|
171
|
+
revokeCredits(p) {
|
172
|
+
return this.uploadService.revokeCredits(p);
|
173
173
|
}
|
174
174
|
}
|
175
175
|
exports.TurboAuthenticatedClient = TurboAuthenticatedClient;
|