Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.3.0 v2 #88

Merged
merged 21 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module.exports = {
ignorePatterns: ["lib/", "node_modules/", "docs/"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "examples/tsconfig.json", "test/tsconfig.json"],
sourceType: "module",
},
plugins: ["@typescript-eslint", "jsdoc"],
extends: [
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended",
"prettier",
],
rules: {
// Off
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-base-to-string": "off",

// Warn
"jsdoc/check-param-names": "warn",
"jsdoc/require-returns": "warn",
"jsdoc/require-returns-description": "warn",
"jsdoc/require-returns-type": "warn",
"jsdoc/require-param": "warn",
"jsdoc/check-types": "warn",
"jsdoc/require-param-description": "warn",
"jsdoc/require-param-name": "warn",
"jsdoc/require-param-type": "warn",
"jsdoc/require-property": "warn",
"jsdoc/require-property-description": "warn",
"jsdoc/require-property-name": "warn",
"jsdoc/require-property-type": "warn",
"jsdoc/check-property-names": "warn",
"jsdoc/empty-tags": "warn",

// Error
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/triple-slash-reference": [
"error",
{
path: "always",
types: "prefer-import",
lib: "always",
},
],
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
},
overrides: [
{
files: ["test/**", "examples/**"],
rules: {
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-explicit-any": "off",
},
},
],
};
19 changes: 19 additions & 0 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Recovery Signer Integration Test
on: [pull_request]
jobs:
test-ci:
name: integration test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Start docker
run: docker-compose -f test/docker/docker-compose.yml up -d
- uses: actions/setup-node@v2
with:
node-version: 18
- run: yarn install
- run: yarn build
- run: yarn test:integration:ci
- name: Print Docker Logs
if: always() # This ensures that the logs are printed even if the tests fail
run: docker-compose -f test/docker/docker-compose.yml logs
14 changes: 14 additions & 0 deletions .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Run Tests
on: [pull_request]
jobs:
test-ci:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18
- run: yarn install
- run: yarn build
- run: yarn test:ci
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
. "$(dirname -- "$0")/_/husky.sh"

yarn pretty-quick --staged
yarn lint-staged
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# 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)
# 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)

Typescript Wallet SDK is a library that allows developers to build wallet applications on the Stellar network faster. It
utilizes [Javascript Stellar SDK](https://github.com/stellar/js-stellar-sdk) to communicate with a Stellar Horizon server.
It offers wide range of functionality to simplify integration with the Stellar network, and connect to the anchors easily, utilizing
various Stellar protocols (SEPs)
Typescript Wallet SDK is a library that allows developers to build wallet
applications on the Stellar network faster. It utilizes
[Javascript Stellar SDK](https://github.com/stellar/js-stellar-sdk) to
communicate with a Stellar Horizon server.
It offers wide range of functionality to simplify integration with the Stellar
network, and connect to the anchors easily, utilizing various Stellar protocols
(SEPs)

## Dependency

The library is available via npm.
To import `typescript-wallet-sdk` library you need to add it as a dependency to your code:
The library is available via npm. To import `typescript-wallet-sdk` library you
need to add it as a dependency to your code:

yarn:

Expand All @@ -24,21 +27,25 @@ npm install @stellar/typescript-wallet-sdk

## Introduction

Here's a small example creating main wallet class with default configuration connected to testnet network:
Here's a small example creating main wallet class with default configuration
connected to testnet network:

```typescript
let wallet = walletSdk.Wallet.TestNet();
```

It should later be re-used across the code, as it has access to various useful children classes. For example, you can
authenticate with the `testanchor` as simple as:
It should later be re-used across the code, as it has access to various useful
children classes. For example, you can authenticate with the `testanchor` as
simple as:

```typescript
const authKey = SigningKeypair.fromSecret("my secret key");
const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
const sep10 = await anchor.sep10();

const authToken = await sep10.authenticate({accountKp: authKey});
const authToken = await sep10.authenticate({ accountKp: authKey });
```

Read [full wallet guide](https://developers.stellar.org/docs/category/build-a-wallet) for more info
Read
[full wallet guide](https://developers.stellar.org/docs/category/build-a-wallet-with-the-wallet-sdk)
for more info
4 changes: 4 additions & 0 deletions examples/sep24/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ANCHOR_DOMAIN=testanchor.stellar.org
ASSET_CODE=USDC
ASSET_ISSUER=GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5
RUN_MAINNET=false
17 changes: 17 additions & 0 deletions examples/sep24/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ example.
Progress will be logged in the terminal.

_note: the identity values used in the sep24 interactive portal can all be fake_

## Changing environment variables

If you'd like to use different environment variable values than the default
ones, you can add a `.env` file. See `.env.example` as an example.

The environment variables you can set are:

| Variable Name | Description | Default Value |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------- |
| ANCHOR_DOMAIN | The anchor domain for your application. | testanchor.stellar.org |
| ASSET_CODE | The code representing the asset. | USDC |
| ASSET_ISSUER | The issuer's public key for the asset. | GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 |
| 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 |
| RUN_MAINNET | Set to `true` to run the application on Mainnet. | false |
| CLIENT_DOMAIN | [SEP-10](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md) client domain used for authentication. | none |
| CLIENT_SECRET | Secret key for the client domain. Alternatively, you may want to implement your own `WalletSigner`. | none |
83 changes: 69 additions & 14 deletions examples/sep24/sep24.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
import axios from "axios";
import readline from "readline";
import path from "path";

import {
walletSdk,
Anchor,
SigningKeypair,
Types,
IssuedAssetId,
DefaultSigner,
} from "../../src";
import { Memo, MemoText } from "stellar-sdk";

const wallet = walletSdk.Wallet.TestNet();
import { Memo, MemoText, Transaction, TransactionBuilder } from "stellar-sdk";

import * as dotenv from "dotenv";
dotenv.config({ path: path.resolve(__dirname, ".env") });

// Grabbing environment variables

const anchorDomain = process.env.ANCHOR_DOMAIN || "testanchor.stellar.org";
const assetCode = process.env.ASSET_CODE || "USDC";
const assetIssuer =
process.env.ASSET_ISSUER ||
"GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
const runMainnet = process.env.RUN_MAINNET || false;
const sourceAccountSecret = process.env.SOURCE_ACCOUNT_SECRET;
const clientDomain = process.env.CLIENT_DOMAIN;
const clientSecret = process.env.CLIENT_SECRET;

// Running example

let wallet;
if (runMainnet === "true") {
console.log("Warning: you are running this script on the public network.");
wallet = walletSdk.Wallet.MainNet();
} else {
wallet = walletSdk.Wallet.TestNet();
}
const stellar = wallet.stellar();
const anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
const anchor = wallet.anchor({
homeDomain: anchorDomain,
});
const account = stellar.account();

let kp: SigningKeypair;

const asset = new IssuedAssetId(
"USDC",
"GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
);
const asset = new IssuedAssetId(assetCode, assetIssuer);

const runSep24 = async () => {
await createAccount();
await runDeposit(anchor, kp);
await runDepositWatcher(anchor);
runDepositWatcher(anchor);

while (!depositDone) {
await new Promise((resolve) => setTimeout(resolve, 1000));
Expand All @@ -37,11 +61,16 @@ const runSep24 = async () => {
}

await runWithdraw(anchor, kp);
await runWithdrawWatcher(anchor, kp);
runWithdrawWatcher(anchor, kp);
};

// Create Account
const createAccount = async () => {
if (sourceAccountSecret) {
kp = SigningKeypair.fromSecret(sourceAccountSecret);
return;
}

console.log("creating account ...");
kp = account.createKeypair();
console.log(`kp: \n${kp.publicKey}\n${kp.secretKey}`);
Expand All @@ -59,11 +88,15 @@ const createAccount = async () => {
};

// Create Deposit
let authToken: string;
let authToken: Types.AuthToken;
export const runDeposit = async (anchor: Anchor, kp: SigningKeypair) => {
console.log("\ncreating deposit ...");
const auth = await anchor.sep10();
authToken = await auth.authenticate({ accountKp: kp });
authToken = await auth.authenticate({
accountKp: kp,
clientDomain,
walletSigner,
});

const resp = await anchor.sep24().deposit({
assetCode: asset.code,
Expand All @@ -85,7 +118,7 @@ export let depositDone = false;
export const runDepositWatcher = (anchor: Anchor) => {
console.log("\nstarting watcher ...");

let stop: Types.WatcherStopFunction;
const stop: Types.WatcherStopFunction;
const onMessage = (m: Types.AnchorTransaction) => {
console.log({ m });
if (m.status === Types.TransactionStatus.completed) {
Expand Down Expand Up @@ -150,7 +183,7 @@ const sendWithdrawalTransaction = async (withdrawalTxn, kp) => {
export const runWithdrawWatcher = (anchor, kp) => {
console.log("\nstarting watcher ...");

let stop;
const stop;
const onMessage = (m) => {
console.log({ m });

Expand Down Expand Up @@ -182,6 +215,28 @@ export const runWithdrawWatcher = (anchor, kp) => {
stop = resp.stop;
};

const walletSigner = DefaultSigner;
walletSigner.signWithDomainAccount = async ({
transactionXDR,
networkPassphrase,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
accountKp,
}: Types.SignWithDomainAccountParams): Promise<Transaction> => {
if (!clientSecret) {
throw new Error("Client Secret missing from .env file");
}

const signer = SigningKeypair.fromSecret(clientSecret);

const transaction = TransactionBuilder.fromXDR(
transactionXDR,
networkPassphrase,
) as Transaction;
signer.sign(transaction);

return Promise.resolve(transaction);
};

export const askQuestion = (query) => {
const rl = readline.createInterface({
input: process.stdin,
Expand Down
10 changes: 10 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"esModuleInterop": true,
"baseUrl": "./",
"outDir": "lib",
"declaration": true,
"declarationDir": "lib"
},
"include": ["./"]
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
"^.+\\.(ts|tsx)?$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest",
},
testPathIgnorePatterns: ["/node_modules/", "integration.test.ts"],
};
9 changes: 9 additions & 0 deletions jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
rootDir: "./",
preset: "ts-jest",
transform: {
"^.+\\.(ts|tsx)?$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest",
},
testMatch: ["**/*integration.test.ts"],
};
Loading
Loading