@ardrive/turbo-sdk 1.18.0 → 1.19.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.
Files changed (39) hide show
  1. package/bundles/web.bundle.min.js +954 -857
  2. package/lib/cjs/common/factory.js +92 -0
  3. package/lib/cjs/common/signer.js +17 -2
  4. package/lib/cjs/common/token/solana.js +2 -2
  5. package/lib/cjs/node/factory.js +16 -49
  6. package/lib/cjs/node/signer.js +4 -1
  7. package/lib/cjs/types.js +8 -0
  8. package/lib/cjs/version.js +1 -1
  9. package/lib/cjs/web/factory.js +16 -48
  10. package/lib/cjs/web/signer.js +10 -5
  11. package/lib/esm/common/factory.js +94 -2
  12. package/lib/esm/common/signer.js +17 -2
  13. package/lib/esm/common/token/solana.js +2 -2
  14. package/lib/esm/node/factory.js +16 -49
  15. package/lib/esm/node/signer.js +4 -1
  16. package/lib/esm/types.js +6 -0
  17. package/lib/esm/version.js +1 -1
  18. package/lib/esm/web/factory.js +16 -48
  19. package/lib/esm/web/signer.js +11 -6
  20. package/lib/types/common/factory.d.ts +9 -17
  21. package/lib/types/common/factory.d.ts.map +1 -1
  22. package/lib/types/common/http.d.ts +1 -0
  23. package/lib/types/common/http.d.ts.map +1 -1
  24. package/lib/types/common/signer.d.ts +3 -2
  25. package/lib/types/common/signer.d.ts.map +1 -1
  26. package/lib/types/node/factory.d.ts +19 -4
  27. package/lib/types/node/factory.d.ts.map +1 -1
  28. package/lib/types/node/signer.d.ts +2 -6
  29. package/lib/types/node/signer.d.ts.map +1 -1
  30. package/lib/types/node/upload.d.ts +1 -0
  31. package/lib/types/node/upload.d.ts.map +1 -1
  32. package/lib/types/types.d.ts +29 -4
  33. package/lib/types/types.d.ts.map +1 -1
  34. package/lib/types/version.d.ts +1 -1
  35. package/lib/types/web/factory.d.ts +19 -4
  36. package/lib/types/web/factory.d.ts.map +1 -1
  37. package/lib/types/web/signer.d.ts +1 -0
  38. package/lib/types/web/signer.d.ts.map +1 -1
  39. package/package.json +1 -1
@@ -303388,6 +303388,11 @@ init_dirname();
303388
303388
  init_buffer2();
303389
303389
  init_process2();
303390
303390
 
303391
+ // src/common/factory.ts
303392
+ init_dirname();
303393
+ init_buffer2();
303394
+ init_process2();
303395
+
303391
303396
  // node_modules/@dha-team/arbundles/build/web/esm/webIndex.js
303392
303397
  init_dirname();
303393
303398
  init_buffer2();
@@ -310489,10 +310494,52 @@ var streamExportForTesting = {
310489
310494
  var expObj = { ...src_exports, stream: stream_exports2 };
310490
310495
  globalThis.arbundles ??= expObj;
310491
310496
 
310492
- // src/common/factory.ts
310497
+ // src/types.ts
310493
310498
  init_dirname();
310494
310499
  init_buffer2();
310495
310500
  init_process2();
310501
+ var fiatCurrencyTypes = [
310502
+ "usd",
310503
+ "eur",
310504
+ "gbp",
310505
+ "cad",
310506
+ "aud",
310507
+ "jpy",
310508
+ "inr",
310509
+ "sgd",
310510
+ "hkd",
310511
+ "brl"
310512
+ ];
310513
+ function isCurrency(currency) {
310514
+ return fiatCurrencyTypes.includes(currency);
310515
+ }
310516
+ var tokenTypes = [
310517
+ "arweave",
310518
+ "solana",
310519
+ "ethereum",
310520
+ "kyve",
310521
+ "matic",
310522
+ "pol"
310523
+ ];
310524
+ var isNodeUploadFolderParams = (p8) => p8.folderPath !== void 0;
310525
+ var isWebUploadFolderParams = (p8) => p8.files !== void 0;
310526
+ function isKyvePrivateKey(wallet) {
310527
+ if (typeof wallet !== "string")
310528
+ return false;
310529
+ return true;
310530
+ }
310531
+ function isEthPrivateKey(wallet) {
310532
+ if (typeof wallet !== "string")
310533
+ return false;
310534
+ return wallet.startsWith("0x");
310535
+ }
310536
+ var isJWK = (wallet) => wallet.kty !== void 0;
310537
+ function isSolanaWalletAdapter(walletAdapter) {
310538
+ return "publicKey" in walletAdapter && "signMessage" in walletAdapter;
310539
+ }
310540
+ function isEthereumWalletAdapter(walletAdapter) {
310541
+ return "getSigner" in walletAdapter;
310542
+ }
310496
310543
 
310497
310544
  // src/common/logger.ts
310498
310545
  init_dirname();
@@ -310504,7 +310551,7 @@ var import_winston = __toESM(require_winston(), 1);
310504
310551
  init_dirname();
310505
310552
  init_buffer2();
310506
310553
  init_process2();
310507
- var version16 = "1.18.0-alpha.1";
310554
+ var version16 = "1.18.1-alpha.1";
310508
310555
 
310509
310556
  // src/common/logger.ts
310510
310557
  var TurboWinstonLogger = class _TurboWinstonLogger {
@@ -314929,844 +314976,213 @@ var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPayment
314929
314976
  }
314930
314977
  };
314931
314978
 
314932
- // src/common/turbo.ts
314979
+ // src/common/token/index.ts
314933
314980
  init_dirname();
314934
314981
  init_buffer2();
314935
314982
  init_process2();
314936
314983
 
314937
- // src/common/upload.ts
314984
+ // src/common/token/arweave.ts
314938
314985
  init_dirname();
314939
314986
  init_buffer2();
314940
314987
  init_process2();
314988
+ var import_arweave = __toESM(require_web(), 1);
314941
314989
  init_buffer();
314942
314990
 
314943
- // node_modules/plimit-lit/dist/index.js
314991
+ // src/utils/base64.ts
314944
314992
  init_dirname();
314945
314993
  init_buffer2();
314946
314994
  init_process2();
314947
- var __defProp2 = Object.defineProperty;
314948
- var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp2(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
314949
- var __publicField = (obj, key2, value) => {
314950
- __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
314951
- return value;
314952
- };
314953
- var Node = class {
314954
- constructor(value) {
314955
- __publicField(this, "value");
314956
- __publicField(this, "next");
314957
- this.value = value;
314958
- }
314959
- };
314960
- var Queue = class {
314961
- constructor() {
314962
- __publicField(this, "head");
314963
- __publicField(this, "tail");
314964
- __publicField(this, "_size", 0);
314965
- this.clear();
314966
- }
314967
- /**
314968
- * Removes all elements from the queue.
314969
- */
314970
- clear() {
314971
- this.head = void 0;
314972
- this.tail = void 0;
314973
- this._size = 0;
314974
- }
314975
- /**
314976
- * Adds a new element to the queue.
314977
- */
314978
- push(value) {
314979
- const node = new Node(value);
314980
- if (this.head && this.tail) {
314981
- this.tail.next = node;
314982
- this.tail = node;
314983
- } else {
314984
- this.head = node;
314985
- this.tail = node;
314986
- }
314987
- this._size++;
314988
- return this._size;
314989
- }
314990
- /**
314991
- * Removes and returns the first element in the queue.
314992
- */
314993
- pop() {
314994
- if (!this.head)
314995
- return;
314996
- const current = this.head;
314997
- this.head = this.head.next;
314998
- this._size--;
314999
- return current.value;
315000
- }
315001
- /**
315002
- * Returns the number of elements in the queue.
315003
- */
315004
- get size() {
315005
- return this._size;
315006
- }
315007
- *[Symbol.iterator]() {
315008
- let current = this.head;
315009
- while (current) {
315010
- yield current.value;
315011
- current = current.next;
315012
- }
314995
+ var import_utils28 = __toESM(require_utils5(), 1);
314996
+ init_crypto();
314997
+ init_buffer();
314998
+ function ownerToAddress(owner) {
314999
+ return sha256B64Url(fromB64Url(owner));
315000
+ }
315001
+ function fromB64Url(input) {
315002
+ const paddingLength = input.length % 4 === 0 ? 0 : 4 - input.length % 4;
315003
+ const base64 = input.replace(/-/g, "+").replace(/_/g, "/").concat("=".repeat(paddingLength));
315004
+ return Buffer.from(base64, "base64");
315005
+ }
315006
+ function toB64Url(buffer2) {
315007
+ return (0, import_utils28.bufferTob64Url)(buffer2);
315008
+ }
315009
+ function sha256B64Url(input) {
315010
+ return toB64Url(createHash("sha256").update(input).digest());
315011
+ }
315012
+
315013
+ // src/utils/common.ts
315014
+ init_dirname();
315015
+ init_buffer2();
315016
+ init_process2();
315017
+ var import_amino = __toESM(require_build5(), 1);
315018
+ var import_crypto7 = __toESM(require_build4(), 1);
315019
+ var import_encoding = __toESM(require_build(), 1);
315020
+ function sleep(ms) {
315021
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
315022
+ }
315023
+ function createTurboSigner({
315024
+ signer: clientProvidedSigner,
315025
+ privateKey: clientProvidedPrivateKey,
315026
+ token = "arweave"
315027
+ }) {
315028
+ if (clientProvidedSigner !== void 0) {
315029
+ return clientProvidedSigner;
315013
315030
  }
315014
- };
315015
- function pLimit(concurrency) {
315016
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
315017
- throw new TypeError("Expected `concurrency` to be a number greater than 1");
315031
+ if (clientProvidedPrivateKey === void 0) {
315032
+ throw new Error("A privateKey or signer must be provided.");
315018
315033
  }
315019
- const queue2 = new Queue();
315020
- let activeCount = 0;
315021
- const next = () => {
315022
- activeCount--;
315023
- if (queue2.size > 0) {
315024
- queue2.pop()();
315025
- }
315026
- };
315027
- const run2 = async (fn, resolve3, args) => {
315028
- activeCount++;
315029
- const result = (async () => fn(...args))();
315030
- resolve3(result);
315031
- try {
315032
- await result;
315033
- } catch {
315034
- }
315035
- next();
315036
- };
315037
- const enqueue = (fn, resolve3, args) => {
315038
- queue2.push(run2.bind(null, fn, resolve3, args));
315039
- (async () => {
315040
- await Promise.resolve();
315041
- if (activeCount < concurrency && queue2.size > 0) {
315042
- queue2.pop()();
315034
+ switch (token) {
315035
+ case "solana":
315036
+ return new HexSolanaSigner2(clientProvidedPrivateKey);
315037
+ case "ethereum":
315038
+ case "matic":
315039
+ if (!isEthPrivateKey(clientProvidedPrivateKey)) {
315040
+ throw new Error(
315041
+ "A valid Ethereum private key must be provided for EthereumSigner."
315042
+ );
315043
315043
  }
315044
- })();
315045
- };
315046
- const generator = (fn, ...args) => new Promise((resolve3) => {
315047
- enqueue(fn, resolve3, args);
315048
- });
315049
- Object.defineProperties(generator, {
315050
- activeCount: {
315051
- get: () => activeCount
315052
- },
315053
- pendingCount: {
315054
- get: () => queue2.size
315055
- },
315056
- clearQueue: {
315057
- value: () => {
315058
- queue2.clear();
315044
+ return new EthereumSigner(clientProvidedPrivateKey);
315045
+ case "kyve":
315046
+ if (!isKyvePrivateKey(clientProvidedPrivateKey)) {
315047
+ throw new Error(
315048
+ "A valid Kyve private key must be provided for KyveSigner."
315049
+ );
315059
315050
  }
315060
- }
315061
- });
315062
- return generator;
315051
+ return signerFromKyvePrivateKey(clientProvidedPrivateKey);
315052
+ default:
315053
+ if (!isJWK(clientProvidedPrivateKey)) {
315054
+ throw new Error("A JWK must be provided for ArweaveSigner.");
315055
+ }
315056
+ return new ArweaveSigner(clientProvidedPrivateKey);
315057
+ }
315058
+ }
315059
+ function signerFromKyvePrivateKey(privateKey) {
315060
+ return new EthereumSigner(privateKey);
315063
315061
  }
315064
315062
 
315065
- // src/common/upload.ts
315066
- var developmentUploadServiceURL = "https://upload.ardrive.dev";
315067
- var defaultUploadServiceURL = "https://upload.ardrive.io";
315068
- var TurboUnauthenticatedUploadService = class {
315063
+ // src/common/token/arweave.ts
315064
+ var ArweaveToken = class {
315069
315065
  constructor({
315070
- url = defaultUploadServiceURL,
315071
- retryConfig,
315066
+ gatewayUrl = "https://arweave.net",
315067
+ arweave,
315072
315068
  logger: logger15 = TurboWinstonLogger.default,
315073
- token = "arweave"
315074
- }) {
315075
- this.token = token;
315076
- this.logger = logger15;
315077
- this.httpService = new TurboHTTPService({
315078
- url: `${url}/v1`,
315079
- retryConfig,
315080
- logger: this.logger
315081
- });
315082
- }
315083
- async uploadSignedDataItem({
315084
- dataItemStreamFactory,
315085
- dataItemSizeFactory,
315086
- signal
315087
- }) {
315088
- const fileSize = dataItemSizeFactory();
315089
- this.logger.debug("Uploading signed data item...");
315090
- return this.httpService.post({
315091
- endpoint: `/tx/${this.token}`,
315092
- signal,
315093
- data: dataItemStreamFactory(),
315094
- headers: {
315095
- "content-type": "application/octet-stream",
315096
- "content-length": `${fileSize}`
315097
- }
315069
+ mintU = true,
315070
+ pollingOptions = {
315071
+ maxAttempts: 10,
315072
+ pollingIntervalMs: 3e3,
315073
+ initialBackoffMs: 7e3
315074
+ }
315075
+ } = {}) {
315076
+ const url = new URL(gatewayUrl);
315077
+ this.arweave = arweave ?? import_arweave.default.init({
315078
+ host: url.hostname,
315079
+ port: url.port,
315080
+ protocol: url.protocol.replace(":", "")
315098
315081
  });
315082
+ this.logger = logger15;
315083
+ this.mintU = mintU;
315084
+ this.pollingOptions = pollingOptions;
315099
315085
  }
315100
- };
315101
- var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUploadService {
315102
- constructor({
315103
- url = defaultUploadServiceURL,
315104
- retryConfig,
315105
- signer,
315106
- logger: logger15,
315107
- token
315108
- }) {
315109
- super({ url, retryConfig, logger: logger15, token });
315110
- this.signer = signer;
315111
- }
315112
- async uploadFile({
315113
- fileStreamFactory,
315114
- fileSizeFactory,
315115
- signal,
315116
- dataItemOpts
315086
+ async createAndSubmitTx({
315087
+ feeMultiplier,
315088
+ target,
315089
+ tokenAmount,
315090
+ signer
315117
315091
  }) {
315118
- const { dataItemStreamFactory, dataItemSizeFactory } = await this.signer.signDataItem({
315119
- fileStreamFactory,
315120
- fileSizeFactory,
315121
- dataItemOpts
315092
+ const tx = await this.arweave.createTransaction({
315093
+ target,
315094
+ quantity: tokenAmount.toString(),
315095
+ data: ""
315122
315096
  });
315123
- const signedDataItem = dataItemStreamFactory();
315124
- const fileSize = dataItemSizeFactory();
315125
- this.logger.debug("Uploading signed data item...");
315126
- return this.httpService.post({
315127
- endpoint: `/tx/${this.token}`,
315128
- signal,
315129
- data: signedDataItem,
315130
- headers: {
315131
- "content-type": "application/octet-stream",
315132
- "content-length": `${fileSize}`
315133
- }
315097
+ if (feeMultiplier !== 1) {
315098
+ tx.reward = BigNumber5(tx.reward).times(BigNumber5(feeMultiplier)).toFixed(0, BigNumber5.ROUND_UP);
315099
+ }
315100
+ if (this.mintU) {
315101
+ tx.addTag("App-Name", "SmartWeaveAction");
315102
+ tx.addTag("App-Version", "0.3.0");
315103
+ tx.addTag("Contract", "KTzTXT_ANmF84fWEKHzWURD1LWd9QaFR9yfYUwH2Lxw");
315104
+ tx.addTag("Input", JSON.stringify({ function: "mint" }));
315105
+ }
315106
+ const publicKeyB64Url = toB64Url(await signer.getPublicKey());
315107
+ tx.setOwner(publicKeyB64Url);
315108
+ const dataToSign = await tx.getSignatureData();
315109
+ const signatureUint8Array = await signer.signData(dataToSign);
315110
+ const signatureBuffer = Buffer.from(signatureUint8Array);
315111
+ const id3 = sha256B64Url(signatureBuffer);
315112
+ tx.setSignature({
315113
+ id: id3,
315114
+ owner: publicKeyB64Url,
315115
+ signature: toB64Url(signatureBuffer)
315134
315116
  });
315117
+ this.logger.debug("Submitting fund transaction...", { id: id3 });
315118
+ await this.submitTx(tx);
315119
+ return { id: id3, target, reward: tx.reward };
315135
315120
  }
315136
- async generateManifest({
315137
- paths,
315138
- indexFile,
315139
- fallbackFile
315121
+ async pollForTxBeingAvailable({
315122
+ txId
315140
315123
  }) {
315141
- const indexPath = (
315142
- // Use the user provided index file if it exists,
315143
- indexFile !== void 0 && paths[indexFile]?.id !== void 0 ? indexFile : (
315144
- // Else use index.html if it exists,
315145
- paths["index.html"]?.id !== void 0 ? "index.html" : (
315146
- // Else use the first file in the paths object.
315147
- Object.keys(paths)[0]
315148
- )
315149
- )
315150
- );
315151
- const fallbackId = (
315152
- // Use the user provided fallback file if it exists,
315153
- fallbackFile !== void 0 && paths[fallbackFile]?.id !== void 0 ? paths[fallbackFile].id : (
315154
- // Else use 404.html if it exists, else use the index path.
315155
- paths["404.html"]?.id ?? paths[indexPath].id
315156
- )
315157
- );
315158
- const manifest = {
315159
- manifest: "arweave/paths",
315160
- version: "0.2.0",
315161
- index: { path: indexPath },
315162
- paths,
315163
- fallback: { id: fallbackId }
315164
- };
315165
- return manifest;
315166
- }
315167
- getContentType(file, dataItemOpts) {
315168
- const userDefinedContentType = dataItemOpts?.tags?.find(
315169
- (tag) => tag.name === "Content-Type"
315170
- )?.value;
315171
- if (userDefinedContentType !== void 0) {
315172
- return userDefinedContentType;
315173
- }
315174
- return this.contentTypeFromFile(file);
315175
- }
315176
- async uploadFolder(params) {
315177
- this.logger.debug("Uploading folder...", { params });
315178
- const {
315179
- dataItemOpts,
315180
- signal,
315181
- manifestOptions = {},
315182
- maxConcurrentUploads = 1,
315183
- throwOnFailure = true
315184
- } = params;
315185
- const { disableManifest, indexFile, fallbackFile } = manifestOptions;
315186
- const paths = {};
315187
- const response = {
315188
- fileResponses: []
315189
- };
315190
- const errors = [];
315191
- const uploadFile = async (file) => {
315192
- const contentType = this.getContentType(file, dataItemOpts);
315193
- const dataItemOptsWithContentType = {
315194
- ...dataItemOpts,
315195
- tags: [
315196
- ...dataItemOpts?.tags?.filter(
315197
- (tag) => tag.name !== "Content-Type"
315198
- ) ?? [],
315199
- { name: "Content-Type", value: contentType }
315200
- ]
315201
- };
315124
+ const { maxAttempts, pollingIntervalMs, initialBackoffMs } = this.pollingOptions;
315125
+ this.logger.debug("Polling for transaction...", { txId });
315126
+ await sleep(initialBackoffMs);
315127
+ let attempts = 0;
315128
+ while (attempts < maxAttempts) {
315129
+ let transaction;
315130
+ attempts++;
315202
315131
  try {
315203
- const result = await this.uploadFile({
315204
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
315205
- fileStreamFactory: () => this.getFileStreamForFile(file),
315206
- fileSizeFactory: () => this.getFileSize(file),
315207
- signal,
315208
- dataItemOpts: dataItemOptsWithContentType
315132
+ const response = await this.arweave.api.post("/graphql", {
315133
+ query: `
315134
+ query {
315135
+ transaction(id: "${txId}") {
315136
+ recipient
315137
+ owner {
315138
+ address
315139
+ }
315140
+ quantity {
315141
+ winston
315142
+ }
315143
+ }
315144
+ }
315145
+ `
315209
315146
  });
315210
- const relativePath = this.getRelativePath(file, params);
315211
- paths[relativePath] = { id: result.id };
315212
- response.fileResponses.push(result);
315213
- } catch (error) {
315214
- if (throwOnFailure) {
315215
- throw error;
315216
- }
315217
- this.logger.error(`Error uploading file: ${file}`, error);
315218
- errors.push(error);
315147
+ transaction = response?.data?.data?.transaction;
315148
+ } catch (err) {
315149
+ this.logger.debug("Failed to poll for transaction...", { err });
315219
315150
  }
315220
- };
315221
- const files = await this.getFiles(params);
315222
- const limit = pLimit(maxConcurrentUploads);
315223
- await Promise.all(files.map((file) => limit(() => uploadFile(file))));
315224
- this.logger.debug("Finished uploading files", {
315225
- numFiles: files.length,
315226
- numErrors: errors.length,
315227
- results: response.fileResponses
315228
- });
315229
- if (errors.length > 0) {
315230
- response.errors = errors;
315151
+ if (transaction) {
315152
+ return;
315153
+ }
315154
+ this.logger.debug("Transaction not found...", {
315155
+ txId,
315156
+ attempts,
315157
+ maxAttempts,
315158
+ pollingIntervalMs
315159
+ });
315160
+ await sleep(pollingIntervalMs);
315231
315161
  }
315232
- if (disableManifest) {
315233
- return response;
315162
+ throw new Error(
315163
+ "Transaction not found after polling, transaction id: " + txId
315164
+ );
315165
+ }
315166
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
315167
+ async submitTx(tx) {
315168
+ try {
315169
+ const response = await this.arweave.transactions.post(tx);
315170
+ if (response.status !== 200) {
315171
+ throw new Error(
315172
+ `Failed to post transaction -- Status ${response.status}, ${response.statusText}, ${response.data}`
315173
+ );
315174
+ }
315175
+ this.logger.debug("Successfully posted fund transaction...", { tx });
315176
+ } catch (err) {
315177
+ throw new Error(
315178
+ `Failed to post transaction -- ${err instanceof Error ? err.message : err}`
315179
+ );
315234
315180
  }
315235
- const manifest = await this.generateManifest({
315236
- paths,
315237
- indexFile,
315238
- fallbackFile
315239
- });
315240
- const tagsWithManifestContentType = [
315241
- ...dataItemOpts?.tags?.filter((tag) => tag.name !== "Content-Type") ?? [],
315242
- { name: "Content-Type", value: "application/x.arweave-manifest+json" }
315243
- ];
315244
- const manifestBuffer = Buffer.from(JSON.stringify(manifest));
315245
- const manifestResponse = await this.uploadFile({
315246
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
315247
- fileStreamFactory: () => this.createManifestStream(manifestBuffer),
315248
- fileSizeFactory: () => manifestBuffer.byteLength,
315249
- signal,
315250
- dataItemOpts: { ...dataItemOpts, tags: tagsWithManifestContentType }
315251
- });
315252
- return {
315253
- ...response,
315254
- manifest,
315255
- manifestResponse
315256
- };
315181
+ this.logger.debug("Posted transaction...", { tx });
315257
315182
  }
315258
315183
  };
315259
-
315260
- // src/common/turbo.ts
315261
- var developmentTurboConfiguration = {
315262
- paymentServiceConfig: {
315263
- url: developmentPaymentServiceURL
315264
- },
315265
- uploadServiceConfig: {
315266
- url: developmentUploadServiceURL
315267
- }
315268
- };
315269
- var defaultTurboConfiguration = {
315270
- paymentServiceConfig: {
315271
- url: defaultPaymentServiceURL
315272
- },
315273
- uploadServiceConfig: {
315274
- url: defaultUploadServiceURL
315275
- }
315276
- };
315277
- var TurboUnauthenticatedClient = class {
315278
- constructor({
315279
- uploadService = new TurboUnauthenticatedUploadService({}),
315280
- paymentService = new TurboUnauthenticatedPaymentService({})
315281
- }) {
315282
- this.paymentService = paymentService;
315283
- this.uploadService = uploadService;
315284
- }
315285
- /**
315286
- * Returns the supported fiat currency conversion rate for 1AR based on current market prices.
315287
- */
315288
- getFiatToAR({
315289
- currency
315290
- }) {
315291
- return this.paymentService.getFiatToAR({ currency });
315292
- }
315293
- /**
315294
- * Returns the latest conversion rates to purchase 1GiB of data for all supported currencies, including all adjustments and fees.
315295
- *
315296
- * Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
315297
- * cost in 'winc' for a given number of bytes, use getUploadCosts.
315298
- */
315299
- getFiatRates() {
315300
- return this.paymentService.getFiatRates();
315301
- }
315302
- /**
315303
- * Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
315304
- */
315305
- getSupportedCountries() {
315306
- return this.paymentService.getSupportedCountries();
315307
- }
315308
- getBalance(address) {
315309
- return this.paymentService.getBalance(address);
315310
- }
315311
- /**
315312
- * Returns a list of all supported fiat currencies.
315313
- */
315314
- getSupportedCurrencies() {
315315
- return this.paymentService.getSupportedCurrencies();
315316
- }
315317
- /**
315318
- * Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
315319
- */
315320
- getUploadCosts({
315321
- bytes: bytes4
315322
- }) {
315323
- return this.paymentService.getUploadCosts({ bytes: bytes4 });
315324
- }
315325
- /**
315326
- * Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
315327
- */
315328
- getWincForFiat(params) {
315329
- return this.paymentService.getWincForFiat(params);
315330
- }
315331
- /**
315332
- * Determines the amount of 'winc' that would be returned for a given token and amount, including all Turbo cost adjustments and fees.
315333
- */
315334
- getWincForToken(params) {
315335
- return this.paymentService.getWincForToken(params);
315336
- }
315337
- /**
315338
- * Uploads a signed data item to the Turbo Upload Service.
315339
- */
315340
- uploadSignedDataItem({
315341
- dataItemStreamFactory,
315342
- dataItemSizeFactory,
315343
- signal
315344
- }) {
315345
- return this.uploadService.uploadSignedDataItem({
315346
- dataItemStreamFactory,
315347
- dataItemSizeFactory,
315348
- signal
315349
- });
315350
- }
315351
- /**
315352
- * Creates a Turbo Checkout Session for a given amount and currency.
315353
- */
315354
- createCheckoutSession(params) {
315355
- return this.paymentService.createCheckoutSession(params);
315356
- }
315357
- /**
315358
- * Submits a transaction ID to the Turbo Payment Service for processing.
315359
- */
315360
- submitFundTransaction(p8) {
315361
- return this.paymentService.submitFundTransaction(p8);
315362
- }
315363
- /**
315364
- * Returns the connected target Turbo wallet addresses for all supported tokens.
315365
- */
315366
- async getTurboCryptoWallets() {
315367
- const wallets = await this.paymentService.getTurboCryptoWallets();
315368
- wallets.pol = wallets.matic;
315369
- return wallets;
315370
- }
315371
- };
315372
- var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
315373
- constructor({
315374
- paymentService,
315375
- uploadService,
315376
- signer
315377
- }) {
315378
- super({ paymentService, uploadService });
315379
- this.signer = signer;
315380
- }
315381
- /**
315382
- * Returns the current balance of the user's wallet in 'winc'.
315383
- */
315384
- getBalance(address) {
315385
- return this.paymentService.getBalance(address);
315386
- }
315387
- /**
315388
- * Signs and uploads raw data to the Turbo Upload Service.
315389
- */
315390
- uploadFile({
315391
- fileStreamFactory,
315392
- fileSizeFactory,
315393
- signal,
315394
- dataItemOpts
315395
- }) {
315396
- return this.uploadService.uploadFile({
315397
- fileStreamFactory,
315398
- fileSizeFactory,
315399
- signal,
315400
- dataItemOpts
315401
- });
315402
- }
315403
- uploadFolder(p8) {
315404
- return this.uploadService.uploadFolder(p8);
315405
- }
315406
- /**
315407
- * Submits fund transaction to the token's blockchain then sends
315408
- * the transaction ID to the Turbo Payment Service for processing.
315409
- */
315410
- topUpWithTokens(p8) {
315411
- return this.paymentService.topUpWithTokens(p8);
315412
- }
315413
- };
315414
-
315415
- // src/common/factory.ts
315416
- var TurboBaseFactory = class {
315417
- static {
315418
- this.logger = TurboWinstonLogger.default;
315419
- }
315420
- /* @deprecated - use TurboWinstonLogger directly */
315421
- static setLogLevel(level) {
315422
- this.logger.setLogLevel(level);
315423
- }
315424
- /* @deprecated - use TurboWinstonLogger directly */
315425
- static setLogFormat(format6) {
315426
- this.logger.setLogFormat(format6);
315427
- }
315428
- static unauthenticated({
315429
- paymentServiceConfig = {},
315430
- uploadServiceConfig = {},
315431
- token
315432
- } = {}) {
315433
- token = token === "pol" ? "matic" : token;
315434
- const paymentService = new TurboUnauthenticatedPaymentService({
315435
- ...paymentServiceConfig,
315436
- logger: this.logger,
315437
- token
315438
- });
315439
- const uploadService = new TurboUnauthenticatedUploadService({
315440
- ...uploadServiceConfig,
315441
- logger: this.logger,
315442
- token
315443
- });
315444
- return new TurboUnauthenticatedClient({
315445
- uploadService,
315446
- paymentService
315447
- });
315448
- }
315449
- };
315450
-
315451
- // src/common/index.ts
315452
- init_dirname();
315453
- init_buffer2();
315454
- init_process2();
315455
-
315456
- // src/common/currency.ts
315457
- init_dirname();
315458
- init_buffer2();
315459
- init_process2();
315460
- var ZeroDecimalCurrency = class {
315461
- constructor(amt, type3) {
315462
- this.amt = amt;
315463
- this.type = type3;
315464
- if (amt < 0) {
315465
- throw new ProvidedInputError(
315466
- `${type3} currency amount cannot be negative`
315467
- );
315468
- }
315469
- this.assertDecimalPlaces(amt);
315470
- }
315471
- assertDecimalPlaces(a8) {
315472
- if (a8 % 1 !== 0) {
315473
- throw new ProvidedInputError(
315474
- `${this.type} currency amount must have zero decimal places`
315475
- );
315476
- }
315477
- }
315478
- get amount() {
315479
- return this.amt;
315480
- }
315481
- };
315482
- var TwoDecimalCurrency = class extends ZeroDecimalCurrency {
315483
- constructor(a8, type3) {
315484
- super(a8, type3);
315485
- this.a = a8;
315486
- this.type = type3;
315487
- }
315488
- assertDecimalPlaces(a8) {
315489
- if (a8 * 100 % 1 !== 0) {
315490
- throw new ProvidedInputError(
315491
- `${this.type} currency amount must have two decimal places`
315492
- );
315493
- }
315494
- }
315495
- get amount() {
315496
- return this.a * 100;
315497
- }
315498
- };
315499
- var USD = (usd) => new TwoDecimalCurrency(usd, "usd");
315500
- var EUR = (eur) => new TwoDecimalCurrency(eur, "eur");
315501
- var GBP = (gbp) => new TwoDecimalCurrency(gbp, "gbp");
315502
- var CAD = (cad) => new TwoDecimalCurrency(cad, "cad");
315503
- var AUD = (aud) => new TwoDecimalCurrency(aud, "aud");
315504
- var INR = (inr) => new TwoDecimalCurrency(inr, "inr");
315505
- var SGD = (sgd) => new TwoDecimalCurrency(sgd, "sgd");
315506
- var HKD = (hkd) => new TwoDecimalCurrency(hkd, "hkd");
315507
- var BRL = (brl) => new TwoDecimalCurrency(brl, "brl");
315508
- var JPY = (jpy) => new ZeroDecimalCurrency(jpy, "jpy");
315509
- var currencyMap = {
315510
- usd: USD,
315511
- eur: EUR,
315512
- gbp: GBP,
315513
- cad: CAD,
315514
- aud: AUD,
315515
- inr: INR,
315516
- sgd: SGD,
315517
- hkd: HKD,
315518
- brl: BRL,
315519
- jpy: JPY
315520
- };
315521
-
315522
- // src/common/token/index.ts
315523
- init_dirname();
315524
- init_buffer2();
315525
- init_process2();
315526
-
315527
- // src/types.ts
315528
- init_dirname();
315529
- init_buffer2();
315530
- init_process2();
315531
- var fiatCurrencyTypes = [
315532
- "usd",
315533
- "eur",
315534
- "gbp",
315535
- "cad",
315536
- "aud",
315537
- "jpy",
315538
- "inr",
315539
- "sgd",
315540
- "hkd",
315541
- "brl"
315542
- ];
315543
- function isCurrency(currency) {
315544
- return fiatCurrencyTypes.includes(currency);
315545
- }
315546
- var tokenTypes = [
315547
- "arweave",
315548
- "solana",
315549
- "ethereum",
315550
- "kyve",
315551
- "matic",
315552
- "pol"
315553
- ];
315554
- var isNodeUploadFolderParams = (p8) => p8.folderPath !== void 0;
315555
- var isWebUploadFolderParams = (p8) => p8.files !== void 0;
315556
- function isKyvePrivateKey(wallet) {
315557
- if (typeof wallet !== "string")
315558
- return false;
315559
- return true;
315560
- }
315561
- function isEthPrivateKey(wallet) {
315562
- if (typeof wallet !== "string")
315563
- return false;
315564
- return wallet.startsWith("0x");
315565
- }
315566
- var isJWK = (wallet) => wallet.kty !== void 0;
315567
-
315568
- // src/common/token/arweave.ts
315569
- init_dirname();
315570
- init_buffer2();
315571
- init_process2();
315572
- var import_arweave = __toESM(require_web(), 1);
315573
- init_buffer();
315574
-
315575
- // src/utils/base64.ts
315576
- init_dirname();
315577
- init_buffer2();
315578
- init_process2();
315579
- var import_utils28 = __toESM(require_utils5(), 1);
315580
- init_crypto();
315581
- init_buffer();
315582
- function ownerToAddress(owner) {
315583
- return sha256B64Url(fromB64Url(owner));
315584
- }
315585
- function fromB64Url(input) {
315586
- const paddingLength = input.length % 4 === 0 ? 0 : 4 - input.length % 4;
315587
- const base64 = input.replace(/-/g, "+").replace(/_/g, "/").concat("=".repeat(paddingLength));
315588
- return Buffer.from(base64, "base64");
315589
- }
315590
- function toB64Url(buffer2) {
315591
- return (0, import_utils28.bufferTob64Url)(buffer2);
315592
- }
315593
- function sha256B64Url(input) {
315594
- return toB64Url(createHash("sha256").update(input).digest());
315595
- }
315596
-
315597
- // src/utils/common.ts
315598
- init_dirname();
315599
- init_buffer2();
315600
- init_process2();
315601
- var import_amino = __toESM(require_build5(), 1);
315602
- var import_crypto7 = __toESM(require_build4(), 1);
315603
- var import_encoding = __toESM(require_build(), 1);
315604
- function sleep(ms) {
315605
- return new Promise((resolve3) => setTimeout(resolve3, ms));
315606
- }
315607
- function createTurboSigner({
315608
- signer: clientProvidedSigner,
315609
- privateKey: clientProvidedPrivateKey,
315610
- token = "arweave"
315611
- }) {
315612
- if (clientProvidedSigner !== void 0) {
315613
- return clientProvidedSigner;
315614
- }
315615
- if (clientProvidedPrivateKey === void 0) {
315616
- throw new Error("A privateKey or signer must be provided.");
315617
- }
315618
- switch (token) {
315619
- case "solana":
315620
- return new HexSolanaSigner2(clientProvidedPrivateKey);
315621
- case "ethereum":
315622
- case "matic":
315623
- if (!isEthPrivateKey(clientProvidedPrivateKey)) {
315624
- throw new Error(
315625
- "A valid Ethereum private key must be provided for EthereumSigner."
315626
- );
315627
- }
315628
- return new EthereumSigner(clientProvidedPrivateKey);
315629
- case "kyve":
315630
- if (!isKyvePrivateKey(clientProvidedPrivateKey)) {
315631
- throw new Error(
315632
- "A valid Kyve private key must be provided for KyveSigner."
315633
- );
315634
- }
315635
- return signerFromKyvePrivateKey(clientProvidedPrivateKey);
315636
- default:
315637
- if (!isJWK(clientProvidedPrivateKey)) {
315638
- throw new Error("A JWK must be provided for ArweaveSigner.");
315639
- }
315640
- return new ArweaveSigner(clientProvidedPrivateKey);
315641
- }
315642
- }
315643
- function signerFromKyvePrivateKey(privateKey) {
315644
- return new EthereumSigner(privateKey);
315645
- }
315646
-
315647
- // src/common/token/arweave.ts
315648
- var ArweaveToken = class {
315649
- constructor({
315650
- gatewayUrl = "https://arweave.net",
315651
- arweave,
315652
- logger: logger15 = TurboWinstonLogger.default,
315653
- mintU = true,
315654
- pollingOptions = {
315655
- maxAttempts: 10,
315656
- pollingIntervalMs: 3e3,
315657
- initialBackoffMs: 7e3
315658
- }
315659
- } = {}) {
315660
- const url = new URL(gatewayUrl);
315661
- this.arweave = arweave ?? import_arweave.default.init({
315662
- host: url.hostname,
315663
- port: url.port,
315664
- protocol: url.protocol.replace(":", "")
315665
- });
315666
- this.logger = logger15;
315667
- this.mintU = mintU;
315668
- this.pollingOptions = pollingOptions;
315669
- }
315670
- async createAndSubmitTx({
315671
- feeMultiplier,
315672
- target,
315673
- tokenAmount,
315674
- signer
315675
- }) {
315676
- const tx = await this.arweave.createTransaction({
315677
- target,
315678
- quantity: tokenAmount.toString(),
315679
- data: ""
315680
- });
315681
- if (feeMultiplier !== 1) {
315682
- tx.reward = BigNumber5(tx.reward).times(BigNumber5(feeMultiplier)).toFixed(0, BigNumber5.ROUND_UP);
315683
- }
315684
- if (this.mintU) {
315685
- tx.addTag("App-Name", "SmartWeaveAction");
315686
- tx.addTag("App-Version", "0.3.0");
315687
- tx.addTag("Contract", "KTzTXT_ANmF84fWEKHzWURD1LWd9QaFR9yfYUwH2Lxw");
315688
- tx.addTag("Input", JSON.stringify({ function: "mint" }));
315689
- }
315690
- const publicKeyB64Url = toB64Url(await signer.getPublicKey());
315691
- tx.setOwner(publicKeyB64Url);
315692
- const dataToSign = await tx.getSignatureData();
315693
- const signatureUint8Array = await signer.signData(dataToSign);
315694
- const signatureBuffer = Buffer.from(signatureUint8Array);
315695
- const id3 = sha256B64Url(signatureBuffer);
315696
- tx.setSignature({
315697
- id: id3,
315698
- owner: publicKeyB64Url,
315699
- signature: toB64Url(signatureBuffer)
315700
- });
315701
- this.logger.debug("Submitting fund transaction...", { id: id3 });
315702
- await this.submitTx(tx);
315703
- return { id: id3, target, reward: tx.reward };
315704
- }
315705
- async pollForTxBeingAvailable({
315706
- txId
315707
- }) {
315708
- const { maxAttempts, pollingIntervalMs, initialBackoffMs } = this.pollingOptions;
315709
- this.logger.debug("Polling for transaction...", { txId });
315710
- await sleep(initialBackoffMs);
315711
- let attempts = 0;
315712
- while (attempts < maxAttempts) {
315713
- let transaction;
315714
- attempts++;
315715
- try {
315716
- const response = await this.arweave.api.post("/graphql", {
315717
- query: `
315718
- query {
315719
- transaction(id: "${txId}") {
315720
- recipient
315721
- owner {
315722
- address
315723
- }
315724
- quantity {
315725
- winston
315726
- }
315727
- }
315728
- }
315729
- `
315730
- });
315731
- transaction = response?.data?.data?.transaction;
315732
- } catch (err) {
315733
- this.logger.debug("Failed to poll for transaction...", { err });
315734
- }
315735
- if (transaction) {
315736
- return;
315737
- }
315738
- this.logger.debug("Transaction not found...", {
315739
- txId,
315740
- attempts,
315741
- maxAttempts,
315742
- pollingIntervalMs
315743
- });
315744
- await sleep(pollingIntervalMs);
315745
- }
315746
- throw new Error(
315747
- "Transaction not found after polling, transaction id: " + txId
315748
- );
315749
- }
315750
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
315751
- async submitTx(tx) {
315752
- try {
315753
- const response = await this.arweave.transactions.post(tx);
315754
- if (response.status !== 200) {
315755
- throw new Error(
315756
- `Failed to post transaction -- Status ${response.status}, ${response.statusText}, ${response.data}`
315757
- );
315758
- }
315759
- this.logger.debug("Successfully posted fund transaction...", { tx });
315760
- } catch (err) {
315761
- throw new Error(
315762
- `Failed to post transaction -- ${err instanceof Error ? err.message : err}`
315763
- );
315764
- }
315765
- this.logger.debug("Posted transaction...", { tx });
315766
- }
315767
- };
315768
- var WinstonToTokenAmount = (winston2) => winston2;
315769
- var ARToTokenAmount = (ar) => new BigNumber5(ar).times(1e12).valueOf();
315184
+ var WinstonToTokenAmount = (winston2) => winston2;
315185
+ var ARToTokenAmount = (ar) => new BigNumber5(ar).times(1e12).valueOf();
315770
315186
 
315771
315187
  // src/common/token/ethereum.ts
315772
315188
  init_dirname();
@@ -349961,8 +349377,8 @@ var SolanaToken = class {
349961
349377
  gatewayUrl = "https://api.mainnet-beta.solana.com",
349962
349378
  pollingOptions = {
349963
349379
  maxAttempts: 10,
349964
- pollingIntervalMs: 5e3,
349965
- initialBackoffMs: 7e3
349380
+ pollingIntervalMs: 2500,
349381
+ initialBackoffMs: 500
349966
349382
  }
349967
349383
  } = {}) {
349968
349384
  this.logger = logger15;
@@ -350072,10 +349488,617 @@ function isTokenType(token) {
350072
349488
  return tokenTypes.includes(token);
350073
349489
  }
350074
349490
 
349491
+ // src/common/turbo.ts
349492
+ init_dirname();
349493
+ init_buffer2();
349494
+ init_process2();
349495
+
349496
+ // src/common/upload.ts
349497
+ init_dirname();
349498
+ init_buffer2();
349499
+ init_process2();
349500
+ init_buffer();
349501
+
349502
+ // node_modules/plimit-lit/dist/index.js
349503
+ init_dirname();
349504
+ init_buffer2();
349505
+ init_process2();
349506
+ var __defProp2 = Object.defineProperty;
349507
+ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp2(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
349508
+ var __publicField = (obj, key2, value) => {
349509
+ __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
349510
+ return value;
349511
+ };
349512
+ var Node = class {
349513
+ constructor(value) {
349514
+ __publicField(this, "value");
349515
+ __publicField(this, "next");
349516
+ this.value = value;
349517
+ }
349518
+ };
349519
+ var Queue = class {
349520
+ constructor() {
349521
+ __publicField(this, "head");
349522
+ __publicField(this, "tail");
349523
+ __publicField(this, "_size", 0);
349524
+ this.clear();
349525
+ }
349526
+ /**
349527
+ * Removes all elements from the queue.
349528
+ */
349529
+ clear() {
349530
+ this.head = void 0;
349531
+ this.tail = void 0;
349532
+ this._size = 0;
349533
+ }
349534
+ /**
349535
+ * Adds a new element to the queue.
349536
+ */
349537
+ push(value) {
349538
+ const node = new Node(value);
349539
+ if (this.head && this.tail) {
349540
+ this.tail.next = node;
349541
+ this.tail = node;
349542
+ } else {
349543
+ this.head = node;
349544
+ this.tail = node;
349545
+ }
349546
+ this._size++;
349547
+ return this._size;
349548
+ }
349549
+ /**
349550
+ * Removes and returns the first element in the queue.
349551
+ */
349552
+ pop() {
349553
+ if (!this.head)
349554
+ return;
349555
+ const current = this.head;
349556
+ this.head = this.head.next;
349557
+ this._size--;
349558
+ return current.value;
349559
+ }
349560
+ /**
349561
+ * Returns the number of elements in the queue.
349562
+ */
349563
+ get size() {
349564
+ return this._size;
349565
+ }
349566
+ *[Symbol.iterator]() {
349567
+ let current = this.head;
349568
+ while (current) {
349569
+ yield current.value;
349570
+ current = current.next;
349571
+ }
349572
+ }
349573
+ };
349574
+ function pLimit(concurrency) {
349575
+ if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
349576
+ throw new TypeError("Expected `concurrency` to be a number greater than 1");
349577
+ }
349578
+ const queue2 = new Queue();
349579
+ let activeCount = 0;
349580
+ const next = () => {
349581
+ activeCount--;
349582
+ if (queue2.size > 0) {
349583
+ queue2.pop()();
349584
+ }
349585
+ };
349586
+ const run2 = async (fn, resolve3, args) => {
349587
+ activeCount++;
349588
+ const result = (async () => fn(...args))();
349589
+ resolve3(result);
349590
+ try {
349591
+ await result;
349592
+ } catch {
349593
+ }
349594
+ next();
349595
+ };
349596
+ const enqueue = (fn, resolve3, args) => {
349597
+ queue2.push(run2.bind(null, fn, resolve3, args));
349598
+ (async () => {
349599
+ await Promise.resolve();
349600
+ if (activeCount < concurrency && queue2.size > 0) {
349601
+ queue2.pop()();
349602
+ }
349603
+ })();
349604
+ };
349605
+ const generator = (fn, ...args) => new Promise((resolve3) => {
349606
+ enqueue(fn, resolve3, args);
349607
+ });
349608
+ Object.defineProperties(generator, {
349609
+ activeCount: {
349610
+ get: () => activeCount
349611
+ },
349612
+ pendingCount: {
349613
+ get: () => queue2.size
349614
+ },
349615
+ clearQueue: {
349616
+ value: () => {
349617
+ queue2.clear();
349618
+ }
349619
+ }
349620
+ });
349621
+ return generator;
349622
+ }
349623
+
349624
+ // src/common/upload.ts
349625
+ var developmentUploadServiceURL = "https://upload.ardrive.dev";
349626
+ var defaultUploadServiceURL = "https://upload.ardrive.io";
349627
+ var TurboUnauthenticatedUploadService = class {
349628
+ constructor({
349629
+ url = defaultUploadServiceURL,
349630
+ retryConfig,
349631
+ logger: logger15 = TurboWinstonLogger.default,
349632
+ token = "arweave"
349633
+ }) {
349634
+ this.token = token;
349635
+ this.logger = logger15;
349636
+ this.httpService = new TurboHTTPService({
349637
+ url: `${url}/v1`,
349638
+ retryConfig,
349639
+ logger: this.logger
349640
+ });
349641
+ }
349642
+ async uploadSignedDataItem({
349643
+ dataItemStreamFactory,
349644
+ dataItemSizeFactory,
349645
+ signal
349646
+ }) {
349647
+ const fileSize = dataItemSizeFactory();
349648
+ this.logger.debug("Uploading signed data item...");
349649
+ return this.httpService.post({
349650
+ endpoint: `/tx/${this.token}`,
349651
+ signal,
349652
+ data: dataItemStreamFactory(),
349653
+ headers: {
349654
+ "content-type": "application/octet-stream",
349655
+ "content-length": `${fileSize}`
349656
+ }
349657
+ });
349658
+ }
349659
+ };
349660
+ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUploadService {
349661
+ constructor({
349662
+ url = defaultUploadServiceURL,
349663
+ retryConfig,
349664
+ signer,
349665
+ logger: logger15,
349666
+ token
349667
+ }) {
349668
+ super({ url, retryConfig, logger: logger15, token });
349669
+ this.signer = signer;
349670
+ }
349671
+ async uploadFile({
349672
+ fileStreamFactory,
349673
+ fileSizeFactory,
349674
+ signal,
349675
+ dataItemOpts
349676
+ }) {
349677
+ const { dataItemStreamFactory, dataItemSizeFactory } = await this.signer.signDataItem({
349678
+ fileStreamFactory,
349679
+ fileSizeFactory,
349680
+ dataItemOpts
349681
+ });
349682
+ const signedDataItem = dataItemStreamFactory();
349683
+ const fileSize = dataItemSizeFactory();
349684
+ this.logger.debug("Uploading signed data item...");
349685
+ return this.httpService.post({
349686
+ endpoint: `/tx/${this.token}`,
349687
+ signal,
349688
+ data: signedDataItem,
349689
+ headers: {
349690
+ "content-type": "application/octet-stream",
349691
+ "content-length": `${fileSize}`
349692
+ }
349693
+ });
349694
+ }
349695
+ async generateManifest({
349696
+ paths,
349697
+ indexFile,
349698
+ fallbackFile
349699
+ }) {
349700
+ const indexPath = (
349701
+ // Use the user provided index file if it exists,
349702
+ indexFile !== void 0 && paths[indexFile]?.id !== void 0 ? indexFile : (
349703
+ // Else use index.html if it exists,
349704
+ paths["index.html"]?.id !== void 0 ? "index.html" : (
349705
+ // Else use the first file in the paths object.
349706
+ Object.keys(paths)[0]
349707
+ )
349708
+ )
349709
+ );
349710
+ const fallbackId = (
349711
+ // Use the user provided fallback file if it exists,
349712
+ fallbackFile !== void 0 && paths[fallbackFile]?.id !== void 0 ? paths[fallbackFile].id : (
349713
+ // Else use 404.html if it exists, else use the index path.
349714
+ paths["404.html"]?.id ?? paths[indexPath].id
349715
+ )
349716
+ );
349717
+ const manifest = {
349718
+ manifest: "arweave/paths",
349719
+ version: "0.2.0",
349720
+ index: { path: indexPath },
349721
+ paths,
349722
+ fallback: { id: fallbackId }
349723
+ };
349724
+ return manifest;
349725
+ }
349726
+ getContentType(file, dataItemOpts) {
349727
+ const userDefinedContentType = dataItemOpts?.tags?.find(
349728
+ (tag) => tag.name === "Content-Type"
349729
+ )?.value;
349730
+ if (userDefinedContentType !== void 0) {
349731
+ return userDefinedContentType;
349732
+ }
349733
+ return this.contentTypeFromFile(file);
349734
+ }
349735
+ async uploadFolder(params) {
349736
+ this.logger.debug("Uploading folder...", { params });
349737
+ const {
349738
+ dataItemOpts,
349739
+ signal,
349740
+ manifestOptions = {},
349741
+ maxConcurrentUploads = 1,
349742
+ throwOnFailure = true
349743
+ } = params;
349744
+ const { disableManifest, indexFile, fallbackFile } = manifestOptions;
349745
+ const paths = {};
349746
+ const response = {
349747
+ fileResponses: []
349748
+ };
349749
+ const errors = [];
349750
+ const uploadFile = async (file) => {
349751
+ const contentType = this.getContentType(file, dataItemOpts);
349752
+ const dataItemOptsWithContentType = {
349753
+ ...dataItemOpts,
349754
+ tags: [
349755
+ ...dataItemOpts?.tags?.filter(
349756
+ (tag) => tag.name !== "Content-Type"
349757
+ ) ?? [],
349758
+ { name: "Content-Type", value: contentType }
349759
+ ]
349760
+ };
349761
+ try {
349762
+ const result = await this.uploadFile({
349763
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
349764
+ fileStreamFactory: () => this.getFileStreamForFile(file),
349765
+ fileSizeFactory: () => this.getFileSize(file),
349766
+ signal,
349767
+ dataItemOpts: dataItemOptsWithContentType
349768
+ });
349769
+ const relativePath = this.getRelativePath(file, params);
349770
+ paths[relativePath] = { id: result.id };
349771
+ response.fileResponses.push(result);
349772
+ } catch (error) {
349773
+ if (throwOnFailure) {
349774
+ throw error;
349775
+ }
349776
+ this.logger.error(`Error uploading file: ${file}`, error);
349777
+ errors.push(error);
349778
+ }
349779
+ };
349780
+ const files = await this.getFiles(params);
349781
+ const limit = pLimit(maxConcurrentUploads);
349782
+ await Promise.all(files.map((file) => limit(() => uploadFile(file))));
349783
+ this.logger.debug("Finished uploading files", {
349784
+ numFiles: files.length,
349785
+ numErrors: errors.length,
349786
+ results: response.fileResponses
349787
+ });
349788
+ if (errors.length > 0) {
349789
+ response.errors = errors;
349790
+ }
349791
+ if (disableManifest) {
349792
+ return response;
349793
+ }
349794
+ const manifest = await this.generateManifest({
349795
+ paths,
349796
+ indexFile,
349797
+ fallbackFile
349798
+ });
349799
+ const tagsWithManifestContentType = [
349800
+ ...dataItemOpts?.tags?.filter((tag) => tag.name !== "Content-Type") ?? [],
349801
+ { name: "Content-Type", value: "application/x.arweave-manifest+json" }
349802
+ ];
349803
+ const manifestBuffer = Buffer.from(JSON.stringify(manifest));
349804
+ const manifestResponse = await this.uploadFile({
349805
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
349806
+ fileStreamFactory: () => this.createManifestStream(manifestBuffer),
349807
+ fileSizeFactory: () => manifestBuffer.byteLength,
349808
+ signal,
349809
+ dataItemOpts: { ...dataItemOpts, tags: tagsWithManifestContentType }
349810
+ });
349811
+ return {
349812
+ ...response,
349813
+ manifest,
349814
+ manifestResponse
349815
+ };
349816
+ }
349817
+ };
349818
+
349819
+ // src/common/turbo.ts
349820
+ var developmentTurboConfiguration = {
349821
+ paymentServiceConfig: {
349822
+ url: developmentPaymentServiceURL
349823
+ },
349824
+ uploadServiceConfig: {
349825
+ url: developmentUploadServiceURL
349826
+ }
349827
+ };
349828
+ var defaultTurboConfiguration = {
349829
+ paymentServiceConfig: {
349830
+ url: defaultPaymentServiceURL
349831
+ },
349832
+ uploadServiceConfig: {
349833
+ url: defaultUploadServiceURL
349834
+ }
349835
+ };
349836
+ var TurboUnauthenticatedClient = class {
349837
+ constructor({
349838
+ uploadService = new TurboUnauthenticatedUploadService({}),
349839
+ paymentService = new TurboUnauthenticatedPaymentService({})
349840
+ }) {
349841
+ this.paymentService = paymentService;
349842
+ this.uploadService = uploadService;
349843
+ }
349844
+ /**
349845
+ * Returns the supported fiat currency conversion rate for 1AR based on current market prices.
349846
+ */
349847
+ getFiatToAR({
349848
+ currency
349849
+ }) {
349850
+ return this.paymentService.getFiatToAR({ currency });
349851
+ }
349852
+ /**
349853
+ * Returns the latest conversion rates to purchase 1GiB of data for all supported currencies, including all adjustments and fees.
349854
+ *
349855
+ * Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
349856
+ * cost in 'winc' for a given number of bytes, use getUploadCosts.
349857
+ */
349858
+ getFiatRates() {
349859
+ return this.paymentService.getFiatRates();
349860
+ }
349861
+ /**
349862
+ * Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
349863
+ */
349864
+ getSupportedCountries() {
349865
+ return this.paymentService.getSupportedCountries();
349866
+ }
349867
+ getBalance(address) {
349868
+ return this.paymentService.getBalance(address);
349869
+ }
349870
+ /**
349871
+ * Returns a list of all supported fiat currencies.
349872
+ */
349873
+ getSupportedCurrencies() {
349874
+ return this.paymentService.getSupportedCurrencies();
349875
+ }
349876
+ /**
349877
+ * Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
349878
+ */
349879
+ getUploadCosts({
349880
+ bytes: bytes4
349881
+ }) {
349882
+ return this.paymentService.getUploadCosts({ bytes: bytes4 });
349883
+ }
349884
+ /**
349885
+ * Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
349886
+ */
349887
+ getWincForFiat(params) {
349888
+ return this.paymentService.getWincForFiat(params);
349889
+ }
349890
+ /**
349891
+ * Determines the amount of 'winc' that would be returned for a given token and amount, including all Turbo cost adjustments and fees.
349892
+ */
349893
+ getWincForToken(params) {
349894
+ return this.paymentService.getWincForToken(params);
349895
+ }
349896
+ /**
349897
+ * Uploads a signed data item to the Turbo Upload Service.
349898
+ */
349899
+ uploadSignedDataItem({
349900
+ dataItemStreamFactory,
349901
+ dataItemSizeFactory,
349902
+ signal
349903
+ }) {
349904
+ return this.uploadService.uploadSignedDataItem({
349905
+ dataItemStreamFactory,
349906
+ dataItemSizeFactory,
349907
+ signal
349908
+ });
349909
+ }
349910
+ /**
349911
+ * Creates a Turbo Checkout Session for a given amount and currency.
349912
+ */
349913
+ createCheckoutSession(params) {
349914
+ return this.paymentService.createCheckoutSession(params);
349915
+ }
349916
+ /**
349917
+ * Submits a transaction ID to the Turbo Payment Service for processing.
349918
+ */
349919
+ submitFundTransaction(p8) {
349920
+ return this.paymentService.submitFundTransaction(p8);
349921
+ }
349922
+ /**
349923
+ * Returns the connected target Turbo wallet addresses for all supported tokens.
349924
+ */
349925
+ async getTurboCryptoWallets() {
349926
+ const wallets = await this.paymentService.getTurboCryptoWallets();
349927
+ wallets.pol = wallets.matic;
349928
+ return wallets;
349929
+ }
349930
+ };
349931
+ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
349932
+ constructor({
349933
+ paymentService,
349934
+ uploadService,
349935
+ signer
349936
+ }) {
349937
+ super({ paymentService, uploadService });
349938
+ this.signer = signer;
349939
+ }
349940
+ /**
349941
+ * Returns the current balance of the user's wallet in 'winc'.
349942
+ */
349943
+ getBalance(address) {
349944
+ return this.paymentService.getBalance(address);
349945
+ }
349946
+ /**
349947
+ * Signs and uploads raw data to the Turbo Upload Service.
349948
+ */
349949
+ uploadFile({
349950
+ fileStreamFactory,
349951
+ fileSizeFactory,
349952
+ signal,
349953
+ dataItemOpts
349954
+ }) {
349955
+ return this.uploadService.uploadFile({
349956
+ fileStreamFactory,
349957
+ fileSizeFactory,
349958
+ signal,
349959
+ dataItemOpts
349960
+ });
349961
+ }
349962
+ uploadFolder(p8) {
349963
+ return this.uploadService.uploadFolder(p8);
349964
+ }
349965
+ /**
349966
+ * Submits fund transaction to the token's blockchain then sends
349967
+ * the transaction ID to the Turbo Payment Service for processing.
349968
+ */
349969
+ topUpWithTokens(p8) {
349970
+ return this.paymentService.topUpWithTokens(p8);
349971
+ }
349972
+ };
349973
+
349974
+ // src/common/factory.ts
349975
+ var TurboBaseFactory = class {
349976
+ static {
349977
+ this.logger = TurboWinstonLogger.default;
349978
+ }
349979
+ /* @deprecated - use TurboWinstonLogger directly */
349980
+ static setLogLevel(level) {
349981
+ this.logger.setLogLevel(level);
349982
+ }
349983
+ /* @deprecated - use TurboWinstonLogger directly */
349984
+ static setLogFormat(format6) {
349985
+ this.logger.setLogFormat(format6);
349986
+ }
349987
+ static unauthenticated({
349988
+ paymentServiceConfig = {},
349989
+ uploadServiceConfig = {},
349990
+ token
349991
+ } = {}) {
349992
+ token = token === "pol" ? "matic" : token;
349993
+ token ??= "arweave";
349994
+ const paymentService = new TurboUnauthenticatedPaymentService({
349995
+ ...paymentServiceConfig,
349996
+ logger: this.logger,
349997
+ token
349998
+ });
349999
+ const uploadService = new TurboUnauthenticatedUploadService({
350000
+ ...uploadServiceConfig,
350001
+ logger: this.logger,
350002
+ token
350003
+ });
350004
+ return new TurboUnauthenticatedClient({
350005
+ uploadService,
350006
+ paymentService
350007
+ });
350008
+ }
350009
+ getAuthenticatedTurbo({
350010
+ privateKey,
350011
+ signer: providedSigner,
350012
+ paymentServiceConfig = {},
350013
+ uploadServiceConfig = {},
350014
+ token,
350015
+ gatewayUrl,
350016
+ tokenMap,
350017
+ tokenTools,
350018
+ logger: logger15,
350019
+ walletAdapter
350020
+ }) {
350021
+ token = token === "pol" ? "matic" : token;
350022
+ if (!token) {
350023
+ if (providedSigner) {
350024
+ if (providedSigner instanceof EthereumSigner) {
350025
+ token = "ethereum";
350026
+ } else if (providedSigner instanceof HexSolanaSigner2) {
350027
+ token = "solana";
350028
+ } else {
350029
+ token = "arweave";
350030
+ }
350031
+ } else {
350032
+ token = "arweave";
350033
+ }
350034
+ }
350035
+ token ??= "arweave";
350036
+ if (walletAdapter) {
350037
+ providedSigner = this.signerFromAdapter(walletAdapter, token);
350038
+ }
350039
+ const turboSigner = this.getSigner({
350040
+ providedSigner,
350041
+ providedPrivateKey: privateKey,
350042
+ token,
350043
+ logger: logger15,
350044
+ providedWalletAdapter: walletAdapter
350045
+ });
350046
+ if (!tokenTools) {
350047
+ if (tokenMap && token === "arweave") {
350048
+ tokenTools = tokenMap.arweave;
350049
+ }
350050
+ tokenTools = defaultTokenMap[token]?.({
350051
+ gatewayUrl,
350052
+ logger: logger15
350053
+ });
350054
+ }
350055
+ const paymentService = new TurboAuthenticatedPaymentService({
350056
+ ...paymentServiceConfig,
350057
+ signer: turboSigner,
350058
+ logger: logger15,
350059
+ token,
350060
+ tokenTools
350061
+ });
350062
+ const uploadService = this.getAuthenticatedUploadService({
350063
+ ...uploadServiceConfig,
350064
+ signer: turboSigner,
350065
+ logger: logger15,
350066
+ token
350067
+ });
350068
+ return new TurboAuthenticatedClient({
350069
+ uploadService,
350070
+ paymentService,
350071
+ signer: turboSigner
350072
+ });
350073
+ }
350074
+ signerFromAdapter(walletAdapter, token) {
350075
+ if (token === "solana") {
350076
+ if (!isSolanaWalletAdapter(walletAdapter)) {
350077
+ throw new Error(
350078
+ "Unsupported wallet adapter -- must implement publicKey and signMessage"
350079
+ );
350080
+ }
350081
+ return new HexSolanaSigner(walletAdapter);
350082
+ }
350083
+ if (token === "ethereum") {
350084
+ if (!isEthereumWalletAdapter(walletAdapter)) {
350085
+ throw new Error(
350086
+ "Unsupported wallet adapter -- must implement getSigner"
350087
+ );
350088
+ }
350089
+ return new InjectedEthereumSigner(walletAdapter);
350090
+ }
350091
+ throw new Error(
350092
+ "Unsupported wallet adapter -- wallet adapter is currently only supported for Solana and Ethereum"
350093
+ );
350094
+ }
350095
+ };
350096
+
350075
350097
  // src/web/signer.ts
350076
350098
  init_dirname();
350077
350099
  init_buffer2();
350078
350100
  init_process2();
350101
+ init_buffer();
350079
350102
 
350080
350103
  // src/common/signer.ts
350081
350104
  init_dirname();
@@ -350093,11 +350116,13 @@ var TurboDataItemAbstractSigner = class {
350093
350116
  constructor({
350094
350117
  signer,
350095
350118
  logger: logger15 = TurboWinstonLogger.default,
350096
- token
350119
+ token,
350120
+ walletAdapter
350097
350121
  }) {
350098
350122
  this.logger = logger15;
350099
350123
  this.signer = signer;
350100
350124
  this.token = token;
350125
+ this.walletAdapter = walletAdapter;
350101
350126
  }
350102
350127
  ownerToNativeAddress(owner, token) {
350103
350128
  switch (token) {
@@ -350146,6 +350171,24 @@ var TurboDataItemAbstractSigner = class {
350146
350171
  amount,
350147
350172
  gatewayUrl
350148
350173
  }) {
350174
+ if (this.walletAdapter) {
350175
+ if (!isEthereumWalletAdapter(this.walletAdapter)) {
350176
+ throw new Error(
350177
+ "Unsupported wallet adapter -- must implement getSigner"
350178
+ );
350179
+ }
350180
+ const signer = this.walletAdapter.getSigner();
350181
+ if (signer.sendTransaction === void 0) {
350182
+ throw new Error(
350183
+ "Unsupported wallet adapter -- getSigner must return a signer with sendTransaction API for crypto funds transfer"
350184
+ );
350185
+ }
350186
+ const { hash: hash6 } = await signer.sendTransaction({
350187
+ to: target,
350188
+ value: parseEther(amount.toFixed(18))
350189
+ });
350190
+ return hash6;
350191
+ }
350149
350192
  if (!(this.signer instanceof EthereumSigner)) {
350150
350193
  throw new Error(
350151
350194
  "Only EthereumSigner is supported for sendTransaction API currently!"
@@ -350222,7 +350265,7 @@ var TurboWebArweaveSigner = class extends TurboDataItemAbstractSigner {
350222
350265
  super(p8);
350223
350266
  }
350224
350267
  async setPublicKey() {
350225
- if (this.signer.publicKey === void 0 && this.signer instanceof InjectedArweaveSigner) {
350268
+ if (this.signer.publicKey === void 0 && (this.signer instanceof InjectedArweaveSigner || this.signer instanceof InjectedEthereumSigner)) {
350226
350269
  await this.signer.setPublicKey();
350227
350270
  }
350228
350271
  }
@@ -350236,8 +350279,9 @@ var TurboWebArweaveSigner = class extends TurboDataItemAbstractSigner {
350236
350279
  dataItemOpts
350237
350280
  }) {
350238
350281
  await this.setPublicKey();
350239
- const buffer2 = await readableStreamToBuffer({
350240
- stream: fileStreamFactory(),
350282
+ const fileStream = fileStreamFactory();
350283
+ const buffer2 = fileStream instanceof Buffer ? fileStream : await readableStreamToBuffer({
350284
+ stream: fileStream,
350241
350285
  size: fileSizeFactory()
350242
350286
  });
350243
350287
  this.logger.debug("Signing data item...");
@@ -350307,18 +350351,28 @@ var TurboAuthenticatedUploadService = class extends TurboAuthenticatedBaseUpload
350307
350351
  };
350308
350352
 
350309
350353
  // src/web/factory.ts
350310
- var TurboFactory = class extends TurboBaseFactory {
350311
- static getSigner(providedSigner, providedPrivateKey, token) {
350354
+ var TurboFactory = class _TurboFactory extends TurboBaseFactory {
350355
+ getSigner({
350356
+ providedPrivateKey,
350357
+ logger: logger15,
350358
+ providedSigner,
350359
+ providedWalletAdapter,
350360
+ token
350361
+ }) {
350312
350362
  return new TurboWebArweaveSigner({
350313
350363
  signer: createTurboSigner({
350314
350364
  signer: providedSigner,
350315
350365
  privateKey: providedPrivateKey,
350316
350366
  token
350317
350367
  }),
350318
- logger: this.logger,
350319
- token
350368
+ logger: logger15,
350369
+ token,
350370
+ walletAdapter: providedWalletAdapter
350320
350371
  });
350321
350372
  }
350373
+ getAuthenticatedUploadService(config2) {
350374
+ return new TurboAuthenticatedUploadService(config2);
350375
+ }
350322
350376
  static authenticated({
350323
350377
  privateKey,
350324
350378
  signer: providedSigner,
@@ -350327,53 +350381,94 @@ var TurboFactory = class extends TurboBaseFactory {
350327
350381
  token,
350328
350382
  gatewayUrl,
350329
350383
  tokenMap,
350330
- tokenTools
350384
+ tokenTools,
350385
+ walletAdapter
350331
350386
  }) {
350332
- token = token === "pol" ? "matic" : token;
350333
- if (!token) {
350334
- if (providedSigner) {
350335
- if (providedSigner instanceof EthereumSigner) {
350336
- token = "ethereum";
350337
- } else if (providedSigner instanceof HexSolanaSigner2) {
350338
- token = "solana";
350339
- } else {
350340
- token = "arweave";
350341
- }
350342
- } else {
350343
- token = "arweave";
350344
- }
350345
- }
350346
- const turboSigner = this.getSigner(providedSigner, privateKey, token);
350347
- token ??= "arweave";
350348
- if (!tokenTools) {
350349
- if (tokenMap && token === "arweave") {
350350
- tokenTools = tokenMap.arweave;
350351
- }
350352
- tokenTools = defaultTokenMap[token]?.({
350353
- gatewayUrl,
350354
- logger: this.logger
350355
- });
350356
- }
350357
- const paymentService = new TurboAuthenticatedPaymentService({
350358
- ...paymentServiceConfig,
350359
- signer: turboSigner,
350360
- logger: this.logger,
350387
+ return new _TurboFactory().getAuthenticatedTurbo({
350388
+ privateKey,
350389
+ signer: providedSigner,
350390
+ paymentServiceConfig,
350391
+ uploadServiceConfig,
350361
350392
  token,
350362
- tokenTools
350363
- });
350364
- const uploadService = new TurboAuthenticatedUploadService({
350365
- ...uploadServiceConfig,
350366
- signer: turboSigner,
350393
+ gatewayUrl,
350394
+ tokenMap,
350395
+ tokenTools,
350367
350396
  logger: this.logger,
350368
- token
350369
- });
350370
- return new TurboAuthenticatedClient({
350371
- uploadService,
350372
- paymentService,
350373
- signer: turboSigner
350397
+ walletAdapter
350374
350398
  });
350375
350399
  }
350376
350400
  };
350401
+
350402
+ // src/common/index.ts
350403
+ init_dirname();
350404
+ init_buffer2();
350405
+ init_process2();
350406
+
350407
+ // src/common/currency.ts
350408
+ init_dirname();
350409
+ init_buffer2();
350410
+ init_process2();
350411
+ var ZeroDecimalCurrency = class {
350412
+ constructor(amt, type3) {
350413
+ this.amt = amt;
350414
+ this.type = type3;
350415
+ if (amt < 0) {
350416
+ throw new ProvidedInputError(
350417
+ `${type3} currency amount cannot be negative`
350418
+ );
350419
+ }
350420
+ this.assertDecimalPlaces(amt);
350421
+ }
350422
+ assertDecimalPlaces(a8) {
350423
+ if (a8 % 1 !== 0) {
350424
+ throw new ProvidedInputError(
350425
+ `${this.type} currency amount must have zero decimal places`
350426
+ );
350427
+ }
350428
+ }
350429
+ get amount() {
350430
+ return this.amt;
350431
+ }
350432
+ };
350433
+ var TwoDecimalCurrency = class extends ZeroDecimalCurrency {
350434
+ constructor(a8, type3) {
350435
+ super(a8, type3);
350436
+ this.a = a8;
350437
+ this.type = type3;
350438
+ }
350439
+ assertDecimalPlaces(a8) {
350440
+ if (a8 * 100 % 1 !== 0) {
350441
+ throw new ProvidedInputError(
350442
+ `${this.type} currency amount must have two decimal places`
350443
+ );
350444
+ }
350445
+ }
350446
+ get amount() {
350447
+ return this.a * 100;
350448
+ }
350449
+ };
350450
+ var USD = (usd) => new TwoDecimalCurrency(usd, "usd");
350451
+ var EUR = (eur) => new TwoDecimalCurrency(eur, "eur");
350452
+ var GBP = (gbp) => new TwoDecimalCurrency(gbp, "gbp");
350453
+ var CAD = (cad) => new TwoDecimalCurrency(cad, "cad");
350454
+ var AUD = (aud) => new TwoDecimalCurrency(aud, "aud");
350455
+ var INR = (inr) => new TwoDecimalCurrency(inr, "inr");
350456
+ var SGD = (sgd) => new TwoDecimalCurrency(sgd, "sgd");
350457
+ var HKD = (hkd) => new TwoDecimalCurrency(hkd, "hkd");
350458
+ var BRL = (brl) => new TwoDecimalCurrency(brl, "brl");
350459
+ var JPY = (jpy) => new ZeroDecimalCurrency(jpy, "jpy");
350460
+ var currencyMap = {
350461
+ usd: USD,
350462
+ eur: EUR,
350463
+ gbp: GBP,
350464
+ cad: CAD,
350465
+ aud: AUD,
350466
+ inr: INR,
350467
+ sgd: SGD,
350468
+ hkd: HKD,
350469
+ brl: BRL,
350470
+ jpy: JPY
350471
+ };
350377
350472
  export {
350378
350473
  ARToTokenAmount,
350379
350474
  AUD,
@@ -350420,9 +350515,11 @@ export {
350420
350515
  fiatCurrencyTypes,
350421
350516
  isCurrency,
350422
350517
  isEthPrivateKey,
350518
+ isEthereumWalletAdapter,
350423
350519
  isJWK,
350424
350520
  isKyvePrivateKey,
350425
350521
  isNodeUploadFolderParams,
350522
+ isSolanaWalletAdapter,
350426
350523
  isTokenType,
350427
350524
  isWebUploadFolderParams,
350428
350525
  lamportToTokenAmount,