@stellar/typescript-wallet-sdk 1.9.0 → 1.10.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.
- package/CHANGELOG.MD +14 -0
- package/lib/bundle.js +5807 -1314
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +428 -7717
- package/lib/bundle_browser.js.map +1 -1
- package/lib/walletSdk/Auth/index.d.ts +2 -0
- package/lib/walletSdk/Exceptions/index.d.ts +6 -0
- package/lib/walletSdk/Types/recovery.d.ts +1 -0
- package/lib/walletSdk/Types/sep7.d.ts +1 -0
- package/package.json +1 -1
- package/src/walletSdk/Anchor/index.ts +1 -0
- package/src/walletSdk/Auth/index.ts +194 -7
- package/src/walletSdk/Exceptions/index.ts +16 -0
- package/src/walletSdk/Recovery/index.ts +1 -0
- package/src/walletSdk/Types/auth.ts +11 -5
- package/src/walletSdk/Types/recovery.ts +1 -0
- package/src/walletSdk/Types/sep7.ts +1 -0
- package/src/walletSdk/Uri/sep7Parser.ts +46 -6
- package/test/auth.test.ts +1032 -0
- package/test/customer.test.ts +2 -1
- package/test/docker/docker-compose.yml +2 -2
- package/test/e2e/browser.test.ts +0 -2
- package/test/integration/README.md +3 -8
- package/test/integration/anchorplatform.test.ts +2 -1
- package/test/sep38.test.ts +0 -2
- package/test/sep6.test.ts +9 -3
- package/test/sep7.test.ts +43 -1
- package/test/server.test.ts +19 -23
- package/test/wallet.test.ts +10 -11
- package/tsconfig.json +2 -1
package/test/customer.test.ts
CHANGED
|
@@ -16,7 +16,8 @@ describe("Customer", () => {
|
|
|
16
16
|
);
|
|
17
17
|
}, 10000);
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// skipped: the testanchor changed its SEP-12 API behavior
|
|
20
|
+
test.skip("Sep-12 methods work", async () => {
|
|
20
21
|
const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
|
|
21
22
|
|
|
22
23
|
const auth = await anchor.sep10();
|
|
@@ -53,7 +53,7 @@ services:
|
|
|
53
53
|
environment:
|
|
54
54
|
SIGNING_KEY: SDYHSG4V2JP5H66N2CXBFCOBTAUFWXGJVPKWY6OXSIPMYW743N62QX6U
|
|
55
55
|
JWK: '{"kty":"EC","crv":"P-256","alg":"ES256","x":"dzqvhrMYwbmv7kcZK6L1oOATMFXG9wLFlnKfHf3E7FM","y":"Vb_wmcX-Zq2Hg2LFoXCEVWMwdJ01q41pSnxC3psunUY","d":"ivOMB4Wscz8ShvhwWDRyd-JJVfSMsjsz1oU3sNc-XJo"}'
|
|
56
|
-
DOMAIN:
|
|
56
|
+
DOMAIN: localhost
|
|
57
57
|
AUTH_HOME_DOMAIN: test-domain
|
|
58
58
|
JWT_ISSUER: test
|
|
59
59
|
PORT: 8001
|
|
@@ -65,7 +65,7 @@ services:
|
|
|
65
65
|
environment:
|
|
66
66
|
SIGNING_KEY: SCAS7BUKVDL44A2BAP23RVAM6XXHB24YRCANQGDTP24HP7T6LPUFIGGU # Use a different key for the second web auth server
|
|
67
67
|
JWK: '{"kty":"EC","crv":"P-256","alg":"ES256","x":"dzqvhrMYwbmv7kcZK6L1oOATMFXG9wLFlnKfHf3E7FM","y":"Vb_wmcX-Zq2Hg2LFoXCEVWMwdJ01q41pSnxC3psunUY","d":"ivOMB4Wscz8ShvhwWDRyd-JJVfSMsjsz1oU3sNc-XJo"}'
|
|
68
|
-
DOMAIN:
|
|
68
|
+
DOMAIN: localhost
|
|
69
69
|
AUTH_HOME_DOMAIN: test-domain
|
|
70
70
|
JWT_ISSUER: test
|
|
71
71
|
PORT: 8003
|
package/test/e2e/browser.test.ts
CHANGED
|
@@ -28,11 +28,6 @@ against.
|
|
|
28
28
|
|
|
29
29
|
## To run tests locally:
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
1. Clone the java-stellar-anchor-sdk repo locally
|
|
36
|
-
2. Run the docker build command
|
|
37
|
-
3. Run the docker command
|
|
38
|
-
4. Run the anchorPlatform tests from this repo
|
|
31
|
+
```
|
|
32
|
+
yarn test:anchorplatform:ci
|
|
33
|
+
```
|
|
@@ -6,7 +6,7 @@ let wallet;
|
|
|
6
6
|
let stellar;
|
|
7
7
|
let anchor;
|
|
8
8
|
let accountKp;
|
|
9
|
-
const anchorUrl = "
|
|
9
|
+
const anchorUrl = "https://anchor-sep-server-dev.stellar.org/";
|
|
10
10
|
|
|
11
11
|
describe("Anchor Platform Integration Tests", () => {
|
|
12
12
|
beforeAll(async () => {
|
|
@@ -69,6 +69,7 @@ describe("Anchor Platform Integration Tests", () => {
|
|
|
69
69
|
params: {
|
|
70
70
|
asset_code: "USDC",
|
|
71
71
|
account: accountKp.publicKey,
|
|
72
|
+
type: "SEPA",
|
|
72
73
|
},
|
|
73
74
|
});
|
|
74
75
|
expect(dResp.id).toBeTruthy();
|
package/test/sep38.test.ts
CHANGED
|
@@ -29,7 +29,6 @@ describe("SEP-38", () => {
|
|
|
29
29
|
const resp = await sep38.prices({
|
|
30
30
|
sellAsset: "iso4217:USD",
|
|
31
31
|
sellAmount: "5",
|
|
32
|
-
sellDeliveryMethod: "ach_debit",
|
|
33
32
|
});
|
|
34
33
|
expect(resp.buy_assets[0].asset).toBeTruthy();
|
|
35
34
|
});
|
|
@@ -59,7 +58,6 @@ describe("SEP-38", () => {
|
|
|
59
58
|
"stellar:SRT:GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B",
|
|
60
59
|
sell_amount: "5",
|
|
61
60
|
context: "sep6",
|
|
62
|
-
sell_delivery_method: "ach_debit",
|
|
63
61
|
});
|
|
64
62
|
expect(postResp.id).toBeTruthy();
|
|
65
63
|
|
package/test/sep6.test.ts
CHANGED
|
@@ -17,6 +17,7 @@ describe("SEP-6", () => {
|
|
|
17
17
|
"https://friendbot.stellar.org/?addr=" + accountKp.publicKey,
|
|
18
18
|
);
|
|
19
19
|
}, 10000);
|
|
20
|
+
|
|
20
21
|
it("should get anchor info", async () => {
|
|
21
22
|
const resp = await sep6.info();
|
|
22
23
|
expect(resp.deposit).toBeTruthy();
|
|
@@ -26,7 +27,9 @@ describe("SEP-6", () => {
|
|
|
26
27
|
expect(refreshed.deposit).toBeTruthy();
|
|
27
28
|
expect(refreshed.withdraw).toBeTruthy();
|
|
28
29
|
});
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
// skipped: the testanchor changed its SEP-6 API behavior
|
|
32
|
+
it.skip("should deposit", async () => {
|
|
30
33
|
const auth = await anchor.sep10();
|
|
31
34
|
const authToken = await auth.authenticate({ accountKp });
|
|
32
35
|
|
|
@@ -65,6 +68,7 @@ describe("SEP-6", () => {
|
|
|
65
68
|
});
|
|
66
69
|
expect(resp.id).toBeTruthy();
|
|
67
70
|
});
|
|
71
|
+
|
|
68
72
|
it("should withdraw", async () => {
|
|
69
73
|
const auth = await anchor.sep10();
|
|
70
74
|
const authToken = await auth.authenticate({ accountKp });
|
|
@@ -94,7 +98,8 @@ describe("SEP-6", () => {
|
|
|
94
98
|
expect(resp.id).toBeTruthy();
|
|
95
99
|
});
|
|
96
100
|
|
|
97
|
-
|
|
101
|
+
// skipped: the testanchor changed its SEP-6 API behavior
|
|
102
|
+
it.skip("deposit-exchange should work", async () => {
|
|
98
103
|
const auth = await anchor.sep10();
|
|
99
104
|
const authToken = await auth.authenticate({ accountKp });
|
|
100
105
|
|
|
@@ -122,7 +127,8 @@ describe("SEP-6", () => {
|
|
|
122
127
|
expect(resp.id).toBeTruthy();
|
|
123
128
|
});
|
|
124
129
|
|
|
125
|
-
|
|
130
|
+
// skipped: the testanchor changed its SEP-6 API behavior
|
|
131
|
+
it.skip("withdraw-exchange should work", async () => {
|
|
126
132
|
const auth = await anchor.sep10();
|
|
127
133
|
const authToken = await auth.authenticate({ accountKp });
|
|
128
134
|
|
package/test/sep7.test.ts
CHANGED
|
@@ -11,7 +11,10 @@ import {
|
|
|
11
11
|
sep7ReplacementsFromString,
|
|
12
12
|
sep7ReplacementsToString,
|
|
13
13
|
} from "../src";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
Sep7OperationType,
|
|
16
|
+
URI_REPLACE_MAX_LENGTH,
|
|
17
|
+
} from "../src/walletSdk/Types";
|
|
15
18
|
import {
|
|
16
19
|
Sep7InvalidUriError,
|
|
17
20
|
Sep7LongMsgError,
|
|
@@ -798,6 +801,45 @@ describe("sep7Parser", () => {
|
|
|
798
801
|
);
|
|
799
802
|
});
|
|
800
803
|
|
|
804
|
+
it("sep7ReplacementsFromString() throws on replace string without hints (no ';' delimiter)", () => {
|
|
805
|
+
const str = "sourceAccount:X,operations[0].sourceAccount:Y";
|
|
806
|
+
expect(() => sep7ReplacementsFromString(str)).toThrow(Sep7InvalidUriError);
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it("sep7ReplacementsFromString() throws on single replacement without hints", () => {
|
|
810
|
+
const str = "sourceAccount:X";
|
|
811
|
+
expect(() => sep7ReplacementsFromString(str)).toThrow(Sep7InvalidUriError);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it("sep7ReplacementsFromString() throws on unbalanced identifiers", () => {
|
|
815
|
+
// Spec example: {X} on left but {Y} on right should be rejected
|
|
816
|
+
const str = "sourceAccount:X;Y:The account";
|
|
817
|
+
expect(() => sep7ReplacementsFromString(str)).toThrow(Sep7InvalidUriError);
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it("sep7ReplacementsFromString() throws when replace string exceeds URI_REPLACE_MAX_LENGTH", () => {
|
|
821
|
+
const longPath = "a".repeat(URI_REPLACE_MAX_LENGTH);
|
|
822
|
+
const str = `${longPath}:X;X:hint`;
|
|
823
|
+
expect(str.length).toBeGreaterThan(URI_REPLACE_MAX_LENGTH);
|
|
824
|
+
expect(() => sep7ReplacementsFromString(str)).toThrow(Sep7InvalidUriError);
|
|
825
|
+
expect(() => sep7ReplacementsFromString(str)).toThrow(
|
|
826
|
+
"the 'replace' parameter exceeds the maximum allowed length",
|
|
827
|
+
);
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
it("sep7ReplacementsFromString() returns empty array for undefined/empty input", () => {
|
|
831
|
+
expect(sep7ReplacementsFromString(undefined)).toEqual([]);
|
|
832
|
+
expect(sep7ReplacementsFromString("")).toEqual([]);
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
it("Sep7Tx.getReplacements() throws on replace param missing hints", () => {
|
|
836
|
+
const uri = new Sep7Tx(
|
|
837
|
+
`web+stellar:tx?xdr=test&replace=${encodeURIComponent("sourceAccount:X")}`,
|
|
838
|
+
);
|
|
839
|
+
|
|
840
|
+
expect(() => uri.getReplacements()).toThrow(Sep7InvalidUriError);
|
|
841
|
+
});
|
|
842
|
+
|
|
801
843
|
it("sep7ReplacementsToString outputs the right string", () => {
|
|
802
844
|
const expected =
|
|
803
845
|
"sourceAccount:X,operations[0].sourceAccount:Y,operations[1].destination:Y;X:account from where you want to pay fees,Y:account that needs the trustline and which will receive the new tokens";
|
package/test/server.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import axios from "axios";
|
|
1
2
|
import { TransactionBuilder } from "@stellar/stellar-sdk";
|
|
2
3
|
import { Wallet, Server } from "../src";
|
|
3
4
|
|
|
@@ -5,6 +6,7 @@ let wallet;
|
|
|
5
6
|
let account;
|
|
6
7
|
let accountKp;
|
|
7
8
|
const networkPassphrase = "Test SDF Network ; September 2015";
|
|
9
|
+
const anchorDomain = "testanchor.stellar.org";
|
|
8
10
|
describe("SEP-10 helpers", () => {
|
|
9
11
|
beforeEach(() => {
|
|
10
12
|
wallet = Wallet.TestNet();
|
|
@@ -13,29 +15,23 @@ describe("SEP-10 helpers", () => {
|
|
|
13
15
|
});
|
|
14
16
|
|
|
15
17
|
it("should validate and sign challenge txn", async () => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
+
const resp = await axios.get(
|
|
19
|
+
`https://${anchorDomain}/auth?account=${accountKp.publicKey}&home_domain=${anchorDomain}`,
|
|
20
|
+
);
|
|
21
|
+
const validChallengeTx = resp.data.transaction;
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
expect(signedTxn.signatures.length).toBe(2);
|
|
32
|
-
expect(signedResp.networkPassphrase).toBe(networkPassphrase);
|
|
33
|
-
isValid = true;
|
|
34
|
-
} catch (e) {
|
|
35
|
-
isValid = false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
expect(isValid).toBeTruthy();
|
|
23
|
+
const signedResp = await Server.signChallengeTransaction({
|
|
24
|
+
accountKp,
|
|
25
|
+
challengeTx: validChallengeTx,
|
|
26
|
+
networkPassphrase,
|
|
27
|
+
anchorDomain,
|
|
28
|
+
});
|
|
29
|
+
const signedTxn = TransactionBuilder.fromXDR(
|
|
30
|
+
signedResp.transaction,
|
|
31
|
+
networkPassphrase,
|
|
32
|
+
);
|
|
33
|
+
expect(signedTxn.signatures.length).toBe(2);
|
|
34
|
+
expect(signedResp.networkPassphrase).toBe(networkPassphrase);
|
|
39
35
|
});
|
|
40
36
|
|
|
41
37
|
it("should invalidate bad challenge txn", async () => {
|
|
@@ -48,7 +44,7 @@ describe("SEP-10 helpers", () => {
|
|
|
48
44
|
accountKp,
|
|
49
45
|
challengeTx: invalidChallengeTx,
|
|
50
46
|
networkPassphrase,
|
|
51
|
-
anchorDomain
|
|
47
|
+
anchorDomain,
|
|
52
48
|
});
|
|
53
49
|
isValid = true;
|
|
54
50
|
} catch (e) {
|
package/test/wallet.test.ts
CHANGED
|
@@ -91,12 +91,12 @@ describe("Anchor", () => {
|
|
|
91
91
|
it("should give TOML info", async () => {
|
|
92
92
|
let resp = await anchor.sep1();
|
|
93
93
|
expect(resp.webAuthEndpoint).toBe("https://testanchor.stellar.org/auth");
|
|
94
|
-
expect(resp.currencies.length).toBe(
|
|
94
|
+
expect(resp.currencies.length).toBe(3);
|
|
95
95
|
|
|
96
96
|
// alias
|
|
97
97
|
resp = await anchor.getInfo();
|
|
98
98
|
expect(resp.webAuthEndpoint).toBe("https://testanchor.stellar.org/auth");
|
|
99
|
-
expect(resp.currencies.length).toBe(
|
|
99
|
+
expect(resp.currencies.length).toBe(3);
|
|
100
100
|
});
|
|
101
101
|
it("should be able to authenticate", async () => {
|
|
102
102
|
let auth = await anchor.sep10();
|
|
@@ -339,15 +339,14 @@ describe("Anchor", () => {
|
|
|
339
339
|
expect(transactions.length === 2).toBeTruthy();
|
|
340
340
|
});
|
|
341
341
|
|
|
342
|
-
it("should
|
|
343
|
-
await
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}).rejects.toThrowError(ServerRequestFailedError);
|
|
342
|
+
it("should accept any paging id when fetching transactions", async () => {
|
|
343
|
+
const transactions = await anchor.sep24().getTransactionsForAsset({
|
|
344
|
+
authToken,
|
|
345
|
+
assetCode: "SRT",
|
|
346
|
+
lang: "en-US",
|
|
347
|
+
pagingId: "randomPagingId",
|
|
348
|
+
});
|
|
349
|
+
expect(transactions).toBeDefined();
|
|
351
350
|
});
|
|
352
351
|
|
|
353
352
|
describe("watchAllTransactions", () => {
|