feat(wallet): IWalletAccount abstraction and WIF/xpub/xprv keystore import types

Introduce IWalletAccount interface to abstract HD, imported-xprv, WIF,
and watch-only account types. HdAccount implements the interface; the
new ImportedKeyAccount handles lists of WIF keys with fixed addresses
(no gap scanning, change returns to first address).

WalletLoader gains three factory methods:
- NewFromXpub: watch-only from SLIP-132 xpub/ypub/zpub
- NewFromXprv: spendable from SLIP-132 xprv/yprv/zprv
- NewFromWif: spendable from one or more WIF private keys

WalletDocument gains optional AccountXprv and WifKeys fields; AccountPath
and AccountXpub become nullable (absent for WIF wallets). IsWatchOnly
updated to cover all non-signing wallet kinds.

TransactionFactory and CLI OpenWallet() updated to IWalletAccount.
12 new unit tests in ImportedKeyAccountTests cover factory round-trips,
address derivation, and watch-only detection.
This commit is contained in:
2026-06-15 14:20:10 +02:00
parent 002c854497
commit 47b6064964
9 changed files with 459 additions and 18 deletions
+3 -2
View File
@@ -27,7 +27,7 @@ public sealed class BuiltTransaction
/// invia-tutto con fee sottratta, change sulla catena interna, RBF di default.
/// Con un account watch-only produce la PSBT non firmata (§6.5).
/// </summary>
public sealed class TransactionFactory(HdAccount account)
public sealed class TransactionFactory(IWalletAccount account)
{
private Network Network => PalladiumNetworks.For(account.Profile.Kind);
@@ -82,7 +82,8 @@ public sealed class TransactionFactory(HdAccount account)
if (!account.IsWatchOnly)
{
builder.AddKeys(spendable
.Select(u => account.GetExtPrivateKey(u.IsChange, u.AddressIndex))
.Select(u => account.GetPrivateKey(u.IsChange, u.AddressIndex))
.OfType<Key>()
.ToArray());
}