[@types/sodium-native] Add crypto_box_* constants (#42079)

This commit is contained in:
Sean Stephens 2020-02-04 13:08:28 -08:00 committed by GitHub
parent 2fa35a8617
commit 11d1ff87d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -114,6 +114,9 @@ export const crypto_secretstream_xchacha20poly1305_TAG_PUSH: number;
export const crypto_secretstream_xchacha20poly1305_TAG_REKEY: number;
/** NOTE: Unofficial constant */
export const crypto_secretstream_xchacha20poly1305_TAGBYTES: number;
export const crypto_box_SEALBYTES: number;
export const crypto_box_PUBLICKEYBYTES: number;
export const crypto_box_SECRETKEYBYTES: number;
/**
* Zero out the data in `buffer`.

View File

@ -98,3 +98,11 @@ sc.fill(0xcd, 0, sodium.crypto_core_ed25519_UNIFORMBYTES);
sc2.fill(0x42, 0, sodium.crypto_core_ed25519_UNIFORMBYTES);
sodium.crypto_core_ed25519_scalar_add(sc, sc2, sc);
sodium.crypto_core_ed25519_scalar_sub(sc, sc, sc2);
const publicKey = sodium.sodium_malloc(sodium.crypto_box_PUBLICKEYBYTES);
const secretKey = sodium.sodium_malloc(sodium.crypto_box_SECRETKEYBYTES);
sodium.crypto_box_keypair(publicKey, secretKey);
const message = sodium.sodium_malloc(4);
const cipherText = sodium.sodium_malloc(message.length + sodium.crypto_box_SEALBYTES);
sodium.crypto_box_seal(cipherText, message, publicKey);
sodium.crypto_box_seal_open(message, cipherText, publicKey, secretKey);