Store private key in IndexDB
Closed this issue · 0 comments
PumpkinSeed commented
For the first version store the private key in the IndexDB.
Tasks:
- Under this line, think about whether you can store the
keys.privateKey
in the IndexDB (because in this case you don't need to import it), otherwise store theexportedPrivateKey
(but in this case you need to import it). - If the
current_active
key doesn't exists or contain a privateKey than generate a new one and store it. - All actions needs to use the private key stored in the
current_active
.
Example:
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction || { READ_WRITE: "readwrite" };
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
if (!window.indexedDB) {
console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}
async function process() {
let open = window.indexedDB.open('crypter', 1)
open.onupgradeneeded = function() {
let db = open.result
db.createObjectStore('private_keys', { autoIncrement: false })
}
open.onsuccess = function() {
let db = open.result
let tx = db.transaction('private_keys', 'readwrite')
let store = tx.objectStore('private_keys')
store.put({ firstname: 'John', lastname: 'Doe', age: 33 }, "current_active")
tx.oncomplete = function() {
db.close()
}
}
}
async function get() {
let open = window.indexedDB.open('crypter', 1)
open.onupgradeneeded = function() {
let db = open.result
db.createObjectStore('private_keys', { autoIncrement: false })
}
open.onsuccess = function() {
let db = open.result
let tx = db.transaction('private_keys', 'readonly')
let store = tx.objectStore('private_keys')
store.get("current_active")
var objectStoreRequest = store.get("current_active");
objectStoreRequest.onsuccess = (event) => {
if (objectStoreRequest.result !== undefined) {
console.log(objectStoreRequest.result);
}
}
tx.oncomplete = function() {
db.close()
}
}
}
process();
get();