@ardrive/turbo-sdk 1.14.0-alpha.1 → 1.14.0-alpha.3

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 (50) hide show
  1. package/README.md +15 -0
  2. package/bundles/web.bundle.min.js +9721 -15515
  3. package/lib/cjs/cli/cli.js +4 -13
  4. package/lib/cjs/cli/commands.js +25 -12
  5. package/lib/cjs/cli/options.js +7 -2
  6. package/lib/cjs/cli/types.js +16 -0
  7. package/lib/cjs/cli/utils.js +17 -5
  8. package/lib/cjs/common/signer.js +1 -1
  9. package/lib/cjs/common/token/arweave.js +10 -5
  10. package/lib/cjs/common/token/kyve.js +1 -1
  11. package/lib/cjs/node/factory.js +1 -1
  12. package/lib/cjs/node/signer.js +1 -1
  13. package/lib/cjs/utils/common.js +1 -1
  14. package/lib/cjs/version.js +1 -1
  15. package/lib/cjs/web/factory.js +1 -1
  16. package/lib/cjs/web/signer.js +1 -1
  17. package/lib/esm/cli/cli.js +7 -16
  18. package/lib/esm/cli/commands.js +25 -13
  19. package/lib/esm/cli/options.js +6 -1
  20. package/lib/esm/cli/types.js +16 -0
  21. package/lib/esm/cli/utils.js +17 -6
  22. package/lib/esm/common/signer.js +1 -1
  23. package/lib/esm/common/token/arweave.js +10 -5
  24. package/lib/esm/common/token/kyve.js +1 -1
  25. package/lib/esm/node/factory.js +1 -1
  26. package/lib/esm/node/signer.js +1 -1
  27. package/lib/esm/utils/common.js +1 -1
  28. package/lib/esm/version.js +1 -1
  29. package/lib/esm/web/factory.js +1 -1
  30. package/lib/esm/web/signer.js +1 -1
  31. package/lib/types/cli/commands.d.ts +3 -9
  32. package/lib/types/cli/commands.d.ts.map +1 -1
  33. package/lib/types/cli/options.d.ts +19 -2
  34. package/lib/types/cli/options.d.ts.map +1 -1
  35. package/lib/types/cli/types.d.ts +8 -3
  36. package/lib/types/cli/types.d.ts.map +1 -1
  37. package/lib/types/cli/utils.d.ts +3 -2
  38. package/lib/types/cli/utils.d.ts.map +1 -1
  39. package/lib/types/common/token/arweave.d.ts +1 -1
  40. package/lib/types/common/token/arweave.d.ts.map +1 -1
  41. package/lib/types/node/signer.d.ts +1 -1
  42. package/lib/types/node/signer.d.ts.map +1 -1
  43. package/lib/types/types.d.ts +1 -1
  44. package/lib/types/types.d.ts.map +1 -1
  45. package/lib/types/utils/common.d.ts.map +1 -1
  46. package/lib/types/version.d.ts +1 -1
  47. package/lib/types/version.d.ts.map +1 -1
  48. package/lib/types/web/signer.d.ts +1 -1
  49. package/lib/types/web/signer.d.ts.map +1 -1
  50. package/package.json +4 -3
@@ -35,23 +35,14 @@ const utils_js_1 = require("./utils.js");
35
35
  await (0, utils_js_1.runCommand)(command, commands_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]).action(async (_commandOptions, command) => {
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- const options = command.optsWithGlobals();
40
- const token = (0, utils_js_1.tokenFromOptions)(options);
41
- const value = (0, utils_js_1.valueFromOptions)(options);
42
- const privateKey = await (0, utils_js_1.privateKeyFromOptions)(options);
43
- const config = (0, utils_js_1.configFromOptions)(options);
44
- try {
45
- await (0, commands_js_1.cryptoFund)({ privateKey, value, token, config });
46
- process.exit(0);
47
- }
48
- catch (error) {
49
- (0, utils_js_1.exitWithErrorLog)(error);
50
- }
38
+ await (0, utils_js_1.runCommand)(command, commands_js_1.cryptoFund);
51
39
  });
52
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) => {
53
41
  await (0, utils_js_1.runCommand)(command, commands_js_1.uploadFolder);
54
42
  });
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, commands_js_1.uploadFile);
45
+ });
55
46
  if (process.argv[1].includes('bin/turbo') || // Running from global .bin
56
47
  process.argv[1].includes('cli/cli') // Running from source
57
48
  ) {
@@ -5,6 +5,7 @@ exports.cryptoFund = cryptoFund;
5
5
  exports.topUp = topUp;
6
6
  exports.openUrl = openUrl;
7
7
  exports.uploadFolder = uploadFolder;
8
+ exports.uploadFile = uploadFile;
8
9
  /**
9
10
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
10
11
  *
@@ -22,6 +23,7 @@ exports.uploadFolder = uploadFolder;
22
23
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24
  */
24
25
  const node_child_process_1 = require("node:child_process");
26
+ const node_fs_1 = require("node:fs");
25
27
  const index_js_1 = require("../node/index.js");
26
28
  const common_js_1 = require("../utils/common.js");
27
29
  const version_js_1 = require("../version.js");
@@ -46,13 +48,14 @@ async function getBalance(options) {
46
48
  console.log(`Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${+winc / 1_000_000_000_000}`);
47
49
  }
48
50
  /** Fund the connected signer with crypto */
49
- async function cryptoFund({ value, privateKey, token, config, }) {
50
- const authenticatedTurbo = index_js_1.TurboFactory.authenticated({
51
- ...config,
52
- privateKey: privateKey,
53
- token,
54
- });
55
- const result = await authenticatedTurbo.topUpWithTokens({
51
+ async function cryptoFund(options) {
52
+ const value = options.value;
53
+ if (value === undefined) {
54
+ throw new Error('Must provide a --value to top up');
55
+ }
56
+ const turbo = await (0, utils_js_1.turboFromOptions)(options);
57
+ const token = (0, utils_js_1.tokenFromOptions)(options);
58
+ const result = await turbo.topUpWithTokens({
56
59
  tokenAmount: index_js_1.tokenToBaseMap[token](value),
57
60
  });
58
61
  console.log('Sent crypto fund transaction: \n', JSON.stringify(result, null, 2));
@@ -118,11 +121,7 @@ const turboCliTags = [
118
121
  { name: 'App-Platform', value: process.platform },
119
122
  ];
120
123
  async function uploadFolder(options) {
121
- const privateKey = await (0, utils_js_1.privateKeyFromOptions)(options);
122
- const turbo = index_js_1.TurboFactory.authenticated({
123
- ...(0, utils_js_1.configFromOptions)(options),
124
- privateKey,
125
- });
124
+ const turbo = await (0, utils_js_1.turboFromOptions)(options);
126
125
  const { disableManifest, fallbackFile, folderPath, indexFile, maxConcurrentUploads, } = (0, utils_js_1.getUploadFolderOptions)(options);
127
126
  const result = await turbo.uploadFolder({
128
127
  folderPath: folderPath,
@@ -136,3 +135,17 @@ async function uploadFolder(options) {
136
135
  });
137
136
  console.log('Uploaded folder:', JSON.stringify(result, null, 2));
138
137
  }
138
+ async function uploadFile(options) {
139
+ const { filePath } = options;
140
+ if (filePath === undefined) {
141
+ throw new Error('Must provide a --file-path to upload');
142
+ }
143
+ const turbo = await (0, utils_js_1.turboFromOptions)(options);
144
+ const fileSize = (0, node_fs_1.statSync)(filePath).size;
145
+ const result = await turbo.uploadFile({
146
+ fileStreamFactory: () => (0, node_fs_1.createReadStream)(filePath),
147
+ fileSizeFactory: () => fileSize,
148
+ dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags
149
+ });
150
+ console.log('Uploaded file:', JSON.stringify(result, null, 2));
151
+ }
@@ -16,7 +16,7 @@
16
16
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.uploadFolderOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
19
+ exports.uploadFileOptions = exports.uploadFolderOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
20
20
  exports.optionMap = {
21
21
  token: {
22
22
  alias: '-t, --token <type>',
@@ -74,6 +74,10 @@ exports.optionMap = {
74
74
  alias: '-f, --folder-path <folderPath>',
75
75
  description: 'Directory to upload',
76
76
  },
77
+ filePath: {
78
+ alias: '-f, --file-path <filePath>',
79
+ description: 'File to upload',
80
+ },
77
81
  indexFile: {
78
82
  alias: '--index-file <indexFile>',
79
83
  description: 'Index file to use in the manifest created for folder upload',
@@ -85,7 +89,7 @@ exports.optionMap = {
85
89
  manifest: {
86
90
  alias: '--no-manifest',
87
91
  description: 'Disable manifest creation with --no-manifest',
88
- default: false,
92
+ default: true,
89
93
  },
90
94
  maxConcurrency: {
91
95
  alias: '--max-concurrency <maxConcurrency>',
@@ -112,3 +116,4 @@ exports.uploadFolderOptions = [
112
116
  exports.optionMap.manifest,
113
117
  exports.optionMap.maxConcurrency,
114
118
  ];
119
+ exports.uploadFileOptions = [...exports.walletOptions, exports.optionMap.filePath];
@@ -1,2 +1,18 @@
1
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
+ */
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -13,6 +13,7 @@ exports.addressOrPrivateKeyFromOptions = addressOrPrivateKeyFromOptions;
13
13
  exports.optionalPrivateKeyFromOptions = optionalPrivateKeyFromOptions;
14
14
  exports.privateKeyFromOptions = privateKeyFromOptions;
15
15
  exports.configFromOptions = configFromOptions;
16
+ exports.turboFromOptions = turboFromOptions;
16
17
  exports.getUploadFolderOptions = getUploadFolderOptions;
17
18
  /**
18
19
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
@@ -132,9 +133,11 @@ const tokenToDevGatewayMap = {
132
133
  kyve: 'https://api.korellia.kyve.network',
133
134
  // matic: 'https://rpc-amoy.polygon.technology',
134
135
  };
135
- function configFromOptions({ gateway, dev, token, }) {
136
+ function configFromOptions(options) {
136
137
  let config = {};
137
- if (dev) {
138
+ const token = tokenFromOptions(options);
139
+ config.token = token;
140
+ if (options.dev) {
138
141
  config = index_js_1.developmentTurboConfiguration;
139
142
  config.gatewayUrl = tokenToDevGatewayMap[token];
140
143
  }
@@ -142,13 +145,22 @@ function configFromOptions({ gateway, dev, token, }) {
142
145
  config = index_js_1.defaultTurboConfiguration;
143
146
  }
144
147
  // If gateway is provided, override the default or dev gateway
145
- if (gateway !== undefined) {
146
- config.gatewayUrl = gateway;
148
+ if (options.gateway !== undefined) {
149
+ config.gatewayUrl = options.gateway;
147
150
  }
148
- config.token = token;
149
151
  return config;
150
152
  }
153
+ async function turboFromOptions(options) {
154
+ const privateKey = await privateKeyFromOptions(options);
155
+ return index_js_1.TurboFactory.authenticated({
156
+ ...configFromOptions(options),
157
+ privateKey,
158
+ });
159
+ }
151
160
  function getUploadFolderOptions(options) {
161
+ if (options.folderPath === undefined) {
162
+ throw new Error('--folder-path is required');
163
+ }
152
164
  return {
153
165
  folderPath: options.folderPath,
154
166
  indexFile: options.indexFile,
@@ -20,12 +20,12 @@ exports.TurboDataItemAbstractSigner = void 0;
20
20
  * You should have received a copy of the GNU Affero General Public License
21
21
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
  */
23
+ const arbundles_1 = require("@ar.io/arbundles");
23
24
  const amino_1 = require("@cosmjs/amino");
24
25
  const crypto_1 = require("@cosmjs/crypto");
25
26
  const encoding_1 = require("@cosmjs/encoding");
26
27
  const signing_key_1 = require("@ethersproject/signing-key");
27
28
  const sdk_js_1 = require("@kyvejs/sdk/dist/sdk.js");
28
- const arbundles_1 = require("arbundles");
29
29
  const bs58_1 = __importDefault(require("bs58"));
30
30
  const crypto_2 = require("crypto");
31
31
  const ethers_1 = require("ethers");
@@ -20,21 +20,26 @@ exports.ARToTokenAmount = exports.WinstonToTokenAmount = exports.ArweaveToken =
20
20
  * You should have received a copy of the GNU Affero General Public License
21
21
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
  */
23
- const arweave_1 = __importDefault(require("@irys/arweave"));
23
+ const arweave_1 = __importDefault(require("arweave"));
24
24
  const bignumber_js_1 = require("bignumber.js");
25
25
  const node_buffer_1 = require("node:buffer");
26
26
  const base64_js_1 = require("../../utils/base64.js");
27
27
  const common_js_1 = require("../../utils/common.js");
28
28
  const logger_js_1 = require("../logger.js");
29
29
  class ArweaveToken {
30
- constructor({ gatewayUrl = 'https://arweave.net', arweave = arweave_1.default.init({
31
- url: gatewayUrl,
32
- }), logger = logger_js_1.TurboWinstonLogger.default, mintU = true, pollingOptions = {
30
+ constructor({ gatewayUrl = 'https://arweave.net', arweave, logger = logger_js_1.TurboWinstonLogger.default, mintU = true, pollingOptions = {
33
31
  maxAttempts: 10,
34
32
  pollingIntervalMs: 3_000,
35
33
  initialBackoffMs: 7_000,
36
34
  }, } = {}) {
37
- this.arweave = arweave;
35
+ const url = new URL(gatewayUrl);
36
+ this.arweave =
37
+ arweave ??
38
+ arweave_1.default.init({
39
+ host: url.hostname,
40
+ port: url.port,
41
+ protocol: url.protocol.replace(':', ''),
42
+ });
38
43
  this.logger = logger;
39
44
  this.mintU = mintU;
40
45
  this.pollingOptions = pollingOptions;
@@ -20,10 +20,10 @@ exports.signerFromKyveMnemonic = signerFromKyveMnemonic;
20
20
  * You should have received a copy of the GNU Affero General Public License
21
21
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
  */
23
+ const arbundles_1 = require("@ar.io/arbundles");
23
24
  const amino_1 = require("@cosmjs/amino");
24
25
  const crypto_1 = require("@cosmjs/crypto");
25
26
  const encoding_1 = require("@cosmjs/encoding");
26
- const arbundles_1 = require("arbundles");
27
27
  const bignumber_js_1 = require("bignumber.js");
28
28
  const axiosClient_js_1 = require("../../utils/axiosClient.js");
29
29
  const common_js_1 = require("../../utils/common.js");
@@ -17,7 +17,7 @@ exports.TurboFactory = void 0;
17
17
  * You should have received a copy of the GNU Affero General Public License
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
- const arbundles_1 = require("arbundles");
20
+ const arbundles_1 = require("@ar.io/arbundles");
21
21
  const factory_js_1 = require("../common/factory.js");
22
22
  const index_js_1 = require("../common/index.js");
23
23
  const payment_js_1 = require("../common/payment.js");
@@ -17,7 +17,7 @@ exports.TurboNodeSigner = exports.HexSolanaSigner = exports.EthereumSigner = exp
17
17
  * You should have received a copy of the GNU Affero General Public License
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
- const arbundles_1 = require("arbundles");
20
+ const arbundles_1 = require("@ar.io/arbundles");
21
21
  Object.defineProperty(exports, "ArconnectSigner", { enumerable: true, get: function () { return arbundles_1.ArconnectSigner; } });
22
22
  Object.defineProperty(exports, "ArweaveSigner", { enumerable: true, get: function () { return arbundles_1.ArweaveSigner; } });
23
23
  Object.defineProperty(exports, "EthereumSigner", { enumerable: true, get: function () { return arbundles_1.EthereumSigner; } });
@@ -21,10 +21,10 @@ exports.signerFromKyveMnemonic = signerFromKyveMnemonic;
21
21
  * You should have received a copy of the GNU Affero General Public License
22
22
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
23
  */
24
+ const arbundles_1 = require("@ar.io/arbundles");
24
25
  const amino_1 = require("@cosmjs/amino");
25
26
  const crypto_1 = require("@cosmjs/crypto");
26
27
  const encoding_1 = require("@cosmjs/encoding");
27
- const arbundles_1 = require("arbundles");
28
28
  const types_js_1 = require("../types.js");
29
29
  function sleep(ms) {
30
30
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -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.14.0-alpha.1';
21
+ exports.version = '1.14.0-alpha.3';
@@ -17,7 +17,7 @@ exports.TurboFactory = void 0;
17
17
  * You should have received a copy of the GNU Affero General Public License
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
- const arbundles_1 = require("arbundles");
20
+ const arbundles_1 = require("@ar.io/arbundles");
21
21
  const factory_js_1 = require("../common/factory.js");
22
22
  const index_js_1 = require("../common/index.js");
23
23
  const common_js_1 = require("../utils/common.js");
@@ -17,7 +17,7 @@ exports.TurboWebArweaveSigner = exports.HexSolanaSigner = exports.EthereumSigner
17
17
  * You should have received a copy of the GNU Affero General Public License
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
- const arbundles_1 = require("arbundles");
20
+ const arbundles_1 = require("@ar.io/arbundles");
21
21
  Object.defineProperty(exports, "ArconnectSigner", { enumerable: true, get: function () { return arbundles_1.ArconnectSigner; } });
22
22
  Object.defineProperty(exports, "ArweaveSigner", { enumerable: true, get: function () { return arbundles_1.ArweaveSigner; } });
23
23
  Object.defineProperty(exports, "EthereumSigner", { enumerable: true, get: function () { return arbundles_1.EthereumSigner; } });
@@ -18,9 +18,9 @@
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, uploadFolder } from './commands.js';
22
- import { globalOptions, optionMap, uploadFolderOptions, walletOptions, } from './options.js';
23
- import { applyOptions, configFromOptions, exitWithErrorLog, privateKeyFromOptions, runCommand, tokenFromOptions, valueFromOptions, } from './utils.js';
21
+ import { cryptoFund, getBalance, topUp, uploadFile, uploadFolder, } from './commands.js';
22
+ import { globalOptions, optionMap, uploadFileOptions, uploadFolderOptions, walletOptions, } from './options.js';
23
+ import { applyOptions, runCommand } from './utils.js';
24
24
  applyOptions(program
25
25
  .name('turbo')
26
26
  .version(version)
@@ -33,23 +33,14 @@ applyOptions(program.command('top-up').description('Top up a Turbo address with
33
33
  await runCommand(command, topUp);
34
34
  });
35
35
  applyOptions(program.command('crypto-fund').description('Top up a wallet with crypto'), [...walletOptions, optionMap.value]).action(async (_commandOptions, command) => {
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- const options = command.optsWithGlobals();
38
- const token = tokenFromOptions(options);
39
- const value = valueFromOptions(options);
40
- const privateKey = await privateKeyFromOptions(options);
41
- const config = configFromOptions(options);
42
- try {
43
- await cryptoFund({ privateKey, value, token, config });
44
- process.exit(0);
45
- }
46
- catch (error) {
47
- exitWithErrorLog(error);
48
- }
36
+ await runCommand(command, cryptoFund);
49
37
  });
50
38
  applyOptions(program.command('upload-folder').description('Upload a folder using Turbo'), uploadFolderOptions).action(async (_commandOptions, command) => {
51
39
  await runCommand(command, uploadFolder);
52
40
  });
41
+ applyOptions(program.command('upload-file').description('Upload a file using Turbo'), uploadFileOptions).action(async (_commandOptions, command) => {
42
+ await runCommand(command, uploadFile);
43
+ });
53
44
  if (process.argv[1].includes('bin/turbo') || // Running from global .bin
54
45
  process.argv[1].includes('cli/cli') // Running from source
55
46
  ) {
@@ -15,10 +15,11 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  import { exec } from 'node:child_process';
18
+ import { createReadStream, statSync } from 'node:fs';
18
19
  import { TurboFactory, currencyMap, fiatCurrencyTypes, isCurrency, tokenToBaseMap, } from '../node/index.js';
19
20
  import { sleep } from '../utils/common.js';
20
21
  import { version } from '../version.js';
21
- import { addressOrPrivateKeyFromOptions, configFromOptions, getUploadFolderOptions, privateKeyFromOptions, } from './utils.js';
22
+ import { addressOrPrivateKeyFromOptions, configFromOptions, getUploadFolderOptions, tokenFromOptions, turboFromOptions, } from './utils.js';
22
23
  export async function getBalance(options) {
23
24
  const config = configFromOptions(options);
24
25
  const { address, privateKey } = await addressOrPrivateKeyFromOptions(options);
@@ -39,13 +40,14 @@ export async function getBalance(options) {
39
40
  console.log(`Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${+winc / 1_000_000_000_000}`);
40
41
  }
41
42
  /** Fund the connected signer with crypto */
42
- export async function cryptoFund({ value, privateKey, token, config, }) {
43
- const authenticatedTurbo = TurboFactory.authenticated({
44
- ...config,
45
- privateKey: privateKey,
46
- token,
47
- });
48
- const result = await authenticatedTurbo.topUpWithTokens({
43
+ export async function cryptoFund(options) {
44
+ const value = options.value;
45
+ if (value === undefined) {
46
+ throw new Error('Must provide a --value to top up');
47
+ }
48
+ const turbo = await turboFromOptions(options);
49
+ const token = tokenFromOptions(options);
50
+ const result = await turbo.topUpWithTokens({
49
51
  tokenAmount: tokenToBaseMap[token](value),
50
52
  });
51
53
  console.log('Sent crypto fund transaction: \n', JSON.stringify(result, null, 2));
@@ -111,11 +113,7 @@ const turboCliTags = [
111
113
  { name: 'App-Platform', value: process.platform },
112
114
  ];
113
115
  export async function uploadFolder(options) {
114
- const privateKey = await privateKeyFromOptions(options);
115
- const turbo = TurboFactory.authenticated({
116
- ...configFromOptions(options),
117
- privateKey,
118
- });
116
+ const turbo = await turboFromOptions(options);
119
117
  const { disableManifest, fallbackFile, folderPath, indexFile, maxConcurrentUploads, } = getUploadFolderOptions(options);
120
118
  const result = await turbo.uploadFolder({
121
119
  folderPath: folderPath,
@@ -129,3 +127,17 @@ export async function uploadFolder(options) {
129
127
  });
130
128
  console.log('Uploaded folder:', JSON.stringify(result, null, 2));
131
129
  }
130
+ export async function uploadFile(options) {
131
+ const { filePath } = options;
132
+ if (filePath === undefined) {
133
+ throw new Error('Must provide a --file-path to upload');
134
+ }
135
+ const turbo = await turboFromOptions(options);
136
+ const fileSize = statSync(filePath).size;
137
+ const result = await turbo.uploadFile({
138
+ fileStreamFactory: () => createReadStream(filePath),
139
+ fileSizeFactory: () => fileSize,
140
+ dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags
141
+ });
142
+ console.log('Uploaded file:', JSON.stringify(result, null, 2));
143
+ }
@@ -71,6 +71,10 @@ export const optionMap = {
71
71
  alias: '-f, --folder-path <folderPath>',
72
72
  description: 'Directory to upload',
73
73
  },
74
+ filePath: {
75
+ alias: '-f, --file-path <filePath>',
76
+ description: 'File to upload',
77
+ },
74
78
  indexFile: {
75
79
  alias: '--index-file <indexFile>',
76
80
  description: 'Index file to use in the manifest created for folder upload',
@@ -82,7 +86,7 @@ export const optionMap = {
82
86
  manifest: {
83
87
  alias: '--no-manifest',
84
88
  description: 'Disable manifest creation with --no-manifest',
85
- default: false,
89
+ default: true,
86
90
  },
87
91
  maxConcurrency: {
88
92
  alias: '--max-concurrency <maxConcurrency>',
@@ -109,3 +113,4 @@ export const uploadFolderOptions = [
109
113
  optionMap.manifest,
110
114
  optionMap.maxConcurrency,
111
115
  ];
116
+ export const uploadFileOptions = [...walletOptions, optionMap.filePath];
@@ -1 +1,17 @@
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
+ */
1
17
  export {};
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import bs58 from 'bs58';
18
18
  import { readFileSync, statSync } from 'fs';
19
- import { defaultTurboConfiguration, developmentTurboConfiguration, isTokenType, privateKeyFromKyveMnemonic, } from '../node/index.js';
19
+ import { TurboFactory, defaultTurboConfiguration, developmentTurboConfiguration, isTokenType, privateKeyFromKyveMnemonic, } from '../node/index.js';
20
20
  import { NoWalletProvidedError } from './errors.js';
21
21
  export function exitWithErrorLog(error) {
22
22
  console.error(error instanceof Error ? error.message : error);
@@ -116,9 +116,11 @@ const tokenToDevGatewayMap = {
116
116
  kyve: 'https://api.korellia.kyve.network',
117
117
  // matic: 'https://rpc-amoy.polygon.technology',
118
118
  };
119
- export function configFromOptions({ gateway, dev, token, }) {
119
+ export function configFromOptions(options) {
120
120
  let config = {};
121
- if (dev) {
121
+ const token = tokenFromOptions(options);
122
+ config.token = token;
123
+ if (options.dev) {
122
124
  config = developmentTurboConfiguration;
123
125
  config.gatewayUrl = tokenToDevGatewayMap[token];
124
126
  }
@@ -126,13 +128,22 @@ export function configFromOptions({ gateway, dev, token, }) {
126
128
  config = defaultTurboConfiguration;
127
129
  }
128
130
  // If gateway is provided, override the default or dev gateway
129
- if (gateway !== undefined) {
130
- config.gatewayUrl = gateway;
131
+ if (options.gateway !== undefined) {
132
+ config.gatewayUrl = options.gateway;
131
133
  }
132
- config.token = token;
133
134
  return config;
134
135
  }
136
+ export async function turboFromOptions(options) {
137
+ const privateKey = await privateKeyFromOptions(options);
138
+ return TurboFactory.authenticated({
139
+ ...configFromOptions(options),
140
+ privateKey,
141
+ });
142
+ }
135
143
  export function getUploadFolderOptions(options) {
144
+ if (options.folderPath === undefined) {
145
+ throw new Error('--folder-path is required');
146
+ }
136
147
  return {
137
148
  folderPath: options.folderPath,
138
149
  indexFile: options.indexFile,
@@ -14,12 +14,12 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
+ import { EthereumSigner, HexSolanaSigner } from '@ar.io/arbundles';
17
18
  import { pubkeyToAddress } from '@cosmjs/amino';
18
19
  import { Secp256k1 } from '@cosmjs/crypto';
19
20
  import { toBase64 } from '@cosmjs/encoding';
20
21
  import { computePublicKey } from '@ethersproject/signing-key';
21
22
  import { KyveSDK } from '@kyvejs/sdk/dist/sdk.js';
22
- import { EthereumSigner, HexSolanaSigner } from 'arbundles';
23
23
  import bs58 from 'bs58';
24
24
  import { randomBytes } from 'crypto';
25
25
  import { Wallet as EthereumWallet, ethers, parseEther } from 'ethers';
@@ -14,21 +14,26 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- import Arweave from '@irys/arweave';
17
+ import Arweave from 'arweave';
18
18
  import { BigNumber } from 'bignumber.js';
19
19
  import { Buffer } from 'node:buffer';
20
20
  import { sha256B64Url, toB64Url } from '../../utils/base64.js';
21
21
  import { sleep } from '../../utils/common.js';
22
22
  import { TurboWinstonLogger } from '../logger.js';
23
23
  export class ArweaveToken {
24
- constructor({ gatewayUrl = 'https://arweave.net', arweave = Arweave.init({
25
- url: gatewayUrl,
26
- }), logger = TurboWinstonLogger.default, mintU = true, pollingOptions = {
24
+ constructor({ gatewayUrl = 'https://arweave.net', arweave, logger = TurboWinstonLogger.default, mintU = true, pollingOptions = {
27
25
  maxAttempts: 10,
28
26
  pollingIntervalMs: 3_000,
29
27
  initialBackoffMs: 7_000,
30
28
  }, } = {}) {
31
- this.arweave = arweave;
29
+ const url = new URL(gatewayUrl);
30
+ this.arweave =
31
+ arweave ??
32
+ Arweave.init({
33
+ host: url.hostname,
34
+ port: url.port,
35
+ protocol: url.protocol.replace(':', ''),
36
+ });
32
37
  this.logger = logger;
33
38
  this.mintU = mintU;
34
39
  this.pollingOptions = pollingOptions;
@@ -14,10 +14,10 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
+ import { EthereumSigner } from '@ar.io/arbundles';
17
18
  import { Secp256k1HdWallet, makeCosmoshubPath } from '@cosmjs/amino';
18
19
  import { Slip10, Slip10Curve } from '@cosmjs/crypto';
19
20
  import { toHex } from '@cosmjs/encoding';
20
- import { EthereumSigner } from 'arbundles';
21
21
  import { BigNumber } from 'bignumber.js';
22
22
  import { createAxiosInstance } from '../../utils/axiosClient.js';
23
23
  import { sleep } from '../../utils/common.js';
@@ -14,7 +14,7 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- import { EthereumSigner, HexSolanaSigner } from 'arbundles';
17
+ import { EthereumSigner, HexSolanaSigner } from '@ar.io/arbundles';
18
18
  import { TurboBaseFactory } from '../common/factory.js';
19
19
  import { defaultTokenMap } from '../common/index.js';
20
20
  import { TurboAuthenticatedPaymentService } from '../common/payment.js';
@@ -14,7 +14,7 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- import { ArconnectSigner, ArweaveSigner, EthereumSigner, HexSolanaSigner, serializeTags, streamSigner, } from 'arbundles';
17
+ import { ArconnectSigner, ArweaveSigner, EthereumSigner, HexSolanaSigner, serializeTags, streamSigner, } from '@ar.io/arbundles';
18
18
  import { Buffer } from 'node:buffer';
19
19
  import { TurboDataItemAbstractSigner } from '../common/signer.js';
20
20
  import { fromB64Url } from '../utils/base64.js';
@@ -14,10 +14,10 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
+ import { ArweaveSigner, EthereumSigner, HexSolanaSigner, } from '@ar.io/arbundles';
17
18
  import { Secp256k1HdWallet, makeCosmoshubPath } from '@cosmjs/amino';
18
19
  import { Slip10, Slip10Curve } from '@cosmjs/crypto';
19
20
  import { toHex } from '@cosmjs/encoding';
20
- import { ArweaveSigner, EthereumSigner, HexSolanaSigner } from 'arbundles';
21
21
  import { isEthPrivateKey, isJWK, isKyvePrivateKey, } from '../types.js';
22
22
  export function sleep(ms) {
23
23
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -15,4 +15,4 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
18
- export const version = '1.14.0-alpha.1';
18
+ export const version = '1.14.0-alpha.3';
@@ -14,7 +14,7 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- import { EthereumSigner, HexSolanaSigner } from 'arbundles';
17
+ import { EthereumSigner, HexSolanaSigner } from '@ar.io/arbundles';
18
18
  import { TurboBaseFactory } from '../common/factory.js';
19
19
  import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, defaultTokenMap, } from '../common/index.js';
20
20
  import { createTurboSigner } from '../utils/common.js';
@@ -14,7 +14,7 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- import { ArconnectSigner, ArweaveSigner, EthereumSigner, HexSolanaSigner, createData, } from 'arbundles';
17
+ import { ArconnectSigner, ArweaveSigner, EthereumSigner, HexSolanaSigner, createData, } from '@ar.io/arbundles';
18
18
  import { TurboDataItemAbstractSigner } from '../common/signer.js';
19
19
  import { readableStreamToBuffer } from '../utils/readableStream.js';
20
20
  /**