@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.
Files changed (92) hide show
  1. package/README.md +58 -1
  2. package/bundles/web.bundle.min.js +75 -9
  3. package/lib/cjs/cli/cli.js +11 -6
  4. package/lib/cjs/cli/commands/balance.js +40 -0
  5. package/lib/cjs/cli/commands/cryptoFund.js +61 -0
  6. package/lib/cjs/cli/commands/index.js +38 -0
  7. package/lib/cjs/cli/commands/price.js +53 -0
  8. package/lib/cjs/cli/commands/topUp.js +80 -0
  9. package/lib/cjs/cli/commands/uploadFile.js +36 -0
  10. package/lib/cjs/cli/commands/uploadFolder.js +36 -0
  11. package/lib/cjs/cli/constants.js +25 -0
  12. package/lib/cjs/cli/options.js +5 -0
  13. package/lib/cjs/cli/utils.js +2 -1
  14. package/lib/cjs/common/currency.js +22 -3
  15. package/lib/cjs/common/factory.js +1 -0
  16. package/lib/cjs/common/signer.js +2 -0
  17. package/lib/cjs/common/token/index.js +5 -0
  18. package/lib/cjs/common/token/polygon.js +16 -0
  19. package/lib/cjs/common/turbo.js +4 -2
  20. package/lib/cjs/node/factory.js +1 -0
  21. package/lib/cjs/types.js +8 -1
  22. package/lib/cjs/utils/common.js +1 -0
  23. package/lib/cjs/utils/errors.js +7 -1
  24. package/lib/cjs/version.js +1 -1
  25. package/lib/cjs/web/factory.js +1 -0
  26. package/lib/esm/cli/cli.js +7 -2
  27. package/lib/esm/cli/commands/balance.js +37 -0
  28. package/lib/esm/cli/commands/cryptoFund.js +55 -0
  29. package/lib/esm/cli/commands/index.js +22 -0
  30. package/lib/esm/cli/commands/price.js +50 -0
  31. package/lib/esm/cli/commands/topUp.js +77 -0
  32. package/lib/esm/cli/commands/uploadFile.js +33 -0
  33. package/lib/esm/cli/commands/uploadFolder.js +33 -0
  34. package/lib/esm/cli/constants.js +22 -0
  35. package/lib/esm/cli/options.js +5 -0
  36. package/lib/esm/cli/utils.js +2 -1
  37. package/lib/esm/common/currency.js +22 -3
  38. package/lib/esm/common/factory.js +1 -0
  39. package/lib/esm/common/signer.js +2 -0
  40. package/lib/esm/common/token/index.js +5 -0
  41. package/lib/esm/common/token/polygon.js +12 -0
  42. package/lib/esm/common/turbo.js +4 -2
  43. package/lib/esm/node/factory.js +1 -0
  44. package/lib/esm/types.js +8 -1
  45. package/lib/esm/utils/common.js +1 -0
  46. package/lib/esm/utils/errors.js +5 -0
  47. package/lib/esm/version.js +1 -1
  48. package/lib/esm/web/factory.js +1 -0
  49. package/lib/types/cli/commands/balance.d.ts +3 -0
  50. package/lib/types/cli/commands/balance.d.ts.map +1 -0
  51. package/lib/types/cli/commands/cryptoFund.d.ts +3 -0
  52. package/lib/types/cli/commands/cryptoFund.d.ts.map +1 -0
  53. package/lib/types/cli/commands/index.d.ts +23 -0
  54. package/lib/types/cli/commands/index.d.ts.map +1 -0
  55. package/lib/types/cli/commands/price.d.ts +3 -0
  56. package/lib/types/cli/commands/price.d.ts.map +1 -0
  57. package/lib/types/cli/commands/topUp.d.ts +3 -0
  58. package/lib/types/cli/commands/topUp.d.ts.map +1 -0
  59. package/lib/types/cli/commands/uploadFile.d.ts +3 -0
  60. package/lib/types/cli/commands/uploadFile.d.ts.map +1 -0
  61. package/lib/types/cli/commands/uploadFolder.d.ts +3 -0
  62. package/lib/types/cli/commands/uploadFolder.d.ts.map +1 -0
  63. package/lib/types/cli/constants.d.ts +5 -0
  64. package/lib/types/cli/constants.d.ts.map +1 -0
  65. package/lib/types/cli/options.d.ts +5 -0
  66. package/lib/types/cli/options.d.ts.map +1 -1
  67. package/lib/types/cli/types.d.ts +4 -0
  68. package/lib/types/cli/types.d.ts.map +1 -1
  69. package/lib/types/cli/utils.d.ts.map +1 -1
  70. package/lib/types/common/currency.d.ts +7 -4
  71. package/lib/types/common/currency.d.ts.map +1 -1
  72. package/lib/types/common/factory.d.ts.map +1 -1
  73. package/lib/types/common/signer.d.ts.map +1 -1
  74. package/lib/types/common/token/index.d.ts +1 -6
  75. package/lib/types/common/token/index.d.ts.map +1 -1
  76. package/lib/types/common/token/polygon.d.ts +23 -0
  77. package/lib/types/common/token/polygon.d.ts.map +1 -0
  78. package/lib/types/common/turbo.d.ts.map +1 -1
  79. package/lib/types/node/factory.d.ts.map +1 -1
  80. package/lib/types/types.d.ts +1 -1
  81. package/lib/types/types.d.ts.map +1 -1
  82. package/lib/types/utils/common.d.ts.map +1 -1
  83. package/lib/types/utils/errors.d.ts +3 -0
  84. package/lib/types/utils/errors.d.ts.map +1 -1
  85. package/lib/types/version.d.ts +1 -1
  86. package/lib/types/version.d.ts.map +1 -1
  87. package/lib/types/web/factory.d.ts.map +1 -1
  88. package/package.json +1 -1
  89. package/lib/cjs/cli/commands.js +0 -178
  90. package/lib/esm/cli/commands.js +0 -167
  91. package/lib/types/cli/commands.d.ts +0 -9
  92. package/lib/types/cli/commands.d.ts.map +0 -1
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.turboCliTags = void 0;
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 version_js_1 = require("../version.js");
21
+ exports.turboCliTags = [
22
+ { name: 'App-Name', value: 'Turbo-CLI' },
23
+ { name: 'App-Version', value: version_js_1.version },
24
+ { name: 'App-Platform', value: process.platform },
25
+ ];
@@ -28,6 +28,11 @@ exports.optionMap = {
28
28
  description: 'Fiat currency type to use for the action',
29
29
  default: 'usd',
30
30
  },
31
+ type: {
32
+ alias: '--type <priceType>',
33
+ description: 'Price type for the action. Can be a fiat currency or crypto token or bytes',
34
+ default: 'bytes',
35
+ },
31
36
  txId: {
32
37
  alias: '-i, --tx-id <txId>',
33
38
  description: 'Transaction ID or hash to use for action',
@@ -131,7 +131,8 @@ const tokenToDevGatewayMap = {
131
131
  solana: 'https://api.devnet.solana.com',
132
132
  ethereum: 'https://ethereum-holesky-rpc.publicnode.com',
133
133
  kyve: 'https://api.korellia.kyve.network',
134
- // matic: 'https://rpc-amoy.polygon.technology',
134
+ matic: 'https://rpc-amoy.polygon.technology',
135
+ pol: 'https://rpc-amoy.polygon.technology',
135
136
  };
136
137
  function configFromOptions(options) {
137
138
  let config = {};
@@ -1,18 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.currencyMap = exports.JPY = exports.BRL = exports.HKD = exports.SGD = exports.INR = exports.AUD = exports.CAD = exports.GBP = exports.EUR = exports.USD = exports.TwoDecimalCurrency = exports.ZeroDecimalCurrency = void 0;
4
+ const errors_js_1 = require("../utils/errors.js");
4
5
  class ZeroDecimalCurrency {
5
- constructor(amount, type) {
6
- this.amount = amount;
6
+ constructor(amt, type) {
7
+ this.amt = amt;
7
8
  this.type = type;
9
+ if (amt < 0) {
10
+ throw new errors_js_1.ProvidedInputError(`${type} currency amount cannot be negative`);
11
+ }
12
+ this.assertDecimalPlaces(amt);
13
+ }
14
+ assertDecimalPlaces(a) {
15
+ if (a % 1 !== 0) {
16
+ throw new errors_js_1.ProvidedInputError(`${this.type} currency amount must have zero decimal places`);
17
+ }
18
+ }
19
+ get amount() {
20
+ return this.amt;
8
21
  }
9
22
  }
10
23
  exports.ZeroDecimalCurrency = ZeroDecimalCurrency;
11
- class TwoDecimalCurrency {
24
+ class TwoDecimalCurrency extends ZeroDecimalCurrency {
12
25
  constructor(a, type) {
26
+ super(a, type);
13
27
  this.a = a;
14
28
  this.type = type;
15
29
  }
30
+ assertDecimalPlaces(a) {
31
+ if ((a * 100) % 1 !== 0) {
32
+ throw new errors_js_1.ProvidedInputError(`${this.type} currency amount must have two decimal places`);
33
+ }
34
+ }
16
35
  get amount() {
17
36
  return this.a * 100;
18
37
  }
@@ -15,6 +15,7 @@ class TurboBaseFactory {
15
15
  this.logger.setLogFormat(format);
16
16
  }
17
17
  static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, token, } = {}) {
18
+ token = token === 'pol' ? 'matic' : token;
18
19
  const paymentService = new payment_js_1.TurboUnauthenticatedPaymentService({
19
20
  ...paymentServiceConfig,
20
21
  logger: this.logger,
@@ -48,6 +48,8 @@ class TurboDataItemAbstractSigner {
48
48
  case 'solana':
49
49
  return bs58_1.default.encode((0, base64_js_1.fromB64Url)(owner));
50
50
  case 'ethereum':
51
+ case 'matic':
52
+ case 'pol':
51
53
  return (0, ethers_2.computeAddress)((0, signing_key_1.computePublicKey)((0, base64_js_1.fromB64Url)(owner)));
52
54
  case 'kyve':
53
55
  return (0, amino_1.pubkeyToAddress)({
@@ -20,18 +20,23 @@ const types_js_1 = require("../../types.js");
20
20
  const arweave_js_1 = require("./arweave.js");
21
21
  const ethereum_js_1 = require("./ethereum.js");
22
22
  const kyve_js_1 = require("./kyve.js");
23
+ const polygon_js_1 = require("./polygon.js");
23
24
  const solana_js_1 = require("./solana.js");
24
25
  exports.defaultTokenMap = {
25
26
  arweave: (config) => new arweave_js_1.ArweaveToken(config),
26
27
  solana: (config) => new solana_js_1.SolanaToken(config),
27
28
  ethereum: (config) => new ethereum_js_1.EthereumToken(config),
28
29
  kyve: (config) => new kyve_js_1.KyveToken(config),
30
+ matic: (config) => new polygon_js_1.PolygonToken(config),
31
+ pol: (config) => new polygon_js_1.PolygonToken(config),
29
32
  };
30
33
  exports.tokenToBaseMap = {
31
34
  arweave: (a) => (0, arweave_js_1.ARToTokenAmount)(a),
32
35
  solana: (a) => (0, solana_js_1.SOLToTokenAmount)(a),
33
36
  ethereum: (a) => (0, ethereum_js_1.ETHToTokenAmount)(a),
34
37
  kyve: (a) => (0, kyve_js_1.KYVEToTokenAmount)(a),
38
+ matic: (a) => (0, polygon_js_1.POLToTokenAmount)(a),
39
+ pol: (a) => (0, polygon_js_1.POLToTokenAmount)(a),
35
40
  };
36
41
  function isTokenType(token) {
37
42
  return types_js_1.tokenTypes.includes(token);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolygonToken = exports.POLToTokenAmount = void 0;
4
+ const logger_js_1 = require("../logger.js");
5
+ const ethereum_js_1 = require("./ethereum.js");
6
+ exports.POLToTokenAmount = ethereum_js_1.ETHToTokenAmount;
7
+ class PolygonToken extends ethereum_js_1.EthereumToken {
8
+ constructor({ logger = logger_js_1.TurboWinstonLogger.default, gatewayUrl = 'https://polygon-rpc.com/', pollingOptions = {
9
+ maxAttempts: 10,
10
+ pollingIntervalMs: 4_000,
11
+ initialBackoffMs: 5_000,
12
+ }, } = {}) {
13
+ super({ logger, gatewayUrl, pollingOptions });
14
+ }
15
+ }
16
+ exports.PolygonToken = PolygonToken;
@@ -103,8 +103,10 @@ class TurboUnauthenticatedClient {
103
103
  /**
104
104
  * Returns the connected target Turbo wallet addresses for all supported tokens.
105
105
  */
106
- getTurboCryptoWallets() {
107
- return this.paymentService.getTurboCryptoWallets();
106
+ async getTurboCryptoWallets() {
107
+ const wallets = await this.paymentService.getTurboCryptoWallets();
108
+ wallets.pol = wallets.matic;
109
+ return wallets;
108
110
  }
109
111
  }
110
112
  exports.TurboUnauthenticatedClient = TurboUnauthenticatedClient;
@@ -38,6 +38,7 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
38
38
  });
39
39
  }
40
40
  static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, tokenMap, gatewayUrl, tokenTools, }) {
41
+ token = token === 'pol' ? 'matic' : token;
41
42
  if (!token) {
42
43
  if (providedSigner) {
43
44
  // Derive token from signer if not provided
package/lib/cjs/types.js CHANGED
@@ -19,7 +19,14 @@ exports.fiatCurrencyTypes = [
19
19
  function isCurrency(currency) {
20
20
  return exports.fiatCurrencyTypes.includes(currency);
21
21
  }
22
- exports.tokenTypes = ['arweave', 'solana', 'ethereum', 'kyve'];
22
+ exports.tokenTypes = [
23
+ 'arweave',
24
+ 'solana',
25
+ 'ethereum',
26
+ 'kyve',
27
+ 'matic',
28
+ 'pol',
29
+ ];
23
30
  const isNodeUploadFolderParams = (p) => p.folderPath !== undefined;
24
31
  exports.isNodeUploadFolderParams = isNodeUploadFolderParams;
25
32
  const isWebUploadFolderParams = (p) => p.files !== undefined;
@@ -43,6 +43,7 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
43
43
  case 'solana':
44
44
  return new arbundles_1.HexSolanaSigner(clientProvidedPrivateKey);
45
45
  case 'ethereum':
46
+ case 'matic':
46
47
  if (!(0, types_js_1.isEthPrivateKey)(clientProvidedPrivateKey)) {
47
48
  throw new Error('A valid Ethereum private key must be provided for EthereumSigner.');
48
49
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FailedRequestError = exports.UnauthenticatedRequestError = exports.BaseError = void 0;
3
+ exports.ProvidedInputError = exports.FailedRequestError = exports.UnauthenticatedRequestError = exports.BaseError = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
@@ -36,3 +36,9 @@ class FailedRequestError extends BaseError {
36
36
  }
37
37
  }
38
38
  exports.FailedRequestError = FailedRequestError;
39
+ class ProvidedInputError extends BaseError {
40
+ constructor(message) {
41
+ super(message ?? `User has provided an invalid input`);
42
+ }
43
+ }
44
+ exports.ProvidedInputError = ProvidedInputError;
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.version = void 0;
20
20
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
21
- exports.version = '1.16.1';
21
+ exports.version = '1.17.0-alpha.2';
@@ -36,6 +36,7 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
36
36
  });
37
37
  }
38
38
  static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, }) {
39
+ token = token === 'pol' ? 'matic' : token;
39
40
  if (!token) {
40
41
  if (providedSigner) {
41
42
  // Derive token from signer if not provided
@@ -18,7 +18,7 @@
18
18
  // eslint-disable-next-line header/header -- This is a CLI file
19
19
  import { program } from 'commander';
20
20
  import { version } from '../version.js';
21
- import { cryptoFund, getBalance, topUp, uploadFile, uploadFolder, } from './commands.js';
21
+ import { balance, cryptoFund, price, topUp, uploadFile, uploadFolder, } from './commands/index.js';
22
22
  import { globalOptions, optionMap, uploadFileOptions, uploadFolderOptions, walletOptions, } from './options.js';
23
23
  import { applyOptions, runCommand } from './utils.js';
24
24
  applyOptions(program
@@ -27,7 +27,7 @@ applyOptions(program
27
27
  .description('Turbo CLI')
28
28
  .helpCommand(true), globalOptions);
29
29
  applyOptions(program.command('balance').description('Get balance of a Turbo address'), [optionMap.address, ...walletOptions]).action(async (_commandOptions, command) => {
30
- await runCommand(command, getBalance);
30
+ await runCommand(command, balance);
31
31
  });
32
32
  applyOptions(program.command('top-up').description('Top up a Turbo address with Fiat'), [...walletOptions, optionMap.address, optionMap.value, optionMap.currency]).action(async (_commandOptions, command) => {
33
33
  await runCommand(command, topUp);
@@ -41,6 +41,11 @@ applyOptions(program.command('upload-folder').description('Upload a folder using
41
41
  applyOptions(program.command('upload-file').description('Upload a file using Turbo'), uploadFileOptions).action(async (_commandOptions, command) => {
42
42
  await runCommand(command, uploadFile);
43
43
  });
44
+ applyOptions(program
45
+ .command('price')
46
+ .description('Get the current Credits estimate for byte, crypto, or fiat value'), [optionMap.value, optionMap.type]).action(async (_commandOptions, command) => {
47
+ await runCommand(command, price);
48
+ });
44
49
  if (process.argv[1].includes('bin/turbo') || // Running from global .bin
45
50
  process.argv[1].includes('cli/cli') // Running from source
46
51
  ) {
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { TurboFactory } from '../../node/factory.js';
18
+ import { addressOrPrivateKeyFromOptions, configFromOptions } from '../utils.js';
19
+ export async function balance(options) {
20
+ const config = configFromOptions(options);
21
+ const { address, privateKey } = await addressOrPrivateKeyFromOptions(options);
22
+ if (address !== undefined) {
23
+ const turbo = TurboFactory.unauthenticated(config);
24
+ const { winc } = await turbo.getBalance(address);
25
+ console.log(`Turbo Balance for Native Address "${address}"\nCredits: ${+winc / 1_000_000_000_000}`);
26
+ return;
27
+ }
28
+ if (privateKey === undefined) {
29
+ throw new Error('Must provide an (--address) or use a valid wallet');
30
+ }
31
+ const turbo = TurboFactory.authenticated({
32
+ ...config,
33
+ privateKey,
34
+ });
35
+ const { winc } = await turbo.getBalance();
36
+ console.log(`Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${+winc / 1_000_000_000_000}`);
37
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import prompts from 'prompts';
18
+ import { tokenToBaseMap } from '../../common/index.js';
19
+ import { TurboFactory } from '../../node/factory.js';
20
+ import { configFromOptions, tokenFromOptions, turboFromOptions, } from '../utils.js';
21
+ export async function cryptoFund(options) {
22
+ const value = options.value;
23
+ const txId = options.txId;
24
+ if (txId !== undefined) {
25
+ const turbo = TurboFactory.unauthenticated(configFromOptions(options));
26
+ const result = await turbo.submitFundTransaction({ txId: txId });
27
+ console.log('Submitted existing crypto fund transaction to payment service: \n', JSON.stringify(result, null, 2));
28
+ return;
29
+ }
30
+ if (value === undefined) {
31
+ throw new Error('Must provide a --value or --transaction-id for crypto-fund command');
32
+ }
33
+ const turbo = await turboFromOptions(options);
34
+ const token = tokenFromOptions(options);
35
+ const tokenAmount = tokenToBaseMap[token](value);
36
+ if (!options.skipConfirmation) {
37
+ const { winc } = await turbo.getWincForToken({ tokenAmount });
38
+ const targetWallet = (await turbo.getTurboCryptoWallets())[token];
39
+ const credits = (+winc / 1_000_000_000_000).toFixed(12);
40
+ const { confirm } = await prompts({
41
+ type: 'confirm',
42
+ name: 'confirm',
43
+ 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?`,
44
+ initial: true,
45
+ });
46
+ if (!confirm) {
47
+ console.log('Aborted crypto fund transaction');
48
+ return;
49
+ }
50
+ }
51
+ const result = await turbo.topUpWithTokens({
52
+ tokenAmount,
53
+ });
54
+ console.log('Sent crypto fund transaction: \n', JSON.stringify(result, null, 2));
55
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ export * from './balance.js';
18
+ export * from './cryptoFund.js';
19
+ export * from './price.js';
20
+ export * from './topUp.js';
21
+ export * from './uploadFile.js';
22
+ export * from './uploadFolder.js';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { currencyMap } from '../../common/currency.js';
18
+ import { isTokenType, tokenToBaseMap } from '../../common/index.js';
19
+ import { TurboFactory } from '../../node/factory.js';
20
+ import { fiatCurrencyTypes, isCurrency, tokenTypes } from '../../types.js';
21
+ import { configFromOptions } from '../utils.js';
22
+ export async function price(options) {
23
+ const value = options.value;
24
+ if (value === undefined || +value <= 0 || isNaN(+value)) {
25
+ throw new Error('Must provide a positive number --value to get price');
26
+ }
27
+ const type = options.type ?? 'bytes';
28
+ const winc = await (async () => {
29
+ if (isTokenType(type)) {
30
+ const turbo = TurboFactory.unauthenticated({
31
+ ...configFromOptions(options),
32
+ token: type,
33
+ });
34
+ return (await turbo.getWincForToken({
35
+ tokenAmount: tokenToBaseMap[type](value),
36
+ })).winc;
37
+ }
38
+ const turbo = TurboFactory.unauthenticated(configFromOptions(options));
39
+ if (type === 'bytes') {
40
+ return (await turbo.getUploadCosts({ bytes: [+value] }))[0].winc;
41
+ }
42
+ if (isCurrency(type)) {
43
+ return (await turbo.getWincForFiat({
44
+ amount: currencyMap[type](+value),
45
+ })).winc;
46
+ }
47
+ throw new Error(`Invalid price type!\nMust be one of: bytes, ${fiatCurrencyTypes.join(', ') + ' ' + tokenTypes.join(', ')}`);
48
+ })();
49
+ console.log(`Current price estimate for ${value} ${type} is ~${(+winc / 1_000_000_000_000).toFixed(12)} Credits`);
50
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { exec } from 'child_process';
18
+ import { currencyMap } from '../../common/currency.js';
19
+ import { TurboFactory } from '../../node/factory.js';
20
+ import { fiatCurrencyTypes, isCurrency } from '../../types.js';
21
+ import { sleep } from '../../utils/common.js';
22
+ import { addressOrPrivateKeyFromOptions, configFromOptions } from '../utils.js';
23
+ function openUrl(url) {
24
+ if (process.platform === 'darwin') {
25
+ // macOS
26
+ exec(`open ${url}`);
27
+ }
28
+ else if (process.platform === 'win32') {
29
+ // Windows
30
+ exec(`start "" "${url}"`, { windowsHide: true });
31
+ }
32
+ else {
33
+ // Linux/Unix
34
+ open(url);
35
+ }
36
+ }
37
+ export async function topUp(options) {
38
+ const config = configFromOptions(options);
39
+ const { address, privateKey } = await addressOrPrivateKeyFromOptions(options);
40
+ const value = options.value;
41
+ if (value === undefined) {
42
+ throw new Error('Must provide a --value to top up');
43
+ }
44
+ const currency = (options.currency ?? 'usd').toLowerCase();
45
+ if (!isCurrency(currency)) {
46
+ throw new Error(`Invalid fiat currency type ${currency}!\nPlease use one of these:\n${JSON.stringify(fiatCurrencyTypes, null, 2)}`);
47
+ }
48
+ // TODO: Pay in CLI prompts via --cli options
49
+ const { url, paymentAmount, winc } = await (async () => {
50
+ const amount = currencyMap[currency](+value);
51
+ if (address !== undefined) {
52
+ const turbo = TurboFactory.unauthenticated(config);
53
+ return turbo.createCheckoutSession({
54
+ amount,
55
+ owner: address,
56
+ });
57
+ }
58
+ if (privateKey === undefined) {
59
+ throw new Error('Must provide a wallet to top up');
60
+ }
61
+ const turbo = TurboFactory.authenticated({
62
+ ...config,
63
+ privateKey,
64
+ });
65
+ return turbo.createCheckoutSession({
66
+ amount,
67
+ owner: await turbo.signer.getNativeAddress(),
68
+ });
69
+ })();
70
+ if (url === undefined) {
71
+ throw new Error('Failed to create checkout session');
72
+ }
73
+ console.log('Got Checkout Session\n' + JSON.stringify({ url, paymentAmount, winc }));
74
+ console.log('Opening checkout session in browser...');
75
+ await sleep(2000);
76
+ openUrl(url);
77
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { createReadStream, statSync } from 'fs';
18
+ import { turboCliTags } from '../constants.js';
19
+ import { turboFromOptions } from '../utils.js';
20
+ export async function uploadFile(options) {
21
+ const { filePath } = options;
22
+ if (filePath === undefined) {
23
+ throw new Error('Must provide a --file-path to upload');
24
+ }
25
+ const turbo = await turboFromOptions(options);
26
+ const fileSize = statSync(filePath).size;
27
+ const result = await turbo.uploadFile({
28
+ fileStreamFactory: () => createReadStream(filePath),
29
+ fileSizeFactory: () => fileSize,
30
+ dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags
31
+ });
32
+ console.log('Uploaded file:', JSON.stringify(result, null, 2));
33
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { turboCliTags } from '../constants.js';
18
+ import { getUploadFolderOptions, turboFromOptions } from '../utils.js';
19
+ export async function uploadFolder(options) {
20
+ const turbo = await turboFromOptions(options);
21
+ const { disableManifest, fallbackFile, folderPath, indexFile, maxConcurrentUploads, } = getUploadFolderOptions(options);
22
+ const result = await turbo.uploadFolder({
23
+ folderPath: folderPath,
24
+ dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags
25
+ manifestOptions: {
26
+ disableManifest,
27
+ indexFile,
28
+ fallbackFile,
29
+ },
30
+ maxConcurrentUploads,
31
+ });
32
+ console.log('Uploaded folder:', JSON.stringify(result, null, 2));
33
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { version } from '../version.js';
18
+ export const turboCliTags = [
19
+ { name: 'App-Name', value: 'Turbo-CLI' },
20
+ { name: 'App-Version', value: version },
21
+ { name: 'App-Platform', value: process.platform },
22
+ ];
@@ -25,6 +25,11 @@ export const optionMap = {
25
25
  description: 'Fiat currency type to use for the action',
26
26
  default: 'usd',
27
27
  },
28
+ type: {
29
+ alias: '--type <priceType>',
30
+ description: 'Price type for the action. Can be a fiat currency or crypto token or bytes',
31
+ default: 'bytes',
32
+ },
28
33
  txId: {
29
34
  alias: '-i, --tx-id <txId>',
30
35
  description: 'Transaction ID or hash to use for action',
@@ -114,7 +114,8 @@ const tokenToDevGatewayMap = {
114
114
  solana: 'https://api.devnet.solana.com',
115
115
  ethereum: 'https://ethereum-holesky-rpc.publicnode.com',
116
116
  kyve: 'https://api.korellia.kyve.network',
117
- // matic: 'https://rpc-amoy.polygon.technology',
117
+ matic: 'https://rpc-amoy.polygon.technology',
118
+ pol: 'https://rpc-amoy.polygon.technology',
118
119
  };
119
120
  export function configFromOptions(options) {
120
121
  let config = {};