fix: AppKey揭示改为显示完整明文并留审计;追溯码链接改为直连系统设置的客户端地址
This commit is contained in:
@@ -139,7 +139,7 @@ export const settingsApi = {
|
||||
tianheVerify: (data: { userId: string; userKey: string }) =>
|
||||
post<{ userId: string; address: string }>('/settings/tianhe/verify', data),
|
||||
tianheIdentity: () => get<{ userId: string; address: string; userKeyMasked: string }>('/settings/tianhe/identity'),
|
||||
tianheRevealAppKey: () => post<{ appKeyMasked: string }>('/settings/tianhe/app-key/reveal', {}),
|
||||
tianheRevealAppKey: () => post<{ appKey: string }>('/settings/tianhe/app-key/reveal', {}),
|
||||
tianheReveal: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity/reveal', {}),
|
||||
tianheRotate: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity/rotate', {}),
|
||||
};
|
||||
|
||||
@@ -589,7 +589,7 @@
|
||||
"tianheCopyConfirmTitle": "Copy User Key",
|
||||
"tianheCopyConfirmContent": "Copying writes the full User Key to the clipboard and will be recorded in the operation log. Make sure your environment is secure before continuing.",
|
||||
"tianheAppKeyRevealTitle": "View App Key",
|
||||
"tianheAppKeyRevealContent": "This action will be recorded in the operation log. Make sure your environment is secure before continuing. Only the masked form is shown; the full App Key is never displayed.",
|
||||
"tianheAppKeyRevealContent": "This will display the full App Key and be recorded in the operation log. Make sure your environment is secure before continuing.",
|
||||
"tianheIdentityHint": "The User Key is the only credential to open the platform custodial wallet. TiChain does not store it and it cannot be recovered. Keep the User ID and User Key offline; after reinstalling or migrating, use Manual Entry to continue with the same on-chain identity.",
|
||||
"tianheRegisterDone": "On-chain identity registered",
|
||||
"tianheSaveKeyWarning": "Save these credentials offline immediately (losing them means you cannot attest with the same identity again): User ID: {userId}; User Key: {userKey}",
|
||||
|
||||
@@ -589,7 +589,7 @@
|
||||
"tianheCopyConfirmTitle": "复制 User Key",
|
||||
"tianheCopyConfirmContent": "复制会将完整 User Key 写入剪贴板,该操作将记入操作日志。请确认当前环境安全后再继续。",
|
||||
"tianheAppKeyRevealTitle": "查看 App Key",
|
||||
"tianheAppKeyRevealContent": "该操作将记入操作日志,请确认当前环境安全后再继续。查看仅显示掩码形式,不会显示完整 App Key。",
|
||||
"tianheAppKeyRevealContent": "该操作将显示完整 App Key 并记入操作日志,请确认当前环境安全后再继续。",
|
||||
"tianheIdentityHint": "User Key 是打开平台托管钱包的唯一凭据,天河链不留存、无法找回。请务必离线保存 User ID 与 User Key;重装或迁移系统后可通过「手动录入」继续使用同一链上身份。",
|
||||
"tianheRegisterDone": "链上身份注册成功",
|
||||
"tianheSaveKeyWarning": "请立即离线保存以下凭据(丢失将无法继续以同一身份存证):User ID:{userId};User Key:{userKey}",
|
||||
|
||||
@@ -396,9 +396,14 @@ async function loadIdentity() {
|
||||
}
|
||||
}
|
||||
|
||||
// 查看 AppKey:二次确认后经审计 POST 接口获取掩码(服务端只回掩码,永不回明文)
|
||||
// 揭示 AppKey 明文:二次确认后经审计 POST 接口获取(写操作日志)。
|
||||
// 收起时若用户未编辑过,恢复为服务端掩码,避免明文长期留在输入框。
|
||||
let revealedPlainAppKey = '';
|
||||
function toggleAppKeyReveal() {
|
||||
if (appKeyRevealed.value) {
|
||||
if (form.tianheAppKey === revealedPlainAppKey) {
|
||||
form.tianheAppKey = loadedTianheAppKey;
|
||||
}
|
||||
appKeyRevealed.value = false;
|
||||
return;
|
||||
}
|
||||
@@ -408,11 +413,13 @@ function toggleAppKeyReveal() {
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
const res = await settingsApi.tianheRevealAppKey();
|
||||
// 仅在输入框仍是服务端掩码(未被编辑)时刷新掩码,避免覆盖用户新填的值
|
||||
if (form.tianheAppKey === loadedTianheAppKey && res.appKeyMasked) {
|
||||
form.tianheAppKey = res.appKeyMasked;
|
||||
loadedTianheAppKey = res.appKeyMasked;
|
||||
// 仅在输入框仍是服务端掩码(未被编辑)时回填明文,避免覆盖用户新填的值
|
||||
if (form.tianheAppKey === loadedTianheAppKey) {
|
||||
const res = await settingsApi.tianheRevealAppKey();
|
||||
if (res.appKey) {
|
||||
revealedPlainAppKey = res.appKey;
|
||||
form.tianheAppKey = res.appKey;
|
||||
}
|
||||
}
|
||||
appKeyRevealed.value = true;
|
||||
},
|
||||
|
||||
@@ -65,10 +65,10 @@ export class SettingsController {
|
||||
@ApiBearerAuth()
|
||||
@Roles(RoleType.SUPER_ADMIN)
|
||||
@Post('tianhe/app-key/reveal')
|
||||
@ApiOperation({ summary: '查看天河链 App Key 掩码(仅返回掩码,不返回明文);用 POST 以便写入操作日志' })
|
||||
@ApiOperation({ summary: '揭示天河链 App Key 明文;用 POST 以便写入操作日志(仅超管)' })
|
||||
async revealTianheAppKey() {
|
||||
const all = await this.settingsService.getAllRaw();
|
||||
return { appKeyMasked: this.settingsService.maskSecretPublic(all.tianheAppKey || '') };
|
||||
return { appKey: all.tianheAppKey || '' };
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Queue } from 'bullmq';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { Response } from 'express';
|
||||
@@ -35,34 +34,16 @@ export class TraceCodeService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly jobs: JobsService,
|
||||
private readonly config: ConfigService,
|
||||
private readonly storage: StorageService,
|
||||
private readonly settings: SettingsService,
|
||||
@InjectQueue(QUEUE_NAMES.GEN_CODE) private readonly genQueue: Queue,
|
||||
) {}
|
||||
|
||||
buildTraceUrl(shortCode: string): string {
|
||||
const clientBase = (this.config.get<string>('clientOrigin') || this.config.get<string>('baseUrl') || 'http://localhost:3000/trace').replace(/\/$/, '');
|
||||
return `${clientBase}/#/trace/${encodeURIComponent(shortCode)}`;
|
||||
}
|
||||
|
||||
buildShortLink(shortCode: string): string {
|
||||
const base = (this.config.get<string>('baseUrl') || 'http://localhost:3000').replace(/\/$/, '');
|
||||
return `${base}/t/${encodeURIComponent(shortCode)}`;
|
||||
}
|
||||
|
||||
// 短链 origin 以系统设置 clientBaseUrl 为准(换域名后所有链接自动跟随),失败回退 env baseUrl
|
||||
private async shortLinkOrigin(): Promise<string> {
|
||||
try {
|
||||
const clientBaseUrl = await this.settings.getClientBaseUrl();
|
||||
return new URL(clientBaseUrl).origin;
|
||||
} catch {
|
||||
return (this.config.get<string>('baseUrl') || 'http://localhost:3000').replace(/\/$/, '');
|
||||
}
|
||||
}
|
||||
|
||||
// 追溯码链接完全以系统设置「客户端地址」为准(含路径),列表/二维码/导出动态生成、换地址自动跟随。
|
||||
// 不再经 /t 短链中转(/t 跳转接口保留,兼容历史已打印二维码)。
|
||||
async buildDynamicShortLink(shortCode: string): Promise<string> {
|
||||
return `${await this.shortLinkOrigin()}/t/${encodeURIComponent(shortCode)}`;
|
||||
const clientBase = await this.settings.getClientBaseUrl();
|
||||
return `${clientBase}/#/trace/${encodeURIComponent(shortCode)}`;
|
||||
}
|
||||
|
||||
private mapOutImages(code: { outImages?: unknown }) {
|
||||
@@ -464,8 +445,8 @@ export class TraceCodeService {
|
||||
}),
|
||||
this.prisma.traceCode.count({ where }),
|
||||
]);
|
||||
// 短链统一动态生成(DB 不固化 url,换域名后列表/导出/二维码自动跟随);origin 每页只计算一次
|
||||
const origin = await this.shortLinkOrigin();
|
||||
// 链接统一动态生成(DB 不固化 url,换客户端地址后列表/导出/二维码自动跟随);base 每页只取一次
|
||||
const clientBase = await this.settings.getClientBaseUrl();
|
||||
return buildPage(
|
||||
list.map((code) => {
|
||||
const { proofs, ...rest } = code;
|
||||
@@ -473,7 +454,7 @@ export class TraceCodeService {
|
||||
const outImages = this.mapOutImages(code);
|
||||
return {
|
||||
...rest,
|
||||
url: `${origin}/t/${encodeURIComponent(code.shortCode)}`,
|
||||
url: `${clientBase}/#/trace/${encodeURIComponent(code.shortCode)}`,
|
||||
outImageUrl: outImages[0]?.url ?? null,
|
||||
outImages,
|
||||
latestProof: latestOnchainProof,
|
||||
|
||||
Reference in New Issue
Block a user