@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
package/.eslintrc.js ADDED
@@ -0,0 +1,76 @@
1
+ module.exports = {
2
+ ignorePatterns: ["lib/", "node_modules/", "docs/"],
3
+ parser: "@typescript-eslint/parser",
4
+ parserOptions: {
5
+ project: ["tsconfig.json", "examples/tsconfig.json", "test/tsconfig.json"],
6
+ sourceType: "module",
7
+ },
8
+ plugins: ["@typescript-eslint", "jsdoc"],
9
+ extends: [
10
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
11
+ "plugin:@typescript-eslint/recommended",
12
+ "prettier",
13
+ ],
14
+ rules: {
15
+ // Off
16
+ "@typescript-eslint/no-unsafe-argument": "off",
17
+ "@typescript-eslint/no-floating-promises": "off",
18
+ "@typescript-eslint/no-unsafe-assignment": "off",
19
+ "@typescript-eslint/no-unsafe-call": "off",
20
+ "@typescript-eslint/no-unsafe-member-access": "off",
21
+ "@typescript-eslint/no-unsafe-return": "off",
22
+ "@typescript-eslint/prefer-regexp-exec": "off",
23
+ "@typescript-eslint/restrict-template-expressions": "off",
24
+ "@typescript-eslint/no-inferrable-types": "off",
25
+ "@typescript-eslint/no-misused-promises": "off",
26
+ "@typescript-eslint/no-base-to-string": "off",
27
+
28
+ // Warn
29
+ "jsdoc/check-param-names": "warn",
30
+ "jsdoc/require-returns": "warn",
31
+ "jsdoc/require-returns-description": "warn",
32
+ "jsdoc/require-returns-type": "warn",
33
+ "jsdoc/require-param": "warn",
34
+ "jsdoc/check-types": "warn",
35
+ "jsdoc/require-param-description": "warn",
36
+ "jsdoc/require-param-name": "warn",
37
+ "jsdoc/require-param-type": "warn",
38
+ "jsdoc/require-property": "warn",
39
+ "jsdoc/require-property-description": "warn",
40
+ "jsdoc/require-property-name": "warn",
41
+ "jsdoc/require-property-type": "warn",
42
+ "jsdoc/check-property-names": "warn",
43
+ "jsdoc/empty-tags": "warn",
44
+
45
+ // Error
46
+ "@typescript-eslint/no-shadow": "error",
47
+ "@typescript-eslint/no-unused-expressions": "error",
48
+ "@typescript-eslint/no-var-requires": "error",
49
+ "@typescript-eslint/prefer-for-of": "error",
50
+ "@typescript-eslint/prefer-function-type": "error",
51
+ "@typescript-eslint/prefer-namespace-keyword": "error",
52
+ "@typescript-eslint/triple-slash-reference": [
53
+ "error",
54
+ {
55
+ path: "always",
56
+ types: "prefer-import",
57
+ lib: "always",
58
+ },
59
+ ],
60
+ "@typescript-eslint/unified-signatures": "error",
61
+ "@typescript-eslint/no-misused-new": "error",
62
+ "@typescript-eslint/no-empty-function": "error",
63
+ "@typescript-eslint/no-empty-interface": "error",
64
+ "jsdoc/check-alignment": "error",
65
+ "jsdoc/check-indentation": "error",
66
+ },
67
+ overrides: [
68
+ {
69
+ files: ["test/**", "examples/**"],
70
+ rules: {
71
+ "@typescript-eslint/no-shadow": "off",
72
+ "@typescript-eslint/no-explicit-any": "off",
73
+ },
74
+ },
75
+ ],
76
+ };
@@ -0,0 +1,19 @@
1
+ name: Recovery Signer Integration Test
2
+ on: [pull_request]
3
+ jobs:
4
+ test-ci:
5
+ name: integration test
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v2
9
+ - name: Start docker
10
+ run: docker-compose -f test/docker/docker-compose.yml up -d
11
+ - uses: actions/setup-node@v2
12
+ with:
13
+ node-version: 18
14
+ - run: yarn install
15
+ - run: yarn build
16
+ - run: yarn test:integration:ci
17
+ - name: Print Docker Logs
18
+ if: always() # This ensures that the logs are printed even if the tests fail
19
+ run: docker-compose -f test/docker/docker-compose.yml logs
@@ -0,0 +1,14 @@
1
+ name: Run Tests
2
+ on: [pull_request]
3
+ jobs:
4
+ test-ci:
5
+ name: test
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v2
9
+ - uses: actions/setup-node@v2
10
+ with:
11
+ node-version: 18
12
+ - run: yarn install
13
+ - run: yarn build
14
+ - run: yarn test:ci
package/.husky/pre-commit CHANGED
@@ -2,3 +2,4 @@
2
2
  . "$(dirname -- "$0")/_/husky.sh"
3
3
 
4
4
  yarn pretty-quick --staged
5
+ yarn lint-staged
package/README.md CHANGED
@@ -1,14 +1,17 @@
1
- # Stellar Typescript Wallet SDK [![npm version](https://badge.fury.io/js/@stellar%2Ftypescript-wallet-sdk.svg)](https://badge.fury.io/js/@stellar%2Ftypescript-wallet-sdk)
1
+ # Stellar Typescript Wallet SDK [![npm version](https://badge.fury.io/js/@stellar%2Ftypescript-wallet-sdk.svg)](https://badge.fury.io/js/@stellar%2Ftypescript-wallet-sdk)
2
2
 
3
- Typescript Wallet SDK is a library that allows developers to build wallet applications on the Stellar network faster. It
4
- utilizes [Javascript Stellar SDK](https://github.com/stellar/js-stellar-sdk) to communicate with a Stellar Horizon server.
5
- It offers wide range of functionality to simplify integration with the Stellar network, and connect to the anchors easily, utilizing
6
- various Stellar protocols (SEPs)
3
+ Typescript Wallet SDK is a library that allows developers to build wallet
4
+ applications on the Stellar network faster. It utilizes
5
+ [Javascript Stellar SDK](https://github.com/stellar/js-stellar-sdk) to
6
+ communicate with a Stellar Horizon server.
7
+ It offers wide range of functionality to simplify integration with the Stellar
8
+ network, and connect to the anchors easily, utilizing various Stellar protocols
9
+ (SEPs)
7
10
 
8
11
  ## Dependency
9
12
 
10
- The library is available via npm.
11
- To import `typescript-wallet-sdk` library you need to add it as a dependency to your code:
13
+ The library is available via npm. To import `typescript-wallet-sdk` library you
14
+ need to add it as a dependency to your code:
12
15
 
13
16
  yarn:
14
17
 
@@ -24,21 +27,25 @@ npm install @stellar/typescript-wallet-sdk
24
27
 
25
28
  ## Introduction
26
29
 
27
- Here's a small example creating main wallet class with default configuration connected to testnet network:
30
+ Here's a small example creating main wallet class with default configuration
31
+ connected to testnet network:
28
32
 
29
33
  ```typescript
30
34
  let wallet = walletSdk.Wallet.TestNet();
31
35
  ```
32
36
 
33
- It should later be re-used across the code, as it has access to various useful children classes. For example, you can
34
- authenticate with the `testanchor` as simple as:
37
+ It should later be re-used across the code, as it has access to various useful
38
+ children classes. For example, you can authenticate with the `testanchor` as
39
+ simple as:
35
40
 
36
41
  ```typescript
37
42
  const authKey = SigningKeypair.fromSecret("my secret key");
38
43
  const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
39
44
  const sep10 = await anchor.sep10();
40
45
 
41
- const authToken = await sep10.authenticate({accountKp: authKey});
46
+ const authToken = await sep10.authenticate({ accountKp: authKey });
42
47
  ```
43
48
 
44
- Read [full wallet guide](https://developers.stellar.org/docs/category/build-a-wallet) for more info
49
+ Read
50
+ [full wallet guide](https://developers.stellar.org/docs/category/build-a-wallet-with-the-wallet-sdk)
51
+ for more info
@@ -0,0 +1,4 @@
1
+ ANCHOR_DOMAIN=testanchor.stellar.org
2
+ ASSET_CODE=USDC
3
+ ASSET_ISSUER=GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5
4
+ RUN_MAINNET=false
@@ -20,3 +20,20 @@ example.
20
20
  Progress will be logged in the terminal.
21
21
 
22
22
  _note: the identity values used in the sep24 interactive portal can all be fake_
23
+
24
+ ## Changing environment variables
25
+
26
+ If you'd like to use different environment variable values than the default
27
+ ones, you can add a `.env` file. See `.env.example` as an example.
28
+
29
+ The environment variables you can set are:
30
+
31
+ | Variable Name | Description | Default Value |
32
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------- |
33
+ | ANCHOR_DOMAIN | The anchor domain for your application. | testanchor.stellar.org |
34
+ | ASSET_CODE | The code representing the asset. | USDC |
35
+ | ASSET_ISSUER | The issuer's public key for the asset. | GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 |
36
+ | SOURCE_ACCOUNT_SECRET | The secret key for the account depositing or withdrawing from the anchor. If none given then a new account will be created. | none |
37
+ | RUN_MAINNET | Set to `true` to run the application on Mainnet. | false |
38
+ | CLIENT_DOMAIN | [SEP-10](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md) client domain used for authentication. | none |
39
+ | CLIENT_SECRET | Secret key for the client domain. Alternatively, you may want to implement your own `WalletSigner`. | none |
@@ -1,5 +1,6 @@
1
1
  import axios from "axios";
2
2
  import readline from "readline";
3
+ import path from "path";
3
4
 
4
5
  import {
5
6
  walletSdk,
@@ -7,25 +8,48 @@ import {
7
8
  SigningKeypair,
8
9
  Types,
9
10
  IssuedAssetId,
11
+ DefaultSigner,
10
12
  } from "../../src";
11
- import { Memo, MemoText } from "stellar-sdk";
12
-
13
- const wallet = walletSdk.Wallet.TestNet();
13
+ import { Memo, MemoText, Transaction, TransactionBuilder } from "stellar-sdk";
14
+
15
+ import * as dotenv from "dotenv";
16
+ dotenv.config({ path: path.resolve(__dirname, ".env") });
17
+
18
+ // Grabbing environment variables
19
+
20
+ const anchorDomain = process.env.ANCHOR_DOMAIN || "testanchor.stellar.org";
21
+ const assetCode = process.env.ASSET_CODE || "USDC";
22
+ const assetIssuer =
23
+ process.env.ASSET_ISSUER ||
24
+ "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
25
+ const runMainnet = process.env.RUN_MAINNET || false;
26
+ const sourceAccountSecret = process.env.SOURCE_ACCOUNT_SECRET;
27
+ const clientDomain = process.env.CLIENT_DOMAIN;
28
+ const clientSecret = process.env.CLIENT_SECRET;
29
+
30
+ // Running example
31
+
32
+ let wallet;
33
+ if (runMainnet === "true") {
34
+ console.log("Warning: you are running this script on the public network.");
35
+ wallet = walletSdk.Wallet.MainNet();
36
+ } else {
37
+ wallet = walletSdk.Wallet.TestNet();
38
+ }
14
39
  const stellar = wallet.stellar();
15
- const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
40
+ const anchor = wallet.anchor({
41
+ homeDomain: anchorDomain,
42
+ });
16
43
  const account = stellar.account();
17
44
 
18
45
  let kp: SigningKeypair;
19
46
 
20
- const asset = new IssuedAssetId(
21
- "USDC",
22
- "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
23
- );
47
+ const asset = new IssuedAssetId(assetCode, assetIssuer);
24
48
 
25
49
  const runSep24 = async () => {
26
50
  await createAccount();
27
51
  await runDeposit(anchor, kp);
28
- await runDepositWatcher(anchor);
52
+ runDepositWatcher(anchor);
29
53
 
30
54
  while (!depositDone) {
31
55
  await new Promise((resolve) => setTimeout(resolve, 1000));
@@ -37,11 +61,16 @@ const runSep24 = async () => {
37
61
  }
38
62
 
39
63
  await runWithdraw(anchor, kp);
40
- await runWithdrawWatcher(anchor, kp);
64
+ runWithdrawWatcher(anchor, kp);
41
65
  };
42
66
 
43
67
  // Create Account
44
68
  const createAccount = async () => {
69
+ if (sourceAccountSecret) {
70
+ kp = SigningKeypair.fromSecret(sourceAccountSecret);
71
+ return;
72
+ }
73
+
45
74
  console.log("creating account ...");
46
75
  kp = account.createKeypair();
47
76
  console.log(`kp: \n${kp.publicKey}\n${kp.secretKey}`);
@@ -59,11 +88,15 @@ const createAccount = async () => {
59
88
  };
60
89
 
61
90
  // Create Deposit
62
- let authToken: string;
91
+ let authToken: Types.AuthToken;
63
92
  export const runDeposit = async (anchor: Anchor, kp: SigningKeypair) => {
64
93
  console.log("\ncreating deposit ...");
65
94
  const auth = await anchor.sep10();
66
- authToken = await auth.authenticate({ accountKp: kp });
95
+ authToken = await auth.authenticate({
96
+ accountKp: kp,
97
+ clientDomain,
98
+ walletSigner,
99
+ });
67
100
 
68
101
  const resp = await anchor.sep24().deposit({
69
102
  assetCode: asset.code,
@@ -85,7 +118,7 @@ export let depositDone = false;
85
118
  export const runDepositWatcher = (anchor: Anchor) => {
86
119
  console.log("\nstarting watcher ...");
87
120
 
88
- let stop: Types.WatcherStopFunction;
121
+ const stop: Types.WatcherStopFunction;
89
122
  const onMessage = (m: Types.AnchorTransaction) => {
90
123
  console.log({ m });
91
124
  if (m.status === Types.TransactionStatus.completed) {
@@ -150,7 +183,7 @@ const sendWithdrawalTransaction = async (withdrawalTxn, kp) => {
150
183
  export const runWithdrawWatcher = (anchor, kp) => {
151
184
  console.log("\nstarting watcher ...");
152
185
 
153
- let stop;
186
+ const stop;
154
187
  const onMessage = (m) => {
155
188
  console.log({ m });
156
189
 
@@ -182,6 +215,28 @@ export const runWithdrawWatcher = (anchor, kp) => {
182
215
  stop = resp.stop;
183
216
  };
184
217
 
218
+ const walletSigner = DefaultSigner;
219
+ walletSigner.signWithDomainAccount = async ({
220
+ transactionXDR,
221
+ networkPassphrase,
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
223
+ accountKp,
224
+ }: Types.SignWithDomainAccountParams): Promise<Transaction> => {
225
+ if (!clientSecret) {
226
+ throw new Error("Client Secret missing from .env file");
227
+ }
228
+
229
+ const signer = SigningKeypair.fromSecret(clientSecret);
230
+
231
+ const transaction = TransactionBuilder.fromXDR(
232
+ transactionXDR,
233
+ networkPassphrase,
234
+ ) as Transaction;
235
+ signer.sign(transaction);
236
+
237
+ return Promise.resolve(transaction);
238
+ };
239
+
185
240
  export const askQuestion = (query) => {
186
241
  const rl = readline.createInterface({
187
242
  input: process.stdin,
@@ -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
+ }
package/jest.config.js CHANGED
@@ -5,4 +5,5 @@ module.exports = {
5
5
  "^.+\\.(ts|tsx)?$": "ts-jest",
6
6
  "^.+\\.(js|jsx)$": "babel-jest",
7
7
  },
8
+ testPathIgnorePatterns: ["/node_modules/", "integration.test.ts"],
8
9
  };
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ rootDir: "./",
3
+ preset: "ts-jest",
4
+ transform: {
5
+ "^.+\\.(ts|tsx)?$": "ts-jest",
6
+ "^.+\\.(js|jsx)$": "babel-jest",
7
+ },
8
+ testMatch: ["**/*integration.test.ts"],
9
+ };