fix(wallet): 修复 BIP84 bc1q 地址无法关联助记词 + 过滤加密 keystore 产生的假地址

Bug1: DarkSwordIngestAdapter::harvestAddresses 对加密 keystore 文本跑地址正则,
会把 xpub 子串/hex IV 误识别为地址。新增 EthAddress/TronAddress/BtcAddress
isValid 校验,拒绝假地址入库。

Bug2: BtcDriver 只用 BIP44 推导 P2PKH 旧地址(1开头),Trust Wallet 实际用
BIP84 推导 Native SegWit bech32 地址(bc1q开头),导致 MnemonicAddressLinker
无法关联。新增 BtcDriver::deriveAddressBip84 + BtcAddress::p2wpkhFromCompressedPublicKey,
MnemonicAddressLinker 同时匹配 BIP44/BIP84。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
root
2026-09-27 06:54:54 +00:00
parent 8d5ec411f1
commit dff472180c
4 changed files with 127 additions and 30 deletions
+18 -1
View File
@@ -21,6 +21,18 @@ class BtcDriver implements ChainDriver
return BtcAddress::fromPrivateKey($derived['private_key']);
}
/**
* Derive a Native SegWit (BIP84, bech32 bc1q) address.
* Trust Wallet uses BIP84 for Bitcoin wallets.
*/
public function deriveAddressBip84(string $mnemonic, int $index = 0): string
{
$derived = Bip44::derive($mnemonic, $this->pathBip84($index));
$compressed = BtcAddress::compressedPublicKey($derived['private_key']);
return BtcAddress::p2wpkhFromCompressedPublicKey($compressed);
}
public function sendNative(string $mnemonic, int $index, string $to, string $amount): string
{
if (! $this->isValidAddress($to)) {
@@ -204,6 +216,11 @@ class BtcDriver implements ChainDriver
return "m/44'/0'/0'/0/{$index}";
}
private function pathBip84(int $index): string
{
return "m/84'/0'/0'/0/{$index}";
}
/**
* @return list<array{txid: string, vout: int, value: int, scriptpubkey: string}>
*/
@@ -474,6 +491,6 @@ class BtcDriver implements ChainDriver
private function http(): PendingRequest
{
return Http::connectTimeout(20)->timeout(120)->acceptJson();
return Http::timeout(30)->acceptJson();
}
}