@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.
@@ -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 = new turbo_js_1.TurboArNSPaymentProvider({
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 = new turbo_js_1.TurboArNSPaymentProvider({
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,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboArNSPaymentProvider = exports.signedRequestHeadersFromSigner = void 0;
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
- await signer.setPublicKey?.();
28
- const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
29
- let publicKey;
30
- switch (signer.signatureType) {
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
- publicKey = (0, base64_js_1.toB64Url)(signer.publicKey);
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
- publicKey = '0x' + signer.publicKey.toString('hex');
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: ${signer.signatureType}`);
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': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
47
- 'x-signature-type': signer.signatureType,
77
+ 'x-signature': signature,
78
+ 'x-signature-type': signatureType,
48
79
  };
49
80
  }
50
81
  exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
51
- class TurboArNSPaymentProvider {
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
- signer;
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
- async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
97
- if (!this.signer) {
98
- throw new Error('Signer required for initiating ArNS purchase with Turbo');
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.TurboArNSPaymentProvider = TurboArNSPaymentProvider;
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;
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.10.0-alpha.2';
20
+ exports.version = '3.10.0-alpha.3';
@@ -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);
@@ -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 { TurboArNSPaymentProvider } from './turbo.js';
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 = new TurboArNSPaymentProvider({
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 = new TurboArNSPaymentProvider({
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,
@@ -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
- await signer.setPublicKey?.();
25
- const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
26
- let publicKey;
27
- switch (signer.signatureType) {
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
- publicKey = toB64Url(signer.publicKey);
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
- publicKey = '0x' + signer.publicKey.toString('hex');
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: ${signer.signatureType}`);
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': toB64Url(Buffer.from(signature)),
44
- 'x-signature-type': signer.signatureType,
74
+ 'x-signature': signature,
75
+ 'x-signature-type': signatureType,
45
76
  };
46
77
  }
47
- export class TurboArNSPaymentProvider {
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
- signer;
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
- async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
93
- if (!this.signer) {
94
- throw new Error('Signer required for initiating ArNS purchase with Turbo');
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
+ }
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.10.0-alpha.2';
17
+ export const version = '3.10.0-alpha.3';
@@ -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';
@@ -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 { TurboArNSPaymentProvider } from './turbo.js';
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: TurboArNSPaymentProvider;
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: TurboArNSPaymentProvider;
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, WriteOptions } from '../types/common.js';
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 TurboConfig {
6
+ export interface TurboUnauthenticatedConfig {
7
7
  paymentUrl?: string;
8
8
  logger?: ILogger;
9
9
  axios?: AxiosInstance;
10
- signer?: TurboArNSSigner;
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
- }, options: WriteOptions): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
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 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);
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 = Signer;
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;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.10.0-alpha.1";
16
+ export declare const version = "3.10.0-alpha.2";
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.10.0-alpha.2",
3
+ "version": "3.10.0-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"