-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #579 from matrix-org/dbkr/e2e_indexeddb
Move Olm account to IndexedDB
- Loading branch information
Showing
7 changed files
with
211 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2017 New Vector Ltd | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import Promise from 'bluebird'; | ||
import MemoryCryptoStore from './memory-crypto-store.js'; | ||
|
||
/** | ||
* Internal module. Partial localStorage backed storage for e2e. | ||
* This is not a full crypto store, just the in-memory store with | ||
* some things backed by localStorage. It exists because indexedDB | ||
* is broken in Firefox private mode or set to, "will not remember | ||
* history". | ||
* | ||
* @module | ||
*/ | ||
|
||
const E2E_PREFIX = "crypto."; | ||
const KEY_END_TO_END_ACCOUNT = E2E_PREFIX + "account"; | ||
|
||
/** | ||
* @implements {module:crypto/store/base~CryptoStore} | ||
*/ | ||
export default class LocalStorageCryptoStore extends MemoryCryptoStore { | ||
constructor() { | ||
super(); | ||
this.store = global.localStorage; | ||
} | ||
|
||
/** | ||
* Delete all data from this store. | ||
* | ||
* @returns {Promise} Promise which resolves when the store has been cleared. | ||
*/ | ||
deleteAllData() { | ||
this.store.removeItem(KEY_END_TO_END_ACCOUNT); | ||
return Promise.resolve(); | ||
} | ||
|
||
endToEndAccountTransaction(func) { | ||
const account = this.store.getItem(KEY_END_TO_END_ACCOUNT); | ||
return Promise.resolve(func(account, (newData) => { | ||
this.store.setItem(KEY_END_TO_END_ACCOUNT, newData); | ||
})); | ||
} | ||
} |
Oops, something went wrong.