@ardrive/turbo-sdk 1.16.1 → 1.17.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 +58 -1
- package/bundles/web.bundle.min.js +75 -9
- package/lib/cjs/cli/cli.js +11 -6
- package/lib/cjs/cli/commands/balance.js +40 -0
- package/lib/cjs/cli/commands/cryptoFund.js +61 -0
- package/lib/cjs/cli/commands/index.js +38 -0
- package/lib/cjs/cli/commands/price.js +53 -0
- package/lib/cjs/cli/commands/topUp.js +80 -0
- package/lib/cjs/cli/commands/uploadFile.js +36 -0
- package/lib/cjs/cli/commands/uploadFolder.js +36 -0
- package/lib/cjs/cli/constants.js +25 -0
- package/lib/cjs/cli/options.js +5 -0
- package/lib/cjs/cli/utils.js +2 -1
- package/lib/cjs/common/currency.js +22 -3
- package/lib/cjs/common/factory.js +1 -0
- package/lib/cjs/common/signer.js +2 -0
- package/lib/cjs/common/token/index.js +5 -0
- package/lib/cjs/common/token/polygon.js +16 -0
- package/lib/cjs/common/turbo.js +4 -2
- package/lib/cjs/node/factory.js +1 -0
- package/lib/cjs/types.js +8 -1
- package/lib/cjs/utils/common.js +1 -0
- package/lib/cjs/utils/errors.js +7 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/web/factory.js +1 -0
- package/lib/esm/cli/cli.js +7 -2
- package/lib/esm/cli/commands/balance.js +37 -0
- package/lib/esm/cli/commands/cryptoFund.js +55 -0
- package/lib/esm/cli/commands/index.js +22 -0
- package/lib/esm/cli/commands/price.js +50 -0
- package/lib/esm/cli/commands/topUp.js +77 -0
- package/lib/esm/cli/commands/uploadFile.js +33 -0
- package/lib/esm/cli/commands/uploadFolder.js +33 -0
- package/lib/esm/cli/constants.js +22 -0
- package/lib/esm/cli/options.js +5 -0
- package/lib/esm/cli/utils.js +2 -1
- package/lib/esm/common/currency.js +22 -3
- package/lib/esm/common/factory.js +1 -0
- package/lib/esm/common/signer.js +2 -0
- package/lib/esm/common/token/index.js +5 -0
- package/lib/esm/common/token/polygon.js +12 -0
- package/lib/esm/common/turbo.js +4 -2
- package/lib/esm/node/factory.js +1 -0
- package/lib/esm/types.js +8 -1
- package/lib/esm/utils/common.js +1 -0
- package/lib/esm/utils/errors.js +5 -0
- package/lib/esm/version.js +1 -1
- package/lib/esm/web/factory.js +1 -0
- package/lib/types/cli/commands/balance.d.ts +3 -0
- package/lib/types/cli/commands/balance.d.ts.map +1 -0
- package/lib/types/cli/commands/cryptoFund.d.ts +3 -0
- package/lib/types/cli/commands/cryptoFund.d.ts.map +1 -0
- package/lib/types/cli/commands/index.d.ts +23 -0
- package/lib/types/cli/commands/index.d.ts.map +1 -0
- package/lib/types/cli/commands/price.d.ts +3 -0
- package/lib/types/cli/commands/price.d.ts.map +1 -0
- package/lib/types/cli/commands/topUp.d.ts +3 -0
- package/lib/types/cli/commands/topUp.d.ts.map +1 -0
- package/lib/types/cli/commands/uploadFile.d.ts +3 -0
- package/lib/types/cli/commands/uploadFile.d.ts.map +1 -0
- package/lib/types/cli/commands/uploadFolder.d.ts +3 -0
- package/lib/types/cli/commands/uploadFolder.d.ts.map +1 -0
- package/lib/types/cli/constants.d.ts +5 -0
- package/lib/types/cli/constants.d.ts.map +1 -0
- package/lib/types/cli/options.d.ts +5 -0
- package/lib/types/cli/options.d.ts.map +1 -1
- package/lib/types/cli/types.d.ts +4 -0
- package/lib/types/cli/types.d.ts.map +1 -1
- package/lib/types/cli/utils.d.ts.map +1 -1
- package/lib/types/common/currency.d.ts +7 -4
- package/lib/types/common/currency.d.ts.map +1 -1
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts +1 -6
- package/lib/types/common/token/index.d.ts.map +1 -1
- package/lib/types/common/token/polygon.d.ts +23 -0
- package/lib/types/common/token/polygon.d.ts.map +1 -0
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/node/factory.d.ts.map +1 -1
- package/lib/types/types.d.ts +1 -1
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/common.d.ts.map +1 -1
- package/lib/types/utils/errors.d.ts +3 -0
- package/lib/types/utils/errors.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/lib/types/version.d.ts.map +1 -1
- package/lib/types/web/factory.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/cli/commands.js +0 -178
- package/lib/esm/cli/commands.js +0 -167
- package/lib/types/cli/commands.d.ts +0 -9
- package/lib/types/cli/commands.d.ts.map +0 -1
package/README.md
CHANGED
@@ -29,6 +29,7 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
29
29
|
- [ArconnectSigner](#arconnectsigner)
|
30
30
|
- [EthereumSigner](#ethereumsigner)
|
31
31
|
- [Ethereum Private Key](#ethereum-private-key)
|
32
|
+
- [POL (MATIC) Private Key](#pol-matic-private-key)
|
32
33
|
- [HexSolanaSigner](#hexsolanasigner)
|
33
34
|
- [Solana Secret Key](#solana-secret-key)
|
34
35
|
- [KYVE Private Key](#kyve-private-key)
|
@@ -46,6 +47,7 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
46
47
|
- [Arweave (AR) Fiat Top Up](#arweave-ar-fiat-top-up)
|
47
48
|
- [Ethereum (ETH) Fiat Top Up](#ethereum-eth-fiat-top-up)
|
48
49
|
- [Solana (SOL) Fiat Top Up](#solana-sol-fiat-top-up)
|
50
|
+
- [Polygon (POL / MATIC) Fiat Top Up](#polygon-pol--matic-fiat-top-up)
|
49
51
|
- [KYVE Fiat Top Up](#kyve-fiat-top-up)
|
50
52
|
- [`submitFundTransaction({ txId })`](#submitfundtransaction-txid-)
|
51
53
|
- [TurboAuthenticatedClient](#turboauthenticatedclient)
|
@@ -60,6 +62,7 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
60
62
|
- [`topUpWithTokens({ tokenAmount, feeMultiplier })`](#topupwithtokens-tokenamount-feemultiplier-)
|
61
63
|
- [Arweave (AR) Crypto Top Up](#arweave-ar-crypto-top-up)
|
62
64
|
- [Ethereum (ETH) Crypto Top Up](#ethereum-eth-crypto-top-up)
|
65
|
+
- [Polygon (POL / MATIC) Crypto Top Up](#polygon-pol--matic-crypto-top-up)
|
63
66
|
- [Solana (SOL) Crypto Top Up](#solana-sol-crypto-top-up)
|
64
67
|
- [KYVE Crypto Top Up](#kyve-crypto-top-up)
|
65
68
|
- [CLI](#cli)
|
@@ -72,6 +75,7 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
72
75
|
- [`crypto-fund`](#crypto-fund)
|
73
76
|
- [`upload-folder`](#upload-folder)
|
74
77
|
- [`upload-file`](#upload-file)
|
78
|
+
- [`price`](#price)
|
75
79
|
- [Developers](#developers)
|
76
80
|
- [Requirements](#requirements)
|
77
81
|
- [Setup & Build](#setup--build)
|
@@ -269,6 +273,15 @@ const turbo = TurboFactory.authenticated({
|
|
269
273
|
});
|
270
274
|
```
|
271
275
|
|
276
|
+
##### POL (MATIC) Private Key
|
277
|
+
|
278
|
+
```typescript
|
279
|
+
const turbo = TurboFactory.authenticated({
|
280
|
+
privateKey: ethHexadecimalPrivateKey,
|
281
|
+
token: 'pol',
|
282
|
+
});
|
283
|
+
```
|
284
|
+
|
272
285
|
##### HexSolanaSigner
|
273
286
|
|
274
287
|
```typescript
|
@@ -433,6 +446,17 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
|
|
433
446
|
});
|
434
447
|
```
|
435
448
|
|
449
|
+
##### Polygon (POL / MATIC) Fiat Top Up
|
450
|
+
|
451
|
+
```ts
|
452
|
+
const turbo = TurboFactory.unauthenticated({ token: 'pol' });
|
453
|
+
|
454
|
+
const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
|
455
|
+
amount: USD(10.0), // $10.00 USD
|
456
|
+
owner: publicPolygonAddress,
|
457
|
+
});
|
458
|
+
```
|
459
|
+
|
436
460
|
##### KYVE Fiat Top Up
|
437
461
|
|
438
462
|
```ts
|
@@ -623,6 +647,16 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
|
623
647
|
});
|
624
648
|
```
|
625
649
|
|
650
|
+
##### Polygon (POL / MATIC) Crypto Top Up
|
651
|
+
|
652
|
+
```ts
|
653
|
+
const turbo = TurboFactory.authenticated({ signer, token: 'pol' });
|
654
|
+
|
655
|
+
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
656
|
+
tokenAmount: POLToTokenAmount(0.00001), // 0.00001 POL
|
657
|
+
});
|
658
|
+
```
|
659
|
+
|
626
660
|
##### Solana (SOL) Crypto Top Up
|
627
661
|
|
628
662
|
```ts
|
@@ -695,7 +729,7 @@ npx turbo --help
|
|
695
729
|
- `-g, --gateway <url>` - Set a custom crypto gateway URL
|
696
730
|
- `-t, --token <token>` - Token type for the command or connected wallet (default: "arweave")
|
697
731
|
|
698
|
-
- `-w, --wallet-file <filePath>` - Wallet file to use with the action. Formats accepted: JWK.json, KYVE or
|
732
|
+
- `-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
|
699
733
|
- `-m, --mnemonic <phrase>` - Mnemonic to use with the action (KYVE only)
|
700
734
|
- `-p, --private-key <key>` - Private key to use with the action
|
701
735
|
|
@@ -787,6 +821,29 @@ e.g:
|
|
787
821
|
turbo upload-file --file-path '../path/to/my/file.txt' --token ethereum --wallet-file ../path/to/eth/private/key.txt
|
788
822
|
```
|
789
823
|
|
824
|
+
##### `price`
|
825
|
+
|
826
|
+
Get the current credit price estimate from Turbo Payment Service for a given value and price type.
|
827
|
+
|
828
|
+
Command Options:
|
829
|
+
|
830
|
+
- `--value <value>` - Value to get the price for. e.g: 10.50 for $10.50 USD, 1024 for 1 KiB, 1.1 for 1.1 AR
|
831
|
+
- `--type <type>` - Type of price to get. e.g: 'bytes', 'arweave', 'usd', 'kyve'. Default: 'bytes'
|
832
|
+
|
833
|
+
e.g:
|
834
|
+
|
835
|
+
```shell
|
836
|
+
turbo price --value 10.50 --type usd
|
837
|
+
```
|
838
|
+
|
839
|
+
```shell
|
840
|
+
turbo price --value 1024 --type bytes
|
841
|
+
```
|
842
|
+
|
843
|
+
```shell
|
844
|
+
turbo price --value 1.1 --type arweave
|
845
|
+
```
|
846
|
+
|
790
847
|
## Developers
|
791
848
|
|
792
849
|
### Requirements
|
@@ -310504,7 +310504,7 @@ var import_winston = __toESM(require_winston(), 1);
|
|
310504
310504
|
init_dirname();
|
310505
310505
|
init_buffer2();
|
310506
310506
|
init_process2();
|
310507
|
-
var version16 = "1.
|
310507
|
+
var version16 = "1.17.0-alpha.1";
|
310508
310508
|
|
310509
310509
|
// src/common/logger.ts
|
310510
310510
|
var TurboWinstonLogger = class _TurboWinstonLogger {
|
@@ -314606,6 +314606,11 @@ var FailedRequestError = class extends BaseError {
|
|
314606
314606
|
super(`Failed request: ${status}: ${message}`);
|
314607
314607
|
}
|
314608
314608
|
};
|
314609
|
+
var ProvidedInputError = class extends BaseError {
|
314610
|
+
constructor(message) {
|
314611
|
+
super(message ?? `User has provided an invalid input`);
|
314612
|
+
}
|
314613
|
+
};
|
314609
314614
|
|
314610
314615
|
// src/common/http.ts
|
314611
314616
|
var TurboHTTPService = class {
|
@@ -315358,8 +315363,10 @@ var TurboUnauthenticatedClient = class {
|
|
315358
315363
|
/**
|
315359
315364
|
* Returns the connected target Turbo wallet addresses for all supported tokens.
|
315360
315365
|
*/
|
315361
|
-
getTurboCryptoWallets() {
|
315362
|
-
|
315366
|
+
async getTurboCryptoWallets() {
|
315367
|
+
const wallets = await this.paymentService.getTurboCryptoWallets();
|
315368
|
+
wallets.pol = wallets.matic;
|
315369
|
+
return wallets;
|
315363
315370
|
}
|
315364
315371
|
};
|
315365
315372
|
var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
@@ -315423,6 +315430,7 @@ var TurboBaseFactory = class {
|
|
315423
315430
|
uploadServiceConfig = {},
|
315424
315431
|
token
|
315425
315432
|
} = {}) {
|
315433
|
+
token = token === "pol" ? "matic" : token;
|
315426
315434
|
const paymentService = new TurboUnauthenticatedPaymentService({
|
315427
315435
|
...paymentServiceConfig,
|
315428
315436
|
logger: this.logger,
|
@@ -315450,16 +315458,40 @@ init_dirname();
|
|
315450
315458
|
init_buffer2();
|
315451
315459
|
init_process2();
|
315452
315460
|
var ZeroDecimalCurrency = class {
|
315453
|
-
constructor(
|
315454
|
-
this.
|
315461
|
+
constructor(amt, type3) {
|
315462
|
+
this.amt = amt;
|
315455
315463
|
this.type = type3;
|
315464
|
+
if (amt < 0) {
|
315465
|
+
throw new ProvidedInputError(
|
315466
|
+
`${type3} currency amount cannot be negative`
|
315467
|
+
);
|
315468
|
+
}
|
315469
|
+
this.assertDecimalPlaces(amt);
|
315470
|
+
}
|
315471
|
+
assertDecimalPlaces(a8) {
|
315472
|
+
if (a8 % 1 !== 0) {
|
315473
|
+
throw new ProvidedInputError(
|
315474
|
+
`${this.type} currency amount must have zero decimal places`
|
315475
|
+
);
|
315476
|
+
}
|
315477
|
+
}
|
315478
|
+
get amount() {
|
315479
|
+
return this.amt;
|
315456
315480
|
}
|
315457
315481
|
};
|
315458
|
-
var TwoDecimalCurrency = class {
|
315482
|
+
var TwoDecimalCurrency = class extends ZeroDecimalCurrency {
|
315459
315483
|
constructor(a8, type3) {
|
315484
|
+
super(a8, type3);
|
315460
315485
|
this.a = a8;
|
315461
315486
|
this.type = type3;
|
315462
315487
|
}
|
315488
|
+
assertDecimalPlaces(a8) {
|
315489
|
+
if (a8 * 100 % 1 !== 0) {
|
315490
|
+
throw new ProvidedInputError(
|
315491
|
+
`${this.type} currency amount must have two decimal places`
|
315492
|
+
);
|
315493
|
+
}
|
315494
|
+
}
|
315463
315495
|
get amount() {
|
315464
315496
|
return this.a * 100;
|
315465
315497
|
}
|
@@ -315511,7 +315543,14 @@ var fiatCurrencyTypes = [
|
|
315511
315543
|
function isCurrency(currency) {
|
315512
315544
|
return fiatCurrencyTypes.includes(currency);
|
315513
315545
|
}
|
315514
|
-
var tokenTypes = [
|
315546
|
+
var tokenTypes = [
|
315547
|
+
"arweave",
|
315548
|
+
"solana",
|
315549
|
+
"ethereum",
|
315550
|
+
"kyve",
|
315551
|
+
"matic",
|
315552
|
+
"pol"
|
315553
|
+
];
|
315515
315554
|
var isNodeUploadFolderParams = (p8) => p8.folderPath !== void 0;
|
315516
315555
|
var isWebUploadFolderParams = (p8) => p8.files !== void 0;
|
315517
315556
|
function isKyvePrivateKey(wallet) {
|
@@ -315580,6 +315619,7 @@ function createTurboSigner({
|
|
315580
315619
|
case "solana":
|
315581
315620
|
return new HexSolanaSigner2(clientProvidedPrivateKey);
|
315582
315621
|
case "ethereum":
|
315622
|
+
case "matic":
|
315583
315623
|
if (!isEthPrivateKey(clientProvidedPrivateKey)) {
|
315584
315624
|
throw new Error(
|
315585
315625
|
"A valid Ethereum private key must be provided for EthereumSigner."
|
@@ -339329,6 +339369,25 @@ async function signerFromKyveMnemonic(mnemonic) {
|
|
339329
339369
|
return signerFromKyvePrivateKey2(privateKey);
|
339330
339370
|
}
|
339331
339371
|
|
339372
|
+
// src/common/token/polygon.ts
|
339373
|
+
init_dirname();
|
339374
|
+
init_buffer2();
|
339375
|
+
init_process2();
|
339376
|
+
var POLToTokenAmount = ETHToTokenAmount;
|
339377
|
+
var PolygonToken = class extends EthereumToken {
|
339378
|
+
constructor({
|
339379
|
+
logger: logger15 = TurboWinstonLogger.default,
|
339380
|
+
gatewayUrl = "https://polygon-rpc.com/",
|
339381
|
+
pollingOptions = {
|
339382
|
+
maxAttempts: 10,
|
339383
|
+
pollingIntervalMs: 4e3,
|
339384
|
+
initialBackoffMs: 5e3
|
339385
|
+
}
|
339386
|
+
} = {}) {
|
339387
|
+
super({ logger: logger15, gatewayUrl, pollingOptions });
|
339388
|
+
}
|
339389
|
+
};
|
339390
|
+
|
339332
339391
|
// src/common/token/solana.ts
|
339333
339392
|
init_dirname();
|
339334
339393
|
init_buffer2();
|
@@ -349997,13 +350056,17 @@ var defaultTokenMap = {
|
|
349997
350056
|
arweave: (config2) => new ArweaveToken(config2),
|
349998
350057
|
solana: (config2) => new SolanaToken(config2),
|
349999
350058
|
ethereum: (config2) => new EthereumToken(config2),
|
350000
|
-
kyve: (config2) => new KyveToken(config2)
|
350059
|
+
kyve: (config2) => new KyveToken(config2),
|
350060
|
+
matic: (config2) => new PolygonToken(config2),
|
350061
|
+
pol: (config2) => new PolygonToken(config2)
|
350001
350062
|
};
|
350002
350063
|
var tokenToBaseMap = {
|
350003
350064
|
arweave: (a8) => ARToTokenAmount(a8),
|
350004
350065
|
solana: (a8) => SOLToTokenAmount(a8),
|
350005
350066
|
ethereum: (a8) => ETHToTokenAmount(a8),
|
350006
|
-
kyve: (a8) => KYVEToTokenAmount(a8)
|
350067
|
+
kyve: (a8) => KYVEToTokenAmount(a8),
|
350068
|
+
matic: (a8) => POLToTokenAmount(a8),
|
350069
|
+
pol: (a8) => POLToTokenAmount(a8)
|
350007
350070
|
};
|
350008
350071
|
function isTokenType(token) {
|
350009
350072
|
return tokenTypes.includes(token);
|
@@ -350041,6 +350104,8 @@ var TurboDataItemAbstractSigner = class {
|
|
350041
350104
|
case "solana":
|
350042
350105
|
return import_bs584.default.encode(fromB64Url(owner));
|
350043
350106
|
case "ethereum":
|
350107
|
+
case "matic":
|
350108
|
+
case "pol":
|
350044
350109
|
return computeAddress2(computePublicKey(fromB64Url(owner)));
|
350045
350110
|
case "kyve":
|
350046
350111
|
return (0, import_amino3.pubkeyToAddress)(
|
@@ -350264,6 +350329,7 @@ var TurboFactory = class extends TurboBaseFactory {
|
|
350264
350329
|
tokenMap,
|
350265
350330
|
tokenTools
|
350266
350331
|
}) {
|
350332
|
+
token = token === "pol" ? "matic" : token;
|
350267
350333
|
if (!token) {
|
350268
350334
|
if (providedSigner) {
|
350269
350335
|
if (providedSigner instanceof EthereumSigner) {
|
package/lib/cjs/cli/cli.js
CHANGED
@@ -20,7 +20,7 @@ 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
|
23
|
+
const index_js_1 = require("./commands/index.js");
|
24
24
|
const options_js_1 = require("./options.js");
|
25
25
|
const utils_js_1 = require("./utils.js");
|
26
26
|
(0, utils_js_1.applyOptions)(commander_1.program
|
@@ -29,19 +29,24 @@ const utils_js_1 = require("./utils.js");
|
|
29
29
|
.description('Turbo CLI')
|
30
30
|
.helpCommand(true), options_js_1.globalOptions);
|
31
31
|
(0, utils_js_1.applyOptions)(commander_1.program.command('balance').description('Get balance of a Turbo address'), [options_js_1.optionMap.address, ...options_js_1.walletOptions]).action(async (_commandOptions, command) => {
|
32
|
-
await (0, utils_js_1.runCommand)(command,
|
32
|
+
await (0, utils_js_1.runCommand)(command, index_js_1.balance);
|
33
33
|
});
|
34
34
|
(0, utils_js_1.applyOptions)(commander_1.program.command('top-up').description('Top up a Turbo address with Fiat'), [...options_js_1.walletOptions, options_js_1.optionMap.address, options_js_1.optionMap.value, options_js_1.optionMap.currency]).action(async (_commandOptions, command) => {
|
35
|
-
await (0, utils_js_1.runCommand)(command,
|
35
|
+
await (0, utils_js_1.runCommand)(command, index_js_1.topUp);
|
36
36
|
});
|
37
37
|
(0, utils_js_1.applyOptions)(commander_1.program.command('crypto-fund').description('Top up a wallet with crypto'), [...options_js_1.walletOptions, options_js_1.optionMap.value, options_js_1.optionMap.txId]).action(async (_commandOptions, command) => {
|
38
|
-
await (0, utils_js_1.runCommand)(command,
|
38
|
+
await (0, utils_js_1.runCommand)(command, index_js_1.cryptoFund);
|
39
39
|
});
|
40
40
|
(0, utils_js_1.applyOptions)(commander_1.program.command('upload-folder').description('Upload a folder using Turbo'), options_js_1.uploadFolderOptions).action(async (_commandOptions, command) => {
|
41
|
-
await (0, utils_js_1.runCommand)(command,
|
41
|
+
await (0, utils_js_1.runCommand)(command, index_js_1.uploadFolder);
|
42
42
|
});
|
43
43
|
(0, utils_js_1.applyOptions)(commander_1.program.command('upload-file').description('Upload a file using Turbo'), options_js_1.uploadFileOptions).action(async (_commandOptions, command) => {
|
44
|
-
await (0, utils_js_1.runCommand)(command,
|
44
|
+
await (0, utils_js_1.runCommand)(command, index_js_1.uploadFile);
|
45
|
+
});
|
46
|
+
(0, utils_js_1.applyOptions)(commander_1.program
|
47
|
+
.command('price')
|
48
|
+
.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
|
+
await (0, utils_js_1.runCommand)(command, index_js_1.price);
|
45
50
|
});
|
46
51
|
if (process.argv[1].includes('bin/turbo') || // Running from global .bin
|
47
52
|
process.argv[1].includes('cli/cli') // Running from source
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.balance = balance;
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const factory_js_1 = require("../../node/factory.js");
|
21
|
+
const utils_js_1 = require("../utils.js");
|
22
|
+
async function balance(options) {
|
23
|
+
const config = (0, utils_js_1.configFromOptions)(options);
|
24
|
+
const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
|
25
|
+
if (address !== undefined) {
|
26
|
+
const turbo = factory_js_1.TurboFactory.unauthenticated(config);
|
27
|
+
const { winc } = await turbo.getBalance(address);
|
28
|
+
console.log(`Turbo Balance for Native Address "${address}"\nCredits: ${+winc / 1_000_000_000_000}`);
|
29
|
+
return;
|
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 { winc } = await turbo.getBalance();
|
39
|
+
console.log(`Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${+winc / 1_000_000_000_000}`);
|
40
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.cryptoFund = cryptoFund;
|
7
|
+
/**
|
8
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
9
|
+
*
|
10
|
+
* This program is free software: you can redistribute it and/or modify
|
11
|
+
* it under the terms of the GNU Affero General Public License as published by
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
13
|
+
* (at your option) any later version.
|
14
|
+
*
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
+
* GNU Affero General Public License for more details.
|
19
|
+
*
|
20
|
+
* You should have received a copy of the GNU Affero General Public License
|
21
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
*/
|
23
|
+
const prompts_1 = __importDefault(require("prompts"));
|
24
|
+
const index_js_1 = require("../../common/index.js");
|
25
|
+
const factory_js_1 = require("../../node/factory.js");
|
26
|
+
const utils_js_1 = require("../utils.js");
|
27
|
+
async function cryptoFund(options) {
|
28
|
+
const value = options.value;
|
29
|
+
const txId = options.txId;
|
30
|
+
if (txId !== undefined) {
|
31
|
+
const turbo = factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
|
32
|
+
const result = await turbo.submitFundTransaction({ txId: txId });
|
33
|
+
console.log('Submitted existing crypto fund transaction to payment service: \n', JSON.stringify(result, null, 2));
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
if (value === undefined) {
|
37
|
+
throw new Error('Must provide a --value or --transaction-id for crypto-fund command');
|
38
|
+
}
|
39
|
+
const turbo = await (0, utils_js_1.turboFromOptions)(options);
|
40
|
+
const token = (0, utils_js_1.tokenFromOptions)(options);
|
41
|
+
const tokenAmount = index_js_1.tokenToBaseMap[token](value);
|
42
|
+
if (!options.skipConfirmation) {
|
43
|
+
const { winc } = await turbo.getWincForToken({ tokenAmount });
|
44
|
+
const targetWallet = (await turbo.getTurboCryptoWallets())[token];
|
45
|
+
const credits = (+winc / 1_000_000_000_000).toFixed(12);
|
46
|
+
const { confirm } = await (0, prompts_1.default)({
|
47
|
+
type: 'confirm',
|
48
|
+
name: 'confirm',
|
49
|
+
message: `\nTransaction details:\n\n Amount: ${value} ${token}\n Target: ${targetWallet}\n Credits received: ${credits}\n Credit recipient: ${await turbo.signer.getNativeAddress()}\n Network fees: (Gas fees apply)\n\nThis payment is non-refundable. Proceed with transaction?`,
|
50
|
+
initial: true,
|
51
|
+
});
|
52
|
+
if (!confirm) {
|
53
|
+
console.log('Aborted crypto fund transaction');
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
const result = await turbo.topUpWithTokens({
|
58
|
+
tokenAmount,
|
59
|
+
});
|
60
|
+
console.log('Sent crypto fund transaction: \n', JSON.stringify(result, null, 2));
|
61
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
4
|
+
*
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU Affero General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
19
|
+
if (k2 === undefined) k2 = k;
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
23
|
+
}
|
24
|
+
Object.defineProperty(o, k2, desc);
|
25
|
+
}) : (function(o, m, k, k2) {
|
26
|
+
if (k2 === undefined) k2 = k;
|
27
|
+
o[k2] = m[k];
|
28
|
+
}));
|
29
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
30
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
31
|
+
};
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
33
|
+
__exportStar(require("./balance.js"), exports);
|
34
|
+
__exportStar(require("./cryptoFund.js"), exports);
|
35
|
+
__exportStar(require("./price.js"), exports);
|
36
|
+
__exportStar(require("./topUp.js"), exports);
|
37
|
+
__exportStar(require("./uploadFile.js"), exports);
|
38
|
+
__exportStar(require("./uploadFolder.js"), exports);
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.price = price;
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const currency_js_1 = require("../../common/currency.js");
|
21
|
+
const index_js_1 = require("../../common/index.js");
|
22
|
+
const factory_js_1 = require("../../node/factory.js");
|
23
|
+
const types_js_1 = require("../../types.js");
|
24
|
+
const utils_js_1 = require("../utils.js");
|
25
|
+
async function price(options) {
|
26
|
+
const value = options.value;
|
27
|
+
if (value === undefined || +value <= 0 || isNaN(+value)) {
|
28
|
+
throw new Error('Must provide a positive number --value to get price');
|
29
|
+
}
|
30
|
+
const type = options.type ?? 'bytes';
|
31
|
+
const winc = await (async () => {
|
32
|
+
if ((0, index_js_1.isTokenType)(type)) {
|
33
|
+
const turbo = factory_js_1.TurboFactory.unauthenticated({
|
34
|
+
...(0, utils_js_1.configFromOptions)(options),
|
35
|
+
token: type,
|
36
|
+
});
|
37
|
+
return (await turbo.getWincForToken({
|
38
|
+
tokenAmount: index_js_1.tokenToBaseMap[type](value),
|
39
|
+
})).winc;
|
40
|
+
}
|
41
|
+
const turbo = factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
|
42
|
+
if (type === 'bytes') {
|
43
|
+
return (await turbo.getUploadCosts({ bytes: [+value] }))[0].winc;
|
44
|
+
}
|
45
|
+
if ((0, types_js_1.isCurrency)(type)) {
|
46
|
+
return (await turbo.getWincForFiat({
|
47
|
+
amount: currency_js_1.currencyMap[type](+value),
|
48
|
+
})).winc;
|
49
|
+
}
|
50
|
+
throw new Error(`Invalid price type!\nMust be one of: bytes, ${types_js_1.fiatCurrencyTypes.join(', ') + ' ' + types_js_1.tokenTypes.join(', ')}`);
|
51
|
+
})();
|
52
|
+
console.log(`Current price estimate for ${value} ${type} is ~${(+winc / 1_000_000_000_000).toFixed(12)} Credits`);
|
53
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.topUp = topUp;
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const child_process_1 = require("child_process");
|
21
|
+
const currency_js_1 = require("../../common/currency.js");
|
22
|
+
const factory_js_1 = require("../../node/factory.js");
|
23
|
+
const types_js_1 = require("../../types.js");
|
24
|
+
const common_js_1 = require("../../utils/common.js");
|
25
|
+
const utils_js_1 = require("../utils.js");
|
26
|
+
function openUrl(url) {
|
27
|
+
if (process.platform === 'darwin') {
|
28
|
+
// macOS
|
29
|
+
(0, child_process_1.exec)(`open ${url}`);
|
30
|
+
}
|
31
|
+
else if (process.platform === 'win32') {
|
32
|
+
// Windows
|
33
|
+
(0, child_process_1.exec)(`start "" "${url}"`, { windowsHide: true });
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
// Linux/Unix
|
37
|
+
open(url);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
async function topUp(options) {
|
41
|
+
const config = (0, utils_js_1.configFromOptions)(options);
|
42
|
+
const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
|
43
|
+
const value = options.value;
|
44
|
+
if (value === undefined) {
|
45
|
+
throw new Error('Must provide a --value to top up');
|
46
|
+
}
|
47
|
+
const currency = (options.currency ?? 'usd').toLowerCase();
|
48
|
+
if (!(0, types_js_1.isCurrency)(currency)) {
|
49
|
+
throw new Error(`Invalid fiat currency type ${currency}!\nPlease use one of these:\n${JSON.stringify(types_js_1.fiatCurrencyTypes, null, 2)}`);
|
50
|
+
}
|
51
|
+
// TODO: Pay in CLI prompts via --cli options
|
52
|
+
const { url, paymentAmount, winc } = await (async () => {
|
53
|
+
const amount = currency_js_1.currencyMap[currency](+value);
|
54
|
+
if (address !== undefined) {
|
55
|
+
const turbo = factory_js_1.TurboFactory.unauthenticated(config);
|
56
|
+
return turbo.createCheckoutSession({
|
57
|
+
amount,
|
58
|
+
owner: address,
|
59
|
+
});
|
60
|
+
}
|
61
|
+
if (privateKey === undefined) {
|
62
|
+
throw new Error('Must provide a wallet to top up');
|
63
|
+
}
|
64
|
+
const turbo = factory_js_1.TurboFactory.authenticated({
|
65
|
+
...config,
|
66
|
+
privateKey,
|
67
|
+
});
|
68
|
+
return turbo.createCheckoutSession({
|
69
|
+
amount,
|
70
|
+
owner: await turbo.signer.getNativeAddress(),
|
71
|
+
});
|
72
|
+
})();
|
73
|
+
if (url === undefined) {
|
74
|
+
throw new Error('Failed to create checkout session');
|
75
|
+
}
|
76
|
+
console.log('Got Checkout Session\n' + JSON.stringify({ url, paymentAmount, winc }));
|
77
|
+
console.log('Opening checkout session in browser...');
|
78
|
+
await (0, common_js_1.sleep)(2000);
|
79
|
+
openUrl(url);
|
80
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.uploadFile = uploadFile;
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const fs_1 = require("fs");
|
21
|
+
const constants_js_1 = require("../constants.js");
|
22
|
+
const utils_js_1 = require("../utils.js");
|
23
|
+
async function uploadFile(options) {
|
24
|
+
const { filePath } = options;
|
25
|
+
if (filePath === undefined) {
|
26
|
+
throw new Error('Must provide a --file-path to upload');
|
27
|
+
}
|
28
|
+
const turbo = await (0, utils_js_1.turboFromOptions)(options);
|
29
|
+
const fileSize = (0, fs_1.statSync)(filePath).size;
|
30
|
+
const result = await turbo.uploadFile({
|
31
|
+
fileStreamFactory: () => (0, fs_1.createReadStream)(filePath),
|
32
|
+
fileSizeFactory: () => fileSize,
|
33
|
+
dataItemOpts: { tags: [...constants_js_1.turboCliTags] }, // TODO: Inject user tags
|
34
|
+
});
|
35
|
+
console.log('Uploaded file:', JSON.stringify(result, null, 2));
|
36
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.uploadFolder = uploadFolder;
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const constants_js_1 = require("../constants.js");
|
21
|
+
const utils_js_1 = require("../utils.js");
|
22
|
+
async function uploadFolder(options) {
|
23
|
+
const turbo = await (0, utils_js_1.turboFromOptions)(options);
|
24
|
+
const { disableManifest, fallbackFile, folderPath, indexFile, maxConcurrentUploads, } = (0, utils_js_1.getUploadFolderOptions)(options);
|
25
|
+
const result = await turbo.uploadFolder({
|
26
|
+
folderPath: folderPath,
|
27
|
+
dataItemOpts: { tags: [...constants_js_1.turboCliTags] }, // TODO: Inject user tags
|
28
|
+
manifestOptions: {
|
29
|
+
disableManifest,
|
30
|
+
indexFile,
|
31
|
+
fallbackFile,
|
32
|
+
},
|
33
|
+
maxConcurrentUploads,
|
34
|
+
});
|
35
|
+
console.log('Uploaded folder:', JSON.stringify(result, null, 2));
|
36
|
+
}
|