revert: undo incorrect threshold conversion that broke keygen
Reverts e81757ad - the threshold conversion was wrong.
Keygen works with original thresholdT/thresholdN parameters.
The signing issue needs a different fix.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e81757ad83
commit
54121fa494
|
|
@ -1226,54 +1226,16 @@ function setupIpcHandlers() {
|
||||||
return { success: false, error: '请先连接到消息路由器' };
|
return { success: false, error: '请先连接到消息路由器' };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support both old format (thresholdT, thresholdN) and new format (requiredSigners, totalParties)
|
// 动态计算 server-party 数量: persistent = n - t
|
||||||
// New format uses user-friendly "required signers" which needs conversion to tss-lib threshold
|
// 例如: 2-of-3 -> persistent=1, 3-of-5 -> persistent=2, 4-of-7 -> persistent=3
|
||||||
let thresholdT: number;
|
// 这样平台备份方数量等于"允许丢失的份额数",确保用户丢失密钥后仍可恢复
|
||||||
let thresholdN: number;
|
const persistentCount = params.thresholdN - params.thresholdT;
|
||||||
let externalCount: number;
|
const externalCount = params.thresholdT; // 用户持有的份额数量
|
||||||
let persistentCount: number;
|
|
||||||
|
|
||||||
if (params.requiredSigners !== undefined && params.totalParties !== undefined) {
|
|
||||||
// New format: Convert user-friendly parameters to tss-lib parameters
|
|
||||||
// In tss-lib, threshold_t means you need (t+1) parties to sign
|
|
||||||
// So if user wants 3 signers, threshold_t = 3 - 1 = 2
|
|
||||||
const requiredSigners = params.requiredSigners;
|
|
||||||
const totalParties = params.totalParties;
|
|
||||||
|
|
||||||
thresholdT = requiredSigners - 1; // tss-lib threshold
|
|
||||||
thresholdN = totalParties;
|
|
||||||
externalCount = requiredSigners; // user parties = required signers
|
|
||||||
persistentCount = totalParties - requiredSigners; // server backup parties
|
|
||||||
|
|
||||||
console.log('[CreateSession] Converting user-friendly params to tss-lib:', {
|
|
||||||
requiredSigners,
|
|
||||||
totalParties,
|
|
||||||
'tss-lib threshold_t': thresholdT,
|
|
||||||
'tss-lib threshold_n': thresholdN,
|
|
||||||
externalCount,
|
|
||||||
persistentCount,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Old format: Use thresholdT and thresholdN directly (backward compatible)
|
|
||||||
thresholdT = params.thresholdT;
|
|
||||||
thresholdN = params.thresholdN;
|
|
||||||
// 动态计算 server-party 数量: persistent = n - t
|
|
||||||
// 例如: 2-of-3 -> persistent=1, 3-of-5 -> persistent=2, 4-of-7 -> persistent=3
|
|
||||||
persistentCount = thresholdN - thresholdT;
|
|
||||||
externalCount = thresholdT;
|
|
||||||
|
|
||||||
console.log('[CreateSession] Using legacy params (backward compatible):', {
|
|
||||||
thresholdT,
|
|
||||||
thresholdN,
|
|
||||||
externalCount,
|
|
||||||
persistentCount,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await accountClient?.createKeygenSession({
|
const result = await accountClient?.createKeygenSession({
|
||||||
wallet_name: params.walletName,
|
wallet_name: params.walletName,
|
||||||
threshold_t: thresholdT,
|
threshold_t: params.thresholdT,
|
||||||
threshold_n: thresholdN,
|
threshold_n: params.thresholdN,
|
||||||
initiator_party_id: partyId,
|
initiator_party_id: partyId,
|
||||||
initiator_name: params.initiatorName || '发起者',
|
initiator_name: params.initiatorName || '发起者',
|
||||||
persistent_count: persistentCount,
|
persistent_count: persistentCount,
|
||||||
|
|
@ -1309,8 +1271,8 @@ function setupIpcHandlers() {
|
||||||
partyIndex: joinResult.party_index,
|
partyIndex: joinResult.party_index,
|
||||||
participants: participants,
|
participants: participants,
|
||||||
threshold: {
|
threshold: {
|
||||||
t: thresholdT,
|
t: params.thresholdT,
|
||||||
n: thresholdN,
|
n: params.thresholdN,
|
||||||
},
|
},
|
||||||
walletName: params.walletName,
|
walletName: params.walletName,
|
||||||
encryptionPassword: '', // 不使用加密密码
|
encryptionPassword: '', // 不使用加密密码
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,8 @@ export default function Create() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [walletName, setWalletName] = useState('');
|
const [walletName, setWalletName] = useState('');
|
||||||
// requiredSigners: 用户选择的"需要几人签名"(用户直观理解)
|
const [thresholdT, setThresholdT] = useState(3);
|
||||||
// 例如:用户选择 3 表示需要 3 人签名
|
const [thresholdN, setThresholdN] = useState(5);
|
||||||
// 在 tss-lib 中,threshold_t = requiredSigners - 1(因为 tss-lib 需要 t+1 人签名)
|
|
||||||
const [requiredSigners, setRequiredSigners] = useState(3);
|
|
||||||
const [totalParties, setTotalParties] = useState(5);
|
|
||||||
const [participantName, setParticipantName] = useState('');
|
const [participantName, setParticipantName] = useState('');
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
@ -33,15 +30,15 @@ export default function Create() {
|
||||||
setError('请输入您的名称');
|
setError('请输入您的名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requiredSigners > totalParties) {
|
if (thresholdT > thresholdN) {
|
||||||
setError('签名人数不能大于参与方总数');
|
setError('签名阈值不能大于参与方总数');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requiredSigners < 2) {
|
if (thresholdT < 1) {
|
||||||
setError('签名人数至少为 2');
|
setError('签名阈值至少为 1');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (totalParties < 2) {
|
if (thresholdN < 2) {
|
||||||
setError('参与方总数至少为 2');
|
setError('参与方总数至少为 2');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -51,17 +48,10 @@ export default function Create() {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Pass user-friendly parameters directly
|
|
||||||
// main.ts will convert to tss-lib parameters
|
|
||||||
console.log('[Create] Sending parameters:', {
|
|
||||||
requiredSigners,
|
|
||||||
totalParties,
|
|
||||||
});
|
|
||||||
|
|
||||||
const createResult = await window.electronAPI.grpc.createSession({
|
const createResult = await window.electronAPI.grpc.createSession({
|
||||||
walletName: walletName.trim(),
|
walletName: walletName.trim(),
|
||||||
requiredSigners,
|
thresholdT,
|
||||||
totalParties,
|
thresholdN,
|
||||||
initiatorName: participantName.trim(),
|
initiatorName: participantName.trim(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -132,23 +122,23 @@ export default function Create() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.inputGroup}>
|
<div className={styles.inputGroup}>
|
||||||
<label className={styles.label}>签名设置</label>
|
<label className={styles.label}>阈值设置 (T-of-N)</label>
|
||||||
<div className={styles.thresholdConfig}>
|
<div className={styles.thresholdConfig}>
|
||||||
<div className={styles.thresholdItem}>
|
<div className={styles.thresholdItem}>
|
||||||
<span className={styles.thresholdLabel}>需要签名人数</span>
|
<span className={styles.thresholdLabel}>签名阈值 (T)</span>
|
||||||
<div className={styles.numberInput}>
|
<div className={styles.numberInput}>
|
||||||
<button
|
<button
|
||||||
className={styles.numberButton}
|
className={styles.numberButton}
|
||||||
onClick={() => setRequiredSigners(Math.max(2, requiredSigners - 1))}
|
onClick={() => setThresholdT(Math.max(1, thresholdT - 1))}
|
||||||
disabled={requiredSigners <= 2}
|
disabled={thresholdT <= 1}
|
||||||
>
|
>
|
||||||
-
|
-
|
||||||
</button>
|
</button>
|
||||||
<span className={styles.numberValue}>{requiredSigners}</span>
|
<span className={styles.numberValue}>{thresholdT}</span>
|
||||||
<button
|
<button
|
||||||
className={styles.numberButton}
|
className={styles.numberButton}
|
||||||
onClick={() => setRequiredSigners(Math.min(totalParties, requiredSigners + 1))}
|
onClick={() => setThresholdT(Math.min(thresholdN, thresholdT + 1))}
|
||||||
disabled={requiredSigners >= totalParties}
|
disabled={thresholdT >= thresholdN}
|
||||||
>
|
>
|
||||||
+
|
+
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -156,24 +146,24 @@ export default function Create() {
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.thresholdDivider}>of</div>
|
<div className={styles.thresholdDivider}>of</div>
|
||||||
<div className={styles.thresholdItem}>
|
<div className={styles.thresholdItem}>
|
||||||
<span className={styles.thresholdLabel}>参与方总数</span>
|
<span className={styles.thresholdLabel}>参与方总数 (N)</span>
|
||||||
<div className={styles.numberInput}>
|
<div className={styles.numberInput}>
|
||||||
<button
|
<button
|
||||||
className={styles.numberButton}
|
className={styles.numberButton}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const newN = Math.max(3, totalParties - 1);
|
const newN = Math.max(2, thresholdN - 1);
|
||||||
setTotalParties(newN);
|
setThresholdN(newN);
|
||||||
if (requiredSigners > newN) setRequiredSigners(newN);
|
if (thresholdT > newN) setThresholdT(newN);
|
||||||
}}
|
}}
|
||||||
disabled={totalParties <= 3}
|
disabled={thresholdN <= 2}
|
||||||
>
|
>
|
||||||
-
|
-
|
||||||
</button>
|
</button>
|
||||||
<span className={styles.numberValue}>{totalParties}</span>
|
<span className={styles.numberValue}>{thresholdN}</span>
|
||||||
<button
|
<button
|
||||||
className={styles.numberButton}
|
className={styles.numberButton}
|
||||||
onClick={() => setTotalParties(totalParties + 1)}
|
onClick={() => setThresholdN(thresholdN + 1)}
|
||||||
disabled={totalParties >= 10}
|
disabled={thresholdN >= 10}
|
||||||
>
|
>
|
||||||
+
|
+
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -181,7 +171,7 @@ export default function Create() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className={styles.hint}>
|
<p className={styles.hint}>
|
||||||
需要 {requiredSigners} 个参与方共同签名才能执行交易 (其中 {totalParties - requiredSigners} 个由平台托管用于备份)
|
需要 {thresholdT} 个参与方共同签名才能执行交易 (其中 2 个由平台托管用于备份)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,12 +112,8 @@ interface Settings {
|
||||||
|
|
||||||
interface CreateSessionParams {
|
interface CreateSessionParams {
|
||||||
walletName: string;
|
walletName: string;
|
||||||
// New format: user-friendly parameters (preferred)
|
thresholdT: number;
|
||||||
requiredSigners?: number; // Number of signers needed (e.g., 3 for "3-of-5")
|
thresholdN: number;
|
||||||
totalParties?: number; // Total parties (e.g., 5 for "3-of-5")
|
|
||||||
// Legacy format: tss-lib parameters (backward compatible)
|
|
||||||
thresholdT?: number; // tss-lib threshold (requiredSigners - 1)
|
|
||||||
thresholdN?: number; // Same as totalParties
|
|
||||||
initiatorName: string;
|
initiatorName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue