@ardrive/turbo-sdk 1.16.1 → 1.17.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/bundles/web.bundle.min.js +43 -6
- package/lib/cjs/cli/cli.js +6 -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 +37 -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/utils.js +2 -1
- 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/version.js +1 -1
- package/lib/cjs/web/factory.js +1 -0
- package/lib/esm/cli/cli.js +2 -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 +21 -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/utils.js +2 -1
- 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/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 +22 -0
- package/lib/types/cli/commands/index.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/utils.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/version.d.ts +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)
|
@@ -269,6 +272,15 @@ const turbo = TurboFactory.authenticated({
|
|
269
272
|
});
|
270
273
|
```
|
271
274
|
|
275
|
+
##### POL (MATIC) Private Key
|
276
|
+
|
277
|
+
```typescript
|
278
|
+
const turbo = TurboFactory.authenticated({
|
279
|
+
privateKey: ethHexadecimalPrivateKey,
|
280
|
+
token: 'pol',
|
281
|
+
});
|
282
|
+
```
|
283
|
+
|
272
284
|
##### HexSolanaSigner
|
273
285
|
|
274
286
|
```typescript
|
@@ -433,6 +445,17 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
|
|
433
445
|
});
|
434
446
|
```
|
435
447
|
|
448
|
+
##### Polygon (POL / MATIC) Fiat Top Up
|
449
|
+
|
450
|
+
```ts
|
451
|
+
const turbo = TurboFactory.unauthenticated({ token: 'pol' });
|
452
|
+
|
453
|
+
const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
|
454
|
+
amount: USD(10.0), // $10.00 USD
|
455
|
+
owner: publicPolygonAddress,
|
456
|
+
});
|
457
|
+
```
|
458
|
+
|
436
459
|
##### KYVE Fiat Top Up
|
437
460
|
|
438
461
|
```ts
|
@@ -623,6 +646,16 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
|
623
646
|
});
|
624
647
|
```
|
625
648
|
|
649
|
+
##### Polygon (POL / MATIC) Crypto Top Up
|
650
|
+
|
651
|
+
```ts
|
652
|
+
const turbo = TurboFactory.authenticated({ signer, token: 'pol' });
|
653
|
+
|
654
|
+
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
655
|
+
tokenAmount: POLToTokenAmount(0.00001), // 0.00001 POL
|
656
|
+
});
|
657
|
+
```
|
658
|
+
|
626
659
|
##### Solana (SOL) Crypto Top Up
|
627
660
|
|
628
661
|
```ts
|
@@ -695,7 +728,7 @@ npx turbo --help
|
|
695
728
|
- `-g, --gateway <url>` - Set a custom crypto gateway URL
|
696
729
|
- `-t, --token <token>` - Token type for the command or connected wallet (default: "arweave")
|
697
730
|
|
698
|
-
- `-w, --wallet-file <filePath>` - Wallet file to use with the action. Formats accepted: JWK.json, KYVE or
|
731
|
+
- `-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
732
|
- `-m, --mnemonic <phrase>` - Mnemonic to use with the action (KYVE only)
|
700
733
|
- `-p, --private-key <key>` - Private key to use with the action
|
701
734
|
|
@@ -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.16.
|
310507
|
+
var version16 = "1.16.1";
|
310508
310508
|
|
310509
310509
|
// src/common/logger.ts
|
310510
310510
|
var TurboWinstonLogger = class _TurboWinstonLogger {
|
@@ -315358,8 +315358,10 @@ var TurboUnauthenticatedClient = class {
|
|
315358
315358
|
/**
|
315359
315359
|
* Returns the connected target Turbo wallet addresses for all supported tokens.
|
315360
315360
|
*/
|
315361
|
-
getTurboCryptoWallets() {
|
315362
|
-
|
315361
|
+
async getTurboCryptoWallets() {
|
315362
|
+
const wallets = await this.paymentService.getTurboCryptoWallets();
|
315363
|
+
wallets.pol = wallets.matic;
|
315364
|
+
return wallets;
|
315363
315365
|
}
|
315364
315366
|
};
|
315365
315367
|
var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
@@ -315423,6 +315425,7 @@ var TurboBaseFactory = class {
|
|
315423
315425
|
uploadServiceConfig = {},
|
315424
315426
|
token
|
315425
315427
|
} = {}) {
|
315428
|
+
token = token === "pol" ? "matic" : token;
|
315426
315429
|
const paymentService = new TurboUnauthenticatedPaymentService({
|
315427
315430
|
...paymentServiceConfig,
|
315428
315431
|
logger: this.logger,
|
@@ -315511,7 +315514,14 @@ var fiatCurrencyTypes = [
|
|
315511
315514
|
function isCurrency(currency) {
|
315512
315515
|
return fiatCurrencyTypes.includes(currency);
|
315513
315516
|
}
|
315514
|
-
var tokenTypes = [
|
315517
|
+
var tokenTypes = [
|
315518
|
+
"arweave",
|
315519
|
+
"solana",
|
315520
|
+
"ethereum",
|
315521
|
+
"kyve",
|
315522
|
+
"matic",
|
315523
|
+
"pol"
|
315524
|
+
];
|
315515
315525
|
var isNodeUploadFolderParams = (p8) => p8.folderPath !== void 0;
|
315516
315526
|
var isWebUploadFolderParams = (p8) => p8.files !== void 0;
|
315517
315527
|
function isKyvePrivateKey(wallet) {
|
@@ -315580,6 +315590,7 @@ function createTurboSigner({
|
|
315580
315590
|
case "solana":
|
315581
315591
|
return new HexSolanaSigner2(clientProvidedPrivateKey);
|
315582
315592
|
case "ethereum":
|
315593
|
+
case "matic":
|
315583
315594
|
if (!isEthPrivateKey(clientProvidedPrivateKey)) {
|
315584
315595
|
throw new Error(
|
315585
315596
|
"A valid Ethereum private key must be provided for EthereumSigner."
|
@@ -339329,6 +339340,25 @@ async function signerFromKyveMnemonic(mnemonic) {
|
|
339329
339340
|
return signerFromKyvePrivateKey2(privateKey);
|
339330
339341
|
}
|
339331
339342
|
|
339343
|
+
// src/common/token/polygon.ts
|
339344
|
+
init_dirname();
|
339345
|
+
init_buffer2();
|
339346
|
+
init_process2();
|
339347
|
+
var POLToTokenAmount = ETHToTokenAmount;
|
339348
|
+
var PolygonToken = class extends EthereumToken {
|
339349
|
+
constructor({
|
339350
|
+
logger: logger15 = TurboWinstonLogger.default,
|
339351
|
+
gatewayUrl = "https://polygon-rpc.com/",
|
339352
|
+
pollingOptions = {
|
339353
|
+
maxAttempts: 10,
|
339354
|
+
pollingIntervalMs: 4e3,
|
339355
|
+
initialBackoffMs: 5e3
|
339356
|
+
}
|
339357
|
+
} = {}) {
|
339358
|
+
super({ logger: logger15, gatewayUrl, pollingOptions });
|
339359
|
+
}
|
339360
|
+
};
|
339361
|
+
|
339332
339362
|
// src/common/token/solana.ts
|
339333
339363
|
init_dirname();
|
339334
339364
|
init_buffer2();
|
@@ -349997,13 +350027,17 @@ var defaultTokenMap = {
|
|
349997
350027
|
arweave: (config2) => new ArweaveToken(config2),
|
349998
350028
|
solana: (config2) => new SolanaToken(config2),
|
349999
350029
|
ethereum: (config2) => new EthereumToken(config2),
|
350000
|
-
kyve: (config2) => new KyveToken(config2)
|
350030
|
+
kyve: (config2) => new KyveToken(config2),
|
350031
|
+
matic: (config2) => new PolygonToken(config2),
|
350032
|
+
pol: (config2) => new PolygonToken(config2)
|
350001
350033
|
};
|
350002
350034
|
var tokenToBaseMap = {
|
350003
350035
|
arweave: (a8) => ARToTokenAmount(a8),
|
350004
350036
|
solana: (a8) => SOLToTokenAmount(a8),
|
350005
350037
|
ethereum: (a8) => ETHToTokenAmount(a8),
|
350006
|
-
kyve: (a8) => KYVEToTokenAmount(a8)
|
350038
|
+
kyve: (a8) => KYVEToTokenAmount(a8),
|
350039
|
+
matic: (a8) => POLToTokenAmount(a8),
|
350040
|
+
pol: (a8) => POLToTokenAmount(a8)
|
350007
350041
|
};
|
350008
350042
|
function isTokenType(token) {
|
350009
350043
|
return tokenTypes.includes(token);
|
@@ -350041,6 +350075,8 @@ var TurboDataItemAbstractSigner = class {
|
|
350041
350075
|
case "solana":
|
350042
350076
|
return import_bs584.default.encode(fromB64Url(owner));
|
350043
350077
|
case "ethereum":
|
350078
|
+
case "matic":
|
350079
|
+
case "pol":
|
350044
350080
|
return computeAddress2(computePublicKey(fromB64Url(owner)));
|
350045
350081
|
case "kyve":
|
350046
350082
|
return (0, import_amino3.pubkeyToAddress)(
|
@@ -350264,6 +350300,7 @@ var TurboFactory = class extends TurboBaseFactory {
|
|
350264
350300
|
tokenMap,
|
350265
350301
|
tokenTools
|
350266
350302
|
}) {
|
350303
|
+
token = token === "pol" ? "matic" : token;
|
350267
350304
|
if (!token) {
|
350268
350305
|
if (providedSigner) {
|
350269
350306
|
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,19 @@ 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
45
|
});
|
46
46
|
if (process.argv[1].includes('bin/turbo') || // Running from global .bin
|
47
47
|
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,37 @@
|
|
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("./topUp.js"), exports);
|
36
|
+
__exportStar(require("./uploadFile.js"), exports);
|
37
|
+
__exportStar(require("./uploadFolder.js"), exports);
|
@@ -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
|
+
}
|
@@ -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
|
+
];
|
package/lib/cjs/cli/utils.js
CHANGED
@@ -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
|
-
|
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 = {};
|
@@ -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,
|
package/lib/cjs/common/signer.js
CHANGED
@@ -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;
|
package/lib/cjs/common/turbo.js
CHANGED
@@ -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
|
-
|
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;
|
package/lib/cjs/node/factory.js
CHANGED
@@ -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
|