Files
common/packages/util-crypto/src/nacl/decrypt.spec.ts
T
Jaco Greeff 80db504a3b Swap to using eslint (#435)
* WIP

* ... and more

* yet more...

* and examples (more-or-less) fixed

* Only problematic promisify left...

* Last batch

* rm config header

* Update

* Use Record

* Bumps
2019-07-14 11:12:46 +02:00

26 lines
766 B
TypeScript

// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { naclDecrypt, naclEncrypt } from '.';
describe('naclDecrypt', (): void => {
it('decrypts a encrypted message', (): void => {
const secret = new Uint8Array(32);
const message = new Uint8Array([1, 2, 3, 4, 5, 4, 3, 2, 1]);
const { encrypted, nonce } = naclEncrypt(message, secret);
expect(
naclDecrypt(encrypted, nonce, secret)
).toEqual(
message
);
});
it('returns null on invalid', (): void => {
expect(
naclDecrypt(new Uint8Array(), new Uint8Array(24), new Uint8Array(32))
).toEqual(null);
});
});