feat: experimental 005 operator (#1753)

This commit is contained in:
Mo
2022-10-06 11:03:43 -05:00
committed by GitHub
parent c13dd883a4
commit cbbe913cd6
21 changed files with 284 additions and 46 deletions

View File

@@ -69,7 +69,8 @@ export default class FakeWebCrypto {
}
generateRandomKey(bits) {
const length = bits / 8
const bitsPerHexChar = 4
const length = bits / bitsPerHexChar
return this.randomString(length)
}
@@ -107,7 +108,13 @@ export default class FakeWebCrypto {
}
argon2(password, salt, iterations, bytes, length) {
return btoa(password)
const bitsPerHexChar = 4
const bitsInByte = 8
const encoded = btoa(password)
const desiredLength = length * (bitsInByte / bitsPerHexChar)
const missingLength = desiredLength - encoded.length
const result = `${encoded}${encoded.repeat(Math.ceil(missingLength / encoded.length))}`.slice(0, desiredLength)
return result
}
xchacha20Encrypt(plaintext, nonce, key, assocData) {
@@ -128,6 +135,33 @@ export default class FakeWebCrypto {
return data.plaintext
}
sodiumCryptoBoxEasyEncrypt(message, nonce, senderSecretKey, recipientPublicKey) {
const data = {
message,
nonce,
senderSecretKey,
recipientPublicKey,
}
return btoa(JSON.stringify(data))
}
sodiumCryptoBoxEasyDecrypt(ciphertext, nonce, senderPublicKey, recipientSecretKey) {
const data = JSON.parse(atob(ciphertext))
if (
data.senderPublicKey !== senderPublicKey ||
data.recipientSecretKey !== recipientSecretKey ||
data.nonce !== nonce ||
data.assocData !== assocData
) {
return undefined
}
return data.message
}
sodiumCryptoBoxGenerateKeypair() {
return { publicKey: this.randomString(64), privateKey: this.randomString(64), keyType: 'x25519' }
}
generateOtpSecret() {
return 'WQVV2GFBRQWU3UQZWQFZC37PSNRXKTA6'
}