@txnlab/use-wallet 3.10.0 → 4.0.0-beta.2

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
@@ -3267,9 +3267,11 @@ var src_exports = {};
3267
3267
  __export(src_exports, {
3268
3268
  BaseWallet: () => BaseWallet,
3269
3269
  CustomWallet: () => CustomWallet,
3270
+ DEFAULT_NETWORKS: () => DEFAULT_NETWORKS,
3271
+ DEFAULT_STATE: () => DEFAULT_STATE,
3270
3272
  DeflyWallet: () => DeflyWallet,
3271
3273
  ExodusWallet: () => ExodusWallet,
3272
- ICON: () => ICON6,
3274
+ ICON: () => ICON7,
3273
3275
  KIBISIS_AVM_WEB_PROVIDER_ID: () => KIBISIS_AVM_WEB_PROVIDER_ID,
3274
3276
  KibisisWallet: () => KibisisWallet,
3275
3277
  KmdWallet: () => KmdWallet,
@@ -3286,8 +3288,6 @@ __export(src_exports, {
3286
3288
  WalletConnect: () => WalletConnect,
3287
3289
  WalletId: () => WalletId,
3288
3290
  WalletManager: () => WalletManager,
3289
- defaultState: () => defaultState,
3290
- isAVMWebProviderSDKError: () => isAVMWebProviderSDKError,
3291
3291
  webpackFallback: () => webpackFallback
3292
3292
  });
3293
3293
  module.exports = __toCommonJS(src_exports);
@@ -3363,61 +3363,178 @@ var logger = Logger.getInstance();
3363
3363
 
3364
3364
  // src/manager.ts
3365
3365
  var import_store14 = require("@tanstack/store");
3366
- var import_algosdk12 = __toESM(require("algosdk"), 1);
3366
+ var import_algosdk13 = __toESM(require("algosdk"), 1);
3367
3367
 
3368
3368
  // src/network.ts
3369
+ var DEFAULT_NETWORKS = {
3370
+ mainnet: {
3371
+ name: "MainNet",
3372
+ algod: {
3373
+ token: "",
3374
+ baseServer: "https://mainnet-api.4160.nodely.dev",
3375
+ headers: {}
3376
+ },
3377
+ isTestnet: false,
3378
+ genesisHash: "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=",
3379
+ genesisId: "mainnet-v1.0",
3380
+ caipChainId: "algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k"
3381
+ },
3382
+ testnet: {
3383
+ name: "TestNet",
3384
+ algod: {
3385
+ token: "",
3386
+ baseServer: "https://testnet-api.4160.nodely.dev",
3387
+ headers: {}
3388
+ },
3389
+ isTestnet: true,
3390
+ genesisHash: "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=",
3391
+ genesisId: "testnet-v1.0",
3392
+ caipChainId: "algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe"
3393
+ },
3394
+ betanet: {
3395
+ name: "BetaNet",
3396
+ algod: {
3397
+ token: "",
3398
+ baseServer: "https://betanet-api.4160.nodely.dev",
3399
+ headers: {}
3400
+ },
3401
+ isTestnet: true,
3402
+ genesisHash: "mFgazF-2uRS1tMiL9dsj01hJGySEmPN2OvOTQHJ6iQg=",
3403
+ genesisId: "betanet-v1.0",
3404
+ caipChainId: "algorand:mFgazF-2uRS1tMiL9dsj01hJGySEmPN2"
3405
+ },
3406
+ fnet: {
3407
+ name: "FNet",
3408
+ algod: {
3409
+ token: "",
3410
+ baseServer: "https://fnet-api.4160.nodely.dev",
3411
+ headers: {}
3412
+ },
3413
+ isTestnet: true,
3414
+ genesisHash: "kUt08LxeVAAGHnh4JoAoAMM9ql_hBwSoRrQQKWSVgxk=",
3415
+ genesisId: "fnet-v1.0",
3416
+ caipChainId: "algorand:kUt08LxeVAAGHnh4JoAoAMM9ql_hBwSo"
3417
+ },
3418
+ localnet: {
3419
+ name: "LocalNet",
3420
+ algod: {
3421
+ token: "a".repeat(64),
3422
+ baseServer: "http://localhost",
3423
+ port: 4001,
3424
+ headers: {}
3425
+ },
3426
+ isTestnet: true
3427
+ }
3428
+ };
3429
+ var NetworkConfigBuilder = class {
3430
+ networks;
3431
+ constructor() {
3432
+ this.networks = new Map(Object.entries(DEFAULT_NETWORKS));
3433
+ }
3434
+ // Methods to customize default networks
3435
+ mainnet(config) {
3436
+ this.networks.set("mainnet", {
3437
+ ...DEFAULT_NETWORKS.mainnet,
3438
+ ...config,
3439
+ genesisHash: DEFAULT_NETWORKS.mainnet.genesisHash,
3440
+ genesisId: DEFAULT_NETWORKS.mainnet.genesisId,
3441
+ caipChainId: DEFAULT_NETWORKS.mainnet.caipChainId,
3442
+ algod: {
3443
+ ...DEFAULT_NETWORKS.mainnet.algod,
3444
+ ...config.algod || {}
3445
+ }
3446
+ });
3447
+ return this;
3448
+ }
3449
+ testnet(config) {
3450
+ this.networks.set("testnet", {
3451
+ ...DEFAULT_NETWORKS.testnet,
3452
+ ...config,
3453
+ genesisHash: DEFAULT_NETWORKS.testnet.genesisHash,
3454
+ genesisId: DEFAULT_NETWORKS.testnet.genesisId,
3455
+ caipChainId: DEFAULT_NETWORKS.testnet.caipChainId,
3456
+ algod: {
3457
+ ...DEFAULT_NETWORKS.testnet.algod,
3458
+ ...config.algod || {}
3459
+ }
3460
+ });
3461
+ return this;
3462
+ }
3463
+ betanet(config) {
3464
+ this.networks.set("betanet", {
3465
+ ...DEFAULT_NETWORKS.betanet,
3466
+ ...config,
3467
+ genesisHash: DEFAULT_NETWORKS.betanet.genesisHash,
3468
+ genesisId: DEFAULT_NETWORKS.betanet.genesisId,
3469
+ caipChainId: DEFAULT_NETWORKS.betanet.caipChainId,
3470
+ algod: {
3471
+ ...DEFAULT_NETWORKS.betanet.algod,
3472
+ ...config.algod || {}
3473
+ }
3474
+ });
3475
+ return this;
3476
+ }
3477
+ fnet(config) {
3478
+ this.networks.set("fnet", {
3479
+ ...DEFAULT_NETWORKS.fnet,
3480
+ ...config,
3481
+ genesisHash: DEFAULT_NETWORKS.fnet.genesisHash,
3482
+ genesisId: DEFAULT_NETWORKS.fnet.genesisId,
3483
+ caipChainId: DEFAULT_NETWORKS.fnet.caipChainId,
3484
+ algod: {
3485
+ ...DEFAULT_NETWORKS.fnet.algod,
3486
+ ...config.algod || {}
3487
+ }
3488
+ });
3489
+ return this;
3490
+ }
3491
+ localnet(config) {
3492
+ this.networks.set("localnet", {
3493
+ ...DEFAULT_NETWORKS.localnet,
3494
+ ...config,
3495
+ algod: {
3496
+ ...DEFAULT_NETWORKS.localnet.algod,
3497
+ ...config.algod || {}
3498
+ }
3499
+ });
3500
+ return this;
3501
+ }
3502
+ // Method to add custom networks (still needs full NetworkConfig)
3503
+ addNetwork(id, config) {
3504
+ if (DEFAULT_NETWORKS[id]) {
3505
+ throw new Error(
3506
+ `Cannot add network with reserved id "${id}". Use the ${id}() method instead.`
3507
+ );
3508
+ }
3509
+ this.networks.set(id, config);
3510
+ return this;
3511
+ }
3512
+ build() {
3513
+ return Object.fromEntries(this.networks);
3514
+ }
3515
+ };
3516
+ var createNetworkConfig = () => new NetworkConfigBuilder().build();
3517
+ function isValidToken(token) {
3518
+ if (typeof token === "string") return true;
3519
+ if (typeof token !== "object" || token === null) return false;
3520
+ if ("X-Algo-API-Token" in token && typeof token["X-Algo-API-Token"] === "string") return true;
3521
+ if ("get" in token && "post" in token && "delete" in token) return true;
3522
+ return Object.values(token).every((value) => typeof value === "string");
3523
+ }
3524
+ function isNetworkConfig(config) {
3525
+ if (typeof config !== "object" || config === null) return false;
3526
+ const { name, algod, isTestnet, genesisHash, genesisId, caipChainId } = config;
3527
+ const isValidAlgod = typeof algod === "object" && algod !== null && isValidToken(algod.token) && typeof algod.baseServer === "string";
3528
+ return typeof name === "string" && isValidAlgod && (isTestnet === void 0 || typeof isTestnet === "boolean") && (genesisHash === void 0 || typeof genesisHash === "string") && (genesisId === void 0 || typeof genesisId === "string") && (caipChainId === void 0 || typeof caipChainId === "string");
3529
+ }
3369
3530
  var NetworkId = /* @__PURE__ */ ((NetworkId2) => {
3370
3531
  NetworkId2["MAINNET"] = "mainnet";
3371
3532
  NetworkId2["TESTNET"] = "testnet";
3372
3533
  NetworkId2["BETANET"] = "betanet";
3373
3534
  NetworkId2["FNET"] = "fnet";
3374
3535
  NetworkId2["LOCALNET"] = "localnet";
3375
- NetworkId2["VOIMAIN"] = "voimain";
3376
- NetworkId2["ARAMIDMAIN"] = "aramidmain";
3377
3536
  return NetworkId2;
3378
3537
  })(NetworkId || {});
3379
- function isValidNetworkId(networkId) {
3380
- return Object.values(NetworkId).includes(networkId);
3381
- }
3382
- function isNetworkConfigMap(config) {
3383
- const networkKeys = Object.values(NetworkId);
3384
- return Object.keys(config).some((key) => networkKeys.includes(key));
3385
- }
3386
- var nodeServerMap = {
3387
- ["mainnet" /* MAINNET */]: "https://mainnet-api.4160.nodely.dev",
3388
- ["testnet" /* TESTNET */]: "https://testnet-api.4160.nodely.dev",
3389
- ["betanet" /* BETANET */]: "https://betanet-api.4160.nodely.dev",
3390
- ["fnet" /* FNET */]: "https://fnet-api.4160.nodely.dev",
3391
- ["voimain" /* VOIMAIN */]: "https://mainnet-api.voi.nodely.dev",
3392
- ["aramidmain" /* ARAMIDMAIN */]: "https://algod.aramidmain.a-wallet.net"
3393
- };
3394
- function createDefaultNetworkConfig() {
3395
- const localnetConfig = {
3396
- token: "a".repeat(64),
3397
- baseServer: "http://localhost",
3398
- port: 4001,
3399
- headers: {}
3400
- };
3401
- return Object.values(NetworkId).reduce((configMap, value) => {
3402
- const network = value;
3403
- const isLocalnet = network === "localnet" /* LOCALNET */;
3404
- configMap[network] = isLocalnet ? localnetConfig : {
3405
- token: "",
3406
- baseServer: nodeServerMap[network],
3407
- port: "",
3408
- headers: {}
3409
- };
3410
- return configMap;
3411
- }, {});
3412
- }
3413
- var caipChainId = {
3414
- ["mainnet" /* MAINNET */]: "algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k",
3415
- ["testnet" /* TESTNET */]: "algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe",
3416
- ["betanet" /* BETANET */]: "algorand:mFgazF-2uRS1tMiL9dsj01hJGySEmPN2",
3417
- ["fnet" /* FNET */]: "algorand:kUt08LxeVAAGHnh4JoAoAMM9ql_hBwSo",
3418
- ["voimain" /* VOIMAIN */]: "algorand:r20fSQI8gWe_kFZziNonSPCXLwcQmH_n",
3419
- ["aramidmain" /* ARAMIDMAIN */]: "algorand:PgeQVJJgx_LYKJfIEz7dbfNPuXmDyJ-O"
3420
- };
3421
3538
 
3422
3539
  // src/storage.ts
3423
3540
  var StorageAdapter = class {
@@ -3448,6 +3565,7 @@ var import_algosdk = __toESM(require("algosdk"), 1);
3448
3565
  var WalletId = /* @__PURE__ */ ((WalletId2) => {
3449
3566
  WalletId2["BIATEC"] = "biatec";
3450
3567
  WalletId2["DEFLY"] = "defly";
3568
+ WalletId2["DEFLY_WEB"] = "defly-web";
3451
3569
  WalletId2["CUSTOM"] = "custom";
3452
3570
  WalletId2["EXODUS"] = "exodus";
3453
3571
  WalletId2["KIBISIS"] = "kibisis";
@@ -3473,10 +3591,10 @@ var SignTxnsError = class extends Error {
3473
3591
  };
3474
3592
 
3475
3593
  // src/store.ts
3476
- var defaultState = {
3594
+ var DEFAULT_STATE = {
3477
3595
  wallets: {},
3478
3596
  activeWallet: null,
3479
- activeNetwork: "testnet" /* TESTNET */,
3597
+ activeNetwork: "testnet",
3480
3598
  algodClient: new import_algosdk.default.Algodv2("", "https://testnet-api.4160.nodely.dev/")
3481
3599
  };
3482
3600
  var LOCAL_STORAGE_KEY = "@txnlab/use-wallet:v3";
@@ -3590,10 +3708,13 @@ function isValidState(state) {
3590
3708
  if (!isValidWalletId(walletId) || !isValidWalletState(wallet)) return false;
3591
3709
  }
3592
3710
  if (state.activeWallet !== null && !isValidWalletId(state.activeWallet)) return false;
3593
- if (!isValidNetworkId(state.activeNetwork)) return false;
3711
+ if (typeof state.activeNetwork !== "string") return false;
3594
3712
  return true;
3595
3713
  }
3596
3714
 
3715
+ // src/utils.ts
3716
+ var import_algosdk12 = __toESM(require("algosdk"), 1);
3717
+
3597
3718
  // src/wallets/walletconnect.ts
3598
3719
  var import_algosdk2 = __toESM(require("algosdk"), 1);
3599
3720
 
@@ -3601,6 +3722,7 @@ var import_algosdk2 = __toESM(require("algosdk"), 1);
3601
3722
  var BaseWallet = class {
3602
3723
  id;
3603
3724
  metadata;
3725
+ networks;
3604
3726
  store;
3605
3727
  getAlgodClient;
3606
3728
  subscribe;
@@ -3610,12 +3732,14 @@ var BaseWallet = class {
3610
3732
  metadata,
3611
3733
  store,
3612
3734
  subscribe,
3613
- getAlgodClient
3735
+ getAlgodClient,
3736
+ networks
3614
3737
  }) {
3615
3738
  this.id = id;
3616
3739
  this.store = store;
3617
3740
  this.subscribe = subscribe;
3618
3741
  this.getAlgodClient = getAlgodClient;
3742
+ this.networks = networks;
3619
3743
  const ctor = this.constructor;
3620
3744
  this.metadata = { ...ctor.defaultMetadata, ...metadata };
3621
3745
  this.logger = logger.createScopedLogger(`Wallet:${this.id.toUpperCase()}`);
@@ -3675,6 +3799,17 @@ var BaseWallet = class {
3675
3799
  const state = this.store.state;
3676
3800
  return state.activeWallet === this.id;
3677
3801
  }
3802
+ // Make networks accessible for testing
3803
+ get networkConfig() {
3804
+ return this.networks;
3805
+ }
3806
+ get activeNetworkConfig() {
3807
+ const config = this.networks[this.activeNetwork];
3808
+ if (!config) {
3809
+ throw new Error(`No configuration found for network: ${this.activeNetwork}`);
3810
+ }
3811
+ return config;
3812
+ }
3678
3813
  // ---------- Protected Methods ------------------------------------- //
3679
3814
  onDisconnect = () => {
3680
3815
  this.logger.debug(`Removing wallet from store...`);
@@ -3726,9 +3861,10 @@ var WalletConnect = class extends BaseWallet {
3726
3861
  subscribe,
3727
3862
  getAlgodClient,
3728
3863
  options,
3729
- metadata = {}
3864
+ metadata = {},
3865
+ networks
3730
3866
  }) {
3731
- super({ id, metadata, getAlgodClient, store, subscribe });
3867
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
3732
3868
  if (!options?.projectId) {
3733
3869
  this.logger.error("Missing required option: projectId");
3734
3870
  throw new Error("Missing required option: projectId");
@@ -3950,12 +4086,12 @@ var WalletConnect = class extends BaseWallet {
3950
4086
  return walletAccounts;
3951
4087
  }
3952
4088
  get activeChainId() {
3953
- const chainId = caipChainId[this.activeNetwork];
3954
- if (!chainId) {
4089
+ const network = this.networks[this.activeNetwork];
4090
+ if (!network?.caipChainId) {
3955
4091
  this.logger.warn(`No CAIP-2 chain ID found for network: ${this.activeNetwork}`);
3956
4092
  return "";
3957
4093
  }
3958
- return chainId;
4094
+ return network.caipChainId;
3959
4095
  }
3960
4096
  connect = async () => {
3961
4097
  this.logger.info("Connecting...");
@@ -4031,7 +4167,7 @@ var WalletConnect = class extends BaseWallet {
4031
4167
  const txnsToSign = [];
4032
4168
  txnGroup.forEach((txn, index) => {
4033
4169
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4034
- const signer = import_algosdk2.default.encodeAddress(txn.from.publicKey);
4170
+ const signer = txn.sender.toString();
4035
4171
  const canSignTxn = this.addresses.includes(signer);
4036
4172
  const txnString = byteArrayToBase64(txn.toByte());
4037
4173
  if (isIndexMatch && canSignTxn) {
@@ -4045,11 +4181,11 @@ var WalletConnect = class extends BaseWallet {
4045
4181
  processEncodedTxns(txnGroup, indexesToSign) {
4046
4182
  const txnsToSign = [];
4047
4183
  txnGroup.forEach((txnBuffer, index) => {
4048
- const txnDecodeObj = import_algosdk2.default.decodeObj(txnBuffer);
4049
- const isSigned = isSignedTxn(txnDecodeObj);
4184
+ const decodedObj = import_algosdk2.default.msgpackRawDecode(txnBuffer);
4185
+ const isSigned = isSignedTxn(decodedObj);
4050
4186
  const txn = isSigned ? import_algosdk2.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk2.default.decodeUnsignedTransaction(txnBuffer);
4051
4187
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4052
- const signer = import_algosdk2.default.encodeAddress(txn.from.publicKey);
4188
+ const signer = txn.sender.toString();
4053
4189
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4054
4190
  const txnString = byteArrayToBase64(txn.toByte());
4055
4191
  if (isIndexMatch && canSignTxn) {
@@ -4146,10 +4282,11 @@ var CustomWallet = class extends BaseWallet {
4146
4282
  store,
4147
4283
  subscribe,
4148
4284
  getAlgodClient,
4285
+ networks,
4149
4286
  options,
4150
4287
  metadata = {}
4151
4288
  }) {
4152
- super({ id, metadata, getAlgodClient, store, subscribe });
4289
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
4153
4290
  if (!options?.provider) {
4154
4291
  this.logger.error("Missing required option: provider");
4155
4292
  throw new Error("Missing required option: provider");
@@ -4265,9 +4402,10 @@ var DeflyWallet = class extends BaseWallet {
4265
4402
  subscribe,
4266
4403
  getAlgodClient,
4267
4404
  options = {},
4268
- metadata = {}
4405
+ metadata = {},
4406
+ networks
4269
4407
  }) {
4270
- super({ id, metadata, getAlgodClient, store, subscribe });
4408
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
4271
4409
  this.options = options;
4272
4410
  this.store = store;
4273
4411
  }
@@ -4379,7 +4517,7 @@ var DeflyWallet = class extends BaseWallet {
4379
4517
  const txnsToSign = [];
4380
4518
  txnGroup.forEach((txn, index) => {
4381
4519
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4382
- const signer = import_algosdk3.default.encodeAddress(txn.from.publicKey);
4520
+ const signer = txn.sender.toString();
4383
4521
  const canSignTxn = this.addresses.includes(signer);
4384
4522
  if (isIndexMatch && canSignTxn) {
4385
4523
  txnsToSign.push({ txn });
@@ -4392,11 +4530,11 @@ var DeflyWallet = class extends BaseWallet {
4392
4530
  processEncodedTxns(txnGroup, indexesToSign) {
4393
4531
  const txnsToSign = [];
4394
4532
  txnGroup.forEach((txnBuffer, index) => {
4395
- const txnDecodeObj = import_algosdk3.default.decodeObj(txnBuffer);
4396
- const isSigned = isSignedTxn(txnDecodeObj);
4533
+ const decodedObj = import_algosdk3.default.msgpackRawDecode(txnBuffer);
4534
+ const isSigned = isSignedTxn(decodedObj);
4397
4535
  const txn = isSigned ? import_algosdk3.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk3.default.decodeUnsignedTransaction(txnBuffer);
4398
4536
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4399
- const signer = import_algosdk3.default.encodeAddress(txn.from.publicKey);
4537
+ const signer = txn.sender.toString();
4400
4538
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4401
4539
  if (isIndexMatch && canSignTxn) {
4402
4540
  txnsToSign.push({ txn });
@@ -4441,9 +4579,408 @@ var DeflyWallet = class extends BaseWallet {
4441
4579
  };
4442
4580
  };
4443
4581
 
4444
- // src/wallets/exodus.ts
4582
+ // src/wallets/avm-web-provider.ts
4445
4583
  var import_algosdk4 = __toESM(require("algosdk"), 1);
4584
+ function isAVMWebProviderSDKError(error) {
4585
+ return typeof error === "object" && "code" in error && "message" in error;
4586
+ }
4587
+ var AVMProvider = class extends BaseWallet {
4588
+ avmWebClient = null;
4589
+ avmWebProviderSDK = null;
4590
+ providerId;
4591
+ constructor(args) {
4592
+ super(args);
4593
+ this.providerId = args.providerId;
4594
+ }
4595
+ async _initializeAVMWebProviderSDK() {
4596
+ if (!this.avmWebProviderSDK) {
4597
+ this.logger.info("Initializing @agoralabs-sh/avm-web-provider...");
4598
+ const module2 = await import("@agoralabs-sh/avm-web-provider");
4599
+ this.avmWebProviderSDK = module2.default ? module2.default : module2;
4600
+ if (!this.avmWebProviderSDK) {
4601
+ throw new Error(
4602
+ "Failed to initialize, the @agoralabs-sh/avm-web-provider SDK was not provided"
4603
+ );
4604
+ }
4605
+ if (!this.avmWebProviderSDK.AVMWebClient) {
4606
+ throw new Error(
4607
+ "Failed to initialize, AVMWebClient missing from @agoralabs-sh/avm-web-provider SDK"
4608
+ );
4609
+ }
4610
+ this.logger.info("@agoralabs-sh/avm-web-provider SDK initialized");
4611
+ }
4612
+ return this.avmWebProviderSDK;
4613
+ }
4614
+ async _initializeAVMWebClient() {
4615
+ const avmWebProviderSDK = await this._initializeAVMWebProviderSDK();
4616
+ if (!avmWebProviderSDK.AVMWebClient) {
4617
+ throw new Error("Failed to initialize, AVMWebClient not found");
4618
+ }
4619
+ if (!this.avmWebClient) {
4620
+ this.logger.info("Initializing new AVM Web Client...");
4621
+ this.avmWebClient = avmWebProviderSDK.AVMWebClient.init();
4622
+ this.logger.info("AVM Web Client initialized");
4623
+ }
4624
+ return this.avmWebClient;
4625
+ }
4626
+ async _getGenesisHash() {
4627
+ const network = this.activeNetworkConfig;
4628
+ if (network.genesisHash) {
4629
+ return network.genesisHash;
4630
+ }
4631
+ const algodClient = this.getAlgodClient();
4632
+ const version = await algodClient.versionsCheck().do();
4633
+ return import_algosdk4.default.bytesToBase64(version.genesisHashB64);
4634
+ }
4635
+ _mapAVMWebProviderAccountToWalletAccounts(accounts) {
4636
+ return accounts.map(({ address, name }, idx) => ({
4637
+ name: name || `[${this.metadata.name}] Account ${idx + 1}`,
4638
+ address
4639
+ }));
4640
+ }
4641
+ processTxns(txnGroup, indexesToSign) {
4642
+ const txnsToSign = [];
4643
+ txnGroup.forEach((txn, index) => {
4644
+ const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4645
+ const signer = txn.sender.toString();
4646
+ const canSignTxn = this.addresses.includes(signer);
4647
+ const txnString = byteArrayToBase64(txn.toByte());
4648
+ if (isIndexMatch && canSignTxn) {
4649
+ txnsToSign.push({ txn: txnString });
4650
+ } else {
4651
+ txnsToSign.push({ txn: txnString, signers: [] });
4652
+ }
4653
+ });
4654
+ return txnsToSign;
4655
+ }
4656
+ processEncodedTxns(txnGroup, indexesToSign) {
4657
+ const txnsToSign = [];
4658
+ txnGroup.forEach((txnBuffer, index) => {
4659
+ const decodedObj = import_algosdk4.default.msgpackRawDecode(txnBuffer);
4660
+ const isSigned = isSignedTxn(decodedObj);
4661
+ const txn = isSigned ? import_algosdk4.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk4.default.decodeUnsignedTransaction(txnBuffer);
4662
+ const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4663
+ const signer = txn.sender.toString();
4664
+ const canSignTxn = !isSigned && this.addresses.includes(signer);
4665
+ const txnString = byteArrayToBase64(txn.toByte());
4666
+ if (isIndexMatch && canSignTxn) {
4667
+ txnsToSign.push({ txn: txnString });
4668
+ } else {
4669
+ txnsToSign.push({ txn: txnString, signers: [] });
4670
+ }
4671
+ });
4672
+ return txnsToSign;
4673
+ }
4674
+ /**
4675
+ * Common methods
4676
+ * These methods can be overridden by specific wallet providers if needed
4677
+ */
4678
+ async connect() {
4679
+ try {
4680
+ this.logger.info("Connecting...");
4681
+ const result = await this._enable();
4682
+ this.logger.info(`Successfully connected on network "${result.genesisId}"`);
4683
+ const walletAccounts = this._mapAVMWebProviderAccountToWalletAccounts(result.accounts);
4684
+ const walletState = {
4685
+ accounts: walletAccounts,
4686
+ activeAccount: walletAccounts[0]
4687
+ };
4688
+ addWallet(this.store, {
4689
+ walletId: this.id,
4690
+ wallet: walletState
4691
+ });
4692
+ this.logger.info("\u2705 Connected.", walletState);
4693
+ return walletAccounts;
4694
+ } catch (error) {
4695
+ this.logger.error(
4696
+ "Error connecting: ",
4697
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4698
+ );
4699
+ throw error;
4700
+ }
4701
+ }
4702
+ async disconnect() {
4703
+ try {
4704
+ this.logger.info("Disconnecting...");
4705
+ this.onDisconnect();
4706
+ const result = await this._disable();
4707
+ this.logger.info(
4708
+ `Successfully disconnected${result.sessionIds && result.sessionIds.length ? ` sessions [${result.sessionIds.join(",")}]` : ""} on network "${result.genesisId}"`
4709
+ );
4710
+ } catch (error) {
4711
+ this.logger.error(
4712
+ "Error disconnecting: ",
4713
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4714
+ );
4715
+ throw error;
4716
+ }
4717
+ }
4718
+ async resumeSession() {
4719
+ const state = this.store.state;
4720
+ const walletState = state.wallets[this.id];
4721
+ if (!walletState) {
4722
+ this.logger.info("No session to resume");
4723
+ return;
4724
+ }
4725
+ try {
4726
+ this.logger.info("Resuming session...");
4727
+ const result = await this._enable();
4728
+ if (result.accounts.length === 0) {
4729
+ throw new Error("No accounts found!");
4730
+ }
4731
+ const walletAccounts = this._mapAVMWebProviderAccountToWalletAccounts(result.accounts);
4732
+ const match = compareAccounts(walletAccounts, walletState.accounts);
4733
+ if (!match) {
4734
+ this.logger.warn("Session accounts mismatch, updating accounts", {
4735
+ prev: walletState.accounts,
4736
+ current: walletAccounts
4737
+ });
4738
+ setAccounts(this.store, {
4739
+ walletId: this.id,
4740
+ accounts: walletAccounts
4741
+ });
4742
+ }
4743
+ this.logger.info("Session resumed successfully");
4744
+ } catch (error) {
4745
+ this.logger.error(
4746
+ "Error resuming session: ",
4747
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4748
+ );
4749
+ this.onDisconnect();
4750
+ throw error;
4751
+ }
4752
+ }
4753
+ async signTransactions(txnGroup, indexesToSign) {
4754
+ try {
4755
+ this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4756
+ let txnsToSign = [];
4757
+ if (isTransactionArray(txnGroup)) {
4758
+ const flatTxns = flattenTxnGroup(txnGroup);
4759
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
4760
+ } else {
4761
+ const flatTxns = flattenTxnGroup(txnGroup);
4762
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4763
+ }
4764
+ this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
4765
+ const signTxnsResult = await this._signTransactions(txnsToSign);
4766
+ this.logger.debug("Received signed transactions from wallet", signTxnsResult);
4767
+ const result = signTxnsResult.stxns.map((value) => {
4768
+ if (value === null) {
4769
+ return null;
4770
+ }
4771
+ return base64ToByteArray(value);
4772
+ });
4773
+ this.logger.debug("Transactions signed successfully", result);
4774
+ return result;
4775
+ } catch (error) {
4776
+ this.logger.error(
4777
+ "Error signing transactions: ",
4778
+ isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4779
+ );
4780
+ throw error;
4781
+ }
4782
+ }
4783
+ };
4784
+
4785
+ // src/wallets/defly-web.ts
4786
+ var DEFLY_WEB_PROVIDER_ID = "95426e60-5f2e-49e9-b912-c488577be962";
4446
4787
  var ICON5 = `data:image/svg+xml;base64,${btoa(`
4788
+ <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
4789
+ <rect width="1024" height="1024" />
4790
+ <path fill="#FFFFFF" d="M779.9,684.4L512,230L244.1,684.4L512,529.5L779.9,684.4z" />
4791
+ <path fill="#FFFFFF" d="M733.1,730L512,613.5L290.9,730L512,658L733.1,730z" />
4792
+ </svg>
4793
+ `)}`;
4794
+ var DeflyWebWallet = class extends AVMProvider {
4795
+ constructor({
4796
+ id,
4797
+ store,
4798
+ subscribe,
4799
+ getAlgodClient,
4800
+ metadata = {},
4801
+ networks
4802
+ }) {
4803
+ super({
4804
+ id,
4805
+ metadata,
4806
+ getAlgodClient,
4807
+ store,
4808
+ subscribe,
4809
+ networks,
4810
+ providerId: DEFLY_WEB_PROVIDER_ID
4811
+ });
4812
+ }
4813
+ static defaultMetadata = {
4814
+ name: "Defly Web Wallet",
4815
+ icon: ICON5
4816
+ };
4817
+ /**
4818
+ * Calls the "enable" method on the provider. This method will timeout after 3 minutes.
4819
+ * @returns {Promise<AVMWebProviderSDK.IEnableResult>} a promise that resolves to the result.
4820
+ * @protected
4821
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
4822
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
4823
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
4824
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
4825
+ * @throws {UnknownError} if the response result is empty.
4826
+ */
4827
+ async _enable() {
4828
+ const {
4829
+ ARC0027MethodEnum,
4830
+ ARC0027MethodTimedOutError,
4831
+ ARC0027UnknownError,
4832
+ DEFAULT_REQUEST_TIMEOUT
4833
+ } = await this._initializeAVMWebProviderSDK();
4834
+ const avmWebClient = await this._initializeAVMWebClient();
4835
+ const genesisHash = await this._getGenesisHash();
4836
+ return new Promise((resolve, reject) => {
4837
+ const timerId = window.setTimeout(() => {
4838
+ avmWebClient.removeListener(listenerId);
4839
+ reject(
4840
+ new ARC0027MethodTimedOutError({
4841
+ method: ARC0027MethodEnum.Enable,
4842
+ message: `no response from provider "${this.metadata.name}"`,
4843
+ providerId: DEFLY_WEB_PROVIDER_ID
4844
+ })
4845
+ );
4846
+ }, DEFAULT_REQUEST_TIMEOUT);
4847
+ const listenerId = avmWebClient.onEnable(({ error, method, result }) => {
4848
+ avmWebClient.removeListener(listenerId);
4849
+ window.clearTimeout(timerId);
4850
+ if (error) {
4851
+ return reject(error);
4852
+ }
4853
+ if (!result) {
4854
+ return reject(
4855
+ new ARC0027UnknownError({
4856
+ message: `received response, but "${method}" request details were empty for provider "${this.metadata.name}"`,
4857
+ providerId: DEFLY_WEB_PROVIDER_ID
4858
+ })
4859
+ );
4860
+ }
4861
+ return resolve(result);
4862
+ });
4863
+ avmWebClient.enable({
4864
+ genesisHash,
4865
+ providerId: DEFLY_WEB_PROVIDER_ID
4866
+ });
4867
+ });
4868
+ }
4869
+ /**
4870
+ * Calls the "disable" method on the provider. This method will timeout after 0.75 seconds.
4871
+ * @returns {Promise<AVMWebProviderSDK.IDisableResult>} a promise that resolves to the result.
4872
+ * @protected
4873
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
4874
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
4875
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
4876
+ * @throws {UnknownError} if the response result is empty.
4877
+ */
4878
+ async _disable() {
4879
+ const {
4880
+ ARC0027MethodEnum,
4881
+ ARC0027MethodTimedOutError,
4882
+ ARC0027UnknownError,
4883
+ LOWER_REQUEST_TIMEOUT
4884
+ } = await this._initializeAVMWebProviderSDK();
4885
+ const avmWebClient = await this._initializeAVMWebClient();
4886
+ const genesisHash = await this._getGenesisHash();
4887
+ return new Promise((resolve, reject) => {
4888
+ const timerId = window.setTimeout(() => {
4889
+ avmWebClient.removeListener(listenerId);
4890
+ reject(
4891
+ new ARC0027MethodTimedOutError({
4892
+ method: ARC0027MethodEnum.Disable,
4893
+ message: `no response from provider "${this.metadata.name}"`,
4894
+ providerId: DEFLY_WEB_PROVIDER_ID
4895
+ })
4896
+ );
4897
+ }, LOWER_REQUEST_TIMEOUT);
4898
+ const listenerId = avmWebClient.onDisable(({ error, method, result }) => {
4899
+ avmWebClient.removeListener(listenerId);
4900
+ window.clearTimeout(timerId);
4901
+ if (error) {
4902
+ return reject(error);
4903
+ }
4904
+ if (!result) {
4905
+ return reject(
4906
+ new ARC0027UnknownError({
4907
+ message: `received response, but "${method}" request details were empty for provider "${this.metadata.name}"`,
4908
+ providerId: DEFLY_WEB_PROVIDER_ID
4909
+ })
4910
+ );
4911
+ }
4912
+ this.logger.debug("Disable successful", { result });
4913
+ return resolve(result);
4914
+ });
4915
+ this.logger.debug("Sending disable request...", { genesisHash });
4916
+ avmWebClient.disable({
4917
+ genesisHash,
4918
+ providerId: DEFLY_WEB_PROVIDER_ID
4919
+ });
4920
+ });
4921
+ }
4922
+ /**
4923
+ * Calls the "signTransactions" method to sign the supplied ARC-0001 transactions. This method will timeout after 3
4924
+ * minutes.
4925
+ * @returns {Promise<AVMWebProviderSDK.ISignTransactionsResult>} a promise that resolves to the result.
4926
+ * @protected
4927
+ * @throws {InvalidInputError} if computed group ID for the txns does not match the assigned group ID.
4928
+ * @throws {InvalidGroupIdError} if the unsigned txns is malformed or not conforming to ARC-0001.
4929
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
4930
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
4931
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
4932
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
4933
+ * @throws {UnauthorizedSignerError} if a signer in the request is not authorized by the provider.
4934
+ * @throws {UnknownError} if the response result is empty.
4935
+ */
4936
+ async _signTransactions(txns) {
4937
+ const {
4938
+ ARC0027MethodEnum,
4939
+ ARC0027MethodTimedOutError,
4940
+ ARC0027UnknownError,
4941
+ DEFAULT_REQUEST_TIMEOUT
4942
+ } = await this._initializeAVMWebProviderSDK();
4943
+ const avmWebClient = await this._initializeAVMWebClient();
4944
+ return new Promise((resolve, reject) => {
4945
+ const timerId = window.setTimeout(() => {
4946
+ avmWebClient.removeListener(listenerId);
4947
+ reject(
4948
+ new ARC0027MethodTimedOutError({
4949
+ method: ARC0027MethodEnum.SignTransactions,
4950
+ message: `no response from provider "${this.metadata.name}"`,
4951
+ providerId: DEFLY_WEB_PROVIDER_ID
4952
+ })
4953
+ );
4954
+ }, DEFAULT_REQUEST_TIMEOUT);
4955
+ const listenerId = avmWebClient.onSignTransactions(({ error, method, result }) => {
4956
+ avmWebClient.removeListener(listenerId);
4957
+ window.clearTimeout(timerId);
4958
+ if (error) {
4959
+ return reject(error);
4960
+ }
4961
+ if (!result) {
4962
+ return reject(
4963
+ new ARC0027UnknownError({
4964
+ message: `received response, but "${method}" request details were empty for provider "${this.metadata.name}"`,
4965
+ providerId: DEFLY_WEB_PROVIDER_ID
4966
+ })
4967
+ );
4968
+ }
4969
+ this.logger.debug("Sign transactions successful", { result });
4970
+ return resolve(result);
4971
+ });
4972
+ this.logger.debug("Sending sign transactions request...", { txns });
4973
+ avmWebClient.signTransactions({
4974
+ txns,
4975
+ providerId: DEFLY_WEB_PROVIDER_ID
4976
+ });
4977
+ });
4978
+ }
4979
+ };
4980
+
4981
+ // src/wallets/exodus.ts
4982
+ var import_algosdk5 = __toESM(require("algosdk"), 1);
4983
+ var ICON6 = `data:image/svg+xml;base64,${btoa(`
4447
4984
  <svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
4448
4985
  <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)">
4449
4986
  <stop offset="0" stop-color="#0B46F9" />
@@ -4479,15 +5016,16 @@ var ExodusWallet = class extends BaseWallet {
4479
5016
  subscribe,
4480
5017
  getAlgodClient,
4481
5018
  options = {},
4482
- metadata = {}
5019
+ metadata = {},
5020
+ networks
4483
5021
  }) {
4484
- super({ id, metadata, getAlgodClient, store, subscribe });
5022
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
4485
5023
  this.options = options;
4486
5024
  this.store = store;
4487
5025
  }
4488
5026
  static defaultMetadata = {
4489
5027
  name: "Exodus",
4490
- icon: ICON5
5028
+ icon: ICON6
4491
5029
  };
4492
5030
  async initializeClient() {
4493
5031
  this.logger.info("Initializing client...");
@@ -4554,7 +5092,7 @@ var ExodusWallet = class extends BaseWallet {
4554
5092
  const txnsToSign = [];
4555
5093
  txnGroup.forEach((txn, index) => {
4556
5094
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4557
- const signer = import_algosdk4.default.encodeAddress(txn.from.publicKey);
5095
+ const signer = txn.sender.toString();
4558
5096
  const canSignTxn = this.addresses.includes(signer);
4559
5097
  const txnString = byteArrayToBase64(txn.toByte());
4560
5098
  if (isIndexMatch && canSignTxn) {
@@ -4568,11 +5106,11 @@ var ExodusWallet = class extends BaseWallet {
4568
5106
  processEncodedTxns(txnGroup, indexesToSign) {
4569
5107
  const txnsToSign = [];
4570
5108
  txnGroup.forEach((txnBuffer, index) => {
4571
- const txnDecodeObj = import_algosdk4.default.decodeObj(txnBuffer);
4572
- const isSigned = isSignedTxn(txnDecodeObj);
4573
- const txn = isSigned ? import_algosdk4.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk4.default.decodeUnsignedTransaction(txnBuffer);
5109
+ const decodedObj = import_algosdk5.default.msgpackRawDecode(txnBuffer);
5110
+ const isSigned = isSignedTxn(decodedObj);
5111
+ const txn = isSigned ? import_algosdk5.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk5.default.decodeUnsignedTransaction(txnBuffer);
4574
5112
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4575
- const signer = import_algosdk4.default.encodeAddress(txn.from.publicKey);
5113
+ const signer = txn.sender.toString();
4576
5114
  const canSignTxn = !isSigned && this.addresses.includes(signer);
4577
5115
  const txnString = byteArrayToBase64(txn.toByte());
4578
5116
  if (isIndexMatch && canSignTxn) {
@@ -4614,69 +5152,68 @@ var ExodusWallet = class extends BaseWallet {
4614
5152
  };
4615
5153
 
4616
5154
  // src/wallets/kibisis.ts
4617
- var import_algosdk5 = __toESM(require("algosdk"), 1);
4618
- function isAVMWebProviderSDKError(error) {
4619
- return typeof error === "object" && "code" in error && "message" in error;
4620
- }
4621
5155
  var KIBISIS_AVM_WEB_PROVIDER_ID = "f6d1c86b-4493-42fb-b88d-a62407b4cdf6";
4622
- var ICON6 = `data:image/svg+xml;base64,${btoa(`
5156
+ var ICON7 = `data:image/svg+xml;base64,${btoa(`
4623
5157
  <svg viewBox="0 0 480 480" xmlns="http://www.w3.org/2000/svg">
4624
5158
  <rect fill="#801C96" width="480" height="480" />
4625
5159
  <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" />
4626
5160
  <path fill="#FFFFFF" d="M158.1,359.8h19.7V245.5c-6.1-5.4-12.7-10-19.7-14V359.8z" />
4627
- </svg>
4628
- `)}`;
4629
- var KibisisWallet = class extends BaseWallet {
4630
- avmWebClient = null;
4631
- avmWebProviderSDK = null;
4632
- store;
5161
+ </svg>
5162
+ `)}`;
5163
+ var KibisisWallet = class extends AVMProvider {
4633
5164
  constructor({
4634
5165
  id,
4635
5166
  store,
4636
5167
  subscribe,
4637
5168
  getAlgodClient,
4638
- metadata = {}
5169
+ metadata = {},
5170
+ networks
4639
5171
  }) {
4640
- super({ id, metadata, getAlgodClient, store, subscribe });
4641
- this.store = store;
5172
+ super({
5173
+ id,
5174
+ metadata,
5175
+ getAlgodClient,
5176
+ store,
5177
+ subscribe,
5178
+ networks,
5179
+ providerId: KIBISIS_AVM_WEB_PROVIDER_ID
5180
+ });
4642
5181
  }
4643
5182
  static defaultMetadata = {
4644
5183
  name: "Kibisis",
4645
- icon: ICON6
5184
+ icon: ICON7
4646
5185
  };
4647
5186
  /**
4648
- * private functions
4649
- */
4650
- /**
4651
- * Calls the "disable" method on the provider. This method will timeout after 0.75 seconds.
4652
- * @returns {Promise<AVMWebProviderSDK.IDisableResult>} a promise that resolves to the result.
4653
- * @private
5187
+ * Calls the "enable" method on the provider. This method will timeout after 3 minutes.
5188
+ * @returns {Promise<AVMWebProviderSDK.IEnableResult>} a promise that resolves to the result.
5189
+ * @protected
5190
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
4654
5191
  * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
4655
5192
  * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
4656
5193
  * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
4657
5194
  * @throws {UnknownError} if the response result is empty.
4658
5195
  */
4659
- async _disable() {
5196
+ async _enable() {
4660
5197
  const {
4661
5198
  ARC0027MethodEnum,
4662
5199
  ARC0027MethodTimedOutError,
4663
5200
  ARC0027UnknownError,
4664
- LOWER_REQUEST_TIMEOUT
4665
- } = this.avmWebProviderSDK || await this._initializeAVMWebProviderSDK();
4666
- const avmWebClient = this.avmWebClient || await this._initializeAVMWebClient();
5201
+ DEFAULT_REQUEST_TIMEOUT
5202
+ } = await this._initializeAVMWebProviderSDK();
5203
+ const avmWebClient = await this._initializeAVMWebClient();
4667
5204
  const genesisHash = await this._getGenesisHash();
4668
5205
  return new Promise((resolve, reject) => {
4669
5206
  const timerId = window.setTimeout(() => {
4670
5207
  avmWebClient.removeListener(listenerId);
4671
5208
  reject(
4672
5209
  new ARC0027MethodTimedOutError({
4673
- method: ARC0027MethodEnum.Disable,
5210
+ method: ARC0027MethodEnum.Enable,
4674
5211
  message: `no response from provider "${this.metadata.name}"`,
4675
5212
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
4676
5213
  })
4677
5214
  );
4678
- }, LOWER_REQUEST_TIMEOUT);
4679
- const listenerId = avmWebClient.onDisable(({ error, method, result }) => {
5215
+ }, DEFAULT_REQUEST_TIMEOUT);
5216
+ const listenerId = avmWebClient.onEnable(({ error, method, result }) => {
4680
5217
  avmWebClient.removeListener(listenerId);
4681
5218
  window.clearTimeout(timerId);
4682
5219
  if (error) {
@@ -4690,47 +5227,44 @@ var KibisisWallet = class extends BaseWallet {
4690
5227
  })
4691
5228
  );
4692
5229
  }
4693
- this.logger.debug("Disable successful", { result });
4694
5230
  return resolve(result);
4695
5231
  });
4696
- this.logger.debug("Sending disable request...", { genesisHash });
4697
- avmWebClient.disable({
5232
+ avmWebClient.enable({
4698
5233
  genesisHash,
4699
5234
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
4700
5235
  });
4701
5236
  });
4702
5237
  }
4703
5238
  /**
4704
- * Calls the "enable" method on the provider. This method will timeout after 3 minutes.
4705
- * @returns {Promise<AVMWebProviderSDK.IEnableResult>} a promise that resolves to the result.
4706
- * @private
4707
- * @throws {MethodCanceledError} if the method was cancelled by the user.
5239
+ * Calls the "disable" method on the provider. This method will timeout after 0.75 seconds.
5240
+ * @returns {Promise<AVMWebProviderSDK.IDisableResult>} a promise that resolves to the result.
5241
+ * @protected
4708
5242
  * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
4709
5243
  * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
4710
5244
  * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
4711
5245
  * @throws {UnknownError} if the response result is empty.
4712
5246
  */
4713
- async _enable() {
5247
+ async _disable() {
4714
5248
  const {
4715
5249
  ARC0027MethodEnum,
4716
5250
  ARC0027MethodTimedOutError,
4717
5251
  ARC0027UnknownError,
4718
- DEFAULT_REQUEST_TIMEOUT
4719
- } = this.avmWebProviderSDK || await this._initializeAVMWebProviderSDK();
4720
- const avmWebClient = this.avmWebClient || await this._initializeAVMWebClient();
5252
+ LOWER_REQUEST_TIMEOUT
5253
+ } = await this._initializeAVMWebProviderSDK();
5254
+ const avmWebClient = await this._initializeAVMWebClient();
4721
5255
  const genesisHash = await this._getGenesisHash();
4722
5256
  return new Promise((resolve, reject) => {
4723
5257
  const timerId = window.setTimeout(() => {
4724
5258
  avmWebClient.removeListener(listenerId);
4725
5259
  reject(
4726
5260
  new ARC0027MethodTimedOutError({
4727
- method: ARC0027MethodEnum.Enable,
5261
+ method: ARC0027MethodEnum.Disable,
4728
5262
  message: `no response from provider "${this.metadata.name}"`,
4729
5263
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
4730
5264
  })
4731
5265
  );
4732
- }, DEFAULT_REQUEST_TIMEOUT);
4733
- const listenerId = avmWebClient.onEnable(({ error, method, result }) => {
5266
+ }, LOWER_REQUEST_TIMEOUT);
5267
+ const listenerId = avmWebClient.onDisable(({ error, method, result }) => {
4734
5268
  avmWebClient.removeListener(listenerId);
4735
5269
  window.clearTimeout(timerId);
4736
5270
  if (error) {
@@ -4744,60 +5278,21 @@ var KibisisWallet = class extends BaseWallet {
4744
5278
  })
4745
5279
  );
4746
5280
  }
4747
- this.logger.debug("Enable successful", { result });
5281
+ this.logger.debug("Disable successful", { result });
4748
5282
  return resolve(result);
4749
5283
  });
4750
- this.logger.debug("Sending enable request...", { genesisHash });
4751
- avmWebClient.enable({
5284
+ this.logger.debug("Sending disable request...", { genesisHash });
5285
+ avmWebClient.disable({
4752
5286
  genesisHash,
4753
5287
  providerId: KIBISIS_AVM_WEB_PROVIDER_ID
4754
5288
  });
4755
5289
  });
4756
5290
  }
4757
- async _getGenesisHash() {
4758
- const algodClient = this.getAlgodClient();
4759
- const version = await algodClient.versionsCheck().do();
4760
- return version.genesis_hash_b64;
4761
- }
4762
- async _initializeAVMWebClient() {
4763
- const avmWebProviderSDK = this.avmWebProviderSDK || await this._initializeAVMWebProviderSDK();
4764
- if (!this.avmWebClient) {
4765
- this.logger.info("Initializing new AVM Web Client...");
4766
- this.avmWebClient = avmWebProviderSDK.AVMWebClient.init();
4767
- this.logger.info("AVM Web Client initialized");
4768
- }
4769
- return this.avmWebClient;
4770
- }
4771
- async _initializeAVMWebProviderSDK() {
4772
- if (!this.avmWebProviderSDK) {
4773
- this.logger.info("Initializing @agoralabs-sh/avm-web-provider...");
4774
- const module2 = await import("@agoralabs-sh/avm-web-provider");
4775
- this.avmWebProviderSDK = module2.default ? module2.default : module2;
4776
- if (!this.avmWebProviderSDK) {
4777
- throw new Error(
4778
- "Failed to initialize, the @agoralabs-sh/avm-web-provider SDK was not provided"
4779
- );
4780
- }
4781
- if (!this.avmWebProviderSDK.AVMWebClient) {
4782
- throw new Error(
4783
- "Failed to initialize, AVMWebClient missing from @agoralabs-sh/avm-web-provider SDK"
4784
- );
4785
- }
4786
- this.logger.info("@agoralabs-sh/avm-web-provider initialized");
4787
- }
4788
- return this.avmWebProviderSDK;
4789
- }
4790
- _mapAVMWebProviderAccountToWalletAccounts(accounts) {
4791
- return accounts.map(({ address, name }, idx) => ({
4792
- name: name || `[${this.metadata.name}] Account ${idx + 1}`,
4793
- address
4794
- }));
4795
- }
4796
5291
  /**
4797
5292
  * Calls the "signTransactions" method to sign the supplied ARC-0001 transactions. This method will timeout after 3
4798
5293
  * minutes.
4799
5294
  * @returns {Promise<AVMWebProviderSDK.ISignTransactionsResult>} a promise that resolves to the result.
4800
- * @private
5295
+ * @protected
4801
5296
  * @throws {InvalidInputError} if computed group ID for the txns does not match the assigned group ID.
4802
5297
  * @throws {InvalidGroupIdError} if the unsigned txns is malformed or not conforming to ARC-0001.
4803
5298
  * @throws {MethodCanceledError} if the method was cancelled by the user.
@@ -4813,8 +5308,8 @@ var KibisisWallet = class extends BaseWallet {
4813
5308
  ARC0027MethodTimedOutError,
4814
5309
  ARC0027UnknownError,
4815
5310
  DEFAULT_REQUEST_TIMEOUT
4816
- } = this.avmWebProviderSDK || await this._initializeAVMWebProviderSDK();
4817
- const avmWebClient = this.avmWebClient || await this._initializeAVMWebClient();
5311
+ } = await this._initializeAVMWebProviderSDK();
5312
+ const avmWebClient = await this._initializeAVMWebClient();
4818
5313
  return new Promise((resolve, reject) => {
4819
5314
  const timerId = window.setTimeout(() => {
4820
5315
  avmWebClient.removeListener(listenerId);
@@ -4850,154 +5345,11 @@ var KibisisWallet = class extends BaseWallet {
4850
5345
  });
4851
5346
  });
4852
5347
  }
4853
- /**
4854
- * public functions
4855
- */
4856
- async connect() {
4857
- let result;
4858
- try {
4859
- this.logger.info("Connecting...");
4860
- result = await this._enable();
4861
- this.logger.info(`Successfully connected on network "${result.genesisId}"`);
4862
- } catch (error) {
4863
- this.logger.error(
4864
- "Error connecting:",
4865
- isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4866
- );
4867
- throw error;
4868
- }
4869
- const walletAccounts = this._mapAVMWebProviderAccountToWalletAccounts(result.accounts);
4870
- const walletState = {
4871
- accounts: walletAccounts,
4872
- activeAccount: walletAccounts[0]
4873
- };
4874
- addWallet(this.store, {
4875
- walletId: this.id,
4876
- wallet: walletState
4877
- });
4878
- this.logger.info("\u2705 Connected.", walletState);
4879
- return walletAccounts;
4880
- }
4881
- async disconnect() {
4882
- try {
4883
- this.logger.info("Disconnecting...");
4884
- this.onDisconnect();
4885
- const result = await this._disable();
4886
- this.logger.info(
4887
- `Successfully disconnected${result.sessionIds && result.sessionIds.length ? ` sessions [${result.sessionIds.join(",")}]` : ""} on network "${result.genesisId}"`
4888
- );
4889
- } catch (error) {
4890
- this.logger.error(
4891
- "Error disconnecting:",
4892
- isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4893
- );
4894
- throw error;
4895
- }
4896
- }
4897
- async resumeSession() {
4898
- const state = this.store.state;
4899
- const walletState = state.wallets[this.id];
4900
- let result;
4901
- if (!walletState) {
4902
- this.logger.info("No session to resume");
4903
- return;
4904
- }
4905
- try {
4906
- this.logger.info("Resuming session...");
4907
- result = await this._enable();
4908
- if (result.accounts.length === 0) {
4909
- throw new Error("No accounts found!");
4910
- }
4911
- const walletAccounts = this._mapAVMWebProviderAccountToWalletAccounts(result.accounts);
4912
- const match = compareAccounts(walletAccounts, walletState.accounts);
4913
- if (!match) {
4914
- this.logger.warn("Session accounts mismatch, updating accounts", {
4915
- prev: walletState.accounts,
4916
- current: walletAccounts
4917
- });
4918
- setAccounts(this.store, {
4919
- walletId: this.id,
4920
- accounts: walletAccounts
4921
- });
4922
- }
4923
- this.logger.info("Session resumed successfully");
4924
- } catch (error) {
4925
- this.logger.error(
4926
- "Error resuming session:",
4927
- isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4928
- );
4929
- this.onDisconnect();
4930
- throw error;
4931
- }
4932
- }
4933
- processTxns(txnGroup, indexesToSign) {
4934
- const txnsToSign = [];
4935
- txnGroup.forEach((txn, index) => {
4936
- const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4937
- const signer = import_algosdk5.default.encodeAddress(txn.from.publicKey);
4938
- const canSignTxn = this.addresses.includes(signer);
4939
- const txnString = byteArrayToBase64(txn.toByte());
4940
- if (isIndexMatch && canSignTxn) {
4941
- txnsToSign.push({ txn: txnString });
4942
- } else {
4943
- txnsToSign.push({ txn: txnString, signers: [] });
4944
- }
4945
- });
4946
- return txnsToSign;
4947
- }
4948
- processEncodedTxns(txnGroup, indexesToSign) {
4949
- const txnsToSign = [];
4950
- txnGroup.forEach((txnBuffer, index) => {
4951
- const txnDecodeObj = import_algosdk5.default.decodeObj(txnBuffer);
4952
- const isSigned = isSignedTxn(txnDecodeObj);
4953
- const txn = isSigned ? import_algosdk5.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk5.default.decodeUnsignedTransaction(txnBuffer);
4954
- const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
4955
- const signer = import_algosdk5.default.encodeAddress(txn.from.publicKey);
4956
- const canSignTxn = !isSigned && this.addresses.includes(signer);
4957
- const txnString = byteArrayToBase64(txn.toByte());
4958
- if (isIndexMatch && canSignTxn) {
4959
- txnsToSign.push({ txn: txnString });
4960
- } else {
4961
- txnsToSign.push({ txn: txnString, signers: [] });
4962
- }
4963
- });
4964
- return txnsToSign;
4965
- }
4966
- signTransactions = async (txnGroup, indexesToSign) => {
4967
- try {
4968
- this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
4969
- let txnsToSign = [];
4970
- if (isTransactionArray(txnGroup)) {
4971
- const flatTxns = flattenTxnGroup(txnGroup);
4972
- txnsToSign = this.processTxns(flatTxns, indexesToSign);
4973
- } else {
4974
- const flatTxns = flattenTxnGroup(txnGroup);
4975
- txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
4976
- }
4977
- this.logger.debug("Sending processed transactions to wallet...", txnsToSign);
4978
- const signTxnsResult = await this._signTransactions(txnsToSign);
4979
- this.logger.debug("Received signed transactions from wallet", signTxnsResult);
4980
- const result = signTxnsResult.stxns.map((value) => {
4981
- if (value === null) {
4982
- return null;
4983
- }
4984
- return base64ToByteArray(value);
4985
- });
4986
- this.logger.debug("Transactions signed successfully", result);
4987
- return result;
4988
- } catch (error) {
4989
- this.logger.error(
4990
- "Error signing transactions:",
4991
- isAVMWebProviderSDKError(error) ? `${error.message} (code: ${error.code})` : error.message
4992
- );
4993
- throw error;
4994
- }
4995
- };
4996
5348
  };
4997
5349
 
4998
5350
  // src/wallets/kmd.ts
4999
5351
  var import_algosdk6 = __toESM(require("algosdk"), 1);
5000
- var ICON7 = `data:image/svg+xml;base64,${btoa(`
5352
+ var ICON8 = `data:image/svg+xml;base64,${btoa(`
5001
5353
  <svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
5002
5354
  <linearGradient id="algokitGradient" gradientUnits="userSpaceOnUse" x1="0" y1="400" x2="400" y2="0">
5003
5355
  <stop offset="0" style="stop-color:#31D8EE"/>
@@ -5019,10 +5371,11 @@ var KmdWallet = class extends BaseWallet {
5019
5371
  store,
5020
5372
  subscribe,
5021
5373
  getAlgodClient,
5374
+ networks,
5022
5375
  options,
5023
5376
  metadata = {}
5024
5377
  }) {
5025
- super({ id, metadata, getAlgodClient, store, subscribe });
5378
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
5026
5379
  const {
5027
5380
  token = "a".repeat(64),
5028
5381
  baseServer = "http://127.0.0.1",
@@ -5035,7 +5388,7 @@ var KmdWallet = class extends BaseWallet {
5035
5388
  }
5036
5389
  static defaultMetadata = {
5037
5390
  name: "KMD",
5038
- icon: ICON7
5391
+ icon: ICON8
5039
5392
  };
5040
5393
  async initializeClient() {
5041
5394
  this.logger.info("Initializing client...");
@@ -5103,7 +5456,7 @@ var KmdWallet = class extends BaseWallet {
5103
5456
  const txnsToSign = [];
5104
5457
  txnGroup.forEach((txn, index) => {
5105
5458
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5106
- const signer = import_algosdk6.default.encodeAddress(txn.from.publicKey);
5459
+ const signer = txn.sender.toString();
5107
5460
  const canSignTxn = this.addresses.includes(signer);
5108
5461
  if (isIndexMatch && canSignTxn) {
5109
5462
  txnsToSign.push(txn);
@@ -5114,11 +5467,11 @@ var KmdWallet = class extends BaseWallet {
5114
5467
  processEncodedTxns(txnGroup, indexesToSign) {
5115
5468
  const txnsToSign = [];
5116
5469
  txnGroup.forEach((txnBuffer, index) => {
5117
- const txnDecodeObj = import_algosdk6.default.decodeObj(txnBuffer);
5118
- const isSigned = isSignedTxn(txnDecodeObj);
5470
+ const decodedObj = import_algosdk6.default.msgpackRawDecode(txnBuffer);
5471
+ const isSigned = isSignedTxn(decodedObj);
5119
5472
  const txn = isSigned ? import_algosdk6.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk6.default.decodeUnsignedTransaction(txnBuffer);
5120
5473
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5121
- const signer = import_algosdk6.default.encodeAddress(txn.from.publicKey);
5474
+ const signer = txn.sender.toString();
5122
5475
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5123
5476
  if (isIndexMatch && canSignTxn) {
5124
5477
  txnsToSign.push(txn);
@@ -5202,7 +5555,7 @@ var KmdWallet = class extends BaseWallet {
5202
5555
  };
5203
5556
 
5204
5557
  // src/wallets/liquid.ts
5205
- var ICON8 = `data:image/svg+xml;base64,${btoa(`
5558
+ var ICON9 = `data:image/svg+xml;base64,${btoa(`
5206
5559
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="249" height="249" viewBox="0 0 249 249" xml:space="preserve">
5207
5560
  <g transform="matrix(2.52 0 0 2.52 124.74 124.74)">
5208
5561
  <circle style="stroke: rgb(0,0,0); stroke-width: 19; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" cx="0" cy="0" r="40"/>
@@ -5225,9 +5578,10 @@ var LiquidWallet = class extends BaseWallet {
5225
5578
  subscribe,
5226
5579
  getAlgodClient,
5227
5580
  options,
5228
- metadata = {}
5581
+ metadata = {},
5582
+ networks
5229
5583
  }) {
5230
- super({ id, metadata, getAlgodClient, store, subscribe });
5584
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
5231
5585
  this.store = store;
5232
5586
  this.options = options ?? {
5233
5587
  RTC_config_username: "username",
@@ -5236,7 +5590,7 @@ var LiquidWallet = class extends BaseWallet {
5236
5590
  }
5237
5591
  static defaultMetadata = {
5238
5592
  name: "Liquid",
5239
- icon: ICON8
5593
+ icon: ICON9
5240
5594
  };
5241
5595
  async initializeClient() {
5242
5596
  this.logger.info("Initializing client...");
@@ -5320,7 +5674,7 @@ var import_algosdk7 = __toESM(require("algosdk"), 1);
5320
5674
  function isSignTxnsError(error) {
5321
5675
  return error instanceof Error && "code" in error;
5322
5676
  }
5323
- var ICON9 = `data:image/svg+xml;base64,${btoa(`
5677
+ var ICON10 = `data:image/svg+xml;base64,${btoa(`
5324
5678
  <svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
5325
5679
  <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.1,1.5,2.1,3.3,2.8,5.1c0.7,1.9,1.2,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.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" />
5326
5680
  </svg>
@@ -5335,9 +5689,10 @@ var LuteWallet = class extends BaseWallet {
5335
5689
  subscribe,
5336
5690
  getAlgodClient,
5337
5691
  options,
5338
- metadata = {}
5692
+ metadata = {},
5693
+ networks
5339
5694
  }) {
5340
- super({ id, metadata, getAlgodClient, store, subscribe });
5695
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
5341
5696
  if (!options?.siteName) {
5342
5697
  this.logger.error("Missing required option: siteName");
5343
5698
  throw new Error("Missing required option: siteName");
@@ -5347,7 +5702,7 @@ var LuteWallet = class extends BaseWallet {
5347
5702
  }
5348
5703
  static defaultMetadata = {
5349
5704
  name: "Lute",
5350
- icon: ICON9
5705
+ icon: ICON10
5351
5706
  };
5352
5707
  async initializeClient() {
5353
5708
  this.logger.info("Initializing client...");
@@ -5359,10 +5714,16 @@ var LuteWallet = class extends BaseWallet {
5359
5714
  return client;
5360
5715
  }
5361
5716
  async getGenesisId() {
5717
+ const network = this.activeNetworkConfig;
5718
+ if (network.genesisId) {
5719
+ return network.genesisId;
5720
+ }
5362
5721
  const algodClient = this.getAlgodClient();
5363
- const genesis = await algodClient.genesis().do();
5364
- const genesisId = `${genesis.network}-${genesis.id}`;
5365
- return genesisId;
5722
+ const genesisStr = await algodClient.genesis().do();
5723
+ const genesis = import_algosdk7.default.parseJSON(genesisStr, {
5724
+ intDecoding: import_algosdk7.default.IntDecoding.MIXED
5725
+ });
5726
+ return `${genesis.network}-${genesis.id}`;
5366
5727
  }
5367
5728
  connect = async () => {
5368
5729
  this.logger.info("Connecting...");
@@ -5414,7 +5775,7 @@ var LuteWallet = class extends BaseWallet {
5414
5775
  const txnsToSign = [];
5415
5776
  txnGroup.forEach((txn, index) => {
5416
5777
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5417
- const signer = import_algosdk7.default.encodeAddress(txn.from.publicKey);
5778
+ const signer = txn.sender.toString();
5418
5779
  const canSignTxn = this.addresses.includes(signer);
5419
5780
  const txnString = byteArrayToBase64(txn.toByte());
5420
5781
  if (isIndexMatch && canSignTxn) {
@@ -5428,11 +5789,11 @@ var LuteWallet = class extends BaseWallet {
5428
5789
  processEncodedTxns(txnGroup, indexesToSign) {
5429
5790
  const txnsToSign = [];
5430
5791
  txnGroup.forEach((txnBuffer, index) => {
5431
- const txnDecodeObj = import_algosdk7.default.decodeObj(txnBuffer);
5432
- const isSigned = isSignedTxn(txnDecodeObj);
5792
+ const decodedObj = import_algosdk7.default.msgpackRawDecode(txnBuffer);
5793
+ const isSigned = isSignedTxn(decodedObj);
5433
5794
  const txn = isSigned ? import_algosdk7.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk7.default.decodeUnsignedTransaction(txnBuffer);
5434
5795
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5435
- const signer = import_algosdk7.default.encodeAddress(txn.from.publicKey);
5796
+ const signer = txn.sender.toString();
5436
5797
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5437
5798
  const txnString = byteArrayToBase64(txn.toByte());
5438
5799
  if (isIndexMatch && canSignTxn) {
@@ -5472,7 +5833,7 @@ var LuteWallet = class extends BaseWallet {
5472
5833
 
5473
5834
  // src/wallets/magic.ts
5474
5835
  var import_algosdk8 = __toESM(require("algosdk"), 1);
5475
- var ICON10 = `data:image/svg+xml;base64,${btoa(`
5836
+ var ICON11 = `data:image/svg+xml;base64,${btoa(`
5476
5837
  <svg viewBox="0 0 47 47" xmlns="http://www.w3.org/2000/svg">
5477
5838
  <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" />
5478
5839
  </svg>
@@ -5488,9 +5849,10 @@ var MagicAuth = class extends BaseWallet {
5488
5849
  subscribe,
5489
5850
  getAlgodClient,
5490
5851
  options,
5491
- metadata = {}
5852
+ metadata = {},
5853
+ networks
5492
5854
  }) {
5493
- super({ id, metadata, getAlgodClient, store, subscribe });
5855
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
5494
5856
  if (!options?.apiKey) {
5495
5857
  this.logger.error("Missing required option: apiKey");
5496
5858
  throw new Error("Missing required option: apiKey");
@@ -5500,7 +5862,7 @@ var MagicAuth = class extends BaseWallet {
5500
5862
  }
5501
5863
  static defaultMetadata = {
5502
5864
  name: "Magic",
5503
- icon: ICON10
5865
+ icon: ICON11
5504
5866
  };
5505
5867
  async initializeClient() {
5506
5868
  this.logger.info("Initializing client...");
@@ -5618,7 +5980,7 @@ var MagicAuth = class extends BaseWallet {
5618
5980
  const txnsToSign = [];
5619
5981
  txnGroup.forEach((txn, index) => {
5620
5982
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5621
- const signer = import_algosdk8.default.encodeAddress(txn.from.publicKey);
5983
+ const signer = txn.sender.toString();
5622
5984
  const canSignTxn = this.addresses.includes(signer);
5623
5985
  const txnString = byteArrayToBase64(txn.toByte());
5624
5986
  if (isIndexMatch && canSignTxn) {
@@ -5632,11 +5994,11 @@ var MagicAuth = class extends BaseWallet {
5632
5994
  processEncodedTxns(txnGroup, indexesToSign) {
5633
5995
  const txnsToSign = [];
5634
5996
  txnGroup.forEach((txnBuffer, index) => {
5635
- const txnDecodeObj = import_algosdk8.default.decodeObj(txnBuffer);
5636
- const isSigned = isSignedTxn(txnDecodeObj);
5997
+ const decodedObj = import_algosdk8.default.msgpackRawDecode(txnBuffer);
5998
+ const isSigned = isSignedTxn(decodedObj);
5637
5999
  const txn = isSigned ? import_algosdk8.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk8.default.decodeUnsignedTransaction(txnBuffer);
5638
6000
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5639
- const signer = import_algosdk8.default.encodeAddress(txn.from.publicKey);
6001
+ const signer = txn.sender.toString();
5640
6002
  const canSignTxn = !isSigned && this.addresses.includes(signer);
5641
6003
  const txnString = byteArrayToBase64(txn.toByte());
5642
6004
  if (isIndexMatch && canSignTxn) {
@@ -5682,7 +6044,7 @@ var MagicAuth = class extends BaseWallet {
5682
6044
  // src/wallets/mnemonic.ts
5683
6045
  var import_algosdk9 = __toESM(require("algosdk"), 1);
5684
6046
  var LOCAL_STORAGE_MNEMONIC_KEY = `${LOCAL_STORAGE_KEY}_mnemonic`;
5685
- var ICON11 = `data:image/svg+xml;base64,${btoa(`
6047
+ var ICON12 = `data:image/svg+xml;base64,${btoa(`
5686
6048
  <svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
5687
6049
  <rect fill="#525252" width="400" height="400" />
5688
6050
  <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" />
@@ -5698,9 +6060,10 @@ var MnemonicWallet = class extends BaseWallet {
5698
6060
  subscribe,
5699
6061
  getAlgodClient,
5700
6062
  options,
5701
- metadata = {}
6063
+ metadata = {},
6064
+ networks
5702
6065
  }) {
5703
- super({ id, metadata, getAlgodClient, store, subscribe });
6066
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
5704
6067
  const { persistToStorage = false } = options || {};
5705
6068
  this.options = { persistToStorage };
5706
6069
  this.store = store;
@@ -5712,7 +6075,7 @@ var MnemonicWallet = class extends BaseWallet {
5712
6075
  }
5713
6076
  static defaultMetadata = {
5714
6077
  name: "Mnemonic",
5715
- icon: ICON11
6078
+ icon: ICON12
5716
6079
  };
5717
6080
  loadMnemonicFromStorage() {
5718
6081
  return StorageAdapter.getItem(LOCAL_STORAGE_MNEMONIC_KEY);
@@ -5725,12 +6088,12 @@ var MnemonicWallet = class extends BaseWallet {
5725
6088
  }
5726
6089
  checkMainnet() {
5727
6090
  try {
5728
- const network = this.activeNetwork;
5729
- if (network === "mainnet" /* MAINNET */) {
6091
+ const network = this.activeNetworkConfig;
6092
+ if (!network.isTestnet) {
5730
6093
  this.logger.warn(
5731
6094
  "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)."
5732
6095
  );
5733
- throw new Error("MainNet active network detected. Aborting.");
6096
+ throw new Error("Production network detected. Aborting.");
5734
6097
  }
5735
6098
  } catch (error) {
5736
6099
  this.disconnect();
@@ -5761,7 +6124,7 @@ var MnemonicWallet = class extends BaseWallet {
5761
6124
  const account = this.initializeAccount();
5762
6125
  const walletAccount = {
5763
6126
  name: `${this.metadata.name} Account`,
5764
- address: account.addr
6127
+ address: account.addr.toString()
5765
6128
  };
5766
6129
  const walletState = {
5767
6130
  accounts: [walletAccount],
@@ -5808,8 +6171,8 @@ var MnemonicWallet = class extends BaseWallet {
5808
6171
  const txnsToSign = [];
5809
6172
  txnGroup.forEach((txn, index) => {
5810
6173
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5811
- const signer = import_algosdk9.default.encodeAddress(txn.from.publicKey);
5812
- const canSignTxn = signer === this.account.addr;
6174
+ const signer = txn.sender.toString();
6175
+ const canSignTxn = signer === this.account.addr.toString();
5813
6176
  if (isIndexMatch && canSignTxn) {
5814
6177
  txnsToSign.push(txn);
5815
6178
  }
@@ -5819,12 +6182,12 @@ var MnemonicWallet = class extends BaseWallet {
5819
6182
  processEncodedTxns(txnGroup, indexesToSign) {
5820
6183
  const txnsToSign = [];
5821
6184
  txnGroup.forEach((txnBuffer, index) => {
5822
- const txnDecodeObj = import_algosdk9.default.decodeObj(txnBuffer);
5823
- const isSigned = isSignedTxn(txnDecodeObj);
6185
+ const decodedObj = import_algosdk9.default.msgpackRawDecode(txnBuffer);
6186
+ const isSigned = isSignedTxn(decodedObj);
5824
6187
  const txn = isSigned ? import_algosdk9.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk9.default.decodeUnsignedTransaction(txnBuffer);
5825
6188
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5826
- const signer = import_algosdk9.default.encodeAddress(txn.from.publicKey);
5827
- const canSignTxn = !isSigned && signer === this.account.addr;
6189
+ const signer = txn.sender.toString();
6190
+ const canSignTxn = !isSigned && signer === this.account.addr.toString();
5828
6191
  if (isIndexMatch && canSignTxn) {
5829
6192
  txnsToSign.push(txn);
5830
6193
  }
@@ -5855,7 +6218,7 @@ var MnemonicWallet = class extends BaseWallet {
5855
6218
 
5856
6219
  // src/wallets/pera.ts
5857
6220
  var import_algosdk10 = __toESM(require("algosdk"), 1);
5858
- var ICON12 = `data:image/svg+xml;base64,${btoa(`
6221
+ var ICON13 = `data:image/svg+xml;base64,${btoa(`
5859
6222
  <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
5860
6223
  <rect fill="#FFEE55" width="200" height="200" />
5861
6224
  <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" />
@@ -5876,15 +6239,16 @@ var PeraWallet = class extends BaseWallet {
5876
6239
  subscribe,
5877
6240
  getAlgodClient,
5878
6241
  options = {},
5879
- metadata = {}
6242
+ metadata = {},
6243
+ networks
5880
6244
  }) {
5881
- super({ id, metadata, getAlgodClient, store, subscribe });
6245
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
5882
6246
  this.options = options;
5883
6247
  this.store = store;
5884
6248
  }
5885
6249
  static defaultMetadata = {
5886
6250
  name: "Pera",
5887
- icon: ICON12
6251
+ icon: ICON13
5888
6252
  };
5889
6253
  async initializeClient() {
5890
6254
  this.logger.info("Initializing client...");
@@ -5990,7 +6354,7 @@ var PeraWallet = class extends BaseWallet {
5990
6354
  const txnsToSign = [];
5991
6355
  txnGroup.forEach((txn, index) => {
5992
6356
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
5993
- const signer = import_algosdk10.default.encodeAddress(txn.from.publicKey);
6357
+ const signer = txn.sender.toString();
5994
6358
  const canSignTxn = this.addresses.includes(signer);
5995
6359
  if (isIndexMatch && canSignTxn) {
5996
6360
  txnsToSign.push({ txn });
@@ -6003,11 +6367,11 @@ var PeraWallet = class extends BaseWallet {
6003
6367
  processEncodedTxns(txnGroup, indexesToSign) {
6004
6368
  const txnsToSign = [];
6005
6369
  txnGroup.forEach((txnBuffer, index) => {
6006
- const txnDecodeObj = import_algosdk10.default.decodeObj(txnBuffer);
6007
- const isSigned = isSignedTxn(txnDecodeObj);
6370
+ const decodedObj = import_algosdk10.default.msgpackRawDecode(txnBuffer);
6371
+ const isSigned = isSignedTxn(decodedObj);
6008
6372
  const txn = isSigned ? import_algosdk10.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk10.default.decodeUnsignedTransaction(txnBuffer);
6009
6373
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
6010
- const signer = import_algosdk10.default.encodeAddress(txn.from.publicKey);
6374
+ const signer = txn.sender.toString();
6011
6375
  const canSignTxn = !isSigned && this.addresses.includes(signer);
6012
6376
  if (isIndexMatch && canSignTxn) {
6013
6377
  txnsToSign.push({ txn });
@@ -6054,7 +6418,7 @@ var PeraWallet = class extends BaseWallet {
6054
6418
 
6055
6419
  // src/wallets/pera2.ts
6056
6420
  var import_algosdk11 = __toESM(require("algosdk"), 1);
6057
- var ICON13 = `data:image/svg+xml;base64,${btoa(`
6421
+ var ICON14 = `data:image/svg+xml;base64,${btoa(`
6058
6422
  <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
6059
6423
  <rect fill="#FFEE55" width="200" height="200" />
6060
6424
  <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" />
@@ -6075,9 +6439,10 @@ var PeraWallet2 = class extends BaseWallet {
6075
6439
  subscribe,
6076
6440
  getAlgodClient,
6077
6441
  options,
6078
- metadata = {}
6442
+ metadata = {},
6443
+ networks
6079
6444
  }) {
6080
- super({ id, metadata, getAlgodClient, store, subscribe });
6445
+ super({ id, metadata, getAlgodClient, store, subscribe, networks });
6081
6446
  if (!options?.projectId) {
6082
6447
  this.logger.error("Missing required option: projectId");
6083
6448
  throw new Error("Missing required option: projectId");
@@ -6087,7 +6452,7 @@ var PeraWallet2 = class extends BaseWallet {
6087
6452
  }
6088
6453
  static defaultMetadata = {
6089
6454
  name: "Pera",
6090
- icon: ICON13
6455
+ icon: ICON14
6091
6456
  };
6092
6457
  async initializeClient() {
6093
6458
  this.logger.info("Initializing client...");
@@ -6171,7 +6536,7 @@ var PeraWallet2 = class extends BaseWallet {
6171
6536
  const txnsToSign = [];
6172
6537
  txnGroup.forEach((txn, index) => {
6173
6538
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
6174
- const signer = import_algosdk11.default.encodeAddress(txn.from.publicKey);
6539
+ const signer = txn.sender.toString();
6175
6540
  const canSignTxn = this.addresses.includes(signer);
6176
6541
  if (isIndexMatch && canSignTxn) {
6177
6542
  txnsToSign.push({ txn });
@@ -6184,11 +6549,11 @@ var PeraWallet2 = class extends BaseWallet {
6184
6549
  processEncodedTxns(txnGroup, indexesToSign) {
6185
6550
  const txnsToSign = [];
6186
6551
  txnGroup.forEach((txnBuffer, index) => {
6187
- const txnDecodeObj = import_algosdk11.default.decodeObj(txnBuffer);
6188
- const isSigned = isSignedTxn(txnDecodeObj);
6552
+ const decodedObj = import_algosdk11.default.msgpackRawDecode(txnBuffer);
6553
+ const isSigned = isSignedTxn(decodedObj);
6189
6554
  const txn = isSigned ? import_algosdk11.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk11.default.decodeUnsignedTransaction(txnBuffer);
6190
6555
  const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
6191
- const signer = import_algosdk11.default.encodeAddress(txn.from.publicKey);
6556
+ const signer = txn.sender.toString();
6192
6557
  const canSignTxn = !isSigned && this.addresses.includes(signer);
6193
6558
  if (isIndexMatch && canSignTxn) {
6194
6559
  txnsToSign.push({ txn });
@@ -6239,6 +6604,7 @@ function createWalletMap() {
6239
6604
  ["biatec" /* BIATEC */]: BiatecWallet,
6240
6605
  ["custom" /* CUSTOM */]: CustomWallet,
6241
6606
  ["defly" /* DEFLY */]: DeflyWallet,
6607
+ ["defly-web" /* DEFLY_WEB */]: DeflyWebWallet,
6242
6608
  ["exodus" /* EXODUS */]: ExodusWallet,
6243
6609
  ["kibisis" /* KIBISIS */]: KibisisWallet,
6244
6610
  ["kmd" /* KMD */]: KmdWallet,
@@ -6284,11 +6650,17 @@ function byteArrayToString(array) {
6284
6650
  }
6285
6651
  return result;
6286
6652
  }
6287
- function isSignedTxn(txnDecodeObj) {
6288
- return txnDecodeObj.txn !== void 0;
6653
+ function isSignedTxn(txnObj) {
6654
+ if (!txnObj || typeof txnObj !== "object") return false;
6655
+ if (!("sig" in txnObj && "txn" in txnObj)) return false;
6656
+ if (!(txnObj.sig instanceof Uint8Array)) return false;
6657
+ const txn = txnObj.txn;
6658
+ if (!txn || typeof txn !== "object") return false;
6659
+ const hasRequiredProps = "type" in txn && "snd" in txn;
6660
+ return hasRequiredProps;
6289
6661
  }
6290
6662
  function isTransaction(item) {
6291
- return item && typeof item === "object" && "genesisID" in item && typeof item.genesisID === "string";
6663
+ return item && typeof item === "object" && "sender" in item && (item.sender instanceof import_algosdk12.default.Address || typeof item.sender === "string");
6292
6664
  }
6293
6665
  function isTransactionArray(txnGroup) {
6294
6666
  if (!Array.isArray(txnGroup) || txnGroup.length === 0) {
@@ -6318,24 +6690,6 @@ function formatJsonRpcRequest(method, params) {
6318
6690
  params
6319
6691
  };
6320
6692
  }
6321
- function deepMerge(target, source) {
6322
- const isObject = (obj) => obj && typeof obj === "object";
6323
- if (!isObject(target) || !isObject(source)) {
6324
- throw new Error("Target and source must be objects");
6325
- }
6326
- Object.keys(source).forEach((key) => {
6327
- const targetValue = target[key];
6328
- const sourceValue = source[key];
6329
- if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
6330
- target[key] = targetValue.concat(sourceValue);
6331
- } else if (isObject(targetValue) && isObject(sourceValue)) {
6332
- target[key] = deepMerge(Object.assign({}, targetValue), sourceValue);
6333
- } else {
6334
- target[key] = sourceValue;
6335
- }
6336
- });
6337
- return target;
6338
- }
6339
6693
 
6340
6694
  // src/manager.ts
6341
6695
  var WalletManager = class {
@@ -6347,24 +6701,27 @@ var WalletManager = class {
6347
6701
  logger;
6348
6702
  constructor({
6349
6703
  wallets = [],
6350
- network = "testnet" /* TESTNET */,
6351
- algod = {},
6704
+ networks,
6705
+ defaultNetwork = "testnet",
6352
6706
  options = {}
6353
6707
  } = {}) {
6354
6708
  this.logger = this.initializeLogger(options);
6355
6709
  this.logger.debug("Initializing WalletManager with config:", {
6356
6710
  wallets,
6357
- network,
6358
- algod,
6711
+ networks,
6712
+ defaultNetwork,
6359
6713
  options
6360
6714
  });
6361
- this.networkConfig = this.initNetworkConfig(network, algod);
6715
+ this.networkConfig = this.initNetworkConfig(networks);
6362
6716
  this.options = { resetNetwork: options.resetNetwork || false };
6363
6717
  const persistedState = this.loadPersistedState();
6364
- const activeNetwork = this.options.resetNetwork ? network : persistedState?.activeNetwork || network;
6718
+ const activeNetwork = this.options.resetNetwork ? defaultNetwork : persistedState?.activeNetwork || defaultNetwork;
6719
+ if (!this.networkConfig[activeNetwork]) {
6720
+ throw new Error(`Network "${activeNetwork}" not found in network configuration`);
6721
+ }
6365
6722
  const algodClient = this.createAlgodClient(activeNetwork);
6366
6723
  const initialState = {
6367
- ...defaultState,
6724
+ ...DEFAULT_STATE,
6368
6725
  ...persistedState,
6369
6726
  activeNetwork,
6370
6727
  algodClient
@@ -6457,7 +6814,8 @@ var WalletManager = class {
6457
6814
  options: walletOptions,
6458
6815
  getAlgodClient: this.getAlgodClient,
6459
6816
  store: this.store,
6460
- subscribe: this.subscribe
6817
+ subscribe: this.subscribe,
6818
+ networks: this.networkConfig
6461
6819
  });
6462
6820
  this._clients.set(walletId, walletInstance);
6463
6821
  this.logger.info(`\u2705 Initialized ${walletId}`);
@@ -6490,21 +6848,25 @@ var WalletManager = class {
6490
6848
  await Promise.all(promises);
6491
6849
  }
6492
6850
  // ---------- Network ----------------------------------------------- //
6493
- initNetworkConfig(network, config) {
6494
- this.logger.info("Initializing network...");
6495
- let networkConfig = createDefaultNetworkConfig();
6496
- if (isNetworkConfigMap(config)) {
6497
- networkConfig = deepMerge(networkConfig, config);
6498
- } else {
6499
- networkConfig[network] = deepMerge(networkConfig[network], config);
6851
+ initNetworkConfig(networks) {
6852
+ this.logger.info("Initializing network configuration...");
6853
+ const config = networks || createNetworkConfig();
6854
+ for (const [id, network] of Object.entries(config)) {
6855
+ if (!isNetworkConfig(network)) {
6856
+ throw new Error(`Invalid network configuration for "${id}"`);
6857
+ }
6500
6858
  }
6501
- this.logger.debug("Algodv2 config:", networkConfig);
6502
- return networkConfig;
6859
+ this.logger.debug("Network configuration:", config);
6860
+ return config;
6503
6861
  }
6504
6862
  createAlgodClient(networkId) {
6505
6863
  this.logger.info(`Creating Algodv2 client for ${networkId}...`);
6506
- const { token = "", baseServer, port = "", headers = {} } = this.networkConfig[networkId];
6507
- return new import_algosdk12.default.Algodv2(token, baseServer, port, headers);
6864
+ const network = this.networkConfig[networkId];
6865
+ if (!network) {
6866
+ throw new Error(`Network "${networkId}" not found in network configuration`);
6867
+ }
6868
+ const { token = "", baseServer, port = "", headers = {} } = network.algod;
6869
+ return new import_algosdk13.default.Algodv2(token, baseServer, port, headers);
6508
6870
  }
6509
6871
  getAlgodClient = () => {
6510
6872
  return this.algodClient;
@@ -6513,13 +6875,19 @@ var WalletManager = class {
6513
6875
  if (this.activeNetwork === networkId) {
6514
6876
  return;
6515
6877
  }
6878
+ if (!this.networkConfig[networkId]) {
6879
+ throw new Error(`Network "${networkId}" not found in network configuration`);
6880
+ }
6516
6881
  const algodClient = this.createAlgodClient(networkId);
6517
6882
  setActiveNetwork(this.store, { networkId, algodClient });
6518
- this.logger.info(`\u2705 Active network set to ${networkId}.`);
6883
+ this.logger.info(`\u2705 Active network set to ${networkId}`);
6519
6884
  };
6520
6885
  get activeNetwork() {
6521
6886
  return this.store.state.activeNetwork;
6522
6887
  }
6888
+ get networks() {
6889
+ return { ...this.networkConfig };
6890
+ }
6523
6891
  // ---------- Active Wallet ----------------------------------------- //
6524
6892
  get activeWallet() {
6525
6893
  const state = this.store.state;
@@ -6587,6 +6955,8 @@ var webpackFallback = {
6587
6955
  0 && (module.exports = {
6588
6956
  BaseWallet,
6589
6957
  CustomWallet,
6958
+ DEFAULT_NETWORKS,
6959
+ DEFAULT_STATE,
6590
6960
  DeflyWallet,
6591
6961
  ExodusWallet,
6592
6962
  ICON,
@@ -6606,8 +6976,6 @@ var webpackFallback = {
6606
6976
  WalletConnect,
6607
6977
  WalletId,
6608
6978
  WalletManager,
6609
- defaultState,
6610
- isAVMWebProviderSDKError,
6611
6979
  webpackFallback
6612
6980
  });
6613
6981
  //# sourceMappingURL=index.cjs.map