dexie-encrypted
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -93,7 +93,14 @@ 'use strict'; | ||
function encrypt(db, key, cryptoSettings, nonceOverride) { | ||
if (key instanceof Uint8Array === false || key.length !== 32) { | ||
function encrypt(db, keyOrPromise, cryptoSettings, nonceOverride) { | ||
let keyPromise; | ||
if (keyOrPromise.then) { | ||
keyPromise = keyOrPromise; | ||
} else if ((keyOrPromise instanceof Uint8Array) && keyOrPromise.length === 32) { | ||
keyPromise = Dexie.Promise.resolve(keyOrPromise); | ||
} else { | ||
throw new Error('Dexie-encrypted requires a UInt8Array of length 32 for a encryption key.'); | ||
} | ||
let key; | ||
db.Version.prototype._parseStoresSpec = override( | ||
@@ -182,3 +189,9 @@ db.Version.prototype._parseStoresSpec, | ||
} | ||
return encryptionSettings | ||
return keyPromise.then((receivedKey) => { | ||
if ((receivedKey instanceof Uint8Array) && receivedKey.length === 32) { | ||
key = receivedKey; | ||
} else { | ||
throw new Error('Dexie-encrypted requires a UInt8Array of length 32 for a encryption key.'); | ||
} | ||
}).then(() => encryptionSettings | ||
.toCollection() | ||
@@ -262,3 +275,3 @@ .last() | ||
} | ||
}); | ||
})); | ||
}); | ||
@@ -265,0 +278,0 @@ } |
{ | ||
"name": "dexie-encrypted", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Encryption middleware for Dexie", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -48,3 +48,3 @@ # Dexie-encrypted | ||
- `db` - a Dexie database that has not had .version called. | ||
- `key` - a Uint8Array of length 32 that will be used for both encryption and decryption. | ||
- `key` - a Uint8Array of length 32, or a promise that will resolve with one. This will be used for both encryption and decryption. | ||
- `config` - a table level configuration that determines how dexie-encrypted will encrypt. | ||
@@ -51,0 +51,0 @@ |
17160
255