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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user