@stellar/typescript-wallet-sdk 1.2.1 → 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 (92) 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 +6563 -2344
  13. package/lib/bundle.js.map +1 -1
  14. package/lib/bundle_browser.js +6005 -1833
  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 +21 -3
  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 +41 -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 +39 -0
  29. package/lib/walletSdk/Horizon/Transaction/SponsoringBuilder.d.ts +29 -1
  30. package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +81 -13
  31. package/lib/walletSdk/Horizon/index.d.ts +2 -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 +11 -1
  36. package/lib/walletSdk/Types/horizon.d.ts +6 -5
  37. package/lib/walletSdk/Types/index.d.ts +8 -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/toml.d.ts +2 -2
  44. package/lib/walletSdk/Watcher/getTransactions.d.ts +8 -0
  45. package/lib/walletSdk/Watcher/index.d.ts +41 -4
  46. package/lib/walletSdk/index.d.ts +41 -4
  47. package/package.json +17 -4
  48. package/src/index.ts +2 -0
  49. package/src/walletSdk/Anchor/Sep24.ts +93 -86
  50. package/src/walletSdk/Anchor/Sep38.ts +180 -0
  51. package/src/walletSdk/Anchor/Sep6.ts +291 -0
  52. package/src/walletSdk/Anchor/index.ts +138 -5
  53. package/src/walletSdk/Asset/index.ts +21 -4
  54. package/src/walletSdk/Auth/WalletSigner.ts +23 -5
  55. package/src/walletSdk/Auth/index.ts +24 -5
  56. package/src/walletSdk/Customer/index.ts +174 -0
  57. package/src/walletSdk/Exceptions/index.ts +100 -3
  58. package/src/walletSdk/Horizon/AccountService.ts +33 -21
  59. package/src/walletSdk/Horizon/Stellar.ts +89 -6
  60. package/src/walletSdk/Horizon/Transaction/CommonTransactionBuilder.ts +43 -4
  61. package/src/walletSdk/Horizon/Transaction/SponsoringBuilder.ts +30 -7
  62. package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +88 -15
  63. package/src/walletSdk/Horizon/index.ts +2 -1
  64. package/src/walletSdk/Recovery/AccountRecover.ts +255 -0
  65. package/src/walletSdk/Recovery/index.ts +314 -13
  66. package/src/walletSdk/Types/anchor.ts +23 -2
  67. package/src/walletSdk/Types/auth.ts +36 -2
  68. package/src/walletSdk/Types/horizon.ts +7 -5
  69. package/src/walletSdk/Types/index.ts +9 -3
  70. package/src/walletSdk/Types/recovery.ts +152 -0
  71. package/src/walletSdk/Types/sep12.ts +61 -0
  72. package/src/walletSdk/Types/sep38.ts +106 -0
  73. package/src/walletSdk/Types/sep6.ts +168 -0
  74. package/src/walletSdk/Types/watcher.ts +8 -2
  75. package/src/walletSdk/Utils/camelToSnakeCase.ts +1 -0
  76. package/src/walletSdk/Utils/toml.ts +2 -2
  77. package/src/walletSdk/Watcher/getTransactions.ts +65 -0
  78. package/src/walletSdk/Watcher/index.ts +70 -9
  79. package/src/walletSdk/index.ts +45 -8
  80. package/test/README.md +18 -0
  81. package/test/accountService.test.ts +21 -3
  82. package/test/customer.test.ts +82 -0
  83. package/test/docker/docker-compose.yml +97 -0
  84. package/test/integration.test.ts +166 -0
  85. package/test/recovery.test.ts +107 -0
  86. package/test/sep38.test.ts +71 -0
  87. package/test/sep6.test.ts +240 -0
  88. package/test/stellar.test.ts +57 -12
  89. package/test/transaction.test.ts +8 -10
  90. package/test/tsconfig.json +10 -0
  91. package/test/utils/index.ts +12 -0
  92. package/test/wallet.test.ts +43 -23
@@ -0,0 +1,240 @@
1
+ import { Wallet } from "../src";
2
+ import axios from "axios";
3
+
4
+ let wallet;
5
+ let anchor;
6
+ let sep6;
7
+ let accountKp;
8
+
9
+ describe("SEP-6", () => {
10
+ beforeAll(async () => {
11
+ wallet = Wallet.TestNet();
12
+ anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
13
+ sep6 = anchor.sep6();
14
+
15
+ accountKp = wallet.stellar().account().createKeypair();
16
+ await axios.get(
17
+ "https://friendbot.stellar.org/?addr=" + accountKp.publicKey,
18
+ );
19
+ }, 10000);
20
+ it("should get anchor info", async () => {
21
+ const resp = await sep6.info();
22
+ expect(resp.deposit).toBeTruthy();
23
+ expect(resp.withdraw).toBeTruthy();
24
+
25
+ const refreshed = await sep6.info(true);
26
+ expect(refreshed.deposit).toBeTruthy();
27
+ expect(refreshed.withdraw).toBeTruthy();
28
+ });
29
+ it("should deposit", async () => {
30
+ const auth = await anchor.sep10();
31
+ const authToken = await auth.authenticate({ accountKp });
32
+
33
+ const sep12 = await anchor.sep12(authToken);
34
+
35
+ // Make first call with missing KYC info
36
+ let resp = await sep6.deposit({
37
+ authToken,
38
+ params: {
39
+ asset_code: "SRT",
40
+ account: accountKp.publicKey,
41
+ type: "bank_account",
42
+ },
43
+ });
44
+ expect(resp.type).toBe("non_interactive_customer_info_needed");
45
+
46
+ // Add the missing KYC info
47
+ await sep12.add({
48
+ sep9Info: {
49
+ first_name: "john",
50
+ last_name: "smith",
51
+ email_address: "123@gmail.com",
52
+ bank_number: "12345",
53
+ bank_account_number: "12345",
54
+ },
55
+ });
56
+
57
+ // Make deposit call again with all info uploaded
58
+ resp = await sep6.deposit({
59
+ authToken,
60
+ params: {
61
+ asset_code: "SRT",
62
+ account: accountKp.publicKey,
63
+ type: "bank_account",
64
+ },
65
+ });
66
+ expect(resp.id).toBeTruthy();
67
+ });
68
+ it("should withdraw", async () => {
69
+ const auth = await anchor.sep10();
70
+ const authToken = await auth.authenticate({ accountKp });
71
+
72
+ const sep12 = await anchor.sep12(authToken);
73
+
74
+ await sep12.add({
75
+ sep9Info: {
76
+ first_name: "john",
77
+ last_name: "smith",
78
+ email_address: "123@gmail.com",
79
+ bank_number: "12345",
80
+ bank_account_number: "12345",
81
+ },
82
+ });
83
+
84
+ const resp = await sep6.withdraw({
85
+ authToken,
86
+ params: {
87
+ asset_code: "SRT",
88
+ account: accountKp.publicKey,
89
+ type: "bank_account",
90
+ dest: "123",
91
+ dest_extra: "12345",
92
+ },
93
+ });
94
+ expect(resp.id).toBeTruthy();
95
+ });
96
+
97
+ it("deposit-exchange should work", async () => {
98
+ const auth = await anchor.sep10();
99
+ const authToken = await auth.authenticate({ accountKp });
100
+
101
+ const sep12 = await anchor.sep12(authToken);
102
+ await sep12.add({
103
+ sep9Info: {
104
+ first_name: "john",
105
+ last_name: "smith",
106
+ email_address: "123@gmail.com",
107
+ bank_number: "12345",
108
+ bank_account_number: "12345",
109
+ },
110
+ });
111
+
112
+ const params = {
113
+ destination_asset:
114
+ "stellar:SRT:GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B",
115
+ source_asset: "iso4217:USD",
116
+ amount: "1",
117
+ account: accountKp.publicKey,
118
+ type: "bank_account",
119
+ };
120
+
121
+ const resp = await sep6.depositExchange({ authToken, params });
122
+ expect(resp.id).toBeTruthy();
123
+ });
124
+
125
+ it("withdraw-exchange should work", async () => {
126
+ const auth = await anchor.sep10();
127
+ const authToken = await auth.authenticate({ accountKp });
128
+
129
+ const sep12 = await anchor.sep12(authToken);
130
+ await sep12.add({
131
+ sep9Info: {
132
+ first_name: "john",
133
+ last_name: "smith",
134
+ email_address: "123@gmail.com",
135
+ bank_number: "12345",
136
+ bank_account_number: "12345",
137
+ },
138
+ });
139
+
140
+ const params = {
141
+ destination_asset: "iso4217:USD",
142
+ source_asset:
143
+ "stellar:SRT:GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B",
144
+ amount: "1",
145
+ dest: accountKp.publicKey,
146
+ dest_extra: "1234",
147
+ type: "bank_account",
148
+ };
149
+
150
+ const resp = await sep6.withdrawExchange({ authToken, params });
151
+ expect(resp.id).toBeTruthy();
152
+ });
153
+
154
+ it("should get transactions", async () => {
155
+ const auth = await anchor.sep10();
156
+ const authToken = await auth.authenticate({ accountKp });
157
+
158
+ let resp = await anchor.sep6().getTransactionsForAsset({
159
+ authToken,
160
+ assetCode: "SRT",
161
+ });
162
+ expect(resp[0].id).toBeTruthy();
163
+
164
+ const id = resp[0].id;
165
+
166
+ resp = await anchor.sep6().getTransactionBy({ authToken, id });
167
+
168
+ expect(resp.id).toEqual(id);
169
+ });
170
+
171
+ let txId;
172
+
173
+ it("should watch all transactions", async () => {
174
+ const auth = await anchor.sep10();
175
+ const authToken = await auth.authenticate({ accountKp });
176
+
177
+ const watcher = anchor.sep6().watcher();
178
+
179
+ let messageCount = 0;
180
+ let errorCount = 0;
181
+ const onMessage = (m) => {
182
+ expect(m.id).toBeTruthy();
183
+ messageCount += 1;
184
+ txId = m.id;
185
+ };
186
+ const onError = (e) => {
187
+ expect(e).toBeFalsy();
188
+ errorCount += 1;
189
+ };
190
+
191
+ const { stop } = watcher.watchAllTransactions({
192
+ authToken,
193
+ assetCode: "SRT",
194
+ onMessage,
195
+ onError,
196
+ timeout: 1,
197
+ });
198
+ await new Promise((resolve) => setTimeout(resolve, 2000));
199
+ stop();
200
+ expect(messageCount > 0).toBe(true);
201
+ expect(errorCount).toBe(0);
202
+ });
203
+
204
+ it("should watch one transaction", async () => {
205
+ const auth = await anchor.sep10();
206
+ const authToken = await auth.authenticate({ accountKp });
207
+
208
+ const watcher = anchor.sep6().watcher();
209
+
210
+ let messageCount = 0;
211
+ let errorCount = 0;
212
+ let successCount = 0;
213
+ const onMessage = (m) => {
214
+ expect(m.id).toBeTruthy();
215
+ messageCount += 1;
216
+ };
217
+ const onError = (e) => {
218
+ expect(e).toBeFalsy();
219
+ errorCount += 1;
220
+ };
221
+ const onSuccess = (s) => {
222
+ expect(s.id).toBeTruthy();
223
+ successCount += 1;
224
+ };
225
+ const { stop } = watcher.watchOneTransaction({
226
+ authToken,
227
+ assetCode: "SRT",
228
+ id: txId,
229
+ onSuccess,
230
+ onMessage,
231
+ onError,
232
+ timeout: 1,
233
+ });
234
+ await new Promise((resolve) => setTimeout(resolve, 2000));
235
+ stop();
236
+ expect(messageCount > 0).toBe(true);
237
+ expect(errorCount).toBe(0);
238
+ expect(successCount).toBe(0);
239
+ });
240
+ });
@@ -1,11 +1,4 @@
1
- import {
2
- Keypair,
3
- Memo,
4
- MemoText,
5
- Operation,
6
- Asset,
7
- Horizon,
8
- } from "stellar-sdk";
1
+ import { Keypair, Memo, MemoText, Horizon } from "stellar-sdk";
9
2
  import axios from "axios";
10
3
 
11
4
  import { Stellar, Wallet } from "../src";
@@ -17,6 +10,7 @@ import {
17
10
  IssuedAssetId,
18
11
  FiatAssetId,
19
12
  NativeAssetId,
13
+ Assets,
20
14
  } from "../src/walletSdk/Asset";
21
15
  import { TransactionStatus, WithdrawTransaction } from "../src/walletSdk/Types";
22
16
 
@@ -34,7 +28,7 @@ describe("Stellar", () => {
34
28
  try {
35
29
  await stellar.server.loadAccount(kp.publicKey);
36
30
  } catch (e) {
37
- await axios.get("https://friendbot.stellar.org/?addr=" + kp.publicKey);
31
+ await stellar.fundTestnetAccount(kp.publicKey);
38
32
  }
39
33
  }, 10000);
40
34
  it("should create and submit a transaction", async () => {
@@ -174,7 +168,7 @@ describe("Stellar", () => {
174
168
 
175
169
  let acc = await stellar.server.loadAccount(kp.publicKey);
176
170
  let balance = acc.balances.find(
177
- (b) => (b as Horizon.BalanceLineAsset).asset_code === "USDC",
171
+ (b) => (b as Horizon.HorizonApi.BalanceLineAsset).asset_code === "USDC",
178
172
  );
179
173
  expect(balance).toBeTruthy();
180
174
 
@@ -184,12 +178,12 @@ describe("Stellar", () => {
184
178
 
185
179
  acc = await stellar.server.loadAccount(kp.publicKey);
186
180
  balance = acc.balances.find(
187
- (b) => (b as Horizon.BalanceLineAsset).asset_code === "USDC",
181
+ (b) => (b as Horizon.HorizonApi.BalanceLineAsset).asset_code === "USDC",
188
182
  );
189
183
  expect(balance).toBeFalsy();
190
184
  }, 20000);
191
185
 
192
- it("should import and sign a transaction from xdr", async () => {
186
+ it("should import and sign a transaction from xdr", () => {
193
187
  const txnXdr =
194
188
  "AAAAAgAAAACHw+LvUYx5O3Ot8A1SUChfTVk4qxFFJZ5QZ/ktaEUKPwAAAGQACEjuAAABDAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAACHw+LvUYx5O3Ot8A1SUChfTVk4qxFFJZ5QZ/ktaEUKPwAAAAAAAAAAATEtAAAAAAAAAAAA";
195
189
 
@@ -244,6 +238,11 @@ describe("Stellar", () => {
244
238
  expect(txn).toBeTruthy();
245
239
  }
246
240
  }, 20000);
241
+
242
+ it("should return recommended fee", async () => {
243
+ const fee = await stellar.getRecommendedFee();
244
+ expect(fee).toBeTruthy();
245
+ });
247
246
  });
248
247
 
249
248
  let txnSourceKp;
@@ -385,6 +384,17 @@ describe("Asset", () => {
385
384
  const fiat = new FiatAssetId("USD");
386
385
  expect(fiat.sep38).toBe("iso4217:USD");
387
386
  });
387
+ it("should use premade constants", () => {
388
+ let issued = Assets.Main.USDC;
389
+ expect(issued.sep38).toBe(
390
+ "stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
391
+ );
392
+
393
+ issued = Assets.Test.USDC;
394
+ expect(issued.sep38).toBe(
395
+ "stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
396
+ );
397
+ });
388
398
  });
389
399
 
390
400
  describe("Account Modifying", () => {
@@ -462,4 +472,39 @@ describe("Account Modifying", () => {
462
472
  resp = await stellar.server.loadAccount(sourceKp.publicKey);
463
473
  expect(resp.signers[0].weight).toBe(0);
464
474
  }, 45000);
475
+
476
+ it("should merge account", async () => {
477
+ const wallet = Wallet.TestNet();
478
+ const stellar = wallet.stellar();
479
+ const account = wallet.stellar().account();
480
+
481
+ const accountKp = account.createKeypair();
482
+ const sourceKp = account.createKeypair();
483
+ await stellar.fundTestnetAccount(accountKp.publicKey);
484
+ await stellar.fundTestnetAccount(sourceKp.publicKey);
485
+
486
+ const txBuilder = await stellar.transaction({
487
+ sourceAddress: accountKp,
488
+ baseFee: 1000,
489
+ });
490
+ const mergeTxn = txBuilder
491
+ .accountMerge(accountKp.publicKey, sourceKp.publicKey)
492
+ .build();
493
+ mergeTxn.sign(accountKp.keypair);
494
+ mergeTxn.sign(sourceKp.keypair);
495
+ await stellar.submitTransaction(mergeTxn);
496
+
497
+ let found;
498
+ try {
499
+ const accResp = await stellar.server.loadAccount(sourceKp.publicKey);
500
+ if (accResp) {
501
+ found = true;
502
+ }
503
+ } catch (e) {
504
+ found = false;
505
+ }
506
+ expect(found).toBeFalsy();
507
+ const accResp = await stellar.server.loadAccount(accountKp.publicKey);
508
+ expect(parseInt(accResp.balances[0].balance)).toBeGreaterThan(19998);
509
+ }, 30000);
465
510
  });
@@ -19,10 +19,10 @@ describe("Muxed Transactions", () => {
19
19
  accountService = stellar.account();
20
20
 
21
21
  // Keys for accounts to issue and receive the new TSWT asset
22
- var issuingKeys = SigningKeypair.fromSecret(
22
+ const issuingKeys = SigningKeypair.fromSecret(
23
23
  "SAJMJSEC44DWU22TJF6RWYLRPPXLY4G3L5PVGC7D2QDUCPJIFCOISNQE",
24
24
  );
25
- var receivingKeys = SigningKeypair.fromSecret(
25
+ const receivingKeys = SigningKeypair.fromSecret(
26
26
  "SAOQQ76UQFEYN4QAAAOIO45KNZZNQKSXAUB5GXKI6YOFLEDCWPWTCDM3",
27
27
  );
28
28
 
@@ -41,7 +41,7 @@ describe("Muxed Transactions", () => {
41
41
  const tswtAssetBalance = receivingAccountInfo.balances.find(
42
42
  (balanceLine) => {
43
43
  const { asset_code, balance } =
44
- balanceLine as Horizon.BalanceLineAsset;
44
+ balanceLine as Horizon.HorizonApi.BalanceLineAsset;
45
45
  return asset_code === testingAsset.code && Number(balance) > 1000;
46
46
  },
47
47
  );
@@ -291,9 +291,7 @@ describe("Path Payment", () => {
291
291
  sendAmount: "5",
292
292
  })
293
293
  .build();
294
- sourceKp.sign(txn);
295
- const success = await stellar.submitTransaction(txn);
296
- expect(success).toBe(true);
294
+ expect(txn.operations[0].type).toBe("pathPaymentStrictSend");
297
295
  }, 15000);
298
296
 
299
297
  it("should use path payment receive", async () => {
@@ -308,16 +306,16 @@ describe("Path Payment", () => {
308
306
  destAmount: "5",
309
307
  })
310
308
  .build();
311
- sourceKp.sign(txn);
312
- const success = await stellar.submitTransaction(txn);
313
- expect(success).toBe(true);
309
+ expect(txn.operations[0].type).toBe("pathPaymentStrictReceive");
314
310
  }, 15000);
315
311
 
316
312
  it("should swap", async () => {
317
313
  const txBuilder = await stellar.transaction({
318
314
  sourceAddress: sourceKp,
319
315
  });
320
- const txn = txBuilder.swap(new NativeAssetId(), usdcAsset, "1").build();
316
+ const txn = txBuilder
317
+ .swap(new NativeAssetId(), new NativeAssetId(), ".1")
318
+ .build();
321
319
  sourceKp.sign(txn);
322
320
  const success = await stellar.submitTransaction(txn);
323
321
  expect(success).toBe(true);
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "esModuleInterop": true,
4
+ "baseUrl": "./",
5
+ "outDir": "lib",
6
+ "declaration": true,
7
+ "declarationDir": "lib"
8
+ },
9
+ "include": ["./"]
10
+ }
@@ -0,0 +1,12 @@
1
+ export const getRandomString = (length) => {
2
+ const charset =
3
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
4
+ let randomString = "";
5
+
6
+ for (let i = 0; i < length; i++) {
7
+ const randomIndex = Math.floor(Math.random() * charset.length);
8
+ randomString += charset[randomIndex];
9
+ }
10
+
11
+ return randomString;
12
+ };
@@ -11,7 +11,11 @@ import {
11
11
  import { DefaultClient } from "../src/walletSdk";
12
12
  import { ServerRequestFailedError } from "../src/walletSdk/Exceptions";
13
13
  import { Watcher } from "../src/walletSdk/Watcher";
14
- import { TransactionStatus, AnchorTransaction } from "../src/walletSdk/Types";
14
+ import {
15
+ TransactionStatus,
16
+ AnchorTransaction,
17
+ AuthToken,
18
+ } from "../src/walletSdk/Types";
15
19
  import {
16
20
  WalletSigner,
17
21
  DefaultSigner,
@@ -34,21 +38,21 @@ describe("Wallet", () => {
34
38
  Wallet.TestNet();
35
39
  Wallet.MainNet();
36
40
  });
37
- it("should be able return a client", async () => {
38
- let appConfig = new ApplicationConfiguration();
39
- let wal = new Wallet({
41
+ it("should be able customize config", () => {
42
+ const appConfig = new ApplicationConfiguration();
43
+ new Wallet({
40
44
  stellarConfiguration: StellarConfiguration.TestNet(),
41
45
  applicationConfiguration: appConfig,
42
46
  });
43
47
  });
44
- it("should be able to customize a client", async () => {
48
+ it("should be able to customize a client", () => {
45
49
  const customClient: AxiosInstance = axios.create({
46
50
  baseURL: "https://some-url.com/api",
47
51
  timeout: 1000,
48
52
  headers: { "X-Custom-Header": "foobar" },
49
53
  });
50
- let appConfig = new ApplicationConfiguration(DefaultSigner, customClient);
51
- let wal = new Wallet({
54
+ const appConfig = new ApplicationConfiguration(DefaultSigner, customClient);
55
+ new Wallet({
52
56
  stellarConfiguration: StellarConfiguration.TestNet(),
53
57
  applicationConfiguration: appConfig,
54
58
  });
@@ -64,7 +68,7 @@ describe("SEP-24 flow", () => {
64
68
 
65
69
  let anchor: Anchor;
66
70
  let accountKp: SigningKeypair;
67
- let authToken: string;
71
+ let authToken: AuthToken;
68
72
  const makeTransaction = (eta: number, txStatus: TransactionStatus) => ({
69
73
  kind: "deposit",
70
74
  id: "TEST",
@@ -81,17 +85,26 @@ describe("Anchor", () => {
81
85
  );
82
86
  });
83
87
  it("should give TOML info", async () => {
84
- const resp = await anchor.sep1();
88
+ let resp = await anchor.sep1();
89
+ expect(resp.webAuthEndpoint).toBe("https://testanchor.stellar.org/auth");
90
+ expect(resp.currencies.length).toBe(2);
85
91
 
92
+ // alias
93
+ resp = await anchor.getInfo();
86
94
  expect(resp.webAuthEndpoint).toBe("https://testanchor.stellar.org/auth");
87
95
  expect(resp.currencies.length).toBe(2);
88
96
  });
89
97
  it("should be able to authenticate", async () => {
90
- const auth = await anchor.sep10();
98
+ let auth = await anchor.sep10();
99
+ authToken = await auth.authenticate({ accountKp });
100
+ expect(authToken).toBeTruthy();
101
+ expect(authToken.account).toBeTruthy();
91
102
 
103
+ // alias
104
+ auth = await anchor.auth();
92
105
  authToken = await auth.authenticate({ accountKp });
93
106
  expect(authToken).toBeTruthy();
94
- expect(typeof authToken).toBe("string");
107
+ expect(authToken.account).toBeTruthy();
95
108
  });
96
109
 
97
110
  it("should be able to authenticate with client domain", async () => {
@@ -111,7 +124,9 @@ describe("Anchor", () => {
111
124
  signWithDomainAccount: async ({
112
125
  transactionXDR,
113
126
  networkPassphrase,
127
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
114
128
  accountKp,
129
+ // eslint-disable-next-line @typescript-eslint/require-await
115
130
  }) => {
116
131
  // dummy secret key for signing
117
132
  const clientDomainKp = Keypair.fromSecret(
@@ -138,8 +153,12 @@ describe("Anchor", () => {
138
153
  expect(signedByDomain).toBe(true);
139
154
  });
140
155
  it("should get anchor services info", async () => {
141
- const serviceInfo = await anchor.sep24().getServicesInfo();
156
+ let serviceInfo = await anchor.sep24().getServicesInfo();
157
+ expect(serviceInfo.deposit).toBeTruthy();
158
+ expect(serviceInfo.withdraw).toBeTruthy();
142
159
 
160
+ // alias
161
+ serviceInfo = await anchor.interactive().getServicesInfo();
143
162
  expect(serviceInfo.deposit).toBeTruthy();
144
163
  expect(serviceInfo.withdraw).toBeTruthy();
145
164
  });
@@ -198,11 +217,12 @@ describe("Anchor", () => {
198
217
  it("should throw ServerRequestFailedError", async () => {
199
218
  const assetCode = "SRT";
200
219
  let didError = false;
220
+ const badAuthToken = new AuthToken();
201
221
  try {
202
- const resp = await anchor.sep24().withdraw({
222
+ await anchor.sep24().withdraw({
203
223
  withdrawalAccount: accountKp.publicKey,
204
224
  assetCode,
205
- authToken: "bad auth token",
225
+ authToken: badAuthToken,
206
226
  });
207
227
  } catch (e) {
208
228
  didError = true;
@@ -232,12 +252,12 @@ describe("Anchor", () => {
232
252
  const { id, kind, status, amount_in, amount_out } = transaction;
233
253
 
234
254
  expect(transaction).toBeTruthy();
235
- expect(id === transactionId).toBeTruthy;
236
- expect(kind === "deposit").toBeTruthy;
237
- expect(status === "incomplete").toBeTruthy;
255
+ expect(id === transactionId).toBeTruthy();
256
+ expect(kind === "deposit").toBeTruthy();
257
+ expect(status === TransactionStatus.incomplete).toBeTruthy();
238
258
  // we expect fresh 'incomplete' transactions to not have amounts set yet
239
- expect(amount_in).toBeFalsy;
240
- expect(amount_out).toBeFalsy;
259
+ expect(amount_in).toBeFalsy();
260
+ expect(amount_out).toBeFalsy();
241
261
  });
242
262
 
243
263
  it("should error fetching non-existing transaction by id", async () => {
@@ -313,7 +333,7 @@ describe("Anchor", () => {
313
333
  let clock: sinon.SinonFakeTimers;
314
334
  let watcher: Watcher;
315
335
 
316
- beforeEach(async () => {
336
+ beforeEach(() => {
317
337
  clock = sinon.useFakeTimers(0);
318
338
  watcher = anchor.sep24().watcher();
319
339
  });
@@ -895,7 +915,7 @@ describe("Anchor", () => {
895
915
  let clock: sinon.SinonFakeTimers;
896
916
  let watcher: Watcher;
897
917
 
898
- beforeEach(async () => {
918
+ beforeEach(() => {
899
919
  clock = sinon.useFakeTimers(0);
900
920
  watcher = anchor.sep24().watcher();
901
921
  jest.resetAllMocks();
@@ -1190,7 +1210,7 @@ describe("Anchor", () => {
1190
1210
  });
1191
1211
 
1192
1212
  test("Several pending transactions, one completed, no more after that", async () => {
1193
- const onMessage = sinon.spy((m) => {
1213
+ const onMessage = sinon.spy(() => {
1194
1214
  expect(onMessage.callCount).toBeLessThanOrEqual(8);
1195
1215
  });
1196
1216
 
@@ -1463,7 +1483,7 @@ describe("Anchor", () => {
1463
1483
  });
1464
1484
 
1465
1485
  test("One pending, one refunded, no more after that", async () => {
1466
- const onMessage = sinon.spy((e) => {
1486
+ const onMessage = sinon.spy(() => {
1467
1487
  expect(onMessage.callCount).toBeLessThanOrEqual(1);
1468
1488
  });
1469
1489