@stellar/stellar-sdk 11.0.1 → 11.2.0

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 (37) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +158 -139
  3. package/dist/stellar-sdk.js +865 -376
  4. package/dist/stellar-sdk.min.js +1 -1
  5. package/lib/config.js +2 -2
  6. package/lib/contract_spec.d.ts +22 -1
  7. package/lib/contract_spec.js +684 -187
  8. package/lib/errors.js +11 -16
  9. package/lib/federation/server.js +2 -2
  10. package/lib/horizon/account_call_builder.js +7 -8
  11. package/lib/horizon/account_response.js +2 -2
  12. package/lib/horizon/assets_call_builder.js +7 -8
  13. package/lib/horizon/call_builder.js +2 -2
  14. package/lib/horizon/claimable_balances_call_builder.js +7 -8
  15. package/lib/horizon/effect_call_builder.js +7 -8
  16. package/lib/horizon/friendbot_builder.js +7 -8
  17. package/lib/horizon/ledger_call_builder.js +7 -8
  18. package/lib/horizon/liquidity_pool_call_builder.js +7 -8
  19. package/lib/horizon/offer_call_builder.js +7 -8
  20. package/lib/horizon/operation_call_builder.js +7 -8
  21. package/lib/horizon/orderbook_call_builder.js +7 -8
  22. package/lib/horizon/path_call_builder.js +7 -8
  23. package/lib/horizon/payment_call_builder.js +7 -8
  24. package/lib/horizon/server.js +2 -2
  25. package/lib/horizon/strict_receive_path_call_builder.js +7 -8
  26. package/lib/horizon/strict_send_path_call_builder.js +7 -8
  27. package/lib/horizon/trade_aggregation_call_builder.js +7 -8
  28. package/lib/horizon/trades_call_builder.js +7 -8
  29. package/lib/horizon/transaction_call_builder.js +7 -8
  30. package/lib/soroban/api.d.ts +8 -1
  31. package/lib/soroban/parsers.js +12 -6
  32. package/lib/soroban/server.d.ts +6 -2
  33. package/lib/soroban/server.js +18 -12
  34. package/lib/stellartoml/index.js +2 -2
  35. package/lib/utils.js +2 -2
  36. package/lib/webauth/errors.js +7 -8
  37. package/package.json +17 -15
package/CHANGELOG.md CHANGED
@@ -1,8 +1,32 @@
1
+
1
2
  # Changelog
2
3
 
3
4
  A breaking change will get clearly marked in this log.
4
5
 
5
6
 
7
+ ## Unreleased
8
+
9
+
10
+ ## [v11.2.0](https://github.com/stellar/js-stellar-sdk/compare/v11.1.0...v11.2.0)
11
+
12
+ ### Added
13
+ * Support for the new, optional `diagnosticEventsXdr` field on the `SorobanRpc.Server.sendTransaction` method. The raw field will be present when using the `_sendTransaction` method, while the normal method will have an already-parsed `diagnosticEvents: xdr.DiagnosticEvent[]` field, instead ([#905](https://github.com/stellar/js-stellar-sdk/pull/905)).
14
+ * A new exported interface `SorobanRpc.Api.EventResponse` so that developers can type-check individual events ([#904](https://github.com/stellar/js-stellar-sdk/pull/904)).
15
+
16
+ ### Updated
17
+ * Dependencies have been updated to their latest versions ([#906](https://github.com/stellar/js-stellar-sdk/pull/906), [#908](https://github.com/stellar/js-stellar-sdk/pull/908)).
18
+
19
+
20
+ ## [v11.1.0](https://github.com/stellar/js-stellar-sdk/compare/v11.0.1...v11.1.0)
21
+
22
+ ### Added
23
+ * `SorobanRpc.Server.simulateTransaction` now supports an optional `addlResources` parameter to allow users to specify additional resources that they want to include in a simulation ([#896](https://github.com/stellar/js-stellar-sdk/pull/896)).
24
+ * `ContractSpec` now has a `jsonSchema()` method to generate a [JSON Schema](https://json-schema.org/) for a particular contract specification ([#889](https://github.com/stellar/js-stellar-sdk/pull/889)).
25
+
26
+ ### Fixed
27
+ * All dependencies have been updated to their latest versions, including `stellar-base` to [v10.0.1](https://github.com/stellar/js-stellar-base/releases/tag/v10.0.1) which included a small patch ([#897](https://github.com/stellar/js-stellar-sdk/pull/897)).
28
+
29
+
6
30
  ## [v11.0.1](https://github.com/stellar/js-stellar-sdk/compare/v10.2.1...v11.0.0)
7
31
 
8
32
  ### Fixed
package/README.md CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  <div align="center">
2
3
  <img alt="Stellar" src="https://github.com/stellar/.github/raw/master/stellar-logo.png" width="558" />
3
4
  <br/>
@@ -13,162 +14,89 @@
13
14
  <a href="https://github.com/stellar/js-stellar-sdk/actions/workflows/tests.yml"><img alt="Test Status" src="https://github.com/stellar/js-stellar-sdk/actions/workflows/tests.yml/badge.svg" /></a>
14
15
  </p>
15
16
 
16
- js-stellar-sdk is a Javascript library for communicating with a
17
- [Stellar Horizon server](https://github.com/stellar/go/tree/master/services/horizon).
18
- It is used for building Stellar apps either on Node.js or in the browser.
17
+ js-stellar-sdk is a JavaScript library for communicating with a
18
+ [Stellar Horizon server](https://github.com/stellar/go/tree/master/services/horizon) and [Soroban RPC](https://soroban.stellar.org/docs/reference/rpc).
19
+ It is used for building Stellar apps either on Node.js or in the browser, though it can be used in other environments with some tinkering.
19
20
 
20
21
  It provides:
21
22
 
22
- - a networking layer API for Horizon endpoints.
23
+ - a networking layer API for Horizon endpoints (REST-based),
24
+ - a networking layer for Soroban RPC (JSONRPC-based).
23
25
  - facilities for building and signing transactions, for communicating with a
24
26
  Stellar Horizon instance, and for submitting transactions or querying network
25
27
  history.
26
28
 
27
- ### stellar-sdk vs stellar-base
28
-
29
- stellar-sdk is a high-level library that serves as client-side API for Horizon.
30
- [stellar-base](https://github.com/stellar/js-stellar-base) is lower-level
31
- library for creating Stellar primitive constructs via XDR helpers and wrappers.
32
-
33
- **Most people will want stellar-sdk instead of stellar-base.** You should only
34
- use stellar-base if you know what you're doing!
35
-
36
- If you add `stellar-sdk` to a project, **do not add `stellar-base`!** Mis-matching
37
- versions could cause weird, hard-to-find bugs. `stellar-sdk` automatically
38
- installs `stellar-base` and exposes all of its exports in case you need them.
39
-
40
- > **Important!** The Node.js version of the `stellar-base` (`stellar-sdk` dependency) package
41
- > uses the [`sodium-native`](https://www.npmjs.com/package/sodium-native) package as
42
- > an [optional dependency](https://docs.npmjs.com/files/package.json#optionaldependencies). `sodium-native` is
43
- > a low level binding to [libsodium](https://github.com/jedisct1/libsodium),
44
- > (an implementation of [Ed25519](https://ed25519.cr.yp.to/) signatures).
45
- > If installation of `sodium-native` fails, or it is unavailable, `stellar-base` (and `stellar-sdk`) will
46
- > fallback to using the [`tweetnacl`](https://www.npmjs.com/package/tweetnacl) package implementation.
47
- >
48
- > If you are using `stellar-sdk`/`stellar-base` in a browser you can ignore
49
- > this. However, for production backend deployments you should be
50
- > using `sodium-native`. If `sodium-native` is successfully installed and working the
51
- > `StellarSdk.FastSigning` variable will return `true`.
52
-
53
- ## Quick start
54
-
55
- Using npm to include js-stellar-sdk in your own project:
56
-
57
- ```shell
58
- npm install --save stellar-sdk
59
- ```
60
-
61
- Alternatively, you can use cdnjs in a browser:
62
-
63
- ```html
64
- <script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.js"></script>
65
- ````
29
+ **Jump to:**
66
30
 
67
- ## Install
31
+ * [Installation](#installation): details on hitting the ground running
32
+ * [Usage](#usage): links to documentation and a variety of workarounds for non-traditional JavaScript environments
33
+ - [...with React Native](#usage-with-react-native)
34
+ - [...with Expo](#usage-with-expo-managed-workflows)
35
+ - [...with CloudFlare Workers](#usage-with-cloudflare-workers)
36
+ * [Developing](#developing): contribute to the project!
37
+ * [Understanding `stellar-sdk` vs. `stellar-base`](#stellar-sdk-vs-stellar-base)
38
+ * [License](#license)
68
39
 
69
- ### To use as a module in a Node.js project
40
+ ## Installation
70
41
 
71
- 1. Install it using npm:
42
+ Using npm or yarn to include `stellar-sdk` in your own project:
72
43
 
73
44
  ```shell
74
- npm install --save stellar-sdk
45
+ npm install --save @stellar/stellar-sdk
46
+ # or
47
+ yarn add @stellar/stellar-sdk
75
48
  ```
76
49
 
77
- 2. require/import it in your JavaScript:
50
+ Then, require or import it in your JavaScript code:
78
51
 
79
52
  ```js
80
- var StellarSdk = require('stellar-sdk');
53
+ var StellarSdk = require('@stellar/stellar-sdk');
54
+ // or
55
+ import * as StellarSdk from '@stellar/stellar-sdk';
81
56
  ```
82
57
 
83
- ### To self host for use in the browser
84
-
85
- 1. Install it using [bower](http://bower.io):
58
+ (Preferably, you would only import the pieces you need to enable tree-shaking and lower your final bundle sizes.)
86
59
 
87
- ```shell
88
- bower install stellar-sdk
89
- ```
60
+ ### Browsers
90
61
 
91
- 2. Include it in the browser:
62
+ You can use a CDN:
92
63
 
93
64
  ```html
94
- <script src="./bower_components/stellar-sdk/stellar-sdk.js"></script>
95
- <script>
96
- console.log(StellarSdk);
97
- </script>
65
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.js"></script>
98
66
  ```
99
67
 
100
- If you don't want to use or install Bower, you can copy built JS files from the
101
- [bower-js-stellar-sdk repo](https://github.com/stellar/bower-js-stellar-sdk).
68
+ Note that this method relies using a third party to host the JS library. This may not be entirely secure. You can self-host it via [Bower](http://bower.io):
102
69
 
103
- ### To use the [cdnjs](https://cdnjs.com/libraries/stellar-sdk) hosted script in the browser
70
+ ```shell
71
+ bower install @stellar/stellar-sdk
72
+ ```
104
73
 
105
- 1. Instruct the browser to fetch the library from
106
- [cdnjs](https://cdnjs.com/libraries/stellar-sdk), a 3rd party service that
107
- hosts js libraries:
74
+ and include it in the browser:
108
75
 
109
76
  ```html
110
- <script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.js"></script>
77
+ <script src="./bower_components/stellar-sdk/stellar-sdk.js"></script>
111
78
  <script>
112
79
  console.log(StellarSdk);
113
80
  </script>
114
81
  ```
115
82
 
116
- Note that this method relies using a third party to host the JS library. This
117
- may not be entirely secure.
118
-
119
- Make sure that you are using the latest version number. They can be found on the
120
- [releases page in Github](https://github.com/stellar/js-stellar-sdk/releases).
121
-
122
- ### To develop and test js-stellar-sdk itself
123
-
124
- 1. Clone the repo:
125
-
126
- ```shell
127
- git clone https://github.com/stellar/js-stellar-sdk.git
128
- ```
129
-
130
- 2. Install dependencies inside js-stellar-sdk folder:
131
-
132
- ```shell
133
- cd js-stellar-sdk
134
- npm install
135
- ```
136
-
137
- 3. Install Node 16
138
-
139
- Because we support the oldest maintenance version of Node, please install and develop on Node 16 so you don't get surprised when your code works locally but breaks in CI.
140
-
141
- Here's how to install `nvm` if you haven't: https://github.com/creationix/nvm
142
-
143
- ```shell
144
- nvm install
145
-
146
- # if you've never installed 16 before you'll want to re-install yarn
147
- npm install -g yarn
148
- ```
149
-
150
- If you work on several projects that use different Node versions, you might it
151
- helpful to install this automatic version manager:
152
- https://github.com/wbyoung/avn
153
-
154
- 4. Observe the project's code style
83
+ If you don't want to use or install Bower, you can copy the packaged JS files from the [Bower repo](https://github.com/stellar/bower-js-stellar-sdk), or just build the package yourself locally (see [Developing :arrow_right: Building](#building)) and copy the bundle.
155
84
 
156
- While you're making changes, make sure to run the linter-watcher to catch any
157
- linting errors (in addition to making sure your text editor supports ESLint)
85
+ | Always make sure that you are using the latest version number. They can be found on the [releases page](https://github.com/stellar/js-stellar-sdk/releases) in GitHub. |
86
+ |----|
158
87
 
159
- ```shell
160
- node_modules/.bin/gulp watch
161
- ```
88
+ ## Usage
162
89
 
90
+ The usage documentation for this library lives in a handful of places:
163
91
 
164
- ## Usage
92
+ * across the [Stellar Developer Docs](), which includes tutorials and examples,
93
+ * within [this repository itself](https://github.com/stellar/js-stellar-sdk/blob/master/docs/reference/readme.md), and
94
+ * on the generated [API doc site](https://stellar.github.io/js-stellar-sdk/).
165
95
 
166
- For information on how to use js-stellar-sdk, take a look at [the
167
- documentation](https://stellar.github.io/js-stellar-sdk/), or [the
168
- examples](https://github.com/stellar/js-stellar-sdk/tree/master/docs/reference).
96
+ You can also refer to:
169
97
 
170
- There is also Horizon REST API Documentation
171
- [here](https://developers.stellar.org/api/introduction/).
98
+ * the [documentation](https://developers.stellar.org/api/introduction/) for the Horizon REST API (if using the `Horizon` module) and
99
+ * the [documentation](https://soroban.stellar.org/docs/reference/rpc) for Soroban RPC's API (if using the `SorobanRpc` module)
172
100
 
173
101
  ### Usage with React-Native
174
102
 
@@ -188,11 +116,11 @@ module.exports = {
188
116
  };
189
117
  ```
190
118
  6. Add `import "./shim";` to the top of `index.js`
191
- 7. `yarn add stellar-sdk`
119
+ 7. `yarn add @stellar/stellar-sdk`
192
120
 
193
121
  There is also a [sample](https://github.com/fnando/rn-stellar-sdk-sample) that you can follow.
194
122
 
195
- #### Using in an Expo managed workflow
123
+ #### Usage with Expo managed workflows
196
124
 
197
125
  1. Install `yarn add --dev rn-nodeify`
198
126
  2. Add the following postinstall script:
@@ -200,23 +128,111 @@ There is also a [sample](https://github.com/fnando/rn-stellar-sdk-sample) that y
200
128
  yarn rn-nodeify --install process,url,events,https,http,util,stream,crypto,vm,buffer --hack --yarn
201
129
  ```
202
130
  3. Add `import "./shim";` to the your app's entry point (by default `./App.js`)
203
- 4. `yarn add stellar-sdk`
131
+ 4. `yarn add @stellar/stellar-sdk`
204
132
  5. `expo install expo-random`
205
133
 
206
134
  At this point, the Stellar SDK will work, except that `StellarSdk.Keypair.random()` will throw an error. To work around this, you can create your own method to generate a random keypair like this:
207
135
 
208
136
  ```javascript
209
137
  import * as Random from 'expo-random';
210
- import StellarSdk from 'stellar-sdk';
138
+ import { Keypair } from '@stellar/stellar-sdk';
211
139
 
212
140
  const generateRandomKeypair = () => {
213
141
  const randomBytes = Random.getRandomBytes(32);
214
-
215
- return StellarSdk.Keypair.fromRawEd25519Seed(Buffer.from(randomBytes));
142
+ return Keypair.fromRawEd25519Seed(Buffer.from(randomBytes));
216
143
  };
217
144
  ```
218
145
 
219
- ## Testing
146
+ #### Usage with CloudFlare Workers
147
+
148
+ Both `eventsource` (needed for streaming) and `axios` (needed for making HTTP requests) are problematic dependencies in the CFW environment. The experimental branch [`make-eventsource-optional`](https://github.com/stellar/js-stellar-sdk/pull/901) is an attempt to resolve these issues.
149
+
150
+ It requires the following additional tweaks to your project:
151
+ * the `axios-fetch-adapter` lets you use `axios` with `fetch` as a backend, which is available to CF workers
152
+ * it only works with `axios@"<= 1.0.0"` versions, so we need to force an override into the underlying dependency
153
+ * and this can be problematic with newer `yarn` versions, so we need to force the environment to use Yarn 1
154
+
155
+ In summary, the `package.json` tweaks look something like this:
156
+
157
+ ```jsonc
158
+ "dependencies": {
159
+ // ...
160
+ "@stellar/stellar-sdk": "git+https://github.com/stellar/js-stellar-sdk#make-eventsource-optional",
161
+ "@vespaiach/axios-fetch-adapter": "^0.3.1",
162
+ "axios": "^0.26.1"
163
+ },
164
+ "overrides": {
165
+ "@stellar/stellar-sdk": {
166
+ "axios": "$axios"
167
+ }
168
+ },
169
+ "packageManager": "yarn@1.22.19"
170
+ ```
171
+
172
+ Then, you need to override the adapter in your codebase:
173
+
174
+ ```typescript
175
+ import { Horizon } from '@stellar/stellar-sdk';
176
+ import fetchAdapter from '@vespaiach/axios-fetch-adapter';
177
+
178
+ Horizon.AxiosClient.defaults.adapter = fetchAdapter as any;
179
+
180
+ // then, the rest of your code...
181
+ ```
182
+
183
+ All HTTP calls will use `fetch`, now, meaning it should work in the CloudFlare Worker environment.
184
+
185
+ ## Developing
186
+
187
+ So you want to contribute to the library: welcome! Whether you're working on a fork or want to make an upstream request, the dev-test loop is pretty straightforward.
188
+
189
+ 1. Clone the repo:
190
+
191
+ ```shell
192
+ git clone https://github.com/stellar/js-stellar-sdk.git
193
+ ```
194
+
195
+ 2. Install dependencies inside js-stellar-sdk folder:
196
+
197
+ ```shell
198
+ cd js-stellar-sdk
199
+ yarn
200
+ ```
201
+
202
+ 3. Install Node 18
203
+
204
+ Because we support the oldest maintenance version of Node, please install and develop on Node 18 so you don't get surprised when your code works locally but breaks in CI.
205
+
206
+ Here's how to install `nvm` if you haven't: https://github.com/creationix/nvm
207
+
208
+ ```shell
209
+ nvm install 18
210
+
211
+ # if you've never installed 18 before you'll want to re-install yarn
212
+ npm install -g yarn
213
+ ```
214
+
215
+ If you work on several projects that use different Node versions, you might it helpful to install this automatic version manager: https://github.com/wbyoung/avn
216
+
217
+ 4. Observe the project's code style
218
+
219
+ While you're making changes, make sure to run the linter to catch any linting
220
+ errors (in addition to making sure your text editor supports ESLint) and conform to the project's code style.
221
+
222
+ ```shell
223
+ yarn fmt
224
+ ```
225
+
226
+ ### Building
227
+ You can build the developer version (unoptimized, commented, with source maps, etc.) or the production bundles:
228
+
229
+ ```shell
230
+ yarn build
231
+ # or
232
+ yarn build:prod
233
+ ```
234
+
235
+ ### Testing
220
236
 
221
237
  To run all tests:
222
238
 
@@ -229,13 +245,19 @@ To run a specific set of tests:
229
245
  ```shell
230
246
  yarn test:node
231
247
  yarn test:browser
248
+ yarn test:integration
232
249
  ```
233
250
 
251
+ In order to have a faster test loop, these suite-specific commands **do not** build the bundles first (unlike `yarn test`). If you make code changes, you will need to run `yarn build` (or a subset like `yarn build:node` corresponding to the test suite) before running the tests again to see your changes.
252
+
234
253
  To generate and check the documentation site:
235
254
 
236
255
  ```shell
237
256
  # install the `serve` command if you don't have it already
238
- npm install -g serve
257
+ npm i -g serve
258
+
259
+ # clone the base library for complete docs
260
+ git clone https://github.com/stellar/js-stellar-base
239
261
 
240
262
  # generate the docs files
241
263
  yarn docs
@@ -246,28 +268,25 @@ cd jsdoc && serve .
246
268
  # you'll be able to browse the docs at http://localhost:5000
247
269
  ```
248
270
 
249
- ## Documentation
271
+ ### Publishing
250
272
 
251
- Documentation for this repo lives in
252
- [Developers site](https://github.com/stellar/js-stellar-sdk/blob/master/docs/reference/readme.md).
273
+ For information on how to contribute or publish new versions of this software to `npm`, please refer to our [contribution guide](https://github.com/stellar/js-stellar-sdk/blob/master/CONTRIBUTING.md).
253
274
 
254
- ## Contributing
275
+ ## Miscellaneous
255
276
 
256
- For information on how to contribute, please refer to our
257
- [contribution guide](https://github.com/stellar/js-stellar-sdk/blob/master/CONTRIBUTING.md).
277
+ ### `stellar-sdk` vs `stellar-base`
258
278
 
259
- ## Publishing to npm
279
+ `stellar-sdk` is a high-level library that serves as client-side API for Horizon and Soroban RPC, while [`stellar-base](https://github.com/stellar/js-stellar-base) is lower-level library for creating Stellar primitive constructs via XDR helpers and wrappers.
260
280
 
261
- ```
262
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]
263
- ```
281
+ **Most people will want stellar-sdk instead of stellar-base.** You should only use stellar-base if you know what you're doing!
264
282
 
265
- A new version will be published to npm **and** Bower by GitHub actions.
283
+ If you add `stellar-sdk` to a project, **do not add `stellar-base`!** Mismatching versions could cause weird, hard-to-find bugs. `stellar-sdk` automatically installs `stellar-base` and exposes all of its exports in case you need them.
266
284
 
267
- npm >= 2.13.0 required. Read more about
268
- [npm version](https://docs.npmjs.com/cli/version).
285
+ > **Important!** The Node.js version of the `stellar-base` (`stellar-sdk` dependency) package uses the [`sodium-native`](https://www.npmjs.com/package/sodium-native) package as an [optional dependency](https://docs.npmjs.com/files/package.json#optionaldependencies). `sodium-native` is a low level binding to [libsodium](https://github.com/jedisct1/libsodium), (an implementation of [Ed25519](https://ed25519.cr.yp.to/) signatures).
286
+ > If installation of `sodium-native` fails, or it is unavailable, `stellar-base` (and `stellar-sdk`) will fallback to using the [`tweetnacl`](https://www.npmjs.com/package/tweetnacl) package implementation. If you are using them in a browser, you can ignore this. However, for production backend deployments, you should be using `sodium-native`.
287
+ > If `sodium-native` is successfully installed and working the `StellarSdk.FastSigning` variable will return `true`.
269
288
 
270
- ## License
289
+ ### License
271
290
 
272
291
  js-stellar-sdk is licensed under an Apache-2.0 license. See the
273
292
  [LICENSE](https://github.com/stellar/js-stellar-sdk/blob/master/LICENSE) file