@stellar/stellar-base 14.0.2 → 14.0.4

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
@@ -228,7 +228,10 @@ var Address = exports.Address = /*#__PURE__*/function () {
228
228
  return Address.muxedAccount(raw);
229
229
  }
230
230
  case _xdr["default"].ScAddressType.scAddressTypeClaimableBalance().value:
231
- return Address.claimableBalance(scAddress.claimableBalanceId());
231
+ {
232
+ var cbi = scAddress.claimableBalanceId();
233
+ return Address.claimableBalance(Buffer.concat([Buffer.from([cbi["switch"]().value]), cbi.v0()]));
234
+ }
232
235
  case _xdr["default"].ScAddressType.scAddressTypeLiquidityPool().value:
233
236
  return Address.liquidityPool(scAddress.liquidityPoolId());
234
237
  default:
@@ -72,6 +72,8 @@ function scValToBigInt(scv) {
72
72
  return BigInt(scv.value());
73
73
  case 'scvU64':
74
74
  case 'scvI64':
75
+ case 'scvTimepoint':
76
+ case 'scvDuration':
75
77
  return new _xdr_large_int.XdrLargeInt(scIntType, scv.value()).toBigInt();
76
78
  case 'scvU128':
77
79
  case 'scvI128':
@@ -65,6 +65,8 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
65
65
  this["int"] = new _int2.Int256(values);
66
66
  break;
67
67
  case 'u64':
68
+ case 'timepoint':
69
+ case 'duration':
68
70
  this["int"] = new _jsXdr.UnsignedHyper(values);
69
71
  break;
70
72
  case 'u128':
@@ -121,6 +123,24 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
121
123
  );
122
124
  }
123
125
 
126
+ /** @returns {xdr.ScVal} the integer encoded with `ScValType = Timepoint` */
127
+ }, {
128
+ key: "toTimepoint",
129
+ value: function toTimepoint() {
130
+ this._sizeCheck(64);
131
+ return _xdr["default"].ScVal.scvTimepoint(new _xdr["default"].Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
132
+ );
133
+ }
134
+
135
+ /** @returns {xdr.ScVal} the integer encoded with `ScValType = Duration` */
136
+ }, {
137
+ key: "toDuration",
138
+ value: function toDuration() {
139
+ this._sizeCheck(64);
140
+ return _xdr["default"].ScVal.scvDuration(new _xdr["default"].Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
141
+ );
142
+ }
143
+
124
144
  /**
125
145
  * @returns {xdr.ScVal} the integer encoded with `ScValType = I128`
126
146
  * @throws {RangeError} if the value cannot fit in 128 bits
@@ -205,6 +225,10 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
205
225
  return this.toU128();
206
226
  case 'u256':
207
227
  return this.toU256();
228
+ case 'timepoint':
229
+ return this.toTimepoint();
230
+ case 'duration':
231
+ return this.toDuration();
208
232
  default:
209
233
  throw TypeError("invalid type: ".concat(this.type));
210
234
  }
@@ -244,6 +268,8 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
244
268
  case 'u64':
245
269
  case 'u128':
246
270
  case 'u256':
271
+ case 'timepoint':
272
+ case 'duration':
247
273
  return true;
248
274
  default:
249
275
  return false;
package/lib/scval.js CHANGED
@@ -303,7 +303,7 @@ function nativeToScVal(val) {
303
303
  *
304
304
  * - void -> `null`
305
305
  * - u32, i32 -> `number`
306
- * - u64, i64, u128, i128, u256, i256 -> `bigint`
306
+ * - u64, i64, u128, i128, u256, i256, timepoint, duration -> `bigint`
307
307
  * - vec -> `Array` of any of the above (via recursion)
308
308
  * - map -> key-value object of any of the above (via recursion)
309
309
  * - bool -> `boolean`
package/lib/soroban.js CHANGED
@@ -38,6 +38,8 @@ var Soroban = exports.Soroban = /*#__PURE__*/function () {
38
38
  * @throws {TypeError} if the given amount has a decimal point already
39
39
  * @example
40
40
  * formatTokenAmount("123000", 4) === "12.3";
41
+ * formatTokenAmount("123000", 3) === "123.0";
42
+ * formatTokenAmount("123", 3) === "0.123";
41
43
  */
42
44
  function formatTokenAmount(amount, decimals) {
43
45
  if (amount.includes('.')) {
@@ -51,9 +53,9 @@ var Soroban = exports.Soroban = /*#__PURE__*/function () {
51
53
  formatted = [formatted.slice(0, -decimals), formatted.slice(-decimals)].join('.');
52
54
  }
53
55
  }
54
-
55
- // remove trailing zero if any
56
- return formatted.replace(/(\.\d*?)0+$/, '$1');
56
+ return formatted.replace(/(\.\d*?)0+$/, '$1') // strip trailing zeroes
57
+ .replace(/\.$/, '.0') // but keep at least one
58
+ .replace(/^\./, '0.'); // and a leading one
57
59
  }
58
60
 
59
61
  /**
@@ -84,7 +86,7 @@ var Soroban = exports.Soroban = /*#__PURE__*/function () {
84
86
  _value$split$slice2 = _toArray(_value$split$slice),
85
87
  whole = _value$split$slice2[0],
86
88
  fraction = _value$split$slice2[1],
87
- rest = _value$split$slice2.slice(2);
89
+ rest = _arrayLikeToArray(_value$split$slice2).slice(2);
88
90
  if (rest.length) {
89
91
  throw new Error("Invalid decimal value: ".concat(value));
90
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar/stellar-base",
3
- "version": "14.0.2",
3
+ "version": "14.0.4",
4
4
  "description": "Low-level support library for the Stellar network.",
5
5
  "main": "./lib/index.js",
6
6
  "browser": {
@@ -73,10 +73,10 @@
73
73
  "homepage": "https://github.com/stellar/js-stellar-base",
74
74
  "devDependencies": {
75
75
  "@babel/cli": "^7.28.3",
76
- "@babel/core": "^7.28.3",
77
- "@babel/eslint-parser": "^7.28.0",
76
+ "@babel/core": "^7.28.5",
77
+ "@babel/eslint-parser": "^7.28.5",
78
78
  "@babel/eslint-plugin": "^7.27.1",
79
- "@babel/preset-env": "^7.28.3",
79
+ "@babel/preset-env": "^7.28.5",
80
80
  "@babel/register": "^7.28.3",
81
81
  "@definitelytyped/dtslint": "^0.0.182",
82
82
  "@istanbuljs/nyc-config-babel": "3.0.0",
@@ -97,7 +97,7 @@
97
97
  "eslint-webpack-plugin": "^4.2.0",
98
98
  "ghooks": "^2.0.4",
99
99
  "husky": "^8.0.3",
100
- "jsdoc": "^4.0.4",
100
+ "jsdoc": "^4.0.5",
101
101
  "karma": "^6.4.4",
102
102
  "karma-chrome-launcher": "^3.1.0",
103
103
  "karma-coverage": "^2.2.1",
@@ -110,15 +110,15 @@
110
110
  "mocha": "^10.8.2",
111
111
  "node-polyfill-webpack-plugin": "^3.0.0",
112
112
  "nyc": "^15.1.0",
113
- "prettier": "^3.6.2",
113
+ "prettier": "^3.7.4",
114
114
  "randombytes": "^2.1.0",
115
115
  "sinon": "^16.1.0",
116
116
  "sinon-chai": "^3.7.0",
117
117
  "taffydb": "^2.7.3",
118
- "terser-webpack-plugin": "^5.3.14",
118
+ "terser-webpack-plugin": "^5.3.16",
119
119
  "ts-node": "^10.9.2",
120
120
  "typescript": "5.6.3",
121
- "webpack": "^5.101.2",
121
+ "webpack": "^5.104.1",
122
122
  "webpack-cli": "^5.1.1"
123
123
  },
124
124
  "dependencies": {