@stellar/stellar-base 10.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 (80) hide show
  1. package/CHANGELOG.md +1262 -0
  2. package/LICENSE +202 -0
  3. package/README.md +198 -0
  4. package/dist/stellar-base.js +30777 -0
  5. package/dist/stellar-base.min.js +2 -0
  6. package/lib/account.js +80 -0
  7. package/lib/address.js +169 -0
  8. package/lib/asset.js +323 -0
  9. package/lib/auth.js +253 -0
  10. package/lib/claimant.js +193 -0
  11. package/lib/contract.js +113 -0
  12. package/lib/events.js +42 -0
  13. package/lib/fee_bump_transaction.js +134 -0
  14. package/lib/generated/curr_generated.js +8315 -0
  15. package/lib/generated/next_generated.js +8315 -0
  16. package/lib/get_liquidity_pool_id.js +57 -0
  17. package/lib/hashing.js +12 -0
  18. package/lib/index.js +385 -0
  19. package/lib/invocation.js +195 -0
  20. package/lib/keypair.js +308 -0
  21. package/lib/liquidity_pool_asset.js +126 -0
  22. package/lib/liquidity_pool_id.js +101 -0
  23. package/lib/memo.js +270 -0
  24. package/lib/muxed_account.js +159 -0
  25. package/lib/network.js +22 -0
  26. package/lib/numbers/index.js +85 -0
  27. package/lib/numbers/int128.js +50 -0
  28. package/lib/numbers/int256.js +50 -0
  29. package/lib/numbers/sc_int.js +134 -0
  30. package/lib/numbers/uint128.js +50 -0
  31. package/lib/numbers/uint256.js +50 -0
  32. package/lib/numbers/xdr_large_int.js +267 -0
  33. package/lib/operation.js +715 -0
  34. package/lib/operations/account_merge.js +32 -0
  35. package/lib/operations/allow_trust.js +57 -0
  36. package/lib/operations/begin_sponsoring_future_reserves.js +38 -0
  37. package/lib/operations/bump_sequence.js +37 -0
  38. package/lib/operations/change_trust.js +52 -0
  39. package/lib/operations/claim_claimable_balance.js +40 -0
  40. package/lib/operations/clawback.js +46 -0
  41. package/lib/operations/clawback_claimable_balance.js +39 -0
  42. package/lib/operations/create_account.js +37 -0
  43. package/lib/operations/create_claimable_balance.js +65 -0
  44. package/lib/operations/create_passive_sell_offer.js +44 -0
  45. package/lib/operations/end_sponsoring_future_reserves.js +27 -0
  46. package/lib/operations/extend_footprint_ttl.js +45 -0
  47. package/lib/operations/index.js +254 -0
  48. package/lib/operations/inflation.js +23 -0
  49. package/lib/operations/invoke_host_function.js +219 -0
  50. package/lib/operations/liquidity_pool_deposit.js +64 -0
  51. package/lib/operations/liquidity_pool_withdraw.js +50 -0
  52. package/lib/operations/manage_buy_offer.js +50 -0
  53. package/lib/operations/manage_data.js +41 -0
  54. package/lib/operations/manage_sell_offer.js +50 -0
  55. package/lib/operations/path_payment_strict_receive.js +68 -0
  56. package/lib/operations/path_payment_strict_send.js +68 -0
  57. package/lib/operations/payment.js +47 -0
  58. package/lib/operations/restore_footprint.js +38 -0
  59. package/lib/operations/revoke_sponsorship.js +301 -0
  60. package/lib/operations/set_options.js +135 -0
  61. package/lib/operations/set_trustline_flags.js +84 -0
  62. package/lib/scval.js +369 -0
  63. package/lib/signerkey.js +103 -0
  64. package/lib/signing.js +96 -0
  65. package/lib/soroban.js +96 -0
  66. package/lib/sorobandata_builder.js +218 -0
  67. package/lib/strkey.js +400 -0
  68. package/lib/transaction.js +369 -0
  69. package/lib/transaction_base.js +248 -0
  70. package/lib/transaction_builder.js +753 -0
  71. package/lib/util/checksum.js +20 -0
  72. package/lib/util/continued_fraction.js +58 -0
  73. package/lib/util/decode_encode_muxed_account.js +116 -0
  74. package/lib/util/util.js +14 -0
  75. package/lib/xdr.js +9 -0
  76. package/package.json +133 -0
  77. package/types/curr.d.ts +14078 -0
  78. package/types/index.d.ts +1270 -0
  79. package/types/next.d.ts +14078 -0
  80. package/types/xdr.d.ts +1 -0
package/lib/keypair.js ADDED
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Keypair = void 0;
7
+ var _tweetnacl = _interopRequireDefault(require("tweetnacl"));
8
+ var _signing = require("./signing");
9
+ var _strkey = require("./strkey");
10
+ var _hashing = require("./hashing");
11
+ var _xdr = _interopRequireDefault(require("./xdr"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+ 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); }
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+ 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); } }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
+ 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); } /* eslint no-bitwise: ["error", {"allow": ["^"]}] */
19
+ /**
20
+ * `Keypair` represents public (and secret) keys of the account.
21
+ *
22
+ * Currently `Keypair` only supports ed25519 but in a future this class can be abstraction layer for other
23
+ * public-key signature systems.
24
+ *
25
+ * Use more convenient methods to create `Keypair` object:
26
+ * * `{@link Keypair.fromPublicKey}`
27
+ * * `{@link Keypair.fromSecret}`
28
+ * * `{@link Keypair.random}`
29
+ *
30
+ * @constructor
31
+ * @param {object} keys At least one of keys must be provided.
32
+ * @param {string} keys.type Public-key signature system name. (currently only `ed25519` keys are supported)
33
+ * @param {Buffer} [keys.publicKey] Raw public key
34
+ * @param {Buffer} [keys.secretKey] Raw secret key (32-byte secret seed in ed25519`)
35
+ */
36
+ var Keypair = exports.Keypair = /*#__PURE__*/function () {
37
+ function Keypair(keys) {
38
+ _classCallCheck(this, Keypair);
39
+ if (keys.type !== 'ed25519') {
40
+ throw new Error('Invalid keys type');
41
+ }
42
+ this.type = keys.type;
43
+ if (keys.secretKey) {
44
+ keys.secretKey = Buffer.from(keys.secretKey);
45
+ if (keys.secretKey.length !== 32) {
46
+ throw new Error('secretKey length is invalid');
47
+ }
48
+ this._secretSeed = keys.secretKey;
49
+ this._publicKey = (0, _signing.generate)(keys.secretKey);
50
+ this._secretKey = Buffer.concat([keys.secretKey, this._publicKey]);
51
+ if (keys.publicKey && !this._publicKey.equals(Buffer.from(keys.publicKey))) {
52
+ throw new Error('secretKey does not match publicKey');
53
+ }
54
+ } else {
55
+ this._publicKey = Buffer.from(keys.publicKey);
56
+ if (this._publicKey.length !== 32) {
57
+ throw new Error('publicKey length is invalid');
58
+ }
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Creates a new `Keypair` instance from secret. This can either be secret key or secret seed depending
64
+ * on underlying public-key signature system. Currently `Keypair` only supports ed25519.
65
+ * @param {string} secret secret key (ex. `SDAKFNYEIAORZKKCYRILFQKLLOCNPL5SWJ3YY5NM3ZH6GJSZGXHZEPQS`)
66
+ * @returns {Keypair}
67
+ */
68
+ _createClass(Keypair, [{
69
+ key: "xdrAccountId",
70
+ value: function xdrAccountId() {
71
+ return new _xdr["default"].AccountId.publicKeyTypeEd25519(this._publicKey);
72
+ }
73
+ }, {
74
+ key: "xdrPublicKey",
75
+ value: function xdrPublicKey() {
76
+ return new _xdr["default"].PublicKey.publicKeyTypeEd25519(this._publicKey);
77
+ }
78
+
79
+ /**
80
+ * Creates a {@link xdr.MuxedAccount} object from the public key.
81
+ *
82
+ * You will get a different type of muxed account depending on whether or not
83
+ * you pass an ID.
84
+ *
85
+ * @param {string} [id] - stringified integer indicating the underlying muxed
86
+ * ID of the new account object
87
+ *
88
+ * @return {xdr.MuxedAccount}
89
+ */
90
+ }, {
91
+ key: "xdrMuxedAccount",
92
+ value: function xdrMuxedAccount(id) {
93
+ if (typeof id !== 'undefined') {
94
+ if (typeof id !== 'string') {
95
+ throw new TypeError("expected string for ID, got ".concat(_typeof(id)));
96
+ }
97
+ return _xdr["default"].MuxedAccount.keyTypeMuxedEd25519(new _xdr["default"].MuxedAccountMed25519({
98
+ id: _xdr["default"].Uint64.fromString(id),
99
+ ed25519: this._publicKey
100
+ }));
101
+ }
102
+ return new _xdr["default"].MuxedAccount.keyTypeEd25519(this._publicKey);
103
+ }
104
+
105
+ /**
106
+ * Returns raw public key
107
+ * @returns {Buffer}
108
+ */
109
+ }, {
110
+ key: "rawPublicKey",
111
+ value: function rawPublicKey() {
112
+ return this._publicKey;
113
+ }
114
+ }, {
115
+ key: "signatureHint",
116
+ value: function signatureHint() {
117
+ var a = this.xdrAccountId().toXDR();
118
+ return a.slice(a.length - 4);
119
+ }
120
+
121
+ /**
122
+ * Returns public key associated with this `Keypair` object.
123
+ * @returns {string}
124
+ */
125
+ }, {
126
+ key: "publicKey",
127
+ value: function publicKey() {
128
+ return _strkey.StrKey.encodeEd25519PublicKey(this._publicKey);
129
+ }
130
+
131
+ /**
132
+ * Returns secret key associated with this `Keypair` object
133
+ * @returns {string}
134
+ */
135
+ }, {
136
+ key: "secret",
137
+ value: function secret() {
138
+ if (!this._secretSeed) {
139
+ throw new Error('no secret key available');
140
+ }
141
+ if (this.type === 'ed25519') {
142
+ return _strkey.StrKey.encodeEd25519SecretSeed(this._secretSeed);
143
+ }
144
+ throw new Error('Invalid Keypair type');
145
+ }
146
+
147
+ /**
148
+ * Returns raw secret key.
149
+ * @returns {Buffer}
150
+ */
151
+ }, {
152
+ key: "rawSecretKey",
153
+ value: function rawSecretKey() {
154
+ return this._secretSeed;
155
+ }
156
+
157
+ /**
158
+ * Returns `true` if this `Keypair` object contains secret key and can sign.
159
+ * @returns {boolean}
160
+ */
161
+ }, {
162
+ key: "canSign",
163
+ value: function canSign() {
164
+ return !!this._secretKey;
165
+ }
166
+
167
+ /**
168
+ * Signs data.
169
+ * @param {Buffer} data Data to sign
170
+ * @returns {Buffer}
171
+ */
172
+ }, {
173
+ key: "sign",
174
+ value: function sign(data) {
175
+ if (!this.canSign()) {
176
+ throw new Error('cannot sign: no secret key available');
177
+ }
178
+ return (0, _signing.sign)(data, this._secretKey);
179
+ }
180
+
181
+ /**
182
+ * Verifies if `signature` for `data` is valid.
183
+ * @param {Buffer} data Signed data
184
+ * @param {Buffer} signature Signature
185
+ * @returns {boolean}
186
+ */
187
+ }, {
188
+ key: "verify",
189
+ value: function verify(data, signature) {
190
+ return (0, _signing.verify)(data, signature, this._publicKey);
191
+ }
192
+
193
+ /**
194
+ * Returns the decorated signature (hint+sig) for arbitrary data.
195
+ *
196
+ * @param {Buffer} data arbitrary data to sign
197
+ * @return {xdr.DecoratedSignature} the raw signature structure which can be
198
+ * added directly to a transaction envelope
199
+ *
200
+ * @see TransactionBase.addDecoratedSignature
201
+ */
202
+ }, {
203
+ key: "signDecorated",
204
+ value: function signDecorated(data) {
205
+ var signature = this.sign(data);
206
+ var hint = this.signatureHint();
207
+ return new _xdr["default"].DecoratedSignature({
208
+ hint: hint,
209
+ signature: signature
210
+ });
211
+ }
212
+
213
+ /**
214
+ * Returns the raw decorated signature (hint+sig) for a signed payload signer.
215
+ *
216
+ * The hint is defined as the last 4 bytes of the signer key XORed with last
217
+ * 4 bytes of the payload (zero-left-padded if necessary).
218
+ *
219
+ * @param {Buffer} data data to both sign and treat as the payload
220
+ * @return {xdr.DecoratedSignature}
221
+ *
222
+ * @see https://github.com/stellar/stellar-protocol/blob/master/core/cap-0040.md#signature-hint
223
+ * @see TransactionBase.addDecoratedSignature
224
+ */
225
+ }, {
226
+ key: "signPayloadDecorated",
227
+ value: function signPayloadDecorated(data) {
228
+ var signature = this.sign(data);
229
+ var keyHint = this.signatureHint();
230
+ var hint = Buffer.from(data.slice(-4));
231
+ if (hint.length < 4) {
232
+ // append zeroes as needed
233
+ hint = Buffer.concat([hint, Buffer.alloc(4 - data.length, 0)]);
234
+ }
235
+ return new _xdr["default"].DecoratedSignature({
236
+ hint: hint.map(function (_byte, i) {
237
+ return _byte ^ keyHint[i];
238
+ }),
239
+ signature: signature
240
+ });
241
+ }
242
+ }], [{
243
+ key: "fromSecret",
244
+ value: function fromSecret(secret) {
245
+ var rawSecret = _strkey.StrKey.decodeEd25519SecretSeed(secret);
246
+ return this.fromRawEd25519Seed(rawSecret);
247
+ }
248
+
249
+ /**
250
+ * Creates a new `Keypair` object from ed25519 secret key seed raw bytes.
251
+ *
252
+ * @param {Buffer} rawSeed Raw 32-byte ed25519 secret key seed
253
+ * @returns {Keypair}
254
+ */
255
+ }, {
256
+ key: "fromRawEd25519Seed",
257
+ value: function fromRawEd25519Seed(rawSeed) {
258
+ return new this({
259
+ type: 'ed25519',
260
+ secretKey: rawSeed
261
+ });
262
+ }
263
+
264
+ /**
265
+ * Returns `Keypair` object representing network master key.
266
+ * @param {string} networkPassphrase passphrase of the target stellar network (e.g. "Public Global Stellar Network ; September 2015").
267
+ * @returns {Keypair}
268
+ */
269
+ }, {
270
+ key: "master",
271
+ value: function master(networkPassphrase) {
272
+ if (!networkPassphrase) {
273
+ throw new Error('No network selected. Please pass a network argument, e.g. `Keypair.master(Networks.PUBLIC)`.');
274
+ }
275
+ return this.fromRawEd25519Seed((0, _hashing.hash)(networkPassphrase));
276
+ }
277
+
278
+ /**
279
+ * Creates a new `Keypair` object from public key.
280
+ * @param {string} publicKey public key (ex. `GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA`)
281
+ * @returns {Keypair}
282
+ */
283
+ }, {
284
+ key: "fromPublicKey",
285
+ value: function fromPublicKey(publicKey) {
286
+ publicKey = _strkey.StrKey.decodeEd25519PublicKey(publicKey);
287
+ if (publicKey.length !== 32) {
288
+ throw new Error('Invalid Stellar public key');
289
+ }
290
+ return new this({
291
+ type: 'ed25519',
292
+ publicKey: publicKey
293
+ });
294
+ }
295
+
296
+ /**
297
+ * Create a random `Keypair` object.
298
+ * @returns {Keypair}
299
+ */
300
+ }, {
301
+ key: "random",
302
+ value: function random() {
303
+ var secret = _tweetnacl["default"].randomBytes(32);
304
+ return this.fromRawEd25519Seed(secret);
305
+ }
306
+ }]);
307
+ return Keypair;
308
+ }();
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LiquidityPoolAsset = void 0;
7
+ var _xdr = _interopRequireDefault(require("./xdr"));
8
+ var _asset = require("./asset");
9
+ var _get_liquidity_pool_id = require("./get_liquidity_pool_id");
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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
+ /**
21
+ * LiquidityPoolAsset class represents a liquidity pool trustline change.
22
+ *
23
+ * @constructor
24
+ * @param {Asset} assetA – The first asset in the Pool, it must respect the rule assetA < assetB. See {@link Asset.compare} for more details on how assets are sorted.
25
+ * @param {Asset} assetB – The second asset in the Pool, it must respect the rule assetA < assetB. See {@link Asset.compare} for more details on how assets are sorted.
26
+ * @param {number} fee – The liquidity pool fee. For now the only fee supported is `30`.
27
+ */
28
+ var LiquidityPoolAsset = exports.LiquidityPoolAsset = /*#__PURE__*/function () {
29
+ function LiquidityPoolAsset(assetA, assetB, fee) {
30
+ _classCallCheck(this, LiquidityPoolAsset);
31
+ if (!assetA || !(assetA instanceof _asset.Asset)) {
32
+ throw new Error('assetA is invalid');
33
+ }
34
+ if (!assetB || !(assetB instanceof _asset.Asset)) {
35
+ throw new Error('assetB is invalid');
36
+ }
37
+ if (_asset.Asset.compare(assetA, assetB) !== -1) {
38
+ throw new Error('Assets are not in lexicographic order');
39
+ }
40
+ if (!fee || fee !== _get_liquidity_pool_id.LiquidityPoolFeeV18) {
41
+ throw new Error('fee is invalid');
42
+ }
43
+ this.assetA = assetA;
44
+ this.assetB = assetB;
45
+ this.fee = fee;
46
+ }
47
+
48
+ /**
49
+ * Returns a liquidity pool asset object from its XDR ChangeTrustAsset object
50
+ * representation.
51
+ * @param {xdr.ChangeTrustAsset} ctAssetXdr - The asset XDR object.
52
+ * @returns {LiquidityPoolAsset}
53
+ */
54
+ _createClass(LiquidityPoolAsset, [{
55
+ key: "toXDRObject",
56
+ value:
57
+ /**
58
+ * Returns the `xdr.ChangeTrustAsset` object for this liquidity pool asset.
59
+ *
60
+ * Note: To convert from an {@link Asset `Asset`} to `xdr.ChangeTrustAsset`
61
+ * please refer to the
62
+ * {@link Asset.toChangeTrustXDRObject `Asset.toChangeTrustXDRObject`} method.
63
+ *
64
+ * @returns {xdr.ChangeTrustAsset} XDR ChangeTrustAsset object.
65
+ */
66
+ function toXDRObject() {
67
+ var lpConstantProductParamsXdr = new _xdr["default"].LiquidityPoolConstantProductParameters({
68
+ assetA: this.assetA.toXDRObject(),
69
+ assetB: this.assetB.toXDRObject(),
70
+ fee: this.fee
71
+ });
72
+ var lpParamsXdr = new _xdr["default"].LiquidityPoolParameters('liquidityPoolConstantProduct', lpConstantProductParamsXdr);
73
+ return new _xdr["default"].ChangeTrustAsset('assetTypePoolShare', lpParamsXdr);
74
+ }
75
+
76
+ /**
77
+ * @returns {LiquidityPoolParameters} Liquidity pool parameters.
78
+ */
79
+ }, {
80
+ key: "getLiquidityPoolParameters",
81
+ value: function getLiquidityPoolParameters() {
82
+ return _objectSpread(_objectSpread({}, this), {}, {
83
+ assetA: this.assetA,
84
+ assetB: this.assetB,
85
+ fee: this.fee
86
+ });
87
+ }
88
+
89
+ /**
90
+ * @see [Assets concept](https://developers.stellar.org/docs/glossary/assets/)
91
+ * @returns {AssetType.liquidityPoolShares} asset type. Can only be `liquidity_pool_shares`.
92
+ */
93
+ }, {
94
+ key: "getAssetType",
95
+ value: function getAssetType() {
96
+ return 'liquidity_pool_shares';
97
+ }
98
+
99
+ /**
100
+ * @param {LiquidityPoolAsset} other the LiquidityPoolAsset to compare
101
+ * @returns {boolean} `true` if this asset equals the given asset.
102
+ */
103
+ }, {
104
+ key: "equals",
105
+ value: function equals(other) {
106
+ return this.assetA.equals(other.assetA) && this.assetB.equals(other.assetB) && this.fee === other.fee;
107
+ }
108
+ }, {
109
+ key: "toString",
110
+ value: function toString() {
111
+ var poolId = (0, _get_liquidity_pool_id.getLiquidityPoolId)('constant_product', this.getLiquidityPoolParameters()).toString('hex');
112
+ return "liquidity_pool:".concat(poolId);
113
+ }
114
+ }], [{
115
+ key: "fromOperation",
116
+ value: function fromOperation(ctAssetXdr) {
117
+ var assetType = ctAssetXdr["switch"]();
118
+ if (assetType === _xdr["default"].AssetType.assetTypePoolShare()) {
119
+ var liquidityPoolParameters = ctAssetXdr.liquidityPool().constantProduct();
120
+ return new this(_asset.Asset.fromOperation(liquidityPoolParameters.assetA()), _asset.Asset.fromOperation(liquidityPoolParameters.assetB()), liquidityPoolParameters.fee());
121
+ }
122
+ throw new Error("Invalid asset type: ".concat(assetType.name));
123
+ }
124
+ }]);
125
+ return LiquidityPoolAsset;
126
+ }();
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LiquidityPoolId = void 0;
7
+ var _xdr = _interopRequireDefault(require("./xdr"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ 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); }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
15
+ /**
16
+ * LiquidityPoolId class represents the asset referenced by a trustline to a
17
+ * liquidity pool.
18
+ *
19
+ * @constructor
20
+ * @param {string} liquidityPoolId - The ID of the liquidity pool in string 'hex'.
21
+ */
22
+ var LiquidityPoolId = exports.LiquidityPoolId = /*#__PURE__*/function () {
23
+ function LiquidityPoolId(liquidityPoolId) {
24
+ _classCallCheck(this, LiquidityPoolId);
25
+ if (!liquidityPoolId) {
26
+ throw new Error('liquidityPoolId cannot be empty');
27
+ }
28
+ if (!/^[a-f0-9]{64}$/.test(liquidityPoolId)) {
29
+ throw new Error('Liquidity pool ID is not a valid hash');
30
+ }
31
+ this.liquidityPoolId = liquidityPoolId;
32
+ }
33
+
34
+ /**
35
+ * Returns a liquidity pool ID object from its xdr.TrustLineAsset representation.
36
+ * @param {xdr.TrustLineAsset} tlAssetXdr - The asset XDR object.
37
+ * @returns {LiquidityPoolId}
38
+ */
39
+ _createClass(LiquidityPoolId, [{
40
+ key: "toXDRObject",
41
+ value:
42
+ /**
43
+ * Returns the `xdr.TrustLineAsset` object for this liquidity pool ID.
44
+ *
45
+ * Note: To convert from {@link Asset `Asset`} to `xdr.TrustLineAsset` please
46
+ * refer to the
47
+ * {@link Asset.toTrustLineXDRObject `Asset.toTrustLineXDRObject`} method.
48
+ *
49
+ * @returns {xdr.TrustLineAsset} XDR LiquidityPoolId object
50
+ */
51
+ function toXDRObject() {
52
+ var xdrPoolId = _xdr["default"].PoolId.fromXDR(this.liquidityPoolId, 'hex');
53
+ return new _xdr["default"].TrustLineAsset('assetTypePoolShare', xdrPoolId);
54
+ }
55
+
56
+ /**
57
+ * @returns {string} Liquidity pool ID.
58
+ */
59
+ }, {
60
+ key: "getLiquidityPoolId",
61
+ value: function getLiquidityPoolId() {
62
+ return String(this.liquidityPoolId);
63
+ }
64
+
65
+ /**
66
+ * @see [Assets concept](https://developers.stellar.org/docs/glossary/assets/)
67
+ * @returns {AssetType.liquidityPoolShares} asset type. Can only be `liquidity_pool_shares`.
68
+ */
69
+ }, {
70
+ key: "getAssetType",
71
+ value: function getAssetType() {
72
+ return 'liquidity_pool_shares';
73
+ }
74
+
75
+ /**
76
+ * @param {LiquidityPoolId} asset LiquidityPoolId to compare.
77
+ * @returns {boolean} `true` if this asset equals the given asset.
78
+ */
79
+ }, {
80
+ key: "equals",
81
+ value: function equals(asset) {
82
+ return this.liquidityPoolId === asset.getLiquidityPoolId();
83
+ }
84
+ }, {
85
+ key: "toString",
86
+ value: function toString() {
87
+ return "liquidity_pool:".concat(this.liquidityPoolId);
88
+ }
89
+ }], [{
90
+ key: "fromOperation",
91
+ value: function fromOperation(tlAssetXdr) {
92
+ var assetType = tlAssetXdr["switch"]();
93
+ if (assetType === _xdr["default"].AssetType.assetTypePoolShare()) {
94
+ var liquidityPoolId = tlAssetXdr.liquidityPoolId().toString('hex');
95
+ return new this(liquidityPoolId);
96
+ }
97
+ throw new Error("Invalid asset type: ".concat(assetType.name));
98
+ }
99
+ }]);
100
+ return LiquidityPoolId;
101
+ }();