@ar.io/sdk 3.10.0-alpha.2 → 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/bundles/web.bundle.min.js +76 -76
- package/lib/cjs/common/io.js +30 -3
- package/lib/cjs/common/turbo.js +92 -18
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/web/index.js +3 -1
- package/lib/esm/common/io.js +31 -4
- package/lib/esm/common/turbo.js +88 -17
- package/lib/esm/version.js +1 -1
- package/lib/esm/web/index.js +1 -1
- package/lib/types/common/io.d.ts +3 -3
- package/lib/types/common/turbo.d.ts +25 -10
- package/lib/types/types/common.d.ts +2 -2
- package/lib/types/version.d.ts +1 -1
- package/lib/types/web/index.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
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
|
+
*/
|
|
4
19
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
5
20
|
const constants_js_1 = require("../constants.js");
|
|
6
21
|
const index_js_1 = require("../types/index.js");
|
|
@@ -94,7 +109,7 @@ class ARIOReadable {
|
|
|
94
109
|
else {
|
|
95
110
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
96
111
|
}
|
|
97
|
-
this.paymentProvider =
|
|
112
|
+
this.paymentProvider = turbo_js_1.TurboArNSPaymentFactory.init({
|
|
98
113
|
paymentUrl: config?.paymentUrl,
|
|
99
114
|
});
|
|
100
115
|
}
|
|
@@ -622,8 +637,8 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
622
637
|
super(config);
|
|
623
638
|
}
|
|
624
639
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
625
|
-
this.paymentProvider =
|
|
626
|
-
signer: signer,
|
|
640
|
+
this.paymentProvider = turbo_js_1.TurboArNSPaymentFactory.init({
|
|
641
|
+
signer: (0, turbo_js_1.isTurboArNSSigner)(signer) ? signer : undefined,
|
|
627
642
|
paymentUrl,
|
|
628
643
|
});
|
|
629
644
|
}
|
|
@@ -901,6 +916,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
901
916
|
}
|
|
902
917
|
async buyRecord(params, options) {
|
|
903
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
|
+
}
|
|
904
922
|
return this.paymentProvider.initiateArNSPurchase({
|
|
905
923
|
intent: 'Buy-Name',
|
|
906
924
|
...params,
|
|
@@ -931,6 +949,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
931
949
|
*/
|
|
932
950
|
async upgradeRecord(params, options) {
|
|
933
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
|
+
}
|
|
934
955
|
return this.paymentProvider.initiateArNSPurchase({
|
|
935
956
|
intent: 'Upgrade-Name',
|
|
936
957
|
name: params.name,
|
|
@@ -959,6 +980,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
959
980
|
*/
|
|
960
981
|
async extendLease(params, options) {
|
|
961
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
|
+
}
|
|
962
986
|
return this.paymentProvider.initiateArNSPurchase({
|
|
963
987
|
intent: 'Extend-Lease',
|
|
964
988
|
...params,
|
|
@@ -979,6 +1003,9 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
979
1003
|
}
|
|
980
1004
|
async increaseUndernameLimit(params, options) {
|
|
981
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
|
+
}
|
|
982
1009
|
return this.paymentProvider.initiateArNSPurchase({
|
|
983
1010
|
intent: 'Increase-Undername-Limit',
|
|
984
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/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);
|
package/lib/esm/common/io.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
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
|
+
*/
|
|
1
16
|
import { connect } from '@permaweb/aoconnect';
|
|
2
17
|
import { ARIO_MAINNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, } from '../constants.js';
|
|
3
18
|
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
|
|
@@ -7,7 +22,7 @@ import { defaultArweave } from './arweave.js';
|
|
|
7
22
|
import { AOProcess } from './contracts/ao-process.js';
|
|
8
23
|
import { InvalidContractConfigurationError } from './error.js';
|
|
9
24
|
import { createFaucet } from './faucet.js';
|
|
10
|
-
import {
|
|
25
|
+
import { TurboArNSPaymentFactory, TurboArNSPaymentProviderAuthenticated, isTurboArNSSigner, } from './turbo.js';
|
|
11
26
|
export class ARIO {
|
|
12
27
|
// Implementation
|
|
13
28
|
static init(config) {
|
|
@@ -90,7 +105,7 @@ export class ARIOReadable {
|
|
|
90
105
|
else {
|
|
91
106
|
throw new InvalidContractConfigurationError();
|
|
92
107
|
}
|
|
93
|
-
this.paymentProvider =
|
|
108
|
+
this.paymentProvider = TurboArNSPaymentFactory.init({
|
|
94
109
|
paymentUrl: config?.paymentUrl,
|
|
95
110
|
});
|
|
96
111
|
}
|
|
@@ -617,8 +632,8 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
617
632
|
super(config);
|
|
618
633
|
}
|
|
619
634
|
this.signer = createAoSigner(signer);
|
|
620
|
-
this.paymentProvider =
|
|
621
|
-
signer: signer,
|
|
635
|
+
this.paymentProvider = TurboArNSPaymentFactory.init({
|
|
636
|
+
signer: isTurboArNSSigner(signer) ? signer : undefined,
|
|
622
637
|
paymentUrl,
|
|
623
638
|
});
|
|
624
639
|
}
|
|
@@ -896,6 +911,9 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
896
911
|
}
|
|
897
912
|
async buyRecord(params, options) {
|
|
898
913
|
if (params.fundFrom === 'turbo') {
|
|
914
|
+
if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
|
|
915
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
916
|
+
}
|
|
899
917
|
return this.paymentProvider.initiateArNSPurchase({
|
|
900
918
|
intent: 'Buy-Name',
|
|
901
919
|
...params,
|
|
@@ -926,6 +944,9 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
926
944
|
*/
|
|
927
945
|
async upgradeRecord(params, options) {
|
|
928
946
|
if (params.fundFrom === 'turbo') {
|
|
947
|
+
if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
|
|
948
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
949
|
+
}
|
|
929
950
|
return this.paymentProvider.initiateArNSPurchase({
|
|
930
951
|
intent: 'Upgrade-Name',
|
|
931
952
|
name: params.name,
|
|
@@ -954,6 +975,9 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
954
975
|
*/
|
|
955
976
|
async extendLease(params, options) {
|
|
956
977
|
if (params.fundFrom === 'turbo') {
|
|
978
|
+
if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
|
|
979
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
980
|
+
}
|
|
957
981
|
return this.paymentProvider.initiateArNSPurchase({
|
|
958
982
|
intent: 'Extend-Lease',
|
|
959
983
|
...params,
|
|
@@ -974,6 +998,9 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
974
998
|
}
|
|
975
999
|
async increaseUndernameLimit(params, options) {
|
|
976
1000
|
if (params.fundFrom === 'turbo') {
|
|
1001
|
+
if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
|
|
1002
|
+
throw new Error('Turbo funding is not supported for this payment provider');
|
|
1003
|
+
}
|
|
977
1004
|
return this.paymentProvider.initiateArNSPurchase({
|
|
978
1005
|
intent: 'Increase-Undername-Limit',
|
|
979
1006
|
...params,
|
package/lib/esm/common/turbo.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { SignatureConfig } from '@dha-team/arbundles';
|
|
16
|
+
import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, SignatureConfig, } from '@dha-team/arbundles';
|
|
17
17
|
import { v4 as uuidv4 } from 'uuid';
|
|
18
18
|
import { mARIOToken } from '../types/token.js';
|
|
19
19
|
import { toB64Url } from '../utils/base64.js';
|
|
@@ -21,39 +21,87 @@ import { createAxiosInstance } from '../utils/http-client.js';
|
|
|
21
21
|
import { urlWithSearchParams } from '../utils/url.js';
|
|
22
22
|
import { Logger } from './logger.js';
|
|
23
23
|
export async function signedRequestHeadersFromSigner({ signer, nonce = uuidv4(), }) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
let signature = undefined;
|
|
25
|
+
let publicKey = undefined;
|
|
26
|
+
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
27
|
+
? SignatureConfig.ARWEAVE
|
|
28
|
+
: signer.signatureType;
|
|
29
|
+
// equivalent to window.arweaveWallet
|
|
30
|
+
if (isWanderArweaveBrowserSigner(signer)) {
|
|
31
|
+
signature = toB64Url(Buffer.from(await signer.signMessage(Uint8Array.from(Buffer.from(nonce)))));
|
|
32
|
+
}
|
|
33
|
+
else if (signer instanceof ArconnectSigner) {
|
|
34
|
+
signature = toB64Url(Buffer.from(await signer['signer'].signMessage(Uint8Array.from(Buffer.from(nonce)))));
|
|
35
|
+
}
|
|
36
|
+
else if (signer instanceof ArweaveSigner ||
|
|
37
|
+
signer instanceof EthereumSigner ||
|
|
38
|
+
signer instanceof InjectedEthereumSigner) {
|
|
39
|
+
if ('setPublicKey' in signer) {
|
|
40
|
+
await signer.setPublicKey();
|
|
41
|
+
}
|
|
42
|
+
signature = toB64Url(Buffer.from(await signer.sign(Uint8Array.from(Buffer.from(nonce)))));
|
|
43
|
+
}
|
|
44
|
+
switch (signatureType) {
|
|
28
45
|
case SignatureConfig.ARWEAVE:
|
|
29
|
-
|
|
46
|
+
if (isWanderArweaveBrowserSigner(signer)) {
|
|
47
|
+
publicKey = await signer.getActivePublicKey();
|
|
48
|
+
}
|
|
49
|
+
else if ('setPublicKey' in signer) {
|
|
50
|
+
await signer.setPublicKey();
|
|
51
|
+
publicKey = toB64Url(signer.publicKey);
|
|
52
|
+
}
|
|
30
53
|
break;
|
|
31
54
|
case SignatureConfig.ETHEREUM:
|
|
32
|
-
|
|
55
|
+
if ('publicKey' in signer) {
|
|
56
|
+
publicKey = '0x' + signer.publicKey.toString('hex');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error('Public key not found');
|
|
60
|
+
}
|
|
33
61
|
break;
|
|
34
62
|
// TODO: solana sig support
|
|
35
63
|
// case SignatureConfig.SOLANA:
|
|
36
64
|
// case SignatureConfig.ED25519:
|
|
37
65
|
default:
|
|
38
|
-
throw new Error(`Unsupported signer type for signing requests: ${
|
|
66
|
+
throw new Error(`Unsupported signer type for signing requests: ${signatureType}`);
|
|
67
|
+
}
|
|
68
|
+
if (publicKey === undefined || signature === undefined) {
|
|
69
|
+
throw new Error('Public key or signature not found');
|
|
39
70
|
}
|
|
40
71
|
return {
|
|
41
72
|
'x-public-key': publicKey,
|
|
42
73
|
'x-nonce': nonce,
|
|
43
|
-
'x-signature':
|
|
44
|
-
'x-signature-type':
|
|
74
|
+
'x-signature': signature,
|
|
75
|
+
'x-signature-type': signatureType,
|
|
45
76
|
};
|
|
46
77
|
}
|
|
47
|
-
export class
|
|
78
|
+
export class TurboArNSPaymentFactory {
|
|
79
|
+
static init(config) {
|
|
80
|
+
const { signer, paymentUrl, axios, logger } = config ?? {};
|
|
81
|
+
if (signer !== undefined) {
|
|
82
|
+
return new TurboArNSPaymentProviderAuthenticated({
|
|
83
|
+
signer,
|
|
84
|
+
paymentUrl,
|
|
85
|
+
axios,
|
|
86
|
+
logger,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return new TurboArNSPaymentProviderUnauthenticated({
|
|
90
|
+
paymentUrl,
|
|
91
|
+
axios,
|
|
92
|
+
logger,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Base class for unauthenticated operations
|
|
97
|
+
export class TurboArNSPaymentProviderUnauthenticated {
|
|
48
98
|
paymentUrl;
|
|
49
99
|
axios;
|
|
50
100
|
logger;
|
|
51
|
-
|
|
52
|
-
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = createAxiosInstance(), logger = Logger.default, signer, }) {
|
|
101
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', axios = createAxiosInstance(), logger = Logger.default, }) {
|
|
53
102
|
this.paymentUrl = paymentUrl;
|
|
54
103
|
this.axios = axios;
|
|
55
104
|
this.logger = logger;
|
|
56
|
-
this.signer = signer;
|
|
57
105
|
}
|
|
58
106
|
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
59
107
|
const url = urlWithSearchParams({
|
|
@@ -89,10 +137,19 @@ export class TurboArNSPaymentProvider {
|
|
|
89
137
|
const { winc } = await this.getArNSPriceDetails(params);
|
|
90
138
|
return +winc;
|
|
91
139
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
140
|
+
}
|
|
141
|
+
// Class for authenticated operations, extending the base class
|
|
142
|
+
export class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated {
|
|
143
|
+
signer;
|
|
144
|
+
constructor({ signer, ...restConfig }) {
|
|
145
|
+
super(restConfig); // Pass unauthenticated config to base class+
|
|
146
|
+
if (!isTurboArNSSigner(signer)) {
|
|
147
|
+
throw new Error('Signer must be a TurboArNSSigner');
|
|
95
148
|
}
|
|
149
|
+
this.signer = signer;
|
|
150
|
+
}
|
|
151
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
152
|
+
// Signer check is implicitly handled by requiring it in the constructor
|
|
96
153
|
const url = urlWithSearchParams({
|
|
97
154
|
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
98
155
|
params: {
|
|
@@ -127,3 +184,17 @@ export class TurboArNSPaymentProvider {
|
|
|
127
184
|
};
|
|
128
185
|
}
|
|
129
186
|
}
|
|
187
|
+
function isWanderArweaveBrowserSigner(signer) {
|
|
188
|
+
return (typeof signer === 'object' &&
|
|
189
|
+
signer !== null &&
|
|
190
|
+
'signMessage' in signer &&
|
|
191
|
+
'getActivePublicKey' in signer);
|
|
192
|
+
}
|
|
193
|
+
export function isTurboArNSSigner(signer) {
|
|
194
|
+
const isWanderWallet = isWanderArweaveBrowserSigner(signer);
|
|
195
|
+
const isSigner = signer instanceof EthereumSigner ||
|
|
196
|
+
signer instanceof InjectedEthereumSigner ||
|
|
197
|
+
signer instanceof ArweaveSigner ||
|
|
198
|
+
signer instanceof ArconnectSigner;
|
|
199
|
+
return isWanderWallet || isSigner;
|
|
200
|
+
}
|
package/lib/esm/version.js
CHANGED
package/lib/esm/web/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { ArweaveSigner, ArconnectSigner } from '@dha-team/arbundles';
|
|
16
|
+
export { ArweaveSigner, ArconnectSigner, InjectedEthereumSigner, EthereumSigner, } from '@dha-team/arbundles';
|
|
17
17
|
export * from '../types/index.js';
|
|
18
18
|
export * from '../common/index.js';
|
|
19
19
|
export * from '../constants.js';
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Arweave from 'arweave';
|
|
2
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';
|
|
3
3
|
import { AOProcess } from './contracts/ao-process.js';
|
|
4
|
-
import {
|
|
4
|
+
import { TurboArNSPaymentProviderAuthenticated, TurboArNSPaymentProviderUnauthenticated } from './turbo.js';
|
|
5
5
|
type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>;
|
|
6
6
|
type ARIOConfigWithSigner = WithSigner<OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>>;
|
|
7
7
|
export declare class ARIO {
|
|
@@ -27,7 +27,7 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
27
27
|
readonly process: AOProcess;
|
|
28
28
|
protected epochSettings: AoEpochSettings | undefined;
|
|
29
29
|
protected arweave: Arweave;
|
|
30
|
-
protected paymentProvider:
|
|
30
|
+
protected paymentProvider: TurboArNSPaymentProviderUnauthenticated;
|
|
31
31
|
constructor(config?: ARIOConfigNoSigner);
|
|
32
32
|
getInfo(): Promise<{
|
|
33
33
|
Name: string;
|
|
@@ -143,7 +143,7 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
143
143
|
export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
|
|
144
144
|
readonly process: AOProcess;
|
|
145
145
|
private signer;
|
|
146
|
-
protected paymentProvider:
|
|
146
|
+
protected paymentProvider: TurboArNSPaymentProviderAuthenticated | TurboArNSPaymentProviderUnauthenticated;
|
|
147
147
|
constructor({ signer, paymentUrl, ...config }: ARIOConfigWithSigner);
|
|
148
148
|
transfer({ target, qty, }: {
|
|
149
149
|
target: string;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
2
|
-
import { AoMessageResult, TransactionId, TurboArNSSigner
|
|
2
|
+
import { AoMessageResult, TransactionId, TurboArNSSigner } from '../types/common.js';
|
|
3
3
|
import { AoTokenCostParams } from '../types/io.js';
|
|
4
4
|
import { mARIOToken } from '../types/token.js';
|
|
5
5
|
import { ILogger } from './logger.js';
|
|
6
|
-
export interface
|
|
6
|
+
export interface TurboUnauthenticatedConfig {
|
|
7
7
|
paymentUrl?: string;
|
|
8
8
|
logger?: ILogger;
|
|
9
9
|
axios?: AxiosInstance;
|
|
10
|
-
|
|
10
|
+
}
|
|
11
|
+
export interface TurboAuthenticatedConfig extends TurboUnauthenticatedConfig {
|
|
12
|
+
signer: TurboArNSSigner;
|
|
11
13
|
}
|
|
12
14
|
export declare function signedRequestHeadersFromSigner({ signer, nonce, }: {
|
|
13
15
|
signer: TurboArNSSigner;
|
|
@@ -26,22 +28,35 @@ export interface ArNSPaymentProvider {
|
|
|
26
28
|
winc: string;
|
|
27
29
|
mARIO: mARIOToken;
|
|
28
30
|
}>;
|
|
31
|
+
}
|
|
32
|
+
export interface ArNSAuthenticatedPaymentProvider extends ArNSPaymentProvider {
|
|
29
33
|
initiateArNSPurchase(params: AoTokenCostParams & {
|
|
30
34
|
processId?: TransactionId;
|
|
31
|
-
}
|
|
35
|
+
}): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
36
|
+
}
|
|
37
|
+
export declare class TurboArNSPaymentFactory {
|
|
38
|
+
static init(): TurboArNSPaymentProviderUnauthenticated;
|
|
39
|
+
static init({ paymentUrl, axios, logger, }: TurboUnauthenticatedConfig & {
|
|
40
|
+
signer?: TurboArNSSigner;
|
|
41
|
+
}): TurboArNSPaymentProviderUnauthenticated;
|
|
42
|
+
static init({ signer, paymentUrl, axios, logger, }: TurboAuthenticatedConfig): TurboArNSPaymentProviderAuthenticated;
|
|
32
43
|
}
|
|
33
|
-
export declare class
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
constructor({ paymentUrl, axios, logger, signer, }: TurboConfig);
|
|
44
|
+
export declare class TurboArNSPaymentProviderUnauthenticated implements ArNSPaymentProvider {
|
|
45
|
+
protected readonly paymentUrl: string;
|
|
46
|
+
protected readonly axios: AxiosInstance;
|
|
47
|
+
protected readonly logger: ILogger;
|
|
48
|
+
constructor({ paymentUrl, axios, logger, }: TurboUnauthenticatedConfig);
|
|
39
49
|
getArNSPriceDetails({ intent, name, quantity, type, years, }: AoTokenCostParams): Promise<{
|
|
40
50
|
winc: string;
|
|
41
51
|
mARIO: mARIOToken;
|
|
42
52
|
}>;
|
|
43
53
|
getPrice(params: AoTokenCostParams): Promise<number>;
|
|
54
|
+
}
|
|
55
|
+
export declare class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated implements ArNSAuthenticatedPaymentProvider {
|
|
56
|
+
private readonly signer;
|
|
57
|
+
constructor({ signer, ...restConfig }: TurboAuthenticatedConfig);
|
|
44
58
|
initiateArNSPurchase({ intent, name, quantity, type, processId, years, }: AoTokenCostParams & {
|
|
45
59
|
processId?: TransactionId;
|
|
46
60
|
}): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
47
61
|
}
|
|
62
|
+
export declare function isTurboArNSSigner(signer: unknown): signer is TurboArNSSigner;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { Signer } from '@dha-team/arbundles';
|
|
17
|
+
import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, Signer } from '@dha-team/arbundles';
|
|
18
18
|
import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
|
|
19
19
|
import Arweave from 'arweave';
|
|
20
20
|
import { AoSigner } from './token.js';
|
|
@@ -30,7 +30,7 @@ export type OptionalArweave<T = NonNullable<unknown>> = {
|
|
|
30
30
|
export type OptionalPaymentUrl<T = NonNullable<unknown>> = {
|
|
31
31
|
paymentUrl?: string;
|
|
32
32
|
} & T;
|
|
33
|
-
export type TurboArNSSigner =
|
|
33
|
+
export type TurboArNSSigner = EthereumSigner | InjectedEthereumSigner | ArweaveSigner | ArconnectSigner | Window['arweaveWallet'];
|
|
34
34
|
export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
|
|
35
35
|
export type WithSigner<T = NonNullable<unknown>> = {
|
|
36
36
|
signer: ContractSigner;
|
package/lib/types/version.d.ts
CHANGED
package/lib/types/web/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { ArweaveSigner, ArconnectSigner } from '@dha-team/arbundles';
|
|
16
|
+
export { ArweaveSigner, ArconnectSigner, InjectedEthereumSigner, EthereumSigner, } from '@dha-team/arbundles';
|
|
17
17
|
export * from '../types/index.js';
|
|
18
18
|
export * from '../common/index.js';
|
|
19
19
|
export * from '../constants.js';
|