@txnlab/use-wallet 3.4.0 → 3.5.0

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/index.cjs CHANGED
@@ -3238,6 +3238,7 @@ __export(src_exports, {
3238
3238
  KibisisWallet: () => KibisisWallet,
3239
3239
  KmdWallet: () => KmdWallet,
3240
3240
  LOCAL_STORAGE_MNEMONIC_KEY: () => LOCAL_STORAGE_MNEMONIC_KEY,
3241
+ LogLevel: () => LogLevel,
3241
3242
  MagicAuth: () => MagicAuth,
3242
3243
  MnemonicWallet: () => MnemonicWallet,
3243
3244
  NetworkId: () => NetworkId,
@@ -3253,6 +3254,75 @@ __export(src_exports, {
3253
3254
  });
3254
3255
  module.exports = __toCommonJS(src_exports);
3255
3256
 
3257
+ // src/logger.ts
3258
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
3259
+ LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
3260
+ LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
3261
+ LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
3262
+ LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
3263
+ return LogLevel2;
3264
+ })(LogLevel || {});
3265
+ var Logger = class _Logger {
3266
+ static instance = null;
3267
+ level;
3268
+ isClient;
3269
+ constructor() {
3270
+ this.level = 2 /* WARN */;
3271
+ this.isClient = typeof window !== "undefined";
3272
+ }
3273
+ static getInstance() {
3274
+ if (!_Logger.instance) {
3275
+ _Logger.instance = new _Logger();
3276
+ }
3277
+ return _Logger.instance;
3278
+ }
3279
+ static setLevel(level) {
3280
+ _Logger.getInstance().level = level;
3281
+ }
3282
+ log(level, scope, message, ...args) {
3283
+ if (level >= this.level && this.isClient) {
3284
+ const formattedMessage = scope ? `[${scope}] ${message}` : message;
3285
+ switch (level) {
3286
+ case 0 /* DEBUG */:
3287
+ case 1 /* INFO */:
3288
+ console.info(formattedMessage, ...args);
3289
+ break;
3290
+ case 2 /* WARN */:
3291
+ console.warn(formattedMessage, ...args);
3292
+ break;
3293
+ case 3 /* ERROR */:
3294
+ console.error(formattedMessage, ...args);
3295
+ break;
3296
+ }
3297
+ }
3298
+ }
3299
+ createScopedLogger(scope) {
3300
+ return {
3301
+ debug: (message, ...args) => this.log(0 /* DEBUG */, scope, message, ...args),
3302
+ info: (message, ...args) => this.log(1 /* INFO */, scope, message, ...args),
3303
+ warn: (message, ...args) => this.log(2 /* WARN */, scope, message, ...args),
3304
+ error: (message, ...args) => this.log(3 /* ERROR */, scope, message, ...args)
3305
+ };
3306
+ }
3307
+ debug(message, ...args) {
3308
+ this.log(0 /* DEBUG */, void 0, message, ...args);
3309
+ }
3310
+ info(message, ...args) {
3311
+ this.log(1 /* INFO */, void 0, message, ...args);
3312
+ }
3313
+ warn(message, ...args) {
3314
+ this.log(2 /* WARN */, void 0, message, ...args);
3315
+ }
3316
+ error(message, ...args) {
3317
+ this.log(3 /* ERROR */, void 0, message, ...args);
3318
+ }
3319
+ // For testing purposes
3320
+ setIsClient(isClient) {
3321
+ this.isClient = isClient;
3322
+ }
3323
+ };
3324
+ var logger = Logger.getInstance();
3325
+
3256
3326
  // src/manager.ts
3257
3327
  var import_store13 = require("@tanstack/store");
3258
3328
  var import_algosdk12 = __toESM(require("algosdk"), 1);
@@ -3330,6 +3400,7 @@ var BaseWallet = class {
3330
3400
  store;
3331
3401
  getAlgodClient;
3332
3402
  subscribe;
3403
+ logger;
3333
3404
  constructor({
3334
3405
  id,
3335
3406
  metadata,
@@ -3343,14 +3414,15 @@ var BaseWallet = class {
3343
3414
  this.getAlgodClient = getAlgodClient;
3344
3415
  const ctor = this.constructor;
3345
3416
  this.metadata = { ...ctor.defaultMetadata, ...metadata };
3417
+ this.logger = logger.createScopedLogger(`Wallet:${this.id.toUpperCase()}`);
3346
3418
  }
3347
3419
  static defaultMetadata = { name: "Base Wallet", icon: "" };
3348
3420
  setActive = () => {
3349
- console.info(`[Wallet] Set active wallet: ${this.id}`);
3421
+ this.logger.info(`Set active wallet: ${this.id}`);
3350
3422
  setActiveWallet(this.store, { walletId: this.id });
3351
3423
  };
3352
3424
  setActiveAccount = (account) => {
3353
- console.info(`[Wallet] Set active account: ${account}`);
3425
+ this.logger.info(`Set active account: ${account}`);
3354
3426
  setActiveAccount(this.store, {
3355
3427
  walletId: this.id,
3356
3428
  address: account
@@ -3461,19 +3533,21 @@ var DeflyWallet = class extends BaseWallet {
3461
3533
  icon: ICON
3462
3534
  };
3463
3535
  async initializeClient() {
3464
- console.info(`[${this.metadata.name}] Initializing client...`);
3536
+ this.logger.info("Initializing client...");
3465
3537
  const module2 = await import("@blockshake/defly-connect");
3466
3538
  const DeflyWalletConnect = module2.default ? module2.default.DeflyWalletConnect : module2.DeflyWalletConnect;
3467
3539
  const client = new DeflyWalletConnect(this.options);
3468
3540
  client.connector?.on("disconnect", this.onDisconnect);
3469
3541
  this.client = client;
3542
+ this.logger.info("Client initialized");
3470
3543
  return client;
3471
3544
  }
3472
3545
  connect = async () => {
3473
- console.info(`[${this.metadata.name}] Connecting...`);
3546
+ this.logger.info("Connecting...");
3474
3547
  const client = this.client || await this.initializeClient();
3475
3548
  const accounts = await client.connect();
3476
3549
  if (accounts.length === 0) {
3550
+ this.logger.error("No accounts found!");
3477
3551
  throw new Error("No accounts found!");
3478
3552
  }
3479
3553
  const walletAccounts = accounts.map((address, idx) => ({
@@ -3489,27 +3563,29 @@ var DeflyWallet = class extends BaseWallet {
3489
3563
  walletId: this.id,
3490
3564
  wallet: walletState
3491
3565
  });
3492
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
3566
+ this.logger.info("\u2705 Connected.", walletState);
3493
3567
  return walletAccounts;
3494
3568
  };
3495
3569
  disconnect = async () => {
3496
- console.info(`[${this.metadata.name}] Disconnecting...`);
3570
+ this.logger.info("Disconnecting...");
3497
3571
  this.onDisconnect();
3498
3572
  const client = this.client || await this.initializeClient();
3499
3573
  await client.disconnect();
3500
- console.info(`[${this.metadata.name}] Disconnected.`);
3574
+ this.logger.info("Disconnected.");
3501
3575
  };
3502
3576
  resumeSession = async () => {
3503
3577
  try {
3504
3578
  const state = this.store.state;
3505
3579
  const walletState = state.wallets[this.id];
3506
3580
  if (!walletState) {
3581
+ this.logger.info("No session to resume");
3507
3582
  return;
3508
3583
  }
3509
- console.info(`[${this.metadata.name}] Resuming session...`);
3584
+ this.logger.info("Resuming session...");
3510
3585
  const client = this.client || await this.initializeClient();
3511
3586
  const accounts = await client.reconnectSession();
3512
3587
  if (accounts.length === 0) {
3588
+ this.logger.error("No accounts found!");
3513
3589
  throw new Error("No accounts found!");
3514
3590
  }
3515
3591
  const walletAccounts = accounts.map((address, idx) => ({
@@ -3518,7 +3594,7 @@ var DeflyWallet = class extends BaseWallet {
3518
3594
  }));
3519
3595
  const match = compareAccounts(walletAccounts, walletState.accounts);
3520
3596
  if (!match) {
3521
- console.warn(`[${this.metadata.name}] Session accounts mismatch, updating accounts`, {
3597
+ this.logger.warn("Session accounts mismatch, updating accounts", {
3522
3598
  prev: walletState.accounts,
3523
3599
  current: walletAccounts
3524
3600
  });
@@ -3527,8 +3603,9 @@ var DeflyWallet = class extends BaseWallet {
3527
3603
  accounts: walletAccounts
3528
3604
  });
3529
3605
  }
3606
+ this.logger.info("Session resumed");
3530
3607
  } catch (error) {
3531
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
3608
+ this.logger.error("Error resuming session:", error.message);
3532
3609
  this.onDisconnect();
3533
3610
  throw error;
3534
3611
  }
@@ -3565,28 +3642,37 @@ var DeflyWallet = class extends BaseWallet {
3565
3642
  return txnsToSign;
3566
3643
  }
3567
3644
  signTransactions = async (txnGroup, indexesToSign) => {
3568
- let txnsToSign = [];
3569
- if (isTransactionArray(txnGroup)) {
3570
- const flatTxns = flattenTxnGroup(txnGroup);
3571
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
3572
- } else {
3573
- const flatTxns = flattenTxnGroup(txnGroup);
3574
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
3575
- }
3576
- const client = this.client || await this.initializeClient();
3577
- const signedTxns = await client.signTransaction([txnsToSign]);
3578
- const result = txnsToSign.reduce((acc, txn) => {
3579
- if (txn.signers && txn.signers.length == 0) {
3580
- acc.push(null);
3645
+ try {
3646
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
3647
+ let txnsToSign = [];
3648
+ if (isTransactionArray(txnGroup)) {
3649
+ const flatTxns = flattenTxnGroup(txnGroup);
3650
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
3581
3651
  } else {
3582
- const signedTxn = signedTxns.shift();
3583
- if (signedTxn) {
3584
- acc.push(signedTxn);
3585
- }
3652
+ const flatTxns = flattenTxnGroup(txnGroup);
3653
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
3586
3654
  }
3587
- return acc;
3588
- }, []);
3589
- return result;
3655
+ const client = this.client || await this.initializeClient();
3656
+ this.logger.debug("Sending processed transactions to wallet...", [txnsToSign]);
3657
+ const signedTxns = await client.signTransaction([txnsToSign]);
3658
+ this.logger.debug("Received signed transactions from wallet", signedTxns);
3659
+ const result = txnsToSign.reduce((acc, txn) => {
3660
+ if (txn.signers && txn.signers.length == 0) {
3661
+ acc.push(null);
3662
+ } else {
3663
+ const signedTxn = signedTxns.shift();
3664
+ if (signedTxn) {
3665
+ acc.push(signedTxn);
3666
+ }
3667
+ }
3668
+ return acc;
3669
+ }, []);
3670
+ this.logger.debug("Transactions signed successfully", result);
3671
+ return result;
3672
+ } catch (error) {
3673
+ this.logger.error("Error signing transactions:", error.message);
3674
+ throw error;
3675
+ }
3590
3676
  };
3591
3677
  };
3592
3678
 
@@ -3639,19 +3725,22 @@ var ExodusWallet = class extends BaseWallet {
3639
3725
  icon: ICON2
3640
3726
  };
3641
3727
  async initializeClient() {
3642
- console.info(`[${this.metadata.name}] Initializing client...`);
3728
+ this.logger.info("Initializing client...");
3643
3729
  if (typeof window === "undefined" || window.algorand === void 0) {
3730
+ this.logger.error("Exodus is not available.");
3644
3731
  throw new Error("Exodus is not available.");
3645
3732
  }
3646
3733
  const client = window.algorand;
3647
3734
  this.client = client;
3735
+ this.logger.info("Client initialized");
3648
3736
  return client;
3649
3737
  }
3650
3738
  connect = async () => {
3651
- console.info(`[${this.metadata.name}] Connecting...`);
3739
+ this.logger.info("Connecting...");
3652
3740
  const client = this.client || await this.initializeClient();
3653
3741
  const { accounts } = await client.enable(this.options);
3654
3742
  if (accounts.length === 0) {
3743
+ this.logger.error("No accounts found!");
3655
3744
  throw new Error("No accounts found!");
3656
3745
  }
3657
3746
  const walletAccounts = accounts.map((address, idx) => ({
@@ -3667,27 +3756,31 @@ var ExodusWallet = class extends BaseWallet {
3667
3756
  walletId: this.id,
3668
3757
  wallet: walletState
3669
3758
  });
3670
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
3759
+ this.logger.info("\u2705 Connected.", walletState);
3671
3760
  return walletAccounts;
3672
3761
  };
3673
3762
  disconnect = async () => {
3763
+ this.logger.info("Disconnecting...");
3674
3764
  this.onDisconnect();
3675
- console.info(`[${this.metadata.name}] Disconnected.`);
3765
+ this.logger.info("Disconnected.");
3676
3766
  };
3677
3767
  resumeSession = async () => {
3678
3768
  try {
3679
3769
  const state = this.store.state;
3680
3770
  const walletState = state.wallets[this.id];
3681
3771
  if (!walletState) {
3772
+ this.logger.info("No session to resume");
3682
3773
  return;
3683
3774
  }
3684
- console.info(`[${this.metadata.name}] Resuming session...`);
3775
+ this.logger.info("Resuming session...");
3685
3776
  const client = await this.initializeClient();
3686
3777
  if (!client.isConnected) {
3778
+ this.logger.error("Exodus is not connected.");
3687
3779
  throw new Error("Exodus is not connected.");
3688
3780
  }
3781
+ this.logger.info("Session resumed");
3689
3782
  } catch (error) {
3690
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
3783
+ this.logger.error("Error resuming session:", error.message);
3691
3784
  this.onDisconnect();
3692
3785
  throw error;
3693
3786
  }
@@ -3726,23 +3819,32 @@ var ExodusWallet = class extends BaseWallet {
3726
3819
  return txnsToSign;
3727
3820
  }
3728
3821
  signTransactions = async (txnGroup, indexesToSign) => {
3729
- let txnsToSign = [];
3730
- if (isTransactionArray(txnGroup)) {
3731
- const flatTxns = flattenTxnGroup(txnGroup);
3732
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
3733
- } else {
3734
- const flatTxns = flattenTxnGroup(txnGroup);
3735
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
3736
- }
3737
- const client = this.client || await this.initializeClient();
3738
- const signTxnsResult = await client.signTxns(txnsToSign);
3739
- const result = signTxnsResult.map((value) => {
3740
- if (value === null) {
3741
- return null;
3822
+ try {
3823
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
3824
+ let txnsToSign = [];
3825
+ if (isTransactionArray(txnGroup)) {
3826
+ const flatTxns = flattenTxnGroup(txnGroup);
3827
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
3828
+ } else {
3829
+ const flatTxns = flattenTxnGroup(txnGroup);
3830
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
3742
3831
  }
3743
- return base64ToByteArray(value);
3744
- });
3745
- return result;
3832
+ const client = this.client || await this.initializeClient();
3833
+ this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
3834
+ const signTxnsResult = await client.signTxns(txnsToSign);
3835
+ this.logger.debug("Received signed transactions from wallet", signTxnsResult);
3836
+ const result = signTxnsResult.map((value) => {
3837
+ if (value === null) {
3838
+ return null;
3839
+ }
3840
+ return base64ToByteArray(value);
3841
+ });
3842
+ this.logger.debug("Transactions signed successfully", result);
3843
+ return result;
3844
+ } catch (error) {
3845
+ this.logger.error("Error signing transactions:", error.message);
3846
+ throw error;
3847
+ }
3746
3848
  };
3747
3849
  };
3748
3850
 
@@ -3759,7 +3861,7 @@ var ICON3 = `data:image/svg+xml;base64,${btoa(`
3759
3861
  <path fill="#FFFFFF" d="M158.1,359.8h19.7V245.5c-6.1-5.4-12.7-10-19.7-14V359.8z" />
3760
3862
  </svg>
3761
3863
  `)}`;
3762
- var KibisisWallet = class _KibisisWallet extends BaseWallet {
3864
+ var KibisisWallet = class extends BaseWallet {
3763
3865
  avmWebClient = null;
3764
3866
  avmWebProviderSDK = null;
3765
3867
  store;
@@ -3823,8 +3925,10 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
3823
3925
  })
3824
3926
  );
3825
3927
  }
3928
+ this.logger.debug("Disable successful", { result });
3826
3929
  return resolve(result);
3827
3930
  });
3931
+ this.logger.debug("Sending disable request...", { genesisHash });
3828
3932
  avmWebClient.disable({
3829
3933
  genesisHash,
3830
3934
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
@@ -3875,8 +3979,10 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
3875
3979
  })
3876
3980
  );
3877
3981
  }
3982
+ this.logger.debug("Enable successful", { result });
3878
3983
  return resolve(result);
3879
3984
  });
3985
+ this.logger.debug("Sending enable request...", { genesisHash });
3880
3986
  avmWebClient.enable({
3881
3987
  genesisHash,
3882
3988
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
@@ -3889,32 +3995,30 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
3889
3995
  return version.genesis_hash_b64;
3890
3996
  }
3891
3997
  async _initializeAVMWebClient() {
3892
- const _functionName = "_initializeAVMWebClient";
3893
3998
  const avmWebProviderSDK = this.avmWebProviderSDK || await this._initializeAVMWebProviderSDK();
3894
3999
  if (!this.avmWebClient) {
3895
- console.info(`[${_KibisisWallet.name}]#${_functionName}: initializing new client...`);
4000
+ this.logger.info("Initializing new AVM Web Client...");
3896
4001
  this.avmWebClient = avmWebProviderSDK.AVMWebClient.init();
4002
+ this.logger.info("AVM Web Client initialized");
3897
4003
  }
3898
4004
  return this.avmWebClient;
3899
4005
  }
3900
4006
  async _initializeAVMWebProviderSDK() {
3901
- const _functionName = "_initializeAVMWebProviderSDK";
3902
4007
  if (!this.avmWebProviderSDK) {
3903
- console.info(
3904
- `[${_KibisisWallet.name}]#${_functionName}: initializing @agoralabs-sh/avm-web-provider...`
3905
- );
4008
+ this.logger.info("Initializing @agoralabs-sh/avm-web-provider...");
3906
4009
  const module2 = await import("@agoralabs-sh/avm-web-provider");
3907
4010
  this.avmWebProviderSDK = module2.default ? module2.default : module2;
3908
4011
  if (!this.avmWebProviderSDK) {
3909
4012
  throw new Error(
3910
- "failed to initialize, the @agoralabs-sh/avm-web-provider sdk was not provided"
4013
+ "Failed to initialize, the @agoralabs-sh/avm-web-provider SDK was not provided"
3911
4014
  );
3912
4015
  }
3913
4016
  if (!this.avmWebProviderSDK.AVMWebClient) {
3914
4017
  throw new Error(
3915
- "failed to initialize, the @agoralabs-sh/avm-web-provider sdk was not provided. AVMWebClient missing"
4018
+ "Failed to initialize, AVMWebClient missing from @agoralabs-sh/avm-web-provider SDK"
3916
4019
  );
3917
4020
  }
4021
+ this.logger.info("@agoralabs-sh/avm-web-provider initialized");
3918
4022
  }
3919
4023
  return this.avmWebProviderSDK;
3920
4024
  }
@@ -3971,8 +4075,10 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
3971
4075
  })
3972
4076
  );
3973
4077
  }
4078
+ this.logger.debug("Sign transactions successful", { result });
3974
4079
  return resolve(result);
3975
4080
  });
4081
+ this.logger.debug("Sending sign transactions request...", { txns });
3976
4082
  avmWebClient.signTransactions({
3977
4083
  txns,
3978
4084
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
@@ -3985,14 +4091,13 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
3985
4091
  async connect() {
3986
4092
  let result;
3987
4093
  try {
3988
- console.info(`[${this.metadata.name}] Connecting...`);
4094
+ this.logger.info("Connecting...");
3989
4095
  result = await this._enable();
3990
- console.info(
3991
- `[${this.metadata.name}] Successfully connected on network "${result.genesisId}"`
3992
- );
4096
+ this.logger.info(`Successfully connected on network "${result.genesisId}"`);
3993
4097
  } catch (error) {
3994
- console.error(
3995
- `[${this.metadata.name}] Error connecting: ` + (isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message)
4098
+ this.logger.error(
4099
+ "Error connecting:",
4100
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
3996
4101
  );
3997
4102
  throw error;
3998
4103
  }
@@ -4005,20 +4110,21 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
4005
4110
  walletId: this.id,
4006
4111
  wallet: walletState
4007
4112
  });
4008
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
4113
+ this.logger.info("\u2705 Connected.", walletState);
4009
4114
  return walletAccounts;
4010
4115
  }
4011
4116
  async disconnect() {
4012
4117
  try {
4013
- console.info(`[${this.metadata.name}] Disconnecting...`);
4118
+ this.logger.info("Disconnecting...");
4014
4119
  this.onDisconnect();
4015
4120
  const result = await this._disable();
4016
- console.info(
4017
- `[${this.metadata.name}] Successfully disconnected${result.sessionIds && result.sessionIds.length ? ` sessions [${result.sessionIds.join(",")}]` : ""} on network "${result.genesisId}"`
4121
+ this.logger.info(
4122
+ `Successfully disconnected${result.sessionIds && result.sessionIds.length ? ` sessions [${result.sessionIds.join(",")}]` : ""} on network "${result.genesisId}"`
4018
4123
  );
4019
4124
  } catch (error) {
4020
- console.error(
4021
- `[${this.metadata.name}] Error disconnecting: ` + (isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message)
4125
+ this.logger.error(
4126
+ "Error disconnecting:",
4127
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4022
4128
  );
4023
4129
  throw error;
4024
4130
  }
@@ -4028,18 +4134,19 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
4028
4134
  const walletState = state.wallets[this.id];
4029
4135
  let result;
4030
4136
  if (!walletState) {
4137
+ this.logger.info("No session to resume");
4031
4138
  return;
4032
4139
  }
4033
4140
  try {
4034
- console.info(`[${this.metadata.name}] Resuming session...`);
4141
+ this.logger.info("Resuming session...");
4035
4142
  result = await this._enable();
4036
4143
  if (result.accounts.length === 0) {
4037
- throw new Error(`No accounts found!`);
4144
+ throw new Error("No accounts found!");
4038
4145
  }
4039
4146
  const walletAccounts = this._mapAVMWebProviderAccountToWalletAccounts(result.accounts);
4040
4147
  const match = compareAccounts(walletAccounts, walletState.accounts);
4041
4148
  if (!match) {
4042
- console.warn(`[${this.metadata.name}] Session accounts mismatch, updating accounts`, {
4149
+ this.logger.warn("Session accounts mismatch, updating accounts", {
4043
4150
  prev: walletState.accounts,
4044
4151
  current: walletAccounts
4045
4152
  });
@@ -4048,9 +4155,11 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
4048
4155
  accounts: walletAccounts
4049
4156
  });
4050
4157
  }
4158
+ this.logger.info("Session resumed successfully");
4051
4159
  } catch (error) {
4052
- console.error(
4053
- `[${this.metadata.name}] Error resuming session: ` + (isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message)
4160
+ this.logger.error(
4161
+ "Error resuming session:",
4162
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4054
4163
  );
4055
4164
  this.onDisconnect();
4056
4165
  throw error;
@@ -4091,6 +4200,7 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
4091
4200
  }
4092
4201
  signTransactions = async (txnGroup, indexesToSign) => {
4093
4202
  try {
4203
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4094
4204
  let txnsToSign = [];
4095
4205
  if (isTransactionArray(txnGroup)) {
4096
4206
  const flatTxns = flattenTxnGroup(txnGroup);
@@ -4099,17 +4209,21 @@ var KibisisWallet = class _KibisisWallet extends BaseWallet {
4099
4209
  const flatTxns = flattenTxnGroup(txnGroup);
4100
4210
  txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4101
4211
  }
4212
+ this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
4102
4213
  const signTxnsResult = await this._signTransactions(txnsToSign);
4214
+ this.logger.debug("Received signed transactions from wallet", signTxnsResult);
4103
4215
  const result = signTxnsResult.stxns.map((value) => {
4104
4216
  if (value === null) {
4105
4217
  return null;
4106
4218
  }
4107
4219
  return base64ToByteArray(value);
4108
4220
  });
4221
+ this.logger.debug("Transactions signed successfully", result);
4109
4222
  return result;
4110
4223
  } catch (error) {
4111
- console.error(
4112
- `[${this.metadata.name}] error signing transactions: ` + (isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message)
4224
+ this.logger.error(
4225
+ "Error signing transactions:",
4226
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4113
4227
  );
4114
4228
  throw error;
4115
4229
  }
@@ -4159,54 +4273,63 @@ var KmdWallet = class extends BaseWallet {
4159
4273
  icon: ICON4
4160
4274
  };
4161
4275
  async initializeClient() {
4162
- console.info(`[${this.metadata.name}] Initializing client...`);
4276
+ this.logger.info("Initializing client...");
4163
4277
  const { token, baseServer, port } = this.options;
4164
4278
  const client = new import_algosdk4.default.Kmd(token, baseServer, port);
4165
4279
  this.client = client;
4280
+ this.logger.info("Client initialized");
4166
4281
  return client;
4167
4282
  }
4168
4283
  connect = async () => {
4169
- console.info(`[${this.metadata.name}] Connecting...`);
4284
+ this.logger.info("Connecting...");
4170
4285
  if (!this.client) {
4171
4286
  await this.initializeClient();
4172
4287
  }
4173
- const token = await this.fetchToken();
4174
- const accounts = await this.fetchAccounts(token);
4175
- if (accounts.length === 0) {
4176
- throw new Error("No accounts found!");
4288
+ try {
4289
+ const token = await this.fetchToken();
4290
+ const accounts = await this.fetchAccounts(token);
4291
+ if (accounts.length === 0) {
4292
+ throw new Error("No accounts found!");
4293
+ }
4294
+ const walletAccounts = accounts.map((address, idx) => ({
4295
+ name: `${this.metadata.name} Account ${idx + 1}`,
4296
+ address
4297
+ }));
4298
+ const activeAccount = walletAccounts[0];
4299
+ const walletState = {
4300
+ accounts: walletAccounts,
4301
+ activeAccount
4302
+ };
4303
+ addWallet(this.store, {
4304
+ walletId: this.id,
4305
+ wallet: walletState
4306
+ });
4307
+ await this.releaseToken(token);
4308
+ this.logger.info("\u2705 Connected.", walletState);
4309
+ return walletAccounts;
4310
+ } catch (error) {
4311
+ this.logger.error("Error connecting:", error.message);
4312
+ throw error;
4177
4313
  }
4178
- const walletAccounts = accounts.map((address, idx) => ({
4179
- name: `${this.metadata.name} Account ${idx + 1}`,
4180
- address
4181
- }));
4182
- const activeAccount = walletAccounts[0];
4183
- const walletState = {
4184
- accounts: walletAccounts,
4185
- activeAccount
4186
- };
4187
- addWallet(this.store, {
4188
- walletId: this.id,
4189
- wallet: walletState
4190
- });
4191
- await this.releaseToken(token);
4192
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
4193
- return walletAccounts;
4194
4314
  };
4195
4315
  disconnect = async () => {
4316
+ this.logger.info("Disconnecting...");
4196
4317
  this.onDisconnect();
4197
- console.info(`[${this.metadata.name}] Disconnected.`);
4318
+ this.logger.info("Disconnected.");
4198
4319
  };
4199
4320
  resumeSession = async () => {
4200
4321
  try {
4201
4322
  const state = this.store.state;
4202
4323
  const walletState = state.wallets[this.id];
4203
4324
  if (!walletState) {
4325
+ this.logger.info("No session to resume");
4204
4326
  return;
4205
4327
  }
4206
- console.info(`[${this.metadata.name}] Resuming session...`);
4328
+ this.logger.info("Resuming session...");
4207
4329
  await this.initializeClient();
4330
+ this.logger.info("Session resumed");
4208
4331
  } catch (error) {
4209
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
4332
+ this.logger.error("Error resuming session:", error.message);
4210
4333
  this.onDisconnect();
4211
4334
  throw error;
4212
4335
  }
@@ -4239,36 +4362,47 @@ var KmdWallet = class extends BaseWallet {
4239
4362
  return txnsToSign;
4240
4363
  }
4241
4364
  signTransactions = async (txnGroup, indexesToSign) => {
4242
- let txnsToSign = [];
4243
- if (isTransactionArray(txnGroup)) {
4244
- const flatTxns = flattenTxnGroup(txnGroup);
4245
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
4246
- } else {
4247
- const flatTxns = flattenTxnGroup(txnGroup);
4248
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4365
+ try {
4366
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4367
+ let txnsToSign = [];
4368
+ if (isTransactionArray(txnGroup)) {
4369
+ const flatTxns = flattenTxnGroup(txnGroup);
4370
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
4371
+ } else {
4372
+ const flatTxns = flattenTxnGroup(txnGroup);
4373
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4374
+ }
4375
+ const token = await this.fetchToken();
4376
+ const password = this.getPassword();
4377
+ const client = this.client || await this.initializeClient();
4378
+ this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
4379
+ const signedTxns = await Promise.all(
4380
+ txnsToSign.map((txn) => client.signTransaction(token, password, txn))
4381
+ );
4382
+ this.logger.debug("Received signed transactions from wallet", signedTxns);
4383
+ await this.releaseToken(token);
4384
+ this.logger.debug("Transactions signed successfully", signedTxns);
4385
+ return signedTxns;
4386
+ } catch (error) {
4387
+ this.logger.error("Error signing transactions:", error.message);
4388
+ throw error;
4249
4389
  }
4250
- const token = await this.fetchToken();
4251
- const password = this.getPassword();
4252
- const client = this.client || await this.initializeClient();
4253
- const signedTxns = await Promise.all(
4254
- txnsToSign.map((txn) => client.signTransaction(token, password, txn))
4255
- );
4256
- await this.releaseToken(token);
4257
- return signedTxns;
4258
4390
  };
4259
4391
  async fetchWalletId() {
4260
- console.info(`[${this.metadata.name}] Fetching wallet data...`);
4392
+ this.logger.debug("Fetching wallet data...", { walletName: this.walletName });
4261
4393
  const client = this.client || await this.initializeClient();
4262
4394
  const { wallets } = await client.listWallets();
4263
4395
  const wallet = wallets.find((wallet2) => wallet2.name === this.walletName);
4264
4396
  if (!wallet) {
4397
+ this.logger.error(`Wallet "${this.walletName}" not found!`);
4265
4398
  throw new Error(`Wallet "${this.walletName}" not found!`);
4266
4399
  }
4267
4400
  this.walletId = wallet.id;
4401
+ this.logger.debug("Wallet data fetched successfully", { walletId: this.walletId });
4268
4402
  return wallet.id;
4269
4403
  }
4270
4404
  async fetchToken() {
4271
- console.info(`[${this.metadata.name}] Fetching token...`);
4405
+ this.logger.debug("Fetching token...", { walletId: this.walletId });
4272
4406
  const client = this.client || await this.initializeClient();
4273
4407
  const walletId = this.walletId || await this.fetchWalletId();
4274
4408
  const password = this.getPassword();
@@ -4276,12 +4410,14 @@ var KmdWallet = class extends BaseWallet {
4276
4410
  walletId,
4277
4411
  password
4278
4412
  );
4413
+ this.logger.debug("Token fetched successfully");
4279
4414
  return wallet_handle_token;
4280
4415
  }
4281
4416
  async releaseToken(token) {
4282
- console.info(`[${this.metadata.name}] Releasing token...`);
4417
+ this.logger.debug("Releasing token...");
4283
4418
  const client = this.client || await this.initializeClient();
4284
4419
  await client.releaseWalletHandle(token);
4420
+ this.logger.debug("Token released successfully");
4285
4421
  }
4286
4422
  getPassword() {
4287
4423
  if (this.password) {
@@ -4292,9 +4428,10 @@ var KmdWallet = class extends BaseWallet {
4292
4428
  return password;
4293
4429
  }
4294
4430
  async fetchAccounts(token) {
4295
- console.info(`[${this.metadata.name}] Fetching accounts...`);
4431
+ this.logger.debug("Fetching accounts...");
4296
4432
  const client = this.client || await this.initializeClient();
4297
4433
  const { addresses } = await client.listKeys(token);
4434
+ this.logger.debug("Accounts fetched successfully", { addresses });
4298
4435
  return addresses;
4299
4436
  }
4300
4437
  };
@@ -4323,7 +4460,8 @@ var LuteWallet = class extends BaseWallet {
4323
4460
  }) {
4324
4461
  super({ id, metadata, getAlgodClient, store, subscribe });
4325
4462
  if (!options?.siteName) {
4326
- throw new Error("[LuteWallet] Missing required option: siteName");
4463
+ this.logger.error("Missing required option: siteName");
4464
+ throw new Error("Missing required option: siteName");
4327
4465
  }
4328
4466
  this.options = options;
4329
4467
  this.store = store;
@@ -4333,11 +4471,12 @@ var LuteWallet = class extends BaseWallet {
4333
4471
  icon: ICON5
4334
4472
  };
4335
4473
  async initializeClient() {
4336
- console.info(`[${this.metadata.name}] Initializing client...`);
4474
+ this.logger.info("Initializing client...");
4337
4475
  const module2 = await import("lute-connect");
4338
4476
  const LuteConnect = module2.default;
4339
4477
  const client = new LuteConnect(this.options.siteName);
4340
4478
  this.client = client;
4479
+ this.logger.info("Client initialized");
4341
4480
  return client;
4342
4481
  }
4343
4482
  async getGenesisId() {
@@ -4347,11 +4486,12 @@ var LuteWallet = class extends BaseWallet {
4347
4486
  return genesisId;
4348
4487
  }
4349
4488
  connect = async () => {
4350
- console.info(`[${this.metadata.name}] Connecting...`);
4489
+ this.logger.info("Connecting...");
4351
4490
  const client = this.client || await this.initializeClient();
4352
4491
  const genesisId = await this.getGenesisId();
4353
4492
  const accounts = await client.connect(genesisId);
4354
4493
  if (accounts.length === 0) {
4494
+ this.logger.error("No accounts found!");
4355
4495
  throw new Error("No accounts found!");
4356
4496
  }
4357
4497
  const walletAccounts = accounts.map((address, idx) => ({
@@ -4367,24 +4507,26 @@ var LuteWallet = class extends BaseWallet {
4367
4507
  walletId: this.id,
4368
4508
  wallet: walletState
4369
4509
  });
4370
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
4510
+ this.logger.info("Connected successfully", walletState);
4371
4511
  return walletAccounts;
4372
4512
  };
4373
4513
  disconnect = async () => {
4374
4514
  this.onDisconnect();
4375
- console.info(`[${this.metadata.name}] Disconnected.`);
4515
+ this.logger.info("Disconnected");
4376
4516
  };
4377
4517
  resumeSession = async () => {
4378
4518
  try {
4379
4519
  const state = this.store.state;
4380
4520
  const walletState = state.wallets[this.id];
4381
4521
  if (!walletState) {
4522
+ this.logger.info("No session to resume");
4382
4523
  return;
4383
4524
  }
4384
- console.info(`[${this.metadata.name}] Resuming session...`);
4525
+ this.logger.info("Resuming session...");
4385
4526
  await this.initializeClient();
4527
+ this.logger.info("Session resumed successfully");
4386
4528
  } catch (error) {
4387
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
4529
+ this.logger.error("Error resuming session:", error.message);
4388
4530
  this.onDisconnect();
4389
4531
  throw error;
4390
4532
  }
@@ -4424,6 +4566,7 @@ var LuteWallet = class extends BaseWallet {
4424
4566
  }
4425
4567
  signTransactions = async (txnGroup, indexesToSign) => {
4426
4568
  try {
4569
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4427
4570
  let txnsToSign = [];
4428
4571
  if (isTransactionArray(txnGroup)) {
4429
4572
  const flatTxns = flattenTxnGroup(txnGroup);
@@ -4433,12 +4576,16 @@ var LuteWallet = class extends BaseWallet {
4433
4576
  txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4434
4577
  }
4435
4578
  const client = this.client || await this.initializeClient();
4579
+ this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
4436
4580
  const signTxnsResult = await client.signTxns(txnsToSign);
4581
+ this.logger.debug("Transactions signed successfully", signTxnsResult);
4437
4582
  return signTxnsResult;
4438
4583
  } catch (error) {
4439
4584
  if (isSignTxnsError(error)) {
4585
+ this.logger.error("Error signing transactions:", error.message, `(code: ${error.code})`);
4440
4586
  throw new SignTxnsError(error.message, error.code);
4441
4587
  }
4588
+ this.logger.error("Unknown error signing transactions:", error);
4442
4589
  throw error;
4443
4590
  }
4444
4591
  };
@@ -4466,7 +4613,8 @@ var MagicAuth = class extends BaseWallet {
4466
4613
  }) {
4467
4614
  super({ id, metadata, getAlgodClient, store, subscribe });
4468
4615
  if (!options?.apiKey) {
4469
- throw new Error(`[${this.metadata.name}] Missing required option: apiKey`);
4616
+ this.logger.error("Missing required option: apiKey");
4617
+ throw new Error("Missing required option: apiKey");
4470
4618
  }
4471
4619
  this.options = options;
4472
4620
  this.store = store;
@@ -4476,7 +4624,7 @@ var MagicAuth = class extends BaseWallet {
4476
4624
  icon: ICON6
4477
4625
  };
4478
4626
  async initializeClient() {
4479
- console.info(`[${this.metadata.name}] Initializing client...`);
4627
+ this.logger.info("Initializing client...");
4480
4628
  const Magic = (await Promise.resolve().then(() => (init_es4(), es_exports))).Magic;
4481
4629
  const AlgorandExtension = (await Promise.resolve().then(() => (init_es5(), es_exports2))).AlgorandExtension;
4482
4630
  const client = new Magic(this.options.apiKey, {
@@ -4487,26 +4635,30 @@ var MagicAuth = class extends BaseWallet {
4487
4635
  }
4488
4636
  });
4489
4637
  this.client = client;
4638
+ this.logger.info("Client initialized");
4490
4639
  return client;
4491
4640
  }
4492
4641
  connect = async (args) => {
4493
- console.info(`[${this.metadata.name}] Connecting...`);
4642
+ this.logger.info("Connecting...");
4494
4643
  if (!args?.email || typeof args.email !== "string") {
4644
+ this.logger.error("Magic Link provider requires an email (string) to connect");
4495
4645
  throw new Error("Magic Link provider requires an email (string) to connect");
4496
4646
  }
4497
4647
  const { email } = args;
4498
4648
  const client = this.client || await this.initializeClient();
4499
- console.info(`[${this.metadata.name}] Logging in ${email}...`);
4649
+ this.logger.info(`Logging in ${email}...`);
4500
4650
  await client.auth.loginWithMagicLink({ email });
4501
4651
  const userInfo = await client.user.getInfo();
4502
4652
  if (!userInfo) {
4653
+ this.logger.error("User info not found!");
4503
4654
  throw new Error("User info not found!");
4504
4655
  }
4505
4656
  if (!userInfo.publicAddress) {
4657
+ this.logger.error("No account found!");
4506
4658
  throw new Error("No account found!");
4507
4659
  }
4508
4660
  this.userInfo = userInfo;
4509
- console.info(`[${this.metadata.name}] Login successful`, userInfo);
4661
+ this.logger.info("Login successful", userInfo);
4510
4662
  const walletAccount = {
4511
4663
  name: userInfo.email ?? "Magic Wallet 1",
4512
4664
  address: userInfo.publicAddress
@@ -4519,39 +4671,42 @@ var MagicAuth = class extends BaseWallet {
4519
4671
  walletId: this.id,
4520
4672
  wallet: walletState
4521
4673
  });
4522
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
4674
+ this.logger.info("Connected successfully", walletState);
4523
4675
  return [walletAccount];
4524
4676
  };
4525
4677
  disconnect = async () => {
4526
- console.info(`[${this.metadata.name}] Disconnecting...`);
4678
+ this.logger.info("Disconnecting...");
4527
4679
  this.onDisconnect();
4528
4680
  const client = this.client || await this.initializeClient();
4529
- console.info(`[${this.metadata.name}] Logging out ${this.userInfo?.email || "user"}...`);
4681
+ this.logger.info(`Logging out ${this.userInfo?.email || "user"}...`);
4530
4682
  await client.user.logout();
4531
- console.info(`[${this.metadata.name}] Disconnected.`);
4683
+ this.logger.info("Disconnected");
4532
4684
  };
4533
4685
  resumeSession = async () => {
4534
4686
  try {
4535
4687
  const state = this.store.state;
4536
4688
  const walletState = state.wallets[this.id];
4537
4689
  if (!walletState) {
4690
+ this.logger.info("No session to resume");
4538
4691
  return;
4539
4692
  }
4540
- console.info(`[${this.metadata.name}] Resuming session...`);
4693
+ this.logger.info("Resuming session...");
4541
4694
  const client = this.client || await this.initializeClient();
4542
4695
  const isLoggedIn = await client.user.isLoggedIn();
4543
4696
  if (!isLoggedIn) {
4544
- console.warn(`[${this.metadata.name}] Not logged in, please reconnect...`);
4697
+ this.logger.warn("Not logged in, please reconnect...");
4545
4698
  this.onDisconnect();
4546
4699
  return;
4547
4700
  }
4548
4701
  const userInfo = await client.user.getInfo();
4549
4702
  if (!userInfo) {
4550
4703
  await client.user.logout();
4704
+ this.logger.error("User info not found!");
4551
4705
  throw new Error("User info not found!");
4552
4706
  }
4553
4707
  if (!userInfo.publicAddress) {
4554
4708
  await client.user.logout();
4709
+ this.logger.error("No account found!");
4555
4710
  throw new Error("No account found!");
4556
4711
  }
4557
4712
  this.userInfo = userInfo;
@@ -4564,7 +4719,7 @@ var MagicAuth = class extends BaseWallet {
4564
4719
  const { name: storedName, address: storedAddress } = storedAccount;
4565
4720
  const match = name === storedName && address === storedAddress;
4566
4721
  if (!match) {
4567
- console.warn(`[${this.metadata.name}] Session account mismatch, updating account`, {
4722
+ this.logger.warn("Session account mismatch, updating account", {
4568
4723
  prev: storedAccount,
4569
4724
  current: walletAccount
4570
4725
  });
@@ -4573,9 +4728,9 @@ var MagicAuth = class extends BaseWallet {
4573
4728
  accounts: [walletAccount]
4574
4729
  });
4575
4730
  }
4576
- console.info(`[${this.metadata.name}] Session resumed.`);
4731
+ this.logger.info("Session resumed successfully");
4577
4732
  } catch (error) {
4578
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
4733
+ this.logger.error("Error resuming session:", error.message);
4579
4734
  this.onDisconnect();
4580
4735
  throw error;
4581
4736
  }
@@ -4614,25 +4769,34 @@ var MagicAuth = class extends BaseWallet {
4614
4769
  return txnsToSign;
4615
4770
  }
4616
4771
  signTransactions = async (txnGroup, indexesToSign) => {
4617
- let txnsToSign = [];
4618
- if (isTransactionArray(txnGroup)) {
4619
- const flatTxns = flattenTxnGroup(txnGroup);
4620
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
4621
- } else {
4622
- const flatTxns = flattenTxnGroup(txnGroup);
4623
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4624
- }
4625
- const client = this.client || await this.initializeClient();
4626
- const signTxnsResult = await client.algorand.signGroupTransactionV2(
4627
- txnsToSign
4628
- );
4629
- const result = signTxnsResult.map((value) => {
4630
- if (value === void 0) {
4631
- return null;
4772
+ try {
4773
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4774
+ let txnsToSign = [];
4775
+ if (isTransactionArray(txnGroup)) {
4776
+ const flatTxns = flattenTxnGroup(txnGroup);
4777
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
4778
+ } else {
4779
+ const flatTxns = flattenTxnGroup(txnGroup);
4780
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4632
4781
  }
4633
- return base64ToByteArray(value);
4634
- });
4635
- return result;
4782
+ const client = this.client || await this.initializeClient();
4783
+ this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
4784
+ const signTxnsResult = await client.algorand.signGroupTransactionV2(
4785
+ txnsToSign
4786
+ );
4787
+ this.logger.debug("Received signed transactions from wallet", signTxnsResult);
4788
+ const result = signTxnsResult.map((value) => {
4789
+ if (value === void 0) {
4790
+ return null;
4791
+ }
4792
+ return base64ToByteArray(value);
4793
+ });
4794
+ this.logger.debug("Transactions signed successfully", result);
4795
+ return result;
4796
+ } catch (error) {
4797
+ this.logger.error("Error signing transactions:", error.message);
4798
+ throw error;
4799
+ }
4636
4800
  };
4637
4801
  };
4638
4802
 
@@ -4662,8 +4826,8 @@ var MnemonicWallet = class extends BaseWallet {
4662
4826
  this.options = { persistToStorage };
4663
4827
  this.store = store;
4664
4828
  if (this.options.persistToStorage) {
4665
- console.warn(
4666
- `[${this.metadata.name}] Persisting mnemonics to storage is insecure. Any private key mnemonics used should never hold real Algos (i.e., on MainNet). Use with caution!`
4829
+ this.logger.warn(
4830
+ "Persisting mnemonics to storage is insecure. Any private key mnemonics used should never hold real Algos (i.e., on MainNet). Use with caution!"
4667
4831
  );
4668
4832
  }
4669
4833
  }
@@ -4681,8 +4845,8 @@ var MnemonicWallet = class extends BaseWallet {
4681
4845
  try {
4682
4846
  const network = this.activeNetwork;
4683
4847
  if (network === "mainnet" /* MAINNET */) {
4684
- console.warn(
4685
- `[${this.metadata.name}] The Mnemonic wallet provider is insecure and intended for testing only. Any private key mnemonics used should never hold real Algos (i.e., on MainNet).`
4848
+ this.logger.warn(
4849
+ "The Mnemonic wallet provider is insecure and intended for testing only. Any private key mnemonics used should never hold real Algos (i.e., on MainNet)."
4686
4850
  );
4687
4851
  throw new Error("MainNet active network detected. Aborting.");
4688
4852
  }
@@ -4697,10 +4861,11 @@ var MnemonicWallet = class extends BaseWallet {
4697
4861
  mnemonic = prompt("Enter 25-word mnemonic passphrase:");
4698
4862
  if (!mnemonic) {
4699
4863
  this.account = null;
4864
+ this.logger.error("No mnemonic provided");
4700
4865
  throw new Error("No mnemonic provided");
4701
4866
  }
4702
4867
  if (this.options.persistToStorage) {
4703
- console.warn(`[${this.metadata.name}] Mnemonic saved to localStorage.`);
4868
+ this.logger.warn("Mnemonic saved to localStorage.");
4704
4869
  this.saveMnemonicToStorage(mnemonic);
4705
4870
  }
4706
4871
  }
@@ -4710,7 +4875,7 @@ var MnemonicWallet = class extends BaseWallet {
4710
4875
  }
4711
4876
  connect = async () => {
4712
4877
  this.checkMainnet();
4713
- console.info(`[${this.metadata.name}] Connecting...`);
4878
+ this.logger.info("Connecting...");
4714
4879
  const account = this.initializeAccount();
4715
4880
  const walletAccount = {
4716
4881
  name: `${this.metadata.name} Account`,
@@ -4724,20 +4889,24 @@ var MnemonicWallet = class extends BaseWallet {
4724
4889
  walletId: this.id,
4725
4890
  wallet: walletState
4726
4891
  });
4727
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
4892
+ this.logger.info("Connected successfully", walletState);
4728
4893
  return [walletAccount];
4729
4894
  };
4730
4895
  disconnect = async () => {
4896
+ this.logger.info("Disconnecting...");
4731
4897
  this.onDisconnect();
4732
4898
  this.account = null;
4733
- console.info(`[${this.metadata.name}] Disconnected.`);
4899
+ this.logger.info("Disconnected");
4734
4900
  };
4735
4901
  resumeSession = async () => {
4736
4902
  this.checkMainnet();
4737
4903
  const state = this.store.state;
4738
4904
  const walletState = state.wallets[this.id];
4739
4905
  if (walletState) {
4906
+ this.logger.info("No session to resume, disconnecting...");
4740
4907
  this.disconnect();
4908
+ } else {
4909
+ this.logger.info("No session to resume");
4741
4910
  }
4742
4911
  };
4743
4912
  processTxns(txnGroup, indexesToSign) {
@@ -4769,16 +4938,23 @@ var MnemonicWallet = class extends BaseWallet {
4769
4938
  }
4770
4939
  signTransactions = async (txnGroup, indexesToSign) => {
4771
4940
  this.checkMainnet();
4772
- let txnsToSign = [];
4773
- if (isTransactionArray(txnGroup)) {
4774
- const flatTxns = flattenTxnGroup(txnGroup);
4775
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
4776
- } else {
4777
- const flatTxns = flattenTxnGroup(txnGroup);
4778
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4941
+ try {
4942
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4943
+ let txnsToSign = [];
4944
+ if (isTransactionArray(txnGroup)) {
4945
+ const flatTxns = flattenTxnGroup(txnGroup);
4946
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
4947
+ } else {
4948
+ const flatTxns = flattenTxnGroup(txnGroup);
4949
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4950
+ }
4951
+ const signedTxns = txnsToSign.map((txn) => txn.signTxn(this.account.sk));
4952
+ this.logger.debug("Transactions signed successfully", { signedTxns });
4953
+ return signedTxns;
4954
+ } catch (error) {
4955
+ this.logger.error("Error signing transactions:", error.message);
4956
+ throw error;
4779
4957
  }
4780
- const signedTxns = txnsToSign.map((txn) => txn.signTxn(this.account.sk));
4781
- return signedTxns;
4782
4958
  };
4783
4959
  };
4784
4960
 
@@ -4816,19 +4992,21 @@ var PeraWallet = class extends BaseWallet {
4816
4992
  icon: ICON8
4817
4993
  };
4818
4994
  async initializeClient() {
4819
- console.info(`[${this.metadata.name}] Initializing client...`);
4995
+ this.logger.info("Initializing client...");
4820
4996
  const module2 = await import("@perawallet/connect");
4821
4997
  const PeraWalletConnect = module2.default ? module2.default.PeraWalletConnect : module2.PeraWalletConnect;
4822
4998
  const client = new PeraWalletConnect(this.options);
4823
4999
  client.connector?.on("disconnect", this.onDisconnect);
4824
5000
  this.client = client;
5001
+ this.logger.info("Client initialized");
4825
5002
  return client;
4826
5003
  }
4827
5004
  connect = async () => {
4828
- console.info(`[${this.metadata.name}] Connecting...`);
5005
+ this.logger.info("Connecting...");
4829
5006
  const client = this.client || await this.initializeClient();
4830
5007
  const accounts = await client.connect();
4831
5008
  if (accounts.length === 0) {
5009
+ this.logger.error("No accounts found!");
4832
5010
  throw new Error("No accounts found!");
4833
5011
  }
4834
5012
  const walletAccounts = accounts.map((address, idx) => ({
@@ -4844,27 +5022,29 @@ var PeraWallet = class extends BaseWallet {
4844
5022
  walletId: this.id,
4845
5023
  wallet: walletState
4846
5024
  });
4847
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
5025
+ this.logger.info("Connected successfully", walletState);
4848
5026
  return walletAccounts;
4849
5027
  };
4850
5028
  disconnect = async () => {
4851
- console.info(`[${this.metadata.name}] Disconnecting...`);
5029
+ this.logger.info("Disconnecting...");
4852
5030
  this.onDisconnect();
4853
5031
  const client = this.client || await this.initializeClient();
4854
5032
  await client.disconnect();
4855
- console.info(`[${this.metadata.name}] Disconnected.`);
5033
+ this.logger.info("Disconnected");
4856
5034
  };
4857
5035
  resumeSession = async () => {
4858
5036
  try {
4859
5037
  const state = this.store.state;
4860
5038
  const walletState = state.wallets[this.id];
4861
5039
  if (!walletState) {
5040
+ this.logger.info("No session to resume");
4862
5041
  return;
4863
5042
  }
4864
- console.info(`[${this.metadata.name}] Resuming session...`);
5043
+ this.logger.info("Resuming session...");
4865
5044
  const client = this.client || await this.initializeClient();
4866
5045
  const accounts = await client.reconnectSession();
4867
5046
  if (accounts.length === 0) {
5047
+ this.logger.error("No accounts found!");
4868
5048
  throw new Error("No accounts found!");
4869
5049
  }
4870
5050
  const walletAccounts = accounts.map((address, idx) => ({
@@ -4873,7 +5053,7 @@ var PeraWallet = class extends BaseWallet {
4873
5053
  }));
4874
5054
  const match = compareAccounts(walletAccounts, walletState.accounts);
4875
5055
  if (!match) {
4876
- console.warn(`[${this.metadata.name}] Session accounts mismatch, updating accounts`, {
5056
+ this.logger.warn("Session accounts mismatch, updating accounts", {
4877
5057
  prev: walletState.accounts,
4878
5058
  current: walletAccounts
4879
5059
  });
@@ -4882,8 +5062,9 @@ var PeraWallet = class extends BaseWallet {
4882
5062
  accounts: walletAccounts
4883
5063
  });
4884
5064
  }
5065
+ this.logger.info("Session resumed successfully");
4885
5066
  } catch (error) {
4886
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
5067
+ this.logger.error("Error resuming session:", error.message);
4887
5068
  this.onDisconnect();
4888
5069
  throw error;
4889
5070
  }
@@ -4920,28 +5101,37 @@ var PeraWallet = class extends BaseWallet {
4920
5101
  return txnsToSign;
4921
5102
  }
4922
5103
  signTransactions = async (txnGroup, indexesToSign) => {
4923
- let txnsToSign = [];
4924
- if (isTransactionArray(txnGroup)) {
4925
- const flatTxns = flattenTxnGroup(txnGroup);
4926
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
4927
- } else {
4928
- const flatTxns = flattenTxnGroup(txnGroup);
4929
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4930
- }
4931
- const client = this.client || await this.initializeClient();
4932
- const signedTxns = await client.signTransaction([txnsToSign]);
4933
- const result = txnsToSign.reduce((acc, txn) => {
4934
- if (txn.signers && txn.signers.length == 0) {
4935
- acc.push(null);
5104
+ try {
5105
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
5106
+ let txnsToSign = [];
5107
+ if (isTransactionArray(txnGroup)) {
5108
+ const flatTxns = flattenTxnGroup(txnGroup);
5109
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
4936
5110
  } else {
4937
- const signedTxn = signedTxns.shift();
4938
- if (signedTxn) {
4939
- acc.push(signedTxn);
4940
- }
5111
+ const flatTxns = flattenTxnGroup(txnGroup);
5112
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4941
5113
  }
4942
- return acc;
4943
- }, []);
4944
- return result;
5114
+ const client = this.client || await this.initializeClient();
5115
+ this.logger.debug("Sending processed transactions to wallet...", [txnsToSign]);
5116
+ const signedTxns = await client.signTransaction([txnsToSign]);
5117
+ this.logger.debug("Received signed transactions from wallet", signedTxns);
5118
+ const result = txnsToSign.reduce((acc, txn) => {
5119
+ if (txn.signers && txn.signers.length == 0) {
5120
+ acc.push(null);
5121
+ } else {
5122
+ const signedTxn = signedTxns.shift();
5123
+ if (signedTxn) {
5124
+ acc.push(signedTxn);
5125
+ }
5126
+ }
5127
+ return acc;
5128
+ }, []);
5129
+ this.logger.debug("Transactions signed successfully", result);
5130
+ return result;
5131
+ } catch (error) {
5132
+ this.logger.error("Error signing transactions:", error.message);
5133
+ throw error;
5134
+ }
4945
5135
  };
4946
5136
  };
4947
5137
 
@@ -4972,7 +5162,8 @@ var PeraWallet2 = class extends BaseWallet {
4972
5162
  }) {
4973
5163
  super({ id, metadata, getAlgodClient, store, subscribe });
4974
5164
  if (!options?.projectId) {
4975
- throw new Error(`[${this.metadata.name}] Missing required option: projectId`);
5165
+ this.logger.error("Missing required option: projectId");
5166
+ throw new Error("Missing required option: projectId");
4976
5167
  }
4977
5168
  this.options = options;
4978
5169
  this.store = store;
@@ -4982,19 +5173,21 @@ var PeraWallet2 = class extends BaseWallet {
4982
5173
  icon: ICON9
4983
5174
  };
4984
5175
  async initializeClient() {
4985
- console.info(`[${this.metadata.name}] Initializing client...`);
5176
+ this.logger.info("Initializing client...");
4986
5177
  const module2 = await import("@perawallet/connect-beta");
4987
5178
  const PeraWalletConnect = module2.PeraWalletConnect || module2.default.PeraWalletConnect;
4988
5179
  const client = new PeraWalletConnect(this.options);
4989
5180
  client.client?.on("session_delete", this.onDisconnect);
4990
5181
  this.client = client;
5182
+ this.logger.info("Client initialized");
4991
5183
  return client;
4992
5184
  }
4993
5185
  connect = async () => {
4994
- console.info(`[${this.metadata.name}] Connecting...`);
5186
+ this.logger.info("Connecting...");
4995
5187
  const client = this.client || await this.initializeClient();
4996
5188
  const accounts = await client.connect();
4997
5189
  if (accounts.length === 0) {
5190
+ this.logger.error("No accounts found!");
4998
5191
  throw new Error("No accounts found!");
4999
5192
  }
5000
5193
  const walletAccounts = accounts.map((address, idx) => ({
@@ -5010,27 +5203,29 @@ var PeraWallet2 = class extends BaseWallet {
5010
5203
  walletId: this.id,
5011
5204
  wallet: walletState
5012
5205
  });
5013
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
5206
+ this.logger.info("Connected successfully", walletState);
5014
5207
  return walletAccounts;
5015
5208
  };
5016
5209
  disconnect = async () => {
5017
- console.info(`[${this.metadata.name}] Disconnecting...`);
5210
+ this.logger.info("Disconnecting...");
5018
5211
  this.onDisconnect();
5019
5212
  const client = this.client || await this.initializeClient();
5020
5213
  await client.disconnect();
5021
- console.info(`[${this.metadata.name}] Disconnected.`);
5214
+ this.logger.info("Disconnected");
5022
5215
  };
5023
5216
  resumeSession = async () => {
5024
5217
  try {
5025
5218
  const state = this.store.state;
5026
5219
  const walletState = state.wallets[this.id];
5027
5220
  if (!walletState) {
5221
+ this.logger.info("No session to resume");
5028
5222
  return;
5029
5223
  }
5030
- console.info(`[${this.metadata.name}] Resuming session...`);
5224
+ this.logger.info("Resuming session...");
5031
5225
  const client = this.client || await this.initializeClient();
5032
5226
  const accounts = await client.reconnectSession();
5033
5227
  if (accounts.length === 0) {
5228
+ this.logger.error("No accounts found!");
5034
5229
  throw new Error("No accounts found!");
5035
5230
  }
5036
5231
  const walletAccounts = accounts.map((address, idx) => ({
@@ -5039,7 +5234,7 @@ var PeraWallet2 = class extends BaseWallet {
5039
5234
  }));
5040
5235
  const match = compareAccounts(walletAccounts, walletState.accounts);
5041
5236
  if (!match) {
5042
- console.warn(`[${this.metadata.name}] Session accounts mismatch, updating accounts`, {
5237
+ this.logger.warn("Session accounts mismatch, updating accounts", {
5043
5238
  prev: walletState.accounts,
5044
5239
  current: walletAccounts
5045
5240
  });
@@ -5048,8 +5243,9 @@ var PeraWallet2 = class extends BaseWallet {
5048
5243
  accounts: walletAccounts
5049
5244
  });
5050
5245
  }
5246
+ this.logger.info("Session resumed successfully");
5051
5247
  } catch (error) {
5052
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
5248
+ this.logger.error("Error resuming session:", error.message);
5053
5249
  this.onDisconnect();
5054
5250
  throw error;
5055
5251
  }
@@ -5086,28 +5282,37 @@ var PeraWallet2 = class extends BaseWallet {
5086
5282
  return txnsToSign;
5087
5283
  }
5088
5284
  signTransactions = async (txnGroup, indexesToSign) => {
5089
- let txnsToSign = [];
5090
- if (isTransactionArray(txnGroup)) {
5091
- const flatTxns = flattenTxnGroup(txnGroup);
5092
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
5093
- } else {
5094
- const flatTxns = flattenTxnGroup(txnGroup);
5095
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
5096
- }
5097
- const client = this.client || await this.initializeClient();
5098
- const signedTxns = await client.signTransaction([txnsToSign]);
5099
- const result = txnsToSign.reduce((acc, txn) => {
5100
- if (txn.signers && txn.signers.length == 0) {
5101
- acc.push(null);
5285
+ try {
5286
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
5287
+ let txnsToSign = [];
5288
+ if (isTransactionArray(txnGroup)) {
5289
+ const flatTxns = flattenTxnGroup(txnGroup);
5290
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
5102
5291
  } else {
5103
- const signedTxn = signedTxns.shift();
5104
- if (signedTxn) {
5105
- acc.push(signedTxn);
5106
- }
5292
+ const flatTxns = flattenTxnGroup(txnGroup);
5293
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
5107
5294
  }
5108
- return acc;
5109
- }, []);
5110
- return result;
5295
+ const client = this.client || await this.initializeClient();
5296
+ this.logger.debug("Sending processed transactions to wallet...", [txnsToSign]);
5297
+ const signedTxns = await client.signTransaction([txnsToSign]);
5298
+ this.logger.debug("Received signed transactions from wallet", signedTxns);
5299
+ const result = txnsToSign.reduce((acc, txn) => {
5300
+ if (txn.signers && txn.signers.length == 0) {
5301
+ acc.push(null);
5302
+ } else {
5303
+ const signedTxn = signedTxns.shift();
5304
+ if (signedTxn) {
5305
+ acc.push(signedTxn);
5306
+ }
5307
+ }
5308
+ return acc;
5309
+ }, []);
5310
+ this.logger.debug("Transactions signed successfully", result);
5311
+ return result;
5312
+ } catch (error) {
5313
+ this.logger.error("Error signing transactions:", error.message);
5314
+ throw error;
5315
+ }
5111
5316
  };
5112
5317
  };
5113
5318
 
@@ -5143,7 +5348,8 @@ var WalletConnect = class extends BaseWallet {
5143
5348
  }) {
5144
5349
  super({ id, metadata, getAlgodClient, store, subscribe });
5145
5350
  if (!options?.projectId) {
5146
- throw new Error(`[${this.metadata.name}] Missing required option: projectId`);
5351
+ this.logger.error("Missing required option: projectId");
5352
+ throw new Error("Missing required option: projectId");
5147
5353
  }
5148
5354
  const {
5149
5355
  projectId,
@@ -5206,7 +5412,7 @@ var WalletConnect = class extends BaseWallet {
5206
5412
  doc = getDocumentOrThrow();
5207
5413
  loc = getLocationOrThrow();
5208
5414
  } catch (error) {
5209
- console.warn(`[${this.metadata.name}] Error getting window metadata:`, error);
5415
+ this.logger.warn("Error getting window metadata:", error);
5210
5416
  return defaultMetadata;
5211
5417
  }
5212
5418
  function getIcons() {
@@ -5290,43 +5496,44 @@ var WalletConnect = class extends BaseWallet {
5290
5496
  return meta;
5291
5497
  }
5292
5498
  async initializeClient() {
5293
- console.info(`[${this.metadata.name}] Initializing client...`);
5499
+ this.logger.info("Initializing client...");
5294
5500
  const SignClient = (await import("@walletconnect/sign-client")).SignClient;
5295
5501
  const client = await SignClient.init(this.options);
5296
5502
  client.on("session_event", (args) => {
5297
- console.log(`[${this.metadata.name}] EVENT`, "session_event", args);
5503
+ this.logger.info("EVENT: session_event", args);
5298
5504
  });
5299
5505
  client.on("session_update", ({ topic, params }) => {
5300
- console.log(`[${this.metadata.name}] EVENT`, "session_update", { topic, params });
5506
+ this.logger.info("EVENT: session_update", { topic, params });
5301
5507
  const { namespaces } = params;
5302
5508
  const session = client.session.get(topic);
5303
5509
  const updatedSession = { ...session, namespaces };
5304
5510
  this.onSessionConnected(updatedSession);
5305
5511
  });
5306
5512
  client.on("session_delete", () => {
5307
- console.log(`[${this.metadata.name}] EVENT`, "session_delete");
5513
+ this.logger.info("EVENT: session_delete");
5308
5514
  this.session = null;
5309
5515
  });
5310
5516
  this.client = client;
5517
+ this.logger.info("Client initialized");
5311
5518
  return client;
5312
5519
  }
5313
5520
  async initializeModal() {
5314
- console.info(`[${this.metadata.name}] Initializing modal...`);
5521
+ this.logger.info("Initializing modal...");
5315
5522
  const WalletConnectModal = (await import("@walletconnect/modal")).WalletConnectModal;
5316
5523
  const modal = new WalletConnectModal({
5317
5524
  projectId: this.options.projectId,
5318
5525
  chains: this.chains,
5319
5526
  ...this.modalOptions
5320
5527
  });
5321
- modal.subscribeModal(
5322
- (state) => console.info(`[${this.metadata.name}] Modal ${state.open ? "open" : "closed"}`)
5323
- );
5528
+ modal.subscribeModal((state) => this.logger.info(`Modal ${state.open ? "open" : "closed"}`));
5324
5529
  this.modal = modal;
5530
+ this.logger.info("Modal initialized");
5325
5531
  return modal;
5326
5532
  }
5327
5533
  onSessionConnected(session) {
5328
5534
  const caipAccounts = session.namespaces.algorand.accounts;
5329
5535
  if (!caipAccounts.length) {
5536
+ this.logger.error("No accounts found!");
5330
5537
  throw new Error("No accounts found!");
5331
5538
  }
5332
5539
  const accounts = [...new Set(caipAccounts.map((account) => account.split(":").pop()))];
@@ -5345,11 +5552,11 @@ var WalletConnect = class extends BaseWallet {
5345
5552
  walletId: this.id,
5346
5553
  wallet: newWalletState
5347
5554
  });
5348
- console.info(`[${this.metadata.name}] \u2705 Connected.`, newWalletState);
5555
+ this.logger.info("Connected", newWalletState);
5349
5556
  } else {
5350
5557
  const match = compareAccounts(walletAccounts, walletState.accounts);
5351
5558
  if (!match) {
5352
- console.warn(`[${this.metadata.name}] Session accounts mismatch, updating accounts`, {
5559
+ this.logger.warn("Session accounts mismatch, updating accounts", {
5353
5560
  prev: walletState.accounts,
5354
5561
  current: walletAccounts
5355
5562
  });
@@ -5363,7 +5570,7 @@ var WalletConnect = class extends BaseWallet {
5363
5570
  return walletAccounts;
5364
5571
  }
5365
5572
  connect = async () => {
5366
- console.info(`[${this.metadata.name}] Connecting...`);
5573
+ this.logger.info("Connecting...");
5367
5574
  try {
5368
5575
  const client = this.client || await this.initializeClient();
5369
5576
  const modal = this.modal || await this.initializeModal();
@@ -5376,18 +5583,23 @@ var WalletConnect = class extends BaseWallet {
5376
5583
  };
5377
5584
  const { uri, approval } = await client.connect({ requiredNamespaces });
5378
5585
  if (!uri) {
5586
+ this.logger.error("No URI found");
5379
5587
  throw new Error("No URI found");
5380
5588
  }
5381
5589
  await modal.openModal({ uri });
5382
5590
  const session = await approval();
5383
5591
  const walletAccounts = this.onSessionConnected(session);
5592
+ this.logger.info("Connected successfully");
5384
5593
  return walletAccounts;
5594
+ } catch (error) {
5595
+ this.logger.error("Error connecting:", error.message);
5596
+ throw error;
5385
5597
  } finally {
5386
5598
  this.modal?.closeModal();
5387
5599
  }
5388
5600
  };
5389
5601
  disconnect = async () => {
5390
- console.info(`[${this.metadata.name}] Disconnecting...`);
5602
+ this.logger.info("Disconnecting...");
5391
5603
  try {
5392
5604
  this.onDisconnect();
5393
5605
  if (this.client && this.session) {
@@ -5399,9 +5611,10 @@ var WalletConnect = class extends BaseWallet {
5399
5611
  }
5400
5612
  });
5401
5613
  }
5402
- console.info(`[${this.metadata.name}] Disconnected.`);
5614
+ this.logger.info("Disconnected");
5403
5615
  } catch (error) {
5404
- console.error(error);
5616
+ this.logger.error("Error disconnecting:", error.message);
5617
+ throw error;
5405
5618
  }
5406
5619
  };
5407
5620
  resumeSession = async () => {
@@ -5409,17 +5622,19 @@ var WalletConnect = class extends BaseWallet {
5409
5622
  const state = this.store.state;
5410
5623
  const walletState = state.wallets[this.id];
5411
5624
  if (!walletState) {
5625
+ this.logger.info("No session to resume");
5412
5626
  return;
5413
5627
  }
5414
- console.info(`[${this.metadata.name}] Resuming session...`);
5628
+ this.logger.info("Resuming session...");
5415
5629
  const client = this.client || await this.initializeClient();
5416
5630
  if (client.session.length) {
5417
5631
  const lastKeyIndex = client.session.keys.length - 1;
5418
5632
  const restoredSession = client.session.get(client.session.keys[lastKeyIndex]);
5419
5633
  this.onSessionConnected(restoredSession);
5420
5634
  }
5635
+ this.logger.info("Session resumed successfully");
5421
5636
  } catch (error) {
5422
- console.error(`[${this.metadata.name}] Error resuming session: ${error.message}`);
5637
+ this.logger.error("Error resuming session:", error.message);
5423
5638
  this.onDisconnect();
5424
5639
  throw error;
5425
5640
  }
@@ -5460,8 +5675,10 @@ var WalletConnect = class extends BaseWallet {
5460
5675
  signTransactions = async (txnGroup, indexesToSign) => {
5461
5676
  try {
5462
5677
  if (!this.session) {
5463
- throw new SessionError(`No session found!`);
5678
+ this.logger.error("No session found!");
5679
+ throw new SessionError("No session found!");
5464
5680
  }
5681
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
5465
5682
  let txnsToSign = [];
5466
5683
  if (isTransactionArray(txnGroup)) {
5467
5684
  const flatTxns = flattenTxnGroup(txnGroup);
@@ -5471,12 +5688,14 @@ var WalletConnect = class extends BaseWallet {
5471
5688
  txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
5472
5689
  }
5473
5690
  const client = this.client || await this.initializeClient();
5691
+ this.logger.debug("Sending processed transactions to wallet...", [txnsToSign]);
5474
5692
  const request = formatJsonRpcRequest("algo_signTxn", [txnsToSign]);
5475
5693
  const signTxnsResult = await client.request({
5476
5694
  chainId: caipChainId[this.activeNetwork],
5477
5695
  topic: this.session.topic,
5478
5696
  request
5479
5697
  });
5698
+ this.logger.debug("Received signed transactions from wallet", signTxnsResult);
5480
5699
  const signedTxns = signTxnsResult.reduce((acc, value) => {
5481
5700
  if (value) {
5482
5701
  let signedTxn;
@@ -5487,7 +5706,7 @@ var WalletConnect = class extends BaseWallet {
5487
5706
  } else if (Array.isArray(value)) {
5488
5707
  signedTxn = new Uint8Array(value);
5489
5708
  } else {
5490
- console.warn(`[${this.metadata.name}] Unexpected type in signTxnsResult`, value);
5709
+ this.logger.warn("Unexpected type in signTxnsResult", value);
5491
5710
  signedTxn = new Uint8Array();
5492
5711
  }
5493
5712
  acc.push(signedTxn);
@@ -5505,12 +5724,10 @@ var WalletConnect = class extends BaseWallet {
5505
5724
  }
5506
5725
  return acc;
5507
5726
  }, []);
5727
+ this.logger.debug("Transactions signed successfully", result);
5508
5728
  return result;
5509
5729
  } catch (error) {
5510
- if (error instanceof SessionError) {
5511
- this.onDisconnect();
5512
- }
5513
- console.error(`[${this.metadata.name}] Error signing transactions:`, error);
5730
+ this.logger.error("Error signing transactions:", error.message);
5514
5731
  throw error;
5515
5732
  }
5516
5733
  };
@@ -5637,7 +5854,8 @@ var CustomWallet = class extends BaseWallet {
5637
5854
  }) {
5638
5855
  super({ id, metadata, getAlgodClient, store, subscribe });
5639
5856
  if (!options?.provider) {
5640
- throw new Error(`[${this.metadata.name}] Missing required option: provider`);
5857
+ this.logger.error("Missing required option: provider");
5858
+ throw new Error("Missing required option: provider");
5641
5859
  }
5642
5860
  this.provider = options.provider;
5643
5861
  this.store = store;
@@ -5647,13 +5865,15 @@ var CustomWallet = class extends BaseWallet {
5647
5865
  icon: ICON11
5648
5866
  };
5649
5867
  connect = async (args) => {
5650
- console.info(`[${this.metadata.name}] Connecting...`);
5868
+ this.logger.info("Connecting...");
5651
5869
  try {
5652
5870
  if (!this.provider.connect) {
5653
- throw new Error(`[${this.metadata.name}] Method not supported: connect`);
5871
+ this.logger.error("Method not supported: connect");
5872
+ throw new Error("Method not supported: connect");
5654
5873
  }
5655
5874
  const walletAccounts = await this.provider.connect(args);
5656
5875
  if (walletAccounts.length === 0) {
5876
+ this.logger.error("No accounts found!");
5657
5877
  throw new Error("No accounts found!");
5658
5878
  }
5659
5879
  const activeAccount = walletAccounts[0];
@@ -5665,15 +5885,15 @@ var CustomWallet = class extends BaseWallet {
5665
5885
  walletId: this.id,
5666
5886
  wallet: walletState
5667
5887
  });
5668
- console.info(`[${this.metadata.name}] \u2705 Connected.`, walletState);
5888
+ this.logger.info("\u2705 Connected.", walletState);
5669
5889
  return walletAccounts;
5670
5890
  } catch (error) {
5671
- console.error(`[${this.metadata.name}] Error connecting:`, error.message || error);
5891
+ this.logger.error("Error connecting:", error.message || error);
5672
5892
  throw error;
5673
5893
  }
5674
5894
  };
5675
5895
  disconnect = async () => {
5676
- console.info(`[${this.metadata.name}] Disconnecting...`);
5896
+ this.logger.info("Disconnecting...");
5677
5897
  this.onDisconnect();
5678
5898
  await this.provider.disconnect?.();
5679
5899
  };
@@ -5682,18 +5902,20 @@ var CustomWallet = class extends BaseWallet {
5682
5902
  const state = this.store.state;
5683
5903
  const walletState = state.wallets[this.id];
5684
5904
  if (!walletState) {
5905
+ this.logger.info("No session to resume");
5685
5906
  return;
5686
5907
  }
5687
- console.info(`[${this.metadata.name}] Resuming session...`);
5908
+ this.logger.info("Resuming session...");
5688
5909
  const result = await this.provider.resumeSession?.();
5689
5910
  if (Array.isArray(result)) {
5690
5911
  const walletAccounts = result;
5691
5912
  if (walletAccounts.length === 0) {
5692
- throw new Error(`[${this.metadata.name}] No accounts found!`);
5913
+ this.logger.error("No accounts found!");
5914
+ throw new Error("No accounts found!");
5693
5915
  }
5694
5916
  const match = compareAccounts(walletAccounts, walletState.accounts);
5695
5917
  if (!match) {
5696
- console.warn(`[${this.metadata.name}] Session accounts mismatch, updating accounts`, {
5918
+ this.logger.warn("Session accounts mismatch, updating accounts", {
5697
5919
  prev: walletState.accounts,
5698
5920
  current: walletAccounts
5699
5921
  });
@@ -5703,22 +5925,26 @@ var CustomWallet = class extends BaseWallet {
5703
5925
  });
5704
5926
  }
5705
5927
  }
5706
- console.info(`[${this.metadata.name}] Session resumed.`);
5928
+ this.logger.info("Session resumed.");
5707
5929
  } catch (error) {
5708
- console.error(`[${this.metadata.name}] Error resuming session:`, error.message);
5930
+ this.logger.error("Error resuming session:", error.message);
5709
5931
  throw error;
5710
5932
  }
5711
5933
  };
5712
5934
  signTransactions = async (txnGroup, indexesToSign) => {
5713
5935
  if (!this.provider.signTransactions) {
5714
- throw new Error(`[${this.metadata.name}] Method not supported: signTransactions`);
5936
+ this.logger.error("Method not supported: signTransactions");
5937
+ throw new Error("Method not supported: signTransactions");
5715
5938
  }
5939
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
5716
5940
  return await this.provider.signTransactions(txnGroup, indexesToSign);
5717
5941
  };
5718
5942
  transactionSigner = async (txnGroup, indexesToSign) => {
5719
5943
  if (!this.provider.transactionSigner) {
5720
- throw new Error(`[${this.metadata.name}] Method not supported: transactionSigner`);
5944
+ this.logger.error("Method not supported: transactionSigner");
5945
+ throw new Error("Method not supported: transactionSigner");
5721
5946
  }
5947
+ this.logger.debug("Transaction signer called...", { txnGroup, indexesToSign });
5722
5948
  return await this.provider.transactionSigner(txnGroup, indexesToSign);
5723
5949
  };
5724
5950
  };
@@ -5768,12 +5994,12 @@ function setActiveAccount(store, { walletId, address }) {
5768
5994
  store.setState((state) => {
5769
5995
  const wallet = state.wallets[walletId];
5770
5996
  if (!wallet) {
5771
- console.warn(`Wallet with id "${walletId}" not found`);
5997
+ logger.warn(`Wallet with id "${walletId}" not found`);
5772
5998
  return state;
5773
5999
  }
5774
6000
  const newActiveAccount = wallet.accounts.find((a2) => a2.address === address);
5775
6001
  if (!newActiveAccount) {
5776
- console.warn(`Account with address ${address} not found in wallet "${walletId}"`);
6002
+ logger.warn(`Account with address ${address} not found in wallet "${walletId}"`);
5777
6003
  return state;
5778
6004
  }
5779
6005
  const updatedWallet = {
@@ -5795,7 +6021,7 @@ function setAccounts(store, { walletId, accounts }) {
5795
6021
  store.setState((state) => {
5796
6022
  const wallet = state.wallets[walletId];
5797
6023
  if (!wallet) {
5798
- console.warn(`Wallet with id "${walletId}" not found`);
6024
+ logger.warn(`Wallet with id "${walletId}" not found`);
5799
6025
  return state;
5800
6026
  }
5801
6027
  const newAccounts = accounts.map((account) => ({ ...account }));
@@ -5852,17 +6078,25 @@ var WalletManager = class {
5852
6078
  store;
5853
6079
  subscribe;
5854
6080
  options;
6081
+ logger;
5855
6082
  constructor({
5856
6083
  wallets = [],
5857
6084
  network = "testnet" /* TESTNET */,
5858
6085
  algod = {},
5859
6086
  options = {}
5860
6087
  } = {}) {
6088
+ this.logger = this.initializeLogger(options);
6089
+ this.logger.debug("Initializing WalletManager with config:", {
6090
+ wallets,
6091
+ network,
6092
+ algod,
6093
+ options
6094
+ });
5861
6095
  this.networkConfig = this.initNetworkConfig(network, algod);
5862
6096
  this.options = { resetNetwork: options.resetNetwork || false };
5863
6097
  const persistedState = this.loadPersistedState();
5864
6098
  const activeNetwork = this.options.resetNetwork ? network : persistedState?.activeNetwork || network;
5865
- const algodClient = this.createAlgodClient(this.networkConfig[activeNetwork]);
6099
+ const algodClient = this.createAlgodClient(activeNetwork);
5866
6100
  const initialState = {
5867
6101
  ...defaultState,
5868
6102
  ...persistedState,
@@ -5881,6 +6115,18 @@ var WalletManager = class {
5881
6115
  };
5882
6116
  this.initializeWallets(wallets);
5883
6117
  }
6118
+ // ---------- Logging ----------------------------------------------- //
6119
+ initializeLogger(options) {
6120
+ const logLevel = this.determineLogLevel(options);
6121
+ Logger.setLevel(logLevel);
6122
+ return logger.createScopedLogger("WalletManager");
6123
+ }
6124
+ determineLogLevel(options) {
6125
+ if (options?.debug) {
6126
+ return 0 /* DEBUG */;
6127
+ }
6128
+ return options?.logLevel !== void 0 ? options.logLevel : 2 /* WARN */;
6129
+ }
5884
6130
  // ---------- Store ------------------------------------------------- //
5885
6131
  get algodClient() {
5886
6132
  return this.store.state.algodClient;
@@ -5899,12 +6145,12 @@ var WalletManager = class {
5899
6145
  }
5900
6146
  const parsedState = JSON.parse(serializedState);
5901
6147
  if (!isValidState(parsedState)) {
5902
- console.warn("[Store] Parsed state:", parsedState);
6148
+ this.logger.warn("Parsed state:", parsedState);
5903
6149
  throw new Error("Persisted state is invalid");
5904
6150
  }
5905
6151
  return parsedState;
5906
6152
  } catch (error) {
5907
- console.error(`[Store] Could not load state from local storage: ${error.message}`);
6153
+ this.logger.error(`Could not load state from local storage: ${error.message}`);
5908
6154
  return null;
5909
6155
  }
5910
6156
  }
@@ -5915,12 +6161,12 @@ var WalletManager = class {
5915
6161
  const serializedState = JSON.stringify(persistedState);
5916
6162
  StorageAdapter.setItem(LOCAL_STORAGE_KEY, serializedState);
5917
6163
  } catch (error) {
5918
- console.error("[Store] Could not save state to local storage:", error);
6164
+ this.logger.error("Could not save state to local storage:", error);
5919
6165
  }
5920
6166
  }
5921
6167
  // ---------- Wallets ----------------------------------------------- //
5922
6168
  initializeWallets(walletsConfig) {
5923
- console.info("[Manager] Initializing wallets...");
6169
+ this.logger.info("Initializing wallets...");
5924
6170
  for (const walletConfig of walletsConfig) {
5925
6171
  let walletId;
5926
6172
  let walletOptions;
@@ -5936,7 +6182,7 @@ var WalletManager = class {
5936
6182
  const walletMap = createWalletMap();
5937
6183
  const WalletClass = walletMap[walletId];
5938
6184
  if (!WalletClass) {
5939
- console.error(`[Manager] Wallet not found: ${walletId}`);
6185
+ this.logger.error(`Wallet not found: ${walletId}`);
5940
6186
  continue;
5941
6187
  }
5942
6188
  const walletInstance = new WalletClass({
@@ -5948,18 +6194,18 @@ var WalletManager = class {
5948
6194
  subscribe: this.subscribe
5949
6195
  });
5950
6196
  this._clients.set(walletId, walletInstance);
5951
- console.info(`[Manager] \u2705 Initialized ${walletId}`);
6197
+ this.logger.info(`\u2705 Initialized ${walletId}`);
5952
6198
  }
5953
6199
  const state = this.store.state;
5954
6200
  const connectedWallets = Object.keys(state.wallets);
5955
6201
  for (const walletId of connectedWallets) {
5956
6202
  if (!this._clients.has(walletId)) {
5957
- console.warn(`[Manager] Connected wallet not found: ${walletId}`);
6203
+ this.logger.warn(`Connected wallet not found: ${walletId}`);
5958
6204
  removeWallet(this.store, { walletId });
5959
6205
  }
5960
6206
  }
5961
6207
  if (state.activeWallet && !this._clients.has(state.activeWallet)) {
5962
- console.warn(`[Manager] Active wallet not found: ${state.activeWallet}`);
6208
+ this.logger.warn(`Active wallet not found: ${state.activeWallet}`);
5963
6209
  setActiveWallet(this.store, { walletId: null });
5964
6210
  }
5965
6211
  }
@@ -5979,19 +6225,19 @@ var WalletManager = class {
5979
6225
  }
5980
6226
  // ---------- Network ----------------------------------------------- //
5981
6227
  initNetworkConfig(network, config) {
5982
- console.info("[Manager] Initializing network...");
6228
+ this.logger.info("Initializing network...");
5983
6229
  let networkConfig = createDefaultNetworkConfig();
5984
6230
  if (isNetworkConfigMap(config)) {
5985
6231
  networkConfig = deepMerge(networkConfig, config);
5986
6232
  } else {
5987
6233
  networkConfig[network] = deepMerge(networkConfig[network], config);
5988
6234
  }
5989
- console.info("[Manager] Algodv2 config:", networkConfig);
6235
+ this.logger.debug("Algodv2 config:", networkConfig);
5990
6236
  return networkConfig;
5991
6237
  }
5992
- createAlgodClient(config) {
5993
- if (this.store) console.info(`[Manager] Creating Algodv2 client for ${this.activeNetwork}...`);
5994
- const { token = "", baseServer, port = "", headers = {} } = config;
6238
+ createAlgodClient(networkId) {
6239
+ this.logger.info(`Creating Algodv2 client for ${networkId}...`);
6240
+ const { token = "", baseServer, port = "", headers = {} } = this.networkConfig[networkId];
5995
6241
  return new import_algosdk12.default.Algodv2(token, baseServer, port, headers);
5996
6242
  }
5997
6243
  getAlgodClient = () => {
@@ -6001,9 +6247,9 @@ var WalletManager = class {
6001
6247
  if (this.activeNetwork === networkId) {
6002
6248
  return;
6003
6249
  }
6004
- const algodClient = this.createAlgodClient(this.networkConfig[networkId]);
6250
+ const algodClient = this.createAlgodClient(networkId);
6005
6251
  setActiveNetwork(this.store, { networkId, algodClient });
6006
- console.info(`[Manager] \u2705 Active network set to ${networkId}.`);
6252
+ this.logger.info(`\u2705 Active network set to ${networkId}.`);
6007
6253
  };
6008
6254
  get activeNetwork() {
6009
6255
  return this.store.state.activeNetwork;
@@ -6044,13 +6290,15 @@ var WalletManager = class {
6044
6290
  // ---------- Sign Transactions ------------------------------------- //
6045
6291
  get signTransactions() {
6046
6292
  if (!this.activeWallet) {
6047
- throw new Error("[Manager] No active wallet found!");
6293
+ this.logger.error("No active wallet found!");
6294
+ throw new Error("No active wallet found!");
6048
6295
  }
6049
6296
  return this.activeWallet.signTransactions;
6050
6297
  }
6051
6298
  get transactionSigner() {
6052
6299
  if (!this.activeWallet) {
6053
- throw new Error("[Manager] No active wallet found!");
6300
+ this.logger.error("No active wallet found!");
6301
+ throw new Error("No active wallet found!");
6054
6302
  }
6055
6303
  return this.activeWallet.transactionSigner;
6056
6304
  }
@@ -6066,6 +6314,7 @@ var WalletManager = class {
6066
6314
  KibisisWallet,
6067
6315
  KmdWallet,
6068
6316
  LOCAL_STORAGE_MNEMONIC_KEY,
6317
+ LogLevel,
6069
6318
  MagicAuth,
6070
6319
  MnemonicWallet,
6071
6320
  NetworkId,