This repository was archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.html
More file actions
93 lines (77 loc) · 2.86 KB
/
temp.html
File metadata and controls
93 lines (77 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/idb@8/build/umd.js"></script>
<script>
const dbName = 'keyDatabase';
const storeName = 'keys';
const version = 1;
const key = 'privt';
/*
function writeKeyToIDB(key) {
return new Promise((resolve, reject) => {
const request = indexedDB.open("keyDatabase", 2);
request.onerror = (err) => {
console.error(err);
};
request.onupgradeneeded = (event) => {
const db = event.target.result;
const objectStore = db.createObjectStore("keys", { keyPath: "keyType" });
objectStore.createIndex("key", "key", { unique: true });
objectStore.transaction.oncomplete = (event) => {
const keyObjStore = db
.transaction("keys", "readwrite")
.objectStore("keys");
keyObjStore.add({ keyType: 'prvt', key: "DJDHDJKHKJDHKFJSHFKJDSHFLKJDf" });
};
};
})
}
*/
const getDB = () => {
return new Promise(async (resolve, reject) => {
if (!('indexedDB' in window)) {
console.warn('IndexedDB not supported');
return reject();
}
const db = await idb.openDB(dbName, version, {
upgrade(db, oldVersion, newVersion, transaction) {
const store = db.createObjectStore(storeName);
}
});
resolve(db);
});
}
async function writeKeyToIDB(cKey) {
try {
const db = await getDB();
if (!db) return;
const tx = db.transaction(storeName, 'readwrite');
const store = await tx.objectStore(storeName);
const val = cKey;
const value = await store.put(val, key);
await tx.done;
return true;
}
catch (err) {
console.error(err);
return false;
}
}
async function send() {
const db = await getDB();
if (!db) return;
const privtKey = await db.transaction(storeName).objectStore(storeName).get(key);
console.log(privtKey);
}
</script>
</head>
<body>
<button onclick="writeKeyToIDB('MY PRIVATE KEY!!!')">New Private Key</button>
<input type="text" id="txtinp">
<button onclick="send()">send message</button>
</body>
</html>