@stellar/typescript-wallet-sdk 1.0.0-beta.0 → 1.0.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 (53) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/docs/WalletGuide.md +323 -0
  3. package/lib/bundle.js +28367 -3664
  4. package/lib/bundle.js.map +1 -1
  5. package/lib/index.d.ts +4 -4
  6. package/lib/walletSdk/Exceptions/index.d.ts +19 -0
  7. package/lib/walletSdk/Types/auth.d.ts +7 -6
  8. package/lib/walletSdk/Types/horizon.d.ts +8 -0
  9. package/lib/walletSdk/Types/index.d.ts +2 -4
  10. package/lib/walletSdk/Types/{interactive.d.ts → sep24.d.ts} +9 -6
  11. package/lib/walletSdk/Watcher/index.d.ts +17 -17
  12. package/lib/walletSdk/anchor/Sep24.d.ts +48 -0
  13. package/lib/walletSdk/anchor/index.d.ts +6 -54
  14. package/lib/walletSdk/auth/WalletSigner.d.ts +2 -2
  15. package/lib/walletSdk/auth/index.d.ts +3 -3
  16. package/lib/walletSdk/horizon/Account.d.ts +1 -2
  17. package/lib/walletSdk/horizon/Stellar.d.ts +6 -0
  18. package/lib/walletSdk/horizon/transaction/TransactionBuilder.d.ts +12 -0
  19. package/lib/walletSdk/index.d.ts +9 -8
  20. package/lib/walletSdk/interactive/index.d.ts +20 -9
  21. package/package.json +7 -1
  22. package/prettier.config.js +1 -0
  23. package/src/index.ts +12 -12
  24. package/src/walletSdk/Anchor/Sep24.ts +267 -0
  25. package/src/walletSdk/Anchor/index.ts +19 -213
  26. package/src/walletSdk/Auth/WalletSigner.ts +13 -11
  27. package/src/walletSdk/Auth/index.ts +42 -24
  28. package/src/walletSdk/Exceptions/index.ts +81 -29
  29. package/src/walletSdk/Horizon/Account.ts +4 -4
  30. package/src/walletSdk/Horizon/Stellar.ts +62 -1
  31. package/src/walletSdk/Horizon/index.ts +1 -1
  32. package/src/walletSdk/Horizon/transaction/TransactionBuilder.ts +65 -0
  33. package/src/walletSdk/Recovery/index.ts +1 -6
  34. package/src/walletSdk/Types/anchor.ts +14 -14
  35. package/src/walletSdk/Types/auth.ts +12 -11
  36. package/src/walletSdk/Types/horizon.ts +11 -1
  37. package/src/walletSdk/Types/index.ts +8 -9
  38. package/src/walletSdk/Types/{interactive.ts → sep24.ts} +15 -10
  39. package/src/walletSdk/Types/utils.ts +1 -1
  40. package/src/walletSdk/Types/watcher.ts +2 -2
  41. package/src/walletSdk/Utils/camelToSnakeCase.ts +11 -8
  42. package/src/walletSdk/Utils/index.ts +1 -1
  43. package/src/walletSdk/Watcher/index.ts +94 -97
  44. package/src/walletSdk/index.ts +40 -55
  45. package/test/account.test.ts +10 -3
  46. package/test/fixtures/TransactionsResponse.ts +144 -127
  47. package/test/stellar.test.ts +65 -0
  48. package/test/wallet.test.ts +155 -170
  49. package/tsconfig.json +3 -7
  50. package/webpack.config.js +2 -0
  51. package/lib/walletSdk/anchor/Types.d.ts +0 -75
  52. package/lib/walletSdk/util/sleep.d.ts +0 -1
  53. package/src/walletSdk/Interactive/index.ts +0 -126
@@ -1,14 +1,23 @@
1
- import StellarSdk, { Keypair } from "stellar-sdk";
1
+ import StellarSdk, { Keypair, Memo, MemoText } from "stellar-sdk";
2
2
  import http from "http";
3
3
  import sinon from "sinon";
4
+ import axios, { AxiosInstance } from "axios";
4
5
 
5
6
  import sdk from "../src";
6
- import { AssetNotSupportedError, ServerRequestFailedError } from "../src/walletSdk/Exceptions";
7
+ import {
8
+ AssetNotSupportedError,
9
+ ServerRequestFailedError,
10
+ } from "../src/walletSdk/Exceptions";
7
11
  import { Watcher } from "../src/walletSdk/Watcher";
8
- import { TransactionStatus } from "../src/walletSdk/Types";
12
+ import { TransactionStatus, AnchorTransaction } from "../src/walletSdk/Types";
9
13
 
10
14
  import { TransactionsResponse } from "../test/fixtures/TransactionsResponse";
11
- import { WalletSigner } from "../src/walletSdk/Auth/WalletSigner";
15
+ import {
16
+ WalletSigner,
17
+ DefaultSigner,
18
+ } from "../src/walletSdk/Auth/WalletSigner";
19
+ import { SigningKeypair } from "../src/walletSdk/Horizon/Account";
20
+ import { Sep24 } from "../src/walletSdk/Anchor/Sep24";
12
21
 
13
22
  const originalSetTimeout = global.setTimeout;
14
23
  function sleep(time: number) {
@@ -27,14 +36,22 @@ describe("Wallet", () => {
27
36
  let appConfig = new walletSdk.ApplicationConfiguration();
28
37
  let wal = new walletSdk.Wallet({
29
38
  stellarConfiguration: walletSdk.StellarConfiguration.TestNet(),
30
- applicationConfiguration: appConfig
39
+ applicationConfiguration: appConfig,
31
40
  });
32
-
33
- let client = wal.getClient();
34
-
35
- // custom client
36
- client = wal.getClient({
37
- httpAgent: new http.Agent({ keepAlive: false }),
41
+ });
42
+ it("should be able to customize a client", async () => {
43
+ const customClient: AxiosInstance = axios.create({
44
+ baseURL: "https://some-url.com/api",
45
+ timeout: 1000,
46
+ headers: { "X-Custom-Header": "foobar" },
47
+ });
48
+ let appConfig = new walletSdk.ApplicationConfiguration(
49
+ DefaultSigner,
50
+ customClient,
51
+ );
52
+ let wal = new walletSdk.Wallet({
53
+ stellarConfiguration: walletSdk.StellarConfiguration.TestNet(),
54
+ applicationConfiguration: appConfig,
38
55
  });
39
56
  });
40
57
  });
@@ -53,18 +70,18 @@ describe("Anchor", () => {
53
70
  beforeEach(() => {
54
71
  const Wal = walletSdk.Wallet.TestNet();
55
72
  anchor = Wal.anchor({ homeDomain: "testanchor.stellar.org" });
56
- accountKp = Keypair.fromSecret(
57
- "SDXC3OHSJZEQIXKEWFDNEZEQ7SW5DWBPW7RKUWI36ILY3QZZ6VER7TXV"
73
+ accountKp = SigningKeypair.fromSecret(
74
+ "SDXC3OHSJZEQIXKEWFDNEZEQ7SW5DWBPW7RKUWI36ILY3QZZ6VER7TXV",
58
75
  );
59
76
  });
60
77
  it("should give TOML info", async () => {
61
- const resp = await anchor.getInfo();
78
+ const resp = await anchor.sep1();
62
79
 
63
80
  expect(resp.webAuthEndpoint).toBe("https://testanchor.stellar.org/auth");
64
81
  expect(resp.currencies.length).toBe(2);
65
82
  });
66
83
  it("should be able to authenticate", async () => {
67
- const auth = await anchor.auth();
84
+ const auth = await anchor.sep10();
68
85
 
69
86
  authToken = await auth.authenticate({ accountKp });
70
87
  expect(authToken).toBeTruthy();
@@ -72,24 +89,28 @@ describe("Anchor", () => {
72
89
  });
73
90
 
74
91
  it("should be able to authenticate with client domain", async () => {
75
- const auth = await anchor.auth();
92
+ const auth = await anchor.sep10();
76
93
  let signedByClient = false;
77
94
  let signedByDomain = false;
78
95
 
79
96
  const walletSigner: WalletSigner = {
80
97
  signWithClientAccount: ({ transaction, accountKp }) => {
81
- transaction.sign(accountKp);
98
+ transaction.sign(accountKp.keypair);
82
99
  signedByClient = true;
83
100
  return transaction;
84
101
  },
85
- signWithDomainAccount: ({ transactionXDR, networkPassphrase, accountKp }) => {
102
+ signWithDomainAccount: async ({
103
+ transactionXDR,
104
+ networkPassphrase,
105
+ accountKp,
106
+ }) => {
86
107
  // dummy secret key for signing
87
108
  const clientDomainKp = Keypair.fromSecret(
88
- "SC7PKBRGRI5X4XP4QICBZ2NL67VUJJVKFKXDTGSPI3SQYZGC4NZWONIH"
109
+ "SC7PKBRGRI5X4XP4QICBZ2NL67VUJJVKFKXDTGSPI3SQYZGC4NZWONIH",
89
110
  );
90
111
  const transaction = StellarSdk.TransactionBuilder.fromXDR(
91
112
  transactionXDR,
92
- networkPassphrase
113
+ networkPassphrase,
93
114
  );
94
115
  transaction.sign(clientDomainKp);
95
116
  signedByDomain = true;
@@ -100,15 +121,15 @@ describe("Anchor", () => {
100
121
  // because using dummy sk and not real demo wallet sk, lets just check that signing is called
101
122
  const challengeResponse = await auth.challenge({
102
123
  accountKp,
103
- clientDomain: "demo-wallet-server.stellar.org"
124
+ clientDomain: "demo-wallet-server.stellar.org",
104
125
  });
105
- const txn = auth.sign({ accountKp, challengeResponse, walletSigner });
126
+ const txn = await auth.sign({ accountKp, challengeResponse, walletSigner });
106
127
  expect(txn).toBeTruthy();
107
128
  expect(signedByClient).toBe(true);
108
129
  expect(signedByDomain).toBe(true);
109
130
  });
110
131
  it("should get anchor services info", async () => {
111
- const serviceInfo = await anchor.getServicesInfo();
132
+ const serviceInfo = await anchor.sep24().getServicesInfo();
112
133
 
113
134
  expect(serviceInfo.deposit).toBeTruthy();
114
135
  expect(serviceInfo.withdraw).toBeTruthy();
@@ -116,11 +137,28 @@ describe("Anchor", () => {
116
137
 
117
138
  it("should give interactive deposit url", async () => {
118
139
  const assetCode = "SRT";
119
- const resp = await anchor.interactive().deposit({
120
- accountAddress: accountKp.publicKey(),
140
+ const resp = await anchor.sep24().deposit({
141
+ destinationAccount: accountKp.publicKey,
142
+ assetCode,
143
+ authToken,
144
+ lang: "en-US",
145
+ extraFields: {
146
+ wallet_name: "Test Wallet",
147
+ wallet_url: "https://stellar.org/",
148
+ },
149
+ });
150
+
151
+ expect(resp.url).toBeTruthy();
152
+ expect(resp.id).toBeTruthy();
153
+ });
154
+
155
+ it("should give interactive deposit url without giving account and giving memo", async () => {
156
+ const assetCode = "SRT";
157
+ const resp = await anchor.sep24().deposit({
121
158
  assetCode,
122
159
  authToken,
123
160
  lang: "en-US",
161
+ destinationMemo: new Memo(MemoText, "test-memo"),
124
162
  extraFields: {
125
163
  wallet_name: "Test Wallet",
126
164
  wallet_url: "https://stellar.org/",
@@ -133,8 +171,8 @@ describe("Anchor", () => {
133
171
 
134
172
  it("should give interactive withdraw url", async () => {
135
173
  const assetCode = "SRT";
136
- const resp = await anchor.interactive().withdraw({
137
- accountAddress: accountKp.publicKey(),
174
+ const resp = await anchor.sep24().withdraw({
175
+ withdrawalAccount: accountKp.publicKey,
138
176
  assetCode,
139
177
  authToken,
140
178
  lang: "en-US",
@@ -152,14 +190,14 @@ describe("Anchor", () => {
152
190
  const assetCode = "SRT";
153
191
 
154
192
  // creates new 'incomplete' deposit transaction
155
- const { id: transactionId } = await anchor.interactive().deposit({
156
- accountAddress: accountKp.publicKey(),
193
+ const { id: transactionId } = await anchor.sep24().deposit({
194
+ accountAddress: accountKp.publicKey,
157
195
  assetCode,
158
196
  authToken,
159
197
  });
160
198
 
161
199
  // fetches transaction that has just been created
162
- const transaction = await anchor.getTransactionBy({
200
+ const transaction = await anchor.sep24().getTransactionBy({
163
201
  authToken,
164
202
  id: transactionId,
165
203
  });
@@ -178,7 +216,7 @@ describe("Anchor", () => {
178
216
  it("should error fetching non-existing transaction by id", async () => {
179
217
  await expect(async () => {
180
218
  const nonExistingTransactionId = "da8575e9-edc6-4f99-98cf-2b302f203cc7";
181
- await anchor.getTransactionBy({
219
+ await anchor.sep24().getTransactionBy({
182
220
  authToken,
183
221
  id: nonExistingTransactionId,
184
222
  });
@@ -186,7 +224,7 @@ describe("Anchor", () => {
186
224
  });
187
225
 
188
226
  it("should fetch 5 existing transactions by token code", async () => {
189
- const transactions = await anchor.getTransactionsForAsset({
227
+ const transactions = await anchor.sep24().getTransactionsForAsset({
190
228
  authToken,
191
229
  assetCode: "SRT",
192
230
  limit: 5,
@@ -202,7 +240,7 @@ describe("Anchor", () => {
202
240
  });
203
241
 
204
242
  it("should fetch 3 existing deposit transactions by token code", async () => {
205
- const transactions = await anchor.getTransactionsForAsset({
243
+ const transactions = await anchor.sep24().getTransactionsForAsset({
206
244
  authToken,
207
245
  assetCode: "SRT",
208
246
  limit: 3,
@@ -218,7 +256,7 @@ describe("Anchor", () => {
218
256
  });
219
257
 
220
258
  it("should fetch 2 existing withdrawal transactions by token code", async () => {
221
- const transactions = await anchor.getTransactionsForAsset({
259
+ const transactions = await anchor.sep24().getTransactionsForAsset({
222
260
  authToken,
223
261
  assetCode: "SRT",
224
262
  limit: 2,
@@ -235,7 +273,7 @@ describe("Anchor", () => {
235
273
 
236
274
  it("should error fetching transactions with invalid pading id", async () => {
237
275
  await expect(async () => {
238
- await anchor.getTransactionsForAsset({
276
+ await anchor.sep24().getTransactionsForAsset({
239
277
  authToken,
240
278
  assetCode: "SRT",
241
279
  lang: "en-US",
@@ -244,64 +282,13 @@ describe("Anchor", () => {
244
282
  }).rejects.toThrowError(ServerRequestFailedError);
245
283
  });
246
284
 
247
- it("should fetch only finished transactions", async () => {
248
- // mock TOML response to include the "SRT" currency
249
- jest
250
- .spyOn(anchor, "getInfo")
251
- .mockResolvedValue({
252
- networkPassphrase: 'Test SDF Network ; September 2015',
253
- transferServerSep24: 'https://testanchor.stellar.org/sep24',
254
- webAuthEndpoint: 'https://testanchor.stellar.org/auth',
255
- accounts: [
256
- 'GCSGSR6KQQ5BP2FXVPWRL6SWPUSFWLVONLIBJZUKTVQB5FYJFVL6XOXE',
257
- 'GDRND2IUXVMHZ4XTB2RZ4AJ3AOLON3WTAOC23XEASB56NHDFW3ED57TW'
258
- ],
259
- documentation: {
260
- orgName: 'Stellar Development Foundation',
261
- orgUrl: 'https://stellar.org',
262
- orgGithub: 'stellar',
263
- },
264
- principals: [],
265
- currencies: [{ code: "SRT" }, { code: "USDC" }],
266
- validators: []
267
- });
268
-
269
- // mock transactions response so we have a few completed/refunded
270
- jest
271
- .spyOn(anchor, "getTransactionsForAsset")
272
- .mockResolvedValue(TransactionsResponse);
273
-
274
- const transactions = await anchor.getHistory({
275
- authToken,
276
- assetCode: "SRT",
277
- });
278
-
279
- expect(transactions.length).toBeGreaterThan(0);
280
-
281
- transactions.forEach(({ status }) => {
282
- expect([
283
- TransactionStatus.completed,
284
- TransactionStatus.refunded
285
- ].includes(status)).toBeTruthy();
286
- });
287
- });
288
-
289
- it("should error fetching history for unsupported asset", async () => {
290
- await expect(async () => {
291
- await anchor.getHistory({
292
- authToken,
293
- assetCode: "ABC",
294
- });
295
- }).rejects.toThrowError(AssetNotSupportedError);
296
- });
297
-
298
285
  describe("watchAllTransactions", () => {
299
286
  let clock: sinon.SinonFakeTimers;
300
287
  let watcher: Watcher;
301
288
 
302
289
  beforeEach(async () => {
303
290
  clock = sinon.useFakeTimers(0);
304
- watcher = anchor.watcher();
291
+ watcher = anchor.sep24().watcher();
305
292
  });
306
293
 
307
294
  afterEach(() => {
@@ -319,7 +306,7 @@ describe("Anchor", () => {
319
306
 
320
307
  // mock default transactions response
321
308
  jest
322
- .spyOn(anchor, "getTransactionsForAsset")
309
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
323
310
  .mockResolvedValue(TransactionsResponse);
324
311
 
325
312
  // start watching
@@ -357,7 +344,7 @@ describe("Anchor", () => {
357
344
 
358
345
  // mock default transactions response
359
346
  jest
360
- .spyOn(anchor, "getTransactionsForAsset")
347
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
361
348
  .mockResolvedValue(TransactionsResponse);
362
349
 
363
350
  // start watching
@@ -401,7 +388,7 @@ describe("Anchor", () => {
401
388
 
402
389
  // mock default transactions response
403
390
  jest
404
- .spyOn(anchor, "getTransactionsForAsset")
391
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
405
392
  .mockResolvedValue(TransactionsResponse);
406
393
 
407
394
  // start watching
@@ -436,7 +423,7 @@ describe("Anchor", () => {
436
423
 
437
424
  // update mock with new transaction status
438
425
  jest
439
- .spyOn(anchor, "getTransactionsForAsset")
426
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
440
427
  .mockResolvedValue(updatedTransactions);
441
428
 
442
429
  clock.next();
@@ -465,7 +452,7 @@ describe("Anchor", () => {
465
452
 
466
453
  // update mock with new transaction status
467
454
  jest
468
- .spyOn(anchor, "getTransactionsForAsset")
455
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
469
456
  .mockResolvedValue(updatedTransactions);
470
457
 
471
458
  clock.next();
@@ -489,7 +476,7 @@ describe("Anchor", () => {
489
476
 
490
477
  // update mock with new transaction status
491
478
  jest
492
- .spyOn(anchor, "getTransactionsForAsset")
479
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
493
480
  .mockResolvedValue(updatedTransactions);
494
481
 
495
482
  clock.next();
@@ -514,7 +501,7 @@ describe("Anchor", () => {
514
501
 
515
502
  // mock default transactions response
516
503
  jest
517
- .spyOn(anchor, "getTransactionsForAsset")
504
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
518
505
  .mockResolvedValue(TransactionsResponse);
519
506
 
520
507
  // start watching
@@ -549,7 +536,7 @@ describe("Anchor", () => {
549
536
 
550
537
  // update mock with new transaction status
551
538
  jest
552
- .spyOn(anchor, "getTransactionsForAsset")
539
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
553
540
  .mockResolvedValue(updatedTransactions);
554
541
 
555
542
  clock.next();
@@ -578,7 +565,7 @@ describe("Anchor", () => {
578
565
 
579
566
  // update mock with new transaction status
580
567
  jest
581
- .spyOn(anchor, "getTransactionsForAsset")
568
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
582
569
  .mockResolvedValue(updatedTransactions);
583
570
 
584
571
  clock.next();
@@ -605,7 +592,7 @@ describe("Anchor", () => {
605
592
 
606
593
  // update mock with new transaction status
607
594
  jest
608
- .spyOn(anchor, "getTransactionsForAsset")
595
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
609
596
  .mockResolvedValue(updatedTransactions);
610
597
 
611
598
  clock.next();
@@ -626,7 +613,9 @@ describe("Anchor", () => {
626
613
  });
627
614
 
628
615
  // mock an empty transactions array
629
- jest.spyOn(anchor, "getTransactionsForAsset").mockResolvedValue([]);
616
+ jest
617
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
618
+ .mockResolvedValue([]);
630
619
 
631
620
  // start watching
632
621
  const { stop } = watcher.watchAllTransactions({
@@ -648,10 +637,10 @@ describe("Anchor", () => {
648
637
  expect(onMessage.callCount).toBe(0);
649
638
  expect(onError.callCount).toBe(0);
650
639
 
651
- const completedTransaction = {
640
+ const completedTransaction: AnchorTransaction = {
652
641
  id: "uyt1576b-ac28-4c02-a521-ddbfd9ae7oiu",
653
642
  kind: "deposit",
654
- status: "completed",
643
+ status: TransactionStatus.completed,
655
644
  status_eta: null,
656
645
  amount_in: "150.45",
657
646
  amount_out: "149.45",
@@ -663,7 +652,6 @@ describe("Anchor", () => {
663
652
  external_transaction_id: null,
664
653
  more_info_url:
665
654
  "https://testanchor.stellar.org/sep24/transaction/more_info?id=uyt1576b-ac28-4c02-a521-ddbfd9ae7oiu",
666
- refunded: false,
667
655
  message: "deposit completed!",
668
656
  claimable_balance_id: null,
669
657
  to: "GCZSYKPDWAKPGR7GYFBOIQB3TH352X7ELZL27WSJET5PDVFORDMGYTB5",
@@ -674,7 +662,7 @@ describe("Anchor", () => {
674
662
 
675
663
  // add a new success message
676
664
  jest
677
- .spyOn(anchor, "getTransactionsForAsset")
665
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
678
666
  .mockResolvedValue([completedTransaction]);
679
667
 
680
668
  clock.next();
@@ -686,7 +674,7 @@ describe("Anchor", () => {
686
674
 
687
675
  // getting the same thing again should change nothing
688
676
  jest
689
- .spyOn(anchor, "getTransactionsForAsset")
677
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
690
678
  .mockResolvedValue([completedTransaction]);
691
679
 
692
680
  clock.next();
@@ -696,10 +684,10 @@ describe("Anchor", () => {
696
684
  expect(onMessage.callCount).toBe(1);
697
685
  expect(onError.callCount).toBe(0);
698
686
 
699
- const refundedTransaction = {
687
+ const refundedTransaction: AnchorTransaction = {
700
688
  id: "def5d166-5a5e-4d5c-ba5d-271c32cd8abc",
701
689
  kind: "withdrawal",
702
- status: "refunded",
690
+ status: TransactionStatus.refunded,
703
691
  status_eta: null,
704
692
  amount_in: "95.35",
705
693
  amount_in_asset:
@@ -716,7 +704,6 @@ describe("Anchor", () => {
716
704
  external_transaction_id: null,
717
705
  more_info_url:
718
706
  "https://testanchor.stellar.org/sep24/transaction/more_info?id=def5d166-5a5e-4d5c-ba5d-271c32cd8abc",
719
- refunded: true,
720
707
  refunds: {
721
708
  amount_refunded: "95.35",
722
709
  amount_fee: "5",
@@ -728,8 +715,7 @@ describe("Anchor", () => {
728
715
  fee: "5",
729
716
  },
730
717
  {
731
- id:
732
- "b9d0b2292c4e09e8eb22d036171491e87b8d2086bf8b265874c8d182cb9c9020",
718
+ id: "b9d0b2292c4e09e8eb22d036171491e87b8d2086bf8b265874c8d182cb9c9020",
733
719
  id_type: "stellar",
734
720
  amount: "55.35",
735
721
  fee: "0",
@@ -747,7 +733,7 @@ describe("Anchor", () => {
747
733
 
748
734
  // add a new success message
749
735
  jest
750
- .spyOn(anchor, "getTransactionsForAsset")
736
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
751
737
  .mockResolvedValue([completedTransaction, refundedTransaction]);
752
738
 
753
739
  clock.next();
@@ -759,7 +745,7 @@ describe("Anchor", () => {
759
745
 
760
746
  // getting the same thing again should change nothing
761
747
  jest
762
- .spyOn(anchor, "getTransactionsForAsset")
748
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
763
749
  .mockResolvedValue([completedTransaction, refundedTransaction]);
764
750
 
765
751
  clock.next();
@@ -769,10 +755,10 @@ describe("Anchor", () => {
769
755
  expect(onMessage.callCount).toBe(2);
770
756
  expect(onError.callCount).toBe(0);
771
757
 
772
- const expiredTransaction = {
758
+ const expiredTransaction: AnchorTransaction = {
773
759
  id: "hytcf7c4-927d-4b7a-8a1f-d7188ebddu8i",
774
760
  kind: "withdrawal",
775
- status: "expired",
761
+ status: TransactionStatus.expired,
776
762
  status_eta: null,
777
763
  amount_in: null,
778
764
  amount_out: null,
@@ -783,7 +769,6 @@ describe("Anchor", () => {
783
769
  external_transaction_id: null,
784
770
  more_info_url:
785
771
  "https://testanchor.stellar.org/sep24/transaction/more_info?id=hytcf7c4-927d-4b7a-8a1f-d7188ebddu8i",
786
- refunded: false,
787
772
  message: "transaction has expired",
788
773
  to: null,
789
774
  from: "GCZSYKPDWAKPGR7GYFBOIQB3TH352X7ELZL27WSJET5PDVFORDMGYTB5",
@@ -794,7 +779,7 @@ describe("Anchor", () => {
794
779
 
795
780
  // add a new success message
796
781
  jest
797
- .spyOn(anchor, "getTransactionsForAsset")
782
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
798
783
  .mockResolvedValue([
799
784
  completedTransaction,
800
785
  refundedTransaction,
@@ -810,7 +795,7 @@ describe("Anchor", () => {
810
795
 
811
796
  // getting the same thing again should change nothing
812
797
  jest
813
- .spyOn(anchor, "getTransactionsForAsset")
798
+ .spyOn(Sep24.prototype, "getTransactionsForAsset")
814
799
  .mockResolvedValue([
815
800
  completedTransaction,
816
801
  refundedTransaction,
@@ -842,7 +827,8 @@ describe("Anchor", () => {
842
827
 
843
828
  beforeEach(async () => {
844
829
  clock = sinon.useFakeTimers(0);
845
- watcher = anchor.watcher();
830
+ watcher = anchor.sep24().watcher();
831
+ jest.resetAllMocks();
846
832
  });
847
833
 
848
834
  afterEach(() => {
@@ -864,12 +850,12 @@ describe("Anchor", () => {
864
850
 
865
851
  const successfulTransaction = makeTransaction(
866
852
  0,
867
- TransactionStatus.completed
853
+ TransactionStatus.completed,
868
854
  );
869
855
 
870
856
  // queue up a success
871
857
  jest
872
- .spyOn(anchor, "getTransactionBy")
858
+ .spyOn(Sep24.prototype, "getTransactionBy")
873
859
  .mockResolvedValue(successfulTransaction);
874
860
 
875
861
  // start watching
@@ -901,12 +887,12 @@ describe("Anchor", () => {
901
887
 
902
888
  const refundedTransaction = makeTransaction(
903
889
  0,
904
- TransactionStatus.refunded
890
+ TransactionStatus.refunded,
905
891
  );
906
892
 
907
893
  // queue up a success
908
894
  jest
909
- .spyOn(anchor, "getTransactionBy")
895
+ .spyOn(Sep24.prototype, "getTransactionBy")
910
896
  .mockResolvedValue(refundedTransaction);
911
897
 
912
898
  // start watching
@@ -940,7 +926,7 @@ describe("Anchor", () => {
940
926
 
941
927
  // queue up a success
942
928
  jest
943
- .spyOn(anchor, "getTransactionBy")
929
+ .spyOn(Sep24.prototype, "getTransactionBy")
944
930
  .mockResolvedValue(expiredTransaction);
945
931
 
946
932
  // start watching
@@ -986,12 +972,12 @@ describe("Anchor", () => {
986
972
 
987
973
  const incompleteTransaction = makeTransaction(
988
974
  0,
989
- TransactionStatus.incomplete
975
+ TransactionStatus.incomplete,
990
976
  );
991
977
 
992
978
  // queue up an incomplete transaction response
993
979
  jest
994
- .spyOn(anchor, "getTransactionBy")
980
+ .spyOn(Sep24.prototype, "getTransactionBy")
995
981
  .mockResolvedValue(incompleteTransaction);
996
982
 
997
983
  // start watching
@@ -1020,12 +1006,12 @@ describe("Anchor", () => {
1020
1006
 
1021
1007
  const pendingTransaction = makeTransaction(
1022
1008
  0,
1023
- TransactionStatus.pending_user_transfer_start
1009
+ TransactionStatus.pending_user_transfer_start,
1024
1010
  );
1025
1011
 
1026
1012
  // queue up a pending transaction response
1027
1013
  jest
1028
- .spyOn(anchor, "getTransactionBy")
1014
+ .spyOn(Sep24.prototype, "getTransactionBy")
1029
1015
  .mockResolvedValue(pendingTransaction);
1030
1016
 
1031
1017
  // start watching
@@ -1071,7 +1057,7 @@ describe("Anchor", () => {
1071
1057
 
1072
1058
  // queue up an error transaction response
1073
1059
  jest
1074
- .spyOn(anchor, "getTransactionBy")
1060
+ .spyOn(Sep24.prototype, "getTransactionBy")
1075
1061
  .mockResolvedValue(errorTransaction);
1076
1062
 
1077
1063
  // start watching
@@ -1100,12 +1086,12 @@ describe("Anchor", () => {
1100
1086
 
1101
1087
  const noMarketTransaction = makeTransaction(
1102
1088
  0,
1103
- TransactionStatus.no_market
1089
+ TransactionStatus.no_market,
1104
1090
  );
1105
1091
 
1106
1092
  // queue up a "no market" transaction response
1107
1093
  jest
1108
- .spyOn(anchor, "getTransactionBy")
1094
+ .spyOn(Sep24.prototype, "getTransactionBy")
1109
1095
  .mockResolvedValue(noMarketTransaction);
1110
1096
 
1111
1097
  // start watching
@@ -1148,35 +1134,35 @@ describe("Anchor", () => {
1148
1134
 
1149
1135
  // queue up several pending status updates
1150
1136
  jest
1151
- .spyOn(anchor, "getTransactionBy")
1137
+ .spyOn(Sep24.prototype, "getTransactionBy")
1152
1138
  .mockResolvedValueOnce(makeTransaction(0, TransactionStatus.incomplete))
1153
1139
  .mockResolvedValueOnce(
1154
- makeTransaction(1, TransactionStatus.pending_user)
1140
+ makeTransaction(1, TransactionStatus.pending_user),
1155
1141
  )
1156
1142
  .mockResolvedValueOnce(
1157
- makeTransaction(2, TransactionStatus.pending_anchor)
1143
+ makeTransaction(2, TransactionStatus.pending_anchor),
1158
1144
  )
1159
1145
  .mockResolvedValueOnce(
1160
- makeTransaction(3, TransactionStatus.pending_external)
1146
+ makeTransaction(3, TransactionStatus.pending_external),
1161
1147
  )
1162
1148
  .mockResolvedValueOnce(
1163
- makeTransaction(4, TransactionStatus.pending_stellar)
1149
+ makeTransaction(4, TransactionStatus.pending_stellar),
1164
1150
  )
1165
1151
  .mockResolvedValueOnce(
1166
- makeTransaction(5, TransactionStatus.pending_trust)
1152
+ makeTransaction(5, TransactionStatus.pending_trust),
1167
1153
  )
1168
1154
  .mockResolvedValueOnce(
1169
- makeTransaction(6, TransactionStatus.pending_user_transfer_start)
1155
+ makeTransaction(6, TransactionStatus.pending_user_transfer_start),
1170
1156
  )
1171
1157
  .mockResolvedValueOnce(
1172
- makeTransaction(7, TransactionStatus.pending_user_transfer_complete)
1158
+ makeTransaction(7, TransactionStatus.pending_user_transfer_complete),
1173
1159
  )
1174
1160
  .mockResolvedValueOnce(makeTransaction(8, TransactionStatus.completed))
1175
1161
  .mockResolvedValueOnce(
1176
- makeTransaction(9, TransactionStatus.pending_anchor)
1162
+ makeTransaction(9, TransactionStatus.pending_anchor),
1177
1163
  )
1178
1164
  .mockResolvedValueOnce(
1179
- makeTransaction(10, TransactionStatus.pending_external)
1165
+ makeTransaction(10, TransactionStatus.pending_external),
1180
1166
  );
1181
1167
 
1182
1168
  // start watching
@@ -1260,22 +1246,22 @@ describe("Anchor", () => {
1260
1246
 
1261
1247
  // queue up several pending status updates
1262
1248
  jest
1263
- .spyOn(anchor, "getTransactionBy")
1249
+ .spyOn(Sep24.prototype, "getTransactionBy")
1264
1250
  .mockResolvedValueOnce(makeTransaction(0, TransactionStatus.incomplete))
1265
1251
  .mockResolvedValueOnce(
1266
- makeTransaction(1, TransactionStatus.pending_user)
1252
+ makeTransaction(1, TransactionStatus.pending_user),
1267
1253
  )
1268
1254
  .mockResolvedValueOnce(
1269
- makeTransaction(2, TransactionStatus.pending_anchor)
1255
+ makeTransaction(2, TransactionStatus.pending_anchor),
1270
1256
  )
1271
1257
  .mockResolvedValueOnce(
1272
- makeTransaction(3, TransactionStatus.pending_external)
1258
+ makeTransaction(3, TransactionStatus.pending_external),
1273
1259
  )
1274
1260
  .mockResolvedValueOnce(
1275
- makeTransaction(4, TransactionStatus.pending_stellar)
1261
+ makeTransaction(4, TransactionStatus.pending_stellar),
1276
1262
  )
1277
1263
  .mockResolvedValueOnce(
1278
- makeTransaction(5, TransactionStatus.pending_trust)
1264
+ makeTransaction(5, TransactionStatus.pending_trust),
1279
1265
  );
1280
1266
 
1281
1267
  // start watching
@@ -1342,16 +1328,16 @@ describe("Anchor", () => {
1342
1328
 
1343
1329
  // queue up transactions
1344
1330
  jest
1345
- .spyOn(anchor, "getTransactionBy")
1331
+ .spyOn(Sep24.prototype, "getTransactionBy")
1346
1332
  .mockResolvedValueOnce(
1347
- makeTransaction(0, TransactionStatus.pending_user_transfer_complete)
1333
+ makeTransaction(0, TransactionStatus.pending_user_transfer_complete),
1348
1334
  )
1349
1335
  .mockResolvedValueOnce(makeTransaction(1, TransactionStatus.completed))
1350
1336
  .mockResolvedValueOnce(
1351
- makeTransaction(2, TransactionStatus.pending_anchor)
1337
+ makeTransaction(2, TransactionStatus.pending_anchor),
1352
1338
  )
1353
1339
  .mockResolvedValueOnce(
1354
- makeTransaction(3, TransactionStatus.pending_external)
1340
+ makeTransaction(3, TransactionStatus.pending_external),
1355
1341
  );
1356
1342
 
1357
1343
  // start watching
@@ -1400,7 +1386,7 @@ describe("Anchor", () => {
1400
1386
  });
1401
1387
 
1402
1388
  test("One pending, one refunded, no more after that", async () => {
1403
- const onMessage = sinon.spy(() => {
1389
+ const onMessage = sinon.spy((e) => {
1404
1390
  expect(onMessage.callCount).toBeLessThanOrEqual(1);
1405
1391
  });
1406
1392
 
@@ -1414,16 +1400,16 @@ describe("Anchor", () => {
1414
1400
 
1415
1401
  // queue up transactions
1416
1402
  jest
1417
- .spyOn(anchor, "getTransactionBy")
1403
+ .spyOn(Sep24.prototype, "getTransactionBy")
1418
1404
  .mockResolvedValueOnce(
1419
- makeTransaction(0, TransactionStatus.pending_user_transfer_complete)
1405
+ makeTransaction(0, TransactionStatus.pending_user_transfer_complete),
1420
1406
  )
1421
1407
  .mockResolvedValueOnce(makeTransaction(1, TransactionStatus.refunded))
1422
1408
  .mockResolvedValueOnce(
1423
- makeTransaction(2, TransactionStatus.pending_anchor)
1409
+ makeTransaction(2, TransactionStatus.pending_anchor),
1424
1410
  )
1425
1411
  .mockResolvedValueOnce(
1426
- makeTransaction(3, TransactionStatus.pending_external)
1412
+ makeTransaction(3, TransactionStatus.pending_external),
1427
1413
  );
1428
1414
 
1429
1415
  // start watching
@@ -1487,16 +1473,16 @@ describe("Anchor", () => {
1487
1473
 
1488
1474
  // queue up transactions
1489
1475
  jest
1490
- .spyOn(anchor, "getTransactionBy")
1476
+ .spyOn(Sep24.prototype, "getTransactionBy")
1491
1477
  .mockResolvedValueOnce(
1492
- makeTransaction(0, TransactionStatus.pending_user_transfer_start)
1478
+ makeTransaction(0, TransactionStatus.pending_user_transfer_start),
1493
1479
  )
1494
1480
  .mockResolvedValueOnce(makeTransaction(1, TransactionStatus.error))
1495
1481
  .mockResolvedValueOnce(
1496
- makeTransaction(2, TransactionStatus.pending_anchor)
1482
+ makeTransaction(2, TransactionStatus.pending_anchor),
1497
1483
  )
1498
1484
  .mockResolvedValueOnce(
1499
- makeTransaction(3, TransactionStatus.pending_external)
1485
+ makeTransaction(3, TransactionStatus.pending_external),
1500
1486
  );
1501
1487
 
1502
1488
  // start watching
@@ -1560,16 +1546,16 @@ describe("Anchor", () => {
1560
1546
 
1561
1547
  // queue up transactions
1562
1548
  jest
1563
- .spyOn(anchor, "getTransactionBy")
1549
+ .spyOn(Sep24.prototype, "getTransactionBy")
1564
1550
  .mockResolvedValueOnce(
1565
- makeTransaction(0, TransactionStatus.pending_user_transfer_start)
1551
+ makeTransaction(0, TransactionStatus.pending_user_transfer_start),
1566
1552
  )
1567
1553
  .mockResolvedValueOnce(makeTransaction(1, TransactionStatus.no_market))
1568
1554
  .mockResolvedValueOnce(
1569
- makeTransaction(2, TransactionStatus.pending_anchor)
1555
+ makeTransaction(2, TransactionStatus.pending_anchor),
1570
1556
  )
1571
1557
  .mockResolvedValueOnce(
1572
- makeTransaction(3, TransactionStatus.pending_external)
1558
+ makeTransaction(3, TransactionStatus.pending_external),
1573
1559
  );
1574
1560
 
1575
1561
  // start watching
@@ -1633,19 +1619,19 @@ describe("Anchor", () => {
1633
1619
 
1634
1620
  // queue up transactions
1635
1621
  jest
1636
- .spyOn(anchor, "getTransactionBy")
1622
+ .spyOn(Sep24.prototype, "getTransactionBy")
1637
1623
  .mockResolvedValueOnce(
1638
- makeTransaction(0, TransactionStatus.pending_user_transfer_start)
1624
+ makeTransaction(0, TransactionStatus.pending_user_transfer_start),
1639
1625
  )
1640
1626
  .mockResolvedValueOnce(
1641
- makeTransaction(1, TransactionStatus.pending_user_transfer_complete)
1627
+ makeTransaction(1, TransactionStatus.pending_user_transfer_complete),
1642
1628
  )
1643
1629
  .mockResolvedValueOnce(makeTransaction(2, TransactionStatus.error))
1644
1630
  .mockResolvedValueOnce(
1645
- makeTransaction(3, TransactionStatus.pending_anchor)
1631
+ makeTransaction(3, TransactionStatus.pending_anchor),
1646
1632
  )
1647
1633
  .mockResolvedValueOnce(
1648
- makeTransaction(4, TransactionStatus.pending_external)
1634
+ makeTransaction(4, TransactionStatus.pending_external),
1649
1635
  );
1650
1636
 
1651
1637
  // start watching
@@ -1706,13 +1692,12 @@ describe("Anchor", () => {
1706
1692
  describe("Http client", () => {
1707
1693
  it("should work with http", async () => {
1708
1694
  const accountKp = Keypair.fromSecret(
1709
- "SDXC3OHSJZEQIXKEWFDNEZEQ7SW5DWBPW7RKUWI36ILY3QZZ6VER7TXV"
1695
+ "SDXC3OHSJZEQIXKEWFDNEZEQ7SW5DWBPW7RKUWI36ILY3QZZ6VER7TXV",
1710
1696
  );
1711
- const wal = walletSdk.Wallet.TestNet();
1712
- const client = wal.getClient();
1697
+ const client = walletSdk.DefaultClient;
1713
1698
 
1714
1699
  const resp = await client.get(
1715
- `http://testanchor.stellar.org/auth?account=${accountKp.publicKey()}`
1700
+ `http://testanchor.stellar.org/auth?account=${accountKp.publicKey()}`,
1716
1701
  );
1717
1702
  expect(resp.data.transaction).toBeTruthy();
1718
1703
  });