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

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