SHA256
Перенести server UI в shine-UI и объединить PDA-модуль
This commit is contained in:
@@ -52,6 +52,34 @@ export function bytesToBase58(bytes) {
|
||||
return digits.reverse().map((digit) => BASE58_ALPHABET[digit]).join('');
|
||||
}
|
||||
|
||||
export function base58ToBytes(value) {
|
||||
const text = String(value || '').trim();
|
||||
if (!text) return new Uint8Array();
|
||||
|
||||
const digits = [];
|
||||
for (let i = 0; i < text.length; i += 1) {
|
||||
const char = text[i];
|
||||
const index = BASE58_ALPHABET.indexOf(char);
|
||||
if (index < 0) throw new Error(`Недопустимый символ base58: ${char}`);
|
||||
let carry = index;
|
||||
for (let j = 0; j < digits.length; j += 1) {
|
||||
const acc = (digits[j] * 58) + carry;
|
||||
digits[j] = acc & 0xff;
|
||||
carry = acc >> 8;
|
||||
}
|
||||
while (carry > 0) {
|
||||
digits.push(carry & 0xff);
|
||||
carry >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < text.length && text[i] === '1'; i += 1) {
|
||||
digits.push(0);
|
||||
}
|
||||
|
||||
return new Uint8Array(digits.reverse());
|
||||
}
|
||||
|
||||
export function randomBase64(byteLen = 32) {
|
||||
const bytes = getCryptoApi().getRandomValues(new Uint8Array(byteLen));
|
||||
return bytesToBase64(bytes);
|
||||
|
||||
Reference in New Issue
Block a user