@@ -2,66 +2,66 @@ import {
22 KeyPair , PublicKey , PrivateKey , Argon2Parameters ,
33 generateKey , generateKeyPair , encryptAsymmetric , decryptAsymmetric , mixKeyExchange
44} from 'devolutions-crypto'
5- import { expect } from 'chai '
6- import { describe , it } from 'mocha '
5+ import { describe , test } from 'node:test '
6+ import assert from 'node:assert/strict '
77
88const encoder : TextEncoder = new TextEncoder ( )
99
1010describe ( 'generateKeyPair' , ( ) => {
11- it ( 'should generate a random keypair' , ( ) => {
11+ test ( 'should generate a random keypair' , ( ) => {
1212 const keypair : KeyPair = generateKeyPair ( )
13- expect ( keypair . private . bytes ) . to . not . have . lengthOf ( 0 )
14- expect ( keypair . public . bytes ) . to . not . have . lengthOf ( 0 )
15- expect ( keypair . private ) . to . not . eql ( keypair . public )
13+ assert . notStrictEqual ( keypair . private . bytes . length , 0 )
14+ assert . notStrictEqual ( keypair . public . bytes . length , 0 )
15+ assert . notDeepStrictEqual ( keypair . private , keypair . public )
1616 } )
1717} )
1818
1919describe ( 'asymmetricEncrypt/asymmetricDecrypt' , ( ) => {
20- it ( 'should be able to encrypt and decrypt' , ( ) => {
20+ test ( 'should be able to encrypt and decrypt' , ( ) => {
2121 const input : Uint8Array = encoder . encode ( 'This is some test data' )
2222 const keypair : KeyPair = generateKeyPair ( )
2323 const encrypted : Uint8Array = encryptAsymmetric ( input , keypair . public )
2424 const decrypted : Uint8Array = decryptAsymmetric ( encrypted , keypair . private )
25- expect ( encrypted ) . to . not . contains ( input )
26- expect ( decrypted ) . to . eql ( input )
25+ assert . notDeepStrictEqual ( encrypted , input )
26+ assert . deepStrictEqual ( decrypted , input )
2727 } )
2828
29- it ( 'should be able to encrypt and decrypt with an AAD' , ( ) => {
29+ test ( 'should be able to encrypt and decrypt with an AAD' , ( ) => {
3030 const input : Uint8Array = encoder . encode ( 'This is some test data' )
3131 const aad : Uint8Array = encoder . encode ( 'This is some public data' )
3232 const keypair : KeyPair = generateKeyPair ( )
3333 const encrypted : Uint8Array = encryptAsymmetric ( input , keypair . public , aad )
3434 const decrypted : Uint8Array = decryptAsymmetric ( encrypted , keypair . private , aad )
35- expect ( encrypted ) . to . not . contains ( input )
36- expect ( decrypted ) . to . eql ( input )
35+ assert . notDeepStrictEqual ( encrypted , input )
36+ assert . deepStrictEqual ( decrypted , input )
3737 } )
3838
39- it ( 'should fail if AAD is invalid' , ( ) => {
39+ test ( 'should fail if AAD is invalid' , ( ) => {
4040 const input : Uint8Array = encoder . encode ( 'This is some test data' )
4141 const aad : Uint8Array = encoder . encode ( 'This is some public data' )
4242 const wrongAad : Uint8Array = encoder . encode ( 'this is some public data' )
4343 const keypair : KeyPair = generateKeyPair ( )
4444 const encrypted : Uint8Array = encryptAsymmetric ( input , keypair . public , aad )
4545
46- expect ( ( ) => decryptAsymmetric ( encrypted , keypair . private ) ) . to . throw ( )
47- expect ( ( ) => decryptAsymmetric ( encrypted , keypair . private , wrongAad ) ) . to . throw ( )
46+ assert . throws ( ( ) => decryptAsymmetric ( encrypted , keypair . private ) )
47+ assert . throws ( ( ) => decryptAsymmetric ( encrypted , keypair . private , wrongAad ) )
4848 } )
4949} )
5050
5151describe ( 'mixKeyExchange' , ( ) => {
52- it ( 'should give the same 32 byte shared key' , ( ) => {
52+ test ( 'should give the same 32 byte shared key' , ( ) => {
5353 const bobKeyPair : KeyPair = generateKeyPair ( )
5454 const aliceKeyPair : KeyPair = generateKeyPair ( )
5555
5656 const bobShared : Uint8Array = mixKeyExchange ( bobKeyPair . private , aliceKeyPair . public )
5757 const aliceShared : Uint8Array = mixKeyExchange ( aliceKeyPair . private , bobKeyPair . public )
5858
59- expect ( bobShared ) . to . have . lengthOf ( 32 )
60- expect ( bobShared ) . to . not . eql ( new Array ( 32 ) . fill ( 0 ) )
61- expect ( bobShared ) . to . eql ( aliceShared )
59+ assert . strictEqual ( bobShared . length , 32 )
60+ assert . notDeepStrictEqual ( bobShared , new Uint8Array ( 32 ) )
61+ assert . deepStrictEqual ( bobShared , aliceShared )
6262 } )
6363
64- it ( 'should not give the same 32 byte shared key' , ( ) => {
64+ test ( 'should not give the same 32 byte shared key' , ( ) => {
6565 const bobKeyPair : KeyPair = generateKeyPair ( )
6666 const aliceKeyPair : KeyPair = generateKeyPair ( )
6767 const eveKeyPair : KeyPair = generateKeyPair ( )
@@ -72,36 +72,36 @@ describe('mixKeyExchange', () => {
7272 const eveBobShared : Uint8Array = mixKeyExchange ( eveKeyPair . private , bobKeyPair . public )
7373 const eveAliceShared : Uint8Array = mixKeyExchange ( eveKeyPair . private , aliceKeyPair . public )
7474
75- expect ( eveBobShared ) . to . not . eql ( bobShared )
76- expect ( eveBobShared ) . to . not . eql ( aliceShared )
77- expect ( eveAliceShared ) . to . not . eql ( bobShared )
78- expect ( eveAliceShared ) . to . not . eql ( aliceShared )
75+ assert . notDeepStrictEqual ( eveBobShared , bobShared )
76+ assert . notDeepStrictEqual ( eveBobShared , aliceShared )
77+ assert . notDeepStrictEqual ( eveAliceShared , bobShared )
78+ assert . notDeepStrictEqual ( eveAliceShared , aliceShared )
7979 } )
8080} )
8181
8282describe ( 'KeyPair serialization' , ( ) => {
83- it ( 'should return the same keypair' , ( ) => {
83+ test ( 'should return the same keypair' , ( ) => {
8484 const keypair = generateKeyPair ( )
8585 const privateKeyBytes : Uint8Array = keypair . private . bytes
8686 const publicKeyBytes : Uint8Array = keypair . public . bytes
8787
8888 const privateKey : PrivateKey = PrivateKey . fromBytes ( privateKeyBytes )
8989 const publicKey : PublicKey = PublicKey . fromBytes ( publicKeyBytes )
9090
91- expect ( privateKey . bytes ) . to . eql ( privateKeyBytes )
92- expect ( publicKey . bytes ) . to . eql ( publicKeyBytes )
91+ assert . deepStrictEqual ( privateKey . bytes , privateKeyBytes )
92+ assert . deepStrictEqual ( publicKey . bytes , publicKeyBytes )
9393 } )
9494
95- it ( 'should not allow to parse a public key as a private key and vis-versa' , ( ) => {
95+ test ( 'should not allow to parse a public key as a private key and vis-versa' , ( ) => {
9696 const keypair = generateKeyPair ( )
9797 const privateKeyBytes : Uint8Array = keypair . private . bytes
9898 const publicKeyBytes : Uint8Array = keypair . public . bytes
9999
100100 const symmetricKey : Uint8Array = generateKey ( )
101101
102- expect ( ( ) => PrivateKey . fromBytes ( publicKeyBytes ) ) . to . throw ( )
103- expect ( ( ) => PublicKey . fromBytes ( privateKeyBytes ) ) . to . throw ( )
104- expect ( ( ) => PrivateKey . fromBytes ( symmetricKey ) ) . to . throw ( )
105- expect ( ( ) => PublicKey . fromBytes ( symmetricKey ) ) . to . throw ( )
102+ assert . throws ( ( ) => PrivateKey . fromBytes ( publicKeyBytes ) )
103+ assert . throws ( ( ) => PublicKey . fromBytes ( privateKeyBytes ) )
104+ assert . throws ( ( ) => PrivateKey . fromBytes ( symmetricKey ) )
105+ assert . throws ( ( ) => PublicKey . fromBytes ( symmetricKey ) )
106106 } )
107107} )
0 commit comments