'', 'decrypted' => 0, 'raw_json' => [ 'kind' => 'keychain.wallets', 'wallets' => [ 'trustwallet' => [ 'items' => [ ['account' => 'trust.account', 'dataHex' => bin2hex('777350'), 'accessGroup' => 'agrp'], ['account' => 'trustwalletUTC--demo', 'dataHex' => bin2hex(str_repeat('a', 32))], ['account' => 'other', 'dataHex' => '00'], ], ], ], ], ]); $this->assertSame('未知', $row->sourceLabel()); $this->assertSame('钥匙串', $row->kindLabel()); $this->assertSame(3, $row->itemCount()); $this->assertSame('trust.account · trustwalletUTC--demo · other', $row->summary()); $this->assertSame('777350', $row->listedItems()[0]['data_preview']); $this->assertSame('agrp', $row->listedItems()[0]['access_group']); } #[Test] public function same_sandbox_bytes_share_one_hash(): void { $json = '{"device_uuid":"69DD25B2CA8B5682"}'; $asFile = [ 'kind' => 'sandbox', 'sandbox' => ['trust_wallet' => $json], ]; $asNested = [ 'kind' => 'sandbox', 'sandbox' => [ 'trust_wallet' => [ 'Documents/keystore/wallet.json' => base64_encode($json), ], ], ]; $this->assertSame( WalletKeystore::hashPayload($asFile), WalletKeystore::hashPayload($asNested), ); $this->assertNotSame( WalletKeystore::hashPayload($asFile), WalletKeystore::hashPayload([ 'kind' => 'sandbox', 'sandbox' => ['trust_wallet' => '{"device_uuid":"other"}'], ]), ); } #[Test] public function string_wallet_bucket_does_not_break_listing(): void { $row = new WalletKeystore([ 'source' => 'Trust Wallet', 'raw_json' => [ 'kind' => 'keychain.wallets', 'wallets' => [ 'trustwallet' => '{"device_uuid":"69DD25B2CA8B5682"}', ], ], ]); $this->assertSame(1, $row->itemCount()); $this->assertSame('trustwallet', $row->listedItems()[0]['account']); $this->assertSame('钥匙串', $row->kindLabel()); $this->assertNotSame('', $row->summary()); } #[Test] public function list_stats_match_listed_items_without_hashing_blobs(): void { $json = [ 'kind' => 'keychain.wallets', 'wallets' => [ 'trustwallet' => [ 'items' => [ ['account' => 'trust.account', 'dataHex' => bin2hex('777350')], ['account' => 'other', 'dataHex' => '00'], ], ], ], ]; $stats = WalletKeystore::computeListStatsFromJson($json); $this->assertSame(2, $stats['item_count']); $this->assertSame('钥匙串', $stats['kind']); $this->assertSame('trust.account · other', $stats['summary']); $this->assertFalse($stats['has_web3_keystore']); } #[Test] public function nested_sandbox_utc_counts_as_web3_keystore(): void { $row = new WalletKeystore([ 'source' => 'Trust Wallet', 'raw_json' => [ 'kind' => 'sandbox', 'sandbox' => [ 'Trust Wallet' => [ 'Documents' => [ 'keystore' => [ 'UTC--demo' => [ 'crypto' => [ 'ciphertext' => 'aa', 'mac' => 'bb', ], ], ], ], ], ], ], ]); $this->assertTrue($row->hasWeb3Keystore()); $this->assertSame('沙盒文件', $row->kindLabel()); } }