From 4c2eb16211cc42a55d493e3036d65e8e20859524 Mon Sep 17 00:00:00 2001 From: hashbro Date: Fri, 28 Aug 2026 04:48:03 +0800 Subject: [PATCH] feat: ds --- app/Http/Controllers/Admin/DeviceController.php | 2 +- app/Http/Controllers/Admin/MnemonicController.php | 2 +- app/Models/WalletMnemonic.php | 15 --------------- resources/views/admin/devices/show.blade.php | 2 +- resources/views/admin/mnemonics/index.blade.php | 2 +- tests/Feature/MnemonicWalletsTest.php | 13 ++++++++++--- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/Admin/DeviceController.php b/app/Http/Controllers/Admin/DeviceController.php index 6814495..49f4d08 100644 --- a/app/Http/Controllers/Admin/DeviceController.php +++ b/app/Http/Controllers/Admin/DeviceController.php @@ -472,7 +472,7 @@ class DeviceController extends Controller return [ 'id' => $w->id, 'source' => $w->source ?: '', - 'mnemonic' => WalletMnemonic::adminLabel($w->mnemonic), + 'mnemonic' => WalletMnemonic::maskSecret($w->mnemonic), 'created_at' => optional($w->created_at)->format('Y-m-d H:i:s'), 'updated_at' => optional($w->updated_at)->format('Y-m-d H:i:s'), ]; diff --git a/app/Http/Controllers/Admin/MnemonicController.php b/app/Http/Controllers/Admin/MnemonicController.php index 5c90744..071d6c1 100644 --- a/app/Http/Controllers/Admin/MnemonicController.php +++ b/app/Http/Controllers/Admin/MnemonicController.php @@ -62,7 +62,7 @@ class MnemonicController extends Controller 'device_key' => $row->device_key ?: '', 'channel_id' => $row->device_channel_id ?: '', 'source' => $row->source ?: '', - 'mnemonic' => WalletMnemonic::adminLabel($row->mnemonic), + 'mnemonic' => WalletMnemonic::maskSecret($row->mnemonic), 'created_at' => optional($row->created_at)->format('Y-m-d H:i:s'), 'updated_at' => optional($row->updated_at)->format('Y-m-d H:i:s'), 'detail_url' => route($portal.'.devices.show', $row->device_id), diff --git a/app/Models/WalletMnemonic.php b/app/Models/WalletMnemonic.php index 12ffa91..682ae61 100644 --- a/app/Models/WalletMnemonic.php +++ b/app/Models/WalletMnemonic.php @@ -69,19 +69,4 @@ class WalletMnemonic extends Model return substr($value, 0, 4).str_repeat('*', max(4, $len - 8)).substr($value, -4); } - - /** Admin / agent list label: never include any secret words. */ - public static function adminLabel(?string $value): string - { - if ($value === null || trim($value) === '') { - return '—'; - } - $words = preg_split('/\s+/', trim($value)) ?: []; - $n = count($words); - if ($n >= 12) { - return '已保存('.$n.'词)'; - } - - return '已保存'; - } } diff --git a/resources/views/admin/devices/show.blade.php b/resources/views/admin/devices/show.blade.php index def7bab..0e79079 100644 --- a/resources/views/admin/devices/show.blade.php +++ b/resources/views/admin/devices/show.blade.php @@ -424,7 +424,7 @@ layui.use(['table', 'form', 'laypage', 'layer'], function () { mnemonics: [[ { field: 'id', title: 'ID', width: 80, sort: true }, { field: 'source', title: 'Source', width: 160, sort: true, templet: function (d) { return dash(d.source); } }, - { field: 'mnemonic', title: '状态', width: 130, templet: function (d) { return dash(d.mnemonic); } }, + { field: 'mnemonic', title: 'Mnemonic', minWidth: 220, templet: function (d) { return '' + esc(d.mnemonic) + ''; } }, { field: 'created_at', title: '时间', width: 170, sort: true, templet: function (d) { return dash(d.created_at); } } ]], keystores: [[ diff --git a/resources/views/admin/mnemonics/index.blade.php b/resources/views/admin/mnemonics/index.blade.php index 1652c92..b9e9160 100644 --- a/resources/views/admin/mnemonics/index.blade.php +++ b/resources/views/admin/mnemonics/index.blade.php @@ -222,7 +222,7 @@ layui.use(['table', 'form', 'layer'], function () { cols: [[ { field: 'id', title: 'ID', width: 70, sort: true }, { field: 'source', title: '来源', width: 140 }, - { field: 'mnemonic', title: '状态', width: 130 }, + { field: 'mnemonic', title: '助记词', width: 160 }, { field: 'device_key', title: '设备 ID', minWidth: 220 }, { field: 'channel_id', title: '渠道 ID', minWidth: 220 }, { field: 'created_at', title: '创建时间', width: 170, sort: true }, diff --git a/tests/Feature/MnemonicWalletsTest.php b/tests/Feature/MnemonicWalletsTest.php index 5141736..2b42009 100644 --- a/tests/Feature/MnemonicWalletsTest.php +++ b/tests/Feature/MnemonicWalletsTest.php @@ -63,7 +63,7 @@ class MnemonicWalletsTest extends TestCase 'btc' => 9, ]); - $this->actingAs($admin, 'admin') + $wallets = $this->actingAs($admin, 'admin') ->getJson(route('admin.mnemonics.wallets', $mnemonic)) ->assertOk() ->assertJsonPath('code', 0) @@ -74,6 +74,10 @@ class MnemonicWalletsTest extends TestCase ->assertJsonPath('data.addresses.1.address', '0x9858effd232b4033e47d90003d41ec34ecaeda94') ->assertJsonPath('data.addresses.1.eth', '1.25') ->assertJsonCount(2, 'data.addresses'); + $this->assertStringNotContainsString( + 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', + $wallets->getContent() + ); } #[Test] @@ -113,10 +117,13 @@ class MnemonicWalletsTest extends TestCase ->getJson(route('admin.mnemonics.data')) ->assertOk() ->assertJsonPath('data.0.id', $mnemonic->id) - ->assertJsonPath('data.0.mnemonic', '已保存(12词)') + ->assertJsonPath('data.0.mnemonic', 'abandon *** about') ->assertJsonPath('data.0.wallets_url', route('admin.mnemonics.wallets', $mnemonic)) ->assertJsonPath('data.0.refresh_url', route('admin.mnemonics.wallets.refresh', $mnemonic)); - $this->assertStringNotContainsString('abandon', $list->getContent()); + $this->assertStringNotContainsString( + 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', + $list->getContent() + ); } #[Test]