SHA256
Подготовить программы и user PDA к публичной версии 1.0
This commit is contained in:
@@ -12,9 +12,7 @@ import { getNamespace, assertLoginInNamespace, normalizeFullLogin, userPdaSeed32
|
||||
|
||||
const MAGIC = 'SHiNE';
|
||||
const FORMAT_MAJOR = 1;
|
||||
const FORMAT_MINOR_LEGACY = 0;
|
||||
const FORMAT_MINOR_CURRENT = 3;
|
||||
const FORMAT_MINOR_PREVIOUS = 2;
|
||||
const FORMAT_MINOR_CURRENT = 0;
|
||||
const SHINE_PAYMENTS_INFLOW_VAULT_SEED = 'shine_payments_inflow_vault';
|
||||
const SHINE_USERS_USER_PDA_SEED_PREFIX = 'user_login=';
|
||||
const SHINE_USERS_PROMO_SELLER_PDA_SEED_PREFIX = 'promo_seller=';
|
||||
@@ -277,7 +275,7 @@ export function parseShineUserPda(dataBytes) {
|
||||
const formatMajor = reader.readU8();
|
||||
const formatMinor = reader.readU8();
|
||||
const recordLen = reader.readU16();
|
||||
if (formatMajor !== FORMAT_MAJOR || ![FORMAT_MINOR_PREVIOUS, FORMAT_MINOR_CURRENT].includes(formatMinor)) throw new Error(`Неподдерживаемый формат PDA ${formatMajor}.${formatMinor}`);
|
||||
if (formatMajor !== FORMAT_MAJOR || formatMinor !== FORMAT_MINOR_CURRENT) throw new Error(`Неподдерживаемый формат PDA ${formatMajor}.${formatMinor}`);
|
||||
if (recordLen < 9 + 64 || recordLen > bytes.length) throw new Error('Некорректный record_len');
|
||||
const createdAtMs = reader.readU64();
|
||||
const updatedAtMs = reader.readU64();
|
||||
@@ -700,34 +698,6 @@ export async function registerServerOnSolana({ login, keyBundle, serverAddress,
|
||||
return createShineUserPdaOnSolana({ login, keyBundle, solanaEndpoint, isServer: true, serverAddress, serverAddresses: serverAddresses || [], addressFormatType, addressFormatVersion, accessServers, feePayerPrivatePkcs8B64: keyBundle.clientPair.privatePkcs8B64 });
|
||||
}
|
||||
|
||||
export async function closeLegacyShineUserPdaOnSolana({ login, solanaEndpoint, callerPrivatePkcs8B64 }) {
|
||||
const cleanLogin = normalizeLogin(login);
|
||||
if (!cleanLogin || !callerPrivatePkcs8B64) throw new Error('Нужны login и private key вызывающего');
|
||||
const solana = await loadSolanaLib();
|
||||
const endpoint = String(solanaEndpoint || '').trim();
|
||||
const connection = new solana.Connection(endpoint, 'confirmed');
|
||||
const usersProgram = new solana.PublicKey(SHINE_USERS_PROGRAM_ID);
|
||||
const [userPda] = solana.PublicKey.findProgramAddressSync([new TextEncoder().encode(SHINE_USERS_USER_PDA_SEED_PREFIX), new TextEncoder().encode(cleanLogin)], usersProgram);
|
||||
const info = await connection.getAccountInfo(userPda, 'confirmed');
|
||||
if (!info) throw new Error('PDA не найдена');
|
||||
const raw = new Uint8Array(info.data);
|
||||
if (raw.length < 7 || new TextDecoder().decode(raw.slice(0, 5)) !== MAGIC || raw[5] !== FORMAT_MAJOR || raw[6] !== FORMAT_MINOR_LEGACY) {
|
||||
throw new Error('Закрывать этой инструкцией можно только legacy PDA 1.0');
|
||||
}
|
||||
const seed32 = extractSeed32FromPkcs8B64(callerPrivatePkcs8B64);
|
||||
const caller = solana.Keypair.fromSeed(seed32);
|
||||
const ix = new solana.TransactionInstruction({
|
||||
programId: usersProgram,
|
||||
keys: [
|
||||
{ pubkey: caller.publicKey, isSigner: true, isWritable: true },
|
||||
{ pubkey: userPda, isSigner: false, isWritable: true },
|
||||
],
|
||||
data: serializeCloseLegacyArgs(cleanLogin),
|
||||
});
|
||||
const signature = await sendAndConfirmSolanaHttp(connection, new solana.Transaction().add(ix), [caller]);
|
||||
return { signature, pdaAddress: userPda.toBase58() };
|
||||
}
|
||||
|
||||
export async function updateShineUserPdaOnSolana({
|
||||
login,
|
||||
solanaEndpoint,
|
||||
@@ -790,8 +760,7 @@ export async function updateShineUserPdaOnSolana({
|
||||
createdAtMs: current.createdAtMs,
|
||||
updatedAtMs,
|
||||
recordNumber: current.recordNumber + 1,
|
||||
prevRecordHash: await sha256Bytes(current.formatMinor === FORMAT_MINOR_CURRENT
|
||||
? canonicalPdaSigningBytes(current.unsignedBytes) : current.unsignedBytes),
|
||||
prevRecordHash: await sha256Bytes(canonicalPdaSigningBytes(current.unsignedBytes)),
|
||||
rootKey,
|
||||
clientKey,
|
||||
forks,
|
||||
|
||||
Reference in New Issue
Block a user