@ar.io/sdk 3.22.0-alpha.4 → 3.22.0-alpha.6
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 +0 -47
- package/bundles/web.bundle.min.js +70 -75
- package/lib/cjs/common/hyperbeam/hb.js +2 -2
- package/lib/cjs/common/io.js +64 -0
- package/lib/cjs/common/turbo.js +24 -14
- package/lib/cjs/utils/processes.js +8 -9
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/hyperbeam/hb.js +2 -2
- package/lib/esm/common/io.js +64 -0
- package/lib/esm/common/turbo.js +23 -13
- package/lib/esm/utils/processes.js +8 -9
- package/lib/esm/version.js +1 -1
- package/lib/types/common/turbo.d.ts +5 -7
- package/lib/types/utils/processes.d.ts +4 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +4 -16
- package/lib/cjs/common/http.js +0 -40
- package/lib/cjs/utils/http-client.js +0 -48
- package/lib/esm/common/http.js +0 -36
- package/lib/esm/utils/http-client.js +0 -41
- package/lib/types/common/http.d.ts +0 -17
- package/lib/types/utils/http-client.d.ts +0 -24
|
@@ -64,7 +64,7 @@ class HB {
|
|
|
64
64
|
* const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
|
|
65
65
|
* console.log(result);
|
|
66
66
|
*/
|
|
67
|
-
async compute({ path, json =
|
|
67
|
+
async compute({ path, json = true, }) {
|
|
68
68
|
return this.fetchHyperbeamPath({
|
|
69
69
|
path: `${this.url}/${this.processId}~process@1.0/compute/${path}`,
|
|
70
70
|
json,
|
|
@@ -112,7 +112,7 @@ class HB {
|
|
|
112
112
|
return false;
|
|
113
113
|
})
|
|
114
114
|
.catch((error) => {
|
|
115
|
-
this.logger.
|
|
115
|
+
this.logger.error('Failed to check HyperBeam compatibility', {
|
|
116
116
|
cause: error,
|
|
117
117
|
});
|
|
118
118
|
this.isHyperBeamCompatible = false;
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -590,6 +590,30 @@ class ARIOReadable {
|
|
|
590
590
|
});
|
|
591
591
|
}
|
|
592
592
|
async getPrimaryNameRequest(params) {
|
|
593
|
+
if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
|
|
594
|
+
this.logger.debug('Getting primary name request from HyperBEAM', {
|
|
595
|
+
initiator: params.initiator,
|
|
596
|
+
});
|
|
597
|
+
const res = await this.hb
|
|
598
|
+
.compute({
|
|
599
|
+
path: `/primary-names/requests/${params.initiator}`,
|
|
600
|
+
})
|
|
601
|
+
.catch((error) => {
|
|
602
|
+
this.logger.error('Failed to get primary name request from HyperBEAM', {
|
|
603
|
+
cause: error,
|
|
604
|
+
});
|
|
605
|
+
return null;
|
|
606
|
+
});
|
|
607
|
+
if (res !== null) {
|
|
608
|
+
// Ensure initiator is included in the result
|
|
609
|
+
return {
|
|
610
|
+
...res,
|
|
611
|
+
initiator: params.initiator,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
// else fall through to CU read
|
|
615
|
+
this.logger.info('Failed to get primary name request from HyperBEAM, failing over to CU read', { initiator: params.initiator });
|
|
616
|
+
}
|
|
593
617
|
const allTags = [
|
|
594
618
|
{ name: 'Action', value: 'Primary-Name-Request' },
|
|
595
619
|
{
|
|
@@ -610,6 +634,46 @@ class ARIOReadable {
|
|
|
610
634
|
});
|
|
611
635
|
}
|
|
612
636
|
async getPrimaryName(params) {
|
|
637
|
+
if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
|
|
638
|
+
this.logger.debug('Getting primary name from HyperBEAM', { params });
|
|
639
|
+
try {
|
|
640
|
+
let owner;
|
|
641
|
+
if ('name' in params) {
|
|
642
|
+
// Step 1: Get owner from /primary-names/names/<name>
|
|
643
|
+
owner = await this.hb.compute({
|
|
644
|
+
path: `/primary-names/names/${params.name}`,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
// If given address, skip the /names/name query
|
|
649
|
+
owner = params.address;
|
|
650
|
+
}
|
|
651
|
+
// Step 2: Get {name, startTimestamp} from /primary-names/owners/<owner>
|
|
652
|
+
const ownerData = await this.hb.compute({
|
|
653
|
+
path: `/primary-names/owners/${owner}`,
|
|
654
|
+
});
|
|
655
|
+
const name = ownerData.name;
|
|
656
|
+
const startTimestamp = ownerData.startTimestamp;
|
|
657
|
+
// Step 3: Get processId from getArNSRecord
|
|
658
|
+
const record = await this.getArNSRecord({ name });
|
|
659
|
+
const processId = record.processId;
|
|
660
|
+
// Combine all data
|
|
661
|
+
const result = {
|
|
662
|
+
owner,
|
|
663
|
+
name,
|
|
664
|
+
startTimestamp,
|
|
665
|
+
processId,
|
|
666
|
+
};
|
|
667
|
+
return result;
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
this.logger.error('Failed to get primary name from HyperBEAM', {
|
|
671
|
+
cause: error,
|
|
672
|
+
});
|
|
673
|
+
// Fall through to CU read
|
|
674
|
+
this.logger.info('Failed to get primary name from HyperBEAM, failing over to CU read', { params });
|
|
675
|
+
}
|
|
676
|
+
}
|
|
613
677
|
const allTags = [
|
|
614
678
|
{ name: 'Action', value: 'Primary-Name' },
|
|
615
679
|
{
|
package/lib/cjs/common/turbo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = void 0;
|
|
3
|
+
exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = exports.defaultHeaders = void 0;
|
|
4
4
|
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
5
5
|
exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
6
6
|
/**
|
|
@@ -19,13 +19,16 @@ exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
const arbundles_1 = require("@dha-team/arbundles");
|
|
22
|
-
const uuid_1 = require("uuid");
|
|
23
22
|
const token_js_1 = require("../types/token.js");
|
|
24
23
|
const base64_js_1 = require("../utils/base64.js");
|
|
25
|
-
const http_client_js_1 = require("../utils/http-client.js");
|
|
26
24
|
const url_js_1 = require("../utils/url.js");
|
|
25
|
+
const version_js_1 = require("../version.js");
|
|
27
26
|
const logger_js_1 = require("./logger.js");
|
|
28
|
-
|
|
27
|
+
exports.defaultHeaders = {
|
|
28
|
+
'x-source-version': `${version_js_1.version}`,
|
|
29
|
+
'x-source-identifier': 'ar-io-sdk',
|
|
30
|
+
};
|
|
31
|
+
async function signedRequestHeadersFromSigner({ signer, nonce = crypto.randomUUID(), }) {
|
|
29
32
|
let signature = undefined;
|
|
30
33
|
let publicKey = undefined;
|
|
31
34
|
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
@@ -85,18 +88,16 @@ async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)()
|
|
|
85
88
|
}
|
|
86
89
|
class TurboArNSPaymentFactory {
|
|
87
90
|
static init(config) {
|
|
88
|
-
const { signer, paymentUrl,
|
|
91
|
+
const { signer, paymentUrl, logger } = config ?? {};
|
|
89
92
|
if (signer !== undefined) {
|
|
90
93
|
return new TurboArNSPaymentProviderAuthenticated({
|
|
91
94
|
signer,
|
|
92
95
|
paymentUrl,
|
|
93
|
-
axios,
|
|
94
96
|
logger,
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
99
|
return new TurboArNSPaymentProviderUnauthenticated({
|
|
98
100
|
paymentUrl,
|
|
99
|
-
axios,
|
|
100
101
|
logger,
|
|
101
102
|
});
|
|
102
103
|
}
|
|
@@ -105,11 +106,9 @@ exports.TurboArNSPaymentFactory = TurboArNSPaymentFactory;
|
|
|
105
106
|
// Base class for unauthenticated operations
|
|
106
107
|
class TurboArNSPaymentProviderUnauthenticated {
|
|
107
108
|
paymentUrl;
|
|
108
|
-
axios;
|
|
109
109
|
logger;
|
|
110
|
-
constructor({ paymentUrl = 'https://payment.ardrive.io',
|
|
110
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', logger = logger_js_1.Logger.default, }) {
|
|
111
111
|
this.paymentUrl = paymentUrl;
|
|
112
|
-
this.axios = axios;
|
|
113
112
|
this.logger = logger;
|
|
114
113
|
}
|
|
115
114
|
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
@@ -121,7 +120,12 @@ class TurboArNSPaymentProviderUnauthenticated {
|
|
|
121
120
|
years,
|
|
122
121
|
},
|
|
123
122
|
});
|
|
124
|
-
const
|
|
123
|
+
const response = await fetch(url, {
|
|
124
|
+
method: 'GET',
|
|
125
|
+
headers: exports.defaultHeaders,
|
|
126
|
+
});
|
|
127
|
+
const status = response.status;
|
|
128
|
+
const data = (await response.json());
|
|
125
129
|
this.logger.debug('getArNSPriceDetails', {
|
|
126
130
|
intent,
|
|
127
131
|
name,
|
|
@@ -171,12 +175,18 @@ class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnau
|
|
|
171
175
|
referrer,
|
|
172
176
|
},
|
|
173
177
|
});
|
|
174
|
-
const
|
|
178
|
+
const signedHeaders = await signedRequestHeadersFromSigner({
|
|
175
179
|
signer: this.signer,
|
|
176
180
|
});
|
|
177
|
-
const
|
|
178
|
-
|
|
181
|
+
const response = await fetch(url, {
|
|
182
|
+
method: 'POST',
|
|
183
|
+
headers: {
|
|
184
|
+
...exports.defaultHeaders,
|
|
185
|
+
...signedHeaders,
|
|
186
|
+
},
|
|
179
187
|
});
|
|
188
|
+
const status = response.status;
|
|
189
|
+
const data = (await response.json());
|
|
180
190
|
this.logger.debug('Initiated ArNS purchase', {
|
|
181
191
|
intent,
|
|
182
192
|
name,
|
|
@@ -18,7 +18,6 @@ exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcesses
|
|
|
18
18
|
*/
|
|
19
19
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
20
20
|
const eventemitter3_1 = require("eventemitter3");
|
|
21
|
-
const plimit_lit_1 = require("plimit-lit");
|
|
22
21
|
const ant_registry_js_1 = require("../common/ant-registry.js");
|
|
23
22
|
const ant_js_1 = require("../common/ant.js");
|
|
24
23
|
const index_js_1 = require("../common/index.js");
|
|
@@ -49,22 +48,23 @@ function timeout(ms, promise) {
|
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
53
|
+
*/
|
|
52
54
|
class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
53
55
|
contract;
|
|
54
|
-
timeoutMs;
|
|
55
|
-
throttle;
|
|
56
|
+
timeoutMs;
|
|
56
57
|
logger;
|
|
57
58
|
strict;
|
|
58
59
|
antAoClient;
|
|
59
60
|
constructor({ contract = io_js_1.ARIO.init({
|
|
60
61
|
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
61
|
-
}), timeoutMs = 60_000,
|
|
62
|
+
}), timeoutMs = 60_000, logger = logger_js_1.Logger.default, strict = false, antAoClient = (0, aoconnect_1.connect)({
|
|
62
63
|
MODE: 'legacy',
|
|
63
64
|
}), } = {}) {
|
|
64
65
|
super();
|
|
65
66
|
this.contract = contract;
|
|
66
67
|
this.timeoutMs = timeoutMs;
|
|
67
|
-
this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
|
|
68
68
|
this.logger = logger;
|
|
69
69
|
this.strict = strict;
|
|
70
70
|
this.antAoClient = antAoClient;
|
|
@@ -99,7 +99,7 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
99
99
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
100
100
|
this.emit('progress', 0, idCount);
|
|
101
101
|
// check the contract owner and controllers
|
|
102
|
-
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) =>
|
|
102
|
+
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => {
|
|
103
103
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
104
104
|
this.emit('progress', i + 1, idCount);
|
|
105
105
|
return;
|
|
@@ -115,13 +115,12 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
115
115
|
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
116
116
|
return undefined;
|
|
117
117
|
}));
|
|
118
|
-
if (state?.Owner === address ||
|
|
119
|
-
state?.Controllers.includes(address)) {
|
|
118
|
+
if (state?.Owner === address || state?.Controllers.includes(address)) {
|
|
120
119
|
uniqueContractProcessIds[processId].state = state;
|
|
121
120
|
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
122
121
|
}
|
|
123
122
|
this.emit('progress', i + 1, idCount);
|
|
124
|
-
}))
|
|
123
|
+
}));
|
|
125
124
|
this.emit('end', uniqueContractProcessIds);
|
|
126
125
|
}
|
|
127
126
|
}
|
package/lib/cjs/version.js
CHANGED
|
@@ -61,7 +61,7 @@ export class HB {
|
|
|
61
61
|
* const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
|
|
62
62
|
* console.log(result);
|
|
63
63
|
*/
|
|
64
|
-
async compute({ path, json =
|
|
64
|
+
async compute({ path, json = true, }) {
|
|
65
65
|
return this.fetchHyperbeamPath({
|
|
66
66
|
path: `${this.url}/${this.processId}~process@1.0/compute/${path}`,
|
|
67
67
|
json,
|
|
@@ -109,7 +109,7 @@ export class HB {
|
|
|
109
109
|
return false;
|
|
110
110
|
})
|
|
111
111
|
.catch((error) => {
|
|
112
|
-
this.logger.
|
|
112
|
+
this.logger.error('Failed to check HyperBeam compatibility', {
|
|
113
113
|
cause: error,
|
|
114
114
|
});
|
|
115
115
|
this.isHyperBeamCompatible = false;
|
package/lib/esm/common/io.js
CHANGED
|
@@ -586,6 +586,30 @@ export class ARIOReadable {
|
|
|
586
586
|
});
|
|
587
587
|
}
|
|
588
588
|
async getPrimaryNameRequest(params) {
|
|
589
|
+
if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
|
|
590
|
+
this.logger.debug('Getting primary name request from HyperBEAM', {
|
|
591
|
+
initiator: params.initiator,
|
|
592
|
+
});
|
|
593
|
+
const res = await this.hb
|
|
594
|
+
.compute({
|
|
595
|
+
path: `/primary-names/requests/${params.initiator}`,
|
|
596
|
+
})
|
|
597
|
+
.catch((error) => {
|
|
598
|
+
this.logger.error('Failed to get primary name request from HyperBEAM', {
|
|
599
|
+
cause: error,
|
|
600
|
+
});
|
|
601
|
+
return null;
|
|
602
|
+
});
|
|
603
|
+
if (res !== null) {
|
|
604
|
+
// Ensure initiator is included in the result
|
|
605
|
+
return {
|
|
606
|
+
...res,
|
|
607
|
+
initiator: params.initiator,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
// else fall through to CU read
|
|
611
|
+
this.logger.info('Failed to get primary name request from HyperBEAM, failing over to CU read', { initiator: params.initiator });
|
|
612
|
+
}
|
|
589
613
|
const allTags = [
|
|
590
614
|
{ name: 'Action', value: 'Primary-Name-Request' },
|
|
591
615
|
{
|
|
@@ -606,6 +630,46 @@ export class ARIOReadable {
|
|
|
606
630
|
});
|
|
607
631
|
}
|
|
608
632
|
async getPrimaryName(params) {
|
|
633
|
+
if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
|
|
634
|
+
this.logger.debug('Getting primary name from HyperBEAM', { params });
|
|
635
|
+
try {
|
|
636
|
+
let owner;
|
|
637
|
+
if ('name' in params) {
|
|
638
|
+
// Step 1: Get owner from /primary-names/names/<name>
|
|
639
|
+
owner = await this.hb.compute({
|
|
640
|
+
path: `/primary-names/names/${params.name}`,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
// If given address, skip the /names/name query
|
|
645
|
+
owner = params.address;
|
|
646
|
+
}
|
|
647
|
+
// Step 2: Get {name, startTimestamp} from /primary-names/owners/<owner>
|
|
648
|
+
const ownerData = await this.hb.compute({
|
|
649
|
+
path: `/primary-names/owners/${owner}`,
|
|
650
|
+
});
|
|
651
|
+
const name = ownerData.name;
|
|
652
|
+
const startTimestamp = ownerData.startTimestamp;
|
|
653
|
+
// Step 3: Get processId from getArNSRecord
|
|
654
|
+
const record = await this.getArNSRecord({ name });
|
|
655
|
+
const processId = record.processId;
|
|
656
|
+
// Combine all data
|
|
657
|
+
const result = {
|
|
658
|
+
owner,
|
|
659
|
+
name,
|
|
660
|
+
startTimestamp,
|
|
661
|
+
processId,
|
|
662
|
+
};
|
|
663
|
+
return result;
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
this.logger.error('Failed to get primary name from HyperBEAM', {
|
|
667
|
+
cause: error,
|
|
668
|
+
});
|
|
669
|
+
// Fall through to CU read
|
|
670
|
+
this.logger.info('Failed to get primary name from HyperBEAM, failing over to CU read', { params });
|
|
671
|
+
}
|
|
672
|
+
}
|
|
609
673
|
const allTags = [
|
|
610
674
|
{ name: 'Action', value: 'Primary-Name' },
|
|
611
675
|
{
|
package/lib/esm/common/turbo.js
CHANGED
|
@@ -14,13 +14,16 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, SignatureConfig, } from '@dha-team/arbundles';
|
|
17
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
18
17
|
import { mARIOToken } from '../types/token.js';
|
|
19
18
|
import { toB64Url } from '../utils/base64.js';
|
|
20
|
-
import { createAxiosInstance } from '../utils/http-client.js';
|
|
21
19
|
import { urlWithSearchParams } from '../utils/url.js';
|
|
20
|
+
import { version } from '../version.js';
|
|
22
21
|
import { Logger } from './logger.js';
|
|
23
|
-
export
|
|
22
|
+
export const defaultHeaders = {
|
|
23
|
+
'x-source-version': `${version}`,
|
|
24
|
+
'x-source-identifier': 'ar-io-sdk',
|
|
25
|
+
};
|
|
26
|
+
export async function signedRequestHeadersFromSigner({ signer, nonce = crypto.randomUUID(), }) {
|
|
24
27
|
let signature = undefined;
|
|
25
28
|
let publicKey = undefined;
|
|
26
29
|
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
@@ -80,18 +83,16 @@ export async function signedRequestHeadersFromSigner({ signer, nonce = uuidv4(),
|
|
|
80
83
|
}
|
|
81
84
|
export class TurboArNSPaymentFactory {
|
|
82
85
|
static init(config) {
|
|
83
|
-
const { signer, paymentUrl,
|
|
86
|
+
const { signer, paymentUrl, logger } = config ?? {};
|
|
84
87
|
if (signer !== undefined) {
|
|
85
88
|
return new TurboArNSPaymentProviderAuthenticated({
|
|
86
89
|
signer,
|
|
87
90
|
paymentUrl,
|
|
88
|
-
axios,
|
|
89
91
|
logger,
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
return new TurboArNSPaymentProviderUnauthenticated({
|
|
93
95
|
paymentUrl,
|
|
94
|
-
axios,
|
|
95
96
|
logger,
|
|
96
97
|
});
|
|
97
98
|
}
|
|
@@ -99,11 +100,9 @@ export class TurboArNSPaymentFactory {
|
|
|
99
100
|
// Base class for unauthenticated operations
|
|
100
101
|
export class TurboArNSPaymentProviderUnauthenticated {
|
|
101
102
|
paymentUrl;
|
|
102
|
-
axios;
|
|
103
103
|
logger;
|
|
104
|
-
constructor({ paymentUrl = 'https://payment.ardrive.io',
|
|
104
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', logger = Logger.default, }) {
|
|
105
105
|
this.paymentUrl = paymentUrl;
|
|
106
|
-
this.axios = axios;
|
|
107
106
|
this.logger = logger;
|
|
108
107
|
}
|
|
109
108
|
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
@@ -115,7 +114,12 @@ export class TurboArNSPaymentProviderUnauthenticated {
|
|
|
115
114
|
years,
|
|
116
115
|
},
|
|
117
116
|
});
|
|
118
|
-
const
|
|
117
|
+
const response = await fetch(url, {
|
|
118
|
+
method: 'GET',
|
|
119
|
+
headers: defaultHeaders,
|
|
120
|
+
});
|
|
121
|
+
const status = response.status;
|
|
122
|
+
const data = (await response.json());
|
|
119
123
|
this.logger.debug('getArNSPriceDetails', {
|
|
120
124
|
intent,
|
|
121
125
|
name,
|
|
@@ -164,12 +168,18 @@ export class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProvi
|
|
|
164
168
|
referrer,
|
|
165
169
|
},
|
|
166
170
|
});
|
|
167
|
-
const
|
|
171
|
+
const signedHeaders = await signedRequestHeadersFromSigner({
|
|
168
172
|
signer: this.signer,
|
|
169
173
|
});
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const response = await fetch(url, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers: {
|
|
177
|
+
...defaultHeaders,
|
|
178
|
+
...signedHeaders,
|
|
179
|
+
},
|
|
172
180
|
});
|
|
181
|
+
const status = response.status;
|
|
182
|
+
const data = (await response.json());
|
|
173
183
|
this.logger.debug('Initiated ArNS purchase', {
|
|
174
184
|
intent,
|
|
175
185
|
name,
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { connect } from '@permaweb/aoconnect';
|
|
17
17
|
import { EventEmitter } from 'eventemitter3';
|
|
18
|
-
import { pLimit } from 'plimit-lit';
|
|
19
18
|
import { ANTRegistry } from '../common/ant-registry.js';
|
|
20
19
|
import { ANT } from '../common/ant.js';
|
|
21
20
|
import { AOProcess } from '../common/index.js';
|
|
@@ -45,22 +44,23 @@ function timeout(ms, promise) {
|
|
|
45
44
|
});
|
|
46
45
|
});
|
|
47
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
49
|
+
*/
|
|
48
50
|
export class ArNSEventEmitter extends EventEmitter {
|
|
49
51
|
contract;
|
|
50
|
-
timeoutMs;
|
|
51
|
-
throttle;
|
|
52
|
+
timeoutMs;
|
|
52
53
|
logger;
|
|
53
54
|
strict;
|
|
54
55
|
antAoClient;
|
|
55
56
|
constructor({ contract = ARIO.init({
|
|
56
57
|
processId: ARIO_MAINNET_PROCESS_ID,
|
|
57
|
-
}), timeoutMs = 60_000,
|
|
58
|
+
}), timeoutMs = 60_000, logger = Logger.default, strict = false, antAoClient = connect({
|
|
58
59
|
MODE: 'legacy',
|
|
59
60
|
}), } = {}) {
|
|
60
61
|
super();
|
|
61
62
|
this.contract = contract;
|
|
62
63
|
this.timeoutMs = timeoutMs;
|
|
63
|
-
this.throttle = pLimit(concurrency);
|
|
64
64
|
this.logger = logger;
|
|
65
65
|
this.strict = strict;
|
|
66
66
|
this.antAoClient = antAoClient;
|
|
@@ -95,7 +95,7 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
95
95
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
96
96
|
this.emit('progress', 0, idCount);
|
|
97
97
|
// check the contract owner and controllers
|
|
98
|
-
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) =>
|
|
98
|
+
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => {
|
|
99
99
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
100
100
|
this.emit('progress', i + 1, idCount);
|
|
101
101
|
return;
|
|
@@ -111,13 +111,12 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
111
111
|
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
112
112
|
return undefined;
|
|
113
113
|
}));
|
|
114
|
-
if (state?.Owner === address ||
|
|
115
|
-
state?.Controllers.includes(address)) {
|
|
114
|
+
if (state?.Owner === address || state?.Controllers.includes(address)) {
|
|
116
115
|
uniqueContractProcessIds[processId].state = state;
|
|
117
116
|
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
118
117
|
}
|
|
119
118
|
this.emit('progress', i + 1, idCount);
|
|
120
|
-
}))
|
|
119
|
+
}));
|
|
121
120
|
this.emit('end', uniqueContractProcessIds);
|
|
122
121
|
}
|
|
123
122
|
}
|
package/lib/esm/version.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
2
1
|
import { AoMessageResult, TransactionId, TurboArNSSigner } from '../types/common.js';
|
|
3
2
|
import { AoTokenCostParams } from '../types/io.js';
|
|
4
3
|
import { mARIOToken } from '../types/token.js';
|
|
@@ -6,15 +5,15 @@ import { ILogger } from './logger.js';
|
|
|
6
5
|
export interface TurboUnauthenticatedConfig {
|
|
7
6
|
paymentUrl?: string;
|
|
8
7
|
logger?: ILogger;
|
|
9
|
-
axios?: AxiosInstance;
|
|
10
8
|
}
|
|
11
9
|
export interface TurboAuthenticatedConfig extends TurboUnauthenticatedConfig {
|
|
12
10
|
signer: TurboArNSSigner;
|
|
13
11
|
}
|
|
12
|
+
export declare const defaultHeaders: Record<string, string>;
|
|
14
13
|
export declare function signedRequestHeadersFromSigner({ signer, nonce, }: {
|
|
15
14
|
signer: TurboArNSSigner;
|
|
16
15
|
nonce?: string;
|
|
17
|
-
}): Promise<
|
|
16
|
+
}): Promise<Record<string, string>>;
|
|
18
17
|
export type ArNSPurchaseReceipt = AoTokenCostParams & {
|
|
19
18
|
wincQty: string;
|
|
20
19
|
mARIOQty: string;
|
|
@@ -39,16 +38,15 @@ export interface ArNSAuthenticatedPaymentProvider extends ArNSPaymentProvider {
|
|
|
39
38
|
}
|
|
40
39
|
export declare class TurboArNSPaymentFactory {
|
|
41
40
|
static init(): TurboArNSPaymentProviderUnauthenticated;
|
|
42
|
-
static init({ paymentUrl,
|
|
41
|
+
static init({ paymentUrl, logger, }: TurboUnauthenticatedConfig & {
|
|
43
42
|
signer?: TurboArNSSigner;
|
|
44
43
|
}): TurboArNSPaymentProviderUnauthenticated;
|
|
45
|
-
static init({ signer, paymentUrl,
|
|
44
|
+
static init({ signer, paymentUrl, logger, }: TurboAuthenticatedConfig): TurboArNSPaymentProviderAuthenticated;
|
|
46
45
|
}
|
|
47
46
|
export declare class TurboArNSPaymentProviderUnauthenticated implements ArNSPaymentProvider {
|
|
48
47
|
protected readonly paymentUrl: string;
|
|
49
|
-
protected readonly axios: AxiosInstance;
|
|
50
48
|
protected readonly logger: ILogger;
|
|
51
|
-
constructor({ paymentUrl,
|
|
49
|
+
constructor({ paymentUrl, logger, }: TurboUnauthenticatedConfig);
|
|
52
50
|
getArNSPriceDetails({ intent, name, quantity, type, years, }: AoTokenCostParams): Promise<{
|
|
53
51
|
winc: string;
|
|
54
52
|
mARIO: mARIOToken;
|
|
@@ -9,17 +9,18 @@ export declare const getANTProcessesOwnedByWallet: ({ address, registry, }: {
|
|
|
9
9
|
address: WalletAddress;
|
|
10
10
|
registry?: AoANTRegistryRead;
|
|
11
11
|
}) => Promise<ProcessId[]>;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
14
|
+
*/
|
|
12
15
|
export declare class ArNSEventEmitter extends EventEmitter {
|
|
13
16
|
protected contract: AoARIORead;
|
|
14
17
|
private timeoutMs;
|
|
15
|
-
private throttle;
|
|
16
18
|
private logger;
|
|
17
19
|
private strict;
|
|
18
20
|
private antAoClient;
|
|
19
|
-
constructor({ contract, timeoutMs,
|
|
21
|
+
constructor({ contract, timeoutMs, logger, strict, antAoClient, }?: {
|
|
20
22
|
contract?: AoARIORead;
|
|
21
23
|
timeoutMs?: number;
|
|
22
|
-
concurrency?: number;
|
|
23
24
|
logger?: ILogger;
|
|
24
25
|
strict?: boolean;
|
|
25
26
|
antAoClient?: AoClient;
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/sdk",
|
|
3
|
-
"version": "3.22.0-alpha.
|
|
3
|
+
"version": "3.22.0-alpha.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
|
|
@@ -100,10 +100,11 @@
|
|
|
100
100
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
101
101
|
"@typescript-eslint/parser": "^6.4.0",
|
|
102
102
|
"arconnect": "^1.0.3",
|
|
103
|
+
"axios": "^1.13.2",
|
|
103
104
|
"c8": "^10.1.3",
|
|
104
105
|
"dotenv": "^16.4.5",
|
|
105
106
|
"dotenv-cli": "^7.4.2",
|
|
106
|
-
"esbuild": "^0.
|
|
107
|
+
"esbuild": "^0.27.0",
|
|
107
108
|
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
108
109
|
"eslint": "^8.47.0",
|
|
109
110
|
"eslint-config-prettier": "^9.0.0",
|
|
@@ -131,22 +132,9 @@
|
|
|
131
132
|
"@dha-team/arbundles": "^1.0.1",
|
|
132
133
|
"@permaweb/aoconnect": "0.0.68",
|
|
133
134
|
"arweave": "1.15.5",
|
|
134
|
-
"axios": "1.12.0",
|
|
135
|
-
"axios-retry": "^4.3.0",
|
|
136
135
|
"commander": "^12.1.0",
|
|
137
136
|
"eventemitter3": "^5.0.1",
|
|
138
|
-
"
|
|
139
|
-
"prompts": "^2.4.2",
|
|
140
|
-
"uuid": "^11.1.0",
|
|
141
|
-
"zod": "^3.23.8"
|
|
142
|
-
},
|
|
143
|
-
"peerDependencies": {
|
|
144
|
-
"winston": "^3.13.0"
|
|
145
|
-
},
|
|
146
|
-
"peerDependenciesMeta": {
|
|
147
|
-
"winston": {
|
|
148
|
-
"optional": true
|
|
149
|
-
}
|
|
137
|
+
"prompts": "^2.4.2"
|
|
150
138
|
},
|
|
151
139
|
"lint-staged": {
|
|
152
140
|
"**/*.{ts,js,mjs,cjs,md,json}": [
|
package/lib/cjs/common/http.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AxiosHTTPService = void 0;
|
|
4
|
-
const http_client_js_1 = require("../utils/http-client.js");
|
|
5
|
-
const error_js_1 = require("./error.js");
|
|
6
|
-
const logger_js_1 = require("./logger.js");
|
|
7
|
-
class AxiosHTTPService {
|
|
8
|
-
axios;
|
|
9
|
-
logger;
|
|
10
|
-
constructor({ url, logger = logger_js_1.Logger.default, }) {
|
|
11
|
-
this.logger = logger;
|
|
12
|
-
this.axios = (0, http_client_js_1.createAxiosInstance)({
|
|
13
|
-
axiosConfig: {
|
|
14
|
-
baseURL: url,
|
|
15
|
-
},
|
|
16
|
-
logger: this.logger,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async get({ endpoint, signal, allowedStatuses = [200, 202], headers, params, }) {
|
|
20
|
-
this.logger.debug(`Get request to endpoint: ${endpoint} with params ${JSON.stringify(params, undefined, 2)}`);
|
|
21
|
-
const { status, statusText, data } = await this.axios.get(endpoint, {
|
|
22
|
-
headers,
|
|
23
|
-
signal,
|
|
24
|
-
params,
|
|
25
|
-
});
|
|
26
|
-
this.logger.debug(`Response status: ${status} ${statusText}`);
|
|
27
|
-
if (!allowedStatuses.includes(status)) {
|
|
28
|
-
switch (status) {
|
|
29
|
-
case 404:
|
|
30
|
-
throw new error_js_1.NotFound(statusText);
|
|
31
|
-
case 400:
|
|
32
|
-
throw new error_js_1.FailedRequestError(status, statusText);
|
|
33
|
-
default:
|
|
34
|
-
throw new error_js_1.UnknownError(statusText);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.AxiosHTTPService = AxiosHTTPService;
|