mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
fix(music-together): typing
This commit is contained in:
@ -12,14 +12,14 @@ export function SHA1Hash(): {
|
||||
}
|
||||
|
||||
function processBlock(block: number[]): void {
|
||||
let words: number[] = [];
|
||||
const words: number[] = [];
|
||||
for (let i = 0; i < 64; i += 4) {
|
||||
words[i / 4] = block[i] << 24 | block[i + 1] << 16 | block[i + 2] << 8 | block[i + 3];
|
||||
words[i / 4] = (block[i] << 24) | (block[i + 1] << 16) | (block[i + 2] << 8) | block[i + 3];
|
||||
}
|
||||
|
||||
for (let i = 16; i < 80; i++) {
|
||||
let temp = words[i - 3] ^ words[i - 8] ^ words[i - 14] ^ words[i - 16];
|
||||
words[i] = (temp << 1 | temp >>> 31) & 4294967295;
|
||||
const temp = words[i - 3] ^ words[i - 8] ^ words[i - 14] ^ words[i - 16];
|
||||
words[i] = ((temp << 1) | (temp >>> 31)) & 4294967295;
|
||||
}
|
||||
|
||||
let a = hash[0],
|
||||
@ -30,22 +30,22 @@ export function SHA1Hash(): {
|
||||
for (let i = 0; i < 80; i++) {
|
||||
let f, k;
|
||||
if (i < 20) {
|
||||
f = d ^ b & (c ^ d);
|
||||
f = d ^ (b & (c ^ d));
|
||||
k = 1518500249;
|
||||
} else if (i < 40) {
|
||||
f = b ^ c ^ d;
|
||||
k = 1859775393;
|
||||
} else if (i < 60) {
|
||||
f = b & c | d & (b | c);
|
||||
f = (b & c) | (d & (b | c));
|
||||
k = 2400959708;
|
||||
} else {
|
||||
f = b ^ c ^ d;
|
||||
k = 3395469782;
|
||||
}
|
||||
let temp = ((a << 5 | a >>> 27) & 4294967295) + f + e + k + words[i] & 4294967295;
|
||||
const temp = (((a << 5) | (a >>> 27)) & 4294967295) + f + e + k + words[i] & 4294967295;
|
||||
e = d;
|
||||
d = c;
|
||||
c = (b << 30 | b >>> 2) & 4294967295;
|
||||
c = ((b << 30) | (b >>> 2)) & 4294967295;
|
||||
b = a;
|
||||
a = temp;
|
||||
}
|
||||
@ -58,8 +58,9 @@ export function SHA1Hash(): {
|
||||
|
||||
function update(message: string | number[], length?: number): void {
|
||||
if ('string' === typeof message) {
|
||||
// HACK: to decode UTF-8
|
||||
message = unescape(encodeURIComponent(message));
|
||||
let bytes: number[] = [];
|
||||
const bytes: number[] = [];
|
||||
for (let i = 0, len = message.length; i < len; ++i)
|
||||
bytes.push(message.charCodeAt(i));
|
||||
message = bytes;
|
||||
@ -67,48 +68,59 @@ export function SHA1Hash(): {
|
||||
length || (length = message.length);
|
||||
let i = 0;
|
||||
if (0 == currentLength)
|
||||
for (; i + 64 < length;)
|
||||
processBlock(message.slice(i, i + 64)),
|
||||
i += 64,
|
||||
for (; i + 64 < length;) {
|
||||
processBlock(message.slice(i, i + 64));
|
||||
i += 64;
|
||||
totalLength += 64;
|
||||
}
|
||||
for (; i < length;) {
|
||||
if (buffer[currentLength++] = message[i++], totalLength++, 64 == currentLength)
|
||||
for (currentLength = 0, processBlock(buffer); i + 64 < length;) {
|
||||
processBlock(message.slice(i, i + 64));
|
||||
i += 64;
|
||||
totalLength += 64;
|
||||
for (; i < length;)
|
||||
if (buffer[currentLength++] = message[i++],
|
||||
totalLength++,
|
||||
64 == currentLength)
|
||||
for (currentLength = 0,
|
||||
processBlock(buffer); i + 64 < length;)
|
||||
processBlock(message.slice(i, i + 64)),
|
||||
i += 64,
|
||||
totalLength += 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function finalize(): number[] {
|
||||
let result: number[] = []
|
||||
, bits = 8 * totalLength;
|
||||
if (currentLength < 56)
|
||||
const result: number[] = [];
|
||||
let bits = 8 * totalLength;
|
||||
if (currentLength < 56) {
|
||||
update(padding, 56 - currentLength);
|
||||
else
|
||||
} else {
|
||||
update(padding, 64 - (currentLength - 56));
|
||||
for (let i = 63; i >= 56; i--)
|
||||
buffer[i] = bits & 255,
|
||||
bits >>>= 8;
|
||||
}
|
||||
for (let i = 63; i >= 56; i--) {
|
||||
buffer[i] = bits & 255;
|
||||
bits >>>= 8;
|
||||
}
|
||||
processBlock(buffer);
|
||||
for (let i = 0; i < 5; i++)
|
||||
for (let j = 24; j >= 0; j -= 8)
|
||||
result.push(hash[i] >> j & 255);
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 24; j >= 0; j -= 8) {
|
||||
result.push((hash[i] >> j) & 255);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
let buffer: number[] = [], padding: number[] = [128], totalLength: number, currentLength: number;
|
||||
for (let i = 1; i < 64; ++i)
|
||||
const buffer: number[] = [];
|
||||
const padding: number[] = [128];
|
||||
let totalLength: number;
|
||||
let currentLength: number;
|
||||
|
||||
for (let i = 1; i < 64; ++i) {
|
||||
padding[i] = 0;
|
||||
}
|
||||
|
||||
initialize();
|
||||
return {
|
||||
reset: initialize,
|
||||
update: update,
|
||||
digest: finalize,
|
||||
digestString: function(): string {
|
||||
let hash = finalize(), hex = '';
|
||||
const hash = finalize();
|
||||
let hex = '';
|
||||
for (let i = 0; i < hash.length; i++)
|
||||
hex += '0123456789ABCDEF'.charAt(Math.floor(hash[i] / 16)) + '0123456789ABCDEF'.charAt(hash[i] % 16);
|
||||
return hex;
|
||||
|
||||
Reference in New Issue
Block a user