@codesense/conseal 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.d.ts +8 -3
- package/dist/index.js +62 -10
- package/package.json +1 -5
- package/dist/chunk-MDWFWP7Z.js +0 -63
- package/dist/storage.d.ts +0 -8
- package/dist/storage.js +0 -10
package/README.md
CHANGED
|
@@ -102,14 +102,14 @@ const result = await unseal(key, ciphertext, iv)
|
|
|
102
102
|
### IndexedDB key storage
|
|
103
103
|
|
|
104
104
|
```ts
|
|
105
|
-
import {
|
|
105
|
+
import { saveCryptoKey, loadCryptoKey, deleteCryptoKey } from 'conseal'
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
| Function | Description |
|
|
109
109
|
|---|---|
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
110
|
+
| `saveCryptoKey(name, key)` | Persists a CryptoKey to IndexedDB. |
|
|
111
|
+
| `loadCryptoKey(name)` | Loads a CryptoKey. Returns `null` if not found. |
|
|
112
|
+
| `deleteCryptoKey(name)` | Deletes a CryptoKey. |
|
|
113
113
|
|
|
114
114
|
### Utilities
|
|
115
115
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { load, remove, save } from './storage.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* AES-256-GCM symmetric encryption.
|
|
5
3
|
*
|
|
@@ -192,4 +190,11 @@ declare function fromBase64Url(b64url: string): Uint8Array;
|
|
|
192
190
|
/** Returns the SHA-256 hash of the input data as an ArrayBuffer. */
|
|
193
191
|
declare function digest(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
|
|
194
192
|
|
|
195
|
-
|
|
193
|
+
/** Persists a CryptoKey to IndexedDB under the given name. Overwrites if name exists. */
|
|
194
|
+
declare function saveCryptoKey(name: string, key: CryptoKey): Promise<void>;
|
|
195
|
+
/** Loads a CryptoKey from IndexedDB. Returns null if the name is not found. */
|
|
196
|
+
declare function loadCryptoKey(name: string): Promise<CryptoKey | null>;
|
|
197
|
+
/** Removes a CryptoKey from IndexedDB. No-op if the name does not exist. */
|
|
198
|
+
declare function deleteCryptoKey(name: string): Promise<void>;
|
|
199
|
+
|
|
200
|
+
export { AEK_KEY_ID, type SealedEnvelope, combinePassphraseAndSecretKey, decodeEnvelope, deleteCryptoKey, digest, encodeEnvelope, exportPublicKeyAsJwk, fromBase64, fromBase64Url, generateAesKey, generateECDHKeyPair, generateECDSAKeyPair, generateMnemonic, generateSecretKey, importAesKey, importPublicKeyFromJwk, init, loadCryptoKey, recoverWithMnemonic, rekey, rekeySecretKey, saveCryptoKey, seal, sealEnvelope, sealMessage, sign, toBase64, toBase64Url, unseal, unsealEnvelope, unsealMessage, unwrapKey, verify, wrapKey };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
load,
|
|
3
|
-
remove,
|
|
4
|
-
save
|
|
5
|
-
} from "./chunk-MDWFWP7Z.js";
|
|
6
|
-
|
|
7
1
|
// src/aes.ts
|
|
8
2
|
async function seal(key, plaintext) {
|
|
9
3
|
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
@@ -209,11 +203,69 @@ async function verify(publicKey, signature, data) {
|
|
|
209
203
|
return crypto.subtle.verify({ name: "ECDSA", hash: "SHA-256" }, publicKey, signature, data);
|
|
210
204
|
}
|
|
211
205
|
|
|
206
|
+
// src/storage.ts
|
|
207
|
+
var DB_NAME = "conseal-keys";
|
|
208
|
+
var STORE = "keys";
|
|
209
|
+
var VERSION = 1;
|
|
210
|
+
function openDb() {
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
const req = indexedDB.open(DB_NAME, VERSION);
|
|
213
|
+
req.onupgradeneeded = () => {
|
|
214
|
+
req.result.createObjectStore(STORE);
|
|
215
|
+
};
|
|
216
|
+
req.onsuccess = () => resolve(req.result);
|
|
217
|
+
req.onerror = () => reject(req.error);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
async function saveCryptoKey(name, key) {
|
|
221
|
+
const db = await openDb();
|
|
222
|
+
try {
|
|
223
|
+
return await new Promise((resolve, reject) => {
|
|
224
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
225
|
+
tx.objectStore(STORE).put(key, name);
|
|
226
|
+
tx.oncomplete = () => resolve();
|
|
227
|
+
tx.onerror = () => reject(tx.error);
|
|
228
|
+
});
|
|
229
|
+
} finally {
|
|
230
|
+
db.close();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function loadCryptoKey(name) {
|
|
234
|
+
const db = await openDb();
|
|
235
|
+
try {
|
|
236
|
+
return await new Promise((resolve, reject) => {
|
|
237
|
+
const tx = db.transaction(STORE, "readonly");
|
|
238
|
+
const req = tx.objectStore(STORE).get(name);
|
|
239
|
+
let result = null;
|
|
240
|
+
req.onsuccess = () => {
|
|
241
|
+
result = req.result ?? null;
|
|
242
|
+
};
|
|
243
|
+
tx.oncomplete = () => resolve(result);
|
|
244
|
+
tx.onerror = () => reject(tx.error);
|
|
245
|
+
});
|
|
246
|
+
} finally {
|
|
247
|
+
db.close();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function deleteCryptoKey(name) {
|
|
251
|
+
const db = await openDb();
|
|
252
|
+
try {
|
|
253
|
+
return await new Promise((resolve, reject) => {
|
|
254
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
255
|
+
tx.objectStore(STORE).delete(name);
|
|
256
|
+
tx.oncomplete = () => resolve();
|
|
257
|
+
tx.onerror = () => reject(tx.error);
|
|
258
|
+
});
|
|
259
|
+
} finally {
|
|
260
|
+
db.close();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
212
264
|
// src/init.ts
|
|
213
265
|
var AEK_KEY_ID = "aek";
|
|
214
266
|
async function init(wrappedKey, salt, passphrase, secretKey) {
|
|
215
267
|
const aek = await unwrapKey(passphrase, wrappedKey, salt, secretKey);
|
|
216
|
-
await
|
|
268
|
+
await saveCryptoKey(AEK_KEY_ID, aek);
|
|
217
269
|
}
|
|
218
270
|
|
|
219
271
|
// node_modules/@noble/hashes/utils.js
|
|
@@ -2997,6 +3049,7 @@ export {
|
|
|
2997
3049
|
AEK_KEY_ID,
|
|
2998
3050
|
combinePassphraseAndSecretKey,
|
|
2999
3051
|
decodeEnvelope,
|
|
3052
|
+
deleteCryptoKey,
|
|
3000
3053
|
digest,
|
|
3001
3054
|
encodeEnvelope,
|
|
3002
3055
|
exportPublicKeyAsJwk,
|
|
@@ -3010,12 +3063,11 @@ export {
|
|
|
3010
3063
|
importAesKey,
|
|
3011
3064
|
importPublicKeyFromJwk,
|
|
3012
3065
|
init,
|
|
3013
|
-
|
|
3066
|
+
loadCryptoKey,
|
|
3014
3067
|
recoverWithMnemonic,
|
|
3015
3068
|
rekey,
|
|
3016
3069
|
rekeySecretKey,
|
|
3017
|
-
|
|
3018
|
-
save,
|
|
3070
|
+
saveCryptoKey,
|
|
3019
3071
|
seal,
|
|
3020
3072
|
sealEnvelope,
|
|
3021
3073
|
sealMessage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codesense/conseal",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Browser-side zero-knowledge cryptography library using SubtleCrypto.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,10 +9,6 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
|
-
},
|
|
13
|
-
"./storage": {
|
|
14
|
-
"import": "./dist/storage.js",
|
|
15
|
-
"types": "./dist/storage.d.ts"
|
|
16
12
|
}
|
|
17
13
|
},
|
|
18
14
|
"scripts": {
|
package/dist/chunk-MDWFWP7Z.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// src/storage.ts
|
|
2
|
-
var DB_NAME = "conseal-keys";
|
|
3
|
-
var STORE = "keys";
|
|
4
|
-
var VERSION = 1;
|
|
5
|
-
function openDb() {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
const req = indexedDB.open(DB_NAME, VERSION);
|
|
8
|
-
req.onupgradeneeded = () => {
|
|
9
|
-
req.result.createObjectStore(STORE);
|
|
10
|
-
};
|
|
11
|
-
req.onsuccess = () => resolve(req.result);
|
|
12
|
-
req.onerror = () => reject(req.error);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
async function save(name, key) {
|
|
16
|
-
const db = await openDb();
|
|
17
|
-
try {
|
|
18
|
-
return await new Promise((resolve, reject) => {
|
|
19
|
-
const tx = db.transaction(STORE, "readwrite");
|
|
20
|
-
tx.objectStore(STORE).put(key, name);
|
|
21
|
-
tx.oncomplete = () => resolve();
|
|
22
|
-
tx.onerror = () => reject(tx.error);
|
|
23
|
-
});
|
|
24
|
-
} finally {
|
|
25
|
-
db.close();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async function load(name) {
|
|
29
|
-
const db = await openDb();
|
|
30
|
-
try {
|
|
31
|
-
return await new Promise((resolve, reject) => {
|
|
32
|
-
const tx = db.transaction(STORE, "readonly");
|
|
33
|
-
const req = tx.objectStore(STORE).get(name);
|
|
34
|
-
let result = null;
|
|
35
|
-
req.onsuccess = () => {
|
|
36
|
-
result = req.result ?? null;
|
|
37
|
-
};
|
|
38
|
-
tx.oncomplete = () => resolve(result);
|
|
39
|
-
tx.onerror = () => reject(tx.error);
|
|
40
|
-
});
|
|
41
|
-
} finally {
|
|
42
|
-
db.close();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function remove(name) {
|
|
46
|
-
const db = await openDb();
|
|
47
|
-
try {
|
|
48
|
-
return await new Promise((resolve, reject) => {
|
|
49
|
-
const tx = db.transaction(STORE, "readwrite");
|
|
50
|
-
tx.objectStore(STORE).delete(name);
|
|
51
|
-
tx.oncomplete = () => resolve();
|
|
52
|
-
tx.onerror = () => reject(tx.error);
|
|
53
|
-
});
|
|
54
|
-
} finally {
|
|
55
|
-
db.close();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export {
|
|
60
|
-
save,
|
|
61
|
-
load,
|
|
62
|
-
remove
|
|
63
|
-
};
|
package/dist/storage.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Persists a CryptoKey to IndexedDB under the given name. Overwrites if name exists. */
|
|
2
|
-
declare function save(name: string, key: CryptoKey): Promise<void>;
|
|
3
|
-
/** Loads a CryptoKey from IndexedDB. Returns null if the name is not found. */
|
|
4
|
-
declare function load(name: string): Promise<CryptoKey | null>;
|
|
5
|
-
/** Removes a CryptoKey from IndexedDB. No-op if the name does not exist. */
|
|
6
|
-
declare function remove(name: string): Promise<void>;
|
|
7
|
-
|
|
8
|
-
export { load, remove, save };
|