@stellar/typescript-wallet-sdk 1.7.0 → 1.8.0-beta.1731096658096

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 (39) hide show
  1. package/CHANGELOG.MD +8 -0
  2. package/examples/helpers/ask-question.ts +15 -0
  3. package/examples/sep10/.env.example +2 -0
  4. package/examples/sep10/README.md +34 -0
  5. package/examples/sep10/sep10Server.ts +53 -0
  6. package/examples/sep10/sep10Wallet.ts +45 -0
  7. package/examples/sep10/well_known/stellar.toml +18 -0
  8. package/examples/sep12/.env.example +2 -0
  9. package/examples/sep12/README.md +25 -0
  10. package/examples/sep12/sep12.ts +38 -0
  11. package/examples/sep24/sep24.ts +1 -15
  12. package/lib/bundle.js +3277 -1898
  13. package/lib/bundle.js.map +1 -1
  14. package/lib/bundle_browser.js +117 -48
  15. package/lib/bundle_browser.js.map +1 -1
  16. package/lib/walletSdk/Anchor/Sep24.d.ts +19 -7
  17. package/lib/walletSdk/Anchor/Sep38.d.ts +1 -0
  18. package/lib/walletSdk/Anchor/Sep6.d.ts +3 -1
  19. package/lib/walletSdk/Anchor/index.d.ts +5 -3
  20. package/lib/walletSdk/Customer/index.d.ts +12 -6
  21. package/lib/walletSdk/Exceptions/index.d.ts +3 -0
  22. package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +2 -1
  23. package/lib/walletSdk/Types/anchor.d.ts +14 -22
  24. package/lib/walletSdk/Types/sep12.d.ts +7 -1
  25. package/lib/walletSdk/Types/sep24.d.ts +21 -0
  26. package/package.json +8 -4
  27. package/src/walletSdk/Anchor/Sep24.ts +44 -12
  28. package/src/walletSdk/Anchor/Sep38.ts +1 -1
  29. package/src/walletSdk/Anchor/Sep6.ts +9 -2
  30. package/src/walletSdk/Anchor/index.ts +5 -10
  31. package/src/walletSdk/Customer/index.ts +33 -14
  32. package/src/walletSdk/Exceptions/index.ts +9 -0
  33. package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +8 -1
  34. package/src/walletSdk/Types/anchor.ts +15 -20
  35. package/src/walletSdk/Types/sep12.ts +7 -1
  36. package/src/walletSdk/Types/sep24.ts +19 -0
  37. package/test/customer.test.ts +25 -15
  38. package/test/stellar.test.ts +155 -31
  39. package/test/wallet.test.ts +18 -1
package/CHANGELOG.MD CHANGED
@@ -1,3 +1,11 @@
1
+ # Release notes - Typescript Wallet SDK - 1.8.0
2
+
3
+ ### Added
4
+ * Upgrades `@stellar/stellar-sdk` to `13.0.0-beta.1` which supports the `Protocol 22` XDR (#172)
5
+ * Add `transaction_id` field to SEP-12 requests (#165)
6
+ * Make `withdraw_anchor_account` field optional (#164)
7
+ * Deprecate `getServicesInfo()` in favor of `Sep24.info()` (#166)
8
+
1
9
  # Release notes - Typescript Wallet SDK - 1.7.0
2
10
 
3
11
  ### Fixed
@@ -0,0 +1,15 @@
1
+ import readline from "readline";
2
+
3
+ export const askQuestion = (query) => {
4
+ const rl = readline.createInterface({
5
+ input: process.stdin,
6
+ output: process.stdout,
7
+ });
8
+
9
+ return new Promise<string>((resolve) =>
10
+ rl.question(query, (ans) => {
11
+ rl.close();
12
+ resolve(ans);
13
+ }),
14
+ );
15
+ };
@@ -0,0 +1,2 @@
1
+ ANCHOR_DOMAIN=testanchor.stellar.org
2
+ RUN_MAINNET=false
@@ -0,0 +1,34 @@
1
+ # Sep-10 examples for stellar typescript-wallet-sdk
2
+
3
+ ## Example code
4
+
5
+ To view how the wallet-sdk can be used to create a sep-10 auth token for a
6
+ wallet to send to an anchor, look at `sep10Wallet.ts`.
7
+
8
+ To view how to setup an authentication server for the anchor, look at
9
+ `sep10Server.ts`.
10
+
11
+ ## Running deposit and withdrawals
12
+
13
+ To see them in action you can run below from the project root:
14
+
15
+ ```
16
+ $ yarn example:sep10
17
+ ```
18
+
19
+ This will run an example SEP-10 server which can use to sign authentication
20
+ requests and to serve a SEP-1 stellar.toml
21
+
22
+ ## Changing environment variables
23
+
24
+ If you'd like to use different environment variable values than the default
25
+ ones, you can add a `.env` file. See `.env.example` as an example.
26
+
27
+ The environment variables you can set are:
28
+
29
+ | Variable Name | Description | Default Value |
30
+ | --------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------- |
31
+ | ANCHOR_DOMAIN | The anchor domain for your application. | testanchor.stellar.org |
32
+ | AUTH_KEY_SECRET | The secret key for the account authenticating | none |
33
+ | RUN_MAINNET | Set to `true` to run the application on Mainnet. | false |
34
+ | CLIENT_DOMAIN | [SEP-10](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md) client domain used for authentication. | none |
@@ -0,0 +1,53 @@
1
+ import path from "path";
2
+ import express from "express";
3
+ import { Transaction, Keypair } from "@stellar/stellar-sdk";
4
+ import * as dotenv from "dotenv";
5
+ import bodyParser from "body-parser";
6
+
7
+ dotenv.config({ path: path.resolve(__dirname, ".env") });
8
+
9
+ const PORT = process.env.SERVER_PORT ?? 7000;
10
+ const SERVER_SIGNING_KEY = String(process.env.SERVER_SIGNING_KEY);
11
+ const app = express();
12
+
13
+ app.use(bodyParser.json());
14
+ app.use(bodyParser.urlencoded({ extended: true }));
15
+
16
+ // Serve the sep-1 stellar.toml file
17
+ app.use(
18
+ "/.well-known",
19
+ express.static(path.join(__dirname, "well_known"), {
20
+ setHeaders: function (res) {
21
+ res.set("Access-Control-Allow-Headers", "Content-Type,X-Requested-With");
22
+ res.type("application/json");
23
+ console.log("request to /.well-known");
24
+ },
25
+ }),
26
+ );
27
+
28
+ // Sign requests from the wallet for sep-10 client attribution
29
+ app.post("/sign", (req, res) => {
30
+ console.log("request to /sign");
31
+ const envelope_xdr = req.body.transaction;
32
+ const network_passphrase = req.body.network_passphrase;
33
+ const transaction = new Transaction(envelope_xdr, network_passphrase);
34
+
35
+ if (Number.parseInt(transaction.sequence, 10) !== 0) {
36
+ res.status(400);
37
+ res.send("transaction sequence value must be '0'");
38
+ return;
39
+ }
40
+
41
+ transaction.sign(Keypair.fromSecret(SERVER_SIGNING_KEY));
42
+
43
+ res.set("Access-Control-Allow-Origin", "*");
44
+ res.status(200);
45
+ res.send({
46
+ transaction: transaction.toEnvelope().toXDR("base64"),
47
+ network_passphrase: network_passphrase,
48
+ });
49
+ });
50
+
51
+ app.listen(PORT, () => {
52
+ console.log(`Listening on port ${PORT}`);
53
+ });
@@ -0,0 +1,45 @@
1
+ import path from "path";
2
+
3
+ import { walletSdk, SigningKeypair, DefaultSigner, Wallet } from "../../src";
4
+
5
+ import * as dotenv from "dotenv";
6
+ dotenv.config({ path: path.resolve(__dirname, ".env") });
7
+
8
+ // Grabbing environment variables
9
+
10
+ const anchorDomain = process.env.ANCHOR_DOMAIN || "testanchor.stellar.org";
11
+ const runMainnet = process.env.RUN_MAINNET || false;
12
+ const authKeySecret = process.env.AUTH_KEY_SECRET;
13
+ const clientDomain = process.env.CLIENT_DOMAIN;
14
+
15
+ let wallet: Wallet;
16
+ if (runMainnet === "true") {
17
+ console.log("Warning: you are running this script on the public network.");
18
+ wallet = walletSdk.Wallet.MainNet();
19
+ } else {
20
+ wallet = walletSdk.Wallet.TestNet();
21
+ }
22
+ const anchor = wallet.anchor({
23
+ homeDomain: anchorDomain,
24
+ });
25
+
26
+ const getSep10AuthToken = async () => {
27
+ const authKey = SigningKeypair.fromSecret(authKeySecret);
28
+ const sep10 = await anchor.sep10();
29
+ const signer = DefaultSigner;
30
+
31
+ const getAuthToken = async () => {
32
+ return sep10.authenticate({
33
+ accountKp: authKey,
34
+ walletSigner: signer,
35
+ clientDomain,
36
+ });
37
+ };
38
+
39
+ const authToken = await getAuthToken();
40
+
41
+ return authToken;
42
+ };
43
+
44
+ const authToken = getSep10AuthToken();
45
+ console.log(`Auth Token: ${authToken}`);
@@ -0,0 +1,18 @@
1
+ ACCOUNTS = [ "GBM53YM5CUICEOTGY3N2UJLLZ4QXNCAANINBNLHSNTEULBQ3HENOUU2J" ]
2
+ VERSION = "0.1.0"
3
+ SIGNING_KEY = "GBM53YM5CUICEOTGY3N2UJLLZ4QXNCAANINBNLHSNTEULBQ3HENOUU2J"
4
+ NETWORK_PASSPHRASE = "Test SDF Network ; September 2015"
5
+
6
+ [[PRINCIPALS]]
7
+ name = "user"
8
+ email = "user@stellar.org"
9
+ keybase = "user"
10
+ github = "https://www.github.com/user"
11
+
12
+ [DOCUMENTATION]
13
+ ORG_NAME = "Stellar Development Foundation"
14
+ ORG_URL = "https://stellar.org"
15
+ ORG_DESCRIPTION = "TS example backend server."
16
+ ORG_KEYBASE = "stellar.public"
17
+ ORG_TWITTER = "StellarOrg"
18
+ ORG_GITHUB = "stellar"
@@ -0,0 +1,2 @@
1
+ SECRET_KEY="S..."
2
+ ANCHOR_DOMAIN=testanchor.stellar.org
@@ -0,0 +1,25 @@
1
+ # Sep-12 examples for stellar typescript-wallet-sdk
2
+
3
+ ## Example code
4
+
5
+ To view how the wallet-sdk can be used to add sep12 KYC details, look at
6
+ `./sep12.ts`.
7
+
8
+ To run the script and interactively collect KYC details, configure the
9
+ appropriate environment variables and run -
10
+
11
+ ```
12
+ $ yarn example:sep12
13
+ ```
14
+
15
+ ## Changing environment variables
16
+
17
+ If you'd like to use different environment variable values than the default
18
+ ones, you can add a `.env` file. See `.env.example` as an example.
19
+
20
+ The environment variables you can set are:
21
+
22
+ | Variable Name | Description | Default Value |
23
+ | ------------- | ---------------------------------------------- | ---------------------- |
24
+ | ANCHOR_DOMAIN | The anchor domain for your application. | testanchor.stellar.org |
25
+ | SECRET_KEY | The secret key to use for sep10 authentication | |
@@ -0,0 +1,38 @@
1
+ import path from "path";
2
+
3
+ import * as dotenv from "dotenv";
4
+ import { SigningKeypair, walletSdk } from "../../src";
5
+ import { askQuestion } from "helpers/ask-question";
6
+
7
+ dotenv.config({ path: path.resolve(__dirname, ".env") });
8
+
9
+ const main = async () => {
10
+ const homeDomain = process.env.ANCHOR_DOMAIN || "testanchor.stellar.org";
11
+ const secretKey = process.env.SECRET_KEY;
12
+ if (!secretKey) {
13
+ throw new Error("No secret key provided");
14
+ }
15
+
16
+ const wallet = walletSdk.Wallet.TestNet();
17
+ const anchor = wallet.anchor({ homeDomain });
18
+
19
+ const authKey = SigningKeypair.fromSecret(secretKey);
20
+ const sep10 = await anchor.sep10();
21
+ const authToken = await sep10.authenticate({ accountKp: authKey });
22
+ const sep12 = await anchor.sep12(authToken);
23
+
24
+ const firstName = await askQuestion("What is your first name?");
25
+ const lastName = await askQuestion("What is your last name?");
26
+
27
+ const response = await sep12.add({
28
+ sep9Info: {
29
+ first_name: firstName,
30
+ last_name: lastName,
31
+ // ...
32
+ },
33
+ });
34
+
35
+ console.log(response.id);
36
+ };
37
+
38
+ main();
@@ -1,5 +1,4 @@
1
1
  import axios from "axios";
2
- import readline from "readline";
3
2
  import path from "path";
4
3
 
5
4
  import {
@@ -19,6 +18,7 @@ import {
19
18
  } from "@stellar/stellar-sdk";
20
19
 
21
20
  import * as dotenv from "dotenv";
21
+ import { askQuestion } from "helpers/ask-question";
22
22
  dotenv.config({ path: path.resolve(__dirname, ".env") });
23
23
 
24
24
  // Grabbing environment variables
@@ -237,18 +237,4 @@ walletSigner.signWithDomainAccount = async ({
237
237
  return Promise.resolve(transaction);
238
238
  };
239
239
 
240
- export const askQuestion = (query) => {
241
- const rl = readline.createInterface({
242
- input: process.stdin,
243
- output: process.stdout,
244
- });
245
-
246
- return new Promise((resolve) =>
247
- rl.question(query, (ans) => {
248
- rl.close();
249
- resolve(ans);
250
- }),
251
- );
252
- };
253
-
254
240
  runSep24();