How to use the libsodium-wrappers.crypto_box_seal 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 samuelmaddock / metastream / packages / metastream-signal-server / src / index.ts View on Github external
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
  }
github TankerHQ / sdk-js / packages / crypto / src / tcrypto.js View on Github external
export function sealEncrypt(clearData: Uint8Array, pubKey: Uint8Array): Uint8Array {
  return sodium.crypto_box_seal(clearData, pubKey);
}
github samuelmaddock / metastream / packages / metastream-app / src / platform / web / crypto.ts View on Github external
export const seal = (msg: Data, publicKey: Key) => sodium.crypto_box_seal(msg, publicKey)
github Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
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
        }
      }
    })
github Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
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
        }
      }
    })