@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.
- package/CHANGELOG.md +1262 -0
- package/LICENSE +202 -0
- package/README.md +198 -0
- package/dist/stellar-base.js +30777 -0
- package/dist/stellar-base.min.js +2 -0
- package/lib/account.js +80 -0
- package/lib/address.js +169 -0
- package/lib/asset.js +323 -0
- package/lib/auth.js +253 -0
- package/lib/claimant.js +193 -0
- package/lib/contract.js +113 -0
- package/lib/events.js +42 -0
- package/lib/fee_bump_transaction.js +134 -0
- package/lib/generated/curr_generated.js +8315 -0
- package/lib/generated/next_generated.js +8315 -0
- package/lib/get_liquidity_pool_id.js +57 -0
- package/lib/hashing.js +12 -0
- package/lib/index.js +385 -0
- package/lib/invocation.js +195 -0
- package/lib/keypair.js +308 -0
- package/lib/liquidity_pool_asset.js +126 -0
- package/lib/liquidity_pool_id.js +101 -0
- package/lib/memo.js +270 -0
- package/lib/muxed_account.js +159 -0
- package/lib/network.js +22 -0
- package/lib/numbers/index.js +85 -0
- package/lib/numbers/int128.js +50 -0
- package/lib/numbers/int256.js +50 -0
- package/lib/numbers/sc_int.js +134 -0
- package/lib/numbers/uint128.js +50 -0
- package/lib/numbers/uint256.js +50 -0
- package/lib/numbers/xdr_large_int.js +267 -0
- package/lib/operation.js +715 -0
- package/lib/operations/account_merge.js +32 -0
- package/lib/operations/allow_trust.js +57 -0
- package/lib/operations/begin_sponsoring_future_reserves.js +38 -0
- package/lib/operations/bump_sequence.js +37 -0
- package/lib/operations/change_trust.js +52 -0
- package/lib/operations/claim_claimable_balance.js +40 -0
- package/lib/operations/clawback.js +46 -0
- package/lib/operations/clawback_claimable_balance.js +39 -0
- package/lib/operations/create_account.js +37 -0
- package/lib/operations/create_claimable_balance.js +65 -0
- package/lib/operations/create_passive_sell_offer.js +44 -0
- package/lib/operations/end_sponsoring_future_reserves.js +27 -0
- package/lib/operations/extend_footprint_ttl.js +45 -0
- package/lib/operations/index.js +254 -0
- package/lib/operations/inflation.js +23 -0
- package/lib/operations/invoke_host_function.js +219 -0
- package/lib/operations/liquidity_pool_deposit.js +64 -0
- package/lib/operations/liquidity_pool_withdraw.js +50 -0
- package/lib/operations/manage_buy_offer.js +50 -0
- package/lib/operations/manage_data.js +41 -0
- package/lib/operations/manage_sell_offer.js +50 -0
- package/lib/operations/path_payment_strict_receive.js +68 -0
- package/lib/operations/path_payment_strict_send.js +68 -0
- package/lib/operations/payment.js +47 -0
- package/lib/operations/restore_footprint.js +38 -0
- package/lib/operations/revoke_sponsorship.js +301 -0
- package/lib/operations/set_options.js +135 -0
- package/lib/operations/set_trustline_flags.js +84 -0
- package/lib/scval.js +369 -0
- package/lib/signerkey.js +103 -0
- package/lib/signing.js +96 -0
- package/lib/soroban.js +96 -0
- package/lib/sorobandata_builder.js +218 -0
- package/lib/strkey.js +400 -0
- package/lib/transaction.js +369 -0
- package/lib/transaction_base.js +248 -0
- package/lib/transaction_builder.js +753 -0
- package/lib/util/checksum.js +20 -0
- package/lib/util/continued_fraction.js +58 -0
- package/lib/util/decode_encode_muxed_account.js +116 -0
- package/lib/util/util.js +14 -0
- package/lib/xdr.js +9 -0
- package/package.json +133 -0
- package/types/curr.d.ts +14078 -0
- package/types/index.d.ts +1270 -0
- package/types/next.d.ts +14078 -0
- package/types/xdr.d.ts +1 -0
package/lib/memo.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MemoText = exports.MemoReturn = exports.MemoNone = exports.MemoID = exports.MemoHash = exports.Memo = void 0;
|
|
7
|
+
var _jsXdr = require("@stellar/js-xdr");
|
|
8
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
9
|
+
var _xdr = _interopRequireDefault(require("./xdr"));
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
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); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
17
|
+
/**
|
|
18
|
+
* Type of {@link Memo}.
|
|
19
|
+
*/
|
|
20
|
+
var MemoNone = exports.MemoNone = 'none';
|
|
21
|
+
/**
|
|
22
|
+
* Type of {@link Memo}.
|
|
23
|
+
*/
|
|
24
|
+
var MemoID = exports.MemoID = 'id';
|
|
25
|
+
/**
|
|
26
|
+
* Type of {@link Memo}.
|
|
27
|
+
*/
|
|
28
|
+
var MemoText = exports.MemoText = 'text';
|
|
29
|
+
/**
|
|
30
|
+
* Type of {@link Memo}.
|
|
31
|
+
*/
|
|
32
|
+
var MemoHash = exports.MemoHash = 'hash';
|
|
33
|
+
/**
|
|
34
|
+
* Type of {@link Memo}.
|
|
35
|
+
*/
|
|
36
|
+
var MemoReturn = exports.MemoReturn = 'return';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `Memo` represents memos attached to transactions.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} type - `MemoNone`, `MemoID`, `MemoText`, `MemoHash` or `MemoReturn`
|
|
42
|
+
* @param {*} value - `string` for `MemoID`, `MemoText`, buffer of hex string for `MemoHash` or `MemoReturn`
|
|
43
|
+
* @see [Transactions concept](https://developers.stellar.org/docs/glossary/transactions/)
|
|
44
|
+
* @class Memo
|
|
45
|
+
*/
|
|
46
|
+
var Memo = exports.Memo = /*#__PURE__*/function () {
|
|
47
|
+
function Memo(type) {
|
|
48
|
+
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
49
|
+
_classCallCheck(this, Memo);
|
|
50
|
+
this._type = type;
|
|
51
|
+
this._value = value;
|
|
52
|
+
switch (this._type) {
|
|
53
|
+
case MemoNone:
|
|
54
|
+
break;
|
|
55
|
+
case MemoID:
|
|
56
|
+
Memo._validateIdValue(value);
|
|
57
|
+
break;
|
|
58
|
+
case MemoText:
|
|
59
|
+
Memo._validateTextValue(value);
|
|
60
|
+
break;
|
|
61
|
+
case MemoHash:
|
|
62
|
+
case MemoReturn:
|
|
63
|
+
Memo._validateHashValue(value);
|
|
64
|
+
// We want MemoHash and MemoReturn to have Buffer as a value
|
|
65
|
+
if (typeof value === 'string') {
|
|
66
|
+
this._value = Buffer.from(value, 'hex');
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
throw new Error('Invalid memo type');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Contains memo type: `MemoNone`, `MemoID`, `MemoText`, `MemoHash` or `MemoReturn`
|
|
76
|
+
*/
|
|
77
|
+
_createClass(Memo, [{
|
|
78
|
+
key: "type",
|
|
79
|
+
get: function get() {
|
|
80
|
+
return this._type;
|
|
81
|
+
},
|
|
82
|
+
set: function set(type) {
|
|
83
|
+
throw new Error('Memo is immutable');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Contains memo value:
|
|
88
|
+
* * `null` for `MemoNone`,
|
|
89
|
+
* * `string` for `MemoID`,
|
|
90
|
+
* * `Buffer` for `MemoText` after decoding using `fromXDRObject`, original value otherwise,
|
|
91
|
+
* * `Buffer` for `MemoHash`, `MemoReturn`.
|
|
92
|
+
*/
|
|
93
|
+
}, {
|
|
94
|
+
key: "value",
|
|
95
|
+
get: function get() {
|
|
96
|
+
switch (this._type) {
|
|
97
|
+
case MemoNone:
|
|
98
|
+
return null;
|
|
99
|
+
case MemoID:
|
|
100
|
+
case MemoText:
|
|
101
|
+
return this._value;
|
|
102
|
+
case MemoHash:
|
|
103
|
+
case MemoReturn:
|
|
104
|
+
return Buffer.from(this._value);
|
|
105
|
+
default:
|
|
106
|
+
throw new Error('Invalid memo type');
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
set: function set(value) {
|
|
110
|
+
throw new Error('Memo is immutable');
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "toXDRObject",
|
|
114
|
+
value:
|
|
115
|
+
/**
|
|
116
|
+
* Returns XDR memo object.
|
|
117
|
+
* @returns {xdr.Memo}
|
|
118
|
+
*/
|
|
119
|
+
function toXDRObject() {
|
|
120
|
+
switch (this._type) {
|
|
121
|
+
case MemoNone:
|
|
122
|
+
return _xdr["default"].Memo.memoNone();
|
|
123
|
+
case MemoID:
|
|
124
|
+
return _xdr["default"].Memo.memoId(_jsXdr.UnsignedHyper.fromString(this._value));
|
|
125
|
+
case MemoText:
|
|
126
|
+
return _xdr["default"].Memo.memoText(this._value);
|
|
127
|
+
case MemoHash:
|
|
128
|
+
return _xdr["default"].Memo.memoHash(this._value);
|
|
129
|
+
case MemoReturn:
|
|
130
|
+
return _xdr["default"].Memo.memoReturn(this._value);
|
|
131
|
+
default:
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Returns {@link Memo} from XDR memo object.
|
|
138
|
+
* @param {xdr.Memo} object XDR memo object
|
|
139
|
+
* @returns {Memo}
|
|
140
|
+
*/
|
|
141
|
+
}], [{
|
|
142
|
+
key: "_validateIdValue",
|
|
143
|
+
value: function _validateIdValue(value) {
|
|
144
|
+
var error = new Error("Expects a int64 as a string. Got ".concat(value));
|
|
145
|
+
if (typeof value !== 'string') {
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
var number;
|
|
149
|
+
try {
|
|
150
|
+
number = new _bignumber["default"](value);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Infinity
|
|
156
|
+
if (!number.isFinite()) {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// NaN
|
|
161
|
+
if (number.isNaN()) {
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "_validateTextValue",
|
|
167
|
+
value: function _validateTextValue(value) {
|
|
168
|
+
if (!_xdr["default"].Memo.armTypeForArm('text').isValid(value)) {
|
|
169
|
+
throw new Error('Expects string, array or buffer, max 28 bytes');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "_validateHashValue",
|
|
174
|
+
value: function _validateHashValue(value) {
|
|
175
|
+
var error = new Error("Expects a 32 byte hash value or hex encoded string. Got ".concat(value));
|
|
176
|
+
if (value === null || typeof value === 'undefined') {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
var valueBuffer;
|
|
180
|
+
if (typeof value === 'string') {
|
|
181
|
+
if (!/^[0-9A-Fa-f]{64}$/g.test(value)) {
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
valueBuffer = Buffer.from(value, 'hex');
|
|
185
|
+
} else if (Buffer.isBuffer(value)) {
|
|
186
|
+
valueBuffer = Buffer.from(value);
|
|
187
|
+
} else {
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
if (!valueBuffer.length || valueBuffer.length !== 32) {
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns an empty memo (`MemoNone`).
|
|
197
|
+
* @returns {Memo}
|
|
198
|
+
*/
|
|
199
|
+
}, {
|
|
200
|
+
key: "none",
|
|
201
|
+
value: function none() {
|
|
202
|
+
return new Memo(MemoNone);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Creates and returns a `MemoText` memo.
|
|
207
|
+
* @param {string} text - memo text
|
|
208
|
+
* @returns {Memo}
|
|
209
|
+
*/
|
|
210
|
+
}, {
|
|
211
|
+
key: "text",
|
|
212
|
+
value: function text(_text) {
|
|
213
|
+
return new Memo(MemoText, _text);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Creates and returns a `MemoID` memo.
|
|
218
|
+
* @param {string} id - 64-bit number represented as a string
|
|
219
|
+
* @returns {Memo}
|
|
220
|
+
*/
|
|
221
|
+
}, {
|
|
222
|
+
key: "id",
|
|
223
|
+
value: function id(_id) {
|
|
224
|
+
return new Memo(MemoID, _id);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Creates and returns a `MemoHash` memo.
|
|
229
|
+
* @param {array|string} hash - 32 byte hash or hex encoded string
|
|
230
|
+
* @returns {Memo}
|
|
231
|
+
*/
|
|
232
|
+
}, {
|
|
233
|
+
key: "hash",
|
|
234
|
+
value: function hash(_hash) {
|
|
235
|
+
return new Memo(MemoHash, _hash);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Creates and returns a `MemoReturn` memo.
|
|
240
|
+
* @param {array|string} hash - 32 byte hash or hex encoded string
|
|
241
|
+
* @returns {Memo}
|
|
242
|
+
*/
|
|
243
|
+
}, {
|
|
244
|
+
key: "return",
|
|
245
|
+
value: function _return(hash) {
|
|
246
|
+
return new Memo(MemoReturn, hash);
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "fromXDRObject",
|
|
250
|
+
value: function fromXDRObject(object) {
|
|
251
|
+
switch (object.arm()) {
|
|
252
|
+
case 'id':
|
|
253
|
+
return Memo.id(object.value().toString());
|
|
254
|
+
case 'text':
|
|
255
|
+
return Memo.text(object.value());
|
|
256
|
+
case 'hash':
|
|
257
|
+
return Memo.hash(object.value());
|
|
258
|
+
case 'retHash':
|
|
259
|
+
return Memo["return"](object.value());
|
|
260
|
+
default:
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
if (typeof object.value() === 'undefined') {
|
|
264
|
+
return Memo.none();
|
|
265
|
+
}
|
|
266
|
+
throw new Error('Unknown type');
|
|
267
|
+
}
|
|
268
|
+
}]);
|
|
269
|
+
return Memo;
|
|
270
|
+
}();
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MuxedAccount = void 0;
|
|
7
|
+
var _xdr = _interopRequireDefault(require("./xdr"));
|
|
8
|
+
var _account = require("./account");
|
|
9
|
+
var _strkey = require("./strkey");
|
|
10
|
+
var _decode_encode_muxed_account = require("./util/decode_encode_muxed_account");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
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); }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
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); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
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); }
|
|
18
|
+
/**
|
|
19
|
+
* Represents a muxed account for transactions and operations.
|
|
20
|
+
*
|
|
21
|
+
* A muxed (or *multiplexed*) account (defined rigorously in
|
|
22
|
+
* [CAP-27](https://stellar.org/protocol/cap-27) and briefly in
|
|
23
|
+
* [SEP-23](https://stellar.org/protocol/sep-23)) is one that resolves a single
|
|
24
|
+
* Stellar `G...`` account to many different underlying IDs.
|
|
25
|
+
*
|
|
26
|
+
* For example, you may have a single Stellar address for accounting purposes:
|
|
27
|
+
* GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ
|
|
28
|
+
*
|
|
29
|
+
* Yet would like to use it for 4 different family members:
|
|
30
|
+
* 1: MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAAGZFQ
|
|
31
|
+
* 2: MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAALIWQ
|
|
32
|
+
* 3: MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAAPYHQ
|
|
33
|
+
* 4: MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAAQLQQ
|
|
34
|
+
*
|
|
35
|
+
* This object makes it easy to create muxed accounts from regular accounts,
|
|
36
|
+
* duplicate them, get/set the underlying IDs, etc. without mucking around with
|
|
37
|
+
* the raw XDR.
|
|
38
|
+
*
|
|
39
|
+
* Because muxed accounts are purely an off-chain convention, they all share the
|
|
40
|
+
* sequence number tied to their underlying G... account. Thus, this object
|
|
41
|
+
* *requires* an {@link Account} instance to be passed in, so that muxed
|
|
42
|
+
* instances of an account can collectively modify the sequence number whenever
|
|
43
|
+
* a muxed account is used as the source of a @{link Transaction} with {@link
|
|
44
|
+
* TransactionBuilder}.
|
|
45
|
+
*
|
|
46
|
+
* @constructor
|
|
47
|
+
*
|
|
48
|
+
* @param {Account} account - the @{link Account} instance representing the
|
|
49
|
+
* underlying G... address
|
|
50
|
+
* @param {string} id - a stringified uint64 value that represents the
|
|
51
|
+
* ID of the muxed account
|
|
52
|
+
*
|
|
53
|
+
* @link https://developers.stellar.org/docs/glossary/muxed-accounts/
|
|
54
|
+
*/
|
|
55
|
+
var MuxedAccount = exports.MuxedAccount = /*#__PURE__*/function () {
|
|
56
|
+
function MuxedAccount(baseAccount, id) {
|
|
57
|
+
_classCallCheck(this, MuxedAccount);
|
|
58
|
+
var accountId = baseAccount.accountId();
|
|
59
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(accountId)) {
|
|
60
|
+
throw new Error('accountId is invalid');
|
|
61
|
+
}
|
|
62
|
+
this.account = baseAccount;
|
|
63
|
+
this._muxedXdr = (0, _decode_encode_muxed_account.encodeMuxedAccount)(accountId, id);
|
|
64
|
+
this._mAddress = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(this._muxedXdr);
|
|
65
|
+
this._id = id;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Parses an M-address into a MuxedAccount object.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} mAddress - an M-address to transform
|
|
72
|
+
* @param {string} sequenceNum - the sequence number of the underlying {@link
|
|
73
|
+
* Account}, to use for the underlying base account (@link
|
|
74
|
+
* MuxedAccount.baseAccount). If you're using the SDK, you can use
|
|
75
|
+
* `server.loadAccount` to fetch this if you don't know it.
|
|
76
|
+
*
|
|
77
|
+
* @return {MuxedAccount}
|
|
78
|
+
*/
|
|
79
|
+
_createClass(MuxedAccount, [{
|
|
80
|
+
key: "baseAccount",
|
|
81
|
+
value:
|
|
82
|
+
/**
|
|
83
|
+
* @return {Account} the underlying account object shared among all muxed
|
|
84
|
+
* accounts with this Stellar address
|
|
85
|
+
*/
|
|
86
|
+
function baseAccount() {
|
|
87
|
+
return this.account;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @return {string} the M-address representing this account's (G-address, ID)
|
|
92
|
+
*/
|
|
93
|
+
}, {
|
|
94
|
+
key: "accountId",
|
|
95
|
+
value: function accountId() {
|
|
96
|
+
return this._mAddress;
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: "id",
|
|
100
|
+
value: function id() {
|
|
101
|
+
return this._id;
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "setId",
|
|
105
|
+
value: function setId(id) {
|
|
106
|
+
if (typeof id !== 'string') {
|
|
107
|
+
throw new Error('id should be a string representing a number (uint64)');
|
|
108
|
+
}
|
|
109
|
+
this._muxedXdr.med25519().id(_xdr["default"].Uint64.fromString(id));
|
|
110
|
+
this._mAddress = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(this._muxedXdr);
|
|
111
|
+
this._id = id;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Accesses the underlying account's sequence number.
|
|
117
|
+
* @return {string} strigified sequence number for the underlying account
|
|
118
|
+
*/
|
|
119
|
+
}, {
|
|
120
|
+
key: "sequenceNumber",
|
|
121
|
+
value: function sequenceNumber() {
|
|
122
|
+
return this.account.sequenceNumber();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Increments the underlying account's sequence number by one.
|
|
127
|
+
* @return {void}
|
|
128
|
+
*/
|
|
129
|
+
}, {
|
|
130
|
+
key: "incrementSequenceNumber",
|
|
131
|
+
value: function incrementSequenceNumber() {
|
|
132
|
+
return this.account.incrementSequenceNumber();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @return {xdr.MuxedAccount} the XDR object representing this muxed account's
|
|
137
|
+
* G-address and uint64 ID
|
|
138
|
+
*/
|
|
139
|
+
}, {
|
|
140
|
+
key: "toXDRObject",
|
|
141
|
+
value: function toXDRObject() {
|
|
142
|
+
return this._muxedXdr;
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
key: "equals",
|
|
146
|
+
value: function equals(otherMuxedAccount) {
|
|
147
|
+
return this.accountId() === otherMuxedAccount.accountId();
|
|
148
|
+
}
|
|
149
|
+
}], [{
|
|
150
|
+
key: "fromAddress",
|
|
151
|
+
value: function fromAddress(mAddress, sequenceNum) {
|
|
152
|
+
var muxedAccount = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(mAddress);
|
|
153
|
+
var gAddress = (0, _decode_encode_muxed_account.extractBaseAddress)(mAddress);
|
|
154
|
+
var id = muxedAccount.med25519().id().toString();
|
|
155
|
+
return new MuxedAccount(new _account.Account(gAddress, sequenceNum), id);
|
|
156
|
+
}
|
|
157
|
+
}]);
|
|
158
|
+
return MuxedAccount;
|
|
159
|
+
}();
|
package/lib/network.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Networks = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Contains passphrases for common networks:
|
|
9
|
+
* * `Networks.PUBLIC`: `Public Global Stellar Network ; September 2015`
|
|
10
|
+
* * `Networks.TESTNET`: `Test SDF Network ; September 2015`
|
|
11
|
+
* * `Networks.FUTURENET`: `Test SDF Future Network ; October 2022`
|
|
12
|
+
* * `Networks.STANDALONE`: `Standalone Network ; February 2017`
|
|
13
|
+
*
|
|
14
|
+
* @type {{PUBLIC: string, TESTNET: string, FUTURENET: string, STANDALONE: string }}
|
|
15
|
+
*/
|
|
16
|
+
var Networks = exports.Networks = {
|
|
17
|
+
PUBLIC: 'Public Global Stellar Network ; September 2015',
|
|
18
|
+
TESTNET: 'Test SDF Network ; September 2015',
|
|
19
|
+
FUTURENET: 'Test SDF Future Network ; October 2022',
|
|
20
|
+
SANDBOX: 'Local Sandbox Stellar Network ; September 2022',
|
|
21
|
+
STANDALONE: 'Standalone Network ; February 2017'
|
|
22
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Int128", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _int.Int128;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Int256", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _int2.Int256;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ScInt", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _sc_int.ScInt;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Uint128", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _uint.Uint128;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Uint256", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _uint2.Uint256;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "XdrLargeInt", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _xdr_large_int.XdrLargeInt;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
exports.scValToBigInt = scValToBigInt;
|
|
43
|
+
var _xdr_large_int = require("./xdr_large_int");
|
|
44
|
+
var _uint = require("./uint128");
|
|
45
|
+
var _uint2 = require("./uint256");
|
|
46
|
+
var _int = require("./int128");
|
|
47
|
+
var _int2 = require("./int256");
|
|
48
|
+
var _sc_int = require("./sc_int");
|
|
49
|
+
/**
|
|
50
|
+
* Transforms an opaque {@link xdr.ScVal} into a native bigint, if possible.
|
|
51
|
+
*
|
|
52
|
+
* If you then want to use this in the abstractions provided by this module,
|
|
53
|
+
* you can pass it to the constructor of {@link XdrLargeInt}.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* let scv = contract.call("add", x, y); // assume it returns an xdr.ScVal
|
|
57
|
+
* let bigi = scValToBigInt(scv);
|
|
58
|
+
*
|
|
59
|
+
* new ScInt(bigi); // if you don't care about types, and
|
|
60
|
+
* new XdrLargeInt('i128', bigi); // if you do
|
|
61
|
+
*
|
|
62
|
+
* @param {xdr.ScVal} scv - the raw XDR value to parse into an integer
|
|
63
|
+
* @returns {bigint} the native value of this input value
|
|
64
|
+
*
|
|
65
|
+
* @throws {TypeError} if the `scv` input value doesn't represent an integer
|
|
66
|
+
*/
|
|
67
|
+
function scValToBigInt(scv) {
|
|
68
|
+
var scIntType = _xdr_large_int.XdrLargeInt.getType(scv["switch"]().name);
|
|
69
|
+
switch (scv["switch"]().name) {
|
|
70
|
+
case 'scvU32':
|
|
71
|
+
case 'scvI32':
|
|
72
|
+
return BigInt(scv.value());
|
|
73
|
+
case 'scvU64':
|
|
74
|
+
case 'scvI64':
|
|
75
|
+
return new _xdr_large_int.XdrLargeInt(scIntType, scv.value()).toBigInt();
|
|
76
|
+
case 'scvU128':
|
|
77
|
+
case 'scvI128':
|
|
78
|
+
return new _xdr_large_int.XdrLargeInt(scIntType, [scv.value().lo(), scv.value().hi()]).toBigInt();
|
|
79
|
+
case 'scvU256':
|
|
80
|
+
case 'scvI256':
|
|
81
|
+
return new _xdr_large_int.XdrLargeInt(scIntType, [scv.value().loLo(), scv.value().loHi(), scv.value().hiLo(), scv.value().hiHi()]).toBigInt();
|
|
82
|
+
default:
|
|
83
|
+
throw TypeError("expected integer type, got ".concat(scv["switch"]()));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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.Int128 = void 0;
|
|
8
|
+
var _jsXdr = require("@stellar/js-xdr");
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
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); }
|
|
14
|
+
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); }
|
|
15
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
+
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); }; }
|
|
17
|
+
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); }
|
|
18
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
|
+
var Int128 = exports.Int128 = /*#__PURE__*/function (_LargeInt) {
|
|
22
|
+
_inherits(Int128, _LargeInt);
|
|
23
|
+
var _super = _createSuper(Int128);
|
|
24
|
+
/**
|
|
25
|
+
* Construct a signed 128-bit integer that can be XDR-encoded.
|
|
26
|
+
*
|
|
27
|
+
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
28
|
+
* in big-endian format (i.e. earlier elements are higher bits)
|
|
29
|
+
*/
|
|
30
|
+
function Int128() {
|
|
31
|
+
_classCallCheck(this, Int128);
|
|
32
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
+
args[_key] = arguments[_key];
|
|
34
|
+
}
|
|
35
|
+
return _super.call(this, args);
|
|
36
|
+
}
|
|
37
|
+
_createClass(Int128, [{
|
|
38
|
+
key: "unsigned",
|
|
39
|
+
get: function get() {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "size",
|
|
44
|
+
get: function get() {
|
|
45
|
+
return 128;
|
|
46
|
+
}
|
|
47
|
+
}]);
|
|
48
|
+
return Int128;
|
|
49
|
+
}(_jsXdr.LargeInt);
|
|
50
|
+
Int128.defineIntBoundaries();
|
|
@@ -0,0 +1,50 @@
|
|
|
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.Int256 = void 0;
|
|
8
|
+
var _jsXdr = require("@stellar/js-xdr");
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
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); }
|
|
14
|
+
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); }
|
|
15
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
+
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); }; }
|
|
17
|
+
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); }
|
|
18
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
|
+
var Int256 = exports.Int256 = /*#__PURE__*/function (_LargeInt) {
|
|
22
|
+
_inherits(Int256, _LargeInt);
|
|
23
|
+
var _super = _createSuper(Int256);
|
|
24
|
+
/**
|
|
25
|
+
* Construct a signed 256-bit integer that can be XDR-encoded.
|
|
26
|
+
*
|
|
27
|
+
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
28
|
+
* in big-endian format (i.e. earlier elements are higher bits)
|
|
29
|
+
*/
|
|
30
|
+
function Int256() {
|
|
31
|
+
_classCallCheck(this, Int256);
|
|
32
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
+
args[_key] = arguments[_key];
|
|
34
|
+
}
|
|
35
|
+
return _super.call(this, args);
|
|
36
|
+
}
|
|
37
|
+
_createClass(Int256, [{
|
|
38
|
+
key: "unsigned",
|
|
39
|
+
get: function get() {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "size",
|
|
44
|
+
get: function get() {
|
|
45
|
+
return 256;
|
|
46
|
+
}
|
|
47
|
+
}]);
|
|
48
|
+
return Int256;
|
|
49
|
+
}(_jsXdr.LargeInt);
|
|
50
|
+
Int256.defineIntBoundaries();
|