Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import {
crypto_sign_SEEDBYTES,
crypto_sign_verify_detached,
from_base64,
memzero,
randombytes_buf,
randombytes_uniform,
to_base64,
Expand Down
1 change: 1 addition & 0 deletions example/src/components/TestResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import '../tests/crypto_sign_keypair_test';
import '../tests/crypto_sign_seed_keypair_test';
import '../tests/crypto_sign_verify_detached_test';
import '../tests/from_base64_test';
import '../tests/memzero_test';
import '../tests/randombytes_buf_test';
import '../tests/randombytes_uniform_test';
import '../tests/to_base64_test';
Expand Down
10 changes: 10 additions & 0 deletions example/src/tests/memzero_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { memzero, to_hex } from 'react-native-libsodium';
import { expect, test } from '../utils/testRunner';

test('memzero', () => {
let buf = new Uint8Array([222, 173, 190, 239]);
memzero(buf);
expect(to_hex(buf)).toBe('00000000');

expect(() => memzero([0, 1, 2, 3] as unknown as Uint8Array)).toThrow();
});
10 changes: 10 additions & 0 deletions src/lib.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ export function to_hex(input: string | Uint8Array): string {
return global.jsi_to_hex(inputParam);
}

export function memzero(bytes: Uint8Array): void {
if (!(bytes instanceof Uint8Array)) {
throw new TypeError('Only Uint8Array instances can be wiped');
}
for (let i = 0; i < bytes.length; i++) {
bytes[i] = 0;
}
}

export function randombytes_buf(
length: number,
outputFormat?: Uint8ArrayOutputFormat | null
Expand Down Expand Up @@ -889,6 +898,7 @@ export default {
crypto_sign_keypair,
crypto_sign_verify_detached,
from_base64,
memzero,
randombytes_buf,
randombytes_uniform,
ready,
Expand Down