Skip to content

Commit

Permalink
Release/1.3.0 v2 (#88)
Browse files Browse the repository at this point in the history
* add type aliases, and make sep24 example use env vars (#66)

* add type aliases

* make example use env vars

* Account setup and recovery using SEP-30 (#65)

* Add AccountRecover class

* Add Recovery class

* Add builderExtra param

* Fix importing

* Swallow 404 error on registerRecoveryServerSigners function

* Remove todo comment

* Use plural

* Add basic testing

* increase timeout

* Move private functions to the bottom

* Make AccountRecover abstract

* Rename type to WalletRecoveryServers

* add Customer / SEP-12 code (#71)

* add type aliases

* make example use env vars

* finish tests

* add types

* cleanup

* comment update

* use getCustomer

* jsdoc

* for binary data

* clean up

* cleanup

* use sep9BinaryInfo

* cleanup

* add gha and linting (#72)

* add type aliases

* make example use env vars

* finish tests

* add types

* cleanup

* add gha

* clean up all files

* add prettier lint

* sep12 stuff linting

* cleanup

* move to devdeps

* add jsdocs to all major functions (#73)

* add type aliases

* make example use env vars

* finish tests

* add types

* cleanup

* add gha

* clean up all files

* add prettier lint

* sep12 stuff linting

* cleanup

* add for all classes

* more comments

* more fixes

* more changes

* cleanup

* small fixes to Recovery code (#75)

* small fixes

* fix path payment test

* add sep6 get info (#76)

* add SEP6 deposit and withdrawal (#77)

* add sep6 deposit and withdrawal

* comment

* make better response

* remove wrapper type

* add exchange endpoints (#78)

* adding recovery integration tests (#74)

* first cut

* try workflow

* run daemon

* print logs

* restart on failure

* try this

* try

* try

* try

* try

* cross fingers

* fix

* works hopefully

* fix

* add back

* cleanup

* image versions and readme

* add watcher and polling to sep6 (#79)

* upgrade stellar-sdk to v11.0.0-beta.6 (#80)

* add authToken class (#81)

* add authToken class

* make account optional

* cleanup

* remove un-needed account

* adding some helper methods (#82)

* account merge and premade assets (#83)

* add sep38 info, price, and prices (#84)

* sep38 getinfo

* add prices info, cleanup

* move authToken to optional arg

* add jsdoc

* throw if both buy and sell amount given

* add sep38 quote (#85)

* sep38 getinfo

* add prices info, cleanup

* first cut

* move authToken to optional arg

* cleanup

* add jsdoc

* throw if both buy and sell amount given

* make context type right (#86)

* fix test

* bumping package version

---------

Co-authored-by: Alec Charbonneau <[email protected]>
Co-authored-by: Cássio Marcos Goulart <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2024
1 parent b852646 commit dd4b52a
Show file tree
Hide file tree
Showing 59 changed files with 4,388 additions and 397 deletions.
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

0 comments on commit dd4b52a

Please sign in to comment.