@ardrive/turbo-sdk 1.0.0-alpha.17 → 1.0.0-alpha.18

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.
@@ -55541,13 +55541,13 @@ var expObj = { ...src_exports, stream: stream_exports };
55541
55541
  globalThis.arbundles ??= expObj;
55542
55542
 
55543
55543
  // src/web/signer.ts
55544
- var import_arweave2 = __toESM(require_web2());
55545
- var import_node_crypto = __toESM(require_crypto_browserify());
55544
+ var import_arweave2 = __toESM(require_web2(), 1);
55545
+ var import_node_crypto = __toESM(require_crypto_browserify(), 1);
55546
55546
 
55547
55547
  // src/utils/base64.ts
55548
55548
  init_shim();
55549
- var import_utils28 = __toESM(require_utils8());
55550
- var import_crypto6 = __toESM(require_crypto_browserify());
55549
+ var import_utils28 = __toESM(require_utils8(), 1);
55550
+ var import_crypto6 = __toESM(require_crypto_browserify(), 1);
55551
55551
  function toB64Url(buffer) {
55552
55552
  return (0, import_utils28.bufferTob64Url)(buffer);
55553
55553
  }
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboBaseFactory = void 0;
4
- const payment_js_1 = require("./payment.js");
5
- const turbo_js_1 = require("./turbo.js");
6
- const upload_js_1 = require("./upload.js");
7
- class TurboBaseFactory {
1
+ import { TurboUnauthenticatedPaymentService } from './payment.js';
2
+ import { TurboUnauthenticatedClient } from './turbo.js';
3
+ import { TurboUnauthenticatedUploadService } from './upload.js';
4
+ export class TurboBaseFactory {
8
5
  static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, } = {}) {
9
- const paymentService = new payment_js_1.TurboUnauthenticatedPaymentService(Object.assign({}, paymentServiceConfig));
10
- const uploadService = new upload_js_1.TurboUnauthenticatedUploadService(Object.assign({}, uploadServiceConfig));
11
- return new turbo_js_1.TurboUnauthenticatedClient({
6
+ const paymentService = new TurboUnauthenticatedPaymentService(Object.assign({}, paymentServiceConfig));
7
+ const uploadService = new TurboUnauthenticatedUploadService(Object.assign({}, uploadServiceConfig));
8
+ return new TurboUnauthenticatedClient({
12
9
  uploadService,
13
10
  paymentService,
14
11
  });
15
12
  }
16
13
  }
17
- exports.TurboBaseFactory = TurboBaseFactory;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,13 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TurboHTTPService = void 0;
13
- const axiosClient_js_1 = require("../utils/axiosClient.js");
14
- const errors_js_1 = require("../utils/errors.js");
15
- class TurboHTTPService {
10
+ import { createAxiosInstance } from '../utils/axiosClient.js';
11
+ import { FailedRequestError } from '../utils/errors.js';
12
+ export class TurboHTTPService {
16
13
  constructor({ url, retryConfig, }) {
17
- this.axios = (0, axiosClient_js_1.createAxiosInstance)({
14
+ this.axios = createAxiosInstance({
18
15
  axiosConfig: {
19
16
  baseURL: url,
20
17
  },
@@ -28,7 +25,7 @@ class TurboHTTPService {
28
25
  signal,
29
26
  });
30
27
  if (!allowedStatuses.includes(status)) {
31
- throw new errors_js_1.FailedRequestError(status, statusText);
28
+ throw new FailedRequestError(status, statusText);
32
29
  }
33
30
  return data;
34
31
  });
@@ -40,10 +37,9 @@ class TurboHTTPService {
40
37
  signal,
41
38
  });
42
39
  if (!allowedStatuses.includes(status)) {
43
- throw new errors_js_1.FailedRequestError(status, statusText);
40
+ throw new FailedRequestError(status, statusText);
44
41
  }
45
42
  return response;
46
43
  });
47
44
  }
48
45
  }
49
- exports.TurboHTTPService = TurboHTTPService;
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
1
  /**
18
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
19
3
  *
@@ -30,6 +14,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
14
  * You should have received a copy of the GNU Affero General Public License
31
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
16
  */
33
- __exportStar(require("./upload.js"), exports);
34
- __exportStar(require("./payment.js"), exports);
35
- __exportStar(require("./turbo.js"), exports);
17
+ export * from './upload.js';
18
+ export * from './payment.js';
19
+ export * from './turbo.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentService = void 0;
13
- const http_js_1 = require("./http.js");
14
- class TurboUnauthenticatedPaymentService {
10
+ import { TurboHTTPService } from './http.js';
11
+ export class TurboUnauthenticatedPaymentService {
15
12
  constructor({ url = 'https://payment.ardrive.dev', retryConfig, }) {
16
- this.httpService = new http_js_1.TurboHTTPService({
13
+ this.httpService = new TurboHTTPService({
17
14
  url: `${url}/v1`,
18
15
  retryConfig,
19
16
  });
@@ -63,9 +60,8 @@ class TurboUnauthenticatedPaymentService {
63
60
  });
64
61
  }
65
62
  }
66
- exports.TurboUnauthenticatedPaymentService = TurboUnauthenticatedPaymentService;
67
63
  // NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
68
- class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
64
+ export class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
69
65
  constructor({ url = 'https://payment.ardrive.dev', retryConfig, signer, }) {
70
66
  super({ url, retryConfig });
71
67
  this.signer = signer;
@@ -83,4 +79,3 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
83
79
  });
84
80
  }
85
81
  }
86
- exports.TurboAuthenticatedPaymentService = TurboAuthenticatedPaymentService;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TurboAuthenticatedClient = exports.TurboUnauthenticatedClient = void 0;
13
- const payment_js_1 = require("./payment.js");
14
- const upload_js_1 = require("./upload.js");
15
- class TurboUnauthenticatedClient {
16
- constructor({ uploadService = new upload_js_1.TurboUnauthenticatedUploadService({}), paymentService = new payment_js_1.TurboUnauthenticatedPaymentService({}), }) {
10
+ import { TurboUnauthenticatedPaymentService } from './payment.js';
11
+ import { TurboUnauthenticatedUploadService } from './upload.js';
12
+ export class TurboUnauthenticatedClient {
13
+ constructor({ uploadService = new TurboUnauthenticatedUploadService({}), paymentService = new TurboUnauthenticatedPaymentService({}), }) {
17
14
  this.paymentService = paymentService;
18
15
  this.uploadService = uploadService;
19
16
  }
@@ -80,8 +77,7 @@ class TurboUnauthenticatedClient {
80
77
  });
81
78
  }
82
79
  }
83
- exports.TurboUnauthenticatedClient = TurboUnauthenticatedClient;
84
- class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
80
+ export class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
85
81
  constructor({ paymentService, uploadService, }) {
86
82
  super({ paymentService, uploadService });
87
83
  }
@@ -102,4 +98,3 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
102
98
  });
103
99
  }
104
100
  }
105
- exports.TurboAuthenticatedClient = TurboAuthenticatedClient;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TurboAuthenticatedUploadService = exports.TurboUnauthenticatedUploadService = void 0;
13
- const http_js_1 = require("./http.js");
14
- class TurboUnauthenticatedUploadService {
10
+ import { TurboHTTPService } from './http.js';
11
+ export class TurboUnauthenticatedUploadService {
15
12
  constructor({ url = 'https://upload.ardrive.dev', retryConfig, }) {
16
- this.httpService = new http_js_1.TurboHTTPService({
13
+ this.httpService = new TurboHTTPService({
17
14
  url: `${url}/v1`,
18
15
  retryConfig,
19
16
  });
@@ -32,9 +29,8 @@ class TurboUnauthenticatedUploadService {
32
29
  });
33
30
  }
34
31
  }
35
- exports.TurboUnauthenticatedUploadService = TurboUnauthenticatedUploadService;
36
32
  // NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
37
- class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
33
+ export class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
38
34
  constructor({ url = 'https://upload.ardrive.dev', retryConfig, signer, }) {
39
35
  super({ url, retryConfig });
40
36
  this.signer = signer;
@@ -56,4 +52,3 @@ class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService
56
52
  });
57
53
  }
58
54
  }
59
- exports.TurboAuthenticatedUploadService = TurboAuthenticatedUploadService;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboFactory = void 0;
4
1
  /**
5
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
6
3
  *
@@ -17,18 +14,17 @@ exports.TurboFactory = void 0;
17
14
  * You should have received a copy of the GNU Affero General Public License
18
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
16
  */
20
- const factory_js_1 = require("../common/factory.js");
21
- const index_js_1 = require("../common/index.js");
22
- const signer_js_1 = require("./signer.js");
23
- class TurboFactory extends factory_js_1.TurboBaseFactory {
17
+ import { TurboBaseFactory } from '../common/factory.js';
18
+ import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, TurboAuthenticatedUploadService, } from '../common/index.js';
19
+ import { TurboNodeArweaveSigner } from './signer.js';
20
+ export class TurboFactory extends TurboBaseFactory {
24
21
  static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
25
- const signer = new signer_js_1.TurboNodeArweaveSigner({ privateKey });
26
- const paymentService = new index_js_1.TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
27
- const uploadService = new index_js_1.TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
28
- return new index_js_1.TurboAuthenticatedClient({
22
+ const signer = new TurboNodeArweaveSigner({ privateKey });
23
+ const paymentService = new TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
24
+ const uploadService = new TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
25
+ return new TurboAuthenticatedClient({
29
26
  uploadService,
30
27
  paymentService,
31
28
  });
32
29
  }
33
30
  }
34
- exports.TurboFactory = TurboFactory;
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
1
  /**
18
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
19
3
  *
@@ -30,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
14
  * You should have received a copy of the GNU Affero General Public License
31
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
16
  */
33
- __exportStar(require("./factory.js"), exports);
34
- __exportStar(require("./signer.js"), exports);
35
- __exportStar(require("../types.js"), exports);
36
- __exportStar(require("../common/index.js"), exports);
17
+ export * from './factory.js';
18
+ export * from './signer.js';
19
+ export * from '../types.js';
20
+ export * from '../common/index.js';
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,11 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.TurboNodeArweaveSigner = void 0;
16
10
  /**
17
11
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
18
12
  *
@@ -29,33 +23,32 @@ exports.TurboNodeArweaveSigner = void 0;
29
23
  * You should have received a copy of the GNU Affero General Public License
30
24
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31
25
  */
32
- const arbundles_1 = require("arbundles");
33
- const index_js_1 = __importDefault(require("arweave/node/index.js"));
34
- const node_crypto_1 = require("node:crypto");
35
- const base64_js_1 = require("../utils/base64.js");
36
- class TurboNodeArweaveSigner {
26
+ import { ArweaveSigner, streamSigner } from 'arbundles';
27
+ import Arweave from 'arweave/node/index.js';
28
+ import { randomBytes } from 'node:crypto';
29
+ import { toB64Url } from '../utils/base64.js';
30
+ export class TurboNodeArweaveSigner {
37
31
  // TODO: replace with internal signer class
38
32
  constructor({ privateKey }) {
39
33
  this.privateKey = privateKey;
40
- this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
34
+ this.signer = new ArweaveSigner(this.privateKey);
41
35
  }
42
36
  signDataItem({ fileStreamFactory, }) {
43
37
  // TODO: replace with our own signer implementation
44
38
  const [stream1, stream2] = [fileStreamFactory(), fileStreamFactory()];
45
- return (0, arbundles_1.streamSigner)(stream1, stream2, this.signer);
39
+ return streamSigner(stream1, stream2, this.signer);
46
40
  }
47
41
  // NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto
48
42
  generateSignedRequestHeaders() {
49
43
  return __awaiter(this, void 0, void 0, function* () {
50
- const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
44
+ const nonce = randomBytes(16).toString('hex');
51
45
  const buffer = Buffer.from(nonce);
52
- const signature = yield index_js_1.default.crypto.sign(this.privateKey, buffer);
46
+ const signature = yield Arweave.crypto.sign(this.privateKey, buffer);
53
47
  return {
54
48
  'x-public-key': this.privateKey.n,
55
49
  'x-nonce': nonce,
56
- 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
50
+ 'x-signature': toB64Url(Buffer.from(signature)),
57
51
  };
58
52
  });
59
53
  }
60
54
  }
61
- exports.TurboNodeArweaveSigner = TurboNodeArweaveSigner;
package/lib/esm/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,32 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.createAxiosInstance = void 0;
30
1
  /**
31
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
32
3
  *
@@ -43,24 +14,23 @@ exports.createAxiosInstance = void 0;
43
14
  * You should have received a copy of the GNU Affero General Public License
44
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
45
16
  */
46
- const axios_1 = __importStar(require("axios"));
47
- const axios_retry_1 = __importDefault(require("axios-retry"));
48
- const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
49
- retryDelay: axios_retry_1.default.exponentialDelay,
17
+ import axios, { CanceledError } from 'axios';
18
+ import axiosRetry from 'axios-retry';
19
+ export const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
20
+ retryDelay: axiosRetry.exponentialDelay,
50
21
  retries: 3,
51
22
  retryCondition: (error) => {
52
- return (!(error instanceof axios_1.CanceledError) &&
53
- axios_retry_1.default.isNetworkOrIdempotentRequestError(error));
23
+ return (!(error instanceof CanceledError) &&
24
+ axiosRetry.isNetworkOrIdempotentRequestError(error));
54
25
  },
55
26
  onRetry: (retryCount, error) => {
56
27
  console.debug(`Request failed, ${error}. Retry attempt #${retryCount}...`);
57
28
  },
58
29
  }, }) => {
59
- const axiosInstance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
30
+ const axiosInstance = axios.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
60
31
  // eslint-disable-next-line
61
32
  if (retryConfig.retries && retryConfig.retries > 0) {
62
- (0, axios_retry_1.default)(axiosInstance, retryConfig);
33
+ axiosRetry(axiosInstance, retryConfig);
63
34
  }
64
35
  return axiosInstance;
65
36
  };
66
- exports.createAxiosInstance = createAxiosInstance;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sha256B64Url = exports.toB64Url = exports.fromB64Url = exports.ownerToAddress = exports.jwkToPublicArweaveAddress = exports.base64URLRegex = void 0;
4
1
  /**
5
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
6
3
  *
@@ -17,18 +14,16 @@ exports.sha256B64Url = exports.toB64Url = exports.fromB64Url = exports.ownerToAd
17
14
  * You should have received a copy of the GNU Affero General Public License
18
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
16
  */
20
- const utils_js_1 = require("arweave/node/lib/utils.js");
21
- const crypto_1 = require("crypto");
22
- exports.base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;
23
- function jwkToPublicArweaveAddress(jwk) {
17
+ import { bufferTob64Url } from 'arweave/node/lib/utils.js';
18
+ import { createHash } from 'crypto';
19
+ export const base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;
20
+ export function jwkToPublicArweaveAddress(jwk) {
24
21
  return ownerToAddress(jwk.n);
25
22
  }
26
- exports.jwkToPublicArweaveAddress = jwkToPublicArweaveAddress;
27
- function ownerToAddress(owner) {
23
+ export function ownerToAddress(owner) {
28
24
  return sha256B64Url(fromB64Url(owner));
29
25
  }
30
- exports.ownerToAddress = ownerToAddress;
31
- function fromB64Url(input) {
26
+ export function fromB64Url(input) {
32
27
  const paddingLength = input.length % 4 === 0 ? 0 : 4 - (input.length % 4);
33
28
  const base64 = input
34
29
  .replace(/-/g, '+')
@@ -36,12 +31,9 @@ function fromB64Url(input) {
36
31
  .concat('='.repeat(paddingLength));
37
32
  return Buffer.from(base64, 'base64');
38
33
  }
39
- exports.fromB64Url = fromB64Url;
40
- function toB64Url(buffer) {
41
- return (0, utils_js_1.bufferTob64Url)(buffer);
34
+ export function toB64Url(buffer) {
35
+ return bufferTob64Url(buffer);
42
36
  }
43
- exports.toB64Url = toB64Url;
44
- function sha256B64Url(input) {
45
- return toB64Url((0, crypto_1.createHash)('sha256').update(input).digest());
37
+ export function sha256B64Url(input) {
38
+ return toB64Url(createHash('sha256').update(input).digest());
46
39
  }
47
- exports.sha256B64Url = sha256B64Url;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FailedRequestError = exports.UnauthenticatedRequestError = void 0;
4
1
  /**
5
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
6
3
  *
@@ -17,17 +14,15 @@ exports.FailedRequestError = exports.UnauthenticatedRequestError = void 0;
17
14
  * You should have received a copy of the GNU Affero General Public License
18
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
16
  */
20
- class UnauthenticatedRequestError extends Error {
17
+ export class UnauthenticatedRequestError extends Error {
21
18
  constructor() {
22
19
  super('Failed authentication. JWK is required.');
23
20
  this.name = 'UnauthenticatedRequestError';
24
21
  }
25
22
  }
26
- exports.UnauthenticatedRequestError = UnauthenticatedRequestError;
27
- class FailedRequestError extends Error {
23
+ export class FailedRequestError extends Error {
28
24
  constructor(status, message) {
29
25
  super(`Failed request: ${status}: ${message}`);
30
26
  this.name = 'FailedRequestError';
31
27
  }
32
28
  }
33
- exports.FailedRequestError = FailedRequestError;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,9 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.readableStreamToBuffer = void 0;
13
- function readableStreamToBuffer({ stream, }) {
10
+ export function readableStreamToBuffer({ stream, }) {
14
11
  return __awaiter(this, void 0, void 0, function* () {
15
12
  const reader = stream.getReader();
16
13
  const chunks = [];
@@ -25,4 +22,3 @@ function readableStreamToBuffer({ stream, }) {
25
22
  return Buffer.concat(chunks);
26
23
  });
27
24
  }
28
- exports.readableStreamToBuffer = readableStreamToBuffer;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboFactory = void 0;
4
1
  /**
5
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
6
3
  *
@@ -17,18 +14,17 @@ exports.TurboFactory = void 0;
17
14
  * You should have received a copy of the GNU Affero General Public License
18
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
16
  */
20
- const factory_js_1 = require("../common/factory.js");
21
- const index_js_1 = require("../common/index.js");
22
- const signer_js_1 = require("./signer.js");
23
- class TurboFactory extends factory_js_1.TurboBaseFactory {
17
+ import { TurboBaseFactory } from '../common/factory.js';
18
+ import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, TurboAuthenticatedUploadService, } from '../common/index.js';
19
+ import { TurboWebArweaveSigner } from './signer.js';
20
+ export class TurboFactory extends TurboBaseFactory {
24
21
  static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
25
- const signer = new signer_js_1.TurboWebArweaveSigner({ privateKey });
26
- const paymentService = new index_js_1.TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
27
- const uploadService = new index_js_1.TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
28
- return new index_js_1.TurboAuthenticatedClient({
22
+ const signer = new TurboWebArweaveSigner({ privateKey });
23
+ const paymentService = new TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
24
+ const uploadService = new TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
25
+ return new TurboAuthenticatedClient({
29
26
  uploadService,
30
27
  paymentService,
31
28
  });
32
29
  }
33
30
  }
34
- exports.TurboFactory = TurboFactory;
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
1
  /**
18
2
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
19
3
  *
@@ -30,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
14
  * You should have received a copy of the GNU Affero General Public License
31
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
16
  */
33
- __exportStar(require("./factory.js"), exports);
34
- __exportStar(require("./signer.js"), exports);
35
- __exportStar(require("../common/index.js"), exports);
36
- __exportStar(require("../types.js"), exports);
17
+ export * from './factory.js';
18
+ export * from './signer.js';
19
+ export * from '../common/index.js';
20
+ export * from '../types.js';
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,11 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.TurboWebArweaveSigner = void 0;
16
10
  /**
17
11
  * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
18
12
  *
@@ -29,24 +23,24 @@ exports.TurboWebArweaveSigner = void 0;
29
23
  * You should have received a copy of the GNU Affero General Public License
30
24
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31
25
  */
32
- const arbundles_1 = require("arbundles");
33
- const arweave_1 = __importDefault(require("arweave"));
34
- const node_crypto_1 = require("node:crypto");
35
- const base64_js_1 = require("../utils/base64.js");
36
- const readableStream_js_1 = require("../utils/readableStream.js");
37
- class TurboWebArweaveSigner {
26
+ import { ArweaveSigner, createData } from 'arbundles';
27
+ import Arweave from 'arweave';
28
+ import { randomBytes } from 'node:crypto';
29
+ import { toB64Url } from '../utils/base64.js';
30
+ import { readableStreamToBuffer } from '../utils/readableStream.js';
31
+ export class TurboWebArweaveSigner {
38
32
  constructor({ privateKey }) {
39
33
  this.privateKey = privateKey;
40
- this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
34
+ this.signer = new ArweaveSigner(this.privateKey);
41
35
  }
42
36
  signDataItem({ fileStreamFactory, }) {
43
37
  return __awaiter(this, void 0, void 0, function* () {
44
38
  // TODO: converts the readable stream to a buffer bc incrementally signing ReadableStreams is not trivial
45
- const buffer = yield (0, readableStream_js_1.readableStreamToBuffer)({
39
+ const buffer = yield readableStreamToBuffer({
46
40
  stream: fileStreamFactory(),
47
41
  // TODO: add payload size to get performance improvements
48
42
  });
49
- const signedDataItem = (0, arbundles_1.createData)(buffer, this.signer);
43
+ const signedDataItem = createData(buffer, this.signer);
50
44
  yield signedDataItem.sign(this.signer);
51
45
  return signedDataItem.getRaw();
52
46
  });
@@ -56,16 +50,15 @@ class TurboWebArweaveSigner {
56
50
  var _a;
57
51
  return __awaiter(this, void 0, void 0, function* () {
58
52
  // a bit hacky - but arweave exports cause issues in tests vs. browser
59
- const arweave = (_a = arweave_1.default.default) !== null && _a !== void 0 ? _a : arweave_1.default;
60
- const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
53
+ const arweave = (_a = Arweave.default) !== null && _a !== void 0 ? _a : Arweave;
54
+ const nonce = randomBytes(16).toString('hex');
61
55
  const buffer = Buffer.from(nonce);
62
56
  const signature = yield arweave.crypto.sign(this.privateKey, buffer, {});
63
57
  return {
64
58
  'x-public-key': this.privateKey.n,
65
59
  'x-nonce': nonce,
66
- 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
60
+ 'x-signature': toB64Url(Buffer.from(signature)),
67
61
  };
68
62
  });
69
63
  }
70
64
  }
71
- exports.TurboWebArweaveSigner = TurboWebArweaveSigner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ardrive/turbo-sdk",
3
- "version": "1.0.0-alpha.17",
3
+ "version": "1.0.0-alpha.18",
4
4
  "main": "./lib/cjs/node/index.js",
5
5
  "types": "./lib/types/node/index.d.ts",
6
6
  "module": "./lib/esm/node/index.js",