How to use the libsodium-wrappers.crypto_box_seal_open function in libsodium-wrappers

To help you get started, we’ve selected a few libsodium-wrappers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
const recipient = recipsOuter.recipients.find(r => {
      return r.header.kid === keys.public58
    })
    if (!recipient) {
      throw new Error('No corresponding recipient key found')
    }
    let pk = sodium.crypto_sign_ed25519_pk_to_curve25519(keys.public)
    let sk = sodium.crypto_sign_ed25519_sk_to_curve25519(keys.private)
    let encrytpedKey = b64dec(recipient.encrypted_key)
    let nonce = recipient.header.iv ? b64dec(recipient.header.iv) : null
    let encSender = recipient.header.sender ? b64dec(recipient.header.sender) : null
    let senderVK = null
    let cek = null
    if (nonce && encSender) {
      senderVK = sodium.to_string(sodium.crypto_box_seal_open(encSender, pk, sk))
      const senderPK = sodium.crypto_sign_ed25519_pk_to_curve25519(bs58.decode(senderVK))
      cek = sodium.crypto_box_open_easy(encrytpedKey, nonce, senderPK, sk)
    } else {
      cek = sodium.crypto_box_seal_open(encrytpedKey, pk, sk)
    }

    switch (recipsOuter.alg) {
      case 'Authcrypt':
        if (!senderVK) {
          throw new Error('Sender public key not provided in Authcrypt message')
        }
        break
      case 'Anoncrypt':
        break
      default:
        throw new Error(`Unsupported pack algorithm: ${recipsOuter.alg}`)
github samuelmaddock / metastream / packages / metastream-signal-server / src / client.ts View on Github external
private solveChallenge(keyPair: KeyPair, data: string) {
    const challenge = sodium.from_base64(data, sodium.base64_variants.URLSAFE_NO_PADDING)
    const nonce = sodium.crypto_box_seal_open(challenge, keyPair.publicKey, keyPair.privateKey)

    const decoded = sodium.to_base64(nonce, sodium.base64_variants.URLSAFE_NO_PADDING)
    this.send({
      t: MessageType.AuthResponse,
      c: decoded
    })
  }
github samuelmaddock / metastream / packages / metastream-app / src / platform / web / crypto.ts View on Github external
export const unseal = (cipher: Data, publicKey: Key, secretKey: Key) => {
  if (cipher.length < sodium.crypto_box_SEALBYTES) return null
  let msg
  try {
    msg = sodium.crypto_box_seal_open(cipher, publicKey, secretKey)
  } catch (e) {
    return null
  }
  return msg
}
github TankerHQ / sdk-js / packages / crypto / src / tcrypto.js View on Github external
export function sealDecrypt(cipherText: Uint8Array, recipientKeys: SodiumKeyPair): Uint8Array {
  return sodium.crypto_box_seal_open(cipherText, recipientKeys.publicKey, recipientKeys.privateKey);
}
github Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
if (!recipient) {
      throw new Error('No corresponding recipient key found')
    }
    let pk = sodium.crypto_sign_ed25519_pk_to_curve25519(keys.public)
    let sk = sodium.crypto_sign_ed25519_sk_to_curve25519(keys.private)
    let encrytpedKey = b64dec(recipient.encrypted_key)
    let nonce = recipient.header.iv ? b64dec(recipient.header.iv) : null
    let encSender = recipient.header.sender ? b64dec(recipient.header.sender) : null
    let senderVK = null
    let cek = null
    if (nonce && encSender) {
      senderVK = sodium.to_string(sodium.crypto_box_seal_open(encSender, pk, sk))
      const senderPK = sodium.crypto_sign_ed25519_pk_to_curve25519(bs58.decode(senderVK))
      cek = sodium.crypto_box_open_easy(encrytpedKey, nonce, senderPK, sk)
    } else {
      cek = sodium.crypto_box_seal_open(encrytpedKey, pk, sk)
    }

    switch (recipsOuter.alg) {
      case 'Authcrypt':
        if (!senderVK) {
          throw new Error('Sender public key not provided in Authcrypt message')
        }
        break
      case 'Anoncrypt':
        break
      default:
        throw new Error(`Unsupported pack algorithm: ${recipsOuter.alg}`)
    }

    const ciphertext = b64dec(wrapper.ciphertext)
    nonce = b64dec(wrapper.iv)