@ardrive/turbo-sdk 1.19.2 → 1.20.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.
- package/README.md +95 -1
- package/bundles/web.bundle.min.js +143 -14
- package/lib/cjs/cli/cli.js +18 -0
- package/lib/cjs/cli/commands/balance.js +26 -15
- package/lib/cjs/cli/commands/createApproval.js +39 -0
- package/lib/cjs/cli/commands/cryptoFund.js +3 -1
- package/lib/cjs/cli/commands/listApprovals.js +58 -0
- package/lib/cjs/cli/commands/price.js +2 -1
- package/lib/cjs/cli/commands/revokeApprovals.js +15 -0
- package/lib/cjs/cli/commands/uploadFile.js +2 -1
- package/lib/cjs/cli/commands/uploadFolder.js +2 -1
- package/lib/cjs/cli/constants.js +2 -1
- package/lib/cjs/cli/options.js +43 -4
- package/lib/cjs/cli/utils.js +31 -0
- package/lib/cjs/common/payment.js +30 -4
- package/lib/cjs/common/token/solana.js +2 -2
- package/lib/cjs/common/turbo.js +31 -2
- package/lib/cjs/common/upload.js +65 -6
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +19 -1
- package/lib/esm/cli/commands/balance.js +26 -15
- package/lib/esm/cli/commands/createApproval.js +36 -0
- package/lib/esm/cli/commands/cryptoFund.js +3 -1
- package/lib/esm/cli/commands/listApprovals.js +55 -0
- package/lib/esm/cli/commands/price.js +2 -1
- package/lib/esm/cli/commands/revokeApprovals.js +12 -0
- package/lib/esm/cli/commands/uploadFile.js +3 -2
- package/lib/esm/cli/commands/uploadFolder.js +3 -2
- package/lib/esm/cli/constants.js +1 -0
- package/lib/esm/cli/options.js +42 -3
- package/lib/esm/cli/utils.js +30 -0
- package/lib/esm/common/payment.js +30 -4
- package/lib/esm/common/token/solana.js +2 -2
- package/lib/esm/common/turbo.js +31 -2
- package/lib/esm/common/upload.js +64 -5
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/balance.d.ts.map +1 -1
- package/lib/types/cli/commands/createApproval.d.ts +3 -0
- package/lib/types/cli/commands/createApproval.d.ts.map +1 -0
- package/lib/types/cli/commands/cryptoFund.d.ts.map +1 -1
- package/lib/types/cli/commands/listApprovals.d.ts +3 -0
- package/lib/types/cli/commands/listApprovals.d.ts.map +1 -0
- package/lib/types/cli/commands/price.d.ts.map +1 -1
- package/lib/types/cli/commands/revokeApprovals.d.ts +18 -0
- package/lib/types/cli/commands/revokeApprovals.d.ts.map +1 -0
- package/lib/types/cli/commands/uploadFile.d.ts.map +1 -1
- package/lib/types/cli/commands/uploadFolder.d.ts.map +1 -1
- package/lib/types/cli/constants.d.ts +1 -0
- package/lib/types/cli/constants.d.ts.map +1 -1
- package/lib/types/cli/options.d.ts +121 -2
- package/lib/types/cli/options.d.ts.map +1 -1
- package/lib/types/cli/types.d.ts +17 -2
- package/lib/types/cli/types.d.ts.map +1 -1
- package/lib/types/cli/utils.d.ts +2 -1
- package/lib/types/cli/utils.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts +8 -2
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/token/solana.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +27 -2
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +7 -1
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/types.d.ts +54 -3
- package/lib/types/types.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 +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
|
+
- [`createDelegatedPaymentApproval({ approvedAddress, approvedWincAmount, expiresBySeconds })`](#createdelegatedpaymentapproval-approvedaddress-approvedwincamount-expiresbyseconds-)
|
69
|
+
- [`revokeDelegatedPaymentApprovals({ approvedAddress })`](#revokedelegatedpaymentapprovals-approvedaddress-)
|
70
|
+
- [`getDelegatedPaymentApprovals({ userAddress })`](#getdelegatedpaymentapprovals-useraddress-)
|
68
71
|
- [CLI](#cli)
|
69
72
|
- [Install CLI](#install-cli)
|
70
73
|
- [CLI Usage](#cli-usage)
|
@@ -76,6 +79,9 @@ 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
|
+
- [`create-approval`](#create-approval)
|
83
|
+
- [`revoke-approvals`](#revoke-approvals)
|
84
|
+
- [`list-approvals`](#list-approvals)
|
79
85
|
- [Developers](#developers)
|
80
86
|
- [Requirements](#requirements)
|
81
87
|
- [Setup & Build](#setup--build)
|
@@ -677,6 +683,40 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
|
677
683
|
});
|
678
684
|
```
|
679
685
|
|
686
|
+
#### `createDelegatedPaymentApproval({ approvedAddress, approvedWincAmount, expiresBySeconds })`
|
687
|
+
|
688
|
+
Creates a delegated payment approval from the connected wallet to the provided native address and approved winc amount. This action will create a data item for the approval
|
689
|
+
|
690
|
+
```typescript
|
691
|
+
const { approvalDataItemId, approvedWincAmount } =
|
692
|
+
await turbo.createDelegatedPaymentApproval({
|
693
|
+
approvedAddress: '2cor...VUa',
|
694
|
+
approvedWincAmount: 0.08315565032,
|
695
|
+
expiresBySeconds: 3600,
|
696
|
+
});
|
697
|
+
```
|
698
|
+
|
699
|
+
#### `revokeDelegatedPaymentApprovals({ approvedAddress })`
|
700
|
+
|
701
|
+
Revokes all delegated payment approvals from the connected wallet to the provided native address.
|
702
|
+
|
703
|
+
```typescript
|
704
|
+
const revokedApprovals = await turbo.revokeDelegatePaymentApprovals({
|
705
|
+
approvedAddress: '2cor...VUa',
|
706
|
+
});
|
707
|
+
```
|
708
|
+
|
709
|
+
#### `getDelegatedPaymentApprovals({ userAddress })`
|
710
|
+
|
711
|
+
Returns all delegated payment approvals from the connected wallet or the provided native address.
|
712
|
+
|
713
|
+
```typescript
|
714
|
+
const { givenApprovals, receivedApprovals } =
|
715
|
+
await turbo.getDelegatedPaymentApprovals({
|
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...>` - An array of native addresses to pay for the upload
|
785
|
+
- `--ignore-approvals` - The CLI will normally use any delegated payment approvals 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 delegated payment 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...address' '0x...another-address'
|
824
874
|
```
|
825
875
|
|
826
876
|
##### `price`
|
@@ -846,6 +896,50 @@ turbo price --value 1024 --type bytes
|
|
846
896
|
turbo price --value 1.1 --type arweave
|
847
897
|
```
|
848
898
|
|
899
|
+
##### `create-approval`
|
900
|
+
|
901
|
+
Create a delegated payment approval 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 delegated payment approval
|
906
|
+
- `-v, --value <value>` - Value of winc to create delegated payment approval for
|
907
|
+
- `-e, --expires-by-seconds <seconds>` - Expiry time in seconds for the delegated payment approval
|
908
|
+
|
909
|
+
e.g:
|
910
|
+
|
911
|
+
```shell
|
912
|
+
turbo create-approval --address 2cor...VUa --value 0.083155650320 --wallet-file ../path/to/my/wallet --expires-by-seconds 3600
|
913
|
+
```
|
914
|
+
|
915
|
+
##### `revoke-approvals`
|
916
|
+
|
917
|
+
Revoke all delegated payment approvals from the connected wallet to the provided native address.
|
918
|
+
|
919
|
+
Command Options:
|
920
|
+
|
921
|
+
- `-a, --address <nativeAddress>` - Native address to revoke delegated payment approvals for
|
922
|
+
|
923
|
+
e.g:
|
924
|
+
|
925
|
+
```shell
|
926
|
+
turbo revoke-approvals --wallet-file ../path/to/my/wallet
|
927
|
+
```
|
928
|
+
|
929
|
+
##### `list-approvals`
|
930
|
+
|
931
|
+
List all given and received delegated payment approvals from the connected wallet or the provided native address.
|
932
|
+
|
933
|
+
Command Options:
|
934
|
+
|
935
|
+
- `-a, --address <nativeAddress>` - Native address to list delegated payment approvals for
|
936
|
+
|
937
|
+
e.g:
|
938
|
+
|
939
|
+
```shell
|
940
|
+
turbo list-approvals --address 2cor...VUa --wallet-file ../path/to/my/wallet
|
941
|
+
```
|
942
|
+
|
849
943
|
## Developers
|
850
944
|
|
851
945
|
### 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
|
310554
|
+
var version16 = "1.19.2";
|
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 : {
|
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 getDelegatedPaymentApprovals({
|
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(
|
314909
|
-
|
314910
|
-
return super.getBalance(
|
314929
|
+
async getBalance(userAddress) {
|
314930
|
+
userAddress ??= await this.signer.getNativeAddress();
|
314931
|
+
return super.getBalance(userAddress);
|
314932
|
+
}
|
314933
|
+
async getDelegatedPaymentApprovals({
|
314934
|
+
userAddress
|
314935
|
+
}) {
|
314936
|
+
userAddress ??= await this.signer.getNativeAddress();
|
314937
|
+
return super.getDelegatedPaymentApprovals({ 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(
|
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,10 @@ function pLimit(concurrency) {
|
|
349622
349652
|
}
|
349623
349653
|
|
349624
349654
|
// src/common/upload.ts
|
349655
|
+
var createDelegatedPaymentApprovalTagName = "x-approve-payment";
|
349656
|
+
var approvalAmountTagName = "x-amount";
|
349657
|
+
var approvalExpiresBySecondsTagName = "x-expires-seconds";
|
349658
|
+
var revokeDelegatePaymentApprovalTagName = "x-delete-payment-approval";
|
349625
349659
|
var developmentUploadServiceURL = "https://upload.ardrive.dev";
|
349626
349660
|
var defaultUploadServiceURL = "https://upload.ardrive.io";
|
349627
349661
|
var TurboUnauthenticatedUploadService = class {
|
@@ -349680,16 +349714,22 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
|
|
349680
349714
|
dataItemOpts
|
349681
349715
|
});
|
349682
349716
|
const signedDataItem = dataItemStreamFactory();
|
349683
|
-
const fileSize = dataItemSizeFactory();
|
349684
349717
|
this.logger.debug("Uploading signed data item...");
|
349718
|
+
const headers = {
|
349719
|
+
"content-type": "application/octet-stream",
|
349720
|
+
"content-length": `${dataItemSizeFactory()}`
|
349721
|
+
};
|
349722
|
+
if (dataItemOpts !== void 0 && dataItemOpts.paidBy !== void 0) {
|
349723
|
+
const paidBy = Array.isArray(dataItemOpts.paidBy) ? dataItemOpts.paidBy : [dataItemOpts.paidBy];
|
349724
|
+
if (dataItemOpts.paidBy.length > 0) {
|
349725
|
+
headers["x-paid-by"] = paidBy;
|
349726
|
+
}
|
349727
|
+
}
|
349685
349728
|
return this.httpService.post({
|
349686
349729
|
endpoint: `/tx/${this.token}`,
|
349687
349730
|
signal,
|
349688
349731
|
data: signedDataItem,
|
349689
|
-
headers
|
349690
|
-
"content-type": "application/octet-stream",
|
349691
|
-
"content-length": `${fileSize}`
|
349692
|
-
}
|
349732
|
+
headers
|
349693
349733
|
});
|
349694
349734
|
}
|
349695
349735
|
async generateManifest({
|
@@ -349814,6 +349854,62 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
|
|
349814
349854
|
manifestResponse
|
349815
349855
|
};
|
349816
349856
|
}
|
349857
|
+
async createDelegatedPaymentApproval({
|
349858
|
+
approvedAddress,
|
349859
|
+
approvedWincAmount,
|
349860
|
+
expiresBySeconds
|
349861
|
+
}) {
|
349862
|
+
const dataItemOpts = {
|
349863
|
+
tags: [
|
349864
|
+
{ name: createDelegatedPaymentApprovalTagName, value: approvedAddress },
|
349865
|
+
{ name: approvalAmountTagName, value: approvedWincAmount.toString() }
|
349866
|
+
]
|
349867
|
+
};
|
349868
|
+
if (expiresBySeconds !== void 0) {
|
349869
|
+
dataItemOpts.tags.push({
|
349870
|
+
name: approvalExpiresBySecondsTagName,
|
349871
|
+
value: expiresBySeconds.toString()
|
349872
|
+
});
|
349873
|
+
}
|
349874
|
+
const nonceData = Buffer.from(
|
349875
|
+
approvedAddress + approvedWincAmount + Date.now()
|
349876
|
+
);
|
349877
|
+
const { createdApproval, ...uploadResponse } = await this.uploadFile({
|
349878
|
+
fileStreamFactory: () => Readable.from(nonceData),
|
349879
|
+
fileSizeFactory: () => nonceData.byteLength,
|
349880
|
+
dataItemOpts
|
349881
|
+
});
|
349882
|
+
if (!createdApproval) {
|
349883
|
+
throw new Error(
|
349884
|
+
"Failed to create delegated payment approval but upload has succeeded\n" + JSON.stringify(uploadResponse)
|
349885
|
+
);
|
349886
|
+
}
|
349887
|
+
return createdApproval;
|
349888
|
+
}
|
349889
|
+
async revokeDelegatedPaymentApprovals({
|
349890
|
+
revokedAddress
|
349891
|
+
}) {
|
349892
|
+
const dataItemOpts = {
|
349893
|
+
tags: [
|
349894
|
+
{
|
349895
|
+
name: revokeDelegatePaymentApprovalTagName,
|
349896
|
+
value: revokedAddress
|
349897
|
+
}
|
349898
|
+
]
|
349899
|
+
};
|
349900
|
+
const nonceData = Buffer.from(revokedAddress + Date.now());
|
349901
|
+
const { revokedApprovals, ...uploadResponse } = await this.uploadFile({
|
349902
|
+
fileStreamFactory: () => Readable.from(nonceData),
|
349903
|
+
fileSizeFactory: () => nonceData.byteLength,
|
349904
|
+
dataItemOpts
|
349905
|
+
});
|
349906
|
+
if (!revokedApprovals) {
|
349907
|
+
throw new Error(
|
349908
|
+
"Failed to revoke delegated payment approvals but upload has succeeded\n" + JSON.stringify(uploadResponse)
|
349909
|
+
);
|
349910
|
+
}
|
349911
|
+
return revokedApprovals;
|
349912
|
+
}
|
349817
349913
|
};
|
349818
349914
|
|
349819
349915
|
// src/common/turbo.ts
|
@@ -349927,6 +350023,12 @@ var TurboUnauthenticatedClient = class {
|
|
349927
350023
|
wallets.pol = wallets.matic;
|
349928
350024
|
return wallets;
|
349929
350025
|
}
|
350026
|
+
/**
|
350027
|
+
* Returns a list of all delegated payment approvals for the user.
|
350028
|
+
*/
|
350029
|
+
getDelegatedPaymentApprovals(p8) {
|
350030
|
+
return this.paymentService.getDelegatedPaymentApprovals(p8);
|
350031
|
+
}
|
349930
350032
|
};
|
349931
350033
|
var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
349932
350034
|
constructor({
|
@@ -349940,8 +350042,14 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
|
349940
350042
|
/**
|
349941
350043
|
* Returns the current balance of the user's wallet in 'winc'.
|
349942
350044
|
*/
|
349943
|
-
getBalance(
|
349944
|
-
return this.paymentService.getBalance(
|
350045
|
+
getBalance(userAddress) {
|
350046
|
+
return this.paymentService.getBalance(userAddress);
|
350047
|
+
}
|
350048
|
+
/**
|
350049
|
+
* Returns a list of all delegated payment approvals for the user.
|
350050
|
+
*/
|
350051
|
+
getDelegatedPaymentApprovals(p8 = {}) {
|
350052
|
+
return this.paymentService.getDelegatedPaymentApprovals(p8);
|
349945
350053
|
}
|
349946
350054
|
/**
|
349947
350055
|
* Signs and uploads raw data to the Turbo Upload Service.
|
@@ -349969,6 +350077,23 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
|
349969
350077
|
topUpWithTokens(p8) {
|
349970
350078
|
return this.paymentService.topUpWithTokens(p8);
|
349971
350079
|
}
|
350080
|
+
/**
|
350081
|
+
* Creates a data item with tags that designate it as a delegated payment approval.
|
350082
|
+
* Signs the data item and sends it to the Turbo Upload Service, which will verify
|
350083
|
+
* the signature and forward the admin action towards the Turbo Payment Service.
|
350084
|
+
*/
|
350085
|
+
createDelegatedPaymentApproval(p8) {
|
350086
|
+
return this.uploadService.createDelegatedPaymentApproval(p8);
|
350087
|
+
}
|
350088
|
+
/**
|
350089
|
+
* Creates a data item with tags that designate it as a revoke action for delegated
|
350090
|
+
* payment approvals for target revokedAddress. Signs the data item and sends it to
|
350091
|
+
* the Turbo Upload Service, which will verify the signature and forward the admin
|
350092
|
+
* action towards the Turbo Payment Service.
|
350093
|
+
*/
|
350094
|
+
revokeDelegatedPaymentApprovals(p8) {
|
350095
|
+
return this.uploadService.revokeDelegatedPaymentApprovals(p8);
|
350096
|
+
}
|
349972
350097
|
};
|
349973
350098
|
|
349974
350099
|
// src/common/factory.ts
|
@@ -350504,6 +350629,9 @@ export {
|
|
350504
350629
|
USD,
|
350505
350630
|
WinstonToTokenAmount,
|
350506
350631
|
ZeroDecimalCurrency,
|
350632
|
+
approvalAmountTagName,
|
350633
|
+
approvalExpiresBySecondsTagName,
|
350634
|
+
createDelegatedPaymentApprovalTagName,
|
350507
350635
|
currencyMap,
|
350508
350636
|
defaultPaymentServiceURL,
|
350509
350637
|
defaultTokenMap,
|
@@ -350524,6 +350652,7 @@ export {
|
|
350524
350652
|
isWebUploadFolderParams,
|
350525
350653
|
lamportToTokenAmount,
|
350526
350654
|
privateKeyFromKyveMnemonic,
|
350655
|
+
revokeDelegatePaymentApprovalTagName,
|
350527
350656
|
signerFromKyveMnemonic,
|
350528
350657
|
signerFromKyvePrivateKey2 as signerFromKyvePrivateKey,
|
350529
350658
|
tokenToBaseMap,
|
package/lib/cjs/cli/cli.js
CHANGED
@@ -20,7 +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");
|
23
24
|
const index_js_1 = require("./commands/index.js");
|
25
|
+
const listApprovals_js_1 = require("./commands/listApprovals.js");
|
26
|
+
const revokeApprovals_js_1 = require("./commands/revokeApprovals.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('create-approval')
|
56
|
+
.description('Create a Turbo delegated payment approval'), options_js_1.createApprovalOptions).action(async (_commandOptions, command) => {
|
57
|
+
await (0, utils_js_1.runCommand)(command, createApproval_js_1.createApproval);
|
58
|
+
});
|
59
|
+
(0, utils_js_1.applyOptions)(commander_1.program
|
60
|
+
.command('revoke-approvals')
|
61
|
+
.description('Revokes all Turbo delegated payment approvals for given address'), options_js_1.revokeApprovalsOptions).action(async (_commandOptions, command) => {
|
62
|
+
await (0, utils_js_1.runCommand)(command, revokeApprovals_js_1.revokeApprovals);
|
63
|
+
});
|
64
|
+
(0, utils_js_1.applyOptions)(commander_1.program
|
65
|
+
.command('list-approvals')
|
66
|
+
.description('Lists all Turbo delegated payment approvals for given address or wallet'), options_js_1.listApprovalsOptions).action(async (_commandOptions, command) => {
|
67
|
+
await (0, utils_js_1.runCommand)(command, listApprovals_js_1.listApprovals);
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createApproval = createApproval;
|
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 createApproval(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.createDelegatedPaymentApproval({
|
34
|
+
approvedAddress,
|
35
|
+
approvedWincAmount,
|
36
|
+
expiresBySeconds,
|
37
|
+
});
|
38
|
+
console.log(JSON.stringify({ message: 'Created approval:', ...result }, null, 2));
|
39
|
+
}
|
@@ -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 = (
|
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.listApprovals = listApprovals;
|
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 listApprovals(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).getDelegatedPaymentApprovals({
|
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.getDelegatedPaymentApprovals();
|
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 approvals found' : 'Approvals found'}` +
|
47
|
+
` 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 /
|
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.revokeApprovals = revokeApprovals;
|
4
|
+
const utils_js_1 = require("../utils.js");
|
5
|
+
async function revokeApprovals(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.revokeDelegatedPaymentApprovals({
|
12
|
+
revokedAddress,
|
13
|
+
});
|
14
|
+
console.log(JSON.stringify({ message: 'Revoked approvals', revokedApprovals }, null, 2));
|
15
|
+
}
|
@@ -25,11 +25,12 @@ async function uploadFile(options) {
|
|
25
25
|
throw new Error('Must provide a --file-path to upload');
|
26
26
|
}
|
27
27
|
const turbo = await (0, utils_js_1.turboFromOptions)(options);
|
28
|
+
const paidBy = await (0, utils_js_1.paidByFromOptions)(options, turbo);
|
28
29
|
const fileSize = (0, fs_1.statSync)(filePath).size;
|
29
30
|
const result = await turbo.uploadFile({
|
30
31
|
fileStreamFactory: () => (0, fs_1.createReadStream)(filePath),
|
31
32
|
fileSizeFactory: () => fileSize,
|
32
|
-
dataItemOpts: { tags: [...constants_js_1.turboCliTags] }, // TODO: Inject user tags
|
33
|
+
dataItemOpts: { tags: [...constants_js_1.turboCliTags], paidBy }, // TODO: Inject user tags
|
33
34
|
});
|
34
35
|
console.log('Uploaded file:', JSON.stringify(result, null, 2));
|
35
36
|
}
|
@@ -20,10 +20,11 @@ const constants_js_1 = require("../constants.js");
|
|
20
20
|
const utils_js_1 = require("../utils.js");
|
21
21
|
async function uploadFolder(options) {
|
22
22
|
const turbo = await (0, utils_js_1.turboFromOptions)(options);
|
23
|
+
const paidBy = await (0, utils_js_1.paidByFromOptions)(options, turbo);
|
23
24
|
const { disableManifest, fallbackFile, folderPath, indexFile, maxConcurrentUploads, } = (0, utils_js_1.getUploadFolderOptions)(options);
|
24
25
|
const result = await turbo.uploadFolder({
|
25
26
|
folderPath: folderPath,
|
26
|
-
dataItemOpts: { tags: [...constants_js_1.turboCliTags] }, // TODO: Inject user tags
|
27
|
+
dataItemOpts: { tags: [...constants_js_1.turboCliTags], paidBy }, // TODO: Inject user tags
|
27
28
|
manifestOptions: {
|
28
29
|
disableManifest,
|
29
30
|
indexFile,
|