Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private authCheck(client: Client, publicKey: string) {
if (client.status === ClientStatus.Authed) return true
else if (client.status === ClientStatus.PendingAuth) return false
else if (!isValidRoom(publicKey)) return false
const nonce = sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES)
const box = sodium.crypto_box_seal(nonce, sodium.from_hex(publicKey))
const challenge = sodium.to_base64(box, sodium.base64_variants.URLSAFE_NO_PADDING)
client.status = ClientStatus.PendingAuth
client.authSecret = nonce
this.sendTo(client, {
t: MessageType.AuthChallenge,
c: challenge
})
return false
}
export function sealEncrypt(clearData: Uint8Array, pubKey: Uint8Array): Uint8Array {
return sodium.crypto_box_seal(clearData, pubKey);
}
export const seal = (msg: Data, publicKey: Key) => sodium.crypto_box_seal(msg, publicKey)
const recipients = args.toPublicKeys.map(targetVKey => {
if (typeof targetVKey === 'string') {
targetVKey = bs58.decode(targetVKey)
}
let encSender = null
let nonce = null
let encCEK = null
const targetPK = sodium.crypto_sign_ed25519_pk_to_curve25519(targetVKey)
if (sender) {
nonce = sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES)
encSender = sodium.crypto_box_seal(sender.vk, targetPK)
encCEK = sodium.crypto_box_easy(cek, nonce, targetPK, sender.sk)
} else {
encCEK = sodium.crypto_box_seal(cek, targetPK)
}
return {
encrypted_key: b64url(encCEK),
header: {
kid: bs58.encode(targetVKey),
sender: encSender ? b64url(encSender) : null,
iv: nonce ? b64url(nonce) : null
}
}
})
const recipients = args.toPublicKeys.map(targetVKey => {
if (typeof targetVKey === 'string') {
targetVKey = bs58.decode(targetVKey)
}
let encSender = null
let nonce = null
let encCEK = null
const targetPK = sodium.crypto_sign_ed25519_pk_to_curve25519(targetVKey)
if (sender) {
nonce = sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES)
encSender = sodium.crypto_box_seal(sender.vk, targetPK)
encCEK = sodium.crypto_box_easy(cek, nonce, targetPK, sender.sk)
} else {
encCEK = sodium.crypto_box_seal(cek, targetPK)
}
return {
encrypted_key: b64url(encCEK),
header: {
kid: bs58.encode(targetVKey),
sender: encSender ? b64url(encSender) : null,
iv: nonce ? b64url(nonce) : null
}
}
})