fix: 天河链对接修复 T1-T3/T6-T8(托管钱包注册与身份生命周期)

- TianheProvider 新增 registerUser/userInfo/ensureRegistered(接口1/8),attest 前幂等确保钱包已注册
- userDto 分段改为 application/json 类型 Blob,避免 Media Type Error
- 严格校验 code===0 且必须返回 transactionHash,杜绝以本地 dataHash 冒充链上哈希的假上链
- upload 响应不再提取恒空的区块信息,注释固化"每物一条 proof、独立 txHash"不变量
- userKey 改为一次性随机生成并明文持久化(不再从 appKey 派生),明文存储保证备份跨重装可恢复
- 新增 /settings/tianhe/register|verify|identity 接口与设置页链上身份区(注册/显示地址/揭示复制/手动录入校验)
- 单测扩至 27 个:新增注册、严格校验、userDto 类型、ensureRegistered 回退用例
This commit is contained in:
Nixevol
2026-07-09 19:05:32 +08:00
parent 8a7032070a
commit fa4215bd52
9 changed files with 512 additions and 104 deletions
+4
View File
@@ -134,6 +134,10 @@ export const userApi = {
export const settingsApi = {
getAll: () => get<Record<string, string>>('/settings'),
update: (data: object) => put('/settings', data),
tianheRegister: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/register', {}),
tianheVerify: (data: { userId: string; userKey: string }) =>
post<{ userId: string; address: string }>('/settings/tianhe/verify', data),
tianheIdentity: () => get<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity'),
};
export const storageApi = {
+19 -1
View File
@@ -545,7 +545,25 @@
"tianheEnvCustom": "Custom",
"tianheBaseUrl": "API URL",
"tianheAppId": "App ID",
"tianheAppKey": "App Key"
"tianheAppKey": "App Key",
"tianheIdentity": "On-chain Identity (Platform Custodial Wallet)",
"tianheWalletAddress": "Wallet Address",
"tianheNotRegistered": "Not registered",
"tianheRegister": "Register Identity",
"tianheReRegister": "Re-verify Identity",
"tianheManualEntry": "Manual Entry",
"tianheReveal": "Reveal",
"tianheHide": "Hide",
"tianheCopy": "Copy",
"tianheCopied": "User Key copied",
"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}",
"tianheVerifySave": "Verify & Save",
"tianheVerifyOk": "Verified. On-chain identity saved",
"tianheManualHint": "Enter the saved User ID and User Key. The system verifies them with TiChain before saving (for reusing the existing wallet after reinstall/migration).",
"tianheManualUserIdPh": "e.g. artveris-platform",
"tianheManualUserKeyPh": "The User Key you saved offline"
},
"profile": {
"title": "Personal Info",
+19 -1
View File
@@ -545,7 +545,25 @@
"tianheEnvCustom": "自定义",
"tianheBaseUrl": "接口地址",
"tianheAppId": "App ID",
"tianheAppKey": "App Key"
"tianheAppKey": "App Key",
"tianheIdentity": "链上身份(平台托管钱包)",
"tianheWalletAddress": "钱包地址",
"tianheNotRegistered": "未注册",
"tianheRegister": "注册链上身份",
"tianheReRegister": "重新确认身份",
"tianheManualEntry": "手动录入",
"tianheReveal": "揭示",
"tianheHide": "隐藏",
"tianheCopy": "复制",
"tianheCopied": "User Key 已复制",
"tianheIdentityHint": "User Key 是打开平台托管钱包的唯一凭据,天河链不留存、无法找回。请务必离线保存 User ID 与 User Key;重装或迁移系统后可通过「手动录入」继续使用同一链上身份。",
"tianheRegisterDone": "链上身份注册成功",
"tianheSaveKeyWarning": "请立即离线保存以下凭据(丢失将无法继续以同一身份存证):User ID:{userId};User Key:{userKey}",
"tianheVerifySave": "校验并保存",
"tianheVerifyOk": "校验通过,链上身份已保存",
"tianheManualHint": "输入已保存的 User ID 与 User Key,系统将向天河链校验后保存(用于重装/迁移后复用既有钱包)。",
"tianheManualUserIdPh": "如 artveris-platform",
"tianheManualUserKeyPh": "已离线保存的 User Key"
},
"profile": {
"title": "个人信息",
+152 -2
View File
@@ -116,8 +116,59 @@
<n-input v-model:value="form.tianheAppKey" type="password" show-password-on="click" class="text-control" />
</n-form-item>
</div>
<template v-if="form.blockchainDriver === 'tianhe'">
<div class="setting-row identity-head">
<span class="identity-title">{{ t('pages.settings.tianheIdentity') }}</span>
<div class="card-actions">
<n-button size="small" :loading="registeringIdentity" @click="registerIdentity">
{{ identity.address ? t('pages.settings.tianheReRegister') : t('pages.settings.tianheRegister') }}
</n-button>
<n-button size="small" @click="manualEntryVisible = true">{{ t('pages.settings.tianheManualEntry') }}</n-button>
</div>
</div>
<div class="setting-row">
<n-form-item :label="t('pages.settings.tianheWalletAddress')">
<span class="identity-value mono">{{ identity.address || t('pages.settings.tianheNotRegistered') }}</span>
</n-form-item>
</div>
<div class="setting-row">
<n-form-item label="User ID">
<span class="identity-value mono">{{ identity.userId || '-' }}</span>
</n-form-item>
</div>
<div class="setting-row">
<n-form-item label="User Key">
<div class="identity-key">
<span class="identity-value mono">{{ identity.userKey ? (revealKey ? identity.userKey : maskKey(identity.userKey)) : '-' }}</span>
<n-button v-if="identity.userKey" size="tiny" quaternary @click="revealKey = !revealKey">
{{ revealKey ? t('pages.settings.tianheHide') : t('pages.settings.tianheReveal') }}
</n-button>
<n-button v-if="identity.userKey" size="tiny" quaternary @click="copyUserKey">{{ t('pages.settings.tianheCopy') }}</n-button>
</div>
</n-form-item>
</div>
<p class="identity-hint">{{ t('pages.settings.tianheIdentityHint') }}</p>
</template>
</section>
<n-modal
v-model:show="manualEntryVisible"
preset="dialog"
:title="t('pages.settings.tianheManualEntry')"
:positive-text="t('pages.settings.tianheVerifySave')"
:negative-text="t('common.action.cancel')"
:loading="verifyingIdentity"
@positive-click="verifyIdentity"
>
<p class="identity-hint">{{ t('pages.settings.tianheManualHint') }}</p>
<n-form-item label="User ID">
<n-input v-model:value="manualEntry.userId" :placeholder="t('pages.settings.tianheManualUserIdPh')" />
</n-form-item>
<n-form-item label="User Key">
<n-input v-model:value="manualEntry.userKey" type="password" show-password-on="click" :placeholder="t('pages.settings.tianheManualUserKeyPh')" />
</n-form-item>
</n-modal>
<section class="settings-card storage-card">
<div class="card-title">
<span class="card-title-text">
@@ -193,7 +244,7 @@
import { computed, onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { settingsApi, storageApi } from '@/api';
import { message } from '@/utils/feedback';
import { dialog, message } from '@/utils/feedback';
import { HelpCircleOutline } from '@vicons/ionicons5';
import BackupRestorePanel from '@/components/BackupRestorePanel.vue';
import MediaUpload from '@/components/MediaUpload.vue';
@@ -204,6 +255,12 @@ const saving = ref(false);
const testingStorage = ref(false);
const migratingStorage = ref(false);
const confirmingStorage = ref(false);
const registeringIdentity = ref(false);
const verifyingIdentity = ref(false);
const revealKey = ref(false);
const manualEntryVisible = ref(false);
const identity = reactive({ userId: '', userKey: '', address: '' });
const manualEntry = reactive({ userId: '', userKey: '' });
const TIANHE_TEST_URL = 'https://test.api.tichain.tianhecloud.com';
const TIANHE_PRODUCTION_URL = 'https://api.tichain.tianhecloud.com';
const blockchainDriverOptions = computed(() => [
@@ -296,6 +353,66 @@ function onTianheEnvChange(value: string) {
if (value === 'production') form.tianheBaseUrl = TIANHE_PRODUCTION_URL;
}
async function loadIdentity() {
try {
const res = await settingsApi.tianheIdentity();
identity.userId = res.userId || '';
identity.userKey = res.userKey || '';
identity.address = res.address || '';
} catch {
// 身份信息读取失败不阻塞设置页
}
}
function maskKey(value: string): string {
if (!value || value.length <= 8) return '******';
return `${value.slice(0, 4)}******${value.slice(-4)}`;
}
async function copyUserKey() {
await navigator.clipboard.writeText(identity.userKey);
message.success(t('pages.settings.tianheCopied'));
}
// 注册(或确认)平台托管钱包;注册前先保存表单里的 AppID/AppKey,避免「填了没存」
async function registerIdentity() {
registeringIdentity.value = true;
try {
await save();
const res = await settingsApi.tianheRegister();
identity.userId = res.userId;
identity.userKey = res.userKey;
identity.address = res.address;
revealKey.value = true;
dialog.warning({
title: t('pages.settings.tianheRegisterDone'),
content: t('pages.settings.tianheSaveKeyWarning', { userId: res.userId, userKey: res.userKey }),
positiveText: t('common.action.confirm'),
});
} finally {
registeringIdentity.value = false;
}
}
async function verifyIdentity() {
verifyingIdentity.value = true;
try {
const res = await settingsApi.tianheVerify({ userId: manualEntry.userId, userKey: manualEntry.userKey });
identity.userId = res.userId;
identity.userKey = manualEntry.userKey;
identity.address = res.address;
manualEntry.userId = '';
manualEntry.userKey = '';
manualEntryVisible.value = false;
message.success(t('pages.settings.tianheVerifyOk'));
return true;
} catch {
return false;
} finally {
verifyingIdentity.value = false;
}
}
async function save() {
saving.value = true;
try {
@@ -370,7 +487,10 @@ async function confirmStorage() {
}
}
onMounted(load);
onMounted(async () => {
await load();
await loadIdentity();
});
const currentIconUrl = computed(() => resolveAppIcon(form.appIconFiles[0]?.url || form.appIconFiles[0]?.key));
</script>
@@ -476,6 +596,36 @@ const currentIconUrl = computed(() => resolveAppIcon(form.appIconFiles[0]?.url |
font-size: 12px;
line-height: 1.7;
}
.identity-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.identity-title {
font-size: 13px;
font-weight: 600;
color: var(--n-text-color-2, #526070);
}
.identity-value {
font-size: 12px;
word-break: break-all;
}
.identity-value.mono {
font-family: Consolas, Menlo, monospace;
}
.identity-key {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.identity-hint {
margin: 4px 12px 10px;
font-size: 12px;
line-height: 1.6;
color: #d03050;
}
.setting-row {
padding: 8px 12px;
border-bottom: 1px solid var(--n-border-color);