@ton/mcp 0.1.15-alpha.19 → 0.1.15-alpha.20

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/dist/cli.js CHANGED
@@ -20889,40 +20889,84 @@ var require_nacl_fast = /* @__PURE__ */ __commonJSMin(((exports, module) => {
20889
20889
  })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
20890
20890
  }));
20891
20891
  //#endregion
20892
- //#region ../../node_modules/.pnpm/@tonconnect+protocol@2.5.0-alpha.1/node_modules/@tonconnect/protocol/lib/esm/index.mjs
20892
+ //#region ../../node_modules/.pnpm/@tonconnect+protocol@3.0.0/node_modules/@tonconnect/protocol/lib/esm/index.mjs
20893
20893
  var import_nacl_util = /* @__PURE__ */ __toESM(require_nacl_util(), 1);
20894
20894
  var import_nacl_fast = /* @__PURE__ */ __toESM(require_nacl_fast(), 1);
20895
+ /**
20896
+ * Error codes the wallet may return in {@link ConnectEventError}.
20897
+ *
20898
+ * @see [Connect event error codes (Connect spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/connect.md#connect-event-error-codes)
20899
+ */
20895
20900
  var CONNECT_EVENT_ERROR_CODES$1;
20896
20901
  (function(CONNECT_EVENT_ERROR_CODES) {
20902
+ /** Unexpected wallet-side failure. */
20897
20903
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
20904
+ /** Request payload is malformed. */
20898
20905
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["BAD_REQUEST_ERROR"] = 1] = "BAD_REQUEST_ERROR";
20906
+ /** Wallet could not fetch the `tonconnect-manifest.json`. */
20899
20907
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["MANIFEST_NOT_FOUND_ERROR"] = 2] = "MANIFEST_NOT_FOUND_ERROR";
20908
+ /** Manifest was fetched but fails JSON / schema validation. */
20900
20909
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["MANIFEST_CONTENT_ERROR"] = 3] = "MANIFEST_CONTENT_ERROR";
20910
+ /** Wallet does not know the app / session. */
20901
20911
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["UNKNOWN_APP_ERROR"] = 100] = "UNKNOWN_APP_ERROR";
20912
+ /** User explicitly declined the connect prompt. */
20902
20913
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["USER_REJECTS_ERROR"] = 300] = "USER_REJECTS_ERROR";
20914
+ /** Wallet does not support the requested method. */
20903
20915
  CONNECT_EVENT_ERROR_CODES[CONNECT_EVENT_ERROR_CODES["METHOD_NOT_SUPPORTED"] = 400] = "METHOD_NOT_SUPPORTED";
20904
20916
  })(CONNECT_EVENT_ERROR_CODES$1 || (CONNECT_EVENT_ERROR_CODES$1 = {}));
20917
+ /**
20918
+ * Per-item error codes returned inside a {@link ConnectItemReplyError}.
20919
+ *
20920
+ * @see [Connect item error codes (Connect spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/connect.md#connect-item-error-codes)
20921
+ */
20905
20922
  var CONNECT_ITEM_ERROR_CODES$1;
20906
20923
  (function(CONNECT_ITEM_ERROR_CODES) {
20924
+ /** Unexpected wallet-side failure. */
20907
20925
  CONNECT_ITEM_ERROR_CODES[CONNECT_ITEM_ERROR_CODES["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
20926
+ /** Wallet does not support this connect item. */
20908
20927
  CONNECT_ITEM_ERROR_CODES[CONNECT_ITEM_ERROR_CODES["METHOD_NOT_SUPPORTED"] = 400] = "METHOD_NOT_SUPPORTED";
20909
20928
  })(CONNECT_ITEM_ERROR_CODES$1 || (CONNECT_ITEM_ERROR_CODES$1 = {}));
20929
+ /**
20930
+ * Error codes the wallet may return from `sendTransaction`.
20931
+ *
20932
+ * @see [`sendTransaction` errors (RPC spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/rpc.md#sendtransaction)
20933
+ */
20910
20934
  var SEND_TRANSACTION_ERROR_CODES$1;
20911
20935
  (function(SEND_TRANSACTION_ERROR_CODES) {
20936
+ /** Unexpected wallet-side failure. */
20912
20937
  SEND_TRANSACTION_ERROR_CODES[SEND_TRANSACTION_ERROR_CODES["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
20938
+ /** Request payload is malformed. */
20913
20939
  SEND_TRANSACTION_ERROR_CODES[SEND_TRANSACTION_ERROR_CODES["BAD_REQUEST_ERROR"] = 1] = "BAD_REQUEST_ERROR";
20940
+ /** Wallet does not know the dApp / session. */
20914
20941
  SEND_TRANSACTION_ERROR_CODES[SEND_TRANSACTION_ERROR_CODES["UNKNOWN_APP_ERROR"] = 100] = "UNKNOWN_APP_ERROR";
20942
+ /** User explicitly declined the transaction. */
20915
20943
  SEND_TRANSACTION_ERROR_CODES[SEND_TRANSACTION_ERROR_CODES["USER_REJECTS_ERROR"] = 300] = "USER_REJECTS_ERROR";
20944
+ /** Wallet does not support the method. */
20916
20945
  SEND_TRANSACTION_ERROR_CODES[SEND_TRANSACTION_ERROR_CODES["METHOD_NOT_SUPPORTED"] = 400] = "METHOD_NOT_SUPPORTED";
20917
20946
  })(SEND_TRANSACTION_ERROR_CODES$1 || (SEND_TRANSACTION_ERROR_CODES$1 = {}));
20947
+ /**
20948
+ * Error codes the wallet may return from `signData`.
20949
+ *
20950
+ * @see [`signData` errors (RPC spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/rpc.md#signdata)
20951
+ */
20918
20952
  var SIGN_DATA_ERROR_CODES$1;
20919
20953
  (function(SIGN_DATA_ERROR_CODES) {
20954
+ /** Unexpected wallet-side failure. */
20920
20955
  SIGN_DATA_ERROR_CODES[SIGN_DATA_ERROR_CODES["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
20956
+ /** Invalid request payload. */
20921
20957
  SIGN_DATA_ERROR_CODES[SIGN_DATA_ERROR_CODES["BAD_REQUEST_ERROR"] = 1] = "BAD_REQUEST_ERROR";
20958
+ /** Wallet does not know the dApp / session. */
20922
20959
  SIGN_DATA_ERROR_CODES[SIGN_DATA_ERROR_CODES["UNKNOWN_APP_ERROR"] = 100] = "UNKNOWN_APP_ERROR";
20960
+ /** User explicitly declined. */
20923
20961
  SIGN_DATA_ERROR_CODES[SIGN_DATA_ERROR_CODES["USER_REJECTS_ERROR"] = 300] = "USER_REJECTS_ERROR";
20962
+ /** Wallet does not support `signData` method or the requested `type`. */
20924
20963
  SIGN_DATA_ERROR_CODES[SIGN_DATA_ERROR_CODES["METHOD_NOT_SUPPORTED"] = 400] = "METHOD_NOT_SUPPORTED";
20925
20964
  })(SIGN_DATA_ERROR_CODES$1 || (SIGN_DATA_ERROR_CODES$1 = {}));
20965
+ /**
20966
+ * Error codes the wallet may return from `disconnect`.
20967
+
20968
+ * @see [`disconnect` errors (RPC spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/rpc.md#disconnect)
20969
+ */
20926
20970
  var DISCONNECT_ERROR_CODES$1;
20927
20971
  (function(DISCONNECT_ERROR_CODES) {
20928
20972
  DISCONNECT_ERROR_CODES[DISCONNECT_ERROR_CODES["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
@@ -20930,14 +20974,27 @@ var DISCONNECT_ERROR_CODES$1;
20930
20974
  DISCONNECT_ERROR_CODES[DISCONNECT_ERROR_CODES["UNKNOWN_APP_ERROR"] = 100] = "UNKNOWN_APP_ERROR";
20931
20975
  DISCONNECT_ERROR_CODES[DISCONNECT_ERROR_CODES["METHOD_NOT_SUPPORTED"] = 400] = "METHOD_NOT_SUPPORTED";
20932
20976
  })(DISCONNECT_ERROR_CODES$1 || (DISCONNECT_ERROR_CODES$1 = {}));
20977
+ /**
20978
+ * Error codes the wallet may return from `signMessage`.
20979
+ *
20980
+ * @see [`signMessage` errors (RPC spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/rpc.md#signmessage)
20981
+ */
20933
20982
  var SIGN_MESSAGE_ERROR_CODES;
20934
20983
  (function(SIGN_MESSAGE_ERROR_CODES) {
20984
+ /** Unexpected wallet-side failure. */
20935
20985
  SIGN_MESSAGE_ERROR_CODES[SIGN_MESSAGE_ERROR_CODES["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
20986
+ /** Invalid request payload. */
20936
20987
  SIGN_MESSAGE_ERROR_CODES[SIGN_MESSAGE_ERROR_CODES["BAD_REQUEST_ERROR"] = 1] = "BAD_REQUEST_ERROR";
20988
+ /** Wallet does not know the dApp / session. */
20937
20989
  SIGN_MESSAGE_ERROR_CODES[SIGN_MESSAGE_ERROR_CODES["UNKNOWN_APP_ERROR"] = 100] = "UNKNOWN_APP_ERROR";
20990
+ /** User explicitly declined. */
20938
20991
  SIGN_MESSAGE_ERROR_CODES[SIGN_MESSAGE_ERROR_CODES["USER_REJECTS_ERROR"] = 300] = "USER_REJECTS_ERROR";
20992
+ /** Wallet does not support `signMessage`. */
20939
20993
  SIGN_MESSAGE_ERROR_CODES[SIGN_MESSAGE_ERROR_CODES["METHOD_NOT_SUPPORTED"] = 400] = "METHOD_NOT_SUPPORTED";
20940
20994
  })(SIGN_MESSAGE_ERROR_CODES || (SIGN_MESSAGE_ERROR_CODES = {}));
20995
+ /**
20996
+ * Two baseline TON network IDs.
20997
+ */
20941
20998
  var CHAIN$1;
20942
20999
  (function(CHAIN) {
20943
21000
  CHAIN["MAINNET"] = "-239";
@@ -20979,6 +21036,20 @@ function decode$1(value, urlSafe = false) {
20979
21036
  }
20980
21037
  };
20981
21038
  }
21039
+ /**
21040
+ * UTF-8 base64 codec used by `@tonconnect/protocol`. Wraps the NaCl
21041
+ * helpers with optional URL-safe encoding and a typed decoder that can
21042
+ * yield a string, an object (JSON-parsed), or the raw byte array.
21043
+ *
21044
+ * @example
21045
+ * ```ts
21046
+ * import { Base64 } from '@tonconnect/protocol';
21047
+ *
21048
+ * const encoded = Base64.encode({ hello: 'world' });
21049
+ * const obj = Base64.decode(encoded).toObject<{ hello: string }>();
21050
+ * const bin = Base64.decode(Base64.encode('Hello')).toUint8Array();
21051
+ * ```
21052
+ */
20982
21053
  const Base64$1 = {
20983
21054
  encode: encode$1,
20984
21055
  decode: decode$1
@@ -21102,16 +21173,22 @@ function decodeEmbeddedRequestParam(reqParam) {
21102
21173
  const json = fromBase64Url(reqParam);
21103
21174
  return decodeWireEmbeddedRequest(JSON.parse(json));
21104
21175
  }
21176
+ /** Concatenate two byte arrays into a new `Uint8Array`. */
21105
21177
  function concatUint8Arrays(buffer1, buffer2) {
21106
21178
  const mergedArray = new Uint8Array(buffer1.length + buffer2.length);
21107
21179
  mergedArray.set(buffer1);
21108
21180
  mergedArray.set(buffer2, buffer1.length);
21109
21181
  return mergedArray;
21110
21182
  }
21183
+ /**
21184
+ * Split `array` at `index` and return the two halves as fresh
21185
+ * `Uint8Array`s.
21186
+ */
21111
21187
  function splitToUint8Arrays(array, index) {
21112
21188
  if (index >= array.length) throw new Error("Index is out of buffer");
21113
21189
  return [array.slice(0, index), array.slice(index)];
21114
21190
  }
21191
+ /** Hex-encode a byte array, lowercase, no `0x` prefix. */
21115
21192
  function toHexString(byteArray) {
21116
21193
  let hexString = "";
21117
21194
  byteArray.forEach((byte) => {
@@ -21119,13 +21196,52 @@ function toHexString(byteArray) {
21119
21196
  });
21120
21197
  return hexString;
21121
21198
  }
21199
+ /**
21200
+ * Inverse of {@link toHexString}. Throws when `hexString` has an odd length.
21201
+ */
21122
21202
  function hexToByteArray$1(hexString) {
21123
21203
  if (hexString.length % 2 !== 0) throw new Error(`Cannot convert ${hexString} to bytesArray`);
21124
21204
  const result = new Uint8Array(hexString.length / 2);
21125
21205
  for (let i = 0; i < hexString.length; i += 2) result[i / 2] = parseInt(hexString.slice(i, i + 2), 16);
21126
21206
  return result;
21127
21207
  }
21208
+ /**
21209
+ * Implements the TON Connect session-encryption protocol on top of NaCl's
21210
+ * `crypto_box`.
21211
+ *
21212
+ * The protocol is symmetric: each side encrypts the messages it sends and
21213
+ * decrypts the messages it receives. On the dApp side that means encrypting
21214
+ * outgoing {@link AppMessage} and decrypting incoming {@link WalletMessage};
21215
+ * the wallet does the reverse.
21216
+ *
21217
+ * @example
21218
+ * ```ts
21219
+ * import { SessionCrypto, Base64, hexToByteArray } from '@tonconnect/protocol';
21220
+ *
21221
+ * // Generate a fresh session
21222
+ * const session = new SessionCrypto();
21223
+ * const myClientId = session.sessionId; // hex public key (sent to the peer)
21224
+ *
21225
+ * // Encrypt an outgoing message for the peer
21226
+ * const ciphertext = session.encrypt(
21227
+ * JSON.stringify(message),
21228
+ * hexToByteArray(peerClientId)
21229
+ * );
21230
+ *
21231
+ * // Decrypt an incoming message from the peer
21232
+ * const plaintext = session.decrypt(
21233
+ * Base64.decode(bridgeMessage.message).toUint8Array(),
21234
+ * hexToByteArray(bridgeMessage.from)
21235
+ * );
21236
+ * ```
21237
+ *
21238
+ * @see [Session protocol (Session spec)](https://github.com/ton-blockchain/ton-connect/blob/main/spec/session.md)
21239
+ */
21128
21240
  var SessionCrypto = class {
21241
+ /**
21242
+ * Reuse an existing {@link KeyPair} (resuming a session) or generate a
21243
+ * fresh one (`crypto_box.keyPair()`) when omitted.
21244
+ */
21129
21245
  constructor(keyPair) {
21130
21246
  this.nonceLength = 24;
21131
21247
  this.keyPair = keyPair ? this.createKeypairFromString(keyPair) : this.createKeypair();
@@ -21143,17 +21259,31 @@ var SessionCrypto = class {
21143
21259
  createNonce() {
21144
21260
  return import_nacl_fast.default.randomBytes(this.nonceLength);
21145
21261
  }
21262
+ /**
21263
+ * Encrypt `message` for `receiverPublicKey` using a fresh 24-byte random
21264
+ * nonce. Returns `nonce || ciphertext` as raw bytes; base64-encode this
21265
+ * value before placing it in the bridge `POST /message` body.
21266
+ */
21146
21267
  encrypt(message, receiverPublicKey) {
21147
21268
  const encodedMessage = new TextEncoder().encode(message);
21148
21269
  const nonce = this.createNonce();
21149
21270
  return concatUint8Arrays(nonce, import_nacl_fast.default.box(encodedMessage, nonce, receiverPublicKey, this.keyPair.secretKey));
21150
21271
  }
21272
+ /**
21273
+ * Decrypt the `nonce || ciphertext` blob received from the bridge.
21274
+ * Throws if `nacl.box.open` rejects the message — wrong key, truncated
21275
+ * input or tampered ciphertext.
21276
+ */
21151
21277
  decrypt(message, senderPublicKey) {
21152
21278
  const [nonce, internalMessage] = splitToUint8Arrays(message, this.nonceLength);
21153
21279
  const decrypted = import_nacl_fast.default.box.open(internalMessage, nonce, senderPublicKey, this.keyPair.secretKey);
21154
21280
  if (!decrypted) throw new Error(`Decryption error: \n message: ${message.toString()} \n sender pubkey: ${senderPublicKey.toString()} \n keypair pubkey: ${this.keyPair.publicKey.toString()} \n keypair secretkey: ${this.keyPair.secretKey.toString()}`);
21155
21281
  return new TextDecoder().decode(decrypted);
21156
21282
  }
21283
+ /**
21284
+ * Export the underlying keypair as a {@link KeyPair} of hex strings.
21285
+ * Persist this in dApp / wallet storage to resume the session later.
21286
+ */
21157
21287
  stringifyKeypair() {
21158
21288
  return {
21159
21289
  publicKey: toHexString(this.keyPair.publicKey),
@@ -41756,7 +41886,7 @@ async function CallForSuccess(toCall, attempts = 20, delayMs = 100, shouldRetry)
41756
41886
  return await toCall();
41757
41887
  } catch (err) {
41758
41888
  lastError = err;
41759
- if (shouldRetry && !shouldRetry(err)) throw err;
41889
+ if (typeof shouldRetry === "function" && shouldRetry(err) === false) throw err;
41760
41890
  i++;
41761
41891
  await delay(delayMs);
41762
41892
  }
@@ -41877,7 +42007,7 @@ var MemoryStorageAdapter = class {
41877
42007
  * LICENSE file in the root directory of this source tree.
41878
42008
  *
41879
42009
  */
41880
- const log$37 = globalLogger.createChild("StorageAdapter");
42010
+ const log$38 = globalLogger.createChild("StorageAdapter");
41881
42011
  /**
41882
42012
  * Create storage adapter based on environment and preferences
41883
42013
  */
@@ -41885,7 +42015,7 @@ function createStorageAdapter(config = {}) {
41885
42015
  if (typeof localStorage !== "undefined") try {
41886
42016
  return new LocalStorageAdapter(config);
41887
42017
  } catch (error) {
41888
- log$37.warn("Failed to create LocalStorageAdapter, falling back to memory", { error });
42018
+ log$38.warn("Failed to create LocalStorageAdapter, falling back to memory", { error });
41889
42019
  }
41890
42020
  if (config.allowMemory) return new MemoryStorageAdapter(config);
41891
42021
  else throw new Error("No storage adapter available");
@@ -41899,7 +42029,7 @@ function createStorageAdapter(config = {}) {
41899
42029
  * LICENSE file in the root directory of this source tree.
41900
42030
  *
41901
42031
  */
41902
- const log$36 = globalLogger.createChild("Storage");
42032
+ const log$37 = globalLogger.createChild("Storage");
41903
42033
  /**
41904
42034
  * High-level storage interface with generic type support
41905
42035
  * Wraps StorageAdapter to provide type-safe get/set operations
@@ -41920,7 +42050,7 @@ var Storage = class {
41920
42050
  if (value === null) return null;
41921
42051
  return JSON.parse(value);
41922
42052
  } catch (error) {
41923
- log$36.warn("Failed to parse stored value", {
42053
+ log$37.warn("Failed to parse stored value", {
41924
42054
  key,
41925
42055
  error
41926
42056
  });
@@ -41937,7 +42067,7 @@ var Storage = class {
41937
42067
  const serialized = JSON.stringify(value);
41938
42068
  await this.adapter.set(key, serialized);
41939
42069
  } catch (error) {
41940
- log$36.error("Failed to serialize value for storage", {
42070
+ log$37.error("Failed to serialize value for storage", {
41941
42071
  key,
41942
42072
  error
41943
42073
  });
@@ -42316,7 +42446,7 @@ var WalletManager = class {
42316
42446
  * LICENSE file in the root directory of this source tree.
42317
42447
  *
42318
42448
  */
42319
- const log$35 = globalLogger.createChild("TONConnectStoredSessionManager");
42449
+ const log$36 = globalLogger.createChild("TONConnectStoredSessionManager");
42320
42450
  var TONConnectStoredSessionManager = class {
42321
42451
  sessions = /* @__PURE__ */ new Map();
42322
42452
  storage;
@@ -42449,16 +42579,16 @@ var TONConnectStoredSessionManager = class {
42449
42579
  const wallet = this.walletManager.getWallet(session.walletId);
42450
42580
  if (wallet) session.walletAddress = wallet.getAddress();
42451
42581
  else {
42452
- log$35.warn("Session Wallet not found for session", { sessionId: session.sessionId });
42582
+ log$36.warn("Session Wallet not found for session", { sessionId: session.sessionId });
42453
42583
  continue;
42454
42584
  }
42455
42585
  }
42456
42586
  this.sessions.set(session.sessionId, session);
42457
42587
  }
42458
- log$35.debug("Loaded session metadata", { count: storedSessions.length });
42588
+ log$36.debug("Loaded session metadata", { count: storedSessions.length });
42459
42589
  }
42460
42590
  } catch (error) {
42461
- log$35.warn("Failed to load sessions from storage", { error });
42591
+ log$36.warn("Failed to load sessions from storage", { error });
42462
42592
  }
42463
42593
  }
42464
42594
  /**
@@ -42469,7 +42599,7 @@ var TONConnectStoredSessionManager = class {
42469
42599
  const sessionsToStore = Array.from(this.sessions.values());
42470
42600
  await this.storage.set(this.storageKey, sessionsToStore);
42471
42601
  } catch (error) {
42472
- log$35.warn("Failed to persist sessions to storage", { error });
42602
+ log$36.warn("Failed to persist sessions to storage", { error });
42473
42603
  }
42474
42604
  }
42475
42605
  async migrateSessions() {
@@ -82640,7 +82770,7 @@ globalLogger.createChild("ExtensionTransport");
82640
82770
  * LICENSE file in the root directory of this source tree.
82641
82771
  *
82642
82772
  */
82643
- const log$33 = globalLogger.createChild("BridgeManager");
82773
+ const log$34 = globalLogger.createChild("BridgeManager");
82644
82774
  var BridgeManager = class {
82645
82775
  config;
82646
82776
  bridgeProvider;
@@ -82682,7 +82812,7 @@ var BridgeManager = class {
82682
82812
  this.walletKitConfig = walletKitConfig;
82683
82813
  this.jsBridgeTransport = config?.jsBridgeTransport;
82684
82814
  if (this.config.bridgeUrl && !this.config.disableHttpConnection) this.bridgeProvider = new C(this.config.bridgeUrl, this.queueBridgeEvent.bind(this), (error) => {
82685
- log$33.error("Bridge listener error", { error: error.toString() });
82815
+ log$34.error("Bridge listener error", { error: error.toString() });
82686
82816
  this.analytics?.emitBridgeClientConnectError({
82687
82817
  error_message: `${error?.toString() || "Unknown error"}${error?.errorCode ? ` (Code: ${error?.errorCode})` : ""}`,
82688
82818
  trace_id: error?.traceId,
@@ -82696,12 +82826,12 @@ var BridgeManager = class {
82696
82826
  */
82697
82827
  async start() {
82698
82828
  if (this.isActive === true) {
82699
- log$33.warn("Bridge already started");
82829
+ log$34.warn("Bridge already started");
82700
82830
  return;
82701
82831
  }
82702
82832
  this.isActive = true;
82703
82833
  if (this.isConnected === true) {
82704
- log$33.warn("Bridge already connected");
82834
+ log$34.warn("Bridge already connected");
82705
82835
  return;
82706
82836
  }
82707
82837
  try {
@@ -82713,7 +82843,7 @@ var BridgeManager = class {
82713
82843
  }
82714
82844
  } catch (error) {
82715
82845
  this.isActive = false;
82716
- log$33.error("Failed to start bridge", { error });
82846
+ log$34.error("Failed to start bridge", { error });
82717
82847
  throw error;
82718
82848
  }
82719
82849
  const requestProcessing = () => {
@@ -82726,10 +82856,10 @@ var BridgeManager = class {
82726
82856
  * Create new session for a dApp connection
82727
82857
  */
82728
82858
  async createSession(appSessionId) {
82729
- log$33.info("[BRIDGE] Creating session", { appSessionId });
82859
+ log$34.info("[BRIDGE] Creating session", { appSessionId });
82730
82860
  if (!await this.sessionManager.getSession(appSessionId)) throw new WalletKitError(ERROR_CODES.SESSION_NOT_FOUND, `Session not found`, void 0, { appSessionId });
82731
82861
  if (this.bridgeProvider && this.isConnected) {
82732
- log$33.info("[BRIDGE] Updating clients");
82862
+ log$34.info("[BRIDGE] Updating clients");
82733
82863
  await this.updateClients();
82734
82864
  }
82735
82865
  }
@@ -82738,7 +82868,7 @@ var BridgeManager = class {
82738
82868
  */
82739
82869
  async removeSession(appSessionId) {
82740
82870
  if (this.bridgeProvider && this.isConnected) await this.updateClients();
82741
- log$33.debug("Session removed", { appSessionId });
82871
+ log$34.debug("Session removed", { appSessionId });
82742
82872
  }
82743
82873
  /**
82744
82874
  * Send response to dApp
@@ -82763,12 +82893,12 @@ var BridgeManager = class {
82763
82893
  }
82764
82894
  try {
82765
82895
  await this.bridgeProvider.send(response, sessionCrypto, sessionId, { traceId: event?.traceId });
82766
- log$33.debug("Response sent successfully", {
82896
+ log$34.debug("Response sent successfully", {
82767
82897
  sessionId,
82768
82898
  requestId: event.id
82769
82899
  });
82770
82900
  } catch (error) {
82771
- log$33.error("Failed to send response through bridge", {
82901
+ log$34.error("Failed to send response through bridge", {
82772
82902
  sessionId,
82773
82903
  requestId: event.id,
82774
82904
  error
@@ -82850,7 +82980,7 @@ var BridgeManager = class {
82850
82980
  await this.bridgeProvider?.restoreConnection(clients, { lastEventId: this.lastEventId });
82851
82981
  this.isConnected = true;
82852
82982
  this.reconnectAttempts = 0;
82853
- log$33.info("Bridge connected successfully");
82983
+ log$34.info("Bridge connected successfully");
82854
82984
  if (this.analytics) {
82855
82985
  const client = clients[0];
82856
82986
  this.analytics.emitBridgeClientConnectEstablished({
@@ -82859,7 +82989,7 @@ var BridgeManager = class {
82859
82989
  });
82860
82990
  }
82861
82991
  } catch (error) {
82862
- log$33.error("Bridge connection failed", { error: error?.toString() });
82992
+ log$34.error("Bridge connection failed", { error: error?.toString() });
82863
82993
  this.analytics?.emitBridgeClientConnectError({
82864
82994
  error_message: `${error?.toString() || "Unknown error"}${error?.errorCode ? ` (Code: ${error?.errorCode})` : ""}`,
82865
82995
  trace_id: error?.traceId ?? connectTraceId,
@@ -82868,9 +82998,9 @@ var BridgeManager = class {
82868
82998
  if (!this.config.disableHttpConnection) {
82869
82999
  if (this.reconnectAttempts < (this.config.maxReconnectAttempts || 5)) {
82870
83000
  this.reconnectAttempts++;
82871
- log$33.info("Bridge reconnection attempt", { attempt: this.reconnectAttempts });
83001
+ log$34.info("Bridge reconnection attempt", { attempt: this.reconnectAttempts });
82872
83002
  setTimeout(() => {
82873
- this.connectToSSEBridge().catch((error) => log$33.error("Bridge reconnection failed", { error }));
83003
+ this.connectToSSEBridge().catch((error) => log$34.error("Bridge reconnection failed", { error }));
82874
83004
  }, this.config.reconnectInterval);
82875
83005
  }
82876
83006
  }
@@ -82891,10 +83021,10 @@ var BridgeManager = class {
82891
83021
  * Add client to existing bridge connection
82892
83022
  */
82893
83023
  async updateClients() {
82894
- log$33.debug("Updating clients");
83024
+ log$34.debug("Updating clients");
82895
83025
  if (this.bridgeProvider) {
82896
83026
  const clients = await this.getClients();
82897
- log$33.info("[BRIDGE] Restoring connection", { clients: clients.length });
83027
+ log$34.info("[BRIDGE] Restoring connection", { clients: clients.length });
82898
83028
  await this.bridgeProvider.restoreConnection(clients, { lastEventId: this.lastEventId });
82899
83029
  }
82900
83030
  }
@@ -82902,17 +83032,17 @@ var BridgeManager = class {
82902
83032
  * Queue incoming bridge events for processing
82903
83033
  */
82904
83034
  queueBridgeEvent(event) {
82905
- log$33.debug("Bridge event queued", {
83035
+ log$34.debug("Bridge event queued", {
82906
83036
  eventId: event?.id,
82907
83037
  event
82908
83038
  });
82909
83039
  this.eventQueue.push(event);
82910
83040
  this.processBridgeEvents().catch((error) => {
82911
- log$33.error("Error in background event processing", { error });
83041
+ log$34.error("Error in background event processing", { error });
82912
83042
  });
82913
83043
  }
82914
83044
  queueJsBridgeEvent(messageInfo, event) {
82915
- log$33.debug("JS Bridge event queued", { eventId: messageInfo?.messageId });
83045
+ log$34.debug("JS Bridge event queued", { eventId: messageInfo?.messageId });
82916
83046
  if (!event) return;
82917
83047
  if (!event.traceId) event.traceId = v7();
82918
83048
  if (event.method == "connect") this.eventQueue.push({
@@ -82941,7 +83071,7 @@ var BridgeManager = class {
82941
83071
  walletId: messageInfo.walletId
82942
83072
  });
82943
83073
  this.processBridgeEvents().catch((error) => {
82944
- log$33.error("Error in background event processing", { error });
83074
+ log$34.error("Error in background event processing", { error });
82945
83075
  });
82946
83076
  }
82947
83077
  /**
@@ -82953,7 +83083,7 @@ var BridgeManager = class {
82953
83083
  */
82954
83084
  async processBridgeEvents() {
82955
83085
  if (this.isProcessing) {
82956
- log$33.debug("Event processing already in progress, skipping");
83086
+ log$34.debug("Event processing already in progress, skipping");
82957
83087
  return;
82958
83088
  }
82959
83089
  this.isProcessing = true;
@@ -82966,7 +83096,7 @@ var BridgeManager = class {
82966
83096
  }
82967
83097
  }
82968
83098
  } catch (error) {
82969
- log$33.error("Error during event processing", { error });
83099
+ log$34.error("Error during event processing", { error });
82970
83100
  this.isProcessing = false;
82971
83101
  this.restartConnection();
82972
83102
  return;
@@ -82979,7 +83109,7 @@ var BridgeManager = class {
82979
83109
  */
82980
83110
  async handleBridgeEvent(event) {
82981
83111
  try {
82982
- log$33.info("Bridge event received", { event });
83112
+ log$34.info("Bridge event received", { event });
82983
83113
  const rawEvent = {
82984
83114
  id: event.id || crypto.randomUUID(),
82985
83115
  method: event.method || "unknown",
@@ -83033,12 +83163,12 @@ var BridgeManager = class {
83033
83163
  try {
83034
83164
  await this.eventStore.storeEvent(rawEvent);
83035
83165
  if (this.eventEmitter) this.eventEmitter.emit("bridgeStorageUpdated", {}, "bridge-manager");
83036
- log$33.info("Event stored durably", {
83166
+ log$34.info("Event stored durably", {
83037
83167
  eventId: rawEvent.id,
83038
83168
  method: rawEvent.method
83039
83169
  });
83040
83170
  } catch (error) {
83041
- log$33.error("Failed to store event durably", {
83171
+ log$34.error("Failed to store event durably", {
83042
83172
  eventId: rawEvent.id,
83043
83173
  error: error.message
83044
83174
  });
@@ -83047,13 +83177,13 @@ var BridgeManager = class {
83047
83177
  method: rawEvent.method
83048
83178
  });
83049
83179
  }
83050
- log$33.info("Bridge event processed", { rawEvent });
83180
+ log$34.info("Bridge event processed", { rawEvent });
83051
83181
  if (event?.lastEventId && event.lastEventId !== this.lastEventId) {
83052
83182
  this.lastEventId = event.lastEventId;
83053
83183
  await this.saveLastEventId();
83054
83184
  }
83055
83185
  } catch (error) {
83056
- log$33.error("Error handling bridge event", { error });
83186
+ log$34.error("Error handling bridge event", { error });
83057
83187
  }
83058
83188
  }
83059
83189
  /**
@@ -83064,11 +83194,11 @@ var BridgeManager = class {
83064
83194
  const savedEventId = await this.storage.get(this.storageKey);
83065
83195
  if (savedEventId) {
83066
83196
  this.lastEventId = savedEventId;
83067
- log$33.debug("Loaded last event ID from storage", { lastEventId: this.lastEventId });
83197
+ log$34.debug("Loaded last event ID from storage", { lastEventId: this.lastEventId });
83068
83198
  }
83069
83199
  } catch (error) {
83070
83200
  const storageError = WalletKitError.fromError(ERROR_CODES.STORAGE_READ_FAILED, "Failed to load last event ID from storage", error);
83071
- log$33.warn("Failed to load last event ID from storage", { error: storageError });
83201
+ log$34.warn("Failed to load last event ID from storage", { error: storageError });
83072
83202
  }
83073
83203
  }
83074
83204
  /**
@@ -83078,11 +83208,11 @@ var BridgeManager = class {
83078
83208
  try {
83079
83209
  if (this.lastEventId) {
83080
83210
  await this.storage.set(this.storageKey, this.lastEventId);
83081
- log$33.debug("Saved last event ID to storage", { lastEventId: this.lastEventId });
83211
+ log$34.debug("Saved last event ID to storage", { lastEventId: this.lastEventId });
83082
83212
  }
83083
83213
  } catch (error) {
83084
83214
  const storageError = WalletKitError.fromError(ERROR_CODES.STORAGE_WRITE_FAILED, "Failed to save last event ID to storage", error);
83085
- log$33.warn("Failed to save last event ID to storage", { error: storageError });
83215
+ log$34.warn("Failed to save last event ID to storage", { error: storageError });
83086
83216
  }
83087
83217
  }
83088
83218
  };
@@ -83137,7 +83267,7 @@ function isValidHost(host) {
83137
83267
  * LICENSE file in the root directory of this source tree.
83138
83268
  *
83139
83269
  */
83140
- const log$32 = globalLogger.createChild("ManifestUtils");
83270
+ const log$33 = globalLogger.createChild("ManifestUtils");
83141
83271
  async function fetchManifest(manifestUrl, proxyUrl) {
83142
83272
  try {
83143
83273
  if (!isValidHost(new URL(manifestUrl).host)) return {
@@ -83156,14 +83286,14 @@ async function fetchManifest(manifestUrl, proxyUrl) {
83156
83286
  manifest: null,
83157
83287
  manifestFetchErrorCode: CONNECT_EVENT_ERROR_CODES$1.MANIFEST_CONTENT_ERROR
83158
83288
  };
83159
- log$32.info("Direct manifest fetch failed, trying proxy", { manifestUrl });
83289
+ log$33.info("Direct manifest fetch failed, trying proxy", { manifestUrl });
83160
83290
  return tryFetchManifest(`${proxyUrl}${manifestUrl}`);
83161
83291
  }
83162
83292
  async function tryFetchManifest(url) {
83163
83293
  try {
83164
83294
  const response = await fetch(url);
83165
83295
  if (!response.ok) {
83166
- log$32.error("Failed to fetch manifest not ok", {
83296
+ log$33.error("Failed to fetch manifest not ok", {
83167
83297
  url,
83168
83298
  status: response.status
83169
83299
  });
@@ -83177,7 +83307,7 @@ async function tryFetchManifest(url) {
83177
83307
  manifestFetchErrorCode: void 0
83178
83308
  };
83179
83309
  } catch (e) {
83180
- log$32.error("Failed to fetch manifest catched", {
83310
+ log$33.error("Failed to fetch manifest catched", {
83181
83311
  url,
83182
83312
  error: e
83183
83313
  });
@@ -83196,7 +83326,7 @@ async function tryFetchManifest(url) {
83196
83326
  * LICENSE file in the root directory of this source tree.
83197
83327
  *
83198
83328
  */
83199
- const log$31 = globalLogger.createChild("ConnectHandler");
83329
+ const log$32 = globalLogger.createChild("ConnectHandler");
83200
83330
  var ConnectHandler = class extends BasicHandler {
83201
83331
  config;
83202
83332
  analytics;
@@ -83217,7 +83347,7 @@ var ConnectHandler = class extends BasicHandler {
83217
83347
  manifest = result.manifest;
83218
83348
  manifestFetchErrorCode = result.manifestFetchErrorCode;
83219
83349
  } catch (error) {
83220
- log$31.warn("Failed to fetch manifest", { error });
83350
+ log$32.warn("Failed to fetch manifest", { error });
83221
83351
  }
83222
83352
  const preview = this.createPreview(event, manifestUrl, manifest, manifestFetchErrorCode);
83223
83353
  const connectEvent = {
@@ -83278,14 +83408,14 @@ var ConnectHandler = class extends BasicHandler {
83278
83408
  if (!finalManifestFetchErrorCode && dAppUrl) try {
83279
83409
  const parsedDAppUrl = new URL(dAppUrl);
83280
83410
  if (!isValidHost(parsedDAppUrl.host)) {
83281
- log$31.warn("Invalid dApp URL in manifest - invalid host format", {
83411
+ log$32.warn("Invalid dApp URL in manifest - invalid host format", {
83282
83412
  dAppUrl,
83283
83413
  host: parsedDAppUrl.host
83284
83414
  });
83285
83415
  finalManifestFetchErrorCode = CONNECT_EVENT_ERROR_CODES$1.MANIFEST_CONTENT_ERROR;
83286
83416
  }
83287
83417
  } catch (_) {
83288
- log$31.warn("Invalid dApp URL in manifest - failed to parse", { dAppUrl });
83418
+ log$32.warn("Invalid dApp URL in manifest - failed to parse", { dAppUrl });
83289
83419
  finalManifestFetchErrorCode = CONNECT_EVENT_ERROR_CODES$1.MANIFEST_CONTENT_ERROR;
83290
83420
  }
83291
83421
  }
@@ -83945,7 +84075,7 @@ function createTransferTransaction(params) {
83945
84075
  * LICENSE file in the root directory of this source tree.
83946
84076
  *
83947
84077
  */
83948
- const log$30 = globalLogger.createChild("ItemsResolver");
84078
+ const log$31 = globalLogger.createChild("ItemsResolver");
83949
84079
  /**
83950
84080
  * Resolve structured items (ton/jetton/nft) into raw TransactionRequestMessages.
83951
84081
  * After resolution, downstream code only needs to handle messages.
@@ -83963,7 +84093,7 @@ async function resolveItemsToMessages(items, wallet) {
83963
84093
  messages.push(resolveNftItem(item, wallet));
83964
84094
  break;
83965
84095
  default:
83966
- log$30.warn("Unknown item type, skipping", { item });
84096
+ log$31.warn("Unknown item type, skipping", { item });
83967
84097
  break;
83968
84098
  }
83969
84099
  return messages;
@@ -84025,7 +84155,7 @@ function resolveNftItem(item, wallet) {
84025
84155
  * LICENSE file in the root directory of this source tree.
84026
84156
  *
84027
84157
  */
84028
- const log$29 = globalLogger.createChild("EventsUtils");
84158
+ const log$30 = globalLogger.createChild("EventsUtils");
84029
84159
  /**
84030
84160
  * Helper to get wallet from event
84031
84161
  */
@@ -84084,7 +84214,7 @@ function parseTonConnectTransactionRequest(event, wallet) {
84084
84214
  validation: validateTransactionRequestForWallet(request, wallet, event.isLocal)
84085
84215
  };
84086
84216
  } catch (error) {
84087
- log$29.error("Failed to parse transaction request", { error });
84217
+ log$30.error("Failed to parse transaction request", { error });
84088
84218
  errors.push("Failed to parse transaction request");
84089
84219
  return {
84090
84220
  result: void 0,
@@ -86457,7 +86587,7 @@ async function computeMoneyFlow(client, response, options = {}) {
86457
86587
  * LICENSE file in the root directory of this source tree.
86458
86588
  *
86459
86589
  */
86460
- const log$28 = globalLogger.createChild("TransactionPreview");
86590
+ const log$29 = globalLogger.createChild("TransactionPreview");
86461
86591
  const SIGN_MODE_EMULATION_VALUE = 2000000000n;
86462
86592
  async function createTransactionPreview(client, request, wallet, options = {}) {
86463
86593
  const isSignMode = (options.mode ?? "send") === "sign";
@@ -86509,7 +86639,7 @@ async function createTransactionPreviewIfPossible(config, client, request, walle
86509
86639
  try {
86510
86640
  preview = await CallForSuccess(() => createTransactionPreview(client, request, wallet, options));
86511
86641
  } catch (error) {
86512
- log$28.error("Failed to create transaction preview", { error });
86642
+ log$29.error("Failed to create transaction preview", { error });
86513
86643
  preview = {
86514
86644
  error: {
86515
86645
  code: ERROR_CODES.UNKNOWN_EMULATION_ERROR,
@@ -86784,7 +86914,7 @@ async function getTransactionStatus(client, params) {
86784
86914
  * LICENSE file in the root directory of this source tree.
86785
86915
  *
86786
86916
  */
86787
- const log$27 = globalLogger.createChild("TransactionHandler");
86917
+ const log$28 = globalLogger.createChild("TransactionHandler");
86788
86918
  var TransactionHandler = class extends BasicHandler {
86789
86919
  config;
86790
86920
  walletManager;
@@ -86806,7 +86936,7 @@ var TransactionHandler = class extends BasicHandler {
86806
86936
  async handle(event) {
86807
86937
  const wallet = getWalletFromEvent(this.walletManager, event);
86808
86938
  if (!wallet) {
86809
- log$27.error("Wallet not found", { event });
86939
+ log$28.error("Wallet not found", { event });
86810
86940
  return {
86811
86941
  error: {
86812
86942
  code: SEND_TRANSACTION_ERROR_CODES$1.UNKNOWN_APP_ERROR,
@@ -86817,7 +86947,7 @@ var TransactionHandler = class extends BasicHandler {
86817
86947
  }
86818
86948
  const requestValidation = this.parseTonConnectTransactionRequest(event, wallet);
86819
86949
  if (!requestValidation.result || !requestValidation?.validation?.isValid) {
86820
- log$27.error("Failed to parse transaction request", {
86950
+ log$28.error("Failed to parse transaction request", {
86821
86951
  event,
86822
86952
  requestValidation
86823
86953
  });
@@ -86869,7 +86999,7 @@ var TransactionHandler = class extends BasicHandler {
86869
86999
  * LICENSE file in the root directory of this source tree.
86870
87000
  *
86871
87001
  */
86872
- const log$26 = globalLogger.createChild("SignDataHandler");
87002
+ const log$27 = globalLogger.createChild("SignDataHandler");
86873
87003
  var SignDataHandler = class extends BasicHandler {
86874
87004
  analytics;
86875
87005
  walletManager;
@@ -86890,12 +87020,12 @@ var SignDataHandler = class extends BasicHandler {
86890
87020
  const wallet = walletId ? this.walletManager.getWallet(walletId) : void 0;
86891
87021
  const payload = this.parseDataToSign(event);
86892
87022
  if (!payload) {
86893
- log$26.error("No data to sign found in request", { event });
87023
+ log$27.error("No data to sign found in request", { event });
86894
87024
  throw new WalletKitError(ERROR_CODES.INVALID_REQUEST_EVENT, "No data to sign found in request", void 0, { eventId: event.id });
86895
87025
  }
86896
87026
  const preview = this.createDataPreview(payload.data, event);
86897
87027
  if (!preview) {
86898
- log$26.error("No preview found for data", { data: payload });
87028
+ log$27.error("No preview found for data", { data: payload });
86899
87029
  throw new WalletKitError(ERROR_CODES.RESPONSE_CREATION_FAILED, "Failed to create preview for sign data request", void 0, {
86900
87030
  eventId: event.id,
86901
87031
  data: payload
@@ -86952,7 +87082,7 @@ var SignDataHandler = class extends BasicHandler {
86952
87082
  }
86953
87083
  };
86954
87084
  } catch (error) {
86955
- log$26.error("Error deserializing cell", { error });
87085
+ log$27.error("Error deserializing cell", { error });
86956
87086
  return {
86957
87087
  type: "cell",
86958
87088
  value: {
@@ -86972,7 +87102,7 @@ var SignDataHandler = class extends BasicHandler {
86972
87102
  * LICENSE file in the root directory of this source tree.
86973
87103
  *
86974
87104
  */
86975
- const log$25 = globalLogger.createChild("SignMessageHandler");
87105
+ const log$26 = globalLogger.createChild("SignMessageHandler");
86976
87106
  var SignMessageHandler = class extends BasicHandler {
86977
87107
  config;
86978
87108
  walletManager;
@@ -86994,7 +87124,7 @@ var SignMessageHandler = class extends BasicHandler {
86994
87124
  async handle(event) {
86995
87125
  const wallet = getWalletFromEvent(this.walletManager, event);
86996
87126
  if (!wallet) {
86997
- log$25.error("Wallet not found", { event });
87127
+ log$26.error("Wallet not found", { event });
86998
87128
  return {
86999
87129
  error: {
87000
87130
  code: SIGN_MESSAGE_ERROR_CODES.UNKNOWN_APP_ERROR,
@@ -87005,7 +87135,7 @@ var SignMessageHandler = class extends BasicHandler {
87005
87135
  }
87006
87136
  const requestValidation = this.parseTonConnectTransactionRequest(event, wallet);
87007
87137
  if (!requestValidation.result || !requestValidation?.validation?.isValid) {
87008
- log$25.error("Failed to parse sign message request", {
87138
+ log$26.error("Failed to parse sign message request", {
87009
87139
  event,
87010
87140
  requestValidation
87011
87141
  });
@@ -87098,7 +87228,7 @@ var DisconnectHandler = class extends BasicHandler {
87098
87228
  * LICENSE file in the root directory of this source tree.
87099
87229
  *
87100
87230
  */
87101
- const log$24 = globalLogger.createChild("EventRouter");
87231
+ const log$25 = globalLogger.createChild("EventRouter");
87102
87232
  var EventRouter = class {
87103
87233
  config;
87104
87234
  eventEmitter;
@@ -87130,7 +87260,7 @@ var EventRouter = class {
87130
87260
  async routeEvent(event) {
87131
87261
  const validation = validateBridgeEvent(event);
87132
87262
  if (!validation.isValid) {
87133
- log$24.error("Invalid bridge event", { errors: validation.errors });
87263
+ log$25.error("Invalid bridge event", { errors: validation.errors });
87134
87264
  return;
87135
87265
  }
87136
87266
  try {
@@ -87145,7 +87275,7 @@ var EventRouter = class {
87145
87275
  try {
87146
87276
  await this.bridgeManager.sendResponse(event, result);
87147
87277
  } catch (error) {
87148
- log$24.error("Error sending response for error event", {
87278
+ log$25.error("Error sending response for error event", {
87149
87279
  error,
87150
87280
  event,
87151
87281
  result
@@ -87157,7 +87287,7 @@ var EventRouter = class {
87157
87287
  break;
87158
87288
  }
87159
87289
  } catch (error) {
87160
- log$24.error("Error routing event", { error });
87290
+ log$25.error("Error routing event", { error });
87161
87291
  throw error;
87162
87292
  }
87163
87293
  }
@@ -87284,7 +87414,7 @@ var EventRouter = class {
87284
87414
  * LICENSE file in the root directory of this source tree.
87285
87415
  *
87286
87416
  */
87287
- const log$23 = globalLogger.createChild("RequestProcessor");
87417
+ const log$24 = globalLogger.createChild("RequestProcessor");
87288
87418
  function hasConnectionResult(event) {
87289
87419
  return "connectionResult" in event;
87290
87420
  }
@@ -87353,7 +87483,7 @@ var RequestProcessor = class {
87353
87483
  }
87354
87484
  return;
87355
87485
  } catch (error) {
87356
- log$23.error("Failed to approve connect request", { error });
87486
+ log$24.error("Failed to approve connect request", { error });
87357
87487
  throw error;
87358
87488
  }
87359
87489
  }
@@ -87488,7 +87618,7 @@ var RequestProcessor = class {
87488
87618
  */
87489
87619
  async rejectConnectRequest(event, reason, errorCode) {
87490
87620
  try {
87491
- log$23.info("Connect request rejected", {
87621
+ log$24.info("Connect request rejected", {
87492
87622
  id: event.id,
87493
87623
  dAppName: event.preview.dAppInfo?.name || "",
87494
87624
  reason: reason || "User rejected connection"
@@ -87505,7 +87635,7 @@ var RequestProcessor = class {
87505
87635
  try {
87506
87636
  await this.bridgeManager.sendResponse(event, response, new SessionCrypto());
87507
87637
  } catch (error) {
87508
- log$23.error("Failed to send connect request rejection response", { error });
87638
+ log$24.error("Failed to send connect request rejection response", { error });
87509
87639
  }
87510
87640
  if (this.analytics) {
87511
87641
  const sessionData = event.from ? await this.sessionManager.getSession(sessionId) : void 0;
@@ -87534,7 +87664,7 @@ var RequestProcessor = class {
87534
87664
  }
87535
87665
  return;
87536
87666
  } catch (error) {
87537
- log$23.error("Failed to reject connect request", { error });
87667
+ log$24.error("Failed to reject connect request", { error });
87538
87668
  throw error;
87539
87669
  }
87540
87670
  }
@@ -87566,7 +87696,7 @@ var RequestProcessor = class {
87566
87696
  return { signedBoc };
87567
87697
  }
87568
87698
  } catch (error) {
87569
- log$23.error("Failed to approve transaction request", { error });
87699
+ log$24.error("Failed to approve transaction request", { error });
87570
87700
  if (error instanceof WalletKitError) throw error;
87571
87701
  if (error?.message?.includes("Ledger device")) throw new WalletKitError(ERROR_CODES.LEDGER_DEVICE_ERROR, "Ledger device error", error);
87572
87702
  throw error;
@@ -87616,7 +87746,7 @@ var RequestProcessor = class {
87616
87746
  }
87617
87747
  return;
87618
87748
  } catch (error) {
87619
- log$23.error("Failed to reject transaction request", { error });
87749
+ log$24.error("Failed to reject transaction request", { error });
87620
87750
  throw error;
87621
87751
  }
87622
87752
  }
@@ -87647,7 +87777,7 @@ var RequestProcessor = class {
87647
87777
  return { internalBoc };
87648
87778
  }
87649
87779
  } catch (error) {
87650
- log$23.error("Failed to approve sign message request", { error });
87780
+ log$24.error("Failed to approve sign message request", { error });
87651
87781
  throw error;
87652
87782
  }
87653
87783
  }
@@ -87665,7 +87795,7 @@ var RequestProcessor = class {
87665
87795
  };
87666
87796
  await this.sendBridgeMessage(event, void 0, response);
87667
87797
  } catch (error) {
87668
- log$23.error("Failed to reject sign message request", { error });
87798
+ log$24.error("Failed to reject sign message request", { error });
87669
87799
  throw error;
87670
87800
  }
87671
87801
  }
@@ -87768,7 +87898,7 @@ var RequestProcessor = class {
87768
87898
  };
87769
87899
  }
87770
87900
  } catch (error) {
87771
- log$23.error("Failed to approve sign data request", { error: error?.message?.toString() ?? error?.toString() });
87901
+ log$24.error("Failed to approve sign data request", { error: error?.message?.toString() ?? error?.toString() });
87772
87902
  if (error instanceof WalletKitError) throw error;
87773
87903
  throw error;
87774
87904
  }
@@ -87803,7 +87933,7 @@ var RequestProcessor = class {
87803
87933
  }
87804
87934
  return;
87805
87935
  } catch (error) {
87806
- log$23.error("Failed to reject sign data request", { error });
87936
+ log$24.error("Failed to reject sign data request", { error });
87807
87937
  throw error;
87808
87938
  }
87809
87939
  }
@@ -87882,7 +88012,7 @@ var RequestProcessor = class {
87882
88012
  */
87883
88013
  async function signTransactionInternal(wallet, request) {
87884
88014
  const signedBoc = await wallet.getSignedSendTransaction(request, { fakeSignature: false });
87885
- log$23.debug("Signing transaction", {
88015
+ log$24.debug("Signing transaction", {
87886
88016
  messagesNumber: request.messages.length,
87887
88017
  fromAddress: request.fromAddress,
87888
88018
  validUntil: request.validUntil
@@ -87938,7 +88068,7 @@ function parseDomain(url) {
87938
88068
  value: parsedUrl.host
87939
88069
  };
87940
88070
  } catch (error) {
87941
- log$23.error("Failed to parse domain", { error });
88071
+ log$24.error("Failed to parse domain", { error });
87942
88072
  return {
87943
88073
  lengthBytes: 0,
87944
88074
  value: ""
@@ -87978,7 +88108,7 @@ function toTonConnectSignDataPayload(payload) {
87978
88108
  const getEventUUID = () => {
87979
88109
  return crypto.randomUUID();
87980
88110
  };
87981
- const log$22 = globalLogger.createChild("EventStore");
88111
+ const log$23 = globalLogger.createChild("EventStore");
87982
88112
  const MAX_EVENT_SIZE_BYTES = 100 * 1024;
87983
88113
  /**
87984
88114
  * Concrete implementation of EventStore using Storage
@@ -88014,7 +88144,7 @@ var StorageEventStore = class {
88014
88144
  sizeBytes
88015
88145
  };
88016
88146
  await this.saveEvent(storedEvent);
88017
- log$22.info("Event stored", {
88147
+ log$23.info("Event stored", {
88018
88148
  eventId: storedEvent.id,
88019
88149
  eventType,
88020
88150
  sizeBytes,
@@ -88042,11 +88172,11 @@ var StorageEventStore = class {
88042
88172
  const allEvents = await this.getAllEventsFromStorage();
88043
88173
  const event = allEvents[eventId];
88044
88174
  if (!event) {
88045
- log$22.warn("Cannot lock non-existent event", { eventId });
88175
+ log$23.warn("Cannot lock non-existent event", { eventId });
88046
88176
  return;
88047
88177
  }
88048
88178
  if (event.status !== "new") {
88049
- log$22.debug("Cannot lock event - not in new status", {
88179
+ log$23.debug("Cannot lock event - not in new status", {
88050
88180
  eventId,
88051
88181
  status: event.status,
88052
88182
  lockedBy: event.lockedBy
@@ -88061,7 +88191,7 @@ var StorageEventStore = class {
88061
88191
  };
88062
88192
  allEvents[eventId] = updatedEvent;
88063
88193
  await this.storage.set(this.storageKey, allEvents);
88064
- log$22.debug("Event lock acquired", {
88194
+ log$23.debug("Event lock acquired", {
88065
88195
  eventId,
88066
88196
  walletAddress: walletId
88067
88197
  });
@@ -88088,7 +88218,7 @@ var StorageEventStore = class {
88088
88218
  };
88089
88219
  allEvents[eventId] = updatedEvent;
88090
88220
  await this.storage.set(this.storageKey, allEvents);
88091
- log$22.debug("Event retry count incremented", {
88221
+ log$23.debug("Event retry count incremented", {
88092
88222
  eventId,
88093
88223
  retryCount: updatedEvent.retryCount,
88094
88224
  error
@@ -88112,7 +88242,7 @@ var StorageEventStore = class {
88112
88242
  if (status === "completed") updatedEvent.completedAt = Date.now();
88113
88243
  allEvents[eventId] = updatedEvent;
88114
88244
  await this.storage.set(this.storageKey, allEvents);
88115
- log$22.debug("Event status updated", {
88245
+ log$23.debug("Event status updated", {
88116
88246
  eventId,
88117
88247
  oldStatus,
88118
88248
  newStatus: status
@@ -88127,7 +88257,7 @@ var StorageEventStore = class {
88127
88257
  try {
88128
88258
  return (await this.getAllEventsFromStorage())[eventId] || null;
88129
88259
  } catch (error) {
88130
- log$22.warn("Failed to get event", {
88260
+ log$23.warn("Failed to get event", {
88131
88261
  eventId,
88132
88262
  error
88133
88263
  });
@@ -88149,14 +88279,14 @@ var StorageEventStore = class {
88149
88279
  };
88150
88280
  await this.saveEvent(recoveredEvent);
88151
88281
  recoveredCount++;
88152
- log$22.info("Recovered stale event", {
88282
+ log$23.info("Recovered stale event", {
88153
88283
  eventId: event.id,
88154
88284
  lockedBy: event.lockedBy,
88155
88285
  staleMinutes: Math.round((now - event.processingStartedAt) / 6e4),
88156
88286
  retryCount: event.retryCount || 0
88157
88287
  });
88158
88288
  }
88159
- if (recoveredCount > 0) log$22.info("Event recovery completed", { recoveredCount });
88289
+ if (recoveredCount > 0) log$23.info("Event recovery completed", { recoveredCount });
88160
88290
  return recoveredCount;
88161
88291
  }
88162
88292
  /**
@@ -88169,7 +88299,7 @@ var StorageEventStore = class {
88169
88299
  const eventsToRemove = [];
88170
88300
  for (const event of events) if (event.status === "completed" && event.completedAt && event.completedAt < cutoffTime || event.status === "errored" && event.createdAt < cutoffTime) {
88171
88301
  eventsToRemove.push(event.id);
88172
- log$22.debug("Marked event for cleanup", {
88302
+ log$23.debug("Marked event for cleanup", {
88173
88303
  eventId: event.id,
88174
88304
  status: event.status
88175
88305
  });
@@ -88183,7 +88313,7 @@ var StorageEventStore = class {
88183
88313
  }
88184
88314
  await this.storage.set(this.storageKey, allEvents);
88185
88315
  });
88186
- log$22.info("Event cleanup completed", { cleanedUpCount });
88316
+ log$23.info("Event cleanup completed", { cleanedUpCount });
88187
88317
  }
88188
88318
  return cleanedUpCount;
88189
88319
  }
@@ -88195,7 +88325,7 @@ var StorageEventStore = class {
88195
88325
  const allEvents = await this.getAllEventsFromStorage();
88196
88326
  return Object.values(allEvents);
88197
88327
  } catch (error) {
88198
- log$22.warn("Failed to get all events", { error });
88328
+ log$23.warn("Failed to get all events", { error });
88199
88329
  return [];
88200
88330
  }
88201
88331
  }
@@ -88217,7 +88347,7 @@ var StorageEventStore = class {
88217
88347
  try {
88218
88348
  return await this.storage.get(this.storageKey) || {};
88219
88349
  } catch (error) {
88220
- log$22.warn("Failed to get events from storage", { error });
88350
+ log$23.warn("Failed to get events from storage", { error });
88221
88351
  return {};
88222
88352
  }
88223
88353
  }
@@ -88256,7 +88386,7 @@ var StorageEventStore = class {
88256
88386
  * LICENSE file in the root directory of this source tree.
88257
88387
  *
88258
88388
  */
88259
- const log$21 = globalLogger.createChild("EventProcessor");
88389
+ const log$22 = globalLogger.createChild("EventProcessor");
88260
88390
  /**
88261
88391
  * Processes durable events for wallets based on their active sessions and enabled event types
88262
88392
  */
@@ -88291,14 +88421,14 @@ var StorageEventProcessor = class {
88291
88421
  */
88292
88422
  async startProcessing(walletId) {
88293
88423
  if (this.processorConfig.disableEvents) return;
88294
- if (walletId) if (this.registeredWallets.has(walletId)) log$21.debug("Processing already registered for wallet", { walletId });
88424
+ if (walletId) if (this.registeredWallets.has(walletId)) log$22.debug("Processing already registered for wallet", { walletId });
88295
88425
  else {
88296
88426
  this.registeredWallets.add(walletId);
88297
- log$21.info("Registered wallet for event processing", { walletId });
88427
+ log$22.info("Registered wallet for event processing", { walletId });
88298
88428
  }
88299
88429
  if (!this.isProcessing) {
88300
88430
  this.isProcessing = true;
88301
- log$21.info("Started global event processing loop");
88431
+ log$22.info("Started global event processing loop");
88302
88432
  this.processEventsLoop();
88303
88433
  } else this.triggerProcessing();
88304
88434
  }
@@ -88309,7 +88439,7 @@ var StorageEventProcessor = class {
88309
88439
  if (this.processorConfig.disableEvents) return;
88310
88440
  if (walletId) {
88311
88441
  this.registeredWallets.delete(walletId);
88312
- log$21.info("Unregistered wallet from event processing", { walletId });
88442
+ log$22.info("Unregistered wallet from event processing", { walletId });
88313
88443
  }
88314
88444
  if (this.registeredWallets.size === 0 && this.isProcessing && !walletId) {
88315
88445
  this.isProcessing = false;
@@ -88317,12 +88447,12 @@ var StorageEventProcessor = class {
88317
88447
  this.wakeUpResolver();
88318
88448
  this.wakeUpResolver = void 0;
88319
88449
  }
88320
- log$21.info("Stopped global event processing loop (no more wallets)");
88450
+ log$22.info("Stopped global event processing loop (no more wallets)");
88321
88451
  }
88322
88452
  }
88323
88453
  async clearRegisteredWallets() {
88324
88454
  this.registeredWallets.clear();
88325
- log$21.info("Cleared registered wallets from event processing");
88455
+ log$22.info("Cleared registered wallets from event processing");
88326
88456
  }
88327
88457
  /**
88328
88458
  * Process next available event from any source (wallet or no-wallet)
@@ -88352,7 +88482,7 @@ var StorageEventProcessor = class {
88352
88482
  const walletId = allSessions.find((s) => s.sessionId === eventToUse.sessionId)?.walletId || "no-wallet";
88353
88483
  return await this.processEvent(eventToUse, walletId);
88354
88484
  } catch (error) {
88355
- log$21.error("Error in processNextAvailableEvent", { error: error.message });
88485
+ log$22.error("Error in processNextAvailableEvent", { error: error.message });
88356
88486
  return false;
88357
88487
  }
88358
88488
  }
@@ -88362,9 +88492,9 @@ var StorageEventProcessor = class {
88362
88492
  async completeEvent(eventId) {
88363
88493
  try {
88364
88494
  await this.eventStore.updateEventStatus(eventId, "completed", "processing");
88365
- log$21.debug("Event marked as completed", { eventId });
88495
+ log$22.debug("Event marked as completed", { eventId });
88366
88496
  } catch (error) {
88367
- log$21.error("Failed to mark event as completed", {
88497
+ log$22.error("Failed to mark event as completed", {
88368
88498
  eventId,
88369
88499
  error: error.message
88370
88500
  });
@@ -88375,14 +88505,14 @@ var StorageEventProcessor = class {
88375
88505
  */
88376
88506
  startRecoveryLoop() {
88377
88507
  if (this.recoveryTimeoutId) {
88378
- log$21.debug("Recovery loop already running");
88508
+ log$22.debug("Recovery loop already running");
88379
88509
  return;
88380
88510
  }
88381
88511
  const recoveryLoop = async () => {
88382
88512
  try {
88383
88513
  if (await this.eventStore.recoverStaleEvents(this.config.processingTimeoutMs) > 0) this.triggerProcessing();
88384
88514
  } catch (error) {
88385
- log$21.error("Error in recovery loop", { error: error.message });
88515
+ log$22.error("Error in recovery loop", { error: error.message });
88386
88516
  }
88387
88517
  if (this.recoveryTimeoutId !== void 0) this.recoveryTimeoutId = setTimeout(recoveryLoop, this.config.recoveryIntervalMs);
88388
88518
  };
@@ -88390,13 +88520,13 @@ var StorageEventProcessor = class {
88390
88520
  try {
88391
88521
  await this.eventStore.cleanupOldEvents(this.config.retentionMs);
88392
88522
  } catch (error) {
88393
- log$21.error("Error in cleanup loop", { error: error.message });
88523
+ log$22.error("Error in cleanup loop", { error: error.message });
88394
88524
  }
88395
88525
  if (this.cleanupTimeoutId !== void 0) this.cleanupTimeoutId = setTimeout(cleanupLoop, this.config.cleanupIntervalMs);
88396
88526
  };
88397
88527
  this.recoveryTimeoutId = setTimeout(recoveryLoop, this.config.recoveryIntervalMs);
88398
88528
  this.cleanupTimeoutId = setTimeout(cleanupLoop, this.config.cleanupIntervalMs);
88399
- log$21.info("Recovery and cleanup loops started");
88529
+ log$22.info("Recovery and cleanup loops started");
88400
88530
  }
88401
88531
  /**
88402
88532
  * Stop the recovery process
@@ -88410,7 +88540,7 @@ var StorageEventProcessor = class {
88410
88540
  clearTimeout(this.cleanupTimeoutId);
88411
88541
  this.cleanupTimeoutId = void 0;
88412
88542
  }
88413
- log$21.info("Recovery and cleanup loops stopped");
88543
+ log$22.info("Recovery and cleanup loops stopped");
88414
88544
  }
88415
88545
  /**
88416
88546
  * Process a single event with retry logic
@@ -88418,7 +88548,7 @@ var StorageEventProcessor = class {
88418
88548
  */
88419
88549
  async processEvent(event, walletId) {
88420
88550
  if (!await this.eventStore.acquireLock(event.id, walletId)) {
88421
- log$21.debug("Failed to acquire lock on event", {
88551
+ log$22.debug("Failed to acquire lock on event", {
88422
88552
  eventId: event.id,
88423
88553
  walletId
88424
88554
  });
@@ -88426,7 +88556,7 @@ var StorageEventProcessor = class {
88426
88556
  }
88427
88557
  const retryCount = event.retryCount || 0;
88428
88558
  if (retryCount >= this.config.maxRetries) {
88429
- log$21.error("Event exceeded max retries, marking as errored", {
88559
+ log$22.error("Event exceeded max retries, marking as errored", {
88430
88560
  eventId: event.id,
88431
88561
  retryCount,
88432
88562
  maxRetries: this.config.maxRetries
@@ -88434,14 +88564,14 @@ var StorageEventProcessor = class {
88434
88564
  try {
88435
88565
  await this.eventStore.updateEventStatus(event.id, "errored", "processing");
88436
88566
  } catch (error) {
88437
- log$21.error("Failed to mark event as errored", {
88567
+ log$22.error("Failed to mark event as errored", {
88438
88568
  eventId: event.id,
88439
88569
  error: error.message
88440
88570
  });
88441
88571
  }
88442
88572
  return false;
88443
88573
  }
88444
- log$21.info("Processing event", {
88574
+ log$22.info("Processing event", {
88445
88575
  eventId: event.id,
88446
88576
  eventType: event.eventType,
88447
88577
  walletId,
@@ -88461,11 +88591,11 @@ var StorageEventProcessor = class {
88461
88591
  ...walletAddress ? { walletAddress } : {}
88462
88592
  });
88463
88593
  await this.eventStore.updateEventStatus(event.id, "completed", "processing");
88464
- log$21.info("Event processing completed", { eventId: event.id });
88594
+ log$22.info("Event processing completed", { eventId: event.id });
88465
88595
  return true;
88466
88596
  } catch (error) {
88467
88597
  const errorMessage = error.message ?? "Unknown error";
88468
- log$21.error("Error processing event", {
88598
+ log$22.error("Error processing event", {
88469
88599
  eventId: event.id,
88470
88600
  error: errorMessage,
88471
88601
  retryCount
@@ -88473,7 +88603,7 @@ var StorageEventProcessor = class {
88473
88603
  try {
88474
88604
  await this.eventStore.releaseLock(event.id, errorMessage);
88475
88605
  } catch (updateError) {
88476
- log$21.error("Failed to increment retry count", {
88606
+ log$22.error("Failed to increment retry count", {
88477
88607
  eventId: event.id,
88478
88608
  error: updateError.message
88479
88609
  });
@@ -88488,18 +88618,18 @@ var StorageEventProcessor = class {
88488
88618
  while (this.isProcessing) try {
88489
88619
  if (!await this.processNextAvailableEvent()) await this.waitForWakeUpOrTimeout(500);
88490
88620
  } catch (error) {
88491
- log$21.error("Error in global processing loop", { error: error.message });
88621
+ log$22.error("Error in global processing loop", { error: error.message });
88492
88622
  await this.waitForWakeUpOrTimeout(500);
88493
88623
  }
88494
88624
  this.wakeUpResolver = void 0;
88495
- log$21.debug("Global processing loop ended");
88625
+ log$22.debug("Global processing loop ended");
88496
88626
  }
88497
88627
  /**
88498
88628
  * Trigger the global processing loop
88499
88629
  */
88500
88630
  triggerProcessing() {
88501
88631
  if (this.isProcessing && this.wakeUpResolver) {
88502
- log$21.debug("Waking up global processing loop");
88632
+ log$22.debug("Waking up global processing loop");
88503
88633
  this.wakeUpResolver();
88504
88634
  }
88505
88635
  }
@@ -88542,7 +88672,7 @@ var StorageEventProcessor = class {
88542
88672
  * LICENSE file in the root directory of this source tree.
88543
88673
  *
88544
88674
  */
88545
- const log$20 = globalLogger.createChild("WalletTonClass");
88675
+ const log$21 = globalLogger.createChild("WalletTonClass");
88546
88676
  var WalletTonClass = class {
88547
88677
  async createTransferTonTransaction(param) {
88548
88678
  if (!isValidAddress(param.recipientAddress)) throw new Error(`Invalid to address: ${param.recipientAddress}`);
@@ -88603,7 +88733,7 @@ var WalletTonClass = class {
88603
88733
  normalizedHash
88604
88734
  };
88605
88735
  } catch (error) {
88606
- log$20.error("Failed to send transaction", { error });
88736
+ log$21.error("Failed to send transaction", { error });
88607
88737
  if (error instanceof WalletKitError) throw error;
88608
88738
  if (error?.message?.includes("Ledger device")) throw new WalletKitError(ERROR_CODES.LEDGER_DEVICE_ERROR, "Ledger device error", error);
88609
88739
  throw error;
@@ -88633,7 +88763,7 @@ var WalletJettonClass = class {
88633
88763
  payload: createJettonTransferPayload({
88634
88764
  amount: BigInt(params.transferAmount),
88635
88765
  destination: params.recipientAddress,
88636
- responseDestination: this.getAddress(),
88766
+ responseDestination: params.responseDestination || this.getAddress(),
88637
88767
  comment: params.comment
88638
88768
  }),
88639
88769
  fromAddress: this.getAddress()
@@ -88705,7 +88835,7 @@ var WalletNftClass = class {
88705
88835
  * LICENSE file in the root directory of this source tree.
88706
88836
  *
88707
88837
  */
88708
- const log$19 = globalLogger.createChild("Initializer");
88838
+ const log$20 = globalLogger.createChild("Initializer");
88709
88839
  /**
88710
88840
  * Handles initialization of all TonWalletKit components
88711
88841
  */
@@ -88724,12 +88854,12 @@ var Initializer = class {
88724
88854
  */
88725
88855
  async initialize(options, networkManager) {
88726
88856
  try {
88727
- log$19.info("Initializing TonWalletKit...");
88857
+ log$20.info("Initializing TonWalletKit...");
88728
88858
  this.networkManager = networkManager;
88729
88859
  const storage = this.initializeStorage(options);
88730
88860
  const { walletManager, sessionManager, bridgeManager, eventRouter, eventProcessor } = await this.initializeManagers(options, storage);
88731
88861
  const { requestProcessor } = this.initializeProcessors(sessionManager, bridgeManager, walletManager);
88732
- log$19.info("TonWalletKit initialized successfully");
88862
+ log$20.info("TonWalletKit initialized successfully");
88733
88863
  return {
88734
88864
  walletManager,
88735
88865
  sessionManager,
@@ -88740,7 +88870,7 @@ var Initializer = class {
88740
88870
  eventProcessor
88741
88871
  };
88742
88872
  } catch (error) {
88743
- log$19.error("Failed to initialize TonWalletKit", { error });
88873
+ log$20.error("Failed to initialize TonWalletKit", { error });
88744
88874
  throw error;
88745
88875
  }
88746
88876
  }
@@ -88776,9 +88906,9 @@ var Initializer = class {
88776
88906
  const bridgeManager = new BridgeManager(options?.walletManifest, options?.bridge, sessionManager, storage, eventStore, eventRouter, options, this.eventEmitter, this.analyticsManager);
88777
88907
  eventRouter.setBridgeManager(bridgeManager);
88778
88908
  bridgeManager.start().then(() => {
88779
- log$19.info("Bridge manager started successfully");
88909
+ log$20.info("Bridge manager started successfully");
88780
88910
  }).catch((e) => {
88781
- log$19.error("Could not start bridge manager", { error: e?.toString?.() });
88911
+ log$20.error("Could not start bridge manager", { error: e?.toString?.() });
88782
88912
  });
88783
88913
  const eventProcessor = new StorageEventProcessor(options?.eventProcessor, eventStore, DEFAULT_DURABLE_EVENTS_CONFIG, walletManager, sessionManager, eventRouter, this.eventEmitter);
88784
88914
  return {
@@ -88800,7 +88930,7 @@ var Initializer = class {
88800
88930
  */
88801
88931
  async cleanup(components) {
88802
88932
  try {
88803
- log$19.info("Cleaning up TonWalletKit components...");
88933
+ log$20.info("Cleaning up TonWalletKit components...");
88804
88934
  if (components.eventProcessor) {
88805
88935
  components.eventProcessor.stopRecoveryLoop();
88806
88936
  await components.eventProcessor.clearRegisteredWallets();
@@ -88808,9 +88938,9 @@ var Initializer = class {
88808
88938
  }
88809
88939
  if (components.bridgeManager) await components.bridgeManager.close();
88810
88940
  if (components.eventRouter) components.eventRouter.clearCallbacks();
88811
- log$19.info("TonWalletKit cleanup completed");
88941
+ log$20.info("TonWalletKit cleanup completed");
88812
88942
  } catch (error) {
88813
- log$19.error("Error during cleanup", { error });
88943
+ log$20.error("Error during cleanup", { error });
88814
88944
  }
88815
88945
  }
88816
88946
  };
@@ -88845,7 +88975,7 @@ async function wrapWalletInterface(wallet) {
88845
88975
  * LICENSE file in the root directory of this source tree.
88846
88976
  *
88847
88977
  */
88848
- const log$18 = globalLogger.createChild("JettonsManager");
88978
+ const log$19 = globalLogger.createChild("JettonsManager");
88849
88979
  const TON_ADDRESS = "TON";
88850
88980
  function isTonAddress(address) {
88851
88981
  return address.toLowerCase() === "ton";
@@ -88885,7 +89015,7 @@ var JettonsManager = class {
88885
89015
  ttl: 1e3 * 60 * 10
88886
89016
  });
88887
89017
  for (const network of this.networkManager.getConfiguredNetworks()) this.addTonToCache(network);
88888
- log$18.info("JettonsManager initialized", { cacheSize });
89018
+ log$19.info("JettonsManager initialized", { cacheSize });
88889
89019
  }
88890
89020
  /**
88891
89021
  * Add TON native token to cache for a specific network
@@ -88906,19 +89036,19 @@ var JettonsManager = class {
88906
89036
  const cacheKey = this.normalizedCacheKey(targetNetwork, jettonAddress);
88907
89037
  const cachedInfo = this.cache.get(cacheKey);
88908
89038
  if (cachedInfo) {
88909
- log$18.debug("Jetton info found in cache", {
89039
+ log$19.debug("Jetton info found in cache", {
88910
89040
  jettonAddress,
88911
89041
  network: targetNetwork
88912
89042
  });
88913
89043
  return cachedInfo;
88914
89044
  }
88915
- log$18.debug("Jetton info not found in cache", {
89045
+ log$19.debug("Jetton info not found in cache", {
88916
89046
  jettonAddress,
88917
89047
  network: targetNetwork
88918
89048
  });
88919
89049
  const address = asMaybeAddressFriendly(jettonAddress);
88920
89050
  if (!address) {
88921
- log$18.error("Invalid jetton address format", {
89051
+ log$19.error("Invalid jetton address format", {
88922
89052
  jettonAddress,
88923
89053
  network: targetNetwork
88924
89054
  });
@@ -88953,7 +89083,7 @@ var JettonsManager = class {
88953
89083
  }
88954
89084
  return null;
88955
89085
  } catch (error) {
88956
- log$18.error("Error getting jetton info", {
89086
+ log$19.error("Error getting jetton info", {
88957
89087
  error,
88958
89088
  jettonAddress,
88959
89089
  network: targetNetwork
@@ -88972,7 +89102,7 @@ var JettonsManager = class {
88972
89102
  const targetNetwork = network;
88973
89103
  try {
88974
89104
  const apiClient = this.networkManager.getClient(targetNetwork);
88975
- log$18.debug("Getting address jettons", {
89105
+ log$19.debug("Getting address jettons", {
88976
89106
  userAddress,
88977
89107
  network: targetNetwork,
88978
89108
  offset,
@@ -88986,13 +89116,13 @@ var JettonsManager = class {
88986
89116
  if (!response.jettons) return [];
88987
89117
  const addressJettons = [];
88988
89118
  for (const item of response.jettons) addressJettons.push(item);
88989
- log$18.debug("Retrieved address jettons", {
89119
+ log$19.debug("Retrieved address jettons", {
88990
89120
  count: addressJettons.length,
88991
89121
  network: targetNetwork
88992
89122
  });
88993
89123
  return addressJettons;
88994
89124
  } catch (error) {
88995
- log$18.error("Failed to get address jettons", {
89125
+ log$19.error("Failed to get address jettons", {
88996
89126
  error,
88997
89127
  userAddress,
88998
89128
  network: targetNetwork
@@ -89016,14 +89146,14 @@ var JettonsManager = class {
89016
89146
  uri: emulationInfo.extra.uri
89017
89147
  };
89018
89148
  this.cache.set(cacheKey, jettonInfo);
89019
- log$18.debug("Added jetton info from emulation to cache", {
89149
+ log$19.debug("Added jetton info from emulation to cache", {
89020
89150
  jettonAddress,
89021
89151
  network,
89022
89152
  name: jettonInfo.name,
89023
89153
  symbol: jettonInfo.symbol
89024
89154
  });
89025
89155
  } catch (error) {
89026
- log$18.error("Error adding jetton from emulation", {
89156
+ log$19.error("Error adding jetton from emulation", {
89027
89157
  error,
89028
89158
  jettonAddress,
89029
89159
  network
@@ -89040,7 +89170,7 @@ var JettonsManager = class {
89040
89170
  if (!addressMetadata.is_indexed || !addressMetadata.token_info) continue;
89041
89171
  const jettonMasterInfo = addressMetadata.token_info.find((info) => typeof info === "object" && info !== null && "type" in info && info.type === "jetton_masters");
89042
89172
  if (jettonMasterInfo) {
89043
- log$18.debug("Adding jetton from emulation metadata", {
89173
+ log$19.debug("Adding jetton from emulation metadata", {
89044
89174
  jettonAddress,
89045
89175
  network
89046
89176
  });
@@ -89048,12 +89178,12 @@ var JettonsManager = class {
89048
89178
  addedCount++;
89049
89179
  }
89050
89180
  }
89051
- if (addedCount > 0) log$18.info("Added jettons from emulation metadata", {
89181
+ if (addedCount > 0) log$19.info("Added jettons from emulation metadata", {
89052
89182
  addedCount,
89053
89183
  network
89054
89184
  });
89055
89185
  } catch (error) {
89056
- log$18.error("Error adding jettons from emulation metadata", {
89186
+ log$19.error("Error adding jettons from emulation metadata", {
89057
89187
  error,
89058
89188
  network
89059
89189
  });
@@ -89094,11 +89224,11 @@ var JettonsManager = class {
89094
89224
  if (network) {
89095
89225
  for (const key of this.cache.keys()) if (key.startsWith(`${network.chainId}:`)) this.cache.delete(key);
89096
89226
  this.addTonToCache(network);
89097
- log$18.info("Jetton cache cleared for network", { network });
89227
+ log$19.info("Jetton cache cleared for network", { network });
89098
89228
  } else {
89099
89229
  this.cache.clear();
89100
89230
  for (const net of this.networkManager.getConfiguredNetworks()) this.addTonToCache(net);
89101
- log$18.info("Jetton cache cleared for all networks");
89231
+ log$19.info("Jetton cache cleared for all networks");
89102
89232
  }
89103
89233
  }
89104
89234
  };
@@ -89298,7 +89428,7 @@ var DefiManager = class {
89298
89428
  * LICENSE file in the root directory of this source tree.
89299
89429
  *
89300
89430
  */
89301
- const log$17 = globalLogger.createChild("SwapManager");
89431
+ const log$18 = globalLogger.createChild("SwapManager");
89302
89432
  /**
89303
89433
  * SwapManager - manages swap providers and delegates swap operations
89304
89434
  *
@@ -89316,7 +89446,7 @@ var SwapManager = class extends DefiManager {
89316
89446
  * @returns Promise resolving to swap quote
89317
89447
  */
89318
89448
  async getQuote(params, providerId) {
89319
- log$17.debug("Getting swap quote", {
89449
+ log$18.debug("Getting swap quote", {
89320
89450
  fromToken: params.from,
89321
89451
  toToken: params.to,
89322
89452
  amount: params.amount,
@@ -89325,14 +89455,14 @@ var SwapManager = class extends DefiManager {
89325
89455
  });
89326
89456
  try {
89327
89457
  const quote = await this.getProvider(providerId || this.defaultProviderId).getQuote(params);
89328
- log$17.debug("Received swap quote", {
89458
+ log$18.debug("Received swap quote", {
89329
89459
  fromAmount: quote.fromAmount,
89330
89460
  toAmount: quote.toAmount,
89331
89461
  priceImpact: quote.priceImpact
89332
89462
  });
89333
89463
  return quote;
89334
89464
  } catch (error) {
89335
- log$17.error("Failed to get swap quote", {
89465
+ log$18.error("Failed to get swap quote", {
89336
89466
  error,
89337
89467
  params
89338
89468
  });
@@ -89346,16 +89476,16 @@ var SwapManager = class extends DefiManager {
89346
89476
  */
89347
89477
  async buildSwapTransaction(params) {
89348
89478
  const providerId = params.quote.providerId || this.defaultProviderId;
89349
- log$17.debug("Building swap transaction", {
89479
+ log$18.debug("Building swap transaction", {
89350
89480
  providerId,
89351
89481
  userAddress: params.userAddress
89352
89482
  });
89353
89483
  try {
89354
89484
  const transaction = await this.getProvider(providerId).buildSwapTransaction(params);
89355
- log$17.debug("Built swap transaction", params.quote);
89485
+ log$18.debug("Built swap transaction", params.quote);
89356
89486
  return transaction;
89357
89487
  } catch (error) {
89358
- log$17.error("Failed to build swap transaction", {
89488
+ log$18.error("Failed to build swap transaction", {
89359
89489
  error,
89360
89490
  params
89361
89491
  });
@@ -89397,7 +89527,7 @@ var StakingError = class extends DefiError {
89397
89527
  * LICENSE file in the root directory of this source tree.
89398
89528
  *
89399
89529
  */
89400
- const log$16 = globalLogger.createChild("StakingManager");
89530
+ const log$17 = globalLogger.createChild("StakingManager");
89401
89531
  /**
89402
89532
  * StakingManager - manages staking providers and delegates staking operations
89403
89533
  *
@@ -89414,13 +89544,13 @@ var StakingManager = class extends DefiManager {
89414
89544
  * @param providerId - Optional provider id to use
89415
89545
  */
89416
89546
  async getQuote(params, providerId) {
89417
- log$16.debug("Getting staking quote", params);
89547
+ log$17.debug("Getting staking quote", params);
89418
89548
  try {
89419
89549
  const quote = await this.getProvider(providerId).getQuote(params);
89420
- log$16.debug("Received staking quote", quote);
89550
+ log$17.debug("Received staking quote", quote);
89421
89551
  return quote;
89422
89552
  } catch (error) {
89423
- log$16.error("Failed to get staking quote", {
89553
+ log$17.error("Failed to get staking quote", {
89424
89554
  error,
89425
89555
  params
89426
89556
  });
@@ -89433,11 +89563,11 @@ var StakingManager = class extends DefiManager {
89433
89563
  * @param providerId - Optional provider id to use
89434
89564
  */
89435
89565
  async buildStakeTransaction(params, providerId) {
89436
- log$16.debug("Building staking transaction", params);
89566
+ log$17.debug("Building staking transaction", params);
89437
89567
  try {
89438
89568
  return await this.getProvider(providerId).buildStakeTransaction(params);
89439
89569
  } catch (error) {
89440
- log$16.error("Failed to build staking transaction", {
89570
+ log$17.error("Failed to build staking transaction", {
89441
89571
  error,
89442
89572
  params
89443
89573
  });
@@ -89451,7 +89581,7 @@ var StakingManager = class extends DefiManager {
89451
89581
  * @param providerId - Optional provider id to use
89452
89582
  */
89453
89583
  async getStakedBalance(userAddress, network, providerId) {
89454
- log$16.debug("Getting staking balance", {
89584
+ log$17.debug("Getting staking balance", {
89455
89585
  userAddress,
89456
89586
  network,
89457
89587
  provider: providerId || this.defaultProviderId
@@ -89459,7 +89589,7 @@ var StakingManager = class extends DefiManager {
89459
89589
  try {
89460
89590
  return await this.getProvider(providerId).getStakedBalance(userAddress, network);
89461
89591
  } catch (error) {
89462
- log$16.error("Failed to get staking balance", {
89592
+ log$17.error("Failed to get staking balance", {
89463
89593
  error,
89464
89594
  userAddress,
89465
89595
  network
@@ -89473,14 +89603,14 @@ var StakingManager = class extends DefiManager {
89473
89603
  * @param providerId - Optional provider id to use
89474
89604
  */
89475
89605
  async getStakingProviderInfo(network, providerId) {
89476
- log$16.debug("Getting staking info", {
89606
+ log$17.debug("Getting staking info", {
89477
89607
  network,
89478
89608
  provider: providerId || this.defaultProviderId
89479
89609
  });
89480
89610
  try {
89481
89611
  return await this.getProvider(providerId).getStakingProviderInfo(network);
89482
89612
  } catch (error) {
89483
- log$16.error("Failed to get staking info", {
89613
+ log$17.error("Failed to get staking info", {
89484
89614
  error,
89485
89615
  network
89486
89616
  });
@@ -89493,14 +89623,14 @@ var StakingManager = class extends DefiManager {
89493
89623
  * @param providerId - Optional provider id to use
89494
89624
  */
89495
89625
  getStakingProviderMetadata(network, providerId) {
89496
- log$16.debug("Getting staking metadata", {
89626
+ log$17.debug("Getting staking metadata", {
89497
89627
  network,
89498
89628
  provider: providerId || this.defaultProviderId
89499
89629
  });
89500
89630
  try {
89501
89631
  return this.getProvider(providerId).getStakingProviderMetadata(network);
89502
89632
  } catch (error) {
89503
- log$16.error("Failed to get staking metadata", {
89633
+ log$17.error("Failed to get staking metadata", {
89504
89634
  error,
89505
89635
  network
89506
89636
  });
@@ -89509,7 +89639,7 @@ var StakingManager = class extends DefiManager {
89509
89639
  }
89510
89640
  createError(message, code, details) {
89511
89641
  const errorCode = Object.values(StakingErrorCode).includes(code) ? code : StakingErrorCode.InvalidParams;
89512
- log$16.error(message, {
89642
+ log$17.error(message, {
89513
89643
  code,
89514
89644
  details
89515
89645
  });
@@ -89517,6 +89647,128 @@ var StakingManager = class extends DefiManager {
89517
89647
  }
89518
89648
  };
89519
89649
  //#endregion
89650
+ //#region ../walletkit/dist/esm/defi/gasless/errors.js
89651
+ /**
89652
+ * Copyright (c) TonTech.
89653
+ *
89654
+ * This source code is licensed under the MIT license found in the
89655
+ * LICENSE file in the root directory of this source tree.
89656
+ *
89657
+ */
89658
+ var GaslessErrorCode;
89659
+ (function(GaslessErrorCode) {
89660
+ GaslessErrorCode["UnsupportedFeeAsset"] = "UNSUPPORTED_FEE_ASSET";
89661
+ GaslessErrorCode["UnsupportedOperation"] = "UNSUPPORTED_OPERATION";
89662
+ GaslessErrorCode["QuoteFailed"] = "QUOTE_FAILED";
89663
+ GaslessErrorCode["SendFailed"] = "SEND_FAILED";
89664
+ GaslessErrorCode["ConfigFailed"] = "CONFIG_FAILED";
89665
+ GaslessErrorCode["SignMessageNotSupported"] = "SIGN_MESSAGE_NOT_SUPPORTED";
89666
+ GaslessErrorCode["TooManyMessages"] = "TOO_MANY_MESSAGES";
89667
+ GaslessErrorCode["QuoteExpired"] = "QUOTE_EXPIRED";
89668
+ GaslessErrorCode["WalletMismatch"] = "WALLET_MISMATCH";
89669
+ GaslessErrorCode["FeeAssetNotOwned"] = "FEE_ASSET_NOT_OWNED";
89670
+ })(GaslessErrorCode || (GaslessErrorCode = {}));
89671
+ var GaslessError = class extends DefiError {
89672
+ code;
89673
+ constructor(message, code, details) {
89674
+ super(message, code, details);
89675
+ this.name = "GaslessError";
89676
+ this.code = code;
89677
+ }
89678
+ };
89679
+ //#endregion
89680
+ //#region ../walletkit/dist/esm/defi/gasless/GaslessManager.js
89681
+ /**
89682
+ * Copyright (c) TonTech.
89683
+ *
89684
+ * This source code is licensed under the MIT license found in the
89685
+ * LICENSE file in the root directory of this source tree.
89686
+ *
89687
+ */
89688
+ const log$16 = globalLogger.createChild("GaslessManager");
89689
+ /**
89690
+ * GaslessManager — manages gasless relay providers and delegates gasless operations.
89691
+ *
89692
+ * Allows registration of multiple gasless providers and provides a unified API.
89693
+ * Providers can be switched dynamically.
89694
+ */
89695
+ var GaslessManager = class extends DefiManager {
89696
+ constructor(createFactoryContext) {
89697
+ super(createFactoryContext);
89698
+ }
89699
+ /**
89700
+ * Get static metadata for a gasless provider (display name, logo, url).
89701
+ */
89702
+ async getMetadata(providerId) {
89703
+ const selectedProviderId = providerId ?? this.defaultProviderId;
89704
+ log$16.debug("Getting gasless provider metadata", { providerId: selectedProviderId });
89705
+ try {
89706
+ return await this.getProvider(selectedProviderId).getMetadata();
89707
+ } catch (error) {
89708
+ log$16.error("Failed to get gasless provider metadata", { error });
89709
+ throw error;
89710
+ }
89711
+ }
89712
+ /**
89713
+ * Fetch the relayer's configuration (relay address + accepted fee assets).
89714
+ *
89715
+ * `network` defaults to the provider's first supported network.
89716
+ */
89717
+ async getConfig(network, providerId) {
89718
+ const provider = this.getProvider(providerId ?? this.defaultProviderId);
89719
+ const targetNetwork = network ?? provider.getSupportedNetworks()[0];
89720
+ log$16.debug("Getting gasless config", {
89721
+ network: targetNetwork?.chainId,
89722
+ providerId: providerId ?? this.defaultProviderId
89723
+ });
89724
+ try {
89725
+ return await provider.getConfig(targetNetwork);
89726
+ } catch (error) {
89727
+ log$16.error("Failed to get gasless config", { error });
89728
+ throw error;
89729
+ }
89730
+ }
89731
+ /**
89732
+ * Quote fees and obtain relayer-wrapped messages for signing.
89733
+ */
89734
+ async getQuote(params, providerId) {
89735
+ log$16.debug("Quoting gasless transaction", {
89736
+ network: params.network.chainId,
89737
+ walletAddress: params.walletAddress,
89738
+ feeAsset: params.feeAsset,
89739
+ messagesCount: params.messages.length,
89740
+ providerId: providerId ?? this.defaultProviderId
89741
+ });
89742
+ try {
89743
+ return await this.getProvider(providerId ?? this.defaultProviderId).getQuote(params);
89744
+ } catch (error) {
89745
+ log$16.error("Failed to quote gasless transaction", {
89746
+ error,
89747
+ params
89748
+ });
89749
+ throw error;
89750
+ }
89751
+ }
89752
+ /**
89753
+ * Submit a signed transaction BoC to the relayer.
89754
+ */
89755
+ async sendTransaction(params, providerId) {
89756
+ log$16.debug("Sending gasless transaction", {
89757
+ network: params.network.chainId,
89758
+ providerId: providerId ?? this.defaultProviderId
89759
+ });
89760
+ try {
89761
+ return await this.getProvider(providerId ?? this.defaultProviderId).sendTransaction(params);
89762
+ } catch (error) {
89763
+ log$16.error("Failed to send gasless transaction", { error });
89764
+ throw error;
89765
+ }
89766
+ }
89767
+ createError(message, code, details) {
89768
+ return new GaslessError(message, code, details);
89769
+ }
89770
+ };
89771
+ //#endregion
89520
89772
  //#region ../walletkit/dist/esm/core/EventEmitter.js
89521
89773
  /**
89522
89774
  * Copyright (c) TonTech.
@@ -91308,6 +91560,7 @@ var TonWalletKit = class {
91308
91560
  swapManager;
91309
91561
  streamingManager;
91310
91562
  stakingManager;
91563
+ gaslessManager;
91311
91564
  initializer;
91312
91565
  eventProcessor;
91313
91566
  bridgeManager;
@@ -91334,6 +91587,7 @@ var TonWalletKit = class {
91334
91587
  this.jettonsManager = new JettonsManager(1e4, this.eventEmitter, this.networkManager);
91335
91588
  this.swapManager = new SwapManager(() => this.createFactoryContext());
91336
91589
  this.stakingManager = new StakingManager(() => this.createFactoryContext());
91590
+ this.gaslessManager = new GaslessManager(() => this.createFactoryContext());
91337
91591
  this.eventEmitter.on("restoreConnection", async ({ payload: event }) => {
91338
91592
  if (!event.domain) {
91339
91593
  log$9.error("Domain is required for restore connection");
@@ -91820,6 +92074,9 @@ var TonWalletKit = class {
91820
92074
  case "streaming":
91821
92075
  this.streamingManager.registerProvider(provider);
91822
92076
  break;
92077
+ case "gasless":
92078
+ this.gaslessManager.registerProvider(provider);
92079
+ break;
91823
92080
  default: throw new Error("Unknown provider type");
91824
92081
  }
91825
92082
  }
@@ -91854,6 +92111,12 @@ var TonWalletKit = class {
91854
92111
  return this.stakingManager;
91855
92112
  }
91856
92113
  /**
92114
+ * Gasless API access
92115
+ */
92116
+ get gasless() {
92117
+ return this.gaslessManager;
92118
+ }
92119
+ /**
91857
92120
  * Get the event emitter for this kit instance
91858
92121
  * Allows external components to listen to and emit events
91859
92122
  */