@ar.io/sdk 3.10.0-alpha.1 → 3.10.0
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 +150 -126
- package/lib/cjs/cli/commands/antCommands.js +3 -4
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -6
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +11 -12
- package/lib/cjs/cli/commands/readCommands.js +21 -22
- package/lib/cjs/cli/commands/transfer.js +6 -7
- package/lib/cjs/cli/options.js +0 -12
- package/lib/cjs/cli/utils.js +52 -74
- 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 +71 -55
- package/lib/cjs/types/ant.js +2 -2
- package/lib/cjs/types/faucet.js +2 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/io.js +8 -7
- package/lib/cjs/utils/ao.js +11 -9
- package/lib/cjs/utils/arweave.js +4 -4
- package/lib/cjs/utils/base64.js +4 -5
- package/lib/cjs/utils/json.js +1 -2
- package/lib/cjs/utils/schema.js +1 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/options.js +0 -12
- package/lib/esm/cli/utils.js +10 -31
- 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 +70 -54
- 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/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 +3 -4
- package/lib/types/cli/commands/transfer.d.ts +3 -3
- package/lib/types/cli/options.d.ts +0 -9
- package/lib/types/cli/types.d.ts +0 -3
- package/lib/types/cli/utils.d.ts +1 -5
- package/lib/types/common/ant-versions.d.ts +6 -3
- package/lib/types/common/faucet.d.ts +96 -0
- package/lib/types/common/http.d.ts +0 -1
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/io.d.ts +22 -13
- package/lib/types/types/common.d.ts +1 -7
- 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 -10
- package/lib/types/types/token.d.ts +0 -1
- package/lib/types/utils/base64.d.ts +0 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +5 -7
- package/lib/cjs/common/turbo.js +0 -134
- package/lib/cjs/utils/url.js +0 -28
- package/lib/cjs/utils/url.test.js +0 -24
- package/lib/esm/common/turbo.js +0 -129
- package/lib/esm/utils/url.js +0 -24
- package/lib/esm/utils/url.test.js +0 -19
- package/lib/types/common/turbo.d.ts +0 -47
- package/lib/types/utils/url.d.ts +0 -19
- /package/lib/{types/utils/url.test.d.ts → esm/types/faucet.js} +0 -0
package/lib/esm/common/turbo.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/esm/utils/url.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/types/utils/url.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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 declare const urlWithSearchParams: ({ baseUrl, params, }: {
|
|
17
|
-
baseUrl: string;
|
|
18
|
-
params: Record<string, string | number | boolean | null | undefined>;
|
|
19
|
-
}) => string;
|
|
File without changes
|