@ar.io/sdk 3.10.0-alpha.1 → 3.10.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/README.md +124 -140
- package/bundles/web.bundle.min.js +70 -67
- package/lib/cjs/common/faucet.js +150 -0
- package/lib/cjs/common/index.js +1 -0
- package/lib/cjs/common/io.js +85 -6
- package/lib/cjs/common/turbo.js +92 -18
- package/lib/cjs/types/faucet.js +2 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/io.js +3 -2
- package/lib/cjs/utils/ao.js +2 -0
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/web/index.js +3 -1
- package/lib/esm/common/faucet.js +145 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/io.js +85 -6
- package/lib/esm/common/turbo.js +88 -17
- package/lib/esm/types/faucet.js +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/io.js +3 -2
- package/lib/esm/utils/ao.js +2 -0
- package/lib/esm/version.js +1 -1
- package/lib/esm/web/index.js +1 -1
- package/lib/types/cli/utils.d.ts +1 -1
- 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 +20 -8
- package/lib/types/common/turbo.d.ts +25 -10
- package/lib/types/types/common.d.ts +2 -2
- 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 +2 -2
- package/lib/types/version.d.ts +1 -1
- package/lib/types/web/index.d.ts +1 -1
- package/package.json +5 -6
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARIOTokenFaucet = exports.createFaucet = void 0;
|
|
4
|
+
const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
7
|
+
* @param arioInstance - The ARIOReadable instance
|
|
8
|
+
* @param faucetApiUrl - The URL of the faucet API
|
|
9
|
+
* @returns A proxy object that implements the TokenFaucet interface
|
|
10
|
+
*/
|
|
11
|
+
function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, }) {
|
|
12
|
+
const faucet = new ARIOTokenFaucet({
|
|
13
|
+
faucetUrl: faucetApiUrl,
|
|
14
|
+
processId: arioInstance.process.processId,
|
|
15
|
+
});
|
|
16
|
+
const proxy = new Proxy(arioInstance, {
|
|
17
|
+
get(target, prop) {
|
|
18
|
+
if (prop === 'faucet') {
|
|
19
|
+
return faucet;
|
|
20
|
+
}
|
|
21
|
+
if (prop in target) {
|
|
22
|
+
const result = target[prop];
|
|
23
|
+
if (typeof result === 'function') {
|
|
24
|
+
return result.bind(target);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
return proxy;
|
|
32
|
+
}
|
|
33
|
+
exports.createFaucet = createFaucet;
|
|
34
|
+
class ARIOTokenFaucet {
|
|
35
|
+
faucetUrl;
|
|
36
|
+
processId;
|
|
37
|
+
constructor({ faucetUrl, processId, }) {
|
|
38
|
+
this.faucetUrl = faucetUrl;
|
|
39
|
+
this.processId = processId;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 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.
|
|
43
|
+
* @returns The captcha URL for a process
|
|
44
|
+
*/
|
|
45
|
+
async captchaUrl() {
|
|
46
|
+
const res = await fetch(`${this.faucetUrl}/api/captcha/url?process-id=${this.processId}`, {
|
|
47
|
+
method: 'GET',
|
|
48
|
+
});
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
51
|
+
throw new Error(body.error);
|
|
52
|
+
}
|
|
53
|
+
const data = (await res.json());
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
|
|
58
|
+
* @param captchaResponse - The captcha response
|
|
59
|
+
* @param recipient - The recipient address
|
|
60
|
+
* @param quantity - The quantity of tokens to claim
|
|
61
|
+
* @returns The claim id and success status
|
|
62
|
+
*/
|
|
63
|
+
async claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }) {
|
|
64
|
+
const res = await fetch(`${this.faucetUrl}/api/claim/sync`, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: { 'Content-Type': 'application/json' },
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
processId: this.processId,
|
|
69
|
+
recipient,
|
|
70
|
+
quantity,
|
|
71
|
+
captchaResponse,
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
76
|
+
throw new Error(body.error);
|
|
77
|
+
}
|
|
78
|
+
const data = (await res.json());
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 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.
|
|
83
|
+
* @param captchaResponse - The captcha response
|
|
84
|
+
* @returns The status of the request, the authorization token, and the expiration time
|
|
85
|
+
*/
|
|
86
|
+
async requestAuthToken({ captchaResponse, }) {
|
|
87
|
+
const res = await fetch(`${this.faucetUrl}/api/captcha/verify`, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: { 'Content-Type': 'application/json' },
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
processId: this.processId,
|
|
92
|
+
captchaResponse,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
97
|
+
throw new Error(body.error);
|
|
98
|
+
}
|
|
99
|
+
const data = (await res.json());
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 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.
|
|
104
|
+
* @param authToken - The authorization token
|
|
105
|
+
* @param recipient - The recipient address
|
|
106
|
+
* @param quantity - The quantity of tokens to claim
|
|
107
|
+
* @returns The message id of the transfer and success status
|
|
108
|
+
*/
|
|
109
|
+
async claimWithAuthToken({ authToken, recipient, quantity, }) {
|
|
110
|
+
const res = await fetch(`${this.faucetUrl}/api/claim/async`, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
Authorization: `Bearer ${authToken}`,
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify({
|
|
117
|
+
recipient,
|
|
118
|
+
qty: quantity,
|
|
119
|
+
processId: this.processId,
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
if (!res.ok) {
|
|
123
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
124
|
+
throw new Error(body.error);
|
|
125
|
+
}
|
|
126
|
+
const data = (await res.json());
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Verifies an authorization token is valid.
|
|
131
|
+
* @param authToken - The authorization token
|
|
132
|
+
* @returns The validity of the authorization token and the expiration time
|
|
133
|
+
*/
|
|
134
|
+
async verifyAuthToken({ authToken }) {
|
|
135
|
+
const res = await fetch(`${this.faucetUrl}/api/token/verify?process-id=${this.processId}`, {
|
|
136
|
+
method: 'GET',
|
|
137
|
+
headers: {
|
|
138
|
+
'Content-Type': 'application/json',
|
|
139
|
+
Authorization: `Bearer ${authToken}`,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
if (!res.ok) {
|
|
143
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
144
|
+
throw new Error(body.error);
|
|
145
|
+
}
|
|
146
|
+
const data = (await res.json());
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.ARIOTokenFaucet = ARIOTokenFaucet;
|
package/lib/cjs/common/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __exportStar(require("./logger.js"), exports);
|
|
|
34
34
|
__exportStar(require("./ant.js"), exports);
|
|
35
35
|
__exportStar(require("./ant-registry.js"), exports);
|
|
36
36
|
__exportStar(require("./ant-versions.js"), exports);
|
|
37
|
+
__exportStar(require("./faucet.js"), exports);
|
|
37
38
|
// ao
|
|
38
39
|
__exportStar(require("./io.js"), exports);
|
|
39
40
|
__exportStar(require("./contracts/ao-process.js"), exports);
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ARIOWriteable = exports.ARIOReadable = exports.ARIO = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
4
20
|
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const
|
|
21
|
+
const index_js_1 = require("../types/index.js");
|
|
6
22
|
const ao_js_1 = require("../utils/ao.js");
|
|
7
23
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
8
24
|
const arweave_js_2 = require("./arweave.js");
|
|
9
25
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
10
26
|
const error_js_1 = require("./error.js");
|
|
27
|
+
const faucet_js_1 = require("./faucet.js");
|
|
11
28
|
const turbo_js_1 = require("./turbo.js");
|
|
12
29
|
class ARIO {
|
|
13
30
|
// Implementation
|
|
@@ -17,6 +34,56 @@ class ARIO {
|
|
|
17
34
|
}
|
|
18
35
|
return new ARIOReadable(config);
|
|
19
36
|
}
|
|
37
|
+
static mainnet(config) {
|
|
38
|
+
if (config !== undefined && 'signer' in config) {
|
|
39
|
+
return new ARIOWriteable({
|
|
40
|
+
...config,
|
|
41
|
+
process: new ao_process_js_1.AOProcess({
|
|
42
|
+
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
43
|
+
ao: (0, aoconnect_1.connect)({
|
|
44
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
45
|
+
...config?.process?.ao,
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return new ARIOReadable({
|
|
51
|
+
...config,
|
|
52
|
+
process: new ao_process_js_1.AOProcess({
|
|
53
|
+
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
static testnet(config) {
|
|
58
|
+
if (config !== undefined && 'signer' in config) {
|
|
59
|
+
return (0, faucet_js_1.createFaucet)({
|
|
60
|
+
arioInstance: new ARIOWriteable({
|
|
61
|
+
...config,
|
|
62
|
+
process: new ao_process_js_1.AOProcess({
|
|
63
|
+
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
64
|
+
ao: (0, aoconnect_1.connect)({
|
|
65
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
66
|
+
...config?.process?.ao,
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
faucetApiUrl: config?.faucetUrl,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return (0, faucet_js_1.createFaucet)({
|
|
74
|
+
arioInstance: new ARIOReadable({
|
|
75
|
+
...config,
|
|
76
|
+
process: new ao_process_js_1.AOProcess({
|
|
77
|
+
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
78
|
+
ao: (0, aoconnect_1.connect)({
|
|
79
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
80
|
+
...config?.process?.ao,
|
|
81
|
+
}),
|
|
82
|
+
}),
|
|
83
|
+
}),
|
|
84
|
+
faucetApiUrl: config?.faucetUrl,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
20
87
|
}
|
|
21
88
|
exports.ARIO = ARIO;
|
|
22
89
|
class ARIOReadable {
|
|
@@ -31,10 +98,10 @@ class ARIOReadable {
|
|
|
31
98
|
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
32
99
|
});
|
|
33
100
|
}
|
|
34
|
-
else if ((0,
|
|
101
|
+
else if ((0, index_js_1.isProcessConfiguration)(config)) {
|
|
35
102
|
this.process = config.process;
|
|
36
103
|
}
|
|
37
|
-
else if ((0,
|
|
104
|
+
else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
|
|
38
105
|
this.process = new ao_process_js_1.AOProcess({
|
|
39
106
|
processId: config.processId,
|
|
40
107
|
});
|
|
@@ -42,7 +109,7 @@ class ARIOReadable {
|
|
|
42
109
|
else {
|
|
43
110
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
44
111
|
}
|
|
45
|
-
this.paymentProvider =
|
|
112
|
+
this.paymentProvider = turbo_js_1.TurboArNSPaymentFactory.init({
|
|
46
113
|
paymentUrl: config?.paymentUrl,
|
|
47
114
|
});
|
|
48
115
|
}
|
|
@@ -570,8 +637,8 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
570
637
|
super(config);
|
|
571
638
|
}
|
|
572
639
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
573
|
-
this.paymentProvider =
|
|
574
|
-
signer: signer,
|
|
640
|
+
this.paymentProvider = turbo_js_1.TurboArNSPaymentFactory.init({
|
|
641
|
+
signer: (0, turbo_js_1.isTurboArNSSigner)(signer) ? signer : undefined,
|
|
575
642
|
paymentUrl,
|
|
576
643
|
});
|
|
577
644
|
}
|
|
@@ -849,6 +916,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
849
916
|
}
|
|
850
917
|
async buyRecord(params, options) {
|
|
851
918
|
if (params.fundFrom === 'turbo') {
|
|
919
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
920
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
921
|
+
}
|
|
852
922
|
return this.paymentProvider.initiateArNSPurchase({
|
|
853
923
|
intent: 'Buy-Name',
|
|
854
924
|
...params,
|
|
@@ -879,6 +949,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
879
949
|
*/
|
|
880
950
|
async upgradeRecord(params, options) {
|
|
881
951
|
if (params.fundFrom === 'turbo') {
|
|
952
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
953
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
954
|
+
}
|
|
882
955
|
return this.paymentProvider.initiateArNSPurchase({
|
|
883
956
|
intent: 'Upgrade-Name',
|
|
884
957
|
name: params.name,
|
|
@@ -907,6 +980,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
907
980
|
*/
|
|
908
981
|
async extendLease(params, options) {
|
|
909
982
|
if (params.fundFrom === 'turbo') {
|
|
983
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
984
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
985
|
+
}
|
|
910
986
|
return this.paymentProvider.initiateArNSPurchase({
|
|
911
987
|
intent: 'Extend-Lease',
|
|
912
988
|
...params,
|
|
@@ -927,6 +1003,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
927
1003
|
}
|
|
928
1004
|
async increaseUndernameLimit(params, options) {
|
|
929
1005
|
if (params.fundFrom === 'turbo') {
|
|
1006
|
+
if (!(this.paymentProvider instanceof turbo_js_1.TurboArNSPaymentProviderAuthenticated)) {
|
|
1007
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
1008
|
+
}
|
|
930
1009
|
return this.paymentProvider.initiateArNSPurchase({
|
|
931
1010
|
intent: 'Increase-Undername-Limit',
|
|
932
1011
|
...params,
|
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.
|
|
3
|
+
exports.isTurboArNSSigner = exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = exports.signedRequestHeadersFromSigner = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
6
|
*
|
|
@@ -24,40 +24,89 @@ const http_client_js_1 = require("../utils/http-client.js");
|
|
|
24
24
|
const url_js_1 = require("../utils/url.js");
|
|
25
25
|
const logger_js_1 = require("./logger.js");
|
|
26
26
|
async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)(), }) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
let signature = undefined;
|
|
28
|
+
let publicKey = undefined;
|
|
29
|
+
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
30
|
+
? arbundles_1.SignatureConfig.ARWEAVE
|
|
31
|
+
: signer.signatureType;
|
|
32
|
+
// equivalent to window.arweaveWallet
|
|
33
|
+
if (isWanderArweaveBrowserSigner(signer)) {
|
|
34
|
+
signature = (0, base64_js_1.toB64Url)(Buffer.from(await signer.signMessage(Uint8Array.from(Buffer.from(nonce)))));
|
|
35
|
+
}
|
|
36
|
+
else if (signer instanceof arbundles_1.ArconnectSigner) {
|
|
37
|
+
signature = (0, base64_js_1.toB64Url)(Buffer.from(await signer['signer'].signMessage(Uint8Array.from(Buffer.from(nonce)))));
|
|
38
|
+
}
|
|
39
|
+
else if (signer instanceof arbundles_1.ArweaveSigner ||
|
|
40
|
+
signer instanceof arbundles_1.EthereumSigner ||
|
|
41
|
+
signer instanceof arbundles_1.InjectedEthereumSigner) {
|
|
42
|
+
if ('setPublicKey' in signer) {
|
|
43
|
+
await signer.setPublicKey();
|
|
44
|
+
}
|
|
45
|
+
signature = (0, base64_js_1.toB64Url)(Buffer.from(await signer.sign(Uint8Array.from(Buffer.from(nonce)))));
|
|
46
|
+
}
|
|
47
|
+
switch (signatureType) {
|
|
31
48
|
case arbundles_1.SignatureConfig.ARWEAVE:
|
|
32
|
-
|
|
49
|
+
if (isWanderArweaveBrowserSigner(signer)) {
|
|
50
|
+
publicKey = await signer.getActivePublicKey();
|
|
51
|
+
}
|
|
52
|
+
else if ('setPublicKey' in signer) {
|
|
53
|
+
await signer.setPublicKey();
|
|
54
|
+
publicKey = (0, base64_js_1.toB64Url)(signer.publicKey);
|
|
55
|
+
}
|
|
33
56
|
break;
|
|
34
57
|
case arbundles_1.SignatureConfig.ETHEREUM:
|
|
35
|
-
|
|
58
|
+
if ('publicKey' in signer) {
|
|
59
|
+
publicKey = '0x' + signer.publicKey.toString('hex');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error('Public key not found');
|
|
63
|
+
}
|
|
36
64
|
break;
|
|
37
65
|
// TODO: solana sig support
|
|
38
66
|
// case SignatureConfig.SOLANA:
|
|
39
67
|
// case SignatureConfig.ED25519:
|
|
40
68
|
default:
|
|
41
|
-
throw new Error(`Unsupported signer type for signing requests: ${
|
|
69
|
+
throw new Error(`Unsupported signer type for signing requests: ${signatureType}`);
|
|
70
|
+
}
|
|
71
|
+
if (publicKey === undefined || signature === undefined) {
|
|
72
|
+
throw new Error('Public key or signature not found');
|
|
42
73
|
}
|
|
43
74
|
return {
|
|
44
75
|
'x-public-key': publicKey,
|
|
45
76
|
'x-nonce': nonce,
|
|
46
|
-
'x-signature':
|
|
47
|
-
'x-signature-type':
|
|
77
|
+
'x-signature': signature,
|
|
78
|
+
'x-signature-type': signatureType,
|
|
48
79
|
};
|
|
49
80
|
}
|
|
50
81
|
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
51
|
-
class
|
|
82
|
+
class TurboArNSPaymentFactory {
|
|
83
|
+
static init(config) {
|
|
84
|
+
const { signer, paymentUrl, axios, logger } = config ?? {};
|
|
85
|
+
if (signer !== undefined) {
|
|
86
|
+
return new TurboArNSPaymentProviderAuthenticated({
|
|
87
|
+
signer,
|
|
88
|
+
paymentUrl,
|
|
89
|
+
axios,
|
|
90
|
+
logger,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return new TurboArNSPaymentProviderUnauthenticated({
|
|
94
|
+
paymentUrl,
|
|
95
|
+
axios,
|
|
96
|
+
logger,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.TurboArNSPaymentFactory = TurboArNSPaymentFactory;
|
|
101
|
+
// Base class for unauthenticated operations
|
|
102
|
+
class TurboArNSPaymentProviderUnauthenticated {
|
|
52
103
|
paymentUrl;
|
|
53
104
|
axios;
|
|
54
105
|
logger;
|
|
55
|
-
|
|
56
|
-
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = (0, http_client_js_1.createAxiosInstance)(), logger = logger_js_1.Logger.default, signer, }) {
|
|
106
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = (0, http_client_js_1.createAxiosInstance)(), logger = logger_js_1.Logger.default, }) {
|
|
57
107
|
this.paymentUrl = paymentUrl;
|
|
58
108
|
this.axios = axios;
|
|
59
109
|
this.logger = logger;
|
|
60
|
-
this.signer = signer;
|
|
61
110
|
}
|
|
62
111
|
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
63
112
|
const url = (0, url_js_1.urlWithSearchParams)({
|
|
@@ -93,10 +142,20 @@ class TurboArNSPaymentProvider {
|
|
|
93
142
|
const { winc } = await this.getArNSPriceDetails(params);
|
|
94
143
|
return +winc;
|
|
95
144
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
145
|
+
}
|
|
146
|
+
exports.TurboArNSPaymentProviderUnauthenticated = TurboArNSPaymentProviderUnauthenticated;
|
|
147
|
+
// Class for authenticated operations, extending the base class
|
|
148
|
+
class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated {
|
|
149
|
+
signer;
|
|
150
|
+
constructor({ signer, ...restConfig }) {
|
|
151
|
+
super(restConfig); // Pass unauthenticated config to base class+
|
|
152
|
+
if (!isTurboArNSSigner(signer)) {
|
|
153
|
+
throw new Error('Signer must be a TurboArNSSigner');
|
|
99
154
|
}
|
|
155
|
+
this.signer = signer;
|
|
156
|
+
}
|
|
157
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
158
|
+
// Signer check is implicitly handled by requiring it in the constructor
|
|
100
159
|
const url = (0, url_js_1.urlWithSearchParams)({
|
|
101
160
|
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
102
161
|
params: {
|
|
@@ -131,4 +190,19 @@ class TurboArNSPaymentProvider {
|
|
|
131
190
|
};
|
|
132
191
|
}
|
|
133
192
|
}
|
|
134
|
-
exports.
|
|
193
|
+
exports.TurboArNSPaymentProviderAuthenticated = TurboArNSPaymentProviderAuthenticated;
|
|
194
|
+
function isWanderArweaveBrowserSigner(signer) {
|
|
195
|
+
return (typeof signer === 'object' &&
|
|
196
|
+
signer !== null &&
|
|
197
|
+
'signMessage' in signer &&
|
|
198
|
+
'getActivePublicKey' in signer);
|
|
199
|
+
}
|
|
200
|
+
function isTurboArNSSigner(signer) {
|
|
201
|
+
const isWanderWallet = isWanderArweaveBrowserSigner(signer);
|
|
202
|
+
const isSigner = signer instanceof arbundles_1.EthereumSigner ||
|
|
203
|
+
signer instanceof arbundles_1.InjectedEthereumSigner ||
|
|
204
|
+
signer instanceof arbundles_1.ArweaveSigner ||
|
|
205
|
+
signer instanceof arbundles_1.ArconnectSigner;
|
|
206
|
+
return isWanderWallet || isSigner;
|
|
207
|
+
}
|
|
208
|
+
exports.isTurboArNSSigner = isTurboArNSSigner;
|
package/lib/cjs/types/index.js
CHANGED
|
@@ -32,5 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
__exportStar(require("./ant-registry.js"), exports);
|
|
33
33
|
__exportStar(require("./ant.js"), exports);
|
|
34
34
|
__exportStar(require("./common.js"), exports);
|
|
35
|
+
__exportStar(require("./faucet.js"), exports);
|
|
35
36
|
__exportStar(require("./io.js"), exports);
|
|
36
37
|
__exportStar(require("./token.js"), exports);
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -35,11 +35,12 @@ const isValidFundFrom = (fundFrom) => {
|
|
|
35
35
|
exports.isValidFundFrom = isValidFundFrom;
|
|
36
36
|
// Type-guard functions
|
|
37
37
|
function isProcessConfiguration(config) {
|
|
38
|
-
return 'process' in config;
|
|
38
|
+
return config !== undefined && 'process' in config;
|
|
39
39
|
}
|
|
40
40
|
exports.isProcessConfiguration = isProcessConfiguration;
|
|
41
41
|
function isProcessIdConfiguration(config) {
|
|
42
|
-
return (
|
|
42
|
+
return (config !== undefined &&
|
|
43
|
+
'processId' in config &&
|
|
43
44
|
typeof config.processId === 'string' &&
|
|
44
45
|
(0, arweave_js_1.validateArweaveId)(config.processId) === true);
|
|
45
46
|
}
|
package/lib/cjs/utils/ao.js
CHANGED
package/lib/cjs/version.js
CHANGED
package/lib/cjs/web/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ArconnectSigner = exports.ArweaveSigner = void 0;
|
|
17
|
+
exports.EthereumSigner = exports.InjectedEthereumSigner = exports.ArconnectSigner = exports.ArweaveSigner = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
20
20
|
*
|
|
@@ -33,6 +33,8 @@ exports.ArconnectSigner = exports.ArweaveSigner = void 0;
|
|
|
33
33
|
var arbundles_1 = require("@dha-team/arbundles");
|
|
34
34
|
Object.defineProperty(exports, "ArweaveSigner", { enumerable: true, get: function () { return arbundles_1.ArweaveSigner; } });
|
|
35
35
|
Object.defineProperty(exports, "ArconnectSigner", { enumerable: true, get: function () { return arbundles_1.ArconnectSigner; } });
|
|
36
|
+
Object.defineProperty(exports, "InjectedEthereumSigner", { enumerable: true, get: function () { return arbundles_1.InjectedEthereumSigner; } });
|
|
37
|
+
Object.defineProperty(exports, "EthereumSigner", { enumerable: true, get: function () { return arbundles_1.EthereumSigner; } });
|
|
36
38
|
__exportStar(require("../types/index.js"), exports);
|
|
37
39
|
__exportStar(require("../common/index.js"), exports);
|
|
38
40
|
__exportStar(require("../constants.js"), exports);
|