@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,149 @@
|
|
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 { Readable } from 'node:stream';
|
21
|
+
import { ReadableStream } from 'node:stream/web';
|
22
|
+
import { RetryConfig } from 'retry-axios';
|
23
|
+
import winston from 'winston';
|
24
|
+
import { JWKInterface } from './arweave.js';
|
25
|
+
export type Base64String = string;
|
26
|
+
export type PublicArweaveAddress = Base64String;
|
27
|
+
export type TransactionId = Base64String;
|
28
|
+
export type UserAddress = string | PublicArweaveAddress;
|
29
|
+
export type Currency = 'usd' | 'eur' | 'gbp' | 'cad' | 'aud' | 'nzd' | 'jpy';
|
30
|
+
export type Country = 'United States' | 'United Kingdom' | 'Canada';
|
31
|
+
export type CurrencyLimit = {
|
32
|
+
minimumPaymentAmount: number;
|
33
|
+
maximumPaymentAmount: number;
|
34
|
+
suggestedPaymentAmount: number[];
|
35
|
+
zeroDecimalCurrency: boolean;
|
36
|
+
};
|
37
|
+
export type TurboPriceResponse = {
|
38
|
+
winc: string;
|
39
|
+
adjustments: any;
|
40
|
+
};
|
41
|
+
export type TurboBalanceResponse = Omit<TurboPriceResponse, 'adjustments'>;
|
42
|
+
export type TurboFiatToArResponse = {
|
43
|
+
currency: Currency;
|
44
|
+
rate: number;
|
45
|
+
};
|
46
|
+
export type TurboRatesResponse = TurboPriceResponse & Record<'fiat', Record<Currency, number>>;
|
47
|
+
export type TurboCountriesResponse = Country[];
|
48
|
+
export type TurboCurrenciesResponse = {
|
49
|
+
supportedCurrencies: Currency[];
|
50
|
+
limits: Record<Currency, CurrencyLimit>;
|
51
|
+
};
|
52
|
+
export type TurboUploadDataItemResponse = {
|
53
|
+
dataCaches: string[];
|
54
|
+
fastFinalityIndexes: string[];
|
55
|
+
id: TransactionId;
|
56
|
+
owner: PublicArweaveAddress;
|
57
|
+
};
|
58
|
+
export type TurboWallet = JWKInterface;
|
59
|
+
export type TurboSignedRequestHeaders = {
|
60
|
+
'x-public-key': string;
|
61
|
+
'x-nonce': string;
|
62
|
+
'x-signature': string;
|
63
|
+
};
|
64
|
+
type TurboAuthConfiguration = {
|
65
|
+
signer: TurboWalletSigner;
|
66
|
+
};
|
67
|
+
type TurboServiceConfiguration = {
|
68
|
+
url?: string;
|
69
|
+
retryConfig?: RetryConfig;
|
70
|
+
logger?: winston.Logger;
|
71
|
+
};
|
72
|
+
export type TurboUnauthenticatedUploadServiceInterfaceConfiguration = TurboServiceConfiguration;
|
73
|
+
export type TurboAuthenticatedUploadServiceConfiguration = TurboUnauthenticatedUploadServiceInterfaceConfiguration & TurboAuthConfiguration;
|
74
|
+
export type TurboUnauthenticatedPaymentServiceInterfaceConfiguration = TurboServiceConfiguration;
|
75
|
+
export type TurboAuthenticatedPaymentServiceInterfaceConfiguration = TurboServiceConfiguration & TurboAuthConfiguration;
|
76
|
+
export type TurboPublicConfiguration = {
|
77
|
+
paymentServiceConfig?: TurboUnauthenticatedPaymentServiceInterfaceConfiguration;
|
78
|
+
uploadServiceConfig?: TurboUnauthenticatedUploadServiceInterfaceConfiguration;
|
79
|
+
};
|
80
|
+
export type TurboPrivateConfiguration = TurboPublicConfiguration & {
|
81
|
+
privateKey: TurboWallet;
|
82
|
+
};
|
83
|
+
export type TurboPublicClientConfiguration = {
|
84
|
+
paymentService: TurboUnauthenticatedPaymentServiceInterface;
|
85
|
+
uploadService: TurboUnauthenticatedUploadServiceInterface;
|
86
|
+
};
|
87
|
+
export type TurboPrivateClientConfiguration = {
|
88
|
+
paymentService: TurboAuthenticatedPaymentServiceInterface;
|
89
|
+
uploadService: TurboAuthenticatedUploadServiceInterface;
|
90
|
+
};
|
91
|
+
export type FileStreamFactory = (() => Readable) | (() => ReadableStream) | (() => Buffer);
|
92
|
+
export type SignedDataStreamFactory = FileStreamFactory;
|
93
|
+
export type TurboFileFactory = {
|
94
|
+
fileStreamFactory: FileStreamFactory;
|
95
|
+
};
|
96
|
+
export type TurboSignedDataItemFactory = {
|
97
|
+
dataItemStreamFactory: SignedDataStreamFactory;
|
98
|
+
};
|
99
|
+
export type TurboAbortSignal = {
|
100
|
+
signal?: AbortSignal;
|
101
|
+
};
|
102
|
+
export interface TurboHTTPServiceInterface {
|
103
|
+
get<T>({ endpoint, signal, headers, allowedStatuses, }: {
|
104
|
+
endpoint: string;
|
105
|
+
signal?: AbortSignal;
|
106
|
+
headers?: Partial<TurboSignedRequestHeaders> & Record<string, string>;
|
107
|
+
allowedStatuses?: number[];
|
108
|
+
}): Promise<T>;
|
109
|
+
post<T>({ endpoint, signal, headers, allowedStatuses, data, }: {
|
110
|
+
endpoint: string;
|
111
|
+
signal: AbortSignal;
|
112
|
+
headers?: Partial<TurboSignedRequestHeaders> & Record<string, string>;
|
113
|
+
allowedStatuses?: number[];
|
114
|
+
data: Readable | ReadableStream | Buffer;
|
115
|
+
}): Promise<T>;
|
116
|
+
}
|
117
|
+
export interface TurboWalletSigner {
|
118
|
+
signDataItem({ fileStreamFactory, }: TurboFileFactory): Promise<Readable> | Promise<Buffer>;
|
119
|
+
generateSignedRequestHeaders(): Promise<TurboSignedRequestHeaders>;
|
120
|
+
}
|
121
|
+
export interface TurboUnauthenticatedPaymentServiceInterface {
|
122
|
+
getSupportedCurrencies(): Promise<TurboCurrenciesResponse>;
|
123
|
+
getSupportedCountries(): Promise<TurboCountriesResponse>;
|
124
|
+
getFiatToAR({ currency, }: {
|
125
|
+
currency: Currency;
|
126
|
+
}): Promise<TurboFiatToArResponse>;
|
127
|
+
getFiatRates(): Promise<TurboRatesResponse>;
|
128
|
+
getWincForFiat({ amount, currency, }: {
|
129
|
+
amount: number;
|
130
|
+
currency: Currency;
|
131
|
+
}): Promise<Omit<TurboPriceResponse, 'adjustments'>>;
|
132
|
+
getUploadCosts({ bytes }: {
|
133
|
+
bytes: number[];
|
134
|
+
}): Promise<TurboPriceResponse[]>;
|
135
|
+
}
|
136
|
+
export interface TurboAuthenticatedPaymentServiceInterface extends TurboUnauthenticatedPaymentServiceInterface {
|
137
|
+
getBalance: () => Promise<TurboBalanceResponse>;
|
138
|
+
}
|
139
|
+
export interface TurboUnauthenticatedUploadServiceInterface {
|
140
|
+
uploadSignedDataItem({ dataItemStreamFactory, signal, }: TurboSignedDataItemFactory & TurboAbortSignal): Promise<TurboUploadDataItemResponse>;
|
141
|
+
}
|
142
|
+
export interface TurboAuthenticatedUploadServiceInterface extends TurboUnauthenticatedUploadServiceInterface {
|
143
|
+
uploadFile({ fileStreamFactory, }: TurboFileFactory & TurboAbortSignal): Promise<TurboUploadDataItemResponse>;
|
144
|
+
}
|
145
|
+
export interface TurboUnauthenticatedClientInterface extends TurboUnauthenticatedPaymentServiceInterface, TurboUnauthenticatedUploadServiceInterface {
|
146
|
+
}
|
147
|
+
export interface TurboAuthenticatedClientInterface extends TurboAuthenticatedPaymentServiceInterface, TurboAuthenticatedUploadServiceInterface {
|
148
|
+
}
|
149
|
+
export {};
|
@@ -0,0 +1,60 @@
|
|
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
|
+
/**
|
31
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
32
|
+
*
|
33
|
+
* This program is free software: you can redistribute it and/or modify
|
34
|
+
* it under the terms of the GNU Affero General Public License as published by
|
35
|
+
* the Free Software Foundation, either version 3 of the License, or
|
36
|
+
* (at your option) any later version.
|
37
|
+
*
|
38
|
+
* This program is distributed in the hope that it will be useful,
|
39
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
40
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
41
|
+
* GNU Affero General Public License for more details.
|
42
|
+
*
|
43
|
+
* You should have received a copy of the GNU Affero General Public License
|
44
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
45
|
+
*/
|
46
|
+
const axios_1 = __importDefault(require("axios"));
|
47
|
+
const rax = __importStar(require("retry-axios"));
|
48
|
+
const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
|
49
|
+
backoffType: 'exponential',
|
50
|
+
retry: 3,
|
51
|
+
onRetryAttempt: (err) => {
|
52
|
+
const cfg = rax.getConfig(err);
|
53
|
+
console.debug(`Retry attempt #${cfg === null || cfg === void 0 ? void 0 : cfg.currentRetryAttempt}`);
|
54
|
+
},
|
55
|
+
}, }) => {
|
56
|
+
const axiosInstance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
|
57
|
+
axiosInstance.defaults.raxConfig = Object.assign({ instance: axiosInstance }, retryConfig);
|
58
|
+
return axiosInstance;
|
59
|
+
};
|
60
|
+
exports.createAxiosInstance = createAxiosInstance;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { JWKInterface } from '../types/index.js';
|
3
|
+
import { Base64String, PublicArweaveAddress } from '../types/index.js';
|
4
|
+
export declare const base64URLRegex: RegExp;
|
5
|
+
export declare function jwkToPublicArweaveAddress(jwk: JWKInterface): PublicArweaveAddress;
|
6
|
+
export declare function ownerToAddress(owner: Base64String): PublicArweaveAddress;
|
7
|
+
export declare function fromB64Url(input: Base64String): Buffer;
|
8
|
+
export declare function toB64Url(buffer: Buffer): Base64String;
|
9
|
+
export declare function sha256B64Url(input: Buffer): Base64String;
|
@@ -0,0 +1,47 @@
|
|
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
|
+
/**
|
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 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) {
|
24
|
+
return ownerToAddress(jwk.n);
|
25
|
+
}
|
26
|
+
exports.jwkToPublicArweaveAddress = jwkToPublicArweaveAddress;
|
27
|
+
function ownerToAddress(owner) {
|
28
|
+
return sha256B64Url(fromB64Url(owner));
|
29
|
+
}
|
30
|
+
exports.ownerToAddress = ownerToAddress;
|
31
|
+
function fromB64Url(input) {
|
32
|
+
const paddingLength = input.length % 4 === 0 ? 0 : 4 - (input.length % 4);
|
33
|
+
const base64 = input
|
34
|
+
.replace(/-/g, '+')
|
35
|
+
.replace(/_/g, '/')
|
36
|
+
.concat('='.repeat(paddingLength));
|
37
|
+
return Buffer.from(base64, 'base64');
|
38
|
+
}
|
39
|
+
exports.fromB64Url = fromB64Url;
|
40
|
+
function toB64Url(buffer) {
|
41
|
+
return (0, utils_js_1.bufferTob64Url)(buffer);
|
42
|
+
}
|
43
|
+
exports.toB64Url = toB64Url;
|
44
|
+
function sha256B64Url(input) {
|
45
|
+
return toB64Url((0, crypto_1.createHash)('sha256').update(input).digest());
|
46
|
+
}
|
47
|
+
exports.sha256B64Url = sha256B64Url;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FailedRequestError = exports.UnauthenticatedRequestError = 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
|
+
class UnauthenticatedRequestError extends Error {
|
21
|
+
constructor() {
|
22
|
+
super('Failed authentication. JWK is required.');
|
23
|
+
this.name = 'UnauthenticatedRequestError';
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.UnauthenticatedRequestError = UnauthenticatedRequestError;
|
27
|
+
class FailedRequestError extends Error {
|
28
|
+
constructor(status, message) {
|
29
|
+
super(`Failed request: ${status}: ${message}`);
|
30
|
+
this.name = 'FailedRequestError';
|
31
|
+
}
|
32
|
+
}
|
33
|
+
exports.FailedRequestError = FailedRequestError;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/**
|
4
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
5
|
+
*
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
7
|
+
* it under the terms of the GNU Affero General Public License as published by
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
9
|
+
* (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
* GNU Affero General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Affero General Public License
|
17
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
import { ReadableStream } from 'node:stream/web';
|
20
|
+
export declare function readableStreamToBuffer({ stream, }: {
|
21
|
+
stream: ReadableStream;
|
22
|
+
}): Promise<Buffer>;
|
@@ -0,0 +1,28 @@
|
|
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.readableStreamToBuffer = void 0;
|
13
|
+
function readableStreamToBuffer({ stream, }) {
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
15
|
+
const reader = stream.getReader();
|
16
|
+
const chunks = [];
|
17
|
+
let done = false;
|
18
|
+
while (!done) {
|
19
|
+
const { done: streamDone, value } = yield reader.read();
|
20
|
+
done = streamDone;
|
21
|
+
if (!done) {
|
22
|
+
chunks.push(value);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return Buffer.concat(chunks);
|
26
|
+
});
|
27
|
+
}
|
28
|
+
exports.readableStreamToBuffer = readableStreamToBuffer;
|
@@ -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.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({
|
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,37 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/**
|
4
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
5
|
+
*
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
7
|
+
* it under the terms of the GNU Affero General Public License as published by
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
9
|
+
* (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
* GNU Affero General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Affero General Public License
|
17
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
import { ArweaveSigner } from 'arbundles';
|
20
|
+
import { ReadableStream } from 'node:stream/web';
|
21
|
+
import { JWKInterface } from '../types/arweave.js';
|
22
|
+
import { TurboWalletSigner } from '../types/turbo.js';
|
23
|
+
export declare class TurboWebArweaveSigner implements TurboWalletSigner {
|
24
|
+
protected privateKey: JWKInterface;
|
25
|
+
protected signer: ArweaveSigner;
|
26
|
+
constructor({ privateKey }: {
|
27
|
+
privateKey: JWKInterface;
|
28
|
+
});
|
29
|
+
signDataItem({ fileStreamFactory, }: {
|
30
|
+
fileStreamFactory: () => ReadableStream;
|
31
|
+
}): Promise<Buffer>;
|
32
|
+
generateSignedRequestHeaders(): Promise<{
|
33
|
+
'x-public-key': string;
|
34
|
+
'x-nonce': string;
|
35
|
+
'x-signature': string;
|
36
|
+
}>;
|
37
|
+
}
|
@@ -0,0 +1,69 @@
|
|
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.TurboWebArweaveSigner = 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 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 {
|
38
|
+
constructor({ privateKey }) {
|
39
|
+
this.privateKey = privateKey;
|
40
|
+
this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
|
41
|
+
}
|
42
|
+
signDataItem({ fileStreamFactory, }) {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
// TODO: converts the readable stream to a buffer bc incrementally signing ReadableStreams is not trivial
|
45
|
+
const buffer = yield (0, readableStream_js_1.readableStreamToBuffer)({
|
46
|
+
stream: fileStreamFactory(),
|
47
|
+
// TODO: add payload size to get performance improvements
|
48
|
+
});
|
49
|
+
const signedDataItem = (0, arbundles_1.createData)(buffer, this.signer);
|
50
|
+
yield signedDataItem.sign(this.signer);
|
51
|
+
return signedDataItem.getRaw();
|
52
|
+
});
|
53
|
+
}
|
54
|
+
// 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
|
55
|
+
generateSignedRequestHeaders() {
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
57
|
+
const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
|
58
|
+
const buffer = Buffer.from(nonce);
|
59
|
+
// a bit hacky - but easiest way to solve web signing issues while still building for cjs
|
60
|
+
const signature = yield arweave_1.default.default.crypto.sign(this.privateKey, buffer, {});
|
61
|
+
return {
|
62
|
+
'x-public-key': this.privateKey.n,
|
63
|
+
'x-nonce': nonce,
|
64
|
+
'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
|
65
|
+
};
|
66
|
+
});
|
67
|
+
}
|
68
|
+
}
|
69
|
+
exports.TurboWebArweaveSigner = TurboWebArweaveSigner;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { TurboPublicConfiguration } from '../types/turbo.js';
|
18
|
+
import { TurboUnauthenticatedClient } from './turbo.js';
|
19
|
+
export declare class TurboBaseFactory {
|
20
|
+
static unauthenticated({ paymentServiceConfig, uploadServiceConfig, }?: TurboPublicConfiguration): TurboUnauthenticatedClient;
|
21
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
export * from './upload.js';
|
18
|
+
export * from './payment.js';
|
19
|
+
export * from './turbo.js';
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { Currency, TurboAuthenticatedPaymentServiceInterface, TurboAuthenticatedPaymentServiceInterfaceConfiguration, TurboBalanceResponse, TurboCountriesResponse, TurboCurrenciesResponse, TurboFiatToArResponse, TurboPriceResponse, TurboRatesResponse, TurboUnauthenticatedPaymentServiceInterface, TurboUnauthenticatedPaymentServiceInterfaceConfiguration, TurboWalletSigner } from '../types/turbo.js';
|
18
|
+
import { TurboHTTPService } from './http.js';
|
19
|
+
export declare class TurboUnauthenticatedPaymentService implements TurboUnauthenticatedPaymentServiceInterface {
|
20
|
+
protected readonly httpService: TurboHTTPService;
|
21
|
+
constructor({ url, retryConfig, }: TurboUnauthenticatedPaymentServiceInterfaceConfiguration);
|
22
|
+
getFiatRates(): Promise<TurboRatesResponse>;
|
23
|
+
getFiatToAR({ currency, }: {
|
24
|
+
currency: Currency;
|
25
|
+
}): Promise<TurboFiatToArResponse>;
|
26
|
+
getSupportedCountries(): Promise<TurboCountriesResponse>;
|
27
|
+
getSupportedCurrencies(): Promise<TurboCurrenciesResponse>;
|
28
|
+
getUploadCosts({ bytes, }: {
|
29
|
+
bytes: number[];
|
30
|
+
}): Promise<TurboPriceResponse[]>;
|
31
|
+
getWincForFiat({ amount, currency }: {
|
32
|
+
amount: any;
|
33
|
+
currency: any;
|
34
|
+
}): Promise<TurboPriceResponse>;
|
35
|
+
}
|
36
|
+
export declare class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService implements TurboAuthenticatedPaymentServiceInterface {
|
37
|
+
protected readonly httpService: TurboHTTPService;
|
38
|
+
protected readonly signer: TurboWalletSigner;
|
39
|
+
constructor({ url, retryConfig, signer, }: TurboAuthenticatedPaymentServiceInterfaceConfiguration);
|
40
|
+
getBalance(): Promise<TurboBalanceResponse>;
|
41
|
+
}
|