@@ -388,8 +388,8 @@ var VaultFolder = class _VaultFolder {
388388 this . key = key ;
389389 this . metadata = metadata ?? { s : [ ] , f : [ ] } ;
390390 }
391- async serialize ( ) {
392- return await this . key . encryptObject ( this . metadata ) ;
391+ async serialize ( extra ) {
392+ return await this . key . encryptObject ( extra ? { ... extra , ... this . metadata } : this . metadata ) ;
393393 }
394394 handle ( name ) {
395395 return {
@@ -604,25 +604,25 @@ var Vault = class _Vault {
604604 }
605605 static async deserialize ( data , password , io ) {
606606 const parts = data . split ( "~" ) ;
607- if ( parts . length !== 2 && parts . length !== 3 ) {
607+ if ( parts . length !== 2 ) {
608608 return null ;
609609 }
610610 const imp = await CryptoKey . importWithPassword ( parts [ 0 ] , password ) ;
611611 if ( ! imp ) {
612612 return null ;
613613 }
614614 const { key, difficulty } = imp ;
615- if ( parts . length === 3 ) {
616- const exp = parseFloat ( await key . decryptString ( parts [ 2 ] ) ) ;
617- const now = Math . floor ( Date . now ( ) / 6e4 ) ;
618- if ( now >= exp ) {
619- return null ;
620- }
621- }
622615 const root = await VaultFolder . deserialize ( - 1 , key , parts [ 1 ] ) ;
623616 if ( ! root ) {
624617 return null ;
625618 }
619+ const metadata = root . metadata ;
620+ if ( "x" in metadata && typeof metadata . x === "number" ) {
621+ const now = Math . floor ( Date . now ( ) / 6e4 ) ;
622+ if ( now >= metadata . x ) {
623+ return null ;
624+ }
625+ }
626626 return new _Vault ( root , difficulty , io ) ;
627627 }
628628 containerDirty ( ) {
@@ -631,15 +631,13 @@ var Vault = class _Vault {
631631 // expiration is enforced on the client-side... so not 100% secure but at least it's something
632632 async serialize ( password , difficulty = 0 , expiresInMinutes = 0 ) {
633633 const d = difficulty > 0 ? difficulty : this . difficulty > 0 ? this . difficulty : _Vault . DEFAULT_DIFFICULTY ;
634- const parts = [
635- await this . root . key . exportWithPassword ( password , d ) ,
636- await this . root . serialize ( )
637- ] ;
634+ let more = void 0 ;
638635 if ( expiresInMinutes > 0 ) {
639- const exp = Math . ceil ( Date . now ( ) / 6e4 ) + expiresInMinutes ;
640- parts . push ( await this . root . key . encryptString ( `${ exp } ` ) ) ;
636+ more = { x : Math . ceil ( Date . now ( ) / 6e4 ) + expiresInMinutes } ;
641637 }
642- return parts . join ( "~" ) ;
638+ const k = await this . root . key . exportWithPassword ( password , d ) ;
639+ const r = await this . root . serialize ( more ) ;
640+ return `${ k } ~${ r } ` ;
643641 }
644642 async save ( forceEverything = false ) {
645643 const saveFile = async ( file ) => {
@@ -1097,7 +1095,11 @@ Missing destination directory`);
10971095 }
10981096 for ( const file of vault . listFiles ( ) ) {
10991097 const bytes = await vault . getFile ( file ) ;
1100- await fs2 . writeFile ( path . join ( dir , file ) , bytes ) ;
1098+ if ( ! bytes ) {
1099+ console . warn ( `Warning: Failed to decrypt file: ${ vault . getPath ( ) } /${ file } ` ) ;
1100+ } else {
1101+ await fs2 . writeFile ( path . join ( dir , file ) , bytes ) ;
1102+ }
11011103 }
11021104 } ;
11031105 await walk ( destination ) ;
0 commit comments