Skip to content

Commit

Permalink
add backend server for sep-10 client attribution
Browse files Browse the repository at this point in the history
  • Loading branch information
stfung77 committed Dec 6, 2021
1 parent 54493d3 commit c0fc908
Show file tree
Hide file tree
Showing 22 changed files with 482 additions and 188 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
/packages/*/.env
/packages/*/.env.local
/packages/*/.env.development.local
/packages/*/.env.test.local
/packages/*/.env.production.local

npm-debug.log*
yarn-debug.log*
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,28 @@ To start building with this project clone this repo and install the deps:
yarn install
```

create a **.env** file in *packages/demo-wallet-client* with the **REACT_APP_CLIENT_DOMAIN**
(where stellar.toml is hosted) and the wallet backend **REACT_APP_WALLET_BACKEND_ENDPOINT**

NOTE: if using a locally running test anchor (in docker) use *docker.for.mac.host.internal*,
this will allow the anchor thats running in a docker container to access the host network where

This comment has been minimized.

Copy link
@quietbits

quietbits Dec 6, 2021

Contributor

Typo in thats

the client domain (server hosting the stellar.toml) is running.
ex:
```
REACT_APP_CLIENT_DOMAIN = docker.for.mac.host.internal:7000
REACT_APP_WALLET_BACKEND_ENDPOINT = http://demo-wallet-server.stellar.org
```

and run:

```bash
yarn start
yarn start:client
```

To build the app for production, run:

```bash
yarn build
yarn build:client
```

---
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"build:client": "yarn workspace demo-wallet-client build",
"build:shared": "yarn workspace demo-wallet-shared build",
"build:server": "yarn workspace demo-wallet-server build",
"build": "run-s build:shared build:client",
"start:client": "yarn workspace demo-wallet-client start",
"start:shared": "yarn workspace demo-wallet-shared start",
Expand All @@ -14,6 +15,7 @@
},
"dependencies": {
"demo-wallet-shared": "^1.0.0",
"npm-run-all": "^4.1.5"
"npm-run-all": "^4.1.5",
"stellar-sdk": "^9.1.0"
}
}
4 changes: 3 additions & 1 deletion packages/demo-wallet-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"bignumber.js": "^9.0.1",
"crypto": "^1.0.1",
"dompurify": "^2.3.3",
"env-cmd": "^10.1.0",
"find-config": "^1.0.0",
"html-react-parser": "^1.4.0",
"lodash": "^4.17.21",
"marked": "^3.0.4",
Expand All @@ -39,7 +41,7 @@
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"redux": "^4.1.1",
"stellar-sdk": "^9.0.0-beta.1",
"stellar-sdk": "^9.1.0",
"styled-components": "^5.3.1",
"toml": "^3.0.0",
"tslib": "^2.3.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/demo-wallet-client/src/config/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ export const store = configureStore({
}),
],
});

export const walletBackendEndpoint: string = process.env.REACT_APP_WALLET_BACKEND_ENDPOINT ?? "";
export const clientDomain: string = process.env.REACT_APP_CLIENT_DOMAIN ?? "";
6 changes: 4 additions & 2 deletions packages/demo-wallet-client/src/ducks/sep24DepositAsset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { RootState } from "config/store";
import { RootState, walletBackendEndpoint, clientDomain } from "config/store";
import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
Expand Down Expand Up @@ -102,13 +102,15 @@ export const depositAssetAction = createAsyncThunk<
serverSigningKey: tomlResponse.SIGNING_KEY,
publicKey,
homeDomain,
clientDomain,
});

// SEP-10 sign
const signedChallengeTransaction = sep10AuthSign({
const signedChallengeTransaction = await sep10AuthSign({
secretKey,
networkPassphrase: networkConfig.network,
challengeTransaction,
walletBackendEndpoint,
});

// SEP-10 send
Expand Down
6 changes: 4 additions & 2 deletions packages/demo-wallet-client/src/ducks/sep24WithdrawAsset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { RootState } from "config/store";
import { RootState, walletBackendEndpoint, clientDomain } from "config/store";
import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
Expand Down Expand Up @@ -81,13 +81,15 @@ export const withdrawAssetAction = createAsyncThunk<
serverSigningKey: tomlResponse.SIGNING_KEY,
publicKey,
homeDomain,
clientDomain,
});

// SEP-10 sign
const signedChallengeTransaction = sep10AuthSign({
const signedChallengeTransaction = await sep10AuthSign({
secretKey,
networkPassphrase: networkConfig.network,
challengeTransaction,
walletBackendEndpoint,
});

// SEP-10 send
Expand Down
6 changes: 4 additions & 2 deletions packages/demo-wallet-client/src/ducks/sep31Send.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { RootState } from "config/store";
import { RootState, walletBackendEndpoint, clientDomain } from "config/store";
import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
Expand Down Expand Up @@ -214,13 +214,15 @@ export const fetchSendFieldsAction = createAsyncThunk<
serverSigningKey,
publicKey,
homeDomain,
clientDomain,
});

// SEP-10 sign
const signedChallengeTransaction = sep10AuthSign({
const signedChallengeTransaction = await sep10AuthSign({
secretKey,
networkPassphrase: networkConfig.network,
challengeTransaction,
walletBackendEndpoint,
});

// SEP-10 send
Expand Down
7 changes: 5 additions & 2 deletions packages/demo-wallet-client/src/ducks/sep6DepositAsset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { RootState } from "config/store";
import { RootState, walletBackendEndpoint, clientDomain } from "config/store";
import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
Expand Down Expand Up @@ -116,19 +116,22 @@ export const initiateDepositAction = createAsyncThunk<
title:
"SEP-6 deposit is enabled, and requires authentication so we should go through SEP-10",
});

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint: webAuthTomlResponse.WEB_AUTH_ENDPOINT,
serverSigningKey: webAuthTomlResponse.SIGNING_KEY,
publicKey,
homeDomain,
clientDomain,
});

// SEP-10 sign
const signedChallengeTransaction = sep10AuthSign({
const signedChallengeTransaction = await sep10AuthSign({
secretKey,
networkPassphrase: networkConfig.network,
challengeTransaction,
walletBackendEndpoint,
});

// SEP-10 send
Expand Down
7 changes: 5 additions & 2 deletions packages/demo-wallet-client/src/ducks/sep6WithdrawAsset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { RootState } from "config/store";
import { RootState, walletBackendEndpoint, clientDomain } from "config/store";
import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
Expand Down Expand Up @@ -111,19 +111,22 @@ export const initiateWithdrawAction = createAsyncThunk<
title:
"SEP-6 withdrawal is enabled, and requires authentication so we should go through SEP-10",
});

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint: webAuthTomlResponse.WEB_AUTH_ENDPOINT,
serverSigningKey: webAuthTomlResponse.SIGNING_KEY,
publicKey,
homeDomain,
clientDomain,
});

// SEP-10 sign
const signedChallengeTransaction = sep10AuthSign({
const signedChallengeTransaction = await sep10AuthSign({
secretKey,
networkPassphrase: networkConfig.network,
challengeTransaction,
walletBackendEndpoint,
});

// SEP-10 send
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-client/src/ducks/sep8Send.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Horizon } from "stellar-sdk";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { RootState } from "config/store";
import { RootState} from "config/store";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getErrorString } from "demo-wallet-shared/build/helpers/getErrorString";
Expand Down
35 changes: 35 additions & 0 deletions packages/demo-wallet-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Stellar Demo Wallet Server

This Stellar Demo Wallet is the backend to the demo wallet, currently it is only used to host
the stellar.toml file and also sign requests to enable ([SEP-10]) client attribution. During
the signing phase of the SEP-10 flow, the wallet client will make a request to the backend server
to have the backend server sign the challenge that was issued by the anchor server. The wallet client
will then sign the same request with the user's key before sending the challenge back to the anchor
server for verification.


### Running the Demo Wallet Server
1. Create a keypair on the Stellar network (you can use the demo wallet for this).
Thekeypair will be used for the Demo Wallet Server

This comment has been minimized.

Copy link
@quietbits

quietbits Dec 6, 2021

Contributor

Typo Thekeypair

2. Create a .env file in the package/demo-wallet-server directory.
```
SERVER_PORT = 7000
SERVER_SIGNING_KEY = <private signing key generated in step 1>
```
3. Modify the *stellar.toml* file in *package/demo-wallet-server/src/static/well_known*
Replace the **SIGNING_KEY** with the public key that was generated in step 1
4. Run the server
```
yarn start:server
```

### Helpful links

- [https://www.stellar.org/developers](https://www.stellar.org/developers)
- [https://stellar.github.io/js-stellar-sdk/](https://stellar.github.io/js-stellar-sdk/)
- [https://github.com/stellar/js-stellar-sdk](https://github.com/stellar/js-stellar-sdk)

[sep-10]:
https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md


Loading

0 comments on commit c0fc908

Please sign in to comment.