@ar.io/sdk 3.10.0 → 3.11.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 +66 -125
- package/bundles/web.bundle.min.js +130 -125
- package/lib/cjs/cli/options.js +12 -0
- package/lib/cjs/cli/utils.js +32 -10
- package/lib/cjs/cli/wayfinder.js +34 -0
- package/lib/cjs/common/ant-versions.js +5 -5
- package/lib/cjs/common/index.js +2 -0
- package/lib/cjs/common/io.js +64 -1
- package/lib/cjs/common/turbo.js +208 -0
- package/lib/cjs/common/wayfinder/gateways.js +75 -0
- package/lib/cjs/common/wayfinder/index.js +38 -0
- package/lib/cjs/common/wayfinder/routers/fixed.js +14 -0
- package/lib/cjs/common/wayfinder/routers/fixed.test.js +14 -0
- package/lib/cjs/common/wayfinder/routers/priority.js +38 -0
- package/lib/cjs/common/wayfinder/routers/priority.test.js +155 -0
- package/lib/cjs/common/wayfinder/routers/random.js +23 -0
- package/lib/cjs/common/wayfinder/routers/random.test.js +104 -0
- package/lib/cjs/common/wayfinder/routers/simple-cache.js +25 -0
- package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +41 -0
- package/lib/cjs/common/wayfinder/wayfinder.js +174 -0
- package/lib/cjs/common/wayfinder/wayfinder.test.js +253 -0
- package/lib/cjs/types/ant.js +12 -1
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/io.js +1 -1
- package/lib/cjs/types/wayfinder.js +2 -0
- package/lib/cjs/utils/ao.js +5 -0
- package/lib/cjs/utils/random.js +30 -0
- package/lib/cjs/utils/url.js +28 -0
- package/lib/cjs/utils/url.test.js +24 -0
- package/lib/cjs/utils/utils.test.js +8 -8
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/web/index.js +3 -1
- package/lib/esm/cli/options.js +12 -0
- package/lib/esm/cli/utils.js +31 -10
- package/lib/esm/cli/wayfinder.js +32 -0
- package/lib/esm/common/ant-versions.js +5 -5
- package/lib/esm/common/index.js +2 -0
- package/lib/esm/common/io.js +64 -1
- package/lib/esm/common/turbo.js +200 -0
- package/lib/esm/common/wayfinder/gateways.js +69 -0
- package/lib/esm/common/wayfinder/index.js +22 -0
- package/lib/esm/common/wayfinder/routers/fixed.js +10 -0
- package/lib/esm/common/wayfinder/routers/fixed.test.js +12 -0
- package/lib/esm/common/wayfinder/routers/priority.js +34 -0
- package/lib/esm/common/wayfinder/routers/priority.test.js +153 -0
- package/lib/esm/common/wayfinder/routers/random.js +19 -0
- package/lib/esm/common/wayfinder/routers/random.test.js +102 -0
- package/lib/esm/common/wayfinder/routers/simple-cache.js +21 -0
- package/lib/esm/common/wayfinder/routers/simple-cache.test.js +39 -0
- package/lib/esm/common/wayfinder/wayfinder.js +168 -0
- package/lib/esm/common/wayfinder/wayfinder.test.js +248 -0
- package/lib/esm/types/ant.js +11 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/io.js +1 -1
- package/lib/esm/types/wayfinder.js +1 -0
- package/lib/esm/utils/ao.js +5 -0
- package/lib/esm/utils/random.js +26 -0
- package/lib/esm/utils/url.js +24 -0
- package/lib/esm/utils/url.test.js +19 -0
- package/lib/esm/utils/utils.test.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/web/index.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/cli/wayfinder.d.ts +1 -0
- package/lib/types/common/ant-versions.d.ts +3 -6
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/io.d.ts +9 -7
- package/lib/types/common/turbo.d.ts +62 -0
- package/lib/types/common/wayfinder/gateways.d.ts +44 -0
- package/lib/types/common/wayfinder/index.d.ts +20 -0
- package/lib/types/common/wayfinder/routers/fixed.d.ts +24 -0
- package/lib/types/common/wayfinder/routers/fixed.test.d.ts +1 -0
- package/lib/types/common/wayfinder/routers/priority.d.ts +33 -0
- package/lib/types/common/wayfinder/routers/priority.test.d.ts +1 -0
- package/lib/types/common/wayfinder/routers/random.d.ts +27 -0
- package/lib/types/common/wayfinder/routers/random.test.d.ts +1 -0
- package/lib/types/common/wayfinder/routers/simple-cache.d.ts +28 -0
- package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +1 -0
- package/lib/types/common/wayfinder/wayfinder.d.ts +120 -0
- package/lib/types/common/wayfinder/wayfinder.test.d.ts +1 -0
- package/lib/types/types/ant.d.ts +53 -1
- package/lib/types/types/common.d.ts +7 -2
- package/lib/types/types/index.d.ts +1 -0
- package/lib/types/types/io.d.ts +7 -5
- package/lib/types/types/wayfinder.d.ts +19 -0
- package/lib/types/utils/ao.d.ts +1 -12
- package/lib/types/utils/random.d.ts +7 -0
- 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/lib/types/web/index.d.ts +1 -1
- package/package.json +5 -3
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
|
@@ -13,6 +13,7 @@ exports.requiredJwkFromOptions = requiredJwkFromOptions;
|
|
|
13
13
|
exports.jwkToAddress = jwkToAddress;
|
|
14
14
|
exports.getLoggerFromOptions = getLoggerFromOptions;
|
|
15
15
|
exports.readARIOFromOptions = readARIOFromOptions;
|
|
16
|
+
exports.contractSignerFromOptions = contractSignerFromOptions;
|
|
16
17
|
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
17
18
|
exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
|
|
18
19
|
exports.writeARIOFromOptions = writeARIOFromOptions;
|
|
@@ -60,6 +61,7 @@ exports.assertLockLengthInRange = assertLockLengthInRange;
|
|
|
60
61
|
* See the License for the specific language governing permissions and
|
|
61
62
|
* limitations under the License.
|
|
62
63
|
*/
|
|
64
|
+
const arbundles_1 = require("@dha-team/arbundles");
|
|
63
65
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
64
66
|
const commander_1 = require("commander");
|
|
65
67
|
const fs_1 = require("fs");
|
|
@@ -124,7 +126,7 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
|
124
126
|
}
|
|
125
127
|
return index_js_1.ARIO_MAINNET_PROCESS_ID;
|
|
126
128
|
}
|
|
127
|
-
function
|
|
129
|
+
function walletFromOptions({ privateKey, walletFile, }) {
|
|
128
130
|
if (privateKey !== undefined) {
|
|
129
131
|
return JSON.parse(privateKey);
|
|
130
132
|
}
|
|
@@ -134,7 +136,7 @@ function jwkFromOptions({ privateKey, walletFile, }) {
|
|
|
134
136
|
return undefined;
|
|
135
137
|
}
|
|
136
138
|
function requiredJwkFromOptions(options) {
|
|
137
|
-
const jwk =
|
|
139
|
+
const jwk = walletFromOptions(options);
|
|
138
140
|
if (jwk === undefined) {
|
|
139
141
|
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`');
|
|
140
142
|
}
|
|
@@ -164,13 +166,30 @@ function readARIOFromOptions(options) {
|
|
|
164
166
|
setLoggerIfDebug(options);
|
|
165
167
|
return index_js_1.ARIO.init({
|
|
166
168
|
process: aoProcessFromOptions(options),
|
|
169
|
+
paymentUrl: options.paymentUrl,
|
|
167
170
|
});
|
|
168
171
|
}
|
|
169
|
-
function
|
|
172
|
+
function contractSignerFromOptions(options) {
|
|
173
|
+
const wallet = walletFromOptions(options);
|
|
174
|
+
if (wallet === undefined) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const token = options.token ?? 'arweave';
|
|
178
|
+
if (token === 'ethereum') {
|
|
179
|
+
const signer = new arbundles_1.EthereumSigner(wallet);
|
|
180
|
+
// For EthereumSigner, we need to convert the JWK to a string
|
|
181
|
+
return { signer, signerAddress: signer.publicKey.toString('hex') };
|
|
182
|
+
}
|
|
170
183
|
// TODO: Support other wallet types
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
184
|
+
const signer = new index_js_1.ArweaveSigner(wallet);
|
|
185
|
+
return { signer, signerAddress: jwkToAddress(wallet) };
|
|
186
|
+
}
|
|
187
|
+
function requiredContractSignerFromOptions(options) {
|
|
188
|
+
const contractSigner = contractSignerFromOptions(options);
|
|
189
|
+
if (contractSigner === undefined) {
|
|
190
|
+
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`');
|
|
191
|
+
}
|
|
192
|
+
return contractSigner;
|
|
174
193
|
}
|
|
175
194
|
function requiredAoSignerFromOptions(options) {
|
|
176
195
|
return (0, index_js_1.createAoSigner)(requiredContractSignerFromOptions(options).signer);
|
|
@@ -182,6 +201,7 @@ function writeARIOFromOptions(options) {
|
|
|
182
201
|
ario: index_js_1.ARIO.init({
|
|
183
202
|
process: aoProcessFromOptions(options),
|
|
184
203
|
signer,
|
|
204
|
+
paymentUrl: options.paymentUrl,
|
|
185
205
|
}),
|
|
186
206
|
signerAddress,
|
|
187
207
|
};
|
|
@@ -202,10 +222,9 @@ function addressFromOptions(options) {
|
|
|
202
222
|
if (options.address !== undefined) {
|
|
203
223
|
return options.address;
|
|
204
224
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return jwkToAddress(jwk);
|
|
225
|
+
const signer = contractSignerFromOptions(options);
|
|
226
|
+
if (signer !== undefined) {
|
|
227
|
+
return signer.signerAddress;
|
|
209
228
|
}
|
|
210
229
|
return undefined;
|
|
211
230
|
}
|
|
@@ -328,6 +347,9 @@ function requiredMARIOFromOptions(options, key) {
|
|
|
328
347
|
return new index_js_1.ARIOToken(+options[key]).toMARIO();
|
|
329
348
|
}
|
|
330
349
|
async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
350
|
+
if (costDetailsParams.fundFrom === 'turbo') {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
331
353
|
const costDetails = await ario.getCostDetails(costDetailsParams);
|
|
332
354
|
if (costDetails.fundingPlan) {
|
|
333
355
|
if (costDetails.fundingPlan.shortfall > 0) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
const commander_1 = require("commander");
|
|
19
|
+
const version_js_1 = require("../version.js");
|
|
20
|
+
const options_js_1 = require("./options.js");
|
|
21
|
+
const utils_js_1 = require("./utils.js");
|
|
22
|
+
(0, utils_js_1.applyOptions)(commander_1.program
|
|
23
|
+
.name('ar.io')
|
|
24
|
+
.version(version_js_1.version)
|
|
25
|
+
.description('AR.IO Network CLI')
|
|
26
|
+
.helpCommand(true), options_js_1.globalOptions);
|
|
27
|
+
(0, utils_js_1.makeCommand)({
|
|
28
|
+
name: '',
|
|
29
|
+
description: 'Get network info',
|
|
30
|
+
action: () => {
|
|
31
|
+
console.log('wayfinder');
|
|
32
|
+
return Promise.resolve({});
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -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,
|
package/lib/cjs/common/index.js
CHANGED
package/lib/cjs/common/io.js
CHANGED
|
@@ -25,6 +25,7 @@ const arweave_js_2 = require("./arweave.js");
|
|
|
25
25
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
26
26
|
const error_js_1 = require("./error.js");
|
|
27
27
|
const faucet_js_1 = require("./faucet.js");
|
|
28
|
+
const turbo_js_1 = require("./turbo.js");
|
|
28
29
|
class ARIO {
|
|
29
30
|
// Implementation
|
|
30
31
|
static init(config) {
|
|
@@ -89,6 +90,7 @@ class ARIOReadable {
|
|
|
89
90
|
process;
|
|
90
91
|
epochSettings;
|
|
91
92
|
arweave;
|
|
93
|
+
paymentProvider; // TODO: this could be an array/map of payment providers
|
|
92
94
|
constructor(config) {
|
|
93
95
|
this.arweave = config?.arweave ?? arweave_js_2.defaultArweave;
|
|
94
96
|
if (config === undefined || Object.keys(config).length === 0) {
|
|
@@ -107,6 +109,9 @@ class ARIOReadable {
|
|
|
107
109
|
else {
|
|
108
110
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
109
111
|
}
|
|
112
|
+
this.paymentProvider = turbo_js_1.TurboArNSPaymentFactory.init({
|
|
113
|
+
paymentUrl: config?.paymentUrl,
|
|
114
|
+
});
|
|
110
115
|
}
|
|
111
116
|
async getInfo() {
|
|
112
117
|
return this.process.read({
|
|
@@ -438,6 +443,20 @@ class ARIOReadable {
|
|
|
438
443
|
// TODO: Can overload this function to refine different types of cost details params
|
|
439
444
|
async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
|
|
440
445
|
const replacedBuyRecordWithBuyName = intent === 'Buy-Record' ? 'Buy-Name' : intent;
|
|
446
|
+
if (fundFrom === 'turbo') {
|
|
447
|
+
const { mARIO, winc } = await this.paymentProvider.getArNSPriceDetails({
|
|
448
|
+
intent: replacedBuyRecordWithBuyName,
|
|
449
|
+
name,
|
|
450
|
+
quantity,
|
|
451
|
+
type,
|
|
452
|
+
years,
|
|
453
|
+
});
|
|
454
|
+
return {
|
|
455
|
+
tokenCost: +mARIO,
|
|
456
|
+
wincQty: winc,
|
|
457
|
+
discounts: [],
|
|
458
|
+
};
|
|
459
|
+
}
|
|
441
460
|
const allTags = [
|
|
442
461
|
{ name: 'Action', value: 'Cost-Details' },
|
|
443
462
|
{
|
|
@@ -605,7 +624,8 @@ class ARIOReadable {
|
|
|
605
624
|
exports.ARIOReadable = ARIOReadable;
|
|
606
625
|
class ARIOWriteable extends ARIOReadable {
|
|
607
626
|
signer;
|
|
608
|
-
|
|
627
|
+
paymentProvider;
|
|
628
|
+
constructor({ signer, paymentUrl, ...config }) {
|
|
609
629
|
if (config === undefined) {
|
|
610
630
|
super({
|
|
611
631
|
process: new ao_process_js_1.AOProcess({
|
|
@@ -617,6 +637,10 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
617
637
|
super(config);
|
|
618
638
|
}
|
|
619
639
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
640
|
+
this.paymentProvider = turbo_js_1.TurboArNSPaymentFactory.init({
|
|
641
|
+
signer: (0, turbo_js_1.isTurboArNSSigner)(signer) ? signer : undefined,
|
|
642
|
+
paymentUrl,
|
|
643
|
+
});
|
|
620
644
|
}
|
|
621
645
|
async transfer({ target, qty, }, options) {
|
|
622
646
|
const { tags = [] } = options || {};
|
|
@@ -891,6 +915,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
891
915
|
});
|
|
892
916
|
}
|
|
893
917
|
async buyRecord(params, options) {
|
|
918
|
+
if (params.fundFrom === 'turbo') {
|
|
919
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
920
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
921
|
+
}
|
|
922
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
923
|
+
intent: 'Buy-Name',
|
|
924
|
+
...params,
|
|
925
|
+
});
|
|
926
|
+
}
|
|
894
927
|
const { tags = [] } = options || {};
|
|
895
928
|
const allTags = [
|
|
896
929
|
...tags,
|
|
@@ -915,6 +948,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
915
948
|
* @returns {Promise<AoMessageResult>} The result of the upgrade
|
|
916
949
|
*/
|
|
917
950
|
async upgradeRecord(params, options) {
|
|
951
|
+
if (params.fundFrom === 'turbo') {
|
|
952
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
953
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
954
|
+
}
|
|
955
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
956
|
+
intent: 'Upgrade-Name',
|
|
957
|
+
name: params.name,
|
|
958
|
+
});
|
|
959
|
+
}
|
|
918
960
|
const { tags = [] } = options || {};
|
|
919
961
|
const allTags = [
|
|
920
962
|
...tags,
|
|
@@ -937,6 +979,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
937
979
|
* @returns {Promise<AoMessageResult>} The result of the extension
|
|
938
980
|
*/
|
|
939
981
|
async extendLease(params, options) {
|
|
982
|
+
if (params.fundFrom === 'turbo') {
|
|
983
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
984
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
985
|
+
}
|
|
986
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
987
|
+
intent: 'Extend-Lease',
|
|
988
|
+
...params,
|
|
989
|
+
});
|
|
990
|
+
}
|
|
940
991
|
const { tags = [] } = options || {};
|
|
941
992
|
const allTags = [
|
|
942
993
|
...tags,
|
|
@@ -951,6 +1002,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
951
1002
|
});
|
|
952
1003
|
}
|
|
953
1004
|
async increaseUndernameLimit(params, options) {
|
|
1005
|
+
if (params.fundFrom === 'turbo') {
|
|
1006
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
1007
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
1008
|
+
}
|
|
1009
|
+
return this.paymentProvider.initiateArNSPurchase({
|
|
1010
|
+
intent: 'Increase-Undername-Limit',
|
|
1011
|
+
...params,
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
954
1014
|
const { tags = [] } = options || {};
|
|
955
1015
|
const allTags = [
|
|
956
1016
|
...tags,
|
|
@@ -987,6 +1047,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
987
1047
|
});
|
|
988
1048
|
}
|
|
989
1049
|
async requestPrimaryName(params, options) {
|
|
1050
|
+
if (params.fundFrom === 'turbo') {
|
|
1051
|
+
throw new Error('Turbo funding is not yet supported for primary name requests');
|
|
1052
|
+
}
|
|
990
1053
|
const { tags = [] } = options || {};
|
|
991
1054
|
const allTags = [
|
|
992
1055
|
...tags,
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = void 0;
|
|
4
|
+
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
5
|
+
exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
const arbundles_1 = require("@dha-team/arbundles");
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const token_js_1 = require("../types/token.js");
|
|
24
|
+
const base64_js_1 = require("../utils/base64.js");
|
|
25
|
+
const http_client_js_1 = require("../utils/http-client.js");
|
|
26
|
+
const url_js_1 = require("../utils/url.js");
|
|
27
|
+
const logger_js_1 = require("./logger.js");
|
|
28
|
+
async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)(), }) {
|
|
29
|
+
let signature = undefined;
|
|
30
|
+
let publicKey = undefined;
|
|
31
|
+
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
32
|
+
? arbundles_1.SignatureConfig.ARWEAVE
|
|
33
|
+
: signer.signatureType;
|
|
34
|
+
// equivalent to window.arweaveWallet
|
|
35
|
+
if (isWanderArweaveBrowserSigner(signer)) {
|
|
36
|
+
signature = (0, base64_js_1.toB64Url)(Buffer.from(await signer.signMessage(Uint8Array.from(Buffer.from(nonce)))));
|
|
37
|
+
}
|
|
38
|
+
else if (signer instanceof arbundles_1.ArconnectSigner) {
|
|
39
|
+
signature = (0, base64_js_1.toB64Url)(Buffer.from(await signer['signer'].signMessage(Uint8Array.from(Buffer.from(nonce)))));
|
|
40
|
+
}
|
|
41
|
+
else if (signer instanceof arbundles_1.ArweaveSigner ||
|
|
42
|
+
signer instanceof arbundles_1.EthereumSigner ||
|
|
43
|
+
signer instanceof arbundles_1.InjectedEthereumSigner) {
|
|
44
|
+
if ('setPublicKey' in signer && signer['publicKey'] === undefined) {
|
|
45
|
+
await signer.setPublicKey();
|
|
46
|
+
}
|
|
47
|
+
signature = (0, base64_js_1.toB64Url)(Buffer.from(await signer.sign(Uint8Array.from(Buffer.from(nonce)))));
|
|
48
|
+
}
|
|
49
|
+
switch (signatureType) {
|
|
50
|
+
case arbundles_1.SignatureConfig.ARWEAVE:
|
|
51
|
+
if (isWanderArweaveBrowserSigner(signer)) {
|
|
52
|
+
publicKey = await signer.getActivePublicKey();
|
|
53
|
+
}
|
|
54
|
+
else if ('setPublicKey' in signer) {
|
|
55
|
+
await signer.setPublicKey();
|
|
56
|
+
publicKey = (0, base64_js_1.toB64Url)(signer.publicKey);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case arbundles_1.SignatureConfig.ETHEREUM:
|
|
60
|
+
if ('publicKey' in signer) {
|
|
61
|
+
publicKey = '0x' + signer.publicKey.toString('hex');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error('Public key not found');
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
// TODO: solana sig support
|
|
68
|
+
// case SignatureConfig.SOLANA:
|
|
69
|
+
// case SignatureConfig.ED25519:
|
|
70
|
+
default:
|
|
71
|
+
throw new Error(`Unsupported signer type for signing requests: ${signatureType}`);
|
|
72
|
+
}
|
|
73
|
+
if (publicKey === undefined || signature === undefined) {
|
|
74
|
+
throw new Error('Public key or signature not found');
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
'x-public-key': publicKey,
|
|
78
|
+
'x-nonce': nonce,
|
|
79
|
+
'x-signature': signature,
|
|
80
|
+
'x-signature-type': signatureType,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
class TurboArNSPaymentFactory {
|
|
84
|
+
static init(config) {
|
|
85
|
+
const { signer, paymentUrl, axios, logger } = config ?? {};
|
|
86
|
+
if (signer !== undefined) {
|
|
87
|
+
return new TurboArNSPaymentProviderAuthenticated({
|
|
88
|
+
signer,
|
|
89
|
+
paymentUrl,
|
|
90
|
+
axios,
|
|
91
|
+
logger,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return new TurboArNSPaymentProviderUnauthenticated({
|
|
95
|
+
paymentUrl,
|
|
96
|
+
axios,
|
|
97
|
+
logger,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TurboArNSPaymentFactory = TurboArNSPaymentFactory;
|
|
102
|
+
// Base class for unauthenticated operations
|
|
103
|
+
class TurboArNSPaymentProviderUnauthenticated {
|
|
104
|
+
paymentUrl;
|
|
105
|
+
axios;
|
|
106
|
+
logger;
|
|
107
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = (0, http_client_js_1.createAxiosInstance)(), logger = logger_js_1.Logger.default, }) {
|
|
108
|
+
this.paymentUrl = paymentUrl;
|
|
109
|
+
this.axios = axios;
|
|
110
|
+
this.logger = logger;
|
|
111
|
+
}
|
|
112
|
+
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
113
|
+
const url = (0, url_js_1.urlWithSearchParams)({
|
|
114
|
+
baseUrl: `${this.paymentUrl}/v1/arns/price/${intent}/${name}`,
|
|
115
|
+
params: {
|
|
116
|
+
increaseQty: quantity,
|
|
117
|
+
type,
|
|
118
|
+
years,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const { data, status } = await this.axios.get(url);
|
|
122
|
+
this.logger.debug('getArNSPriceDetails', {
|
|
123
|
+
intent,
|
|
124
|
+
name,
|
|
125
|
+
quantity,
|
|
126
|
+
type,
|
|
127
|
+
years,
|
|
128
|
+
data,
|
|
129
|
+
status,
|
|
130
|
+
});
|
|
131
|
+
if (status !== 200) {
|
|
132
|
+
throw new Error('Failed to get ArNS purchase price ' + JSON.stringify(data));
|
|
133
|
+
}
|
|
134
|
+
if (!data.winc || !data.mARIO) {
|
|
135
|
+
throw new Error('Invalid response from Turbo ' + JSON.stringify(data));
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
winc: data.winc,
|
|
139
|
+
mARIO: new token_js_1.mARIOToken(+data.mARIO),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
async getPrice(params) {
|
|
143
|
+
const { winc } = await this.getArNSPriceDetails(params);
|
|
144
|
+
return +winc;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.TurboArNSPaymentProviderUnauthenticated = TurboArNSPaymentProviderUnauthenticated;
|
|
148
|
+
// Class for authenticated operations, extending the base class
|
|
149
|
+
class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated {
|
|
150
|
+
signer;
|
|
151
|
+
constructor({ signer, ...restConfig }) {
|
|
152
|
+
super(restConfig); // Pass unauthenticated config to base class+
|
|
153
|
+
if (!isTurboArNSSigner(signer)) {
|
|
154
|
+
throw new Error('Signer must be a TurboArNSSigner');
|
|
155
|
+
}
|
|
156
|
+
this.signer = signer;
|
|
157
|
+
}
|
|
158
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
159
|
+
// Signer check is implicitly handled by requiring it in the constructor
|
|
160
|
+
const url = (0, url_js_1.urlWithSearchParams)({
|
|
161
|
+
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
162
|
+
params: {
|
|
163
|
+
increaseQty: quantity,
|
|
164
|
+
processId,
|
|
165
|
+
type,
|
|
166
|
+
years,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
const headers = await signedRequestHeadersFromSigner({
|
|
170
|
+
signer: this.signer,
|
|
171
|
+
});
|
|
172
|
+
const { data, status } = await this.axios.post(url, null, {
|
|
173
|
+
headers,
|
|
174
|
+
});
|
|
175
|
+
this.logger.debug('Initiated ArNS purchase', {
|
|
176
|
+
intent,
|
|
177
|
+
name,
|
|
178
|
+
quantity,
|
|
179
|
+
processId,
|
|
180
|
+
type,
|
|
181
|
+
years,
|
|
182
|
+
data,
|
|
183
|
+
status,
|
|
184
|
+
});
|
|
185
|
+
if (status !== 200) {
|
|
186
|
+
throw new Error('Failed to initiate ArNS purchase ' + JSON.stringify(data));
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
id: data.arioWriteResult.id,
|
|
190
|
+
result: data.purchaseReceipt,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.TurboArNSPaymentProviderAuthenticated = TurboArNSPaymentProviderAuthenticated;
|
|
195
|
+
function isWanderArweaveBrowserSigner(signer) {
|
|
196
|
+
return (typeof signer === 'object' &&
|
|
197
|
+
signer !== null &&
|
|
198
|
+
'signMessage' in signer &&
|
|
199
|
+
'getActivePublicKey' in signer);
|
|
200
|
+
}
|
|
201
|
+
function isTurboArNSSigner(signer) {
|
|
202
|
+
const isWanderWallet = isWanderArweaveBrowserSigner(signer);
|
|
203
|
+
const isSigner = signer instanceof arbundles_1.EthereumSigner ||
|
|
204
|
+
signer instanceof arbundles_1.InjectedEthereumSigner ||
|
|
205
|
+
signer instanceof arbundles_1.ArweaveSigner ||
|
|
206
|
+
signer instanceof arbundles_1.ArconnectSigner;
|
|
207
|
+
return isWanderWallet || isSigner;
|
|
208
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleCacheGatewaysProvider = exports.StaticGatewaysProvider = exports.ARIOGatewaysProvider = void 0;
|
|
4
|
+
class ARIOGatewaysProvider {
|
|
5
|
+
ario;
|
|
6
|
+
constructor({ ario }) {
|
|
7
|
+
this.ario = ario;
|
|
8
|
+
}
|
|
9
|
+
async getGateways() {
|
|
10
|
+
let cursor;
|
|
11
|
+
let attempts = 0;
|
|
12
|
+
const gateways = [];
|
|
13
|
+
do {
|
|
14
|
+
try {
|
|
15
|
+
const { items: newGateways, nextCursor } = await this.ario.getGateways({
|
|
16
|
+
limit: 1000,
|
|
17
|
+
cursor,
|
|
18
|
+
});
|
|
19
|
+
gateways.push(...newGateways);
|
|
20
|
+
cursor = nextCursor;
|
|
21
|
+
attempts = 0; // reset attempts if we get a new cursor
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error('Error fetching gateways', {
|
|
25
|
+
cursor,
|
|
26
|
+
attempts,
|
|
27
|
+
error,
|
|
28
|
+
});
|
|
29
|
+
attempts++;
|
|
30
|
+
}
|
|
31
|
+
} while (cursor !== undefined && attempts < 3);
|
|
32
|
+
// filter out any gateways that are not joined
|
|
33
|
+
return gateways.filter((g) => g.status === 'joined');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ARIOGatewaysProvider = ARIOGatewaysProvider;
|
|
37
|
+
class StaticGatewaysProvider {
|
|
38
|
+
gateways;
|
|
39
|
+
constructor({ gateways }) {
|
|
40
|
+
this.gateways = gateways;
|
|
41
|
+
}
|
|
42
|
+
async getGateways() {
|
|
43
|
+
return this.gateways;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.StaticGatewaysProvider = StaticGatewaysProvider;
|
|
47
|
+
class SimpleCacheGatewaysProvider {
|
|
48
|
+
gatewaysProvider;
|
|
49
|
+
ttlSeconds;
|
|
50
|
+
lastUpdated;
|
|
51
|
+
gatewaysCache;
|
|
52
|
+
constructor({ gatewaysProvider, ttlSeconds = 5 * 60, // 5 minutes
|
|
53
|
+
}) {
|
|
54
|
+
this.gatewaysCache = [];
|
|
55
|
+
this.gatewaysProvider = gatewaysProvider;
|
|
56
|
+
this.ttlSeconds = ttlSeconds;
|
|
57
|
+
}
|
|
58
|
+
async getGateways() {
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
if (this.gatewaysCache.length === 0 ||
|
|
61
|
+
now - this.lastUpdated > this.ttlSeconds * 1000) {
|
|
62
|
+
try {
|
|
63
|
+
// preserve the cache if the fetch fails
|
|
64
|
+
const allGateways = await this.gatewaysProvider.getGateways();
|
|
65
|
+
this.gatewaysCache = allGateways.filter((g) => g.status === 'joined');
|
|
66
|
+
this.lastUpdated = now;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error('Error fetching gateways', error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return this.gatewaysCache;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.SimpleCacheGatewaysProvider = SimpleCacheGatewaysProvider;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
19
|
+
*
|
|
20
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
* you may not use this file except in compliance with the License.
|
|
22
|
+
* You may obtain a copy of the License at
|
|
23
|
+
*
|
|
24
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
*
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
* See the License for the specific language governing permissions and
|
|
30
|
+
* limitations under the License.
|
|
31
|
+
*/
|
|
32
|
+
__exportStar(require("./wayfinder.js"), exports);
|
|
33
|
+
// routers
|
|
34
|
+
__exportStar(require("./routers/random.js"), exports);
|
|
35
|
+
__exportStar(require("./routers/priority.js"), exports);
|
|
36
|
+
__exportStar(require("./routers/fixed.js"), exports);
|
|
37
|
+
// gateways providers
|
|
38
|
+
__exportStar(require("./gateways.js"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixedGatewayRouter = void 0;
|
|
4
|
+
class FixedGatewayRouter {
|
|
5
|
+
name = 'fixed';
|
|
6
|
+
gateway;
|
|
7
|
+
constructor({ gateway }) {
|
|
8
|
+
this.gateway = gateway;
|
|
9
|
+
}
|
|
10
|
+
async getTargetGateway() {
|
|
11
|
+
return this.gateway;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.FixedGatewayRouter = FixedGatewayRouter;
|