SHA256
Логин guard: корректный precheck, company приоритет, hp в trademarks; подробные ошибки UI
This commit is contained in:
@@ -7,7 +7,8 @@ import {
|
||||
} from '../solana-programs.js';
|
||||
|
||||
const CREATE_USER_PDA_DISCRIMINATOR = new Uint8Array([139, 157, 13, 41, 142, 174, 226, 214]);
|
||||
const CLASSIFY_LOGIN_DISCRIMINATOR = new Uint8Array([118, 253, 204, 124, 22, 232, 235, 32]);
|
||||
const CLASSIFY_LOGIN_DISCRIMINATOR = new Uint8Array([112, 97, 152, 32, 255, 73, 108, 86]);
|
||||
const PRECHECK_SIM_PAYER = 'FUc28vNixp7F3nnkpGVt6nuJbgvJ4429v4B5wS52Df6P';
|
||||
const ED25519_PROGRAM_ID = 'Ed25519SigVerify111111111111111111111111111';
|
||||
const SYSVAR_INSTRUCTIONS_ID = 'Sysvar1nstructions1111111111111111111111111';
|
||||
|
||||
@@ -197,24 +198,61 @@ function decodeU32FromB64(rawB64) {
|
||||
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0, true);
|
||||
}
|
||||
|
||||
function safeJson(value) {
|
||||
try {
|
||||
return JSON.stringify(value);
|
||||
} catch {
|
||||
return String(value);
|
||||
}
|
||||
}
|
||||
|
||||
export function formatSolanaErrorDetails(error) {
|
||||
const parts = [];
|
||||
const msg = String(error?.message || error || '').trim();
|
||||
if (msg) parts.push(msg);
|
||||
|
||||
const logs = error?.logs || error?.transactionLogs || error?.simulationLogs || error?.data?.logs;
|
||||
if (Array.isArray(logs) && logs.length) {
|
||||
parts.push(`Logs: ${logs.join(' | ')}`);
|
||||
}
|
||||
|
||||
const errObj = error?.value?.err || error?.err || error?.data?.err;
|
||||
if (errObj) {
|
||||
parts.push(`Err: ${safeJson(errObj)}`);
|
||||
}
|
||||
|
||||
if (!parts.length) return 'unknown';
|
||||
return parts.join(' :: ');
|
||||
}
|
||||
|
||||
export async function precheckLoginClassOnSolana({ login, solanaEndpoint }) {
|
||||
const solana = await loadSolanaLib();
|
||||
const connection = new solana.Connection(String(solanaEndpoint || ''), 'confirmed');
|
||||
const loginGuardProgram = new solana.PublicKey(SHINE_LOGIN_GUARD_PROGRAM_ID);
|
||||
const signer = solana.Keypair.generate();
|
||||
const payer = new solana.PublicKey(PRECHECK_SIM_PAYER);
|
||||
const ix = new solana.TransactionInstruction({
|
||||
programId: loginGuardProgram,
|
||||
keys: [{ pubkey: signer.publicKey, isSigner: true, isWritable: false }],
|
||||
keys: [{ pubkey: payer, isSigner: true, isWritable: false }],
|
||||
data: serializeClassifyLoginArgs(String(login || '').toLowerCase()),
|
||||
});
|
||||
const tx = new solana.Transaction().add(ix);
|
||||
tx.feePayer = signer.publicKey;
|
||||
tx.recentBlockhash = (await connection.getLatestBlockhash('confirmed')).blockhash;
|
||||
tx.sign(signer);
|
||||
const { blockhash } = await connection.getLatestBlockhash('confirmed');
|
||||
const v0Message = new solana.TransactionMessage({
|
||||
payerKey: payer,
|
||||
recentBlockhash: blockhash,
|
||||
instructions: [ix],
|
||||
}).compileToV0Message();
|
||||
const tx = new solana.VersionedTransaction(v0Message);
|
||||
|
||||
const sim = await connection.simulateTransaction(tx, { commitment: 'confirmed', sigVerify: true });
|
||||
const sim = await connection.simulateTransaction(tx, {
|
||||
commitment: 'confirmed',
|
||||
sigVerify: false,
|
||||
replaceRecentBlockhash: true,
|
||||
});
|
||||
if (sim?.value?.err) {
|
||||
throw new Error(`LOGIN_GUARD_SIMULATION_FAILED: ${JSON.stringify(sim.value.err)}`);
|
||||
const simErr = new Error(`LOGIN_GUARD_SIMULATION_FAILED: ${safeJson(sim.value.err)}`);
|
||||
simErr.logs = sim?.value?.logs || [];
|
||||
simErr.err = sim?.value?.err;
|
||||
throw simErr;
|
||||
}
|
||||
const returnData = sim?.value?.returnData;
|
||||
if (!returnData || returnData.programId !== SHINE_LOGIN_GUARD_PROGRAM_ID) {
|
||||
|
||||
Reference in New Issue
Block a user