@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.
Files changed (112) hide show
  1. package/CHANGELOG.md +1275 -0
  2. package/LICENSE +228 -0
  3. package/README.md +274 -0
  4. package/dist/stellar-sdk.js +56470 -0
  5. package/dist/stellar-sdk.min.js +2 -0
  6. package/dist/stellar-sdk.min.js.LICENSE.txt +71 -0
  7. package/lib/browser.d.ts +6 -0
  8. package/lib/browser.js +37 -0
  9. package/lib/config.d.ts +52 -0
  10. package/lib/config.js +49 -0
  11. package/lib/contract_spec.d.ts +130 -0
  12. package/lib/contract_spec.js +549 -0
  13. package/lib/errors.d.ts +59 -0
  14. package/lib/errors.js +105 -0
  15. package/lib/federation/api.d.ts +11 -0
  16. package/lib/federation/api.js +7 -0
  17. package/lib/federation/index.d.ts +2 -0
  18. package/lib/federation/index.js +24 -0
  19. package/lib/federation/server.d.ts +118 -0
  20. package/lib/federation/server.js +253 -0
  21. package/lib/friendbot/index.d.ts +5 -0
  22. package/lib/friendbot/index.js +7 -0
  23. package/lib/horizon/account_call_builder.d.ts +55 -0
  24. package/lib/horizon/account_call_builder.js +64 -0
  25. package/lib/horizon/account_response.d.ts +58 -0
  26. package/lib/horizon/account_response.js +50 -0
  27. package/lib/horizon/assets_call_builder.d.ts +27 -0
  28. package/lib/horizon/assets_call_builder.js +45 -0
  29. package/lib/horizon/call_builder.d.ts +128 -0
  30. package/lib/horizon/call_builder.js +360 -0
  31. package/lib/horizon/claimable_balances_call_builder.d.ts +49 -0
  32. package/lib/horizon/claimable_balances_call_builder.js +58 -0
  33. package/lib/horizon/effect_call_builder.d.ts +53 -0
  34. package/lib/horizon/effect_call_builder.js +58 -0
  35. package/lib/horizon/friendbot_builder.d.ts +5 -0
  36. package/lib/horizon/friendbot_builder.js +33 -0
  37. package/lib/horizon/horizon_api.d.ts +523 -0
  38. package/lib/horizon/horizon_api.js +96 -0
  39. package/lib/horizon/horizon_axios_client.d.ts +30 -0
  40. package/lib/horizon/horizon_axios_client.js +48 -0
  41. package/lib/horizon/index.d.ts +7 -0
  42. package/lib/horizon/index.js +78 -0
  43. package/lib/horizon/ledger_call_builder.d.ts +22 -0
  44. package/lib/horizon/ledger_call_builder.js +39 -0
  45. package/lib/horizon/liquidity_pool_call_builder.d.ts +38 -0
  46. package/lib/horizon/liquidity_pool_call_builder.js +61 -0
  47. package/lib/horizon/offer_call_builder.d.ts +64 -0
  48. package/lib/horizon/offer_call_builder.js +81 -0
  49. package/lib/horizon/operation_call_builder.d.ts +68 -0
  50. package/lib/horizon/operation_call_builder.js +71 -0
  51. package/lib/horizon/orderbook_call_builder.d.ts +16 -0
  52. package/lib/horizon/orderbook_call_builder.js +46 -0
  53. package/lib/horizon/path_call_builder.d.ts +31 -0
  54. package/lib/horizon/path_call_builder.js +42 -0
  55. package/lib/horizon/payment_call_builder.d.ts +36 -0
  56. package/lib/horizon/payment_call_builder.js +48 -0
  57. package/lib/horizon/server.d.ts +361 -0
  58. package/lib/horizon/server.js +507 -0
  59. package/lib/horizon/server_api.d.ts +279 -0
  60. package/lib/horizon/server_api.js +19 -0
  61. package/lib/horizon/strict_receive_path_call_builder.d.ts +34 -0
  62. package/lib/horizon/strict_receive_path_call_builder.js +51 -0
  63. package/lib/horizon/strict_send_path_call_builder.d.ts +34 -0
  64. package/lib/horizon/strict_send_path_call_builder.js +51 -0
  65. package/lib/horizon/trade_aggregation_call_builder.d.ts +48 -0
  66. package/lib/horizon/trade_aggregation_call_builder.js +82 -0
  67. package/lib/horizon/trades_call_builder.d.ts +50 -0
  68. package/lib/horizon/trades_call_builder.js +74 -0
  69. package/lib/horizon/transaction_call_builder.d.ts +58 -0
  70. package/lib/horizon/transaction_call_builder.js +66 -0
  71. package/lib/horizon/types/account.d.ts +5 -0
  72. package/lib/horizon/types/account.js +5 -0
  73. package/lib/horizon/types/assets.d.ts +19 -0
  74. package/lib/horizon/types/assets.js +5 -0
  75. package/lib/horizon/types/effects.d.ts +285 -0
  76. package/lib/horizon/types/effects.js +62 -0
  77. package/lib/horizon/types/offer.d.ts +20 -0
  78. package/lib/horizon/types/offer.js +5 -0
  79. package/lib/horizon/types/trade.d.ts +13 -0
  80. package/lib/horizon/types/trade.js +5 -0
  81. package/lib/index.d.ts +14 -0
  82. package/lib/index.js +79 -0
  83. package/lib/soroban/api.d.ts +247 -0
  84. package/lib/soroban/api.js +32 -0
  85. package/lib/soroban/axios.d.ts +3 -0
  86. package/lib/soroban/axios.js +16 -0
  87. package/lib/soroban/browser.d.ts +6 -0
  88. package/lib/soroban/browser.js +37 -0
  89. package/lib/soroban/index.d.ts +8 -0
  90. package/lib/soroban/index.js +72 -0
  91. package/lib/soroban/jsonrpc.d.ts +33 -0
  92. package/lib/soroban/jsonrpc.js +93 -0
  93. package/lib/soroban/parsers.d.ts +17 -0
  94. package/lib/soroban/parsers.js +111 -0
  95. package/lib/soroban/server.d.ts +427 -0
  96. package/lib/soroban/server.js +598 -0
  97. package/lib/soroban/transaction.d.ts +20 -0
  98. package/lib/soroban/transaction.js +55 -0
  99. package/lib/soroban/utils.d.ts +1 -0
  100. package/lib/soroban/utils.js +9 -0
  101. package/lib/stellartoml/index.d.ts +121 -0
  102. package/lib/stellartoml/index.js +78 -0
  103. package/lib/utils.d.ts +12 -0
  104. package/lib/utils.js +32 -0
  105. package/lib/webauth/errors.d.ts +4 -0
  106. package/lib/webauth/errors.js +37 -0
  107. package/lib/webauth/index.d.ts +2 -0
  108. package/lib/webauth/index.js +27 -0
  109. package/lib/webauth/utils.d.ts +294 -0
  110. package/lib/webauth/utils.js +332 -0
  111. package/package.json +153 -0
  112. package/types/dom-monkeypatch.d.ts +126 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assembleTransaction = assembleTransaction;
7
+ var _stellarBase = require("@stellar/stellar-base");
8
+ var _api = require("./api");
9
+ var _parsers = require("./parsers");
10
+ function assembleTransaction(raw, simulation) {
11
+ var _invokeOp$auth;
12
+ if ('innerTransaction' in raw) {
13
+ return assembleTransaction(raw.innerTransaction, simulation);
14
+ }
15
+ if (!isSorobanTransaction(raw)) {
16
+ throw new TypeError('unsupported transaction: must contain exactly one ' + 'invokeHostFunction, extendFootprintTtl, or restoreFootprint ' + 'operation');
17
+ }
18
+ var success = (0, _parsers.parseRawSimulation)(simulation);
19
+ if (!_api.Api.isSimulationSuccess(success)) {
20
+ throw new Error("simulation incorrect: ".concat(JSON.stringify(success)));
21
+ }
22
+ var classicFeeNum = parseInt(raw.fee) || 0;
23
+ var minResourceFeeNum = parseInt(success.minResourceFee) || 0;
24
+ var txnBuilder = _stellarBase.TransactionBuilder.cloneFrom(raw, {
25
+ fee: (classicFeeNum + minResourceFeeNum).toString(),
26
+ sorobanData: success.transactionData.build(),
27
+ networkPassphrase: raw.networkPassphrase
28
+ });
29
+ switch (raw.operations[0].type) {
30
+ case 'invokeHostFunction':
31
+ txnBuilder.clearOperations();
32
+ var invokeOp = raw.operations[0];
33
+ var existingAuth = (_invokeOp$auth = invokeOp.auth) !== null && _invokeOp$auth !== void 0 ? _invokeOp$auth : [];
34
+ txnBuilder.addOperation(_stellarBase.Operation.invokeHostFunction({
35
+ source: invokeOp.source,
36
+ func: invokeOp.func,
37
+ auth: existingAuth.length > 0 ? existingAuth : success.result.auth
38
+ }));
39
+ break;
40
+ }
41
+ return txnBuilder;
42
+ }
43
+ function isSorobanTransaction(tx) {
44
+ if (tx.operations.length !== 1) {
45
+ return false;
46
+ }
47
+ switch (tx.operations[0].type) {
48
+ case 'invokeHostFunction':
49
+ case 'extendFootprintTtl':
50
+ case 'restoreFootprint':
51
+ return true;
52
+ default:
53
+ return false;
54
+ }
55
+ }
@@ -0,0 +1 @@
1
+ export declare function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasOwnProperty = hasOwnProperty;
7
+ function hasOwnProperty(obj, prop) {
8
+ return obj.hasOwnProperty(prop);
9
+ }
@@ -0,0 +1,121 @@
1
+ import { Networks } from "@stellar/stellar-base";
2
+ /** the maximum size of stellar.toml file */
3
+ export declare const STELLAR_TOML_MAX_SIZE: number;
4
+ /** Resolver allows resolving `stellar.toml` files. */
5
+ export declare class Resolver {
6
+ /**
7
+ * Returns a parsed `stellar.toml` file for a given domain.
8
+ * ```js
9
+ * StellarSdk.Resolver.resolve('acme.com')
10
+ * .then(stellarToml => {
11
+ * // stellarToml in an object representing domain stellar.toml file.
12
+ * })
13
+ * .catch(error => {
14
+ * // stellar.toml does not exist or is invalid
15
+ * });
16
+ * ```
17
+ * @see <a href="https://developers.stellar.org/docs/issuing-assets/publishing-asset-info/" target="_blank">Stellar.toml doc</a>
18
+ * @param {string} domain Domain to get stellar.toml file for
19
+ * @param {object} [opts] Options object
20
+ * @param {boolean} [opts.allowHttp] - Allow connecting to http servers, default: `false`. This must be set to false in production deployments!
21
+ * @param {number} [opts.timeout] - Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue.
22
+ * @returns {Promise} A `Promise` that resolves to the parsed stellar.toml object
23
+ */
24
+ static resolve(domain: string, opts?: Api.StellarTomlResolveOptions): Promise<Api.StellarToml>;
25
+ }
26
+ export declare namespace Api {
27
+ interface StellarTomlResolveOptions {
28
+ allowHttp?: boolean;
29
+ timeout?: number;
30
+ }
31
+ type Url = string;
32
+ type PublicKey = string;
33
+ type ISODateTime = string;
34
+ interface Documentation {
35
+ ORG_NAME?: string;
36
+ ORG_DBA?: string;
37
+ ORG_URL?: Url;
38
+ ORG_PHONE_NUMBER?: string;
39
+ ORG_LOGO?: Url;
40
+ ORG_LICENSE_NUMBER?: string;
41
+ ORG_LICENSING_AUTHORITY?: string;
42
+ ORG_LICENSE_TYPE?: string;
43
+ ORG_DESCRIPTION?: string;
44
+ ORG_PHYSICAL_ADDRESS?: string;
45
+ ORG_PHYSICAL_ADDRESS_ATTESTATION?: string;
46
+ ORG_PHONE_NUMBER_ATTESTATION?: string;
47
+ ORG_OFFICIAL_EMAIL?: string;
48
+ ORG_SUPPORT_EMAIL?: string;
49
+ ORG_KEYBASE?: string;
50
+ ORG_TWITTER?: string;
51
+ ORG_GITHUB?: string;
52
+ [key: string]: unknown;
53
+ }
54
+ interface Principal {
55
+ name: string;
56
+ email: string;
57
+ github?: string;
58
+ keybase?: string;
59
+ telegram?: string;
60
+ twitter?: string;
61
+ id_photo_hash?: string;
62
+ verification_photo_hash?: string;
63
+ [key: string]: unknown;
64
+ }
65
+ interface Currency {
66
+ code?: string;
67
+ code_template?: string;
68
+ issuer?: PublicKey;
69
+ display_decimals?: number;
70
+ status?: "live" | "dead" | "test" | "private";
71
+ name?: string;
72
+ desc?: string;
73
+ conditions?: string;
74
+ fixed_number?: number;
75
+ max_number?: number;
76
+ is_asset_anchored?: boolean;
77
+ anchor_asset_type?: "fiat" | "crypto" | "nft" | "stock" | "bond" | "commodity" | "realestate" | "other";
78
+ anchor_asset?: string;
79
+ attestation_of_reserve?: Url;
80
+ attestation_of_reserve_amount?: string;
81
+ attestation_of_reserve_last_audit?: ISODateTime;
82
+ is_unlimited?: boolean;
83
+ redemption_instructions?: string;
84
+ image?: Url;
85
+ regulated?: boolean;
86
+ collateral_addresses?: string[];
87
+ collateral_address_messages?: string[];
88
+ collateral_address_signatures?: string[];
89
+ approval_server?: Url;
90
+ approval_criteria?: string;
91
+ [key: string]: unknown;
92
+ }
93
+ interface Validator {
94
+ ALIAS?: string;
95
+ DISPLAY_NAME?: string;
96
+ PUBLIC_KEY?: PublicKey;
97
+ HOST?: string;
98
+ HISTORY?: Url;
99
+ [key: string]: unknown;
100
+ }
101
+ interface StellarToml {
102
+ VERSION?: string;
103
+ ACCOUNTS?: PublicKey[];
104
+ NETWORK_PASSPHRASE?: Networks;
105
+ TRANSFER_SERVER_SEP0024?: Url;
106
+ TRANSFER_SERVER?: Url;
107
+ KYC_SERVER?: Url;
108
+ WEB_AUTH_ENDPOINT?: Url;
109
+ FEDERATION_SERVER?: Url;
110
+ SIGNING_KEY?: PublicKey;
111
+ HORIZON_URL?: Url;
112
+ URI_REQUEST_SIGNING_KEY?: PublicKey;
113
+ DIRECT_PAYMENT_SERVER?: Url;
114
+ ANCHOR_QUOTE_SERVER?: Url;
115
+ DOCUMENTATION?: Documentation;
116
+ PRINCIPALS?: Principal[];
117
+ CURRENCIES?: Currency[];
118
+ VALIDATORS?: Validator[];
119
+ [key: string]: unknown;
120
+ }
121
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.STELLAR_TOML_MAX_SIZE = exports.Resolver = exports.Api = void 0;
7
+ var _axios = _interopRequireDefault(require("axios"));
8
+ var _toml = _interopRequireDefault(require("toml"));
9
+ var _config = require("../config");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ 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); }
12
+ 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; }
13
+ 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); } }
14
+ 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); }); }; }
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+ 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); } }
17
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
18
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
+ 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); }
20
+ var STELLAR_TOML_MAX_SIZE = exports.STELLAR_TOML_MAX_SIZE = 100 * 1024;
21
+ var CancelToken = _axios.default.CancelToken;
22
+ var Resolver = exports.Resolver = function () {
23
+ function Resolver() {
24
+ _classCallCheck(this, Resolver);
25
+ }
26
+ _createClass(Resolver, null, [{
27
+ key: "resolve",
28
+ value: (function () {
29
+ var _resolve = _asyncToGenerator(_regeneratorRuntime().mark(function _callee(domain) {
30
+ var opts,
31
+ allowHttp,
32
+ timeout,
33
+ protocol,
34
+ _args = arguments;
35
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
36
+ while (1) switch (_context.prev = _context.next) {
37
+ case 0:
38
+ opts = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
39
+ allowHttp = typeof opts.allowHttp === "undefined" ? _config.Config.isAllowHttp() : opts.allowHttp;
40
+ timeout = typeof opts.timeout === "undefined" ? _config.Config.getTimeout() : opts.timeout;
41
+ protocol = allowHttp ? "http" : "https";
42
+ return _context.abrupt("return", _axios.default.get("".concat(protocol, "://").concat(domain, "/.well-known/stellar.toml"), {
43
+ maxContentLength: STELLAR_TOML_MAX_SIZE,
44
+ cancelToken: timeout ? new CancelToken(function (cancel) {
45
+ return setTimeout(function () {
46
+ return cancel("timeout of ".concat(timeout, "ms exceeded"));
47
+ }, timeout);
48
+ }) : undefined,
49
+ timeout: timeout
50
+ }).then(function (response) {
51
+ try {
52
+ var tomlObject = _toml.default.parse(response.data);
53
+ return Promise.resolve(tomlObject);
54
+ } catch (e) {
55
+ return Promise.reject(new Error("stellar.toml is invalid - Parsing error on line ".concat(e.line, ", column ").concat(e.column, ": ").concat(e.message)));
56
+ }
57
+ }).catch(function (err) {
58
+ if (err.message.match(/^maxContentLength size/)) {
59
+ throw new Error("stellar.toml file exceeds allowed size of ".concat(STELLAR_TOML_MAX_SIZE));
60
+ } else {
61
+ throw err;
62
+ }
63
+ }));
64
+ case 5:
65
+ case "end":
66
+ return _context.stop();
67
+ }
68
+ }, _callee);
69
+ }));
70
+ function resolve(_x) {
71
+ return _resolve.apply(this, arguments);
72
+ }
73
+ return resolve;
74
+ }())
75
+ }]);
76
+ return Resolver;
77
+ }();
78
+ var Api;
package/lib/utils.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Transaction } from "@stellar/stellar-base";
2
+ export declare class Utils {
3
+ /**
4
+ * Verifies if the current date is within the transaction's timebonds
5
+ *
6
+ * @static
7
+ * @function
8
+ * @param {Transaction} transaction the transaction whose timebonds will be validated.
9
+ * @returns {boolean} returns true if the current time is within the transaction's [minTime, maxTime] range.
10
+ */
11
+ static validateTimebounds(transaction: Transaction, gracePeriod?: number): boolean;
12
+ }
package/lib/utils.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Utils = void 0;
7
+ 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); }
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
+ var Utils = exports.Utils = function () {
14
+ function Utils() {
15
+ _classCallCheck(this, Utils);
16
+ }
17
+ _createClass(Utils, null, [{
18
+ key: "validateTimebounds",
19
+ value: function validateTimebounds(transaction) {
20
+ var gracePeriod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
21
+ if (!transaction.timeBounds) {
22
+ return false;
23
+ }
24
+ var now = Math.floor(Date.now() / 1000);
25
+ var _transaction$timeBoun = transaction.timeBounds,
26
+ minTime = _transaction$timeBoun.minTime,
27
+ maxTime = _transaction$timeBoun.maxTime;
28
+ return now >= Number.parseInt(minTime, 10) - gracePeriod && now <= Number.parseInt(maxTime, 10) + gracePeriod;
29
+ }
30
+ }]);
31
+ return Utils;
32
+ }();
@@ -0,0 +1,4 @@
1
+ export declare class InvalidChallengeError extends Error {
2
+ __proto__: InvalidChallengeError;
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,37 @@
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.InvalidChallengeError = void 0;
8
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
+ 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); }
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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 InvalidChallengeError = exports.InvalidChallengeError = function (_Error) {
24
+ _inherits(InvalidChallengeError, _Error);
25
+ var _super = _createSuper(InvalidChallengeError);
26
+ function InvalidChallengeError(message) {
27
+ var _this;
28
+ _classCallCheck(this, InvalidChallengeError);
29
+ var trueProto = (this instanceof InvalidChallengeError ? this.constructor : void 0).prototype;
30
+ _this = _super.call(this, message);
31
+ _this.__proto__ = trueProto;
32
+ _this.constructor = InvalidChallengeError;
33
+ _this.name = "InvalidChallengeError";
34
+ return _this;
35
+ }
36
+ return _createClass(InvalidChallengeError);
37
+ }(_wrapNativeSuper(Error));
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ export { InvalidChallengeError } from './errors';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ InvalidChallengeError: true
8
+ };
9
+ Object.defineProperty(exports, "InvalidChallengeError", {
10
+ enumerable: true,
11
+ get: function get() {
12
+ return _errors.InvalidChallengeError;
13
+ }
14
+ });
15
+ var _utils = require("./utils");
16
+ Object.keys(_utils).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
+ if (key in exports && exports[key] === _utils[key]) return;
20
+ Object.defineProperty(exports, key, {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _utils[key];
24
+ }
25
+ });
26
+ });
27
+ var _errors = require("./errors");