@txnlab/use-wallet 3.6.0 → 3.7.1

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
@@ -3247,7 +3247,7 @@ __export(src_exports, {
3247
3247
  CustomWallet: () => CustomWallet,
3248
3248
  DeflyWallet: () => DeflyWallet,
3249
3249
  ExodusWallet: () => ExodusWallet,
3250
- ICON: () => ICON5,
3250
+ ICON: () => ICON6,
3251
3251
  KIBISIS_AVM_WEB_PROVIDER_ID: () => KIBISIS_AVM_WEB_PROVIDER_ID,
3252
3252
  KibisisWallet: () => KibisisWallet,
3253
3253
  KmdWallet: () => KmdWallet,
@@ -3409,10 +3409,168 @@ var StorageAdapter = class {
3409
3409
  }
3410
3410
  localStorage.setItem(key, value);
3411
3411
  }
3412
+ static removeItem(key) {
3413
+ if (typeof window === "undefined") {
3414
+ return;
3415
+ }
3416
+ localStorage.removeItem(key);
3417
+ }
3412
3418
  };
3413
3419
 
3414
3420
  // src/store.ts
3415
- var import_algosdk11 = __toESM(require("algosdk"), 1);
3421
+ var import_algosdk = __toESM(require("algosdk"), 1);
3422
+
3423
+ // src/wallets/types.ts
3424
+ var WalletId = /* @__PURE__ */ ((WalletId2) => {
3425
+ WalletId2["BIATEC"] = "biatec";
3426
+ WalletId2["DEFLY"] = "defly";
3427
+ WalletId2["CUSTOM"] = "custom";
3428
+ WalletId2["EXODUS"] = "exodus";
3429
+ WalletId2["KIBISIS"] = "kibisis";
3430
+ WalletId2["KMD"] = "kmd";
3431
+ WalletId2["LUTE"] = "lute";
3432
+ WalletId2["MAGIC"] = "magic";
3433
+ WalletId2["MNEMONIC"] = "mnemonic";
3434
+ WalletId2["PERA"] = "pera";
3435
+ WalletId2["PERA2"] = "pera-beta";
3436
+ WalletId2["WALLETCONNECT"] = "walletconnect";
3437
+ return WalletId2;
3438
+ })(WalletId || {});
3439
+ var SignTxnsError = class extends Error {
3440
+ code;
3441
+ data;
3442
+ constructor(message, code, data) {
3443
+ super(message);
3444
+ this.name = "SignTxnsError";
3445
+ this.code = code;
3446
+ this.data = data;
3447
+ }
3448
+ };
3449
+
3450
+ // src/store.ts
3451
+ var defaultState = {
3452
+ wallets: {},
3453
+ activeWallet: null,
3454
+ activeNetwork: "testnet" /* TESTNET */,
3455
+ algodClient: new import_algosdk.default.Algodv2("", "https://testnet-api.4160.nodely.dev/")
3456
+ };
3457
+ var LOCAL_STORAGE_KEY = "@txnlab/use-wallet:v3";
3458
+ function addWallet(store, { walletId, wallet }) {
3459
+ store.setState((state) => {
3460
+ const updatedWallets = {
3461
+ ...state.wallets,
3462
+ [walletId]: {
3463
+ accounts: wallet.accounts.map((account) => ({ ...account })),
3464
+ activeAccount: wallet.activeAccount ? { ...wallet.activeAccount } : null
3465
+ }
3466
+ };
3467
+ return {
3468
+ ...state,
3469
+ wallets: updatedWallets,
3470
+ activeWallet: walletId
3471
+ };
3472
+ });
3473
+ }
3474
+ function removeWallet(store, { walletId }) {
3475
+ store.setState((state) => {
3476
+ const updatedWallets = { ...state.wallets };
3477
+ delete updatedWallets[walletId];
3478
+ return {
3479
+ ...state,
3480
+ wallets: updatedWallets,
3481
+ activeWallet: state.activeWallet === walletId ? null : state.activeWallet
3482
+ };
3483
+ });
3484
+ }
3485
+ function setActiveWallet(store, { walletId }) {
3486
+ store.setState((state) => ({
3487
+ ...state,
3488
+ activeWallet: walletId
3489
+ }));
3490
+ }
3491
+ function setActiveAccount(store, { walletId, address }) {
3492
+ store.setState((state) => {
3493
+ const wallet = state.wallets[walletId];
3494
+ if (!wallet) {
3495
+ logger.warn(`Wallet with id "${walletId}" not found`);
3496
+ return state;
3497
+ }
3498
+ const newActiveAccount = wallet.accounts.find((a2) => a2.address === address);
3499
+ if (!newActiveAccount) {
3500
+ logger.warn(`Account with address ${address} not found in wallet "${walletId}"`);
3501
+ return state;
3502
+ }
3503
+ const updatedWallet = {
3504
+ ...wallet,
3505
+ accounts: wallet.accounts.map((account) => ({ ...account })),
3506
+ activeAccount: { ...newActiveAccount }
3507
+ };
3508
+ const updatedWallets = {
3509
+ ...state.wallets,
3510
+ [walletId]: updatedWallet
3511
+ };
3512
+ return {
3513
+ ...state,
3514
+ wallets: updatedWallets
3515
+ };
3516
+ });
3517
+ }
3518
+ function setAccounts(store, { walletId, accounts }) {
3519
+ store.setState((state) => {
3520
+ const wallet = state.wallets[walletId];
3521
+ if (!wallet) {
3522
+ logger.warn(`Wallet with id "${walletId}" not found`);
3523
+ return state;
3524
+ }
3525
+ const newAccounts = accounts.map((account) => ({ ...account }));
3526
+ const isActiveAccountConnected = newAccounts.some(
3527
+ (account) => account.address === wallet.activeAccount?.address
3528
+ );
3529
+ const newActiveAccount = isActiveAccountConnected ? { ...wallet.activeAccount } : newAccounts[0] || null;
3530
+ const updatedWallet = {
3531
+ ...wallet,
3532
+ accounts: newAccounts,
3533
+ activeAccount: newActiveAccount
3534
+ };
3535
+ const updatedWallets = {
3536
+ ...state.wallets,
3537
+ [walletId]: updatedWallet
3538
+ };
3539
+ return {
3540
+ ...state,
3541
+ wallets: updatedWallets
3542
+ };
3543
+ });
3544
+ }
3545
+ function setActiveNetwork(store, { networkId, algodClient }) {
3546
+ store.setState((state) => ({
3547
+ ...state,
3548
+ activeNetwork: networkId,
3549
+ algodClient
3550
+ }));
3551
+ }
3552
+ function isValidWalletId(walletId) {
3553
+ return Object.values(WalletId).includes(walletId);
3554
+ }
3555
+ function isValidWalletAccount(account) {
3556
+ return typeof account === "object" && account !== null && typeof account.name === "string" && typeof account.address === "string";
3557
+ }
3558
+ function isValidWalletState(wallet) {
3559
+ return typeof wallet === "object" && wallet !== null && Array.isArray(wallet.accounts) && wallet.accounts.every(isValidWalletAccount) && (wallet.activeAccount === null || isValidWalletAccount(wallet.activeAccount));
3560
+ }
3561
+ function isValidState(state) {
3562
+ if (!state || typeof state !== "object") return false;
3563
+ if (typeof state.wallets !== "object") return false;
3564
+ for (const [walletId, wallet] of Object.entries(state.wallets)) {
3565
+ if (!isValidWalletId(walletId) || !isValidWalletState(wallet)) return false;
3566
+ }
3567
+ if (state.activeWallet !== null && !isValidWalletId(state.activeWallet)) return false;
3568
+ if (!isValidNetworkId(state.activeNetwork)) return false;
3569
+ return true;
3570
+ }
3571
+
3572
+ // src/wallets/walletconnect.ts
3573
+ var import_algosdk2 = __toESM(require("algosdk"), 1);
3416
3574
 
3417
3575
  // src/wallets/base.ts
3418
3576
  var BaseWallet = class {
@@ -3497,37 +3655,27 @@ var BaseWallet = class {
3497
3655
  this.logger.debug(`Removing wallet from store...`);
3498
3656
  removeWallet(this.store, { walletId: this.id });
3499
3657
  };
3500
- };
3501
-
3502
- // src/wallets/types.ts
3503
- var WalletId = /* @__PURE__ */ ((WalletId2) => {
3504
- WalletId2["BIATEC"] = "biatec";
3505
- WalletId2["DEFLY"] = "defly";
3506
- WalletId2["CUSTOM"] = "custom";
3507
- WalletId2["EXODUS"] = "exodus";
3508
- WalletId2["KIBISIS"] = "kibisis";
3509
- WalletId2["KMD"] = "kmd";
3510
- WalletId2["LUTE"] = "lute";
3511
- WalletId2["MAGIC"] = "magic";
3512
- WalletId2["MNEMONIC"] = "mnemonic";
3513
- WalletId2["PERA"] = "pera";
3514
- WalletId2["PERA2"] = "pera-beta";
3515
- WalletId2["WALLETCONNECT"] = "walletconnect";
3516
- return WalletId2;
3517
- })(WalletId || {});
3518
- var SignTxnsError = class extends Error {
3519
- code;
3520
- data;
3521
- constructor(message, code, data) {
3522
- super(message);
3523
- this.name = "SignTxnsError";
3524
- this.code = code;
3525
- this.data = data;
3526
- }
3658
+ manageWalletConnectSession = (action, targetWalletId) => {
3659
+ const walletId = targetWalletId || this.id;
3660
+ if (action === "backup") {
3661
+ const data = StorageAdapter.getItem("walletconnect");
3662
+ if (data) {
3663
+ StorageAdapter.setItem(`walletconnect-${walletId}`, data);
3664
+ StorageAdapter.removeItem("walletconnect");
3665
+ this.logger.debug(`Backed up WalletConnect session for ${walletId}`);
3666
+ }
3667
+ } else if (action === "restore") {
3668
+ const data = StorageAdapter.getItem(`walletconnect-${walletId}`);
3669
+ if (data) {
3670
+ StorageAdapter.setItem("walletconnect", data);
3671
+ StorageAdapter.removeItem(`walletconnect-${walletId}`);
3672
+ this.logger.debug(`Restored WalletConnect session for ${walletId}`);
3673
+ }
3674
+ }
3675
+ };
3527
3676
  };
3528
3677
 
3529
3678
  // src/wallets/walletconnect.ts
3530
- var import_algosdk = __toESM(require("algosdk"), 1);
3531
3679
  var SessionError = class extends Error {
3532
3680
  constructor(message) {
3533
3681
  super(message);
@@ -3853,7 +4001,7 @@ var WalletConnect = class extends BaseWallet {
3853
4001
  const txnsToSign = [];
3854
4002
  txnGroup.forEach((txn, index) => {
3855
4003
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
3856
- const signer = import_algosdk.default.encodeAddress(txn.from.publicKey);
4004
+ const signer = import_algosdk2.default.encodeAddress(txn.from.publicKey);
3857
4005
  const canSignTxn = this.addresses.includes(signer);
3858
4006
  const txnString = byteArrayToBase64(txn.toByte());
3859
4007
  if (isIndexMatch && canSignTxn) {
@@ -3867,11 +4015,11 @@ var WalletConnect = class extends BaseWallet {
3867
4015
  processEncodedTxns(txnGroup, indexesToSign) {
3868
4016
  const txnsToSign = [];
3869
4017
  txnGroup.forEach((txnBuffer, index) => {
3870
- const txnDecodeObj = import_algosdk.default.decodeObj(txnBuffer);
4018
+ const txnDecodeObj = import_algosdk2.default.decodeObj(txnBuffer);
3871
4019
  const isSigned = isSignedTxn(txnDecodeObj);
3872
- const txn = isSigned ? import_algosdk.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk.default.decodeUnsignedTransaction(txnBuffer);
4020
+ const txn = isSigned ? import_algosdk2.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk2.default.decodeUnsignedTransaction(txnBuffer);
3873
4021
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
3874
- const signer = import_algosdk.default.encodeAddress(txn.from.publicKey);
4022
+ const signer = import_algosdk2.default.encodeAddress(txn.from.publicKey);
3875
4023
  const canSignTxn = !isSigned && this.addresses.includes(signer);
3876
4024
  const txnString = byteArrayToBase64(txn.toByte());
3877
4025
  if (isIndexMatch && canSignTxn) {
@@ -3954,75 +4102,211 @@ var BiatecWallet = class extends WalletConnect {
3954
4102
  };
3955
4103
  };
3956
4104
 
3957
- // src/wallets/defly.ts
3958
- var import_algosdk2 = __toESM(require("algosdk"), 1);
4105
+ // src/wallets/custom.ts
3959
4106
  var ICON3 = `data:image/svg+xml;base64,${btoa(`
3960
- <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
3961
- <rect width="1024" height="1024" />
3962
- <path fill="#FFFFFF" d="M779.9,684.4L512,230L244.1,684.4L512,529.5L779.9,684.4z" />
3963
- <path fill="#FFFFFF" d="M733.1,730L512,613.5L290.9,730L512,658L733.1,730z" />
4107
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4108
+ <rect width="24" height="24" fill="#525252" />
3964
4109
  </svg>
3965
4110
  `)}`;
3966
- var DeflyWallet = class extends BaseWallet {
3967
- client = null;
3968
- options;
4111
+ var CustomWallet = class extends BaseWallet {
4112
+ provider;
3969
4113
  store;
3970
4114
  constructor({
3971
4115
  id,
3972
4116
  store,
3973
4117
  subscribe,
3974
4118
  getAlgodClient,
3975
- options = {},
4119
+ options,
3976
4120
  metadata = {}
3977
4121
  }) {
3978
4122
  super({ id, metadata, getAlgodClient, store, subscribe });
3979
- this.options = options;
4123
+ if (!options?.provider) {
4124
+ this.logger.error("Missing required option: provider");
4125
+ throw new Error("Missing required option: provider");
4126
+ }
4127
+ this.provider = options.provider;
3980
4128
  this.store = store;
3981
4129
  }
3982
4130
  static defaultMetadata = {
3983
- name: "Defly",
4131
+ name: "Custom",
3984
4132
  icon: ICON3
3985
4133
  };
3986
- async initializeClient() {
3987
- this.logger.info("Initializing client...");
3988
- const module2 = await import("@blockshake/defly-connect");
3989
- const DeflyWalletConnect = module2.default ? module2.default.DeflyWalletConnect : module2.DeflyWalletConnect;
3990
- const client = new DeflyWalletConnect(this.options);
3991
- this.client = client;
3992
- this.logger.info("Client initialized");
3993
- return client;
3994
- }
3995
- connect = async () => {
4134
+ connect = async (args) => {
3996
4135
  this.logger.info("Connecting...");
3997
- const client = this.client || await this.initializeClient();
3998
- const accounts = await client.connect();
3999
- client.connector?.on("disconnect", this.onDisconnect);
4000
- if (accounts.length === 0) {
4001
- this.logger.error("No accounts found!");
4002
- throw new Error("No accounts found!");
4003
- }
4004
- const walletAccounts = accounts.map((address, idx) => ({
4005
- name: `${this.metadata.name} Account ${idx + 1}`,
4006
- address
4007
- }));
4008
- const activeAccount = walletAccounts[0];
4009
- const walletState = {
4010
- accounts: walletAccounts,
4011
- activeAccount
4012
- };
4013
- addWallet(this.store, {
4014
- walletId: this.id,
4015
- wallet: walletState
4016
- });
4017
- this.logger.info("\u2705 Connected.", walletState);
4018
- return walletAccounts;
4019
- };
4020
- disconnect = async () => {
4021
- this.logger.info("Disconnecting...");
4022
- this.onDisconnect();
4023
- const client = this.client || await this.initializeClient();
4024
- await client.disconnect();
4025
- this.logger.info("Disconnected.");
4136
+ try {
4137
+ if (!this.provider.connect) {
4138
+ this.logger.error("Method not supported: connect");
4139
+ throw new Error("Method not supported: connect");
4140
+ }
4141
+ const walletAccounts = await this.provider.connect(args);
4142
+ if (walletAccounts.length === 0) {
4143
+ this.logger.error("No accounts found!");
4144
+ throw new Error("No accounts found!");
4145
+ }
4146
+ const activeAccount = walletAccounts[0];
4147
+ const walletState = {
4148
+ accounts: walletAccounts,
4149
+ activeAccount
4150
+ };
4151
+ addWallet(this.store, {
4152
+ walletId: this.id,
4153
+ wallet: walletState
4154
+ });
4155
+ this.logger.info("\u2705 Connected.", walletState);
4156
+ return walletAccounts;
4157
+ } catch (error) {
4158
+ this.logger.error("Error connecting:", error.message || error);
4159
+ throw error;
4160
+ }
4161
+ };
4162
+ disconnect = async () => {
4163
+ this.logger.info("Disconnecting...");
4164
+ this.onDisconnect();
4165
+ await this.provider.disconnect?.();
4166
+ };
4167
+ resumeSession = async () => {
4168
+ try {
4169
+ const state = this.store.state;
4170
+ const walletState = state.wallets[this.id];
4171
+ if (!walletState) {
4172
+ this.logger.info("No session to resume");
4173
+ return;
4174
+ }
4175
+ this.logger.info("Resuming session...");
4176
+ const result = await this.provider.resumeSession?.();
4177
+ if (Array.isArray(result)) {
4178
+ const walletAccounts = result;
4179
+ if (walletAccounts.length === 0) {
4180
+ this.logger.error("No accounts found!");
4181
+ throw new Error("No accounts found!");
4182
+ }
4183
+ const match = compareAccounts(walletAccounts, walletState.accounts);
4184
+ if (!match) {
4185
+ this.logger.warn("Session accounts mismatch, updating accounts", {
4186
+ prev: walletState.accounts,
4187
+ current: walletAccounts
4188
+ });
4189
+ setAccounts(this.store, {
4190
+ walletId: this.id,
4191
+ accounts: walletAccounts
4192
+ });
4193
+ }
4194
+ }
4195
+ this.logger.info("Session resumed.");
4196
+ } catch (error) {
4197
+ this.logger.error("Error resuming session:", error.message);
4198
+ throw error;
4199
+ }
4200
+ };
4201
+ signTransactions = async (txnGroup, indexesToSign) => {
4202
+ if (!this.provider.signTransactions) {
4203
+ this.logger.error("Method not supported: signTransactions");
4204
+ throw new Error("Method not supported: signTransactions");
4205
+ }
4206
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4207
+ return await this.provider.signTransactions(txnGroup, indexesToSign);
4208
+ };
4209
+ transactionSigner = async (txnGroup, indexesToSign) => {
4210
+ if (!this.provider.transactionSigner) {
4211
+ this.logger.error("Method not supported: transactionSigner");
4212
+ throw new Error("Method not supported: transactionSigner");
4213
+ }
4214
+ this.logger.debug("Transaction signer called...", { txnGroup, indexesToSign });
4215
+ return await this.provider.transactionSigner(txnGroup, indexesToSign);
4216
+ };
4217
+ };
4218
+
4219
+ // src/wallets/defly.ts
4220
+ var import_algosdk3 = __toESM(require("algosdk"), 1);
4221
+ var ICON4 = `data:image/svg+xml;base64,${btoa(`
4222
+ <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
4223
+ <rect width="1024" height="1024" />
4224
+ <path fill="#FFFFFF" d="M779.9,684.4L512,230L244.1,684.4L512,529.5L779.9,684.4z" />
4225
+ <path fill="#FFFFFF" d="M733.1,730L512,613.5L290.9,730L512,658L733.1,730z" />
4226
+ </svg>
4227
+ `)}`;
4228
+ var DeflyWallet = class extends BaseWallet {
4229
+ client = null;
4230
+ options;
4231
+ store;
4232
+ constructor({
4233
+ id,
4234
+ store,
4235
+ subscribe,
4236
+ getAlgodClient,
4237
+ options = {},
4238
+ metadata = {}
4239
+ }) {
4240
+ super({ id, metadata, getAlgodClient, store, subscribe });
4241
+ this.options = options;
4242
+ this.store = store;
4243
+ }
4244
+ static defaultMetadata = {
4245
+ name: "Defly",
4246
+ icon: ICON4
4247
+ };
4248
+ async initializeClient() {
4249
+ this.logger.info("Initializing client...");
4250
+ const module2 = await import("@blockshake/defly-connect");
4251
+ const DeflyWalletConnect = module2.default ? module2.default.DeflyWalletConnect : module2.DeflyWalletConnect;
4252
+ const client = new DeflyWalletConnect(this.options);
4253
+ this.client = client;
4254
+ this.logger.info("Client initialized");
4255
+ return client;
4256
+ }
4257
+ connect = async () => {
4258
+ this.logger.info("Connecting...");
4259
+ const currentActiveWallet = this.store.state.activeWallet;
4260
+ if (currentActiveWallet && currentActiveWallet !== this.id) {
4261
+ this.manageWalletConnectSession("backup", currentActiveWallet);
4262
+ }
4263
+ const client = this.client || await this.initializeClient();
4264
+ const accounts = await client.connect();
4265
+ client.connector?.on("disconnect", this.onDisconnect);
4266
+ if (accounts.length === 0) {
4267
+ this.logger.error("No accounts found!");
4268
+ throw new Error("No accounts found!");
4269
+ }
4270
+ const walletAccounts = accounts.map((address, idx) => ({
4271
+ name: `${this.metadata.name} Account ${idx + 1}`,
4272
+ address
4273
+ }));
4274
+ const activeAccount = walletAccounts[0];
4275
+ const walletState = {
4276
+ accounts: walletAccounts,
4277
+ activeAccount
4278
+ };
4279
+ addWallet(this.store, {
4280
+ walletId: this.id,
4281
+ wallet: walletState
4282
+ });
4283
+ this.logger.info("\u2705 Connected.", walletState);
4284
+ return walletAccounts;
4285
+ };
4286
+ disconnect = async () => {
4287
+ this.logger.info("Disconnecting...");
4288
+ const client = this.client || await this.initializeClient();
4289
+ const currentActiveWallet = this.store.state.activeWallet;
4290
+ if (currentActiveWallet && currentActiveWallet !== this.id) {
4291
+ this.manageWalletConnectSession("backup", currentActiveWallet);
4292
+ this.manageWalletConnectSession("restore", this.id);
4293
+ await client.disconnect();
4294
+ await new Promise((resolve) => setTimeout(resolve, 500));
4295
+ this.manageWalletConnectSession("restore", currentActiveWallet);
4296
+ } else {
4297
+ await client.disconnect();
4298
+ }
4299
+ this.onDisconnect();
4300
+ this.logger.info("Disconnected");
4301
+ };
4302
+ setActive = () => {
4303
+ this.logger.info(`Set active wallet: ${this.id}`);
4304
+ const currentActiveWallet = this.store.state.activeWallet;
4305
+ if (currentActiveWallet && currentActiveWallet !== this.id) {
4306
+ this.manageWalletConnectSession("backup", currentActiveWallet);
4307
+ }
4308
+ this.manageWalletConnectSession("restore");
4309
+ setActiveWallet(this.store, { walletId: this.id });
4026
4310
  };
4027
4311
  resumeSession = async () => {
4028
4312
  try {
@@ -4065,7 +4349,7 @@ var DeflyWallet = class extends BaseWallet {
4065
4349
  const txnsToSign = [];
4066
4350
  txnGroup.forEach((txn, index) => {
4067
4351
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4068
- const signer = import_algosdk2.default.encodeAddress(txn.from.publicKey);
4352
+ const signer = import_algosdk3.default.encodeAddress(txn.from.publicKey);
4069
4353
  const canSignTxn = this.addresses.includes(signer);
4070
4354
  if (isIndexMatch && canSignTxn) {
4071
4355
  txnsToSign.push({ txn });
@@ -4078,11 +4362,11 @@ var DeflyWallet = class extends BaseWallet {
4078
4362
  processEncodedTxns(txnGroup, indexesToSign) {
4079
4363
  const txnsToSign = [];
4080
4364
  txnGroup.forEach((txnBuffer, index) => {
4081
- const txnDecodeObj = import_algosdk2.default.decodeObj(txnBuffer);
4365
+ const txnDecodeObj = import_algosdk3.default.decodeObj(txnBuffer);
4082
4366
  const isSigned = isSignedTxn(txnDecodeObj);
4083
- const txn = isSigned ? import_algosdk2.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk2.default.decodeUnsignedTransaction(txnBuffer);
4367
+ const txn = isSigned ? import_algosdk3.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk3.default.decodeUnsignedTransaction(txnBuffer);
4084
4368
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4085
- const signer = import_algosdk2.default.encodeAddress(txn.from.publicKey);
4369
+ const signer = import_algosdk3.default.encodeAddress(txn.from.publicKey);
4086
4370
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4087
4371
  if (isIndexMatch && canSignTxn) {
4088
4372
  txnsToSign.push({ txn });
@@ -4128,8 +4412,8 @@ var DeflyWallet = class extends BaseWallet {
4128
4412
  };
4129
4413
 
4130
4414
  // src/wallets/exodus.ts
4131
- var import_algosdk3 = __toESM(require("algosdk"), 1);
4132
- var ICON4 = `data:image/svg+xml;base64,${btoa(`
4415
+ var import_algosdk4 = __toESM(require("algosdk"), 1);
4416
+ var ICON5 = `data:image/svg+xml;base64,${btoa(`
4133
4417
  <svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
4134
4418
  <linearGradient id="grad1" gradientUnits="userSpaceOnUse" x1="246.603" y1="9.2212" x2="174.158" y2="308.5426" gradientTransform="matrix(1 0 0 -1 0 302)">
4135
4419
  <stop offset="0" stop-color="#0B46F9" />
@@ -4173,7 +4457,7 @@ var ExodusWallet = class extends BaseWallet {
4173
4457
  }
4174
4458
  static defaultMetadata = {
4175
4459
  name: "Exodus",
4176
- icon: ICON4
4460
+ icon: ICON5
4177
4461
  };
4178
4462
  async initializeClient() {
4179
4463
  this.logger.info("Initializing client...");
@@ -4240,7 +4524,7 @@ var ExodusWallet = class extends BaseWallet {
4240
4524
  const txnsToSign = [];
4241
4525
  txnGroup.forEach((txn, index) => {
4242
4526
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4243
- const signer = import_algosdk3.default.encodeAddress(txn.from.publicKey);
4527
+ const signer = import_algosdk4.default.encodeAddress(txn.from.publicKey);
4244
4528
  const canSignTxn = this.addresses.includes(signer);
4245
4529
  const txnString = byteArrayToBase64(txn.toByte());
4246
4530
  if (isIndexMatch && canSignTxn) {
@@ -4254,11 +4538,11 @@ var ExodusWallet = class extends BaseWallet {
4254
4538
  processEncodedTxns(txnGroup, indexesToSign) {
4255
4539
  const txnsToSign = [];
4256
4540
  txnGroup.forEach((txnBuffer, index) => {
4257
- const txnDecodeObj = import_algosdk3.default.decodeObj(txnBuffer);
4541
+ const txnDecodeObj = import_algosdk4.default.decodeObj(txnBuffer);
4258
4542
  const isSigned = isSignedTxn(txnDecodeObj);
4259
- const txn = isSigned ? import_algosdk3.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk3.default.decodeUnsignedTransaction(txnBuffer);
4543
+ const txn = isSigned ? import_algosdk4.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk4.default.decodeUnsignedTransaction(txnBuffer);
4260
4544
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4261
- const signer = import_algosdk3.default.encodeAddress(txn.from.publicKey);
4545
+ const signer = import_algosdk4.default.encodeAddress(txn.from.publicKey);
4262
4546
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4263
4547
  const txnString = byteArrayToBase64(txn.toByte());
4264
4548
  if (isIndexMatch && canSignTxn) {
@@ -4300,12 +4584,12 @@ var ExodusWallet = class extends BaseWallet {
4300
4584
  };
4301
4585
 
4302
4586
  // src/wallets/kibisis.ts
4303
- var import_algosdk4 = __toESM(require("algosdk"), 1);
4587
+ var import_algosdk5 = __toESM(require("algosdk"), 1);
4304
4588
  function isAVMWebProviderSDKError(error) {
4305
4589
  return typeof error === "object" && "code" in error && "message" in error;
4306
4590
  }
4307
4591
  var KIBISIS_AVM_WEB_PROVIDER_ID = "f6d1c86b-4493-42fb-b88d-a62407b4cdf6";
4308
- var ICON5 = `data:image/svg+xml;base64,${btoa(`
4592
+ var ICON6 = `data:image/svg+xml;base64,${btoa(`
4309
4593
  <svg viewBox="0 0 480 480" xmlns="http://www.w3.org/2000/svg">
4310
4594
  <rect fill="#801C96" width="480" height="480" />
4311
4595
  <path fill="#FFFFFF" d="M393.5,223.2c0-7.3-0.6-14.6-1.6-21.6c-0.9-6.5-2.3-12.8-4-18.9c-18-64.9-77.4-112.5-148-112.5c-70.6,0-130,47.6-148,112.5c-1.7,6.2-3,12.5-4,19c-1,7.1-1.6,14.3-1.6,21.6h0v85.5h19.7v-85.5c0-7.2,0.6-14.4,1.8-21.4c14,1.1,27.6,4.3,40.5,9.5c15.9,6.4,30.3,15.6,42.6,27.3c12.3,11.7,22,25.4,28.7,40.6c6.9,15.6,10.5,32.2,10.5,49.2v81.4h0.1h19.6h0.1v-81.5c0.1-17.1,3.6-33.7,10.5-49.2c6.7-15.2,16.4-28.8,28.7-40.6c4.2-4,8.6-7.7,13.2-11.1v132.2h19.7V223.2h0c0-2.5-0.1-5-0.4-7.4c3.3-1.6,6.6-3.1,10-4.5c12.9-5.2,26.4-8.4,40.4-9.5c1.2,7,1.7,14.2,1.8,21.4v85.5h19.7L393.5,223.2L393.5,223.2z M240.1,277.3c-11.6-29.3-32.7-54.1-59.8-71c2.9-10,8.2-19.1,15.8-26.6c11.8-11.8,27.4-18.2,44-18.2s32.3,6.5,44,18.2c4.1,4.1,7.5,8.7,10.3,13.6c5.6-3.4,11.4-6.4,17.4-9.2c-14-25.2-40.9-42.3-71.8-42.3c-35.9,0-66.3,23-77.5,55.1c-15.5-7.1-32.5-11.8-50.4-13.5c1.3-4,2.7-7.9,4.3-11.8c6.7-15.9,16.4-30.3,28.7-42.6s26.6-22,42.6-28.7c16.5-7,34-10.5,52.1-10.5s35.6,3.5,52.1,10.5c15.9,6.7,30.3,16.4,42.6,28.7s22,26.6,28.7,42.6c1.6,3.9,3.1,7.8,4.3,11.8C309,189.2,260.1,226.5,240.1,277.3z" />
@@ -4328,7 +4612,7 @@ var KibisisWallet = class extends BaseWallet {
4328
4612
  }
4329
4613
  static defaultMetadata = {
4330
4614
  name: "Kibisis",
4331
- icon: ICON5
4615
+ icon: ICON6
4332
4616
  };
4333
4617
  /**
4334
4618
  * private functions
@@ -4620,7 +4904,7 @@ var KibisisWallet = class extends BaseWallet {
4620
4904
  const txnsToSign = [];
4621
4905
  txnGroup.forEach((txn, index) => {
4622
4906
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4623
- const signer = import_algosdk4.default.encodeAddress(txn.from.publicKey);
4907
+ const signer = import_algosdk5.default.encodeAddress(txn.from.publicKey);
4624
4908
  const canSignTxn = this.addresses.includes(signer);
4625
4909
  const txnString = byteArrayToBase64(txn.toByte());
4626
4910
  if (isIndexMatch && canSignTxn) {
@@ -4634,11 +4918,11 @@ var KibisisWallet = class extends BaseWallet {
4634
4918
  processEncodedTxns(txnGroup, indexesToSign) {
4635
4919
  const txnsToSign = [];
4636
4920
  txnGroup.forEach((txnBuffer, index) => {
4637
- const txnDecodeObj = import_algosdk4.default.decodeObj(txnBuffer);
4921
+ const txnDecodeObj = import_algosdk5.default.decodeObj(txnBuffer);
4638
4922
  const isSigned = isSignedTxn(txnDecodeObj);
4639
- const txn = isSigned ? import_algosdk4.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk4.default.decodeUnsignedTransaction(txnBuffer);
4923
+ const txn = isSigned ? import_algosdk5.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk5.default.decodeUnsignedTransaction(txnBuffer);
4640
4924
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4641
- const signer = import_algosdk4.default.encodeAddress(txn.from.publicKey);
4925
+ const signer = import_algosdk5.default.encodeAddress(txn.from.publicKey);
4642
4926
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4643
4927
  const txnString = byteArrayToBase64(txn.toByte());
4644
4928
  if (isIndexMatch && canSignTxn) {
@@ -4682,8 +4966,8 @@ var KibisisWallet = class extends BaseWallet {
4682
4966
  };
4683
4967
 
4684
4968
  // src/wallets/kmd.ts
4685
- var import_algosdk5 = __toESM(require("algosdk"), 1);
4686
- var ICON6 = `data:image/svg+xml;base64,${btoa(`
4969
+ var import_algosdk6 = __toESM(require("algosdk"), 1);
4970
+ var ICON7 = `data:image/svg+xml;base64,${btoa(`
4687
4971
  <svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
4688
4972
  <linearGradient id="algokitGradient" gradientUnits="userSpaceOnUse" x1="0" y1="400" x2="400" y2="0">
4689
4973
  <stop offset="0" style="stop-color:#31D8EE"/>
@@ -4721,12 +5005,12 @@ var KmdWallet = class extends BaseWallet {
4721
5005
  }
4722
5006
  static defaultMetadata = {
4723
5007
  name: "KMD",
4724
- icon: ICON6
5008
+ icon: ICON7
4725
5009
  };
4726
5010
  async initializeClient() {
4727
5011
  this.logger.info("Initializing client...");
4728
5012
  const { token, baseServer, port } = this.options;
4729
- const client = new import_algosdk5.default.Kmd(token, baseServer, port);
5013
+ const client = new import_algosdk6.default.Kmd(token, baseServer, port);
4730
5014
  this.client = client;
4731
5015
  this.logger.info("Client initialized");
4732
5016
  return client;
@@ -4789,7 +5073,7 @@ var KmdWallet = class extends BaseWallet {
4789
5073
  const txnsToSign = [];
4790
5074
  txnGroup.forEach((txn, index) => {
4791
5075
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4792
- const signer = import_algosdk5.default.encodeAddress(txn.from.publicKey);
5076
+ const signer = import_algosdk6.default.encodeAddress(txn.from.publicKey);
4793
5077
  const canSignTxn = this.addresses.includes(signer);
4794
5078
  if (isIndexMatch && canSignTxn) {
4795
5079
  txnsToSign.push(txn);
@@ -4800,11 +5084,11 @@ var KmdWallet = class extends BaseWallet {
4800
5084
  processEncodedTxns(txnGroup, indexesToSign) {
4801
5085
  const txnsToSign = [];
4802
5086
  txnGroup.forEach((txnBuffer, index) => {
4803
- const txnDecodeObj = import_algosdk5.default.decodeObj(txnBuffer);
5087
+ const txnDecodeObj = import_algosdk6.default.decodeObj(txnBuffer);
4804
5088
  const isSigned = isSignedTxn(txnDecodeObj);
4805
- const txn = isSigned ? import_algosdk5.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk5.default.decodeUnsignedTransaction(txnBuffer);
5089
+ const txn = isSigned ? import_algosdk6.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk6.default.decodeUnsignedTransaction(txnBuffer);
4806
5090
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4807
- const signer = import_algosdk5.default.encodeAddress(txn.from.publicKey);
5091
+ const signer = import_algosdk6.default.encodeAddress(txn.from.publicKey);
4808
5092
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4809
5093
  if (isIndexMatch && canSignTxn) {
4810
5094
  txnsToSign.push(txn);
@@ -4888,11 +5172,11 @@ var KmdWallet = class extends BaseWallet {
4888
5172
  };
4889
5173
 
4890
5174
  // src/wallets/lute.ts
4891
- var import_algosdk6 = __toESM(require("algosdk"), 1);
5175
+ var import_algosdk7 = __toESM(require("algosdk"), 1);
4892
5176
  function isSignTxnsError(error) {
4893
5177
  return error instanceof Error && "code" in error;
4894
5178
  }
4895
- var ICON7 = `data:image/svg+xml;base64,${btoa(`
5179
+ var ICON8 = `data:image/svg+xml;base64,${btoa(`
4896
5180
  <svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
4897
5181
  <path fill="#AB47BC" d="M283.7,263.6c-0.6,0-1.3-0.1-1.8-0.4c-0.6-0.3-1.1-0.8-1.5-1.3c-0.4-0.6-0.7-1.3-0.8-2 c-0.1-0.8-0.1-1.7,0.1-2.5c0.2-0.9,0.6-1.8,1.2-2.6c0.6-0.8,1.4-1.7,2.2-2.3c0.9-0.7,2.1-1.2,3.2-1.6c1.2-0.4,2.7-0.5,4-0.5 c1.4,0,3,0.3,4.4,0.8c1.5,0.5,3.1,1.4,4.3,2.3c1.4,1,2.8,2.4,3.8,3.7c1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,11.3,4.9,16.3c2.2,4.8,5.4,10,8.7,14 c3.2,3.9,7.6,8,11.7,10.9c4,2.9,9.1,5.6,13.8,7.3c4.5,1.7,9.9,2.9,14.7,3.3c4.6,0.4,10,0.2,14.6-0.7c4.4-0.8,9.4-2.4,13.5-4.3 c3.9-1.9,8.2-4.6,11.5-7.5c3.2-2.7,6.4-6.4,8.8-9.9c2.3-3.4,4.4-7.6,5.7-11.4c1.2-3.7,2.1-8.1,2.3-12c0.2-3.7-0.1-8.1-0.9-11.8 c-0.8-3.5-2.2-7.5-3.8-10.7c-1.6-3.1-3.9-6.3-6.2-8.9c-2.2-2.4-5.2-4.9-8-6.6c-2.7-1.7-6-3.2-9.1-4c-2.9-0.8-6.3-1.4-9.3-1.4 c-2.9,0-6.2,0.4-8.9,1.1c-2.6,0.7-5.5,1.9-7.9,3.3c-2.2,1.3-4.5,3.2-6.3,5c-1.7,1.8-3.3,4-4.4,6.2c-1.1,2-2,4.5-2.4,6.7 c-0.4,2.1-0.6,4.5-0.4,6.7c0.2,2,0.6,4.2,1.3,6.1c0.6,1.7,1.7,3.6,2.8,5.1c1,1.3,2.4,2.7,3.8,3.7c1.3,0.9,2.8,1.8,4.3,2.3 c1.3,0.5,2.9,0.8,4.4,0.8c1.3,0,2.7-0.1,4-0.5c1.1-0.3,2.3-0.9,3.2-1.6c0.8-0.6,1.7-1.4,2.2-2.3c0.5-0.7,0.9-1.7,1.2-2.6 c0.2-0.8,0.2-1.7,0.1-2.5c-0.1-0.7-0.4-1.4-0.8-2c-0.4-0.5-0.9-1-1.5-1.3C285,263.7,284.3,263.6,283.7,263.6L283.7,263.6z" />
4898
5182
  </svg>
@@ -4919,7 +5203,7 @@ var LuteWallet = class extends BaseWallet {
4919
5203
  }
4920
5204
  static defaultMetadata = {
4921
5205
  name: "Lute",
4922
- icon: ICON7
5206
+ icon: ICON8
4923
5207
  };
4924
5208
  async initializeClient() {
4925
5209
  this.logger.info("Initializing client...");
@@ -4986,7 +5270,7 @@ var LuteWallet = class extends BaseWallet {
4986
5270
  const txnsToSign = [];
4987
5271
  txnGroup.forEach((txn, index) => {
4988
5272
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4989
- const signer = import_algosdk6.default.encodeAddress(txn.from.publicKey);
5273
+ const signer = import_algosdk7.default.encodeAddress(txn.from.publicKey);
4990
5274
  const canSignTxn = this.addresses.includes(signer);
4991
5275
  const txnString = byteArrayToBase64(txn.toByte());
4992
5276
  if (isIndexMatch && canSignTxn) {
@@ -5000,11 +5284,11 @@ var LuteWallet = class extends BaseWallet {
5000
5284
  processEncodedTxns(txnGroup, indexesToSign) {
5001
5285
  const txnsToSign = [];
5002
5286
  txnGroup.forEach((txnBuffer, index) => {
5003
- const txnDecodeObj = import_algosdk6.default.decodeObj(txnBuffer);
5287
+ const txnDecodeObj = import_algosdk7.default.decodeObj(txnBuffer);
5004
5288
  const isSigned = isSignedTxn(txnDecodeObj);
5005
- const txn = isSigned ? import_algosdk6.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk6.default.decodeUnsignedTransaction(txnBuffer);
5289
+ const txn = isSigned ? import_algosdk7.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk7.default.decodeUnsignedTransaction(txnBuffer);
5006
5290
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5007
- const signer = import_algosdk6.default.encodeAddress(txn.from.publicKey);
5291
+ const signer = import_algosdk7.default.encodeAddress(txn.from.publicKey);
5008
5292
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5009
5293
  const txnString = byteArrayToBase64(txn.toByte());
5010
5294
  if (isIndexMatch && canSignTxn) {
@@ -5043,8 +5327,8 @@ var LuteWallet = class extends BaseWallet {
5043
5327
  };
5044
5328
 
5045
5329
  // src/wallets/magic.ts
5046
- var import_algosdk7 = __toESM(require("algosdk"), 1);
5047
- var ICON8 = `data:image/svg+xml;base64,${btoa(`
5330
+ var import_algosdk8 = __toESM(require("algosdk"), 1);
5331
+ var ICON9 = `data:image/svg+xml;base64,${btoa(`
5048
5332
  <svg viewBox="0 0 47 47" xmlns="http://www.w3.org/2000/svg">
5049
5333
  <path fill="#6851FF" d="M 23.960861 1.80769 C 25.835077 4.103153 27.902216 6.23489 30.137539 8.178169 C 28.647968 13.009323 27.846092 18.142094 27.846092 23.462154 C 27.846092 28.782307 28.648062 33.915169 30.13763 38.746368 C 27.902216 40.689724 25.835077 42.821476 23.960861 45.116985 C 22.086554 42.821476 20.019415 40.689632 17.783998 38.746368 C 19.273476 33.915169 20.075445 28.7824 20.075445 23.462337 C 20.075445 18.142277 19.273476 13.009506 17.783998 8.178318 C 20.019415 6.235001 22.086554 4.10321 23.960861 1.80769 Z M 13.511427 35.406403 C 11.145139 33.747814 8.633816 32.282063 6.000269 31.031937 C 6.730776 28.637476 7.123754 26.095783 7.123754 23.462429 C 7.123754 20.828892 6.730762 18.287201 6.000235 15.892738 C 8.633816 14.642616 11.145175 13.176861 13.511501 11.518276 C 14.416311 15.352554 14.895074 19.351414 14.895074 23.462154 C 14.895074 27.572985 14.416283 31.571938 13.511427 35.406403 Z M 33.027046 23.462337 C 33.027046 27.572985 33.505753 31.571846 34.410553 35.406124 C 36.776859 33.747631 39.288094 32.281876 41.921539 31.031845 C 41.191017 28.637384 40.798061 26.095692 40.798061 23.462246 C 40.798061 20.8288 41.191017 18.287201 41.921539 15.89283 C 39.288094 14.642708 36.776768 13.177048 34.410553 11.518555 C 33.505753 15.352831 33.027046 19.351692 33.027046 23.462337 Z" />
5050
5334
  </svg>
@@ -5072,7 +5356,7 @@ var MagicAuth = class extends BaseWallet {
5072
5356
  }
5073
5357
  static defaultMetadata = {
5074
5358
  name: "Magic",
5075
- icon: ICON8
5359
+ icon: ICON9
5076
5360
  };
5077
5361
  async initializeClient() {
5078
5362
  this.logger.info("Initializing client...");
@@ -5190,7 +5474,7 @@ var MagicAuth = class extends BaseWallet {
5190
5474
  const txnsToSign = [];
5191
5475
  txnGroup.forEach((txn, index) => {
5192
5476
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5193
- const signer = import_algosdk7.default.encodeAddress(txn.from.publicKey);
5477
+ const signer = import_algosdk8.default.encodeAddress(txn.from.publicKey);
5194
5478
  const canSignTxn = this.addresses.includes(signer);
5195
5479
  const txnString = byteArrayToBase64(txn.toByte());
5196
5480
  if (isIndexMatch && canSignTxn) {
@@ -5204,11 +5488,11 @@ var MagicAuth = class extends BaseWallet {
5204
5488
  processEncodedTxns(txnGroup, indexesToSign) {
5205
5489
  const txnsToSign = [];
5206
5490
  txnGroup.forEach((txnBuffer, index) => {
5207
- const txnDecodeObj = import_algosdk7.default.decodeObj(txnBuffer);
5491
+ const txnDecodeObj = import_algosdk8.default.decodeObj(txnBuffer);
5208
5492
  const isSigned = isSignedTxn(txnDecodeObj);
5209
- const txn = isSigned ? import_algosdk7.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk7.default.decodeUnsignedTransaction(txnBuffer);
5493
+ const txn = isSigned ? import_algosdk8.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk8.default.decodeUnsignedTransaction(txnBuffer);
5210
5494
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5211
- const signer = import_algosdk7.default.encodeAddress(txn.from.publicKey);
5495
+ const signer = import_algosdk8.default.encodeAddress(txn.from.publicKey);
5212
5496
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5213
5497
  const txnString = byteArrayToBase64(txn.toByte());
5214
5498
  if (isIndexMatch && canSignTxn) {
@@ -5252,9 +5536,9 @@ var MagicAuth = class extends BaseWallet {
5252
5536
  };
5253
5537
 
5254
5538
  // src/wallets/mnemonic.ts
5255
- var import_algosdk8 = __toESM(require("algosdk"), 1);
5539
+ var import_algosdk9 = __toESM(require("algosdk"), 1);
5256
5540
  var LOCAL_STORAGE_MNEMONIC_KEY = `${LOCAL_STORAGE_KEY}_mnemonic`;
5257
- var ICON9 = `data:image/svg+xml;base64,${btoa(`
5541
+ var ICON10 = `data:image/svg+xml;base64,${btoa(`
5258
5542
  <svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
5259
5543
  <rect fill="#525252" width="400" height="400" />
5260
5544
  <path fill="#FFFFFF" d="M309.2,309.3H275l-22.2-82.7l-47.9,82.7h-38.3l73.9-128l-11.9-44.5l-99.6,172.6H90.8L217.1,90.6 h33.5l14.7,54.3h34.6l-23.6,41L309.2,309.3z" />
@@ -5284,7 +5568,7 @@ var MnemonicWallet = class extends BaseWallet {
5284
5568
  }
5285
5569
  static defaultMetadata = {
5286
5570
  name: "Mnemonic",
5287
- icon: ICON9
5571
+ icon: ICON10
5288
5572
  };
5289
5573
  loadMnemonicFromStorage() {
5290
5574
  return StorageAdapter.getItem(LOCAL_STORAGE_MNEMONIC_KEY);
@@ -5320,7 +5604,7 @@ var MnemonicWallet = class extends BaseWallet {
5320
5604
  this.saveMnemonicToStorage(mnemonic);
5321
5605
  }
5322
5606
  }
5323
- const account = import_algosdk8.default.mnemonicToSecretKey(mnemonic);
5607
+ const account = import_algosdk9.default.mnemonicToSecretKey(mnemonic);
5324
5608
  this.account = account;
5325
5609
  return account;
5326
5610
  }
@@ -5364,7 +5648,7 @@ var MnemonicWallet = class extends BaseWallet {
5364
5648
  const txnsToSign = [];
5365
5649
  txnGroup.forEach((txn, index) => {
5366
5650
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5367
- const signer = import_algosdk8.default.encodeAddress(txn.from.publicKey);
5651
+ const signer = import_algosdk9.default.encodeAddress(txn.from.publicKey);
5368
5652
  const canSignTxn = signer === this.account.addr;
5369
5653
  if (isIndexMatch && canSignTxn) {
5370
5654
  txnsToSign.push(txn);
@@ -5375,11 +5659,11 @@ var MnemonicWallet = class extends BaseWallet {
5375
5659
  processEncodedTxns(txnGroup, indexesToSign) {
5376
5660
  const txnsToSign = [];
5377
5661
  txnGroup.forEach((txnBuffer, index) => {
5378
- const txnDecodeObj = import_algosdk8.default.decodeObj(txnBuffer);
5662
+ const txnDecodeObj = import_algosdk9.default.decodeObj(txnBuffer);
5379
5663
  const isSigned = isSignedTxn(txnDecodeObj);
5380
- const txn = isSigned ? import_algosdk8.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk8.default.decodeUnsignedTransaction(txnBuffer);
5664
+ const txn = isSigned ? import_algosdk9.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk9.default.decodeUnsignedTransaction(txnBuffer);
5381
5665
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5382
- const signer = import_algosdk8.default.encodeAddress(txn.from.publicKey);
5666
+ const signer = import_algosdk9.default.encodeAddress(txn.from.publicKey);
5383
5667
  const canSignTxn = !isSigned && signer === this.account.addr;
5384
5668
  if (isIndexMatch && canSignTxn) {
5385
5669
  txnsToSign.push(txn);
@@ -5410,8 +5694,8 @@ var MnemonicWallet = class extends BaseWallet {
5410
5694
  };
5411
5695
 
5412
5696
  // src/wallets/pera.ts
5413
- var import_algosdk9 = __toESM(require("algosdk"), 1);
5414
- var ICON10 = `data:image/svg+xml;base64,${btoa(`
5697
+ var import_algosdk10 = __toESM(require("algosdk"), 1);
5698
+ var ICON11 = `data:image/svg+xml;base64,${btoa(`
5415
5699
  <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
5416
5700
  <rect fill="#FFEE55" width="200" height="200" />
5417
5701
  <path fill="#1C1C1C" d="M106.1,64.3c2.2,9.1,1.5,17-1.7,17.8c-3.1,0.8-7.4-6-9.6-15c-2.2-9.1-1.5-17,1.7-17.8 C99.6,48.5,103.9,55.2,106.1,64.3z" />
@@ -5440,7 +5724,7 @@ var PeraWallet = class extends BaseWallet {
5440
5724
  }
5441
5725
  static defaultMetadata = {
5442
5726
  name: "Pera",
5443
- icon: ICON10
5727
+ icon: ICON11
5444
5728
  };
5445
5729
  async initializeClient() {
5446
5730
  this.logger.info("Initializing client...");
@@ -5453,6 +5737,10 @@ var PeraWallet = class extends BaseWallet {
5453
5737
  }
5454
5738
  connect = async () => {
5455
5739
  this.logger.info("Connecting...");
5740
+ const currentActiveWallet = this.store.state.activeWallet;
5741
+ if (currentActiveWallet && currentActiveWallet !== this.id) {
5742
+ this.manageWalletConnectSession("backup", currentActiveWallet);
5743
+ }
5456
5744
  const client = this.client || await this.initializeClient();
5457
5745
  const accounts = await client.connect();
5458
5746
  client.connector?.on("disconnect", this.onDisconnect);
@@ -5478,11 +5766,29 @@ var PeraWallet = class extends BaseWallet {
5478
5766
  };
5479
5767
  disconnect = async () => {
5480
5768
  this.logger.info("Disconnecting...");
5481
- this.onDisconnect();
5482
5769
  const client = this.client || await this.initializeClient();
5483
- await client.disconnect();
5770
+ const currentActiveWallet = this.store.state.activeWallet;
5771
+ if (currentActiveWallet && currentActiveWallet !== this.id) {
5772
+ this.manageWalletConnectSession("backup", currentActiveWallet);
5773
+ this.manageWalletConnectSession("restore", this.id);
5774
+ await client.disconnect();
5775
+ await new Promise((resolve) => setTimeout(resolve, 500));
5776
+ this.manageWalletConnectSession("restore", currentActiveWallet);
5777
+ } else {
5778
+ await client.disconnect();
5779
+ }
5780
+ this.onDisconnect();
5484
5781
  this.logger.info("Disconnected");
5485
5782
  };
5783
+ setActive = () => {
5784
+ this.logger.info(`Set active wallet: ${this.id}`);
5785
+ const currentActiveWallet = this.store.state.activeWallet;
5786
+ if (currentActiveWallet && currentActiveWallet !== this.id) {
5787
+ this.manageWalletConnectSession("backup", currentActiveWallet);
5788
+ }
5789
+ this.manageWalletConnectSession("restore");
5790
+ setActiveWallet(this.store, { walletId: this.id });
5791
+ };
5486
5792
  resumeSession = async () => {
5487
5793
  try {
5488
5794
  const state = this.store.state;
@@ -5524,7 +5830,7 @@ var PeraWallet = class extends BaseWallet {
5524
5830
  const txnsToSign = [];
5525
5831
  txnGroup.forEach((txn, index) => {
5526
5832
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5527
- const signer = import_algosdk9.default.encodeAddress(txn.from.publicKey);
5833
+ const signer = import_algosdk10.default.encodeAddress(txn.from.publicKey);
5528
5834
  const canSignTxn = this.addresses.includes(signer);
5529
5835
  if (isIndexMatch && canSignTxn) {
5530
5836
  txnsToSign.push({ txn });
@@ -5537,11 +5843,11 @@ var PeraWallet = class extends BaseWallet {
5537
5843
  processEncodedTxns(txnGroup, indexesToSign) {
5538
5844
  const txnsToSign = [];
5539
5845
  txnGroup.forEach((txnBuffer, index) => {
5540
- const txnDecodeObj = import_algosdk9.default.decodeObj(txnBuffer);
5846
+ const txnDecodeObj = import_algosdk10.default.decodeObj(txnBuffer);
5541
5847
  const isSigned = isSignedTxn(txnDecodeObj);
5542
- const txn = isSigned ? import_algosdk9.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk9.default.decodeUnsignedTransaction(txnBuffer);
5848
+ const txn = isSigned ? import_algosdk10.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk10.default.decodeUnsignedTransaction(txnBuffer);
5543
5849
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5544
- const signer = import_algosdk9.default.encodeAddress(txn.from.publicKey);
5850
+ const signer = import_algosdk10.default.encodeAddress(txn.from.publicKey);
5545
5851
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5546
5852
  if (isIndexMatch && canSignTxn) {
5547
5853
  txnsToSign.push({ txn });
@@ -5587,8 +5893,8 @@ var PeraWallet = class extends BaseWallet {
5587
5893
  };
5588
5894
 
5589
5895
  // src/wallets/pera2.ts
5590
- var import_algosdk10 = __toESM(require("algosdk"), 1);
5591
- var ICON11 = `data:image/svg+xml;base64,${btoa(`
5896
+ var import_algosdk11 = __toESM(require("algosdk"), 1);
5897
+ var ICON12 = `data:image/svg+xml;base64,${btoa(`
5592
5898
  <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
5593
5899
  <rect fill="#FFEE55" width="200" height="200" />
5594
5900
  <path fill="#1C1C1C" d="M106.1,64.3c2.2,9.1,1.5,17-1.7,17.8c-3.1,0.8-7.4-6-9.6-15c-2.2-9.1-1.5-17,1.7-17.8 C99.6,48.5,103.9,55.2,106.1,64.3z" />
@@ -5621,7 +5927,7 @@ var PeraWallet2 = class extends BaseWallet {
5621
5927
  }
5622
5928
  static defaultMetadata = {
5623
5929
  name: "Pera",
5624
- icon: ICON11
5930
+ icon: ICON12
5625
5931
  };
5626
5932
  async initializeClient() {
5627
5933
  this.logger.info("Initializing client...");
@@ -5705,7 +6011,7 @@ var PeraWallet2 = class extends BaseWallet {
5705
6011
  const txnsToSign = [];
5706
6012
  txnGroup.forEach((txn, index) => {
5707
6013
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5708
- const signer = import_algosdk10.default.encodeAddress(txn.from.publicKey);
6014
+ const signer = import_algosdk11.default.encodeAddress(txn.from.publicKey);
5709
6015
  const canSignTxn = this.addresses.includes(signer);
5710
6016
  if (isIndexMatch && canSignTxn) {
5711
6017
  txnsToSign.push({ txn });
@@ -5718,11 +6024,11 @@ var PeraWallet2 = class extends BaseWallet {
5718
6024
  processEncodedTxns(txnGroup, indexesToSign) {
5719
6025
  const txnsToSign = [];
5720
6026
  txnGroup.forEach((txnBuffer, index) => {
5721
- const txnDecodeObj = import_algosdk10.default.decodeObj(txnBuffer);
6027
+ const txnDecodeObj = import_algosdk11.default.decodeObj(txnBuffer);
5722
6028
  const isSigned = isSignedTxn(txnDecodeObj);
5723
- const txn = isSigned ? import_algosdk10.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk10.default.decodeUnsignedTransaction(txnBuffer);
6029
+ const txn = isSigned ? import_algosdk11.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk11.default.decodeUnsignedTransaction(txnBuffer);
5724
6030
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5725
- const signer = import_algosdk10.default.encodeAddress(txn.from.publicKey);
6031
+ const signer = import_algosdk11.default.encodeAddress(txn.from.publicKey);
5726
6032
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5727
6033
  if (isIndexMatch && canSignTxn) {
5728
6034
  txnsToSign.push({ txn });
@@ -5870,242 +6176,6 @@ function deepMerge(target, source) {
5870
6176
  return target;
5871
6177
  }
5872
6178
 
5873
- // src/wallets/custom.ts
5874
- var ICON12 = `data:image/svg+xml;base64,${btoa(`
5875
- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
5876
- <rect width="24" height="24" fill="#525252" />
5877
- </svg>
5878
- `)}`;
5879
- var CustomWallet = class extends BaseWallet {
5880
- provider;
5881
- store;
5882
- constructor({
5883
- id,
5884
- store,
5885
- subscribe,
5886
- getAlgodClient,
5887
- options,
5888
- metadata = {}
5889
- }) {
5890
- super({ id, metadata, getAlgodClient, store, subscribe });
5891
- if (!options?.provider) {
5892
- this.logger.error("Missing required option: provider");
5893
- throw new Error("Missing required option: provider");
5894
- }
5895
- this.provider = options.provider;
5896
- this.store = store;
5897
- }
5898
- static defaultMetadata = {
5899
- name: "Custom",
5900
- icon: ICON12
5901
- };
5902
- connect = async (args) => {
5903
- this.logger.info("Connecting...");
5904
- try {
5905
- if (!this.provider.connect) {
5906
- this.logger.error("Method not supported: connect");
5907
- throw new Error("Method not supported: connect");
5908
- }
5909
- const walletAccounts = await this.provider.connect(args);
5910
- if (walletAccounts.length === 0) {
5911
- this.logger.error("No accounts found!");
5912
- throw new Error("No accounts found!");
5913
- }
5914
- const activeAccount = walletAccounts[0];
5915
- const walletState = {
5916
- accounts: walletAccounts,
5917
- activeAccount
5918
- };
5919
- addWallet(this.store, {
5920
- walletId: this.id,
5921
- wallet: walletState
5922
- });
5923
- this.logger.info("\u2705 Connected.", walletState);
5924
- return walletAccounts;
5925
- } catch (error) {
5926
- this.logger.error("Error connecting:", error.message || error);
5927
- throw error;
5928
- }
5929
- };
5930
- disconnect = async () => {
5931
- this.logger.info("Disconnecting...");
5932
- this.onDisconnect();
5933
- await this.provider.disconnect?.();
5934
- };
5935
- resumeSession = async () => {
5936
- try {
5937
- const state = this.store.state;
5938
- const walletState = state.wallets[this.id];
5939
- if (!walletState) {
5940
- this.logger.info("No session to resume");
5941
- return;
5942
- }
5943
- this.logger.info("Resuming session...");
5944
- const result = await this.provider.resumeSession?.();
5945
- if (Array.isArray(result)) {
5946
- const walletAccounts = result;
5947
- if (walletAccounts.length === 0) {
5948
- this.logger.error("No accounts found!");
5949
- throw new Error("No accounts found!");
5950
- }
5951
- const match = compareAccounts(walletAccounts, walletState.accounts);
5952
- if (!match) {
5953
- this.logger.warn("Session accounts mismatch, updating accounts", {
5954
- prev: walletState.accounts,
5955
- current: walletAccounts
5956
- });
5957
- setAccounts(this.store, {
5958
- walletId: this.id,
5959
- accounts: walletAccounts
5960
- });
5961
- }
5962
- }
5963
- this.logger.info("Session resumed.");
5964
- } catch (error) {
5965
- this.logger.error("Error resuming session:", error.message);
5966
- throw error;
5967
- }
5968
- };
5969
- signTransactions = async (txnGroup, indexesToSign) => {
5970
- if (!this.provider.signTransactions) {
5971
- this.logger.error("Method not supported: signTransactions");
5972
- throw new Error("Method not supported: signTransactions");
5973
- }
5974
- this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
5975
- return await this.provider.signTransactions(txnGroup, indexesToSign);
5976
- };
5977
- transactionSigner = async (txnGroup, indexesToSign) => {
5978
- if (!this.provider.transactionSigner) {
5979
- this.logger.error("Method not supported: transactionSigner");
5980
- throw new Error("Method not supported: transactionSigner");
5981
- }
5982
- this.logger.debug("Transaction signer called...", { txnGroup, indexesToSign });
5983
- return await this.provider.transactionSigner(txnGroup, indexesToSign);
5984
- };
5985
- };
5986
-
5987
- // src/store.ts
5988
- var defaultState = {
5989
- wallets: {},
5990
- activeWallet: null,
5991
- activeNetwork: "testnet" /* TESTNET */,
5992
- algodClient: new import_algosdk11.default.Algodv2("", "https://testnet-api.4160.nodely.dev/")
5993
- };
5994
- var LOCAL_STORAGE_KEY = "@txnlab/use-wallet:v3";
5995
- function addWallet(store, { walletId, wallet }) {
5996
- store.setState((state) => {
5997
- const updatedWallets = {
5998
- ...state.wallets,
5999
- [walletId]: {
6000
- accounts: wallet.accounts.map((account) => ({ ...account })),
6001
- activeAccount: wallet.activeAccount ? { ...wallet.activeAccount } : null
6002
- }
6003
- };
6004
- return {
6005
- ...state,
6006
- wallets: updatedWallets,
6007
- activeWallet: walletId
6008
- };
6009
- });
6010
- }
6011
- function removeWallet(store, { walletId }) {
6012
- store.setState((state) => {
6013
- const updatedWallets = { ...state.wallets };
6014
- delete updatedWallets[walletId];
6015
- return {
6016
- ...state,
6017
- wallets: updatedWallets,
6018
- activeWallet: state.activeWallet === walletId ? null : state.activeWallet
6019
- };
6020
- });
6021
- }
6022
- function setActiveWallet(store, { walletId }) {
6023
- store.setState((state) => ({
6024
- ...state,
6025
- activeWallet: walletId
6026
- }));
6027
- }
6028
- function setActiveAccount(store, { walletId, address }) {
6029
- store.setState((state) => {
6030
- const wallet = state.wallets[walletId];
6031
- if (!wallet) {
6032
- logger.warn(`Wallet with id "${walletId}" not found`);
6033
- return state;
6034
- }
6035
- const newActiveAccount = wallet.accounts.find((a2) => a2.address === address);
6036
- if (!newActiveAccount) {
6037
- logger.warn(`Account with address ${address} not found in wallet "${walletId}"`);
6038
- return state;
6039
- }
6040
- const updatedWallet = {
6041
- ...wallet,
6042
- accounts: wallet.accounts.map((account) => ({ ...account })),
6043
- activeAccount: { ...newActiveAccount }
6044
- };
6045
- const updatedWallets = {
6046
- ...state.wallets,
6047
- [walletId]: updatedWallet
6048
- };
6049
- return {
6050
- ...state,
6051
- wallets: updatedWallets
6052
- };
6053
- });
6054
- }
6055
- function setAccounts(store, { walletId, accounts }) {
6056
- store.setState((state) => {
6057
- const wallet = state.wallets[walletId];
6058
- if (!wallet) {
6059
- logger.warn(`Wallet with id "${walletId}" not found`);
6060
- return state;
6061
- }
6062
- const newAccounts = accounts.map((account) => ({ ...account }));
6063
- const isActiveAccountConnected = newAccounts.some(
6064
- (account) => account.address === wallet.activeAccount?.address
6065
- );
6066
- const newActiveAccount = isActiveAccountConnected ? { ...wallet.activeAccount } : newAccounts[0] || null;
6067
- const updatedWallet = {
6068
- ...wallet,
6069
- accounts: newAccounts,
6070
- activeAccount: newActiveAccount
6071
- };
6072
- const updatedWallets = {
6073
- ...state.wallets,
6074
- [walletId]: updatedWallet
6075
- };
6076
- return {
6077
- ...state,
6078
- wallets: updatedWallets
6079
- };
6080
- });
6081
- }
6082
- function setActiveNetwork(store, { networkId, algodClient }) {
6083
- store.setState((state) => ({
6084
- ...state,
6085
- activeNetwork: networkId,
6086
- algodClient
6087
- }));
6088
- }
6089
- function isValidWalletId(walletId) {
6090
- return Object.values(WalletId).includes(walletId);
6091
- }
6092
- function isValidWalletAccount(account) {
6093
- return typeof account === "object" && account !== null && typeof account.name === "string" && typeof account.address === "string";
6094
- }
6095
- function isValidWalletState(wallet) {
6096
- return typeof wallet === "object" && wallet !== null && Array.isArray(wallet.accounts) && wallet.accounts.every(isValidWalletAccount) && (wallet.activeAccount === null || isValidWalletAccount(wallet.activeAccount));
6097
- }
6098
- function isValidState(state) {
6099
- if (!state || typeof state !== "object") return false;
6100
- if (typeof state.wallets !== "object") return false;
6101
- for (const [walletId, wallet] of Object.entries(state.wallets)) {
6102
- if (!isValidWalletId(walletId) || !isValidWalletState(wallet)) return false;
6103
- }
6104
- if (state.activeWallet !== null && !isValidWalletId(state.activeWallet)) return false;
6105
- if (!isValidNetworkId(state.activeNetwork)) return false;
6106
- return true;
6107
- }
6108
-
6109
6179
  // src/manager.ts
6110
6180
  var WalletManager = class {
6111
6181
  _clients = /* @__PURE__ */ new Map();