@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
|
@@ -0,0 +1,129 @@
|
|
|
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 { SignatureConfig } from '@dha-team/arbundles';
|
|
17
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
18
|
+
import { mARIOToken } from '../types/token.js';
|
|
19
|
+
import { toB64Url } from '../utils/base64.js';
|
|
20
|
+
import { createAxiosInstance } from '../utils/http-client.js';
|
|
21
|
+
import { urlWithSearchParams } from '../utils/url.js';
|
|
22
|
+
import { Logger } from './logger.js';
|
|
23
|
+
export async function signedRequestHeadersFromSigner({ signer, nonce = uuidv4(), }) {
|
|
24
|
+
await signer.setPublicKey?.();
|
|
25
|
+
const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
|
|
26
|
+
let publicKey;
|
|
27
|
+
switch (signer.signatureType) {
|
|
28
|
+
case SignatureConfig.ARWEAVE:
|
|
29
|
+
publicKey = toB64Url(signer.publicKey);
|
|
30
|
+
break;
|
|
31
|
+
case SignatureConfig.ETHEREUM:
|
|
32
|
+
publicKey = '0x' + signer.publicKey.toString('hex');
|
|
33
|
+
break;
|
|
34
|
+
// TODO: solana sig support
|
|
35
|
+
// case SignatureConfig.SOLANA:
|
|
36
|
+
// case SignatureConfig.ED25519:
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`Unsupported signer type for signing requests: ${signer.signatureType}`);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
'x-public-key': publicKey,
|
|
42
|
+
'x-nonce': nonce,
|
|
43
|
+
'x-signature': toB64Url(Buffer.from(signature)),
|
|
44
|
+
'x-signature-type': signer.signatureType,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export class TurboArNSPaymentProvider {
|
|
48
|
+
paymentUrl;
|
|
49
|
+
axios;
|
|
50
|
+
logger;
|
|
51
|
+
signer;
|
|
52
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = createAxiosInstance(), logger = Logger.default, signer, }) {
|
|
53
|
+
this.paymentUrl = paymentUrl;
|
|
54
|
+
this.axios = axios;
|
|
55
|
+
this.logger = logger;
|
|
56
|
+
this.signer = signer;
|
|
57
|
+
}
|
|
58
|
+
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
59
|
+
const url = urlWithSearchParams({
|
|
60
|
+
baseUrl: `${this.paymentUrl}/v1/arns/price/${intent}/${name}`,
|
|
61
|
+
params: {
|
|
62
|
+
increaseQty: quantity,
|
|
63
|
+
type,
|
|
64
|
+
years,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const { data, status } = await this.axios.get(url);
|
|
68
|
+
this.logger.debug('getArNSPriceDetails', {
|
|
69
|
+
intent,
|
|
70
|
+
name,
|
|
71
|
+
quantity,
|
|
72
|
+
type,
|
|
73
|
+
years,
|
|
74
|
+
data,
|
|
75
|
+
status,
|
|
76
|
+
});
|
|
77
|
+
if (status !== 200) {
|
|
78
|
+
throw new Error('Failed to get ArNS purchase price ' + JSON.stringify(data));
|
|
79
|
+
}
|
|
80
|
+
if (!data.winc || !data.mARIO) {
|
|
81
|
+
throw new Error('Invalid response from Turbo ' + JSON.stringify(data));
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
winc: data.winc,
|
|
85
|
+
mARIO: new mARIOToken(+data.mARIO),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async getPrice(params) {
|
|
89
|
+
const { winc } = await this.getArNSPriceDetails(params);
|
|
90
|
+
return +winc;
|
|
91
|
+
}
|
|
92
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
93
|
+
if (!this.signer) {
|
|
94
|
+
throw new Error('Signer required for initiating ArNS purchase with Turbo');
|
|
95
|
+
}
|
|
96
|
+
const url = urlWithSearchParams({
|
|
97
|
+
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
98
|
+
params: {
|
|
99
|
+
increaseQty: quantity,
|
|
100
|
+
processId,
|
|
101
|
+
type,
|
|
102
|
+
years,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
const headers = await signedRequestHeadersFromSigner({
|
|
106
|
+
signer: this.signer,
|
|
107
|
+
});
|
|
108
|
+
const { data, status } = await this.axios.post(url, null, {
|
|
109
|
+
headers,
|
|
110
|
+
});
|
|
111
|
+
this.logger.debug('Initiated ArNS purchase', {
|
|
112
|
+
intent,
|
|
113
|
+
name,
|
|
114
|
+
quantity,
|
|
115
|
+
processId,
|
|
116
|
+
type,
|
|
117
|
+
years,
|
|
118
|
+
data,
|
|
119
|
+
status,
|
|
120
|
+
});
|
|
121
|
+
if (status !== 200) {
|
|
122
|
+
throw new Error('Failed to initiate ArNS purchase ' + JSON.stringify(data));
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
id: data.arioWriteResult.id,
|
|
126
|
+
result: data.purchaseReceipt,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/types/index.js
CHANGED
package/lib/esm/types/io.js
CHANGED
|
@@ -22,16 +22,17 @@ export const intentsUsingYears = [
|
|
|
22
22
|
export const isValidIntent = (intent) => {
|
|
23
23
|
return validIntents.indexOf(intent) !== -1;
|
|
24
24
|
};
|
|
25
|
-
export const fundFromOptions = ['balance', 'stakes', 'any'];
|
|
25
|
+
export const fundFromOptions = ['balance', 'stakes', 'any', 'turbo'];
|
|
26
26
|
export const isValidFundFrom = (fundFrom) => {
|
|
27
27
|
return fundFromOptions.indexOf(fundFrom) !== -1;
|
|
28
28
|
};
|
|
29
29
|
// Type-guard functions
|
|
30
30
|
export function isProcessConfiguration(config) {
|
|
31
|
-
return 'process' in config;
|
|
31
|
+
return config !== undefined && 'process' in config;
|
|
32
32
|
}
|
|
33
33
|
export function isProcessIdConfiguration(config) {
|
|
34
|
-
return (
|
|
34
|
+
return (config !== undefined &&
|
|
35
|
+
'processId' in config &&
|
|
35
36
|
typeof config.processId === 'string' &&
|
|
36
37
|
validateArweaveId(config.processId) === true);
|
|
37
38
|
}
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -131,6 +131,8 @@ export function createAoSigner(signer) {
|
|
|
131
131
|
}));
|
|
132
132
|
return signedData;
|
|
133
133
|
};
|
|
134
|
+
// eslint-disable-next-line
|
|
135
|
+
// @ts-ignore Buffer vs ArrayBuffer type mismatch
|
|
134
136
|
return aoSigner;
|
|
135
137
|
}
|
|
136
138
|
export const defaultTargetManifestId = '-k7t8xMoB8hW482609Z9F4bTFMC3MnuW8bTvTyT8pFI';
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
export const urlWithSearchParams = ({ baseUrl, params, }) => {
|
|
17
|
+
const urlObj = new URL(baseUrl);
|
|
18
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
19
|
+
if (value === undefined || value === null)
|
|
20
|
+
return;
|
|
21
|
+
urlObj.searchParams.set(key, value.toString());
|
|
22
|
+
});
|
|
23
|
+
return urlObj.toString();
|
|
24
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { urlWithSearchParams } from './url.js';
|
|
4
|
+
test('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
|
|
5
|
+
const result = urlWithSearchParams({
|
|
6
|
+
baseUrl: 'https://example.com',
|
|
7
|
+
params: {
|
|
8
|
+
number: 1,
|
|
9
|
+
string: 'string',
|
|
10
|
+
boolean: true,
|
|
11
|
+
empty: '',
|
|
12
|
+
zero: 0,
|
|
13
|
+
false: false,
|
|
14
|
+
null: null,
|
|
15
|
+
undef: undefined,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
assert.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
|
|
19
|
+
});
|
package/lib/esm/version.js
CHANGED
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
import { AoANTSetBaseNameRecordParams, AoANTSetUndernameRecordParams } from '../../types/ant.js';
|
|
17
17
|
import { CLIWriteOptionsFromAoAntParams } from '../types.js';
|
|
18
18
|
/** @deprecated -- use set-ant-base-name and set-ant-undername */
|
|
19
|
-
export declare function setAntRecordCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
20
|
-
export declare function setAntBaseNameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetBaseNameRecordParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
21
|
-
export declare function setAntUndernameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
19
|
+
export declare function setAntRecordCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
20
|
+
export declare function setAntBaseNameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetBaseNameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
21
|
+
export declare function setAntUndernameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
@@ -19,4 +19,4 @@ export declare function buyRecordCLICommand(o: CLIWriteOptionsFromAoParams<AoBuy
|
|
|
19
19
|
export declare function upgradeRecordCLICommand(o: CLIWriteOptionsFromAoParams<AoArNSPurchaseParams>): Promise<import("../../types/common.js").AoMessageResult>;
|
|
20
20
|
export declare function extendLeaseCLICommand(o: CLIWriteOptionsFromAoParams<AoExtendLeaseParams>): Promise<import("../../types/common.js").AoMessageResult>;
|
|
21
21
|
export declare function increaseUndernameLimitCLICommand(o: CLIWriteOptionsFromAoParams<AoIncreaseUndernameLimitParams>): Promise<import("../../types/common.js").AoMessageResult>;
|
|
22
|
-
export declare function requestPrimaryNameCLICommand(o: CLIWriteOptionsFromAoParams<AoArNSPurchaseParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
22
|
+
export declare function requestPrimaryNameCLICommand(o: CLIWriteOptionsFromAoParams<AoArNSPurchaseParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AddressAndVaultIdCLIWriteOptions, DecreaseDelegateStakeCLIOptions, JoinNetworkCLIOptions, OperatorStakeCLIOptions, RedelegateStakeCLIOptions, TransferCLIOptions, UpdateGatewaySettingsCLIOptions, WriteActionCLIOptions } from '../types.js';
|
|
2
2
|
export declare function joinNetwork(options: JoinNetworkCLIOptions): Promise<{
|
|
3
|
-
joinNetworkResult: import("../../types/common.js").AoMessageResult
|
|
3
|
+
joinNetworkResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
4
4
|
joinedAddress: string;
|
|
5
5
|
message: string;
|
|
6
6
|
}>;
|
|
7
7
|
export declare function updateGatewaySettings(options: UpdateGatewaySettingsCLIOptions): Promise<{
|
|
8
|
-
updateGatewaySettingsResult: import("../../types/common.js").AoMessageResult
|
|
8
|
+
updateGatewaySettingsResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
9
9
|
updatedGatewayAddress: string;
|
|
10
10
|
message: string;
|
|
11
11
|
}>;
|
|
@@ -13,26 +13,26 @@ export declare function leaveNetwork(options: WriteActionCLIOptions): Promise<im
|
|
|
13
13
|
export declare function saveObservations(o: WriteActionCLIOptions & {
|
|
14
14
|
failedGateways?: string[];
|
|
15
15
|
transactionId?: string;
|
|
16
|
-
}): Promise<import("../../types/common.js").AoMessageResult
|
|
16
|
+
}): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
17
17
|
export declare function increaseOperatorStake(o: OperatorStakeCLIOptions): Promise<import("../../types/common.js").WriteOptions>;
|
|
18
|
-
export declare function decreaseOperatorStake(o: OperatorStakeCLIOptions): Promise<import("../../types/common.js").AoMessageResult
|
|
19
|
-
export declare function instantWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult
|
|
20
|
-
export declare function cancelWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult
|
|
18
|
+
export declare function decreaseOperatorStake(o: OperatorStakeCLIOptions): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
19
|
+
export declare function instantWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
20
|
+
export declare function cancelWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
21
21
|
export declare function delegateStake(options: TransferCLIOptions): Promise<{
|
|
22
22
|
senderAddress: string;
|
|
23
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
23
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
24
24
|
message: string;
|
|
25
25
|
} | {
|
|
26
26
|
message: string;
|
|
27
27
|
}>;
|
|
28
28
|
export declare function decreaseDelegateStake(options: DecreaseDelegateStakeCLIOptions): Promise<{
|
|
29
29
|
targetGateway: string;
|
|
30
|
-
decreaseDelegateStakeResult: import("../../types/common.js").AoMessageResult
|
|
30
|
+
decreaseDelegateStakeResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
31
31
|
message: string;
|
|
32
32
|
}>;
|
|
33
33
|
export declare function redelegateStake(options: RedelegateStakeCLIOptions): Promise<{
|
|
34
34
|
sourceGateway: string;
|
|
35
35
|
targetGateway: string;
|
|
36
|
-
redelegateStakeResult: import("../../types/common.js").AoMessageResult
|
|
36
|
+
redelegateStakeResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
37
37
|
message: string;
|
|
38
38
|
}>;
|
|
@@ -58,6 +58,7 @@ export declare function getCostDetails(o: GlobalCLIOptions & CLIOptionsFromAoPar
|
|
|
58
58
|
basePrice: number;
|
|
59
59
|
}) | undefined;
|
|
60
60
|
fundingPlan?: import("../../types/io.js").AoFundingPlan | undefined;
|
|
61
|
+
wincQty?: string | undefined;
|
|
61
62
|
}>;
|
|
62
63
|
export declare function getPrimaryName(o: AddressAndNameCLIOptions): Promise<import("../../types/common.js").AoPrimaryName>;
|
|
63
64
|
export declare function getGatewayVaults(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoGatewayVault> | {
|
|
@@ -17,7 +17,7 @@ import { AoCreateVaultParams, AoExtendVaultParams, AoIncreaseVaultParams, AoRevo
|
|
|
17
17
|
import { CLIWriteOptionsFromAoParams, JsonSerializable, TransferCLIOptions } from '../types.js';
|
|
18
18
|
export declare function transferCLICommand(options: TransferCLIOptions): Promise<{
|
|
19
19
|
senderAddress: string;
|
|
20
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
20
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
21
21
|
message: string;
|
|
22
22
|
} | {
|
|
23
23
|
message: string;
|
|
@@ -27,14 +27,14 @@ export declare function revokeVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoR
|
|
|
27
27
|
export declare function createVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoCreateVaultParams>): Promise<JsonSerializable>;
|
|
28
28
|
export declare function extendVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoExtendVaultParams>): Promise<{
|
|
29
29
|
senderAddress: string;
|
|
30
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
30
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
31
31
|
message: string;
|
|
32
32
|
} | {
|
|
33
33
|
message: string;
|
|
34
34
|
}>;
|
|
35
35
|
export declare function increaseVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoIncreaseVaultParams>): Promise<{
|
|
36
36
|
senderAddress: string;
|
|
37
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
37
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
38
38
|
message: string;
|
|
39
39
|
} | {
|
|
40
40
|
message: string;
|
|
@@ -45,6 +45,10 @@ export declare const optionMap: {
|
|
|
45
45
|
alias: string;
|
|
46
46
|
description: string;
|
|
47
47
|
};
|
|
48
|
+
paymentUrl: {
|
|
49
|
+
alias: string;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
48
52
|
processId: {
|
|
49
53
|
alias: string;
|
|
50
54
|
description: string;
|
|
@@ -265,6 +269,11 @@ export declare const optionMap: {
|
|
|
265
269
|
alias: string;
|
|
266
270
|
description: string;
|
|
267
271
|
};
|
|
272
|
+
token: {
|
|
273
|
+
alias: string;
|
|
274
|
+
description: string;
|
|
275
|
+
default: string;
|
|
276
|
+
};
|
|
268
277
|
};
|
|
269
278
|
export declare const walletOptions: {
|
|
270
279
|
alias: string;
|
package/lib/types/cli/types.d.ts
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { AoAddressParams, AoArNSNameParams, AoGetVaultParams, AoJoinNetworkParams, AoTokenCostParams, PaginationParams } from '../types/io.js';
|
|
17
|
+
export type SupportedCLITokenType = 'ethereum' | 'arweave';
|
|
17
18
|
export type WalletCLIOptions = {
|
|
18
19
|
walletFile?: string;
|
|
20
|
+
token?: SupportedCLITokenType;
|
|
19
21
|
privateKey?: string;
|
|
20
22
|
};
|
|
21
23
|
export type GlobalCLIOptions = WalletCLIOptions & {
|
|
@@ -25,6 +27,7 @@ export type GlobalCLIOptions = WalletCLIOptions & {
|
|
|
25
27
|
debug: boolean;
|
|
26
28
|
arioProcessId?: string;
|
|
27
29
|
cuUrl?: string;
|
|
30
|
+
paymentUrl?: string;
|
|
28
31
|
};
|
|
29
32
|
export type WriteActionCLIOptions = GlobalCLIOptions & {
|
|
30
33
|
tags?: string[];
|
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export declare function requiredJwkFromOptions(options: WalletCLIOptions): JWKIn
|
|
|
22
22
|
export declare function jwkToAddress(jwk: JWKInterface): string;
|
|
23
23
|
export declare function getLoggerFromOptions(options: GlobalCLIOptions): Logger;
|
|
24
24
|
export declare function readARIOFromOptions(options: GlobalCLIOptions): AoARIORead;
|
|
25
|
+
export declare function contractSignerFromOptions(options: WalletCLIOptions): {
|
|
26
|
+
signer: ContractSigner;
|
|
27
|
+
signerAddress: string;
|
|
28
|
+
} | undefined;
|
|
25
29
|
export declare function requiredContractSignerFromOptions(options: WalletCLIOptions): {
|
|
26
30
|
signer: ContractSigner;
|
|
27
31
|
signerAddress: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AoANTVersionsRead, AoANTVersionsWrite } from '../types/ant.js';
|
|
2
|
-
import { WithSigner } from '../types/common.js';
|
|
2
|
+
import { AoMessageResult, WithSigner } from '../types/common.js';
|
|
3
3
|
import { ProcessConfiguration } from '../types/io.js';
|
|
4
4
|
import { AOProcess } from './contracts/ao-process.js';
|
|
5
5
|
type ANTVersionsNoSigner = ProcessConfiguration;
|
|
@@ -27,16 +27,13 @@ export declare class ANTVersionsReadable implements AoANTVersionsRead {
|
|
|
27
27
|
export declare class ANTVersionsWritable extends ANTVersionsReadable implements AoANTVersionsWrite {
|
|
28
28
|
private signer;
|
|
29
29
|
constructor({ signer, ...config }: WithSigner<ProcessConfiguration>);
|
|
30
|
-
addVersion(
|
|
30
|
+
addVersion({ version, moduleId, luaSourceId, notes, }: {
|
|
31
31
|
version: string;
|
|
32
32
|
moduleId: string;
|
|
33
33
|
luaSourceId?: string;
|
|
34
34
|
notes?: string;
|
|
35
35
|
}, { tags }: {
|
|
36
36
|
tags: any;
|
|
37
|
-
}): Promise<
|
|
38
|
-
id: string;
|
|
39
|
-
result?: unknown;
|
|
40
|
-
}>;
|
|
37
|
+
}): Promise<AoMessageResult>;
|
|
41
38
|
}
|
|
42
39
|
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { ARIOWithFaucet, TokenFaucet } from '../types/faucet.js';
|
|
17
|
+
import { ARIOReadable, ARIOWriteable } from './io.js';
|
|
18
|
+
/**
|
|
19
|
+
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
20
|
+
* @param arioInstance - The ARIOReadable instance
|
|
21
|
+
* @param faucetApiUrl - The URL of the faucet API
|
|
22
|
+
* @returns A proxy object that implements the TokenFaucet interface
|
|
23
|
+
*/
|
|
24
|
+
export declare function createFaucet({ arioInstance, faucetApiUrl, }: {
|
|
25
|
+
arioInstance: ARIOReadable | ARIOWriteable;
|
|
26
|
+
faucetApiUrl?: string;
|
|
27
|
+
}): ARIOWithFaucet<ARIOReadable | ARIOWriteable>;
|
|
28
|
+
export declare class ARIOTokenFaucet implements TokenFaucet {
|
|
29
|
+
private faucetUrl;
|
|
30
|
+
private processId;
|
|
31
|
+
constructor({ faucetUrl, processId, }: {
|
|
32
|
+
faucetUrl: string;
|
|
33
|
+
processId: string;
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
|
|
37
|
+
* @returns The captcha URL for a process
|
|
38
|
+
*/
|
|
39
|
+
captchaUrl(): Promise<{
|
|
40
|
+
processId: string;
|
|
41
|
+
captchaUrl: string;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
|
|
45
|
+
* @param captchaResponse - The captcha response
|
|
46
|
+
* @param recipient - The recipient address
|
|
47
|
+
* @param quantity - The quantity of tokens to claim
|
|
48
|
+
* @returns The claim id and success status
|
|
49
|
+
*/
|
|
50
|
+
claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }: {
|
|
51
|
+
captchaResponse: string;
|
|
52
|
+
recipient: string;
|
|
53
|
+
quantity: number;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
success: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
|
|
60
|
+
* @param captchaResponse - The captcha response
|
|
61
|
+
* @returns The status of the request, the authorization token, and the expiration time
|
|
62
|
+
*/
|
|
63
|
+
requestAuthToken({ captchaResponse, }: {
|
|
64
|
+
captchaResponse: string;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
status: 'success' | 'error';
|
|
67
|
+
token: string;
|
|
68
|
+
expiresAt: number;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
|
|
72
|
+
* @param authToken - The authorization token
|
|
73
|
+
* @param recipient - The recipient address
|
|
74
|
+
* @param quantity - The quantity of tokens to claim
|
|
75
|
+
* @returns The message id of the transfer and success status
|
|
76
|
+
*/
|
|
77
|
+
claimWithAuthToken({ authToken, recipient, quantity, }: {
|
|
78
|
+
authToken: string;
|
|
79
|
+
recipient: string;
|
|
80
|
+
quantity: number;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
id: string;
|
|
83
|
+
success: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Verifies an authorization token is valid.
|
|
87
|
+
* @param authToken - The authorization token
|
|
88
|
+
* @returns The validity of the authorization token and the expiration time
|
|
89
|
+
*/
|
|
90
|
+
verifyAuthToken({ authToken }: {
|
|
91
|
+
authToken: string;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
valid: boolean;
|
|
94
|
+
expiresAt: number;
|
|
95
|
+
}>;
|
|
96
|
+
}
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
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
1
|
import Arweave from 'arweave';
|
|
17
|
-
import { AoArNSNameDataWithName, AoArNSReservedNameData, AoBalanceWithAddress, AoEpochDistributionData, AoEpochObservationData, AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoReturnedName, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, OptionalArweave, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
|
|
18
|
-
import { AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionTotalsData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoPaginatedAddressParams, AoRegistrationFees, AoRevokeVaultParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
|
|
19
|
-
import { mARIOToken } from '../types/token.js';
|
|
2
|
+
import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, 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, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
|
|
20
3
|
import { AOProcess } from './contracts/ao-process.js';
|
|
21
|
-
|
|
22
|
-
type
|
|
4
|
+
import { TurboArNSPaymentProvider } from './turbo.js';
|
|
5
|
+
type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>;
|
|
6
|
+
type ARIOConfigWithSigner = WithSigner<OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>>;
|
|
23
7
|
export declare class ARIO {
|
|
24
8
|
static init(): AoARIORead;
|
|
25
9
|
static init(config: ARIOConfigWithSigner): AoARIOWrite;
|
|
26
10
|
static init(config: ARIOConfigNoSigner): AoARIORead;
|
|
11
|
+
static mainnet(): AoARIORead;
|
|
12
|
+
static mainnet(config: ARIOConfigNoSigner & {
|
|
13
|
+
faucetUrl?: string;
|
|
14
|
+
}): AoARIORead;
|
|
15
|
+
static mainnet(config: ARIOConfigWithSigner & {
|
|
16
|
+
faucetUrl?: string;
|
|
17
|
+
}): AoARIOWrite;
|
|
18
|
+
static testnet(): ARIOWithFaucet<AoARIORead>;
|
|
19
|
+
static testnet(config: ARIOConfigNoSigner & {
|
|
20
|
+
faucetUrl?: string;
|
|
21
|
+
}): ARIOWithFaucet<AoARIORead>;
|
|
22
|
+
static testnet(config: ARIOConfigWithSigner & {
|
|
23
|
+
faucetUrl?: string;
|
|
24
|
+
}): ARIOWithFaucet<AoARIOWrite>;
|
|
27
25
|
}
|
|
28
26
|
export declare class ARIOReadable implements AoARIORead {
|
|
29
|
-
|
|
27
|
+
readonly process: AOProcess;
|
|
30
28
|
protected epochSettings: AoEpochSettings | undefined;
|
|
31
29
|
protected arweave: Arweave;
|
|
32
|
-
|
|
30
|
+
protected paymentProvider: TurboArNSPaymentProvider;
|
|
31
|
+
constructor(config?: ARIOConfigNoSigner);
|
|
33
32
|
getInfo(): Promise<{
|
|
34
33
|
Name: string;
|
|
35
34
|
Ticker: string;
|
|
@@ -44,8 +43,8 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
44
43
|
private computeCurrentEpochIndex;
|
|
45
44
|
private computeEpochIndex;
|
|
46
45
|
getEpochSettings(): Promise<AoEpochSettings>;
|
|
47
|
-
getEpoch(epoch: EpochInput): Promise<AoEpochData<AoEpochDistributed>>;
|
|
48
46
|
getEpoch(): Promise<AoEpochData<AoEpochDistributionTotalsData>>;
|
|
47
|
+
getEpoch(epoch: EpochInput): Promise<AoEpochData<AoEpochDistributed>>;
|
|
49
48
|
getArNSRecord({ name }: {
|
|
50
49
|
name: string;
|
|
51
50
|
}): Promise<AoArNSNameData>;
|
|
@@ -142,9 +141,10 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
142
141
|
getAllGatewayVaults(params?: PaginationParams<AoAllGatewayVaults>): Promise<PaginationResult<AoAllGatewayVaults>>;
|
|
143
142
|
}
|
|
144
143
|
export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
|
|
145
|
-
|
|
144
|
+
readonly process: AOProcess;
|
|
146
145
|
private signer;
|
|
147
|
-
|
|
146
|
+
protected paymentProvider: TurboArNSPaymentProvider;
|
|
147
|
+
constructor({ signer, paymentUrl, ...config }: ARIOConfigWithSigner);
|
|
148
148
|
transfer({ target, qty, }: {
|
|
149
149
|
target: string;
|
|
150
150
|
qty: number | mARIOToken;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
2
|
+
import { AoMessageResult, TransactionId, TurboArNSSigner, WriteOptions } from '../types/common.js';
|
|
3
|
+
import { AoTokenCostParams } from '../types/io.js';
|
|
4
|
+
import { mARIOToken } from '../types/token.js';
|
|
5
|
+
import { ILogger } from './logger.js';
|
|
6
|
+
export interface TurboConfig {
|
|
7
|
+
paymentUrl?: string;
|
|
8
|
+
logger?: ILogger;
|
|
9
|
+
axios?: AxiosInstance;
|
|
10
|
+
signer?: TurboArNSSigner;
|
|
11
|
+
}
|
|
12
|
+
export declare function signedRequestHeadersFromSigner({ signer, nonce, }: {
|
|
13
|
+
signer: TurboArNSSigner;
|
|
14
|
+
nonce?: string;
|
|
15
|
+
}): Promise<RawAxiosRequestHeaders>;
|
|
16
|
+
export type ArNSPurchaseReceipt = AoTokenCostParams & {
|
|
17
|
+
wincQty: string;
|
|
18
|
+
mARIOQty: string;
|
|
19
|
+
usdArRate: number;
|
|
20
|
+
createdDate: string;
|
|
21
|
+
};
|
|
22
|
+
export interface ArNSPaymentProvider {
|
|
23
|
+
/** Returns the cost of the action in the Payment Provider's native currency (winc for Turbo) */
|
|
24
|
+
getPrice(params: AoTokenCostParams): Promise<number>;
|
|
25
|
+
getArNSPriceDetails(params: AoTokenCostParams): Promise<{
|
|
26
|
+
winc: string;
|
|
27
|
+
mARIO: mARIOToken;
|
|
28
|
+
}>;
|
|
29
|
+
initiateArNSPurchase(params: AoTokenCostParams & {
|
|
30
|
+
processId?: TransactionId;
|
|
31
|
+
}, options: WriteOptions): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
32
|
+
}
|
|
33
|
+
export declare class TurboArNSPaymentProvider implements ArNSPaymentProvider {
|
|
34
|
+
private readonly paymentUrl;
|
|
35
|
+
private readonly axios;
|
|
36
|
+
private readonly logger;
|
|
37
|
+
private readonly signer?;
|
|
38
|
+
constructor({ paymentUrl, axios, logger, signer, }: TurboConfig);
|
|
39
|
+
getArNSPriceDetails({ intent, name, quantity, type, years, }: AoTokenCostParams): Promise<{
|
|
40
|
+
winc: string;
|
|
41
|
+
mARIO: mARIOToken;
|
|
42
|
+
}>;
|
|
43
|
+
getPrice(params: AoTokenCostParams): Promise<number>;
|
|
44
|
+
initiateArNSPurchase({ intent, name, quantity, type, processId, years, }: AoTokenCostParams & {
|
|
45
|
+
processId?: TransactionId;
|
|
46
|
+
}): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
47
|
+
}
|