Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add tests for crypto_box_beforenm function
  • Loading branch information
prathameshmm02 committed Dec 11, 2025
commit e515042b6640c38af003eacb56aaa9c87bb74105
1 change: 1 addition & 0 deletions example/src/components/TestResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../tests/crypto_aead_xchacha20poly1305_ietf_keygen_test';
import '../tests/crypto_auth_keygen_test';
import '../tests/crypto_auth_test';
import '../tests/crypto_auth_verify_test';
import '../tests/crypto_box_beforenm_test';
import '../tests/crypto_box_easy_test';
import '../tests/crypto_box_keypair_test';
import '../tests/crypto_box_open_easy_test';
Expand Down
41 changes: 41 additions & 0 deletions example/src/tests/crypto_box_beforenm_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
crypto_box_BEFORENMBYTES,
crypto_box_beforenm,
crypto_box_keypair,
} from 'react-native-libsodium';
import { expect, test } from '../utils/testRunner';

test('crypto_box_beforenm', () => {
const alice = crypto_box_keypair();
const bob = crypto_box_keypair();

// produces symmetric shared keys
const sharedAlice = crypto_box_beforenm(bob.publicKey, alice.privateKey);
const sharedBob = crypto_box_beforenm(alice.publicKey, bob.privateKey);

expect(sharedAlice.length).toEqual(crypto_box_BEFORENMBYTES);
expect(sharedBob.length).toEqual(crypto_box_BEFORENMBYTES);
expect(sharedAlice).toEqual(sharedBob);

// validates its inputs
expect(() => {
crypto_box_beforenm(
alice.publicKey.slice(0, alice.publicKey.length - 1),
alice.privateKey
);
}).toThrow();

expect(() => {
crypto_box_beforenm(
alice.publicKey,
alice.privateKey.slice(0, alice.privateKey.length - 1)
);
}).toThrow();

expect(() => {
crypto_box_beforenm(
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
alice.privateKey
);
}).toThrow();
});