@ardrive/turbo-sdk 1.0.0-alpha.2 → 1.0.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/bundles/web.bundle.min.js +277 -38
  2. package/lib/cjs/common/factory.js +21 -0
  3. package/lib/cjs/common/http.js +36 -0
  4. package/lib/cjs/common/index.js +35 -0
  5. package/lib/cjs/common/jwk.js +2 -0
  6. package/lib/cjs/common/payment.js +63 -0
  7. package/lib/cjs/common/turbo.js +78 -0
  8. package/lib/cjs/common/upload.js +46 -0
  9. package/lib/cjs/node/factory.js +40 -0
  10. package/lib/cjs/node/index.js +36 -0
  11. package/lib/cjs/node/signer.js +50 -0
  12. package/lib/cjs/package.json +1 -0
  13. package/lib/cjs/types.js +2 -0
  14. package/lib/cjs/utils/axiosClient.js +69 -0
  15. package/lib/cjs/utils/base64.js +47 -0
  16. package/lib/cjs/utils/errors.js +33 -0
  17. package/lib/cjs/utils/readableStream.js +17 -0
  18. package/lib/cjs/web/factory.js +40 -0
  19. package/lib/cjs/web/index.js +36 -0
  20. package/lib/cjs/web/signer.js +57 -0
  21. package/lib/{common → esm/common}/factory.js +6 -2
  22. package/lib/esm/common/http.js +32 -0
  23. package/lib/esm/common/payment.js +58 -0
  24. package/lib/esm/common/turbo.js +73 -0
  25. package/lib/esm/common/upload.js +41 -0
  26. package/lib/{node → esm/node}/factory.js +8 -2
  27. package/lib/{web → esm/node}/index.js +1 -0
  28. package/lib/{node → esm/node}/signer.js +9 -20
  29. package/lib/{utils → esm/utils}/axiosClient.js +18 -9
  30. package/lib/esm/utils/readableStream.js +13 -0
  31. package/lib/{web → esm/web}/factory.js +8 -2
  32. package/lib/{node → esm/web}/index.js +1 -0
  33. package/lib/esm/web/signer.js +50 -0
  34. package/lib/{common → types/common}/factory.d.ts +2 -1
  35. package/lib/types/common/factory.d.ts.map +1 -0
  36. package/lib/{common → types/common}/http.d.ts +7 -6
  37. package/lib/types/common/http.d.ts.map +1 -0
  38. package/lib/{common → types/common}/index.d.ts +1 -0
  39. package/lib/types/common/index.d.ts.map +1 -0
  40. package/lib/types/{arweave.d.ts → common/jwk.d.ts} +1 -0
  41. package/lib/types/common/jwk.d.ts.map +1 -0
  42. package/lib/{common → types/common}/payment.d.ts +2 -2
  43. package/lib/types/common/payment.d.ts.map +1 -0
  44. package/lib/{common → types/common}/turbo.d.ts +6 -5
  45. package/lib/types/common/turbo.d.ts.map +1 -0
  46. package/lib/{common → types/common}/upload.d.ts +2 -2
  47. package/lib/types/common/upload.d.ts.map +1 -0
  48. package/lib/{node → types/node}/factory.d.ts +2 -1
  49. package/lib/types/node/factory.d.ts.map +1 -0
  50. package/lib/{web → types/node}/index.d.ts +2 -0
  51. package/lib/types/node/index.d.ts.map +1 -0
  52. package/lib/{node → types/node}/signer.d.ts +4 -3
  53. package/lib/types/node/signer.d.ts.map +1 -0
  54. package/lib/types/{turbo.d.ts → types.d.ts} +7 -6
  55. package/lib/types/types.d.ts.map +1 -0
  56. package/lib/{utils → types/utils}/axiosClient.d.ts +3 -2
  57. package/lib/types/utils/axiosClient.d.ts.map +1 -0
  58. package/lib/{utils → types/utils}/base64.d.ts +4 -3
  59. package/lib/types/utils/base64.d.ts.map +1 -0
  60. package/lib/{utils → types/utils}/errors.d.ts +1 -0
  61. package/lib/types/utils/errors.d.ts.map +1 -0
  62. package/lib/{utils → types/utils}/readableStream.d.ts +3 -2
  63. package/lib/types/utils/readableStream.d.ts.map +1 -0
  64. package/lib/{web → types/web}/factory.d.ts +2 -1
  65. package/lib/types/web/factory.d.ts.map +1 -0
  66. package/lib/{node → types/web}/index.d.ts +2 -0
  67. package/lib/types/web/index.d.ts.map +1 -0
  68. package/lib/{web → types/web}/signer.d.ts +6 -5
  69. package/lib/types/web/signer.d.ts.map +1 -0
  70. package/package.json +19 -16
  71. package/lib/LICENSE.md +0 -661
  72. package/lib/README.md +0 -114
  73. package/lib/common/http.js +0 -45
  74. package/lib/common/payment.js +0 -81
  75. package/lib/common/turbo.js +0 -100
  76. package/lib/common/upload.js +0 -54
  77. package/lib/package.json +0 -105
  78. package/lib/types/index.d.ts +0 -18
  79. package/lib/types/index.js +0 -18
  80. package/lib/utils/readableStream.js +0 -24
  81. package/lib/web/signer.js +0 -61
  82. /package/lib/{common → esm/common}/index.js +0 -0
  83. /package/lib/{types/arweave.js → esm/common/jwk.js} +0 -0
  84. /package/lib/{types/turbo.js → esm/types.js} +0 -0
  85. /package/lib/{utils → esm/utils}/base64.js +0 -0
  86. /package/lib/{utils → esm/utils}/errors.js +0 -0
package/lib/README.md DELETED
@@ -1,114 +0,0 @@
1
- # @ardriveapp/turbo-sdk 🚀
2
-
3
- Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionalities for interacting with the Turbo Upload and Payment Services. It is available in both NodeJS and Web environments.
4
-
5
- ## Table of Contents
6
-
7
- - [Installation](#installation)
8
- - [Usage](#usage):
9
-
10
- - [NodeJS Environments](#nodejs)
11
- - [CommonJS](#commonjs)
12
- - [ESM](#esm)
13
- - [Web Environments](#web)
14
- - [Bundlers (Webpack, Rollup, ESbuild, etc.)](#bundlers-webpack-rollup-esbuild-etc)
15
- - [Browser](#browser)
16
- - [Typescript](#typescript)
17
- - [Examples](./examples)
18
-
19
- - [Contributions](#contributions)
20
-
21
- ## Installation
22
-
23
- ```shell
24
- npm install @ardrive/turbo-sdk
25
- ```
26
-
27
- or
28
-
29
- ```shell
30
- yarn add @ardrive/turbo-sdk
31
- ```
32
-
33
- ## Usage
34
-
35
- The SDK is available in both CommonJS and ESM formats and is compatible with bundlers such as Webpack, Rollup, and ESbuild.
36
-
37
- ### Web
38
-
39
- #### Bundlers (Webpack, Rollup, ESbuild, etc.)
40
-
41
- ```javascript
42
- import { TurboFactory } from '@ardrive/turbo-sdk/web';
43
-
44
- const turbo = TurboFactory.unauthenticated({});
45
- const rates = await turbo.getFiatRates();
46
- ```
47
-
48
- #### Browser
49
-
50
- ```html
51
- <script src="https://cdn.jsdelivr.net/npm/@ardrive/turbo-sdk"></script>
52
- <script>
53
- const turbo = TurboFactory.unauthenticated({});
54
- const rates = await turbo.getFiatRates();
55
- </script>
56
- ```
57
-
58
- ### NodeJS
59
-
60
- #### CommonJS
61
-
62
- ```javascript
63
- const { TurboFactory } = require('@ardrive/turbo-sdk/node');
64
-
65
- const turbo = TurboFactory.unauthenticated({});
66
- const rates = await turbo.getFiatRates();
67
- ```
68
-
69
- ### ESM
70
-
71
- ```javascript
72
- import { TurboFactory } from '@ardrive/turbo-sdk/node';
73
-
74
- const turbo = TurboFactory.unauthenticated({});
75
- const rates = await turbo.getFiatRates();
76
- ```
77
-
78
- ### Typescript
79
-
80
- The SDK provides TypeScript typings. When you import the SDK in a TypeScript project:
81
-
82
- ```typescript
83
- import Ardrive from '@ardrive/turbo-sdk/web';
84
-
85
- // or '@ardrive/turbo-sdk/node' for Node.js projects
86
- ```
87
-
88
- The provided typings (`./lib/types/index.d.ts`) will be automatically recognized, offering type checking and autocompletion benefits.
89
-
90
- ## APIs (WIP)
91
-
92
- ### TurboFactory
93
-
94
- - `public()`
95
- - `private()`
96
-
97
- ### TurboUnauthenticatedClient
98
-
99
- - `getFiatRates()`
100
- - `getFiatToAR()`
101
- - `getSupportedCountries()`
102
- - `getSupportedCurrencies()`
103
- - `getWincForFiat()`
104
- - `getUploadCosts()`
105
- - `uploadSignedDataItem()`
106
-
107
- ### TurboAuthenticatedClient
108
-
109
- - `getBalance()`
110
- - `uploadFile()`
111
-
112
- ## Contributions
113
-
114
- If you encounter any issues or have feature requests, please file an issue on our GitHub repository. Contributions, pull requests, and feedback are welcome and encouraged.
@@ -1,45 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { createAxiosInstance } from '../utils/axiosClient.js';
11
- import { FailedRequestError } from '../utils/errors.js';
12
- export class TurboHTTPService {
13
- constructor({ url, retryConfig, }) {
14
- this.axios = createAxiosInstance({
15
- axiosConfig: {
16
- baseURL: url,
17
- },
18
- retryConfig,
19
- });
20
- }
21
- get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { status, statusText, data } = yield this.axios.get(endpoint, {
24
- headers,
25
- signal,
26
- });
27
- if (!allowedStatuses.includes(status)) {
28
- throw new FailedRequestError(status, statusText);
29
- }
30
- return data;
31
- });
32
- }
33
- post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const { status, statusText, data: response, } = yield this.axios.post(endpoint, data, {
36
- headers,
37
- signal,
38
- });
39
- if (!allowedStatuses.includes(status)) {
40
- throw new FailedRequestError(status, statusText);
41
- }
42
- return response;
43
- });
44
- }
45
- }
@@ -1,81 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { TurboHTTPService } from './http.js';
11
- export class TurboUnauthenticatedPaymentService {
12
- constructor({ url = 'https://payment.ardrive.dev', retryConfig, }) {
13
- this.httpService = new TurboHTTPService({
14
- url: `${url}/v1`,
15
- retryConfig,
16
- });
17
- }
18
- getFiatRates() {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return this.httpService.get({
21
- endpoint: '/rates',
22
- });
23
- });
24
- }
25
- getFiatToAR({ currency, }) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- return this.httpService.get({
28
- endpoint: `/rates/${currency}`,
29
- });
30
- });
31
- }
32
- getSupportedCountries() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- return this.httpService.get({
35
- endpoint: '/countries',
36
- });
37
- });
38
- }
39
- getSupportedCurrencies() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return this.httpService.get({
42
- endpoint: '/currencies',
43
- });
44
- });
45
- }
46
- getUploadCosts({ bytes, }) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const fetchPricePromises = bytes.map((byteCount) => this.httpService.get({
49
- endpoint: `/price/bytes/${byteCount}`,
50
- }));
51
- const wincCostsForBytes = yield Promise.all(fetchPricePromises);
52
- return wincCostsForBytes;
53
- });
54
- }
55
- getWincForFiat({ amount, currency }) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- return this.httpService.get({
58
- endpoint: `/price/${currency}/${amount}`,
59
- });
60
- });
61
- }
62
- }
63
- // NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
64
- export class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
65
- constructor({ url = 'https://payment.ardrive.dev', retryConfig, signer, }) {
66
- super({ url, retryConfig });
67
- this.signer = signer;
68
- }
69
- getBalance() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const headers = yield this.signer.generateSignedRequestHeaders();
72
- const balance = yield this.httpService.get({
73
- endpoint: '/balance',
74
- headers,
75
- allowedStatuses: [200, 404],
76
- });
77
- // 404's don't return a balance, so default to 0
78
- return balance.winc ? balance : { winc: '0' };
79
- });
80
- }
81
- }
@@ -1,100 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { TurboUnauthenticatedPaymentService } from './payment.js';
11
- import { TurboUnauthenticatedUploadService } from './upload.js';
12
- export class TurboUnauthenticatedClient {
13
- constructor({ uploadService = new TurboUnauthenticatedUploadService({}), paymentService = new TurboUnauthenticatedPaymentService({}), }) {
14
- this.paymentService = paymentService;
15
- this.uploadService = uploadService;
16
- }
17
- /**
18
- * Returns the supported fiat currency conversion rate for 1AR based on current market prices.
19
- */
20
- getFiatToAR({ currency, }) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- return this.paymentService.getFiatToAR({ currency });
23
- });
24
- }
25
- /**
26
- * Returns the latest conversion rates to purchase 1GiB of data for all supported currencies, including all adjustments and fees.
27
- *
28
- * Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
29
- * cost in 'winc' for a given number of bytes, use getUploadCosts.
30
- */
31
- getFiatRates() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return this.paymentService.getFiatRates();
34
- });
35
- }
36
- /**
37
- * Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
38
- */
39
- getSupportedCountries() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return this.paymentService.getSupportedCountries();
42
- });
43
- }
44
- /**
45
- * Returns a list of all supported fiat currencies.
46
- */
47
- getSupportedCurrencies() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- return this.paymentService.getSupportedCurrencies();
50
- });
51
- }
52
- /**
53
- * Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
54
- */
55
- getUploadCosts({ bytes, }) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- return this.paymentService.getUploadCosts({ bytes });
58
- });
59
- }
60
- /**
61
- * Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
62
- */
63
- getWincForFiat({ amount, currency, }) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- return this.paymentService.getWincForFiat({ amount, currency });
66
- });
67
- }
68
- /**
69
- * Uploads a signed data item to the Turbo Upload Service.
70
- */
71
- uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- return this.uploadService.uploadSignedDataItem({
74
- dataItemStreamFactory,
75
- signal,
76
- });
77
- });
78
- }
79
- }
80
- export class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
81
- constructor({ paymentService, uploadService, }) {
82
- super({ paymentService, uploadService });
83
- }
84
- /**
85
- * Returns the current balance of the user's wallet in 'winc'.
86
- */
87
- getBalance() {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- return this.paymentService.getBalance();
90
- });
91
- }
92
- /**
93
- * Signs and uploads raw data to the Turbo Upload Service.
94
- */
95
- uploadFile({ fileStreamFactory, signal, }) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return this.uploadService.uploadFile({ fileStreamFactory, signal });
98
- });
99
- }
100
- }
@@ -1,54 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { TurboHTTPService } from './http.js';
11
- export class TurboUnauthenticatedUploadService {
12
- constructor({ url = 'https://upload.ardrive.dev', retryConfig, }) {
13
- this.httpService = new TurboHTTPService({
14
- url: `${url}/v1`,
15
- retryConfig,
16
- });
17
- }
18
- uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- // TODO: add p-limit constraint or replace with separate upload class
21
- return this.httpService.post({
22
- endpoint: `/tx`,
23
- signal,
24
- data: dataItemStreamFactory(),
25
- headers: {
26
- 'content-type': 'application/octet-stream',
27
- },
28
- });
29
- });
30
- }
31
- }
32
- // NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
33
- export class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
34
- constructor({ url = 'https://upload.ardrive.dev', retryConfig, signer, }) {
35
- super({ url, retryConfig });
36
- this.signer = signer;
37
- }
38
- uploadFile({ fileStreamFactory, signal, }) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const signedDataItem = yield this.signer.signDataItem({
41
- fileStreamFactory,
42
- });
43
- // TODO: add p-limit constraint or replace with separate upload class
44
- return this.httpService.post({
45
- endpoint: `/tx`,
46
- signal,
47
- data: signedDataItem,
48
- headers: {
49
- 'content-type': 'application/octet-stream',
50
- },
51
- });
52
- });
53
- }
54
- }
package/lib/package.json DELETED
@@ -1,105 +0,0 @@
1
- {
2
- "name": "@ardrive/turbo-sdk",
3
- "version": "1.0.0-alpha.1",
4
- "main": "./lib/node/index.js",
5
- "types": "./lib/types/index.d.ts",
6
- "type": "module",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/ardriveapp/turbo-sdk.git"
10
- },
11
- "files": [
12
- "lib",
13
- "bundles",
14
- "LICENSE",
15
- "README.md"
16
- ],
17
- "author": {
18
- "name": "Permanent Data Solutions Inc",
19
- "email": "info@ardrive.io",
20
- "website": "https://ardrive.io"
21
- },
22
- "exports": {
23
- ".": {
24
- "import": "./lib/node/index.js",
25
- "require": "./lib/node/index.js",
26
- "types": "./lib/types/index.d.ts",
27
- "browser": "./bundles/web.bundle.min.js"
28
- },
29
- "./node": {
30
- "import": "./lib/node/index.js",
31
- "require": "./lib/node/index.js",
32
- "types": "./lib/types/index.d.ts"
33
- },
34
- "./web": {
35
- "import": "./lib/web/index.js",
36
- "require": "./lib/web/index.js",
37
- "types": "./lib/types/index.d.ts",
38
- "browser": "./bundles/web.bundle.min.js"
39
- }
40
- },
41
- "engines": {
42
- "node": ">=18"
43
- },
44
- "license": "AGPL-3.0-or-later",
45
- "scripts": {
46
- "build:web": "node bundle.cjs",
47
- "build:esm": "yarn tsc -p tsconfig.node.json && yarn tsc -p tsconfig.web.json && cp package.json README.md LICENSE.md ./lib",
48
- "build": "yarn clean && yarn build:web && yarn build:esm",
49
- "clean": "rimraf [ lib coverage bundles ]",
50
- "lint": "eslint src",
51
- "lint:fix": "eslint src --fix",
52
- "format": "prettier --check .",
53
- "format:fix": "prettier --write .",
54
- "test": "c8 mocha --config .mocharc --exit",
55
- "test:web": "c8 mocha --config .mocharc --exclude tests/**/*.node.test.ts --exit",
56
- "test:node": "c8 mocha --config .mocharc --exclude tests/**/*.web.test.ts --exit",
57
- "prepare": "husky install",
58
- "example:mjs": "yarn build:esm && node examples/node/index.mjs",
59
- "example:cjs": "yarn build:esm && node examples/node/index.cjs",
60
- "example:web": "yarn build:web && cp -r bundles/* examples/web && http-server --port 8080 --host -o examples/web"
61
- },
62
- "dependencies": {
63
- "arbundles": "^0.9.9",
64
- "arweave": "^1.14.4",
65
- "axios": "^1.4.0",
66
- "retry-axios": "^3.0.0",
67
- "winston": "^3.10.0"
68
- },
69
- "devDependencies": {
70
- "@commitlint/cli": "^17.1.2",
71
- "@commitlint/config-conventional": "^17.1.0",
72
- "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
73
- "@semantic-release/changelog": "^6.0.3",
74
- "@semantic-release/git": "^10.0.1",
75
- "@trivago/prettier-plugin-sort-imports": "^4.2.0",
76
- "@types/chai": "^4.3.5",
77
- "@types/mocha": "^10.0.1",
78
- "@types/node": "^20.4.8",
79
- "@types/sinon": "^10.0.15",
80
- "@typescript-eslint/eslint-plugin": "^5.62.0",
81
- "@typescript-eslint/parser": "^6.4.0",
82
- "c8": "^8.0.1",
83
- "chai": "^4.3.7",
84
- "esbuild": "^0.19.2",
85
- "eslint": "^8.47.0",
86
- "eslint-config-prettier": "^9.0.0",
87
- "eslint-config-standard-with-typescript": "^37.0.0",
88
- "eslint-plugin-header": "^3.1.1",
89
- "eslint-plugin-import": "^2.28.0",
90
- "eslint-plugin-mocha": "^10.1.0",
91
- "eslint-plugin-n": "^16.0.1",
92
- "eslint-plugin-prettier": "^5.0.0",
93
- "eslint-plugin-promise": "^6.1.1",
94
- "http-server": "^14.1.1",
95
- "husky": "^8.0.3",
96
- "mocha": "^10.2.0",
97
- "node-stdlib-browser": "^1.2.0",
98
- "prettier": "^3.0.2",
99
- "rimraf": "^5.0.1",
100
- "semantic-release": "^21.0.7",
101
- "sinon": "^15.2.0",
102
- "ts-node": "^10.9.1",
103
- "typescript": "^5.1.6"
104
- }
105
- }
@@ -1,18 +0,0 @@
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 './arweave.js';
18
- export * from './turbo.js';
@@ -1,18 +0,0 @@
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 './arweave.js';
18
- export * from './turbo.js';
@@ -1,24 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export function readableStreamToBuffer({ stream, }) {
11
- return __awaiter(this, void 0, void 0, function* () {
12
- const reader = stream.getReader();
13
- const chunks = [];
14
- let done = false;
15
- while (!done) {
16
- const { done: streamDone, value } = yield reader.read();
17
- done = streamDone;
18
- if (!done) {
19
- chunks.push(value);
20
- }
21
- }
22
- return Buffer.concat(chunks);
23
- });
24
- }
package/lib/web/signer.js DELETED
@@ -1,61 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /**
11
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
12
- *
13
- * This program is free software: you can redistribute it and/or modify
14
- * it under the terms of the GNU Affero General Public License as published by
15
- * the Free Software Foundation, either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU Affero General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU Affero General Public License
24
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
- */
26
- import { ArweaveSigner, createData } from 'arbundles/web';
27
- import Arweave from 'arweave/web/index.js';
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
- constructor({ privateKey }) {
33
- this.privateKey = privateKey;
34
- this.signer = new ArweaveSigner(this.privateKey);
35
- }
36
- signDataItem({ fileStreamFactory, }) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- // TODO: converts the readable stream to a buffer bc incrementally signing ReadableStreams is not trivial
39
- const buffer = yield readableStreamToBuffer({
40
- stream: fileStreamFactory(),
41
- // TODO: add payload size to get performance improvements
42
- });
43
- const signedDataItem = createData(buffer, this.signer);
44
- yield signedDataItem.sign(this.signer);
45
- return signedDataItem.getRaw();
46
- });
47
- }
48
- // 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
49
- generateSignedRequestHeaders() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const nonce = randomBytes(16).toString('hex');
52
- const buffer = Buffer.from(nonce);
53
- const signature = yield Arweave.default.crypto.sign(this.privateKey, buffer);
54
- return {
55
- 'x-public-key': this.privateKey.n,
56
- 'x-nonce': nonce,
57
- 'x-signature': toB64Url(Buffer.from(signature)),
58
- };
59
- });
60
- }
61
- }
File without changes
File without changes
File without changes
File without changes
File without changes