@ardrive/turbo-sdk 1.41.2 → 1.42.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/lib/cjs/cli/options.js +0 -10
- package/lib/cjs/cli/utils.js +3 -19
- package/lib/cjs/common/factory.js +1 -3
- package/lib/cjs/common/payment.js +5 -3
- package/lib/cjs/common/token/ario.js +104 -83
- package/lib/cjs/common/token/solana.js +1 -0
- package/lib/cjs/node/factory.js +1 -3
- package/lib/cjs/utils/common.js +5 -17
- package/lib/cjs/web/factory.js +1 -3
- package/lib/esm/cli/options.js +0 -10
- package/lib/esm/cli/utils.js +4 -20
- package/lib/esm/common/factory.js +1 -3
- package/lib/esm/common/payment.js +5 -3
- package/lib/esm/common/token/ario.js +102 -84
- package/lib/esm/common/token/solana.js +1 -0
- package/lib/esm/node/factory.js +1 -3
- package/lib/esm/utils/common.js +4 -16
- package/lib/esm/web/factory.js +1 -3
- package/lib/types/cli/options.d.ts +0 -10
- package/lib/types/cli/options.d.ts.map +1 -1
- package/lib/types/cli/types.d.ts +0 -2
- package/lib/types/cli/types.d.ts.map +1 -1
- package/lib/types/cli/utils.d.ts.map +1 -1
- package/lib/types/common/factory.d.ts +1 -1
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts +1 -0
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/token/ario.d.ts +13 -9
- package/lib/types/common/token/ario.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts.map +1 -1
- package/lib/types/common/token/solana.d.ts.map +1 -1
- package/lib/types/node/factory.d.ts +1 -1
- package/lib/types/node/factory.d.ts.map +1 -1
- package/lib/types/types.d.ts +0 -4
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/common.d.ts +0 -12
- package/lib/types/utils/common.d.ts.map +1 -1
- package/lib/types/web/factory.d.ts +1 -1
- package/lib/types/web/factory.d.ts.map +1 -1
- package/package.json +2 -1
package/lib/cjs/cli/options.js
CHANGED
|
@@ -76,16 +76,6 @@ exports.optionMap = {
|
|
|
76
76
|
description: 'Set a custom payment service URL',
|
|
77
77
|
default: undefined,
|
|
78
78
|
},
|
|
79
|
-
processId: {
|
|
80
|
-
alias: '--process-id <processId>',
|
|
81
|
-
description: 'Set a custom target process ID for the action',
|
|
82
|
-
default: undefined,
|
|
83
|
-
},
|
|
84
|
-
cuUrl: {
|
|
85
|
-
alias: '--cu-url <cuUrl>',
|
|
86
|
-
description: 'Set a custom CU URL for the action',
|
|
87
|
-
default: undefined,
|
|
88
|
-
},
|
|
89
79
|
dev: {
|
|
90
80
|
alias: '--dev',
|
|
91
81
|
description: 'Enable Turbo development endpoints',
|
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -124,7 +124,9 @@ async function privateKeyFromOptions({ mnemonic, privateKey, walletFile, token,
|
|
|
124
124
|
}
|
|
125
125
|
else if (walletFile !== undefined) {
|
|
126
126
|
const wallet = JSON.parse((0, fs_1.readFileSync)(walletFile, 'utf-8'));
|
|
127
|
-
return token === 'solana'
|
|
127
|
+
return token === 'solana' || token === 'ario'
|
|
128
|
+
? bs58_1.default.encode(wallet)
|
|
129
|
+
: wallet;
|
|
128
130
|
}
|
|
129
131
|
else if (privateKey !== undefined) {
|
|
130
132
|
return privateKey;
|
|
@@ -138,8 +140,6 @@ function configFromOptions(options) {
|
|
|
138
140
|
let paymentUrl = undefined;
|
|
139
141
|
let uploadUrl = undefined;
|
|
140
142
|
let gatewayUrl = undefined;
|
|
141
|
-
let processId = undefined;
|
|
142
|
-
let cuUrl = undefined;
|
|
143
143
|
if (options.local && options.dev) {
|
|
144
144
|
throw new Error('Cannot use both --local and --dev flags');
|
|
145
145
|
}
|
|
@@ -148,10 +148,6 @@ function configFromOptions(options) {
|
|
|
148
148
|
paymentUrl = index_js_1.developmentTurboConfiguration.paymentServiceConfig.url;
|
|
149
149
|
uploadUrl = index_js_1.developmentTurboConfiguration.uploadServiceConfig.url;
|
|
150
150
|
gatewayUrl = common_js_1.tokenToDevGatewayMap[token];
|
|
151
|
-
if (options.token === 'ario') {
|
|
152
|
-
processId = common_js_1.tokenToDevAoConfigMap[token].processId;
|
|
153
|
-
cuUrl = common_js_1.tokenToDevAoConfigMap[token].cuUrl;
|
|
154
|
-
}
|
|
155
151
|
}
|
|
156
152
|
else if (options.local) {
|
|
157
153
|
// Use local endpoints
|
|
@@ -163,10 +159,6 @@ function configFromOptions(options) {
|
|
|
163
159
|
// Use default endpoints
|
|
164
160
|
paymentUrl = index_js_1.defaultTurboConfiguration.paymentServiceConfig.url;
|
|
165
161
|
uploadUrl = index_js_1.defaultTurboConfiguration.uploadServiceConfig.url;
|
|
166
|
-
if (options.token === 'ario') {
|
|
167
|
-
processId = common_js_1.defaultProdAoConfigs[token].processId;
|
|
168
|
-
cuUrl = common_js_1.defaultProdAoConfigs[token].cuUrl;
|
|
169
|
-
}
|
|
170
162
|
}
|
|
171
163
|
// Override gateway, payment, and upload service default endpoints if provided
|
|
172
164
|
if (options.gateway !== undefined) {
|
|
@@ -178,19 +170,11 @@ function configFromOptions(options) {
|
|
|
178
170
|
if (options.uploadUrl !== undefined) {
|
|
179
171
|
uploadUrl = options.uploadUrl;
|
|
180
172
|
}
|
|
181
|
-
if (options.cuUrl !== undefined) {
|
|
182
|
-
cuUrl = options.cuUrl;
|
|
183
|
-
}
|
|
184
|
-
if (options.processId !== undefined) {
|
|
185
|
-
processId = options.processId;
|
|
186
|
-
}
|
|
187
173
|
const config = {
|
|
188
174
|
paymentServiceConfig: { url: paymentUrl },
|
|
189
175
|
uploadServiceConfig: { url: uploadUrl },
|
|
190
176
|
gatewayUrl,
|
|
191
177
|
token,
|
|
192
|
-
processId,
|
|
193
|
-
cuUrl,
|
|
194
178
|
};
|
|
195
179
|
return config;
|
|
196
180
|
}
|
|
@@ -46,7 +46,7 @@ class TurboBaseFactory {
|
|
|
46
46
|
paymentService,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
getAuthenticatedTurbo({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, logger, walletAdapter,
|
|
49
|
+
getAuthenticatedTurbo({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, logger, walletAdapter, }) {
|
|
50
50
|
token = token === 'pol' ? 'matic' : token;
|
|
51
51
|
if (!token) {
|
|
52
52
|
if (providedSigner) {
|
|
@@ -104,8 +104,6 @@ class TurboBaseFactory {
|
|
|
104
104
|
tokenTools = tokenMap.arweave;
|
|
105
105
|
}
|
|
106
106
|
tokenTools = index_js_1.defaultTokenMap[token]?.({
|
|
107
|
-
cuUrl,
|
|
108
|
-
processId,
|
|
109
107
|
gatewayUrl,
|
|
110
108
|
logger,
|
|
111
109
|
});
|
|
@@ -33,6 +33,7 @@ class TurboUnauthenticatedPaymentService {
|
|
|
33
33
|
logger: this.logger,
|
|
34
34
|
});
|
|
35
35
|
this.token = token;
|
|
36
|
+
this.url = url;
|
|
36
37
|
}
|
|
37
38
|
async getBalance(address) {
|
|
38
39
|
const balance = await this.httpService.get({
|
|
@@ -144,6 +145,10 @@ class TurboUnauthenticatedPaymentService {
|
|
|
144
145
|
return this.getCheckout(params);
|
|
145
146
|
}
|
|
146
147
|
async submitFundTransaction({ txId, }) {
|
|
148
|
+
this.logger.debug('Submitting fund transaction to Turbo...', {
|
|
149
|
+
txId,
|
|
150
|
+
url: this.url,
|
|
151
|
+
});
|
|
147
152
|
const response = await this.httpService.post({
|
|
148
153
|
endpoint: `/account/balance/${this.token}`,
|
|
149
154
|
data: Buffer.from(JSON.stringify({ tx_id: txId })),
|
|
@@ -282,9 +287,6 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
|
|
|
282
287
|
if (!this.tokenTools) {
|
|
283
288
|
throw new Error(`Token type not supported for crypto fund ${this.token}`);
|
|
284
289
|
}
|
|
285
|
-
if (this.token === 'ario') {
|
|
286
|
-
throw new Error(`Top up with tokens is not supported for ARIO until after SOL migration is complete`);
|
|
287
|
-
}
|
|
288
290
|
if (turboCreditDestinationAddress !== undefined) {
|
|
289
291
|
if ((0, common_js_1.isAnyValidUserAddress)(turboCreditDestinationAddress) === false) {
|
|
290
292
|
throw new Error(`Invalid turboCreditDestinationAddress provided: ${turboCreditDestinationAddress}`);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ARIOToTokenAmount = exports.mARIOToTokenAmount = exports.ARIOToken = void 0;
|
|
4
7
|
/**
|
|
@@ -16,68 +19,123 @@ exports.ARIOToTokenAmount = exports.mARIOToTokenAmount = exports.ARIOToken = voi
|
|
|
16
19
|
* See the License for the specific language governing permissions and
|
|
17
20
|
* limitations under the License.
|
|
18
21
|
*/
|
|
19
|
-
const
|
|
20
|
-
const
|
|
22
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
23
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
21
24
|
const bignumber_js_1 = require("bignumber.js");
|
|
25
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
22
26
|
const common_js_1 = require("../../utils/common.js");
|
|
23
|
-
const version_js_1 = require("../../version.js");
|
|
24
27
|
const logger_js_1 = require("../logger.js");
|
|
28
|
+
const solana_js_1 = require("./solana.js");
|
|
29
|
+
const ARIO_SPL_MINT_ADDRESS = 'DcNnMuFxwhgV4WY1HVSaSEgr92bv2b1vUvEKiNxWqHdF';
|
|
30
|
+
const DEVNET_ARIO_SPL_MINT_ADDRESS = '6vTw5CysRXQ4ybbHkDUiisHWVsBeMtUzYvJqs2iqHyaN';
|
|
31
|
+
const ARIO_TOKEN_DECIMALS = 6;
|
|
25
32
|
class ARIOToken {
|
|
26
|
-
constructor({
|
|
33
|
+
constructor({ gatewayUrl = common_js_1.defaultProdGatewayUrls.solana, logger = logger_js_1.Logger.default, pollingOptions = {
|
|
34
|
+
maxAttempts: 10,
|
|
35
|
+
pollingIntervalMs: 2_500,
|
|
27
36
|
initialBackoffMs: 500,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.ao = (0, aoconnect_1.connect)({
|
|
32
|
-
CU_URL: cuUrl,
|
|
33
|
-
});
|
|
34
|
-
this.processId = processId;
|
|
37
|
+
}, } = {}) {
|
|
38
|
+
this.gatewayUrl = gatewayUrl;
|
|
39
|
+
this.connection = new web3_js_1.Connection(gatewayUrl, 'confirmed');
|
|
35
40
|
this.pollingOptions = pollingOptions;
|
|
36
41
|
this.logger = logger;
|
|
42
|
+
if (gatewayUrl.includes('devnet')) {
|
|
43
|
+
this.mintAddress = DEVNET_ARIO_SPL_MINT_ADDRESS;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.mintAddress = ARIO_SPL_MINT_ADDRESS;
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
|
-
async createAndSubmitTx({ target, signer
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
value: tokenAmount.toString(),
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'Turbo-SDK',
|
|
54
|
-
value: version_js_1.version,
|
|
55
|
-
},
|
|
56
|
-
];
|
|
49
|
+
async createAndSubmitTx({ target, signer, tokenAmount, turboCreditDestinationAddress, }) {
|
|
50
|
+
const ownerPublicKey = new web3_js_1.PublicKey(bs58_1.default.encode(Uint8Array.from(await signer.getPublicKey())));
|
|
51
|
+
const recipient = new web3_js_1.PublicKey(target);
|
|
52
|
+
const mint = new web3_js_1.PublicKey(this.mintAddress);
|
|
53
|
+
const fromAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, ownerPublicKey);
|
|
54
|
+
const toAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, recipient);
|
|
55
|
+
const tx = new web3_js_1.Transaction({
|
|
56
|
+
feePayer: ownerPublicKey,
|
|
57
|
+
...(await this.connection.getLatestBlockhash()),
|
|
58
|
+
});
|
|
59
|
+
tx.add((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(ownerPublicKey, toAta, recipient, mint));
|
|
60
|
+
tx.add((0, spl_token_1.createTransferCheckedInstruction)(fromAta, mint, toAta, ownerPublicKey, BigInt(new bignumber_js_1.BigNumber(tokenAmount).toFixed(0)), ARIO_TOKEN_DECIMALS));
|
|
57
61
|
if (turboCreditDestinationAddress !== undefined) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
tx.add(new web3_js_1.TransactionInstruction({
|
|
63
|
+
programId: new web3_js_1.PublicKey(solana_js_1.memoProgramId),
|
|
64
|
+
keys: [],
|
|
65
|
+
data: Buffer.from('turboCreditDestinationAddress=' + turboCreditDestinationAddress),
|
|
66
|
+
}));
|
|
62
67
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.logger.debug('Submitted
|
|
68
|
+
const serializedTx = tx.serializeMessage();
|
|
69
|
+
const signature = await signer.signData(Uint8Array.from(serializedTx));
|
|
70
|
+
tx.addSignature(ownerPublicKey, Buffer.from(signature));
|
|
71
|
+
const txId = bs58_1.default.encode(signature);
|
|
72
|
+
await this.submitTx(tx, txId);
|
|
73
|
+
this.logger.debug('Submitted ARIO SPL transfer transaction...', {
|
|
69
74
|
id: txId,
|
|
70
75
|
target,
|
|
71
76
|
tokenAmount,
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
fromAta: fromAta.toBase58(),
|
|
78
|
+
toAta: toAta.toBase58(),
|
|
79
|
+
mint: mint.toBase58(),
|
|
74
80
|
});
|
|
75
81
|
return { id: txId, target, reward: '0' };
|
|
76
82
|
}
|
|
77
|
-
async
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
async submitTx(tx, id) {
|
|
84
|
+
this.logger.debug('Submitting ARIO fund transaction...', { id });
|
|
85
|
+
await this.connection.sendRawTransaction(tx.serialize(), {
|
|
86
|
+
maxRetries: this.pollingOptions.maxAttempts,
|
|
87
|
+
});
|
|
88
|
+
if (tx.recentBlockhash === undefined ||
|
|
89
|
+
tx.lastValidBlockHeight === undefined) {
|
|
90
|
+
throw new Error('Failed to submit Transaction -- missing blockhash or lastValidBlockHeight from transaction creation. Solana Gateway Url:' +
|
|
91
|
+
this.gatewayUrl);
|
|
92
|
+
}
|
|
93
|
+
await this.connection.confirmTransaction({
|
|
94
|
+
signature: id,
|
|
95
|
+
blockhash: tx.recentBlockhash,
|
|
96
|
+
lastValidBlockHeight: tx.lastValidBlockHeight,
|
|
97
|
+
}, 'finalized');
|
|
98
|
+
}
|
|
99
|
+
async pollTxAvailability({ txId }) {
|
|
100
|
+
const { maxAttempts, pollingIntervalMs, initialBackoffMs } = this.pollingOptions;
|
|
101
|
+
this.logger.debug('Polling for ARIO SPL transaction...', {
|
|
102
|
+
txId,
|
|
103
|
+
pollingOptions: this.pollingOptions,
|
|
104
|
+
gatewayUrl: this.gatewayUrl,
|
|
105
|
+
});
|
|
106
|
+
await (0, common_js_1.sleep)(initialBackoffMs);
|
|
107
|
+
let attempts = 0;
|
|
108
|
+
while (attempts < maxAttempts) {
|
|
109
|
+
let status;
|
|
110
|
+
attempts++;
|
|
111
|
+
try {
|
|
112
|
+
const statuses = await this.connection.getSignatureStatuses([txId], {
|
|
113
|
+
searchTransactionHistory: true,
|
|
114
|
+
});
|
|
115
|
+
status = {
|
|
116
|
+
context: statuses.context,
|
|
117
|
+
value: statuses.value[0],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
this.logger.debug('Failed to poll ARIO SPL transaction...', { err });
|
|
122
|
+
}
|
|
123
|
+
if (status && status.value && status.value.err !== null) {
|
|
124
|
+
throw new Error(`Transaction failed: ${status.value.err}`);
|
|
125
|
+
}
|
|
126
|
+
if (status && status.value && status.value.slot !== null) {
|
|
127
|
+
this.logger.debug('Transaction found!', { txId, status });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.logger.debug('ARIO SPL transaction not found, polling...', {
|
|
131
|
+
txId,
|
|
132
|
+
attempts,
|
|
133
|
+
maxAttempts,
|
|
134
|
+
pollingIntervalMs,
|
|
135
|
+
});
|
|
136
|
+
await (0, common_js_1.sleep)(pollingIntervalMs);
|
|
137
|
+
}
|
|
138
|
+
throw new Error('Transaction not found after polling, transaction id: ' + txId);
|
|
81
139
|
}
|
|
82
140
|
}
|
|
83
141
|
exports.ARIOToken = ARIOToken;
|
|
@@ -85,40 +143,3 @@ const mARIOToTokenAmount = (mARIO) => mARIO;
|
|
|
85
143
|
exports.mARIOToTokenAmount = mARIOToTokenAmount;
|
|
86
144
|
const ARIOToTokenAmount = (ario) => new bignumber_js_1.BigNumber(ario).times(1e6).valueOf();
|
|
87
145
|
exports.ARIOToTokenAmount = ARIOToTokenAmount;
|
|
88
|
-
function createAoSigner(signer) {
|
|
89
|
-
if (!('publicKey' in signer)) {
|
|
90
|
-
return (0, aoconnect_1.createDataItemSigner)(signer);
|
|
91
|
-
}
|
|
92
|
-
const aoSigner = async ({ data, tags, target, anchor }) => {
|
|
93
|
-
// ensure appropriate permissions are granted with injected signers.
|
|
94
|
-
if (signer.publicKey === undefined &&
|
|
95
|
-
'setPublicKey' in signer &&
|
|
96
|
-
typeof signer.setPublicKey === 'function') {
|
|
97
|
-
await signer.setPublicKey();
|
|
98
|
-
}
|
|
99
|
-
if (signer instanceof arbundles_1.ArconnectSigner) {
|
|
100
|
-
// Sign using Arconnect signDataItem API
|
|
101
|
-
const signedDataItem = await signer['signer'].signDataItem({
|
|
102
|
-
data,
|
|
103
|
-
tags,
|
|
104
|
-
target,
|
|
105
|
-
anchor,
|
|
106
|
-
});
|
|
107
|
-
const dataItem = new arbundles_1.DataItem(Buffer.from(signedDataItem));
|
|
108
|
-
return {
|
|
109
|
-
id: dataItem.id,
|
|
110
|
-
raw: dataItem.getRaw(),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
const dataItem = (0, arbundles_1.createData)(data ?? '', signer, { tags, target, anchor });
|
|
114
|
-
await dataItem.sign(signer);
|
|
115
|
-
const signedData = {
|
|
116
|
-
id: dataItem.id,
|
|
117
|
-
raw: dataItem.getRaw(),
|
|
118
|
-
};
|
|
119
|
-
return signedData;
|
|
120
|
-
};
|
|
121
|
-
// eslint-disable-next-line
|
|
122
|
-
// @ts-ignore Buffer vs ArrayBuffer type mismatch
|
|
123
|
-
return aoSigner;
|
|
124
|
-
}
|
|
@@ -114,6 +114,7 @@ class SolanaToken {
|
|
|
114
114
|
throw new Error(`Transaction failed: ${status.value.err}`);
|
|
115
115
|
}
|
|
116
116
|
if (status && status.value && status.value.slot !== null) {
|
|
117
|
+
this.logger.debug('Transaction found!', { txId, status });
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
120
|
this.logger.debug('Transaction not found, polling...', {
|
package/lib/cjs/node/factory.js
CHANGED
|
@@ -37,7 +37,7 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
|
|
|
37
37
|
// Import the TurboAuthenticatedUploadService class from the node upload module
|
|
38
38
|
return new upload_js_1.TurboAuthenticatedUploadService(config);
|
|
39
39
|
}
|
|
40
|
-
static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, tokenMap, gatewayUrl, tokenTools, walletAdapter,
|
|
40
|
+
static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, tokenMap, gatewayUrl, tokenTools, walletAdapter, }) {
|
|
41
41
|
return new TurboFactory().getAuthenticatedTurbo({
|
|
42
42
|
privateKey,
|
|
43
43
|
signer: providedSigner,
|
|
@@ -48,8 +48,6 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
|
|
|
48
48
|
gatewayUrl,
|
|
49
49
|
tokenTools,
|
|
50
50
|
walletAdapter,
|
|
51
|
-
processId,
|
|
52
|
-
cuUrl,
|
|
53
51
|
logger: this.logger,
|
|
54
52
|
});
|
|
55
53
|
}
|
package/lib/cjs/utils/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defaultProdGatewayUrls = exports.tokenToDevGatewayMap = void 0;
|
|
4
4
|
exports.sleep = sleep;
|
|
5
5
|
exports.isWeb = isWeb;
|
|
6
6
|
exports.createTurboSigner = createTurboSigner;
|
|
@@ -49,7 +49,7 @@ const polygonTestnetRpc = 'https://rpc-amoy.polygon.technology';
|
|
|
49
49
|
const baseMainnetRpc = 'https://mainnet.base.org';
|
|
50
50
|
exports.tokenToDevGatewayMap = {
|
|
51
51
|
arweave: 'https://turbo-gateway.com', // No arweave test net
|
|
52
|
-
ario: 'https://
|
|
52
|
+
ario: 'https://api.devnet.solana.com',
|
|
53
53
|
'base-ario': baseMainnetRpc, // No base-ario test net contract deployed
|
|
54
54
|
solana: 'https://api.devnet.solana.com',
|
|
55
55
|
ethereum: ethTestnetRpc,
|
|
@@ -61,15 +61,9 @@ exports.tokenToDevGatewayMap = {
|
|
|
61
61
|
'base-usdc': baseTestnetRpc,
|
|
62
62
|
'polygon-usdc': polygonTestnetRpc,
|
|
63
63
|
};
|
|
64
|
-
exports.tokenToDevAoConfigMap = {
|
|
65
|
-
ario: {
|
|
66
|
-
processId: 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA',
|
|
67
|
-
cuUrl: 'https://cu.ardrive.io',
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
64
|
exports.defaultProdGatewayUrls = {
|
|
71
65
|
arweave: 'https://turbo-gateway.com',
|
|
72
|
-
ario: 'https://
|
|
66
|
+
ario: 'https://api.mainnet-beta.solana.com',
|
|
73
67
|
'base-ario': baseMainnetRpc,
|
|
74
68
|
solana: 'https://api.mainnet-beta.solana.com',
|
|
75
69
|
ethereum: 'https://cloudflare-eth.com/',
|
|
@@ -81,12 +75,6 @@ exports.defaultProdGatewayUrls = {
|
|
|
81
75
|
'base-usdc': baseMainnetRpc,
|
|
82
76
|
'polygon-usdc': 'https://polygon-rpc.com/',
|
|
83
77
|
};
|
|
84
|
-
exports.defaultProdAoConfigs = {
|
|
85
|
-
ario: {
|
|
86
|
-
processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE',
|
|
87
|
-
cuUrl: 'https://cu.ardrive.io',
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
78
|
function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientProvidedPrivateKey, token = 'arweave', }) {
|
|
91
79
|
if (clientProvidedSigner !== undefined) {
|
|
92
80
|
if (clientProvidedSigner instanceof arbundles_1.InjectedEthereumSigner) {
|
|
@@ -106,6 +94,7 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
|
|
|
106
94
|
}
|
|
107
95
|
switch (token) {
|
|
108
96
|
case 'solana':
|
|
97
|
+
case 'ario':
|
|
109
98
|
return new arbundles_1.HexSolanaSigner(clientProvidedPrivateKey);
|
|
110
99
|
case 'ethereum':
|
|
111
100
|
case 'pol':
|
|
@@ -125,7 +114,6 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
|
|
|
125
114
|
}
|
|
126
115
|
return signerFromKyvePrivateKey(clientProvidedPrivateKey);
|
|
127
116
|
case 'arweave':
|
|
128
|
-
case 'ario':
|
|
129
117
|
if (!(0, types_js_1.isJWK)(clientProvidedPrivateKey)) {
|
|
130
118
|
throw new Error('A JWK must be provided for ArweaveSigner.');
|
|
131
119
|
}
|
|
@@ -170,8 +158,8 @@ function isValidKyveAddress(address) {
|
|
|
170
158
|
function isValidUserAddress(address, type) {
|
|
171
159
|
switch (type) {
|
|
172
160
|
case 'arweave':
|
|
173
|
-
case 'ario':
|
|
174
161
|
return isValidArweaveBase64URL(address);
|
|
162
|
+
case 'ario':
|
|
175
163
|
case 'solana':
|
|
176
164
|
return isValidSolanaAddress(address);
|
|
177
165
|
case 'ethereum':
|
package/lib/cjs/web/factory.js
CHANGED
|
@@ -37,7 +37,7 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
|
|
|
37
37
|
// Import the TurboAuthenticatedUploadService class from the web upload module
|
|
38
38
|
return new upload_js_1.TurboAuthenticatedUploadService(config);
|
|
39
39
|
}
|
|
40
|
-
static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, walletAdapter,
|
|
40
|
+
static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, walletAdapter, }) {
|
|
41
41
|
return new TurboFactory().getAuthenticatedTurbo({
|
|
42
42
|
privateKey,
|
|
43
43
|
signer: providedSigner,
|
|
@@ -49,8 +49,6 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
|
|
|
49
49
|
tokenTools,
|
|
50
50
|
logger: this.logger,
|
|
51
51
|
walletAdapter,
|
|
52
|
-
cuUrl,
|
|
53
|
-
processId,
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
}
|
package/lib/esm/cli/options.js
CHANGED
|
@@ -73,16 +73,6 @@ export const optionMap = {
|
|
|
73
73
|
description: 'Set a custom payment service URL',
|
|
74
74
|
default: undefined,
|
|
75
75
|
},
|
|
76
|
-
processId: {
|
|
77
|
-
alias: '--process-id <processId>',
|
|
78
|
-
description: 'Set a custom target process ID for the action',
|
|
79
|
-
default: undefined,
|
|
80
|
-
},
|
|
81
|
-
cuUrl: {
|
|
82
|
-
alias: '--cu-url <cuUrl>',
|
|
83
|
-
description: 'Set a custom CU URL for the action',
|
|
84
|
-
default: undefined,
|
|
85
|
-
},
|
|
86
76
|
dev: {
|
|
87
77
|
alias: '--dev',
|
|
88
78
|
description: 'Enable Turbo development endpoints',
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import bs58 from 'bs58';
|
|
17
17
|
import { readFileSync, statSync } from 'fs';
|
|
18
18
|
import { ExistingBalanceFunding, OnDemandFunding, TurboFactory, X402Funding, defaultTurboConfiguration, developmentTurboConfiguration, fiatCurrencyTypes, isCurrency, isTokenType, privateKeyFromKyveMnemonic, tokenToBaseMap, } from '../node/index.js';
|
|
19
|
-
import {
|
|
19
|
+
import { tokenToDevGatewayMap } from '../utils/common.js';
|
|
20
20
|
import { NoWalletProvidedError } from './errors.js';
|
|
21
21
|
export function exitWithErrorLog(error) {
|
|
22
22
|
console.error(error instanceof Error ? error.message : error);
|
|
@@ -100,7 +100,9 @@ export async function privateKeyFromOptions({ mnemonic, privateKey, walletFile,
|
|
|
100
100
|
}
|
|
101
101
|
else if (walletFile !== undefined) {
|
|
102
102
|
const wallet = JSON.parse(readFileSync(walletFile, 'utf-8'));
|
|
103
|
-
return token === 'solana'
|
|
103
|
+
return token === 'solana' || token === 'ario'
|
|
104
|
+
? bs58.encode(wallet)
|
|
105
|
+
: wallet;
|
|
104
106
|
}
|
|
105
107
|
else if (privateKey !== undefined) {
|
|
106
108
|
return privateKey;
|
|
@@ -114,8 +116,6 @@ export function configFromOptions(options) {
|
|
|
114
116
|
let paymentUrl = undefined;
|
|
115
117
|
let uploadUrl = undefined;
|
|
116
118
|
let gatewayUrl = undefined;
|
|
117
|
-
let processId = undefined;
|
|
118
|
-
let cuUrl = undefined;
|
|
119
119
|
if (options.local && options.dev) {
|
|
120
120
|
throw new Error('Cannot use both --local and --dev flags');
|
|
121
121
|
}
|
|
@@ -124,10 +124,6 @@ export function configFromOptions(options) {
|
|
|
124
124
|
paymentUrl = developmentTurboConfiguration.paymentServiceConfig.url;
|
|
125
125
|
uploadUrl = developmentTurboConfiguration.uploadServiceConfig.url;
|
|
126
126
|
gatewayUrl = tokenToDevGatewayMap[token];
|
|
127
|
-
if (options.token === 'ario') {
|
|
128
|
-
processId = tokenToDevAoConfigMap[token].processId;
|
|
129
|
-
cuUrl = tokenToDevAoConfigMap[token].cuUrl;
|
|
130
|
-
}
|
|
131
127
|
}
|
|
132
128
|
else if (options.local) {
|
|
133
129
|
// Use local endpoints
|
|
@@ -139,10 +135,6 @@ export function configFromOptions(options) {
|
|
|
139
135
|
// Use default endpoints
|
|
140
136
|
paymentUrl = defaultTurboConfiguration.paymentServiceConfig.url;
|
|
141
137
|
uploadUrl = defaultTurboConfiguration.uploadServiceConfig.url;
|
|
142
|
-
if (options.token === 'ario') {
|
|
143
|
-
processId = defaultProdAoConfigs[token].processId;
|
|
144
|
-
cuUrl = defaultProdAoConfigs[token].cuUrl;
|
|
145
|
-
}
|
|
146
138
|
}
|
|
147
139
|
// Override gateway, payment, and upload service default endpoints if provided
|
|
148
140
|
if (options.gateway !== undefined) {
|
|
@@ -154,19 +146,11 @@ export function configFromOptions(options) {
|
|
|
154
146
|
if (options.uploadUrl !== undefined) {
|
|
155
147
|
uploadUrl = options.uploadUrl;
|
|
156
148
|
}
|
|
157
|
-
if (options.cuUrl !== undefined) {
|
|
158
|
-
cuUrl = options.cuUrl;
|
|
159
|
-
}
|
|
160
|
-
if (options.processId !== undefined) {
|
|
161
|
-
processId = options.processId;
|
|
162
|
-
}
|
|
163
149
|
const config = {
|
|
164
150
|
paymentServiceConfig: { url: paymentUrl },
|
|
165
151
|
uploadServiceConfig: { url: uploadUrl },
|
|
166
152
|
gatewayUrl,
|
|
167
153
|
token,
|
|
168
|
-
processId,
|
|
169
|
-
cuUrl,
|
|
170
154
|
};
|
|
171
155
|
return config;
|
|
172
156
|
}
|
|
@@ -43,7 +43,7 @@ export class TurboBaseFactory {
|
|
|
43
43
|
paymentService,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
getAuthenticatedTurbo({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, logger, walletAdapter,
|
|
46
|
+
getAuthenticatedTurbo({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, gatewayUrl, tokenMap, tokenTools, logger, walletAdapter, }) {
|
|
47
47
|
token = token === 'pol' ? 'matic' : token;
|
|
48
48
|
if (!token) {
|
|
49
49
|
if (providedSigner) {
|
|
@@ -101,8 +101,6 @@ export class TurboBaseFactory {
|
|
|
101
101
|
tokenTools = tokenMap.arweave;
|
|
102
102
|
}
|
|
103
103
|
tokenTools = defaultTokenMap[token]?.({
|
|
104
|
-
cuUrl,
|
|
105
|
-
processId,
|
|
106
104
|
gatewayUrl,
|
|
107
105
|
logger,
|
|
108
106
|
});
|
|
@@ -30,6 +30,7 @@ export class TurboUnauthenticatedPaymentService {
|
|
|
30
30
|
logger: this.logger,
|
|
31
31
|
});
|
|
32
32
|
this.token = token;
|
|
33
|
+
this.url = url;
|
|
33
34
|
}
|
|
34
35
|
async getBalance(address) {
|
|
35
36
|
const balance = await this.httpService.get({
|
|
@@ -141,6 +142,10 @@ export class TurboUnauthenticatedPaymentService {
|
|
|
141
142
|
return this.getCheckout(params);
|
|
142
143
|
}
|
|
143
144
|
async submitFundTransaction({ txId, }) {
|
|
145
|
+
this.logger.debug('Submitting fund transaction to Turbo...', {
|
|
146
|
+
txId,
|
|
147
|
+
url: this.url,
|
|
148
|
+
});
|
|
144
149
|
const response = await this.httpService.post({
|
|
145
150
|
endpoint: `/account/balance/${this.token}`,
|
|
146
151
|
data: Buffer.from(JSON.stringify({ tx_id: txId })),
|
|
@@ -278,9 +283,6 @@ export class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymen
|
|
|
278
283
|
if (!this.tokenTools) {
|
|
279
284
|
throw new Error(`Token type not supported for crypto fund ${this.token}`);
|
|
280
285
|
}
|
|
281
|
-
if (this.token === 'ario') {
|
|
282
|
-
throw new Error(`Top up with tokens is not supported for ARIO until after SOL migration is complete`);
|
|
283
|
-
}
|
|
284
286
|
if (turboCreditDestinationAddress !== undefined) {
|
|
285
287
|
if (isAnyValidUserAddress(turboCreditDestinationAddress) === false) {
|
|
286
288
|
throw new Error(`Invalid turboCreditDestinationAddress provided: ${turboCreditDestinationAddress}`);
|