@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,71 @@
1
+ import { Wallet } from "../src";
2
+
3
+ let wallet;
4
+ let anchor;
5
+ let sep38;
6
+ let accountKp;
7
+
8
+ describe("SEP-38", () => {
9
+ beforeAll(() => {
10
+ wallet = Wallet.TestNet();
11
+ anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
12
+ sep38 = anchor.sep38();
13
+ accountKp = accountKp = wallet.stellar().account().createKeypair();
14
+ }, 10000);
15
+
16
+ it("should get Sep-38 anchor info", async () => {
17
+ const resp = await sep38.info();
18
+ expect(resp.assets[0]).toBeTruthy();
19
+
20
+ const refreshed = await sep38.info(true);
21
+ expect(refreshed.assets[0]).toBeTruthy();
22
+ });
23
+
24
+ it("should get Sep-38 prices", async () => {
25
+ const auth = await anchor.sep10();
26
+ const authToken = await auth.authenticate({ accountKp });
27
+ sep38 = anchor.sep38(authToken);
28
+
29
+ const resp = await sep38.prices({
30
+ sellAsset: "iso4217:USD",
31
+ sellAmount: "5",
32
+ sellDeliveryMethod: "ach_debit",
33
+ });
34
+ expect(resp.buy_assets[0].asset).toBeTruthy();
35
+ });
36
+
37
+ it("should get Sep-38 price", async () => {
38
+ const auth = await anchor.sep10();
39
+ const authToken = await auth.authenticate({ accountKp });
40
+ sep38 = anchor.sep38(authToken);
41
+
42
+ const resp = await sep38.price({
43
+ sellAsset: "iso4217:USD",
44
+ buyAsset:
45
+ "stellar:SRT:GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B",
46
+ sellAmount: "5",
47
+ context: "sep6",
48
+ });
49
+ expect(resp.price).toBeTruthy();
50
+ });
51
+
52
+ it("should request and get Sep-38 Quote", async () => {
53
+ const auth = await anchor.sep10();
54
+ const authToken = await auth.authenticate({ accountKp });
55
+ sep38 = anchor.sep38(authToken);
56
+ const postResp = await sep38.requestQuote({
57
+ sell_asset: "iso4217:USD",
58
+ buy_asset:
59
+ "stellar:SRT:GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B",
60
+ sell_amount: "5",
61
+ context: "sep6",
62
+ sell_delivery_method: "ach_debit",
63
+ });
64
+ expect(postResp.id).toBeTruthy();
65
+
66
+ const quoteId = postResp.id;
67
+ const getResp = await sep38.getQuote(quoteId);
68
+
69
+ expect(getResp.id).toBeTruthy();
70
+ });
71
+ });
@@ -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
  });
@@ -195,6 +214,26 @@ describe("Anchor", () => {
195
214
  expect(resp.id).toBeTruthy();
196
215
  });
197
216
 
217
+ it("should throw ServerRequestFailedError", async () => {
218
+ const assetCode = "SRT";
219
+ let didError = false;
220
+ const badAuthToken = new AuthToken();
221
+ try {
222
+ await anchor.sep24().withdraw({
223
+ withdrawalAccount: accountKp.publicKey,
224
+ assetCode,
225
+ authToken: badAuthToken,
226
+ });
227
+ } catch (e) {
228
+ didError = true;
229
+ expect(e.data.status).toBe(403);
230
+ expect(e.data.statusText).toBe("Forbidden");
231
+ expect(e.data.responseData.error).toBeTruthy();
232
+ expect(e.data.headers).toBeTruthy();
233
+ }
234
+ expect(didError).toBe(true);
235
+ });
236
+
198
237
  it("should fetch new transaction by id", async () => {
199
238
  const assetCode = "SRT";
200
239
 
@@ -213,12 +252,12 @@ describe("Anchor", () => {
213
252
  const { id, kind, status, amount_in, amount_out } = transaction;
214
253
 
215
254
  expect(transaction).toBeTruthy();
216
- expect(id === transactionId).toBeTruthy;
217
- expect(kind === "deposit").toBeTruthy;
218
- expect(status === "incomplete").toBeTruthy;
255
+ expect(id === transactionId).toBeTruthy();
256
+ expect(kind === "deposit").toBeTruthy();
257
+ expect(status === TransactionStatus.incomplete).toBeTruthy();
219
258
  // we expect fresh 'incomplete' transactions to not have amounts set yet
220
- expect(amount_in).toBeFalsy;
221
- expect(amount_out).toBeFalsy;
259
+ expect(amount_in).toBeFalsy();
260
+ expect(amount_out).toBeFalsy();
222
261
  });
223
262
 
224
263
  it("should error fetching non-existing transaction by id", async () => {
@@ -294,7 +333,7 @@ describe("Anchor", () => {
294
333
  let clock: sinon.SinonFakeTimers;
295
334
  let watcher: Watcher;
296
335
 
297
- beforeEach(async () => {
336
+ beforeEach(() => {
298
337
  clock = sinon.useFakeTimers(0);
299
338
  watcher = anchor.sep24().watcher();
300
339
  });
@@ -876,7 +915,7 @@ describe("Anchor", () => {
876
915
  let clock: sinon.SinonFakeTimers;
877
916
  let watcher: Watcher;
878
917
 
879
- beforeEach(async () => {
918
+ beforeEach(() => {
880
919
  clock = sinon.useFakeTimers(0);
881
920
  watcher = anchor.sep24().watcher();
882
921
  jest.resetAllMocks();
@@ -1171,7 +1210,7 @@ describe("Anchor", () => {
1171
1210
  });
1172
1211
 
1173
1212
  test("Several pending transactions, one completed, no more after that", async () => {
1174
- const onMessage = sinon.spy((m) => {
1213
+ const onMessage = sinon.spy(() => {
1175
1214
  expect(onMessage.callCount).toBeLessThanOrEqual(8);
1176
1215
  });
1177
1216
 
@@ -1444,7 +1483,7 @@ describe("Anchor", () => {
1444
1483
  });
1445
1484
 
1446
1485
  test("One pending, one refunded, no more after that", async () => {
1447
- const onMessage = sinon.spy((e) => {
1486
+ const onMessage = sinon.spy(() => {
1448
1487
  expect(onMessage.callCount).toBeLessThanOrEqual(1);
1449
1488
  });
1450
1489