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

DRAFT: Merge the Soroban client into this package #857

Closed
wants to merge 14 commits into from
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
env: {
es6: true,
es6: true
},
extends: ["airbnb-base", "prettier"],
plugins: ["@babel", "prettier", "prefer-import"],
parser: "@babel/eslint-parser",
extends: ['airbnb-base', 'prettier'],
plugins: ['@babel', 'prettier', 'prefer-import'],
parser: '@babel/eslint-parser',
rules: {
"node/no-unpublished-require": 0,
},
'node/no-unpublished-require': 0
}
};
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ This release introduces breaking changes from `stellar-base`. It adds **uncondit

### Updates

- Updates the following SEP-10 utility functions to include [client domain verification](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md#verifying-the-client-domain) functionality ([#720](https://github.com/stellar/js-stellar-sdk/pull/720)):
- Updates the following SEP-10 utility functions to include [client domain verification](https://stellar.org/protocol/sep-10.md#verifying-the-client-domain) functionality ([#720](https://github.com/stellar/js-stellar-sdk/pull/720)):
- `Utils.buildChallengeTx()` accepts the `clientDomain` and `clientSigningKey` optional parameters
- `Utils.readChallengeTx()` parses challenge transactions containing a `client_domain` ManageData operation
- `Utils.verifyChallengeTxSigners()` verifies an additional signature from the `clientSigningKey` keypair if a `client_domain` Manage Data operation is included in the challenge
Expand Down Expand Up @@ -634,7 +634,7 @@ The following enum values were rename in `OperationType`:

If the transaction includes a memo, then memo required checking is skipped.

See [SEP0029](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0029.md) for more information about memo required check.
See [SEP0029](https://stellar.org/protocol/sep-29.md) for more information about memo required check.

## [v4.0.2](https://github.com/stellar/js-stellar-sdk/compare/v4.0.1...v4.0.2)

Expand Down
5 changes: 3 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"@babel/typescript"
],
"targets": {
"browsers": [ "> 2%" ] // target modern browsers and ES6
"node": 16,
"browsers": [ "> 2%" ] // target modern browsers and ES6
},
"env": {
"development": {
Expand All @@ -14,7 +15,7 @@
"production": {
"comments": false,
"targets": {
"node": 16,
// larger feature set for prod bundle
"browsers": [
"> 2%",
"ie 11",
Expand Down
65 changes: 32 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"name": "stellar-sdk",
"version": "11.0.0-beta.1",
"description": "A library for working with the Stellar Horizon server.",
"keywords": [
"stellar"
],
"keywords": [ "stellar", "soroban", "horizon" ],
"homepage": "https://github.com/stellar/js-stellar-sdk",
"bugs": {
"url": "https://github.com/stellar/js-stellar-sdk/issues"
Expand All @@ -17,7 +15,7 @@
"author": "Stellar Development Foundation <[email protected]>",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"browser": "./dist/stellar-sdk.js",
"browser": "./dist/stellar-sdk.min.js",
"files": [
"/types",
"/lib",
Expand All @@ -32,17 +30,17 @@
"build:docs": "cross-env NODE_ENV=docs yarn _babel",
"clean": "rm -rf lib/ dist/ coverage/ .nyc_output/ jsdoc/",
"docs": "yarn build:docs && jsdoc -c ./config/.jsdoc.json --verbose",
"test": "yarn test:node && yarn test:integration && yarn test:browser",
"test:node": "yarn _nyc mocha --recursive 'test/unit/**/*.js'",
"test:integration": "yarn _nyc mocha --recursive 'test/integration/**/*.js'",
"test": "yarn build && yarn test:node && yarn test:integration && yarn test:browser",
"test:node": "yarn _nyc 'test/unit/**/*.js'",
"test:integration": "yarn _nyc 'test/integration/**/*.js'",
"test:browser": "karma start config/karma.conf.js",
"fmt": "yarn eslint -c .eslintrc.js src/ --fix && yarn _prettier",
"preversion": "yarn clean && yarn fmt && yarn build:prod && yarn test",
"prepare": "yarn build:prod",
"_build": "yarn build:node && yarn build:browser",
"_babel": "babel --extensions '.ts' --out-dir lib/ src/",
"_nyc": "nyc --nycrc-path config/.nycrc",
"_prettier": "prettier --ignore-path config/.prettierignore --write './**/*.js'"
"_nyc": "nyc --nycrc-path config/.nycrc mocha --recursive",
"_prettier": "prettier --config config/prettier.config.js --ignore-path config/.prettierignore --write './**/*.js'"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -76,43 +74,42 @@
]
},
"devDependencies": {
"@babel/cli": "^7.22.6",
"@babel/core": "^7.22.8",
"@babel/eslint-parser": "^7.22.7",
"@babel/eslint-plugin": "^7.19.1",
"@babel/preset-env": "^7.22.7",
"@babel/preset-typescript": "^7.21.4",
"@babel/register": "^7.21.0",
"@definitelytyped/dtslint": "^0.0.163",
"@babel/cli": "^7.22.9",
"@babel/core": "^7.22.9",
"@babel/eslint-parser": "^7.22.9",
"@babel/eslint-plugin": "^7.22.5",
"@babel/preset-env": "^7.22.9",
"@babel/preset-typescript": "^7.22.5",
"@babel/register": "^7.22.5",
"@definitelytyped/dtslint": "^0.0.165",
"@istanbuljs/nyc-config-babel": "3.0.0",
"@stellar/tsconfig": "^1.0.2",
"@types/detect-node": "^2.0.0",
"@types/eventsource": "^1.1.2",
"@types/lodash": "^4.14.192",
"@types/node": "^20.4.1",
"@types/lodash": "^4.14.196",
"@types/node": "^20.4.2",
"@types/randombytes": "^2.0.0",
"@types/urijs": "^1.19.6",
"@typescript-eslint/parser": "^5.59.7",
"@typescript-eslint/parser": "^6.2.1",
"axios-mock-adapter": "^1.21.5",
"babel-loader": "^9.1.3",
"babel-loader": "^9.1.2",
"babel-plugin-istanbul": "^6.1.1",
"buffer": "^6.0.3",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai-http": "^4.3.0",
"chai-http": "^4.4.0",
"cross-env": "^7.0.3",
"eslint": "^8.44.0",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.25.2",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-import": "^0.0.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-webpack-plugin": "^4.0.1",
"ghooks": "^2.0.4",
"husky": "^8.0.3",
"jsdoc": "^4.0.2",
"karma": "^6.4.1",
"karma": "^6.4.2",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.2.1",
Expand All @@ -126,24 +123,26 @@
"mocha": "^10.2.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"nyc": "^15.1.0",
"prettier": "^2.8.7",
"prettier": "^3.0.1",
"randombytes": "^2.1.0",
"sinon": "^15.2.0",
"sinon-chai": "^3.7.0",
"taffydb": "^2.7.3",
"terser-webpack-plugin": "^5.3.9",
"terser-webpack-plugin": "^5.3.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"utility-types": "^3.7.0",
"webpack": "^5.88.1",
"webpack-cli": "^5.0.1"
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"buffer": "^6.0.3",
"detect-node": "^2.0.4",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"stellar-base": "^9.0.0",
"stellar-base": "10.0.0-soroban.5",
"toml": "^3.0.0",
"urijs": "^1.19.1"
}
Expand Down
50 changes: 25 additions & 25 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
module.exports = {
env: {
es6: true,
es6: true
},
rules: {
// OFF
"import/prefer-default-export": 0,
"node/no-unsupported-features/es-syntax": 0,
"node/no-unsupported-features/es-builtins": 0,
'import/prefer-default-export': 0,
'node/no-unsupported-features/es-syntax': 0,
'node/no-unsupported-features/es-builtins': 0,
camelcase: 0,
"class-methods-use-this": 0,
"linebreak-style": 0,
"new-cap": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"prefer-destructuring": 0,
"lines-between-class-members": 0,
'class-methods-use-this': 0,
'linebreak-style': 0,
'new-cap': 0,
'no-param-reassign': 0,
'no-underscore-dangle': 0,
'no-use-before-define': 0,
'prefer-destructuring': 0,
'lines-between-class-members': 0,

// WARN
"prefer-import/prefer-import-over-require": [1],
"no-console": ["warn", { allow: ["assert"] }],
"no-debugger": 1,
"no-unused-vars": 1,
"arrow-body-style": 1,
"valid-jsdoc": [
'prefer-import/prefer-import-over-require': [1],
'no-console': ['warn', { allow: ['assert'] }],
'no-debugger': 1,
'no-unused-vars': 1,
'arrow-body-style': 1,
'valid-jsdoc': [
1,
{
requireReturnDescription: false,
},
requireReturnDescription: false
}
],
"prefer-const": 1,
"object-shorthand": 1,
"require-await": 1,
'prefer-const': 1,
'object-shorthand': 1,
'require-await': 1,

// ERROR
"no-unused-expressions": [2, { allowTaggedTemplates: true }],
},
'no-unused-expressions': [2, { allowTaggedTemplates: true }]
}
};
12 changes: 6 additions & 6 deletions src/horizon_axios_client.ts → src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosResponse } from "axios";
import URI from "urijs";

/* tslint:disable-next-line:no-var-requires */
const version = require("../package.json").version;
export const version = require("../package.json").version;

export interface ServerTime {
serverTime: number;
Expand All @@ -23,7 +23,7 @@ export interface ServerTime {
*/
export const SERVER_TIME_MAP: Record<string, ServerTime> = {};

const HorizonAxiosClient = axios.create({
const AxiosClient = axios.create({
headers: {
"X-Client-Name": "js-stellar-sdk",
"X-Client-Version": version,
Expand All @@ -34,8 +34,8 @@ function _toSeconds(ms: number): number {
return Math.floor(ms / 1000);
}

HorizonAxiosClient.interceptors.response.use(
function interceptorHorizonResponse(response: AxiosResponse) {
AxiosClient.interceptors.response.use(
(response: AxiosResponse) => {
const hostname = URI(response.config.url!).hostname();
const serverTime = _toSeconds(Date.parse(response.headers.date));
const localTimeRecorded = _toSeconds(new Date().getTime());
Expand All @@ -48,10 +48,10 @@ HorizonAxiosClient.interceptors.response.use(
}

return response;
},
}
);

export default HorizonAxiosClient;
export default AxiosClient;

/**
* Given a hostname, get the current time of that server (i.e., use the last-
Expand Down
8 changes: 5 additions & 3 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* tslint:disable:no-var-requires */

export * from "./index";
export * as StellarBase from "stellar-base";
export * from './index';
export * as StellarBase from 'stellar-base';
export * as SorobanClient from './soroban';
export * from './horizon';

import axios from "axios"; // idk why axios is weird
import axios from 'axios'; // idk why axios is weird
export { axios };

export default module.exports;
4 changes: 2 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Horizon } from "./horizon_api";
import { Horizon } from "./horizon/horizon_api";

// For ES5 compatibility (https://stackoverflow.com/a/55066280).
/* tslint:disable:variable-name max-classes-per-file */
Expand Down Expand Up @@ -70,7 +70,7 @@ export class InvalidSep10ChallengeError extends Error {
/**
* AccountRequiresMemoError is raised when a transaction is trying to submit an
* operation to an account which requires a memo. See
* [SEP0029](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0029.md)
* [SEP0029](https://stellar.org/protocol/sep-29.md)
* for more information.
*
* This error contains two attributes to help you identify the account requiring
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Asset } from "stellar-base";

import { CallBuilder } from "./call_builder";
import { ServerApi } from "./server_api";

Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions src/call_builder.ts → src/horizon/call_builder.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import URI from "urijs";
import URITemplate from "urijs/src/URITemplate";

import { BadRequestError, NetworkError, NotFoundError } from "./errors";
import { BadRequestError, NetworkError, NotFoundError } from "../errors";
import { Horizon } from "./horizon_api";
import HorizonAxiosClient from "./horizon_axios_client";
import AxiosClient, { version } from "../axios";
import { ServerApi } from "./server_api";

/* tslint:disable-next-line:no-var-requires */
const version = require("../package.json").version;

// Resources which can be included in the Horizon response via the `join`
// query-param.
const JOINABLE = ["transaction"];
Expand Down Expand Up @@ -344,7 +341,7 @@ export class CallBuilder<
url = url.protocol(this.url.protocol());
}

return HorizonAxiosClient.get(url.toString())
return AxiosClient.get(url.toString())
.then((response) => response.data)
.catch(this._handleNetworkError);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions src/horizon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// tslint:disable-next-line: no-reference
/// <reference path="../../types/dom-monkeypatch.d.ts" />

// Expose all types
export * from './horizon_api';
export * from './server_api';

// stellar-sdk classes to expose
export * from './account_response';
export { Server } from './server';

export default module.exports;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading