@ardrive/turbo-sdk 1.0.0-alpha.1
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/LICENSE.md +661 -0
- package/README.md +114 -0
- package/bundles/web.bundle.min.js +55429 -0
- package/lib/LICENSE.md +661 -0
- package/lib/README.md +114 -0
- package/lib/common/factory.d.ts +21 -0
- package/lib/common/factory.js +13 -0
- package/lib/common/http.d.ts +44 -0
- package/lib/common/http.js +45 -0
- package/lib/common/index.d.ts +19 -0
- package/lib/common/index.js +19 -0
- package/lib/common/payment.d.ts +41 -0
- package/lib/common/payment.js +81 -0
- package/lib/common/turbo.d.ts +73 -0
- package/lib/common/turbo.js +100 -0
- package/lib/common/upload.d.ts +29 -0
- package/lib/common/upload.js +54 -0
- package/lib/node/factory.d.ts +22 -0
- package/lib/node/factory.js +30 -0
- package/lib/node/index.d.ts +19 -0
- package/lib/node/index.js +19 -0
- package/lib/node/signer.d.ts +36 -0
- package/lib/node/signer.js +54 -0
- package/lib/package.json +106 -0
- package/lib/types/arweave.d.ts +29 -0
- package/lib/types/arweave.js +1 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/index.js +18 -0
- package/lib/types/turbo.d.ts +149 -0
- package/lib/types/turbo.js +1 -0
- package/lib/utils/axiosClient.d.ts +23 -0
- package/lib/utils/axiosClient.js +30 -0
- package/lib/utils/base64.d.ts +9 -0
- package/lib/utils/base64.js +39 -0
- package/lib/utils/errors.d.ts +22 -0
- package/lib/utils/errors.js +28 -0
- package/lib/utils/readableStream.d.ts +22 -0
- package/lib/utils/readableStream.js +24 -0
- package/lib/web/factory.d.ts +22 -0
- package/lib/web/factory.js +30 -0
- package/lib/web/index.d.ts +19 -0
- package/lib/web/index.js +19 -0
- package/lib/web/signer.d.ts +37 -0
- package/lib/web/signer.js +61 -0
- package/package.json +106 -0
@@ -0,0 +1,22 @@
|
|
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 { TurboBaseFactory } from '../common/factory.js';
|
18
|
+
import { TurboAuthenticatedClient } from '../common/index.js';
|
19
|
+
import { TurboPrivateConfiguration } from '../types/index.js';
|
20
|
+
export declare class TurboFactory extends TurboBaseFactory {
|
21
|
+
static authenticated({ privateKey, paymentServiceConfig, uploadServiceConfig, }: TurboPrivateConfiguration): TurboAuthenticatedClient;
|
22
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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 { TurboBaseFactory } from '../common/factory.js';
|
18
|
+
import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, TurboAuthenticatedUploadService, } from '../common/index.js';
|
19
|
+
import { TurboNodeArweaveSigner } from './signer.js';
|
20
|
+
export class TurboFactory extends TurboBaseFactory {
|
21
|
+
static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
|
22
|
+
const signer = new TurboNodeArweaveSigner({ privateKey });
|
23
|
+
const paymentService = new TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
|
24
|
+
const uploadService = new TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
|
25
|
+
return new TurboAuthenticatedClient({
|
26
|
+
uploadService,
|
27
|
+
paymentService,
|
28
|
+
});
|
29
|
+
}
|
30
|
+
}
|
@@ -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 './factory.js';
|
18
|
+
export * from './signer.js';
|
19
|
+
export * from '../common/index.js';
|
@@ -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 './factory.js';
|
18
|
+
export * from './signer.js';
|
19
|
+
export * from '../common/index.js';
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
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,54 @@
|
|
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, streamSigner } from 'arbundles';
|
27
|
+
import Arweave from 'arweave/node/index.js';
|
28
|
+
import { randomBytes } from 'node:crypto';
|
29
|
+
import { toB64Url } from '../utils/base64.js';
|
30
|
+
export class TurboNodeArweaveSigner {
|
31
|
+
// TODO: replace with internal signer class
|
32
|
+
constructor({ privateKey }) {
|
33
|
+
this.privateKey = privateKey;
|
34
|
+
this.signer = new ArweaveSigner(this.privateKey);
|
35
|
+
}
|
36
|
+
signDataItem({ fileStreamFactory, }) {
|
37
|
+
// TODO: replace with our own signer implementation
|
38
|
+
const [stream1, stream2] = [fileStreamFactory(), fileStreamFactory()];
|
39
|
+
return streamSigner(stream1, stream2, this.signer);
|
40
|
+
}
|
41
|
+
// NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto
|
42
|
+
generateSignedRequestHeaders() {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
const nonce = randomBytes(16).toString('hex');
|
45
|
+
const buffer = Buffer.from(nonce);
|
46
|
+
const signature = yield Arweave.crypto.sign(this.privateKey, buffer);
|
47
|
+
return {
|
48
|
+
'x-public-key': this.privateKey.n,
|
49
|
+
'x-nonce': nonce,
|
50
|
+
'x-signature': toB64Url(Buffer.from(signature)),
|
51
|
+
};
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
package/lib/package.json
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
{
|
2
|
+
"name": "@ardrive/turbo-sdk",
|
3
|
+
"version": "0.0.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
|
+
"postinstall": "husky install",
|
51
|
+
"lint": "eslint src",
|
52
|
+
"lint:fix": "eslint src --fix",
|
53
|
+
"format": "prettier --check .",
|
54
|
+
"format:fix": "prettier --write .",
|
55
|
+
"test": "c8 mocha --config .mocharc --exit",
|
56
|
+
"test:web": "c8 mocha --config .mocharc --exclude tests/**/*.node.test.ts --exit",
|
57
|
+
"test:node": "c8 mocha --config .mocharc --exclude tests/**/*.web.test.ts --exit",
|
58
|
+
"prepare": "husky install",
|
59
|
+
"example:mjs": "yarn build:esm && node examples/node/index.mjs",
|
60
|
+
"example:cjs": "yarn build:esm && node examples/node/index.cjs",
|
61
|
+
"example:web": "yarn build:web && cp -r bundles/* examples/web && http-server --port 8080 --host -o examples/web"
|
62
|
+
},
|
63
|
+
"dependencies": {
|
64
|
+
"arbundles": "^0.9.9",
|
65
|
+
"arweave": "^1.14.4",
|
66
|
+
"axios": "^1.4.0",
|
67
|
+
"retry-axios": "^3.0.0",
|
68
|
+
"winston": "^3.10.0"
|
69
|
+
},
|
70
|
+
"devDependencies": {
|
71
|
+
"@commitlint/cli": "^17.1.2",
|
72
|
+
"@commitlint/config-conventional": "^17.1.0",
|
73
|
+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
74
|
+
"@semantic-release/changelog": "^6.0.3",
|
75
|
+
"@semantic-release/git": "^10.0.1",
|
76
|
+
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
|
77
|
+
"@types/chai": "^4.3.5",
|
78
|
+
"@types/mocha": "^10.0.1",
|
79
|
+
"@types/node": "^20.4.8",
|
80
|
+
"@types/sinon": "^10.0.15",
|
81
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
82
|
+
"@typescript-eslint/parser": "^6.4.0",
|
83
|
+
"c8": "^8.0.1",
|
84
|
+
"chai": "^4.3.7",
|
85
|
+
"esbuild": "^0.19.2",
|
86
|
+
"eslint": "^8.47.0",
|
87
|
+
"eslint-config-prettier": "^9.0.0",
|
88
|
+
"eslint-config-standard-with-typescript": "^37.0.0",
|
89
|
+
"eslint-plugin-header": "^3.1.1",
|
90
|
+
"eslint-plugin-import": "^2.28.0",
|
91
|
+
"eslint-plugin-mocha": "^10.1.0",
|
92
|
+
"eslint-plugin-n": "^16.0.1",
|
93
|
+
"eslint-plugin-prettier": "^5.0.0",
|
94
|
+
"eslint-plugin-promise": "^6.1.1",
|
95
|
+
"http-server": "^14.1.1",
|
96
|
+
"husky": "^8.0.3",
|
97
|
+
"mocha": "^10.2.0",
|
98
|
+
"node-stdlib-browser": "^1.2.0",
|
99
|
+
"prettier": "^3.0.2",
|
100
|
+
"rimraf": "^5.0.1",
|
101
|
+
"semantic-release": "^21.0.7",
|
102
|
+
"sinon": "^15.2.0",
|
103
|
+
"ts-node": "^10.9.1",
|
104
|
+
"typescript": "^5.1.6"
|
105
|
+
}
|
106
|
+
}
|
@@ -0,0 +1,29 @@
|
|
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 interface JWKPublicInterface {
|
18
|
+
kty: string;
|
19
|
+
e: string;
|
20
|
+
n: string;
|
21
|
+
}
|
22
|
+
export interface JWKInterface extends JWKPublicInterface {
|
23
|
+
d?: string;
|
24
|
+
p?: string;
|
25
|
+
q?: string;
|
26
|
+
dp?: string;
|
27
|
+
dq?: string;
|
28
|
+
qi?: string;
|
29
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,18 @@
|
|
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';
|
@@ -0,0 +1,18 @@
|
|
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';
|
@@ -0,0 +1,149 @@
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
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 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,23 @@
|
|
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 { AxiosInstance, AxiosRequestConfig } from 'axios';
|
18
|
+
import * as rax from 'retry-axios';
|
19
|
+
export interface AxiosInstanceParameters {
|
20
|
+
axiosConfig?: Omit<AxiosRequestConfig, 'validateStatus'>;
|
21
|
+
retryConfig?: rax.RetryConfig;
|
22
|
+
}
|
23
|
+
export declare const createAxiosInstance: ({ axiosConfig, retryConfig, }: AxiosInstanceParameters) => AxiosInstance;
|
@@ -0,0 +1,30 @@
|
|
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 axios from 'axios';
|
18
|
+
import * as rax from 'retry-axios';
|
19
|
+
export const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
|
20
|
+
backoffType: 'exponential',
|
21
|
+
retry: 3,
|
22
|
+
onRetryAttempt: (err) => {
|
23
|
+
const cfg = rax.getConfig(err);
|
24
|
+
console.debug(`Retry attempt #${cfg === null || cfg === void 0 ? void 0 : cfg.currentRetryAttempt}`);
|
25
|
+
},
|
26
|
+
}, }) => {
|
27
|
+
const axiosInstance = axios.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
|
28
|
+
axiosInstance.defaults.raxConfig = Object.assign({ instance: axiosInstance }, retryConfig);
|
29
|
+
return axiosInstance;
|
30
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
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,39 @@
|
|
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 { bufferTob64Url } from 'arweave/node/lib/utils.js';
|
18
|
+
import { createHash } from 'crypto';
|
19
|
+
export const base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;
|
20
|
+
export function jwkToPublicArweaveAddress(jwk) {
|
21
|
+
return ownerToAddress(jwk.n);
|
22
|
+
}
|
23
|
+
export function ownerToAddress(owner) {
|
24
|
+
return sha256B64Url(fromB64Url(owner));
|
25
|
+
}
|
26
|
+
export function fromB64Url(input) {
|
27
|
+
const paddingLength = input.length % 4 === 0 ? 0 : 4 - (input.length % 4);
|
28
|
+
const base64 = input
|
29
|
+
.replace(/-/g, '+')
|
30
|
+
.replace(/_/g, '/')
|
31
|
+
.concat('='.repeat(paddingLength));
|
32
|
+
return Buffer.from(base64, 'base64');
|
33
|
+
}
|
34
|
+
export function toB64Url(buffer) {
|
35
|
+
return bufferTob64Url(buffer);
|
36
|
+
}
|
37
|
+
export function sha256B64Url(input) {
|
38
|
+
return toB64Url(createHash('sha256').update(input).digest());
|
39
|
+
}
|
@@ -0,0 +1,22 @@
|
|
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 declare class UnauthenticatedRequestError extends Error {
|
18
|
+
constructor();
|
19
|
+
}
|
20
|
+
export declare class FailedRequestError extends Error {
|
21
|
+
constructor(status: number, message: string);
|
22
|
+
}
|