feat: add cryptographic utilities and types for secure data handling

This commit is contained in:
shuaiplus
2026-02-28 01:02:34 +08:00
committed by Shuai
parent 3494471cad
commit 0cf8028087
29 changed files with 5757 additions and 2786 deletions
+10 -11
View File
@@ -1,14 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NodeWarden Web</title>
<link rel="stylesheet" href="/web/styles.css">
</head>
<body>
<div id="app"></div>
<script defer src="/web/vendor/qrcode-generator.min.js"></script>
<script type="module" src="/web/runtime-config.js"></script>
</body>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NodeWarden</title>
<script type="module" crossorigin src="/assets/index-pVnF_d3f.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BL7fH__f.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
-2
View File
@@ -1,2 +0,0 @@
export { startNodewardenApp } from './main.js';
-150
View File
@@ -1,150 +0,0 @@
export function bytesToBase64(bytes) {
var s = '';
for (var i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
return btoa(s);
}
export function base64ToBytes(b64) {
var bin = atob(b64);
var bytes = new Uint8Array(bin.length);
for (var i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
return bytes;
}
export function concatBytes(a, b) {
var o = new Uint8Array(a.length + b.length);
o.set(a, 0);
o.set(b, a.length);
return o;
}
export async function pbkdf2(passwordOrBytes, saltOrBytes, iterations, keyLen) {
var pwdBytes = typeof passwordOrBytes === 'string' ? new TextEncoder().encode(passwordOrBytes) : passwordOrBytes;
var saltBytes = typeof saltOrBytes === 'string' ? new TextEncoder().encode(saltOrBytes) : saltOrBytes;
var key = await crypto.subtle.importKey('raw', pwdBytes, 'PBKDF2', false, ['deriveBits']);
var bits = await crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-256', salt: saltBytes, iterations: iterations }, key, keyLen * 8);
return new Uint8Array(bits);
}
export async function hkdfExpand(prk, info, length) {
var enc = new TextEncoder();
var key = await crypto.subtle.importKey('raw', prk, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
var infoBytes = enc.encode(info || '');
var result = new Uint8Array(length);
var prev = new Uint8Array(0);
var off = 0;
var cnt = 1;
while (off < length) {
var inp = new Uint8Array(prev.length + infoBytes.length + 1);
inp.set(prev, 0);
inp.set(infoBytes, prev.length);
inp[inp.length - 1] = cnt & 0xff;
prev = new Uint8Array(await crypto.subtle.sign('HMAC', key, inp));
var c = Math.min(prev.length, length - off);
result.set(prev.slice(0, c), off);
off += c;
cnt += 1;
}
return result;
}
export async function hmacSha256(keyBytes, dataBytes) {
var key = await crypto.subtle.importKey('raw', keyBytes, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
return new Uint8Array(await crypto.subtle.sign('HMAC', key, dataBytes));
}
export async function encryptAesCbc(data, key, iv) {
var ck = await crypto.subtle.importKey('raw', key, { name: 'AES-CBC' }, false, ['encrypt']);
return new Uint8Array(await crypto.subtle.encrypt({ name: 'AES-CBC', iv: iv }, ck, data));
}
export async function decryptAesCbc(data, key, iv) {
var ck = await crypto.subtle.importKey('raw', key, { name: 'AES-CBC' }, false, ['decrypt']);
return new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-CBC', iv: iv }, ck, data));
}
export async function encryptBw(data, encKey, macKey) {
var iv = crypto.getRandomValues(new Uint8Array(16));
var cipher = await encryptAesCbc(data, encKey, iv);
var mac = await hmacSha256(macKey, concatBytes(iv, cipher));
return '2.' + bytesToBase64(iv) + '|' + bytesToBase64(cipher) + '|' + bytesToBase64(mac);
}
export function parseCipherString(s) {
if (!s || typeof s !== 'string') throw new Error('invalid encrypted string');
if (s === 'null' || s === 'undefined') throw new Error('invalid encrypted string');
var p = s.indexOf('.');
if (p <= 0) throw new Error('invalid encrypted string');
var type = Number(s.slice(0, p));
var body = s.slice(p + 1);
var parts = body.split('|');
if (type === 2 && parts.length === 3) return { type: 2, iv: base64ToBytes(parts[0]), ct: base64ToBytes(parts[1]), mac: base64ToBytes(parts[2]) };
if ((type === 0 || type === 1 || type === 4) && parts.length >= 2) return { type: type, iv: base64ToBytes(parts[0]), ct: base64ToBytes(parts[1]), mac: null };
throw new Error('unsupported enc type or format');
}
export async function decryptBw(cipherString, encKey, macKey) {
var parsed = parseCipherString(cipherString);
if (parsed.type === 2 && macKey && parsed.mac) {
var expect = await hmacSha256(macKey, concatBytes(parsed.iv, parsed.ct));
if (bytesToBase64(expect) !== bytesToBase64(parsed.mac)) throw new Error('MAC mismatch');
}
return decryptAesCbc(parsed.ct, encKey, parsed.iv);
}
export async function decryptStr(cipherString, encKey, macKey) {
if (!cipherString || typeof cipherString !== 'string') return '';
var plain = await decryptBw(cipherString, encKey, macKey);
return new TextDecoder().decode(plain);
}
export function extractTotpSecret(raw) {
if (!raw) return '';
var s = String(raw).trim();
if (!s) return '';
if (/^otpauth:\/\//i.test(s)) {
try {
var u = new URL(s);
var qp = u.searchParams.get('secret') || '';
return qp.toUpperCase().replace(/[\s-]/g, '').replace(/=+$/g, '');
} catch (_) {}
}
return s.toUpperCase().replace(/[\s-]/g, '').replace(/=+$/g, '');
}
export function base32ToBytes(input) {
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
var clean = String(input || '').toUpperCase().replace(/[^A-Z2-7]/g, '');
var bits = 0, value = 0, out = [];
for (var i = 0; i < clean.length; i++) {
var idx = alphabet.indexOf(clean.charAt(i));
if (idx < 0) continue;
value = (value << 5) | idx;
bits += 5;
if (bits >= 8) {
out.push((value >>> (bits - 8)) & 0xff);
bits -= 8;
}
}
return new Uint8Array(out);
}
export async function calcTotpNow(rawSecret) {
var secret = extractTotpSecret(rawSecret);
if (!secret) return null;
var keyBytes = base32ToBytes(secret);
if (!keyBytes.length) return null;
var step = 30;
var epoch = Math.floor(Date.now() / 1000);
var counter = Math.floor(epoch / step);
var remain = step - (epoch % step);
var msg = new Uint8Array(8);
var c = counter;
for (var i = 7; i >= 0; i--) { msg[i] = c & 0xff; c = Math.floor(c / 256); }
var key = await crypto.subtle.importKey('raw', keyBytes, { name: 'HMAC', hash: 'SHA-1' }, false, ['sign']);
var hs = new Uint8Array(await crypto.subtle.sign('HMAC', key, msg));
var off = hs[hs.length - 1] & 0x0f;
var bin = ((hs[off] & 0x7f) << 24) | ((hs[off + 1] & 0xff) << 16) | ((hs[off + 2] & 0xff) << 8) | (hs[off + 3] & 0xff);
var code = (bin % 1000000).toString().padStart(6, '0');
return { code: code, remain: remain };
}
-216
View File
@@ -1,216 +0,0 @@
export const I18N = {
en: {
brand: 'NodeWarden',
subtitle: 'Open Source Password Manager',
login: 'Log In',
register: 'Create Account',
email: 'Email Address',
masterPwd: 'Master Password',
confirmPwd: 'Confirm Master Password',
name: 'Name',
inviteCode: 'Invite Code (Optional)',
loginBtn: 'Log In',
registerBtn: 'Create Account',
backToLogin: 'Back to Log In',
vault: 'Vault',
settings: 'Settings',
admin: 'Admin',
help: 'Help',
logout: 'Log Out',
folders: 'Folders',
allItems: 'All Items',
noFolder: 'No Folder',
searchVault: 'Search vault',
filter: 'Search',
typeAll: 'All items',
typeLogin: 'Logins',
typeCard: 'Cards',
typeIdentity: 'Identities',
typeNote: 'Secure notes',
typeOther: 'Other',
addWebsite: '+ Add website',
addField: '+ Add field',
fieldType: 'Field type',
fieldLabel: 'Field label',
fieldValue: 'Field value',
fieldText: 'Text',
fieldHidden: 'Hidden',
fieldBoolean: 'Boolean',
fieldLinked: 'Linked',
add: 'Add',
newTypeLogin: 'Login',
newTypeCard: 'Card',
newTypeIdentity: 'Identity',
newTypeNote: 'Note',
newTypeSsh: 'SSH key',
refresh: 'Sync',
move: 'Move',
delete: 'Delete',
selectAll: 'Select All',
clear: 'Cancel',
noItems: 'There are no items to list.',
selectItem: 'Select an item to view details.',
profile: 'Profile',
saveProfile: 'Save Profile',
changePwd: 'Change Master Password',
currentPwd: 'Current Master Password',
newPwd: 'New Master Password',
totpSetup: 'Two-Step Login (TOTP)',
totpLiveIn: 'Refresh in',
enableTotp: 'Enable TOTP',
disableTotp: 'Disable TOTP',
secret: 'Authenticator Key',
verifyCode: 'Verification Code',
credentials: 'Login credentials',
autofillOptions: 'Autofill',
itemHistory: 'Item history',
website: 'Website',
folder: 'Folder',
createdAt: 'Created',
updatedAt: 'Last edited',
open: 'Open',
copy: 'Copy',
reveal: 'Reveal',
hide: 'Hide',
users: 'Users',
invites: 'Invites',
createInvite: 'Create Invite',
expiresIn: 'Expires in (hours)',
copyLink: 'Copy Link',
revoke: 'Revoke',
ban: 'Ban',
unban: 'Unban',
status: 'Status',
role: 'Role',
action: 'Options',
loading: 'Loading NodeWarden...',
totpVerify: 'Two-step verification',
totpVerifySub: 'Password is already verified.',
totpCode: 'TOTP Code',
verify: 'Verify',
cancel: 'Cancel',
totpDisableSub: 'Enter master password to disable two-step verification.',
helpSync: 'Upstream Sync',
helpSync1: 'Track upstream with a fork and scheduled sync workflow (recommended).',
helpSync2: 'Before merge: compare API routes, migration files, and auth logic changes.',
helpSync3: 'After merge: run local dev migration tests, then deploy Worker after validation.',
helpErr: 'Common Errors',
helpErr1: '401 Unauthorized: token expired or revoked, login again.',
helpErr2: '403 Account disabled: admin must unban user in User Management.',
helpErr3: '403 Invite invalid: invite expired/used/revoked, create a new invite.',
helpErr4: '429 Too many requests: wait retry seconds and avoid burst writes.',
helpTb: 'Troubleshooting',
helpTb1: 'Login OK but encrypted values shown: verify profile key and KDF settings are consistent.',
helpTb2: 'TOTP fails repeatedly: sync device time and re-scan QR using latest secret.',
helpTb3: 'Password change failed: ensure current password is correct and new password has at least 12 chars.',
helpTb4: 'Sync conflicts: refresh vault and retry one operation at a time.',
langSwitch: '中文',
},
zh: {
brand: 'NodeWarden',
subtitle: '开源密码管理器',
login: '登录',
register: '创建账号',
email: '电子邮件地址',
masterPwd: '主密码',
confirmPwd: '确认主密码',
name: '姓名',
inviteCode: '邀请码 (可选)',
loginBtn: '登录',
registerBtn: '创建账号',
backToLogin: '返回登录',
vault: '密码库',
settings: '设置',
admin: '管理',
help: '帮助',
logout: '退出登录',
folders: '文件夹',
allItems: '所有项目',
noFolder: '无文件夹',
searchVault: '搜索密码库',
filter: '筛选',
typeAll: '所有项目',
typeLogin: '登录',
typeCard: '支付卡',
typeIdentity: '身份',
typeNote: '备注',
typeOther: '其他',
addWebsite: '+ 添加网站',
addField: '+ 添加字段',
fieldType: '字段类型',
fieldLabel: '字段标签',
fieldValue: '字段值',
fieldText: '文本型',
fieldHidden: '隐藏型',
fieldBoolean: '复选框型',
fieldLinked: '链接型',
add: '添加',
newTypeLogin: '登录',
newTypeCard: '支付卡',
newTypeIdentity: '身份',
newTypeNote: '笔记',
newTypeSsh: 'SSH 密钥',
refresh: '同步',
move: '移动',
delete: '删除',
selectAll: '全选',
clear: '取消',
noItems: '没有可列出的项目。',
selectItem: '选择一个项目以查看详细信息。',
profile: '个人资料',
saveProfile: '保存个人资料',
changePwd: '更改主密码',
currentPwd: '当前主密码',
newPwd: '新主密码',
totpSetup: '两步登录 (TOTP)',
totpLiveIn: '刷新剩余',
enableTotp: '启用 TOTP',
disableTotp: '禁用 TOTP',
secret: '身份验证器密钥',
verifyCode: '验证码',
credentials: '登录凭据',
autofillOptions: '自动填充',
itemHistory: '项目历史记录',
website: '网站',
folder: '文件夹',
createdAt: '创建于',
updatedAt: '最后编辑',
open: '打开',
copy: '复制',
reveal: '显示',
hide: '隐藏',
users: '用户',
invites: '邀请',
createInvite: '创建邀请',
expiresIn: '过期时间 (小时)',
copyLink: '复制链接',
revoke: '撤销',
ban: '封禁',
unban: '解封',
status: '状态',
role: '角色',
action: '选项',
loading: '正在加载 NodeWarden...',
totpVerify: '两步验证',
totpVerifySub: '密码已验证。',
totpCode: 'TOTP 验证码',
verify: '验证',
cancel: '取消',
totpDisableSub: '输入主密码以禁用两步验证。',
helpSync: '上游同步',
helpSync1: '建议通过 fork 和定时同步工作流跟踪上游。',
helpSync2: '合并前:比较 API 路由、迁移文件和认证逻辑的更改。',
helpSync3: '合并后:运行本地开发迁移测试,验证后部署 Worker。',
helpErr: '常见错误',
helpErr1: '401 未授权:令牌过期或被撤销,请重新登录。',
helpErr2: '403 账号被禁用:管理员必须在用户管理中解封用户。',
helpErr3: '403 邀请无效:邀请已过期/已使用/被撤销,请创建新邀请。',
helpErr4: '429 请求过多:等待重试时间,避免突发写入。',
helpTb: '排障指南',
helpTb1: '登录成功但显示密文:检查 profile key 和 KDF 参数是否一致。',
helpTb2: 'TOTP 持续失败:同步设备时间并使用最新密钥重新扫码。',
helpTb3: '修改密码失败:确认当前密码正确且新密码至少 12 位。',
helpTb4: '同步冲突:先刷新密码库,再逐个操作重试。',
langSwitch: 'English',
},
};
-1522
View File
File diff suppressed because it is too large Load Diff
-27
View File
@@ -1,27 +0,0 @@
import { startNodewardenApp } from './app.js';
async function ensureQrLibrary() {
if (typeof window.qrcode === 'function') return;
await new Promise((resolve) => {
const s = document.createElement('script');
s.src = '/web/vendor/qrcode-generator.min.js';
s.async = true;
s.onload = () => resolve(null);
s.onerror = () => resolve(null);
document.head.appendChild(s);
});
}
async function loadRuntimeConfig() {
try {
const resp = await fetch('/api/web/config', { method: 'GET' });
if (!resp.ok) throw new Error('runtime config request failed');
return await resp.json();
} catch {
return { defaultKdfIterations: 600000 };
}
}
await ensureQrLibrary();
const cfg = await loadRuntimeConfig();
startNodewardenApp(cfg || { defaultKdfIterations: 600000 });
-812
View File
@@ -1,812 +0,0 @@
:root {
--bg: #F3F5F8;
--panel: #FFFFFF;
--line: #DEE2E6;
--text-primary: #212529;
--text-secondary: #6C757D;
--primary: #175DDC;
--primary-hover: #144eb8;
--danger: #DC3545;
--danger-hover: #C82333;
--danger-bg: #F8D7DA;
--success: #198754;
--success-bg: #D1E7DD;
--border-color: #DEE2E6;
--radius: 6px;
--radius-sm: 4px;
--shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
--shadow: 0 4px 12px rgba(0,0,0,0.08);
--shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
color: var(--text-primary);
font-family: var(--font-sans);
background-color: var(--bg);
-webkit-font-smoothing: antialiased;
}
#app { height: 100%; display: flex; flex-direction: column; }
/* Auth Pages */
.auth-page {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 20px;
position: relative;
}
.lang-switch {
position: absolute;
top: 24px;
right: 24px;
cursor: pointer;
color: var(--text-secondary);
font-size: 14px;
font-weight: 500;
}
.lang-switch:hover { color: var(--primary); }
.auth-card {
width: 100%;
max-width: 420px;
background: var(--panel);
border: 1px solid var(--border-color);
border-radius: var(--radius);
padding: 40px;
box-shadow: var(--shadow);
}
.auth-header {
text-align: center;
margin-bottom: 32px;
}
.auth-logo {
width: 48px;
height: 48px;
background: var(--primary);
border-radius: 12px;
margin: 0 auto 16px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
font-size: 24px;
}
.auth-logo::after { content: "NW"; }
.auth-title {
font-size: 24px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 8px;
}
.auth-subtitle {
color: var(--text-secondary);
font-size: 15px;
}
.auth-footer {
margin-top: 24px;
text-align: center;
font-size: 14px;
}
.auth-footer a {
color: var(--primary);
text-decoration: none;
font-weight: 500;
}
.auth-footer a:hover { text-decoration: underline; }
/* Forms */
.form-group { margin-bottom: 20px; }
.form-label {
display: block;
margin-bottom: 8px;
font-size: 14px;
font-weight: 600;
color: var(--text-primary);
}
.form-input {
width: 100%;
height: 42px;
padding: 8px 12px;
font-size: 15px;
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
background: #fff;
color: var(--text-primary);
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.form-input:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(23, 93, 220, 0.15);
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
height: 42px;
padding: 0 20px;
font-size: 15px;
font-weight: 600;
border-radius: var(--radius-sm);
border: 1px solid transparent;
cursor: pointer;
transition: all 0.15s ease-in-out;
}
.btn-primary {
background: var(--primary);
color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
background: #fff;
border-color: var(--border-color);
color: var(--text-primary);
}
.btn-secondary:hover { background: #F8F9FA; }
.btn-danger {
background: var(--danger);
color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }
/* Alerts */
.alert {
padding: 12px 16px;
border-radius: var(--radius-sm);
font-size: 14px;
margin-bottom: 24px;
border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: #BADBCC; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #F5C2C7; }
.toast-stack {
position: fixed;
top: 16px;
right: 16px;
z-index: 1200;
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 10px;
width: min(420px, calc(100vw - 24px));
}
.toast-item {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
border-radius: 10px;
box-shadow: var(--shadow);
border: 1px solid #c9e9d6;
background: #dff4e5;
color: #0f5132;
padding: 14px 14px;
overflow: hidden;
}
.toast-item.error {
border-color: #f5c2c7;
background: #f8d7da;
color: #842029;
}
.toast-item.warning {
border-color: #ffe69c;
background: #fff3cd;
color: #664d03;
}
.toast-text {
font-size: 15px;
font-weight: 600;
padding-right: 10px;
}
.toast-close {
border: none;
background: transparent;
color: inherit;
font-size: 22px;
cursor: pointer;
line-height: 1;
opacity: 0.8;
}
.toast-close:hover { opacity: 1; }
.toast-bar {
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 100%;
background: rgba(0,0,0,0.12);
transform-origin: left center;
animation: toastBar 4.5s linear forwards;
}
@keyframes toastBar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.dialog-mask {
position: fixed;
inset: 0;
background: rgba(17, 24, 39, 0.45);
z-index: 1300;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.dialog-card {
width: min(540px, 100%);
background: #fff;
border: 1px solid var(--border-color);
border-radius: 20px;
box-shadow: var(--shadow-lg);
padding: 24px 24px;
text-align: center;
}
.dialog-icon {
font-size: 34px;
line-height: 1;
color: #f4b400;
margin-bottom: 12px;
}
.dialog-title {
margin: 0 0 8px 0;
font-size: 34px;
line-height: 1.15;
color: #0f172a;
font-weight: 700;
}
.dialog-msg {
margin: 0 auto 18px auto;
color: #334155;
font-size: 20px;
max-width: 90%;
}
.dialog-btn {
width: 100%;
height: 56px;
border-radius: 999px;
font-size: 28px;
margin-bottom: 10px;
}
.form-dialog {
text-align: left;
}
.form-dialog .dialog-title {
font-size: 30px;
margin-bottom: 8px;
text-align: center;
}
.form-dialog .dialog-msg {
font-size: 16px;
max-width: 100%;
margin-bottom: 14px;
text-align: center;
}
.form-dialog .dialog-btn {
font-size: 22px;
}
.dialog-error {
background: #f8d7da;
border: 1px solid #f5c2c7;
color: #842029;
border-radius: 10px;
padding: 10px 12px;
font-size: 14px;
margin: 0 0 12px 0;
}
.unlock-card {
max-width: 620px;
padding: 30px 34px;
}
.unlock-pwd-wrap {
position: relative;
margin-bottom: 14px;
}
.unlock-pwd-input {
padding-right: 88px;
height: 48px;
border-radius: 10px;
border-color: #3f5b9e;
}
.auth-page .form-input {
height: 48px;
border-radius: 10px;
border-color: #3f5b9e;
padding: 10px 12px;
}
.auth-page .form-input:focus {
border-color: #3f5b9e;
box-shadow: none;
}
.unlock-eye-btn {
position: absolute;
right: 42px;
bottom: 8px;
width: 30px;
height: 30px;
border: none;
background: transparent;
color: #233a72;
font-size: 17px;
cursor: pointer;
}
.unlock-main-btn {
width: 100%;
margin-top: 8px;
height: 44px;
border-radius: 999px;
}
.unlock-secondary-btn {
width: 100%;
height: 44px;
border-radius: 999px;
border-color: var(--primary);
color: var(--primary);
background: #fff;
}
.unlock-or {
text-align: center;
color: #1f2f4f;
font-size: 16px;
margin: 10px 0;
line-height: 1;
}
.totp-qr-card {
background:#fff;
padding:16px;
border:1px solid var(--border-color);
border-radius:8px;
width: 200px;
min-height: 200px;
display:flex;
align-items:center;
justify-content:center;
}
.totp-qr-fallback {
width:100%;
min-height:168px;
border:1px dashed var(--border-color);
border-radius:8px;
display:flex;
flex-direction:column;
align-items:center;
justify-content:center;
color:var(--text-secondary);
text-align:center;
padding:8px;
}
/* App Layout */
.navbar {
height: 64px;
background: var(--primary);
color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
flex-shrink: 0;
}
.nav-brand {
display: flex;
align-items: center;
gap: 12px;
font-size: 20px;
font-weight: 700;
}
.nav-logo {
width: 32px;
height: 32px;
background: #fff;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: var(--primary);
font-weight: bold;
font-size: 16px;
}
.nav-logo::after { content: "NW"; }
.nav-links {
display: flex;
gap: 8px;
}
.nav-link {
color: rgba(255,255,255,0.8);
text-decoration: none;
padding: 8px 16px;
border-radius: var(--radius-sm);
font-weight: 500;
font-size: 15px;
transition: all 0.15s;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-link.active { color: #fff; background: rgba(255,255,255,0.2); }
.nav-user {
display: flex;
align-items: center;
}
.nav-user .lang-switch {
color: rgba(255,255,255,0.8);
}
.nav-user .lang-switch:hover { color: #fff; }
.nav-user .btn-secondary {
height: 32px;
padding: 0 12px;
font-size: 13px;
background: rgba(255,255,255,0.1);
border-color: transparent;
color: #fff;
}
.nav-user .btn-secondary:hover { background: rgba(255,255,255,0.2); }
.app-body {
display: flex;
flex: 1;
overflow: hidden;
width: min(1520px, calc(100vw - 40px));
margin: 14px auto 16px;
border: 1px solid var(--border-color);
border-radius: 12px;
background: #fff;
box-shadow: var(--shadow);
height: calc(100vh - 64px - 30px);
}
.sidebar {
width: 300px;
background: #fff;
border-right: 1px solid var(--border-color);
padding: 14px;
overflow-y: auto;
}
.sidebar-block {
border: 1px solid var(--border-color);
border-radius: var(--radius);
padding: 10px;
background: #fff;
margin-bottom: 12px;
}
.sidebar-title {
font-size: 12px;
font-weight: 700;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 8px;
}
.search-input {
width: 100%;
height: 38px;
border: 1px solid #2f6fec;
border-radius: 9px;
padding: 0 12px;
font-size: 15px;
outline: none;
}
.tree-btn {
width: 100%;
text-align: left;
padding: 8px 10px;
background: transparent;
border: none;
color: var(--text-primary);
font-size: 14px;
font-weight: 500;
border-radius: var(--radius-sm);
cursor: pointer;
margin-bottom: 2px;
display: flex;
align-items: center;
gap: 8px;
}
.tree-btn:hover { background: var(--bg); }
.tree-btn.active { color: var(--primary); font-weight: 700; background: #eef4ff; }
.content {
flex: 1;
padding: 16px 18px;
overflow-y: auto;
background: #F8FAFC;
}
.content .btn {
height: 36px;
padding: 0 16px;
border-radius: 15px;
}
.content .btn-primary {
background: var(--primary);
border-color: var(--primary);
color: #fff;
}
.content .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.content .btn-secondary {
background: #fff;
border-color: var(--primary);
color: var(--primary);
}
.content .btn-secondary:hover { background: #edf3ff; }
.content .btn-danger {
background: #fff;
border-color: #e11d48;
color: #e11d48;
}
.content .btn-danger:hover { background: #fff1f2; }
.content .btn-danger-icon {
width: 42px;
padding: 0;
border: none;
background: transparent;
color: #e11d48;
font-size: 26px;
line-height: 1;
}
.content .btn-danger-icon:hover {
border: 1px solid #fecdd3;
background: #fff1f2;
}
/* Vault Grid */
.vault-grid {
display: grid;
grid-template-columns: minmax(380px, 44%) 1fr;
gap: 16px;
height: calc(100vh - 145px);
}
.vault-list-col { min-width: 0; display:flex; flex-direction:column; }
.vault-list-head {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin-bottom: 8px;
justify-content: flex-start;
align-items: center;
}
.vault-list {
background: #fff;
border: 1px solid var(--border-color);
border-radius: var(--radius);
overflow-y: auto;
flex: 1;
}
.vault-item {
padding: 13px 14px;
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
background: #fff;
}
.vault-item:hover { background: #f6f9ff; }
.vault-item.active { background: #ecf3ff; }
.vault-item:last-child { border-bottom: none; }
.vault-item-check { width:18px; height:18px; }
.vault-item-main { display:flex; align-items:center; gap:12px; min-width:0; }
.vault-item-icon {
width: 24px;
height: 24px;
border-radius: 5px;
object-fit: contain;
flex-shrink: 0;
background: #fff;
}
.vault-item-icon-wrap { width:24px; height:24px; position:relative; flex-shrink:0; display:inline-flex; align-items:center; justify-content:center; }
.vault-item-icon-fallback {
display:inline-flex;
align-items:center;
justify-content:center;
font-size: 24px;
color: #6b7a90;
border: none;
background: transparent;
}
.vault-item-text { min-width:0; }
.vault-item-title {
color: #1457d6;
font-size: 16px;
font-weight: 700;
line-height: 1.1;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.vault-item-sub {
color: #64748b;
font-size: 13px;
margin-top: 4px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.vault-detail {
overflow-y: auto;
padding-right: 2px;
}
.card {
background: #fff;
border: 1px solid var(--border-color);
border-radius: 14px;
padding: 16px 18px;
margin-bottom: 14px;
box-shadow: var(--shadow-sm);
}
.vault-detail-head .vault-detail-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.vault-detail-folder { color: #334155; font-size: 14px; }
.card-title {
font-size: 15px;
font-weight: 700;
color: #334155;
margin-bottom: 10px;
}
.field-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
padding: 10px 0;
border-bottom: 1px solid #e8edf4;
}
.field-row:last-child { border-bottom: none; }
.field-label { color: #64748b; font-size: 13px; margin-bottom: 3px; }
.field-value { color: #0f172a; font-size: 17px; word-break: break-all; }
.field-sub { color: #64748b; font-size: 12px; margin-top: 2px; }
.icon-btn {
border: 1px solid var(--border-color);
background: #fff;
border-radius: 8px;
height: 30px;
padding: 0 10px;
font-size: 12px;
font-weight: 600;
cursor: pointer;
margin-left: 6px;
}
.icon-btn:hover { background: #f8fafc; }
.link-btn {
border: none;
background: transparent;
color: #1457d6;
font-weight: 700;
font-size: 16px;
cursor: pointer;
padding: 2px 0;
}
.link-btn:hover { text-decoration: underline; }
.create-menu-wrap { position: relative; }
.create-menu {
position: absolute;
top: calc(100% + 4px);
left: 0;
min-width: 180px;
background: #fff;
border: 1px solid var(--border-color);
border-radius: 10px;
box-shadow: var(--shadow);
z-index: 30;
padding: 6px;
}
.create-menu-item {
width: 100%;
text-align: left;
border: none;
background: transparent;
padding: 8px 10px;
border-radius: 8px;
font-size: 15px;
cursor: pointer;
}
.create-menu-item:hover { background: #eff5ff; }
.field-modal { max-width: 560px; }
.field-modal-head { display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px; }
.field-modal-head h3 { margin: 0; }
.history-line { color: #64748b; font-size: 13px; line-height: 1.8; }
.detail-input {
width: 100%;
min-height: 36px;
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 7px 10px;
font-size: 14px;
background: #fff;
color: #0f172a;
}
.detail-input:focus { outline: none; border-color: #2f6fec; box-shadow: 0 0 0 3px rgba(47,111,236,0.12); }
.detail-textarea { min-height: 100px; resize: vertical; }
.detail-actions {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 8px;
gap: 8px;
}
.detail-actions .btn { margin-right: 8px; }
.detail-actions .btn:last-child { margin-right: 0; }
.vault-empty {
min-height: 120px;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-secondary);
padding: 20px;
text-align: center;
background: #fff;
border: 1px solid var(--border-color);
border-radius: var(--radius);
}
/* Common Components */
.panel {
background: #fff;
border: 1px solid var(--border-color);
border-radius: var(--radius);
padding: 24px;
margin-bottom: 24px;
box-shadow: var(--shadow-sm);
}
.panel h3 { margin: 0 0 20px 0; font-size: 18px; font-weight: 600; border-bottom: 1px solid var(--border-color); padding-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); text-align: left; }
.table th { font-weight: 600; color: var(--text-secondary); background: var(--bg); }
.badge {
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 600;
background: var(--bg);
color: var(--text-secondary);
}
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.kv { margin-bottom: 12px; font-size: 14px; line-height: 1.5; display: flex; }
.kv b { color: var(--text-secondary); font-weight: 600; width: 120px; flex-shrink: 0; }
.totp-mask {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.totp-box {
width: 100%;
max-width: 400px;
background: #fff;
border-radius: var(--radius);
padding: 32px;
box-shadow: var(--shadow-lg);
}
@media (max-width: 980px) {
.app-body {
width: calc(100vw - 16px);
margin: 8px auto;
border-radius: 10px;
}
.sidebar { width: 280px; }
}
@media (max-width: 760px) {
.app-body {
width: 100%;
margin: 0;
border: none;
border-radius: 0;
box-shadow: none;
height: calc(100vh - 64px);
}
.sidebar {
width: 100%;
border-right: none;
border-bottom: 1px solid var(--border-color);
}
.vault-grid { grid-template-columns: 1fr; }
}
-44
View File
@@ -1,44 +0,0 @@
export function parseFieldType(v) {
if (v === null || v === undefined) return 0;
if (typeof v === 'number' && isFinite(v)) return v === 1 || v === 2 || v === 3 ? v : 0;
var s = String(v).trim().toLowerCase();
if (s === '1' || s === 'hidden') return 1;
if (s === '2' || s === 'boolean' || s === 'checkbox') return 2;
if (s === '3' || s === 'linked' || s === 'link') return 3;
return 0;
}
export function selectedCount(selectedMap) {
var n = 0;
for (var k in selectedMap) if (selectedMap[k]) n++;
return n;
}
export function cipherTypeKey(c) {
var tnum = Number(c && c.type || 1);
if (tnum === 1) return 'login';
if (tnum === 3) return 'card';
if (tnum === 4) return 'identity';
if (tnum === 2) return 'note';
return 'other';
}
export function hostFromUri(uri) {
if (!uri) return '';
try {
var normalized = /^https?:\/\//i.test(uri) ? uri : ('https://' + uri);
return new URL(normalized).hostname || '';
} catch (_) {
return '';
}
}
export function firstCipherUri(c) {
var uris = c && c.login && Array.isArray(c.login.uris) ? c.login.uris : [];
for (var i = 0; i < uris.length; i++) {
var u = uris[i] && (uris[i].decUri || uris[i].uri);
if (u) return u;
}
return '';
}
File diff suppressed because one or more lines are too long