@stellar/stellar-base 12.0.1 → 12.1.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/lib/address.js CHANGED
@@ -36,7 +36,7 @@ var Address = exports.Address = /*#__PURE__*/function () {
36
36
  this._type = 'contract';
37
37
  this._key = _strkey.StrKey.decodeContract(address);
38
38
  } else {
39
- throw new Error('Unsupported address type');
39
+ throw new Error("Unsupported address type: ".concat(address));
40
40
  }
41
41
  }
42
42
 
package/lib/asset.js CHANGED
@@ -176,12 +176,12 @@ var Asset = exports.Asset = /*#__PURE__*/function () {
176
176
  }, {
177
177
  key: "getAssetType",
178
178
  value: function getAssetType() {
179
- switch (this.getRawAssetType()) {
180
- case _xdr["default"].AssetType.assetTypeNative():
179
+ switch (this.getRawAssetType().value) {
180
+ case _xdr["default"].AssetType.assetTypeNative().value:
181
181
  return 'native';
182
- case _xdr["default"].AssetType.assetTypeCreditAlphanum4():
182
+ case _xdr["default"].AssetType.assetTypeCreditAlphanum4().value:
183
183
  return 'credit_alphanum4';
184
- case _xdr["default"].AssetType.assetTypeCreditAlphanum12():
184
+ case _xdr["default"].AssetType.assetTypeCreditAlphanum12().value:
185
185
  return 'credit_alphanum12';
186
186
  default:
187
187
  return 'unknown';
package/lib/events.js CHANGED
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.humanizeEvents = humanizeEvents;
7
- var _xdr = _interopRequireDefault(require("./xdr"));
8
7
  var _strkey = require("./strkey");
9
8
  var _scval = require("./scval");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
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); }
12
10
  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
11
  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; }
@@ -30,14 +28,16 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
30
28
  */
31
29
  function humanizeEvents(events) {
32
30
  return events.map(function (e) {
33
- if (e instanceof _xdr["default"].DiagnosticEvent) {
31
+ // A pseudo-instanceof check for xdr.DiagnosticEvent more reliable
32
+ // in mixed SDK environments:
33
+ if (e.inSuccessfulContractCall) {
34
34
  return extractEvent(e.event());
35
35
  }
36
36
  return extractEvent(e);
37
37
  });
38
38
  }
39
39
  function extractEvent(event) {
40
- return _objectSpread(_objectSpread({}, event.contractId() != null && {
40
+ return _objectSpread(_objectSpread({}, typeof event.contractId === 'function' && event.contractId() != null && {
41
41
  contractId: _strkey.StrKey.encodeContract(event.contractId())
42
42
  }), {}, {
43
43
  type: event.type().name,
package/lib/scval.js CHANGED
@@ -150,75 +150,87 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
150
150
  * scValToNative(scv) == gigaMap; // true
151
151
  */
152
152
  function nativeToScVal(val) {
153
- var _val$constructor$name, _val$constructor;
154
153
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
155
154
  switch (_typeof(val)) {
156
155
  case 'object':
157
- if (val === null) {
158
- return _xdr["default"].ScVal.scvVoid();
159
- }
160
- if (val instanceof _xdr["default"].ScVal) {
161
- return val; // should we copy?
162
- }
163
- if (val instanceof _address.Address) {
164
- return val.toScVal();
165
- }
166
- if (val instanceof _contract.Contract) {
167
- return val.address().toScVal();
168
- }
169
- if (val instanceof Uint8Array || Buffer.isBuffer(val)) {
170
- var _opts$type;
171
- var copy = Uint8Array.from(val);
172
- switch ((_opts$type = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type !== void 0 ? _opts$type : 'bytes') {
173
- case 'bytes':
174
- return _xdr["default"].ScVal.scvBytes(copy);
175
- case 'symbol':
176
- return _xdr["default"].ScVal.scvSymbol(copy);
177
- case 'string':
178
- return _xdr["default"].ScVal.scvString(copy);
179
- default:
180
- throw new TypeError("invalid type (".concat(opts.type, ") specified for bytes-like value"));
156
+ {
157
+ var _val$constructor$name, _val$constructor;
158
+ if (val === null) {
159
+ return _xdr["default"].ScVal.scvVoid();
181
160
  }
182
- }
183
- if (Array.isArray(val)) {
184
- if (val.length > 0 && val.some(function (v) {
185
- return _typeof(v) !== _typeof(val[0]);
186
- })) {
187
- throw new TypeError("array values (".concat(val, ") must have the same type (types: ").concat(val.map(function (v) {
188
- return _typeof(v);
189
- }).join(','), ")"));
161
+ if (val instanceof _xdr["default"].ScVal) {
162
+ return val; // should we copy?
190
163
  }
191
- return _xdr["default"].ScVal.scvVec(val.map(function (v) {
192
- return nativeToScVal(v, opts);
164
+ if (val instanceof _address.Address) {
165
+ return val.toScVal();
166
+ }
167
+ if (val instanceof _contract.Contract) {
168
+ return val.address().toScVal();
169
+ }
170
+ if (val instanceof Uint8Array || Buffer.isBuffer(val)) {
171
+ var _opts$type;
172
+ var copy = Uint8Array.from(val);
173
+ switch ((_opts$type = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type !== void 0 ? _opts$type : 'bytes') {
174
+ case 'bytes':
175
+ return _xdr["default"].ScVal.scvBytes(copy);
176
+ case 'symbol':
177
+ return _xdr["default"].ScVal.scvSymbol(copy);
178
+ case 'string':
179
+ return _xdr["default"].ScVal.scvString(copy);
180
+ default:
181
+ throw new TypeError("invalid type (".concat(opts.type, ") specified for bytes-like value"));
182
+ }
183
+ }
184
+ if (Array.isArray(val)) {
185
+ if (val.length > 0 && val.some(function (v) {
186
+ return _typeof(v) !== _typeof(val[0]);
187
+ })) {
188
+ throw new TypeError("array values (".concat(val, ") must have the same type (types: ").concat(val.map(function (v) {
189
+ return _typeof(v);
190
+ }).join(','), ")"));
191
+ }
192
+ return _xdr["default"].ScVal.scvVec(val.map(function (v) {
193
+ return nativeToScVal(v, opts);
194
+ }));
195
+ }
196
+ if (((_val$constructor$name = (_val$constructor = val.constructor) === null || _val$constructor === void 0 ? void 0 : _val$constructor.name) !== null && _val$constructor$name !== void 0 ? _val$constructor$name : '') !== 'Object') {
197
+ var _val$constructor2;
198
+ throw new TypeError("cannot interpret ".concat((_val$constructor2 = val.constructor) === null || _val$constructor2 === void 0 ? void 0 : _val$constructor2.name, " value as ScVal (").concat(JSON.stringify(val), ")"));
199
+ }
200
+ return _xdr["default"].ScVal.scvMap(Object.entries(val)
201
+ // The Soroban runtime expects maps to have their keys in sorted
202
+ // order, so let's do that here as part of the conversion to prevent
203
+ // confusing error messages on execution.
204
+ .sort(function (_ref, _ref2) {
205
+ var _ref3 = _slicedToArray(_ref, 1),
206
+ key1 = _ref3[0];
207
+ var _ref4 = _slicedToArray(_ref2, 1),
208
+ key2 = _ref4[0];
209
+ return key1.localeCompare(key2);
210
+ }).map(function (_ref5) {
211
+ var _k, _opts$type2;
212
+ var _ref6 = _slicedToArray(_ref5, 2),
213
+ k = _ref6[0],
214
+ v = _ref6[1];
215
+ // the type can be specified with an entry for the key and the value,
216
+ // e.g. val = { 'hello': 1 } and opts.type = { hello: [ 'symbol',
217
+ // 'u128' ]} or you can use `null` for the default interpretation
218
+ var _ref7 = (_k = ((_opts$type2 = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type2 !== void 0 ? _opts$type2 : {})[k]) !== null && _k !== void 0 ? _k : [null, null],
219
+ _ref8 = _slicedToArray(_ref7, 2),
220
+ keyType = _ref8[0],
221
+ valType = _ref8[1];
222
+ var keyOpts = keyType ? {
223
+ type: keyType
224
+ } : {};
225
+ var valOpts = valType ? {
226
+ type: valType
227
+ } : {};
228
+ return new _xdr["default"].ScMapEntry({
229
+ key: nativeToScVal(k, keyOpts),
230
+ val: nativeToScVal(v, valOpts)
231
+ });
193
232
  }));
194
233
  }
195
- if (((_val$constructor$name = (_val$constructor = val.constructor) === null || _val$constructor === void 0 ? void 0 : _val$constructor.name) !== null && _val$constructor$name !== void 0 ? _val$constructor$name : '') !== 'Object') {
196
- var _val$constructor2;
197
- throw new TypeError("cannot interpret ".concat((_val$constructor2 = val.constructor) === null || _val$constructor2 === void 0 ? void 0 : _val$constructor2.name, " value as ScVal (").concat(JSON.stringify(val), ")"));
198
- }
199
- return _xdr["default"].ScVal.scvMap(Object.entries(val).map(function (_ref) {
200
- var _k, _opts$type2;
201
- var _ref2 = _slicedToArray(_ref, 2),
202
- k = _ref2[0],
203
- v = _ref2[1];
204
- // the type can be specified with an entry for the key and the value,
205
- // e.g. val = { 'hello': 1 } and opts.type = { hello: [ 'symbol',
206
- // 'u128' ]} or you can use `null` for the default interpretation
207
- var _ref3 = (_k = ((_opts$type2 = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type2 !== void 0 ? _opts$type2 : {})[k]) !== null && _k !== void 0 ? _k : [null, null],
208
- _ref4 = _slicedToArray(_ref3, 2),
209
- keyType = _ref4[0],
210
- valType = _ref4[1];
211
- var keyOpts = keyType ? {
212
- type: keyType
213
- } : {};
214
- var valOpts = valType ? {
215
- type: valType
216
- } : {};
217
- return new _xdr["default"].ScMapEntry({
218
- key: nativeToScVal(k, keyOpts),
219
- val: nativeToScVal(v, valOpts)
220
- });
221
- }));
222
234
  case 'number':
223
235
  case 'bigint':
224
236
  switch (opts === null || opts === void 0 ? void 0 : opts.type) {
@@ -243,6 +255,10 @@ function nativeToScVal(val) {
243
255
  return _xdr["default"].ScVal.scvSymbol(val);
244
256
  case 'address':
245
257
  return new _address.Address(val).toScVal();
258
+ case 'u32':
259
+ return _xdr["default"].ScVal.scvU32(parseInt(val, 10));
260
+ case 'i32':
261
+ return _xdr["default"].ScVal.scvI32(parseInt(val, 10));
246
262
  default:
247
263
  if (_index.XdrLargeInt.isType(optType)) {
248
264
  return new _index.XdrLargeInt(optType, val).toScVal();
@@ -206,6 +206,21 @@ var TransactionBuilder = exports.TransactionBuilder = /*#__PURE__*/function () {
206
206
  return this;
207
207
  }
208
208
 
209
+ /**
210
+ * Adds an operation to the transaction at a specific index.
211
+ *
212
+ * @param {xdr.Operation} operation - The xdr operation object to add, use {@link Operation} static methods.
213
+ * @param {number} index - The index at which to insert the operation.
214
+ *
215
+ * @returns {TransactionBuilder} - The TransactionBuilder instance for method chaining.
216
+ */
217
+ }, {
218
+ key: "addOperationAt",
219
+ value: function addOperationAt(operation, index) {
220
+ this.operations.splice(index, 0, operation);
221
+ return this;
222
+ }
223
+
209
224
  /**
210
225
  * Removes the operations from the builder (useful when cloning).
211
226
  * @returns {TransactionBuilder} this builder instance
@@ -217,6 +232,20 @@ var TransactionBuilder = exports.TransactionBuilder = /*#__PURE__*/function () {
217
232
  return this;
218
233
  }
219
234
 
235
+ /**
236
+ * Removes the operation at the specified index from the transaction.
237
+ *
238
+ * @param {number} index - The index of the operation to remove.
239
+ *
240
+ * @returns {TransactionBuilder} The TransactionBuilder instance for method chaining.
241
+ */
242
+ }, {
243
+ key: "clearOperationAt",
244
+ value: function clearOperationAt(index) {
245
+ this.operations.splice(index, 1);
246
+ return this;
247
+ }
248
+
220
249
  /**
221
250
  * Adds a memo to the transaction.
222
251
  * @param {Memo} memo {@link Memo} object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar/stellar-base",
3
- "version": "12.0.1",
3
+ "version": "12.1.0",
4
4
  "description": "Low-level support library for the Stellar network.",
5
5
  "main": "./lib/index.js",
6
6
  "browser": {
@@ -70,15 +70,15 @@
70
70
  },
71
71
  "homepage": "https://github.com/stellar/js-stellar-base",
72
72
  "devDependencies": {
73
- "@babel/cli": "^7.24.7",
74
- "@babel/core": "^7.24.7",
75
- "@babel/eslint-parser": "^7.24.7",
73
+ "@babel/cli": "^7.24.8",
74
+ "@babel/core": "^7.24.9",
75
+ "@babel/eslint-parser": "^7.24.8",
76
76
  "@babel/eslint-plugin": "^7.24.7",
77
- "@babel/preset-env": "^7.24.7",
77
+ "@babel/preset-env": "^7.24.8",
78
78
  "@babel/register": "^7.24.6",
79
79
  "@definitelytyped/dtslint": "^0.0.182",
80
80
  "@istanbuljs/nyc-config-babel": "3.0.0",
81
- "@types/node": "^20.14.2",
81
+ "@types/node": "^20.14.11",
82
82
  "@typescript-eslint/parser": "^6.20.0",
83
83
  "babel-loader": "^9.1.3",
84
84
  "babel-plugin-istanbul": "^6.1.1",
@@ -91,7 +91,7 @@
91
91
  "eslint-plugin-import": "^2.29.1",
92
92
  "eslint-plugin-node": "^11.1.0",
93
93
  "eslint-plugin-prefer-import": "^0.0.1",
94
- "eslint-plugin-prettier": "^5.1.3",
94
+ "eslint-plugin-prettier": "^5.2.1",
95
95
  "eslint-webpack-plugin": "^4.2.0",
96
96
  "ghooks": "^2.0.4",
97
97
  "husky": "^8.0.3",
@@ -105,22 +105,22 @@
105
105
  "karma-webpack": "^5.0.1",
106
106
  "lint-staged": "^15.2.7",
107
107
  "minami": "^1.1.1",
108
- "mocha": "^10.4.0",
108
+ "mocha": "^10.6.0",
109
109
  "node-polyfill-webpack-plugin": "^3.0.0",
110
110
  "nyc": "^15.1.0",
111
- "prettier": "^3.3.2",
111
+ "prettier": "^3.3.3",
112
112
  "randombytes": "^2.1.0",
113
113
  "sinon": "^16.1.0",
114
114
  "sinon-chai": "^3.7.0",
115
115
  "taffydb": "^2.7.3",
116
116
  "terser-webpack-plugin": "^5.3.10",
117
117
  "ts-node": "^10.9.2",
118
- "typescript": "^5.4.5",
119
- "webpack": "^5.92.0",
118
+ "typescript": "^5.5.3",
119
+ "webpack": "^5.93.0",
120
120
  "webpack-cli": "^5.1.1"
121
121
  },
122
122
  "dependencies": {
123
- "@stellar/js-xdr": "^3.1.1",
123
+ "@stellar/js-xdr": "^3.1.2",
124
124
  "base32.js": "^0.1.0",
125
125
  "bignumber.js": "^9.1.2",
126
126
  "buffer": "^6.0.3",