@metamask/browser-passworder
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -160,5 +160,6 @@ export declare type DetailedEncryptionResult = { | ||
* @param password - The password to use for encryption. | ||
* @param targetDerivationParams - The options to use for key derivation. | ||
* @returns A promise resolving to the updated vault. | ||
*/ | ||
export declare function updateVault(vault: string, password: string): Promise<string>; | ||
export declare function updateVault(vault: string, password: string, targetDerivationParams?: KeyDerivationOptions): Promise<string>; | ||
/** | ||
@@ -173,4 +174,13 @@ * Updates the provided vault and exported key, re-encrypting | ||
* @param password - The password to use for encryption. | ||
* @param targetDerivationParams - The options to use for key derivation. | ||
* @returns A promise resolving to the updated encrypted data and exported key. | ||
*/ | ||
export declare function updateVaultWithDetail(encryptionResult: DetailedEncryptionResult, password: string): Promise<DetailedEncryptionResult>; | ||
export declare function updateVaultWithDetail(encryptionResult: DetailedEncryptionResult, password: string, targetDerivationParams?: KeyDerivationOptions): Promise<DetailedEncryptionResult>; | ||
/** | ||
* Checks if the provided vault is an updated encryption format. | ||
* | ||
* @param vault - The vault to check. | ||
* @param targetDerivationParams - The options to use for key derivation. | ||
* @returns Whether or not the vault is an updated encryption format. | ||
*/ | ||
export declare function isVaultUpdated(vault: string, targetDerivationParams?: KeyDerivationOptions): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateVaultWithDetail = exports.updateVault = exports.generateSalt = exports.serializeBufferForStorage = exports.serializeBufferFromStorage = exports.keyFromPassword = exports.exportKey = exports.importKey = exports.decryptWithKey = exports.decryptWithDetail = exports.decrypt = exports.encryptWithKey = exports.encryptWithDetail = exports.encrypt = void 0; | ||
exports.isVaultUpdated = exports.updateVaultWithDetail = exports.updateVault = exports.generateSalt = exports.serializeBufferForStorage = exports.serializeBufferFromStorage = exports.keyFromPassword = exports.exportKey = exports.importKey = exports.decryptWithKey = exports.decryptWithDetail = exports.decrypt = exports.encryptWithKey = exports.encryptWithDetail = exports.encrypt = void 0; | ||
const utils_1 = require("@metamask/utils"); | ||
@@ -281,9 +281,10 @@ const EXPORT_FORMAT = 'jwk'; | ||
* @param password - The password to use for encryption. | ||
* @param targetDerivationParams - The options to use for key derivation. | ||
* @returns A promise resolving to the updated vault. | ||
*/ | ||
async function updateVault(vault, password) { | ||
if (isVaultUpdated(vault)) { | ||
async function updateVault(vault, password, targetDerivationParams = DEFAULT_DERIVATION_PARAMS) { | ||
if (isVaultUpdated(vault, targetDerivationParams)) { | ||
return vault; | ||
} | ||
return encrypt(password, await decrypt(password, vault)); | ||
return encrypt(password, await decrypt(password, vault), undefined, undefined, targetDerivationParams); | ||
} | ||
@@ -300,9 +301,10 @@ exports.updateVault = updateVault; | ||
* @param password - The password to use for encryption. | ||
* @param targetDerivationParams - The options to use for key derivation. | ||
* @returns A promise resolving to the updated encrypted data and exported key. | ||
*/ | ||
async function updateVaultWithDetail(encryptionResult, password) { | ||
if (isVaultUpdated(encryptionResult.vault)) { | ||
async function updateVaultWithDetail(encryptionResult, password, targetDerivationParams = DEFAULT_DERIVATION_PARAMS) { | ||
if (isVaultUpdated(encryptionResult.vault, targetDerivationParams)) { | ||
return encryptionResult; | ||
} | ||
return encryptWithDetail(password, await decrypt(password, encryptionResult.vault)); | ||
return encryptWithDetail(password, await decrypt(password, encryptionResult.vault), undefined, targetDerivationParams); | ||
} | ||
@@ -360,11 +362,12 @@ exports.updateVaultWithDetail = updateVaultWithDetail; | ||
* @param vault - The vault to check. | ||
* @param targetDerivationParams - The options to use for key derivation. | ||
* @returns Whether or not the vault is an updated encryption format. | ||
*/ | ||
function isVaultUpdated(vault) { | ||
function isVaultUpdated(vault, targetDerivationParams = DEFAULT_DERIVATION_PARAMS) { | ||
const { keyMetadata } = JSON.parse(vault); | ||
return (isKeyDerivationOptions(keyMetadata) && | ||
keyMetadata.algorithm === DEFAULT_DERIVATION_PARAMS.algorithm && | ||
keyMetadata.params.iterations === | ||
DEFAULT_DERIVATION_PARAMS.params.iterations); | ||
keyMetadata.algorithm === targetDerivationParams.algorithm && | ||
keyMetadata.params.iterations === targetDerivationParams.params.iterations); | ||
} | ||
exports.isVaultUpdated = isVaultUpdated; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@metamask/browser-passworder", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "A simple browserifiable module for password-encrypting JS objects.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
56522
554