upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/db.h
diff options
context:
space:
mode:
authorBitflash <btf01@proton.me>2026-08-01 17:53:17 -0300
committerGitHub <noreply@github.com>2026-08-01 17:53:17 -0300
commitce59d8c72c667ce638bd12f37db26d8b3408a5d2 (patch)
tree95c62a0d0cc0a21bc3349264ce0a3c949deb32c3 /src/db.h
parent593cf346dbce0a8ce46a13a73a4f78ddd044ab52 (diff)
wallet: derive the key pool from a seed, so a phrase could bring it back (#93)
Adds BIP32 derivation behind the wallet key pool, with no user-facing way to create a seed yet. wallet.dat gains hdmaster/hdchaincode/hdnext; the mnemonic is never stored. TopUpKeyPool derives m/n' when a seed exists and falls back to a random key, with a log line, if derivation fails. New -selftest=wallet-hd, wired into make tests on both platforms.
Diffstat (limited to 'src/db.h')
-rw-r--r--src/db.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/db.h b/src/db.h
index f51047e..01b8583 100644
--- a/src/db.h
+++ b/src/db.h
@@ -386,6 +386,33 @@ public:
386 return Write(string("defaultkey"), vchPubKey); 386 return Write(string("defaultkey"), vchPubKey);
387 } 387 }
388 388
389 // --- Deterministic (BIP32) seed ---------------------------------------
390 //
391 // Stored as the master key and chain code rather than the mnemonic: the
392 // twelve words are the user's to write down, and keeping a copy of them in
393 // the file they are meant to protect defeats the point of having them.
394 //
395 // "hdnext" is the next child index to derive, so the sequence a restore
396 // reproduces is the same one this wallet handed out.
397 bool ReadHDMaster(vector<unsigned char>& vchMasterRet, vector<unsigned char>& vchChainCodeRet)
398 {
399 vchMasterRet.clear();
400 vchChainCodeRet.clear();
401 return Read(string("hdmaster"), vchMasterRet)
402 && Read(string("hdchaincode"), vchChainCodeRet);
403 }
404
405 bool WriteHDMaster(const vector<unsigned char>& vchMaster, const vector<unsigned char>& vchChainCode)
406 {
407 return Write(string("hdmaster"), vchMaster)
408 && Write(string("hdchaincode"), vchChainCode);
409 }
410
411 bool WriteHDNext(unsigned int nNext)
412 {
413 return Write(string("hdnext"), nNext);
414 }
415
389 // Keys generated ahead of time and not yet handed out. The private key of 416 // Keys generated ahead of time and not yet handed out. The private key of
390 // each is already stored under its own "key" record by AddKey; a "pool" 417 // each is already stored under its own "key" record by AddKey; a "pool"
391 // record only says that this one is still unspoken for. 418 // record only says that this one is still unspoken for.