@stellar/typescript-wallet-sdk 1.4.0 → 1.5.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 +88 -0
- package/README.md +51 -0
- package/examples/sep24/sep24.ts +4 -9
- package/jest.e2e.config.js +9 -0
- package/lib/bundle.js +43625 -43200
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +45203 -42345
- package/lib/bundle_browser.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/walletSdk/Anchor/index.d.ts +1 -1
- package/lib/walletSdk/Auth/AuthHeaderSigner.d.ts +61 -0
- package/lib/walletSdk/Auth/index.d.ts +2 -2
- package/lib/walletSdk/Exceptions/index.d.ts +6 -0
- package/lib/walletSdk/Horizon/AccountService.d.ts +1 -1
- package/lib/walletSdk/Horizon/Stellar.d.ts +1 -1
- package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +1 -1
- package/lib/walletSdk/Recovery/AccountRecover.d.ts +1 -1
- package/lib/walletSdk/Recovery/index.d.ts +2 -2
- package/lib/walletSdk/Types/auth.d.ts +17 -0
- package/lib/walletSdk/Types/horizon.d.ts +1 -1
- package/lib/walletSdk/Types/index.d.ts +1 -1
- package/lib/walletSdk/Types/recovery.d.ts +2 -2
- package/package.json +6 -1
- package/src/index.ts +5 -0
- package/src/walletSdk/Anchor/index.ts +1 -1
- package/src/walletSdk/Auth/AuthHeaderSigner.ts +162 -0
- package/src/walletSdk/Auth/index.ts +48 -2
- package/src/walletSdk/Exceptions/index.ts +19 -0
- package/src/walletSdk/Horizon/AccountService.ts +1 -1
- package/src/walletSdk/Horizon/Stellar.ts +1 -1
- package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +1 -1
- package/src/walletSdk/Recovery/AccountRecover.ts +1 -1
- package/src/walletSdk/Recovery/index.ts +2 -2
- package/src/walletSdk/Types/auth.ts +19 -0
- package/src/walletSdk/Types/horizon.ts +1 -1
- package/src/walletSdk/Types/index.ts +1 -1
- package/src/walletSdk/Types/recovery.ts +2 -2
- package/test/e2e/README.md +11 -0
- package/test/e2e/browser.test.ts +52 -0
- package/test/integration/README.md +38 -0
- package/test/integration/anchorplatform.test.ts +9 -0
- package/test/server.test.ts +13 -0
- package/test/wallet.test.ts +85 -0
- package/webpack.config.js +4 -0
- package/test/README.md +0 -18
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RawAxiosRequestHeaders } from "axios";
|
|
2
2
|
import { Networks } from "@stellar/stellar-sdk";
|
|
3
|
-
import { ApplicationConfiguration, StellarConfiguration } from "
|
|
3
|
+
import { ApplicationConfiguration, StellarConfiguration } from "../";
|
|
4
4
|
import { RecoveryServerMap } from "./recovery";
|
|
5
5
|
|
|
6
6
|
// Export types from root walletSdk/index.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transaction } from "@stellar/stellar-sdk";
|
|
2
2
|
|
|
3
|
-
import { WalletSigner } from "
|
|
4
|
-
import { AccountKeypair, PublicKeypair } from "
|
|
3
|
+
import { WalletSigner } from "../Auth";
|
|
4
|
+
import { AccountKeypair, PublicKeypair } from "../Horizon";
|
|
5
5
|
import { AuthToken } from "./auth";
|
|
6
6
|
import { CommonBuilder } from "./horizon";
|
|
7
7
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# How it works
|
|
2
|
+
|
|
3
|
+
## browser.test.ts
|
|
4
|
+
|
|
5
|
+
This test uses playwright to load the browser bundle file into a browser
|
|
6
|
+
environment and run its code. If there is a bug in how its built,
|
|
7
|
+
window.WalletSDK will be undefined.
|
|
8
|
+
|
|
9
|
+
### To run
|
|
10
|
+
|
|
11
|
+
$ yarn build $ yarn test browser.test.ts
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { chromium, webkit } from "playwright";
|
|
2
|
+
|
|
3
|
+
describe("Test browser build", () => {
|
|
4
|
+
const browsers = [
|
|
5
|
+
{ name: "Chrome", instance: chromium },
|
|
6
|
+
{ name: "Safari", instance: webkit },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
for (const b of browsers) {
|
|
10
|
+
it(
|
|
11
|
+
"works on " + b.name,
|
|
12
|
+
async () => {
|
|
13
|
+
await (async () => {
|
|
14
|
+
const browser = await b.instance.launch();
|
|
15
|
+
const page = await browser.newPage();
|
|
16
|
+
|
|
17
|
+
await page.goto("https://stellar.org");
|
|
18
|
+
|
|
19
|
+
await page.addScriptTag({
|
|
20
|
+
path: "./lib/bundle_browser.js",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Use the Stellar SDK in the website's context
|
|
24
|
+
const result = await page.evaluate(() => {
|
|
25
|
+
let kp;
|
|
26
|
+
try {
|
|
27
|
+
const wal = (window as any).WalletSDK.Wallet.TestNet();
|
|
28
|
+
const account = wal.stellar().account();
|
|
29
|
+
|
|
30
|
+
kp = account.createKeypair();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return { success: false };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
publicKey: kp.publicKey,
|
|
37
|
+
secretKey: kp.secretKey,
|
|
38
|
+
success: true,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(result.publicKey).toBeTruthy();
|
|
43
|
+
expect(result.secretKey).toBeTruthy();
|
|
44
|
+
expect(result.success).toBeTruthy();
|
|
45
|
+
|
|
46
|
+
await browser.close();
|
|
47
|
+
})();
|
|
48
|
+
},
|
|
49
|
+
15000,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Recovery Integration Tests
|
|
2
|
+
|
|
3
|
+
## How it works
|
|
4
|
+
|
|
5
|
+
The recovery integration tests run different recovery scenarios against recovery
|
|
6
|
+
signer and webauth servers. 2 recovery signer and 2 webauth servers are started
|
|
7
|
+
in a docker-compose file (see test/docker/docker-compose.yml), to simulate a
|
|
8
|
+
wallet interacting with 2 separate recovery servers.
|
|
9
|
+
|
|
10
|
+
## To run tests locally:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
// start servers using docker
|
|
14
|
+
$ docker-compose -f @stellar/typescript-wallet-sdk/test/docker/docker-compose.yml up
|
|
15
|
+
|
|
16
|
+
// run tests
|
|
17
|
+
$ yarn test:recovery:ci
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
# AnchorPlatform Integration Tests
|
|
21
|
+
|
|
22
|
+
## How it works
|
|
23
|
+
|
|
24
|
+
This test works similar to the recovery integration tests. It spins up an
|
|
25
|
+
anchorplatform image from the (java anchor sdk
|
|
26
|
+
repo)[https://github.com/stellar/java-stellar-anchor-sdk] and runs tests
|
|
27
|
+
against.
|
|
28
|
+
|
|
29
|
+
## To run tests locally:
|
|
30
|
+
|
|
31
|
+
- follow the steps defined in the
|
|
32
|
+
(.github/workflows/integration.anchorPlatformTest.yml)[https://github.com/stellar/typescript-wallet-sdk/blob/main/.github/workflows/integration.anchorPlatformTest.yml]
|
|
33
|
+
file locally
|
|
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
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Wallet } from "../../src";
|
|
2
2
|
import { IssuedAssetId } from "../../src/walletSdk/Asset";
|
|
3
|
+
import { DefaultAuthHeaderSigner } from "../../src/walletSdk/Auth/AuthHeaderSigner";
|
|
3
4
|
|
|
4
5
|
let wallet;
|
|
5
6
|
let stellar;
|
|
@@ -23,6 +24,14 @@ describe("Anchor Platform Integration Tests", () => {
|
|
|
23
24
|
expect(authToken.token).toBeTruthy();
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
it("using DefaultAuthHeaderSigner should work", async () => {
|
|
28
|
+
const auth = await anchor.sep10();
|
|
29
|
+
|
|
30
|
+
const authHeaderSigner = new DefaultAuthHeaderSigner();
|
|
31
|
+
const authToken = await auth.authenticate({ accountKp, authHeaderSigner });
|
|
32
|
+
expect(authToken.token).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
|
|
26
35
|
it("SEP-12 KYC and SEP-6 should work", async () => {
|
|
27
36
|
const auth = await anchor.sep10();
|
|
28
37
|
const authToken = await auth.authenticate({ accountKp });
|
package/test/server.test.ts
CHANGED
|
@@ -68,4 +68,17 @@ describe("Server helpers", () => {
|
|
|
68
68
|
parsed = Server.parseAnchorTransaction(withdrawJson);
|
|
69
69
|
expect(parsed.kind).toBe("withdrawal");
|
|
70
70
|
});
|
|
71
|
+
it("should parse moneygram JSON transactions", () => {
|
|
72
|
+
const d1 = `{"id":"19489958-c0c4-4090-a272-a51fc851f524","kind":"deposit","status":"incomplete","amount_in":"3.00","amount_in_asset":"USD","amount_out":"3.00","amount_out_asset":"USD","amount_fee":"0.00","amount_fee_asset":"USD","started_at":"2024-03-28T16:20:09Z","stellar_transaction_id":"","refunded":false,"from":"","to":""}`;
|
|
73
|
+
let parsed = Server.parseAnchorTransaction(d1);
|
|
74
|
+
expect(parsed.kind).toBe("deposit");
|
|
75
|
+
|
|
76
|
+
const w1 = `{"withdraw_anchor_account":"GAYF33NNNMI2Z6VNRFXQ64D4E4SF77PM46NW3ZUZEEU5X7FCHAZCMHKU","withdraw_memo":"639496083328800102","withdraw_memo_type":"id","id":"d64c5d56-de6d-492e-95dd-412fb86c1c14","kind":"withdrawal","status":"pending_user_transfer_start","more_info_url":"https://extstellar.moneygram.com/transaction-status?transaction_id\u003dd64c5d56-de6d-492e-95dd-412fb86c1c14\u0026token\u003deyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkNjRjNWQ1Ni1kZTZkLTQ5MmUtOTVkZC00MTJmYjg2YzFjMTQiLCJpc3MiOiJtb3JlSW5mb1VybCIsInN1YiI6IkdBWkRVRlIyTDQ3S0hBS1g0V1NVWDNJUFo3NDYyVDVFNzNNQVpIWE9XT0NFQlBBUVlIVDdFNjJGIiwiaWF0IjoxNzExNjQyNzU0LCJleHAiOjE3MTE3MjkxNTQsImNsaWVudF9kb21haW4iOiJhcGktZGV2LnZpYnJhbnRhcHAuY29tIn0.CNjnMzXYA9aSU0ZA9Gd-P5bDWmpnaoAen8SnGz6PlHQ\u0026lang\u003den-US\u0026refNumber\u003d89445520","amount_in":"3.0","amount_in_asset":"USDC","amount_out":"4.02","amount_out_asset":"CAD","amount_fee":"0.0","amount_fee_asset":"USDC","started_at":"2024-03-28T16:18:02Z","stellar_transaction_id":"","external_transaction_id":"89445520","refunded":false,"from":"GAZDUFR2L47KHAKX4WSUX3IPZ7462T5E73MAZHXOWOCEBPAQYHT7E62F","to":"GAYF33NNNMI2Z6VNRFXQ64D4E4SF77PM46NW3ZUZEEU5X7FCHAZCMHKU"}`;
|
|
77
|
+
parsed = Server.parseAnchorTransaction(w1);
|
|
78
|
+
expect(parsed.kind).toBe("withdrawal");
|
|
79
|
+
|
|
80
|
+
const w2 = `{"id":"d64c5d56-de6d-492e-95dd-412fb86c1c14","kind":"withdrawal","status":"incomplete","amount_in":"0","amount_out":"0","amount_fee":"0","started_at":"2024-03-28T16:18:02Z","stellar_transaction_id":"","refunded":false,"from":"GAZDUFR2L47KHAKX4WSUX3IPZ7462T5E73MAZHXOWOCEBPAQYHT7E62F"}`;
|
|
81
|
+
parsed = Server.parseAnchorTransaction(w2);
|
|
82
|
+
expect(parsed.kind).toBe("withdrawal");
|
|
83
|
+
});
|
|
71
84
|
});
|
package/test/wallet.test.ts
CHANGED
|
@@ -20,6 +20,10 @@ import {
|
|
|
20
20
|
WalletSigner,
|
|
21
21
|
DefaultSigner,
|
|
22
22
|
} from "../src/walletSdk/Auth/WalletSigner";
|
|
23
|
+
import {
|
|
24
|
+
DefaultAuthHeaderSigner,
|
|
25
|
+
DomainAuthHeaderSigner,
|
|
26
|
+
} from "../src/walletSdk/Auth/AuthHeaderSigner";
|
|
23
27
|
import { SigningKeypair } from "../src/walletSdk/Horizon/Account";
|
|
24
28
|
import { Sep24 } from "../src/walletSdk/Anchor/Sep24";
|
|
25
29
|
import { DomainSigner } from "../src/walletSdk/Auth/WalletSigner";
|
|
@@ -1880,3 +1884,84 @@ describe("Http client", () => {
|
|
|
1880
1884
|
expect(resp.data.transaction).toBeTruthy();
|
|
1881
1885
|
});
|
|
1882
1886
|
});
|
|
1887
|
+
|
|
1888
|
+
describe("AuthHeaderSigner", () => {
|
|
1889
|
+
beforeAll(() => {
|
|
1890
|
+
jest.resetAllMocks();
|
|
1891
|
+
});
|
|
1892
|
+
it("full sep-10 auth using header token should work", async () => {
|
|
1893
|
+
const wallet = Wallet.TestNet();
|
|
1894
|
+
const accountKp = wallet.stellar().account().createKeypair();
|
|
1895
|
+
wallet.stellar().fundTestnetAccount(accountKp.publicKey);
|
|
1896
|
+
|
|
1897
|
+
const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
|
|
1898
|
+
const auth = await anchor.sep10();
|
|
1899
|
+
|
|
1900
|
+
const authHeaderSigner = new DefaultAuthHeaderSigner();
|
|
1901
|
+
const authToken = await auth.authenticate({
|
|
1902
|
+
accountKp,
|
|
1903
|
+
authHeaderSigner,
|
|
1904
|
+
});
|
|
1905
|
+
|
|
1906
|
+
expect(authToken).toBeTruthy();
|
|
1907
|
+
}, 15000);
|
|
1908
|
+
|
|
1909
|
+
it("should match example implementation generated JWT", async () => {
|
|
1910
|
+
const generatedAuthToken =
|
|
1911
|
+
"eyJhbGciOiJFZERTQSJ9.eyJpYXQiOjE3MTE2NDg0ODYsImV4cCI6MTcxMTY0OTM4NiwiYWNjb3VudCI6IkdDNlVDWFZUQU1ORzVKTE9NWkJTQ05ZWFZTTk5GSEwyM1NKUFlPT0ZKRTJBVllERFMyRkZUNDVDIiwiY2xpZW50X2RvbWFpbiI6ImV4YW1wbGUtd2FsbGV0LnN0ZWxsYXIub3JnIiwid2ViX2F1dGhfZW5kcG9pbnQiOiJodHRwczovL2V4YW1wbGUuY29tL3NlcDEwL2F1dGgifQ.UQt8FpUK-BlnFw35o8Ke4GDOoCrMe9ztEx4_TGQ06XhMgUbn_b7EMPMVLWJ8RRNgSk2dNhyGUgIbhKzKtWtBBw";
|
|
1912
|
+
const issuer = SigningKeypair.fromSecret(
|
|
1913
|
+
"SCYVDFYEHNDNTB2UER2FCYSZAYQFAAZ6BDYXL3BWRQWNL327GZUXY7D7",
|
|
1914
|
+
);
|
|
1915
|
+
|
|
1916
|
+
const claims = {
|
|
1917
|
+
iat: 1711648486,
|
|
1918
|
+
exp: 1711649386,
|
|
1919
|
+
account: "GC6UCXVTAMNG5JLOMZBSCNYXVSNNFHL23SJPYOOFJE2AVYDDS2FFT45C",
|
|
1920
|
+
client_domain: "example-wallet.stellar.org",
|
|
1921
|
+
web_auth_endpoint: "https://example.com/sep10/auth",
|
|
1922
|
+
};
|
|
1923
|
+
|
|
1924
|
+
const signer = new DefaultAuthHeaderSigner();
|
|
1925
|
+
const token = await signer.createToken({
|
|
1926
|
+
claims,
|
|
1927
|
+
clientDomain: "",
|
|
1928
|
+
issuer,
|
|
1929
|
+
});
|
|
1930
|
+
|
|
1931
|
+
expect(token).toBe(generatedAuthToken);
|
|
1932
|
+
});
|
|
1933
|
+
|
|
1934
|
+
it("DefaultAuthHeaderSigner should work", async () => {
|
|
1935
|
+
const accountKp = SigningKeypair.fromSecret(
|
|
1936
|
+
"SAFXVNFRZQAC66RUZ2IJKMSNQCPXTKXVRX356COUKJJKJXBSLRX43DEZ",
|
|
1937
|
+
);
|
|
1938
|
+
|
|
1939
|
+
const signer = new DefaultAuthHeaderSigner();
|
|
1940
|
+
const token = await signer.createToken({
|
|
1941
|
+
claims: {},
|
|
1942
|
+
clientDomain: "test-domain",
|
|
1943
|
+
issuer: accountKp,
|
|
1944
|
+
});
|
|
1945
|
+
expect(token).toBeTruthy();
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
it("DomainAuthHeaderSigner should work", async () => {
|
|
1949
|
+
const accountKp = SigningKeypair.fromSecret(
|
|
1950
|
+
"SAFXVNFRZQAC66RUZ2IJKMSNQCPXTKXVRX356COUKJJKJXBSLRX43DEZ",
|
|
1951
|
+
);
|
|
1952
|
+
|
|
1953
|
+
const signer = new DomainAuthHeaderSigner("some-url.com");
|
|
1954
|
+
|
|
1955
|
+
const data = { account: "dummy-account" };
|
|
1956
|
+
|
|
1957
|
+
jest.spyOn(signer, "signTokenRemote").mockResolvedValue("success-token");
|
|
1958
|
+
|
|
1959
|
+
const token = await signer.createToken({
|
|
1960
|
+
authTokenData: data,
|
|
1961
|
+
clientDomain: "test-domain",
|
|
1962
|
+
issuer: accountKp,
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
expect(token).toBe("success-token");
|
|
1966
|
+
});
|
|
1967
|
+
});
|
package/webpack.config.js
CHANGED
|
@@ -29,6 +29,7 @@ module.exports = (env = { NODE: false }) => {
|
|
|
29
29
|
util: require.resolve("util"),
|
|
30
30
|
vm: require.resolve("vm-browserify"),
|
|
31
31
|
"process/browser": require.resolve("process/browser"),
|
|
32
|
+
buffer: require.resolve("buffer"),
|
|
32
33
|
}
|
|
33
34
|
: {},
|
|
34
35
|
},
|
|
@@ -45,6 +46,9 @@ module.exports = (env = { NODE: false }) => {
|
|
|
45
46
|
new webpack.ProvidePlugin({
|
|
46
47
|
process: "process/browser",
|
|
47
48
|
}),
|
|
49
|
+
new webpack.ProvidePlugin({
|
|
50
|
+
Buffer: ["buffer", "Buffer"],
|
|
51
|
+
}),
|
|
48
52
|
]
|
|
49
53
|
: [],
|
|
50
54
|
};
|
package/test/README.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Recovery Integration Tests
|
|
2
|
-
|
|
3
|
-
## How it works
|
|
4
|
-
|
|
5
|
-
The recovery integration tests run different recovery scenarios against recovery
|
|
6
|
-
signer and webauth servers. 2 recovery signer and 2 webauth servers are started
|
|
7
|
-
in a docker-compose file (see test/docker/docker-compose.yml), to simulate a
|
|
8
|
-
wallet interacting with 2 separate recovery servers.
|
|
9
|
-
|
|
10
|
-
## To run tests locally:
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
// start servers using docker
|
|
14
|
-
$ docker-compose -f test/docker/docker-compose.yml up
|
|
15
|
-
|
|
16
|
-
// run tests
|
|
17
|
-
$ yarn test:integration:ci
|
|
18
|
-
```
|