@stellar/stellar-sdk 11.0.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.
- package/CHANGELOG.md +1275 -0
- package/LICENSE +228 -0
- package/README.md +274 -0
- package/dist/stellar-sdk.js +56470 -0
- package/dist/stellar-sdk.min.js +2 -0
- package/dist/stellar-sdk.min.js.LICENSE.txt +71 -0
- package/lib/browser.d.ts +6 -0
- package/lib/browser.js +37 -0
- package/lib/config.d.ts +52 -0
- package/lib/config.js +49 -0
- package/lib/contract_spec.d.ts +130 -0
- package/lib/contract_spec.js +549 -0
- package/lib/errors.d.ts +59 -0
- package/lib/errors.js +105 -0
- package/lib/federation/api.d.ts +11 -0
- package/lib/federation/api.js +7 -0
- package/lib/federation/index.d.ts +2 -0
- package/lib/federation/index.js +24 -0
- package/lib/federation/server.d.ts +118 -0
- package/lib/federation/server.js +253 -0
- package/lib/friendbot/index.d.ts +5 -0
- package/lib/friendbot/index.js +7 -0
- package/lib/horizon/account_call_builder.d.ts +55 -0
- package/lib/horizon/account_call_builder.js +64 -0
- package/lib/horizon/account_response.d.ts +58 -0
- package/lib/horizon/account_response.js +50 -0
- package/lib/horizon/assets_call_builder.d.ts +27 -0
- package/lib/horizon/assets_call_builder.js +45 -0
- package/lib/horizon/call_builder.d.ts +128 -0
- package/lib/horizon/call_builder.js +360 -0
- package/lib/horizon/claimable_balances_call_builder.d.ts +49 -0
- package/lib/horizon/claimable_balances_call_builder.js +58 -0
- package/lib/horizon/effect_call_builder.d.ts +53 -0
- package/lib/horizon/effect_call_builder.js +58 -0
- package/lib/horizon/friendbot_builder.d.ts +5 -0
- package/lib/horizon/friendbot_builder.js +33 -0
- package/lib/horizon/horizon_api.d.ts +523 -0
- package/lib/horizon/horizon_api.js +96 -0
- package/lib/horizon/horizon_axios_client.d.ts +30 -0
- package/lib/horizon/horizon_axios_client.js +48 -0
- package/lib/horizon/index.d.ts +7 -0
- package/lib/horizon/index.js +78 -0
- package/lib/horizon/ledger_call_builder.d.ts +22 -0
- package/lib/horizon/ledger_call_builder.js +39 -0
- package/lib/horizon/liquidity_pool_call_builder.d.ts +38 -0
- package/lib/horizon/liquidity_pool_call_builder.js +61 -0
- package/lib/horizon/offer_call_builder.d.ts +64 -0
- package/lib/horizon/offer_call_builder.js +81 -0
- package/lib/horizon/operation_call_builder.d.ts +68 -0
- package/lib/horizon/operation_call_builder.js +71 -0
- package/lib/horizon/orderbook_call_builder.d.ts +16 -0
- package/lib/horizon/orderbook_call_builder.js +46 -0
- package/lib/horizon/path_call_builder.d.ts +31 -0
- package/lib/horizon/path_call_builder.js +42 -0
- package/lib/horizon/payment_call_builder.d.ts +36 -0
- package/lib/horizon/payment_call_builder.js +48 -0
- package/lib/horizon/server.d.ts +361 -0
- package/lib/horizon/server.js +507 -0
- package/lib/horizon/server_api.d.ts +279 -0
- package/lib/horizon/server_api.js +19 -0
- package/lib/horizon/strict_receive_path_call_builder.d.ts +34 -0
- package/lib/horizon/strict_receive_path_call_builder.js +51 -0
- package/lib/horizon/strict_send_path_call_builder.d.ts +34 -0
- package/lib/horizon/strict_send_path_call_builder.js +51 -0
- package/lib/horizon/trade_aggregation_call_builder.d.ts +48 -0
- package/lib/horizon/trade_aggregation_call_builder.js +82 -0
- package/lib/horizon/trades_call_builder.d.ts +50 -0
- package/lib/horizon/trades_call_builder.js +74 -0
- package/lib/horizon/transaction_call_builder.d.ts +58 -0
- package/lib/horizon/transaction_call_builder.js +66 -0
- package/lib/horizon/types/account.d.ts +5 -0
- package/lib/horizon/types/account.js +5 -0
- package/lib/horizon/types/assets.d.ts +19 -0
- package/lib/horizon/types/assets.js +5 -0
- package/lib/horizon/types/effects.d.ts +285 -0
- package/lib/horizon/types/effects.js +62 -0
- package/lib/horizon/types/offer.d.ts +20 -0
- package/lib/horizon/types/offer.js +5 -0
- package/lib/horizon/types/trade.d.ts +13 -0
- package/lib/horizon/types/trade.js +5 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +79 -0
- package/lib/soroban/api.d.ts +247 -0
- package/lib/soroban/api.js +32 -0
- package/lib/soroban/axios.d.ts +3 -0
- package/lib/soroban/axios.js +16 -0
- package/lib/soroban/browser.d.ts +6 -0
- package/lib/soroban/browser.js +37 -0
- package/lib/soroban/index.d.ts +8 -0
- package/lib/soroban/index.js +72 -0
- package/lib/soroban/jsonrpc.d.ts +33 -0
- package/lib/soroban/jsonrpc.js +93 -0
- package/lib/soroban/parsers.d.ts +17 -0
- package/lib/soroban/parsers.js +111 -0
- package/lib/soroban/server.d.ts +427 -0
- package/lib/soroban/server.js +598 -0
- package/lib/soroban/transaction.d.ts +20 -0
- package/lib/soroban/transaction.js +55 -0
- package/lib/soroban/utils.d.ts +1 -0
- package/lib/soroban/utils.js +9 -0
- package/lib/stellartoml/index.d.ts +121 -0
- package/lib/stellartoml/index.js +78 -0
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +32 -0
- package/lib/webauth/errors.d.ts +4 -0
- package/lib/webauth/errors.js +37 -0
- package/lib/webauth/index.d.ts +2 -0
- package/lib/webauth/index.js +27 -0
- package/lib/webauth/utils.d.ts +294 -0
- package/lib/webauth/utils.js +332 -0
- package/package.json +153 -0
- package/types/dom-monkeypatch.d.ts +126 -0
package/lib/errors.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.NotFoundError = exports.NetworkError = exports.BadResponseError = exports.BadRequestError = exports.AccountRequiresMemoError = void 0;
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
18
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
|
|
21
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
var NetworkError = exports.NetworkError = function (_Error) {
|
|
24
|
+
_inherits(NetworkError, _Error);
|
|
25
|
+
var _super = _createSuper(NetworkError);
|
|
26
|
+
function NetworkError(message, response) {
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, NetworkError);
|
|
29
|
+
var trueProto = (this instanceof NetworkError ? this.constructor : void 0).prototype;
|
|
30
|
+
_this = _super.call(this, message);
|
|
31
|
+
_this.__proto__ = trueProto;
|
|
32
|
+
_this.constructor = NetworkError;
|
|
33
|
+
_this.response = response;
|
|
34
|
+
return _this;
|
|
35
|
+
}
|
|
36
|
+
_createClass(NetworkError, [{
|
|
37
|
+
key: "getResponse",
|
|
38
|
+
value: function getResponse() {
|
|
39
|
+
return this.response;
|
|
40
|
+
}
|
|
41
|
+
}]);
|
|
42
|
+
return NetworkError;
|
|
43
|
+
}(_wrapNativeSuper(Error));
|
|
44
|
+
var NotFoundError = exports.NotFoundError = function (_NetworkError) {
|
|
45
|
+
_inherits(NotFoundError, _NetworkError);
|
|
46
|
+
var _super2 = _createSuper(NotFoundError);
|
|
47
|
+
function NotFoundError(message, response) {
|
|
48
|
+
var _this2;
|
|
49
|
+
_classCallCheck(this, NotFoundError);
|
|
50
|
+
var trueProto = (this instanceof NotFoundError ? this.constructor : void 0).prototype;
|
|
51
|
+
_this2 = _super2.call(this, message, response);
|
|
52
|
+
_this2.__proto__ = trueProto;
|
|
53
|
+
_this2.constructor = NotFoundError;
|
|
54
|
+
_this2.name = "NotFoundError";
|
|
55
|
+
return _this2;
|
|
56
|
+
}
|
|
57
|
+
return _createClass(NotFoundError);
|
|
58
|
+
}(NetworkError);
|
|
59
|
+
var BadRequestError = exports.BadRequestError = function (_NetworkError2) {
|
|
60
|
+
_inherits(BadRequestError, _NetworkError2);
|
|
61
|
+
var _super3 = _createSuper(BadRequestError);
|
|
62
|
+
function BadRequestError(message, response) {
|
|
63
|
+
var _this3;
|
|
64
|
+
_classCallCheck(this, BadRequestError);
|
|
65
|
+
var trueProto = (this instanceof BadRequestError ? this.constructor : void 0).prototype;
|
|
66
|
+
_this3 = _super3.call(this, message, response);
|
|
67
|
+
_this3.__proto__ = trueProto;
|
|
68
|
+
_this3.constructor = BadRequestError;
|
|
69
|
+
_this3.name = "BadRequestError";
|
|
70
|
+
return _this3;
|
|
71
|
+
}
|
|
72
|
+
return _createClass(BadRequestError);
|
|
73
|
+
}(NetworkError);
|
|
74
|
+
var BadResponseError = exports.BadResponseError = function (_NetworkError3) {
|
|
75
|
+
_inherits(BadResponseError, _NetworkError3);
|
|
76
|
+
var _super4 = _createSuper(BadResponseError);
|
|
77
|
+
function BadResponseError(message, response) {
|
|
78
|
+
var _this4;
|
|
79
|
+
_classCallCheck(this, BadResponseError);
|
|
80
|
+
var trueProto = (this instanceof BadResponseError ? this.constructor : void 0).prototype;
|
|
81
|
+
_this4 = _super4.call(this, message, response);
|
|
82
|
+
_this4.__proto__ = trueProto;
|
|
83
|
+
_this4.constructor = BadResponseError;
|
|
84
|
+
_this4.name = "BadResponseError";
|
|
85
|
+
return _this4;
|
|
86
|
+
}
|
|
87
|
+
return _createClass(BadResponseError);
|
|
88
|
+
}(NetworkError);
|
|
89
|
+
var AccountRequiresMemoError = exports.AccountRequiresMemoError = function (_Error2) {
|
|
90
|
+
_inherits(AccountRequiresMemoError, _Error2);
|
|
91
|
+
var _super5 = _createSuper(AccountRequiresMemoError);
|
|
92
|
+
function AccountRequiresMemoError(message, accountId, operationIndex) {
|
|
93
|
+
var _this5;
|
|
94
|
+
_classCallCheck(this, AccountRequiresMemoError);
|
|
95
|
+
var trueProto = (this instanceof AccountRequiresMemoError ? this.constructor : void 0).prototype;
|
|
96
|
+
_this5 = _super5.call(this, message);
|
|
97
|
+
_this5.__proto__ = trueProto;
|
|
98
|
+
_this5.constructor = AccountRequiresMemoError;
|
|
99
|
+
_this5.name = "AccountRequiresMemoError";
|
|
100
|
+
_this5.accountId = accountId;
|
|
101
|
+
_this5.operationIndex = operationIndex;
|
|
102
|
+
return _this5;
|
|
103
|
+
}
|
|
104
|
+
return _createClass(AccountRequiresMemoError);
|
|
105
|
+
}(_wrapNativeSuper(Error));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Api = void 0;
|
|
8
|
+
Object.defineProperty(exports, "FEDERATION_RESPONSE_MAX_SIZE", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _server.FEDERATION_RESPONSE_MAX_SIZE;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "Server", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _server.FederationServer;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var _server = require("./server");
|
|
21
|
+
var _Api = _interopRequireWildcard(require("./api"));
|
|
22
|
+
exports.Api = _Api;
|
|
23
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
24
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Api } from "./api";
|
|
2
|
+
export declare const FEDERATION_RESPONSE_MAX_SIZE: number;
|
|
3
|
+
/**
|
|
4
|
+
* FederationServer handles a network connection to a
|
|
5
|
+
* [federation server](https://developers.stellar.org/docs/glossary/federation/)
|
|
6
|
+
* instance and exposes an interface for requests to that instance.
|
|
7
|
+
* @constructor
|
|
8
|
+
* @param {string} serverURL The federation server URL (ex. `https://acme.com/federation`).
|
|
9
|
+
* @param {string} domain Domain this server represents
|
|
10
|
+
* @param {object} [opts] options object
|
|
11
|
+
* @param {boolean} [opts.allowHttp] - Allow connecting to http servers, default: `false`. This must be set to false in production deployments! You can also use {@link Config} class to set this globally.
|
|
12
|
+
* @param {number} [opts.timeout] - Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue. You can also use {@link Config} class to set this globally.
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
export declare class FederationServer {
|
|
16
|
+
/**
|
|
17
|
+
* The federation server URL (ex. `https://acme.com/federation`).
|
|
18
|
+
*
|
|
19
|
+
* @memberof FederationServer
|
|
20
|
+
*/
|
|
21
|
+
private readonly serverURL;
|
|
22
|
+
/**
|
|
23
|
+
* Domain this server represents.
|
|
24
|
+
*
|
|
25
|
+
* @type {string}
|
|
26
|
+
* @memberof FederationServer
|
|
27
|
+
*/
|
|
28
|
+
private readonly domain;
|
|
29
|
+
/**
|
|
30
|
+
* Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue.
|
|
31
|
+
*
|
|
32
|
+
* @type {number}
|
|
33
|
+
* @memberof FederationServer
|
|
34
|
+
*/
|
|
35
|
+
private readonly timeout;
|
|
36
|
+
/**
|
|
37
|
+
* A helper method for handling user inputs that contain `destination` value.
|
|
38
|
+
* It accepts two types of values:
|
|
39
|
+
*
|
|
40
|
+
* * For Stellar address (ex. `bob*stellar.org`) it splits Stellar address and then tries to find information about
|
|
41
|
+
* federation server in `stellar.toml` file for a given domain. It returns a `Promise` which resolves if federation
|
|
42
|
+
* server exists and user has been found and rejects in all other cases.
|
|
43
|
+
* * For Account ID (ex. `GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS`) it returns a `Promise` which
|
|
44
|
+
* resolves if Account ID is valid and rejects in all other cases. Please note that this method does not check
|
|
45
|
+
* if the account actually exists in a ledger.
|
|
46
|
+
*
|
|
47
|
+
* Example:
|
|
48
|
+
* ```js
|
|
49
|
+
* StellarSdk.FederationServer.resolve('bob*stellar.org')
|
|
50
|
+
* .then(federationRecord => {
|
|
51
|
+
* // {
|
|
52
|
+
* // account_id: 'GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS',
|
|
53
|
+
* // memo_type: 'id',
|
|
54
|
+
* // memo: 100
|
|
55
|
+
* // }
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @see <a href="https://developers.stellar.org/docs/glossary/federation/" target="_blank">Federation doc</a>
|
|
60
|
+
* @see <a href="https://developers.stellar.org/docs/issuing-assets/publishing-asset-info/" target="_blank">Stellar.toml doc</a>
|
|
61
|
+
* @param {string} value Stellar Address (ex. `bob*stellar.org`)
|
|
62
|
+
* @param {object} [opts] Options object
|
|
63
|
+
* @param {boolean} [opts.allowHttp] - Allow connecting to http servers, default: `false`. This must be set to false in production deployments!
|
|
64
|
+
* @param {number} [opts.timeout] - Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue.
|
|
65
|
+
* @returns {Promise} `Promise` that resolves to a JSON object with this shape:
|
|
66
|
+
* * `account_id` - Account ID of the destination,
|
|
67
|
+
* * `memo_type` (optional) - Memo type that needs to be attached to a transaction,
|
|
68
|
+
* * `memo` (optional) - Memo value that needs to be attached to a transaction.
|
|
69
|
+
*/
|
|
70
|
+
static resolve(value: string, opts?: Api.Options): Promise<Api.Record>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a `FederationServer` instance based on information from
|
|
73
|
+
* [stellar.toml](https://developers.stellar.org/docs/issuing-assets/publishing-asset-info/)
|
|
74
|
+
* file for a given domain.
|
|
75
|
+
*
|
|
76
|
+
* If `stellar.toml` file does not exist for a given domain or it does not
|
|
77
|
+
* contain information about a federation server Promise will reject.
|
|
78
|
+
* ```js
|
|
79
|
+
* StellarSdk.FederationServer.createForDomain('acme.com')
|
|
80
|
+
* .then(federationServer => {
|
|
81
|
+
* // federationServer.resolveAddress('bob').then(...)
|
|
82
|
+
* })
|
|
83
|
+
* .catch(error => {
|
|
84
|
+
* // stellar.toml does not exist or it does not contain information about federation server.
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
* @see <a href="https://developers.stellar.org/docs/issuing-assets/publishing-asset-info/" target="_blank">Stellar.toml doc</a>
|
|
88
|
+
* @param {string} domain Domain to get federation server for
|
|
89
|
+
* @param {object} [opts] Options object
|
|
90
|
+
* @param {boolean} [opts.allowHttp] - Allow connecting to http servers, default: `false`. This must be set to false in production deployments!
|
|
91
|
+
* @param {number} [opts.timeout] - Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue.
|
|
92
|
+
* @returns {Promise} `Promise` that resolves to a FederationServer object
|
|
93
|
+
*/
|
|
94
|
+
static createForDomain(domain: string, opts?: Api.Options): Promise<FederationServer>;
|
|
95
|
+
constructor(serverURL: string, domain: string, opts?: Api.Options);
|
|
96
|
+
/**
|
|
97
|
+
* Get the federation record if the user was found for a given Stellar address
|
|
98
|
+
* @see <a href="https://developers.stellar.org/docs/glossary/federation/" target="_blank">Federation doc</a>
|
|
99
|
+
* @param {string} address Stellar address (ex. `bob*stellar.org`). If `FederationServer` was instantiated with `domain` param only username (ex. `bob`) can be passed.
|
|
100
|
+
* @returns {Promise} Promise that resolves to the federation record
|
|
101
|
+
*/
|
|
102
|
+
resolveAddress(address: string): Promise<Api.Record>;
|
|
103
|
+
/**
|
|
104
|
+
* Given an account ID, get their federation record if the user was found
|
|
105
|
+
* @see <a href="https://developers.stellar.org/docs/glossary/federation/" target="_blank">Federation doc</a>
|
|
106
|
+
* @param {string} accountId Account ID (ex. `GBYNR2QJXLBCBTRN44MRORCMI4YO7FZPFBCNOKTOBCAAFC7KC3LNPRYS`)
|
|
107
|
+
* @returns {Promise} A promise that resolves to the federation record
|
|
108
|
+
*/
|
|
109
|
+
resolveAccountId(accountId: string): Promise<Api.Record>;
|
|
110
|
+
/**
|
|
111
|
+
* Given a transactionId, get the federation record if the sender of the transaction was found
|
|
112
|
+
* @see <a href="https://developers.stellar.org/docs/glossary/federation/" target="_blank">Federation doc</a>
|
|
113
|
+
* @param {string} transactionId Transaction ID (ex. `3389e9f0f1a65f19736cacf544c2e825313e8447f569233bb8db39aa607c8889`)
|
|
114
|
+
* @returns {Promise} A promise that resolves to the federation record
|
|
115
|
+
*/
|
|
116
|
+
resolveTransactionId(transactionId: string): Promise<Api.Record>;
|
|
117
|
+
private _sendRequest;
|
|
118
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FederationServer = exports.FEDERATION_RESPONSE_MAX_SIZE = void 0;
|
|
7
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
8
|
+
var _stellarBase = require("@stellar/stellar-base");
|
|
9
|
+
var _urijs = _interopRequireDefault(require("urijs"));
|
|
10
|
+
var _config = require("../config");
|
|
11
|
+
var _errors = require("../errors");
|
|
12
|
+
var _stellartoml = require("../stellartoml");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
15
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
19
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
function _regeneratorRuntime() { "use strict"; _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
22
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
23
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
24
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
28
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
29
|
+
var FEDERATION_RESPONSE_MAX_SIZE = exports.FEDERATION_RESPONSE_MAX_SIZE = 100 * 1024;
|
|
30
|
+
var FederationServer = exports.FederationServer = function () {
|
|
31
|
+
function FederationServer(serverURL, domain) {
|
|
32
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33
|
+
_classCallCheck(this, FederationServer);
|
|
34
|
+
this.serverURL = (0, _urijs.default)(serverURL);
|
|
35
|
+
this.domain = domain;
|
|
36
|
+
var allowHttp = typeof opts.allowHttp === "undefined" ? _config.Config.isAllowHttp() : opts.allowHttp;
|
|
37
|
+
this.timeout = typeof opts.timeout === "undefined" ? _config.Config.getTimeout() : opts.timeout;
|
|
38
|
+
if (this.serverURL.protocol() !== "https" && !allowHttp) {
|
|
39
|
+
throw new Error("Cannot connect to insecure federation server");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_createClass(FederationServer, [{
|
|
43
|
+
key: "resolveAddress",
|
|
44
|
+
value: (function () {
|
|
45
|
+
var _resolveAddress = _asyncToGenerator(_regeneratorRuntime().mark(function _callee(address) {
|
|
46
|
+
var stellarAddress, url;
|
|
47
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
stellarAddress = address;
|
|
51
|
+
if (!(address.indexOf("*") < 0)) {
|
|
52
|
+
_context.next = 5;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
if (this.domain) {
|
|
56
|
+
_context.next = 4;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return _context.abrupt("return", Promise.reject(new Error("Unknown domain. Make sure `address` contains a domain (ex. `bob*stellar.org`) or pass `domain` parameter when instantiating the server object.")));
|
|
60
|
+
case 4:
|
|
61
|
+
stellarAddress = "".concat(address, "*").concat(this.domain);
|
|
62
|
+
case 5:
|
|
63
|
+
url = this.serverURL.query({
|
|
64
|
+
type: "name",
|
|
65
|
+
q: stellarAddress
|
|
66
|
+
});
|
|
67
|
+
return _context.abrupt("return", this._sendRequest(url));
|
|
68
|
+
case 7:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context.stop();
|
|
71
|
+
}
|
|
72
|
+
}, _callee, this);
|
|
73
|
+
}));
|
|
74
|
+
function resolveAddress(_x) {
|
|
75
|
+
return _resolveAddress.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
return resolveAddress;
|
|
78
|
+
}())
|
|
79
|
+
}, {
|
|
80
|
+
key: "resolveAccountId",
|
|
81
|
+
value: (function () {
|
|
82
|
+
var _resolveAccountId = _asyncToGenerator(_regeneratorRuntime().mark(function _callee2(accountId) {
|
|
83
|
+
var url;
|
|
84
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
85
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
86
|
+
case 0:
|
|
87
|
+
url = this.serverURL.query({
|
|
88
|
+
type: "id",
|
|
89
|
+
q: accountId
|
|
90
|
+
});
|
|
91
|
+
return _context2.abrupt("return", this._sendRequest(url));
|
|
92
|
+
case 2:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context2.stop();
|
|
95
|
+
}
|
|
96
|
+
}, _callee2, this);
|
|
97
|
+
}));
|
|
98
|
+
function resolveAccountId(_x2) {
|
|
99
|
+
return _resolveAccountId.apply(this, arguments);
|
|
100
|
+
}
|
|
101
|
+
return resolveAccountId;
|
|
102
|
+
}())
|
|
103
|
+
}, {
|
|
104
|
+
key: "resolveTransactionId",
|
|
105
|
+
value: (function () {
|
|
106
|
+
var _resolveTransactionId = _asyncToGenerator(_regeneratorRuntime().mark(function _callee3(transactionId) {
|
|
107
|
+
var url;
|
|
108
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
109
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
110
|
+
case 0:
|
|
111
|
+
url = this.serverURL.query({
|
|
112
|
+
type: "txid",
|
|
113
|
+
q: transactionId
|
|
114
|
+
});
|
|
115
|
+
return _context3.abrupt("return", this._sendRequest(url));
|
|
116
|
+
case 2:
|
|
117
|
+
case "end":
|
|
118
|
+
return _context3.stop();
|
|
119
|
+
}
|
|
120
|
+
}, _callee3, this);
|
|
121
|
+
}));
|
|
122
|
+
function resolveTransactionId(_x3) {
|
|
123
|
+
return _resolveTransactionId.apply(this, arguments);
|
|
124
|
+
}
|
|
125
|
+
return resolveTransactionId;
|
|
126
|
+
}())
|
|
127
|
+
}, {
|
|
128
|
+
key: "_sendRequest",
|
|
129
|
+
value: function () {
|
|
130
|
+
var _sendRequest2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee4(url) {
|
|
131
|
+
var timeout;
|
|
132
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
133
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
134
|
+
case 0:
|
|
135
|
+
timeout = this.timeout;
|
|
136
|
+
return _context4.abrupt("return", _axios.default.get(url.toString(), {
|
|
137
|
+
maxContentLength: FEDERATION_RESPONSE_MAX_SIZE,
|
|
138
|
+
timeout: timeout
|
|
139
|
+
}).then(function (response) {
|
|
140
|
+
if (typeof response.data.memo !== "undefined" && typeof response.data.memo !== "string") {
|
|
141
|
+
throw new Error("memo value should be of type string");
|
|
142
|
+
}
|
|
143
|
+
return response.data;
|
|
144
|
+
}).catch(function (response) {
|
|
145
|
+
if (response instanceof Error) {
|
|
146
|
+
if (response.message.match(/^maxContentLength size/)) {
|
|
147
|
+
throw new Error("federation response exceeds allowed size of ".concat(FEDERATION_RESPONSE_MAX_SIZE));
|
|
148
|
+
} else {
|
|
149
|
+
return Promise.reject(response);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
return Promise.reject(new _errors.BadResponseError("Server query failed. Server responded: ".concat(response.status, " ").concat(response.statusText), response.data));
|
|
153
|
+
}
|
|
154
|
+
}));
|
|
155
|
+
case 2:
|
|
156
|
+
case "end":
|
|
157
|
+
return _context4.stop();
|
|
158
|
+
}
|
|
159
|
+
}, _callee4, this);
|
|
160
|
+
}));
|
|
161
|
+
function _sendRequest(_x4) {
|
|
162
|
+
return _sendRequest2.apply(this, arguments);
|
|
163
|
+
}
|
|
164
|
+
return _sendRequest;
|
|
165
|
+
}()
|
|
166
|
+
}], [{
|
|
167
|
+
key: "resolve",
|
|
168
|
+
value: (function () {
|
|
169
|
+
var _resolve = _asyncToGenerator(_regeneratorRuntime().mark(function _callee5(value) {
|
|
170
|
+
var opts,
|
|
171
|
+
addressParts,
|
|
172
|
+
_addressParts,
|
|
173
|
+
domain,
|
|
174
|
+
federationServer,
|
|
175
|
+
_args5 = arguments;
|
|
176
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
177
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
178
|
+
case 0:
|
|
179
|
+
opts = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
180
|
+
if (!(value.indexOf("*") < 0)) {
|
|
181
|
+
_context5.next = 5;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
if (_stellarBase.StrKey.isValidEd25519PublicKey(value)) {
|
|
185
|
+
_context5.next = 4;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
return _context5.abrupt("return", Promise.reject(new Error("Invalid Account ID")));
|
|
189
|
+
case 4:
|
|
190
|
+
return _context5.abrupt("return", Promise.resolve({
|
|
191
|
+
account_id: value
|
|
192
|
+
}));
|
|
193
|
+
case 5:
|
|
194
|
+
addressParts = value.split("*");
|
|
195
|
+
_addressParts = _slicedToArray(addressParts, 2), domain = _addressParts[1];
|
|
196
|
+
if (!(addressParts.length !== 2 || !domain)) {
|
|
197
|
+
_context5.next = 9;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
return _context5.abrupt("return", Promise.reject(new Error("Invalid Stellar address")));
|
|
201
|
+
case 9:
|
|
202
|
+
_context5.next = 11;
|
|
203
|
+
return FederationServer.createForDomain(domain, opts);
|
|
204
|
+
case 11:
|
|
205
|
+
federationServer = _context5.sent;
|
|
206
|
+
return _context5.abrupt("return", federationServer.resolveAddress(value));
|
|
207
|
+
case 13:
|
|
208
|
+
case "end":
|
|
209
|
+
return _context5.stop();
|
|
210
|
+
}
|
|
211
|
+
}, _callee5);
|
|
212
|
+
}));
|
|
213
|
+
function resolve(_x5) {
|
|
214
|
+
return _resolve.apply(this, arguments);
|
|
215
|
+
}
|
|
216
|
+
return resolve;
|
|
217
|
+
}())
|
|
218
|
+
}, {
|
|
219
|
+
key: "createForDomain",
|
|
220
|
+
value: (function () {
|
|
221
|
+
var _createForDomain = _asyncToGenerator(_regeneratorRuntime().mark(function _callee6(domain) {
|
|
222
|
+
var opts,
|
|
223
|
+
tomlObject,
|
|
224
|
+
_args6 = arguments;
|
|
225
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
226
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
227
|
+
case 0:
|
|
228
|
+
opts = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
|
|
229
|
+
_context6.next = 3;
|
|
230
|
+
return _stellartoml.Resolver.resolve(domain, opts);
|
|
231
|
+
case 3:
|
|
232
|
+
tomlObject = _context6.sent;
|
|
233
|
+
if (tomlObject.FEDERATION_SERVER) {
|
|
234
|
+
_context6.next = 6;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
return _context6.abrupt("return", Promise.reject(new Error("stellar.toml does not contain FEDERATION_SERVER field")));
|
|
238
|
+
case 6:
|
|
239
|
+
return _context6.abrupt("return", new FederationServer(tomlObject.FEDERATION_SERVER, domain, opts));
|
|
240
|
+
case 7:
|
|
241
|
+
case "end":
|
|
242
|
+
return _context6.stop();
|
|
243
|
+
}
|
|
244
|
+
}, _callee6);
|
|
245
|
+
}));
|
|
246
|
+
function createForDomain(_x6) {
|
|
247
|
+
return _createForDomain.apply(this, arguments);
|
|
248
|
+
}
|
|
249
|
+
return createForDomain;
|
|
250
|
+
}())
|
|
251
|
+
}]);
|
|
252
|
+
return FederationServer;
|
|
253
|
+
}();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="urijs" />
|
|
2
|
+
import { Asset } from "@stellar/stellar-base";
|
|
3
|
+
import { CallBuilder } from "./call_builder";
|
|
4
|
+
import { ServerApi } from "./server_api";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new {@link AccountCallBuilder} pointed to server defined by serverUrl.
|
|
7
|
+
* Do not create this object directly, use {@link Server#accounts}.
|
|
8
|
+
*
|
|
9
|
+
* @see [All Accounts](https://developers.stellar.org/api/resources/accounts/)
|
|
10
|
+
* @class AccountCallBuilder
|
|
11
|
+
* @extends CallBuilder
|
|
12
|
+
* @constructor
|
|
13
|
+
* @param {string} serverUrl Horizon server URL.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AccountCallBuilder extends CallBuilder<ServerApi.CollectionPage<ServerApi.AccountRecord>> {
|
|
16
|
+
constructor(serverUrl: URI);
|
|
17
|
+
/**
|
|
18
|
+
* Returns information and links relating to a single account.
|
|
19
|
+
* The balances section in the returned JSON will also list all the trust lines this account has set up.
|
|
20
|
+
*
|
|
21
|
+
* @see [Account Details](https://developers.stellar.org/api/resources/accounts/single/)
|
|
22
|
+
* @param {string} id For example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD`
|
|
23
|
+
* @returns {CallBuilder} a new CallBuilder instance for the /accounts/:id endpoint
|
|
24
|
+
*/
|
|
25
|
+
accountId(id: string): CallBuilder<ServerApi.AccountRecord>;
|
|
26
|
+
/**
|
|
27
|
+
* This endpoint filters accounts by signer account.
|
|
28
|
+
* @see [Accounts](https://developers.stellar.org/api/resources/accounts/list/)
|
|
29
|
+
* @param {string} id For example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD`
|
|
30
|
+
* @returns {AccountCallBuilder} current AccountCallBuilder instance
|
|
31
|
+
*/
|
|
32
|
+
forSigner(id: string): this;
|
|
33
|
+
/**
|
|
34
|
+
* This endpoint filters all accounts who are trustees to an asset.
|
|
35
|
+
* @see [Accounts](https://developers.stellar.org/api/resources/accounts/list/)
|
|
36
|
+
* @see Asset
|
|
37
|
+
* @param {Asset} asset For example: `new Asset('USD','GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD')`
|
|
38
|
+
* @returns {AccountCallBuilder} current AccountCallBuilder instance
|
|
39
|
+
*/
|
|
40
|
+
forAsset(asset: Asset): this;
|
|
41
|
+
/**
|
|
42
|
+
* This endpoint filters accounts where the given account is sponsoring the account or any of its sub-entries..
|
|
43
|
+
* @see [Accounts](https://developers.stellar.org/api/resources/accounts/list/)
|
|
44
|
+
* @param {string} id For example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD`
|
|
45
|
+
* @returns {AccountCallBuilder} current AccountCallBuilder instance
|
|
46
|
+
*/
|
|
47
|
+
sponsor(id: string): this;
|
|
48
|
+
/**
|
|
49
|
+
* This endpoint filters accounts holding a trustline to the given liquidity pool.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} id The ID of the liquidity pool. For example: `dd7b1ab831c273310ddbec6f97870aa83c2fbd78ce22aded37ecbf4f3380fac7`.
|
|
52
|
+
* @returns {AccountCallBuilder} current AccountCallBuilder instance
|
|
53
|
+
*/
|
|
54
|
+
forLiquidityPool(id: string): this;
|
|
55
|
+
}
|