@pioneer-platform/ton-network 8.11.1 → 8.11.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pioneer-platform/ton-network
2
2
 
3
+ ## 8.11.3
4
+
5
+ ### Patch Changes
6
+
7
+ - chore: fix: move @types/pdfkit to dependencies for Docker --production build
8
+
9
+ ## 8.11.2
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: move @types/pdfkit to dependencies for Docker --production build
14
+
3
15
  ## 8.11.1
4
16
 
5
17
  ### Patch Changes
package/lib/index.js CHANGED
@@ -67,8 +67,11 @@ var axiosLib = require('axios');
67
67
  var Axios = axiosLib.default || axiosLib;
68
68
  var https = require('https');
69
69
  var log = require('@pioneer-platform/loggerdog')();
70
- // Default TON mainnet API (TonCenter)
71
- var DEFAULT_API_URL = "https://toncenter.com/api/v2";
70
+ // Default TON mainnet API (NOWNodes with API key from env)
71
+ var NOWNODES_API_KEY = process.env.NOWNODES_API_KEY;
72
+ var DEFAULT_API_URL = NOWNODES_API_KEY
73
+ ? "https://ton.nownodes.io"
74
+ : "https://toncenter.com/api/v2";
72
75
  // Network constants
73
76
  exports.NETWORK_ID = 'ton:-239';
74
77
  exports.CHAIN_SYMBOL = 'TON';
@@ -106,13 +109,21 @@ module.exports = {
106
109
  case 1:
107
110
  _a.trys.push([1, 3, , 4]);
108
111
  apiUrl = url || process.env['TON_API_URL'] || DEFAULT_API_URL;
109
- apiKey = (settings === null || settings === void 0 ? void 0 : settings.apiKey) || process.env['TONCENTER_API_KEY'] || null;
112
+ apiKey = (settings === null || settings === void 0 ? void 0 : settings.apiKey) || process.env['NOWNODES_API_KEY'] || process.env['TONCENTER_API_KEY'] || null;
110
113
  log.info(tag, "Initializing TON network...");
111
114
  log.info(tag, "API Endpoint:", apiUrl);
112
115
  log.info(tag, "API Key configured:", apiKey ? "Yes" : "No (rate limited)");
116
+ log.info(tag, "NOWNODES_API_KEY from env:", process.env['NOWNODES_API_KEY'] ? "SET" : "NOT SET");
117
+ log.info(tag, "DEFAULT_API_URL value:", DEFAULT_API_URL);
113
118
  headers = { 'Content-Type': 'application/json' };
114
119
  if (apiKey) {
115
- headers['X-API-Key'] = apiKey;
120
+ // NOWNodes uses 'api-key' header, TonCenter uses 'X-API-Key'
121
+ if (apiUrl.includes('nownodes.io')) {
122
+ headers['api-key'] = apiKey;
123
+ }
124
+ else {
125
+ headers['X-API-Key'] = apiKey;
126
+ }
116
127
  }
117
128
  return [4 /*yield*/, axios({
118
129
  url: "".concat(apiUrl, "/getMasterchainInfo"),
@@ -168,6 +179,14 @@ module.exports = {
168
179
  getWalletSeqno: function (address) {
169
180
  return get_wallet_seqno(address);
170
181
  },
182
+ /**
183
+ * Get account info for transaction building
184
+ * Returns data needed to build transactions: seqno, balance, wallet_version
185
+ * @param address - TON address
186
+ */
187
+ getAccountInfo: function (address) {
188
+ return get_account_info_for_tx(address);
189
+ },
171
190
  /**
172
191
  * Broadcast a signed transaction (BOC)
173
192
  * @param boc - Base64 encoded BOC (Bag of Cells)
@@ -210,7 +229,13 @@ module.exports = {
210
229
  function getHeaders() {
211
230
  var headers = { 'Content-Type': 'application/json' };
212
231
  if (apiKey) {
213
- headers['X-API-Key'] = apiKey;
232
+ // NOWNodes uses 'api-key' header, TonCenter uses 'X-API-Key'
233
+ if (apiUrl.includes('nownodes.io')) {
234
+ headers['api-key'] = apiKey;
235
+ }
236
+ else {
237
+ headers['X-API-Key'] = apiKey;
238
+ }
214
239
  }
215
240
  return headers;
216
241
  }
@@ -486,3 +511,82 @@ function get_masterchain_info() {
486
511
  });
487
512
  });
488
513
  }
514
+ function get_account_info_for_tx(address) {
515
+ return __awaiter(this, void 0, void 0, function () {
516
+ var tag, seqno, addressInfo, walletVersion, pubKeyResponse, addressInfoDetailed, code, e_9, e_10;
517
+ var _a;
518
+ return __generator(this, function (_b) {
519
+ switch (_b.label) {
520
+ case 0:
521
+ tag = TAG + " | get_account_info_for_tx | ";
522
+ _b.label = 1;
523
+ case 1:
524
+ _b.trys.push([1, 10, , 11]);
525
+ log.debug(tag, "Getting account info for transaction building:", address);
526
+ return [4 /*yield*/, get_wallet_seqno(address)
527
+ // Get address info for balance and state
528
+ ];
529
+ case 2:
530
+ seqno = _b.sent();
531
+ return [4 /*yield*/, get_address_info(address)
532
+ // Determine wallet version by querying the contract
533
+ ];
534
+ case 3:
535
+ addressInfo = _b.sent();
536
+ walletVersion = 'v4' // Default to v4 as it's most common
537
+ ;
538
+ _b.label = 4;
539
+ case 4:
540
+ _b.trys.push([4, 8, , 9]);
541
+ return [4 /*yield*/, axios({
542
+ url: "".concat(apiUrl, "/runGetMethod"),
543
+ method: 'POST',
544
+ headers: getHeaders(),
545
+ data: {
546
+ address: address,
547
+ method: "get_public_key",
548
+ stack: []
549
+ }
550
+ })
551
+ // If get_public_key exists, it's likely a standard wallet
552
+ ];
553
+ case 5:
554
+ pubKeyResponse = _b.sent();
555
+ if (!(pubKeyResponse.data && pubKeyResponse.data.ok)) return [3 /*break*/, 7];
556
+ return [4 /*yield*/, axios({
557
+ url: "".concat(apiUrl, "/getAddressInformation"),
558
+ method: 'GET',
559
+ headers: getHeaders(),
560
+ params: { address: address }
561
+ })];
562
+ case 6:
563
+ addressInfoDetailed = _b.sent();
564
+ if (addressInfoDetailed.data && addressInfoDetailed.data.ok) {
565
+ code = addressInfoDetailed.data.result.code;
566
+ // Different wallet versions have different code hashes
567
+ // This is a simplified check - you'd want to compare actual code hashes
568
+ if (code) {
569
+ walletVersion = 'v4'; // Default assumption
570
+ }
571
+ }
572
+ _b.label = 7;
573
+ case 7: return [3 /*break*/, 9];
574
+ case 8:
575
+ e_9 = _b.sent();
576
+ // If detection fails, stick with default v4
577
+ log.debug(tag, "Could not detect wallet version, using default v4");
578
+ return [3 /*break*/, 9];
579
+ case 9: return [2 /*return*/, {
580
+ seqno: seqno !== null ? seqno : 0,
581
+ balance: ((_a = addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.balance) === null || _a === void 0 ? void 0 : _a.toString()) || '0',
582
+ wallet_version: walletVersion
583
+ }];
584
+ case 10:
585
+ e_10 = _b.sent();
586
+ log.error(tag, "Error getting account info for tx:", e_10.message);
587
+ throw e_10;
588
+ case 11: return [2 /*return*/];
589
+ }
590
+ });
591
+ });
592
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/ton-network",
3
- "version": "8.11.1",
3
+ "version": "8.11.3",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "description": "Pioneer Platform TON Network module",