@ar.io/sdk 3.10.0-alpha.1 → 3.10.0-alpha.2
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/README.md +124 -140
- package/bundles/web.bundle.min.js +80 -77
- package/lib/cjs/common/faucet.js +150 -0
- package/lib/cjs/common/index.js +1 -0
- package/lib/cjs/common/io.js +55 -3
- package/lib/cjs/types/faucet.js +2 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/io.js +3 -2
- package/lib/cjs/utils/ao.js +2 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/faucet.js +145 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/io.js +54 -2
- package/lib/esm/types/faucet.js +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/io.js +3 -2
- package/lib/esm/utils/ao.js +2 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/utils.d.ts +1 -1
- package/lib/types/common/faucet.d.ts +96 -0
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/io.d.ts +17 -5
- package/lib/types/types/faucet.d.ts +82 -0
- package/lib/types/types/index.d.ts +1 -0
- package/lib/types/types/io.d.ts +2 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +5 -6
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARIOTokenFaucet = exports.createFaucet = void 0;
|
|
4
|
+
const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
7
|
+
* @param arioInstance - The ARIOReadable instance
|
|
8
|
+
* @param faucetApiUrl - The URL of the faucet API
|
|
9
|
+
* @returns A proxy object that implements the TokenFaucet interface
|
|
10
|
+
*/
|
|
11
|
+
function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, }) {
|
|
12
|
+
const faucet = new ARIOTokenFaucet({
|
|
13
|
+
faucetUrl: faucetApiUrl,
|
|
14
|
+
processId: arioInstance.process.processId,
|
|
15
|
+
});
|
|
16
|
+
const proxy = new Proxy(arioInstance, {
|
|
17
|
+
get(target, prop) {
|
|
18
|
+
if (prop === 'faucet') {
|
|
19
|
+
return faucet;
|
|
20
|
+
}
|
|
21
|
+
if (prop in target) {
|
|
22
|
+
const result = target[prop];
|
|
23
|
+
if (typeof result === 'function') {
|
|
24
|
+
return result.bind(target);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
return proxy;
|
|
32
|
+
}
|
|
33
|
+
exports.createFaucet = createFaucet;
|
|
34
|
+
class ARIOTokenFaucet {
|
|
35
|
+
faucetUrl;
|
|
36
|
+
processId;
|
|
37
|
+
constructor({ faucetUrl, processId, }) {
|
|
38
|
+
this.faucetUrl = faucetUrl;
|
|
39
|
+
this.processId = processId;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
|
|
43
|
+
* @returns The captcha URL for a process
|
|
44
|
+
*/
|
|
45
|
+
async captchaUrl() {
|
|
46
|
+
const res = await fetch(`${this.faucetUrl}/api/captcha/url?process-id=${this.processId}`, {
|
|
47
|
+
method: 'GET',
|
|
48
|
+
});
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
51
|
+
throw new Error(body.error);
|
|
52
|
+
}
|
|
53
|
+
const data = (await res.json());
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
|
|
58
|
+
* @param captchaResponse - The captcha response
|
|
59
|
+
* @param recipient - The recipient address
|
|
60
|
+
* @param quantity - The quantity of tokens to claim
|
|
61
|
+
* @returns The claim id and success status
|
|
62
|
+
*/
|
|
63
|
+
async claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }) {
|
|
64
|
+
const res = await fetch(`${this.faucetUrl}/api/claim/sync`, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: { 'Content-Type': 'application/json' },
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
processId: this.processId,
|
|
69
|
+
recipient,
|
|
70
|
+
quantity,
|
|
71
|
+
captchaResponse,
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
76
|
+
throw new Error(body.error);
|
|
77
|
+
}
|
|
78
|
+
const data = (await res.json());
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
|
|
83
|
+
* @param captchaResponse - The captcha response
|
|
84
|
+
* @returns The status of the request, the authorization token, and the expiration time
|
|
85
|
+
*/
|
|
86
|
+
async requestAuthToken({ captchaResponse, }) {
|
|
87
|
+
const res = await fetch(`${this.faucetUrl}/api/captcha/verify`, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: { 'Content-Type': 'application/json' },
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
processId: this.processId,
|
|
92
|
+
captchaResponse,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
97
|
+
throw new Error(body.error);
|
|
98
|
+
}
|
|
99
|
+
const data = (await res.json());
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
|
|
104
|
+
* @param authToken - The authorization token
|
|
105
|
+
* @param recipient - The recipient address
|
|
106
|
+
* @param quantity - The quantity of tokens to claim
|
|
107
|
+
* @returns The message id of the transfer and success status
|
|
108
|
+
*/
|
|
109
|
+
async claimWithAuthToken({ authToken, recipient, quantity, }) {
|
|
110
|
+
const res = await fetch(`${this.faucetUrl}/api/claim/async`, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
Authorization: `Bearer ${authToken}`,
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify({
|
|
117
|
+
recipient,
|
|
118
|
+
qty: quantity,
|
|
119
|
+
processId: this.processId,
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
if (!res.ok) {
|
|
123
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
124
|
+
throw new Error(body.error);
|
|
125
|
+
}
|
|
126
|
+
const data = (await res.json());
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Verifies an authorization token is valid.
|
|
131
|
+
* @param authToken - The authorization token
|
|
132
|
+
* @returns The validity of the authorization token and the expiration time
|
|
133
|
+
*/
|
|
134
|
+
async verifyAuthToken({ authToken }) {
|
|
135
|
+
const res = await fetch(`${this.faucetUrl}/api/token/verify?process-id=${this.processId}`, {
|
|
136
|
+
method: 'GET',
|
|
137
|
+
headers: {
|
|
138
|
+
'Content-Type': 'application/json',
|
|
139
|
+
Authorization: `Bearer ${authToken}`,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
if (!res.ok) {
|
|
143
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
144
|
+
throw new Error(body.error);
|
|
145
|
+
}
|
|
146
|
+
const data = (await res.json());
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.ARIOTokenFaucet = ARIOTokenFaucet;
|
package/lib/cjs/common/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __exportStar(require("./logger.js"), exports);
|
|
|
34
34
|
__exportStar(require("./ant.js"), exports);
|
|
35
35
|
__exportStar(require("./ant-registry.js"), exports);
|
|
36
36
|
__exportStar(require("./ant-versions.js"), exports);
|
|
37
|
+
__exportStar(require("./faucet.js"), exports);
|
|
37
38
|
// ao
|
|
38
39
|
__exportStar(require("./io.js"), exports);
|
|
39
40
|
__exportStar(require("./contracts/ao-process.js"), exports);
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ARIOWriteable = exports.ARIOReadable = exports.ARIO = void 0;
|
|
4
|
+
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
4
5
|
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
6
7
|
const ao_js_1 = require("../utils/ao.js");
|
|
7
8
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
8
9
|
const arweave_js_2 = require("./arweave.js");
|
|
9
10
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
10
11
|
const error_js_1 = require("./error.js");
|
|
12
|
+
const faucet_js_1 = require("./faucet.js");
|
|
11
13
|
const turbo_js_1 = require("./turbo.js");
|
|
12
14
|
class ARIO {
|
|
13
15
|
// Implementation
|
|
@@ -17,6 +19,56 @@ class ARIO {
|
|
|
17
19
|
}
|
|
18
20
|
return new ARIOReadable(config);
|
|
19
21
|
}
|
|
22
|
+
static mainnet(config) {
|
|
23
|
+
if (config !== undefined && 'signer' in config) {
|
|
24
|
+
return new ARIOWriteable({
|
|
25
|
+
...config,
|
|
26
|
+
process: new ao_process_js_1.AOProcess({
|
|
27
|
+
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
28
|
+
ao: (0, aoconnect_1.connect)({
|
|
29
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
30
|
+
...config?.process?.ao,
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return new ARIOReadable({
|
|
36
|
+
...config,
|
|
37
|
+
process: new ao_process_js_1.AOProcess({
|
|
38
|
+
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
static testnet(config) {
|
|
43
|
+
if (config !== undefined && 'signer' in config) {
|
|
44
|
+
return (0, faucet_js_1.createFaucet)({
|
|
45
|
+
arioInstance: new ARIOWriteable({
|
|
46
|
+
...config,
|
|
47
|
+
process: new ao_process_js_1.AOProcess({
|
|
48
|
+
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
49
|
+
ao: (0, aoconnect_1.connect)({
|
|
50
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
51
|
+
...config?.process?.ao,
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
}),
|
|
55
|
+
faucetApiUrl: config?.faucetUrl,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return (0, faucet_js_1.createFaucet)({
|
|
59
|
+
arioInstance: new ARIOReadable({
|
|
60
|
+
...config,
|
|
61
|
+
process: new ao_process_js_1.AOProcess({
|
|
62
|
+
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
63
|
+
ao: (0, aoconnect_1.connect)({
|
|
64
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
65
|
+
...config?.process?.ao,
|
|
66
|
+
}),
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
faucetApiUrl: config?.faucetUrl,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
20
72
|
}
|
|
21
73
|
exports.ARIO = ARIO;
|
|
22
74
|
class ARIOReadable {
|
|
@@ -31,10 +83,10 @@ class ARIOReadable {
|
|
|
31
83
|
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
32
84
|
});
|
|
33
85
|
}
|
|
34
|
-
else if ((0,
|
|
86
|
+
else if ((0, index_js_1.isProcessConfiguration)(config)) {
|
|
35
87
|
this.process = config.process;
|
|
36
88
|
}
|
|
37
|
-
else if ((0,
|
|
89
|
+
else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
|
|
38
90
|
this.process = new ao_process_js_1.AOProcess({
|
|
39
91
|
processId: config.processId,
|
|
40
92
|
});
|
package/lib/cjs/types/index.js
CHANGED
|
@@ -32,5 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
__exportStar(require("./ant-registry.js"), exports);
|
|
33
33
|
__exportStar(require("./ant.js"), exports);
|
|
34
34
|
__exportStar(require("./common.js"), exports);
|
|
35
|
+
__exportStar(require("./faucet.js"), exports);
|
|
35
36
|
__exportStar(require("./io.js"), exports);
|
|
36
37
|
__exportStar(require("./token.js"), exports);
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -35,11 +35,12 @@ const isValidFundFrom = (fundFrom) => {
|
|
|
35
35
|
exports.isValidFundFrom = isValidFundFrom;
|
|
36
36
|
// Type-guard functions
|
|
37
37
|
function isProcessConfiguration(config) {
|
|
38
|
-
return 'process' in config;
|
|
38
|
+
return config !== undefined && 'process' in config;
|
|
39
39
|
}
|
|
40
40
|
exports.isProcessConfiguration = isProcessConfiguration;
|
|
41
41
|
function isProcessIdConfiguration(config) {
|
|
42
|
-
return (
|
|
42
|
+
return (config !== undefined &&
|
|
43
|
+
'processId' in config &&
|
|
43
44
|
typeof config.processId === 'string' &&
|
|
44
45
|
(0, arweave_js_1.validateArweaveId)(config.processId) === true);
|
|
45
46
|
}
|
package/lib/cjs/utils/ao.js
CHANGED
package/lib/cjs/version.js
CHANGED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
4
|
+
* @param arioInstance - The ARIOReadable instance
|
|
5
|
+
* @param faucetApiUrl - The URL of the faucet API
|
|
6
|
+
* @returns A proxy object that implements the TokenFaucet interface
|
|
7
|
+
*/
|
|
8
|
+
export function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, }) {
|
|
9
|
+
const faucet = new ARIOTokenFaucet({
|
|
10
|
+
faucetUrl: faucetApiUrl,
|
|
11
|
+
processId: arioInstance.process.processId,
|
|
12
|
+
});
|
|
13
|
+
const proxy = new Proxy(arioInstance, {
|
|
14
|
+
get(target, prop) {
|
|
15
|
+
if (prop === 'faucet') {
|
|
16
|
+
return faucet;
|
|
17
|
+
}
|
|
18
|
+
if (prop in target) {
|
|
19
|
+
const result = target[prop];
|
|
20
|
+
if (typeof result === 'function') {
|
|
21
|
+
return result.bind(target);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return proxy;
|
|
29
|
+
}
|
|
30
|
+
export class ARIOTokenFaucet {
|
|
31
|
+
faucetUrl;
|
|
32
|
+
processId;
|
|
33
|
+
constructor({ faucetUrl, processId, }) {
|
|
34
|
+
this.faucetUrl = faucetUrl;
|
|
35
|
+
this.processId = processId;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
|
|
39
|
+
* @returns The captcha URL for a process
|
|
40
|
+
*/
|
|
41
|
+
async captchaUrl() {
|
|
42
|
+
const res = await fetch(`${this.faucetUrl}/api/captcha/url?process-id=${this.processId}`, {
|
|
43
|
+
method: 'GET',
|
|
44
|
+
});
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
47
|
+
throw new Error(body.error);
|
|
48
|
+
}
|
|
49
|
+
const data = (await res.json());
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
|
|
54
|
+
* @param captchaResponse - The captcha response
|
|
55
|
+
* @param recipient - The recipient address
|
|
56
|
+
* @param quantity - The quantity of tokens to claim
|
|
57
|
+
* @returns The claim id and success status
|
|
58
|
+
*/
|
|
59
|
+
async claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }) {
|
|
60
|
+
const res = await fetch(`${this.faucetUrl}/api/claim/sync`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
processId: this.processId,
|
|
65
|
+
recipient,
|
|
66
|
+
quantity,
|
|
67
|
+
captchaResponse,
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
72
|
+
throw new Error(body.error);
|
|
73
|
+
}
|
|
74
|
+
const data = (await res.json());
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
|
|
79
|
+
* @param captchaResponse - The captcha response
|
|
80
|
+
* @returns The status of the request, the authorization token, and the expiration time
|
|
81
|
+
*/
|
|
82
|
+
async requestAuthToken({ captchaResponse, }) {
|
|
83
|
+
const res = await fetch(`${this.faucetUrl}/api/captcha/verify`, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: { 'Content-Type': 'application/json' },
|
|
86
|
+
body: JSON.stringify({
|
|
87
|
+
processId: this.processId,
|
|
88
|
+
captchaResponse,
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
if (!res.ok) {
|
|
92
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
93
|
+
throw new Error(body.error);
|
|
94
|
+
}
|
|
95
|
+
const data = (await res.json());
|
|
96
|
+
return data;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
|
|
100
|
+
* @param authToken - The authorization token
|
|
101
|
+
* @param recipient - The recipient address
|
|
102
|
+
* @param quantity - The quantity of tokens to claim
|
|
103
|
+
* @returns The message id of the transfer and success status
|
|
104
|
+
*/
|
|
105
|
+
async claimWithAuthToken({ authToken, recipient, quantity, }) {
|
|
106
|
+
const res = await fetch(`${this.faucetUrl}/api/claim/async`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
Authorization: `Bearer ${authToken}`,
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify({
|
|
113
|
+
recipient,
|
|
114
|
+
qty: quantity,
|
|
115
|
+
processId: this.processId,
|
|
116
|
+
}),
|
|
117
|
+
});
|
|
118
|
+
if (!res.ok) {
|
|
119
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
120
|
+
throw new Error(body.error);
|
|
121
|
+
}
|
|
122
|
+
const data = (await res.json());
|
|
123
|
+
return data;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Verifies an authorization token is valid.
|
|
127
|
+
* @param authToken - The authorization token
|
|
128
|
+
* @returns The validity of the authorization token and the expiration time
|
|
129
|
+
*/
|
|
130
|
+
async verifyAuthToken({ authToken }) {
|
|
131
|
+
const res = await fetch(`${this.faucetUrl}/api/token/verify?process-id=${this.processId}`, {
|
|
132
|
+
method: 'GET',
|
|
133
|
+
headers: {
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
Authorization: `Bearer ${authToken}`,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
if (!res.ok) {
|
|
139
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
140
|
+
throw new Error(body.error);
|
|
141
|
+
}
|
|
142
|
+
const data = (await res.json());
|
|
143
|
+
return data;
|
|
144
|
+
}
|
|
145
|
+
}
|
package/lib/esm/common/index.js
CHANGED
package/lib/esm/common/io.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { connect } from '@permaweb/aoconnect';
|
|
2
|
+
import { ARIO_MAINNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, } from '../constants.js';
|
|
3
|
+
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
|
|
3
4
|
import { createAoSigner } from '../utils/ao.js';
|
|
4
5
|
import { getEpochDataFromGqlWithCUFallback, paginationParamsToTags, pruneTags, removeEligibleRewardsFromEpochData, sortAndPaginateEpochDataIntoEligibleDistributions, } from '../utils/arweave.js';
|
|
5
6
|
import { defaultArweave } from './arweave.js';
|
|
6
7
|
import { AOProcess } from './contracts/ao-process.js';
|
|
7
8
|
import { InvalidContractConfigurationError } from './error.js';
|
|
9
|
+
import { createFaucet } from './faucet.js';
|
|
8
10
|
import { TurboArNSPaymentProvider } from './turbo.js';
|
|
9
11
|
export class ARIO {
|
|
10
12
|
// Implementation
|
|
@@ -14,6 +16,56 @@ export class ARIO {
|
|
|
14
16
|
}
|
|
15
17
|
return new ARIOReadable(config);
|
|
16
18
|
}
|
|
19
|
+
static mainnet(config) {
|
|
20
|
+
if (config !== undefined && 'signer' in config) {
|
|
21
|
+
return new ARIOWriteable({
|
|
22
|
+
...config,
|
|
23
|
+
process: new AOProcess({
|
|
24
|
+
processId: ARIO_MAINNET_PROCESS_ID,
|
|
25
|
+
ao: connect({
|
|
26
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
27
|
+
...config?.process?.ao,
|
|
28
|
+
}),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return new ARIOReadable({
|
|
33
|
+
...config,
|
|
34
|
+
process: new AOProcess({
|
|
35
|
+
processId: ARIO_MAINNET_PROCESS_ID,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static testnet(config) {
|
|
40
|
+
if (config !== undefined && 'signer' in config) {
|
|
41
|
+
return createFaucet({
|
|
42
|
+
arioInstance: new ARIOWriteable({
|
|
43
|
+
...config,
|
|
44
|
+
process: new AOProcess({
|
|
45
|
+
processId: ARIO_TESTNET_PROCESS_ID,
|
|
46
|
+
ao: connect({
|
|
47
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
48
|
+
...config?.process?.ao,
|
|
49
|
+
}),
|
|
50
|
+
}),
|
|
51
|
+
}),
|
|
52
|
+
faucetApiUrl: config?.faucetUrl,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return createFaucet({
|
|
56
|
+
arioInstance: new ARIOReadable({
|
|
57
|
+
...config,
|
|
58
|
+
process: new AOProcess({
|
|
59
|
+
processId: ARIO_TESTNET_PROCESS_ID,
|
|
60
|
+
ao: connect({
|
|
61
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
62
|
+
...config?.process?.ao,
|
|
63
|
+
}),
|
|
64
|
+
}),
|
|
65
|
+
}),
|
|
66
|
+
faucetApiUrl: config?.faucetUrl,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
17
69
|
}
|
|
18
70
|
export class ARIOReadable {
|
|
19
71
|
process;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/types/index.js
CHANGED
package/lib/esm/types/io.js
CHANGED
|
@@ -28,10 +28,11 @@ export const isValidFundFrom = (fundFrom) => {
|
|
|
28
28
|
};
|
|
29
29
|
// Type-guard functions
|
|
30
30
|
export function isProcessConfiguration(config) {
|
|
31
|
-
return 'process' in config;
|
|
31
|
+
return config !== undefined && 'process' in config;
|
|
32
32
|
}
|
|
33
33
|
export function isProcessIdConfiguration(config) {
|
|
34
|
-
return (
|
|
34
|
+
return (config !== undefined &&
|
|
35
|
+
'processId' in config &&
|
|
35
36
|
typeof config.processId === 'string' &&
|
|
36
37
|
validateArweaveId(config.processId) === true);
|
|
37
38
|
}
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -131,6 +131,8 @@ export function createAoSigner(signer) {
|
|
|
131
131
|
}));
|
|
132
132
|
return signedData;
|
|
133
133
|
};
|
|
134
|
+
// eslint-disable-next-line
|
|
135
|
+
// @ts-ignore Buffer vs ArrayBuffer type mismatch
|
|
134
136
|
return aoSigner;
|
|
135
137
|
}
|
|
136
138
|
export const defaultTargetManifestId = '-k7t8xMoB8hW482609Z9F4bTFMC3MnuW8bTvTyT8pFI';
|
package/lib/esm/version.js
CHANGED
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export declare function positiveIntegerFromOptions<O extends GlobalCLIOptions>(o
|
|
|
80
80
|
export declare function requiredPositiveIntegerFromOptions<O extends GlobalCLIOptions>(options: O, key: string): number;
|
|
81
81
|
export declare function getANTStateFromOptions(options: ANTStateCLIOptions): SpawnANTState;
|
|
82
82
|
export declare function getTokenCostParamsFromOptions(o: GetTokenCostCLIOptions): {
|
|
83
|
-
type: "
|
|
83
|
+
type: "lease" | "permabuy";
|
|
84
84
|
quantity: number | undefined;
|
|
85
85
|
years: number;
|
|
86
86
|
intent: "Buy-Name" | "Buy-Record" | "Extend-Lease" | "Increase-Undername-Limit" | "Upgrade-Name" | "Primary-Name-Request";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { ARIOWithFaucet, TokenFaucet } from '../types/faucet.js';
|
|
17
|
+
import { ARIOReadable, ARIOWriteable } from './io.js';
|
|
18
|
+
/**
|
|
19
|
+
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
20
|
+
* @param arioInstance - The ARIOReadable instance
|
|
21
|
+
* @param faucetApiUrl - The URL of the faucet API
|
|
22
|
+
* @returns A proxy object that implements the TokenFaucet interface
|
|
23
|
+
*/
|
|
24
|
+
export declare function createFaucet({ arioInstance, faucetApiUrl, }: {
|
|
25
|
+
arioInstance: ARIOReadable | ARIOWriteable;
|
|
26
|
+
faucetApiUrl?: string;
|
|
27
|
+
}): ARIOWithFaucet<ARIOReadable | ARIOWriteable>;
|
|
28
|
+
export declare class ARIOTokenFaucet implements TokenFaucet {
|
|
29
|
+
private faucetUrl;
|
|
30
|
+
private processId;
|
|
31
|
+
constructor({ faucetUrl, processId, }: {
|
|
32
|
+
faucetUrl: string;
|
|
33
|
+
processId: string;
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
|
|
37
|
+
* @returns The captcha URL for a process
|
|
38
|
+
*/
|
|
39
|
+
captchaUrl(): Promise<{
|
|
40
|
+
processId: string;
|
|
41
|
+
captchaUrl: string;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
|
|
45
|
+
* @param captchaResponse - The captcha response
|
|
46
|
+
* @param recipient - The recipient address
|
|
47
|
+
* @param quantity - The quantity of tokens to claim
|
|
48
|
+
* @returns The claim id and success status
|
|
49
|
+
*/
|
|
50
|
+
claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }: {
|
|
51
|
+
captchaResponse: string;
|
|
52
|
+
recipient: string;
|
|
53
|
+
quantity: number;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
success: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
|
|
60
|
+
* @param captchaResponse - The captcha response
|
|
61
|
+
* @returns The status of the request, the authorization token, and the expiration time
|
|
62
|
+
*/
|
|
63
|
+
requestAuthToken({ captchaResponse, }: {
|
|
64
|
+
captchaResponse: string;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
status: 'success' | 'error';
|
|
67
|
+
token: string;
|
|
68
|
+
expiresAt: number;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
|
|
72
|
+
* @param authToken - The authorization token
|
|
73
|
+
* @param recipient - The recipient address
|
|
74
|
+
* @param quantity - The quantity of tokens to claim
|
|
75
|
+
* @returns The message id of the transfer and success status
|
|
76
|
+
*/
|
|
77
|
+
claimWithAuthToken({ authToken, recipient, quantity, }: {
|
|
78
|
+
authToken: string;
|
|
79
|
+
recipient: string;
|
|
80
|
+
quantity: number;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
id: string;
|
|
83
|
+
success: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Verifies an authorization token is valid.
|
|
87
|
+
* @param authToken - The authorization token
|
|
88
|
+
* @returns The validity of the authorization token and the expiration time
|
|
89
|
+
*/
|
|
90
|
+
verifyAuthToken({ authToken }: {
|
|
91
|
+
authToken: string;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
valid: boolean;
|
|
94
|
+
expiresAt: number;
|
|
95
|
+
}>;
|
|
96
|
+
}
|