@ar.io/sdk 3.22.0-alpha.1 → 3.22.0-alpha.3
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/bundles/web.bundle.min.js +69 -69
- package/lib/cjs/cli/cli.js +1 -5
- package/lib/cjs/cli/options.js +1 -0
- package/lib/cjs/cli/utils.js +4 -0
- package/lib/cjs/common/ant.js +10 -2
- package/lib/cjs/common/hyperbeam/hb.js +173 -0
- package/lib/cjs/common/io.js +35 -1
- package/lib/cjs/utils/ao.js +10 -3
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +1 -5
- package/lib/esm/cli/options.js +1 -0
- package/lib/esm/cli/utils.js +4 -0
- package/lib/esm/common/ant.js +10 -2
- package/lib/esm/common/hyperbeam/hb.js +169 -0
- package/lib/esm/common/io.js +35 -1
- package/lib/esm/utils/ao.js +10 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/common/hyperbeam/hb.d.ts +88 -0
- package/lib/types/common/io.d.ts +2 -0
- package/lib/types/types/common.d.ts +3 -0
- package/lib/types/utils/ao.d.ts +4 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/common/io.js
CHANGED
|
@@ -24,6 +24,7 @@ import { defaultArweave } from './arweave.js';
|
|
|
24
24
|
import { AOProcess } from './contracts/ao-process.js';
|
|
25
25
|
import { InvalidContractConfigurationError } from './error.js';
|
|
26
26
|
import { createFaucet } from './faucet.js';
|
|
27
|
+
import { HB } from './hyperbeam/hb.js';
|
|
27
28
|
import { Logger } from './logger.js';
|
|
28
29
|
import { TurboArNSPaymentFactory, TurboArNSPaymentProviderAuthenticated, isTurboArNSSigner, } from './turbo.js';
|
|
29
30
|
export class ARIO {
|
|
@@ -100,9 +101,9 @@ export class ARIOReadable {
|
|
|
100
101
|
hyperbeamUrl;
|
|
101
102
|
paymentProvider; // TODO: this could be an array/map of payment providers
|
|
102
103
|
logger = Logger.default;
|
|
104
|
+
hb;
|
|
103
105
|
constructor(config) {
|
|
104
106
|
this.arweave = config?.arweave ?? defaultArweave;
|
|
105
|
-
this.hyperbeamUrl = config?.hyperbeamUrl;
|
|
106
107
|
if (config === undefined || Object.keys(config).length === 0) {
|
|
107
108
|
this.process = new AOProcess({
|
|
108
109
|
processId: ARIO_MAINNET_PROCESS_ID,
|
|
@@ -119,6 +120,19 @@ export class ARIOReadable {
|
|
|
119
120
|
else {
|
|
120
121
|
throw new InvalidContractConfigurationError();
|
|
121
122
|
}
|
|
123
|
+
// only use hyperbeam if the client has provided a hyperbeamUrl
|
|
124
|
+
// this will avoid overwhelming the HyperBeam node with requests
|
|
125
|
+
// as we shift using HyperBEAM for all ANT operations
|
|
126
|
+
if (config?.hyperbeamUrl !== undefined) {
|
|
127
|
+
this.hyperbeamUrl = config.hyperbeamUrl;
|
|
128
|
+
this.hb = new HB({
|
|
129
|
+
url: this.hyperbeamUrl,
|
|
130
|
+
processId: this.process.processId,
|
|
131
|
+
});
|
|
132
|
+
this.logger.debug(`Using HyperBEAM node for process ${this.process.processId}`, {
|
|
133
|
+
hyperbeamUrl: this.hyperbeamUrl,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
122
136
|
this.paymentProvider = TurboArNSPaymentFactory.init({
|
|
123
137
|
paymentUrl: config?.paymentUrl,
|
|
124
138
|
});
|
|
@@ -218,6 +232,24 @@ export class ARIOReadable {
|
|
|
218
232
|
});
|
|
219
233
|
}
|
|
220
234
|
async getBalance({ address }) {
|
|
235
|
+
if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
|
|
236
|
+
this.logger.debug('Getting balance from HyperBEAM', { address });
|
|
237
|
+
const res = await this.hb
|
|
238
|
+
.compute({
|
|
239
|
+
path: `balances/${address}`,
|
|
240
|
+
})
|
|
241
|
+
.then((res) => Number(res))
|
|
242
|
+
.catch((error) => {
|
|
243
|
+
this.logger.error('Failed to get balance from HyperBEAM', {
|
|
244
|
+
cause: error,
|
|
245
|
+
});
|
|
246
|
+
return null;
|
|
247
|
+
});
|
|
248
|
+
if (res !== null)
|
|
249
|
+
return res;
|
|
250
|
+
// else fall through to CU read
|
|
251
|
+
this.logger.info('Failed to get balance from HyperBEAM, failing over to to CU read', { address });
|
|
252
|
+
}
|
|
221
253
|
return this.process.read({
|
|
222
254
|
tags: [
|
|
223
255
|
{ name: 'Action', value: 'Balance' },
|
|
@@ -645,6 +677,7 @@ export class ARIOReadable {
|
|
|
645
677
|
ao: this.process.ao,
|
|
646
678
|
processId: nameData.processId,
|
|
647
679
|
}),
|
|
680
|
+
hyperbeamUrl: this.hyperbeamUrl,
|
|
648
681
|
});
|
|
649
682
|
const [owner, antRecord] = await Promise.all([
|
|
650
683
|
ant.getOwner(),
|
|
@@ -1281,6 +1314,7 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
1281
1314
|
ao: this.process.ao,
|
|
1282
1315
|
}),
|
|
1283
1316
|
signer: this.signer,
|
|
1317
|
+
hyperbeamUrl: this.hyperbeamUrl,
|
|
1284
1318
|
});
|
|
1285
1319
|
// approve the primary name request with the ant
|
|
1286
1320
|
const approveResult = await antClient.approvePrimaryNameRequest({
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -27,7 +27,7 @@ export async function spawnANT({ signer, module, ao = connect({
|
|
|
27
27
|
MODE: 'legacy',
|
|
28
28
|
}), scheduler = DEFAULT_SCHEDULER_ID, state, tags = [], antRegistryId = ANT_REGISTRY_ID, logger = Logger.default, authority = AO_AUTHORITY, onSigningProgress = (name, payload) => {
|
|
29
29
|
logger.debug('Signing progress', { name, payload });
|
|
30
|
-
}, }) {
|
|
30
|
+
}, hyperbeamUrl, }) {
|
|
31
31
|
if (state) {
|
|
32
32
|
parseSchemaResult(SpawnANTStateSchema, state);
|
|
33
33
|
}
|
|
@@ -182,7 +182,12 @@ export async function spawnANT({ signer, module, ao = connect({
|
|
|
182
182
|
// check the ACL for the owner
|
|
183
183
|
const antRegistry = ANTRegistry.init({
|
|
184
184
|
signer,
|
|
185
|
-
|
|
185
|
+
process: new AOProcess({
|
|
186
|
+
processId: antRegistryId,
|
|
187
|
+
ao,
|
|
188
|
+
logger,
|
|
189
|
+
}),
|
|
190
|
+
hyperbeamUrl,
|
|
186
191
|
});
|
|
187
192
|
let attempts = 0;
|
|
188
193
|
const maxAttempts = 5;
|
|
@@ -213,7 +218,7 @@ export async function spawnANT({ signer, module, ao = connect({
|
|
|
213
218
|
}
|
|
214
219
|
export async function forkANT({ signer, antProcessId, logger = Logger.default, ao, moduleId, antRegistryId = ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
|
|
215
220
|
logger.debug('Forking ANT', { name, payload });
|
|
216
|
-
}, }) {
|
|
221
|
+
}, hyperbeamUrl, }) {
|
|
217
222
|
// get the state of the current ANT and use it to spawn a new ANT
|
|
218
223
|
const ant = ANT.init({
|
|
219
224
|
process: new AOProcess({
|
|
@@ -221,6 +226,7 @@ export async function forkANT({ signer, antProcessId, logger = Logger.default, a
|
|
|
221
226
|
ao,
|
|
222
227
|
logger,
|
|
223
228
|
}),
|
|
229
|
+
hyperbeamUrl,
|
|
224
230
|
});
|
|
225
231
|
const state = await ant.getState();
|
|
226
232
|
if (state === undefined) {
|
|
@@ -244,6 +250,7 @@ export async function forkANT({ signer, antProcessId, logger = Logger.default, a
|
|
|
244
250
|
balances: state.Balances,
|
|
245
251
|
logo: state.Logo,
|
|
246
252
|
},
|
|
253
|
+
hyperbeamUrl,
|
|
247
254
|
});
|
|
248
255
|
return forkedProcessId;
|
|
249
256
|
}
|
package/lib/esm/version.js
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { JSONValue } from '../../types/common.js';
|
|
17
|
+
import { Logger } from '../logger.js';
|
|
18
|
+
export type HBConfig = {
|
|
19
|
+
url: string;
|
|
20
|
+
processId: string;
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
hbTimeoutMs?: number;
|
|
23
|
+
};
|
|
24
|
+
export declare class HB {
|
|
25
|
+
readonly url: string;
|
|
26
|
+
readonly processId: string;
|
|
27
|
+
protected isHyperBeamCompatible: boolean | undefined;
|
|
28
|
+
protected checkHyperBeamPromise: Promise<boolean> | undefined;
|
|
29
|
+
private logger;
|
|
30
|
+
private hbTimeoutMs;
|
|
31
|
+
constructor(config: HBConfig);
|
|
32
|
+
/**
|
|
33
|
+
* fetches the meta data for the process
|
|
34
|
+
*
|
|
35
|
+
* @returns The meta data for the process
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
|
|
39
|
+
* const meta = await hyperbeam.meta();
|
|
40
|
+
* console.log(meta);
|
|
41
|
+
*/
|
|
42
|
+
meta(): Promise<Record<string, JSONValue>>;
|
|
43
|
+
/**
|
|
44
|
+
* calls the process device /now function, which evaluates the current process state pulling new messages
|
|
45
|
+
* to get the latest state
|
|
46
|
+
*
|
|
47
|
+
* @param path - The path to the hb state
|
|
48
|
+
* @param json - Whether to return the result as JSON, defaults to true
|
|
49
|
+
* @returns The result of the compute operation
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
|
|
53
|
+
* const result = await hyperbeam.now({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
|
|
54
|
+
* console.log(result);
|
|
55
|
+
*/
|
|
56
|
+
now<T extends JSONValue>({ path, json, }: {
|
|
57
|
+
path: string;
|
|
58
|
+
json?: boolean;
|
|
59
|
+
}): Promise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* calls the process device /compute function, which uses the currently evaluated state in the node
|
|
62
|
+
*
|
|
63
|
+
* @param path - The path to the compute resource
|
|
64
|
+
* @param json - Whether to return the result as JSON, defaults to true
|
|
65
|
+
* @returns The result of the compute operation
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
|
|
69
|
+
* const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
|
|
70
|
+
* console.log(result);
|
|
71
|
+
*/
|
|
72
|
+
compute<T extends JSONValue>({ path, json, }: {
|
|
73
|
+
path: string;
|
|
74
|
+
json?: boolean;
|
|
75
|
+
}): Promise<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the process is HyperBeam compatible and caches the result.
|
|
78
|
+
*
|
|
79
|
+
* @returns {Promise<boolean>} True if the process is HyperBeam compatible, false otherwise.
|
|
80
|
+
*/
|
|
81
|
+
checkHyperBeamCompatibility({ minSlot, }?: {
|
|
82
|
+
minSlot?: number;
|
|
83
|
+
}): Promise<boolean>;
|
|
84
|
+
fetchHyperbeamPath<T extends JSONValue>({ path, json, }: {
|
|
85
|
+
path: string;
|
|
86
|
+
json?: boolean;
|
|
87
|
+
}): Promise<T>;
|
|
88
|
+
}
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Arweave from 'arweave';
|
|
2
2
|
import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, AoCreatePrimaryNameRequest, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionData, AoEpochDistributionTotalsData, AoEpochObservationData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGatewayWithAddress, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoJoinNetworkParams, AoMessageResult, AoPaginatedAddressParams, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoRegistrationFees, AoReturnedName, AoRevokeVaultParams, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, AoWeightedObserver, ArNSNameResolutionData, ArNSNameResolver, BuyArNSNameProgressEvents, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, SetPrimaryNameProgressEvents, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
|
|
3
3
|
import { AOProcess } from './contracts/ao-process.js';
|
|
4
|
+
import { HB } from './hyperbeam/hb.js';
|
|
4
5
|
import { Logger } from './logger.js';
|
|
5
6
|
import { TurboArNSPaymentProviderAuthenticated, TurboArNSPaymentProviderUnauthenticated } from './turbo.js';
|
|
6
7
|
type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration & {
|
|
@@ -31,6 +32,7 @@ export declare class ARIOReadable implements AoARIORead, ArNSNameResolver {
|
|
|
31
32
|
protected hyperbeamUrl: string | undefined;
|
|
32
33
|
protected paymentProvider: TurboArNSPaymentProviderUnauthenticated;
|
|
33
34
|
protected logger: Logger;
|
|
35
|
+
protected hb: HB | undefined;
|
|
34
36
|
constructor(config?: ARIOConfigNoSigner);
|
|
35
37
|
getInfo(): Promise<{
|
|
36
38
|
Name: string;
|
package/lib/types/utils/ao.d.ts
CHANGED
|
@@ -28,9 +28,10 @@ export type SpawnANTParams = {
|
|
|
28
28
|
* Callback function to be called when signing progress is made
|
|
29
29
|
*/
|
|
30
30
|
onSigningProgress?: (name: keyof SpawnAntProgressEvent, payload: SpawnAntProgressEvent[keyof SpawnAntProgressEvent]) => void;
|
|
31
|
+
hyperbeamUrl?: string;
|
|
31
32
|
};
|
|
32
|
-
export declare function spawnANT({ signer, module, ao, scheduler, state, tags, antRegistryId, logger, authority, onSigningProgress, }: SpawnANTParams): Promise<ProcessId>;
|
|
33
|
-
export declare function forkANT({ signer, antProcessId, logger, ao, moduleId, antRegistryId, onSigningProgress, }: {
|
|
33
|
+
export declare function spawnANT({ signer, module, ao, scheduler, state, tags, antRegistryId, logger, authority, onSigningProgress, hyperbeamUrl, }: SpawnANTParams): Promise<ProcessId>;
|
|
34
|
+
export declare function forkANT({ signer, antProcessId, logger, ao, moduleId, antRegistryId, onSigningProgress, hyperbeamUrl, }: {
|
|
34
35
|
signer: AoSigner;
|
|
35
36
|
antProcessId: string;
|
|
36
37
|
moduleId?: string;
|
|
@@ -38,6 +39,7 @@ export declare function forkANT({ signer, antProcessId, logger, ao, moduleId, an
|
|
|
38
39
|
ao?: AoClient;
|
|
39
40
|
antRegistryId?: string;
|
|
40
41
|
onSigningProgress?: (name: keyof SpawnAntProgressEvent, payload: SpawnAntProgressEvent[keyof SpawnAntProgressEvent]) => void;
|
|
42
|
+
hyperbeamUrl?: string;
|
|
41
43
|
}): Promise<string>;
|
|
42
44
|
/**
|
|
43
45
|
* @deprecated
|
package/lib/types/version.d.ts
CHANGED