feat: add sncrypto client side packages

This commit is contained in:
Karol Sójko
2022-07-06 12:21:21 +02:00
parent 9d1f7043e5
commit 6ec66795d2
71 changed files with 9786 additions and 34 deletions

View File

@@ -0,0 +1,22 @@
/**
* Constant-time string comparison
* @param a
* @param b
*/
export function timingSafeEqual(a: string, b: string): boolean {
const strA = String(a)
let strB = String(b)
const lenA = strA.length
let result = 0
if (lenA !== strB.length) {
strB = strA
result = 1
}
for (let i = 0; i < lenA; i++) {
result |= strA.charCodeAt(i) ^ strB.charCodeAt(i)
}
return result === 0
}