@@ -199,18 +199,19 @@ describe('encryption methods tests', () => {
199199 const password = 'myPassword' ;
200200 const plaintext = 'Hello, World!' ;
201201
202- it ( 'dispatches to v2 by default and output is decryptable via decryptAsync ' , async ( ) => {
202+ it ( 'dispatches to v1 by default and output is decryptable via decrypt ' , async ( ) => {
203203 const ct = await encryptAsync ( password , plaintext ) ;
204- const envelope : V2Envelope = JSON . parse ( ct ) ;
205- assert . strictEqual ( envelope . v , 2 , 'default should produce v2 envelope' ) ;
206- assert . strictEqual ( await decryptAsync ( password , ct ) , plaintext ) ;
204+ const envelope = JSON . parse ( ct ) ;
205+ assert . notStrictEqual ( envelope . v , 2 , 'default should not produce v2 envelope' ) ;
206+ assert . strictEqual ( decrypt ( password , ct ) , plaintext ) ;
207207 } ) ;
208208
209- it ( 'dispatches to v2 when encryptionVersion: 2 is explicit ' , async ( ) => {
209+ it ( 'dispatches to v2 when encryptionVersion: 2' , async ( ) => {
210210 const ct = await encryptAsync ( password , plaintext , { encryptionVersion : 2 } ) ;
211211 const envelope : V2Envelope = JSON . parse ( ct ) ;
212212 assert . strictEqual ( envelope . v , 2 ) ;
213- assert . strictEqual ( await decryptAsync ( password , ct ) , plaintext ) ;
213+ const result = await decryptAsync ( password , ct ) ;
214+ assert . strictEqual ( result , plaintext ) ;
214215 } ) ;
215216
216217 it ( 'dispatches to v1 when encryptionVersion: 1' , async ( ) => {
@@ -228,18 +229,9 @@ describe('encryption methods tests', () => {
228229 assert . strictEqual ( await decryptAsync ( password , ct ) , plaintext ) ;
229230 } ) ;
230231
231- it ( 'forwards adata to v2 envelope by default ' , async ( ) => {
232+ it ( 'encrypts v1 with adata ' , async ( ) => {
232233 const adata = 'additional data' ;
233234 const ct = await encryptAsync ( password , plaintext , { adata } ) ;
234- const envelope : V2Envelope = JSON . parse ( ct ) ;
235- assert . strictEqual ( envelope . v , 2 ) ;
236- assert . strictEqual ( envelope . adata , adata ) ;
237- assert . strictEqual ( await decryptAsync ( password , ct ) , plaintext ) ;
238- } ) ;
239-
240- it ( 'encrypts v1 with adata when encryptionVersion: 1' , async ( ) => {
241- const adata = 'additional data' ;
242- const ct = await encryptAsync ( password , plaintext , { adata, encryptionVersion : 1 } ) ;
243235 assert . strictEqual ( decrypt ( password , ct ) , plaintext ) ;
244236 } ) ;
245237
@@ -252,24 +244,18 @@ describe('encryption methods tests', () => {
252244 it ( 'forwards salt and iv options to v1 encrypt for deterministic output' , async ( ) => {
253245 const salt = randomBytes ( 8 ) ;
254246 const iv = randomBytes ( 16 ) ;
255- const ct1 = await encryptAsync ( password , plaintext , { salt, iv, encryptionVersion : 1 } ) ;
256- const ct2 = await encryptAsync ( password , plaintext , { salt, iv, encryptionVersion : 1 } ) ;
247+ const ct1 = await encryptAsync ( password , plaintext , { salt, iv } ) ;
248+ const ct2 = await encryptAsync ( password , plaintext , { salt, iv } ) ;
257249 assert . strictEqual ( ct1 , ct2 ) ;
258250 assert . strictEqual ( decrypt ( password , ct1 ) , plaintext ) ;
259251 } ) ;
260252
261- it ( 'throws an error if the salt length is not 8 bytes for v1' , async ( ) => {
262- await assert . rejects (
263- ( ) => encryptAsync ( password , plaintext , { salt : randomBytes ( 4 ) , encryptionVersion : 1 } ) ,
264- / s a l t m u s t b e 8 b y t e s /
265- ) ;
253+ it ( 'throws an error if the salt length is not 8 bytes' , async ( ) => {
254+ await assert . rejects ( ( ) => encryptAsync ( password , plaintext , { salt : randomBytes ( 4 ) } ) , / s a l t m u s t b e 8 b y t e s / ) ;
266255 } ) ;
267256
268- it ( 'throws an error if the iv length is not 16 bytes for v1' , async ( ) => {
269- await assert . rejects (
270- ( ) => encryptAsync ( password , plaintext , { iv : randomBytes ( 4 ) , encryptionVersion : 1 } ) ,
271- / i v m u s t b e 1 6 b y t e s /
272- ) ;
257+ it ( 'throws an error if the iv length is not 16 bytes' , async ( ) => {
258+ await assert . rejects ( ( ) => encryptAsync ( password , plaintext , { iv : randomBytes ( 4 ) } ) , / i v m u s t b e 1 6 b y t e s / ) ;
273259 } ) ;
274260 } ) ;
275261
@@ -462,18 +448,19 @@ describe('encryption methods tests', () => {
462448 bitgo = new BitGoAPI ( { env : 'test' } ) ;
463449 } ) ;
464450
465- it ( 'dispatches to v2 by default and output is decryptable via decryptAsync ' , async ( ) => {
451+ it ( 'dispatches to v1 by default and output is decryptable via decrypt ' , async ( ) => {
466452 const ct = await bitgo . encryptAsync ( { input : plaintext , password } ) ;
467- const envelope : V2Envelope = JSON . parse ( ct ) ;
468- assert . strictEqual ( envelope . v , 2 , 'default should produce v2 envelope' ) ;
469- assert . strictEqual ( await decryptAsync ( password , ct ) , plaintext ) ;
453+ const envelope = JSON . parse ( ct ) ;
454+ assert . notStrictEqual ( envelope . v , 2 , 'default should not produce v2 envelope' ) ;
455+ assert . strictEqual ( decrypt ( password , ct ) , plaintext ) ;
470456 } ) ;
471457
472- it ( 'dispatches to v2 when encryptionVersion: 2 is explicit ' , async ( ) => {
458+ it ( 'dispatches to v2 when encryptionVersion: 2 and output is decryptable via decryptAsync ' , async ( ) => {
473459 const ct = await bitgo . encryptAsync ( { input : plaintext , password, encryptionVersion : 2 } ) ;
474460 const envelope : V2Envelope = JSON . parse ( ct ) ;
475461 assert . strictEqual ( envelope . v , 2 ) ;
476- assert . strictEqual ( await decryptAsync ( password , ct ) , plaintext ) ;
462+ const result = await decryptAsync ( password , ct ) ;
463+ assert . strictEqual ( result , plaintext ) ;
477464 } ) ;
478465
479466 it ( 'forwards adata to v2 envelope' , async ( ) => {
0 commit comments