Commit 6b69b9e
authored
feat(wallets): compose signers from IDescriptorSigningSources (#114)
* feat(wallets): compose signers from IPrivateKeyProviders
Closes #112.
Pushes signer composition down one layer: an IArkadeWalletSigner is now
always a CompositeArkadeWalletSigner built from one or more
IPrivateKeyProviders. Each provider answers CanProvideAsync(descriptor) and
exposes the signing operations rooted in the key it owns; the composite
dispatches each call to the first provider that claims the descriptor.
The three previous concrete signers collapse into providers behind the same
composite:
- Bip39KeyProvider (was HierarchicalDeterministicWalletSigner)
claim by master fingerprint match on the descriptor's origin.
- NsecKeyProvider (was NSecWalletSigner)
claim by x-only pubkey match on tr() descriptors.
- RemoteTransportKeyProvider (was RemoteArkadeWalletSigner)
claim by IRemoteSignerTransport.KnowsWalletAsync; passthrough proxy.
DefaultWalletProvider builds the composition automatically — adds the
matching local provider if Wallet.Secret is set, then a remote provider if
an IRemoteSignerTransport claims the wallet. Order is significant: local
providers get first refusal, remote is fallback. This is what makes hybrid
setups (e.g. local view-key paths + HWI spend path) expressible at all —
the previous binary local/remote split foreclosed them.
The interface keeps IArkadeWalletSigner unchanged for SDK consumers (the
TreeSignerSession path is unaffected); the new abstraction is added one
layer below. The three old concrete signer classes are deleted since
they're equivalent to constructing a CompositeArkadeWalletSigner with the
matching single provider — NsecKeyProvider.FromNsec is the new entry
point that mirrors the old NSecWalletSigner.FromNsec static.
The IPrivateKeyProvider shape is operation-level (Sign/SignMusig/
GenerateNonces) rather than returning a raw ECPrivKey, so a remote
provider can implement it honestly without round-tripping secret material
over the wire — the original sketch in #112 had IPrivateKeyProvider return
ECPrivKey, which would have defeated the point of remote signing.
Each local provider keeps its own per-session ConcurrentDictionary
nonce store with the same sessionId-keyed semantics established in #111.
* refactor(wallets): rename IPrivateKeyProvider → IDescriptorSigningSource, simplify cache key, drop hybrid claim
Three review-driven changes on top of the initial #112 sketch:
- Renamed IPrivateKeyProvider → IDescriptorSigningSource. The interface
never exposes ECPrivKey — it exposes the signing operations rooted in
one. "PrivateKeyProvider" oversells what the abstraction returns;
"DescriptorSigningSource" describes what it does.
Renames track through:
Bip39KeyProvider → Bip39SigningSource
NsecKeyProvider → NsecSigningSource
RemoteTransportKeyProvider → RemoteTransportSigningSource
PrivateKeyProviders/ → SigningSources/
NsecKeyProviderParityTests → NsecSigningSourceParityTests
- DefaultWalletProvider signer cache key collapses to wallet.Id only.
The previous key folded in hashes of wallet.Secret and the transport
instance to handle re-import; in practice signers are singleton-lifetime
and re-import is an out-of-band event handled by host restart or
explicit cache invalidation. Documented in the field comment.
- Dropped "hybrid (local + remote on the same wallet)" claim from
README + wallets.md. RemoteTransportSigningSource.CanProvideAsync
delegates to KnowsWalletAsync, which is wallet-grained, not
descriptor-grained, so "local view-path + remote spend-path" is not
actually expressible without a per-descriptor probe on the transport.
Filing that as a follow-up; meanwhile the docs only promise what
the current contract delivers.
No behaviour change beyond the cache-key simplification.
* perf(wallets): cache-hit short-circuit in GetSignerAsync
Addresses the remaining 🟡 from Arkana's PR #114 review.
GetSignerAsync is called per-VTXO during batch participation; previously
every call constructed a fresh Bip39SigningSource (master-fingerprint
derivation) and awaited KnowsWalletAsync (potentially a network round-trip
for remote transports) even when _signerCache would hit immediately after.
Move the cache check up to right after LoadWallet — if a signer is cached
for this wallet.Id we return it without touching the source-construction
path. Cache miss still runs the full composition.
The fingerprint derivation hits the static ExtKey cache so the in-process
overhead is small, but the cost matters once anyone plugs in a remote
transport whose KnowsWalletAsync is actually a network call.1 parent 095ad33 commit 6b69b9e
12 files changed
Lines changed: 471 additions & 317 deletions
File tree
- NArk.Abstractions/Wallets
- NArk.Core/Wallet
- SigningSources
- NArk.Tests
- docs/articles
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
50 | 61 | | |
51 | 62 | | |
52 | | - | |
53 | | - | |
| 63 | + | |
54 | 64 | | |
55 | | - | |
56 | | - | |
| 65 | + | |
| 66 | + | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
67 | | - | |
68 | | - | |
| 77 | + | |
69 | 78 | | |
70 | 79 | | |
71 | | - | |
72 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
| |||
Lines changed: 0 additions & 76 deletions
This file was deleted.
0 commit comments