@stellar/typescript-wallet-sdk 1.2.0 → 1.3.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.
Files changed (96) hide show
  1. package/.eslintrc.js +76 -0
  2. package/.github/workflows/integrationTest.yml +19 -0
  3. package/.github/workflows/runTests.yml +14 -0
  4. package/.husky/pre-commit +1 -0
  5. package/README.md +19 -12
  6. package/examples/sep24/.env.example +4 -0
  7. package/examples/sep24/README.md +17 -0
  8. package/examples/sep24/sep24.ts +69 -14
  9. package/examples/tsconfig.json +10 -0
  10. package/jest.config.js +1 -0
  11. package/jest.integration.config.js +9 -0
  12. package/lib/bundle.js +6929 -2377
  13. package/lib/bundle.js.map +1 -1
  14. package/lib/bundle_browser.js +6915 -2410
  15. package/lib/bundle_browser.js.map +1 -1
  16. package/lib/index.d.ts +1 -1
  17. package/lib/walletSdk/Anchor/Sep24.d.ts +65 -22
  18. package/lib/walletSdk/Anchor/Sep38.d.ts +56 -0
  19. package/lib/walletSdk/Anchor/Sep6.d.ts +127 -0
  20. package/lib/walletSdk/Anchor/index.d.ts +91 -1
  21. package/lib/walletSdk/Asset/index.d.ts +11 -1
  22. package/lib/walletSdk/Auth/WalletSigner.d.ts +41 -1
  23. package/lib/walletSdk/Auth/index.d.ts +21 -0
  24. package/lib/walletSdk/Customer/index.d.ts +70 -0
  25. package/lib/walletSdk/Exceptions/index.d.ts +45 -2
  26. package/lib/walletSdk/Horizon/AccountService.d.ts +30 -20
  27. package/lib/walletSdk/Horizon/Stellar.d.ts +79 -2
  28. package/lib/walletSdk/Horizon/Transaction/CommonTransactionBuilder.d.ts +57 -0
  29. package/lib/walletSdk/Horizon/Transaction/SponsoringBuilder.d.ts +38 -0
  30. package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +112 -11
  31. package/lib/walletSdk/Horizon/index.d.ts +3 -1
  32. package/lib/walletSdk/Recovery/AccountRecover.d.ts +58 -0
  33. package/lib/walletSdk/Recovery/index.d.ts +69 -7
  34. package/lib/walletSdk/Types/anchor.d.ts +17 -2
  35. package/lib/walletSdk/Types/auth.d.ts +14 -1
  36. package/lib/walletSdk/Types/horizon.d.ts +17 -6
  37. package/lib/walletSdk/Types/index.d.ts +15 -3
  38. package/lib/walletSdk/Types/recovery.d.ts +128 -0
  39. package/lib/walletSdk/Types/sep12.d.ts +57 -0
  40. package/lib/walletSdk/Types/sep38.d.ts +93 -0
  41. package/lib/walletSdk/Types/sep6.d.ts +160 -0
  42. package/lib/walletSdk/Types/watcher.d.ts +7 -2
  43. package/lib/walletSdk/Utils/extractAxiosErrorData.d.ts +2 -0
  44. package/lib/walletSdk/Utils/index.d.ts +1 -0
  45. package/lib/walletSdk/Utils/toml.d.ts +2 -2
  46. package/lib/walletSdk/Watcher/getTransactions.d.ts +8 -0
  47. package/lib/walletSdk/Watcher/index.d.ts +41 -4
  48. package/lib/walletSdk/index.d.ts +43 -5
  49. package/package.json +17 -4
  50. package/src/index.ts +2 -0
  51. package/src/walletSdk/Anchor/Sep24.ts +93 -86
  52. package/src/walletSdk/Anchor/Sep38.ts +180 -0
  53. package/src/walletSdk/Anchor/Sep6.ts +291 -0
  54. package/src/walletSdk/Anchor/index.ts +138 -5
  55. package/src/walletSdk/Asset/index.ts +21 -4
  56. package/src/walletSdk/Auth/WalletSigner.ts +23 -5
  57. package/src/walletSdk/Auth/index.ts +24 -5
  58. package/src/walletSdk/Customer/index.ts +174 -0
  59. package/src/walletSdk/Exceptions/index.ts +115 -4
  60. package/src/walletSdk/Horizon/AccountService.ts +33 -21
  61. package/src/walletSdk/Horizon/Stellar.ts +89 -5
  62. package/src/walletSdk/Horizon/Transaction/CommonTransactionBuilder.ts +43 -4
  63. package/src/walletSdk/Horizon/Transaction/SponsoringBuilder.ts +30 -7
  64. package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +88 -15
  65. package/src/walletSdk/Horizon/index.ts +2 -1
  66. package/src/walletSdk/Recovery/AccountRecover.ts +255 -0
  67. package/src/walletSdk/Recovery/index.ts +314 -13
  68. package/src/walletSdk/Types/anchor.ts +23 -2
  69. package/src/walletSdk/Types/auth.ts +36 -2
  70. package/src/walletSdk/Types/horizon.ts +7 -5
  71. package/src/walletSdk/Types/index.ts +17 -4
  72. package/src/walletSdk/Types/recovery.ts +152 -0
  73. package/src/walletSdk/Types/sep12.ts +61 -0
  74. package/src/walletSdk/Types/sep38.ts +106 -0
  75. package/src/walletSdk/Types/sep6.ts +168 -0
  76. package/src/walletSdk/Types/watcher.ts +8 -2
  77. package/src/walletSdk/Utils/camelToSnakeCase.ts +1 -0
  78. package/src/walletSdk/Utils/extractAxiosErrorData.ts +28 -0
  79. package/src/walletSdk/Utils/index.ts +1 -0
  80. package/src/walletSdk/Utils/toml.ts +2 -2
  81. package/src/walletSdk/Watcher/getTransactions.ts +65 -0
  82. package/src/walletSdk/Watcher/index.ts +70 -9
  83. package/src/walletSdk/index.ts +45 -8
  84. package/test/README.md +18 -0
  85. package/test/accountService.test.ts +21 -3
  86. package/test/customer.test.ts +82 -0
  87. package/test/docker/docker-compose.yml +97 -0
  88. package/test/integration.test.ts +166 -0
  89. package/test/recovery.test.ts +107 -0
  90. package/test/sep38.test.ts +71 -0
  91. package/test/sep6.test.ts +240 -0
  92. package/test/stellar.test.ts +57 -12
  93. package/test/transaction.test.ts +8 -10
  94. package/test/tsconfig.json +10 -0
  95. package/test/utils/index.ts +12 -0
  96. package/test/wallet.test.ts +60 -21
@@ -0,0 +1,291 @@
1
+ import { AxiosInstance } from "axios";
2
+ import queryString from "query-string";
3
+
4
+ import { Anchor } from "../Anchor";
5
+ import {
6
+ ServerRequestFailedError,
7
+ MissingTransactionIdError,
8
+ } from "../Exceptions";
9
+ import {
10
+ Sep6Info,
11
+ Sep6Params,
12
+ Sep6DepositParams,
13
+ Sep6WithdrawParams,
14
+ Sep6DepositResponse,
15
+ Sep6WithdrawResponse,
16
+ Sep6ExchangeParams,
17
+ Sep6Transaction,
18
+ GetTransactionParams,
19
+ GetTransactionsParams,
20
+ WatcherSepType,
21
+ AuthToken,
22
+ } from "../Types";
23
+ import {
24
+ Watcher,
25
+ _getTransactionsForAsset,
26
+ _getTransactionBy,
27
+ } from "../Watcher";
28
+ import { camelToSnakeCaseObject } from "../Utils";
29
+
30
+ /**
31
+ * Flow for creating deposits and withdrawals with an anchor using SEP-6.
32
+ * For an interactive flow use Sep24 instead.
33
+ * @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md}
34
+ * Do not create this object directly, use the Anchor class.
35
+ * @class
36
+ */
37
+ export class Sep6 {
38
+ private anchor: Anchor;
39
+ private httpClient: AxiosInstance;
40
+ private anchorInfo: Sep6Info;
41
+
42
+ /**
43
+ * Creates a new instance of the Sep6 class.
44
+ * @constructor
45
+ * @param {Sep6Params} params - Parameters to initialize the Sep6 instance.
46
+ */
47
+ constructor(params: Sep6Params) {
48
+ const { anchor, httpClient } = params;
49
+
50
+ this.anchor = anchor;
51
+ this.httpClient = httpClient;
52
+ }
53
+
54
+ /**
55
+ * Get SEP-6 anchor information.
56
+ * If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
57
+ * @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
58
+ * @returns {Promise<Sep6Info>} - SEP-6 information about the anchor.
59
+ */
60
+ async info(shouldRefresh?: boolean): Promise<Sep6Info> {
61
+ if (this.anchorInfo && !shouldRefresh) {
62
+ return this.anchorInfo;
63
+ }
64
+
65
+ const { transferServer } = await this.anchor.sep1();
66
+ try {
67
+ const resp = await this.httpClient.get(`${transferServer}/info`);
68
+ this.anchorInfo = resp.data;
69
+ return resp.data;
70
+ } catch (e) {
71
+ throw new ServerRequestFailedError(e);
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Deposits funds using the SEP-6 protocol. Next steps by
77
+ * the anchor are given in the response.
78
+ *
79
+ * @param {object} options - The options for the deposit.
80
+ * @param {AuthToken} options.authToken - The authentication token.
81
+ * @param {Sep6DepositParams} options.params - The parameters for the deposit request.
82
+ *
83
+ * @returns {Promise<Sep6DepositResponse>} Sep6 deposit response, containing next steps if needed
84
+ * to complete the deposit.
85
+ *
86
+ * @throws {Error} If an unexpected error occurs during the deposit operation.
87
+ */
88
+ async deposit({
89
+ authToken,
90
+ params,
91
+ }: {
92
+ authToken: AuthToken;
93
+ params: Sep6DepositParams;
94
+ }): Promise<Sep6DepositResponse> {
95
+ return this.flow({ type: "deposit", authToken, params });
96
+ }
97
+
98
+ /**
99
+ * Initiates a withdrawal using SEP-6.
100
+ *
101
+ * @param {object} options - The options for the withdrawal operation.
102
+ * @param {AuthToken} options.authToken - The authentication token.
103
+ * @param {Sep6WithdrawParams} options.params - The parameters for the withdrawal request.
104
+ *
105
+ * @returns {Promise<Sep6WithdrawResponse>} Sep6 withdraw response.
106
+ */
107
+ async withdraw({
108
+ authToken,
109
+ params,
110
+ }: {
111
+ authToken: AuthToken;
112
+ params: Sep6WithdrawParams;
113
+ }): Promise<Sep6WithdrawResponse> {
114
+ return this.flow({ type: "withdraw", authToken, params });
115
+ }
116
+
117
+ /**
118
+ * Similar to the SEP-6 deposit function, but for non-equivalent assets
119
+ * that require an exchange.
120
+ *
121
+ * @param {object} options - The options for the deposit exchange.
122
+ * @param {AuthToken} options.authToken - The authentication token.
123
+ * @param {Sep6ExchangeParams} options.params - The parameters for the deposit request.
124
+ *
125
+ * @returns {Promise<Sep6DepositResponse>} Sep6 deposit response, containing next steps if needed
126
+ * to complete the deposit.
127
+ *
128
+ * @throws {Error} If an unexpected error occurs during the deposit operation.
129
+ */
130
+ async depositExchange({
131
+ authToken,
132
+ params,
133
+ }: {
134
+ authToken: AuthToken;
135
+ params: Sep6ExchangeParams;
136
+ }): Promise<Sep6DepositResponse> {
137
+ return this.flow({ type: "deposit-exchange", authToken, params });
138
+ }
139
+
140
+ /**
141
+ * Similar to the SEP-6 withdraw function, but for non-equivalent assets
142
+ * that require an exchange.
143
+ *
144
+ * @param {object} options - The options for the deposit exchange.
145
+ * @param {AuthToken} options.authToken - The authentication token.
146
+ * @param {Sep6ExchangeParams} options.params - The parameters for the deposit request.
147
+ *
148
+ * @returns {Promise<Sep6WithdrawResponse>} Sep6 withdraw response, containing next steps if needed
149
+ * to complete the withdrawal.
150
+ *
151
+ * @throws {Error} If an unexpected error occurs during the deposit operation.
152
+ */
153
+ async withdrawExchange({
154
+ authToken,
155
+ params,
156
+ }: {
157
+ authToken: AuthToken;
158
+ params: Sep6ExchangeParams;
159
+ }): Promise<Sep6WithdrawResponse> {
160
+ return this.flow({ type: "withdraw-exchange", authToken, params });
161
+ }
162
+
163
+ private async flow({
164
+ type,
165
+ authToken,
166
+ params,
167
+ }: {
168
+ type: "deposit" | "withdraw" | "deposit-exchange" | "withdraw-exchange";
169
+ authToken: AuthToken;
170
+ params: Sep6DepositParams | Sep6WithdrawParams | Sep6ExchangeParams;
171
+ }) {
172
+ const { transferServer } = await this.anchor.sep1();
173
+
174
+ try {
175
+ const resp = await this.httpClient.get(
176
+ `${transferServer}/${type}?${queryString.stringify(params)}`,
177
+ {
178
+ headers: {
179
+ "Content-Type": "application/json",
180
+ Authorization: `Bearer ${authToken.token}`,
181
+ },
182
+ },
183
+ );
184
+ return resp.data;
185
+ } catch (e) {
186
+ if (e.response?.data?.type === "non_interactive_customer_info_needed") {
187
+ return e.response?.data;
188
+ } else if (e.response?.data?.type === "customer_info_status") {
189
+ return e.response?.data;
190
+ }
191
+ throw e;
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Creates a new instance of the Watcher class, to watch sep6 transactions.
197
+ * @returns {Watcher} A new Watcher instance.
198
+ */
199
+ watcher(): Watcher {
200
+ return new Watcher(this.anchor, WatcherSepType.SEP6);
201
+ }
202
+
203
+ /**
204
+ * Get account's sep6 transactions specified by asset and other params.
205
+ * @param {GetTransactionsParams} params - The Get Transactions params.
206
+ * @param {AuthToken} params.authToken - The authentication token for the account authenticated with the anchor.
207
+ * @param {string} params.assetCode - The target asset to query for.
208
+ * @param {string} [params.noOlderThan] - The response should contain transactions starting on or after this date & time.
209
+ * @param {string} [params.limit] - The response should contain at most 'limit' transactions.
210
+ * @param {string} [params.kind] - The kind of transaction that is desired. E.g.: 'deposit', 'withdrawal', 'depo
211
+ * -exchange', 'withdrawal-exchange'.
212
+ * @param {string} [params.pagingId] - The response should contain transactions starting prior to this ID (exclusive).
213
+ * @param {string} [params.lang] - The desired language (localization), it can also accept locale in the format 'en-US'.
214
+ * @returns {Promise<Sep6Transaction[]>} A list of transactions as requested by the client, sorted in time-descending order.
215
+ * @throws {InvalidTransactionsResponseError} Anchor returns an invalid response.
216
+ * @throws {ServerRequestFailedError} If server request fails.
217
+ */
218
+ async getTransactionsForAsset({
219
+ authToken,
220
+ assetCode,
221
+ noOlderThan,
222
+ limit,
223
+ kind,
224
+ pagingId,
225
+ lang = this.anchor.language,
226
+ }: GetTransactionsParams): Promise<Sep6Transaction[]> {
227
+ const toml = await this.anchor.sep1();
228
+ const transferServerEndpoint = toml.transferServer;
229
+
230
+ // Let's convert all params to snake case for the API call
231
+ const apiParams = camelToSnakeCaseObject({
232
+ assetCode,
233
+ account: authToken.account,
234
+ noOlderThan,
235
+ limit,
236
+ kind,
237
+ pagingId,
238
+ lang,
239
+ });
240
+
241
+ return _getTransactionsForAsset<Sep6Transaction>(
242
+ authToken,
243
+ apiParams,
244
+ transferServerEndpoint,
245
+ this.httpClient,
246
+ );
247
+ }
248
+
249
+ /**
250
+ * Get single sep6 transaction's current status and details from the anchor.
251
+ * @param {GetTransactionParams} params - The Get Transactions params.
252
+ * @param {AuthToken} params.authToken - The authentication token for the account authenticated with the anchor.
253
+ * @param {string} [params.id] - The transaction ID.
254
+ * @param {string} [params.stellarTransactionId] - The Stellar transaction ID.
255
+ * @param {string} [params.externalTransactionId] - The external transaction ID.
256
+ * @param {string} [params.lang] - The language setting.
257
+ * @returns {Promise<Sep6Transaction>} The transaction object.
258
+ * @throws {MissingTransactionIdError} If none of the ID parameters is provided.
259
+ * @throws {InvalidTransactionResponseError} If the anchor returns an invalid transaction response.
260
+ * @throws {ServerRequestFailedError} If the server request fails.
261
+ */
262
+ async getTransactionBy({
263
+ authToken,
264
+ id,
265
+ stellarTransactionId,
266
+ externalTransactionId,
267
+ lang = this.anchor.language,
268
+ }: GetTransactionParams): Promise<Sep6Transaction> {
269
+ if (!id && !stellarTransactionId && !externalTransactionId) {
270
+ throw new MissingTransactionIdError();
271
+ }
272
+
273
+ const toml = await this.anchor.sep1();
274
+ const transferServerEndpoint = toml.transferServer;
275
+
276
+ // Let's convert all params to snake case for the API call
277
+ const apiParams = camelToSnakeCaseObject({
278
+ id,
279
+ stellarTransactionId,
280
+ externalTransactionId,
281
+ lang,
282
+ });
283
+
284
+ return _getTransactionBy<Sep6Transaction>(
285
+ authToken,
286
+ apiParams,
287
+ transferServerEndpoint,
288
+ this.httpClient,
289
+ );
290
+ }
291
+ }
@@ -1,11 +1,17 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { StellarTomlResolver } from "stellar-sdk";
2
+ import { StellarToml } from "stellar-sdk";
3
3
 
4
4
  import { Config } from "walletSdk";
5
5
  import { Sep10 } from "../Auth";
6
- import { ServerRequestFailedError } from "../Exceptions";
6
+ import { Sep12 } from "../Customer";
7
+ import {
8
+ ServerRequestFailedError,
9
+ KYCServerNotFoundError,
10
+ } from "../Exceptions";
11
+ import { Sep6 } from "./Sep6";
7
12
  import { Sep24 } from "./Sep24";
8
- import { AnchorServiceInfo, TomlInfo } from "../Types";
13
+ import { Sep38 } from "./Sep38";
14
+ import { AnchorServiceInfo, TomlInfo, AuthToken } from "../Types";
9
15
  import { parseToml } from "../Utils";
10
16
 
11
17
  // Let's prevent exporting this constructor type as
@@ -17,7 +23,21 @@ type AnchorParams = {
17
23
  language: string;
18
24
  };
19
25
 
20
- // Do not create this object directly, use the Wallet class.
26
+ export type Transfer = Sep6;
27
+
28
+ export type Auth = Sep10;
29
+
30
+ export type Customer = Sep12;
31
+
32
+ export type Interactive = Sep24;
33
+
34
+ export type Quote = Sep38;
35
+
36
+ /**
37
+ * Build on/off ramps with anchors.
38
+ * Do not create this object directly, use the Wallet class.
39
+ * @class
40
+ */
21
41
  export class Anchor {
22
42
  public language: string;
23
43
 
@@ -26,6 +46,11 @@ export class Anchor {
26
46
  private httpClient: AxiosInstance;
27
47
  private toml: TomlInfo;
28
48
 
49
+ /**
50
+ * Creates a new Anchor instance.
51
+ * @constructor
52
+ * @param {AnchorParams} params - The parameters to initialize the Anchor.
53
+ */
29
54
  constructor(params: AnchorParams) {
30
55
  const { cfg, homeDomain, httpClient, language } = params;
31
56
 
@@ -35,6 +60,12 @@ export class Anchor {
35
60
  this.language = language;
36
61
  }
37
62
 
63
+ /**
64
+ * Get anchor information from a TOML file.
65
+ * If `shouldRefresh` is set to `true`, it fetches fresh TOML values; otherwise, it returns cached values if available.
66
+ * @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
67
+ * @returns {Promise<TomlInfo>} - TOML information about the anchor.
68
+ */
38
69
  async sep1(shouldRefresh?: boolean): Promise<TomlInfo> {
39
70
  // return cached TOML values by default
40
71
  if (this.toml && !shouldRefresh) {
@@ -42,12 +73,41 @@ export class Anchor {
42
73
  }
43
74
 
44
75
  // fetch fresh TOML values from Anchor domain
45
- const stellarToml = await StellarTomlResolver.resolve(this.homeDomain);
76
+ const stellarToml = await StellarToml.Resolver.resolve(this.homeDomain);
46
77
  const parsedToml = parseToml(stellarToml);
47
78
  this.toml = parsedToml;
48
79
  return parsedToml;
49
80
  }
50
81
 
82
+ /**
83
+ * Retrieves and returns TOML information using the `sep1` method.
84
+ * @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
85
+ * @returns {Promise<TomlInfo>} - TOML information.
86
+ */
87
+ async getInfo(shouldRefresh?: boolean): Promise<TomlInfo> {
88
+ return this.sep1(shouldRefresh);
89
+ }
90
+
91
+ /**
92
+ * Creates new transfer flow for given anchor. It can be used for withdrawal or deposit.
93
+ * @returns {Sep6} - flow service.
94
+ */
95
+ sep6(): Sep6 {
96
+ return new Sep6({ anchor: this, httpClient: this.httpClient });
97
+ }
98
+
99
+ /**
100
+ * Creates new transfer flow using the `sep6` method.
101
+ * @returns {Transfer} - transfer flow service.
102
+ */
103
+ transfer(): Transfer {
104
+ return this.sep6();
105
+ }
106
+
107
+ /**
108
+ * Create new auth object to authenticate account with the anchor using SEP-10.
109
+ * @returns {Promise<Sep10>} - The SEP-10 authentication manager.
110
+ */
51
111
  async sep10(): Promise<Sep10> {
52
112
  const tomlInfo = await this.sep1();
53
113
  return new Sep10({
@@ -58,10 +118,83 @@ export class Anchor {
58
118
  });
59
119
  }
60
120
 
121
+ /**
122
+ * Create new auth object to authenticate with using the `sep10` method.
123
+ * @returns {Promise<Auth>} - The SEP-10 authentication manager.
124
+ */
125
+ async auth(): Promise<Auth> {
126
+ return this.sep10();
127
+ }
128
+
129
+ /**
130
+ * Create new customer object to handle customer records with the anchor using SEP-12.
131
+ * @param {AuthToken} authToken - The authentication token.
132
+ * @returns {Promise<Sep12>} - A Sep12 customer instance.
133
+ * @throws {KYCServerNotFoundError} - If the KYC server information is not available.
134
+ */
135
+ async sep12(authToken: AuthToken): Promise<Sep12> {
136
+ const tomlInfo = await this.sep1();
137
+ const kycServer = tomlInfo?.kycServer;
138
+ if (!kycServer) {
139
+ throw new KYCServerNotFoundError();
140
+ }
141
+ return new Sep12(authToken, kycServer, this.httpClient);
142
+ }
143
+
144
+ /**
145
+ * Create new customer object to handle customer records using the `sep12` method.
146
+ * @param {AuthToken} authToken - The authentication token.
147
+ * @returns {Promise<Customer>} - A Customer instance.
148
+ */
149
+ async customer(authToken: AuthToken): Promise<Customer> {
150
+ return this.sep12(authToken);
151
+ }
152
+
153
+ /**
154
+ * Creates new interactive flow for given anchor. It can be used for withdrawal or deposit.
155
+ * @returns {Sep24} - interactive flow service.
156
+ */
61
157
  sep24(): Sep24 {
62
158
  return new Sep24({ anchor: this, httpClient: this.httpClient });
63
159
  }
64
160
 
161
+ /**
162
+ * Creates new interactive flow using the `sep24` method.
163
+ * @returns {Interactive} - interactive flow service
164
+ */
165
+ interactive(): Interactive {
166
+ return this.sep24();
167
+ }
168
+
169
+ /**
170
+ * Creates a new quote service. It can be used for getting price quotes from an anchor
171
+ * for exchanging assets.
172
+ * @param {AuthToken} [authToken] - The authentication token.
173
+ * @returns {Sep38} - quote service.
174
+ */
175
+ sep38(authToken?: AuthToken): Sep38 {
176
+ return new Sep38({
177
+ anchor: this,
178
+ httpClient: this.httpClient,
179
+ authToken,
180
+ });
181
+ }
182
+
183
+ /**
184
+ * Creates a new quote service using the `sep38` method.
185
+ * @param {AuthToken} [authToken] - The authentication token.
186
+ * @returns {Quote} - quote service.
187
+ */
188
+ quote(authToken?: AuthToken): Quote {
189
+ return this.sep38(authToken);
190
+ }
191
+
192
+ /**
193
+ * Get information about an Anchor.
194
+ * @param {string} [lang=this.language] - The language in which to retrieve information.
195
+ * @returns {Promise<AnchorServiceInfo>} An object containing information about the Anchor.
196
+ * @throws {ServerRequestFailedError} If the http request fails.
197
+ */
65
198
  async getServicesInfo(
66
199
  lang: string = this.language,
67
200
  ): Promise<AnchorServiceInfo> {
@@ -1,4 +1,4 @@
1
- import StellarSdk from "stellar-sdk";
1
+ import { Asset as StellarAsset } from "stellar-sdk";
2
2
 
3
3
  const STELLAR_SCHEME = "stellar";
4
4
 
@@ -18,11 +18,11 @@ export class StellarAssetId extends AssetId {
18
18
  issuer: string;
19
19
  scheme = STELLAR_SCHEME;
20
20
 
21
- toAsset() {
21
+ toAsset(): StellarAsset {
22
22
  if (this.id === "native") {
23
- return new StellarSdk.Asset("XLM");
23
+ return new StellarAsset("XLM");
24
24
  }
25
- return new StellarSdk.Asset(this.code, this.issuer);
25
+ return new StellarAsset(this.code, this.issuer);
26
26
  }
27
27
  }
28
28
 
@@ -39,6 +39,8 @@ export class IssuedAssetId extends StellarAssetId {
39
39
  }
40
40
  }
41
41
 
42
+ export type XLM = NativeAssetId;
43
+
42
44
  export class NativeAssetId extends StellarAssetId {
43
45
  id = "native";
44
46
  code = "XLM";
@@ -56,3 +58,18 @@ export class FiatAssetId extends AssetId {
56
58
  return this.sep38;
57
59
  }
58
60
  }
61
+
62
+ export const Assets = {
63
+ Main: {
64
+ USDC: new IssuedAssetId(
65
+ "USDC",
66
+ "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
67
+ ),
68
+ },
69
+ Test: {
70
+ USDC: new IssuedAssetId(
71
+ "USDC",
72
+ "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
73
+ ),
74
+ },
75
+ };
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  Transaction,
3
3
  TransactionBuilder as StellarTransactionBuilder,
4
- FeeBumpTransaction,
5
4
  } from "stellar-sdk";
6
5
  import { AxiosInstance } from "axios";
7
6
 
@@ -10,15 +9,31 @@ import {
10
9
  SignWithDomainAccountParams,
11
10
  HttpHeaders,
12
11
  } from "../Types";
13
- import { AccountKeypair } from "../Horizon/Account";
14
12
  import { DefaultClient } from "../";
15
13
 
14
+ /**
15
+ * A Wallet Signer for signing Stellar transactions.
16
+ */
16
17
  export interface WalletSigner {
18
+ /**
19
+ * Sign a transaction with a client keypair.
20
+ * @param {Transaction} params.transaction - The transaction to sign.
21
+ * @param {AccountKeypair} params.accountKp - The keypair to sign with.
22
+ * @returns {Transaction} The signed transaction.
23
+ */
17
24
  signWithClientAccount({
18
25
  transaction,
19
26
  accountKp,
20
27
  }: SignWithClientAccountParams): Transaction;
21
28
 
29
+ /**
30
+ * Sign a transaction using the domain account's keypair. This method is async in the
31
+ * case of signing with a different server.
32
+ * @param {XdrEncodedTransaction} params.transactionXDR - The XDR representation of the transaction to sign.
33
+ * @param {NetworkPassphrase} params.networkPassphrase - The network passphrase for the Stellar network.
34
+ * @param {AccountKeypair} params.accountKp - The keypair of the domain account.
35
+ * @returns {Promise<Transaction>} The signed transaction.
36
+ */
22
37
  signWithDomainAccount({
23
38
  transactionXDR,
24
39
  networkPassphrase,
@@ -26,11 +41,15 @@ export interface WalletSigner {
26
41
  }: SignWithDomainAccountParams): Promise<Transaction>;
27
42
  }
28
43
 
44
+ /**
45
+ * A Default signer used if no signer is given.
46
+ */
29
47
  export const DefaultSigner: WalletSigner = {
30
48
  signWithClientAccount: ({ transaction, accountKp }) => {
31
49
  transaction.sign(accountKp.keypair);
32
50
  return transaction;
33
51
  },
52
+ // eslint-disable-next-line @typescript-eslint/require-await
34
53
  signWithDomainAccount: async () => {
35
54
  throw new Error(
36
55
  "The DefaultSigner can't sign transactions with domain account",
@@ -39,8 +58,7 @@ export const DefaultSigner: WalletSigner = {
39
58
  };
40
59
 
41
60
  /**
42
- * Represents a Domain Signer used for signing Stellar transactions with a domain server.
43
- *
61
+ * A Domain Signer used for signing Stellar transactions with a domain server.
44
62
  * @class
45
63
  * @implements {WalletSigner}
46
64
  */
@@ -51,7 +69,6 @@ export class DomainSigner implements WalletSigner {
51
69
 
52
70
  /**
53
71
  * Create a new instance of the DomainSigner class.
54
- *
55
72
  * @constructor
56
73
  * @param {string} url - The URL of the domain server.
57
74
  * @param {HttpHeaders} headers - The HTTP headers for requests to the domain server.
@@ -74,6 +91,7 @@ export class DomainSigner implements WalletSigner {
74
91
  async signWithDomainAccount({
75
92
  transactionXDR,
76
93
  networkPassphrase,
94
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
77
95
  accountKp,
78
96
  }: SignWithDomainAccountParams): Promise<Transaction> {
79
97
  const response = await this.client.post(
@@ -30,13 +30,24 @@ type Sep10Params = {
30
30
  httpClient: AxiosInstance;
31
31
  };
32
32
 
33
- // Do not create this object directly, use the Wallet class.
33
+ /**
34
+ * Sep-10 used for authentication to an external server.
35
+ * @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md}
36
+ * Do not create this object directly, use the Anchor class.
37
+ * @class
38
+ */
34
39
  export class Sep10 {
35
40
  private cfg: Config;
36
41
  private webAuthEndpoint: string;
37
42
  private homeDomain: string;
38
43
  private httpClient: AxiosInstance;
39
44
 
45
+ /**
46
+ * Creates a new instance of the Sep10 class.
47
+ *
48
+ * @constructor
49
+ * @param {Sep10Params} params - Parameters to initialize the Sep10 instance.
50
+ */
40
51
  constructor(params: Sep10Params) {
41
52
  const { cfg, webAuthEndpoint, homeDomain, httpClient } = params;
42
53
 
@@ -46,6 +57,15 @@ export class Sep10 {
46
57
  this.httpClient = httpClient;
47
58
  }
48
59
 
60
+ /**
61
+ * Initiates the authentication process using SEP-10.
62
+ * @param {AuthenticateParams} params - The Authentication params.
63
+ * @param {AccountKeypair} params.accountKp - Keypair for the Stellar account being authenticated.
64
+ * @param {WalletSigner} [params.walletSigner] - Signer for signing transactions (defaults to the configuration default signer).
65
+ * @param {string} [params.memoId] - Memo ID to distinguish the account.
66
+ * @param {string} [params.clientDomain] - Domain hosting stellar.toml file containing `SIGNING_KEY`.
67
+ * @returns {Promise<AuthToken>} The authentication token.
68
+ */
49
69
  async authenticate({
50
70
  accountKp,
51
71
  walletSigner,
@@ -127,17 +147,16 @@ export class Sep10 {
127
147
  throw new MissingTokenError();
128
148
  }
129
149
 
130
- const authToken: AuthToken = resp.data.token;
131
- validateToken(authToken);
150
+ validateToken(resp.data.token);
132
151
 
133
- return authToken;
152
+ return AuthToken.from(resp.data.token);
134
153
  } catch (e) {
135
154
  throw new ServerRequestFailedError(e);
136
155
  }
137
156
  }
138
157
  }
139
158
 
140
- const validateToken = (token: AuthToken) => {
159
+ const validateToken = (token: string) => {
141
160
  const parsedToken = decode(token);
142
161
  if (!parsedToken) {
143
162
  throw new InvalidTokenError();