@stellar/stellar-base 12.0.1 → 12.1.1

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';
@@ -246,7 +246,7 @@ var Asset = exports.Asset = /*#__PURE__*/function () {
246
246
  */
247
247
  }], [{
248
248
  key: "native",
249
- value: function native() {
249
+ value: function _native() {
250
250
  return new Asset('XLM');
251
251
  }
252
252
 
package/lib/auth.js CHANGED
@@ -65,6 +65,10 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
65
65
  * authorization entry that you can pass along to
66
66
  * {@link Operation.invokeHostFunction}
67
67
  *
68
+ * @note If using the `SigningCallback` variation, the signer is assumed to be
69
+ * the entry's credential address. If you need a different key to sign the
70
+ * entry, you will need to use different method (e.g., fork this code).
71
+ *
68
72
  * @see authorizeInvocation
69
73
  * @example
70
74
  * import {
@@ -147,7 +151,7 @@ function authorizeEntry(_x, _x2, _x3) {
147
151
  * @see authorizeEntry
148
152
  */
149
153
  function _authorizeEntry() {
150
- _authorizeEntry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, signer, validUntilLedgerSeq) {
154
+ _authorizeEntry = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, signer, validUntilLedgerSeq) {
151
155
  var networkPassphrase,
152
156
  clone,
153
157
  addrAuth,
@@ -181,7 +185,7 @@ function _authorizeEntry() {
181
185
  }));
182
186
  payload = (0, _hashing.hash)(preimage.toXDR());
183
187
  if (!(typeof signer === 'function')) {
184
- _context.next = 17;
188
+ _context.next = 18;
185
189
  break;
186
190
  }
187
191
  _context.t0 = Buffer;
@@ -190,18 +194,19 @@ function _authorizeEntry() {
190
194
  case 13:
191
195
  _context.t1 = _context.sent;
192
196
  signature = _context.t0.from.call(_context.t0, _context.t1);
193
- _context.next = 18;
197
+ publicKey = _address.Address.fromScAddress(addrAuth.address()).toString();
198
+ _context.next = 20;
194
199
  break;
195
- case 17:
196
- signature = Buffer.from(signer.sign(payload));
197
200
  case 18:
198
- publicKey = _address.Address.fromScAddress(addrAuth.address()).toString();
201
+ signature = Buffer.from(signer.sign(payload));
202
+ publicKey = signer.publicKey();
203
+ case 20:
199
204
  if (_keypair.Keypair.fromPublicKey(publicKey).verify(payload, signature)) {
200
- _context.next = 21;
205
+ _context.next = 22;
201
206
  break;
202
207
  }
203
208
  throw new Error("signature doesn't match payload");
204
- case 21:
209
+ case 22:
205
210
  // This structure is defined here:
206
211
  // https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#stellar-account-signatures
207
212
  //
@@ -218,7 +223,7 @@ function _authorizeEntry() {
218
223
  });
219
224
  addrAuth.signature(_xdr["default"].ScVal.scvVec([sigScVal]));
220
225
  return _context.abrupt("return", clone);
221
- case 24:
226
+ case 25:
222
227
  case "end":
223
228
  return _context.stop();
224
229
  }
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/invocation.js CHANGED
@@ -168,7 +168,8 @@ function buildInvocationTree(root) {
168
168
  * @param {xdr.SorobanAuthorizedInvocation} [parent] this `node`s parent node,
169
169
  * if any (i.e. this doesn't exist at the root)
170
170
  *
171
- * @returns {boolean?} returning `false` is a hint to stop exploring
171
+ * @returns {boolean|null|void} returning exactly `false` is a hint to stop
172
+ * exploring, other values are ignored
172
173
  */
173
174
 
174
175
  /**
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.1",
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",
76
- "@babel/eslint-plugin": "^7.24.7",
77
- "@babel/preset-env": "^7.24.7",
73
+ "@babel/cli": "^7.25.6",
74
+ "@babel/core": "^7.25.2",
75
+ "@babel/eslint-parser": "^7.25.1",
76
+ "@babel/eslint-plugin": "^7.25.1",
77
+ "@babel/preset-env": "^7.25.4",
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",
@@ -88,39 +88,39 @@
88
88
  "eslint": "^8.57.0",
89
89
  "eslint-config-airbnb-base": "^15.0.0",
90
90
  "eslint-config-prettier": "^9.1.0",
91
- "eslint-plugin-import": "^2.29.1",
91
+ "eslint-plugin-import": "^2.30.0",
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",
98
98
  "jsdoc": "^4.0.3",
99
- "karma": "^6.4.3",
99
+ "karma": "^6.4.4",
100
100
  "karma-chrome-launcher": "^3.1.0",
101
101
  "karma-coverage": "^2.2.1",
102
102
  "karma-firefox-launcher": "^2.1.3",
103
103
  "karma-mocha": "^2.0.0",
104
104
  "karma-sinon-chai": "^2.0.2",
105
105
  "karma-webpack": "^5.0.1",
106
- "lint-staged": "^15.2.7",
106
+ "lint-staged": "^15.2.10",
107
107
  "minami": "^1.1.1",
108
- "mocha": "^10.4.0",
108
+ "mocha": "^10.7.3",
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.6.2",
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",
package/types/index.d.ts CHANGED
@@ -1019,6 +1019,7 @@ export class FeeBumpTransaction extends TransactionI {
1019
1019
  );
1020
1020
  feeSource: string;
1021
1021
  innerTransaction: Transaction;
1022
+ get operations(): Operation[];
1022
1023
  }
1023
1024
 
1024
1025
  export class Transaction<
@@ -1058,7 +1059,9 @@ export class TransactionBuilder {
1058
1059
  options?: TransactionBuilder.TransactionBuilderOptions
1059
1060
  );
1060
1061
  addOperation(operation: xdr.Operation): this;
1062
+ addOperationAt(op: xdr.Operation, i: number): this;
1061
1063
  clearOperations(): this;
1064
+ clearOperationAt(i: number): this;
1062
1065
  addMemo(memo: Memo): this;
1063
1066
  setTimeout(timeoutInSeconds: number): this;
1064
1067
  setTimebounds(min: Date | number, max: Date | number): this;
@@ -1085,6 +1088,7 @@ export class TransactionBuilder {
1085
1088
  envelope: string | xdr.TransactionEnvelope,
1086
1089
  networkPassphrase: string
1087
1090
  ): Transaction | FeeBumpTransaction;
1091
+
1088
1092
  }
1089
1093
 
1090
1094
  export namespace TransactionBuilder {
@@ -1258,7 +1262,7 @@ export type InvocationWalker = (
1258
1262
  node: xdr.SorobanAuthorizedInvocation,
1259
1263
  depth: number,
1260
1264
  parent?: any
1261
- ) => boolean|null;
1265
+ ) => boolean|null|void;
1262
1266
 
1263
1267
  export function walkInvocationTree(
1264
1268
  root: xdr.SorobanAuthorizedInvocation,