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