@ardrive/turbo-sdk 1.0.0-alpha.5 → 1.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/common/factory.js +17 -0
- package/lib/cjs/common/http.d.ts +44 -0
- package/lib/cjs/common/http.js +49 -0
- package/lib/cjs/common/index.js +35 -0
- package/lib/cjs/common/payment.js +86 -0
- package/lib/cjs/common/turbo.js +105 -0
- package/lib/cjs/common/upload.js +59 -0
- package/lib/cjs/node/factory.js +34 -0
- package/lib/cjs/node/index.js +36 -0
- package/lib/cjs/node/signer.d.ts +36 -0
- package/lib/cjs/node/signer.js +61 -0
- package/lib/cjs/types/arweave.js +2 -0
- package/lib/cjs/types/index.js +34 -0
- package/lib/cjs/types/turbo.d.ts +149 -0
- package/lib/cjs/types/turbo.js +2 -0
- package/lib/cjs/utils/axiosClient.js +60 -0
- package/lib/cjs/utils/base64.d.ts +9 -0
- package/lib/cjs/utils/base64.js +47 -0
- package/lib/cjs/utils/errors.js +33 -0
- package/lib/cjs/utils/readableStream.d.ts +22 -0
- package/lib/cjs/utils/readableStream.js +28 -0
- package/lib/cjs/web/factory.js +34 -0
- package/lib/cjs/web/index.js +36 -0
- package/lib/cjs/web/signer.d.ts +37 -0
- package/lib/cjs/web/signer.js +69 -0
- package/lib/esm/common/factory.d.ts +21 -0
- package/lib/esm/common/index.js +19 -0
- package/lib/esm/common/payment.d.ts +41 -0
- package/lib/esm/common/turbo.d.ts +73 -0
- package/lib/esm/common/upload.d.ts +29 -0
- package/lib/esm/node/factory.d.ts +22 -0
- package/lib/esm/types/arweave.d.ts +29 -0
- package/lib/esm/types/index.js +18 -0
- package/lib/esm/utils/axiosClient.d.ts +23 -0
- package/lib/esm/utils/errors.d.ts +22 -0
- package/lib/esm/web/factory.d.ts +22 -0
- package/lib/esm/web/index.d.ts +20 -0
- package/lib/esm/web/index.js +20 -0
- package/lib/{web → esm/web}/signer.d.ts +1 -1
- package/lib/{web → esm/web}/signer.js +4 -3
- package/package.json +4 -10
- package/bundles/web.bundle.min.js +0 -55438
- /package/lib/{common → cjs/common}/factory.d.ts +0 -0
- /package/lib/{common → cjs/common}/index.d.ts +0 -0
- /package/lib/{common → cjs/common}/payment.d.ts +0 -0
- /package/lib/{common → cjs/common}/turbo.d.ts +0 -0
- /package/lib/{common → cjs/common}/upload.d.ts +0 -0
- /package/lib/{node → cjs/node}/factory.d.ts +0 -0
- /package/lib/{node → cjs/node}/index.d.ts +0 -0
- /package/lib/{types → cjs/types}/arweave.d.ts +0 -0
- /package/lib/{types → cjs/types}/index.d.ts +0 -0
- /package/lib/{utils → cjs/utils}/axiosClient.d.ts +0 -0
- /package/lib/{utils → cjs/utils}/errors.d.ts +0 -0
- /package/lib/{web → cjs/web}/factory.d.ts +0 -0
- /package/lib/{web → cjs/web}/index.d.ts +0 -0
- /package/lib/{common → esm/common}/factory.js +0 -0
- /package/lib/{common → esm/common}/http.d.ts +0 -0
- /package/lib/{common → esm/common}/http.js +0 -0
- /package/lib/{common/index.js → esm/common/index.d.ts} +0 -0
- /package/lib/{common → esm/common}/payment.js +0 -0
- /package/lib/{common → esm/common}/turbo.js +0 -0
- /package/lib/{common → esm/common}/upload.js +0 -0
- /package/lib/{node → esm/node}/factory.js +0 -0
- /package/lib/{node/index.js → esm/node/index.d.ts} +0 -0
- /package/lib/{web → esm/node}/index.js +0 -0
- /package/lib/{node → esm/node}/signer.d.ts +0 -0
- /package/lib/{node → esm/node}/signer.js +0 -0
- /package/lib/{types → esm/types}/arweave.js +0 -0
- /package/lib/{types/index.js → esm/types/index.d.ts} +0 -0
- /package/lib/{types → esm/types}/turbo.d.ts +0 -0
- /package/lib/{types → esm/types}/turbo.js +0 -0
- /package/lib/{utils → esm/utils}/axiosClient.js +0 -0
- /package/lib/{utils → esm/utils}/base64.d.ts +0 -0
- /package/lib/{utils → esm/utils}/base64.js +0 -0
- /package/lib/{utils → esm/utils}/errors.js +0 -0
- /package/lib/{utils → esm/utils}/readableStream.d.ts +0 -0
- /package/lib/{utils → esm/utils}/readableStream.js +0 -0
- /package/lib/{web → esm/web}/factory.js +0 -0
@@ -0,0 +1,17 @@
|
|
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 {
|
8
|
+
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({
|
12
|
+
uploadService,
|
13
|
+
paymentService,
|
14
|
+
});
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.TurboBaseFactory = TurboBaseFactory;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
import { AxiosInstance } from 'axios';
|
21
|
+
import { RetryConfig } from 'retry-axios';
|
22
|
+
import { Readable } from 'stream';
|
23
|
+
import { ReadableStream } from 'stream/web';
|
24
|
+
import { TurboHTTPServiceInterface, TurboSignedRequestHeaders } from '../types/turbo.js';
|
25
|
+
export declare class TurboHTTPService implements TurboHTTPServiceInterface {
|
26
|
+
protected axios: AxiosInstance;
|
27
|
+
constructor({ url, retryConfig, }: {
|
28
|
+
url: string;
|
29
|
+
retryConfig?: RetryConfig;
|
30
|
+
});
|
31
|
+
get<T>({ endpoint, signal, allowedStatuses, headers, }: {
|
32
|
+
endpoint: string;
|
33
|
+
signal?: AbortSignal;
|
34
|
+
allowedStatuses?: number[];
|
35
|
+
headers?: Partial<TurboSignedRequestHeaders> & Record<string, string>;
|
36
|
+
}): Promise<T>;
|
37
|
+
post<T>({ endpoint, signal, allowedStatuses, headers, data, }: {
|
38
|
+
endpoint: string;
|
39
|
+
signal?: AbortSignal;
|
40
|
+
allowedStatuses?: number[];
|
41
|
+
headers?: Partial<TurboSignedRequestHeaders> & Record<string, string>;
|
42
|
+
data: Readable | Buffer | ReadableStream;
|
43
|
+
}): Promise<T>;
|
44
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
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 {
|
16
|
+
constructor({ url, retryConfig, }) {
|
17
|
+
this.axios = (0, axiosClient_js_1.createAxiosInstance)({
|
18
|
+
axiosConfig: {
|
19
|
+
baseURL: url,
|
20
|
+
},
|
21
|
+
retryConfig,
|
22
|
+
});
|
23
|
+
}
|
24
|
+
get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
26
|
+
const { status, statusText, data } = yield this.axios.get(endpoint, {
|
27
|
+
headers,
|
28
|
+
signal,
|
29
|
+
});
|
30
|
+
if (!allowedStatuses.includes(status)) {
|
31
|
+
throw new errors_js_1.FailedRequestError(status, statusText);
|
32
|
+
}
|
33
|
+
return data;
|
34
|
+
});
|
35
|
+
}
|
36
|
+
post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
38
|
+
const { status, statusText, data: response, } = yield this.axios.post(endpoint, data, {
|
39
|
+
headers,
|
40
|
+
signal,
|
41
|
+
});
|
42
|
+
if (!allowedStatuses.includes(status)) {
|
43
|
+
throw new errors_js_1.FailedRequestError(status, statusText);
|
44
|
+
}
|
45
|
+
return response;
|
46
|
+
});
|
47
|
+
}
|
48
|
+
}
|
49
|
+
exports.TurboHTTPService = TurboHTTPService;
|
@@ -0,0 +1,35 @@
|
|
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
|
+
/**
|
18
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
19
|
+
*
|
20
|
+
* This program is free software: you can redistribute it and/or modify
|
21
|
+
* it under the terms of the GNU Affero General Public License as published by
|
22
|
+
* the Free Software Foundation, either version 3 of the License, or
|
23
|
+
* (at your option) any later version.
|
24
|
+
*
|
25
|
+
* This program is distributed in the hope that it will be useful,
|
26
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28
|
+
* GNU Affero General Public License for more details.
|
29
|
+
*
|
30
|
+
* You should have received a copy of the GNU Affero General Public License
|
31
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
32
|
+
*/
|
33
|
+
__exportStar(require("./upload.js"), exports);
|
34
|
+
__exportStar(require("./payment.js"), exports);
|
35
|
+
__exportStar(require("./turbo.js"), exports);
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
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 {
|
15
|
+
constructor({ url = 'https://payment.ardrive.dev', retryConfig, }) {
|
16
|
+
this.httpService = new http_js_1.TurboHTTPService({
|
17
|
+
url: `${url}/v1`,
|
18
|
+
retryConfig,
|
19
|
+
});
|
20
|
+
}
|
21
|
+
getFiatRates() {
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
return this.httpService.get({
|
24
|
+
endpoint: '/rates',
|
25
|
+
});
|
26
|
+
});
|
27
|
+
}
|
28
|
+
getFiatToAR({ currency, }) {
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
30
|
+
return this.httpService.get({
|
31
|
+
endpoint: `/rates/${currency}`,
|
32
|
+
});
|
33
|
+
});
|
34
|
+
}
|
35
|
+
getSupportedCountries() {
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
37
|
+
return this.httpService.get({
|
38
|
+
endpoint: '/countries',
|
39
|
+
});
|
40
|
+
});
|
41
|
+
}
|
42
|
+
getSupportedCurrencies() {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
return this.httpService.get({
|
45
|
+
endpoint: '/currencies',
|
46
|
+
});
|
47
|
+
});
|
48
|
+
}
|
49
|
+
getUploadCosts({ bytes, }) {
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
51
|
+
const fetchPricePromises = bytes.map((byteCount) => this.httpService.get({
|
52
|
+
endpoint: `/price/bytes/${byteCount}`,
|
53
|
+
}));
|
54
|
+
const wincCostsForBytes = yield Promise.all(fetchPricePromises);
|
55
|
+
return wincCostsForBytes;
|
56
|
+
});
|
57
|
+
}
|
58
|
+
getWincForFiat({ amount, currency }) {
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
60
|
+
return this.httpService.get({
|
61
|
+
endpoint: `/price/${currency}/${amount}`,
|
62
|
+
});
|
63
|
+
});
|
64
|
+
}
|
65
|
+
}
|
66
|
+
exports.TurboUnauthenticatedPaymentService = TurboUnauthenticatedPaymentService;
|
67
|
+
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
|
68
|
+
class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
|
69
|
+
constructor({ url = 'https://payment.ardrive.dev', retryConfig, signer, }) {
|
70
|
+
super({ url, retryConfig });
|
71
|
+
this.signer = signer;
|
72
|
+
}
|
73
|
+
getBalance() {
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
75
|
+
const headers = yield this.signer.generateSignedRequestHeaders();
|
76
|
+
const balance = yield this.httpService.get({
|
77
|
+
endpoint: '/balance',
|
78
|
+
headers,
|
79
|
+
allowedStatuses: [200, 404],
|
80
|
+
});
|
81
|
+
// 404's don't return a balance, so default to 0
|
82
|
+
return balance.winc ? balance : { winc: '0' };
|
83
|
+
});
|
84
|
+
}
|
85
|
+
}
|
86
|
+
exports.TurboAuthenticatedPaymentService = TurboAuthenticatedPaymentService;
|
@@ -0,0 +1,105 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
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({}), }) {
|
17
|
+
this.paymentService = paymentService;
|
18
|
+
this.uploadService = uploadService;
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* Returns the supported fiat currency conversion rate for 1AR based on current market prices.
|
22
|
+
*/
|
23
|
+
getFiatToAR({ currency, }) {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
return this.paymentService.getFiatToAR({ currency });
|
26
|
+
});
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Returns the latest conversion rates to purchase 1GiB of data for all supported currencies, including all adjustments and fees.
|
30
|
+
*
|
31
|
+
* Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
|
32
|
+
* cost in 'winc' for a given number of bytes, use getUploadCosts.
|
33
|
+
*/
|
34
|
+
getFiatRates() {
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
36
|
+
return this.paymentService.getFiatRates();
|
37
|
+
});
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
|
41
|
+
*/
|
42
|
+
getSupportedCountries() {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
return this.paymentService.getSupportedCountries();
|
45
|
+
});
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Returns a list of all supported fiat currencies.
|
49
|
+
*/
|
50
|
+
getSupportedCurrencies() {
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
52
|
+
return this.paymentService.getSupportedCurrencies();
|
53
|
+
});
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
|
57
|
+
*/
|
58
|
+
getUploadCosts({ bytes, }) {
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
60
|
+
return this.paymentService.getUploadCosts({ bytes });
|
61
|
+
});
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
|
65
|
+
*/
|
66
|
+
getWincForFiat({ amount, currency, }) {
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
68
|
+
return this.paymentService.getWincForFiat({ amount, currency });
|
69
|
+
});
|
70
|
+
}
|
71
|
+
/**
|
72
|
+
* Uploads a signed data item to the Turbo Upload Service.
|
73
|
+
*/
|
74
|
+
uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
76
|
+
return this.uploadService.uploadSignedDataItem({
|
77
|
+
dataItemStreamFactory,
|
78
|
+
signal,
|
79
|
+
});
|
80
|
+
});
|
81
|
+
}
|
82
|
+
}
|
83
|
+
exports.TurboUnauthenticatedClient = TurboUnauthenticatedClient;
|
84
|
+
class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
|
85
|
+
constructor({ paymentService, uploadService, }) {
|
86
|
+
super({ paymentService, uploadService });
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Returns the current balance of the user's wallet in 'winc'.
|
90
|
+
*/
|
91
|
+
getBalance() {
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
93
|
+
return this.paymentService.getBalance();
|
94
|
+
});
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* Signs and uploads raw data to the Turbo Upload Service.
|
98
|
+
*/
|
99
|
+
uploadFile({ fileStreamFactory, signal, }) {
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
101
|
+
return this.uploadService.uploadFile({ fileStreamFactory, signal });
|
102
|
+
});
|
103
|
+
}
|
104
|
+
}
|
105
|
+
exports.TurboAuthenticatedClient = TurboAuthenticatedClient;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
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 {
|
15
|
+
constructor({ url = 'https://upload.ardrive.dev', retryConfig, }) {
|
16
|
+
this.httpService = new http_js_1.TurboHTTPService({
|
17
|
+
url: `${url}/v1`,
|
18
|
+
retryConfig,
|
19
|
+
});
|
20
|
+
}
|
21
|
+
uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
// TODO: add p-limit constraint or replace with separate upload class
|
24
|
+
return this.httpService.post({
|
25
|
+
endpoint: `/tx`,
|
26
|
+
signal,
|
27
|
+
data: dataItemStreamFactory(),
|
28
|
+
headers: {
|
29
|
+
'content-type': 'application/octet-stream',
|
30
|
+
},
|
31
|
+
});
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
35
|
+
exports.TurboUnauthenticatedUploadService = TurboUnauthenticatedUploadService;
|
36
|
+
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
|
37
|
+
class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
|
38
|
+
constructor({ url = 'https://upload.ardrive.dev', retryConfig, signer, }) {
|
39
|
+
super({ url, retryConfig });
|
40
|
+
this.signer = signer;
|
41
|
+
}
|
42
|
+
uploadFile({ fileStreamFactory, signal, }) {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
const signedDataItem = yield this.signer.signDataItem({
|
45
|
+
fileStreamFactory,
|
46
|
+
});
|
47
|
+
// TODO: add p-limit constraint or replace with separate upload class
|
48
|
+
return this.httpService.post({
|
49
|
+
endpoint: `/tx`,
|
50
|
+
signal,
|
51
|
+
data: signedDataItem,
|
52
|
+
headers: {
|
53
|
+
'content-type': 'application/octet-stream',
|
54
|
+
},
|
55
|
+
});
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
exports.TurboAuthenticatedUploadService = TurboAuthenticatedUploadService;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TurboFactory = void 0;
|
4
|
+
/**
|
5
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
|
+
*
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
10
|
+
* (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
* GNU Affero General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
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 {
|
24
|
+
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({
|
29
|
+
uploadService,
|
30
|
+
paymentService,
|
31
|
+
});
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.TurboFactory = TurboFactory;
|
@@ -0,0 +1,36 @@
|
|
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
|
+
/**
|
18
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
19
|
+
*
|
20
|
+
* This program is free software: you can redistribute it and/or modify
|
21
|
+
* it under the terms of the GNU Affero General Public License as published by
|
22
|
+
* the Free Software Foundation, either version 3 of the License, or
|
23
|
+
* (at your option) any later version.
|
24
|
+
*
|
25
|
+
* This program is distributed in the hope that it will be useful,
|
26
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28
|
+
* GNU Affero General Public License for more details.
|
29
|
+
*
|
30
|
+
* You should have received a copy of the GNU Affero General Public License
|
31
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
32
|
+
*/
|
33
|
+
__exportStar(require("./factory.js"), exports);
|
34
|
+
__exportStar(require("./signer.js"), exports);
|
35
|
+
__exportStar(require("../common/index.js"), exports);
|
36
|
+
__exportStar(require("../types/index.js"), exports);
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/**
|
3
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
4
|
+
*
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU Affero General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
import { ArweaveSigner } from 'arbundles';
|
19
|
+
import { Readable } from 'node:stream';
|
20
|
+
import { JWKInterface } from '../types/arweave.js';
|
21
|
+
import { TurboWalletSigner } from '../types/turbo.js';
|
22
|
+
export declare class TurboNodeArweaveSigner implements TurboWalletSigner {
|
23
|
+
protected privateKey: JWKInterface;
|
24
|
+
protected signer: ArweaveSigner;
|
25
|
+
constructor({ privateKey }: {
|
26
|
+
privateKey: JWKInterface;
|
27
|
+
});
|
28
|
+
signDataItem({ fileStreamFactory, }: {
|
29
|
+
fileStreamFactory: () => Readable;
|
30
|
+
}): Promise<Readable>;
|
31
|
+
generateSignedRequestHeaders(): Promise<{
|
32
|
+
'x-public-key': string;
|
33
|
+
'x-nonce': string;
|
34
|
+
'x-signature': string;
|
35
|
+
}>;
|
36
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
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;
|
16
|
+
/**
|
17
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
18
|
+
*
|
19
|
+
* This program is free software: you can redistribute it and/or modify
|
20
|
+
* it under the terms of the GNU Affero General Public License as published by
|
21
|
+
* the Free Software Foundation, either version 3 of the License, or
|
22
|
+
* (at your option) any later version.
|
23
|
+
*
|
24
|
+
* This program is distributed in the hope that it will be useful,
|
25
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
* GNU Affero General Public License for more details.
|
28
|
+
*
|
29
|
+
* You should have received a copy of the GNU Affero General Public License
|
30
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
31
|
+
*/
|
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 {
|
37
|
+
// TODO: replace with internal signer class
|
38
|
+
constructor({ privateKey }) {
|
39
|
+
this.privateKey = privateKey;
|
40
|
+
this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
|
41
|
+
}
|
42
|
+
signDataItem({ fileStreamFactory, }) {
|
43
|
+
// TODO: replace with our own signer implementation
|
44
|
+
const [stream1, stream2] = [fileStreamFactory(), fileStreamFactory()];
|
45
|
+
return (0, arbundles_1.streamSigner)(stream1, stream2, this.signer);
|
46
|
+
}
|
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
|
48
|
+
generateSignedRequestHeaders() {
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
50
|
+
const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
|
51
|
+
const buffer = Buffer.from(nonce);
|
52
|
+
const signature = yield index_js_1.default.crypto.sign(this.privateKey, buffer);
|
53
|
+
return {
|
54
|
+
'x-public-key': this.privateKey.n,
|
55
|
+
'x-nonce': nonce,
|
56
|
+
'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
|
57
|
+
};
|
58
|
+
});
|
59
|
+
}
|
60
|
+
}
|
61
|
+
exports.TurboNodeArweaveSigner = TurboNodeArweaveSigner;
|
@@ -0,0 +1,34 @@
|
|
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
|
+
/**
|
18
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
19
|
+
*
|
20
|
+
* This program is free software: you can redistribute it and/or modify
|
21
|
+
* it under the terms of the GNU Affero General Public License as published by
|
22
|
+
* the Free Software Foundation, either version 3 of the License, or
|
23
|
+
* (at your option) any later version.
|
24
|
+
*
|
25
|
+
* This program is distributed in the hope that it will be useful,
|
26
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28
|
+
* GNU Affero General Public License for more details.
|
29
|
+
*
|
30
|
+
* You should have received a copy of the GNU Affero General Public License
|
31
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
32
|
+
*/
|
33
|
+
__exportStar(require("./arweave.js"), exports);
|
34
|
+
__exportStar(require("./turbo.js"), exports);
|