@xchainjs/xchain-utxo-providers 2.0.14 → 2.0.16

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/index.esm.js CHANGED
@@ -1243,6 +1243,31 @@ const getBalance = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey,
1243
1243
  : baseAmount(balanceResponse.balance).plus(balanceResponse.unconfirmedBalance, assetDecimals);
1244
1244
  return balance;
1245
1245
  });
1246
+ /**
1247
+ * Get the consensus branch ID for the next block from the Blockbook backend status.
1248
+ *
1249
+ * Returned by Blockbook at its API root as `backend.consensus.nextblock`, a hex string
1250
+ * (e.g. "5437f330"). Used to sign Zcash v5 transactions against the currently active
1251
+ * network upgrade so they remain valid after consensus upgrades.
1252
+ *
1253
+ * @param {string} baseUrl The nownodes blockbook URL (already includes /api/v2).
1254
+ * @returns {number | undefined} The consensus branch ID, or undefined if unavailable.
1255
+ */
1256
+ const getConsensusBranchId = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, }) {
1257
+ var _b, _c;
1258
+ const response = yield axios.get(baseUrl, {
1259
+ headers: {
1260
+ 'api-key': apiKey,
1261
+ },
1262
+ timeout: 10000, // fail fast so the caller can fall back to the default branch ID
1263
+ });
1264
+ const nextblock = (_c = (_b = response.data.backend) === null || _b === void 0 ? void 0 : _b.consensus) === null || _c === void 0 ? void 0 : _c.nextblock;
1265
+ // A consensus branch ID is a 32-bit value, always exactly 8 hex digits. Reject anything
1266
+ // else rather than risk signing with a malformed branch ID parsed from a partial match.
1267
+ if (!nextblock || !/^[0-9a-fA-F]{8}$/.test(nextblock))
1268
+ return undefined;
1269
+ return parseInt(nextblock, 16);
1270
+ });
1246
1271
  const broadcastTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, txHex, }) {
1247
1272
  const url = `${baseUrl}/sendtx/${txHex}`;
1248
1273
  const response = yield axios.get(url, {
@@ -1344,6 +1369,19 @@ class NownodesProvider {
1344
1369
  throw Error('Zcash has flat fees. Fee rates not apply');
1345
1370
  });
1346
1371
  }
1372
+ /**
1373
+ * Get the consensus branch ID for the next block from the backend status.
1374
+ * Used to sign Zcash transactions against the active network upgrade.
1375
+ * @returns {number | undefined} The consensus branch ID, or undefined if unavailable.
1376
+ */
1377
+ getConsensusBranchId() {
1378
+ return __awaiter(this, void 0, void 0, function* () {
1379
+ return yield getConsensusBranchId({
1380
+ apiKey: this._apiKey,
1381
+ baseUrl: this.baseUrl,
1382
+ });
1383
+ });
1384
+ }
1347
1385
  mapTransactionToTx(rawTx) {
1348
1386
  return {
1349
1387
  asset: this.asset,
package/lib/index.js CHANGED
@@ -1250,6 +1250,31 @@ const getBalance = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey,
1250
1250
  : xchainUtil.baseAmount(balanceResponse.balance).plus(balanceResponse.unconfirmedBalance, assetDecimals);
1251
1251
  return balance;
1252
1252
  });
1253
+ /**
1254
+ * Get the consensus branch ID for the next block from the Blockbook backend status.
1255
+ *
1256
+ * Returned by Blockbook at its API root as `backend.consensus.nextblock`, a hex string
1257
+ * (e.g. "5437f330"). Used to sign Zcash v5 transactions against the currently active
1258
+ * network upgrade so they remain valid after consensus upgrades.
1259
+ *
1260
+ * @param {string} baseUrl The nownodes blockbook URL (already includes /api/v2).
1261
+ * @returns {number | undefined} The consensus branch ID, or undefined if unavailable.
1262
+ */
1263
+ const getConsensusBranchId = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, }) {
1264
+ var _b, _c;
1265
+ const response = yield axios__default.default.get(baseUrl, {
1266
+ headers: {
1267
+ 'api-key': apiKey,
1268
+ },
1269
+ timeout: 10000, // fail fast so the caller can fall back to the default branch ID
1270
+ });
1271
+ const nextblock = (_c = (_b = response.data.backend) === null || _b === void 0 ? void 0 : _b.consensus) === null || _c === void 0 ? void 0 : _c.nextblock;
1272
+ // A consensus branch ID is a 32-bit value, always exactly 8 hex digits. Reject anything
1273
+ // else rather than risk signing with a malformed branch ID parsed from a partial match.
1274
+ if (!nextblock || !/^[0-9a-fA-F]{8}$/.test(nextblock))
1275
+ return undefined;
1276
+ return parseInt(nextblock, 16);
1277
+ });
1253
1278
  const broadcastTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ apiKey, baseUrl, txHex, }) {
1254
1279
  const url = `${baseUrl}/sendtx/${txHex}`;
1255
1280
  const response = yield axios__default.default.get(url, {
@@ -1351,6 +1376,19 @@ class NownodesProvider {
1351
1376
  throw Error('Zcash has flat fees. Fee rates not apply');
1352
1377
  });
1353
1378
  }
1379
+ /**
1380
+ * Get the consensus branch ID for the next block from the backend status.
1381
+ * Used to sign Zcash transactions against the active network upgrade.
1382
+ * @returns {number | undefined} The consensus branch ID, or undefined if unavailable.
1383
+ */
1384
+ getConsensusBranchId() {
1385
+ return __awaiter(this, void 0, void 0, function* () {
1386
+ return yield getConsensusBranchId({
1387
+ apiKey: this._apiKey,
1388
+ baseUrl: this.baseUrl,
1389
+ });
1390
+ });
1391
+ }
1354
1392
  mapTransactionToTx(rawTx) {
1355
1393
  return {
1356
1394
  asset: this.asset,
@@ -68,3 +68,11 @@ export type GetAddressInfo = {
68
68
  export type BroadcastDTO = {
69
69
  result: string;
70
70
  };
71
+ export type StatusDTO = {
72
+ backend: {
73
+ consensus?: {
74
+ chaintip: string;
75
+ nextblock: string;
76
+ };
77
+ };
78
+ };
@@ -47,6 +47,20 @@ export declare const getUTXOs: ({ apiKey, address, baseUrl, isConfirmed, }: {
47
47
  * @returns {number}
48
48
  */
49
49
  export declare const getBalance: ({ apiKey, baseUrl, address, confirmedOnly, assetDecimals, }: BalanceParams) => Promise<BaseAmount>;
50
+ /**
51
+ * Get the consensus branch ID for the next block from the Blockbook backend status.
52
+ *
53
+ * Returned by Blockbook at its API root as `backend.consensus.nextblock`, a hex string
54
+ * (e.g. "5437f330"). Used to sign Zcash v5 transactions against the currently active
55
+ * network upgrade so they remain valid after consensus upgrades.
56
+ *
57
+ * @param {string} baseUrl The nownodes blockbook URL (already includes /api/v2).
58
+ * @returns {number | undefined} The consensus branch ID, or undefined if unavailable.
59
+ */
60
+ export declare const getConsensusBranchId: ({ apiKey, baseUrl, }: {
61
+ apiKey: string;
62
+ baseUrl: string;
63
+ }) => Promise<number | undefined>;
50
64
  export declare const broadcastTx: ({ apiKey, baseUrl, txHex, }: {
51
65
  apiKey: string;
52
66
  baseUrl: string;
@@ -16,6 +16,12 @@ export declare class NownodesProvider implements UtxoOnlineDataProvider {
16
16
  getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
17
17
  getTransactionData(txId: string): Promise<Tx>;
18
18
  getFeeRates(): Promise<FeeRates>;
19
+ /**
20
+ * Get the consensus branch ID for the next block from the backend status.
21
+ * Used to sign Zcash transactions against the active network upgrade.
22
+ * @returns {number | undefined} The consensus branch ID, or undefined if unavailable.
23
+ */
24
+ getConsensusBranchId(): Promise<number | undefined>;
19
25
  private mapTransactionToTx;
20
26
  private mapUTXOs;
21
27
  private getRawTransactions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-utxo-providers",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@supercharge/promise-pool": "2.4.0",
32
- "@xchainjs/xchain-client": "2.0.13",
32
+ "@xchainjs/xchain-client": "2.0.14",
33
33
  "@xchainjs/xchain-util": "2.0.7",
34
- "axios": "1.15.2"
34
+ "axios": "1.16.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "axios-mock-adapter": "^2.1.0"