@stellar/typescript-wallet-sdk 1.2.1 → 1.3.1

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 (97) 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 +74 -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 +37387 -32486
  13. package/lib/bundle.js.map +1 -1
  14. package/lib/bundle_browser.js +2750 -50105
  15. package/lib/bundle_browser.js.map +1 -1
  16. package/lib/index.d.ts +2 -2
  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 +22 -4
  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 +42 -3
  26. package/lib/walletSdk/Horizon/Account.d.ts +1 -1
  27. package/lib/walletSdk/Horizon/AccountService.d.ts +30 -20
  28. package/lib/walletSdk/Horizon/Stellar.d.ts +79 -2
  29. package/lib/walletSdk/Horizon/Transaction/CommonTransactionBuilder.d.ts +40 -1
  30. package/lib/walletSdk/Horizon/Transaction/SponsoringBuilder.d.ts +30 -2
  31. package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +81 -13
  32. package/lib/walletSdk/Horizon/index.d.ts +2 -1
  33. package/lib/walletSdk/Recovery/AccountRecover.d.ts +58 -0
  34. package/lib/walletSdk/Recovery/index.d.ts +69 -7
  35. package/lib/walletSdk/Types/anchor.d.ts +18 -3
  36. package/lib/walletSdk/Types/auth.d.ts +12 -2
  37. package/lib/walletSdk/Types/horizon.d.ts +6 -5
  38. package/lib/walletSdk/Types/index.d.ts +8 -3
  39. package/lib/walletSdk/Types/recovery.d.ts +128 -0
  40. package/lib/walletSdk/Types/sep12.d.ts +57 -0
  41. package/lib/walletSdk/Types/sep24.d.ts +1 -1
  42. package/lib/walletSdk/Types/sep38.d.ts +93 -0
  43. package/lib/walletSdk/Types/sep6.d.ts +160 -0
  44. package/lib/walletSdk/Types/watcher.d.ts +7 -2
  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 +41 -4
  49. package/package.json +17 -4
  50. package/src/index.ts +3 -1
  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 +24 -6
  57. package/src/walletSdk/Auth/index.ts +25 -6
  58. package/src/walletSdk/Customer/index.ts +174 -0
  59. package/src/walletSdk/Exceptions/index.ts +101 -4
  60. package/src/walletSdk/Horizon/Account.ts +1 -1
  61. package/src/walletSdk/Horizon/AccountService.ts +33 -21
  62. package/src/walletSdk/Horizon/Stellar.ts +90 -7
  63. package/src/walletSdk/Horizon/Transaction/CommonTransactionBuilder.ts +44 -5
  64. package/src/walletSdk/Horizon/Transaction/SponsoringBuilder.ts +30 -7
  65. package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +89 -16
  66. package/src/walletSdk/Horizon/index.ts +2 -1
  67. package/src/walletSdk/Recovery/AccountRecover.ts +255 -0
  68. package/src/walletSdk/Recovery/index.ts +314 -13
  69. package/src/walletSdk/Types/anchor.ts +24 -3
  70. package/src/walletSdk/Types/auth.ts +36 -2
  71. package/src/walletSdk/Types/horizon.ts +7 -5
  72. package/src/walletSdk/Types/index.ts +9 -3
  73. package/src/walletSdk/Types/recovery.ts +152 -0
  74. package/src/walletSdk/Types/sep12.ts +61 -0
  75. package/src/walletSdk/Types/sep24.ts +1 -1
  76. package/src/walletSdk/Types/sep38.ts +106 -0
  77. package/src/walletSdk/Types/sep6.ts +168 -0
  78. package/src/walletSdk/Types/watcher.ts +8 -2
  79. package/src/walletSdk/Utils/camelToSnakeCase.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/account.test.ts +1 -1
  86. package/test/accountService.test.ts +22 -4
  87. package/test/customer.test.ts +82 -0
  88. package/test/docker/docker-compose.yml +97 -0
  89. package/test/integration.test.ts +166 -0
  90. package/test/recovery.test.ts +107 -0
  91. package/test/sep38.test.ts +71 -0
  92. package/test/sep6.test.ts +240 -0
  93. package/test/stellar.test.ts +57 -12
  94. package/test/transaction.test.ts +9 -11
  95. package/test/tsconfig.json +10 -0
  96. package/test/utils/index.ts +12 -0
  97. package/test/wallet.test.ts +44 -24
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,53 @@ 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 {
14
+ Memo,
15
+ MemoText,
16
+ Transaction,
17
+ TransactionBuilder,
18
+ } from "@stellar/stellar-sdk";
19
+
20
+ import * as dotenv from "dotenv";
21
+ dotenv.config({ path: path.resolve(__dirname, ".env") });
22
+
23
+ // Grabbing environment variables
24
+
25
+ const anchorDomain = process.env.ANCHOR_DOMAIN || "testanchor.stellar.org";
26
+ const assetCode = process.env.ASSET_CODE || "USDC";
27
+ const assetIssuer =
28
+ process.env.ASSET_ISSUER ||
29
+ "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
30
+ const runMainnet = process.env.RUN_MAINNET || false;
31
+ const sourceAccountSecret = process.env.SOURCE_ACCOUNT_SECRET;
32
+ const clientDomain = process.env.CLIENT_DOMAIN;
33
+ const clientSecret = process.env.CLIENT_SECRET;
34
+
35
+ // Running example
36
+
37
+ let wallet;
38
+ if (runMainnet === "true") {
39
+ console.log("Warning: you are running this script on the public network.");
40
+ wallet = walletSdk.Wallet.MainNet();
41
+ } else {
42
+ wallet = walletSdk.Wallet.TestNet();
43
+ }
14
44
  const stellar = wallet.stellar();
15
- const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
45
+ const anchor = wallet.anchor({
46
+ homeDomain: anchorDomain,
47
+ });
16
48
  const account = stellar.account();
17
49
 
18
50
  let kp: SigningKeypair;
19
51
 
20
- const asset = new IssuedAssetId(
21
- "USDC",
22
- "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
23
- );
52
+ const asset = new IssuedAssetId(assetCode, assetIssuer);
24
53
 
25
54
  const runSep24 = async () => {
26
55
  await createAccount();
27
56
  await runDeposit(anchor, kp);
28
- await runDepositWatcher(anchor);
57
+ runDepositWatcher(anchor);
29
58
 
30
59
  while (!depositDone) {
31
60
  await new Promise((resolve) => setTimeout(resolve, 1000));
@@ -37,11 +66,16 @@ const runSep24 = async () => {
37
66
  }
38
67
 
39
68
  await runWithdraw(anchor, kp);
40
- await runWithdrawWatcher(anchor, kp);
69
+ runWithdrawWatcher(anchor, kp);
41
70
  };
42
71
 
43
72
  // Create Account
44
73
  const createAccount = async () => {
74
+ if (sourceAccountSecret) {
75
+ kp = SigningKeypair.fromSecret(sourceAccountSecret);
76
+ return;
77
+ }
78
+
45
79
  console.log("creating account ...");
46
80
  kp = account.createKeypair();
47
81
  console.log(`kp: \n${kp.publicKey}\n${kp.secretKey}`);
@@ -59,11 +93,15 @@ const createAccount = async () => {
59
93
  };
60
94
 
61
95
  // Create Deposit
62
- let authToken: string;
96
+ let authToken: Types.AuthToken;
63
97
  export const runDeposit = async (anchor: Anchor, kp: SigningKeypair) => {
64
98
  console.log("\ncreating deposit ...");
65
99
  const auth = await anchor.sep10();
66
- authToken = await auth.authenticate({ accountKp: kp });
100
+ authToken = await auth.authenticate({
101
+ accountKp: kp,
102
+ clientDomain,
103
+ walletSigner,
104
+ });
67
105
 
68
106
  const resp = await anchor.sep24().deposit({
69
107
  assetCode: asset.code,
@@ -85,7 +123,7 @@ export let depositDone = false;
85
123
  export const runDepositWatcher = (anchor: Anchor) => {
86
124
  console.log("\nstarting watcher ...");
87
125
 
88
- let stop: Types.WatcherStopFunction;
126
+ const stop: Types.WatcherStopFunction;
89
127
  const onMessage = (m: Types.AnchorTransaction) => {
90
128
  console.log({ m });
91
129
  if (m.status === Types.TransactionStatus.completed) {
@@ -150,7 +188,7 @@ const sendWithdrawalTransaction = async (withdrawalTxn, kp) => {
150
188
  export const runWithdrawWatcher = (anchor, kp) => {
151
189
  console.log("\nstarting watcher ...");
152
190
 
153
- let stop;
191
+ const stop;
154
192
  const onMessage = (m) => {
155
193
  console.log({ m });
156
194
 
@@ -182,6 +220,28 @@ export const runWithdrawWatcher = (anchor, kp) => {
182
220
  stop = resp.stop;
183
221
  };
184
222
 
223
+ const walletSigner = DefaultSigner;
224
+ walletSigner.signWithDomainAccount = async ({
225
+ transactionXDR,
226
+ networkPassphrase,
227
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
228
+ accountKp,
229
+ }: Types.SignWithDomainAccountParams): Promise<Transaction> => {
230
+ if (!clientSecret) {
231
+ throw new Error("Client Secret missing from .env file");
232
+ }
233
+
234
+ const signer = SigningKeypair.fromSecret(clientSecret);
235
+
236
+ const transaction = TransactionBuilder.fromXDR(
237
+ transactionXDR,
238
+ networkPassphrase,
239
+ ) as Transaction;
240
+ signer.sign(transaction);
241
+
242
+ return Promise.resolve(transaction);
243
+ };
244
+
185
245
  export const askQuestion = (query) => {
186
246
  const rl = readline.createInterface({
187
247
  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
+ };