@ar.io/sdk 3.9.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 +107 -99
- package/lib/cjs/cli/options.js +12 -0
- package/lib/cjs/cli/utils.js +33 -11
- package/lib/cjs/common/ant-versions.js +5 -5
- package/lib/cjs/common/faucet.js +150 -0
- package/lib/cjs/common/index.js +1 -0
- package/lib/cjs/common/io.js +107 -4
- package/lib/cjs/common/turbo.js +134 -0
- package/lib/cjs/types/faucet.js +2 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/io.js +4 -3
- package/lib/cjs/utils/ao.js +2 -0
- package/lib/cjs/utils/url.js +28 -0
- package/lib/cjs/utils/url.test.js +24 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/options.js +12 -0
- package/lib/esm/cli/utils.js +31 -10
- package/lib/esm/common/ant-versions.js +5 -5
- package/lib/esm/common/faucet.js +145 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/io.js +106 -3
- package/lib/esm/common/turbo.js +129 -0
- package/lib/esm/types/faucet.js +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/io.js +4 -3
- package/lib/esm/utils/ao.js +2 -0
- package/lib/esm/utils/url.js +24 -0
- package/lib/esm/utils/url.test.js +19 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +3 -3
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
- package/lib/types/cli/commands/readCommands.d.ts +1 -0
- package/lib/types/cli/commands/transfer.d.ts +3 -3
- package/lib/types/cli/options.d.ts +9 -0
- package/lib/types/cli/types.d.ts +3 -0
- package/lib/types/cli/utils.d.ts +4 -0
- package/lib/types/common/ant-versions.d.ts +3 -6
- 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 +25 -25
- package/lib/types/common/turbo.d.ts +47 -0
- package/lib/types/types/common.d.ts +6 -1
- 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 +9 -8
- package/lib/types/utils/url.d.ts +19 -0
- package/lib/types/utils/url.test.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +7 -7
package/lib/cjs/cli/options.js
CHANGED
|
@@ -52,6 +52,10 @@ exports.optionMap = {
|
|
|
52
52
|
alias: '--cu-url <cuUrl>',
|
|
53
53
|
description: 'The URL for a custom compute unit',
|
|
54
54
|
},
|
|
55
|
+
paymentUrl: {
|
|
56
|
+
alias: '--payment-url <paymentUrl>',
|
|
57
|
+
description: 'The URL for a custom turbo payment service',
|
|
58
|
+
},
|
|
55
59
|
processId: {
|
|
56
60
|
alias: '--process-id <processId>',
|
|
57
61
|
description: 'The process ID to interact with',
|
|
@@ -272,9 +276,15 @@ exports.optionMap = {
|
|
|
272
276
|
alias: '--logo <logo>',
|
|
273
277
|
description: 'The ANT logo',
|
|
274
278
|
},
|
|
279
|
+
token: {
|
|
280
|
+
alias: '-t, --token <type>',
|
|
281
|
+
description: 'Crypto token type for wallet or action',
|
|
282
|
+
default: 'arweave',
|
|
283
|
+
},
|
|
275
284
|
};
|
|
276
285
|
exports.walletOptions = [
|
|
277
286
|
exports.optionMap.walletFile,
|
|
287
|
+
exports.optionMap.token,
|
|
278
288
|
// optionMap.mnemonic,
|
|
279
289
|
exports.optionMap.privateKey,
|
|
280
290
|
];
|
|
@@ -292,6 +302,7 @@ exports.arnsPurchaseOptions = [
|
|
|
292
302
|
...exports.writeActionOptions,
|
|
293
303
|
exports.optionMap.name,
|
|
294
304
|
exports.optionMap.fundFrom,
|
|
305
|
+
exports.optionMap.paymentUrl,
|
|
295
306
|
];
|
|
296
307
|
exports.epochOptions = [exports.optionMap.epochIndex, exports.optionMap.timestamp];
|
|
297
308
|
exports.addressAndVaultIdOptions = [exports.optionMap.address, exports.optionMap.vaultId];
|
|
@@ -315,6 +326,7 @@ exports.tokenCostOptions = [
|
|
|
315
326
|
exports.optionMap.quantity,
|
|
316
327
|
exports.optionMap.address,
|
|
317
328
|
exports.optionMap.fundFrom,
|
|
329
|
+
exports.optionMap.paymentUrl,
|
|
318
330
|
];
|
|
319
331
|
exports.transferOptions = [
|
|
320
332
|
...exports.writeActionOptions,
|
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertLockLengthInRange = exports.fundFromFromOptions = exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.booleanFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughMARIOBalance = exports.assertEnoughBalanceForArNSPurchase = exports.requiredMARIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.customTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatMARIOToARIOWithCommas = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = exports.defaultTtlSecondsCLI = void 0;
|
|
6
|
+
exports.assertLockLengthInRange = exports.fundFromFromOptions = exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.booleanFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughMARIOBalance = exports.assertEnoughBalanceForArNSPurchase = exports.requiredMARIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.customTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatMARIOToARIOWithCommas = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.contractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = exports.defaultTtlSecondsCLI = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
9
|
*
|
|
@@ -19,6 +19,7 @@ exports.assertLockLengthInRange = exports.fundFromFromOptions = exports.getToken
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
const arbundles_1 = require("@dha-team/arbundles");
|
|
22
23
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
23
24
|
const commander_1 = require("commander");
|
|
24
25
|
const fs_1 = require("fs");
|
|
@@ -88,7 +89,7 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
|
88
89
|
return index_js_1.ARIO_MAINNET_PROCESS_ID;
|
|
89
90
|
}
|
|
90
91
|
exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
|
|
91
|
-
function
|
|
92
|
+
function walletFromOptions({ privateKey, walletFile, }) {
|
|
92
93
|
if (privateKey !== undefined) {
|
|
93
94
|
return JSON.parse(privateKey);
|
|
94
95
|
}
|
|
@@ -98,7 +99,7 @@ function jwkFromOptions({ privateKey, walletFile, }) {
|
|
|
98
99
|
return undefined;
|
|
99
100
|
}
|
|
100
101
|
function requiredJwkFromOptions(options) {
|
|
101
|
-
const jwk =
|
|
102
|
+
const jwk = walletFromOptions(options);
|
|
102
103
|
if (jwk === undefined) {
|
|
103
104
|
throw new Error('No JWK provided for signing!\nPlease provide a stringified JWK with `--private-key` or the file path of a jwk.json file with `--wallet-file`');
|
|
104
105
|
}
|
|
@@ -131,14 +132,32 @@ function readARIOFromOptions(options) {
|
|
|
131
132
|
setLoggerIfDebug(options);
|
|
132
133
|
return index_js_1.ARIO.init({
|
|
133
134
|
process: aoProcessFromOptions(options),
|
|
135
|
+
paymentUrl: options.paymentUrl,
|
|
134
136
|
});
|
|
135
137
|
}
|
|
136
138
|
exports.readARIOFromOptions = readARIOFromOptions;
|
|
137
|
-
function
|
|
139
|
+
function contractSignerFromOptions(options) {
|
|
140
|
+
const wallet = walletFromOptions(options);
|
|
141
|
+
if (wallet === undefined) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const token = options.token ?? 'arweave';
|
|
145
|
+
if (token === 'ethereum') {
|
|
146
|
+
const signer = new arbundles_1.EthereumSigner(wallet);
|
|
147
|
+
// For EthereumSigner, we need to convert the JWK to a string
|
|
148
|
+
return { signer, signerAddress: signer.publicKey.toString('hex') };
|
|
149
|
+
}
|
|
138
150
|
// TODO: Support other wallet types
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
151
|
+
const signer = new index_js_1.ArweaveSigner(wallet);
|
|
152
|
+
return { signer, signerAddress: jwkToAddress(wallet) };
|
|
153
|
+
}
|
|
154
|
+
exports.contractSignerFromOptions = contractSignerFromOptions;
|
|
155
|
+
function requiredContractSignerFromOptions(options) {
|
|
156
|
+
const contractSigner = contractSignerFromOptions(options);
|
|
157
|
+
if (contractSigner === undefined) {
|
|
158
|
+
throw new Error('No signer provided for signing!\nPlease provide a stringified JWK or Ethereum private key with `--private-key` or the file path of an arweave.jwk.json or eth.private.key.txt file with `--wallet-file`');
|
|
159
|
+
}
|
|
160
|
+
return contractSigner;
|
|
142
161
|
}
|
|
143
162
|
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
144
163
|
function requiredAoSignerFromOptions(options) {
|
|
@@ -152,6 +171,7 @@ function writeARIOFromOptions(options) {
|
|
|
152
171
|
ario: index_js_1.ARIO.init({
|
|
153
172
|
process: aoProcessFromOptions(options),
|
|
154
173
|
signer,
|
|
174
|
+
paymentUrl: options.paymentUrl,
|
|
155
175
|
}),
|
|
156
176
|
signerAddress,
|
|
157
177
|
};
|
|
@@ -175,10 +195,9 @@ function addressFromOptions(options) {
|
|
|
175
195
|
if (options.address !== undefined) {
|
|
176
196
|
return options.address;
|
|
177
197
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return jwkToAddress(jwk);
|
|
198
|
+
const signer = contractSignerFromOptions(options);
|
|
199
|
+
if (signer !== undefined) {
|
|
200
|
+
return signer.signerAddress;
|
|
182
201
|
}
|
|
183
202
|
return undefined;
|
|
184
203
|
}
|
|
@@ -312,6 +331,9 @@ function requiredMARIOFromOptions(options, key) {
|
|
|
312
331
|
}
|
|
313
332
|
exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
|
|
314
333
|
async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
334
|
+
if (costDetailsParams.fundFrom === 'turbo') {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
315
337
|
const costDetails = await ario.getCostDetails(costDetailsParams);
|
|
316
338
|
if (costDetails.fundingPlan) {
|
|
317
339
|
if (costDetails.fundingPlan.shortfall > 0) {
|
|
@@ -75,14 +75,14 @@ class ANTVersionsWritable extends ANTVersionsReadable {
|
|
|
75
75
|
super(config);
|
|
76
76
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
77
77
|
}
|
|
78
|
-
async addVersion(
|
|
78
|
+
async addVersion({ version, moduleId, luaSourceId, notes, }, { tags }) {
|
|
79
79
|
return this.process.send({
|
|
80
80
|
tags: (0, arweave_js_1.pruneTags)([
|
|
81
81
|
{ name: 'Action', value: 'Add-Version' },
|
|
82
|
-
{ name: 'Version', value:
|
|
83
|
-
{ name: 'Module-Id', value:
|
|
84
|
-
{ name: 'Lua-Source-Id', value:
|
|
85
|
-
{ name: 'Notes', value:
|
|
82
|
+
{ name: 'Version', value: version },
|
|
83
|
+
{ name: 'Module-Id', value: moduleId },
|
|
84
|
+
{ name: 'Lua-Source-Id', value: luaSourceId },
|
|
85
|
+
{ name: 'Notes', value: notes },
|
|
86
86
|
...(tags ?? []),
|
|
87
87
|
]),
|
|
88
88
|
signer: this.signer,
|
|
@@ -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,16 @@
|
|
|
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");
|
|
13
|
+
const turbo_js_1 = require("./turbo.js");
|
|
11
14
|
class ARIO {
|
|
12
15
|
// Implementation
|
|
13
16
|
static init(config) {
|
|
@@ -16,12 +19,63 @@ class ARIO {
|
|
|
16
19
|
}
|
|
17
20
|
return new ARIOReadable(config);
|
|
18
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
|
+
}
|
|
19
72
|
}
|
|
20
73
|
exports.ARIO = ARIO;
|
|
21
74
|
class ARIOReadable {
|
|
22
75
|
process;
|
|
23
76
|
epochSettings;
|
|
24
77
|
arweave;
|
|
78
|
+
paymentProvider; // TODO: this could be an array/map of payment providers
|
|
25
79
|
constructor(config) {
|
|
26
80
|
this.arweave = config?.arweave ?? arweave_js_2.defaultArweave;
|
|
27
81
|
if (config === undefined || Object.keys(config).length === 0) {
|
|
@@ -29,10 +83,10 @@ class ARIOReadable {
|
|
|
29
83
|
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
30
84
|
});
|
|
31
85
|
}
|
|
32
|
-
else if ((0,
|
|
86
|
+
else if ((0, index_js_1.isProcessConfiguration)(config)) {
|
|
33
87
|
this.process = config.process;
|
|
34
88
|
}
|
|
35
|
-
else if ((0,
|
|
89
|
+
else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
|
|
36
90
|
this.process = new ao_process_js_1.AOProcess({
|
|
37
91
|
processId: config.processId,
|
|
38
92
|
});
|
|
@@ -40,6 +94,9 @@ class ARIOReadable {
|
|
|
40
94
|
else {
|
|
41
95
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
42
96
|
}
|
|
97
|
+
this.paymentProvider = new turbo_js_1.TurboArNSPaymentProvider({
|
|
98
|
+
paymentUrl: config?.paymentUrl,
|
|
99
|
+
});
|
|
43
100
|
}
|
|
44
101
|
async getInfo() {
|
|
45
102
|
return this.process.read({
|
|
@@ -371,6 +428,20 @@ class ARIOReadable {
|
|
|
371
428
|
// TODO: Can overload this function to refine different types of cost details params
|
|
372
429
|
async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
|
|
373
430
|
const replacedBuyRecordWithBuyName = intent === 'Buy-Record' ? 'Buy-Name' : intent;
|
|
431
|
+
if (fundFrom === 'turbo') {
|
|
432
|
+
const { mARIO, winc } = await this.paymentProvider.getArNSPriceDetails({
|
|
433
|
+
intent: replacedBuyRecordWithBuyName,
|
|
434
|
+
name,
|
|
435
|
+
quantity,
|
|
436
|
+
type,
|
|
437
|
+
years,
|
|
438
|
+
});
|
|
439
|
+
return {
|
|
440
|
+
tokenCost: +mARIO,
|
|
441
|
+
wincQty: winc,
|
|
442
|
+
discounts: [],
|
|
443
|
+
};
|
|
444
|
+
}
|
|
374
445
|
const allTags = [
|
|
375
446
|
{ name: 'Action', value: 'Cost-Details' },
|
|
376
447
|
{
|
|
@@ -538,7 +609,8 @@ class ARIOReadable {
|
|
|
538
609
|
exports.ARIOReadable = ARIOReadable;
|
|
539
610
|
class ARIOWriteable extends ARIOReadable {
|
|
540
611
|
signer;
|
|
541
|
-
|
|
612
|
+
paymentProvider;
|
|
613
|
+
constructor({ signer, paymentUrl, ...config }) {
|
|
542
614
|
if (config === undefined) {
|
|
543
615
|
super({
|
|
544
616
|
process: new ao_process_js_1.AOProcess({
|
|
@@ -550,6 +622,10 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
550
622
|
super(config);
|
|
551
623
|
}
|
|
552
624
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
625
|
+
this.paymentProvider = new turbo_js_1.TurboArNSPaymentProvider({
|
|
626
|
+
signer: signer,
|
|
627
|
+
paymentUrl,
|
|
628
|
+
});
|
|
553
629
|
}
|
|
554
630
|
async transfer({ target, qty, }, options) {
|
|
555
631
|
const { tags = [] } = options || {};
|
|
@@ -824,6 +900,12 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
824
900
|
});
|
|
825
901
|
}
|
|
826
902
|
async buyRecord(params, options) {
|
|
903
|
+
if (params.fundFrom === 'turbo') {
|
|
904
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
905
|
+
intent: 'Buy-Name',
|
|
906
|
+
...params,
|
|
907
|
+
});
|
|
908
|
+
}
|
|
827
909
|
const { tags = [] } = options || {};
|
|
828
910
|
const allTags = [
|
|
829
911
|
...tags,
|
|
@@ -848,6 +930,12 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
848
930
|
* @returns {Promise<AoMessageResult>} The result of the upgrade
|
|
849
931
|
*/
|
|
850
932
|
async upgradeRecord(params, options) {
|
|
933
|
+
if (params.fundFrom === 'turbo') {
|
|
934
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
935
|
+
intent: 'Upgrade-Name',
|
|
936
|
+
name: params.name,
|
|
937
|
+
});
|
|
938
|
+
}
|
|
851
939
|
const { tags = [] } = options || {};
|
|
852
940
|
const allTags = [
|
|
853
941
|
...tags,
|
|
@@ -870,6 +958,12 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
870
958
|
* @returns {Promise<AoMessageResult>} The result of the extension
|
|
871
959
|
*/
|
|
872
960
|
async extendLease(params, options) {
|
|
961
|
+
if (params.fundFrom === 'turbo') {
|
|
962
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
963
|
+
intent: 'Extend-Lease',
|
|
964
|
+
...params,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
873
967
|
const { tags = [] } = options || {};
|
|
874
968
|
const allTags = [
|
|
875
969
|
...tags,
|
|
@@ -884,6 +978,12 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
884
978
|
});
|
|
885
979
|
}
|
|
886
980
|
async increaseUndernameLimit(params, options) {
|
|
981
|
+
if (params.fundFrom === 'turbo') {
|
|
982
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
983
|
+
intent: 'Increase-Undername-Limit',
|
|
984
|
+
...params,
|
|
985
|
+
});
|
|
986
|
+
}
|
|
887
987
|
const { tags = [] } = options || {};
|
|
888
988
|
const allTags = [
|
|
889
989
|
...tags,
|
|
@@ -920,6 +1020,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
920
1020
|
});
|
|
921
1021
|
}
|
|
922
1022
|
async requestPrimaryName(params, options) {
|
|
1023
|
+
if (params.fundFrom === 'turbo') {
|
|
1024
|
+
throw new Error('Turbo funding is not yet supported for primary name requests');
|
|
1025
|
+
}
|
|
923
1026
|
const { tags = [] } = options || {};
|
|
924
1027
|
const allTags = [
|
|
925
1028
|
...tags,
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TurboArNSPaymentProvider = exports.signedRequestHeadersFromSigner = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const arbundles_1 = require("@dha-team/arbundles");
|
|
20
|
+
const uuid_1 = require("uuid");
|
|
21
|
+
const token_js_1 = require("../types/token.js");
|
|
22
|
+
const base64_js_1 = require("../utils/base64.js");
|
|
23
|
+
const http_client_js_1 = require("../utils/http-client.js");
|
|
24
|
+
const url_js_1 = require("../utils/url.js");
|
|
25
|
+
const logger_js_1 = require("./logger.js");
|
|
26
|
+
async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)(), }) {
|
|
27
|
+
await signer.setPublicKey?.();
|
|
28
|
+
const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
|
|
29
|
+
let publicKey;
|
|
30
|
+
switch (signer.signatureType) {
|
|
31
|
+
case arbundles_1.SignatureConfig.ARWEAVE:
|
|
32
|
+
publicKey = (0, base64_js_1.toB64Url)(signer.publicKey);
|
|
33
|
+
break;
|
|
34
|
+
case arbundles_1.SignatureConfig.ETHEREUM:
|
|
35
|
+
publicKey = '0x' + signer.publicKey.toString('hex');
|
|
36
|
+
break;
|
|
37
|
+
// TODO: solana sig support
|
|
38
|
+
// case SignatureConfig.SOLANA:
|
|
39
|
+
// case SignatureConfig.ED25519:
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unsupported signer type for signing requests: ${signer.signatureType}`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
'x-public-key': publicKey,
|
|
45
|
+
'x-nonce': nonce,
|
|
46
|
+
'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
|
|
47
|
+
'x-signature-type': signer.signatureType,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
51
|
+
class TurboArNSPaymentProvider {
|
|
52
|
+
paymentUrl;
|
|
53
|
+
axios;
|
|
54
|
+
logger;
|
|
55
|
+
signer;
|
|
56
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = (0, http_client_js_1.createAxiosInstance)(), logger = logger_js_1.Logger.default, signer, }) {
|
|
57
|
+
this.paymentUrl = paymentUrl;
|
|
58
|
+
this.axios = axios;
|
|
59
|
+
this.logger = logger;
|
|
60
|
+
this.signer = signer;
|
|
61
|
+
}
|
|
62
|
+
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
63
|
+
const url = (0, url_js_1.urlWithSearchParams)({
|
|
64
|
+
baseUrl: `${this.paymentUrl}/v1/arns/price/${intent}/${name}`,
|
|
65
|
+
params: {
|
|
66
|
+
increaseQty: quantity,
|
|
67
|
+
type,
|
|
68
|
+
years,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
const { data, status } = await this.axios.get(url);
|
|
72
|
+
this.logger.debug('getArNSPriceDetails', {
|
|
73
|
+
intent,
|
|
74
|
+
name,
|
|
75
|
+
quantity,
|
|
76
|
+
type,
|
|
77
|
+
years,
|
|
78
|
+
data,
|
|
79
|
+
status,
|
|
80
|
+
});
|
|
81
|
+
if (status !== 200) {
|
|
82
|
+
throw new Error('Failed to get ArNS purchase price ' + JSON.stringify(data));
|
|
83
|
+
}
|
|
84
|
+
if (!data.winc || !data.mARIO) {
|
|
85
|
+
throw new Error('Invalid response from Turbo ' + JSON.stringify(data));
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
winc: data.winc,
|
|
89
|
+
mARIO: new token_js_1.mARIOToken(+data.mARIO),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async getPrice(params) {
|
|
93
|
+
const { winc } = await this.getArNSPriceDetails(params);
|
|
94
|
+
return +winc;
|
|
95
|
+
}
|
|
96
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
97
|
+
if (!this.signer) {
|
|
98
|
+
throw new Error('Signer required for initiating ArNS purchase with Turbo');
|
|
99
|
+
}
|
|
100
|
+
const url = (0, url_js_1.urlWithSearchParams)({
|
|
101
|
+
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
102
|
+
params: {
|
|
103
|
+
increaseQty: quantity,
|
|
104
|
+
processId,
|
|
105
|
+
type,
|
|
106
|
+
years,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
const headers = await signedRequestHeadersFromSigner({
|
|
110
|
+
signer: this.signer,
|
|
111
|
+
});
|
|
112
|
+
const { data, status } = await this.axios.post(url, null, {
|
|
113
|
+
headers,
|
|
114
|
+
});
|
|
115
|
+
this.logger.debug('Initiated ArNS purchase', {
|
|
116
|
+
intent,
|
|
117
|
+
name,
|
|
118
|
+
quantity,
|
|
119
|
+
processId,
|
|
120
|
+
type,
|
|
121
|
+
years,
|
|
122
|
+
data,
|
|
123
|
+
status,
|
|
124
|
+
});
|
|
125
|
+
if (status !== 200) {
|
|
126
|
+
throw new Error('Failed to initiate ArNS purchase ' + JSON.stringify(data));
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
id: data.arioWriteResult.id,
|
|
130
|
+
result: data.purchaseReceipt,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.TurboArNSPaymentProvider = TurboArNSPaymentProvider;
|
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);
|