@ardrive/turbo-sdk 1.20.2 → 1.21.0
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 +29 -0
- package/bundles/web.bundle.min.js +312 -277
- package/lib/cjs/cli/cli.js +6 -0
- package/lib/cjs/cli/commands/shareCredits.js +1 -1
- package/lib/cjs/cli/commands/tokenPrice.js +45 -0
- package/lib/cjs/cli/options.js +4 -0
- package/lib/cjs/common/payment.js +15 -0
- package/lib/cjs/common/signer.js +3 -3
- package/lib/cjs/common/token/index.js +9 -1
- package/lib/cjs/common/turbo.js +6 -0
- package/lib/cjs/utils/base64.js +2 -2
- package/lib/cjs/utils/common.js +1 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +6 -0
- package/lib/esm/cli/commands/shareCredits.js +1 -1
- package/lib/esm/cli/commands/tokenPrice.js +42 -0
- package/lib/esm/cli/options.js +4 -0
- package/lib/esm/common/payment.js +15 -0
- package/lib/esm/common/signer.js +3 -3
- package/lib/esm/common/token/index.js +8 -0
- package/lib/esm/common/turbo.js +6 -0
- package/lib/esm/utils/base64.js +2 -2
- package/lib/esm/utils/common.js +1 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/shareCredits.d.ts.map +1 -1
- package/lib/types/cli/commands/tokenPrice.d.ts +3 -0
- package/lib/types/cli/commands/tokenPrice.d.ts.map +1 -0
- package/lib/types/cli/options.d.ts +4 -0
- package/lib/types/cli/options.d.ts.map +1 -1
- package/lib/types/cli/types.d.ts +6 -3
- package/lib/types/cli/types.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts +4 -1
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts +1 -0
- package/lib/types/common/token/index.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +7 -1
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/types.d.ts +8 -0
- 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/version.d.ts.map +1 -1
- package/package.json +1 -1
@@ -310551,7 +310551,7 @@ var import_winston = __toESM(require_winston(), 1);
|
|
310551
310551
|
init_dirname();
|
310552
310552
|
init_buffer2();
|
310553
310553
|
init_process2();
|
310554
|
-
var version16 = "1.20.2
|
310554
|
+
var version16 = "1.20.2";
|
310555
310555
|
|
310556
310556
|
// src/common/logger.ts
|
310557
310557
|
var TurboWinstonLogger = class _TurboWinstonLogger {
|
@@ -314732,277 +314732,6 @@ var TurboHTTPService = class {
|
|
314732
314732
|
}
|
314733
314733
|
};
|
314734
314734
|
|
314735
|
-
// src/common/payment.ts
|
314736
|
-
var developmentPaymentServiceURL = "https://payment.ardrive.dev";
|
314737
|
-
var defaultPaymentServiceURL = "https://payment.ardrive.io";
|
314738
|
-
var TurboUnauthenticatedPaymentService = class {
|
314739
|
-
constructor({
|
314740
|
-
url = defaultPaymentServiceURL,
|
314741
|
-
retryConfig,
|
314742
|
-
logger: logger15 = TurboWinstonLogger.default,
|
314743
|
-
token = "arweave"
|
314744
|
-
}) {
|
314745
|
-
this.logger = logger15;
|
314746
|
-
this.httpService = new TurboHTTPService({
|
314747
|
-
url: `${url}/v1`,
|
314748
|
-
retryConfig,
|
314749
|
-
logger: this.logger
|
314750
|
-
});
|
314751
|
-
this.token = token;
|
314752
|
-
}
|
314753
|
-
async getBalance(address) {
|
314754
|
-
const balance = await this.httpService.get({
|
314755
|
-
endpoint: `/account/balance/${this.token}?address=${address}`,
|
314756
|
-
allowedStatuses: [200, 404]
|
314757
|
-
});
|
314758
|
-
return balance.winc ? balance : {
|
314759
|
-
winc: "0",
|
314760
|
-
controlledWinc: "0",
|
314761
|
-
effectiveBalance: "0",
|
314762
|
-
givenApprovals: [],
|
314763
|
-
receivedApprovals: []
|
314764
|
-
};
|
314765
|
-
}
|
314766
|
-
getFiatRates() {
|
314767
|
-
return this.httpService.get({
|
314768
|
-
endpoint: "/rates"
|
314769
|
-
});
|
314770
|
-
}
|
314771
|
-
getFiatToAR({
|
314772
|
-
currency
|
314773
|
-
}) {
|
314774
|
-
return this.httpService.get({
|
314775
|
-
endpoint: `/rates/${currency}`
|
314776
|
-
});
|
314777
|
-
}
|
314778
|
-
getSupportedCountries() {
|
314779
|
-
return this.httpService.get({
|
314780
|
-
endpoint: "/countries"
|
314781
|
-
});
|
314782
|
-
}
|
314783
|
-
getSupportedCurrencies() {
|
314784
|
-
return this.httpService.get({
|
314785
|
-
endpoint: "/currencies"
|
314786
|
-
});
|
314787
|
-
}
|
314788
|
-
async getUploadCosts({
|
314789
|
-
bytes: bytes4
|
314790
|
-
}) {
|
314791
|
-
const fetchPricePromises = bytes4.map(
|
314792
|
-
(byteCount) => this.httpService.get({
|
314793
|
-
endpoint: `/price/bytes/${byteCount}`
|
314794
|
-
})
|
314795
|
-
);
|
314796
|
-
const wincCostsForBytes = await Promise.all(fetchPricePromises);
|
314797
|
-
return wincCostsForBytes;
|
314798
|
-
}
|
314799
|
-
getWincForFiat({
|
314800
|
-
amount,
|
314801
|
-
promoCodes = [],
|
314802
|
-
nativeAddress = "placeholder"
|
314803
|
-
// For price checks we only check promo code eligibility, a placeholder can be used
|
314804
|
-
}) {
|
314805
|
-
return this.httpService.get({
|
314806
|
-
endpoint: `/price/${amount.type}/${amount.amount}?destinationAddress=${nativeAddress}&${this.appendPromoCodesToQuery(
|
314807
|
-
promoCodes
|
314808
|
-
)}`
|
314809
|
-
});
|
314810
|
-
}
|
314811
|
-
async getWincForToken({
|
314812
|
-
tokenAmount
|
314813
|
-
}) {
|
314814
|
-
const { actualPaymentAmount, fees, winc } = await this.httpService.get({
|
314815
|
-
endpoint: `/price/${this.token}/${tokenAmount}`
|
314816
|
-
});
|
314817
|
-
return {
|
314818
|
-
winc,
|
314819
|
-
fees,
|
314820
|
-
actualTokenAmount: tokenAmount.toString(),
|
314821
|
-
equivalentWincTokenAmount: actualPaymentAmount.toString()
|
314822
|
-
};
|
314823
|
-
}
|
314824
|
-
appendPromoCodesToQuery(promoCodes) {
|
314825
|
-
const promoCodesQuery = promoCodes.join(",");
|
314826
|
-
return promoCodesQuery ? `promoCode=${promoCodesQuery}` : "";
|
314827
|
-
}
|
314828
|
-
async getTurboCryptoWallets() {
|
314829
|
-
const { addresses } = await this.httpService.get({
|
314830
|
-
endpoint: "/info"
|
314831
|
-
});
|
314832
|
-
return addresses;
|
314833
|
-
}
|
314834
|
-
async getCheckout({
|
314835
|
-
amount,
|
314836
|
-
owner,
|
314837
|
-
promoCodes = [],
|
314838
|
-
uiMode = "hosted"
|
314839
|
-
}, headers) {
|
314840
|
-
const { amount: paymentAmount, type: currencyType } = amount;
|
314841
|
-
const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}?uiMode=${uiMode}${promoCodes.length > 0 ? `&${this.appendPromoCodesToQuery(promoCodes)}` : ""}&token=${this.token}`;
|
314842
|
-
const { adjustments, paymentSession, topUpQuote, fees } = await this.httpService.get({
|
314843
|
-
endpoint,
|
314844
|
-
headers
|
314845
|
-
});
|
314846
|
-
return {
|
314847
|
-
winc: topUpQuote.winstonCreditAmount,
|
314848
|
-
adjustments,
|
314849
|
-
fees,
|
314850
|
-
url: paymentSession.url ?? void 0,
|
314851
|
-
id: paymentSession.id,
|
314852
|
-
client_secret: paymentSession.client_secret ?? void 0,
|
314853
|
-
/** @deprecated -- backfilled for backwards compatibility, use actualPaymentAmount */
|
314854
|
-
paymentAmount: topUpQuote.paymentAmount,
|
314855
|
-
actualPaymentAmount: topUpQuote.paymentAmount,
|
314856
|
-
quotedPaymentAmount: topUpQuote.quotedPaymentAmount
|
314857
|
-
};
|
314858
|
-
}
|
314859
|
-
createCheckoutSession(params) {
|
314860
|
-
return this.getCheckout(params);
|
314861
|
-
}
|
314862
|
-
async submitFundTransaction({
|
314863
|
-
txId
|
314864
|
-
}) {
|
314865
|
-
const response = await this.httpService.post({
|
314866
|
-
endpoint: `/account/balance/${this.token}`,
|
314867
|
-
data: Buffer.from(JSON.stringify({ tx_id: txId }))
|
314868
|
-
});
|
314869
|
-
if ("creditedTransaction" in response) {
|
314870
|
-
return {
|
314871
|
-
id: response.creditedTransaction.transactionId,
|
314872
|
-
quantity: response.creditedTransaction.transactionQuantity,
|
314873
|
-
owner: response.creditedTransaction.destinationAddress,
|
314874
|
-
winc: response.creditedTransaction.winstonCreditAmount,
|
314875
|
-
token: response.creditedTransaction.tokenType,
|
314876
|
-
status: "confirmed",
|
314877
|
-
block: response.creditedTransaction.blockHeight
|
314878
|
-
};
|
314879
|
-
} else if ("pendingTransaction" in response) {
|
314880
|
-
return {
|
314881
|
-
id: response.pendingTransaction.transactionId,
|
314882
|
-
quantity: response.pendingTransaction.transactionQuantity,
|
314883
|
-
owner: response.pendingTransaction.destinationAddress,
|
314884
|
-
winc: response.pendingTransaction.winstonCreditAmount,
|
314885
|
-
token: response.pendingTransaction.tokenType,
|
314886
|
-
status: "pending"
|
314887
|
-
};
|
314888
|
-
} else if ("failedTransaction" in response) {
|
314889
|
-
return {
|
314890
|
-
id: response.failedTransaction.transactionId,
|
314891
|
-
quantity: response.failedTransaction.transactionQuantity,
|
314892
|
-
owner: response.failedTransaction.destinationAddress,
|
314893
|
-
winc: response.failedTransaction.winstonCreditAmount,
|
314894
|
-
token: response.failedTransaction.tokenType,
|
314895
|
-
status: "failed"
|
314896
|
-
};
|
314897
|
-
}
|
314898
|
-
throw new Error("Unknown response from payment service: " + response);
|
314899
|
-
}
|
314900
|
-
async getCreditShareApprovals({
|
314901
|
-
userAddress
|
314902
|
-
}) {
|
314903
|
-
const response = await this.httpService.get({
|
314904
|
-
endpoint: `/account/approvals/get?userAddress=${userAddress}`,
|
314905
|
-
allowedStatuses: [200, 404]
|
314906
|
-
});
|
314907
|
-
if (response?.givenApprovals === void 0 && response?.receivedApprovals === void 0) {
|
314908
|
-
return {
|
314909
|
-
givenApprovals: [],
|
314910
|
-
receivedApprovals: []
|
314911
|
-
};
|
314912
|
-
}
|
314913
|
-
return response;
|
314914
|
-
}
|
314915
|
-
};
|
314916
|
-
var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPaymentService {
|
314917
|
-
constructor({
|
314918
|
-
url = defaultPaymentServiceURL,
|
314919
|
-
retryConfig,
|
314920
|
-
signer,
|
314921
|
-
logger: logger15 = TurboWinstonLogger.default,
|
314922
|
-
token = "arweave",
|
314923
|
-
tokenTools
|
314924
|
-
}) {
|
314925
|
-
super({ url, retryConfig, logger: logger15, token });
|
314926
|
-
this.signer = signer;
|
314927
|
-
this.tokenTools = tokenTools;
|
314928
|
-
}
|
314929
|
-
async getBalance(userAddress) {
|
314930
|
-
userAddress ??= await this.signer.getNativeAddress();
|
314931
|
-
return super.getBalance(userAddress);
|
314932
|
-
}
|
314933
|
-
async getCreditShareApprovals({
|
314934
|
-
userAddress
|
314935
|
-
}) {
|
314936
|
-
userAddress ??= await this.signer.getNativeAddress();
|
314937
|
-
return super.getCreditShareApprovals({ userAddress });
|
314938
|
-
}
|
314939
|
-
async getWincForFiat({
|
314940
|
-
amount,
|
314941
|
-
promoCodes = []
|
314942
|
-
}) {
|
314943
|
-
return super.getWincForFiat({
|
314944
|
-
amount,
|
314945
|
-
promoCodes,
|
314946
|
-
nativeAddress: await this.signer.getNativeAddress()
|
314947
|
-
});
|
314948
|
-
}
|
314949
|
-
async createCheckoutSession(params) {
|
314950
|
-
return this.getCheckout(params);
|
314951
|
-
}
|
314952
|
-
async getTargetWalletForFund() {
|
314953
|
-
const { addresses } = await this.httpService.get({
|
314954
|
-
endpoint: "/info"
|
314955
|
-
});
|
314956
|
-
const walletAddress = addresses[this.token];
|
314957
|
-
if (!walletAddress) {
|
314958
|
-
throw new Error(`No wallet address found for token type: ${this.token}`);
|
314959
|
-
}
|
314960
|
-
return walletAddress;
|
314961
|
-
}
|
314962
|
-
async topUpWithTokens({
|
314963
|
-
feeMultiplier = 1,
|
314964
|
-
tokenAmount: tokenAmountV
|
314965
|
-
}) {
|
314966
|
-
if (!this.tokenTools) {
|
314967
|
-
throw new Error(`Token type not supported for crypto fund ${this.token}`);
|
314968
|
-
}
|
314969
|
-
const tokenAmount = new BigNumber5(tokenAmountV);
|
314970
|
-
const target = await this.getTargetWalletForFund();
|
314971
|
-
this.logger.debug("Funding account...", {
|
314972
|
-
feeMultiplier,
|
314973
|
-
tokenAmount,
|
314974
|
-
target
|
314975
|
-
});
|
314976
|
-
const fundTx = await this.tokenTools.createAndSubmitTx({
|
314977
|
-
target,
|
314978
|
-
tokenAmount,
|
314979
|
-
feeMultiplier,
|
314980
|
-
signer: this.signer
|
314981
|
-
});
|
314982
|
-
const txId = fundTx.id;
|
314983
|
-
try {
|
314984
|
-
await this.tokenTools.pollForTxBeingAvailable({ txId });
|
314985
|
-
} catch (e12) {
|
314986
|
-
this.logger.error(
|
314987
|
-
`Failed to poll for transaction being available from ${this.token} gateway... Attempting to submit fund tx to Turbo...`,
|
314988
|
-
e12
|
314989
|
-
);
|
314990
|
-
}
|
314991
|
-
try {
|
314992
|
-
return {
|
314993
|
-
...await this.submitFundTransaction({ txId }),
|
314994
|
-
target: fundTx.target,
|
314995
|
-
reward: fundTx.reward
|
314996
|
-
};
|
314997
|
-
} catch (e12) {
|
314998
|
-
this.logger.debug("Failed to submit fund transaction...", e12);
|
314999
|
-
throw Error(
|
315000
|
-
`Failed to submit fund transaction! Save this Transaction ID and try again with 'turbo.submitFundTransaction(id)': ${txId}`
|
315001
|
-
);
|
315002
|
-
}
|
315003
|
-
}
|
315004
|
-
};
|
315005
|
-
|
315006
314735
|
// src/common/token/index.ts
|
315007
314736
|
init_dirname();
|
315008
314737
|
init_buffer2();
|
@@ -315031,10 +314760,10 @@ function fromB64Url(input) {
|
|
315031
314760
|
return Buffer.from(base64, "base64");
|
315032
314761
|
}
|
315033
314762
|
function toB64Url(buffer2) {
|
315034
|
-
return (0, import_utils28.bufferTob64Url)(buffer2);
|
314763
|
+
return (0, import_utils28.bufferTob64Url)(Uint8Array.from(buffer2));
|
315035
314764
|
}
|
315036
314765
|
function sha256B64Url(input) {
|
315037
|
-
return toB64Url(createHash("sha256").update(input).digest());
|
314766
|
+
return toB64Url(createHash("sha256").update(Uint8Array.from(input)).digest());
|
315038
314767
|
}
|
315039
314768
|
|
315040
314769
|
// src/utils/common.ts
|
@@ -315062,6 +314791,7 @@ function createTurboSigner({
|
|
315062
314791
|
case "solana":
|
315063
314792
|
return new HexSolanaSigner2(clientProvidedPrivateKey);
|
315064
314793
|
case "ethereum":
|
314794
|
+
case "pol":
|
315065
314795
|
case "matic":
|
315066
314796
|
if (!isEthPrivateKey(clientProvidedPrivateKey)) {
|
315067
314797
|
throw new Error(
|
@@ -349510,6 +349240,14 @@ var defaultTokenMap = {
|
|
349510
349240
|
matic: (config2) => new PolygonToken(config2),
|
349511
349241
|
pol: (config2) => new PolygonToken(config2)
|
349512
349242
|
};
|
349243
|
+
var exponentMap = {
|
349244
|
+
arweave: 12,
|
349245
|
+
solana: 9,
|
349246
|
+
ethereum: 18,
|
349247
|
+
kyve: 6,
|
349248
|
+
matic: 18,
|
349249
|
+
pol: 18
|
349250
|
+
};
|
349513
349251
|
var tokenToBaseMap = {
|
349514
349252
|
arweave: (a8) => ARToTokenAmount(a8),
|
349515
349253
|
solana: (a8) => SOLToTokenAmount(a8),
|
@@ -349522,6 +349260,292 @@ function isTokenType(token) {
|
|
349522
349260
|
return tokenTypes.includes(token);
|
349523
349261
|
}
|
349524
349262
|
|
349263
|
+
// src/common/payment.ts
|
349264
|
+
var developmentPaymentServiceURL = "https://payment.ardrive.dev";
|
349265
|
+
var defaultPaymentServiceURL = "https://payment.ardrive.io";
|
349266
|
+
var TurboUnauthenticatedPaymentService = class {
|
349267
|
+
constructor({
|
349268
|
+
url = defaultPaymentServiceURL,
|
349269
|
+
retryConfig,
|
349270
|
+
logger: logger15 = TurboWinstonLogger.default,
|
349271
|
+
token = "arweave"
|
349272
|
+
}) {
|
349273
|
+
this.logger = logger15;
|
349274
|
+
this.httpService = new TurboHTTPService({
|
349275
|
+
url: `${url}/v1`,
|
349276
|
+
retryConfig,
|
349277
|
+
logger: this.logger
|
349278
|
+
});
|
349279
|
+
this.token = token;
|
349280
|
+
}
|
349281
|
+
async getBalance(address) {
|
349282
|
+
const balance = await this.httpService.get({
|
349283
|
+
endpoint: `/account/balance/${this.token}?address=${address}`,
|
349284
|
+
allowedStatuses: [200, 404]
|
349285
|
+
});
|
349286
|
+
return balance.winc ? balance : {
|
349287
|
+
winc: "0",
|
349288
|
+
controlledWinc: "0",
|
349289
|
+
effectiveBalance: "0",
|
349290
|
+
givenApprovals: [],
|
349291
|
+
receivedApprovals: []
|
349292
|
+
};
|
349293
|
+
}
|
349294
|
+
getFiatRates() {
|
349295
|
+
return this.httpService.get({
|
349296
|
+
endpoint: "/rates"
|
349297
|
+
});
|
349298
|
+
}
|
349299
|
+
getFiatToAR({
|
349300
|
+
currency
|
349301
|
+
}) {
|
349302
|
+
return this.httpService.get({
|
349303
|
+
endpoint: `/rates/${currency}`
|
349304
|
+
});
|
349305
|
+
}
|
349306
|
+
getSupportedCountries() {
|
349307
|
+
return this.httpService.get({
|
349308
|
+
endpoint: "/countries"
|
349309
|
+
});
|
349310
|
+
}
|
349311
|
+
getSupportedCurrencies() {
|
349312
|
+
return this.httpService.get({
|
349313
|
+
endpoint: "/currencies"
|
349314
|
+
});
|
349315
|
+
}
|
349316
|
+
async getUploadCosts({
|
349317
|
+
bytes: bytes4
|
349318
|
+
}) {
|
349319
|
+
const fetchPricePromises = bytes4.map(
|
349320
|
+
(byteCount) => this.httpService.get({
|
349321
|
+
endpoint: `/price/bytes/${byteCount}`
|
349322
|
+
})
|
349323
|
+
);
|
349324
|
+
const wincCostsForBytes = await Promise.all(fetchPricePromises);
|
349325
|
+
return wincCostsForBytes;
|
349326
|
+
}
|
349327
|
+
getWincForFiat({
|
349328
|
+
amount,
|
349329
|
+
promoCodes = [],
|
349330
|
+
nativeAddress = "placeholder"
|
349331
|
+
// For price checks we only check promo code eligibility, a placeholder can be used
|
349332
|
+
}) {
|
349333
|
+
return this.httpService.get({
|
349334
|
+
endpoint: `/price/${amount.type}/${amount.amount}?destinationAddress=${nativeAddress}&${this.appendPromoCodesToQuery(
|
349335
|
+
promoCodes
|
349336
|
+
)}`
|
349337
|
+
});
|
349338
|
+
}
|
349339
|
+
async getWincForToken({
|
349340
|
+
tokenAmount
|
349341
|
+
}) {
|
349342
|
+
const { actualPaymentAmount, fees, winc } = await this.httpService.get({
|
349343
|
+
endpoint: `/price/${this.token}/${tokenAmount}`
|
349344
|
+
});
|
349345
|
+
return {
|
349346
|
+
winc,
|
349347
|
+
fees,
|
349348
|
+
actualTokenAmount: tokenAmount.toString(),
|
349349
|
+
equivalentWincTokenAmount: actualPaymentAmount.toString()
|
349350
|
+
};
|
349351
|
+
}
|
349352
|
+
appendPromoCodesToQuery(promoCodes) {
|
349353
|
+
const promoCodesQuery = promoCodes.join(",");
|
349354
|
+
return promoCodesQuery ? `promoCode=${promoCodesQuery}` : "";
|
349355
|
+
}
|
349356
|
+
async getTurboCryptoWallets() {
|
349357
|
+
const { addresses } = await this.httpService.get({
|
349358
|
+
endpoint: "/info"
|
349359
|
+
});
|
349360
|
+
return addresses;
|
349361
|
+
}
|
349362
|
+
async getCheckout({
|
349363
|
+
amount,
|
349364
|
+
owner,
|
349365
|
+
promoCodes = [],
|
349366
|
+
uiMode = "hosted"
|
349367
|
+
}, headers) {
|
349368
|
+
const { amount: paymentAmount, type: currencyType } = amount;
|
349369
|
+
const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}?uiMode=${uiMode}${promoCodes.length > 0 ? `&${this.appendPromoCodesToQuery(promoCodes)}` : ""}&token=${this.token}`;
|
349370
|
+
const { adjustments, paymentSession, topUpQuote, fees } = await this.httpService.get({
|
349371
|
+
endpoint,
|
349372
|
+
headers
|
349373
|
+
});
|
349374
|
+
return {
|
349375
|
+
winc: topUpQuote.winstonCreditAmount,
|
349376
|
+
adjustments,
|
349377
|
+
fees,
|
349378
|
+
url: paymentSession.url ?? void 0,
|
349379
|
+
id: paymentSession.id,
|
349380
|
+
client_secret: paymentSession.client_secret ?? void 0,
|
349381
|
+
/** @deprecated -- backfilled for backwards compatibility, use actualPaymentAmount */
|
349382
|
+
paymentAmount: topUpQuote.paymentAmount,
|
349383
|
+
actualPaymentAmount: topUpQuote.paymentAmount,
|
349384
|
+
quotedPaymentAmount: topUpQuote.quotedPaymentAmount
|
349385
|
+
};
|
349386
|
+
}
|
349387
|
+
createCheckoutSession(params) {
|
349388
|
+
return this.getCheckout(params);
|
349389
|
+
}
|
349390
|
+
async submitFundTransaction({
|
349391
|
+
txId
|
349392
|
+
}) {
|
349393
|
+
const response = await this.httpService.post({
|
349394
|
+
endpoint: `/account/balance/${this.token}`,
|
349395
|
+
data: Buffer.from(JSON.stringify({ tx_id: txId }))
|
349396
|
+
});
|
349397
|
+
if ("creditedTransaction" in response) {
|
349398
|
+
return {
|
349399
|
+
id: response.creditedTransaction.transactionId,
|
349400
|
+
quantity: response.creditedTransaction.transactionQuantity,
|
349401
|
+
owner: response.creditedTransaction.destinationAddress,
|
349402
|
+
winc: response.creditedTransaction.winstonCreditAmount,
|
349403
|
+
token: response.creditedTransaction.tokenType,
|
349404
|
+
status: "confirmed",
|
349405
|
+
block: response.creditedTransaction.blockHeight
|
349406
|
+
};
|
349407
|
+
} else if ("pendingTransaction" in response) {
|
349408
|
+
return {
|
349409
|
+
id: response.pendingTransaction.transactionId,
|
349410
|
+
quantity: response.pendingTransaction.transactionQuantity,
|
349411
|
+
owner: response.pendingTransaction.destinationAddress,
|
349412
|
+
winc: response.pendingTransaction.winstonCreditAmount,
|
349413
|
+
token: response.pendingTransaction.tokenType,
|
349414
|
+
status: "pending"
|
349415
|
+
};
|
349416
|
+
} else if ("failedTransaction" in response) {
|
349417
|
+
return {
|
349418
|
+
id: response.failedTransaction.transactionId,
|
349419
|
+
quantity: response.failedTransaction.transactionQuantity,
|
349420
|
+
owner: response.failedTransaction.destinationAddress,
|
349421
|
+
winc: response.failedTransaction.winstonCreditAmount,
|
349422
|
+
token: response.failedTransaction.tokenType,
|
349423
|
+
status: "failed"
|
349424
|
+
};
|
349425
|
+
}
|
349426
|
+
throw new Error("Unknown response from payment service: " + response);
|
349427
|
+
}
|
349428
|
+
async getCreditShareApprovals({
|
349429
|
+
userAddress
|
349430
|
+
}) {
|
349431
|
+
const response = await this.httpService.get({
|
349432
|
+
endpoint: `/account/approvals/get?userAddress=${userAddress}`,
|
349433
|
+
allowedStatuses: [200, 404]
|
349434
|
+
});
|
349435
|
+
if (response?.givenApprovals === void 0 && response?.receivedApprovals === void 0) {
|
349436
|
+
return {
|
349437
|
+
givenApprovals: [],
|
349438
|
+
receivedApprovals: []
|
349439
|
+
};
|
349440
|
+
}
|
349441
|
+
return response;
|
349442
|
+
}
|
349443
|
+
async getTokenPriceForBytes({
|
349444
|
+
byteCount
|
349445
|
+
}) {
|
349446
|
+
const wincPriceForOneToken = (await this.getWincForToken({
|
349447
|
+
tokenAmount: tokenToBaseMap[this.token](1)
|
349448
|
+
})).winc;
|
349449
|
+
const wincPriceForOneGiB = (await this.getUploadCosts({
|
349450
|
+
bytes: [2 ** 30]
|
349451
|
+
}))[0].winc;
|
349452
|
+
const tokenPriceForOneGiB = new BigNumber5(wincPriceForOneGiB).dividedBy(
|
349453
|
+
wincPriceForOneToken
|
349454
|
+
);
|
349455
|
+
const tokenPriceForBytes = tokenPriceForOneGiB.dividedBy(2 ** 30).times(byteCount).toFixed(exponentMap[this.token]);
|
349456
|
+
return { byteCount, tokenPrice: tokenPriceForBytes, token: this.token };
|
349457
|
+
}
|
349458
|
+
};
|
349459
|
+
var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPaymentService {
|
349460
|
+
constructor({
|
349461
|
+
url = defaultPaymentServiceURL,
|
349462
|
+
retryConfig,
|
349463
|
+
signer,
|
349464
|
+
logger: logger15 = TurboWinstonLogger.default,
|
349465
|
+
token = "arweave",
|
349466
|
+
tokenTools
|
349467
|
+
}) {
|
349468
|
+
super({ url, retryConfig, logger: logger15, token });
|
349469
|
+
this.signer = signer;
|
349470
|
+
this.tokenTools = tokenTools;
|
349471
|
+
}
|
349472
|
+
async getBalance(userAddress) {
|
349473
|
+
userAddress ??= await this.signer.getNativeAddress();
|
349474
|
+
return super.getBalance(userAddress);
|
349475
|
+
}
|
349476
|
+
async getCreditShareApprovals({
|
349477
|
+
userAddress
|
349478
|
+
}) {
|
349479
|
+
userAddress ??= await this.signer.getNativeAddress();
|
349480
|
+
return super.getCreditShareApprovals({ userAddress });
|
349481
|
+
}
|
349482
|
+
async getWincForFiat({
|
349483
|
+
amount,
|
349484
|
+
promoCodes = []
|
349485
|
+
}) {
|
349486
|
+
return super.getWincForFiat({
|
349487
|
+
amount,
|
349488
|
+
promoCodes,
|
349489
|
+
nativeAddress: await this.signer.getNativeAddress()
|
349490
|
+
});
|
349491
|
+
}
|
349492
|
+
async createCheckoutSession(params) {
|
349493
|
+
return this.getCheckout(params);
|
349494
|
+
}
|
349495
|
+
async getTargetWalletForFund() {
|
349496
|
+
const { addresses } = await this.httpService.get({
|
349497
|
+
endpoint: "/info"
|
349498
|
+
});
|
349499
|
+
const walletAddress = addresses[this.token];
|
349500
|
+
if (!walletAddress) {
|
349501
|
+
throw new Error(`No wallet address found for token type: ${this.token}`);
|
349502
|
+
}
|
349503
|
+
return walletAddress;
|
349504
|
+
}
|
349505
|
+
async topUpWithTokens({
|
349506
|
+
feeMultiplier = 1,
|
349507
|
+
tokenAmount: tokenAmountV
|
349508
|
+
}) {
|
349509
|
+
if (!this.tokenTools) {
|
349510
|
+
throw new Error(`Token type not supported for crypto fund ${this.token}`);
|
349511
|
+
}
|
349512
|
+
const tokenAmount = new BigNumber5(tokenAmountV);
|
349513
|
+
const target = await this.getTargetWalletForFund();
|
349514
|
+
this.logger.debug("Funding account...", {
|
349515
|
+
feeMultiplier,
|
349516
|
+
tokenAmount,
|
349517
|
+
target
|
349518
|
+
});
|
349519
|
+
const fundTx = await this.tokenTools.createAndSubmitTx({
|
349520
|
+
target,
|
349521
|
+
tokenAmount,
|
349522
|
+
feeMultiplier,
|
349523
|
+
signer: this.signer
|
349524
|
+
});
|
349525
|
+
const txId = fundTx.id;
|
349526
|
+
try {
|
349527
|
+
await this.tokenTools.pollForTxBeingAvailable({ txId });
|
349528
|
+
} catch (e12) {
|
349529
|
+
this.logger.error(
|
349530
|
+
`Failed to poll for transaction being available from ${this.token} gateway... Attempting to submit fund tx to Turbo...`,
|
349531
|
+
e12
|
349532
|
+
);
|
349533
|
+
}
|
349534
|
+
try {
|
349535
|
+
return {
|
349536
|
+
...await this.submitFundTransaction({ txId }),
|
349537
|
+
target: fundTx.target,
|
349538
|
+
reward: fundTx.reward
|
349539
|
+
};
|
349540
|
+
} catch (e12) {
|
349541
|
+
this.logger.debug("Failed to submit fund transaction...", e12);
|
349542
|
+
throw Error(
|
349543
|
+
`Failed to submit fund transaction! Save this Transaction ID and try again with 'turbo.submitFundTransaction(id)': ${txId}`
|
349544
|
+
);
|
349545
|
+
}
|
349546
|
+
}
|
349547
|
+
};
|
349548
|
+
|
349525
349549
|
// src/common/turbo.ts
|
349526
349550
|
init_dirname();
|
349527
349551
|
init_buffer2();
|
@@ -350001,6 +350025,14 @@ var TurboUnauthenticatedClient = class {
|
|
350001
350025
|
getWincForToken(params) {
|
350002
350026
|
return this.paymentService.getWincForToken(params);
|
350003
350027
|
}
|
350028
|
+
/**
|
350029
|
+
* Determines the price in the instantiated token to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
|
350030
|
+
*/
|
350031
|
+
getTokenPriceForBytes({
|
350032
|
+
byteCount
|
350033
|
+
}) {
|
350034
|
+
return this.paymentService.getTokenPriceForBytes({ byteCount });
|
350035
|
+
}
|
350004
350036
|
/**
|
350005
350037
|
* Uploads a signed data item to the Turbo Upload Service.
|
350006
350038
|
*/
|
@@ -350264,7 +350296,7 @@ var TurboDataItemAbstractSigner = class {
|
|
350264
350296
|
ownerToNativeAddress(owner, token) {
|
350265
350297
|
switch (token) {
|
350266
350298
|
case "solana":
|
350267
|
-
return import_bs584.default.encode(fromB64Url(owner));
|
350299
|
+
return import_bs584.default.encode(Uint8Array.from(fromB64Url(owner)));
|
350268
350300
|
case "ethereum":
|
350269
350301
|
case "matic":
|
350270
350302
|
case "pol":
|
@@ -350273,7 +350305,9 @@ var TurboDataItemAbstractSigner = class {
|
|
350273
350305
|
return (0, import_amino3.pubkeyToAddress)(
|
350274
350306
|
{
|
350275
350307
|
type: "tendermint/PubKeySecp256k1",
|
350276
|
-
value: (0, import_encoding3.toBase64)(
|
350308
|
+
value: (0, import_encoding3.toBase64)(
|
350309
|
+
import_crypto32.Secp256k1.compressPubkey(Uint8Array.from(fromB64Url(owner)))
|
350310
|
+
)
|
350277
350311
|
},
|
350278
350312
|
"kyve"
|
350279
350313
|
);
|
@@ -350285,7 +350319,7 @@ var TurboDataItemAbstractSigner = class {
|
|
350285
350319
|
async generateSignedRequestHeaders() {
|
350286
350320
|
const nonce = randomBytes(16).toString("hex");
|
350287
350321
|
const buffer2 = Buffer.from(nonce);
|
350288
|
-
const signature2 = await this.signer.sign(buffer2);
|
350322
|
+
const signature2 = await this.signer.sign(Uint8Array.from(buffer2));
|
350289
350323
|
const publicKey2 = toB64Url(this.signer.publicKey);
|
350290
350324
|
return {
|
350291
350325
|
"x-public-key": publicKey2,
|
@@ -350650,6 +350684,7 @@ export {
|
|
350650
350684
|
developmentPaymentServiceURL,
|
350651
350685
|
developmentTurboConfiguration,
|
350652
350686
|
developmentUploadServiceURL,
|
350687
|
+
exponentMap,
|
350653
350688
|
fiatCurrencyTypes,
|
350654
350689
|
isCurrency,
|
350655
350690
|
isEthPrivateKey,
|
package/lib/cjs/cli/cli.js
CHANGED
@@ -24,6 +24,7 @@ const index_js_1 = require("./commands/index.js");
|
|
24
24
|
const listShares_js_1 = require("./commands/listShares.js");
|
25
25
|
const revokeCredits_js_1 = require("./commands/revokeCredits.js");
|
26
26
|
const shareCredits_js_1 = require("./commands/shareCredits.js");
|
27
|
+
const tokenPrice_js_1 = require("./commands/tokenPrice.js");
|
27
28
|
const options_js_1 = require("./options.js");
|
28
29
|
const utils_js_1 = require("./utils.js");
|
29
30
|
(0, utils_js_1.applyOptions)(commander_1.program
|
@@ -51,6 +52,11 @@ const utils_js_1 = require("./utils.js");
|
|
51
52
|
.description('Get the current Credits estimate for byte, crypto, or fiat value'), [options_js_1.optionMap.value, options_js_1.optionMap.type]).action(async (_commandOptions, command) => {
|
52
53
|
await (0, utils_js_1.runCommand)(command, index_js_1.price);
|
53
54
|
});
|
55
|
+
(0, utils_js_1.applyOptions)(commander_1.program
|
56
|
+
.command('token-price')
|
57
|
+
.description('Get the current token price for provided byte value'), [options_js_1.optionMap.byteCount]).action(async (_commandOptions, command) => {
|
58
|
+
await (0, utils_js_1.runCommand)(command, tokenPrice_js_1.tokenPrice);
|
59
|
+
});
|
54
60
|
(0, utils_js_1.applyOptions)(commander_1.program
|
55
61
|
.command('share-credits')
|
56
62
|
.description('Create a Turbo credit share approval'), options_js_1.shareCreditsOptions).action(async (_commandOptions, command) => {
|
@@ -33,7 +33,7 @@ async function shareCredits(options) {
|
|
33
33
|
const result = await turbo.shareCredits({
|
34
34
|
approvedAddress,
|
35
35
|
approvedWincAmount,
|
36
|
-
expiresBySeconds,
|
36
|
+
expiresBySeconds: expiresBySeconds !== undefined ? +expiresBySeconds : undefined,
|
37
37
|
});
|
38
38
|
console.log(JSON.stringify({ message: 'Created credit share approval!', ...result }, null, 2));
|
39
39
|
}
|