File tree 2 files changed +17
-2
lines changed
packages/snaps-controllers
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "branches" : 92.63 ,
2
+ "branches" : 92.69 ,
3
3
"functions" : 96.65 ,
4
4
"lines" : 97.97 ,
5
5
"statements" : 97.67
Original file line number Diff line number Diff line change @@ -1734,6 +1734,17 @@ export class SnapController extends BaseController<
1734
1734
return { key : encryptionKey , salt } ;
1735
1735
}
1736
1736
1737
+ /**
1738
+ * Check if a given Snap has a cached encryption key stored in the runtime.
1739
+ *
1740
+ * @param snapId - The Snap ID.
1741
+ * @returns True if the Snap has a cached encryption key, otherwise false.
1742
+ */
1743
+ #hasCachedEncryptionKey( snapId : SnapId ) {
1744
+ const runtime = this . #getRuntimeExpect( snapId ) ;
1745
+ return runtime . encryptionKey !== null && runtime . encryptionSalt !== null ;
1746
+ }
1747
+
1737
1748
/**
1738
1749
* Decrypt the encrypted state for a given Snap.
1739
1750
*
@@ -1748,7 +1759,11 @@ export class SnapController extends BaseController<
1748
1759
// This lets us skip JSON validation.
1749
1760
const parsed = JSON . parse ( state ) as EncryptionResult ;
1750
1761
const { salt, keyMetadata } = parsed ;
1751
- const useCache = this . #encryptor. isVaultUpdated ( state ) ;
1762
+
1763
+ // We only cache encryption keys if they are already cached or if the encryption key is using the latest key derivation params.
1764
+ const useCache =
1765
+ this . #hasCachedEncryptionKey( snapId ) ||
1766
+ this . #encryptor. isVaultUpdated ( state ) ;
1752
1767
const { key } = await this . #getSnapEncryptionKey( {
1753
1768
snapId,
1754
1769
salt,
You can’t perform that action at this time.
0 commit comments